]> git.armaanb.net Git - chorizo.git/commitdiff
Refuse to quit if there are active downloads
authorPeter Hofmann <scm@uninformativ.de>
Sat, 8 Apr 2017 09:35:12 +0000 (11:35 +0200)
committerPeter Hofmann <scm@uninformativ.de>
Sat, 8 Apr 2017 09:40:03 +0000 (11:40 +0200)
CC #35.

CHANGES
browser.c
man1/lariza.usage.1

diff --git a/CHANGES b/CHANGES
index bc5113942eab6c98a95cc9fdcd462908c983b320..c25337e592de78504188e1fbd945e21ccd732e4c 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -9,6 +9,9 @@ next
   - Autoreloading of crashed web processes has been removed. It doesn't
     make sense anymore since the switch to webkit's multi-process model.
     Instead, we now simply announce the crash in the location bar.
+  - Refuse to quit if there are active downloads. The user has to cancel
+    them explicitly. (To improve workflow a little bit, the download
+    manager now also knows a "Mod1 + q" hotkey.)
 
 v17.02  2017-02-16
   [Fixed]
index 6c4e849a79b655ec64a831f0d3dd347fe8851a4a..86f27dbdd7394b64a9671f70950c93f65790c1e8 100644 (file)
--- a/browser.c
+++ b/browser.c
@@ -29,6 +29,7 @@ static gboolean decide_policy(WebKitWebView *, WebKitPolicyDecision *,
 static gboolean download_handle(WebKitDownload *, gchar *, gpointer);
 static void download_handle_start(WebKitWebView *, WebKitDownload *, gpointer);
 static void downloadmanager_cancel(GtkToolButton *, gpointer data);
+static gboolean downloadmanager_delete(GtkWidget *, gpointer);
 static void downloadmanager_setup(void);
 static gchar *ensure_uri_scheme(const gchar *);
 static void external_handler_run(GtkAction *, gpointer);
@@ -42,6 +43,7 @@ static void keywords_load(void);
 static gboolean keywords_try_search(WebKitWebView *, const gchar *);
 static gboolean menu_web_view(WebKitWebView *, WebKitContextMenu *, GdkEvent *,
                               WebKitHitTestResult *, gpointer);
+static gboolean quit_if_nothing_active(void);
 static gboolean remote_msg(GIOChannel *, GIOCondition, gpointer);
 static void search(gpointer, gint);
 static void show_web_view(WebKitWebView *, gpointer);
@@ -68,7 +70,7 @@ struct DownloadManager
 
 
 static const gchar *accepted_language[2] = { NULL, NULL };
-static gint clients = 0;
+static gint clients = 0, downloads = 0;
 static gboolean cooperative_alone = TRUE;
 static gboolean cooperative_instances = TRUE;
 static int cooperative_pipe_fp = 0;
@@ -96,8 +98,7 @@ client_destroy(GtkWidget *obj, gpointer data)
     free(c);
     clients--;
 
-    if (clients == 0)
-        gtk_main_quit();
+    quit_if_nothing_active();
 }
 
 gboolean
@@ -405,6 +406,12 @@ decide_policy(WebKitWebView *web_view, WebKitPolicyDecision *decision,
     return TRUE;
 }
 
+void
+download_handle_finished(WebKitDownload *download, gpointer data)
+{
+    downloads--;
+}
+
 void
 download_handle_start(WebKitWebView *web_view, WebKitDownload *download,
                       gpointer data)
@@ -456,6 +463,10 @@ download_handle(WebKitDownload *download, gchar *suggested_filename, gpointer da
         g_signal_connect(G_OBJECT(download), "notify::estimated-progress",
                          G_CALLBACK(changed_download_progress), tb);
 
+        downloads++;
+        g_signal_connect(G_OBJECT(download), "finished",
+                         G_CALLBACK(download_handle_finished), NULL);
+
         g_object_ref(download);
         g_signal_connect(G_OBJECT(tb), "clicked",
                          G_CALLBACK(downloadmanager_cancel), download);
@@ -480,6 +491,15 @@ downloadmanager_cancel(GtkToolButton *tb, gpointer data)
     gtk_widget_destroy(GTK_WIDGET(tb));
 }
 
+gboolean
+downloadmanager_delete(GtkWidget *obj, gpointer data)
+{
+    if (!quit_if_nothing_active())
+        gtk_widget_hide(dm.win);
+
+    return TRUE;
+}
+
 void
 downloadmanager_setup(void)
 {
@@ -488,7 +508,7 @@ downloadmanager_setup(void)
     gtk_window_set_default_size(GTK_WINDOW(dm.win), 500, 250);
     gtk_window_set_title(GTK_WINDOW(dm.win), __NAME__" - Download Manager");
     g_signal_connect(G_OBJECT(dm.win), "delete-event",
-                     G_CALLBACK(gtk_widget_hide_on_delete), NULL);
+                     G_CALLBACK(downloadmanager_delete), NULL);
     g_signal_connect(G_OBJECT(dm.win), "key-press-event",
                      G_CALLBACK(key_downloadmanager), NULL);
 
@@ -704,7 +724,8 @@ key_downloadmanager(GtkWidget *widget, GdkEvent *event, gpointer data)
             switch (((GdkEventKey *)event)->keyval)
             {
                 case GDK_KEY_d:  /* close window (left hand) */
-                    gtk_widget_hide(dm.win);
+                case GDK_KEY_q:
+                    downloadmanager_delete(dm.win, NULL);
                     return TRUE;
             }
         }
@@ -905,6 +926,23 @@ menu_web_view(WebKitWebView *web_view, WebKitContextMenu *menu, GdkEvent *ev,
     return FALSE;
 }
 
+gboolean
+quit_if_nothing_active(void)
+{
+    if (clients == 0)
+    {
+        if (downloads == 0)
+        {
+            gtk_main_quit();
+            return TRUE;
+        }
+        else
+            gtk_widget_show_all(dm.win);
+    }
+
+    return FALSE;
+}
+
 gboolean
 remote_msg(GIOChannel *channel, GIOCondition condition, gpointer data)
 {
index 7c720269dffdc0236a25b6d750455af3fba613ce..17279ccd2afa0dfb00692425d4bd101e836dedcc 100644 (file)
@@ -51,7 +51,9 @@ focused.
 Launch the external handler for the currently loaded URI.
 .TP
 \fBMod1\fP + \fBq\fP
-Close the current window.
+Close the current window. Quits the entire program if this was the last
+window and if there are no more active downloads (download manager is
+shown otherwise).
 .TP
 \fBMod1\fP + \fBw\fP
 Go to your \(lqhomepage\(rq. See the environment variable
@@ -124,7 +126,11 @@ Commit, i.e. begin searching, do a keyword based search or open the URI.
 .SS "Download manager"
 .TP
 \fBMod1\fP + \fBd\fP
-Close the download manager (downloads are not aborted).
+.TQ
+\fBMod1\fP + \fBq\fP
+Close the download manager. Active downloads are never aborted. However,
+if there are no more active downloads and no more browsing windows, then
+the entire program will quit.
 .\" --------------------------------------------------------------------
 .SH "KEYWORD BASED SEARCHING"
 In this file, you can configure keywords and the associated URIs: