GnuCash 2.4.99
gnc-gnome-utils.c
00001 /********************************************************************\
00002  * gnc-gnome-utils.c -- utility functions for gnome for GnuCash     *
00003  * Copyright (C) 2001 Linux Developers Group                        *
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, contact:                        *
00017  *                                                                  *
00018  * Free Software Foundation           Voice:  +1-617-542-5942       *
00019  * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
00020  * Boston, MA  02110-1301,  USA       gnu@gnu.org                   *
00021  *                                                                  *
00022 \********************************************************************/
00023 
00024 #include "config.h"
00025 
00026 #include <gnome.h>
00027 #include <glib/gi18n.h>
00028 #include <libguile.h>
00029 #include <gconf/gconf.h>
00030 #ifdef HAVE_X11_XLIB_H
00031 # include <X11/Xlib.h>
00032 #endif
00033 #include <libxml/xmlIO.h>
00034 
00035 //#include "gnc-html-graph-gog.h"
00036 
00037 #include "assistant-gconf-setup.h"
00038 #include "gnc-gconf-utils.h"
00039 #include "gnc-gnome-utils.h"
00040 //#include "gnc-html.h"
00041 #include "gnc-engine.h"
00042 #include "gnc-path.h"
00043 #include "gnc-ui.h"
00044 #include "gnc-file.h"
00045 #include "gnc-hooks.h"
00046 #include "gnc-filepath-utils.h"
00047 #include "gnc-menu-extensions.h"
00048 #include "gnc-component-manager.h"
00049 #include "gnc-splash.h"
00050 #include "gnc-window.h"
00051 #include "gnc-icons.h"
00052 #include "dialog-options.h"
00053 #include "dialog-commodity.h"
00054 #include "dialog-totd.h"
00055 #include "gnc-ui-util.h"
00056 #include "gnc-session.h"
00057 #ifdef G_OS_WIN32
00058 #    include "gnc-help-utils.h"
00059 #endif
00060 #ifdef MAC_INTEGRATION
00061 #import <Cocoa/Cocoa.h>
00062 #endif
00063 
00064 static QofLogModule log_module = GNC_MOD_GUI;
00065 static GnomeProgram *gnucash_program = NULL;
00066 static int gnome_is_running = FALSE;
00067 static int gnome_is_terminating = FALSE;
00068 static int gnome_is_initialized = FALSE;
00069 
00070 
00071 #define ACCEL_MAP_NAME "accelerator-map"
00072 
00073 static void
00074 gnc_global_options_help_cb (GNCOptionWin *win, gpointer dat)
00075 {
00076     gnc_gnome_help (HF_HELP, HL_GLOBPREFS);
00077 }
00078 
00079 static void
00080 gnc_commodity_help_cb (void)
00081 {
00082     gnc_gnome_help (HF_HELP, HL_COMMODITY);
00083 }
00084 
00085 /* gnc_configure_date_format
00086  *    sets dateFormat to the current value on the scheme side
00087  *
00088  * Args: Nothing
00089  * Returns: Nothing
00090  */
00091 static void
00092 gnc_configure_date_format (void)
00093 {
00094     char *format_code = gnc_gconf_get_string(GCONF_GENERAL,
00095                         KEY_DATE_FORMAT, NULL);
00096 
00097     QofDateFormat df;
00098 
00099     if (format_code == NULL)
00100         format_code = g_strdup("locale");
00101     if (*format_code == '\0')
00102     {
00103         g_free(format_code);
00104         format_code = g_strdup("locale");
00105     }
00106 
00107     if (gnc_date_string_to_dateformat(format_code, &df))
00108     {
00109         PERR("Incorrect date format code");
00110         if (format_code != NULL)
00111             free(format_code);
00112         return;
00113     }
00114 
00115     qof_date_format_set(df);
00116 
00117     if (format_code != NULL)
00118         free(format_code);
00119 }
00120 
00121 /* gnc_configure_date_completion
00122  *    sets dateCompletion to the current value on the scheme side.
00123  *    QOF_DATE_COMPLETION_THISYEAR: use current year
00124  *    QOF_DATE_COMPLETION_SLIDING: use a sliding 12-month window
00125  *    backmonths 0-11: windows starts this many months before current month
00126  *
00127  * Args: Nothing
00128  * Returns: Nothing
00129  */
00130 static void
00131 gnc_configure_date_completion (void)
00132 {
00133     char *date_completion = gnc_gconf_get_string(GCONF_GENERAL,
00134                             KEY_DATE_COMPLETION, NULL);
00135     int backmonths = gnc_gconf_get_float(GCONF_GENERAL,
00136                                          KEY_DATE_BACKMONTHS, NULL);
00137     QofDateCompletion dc;
00138 
00139     if (backmonths < 0)
00140     {
00141         backmonths = 0;
00142     }
00143     else if (backmonths > 11)
00144     {
00145         backmonths = 11;
00146     }
00147 
00148     if (date_completion && strcmp(date_completion, "sliding") == 0)
00149     {
00150         dc = QOF_DATE_COMPLETION_SLIDING;
00151     }
00152     else if (date_completion && strcmp(date_completion, "thisyear") == 0)
00153     {
00154         dc = QOF_DATE_COMPLETION_THISYEAR;
00155     }
00156     else
00157     {
00158         /* No preference has been set yet */
00159         PINFO("Incorrect date completion code, using defaults");
00160         dc = QOF_DATE_COMPLETION_THISYEAR;
00161         backmonths = 6;
00162         gnc_gconf_set_string (GCONF_GENERAL, KEY_DATE_COMPLETION, "thisyear", NULL);
00163         gnc_gconf_set_float (GCONF_GENERAL, KEY_DATE_BACKMONTHS, 6.0, NULL);
00164     }
00165     qof_date_completion_set(dc, backmonths);
00166 
00167     if (date_completion != NULL)
00168     {
00169         free(date_completion);
00170     }
00171 }
00172 
00173 char *
00174 gnc_gnome_locate_pixmap (const char *name)
00175 {
00176     char *fullname;
00177 
00178     g_return_val_if_fail (name != NULL, NULL);
00179 
00180     fullname = gnome_program_locate_file (gnucash_program,
00181                                           GNOME_FILE_DOMAIN_APP_PIXMAP,
00182                                           name, TRUE, NULL);
00183     if (fullname == NULL)
00184     {
00185         PERR ("Could not locate pixmap/pixbuf file %s", name);
00186         return NULL;
00187     }
00188 
00189     return fullname;
00190 }
00191 
00192 char *
00193 gnc_gnome_locate_data_file (const char *name)
00194 {
00195     char *fullname;
00196 
00197     g_return_val_if_fail (name != NULL, NULL);
00198 
00199     fullname = gnome_program_locate_file (gnucash_program,
00200                                           GNOME_FILE_DOMAIN_APP_DATADIR,
00201                                           name, TRUE, NULL);
00202 
00203     if (fullname == NULL)
00204     {
00205         PERR ("Could not locate file %s", name);
00206         return NULL;
00207     }
00208 
00209     return fullname;
00210 }
00211 
00212 char *
00213 gnc_gnome_locate_ui_file (const char *name)
00214 {
00215     char *partial;
00216     char *fullname;
00217 
00218     g_return_val_if_fail (name != NULL, NULL);
00219 
00220     partial = g_strdup_printf("ui/%s", name);
00221     fullname = gnc_gnome_locate_data_file(partial);
00222     g_free(partial);
00223 
00224     return fullname;
00225 }
00226 
00227 static void
00228 gnc_gtk_add_rc_file (void)
00229 {
00230     const gchar *var;
00231     gchar *str;
00232 
00233     var = g_get_home_dir ();
00234     if (var)
00235     {
00236         str = g_build_filename (var, ".gtkrc-2.0.gnucash", (char *)NULL);
00237         gtk_rc_add_default_file (str);
00238         g_free (str);
00239     }
00240 }
00241 
00242 void
00243 gnc_gnome_init (int argc, char **argv, const char * version)
00244 {
00245     GError *error = NULL;
00246     gchar *prefix = gnc_path_get_prefix ();
00247     gchar *pkgsysconfdir = gnc_path_get_pkgsysconfdir ();
00248     gchar *pkgdatadir = gnc_path_get_pkgdatadir ();
00249     gchar *pkglibdir = gnc_path_get_pkglibdir ();
00250     gboolean installation_ok = TRUE;
00251 
00252     /* Verify all the various directory before proceeding */
00253     if (!g_file_test(pkgdatadir, G_FILE_TEST_IS_DIR))
00254     {
00255         g_critical("The installation data directory \"%s\" was not found. Your installation is incomplete and cannot be run.", pkgdatadir);
00256         installation_ok = FALSE;
00257     }
00258     if (!g_file_test(pkglibdir, G_FILE_TEST_IS_DIR))
00259     {
00260         g_critical("The installation lib directory \"%s\" was not found. Your installation is incomplete and cannot be run.", pkglibdir);
00261         installation_ok = FALSE;
00262     }
00263 
00264     if (!g_file_test(pkgsysconfdir, G_FILE_TEST_IS_DIR))
00265     {
00266         g_critical("The installation sysconf directory \"%s\" was not found. Your installation is incomplete and cannot be run.", pkgsysconfdir);
00267         installation_ok = FALSE;
00268     }
00269 
00270     gnc_gtk_add_rc_file();
00271     gnucash_program = gnome_program_init(
00272                           "gnucash", version, LIBGNOMEUI_MODULE,
00273                           argc, argv,
00274                           GNOME_PARAM_APP_PREFIX, prefix,
00275                           GNOME_PARAM_APP_SYSCONFDIR, pkgsysconfdir,
00276                           GNOME_PARAM_APP_DATADIR, pkgdatadir,
00277                           GNOME_PARAM_APP_LIBDIR, pkglibdir,
00278                           GNOME_PARAM_NONE);
00279     if (!installation_ok)
00280     {
00281         /* The following string does not need translation because if
00282          * it shows up, the program is unusable anyway. */
00283         gnc_error_dialog(NULL, "The installation directories were not found.\n\ndatadir=%s\nlibdir=%s\nsysconfdir=%s\n\nYour installation is incomplete and cannot be run.",
00284                          pkgdatadir, pkglibdir, pkgsysconfdir);
00285         /* gnc_error_dialog must not be called before gnome_program_init. */
00286     }
00287 
00288     g_free (prefix);
00289     g_free (pkgsysconfdir);
00290     g_free (pkgdatadir);
00291     g_free (pkglibdir);
00292 
00293     /* Did the installation directory check fail? Terminate
00294      * immediately because it will inevitably fail in the glade file
00295      * lookup. */
00296     if (!installation_ok)
00297     {
00298         /* No correct installation? Shut down immediately. */
00299         exit(-1);
00300     }
00301 
00302 #ifdef G_OS_WIN32
00303     /* workaround for bug #421792 */
00304     xmlCleanupInputCallbacks();
00305 #endif
00306 
00307     /* initialization required for gtkhtml (is it also needed for webkit?) */
00308     gtk_widget_set_default_colormap (gdk_rgb_get_colormap ());
00309 
00310     /* use custom icon */
00311     {
00312         int idx;
00313         char *icon_filenames[] = {"gnucash-icon-16x16.png",
00314                                   "gnucash-icon-32x32.png",
00315                                   "gnucash-icon-48x48.png",
00316                                   NULL
00317                                  };
00318         GList *icons = NULL;
00319         char *fullname, *name_iter;
00320 
00321         for (idx = 0; icon_filenames[idx] != NULL; idx++)
00322         {
00323             GdkPixbuf *buf = NULL;
00324 
00325             fullname = gnc_gnome_locate_pixmap(icon_filenames[idx]);
00326             if (fullname == NULL)
00327             {
00328                 g_warning("couldn't find icon file [%s]", icon_filenames[idx]);
00329                 continue;
00330             }
00331 
00332             buf = gnc_gnome_get_gdkpixbuf(fullname);
00333             if (buf == NULL)
00334             {
00335                 g_warning("error loading image from [%s]", fullname);
00336                 g_free(fullname);
00337                 continue;
00338             }
00339             g_free(fullname);
00340             icons = g_list_append(icons, buf);
00341         }
00342 
00343         gtk_window_set_default_icon_list(icons);
00344         g_list_foreach(icons, (GFunc)g_object_unref, NULL);
00345         g_list_free(icons);
00346     }
00347 
00348     assistant_gconf_install_check_schemas();
00349 
00350     return;
00351 }
00352 
00353 #ifdef MAC_INTEGRATION
00354 
00355 /* Don't be alarmed if this function looks strange to you: It's
00356  * written in Objective-C, the native language of the OSX Cocoa
00357  * toolkit.
00358  */
00359 void
00360 gnc_gnome_help (const char *dir, const char *detail)
00361 {
00362     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
00363 NSString *subdir = [NSString stringWithUTF8String: dir];
00364     NSString *tag;
00365     NSURL *url = NULL;
00366 
00367     if (detail)
00368 tag  = [NSString stringWithUTF8String: detail];
00369 else if ([subdir compare: @HF_HELP] == NSOrderedSame)
00370         tag = @"help";
00371 else if ([subdir compare: @HF_GUIDE] == NSOrderedSame)
00372         tag = @"index";
00373     else
00374     {
00375         PWARN("gnc_gnome_help called with unknown subdirectory %s", dir);
00376         return;
00377     }
00378 
00379     if (![[NSBundle mainBundle] bundleIdentifier])
00380     {
00381         /* If bundleIdentifier is NULL, then we're running from the
00382          * commandline and must construct a file path to the resource. We can
00383          * still get the resource path, but it will point to the "bin"
00384          * directory so we chop that off, break up what's left into pieces,
00385          * add some more pieces, and put it all back together again. Then,
00386          * because the gettext way of handling localizations is different from
00387          * OSX's, we have to figure out which translation to use. */
00388 NSArray *components = [NSArray arrayWithObjects: @"share", @"gnome", @"help", @"gnucash", nil ];
00389         NSString *prefix = [[[NSBundle mainBundle] resourcePath]
00390                             stringByDeletingLastPathComponent];
00391         NSArray *prefix_comps = [[prefix pathComponents]
00392                          arrayByAddingObjectsFromArray: components];
00393 NSString *docs_dir = [NSString pathWithComponents: prefix_comps];
00394         NSArray *languages = [[NSUserDefaults standardUserDefaults]
00395                       objectForKey: @"AppleLanguages"];
00396         BOOL dir;
00397 subdir = [[[subdir lowercaseString] componentsSeparatedByString: @" "]
00398           componentsJoinedByString: @"-"];
00399 if (![[NSFileManager defaultManager] fileExistsAtPath: docs_dir])
00400         {
00401             const gchar *message =
00402                 _("GnuCash could not find the files for the help documentation.  "
00403                   "This is likely because the 'gnucash-docs' package is not installed.");
00404             gnc_error_dialog(NULL, "%s", message);
00405             [pool release];
00406             return;
00407         }
00408         if ([languages count] > 0)
00409         {
00410             NSEnumerator *lang_iter = [languages objectEnumerator];
00411             NSString *path;
00412             NSString *this_lang;
00413             while ((this_lang = [lang_iter nextObject]))
00414             {
00415                 NSArray *elements;
00416                 unsigned int paths;
00417                 NSString *completed_path = [NSString alloc];
00418 this_lang = [this_lang stringByTrimmingCharactersInSet:
00419              [NSCharacterSet characterSetWithCharactersInString:
00420                               @"\""]];
00421 elements = [this_lang componentsSeparatedByString: @"-"];
00422                 this_lang = [elements objectAtIndex: 0];
00423 path = [docs_dir stringByAppendingPathComponent: this_lang];
00424 paths = [path completePathIntoString: &completed_path
00425          caseSensitive: FALSE
00426          matchesIntoArray: NULL filterTypes: NULL];
00427                 if (paths > 1 &&
00428                         [[NSFileManager defaultManager]
00429          fileExistsAtPath: completed_path
00430          isDirectory: &dir])
00431                     if (dir)
00432                     {
00433                         @try
00434                         {
00435 url = [NSURL fileURLWithPath:
00436                                    [[[completed_path
00437           stringByAppendingPathComponent: subdir]
00438          stringByAppendingPathComponent: tag]
00439         stringByAppendingPathExtension: @"html"]];
00440                         }
00441                         @catch (NSException *e)
00442                         {
00443                             PWARN("fileURLWithPath threw %s: %s",
00444                                   [[e name] UTF8String], [[e reason] UTF8String]);
00445                             return;
00446                         }
00447                         break;
00448                     }
00449 if ([this_lang compare: @"en"] == NSOrderedSame)
00450                     break; /* Special case, forces use of "C" locale */
00451             }
00452         }
00453         if (!url)
00454         {
00455             @try
00456             {
00457                 url = [NSURL
00458        fileURLWithPath: [[[[docs_dir
00459                             stringByAppendingPathComponent: @"C"]
00460                            stringByAppendingPathComponent: subdir]
00461                           stringByAppendingPathComponent: tag]
00462                          stringByAppendingPathExtension: @"html"]];
00463             }
00464             @catch (NSException *e)
00465             {
00466                 PWARN("fileURLWithPath threw %s: %s",
00467                       [[e name] UTF8String], [[e reason] UTF8String]);
00468                 return;
00469             }
00470         }
00471     }
00472     /* It's a lot easier in a bundle! OSX finds the best translation for us. */
00473     else
00474     {
00475         @try
00476         {
00477 url = [NSURL fileURLWithPath: [[NSBundle mainBundle]
00478                                pathForResource: tag
00479                                ofType: @"html"
00480                                inDirectory: subdir ]];
00481         }
00482         @catch (NSException *e)
00483         {
00484             PWARN("fileURLWithPath threw %s: %s",
00485                   [[e name] UTF8String], [[e reason] UTF8String]);
00486             return;
00487         }
00488     }
00489     /* Now just open the URL in the default app for opening URLs */
00490     if (url)
00491 [[NSWorkspace sharedWorkspace] openURL: url];
00492     else
00493     {
00494         const gchar *message =
00495             _("GnuCash could not find the files for the help documentation.  "
00496               "This is likely because the 'gnucash-docs' package is not installed.");
00497         gnc_error_dialog(NULL, "%s", message);
00498     }
00499     [pool release];
00500 }
00501 #elif defined G_OS_WIN32 /* G_OS_WIN32 */
00502 void
00503 gnc_gnome_help (const char *file_name, const char *anchor)
00504 {
00505     const gchar * const *lang;
00506     gchar *pkgdatadir, *fullpath, *found = NULL;
00507 
00508     pkgdatadir = gnc_path_get_pkgdatadir ();
00509     for (lang = g_get_language_names (); *lang; lang++)
00510     {
00511         fullpath = g_build_filename (pkgdatadir, "help", *lang, file_name,
00512                                      (gchar*) NULL);
00513         if (g_file_test (fullpath, G_FILE_TEST_IS_REGULAR))
00514         {
00515             found = g_strdup (fullpath);
00516             g_free (fullpath);
00517             break;
00518         }
00519         g_free (fullpath);
00520     }
00521     g_free (pkgdatadir);
00522 
00523     if (!found)
00524     {
00525         const gchar *message =
00526             _("GnuCash could not find the files for the help documentation.");
00527         gnc_error_dialog (NULL, message);
00528     }
00529     else
00530     {
00531         gnc_show_htmlhelp (found, anchor);
00532     }
00533     g_free (found);
00534 }
00535 #else
00536 void
00537 gnc_gnome_help (const char *file_name, const char *anchor)
00538 {
00539     GError *error = NULL;
00540 
00541     DEBUG ("Attempting to opening help file %s", file_name);
00542     if (gnome_help_display (file_name, anchor, &error))
00543         return;
00544 
00545     g_assert(error != NULL);
00546     {
00547         const gchar *message =
00548             _("GnuCash could not find the files for the help documentation.  "
00549               "This is likely because the 'gnucash-docs' package is not installed.");
00550         gnc_error_dialog(NULL, "%s", message);
00551     }
00552     PERR ("%s", error->message);
00553     g_error_free(error);
00554 }
00555 
00556 
00557 #endif
00558 
00559 /********************************************************************\
00560  * gnc_gnome_get_pixmap                                             *
00561  *   returns a GtkWidget given a pixmap filename                    *
00562  *                                                                  *
00563  * Args: none                                                       *
00564  * Returns: GtkWidget or NULL if there was a problem                *
00565  \*******************************************************************/
00566 GtkWidget *
00567 gnc_gnome_get_pixmap (const char *name)
00568 {
00569     GtkWidget *pixmap;
00570     char *fullname;
00571 
00572     g_return_val_if_fail (name != NULL, NULL);
00573 
00574     fullname = gnc_gnome_locate_pixmap (name);
00575     if (fullname == NULL)
00576         return NULL;
00577 
00578     DEBUG ("Loading pixmap file %s", fullname);
00579 
00580     pixmap = gtk_image_new_from_file (fullname);
00581     if (pixmap == NULL)
00582     {
00583         PERR ("Could not load pixmap");
00584     }
00585     g_free (fullname);
00586 
00587     return pixmap;
00588 }
00589 
00590 /********************************************************************\
00591  * gnc_gnome_get_gdkpixbuf                                          *
00592  *   returns a GdkImlibImage object given a pixmap filename         *
00593  *                                                                  *
00594  * Args: none                                                       *
00595  * Returns: GdkPixbuf or NULL if there was a problem                *
00596  \*******************************************************************/
00597 GdkPixbuf *
00598 gnc_gnome_get_gdkpixbuf (const char *name)
00599 {
00600     GdkPixbuf *pixbuf;
00601     GError *error = NULL;
00602     char *fullname;
00603 
00604     g_return_val_if_fail (name != NULL, NULL);
00605 
00606     fullname = gnc_gnome_locate_pixmap (name);
00607     if (fullname == NULL)
00608         return NULL;
00609 
00610     DEBUG ("Loading pixbuf file %s", fullname);
00611     pixbuf = gdk_pixbuf_new_from_file (fullname, &error);
00612     if (error != NULL)
00613     {
00614         g_assert (pixbuf == NULL);
00615         PERR ("Could not load pixbuf: %s", error->message);
00616         g_error_free (error);
00617     }
00618     g_free (fullname);
00619 
00620     return pixbuf;
00621 }
00622 
00623 static gboolean
00624 gnc_ui_check_events (gpointer not_used)
00625 {
00626     QofSession *session;
00627     gboolean force;
00628 
00629     if (gtk_main_level() != 1)
00630         return TRUE;
00631 
00632     if (!gnc_current_session_exist())
00633         return TRUE;
00634     session = gnc_get_current_session ();
00635 
00636     if (gnc_gui_refresh_suspended ())
00637         return TRUE;
00638 
00639     if (!qof_session_events_pending (session))
00640         return TRUE;
00641 
00642     gnc_suspend_gui_refresh ();
00643 
00644     force = qof_session_process_events (session);
00645 
00646     gnc_resume_gui_refresh ();
00647 
00648     if (force)
00649         gnc_gui_refresh_all ();
00650 
00651     return TRUE;
00652 }
00653 
00654 #ifdef HAVE_X11_XLIB_H
00655 static int
00656 gnc_x_error (Display *display, XErrorEvent *error)
00657 {
00658     if (error->error_code)
00659     {
00660         char buf[64];
00661 
00662         XGetErrorText (display, error->error_code, buf, 63);
00663 
00664         g_warning ("X-ERROR **: %s\n  serial %ld error_code %d "
00665                    "request_code %d minor_code %d\n",
00666                    buf,
00667                    error->serial,
00668                    error->error_code,
00669                    error->request_code,
00670                    error->minor_code);
00671     }
00672 
00673     return 0;
00674 }
00675 #endif
00676 
00677 int
00678 gnc_ui_start_event_loop (void)
00679 {
00680     guint id;
00681 
00682     gnome_is_running = TRUE;
00683 
00684     id = g_timeout_add_full (G_PRIORITY_DEFAULT_IDLE, 10000, /* 10 secs */
00685                              gnc_ui_check_events, NULL, NULL);
00686 
00687 #ifdef HAVE_X11_XLIB_H
00688     XSetErrorHandler (gnc_x_error);
00689 #endif
00690 
00691     /* Enter gnome event loop */
00692     gtk_main ();
00693 
00694     g_source_remove (id);
00695 
00696     gnome_is_running = FALSE;
00697     gnome_is_terminating = FALSE;
00698 
00699     return 0;
00700 }
00701 
00702 GncMainWindow *
00703 gnc_gui_init(void)
00704 {
00705     static GncMainWindow *main_window;
00706     gchar *map;
00707     gchar *data_dir;
00708 
00709     ENTER ("");
00710 
00711     if (gnome_is_initialized)
00712     {
00713         return main_window;
00714     }
00715 
00716     g_set_application_name(PACKAGE_NAME);
00717 
00718     gnc_show_splash_screen();
00719 
00720     gnome_is_initialized = TRUE;
00721 
00722     gnc_ui_util_init();
00723     gnc_configure_date_format();
00724     gnc_configure_date_completion();
00725 
00726     gnc_gconf_general_register_cb(
00727         KEY_DATE_FORMAT, (GncGconfGeneralCb)gnc_configure_date_format, NULL);
00728     gnc_gconf_general_register_cb(
00729         KEY_DATE_COMPLETION, (GncGconfGeneralCb)gnc_configure_date_completion, NULL);
00730     gnc_gconf_general_register_cb(
00731         KEY_DATE_BACKMONTHS, (GncGconfGeneralCb)gnc_configure_date_completion, NULL);
00732     gnc_gconf_general_register_any_cb(
00733         (GncGconfGeneralAnyCb)gnc_gui_refresh_all, NULL);
00734 
00735     gnc_ui_commodity_set_help_callback (gnc_commodity_help_cb);
00736     gnc_file_set_shutdown_callback (gnc_shutdown);
00737 
00738     gnc_options_dialog_set_global_help_cb (gnc_global_options_help_cb, NULL);
00739 
00740     main_window = gnc_main_window_new ();
00741     // Bug#350993:
00742     // gtk_widget_show (GTK_WIDGET (main_window));
00743     gnc_window_set_progressbar_window (GNC_WINDOW(main_window));
00744 
00745 #ifdef MAC_INTEGRATION
00746     data_dir = gnc_path_get_pkgdatadir();
00747     map = g_build_filename(data_dir, "ui", "osx_accel_map", NULL);
00748     g_free(data_dir);
00749 #else
00750     map = gnc_build_dotgnucash_path(ACCEL_MAP_NAME);
00751 #endif /* MAC_INTEGRATION */
00752     gtk_accel_map_load(map);
00753     g_free(map);
00754 
00755     gnc_load_stock_icons();
00756     gnc_totd_dialog(GTK_WINDOW(main_window), TRUE);
00757 
00758     LEAVE ("");
00759     return main_window;
00760 }
00761 
00762 gboolean
00763 gnucash_ui_is_running(void)
00764 {
00765     return gnome_is_running;
00766 }
00767 
00768 static void
00769 gnc_gui_destroy (void)
00770 {
00771     if (!gnome_is_initialized)
00772         return;
00773 
00774     gnc_extensions_shutdown ();
00775 }
00776 
00777 static void
00778 gnc_gui_shutdown (void)
00779 {
00780     gchar *map;
00781 
00782     if (gnome_is_running && !gnome_is_terminating)
00783     {
00784         gnome_is_terminating = TRUE;
00785 
00786         map = gnc_build_dotgnucash_path(ACCEL_MAP_NAME);
00787         gtk_accel_map_save(map);
00788         g_free(map);
00789 
00790         gtk_main_quit();
00791     }
00792 }
00793 
00794 /*  shutdown gnucash.  This function will initiate an orderly
00795  *  shutdown, and when that has finished it will exit the program.
00796  */
00797 void
00798 gnc_shutdown (int exit_status)
00799 {
00800     if (gnucash_ui_is_running())
00801     {
00802         if (!gnome_is_terminating)
00803         {
00804             if (gnc_file_query_save(FALSE))
00805             {
00806                 gnc_hook_run(HOOK_UI_SHUTDOWN, NULL);
00807                 gnc_gui_shutdown();
00808             }
00809         }
00810     }
00811     else
00812     {
00813         gnc_gui_destroy();
00814         gnc_hook_run(HOOK_SHUTDOWN, NULL);
00815         gnc_engine_shutdown();
00816         exit(exit_status);
00817     }
00818 }
00819 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines