pidgin: 069f1971: Update the list of statuses when a new s...
sadrul at pidgin.im
sadrul at pidgin.im
Sun Jun 1 00:55:39 EDT 2008
-----------------------------------------------------------------
Revision: 069f197178d158cdd308687095c14d49d8eee0ed
Ancestor: c57d3ddd9e7431dd2a0ecd9be96ec6eee270ac09
Author: sadrul at pidgin.im
Date: 2008-06-01T04:48:51
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/069f197178d158cdd308687095c14d49d8eee0ed
Modified files:
pidgin/gtksavedstatuses.c
ChangeLog:
Update the list of statuses when a new status is added, or an existing
one is modified or deleted. Fixes #5948.
-------------- next part --------------
============================================================
--- pidgin/gtksavedstatuses.c 915bad92c54f3c0f5dadaa965f0d21b6e1601ba0
+++ pidgin/gtksavedstatuses.c b1bbaaacd22b5981a17ac5c0ea475eb91a905d4f
@@ -1679,6 +1679,96 @@ static gboolean pidgin_status_menu_add_p
return currently_selected;
}
+static void
+pidgin_status_menu_update_iter(GtkWidget *combobox, GtkListStore *store, GtkTreeIter *iter,
+ PurpleSavedStatus *status)
+{
+ GdkPixbuf *pixbuf;
+
+ if (store == NULL)
+ store = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(combobox)));
+
+ pixbuf = pidgin_create_status_icon(purple_savedstatus_get_type(status),
+ combobox, PIDGIN_ICON_SIZE_TANGO_EXTRA_SMALL);
+ gtk_list_store_set(store, iter,
+ SS_MENU_TYPE_COLUMN, SS_MENU_ENTRY_TYPE_SAVEDSTATUS,
+ SS_MENU_ICON_COLUMN, pixbuf,
+ SS_MENU_TEXT_COLUMN, purple_savedstatus_get_title(status),
+ SS_MENU_DATA_COLUMN, GINT_TO_POINTER(purple_savedstatus_get_creation_time(status)),
+ SS_MENU_EMBLEM_COLUMN, GTK_STOCK_SAVE,
+ SS_MENU_EMBLEM_VISIBLE_COLUMN, TRUE,
+ -1);
+ if (pixbuf)
+ g_object_unref(G_OBJECT(pixbuf));
+}
+
+static gboolean
+pidgin_status_menu_find_iter(GtkListStore *store, GtkTreeIter *iter, PurpleSavedStatus *find)
+{
+ int type;
+ gpointer data;
+ time_t creation_time = purple_savedstatus_get_creation_time(find);
+ GtkTreeModel *model = GTK_TREE_MODEL(store);
+
+ if (!gtk_tree_model_get_iter_first(model, iter))
+ return FALSE;
+
+ do {
+ gtk_tree_model_get(model, iter,
+ SS_MENU_TYPE_COLUMN, &type,
+ SS_MENU_DATA_COLUMN, &data,
+ -1);
+ if (type == SS_MENU_ENTRY_TYPE_PRIMITIVE)
+ continue;
+ if (GPOINTER_TO_INT(data) == creation_time)
+ return TRUE;
+ } while (gtk_tree_model_iter_next(model, iter));
+
+ return FALSE;
+}
+
+static void
+savedstatus_added_cb(PurpleSavedStatus *status, GtkWidget *combobox)
+{
+ GtkListStore *store;
+ GtkTreeIter iter;
+
+ if (purple_savedstatus_is_transient(status))
+ return;
+
+ store = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(combobox)));
+ gtk_list_store_append(store, &iter);
+ pidgin_status_menu_update_iter(combobox, store, &iter, status);
+}
+
+static void
+savedstatus_deleted_cb(PurpleSavedStatus *status, GtkWidget *combobox)
+{
+ GtkListStore *store;
+ GtkTreeIter iter;
+
+ if (purple_savedstatus_is_transient(status))
+ return;
+
+ store = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(combobox)));
+ if (pidgin_status_menu_find_iter(store, &iter, status))
+ gtk_list_store_remove(store, &iter);
+}
+
+static void
+savedstatus_modified_cb(PurpleSavedStatus *status, GtkWidget *combobox)
+{
+ GtkListStore *store;
+ GtkTreeIter iter;
+
+ if (purple_savedstatus_is_transient(status))
+ return;
+
+ store = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(combobox)));
+ if (pidgin_status_menu_find_iter(store, &iter, status))
+ pidgin_status_menu_update_iter(combobox, store, &iter, status);
+}
+
GtkWidget *pidgin_status_menu(PurpleSavedStatus *current_status, GCallback callback)
{
GtkWidget *combobox;
@@ -1686,7 +1776,6 @@ GtkWidget *pidgin_status_menu(PurpleSave
GList *sorted, *cur;
int i = 0;
int index = -1;
- GdkPixbuf *pixbuf;
GtkTreeIter iter;
GtkCellRenderer *text_rend;
GtkCellRenderer *icon_rend;
@@ -1720,19 +1809,10 @@ GtkWidget *pidgin_status_menu(PurpleSave
PurpleSavedStatus *status = (PurpleSavedStatus *) cur->data;
if (!purple_savedstatus_is_transient(status))
{
- pixbuf = pidgin_create_status_icon(purple_savedstatus_get_type(status),
- combobox, PIDGIN_ICON_SIZE_TANGO_EXTRA_SMALL);
gtk_list_store_append(model, &iter);
- gtk_list_store_set(model, &iter,
- SS_MENU_TYPE_COLUMN, SS_MENU_ENTRY_TYPE_SAVEDSTATUS,
- SS_MENU_ICON_COLUMN, pixbuf,
- SS_MENU_TEXT_COLUMN, purple_savedstatus_get_title(status),
- SS_MENU_DATA_COLUMN, GINT_TO_POINTER(purple_savedstatus_get_creation_time(status)),
- SS_MENU_EMBLEM_COLUMN, GTK_STOCK_SAVE,
- SS_MENU_EMBLEM_VISIBLE_COLUMN, TRUE,
- -1);
- g_object_unref(G_OBJECT(pixbuf));
+ pidgin_status_menu_update_iter(combobox, model, &iter, status);
+
if (status == current_status)
index = i;
i++;
@@ -1756,6 +1836,17 @@ GtkWidget *pidgin_status_menu(PurpleSave
gtk_combo_box_set_active(GTK_COMBO_BOX(combobox), index);
g_signal_connect(G_OBJECT(combobox), "changed", G_CALLBACK(status_menu_cb), callback);
+ /* Make sure the list is updated dynamically when a substatus is changed/deleted
+ * or a new one is added. */
+ purple_signal_connect(purple_savedstatuses_get_handle(), "savedstatus-added",
+ combobox, G_CALLBACK(savedstatus_added_cb), combobox);
+ purple_signal_connect(purple_savedstatuses_get_handle(), "savedstatus-deleted",
+ combobox, G_CALLBACK(savedstatus_deleted_cb), combobox);
+ purple_signal_connect(purple_savedstatuses_get_handle(), "savedstatus-modified",
+ combobox, G_CALLBACK(savedstatus_modified_cb), combobox);
+ g_signal_connect(G_OBJECT(combobox), "destroy",
+ G_CALLBACK(purple_signals_disconnect_by_handle), NULL);
+
return combobox;
}
More information about the Commits
mailing list