Ejemplo n.º 1
0
void MainWindow::newFile()
{
    if (maybeSave())
    {

        if (m_session)
        {
            /* close any ongoing file sessions, and free the accounts.
             * disable events so we don't gobj spammed by redraws. */
            qof_event_suspend ();

            gnc_hook_run(HOOK_BOOK_CLOSED, m_session.gobj());

            qof_session_destroy(m_session.gobj());
            m_session.reset();
            qof_event_resume ();
        }

        /* start a new book */
        m_session.reset(qof_session_new());

        gnc_hook_run(HOOK_NEW_BOOK, NULL);

        /* Call this after re-enabling events. */
        gnc_hook_run(HOOK_BOOK_OPENED, m_session.gobj());

        setCurrentFile("");
    }
}
Ejemplo n.º 2
0
void
gnc_main_gui_init (void)
{
    ENTER(" ");

    if (!gnucash_style_init())
        gnc_shutdown(1);
    gnucash_color_init();

    gnc_html_register_url_handler (URL_TYPE_REGISTER,
                                   gnc_html_register_url_cb);

    gnc_html_register_url_handler (URL_TYPE_PRICE,
                                   gnc_html_price_url_cb);

    gnc_ui_sx_initialize();

    /* FIXME Remove this test code */
    gnc_plugin_manager_add_plugin (
        gnc_plugin_manager_get (), gnc_plugin_account_tree_new ());
    gnc_plugin_manager_add_plugin (
        gnc_plugin_manager_get (), gnc_plugin_basic_commands_new ());
    gnc_plugin_manager_add_plugin (
        gnc_plugin_manager_get (), gnc_plugin_file_history_new ());
    gnc_plugin_manager_add_plugin (
        gnc_plugin_manager_get (), gnc_plugin_menu_additions_new ());
    gnc_plugin_manager_add_plugin (
        gnc_plugin_manager_get (), gnc_plugin_register_new ());
    gnc_plugin_manager_add_plugin (
        gnc_plugin_manager_get (), gnc_plugin_register2_new ());
    /* I'm not sure why the FIXME note says to remove this.  Maybe
       each module should be adding its own plugin to the manager?
       Anyway... Oh, maybe... nah */
    gnc_plugin_manager_add_plugin (gnc_plugin_manager_get (),
                                   gnc_plugin_budget_new ());
    gnc_ui_hierarchy_assistant_initialize();

    /* Run the ui startup hooks. */
    gnc_hook_run(HOOK_UI_STARTUP, NULL);

    gnc_hook_add_dangler(HOOK_BOOK_OPENED,
                         gnc_restore_all_state, NULL);
    gnc_hook_add_dangler(HOOK_BOOK_CLOSED,
                         gnc_save_all_state, NULL);

//    /* CAS: I'm not really sure why we remove before adding. */
//    gnc_hook_remove_dangler(HOOK_BOOK_CLOSED, (GFunc)gnc_reports_flush_global);
//    gnc_hook_add_dangler(HOOK_BOOK_CLOSED,
//                         (GFunc)gnc_reports_flush_global, NULL);


    LEAVE(" ");
    return;
}
Ejemplo n.º 3
0
void MainWindow::closeEvent(QCloseEvent *event)
{
    if (maybeSave())
    {
        m_dboard->mainWindowCloseEvent();
        writeSettings();
        event->accept();

        /* disable events; otherwise the mass deletion of accounts and
         * transactions during shutdown would cause massive redraws */
        qof_event_suspend ();

        gnc_hook_run(HOOK_BOOK_CLOSED, m_session.gobj());

        qof_session_destroy(m_session.gobj());
        m_session.reset();

        qof_event_resume ();
    }
    else
    {
        event->ignore();
    }
}
Ejemplo n.º 4
0
void
test_qofsession_aqb_kvp( void )
{
    /* load the accounts from the users datafile */
    /* but first, check to make sure we've got a session going. */
    QofBackendError io_err;
    char *file1 = get_filepath("file-book.gnucash");
    char *file2 = get_filepath("file-book-hbcislot.gnucash");

    if (1)
    {
        // A file with no content at all, but a valid XML file
        QofSession *new_session = qof_session_new ();
        char *newfile = g_strdup_printf("file://%s", file1);

        qof_session_begin (new_session, newfile, TRUE, FALSE, FALSE);
        io_err = qof_session_get_error (new_session);
        //printf("io_err1 = %d\n", io_err);
        g_assert(io_err != ERR_BACKEND_NO_HANDLER); // Do not have no handler

        g_assert(io_err != ERR_BACKEND_NO_SUCH_DB); // DB must exist
        g_assert(io_err != ERR_BACKEND_LOCKED);
        g_assert(io_err == 0);

        qof_session_load (new_session, NULL);
        io_err = qof_session_get_error (new_session);
        //printf("io_err2 = %d\n", io_err);
        g_assert(io_err == 0);

        g_free(newfile);
        g_free(file1);

        gnc_hook_run(HOOK_BOOK_CLOSED, new_session);
        //qof_session_destroy(new_session); // tries to delete the LCK file but it wasn't created in the first place
    }

    if (1)
    {
        // A file with no content except for the book_template_list kvp
        // slot
        QofSession *new_session = qof_session_new ();
        char *newfile = g_strdup_printf("file://%s", file2);

        qof_session_begin (new_session, newfile, TRUE, FALSE, FALSE);
        io_err = qof_session_get_error (new_session);
        //printf("io_err1 = %d\n", io_err);
        g_assert(io_err != ERR_BACKEND_NO_HANDLER); // Do not have no handler

        g_assert(io_err != ERR_BACKEND_NO_SUCH_DB); // DB must exist
        g_assert(io_err != ERR_BACKEND_LOCKED);
        g_assert(io_err == 0);

        qof_session_load (new_session, NULL);
        io_err = qof_session_get_error (new_session);
        //printf("io_err2 = %d\n", io_err);
        g_assert(io_err == 0);

        {
            GList *templ_list;
            GncABTransTempl *templ;
            QofBook *book = qof_session_get_book(new_session);
            const char* ORIGINAL_NAME = "Some Name";
            const char* CHANGED_NAME = "Some Changed Name";

            templ_list = gnc_ab_trans_templ_list_new_from_book (book);
            g_assert_cmpint(g_list_length(templ_list), ==, 1);

            templ = templ_list->data;
	    //Raise the edit level so that we can check that it's marked dirty.
	    qof_instance_increase_editlevel(QOF_INSTANCE(book));
	    g_assert_cmpstr(gnc_ab_trans_templ_get_name(templ), ==, ORIGINAL_NAME); // ok, name from file is here

            // Now we change the name into something else and verify it can be saved
            gnc_ab_trans_templ_set_name(templ, CHANGED_NAME);
            {
                g_assert(!qof_instance_get_dirty(QOF_INSTANCE(book))); // not yet dirty

                // Here we save the changed kvp
                gnc_ab_set_book_template_list(book, templ_list);
                g_assert(qof_instance_get_dirty(QOF_INSTANCE(book))); // yup, now dirty
                gnc_ab_trans_templ_list_free(templ_list);
            }

            {
                templ_list = gnc_ab_trans_templ_list_new_from_book (book);
                g_assert_cmpint(g_list_length(templ_list), ==, 1);

                templ = templ_list->data;
                g_assert_cmpstr(gnc_ab_trans_templ_get_name(templ), ==, CHANGED_NAME); // ok, the change has been saved!
                gnc_ab_trans_templ_list_free(templ_list);
            }
        }

        {
            // Check the kvp slots of a aqbanking-enabled account
            QofBook *book = qof_session_get_book(new_session);
            Account* account = gnc_book_get_root_account(book);
            GDate retrieved_date, original_date;
            gchar buff[MAX_DATE_LENGTH];

            g_assert(account);

            // The interesting test case here: Can we read the correct date
            // from the xml file?
            if (1)
            {
                Timespec retrieved_ts = gnc_ab_get_account_trans_retrieval(account);
                g_test_message("retrieved_ts=%s\n", gnc_print_date(retrieved_ts));
                //printf("Time=%s\n", gnc_print_date(retrieved_ts));

                retrieved_date = timespec_to_gdate(retrieved_ts);
                g_date_set_dmy(&original_date, 29, 8, 2014);

                g_assert_cmpint(g_date_compare(&retrieved_date, &original_date), ==, 0);
            }

            // A lower-level test here: Can we write and read again the
            // trans_retrieval date? This wouldn't need this particular
            // Account, just a general Account object.
            if (0)
            {
                Timespec original_ts = timespec_now(), retrieved_ts;

                // Check whether the "ab-trans-retrieval" property of Account
                // is written and read again correctly.
                gnc_ab_set_account_trans_retrieval(account, original_ts);
                retrieved_ts = gnc_ab_get_account_trans_retrieval(account);

//                printf("original_ts=%s = %d  retrieved_ts=%s = %d\n",
//                       gnc_print_date(original_ts), original_ts.tv_sec,
//                       gnc_print_date(retrieved_ts), retrieved_ts.tv_sec);

                original_date = timespec_to_gdate(original_ts);
                retrieved_date = timespec_to_gdate(retrieved_ts);

                qof_print_gdate (buff, sizeof (buff), &original_date);
                //printf("original_date=%s\n", buff);
                qof_print_gdate (buff, sizeof (buff), &retrieved_date);
                //printf("retrieved_date=%s\n", buff);

                // Is the retrieved date identical to the one written
                g_assert_cmpint(g_date_compare(&retrieved_date, &original_date), ==, 0);
            }
Ejemplo n.º 5
0
void
gncp_new_user_finish (void)
{
    gnc_hook_run(HOOK_BOOK_OPENED, gnc_get_current_session());
}
Ejemplo n.º 6
0
static void
inner_main (void *closure, int argc, char **argv)
{
    SCM main_mod;
    char* fn;
    GError *error = NULL;

    scm_c_eval_string("(debug-set! stack 200000)");

    main_mod = scm_c_resolve_module("gnucash main");
    scm_set_current_module(main_mod);

    load_gnucash_modules();

    /* Load the config before starting up the gui. This insures that
     * custom reports have been read into memory before the Reports
     * menu is created. */
    load_system_config();
    load_user_config();

    /* Setting-up the report menu must come after the module
       loading but before the gui initialization. */
    scm_c_use_module("gnucash report report-gnome");
    scm_c_eval_string("(gnc:report-menu-setup)");

    /* TODO: After some more guile-extraction, this should happen even
       before booting guile.  */
    gnc_main_gui_init();

    gnc_hook_add_dangler(HOOK_UI_SHUTDOWN, (GFunc)gnc_file_quit, NULL);

    scm_c_eval_string("(gnc:main)");

    /* Install Price Quote Sources */
    gnc_update_splash_screen(_("Checking Finance::Quote..."), GNC_SPLASH_PERCENTAGE_UNKNOWN);
    scm_c_use_module("gnucash price-quotes");
    scm_c_eval_string("(gnc:price-quotes-install-sources)");

    gnc_hook_run(HOOK_STARTUP, NULL);

    if (!nofile && (fn = get_file_to_load()))
    {
        gnc_update_splash_screen(_("Loading data..."), GNC_SPLASH_PERCENTAGE_UNKNOWN);
        gnc_file_open_file(fn);
        g_free(fn);
    }
    else if (gnc_gconf_get_bool("dialogs/new_user", "first_startup", &error)
             && !error)
    {
        gnc_destroy_splash_screen();
        gnc_ui_new_user_dialog();
    }

    gnc_destroy_splash_screen();

    gnc_main_window_show_all_windows();

    gnc_hook_run(HOOK_UI_POST_STARTUP, NULL);
    gnc_ui_start_event_loop();
    gnc_hook_remove_dangler(HOOK_UI_SHUTDOWN, (GFunc)gnc_file_quit);

    gnc_shutdown(0);
    return;
}
Ejemplo n.º 7
0
static void
app_utils_shutdown(void)
{
    gnc_exp_parser_shutdown();
    gnc_hook_run(HOOK_SAVE_OPTIONS, NULL);
}
Ejemplo n.º 8
0
void
gnc_main_gui_init (void)
{
    ENTER(" ");

    if (!gnucash_style_init())
        gnc_shutdown(1);
    gnucash_color_init();

    gnc_html_register_url_handler (URL_TYPE_REGISTER,
                                   gnc_html_register_url_cb);

    gnc_html_register_url_handler (URL_TYPE_PRICE,
                                   gnc_html_price_url_cb);

    /* Register the Owner search type */
    gnc_search_core_register_type (GNC_OWNER_MODULE_NAME,
                                    (GNCSearchCoreNew) gnc_search_owner_new);
    gnc_business_urls_initialize ();
    gnc_business_options_gnome_initialize ();

    /* FIXME Remove this test code */
    gnc_plugin_manager_add_plugin (
        gnc_plugin_manager_get (), gnc_plugin_account_tree_new ());
    gnc_plugin_manager_add_plugin (
        gnc_plugin_manager_get (), gnc_plugin_basic_commands_new ());
    gnc_plugin_manager_add_plugin (
        gnc_plugin_manager_get (), gnc_plugin_file_history_new ());
    gnc_plugin_manager_add_plugin (
        gnc_plugin_manager_get (), gnc_plugin_menu_additions_new ());
    gnc_plugin_manager_add_plugin (
        gnc_plugin_manager_get (), gnc_plugin_register_new ());
    gnc_plugin_manager_add_plugin (
        gnc_plugin_manager_get (), gnc_plugin_register2_new ());
    gnc_plugin_manager_add_plugin (
        gnc_plugin_manager_get (), gnc_plugin_business_new ());
    /* I'm not sure why the FIXME note says to remove this.  Maybe
       each module should be adding its own plugin to the manager?
       Anyway... Oh, maybe... nah */
    gnc_plugin_manager_add_plugin (gnc_plugin_manager_get (),
                                   gnc_plugin_budget_new ());
    gnc_ui_hierarchy_assistant_initialize();

    /* Run the ui startup hooks. */
    gnc_hook_run(HOOK_UI_STARTUP, NULL);

    gnc_hook_add_dangler(HOOK_BOOK_OPENED,
                         gnc_restore_all_state, NULL);
    gnc_hook_add_dangler(HOOK_BOOK_CLOSED,
                         gnc_save_all_state, NULL);
    gnc_hook_add_dangler(HOOK_BOOK_CLOSED,
                         (GFunc)gnc_reports_flush_global, NULL);
    gnc_hook_add_dangler(HOOK_BOOK_OPENED,
                         (GFunc)gnc_invoice_remind_bills_due_cb, NULL);
    gnc_hook_add_dangler(HOOK_BOOK_OPENED,
                         (GFunc)gnc_invoice_remind_invoices_due_cb, NULL);

    gnc_ui_sx_initialize();

    /* Add to preferences under Business */
    /* The parameters are; glade file, items to add from glade file - last being the dialog, preference tab name */
    gnc_preferences_add_page("business-prefs.glade", "liststore_printinvoice,days_in_adj,cust_days_in_adj,business_prefs",
                            _("Business"));

    LEAVE(" ");
    return;
}