diff options
author | Jeremy Henty <onepoint@starurchin.org> | 2012-12-10 02:00:04 +0000 |
---|---|---|
committer | Jeremy Henty <onepoint@starurchin.org> | 2012-12-10 02:00:04 +0000 |
commit | 6675d229bcee77341ef46ec3c2252f2dee52ac66 (patch) | |
tree | 8285797a97d63fd86f2ddd4fdedd6b16cb3c78d5 /src | |
parent | fb85e0c89a2fc119d99e80b0070e95ceb5381f67 (diff) |
Dillo: parameterise window titles.
Diffstat (limited to 'src')
-rw-r--r-- | src/auth.c | 13 | ||||
-rw-r--r-- | src/dialog.cc | 74 | ||||
-rw-r--r-- | src/dialog.hh | 19 | ||||
-rw-r--r-- | src/dpiapi.c | 9 | ||||
-rw-r--r-- | src/nav.c | 3 | ||||
-rw-r--r-- | src/uicmd.cc | 21 |
6 files changed, 82 insertions, 57 deletions
@@ -619,20 +619,21 @@ static int Auth_do_auth_dialog(const AuthParse_t *auth_parse, const DilloUrl *url) { int ret; - char *message; + char *title, *msg; AuthDialogData_t *data; const char *typestr = auth_parse->type == DIGEST ? "Digest" : "Basic"; _MSG("auth.c: Auth_do_auth_dialog: realm = '%s'\n", auth_parse->realm); - message = dStrconcat("The server at ", URL_HOST(url), " requires a username" - " and password for \"", auth_parse->realm, "\".\n\n" - "Authentication scheme: ", typestr, NULL); + title = dStrconcat("Dillo: Password for ", auth_parse->realm, NULL); + msg = dStrconcat("The server at ", URL_HOST(url), " requires a username" + " and password for \"", auth_parse->realm, "\".\n\n" + "Authentication scheme: ", typestr, NULL); data = dNew(AuthDialogData_t, 1); data->auth_parse = auth_parse; data->url = a_Url_dup(url); - ret = a_Dialog_user_password(message, Auth_do_auth_dialog_cb, data); - dFree(message); + ret = a_Dialog_user_password(title, msg, Auth_do_auth_dialog_cb, data); + dFree(title); dFree(msg); a_Url_free((void *)data->url); dFree(data); return ret; diff --git a/src/dialog.cc b/src/dialog.cc index 37a5d39c..94c31fb1 100644 --- a/src/dialog.cc +++ b/src/dialog.cc @@ -120,9 +120,11 @@ int EnterButton::handle(int e) /* * Display a message in a popup window. */ -void a_Dialog_msg(const char *msg) +void a_Dialog_msg(const char *title, const char *msg) { - fl_message_title("Dillo: Message"); + if (!(title && *title)) + title = "Dillo: Message"; + fl_message_title(title); fl_message("%s", msg); } @@ -142,14 +144,17 @@ static void input_cb(Fl_Widget *button, void *number) * * Return value: string on success, NULL upon Cancel or Close window */ -const char *a_Dialog_input(const char *msg) +const char *a_Dialog_input(const char *title, 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; - Fl_Window *window = new Fl_Window(ww,wh,"Dillo: Input"); + if (!(title && *title)) + title = "Dillo: Input"; + + Fl_Window *window = new Fl_Window(ww,wh,title); window->set_modal(); window->begin(); Fl_Group* ib = new Fl_Group(0,0,window->w(),window->h()); @@ -224,9 +229,11 @@ const char *a_Dialog_input(const char *msg) /* * Dialog for password */ -const char *a_Dialog_passwd(const char *msg) +const char *a_Dialog_passwd(const char *title, const char *msg) { - fl_message_title("Dillo: Password"); + if (!(title && *title)) + title = "Dillo: Password"; + fl_message_title(title); return fl_password("%s", "", msg); } @@ -235,10 +242,10 @@ const char *a_Dialog_passwd(const char *msg) * * Return: pointer to chosen filename, or NULL on Cancel. */ -const char *a_Dialog_save_file(const char *msg, +const char *a_Dialog_save_file(const char *title, const char *pattern, const char *fname) { - return fl_file_chooser(msg, pattern, fname); + return fl_file_chooser(title, pattern, fname); } /* @@ -246,14 +253,14 @@ const char *a_Dialog_save_file(const char *msg, * * Return: pointer to chosen filename, or NULL on Cancel. */ -const char *a_Dialog_select_file(const char *msg, +const char *a_Dialog_select_file(const char *title, const char *pattern, const char *fname) { /* * FileChooser::type(MULTI) appears to allow multiple files to be selected, * but just follow save_file's path for now. */ - return a_Dialog_save_file(msg, pattern, fname); + return a_Dialog_save_file(title, pattern, fname); } /* @@ -261,12 +268,12 @@ const char *a_Dialog_select_file(const char *msg, * * Return: pointer to chosen filename, or NULL on Cancel. */ -char *a_Dialog_open_file(const char *msg, +char *a_Dialog_open_file(const char *title, const char *pattern, const char *fname) { const char *fc_name; - fc_name = fl_file_chooser(msg, pattern, fname); + fc_name = fl_file_chooser(title, pattern, fname); return (fc_name) ? a_Misc_escape_chars(fc_name, "% #") : NULL; } @@ -285,11 +292,14 @@ static void text_window_close_cb(Fl_Widget *, void *vtd) /* * Show a new window with the provided text */ -void a_Dialog_text_window(const char *txt, const char *title) +void a_Dialog_text_window(const char *title, const char *txt) { int wh = prefs.height, ww = prefs.width, bh = 30; - Fl_Window *window = new Fl_Window(ww, wh, title ? title : "Dillo: Text"); + if (!(title && *title)) + title = "Dillo: Text"; + + Fl_Window *window = new Fl_Window(ww, wh, title); Fl_Group::current(0); @@ -327,7 +337,7 @@ static void choice5_cb(Fl_Widget *button, void *number) * * Return value: 0 = dialog was cancelled, 1-5 = selected alternative. */ -int a_Dialog_choice5(const char *QuestionTxt, +int a_Dialog_choice5(const char *title, const char *msg, const char *alt1, const char *alt2, const char *alt3, const char *alt4, const char *alt5) { @@ -336,6 +346,11 @@ int a_Dialog_choice5(const char *QuestionTxt, int ww = 440, wh = 120, bw = 50, bh = 45, ih = 50, nb = 0; const char *txt[7]; + if (!(title && *title)) + title = "Dillo: Choice"; + if (!msg) + msg = ""; + txt[0] = txt[6] = NULL; txt[1] = alt1; txt[2] = alt2; txt[3] = alt3; txt[4] = alt4; txt[5] = alt5; @@ -348,7 +363,7 @@ int a_Dialog_choice5(const char *QuestionTxt, } ww = 140 + nb*(bw+10); - Fl_Window *window = new Fl_Window(ww,wh,"Dillo: Choice"); + Fl_Window *window = new Fl_Window(ww,wh,title); window->set_modal(); window->begin(); Fl_Group* ib = new Fl_Group(0,0,window->w(),window->h()); @@ -365,7 +380,7 @@ int a_Dialog_choice5(const char *QuestionTxt, o->label("?"); o->show(); - Fl_Box *box = new Fl_Box(60,0,ww-60,wh-bh, QuestionTxt); + Fl_Box *box = new Fl_Box(60,0,ww-60,wh-bh, msg); box->labelfont(FL_HELVETICA); box->labelsize(14); box->align(FL_ALIGN_WRAP); @@ -406,31 +421,34 @@ static void Dialog_user_password_cb(Fl_Widget *button, void *) * Call the callback with the result (OK or not) and the given user and * password if OK. */ -int a_Dialog_user_password(const char *message, UserPasswordCB cb, void *vp) +int a_Dialog_user_password(const char *title, const char *msg, + UserPasswordCB cb, void *vp) { int ok = 0, window_h = 280, y, msg_w, msg_h; const int window_w = 300, input_x = 80, input_w = 200, input_h = 30, button_h = 30; /* window is resized below */ - Fl_Window *window = new Fl_Window(window_w,window_h,"Dillo: User/Password"); + if (!(title && *title)) + title = "Dillo: User/Password"; + Fl_Window *window = new Fl_Window(window_w,window_h,title); Fl_Group::current(0); window->user_data(NULL); /* message */ y = 20; msg_w = window_w - 40; - Fl_Box *msg = new Fl_Box(20, y, msg_w, 100); /* resized below */ - msg->label(message); - msg->labelfont(FL_HELVETICA); - msg->labelsize(14); - msg->align(FL_ALIGN_INSIDE | FL_ALIGN_TOP_LEFT | FL_ALIGN_WRAP); + Fl_Box *msg_box = new Fl_Box(20, y, msg_w, 100); /* resized below */ + msg_box->label(msg); + msg_box->labelfont(FL_HELVETICA); + msg_box->labelsize(14); + msg_box->align(FL_ALIGN_INSIDE | FL_ALIGN_TOP_LEFT | FL_ALIGN_WRAP); - fl_font(msg->labelfont(), msg->labelsize()); + fl_font(msg_box->labelfont(), msg_box->labelsize()); msg_w -= 6; /* The label doesn't fill the entire box. */ - fl_measure(msg->label(), msg_w, msg_h, 0); /* fl_measure wraps at msg_w */ - msg->size(msg->w(), msg_h); - window->add(msg); + fl_measure(msg_box->label(), msg_w, msg_h, 0); /* fl_measure wraps at msg_w */ + msg_box->size(msg_box->w(), msg_h); + window->add(msg_box); /* inputs */ y += msg_h + 20; diff --git a/src/dialog.hh b/src/dialog.hh index 57b21849..8b3bc1b7 100644 --- a/src/dialog.hh +++ b/src/dialog.hh @@ -8,20 +8,21 @@ extern "C" { typedef void (*UserPasswordCB)(const char *user, const char *password, void *vp); -void a_Dialog_msg(const char *msg); -int a_Dialog_choice5(const char *QuestionTxt, +void a_Dialog_msg(const char *title, const char *msg); +int a_Dialog_choice5(const char *title, const char *msg, const char *alt1, const char *alt2, const char *alt3, const char *alt4, const char *alt5); -int a_Dialog_user_password(const char *message, UserPasswordCB cb, void *vp); -const char *a_Dialog_input(const char *msg); -const char *a_Dialog_passwd(const char *msg); -const char *a_Dialog_save_file(const char *msg, +int a_Dialog_user_password(const char *title, const char *msg, + UserPasswordCB cb, void *vp); +const char *a_Dialog_input(const char *title, const char *msg); +const char *a_Dialog_passwd(const char *title, const char *msg); +const char *a_Dialog_save_file(const char *title, const char *pattern, const char *fname); -const char *a_Dialog_select_file(const char *msg, +const char *a_Dialog_select_file(const char *title, const char *pattern, const char *fname); -char *a_Dialog_open_file(const char *msg, +char *a_Dialog_open_file(const char *title, const char *pattern, const char *fname); -void a_Dialog_text_window(const char *txt, const char *title); +void a_Dialog_text_window(const char *title, const char *txt); #ifdef __cplusplus } diff --git a/src/dpiapi.c b/src/dpiapi.c index 2068146c..d8980a17 100644 --- a/src/dpiapi.c +++ b/src/dpiapi.c @@ -49,7 +49,7 @@ static void Dpiapi_dialog_answer_cb(BrowserWindow *bw, int answer) */ void a_Dpiapi_dialog(BrowserWindow *bw, char *server, char *dpip_tag) { - char *question, *alt1, *alt2, *alt3, *alt4, *alt5; + char *title, *msg, *alt1, *alt2, *alt3, *alt4, *alt5; size_t dpip_tag_len; int ret; @@ -61,18 +61,19 @@ void a_Dpiapi_dialog(BrowserWindow *bw, char *server, char *dpip_tag) /* other options can be parsed the same way */ dpip_tag_len = strlen(dpip_tag); - question = a_Dpip_get_attr_l(dpip_tag, dpip_tag_len, "msg"); + title = a_Dpip_get_attr_l(dpip_tag, dpip_tag_len, "title"); + msg = a_Dpip_get_attr_l(dpip_tag, dpip_tag_len, "msg"); alt1 = a_Dpip_get_attr_l(dpip_tag, dpip_tag_len, "alt1"); alt2 = a_Dpip_get_attr_l(dpip_tag, dpip_tag_len, "alt2"); alt3 = a_Dpip_get_attr_l(dpip_tag, dpip_tag_len, "alt3"); alt4 = a_Dpip_get_attr_l(dpip_tag, dpip_tag_len, "alt4"); alt5 = a_Dpip_get_attr_l(dpip_tag, dpip_tag_len, "alt5"); - ret = a_Dialog_choice5(question, alt1, alt2, alt3, alt4, alt5); + ret = a_Dialog_choice5(title, msg, alt1, alt2, alt3, alt4, alt5); /* As choice5 is modal, call the callback function directly. */ Dpiapi_dialog_answer_cb(bw, ret); dFree(alt1); dFree(alt2); dFree(alt3); dFree(alt4); dFree(alt5); - dFree(question); + dFree(title); dFree(msg); } @@ -487,7 +487,8 @@ static void Nav_reload_callback(void *data) confirmed = 1; } else if (URL_FLAGS(h_url) & URL_Post) { /* Attempt to repost data, let's confirm... */ - choice = a_Dialog_choice5("Repost form data?", + choice = a_Dialog_choice5("Dillo: Repost form?", + "Repost form data?", "No", "Yes", "Cancel", NULL, NULL); confirmed = (choice == 2); /* "Yes" */ } diff --git a/src/uicmd.cc b/src/uicmd.cc index 039a23a4..20d32519 100644 --- a/src/uicmd.cc +++ b/src/uicmd.cc @@ -476,7 +476,8 @@ static void win_cb (Fl_Widget *w, void *cb_data) { int choice = 1, ntabs = tabs->num_tabs(); if (prefs.show_quit_dialog && ntabs > 1) - choice = a_Dialog_choice5("Window contains more than one tab.", + choice = a_Dialog_choice5("Dillo: Close window?", + "Window contains more than one tab.", "Close", "Cancel", NULL, NULL, NULL); if (choice == 1) while (ntabs-- > 0) @@ -616,8 +617,9 @@ void a_UIcmd_close_all_bw(void *) int choice = 1; if (prefs.show_quit_dialog && a_Bw_num() > 1) - choice = a_Dialog_choice5("More than one open tab or window.", - "Quit", "Cancel", NULL, NULL, NULL); + choice = a_Dialog_choice5("Dillo: Quit?", + "More than one open tab or window.", + "Quit", "Cancel", NULL, NULL, NULL); if (choice == 1) while ((bw = a_Bw_get(0))) a_UIcmd_close_bw((void*)bw); @@ -947,7 +949,7 @@ void a_UIcmd_search_dialog(void *vbw) { const char *query; - if ((query = a_Dialog_input("Search the Web:"))) { + if ((query = a_Dialog_input("Dillo: Search", "Search the Web:"))) { char *url_str = UIcmd_make_search_str(query); a_UIcmd_open_urlstr(vbw, url_str); dFree(url_str); @@ -960,9 +962,10 @@ void a_UIcmd_search_dialog(void *vbw) const char *a_UIcmd_get_passwd(const char *user) { const char *passwd; - char *prompt = dStrconcat("Password for user \"", user, "\"", NULL); - passwd = a_Dialog_passwd(prompt); - dFree(prompt); + const char *title = "Dillo: Password"; + char *msg = dStrconcat("Password for user \"", user, "\"", NULL); + passwd = a_Dialog_passwd(title, msg); + dFree(msg); return passwd; } @@ -1099,9 +1102,9 @@ void a_UIcmd_view_page_bugs(void *vbw) BrowserWindow *bw = (BrowserWindow*)vbw; if (bw->num_page_bugs > 0) { - a_Dialog_text_window(bw->page_bugs->str, "Dillo: Detected HTML errors"); + a_Dialog_text_window("Dillo: Detected HTML errors", bw->page_bugs->str); } else { - a_Dialog_msg("Zero detected HTML errors!"); + a_Dialog_msg("Dillo: Valid HTML!", "Zero detected HTML errors!"); } } |