[grisbi-cvs] grisbi/src gsb_file_load.c, 1.218, 1.219 gsb_file_others.c, 1.35, 1.36 gsb_file_others.h, 1.4, 1.5 imputation_budgetaire.c, 1.164, 1.165

Pierre Biava pbiava at users.sourceforge.net
Sun Apr 18 14:47:07 CEST 2010


Update of /cvsroot/grisbi/grisbi/src
In directory sfp-cvsdas-2.v30.ch3.sourceforge.com:/tmp/cvs-serv29036/src

Modified Files:
	gsb_file_load.c gsb_file_others.c gsb_file_others.h 
	imputation_budgetaire.c 
Log Message:
Added ability to create a list of budget allocations from a file categories

Index: gsb_file_others.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/gsb_file_others.c,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -d -r1.35 -r1.36
--- gsb_file_others.c	5 Apr 2010 21:24:53 -0000	1.35
+++ gsb_file_others.c	18 Apr 2010 12:47:05 -0000	1.36
@@ -56,6 +56,12 @@
 					   gulong *length_calculated,
 					   gchar **file_content,
 					   gchar *version );
+static void gsb_file_others_start_budget_from_category ( GMarkupParseContext *context,
+				     const gchar *element_name,
+				     const gchar **attribute_names,
+				     const gchar **attribute_values,
+				     GSList **import_list,
+				     GError **error);
 static void gsb_file_others_start_element ( GMarkupParseContext *context,
 				     const gchar *element_name,
 				     const gchar **attribute_names,
@@ -533,8 +539,13 @@
 		    gsb_gui_navigation_add_report ( report_number );
 
 		    /* inform the user of that */
-		    dialogue_hint ( _("Some things in a report cannot be imported :\nThe selected lists of financial years, accounts, transfer accounts, categories, budgetaries, parties and kind of payments.\nSo that lists have been erased while the import.\nThe currencies have been set too on the first currency of this grisbi file.\nYou should check and modify that in the property box of that account."),
-				    _("Importing a report"));
+		    dialogue_hint ( _("Some things in a report cannot be imported :\n"
+                        "The selected lists of financial years, accounts, transfer accounts, "
+                        "categories, budgetaries, parties and kind of payments.\nSo that lists "
+                        "have been erased while the import.\nThe currencies have been set too "
+                        "on the first currency of this grisbi file.\nYou should check and modify "
+                        "that in the property box of that account."),
+				        _("Importing a report"));
 		}
 		break;
 	}
@@ -637,6 +648,23 @@
 		    dialogue_error ( _("This is not a report file, loading canceled..."));
 	    }
 	    break;
+
+	case 5:
+	    if ( !strncmp ( file_content,
+			    "<?xml version=\"1.0\"?>\n<Grisbi_categ>",
+			    36 ) )
+	    {
+		/* check if not before 0.6 */
+		if ( !strncmp ( file_content,
+				"<?xml version=\"1.0\"?>\n<Grisbi_categ>\n	<General\n",
+				47 ) )
+		    return TRUE;
+		else
+		    dialogue_error (_("The file version is below 0.6.0, Grisbi cannot import it."));
+	    }
+	    else
+		dialogue_error ( _("This is not a category file, loading canceled..."));
+	    break;
     }
 
     return FALSE;
@@ -707,3 +735,105 @@
 }
 
 
+gboolean gsb_file_others_load_budget_from_category ( const gchar *filename )
+{
+    gchar *file_content;
+    gchar* tmp_str;
+    GSList *import_list = NULL;
+
+    devel_debug (filename);
+
+    /* general check */
+    if ( !g_file_test ( filename, G_FILE_TEST_EXISTS ) )
+    {
+        tmp_str = g_strdup_printf (_("Cannot open file '%s': %s"),
+					 filename,
+					 latin2utf8 ( strerror ( errno ) ) );
+        dialogue_error ( tmp_str );
+        g_free ( tmp_str );
+        return FALSE;
+    }
+
+    /* check here if it's not a regular file */
+    if ( !g_file_test ( filename, G_FILE_TEST_IS_REGULAR ) )
+    {
+        tmp_str = g_strdup_printf ( 
+                        _("%s doesn't seem to be a regular file,\nplease check it and try again."),
+					   filename );
+        dialogue_error ( tmp_str );
+        g_free ( tmp_str );
+        return ( FALSE );
+    }
+
+    /* load the file */
+    if ( g_file_get_contents ( filename, &file_content, NULL, NULL ) )
+    {
+        GMarkupParser *markup_parser = g_malloc0 (sizeof (GMarkupParser));
+        GMarkupParseContext *context;
+
+        /* check if it's a good file */
+        if ( !gsb_file_others_check_file ( file_content, 5 ) )
+        {
+            g_free ( file_content );
+            return FALSE;
+        }
+
+        /* we load only after 0.6 files,
+         * there is very few people who will want to upgrade previous categories, budgets...
+         * and i'm too lazy to create an import for old files */
+        /* fill the GMarkupParser for a new xml structure */
+        markup_parser -> start_element = (void *) gsb_file_others_start_budget_from_category;
+        markup_parser -> error = (void *) gsb_file_load_error;
+
+        context = g_markup_parse_context_new ( markup_parser,
+                               0,
+                               &import_list,
+                               NULL );
+        g_markup_parse_context_parse ( context,
+                           file_content,
+                           strlen ( file_content ),
+                           NULL );
+
+        /* on remplit l'arbre des imputation */
+        remplit_arbre_imputation ( );
+
+        g_markup_parse_context_free ( context );
+        g_free ( markup_parser );
+        g_free ( file_content );
+
+        if ( etat.modification_fichier == 0 )
+            modification_fichier ( TRUE );
+    }
+    else
+    {
+        tmp_str = g_strdup_printf (_("Cannot open file '%s': %s"),
+					 filename,
+					 latin2utf8 ( strerror ( errno ) ) );
+        dialogue_error ( tmp_str );
+        g_free ( tmp_str );
+        return FALSE;
+    }
+
+    return TRUE;
+}
+
+
+void gsb_file_others_start_budget_from_category ( GMarkupParseContext *context,
+				     const gchar *element_name,
+				     const gchar **attribute_names,
+				     const gchar **attribute_values,
+				     GSList **import_list,
+				     GError **error)
+{
+    if ( !strcmp ( element_name, "Category" ) )
+    {
+	    gsb_file_load_budgetary ( attribute_names, attribute_values );
+	    return;
+    }
+
+    if ( !strcmp ( element_name, "Sub_category" ))
+    {
+	    gsb_file_load_sub_budgetary ( attribute_names, attribute_values );
+	    return;
+    }
+}

Index: gsb_file_others.h
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/gsb_file_others.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- gsb_file_others.h	18 Feb 2007 12:37:18 -0000	1.4
+++ gsb_file_others.h	18 Apr 2010 12:47:05 -0000	1.5
@@ -6,6 +6,7 @@
 
 /* START_DECLARATION */
 gboolean gsb_file_others_load_budget ( gchar *filename );
+gboolean gsb_file_others_load_budget_from_category ( const gchar *filename );
 gboolean gsb_file_others_load_category ( gchar *filename );
 gboolean gsb_file_others_load_report ( gchar *filename );
 gboolean gsb_file_others_save_budget ( gchar *filename );

Index: gsb_file_load.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/gsb_file_load.c,v
retrieving revision 1.218
retrieving revision 1.219
diff -u -d -r1.218 -r1.219
--- gsb_file_load.c	17 Apr 2010 15:37:03 -0000	1.218
+++ gsb_file_load.c	18 Apr 2010 12:47:05 -0000	1.219
@@ -2835,8 +2835,9 @@
         continue;
     }
 
-    if ( !strcmp ( attribute_names[i],
-                                   "Nbb" ))
+    if ( !strcmp ( attribute_names[i], "Nbb" )
+     ||
+     !strcmp ( attribute_names[i], "Nbc" )  )
     {
         budget_number = utils_str_atoi (attribute_values[i]);
         i++;

Index: imputation_budgetaire.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/imputation_budgetaire.c,v
retrieving revision 1.164
retrieving revision 1.165
diff -u -d -r1.164 -r1.165
--- imputation_budgetaire.c	14 Feb 2010 17:48:50 -0000	1.164
+++ imputation_budgetaire.c	18 Apr 2010 12:47:05 -0000	1.165
@@ -428,6 +428,11 @@
     gtk_file_chooser_set_filter ( GTK_FILE_CHOOSER ( dialog ), filter );
 
     filter = gtk_file_filter_new ();
+    gtk_file_filter_set_name ( filter, _("Grisbi category files (*.cgsb)") );
+    gtk_file_filter_add_pattern ( filter, "*.cgsb" );
+    gtk_file_chooser_add_filter ( GTK_FILE_CHOOSER ( dialog ), filter );
+
+    filter = gtk_file_filter_new ();
     gtk_file_filter_set_name ( filter, _("All files") );
     gtk_file_filter_add_pattern ( filter, "*" );
     gtk_file_chooser_add_filter ( GTK_FILE_CHOOSER ( dialog ), filter );
@@ -472,19 +477,17 @@
 
     switch ( resultat )
     {
-	case 2 :
-	    /* we want to replace the list */
-
-	    if ( !last_transaction_number )
-		gsb_data_budget_init_variables ();
+	    case 2 :
+            /* we want to replace the list */
+            if ( !last_transaction_number )
+                gsb_data_budget_init_variables ();
 
         case 1 :
-	    if ( !gsb_file_others_load_budget ( budget_name ))
-	    {
-		return;
-	    }
+            if ( g_str_has_suffix ( budget_name, ".cgsb" ) )
+                gsb_file_others_load_budget_from_category ( budget_name );
+            else
+                gsb_file_others_load_budget ( budget_name );
 	    break;
-
 	default :
 	    return;
     }
@@ -540,7 +543,8 @@
 					   G_CALLBACK(importer_ib),
 					   NULL );
     gtk_widget_set_tooltip_text ( GTK_WIDGET (button),
-				  SPACIFY(_("Import a Grisbi budgetary line file (.igsb)")));
+				  SPACIFY(_("Import a Grisbi budgetary line file (.igsb)"
+                            " or create from a list of categories (.cgsb)" )));
     gtk_box_pack_start ( GTK_BOX ( hbox2 ), button, FALSE, TRUE, 0 );
 
     /* Export button */



More information about the cvs mailing list