From eec68c5f5ff636b4e72a174b2d2bbbb3aeccfdb8 Mon Sep 17 00:00:00 2001 From: David Hampton Date: Wed, 19 Apr 2006 02:35:39 +0000 Subject: [PATCH] Parse the old ~/.gnome/GnuCash MDI document file to see which 1.8 reports should be opened the first time gnucash2 starts. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@13803 57a11ea4-9604-0410-9ed3-97b8803252fd --- ChangeLog | 7 ++ src/gnome/top-level.c | 2 +- src/report/report-gnome/window-report.c | 120 ++++++++++-------------- src/report/report-gnome/window-report.h | 3 +- 4 files changed, 57 insertions(+), 75 deletions(-) diff --git a/ChangeLog b/ChangeLog index b7c48249d0..26ddd1d162 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2006-04-18 David Hampton + + * src/report/report-gnome/window-report.[ch]: + * src/gnome/top-level.c: Parse the old ~/.gnome/GnuCash MDI + document file to see which 1.8 reports should be opened the first + time gnucash2 starts. + 2006-04-18 Christian Stimming * po/fr.po: Updated French translation by Jonathan Ernst. diff --git a/src/gnome/top-level.c b/src/gnome/top-level.c index 0f990f3ee3..6de50b37ca 100644 --- a/src/gnome/top-level.c +++ b/src/gnome/top-level.c @@ -252,7 +252,7 @@ gnc_restore_all_state (gpointer session, gpointer unused) SCM_BOOL_F)); /* At this point the reports have only been loaded into memory. Now we create their ui component. */ - gnc_reports_show_all(); + gnc_reports_show_all(session); #endif LEAVE("old"); diff --git a/src/report/report-gnome/window-report.c b/src/report/report-gnome/window-report.c index cd2ad1d1c2..5355d237b8 100644 --- a/src/report/report-gnome/window-report.c +++ b/src/report/report-gnome/window-report.c @@ -37,6 +37,7 @@ #include "dialog-options.h" #include "file-utils.h" +#include "gnc-gkeyfile-utils.h" #include "gnc-report.h" #include "gnc-ui.h" #include "option-util.h" @@ -47,7 +48,7 @@ #include "gnc-report.h" #define WINDOW_REPORT_CM_CLASS "window-report" - +#define MDI_CHILD_CONFIG "mdi_child_config" /******************************************************************** * @@ -320,79 +321,52 @@ gnc_report_init (void) } -static gboolean -remove_invalid_report(gpointer key, gpointer val, gpointer data) -{ - SCM report = val; - gchar *name = NULL; - - if (NULL == (name = gnc_report_name(report))) - return TRUE; - - g_free(name); - return FALSE; -} - -static gboolean -remove_old_report(gpointer key, gpointer val, gpointer data) -{ - SCM report = val; - GtkMessageDialog *dialog = GTK_MESSAGE_DIALOG(data); - gchar *name = NULL; - gchar *msg; - gint response; - - name = gnc_report_name(report); - msg = g_strdup_printf(_("Do you want to display '%s'?"), name); - gtk_message_dialog_set_markup(dialog, msg); - response = gtk_dialog_run(GTK_DIALOG(dialog)); - g_free(msg); - g_free(name); - return (response == GTK_RESPONSE_NO); -} - -static void -show_report(gpointer key, gpointer val, gpointer data) -{ - gnc_main_window_open_report(*(gint *)key, NULL); -} - void -gnc_reports_show_all(void) +gnc_reports_show_all(QofSession *session) { - GHashTable *reports = gnc_reports_get_global(); - - if (reports) { - GtkWidget *dialog; - guint num_reports; - gint response; - gchar *msg; - - g_hash_table_foreach_remove(reports, remove_invalid_report, NULL); - num_reports = g_hash_table_size(reports); - if (num_reports > 3) { - msg = g_strdup_printf( - _("GnuCash has found %d reports from an earlier version of " - "GnuCash but can't tell which ones you had open. You will " - "now have the option to open each report or not. From now " - "on, GnuCash will remember which reports you leave open, so " - "you won't see this message again."), num_reports); - dialog = gtk_message_dialog_new( - NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_INFO, - GTK_BUTTONS_OK_CANCEL, msg); - response = gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_destroy(dialog); - g_free(msg); - if (response == GTK_RESPONSE_OK) { - GtkWidget *dialog = gtk_message_dialog_new( - NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, - GTK_BUTTONS_YES_NO, NULL); - g_hash_table_foreach_remove(reports, remove_old_report, - dialog); - gtk_widget_destroy(dialog); - g_hash_table_foreach(reports, show_report, NULL); - } - } else - g_hash_table_foreach(reports, show_report, NULL); + GKeyFile *keyfile; + const gchar *home, *url; + gchar *encoded_url, *mdi_file, *mdi_group, *value; + gchar **keys, **key; + gint report_id; + + url = qof_session_get_url(session); + if (!url) + return; + encoded_url = gnc_html_encode_string(url); + if (!encoded_url) + return; + + home = g_get_home_dir(); + if (!home) { + g_free(encoded_url); + return; + } + + mdi_file = g_build_filename(home, ".gnome", "GnuCash", (gchar *)NULL); + mdi_group = g_strdup_printf("MDI : %s", encoded_url); + + keyfile = gnc_key_file_load_from_file (mdi_file, FALSE, FALSE); + if (keyfile) { + keys = g_key_file_get_keys(keyfile, mdi_group, NULL, NULL); + if (keys) { + for (key = keys; *key; key++) { + if (!strncmp(*key, MDI_CHILD_CONFIG, sizeof(MDI_CHILD_CONFIG))) + continue; + value = g_key_file_get_string(keyfile, mdi_group, *key, NULL); + if (!value) + continue; + if (sscanf(value, "gnc-report:id=%d", &report_id) == 1) { + gnc_main_window_open_report(report_id, NULL); + } + g_free(value); + } + g_strfreev(keys); } + g_key_file_free(keyfile); + } + + g_free(mdi_file); + g_free(mdi_group); + g_free(encoded_url); } diff --git a/src/report/report-gnome/window-report.h b/src/report/report-gnome/window-report.h index ee637e0de6..806d7f8fb6 100644 --- a/src/report/report-gnome/window-report.h +++ b/src/report/report-gnome/window-report.h @@ -26,6 +26,7 @@ #include #include "gnc-html.h" +#include "qof.h" typedef struct gnc_report_window_s gnc_report_window; @@ -45,5 +46,5 @@ void gnc_report_raise_editor(SCM report); // module[/plugin]-init void gnc_report_init (void); -void gnc_reports_show_all(void); +void gnc_reports_show_all (QofSession *session); #endif