static void gn_combo_history_mateconf_register_id (GnComboHistory *history) { gchar *key; g_return_if_fail (GN_IS_COMBO_HISTORY (history)); if (!history->priv->mateconf_client) history->priv->mateconf_client = mateconf_client_get_default (); key = g_strconcat ("/apps/mate-settings/", "mate-nettool", "/history-", history->priv->id, NULL); mateconf_client_add_dir (history->priv->mateconf_client, key, MATECONF_CLIENT_PRELOAD_NONE, NULL); history->priv->mateconf_notify = mateconf_client_notify_add ( history->priv->mateconf_client, key, gn_on_mateconf_history_changed, (gpointer) history, NULL, NULL); g_free (key); }
GtkComboBox * gn_combo_history_get_combo (GnComboHistory *history) { g_return_val_if_fail (GN_IS_COMBO_HISTORY (history), NULL); return history->priv->combo; }
static void gn_combo_history_mateconf_load (GnComboHistory *history) { gchar *key; GSList *mateconf_items, *last; g_return_if_fail (GN_IS_COMBO_HISTORY (history)); g_return_if_fail (history->priv->mateconf_client != NULL); g_return_if_fail (history->priv->id != NULL); gn_combo_free_items (history); key = g_strconcat ("/apps/mate-settings/", "mate-nettool", "/history-", history->priv->id, NULL); mateconf_items = mateconf_client_get_list (history->priv->mateconf_client, key, MATECONF_VALUE_STRING, NULL); g_free (key); /* truncate the list */ last = g_slist_nth (mateconf_items, history->priv->max_history - 1); if (last) { g_slist_foreach (last->next, (GFunc) g_free, NULL); g_slist_free (last->next); last->next = NULL; } history->priv->items = mateconf_items; }
void gn_combo_history_add (GnComboHistory *history, const gchar *text) { GSList *item; g_return_if_fail (GN_IS_COMBO_HISTORY (history)); g_return_if_fail (text != NULL); if ((item = g_slist_find_custom (history->priv->items, (gpointer) text, compare))) { /* item is already in list, remove them */ history->priv->items = g_slist_remove (history->priv->items, item->data); } if (g_slist_length (history->priv->items) >= history->priv->max_history) { item = g_slist_last (history->priv->items); history->priv->items = g_slist_remove (history->priv->items, item->data); } history->priv->items = g_slist_prepend (history->priv->items, g_strdup (text)); gn_combo_history_set_popdown_strings (history); gn_combo_history_settings_save (history); }
const gchar * gn_combo_history_get_id (GnComboHistory *history) { g_return_val_if_fail (GN_IS_COMBO_HISTORY (history), NULL); return history->priv->id; }
guint gn_combo_history_get_max_history (GnComboHistory *history) { g_return_val_if_fail (GN_IS_COMBO_HISTORY (history), 0); return history->priv->max_history; }
static void gn_combo_history_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *spec) { GnComboHistory *history; g_return_if_fail (GN_IS_COMBO_HISTORY (object)); history = GN_COMBO_HISTORY (object); switch (prop_id) { case PROP_COMBO: history->priv->combo = g_value_get_pointer (value); break; case PROP_ID: if (history->priv->id) g_free (history->priv->id); history->priv->id = g_value_dup_string (value); break; case PROP_MAX_HISTORY: history->priv->max_history = g_value_get_uint (value); break; default: break; } }
void gn_combo_history_set_max_history (GnComboHistory *history, guint max_history) { g_return_if_fail (GN_IS_COMBO_HISTORY (history)); history->priv->max_history = max_history; }
void netinfo_set_user (Netinfo * netinfo, const gchar *user) { g_return_if_fail (netinfo != NULL); g_return_if_fail (GN_IS_COMBO_HISTORY (netinfo->history_user)); gn_combo_history_add (GN_COMBO_HISTORY (netinfo->history_user), user); }
void netinfo_set_host (Netinfo * netinfo, const gchar *host) { g_return_if_fail (netinfo != NULL); g_return_if_fail (GN_IS_COMBO_HISTORY (netinfo->history)); gn_combo_history_add (GN_COMBO_HISTORY (netinfo->history), host); }
void gn_combo_history_clear (GnComboHistory *history) { g_return_if_fail (GN_IS_COMBO_HISTORY (history)); if (history->priv->items) { gn_combo_free_items (history); gn_combo_history_settings_save (history); } }
static void gn_combo_history_init (GnComboHistory *history) { g_return_if_fail (GN_IS_COMBO_HISTORY (history)); history->priv = g_new0 (GnComboHistoryPrivate, 1); history->priv->combo = NULL; history->priv->id = NULL; history->priv->max_history = 10; history->priv->items = NULL; history->priv->settings = g_settings_new ("org.gnome.gnome-nettool"); }
void gn_combo_history_set_id (GnComboHistory *history, const gchar *history_id) { g_return_if_fail (GN_IS_COMBO_HISTORY (history)); g_return_if_fail (history_id != NULL); if (history->priv->id) g_free (history->priv->id); history->priv->id = g_strdup (history_id); gn_combo_history_settings_register_id (history); }
static void gn_combo_history_init (GnComboHistory *history) { g_return_if_fail (GN_IS_COMBO_HISTORY (history)); history->priv = g_new0 (GnComboHistoryPrivate, 1); history->priv->combo = NULL; history->priv->id = NULL; history->priv->max_history = 10; history->priv->items = NULL; history->priv->mateconf_client = mateconf_client_get_default (); history->priv->mateconf_notify = 0; }
static void gn_combo_history_settings_save (GnComboHistory *history) { const gchar **items; GSList *item; gint i; g_return_if_fail (GN_IS_COMBO_HISTORY (history)); g_return_if_fail (history->priv->id != NULL); items = g_malloc (sizeof (gchar *) * (g_slist_length (history->priv->items) + 1)); for (item = history->priv->items, i = 0; item; item = item->next, i++) items[i] = item->data; items[i] = NULL; g_settings_set_strv (history->priv->settings, history->priv->id, items); g_free (items); }
static void gn_combo_history_settings_load (GnComboHistory *history) { gchar **items; guint i; g_return_if_fail (GN_IS_COMBO_HISTORY (history)); g_return_if_fail (history->priv->id != NULL); gn_combo_free_items (history); history->priv->items = NULL; items = g_settings_get_strv (history->priv->settings, history->priv->id); for (i = 0; items[i] && i < history->priv->max_history; i++) history->priv->items = g_slist_append (history->priv->items, g_strdup (items[i])); g_strfreev (items); }
static void gn_combo_history_set_popdown_strings (GnComboHistory *history) { GtkTreeModel *model; GtkTreeIter iter; GSList *items; gchar *text; gint text_column, i; g_return_if_fail (GN_IS_COMBO_HISTORY (history)); g_return_if_fail (GTK_IS_COMBO_BOX (history->priv->combo)); model = gtk_combo_box_get_model (history->priv->combo); if (!model) return; text_column = gtk_combo_box_get_entry_text_column ( GTK_COMBO_BOX (history->priv->combo)); gtk_list_store_clear (GTK_LIST_STORE (model)); if (! history->priv->items) { gtk_combo_box_set_active (GTK_COMBO_BOX (history->priv->combo), -1); return; } i = 0; for (items = history->priv->items; items; items = items->next) { text = items->data; gtk_list_store_insert (GTK_LIST_STORE (model), &iter, i); gtk_list_store_set (GTK_LIST_STORE (model), &iter, text_column, text, -1); i ++; } /* At this point the current selection always be at the first place in the model */ gtk_combo_box_set_active (GTK_COMBO_BOX (history->priv->combo), 0); }
static void gn_combo_history_mateconf_save (GnComboHistory *history) { gchar *key; g_return_if_fail (GN_IS_COMBO_HISTORY (history)); g_return_if_fail (history->priv->mateconf_client != NULL); g_return_if_fail (history->priv->id != NULL); key = g_strconcat ("/apps/mate-settings/", "mate-nettool", "/history-", history->priv->id, NULL); mateconf_client_set_list (history->priv->mateconf_client, key, MATECONF_VALUE_STRING, history->priv->items, NULL); g_free (key); }
static void gn_combo_history_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *spec) { GnComboHistory *history; g_return_if_fail (GN_IS_COMBO_HISTORY (object)); history = GN_COMBO_HISTORY (object); switch (prop_id) { case PROP_COMBO: g_value_set_pointer (value, history->priv->combo); break; case PROP_ID: g_value_set_string (value, history->priv->id); break; case PROP_MAX_HISTORY: g_value_set_uint (value, history->priv->max_history); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, spec); } }
void gn_combo_history_set_combo (GnComboHistory *history, GtkComboBox *combo) { g_return_if_fail (GN_IS_COMBO_HISTORY (history)); g_return_if_fail (GTK_IS_COMBO_BOX (combo)); if (history->priv->combo) g_object_unref (G_OBJECT (history->priv->combo)); history->priv->combo = combo; gn_combo_history_settings_load (history); gn_combo_history_set_popdown_strings (history); gtk_combo_box_set_active (GTK_COMBO_BOX (history->priv->combo), -1); gtk_entry_set_text ( GTK_ENTRY (gtk_bin_get_child ( GTK_BIN (history->priv->combo))), ""); g_object_ref (G_OBJECT (history->priv->combo)); }
static void gn_combo_history_settings_register_id (GnComboHistory *history) { g_return_if_fail (GN_IS_COMBO_HISTORY (history)); g_signal_connect (history->priv->settings, "changed", G_CALLBACK (gn_on_settings_history_changed), history); }