GnuCash  5.6-150-g038405b370+
gnc-file.h
1 /********************************************************************\
2  * Copyright (C) 1997 Robin D. Clark *
3  * Copyright (C) 1998, 1999, 2000 Linas Vepstas (linas@linas.org) *
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, write to the Free Software *
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
18 \********************************************************************/
19 
20 /*
21  * FILE: gnc-file.h
22  *
23  * FUNCTION:
24  * A set of file-handling utilities for GnuCash applications.
25  * These utilities will "do the right thing" when used in the "Fileā€¦"
26  * pulldown menu, for the "New", "Open", "Save", "SaveAs", etc. menu entries.
27  * In particular, they will verify that old files don't get clobbered,
28  * they'll put up dialogue boxes to ask the user to confirm their actions,
29  * etc.
30  *
31  * These utilities are written in a GUI-independent fashion, and should
32  * work just fine with the Motif, gnome/gtk and Qt interfaces.
33  * These utilities are appropriate for direct invocation from guile.
34  *
35  * These GUI utilities implement and maintain a single global "session"
36  * that defines the currently edited account group. In a sense, these
37  * functions provide the GUI for the qof_session object. The session
38  * is essentially a file that is open for editing, with locks on it
39  * to prevent other readers and writers from accessing it as long as its
40  * open.
41  *
42  *
43  * The gnc_file_save() routine will check for an existing edit session,
44  * and if one exists, it will save the account info to a file.
45  * If an error occurs, a popup dialogue will inform the user of
46  * the error. If there is no existing filename open, then the
47  * user will be prompted for a file to save to (using the
48  * gnc_file_save_as() routine). The existing session will remain
49  * open for further editing.
50  *
51  * The gnc_file_save_as() routine will prompt the user for a filename
52  * to save the account data to (using the standard GUI file dialogue
53  * box). If the user specifies a filename, the account data will be
54  * saved. If an error occurs, a popup dialogue will inform the user
55  * of the error. One possible error is that another user has
56  * the indicated file already locked up in a different session
57  * (in which case it is up to the user to try again, or to pick
58  * a different filename). If it is possible to save without
59  * an error, then a new session is started for the indicated
60  * filename, locking out other users. This new session remains
61  * open for further editing.
62  *
63  * The gnc_file_query_save() routine will display a popup dialog asking
64  * the user if they wish to save their current work. If they answer
65  * "yes", their work will be saved (using the gncFileSave function),
66  * otherwise no action will be performed. If there is no currently
67  * locked session, a popup will query the user for a filename
68  * (using the gnc_file_save_as() routine). The routine will return
69  * TRUE if the user hits "Yes" or "No" and FALSE if the user
70  * hits "Cancel". If nothing needed to be saved, the routine
71  * will return TRUE.
72  *
73  * The gnc_file_new() routine will check for an existing edit session.
74  * If one exists, it will ask the user if they want to save it,
75  * (using the gnc_file_query_save_as() dialogue). Then the current
76  * session will be destroyed, file locks will be removed, and
77  * account group structures will be set up for a new session.
78  *
79  * The gnc_file_open() routine check for an existing edit session.
80  * If one exists, it will ask the user if they want to save it.
81  * (using the gnc_file_query_save() dialogue). Next, the user will
82  * be prompted with a GUI standard file-selection dialogue to
83  * to pick a new file. If no file is picked, this routine returns.
84  * If a new file was picked, then the current session will be
85  * destroyed and file locks on it will be removed. The new
86  * file will then be opened for editing, establishing locks, etc.
87  * If an error occurs, the user will be informed with a pop-up
88  * dialogue. If the file cannot be found, or if a read
89  * error occurs, a popup describing the error will pop up.
90  * One possible error is that another user has the indicated
91  * file already locked up in a different session (in which
92  * case it is up to the user to try again, or to pick
93  * a different filename).
94  *
95  * The gnc_file_revert() routine will discard any changes since the last
96  * time the session was saved (but only after user confirmation).
97  *
98  * The gnc_file_open_file() routine behaves much like the gnc_file_open()
99  * routine, except that the new file to open is passed as a char *
100  * argument.
101  *
102  * The gnc_file_export() routine will check for an existing edit
103  * session, and if one exists, it will save just the commodities
104  * and accounts to a file. If an error occurs, a popup dialogue
105  * will inform the user of the error.
106  *
107  * The gnc_file_quit() routine will close out and destroy the current session.
108  * The user WILL NOT BE PROMPTED to confirm this action, or do
109  * any kind of saving beforehand.
110  *
111  * HISTORY:
112  * Derived from Rob Clark's original MainWindow.c code, Dec 1998
113  */
114 
115 #ifndef GNC_FILE_H
116 #define GNC_FILE_H
117 
118 #include <glib.h>
119 #include "qof.h"
120 #include <gtk/gtk.h>
121 
122 #ifdef __cplusplus
123 extern "C" {
124 #endif
125 
126 typedef enum
127 {
128  GNC_FILE_DIALOG_OPEN,
129  GNC_FILE_DIALOG_IMPORT,
130  GNC_FILE_DIALOG_SAVE,
131  GNC_FILE_DIALOG_EXPORT
132 } GNCFileDialogType;
133 
134 void gnc_file_new (GtkWindow *parent);
135 gboolean gnc_file_open (GtkWindow *parent);
136 void gnc_file_export(GtkWindow *parent);
137 void gnc_file_save (GtkWindow *parent);
138 void gnc_file_save_as (GtkWindow *parent);
139 void gnc_file_do_export(GtkWindow *parent, const char* filename);
140 void gnc_file_do_save_as(GtkWindow *parent, const char* filename);
141 void gnc_file_revert (GtkWindow *parent);
142 
146 gboolean show_session_error (GtkWindow *parent,
147  QofBackendError io_error,
148  const char *newfile,
149  GNCFileDialogType type);
150 
151 char * gnc_file_dialog (GtkWindow *parent,
152  const char * title,
153  GList * filters,
154  const char * starting_dir,
155  GNCFileDialogType type);
156 
157 GSList * gnc_file_dialog_multi (GtkWindow *parent,
158  const char * title,
159  GList * filters,
160  const char * starting_dir,
161  GNCFileDialogType type);
162 
163 gboolean gnc_file_open_file (GtkWindow *parent,
164  const char *filename,
165  gboolean open_readonly);
166 
167 gboolean gnc_file_query_save (GtkWindow *parent, gboolean can_cancel);
168 
169 void gnc_file_quit (void);
170 
171 typedef void (*GNCShutdownCB) (int);
172 void gnc_file_set_shutdown_callback (GNCShutdownCB cb);
173 gboolean gnc_file_save_in_progress (void);
174 
175 #ifdef __cplusplus
176 }
177 #endif
178 
179 #endif /* GNC_FILE_H */
QofBackendError
The errors that can be reported to the GUI & other front-end users.
Definition: qofbackend.h:57