summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJorge Arellano Cid <jcid@dillo.org>2011-07-24 13:47:24 -0400
committerJorge Arellano Cid <jcid@dillo.org>2011-07-24 13:47:24 -0400
commit378a4098e362794b4feb3d75e40b6ada697c47e9 (patch)
treea0e7e1dd5ed6790227e0f98cf7e17021cb089277 /src
parent58d8a78e4c89ba7609cb16ba8b4462235137fd58 (diff)
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)
Diffstat (limited to 'src')
-rw-r--r--src/dialog.cc43
-rw-r--r--src/prefs.c11
-rw-r--r--src/prefs.h3
-rw-r--r--src/prefsparser.cc16
-rw-r--r--src/uicmd.cc7
5 files changed, 73 insertions, 7 deletions
diff --git a/src/dialog.cc b/src/dialog.cc
index 9b3f8db2..7bde3dd2 100644
--- a/src/dialog.cc
+++ b/src/dialog.cc
@@ -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 @@ int CustInput3::handle(int e)
}
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 @@ static void input_cb(Fl_Widget *button, void *number)
*/
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 @@ const char *a_Dialog_input(const char *msg)
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 @@ const char *a_Dialog_input(const char *msg)
/* 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;
diff --git a/src/prefs.c b/src/prefs.c
index be0882bd..cbd1f5d8 100644
--- a/src/prefs.c
+++ b/src/prefs.c
@@ -75,7 +75,10 @@ void a_Prefs_init(void)
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_init(void)
*/
void a_Prefs_freeall(void)
{
+ int i;
+
dFree(prefs.font_cursive);
dFree(prefs.font_fantasy);
dFree(prefs.font_monospace);
@@ -117,6 +122,8 @@ void a_Prefs_freeall(void)
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);
}
diff --git a/src/prefs.h b/src/prefs.h
index 4debee89..19e3890a 100644
--- a/src/prefs.h
+++ b/src/prefs.h
@@ -85,7 +85,8 @@ struct _DilloPrefs {
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;
diff --git a/src/prefsparser.cc b/src/prefsparser.cc
index 9d245706..bf973225 100644
--- a/src/prefsparser.cc
+++ b/src/prefsparser.cc
@@ -24,6 +24,7 @@ typedef enum {
PREFS_BOOL,
PREFS_COLOR,
PREFS_STRING,
+ PREFS_STRINGS,
PREFS_URL,
PREFS_INT32,
PREFS_DOUBLE,
@@ -86,7 +87,7 @@ int PrefsParser::parseOption(char *name, char *value)
{ "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 @@ int PrefsParser::parseOption(char *name, char *value)
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);
diff --git a/src/uicmd.cc b/src/uicmd.cc
index f257d537..0e0e4f88 100644
--- a/src/uicmd.cc
+++ b/src/uicmd.cc
@@ -774,14 +774,15 @@ void a_UIcmd_open_file(void *vbw)
/*
* 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;
- Dstr *ds = dStr_sized_new(128);
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);
for (; *c; c++) {
if (*c == '%')