diff options
author | Jorge Arellano Cid <jcid@dillo.org> | 2011-07-24 13:47:25 -0400 |
---|---|---|
committer | Jorge Arellano Cid <jcid@dillo.org> | 2011-07-24 13:47:25 -0400 |
commit | a748ecd3ed4b9f620f6b3b911a23f689902cdffd (patch) | |
tree | 7431c26b0de72ac9d768cf3652bca0f217e64951 /src | |
parent | 378a4098e362794b4feb3d75e40b6ada697c47e9 (diff) |
Added an optional label to dillorc's search_url. Format: "[<label> ]<url>"
Diffstat (limited to 'src')
-rw-r--r-- | src/dialog.cc | 17 | ||||
-rw-r--r-- | src/misc.c | 32 | ||||
-rw-r--r-- | src/misc.h | 1 | ||||
-rw-r--r-- | src/uicmd.cc | 10 |
4 files changed, 48 insertions, 12 deletions
diff --git a/src/dialog.cc b/src/dialog.cc index 7bde3dd2..85121c63 100644 --- a/src/dialog.cc +++ b/src/dialog.cc @@ -86,7 +86,8 @@ public: CustChoice (int x, int y, int w, int h, const char* l=0) : Fl_Choice(x,y,w,h,l) {}; int handle(int e) { - if (e == FL_KEYBOARD && Fl::event_key() == FL_Enter && + if (e == FL_KEYBOARD && + (Fl::event_key() == FL_Enter || Fl::event_key() == FL_Down) && (Fl::event_state() & (FL_SHIFT|FL_CTRL|FL_ALT|FL_META)) == 0) { MSG("CustChoice: ENTER\n"); return Fl_Choice::handle(FL_PUSH); @@ -160,14 +161,12 @@ const char *a_Dialog_input(const char *msg) int n_it = dList_length(prefs.search_urls); pm = new Fl_Menu_Item[n_it+1]; memset(pm, '\0', sizeof(Fl_Menu_Item[n_it+1])); - for (int i = 0; i < n_it; i++) { - char *p, *q, label[32]; - char *url = (char *)dList_nth_data(prefs.search_urls, i); - if ((p = strstr(url, "//")) && (q = strstr(p+2,"/"))) { - strncpy(label,p+2,MIN(q-p-2,31)); - label[MIN(q-p-2,31)] = 0; - } - pm[i].label(FL_NORMAL_LABEL, strdup(label)); + for (int i = 0, j = 0; i < n_it; i++) { + char *label, *url, *source; + source = (char *)dList_nth_data(prefs.search_urls, i); + if (a_Misc_parse_search_url(source, &label, &url) < 0) + continue; + pm[j++].label(FL_NORMAL_LABEL, strdup(label)); } } ch->tooltip("Select search engine"); @@ -383,6 +383,38 @@ int a_Misc_parse_geometry(char *str, int *x, int *y, int *w, int *h) } /* + * Parse dillorc's search_url string ("[<label> ]<url>") + * Return value: -1 on error, 0 on success (and label and urlstr pointers) + */ +int a_Misc_parse_search_url(char *source, char **label, char **urlstr) +{ + static char buf[32]; + char *p, *q; + int ret = -1; + + if ((p = strrchr(source, ' '))) { + /* label and url pair */ + strncpy(buf,source,MIN(p-source,31)); + buf[MIN(p-source,31)] = 0; + source = p+1; + if ((p = strchr(source, '/')) && p[1] && (q = strchr(p+2,'/'))) { + *urlstr = source; + ret = 0; + } + } else { + /* url only, make a custom label */ + if ((p = strchr(source, '/')) && p[1] && (q = strchr(p+2,'/'))) { + strncpy(buf,p+2,MIN(q-p-2,31)); + buf[MIN(q-p-2,31)] = 0; + *urlstr = source; + ret = 0; + } + } + *label = buf; + return ret; +} + +/* * Encodes string using base64 encoding. * Return value: new string or NULL if input string is empty. */ @@ -17,6 +17,7 @@ void a_Misc_parse_content_type(const char *str, char **major, char **minor, char **charset); int a_Misc_content_type_cmp(const char* ct1, const char *ct2); int a_Misc_parse_geometry(char *geom, int *x, int *y, int *w, int *h); +int a_Misc_parse_search_url(char *source, char **label, char **urlstr); char *a_Misc_encode_base64(const char *in); Dstr *a_Misc_file2dstr(const char *filename); diff --git a/src/uicmd.cc b/src/uicmd.cc index 0e0e4f88..1efcf845 100644 --- a/src/uicmd.cc +++ b/src/uicmd.cc @@ -36,6 +36,7 @@ #include "history.h" #include "msg.h" #include "prefs.h" +#include "misc.h" #include "dw/fltkviewport.hh" @@ -779,12 +780,15 @@ void a_UIcmd_open_file(void *vbw) */ static char *UIcmd_make_search_str(const char *str) { - char *search_url; + char *search_url, *l, *u, *c; char *keys = a_Url_encode_hex_str(str), - *c = (char*)dList_nth_data(prefs.search_urls, prefs.search_url_idx); + *src = (char*)dList_nth_data(prefs.search_urls, prefs.search_url_idx); Dstr *ds = dStr_sized_new(128); - for (; *c; c++) { + /* parse search_url into label and url */ + a_Misc_parse_search_url(src, &l, &u); + + for (c = u; *c; c++) { if (*c == '%') switch(*++c) { case 's': |