From ryan.flannery at gmail.com Tue Feb 1 08:09:33 2011 From: ryan.flannery at gmail.com (Ryan Flannery) Date: Tue, 1 Feb 2011 03:09:33 -0500 Subject: [Vimprobable-users] Add support for WM_COMMAND atom Message-ID: Hi all, This diff adds support for the WM_COMMAND atom that will allow tabbed-like applications (I'm working on a new one) to re-launch instance(s) of vimprobable with the current URI's they have loaded. git diff --stat main.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 44 insertions(+), 0 deletions(-) diff --git a/main.c b/main.c index 95ad0cd..8a36bc4 100644 --- a/main.c +++ b/main.c @@ -9,6 +9,7 @@ */ #include +#include #include "includes.h" #include "vimprobable.h" #include "utilities.h" @@ -72,6 +73,7 @@ static gboolean zoom(const Arg *arg); static gboolean fake_key_event(const Arg *arg); static void update_url(const char *uri); +static void update_wm_command(const char *uri); static void setup_modkeys(void); static void setup_gui(void); static void setup_settings(void); @@ -121,6 +123,7 @@ static char current_modkey; static char *search_handle; static gboolean search_direction; static gboolean echo_active = TRUE; +static gboolean gui_setup_complete = FALSE; WebKitWebInspector *inspector; static GdkNativeWindow embed = 0; @@ -197,6 +200,7 @@ webview_load_committed_cb(WebKitWebView *webview, WebKitWebFrame *frame, gpointe const char *uri = webkit_web_view_get_uri(webview); update_url(uri); + update_wm_command(uri); script(&a); } @@ -2058,6 +2062,7 @@ setup_gui() { gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(box)); gtk_widget_grab_focus(GTK_WIDGET(webview)); gtk_widget_show_all(GTK_WIDGET(window)); + gui_setup_complete = TRUE; } void @@ -2263,6 +2268,45 @@ mop_up(void) { return; } +void +update_wm_command(const char *uri) +{ + Display *xdisplay = NULL; + Window xwindow = 0; + char *arg_uri; + char *argv[6]; + int argc; + + if (!gui_setup_complete || !uri || strlen(uri) == 0) + return; + + if (xdisplay == NULL && (xdisplay = XOpenDisplay(NULL)) == NULL) + return; + + if (xwindow == 0) + xwindow = GDK_WINDOW_XID(GTK_WIDGET(window)->window); + + if ((arg_uri = strdup(uri)) == NULL) + return; + + if (embed) { + argc = 4; + argv[0] = *args; + argv[1] = "-e"; + argv[2] = winid; + argv[3] = arg_uri; + argv[4] = NULL; + } else { + argc = 2; + argv[0] = *args; + argv[1] = arg_uri; + argv[2] = NULL; + } + + XSetCommand(xdisplay, xwindow, argv, argc); + XFlush(xdisplay); + free(arg_uri); +} int main(int argc, char *argv[]) { static Arg a; From thomas at xteddy.org Tue Feb 1 08:34:38 2011 From: thomas at xteddy.org (Thomas Adam) Date: Tue, 1 Feb 2011 08:34:38 +0000 Subject: [Vimprobable-users] Add support for WM_COMMAND atom In-Reply-To: References: Message-ID: <20110201083436.GB3008@abacus.soton.smoothwall.net> Hi, On Tue, Feb 01, 2011 at 03:09:33AM -0500, Ryan Flannery wrote: > Hi all, > > This diff adds support for the WM_COMMAND atom that will allow > tabbed-like applications (I'm working on a new one) to re-launch > instance(s) of vimprobable with the current URI's they have loaded. Funnily enough, so am I. Email me off list, perhaps we can pull resources? With regards to WM_COMMAND, this looks OK. I can't say I care much for the idea either way, but... > #include > +#include > #include "includes.h" > #include "vimprobable.h" > #include "utilities.h" > @@ -72,6 +73,7 @@ static gboolean zoom(const Arg *arg); > static gboolean fake_key_event(const Arg *arg); > > static void update_url(const char *uri); > +static void update_wm_command(const char *uri); > static void setup_modkeys(void); > static void setup_gui(void); > static void setup_settings(void); > @@ -121,6 +123,7 @@ static char current_modkey; > static char *search_handle; > static gboolean search_direction; > static gboolean echo_active = TRUE; > +static gboolean gui_setup_complete = FALSE; I don't like this idea at all of using gui_setup_complete -- there's another way, surely? > +void > +update_wm_command(const char *uri) > +{ > + Display *xdisplay = NULL; > + Window xwindow = 0; Why? Just always make xwindow equal to GDK_WINDOW_XID() > + char *arg_uri; > + char *argv[6]; > + int argc; > + > + if (!gui_setup_complete || !uri || strlen(uri) == 0) > + return; > + > + if (xdisplay == NULL && (xdisplay = XOpenDisplay(NULL)) == NULL) > + return; This is a bit more fatal than just a return here -- and probably is never going to happen anyway (because by the time setup_gui() has run, it already can access a Display -- but even so, a fprintf(stderr, ...) wouldn't go amiss here. > + if (xwindow == 0) > + xwindow = GDK_WINDOW_XID(GTK_WIDGET(window)->window); > + > + if ((arg_uri = strdup(uri)) == NULL) > + return; This if line might be better off after your check for strlen(uri) as it logically follows. > + if (embed) { > + argc = 4; > + argv[0] = *args; > + argv[1] = "-e"; > + argv[2] = winid; > + argv[3] = arg_uri; > + argv[4] = NULL; > + } else { > + argc = 2; > + argv[0] = *args; > + argv[1] = arg_uri; > + argv[2] = NULL; > + } Yeah -- now we have something similar in main(); I don't like the duplication here. > + XSetCommand(xdisplay, xwindow, argv, argc); Always check the return value from XSetCommand, please. Don't blindly assume it will work, because it doesn't always. :) Otherwise the rest looks OK. -- Thomas Adam From hannes at yllr.net Tue Feb 1 17:44:21 2011 From: hannes at yllr.net (Hannes =?UTF-8?B?U2Now7xsbGVy?=) Date: Tue, 1 Feb 2011 18:44:21 +0100 Subject: [Vimprobable-users] Add support for WM_COMMAND atom In-Reply-To: References: Message-ID: <20110201184421.26f14166@workstation> Hello Ryan! Ryan Flannery wrote: > This diff adds support for the WM_COMMAND atom that will allow > tabbed-like applications (I'm working on a new one) to re-launch > instance(s) of vimprobable with the current URI's they have loaded. Just so that I understand the idea (I'm slow at grasping these things...): The "use case" is to trigger a new window being opened which loads the same URL of the window from which the command was spawned? Hannes -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: not available URL: From thomas at xteddy.org Tue Feb 1 20:01:40 2011 From: thomas at xteddy.org (Thomas Adam) Date: Tue, 1 Feb 2011 20:01:40 +0000 Subject: [Vimprobable-users] Add support for WM_COMMAND atom In-Reply-To: <20110201184421.26f14166@workstation> References: <20110201184421.26f14166@workstation> Message-ID: <20110201200138.GA2234@debian.ttn6tadam> On Tue, Feb 01, 2011 at 06:44:21PM +0100, Hannes Sch??ller wrote: > Hello Ryan! > > Ryan Flannery wrote: > > This diff adds support for the WM_COMMAND atom that will allow > > tabbed-like applications (I'm working on a new one) to re-launch > > instance(s) of vimprobable with the current URI's they have loaded. > > Just so that I understand the idea (I'm slow at grasping these > things...): The "use case" is to trigger a new window being opened > which loads the same URL of the window from which the command was > spawned? Yes -- the WM_COMMAND XAtom is used to show the command that was used to start or restart the client -- so in this case, we store that in the XAtom, but update it each time a new URL is visited -- so that when we look at it, it, it will just be: vimprobable2 -e SOME_SOCKET http://.... For each Vimprobable instance. -- Thomas Adam -- "It was the cruelest game I've ever played and it's played inside my head." -- "Hush The Warmth", Gorky's Zygotic Mynci. From matto at matto.nl Tue Feb 1 20:30:14 2011 From: matto at matto.nl (Matto Fransen) Date: Tue, 1 Feb 2011 21:30:14 +0100 Subject: [Vimprobable-users] Implementing run-time download path (save-as dialogue too?) In-Reply-To: <20110130210355.GA5425@debian.ttn6tadam> References: <20110130210355.GA5425@debian.ttn6tadam> Message-ID: <20110201203012.GB1778@debian64.tradesystem.nl> Hello, On Sun, Jan 30, 2011 at 09:03:58PM +0000, Thomas Adam wrote: > For a while now I've had a patch which makes configuring the location of > downloaded files available via ":set". I was going to clean it up and send > it as another patch, and realised that there's a much more interesting > question. > > Should we have another option for having a save-as dialogue window? > > For instance, I am thinking of allowing this anyway: > > :set download_path ~/some/random/directory/ That could be usefull > Which would make Vimprobable put all downloads into the value of > download_path. > > But now, in addition to that I am wondering if there should not be another > option which always invokes the save-as dialogue prompt to let the user > choose where to put files. > > What do people think? What if we have make this a textmode dialog with tabcompletion? Then we keep the vim-style but have the flexibility to save the current download to whereever we want it, without have to mouseclick to "Filesystem" -> "/tmp" So you can do something like: save-to /h /home/ma /home/matto/t /home/matto/tmp/ Cheers, Matto From ryan.flannery at gmail.com Wed Feb 2 17:34:01 2011 From: ryan.flannery at gmail.com (Ryan Flannery) Date: Wed, 2 Feb 2011 12:34:01 -0500 Subject: [Vimprobable-users] Add support for WM_COMMAND atom In-Reply-To: <20110201083436.GB3008@abacus.soton.smoothwall.net> References: <20110201083436.GB3008@abacus.soton.smoothwall.net> Message-ID: On Tue, Feb 1, 2011 at 3:34 AM, Thomas Adam wrote: > Hi, > > On Tue, Feb 01, 2011 at 03:09:33AM -0500, Ryan Flannery wrote: >> Hi all, >> >> This diff adds support for the WM_COMMAND atom that will allow >> tabbed-like applications (I'm working on a new one) to re-launch >> instance(s) of vimprobable with the current URI's they have loaded. > > Funnily enough, so am I. ?Email me off list, perhaps we can pull resources? Sent. > With regards to WM_COMMAND, this looks OK. ?I can't say I care much for the > idea either way, but... After some playing, I agree. I'm now thinking there should just be an atom with the URI, or something similar, as storing the window-xid obviously doesn't work between re-starts of the tabbed-like program. >> ?#include >> +#include >> ?#include "includes.h" >> ?#include "vimprobable.h" >> ?#include "utilities.h" >> @@ -72,6 +73,7 @@ static gboolean zoom(const Arg *arg); >> ?static gboolean fake_key_event(const Arg *arg); >> >> ?static void update_url(const char *uri); >> +static void update_wm_command(const char *uri); >> ?static void setup_modkeys(void); >> ?static void setup_gui(void); >> ?static void setup_settings(void); >> @@ -121,6 +123,7 @@ static char current_modkey; >> ?static char *search_handle; >> ?static gboolean search_direction; >> ?static gboolean echo_active = TRUE; >> +static gboolean gui_setup_complete = FALSE; > > I don't like this idea at all of using gui_setup_complete -- there's another > way, surely? I'm completely unfamiliar with GDK/GTK. I added that because accessing the GDK window before it was mapped would cause a crash since the GDK window doesn't exist until after the window is realized. Perhaps my problem was elsewhere, though. >> +void >> +update_wm_command(const char *uri) >> +{ >> + ? ? Display *xdisplay = NULL; >> + ? ? Window ? xwindow = 0; > > Why? ?Just always make xwindow equal to GDK_WINDOW_XID() That would be much easier, yes. >> + ? ? char ? ?*arg_uri; >> + ? ? char ? ?*argv[6]; >> + ? ? int ? ? ?argc; >> + >> + ? ? if (!gui_setup_complete || !uri || strlen(uri) == 0) >> + ? ? ? ? ? ? return; >> + >> + ? ? if (xdisplay == NULL && (xdisplay = XOpenDisplay(NULL)) == NULL) >> + ? ? ? ? ? ? return; > > This is a bit more fatal than just a return here -- and probably is never > going to happen anyway (because by the time setup_gui() has run, it already > can access a Display -- but even so, a fprintf(stderr, ...) wouldn't go > amiss here. Ok. >> + ? ? if (xwindow == 0) >> + ? ? ? ? ? ? xwindow = GDK_WINDOW_XID(GTK_WIDGET(window)->window); >> + > >> + ? ? if ((arg_uri = strdup(uri)) == NULL) >> + ? ? ? ? ? ? return; > > This if line might be better off after your check for strlen(uri) as it > logically follows. > >> + ? ? if (embed) { >> + ? ? ? ? ? ? argc = 4; >> + ? ? ? ? ? ? argv[0] = *args; >> + ? ? ? ? ? ? argv[1] = "-e"; >> + ? ? ? ? ? ? argv[2] = winid; >> + ? ? ? ? ? ? argv[3] = arg_uri; >> + ? ? ? ? ? ? argv[4] = NULL; >> + ? ? } else { >> + ? ? ? ? ? ? argc = 2; >> + ? ? ? ? ? ? argv[0] = *args; >> + ? ? ? ? ? ? argv[1] = arg_uri; >> + ? ? ? ? ? ? argv[2] = NULL; >> + ? ? } > > Yeah -- now we have something similar in main(); I don't like the > duplication here. Didn't see that. I would agree, but given the comment above, I don't think WM_COMMAND (and thus this) should be used anyway. >> + ? ? XSetCommand(xdisplay, xwindow, argv, argc); > > Always check the return value from XSetCommand, please. ?Don't blindly > assume it will work, because it doesn't always. ?:) > > Otherwise the rest looks OK. > Will work on another patch after some more testing/playing. Perhaps we can come up with something else that should work for tabbed-like programs. Thanks, -Ryan From mtreibton at googlemail.com Thu Feb 3 23:22:01 2011 From: mtreibton at googlemail.com (Michael Treibton) Date: Thu, 3 Feb 2011 23:22:01 +0000 Subject: [Vimprobable-users] vimprobable crash - tab complete :set Message-ID: hi all, i'm running vimprobable2 version 0.9.7.1. when i type in ":set" and press tab, sometimes i get a list of items to choose from, and sometimes vimprobable crashes. is this known and if so is it fixed? i thought maybe it wsa in my vimprobablerc file, but i moved this away and the prob still is there. tia, Michael From matto at matto.nl Fri Feb 4 11:24:37 2011 From: matto at matto.nl (Matto Fransen) Date: Fri, 4 Feb 2011 12:24:37 +0100 Subject: [Vimprobable-users] vimprobable crash - tab complete :set In-Reply-To: References: Message-ID: <20110204112436.GA1980@aspire.tradesystem.nl> Hi, On Thu, Feb 03, 2011 at 11:22:01PM +0000, Michael Treibton wrote: > i'm running vimprobable2 version 0.9.7.1. > > when i type in ":set" and press tab, sometimes i get a list of items > to choose from, and sometimes vimprobable crashes. > > is this known and if so is it fixed? i thought maybe it wsa in my > vimprobablerc file, but i moved this away and the prob still is there. I can't reproduce that here. What is interesting, is the 'sometimes' bit. That is strange behaviour. It crashes or it doens't. Perhaps you can investigate a bit more to see if you can deduct under which circumstances it crashed and under which it doesn't? Perhaps the difference in getting a list to choose from or not is caused by typing a space after :set ? Cheers, Matto -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 198 bytes Desc: Digital signature URL: From ruskie at codemages.net Fri Feb 4 11:28:06 2011 From: ruskie at codemages.net (=?UTF-8?Q?Andra=C5=BE_'ruskie'_Levstik?=) Date: Fri, 4 Feb 2011 12:28:06 +0100 (CET) Subject: [Vimprobable-users] vimprobable crash - tab complete :set In-Reply-To: <20110204112436.GA1980@aspire.tradesystem.nl> References: <20110204112436.GA1980@aspire.tradesystem.nl> Message-ID: :2011-02-03T23:22:Michael Treibton: > hi all, > > i'm running vimprobable2 version 0.9.7.1. > > when i type in ":set" and press tab, sometimes i get a list of items > to choose from, and sometimes vimprobable crashes. > > is this known and if so is it fixed? i thought maybe it wsa in my > vimprobablerc file, but i moved this away and the prob still is there. > > tia, I've had something similar though I've managed to reproduce it and Thomas Adam managed to fix it. Try the following patch to see if it helps. http://vimprobable.org/pipermail/vimprobable-users/2011-January/000609.html Regards -- Andra? 'ruskie' Levstik Source Mage GNU/Linux Games/Xorg grimoire guru Re-Alpine Coordinator http://sourceforge.net/projects/re-alpine/ Geek/Hacker/Tinker Knowledge is important, knowledge you know is priceless. Share the knowledge, build a better future for everyone. From thomas at xteddy.org Fri Feb 4 11:32:58 2011 From: thomas at xteddy.org (Thomas Adam) Date: Fri, 4 Feb 2011 11:32:58 +0000 Subject: [Vimprobable-users] vimprobable crash - tab complete :set In-Reply-To: <20110204112436.GA1980@aspire.tradesystem.nl> References: <20110204112436.GA1980@aspire.tradesystem.nl> Message-ID: <20110204113256.GB2659@abacus.soton.smoothwall.net> On Fri, Feb 04, 2011 at 12:24:37PM +0100, Matto Fransen wrote: > Hi, > > On Thu, Feb 03, 2011 at 11:22:01PM +0000, Michael Treibton wrote: > > > i'm running vimprobable2 version 0.9.7.1. > > > > when i type in ":set" and press tab, sometimes i get a list of items > > to choose from, and sometimes vimprobable crashes. > > > > is this known and if so is it fixed? i thought maybe it wsa in my > > vimprobablerc file, but i moved this away and the prob still is there. > > I can't reproduce that here. More than likely, Michael's added entries to commands[] -- see: http://vimprobable.org/pipermail/vimprobable-users/2011-January/000609.html -- Thomas Adam From mtreibton at googlemail.com Fri Feb 4 21:05:15 2011 From: mtreibton at googlemail.com (Michael Treibton) Date: Fri, 4 Feb 2011 21:05:15 +0000 Subject: [Vimprobable-users] vimprobable crash - tab complete :set In-Reply-To: References: <20110204112436.GA1980@aspire.tradesystem.nl> Message-ID: hi On 4 February 2011 11:28, Andra? 'ruskie' Levstik wrote: > http://vimprobable.org/pipermail/vimprobable-users/2011-January/000609.html thank you for the patch - this doesnt crash vp anymore! Michael From hannes at yllr.net Sat Feb 5 21:58:22 2011 From: hannes at yllr.net (Hannes =?UTF-8?B?U2Now7xsbGVy?=) Date: Sat, 5 Feb 2011 22:58:22 +0100 Subject: [Vimprobable-users] Modkey bindings Message-ID: <20110205225822.1c0f91d2@workstation> Hi, a small patch enabling users of Vimprobable2 to use Mod1 to Mod5 in their custom keybindings. Reviews or comments welcome! Hannes -------------- next part -------------- A non-text attachment was scrubbed... Name: modkey_bindings.patch Type: text/x-patch Size: 4799 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: not available URL: From thomas at xteddy.org Sat Feb 5 22:11:19 2011 From: thomas at xteddy.org (Thomas Adam) Date: Sat, 5 Feb 2011 22:11:19 +0000 Subject: [Vimprobable-users] Modkey bindings In-Reply-To: <20110205225822.1c0f91d2@workstation> References: <20110205225822.1c0f91d2@workstation> Message-ID: <20110205221118.GC8520@debian.ttn6tadam> Hi, Hannes -- On Sat, Feb 05, 2011 at 10:58:22PM +0100, Hannes Sch??ller wrote: > Hi, > > a small patch enabling users of Vimprobable2 to use Mod1 to Mod5 in > their custom keybindings. Reviews or comments welcome! Looks fine to me. > - if ((strlen(keystring) == 5 || strlen(keystring) == 6) && keystring[0] == '<' && keystring[4] == '>') { > + if ( > + ((strlen(keystring) == 5 || strlen(keystring) == 6) && keystring[0] == '<' && keystring[4] == '>') || > + ((strlen(keystring) == 6 || strlen(keystring) == 7) && keystring[0] == '<' && keystring[5] == '>') > + ) { Can we not macro this, I wonder? Might not be worth it. But it's not obvious from the above what these numbers: 5,6,7, etc., are matching. > switch (toupper(keystring[1])) { > case 'S': > search_key.mask = GDK_SHIFT_MASK; > @@ -332,21 +335,50 @@ process_mapping(char *keystring, int maprecord, char *cmd) { > case 'C': > search_key.mask = GDK_CONTROL_MASK; > break; > + case 'M': > + switch (keystring[2]) { > + case '1': > + search_key.mask = GDK_MOD1_MASK; > + break; > + case '2': > + search_key.mask = GDK_MOD2_MASK; > + break; > + case '3': > + search_key.mask = GDK_MOD3_MASK; > + break; > + case '4': > + search_key.mask = GDK_MOD4_MASK; > + break; > + case '5': > + search_key.mask = GDK_MOD5_MASK; > + break; > + } What about the default case? Presumably an error is wanted here? > - if (strlen(keystring) == 6 && keystring[1] == '<' && keystring[5] == '>') { > + if ( > + (strlen(keystring) == 6 && keystring[1] == '<' && keystring[5] == '>') || > + (strlen(keystring) == 7 && keystring[1] == '<' && keystring[6] == '>') > + ) { Same comment as above regarding a macro. Since the check is now duplicated here as well. > switch (toupper(keystring[2])) { > case 'S': > search_key.mask = GDK_SHIFT_MASK; > @@ -355,11 +387,34 @@ process_mapping(char *keystring, int maprecord, char *cmd) { > case 'C': > search_key.mask = GDK_CONTROL_MASK; > break; > + case 'M': > + switch (keystring[3]) { > + case '1': > + search_key.mask = GDK_MOD1_MASK; > + break; > + case '2': > + search_key.mask = GDK_MOD2_MASK; > + break; > + case '3': > + search_key.mask = GDK_MOD3_MASK; > + break; > + case '4': > + search_key.mask = GDK_MOD4_MASK; > + break; > + case '5': > + search_key.mask = GDK_MOD5_MASK; > + break; This looks decidely similar to the other function. Again, what about the default case? I'd say have another function, which does the above checks, to avoid the duplication, as the result is always the same anyway. Besides that, it looks useful. Thanks! -- Thomas Adam -- "It was the cruelest game I've ever played and it's played inside my head." -- "Hush The Warmth", Gorky's Zygotic Mynci. From hannes at yllr.net Sun Feb 6 10:47:37 2011 From: hannes at yllr.net (Hannes =?UTF-8?B?U2Now7xsbGVy?=) Date: Sun, 6 Feb 2011 11:47:37 +0100 Subject: [Vimprobable-users] Modkey bindings In-Reply-To: <20110205221118.GC8520@debian.ttn6tadam> References: <20110205225822.1c0f91d2@workstation> <20110205221118.GC8520@debian.ttn6tadam> Message-ID: <20110206114737.4dcd517e@workstation> Hi! Thomas Adam wrote: > On Sat, Feb 05, 2011 at 10:58:22PM +0100, Hannes Sch??ller wrote: > > - if ((strlen(keystring) == 5 || strlen(keystring) == 6) && > > keystring[0] == '<' && keystring[4] == '>') { > > + if ( > > + ((strlen(keystring) == 5 || strlen(keystring) == 6) && > > keystring[0] == '<' && keystring[4] == '>') || > > + ((strlen(keystring) == 6 || strlen(keystring) == 7) && > > keystring[0] == '<' && keystring[5] == '>') > > + ) { > > Can we not macro this, I wonder? Might not be worth it. But it's not > obvious from the above what these numbers: 5,6,7, etc., are matching. I think an explanatory comment should do the trick. > > switch (toupper(keystring[1])) { > > case 'S': > > search_key.mask = GDK_SHIFT_MASK; > > @@ -332,21 +335,50 @@ process_mapping(char *keystring, int > > maprecord, char *cmd) { case 'C': > > search_key.mask = GDK_CONTROL_MASK; > > break; > > + case 'M': > > + switch (keystring[2]) { > > + case '1': > > + search_key.mask = GDK_MOD1_MASK; > > + break; > > + case '2': > > + search_key.mask = GDK_MOD2_MASK; > > + break; > > + case '3': > > + search_key.mask = GDK_MOD3_MASK; > > + break; > > + case '4': > > + search_key.mask = GDK_MOD4_MASK; > > + break; > > + case '5': > > + search_key.mask = GDK_MOD5_MASK; > > + break; > > + } > > What about the default case? Presumably an error is wanted here? The default case is caught directly after the switch. Hannes -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: not available URL: From thomas at xteddy.org Tue Feb 15 01:20:30 2011 From: thomas at xteddy.org (Thomas Adam) Date: Tue, 15 Feb 2011 01:20:30 +0000 Subject: [Vimprobable-users] [PATCH 0/8] Allow for configurable downloadpaths Message-ID: <20110215012027.GA20825@debian.ttn6tadam> Hi all, This series changes how downloads operate, by introducing the following features: * The ability to set, at runtime, a download directory for files which can be downloaded. * The ability to always get Vimprobable to ask for a download directory via ":set promptdownload". In doing this, I've had to rejig a few things -- most notably in changing the way we handle downloads via the callback. More importantly though, the way in which the downloadpath is set now allows for tab-completion -- which operates a little bit like Vim, but stlil populates the completion window in the same way we do for other commands. I feel this is the best of both worlds. Note that this patch will not ever address running an arbitrary command to run when a download is complete. Nor will it address the ability to allow for an external downloading tool to be used insted (such as wget, or curl). Whilst this is trivial to add in the future, I don't see any real benefit to adding this. In the case of a callback per download, this can be achieved via inotify (if on Linux) or other means if on BSD. As for external commands, it's trivial to add in the future if someone requests it, but for now, I think it's redundant. Comments welcome, as always. -- Thomas Adam Thomas Adam (8): Allow for :set downloadpath Introduce complete_directories() Teach ":set" new command: downloadpath Includes for directory string matching Document downloadpath in man page Introduce promptdownload boolean setting. Allow for per-download paths to be set Document promptdownload in man page. config.h | 2 + includes.h | 7 ++- main.c | 176 +++++++++++++++++++++++++++++++++++++++++++++++++++---- main.h | 3 +- utilities.c | 73 ++++++++++++++++++++++- utilities.h | 1 + vimprobable.h | 9 +++- vimprobablerc.1 | 7 ++ 8 files changed, 263 insertions(+), 15 deletions(-) -- 1.7.2.3 From thomas at xteddy.org Tue Feb 15 01:21:04 2011 From: thomas at xteddy.org (Thomas Adam) Date: Tue, 15 Feb 2011 01:21:04 +0000 Subject: [Vimprobable-users] [PATCH 1/8] Allow for :set downloadpath Message-ID: <20110215012101.GA20833@debian.ttn6tadam> Make Vimproable understad that saving files to different locations is possible. This is achieved via: ":set downloadpatj /foo/bar" -- and if "/foo/bar" is not found, assumes the value of DOWNLOADS_PATH, which defaults to "$HOME" -- hence, misconfiguration does at least mean files can be downloaded. --- config.h | 1 + includes.h | 3 +++ main.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 50 insertions(+), 1 deletions(-) diff --git a/config.h b/config.h index e0290d3..b699113 100644 --- a/config.h +++ b/config.h @@ -176,4 +176,5 @@ static Setting browsersettings[] = { { "proxy", NULL, "", FALSE, TRUE, FALSE, FALSE }, { "scrollbars", NULL, "", FALSE, TRUE, FALSE, FALSE }, { "completioncase", NULL, "", FALSE, TRUE, FALSE, FALSE }, + { "downloadpath", NULL, "", FALSE, FALSE, FALSE, FALSE }, }; diff --git a/includes.h b/includes.h index b4ad021..00d734b 100644 --- a/includes.h +++ b/includes.h @@ -11,7 +11,10 @@ #include #include #include +#include +#include #include +#include #include #include #include diff --git a/main.c b/main.c index 95ad0cd..3cacbc1 100644 --- a/main.c +++ b/main.c @@ -93,6 +93,7 @@ gboolean process_keypress(GdkEventKey *event); void fill_suggline(char * suggline, const char * command, const char *fill_with); GtkWidget * fill_eventbox(const char * completion_line); static void mop_up(void); +static void set_download_path(char *dl_path); #include "main.h" @@ -135,6 +136,7 @@ static char followTarget[8] = ""; char *error_msg = NULL; GList *activeDownloads; +char *downloadpath; #include "config.h" #include "keymap.h" @@ -191,6 +193,39 @@ ascii_bar(int total, int state, char *string) { } #endif +/* Check validity of specified dl_path, either through :set, or more + * explicitly at the time of download. + */ +void +set_download_path(char *dl_path) +{ + struct stat dir; + + /* TA: XXX - check for write permissions as well? */ + if (dl_path == NULL || (stat(dl_path, &dir) == -1)) + { + { + char *temp_dl_path = g_strdup_printf(DOWNLOADS_PATH); + + give_feedback(g_strdup_printf("Download path \"%s\" doesn't exist, using: " + "\"%s\"", (dl_path == NULL) ? "" : dl_path, + temp_dl_path)); + + g_free(temp_dl_path); + } + downloadpath = g_strdup_printf(DOWNLOADS_PATH); + + return; + } + downloadpath = g_strdup(dl_path); + + /* TA: XXX - use SAFEFREE macro when it's merged. */ + g_free(dl_path); + + return; +} + + void webview_load_committed_cb(WebKitWebView *webview, WebKitWebFrame *frame, gpointer user_data) { Arg a = { .i = Silent, .s = JS_SETUP_HINTS }; @@ -269,11 +304,18 @@ webview_download_cb(WebKitWebView *webview, WebKitDownload *download, gpointer u uint32_t size; Arg a; + /* If there's no path to download the file, let set_download_path() decide + * for us what the default should be. This is why the parameter is NULL + * here. + */ + if (downloadpath == NULL || strlen(downloadpath) == 0) + set_download_path(NULL); + filename = webkit_download_get_suggested_filename(download); if (filename == NULL || strlen(filename) == 0) { filename = "vimprobable_download"; } - path = g_build_filename(g_strdup_printf(DOWNLOADS_PATH), filename, NULL); + path = g_build_filename(downloadpath, filename, NULL); uri = g_strconcat("file://", path, NULL); webkit_download_set_destination_uri(download, uri); g_free(uri); @@ -1740,6 +1782,9 @@ process_set_line(char *line) { if (strlen(my_pair.what) == 14 && strncmp("completioncase", my_pair.what, 14) == 0) complete_case_sensitive = boolval; + if (strlen(my_pair.what) == 12 && strncmp("downloadpath", my_pair.what, 12) == 0) + set_download_path(g_strdup(my_pair.value)); + /* reload page? */ if (browsersettings[i].reload) webkit_web_view_reload(webview); -- 1.7.2.3 From thomas at xteddy.org Tue Feb 15 01:23:00 2011 From: thomas at xteddy.org (Thomas Adam) Date: Tue, 15 Feb 2011 01:23:00 +0000 Subject: [Vimprobable-users] [PATCH 2/8] Introduce complete_directories() Message-ID: <20110215012259.GA20916@debian.ttn6tadam> Used when completing directory paths from ":set downloadpath". --- utilities.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- utilities.h | 1 + 2 files changed, 73 insertions(+), 1 deletions(-) diff --git a/utilities.c b/utilities.c index 753992e..77a4a75 100644 --- a/utilities.c +++ b/utilities.c @@ -3,7 +3,7 @@ (c) 2009, 2010 by Hannes Schueller (c) 2009, 2010 by Matto Fransen (c) 2010 by Hans-Peter Deifel - (c) 2010 by Thomas Adam + (c) 2010, 2011 by Thomas Adam see LICENSE file */ @@ -596,3 +596,74 @@ count_list(Listelement *elementlist) return n; } + +GList +*complete_directories(char *path) +{ + GList *dir_list = NULL; + GDir *dir = NULL; + const char *dir_name = NULL; + + char *base_dir_c = NULL; + char *match_dir_c = NULL; + char *base_dir = NULL; + char *match_component = NULL; + + gboolean full_scan = FALSE; + + /* If path is NULL, return. */ + if (path == NULL) + return NULL; + + /* If we have an incomplete directory path, such as: + * + * /home/xteddy/tedd + * + * And tab is pressed, we must take the dirname of what's entered, and + * tab-completed that, ensuring that "tedd" is considered a prefix for + * a match. + * + * It's a shame glib has no glob() functionality. + */ + + /* path can be modified in place -- so dup the char array here. */ + base_dir_c = g_strdup(path); + match_dir_c = g_strdup(path); + + /* Never pass these to free() as they're NUL-terminated. */ + base_dir = dirname(base_dir_c); + match_component = basename(match_dir_c); + + /* If, when combined, base_dir and match_component happen to + * form a directory, then it's safe to assume this directory + * should be scanned absolute. There are no partial matches + * needed here. + */ + if (g_file_test(g_strconcat(base_dir, "/", match_component, NULL), + G_FILE_TEST_IS_DIR)) + { + base_dir = g_strconcat(base_dir, "/", match_component, NULL); + full_scan = TRUE; + } + + if ((dir = g_dir_open(base_dir, 'r', NULL))) { + while ((dir_name = g_dir_read_name(dir))) { + char *composed_path; + + if (full_scan || g_str_has_prefix(dir_name, match_component)) { + composed_path = g_build_filename(base_dir, dir_name, NULL); + + if (g_file_test(composed_path, G_FILE_TEST_IS_DIR)) { + dir_list = g_list_append(dir_list, composed_path); + } else { + g_free(composed_path); + } + } + } + } + g_free(base_dir_c); + g_free(match_dir_c); + g_dir_close(dir); + + return g_list_sort(dir_list, (GCompareFunc)strcmp); +} diff --git a/utilities.h b/utilities.h index 261d213..99c46ce 100644 --- a/utilities.h +++ b/utilities.h @@ -30,3 +30,4 @@ Listelement * complete_list(const char *searchfor, const int mode, Listelement * Listelement * add_list(const char *element, Listelement *elementlist); int count_list(Listelement *elementlist); void free_list(Listelement *elementlist); +GList *complete_directories(char *path); -- 1.7.2.3 From thomas at xteddy.org Tue Feb 15 01:23:34 2011 From: thomas at xteddy.org (Thomas Adam) Date: Tue, 15 Feb 2011 01:23:34 +0000 Subject: [Vimprobable-users] [PATCH 3/8] Teach ":set" new command: downloadpath Message-ID: <20110215012332.GA20935@debian.ttn6tadam> This allows vimprobable to dynamically set the downloadpath for any given download, using tab-completion if necessary. --- main.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++-- main.h | 3 ++- 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/main.c b/main.c index 3cacbc1..55f74fe 100644 --- a/main.c +++ b/main.c @@ -4,7 +4,7 @@ (c) 2009, 2010 by Hannes Schueller (c) 2009, 2010 by Matto Fransen (c) 2010 by Hans-Peter Deifel - (c) 2010 by Thomas Adam + (c) 2010, 2011 by Thomas Adam see LICENSE file */ @@ -93,7 +93,6 @@ gboolean process_keypress(GdkEventKey *event); void fill_suggline(char * suggline, const char * command, const char *fill_with); GtkWidget * fill_eventbox(const char * completion_line); static void mop_up(void); -static void set_download_path(char *dl_path); #include "main.h" @@ -887,6 +886,56 @@ complete(const Arg *arg) { strncpy(command, (str + 1), spacepos - 1); if (strlen(command) == 3 && strncmp(command, "set", 3) == 0) { /* browser settings */ + if (strlen(searchfor) > 0 && strstr(searchfor, "downloadpath ")) { + char *dl_command = "set downloadpath"; + /* FIXME - we should be using glib g_* string handling + * routines here. + */ + char *tmp = strstr(searchfor, "downloadpath"); + spacepos = strcspn(tmp, " "); + searchfor = (tmp + spacepos + 1); + + /* If there's a tilda as part of the path, we must interpolate + * that out to mean $HOME. We have to do this here, + * so that the input string is transformed when we + * come to match directories in complete_directories() + */ + { + if ((strchr(searchfor, '~') != NULL)) + { + char **tmp_split_str = g_strsplit(searchfor, "~", -1); + char *home_dir = getenv("HOME"); + + /* Shouldn't happen. */ + if (home_dir == NULL) + { + set_error("Home directory invalid."); + return FALSE; + } + + if (tmp_split_str != NULL) { + searchfor = g_strjoinv(home_dir, tmp_split_str); + g_free(tmp_split_str); + } + } + } + + GList *path_items = complete_directories(searchfor); + for (; path_items; path_items = path_items->next) + { + fill_suggline(suggline, dl_command, (char *)path_items->data); + suggurls[n] = (char *)malloc(sizeof(char) * 1024 + 1); + strncpy(suggurls[n], suggline, 1024); + suggestions[n] = suggurls[n]; + row_eventbox = fill_eventbox(suggline); + gtk_box_pack_start(_table, GTK_WIDGET(row_eventbox), FALSE, FALSE, 0); + widgets[n++] = row_eventbox; + if (n >= MAX_LIST_SIZE) + break; + } + g_list_free(path_items); + } + listlen = LENGTH(browsersettings); for (i = 0; i < listlen; i++) { if (n < MAX_LIST_SIZE && strstr(browsersettings[i].name, searchfor) != NULL) { diff --git a/main.h b/main.h index fbda6a5..5816fde 100644 --- a/main.h +++ b/main.h @@ -3,7 +3,7 @@ (c) 2009, 2010 by Hannes Schueller (c) 2009, 2010 by Matto Fransen (c) 2010 by Hans-Peter Deifel - (c) 2010 by Thomas Adam + (c) 2010, 2011 by Thomas Adam see LICENSE file */ @@ -12,3 +12,4 @@ void update_state(void); gboolean process_line(char *line); gboolean echo(const Arg *arg); char * search_word(int whichword); +void set_download_path(char *dl_path); -- 1.7.2.3 From thomas at xteddy.org Tue Feb 15 01:24:44 2011 From: thomas at xteddy.org (Thomas Adam) Date: Tue, 15 Feb 2011 01:24:44 +0000 Subject: [Vimprobable-users] [PATCH 4/8] Includes for directory string matching Message-ID: <20110215012430.GA20946@debian.ttn6tadam> Needed libraries for directory completion. --- includes.h | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-) diff --git a/includes.h b/includes.h index 00d734b..e4b682f 100644 --- a/includes.h +++ b/includes.h @@ -3,7 +3,7 @@ (c) 2009, 2010 by Hannes Schueller (c) 2009, 2010 by Matto Fransen (c) 2010 by Hans-Peter Deifel - (c) 2010 by Thomas Adam + (c) 2010, 2011 by Thomas Adam see LICENSE file */ @@ -20,3 +20,5 @@ #include #include #include +#include +#include -- 1.7.2.3 From thomas at xteddy.org Tue Feb 15 01:25:16 2011 From: thomas at xteddy.org (Thomas Adam) Date: Tue, 15 Feb 2011 01:25:16 +0000 Subject: [Vimprobable-users] [PATCH 5/8] Document downloadpath in man page Message-ID: <20110215012513.GA20954@debian.ttn6tadam> Add a note to the Vimprobale man page that downloadpath exists. --- vimprobablerc.1 | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) diff --git a/vimprobablerc.1 b/vimprobablerc.1 index 6494ff8..bef07a9 100644 --- a/vimprobablerc.1 +++ b/vimprobablerc.1 @@ -59,6 +59,9 @@ their default value. .IP completioncase=[true|false] Case sensitive (true) or insensitive tab completion. +.IP downloadpath=path +Sets the location (path) where Vimprobalbe will store downloads. + .IP homepage=URL Set the URL of the homepage. -- 1.7.2.3 From thomas at xteddy.org Tue Feb 15 01:25:47 2011 From: thomas at xteddy.org (Thomas Adam) Date: Tue, 15 Feb 2011 01:25:47 +0000 Subject: [Vimprobable-users] [PATCH 6/8] Introduce promptdownload boolean setting. Message-ID: <20110215012544.GA20963@debian.ttn6tadam> Used to always be prompted for file downloads, so that the download directory can be set. --- config.h | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/config.h b/config.h index b699113..a40ea33 100644 --- a/config.h +++ b/config.h @@ -177,4 +177,5 @@ static Setting browsersettings[] = { { "scrollbars", NULL, "", FALSE, TRUE, FALSE, FALSE }, { "completioncase", NULL, "", FALSE, TRUE, FALSE, FALSE }, { "downloadpath", NULL, "", FALSE, FALSE, FALSE, FALSE }, + { "promptdownload", NULL, "", FALSE, TRUE, FALSE, FALSE }, }; -- 1.7.2.3 From thomas at xteddy.org Tue Feb 15 01:26:28 2011 From: thomas at xteddy.org (Thomas Adam) Date: Tue, 15 Feb 2011 01:26:28 +0000 Subject: [Vimprobable-users] [PATCH 7/8] Allow for per-download paths to be set Message-ID: <20110215012626.GA20971@debian.ttn6tadam> This introduces a Download struct for handling the meta data surrounding downloads. In the case of promptdownload being set to true, we must maintain the state of the download before we prompt the user for the path. This also extends logically to "automatic" downloads, that is, with promptdownload set to false. --- main.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++--------- vimprobable.h | 9 +++++- 2 files changed, 83 insertions(+), 16 deletions(-) diff --git a/main.c b/main.c index 55f74fe..d15250b 100644 --- a/main.c +++ b/main.c @@ -88,6 +88,7 @@ static gboolean process_set_line(char *line); void save_command_history(char *line); void toggle_proxy(gboolean onoff); void toggle_scrollbars(gboolean onoff); +void start_download(void); gboolean process_keypress(GdkEventKey *event); void fill_suggline(char * suggline, const char * command, const char *fill_with); @@ -121,6 +122,7 @@ static char current_modkey; static char *search_handle; static gboolean search_direction; static gboolean echo_active = TRUE; +static gboolean prompt_download = FALSE; WebKitWebInspector *inspector; static GdkNativeWindow embed = 0; @@ -134,8 +136,7 @@ static char chars[65] = "0000000000000000000000000000000000000000000000000000000 static char followTarget[8] = ""; char *error_msg = NULL; -GList *activeDownloads; -char *downloadpath; +static DownloadInfo dl_info; #include "config.h" #include "keymap.h" @@ -212,15 +213,20 @@ set_download_path(char *dl_path) g_free(temp_dl_path); } - downloadpath = g_strdup_printf(DOWNLOADS_PATH); + dl_info.downloadpath = g_strdup_printf(DOWNLOADS_PATH); return; } - downloadpath = g_strdup(dl_path); + dl_info.downloadpath = g_strdup(dl_path); /* TA: XXX - use SAFEFREE macro when it's merged. */ g_free(dl_path); + if (dl_info.waiting_for_download) { + dl_info.waiting_for_download = FALSE; + start_download(); + } + return; } @@ -298,23 +304,49 @@ inspector_inspect_web_view_cb(gpointer inspector, WebKitWebView* web_view) { gboolean webview_download_cb(WebKitWebView *webview, WebKitDownload *download, gpointer user_data) { + + dl_info.wk_download = download; + if (prompt_download && !dl_info.waiting_for_download) + { + Arg dload = { .s = g_strdup_printf(":set downloadpath %s", + dl_info.downloadpath == NULL ? "" : dl_info.downloadpath) }; + Arg a = { .i = ModeDownload }; + + set(&a); + input(&dload); + + if (dload.s) + g_free(dload.s); + + dl_info.waiting_for_download = TRUE; + } else + start_download(); + + return TRUE; +} + +void +start_download(void) { const gchar *filename; gchar *uri, *path; uint32_t size; Arg a; + WebKitDownload *download = dl_info.wk_download; + /* If there's no path to download the file, let set_download_path() decide * for us what the default should be. This is why the parameter is NULL * here. */ - if (downloadpath == NULL || strlen(downloadpath) == 0) + if (dl_info.downloadpath == NULL || strlen(dl_info.downloadpath) == 0) set_download_path(NULL); + /* FIXME -- This clobbers existing files!! */ filename = webkit_download_get_suggested_filename(download); if (filename == NULL || strlen(filename) == 0) { filename = "vimprobable_download"; } - path = g_build_filename(downloadpath, filename, NULL); + path = g_build_filename(dl_info.downloadpath, filename, NULL); uri = g_strconcat("file://", path, NULL); webkit_download_set_destination_uri(download, uri); g_free(uri); @@ -325,11 +357,13 @@ webview_download_cb(WebKitWebView *webview, WebKitDownload *download, gpointer u else a.s = g_strdup_printf("Download %s started (unknown size)...", filename); echo(&a); - activeDownloads = g_list_prepend(activeDownloads, download); + dl_info.activeDownloads = g_list_prepend(dl_info.activeDownloads, download); g_signal_connect(download, "notify::progress", G_CALLBACK(download_progress), NULL); g_signal_connect(download, "notify::status", G_CALLBACK(download_progress), NULL); + + webkit_download_start(download); + update_state(); - return TRUE; } void @@ -346,8 +380,10 @@ download_progress(WebKitDownload *d, GParamSpec *pspec) { a.i = Info; a.s = g_strdup_printf("Download %s finished", webkit_download_get_suggested_filename(d)); echo(&a); + + dl_info.waiting_for_download = FALSE; } - activeDownloads = g_list_remove(activeDownloads, d); + dl_info.activeDownloads = g_list_remove(dl_info.activeDownloads, d); } update_state(); } @@ -933,7 +969,16 @@ complete(const Arg *arg) { if (n >= MAX_LIST_SIZE) break; } - g_list_free(path_items); + /* Free any items in this list. */ + { + GList *tmp; + for( tmp = path_items; tmp; tmp = tmp->next) + if (tmp->data) + g_free(tmp->data); + + g_list_free(path_items); + g_free(tmp); + } } listlen = LENGTH(browsersettings); @@ -1338,7 +1383,8 @@ set(const Arg *arg) { } gtk_entry_set_text(GTK_ENTRY(inputbox), ""); gtk_widget_grab_focus(GTK_WIDGET(webview)); - break; + dl_info.waiting_for_download = FALSE; + break; case ModePassThrough: a.s = g_strdup("-- PASS THROUGH --"); echo(&a); @@ -1358,6 +1404,9 @@ set(const Arg *arg) { a.s = "vimprobable_show_hints()"; script(&a); break; + case ModeDownload: + dl_info.waiting_for_download = TRUE; + break; default: return TRUE; } @@ -1834,6 +1883,9 @@ process_set_line(char *line) { if (strlen(my_pair.what) == 12 && strncmp("downloadpath", my_pair.what, 12) == 0) set_download_path(g_strdup(my_pair.value)); + if (strlen(my_pair.what) == 14 && strncmp("promptdownload", my_pair.what, 14) == 0) + prompt_download = boolval; + /* reload page? */ if (browsersettings[i].reload) webkit_web_view_reload(webview); @@ -2007,7 +2059,7 @@ update_url(const char *uri) { void update_state() { char *markup; - int download_count = g_list_length(activeDownloads); + int download_count = g_list_length(dl_info.activeDownloads); GString *status = g_string_new(""); /* construct the status line */ @@ -2018,7 +2070,7 @@ update_state() { if (inputBuffer[0]) g_string_append_printf(status, " %s", inputBuffer); /* the number of active downloads */ - if (activeDownloads) { + if (dl_info.activeDownloads) { g_string_append_printf(status, " %d active %s", download_count, (download_count == 1) ? "download" : "downloads"); } @@ -2029,11 +2081,11 @@ update_state() { int progress = -1; char progressbar[progressbartick + 1]; - if (activeDownloads) { + if (dl_info.activeDownloads) { progress = 0; GList *ptr; - for (ptr = activeDownloads; ptr; ptr = g_list_next(ptr)) { + for (ptr = dl_info.activeDownloads; ptr; ptr = g_list_next(ptr)) { progress += 100 * webkit_download_get_progress(ptr->data); } @@ -2354,6 +2406,14 @@ mop_up(void) { if (cookie_store) g_free(cookie_store); #endif + + /* In the case of downloads, ensure we tear down any members allocated + * on the heap. + */ + { + if (dl_info.downloadpath) + g_free(dl_info.downloadpath); + } return; } diff --git a/vimprobable.h b/vimprobable.h index 72fe819..ee74a6f 100644 --- a/vimprobable.h +++ b/vimprobable.h @@ -11,7 +11,7 @@ #define LENGTH(x) (sizeof(x)/sizeof(x[0])) /* enums */ -enum { ModeNormal, ModePassThrough, ModeSendKey, ModeInsert, ModeHints }; /* modes */ +enum { ModeNormal, ModePassThrough, ModeSendKey, ModeInsert, ModeHints, ModeDownload }; /* modes */ enum { TargetCurrent, TargetNew }; /* target */ /* bitmask, 1 << 0: 0 = jumpTo, 1 = scroll @@ -148,6 +148,13 @@ typedef struct { char element[255]; } Listelement; +typedef struct { + char *downloadpath; + gboolean waiting_for_download; + GList *activeDownloads; + WebKitDownload *wk_download; +} DownloadInfo; + /* constants */ #define MOUSE_BUTTON_1 1 #define MOUSE_BUTTON_2 2 -- 1.7.2.3 From thomas at xteddy.org Tue Feb 15 01:27:05 2011 From: thomas at xteddy.org (Thomas Adam) Date: Tue, 15 Feb 2011 01:27:05 +0000 Subject: [Vimprobable-users] [PATCH 8/8] Document promptdownload in man page. Message-ID: <20110215012702.GA20986@debian.ttn6tadam> Add a note explaining what promptdownload does. --- vimprobablerc.1 | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-) diff --git a/vimprobablerc.1 b/vimprobablerc.1 index bef07a9..0bba864 100644 --- a/vimprobablerc.1 +++ b/vimprobablerc.1 @@ -62,6 +62,10 @@ Case sensitive (true) or insensitive tab completion. .IP downloadpath=path Sets the location (path) where Vimprobalbe will store downloads. +.IP promptdownload=[true|false] +Instructs Vimprobable to always prompt for the location of the file to be +downloaded. + .IP homepage=URL Set the URL of the homepage. -- 1.7.2.3 From thomas at xteddy.org Tue Feb 15 14:33:57 2011 From: thomas at xteddy.org (Thomas Adam) Date: Tue, 15 Feb 2011 14:33:57 +0000 Subject: [Vimprobable-users] [PATCH 5/8] Document downloadpath in man page In-Reply-To: <20110215012513.GA20954@debian.ttn6tadam> References: <20110215012513.GA20954@debian.ttn6tadam> Message-ID: <20110215143353.GA3539@abacus.soton.smoothwall.net> On Tue, Feb 15, 2011 at 01:25:16AM +0000, Thomas Adam wrote: > Add a note to the Vimprobale man page that downloadpath exists. > --- > vimprobablerc.1 | 3 +++ > 1 files changed, 3 insertions(+), 0 deletions(-) > > diff --git a/vimprobablerc.1 b/vimprobablerc.1 > index 6494ff8..bef07a9 100644 > --- a/vimprobablerc.1 > +++ b/vimprobablerc.1 > @@ -59,6 +59,9 @@ their default value. > .IP completioncase=[true|false] > Case sensitive (true) or insensitive tab completion. > > +.IP downloadpath=path > +Sets the location (path) where Vimprobalbe will store downloads. > + > .IP homepage=URL > Set the URL of the homepage. Oops -- seems to be a lot of typos in this. I'll resend it. -- Thomas Adam From thomas at xteddy.org Tue Feb 15 19:46:26 2011 From: thomas at xteddy.org (Thomas Adam) Date: Tue, 15 Feb 2011 19:46:26 +0000 Subject: [Vimprobable-users] [PATCH V2 5/8] Document downloadpath in man page Message-ID: <20110215194620.GA3290@debian.ttn6tadam> Add a note to the Vimprobable man page that downloadpath exists. --- Fixes typos from the previous version. vimprobablerc.1 | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) diff --git a/vimprobablerc.1 b/vimprobablerc.1 index 6494ff8..5518ddf 100644 --- a/vimprobablerc.1 +++ b/vimprobablerc.1 @@ -59,6 +59,9 @@ their default value. .IP completioncase=[true|false] Case sensitive (true) or insensitive tab completion. +.IP downloadpath=path +Sets the location (path) where Vimprobable will store downloads. + .IP homepage=URL Set the URL of the homepage. -- 1.7.2.3 From hannes at yllr.net Wed Feb 16 18:53:01 2011 From: hannes at yllr.net (Hannes =?UTF-8?B?U2Now7xsbGVy?=) Date: Wed, 16 Feb 2011 19:53:01 +0100 Subject: [Vimprobable-users] [PATCH 0/8] Allow for configurable downloadpaths In-Reply-To: <20110215012027.GA20825@debian.ttn6tadam> References: <20110215012027.GA20825@debian.ttn6tadam> Message-ID: <20110216195301.71864860@workstation> After playing around with this patch a bit, I encountered the following issues: - ":set downloadpath " + tab produces unexpected results: it lists subdirectories of the current path, but with an additional iteration of ./ AND also lists all other settings, although downloadpath is already unique. - ":set downloadpath /" + tab produces unexpected results: it lists all directories under root, but with three leading slashes. In general, leading slashes are sometimes added in unexpected ways through the use of the tab key. - ":set downloadpath=/" + tab shows no completions at all. - Although there seems to be handling for this in the code, setting the path to ~ doesn't seem to work. It's handled like any invalid path. - Any reason why the boolean handling of "prompt_download" isn't defined directly in browsersettings[]? - Using "promptdownload", entering a non-existent patch will cancel the download. After that, the next download triggered by the user will automatically be started without any prompt. Mind you that this has only been a purely functional test so far. Hannes -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: not available URL: From thomas at xteddy.org Wed Feb 16 19:09:58 2011 From: thomas at xteddy.org (Thomas Adam) Date: Wed, 16 Feb 2011 19:09:58 +0000 Subject: [Vimprobable-users] [PATCH 0/8] Allow for configurable downloadpaths In-Reply-To: <20110216195301.71864860@workstation> References: <20110215012027.GA20825@debian.ttn6tadam> <20110216195301.71864860@workstation> Message-ID: <20110216190955.GB1938@debian.ttn6tadam> On Wed, Feb 16, 2011 at 07:53:01PM +0100, Hannes Sch??ller wrote: > After playing around with this patch a bit, I encountered the following > issues: > > - ":set downloadpath " + tab produces unexpected results: it lists > subdirectories of the current path, but with an additional iteration > of ./ AND also lists all other settings, although downloadpath is > already unique. Fixed. But note that this entire processing is one ugly hack due to how the current completion works for ":set" commands. I might clean this up in the future, but it will look nasty most likely. > - ":set downloadpath /" + tab produces unexpected results: it lists all > directories under root, but with three leading slashes. In general, > leading slashes are sometimes added in unexpected ways through the > use of the tab key. Cosmetic only -- it's to do with not having to sanitise the input for looking for ending '/', etc. Fixed. > - ":set downloadpath=/" + tab shows no completions at all. Not surprised. Will fix. > - Although there seems to be handling for this in the code, setting the > path to ~ doesn't seem to work. It's handled like any invalid path. What works: ":set downloadpath ~" ":set downloadpath ~/" ":set downloadpath ~/start-of-a-known-dir" What won't work: ":set downloadpath /foo/~" ":set downloadpath ~/start-of-a-non-existant-dir" ":set downloadpath ~~~~~" I the cases for those which don't work, I think that's acceptable. If you're referring though to adding this in your vimprobablerc file, that's different. Fixed. > - Any reason why the boolean handling of "prompt_download" isn't > defined directly in browsersettings[]? Probably; can't remember. > - Using "promptdownload", entering a non-existent patch will cancel the > download. After that, the next download triggered by the user will > automatically be started without any prompt. Fixed. > Mind you that this has only been a purely functional test so far. Sure, no problem. I'll resend everything in a bit. Thanks for looking at it. -- Thomas Adam -- "It was the cruelest game I've ever played and it's played inside my head." -- "Hush The Warmth", Gorky's Zygotic Mynci. From thomas at xteddy.org Thu Feb 17 03:06:53 2011 From: thomas at xteddy.org (Thomas Adam) Date: Thu, 17 Feb 2011 03:06:53 +0000 Subject: [Vimprobable-users] [PATCH V2 00/10] Allow for configurable downloadpaths Message-ID: <20110217030650.GA13671@debian.ttn6tadam> Hi all, Hopefully addresses most of Hannes' observations. Sufficiently different from V1 in enough places that I'm re-rolling the whole series. Those playing along at home can get the same thing here: https://github.com/ThomasAdam/vimprobable/tree/ta/runtime-download-path Enjoy. Thomas Adam (10): Allow for :set downloadpath Introduce complete_directories() Teach ":set" new command: downloadpath Includes for directory string matching Document downloadpath in man page Introduce promptdownload boolean setting. Allow for per-download paths to be set Document promptdownload in man page. Introduce __expand_path() Introduce __canonicalise_dir_path() for tab-completion config.h | 2 + includes.h | 7 ++- main.c | 221 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- main.h | 3 +- utilities.c | 120 +++++++++++++++++++++++++++++- utilities.h | 1 + vimprobable.h | 10 ++- vimprobablerc.1 | 7 ++ 8 files changed, 356 insertions(+), 15 deletions(-) -- 1.7.2.3 From thomas at xteddy.org Thu Feb 17 03:07:18 2011 From: thomas at xteddy.org (Thomas Adam) Date: Thu, 17 Feb 2011 03:07:18 +0000 Subject: [Vimprobable-users] [PATCH V2 01/10] Allow for :set downloadpath Message-ID: <20110217030715.GA13695@debian.ttn6tadam> Make Vimproable understad that saving files to different locations is possible. This is achieved via: ":set downloadpatj /foo/bar" -- and if "/foo/bar" is not found, assumes the value of DOWNLOADS_PATH, which defaults to "$HOME" -- hence, misconfiguration does at least mean files can be downloaded. --- config.h | 1 + includes.h | 3 +++ main.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 50 insertions(+), 1 deletions(-) diff --git a/config.h b/config.h index e0290d3..b699113 100644 --- a/config.h +++ b/config.h @@ -176,4 +176,5 @@ static Setting browsersettings[] = { { "proxy", NULL, "", FALSE, TRUE, FALSE, FALSE }, { "scrollbars", NULL, "", FALSE, TRUE, FALSE, FALSE }, { "completioncase", NULL, "", FALSE, TRUE, FALSE, FALSE }, + { "downloadpath", NULL, "", FALSE, FALSE, FALSE, FALSE }, }; diff --git a/includes.h b/includes.h index b4ad021..00d734b 100644 --- a/includes.h +++ b/includes.h @@ -11,7 +11,10 @@ #include #include #include +#include +#include #include +#include #include #include #include diff --git a/main.c b/main.c index 95ad0cd..3cacbc1 100644 --- a/main.c +++ b/main.c @@ -93,6 +93,7 @@ gboolean process_keypress(GdkEventKey *event); void fill_suggline(char * suggline, const char * command, const char *fill_with); GtkWidget * fill_eventbox(const char * completion_line); static void mop_up(void); +static void set_download_path(char *dl_path); #include "main.h" @@ -135,6 +136,7 @@ static char followTarget[8] = ""; char *error_msg = NULL; GList *activeDownloads; +char *downloadpath; #include "config.h" #include "keymap.h" @@ -191,6 +193,39 @@ ascii_bar(int total, int state, char *string) { } #endif +/* Check validity of specified dl_path, either through :set, or more + * explicitly at the time of download. + */ +void +set_download_path(char *dl_path) +{ + struct stat dir; + + /* TA: XXX - check for write permissions as well? */ + if (dl_path == NULL || (stat(dl_path, &dir) == -1)) + { + { + char *temp_dl_path = g_strdup_printf(DOWNLOADS_PATH); + + give_feedback(g_strdup_printf("Download path \"%s\" doesn't exist, using: " + "\"%s\"", (dl_path == NULL) ? "" : dl_path, + temp_dl_path)); + + g_free(temp_dl_path); + } + downloadpath = g_strdup_printf(DOWNLOADS_PATH); + + return; + } + downloadpath = g_strdup(dl_path); + + /* TA: XXX - use SAFEFREE macro when it's merged. */ + g_free(dl_path); + + return; +} + + void webview_load_committed_cb(WebKitWebView *webview, WebKitWebFrame *frame, gpointer user_data) { Arg a = { .i = Silent, .s = JS_SETUP_HINTS }; @@ -269,11 +304,18 @@ webview_download_cb(WebKitWebView *webview, WebKitDownload *download, gpointer u uint32_t size; Arg a; + /* If there's no path to download the file, let set_download_path() decide + * for us what the default should be. This is why the parameter is NULL + * here. + */ + if (downloadpath == NULL || strlen(downloadpath) == 0) + set_download_path(NULL); + filename = webkit_download_get_suggested_filename(download); if (filename == NULL || strlen(filename) == 0) { filename = "vimprobable_download"; } - path = g_build_filename(g_strdup_printf(DOWNLOADS_PATH), filename, NULL); + path = g_build_filename(downloadpath, filename, NULL); uri = g_strconcat("file://", path, NULL); webkit_download_set_destination_uri(download, uri); g_free(uri); @@ -1740,6 +1782,9 @@ process_set_line(char *line) { if (strlen(my_pair.what) == 14 && strncmp("completioncase", my_pair.what, 14) == 0) complete_case_sensitive = boolval; + if (strlen(my_pair.what) == 12 && strncmp("downloadpath", my_pair.what, 12) == 0) + set_download_path(g_strdup(my_pair.value)); + /* reload page? */ if (browsersettings[i].reload) webkit_web_view_reload(webview); -- 1.7.2.3 From thomas at xteddy.org Thu Feb 17 03:07:38 2011 From: thomas at xteddy.org (Thomas Adam) Date: Thu, 17 Feb 2011 03:07:38 +0000 Subject: [Vimprobable-users] [PATCH V2 02/10] Introduce complete_directories() Message-ID: <20110217030736.GA13703@debian.ttn6tadam> Used when completing directory paths from ":set downloadpath". --- utilities.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- utilities.h | 1 + 2 files changed, 73 insertions(+), 1 deletions(-) diff --git a/utilities.c b/utilities.c index 753992e..77a4a75 100644 --- a/utilities.c +++ b/utilities.c @@ -3,7 +3,7 @@ (c) 2009, 2010 by Hannes Schueller (c) 2009, 2010 by Matto Fransen (c) 2010 by Hans-Peter Deifel - (c) 2010 by Thomas Adam + (c) 2010, 2011 by Thomas Adam see LICENSE file */ @@ -596,3 +596,74 @@ count_list(Listelement *elementlist) return n; } + +GList +*complete_directories(char *path) +{ + GList *dir_list = NULL; + GDir *dir = NULL; + const char *dir_name = NULL; + + char *base_dir_c = NULL; + char *match_dir_c = NULL; + char *base_dir = NULL; + char *match_component = NULL; + + gboolean full_scan = FALSE; + + /* If path is NULL, return. */ + if (path == NULL) + return NULL; + + /* If we have an incomplete directory path, such as: + * + * /home/xteddy/tedd + * + * And tab is pressed, we must take the dirname of what's entered, and + * tab-completed that, ensuring that "tedd" is considered a prefix for + * a match. + * + * It's a shame glib has no glob() functionality. + */ + + /* path can be modified in place -- so dup the char array here. */ + base_dir_c = g_strdup(path); + match_dir_c = g_strdup(path); + + /* Never pass these to free() as they're NUL-terminated. */ + base_dir = dirname(base_dir_c); + match_component = basename(match_dir_c); + + /* If, when combined, base_dir and match_component happen to + * form a directory, then it's safe to assume this directory + * should be scanned absolute. There are no partial matches + * needed here. + */ + if (g_file_test(g_strconcat(base_dir, "/", match_component, NULL), + G_FILE_TEST_IS_DIR)) + { + base_dir = g_strconcat(base_dir, "/", match_component, NULL); + full_scan = TRUE; + } + + if ((dir = g_dir_open(base_dir, 'r', NULL))) { + while ((dir_name = g_dir_read_name(dir))) { + char *composed_path; + + if (full_scan || g_str_has_prefix(dir_name, match_component)) { + composed_path = g_build_filename(base_dir, dir_name, NULL); + + if (g_file_test(composed_path, G_FILE_TEST_IS_DIR)) { + dir_list = g_list_append(dir_list, composed_path); + } else { + g_free(composed_path); + } + } + } + } + g_free(base_dir_c); + g_free(match_dir_c); + g_dir_close(dir); + + return g_list_sort(dir_list, (GCompareFunc)strcmp); +} diff --git a/utilities.h b/utilities.h index 261d213..99c46ce 100644 --- a/utilities.h +++ b/utilities.h @@ -30,3 +30,4 @@ Listelement * complete_list(const char *searchfor, const int mode, Listelement * Listelement * add_list(const char *element, Listelement *elementlist); int count_list(Listelement *elementlist); void free_list(Listelement *elementlist); +GList *complete_directories(char *path); -- 1.7.2.3 From thomas at xteddy.org Thu Feb 17 03:07:55 2011 From: thomas at xteddy.org (Thomas Adam) Date: Thu, 17 Feb 2011 03:07:55 +0000 Subject: [Vimprobable-users] [PATCH V2 03/10] Teach ":set" new command: downloadpath Message-ID: <20110217030752.GA13712@debian.ttn6tadam> This allows vimprobable to dynamically set the downloadpath for any given download, using tab-completion if necessary. --- main.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- main.h | 3 +- 2 files changed, 78 insertions(+), 3 deletions(-) diff --git a/main.c b/main.c index 3cacbc1..87eab20 100644 --- a/main.c +++ b/main.c @@ -4,7 +4,7 @@ (c) 2009, 2010 by Hannes Schueller (c) 2009, 2010 by Matto Fransen (c) 2010 by Hans-Peter Deifel - (c) 2010 by Thomas Adam + (c) 2010, 2011 by Thomas Adam see LICENSE file */ @@ -93,7 +93,6 @@ gboolean process_keypress(GdkEventKey *event); void fill_suggline(char * suggline, const char * command, const char *fill_with); GtkWidget * fill_eventbox(const char * completion_line); static void mop_up(void); -static void set_download_path(char *dl_path); #include "main.h" @@ -887,6 +886,81 @@ complete(const Arg *arg) { strncpy(command, (str + 1), spacepos - 1); if (strlen(command) == 3 && strncmp(command, "set", 3) == 0) { /* browser settings */ + if (strlen(searchfor) > 0 && strstr(searchfor, "downloadpath")) { + char *dl_command = "set downloadpath"; + /* FIXME - we should be using glib g_* string handling + * routines here. + */ + char *tmp = strstr(searchfor, "downloadpath"); + spacepos = strcspn(tmp, " = "); + searchfor = (tmp + spacepos + 1); + + /* Remove any whitespace. */ + while (isspace(*searchfor) && *searchfor) + searchfor++; + + /* If we immediately have an equals sign, skip over + * it, along with potentially more whitespace. Caters + * for things like: + * + * :set downloadpath = /t + */ + if (*searchfor == '=') { + searchfor++; + while (*searchfor && + isspace(*searchfor) && + *searchfor != '=') + searchfor++; + } + + /* If there's nothing entered here, or just + * whitespace, don't try and go any further; there's + * nothing to do. + */ + if (strlen(searchfor) <= 0) + return FALSE; + + /* If there's a tilde as part of the path, we must interpolate + * that out to mean $HOME. We have to do this here, + * so that the input string is transformed when we + * come to match directories in complete_directories() + */ + { + if ((strchr(searchfor, '~') != NULL)) + { + char **tmp_split_str = g_strsplit(searchfor, "~", -1); + char *home_dir = getenv("HOME"); + + /* Shouldn't happen. */ + if (home_dir == NULL) + { + set_error("Home directory invalid."); + return FALSE; + } + + if (tmp_split_str != NULL) { + searchfor = g_strjoinv(home_dir, tmp_split_str); + g_free(tmp_split_str); + } + } + } + + GList *path_items = complete_directories(searchfor); + for (; path_items; path_items = path_items->next) + { + fill_suggline(suggline, dl_command, (char *)path_items->data); + suggurls[n] = (char *)malloc(sizeof(char) * 1024 + 1); + strncpy(suggurls[n], suggline, 1024); + suggestions[n] = suggurls[n]; + row_eventbox = fill_eventbox(suggline); + gtk_box_pack_start(_table, GTK_WIDGET(row_eventbox), FALSE, FALSE, 0); + widgets[n++] = row_eventbox; + if (n >= MAX_LIST_SIZE) + break; + } + g_list_free(path_items); + } + listlen = LENGTH(browsersettings); for (i = 0; i < listlen; i++) { if (n < MAX_LIST_SIZE && strstr(browsersettings[i].name, searchfor) != NULL) { diff --git a/main.h b/main.h index fbda6a5..5816fde 100644 --- a/main.h +++ b/main.h @@ -3,7 +3,7 @@ (c) 2009, 2010 by Hannes Schueller (c) 2009, 2010 by Matto Fransen (c) 2010 by Hans-Peter Deifel - (c) 2010 by Thomas Adam + (c) 2010, 2011 by Thomas Adam see LICENSE file */ @@ -12,3 +12,4 @@ void update_state(void); gboolean process_line(char *line); gboolean echo(const Arg *arg); char * search_word(int whichword); +void set_download_path(char *dl_path); -- 1.7.2.3 From thomas at xteddy.org Thu Feb 17 03:08:11 2011 From: thomas at xteddy.org (Thomas Adam) Date: Thu, 17 Feb 2011 03:08:11 +0000 Subject: [Vimprobable-users] [PATCH V2 04/10] Includes for directory string matching Message-ID: <20110217030809.GA13720@debian.ttn6tadam> Needed libraries for directory completion. --- includes.h | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-) diff --git a/includes.h b/includes.h index 00d734b..e4b682f 100644 --- a/includes.h +++ b/includes.h @@ -3,7 +3,7 @@ (c) 2009, 2010 by Hannes Schueller (c) 2009, 2010 by Matto Fransen (c) 2010 by Hans-Peter Deifel - (c) 2010 by Thomas Adam + (c) 2010, 2011 by Thomas Adam see LICENSE file */ @@ -20,3 +20,5 @@ #include #include #include +#include +#include -- 1.7.2.3 From thomas at xteddy.org Thu Feb 17 03:08:26 2011 From: thomas at xteddy.org (Thomas Adam) Date: Thu, 17 Feb 2011 03:08:26 +0000 Subject: [Vimprobable-users] [PATCH V2 05/10] Document downloadpath in man page Message-ID: <20110217030823.GA13728@debian.ttn6tadam> Add a note to the Vimprobable man page that downloadpath exists. --- vimprobablerc.1 | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) diff --git a/vimprobablerc.1 b/vimprobablerc.1 index 6494ff8..5518ddf 100644 --- a/vimprobablerc.1 +++ b/vimprobablerc.1 @@ -59,6 +59,9 @@ their default value. .IP completioncase=[true|false] Case sensitive (true) or insensitive tab completion. +.IP downloadpath=path +Sets the location (path) where Vimprobable will store downloads. + .IP homepage=URL Set the URL of the homepage. -- 1.7.2.3 From thomas at xteddy.org Thu Feb 17 03:08:43 2011 From: thomas at xteddy.org (Thomas Adam) Date: Thu, 17 Feb 2011 03:08:43 +0000 Subject: [Vimprobable-users] [PATCH V2 06/10] Introduce promptdownload boolean setting. Message-ID: <20110217030841.GA13737@debian.ttn6tadam> Used to always be prompted for file downloads, so that the download directory can be set. --- config.h | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/config.h b/config.h index b699113..a40ea33 100644 --- a/config.h +++ b/config.h @@ -177,4 +177,5 @@ static Setting browsersettings[] = { { "scrollbars", NULL, "", FALSE, TRUE, FALSE, FALSE }, { "completioncase", NULL, "", FALSE, TRUE, FALSE, FALSE }, { "downloadpath", NULL, "", FALSE, FALSE, FALSE, FALSE }, + { "promptdownload", NULL, "", FALSE, TRUE, FALSE, FALSE }, }; -- 1.7.2.3 From thomas at xteddy.org Thu Feb 17 03:08:58 2011 From: thomas at xteddy.org (Thomas Adam) Date: Thu, 17 Feb 2011 03:08:58 +0000 Subject: [Vimprobable-users] [PATCH V2 07/10] Allow for per-download paths to be set Message-ID: <20110217030856.GA13745@debian.ttn6tadam> This introduces a Download struct for handling the meta data surrounding downloads. In the case of promptdownload being set to true, we must maintain the state of the download before we prompt the user for the path. This also extends logically to "automatic" downloads, that is, with promptdownload set to false. --- main.c | 94 +++++++++++++++++++++++++++++++++++++++++++++++--------- vimprobable.h | 10 +++++- 2 files changed, 88 insertions(+), 16 deletions(-) diff --git a/main.c b/main.c index 87eab20..933b070 100644 --- a/main.c +++ b/main.c @@ -88,6 +88,7 @@ static gboolean process_set_line(char *line); void save_command_history(char *line); void toggle_proxy(gboolean onoff); void toggle_scrollbars(gboolean onoff); +void start_download(void); gboolean process_keypress(GdkEventKey *event); void fill_suggline(char * suggline, const char * command, const char *fill_with); @@ -121,6 +122,7 @@ static char current_modkey; static char *search_handle; static gboolean search_direction; static gboolean echo_active = TRUE; +static gboolean prompt_download = FALSE; WebKitWebInspector *inspector; static GdkNativeWindow embed = 0; @@ -134,8 +136,7 @@ static char chars[65] = "0000000000000000000000000000000000000000000000000000000 static char followTarget[8] = ""; char *error_msg = NULL; -GList *activeDownloads; -char *downloadpath; +static DownloadInfo dl_info; #include "config.h" #include "keymap.h" @@ -212,15 +213,23 @@ set_download_path(char *dl_path) g_free(temp_dl_path); } - downloadpath = g_strdup_printf(DOWNLOADS_PATH); + dl_info.downloadpath = g_strdup_printf(DOWNLOADS_PATH); + + dl_info.retry_prompt = TRUE; return; } - downloadpath = g_strdup(dl_path); + dl_info.downloadpath = g_strdup(dl_path); /* TA: XXX - use SAFEFREE macro when it's merged. */ g_free(dl_path); + if (dl_info.waiting_for_download) { + dl_info.waiting_for_download = FALSE; + dl_info.retry_prompt = FALSE; + start_download(); + } + return; } @@ -298,23 +307,50 @@ inspector_inspect_web_view_cb(gpointer inspector, WebKitWebView* web_view) { gboolean webview_download_cb(WebKitWebView *webview, WebKitDownload *download, gpointer user_data) { + + dl_info.wk_download = download; + if (dl_info.retry_prompt || + (prompt_download && !dl_info.waiting_for_download)) + { + Arg dload = { .s = g_strdup_printf(":set downloadpath %s", + dl_info.downloadpath == NULL ? "" : dl_info.downloadpath) }; + Arg a = { .i = ModeDownload }; + + set(&a); + input(&dload); + + if (dload.s) + g_free(dload.s); + + dl_info.waiting_for_download = TRUE; + } else + start_download(); + + return TRUE; +} + +void +start_download(void) { const gchar *filename; gchar *uri, *path; uint32_t size; Arg a; + WebKitDownload *download = dl_info.wk_download; + /* If there's no path to download the file, let set_download_path() decide * for us what the default should be. This is why the parameter is NULL * here. */ - if (downloadpath == NULL || strlen(downloadpath) == 0) + if (dl_info.downloadpath == NULL || strlen(dl_info.downloadpath) == 0) set_download_path(NULL); + /* FIXME -- This clobbers existing files!! */ filename = webkit_download_get_suggested_filename(download); if (filename == NULL || strlen(filename) == 0) { filename = "vimprobable_download"; } - path = g_build_filename(downloadpath, filename, NULL); + path = g_build_filename(dl_info.downloadpath, filename, NULL); uri = g_strconcat("file://", path, NULL); webkit_download_set_destination_uri(download, uri); g_free(uri); @@ -325,11 +361,13 @@ webview_download_cb(WebKitWebView *webview, WebKitDownload *download, gpointer u else a.s = g_strdup_printf("Download %s started (unknown size)...", filename); echo(&a); - activeDownloads = g_list_prepend(activeDownloads, download); + dl_info.activeDownloads = g_list_prepend(dl_info.activeDownloads, download); g_signal_connect(download, "notify::progress", G_CALLBACK(download_progress), NULL); g_signal_connect(download, "notify::status", G_CALLBACK(download_progress), NULL); + + webkit_download_start(download); + update_state(); - return TRUE; } void @@ -346,8 +384,10 @@ download_progress(WebKitDownload *d, GParamSpec *pspec) { a.i = Info; a.s = g_strdup_printf("Download %s finished", webkit_download_get_suggested_filename(d)); echo(&a); + + dl_info.waiting_for_download = FALSE; } - activeDownloads = g_list_remove(activeDownloads, d); + dl_info.activeDownloads = g_list_remove(dl_info.activeDownloads, d); } update_state(); } @@ -958,7 +998,16 @@ complete(const Arg *arg) { if (n >= MAX_LIST_SIZE) break; } - g_list_free(path_items); + /* Free any items in this list. */ + { + GList *tmp; + for( tmp = path_items; tmp; tmp = tmp->next) + if (tmp->data) + g_free(tmp->data); + + g_list_free(path_items); + g_free(tmp); + } } listlen = LENGTH(browsersettings); @@ -1363,7 +1412,8 @@ set(const Arg *arg) { } gtk_entry_set_text(GTK_ENTRY(inputbox), ""); gtk_widget_grab_focus(GTK_WIDGET(webview)); - break; + dl_info.waiting_for_download = FALSE; + break; case ModePassThrough: a.s = g_strdup("-- PASS THROUGH --"); echo(&a); @@ -1383,6 +1433,9 @@ set(const Arg *arg) { a.s = "vimprobable_show_hints()"; script(&a); break; + case ModeDownload: + dl_info.waiting_for_download = TRUE; + break; default: return TRUE; } @@ -1859,6 +1912,9 @@ process_set_line(char *line) { if (strlen(my_pair.what) == 12 && strncmp("downloadpath", my_pair.what, 12) == 0) set_download_path(g_strdup(my_pair.value)); + if (strlen(my_pair.what) == 14 && strncmp("promptdownload", my_pair.what, 14) == 0) + prompt_download = boolval; + /* reload page? */ if (browsersettings[i].reload) webkit_web_view_reload(webview); @@ -2032,7 +2088,7 @@ update_url(const char *uri) { void update_state() { char *markup; - int download_count = g_list_length(activeDownloads); + int download_count = g_list_length(dl_info.activeDownloads); GString *status = g_string_new(""); /* construct the status line */ @@ -2043,7 +2099,7 @@ update_state() { if (inputBuffer[0]) g_string_append_printf(status, " %s", inputBuffer); /* the number of active downloads */ - if (activeDownloads) { + if (dl_info.activeDownloads) { g_string_append_printf(status, " %d active %s", download_count, (download_count == 1) ? "download" : "downloads"); } @@ -2054,11 +2110,11 @@ update_state() { int progress = -1; char progressbar[progressbartick + 1]; - if (activeDownloads) { + if (dl_info.activeDownloads) { progress = 0; GList *ptr; - for (ptr = activeDownloads; ptr; ptr = g_list_next(ptr)) { + for (ptr = dl_info.activeDownloads; ptr; ptr = g_list_next(ptr)) { progress += 100 * webkit_download_get_progress(ptr->data); } @@ -2379,6 +2435,14 @@ mop_up(void) { if (cookie_store) g_free(cookie_store); #endif + + /* In the case of downloads, ensure we tear down any members allocated + * on the heap. + */ + { + if (dl_info.downloadpath) + g_free(dl_info.downloadpath); + } return; } diff --git a/vimprobable.h b/vimprobable.h index 72fe819..145a5b5 100644 --- a/vimprobable.h +++ b/vimprobable.h @@ -11,7 +11,7 @@ #define LENGTH(x) (sizeof(x)/sizeof(x[0])) /* enums */ -enum { ModeNormal, ModePassThrough, ModeSendKey, ModeInsert, ModeHints }; /* modes */ +enum { ModeNormal, ModePassThrough, ModeSendKey, ModeInsert, ModeHints, ModeDownload }; /* modes */ enum { TargetCurrent, TargetNew }; /* target */ /* bitmask, 1 << 0: 0 = jumpTo, 1 = scroll @@ -148,6 +148,14 @@ typedef struct { char element[255]; } Listelement; +typedef struct { + char *downloadpath; + gboolean waiting_for_download; + gboolean retry_prompt; + GList *activeDownloads; + WebKitDownload *wk_download; +} DownloadInfo; + /* constants */ #define MOUSE_BUTTON_1 1 #define MOUSE_BUTTON_2 2 -- 1.7.2.3 From thomas at xteddy.org Thu Feb 17 03:09:19 2011 From: thomas at xteddy.org (Thomas Adam) Date: Thu, 17 Feb 2011 03:09:19 +0000 Subject: [Vimprobable-users] [PATCH V2 08/10] Document promptdownload in man page. Message-ID: <20110217030916.GA13753@debian.ttn6tadam> Add a note explaining what promptdownload does. --- vimprobablerc.1 | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-) diff --git a/vimprobablerc.1 b/vimprobablerc.1 index 5518ddf..9e6c64b 100644 --- a/vimprobablerc.1 +++ b/vimprobablerc.1 @@ -62,6 +62,10 @@ Case sensitive (true) or insensitive tab completion. .IP downloadpath=path Sets the location (path) where Vimprobable will store downloads. +.IP promptdownload=[true|false] +Instructs Vimprobable to always prompt for the location of the file to be +downloaded. + .IP homepage=URL Set the URL of the homepage. -- 1.7.2.3 From thomas at xteddy.org Thu Feb 17 03:09:45 2011 From: thomas at xteddy.org (Thomas Adam) Date: Thu, 17 Feb 2011 03:09:45 +0000 Subject: [Vimprobable-users] [PATCH V2 09/10] Introduce __expand_path() Message-ID: <20110217030942.GA13761@debian.ttn6tadam> Expands "~" to mean $HOME. --- main.c | 82 ++++++++++++++++++++++++++++++++++++++------------------------- 1 files changed, 49 insertions(+), 33 deletions(-) diff --git a/main.c b/main.c index 933b070..c74cdba 100644 --- a/main.c +++ b/main.c @@ -89,6 +89,7 @@ void save_command_history(char *line); void toggle_proxy(gboolean onoff); void toggle_scrollbars(gboolean onoff); void start_download(void); +static char *__expand_path(const char *path); gboolean process_keypress(GdkEventKey *event); void fill_suggline(char * suggline, const char * command, const char *fill_with); @@ -199,16 +200,17 @@ ascii_bar(int total, int state, char *string) { void set_download_path(char *dl_path) { - struct stat dir; + char *expanded = __expand_path(dl_path); /* TA: XXX - check for write permissions as well? */ - if (dl_path == NULL || (stat(dl_path, &dir) == -1)) + if (dl_path == NULL || expanded == NULL || + !g_file_test(expanded, G_FILE_TEST_IS_DIR)) { { char *temp_dl_path = g_strdup_printf(DOWNLOADS_PATH); give_feedback(g_strdup_printf("Download path \"%s\" doesn't exist, using: " - "\"%s\"", (dl_path == NULL) ? "" : dl_path, + "\"%s\"", (expanded == NULL) ? "" : expanded, temp_dl_path)); g_free(temp_dl_path); @@ -219,10 +221,11 @@ set_download_path(char *dl_path) return; } - dl_info.downloadpath = g_strdup(dl_path); + dl_info.downloadpath = g_strdup(expanded); /* TA: XXX - use SAFEFREE macro when it's merged. */ g_free(dl_path); + g_free(expanded); if (dl_info.waiting_for_download) { dl_info.waiting_for_download = FALSE; @@ -233,6 +236,39 @@ set_download_path(char *dl_path) return; } +static char* +__expand_path(const char *path) +{ + char *expanded_path = g_strdup(path); + + if (path == NULL) + return NULL; + + if ((strchr(path, '~') != NULL)) + { + char **tmp_split_str = g_strsplit(path, "~", -1); + char *home_dir = getenv("HOME"); + + /* Shouldn't happen. */ + if (home_dir == NULL) { + set_error("Home directory invalid."); + + if (tmp_split_str) + g_free(tmp_split_str); + + return NULL; + } + + if (tmp_split_str) + expanded_path = g_strjoinv(home_dir, tmp_split_str); + + g_strfreev(tmp_split_str); + } + + return expanded_path; +} + + void webview_load_committed_cb(WebKitWebView *webview, WebKitWebFrame *frame, gpointer user_data) { @@ -927,7 +963,7 @@ complete(const Arg *arg) { if (strlen(command) == 3 && strncmp(command, "set", 3) == 0) { /* browser settings */ if (strlen(searchfor) > 0 && strstr(searchfor, "downloadpath")) { - char *dl_command = "set downloadpath"; + const char *dl_command = "set downloadpath"; /* FIXME - we should be using glib g_* string handling * routines here. */ @@ -953,39 +989,17 @@ complete(const Arg *arg) { searchfor++; } - /* If there's nothing entered here, or just - * whitespace, don't try and go any further; there's - * nothing to do. - */ - if (strlen(searchfor) <= 0) - return FALSE; - /* If there's a tilde as part of the path, we must interpolate * that out to mean $HOME. We have to do this here, * so that the input string is transformed when we * come to match directories in complete_directories() */ - { - if ((strchr(searchfor, '~') != NULL)) - { - char **tmp_split_str = g_strsplit(searchfor, "~", -1); - char *home_dir = getenv("HOME"); - - /* Shouldn't happen. */ - if (home_dir == NULL) - { - set_error("Home directory invalid."); - return FALSE; - } - - if (tmp_split_str != NULL) { - searchfor = g_strjoinv(home_dir, tmp_split_str); - g_free(tmp_split_str); - } - } - } + char *expanded = __expand_path(searchfor); + + if (expanded == NULL) + return FALSE; - GList *path_items = complete_directories(searchfor); + GList *path_items = complete_directories(expanded); for (; path_items; path_items = path_items->next) { fill_suggline(suggline, dl_command, (char *)path_items->data); @@ -1005,8 +1019,10 @@ complete(const Arg *arg) { if (tmp->data) g_free(tmp->data); - g_list_free(path_items); g_free(tmp); + g_list_free(path_items); + + g_free(expanded); } } -- 1.7.2.3 From thomas at xteddy.org Thu Feb 17 03:10:03 2011 From: thomas at xteddy.org (Thomas Adam) Date: Thu, 17 Feb 2011 03:10:03 +0000 Subject: [Vimprobable-users] [PATCH V2 10/10] Introduce __canonicalise_dir_path() for tab-completion Message-ID: <20110217031001.GA13769@debian.ttn6tadam> When tab-completing a path such as this: "/////home////xteddy" Ensure we strip leading separators. g_build_path() can then handle the rest for us. --- utilities.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 52 insertions(+), 5 deletions(-) diff --git a/utilities.c b/utilities.c index 77a4a75..4dde1b9 100644 --- a/utilities.c +++ b/utilities.c @@ -12,6 +12,8 @@ #include "main.h" #include "utilities.h" +static void __canonicalise_dir_path(char **base, char **match); + extern char commandhistory[COMMANDHISTSIZE][255]; extern Command commands[COMMANDSIZE]; extern int lastcommand, maxcommands, commandpointer; @@ -608,6 +610,7 @@ GList char *match_dir_c = NULL; char *base_dir = NULL; char *match_component = NULL; + char *full_path = NULL; gboolean full_scan = FALSE; @@ -630,7 +633,6 @@ GList base_dir_c = g_strdup(path); match_dir_c = g_strdup(path); - /* Never pass these to free() as they're NUL-terminated. */ base_dir = dirname(base_dir_c); match_component = basename(match_dir_c); @@ -639,10 +641,22 @@ GList * should be scanned absolute. There are no partial matches * needed here. */ - if (g_file_test(g_strconcat(base_dir, "/", match_component, NULL), - G_FILE_TEST_IS_DIR)) + + /* Using g_build_path() ensures we don't have a situation like this: + * + * //////////tmp////// + * + * Which looks ugly. + * + * But we still have to handle leading path separators ourselves. + */ + __canonicalise_dir_path(&base_dir, &match_component); + + full_path = g_build_path("/", base_dir, match_component, NULL); + + if (g_file_test(full_path, G_FILE_TEST_IS_DIR)) { - base_dir = g_strconcat(base_dir, "/", match_component, NULL); + base_dir = full_path; full_scan = TRUE; } @@ -651,7 +665,7 @@ GList char *composed_path; if (full_scan || g_str_has_prefix(dir_name, match_component)) { - composed_path = g_build_filename(base_dir, dir_name, NULL); + composed_path = g_build_path("/", base_dir, dir_name, NULL); if (g_file_test(composed_path, G_FILE_TEST_IS_DIR)) { dir_list = g_list_append(dir_list, composed_path); @@ -663,7 +677,40 @@ GList } g_free(base_dir_c); g_free(match_dir_c); + g_free(base_dir); + g_free(match_component); g_dir_close(dir); return g_list_sort(dir_list, (GCompareFunc)strcmp); } + +static void +__canonicalise_dir_path(char **base, char **match) +{ + char **base_path_tokens = g_strsplit_set(*base, "/", -1); + char **match_comp_tokens = g_strsplit_set(*match, "/", -1); + + *base = g_build_pathv("/", base_path_tokens); + *match = g_build_pathv("/", match_comp_tokens); + + /* Set both parts to "/" when we get nothing back. */ + if (base == NULL || strlen(*base) == 0) + *base = g_strdup("/"); + if (*match == NULL || strlen(*match) == 0) + *match = g_strdup("/"); + + /* In the case of "//foo", make it "/foo" because otherwise, + * our base_dir is simply "foo". + */ + if (!g_str_has_prefix(*base, "/")) + *base = g_strconcat("/", *base, NULL); + + /* If we have this "//", then set match_component to NULL -- + * full scan of "/". + */ + if (strcmp(*base, "/") == 0 && strcmp(*match, "/") == 0) + *match = NULL; + + g_strfreev(base_path_tokens); + g_strfreev(match_comp_tokens); +} -- 1.7.2.3 From hannes at yllr.net Sat Feb 19 09:25:59 2011 From: hannes at yllr.net (Hannes =?UTF-8?B?U2Now7xsbGVy?=) Date: Sat, 19 Feb 2011 10:25:59 +0100 Subject: [Vimprobable-users] [PATCH V2 01/10] Allow for :set downloadpath In-Reply-To: <20110217030715.GA13695@debian.ttn6tadam> References: <20110217030715.GA13695@debian.ttn6tadam> Message-ID: <20110219102559.35ec13f2@workstation> Thomas Adam wrote: > --- a/config.h > +++ b/config.h > @@ -176,4 +176,5 @@ static Setting browsersettings[] = { > { "proxy", NULL, "", FALSE, TRUE, FALSE, FALSE }, > { "scrollbars", NULL, "", FALSE, TRUE, FALSE, FALSE }, > { "completioncase", NULL, "", FALSE, TRUE, FALSE, FALSE }, > + { "downloadpath", NULL, "", FALSE, FALSE, FALSE, FALSE }, Again, I believe this should be + { "downloadpath", downloadpath, "", FALSE, FALSE, FALSE, FALSE }, unless you've got a good reason not to include the internal variable there for automatic handling. > @@ -191,6 +193,39 @@ ascii_bar(int total, int state, char *string) { > } > #endif > > +/* Check validity of specified dl_path, either through :set, or more > + * explicitly at the time of download. > + */ > +void > +set_download_path(char *dl_path) > +{ > + struct stat dir; > + > + /* TA: XXX - check for write permissions as well? */ I think that would indeed make sense. > + if (dl_path == NULL || (stat(dl_path, &dir) == -1)) > + { > + { > + char *temp_dl_path = g_strdup_printf(DOWNLOADS_PATH); Mixing declarations and code. > + give_feedback(g_strdup_printf("Download path \"%s\" doesn't exist, using: " > + "\"%s\"", (dl_path == NULL) ? "" : dl_path, > + temp_dl_path)); > + > + g_free(temp_dl_path); > + } > + downloadpath = g_strdup_printf(DOWNLOADS_PATH); This error handling *could* be the reason for not using the automated handling, but if so, that should be worth an explanatory comment at the very least. It should also be considered to handle this the other way around: Use the automatic handling, but overwrite it again with the default in case the desired path doesn't exist. > + > + return; > + } > + downloadpath = g_strdup(dl_path); > + > + /* TA: XXX - use SAFEFREE macro when it's merged. */ > + g_free(dl_path); Apparantely, you believe there is still something to do here. > @@ -269,11 +304,18 @@ webview_download_cb(WebKitWebView *webview, WebKitDownload *download, gpointer u > uint32_t size; > Arg a; > > + /* If there's no path to download the file, let set_download_path() decide > + * for us what the default should be. This is why the parameter is NULL > + * here. > + */ > + if (downloadpath == NULL || strlen(downloadpath) == 0) > + set_download_path(NULL); When can this case occur? It's good that you catch it, but I'm curious about the condition leading to this. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: not available URL: From hannes at yllr.net Sat Feb 19 09:33:57 2011 From: hannes at yllr.net (Hannes =?UTF-8?B?U2Now7xsbGVy?=) Date: Sat, 19 Feb 2011 10:33:57 +0100 Subject: [Vimprobable-users] [PATCH V2 02/10] Introduce complete_directories() In-Reply-To: <20110217030736.GA13703@debian.ttn6tadam> References: <20110217030736.GA13703@debian.ttn6tadam> Message-ID: <20110219103357.2963a23c@workstation> Thomas Adam wrote: > @@ -596,3 +596,74 @@ count_list(Listelement *elementlist) > > return n; > } > + > +GList > +*complete_directories(char *path) > +{ > + GList *dir_list = NULL; > + GDir *dir = NULL; > + const char *dir_name = NULL; > + > + char *base_dir_c = NULL; > + char *match_dir_c = NULL; > + char *base_dir = NULL; > + char *match_component = NULL; > + > + gboolean full_scan = FALSE; General comment: I know whitespace in the code is already pretty messy, but we should at least *try* not to make it worse. > + /* If path is NULL, return. */ > + if (path == NULL) > + return NULL; NULL being returned is caught in the calling function? > + /* path can be modified in place -- so dup the char array here. */ > + base_dir_c = g_strdup(path); > + match_dir_c = g_strdup(path); > + > + /* Never pass these to free() as they're NUL-terminated. */ ? -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: not available URL: From hannes at yllr.net Sat Feb 19 09:53:12 2011 From: hannes at yllr.net (Hannes =?UTF-8?B?U2Now7xsbGVy?=) Date: Sat, 19 Feb 2011 10:53:12 +0100 Subject: [Vimprobable-users] [PATCH V2 03/10] Teach ":set" new command: downloadpath In-Reply-To: <20110217030752.GA13712@debian.ttn6tadam> References: <20110217030752.GA13712@debian.ttn6tadam> Message-ID: <20110219105312.0b9a0778@workstation> Whitespace comment applies to this patch, too. Thomas Adam wrote: > @@ -887,6 +886,81 @@ complete(const Arg *arg) { > strncpy(command, (str + 1), spacepos - 1); > if (strlen(command) == 3 && strncmp(command, "set", 3) == 0) { > /* browser settings */ > + if (strlen(searchfor) > 0 && strstr(searchfor, "downloadpath")) { This means that we can never have a separate command command /including/ the string "downloadpath". While I agree with the sentiment that this might be bad practice anyway, we'd need a definite reminder in config.h at least. Preferably, test whether the string *starts* with "downloadpath " or "downloadpath=" here. That would be much cleaner. General comment: After my feeble attempts to clean the complete() function up a bit, you're clobbering it again now. Is this truely necessary? Path completion sounds like something we could use elsewhere, too, so splitting it into a generic function wouldn't hurt. > + char *dl_command = "set downloadpath"; > + /* FIXME - we should be using glib g_* string handling > + * routines here. > + */ > + char *tmp = strstr(searchfor, "downloadpath"); This should be unnecessary as searchfor already points to the beginning of "downloadpath" - doesn't it? > + spacepos = strcspn(tmp, " = "); Will these examples work with the above code: :set downloadpath /tmp :set downloadpath=/tmp ? > + searchfor = (tmp + spacepos + 1); > + > + /* Remove any whitespace. */ > + while (isspace(*searchfor) && *searchfor) > + searchfor++; What about whitespace at the end of the argument? Will this cause trouble? > + /* If we immediately have an equals sign, skip over > + * it, along with potentially more whitespace. Caters > + * for things like: > + * > + * :set downloadpath = /t > + */ > + if (*searchfor == '=') { > + searchfor++; > + while (*searchfor && > + isspace(*searchfor) && > + *searchfor != '=') > + searchfor++; > + } Eh... this seems pretty redundant with the code above. What am I missing? > + /* If there's a tilde as part of the path, we must interpolate > + * that out to mean $HOME. We have to do this here, > + * so that the input string is transformed when we > + * come to match directories in complete_directories() > + */ > + { > + if ((strchr(searchfor, '~') != NULL)) > + { > + char **tmp_split_str = g_strsplit(searchfor, "~", -1); > + char *home_dir = getenv("HOME"); > + > + /* Shouldn't happen. */ > + if (home_dir == NULL) > + { > + set_error("Home directory invalid."); > + return FALSE; > + } > + > + if (tmp_split_str != NULL) { > + searchfor = g_strjoinv(home_dir, tmp_split_str); > + g_free(tmp_split_str); > + } > + } > + } I think this bit is useful - could be split into a separate function (even) outside of the proposed path completion function. > + GList *path_items = complete_directories(searchfor); Mixing declaration and code. > + for (; path_items; path_items = path_items->next) > + { > + fill_suggline(suggline, dl_command, (char *)path_items->data); > + suggurls[n] = (char *)malloc(sizeof(char) * 1024 + 1); > + strncpy(suggurls[n], suggline, 1024); > + suggestions[n] = suggurls[n]; > + row_eventbox = fill_eventbox(suggline); > + gtk_box_pack_start(_table, GTK_WIDGET(row_eventbox), FALSE, FALSE, 0); > + widgets[n++] = row_eventbox; > + if (n >= MAX_LIST_SIZE) > + break; > + } > + g_list_free(path_items); > + } > + Why do you let the function continue after this? Seems like a waste of processing time and could lead to unwanted race conditions/side effects. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: not available URL: From thomas at xteddy.org Sat Feb 19 12:10:38 2011 From: thomas at xteddy.org (Thomas Adam) Date: Sat, 19 Feb 2011 12:10:38 +0000 Subject: [Vimprobable-users] [PATCH V2 01/10] Allow for :set downloadpath In-Reply-To: <20110219102559.35ec13f2@workstation> References: <20110217030715.GA13695@debian.ttn6tadam> <20110219102559.35ec13f2@workstation> Message-ID: <20110219121035.GA1903@debian.ttn6tadam> Hi, On Sat, Feb 19, 2011 at 10:25:59AM +0100, Hannes Sch??ller wrote: > Thomas Adam wrote: > > --- a/config.h > > +++ b/config.h > > @@ -176,4 +176,5 @@ static Setting browsersettings[] = { > > { "proxy", NULL, "", FALSE, TRUE, FALSE, FALSE }, > > { "scrollbars", NULL, "", FALSE, TRUE, FALSE, FALSE }, > > { "completioncase", NULL, "", FALSE, TRUE, FALSE, FALSE }, > > + { "downloadpath", NULL, "", FALSE, FALSE, FALSE, FALSE }, > > Again, I believe this should be > > + { "downloadpath", downloadpath, "", FALSE, FALSE, FALSE, FALSE }, > > unless you've got a good reason not to include the internal variable there for automatic handling. Yes, I don't need it to be stored or handled for me. > > @@ -191,6 +193,39 @@ ascii_bar(int total, int state, char *string) { > > } > > #endif > > > > +/* Check validity of specified dl_path, either through :set, or more > > + * explicitly at the time of download. > > + */ > > +void > > +set_download_path(char *dl_path) > > +{ > > + struct stat dir; > > + > > + /* TA: XXX - check for write permissions as well? */ > > I think that would indeed make sense. OK. > > + if (dl_path == NULL || (stat(dl_path, &dir) == -1)) > > + { > > + { > > + char *temp_dl_path = g_strdup_printf(DOWNLOADS_PATH); > > Mixing declarations and code. Yeah, well. :) If you mean this: char *foo; foo = bar(); Fair enough, although it is allowed by C89. > > + give_feedback(g_strdup_printf("Download path \"%s\" doesn't exist, using: " > > + "\"%s\"", (dl_path == NULL) ? "" : dl_path, > > + temp_dl_path)); > > + > > + g_free(temp_dl_path); > > + } > > + downloadpath = g_strdup_printf(DOWNLOADS_PATH); > > This error handling *could* be the reason for not using the > automated handling, but if so, that should be worth an explanatory > comment at the very least. It should also be considered to handle > this the other way around: Use the automatic handling, but overwrite > it again with the default in case the desired path doesn't exist. I'll add a comment. > > + > > + return; > > + } > > + downloadpath = g_strdup(dl_path); > > + > > + /* TA: XXX - use SAFEFREE macro when it's merged. */ > > + g_free(dl_path); > > Apparantely, you believe there is still something to do here. Yes: http://vimprobable.org/pipermail/vimprobable-users/2011-January/000602.html > > @@ -269,11 +304,18 @@ webview_download_cb(WebKitWebView *webview, WebKitDownload *download, gpointer u > > uint32_t size; > > Arg a; > > > > + /* If there's no path to download the file, let set_download_path() decide > > + * for us what the default should be. This is why the parameter is NULL > > + * here. > > + */ > > + if (downloadpath == NULL || strlen(downloadpath) == 0) > > + set_download_path(NULL); > > When can this case occur? It's good that you catch it, but I'm > curious about the condition leading to this. It probably can't. -- Thomas Adam -- "It was the cruelest game I've ever played and it's played inside my head." -- "Hush The Warmth", Gorky's Zygotic Mynci. From thomas at xteddy.org Sat Feb 19 12:15:52 2011 From: thomas at xteddy.org (Thomas Adam) Date: Sat, 19 Feb 2011 12:15:52 +0000 Subject: [Vimprobable-users] [PATCH V2 02/10] Introduce complete_directories() In-Reply-To: <20110219103357.2963a23c@workstation> References: <20110217030736.GA13703@debian.ttn6tadam> <20110219103357.2963a23c@workstation> Message-ID: <20110219121549.GB1903@debian.ttn6tadam> On Sat, Feb 19, 2011 at 10:33:57AM +0100, Hannes Sch??ller wrote: > Thomas Adam wrote: > > @@ -596,3 +596,74 @@ count_list(Listelement *elementlist) > > > > return n; > > } > > + > > +GList > > +*complete_directories(char *path) > > +{ > > + GList *dir_list = NULL; > > + GDir *dir = NULL; > > + const char *dir_name = NULL; > > + > > + char *base_dir_c = NULL; > > + char *match_dir_c = NULL; > > + char *base_dir = NULL; > > + char *match_component = NULL; > > + > > + gboolean full_scan = FALSE; > > General comment: I know whitespace in the code is already > pretty messy, but we should at least *try* not to make it worse. You'll have to tell me here what's wrong with it? It's broken with respect to the other broken whitespace, but it's just using one tab character. Is your editor converting these things to spaces? > > + /* If path is NULL, return. */ > > + if (path == NULL) > > + return NULL; > > NULL being returned is caught in the calling function? Yes. We never iterate over the GList* in complete() because there won't be one. -- Thomas Adam -- "It was the cruelest game I've ever played and it's played inside my head." -- "Hush The Warmth", Gorky's Zygotic Mynci. From hannes at yllr.net Sat Feb 19 12:19:19 2011 From: hannes at yllr.net (Hannes =?UTF-8?B?U2Now7xsbGVy?=) Date: Sat, 19 Feb 2011 13:19:19 +0100 Subject: [Vimprobable-users] [PATCH V2 01/10] Allow for :set downloadpath In-Reply-To: <20110219121035.GA1903@debian.ttn6tadam> References: <20110217030715.GA13695@debian.ttn6tadam> <20110219102559.35ec13f2@workstation> <20110219121035.GA1903@debian.ttn6tadam> Message-ID: <20110219131919.42ef7319@workstation> Hi! Thomas Adam wrote: > On Sat, Feb 19, 2011 at 10:25:59AM +0100, Hannes Sch??ller wrote: > > Thomas Adam wrote: > > > --- a/config.h > > > +++ b/config.h > > > @@ -176,4 +176,5 @@ static Setting browsersettings[] = { > > > { "proxy", NULL, "", FALSE, TRUE, FALSE, FALSE }, > > > { "scrollbars", NULL, "", FALSE, TRUE, FALSE, FALSE }, > > > { "completioncase", NULL, "", FALSE, TRUE, FALSE, FALSE }, > > > + { "downloadpath", NULL, "", FALSE, FALSE, FALSE, FALSE }, > > > > Again, I believe this should be > > > > + { "downloadpath", downloadpath, "", FALSE, FALSE, FALSE, FALSE }, > > > > unless you've got a good reason not to include the internal variable there for automatic handling. > > Yes, I don't need it to be stored or handled for me. That's like saying "I don't need printf, because I've written a replacement myself." Surely there is a *positive* reason why the generic handling isn't sufficient? Because if there isn't, running it through the regular piece of code which ensures consistency would be preferable. > > > + if (dl_path == NULL || (stat(dl_path, &dir) == -1)) > > > + { > > > + { > > > + char *temp_dl_path = g_strdup_printf(DOWNLOADS_PATH); > > > > Mixing declarations and code. > > Yeah, well. :) If you mean this: > > char *foo; > foo = bar(); > > Fair enough, although it is allowed by C89. I mean: Declarations in one block at the beginning of the function. I'm aware that what you did is legal code, but so would be writing the complete code in one line :) Hannes -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: not available URL: From hannes at yllr.net Sat Feb 19 12:20:48 2011 From: hannes at yllr.net (Hannes =?UTF-8?B?U2Now7xsbGVy?=) Date: Sat, 19 Feb 2011 13:20:48 +0100 Subject: [Vimprobable-users] [PATCH V2 02/10] Introduce complete_directories() In-Reply-To: <20110219121549.GB1903@debian.ttn6tadam> References: <20110217030736.GA13703@debian.ttn6tadam> <20110219103357.2963a23c@workstation> <20110219121549.GB1903@debian.ttn6tadam> Message-ID: <20110219132048.5f3ccdea@workstation> Hi! Thomas Adam wrote: > On Sat, Feb 19, 2011 at 10:33:57AM +0100, Hannes Sch??ller wrote: > > General comment: I know whitespace in the code is already > > pretty messy, but we should at least *try* not to make it worse. > > You'll have to tell me here what's wrong with it? It's broken with respect > to the other broken whitespace, but it's just using one tab character. Is > your editor converting these things to spaces? Currently, the source files aren't using tabs. Or shouldn't. Hannes -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: not available URL: From thomas at xteddy.org Sat Feb 19 12:26:36 2011 From: thomas at xteddy.org (Thomas Adam) Date: Sat, 19 Feb 2011 12:26:36 +0000 Subject: [Vimprobable-users] [PATCH V2 03/10] Teach ":set" new command: downloadpath In-Reply-To: <20110219105312.0b9a0778@workstation> References: <20110217030752.GA13712@debian.ttn6tadam> <20110219105312.0b9a0778@workstation> Message-ID: <20110219122634.GC1903@debian.ttn6tadam> On Sat, Feb 19, 2011 at 10:53:12AM +0100, Hannes Sch??ller wrote: > Whitespace comment applies to this patch, too. > > Thomas Adam wrote: > > @@ -887,6 +886,81 @@ complete(const Arg *arg) { > > strncpy(command, (str + 1), spacepos - 1); > > if (strlen(command) == 3 && strncmp(command, "set", 3) == 0) { > > /* browser settings */ > > + if (strlen(searchfor) > 0 && strstr(searchfor, "downloadpath")) { > > This means that we can never have a separate command command /including/ the > string "downloadpath". While I agree with the sentiment that this might > be bad practice anyway, we'd need a definite reminder in config.h at least. OK. > General comment: After my feeble attempts to clean the complete() > function up a bit, you're clobbering it again now. Is this truely > necessary? Path completion sounds like something we could use elsewhere, > too, so splitting it into a generic function wouldn't hurt. It is necessary given that we're wanting options to a ":set" command which isn't a boolean option, unfortunately. Please don't expect me to clean up complete() as part of this. That will have to wait. > > + char *dl_command = "set downloadpath"; > > + /* FIXME - we should be using glib g_* string handling > > + * routines here. > > + */ > > + char *tmp = strstr(searchfor, "downloadpath"); > > This should be unnecessary as searchfor already points to the beginning of > "downloadpath" - doesn't it? > > > + spacepos = strcspn(tmp, " = "); > > Will these examples work with the above code: > :set downloadpath /tmp > :set downloadpath=/tmp Yes. > > + searchfor = (tmp + spacepos + 1); > > + > > + /* Remove any whitespace. */ > > + while (isspace(*searchfor) && *searchfor) > > + searchfor++; > > What about whitespace at the end of the argument? Will this cause trouble? Yes. I'll fix it. > > + /* If we immediately have an equals sign, skip over > > + * it, along with potentially more whitespace. Caters > > + * for things like: > > + * > > + * :set downloadpath = /t > > + */ > > + if (*searchfor == '=') { > > + searchfor++; > > + while (*searchfor && > > + isspace(*searchfor) && > > + *searchfor != '=') > > + searchfor++; > > + } > > Eh... this seems pretty redundant with the code above. What am I missing? ":set downloadpath" ":set downloadpath " (i.e. contains a space or more space.) ":set downloadpath=" (i.e. contains an equals sign.) ":set downloadpath = " (i.e. contains whitespace and an equals sign.) ":set downloadpath= = /t" (i.e. note "downloadpath= =/t"). I am not prepared to sanitize the input much more beyond this. Note that: :set downloadpath ====/ Won't do anything for tab-completion. > > + /* If there's a tilde as part of the path, we must interpolate > > + * that out to mean $HOME. We have to do this here, > > + * so that the input string is transformed when we > > + * come to match directories in complete_directories() > > + */ > > + { > > + if ((strchr(searchfor, '~') != NULL)) > > + { > > + char **tmp_split_str = g_strsplit(searchfor, "~", -1); > > + char *home_dir = getenv("HOME"); > > + > > + /* Shouldn't happen. */ > > + if (home_dir == NULL) > > + { > > + set_error("Home directory invalid."); > > + return FALSE; > > + } > > + > > + if (tmp_split_str != NULL) { > > + searchfor = g_strjoinv(home_dir, tmp_split_str); > > + g_free(tmp_split_str); > > + } > > + } > > + } > > I think this bit is useful - could be split into a separate function > (even) outside of the proposed path completion function. Keep reading the other patches. > > + GList *path_items = complete_directories(searchfor); > > Mixing declaration and code. Again, you'd rather: char *foo; foo = bar(); Fine. > > + for (; path_items; path_items = path_items->next) > > + { > > + fill_suggline(suggline, dl_command, (char *)path_items->data); > > + suggurls[n] = (char *)malloc(sizeof(char) * 1024 + 1); > > + strncpy(suggurls[n], suggline, 1024); > > + suggestions[n] = suggurls[n]; > > + row_eventbox = fill_eventbox(suggline); > > + gtk_box_pack_start(_table, GTK_WIDGET(row_eventbox), FALSE, FALSE, 0); > > + widgets[n++] = row_eventbox; > > + if (n >= MAX_LIST_SIZE) > > + break; > > + } > > + g_list_free(path_items); > > + } > > + > > Why do you let the function continue after this? Seems like a waste of > processing time and could lead to unwanted race conditions/side effects. Not at all -- no side-effects due to the other nested if/else blocks, and more importantly, if I just blindly return here, I don't get a completion box because the code to handle that is *right* at the end of complete(). :) -- Thomas Adam -- "It was the cruelest game I've ever played and it's played inside my head." -- "Hush The Warmth", Gorky's Zygotic Mynci. From thomas at xteddy.org Sat Feb 19 12:29:19 2011 From: thomas at xteddy.org (Thomas Adam) Date: Sat, 19 Feb 2011 12:29:19 +0000 Subject: [Vimprobable-users] [PATCH V2 01/10] Allow for :set downloadpath In-Reply-To: <20110219131919.42ef7319@workstation> References: <20110217030715.GA13695@debian.ttn6tadam> <20110219102559.35ec13f2@workstation> <20110219121035.GA1903@debian.ttn6tadam> <20110219131919.42ef7319@workstation> Message-ID: <20110219122918.GD1903@debian.ttn6tadam> On Sat, Feb 19, 2011 at 01:19:19PM +0100, Hannes Sch??ller wrote: > Hi! > > Thomas Adam wrote: > > On Sat, Feb 19, 2011 at 10:25:59AM +0100, Hannes Sch??ller wrote: > > > Thomas Adam wrote: > > > > --- a/config.h > > > > +++ b/config.h > > > > @@ -176,4 +176,5 @@ static Setting browsersettings[] = { > > > > { "proxy", NULL, "", FALSE, TRUE, FALSE, FALSE }, > > > > { "scrollbars", NULL, "", FALSE, TRUE, FALSE, FALSE }, > > > > { "completioncase", NULL, "", FALSE, TRUE, FALSE, FALSE }, > > > > + { "downloadpath", NULL, "", FALSE, FALSE, FALSE, FALSE }, > > > > > > Again, I believe this should be > > > > > > + { "downloadpath", downloadpath, "", FALSE, FALSE, FALSE, FALSE }, > > > > > > unless you've got a good reason not to include the internal variable there for automatic handling. > > > > Yes, I don't need it to be stored or handled for me. > > That's like saying "I don't need printf, because I've written a replacement > myself." Surely there is a *positive* reason why the generic handling > isn't sufficient? Because if there isn't, running it through the > regular piece of code which ensures consistency would be preferable. Perhaps you were meaning "promptdownload" here (which is a bool) instead of downloadpath? Because that suddenly makes a bit more sense. > I mean: Declarations in one block at the beginning of the function. I'm > aware that what you did is legal code, but so would be writing the > complete code in one line :) I really don't like that due to the scoping of them, but sobeit. I'll correct it. -- Thomas Adam -- "It was the cruelest game I've ever played and it's played inside my head." -- "Hush The Warmth", Gorky's Zygotic Mynci. From thomas at xteddy.org Sat Feb 19 12:31:16 2011 From: thomas at xteddy.org (Thomas Adam) Date: Sat, 19 Feb 2011 12:31:16 +0000 Subject: [Vimprobable-users] [PATCH V2 02/10] Introduce complete_directories() In-Reply-To: <20110219132048.5f3ccdea@workstation> References: <20110217030736.GA13703@debian.ttn6tadam> <20110219103357.2963a23c@workstation> <20110219121549.GB1903@debian.ttn6tadam> <20110219132048.5f3ccdea@workstation> Message-ID: <20110219123115.GE1903@debian.ttn6tadam> On Sat, Feb 19, 2011 at 01:20:48PM +0100, Hannes Sch??ller wrote: > Hi! > > Thomas Adam wrote: > > On Sat, Feb 19, 2011 at 10:33:57AM +0100, Hannes Sch??ller wrote: > > > General comment: I know whitespace in the code is already > > > pretty messy, but we should at least *try* not to make it worse. > > > > You'll have to tell me here what's wrong with it? It's broken with respect > > to the other broken whitespace, but it's just using one tab character. Is > > your editor converting these things to spaces? > > Currently, the source files aren't using tabs. Or shouldn't. So you're expecting eight spaces to one tab character? In other words, I'll set "expandtab" in Vim and that should make it more standard. Remind me to buy some bleach so I can sanitise myself properly. :) -- Thomas Adam -- "It was the cruelest game I've ever played and it's played inside my head." -- "Hush The Warmth", Gorky's Zygotic Mynci. From hannes at yllr.net Sat Feb 19 12:34:18 2011 From: hannes at yllr.net (Hannes =?UTF-8?B?U2Now7xsbGVy?=) Date: Sat, 19 Feb 2011 13:34:18 +0100 Subject: [Vimprobable-users] [PATCH V2 03/10] Teach ":set" new command: downloadpath In-Reply-To: <20110219122634.GC1903@debian.ttn6tadam> References: <20110217030752.GA13712@debian.ttn6tadam> <20110219105312.0b9a0778@workstation> <20110219122634.GC1903@debian.ttn6tadam> Message-ID: <20110219133418.315f499c@workstation> Hi! Thomas Adam wrote: > On Sat, Feb 19, 2011 at 10:53:12AM +0100, Hannes Sch??ller wrote: > > General comment: After my feeble attempts to clean the complete() > > function up a bit, you're clobbering it again now. Is this truely > > necessary? Path completion sounds like something we could use elsewhere, > > too, so splitting it into a generic function wouldn't hurt. > > It is necessary given that we're wanting options to a ":set" command which > isn't a boolean option, unfortunately. > > Please don't expect me to clean up complete() as part of this. That will > have to wait. I expect you not to make things worse. > > > + /* If we immediately have an equals sign, skip over > > > + * it, along with potentially more whitespace. Caters > > > + * for things like: > > > + * > > > + * :set downloadpath = /t > > > + */ > > > + if (*searchfor == '=') { > > > + searchfor++; > > > + while (*searchfor && > > > + isspace(*searchfor) && > > > + *searchfor != '=') > > > + searchfor++; > > > + } > > > > Eh... this seems pretty redundant with the code above. What am I missing? > > ":set downloadpath" > ":set downloadpath " (i.e. contains a space or more space.) > ":set downloadpath=" (i.e. contains an equals sign.) > ":set downloadpath = " (i.e. contains whitespace and an equals sign.) > ":set downloadpath= = /t" (i.e. note "downloadpath= =/t"). > > I am not prepared to sanitize the input much more beyond this. Note that: > > :set downloadpath ====/ > > Won't do anything for tab-completion. Rightly so - it seriously shouldn't. > > > + for (; path_items; path_items = path_items->next) > > > + { > > > + fill_suggline(suggline, dl_command, (char *)path_items->data); > > > + suggurls[n] = (char *)malloc(sizeof(char) * 1024 + 1); > > > + strncpy(suggurls[n], suggline, 1024); > > > + suggestions[n] = suggurls[n]; > > > + row_eventbox = fill_eventbox(suggline); > > > + gtk_box_pack_start(_table, GTK_WIDGET(row_eventbox), FALSE, FALSE, 0); > > > + widgets[n++] = row_eventbox; > > > + if (n >= MAX_LIST_SIZE) > > > + break; > > > + } > > > + g_list_free(path_items); > > > + } > > > + > > > > Why do you let the function continue after this? Seems like a waste of > > processing time and could lead to unwanted race conditions/side effects. > > Not at all -- no side-effects due to the other nested if/else blocks, and > more importantly, if I just blindly return here, I don't get a completion > box because the code to handle that is *right* at the end of complete(). > :) Fair enough about the displaying part, but your first assumption is plainly untrue. The code iterating through the other available browser settings will be executed. *Very* nasty. Hannes -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: not available URL: From hannes at yllr.net Sat Feb 19 12:38:30 2011 From: hannes at yllr.net (Hannes =?UTF-8?B?U2Now7xsbGVy?=) Date: Sat, 19 Feb 2011 13:38:30 +0100 Subject: [Vimprobable-users] [PATCH V2 02/10] Introduce complete_directories() In-Reply-To: <20110219123115.GE1903@debian.ttn6tadam> References: <20110217030736.GA13703@debian.ttn6tadam> <20110219103357.2963a23c@workstation> <20110219121549.GB1903@debian.ttn6tadam> <20110219132048.5f3ccdea@workstation> <20110219123115.GE1903@debian.ttn6tadam> Message-ID: <20110219133830.1abbac8e@workstation> Thomas Adam wrote: > On Sat, Feb 19, 2011 at 01:20:48PM +0100, Hannes Sch??ller wrote: > > Hi! > > > > Thomas Adam wrote: > > > On Sat, Feb 19, 2011 at 10:33:57AM +0100, Hannes Sch??ller wrote: > > > > General comment: I know whitespace in the code is already > > > > pretty messy, but we should at least *try* not to make it worse. > > > > > > You'll have to tell me here what's wrong with it? It's broken with respect > > > to the other broken whitespace, but it's just using one tab character. Is > > > your editor converting these things to spaces? > > > > Currently, the source files aren't using tabs. Or shouldn't. > > So you're expecting eight spaces to one tab character? In other words, I'll > set "expandtab" in Vim and that should make it more standard. I'm expecting you not to use tabs for indentation at all. I don't want to start a discussion about tabs vs. spaces. I'm a "tabs person" myself. However, the code has been started using four spaces per indentation level and unless we convert the *whole* code, we have to stick to this. I am seriously surprised that this comes up now, after how many patches you made? Or maybe I just wasn't paying enough attention to this in the past? Hannes -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: not available URL: From thomas at xteddy.org Sat Feb 19 12:41:47 2011 From: thomas at xteddy.org (Thomas Adam) Date: Sat, 19 Feb 2011 12:41:47 +0000 Subject: [Vimprobable-users] [PATCH V2 03/10] Teach ":set" new command: downloadpath In-Reply-To: <20110219133418.315f499c@workstation> References: <20110217030752.GA13712@debian.ttn6tadam> <20110219105312.0b9a0778@workstation> <20110219122634.GC1903@debian.ttn6tadam> <20110219133418.315f499c@workstation> Message-ID: <20110219124146.GF1903@debian.ttn6tadam> On Sat, Feb 19, 2011 at 01:34:18PM +0100, Hannes Sch??ller wrote: > Hi! > > Thomas Adam wrote: > > On Sat, Feb 19, 2011 at 10:53:12AM +0100, Hannes Sch??ller wrote: > > > General comment: After my feeble attempts to clean the complete() > > > function up a bit, you're clobbering it again now. Is this truely > > > necessary? Path completion sounds like something we could use elsewhere, > > > too, so splitting it into a generic function wouldn't hurt. > > > > It is necessary given that we're wanting options to a ":set" command which > > isn't a boolean option, unfortunately. > > > > Please don't expect me to clean up complete() as part of this. That will > > have to wait. > > I expect you not to make things worse. It was always going that way as soon as anyone had another command to add to this. I'll split this off into a static function then. It won't make it any better, but it will reduce the clutter. > Fair enough about the displaying part, but your first assumption is plainly > untrue. The code iterating through the other available browser settings will > be executed. *Very* nasty. Right. Scrap this series for now, Hannes. I'm taking a hatchet to complete(). -- Thomas Adam -- "It was the cruelest game I've ever played and it's played inside my head." -- "Hush The Warmth", Gorky's Zygotic Mynci. From thomas at xteddy.org Sat Feb 19 12:42:44 2011 From: thomas at xteddy.org (Thomas Adam) Date: Sat, 19 Feb 2011 12:42:44 +0000 Subject: [Vimprobable-users] [PATCH V2 02/10] Introduce complete_directories() In-Reply-To: <20110219133830.1abbac8e@workstation> References: <20110217030736.GA13703@debian.ttn6tadam> <20110219103357.2963a23c@workstation> <20110219121549.GB1903@debian.ttn6tadam> <20110219132048.5f3ccdea@workstation> <20110219123115.GE1903@debian.ttn6tadam> <20110219133830.1abbac8e@workstation> Message-ID: <20110219124242.GG1903@debian.ttn6tadam> On Sat, Feb 19, 2011 at 01:38:30PM +0100, Hannes Sch??ller wrote: > I am seriously surprised that this comes up now, after how many patches you made? > Or maybe I just wasn't paying enough attention to this in the past? Yup -- you just never noticed. :) -- Thomas Adam -- "It was the cruelest game I've ever played and it's played inside my head." -- "Hush The Warmth", Gorky's Zygotic Mynci. From hannes at yllr.net Sat Feb 19 12:42:11 2011 From: hannes at yllr.net (Hannes =?UTF-8?B?U2Now7xsbGVy?=) Date: Sat, 19 Feb 2011 13:42:11 +0100 Subject: [Vimprobable-users] [PATCH V2 01/10] Allow for :set downloadpath In-Reply-To: <20110219122918.GD1903@debian.ttn6tadam> References: <20110217030715.GA13695@debian.ttn6tadam> <20110219102559.35ec13f2@workstation> <20110219121035.GA1903@debian.ttn6tadam> <20110219131919.42ef7319@workstation> <20110219122918.GD1903@debian.ttn6tadam> Message-ID: <20110219134211.4ad37679@workstation> Thomas Adam wrote: > On Sat, Feb 19, 2011 at 01:19:19PM +0100, Hannes Sch??ller wrote: > > Thomas Adam wrote: > > > On Sat, Feb 19, 2011 at 10:25:59AM +0100, Hannes Sch??ller wrote: > > > > Thomas Adam wrote: > > > > > --- a/config.h > > > > > +++ b/config.h > > > > > @@ -176,4 +176,5 @@ static Setting browsersettings[] = { > > > > > { "proxy", NULL, "", FALSE, TRUE, FALSE, FALSE }, > > > > > { "scrollbars", NULL, "", FALSE, TRUE, FALSE, FALSE }, > > > > > { "completioncase", NULL, "", FALSE, TRUE, FALSE, FALSE }, > > > > > + { "downloadpath", NULL, "", FALSE, FALSE, FALSE, FALSE }, > > > > > > > > Again, I believe this should be > > > > > > > > + { "downloadpath", downloadpath, "", FALSE, FALSE, FALSE, FALSE }, > > > > > > > > unless you've got a good reason not to include the internal variable there for automatic handling. > > > > > > Yes, I don't need it to be stored or handled for me. > > > > That's like saying "I don't need printf, because I've written a replacement > > myself." Surely there is a *positive* reason why the generic handling > > isn't sufficient? Because if there isn't, running it through the > > regular piece of code which ensures consistency would be preferable. > > Perhaps you were meaning "promptdownload" here (which is a bool) instead of > downloadpath? Because that suddenly makes a bit more sense. There is handling for string variables in the code as well, in the function process_set_line. Hannes -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: not available URL: From hannes at yllr.net Sat Feb 19 13:01:03 2011 From: hannes at yllr.net (Hannes =?UTF-8?B?U2Now7xsbGVy?=) Date: Sat, 19 Feb 2011 14:01:03 +0100 Subject: [Vimprobable-users] [PATCH V2 03/10] Teach ":set" new command: downloadpath In-Reply-To: <20110219124146.GF1903@debian.ttn6tadam> References: <20110217030752.GA13712@debian.ttn6tadam> <20110219105312.0b9a0778@workstation> <20110219122634.GC1903@debian.ttn6tadam> <20110219133418.315f499c@workstation> <20110219124146.GF1903@debian.ttn6tadam> Message-ID: <20110219140103.731006f2@workstation> Thomas Adam wrote: > On Sat, Feb 19, 2011 at 01:34:18PM +0100, Hannes Sch??ller wrote: > > Fair enough about the displaying part, but your first assumption is plainly > > untrue. The code iterating through the other available browser settings will > > be executed. *Very* nasty. > > Right. > > Scrap this series for now, Hannes. I'm taking a hatchet to complete(). I think this is an overreaction, but as you wish. Hannes -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: not available URL: From thomas at xteddy.org Sat Feb 19 13:05:36 2011 From: thomas at xteddy.org (Thomas Adam) Date: Sat, 19 Feb 2011 13:05:36 +0000 Subject: [Vimprobable-users] [PATCH V2 03/10] Teach ":set" new command: downloadpath In-Reply-To: <20110219140103.731006f2@workstation> References: <20110217030752.GA13712@debian.ttn6tadam> <20110219105312.0b9a0778@workstation> <20110219122634.GC1903@debian.ttn6tadam> <20110219133418.315f499c@workstation> <20110219124146.GF1903@debian.ttn6tadam> <20110219140103.731006f2@workstation> Message-ID: <20110219130535.GH1903@debian.ttn6tadam> On Sat, Feb 19, 2011 at 02:01:03PM +0100, Hannes Sch??ller wrote: > Thomas Adam wrote: > > On Sat, Feb 19, 2011 at 01:34:18PM +0100, Hannes Sch??ller wrote: > > > Fair enough about the displaying part, but your first assumption is plainly > > > untrue. The code iterating through the other available browser settings will > > > be executed. *Very* nasty. > > > > Right. > > > > Scrap this series for now, Hannes. I'm taking a hatchet to complete(). > > I think this is an overreaction, but as you wish. Nah. :) There's already been one long discussion last month fixing a bug in complete() causing a segfault -- we can invalidate that patch as well with some cleanups. -- Thomas Adam -- "It was the cruelest game I've ever played and it's played inside my head." -- "Hush The Warmth", Gorky's Zygotic Mynci. From hannes at yllr.net Sat Feb 19 13:10:07 2011 From: hannes at yllr.net (Hannes =?UTF-8?B?U2Now7xsbGVy?=) Date: Sat, 19 Feb 2011 14:10:07 +0100 Subject: [Vimprobable-users] [PATCH V2 03/10] Teach ":set" new command: downloadpath In-Reply-To: <20110219130535.GH1903@debian.ttn6tadam> References: <20110217030752.GA13712@debian.ttn6tadam> <20110219105312.0b9a0778@workstation> <20110219122634.GC1903@debian.ttn6tadam> <20110219133418.315f499c@workstation> <20110219124146.GF1903@debian.ttn6tadam> <20110219140103.731006f2@workstation> <20110219130535.GH1903@debian.ttn6tadam> Message-ID: <20110219141007.373c8229@workstation> Thomas Adam wrote: > On Sat, Feb 19, 2011 at 02:01:03PM +0100, Hannes Sch??ller wrote: > > Thomas Adam wrote: > > > On Sat, Feb 19, 2011 at 01:34:18PM +0100, Hannes Sch??ller wrote: > > > > Fair enough about the displaying part, but your first assumption is plainly > > > > untrue. The code iterating through the other available browser settings will > > > > be executed. *Very* nasty. > > > > > > Right. > > > > > > Scrap this series for now, Hannes. I'm taking a hatchet to complete(). > > > > I think this is an overreaction, but as you wish. > > Nah. :) There's already been one long discussion last month fixing a bug > in complete() causing a segfault -- we can invalidate that patch as well > with some cleanups. For the record: I'm perfectly ok with having one central complete() function which determines the "case of completion" and then calls the appropriate complete_*() function. I.e. to have complete() as a hub. My objection was purely concerning putting the complete logic of such a "sub-function" right into complete() itself. Hannes -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: not available URL: From mkoskar at gmail.com Wed Feb 23 23:50:03 2011 From: mkoskar at gmail.com (Miroslav Koskar) Date: Thu, 24 Feb 2011 00:50:03 +0100 Subject: [Vimprobable-users] Enable standard control characters key bindings Message-ID: Hi, it would be very handy if the standard control character key bindings would work as expected. ESC (0x1B, ^[) - escape BS (0x08, ^H) - backspace HT (0x09, ^I) - tab stop LF (0x0A, ^J) - enter Also would be nice if the would cancel any currently edited ex-command (though ESC can be used for that - and if it would be more accessible as ... would be enough) As a motivation / argument - vimperator supports everything listed above Regards ;) -------------- next part -------------- An HTML attachment was scrubbed... URL: From hannes at yllr.net Sat Feb 26 12:22:32 2011 From: hannes at yllr.net (Hannes =?UTF-8?B?U2Now7xsbGVy?=) Date: Sat, 26 Feb 2011 13:22:32 +0100 Subject: [Vimprobable-users] Enable standard control characters key bindings In-Reply-To: References: Message-ID: <20110226132232.1f49c34a@workstation> Hello Miroslav! Miroslav Koskar wrote: > it would be very handy if the standard control character key bindings > would work as expected. Depending on the branch you're using, you can easily define them through vimprobablerc, keymap.h or config.h. Recently, a patch for the escape sequence has been posted here on this list, too. Hannes -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: not available URL: From thomas at xteddy.org Sun Feb 27 12:31:42 2011 From: thomas at xteddy.org (Thomas Adam) Date: Sun, 27 Feb 2011 12:31:42 +0000 Subject: [Vimprobable-users] [PATCH] Fix DSO linker (ld) changes with -lX11 -lXent Message-ID: <20110227123138.GA3998@debian.ttn6tadam> In recent versions of ld which now requires strict dynamic linker object rules, we must tell the linker which libraries to explicitly link against. This affects our use of X11, so link against that. --- I am not too sure of the impact of this change. It might affect linkers on older versions of BSD, but it works fine on the various systems I've tried it on. Without this patch, Vimprobable does not compile: /usr/bin/ld: main.o: undefined reference to symbol 'XFlush' /usr/bin/ld: note: 'XFlush' is defined in DSO //usr/lib/libX11.so.6 so try adding it to the linker command line //usr/lib/libX11.so.6: could not read symbols: Invalid operation Makefile | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Makefile b/Makefile index 12b29ed..10ede45 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ CLEAN = $(TARGET) $(OBJ) $(DEPS) javascript.h INSTALL = $(BINDIR)/$(TARGET) $(addprefix $(MANDIR)/man1/,$(MAN)) CFLAGS += `pkg-config --cflags $(LIBS)` -LDFLAGS += `pkg-config --libs $(LIBS)` +LDFLAGS += `pkg-config --libs $(LIBS)` -lX11 -lXext PREFIX ?= /usr/local BINDIR ?= $(PREFIX)/bin -- 1.7.4.1 From hannes at yllr.net Sun Feb 27 19:17:28 2011 From: hannes at yllr.net (Hannes =?UTF-8?B?U2Now7xsbGVy?=) Date: Sun, 27 Feb 2011 20:17:28 +0100 Subject: [Vimprobable-users] [PATCH 0/2] Add V_DEBUG make target In-Reply-To: <20101120030922.GA15000@shuttle.home> References: <20101120030922.GA15000@shuttle.home> Message-ID: <20110227201728.1d266e93@laptop2.lan.localhost> Since nobody else seems to have any desire to comment, I merged this. Thanks, Thomas! Hannes -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: not available URL: From hannes at yllr.net Sun Feb 27 19:47:20 2011 From: hannes at yllr.net (Hannes =?UTF-8?B?U2Now7xsbGVy?=) Date: Sun, 27 Feb 2011 20:47:20 +0100 Subject: [Vimprobable-users] [PATCH] Fix DSO linker (ld) changes with -lX11 -lXent In-Reply-To: <20110227123138.GA3998@debian.ttn6tadam> References: <20110227123138.GA3998@debian.ttn6tadam> Message-ID: <20110227204720.0f0d9e65@laptop2.lan.localhost> Merged - I don't think this will cause any problems. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: not available URL: From hannes at yllr.net Sun Feb 27 19:57:11 2011 From: hannes at yllr.net (Hannes =?UTF-8?B?U2Now7xsbGVy?=) Date: Sun, 27 Feb 2011 20:57:11 +0100 Subject: [Vimprobable-users] [PATCH v3 1/1] Don't segfault overflowing MAX_LIST_SIZE in complete() In-Reply-To: <20110131101840.GA19570@abacus.soton.smoothwall.net> References: <20110131101840.GA19570@abacus.soton.smoothwall.net> Message-ID: <20110227205711.5050e2db@laptop2.lan.localhost> Merged -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: not available URL: From hannes at yllr.net Sun Feb 27 20:02:27 2011 From: hannes at yllr.net (Hannes =?UTF-8?B?U2Now7xsbGVy?=) Date: Sun, 27 Feb 2011 21:02:27 +0100 Subject: [Vimprobable-users] Small Escape Patch In-Reply-To: <20110111100106.GA21019@elements.hsd1.ca.comcast.net> References: <20110111092633.GA20305@elements.hsd1.ca.comcast.net> <20110111094033.GA2918@abacus.soton.smoothwall.net> <20110111100106.GA21019@elements.hsd1.ca.comcast.net> Message-ID: <20110227210227.678c3642@laptop2.lan.localhost> Merged this version -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: not available URL: From hannes at yllr.net Sun Feb 27 20:24:01 2011 From: hannes at yllr.net (Hannes =?UTF-8?B?U2Now7xsbGVy?=) Date: Sun, 27 Feb 2011 21:24:01 +0100 Subject: [Vimprobable-users] Vimprobable 0.9.21.0 & Vimprobable2 0.9.8.0 released! Message-ID: <20110227212401.00df96f3@laptop2.lan.localhost> Hi! Although there have been two larger patches in the pipeline, I don't believe holding all these smaller things back any longer is a good idea. Hence this release. What's new? - Support for Webkit's enable-page-cache (Thomas Adam) - Customising HTTP Accept-Language header (Stephen Morgan) - Keybinding system now supports Mod1 - Mod5 (Hannes Schueller; Vimprobable2 only) - Debugging target in Makefile (Thomas Adam) - New default keybindings: - keypad slash to trigger search - C-[ to trigger escape Bugfixes: - Stripping whitespace from URLs to avoid them being interpreted as search terms (Hannes Schueller) - Allowing long URLs to be openend in a new window (Hannes Schueller) - X11 library linking fix (Thomas Adam) - Don't overflow MAX_LIST_SIZE (Thomas Adam) Enjoy! Hannes -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: not available URL: From mtreibton at googlemail.com Sun Feb 27 23:50:01 2011 From: mtreibton at googlemail.com (Michael Treibton) Date: Sun, 27 Feb 2011 23:50:01 +0000 Subject: [Vimprobable-users] Vimprobable 0.9.21.0 & Vimprobable2 0.9.8.0 released! In-Reply-To: <20110227212401.00df96f3@laptop2.lan.localhost> References: <20110227212401.00df96f3@laptop2.lan.localhost> Message-ID: hi, thanks for all the hard work, Hannes. you're really making vimprobable uzbl now. :P Michael 2011/2/27 Hannes Sch?ller : > Hi! > > Although there have been two larger patches in the pipeline, I don't > believe holding all these smaller things back any longer is a good > idea. Hence this release. > > What's new? > > - Support for Webkit's enable-page-cache (Thomas Adam) > - Customising HTTP Accept-Language header (Stephen Morgan) > - Keybinding system now supports Mod1 - Mod5 (Hannes Schueller; > ?Vimprobable2 only) > - Debugging target in Makefile (Thomas Adam) > - New default keybindings: > ? ? ? ?- keypad slash to trigger search > ? ? ? ?- C-[ to trigger escape > > Bugfixes: > - Stripping whitespace from URLs to avoid them being interpreted as > ?search terms (Hannes Schueller) > - Allowing long URLs to be openend in a new window (Hannes Schueller) > - X11 library linking fix (Thomas Adam) > - Don't overflow MAX_LIST_SIZE (Thomas Adam) > > Enjoy! > > Hannes > > _______________________________________________ > Vimprobable-users mailing list > Vimprobable-users at vimprobable.org > http://vimprobable.org/mailman/listinfo/vimprobable-users > > From thomas at xteddy.org Mon Feb 28 00:04:06 2011 From: thomas at xteddy.org (Thomas Adam) Date: Mon, 28 Feb 2011 00:04:06 +0000 Subject: [Vimprobable-users] [PATCH v2 1/1] Make general arguments to commands free-by-callee In-Reply-To: <20110130053240.GE3297@debian.ttn6tadam> References: <20110126212524.GA5875@debian> <20110130023011.GA22142@elements.hsd1.ca.comcast.net> <20110130023516.GB3297@debian.ttn6tadam> <20110130031720.GA22328@elements.hsd1.ca.comcast.net> <20110130033155.GC3297@debian.ttn6tadam> <20110130040252.GA23932@elements.hsd1.ca.comcast.net> <20110130041201.GD3297@debian.ttn6tadam> <20110130053240.GE3297@debian.ttn6tadam> Message-ID: <20110228000404.GA1921@debian.ttn6tadam> Hi, On Sun, Jan 30, 2011 at 05:32:41AM +0000, Thomas Adam wrote: > On Sun, Jan 30, 2011 at 04:12:03AM +0000, Thomas Adam wrote: > > On Sat, Jan 29, 2011 at 08:02:52PM -0800, alkim1234 at gmail.com wrote: > > > Valid point. Do you have any ideas for taking care of the double-freeing? > > > > No, I think it's fine to ignore it -- that is, if other command instances in > > the future need to mess with a.s, it will be free()d for us. And with this > > patch, we're still catering for commands in config.h as before. > > Except of course, now nothing is ever free()d. I'll repeat again, that > leaving free()ing up to the caller always gets forgotten -- there's too many > examples of this in Vimprobable; and also note that this is still a much > cleaner interface to the commands *where it's used* currently -- as both > echo() and script() are both functions run for various commands -- you > enumerate the areas where this can all be done centrally. > > So see the following below. It introduces the SAFEFREE() macro (which I > stole from FVWM) which sets the pointers it free()s to NULL, this trying to > avoid the double-free conditions we might see. Note that g_free(), like > free() seems to not to set the pointer to NULL -- I had hoped g_free() > might. > > This is on top of my last patch in this thread. Did you get round to looking at this? If not, and I don't hear from you very soon, I'll re-roll this into a patch of its own right. -- Thomas Adam -- "Deep in my heart I wish I was wrong. But deep in my heart I know I am not." -- Morrissey ("Girl Least Likely To" -- off of Viva Hate.) From thomas at fvwm.org Mon Feb 28 00:32:28 2011 From: thomas at fvwm.org (Thomas Adam) Date: Mon, 28 Feb 2011 00:32:28 +0000 Subject: [Vimprobable-users] [PATCH] Add coding style note to PATCHES Message-ID: <20110228003225.GA24458@debian.ttn6tadam> Mention that the preferred coding style uses four spaces rather than a hard tab, and how to set that in Vim. --- I can't say I like this one bit, but nevertheless this ought to help *myself* as well as others to not make atrocious whitespace violations. :) PATCHES | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-) diff --git a/PATCHES b/PATCHES index 89401a0..f9e8abf 100644 --- a/PATCHES +++ b/PATCHES @@ -39,6 +39,17 @@ pass the "--global" option, as shown. This is a one-off operation once the repository has been cloned, assuming this information has ever been set before. +Coding style +============ + +Vimprobable uses four spaces by default, rather than literal hard tabs. +Most editors by default honour hard tabs only. If you're using Vim (which +isn't an unreasonable assumption ;)) you can set the following: + +:set expandtab ts=4 sts=4 sw=4 + +This should help reduce the number of whitespace fixups needed. + Use of topic branches ===================== -- 1.7.4.1 From hannes at yllr.net Mon Feb 28 18:24:34 2011 From: hannes at yllr.net (Hannes =?UTF-8?B?U2Now7xsbGVy?=) Date: Mon, 28 Feb 2011 19:24:34 +0100 Subject: [Vimprobable-users] Vimprobable 0.9.21.0 & Vimprobable2 0.9.8.0 released! In-Reply-To: References: <20110227212401.00df96f3@laptop2.lan.localhost> Message-ID: <20110228192434.04b22539@workstation> Michael Treibton wrote: > thanks for all the hard work, Hannes. you're really making vimprobable > uzbl now. :P Well, so far, there isn't a single scripting hook in the code, so... ;) Hannes -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: not available URL: