Patch for using gtk_file_chooser instead of gtk_file_selection

Emmanuel Saracco <[email protected]>
Newsgroups gmane.comp.audio.jamin.devel
Message-ID <1179065763.3595.30.camel@localhost>
Hi,

Thanks for committed my previous patch :-)

So, here you are with the second little "cosmetic" patch.

This patch add ability to use gtk_file_chooser_* instead of
gtk_file_selection_* when GTK+ >= 2.4:

* Added a "GTK_VERSION_GE()" macro in main.h (is it the right place?).

* Updated callbacks and "on_open1_activate()" and
"on_save_as1_activate()" functions.

Tell me if it is ok for you.

Thanks,

Bye

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

_______________________________________________
Jamin-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jamin-devel
jamin-0.96.02-gtk_file_chooser.patch (text/x-patch, 5.3 KB)
diff -u -x CVS jamin_orig/src/callbacks.c jamin/src/callbacks.c
--- jamin_orig/src/callbacks.c	2007-05-13 15:24:37.000000000 +0200
+++ jamin/src/callbacks.c	2007-05-13 16:03:24.000000000 +0200
@@ -1270,6 +1270,35 @@
 on_open1_activate                      (GtkMenuItem     *menuitem,
                                         gpointer         user_data)
 {
+#if GTK_VERSION_GE(2, 4)
+
+    GtkFileChooser *file_selector;
+    GtkFileFilter *filter = gtk_file_filter_new ();
+
+    file_selector = (GtkFileChooser *) gtk_file_chooser_dialog_new (
+      _("Select a session file"),
+      NULL,
+      GTK_FILE_CHOOSER_ACTION_OPEN,
+      GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+      GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
+      NULL
+    );
+
+    if (jamin_dir) {
+        gtk_file_chooser_set_current_folder (file_selector, jamin_dir);
+    }
+
+    gtk_file_filter_add_pattern (filter, "*.jam");
+    gtk_file_chooser_set_filter (file_selector, filter);
+
+    if (gtk_dialog_run (GTK_DIALOG (file_selector)) == GTK_RESPONSE_ACCEPT) {
+        s_load_session_from_ui (NULL, (gpointer) file_selector);
+    }
+
+    gtk_widget_destroy (GTK_WIDGET (file_selector));
+
+#else
+
     GtkFileSelection    *file_selector;
 
     file_selector = 
@@ -1291,6 +1320,8 @@
         "clicked", G_CALLBACK (gtk_widget_destroy), (gpointer) file_selector);
 
     gtk_widget_show ((GtkWidget *) file_selector);
+
+#endif
 }
 
 
@@ -1298,13 +1329,45 @@
 on_save_as1_activate                   (GtkMenuItem     *menuitem,
                                         gpointer         user_data)
 {
-    GtkFileSelection    *file_selector;
     gchar *fname = NULL;
 
     if (s_have_session_filename ()) {
         fname = s_get_session_filename ();
     }
 
+#if GTK_VERSION_GE(2, 4)
+
+    GtkFileChooser *file_selector;
+
+    file_selector = (GtkFileChooser *) gtk_file_chooser_dialog_new (
+      _("Select a session file"),
+      NULL,
+      GTK_FILE_CHOOSER_ACTION_SAVE,
+      GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+      GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
+      NULL
+    );
+
+    if (jamin_dir) {
+        gtk_file_chooser_set_current_folder (file_selector, jamin_dir);
+    }
+
+    if (fname != NULL) {
+        gtk_file_chooser_set_current_name (file_selector, fname);
+    } else {
+        gtk_file_chooser_set_current_name (file_selector, "default.jam");
+    }
+
+    if (gtk_dialog_run (GTK_DIALOG (file_selector)) == GTK_RESPONSE_ACCEPT) {
+        s_save_session_from_ui (NULL, (gpointer) file_selector);
+    }
+
+    gtk_widget_destroy (GTK_WIDGET (file_selector));
+
+#else
+
+    GtkFileSelection    *file_selector;
+
     file_selector = 
       (GtkFileSelection *) gtk_file_selection_new (_("Select a session file"));
 
@@ -1319,8 +1382,6 @@
         gtk_file_selection_complete (file_selector, "default.jam");
       }
 
-
-
     g_signal_connect (GTK_OBJECT (file_selector->ok_button),
         "clicked", G_CALLBACK (s_save_session_from_ui), file_selector);
 
@@ -1331,6 +1392,8 @@
         "clicked", G_CALLBACK (gtk_widget_destroy), (gpointer) file_selector);
 
     gtk_widget_show ((GtkWidget *) file_selector);
+
+#endif
 }
 
 
diff -u -x CVS jamin_orig/src/main.h jamin/src/main.h
--- jamin_orig/src/main.h	2004-01-07 23:55:54.000000000 +0100
+++ jamin/src/main.h	2007-05-13 15:50:37.000000000 +0200
@@ -25,6 +25,7 @@
  * JAMIN_DATA_DIR	installed data (pixmaps, etc.)
  * JAMIN_PIXMAP_DIR	installed images
  * JAMIN_EXAMPLES_DIR	installed examples
+ * GTK_VERSION_GE       check if GTK version is greater or equal to a given version number
  */
 #define JAMIN_DIR ".jamin"
 #define JAMIN_UI "jamin_ui"
@@ -32,6 +33,7 @@
 #define JAMIN_DATA_DIR PACKAGE_DATA_DIR "/jamin"
 #define JAMIN_PIXMAP_DIR JAMIN_DATA_DIR "/pixmaps/"
 #define JAMIN_EXAMPLES_DIR JAMIN_DATA_DIR "/examples/"
+#define GTK_VERSION_GE(major, minor) ((GTK_MAJOR_VERSION>major)||(GTK_MAJOR_VERSION==major)&&(GTK_MINOR_VERSION>=minor))
 
 extern GtkWidget *main_window;		/* Main GTK window */
 extern char *jamin_dir;			/* JAMin config directory path */
diff -u -x CVS jamin_orig/src/state.c jamin/src/state.c
--- jamin_orig/src/state.c	2007-05-13 15:24:37.000000000 +0200
+++ jamin/src/state.c	2007-05-13 15:53:42.000000000 +0200
@@ -476,9 +476,22 @@
 
 void s_save_session_from_ui (GtkWidget *w, gpointer user_data)
 {
+#if GTK_VERSION_GE(2, 4)
+
+    gchar *fname = NULL;
+    GtkFileChooser *file_selector = (GtkFileChooser *) user_data;
+
+    fname = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (file_selector));
+    s_save_session (fname);
+    g_free (fname);
+
+#else
+
     GtkFileSelection *file_selector = (GtkFileSelection *) user_data;
 
     s_save_session(gtk_file_selection_get_filename (GTK_FILE_SELECTION (file_selector)));
+
+#endif
 }
     
 void s_save_session (const gchar *fname)
@@ -615,10 +628,23 @@
 
 void s_load_session_from_ui (GtkWidget *w, gpointer user_data)
 {
+#if GTK_VERSION_GE(2, 4)
+
+    gchar *fname = NULL;
+    GtkFileChooser *file_selector = (GtkFileChooser *) user_data;
+
+    fname = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (file_selector));
+    s_load_session (fname);
+    g_free (fname);
+
+#else
+
     GtkFileSelection *file_selector = (GtkFileSelection *) user_data;
 
     s_load_session(gtk_file_selection_get_filename (GTK_FILE_SELECTION
                                                 (file_selector)));
+
+#endif
 }
     
 void s_load_session (const gchar *fname)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.