]> spindle.queued.net Git - midori/commitdiff
Wrap file chooser into the function sokoke_file_chooser_dialog_new
authorChristian Dywan <christian@twotoasts.de>
Sat, 14 Nov 2009 16:38:16 +0000 (17:38 +0100)
committerChristian Dywan <christian@twotoasts.de>
Sat, 14 Nov 2009 21:50:20 +0000 (22:50 +0100)
midori/midori-browser.c
midori/sokoke.c
midori/sokoke.h
midori/wscript_build
wscript

index a0a880b62c695474bf93e13a05b4190e67c3101e..bc18407d6e6c3ef5469c80717aed6d03720536f8 100644 (file)
@@ -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;
 
index 2f488160c9e5d3cc1674f3630253b23ba940f1c3..0a0ef43407bc002316cb954dcd86cea7f2d61ca4 100644 (file)
     #include <idna.h>
 #endif
 
+#ifdef HAVE_HILDON_FM
+    #include <hildon/hildon-file-chooser-dialog.h>
+#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;
+}
index 1039a70a583b1ca6fc4f0846df5f172a4152e7d0..f2155a3db8a0ed1697e105b4fef86e3661e895dd 100644 (file)
@@ -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__ */
index dd8c3a15fa9083519b7cc84bb547fd2aaaa0d443..dbfb38109c5ab36de22148ae14b790e2e24363ff 100644 (file)
@@ -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 76e09915ba35785c4caca405f8052edaed1f40e7..8547d1e1d7cd88f68d36e9119441a2485a3cd009 100644 (file)
--- 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')