static gint get_mateconf_value_with_default_int (PlumaDrawspacesPlugin *plugin, const gchar *key, gint def) { MateConfValue *value; gint ret; value = mateconf_client_get (plugin->priv->mateconf_client, key, NULL); if (value != NULL && value->type == MATECONF_VALUE_INT) { ret = mateconf_value_get_int (value); } else { ret = def; } if (value != NULL) { mateconf_value_free (value); } return ret; }
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 cmd_line_color_bg_b_changed (MateConfClient *client, guint cnxn_id, MateConfEntry *entry, MCData *mc) { if (!entry->value || entry->value->type != MATECONF_VALUE_INT) return; mc->preferences.cmd_line_color_bg_b = mateconf_value_get_int (entry->value); mc_command_update_entry_color (mc); }
static void normal_size_y_changed (MateConfClient *client, guint cnxn_id, MateConfEntry *entry, MCData *mc) { if (!entry->value || entry->value->type != MATECONF_VALUE_INT) return; mc->preferences.normal_size_y = mateconf_value_get_int (entry->value); mc_applet_draw (mc); /* FIXME: we shouldn't have to redraw the whole applet */ }
static void normal_size_x_changed (MateConfClient *client, guint cnxn_id, MateConfEntry *entry, MCData *mc) { if (!entry->value || entry->value->type != MATECONF_VALUE_INT) return; mc->preferences.normal_size_x = mateconf_value_get_int (entry->value); mc_command_update_entry_size (mc); }
static void mateconf_notify_cb (MateConfClient *client, guint cnxn_id, MateConfEntry *entry, gpointer user_data) { DrWright *dr = user_data; GtkWidget *item; if (!strcmp (entry->key, MATECONF_PATH "/type_time")) { if (entry->value->type == MATECONF_VALUE_INT) { dr->type_time = 60 * mateconf_value_get_int (entry->value); dr->warn_time = MIN (dr->type_time / 10, 5*60); dr->state = STATE_START; } } else if (!strcmp (entry->key, MATECONF_PATH "/break_time")) { if (entry->value->type == MATECONF_VALUE_INT) { dr->break_time = 60 * mateconf_value_get_int (entry->value); dr->state = STATE_START; } } else if (!strcmp (entry->key, MATECONF_PATH "/enabled")) { if (entry->value->type == MATECONF_VALUE_BOOL) { dr->enabled = mateconf_value_get_bool (entry->value); dr->state = STATE_START; item = gtk_ui_manager_get_widget (dr->ui_manager, "/Pop/TakeABreak"); gtk_widget_set_sensitive (item, dr->enabled); update_status (dr); } } maybe_change_state (dr); }
static void timeout_changed_cb (MateConfClient * client, guint id, MateConfEntry * entry, gpointer user_data) { HardDriveStatusTile *tile = HARD_DRIVE_STATUS_TILE (user_data); HardDriveStatusTilePrivate *priv = HARD_DRIVE_STATUS_TILE_GET_PRIVATE (tile); int timeout; if (priv->update_timeout) g_source_remove (priv->update_timeout); timeout = mateconf_value_get_int (mateconf_entry_get_value (entry)); timeout = MAX (timeout, 1000); priv->update_timeout = g_timeout_add (timeout, timeout_cb, tile); }
static void num_rows_changed(MateConfClient* client, guint cnxn_id, MateConfEntry* entry, PagerData* pager) { int n_rows = DEFAULT_ROWS; if (entry->value != NULL && entry->value->type == MATECONF_VALUE_INT) { n_rows = mateconf_value_get_int(entry->value); } n_rows = CLAMP(n_rows, 1, MAX_REASONABLE_ROWS); pager->n_rows = n_rows; pager_update(pager); if (pager->num_rows_spin && gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(pager->num_rows_spin)) != n_rows) gtk_spin_button_set_value(GTK_SPIN_BUTTON(pager->num_rows_spin), pager->n_rows); }
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; } }
gchar* mateconf_value_to_string(const MateConfValue* value) { /* These strings shouldn't be translated; they're primarily intended for machines to read, not humans, though I do use them in some debug spew */ gchar* retval = NULL; switch (value->type) { case MATECONF_VALUE_INT: retval = g_strdup_printf("%d", mateconf_value_get_int(value)); break; case MATECONF_VALUE_FLOAT: retval = mateconf_double_to_string(mateconf_value_get_float(value)); break; case MATECONF_VALUE_STRING: retval = g_strdup(mateconf_value_get_string(value)); break; case MATECONF_VALUE_BOOL: retval = mateconf_value_get_bool(value) ? g_strdup("true") : g_strdup("false"); break; case MATECONF_VALUE_LIST: { GSList* list; list = mateconf_value_get_list(value); if (list == NULL) retval = g_strdup("[]"); else { gchar* buf = NULL; guint bufsize = 64; guint cur = 0; g_assert(list != NULL); buf = g_malloc(bufsize+3); /* my +3 superstition */ buf[0] = '['; ++cur; g_assert(cur < bufsize); while (list != NULL) { gchar* tmp; gchar* elem; guint len; tmp = mateconf_value_to_string((MateConfValue*)list->data); g_assert(tmp != NULL); elem = escape_string(tmp, ",]"); g_free(tmp); len = strlen(elem); if ((cur + len + 2) >= bufsize) /* +2 for '\0' and comma */ { bufsize = MAX(bufsize*2, bufsize+len+4); buf = g_realloc(buf, bufsize+3); } g_assert(cur < bufsize); strcpy(&buf[cur], elem); cur += len; g_assert(cur < bufsize); g_free(elem); buf[cur] = ','; ++cur; g_assert(cur < bufsize); list = g_slist_next(list); } g_assert(cur < bufsize); buf[cur-1] = ']'; /* overwrites last comma */ buf[cur] = '\0'; retval = buf; } } break; case MATECONF_VALUE_PAIR: { gchar* tmp; gchar* car; gchar* cdr; if (mateconf_value_get_car (value)) tmp = mateconf_value_to_string(mateconf_value_get_car(value)); else tmp = g_strdup ("nil"); car = escape_string(tmp, ",)"); g_free(tmp); if (mateconf_value_get_cdr (value)) tmp = mateconf_value_to_string(mateconf_value_get_cdr(value)); else tmp = g_strdup ("nil"); cdr = escape_string(tmp, ",)"); g_free(tmp); retval = g_strdup_printf("(%s,%s)", car, cdr); g_free(car); g_free(cdr); } break; /* These remaining shouldn't really be used outside of debug spew... */ case MATECONF_VALUE_INVALID: retval = g_strdup("Invalid"); break; case MATECONF_VALUE_SCHEMA: { const gchar* locale; const gchar* type; const gchar* list_type; const gchar* car_type; const gchar* cdr_type; locale = mateconf_schema_get_locale(mateconf_value_get_schema(value)); type = mateconf_value_type_to_string(mateconf_schema_get_type(mateconf_value_get_schema(value))); list_type = mateconf_value_type_to_string(mateconf_schema_get_list_type(mateconf_value_get_schema(value))); car_type = mateconf_value_type_to_string(mateconf_schema_get_car_type(mateconf_value_get_schema(value))); cdr_type = mateconf_value_type_to_string(mateconf_schema_get_cdr_type(mateconf_value_get_schema(value))); retval = g_strdup_printf("Schema (type: `%s' list_type: '%s' " "car_type: '%s' cdr_type: '%s' locale: `%s')", type, list_type, car_type, cdr_type, locale ? locale : "(null)"); } break; default: g_assert_not_reached(); break; } return retval; }
int mateconf_value_compare (const MateConfValue *value_a, const MateConfValue *value_b) { g_return_val_if_fail (value_a != NULL, 0); g_return_val_if_fail (value_b != NULL, 0); /* Impose arbitrary type ordering, just to keep the * sort invariants stable. */ if (value_a->type < value_b->type) return -1; else if (value_a->type > value_b->type) return 1; switch (value_a->type) { case MATECONF_VALUE_INT: if (mateconf_value_get_int (value_a) < mateconf_value_get_int (value_b)) return -1; else if (mateconf_value_get_int (value_a) > mateconf_value_get_int (value_b)) return 1; else return 0; case MATECONF_VALUE_FLOAT: if (mateconf_value_get_float (value_a) < mateconf_value_get_float (value_b)) return -1; else if (mateconf_value_get_float (value_a) > mateconf_value_get_float (value_b)) return 1; else return 0; case MATECONF_VALUE_STRING: return strcmp (mateconf_value_get_string (value_a), mateconf_value_get_string (value_b)); case MATECONF_VALUE_BOOL: if (mateconf_value_get_bool (value_a) == mateconf_value_get_bool (value_b)) return 0; /* make TRUE > FALSE to maintain sort invariants */ else if (mateconf_value_get_bool (value_a)) return 1; else return -1; case MATECONF_VALUE_LIST: { GSList *list_a; GSList *list_b; list_a = mateconf_value_get_list (value_a); list_b = mateconf_value_get_list (value_b); while (list_a != NULL && list_b != NULL) { int result; result = mateconf_value_compare (list_a->data, list_b->data); if (result != 0) return result; list_a = g_slist_next (list_a); list_b = g_slist_next (list_b); } if (list_a) return 1; /* list_a is longer so "greater" */ else if (list_b) return -1; else return 0; } case MATECONF_VALUE_PAIR: { MateConfValue *a_car, *b_car, *a_cdr, *b_cdr; int result; a_car = mateconf_value_get_car (value_a); b_car = mateconf_value_get_car (value_b); a_cdr = mateconf_value_get_cdr (value_a); b_cdr = mateconf_value_get_cdr (value_b); if (a_car == NULL && b_car != NULL) return -1; else if (a_car != NULL && b_car == NULL) return 1; else if (a_car != NULL && b_car != NULL) { result = mateconf_value_compare (a_car, b_car); if (result != 0) return result; } if (a_cdr == NULL && b_cdr != NULL) return -1; else if (a_cdr != NULL && b_cdr == NULL) return 1; else if (a_cdr != NULL && b_cdr != NULL) { result = mateconf_value_compare (a_cdr, b_cdr); if (result != 0) return result; } return 0; } case MATECONF_VALUE_INVALID: return 0; case MATECONF_VALUE_SCHEMA: { const char *locale_a, *locale_b; MateConfValueType type_a, type_b; MateConfValueType list_type_a, list_type_b; MateConfValueType car_type_a, car_type_b; MateConfValueType cdr_type_a, cdr_type_b; const char *short_desc_a, *short_desc_b; const char *long_desc_a, *long_desc_b; int result; type_a = mateconf_schema_get_type (mateconf_value_get_schema (value_a)); type_b = mateconf_schema_get_type (mateconf_value_get_schema (value_b)); if (type_a < type_b) return -1; else if (type_a > type_b) return 1; short_desc_a = mateconf_schema_get_short_desc (mateconf_value_get_schema (value_a)); short_desc_b = mateconf_schema_get_short_desc (mateconf_value_get_schema (value_b)); result = null_safe_strcmp (short_desc_a, short_desc_b); if (result != 0) return result; long_desc_a = mateconf_schema_get_long_desc (mateconf_value_get_schema (value_a)); long_desc_b = mateconf_schema_get_long_desc (mateconf_value_get_schema (value_b)); result = null_safe_strcmp (long_desc_a, long_desc_b); if (result != 0) return result; locale_a = mateconf_schema_get_locale (mateconf_value_get_schema (value_a)); locale_b = mateconf_schema_get_locale (mateconf_value_get_schema (value_b)); result = null_safe_strcmp (locale_a, locale_b); if (result != 0) return result; if (type_a == MATECONF_VALUE_LIST) { list_type_a = mateconf_schema_get_list_type (mateconf_value_get_schema (value_a)); list_type_b = mateconf_schema_get_list_type (mateconf_value_get_schema (value_b)); if (list_type_a < list_type_b) return -1; else if (list_type_a > list_type_b) return 1; } if (type_a == MATECONF_VALUE_PAIR) { car_type_a = mateconf_schema_get_car_type (mateconf_value_get_schema (value_a)); car_type_b = mateconf_schema_get_car_type (mateconf_value_get_schema (value_b)); if (car_type_a < car_type_b) return -1; else if (car_type_a > car_type_b) return 1; cdr_type_a = mateconf_schema_get_cdr_type (mateconf_value_get_schema (value_a)); cdr_type_b = mateconf_schema_get_cdr_type (mateconf_value_get_schema (value_b)); if (cdr_type_a < cdr_type_b) return -1; else if (cdr_type_a > cdr_type_b) return 1; } return 0; } } g_assert_not_reached (); return 0; }
static gboolean handle_file (const gchar *filename) { GKeyFile *keyfile; MateConfClient *client; MateConfValue *value; gint i, j; gchar *mateconf_key; gchar **groups; gchar **keys; GVariantBuilder *builder; GVariant *v; const gchar *s; gchar *str; gint ii; GSList *list, *l; GSettings *settings; GError *error; keyfile = g_key_file_new (); error = NULL; if (!g_key_file_load_from_file (keyfile, filename, 0, &error)) { g_printerr ("%s\n", error->message); g_error_free (error); g_key_file_free (keyfile); return FALSE; } client = mateconf_client_get_default (); groups = g_key_file_get_groups (keyfile, NULL); for (i = 0; groups[i]; i++) { gchar **schema_path; schema_path = g_strsplit (groups[i], ":", 2); if (verbose) { g_print ("collecting settings for schema '%s'\n", schema_path[0]); if (schema_path[1]) g_print ("for storage at '%s'\n", schema_path[1]); } if (schema_path[1] != NULL) settings = g_settings_new_with_path (schema_path[0], schema_path[1]); else settings = g_settings_new (schema_path[0]); g_settings_delay (settings); error = NULL; if ((keys = g_key_file_get_keys (keyfile, groups[i], NULL, &error)) == NULL) { g_printerr ("%s", error->message); g_error_free (error); continue; } for (j = 0; keys[j]; j++) { if (strchr (keys[j], '/') != 0) { g_printerr ("Key '%s' contains a '/'\n", keys[j]); continue; } error = NULL; if ((mateconf_key = g_key_file_get_string (keyfile, groups[i], keys[j], &error)) == NULL) { g_printerr ("%s", error->message); g_error_free (error); continue; } error = NULL; if ((value = mateconf_client_get_without_default (client, mateconf_key, &error)) == NULL) { if (error) { g_printerr ("Failed to get MateConf key '%s': %s\n", mateconf_key, error->message); g_error_free (error); } else { if (verbose) g_print ("Skipping MateConf key '%s', no user value\n", mateconf_key); } g_free (mateconf_key); continue; } switch (value->type) { case MATECONF_VALUE_STRING: if (dry_run) g_print ("set key '%s' to string '%s'\n", keys[j], mateconf_value_get_string (value)); else g_settings_set (settings, keys[j], "s", mateconf_value_get_string (value)); break; case MATECONF_VALUE_INT: if (dry_run) g_print ("set key '%s' to integer '%d'\n", keys[j], mateconf_value_get_int (value)); else g_settings_set (settings, keys[j], "i", mateconf_value_get_int (value)); break; case MATECONF_VALUE_BOOL: if (dry_run) g_print ("set key '%s' to boolean '%d'\n", keys[j], mateconf_value_get_bool (value)); else g_settings_set (settings, keys[j], "b", mateconf_value_get_bool (value)); break; case MATECONF_VALUE_FLOAT: if (dry_run) g_print ("set key '%s' to double '%g'\n", keys[j], mateconf_value_get_float (value)); else g_settings_set (settings, keys[j], "d", mateconf_value_get_float (value)); break; case MATECONF_VALUE_LIST: switch (mateconf_value_get_list_type (value)) { case MATECONF_VALUE_STRING: builder = g_variant_builder_new (G_VARIANT_TYPE_ARRAY); list = mateconf_value_get_list (value); if (list != NULL) { for (l = list; l; l = l->next) { MateConfValue *lv = l->data; s = mateconf_value_get_string (lv); g_variant_builder_add (builder, "s", s); } v = g_variant_new ("as", builder); } else v = g_variant_new_array (G_VARIANT_TYPE_STRING, NULL, 0); g_variant_ref_sink (v); if (dry_run) { str = g_variant_print (v, FALSE); g_print ("set key '%s' to a list of strings: %s\n", keys[j], str); g_free (str); } else g_settings_set_value (settings, keys[j], v); g_variant_unref (v); g_variant_builder_unref (builder); break; case MATECONF_VALUE_INT: builder = g_variant_builder_new (G_VARIANT_TYPE_ARRAY); list = mateconf_value_get_list (value); if (list != NULL) { for (l = list; l; l = l->next) { MateConfValue *lv = l->data; ii = mateconf_value_get_int (lv); g_variant_builder_add (builder, "i", ii); } v = g_variant_new ("ai", builder); } else v = g_variant_new_array (G_VARIANT_TYPE_INT32, NULL, 0); g_variant_ref_sink (v); if (dry_run) { str = g_variant_print (v, FALSE); g_print ("set key '%s' to a list of integers: %s\n", keys[j], str); g_free (str); } else g_settings_set_value (settings, keys[j], v); g_variant_unref (v); g_variant_builder_unref (builder); break; default: g_printerr ("Keys of type 'list of %s' not handled yet\n", mateconf_value_type_to_string (mateconf_value_get_list_type (value))); break; } break; default: g_printerr ("Keys of type %s not handled yet\n", mateconf_value_type_to_string (value->type)); break; } mateconf_value_free (value); g_free (mateconf_key); } g_strfreev (keys); if (!dry_run) g_settings_apply (settings); g_object_unref (settings); g_strfreev (schema_path); } g_strfreev (groups); g_object_unref (client); return TRUE; }