GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
dialog-new-user.c
1 /********************************************************************\
2  * dialog-new-user.c -- new user dialog for GnuCash *
3  * Copyright (C) 2001 Dave Peticolas <[email protected]> *
4  * *
5  * This program is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU General Public License as *
7  * published by the Free Software Foundation; either version 2 of *
8  * the License, or (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License*
16  * along with this program; if not, contact: *
17  * *
18  * Free Software Foundation Voice: +1-617-542-5942 *
19  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
20  * Boston, MA 02110-1301, USA [email protected] *
21 \********************************************************************/
22 
23 #include "config.h"
24 
25 #include <gtk/gtk.h>
26 #include <glib/gi18n.h>
27 
28 #include "dialog-new-user.h"
29 #include "dialog-utils.h"
30 #include "dialog-file-access.h"
31 #include "assistant-hierarchy.h"
32 #include "gnc-engine.h"
33 #include "gnc-hooks.h"
34 #include "gnc-ui.h"
35 #include "gnc-file.h"
36 #include "gnc-prefs.h"
37 #include "gnc-main-window.h"
39 #include "gnc-session.h"
40 #include "app-utils/gnc-ui-util.h" // for gnc_get_current_book
41 
42 /* This static indicates the debugging module that this .o belongs to. */
43 static QofLogModule log_module = GNC_MOD_GUI;
44 
45 /* function to open a qif import assistant */
46 static void (*qifImportAssistantFcn)(void) = NULL;
47 
48 static void gnc_ui_new_user_cancel_dialog (void);
49 
50 void
51 gnc_new_user_dialog_register_qif_assistant (void (*cb_fcn)(void))
52 {
53  g_return_if_fail (qifImportAssistantFcn == NULL);
54  qifImportAssistantFcn = cb_fcn;
55 }
56 
57 void
58 gnc_set_first_startup (gboolean first_startup)
59 {
60  gnc_prefs_set_bool (GNC_PREFS_GROUP_NEW_USER, GNC_PREF_FIRST_STARTUP, first_startup);
61 }
62 
63 static void
64 after_hierarchy_assistant(void)
65 {
66  gncp_new_user_finish ();
67  gnc_set_first_startup (FALSE);
68 
69  qof_book_mark_session_dirty(gnc_get_current_book());
70  gnc_ui_file_access_for_save_as();
71 }
72 
73 void
74 gnc_ui_new_user_dialog (void)
75 {
76  GtkWidget *dialog;
77  GtkWidget *new_accounts_button;
78  GtkWidget *import_qif_button;
79  GtkWidget *tutorial_button;
80  GtkBuilder *builder;
81  gint result;
82 
83  ENTER(" ");
84  builder = gtk_builder_new();
85  gnc_builder_add_from_file (builder, "dialog-new-user.glade", "New User Dialog");
86 
87  dialog = GTK_WIDGET(gtk_builder_get_object (builder, "New User Dialog"));
88 
89  new_accounts_button = GTK_WIDGET(gtk_builder_get_object (builder, "new_accounts_button"));
90  import_qif_button = GTK_WIDGET(gtk_builder_get_object (builder, "import_qif_button"));
91  tutorial_button = GTK_WIDGET(gtk_builder_get_object (builder, "tutorial_button"));
92 
93  /* Set the sensitivity of the qif-import button based on the availability
94  * of the qif-import assistant.
95  */
96  gtk_widget_set_sensitive (import_qif_button, (qifImportAssistantFcn != NULL));
97 
98  result = gtk_dialog_run (GTK_DIALOG (dialog));
99  switch (result)
100  {
101  case GTK_RESPONSE_CANCEL:
102  case GTK_RESPONSE_DELETE_EVENT:
103  gnc_ui_new_user_cancel_dialog ();
104  break;
105  case GTK_RESPONSE_OK:
106  if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (new_accounts_button)))
107  {
108  gnc_ui_hierarchy_assistant_with_callback(TRUE, after_hierarchy_assistant);
109  }
110  else if ((qifImportAssistantFcn != NULL)
111  && gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (import_qif_button)))
112  {
113  qifImportAssistantFcn();
114  gncp_new_user_finish ();
115  }
116  else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (tutorial_button)))
117  {
118  gnc_gnome_help (HF_GUIDE, NULL);
119  gncp_new_user_finish ();
120  }
121  break;
122  default:
123  g_print ("DEBUG: Response: %d", result);
124  g_assert_not_reached ();
125  break;
126  }
127 
128  g_object_unref(G_OBJECT(builder));
129  gtk_widget_destroy (dialog);
130  LEAVE(" ");
131 }
132 
133 static void
134 gnc_ui_new_user_cancel_dialog (void)
135 {
136  GtkWidget *dialog;
137  GtkBuilder *builder;
138  gint result;
139  gboolean keepshowing;
140 
141  builder = gtk_builder_new();
142  gnc_builder_add_from_file (builder, "dialog-new-user.glade", "New User Cancel Dialog");
143 
144  dialog = GTK_WIDGET(gtk_builder_get_object (builder, "New User Cancel Dialog"));
145 
146  result = gtk_dialog_run (GTK_DIALOG (dialog));
147  keepshowing = (result == GTK_RESPONSE_YES);
148 
149  gnc_set_first_startup (keepshowing);
150  gncp_new_user_finish ();
151 
152  g_object_unref(G_OBJECT(builder));
153  gtk_widget_destroy(dialog);
154 }
155 
156 void
157 gncp_new_user_finish (void)
158 {
159  gnc_hook_run(HOOK_BOOK_OPENED, gnc_get_current_session());
160 }
utility functions for the GnuCash UI
#define ENTER(format, args...)
Definition: qoflog.h:261
Functions for adding content to a window.
gboolean gnc_prefs_set_bool(const gchar *group, const gchar *pref_name, gboolean value)
Definition: gnc-prefs.c:282
void gnc_gnome_help(const char *file_name, const char *anchor)
All type declarations for the whole Gnucash engine.
void qof_book_mark_session_dirty(QofBook *book)
Generic api to store and retrieve preferences.
Functions providing a chart of account page.
#define LEAVE(format, args...)
Definition: qoflog.h:271
const gchar * QofLogModule
Definition: qofid.h:89