GnuCash 2.4.99
gnc-file.h
00001 /********************************************************************\
00002  * Copyright (C) 1997 Robin D. Clark                                *
00003  * Copyright (C) 1998, 1999, 2000 Linas Vepstas (linas@linas.org)   *
00004  *                                                                  *
00005  * This program is free software; you can redistribute it and/or    *
00006  * modify it under the terms of the GNU General Public License as   *
00007  * published by the Free Software Foundation; either version 2 of   *
00008  * the License, or (at your option) any later version.              *
00009  *                                                                  *
00010  * This program is distributed in the hope that it will be useful,  *
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
00013  * GNU General Public License for more details.                     *
00014  *                                                                  *
00015  * You should have received a copy of the GNU General Public License*
00016  * along with this program; if not, write to the Free Software      *
00017  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.        *
00018 \********************************************************************/
00019 
00020 /*
00021  * FILE: gnc-file.h
00022  *
00023  * FUNCTION:
00024  * A set of file-handling utilities for GnuCash applications.
00025  * These utilities will "do the right thing" when used in the "File..."
00026  * pulldown menu, for the "New", "Open", "Save", "SaveAs", etc. menu entries.
00027  * In particular, they will verify that old files don't get clobbered,
00028  * they'll put up dialogue boxes to ask the user to confirm their actions,
00029  * etc.
00030  *
00031  * These utilities are written in a GUI-independent fashion, and should
00032  * work just fine with the Motif, gnome/gtk and Qt interfaces.
00033  * These utilities are appropriate for direct invocation from guile.
00034  *
00035  * These GUI utilities implement and maintain a single global "session"
00036  * that defines the currently edited account group.  In a sense, these
00037  * functions provide the GUI for the xaccSession object.  The session
00038  * is essentially a file that is open for editing, with locks on it
00039  * to prevent other readers and writers from accessing it as long as its
00040  * open.
00041  *
00042  *
00043  * The gnc_file_save() routine will check for an existing edit session,
00044  *    and if one exists, it will save the account info to a file.
00045  *    If an error occurs, a popup dialogue will inform the user of
00046  *    the error.  If there is no existing filename open, then the
00047  *    user will be prompted for a file to save to (using the
00048  *    gnc_file_save_as() routine).  The existing session will remain
00049  *    open for further editing.
00050  *
00051  * The gnc_file_save_as() routine will prompt the user for a filename
00052  *    to save the account data to (using the standard GUI file dialogue
00053  *    box).  If the user specifies a filename, the account data will be
00054  *    saved. If an error occurs, a popup dialogue will inform the user
00055  *    of the error.  One possible error is that another user has
00056  *    the indicated file already locked up in a different session
00057  *    (in which case it is up to the user to try again, or to pick
00058  *    a different filename).  If it is possible to save without
00059  *    an error, then a new session is started for the indicated
00060  *    filename, locking out other users.  This new session remains
00061  *    open for further editing.
00062  *
00063  * The gnc_file_query_save() routine will display a popup dialog asking
00064  *    the user if they wish to save their current work. If they answer
00065  *    "yes", their work will be saved (using the gncFileSave function),
00066  *    otherwise no action will be performed. If there is no currently
00067  *    locked session, a popup will query the user for a filename
00068  *    (using the gnc_file_save_as() routine). The routine will return
00069  *    TRUE if the user hits "Yes" or "No" and FALSE if the user
00070  *    hits "Cancel". If nothing needed to be saved, the routine
00071  *    will return TRUE.
00072  *
00073  * The gnc_file_new() routine will check for an existing edit session.
00074  *    If one exists, it will ask the user if they want to save it,
00075  *    (using the gnc_file_query_save_as() dialogue).  Then the current
00076  *    session will be destroyed, file locks will be removed, and
00077  *    account group structures will be set up for a new session.
00078  *
00079  * The gnc_file_open() routine check for an existing edit session.
00080  *    If one exists, it will ask the user if they want to save it.
00081  *    (using the gnc_file_query_save() dialogue).  Next, the user will
00082  *    be prompted with a GUI standard file-selection dialogue to
00083  *    to pick a new file.  If no file is picked, this routine returns.
00084  *    If a new file was picked, then the current session will be
00085  *    destroyed and file locks on it will be removed.  The new
00086  *    file will then be opened for editing, establishing locks, etc.
00087  *    If an error occurs, the user will be informed with a pop-up
00088  *    dialogue.  If the file cannot be found, or if a read
00089  *    error occurs, a popup describing the error will pop up.
00090  *    One possible error is that another user has the indicated
00091  *    file already locked up in a different session (in which
00092  *    case it is up to the user to try again, or to pick
00093  *    a different filename).
00094  *
00095  * The gnc_file_open_file() routine behaves much like the gnc_file_open()
00096  *    routine, except that the new file to open is passed as a char *
00097  *    argument.
00098  *
00099  * The gnc_file_export() routine will check for an existing edit
00100  *    session, and if one exists, it will save just the commodities
00101  *    and accounts to a file.  If an error occurs, a popup dialogue
00102  *    will inform the user of the error.
00103  *
00104  * The gnc_file_quit() routine will close out and destroy the current session.
00105  *    The user WILL NOT BE PROMPTED to confirm this action, or do do
00106  *    any kind of saving beforehand.
00107  *
00108  * HISTORY:
00109  * Derived from Rob Clark's original MainWindow.c code, Dec 1998
00110  */
00111 
00112 #ifndef GNC_FILE_H
00113 #define GNC_FILE_H
00114 
00115 #include <glib.h>
00116 #include "qof.h"
00117 
00118 typedef enum
00119 {
00120     GNC_FILE_DIALOG_OPEN,
00121     GNC_FILE_DIALOG_IMPORT,
00122     GNC_FILE_DIALOG_SAVE,
00123     GNC_FILE_DIALOG_EXPORT
00124 } GNCFileDialogType;
00125 
00126 void gnc_file_new (void);
00127 gboolean gnc_file_open (void);
00128 void gnc_file_export(void);
00129 void gnc_file_save (void);
00130 void gnc_file_save_as (void);
00131 void gnc_file_do_export(const char* filename);
00132 void gnc_file_do_save_as(const char* filename);
00133 
00137 gboolean show_session_error (QofBackendError io_error,
00138                              const char *newfile,
00139                              GNCFileDialogType type);
00140 
00141 char * gnc_file_dialog (const char * title,
00142                         GList * filters,
00143                         const char * starting_dir,
00144                         GNCFileDialogType type);
00145 
00146 gboolean gnc_file_open_file (const char *filename, gboolean open_readonly);
00147 
00148 gboolean gnc_file_query_save (gboolean can_cancel);
00149 
00150 void gnc_file_quit (void);
00151 
00152 typedef void (*GNCShutdownCB) (int);
00153 void gnc_file_set_shutdown_callback (GNCShutdownCB cb);
00154 gboolean gnc_file_save_in_progress (void);
00155 
00156 #endif /* GNC_FILE_H */
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines