Esempio n. 1
0
static void menubar_open_mod_cb(GtkWidget * widget, gpointer data)
{
    gchar          *modnam = NULL;
    gchar          *modfile;
    gchar          *confdir;
    GtkWidget      *module = NULL;

    (void)widget;
    (void)data;

    sat_log_log(SAT_LOG_LEVEL_DEBUG, _("%s: Open existing module..."),
                __func__);

    modnam = select_module();

    if (modnam)
    {
        sat_log_log(SAT_LOG_LEVEL_DEBUG, _("%s: Open module %s."), __func__,
                    modnam);

        confdir = get_modules_dir();
        modfile =
            g_strconcat(confdir, G_DIR_SEPARATOR_S, modnam, ".mod", NULL);
        g_free(confdir);

        /* create new module */
        module = gtk_sat_module_new(modfile);

        if (module == NULL)
        {
            /* mod manager could not create the module */
            GtkWidget      *dialog;

            dialog = gtk_message_dialog_new(GTK_WINDOW(app),
                                            GTK_DIALOG_MODAL |
                                            GTK_DIALOG_DESTROY_WITH_PARENT,
                                            GTK_MESSAGE_ERROR,
                                            GTK_BUTTONS_OK,
                                            _("Could not open %s. "
                                              "Please examine the log "
                                              "messages for details."),
                                            modnam);

            gtk_dialog_run(GTK_DIALOG(dialog));
            gtk_widget_destroy(dialog);
        }
        else
        {
            /* if module state was window or user does not want to restore the
               state of the modules, pack the module into the notebook */
            if ((GTK_SAT_MODULE(module)->state == GTK_SAT_MOD_STATE_DOCKED) ||
                !sat_cfg_get_bool(SAT_CFG_BOOL_MOD_STATE))
            {
                mod_mgr_add_module(module, TRUE);
            }
            else
            {
                mod_mgr_add_module(module, FALSE);
                create_module_window(module);
            }
        }

        g_free(modnam);
        g_free(modfile);
    }
    else
    {
        sat_log_log(SAT_LOG_LEVEL_DEBUG, _("%s: Open module cancelled."),
                    __func__);
    }
}
Esempio n. 2
0
/** \brief Create and initialise module manger.
 *  \return The main module container widget (GtkNotebook).
 *
 * This function creates and initialises the module manager widget, which
 * consist of a GtkNotebook container. Before returning the container to the
 * caller, the function checks whether any modules should be restored (ie.
 * openend), if yes, it creates them and adds them to the notebook.
 *
 */
GtkWidget *
mod_mgr_create (void)
{
    gchar  *openmods = NULL;
    gchar **mods;
    gint    count,i;
    GtkWidget *module;
    gchar     *modfile;
    gchar     *confdir;

    /* create notebook */
    nbook = gtk_notebook_new ();
    gtk_notebook_set_scrollable (GTK_NOTEBOOK (nbook), TRUE);
    gtk_notebook_popup_enable (GTK_NOTEBOOK (nbook));
    g_object_set (G_OBJECT (nbook), "homogeneous", TRUE, NULL);
    g_signal_connect (G_OBJECT (nbook), "switch-page",
                      G_CALLBACK (switch_page_cb), NULL);

    /* get list of modules which should be open */
    openmods = sat_cfg_get_str (SAT_CFG_STR_OPEN_MODULES);

    if (openmods) {
        mods = g_strsplit (openmods, ";", 0);
        count = g_strv_length (mods);

        for (i = 0; i < count; i++) {

            /* get data file name */
            confdir = get_modules_dir ();
            modfile = g_strconcat (confdir, G_DIR_SEPARATOR_S,
                                   mods[i], ".mod", NULL);
            g_free (confdir);
            
            /* create module */
            module = gtk_sat_module_new (modfile);

            if (IS_GTK_SAT_MODULE (module)) {

                /* if module state was window or user does not want to restore the
                   state of the modules, pack the module into the notebook */
                if ((GTK_SAT_MODULE (module)->state == GTK_SAT_MOD_STATE_DOCKED) ||
                    !sat_cfg_get_bool (SAT_CFG_BOOL_MOD_STATE)) {

                    mod_mgr_add_module (module, TRUE);

                }
                else {
                    mod_mgr_add_module (module, FALSE);
                    create_module_window (module);
                }
            }
            else {
                sat_log_log (SAT_LOG_LEVEL_ERROR,
                             _("%s: Failed to restore %s"),
                             __FUNCTION__, mods[i]);
            }

            g_free (modfile);

        }

        g_strfreev (mods);
        g_free (openmods);

        /* disable tabs if only one page in notebook */
        if ((gtk_notebook_get_n_pages (GTK_NOTEBOOK(nbook))) == 1) {
            gtk_notebook_set_show_tabs (GTK_NOTEBOOK (nbook), FALSE);
        }
        else {
            gtk_notebook_set_show_tabs (GTK_NOTEBOOK (nbook), TRUE);
        }

    }
    else {
        sat_log_log (SAT_LOG_LEVEL_MSG,
                     _("%s: No modules have to be restored."),
                     __FUNCTION__);
    }

    return nbook;
}