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/>.
23 #include "dsp_mainwindow.h"
24 #include "hb-preferences.h"
31 #define APPLICATION_NAME "HomeBank"
33 /****************************************************************************/
35 /****************************************************************************/
44 /* our global datas */
45 struct HomeBank
*GLOBALS
;
46 struct Preferences
*PREFS
;
49 /* installation paths */
50 static gchar
*config_dir
= NULL
;
51 static gchar
*images_dir
= NULL
;
52 static gchar
*pixmaps_dir
= NULL
;
53 static gchar
*locale_dir
= NULL
;
54 static gchar
*help_dir
= NULL
;
55 static gchar
*datas_dir
= NULL
;
56 static gchar
*pkglib_dir
= NULL
;
59 //#define MARKUP_STRING "<span size='small'>%s</span>"
62 /* Application arguments */
63 static gboolean arg_version
= FALSE
;
64 static gchar
**files
= NULL
;
66 static GOptionEntry option_entries
[] =
68 { "version", '\0', 0, G_OPTION_ARG_NONE
, &arg_version
,
69 N_("Output version information and exit"), NULL
},
71 { G_OPTION_REMAINING
, '\0', 0, G_OPTION_ARG_FILENAME_ARRAY
, &files
,
79 ** try to determine the file type (if supported for import by homebank)
83 gint
homebank_alienfile_recognize(gchar
*filename
)
86 gint i
, retval
= FILETYPE_UNKNOW
;
90 static gint csvtype
[7] = {
101 DB( g_print("\n[homebank] alienfile_recognize\n") );
104 io
= g_io_channel_new_file(filename
, "r", NULL
);
107 g_io_channel_set_encoding(io
, NULL
, NULL
); /* set to binary mode */
111 if( retval
!= FILETYPE_UNKNOW
)
114 io_stat
= g_io_channel_read_line(io
, &tmpstr
, NULL
, NULL
, &err
);
115 if( io_stat
== G_IO_STATUS_EOF
)
117 if( io_stat
== G_IO_STATUS_ERROR
)
119 DB (g_print(" + ERROR %s\n",err
->message
));
122 if( io_stat
== G_IO_STATUS_NORMAL
)
124 if( *tmpstr
!= '\0' )
126 DB( g_print(" line %d: '%s' retval=%d\n", i
, tmpstr
, retval
) );
128 /* native homebank file */
129 if( g_str_has_prefix(tmpstr
, "<homebank v="))
131 DB( g_print(" type is HomeBank\n") );
132 retval
= FILETYPE_HOMEBANK
;
137 if( g_str_has_prefix(tmpstr
, "!Type") ||
138 g_str_has_prefix(tmpstr
, "!type") ||
139 g_str_has_prefix(tmpstr
, "!Option") ||
140 g_str_has_prefix(tmpstr
, "!option") ||
141 g_str_has_prefix(tmpstr
, "!Account") ||
142 g_str_has_prefix(tmpstr
, "!account")
145 DB( g_print(" type is QIF\n") );
146 retval
= FILETYPE_QIF
;
151 if( g_strstr_len(tmpstr
, 10, "OFX") != NULL
)
153 DB( g_print(" type is OFX\n") );
154 retval
= FILETYPE_OFX
;
157 /* is it csv homebank ? */
162 hbcsv
= hb_string_csv_valid(tmpstr
, 8, csvtype
);
164 DB( g_print(" hbcsv %d\n", hbcsv
) );
168 DB( g_print(" type is CSV homebank\n") );
169 retval
= FILETYPE_CSV_HB
;
180 g_io_channel_unref (io
);
187 /* = = = = = = = = = = = = = = = = = = = = */
193 ** ensure the filename ends with '.xhb'
195 void homebank_file_ensure_xhb(void)
199 DB( g_print("\n[homebank] file_ensure_xhb\n") );
201 newfilepath
= hb_filename_new_with_extention(GLOBALS
->xhb_filepath
, "xhb");
202 hbfile_change_filepath(newfilepath
);
204 DB( g_print("- out: %s\n", GLOBALS
->xhb_filepath
) );
208 static gboolean
homebank_copy_file(gchar
*srcfile
, gchar
*dstfile
)
212 //GError *error = NULL;
213 gboolean retval
= FALSE
;
215 if (g_file_get_contents (srcfile
, &buffer
, &length
, NULL
))
217 if(g_file_set_contents(dstfile
, buffer
, length
, NULL
))
227 void homebank_backup_current_file(gchar
*pathname
)
235 DB( g_print("\n[homebank] backup_current_file\n") );
237 basename
= g_path_get_basename(pathname
);
238 dirname
= g_path_get_dirname (pathname
);
240 if( g_str_has_suffix(basename
, ".xhb") )
242 str_array
= g_strsplit(basename
, ".", 0);
243 filename
= g_strdup_printf("%s.xhb~", str_array
[0]);
244 newname
= g_build_filename(dirname
, filename
, NULL
);
247 if( g_file_test(newname
, G_FILE_TEST_EXISTS
) )
249 DB( g_print("- remove existing: %s\n", newname
) );
253 DB( g_print("- copy %s => %s\n", pathname
, newname
) );
255 homebank_copy_file (pathname
, newname
);
257 //retval = g_rename(pathname, newname);
259 //DB( g_print("retval %d\n", retval) );
261 g_strfreev(str_array
);
268 /* = = = = = = = = = = = = = = = = = = = = */
276 homebank_util_url_show_win32 (const gchar
*url
)
282 retval
= ShellExecuteA (NULL
, "open", url
, NULL
, NULL
, SW_NORMAL
);
284 if (retval
< 0 || retval
> 32)
287 errmsg
= g_win32_error_message(retval
);
288 DB( g_print ("%s\n", errmsg
) );
297 homebank_util_url_show_unix (const gchar
*url
)
302 retval
= gtk_show_uri (gtk_widget_get_screen (GTK_WIDGET (GLOBALS
->mainwindow
)), url
, GDK_CURRENT_TIME
, &err
);
306 ui_dialog_msg_infoerror(GTK_WINDOW(GLOBALS
->mainwindow
), GTK_MESSAGE_ERROR
,
308 _("Could not display the URL '%s'"),
315 g_print ("%s\n", err
->message
);
325 homebank_util_url_show (const gchar
*url
)
333 return homebank_util_url_show_win32 (url
);
335 return homebank_util_url_show_unix (url
);
340 /* = = = = = = = = = = = = = = = = = = = = */
341 /* lastopenedfiles */
344 ** load lastopenedfiles from homedir/.homebank
346 gboolean
homebank_lastopenedfiles_load(void)
349 gboolean retval
= FALSE
;
350 gchar
*group
, *filename
, *lastfilename
;
352 DB( g_print("\n[homebank] lastopenedfiles load\n") );
354 keyfile
= g_key_file_new();
358 filename
= g_build_filename(homebank_app_get_config_dir(), "lastopenedfiles", NULL
);
360 DB( g_print(" -> filename: %s\n", filename
) );
362 if(g_key_file_load_from_file (keyfile
, filename
, G_KEY_FILE_NONE
, NULL
))
366 DB( g_print(" -> load keyfile ok\n") );
368 if(g_key_file_has_key(keyfile
, group
, "LastOpenedFile", NULL
))
370 DB( g_print(" -> keyfile has key ok\n") );
372 lastfilename
= g_key_file_get_string (keyfile
, group
, "LastOpenedFile", NULL
);
374 DB( g_print(" -> lastfile loaded: %s\n", lastfilename
) );
376 if (g_file_test (lastfilename
, G_FILE_TEST_EXISTS
) != FALSE
)
378 DB( g_print(" -> file exists\n") );
380 hbfile_change_filepath(lastfilename
);
387 g_key_file_free (keyfile
);
390 DB( g_print(" -> return: %d\n", retval
) );
397 ** save lastopenedfiles to homedir/.homebank (HB_DATA_PATH)
399 gboolean
homebank_lastopenedfiles_save(void)
402 gboolean retval
= FALSE
;
403 gchar
*group
, *filename
;
406 DB( g_print("\n[homebank] lastopenedfiles save\n") );
408 if( GLOBALS
->xhb_filepath
!= NULL
)
411 keyfile
= g_key_file_new();
415 g_key_file_set_string (keyfile
, group
, "LastOpenedFile", GLOBALS
->xhb_filepath
);
417 gchar
*contents
= g_key_file_to_data( keyfile
, &length
, NULL
);
419 //DB( g_print(" keyfile:\n%s\nlen=%d\n", contents, length) );
421 filename
= g_build_filename(homebank_app_get_config_dir(), "lastopenedfiles", NULL
);
422 g_file_set_contents(filename
, contents
, length
, NULL
);
426 g_key_file_free (keyfile
);
435 /* = = = = = = = = = = = = = = = = = = = = */
440 static void free_list_pixbuf(void)
444 DB( g_print("\n[homebank] free_list_pixbuf\n") );
446 for(i
=0;i
<NUM_LST_PIXBUF
;i
++)
448 if(GLOBALS
->lst_pixbuf
[i
] != NULL
)
450 g_object_unref(GLOBALS
->lst_pixbuf
[i
]);
455 static void load_list_pixbuf(void)
461 DB( g_print("\n[homebank] load_list_pixbuf\n") );
463 cellview
= gtk_cell_view_new ();
465 /* list added (account/transaction list) */
466 pixbuf
= gtk_widget_render_icon (cellview
, GTK_STOCK_NEW
, GTK_ICON_SIZE_MENU
, NULL
);
467 //g_object_unref(pixbuf);
468 GLOBALS
->lst_pixbuf
[LST_PIXBUF_ADD
] = pixbuf
;
470 /* list scheduled (archive list) */
471 pixbuf
= gtk_widget_render_icon (cellview
, HB_STOCK_OPE_AUTO
, GTK_ICON_SIZE_MENU
, NULL
);
472 //g_object_unref(pixbuf);
473 GLOBALS
->lst_pixbuf
[LST_PIXBUF_AUTO
] = pixbuf
;
475 /* list edited (account/transaction list) */
476 pixbuf
= gtk_widget_render_icon (cellview
, GTK_STOCK_EDIT
, GTK_ICON_SIZE_MENU
, NULL
);
477 //g_object_unref(pixbuf);
478 GLOBALS
->lst_pixbuf
[LST_PIXBUF_EDIT
] = pixbuf
;
480 /* list remind (transaction list) */
481 pixbuf
= gtk_widget_render_icon (cellview
, HB_STOCK_OPE_REMIND
, GTK_ICON_SIZE_MENU
, NULL
);
482 //g_object_unref(pixbuf);
483 GLOBALS
->lst_pixbuf
[LST_PIXBUF_REMIND
] = pixbuf
;
485 /* list reconciled (transaction list) */
486 pixbuf
= gtk_widget_render_icon (cellview
, HB_STOCK_OPE_VALID
, GTK_ICON_SIZE_MENU
, NULL
);
487 //g_object_unref(pixbuf);
488 GLOBALS
->lst_pixbuf
[LST_PIXBUF_VALID
] = pixbuf
;
490 /* list warning (import transaction list) */
491 pixbuf
= gtk_widget_render_icon (cellview
, GTK_STOCK_DIALOG_WARNING
, GTK_ICON_SIZE_MENU
, NULL
);
492 //g_object_unref(pixbuf);
493 GLOBALS
->lst_pixbuf
[LST_PIXBUF_WARNING
] = pixbuf
;
495 GLOBALS
->lst_pixbuf_maxwidth
= 0;
496 for(i
=0;i
<NUM_LST_PIXBUF
;i
++)
498 if( GLOBALS
->lst_pixbuf
[i
] != NULL
)
499 GLOBALS
->lst_pixbuf_maxwidth
= MAX(GLOBALS
->lst_pixbuf_maxwidth
, gdk_pixbuf_get_width(GLOBALS
->lst_pixbuf
[i
]) );
503 DB( g_print(" -> pixbuf list maxwidth: %d\n", GLOBALS
->lst_pixbuf_maxwidth
) );
505 gtk_widget_destroy (cellview
);
511 homebank_register_stock_icons()
513 DB( g_print("\n[homebank] register_stock_icons\n") );
515 GtkIconFactory
*factory
;
516 GtkIconSet
*icon_set
;
517 GtkIconSource
*icon_source
;
520 const char *icon_theme_items
[] =
552 factory
= gtk_icon_factory_new ();
554 for (i
= 0; i
< G_N_ELEMENTS (icon_theme_items
); i
++)
556 icon_source
= gtk_icon_source_new ();
557 gtk_icon_source_set_icon_name (icon_source
, icon_theme_items
[i
]);
559 icon_set
= gtk_icon_set_new ();
560 gtk_icon_set_add_source (icon_set
, icon_source
);
561 gtk_icon_source_free (icon_source
);
563 gtk_icon_factory_add (factory
, icon_theme_items
[i
], icon_set
);
564 gtk_icon_set_unref (icon_set
);
567 //gtk_stock_add_static (icon_theme_items, G_N_ELEMENTS (icon_theme_items));
569 gtk_icon_factory_add_default (factory
);
570 g_object_unref (factory
);
573 GtkIconTheme
*ic
= gtk_icon_theme_get_default();
576 DB( g_print(" -> get default icon theme\n") );
578 gtk_icon_theme_get_search_path(ic
, &paths
, NULL
);
579 for(i
=0;i
<g_strv_length(paths
);i
++)
581 g_print("-> path %d: %s\n", i
, paths
[i
]);
590 DB( g_print(" -> adding theme search path: %s\n", homebank_app_get_pixmaps_dir()) );
591 gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (), homebank_app_get_pixmaps_dir());
595 void homebank_window_set_icon_from_file(GtkWindow *window, gchar *filename)
599 pathfilename = g_build_filename(homebank_app_get_pixmaps_dir(), filename, NULL);
600 gtk_window_set_icon_from_file(GTK_WINDOW (window), pathfilename, NULL);
601 g_free(pathfilename);
606 homebank_app_get_config_dir (void)
612 homebank_app_get_images_dir (void)
618 homebank_app_get_pixmaps_dir (void)
624 homebank_app_get_locale_dir (void)
630 homebank_app_get_help_dir (void)
636 homebank_app_get_datas_dir (void)
642 homebank_app_get_pkglib_dir (void)
648 /* build package paths at runtime */
650 build_package_paths (void)
652 DB( g_print("\n[homebank] build_package_paths\n") );
657 prefix
= g_win32_get_package_installation_directory_of_module (NULL
);
658 locale_dir
= g_build_filename (prefix
, "share", "locale", NULL
);
659 images_dir
= g_build_filename (prefix
, "share", PACKAGE
, "images", NULL
);
660 pixmaps_dir
= g_build_filename (prefix
, "share", PACKAGE
, "icons", NULL
);
661 help_dir
= g_build_filename (prefix
, "share", PACKAGE
, "help", NULL
);
662 datas_dir
= g_build_filename (prefix
, "share", PACKAGE
, "datas", NULL
);
663 pkglib_dir
= g_build_filename (prefix
, "lib", PACKAGE
, NULL
);
665 DB( g_print("- app is portable under windows\n") );
666 config_dir
= g_build_filename(prefix
, "config", NULL
);
668 config_dir
= g_build_filename(g_get_user_config_dir(), HB_DATA_PATH
, NULL
);
672 locale_dir
= g_build_filename (DATA_DIR
, "locale", NULL
);
673 images_dir
= g_build_filename (SHARE_DIR
, "images", NULL
);
674 pixmaps_dir
= g_build_filename (DATA_DIR
, PACKAGE
, "icons", NULL
);
675 help_dir
= g_build_filename (DATA_DIR
, PACKAGE
, "help", NULL
);
676 datas_dir
= g_build_filename (DATA_DIR
, PACKAGE
, "datas", NULL
);
677 config_dir
= g_build_filename (g_get_user_config_dir(), HB_DATA_PATH
, NULL
);
678 pkglib_dir
= g_build_filename (PKGLIB_DIR
, NULL
);
680 //#870023 Ubuntu packages the help files in "/usr/share/doc/homebank-data/help/" for some strange reason
681 if(! g_file_test(help_dir
, (G_FILE_TEST_EXISTS
| G_FILE_TEST_IS_DIR
)))
684 help_dir
= g_build_filename ("/usr", "share", "doc", "homebank-data", "help", NULL
);
688 DB( g_print("- config_dir : %s\n", config_dir
) );
689 DB( g_print("- images_dir : %s\n", images_dir
) );
690 DB( g_print("- pixmaps_dir: %s\n", pixmaps_dir
) );
691 DB( g_print("- locale_dir : %s\n", locale_dir
) );
692 DB( g_print("- help_dir : %s\n", help_dir
) );
693 DB( g_print("- datas_dir : %s\n", datas_dir
) );
694 DB( g_print("- pkglib_dir : %s\n", pkglib_dir
) );
699 guint32
homebank_app_date_get_julian(void)
702 //init global default value
704 g_date_set_time_t(date
, time(NULL
));
705 GLOBALS
->today
= g_date_get_julian(date
);
707 return GLOBALS
->today
;
711 static gboolean
homebank_check_app_dir_migrate_file(gchar
*srcdir
, gchar
*dstdir
, gchar
*filename
)
717 //GError *error = NULL;
718 gboolean retval
= FALSE
;
720 DB( g_print("\n[homebank] check_app_dir_migrate_file\n") );
722 srcpath
= g_build_filename(srcdir
, filename
, NULL
);
723 dstpath
= g_build_filename(dstdir
, filename
, NULL
);
725 if (g_file_get_contents (srcpath
, &buffer
, &length
, NULL
))
727 if(g_file_set_contents(dstpath
, buffer
, length
, NULL
))
729 //g_print("sould remove %s\n", srcpath);
742 * check/create user home directory for .homebank (HB_DATA_PATH) directory
744 static void homebank_check_app_dir()
747 const gchar
*configdir
;
750 DB( g_print("\n[homebank] check_app_dir\n") );
752 /* check if <userdir>/.config exist */
754 configdir
= g_get_user_config_dir();
755 DB( g_print("- check '%s' exists\n", configdir
) );
756 if(!g_file_test(configdir
, G_FILE_TEST_IS_DIR
))
758 DB( g_print("- creating dir\n") );
759 g_mkdir(configdir
, 0755);
763 /* check for XDG .config/homebank */
764 configdir
= homebank_app_get_config_dir();
765 DB( g_print("- config_dir is: '%s'\n", configdir
) );
766 exists
= g_file_test(configdir
, G_FILE_TEST_IS_DIR
);
769 /* just update folder security */
770 DB( g_print("- chmod 0700\n") );
771 g_chmod(configdir
, 0700);
772 GLOBALS
->first_run
= FALSE
;
776 /* create the config dir */
777 DB( g_print("- create config_dir\n") );
778 g_mkdir(configdir
, 0755);
779 g_chmod(configdir
, 0700);
781 /* any old homedir configuration out there ? */
782 homedir
= g_build_filename(g_get_home_dir (), ".homebank", NULL
);
783 DB( g_print("- homedir is: '%s'\n", homedir
) );
785 exists
= g_file_test(homedir
, G_FILE_TEST_IS_DIR
);
789 /* we must do the migration properly */
790 DB( g_print("- migrate old 2 files\n") );
791 f1
= homebank_check_app_dir_migrate_file(homedir
, config_dir
, "preferences");
792 f2
= homebank_check_app_dir_migrate_file(homedir
, config_dir
, "lastopenedfiles");
795 DB( g_print("- removing old dir\n") );
800 GLOBALS
->first_run
= TRUE
;
807 ** application cleanup: icons, GList, memory
809 static void homebank_cleanup()
812 DB( g_print("\n\n[homebank] cleanup\n") );
814 //v3.4 save windows size/position
815 homebank_pref_save();
818 free_paymode_icons();
822 hbfile_cleanup(TRUE
);
824 /* free our global datas */
827 homebank_pref_free();
838 g_free (pixmaps_dir
);
848 ** application setup: icons, GList, memory
850 static gboolean
homebank_setup()
853 DB( g_print("\n[homebank] setup\n") );
855 GLOBALS
= g_malloc0(sizeof(struct HomeBank
));
856 if(!GLOBALS
) return FALSE
;
857 PREFS
= g_malloc0(sizeof(struct Preferences
));
858 if(!PREFS
) return FALSE
;
860 // check homedir for .homebank dir
861 homebank_check_app_dir();
863 homebank_pref_setdefault();
864 homebank_pref_load();
868 homebank_register_stock_icons();
871 load_paymode_icons();
875 homebank_app_date_get_julian();
880 g_print("- user_name: %s\n", g_get_user_name ());
881 g_print("- real_name: %s\n", g_get_real_name ());
882 g_print("- user_cache_dir: %s\n", g_get_user_cache_dir());
883 g_print("- user_data_dir: %s\n", g_get_user_data_dir ());
884 g_print("- user_config_dir: %s\n", g_get_user_config_dir ());
885 //g_print("- system_data_dirs: %s\n", g_get_system_data_dirs ());
886 //g_print("- system_config_dirs: %s\n", g_get_system_config_dirs ());
888 g_print("- home_dir: %s\n", g_get_home_dir ());
889 g_print("- tmp_dir: %s\n", g_get_tmp_dir ());
890 g_print("- current_dir: %s\n", g_get_current_dir ());
898 /* = = = = = = = = = = = = = = = = = = = = */
902 homebank_construct_splash()
905 GtkWidget
*frame
, *vbox
, *image
;
906 //gchar *ver_string, *markup, *version;
909 DB( g_print("[homebank_construct_splash]\n") );
911 window
= gtk_window_new(GTK_WINDOW_POPUP
); //TOPLEVEL DONT WORK
912 gtk_window_set_type_hint (GTK_WINDOW (window
), GDK_WINDOW_TYPE_HINT_SPLASHSCREEN
);
913 gtk_window_set_skip_taskbar_hint (GTK_WINDOW (window
), TRUE
);
915 gtk_window_set_title (GTK_WINDOW (window
), "HomeBank");
916 gtk_window_set_position (GTK_WINDOW (window
), GTK_WIN_POS_CENTER
);
918 pathfilename
= g_build_filename(homebank_app_get_images_dir(), "splash.png", NULL
);
919 image
= gtk_image_new_from_file((const gchar
*)pathfilename
);
920 g_free(pathfilename
);
922 frame
= gtk_frame_new (NULL
);
923 gtk_frame_set_shadow_type (GTK_FRAME (frame
), GTK_SHADOW_OUT
);
924 gtk_container_add (GTK_CONTAINER (window
), frame
);
926 vbox
= gtk_vbox_new (FALSE
, 0);
927 gtk_container_add (GTK_CONTAINER (frame
), vbox
);
930 ver_string = g_strdup_printf(_("Version: HomeBank-%s"), VERSION);
932 version = gtk_label_new(NULL);
933 markup = g_markup_printf_escaped(MARKUP_STRING, ver_string);
934 gtk_label_set_markup(GTK_LABEL(version), markup);
939 gtk_box_pack_start (GTK_BOX (vbox
), image
, FALSE
, FALSE
, 0);
940 //gtk_box_pack_start (GTK_BOX (vbox), version, FALSE, FALSE, 0);
946 homebank_init_i18n (void)
948 /* We may change the locale later if the user specifies a language
949 * in the gimprc file. Here we are just initializing the locale
950 * according to the environment variables and set up the paths to
951 * the message catalogs.
954 setlocale (LC_ALL
, "");
956 bindtextdomain (GETTEXT_PACKAGE
, homebank_app_get_locale_dir ());
957 //#ifdef HAVE_BIND_TEXTDOMAIN_CODESET
958 bind_textdomain_codeset (GETTEXT_PACKAGE
, "UTF-8");
961 textdomain (GETTEXT_PACKAGE
);
964 gchar *wl = g_win32_getlocale ();
965 DB( g_print(" -> win32 locale is '%s'\n", wl) );
973 main (int argc
, char *argv
[], char *env
[])
975 GOptionContext
*option_context
;
976 GOptionGroup
*option_group
;
977 GError
*error
= NULL
;
979 GtkWidget
*splash
= NULL
;
982 DB( g_print("\n--------------------------------" ) );
983 DB( g_print("\nhomebank starting...\n" ) );
985 build_package_paths();
987 homebank_init_i18n ();
989 /* Set up option groups */
990 option_context
= g_option_context_new (NULL
);
992 //g_option_context_set_summary (option_context, _(""));
994 option_group
= g_option_group_new ("homebank",
995 N_("HomeBank options"),
996 N_("HomeBank options"),
998 g_option_group_add_entries (option_group
, option_entries
);
999 g_option_context_set_main_group (option_context
, option_group
);
1000 g_option_group_set_translation_domain (option_group
, GETTEXT_PACKAGE
);
1002 /* Add Gtk option group */
1003 g_option_context_add_group (option_context
, gtk_get_option_group (FALSE
));
1005 /* Parse command line */
1006 if (!g_option_context_parse (option_context
, &argc
, &argv
, &error
))
1008 g_option_context_free (option_context
);
1012 g_print ("%s\n", error
->message
);
1013 g_error_free (error
);
1016 g_print ("An unknown error occurred\n");
1021 g_option_context_free (option_context
);
1022 option_context
= NULL
;
1024 if (arg_version
!= FALSE
)
1026 /* Print version information and exit */
1027 g_print ("%s\n", PACKAGE
" " VERSION
);
1031 /* Pass NULL here since we parsed the gtk+ args already...
1032 * from this point all we need a DISPLAY variable to be set.
1034 gtk_init (NULL
, NULL
);
1036 //todo: sanity check gtk version here ?
1038 g_set_application_name (APPLICATION_NAME
);
1040 if( homebank_setup() )
1042 /* change the locale if a language is specified */
1043 language_init (PREFS
->language
);
1045 DB( g_print(" -> loading plugins\n") );
1046 ext_init(&argc
, &argv
, &env
);
1049 for (it
= PREFS
->ext_whitelist
; it
; it
= g_list_next(it
)) {
1050 ext_load_plugin(it
->data
);
1053 gchar
** plugins
= ext_list_plugins();
1055 for (plugins_it
= plugins
; *plugins_it
; ++plugins_it
) {
1056 gboolean loaded
= ext_is_plugin_loaded(*plugins_it
);
1057 g_print("found plugin: %s, loaded: %d\n", *plugins_it
, loaded
);
1059 g_strfreev(plugins
);
1061 if( PREFS
->showsplash
== TRUE
)
1063 splash
= homebank_construct_splash();
1064 gtk_window_set_auto_startup_notification (FALSE
);
1065 gtk_widget_show_all (splash
);
1066 gtk_window_set_auto_startup_notification (TRUE
);
1068 // make sure splash is up
1069 while (gtk_events_pending ())
1070 gtk_main_iteration ();
1074 pathfilename = g_build_filename(homebank_app_get_pixmaps_dir(), "homebank.svg", NULL);
1075 gtk_window_set_default_icon_from_file(pathfilename, NULL);
1076 g_free(pathfilename);
1079 gtk_window_set_default_icon_name ("homebank");
1081 DB( g_print(" -> creating window\n" ) );
1084 mainwin
= (GtkWidget
*)create_hbfile_window (NULL
);
1086 GValue mainwin_val
= G_VALUE_INIT
;
1087 ext_hook("create_main_window", EXT_OBJECT(&mainwin_val
, mainwin
), NULL
);
1092 //todo: pause on splash
1093 if( PREFS
->showsplash
== TRUE
)
1095 //g_usleep( G_USEC_PER_SEC * 1 );
1096 gtk_widget_hide(splash
);
1097 gtk_widget_destroy(splash
);
1101 #if HB_UNSTABLE == TRUE
1102 /* GtkWidget *dialog = gtk_message_dialog_new (GTK_WINDOW(mainwin),
1103 GTK_DIALOG_DESTROY_WITH_PARENT,
1104 GTK_MESSAGE_WARNING,
1106 "This is a beta version of HomeBank (UNSTABLE)"
1109 gtk_message_dialog_format_secondary_markup (GTK_MESSAGE_DIALOG (dialog),
1110 "DO NOT USE with important files or do a backup first.\n"
1111 "This kind of release is for <b>TESTING ONLY</b>.\n"
1112 "<u>It may be buggy, crash, or lose your data</u>.\n\n"
1114 "For unstable bugs report, questions, suggestions:\n"
1115 " - <b>DO NOT USE LaunchPad</b>\n"
1116 " - direct email to: <homebank@free.fr>\n\n"
1121 gtk_dialog_run (GTK_DIALOG (dialog));
1122 gtk_widget_destroy (dialog);*/
1125 if(GLOBALS
->first_run
)
1127 ui_mainwindow_action_help_welcome();
1131 while (gtk_events_pending ()) /* make sure splash is gone */
1132 gtk_main_iteration ();
1135 DB( g_print(" -> open last file ?\n" ) );
1138 /* load 1st file specified on commandline */
1139 openlast
= PREFS
->loadlast
;
1142 if (g_file_test (files
[0], G_FILE_TEST_EXISTS
) != FALSE
)
1144 DB( g_print(" -> should load %s\n", files
[0] ) );
1145 hbfile_change_filepath(g_strdup(files
[0]));
1146 ui_mainwindow_open_internal(mainwin
, NULL
);
1151 g_warning (_("Unable to open '%s', the file does not exist.\n"), files
[0]);
1158 DB( g_print(" -> GLOBALS->xhb_filepath: '%s'\n", GLOBALS
->xhb_filepath
) );
1162 if( homebank_lastopenedfiles_load() == TRUE
)
1163 ui_mainwindow_open_internal(mainwin
, NULL
);
1166 /* update the mainwin display */
1167 ui_mainwindow_update(mainwin
, GINT_TO_POINTER(UF_TITLE
+UF_SENSITIVE
+UF_BALANCE
+UF_VISUAL
));
1169 ext_hook("enter_main_loop", NULL
);
1171 DB( g_print(" -> gtk_main()\n" ) );
1174 ext_hook("exit_main_loop", NULL
);
1177 DB( g_print(" -> unloading plugins\n") );
1185 return EXIT_SUCCESS
;
1189 /* In case we build this as a windowed application */
1192 #define _stdcall __attribute__((stdcall))
1196 WinMain (struct HINSTANCE__
*hInstance
,
1197 struct HINSTANCE__
*hPrevInstance
,
1201 return main (__argc
, __argv
);