/* Properties dialog */ static void save_macros_to_mateconf (MCData *mc) { MCPrefsDialog *dialog; GtkTreeIter iter; MateConfValue *patterns; MateConfValue *commands; GSList *pattern_list = NULL; GSList *command_list = NULL; MateConfClient *client; dialog = &mc->prefs_dialog; if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (dialog->macros_store), &iter)) return; patterns = mateconf_value_new (MATECONF_VALUE_LIST); mateconf_value_set_list_type (patterns, MATECONF_VALUE_STRING); commands = mateconf_value_new (MATECONF_VALUE_LIST); mateconf_value_set_list_type (commands, MATECONF_VALUE_STRING); do { char *pattern = NULL; char *command = NULL; gtk_tree_model_get ( GTK_TREE_MODEL (dialog->macros_store), &iter, 0, &pattern, 1, &command, -1); pattern_list = g_slist_prepend (pattern_list, mateconf_value_new_from_string (MATECONF_VALUE_STRING, pattern, NULL)); command_list = g_slist_prepend (command_list, mateconf_value_new_from_string (MATECONF_VALUE_STRING, command, NULL)); } while (gtk_tree_model_iter_next (GTK_TREE_MODEL (dialog->macros_store), &iter)); pattern_list = g_slist_reverse (pattern_list); command_list = g_slist_reverse (command_list); mateconf_value_set_list_nocopy (patterns, pattern_list); pattern_list = NULL; mateconf_value_set_list_nocopy (commands, command_list); command_list = NULL; client = mateconf_client_get_default (); mateconf_client_set (client, "/apps/mini-commander/macro_patterns", patterns, NULL); mateconf_client_set (client, "/apps/mini-commander/macro_commands", commands, NULL); mateconf_value_free (patterns); mateconf_value_free (commands); }
static MateConfValue* combo_conv_from_widget_term_flag (MateConfPropertyEditor *peditor, const MateConfValue *value) { MateConfValue *ret; GList *handlers; gint index; MateDATermItem *item; g_object_get (G_OBJECT (peditor), "data", &handlers, NULL); index = mateconf_value_get_int (value); item = g_list_nth_data (handlers, index); ret = mateconf_value_new (MATECONF_VALUE_STRING); if (!item) { /* if item was not found, this is probably the "Custom" item */ /* XXX: returning "" as the value here is not ideal, but required to * prevent the combo box from jumping back to the previous value if the * user has selected Custom */ mateconf_value_set_string (ret, ""); return ret; } else { mateconf_value_set_string (ret, item->exec_flag); return ret; } }
static void cb_dev_selected (GtkComboBox *box, gpointer data) { MateVolumeAppletPreferences *prefs = data; /* MateVolumeApplet *applet = (MateVolumeApplet *) prefs->applet; */ GtkTreeIter iter; if (gtk_combo_box_get_active_iter (box, &iter)) { gchar *label; MateConfValue *value; gtk_tree_model_get (gtk_combo_box_get_model (box), &iter, COL_LABEL, &label, -1); /* write to mateconf */ value = mateconf_value_new (MATECONF_VALUE_STRING); mateconf_value_set_string (value, label); mate_panel_applet_mateconf_set_value (MATE_PANEL_APPLET (prefs->applet), MATE_VOLUME_APPLET_KEY_ACTIVE_ELEMENT, value, NULL); g_free (label); mateconf_value_free (value); } }
MateConfValue* mateconf_value_copy (const MateConfValue* src) { MateConfRealValue *dest; MateConfRealValue *real; g_return_val_if_fail(src != NULL, NULL); real = REAL_VALUE (src); dest = REAL_VALUE (mateconf_value_new (src->type)); switch (real->type) { case MATECONF_VALUE_INT: case MATECONF_VALUE_FLOAT: case MATECONF_VALUE_BOOL: case MATECONF_VALUE_INVALID: dest->d = real->d; break; case MATECONF_VALUE_STRING: set_string(&dest->d.string_data, real->d.string_data); break; case MATECONF_VALUE_SCHEMA: if (real->d.schema_data) dest->d.schema_data = mateconf_schema_copy(real->d.schema_data); else dest->d.schema_data = NULL; break; case MATECONF_VALUE_LIST: { GSList* copy; copy = copy_value_list(real->d.list_data.list); dest->d.list_data.list = copy; dest->d.list_data.type = real->d.list_data.type; } break; case MATECONF_VALUE_PAIR: if (real->d.pair_data.car) dest->d.pair_data.car = mateconf_value_copy(real->d.pair_data.car); else dest->d.pair_data.car = NULL; if (real->d.pair_data.cdr) dest->d.pair_data.cdr = mateconf_value_copy(real->d.pair_data.cdr); else dest->d.pair_data.cdr = NULL; break; default: g_assert_not_reached(); } return (MateConfValue*) dest; }
static MateConfValue* combo_conv_to_widget (MateConfPropertyEditor *peditor, const MateConfValue *value) { MateConfValue *ret; GList *entry, *handlers; const gchar *command; gint index; g_object_get (G_OBJECT (peditor), "data", &handlers, NULL); command = mateconf_value_get_string (value); if (handlers) { entry = g_list_find_custom (handlers, command, (GCompareFunc) generic_item_comp); if (entry) index = g_list_position (handlers, entry); else index = g_list_length (handlers) + 1; } else { /* if the item has no handlers lsit then select the Custom item */ index = 1; } ret = mateconf_value_new (MATECONF_VALUE_INT); mateconf_value_set_int (ret, index); return ret; }
static MateConfValue* combo_conv_to_widget_term_flag (MateConfPropertyEditor *peditor, const MateConfValue *value) { MateConfValue *ret; GtkComboBox *combo; combo = GTK_COMBO_BOX (mateconf_property_editor_get_ui_control (peditor)); ret = mateconf_value_new (MATECONF_VALUE_INT); mateconf_value_set_int (ret, gtk_combo_box_get_active (combo)); return ret; }
static MateConfValue* web_combo_conv_from_widget (MateConfPropertyEditor *peditor, const MateConfValue *value) { MateConfValue *ret; GList *handlers; gint index; MateDAWebItem *item; const gchar *command; MateDACapplet *capplet; g_object_get (G_OBJECT (peditor), "data", &capplet, NULL); index = mateconf_value_get_int (value); handlers = capplet->web_browsers; item = g_list_nth_data (handlers, index); ret = mateconf_value_new (MATECONF_VALUE_STRING); if (!item) { /* if item was not found, this is probably the "Custom" item */ /* XXX: returning "" as the value here is not ideal, but required to * prevent the combo box from jumping back to the previous value if the * user has selected Custom */ mateconf_value_set_string (ret, ""); return ret; } else { if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (capplet->new_win_radiobutton)) && item->netscape_remote == TRUE) command = item->win_command; else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (capplet->new_tab_radiobutton)) && item->netscape_remote == TRUE) command = item->tab_command; else command = item->generic.command; mateconf_value_set_string (ret, command); return ret; } }
static MateConfValue * application_font_to_mateconf (MateConfPropertyEditor *peditor, MateConfValue *value) { MateConfValue *new_value; const char *new_font; GtkWidget *font_button; gint danger_level; font_button = GTK_WIDGET (mateconf_property_editor_get_ui_control (peditor)); g_return_val_if_fail (font_button != NULL, NULL); new_value = mateconf_value_new (MATECONF_VALUE_STRING); new_font = mateconf_value_get_string (value); if (font_dangerous (old_font)) { /* If we're already too large, we don't warn again. */ mateconf_value_set_string (new_value, new_font); return new_value; } danger_level = font_dangerous (new_font); if (danger_level) { GtkWidget *warning_dialog, *apply_button; const gchar *warning_label; gchar *warning_label2; warning_label = _("Font may be too large"); if (danger_level > MAX_FONT_POINT_WITHOUT_WARNING) { warning_label2 = g_strdup_printf (ngettext ( "The font selected is %d point large, " "and may make it difficult to effectively " "use the computer. It is recommended that " "you select a size smaller than %d.", "The font selected is %d points large, " "and may make it difficult to effectively " "use the computer. It is recommended that " "you select a size smaller than %d.", danger_level), danger_level, MAX_FONT_POINT_WITHOUT_WARNING); } else { warning_label2 = g_strdup_printf (ngettext ( "The font selected is %d point large, " "and may make it difficult to effectively " "use the computer. It is recommended that " "you select a smaller sized font.", "The font selected is %d points large, " "and may make it difficult to effectively " "use the computer. It is recommended that " "you select a smaller sized font.", danger_level), danger_level); } warning_dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, GTK_BUTTONS_NONE, "%s", warning_label); gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (warning_dialog), "%s", warning_label2); gtk_dialog_add_button (GTK_DIALOG (warning_dialog), _("Use previous font"), GTK_RESPONSE_CLOSE); apply_button = gtk_button_new_with_label (_("Use selected font")); gtk_button_set_image (GTK_BUTTON (apply_button), gtk_image_new_from_stock (GTK_STOCK_APPLY, GTK_ICON_SIZE_BUTTON)); gtk_dialog_add_action_widget (GTK_DIALOG (warning_dialog), apply_button, GTK_RESPONSE_APPLY); gtk_widget_set_can_default (apply_button, TRUE); gtk_widget_show (apply_button); gtk_dialog_set_default_response (GTK_DIALOG (warning_dialog), GTK_RESPONSE_CLOSE); g_free (warning_label2); if (gtk_dialog_run (GTK_DIALOG (warning_dialog)) == GTK_RESPONSE_APPLY) { mateconf_value_set_string (new_value, new_font); } else { mateconf_value_set_string (new_value, old_font); gtk_font_button_set_font_name (GTK_FONT_BUTTON (font_button), old_font); } gtk_widget_destroy (warning_dialog); } else { mateconf_value_set_string (new_value, new_font); } return new_value; }
/* 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); }
static gboolean cb_track_select (GtkTreeSelection *selection, GtkTreeModel *model, GtkTreePath *path, gboolean path_selected, gpointer data) { MateVolumeAppletPreferences *prefs = data; GtkTreeIter iter; gchar *label; MateConfValue *value; GtkTreeSelection *sel; GString *mateconf_string; GstMixerTrack *selected_track; /* the track just selected */ MateVolumeApplet *applet = (MateVolumeApplet*) prefs->applet; /* required to update the track settings */ int volume_percent; if (prefs->track_lock) return TRUE; mateconf_string = g_string_new (""); /* get value */ gtk_tree_model_get_iter (model, &iter, path); gtk_tree_model_get (model, &iter, COL_LABEL, &label, COL_TRACK, &selected_track, -1); sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (prefs->treeview)); /* clear the list of selected tracks */ if (applet->tracks) { g_list_free (applet->tracks); applet->tracks = NULL; } if (gtk_tree_selection_count_selected_rows (sel) > 0) { GList *lst; /* add the ones already selected */ for (lst = gtk_tree_selection_get_selected_rows (sel, &model); lst != NULL; lst = lst->next) { GstMixerTrack *curr = NULL; gchar *it_label; gtk_tree_model_get_iter (model, &iter, lst->data); gtk_tree_model_get (model, &iter, COL_LABEL, &it_label, COL_TRACK, &curr, -1); /* grab the main volume (they will all be the same, so it doesn't matter * which one we get) */ volume_percent = mate_volume_applet_get_volume (prefs->mixer, curr); if (strcmp (it_label, label)) { applet->tracks = g_list_append (applet->tracks, curr); if (!path_selected) { g_string_append_printf (mateconf_string, "%s:", curr->label); } else { mateconf_string = g_string_append (mateconf_string, curr->label); } } } g_list_foreach (lst, (GFunc)gtk_tree_path_free, NULL); g_list_free (lst); } /* add the one just selected and adjust its volume if it's not the only one * selected */ if (!path_selected) { GstMixerTrack *curr; gtk_tree_model_get_iter (model, &iter, path); gtk_tree_model_get (model, &iter, COL_TRACK, &curr, -1); mateconf_string = g_string_append (mateconf_string, curr->label); applet->tracks = g_list_append (applet->tracks, curr); /* unify the volume of this track with the others already added */ if (g_list_length (applet->tracks) > 1) { mate_volume_applet_adjust_volume (prefs->mixer, curr, volume_percent); } } /* write to mateconf */ value = mateconf_value_new (MATECONF_VALUE_STRING); mateconf_value_set_string (value, mateconf_string->str); mate_panel_applet_mateconf_set_value (MATE_PANEL_APPLET (prefs->applet), MATE_VOLUME_APPLET_KEY_ACTIVE_TRACK, value, NULL); g_free (label); g_string_free (mateconf_string, TRUE); mateconf_value_free (value); return TRUE; }
MateConfValue* mateconf_value_new_from_string(MateConfValueType type, const gchar* value_str, GError** err) { MateConfValue* value; g_return_val_if_fail (type != MATECONF_VALUE_LIST, NULL); g_return_val_if_fail (type != MATECONF_VALUE_PAIR, NULL); value = mateconf_value_new(type); switch (type) { case MATECONF_VALUE_INT: { char* endptr = NULL; glong result; errno = 0; result = strtol(value_str, &endptr, 10); if (endptr == value_str) { if (err) *err = mateconf_error_new(MATECONF_ERROR_PARSE_ERROR, _("Didn't understand `%s' (expected integer)"), value_str); mateconf_value_free(value); value = NULL; } else if (errno == ERANGE) { if (err) *err = mateconf_error_new(MATECONF_ERROR_PARSE_ERROR, _("Integer `%s' is too large or small"), value_str); mateconf_value_free(value); value = NULL; } else mateconf_value_set_int(value, result); } break; case MATECONF_VALUE_FLOAT: { double num; if (mateconf_string_to_double(value_str, &num)) { mateconf_value_set_float(value, num); } else { if (err) *err = mateconf_error_new(MATECONF_ERROR_PARSE_ERROR, _("Didn't understand `%s' (expected real number)"), value_str); mateconf_value_free(value); value = NULL; } } break; case MATECONF_VALUE_STRING: if (!g_utf8_validate (value_str, -1, NULL)) { g_set_error (err, MATECONF_ERROR, MATECONF_ERROR_PARSE_ERROR, _("Text contains invalid UTF-8")); mateconf_value_free(value); value = NULL; } else { mateconf_value_set_string(value, value_str); } break; case MATECONF_VALUE_BOOL: switch (*value_str) { case 't': case 'T': case '1': case 'y': case 'Y': mateconf_value_set_bool(value, TRUE); break; case 'f': case 'F': case '0': case 'n': case 'N': mateconf_value_set_bool(value, FALSE); break; default: if (err) *err = mateconf_error_new(MATECONF_ERROR_PARSE_ERROR, _("Didn't understand `%s' (expected true or false)"), value_str); mateconf_value_free(value); value = NULL; break; } break; case MATECONF_VALUE_LIST: case MATECONF_VALUE_PAIR: default: g_assert_not_reached(); break; } return value; }
MateConfValue* mateconf_value_new_pair_from_string(MateConfValueType car_type, MateConfValueType cdr_type, const gchar* str, GError** err) { int i, len; int elem; gboolean escaped, pending_chars; GString *string; MateConfValue* value; MateConfValue* car; MateConfValue* cdr; g_return_val_if_fail(car_type != MATECONF_VALUE_LIST, NULL); g_return_val_if_fail(car_type != MATECONF_VALUE_PAIR, NULL); g_return_val_if_fail(cdr_type != MATECONF_VALUE_LIST, NULL); g_return_val_if_fail(cdr_type != MATECONF_VALUE_PAIR, NULL); if (!g_utf8_validate (str, -1, NULL)) { g_set_error (err, MATECONF_ERROR, MATECONF_ERROR_PARSE_ERROR, _("Text contains invalid UTF-8")); return NULL; } if (str[0] != '(') { if (err) *err = mateconf_error_new(MATECONF_ERROR_PARSE_ERROR, _("Didn't understand `%s' (pair must start with a '(')"), str); return NULL; } len = strlen(str); /* Note: by now len is sure to be 1 or larger, so len-1 will never be * negative */ if (str[len-1] != ')') { if (err) *err = mateconf_error_new(MATECONF_ERROR_PARSE_ERROR, _("Didn't understand `%s' (pair must end with a ')')"), str); return NULL; } escaped = FALSE; pending_chars = FALSE; car = cdr = NULL; string = g_string_new(NULL); elem = 0; for (i = 1; str[i] != '\0'; i++) { if ( ! escaped && (str[i] == ',' || str[i] == ')')) { if ((str[i] == ')' && elem != 1) || (elem > 1)) { /* Free values so far */ if (car) mateconf_value_free(car); if (cdr) mateconf_value_free(cdr); g_string_free(string, TRUE); if (err) *err = mateconf_error_new(MATECONF_ERROR_PARSE_ERROR, _("Didn't understand `%s' (wrong number of elements)"), str); return NULL; } if (elem == 0) car = mateconf_value_new_from_string(car_type, string->str, err); else if (elem == 1) cdr = mateconf_value_new_from_string(cdr_type, string->str, err); elem ++; if (err && *err != NULL) { /* Free values so far */ if (car) mateconf_value_free(car); if (cdr) mateconf_value_free(cdr); g_string_free(string, TRUE); return NULL; } g_string_assign(string, ""); if (str[i] == ')' && i != len-1) { /* Free values so far */ if (car) mateconf_value_free(car); if (cdr) mateconf_value_free(cdr); g_string_free(string, TRUE); if (err) *err = mateconf_error_new(MATECONF_ERROR_PARSE_ERROR, _("Didn't understand `%s' (extra unescaped ')' found inside pair)"), str); return NULL; } pending_chars = FALSE; } else if ( ! escaped && str[i] == '\\') { escaped = TRUE; pending_chars = TRUE; } else { g_string_append_c(string, str[i]); escaped = FALSE; pending_chars = TRUE; } } g_string_free(string, TRUE); if (pending_chars) { /* Free values so far */ if (car) mateconf_value_free(car); if (cdr) mateconf_value_free(cdr); if (err) *err = mateconf_error_new(MATECONF_ERROR_PARSE_ERROR, _("Didn't understand `%s' (extra trailing characters)"), str); return NULL; } if (elem != 2) { /* Free values so far */ if (car) mateconf_value_free(car); if (cdr) mateconf_value_free(cdr); if (err) *err = mateconf_error_new(MATECONF_ERROR_PARSE_ERROR, _("Didn't understand `%s' (wrong number of elements)"), str); return NULL; } value = mateconf_value_new(MATECONF_VALUE_PAIR); mateconf_value_set_car_nocopy(value, car); mateconf_value_set_cdr_nocopy(value, cdr); return value; }
MateConfValue* mateconf_value_new_list_from_string(MateConfValueType list_type, const gchar* str, GError** err) { int i, len; gboolean escaped, pending_chars; GString *string; MateConfValue* value; GSList *list; g_return_val_if_fail(list_type != MATECONF_VALUE_LIST, NULL); g_return_val_if_fail(list_type != MATECONF_VALUE_PAIR, NULL); if (!g_utf8_validate (str, -1, NULL)) { g_set_error (err, MATECONF_ERROR, MATECONF_ERROR_PARSE_ERROR, _("Text contains invalid UTF-8")); return NULL; } if (str[0] != '[') { if (err) *err = mateconf_error_new(MATECONF_ERROR_PARSE_ERROR, _("Didn't understand `%s' (list must start with a '[')"), str); return NULL; } len = strlen(str); /* Note: by now len is sure to be 1 or larger, so len-1 will never be * negative */ if (str[len-1] != ']') { if (err) *err = mateconf_error_new(MATECONF_ERROR_PARSE_ERROR, _("Didn't understand `%s' (list must end with a ']')"), str); return NULL; } if (strstr(str, "[]")) { value = mateconf_value_new(MATECONF_VALUE_LIST); mateconf_value_set_list_type(value, list_type); return value; } escaped = FALSE; pending_chars = FALSE; list = NULL; string = g_string_new(NULL); for (i = 1; str[i] != '\0'; i++) { if ( ! escaped && (str[i] == ',' || str[i] == ']')) { MateConfValue* val; val = mateconf_value_new_from_string(list_type, string->str, err); if (err && *err != NULL) { /* Free values so far */ g_slist_foreach(list, (GFunc)mateconf_value_free, NULL); g_slist_free(list); g_string_free(string, TRUE); return NULL; } g_string_assign(string, ""); list = g_slist_prepend(list, val); if (str[i] == ']' && i != len-1) { /* Free values so far */ g_slist_foreach(list, (GFunc)mateconf_value_free, NULL); g_slist_free(list); g_string_free(string, TRUE); if (err) *err = mateconf_error_new(MATECONF_ERROR_PARSE_ERROR, _("Didn't understand `%s' (extra unescaped ']' found inside list)"), str); return NULL; } pending_chars = FALSE; } else if ( ! escaped && str[i] == '\\') { escaped = TRUE; pending_chars = TRUE; } else { g_string_append_c(string, str[i]); escaped = FALSE; pending_chars = TRUE; } } g_string_free(string, TRUE); if (pending_chars) { /* Free values so far */ g_slist_foreach(list, (GFunc)mateconf_value_free, NULL); g_slist_free(list); g_string_free(string, TRUE); if (err) *err = mateconf_error_new(MATECONF_ERROR_PARSE_ERROR, _("Didn't understand `%s' (extra trailing characters)"), str); return NULL; } /* inverse list as we were prepending to it */ list = g_slist_reverse(list); value = mateconf_value_new(MATECONF_VALUE_LIST); mateconf_value_set_list_type(value, list_type); mateconf_value_set_list_nocopy(value, list); return value; }