Mercurial > pidgin
comparison src/gtksavedstatuses.c @ 11811:924c6ba240e6
[gaim-migrate @ 14102]
sf patch #1335954, from Sadrul Habib Chowdhury
Add "Apply" button the Saved-status dialog
Is this good?
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Tue, 25 Oct 2005 06:15:13 +0000 |
parents | 8cb75ba77f9d |
children | 9ca386c15ffe |
comparison
equal
deleted
inserted
replaced
11810:42b5b3015d9e | 11811:924c6ba240e6 |
---|---|
40 #include "gtkstock.h" | 40 #include "gtkstock.h" |
41 #include "gtkutils.h" | 41 #include "gtkutils.h" |
42 | 42 |
43 enum | 43 enum |
44 { | 44 { |
45 /* A hidden column containing a pointer to the GaimStatusType */ | |
46 STATUS_WINDOW_COLUMN_STATUS, | |
47 | |
45 STATUS_WINDOW_COLUMN_TITLE, | 48 STATUS_WINDOW_COLUMN_TITLE, |
46 STATUS_WINDOW_COLUMN_TYPE, | 49 STATUS_WINDOW_COLUMN_TYPE, |
47 STATUS_WINDOW_COLUMN_MESSAGE, | 50 STATUS_WINDOW_COLUMN_MESSAGE, |
48 STATUS_WINDOW_NUM_COLUMNS | 51 STATUS_WINDOW_NUM_COLUMNS |
49 }; | 52 }; |
59 typedef struct | 62 typedef struct |
60 { | 63 { |
61 GtkWidget *window; | 64 GtkWidget *window; |
62 GtkListStore *model; | 65 GtkListStore *model; |
63 GtkWidget *treeview; | 66 GtkWidget *treeview; |
67 GtkWidget *use_button; | |
64 GtkWidget *modify_button; | 68 GtkWidget *modify_button; |
65 GtkWidget *delete_button; | 69 GtkWidget *delete_button; |
66 } StatusWindow; | 70 } StatusWindow; |
67 | 71 |
68 typedef struct | 72 typedef struct |
126 | 130 |
127 return FALSE; | 131 return FALSE; |
128 } | 132 } |
129 | 133 |
130 static void | 134 static void |
135 status_window_use_cb(GtkButton *button, StatusWindow *dialog) | |
136 { | |
137 GtkTreeSelection *selection; | |
138 GtkTreeIter iter; | |
139 GaimSavedStatus *saved_status; | |
140 GList *list; | |
141 | |
142 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dialog->treeview)); | |
143 | |
144 if (gtk_tree_selection_count_selected_rows(selection) != 1) | |
145 /* | |
146 * This shouldn't happen because the "Use" button should have | |
147 * been grayed out. Oh well. | |
148 */ | |
149 return; | |
150 | |
151 list = gtk_tree_selection_get_selected_rows(selection, NULL); | |
152 | |
153 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(dialog->model), | |
154 &iter, list->data)) | |
155 { | |
156 gtk_tree_model_get(GTK_TREE_MODEL(dialog->model), &iter, | |
157 STATUS_WINDOW_COLUMN_STATUS, &saved_status, | |
158 -1); | |
159 | |
160 gaim_savedstatus_activate(saved_status); | |
161 } | |
162 | |
163 g_list_foreach(list, (GFunc)gtk_tree_path_free, NULL); | |
164 g_list_free(list); | |
165 } | |
166 | |
167 static void | |
131 status_window_add_cb(GtkButton *button, gpointer user_data) | 168 status_window_add_cb(GtkButton *button, gpointer user_data) |
132 { | 169 { |
133 gaim_gtk_status_editor_show(NULL); | 170 gaim_gtk_status_editor_show(NULL); |
134 } | 171 } |
135 | 172 |
136 static void | 173 static void |
137 status_window_modify_foreach(GtkTreeModel *model, GtkTreePath *path, | 174 status_window_modify_foreach(GtkTreeModel *model, GtkTreePath *path, |
138 GtkTreeIter *iter, gpointer user_data) | 175 GtkTreeIter *iter, gpointer user_data) |
139 { | 176 { |
140 char *title; | |
141 GaimSavedStatus *status; | 177 GaimSavedStatus *status; |
142 | 178 |
143 gtk_tree_model_get(model, iter, STATUS_WINDOW_COLUMN_TITLE, &title, -1); | 179 gtk_tree_model_get(model, iter, STATUS_WINDOW_COLUMN_STATUS, &status, -1); |
144 | |
145 status = gaim_savedstatus_find(title); | |
146 g_free(title); | |
147 gaim_gtk_status_editor_show(status); | 180 gaim_gtk_status_editor_show(status); |
148 } | 181 } |
149 | 182 |
150 static void | 183 static void |
151 status_window_modify_cb(GtkButton *button, gpointer user_data) | 184 status_window_modify_cb(GtkButton *button, gpointer user_data) |
209 #if !GTK_CHECK_VERSION(2,2,0) | 242 #if !GTK_CHECK_VERSION(2,2,0) |
210 static void | 243 static void |
211 get_selected_helper(GtkTreeModel *model, GtkTreePath *path, | 244 get_selected_helper(GtkTreeModel *model, GtkTreePath *path, |
212 GtkTreeIter *iter, gpointer user_data) | 245 GtkTreeIter *iter, gpointer user_data) |
213 { | 246 { |
214 *((gboolean *)user_data) = TRUE; | 247 *((gboolean *)user_data)++; |
215 } | 248 } |
216 #endif | 249 #endif |
217 | 250 |
218 static void | 251 static void |
219 status_selected_cb(GtkTreeSelection *sel, gpointer user_data) | 252 status_selected_cb(GtkTreeSelection *sel, gpointer user_data) |
220 { | 253 { |
221 StatusWindow *dialog = user_data; | 254 StatusWindow *dialog = user_data; |
222 gboolean selected = FALSE; | 255 int num_selected; |
223 | 256 |
224 #if GTK_CHECK_VERSION(2,2,0) | 257 #if GTK_CHECK_VERSION(2,2,0) |
225 selected = (gtk_tree_selection_count_selected_rows(sel) > 0); | 258 num_selected = gtk_tree_selection_count_selected_rows(sel); |
226 #else | 259 #else |
227 gtk_tree_selection_selected_foreach(sel, get_selected_helper, &selected); | 260 gtk_tree_selection_selected_foreach(sel, get_selected_helper, &num_selected); |
228 #endif | 261 #endif |
229 | 262 |
230 gtk_widget_set_sensitive(dialog->modify_button, selected); | 263 gtk_widget_set_sensitive(dialog->use_button, (num_selected == 1)); |
231 gtk_widget_set_sensitive(dialog->delete_button, selected); | 264 gtk_widget_set_sensitive(dialog->modify_button, (num_selected > 0)); |
265 gtk_widget_set_sensitive(dialog->delete_button, (num_selected > 0)); | |
232 } | 266 } |
233 | 267 |
234 static void | 268 static void |
235 add_status_to_saved_status_list(GtkListStore *model, GaimSavedStatus *saved_status) | 269 add_status_to_saved_status_list(GtkListStore *model, GaimSavedStatus *saved_status) |
236 { | 270 { |
246 type = gaim_primitive_get_name_from_type(gaim_savedstatus_get_type(saved_status)); | 280 type = gaim_primitive_get_name_from_type(gaim_savedstatus_get_type(saved_status)); |
247 message = gaim_markup_strip_html(gaim_savedstatus_get_message(saved_status)); | 281 message = gaim_markup_strip_html(gaim_savedstatus_get_message(saved_status)); |
248 | 282 |
249 gtk_list_store_append(model, &iter); | 283 gtk_list_store_append(model, &iter); |
250 gtk_list_store_set(model, &iter, | 284 gtk_list_store_set(model, &iter, |
285 STATUS_WINDOW_COLUMN_STATUS, saved_status, | |
251 STATUS_WINDOW_COLUMN_TITLE, title, | 286 STATUS_WINDOW_COLUMN_TITLE, title, |
252 STATUS_WINDOW_COLUMN_TYPE, type, | 287 STATUS_WINDOW_COLUMN_TYPE, type, |
253 STATUS_WINDOW_COLUMN_MESSAGE, message, | 288 STATUS_WINDOW_COLUMN_MESSAGE, message, |
254 -1); | 289 -1); |
255 free(message); | 290 free(message); |
302 GTK_SHADOW_IN); | 337 GTK_SHADOW_IN); |
303 gtk_widget_show(sw); | 338 gtk_widget_show(sw); |
304 | 339 |
305 /* Create the list model */ | 340 /* Create the list model */ |
306 dialog->model = gtk_list_store_new(STATUS_WINDOW_NUM_COLUMNS, | 341 dialog->model = gtk_list_store_new(STATUS_WINDOW_NUM_COLUMNS, |
342 G_TYPE_POINTER, | |
307 G_TYPE_STRING, | 343 G_TYPE_STRING, |
308 G_TYPE_STRING, | 344 G_TYPE_STRING, |
309 G_TYPE_STRING); | 345 G_TYPE_STRING); |
310 | 346 |
311 /* Create the treeview */ | 347 /* Create the treeview */ |
433 bbox = gtk_hbutton_box_new(); | 469 bbox = gtk_hbutton_box_new(); |
434 gtk_box_set_spacing(GTK_BOX(bbox), GAIM_HIG_BOX_SPACE); | 470 gtk_box_set_spacing(GTK_BOX(bbox), GAIM_HIG_BOX_SPACE); |
435 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); | 471 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); |
436 gtk_box_pack_end(GTK_BOX(vbox), bbox, FALSE, TRUE, 0); | 472 gtk_box_pack_end(GTK_BOX(vbox), bbox, FALSE, TRUE, 0); |
437 gtk_widget_show(bbox); | 473 gtk_widget_show(bbox); |
474 | |
475 /* Use button */ | |
476 /* TODO: It might be better if the button said "Use" or "Activate" */ | |
477 button = gtk_button_new_from_stock(GTK_STOCK_APPLY); | |
478 dialog->use_button = button; | |
479 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
480 gtk_widget_set_sensitive(button, FALSE); | |
481 gtk_widget_show(button); | |
482 | |
483 g_signal_connect(G_OBJECT(button), "clicked", | |
484 G_CALLBACK(status_window_use_cb), dialog); | |
438 | 485 |
439 /* Add button */ | 486 /* Add button */ |
440 button = gtk_button_new_from_stock(GTK_STOCK_ADD); | 487 button = gtk_button_new_from_stock(GTK_STOCK_ADD); |
441 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | 488 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); |
442 gtk_widget_show(button); | 489 gtk_widget_show(button); |