Exemple #1
0
/** User pressed OK. Any changes should be stored in config. */
void sat_pref_layout_ok(GKeyFile * cfg)
{
    if (dirty)
    {
        /* we have new settings */
        if (cfg != NULL)
        {
            g_key_file_set_string(cfg,
                                  MOD_CFG_GLOBAL_SECTION,
                                  MOD_CFG_GRID,
                                  gtk_entry_get_text(GTK_ENTRY(gridstr)));
        }
        else
        {
            sat_cfg_set_str(SAT_CFG_STR_MODULE_GRID,
                            gtk_entry_get_text(GTK_ENTRY(gridstr)));
            sat_cfg_set_bool(SAT_CFG_BOOL_MAIN_WIN_POS,
                             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
                                                          (mwin)));
            sat_cfg_set_bool(SAT_CFG_BOOL_MOD_WIN_POS,
                             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
                                                          (mod)));
            sat_cfg_set_bool(SAT_CFG_BOOL_MOD_STATE,
                             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
                                                          (state)));
        }
    }
    else if (reset)
    {
        /* we have to reset the values to global or default settings */
        if (cfg == NULL)
        {
            /* layout */
            sat_cfg_reset_str(SAT_CFG_STR_MODULE_GRID);

            /* window placement */
            sat_cfg_reset_bool(SAT_CFG_BOOL_MAIN_WIN_POS);
            sat_cfg_reset_bool(SAT_CFG_BOOL_MOD_WIN_POS);
            sat_cfg_reset_bool(SAT_CFG_BOOL_MOD_STATE);
        }
        else
        {
            g_key_file_remove_key((GKeyFile *) (cfg),
                                  MOD_CFG_GLOBAL_SECTION, MOD_CFG_GRID, NULL);
        }
    }
    dirty = FALSE;
    reset = FALSE;
}
Exemple #2
0
/** \brief Load configuration data.
 *  \return 0 if everything OK, 1 otherwise.
 *
 * This function reads the configuration data from gpredict.cfg into
 * memory. This function must be called very early at program start.
 *
 * The the configuration data in memory is already "loaded" the data will
 * be ereased first.
 */
guint sat_cfg_load        ()
{
    gchar  *keyfile,*confdir;
    GError *error = NULL;

    if (config != NULL)
        sat_cfg_close ();

    /* load the configuration file */
    config = g_key_file_new ();
    confdir = get_user_conf_dir ();
    keyfile = g_strconcat (confdir, G_DIR_SEPARATOR_S, "gpredict.cfg", NULL);
    g_free (confdir);

    g_key_file_load_from_file (config, keyfile, G_KEY_FILE_KEEP_COMMENTS, &error);

    g_free (keyfile);

    if (error != NULL) {

        sat_log_log (SAT_LOG_LEVEL_WARN,
                     _("%s: Error reading config file (%s)"),
                     __FUNCTION__, error->message);

        sat_log_log (SAT_LOG_LEVEL_WARN,
                     _("%s: Using built-in defaults"),
                     __FUNCTION__);

        g_clear_error (&error);

        return 1;
    }
    else {
        sat_log_log (SAT_LOG_LEVEL_DEBUG,
                     _("%s: Everything OK."), __FUNCTION__);
    }

    /* if config version is < 1.1; reset SAT_CFG_STR_TLE_FILES */
    guint ver;
    ver = 10*sat_cfg_get_int (SAT_CFG_INT_VERSION_MAJOR) + sat_cfg_get_int (SAT_CFG_INT_VERSION_MINOR);
    if (ver < 11) {
        sat_cfg_reset_str (SAT_CFG_STR_TLE_FILES);
        sat_cfg_set_int (SAT_CFG_INT_VERSION_MAJOR, 1);
        sat_cfg_set_int (SAT_CFG_INT_VERSION_MINOR, 1);
    }


    return 0;
}
/** \brief User pressed OK. Any changes should be stored in config.
 */
void
sat_pref_help_ok     ()
{
    gint idx;

    if (dirty) {
        /* get and store browser type */
        idx = gtk_combo_box_get_active (GTK_COMBO_BOX (combo));
        sat_cfg_set_int (SAT_CFG_INT_WEB_BROWSER_TYPE, idx);

        /* if type is OTHER, store command, otherwise clear command */
        if (idx == BROWSER_TYPE_OTHER) {
            sat_cfg_set_str (SAT_CFG_STR_WEB_BROWSER,
                             gtk_entry_get_text (GTK_ENTRY (entry)));
        }
        else {
            sat_cfg_reset_str (SAT_CFG_STR_WEB_BROWSER);
        }

    }
    dirty = FALSE;
}