From e5d8016bf4158013cf1a9dbc75bf39bdda925bf4 Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Sat, 14 Nov 2009 17:38:16 +0100 Subject: [PATCH] Wrap file chooser into the function sokoke_file_chooser_dialog_new --- midori/midori-browser.c | 37 ++++++++++--------------------------- midori/sokoke.c | 38 ++++++++++++++++++++++++++++++++++++++ midori/sokoke.h | 5 +++++ midori/wscript_build | 4 +++- wscript | 1 + 5 files changed, 57 insertions(+), 28 deletions(-) diff --git a/midori/midori-browser.c b/midori/midori-browser.c index a0a880b6..bc18407d 100644 --- a/midori/midori-browser.c +++ b/midori/midori-browser.c @@ -872,14 +872,8 @@ midori_browser_save_uri (MidoriBrowser* browser, if (!GTK_WIDGET_VISIBLE (browser)) return; - dialog = gtk_file_chooser_dialog_new ( - _("Save file as"), GTK_WINDOW (browser), - GTK_FILE_CHOOSER_ACTION_SAVE, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, - NULL); - gtk_window_set_icon_name (GTK_WINDOW (dialog), GTK_STOCK_SAVE); - gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (browser)); + dialog = sokoke_file_chooser_dialog_new (_("Save file as"), + GTK_WINDOW (browser), GTK_FILE_CHOOSER_ACTION_SAVE); if (uri) { @@ -915,7 +909,7 @@ midori_browser_save_uri (MidoriBrowser* browser, if (!folder_set && last_dir && *last_dir) gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), last_dir); - if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) + if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK) { #if WEBKIT_CHECK_VERSION (1, 1, 3) WebKitNetworkRequest* request; @@ -1425,14 +1419,8 @@ midori_view_download_requested_cb (GtkWidget* view, if (!dialog) { - dialog = gtk_file_chooser_dialog_new ( - _("Save file"), GTK_WINDOW (browser), - GTK_FILE_CHOOSER_ACTION_SAVE, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, - NULL); - gtk_window_set_icon_name (GTK_WINDOW (dialog), GTK_STOCK_SAVE); - gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (browser)); + dialog = sokoke_file_chooser_dialog_new (_("Save file"), + GTK_WINDOW (browser), GTK_FILE_CHOOSER_ACTION_SAVE); gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE); folder = katze_object_get_string (browser->settings, "download-folder"); gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), folder); @@ -2128,21 +2116,16 @@ _action_open_activate (GtkAction* action, gchar* uri = NULL; gboolean folder_set = FALSE; GtkWidget* dialog; + GtkWidget* view; if (!GTK_WIDGET_VISIBLE (browser)) return; - dialog = gtk_file_chooser_dialog_new ( - _("Open file"), GTK_WINDOW (browser), - GTK_FILE_CHOOSER_ACTION_OPEN, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, - NULL); - gtk_window_set_icon_name (GTK_WINDOW (dialog), GTK_STOCK_OPEN); - gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (browser)); + dialog = sokoke_file_chooser_dialog_new (_("Open file"), + GTK_WINDOW (browser), GTK_FILE_CHOOSER_ACTION_OPEN); /* base the start folder on the current view's uri if it is local */ - GtkWidget* view = midori_browser_get_current_tab (browser); + view = midori_browser_get_current_tab (browser); if ((uri = (gchar*)midori_view_get_display_uri (MIDORI_VIEW (view)))) { gchar* filename = g_filename_from_uri (uri, NULL, NULL); @@ -2163,7 +2146,7 @@ _action_open_activate (GtkAction* action, if (!folder_set && last_dir && *last_dir) gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), last_dir); - if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) + if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK) { gchar* folder; diff --git a/midori/sokoke.c b/midori/sokoke.c index 2f488160..0a0ef434 100644 --- a/midori/sokoke.c +++ b/midori/sokoke.c @@ -40,6 +40,10 @@ #include #endif +#ifdef HAVE_HILDON_FM + #include +#endif + static gchar* sokoke_js_string_utf8 (JSStringRef js_string) { @@ -1295,3 +1299,37 @@ sokoke_window_activate_key (GtkWindow* window, return FALSE; } + +/** + * sokoke_file_chooser_dialog_new: + * @title: a window title, or %NULL + * @window: a parent #GtkWindow, or %NULL + * @action: a #GtkFileChooserAction + * + * Creates a new file chooser dialog, as appropriate for + * the platform, with buttons according to the @action. + * + * The positive response is %GTK_RESPONSE_OK. + * + * Return value: a new #GtkFileChooser + **/ +GtkWidget* +sokoke_file_chooser_dialog_new (const gchar* title, + GtkWindow* window, + GtkFileChooserAction action) +{ + const gchar* stock_id = GTK_STOCK_OPEN; + GtkWidget* dialog; + + if (action == GTK_FILE_CHOOSER_ACTION_SAVE) + stock_id = GTK_STOCK_SAVE; + #ifdef HAVE_HILDON_FM + dialog = hildon_file_chooser_dialog_new (window, action); + #else + dialog = gtk_file_chooser_dialog_new (title, window, action, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + stock_id, GTK_RESPONSE_OK, NULL); + gtk_window_set_icon_name (GTK_WINDOW (dialog), stock_id); + #endif + return dialog; +} diff --git a/midori/sokoke.h b/midori/sokoke.h index 1039a70a..f2155a3d 100644 --- a/midori/sokoke.h +++ b/midori/sokoke.h @@ -176,4 +176,9 @@ gboolean sokoke_window_activate_key (GtkWindow* window, GdkEventKey* event); +GtkWidget* +sokoke_file_chooser_dialog_new (const gchar* title, + GtkWindow* window, + GtkFileChooserAction action); + #endif /* !__SOKOKE_H__ */ diff --git a/midori/wscript_build b/midori/wscript_build index dd8c3a15..dbfb3810 100644 --- a/midori/wscript_build +++ b/midori/wscript_build @@ -10,7 +10,9 @@ obj.target = 'midori' obj.includes = '. ..' obj.find_sources_in_dirs ('.', excludes=['main.c']) obj.add_marshal_file ('marshal.list', 'midori_cclosure_marshal') -obj.uselib = 'UNIQUE LIBSOUP LIBIDN GIO GTK SQLITE WEBKIT LIBXML WS2_32 OPENSSL HILDON' +obj.uselib = 'UNIQUE LIBSOUP LIBIDN GIO GTK SQLITE WEBKIT LIBXML ' \ + 'WS2_32 OPENSSL' \ + 'HILDON HILDON_FM' obj.uselib_local = 'katze' obj.install_path = None diff --git a/wscript b/wscript index 76e09915..8547d1e1 100644 --- a/wscript +++ b/wscript @@ -223,6 +223,7 @@ def configure (conf): if check_pkg ('hildon-1', mandatory=False, var='HILDON'): check_pkg ('libosso', var='HILDON') check_pkg ('hildon-1', '2.2', var='HILDON_2_2') + check_pkg ('hildon-fm-2', var='HILDON_FM') hildon = ['N/A','yes'][conf.env['HAVE_HILDON'] == 1] if hildon != 'yes': option_checkfatal ('hildon', 'Maemo integration')