Beispiel #1
0
/* load_history indicates whether the history list is being loaded at startup.
** If true then don't save the new entries with gconf (since they are being read
** using gconf
*/
void
append_history_entry(MCData *mcdata, const char * entry, gboolean load_history)
{
    GArray *history;
    int pos, i;

    /* remove older dupes */
    for(pos = 0; pos <= MC_HISTORY_LIST_LENGTH - 1; pos++)
	{
	    if(exists_history_entry(pos) && strcmp(entry, history_command[pos]) == 0)
		/* dupe found */
		delete_history_entry(pos);
	}

    /* delete oldest entry */
    if(history_command[0] != NULL)
	free(history_command[0]);

    /* move entries */
    for(pos = 0; pos < MC_HISTORY_LIST_LENGTH - 1; pos++)
	{
	    history_command[pos] = history_command[pos+1];
	    /* printf("%s\n", history_command[pos]); */
	}

    /* append entry */
    history_command[MC_HISTORY_LIST_LENGTH - 1] = (char *)malloc(sizeof(char) * (strlen(entry) + 1));
    strcpy(history_command[MC_HISTORY_LIST_LENGTH - 1], entry);
    
    if (load_history)
    	return;

    /* If not writable, just keeps the history around for this session */
    if (!g_settings_is_writable (mcdata->settings, KEY_HISTORY))
        return;
    	
    /* Save history - this seems like a waste to do it every time it's updated 
    ** but it doesn't seem to work when called on the destroy signal of the applet 
    */
    history = g_array_new (TRUE, TRUE, sizeof (gchar *));

    for (i = 0; i < MC_HISTORY_LIST_LENGTH; i++) {
	    if (exists_history_entry(i)) {
	        gchar *entry = g_strdup (get_history_entry (i));
	        history = g_array_append_val (history, entry);
        }
	}

    g_settings_set_strv (mcdata->settings, KEY_HISTORY, (const gchar **) history->data);

    g_array_free (history, TRUE);
}
Beispiel #2
0
/* load_history indicates whether the history list is being loaded at startup.
** If true then don't save the new entries with mateconf (since they are being read
** using mateconf
*/
void
append_history_entry(MCData *mcdata, const char * entry, gboolean load_history)
{
    MatePanelApplet *applet = mcdata->applet;
    MateConfValue *history;
    GSList *list = NULL;
    int pos, i;

    /* remove older dupes */
    for(pos = 0; pos <= MC_HISTORY_LIST_LENGTH - 1; pos++)
	{
	    if(exists_history_entry(pos) && strcmp(entry, history_command[pos]) == 0)
		/* dupe found */
		delete_history_entry(pos);
	}

    /* delete oldest entry */
    if(history_command[0] != NULL)
	free(history_command[0]);

    /* move entries */
    for(pos = 0; pos < MC_HISTORY_LIST_LENGTH - 1; pos++)
	{
	    history_command[pos] = history_command[pos+1];
	    /* printf("%s\n", history_command[pos]); */
	}

    /* append entry */
    history_command[MC_HISTORY_LIST_LENGTH - 1] = (char *)malloc(sizeof(char) * (strlen(entry) + 1));
    strcpy(history_command[MC_HISTORY_LIST_LENGTH - 1], entry);
    
    if (load_history)
    	return;

    /* If not writable, just keeps the history around for this session */
    if ( ! mc_key_writable (mcdata, "history"))
        return;
    	
    /* Save history - this seems like a waste to do it every time it's updated 
    ** but it doesn't seem to work when called on the destroy signal of the applet 
    */
    for(i = 0; i < MC_HISTORY_LIST_LENGTH; i++)
	{
	    MateConfValue *value_entry;
	    
	    value_entry = mateconf_value_new (MATECONF_VALUE_STRING);
	    if(exists_history_entry(i)) {
	    	mateconf_value_set_string (value_entry, (gchar *) get_history_entry(i));
	    	list = g_slist_append (list, value_entry);
	    }        
	    
	}

    history = mateconf_value_new (MATECONF_VALUE_LIST);
    if (list) {
    	mateconf_value_set_list_type (history, MATECONF_VALUE_STRING);
        mateconf_value_set_list (history, list);
        mate_panel_applet_mateconf_set_value (applet, "history", history, NULL);
    }
   
    while (list) {
    	MateConfValue *value = list->data;
    	mateconf_value_free (value);
    	list = g_slist_next (list);
    }
   
    mateconf_value_free (history);
    
}