[grisbi-cvs] grisbi/src gsb_assistant_first.c, 1.17, 1.18 gsb_file.c, 1.38, 1.39 gsb_file_config.c, 1.66, 1.67 gsb_file_config.h, 1.9, 1.10 gsb_select_icon.c, 1.8, 1.9 parametres.c, 1.186, 1.187 parametres.h, 1.26, 1.27 utils_files.c, 1.35, 1.36 utils_files.h, 1.21, 1.22

Pierre Biava pbiava at users.sourceforge.net
Sun Jan 25 08:50:11 CET 2009


Update of /cvsroot/grisbi/grisbi/src
In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv4288/src

Modified Files:
	gsb_assistant_first.c gsb_file.c gsb_file_config.c 
	gsb_file_config.h gsb_select_icon.c parametres.c parametres.h 
	utils_files.c utils_files.h 
Log Message:
using the mechanisms described in the  XDG Base Directory Specification for the data files of grisbi + various bug fixes

Index: gsb_assistant_first.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/gsb_assistant_first.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- gsb_assistant_first.c	1 Nov 2008 21:59:44 -0000	1.17
+++ gsb_assistant_first.c	25 Jan 2009 07:50:09 -0000	1.18
@@ -36,6 +36,7 @@
 #include "./parametres.h"
 #include "./gsb_file.h"
 #include "./traitement_variables.h"
+#include "./utils_files.h"
 #include "./utils.h"
 #include "./structures.h"
 #include "./include.h"
@@ -89,6 +90,11 @@
     /* set up all the default variables */
     init_variables ();
 
+    /* set up the XDG Environment variables for linux*/
+    #ifndef _WIN32
+        utils_files_create_XDG_dir ( );
+    #endif
+
     /* now we launch the assistant */
     return_value = gsb_assistant_run (assistant);
     gtk_widget_destroy (assistant);
@@ -171,6 +177,7 @@
     GtkSizeGroup *size_group;
     gchar *text;
     GtkWidget *hbox;
+    GtkWidget *dialog;
 
     page = gtk_hbox_new (FALSE, 15);
     gtk_container_set_border_width ( GTK_CONTAINER (page),
@@ -268,12 +275,15 @@
     gtk_box_pack_start ( GTK_BOX ( hbox ), label,
 			 FALSE, FALSE, 0);
 
-    button = gtk_file_chooser_button_new (_("Select/Create backup directory"),
-					  GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER );
+    dialog = utils_files_create_file_chooser ( window,
+                        _("Select/Create backup directory") );
+    button = gtk_file_chooser_button_new_with_dialog (dialog);
+    gtk_file_chooser_set_current_folder ( GTK_FILE_CHOOSER (button),
+                        my_get_XDG_grisbi_data_dir () );
     g_signal_connect ( G_OBJECT (button),
-		       "current-folder-changed",
-		       G_CALLBACK (gsb_config_backup_dir_chosen),
-		       NULL );
+                        "selection-changed",
+                        G_CALLBACK (gsb_config_backup_dir_chosen),
+                        NULL );
     gtk_box_pack_start ( GTK_BOX ( hbox ), button,
 			 FALSE, TRUE, 0);
 

Index: gsb_file.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/gsb_file.c,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -d -r1.38 -r1.39
--- gsb_file.c	1 Jan 2009 20:43:49 -0000	1.38
+++ gsb_file.c	25 Jan 2009 07:50:09 -0000	1.39
@@ -595,7 +595,7 @@
      * filename-yyyy-mm-dd_mm:hh:ss */
     time ( &temps );
     day_time = localtime (&temps);
-    filename = g_strdup_printf ( "%s/%s_%d-%02d-%d_%d:%d:%d",
+    filename = g_strdup_printf ( "%s/%s_%d-%02d-%02d_%02d:%02d:%02d",
 				 gsb_file_get_backup_path (),
 				 name,
 				 day_time -> tm_year + 1900, day_time -> tm_mon + 1, day_time -> tm_mday,

Index: parametres.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/parametres.c,v
retrieving revision 1.186
retrieving revision 1.187
diff -u -d -r1.186 -r1.187
--- parametres.c	1 Jan 2009 20:43:49 -0000	1.186
+++ parametres.c	25 Jan 2009 07:50:09 -0000	1.187
@@ -46,6 +46,7 @@
 #include "./gsb_reconcile_config.h"
 #include "./gsb_reconcile_sort_config.h"
 #include "./traitement_variables.h"
+#include "./utils_files.h"
 #include "./affichage_liste.h"
 #include "./affichage.h"
 #include "./import.h"
@@ -649,6 +650,7 @@
     GtkWidget *hbox;
     GtkWidget *label;
     GtkWidget *button;
+    GtkWidget *dialog;
 
     vbox_pref = new_vbox_with_title_and_icon ( _("Files"),
 					       "files.png" );
@@ -765,15 +767,22 @@
     gtk_box_pack_start ( GTK_BOX ( hbox ), label,
 			 FALSE, FALSE, 0);
 
-    button = gtk_file_chooser_button_new (_("Select/Create backup directory"),
-					  GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER );
+    /* on passe par une fonction intermédiaire pour pallier à un bug
+     * du gtk_file_chooser_button_new qui donne le répertoire home
+     * lorsque l'on annule le choix du nouveau répertoire */
+    dialog = utils_files_create_file_chooser ( window,
+                        _("Select/Create backup directory") );
+    button = gtk_file_chooser_button_new_with_dialog (dialog);
     if (gsb_file_get_backup_path ())
-	gtk_file_chooser_set_current_folder ( GTK_FILE_CHOOSER (button),
-					      gsb_file_get_backup_path ());
+        gtk_file_chooser_set_current_folder ( GTK_FILE_CHOOSER (button),
+                        gsb_file_get_backup_path ());
+    else
+        gtk_file_chooser_set_current_folder ( GTK_FILE_CHOOSER (button),
+                        my_get_XDG_grisbi_data_dir () );
     g_signal_connect ( G_OBJECT (button),
-		       "current-folder-changed",
-		       G_CALLBACK (gsb_config_backup_dir_chosen),
-		       NULL );
+		       "selection-changed",
+		       G_CALLBACK ( gsb_config_backup_dir_chosen ),
+		       dialog );
     gtk_box_pack_start ( GTK_BOX ( hbox ), button,
 			 FALSE, TRUE, 0);
 
@@ -816,14 +825,15 @@
  * \return FALSE
  * */
 gboolean gsb_config_backup_dir_chosen ( GtkWidget *button,
-					gpointer null )
+					GtkWidget *dialog )
 {
     gchar *path;
 
     path = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (button));
+    devel_debug ( path);
     gsb_file_set_backup_path (path);
-    if (path)
-	g_free (path);
+    if (path && strlen (path) > 0)
+        g_free (path);
 
     modification_fichier (TRUE);
 

Index: parametres.h
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/parametres.h,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- parametres.h	21 Oct 2008 08:05:18 -0000	1.26
+++ parametres.h	25 Jan 2009 07:50:09 -0000	1.27
@@ -33,7 +33,7 @@
 
 /*START_DECLARATION*/
 gboolean gsb_config_backup_dir_chosen ( GtkWidget *button,
-					gpointer null );
+					GtkWidget *dialog );
 gboolean gsb_gui_encryption_toggled ( GtkWidget * checkbox, gpointer data );
 gboolean gsb_preferences_menu_open ( GtkWidget *menu_item,
 				     gpointer page_ptr );

Index: gsb_select_icon.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/gsb_select_icon.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- gsb_select_icon.c	24 Jan 2009 17:56:58 -0000	1.8
+++ gsb_select_icon.c	25 Jan 2009 07:50:09 -0000	1.9
@@ -319,7 +319,7 @@
 void gsb_select_icon_create_file_chooser ( GtkWidget * button, 
                                            gpointer user_data )
 {
-    GtkWidget * chooser;
+    GtkWidget *chooser;
     GtkFileFilter *filter;
     
     chooser = gtk_file_chooser_dialog_new ( _("Select icon directory"),

Index: utils_files.h
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/utils_files.h,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- utils_files.h	17 Jan 2009 07:23:53 -0000	1.21
+++ utils_files.h	25 Jan 2009 07:50:09 -0000	1.22
@@ -23,12 +23,15 @@
 			       gchar **string,
 			       const gchar *coding_system );
 GtkWidget * my_file_chooser ();
+gchar* my_get_XDG_grisbi_data_dir(void);
 gchar* my_get_XDG_grisbirc_dir(void);
 gchar* my_get_grisbirc_dir(void);
 gchar* my_get_gsb_file_default_dir(void);
 gchar * safe_file_name ( gchar* filename );
 FILE* utf8_fopen(const gchar* utf8filename,gchar* mode);
 gint utf8_remove(const gchar* utf8filename);
+gboolean utils_files_create_XDG_dir (void);
+GtkWidget *utils_files_create_file_chooser ( GtkWidget *parent, gchar * titre );
 /*END_DECLARATION*/
 
 #endif

Index: gsb_file_config.h
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/gsb_file_config.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- gsb_file_config.h	24 Jan 2009 17:56:58 -0000	1.9
+++ gsb_file_config.h	25 Jan 2009 07:50:09 -0000	1.10
@@ -18,6 +18,8 @@
 #else
 /* Some old Windows version have difficulties with dat starting file names */
 #define C_GRISBIRC  (g_strconcat ( "\\", PACKAGE, "rc", NULL))
+#define C_PATH_CONFIG (win32_get_grisbirc_folder_path( ))
+#define C_PATH_DATA_FILES (g_get_home_dir ( ))
 #endif
 
 

Index: utils_files.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/utils_files.c,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -d -r1.35 -r1.36
--- utils_files.c	24 Jan 2009 17:56:58 -0000	1.35
+++ utils_files.c	25 Jan 2009 07:50:09 -0000	1.36
@@ -40,7 +40,7 @@
 
 /*START_STATIC*/
 static void browse_file ( GtkButton *button, gpointer data );
-static gchar *utils_files_create_backup_name ( const gchar *filename );
+static void utils_files_file_chooser_cancel ( GtkWidget *bouton, GtkWidget *chooser);
 /*END_STATIC*/
 
 
@@ -49,10 +49,6 @@
 /*END_EXTERN*/
 
 
-
-
-
-
 /**
  * Handler triggered by clicking on the button of a "print to file"
  * combo.  Pop ups a file selector.
@@ -305,6 +301,81 @@
     return g_strdelimit ( my_strdup(filename), G_DIR_SEPARATOR_S, '_' );
 }
 
+
+/** 
+ * \brief pallie à un bug du gtk_file_chooser_button_new
+ *
+ * \param widget parent et titre de la femnêtre
+ *
+ * \return chooser
+ */
+GtkWidget *utils_files_create_file_chooser ( GtkWidget *parent, gchar * titre )
+{
+    GtkWidget *chooser;
+    GtkWidget *bouton_cancel, *bouton_OK;
+    
+    chooser = gtk_file_chooser_dialog_new ( titre,
+                        GTK_WINDOW (parent),
+                        GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
+                        NULL, NULL, NULL );
+
+    bouton_cancel = gtk_dialog_add_button (GTK_DIALOG ( chooser ),
+                                GTK_STOCK_CANCEL,
+                                GTK_RESPONSE_CANCEL);
+    g_signal_connect ( G_OBJECT (bouton_cancel),
+		       "clicked",
+		       G_CALLBACK (utils_files_file_chooser_cancel),
+		       chooser );
+
+    bouton_OK = gtk_dialog_add_button (GTK_DIALOG ( chooser ),
+                                GTK_STOCK_OPEN,
+                                GTK_RESPONSE_ACCEPT);
+
+	gtk_window_set_position ( GTK_WINDOW (chooser), GTK_WIN_POS_CENTER_ON_PARENT );
+    gtk_window_set_transient_for (GTK_WINDOW (chooser), GTK_WINDOW (parent));
+    gtk_widget_set_size_request ( chooser, 600, 750 );
+
+    return  chooser;
+}
+
+
+/** 
+ * \brief permet de pallier au bug de l'annulation du 
+ * gtk_file_chooser_button_new
+ *
+ * \param bouton appellant et chooser
+ */
+void utils_files_file_chooser_cancel ( GtkWidget *bouton, GtkWidget *chooser)
+{
+    gchar *path;
+
+    path = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser));
+    devel_debug ( path);
+    gtk_file_chooser_set_current_folder ( GTK_FILE_CHOOSER (chooser), path );
+    if (path && strlen (path) > 0)
+        g_free (path);
+}
+
+
+/** 
+ * \brief create the config and the data directories
+ * using the mechanisms described in the XDG Base Directory Specification
+ *
+ * \param 
+ *
+ * \return TRUE if ok
+ */
+gboolean utils_files_create_XDG_dir (void)
+{
+    if ( g_mkdir_with_parents ( C_PATH_CONFIG, 450 ) == 0 &&
+         g_mkdir_with_parents ( C_PATH_DATA_FILES, 450 ) == 0 )
+        return TRUE;
+    else
+        return FALSE;
+}
+
+
+/* comment by pbiava 24/01/2009 */
 /**
  * create a full path backup name from the filename
  * using the backup repertory and add the date and .bak
@@ -313,63 +384,64 @@
  *
  * \return a newly allocated string
  * */
-gchar *utils_files_create_backup_name ( const gchar *filename )
-{
-    gchar *string;
-    gchar *tmp_name;
-    GDate *today;
-    gchar **split;
-    gchar *inserted_string;
+//~ gchar *utils_files_create_backup_name ( const gchar *filename )
+//~ {
+    //~ gchar *string;
+    //~ gchar *tmp_name;
+    //~ GDate *today;
+    //~ gchar **split;
+    //~ gchar *inserted_string;
 
-    /* get the filename */
-    tmp_name = g_path_get_basename (filename);
+    //~ /* get the filename */
+    //~ tmp_name = g_path_get_basename (filename);
 
-    /* create the string to insert into the backup name */
-    today = gdate_today ();
-    inserted_string = g_strdup_printf ( "-%d_%d_%d-backup",
-					g_date_year (today),
-					g_date_month (today),
-					g_date_day (today));
-    g_date_free (today);
+    //~ /* create the string to insert into the backup name */
+    //~ today = gdate_today ();
+    //~ inserted_string = g_strdup_printf ( "-%d_%d_%d-backup",
+					//~ g_date_year (today),
+					//~ g_date_month (today),
+					//~ g_date_day (today));
+    //~ g_date_free (today);
 
-    /* insert the date and backup before .gsb if it exists */
-    split = g_strsplit ( tmp_name,
-			 ".",
-			 0 );
-    g_free (tmp_name);
+    //~ /* insert the date and backup before .gsb if it exists */
+    //~ split = g_strsplit ( tmp_name,
+			 //~ ".",
+			 //~ 0 );
+    //~ g_free (tmp_name);
 
-    if (split[1])
-    {
-	/* have extension */
-	gchar *tmpstr, *tmp_end;
+    //~ if (split[1])
+    //~ {
+	//~ /* have extension */
+	//~ gchar *tmpstr, *tmp_end;
 
-	tmp_end = g_strconcat ( inserted_string,
-				".",
-				split[g_strv_length (split) - 1],
-				NULL );
-	split[g_strv_length (split) - 1] = NULL;
+	//~ tmp_end = g_strconcat ( inserted_string,
+				//~ ".",
+				//~ split[g_strv_length (split) - 1],
+				//~ NULL );
+	//~ split[g_strv_length (split) - 1] = NULL;
 
-	tmpstr = g_strjoinv ( ".",
-			      split );
-	tmp_name = g_strconcat ( tmpstr,
-				 tmp_end,
-				 NULL );
-	g_free (tmpstr);
-	g_free (tmp_end);
-    }
-    else
-	tmp_name = g_strconcat ( split[0],
-				 inserted_string,
-				 NULL );
+	//~ tmpstr = g_strjoinv ( ".",
+			      //~ split );
+	//~ tmp_name = g_strconcat ( tmpstr,
+				 //~ tmp_end,
+				 //~ NULL );
+	//~ g_free (tmpstr);
+	//~ g_free (tmp_end);
+    //~ }
+    //~ else
+	//~ tmp_name = g_strconcat ( split[0],
+				 //~ inserted_string,
+				 //~ NULL );
 
-    g_strfreev (split);
+    //~ g_strfreev (split);
+
+    //~ string = g_build_filename ( gsb_file_get_backup_path (),
+				//~ tmp_name,
+				//~ NULL );
+    //~ g_free (tmp_name);
+    //~ return string;
+//~ }
 
-    string = g_build_filename ( gsb_file_get_backup_path (),
-				tmp_name,
-				NULL );
-    g_free (tmp_name);
-    return string;
-}
 
 /* Local Variables: */
 /* c-basic-offset: 4 */

Index: gsb_file_config.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/gsb_file_config.c,v
retrieving revision 1.66
retrieving revision 1.67
diff -u -d -r1.66 -r1.67
--- gsb_file_config.c	24 Jan 2009 17:56:58 -0000	1.66
+++ gsb_file_config.c	25 Jan 2009 07:50:09 -0000	1.67
@@ -48,7 +48,6 @@
 /*START_STATIC*/
 static gchar *gsb_config_get_old_conf_name ( void );
 static void gsb_file_config_clean_config ( void );
-static gboolean gsb_file_config_create_config_rep ( void );
 static void gsb_file_config_get_xml_text_element ( GMarkupParseContext *context,
 					     const gchar *text,
 					     gsize text_len,  
@@ -716,11 +715,13 @@
     conf_file = fopen ( filename,
 			  "w" );
 
+    #ifndef _WIN32
     if ( !conf_file )
     {
-        gsb_file_config_create_config_rep ( );
+        utils_files_create_XDG_dir ( );
         conf_file = fopen ( filename, "w" );
     }
+    #endif
 
     if ( !conf_file
 	 ||
@@ -1173,7 +1174,7 @@
     
     etat.force_enregistrement = 1;     /* par défaut, on force l'enregistrement */
     gsb_file_update_last_path (g_get_home_dir ());
-    gsb_file_set_backup_path (g_get_home_dir ());
+    gsb_file_set_backup_path (my_get_XDG_grisbi_data_dir ());
     etat.make_backup = 1;       /* on force aussi le backup pbiava le 24/01/2009*/
     etat.make_backup_every_minutes = FALSE;
     etat.make_backup_nb_minutes = 0;
@@ -1241,23 +1242,6 @@
 }
 
 
-/**
- * create the config repertory 
- * using the mechanisms described in the XDG Base Directory Specification
- *
- * \param
- *
- * \return TRUE if ok
- * */
-gboolean gsb_file_config_create_config_rep ( void )
-{
-    /* permissions = 450 trouvé au pif */
-    if ( g_mkdir_with_parents ( C_PATH_CONFIG, 450 ) == 0 )
-        return TRUE;
-    else
-        return FALSE;
-}
-
 static void gsb_file_config_remove_old_config_file ( gchar *filename )
 {
     GtkWidget *dialog;



More information about the cvs mailing list