[Gnucash-changes] r14142 - gnucash/trunk - Extend gnc_file_dialog to take a GList of GtkFileFilters instead of a filter string. Allows patterns like *.[Qq][Ii][Ff] without messing up the dialog, fixes #336124.

Andreas Köhler andi5 at cvs.gnucash.org
Sat May 20 06:25:05 EDT 2006


Author: andi5
Date: 2006-05-20 06:25:04 -0400 (Sat, 20 May 2006)
New Revision: 14142
Trac: http://svn.gnucash.org/trac/changeset/14142

Modified:
   gnucash/trunk/ChangeLog
   gnucash/trunk/src/gnome-utils/gnc-file.c
   gnucash/trunk/src/gnome-utils/gnc-file.h
   gnucash/trunk/src/import-export/log-replay/gnc-log-replay.c
   gnucash/trunk/src/import-export/qif-import/druid-qif-import.c
Log:
Extend gnc_file_dialog to take a GList of GtkFileFilters instead of a filter string. Allows patterns like *.[Qq][Ii][Ff] without messing up the dialog, fixes #336124.


Modified: gnucash/trunk/ChangeLog
===================================================================
--- gnucash/trunk/ChangeLog	2006-05-20 05:54:17 UTC (rev 14141)
+++ gnucash/trunk/ChangeLog	2006-05-20 10:25:04 UTC (rev 14142)
@@ -1,3 +1,12 @@
+2006-05-20  Andreas Köhler  <andi5.py at gmx.net>
+
+	* src/gnome-utils/gnc-file.[ch]:
+	* src/import-export/log-replay/gnc-log-replay.c:
+	* src/import-export/qif-import/druid-qif-import.c: Extend
+	  gnc_file_dialog to take a GList of GtkFileFilters instead of a
+	  filter string. Allows patterns like *.[Qq][Ii][Ff] without
+	  messing up the dialog, fixes #336124.
+
 2006-05-19  David Hampton  <hampton at employees.org>
 
 	* src/register/register-gnome/gnucash-grid.c: Make the blue

Modified: gnucash/trunk/src/gnome-utils/gnc-file.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-file.c	2006-05-20 05:54:17 UTC (rev 14141)
+++ gnucash/trunk/src/gnome-utils/gnc-file.c	2006-05-20 10:25:04 UTC (rev 14142)
@@ -65,7 +65,8 @@
  *   or presses "Cancel" or the window manager destroy button)      * 
  *                                                                  * 
  * Args:   title        - the title of the window                   *
- *         filter       - the file filter to use                    * 
+ *         filters      - list of GtkFileFilters to use, will be    *
+                          freed automatically                       *
  *         default_dir  - start the chooser in this directory       *
  *         type         - what type of dialog (open, save, etc.)    *
  * Return: containing the name of the file the user selected        *
@@ -73,7 +74,7 @@
 
 char *
 gnc_file_dialog (const char * title,
-                 const char * filter,
+                 GList * filters,
                  const char * starting_dir,
 		 GNCFileDialogType type
 		 )
@@ -144,14 +145,16 @@
 			       GTK_WINDOW(gnc_ui_get_toplevel()));
   */
 
-  if (filter != NULL)
+  if (filters != NULL)
   {
-    GtkFileFilter* g_filter = gtk_file_filter_new();
+    GList* filter;
     GtkFileFilter* all_filter = gtk_file_filter_new();
 
-    gtk_file_filter_set_name (g_filter, filter);
-    gtk_file_filter_add_pattern (g_filter, filter);
-    gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (file_box), g_filter);
+    for (filter=filters; filter; filter=filter->next) {
+      g_return_val_if_fail(GTK_IS_FILE_FILTER(filter->data), NULL);
+      gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (file_box),
+				   GTK_FILE_FILTER (filter->data));
+    }
 
     gtk_file_filter_set_name (all_filter, _("All files"));
     gtk_file_filter_add_pattern (all_filter, "*");
@@ -161,7 +164,9 @@
      * The latter wins, and the filter ends up diabled.  Since we are
      * only settin the starting directory for the chooser dialog,
      * everything works as expected. */
-    gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (file_box), g_filter);
+    gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (file_box),
+				 GTK_FILE_FILTER (filters->data));
+    g_list_free (filters);
   }
 
   response = gtk_dialog_run(GTK_DIALOG(file_box));

Modified: gnucash/trunk/src/gnome-utils/gnc-file.h
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-file.h	2006-05-20 05:54:17 UTC (rev 14141)
+++ gnucash/trunk/src/gnome-utils/gnc-file.h	2006-05-20 10:25:04 UTC (rev 14142)
@@ -137,7 +137,7 @@
 			     GNCFileDialogType type);
 
 char * gnc_file_dialog (const char * title,
-			const char * filter,
+			GList * filters,
 			const char * starting_dir,
 			GNCFileDialogType type);
 

Modified: gnucash/trunk/src/import-export/log-replay/gnc-log-replay.c
===================================================================
--- gnucash/trunk/src/import-export/log-replay/gnc-log-replay.c	2006-05-20 05:54:17 UTC (rev 14141)
+++ gnucash/trunk/src/import-export/log-replay/gnc-log-replay.c	2006-05-20 10:25:04 UTC (rev 14142)
@@ -499,6 +499,7 @@
   char *default_dir;
   char read_buf[256];
   char *read_retval;
+  GtkFileFilter *filter;
   FILE *log_file;
   char * record_start_str = "===== START";
   /* NOTE: This string must match src/engine/TransLog.c (sans newline) */
@@ -517,8 +518,12 @@
   default_dir = gnc_gconf_get_string(GCONF_SECTION, KEY_LAST_PATH, NULL);
   if (default_dir == NULL)
     gnc_init_default_directory(&default_dir);
+
+  filter = gtk_file_filter_new();
+  gtk_file_filter_set_name(filter, "*.log");
+  gtk_file_filter_add_pattern(filter, "*.[Ll][Oo][Gg]");
   selected_filename = gnc_file_dialog(_("Select a .log file to replay"),
-				      "*.log",
+				      g_list_prepend(NULL, filter),
 				      default_dir,
 				      GNC_FILE_DIALOG_OPEN);
 

Modified: gnucash/trunk/src/import-export/qif-import/druid-qif-import.c
===================================================================
--- gnucash/trunk/src/import-export/qif-import/druid-qif-import.c	2006-05-20 05:54:17 UTC (rev 14141)
+++ gnucash/trunk/src/import-export/qif-import/druid-qif-import.c	2006-05-20 10:25:04 UTC (rev 14142)
@@ -348,6 +348,7 @@
                                  gpointer user_data)
 {
   QIFImportWindow * wind = user_data;
+  GtkFileFilter *filter;
   char * new_file_name;
   char *file_name, *default_dir;
 
@@ -355,9 +356,15 @@
   default_dir = gnc_gconf_get_string(GCONF_SECTION, KEY_LAST_PATH, NULL);
   if (default_dir == NULL)
     gnc_init_default_directory(&default_dir);
-  new_file_name = gnc_file_dialog (_("Select QIF File"), "*.qif", 
-		  default_dir, GNC_FILE_DIALOG_IMPORT);
 
+  filter = gtk_file_filter_new ();
+  gtk_file_filter_set_name (filter, "*.qif");
+  gtk_file_filter_add_pattern (filter, "*.[Qq][Ii][Ff]");
+  new_file_name = gnc_file_dialog (_("Select QIF File"),
+				   g_list_prepend (NULL, filter),
+				   default_dir,
+				   GNC_FILE_DIALOG_IMPORT);
+
   /* Insure valid data, and something that can be freed. */
   if (new_file_name == NULL) {
     file_name = g_strdup(default_dir);



More information about the gnucash-changes mailing list