Added autocmd events for downloads (#100).
authorDaniel Carl <danielcarl@gmx.de>
Sun, 7 Sep 2014 19:00:31 +0000 (21:00 +0200)
committerDaniel Carl <danielcarl@gmx.de>
Sun, 7 Sep 2014 19:00:31 +0000 (21:00 +0200)
doc/vimb.1
src/autocmd.c
src/autocmd.h
src/main.c

index b0caf37..ddab023 100644 (file)
@@ -631,7 +631,7 @@ associated URL to match.
 .TP
 .B LoadCommited
 Fired if first data chunk has arrived, meaning that the necessary transport
-requirements are stabilished, and the load is being performed. This is the
+requirements are established, and the load is being performed. This is the
 right event to toggle content related setting like 'scripts', 'plugins' and
 such things.
 .TP
@@ -640,11 +640,23 @@ fired if the first layout with actual visible content is shown.
 .TP
 .B LoadFinished
 Fires when everything that was required to display on the page has been loaded.
-.PD
 .TP
 .B LoadFailed
 Fired when some error occurred during the page load that prevented it from
 being completed.
+.TP
+.B DownloadStart
+Fired right before a download is started. This is fired for vimb downloads as
+well as external downloads if 'download-use-external' is enabled.
+.TP
+.B DownloadFinished
+Fired if a vimb managed download is finished. For external download this event
+is not available.
+.TP
+.B DownloadFailed
+Fired if a vimb managed download failed. For external download this event
+is not available.
+.PD
 .RE
 .TP
 .I pat
index 97fc154..2855736 100644 (file)
@@ -39,12 +39,15 @@ static struct {
     const char *name;
     guint      bits;
 } events[] = {
-    {"*",               0x001f},
-    {"LoadProvisional", 0x0001},
-    {"LoadCommited",    0x0002},
-    {"LoadFirstLayout", 0x0004},
-    {"LoadFinished",    0x0008},
-    {"LoadFailed",      0x0010},
+    {"*",                0x00ff},
+    {"LoadProvisional",  0x0001},
+    {"LoadCommited",     0x0002},
+    {"LoadFirstLayout",  0x0004},
+    {"LoadFinished",     0x0008},
+    {"LoadFailed",       0x0010},
+    {"DownloadStart",    0x0020},
+    {"DownloadFinished", 0x0040},
+    {"DownloadFailed",   0x0080},
 };
 
 extern VbCore vb;
index 506560d..ac31be7 100644 (file)
@@ -33,6 +33,9 @@ typedef enum {
     AU_PAGE_LOAD_FIRST_LAYOUT,
     AU_PAGE_LOAD_FINISHED,
     AU_PAGE_LOAD_FAILED,
+    AU_DOWNLOAD_START,
+    AU_DOWNLOAD_FINISHED,
+    AU_DOWNLOAD_FAILED,
 } AuEvent;
 
 void autocmd_init(void);
index 215107a..69b1e26 100644 (file)
@@ -1284,6 +1284,9 @@ gboolean vb_download(WebKitWebView *view, WebKitDownload *download, const char *
         file = util_build_path(path, vb.config.download_dir);
     }
 
+#ifdef FEATURE_AUTOCMD
+    autocmd_run(NULL, AU_DOWNLOAD_START, webkit_download_get_uri(download));
+#endif
     if (use_external && *download_cmd) {
         /* run download with external program */
         vb_download_external(view, download, file);
@@ -1411,8 +1414,14 @@ static void download_progress_cp(WebKitDownload *download, GParamSpec *pspec)
         file += 7;
     }
     if (status != WEBKIT_DOWNLOAD_STATUS_FINISHED) {
+#ifdef FEATURE_AUTOCMD
+        autocmd_run(NULL, AU_DOWNLOAD_FAILED, webkit_download_get_uri(download));
+#endif
         vb_echo(VB_MSG_ERROR, false, "Error downloading %s", file);
     } else {
+#ifdef FEATURE_AUTOCMD
+        autocmd_run(NULL, AU_DOWNLOAD_FINISHED, webkit_download_get_uri(download));
+#endif
         vb_echo(VB_MSG_NORMAL, false, "Download %s finished", file);
     }