1 /* HomeBank -- Free, easy, personal accounting for everyone.
2 * Copyright (C) 1995-2014 Maxime DOYEN
4 * This file is part of HomeBank.
6 * HomeBank is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * HomeBank is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "dsp_mainwindow.h"
23 #include "hb-preferences.h"
30 #define APPLICATION_NAME "HomeBank"
32 /****************************************************************************/
34 /****************************************************************************/
43 /* our global datas */
44 struct HomeBank
*GLOBALS
;
45 struct Preferences
*PREFS
;
48 /* installation paths */
49 static gchar
*config_dir
= NULL
;
50 static gchar
*images_dir
= NULL
;
51 static gchar
*pixmaps_dir
= NULL
;
52 static gchar
*locale_dir
= NULL
;
53 static gchar
*help_dir
= NULL
;
54 static gchar
*datas_dir
= NULL
;
57 //#define MARKUP_STRING "<span size='small'>%s</span>"
60 /* Application arguments */
61 static gboolean arg_version
= FALSE
;
62 static gchar
**files
= NULL
;
64 static GOptionEntry option_entries
[] =
66 { "version", '\0', 0, G_OPTION_ARG_NONE
, &arg_version
,
67 N_("Output version information and exit"), NULL
},
69 { G_OPTION_REMAINING
, '\0', 0, G_OPTION_ARG_FILENAME_ARRAY
, &files
,
77 ** try to determine the file type (if supported for import by homebank)
81 gint
homebank_alienfile_recognize(gchar
*filename
)
84 gint i
, retval
= FILETYPE_UNKNOW
;
88 static gint csvtype
[7] = {
99 DB( g_print("\n[homebank] alienfile_recognize\n") );
102 io
= g_io_channel_new_file(filename
, "r", NULL
);
105 g_io_channel_set_encoding(io
, NULL
, NULL
); /* set to binary mode */
109 if( retval
!= FILETYPE_UNKNOW
)
112 io_stat
= g_io_channel_read_line(io
, &tmpstr
, NULL
, NULL
, &err
);
113 if( io_stat
== G_IO_STATUS_EOF
)
115 if( io_stat
== G_IO_STATUS_ERROR
)
117 DB (g_print(" + ERROR %s\n",err
->message
));
120 if( io_stat
== G_IO_STATUS_NORMAL
)
122 if( *tmpstr
!= '\0' )
124 DB( g_print(" line %d: '%s' retval=%d\n", i
, tmpstr
, retval
) );
126 /* native homebank file */
127 if( g_str_has_prefix(tmpstr
, "<homebank v="))
129 DB( g_print(" type is HomeBank\n") );
130 retval
= FILETYPE_HOMEBANK
;
135 if( g_str_has_prefix(tmpstr
, "!Type") ||
136 g_str_has_prefix(tmpstr
, "!type") ||
137 g_str_has_prefix(tmpstr
, "!Option") ||
138 g_str_has_prefix(tmpstr
, "!option") ||
139 g_str_has_prefix(tmpstr
, "!Account") ||
140 g_str_has_prefix(tmpstr
, "!account")
143 DB( g_print(" type is QIF\n") );
144 retval
= FILETYPE_QIF
;
149 if( g_strstr_len(tmpstr
, 10, "OFX") != NULL
)
151 DB( g_print(" type is OFX\n") );
152 retval
= FILETYPE_OFX
;
155 /* is it csv homebank ? */
160 hbcsv
= hb_string_csv_valid(tmpstr
, 8, csvtype
);
162 DB( g_print(" hbcsv %d\n", hbcsv
) );
166 DB( g_print(" type is CSV homebank\n") );
167 retval
= FILETYPE_CSV_HB
;
178 g_io_channel_unref (io
);
185 /* = = = = = = = = = = = = = = = = = = = = */
191 ** ensure the filename ends with '.xhb'
193 void homebank_file_ensure_xhb(void)
197 DB( g_print("\n[homebank] file_ensure_xhb\n") );
199 newfilepath
= hb_filename_new_with_extention(GLOBALS
->xhb_filepath
, "xhb");
200 hbfile_change_filepath(newfilepath
);
202 DB( g_print("- out: %s\n", GLOBALS
->xhb_filepath
) );
206 static gboolean
homebank_copy_file(gchar
*srcfile
, gchar
*dstfile
)
210 //GError *error = NULL;
211 gboolean retval
= FALSE
;
213 if (g_file_get_contents (srcfile
, &buffer
, &length
, NULL
))
215 if(g_file_set_contents(dstfile
, buffer
, length
, NULL
))
225 void homebank_backup_current_file(gchar
*pathname
)
233 DB( g_print("\n[homebank] backup_current_file\n") );
235 basename
= g_path_get_basename(pathname
);
236 dirname
= g_path_get_dirname (pathname
);
238 if( g_str_has_suffix(basename
, ".xhb") )
240 str_array
= g_strsplit(basename
, ".", 0);
241 filename
= g_strdup_printf("%s.xhb~", str_array
[0]);
242 newname
= g_build_filename(dirname
, filename
, NULL
);
245 if( g_file_test(newname
, G_FILE_TEST_EXISTS
) )
247 DB( g_print("- remove existing: %s\n", newname
) );
251 DB( g_print("- copy %s => %s\n", pathname
, newname
) );
253 homebank_copy_file (pathname
, newname
);
255 //retval = g_rename(pathname, newname);
257 //DB( g_print("retval %d\n", retval) );
259 g_strfreev(str_array
);
266 /* = = = = = = = = = = = = = = = = = = = = */
274 homebank_util_url_show_win32 (const gchar
*url
)
280 retval
= ShellExecuteA (NULL
, "open", url
, NULL
, NULL
, SW_NORMAL
);
282 if (retval
< 0 || retval
> 32)
285 errmsg
= g_win32_error_message(retval
);
286 DB( g_print ("%s\n", errmsg
) );
295 homebank_util_url_show_unix (const gchar
*url
)
300 retval
= gtk_show_uri (gtk_widget_get_screen (GTK_WIDGET (GLOBALS
->mainwindow
)), url
, GDK_CURRENT_TIME
, &err
);
304 ui_dialog_msg_infoerror(GTK_WINDOW(GLOBALS
->mainwindow
), GTK_MESSAGE_ERROR
,
306 _("Could not display the URL '%s'"),
313 g_print ("%s\n", err
->message
);
323 homebank_util_url_show (const gchar
*url
)
331 return homebank_util_url_show_win32 (url
);
333 return homebank_util_url_show_unix (url
);
338 /* = = = = = = = = = = = = = = = = = = = = */
339 /* lastopenedfiles */
342 ** load lastopenedfiles from homedir/.homebank
344 gboolean
homebank_lastopenedfiles_load(void)
347 gboolean retval
= FALSE
;
348 gchar
*group
, *filename
, *lastfilename
;
350 DB( g_print("\n[homebank] lastopenedfiles load\n") );
352 keyfile
= g_key_file_new();
356 filename
= g_build_filename(homebank_app_get_config_dir(), "lastopenedfiles", NULL
);
358 DB( g_print(" -> filename: %s\n", filename
) );
360 if(g_key_file_load_from_file (keyfile
, filename
, G_KEY_FILE_NONE
, NULL
))
364 DB( g_print(" -> load keyfile ok\n") );
366 if(g_key_file_has_key(keyfile
, group
, "LastOpenedFile", NULL
))
368 DB( g_print(" -> keyfile has key ok\n") );
370 lastfilename
= g_key_file_get_string (keyfile
, group
, "LastOpenedFile", NULL
);
372 DB( g_print(" -> lastfile loaded: %s\n", lastfilename
) );
374 if (g_file_test (lastfilename
, G_FILE_TEST_EXISTS
) != FALSE
)
376 DB( g_print(" -> file exists\n") );
378 hbfile_change_filepath(lastfilename
);
385 g_key_file_free (keyfile
);
388 DB( g_print(" -> return: %d\n", retval
) );
395 ** save lastopenedfiles to homedir/.homebank (HB_DATA_PATH)
397 gboolean
homebank_lastopenedfiles_save(void)
400 gboolean retval
= FALSE
;
401 gchar
*group
, *filename
;
404 DB( g_print("\n[homebank] lastopenedfiles save\n") );
406 if( GLOBALS
->xhb_filepath
!= NULL
)
409 keyfile
= g_key_file_new();
413 g_key_file_set_string (keyfile
, group
, "LastOpenedFile", GLOBALS
->xhb_filepath
);
415 gchar
*contents
= g_key_file_to_data( keyfile
, &length
, NULL
);
417 //DB( g_print(" keyfile:\n%s\nlen=%d\n", contents, length) );
419 filename
= g_build_filename(homebank_app_get_config_dir(), "lastopenedfiles", NULL
);
420 g_file_set_contents(filename
, contents
, length
, NULL
);
424 g_key_file_free (keyfile
);
433 /* = = = = = = = = = = = = = = = = = = = = */
438 static void free_list_pixbuf(void)
442 DB( g_print("\n[homebank] free_list_pixbuf\n") );
444 for(i
=0;i
<NUM_LST_PIXBUF
;i
++)
446 if(GLOBALS
->lst_pixbuf
[i
] != NULL
)
448 g_object_unref(GLOBALS
->lst_pixbuf
[i
]);
453 static void load_list_pixbuf(void)
459 DB( g_print("\n[homebank] load_list_pixbuf\n") );
461 cellview
= gtk_cell_view_new ();
463 /* list added (account/transaction list) */
464 pixbuf
= gtk_widget_render_icon (cellview
, GTK_STOCK_NEW
, GTK_ICON_SIZE_MENU
, NULL
);
465 //g_object_unref(pixbuf);
466 GLOBALS
->lst_pixbuf
[LST_PIXBUF_ADD
] = pixbuf
;
468 /* list scheduled (archive list) */
469 pixbuf
= gtk_widget_render_icon (cellview
, HB_STOCK_OPE_AUTO
, GTK_ICON_SIZE_MENU
, NULL
);
470 //g_object_unref(pixbuf);
471 GLOBALS
->lst_pixbuf
[LST_PIXBUF_AUTO
] = pixbuf
;
473 /* list edited (account/transaction list) */
474 pixbuf
= gtk_widget_render_icon (cellview
, GTK_STOCK_EDIT
, GTK_ICON_SIZE_MENU
, NULL
);
475 //g_object_unref(pixbuf);
476 GLOBALS
->lst_pixbuf
[LST_PIXBUF_EDIT
] = pixbuf
;
478 /* list remind (transaction list) */
479 pixbuf
= gtk_widget_render_icon (cellview
, HB_STOCK_OPE_REMIND
, GTK_ICON_SIZE_MENU
, NULL
);
480 //g_object_unref(pixbuf);
481 GLOBALS
->lst_pixbuf
[LST_PIXBUF_REMIND
] = pixbuf
;
483 /* list reconciled (transaction list) */
484 pixbuf
= gtk_widget_render_icon (cellview
, HB_STOCK_OPE_VALID
, GTK_ICON_SIZE_MENU
, NULL
);
485 //g_object_unref(pixbuf);
486 GLOBALS
->lst_pixbuf
[LST_PIXBUF_VALID
] = pixbuf
;
488 /* list warning (import transaction list) */
489 pixbuf
= gtk_widget_render_icon (cellview
, GTK_STOCK_DIALOG_WARNING
, GTK_ICON_SIZE_MENU
, NULL
);
490 //g_object_unref(pixbuf);
491 GLOBALS
->lst_pixbuf
[LST_PIXBUF_WARNING
] = pixbuf
;
493 GLOBALS
->lst_pixbuf_maxwidth
= 0;
494 for(i
=0;i
<NUM_LST_PIXBUF
;i
++)
496 if( GLOBALS
->lst_pixbuf
[i
] != NULL
)
497 GLOBALS
->lst_pixbuf_maxwidth
= MAX(GLOBALS
->lst_pixbuf_maxwidth
, gdk_pixbuf_get_width(GLOBALS
->lst_pixbuf
[i
]) );
501 DB( g_print(" -> pixbuf list maxwidth: %d\n", GLOBALS
->lst_pixbuf_maxwidth
) );
503 gtk_widget_destroy (cellview
);
509 homebank_register_stock_icons()
511 DB( g_print("\n[homebank] register_stock_icons\n") );
513 GtkIconFactory
*factory
;
514 GtkIconSet
*icon_set
;
515 GtkIconSource
*icon_source
;
518 const char *icon_theme_items
[] =
549 factory
= gtk_icon_factory_new ();
551 for (i
= 0; i
< G_N_ELEMENTS (icon_theme_items
); i
++)
553 icon_source
= gtk_icon_source_new ();
554 gtk_icon_source_set_icon_name (icon_source
, icon_theme_items
[i
]);
556 icon_set
= gtk_icon_set_new ();
557 gtk_icon_set_add_source (icon_set
, icon_source
);
558 gtk_icon_source_free (icon_source
);
560 gtk_icon_factory_add (factory
, icon_theme_items
[i
], icon_set
);
561 gtk_icon_set_unref (icon_set
);
564 //gtk_stock_add_static (icon_theme_items, G_N_ELEMENTS (icon_theme_items));
566 gtk_icon_factory_add_default (factory
);
567 g_object_unref (factory
);
570 GtkIconTheme
*ic
= gtk_icon_theme_get_default();
573 DB( g_print(" -> get default icon theme\n") );
575 gtk_icon_theme_get_search_path(ic
, &paths
, NULL
);
576 for(i
=0;i
<g_strv_length(paths
);i
++)
578 g_print("-> path %d: %s\n", i
, paths
[i
]);
587 DB( g_print(" -> adding theme search path: %s\n", homebank_app_get_pixmaps_dir()) );
588 gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (), homebank_app_get_pixmaps_dir());
592 void homebank_window_set_icon_from_file(GtkWindow *window, gchar *filename)
596 pathfilename = g_build_filename(homebank_app_get_pixmaps_dir(), filename, NULL);
597 gtk_window_set_icon_from_file(GTK_WINDOW (window), pathfilename, NULL);
598 g_free(pathfilename);
603 homebank_app_get_config_dir (void)
609 homebank_app_get_images_dir (void)
615 homebank_app_get_pixmaps_dir (void)
621 homebank_app_get_locale_dir (void)
627 homebank_app_get_help_dir (void)
633 homebank_app_get_datas_dir (void)
639 /* build package paths at runtime */
641 build_package_paths (void)
643 DB( g_print("\n[homebank] build_package_paths\n") );
648 prefix
= g_win32_get_package_installation_directory_of_module (NULL
);
649 locale_dir
= g_build_filename (prefix
, "share", "locale", NULL
);
650 images_dir
= g_build_filename (prefix
, "share", PACKAGE
, "images", NULL
);
651 pixmaps_dir
= g_build_filename (prefix
, "share", PACKAGE
, "icons", NULL
);
652 help_dir
= g_build_filename (prefix
, "share", PACKAGE
, "help", NULL
);
653 datas_dir
= g_build_filename (prefix
, "share", PACKAGE
, "datas", NULL
);
655 DB( g_print("- app is portable under windows\n") );
656 config_dir
= g_build_filename(prefix
, "config", NULL
);
658 config_dir
= g_build_filename(g_get_user_config_dir(), HB_DATA_PATH
, NULL
);
662 locale_dir
= g_build_filename (DATA_DIR
, "locale", NULL
);
663 images_dir
= g_build_filename (SHARE_DIR
, "images", NULL
);
664 pixmaps_dir
= g_build_filename (DATA_DIR
, PACKAGE
, "icons", NULL
);
665 help_dir
= g_build_filename (DATA_DIR
, PACKAGE
, "help", NULL
);
666 datas_dir
= g_build_filename (DATA_DIR
, PACKAGE
, "datas", NULL
);
667 config_dir
= g_build_filename(g_get_user_config_dir(), HB_DATA_PATH
, NULL
);
669 //#870023 Ubuntu packages the help files in "/usr/share/doc/homebank-data/help/" for some strange reason
670 if(! g_file_test(help_dir
, (G_FILE_TEST_EXISTS
| G_FILE_TEST_IS_DIR
)))
673 help_dir
= g_build_filename ("/usr", "share", "doc", "homebank-data", "help", NULL
);
677 DB( g_print("- config_dir : %s\n", config_dir
) );
678 DB( g_print("- images_dir : %s\n", images_dir
) );
679 DB( g_print("- pixmaps_dir: %s\n", pixmaps_dir
) );
680 DB( g_print("- locale_dir : %s\n", locale_dir
) );
681 DB( g_print("- help_dir : %s\n", help_dir
) );
682 DB( g_print("- datas_dir : %s\n", datas_dir
) );
687 guint32
homebank_app_date_get_julian(void)
690 //init global default value
692 g_date_set_time_t(date
, time(NULL
));
693 GLOBALS
->today
= g_date_get_julian(date
);
695 return GLOBALS
->today
;
699 static gboolean
homebank_check_app_dir_migrate_file(gchar
*srcdir
, gchar
*dstdir
, gchar
*filename
)
705 //GError *error = NULL;
706 gboolean retval
= FALSE
;
708 DB( g_print("\n[homebank] check_app_dir_migrate_file\n") );
710 srcpath
= g_build_filename(srcdir
, filename
, NULL
);
711 dstpath
= g_build_filename(dstdir
, filename
, NULL
);
713 if (g_file_get_contents (srcpath
, &buffer
, &length
, NULL
))
715 if(g_file_set_contents(dstpath
, buffer
, length
, NULL
))
717 //g_print("sould remove %s\n", srcpath);
730 * check/create user home directory for .homebank (HB_DATA_PATH) directory
732 static void homebank_check_app_dir()
735 const gchar
*configdir
;
738 DB( g_print("\n[homebank] check_app_dir\n") );
740 /* check if <userdir>/.config exist */
742 configdir
= g_get_user_config_dir();
743 DB( g_print("- check '%s' exists\n", configdir
) );
744 if(!g_file_test(configdir
, G_FILE_TEST_IS_DIR
))
746 DB( g_print("- creating dir\n") );
747 g_mkdir(configdir
, 0755);
751 /* check for XDG .config/homebank */
752 configdir
= homebank_app_get_config_dir();
753 DB( g_print("- config_dir is: '%s'\n", configdir
) );
754 exists
= g_file_test(configdir
, G_FILE_TEST_IS_DIR
);
757 /* just update folder security */
758 DB( g_print("- chmod 0700\n") );
759 g_chmod(configdir
, 0700);
760 GLOBALS
->first_run
= FALSE
;
764 /* create the config dir */
765 DB( g_print("- create config_dir\n") );
766 g_mkdir(configdir
, 0755);
767 g_chmod(configdir
, 0700);
769 /* any old homedir configuration out there ? */
770 homedir
= g_build_filename(g_get_home_dir (), ".homebank", NULL
);
771 DB( g_print("- homedir is: '%s'\n", homedir
) );
773 exists
= g_file_test(homedir
, G_FILE_TEST_IS_DIR
);
777 /* we must do the migration properly */
778 DB( g_print("- migrate old 2 files\n") );
779 f1
= homebank_check_app_dir_migrate_file(homedir
, config_dir
, "preferences");
780 f2
= homebank_check_app_dir_migrate_file(homedir
, config_dir
, "lastopenedfiles");
783 DB( g_print("- removing old dir\n") );
788 GLOBALS
->first_run
= TRUE
;
795 ** application cleanup: icons, GList, memory
797 static void homebank_cleanup()
800 DB( g_print("\n\n[homebank] cleanup\n") );
802 //v3.4 save windows size/position
803 homebank_pref_save();
806 free_paymode_icons();
810 hbfile_cleanup(TRUE
);
812 /* free our global datas */
815 homebank_pref_free();
826 g_free (pixmaps_dir
);
835 ** application setup: icons, GList, memory
837 static gboolean
homebank_setup()
840 DB( g_print("\n[homebank] setup\n") );
842 GLOBALS
= g_malloc0(sizeof(struct HomeBank
));
843 if(!GLOBALS
) return FALSE
;
844 PREFS
= g_malloc0(sizeof(struct Preferences
));
845 if(!PREFS
) return FALSE
;
847 // check homedir for .homebank dir
848 homebank_check_app_dir();
850 homebank_pref_setdefault();
851 homebank_pref_load();
855 homebank_register_stock_icons();
858 load_paymode_icons();
862 homebank_app_date_get_julian();
867 g_print("- user_name: %s\n", g_get_user_name ());
868 g_print("- real_name: %s\n", g_get_real_name ());
869 g_print("- user_cache_dir: %s\n", g_get_user_cache_dir());
870 g_print("- user_data_dir: %s\n", g_get_user_data_dir ());
871 g_print("- user_config_dir: %s\n", g_get_user_config_dir ());
872 //g_print("- system_data_dirs: %s\n", g_get_system_data_dirs ());
873 //g_print("- system_config_dirs: %s\n", g_get_system_config_dirs ());
875 g_print("- home_dir: %s\n", g_get_home_dir ());
876 g_print("- tmp_dir: %s\n", g_get_tmp_dir ());
877 g_print("- current_dir: %s\n", g_get_current_dir ());
885 /* = = = = = = = = = = = = = = = = = = = = */
889 homebank_construct_splash()
892 GtkWidget
*frame
, *vbox
, *image
;
893 //gchar *ver_string, *markup, *version;
896 DB( g_print("[homebank_construct_splash]\n") );
898 window
= gtk_window_new(GTK_WINDOW_POPUP
); //TOPLEVEL DONT WORK
899 gtk_window_set_type_hint (GTK_WINDOW (window
), GDK_WINDOW_TYPE_HINT_SPLASHSCREEN
);
900 gtk_window_set_skip_taskbar_hint (GTK_WINDOW (window
), TRUE
);
902 gtk_window_set_title (GTK_WINDOW (window
), "HomeBank");
903 gtk_window_set_position (GTK_WINDOW (window
), GTK_WIN_POS_CENTER
);
905 pathfilename
= g_build_filename(homebank_app_get_images_dir(), "splash.png", NULL
);
906 image
= gtk_image_new_from_file((const gchar
*)pathfilename
);
907 g_free(pathfilename
);
909 frame
= gtk_frame_new (NULL
);
910 gtk_frame_set_shadow_type (GTK_FRAME (frame
), GTK_SHADOW_OUT
);
911 gtk_container_add (GTK_CONTAINER (window
), frame
);
913 vbox
= gtk_vbox_new (FALSE
, 0);
914 gtk_container_add (GTK_CONTAINER (frame
), vbox
);
917 ver_string = g_strdup_printf(_("Version: HomeBank-%s"), VERSION);
919 version = gtk_label_new(NULL);
920 markup = g_markup_printf_escaped(MARKUP_STRING, ver_string);
921 gtk_label_set_markup(GTK_LABEL(version), markup);
926 gtk_box_pack_start (GTK_BOX (vbox
), image
, FALSE
, FALSE
, 0);
927 //gtk_box_pack_start (GTK_BOX (vbox), version, FALSE, FALSE, 0);
933 homebank_init_i18n (void)
935 /* We may change the locale later if the user specifies a language
936 * in the gimprc file. Here we are just initializing the locale
937 * according to the environment variables and set up the paths to
938 * the message catalogs.
941 setlocale (LC_ALL
, "");
943 bindtextdomain (GETTEXT_PACKAGE
, homebank_app_get_locale_dir ());
944 //#ifdef HAVE_BIND_TEXTDOMAIN_CODESET
945 bind_textdomain_codeset (GETTEXT_PACKAGE
, "UTF-8");
948 textdomain (GETTEXT_PACKAGE
);
951 gchar *wl = g_win32_getlocale ();
952 DB( g_print(" -> win32 locale is '%s'\n", wl) );
960 main (int argc
, char *argv
[])
962 GOptionContext
*option_context
;
963 GOptionGroup
*option_group
;
964 GError
*error
= NULL
;
966 GtkWidget
*splash
= NULL
;
969 DB( g_print("\n--------------------------------" ) );
970 DB( g_print("\nhomebank starting...\n" ) );
972 build_package_paths();
974 homebank_init_i18n ();
976 /* Set up option groups */
977 option_context
= g_option_context_new (NULL
);
979 //g_option_context_set_summary (option_context, _(""));
981 option_group
= g_option_group_new ("homebank",
982 N_("HomeBank options"),
983 N_("HomeBank options"),
985 g_option_group_add_entries (option_group
, option_entries
);
986 g_option_context_set_main_group (option_context
, option_group
);
987 g_option_group_set_translation_domain (option_group
, GETTEXT_PACKAGE
);
989 /* Add Gtk option group */
990 g_option_context_add_group (option_context
, gtk_get_option_group (FALSE
));
992 /* Parse command line */
993 if (!g_option_context_parse (option_context
, &argc
, &argv
, &error
))
995 g_option_context_free (option_context
);
999 g_print ("%s\n", error
->message
);
1000 g_error_free (error
);
1003 g_print ("An unknown error occurred\n");
1008 g_option_context_free (option_context
);
1009 option_context
= NULL
;
1011 if (arg_version
!= FALSE
)
1013 /* Print version information and exit */
1014 g_print ("%s\n", PACKAGE
" " VERSION
);
1018 /* Pass NULL here since we parsed the gtk+ args already...
1019 * from this point all we need a DISPLAY variable to be set.
1021 gtk_init (NULL
, NULL
);
1023 //todo: sanity check gtk version here ?
1025 g_set_application_name (APPLICATION_NAME
);
1027 if( homebank_setup() )
1029 /* change the locale if a language is specified */
1030 language_init (PREFS
->language
);
1032 if( PREFS
->showsplash
== TRUE
)
1034 splash
= homebank_construct_splash();
1035 gtk_window_set_auto_startup_notification (FALSE
);
1036 gtk_widget_show_all (splash
);
1037 gtk_window_set_auto_startup_notification (TRUE
);
1039 // make sure splash is up
1040 while (gtk_events_pending ())
1041 gtk_main_iteration ();
1045 pathfilename = g_build_filename(homebank_app_get_pixmaps_dir(), "homebank.svg", NULL);
1046 gtk_window_set_default_icon_from_file(pathfilename, NULL);
1047 g_free(pathfilename);
1050 gtk_window_set_default_icon_name ("homebank");
1052 DB( g_print(" -> creating window\n" ) );
1055 mainwin
= (GtkWidget
*)create_hbfile_window (NULL
);
1060 //todo: pause on splash
1061 if( PREFS
->showsplash
== TRUE
)
1063 //g_usleep( G_USEC_PER_SEC * 1 );
1064 gtk_widget_hide(splash
);
1065 gtk_widget_destroy(splash
);
1069 #if HB_UNSTABLE == TRUE
1070 /* GtkWidget *dialog = gtk_message_dialog_new (GTK_WINDOW(mainwin),
1071 GTK_DIALOG_DESTROY_WITH_PARENT,
1072 GTK_MESSAGE_WARNING,
1074 "This is a beta version of HomeBank (UNSTABLE)"
1077 gtk_message_dialog_format_secondary_markup (GTK_MESSAGE_DIALOG (dialog),
1078 "DO NOT USE with important files or do a backup first.\n"
1079 "This kind of release is for <b>TESTING ONLY</b>.\n"
1080 "<u>It may be buggy, crash, or lose your data</u>.\n\n"
1082 "For unstable bugs report, questions, suggestions:\n"
1083 " - <b>DO NOT USE LaunchPad</b>\n"
1084 " - direct email to: <homebank@free.fr>\n\n"
1089 gtk_dialog_run (GTK_DIALOG (dialog));
1090 gtk_widget_destroy (dialog);*/
1093 if(GLOBALS
->first_run
)
1095 ui_mainwindow_action_help_welcome();
1099 while (gtk_events_pending ()) /* make sure splash is gone */
1100 gtk_main_iteration ();
1103 DB( g_print(" -> open last file ?\n" ) );
1106 /* load 1st file specified on commandline */
1107 openlast
= PREFS
->loadlast
;
1110 if (g_file_test (files
[0], G_FILE_TEST_EXISTS
) != FALSE
)
1112 DB( g_print(" -> should load %s\n", files
[0] ) );
1113 hbfile_change_filepath(g_strdup(files
[0]));
1114 ui_mainwindow_open_internal(mainwin
, NULL
);
1119 g_warning (_("Unable to open '%s', the file does not exist.\n"), files
[0]);
1126 DB( g_print(" -> GLOBALS->xhb_filepath: '%s'\n", GLOBALS
->xhb_filepath
) );
1130 if( homebank_lastopenedfiles_load() == TRUE
)
1131 ui_mainwindow_open_internal(mainwin
, NULL
);
1134 /* update the mainwin display */
1135 ui_mainwindow_update(mainwin
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
+UF_BALANCE
+UF_VISUAL
));
1137 DB( g_print(" -> gtk_main()\n" ) );
1147 return EXIT_SUCCESS
;
1151 /* In case we build this as a windowed application */
1154 #define _stdcall __attribute__((stdcall))
1158 WinMain (struct HINSTANCE__
*hInstance
,
1159 struct HINSTANCE__
*hPrevInstance
,
1163 return main (__argc
, __argv
);