Mercurial > dillo_port1.3
changeset 2145:09d5a78e4244
Added multiple search engines (with several 'search_url' lines in dillorc)
This patch adds the PREFS_STRINGS type to the prefsparser, which allows having
multiple different strings asociated with one dillorc option (stored in a list)
author | Jorge Arellano Cid <jcid@dillo.org> |
---|---|
date | So, 24 Jul 2011 13:47:24 -0400 |
parents | d587288ee7b4 |
children | aac29835ca8c |
files | src/dialog.cc src/prefs.c src/prefs.h src/prefsparser.cc src/uicmd.cc |
diffstat | 5 files changed, 73 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/src/dialog.cc Fr Jul 22 01:58:15 2011 +0000 +++ b/src/dialog.cc So Jul 24 13:47:24 2011 -0400 @@ -22,6 +22,8 @@ #include <FL/Fl_Output.H> #include <FL/Fl_Input.H> #include <FL/Fl_Secret_Input.H> +#include <FL/Fl_Choice.H> +#include <FL/Fl_Menu_Item.H> #include "msg.h" #include "dialog.hh" @@ -75,6 +77,24 @@ } return Fl_Input::handle(e); } + +/* + * Used to make the ENTER key activate the CustChoice + */ +class CustChoice : public Fl_Choice { +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 && + (Fl::event_state() & (FL_SHIFT|FL_CTRL|FL_ALT|FL_META)) == 0) { + MSG("CustChoice: ENTER\n"); + return Fl_Choice::handle(FL_PUSH); + } + return Fl_Choice::handle(e); + }; +}; + //---------------------------------------------------------------------------- @@ -104,6 +124,7 @@ */ const char *a_Dialog_input(const char *msg) { + static Fl_Menu_Item *pm = 0; int ww = 450, wh = 130, gap = 10, ih = 60, bw = 80, bh = 30; input_answer = 0; @@ -134,6 +155,26 @@ c_inp->labelsize(14); c_inp->textsize(14); + CustChoice *ch = new CustChoice(1*gap,ih+3*gap,180,24); + if (!pm) { + 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)); + } + } + ch->tooltip("Select search engine"); + ch->menu(pm); + ch->value(prefs.search_url_idx); + ch->textcolor(FL_DARK_BLUE); + int xpos = ww-2*(gap+bw), ypos = ih+3*gap; Fl_Return_Button *rb = new Fl_Return_Button(xpos, ypos, bw, bh, "OK"); rb->align(FL_ALIGN_INSIDE|FL_ALIGN_CLIP); @@ -156,6 +197,8 @@ /* we have a string, save it */ dFree(input_str); input_str = dStrdup(c_inp->value()); + MSG("a_Dialog_input value() = %d\n", ch->value()); + prefs.search_url_idx = ch->value(); } delete window;
--- a/src/prefs.c Fr Jul 22 01:58:15 2011 +0000 +++ b/src/prefs.c So Jul 24 13:47:24 2011 -0400 @@ -75,7 +75,10 @@ prefs.panel_size = P_medium; prefs.parse_embedded_css=TRUE; prefs.save_dir = dStrdup(PREFS_SAVE_DIR); - prefs.search_url = dStrdup(PREFS_SEARCH_URL); + prefs.search_urls = dList_new(16); + dList_append(prefs.search_urls, dStrdup(PREFS_SEARCH_URL)); + dList_append(prefs.search_urls, NULL); /* flags a default search URL */ + prefs.search_url_idx = 0; prefs.show_back = TRUE; prefs.show_bookmarks = TRUE; prefs.show_clear_url = TRUE; @@ -104,6 +107,8 @@ */ void a_Prefs_freeall(void) { + int i; + dFree(prefs.font_cursive); dFree(prefs.font_fantasy); dFree(prefs.font_monospace); @@ -117,6 +122,8 @@ dFree(prefs.http_user_agent); dFree(prefs.no_proxy); dFree(prefs.save_dir); - dFree(prefs.search_url); + for (i = 0; i < dList_length(prefs.search_urls); ++i) + dFree(dList_nth_data(prefs.search_urls, i)); + dList_free(prefs.search_urls); a_Url_free(prefs.start_page); }
--- a/src/prefs.h Fr Jul 22 01:58:15 2011 +0000 +++ b/src/prefs.h So Jul 24 13:47:24 2011 -0400 @@ -85,7 +85,8 @@ bool_t enterpress_forces_submit; bool_t middle_click_opens_new_tab; bool_t right_click_closes_tab; - char *search_url; + bool_t search_url_idx; + Dlist *search_urls; char *save_dir; bool_t show_msg; bool_t show_extra_warnings;
--- a/src/prefsparser.cc Fr Jul 22 01:58:15 2011 +0000 +++ b/src/prefsparser.cc So Jul 24 13:47:24 2011 -0400 @@ -24,6 +24,7 @@ PREFS_BOOL, PREFS_COLOR, PREFS_STRING, + PREFS_STRINGS, PREFS_URL, PREFS_INT32, PREFS_DOUBLE, @@ -86,7 +87,7 @@ { "panel_size", &prefs.panel_size, PREFS_PANEL_SIZE }, { "parse_embedded_css", &prefs.parse_embedded_css, PREFS_BOOL }, { "save_dir", &prefs.save_dir, PREFS_STRING }, - { "search_url", &prefs.search_url, PREFS_STRING }, + { "search_url", &prefs.search_urls, PREFS_STRINGS }, { "show_back", &prefs.show_back, PREFS_BOOL }, { "show_bookmarks", &prefs.show_bookmarks, PREFS_BOOL }, { "show_clear_url", &prefs.show_clear_url, PREFS_BOOL }, @@ -134,6 +135,19 @@ dFree(*(char **)node->pref); *(char **)node->pref = dStrdup(value); break; + case PREFS_STRINGS: + { + Dlist *lp = *(Dlist **)node->pref; + if (dList_length(lp) == 2 && !dList_nth_data(lp, 1)) { + /* override the default */ + void *data = dList_nth_data(lp, 0); + dList_remove(lp, data); + dList_remove(lp, NULL); + dFree(data); + } + dList_append(lp, dStrdup(value)); + break; + } case PREFS_URL: a_Url_free(*(DilloUrl **)node->pref); *(DilloUrl **)node->pref = a_Url_new(value, NULL);
--- a/src/uicmd.cc Fr Jul 22 01:58:15 2011 +0000 +++ b/src/uicmd.cc So Jul 24 13:47:24 2011 -0400 @@ -774,14 +774,15 @@ /* * Returns a newly allocated string holding a search url generated from - * a string of keywords (separarated by blanks) and prefs.search_url. + * a string of keywords (separarated by blanks) and the current search_url. * The search string is urlencoded. */ static char *UIcmd_make_search_str(const char *str) { - char *keys = a_Url_encode_hex_str(str), *c = prefs.search_url; + char *search_url; + char *keys = a_Url_encode_hex_str(str), + *c = (char*)dList_nth_data(prefs.search_urls, prefs.search_url_idx); Dstr *ds = dStr_sized_new(128); - char *search_url; for (; *c; c++) { if (*c == '%')