Mercurial > pidgin
annotate src/gtksavedstatuses.c @ 12973:e25a2315d9e3
[gaim-migrate @ 15326]
GtkTreeView::indent_expanders is a boolean value not an integer, so change
gaimrc to match. Also fix how changing settings works, all settings should be
instant-apply-on-change for gtk > 2.4, and will either work better or worse
than they did before with gtk < 2.4 (I'm not sure and don't have anywhere to
test.)
committer: Tailor Script <tailor@pidgin.im>
author | Etan Reisner <pidgin@unreliablesource.net> |
---|---|
date | Sat, 21 Jan 2006 00:46:36 +0000 |
parents | 9eaf101af7a7 |
children | e348ed834acc |
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 |
762 if ((button == dialog->saveanduse_button) | |
763 || (button != dialog->save_button)) | |
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; | |
924 GdkPixbuf *scale; | |
12080 | 925 const char *id = NULL, *name = NULL, *message = NULL; |
10418 | 926 |
927 scale = NULL; | |
928 | |
10884 | 929 pixbuf = gaim_gtk_create_prpl_icon(account); |
10418 | 930 |
931 if (pixbuf != NULL) | |
932 { | |
933 scale = gdk_pixbuf_scale_simple(pixbuf, 16, 16, GDK_INTERP_BILINEAR); | |
934 | |
11251 | 935 if (gaim_account_is_disconnected(account)) |
10418 | 936 gdk_pixbuf_saturate_and_pixelate(scale, scale, 0.0, FALSE); |
937 } | |
938 | |
12080 | 939 if (substatus != NULL) |
940 { | |
941 const GaimStatusType *type; | |
942 | |
943 type = gaim_savedstatus_substatus_get_type(substatus); | |
944 id = gaim_status_type_get_id(type); | |
945 name = gaim_status_type_get_name(type); | |
946 if (gaim_status_type_get_attr(type, "message")) | |
947 message = gaim_savedstatus_substatus_get_message(substatus); | |
948 } | |
949 | |
10418 | 950 gtk_list_store_set(store, iter, |
12080 | 951 STATUS_EDITOR_COLUMN_ACCOUNT, account, |
952 STATUS_EDITOR_COLUMN_ENABLE_SUBSTATUS, (substatus != NULL), | |
10418 | 953 STATUS_EDITOR_COLUMN_ICON, scale, |
954 STATUS_EDITOR_COLUMN_SCREENNAME, gaim_account_get_username(account), | |
12080 | 955 STATUS_EDITOR_COLUMN_STATUS_ID, id, |
956 STATUS_EDITOR_COLUMN_STATUS_NAME, name, | |
957 STATUS_EDITOR_COLUMN_STATUS_MESSAGE, message, | |
10418 | 958 -1); |
959 | |
960 if (pixbuf != NULL) g_object_unref(G_OBJECT(pixbuf)); | |
961 if (scale != NULL) g_object_unref(G_OBJECT(scale)); | |
962 } | |
963 | |
964 static void | |
12080 | 965 status_editor_add_account(StatusEditor *dialog, GaimAccount *account, |
966 GaimSavedStatusSub *substatus) | |
10418 | 967 { |
968 GtkTreeIter iter; | |
969 | |
970 gtk_list_store_append(dialog->model, &iter); | |
971 | |
12080 | 972 status_editor_set_account(dialog->model, account, &iter, substatus); |
10418 | 973 } |
974 | |
975 static void | |
12080 | 976 status_editor_populate_list(StatusEditor *dialog, GaimSavedStatus *saved_status) |
10418 | 977 { |
12080 | 978 GList *iter; |
979 GaimSavedStatusSub *substatus; | |
10418 | 980 |
981 gtk_list_store_clear(dialog->model); | |
982 | |
12080 | 983 for (iter = gaim_accounts_get_all(); iter != NULL; iter = iter->next) |
984 { | |
985 GaimAccount *account = (GaimAccount *)iter->data; | |
986 | |
987 if (saved_status != NULL) | |
988 substatus = gaim_savedstatus_get_substatus(saved_status, account); | |
989 else | |
990 substatus = NULL; | |
991 | |
992 status_editor_add_account(dialog, account, substatus); | |
993 } | |
10418 | 994 } |
995 | |
996 void | |
12080 | 997 gaim_gtk_status_editor_show(GaimSavedStatus *saved_status) |
10418 | 998 { |
999 StatusEditor *dialog; | |
1000 GtkSizeGroup *sg; | |
1001 GtkWidget *bbox; | |
1002 GtkWidget *button; | |
1003 GtkWidget *dbox; | |
11735 | 1004 GtkWidget *expander; |
10418 | 1005 GtkWidget *dropdown; |
1006 GtkWidget *entry; | |
1007 GtkWidget *frame; | |
1008 GtkWidget *hbox; | |
1009 GtkWidget *label; | |
1010 GtkWidget *sw; | |
1011 GtkWidget *text; | |
1012 GtkWidget *toolbar; | |
1013 GtkWidget *vbox; | |
1014 GtkWidget *win; | |
1015 | |
1016 dialog = g_new0(StatusEditor, 1); | |
1017 | |
12080 | 1018 if (saved_status != NULL) |
1019 dialog->original_title = g_strdup(gaim_savedstatus_get_title(saved_status)); | |
10420 | 1020 |
10418 | 1021 dialog->window = win = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
1022 gtk_window_set_role(GTK_WINDOW(win), "status"); | |
1023 gtk_window_set_title(GTK_WINDOW(win), _("Status")); | |
1024 gtk_window_set_resizable(GTK_WINDOW(win), FALSE); | |
11243 | 1025 gtk_container_set_border_width(GTK_CONTAINER(win), GAIM_HIG_BORDER); |
10418 | 1026 |
1027 g_signal_connect(G_OBJECT(win), "delete_event", | |
1028 G_CALLBACK(status_editor_destroy_cb), dialog); | |
1029 | |
1030 /* Setup the vbox */ | |
11243 | 1031 vbox = gtk_vbox_new(FALSE, GAIM_HIG_BORDER); |
10418 | 1032 gtk_container_add(GTK_CONTAINER(win), vbox); |
1033 gtk_widget_show(vbox); | |
1034 | |
1035 sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); | |
1036 | |
1037 /* Title */ | |
11243 | 1038 hbox = gtk_hbox_new(FALSE, GAIM_HIG_BOX_SPACE); |
10418 | 1039 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); |
1040 gtk_widget_show(hbox); | |
1041 | |
1042 label = gtk_label_new_with_mnemonic(_("_Title:")); | |
1043 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
1044 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
1045 gtk_widget_show(label); | |
1046 gtk_size_group_add_widget(sg, label); | |
1047 | |
1048 entry = gtk_entry_new(); | |
10420 | 1049 dialog->title = GTK_ENTRY(entry); |
12080 | 1050 if (dialog->original_title != NULL) |
10420 | 1051 gtk_entry_set_text(GTK_ENTRY(entry), dialog->original_title); |
10418 | 1052 gtk_box_pack_start(GTK_BOX(hbox), entry, TRUE, TRUE, 0); |
1053 gtk_widget_show(entry); | |
10420 | 1054 g_signal_connect(G_OBJECT(entry), "changed", |
1055 G_CALLBACK(editor_title_changed_cb), dialog); | |
10418 | 1056 |
1057 /* Status type */ | |
11243 | 1058 hbox = gtk_hbox_new(FALSE, GAIM_HIG_BOX_SPACE); |
10418 | 1059 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); |
1060 gtk_widget_show(hbox); | |
1061 | |
1062 label = gtk_label_new_with_mnemonic(_("_Status:")); | |
1063 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
1064 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
1065 gtk_widget_show(label); | |
1066 gtk_size_group_add_widget(sg, label); | |
1067 | |
12080 | 1068 if (saved_status != NULL) |
1069 dropdown = create_status_type_menu(gaim_savedstatus_get_type(saved_status)); | |
10419 | 1070 else |
1071 dropdown = create_status_type_menu(GAIM_STATUS_AWAY); | |
10420 | 1072 dialog->type = GTK_OPTION_MENU(dropdown); |
10418 | 1073 gtk_box_pack_start(GTK_BOX(hbox), dropdown, TRUE, TRUE, 0); |
1074 gtk_widget_show(dropdown); | |
1075 | |
1076 /* Status message */ | |
11243 | 1077 hbox = gtk_hbox_new(FALSE, GAIM_HIG_BOX_SPACE); |
10418 | 1078 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); |
1079 gtk_widget_show(hbox); | |
1080 | |
1081 label = gtk_label_new_with_mnemonic(_("_Message:")); | |
1082 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
1083 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
1084 gtk_widget_show(label); | |
1085 gtk_size_group_add_widget(sg, label); | |
1086 | |
1087 frame = gaim_gtk_create_imhtml(TRUE, &text, &toolbar); | |
10420 | 1088 dialog->message = GTK_IMHTML(text); |
10418 | 1089 gtk_box_pack_start(GTK_BOX(hbox), frame, TRUE, TRUE, 0); |
1090 gtk_widget_show(frame); | |
1091 | |
12080 | 1092 if ((saved_status != NULL) && (gaim_savedstatus_get_message(saved_status) != NULL)) |
10419 | 1093 gtk_imhtml_append_text(GTK_IMHTML(text), |
12080 | 1094 gaim_savedstatus_get_message(saved_status), 0); |
10419 | 1095 |
12080 | 1096 /* Different status message expander */ |
11735 | 1097 expander = gtk_expander_new_with_mnemonic(_("Use a _different status for some accounts")); |
1098 gtk_box_pack_start(GTK_BOX(vbox), expander, FALSE, FALSE, 0); | |
1099 gtk_widget_show(expander); | |
10418 | 1100 |
11735 | 1101 /* Setup the box that the expander will cover */ |
11243 | 1102 dbox = gtk_vbox_new(FALSE, GAIM_HIG_CAT_SPACE); |
11735 | 1103 gtk_container_add(GTK_CONTAINER(expander), dbox); |
1104 gtk_widget_show(dbox); | |
10418 | 1105 |
12080 | 1106 /* Different status message treeview */ |
10418 | 1107 sw = gtk_scrolled_window_new(NULL, NULL); |
1108 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), | |
1109 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); | |
1110 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), | |
1111 GTK_SHADOW_IN); | |
1112 gtk_box_pack_start(GTK_BOX(dbox), sw, TRUE, TRUE, 0); | |
1113 gtk_widget_show(sw); | |
1114 | |
1115 /* Create the list model */ | |
1116 dialog->model = gtk_list_store_new(STATUS_EDITOR_NUM_COLUMNS, | |
12080 | 1117 G_TYPE_POINTER, |
10418 | 1118 G_TYPE_BOOLEAN, |
12080 | 1119 GDK_TYPE_PIXBUF, |
1120 G_TYPE_STRING, | |
1121 G_TYPE_STRING, | |
1122 G_TYPE_STRING, | |
1123 G_TYPE_STRING); | |
10418 | 1124 |
1125 /* Create the treeview */ | |
1126 dialog->treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(dialog->model)); | |
1127 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(dialog->treeview), TRUE); | |
1128 gtk_widget_set_size_request(dialog->treeview, 400, 250); | |
1129 gtk_container_add(GTK_CONTAINER(sw), dialog->treeview); | |
1130 gtk_widget_show(dialog->treeview); | |
1131 | |
1132 /* Add columns */ | |
1133 status_editor_add_columns(dialog); | |
1134 | |
1135 /* Populate list */ | |
12080 | 1136 status_editor_populate_list(dialog, saved_status); |
10418 | 1137 |
1138 /* Button box */ | |
1139 bbox = gtk_hbutton_box_new(); | |
11243 | 1140 gtk_box_set_spacing(GTK_BOX(bbox), GAIM_HIG_BOX_SPACE); |
10418 | 1141 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); |
1142 gtk_box_pack_end(GTK_BOX(vbox), bbox, FALSE, TRUE, 0); | |
1143 gtk_widget_show(bbox); | |
1144 | |
1145 /* Cancel button */ | |
1146 button = gtk_button_new_from_stock(GTK_STOCK_CANCEL); | |
1147 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
1148 gtk_widget_show(button); | |
1149 | |
1150 g_signal_connect(G_OBJECT(button), "clicked", | |
1151 G_CALLBACK(status_editor_cancel_cb), dialog); | |
1152 | |
12329 | 1153 /* Use button */ |
1154 button = gaim_pixbuf_button_from_stock(_("_Use"), GTK_STOCK_EXECUTE, | |
1155 GAIM_BUTTON_HORIZONTAL); | |
10418 | 1156 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); |
12329 | 1157 gtk_widget_show(button); |
1158 | |
1159 g_signal_connect(G_OBJECT(button), "clicked", | |
1160 G_CALLBACK(status_editor_ok_cb), dialog); | |
1161 | |
1162 /* Save & Use button */ | |
1163 button = gaim_pixbuf_button_from_stock(_("Sa_ve & Use"), GTK_STOCK_OK, | |
1164 GAIM_BUTTON_HORIZONTAL); | |
1165 dialog->saveanduse_button = GTK_BUTTON(button); | |
1166 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
1167 if (dialog->original_title == NULL) | |
12080 | 1168 gtk_widget_set_sensitive(button, FALSE); |
10418 | 1169 gtk_widget_show(button); |
1170 | |
1171 g_signal_connect(G_OBJECT(button), "clicked", | |
12329 | 1172 G_CALLBACK(status_editor_ok_cb), dialog); |
1173 | |
1174 /* Save button */ | |
1175 button = gtk_button_new_from_stock(GTK_STOCK_SAVE); | |
1176 dialog->save_button = GTK_BUTTON(button); | |
1177 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
1178 if (dialog->original_title == NULL) | |
1179 gtk_widget_set_sensitive(button, FALSE); | |
1180 gtk_widget_show(button); | |
1181 | |
1182 g_signal_connect(G_OBJECT(button), "clicked", | |
1183 G_CALLBACK(status_editor_ok_cb), dialog); | |
10418 | 1184 |
1185 gtk_widget_show(win); | |
1186 } | |
1187 | |
1188 | |
10421 | 1189 /************************************************************************** |
12080 | 1190 * SubStatus editor |
1191 **************************************************************************/ | |
1192 | |
1193 static void | |
1194 substatus_selection_changed_cb(GtkComboBox *box, gpointer user_data) | |
1195 { | |
1196 SubStatusEditor *select = user_data; | |
1197 GtkTreeIter iter; | |
1198 GaimAccount *account; | |
1199 char *id; | |
1200 GaimStatusType *type; | |
1201 | |
1202 if (!gtk_combo_box_get_active_iter(box, &iter)) | |
1203 return; | |
1204 gtk_tree_model_get(GTK_TREE_MODEL(select->model), &iter, | |
1205 SUBSTATUS_COLUMN_ACCOUNT, &account, | |
1206 SUBSTATUS_COLUMN_STATUS_ID, &id, | |
1207 -1); | |
1208 type = gaim_account_get_status_type(account, id); | |
1209 g_free(id); | |
1210 | |
1211 if (gaim_status_type_get_attr(type, "message") == NULL) | |
1212 { | |
1213 gtk_widget_set_sensitive(GTK_WIDGET(select->message), FALSE); | |
1214 gtk_widget_set_sensitive(GTK_WIDGET(select->toolbar), FALSE); | |
1215 } | |
1216 else | |
1217 { | |
1218 gtk_widget_set_sensitive(GTK_WIDGET(select->message), TRUE); | |
1219 gtk_widget_set_sensitive(GTK_WIDGET(select->toolbar), TRUE); | |
1220 } | |
1221 } | |
1222 | |
1223 static gboolean | |
1224 substatus_editor_destroy_cb(GtkWidget *widget, GdkEvent *event, gpointer user_data) | |
1225 { | |
1226 SubStatusEditor *dialog = user_data; | |
1227 | |
1228 g_free(dialog); | |
1229 | |
1230 return FALSE; | |
1231 } | |
1232 | |
12246 | 1233 static void |
12080 | 1234 substatus_editor_cancel_cb(GtkButton *button, gpointer user_data) |
1235 { | |
1236 SubStatusEditor *dialog = user_data; | |
1237 | |
1238 gtk_widget_destroy(dialog->window); | |
1239 | |
1240 g_free(dialog); | |
1241 } | |
1242 | |
1243 static gboolean | |
1244 status_editor_find_account_in_treemodel(GtkTreeIter *iter, | |
1245 StatusEditor *status_editor, | |
1246 GaimAccount *account) | |
1247 { | |
1248 GtkTreeModel *model; | |
1249 GaimAccount *cur; | |
1250 | |
1251 g_return_val_if_fail(status_editor != NULL, FALSE); | |
1252 g_return_val_if_fail(account != NULL, FALSE); | |
1253 | |
1254 model = GTK_TREE_MODEL(status_editor->model); | |
1255 | |
1256 if (!gtk_tree_model_get_iter_first(model, iter)) | |
1257 return FALSE; | |
1258 | |
1259 gtk_tree_model_get(model, iter, STATUS_EDITOR_COLUMN_ACCOUNT, &cur, -1); | |
1260 if (cur == account) | |
1261 return TRUE; | |
1262 | |
1263 while (gtk_tree_model_iter_next(model, iter)) | |
1264 { | |
1265 gtk_tree_model_get(model, iter, STATUS_EDITOR_COLUMN_ACCOUNT, &cur, -1); | |
1266 if (cur == account) | |
1267 return TRUE; | |
1268 } | |
1269 | |
1270 return FALSE; | |
1271 } | |
1272 | |
12246 | 1273 static void |
12080 | 1274 substatus_editor_ok_cb(GtkButton *button, gpointer user_data) |
1275 { | |
1276 SubStatusEditor *dialog = user_data; | |
1277 StatusEditor *status_editor; | |
1278 GtkTreeIter iter; | |
1279 GaimAccount *account; | |
1280 GaimStatusType *type; | |
1281 char *id = NULL; | |
1282 char *message = NULL; | |
1283 const char *name = NULL; | |
1284 | |
12856
be1cd5952a48
[gaim-migrate @ 15207]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12823
diff
changeset
|
1285 if (!gtk_combo_box_get_active_iter(dialog->box, &iter)) { |
be1cd5952a48
[gaim-migrate @ 15207]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12823
diff
changeset
|
1286 gtk_widget_destroy(dialog->window); |
be1cd5952a48
[gaim-migrate @ 15207]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12823
diff
changeset
|
1287 g_free(dialog); |
be1cd5952a48
[gaim-migrate @ 15207]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12823
diff
changeset
|
1288 return; |
be1cd5952a48
[gaim-migrate @ 15207]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12823
diff
changeset
|
1289 } |
be1cd5952a48
[gaim-migrate @ 15207]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12823
diff
changeset
|
1290 |
12080 | 1291 gtk_tree_model_get(GTK_TREE_MODEL(dialog->model), &iter, |
1292 SUBSTATUS_COLUMN_ACCOUNT, &account, | |
1293 SUBSTATUS_COLUMN_STATUS_ID, &id, | |
1294 -1); | |
1295 type = gaim_account_get_status_type(account, id); | |
1296 if (gaim_status_type_get_attr(type, "message") != NULL) | |
1297 message = gtk_imhtml_get_text(GTK_IMHTML(dialog->message), NULL, NULL); | |
1298 name = gaim_status_type_get_name(type); | |
1299 | |
1300 status_editor = dialog->status_editor; | |
1301 | |
1302 if (status_editor_find_account_in_treemodel(&iter, status_editor, account)) | |
1303 { | |
1304 gtk_list_store_set(status_editor->model, &iter, | |
1305 STATUS_EDITOR_COLUMN_ENABLE_SUBSTATUS, TRUE, | |
1306 STATUS_EDITOR_COLUMN_STATUS_ID, id, | |
1307 STATUS_EDITOR_COLUMN_STATUS_NAME, name, | |
1308 STATUS_EDITOR_COLUMN_STATUS_MESSAGE, message, | |
1309 -1); | |
1310 } | |
1311 | |
1312 gtk_widget_destroy(dialog->window); | |
1313 g_free(id); | |
1314 g_free(message); | |
1315 g_free(dialog); | |
1316 } | |
1317 | |
1318 static void | |
1319 edit_substatus(StatusEditor *status_editor, GaimAccount *account) | |
1320 { | |
1321 char *tmp; | |
1322 SubStatusEditor *dialog; | |
1323 GtkSizeGroup *sg; | |
1324 GtkWidget *bbox; | |
1325 GtkWidget *button; | |
1326 GtkWidget *combo; | |
1327 GtkWidget *hbox; | |
1328 GtkWidget *frame; | |
1329 GtkWidget *label; | |
1330 GtkWidget *text; | |
1331 GtkWidget *toolbar; | |
1332 GtkWidget *vbox; | |
1333 GtkWidget *win; | |
1334 GtkTreeIter iter; | |
1335 GtkCellRenderer *rend; | |
1336 const char *id = NULL; | |
1337 const GList *list; | |
1338 gboolean select = FALSE; | |
1339 | |
1340 g_return_if_fail(status_editor != NULL); | |
1341 g_return_if_fail(account != NULL); | |
1342 | |
1343 dialog = g_new0(SubStatusEditor, 1); | |
1344 dialog->status_editor = status_editor; | |
1345 | |
1346 dialog->window = win = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
1347 gtk_window_set_role(GTK_WINDOW(win), "substatus"); | |
1348 tmp = g_strdup_printf(_("Status for %s"), gaim_account_get_username(account)); | |
1349 gtk_window_set_title(GTK_WINDOW(win), tmp); | |
1350 g_free(tmp); | |
1351 gtk_window_set_resizable(GTK_WINDOW(win), FALSE); | |
1352 gtk_container_set_border_width(GTK_CONTAINER(win), GAIM_HIG_BORDER); | |
1353 | |
1354 g_signal_connect(G_OBJECT(win), "delete_event", | |
1355 G_CALLBACK(substatus_editor_destroy_cb), dialog); | |
1356 | |
1357 /* Setup the vbox */ | |
1358 vbox = gtk_vbox_new(FALSE, GAIM_HIG_BORDER); | |
1359 gtk_container_add(GTK_CONTAINER(win), vbox); | |
1360 gtk_widget_show(vbox); | |
1361 | |
1362 sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); | |
1363 | |
1364 /* Status type */ | |
1365 hbox = gtk_hbox_new(FALSE, GAIM_HIG_BOX_SPACE); | |
1366 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
1367 gtk_widget_show(hbox); | |
1368 | |
1369 label = gtk_label_new_with_mnemonic(_("_Status:")); | |
1370 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
1371 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
1372 gtk_widget_show(label); | |
1373 gtk_size_group_add_widget(sg, label); | |
1374 | |
1375 dialog->model = gtk_list_store_new(SUBSTATUS_NUM_COLUMNS, | |
1376 G_TYPE_POINTER, | |
1377 GDK_TYPE_PIXBUF, | |
1378 G_TYPE_STRING, | |
1379 G_TYPE_STRING); | |
1380 combo = gtk_combo_box_new_with_model(GTK_TREE_MODEL(dialog->model)); | |
1381 dialog->box = GTK_COMBO_BOX(combo); | |
1382 | |
1383 rend = GTK_CELL_RENDERER(gtk_cell_renderer_pixbuf_new()); | |
1384 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), rend, FALSE); | |
1385 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), rend, | |
1386 "pixbuf", SUBSTATUS_COLUMN_ICON, NULL); | |
1387 | |
1388 rend = GTK_CELL_RENDERER(gtk_cell_renderer_text_new()); | |
1389 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), rend, TRUE); | |
1390 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), rend, | |
1391 "text", SUBSTATUS_COLUMN_STATUS_NAME, NULL); | |
1392 | |
1393 g_signal_connect(G_OBJECT(combo), "changed", | |
1394 G_CALLBACK(substatus_selection_changed_cb), dialog); | |
1395 | |
1396 gtk_box_pack_start(GTK_BOX(hbox), combo, FALSE, FALSE, 0); | |
1397 gtk_widget_show(combo); | |
1398 | |
1399 /* Status mesage */ | |
1400 hbox = gtk_hbox_new(FALSE, GAIM_HIG_BOX_SPACE); | |
1401 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
1402 gtk_widget_show(hbox); | |
1403 | |
1404 label = gtk_label_new_with_mnemonic(_("_Message:")); | |
1405 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
1406 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
1407 gtk_widget_show(label); | |
1408 gtk_size_group_add_widget(sg, label); | |
1409 | |
1410 frame = gaim_gtk_create_imhtml(TRUE, &text, &toolbar); | |
1411 dialog->message = GTK_IMHTML(text); | |
1412 dialog->toolbar = GTK_IMHTMLTOOLBAR(toolbar); | |
1413 gtk_box_pack_start(GTK_BOX(hbox), frame, TRUE, TRUE, 0); | |
1414 gtk_widget_show(frame); | |
1415 | |
1416 /* Button box */ | |
1417 bbox = gtk_hbutton_box_new(); | |
1418 gtk_box_set_spacing(GTK_BOX(bbox), GAIM_HIG_BOX_SPACE); | |
1419 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); | |
1420 gtk_box_pack_end(GTK_BOX(vbox), bbox, FALSE, TRUE, 0); | |
1421 gtk_widget_show(bbox); | |
1422 | |
1423 /* Cancel button */ | |
1424 button = gtk_button_new_from_stock(GTK_STOCK_CANCEL); | |
1425 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
1426 gtk_widget_show(button); | |
1427 | |
1428 g_signal_connect(G_OBJECT(button), "clicked", | |
1429 G_CALLBACK(substatus_editor_cancel_cb), dialog); | |
1430 | |
1431 /* OK button */ | |
1432 button = gtk_button_new_from_stock(GTK_STOCK_OK); | |
1433 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
1434 gtk_widget_show(button); | |
1435 | |
1436 g_signal_connect(G_OBJECT(button), "clicked", | |
1437 G_CALLBACK(substatus_editor_ok_cb), dialog); | |
1438 | |
1439 /* Seed the input widgets with the current values */ | |
1440 /* TODO: Get the current values from our parent's list store, not the saved_status! */ | |
1441 if (status_editor->original_title != NULL) | |
1442 { | |
1443 GaimSavedStatus *saved_status = NULL; | |
1444 GaimSavedStatusSub *substatus = NULL; | |
1445 | |
1446 saved_status = gaim_savedstatus_find(status_editor->original_title); | |
1447 if (saved_status != NULL) | |
1448 substatus = gaim_savedstatus_get_substatus(saved_status, account); | |
1449 | |
1450 if (substatus != NULL) | |
1451 { | |
1452 gtk_imhtml_append_text(dialog->message, | |
1453 gaim_savedstatus_substatus_get_message(substatus), | |
1454 0); | |
1455 id = gaim_status_type_get_id(gaim_savedstatus_substatus_get_type(substatus)); | |
1456 } | |
1457 } | |
1458 | |
1459 for (list = gaim_account_get_status_types(account); list; list = list->next) | |
1460 { | |
1461 GaimStatusType *status_type; | |
1462 GdkPixbuf *pixbuf, *scale = NULL; | |
1463 const char *id, *name; | |
1464 | |
1465 status_type = list->data; | |
1466 id = gaim_status_type_get_id(status_type); | |
1467 pixbuf = gaim_gtk_create_prpl_icon_with_status(account, status_type); | |
1468 if (pixbuf != NULL) | |
1469 scale = gdk_pixbuf_scale_simple(pixbuf, 16, 16, GDK_INTERP_BILINEAR); | |
1470 name = gaim_status_type_get_name(status_type); | |
1471 | |
1472 gtk_list_store_append(dialog->model, &iter); | |
1473 gtk_list_store_set(dialog->model, &iter, | |
1474 SUBSTATUS_COLUMN_ACCOUNT, account, | |
1475 SUBSTATUS_COLUMN_ICON, scale, | |
1476 SUBSTATUS_COLUMN_STATUS_ID, id, | |
1477 SUBSTATUS_COLUMN_STATUS_NAME, name, | |
1478 -1); | |
1479 if (id && !strcmp(id, gaim_status_type_get_id(status_type))) | |
1480 { | |
1481 gtk_combo_box_set_active_iter(GTK_COMBO_BOX(combo), &iter); | |
1482 select = TRUE; | |
1483 } | |
1484 } | |
1485 | |
1486 if (!select) | |
1487 gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0); | |
1488 | |
1489 gtk_widget_show(win); | |
1490 } | |
1491 | |
12329 | 1492 |
12195 | 1493 /************************************************************************** |
1494 * Utilities * | |
1495 **************************************************************************/ | |
1496 | |
12246 | 1497 static void |
1498 status_menu_cb(GtkComboBox *widget, void(*callback)(GaimSavedStatus*)) | |
12195 | 1499 { |
12237 | 1500 GtkTreeIter iter; |
1501 gchar *title = NULL; | |
1502 | |
1503 if (!gtk_combo_box_get_active_iter(widget, &iter)) | |
1504 return; | |
1505 | |
1506 gtk_tree_model_get(gtk_combo_box_get_model(widget), &iter, | |
1507 STATUS_WINDOW_COLUMN_TITLE, &title, -1); | |
1508 callback(gaim_savedstatus_find(title)); | |
1509 g_free(title); | |
12195 | 1510 } |
1511 | |
12817 | 1512 static gint |
1513 saved_status_sort_alphabetically_func(gconstpointer a, gconstpointer b) | |
1514 { | |
1515 const GaimSavedStatus *saved_status_a = a; | |
1516 const GaimSavedStatus *saved_status_b = b; | |
12823
292a846fdeea
[gaim-migrate @ 15171]
Richard Laager <rlaager@wiktel.com>
parents:
12817
diff
changeset
|
1517 return g_utf8_collate(gaim_savedstatus_get_title(saved_status_a), |
12817 | 1518 gaim_savedstatus_get_title(saved_status_b)); |
1519 } | |
1520 | |
12195 | 1521 GtkWidget *gaim_gtk_status_menu(GaimSavedStatus *current_status, GCallback callback) |
1522 { | |
1523 GtkWidget *combobox; | |
12817 | 1524 GList *sorted, *cur; |
12195 | 1525 int i; |
1526 int index = -1; | |
12329 | 1527 |
12199 | 1528 combobox = gtk_combo_box_new_text(); |
12329 | 1529 |
12817 | 1530 sorted = g_list_copy((GList *)gaim_savedstatuses_get_all()); |
1531 sorted = g_list_sort(sorted, saved_status_sort_alphabetically_func); | |
1532 for (cur = sorted, i = 0; | |
1533 cur != NULL; | |
1534 cur = g_list_next(cur)) | |
12329 | 1535 { |
12817 | 1536 GaimSavedStatus *status = (GaimSavedStatus *)cur->data; |
12199 | 1537 if (!gaim_savedstatus_is_transient(status)) { |
12329 | 1538 gtk_combo_box_append_text(GTK_COMBO_BOX(combobox), |
12199 | 1539 gaim_savedstatus_get_title(status)); |
1540 if (status == current_status) | |
1541 index = i; | |
1542 i++; | |
1543 } | |
12195 | 1544 } |
12817 | 1545 g_list_free(sorted); |
12246 | 1546 |
12195 | 1547 gtk_combo_box_set_active(GTK_COMBO_BOX(combobox), index); |
1548 g_signal_connect(G_OBJECT(combobox), "changed", G_CALLBACK(status_menu_cb), callback); | |
12329 | 1549 |
12195 | 1550 return combobox; |
1551 } | |
1552 | |
12080 | 1553 |
1554 /************************************************************************** | |
10814
364a2ef907ae
[gaim-migrate @ 12468]
Luke Schierer <lschiere@pidgin.im>
parents:
10732
diff
changeset
|
1555 * GTK+ saved status glue |
10421 | 1556 **************************************************************************/ |
10418 | 1557 |
1558 void * | |
1559 gaim_gtk_status_get_handle() | |
1560 { | |
1561 static int handle; | |
1562 | |
1563 return &handle; | |
1564 } | |
1565 | |
1566 void | |
1567 gaim_gtk_status_init(void) | |
1568 { | |
1569 gaim_prefs_add_none("/gaim/gtk/status"); | |
1570 gaim_prefs_add_none("/gaim/gtk/status/dialog"); | |
1571 gaim_prefs_add_int("/gaim/gtk/status/dialog/width", 550); | |
1572 gaim_prefs_add_int("/gaim/gtk/status/dialog/height", 250); | |
1573 } | |
1574 | |
1575 void | |
1576 gaim_gtk_status_uninit(void) | |
1577 { | |
1578 gaim_gtk_status_window_hide(); | |
1579 } |