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