Mercurial > pidgin
annotate src/gtksavedstatuses.c @ 13091:7aea8de78463
[gaim-migrate @ 15453]
Set a minimum size for the icons overlayed onto stuff
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Thu, 02 Feb 2006 00:33:30 +0000 |
parents | 0aa231ebbfd5 |
children | 39e7014cb687 |
rev | line source |
---|---|
10418 | 1 /** |
2 * @file gtksavedstatus.c GTK+ Saved Status Editor UI | |
3 * @ingroup gtkui | |
4 * | |
5 * gaim | |
6 * | |
7 * Gaim is the legal property of its developers, whose names are too numerous | |
8 * to list here. Please refer to the COPYRIGHT file distributed with this | |
9 * source distribution. | |
10 * | |
11 * This program is free software; you can redistribute it and/or modify | |
12 * it under the terms of the GNU General Public License as published by | |
13 * the Free Software Foundation; either version 2 of the License, or | |
14 * (at your option) any later version. | |
15 * | |
16 * This program is distributed in the hope that it will be useful, | |
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 * GNU General Public License for more details. | |
20 * | |
21 * You should have received a copy of the GNU General Public License | |
22 * along with this program; if not, write to the Free Software | |
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
24 */ | |
25 | |
26 #include "account.h" | |
27 #include "internal.h" | |
10420 | 28 #include "notify.h" |
10418 | 29 #include "request.h" |
30 #include "savedstatuses.h" | |
31 #include "status.h" | |
32 #include "util.h" | |
33 | |
34 #include "gtkblist.h" | |
11735 | 35 #include "gtkexpander.h" |
10418 | 36 #include "gtkgaim.h" |
37 #include "gtkimhtml.h" | |
38 #include "gtkimhtmltoolbar.h" | |
39 #include "gtksavedstatuses.h" | |
40 #include "gtkstock.h" | |
41 #include "gtkutils.h" | |
42 | |
12080 | 43 /* |
44 * TODO: Should attach to the account-deleted and account-added signals | |
45 * and update the GtkListStores in any StatusEditor windows that | |
46 * may be open. | |
47 */ | |
48 | |
49 /** | |
50 * These are used for the GtkTreeView when you're scrolling through | |
51 * all your saved statuses. | |
52 */ | |
10418 | 53 enum |
54 { | |
10421 | 55 STATUS_WINDOW_COLUMN_TITLE, |
56 STATUS_WINDOW_COLUMN_TYPE, | |
57 STATUS_WINDOW_COLUMN_MESSAGE, | |
58 STATUS_WINDOW_NUM_COLUMNS | |
59 }; | |
60 | |
12080 | 61 /** |
62 * These is used for the GtkTreeView containing the list of accounts | |
63 * at the bottom of the window when you're editing a particular | |
64 * saved status. | |
65 */ | |
10421 | 66 enum |
67 { | |
12080 | 68 /** A hidden column containing a pointer to the GaimAccount */ |
69 STATUS_EDITOR_COLUMN_ACCOUNT, | |
70 STATUS_EDITOR_COLUMN_ENABLE_SUBSTATUS, | |
10418 | 71 STATUS_EDITOR_COLUMN_ICON, |
72 STATUS_EDITOR_COLUMN_SCREENNAME, | |
12080 | 73 /** A hidden column containing the ID of this GaimStatusType. */ |
74 STATUS_EDITOR_COLUMN_STATUS_ID, | |
75 STATUS_EDITOR_COLUMN_STATUS_NAME, | |
76 STATUS_EDITOR_COLUMN_STATUS_MESSAGE, | |
10418 | 77 STATUS_EDITOR_NUM_COLUMNS |
78 }; | |
79 | |
12080 | 80 /** |
81 * These are used in the GtkComboBox to select the specific | |
82 * GaimStatusType when setting a substatus for a particular saved | |
83 * status. | |
84 */ | |
85 enum | |
86 { | |
87 /** A hidden column containing a pointer to the GaimAccount. */ | |
88 SUBSTATUS_COLUMN_ACCOUNT, | |
89 SUBSTATUS_COLUMN_ICON, | |
90 /** A hidden column containing the ID of this GaimStatusType. */ | |
91 SUBSTATUS_COLUMN_STATUS_ID, | |
92 SUBSTATUS_COLUMN_STATUS_NAME, | |
93 SUBSTATUS_NUM_COLUMNS | |
94 }; | |
95 | |
10421 | 96 typedef struct |
10418 | 97 { |
10421 | 98 GtkWidget *window; |
99 GtkListStore *model; | |
100 GtkWidget *treeview; | |
11811 | 101 GtkWidget *use_button; |
10421 | 102 GtkWidget *modify_button; |
103 GtkWidget *delete_button; | |
104 } StatusWindow; | |
10418 | 105 |
106 typedef struct | |
107 { | |
108 GtkWidget *window; | |
109 GtkListStore *model; | |
110 GtkWidget *treeview; | |
12329 | 111 GtkButton *saveanduse_button; |
112 GtkButton *save_button; | |
10420 | 113 |
114 gchar *original_title; | |
115 GtkEntry *title; | |
116 GtkOptionMenu *type; | |
117 GtkIMHtml *message; | |
10418 | 118 } StatusEditor; |
119 | |
12080 | 120 typedef struct |
121 { | |
122 StatusEditor *status_editor; | |
123 GaimAccount *account; | |
124 | |
125 GtkWidget *window; | |
126 GtkListStore *model; | |
127 GtkComboBox *box; | |
128 GtkIMHtml *message; | |
129 GtkIMHtmlToolbar *toolbar; | |
130 } SubStatusEditor; | |
131 | |
10418 | 132 static StatusWindow *status_window = NULL; |
133 | |
10421 | 134 |
135 /************************************************************************** | |
136 * Status window | |
137 **************************************************************************/ | |
138 | |
139 static gboolean | |
140 status_window_find_savedstatus(GtkTreeIter *iter, const char *title) | |
141 { | |
142 GtkTreeModel *model = GTK_TREE_MODEL(status_window->model); | |
10439 | 143 char *cur; |
10421 | 144 |
145 if (!gtk_tree_model_get_iter_first(model, iter)) | |
146 return FALSE; | |
147 | |
148 gtk_tree_model_get(model, iter, STATUS_WINDOW_COLUMN_TITLE, &cur, -1); | |
149 if (!strcmp(title, cur)) | |
10439 | 150 { |
151 g_free(cur); | |
10421 | 152 return TRUE; |
10439 | 153 } |
154 g_free(cur); | |
10421 | 155 |
156 while (gtk_tree_model_iter_next(model, iter)) | |
157 { | |
158 gtk_tree_model_get(model, iter, STATUS_WINDOW_COLUMN_TITLE, &cur, -1); | |
159 if (!strcmp(title, cur)) | |
10439 | 160 { |
161 g_free(cur); | |
10421 | 162 return TRUE; |
10439 | 163 } |
164 g_free(cur); | |
10421 | 165 } |
166 | |
167 return FALSE; | |
168 } | |
169 | |
170 static gboolean | |
171 status_window_destroy_cb(GtkWidget *widget, GdkEvent *event, gpointer user_data) | |
172 { | |
173 StatusWindow *dialog = user_data; | |
174 | |
175 dialog->window = NULL; | |
176 gaim_gtk_status_window_hide(); | |
177 | |
178 return FALSE; | |
179 } | |
180 | |
11888 | 181 #if !GTK_CHECK_VERSION(2,2,0) |
182 static void | |
183 count_selected_helper(GtkTreeModel *model, GtkTreePath *path, | |
184 GtkTreeIter *iter, gpointer user_data) | |
185 { | |
186 (*(gint *)user_data)++; | |
187 } | |
188 | |
189 static void | |
190 list_selected_helper(GtkTreeModel *model, GtkTreePath *path, | |
191 GtkTreeIter *iter, gpointer user_data) | |
192 { | |
11889 | 193 GList **list = (GList **)user_data; |
194 *list = g_list_append(*list, gtk_tree_path_copy(path)); | |
11888 | 195 } |
196 #endif | |
197 | |
10421 | 198 static void |
11811 | 199 status_window_use_cb(GtkButton *button, StatusWindow *dialog) |
200 { | |
201 GtkTreeSelection *selection; | |
202 GtkTreeIter iter; | |
11889 | 203 GList *list = NULL; |
11888 | 204 int num_selected = 0; |
11811 | 205 |
206 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dialog->treeview)); | |
207 | |
11888 | 208 #if GTK_CHECK_VERSION(2,2,0) |
209 num_selected = gtk_tree_selection_count_selected_rows(selection); | |
210 #else | |
211 gtk_tree_selection_selected_foreach(selection, count_selected_helper, &num_selected); | |
212 #endif | |
213 if (num_selected != 1) | |
11811 | 214 /* |
215 * This shouldn't happen because the "Use" button should have | |
216 * been grayed out. Oh well. | |
217 */ | |
218 return; | |
219 | |
11888 | 220 #if GTK_CHECK_VERSION(2,2,0) |
11811 | 221 list = gtk_tree_selection_get_selected_rows(selection, NULL); |
11888 | 222 #else |
223 gtk_tree_selection_selected_foreach(selection, list_selected_helper, &list); | |
224 #endif | |
11811 | 225 |
226 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(dialog->model), | |
227 &iter, list->data)) | |
228 { | |
12080 | 229 gchar *title; |
230 GaimSavedStatus *saved_status; | |
11811 | 231 gtk_tree_model_get(GTK_TREE_MODEL(dialog->model), &iter, |
12080 | 232 STATUS_WINDOW_COLUMN_TITLE, &title, |
11811 | 233 -1); |
12080 | 234 saved_status = gaim_savedstatus_find(title); |
235 g_free(title); | |
11811 | 236 gaim_savedstatus_activate(saved_status); |
237 } | |
238 | |
239 g_list_foreach(list, (GFunc)gtk_tree_path_free, NULL); | |
240 g_list_free(list); | |
241 } | |
242 | |
243 static void | |
10421 | 244 status_window_add_cb(GtkButton *button, gpointer user_data) |
245 { | |
246 gaim_gtk_status_editor_show(NULL); | |
247 } | |
248 | |
249 static void | |
250 status_window_modify_foreach(GtkTreeModel *model, GtkTreePath *path, | |
251 GtkTreeIter *iter, gpointer user_data) | |
252 { | |
12080 | 253 gchar *title; |
254 GaimSavedStatus *saved_status; | |
10421 | 255 |
12080 | 256 gtk_tree_model_get(model, iter, STATUS_WINDOW_COLUMN_TITLE, &title, -1); |
257 saved_status = gaim_savedstatus_find(title); | |
258 g_free(title); | |
259 gaim_gtk_status_editor_show(saved_status); | |
10421 | 260 } |
261 | |
262 static void | |
263 status_window_modify_cb(GtkButton *button, gpointer user_data) | |
264 { | |
265 StatusWindow *dialog = user_data; | |
266 GtkTreeSelection *selection; | |
267 | |
268 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dialog->treeview)); | |
269 | |
270 gtk_tree_selection_selected_foreach(selection, status_window_modify_foreach, user_data); | |
271 } | |
272 | |
273 static void | |
274 status_window_delete_confirm_cb(char *title) | |
275 { | |
276 GtkTreeIter iter; | |
277 | |
278 if (status_window_find_savedstatus(&iter, title)) | |
279 gtk_list_store_remove(status_window->model, &iter); | |
280 | |
281 gaim_savedstatus_delete(title); | |
282 | |
283 g_free(title); | |
284 } | |
285 | |
286 static void | |
287 status_window_delete_foreach(GtkTreeModel *model, GtkTreePath *path, | |
288 GtkTreeIter *iter, gpointer user_data) | |
289 { | |
10439 | 290 char *title; |
12237 | 291 char *buf; |
10421 | 292 |
293 gtk_tree_model_get(model, iter, STATUS_WINDOW_COLUMN_TITLE, &title, -1); | |
294 | |
12237 | 295 buf = g_strdup_printf(_("Are you sure you want to delete %s?"), title); |
12888
03f690fcb78e
[gaim-migrate @ 15241]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12856
diff
changeset
|
296 gaim_request_action(status_window, NULL, buf, NULL, 0, title, 2, |
10421 | 297 _("Delete"), status_window_delete_confirm_cb, |
298 _("Cancel"), g_free); | |
299 g_free(buf); | |
300 } | |
301 | |
302 static void | |
303 status_window_delete_cb(GtkButton *button, gpointer user_data) | |
304 { | |
305 StatusWindow *dialog = user_data; | |
306 GtkTreeSelection *selection; | |
307 | |
308 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dialog->treeview)); | |
309 | |
310 gtk_tree_selection_selected_foreach(selection, status_window_delete_foreach, user_data); | |
311 } | |
312 | |
313 static void | |
314 status_window_close_cb(GtkButton *button, gpointer user_data) | |
315 { | |
316 gaim_gtk_status_window_hide(); | |
317 } | |
318 | |
319 static void | |
320 status_selected_cb(GtkTreeSelection *sel, gpointer user_data) | |
321 { | |
322 StatusWindow *dialog = user_data; | |
11888 | 323 int num_selected = 0; |
10421 | 324 |
325 #if GTK_CHECK_VERSION(2,2,0) | |
11811 | 326 num_selected = gtk_tree_selection_count_selected_rows(sel); |
10421 | 327 #else |
11888 | 328 gtk_tree_selection_selected_foreach(sel, count_selected_helper, &num_selected); |
10421 | 329 #endif |
330 | |
11811 | 331 gtk_widget_set_sensitive(dialog->use_button, (num_selected == 1)); |
332 gtk_widget_set_sensitive(dialog->modify_button, (num_selected > 0)); | |
333 gtk_widget_set_sensitive(dialog->delete_button, (num_selected > 0)); | |
10421 | 334 } |
335 | |
336 static void | |
337 add_status_to_saved_status_list(GtkListStore *model, GaimSavedStatus *saved_status) | |
338 { | |
339 GtkTreeIter iter; | |
340 const char *title; | |
341 const char *type; | |
342 char *message; | |
343 | |
11651 | 344 if (gaim_savedstatus_is_transient(saved_status)) |
345 return; | |
346 | |
10421 | 347 title = gaim_savedstatus_get_title(saved_status); |
348 type = gaim_primitive_get_name_from_type(gaim_savedstatus_get_type(saved_status)); | |
349 message = gaim_markup_strip_html(gaim_savedstatus_get_message(saved_status)); | |
350 | |
351 gtk_list_store_append(model, &iter); | |
352 gtk_list_store_set(model, &iter, | |
353 STATUS_WINDOW_COLUMN_TITLE, title, | |
354 STATUS_WINDOW_COLUMN_TYPE, type, | |
355 STATUS_WINDOW_COLUMN_MESSAGE, message, | |
356 -1); | |
357 free(message); | |
358 } | |
359 | |
360 static void | |
361 populate_saved_status_list(StatusWindow *dialog) | |
362 { | |
363 const GList *saved_statuses; | |
364 | |
365 gtk_list_store_clear(dialog->model); | |
366 | |
367 for (saved_statuses = gaim_savedstatuses_get_all(); saved_statuses != NULL; | |
368 saved_statuses = g_list_next(saved_statuses)) | |
369 { | |
12199 | 370 add_status_to_saved_status_list(dialog->model, saved_statuses->data); |
10421 | 371 } |
372 } | |
373 | |
10435 | 374 static gboolean |
375 search_func(GtkTreeModel *model, gint column, const gchar *key, GtkTreeIter *iter, gpointer search_data) | |
376 { | |
10439 | 377 gboolean result; |
378 char *haystack; | |
10435 | 379 |
380 gtk_tree_model_get(model, iter, column, &haystack, -1); | |
381 | |
10439 | 382 result = (gaim_strcasestr(haystack, key) == NULL); |
383 | |
384 g_free(haystack); | |
385 | |
386 return result; | |
10435 | 387 } |
388 | |
12162
5e24b8e49522
[gaim-migrate @ 14463]
Richard Laager <rlaager@wiktel.com>
parents:
12080
diff
changeset
|
389 static void |
12173
81c63578aa39
[gaim-migrate @ 14475]
Richard Laager <rlaager@wiktel.com>
parents:
12162
diff
changeset
|
390 savedstatus_activated_cb(GtkTreeView *view, GtkTreePath *path, GtkTreeViewColumn *column, StatusWindow *dialog) |
12162
5e24b8e49522
[gaim-migrate @ 14463]
Richard Laager <rlaager@wiktel.com>
parents:
12080
diff
changeset
|
391 { |
12173
81c63578aa39
[gaim-migrate @ 14475]
Richard Laager <rlaager@wiktel.com>
parents:
12162
diff
changeset
|
392 status_window_modify_cb(NULL, dialog); |
12162
5e24b8e49522
[gaim-migrate @ 14463]
Richard Laager <rlaager@wiktel.com>
parents:
12080
diff
changeset
|
393 } |
5e24b8e49522
[gaim-migrate @ 14463]
Richard Laager <rlaager@wiktel.com>
parents:
12080
diff
changeset
|
394 |
10421 | 395 static GtkWidget * |
396 create_saved_status_list(StatusWindow *dialog) | |
397 { | |
398 GtkWidget *sw; | |
399 GtkWidget *treeview; | |
400 GtkTreeSelection *sel; | |
401 GtkTreeViewColumn *column; | |
402 GtkCellRenderer *renderer; | |
403 | |
404 /* Create the scrolled window */ | |
405 sw = gtk_scrolled_window_new(0, 0); | |
406 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), | |
407 GTK_POLICY_AUTOMATIC, | |
408 GTK_POLICY_ALWAYS); | |
409 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), | |
410 GTK_SHADOW_IN); | |
411 gtk_widget_show(sw); | |
412 | |
413 /* Create the list model */ | |
414 dialog->model = gtk_list_store_new(STATUS_WINDOW_NUM_COLUMNS, | |
415 G_TYPE_STRING, | |
416 G_TYPE_STRING, | |
417 G_TYPE_STRING); | |
418 | |
419 /* Create the treeview */ | |
420 treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(dialog->model)); | |
421 dialog->treeview = treeview; | |
422 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(treeview), TRUE); | |
12162
5e24b8e49522
[gaim-migrate @ 14463]
Richard Laager <rlaager@wiktel.com>
parents:
12080
diff
changeset
|
423 g_signal_connect(G_OBJECT(treeview), "row-activated", |
12173
81c63578aa39
[gaim-migrate @ 14475]
Richard Laager <rlaager@wiktel.com>
parents:
12162
diff
changeset
|
424 G_CALLBACK(savedstatus_activated_cb), dialog); |
10421 | 425 |
426 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); | |
427 gtk_tree_selection_set_mode(sel, GTK_SELECTION_MULTIPLE); | |
428 g_signal_connect(G_OBJECT(sel), "changed", | |
429 G_CALLBACK(status_selected_cb), dialog); | |
430 | |
431 gtk_container_add(GTK_CONTAINER(sw), treeview); | |
432 gtk_widget_show(treeview); | |
433 | |
434 /* Add columns */ | |
435 column = gtk_tree_view_column_new(); | |
436 gtk_tree_view_column_set_title(column, _("Title")); | |
437 gtk_tree_view_column_set_resizable(column, TRUE); | |
11548 | 438 gtk_tree_view_column_set_min_width(column, 100); |
10421 | 439 gtk_tree_view_column_set_sort_column_id(column, |
440 STATUS_WINDOW_COLUMN_TITLE); | |
441 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); | |
442 renderer = gtk_cell_renderer_text_new(); | |
443 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
444 gtk_tree_view_column_add_attribute(column, renderer, "text", | |
445 STATUS_WINDOW_COLUMN_TITLE); | |
11548 | 446 #if GTK_CHECK_VERSION(2,6,0) |
447 g_object_set(renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL); | |
448 #endif | |
10421 | 449 |
450 column = gtk_tree_view_column_new(); | |
451 gtk_tree_view_column_set_title(column, _("Type")); | |
452 gtk_tree_view_column_set_resizable(column, TRUE); | |
453 gtk_tree_view_column_set_sort_column_id(column, | |
454 STATUS_WINDOW_COLUMN_TYPE); | |
455 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); | |
456 renderer = gtk_cell_renderer_text_new(); | |
457 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
458 gtk_tree_view_column_add_attribute(column, renderer, "text", | |
459 STATUS_WINDOW_COLUMN_TYPE); | |
460 | |
461 column = gtk_tree_view_column_new(); | |
462 gtk_tree_view_column_set_title(column, _("Message")); | |
463 gtk_tree_view_column_set_resizable(column, TRUE); | |
464 gtk_tree_view_column_set_sort_column_id(column, | |
465 STATUS_WINDOW_COLUMN_MESSAGE); | |
466 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); | |
467 renderer = gtk_cell_renderer_text_new(); | |
468 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
469 gtk_tree_view_column_add_attribute(column, renderer, "text", | |
470 STATUS_WINDOW_COLUMN_MESSAGE); | |
10435 | 471 #if GTK_CHECK_VERSION(2,6,0) |
10502 | 472 g_object_set(renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL); |
10435 | 473 #endif |
474 | |
475 /* Enable CTRL+F searching */ | |
476 gtk_tree_view_set_search_column(GTK_TREE_VIEW(treeview), STATUS_WINDOW_COLUMN_TITLE); | |
477 gtk_tree_view_set_search_equal_func(GTK_TREE_VIEW(treeview), search_func, NULL, NULL); | |
10421 | 478 |
10422 | 479 /* Sort the title column by default */ |
480 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(dialog->model), | |
481 STATUS_WINDOW_COLUMN_TITLE, | |
482 GTK_SORT_ASCENDING); | |
483 | |
10421 | 484 /* Populate list */ |
485 populate_saved_status_list(dialog); | |
486 | |
487 return sw; | |
488 } | |
489 | |
490 static gboolean | |
491 configure_cb(GtkWidget *widget, GdkEventConfigure *event, StatusWindow *dialog) | |
492 { | |
493 if (GTK_WIDGET_VISIBLE(widget)) { | |
494 gaim_prefs_set_int("/gaim/gtk/status/dialog/width", event->width); | |
495 gaim_prefs_set_int("/gaim/gtk/status/dialog/height", event->height); | |
496 } | |
497 | |
498 return FALSE; | |
499 } | |
500 | |
501 void | |
502 gaim_gtk_status_window_show(void) | |
503 { | |
504 StatusWindow *dialog; | |
505 GtkWidget *bbox; | |
506 GtkWidget *button; | |
507 GtkWidget *list; | |
508 GtkWidget *vbox; | |
509 GtkWidget *win; | |
510 int width, height; | |
511 | |
512 if (status_window != NULL) { | |
513 gtk_window_present(GTK_WINDOW(status_window->window)); | |
514 return; | |
515 } | |
516 | |
517 status_window = dialog = g_new0(StatusWindow, 1); | |
518 | |
519 width = gaim_prefs_get_int("/gaim/gtk/status/dialog/width"); | |
520 height = gaim_prefs_get_int("/gaim/gtk/status/dialog/height"); | |
521 | |
522 dialog->window = win = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
523 gtk_window_set_default_size(GTK_WINDOW(win), width, height); | |
524 gtk_window_set_role(GTK_WINDOW(win), "statuses"); | |
525 gtk_window_set_title(GTK_WINDOW(win), _("Saved Statuses")); | |
11243 | 526 gtk_container_set_border_width(GTK_CONTAINER(win), GAIM_HIG_BORDER); |
10421 | 527 |
528 g_signal_connect(G_OBJECT(win), "delete_event", | |
529 G_CALLBACK(status_window_destroy_cb), dialog); | |
530 g_signal_connect(G_OBJECT(win), "configure_event", | |
531 G_CALLBACK(configure_cb), dialog); | |
532 | |
533 /* Setup the vbox */ | |
11243 | 534 vbox = gtk_vbox_new(FALSE, GAIM_HIG_BORDER); |
10421 | 535 gtk_container_add(GTK_CONTAINER(win), vbox); |
536 gtk_widget_show(vbox); | |
537 | |
538 /* List of saved status states */ | |
539 list = create_saved_status_list(dialog); | |
540 gtk_box_pack_start(GTK_BOX(vbox), list, TRUE, TRUE, 0); | |
541 | |
542 /* Button box. */ | |
543 bbox = gtk_hbutton_box_new(); | |
11243 | 544 gtk_box_set_spacing(GTK_BOX(bbox), GAIM_HIG_BOX_SPACE); |
10421 | 545 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); |
546 gtk_box_pack_end(GTK_BOX(vbox), bbox, FALSE, TRUE, 0); | |
547 gtk_widget_show(bbox); | |
548 | |
11811 | 549 /* Use button */ |
11832 | 550 button = gaim_pixbuf_button_from_stock(_("_Use"), GTK_STOCK_EXECUTE, |
551 GAIM_BUTTON_HORIZONTAL); | |
11811 | 552 dialog->use_button = button; |
553 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
554 gtk_widget_set_sensitive(button, FALSE); | |
555 gtk_widget_show(button); | |
556 | |
557 g_signal_connect(G_OBJECT(button), "clicked", | |
558 G_CALLBACK(status_window_use_cb), dialog); | |
559 | |
10421 | 560 /* Add button */ |
561 button = gtk_button_new_from_stock(GTK_STOCK_ADD); | |
562 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
563 gtk_widget_show(button); | |
564 | |
565 g_signal_connect(G_OBJECT(button), "clicked", | |
566 G_CALLBACK(status_window_add_cb), dialog); | |
567 | |
568 /* Modify button */ | |
569 button = gtk_button_new_from_stock(GAIM_STOCK_MODIFY); | |
570 dialog->modify_button = button; | |
571 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
572 gtk_widget_set_sensitive(button, FALSE); | |
573 gtk_widget_show(button); | |
574 | |
575 g_signal_connect(G_OBJECT(button), "clicked", | |
576 G_CALLBACK(status_window_modify_cb), dialog); | |
577 | |
578 /* Delete button */ | |
579 button = gtk_button_new_from_stock(GTK_STOCK_DELETE); | |
580 dialog->delete_button = button; | |
581 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
582 gtk_widget_set_sensitive(button, FALSE); | |
583 gtk_widget_show(button); | |
584 | |
585 g_signal_connect(G_OBJECT(button), "clicked", | |
586 G_CALLBACK(status_window_delete_cb), dialog); | |
587 | |
588 /* Close button */ | |
589 button = gtk_button_new_from_stock(GTK_STOCK_CLOSE); | |
590 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
591 gtk_widget_show(button); | |
592 | |
593 g_signal_connect(G_OBJECT(button), "clicked", | |
594 G_CALLBACK(status_window_close_cb), dialog); | |
595 | |
596 gtk_widget_show(win); | |
597 } | |
598 | |
599 void | |
600 gaim_gtk_status_window_hide(void) | |
601 { | |
602 if (status_window == NULL) | |
603 return; | |
604 | |
605 if (status_window->window != NULL) | |
606 gtk_widget_destroy(status_window->window); | |
607 | |
12888
03f690fcb78e
[gaim-migrate @ 15241]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12856
diff
changeset
|
608 gaim_request_close_with_handle(status_window); |
03f690fcb78e
[gaim-migrate @ 15241]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12856
diff
changeset
|
609 gaim_notify_close_with_handle(status_window); |
10421 | 610 g_free(status_window); |
611 status_window = NULL; | |
612 } | |
613 | |
614 | |
615 /************************************************************************** | |
616 * Status editor | |
617 **************************************************************************/ | |
10420 | 618 |
10418 | 619 static gboolean |
620 status_editor_destroy_cb(GtkWidget *widget, GdkEvent *event, gpointer user_data) | |
621 { | |
10574 | 622 StatusEditor *dialog = user_data; |
10418 | 623 |
10574 | 624 g_free(dialog->original_title); |
10418 | 625 g_free(dialog); |
626 | |
627 return FALSE; | |
628 } | |
629 | |
630 static void | |
631 status_editor_cancel_cb(GtkButton *button, gpointer user_data) | |
632 { | |
10574 | 633 StatusEditor *dialog = user_data; |
10418 | 634 |
635 gtk_widget_destroy(dialog->window); | |
636 | |
10574 | 637 g_free(dialog->original_title); |
10418 | 638 g_free(dialog); |
639 } | |
640 | |
641 static void | |
12329 | 642 status_editor_ok_cb(GtkButton *button, gpointer user_data) |
10418 | 643 { |
10420 | 644 StatusEditor *dialog = user_data; |
645 const char *title; | |
646 GaimStatusPrimitive type; | |
647 char *message, *unformatted; | |
12080 | 648 GaimSavedStatus *saved_status = NULL; |
649 GtkTreeModel *model; | |
650 GtkTreeIter iter; | |
10420 | 651 |
652 title = gtk_entry_get_text(dialog->title); | |
653 | |
654 /* | |
12329 | 655 * If we're saving this status, and the title is already taken |
656 * then show an error dialog and don't do anything. | |
10420 | 657 */ |
12329 | 658 if (((button == dialog->saveanduse_button) || (button == dialog->save_button)) && |
659 (gaim_savedstatus_find(title) != NULL) && | |
10420 | 660 ((dialog->original_title == NULL) || (strcmp(title, dialog->original_title)))) |
661 { | |
12888
03f690fcb78e
[gaim-migrate @ 15241]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12856
diff
changeset
|
662 gaim_notify_error(status_window, NULL, _("Title already in use. You must " |
10420 | 663 "choose a unique title."), NULL); |
664 return; | |
665 } | |
666 | |
12726
868d574dd83e
[gaim-migrate @ 15070]
Richard Laager <rlaager@wiktel.com>
parents:
12693
diff
changeset
|
667 type = gtk_option_menu_get_history(dialog->type) + (GAIM_STATUS_UNSET + 1); |
10420 | 668 message = gtk_imhtml_get_markup(dialog->message); |
669 unformatted = gaim_markup_strip_html(message); | |
670 | |
671 /* | |
12080 | 672 * If we're editing an old status, then lookup the old status (it's |
673 * possible that it has been deleted or renamed or something, and | |
674 * no longer exists). | |
10420 | 675 */ |
676 if (dialog->original_title != NULL) | |
677 { | |
678 GtkTreeIter iter; | |
679 | |
12080 | 680 saved_status = gaim_savedstatus_find(dialog->original_title); |
10420 | 681 |
682 if (status_window_find_savedstatus(&iter, dialog->original_title)) | |
683 { | |
684 gtk_list_store_remove(status_window->model, &iter); | |
685 } | |
686 } | |
687 | |
12080 | 688 if (saved_status == NULL) |
689 { | |
690 /* This is a new status */ | |
12329 | 691 if ((button == dialog->saveanduse_button) |
692 || (button == dialog->save_button)) | |
693 saved_status = gaim_savedstatus_new(title, type); | |
694 else | |
695 saved_status = gaim_savedstatus_new(NULL, type); | |
12080 | 696 } |
697 else | |
698 { | |
699 /* Modify the old status */ | |
700 if (strcmp(title, dialog->original_title)) | |
701 gaim_savedstatus_set_title(saved_status, title); | |
702 gaim_savedstatus_set_type(saved_status, type); | |
703 } | |
704 | |
12951
9eaf101af7a7
[gaim-migrate @ 15304]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12888
diff
changeset
|
705 if (*unformatted == '\0') |
9eaf101af7a7
[gaim-migrate @ 15304]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12888
diff
changeset
|
706 gaim_savedstatus_set_message(saved_status, NULL); |
9eaf101af7a7
[gaim-migrate @ 15304]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12888
diff
changeset
|
707 else |
12080 | 708 gaim_savedstatus_set_message(saved_status, message); |
709 | |
710 /* Set any substatuses */ | |
711 model = GTK_TREE_MODEL(dialog->model); | |
712 if (gtk_tree_model_get_iter_first(model, &iter)) | |
713 { | |
714 GaimAccount *account; | |
715 gboolean enabled; | |
716 char *id; | |
717 char *message; | |
718 GaimStatusType *type; | |
719 | |
720 gtk_tree_model_get(model, &iter, | |
721 STATUS_EDITOR_COLUMN_ACCOUNT, &account, | |
722 STATUS_EDITOR_COLUMN_ENABLE_SUBSTATUS, &enabled, | |
723 STATUS_EDITOR_COLUMN_STATUS_ID, &id, | |
724 STATUS_EDITOR_COLUMN_STATUS_MESSAGE, &message, | |
725 -1); | |
726 if (enabled) | |
727 { | |
728 type = gaim_account_get_status_type(account, id); | |
729 gaim_savedstatus_set_substatus(saved_status, account, type, message); | |
730 } | |
731 g_free(id); | |
732 g_free(message); | |
733 | |
734 while (gtk_tree_model_iter_next(model, &iter)) | |
735 { | |
736 gtk_tree_model_get(model, &iter, | |
737 STATUS_EDITOR_COLUMN_ACCOUNT, &account, | |
738 STATUS_EDITOR_COLUMN_ENABLE_SUBSTATUS, &enabled, | |
739 STATUS_EDITOR_COLUMN_STATUS_ID, &id, | |
740 STATUS_EDITOR_COLUMN_STATUS_MESSAGE, &message, | |
741 -1); | |
742 if (enabled) | |
743 { | |
744 type = gaim_account_get_status_type(account, id); | |
745 gaim_savedstatus_set_substatus(saved_status, account, type, message); | |
746 } | |
747 g_free(id); | |
748 g_free(message); | |
749 } | |
750 } | |
751 | |
10420 | 752 g_free(message); |
753 g_free(unformatted); | |
754 | |
755 gtk_widget_destroy(dialog->window); | |
10574 | 756 g_free(dialog->original_title); |
10420 | 757 g_free(dialog); |
758 | |
12080 | 759 if (status_window != NULL) |
12199 | 760 add_status_to_saved_status_list(status_window->model, saved_status); |
12329 | 761 |
13010 | 762 /* If they clicked on "Save & Use" or "Use," then activate the status */ |
763 if (button != dialog->save_button) | |
12329 | 764 gaim_savedstatus_activate(saved_status); |
10420 | 765 } |
766 | |
767 static void | |
768 editor_title_changed_cb(GtkWidget *widget, gpointer user_data) | |
769 { | |
770 StatusEditor *dialog = user_data; | |
771 const gchar *text; | |
772 | |
773 text = gtk_entry_get_text(dialog->title); | |
774 | |
12329 | 775 gtk_widget_set_sensitive(GTK_WIDGET(dialog->saveanduse_button), (*text != '\0')); |
776 gtk_widget_set_sensitive(GTK_WIDGET(dialog->save_button), (*text != '\0')); | |
10418 | 777 } |
778 | |
779 static GtkWidget * | |
10419 | 780 create_status_type_menu(GaimStatusPrimitive type) |
10418 | 781 { |
10419 | 782 int i; |
10418 | 783 GtkWidget *dropdown; |
784 GtkWidget *menu; | |
785 GtkWidget *item; | |
786 | |
787 dropdown = gtk_option_menu_new(); | |
788 menu = gtk_menu_new(); | |
789 | |
12693
07d6cc1b5a98
[gaim-migrate @ 15036]
Richard Laager <rlaager@wiktel.com>
parents:
12329
diff
changeset
|
790 for (i = GAIM_STATUS_UNSET + 1; i < GAIM_STATUS_NUM_PRIMITIVES; i++) |
10419 | 791 { |
792 item = gtk_menu_item_new_with_label(gaim_primitive_get_name_from_type(i)); | |
793 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); | |
794 gtk_widget_show(item); | |
795 } | |
10418 | 796 |
12693
07d6cc1b5a98
[gaim-migrate @ 15036]
Richard Laager <rlaager@wiktel.com>
parents:
12329
diff
changeset
|
797 gtk_menu_set_active(GTK_MENU(menu), type - (GAIM_STATUS_UNSET + 1)); |
10418 | 798 gtk_option_menu_set_menu(GTK_OPTION_MENU(dropdown), menu); |
799 gtk_widget_show(menu); | |
800 | |
801 return dropdown; | |
802 } | |
803 | |
12080 | 804 static void edit_substatus(StatusEditor *status_editor, GaimAccount *account); |
805 | |
806 static void | |
807 edit_substatus_cb(GtkTreeView *tv, GtkTreePath *path, GtkTreeViewColumn *col, gpointer user_data) | |
808 { | |
809 StatusEditor *dialog = user_data; | |
810 GtkTreeIter iter; | |
811 GaimAccount *account; | |
812 | |
813 gtk_tree_model_get_iter(GTK_TREE_MODEL(dialog->model), &iter, path); | |
814 gtk_tree_model_get(GTK_TREE_MODEL(dialog->model), &iter, | |
815 STATUS_EDITOR_COLUMN_ACCOUNT, &account, | |
816 -1); | |
817 | |
818 edit_substatus(dialog, account); | |
819 } | |
820 | |
821 static void | |
822 status_editor_substatus_cb(GtkCellRendererToggle *renderer, gchar *path_str, gpointer data) | |
823 { | |
824 StatusEditor *dialog = (StatusEditor *)data; | |
825 GtkTreeIter iter; | |
826 gboolean enabled; | |
827 GaimAccount *account; | |
828 | |
829 gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(dialog->model), &iter, path_str); | |
830 gtk_tree_model_get(GTK_TREE_MODEL(dialog->model), &iter, | |
831 STATUS_EDITOR_COLUMN_ACCOUNT, &account, | |
832 STATUS_EDITOR_COLUMN_ENABLE_SUBSTATUS, &enabled, | |
833 -1); | |
834 | |
835 enabled = !enabled; | |
836 | |
837 if (enabled) | |
838 { | |
839 edit_substatus(dialog, account); | |
840 } | |
841 else | |
842 { | |
843 GaimSavedStatus *saved_status; | |
844 | |
845 /* Remove the substatus */ | |
846 saved_status = gaim_savedstatus_find(dialog->original_title); | |
847 gaim_savedstatus_unset_substatus(saved_status, account); | |
848 gtk_list_store_set(dialog->model, &iter, | |
849 STATUS_EDITOR_COLUMN_ENABLE_SUBSTATUS, enabled, | |
850 STATUS_EDITOR_COLUMN_STATUS_ID, NULL, | |
851 STATUS_EDITOR_COLUMN_STATUS_NAME, NULL, | |
852 STATUS_EDITOR_COLUMN_STATUS_MESSAGE, NULL, | |
853 -1); | |
854 } | |
855 } | |
856 | |
10418 | 857 static void |
858 status_editor_add_columns(StatusEditor *dialog) | |
859 { | |
860 GtkCellRenderer *renderer; | |
861 GtkTreeViewColumn *column; | |
862 | |
12080 | 863 /* Enable Different status column */ |
10418 | 864 renderer = gtk_cell_renderer_toggle_new(); |
865 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(dialog->treeview), | |
12080 | 866 -1, _("Different"), |
10418 | 867 renderer, |
12080 | 868 "active", STATUS_EDITOR_COLUMN_ENABLE_SUBSTATUS, |
10418 | 869 NULL); |
870 column = gtk_tree_view_get_column(GTK_TREE_VIEW(dialog->treeview), 1); | |
871 g_signal_connect(G_OBJECT(renderer), "toggled", | |
12080 | 872 G_CALLBACK(status_editor_substatus_cb), dialog); |
10418 | 873 |
874 /* Screen Name column */ | |
875 column = gtk_tree_view_column_new(); | |
876 gtk_tree_view_column_set_resizable(column, TRUE); | |
877 gtk_tree_view_column_set_title(column, _("Screen Name")); | |
878 gtk_tree_view_insert_column(GTK_TREE_VIEW(dialog->treeview), column, -1); | |
879 gtk_tree_view_column_set_resizable(column, TRUE); | |
880 | |
881 /* Icon */ | |
882 renderer = gtk_cell_renderer_pixbuf_new(); | |
883 gtk_tree_view_column_pack_start(column, renderer, FALSE); | |
884 gtk_tree_view_column_add_attribute(column, renderer, "pixbuf", | |
885 STATUS_EDITOR_COLUMN_ICON); | |
886 | |
887 /* Screen Name */ | |
888 renderer = gtk_cell_renderer_text_new(); | |
889 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
890 gtk_tree_view_column_add_attribute(column, renderer, "text", | |
891 STATUS_EDITOR_COLUMN_SCREENNAME); | |
12080 | 892 |
893 /* Status column */ | |
894 column = gtk_tree_view_column_new(); | |
895 gtk_tree_view_column_set_resizable(column, TRUE); | |
896 gtk_tree_view_column_set_title(column, _("Status")); | |
897 gtk_tree_view_insert_column(GTK_TREE_VIEW(dialog->treeview), column, -1); | |
898 gtk_tree_view_column_set_resizable(column, TRUE); | |
899 renderer = gtk_cell_renderer_text_new(); | |
900 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
901 gtk_tree_view_column_add_attribute(column, renderer, "text", | |
902 STATUS_EDITOR_COLUMN_STATUS_NAME); | |
903 | |
904 /* Message column */ | |
905 column = gtk_tree_view_column_new(); | |
906 gtk_tree_view_column_set_resizable(column, TRUE); | |
907 gtk_tree_view_column_set_title(column, _("Message")); | |
908 gtk_tree_view_insert_column(GTK_TREE_VIEW(dialog->treeview), column, -1); | |
909 gtk_tree_view_column_set_resizable(column, TRUE); | |
910 renderer = gtk_cell_renderer_text_new(); | |
911 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
912 gtk_tree_view_column_add_attribute(column, renderer, "text", | |
913 STATUS_EDITOR_COLUMN_STATUS_MESSAGE); | |
914 | |
915 g_signal_connect(G_OBJECT(dialog->treeview), "row-activated", | |
916 G_CALLBACK(edit_substatus_cb), dialog); | |
10418 | 917 } |
918 | |
919 static void | |
12080 | 920 status_editor_set_account(GtkListStore *store, GaimAccount *account, |
921 GtkTreeIter *iter, GaimSavedStatusSub *substatus) | |
10418 | 922 { |
923 GdkPixbuf *pixbuf; | |
12080 | 924 const char *id = NULL, *name = NULL, *message = NULL; |
10418 | 925 |
13090 | 926 pixbuf = gaim_gtk_create_prpl_icon(account, 0.5); |
927 if ((pixbuf != NULL) && !gaim_account_is_connected(account)) | |
10418 | 928 { |
13090 | 929 gdk_pixbuf_saturate_and_pixelate(pixbuf, pixbuf, 0.0, FALSE); |
10418 | 930 } |
931 | |
12080 | 932 if (substatus != NULL) |
933 { | |
934 const GaimStatusType *type; | |
935 | |
936 type = gaim_savedstatus_substatus_get_type(substatus); | |
937 id = gaim_status_type_get_id(type); | |
938 name = gaim_status_type_get_name(type); | |
939 if (gaim_status_type_get_attr(type, "message")) | |
940 message = gaim_savedstatus_substatus_get_message(substatus); | |
941 } | |
942 | |
10418 | 943 gtk_list_store_set(store, iter, |
12080 | 944 STATUS_EDITOR_COLUMN_ACCOUNT, account, |
945 STATUS_EDITOR_COLUMN_ENABLE_SUBSTATUS, (substatus != NULL), | |
13090 | 946 STATUS_EDITOR_COLUMN_ICON, pixbuf, |
10418 | 947 STATUS_EDITOR_COLUMN_SCREENNAME, gaim_account_get_username(account), |
12080 | 948 STATUS_EDITOR_COLUMN_STATUS_ID, id, |
949 STATUS_EDITOR_COLUMN_STATUS_NAME, name, | |
950 STATUS_EDITOR_COLUMN_STATUS_MESSAGE, message, | |
10418 | 951 -1); |
952 | |
13090 | 953 if (pixbuf != NULL) |
954 g_object_unref(G_OBJECT(pixbuf)); | |
10418 | 955 } |
956 | |
957 static void | |
12080 | 958 status_editor_add_account(StatusEditor *dialog, GaimAccount *account, |
959 GaimSavedStatusSub *substatus) | |
10418 | 960 { |
961 GtkTreeIter iter; | |
962 | |
963 gtk_list_store_append(dialog->model, &iter); | |
964 | |
12080 | 965 status_editor_set_account(dialog->model, account, &iter, substatus); |
10418 | 966 } |
967 | |
968 static void | |
12080 | 969 status_editor_populate_list(StatusEditor *dialog, GaimSavedStatus *saved_status) |
10418 | 970 { |
12080 | 971 GList *iter; |
972 GaimSavedStatusSub *substatus; | |
10418 | 973 |
974 gtk_list_store_clear(dialog->model); | |
975 | |
12080 | 976 for (iter = gaim_accounts_get_all(); iter != NULL; iter = iter->next) |
977 { | |
978 GaimAccount *account = (GaimAccount *)iter->data; | |
979 | |
980 if (saved_status != NULL) | |
981 substatus = gaim_savedstatus_get_substatus(saved_status, account); | |
982 else | |
983 substatus = NULL; | |
984 | |
985 status_editor_add_account(dialog, account, substatus); | |
986 } | |
10418 | 987 } |
988 | |
989 void | |
12080 | 990 gaim_gtk_status_editor_show(GaimSavedStatus *saved_status) |
10418 | 991 { |
992 StatusEditor *dialog; | |
993 GtkSizeGroup *sg; | |
994 GtkWidget *bbox; | |
995 GtkWidget *button; | |
996 GtkWidget *dbox; | |
11735 | 997 GtkWidget *expander; |
10418 | 998 GtkWidget *dropdown; |
999 GtkWidget *entry; | |
1000 GtkWidget *frame; | |
1001 GtkWidget *hbox; | |
1002 GtkWidget *label; | |
1003 GtkWidget *sw; | |
1004 GtkWidget *text; | |
1005 GtkWidget *toolbar; | |
1006 GtkWidget *vbox; | |
1007 GtkWidget *win; | |
1008 | |
1009 dialog = g_new0(StatusEditor, 1); | |
1010 | |
12080 | 1011 if (saved_status != NULL) |
1012 dialog->original_title = g_strdup(gaim_savedstatus_get_title(saved_status)); | |
10420 | 1013 |
10418 | 1014 dialog->window = win = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
1015 gtk_window_set_role(GTK_WINDOW(win), "status"); | |
1016 gtk_window_set_title(GTK_WINDOW(win), _("Status")); | |
1017 gtk_window_set_resizable(GTK_WINDOW(win), FALSE); | |
11243 | 1018 gtk_container_set_border_width(GTK_CONTAINER(win), GAIM_HIG_BORDER); |
10418 | 1019 |
1020 g_signal_connect(G_OBJECT(win), "delete_event", | |
1021 G_CALLBACK(status_editor_destroy_cb), dialog); | |
1022 | |
1023 /* Setup the vbox */ | |
11243 | 1024 vbox = gtk_vbox_new(FALSE, GAIM_HIG_BORDER); |
10418 | 1025 gtk_container_add(GTK_CONTAINER(win), vbox); |
1026 gtk_widget_show(vbox); | |
1027 | |
1028 sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); | |
1029 | |
1030 /* Title */ | |
11243 | 1031 hbox = gtk_hbox_new(FALSE, GAIM_HIG_BOX_SPACE); |
10418 | 1032 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); |
1033 gtk_widget_show(hbox); | |
1034 | |
1035 label = gtk_label_new_with_mnemonic(_("_Title:")); | |
1036 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
1037 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
1038 gtk_widget_show(label); | |
1039 gtk_size_group_add_widget(sg, label); | |
1040 | |
1041 entry = gtk_entry_new(); | |
10420 | 1042 dialog->title = GTK_ENTRY(entry); |
12080 | 1043 if (dialog->original_title != NULL) |
10420 | 1044 gtk_entry_set_text(GTK_ENTRY(entry), dialog->original_title); |
10418 | 1045 gtk_box_pack_start(GTK_BOX(hbox), entry, TRUE, TRUE, 0); |
1046 gtk_widget_show(entry); | |
10420 | 1047 g_signal_connect(G_OBJECT(entry), "changed", |
1048 G_CALLBACK(editor_title_changed_cb), dialog); | |
10418 | 1049 |
1050 /* Status type */ | |
11243 | 1051 hbox = gtk_hbox_new(FALSE, GAIM_HIG_BOX_SPACE); |
10418 | 1052 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); |
1053 gtk_widget_show(hbox); | |
1054 | |
1055 label = gtk_label_new_with_mnemonic(_("_Status:")); | |
1056 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
1057 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
1058 gtk_widget_show(label); | |
1059 gtk_size_group_add_widget(sg, label); | |
1060 | |
12080 | 1061 if (saved_status != NULL) |
1062 dropdown = create_status_type_menu(gaim_savedstatus_get_type(saved_status)); | |
10419 | 1063 else |
1064 dropdown = create_status_type_menu(GAIM_STATUS_AWAY); | |
10420 | 1065 dialog->type = GTK_OPTION_MENU(dropdown); |
10418 | 1066 gtk_box_pack_start(GTK_BOX(hbox), dropdown, TRUE, TRUE, 0); |
1067 gtk_widget_show(dropdown); | |
1068 | |
1069 /* Status message */ | |
11243 | 1070 hbox = gtk_hbox_new(FALSE, GAIM_HIG_BOX_SPACE); |
10418 | 1071 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); |
1072 gtk_widget_show(hbox); | |
1073 | |
1074 label = gtk_label_new_with_mnemonic(_("_Message:")); | |
1075 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
1076 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
1077 gtk_widget_show(label); | |
1078 gtk_size_group_add_widget(sg, label); | |
1079 | |
1080 frame = gaim_gtk_create_imhtml(TRUE, &text, &toolbar); | |
10420 | 1081 dialog->message = GTK_IMHTML(text); |
10418 | 1082 gtk_box_pack_start(GTK_BOX(hbox), frame, TRUE, TRUE, 0); |
1083 gtk_widget_show(frame); | |
1084 | |
12080 | 1085 if ((saved_status != NULL) && (gaim_savedstatus_get_message(saved_status) != NULL)) |
10419 | 1086 gtk_imhtml_append_text(GTK_IMHTML(text), |
12080 | 1087 gaim_savedstatus_get_message(saved_status), 0); |
10419 | 1088 |
12080 | 1089 /* Different status message expander */ |
11735 | 1090 expander = gtk_expander_new_with_mnemonic(_("Use a _different status for some accounts")); |
1091 gtk_box_pack_start(GTK_BOX(vbox), expander, FALSE, FALSE, 0); | |
1092 gtk_widget_show(expander); | |
10418 | 1093 |
11735 | 1094 /* Setup the box that the expander will cover */ |
11243 | 1095 dbox = gtk_vbox_new(FALSE, GAIM_HIG_CAT_SPACE); |
11735 | 1096 gtk_container_add(GTK_CONTAINER(expander), dbox); |
1097 gtk_widget_show(dbox); | |
10418 | 1098 |
12080 | 1099 /* Different status message treeview */ |
10418 | 1100 sw = gtk_scrolled_window_new(NULL, NULL); |
1101 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), | |
1102 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); | |
1103 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), | |
1104 GTK_SHADOW_IN); | |
1105 gtk_box_pack_start(GTK_BOX(dbox), sw, TRUE, TRUE, 0); | |
1106 gtk_widget_show(sw); | |
1107 | |
1108 /* Create the list model */ | |
1109 dialog->model = gtk_list_store_new(STATUS_EDITOR_NUM_COLUMNS, | |
12080 | 1110 G_TYPE_POINTER, |
10418 | 1111 G_TYPE_BOOLEAN, |
12080 | 1112 GDK_TYPE_PIXBUF, |
1113 G_TYPE_STRING, | |
1114 G_TYPE_STRING, | |
1115 G_TYPE_STRING, | |
1116 G_TYPE_STRING); | |
10418 | 1117 |
1118 /* Create the treeview */ | |
1119 dialog->treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(dialog->model)); | |
1120 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(dialog->treeview), TRUE); | |
1121 gtk_widget_set_size_request(dialog->treeview, 400, 250); | |
1122 gtk_container_add(GTK_CONTAINER(sw), dialog->treeview); | |
1123 gtk_widget_show(dialog->treeview); | |
1124 | |
1125 /* Add columns */ | |
1126 status_editor_add_columns(dialog); | |
1127 | |
1128 /* Populate list */ | |
12080 | 1129 status_editor_populate_list(dialog, saved_status); |
10418 | 1130 |
1131 /* Button box */ | |
1132 bbox = gtk_hbutton_box_new(); | |
11243 | 1133 gtk_box_set_spacing(GTK_BOX(bbox), GAIM_HIG_BOX_SPACE); |
10418 | 1134 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); |
1135 gtk_box_pack_end(GTK_BOX(vbox), bbox, FALSE, TRUE, 0); | |
1136 gtk_widget_show(bbox); | |
1137 | |
1138 /* Cancel button */ | |
1139 button = gtk_button_new_from_stock(GTK_STOCK_CANCEL); | |
1140 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
1141 gtk_widget_show(button); | |
1142 | |
1143 g_signal_connect(G_OBJECT(button), "clicked", | |
1144 G_CALLBACK(status_editor_cancel_cb), dialog); | |
1145 | |
12329 | 1146 /* Use button */ |
1147 button = gaim_pixbuf_button_from_stock(_("_Use"), GTK_STOCK_EXECUTE, | |
1148 GAIM_BUTTON_HORIZONTAL); | |
10418 | 1149 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); |
12329 | 1150 gtk_widget_show(button); |
1151 | |
1152 g_signal_connect(G_OBJECT(button), "clicked", | |
1153 G_CALLBACK(status_editor_ok_cb), dialog); | |
1154 | |
1155 /* Save & Use button */ | |
1156 button = gaim_pixbuf_button_from_stock(_("Sa_ve & Use"), GTK_STOCK_OK, | |
1157 GAIM_BUTTON_HORIZONTAL); | |
1158 dialog->saveanduse_button = GTK_BUTTON(button); | |
1159 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
1160 if (dialog->original_title == NULL) | |
12080 | 1161 gtk_widget_set_sensitive(button, FALSE); |
10418 | 1162 gtk_widget_show(button); |
1163 | |
1164 g_signal_connect(G_OBJECT(button), "clicked", | |
12329 | 1165 G_CALLBACK(status_editor_ok_cb), dialog); |
1166 | |
1167 /* Save button */ | |
1168 button = gtk_button_new_from_stock(GTK_STOCK_SAVE); | |
1169 dialog->save_button = GTK_BUTTON(button); | |
1170 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
1171 if (dialog->original_title == NULL) | |
1172 gtk_widget_set_sensitive(button, FALSE); | |
1173 gtk_widget_show(button); | |
1174 | |
1175 g_signal_connect(G_OBJECT(button), "clicked", | |
1176 G_CALLBACK(status_editor_ok_cb), dialog); | |
10418 | 1177 |
1178 gtk_widget_show(win); | |
1179 } | |
1180 | |
1181 | |
10421 | 1182 /************************************************************************** |
12080 | 1183 * SubStatus editor |
1184 **************************************************************************/ | |
1185 | |
1186 static void | |
1187 substatus_selection_changed_cb(GtkComboBox *box, gpointer user_data) | |
1188 { | |
1189 SubStatusEditor *select = user_data; | |
1190 GtkTreeIter iter; | |
1191 GaimAccount *account; | |
1192 char *id; | |
1193 GaimStatusType *type; | |
1194 | |
1195 if (!gtk_combo_box_get_active_iter(box, &iter)) | |
1196 return; | |
1197 gtk_tree_model_get(GTK_TREE_MODEL(select->model), &iter, | |
1198 SUBSTATUS_COLUMN_ACCOUNT, &account, | |
1199 SUBSTATUS_COLUMN_STATUS_ID, &id, | |
1200 -1); | |
1201 type = gaim_account_get_status_type(account, id); | |
1202 g_free(id); | |
1203 | |
1204 if (gaim_status_type_get_attr(type, "message") == NULL) | |
1205 { | |
1206 gtk_widget_set_sensitive(GTK_WIDGET(select->message), FALSE); | |
1207 gtk_widget_set_sensitive(GTK_WIDGET(select->toolbar), FALSE); | |
1208 } | |
1209 else | |
1210 { | |
1211 gtk_widget_set_sensitive(GTK_WIDGET(select->message), TRUE); | |
1212 gtk_widget_set_sensitive(GTK_WIDGET(select->toolbar), TRUE); | |
1213 } | |
1214 } | |
1215 | |
1216 static gboolean | |
1217 substatus_editor_destroy_cb(GtkWidget *widget, GdkEvent *event, gpointer user_data) | |
1218 { | |
1219 SubStatusEditor *dialog = user_data; | |
1220 | |
1221 g_free(dialog); | |
1222 | |
1223 return FALSE; | |
1224 } | |
1225 | |
12246 | 1226 static void |
12080 | 1227 substatus_editor_cancel_cb(GtkButton *button, gpointer user_data) |
1228 { | |
1229 SubStatusEditor *dialog = user_data; | |
1230 | |
1231 gtk_widget_destroy(dialog->window); | |
1232 | |
1233 g_free(dialog); | |
1234 } | |
1235 | |
1236 static gboolean | |
1237 status_editor_find_account_in_treemodel(GtkTreeIter *iter, | |
1238 StatusEditor *status_editor, | |
1239 GaimAccount *account) | |
1240 { | |
1241 GtkTreeModel *model; | |
1242 GaimAccount *cur; | |
1243 | |
1244 g_return_val_if_fail(status_editor != NULL, FALSE); | |
1245 g_return_val_if_fail(account != NULL, FALSE); | |
1246 | |
1247 model = GTK_TREE_MODEL(status_editor->model); | |
1248 | |
1249 if (!gtk_tree_model_get_iter_first(model, iter)) | |
1250 return FALSE; | |
1251 | |
1252 gtk_tree_model_get(model, iter, STATUS_EDITOR_COLUMN_ACCOUNT, &cur, -1); | |
1253 if (cur == account) | |
1254 return TRUE; | |
1255 | |
1256 while (gtk_tree_model_iter_next(model, iter)) | |
1257 { | |
1258 gtk_tree_model_get(model, iter, STATUS_EDITOR_COLUMN_ACCOUNT, &cur, -1); | |
1259 if (cur == account) | |
1260 return TRUE; | |
1261 } | |
1262 | |
1263 return FALSE; | |
1264 } | |
1265 | |
12246 | 1266 static void |
12080 | 1267 substatus_editor_ok_cb(GtkButton *button, gpointer user_data) |
1268 { | |
1269 SubStatusEditor *dialog = user_data; | |
1270 StatusEditor *status_editor; | |
1271 GtkTreeIter iter; | |
1272 GaimAccount *account; | |
1273 GaimStatusType *type; | |
1274 char *id = NULL; | |
1275 char *message = NULL; | |
1276 const char *name = NULL; | |
1277 | |
12856
be1cd5952a48
[gaim-migrate @ 15207]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12823
diff
changeset
|
1278 if (!gtk_combo_box_get_active_iter(dialog->box, &iter)) { |
be1cd5952a48
[gaim-migrate @ 15207]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12823
diff
changeset
|
1279 gtk_widget_destroy(dialog->window); |
be1cd5952a48
[gaim-migrate @ 15207]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12823
diff
changeset
|
1280 g_free(dialog); |
be1cd5952a48
[gaim-migrate @ 15207]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12823
diff
changeset
|
1281 return; |
be1cd5952a48
[gaim-migrate @ 15207]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12823
diff
changeset
|
1282 } |
be1cd5952a48
[gaim-migrate @ 15207]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12823
diff
changeset
|
1283 |
12080 | 1284 gtk_tree_model_get(GTK_TREE_MODEL(dialog->model), &iter, |
1285 SUBSTATUS_COLUMN_ACCOUNT, &account, | |
1286 SUBSTATUS_COLUMN_STATUS_ID, &id, | |
1287 -1); | |
1288 type = gaim_account_get_status_type(account, id); | |
1289 if (gaim_status_type_get_attr(type, "message") != NULL) | |
1290 message = gtk_imhtml_get_text(GTK_IMHTML(dialog->message), NULL, NULL); | |
1291 name = gaim_status_type_get_name(type); | |
1292 | |
1293 status_editor = dialog->status_editor; | |
1294 | |
1295 if (status_editor_find_account_in_treemodel(&iter, status_editor, account)) | |
1296 { | |
1297 gtk_list_store_set(status_editor->model, &iter, | |
1298 STATUS_EDITOR_COLUMN_ENABLE_SUBSTATUS, TRUE, | |
1299 STATUS_EDITOR_COLUMN_STATUS_ID, id, | |
1300 STATUS_EDITOR_COLUMN_STATUS_NAME, name, | |
1301 STATUS_EDITOR_COLUMN_STATUS_MESSAGE, message, | |
1302 -1); | |
1303 } | |
1304 | |
1305 gtk_widget_destroy(dialog->window); | |
1306 g_free(id); | |
1307 g_free(message); | |
1308 g_free(dialog); | |
1309 } | |
1310 | |
1311 static void | |
1312 edit_substatus(StatusEditor *status_editor, GaimAccount *account) | |
1313 { | |
1314 char *tmp; | |
1315 SubStatusEditor *dialog; | |
1316 GtkSizeGroup *sg; | |
1317 GtkWidget *bbox; | |
1318 GtkWidget *button; | |
1319 GtkWidget *combo; | |
1320 GtkWidget *hbox; | |
1321 GtkWidget *frame; | |
1322 GtkWidget *label; | |
1323 GtkWidget *text; | |
1324 GtkWidget *toolbar; | |
1325 GtkWidget *vbox; | |
1326 GtkWidget *win; | |
1327 GtkTreeIter iter; | |
1328 GtkCellRenderer *rend; | |
1329 const char *id = NULL; | |
1330 const GList *list; | |
1331 gboolean select = FALSE; | |
1332 | |
1333 g_return_if_fail(status_editor != NULL); | |
1334 g_return_if_fail(account != NULL); | |
1335 | |
1336 dialog = g_new0(SubStatusEditor, 1); | |
1337 dialog->status_editor = status_editor; | |
1338 | |
1339 dialog->window = win = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
1340 gtk_window_set_role(GTK_WINDOW(win), "substatus"); | |
1341 tmp = g_strdup_printf(_("Status for %s"), gaim_account_get_username(account)); | |
1342 gtk_window_set_title(GTK_WINDOW(win), tmp); | |
1343 g_free(tmp); | |
1344 gtk_window_set_resizable(GTK_WINDOW(win), FALSE); | |
1345 gtk_container_set_border_width(GTK_CONTAINER(win), GAIM_HIG_BORDER); | |
1346 | |
1347 g_signal_connect(G_OBJECT(win), "delete_event", | |
1348 G_CALLBACK(substatus_editor_destroy_cb), dialog); | |
1349 | |
1350 /* Setup the vbox */ | |
1351 vbox = gtk_vbox_new(FALSE, GAIM_HIG_BORDER); | |
1352 gtk_container_add(GTK_CONTAINER(win), vbox); | |
1353 gtk_widget_show(vbox); | |
1354 | |
1355 sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); | |
1356 | |
1357 /* Status type */ | |
1358 hbox = gtk_hbox_new(FALSE, GAIM_HIG_BOX_SPACE); | |
1359 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
1360 gtk_widget_show(hbox); | |
1361 | |
1362 label = gtk_label_new_with_mnemonic(_("_Status:")); | |
1363 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
1364 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
1365 gtk_widget_show(label); | |
1366 gtk_size_group_add_widget(sg, label); | |
1367 | |
1368 dialog->model = gtk_list_store_new(SUBSTATUS_NUM_COLUMNS, | |
1369 G_TYPE_POINTER, | |
1370 GDK_TYPE_PIXBUF, | |
1371 G_TYPE_STRING, | |
1372 G_TYPE_STRING); | |
1373 combo = gtk_combo_box_new_with_model(GTK_TREE_MODEL(dialog->model)); | |
1374 dialog->box = GTK_COMBO_BOX(combo); | |
1375 | |
1376 rend = GTK_CELL_RENDERER(gtk_cell_renderer_pixbuf_new()); | |
1377 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), rend, FALSE); | |
1378 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), rend, | |
1379 "pixbuf", SUBSTATUS_COLUMN_ICON, NULL); | |
1380 | |
1381 rend = GTK_CELL_RENDERER(gtk_cell_renderer_text_new()); | |
1382 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), rend, TRUE); | |
1383 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), rend, | |
1384 "text", SUBSTATUS_COLUMN_STATUS_NAME, NULL); | |
1385 | |
1386 g_signal_connect(G_OBJECT(combo), "changed", | |
1387 G_CALLBACK(substatus_selection_changed_cb), dialog); | |
1388 | |
1389 gtk_box_pack_start(GTK_BOX(hbox), combo, FALSE, FALSE, 0); | |
1390 gtk_widget_show(combo); | |
1391 | |
1392 /* Status mesage */ | |
1393 hbox = gtk_hbox_new(FALSE, GAIM_HIG_BOX_SPACE); | |
1394 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
1395 gtk_widget_show(hbox); | |
1396 | |
1397 label = gtk_label_new_with_mnemonic(_("_Message:")); | |
1398 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
1399 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
1400 gtk_widget_show(label); | |
1401 gtk_size_group_add_widget(sg, label); | |
1402 | |
1403 frame = gaim_gtk_create_imhtml(TRUE, &text, &toolbar); | |
1404 dialog->message = GTK_IMHTML(text); | |
1405 dialog->toolbar = GTK_IMHTMLTOOLBAR(toolbar); | |
1406 gtk_box_pack_start(GTK_BOX(hbox), frame, TRUE, TRUE, 0); | |
1407 gtk_widget_show(frame); | |
1408 | |
1409 /* Button box */ | |
1410 bbox = gtk_hbutton_box_new(); | |
1411 gtk_box_set_spacing(GTK_BOX(bbox), GAIM_HIG_BOX_SPACE); | |
1412 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); | |
1413 gtk_box_pack_end(GTK_BOX(vbox), bbox, FALSE, TRUE, 0); | |
1414 gtk_widget_show(bbox); | |
1415 | |
1416 /* Cancel button */ | |
1417 button = gtk_button_new_from_stock(GTK_STOCK_CANCEL); | |
1418 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
1419 gtk_widget_show(button); | |
1420 | |
1421 g_signal_connect(G_OBJECT(button), "clicked", | |
1422 G_CALLBACK(substatus_editor_cancel_cb), dialog); | |
1423 | |
1424 /* OK button */ | |
1425 button = gtk_button_new_from_stock(GTK_STOCK_OK); | |
1426 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
1427 gtk_widget_show(button); | |
1428 | |
1429 g_signal_connect(G_OBJECT(button), "clicked", | |
1430 G_CALLBACK(substatus_editor_ok_cb), dialog); | |
1431 | |
1432 /* Seed the input widgets with the current values */ | |
1433 /* TODO: Get the current values from our parent's list store, not the saved_status! */ | |
1434 if (status_editor->original_title != NULL) | |
1435 { | |
1436 GaimSavedStatus *saved_status = NULL; | |
1437 GaimSavedStatusSub *substatus = NULL; | |
1438 | |
1439 saved_status = gaim_savedstatus_find(status_editor->original_title); | |
1440 if (saved_status != NULL) | |
1441 substatus = gaim_savedstatus_get_substatus(saved_status, account); | |
1442 | |
1443 if (substatus != NULL) | |
1444 { | |
1445 gtk_imhtml_append_text(dialog->message, | |
1446 gaim_savedstatus_substatus_get_message(substatus), | |
1447 0); | |
1448 id = gaim_status_type_get_id(gaim_savedstatus_substatus_get_type(substatus)); | |
1449 } | |
1450 } | |
1451 | |
1452 for (list = gaim_account_get_status_types(account); list; list = list->next) | |
1453 { | |
1454 GaimStatusType *status_type; | |
13090 | 1455 GdkPixbuf *pixbuf; |
12080 | 1456 const char *id, *name; |
1457 | |
1458 status_type = list->data; | |
13010 | 1459 |
1460 /* Only allow users to select statuses that are flagged as "user settable" */ | |
1461 if (!gaim_status_type_is_user_settable(status_type)) | |
1462 continue; | |
1463 | |
12080 | 1464 id = gaim_status_type_get_id(status_type); |
13090 | 1465 pixbuf = gaim_gtk_create_prpl_icon_with_status(account, status_type, 0.5); |
12080 | 1466 name = gaim_status_type_get_name(status_type); |
1467 | |
1468 gtk_list_store_append(dialog->model, &iter); | |
1469 gtk_list_store_set(dialog->model, &iter, | |
1470 SUBSTATUS_COLUMN_ACCOUNT, account, | |
13090 | 1471 SUBSTATUS_COLUMN_ICON, pixbuf, |
12080 | 1472 SUBSTATUS_COLUMN_STATUS_ID, id, |
1473 SUBSTATUS_COLUMN_STATUS_NAME, name, | |
1474 -1); | |
13090 | 1475 if (pixbuf != NULL) |
1476 g_object_unref(pixbuf); | |
12080 | 1477 if (id && !strcmp(id, gaim_status_type_get_id(status_type))) |
1478 { | |
1479 gtk_combo_box_set_active_iter(GTK_COMBO_BOX(combo), &iter); | |
1480 select = TRUE; | |
1481 } | |
1482 } | |
1483 | |
1484 if (!select) | |
1485 gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0); | |
1486 | |
1487 gtk_widget_show(win); | |
1488 } | |
1489 | |
12329 | 1490 |
12195 | 1491 /************************************************************************** |
1492 * Utilities * | |
1493 **************************************************************************/ | |
1494 | |
12246 | 1495 static void |
1496 status_menu_cb(GtkComboBox *widget, void(*callback)(GaimSavedStatus*)) | |
12195 | 1497 { |
12237 | 1498 GtkTreeIter iter; |
1499 gchar *title = NULL; | |
1500 | |
1501 if (!gtk_combo_box_get_active_iter(widget, &iter)) | |
1502 return; | |
1503 | |
1504 gtk_tree_model_get(gtk_combo_box_get_model(widget), &iter, | |
1505 STATUS_WINDOW_COLUMN_TITLE, &title, -1); | |
1506 callback(gaim_savedstatus_find(title)); | |
1507 g_free(title); | |
12195 | 1508 } |
1509 | |
12817 | 1510 static gint |
1511 saved_status_sort_alphabetically_func(gconstpointer a, gconstpointer b) | |
1512 { | |
1513 const GaimSavedStatus *saved_status_a = a; | |
1514 const GaimSavedStatus *saved_status_b = b; | |
12823
292a846fdeea
[gaim-migrate @ 15171]
Richard Laager <rlaager@wiktel.com>
parents:
12817
diff
changeset
|
1515 return g_utf8_collate(gaim_savedstatus_get_title(saved_status_a), |
12817 | 1516 gaim_savedstatus_get_title(saved_status_b)); |
1517 } | |
1518 | |
12195 | 1519 GtkWidget *gaim_gtk_status_menu(GaimSavedStatus *current_status, GCallback callback) |
1520 { | |
1521 GtkWidget *combobox; | |
12817 | 1522 GList *sorted, *cur; |
12195 | 1523 int i; |
1524 int index = -1; | |
12329 | 1525 |
12199 | 1526 combobox = gtk_combo_box_new_text(); |
12329 | 1527 |
12817 | 1528 sorted = g_list_copy((GList *)gaim_savedstatuses_get_all()); |
1529 sorted = g_list_sort(sorted, saved_status_sort_alphabetically_func); | |
1530 for (cur = sorted, i = 0; | |
1531 cur != NULL; | |
1532 cur = g_list_next(cur)) | |
12329 | 1533 { |
12817 | 1534 GaimSavedStatus *status = (GaimSavedStatus *)cur->data; |
12199 | 1535 if (!gaim_savedstatus_is_transient(status)) { |
12329 | 1536 gtk_combo_box_append_text(GTK_COMBO_BOX(combobox), |
12199 | 1537 gaim_savedstatus_get_title(status)); |
1538 if (status == current_status) | |
1539 index = i; | |
1540 i++; | |
1541 } | |
12195 | 1542 } |
12817 | 1543 g_list_free(sorted); |
12246 | 1544 |
12195 | 1545 gtk_combo_box_set_active(GTK_COMBO_BOX(combobox), index); |
1546 g_signal_connect(G_OBJECT(combobox), "changed", G_CALLBACK(status_menu_cb), callback); | |
12329 | 1547 |
12195 | 1548 return combobox; |
1549 } | |
1550 | |
12080 | 1551 |
1552 /************************************************************************** | |
10814
364a2ef907ae
[gaim-migrate @ 12468]
Luke Schierer <lschiere@pidgin.im>
parents:
10732
diff
changeset
|
1553 * GTK+ saved status glue |
10421 | 1554 **************************************************************************/ |
10418 | 1555 |
1556 void * | |
13014 | 1557 gaim_gtk_status_get_handle(void) |
10418 | 1558 { |
1559 static int handle; | |
1560 | |
1561 return &handle; | |
1562 } | |
1563 | |
1564 void | |
1565 gaim_gtk_status_init(void) | |
1566 { | |
1567 gaim_prefs_add_none("/gaim/gtk/status"); | |
1568 gaim_prefs_add_none("/gaim/gtk/status/dialog"); | |
1569 gaim_prefs_add_int("/gaim/gtk/status/dialog/width", 550); | |
1570 gaim_prefs_add_int("/gaim/gtk/status/dialog/height", 250); | |
1571 } | |
1572 | |
1573 void | |
1574 gaim_gtk_status_uninit(void) | |
1575 { | |
1576 gaim_gtk_status_window_hide(); | |
1577 } |