示例#1
0
/**
  * Write history to the ${XDG_CACHE_HOME}/mc/history file
  */
void
dlg_save_history (WDialog * h)
{
    char *profile;
    int i;

    if (num_history_items_recorded == 0)        /* this is how to disable */
        return;

    profile = mc_config_get_full_path (MC_HISTORY_FILE);
    i = open (profile, O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
    if (i != -1)
        close (i);

    /* Make sure the history is only readable by the user */
    if (chmod (profile, S_IRUSR | S_IWUSR) != -1 || errno == ENOENT)
    {
        ev_history_load_save_t event_data;

        event_data.cfg = mc_config_init (profile, FALSE);
        event_data.receiver = NULL;

        /* get all histories in dialog */
        mc_event_raise (h->event_group, MCEVENT_HISTORY_SAVE, &event_data);

        mc_config_save_file (event_data.cfg, NULL);
        mc_config_deinit (event_data.cfg);
    }

    g_free (profile);
}
示例#2
0
static void
learn_save (void)
{
    int i;
    char *section;
    gboolean profile_changed = FALSE;

    section = g_strconcat ("terminal:", getenv ("TERM"), (char *) NULL);

    for (i = 0; i < learn_total; i++)
        if (learnkeys[i].sequence != NULL)
        {
            char *esc_str;

            esc_str = strutils_escape (learnkeys[i].sequence, -1, ";\\", TRUE);
            mc_config_set_string_raw_value (mc_global.main_config, section,
                                            key_name_conv_tab[i].name, esc_str);
            g_free (esc_str);

            profile_changed = TRUE;
        }

    /* On the one hand no good idea to save the complete setup but 
     * without 'Auto save setup' the new key-definitions will not be 
     * saved unless the user does an 'Options/Save Setup'. 
     * On the other hand a save-button that does not save anything to 
     * disk is much worse.
     */
    if (profile_changed)
        mc_config_save_file (mc_global.main_config, NULL);

    g_free (section);
}
示例#3
0
/* save panels.ini */
static void
save_panel_types (void)
{
    panel_view_mode_t type;

    if (mc_run_mode != MC_RUN_FULL)
        return;

    type = get_display_type (0);
    panel_save_type ("New Left Panel", type);
    if (type == view_listing)
        panel_save_setup (left_panel, left_panel->panel_name);
    type = get_display_type (1);
    panel_save_type ("New Right Panel", type);
    if (type == view_listing)
        panel_save_setup (right_panel, right_panel->panel_name);

    mc_config_set_string (mc_panels_config, "Dirs", "other_dir", get_panel_dir_for (other_panel));

    if (current_panel != NULL)
        mc_config_set_string (mc_panels_config, "Dirs", "current_is_left",
                              get_current_index () == 0 ? "1" : "0");

    if (mc_panels_config->ini_path == NULL)
        mc_panels_config->ini_path = g_strdup (panels_profile_name);

    mc_config_del_group (mc_panels_config, "Temporal:New Left Panel");
    mc_config_del_group (mc_panels_config, "Temporal:New Right Panel");

    mc_config_save_file (mc_panels_config, NULL);
}
示例#4
0
文件: setup.c 项目: CyberShadow/mc
static void
setup__move_panels_config_into_separate_file (const char *profile)
{
    mc_config_t *tmp_cfg;
    char **groups, **curr_grp;

    if (!exist_file (profile))
        return;

    tmp_cfg = mc_config_init (profile, FALSE);
    if (!tmp_cfg)
        return;

    curr_grp = groups = mc_config_get_groups (tmp_cfg, NULL);
    if (!groups)
    {
        mc_config_deinit (tmp_cfg);
        return;
    }

    while (*curr_grp)
    {
        if (setup__is_cfg_group_must_panel_config (*curr_grp) == NULL)
            mc_config_del_group (tmp_cfg, *curr_grp);
        curr_grp++;
    }

    mc_config_save_to_file (tmp_cfg, panels_profile_name, NULL);
    mc_config_deinit (tmp_cfg);

    tmp_cfg = mc_config_init (profile, FALSE);
    if (!tmp_cfg)
    {
        g_strfreev (groups);
        return;
    }

    curr_grp = groups;

    while (*curr_grp)
    {
        const char *need_grp;

        need_grp = setup__is_cfg_group_must_panel_config (*curr_grp);
        if (need_grp != NULL)
        {
            mc_config_del_group (tmp_cfg, need_grp);
        }
        curr_grp++;
    }
    g_strfreev (groups);

    mc_config_save_file (tmp_cfg, NULL);
    mc_config_deinit (tmp_cfg);
}
示例#5
0
static void
config_object__reopen (void)
{
    GError *error = NULL;

    if (!mc_config_save_file (mc_config, &error))
    {
        fail ("Unable to save config file: %s", error->message);
        g_error_free (error);
    }

    mc_config_deinit (mc_config);
    mc_config = mc_config_init (ini_filename, FALSE);
}
示例#6
0
END_TEST

/* --------------------------------------------------------------------------------------------- */

START_TEST (emulate__learn_save)
{
    mc_config_t *mc_config;
    char *actual_value, *esc_str;
    char *ini_filename = NULL;
    GError *error = NULL;

    ini_filename = g_build_filename(WORKDIR, "test-emulate__learn_save.ini",NULL);
    unlink(ini_filename);

    mc_config = mc_config_init (ini_filename, FALSE);
    if (mc_config == NULL)
    {
        fail("unable to create mc_congif_t object!");
        return;
    }

    esc_str = strutils_escape ("T;E\\X;T-FOR-\\T;E;S\\TI;N'G", -1, ";", TRUE);
    mc_config_set_string_raw (mc_config, "test-group1", "test-param1", esc_str);
    g_free (esc_str);

    if (!mc_config_save_file (mc_config, &error))
    {
        fail("Unable to save config file: %s",error->message);
        g_error_free(error);
    }

    mc_config_deinit (mc_config);
    mc_config = mc_config_init (ini_filename, FALSE);

    actual_value = mc_config_get_string_raw( mc_config, "test-group1", "test-param1", "not-exists");
    fail_unless_strcmp("T\\;E\\X\\;T-FOR-\\T\\;E\\;S\\TI\\;N'G");
    g_free(actual_value);

    mc_config_deinit (mc_config);
    g_free(ini_filename);
}