GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
gnc-file.h
1 /********************************************************************\
2  * Copyright (C) 1997 Robin D. Clark *
3  * Copyright (C) 1998, 1999, 2000 Linas Vepstas ([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, 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 xaccSession 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_open_file() routine behaves much like the gnc_file_open()
96  * routine, except that the new file to open is passed as a char *
97  * argument.
98  *
99  * The gnc_file_export() routine will check for an existing edit
100  * session, and if one exists, it will save just the commodities
101  * and accounts to a file. If an error occurs, a popup dialogue
102  * will inform the user of the error.
103  *
104  * The gnc_file_quit() routine will close out and destroy the current session.
105  * The user WILL NOT BE PROMPTED to confirm this action, or do do
106  * any kind of saving beforehand.
107  *
108  * HISTORY:
109  * Derived from Rob Clark's original MainWindow.c code, Dec 1998
110  */
111 
112 #ifndef GNC_FILE_H
113 #define GNC_FILE_H
114 
115 #include <glib.h>
116 #include "qof.h"
117 
118 typedef enum
119 {
120  GNC_FILE_DIALOG_OPEN,
121  GNC_FILE_DIALOG_IMPORT,
122  GNC_FILE_DIALOG_SAVE,
123  GNC_FILE_DIALOG_EXPORT
124 } GNCFileDialogType;
125 
126 void gnc_file_new (void);
127 gboolean gnc_file_open (void);
128 void gnc_file_export(void);
129 void gnc_file_save (void);
130 void gnc_file_save_as (void);
131 void gnc_file_do_export(const char* filename);
132 void gnc_file_do_save_as(const char* filename);
133 
137 gboolean show_session_error (QofBackendError io_error,
138  const char *newfile,
139  GNCFileDialogType type);
140 
141 char * gnc_file_dialog (const char * title,
142  GList * filters,
143  const char * starting_dir,
144  GNCFileDialogType type);
145 
146 gboolean gnc_file_open_file (const char *filename, gboolean open_readonly);
147 
148 gboolean gnc_file_query_save (gboolean can_cancel);
149 
150 void gnc_file_quit (void);
151 
152 typedef void (*GNCShutdownCB) (int);
153 void gnc_file_set_shutdown_callback (GNCShutdownCB cb);
154 gboolean gnc_file_save_in_progress (void);
155 
156 #endif /* GNC_FILE_H */
QofBackendError
The errors that can be reported to the GUI & other front-end users.
Definition: qofbackend.h:59