Mercurial > pidgin
annotate src/gtksavedstatuses.c @ 11611:311a743df5ca
[gaim-migrate @ 13884]
fix a crash on getting an im after you close a window with the person
by closing the whole window rather than the conversation.
committer: Tailor Script <tailor@pidgin.im>
author | Tim Ringenbach <marv@pidgin.im> |
---|---|
date | Wed, 05 Oct 2005 00:28:06 +0000 |
parents | 30ad548e8537 |
children | 723487d07aa0 |
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" | |
35 #include "gtkgaim.h" | |
36 #include "gtkgaim-disclosure.h" | |
37 #include "gtkimhtml.h" | |
38 #include "gtkimhtmltoolbar.h" | |
39 #include "gtksavedstatuses.h" | |
40 #include "gtkstock.h" | |
41 #include "gtkutils.h" | |
42 | |
43 enum | |
44 { | |
10421 | 45 STATUS_WINDOW_COLUMN_TITLE, |
46 STATUS_WINDOW_COLUMN_TYPE, | |
47 STATUS_WINDOW_COLUMN_MESSAGE, | |
48 STATUS_WINDOW_NUM_COLUMNS | |
49 }; | |
50 | |
51 enum | |
52 { | |
10418 | 53 STATUS_EDITOR_COLUMN_CUSTOM_STATUS, |
54 STATUS_EDITOR_COLUMN_ICON, | |
55 STATUS_EDITOR_COLUMN_SCREENNAME, | |
56 STATUS_EDITOR_NUM_COLUMNS | |
57 }; | |
58 | |
10421 | 59 typedef struct |
10418 | 60 { |
10421 | 61 GtkWidget *window; |
62 GtkListStore *model; | |
63 GtkWidget *treeview; | |
64 GtkWidget *modify_button; | |
65 GtkWidget *delete_button; | |
66 } StatusWindow; | |
10418 | 67 |
68 typedef struct | |
69 { | |
70 GtkWidget *window; | |
71 GtkListStore *model; | |
72 GtkWidget *treeview; | |
10420 | 73 GtkWidget *save_button; |
74 | |
75 gchar *original_title; | |
76 GtkEntry *title; | |
77 GtkOptionMenu *type; | |
78 GtkIMHtml *message; | |
10418 | 79 } StatusEditor; |
80 | |
81 static StatusWindow *status_window = NULL; | |
82 | |
10421 | 83 |
84 /************************************************************************** | |
85 * Status window | |
86 **************************************************************************/ | |
87 | |
88 static gboolean | |
89 status_window_find_savedstatus(GtkTreeIter *iter, const char *title) | |
90 { | |
91 GtkTreeModel *model = GTK_TREE_MODEL(status_window->model); | |
10439 | 92 char *cur; |
10421 | 93 |
94 if (!gtk_tree_model_get_iter_first(model, iter)) | |
95 return FALSE; | |
96 | |
97 gtk_tree_model_get(model, iter, STATUS_WINDOW_COLUMN_TITLE, &cur, -1); | |
98 if (!strcmp(title, cur)) | |
10439 | 99 { |
100 g_free(cur); | |
10421 | 101 return TRUE; |
10439 | 102 } |
103 g_free(cur); | |
10421 | 104 |
105 while (gtk_tree_model_iter_next(model, iter)) | |
106 { | |
107 gtk_tree_model_get(model, iter, STATUS_WINDOW_COLUMN_TITLE, &cur, -1); | |
108 if (!strcmp(title, cur)) | |
10439 | 109 { |
110 g_free(cur); | |
10421 | 111 return TRUE; |
10439 | 112 } |
113 g_free(cur); | |
10421 | 114 } |
115 | |
116 return FALSE; | |
117 } | |
118 | |
119 static gboolean | |
120 status_window_destroy_cb(GtkWidget *widget, GdkEvent *event, gpointer user_data) | |
121 { | |
122 StatusWindow *dialog = user_data; | |
123 | |
124 dialog->window = NULL; | |
125 gaim_gtk_status_window_hide(); | |
126 | |
127 return FALSE; | |
128 } | |
129 | |
130 static void | |
131 status_window_add_cb(GtkButton *button, gpointer user_data) | |
132 { | |
133 gaim_gtk_status_editor_show(NULL); | |
134 } | |
135 | |
136 static void | |
137 status_window_modify_foreach(GtkTreeModel *model, GtkTreePath *path, | |
138 GtkTreeIter *iter, gpointer user_data) | |
139 { | |
10439 | 140 char *title; |
10421 | 141 GaimSavedStatus *status; |
142 | |
143 gtk_tree_model_get(model, iter, STATUS_WINDOW_COLUMN_TITLE, &title, -1); | |
144 | |
145 status = gaim_savedstatus_find(title); | |
10439 | 146 g_free(title); |
10421 | 147 gaim_gtk_status_editor_show(status); |
148 } | |
149 | |
150 static void | |
151 status_window_modify_cb(GtkButton *button, gpointer user_data) | |
152 { | |
153 StatusWindow *dialog = user_data; | |
154 GtkTreeSelection *selection; | |
155 | |
156 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dialog->treeview)); | |
157 | |
158 gtk_tree_selection_selected_foreach(selection, status_window_modify_foreach, user_data); | |
159 } | |
160 | |
161 static void | |
162 status_window_delete_confirm_cb(char *title) | |
163 { | |
164 GtkTreeIter iter; | |
165 | |
166 if (status_window_find_savedstatus(&iter, title)) | |
167 gtk_list_store_remove(status_window->model, &iter); | |
168 | |
169 gaim_savedstatus_delete(title); | |
170 | |
171 g_free(title); | |
172 } | |
173 | |
174 static void | |
175 status_window_delete_foreach(GtkTreeModel *model, GtkTreePath *path, | |
176 GtkTreeIter *iter, gpointer user_data) | |
177 { | |
10439 | 178 char *title; |
10435 | 179 char *title_escaped, *buf; |
10421 | 180 |
181 gtk_tree_model_get(model, iter, STATUS_WINDOW_COLUMN_TITLE, &title, -1); | |
182 | |
10732
c4cb90065e1d
[gaim-migrate @ 12334]
Luke Schierer <lschiere@pidgin.im>
parents:
10591
diff
changeset
|
183 title_escaped = g_markup_escape_text(title, -1); |
10435 | 184 buf = g_strdup_printf(_("Are you sure you want to delete %s?"), title_escaped); |
185 free(title_escaped); | |
10439 | 186 gaim_request_action(NULL, NULL, buf, NULL, 0, title, 2, |
10421 | 187 _("Delete"), status_window_delete_confirm_cb, |
188 _("Cancel"), g_free); | |
189 g_free(buf); | |
190 } | |
191 | |
192 static void | |
193 status_window_delete_cb(GtkButton *button, gpointer user_data) | |
194 { | |
195 StatusWindow *dialog = user_data; | |
196 GtkTreeSelection *selection; | |
197 | |
198 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dialog->treeview)); | |
199 | |
200 gtk_tree_selection_selected_foreach(selection, status_window_delete_foreach, user_data); | |
201 } | |
202 | |
203 static void | |
204 status_window_close_cb(GtkButton *button, gpointer user_data) | |
205 { | |
206 gaim_gtk_status_window_hide(); | |
207 } | |
208 | |
209 static void | |
210 status_selected_cb(GtkTreeSelection *sel, gpointer user_data) | |
211 { | |
212 StatusWindow *dialog = user_data; | |
213 gboolean selected = FALSE; | |
214 | |
215 #if GTK_CHECK_VERSION(2,2,0) | |
216 selected = (gtk_tree_selection_count_selected_rows(sel) > 0); | |
217 #else | |
218 gtk_tree_selection_selected_foreach(sel, get_selected_helper, &selected); | |
219 #endif | |
220 | |
221 gtk_widget_set_sensitive(dialog->modify_button, selected); | |
222 gtk_widget_set_sensitive(dialog->delete_button, selected); | |
223 } | |
224 | |
225 static void | |
226 add_status_to_saved_status_list(GtkListStore *model, GaimSavedStatus *saved_status) | |
227 { | |
228 GtkTreeIter iter; | |
229 const char *title; | |
230 const char *type; | |
231 char *message; | |
232 | |
233 title = gaim_savedstatus_get_title(saved_status); | |
234 type = gaim_primitive_get_name_from_type(gaim_savedstatus_get_type(saved_status)); | |
235 message = gaim_markup_strip_html(gaim_savedstatus_get_message(saved_status)); | |
236 | |
237 gtk_list_store_append(model, &iter); | |
238 gtk_list_store_set(model, &iter, | |
239 STATUS_WINDOW_COLUMN_TITLE, title, | |
240 STATUS_WINDOW_COLUMN_TYPE, type, | |
241 STATUS_WINDOW_COLUMN_MESSAGE, message, | |
242 -1); | |
243 free(message); | |
244 } | |
245 | |
246 static void | |
247 populate_saved_status_list(StatusWindow *dialog) | |
248 { | |
249 const GList *saved_statuses; | |
250 | |
251 gtk_list_store_clear(dialog->model); | |
252 | |
253 for (saved_statuses = gaim_savedstatuses_get_all(); saved_statuses != NULL; | |
254 saved_statuses = g_list_next(saved_statuses)) | |
255 { | |
256 add_status_to_saved_status_list(dialog->model, saved_statuses->data); | |
257 } | |
258 } | |
259 | |
10435 | 260 static gboolean |
261 search_func(GtkTreeModel *model, gint column, const gchar *key, GtkTreeIter *iter, gpointer search_data) | |
262 { | |
10439 | 263 gboolean result; |
264 char *haystack; | |
10435 | 265 |
266 gtk_tree_model_get(model, iter, column, &haystack, -1); | |
267 | |
10439 | 268 result = (gaim_strcasestr(haystack, key) == NULL); |
269 | |
270 g_free(haystack); | |
271 | |
272 return result; | |
10435 | 273 } |
274 | |
10421 | 275 static GtkWidget * |
276 create_saved_status_list(StatusWindow *dialog) | |
277 { | |
278 GtkWidget *sw; | |
279 GtkWidget *treeview; | |
280 GtkTreeSelection *sel; | |
281 GtkTreeViewColumn *column; | |
282 GtkCellRenderer *renderer; | |
283 | |
284 /* Create the scrolled window */ | |
285 sw = gtk_scrolled_window_new(0, 0); | |
286 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), | |
287 GTK_POLICY_AUTOMATIC, | |
288 GTK_POLICY_ALWAYS); | |
289 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), | |
290 GTK_SHADOW_IN); | |
291 gtk_widget_show(sw); | |
292 | |
293 /* Create the list model */ | |
294 dialog->model = gtk_list_store_new(STATUS_WINDOW_NUM_COLUMNS, | |
295 G_TYPE_STRING, | |
296 G_TYPE_STRING, | |
297 G_TYPE_STRING); | |
298 | |
299 /* Create the treeview */ | |
300 treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(dialog->model)); | |
301 dialog->treeview = treeview; | |
302 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(treeview), TRUE); | |
303 | |
304 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); | |
305 gtk_tree_selection_set_mode(sel, GTK_SELECTION_MULTIPLE); | |
306 g_signal_connect(G_OBJECT(sel), "changed", | |
307 G_CALLBACK(status_selected_cb), dialog); | |
308 | |
309 gtk_container_add(GTK_CONTAINER(sw), treeview); | |
310 gtk_widget_show(treeview); | |
311 | |
312 /* Add columns */ | |
313 column = gtk_tree_view_column_new(); | |
314 gtk_tree_view_column_set_title(column, _("Title")); | |
315 gtk_tree_view_column_set_resizable(column, TRUE); | |
11548 | 316 gtk_tree_view_column_set_min_width(column, 100); |
10421 | 317 gtk_tree_view_column_set_sort_column_id(column, |
318 STATUS_WINDOW_COLUMN_TITLE); | |
319 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); | |
320 renderer = gtk_cell_renderer_text_new(); | |
321 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
322 gtk_tree_view_column_add_attribute(column, renderer, "text", | |
323 STATUS_WINDOW_COLUMN_TITLE); | |
11548 | 324 #if GTK_CHECK_VERSION(2,6,0) |
325 g_object_set(renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL); | |
326 #endif | |
10421 | 327 |
328 column = gtk_tree_view_column_new(); | |
329 gtk_tree_view_column_set_title(column, _("Type")); | |
330 gtk_tree_view_column_set_resizable(column, TRUE); | |
331 gtk_tree_view_column_set_sort_column_id(column, | |
332 STATUS_WINDOW_COLUMN_TYPE); | |
333 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); | |
334 renderer = gtk_cell_renderer_text_new(); | |
335 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
336 gtk_tree_view_column_add_attribute(column, renderer, "text", | |
337 STATUS_WINDOW_COLUMN_TYPE); | |
338 | |
339 column = gtk_tree_view_column_new(); | |
340 gtk_tree_view_column_set_title(column, _("Message")); | |
341 gtk_tree_view_column_set_resizable(column, TRUE); | |
342 gtk_tree_view_column_set_sort_column_id(column, | |
343 STATUS_WINDOW_COLUMN_MESSAGE); | |
344 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); | |
345 renderer = gtk_cell_renderer_text_new(); | |
346 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
347 gtk_tree_view_column_add_attribute(column, renderer, "text", | |
348 STATUS_WINDOW_COLUMN_MESSAGE); | |
10435 | 349 #if GTK_CHECK_VERSION(2,6,0) |
10502 | 350 g_object_set(renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL); |
10435 | 351 #endif |
352 | |
353 /* Enable CTRL+F searching */ | |
354 gtk_tree_view_set_search_column(GTK_TREE_VIEW(treeview), STATUS_WINDOW_COLUMN_TITLE); | |
355 gtk_tree_view_set_search_equal_func(GTK_TREE_VIEW(treeview), search_func, NULL, NULL); | |
10421 | 356 |
10422 | 357 /* Sort the title column by default */ |
358 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(dialog->model), | |
359 STATUS_WINDOW_COLUMN_TITLE, | |
360 GTK_SORT_ASCENDING); | |
361 | |
10421 | 362 /* Populate list */ |
363 populate_saved_status_list(dialog); | |
364 | |
365 return sw; | |
366 } | |
367 | |
368 static gboolean | |
369 configure_cb(GtkWidget *widget, GdkEventConfigure *event, StatusWindow *dialog) | |
370 { | |
371 if (GTK_WIDGET_VISIBLE(widget)) { | |
372 gaim_prefs_set_int("/gaim/gtk/status/dialog/width", event->width); | |
373 gaim_prefs_set_int("/gaim/gtk/status/dialog/height", event->height); | |
374 } | |
375 | |
376 return FALSE; | |
377 } | |
378 | |
379 void | |
380 gaim_gtk_status_window_show(void) | |
381 { | |
382 StatusWindow *dialog; | |
383 GtkWidget *bbox; | |
384 GtkWidget *button; | |
385 GtkWidget *list; | |
386 GtkWidget *vbox; | |
387 GtkWidget *win; | |
388 int width, height; | |
389 | |
390 if (status_window != NULL) { | |
391 gtk_window_present(GTK_WINDOW(status_window->window)); | |
392 return; | |
393 } | |
394 | |
395 status_window = dialog = g_new0(StatusWindow, 1); | |
396 | |
397 width = gaim_prefs_get_int("/gaim/gtk/status/dialog/width"); | |
398 height = gaim_prefs_get_int("/gaim/gtk/status/dialog/height"); | |
399 | |
400 dialog->window = win = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
401 gtk_window_set_default_size(GTK_WINDOW(win), width, height); | |
402 gtk_window_set_role(GTK_WINDOW(win), "statuses"); | |
403 gtk_window_set_title(GTK_WINDOW(win), _("Saved Statuses")); | |
11243 | 404 gtk_container_set_border_width(GTK_CONTAINER(win), GAIM_HIG_BORDER); |
10421 | 405 |
406 g_signal_connect(G_OBJECT(win), "delete_event", | |
407 G_CALLBACK(status_window_destroy_cb), dialog); | |
408 g_signal_connect(G_OBJECT(win), "configure_event", | |
409 G_CALLBACK(configure_cb), dialog); | |
410 | |
411 /* Setup the vbox */ | |
11243 | 412 vbox = gtk_vbox_new(FALSE, GAIM_HIG_BORDER); |
10421 | 413 gtk_container_add(GTK_CONTAINER(win), vbox); |
414 gtk_widget_show(vbox); | |
415 | |
416 /* List of saved status states */ | |
417 list = create_saved_status_list(dialog); | |
418 gtk_box_pack_start(GTK_BOX(vbox), list, TRUE, TRUE, 0); | |
419 | |
420 /* Button box. */ | |
421 bbox = gtk_hbutton_box_new(); | |
11243 | 422 gtk_box_set_spacing(GTK_BOX(bbox), GAIM_HIG_BOX_SPACE); |
10421 | 423 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); |
424 gtk_box_pack_end(GTK_BOX(vbox), bbox, FALSE, TRUE, 0); | |
425 gtk_widget_show(bbox); | |
426 | |
427 /* Add button */ | |
428 button = gtk_button_new_from_stock(GTK_STOCK_ADD); | |
429 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
430 gtk_widget_show(button); | |
431 | |
432 g_signal_connect(G_OBJECT(button), "clicked", | |
433 G_CALLBACK(status_window_add_cb), dialog); | |
434 | |
435 /* Modify button */ | |
436 button = gtk_button_new_from_stock(GAIM_STOCK_MODIFY); | |
437 dialog->modify_button = button; | |
438 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
439 gtk_widget_set_sensitive(button, FALSE); | |
440 gtk_widget_show(button); | |
441 | |
442 g_signal_connect(G_OBJECT(button), "clicked", | |
443 G_CALLBACK(status_window_modify_cb), dialog); | |
444 | |
445 /* Delete button */ | |
446 button = gtk_button_new_from_stock(GTK_STOCK_DELETE); | |
447 dialog->delete_button = button; | |
448 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
449 gtk_widget_set_sensitive(button, FALSE); | |
450 gtk_widget_show(button); | |
451 | |
452 g_signal_connect(G_OBJECT(button), "clicked", | |
453 G_CALLBACK(status_window_delete_cb), dialog); | |
454 | |
455 /* Close button */ | |
456 button = gtk_button_new_from_stock(GTK_STOCK_CLOSE); | |
457 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
458 gtk_widget_show(button); | |
459 | |
460 g_signal_connect(G_OBJECT(button), "clicked", | |
461 G_CALLBACK(status_window_close_cb), dialog); | |
462 | |
463 gtk_widget_show(win); | |
464 } | |
465 | |
466 void | |
467 gaim_gtk_status_window_hide(void) | |
468 { | |
469 if (status_window == NULL) | |
470 return; | |
471 | |
472 if (status_window->window != NULL) | |
473 gtk_widget_destroy(status_window->window); | |
474 | |
475 g_free(status_window); | |
476 status_window = NULL; | |
477 } | |
478 | |
479 | |
480 /************************************************************************** | |
481 * Status editor | |
482 **************************************************************************/ | |
10420 | 483 |
10418 | 484 static gboolean |
485 status_editor_destroy_cb(GtkWidget *widget, GdkEvent *event, gpointer user_data) | |
486 { | |
10574 | 487 StatusEditor *dialog = user_data; |
10418 | 488 |
10574 | 489 g_free(dialog->original_title); |
10418 | 490 g_free(dialog); |
491 | |
492 return FALSE; | |
493 } | |
494 | |
495 static void | |
496 status_editor_cancel_cb(GtkButton *button, gpointer user_data) | |
497 { | |
10574 | 498 StatusEditor *dialog = user_data; |
10418 | 499 |
500 gtk_widget_destroy(dialog->window); | |
501 | |
10574 | 502 g_free(dialog->original_title); |
10418 | 503 g_free(dialog); |
504 } | |
505 | |
506 static void | |
507 status_editor_save_cb(GtkButton *button, gpointer user_data) | |
508 { | |
10420 | 509 StatusEditor *dialog = user_data; |
510 const char *title; | |
511 GaimStatusPrimitive type; | |
512 char *message, *unformatted; | |
513 GaimSavedStatus *status; | |
514 | |
515 title = gtk_entry_get_text(dialog->title); | |
516 | |
517 /* | |
518 * If the title is already taken then show an error dialog and | |
519 * don't do anything. | |
520 */ | |
521 if ((gaim_savedstatus_find(title) != NULL) && | |
522 ((dialog->original_title == NULL) || (strcmp(title, dialog->original_title)))) | |
523 { | |
524 gaim_notify_error(NULL, NULL, _("Title already in use. You must " | |
525 "choose a unique title."), NULL); | |
526 return; | |
527 } | |
528 | |
529 type = gtk_option_menu_get_history(dialog->type); | |
530 message = gtk_imhtml_get_markup(dialog->message); | |
531 unformatted = gaim_markup_strip_html(message); | |
532 | |
533 /* | |
534 * If we're editing an existing status, remove the old one to | |
535 * make way for the modified one. | |
536 */ | |
537 if (dialog->original_title != NULL) | |
538 { | |
539 GtkTreeIter iter; | |
540 | |
541 gaim_savedstatus_delete(dialog->original_title); | |
542 | |
543 if (status_window_find_savedstatus(&iter, dialog->original_title)) | |
544 { | |
545 gtk_list_store_remove(status_window->model, &iter); | |
546 } | |
547 } | |
548 | |
549 status = gaim_savedstatus_new(title, type); | |
550 if (*unformatted != '\0') | |
551 gaim_savedstatus_set_message(status, message); | |
552 g_free(message); | |
553 g_free(unformatted); | |
554 | |
555 gtk_widget_destroy(dialog->window); | |
10574 | 556 g_free(dialog->original_title); |
10420 | 557 g_free(dialog); |
558 | |
559 add_status_to_saved_status_list(status_window->model, status); | |
560 } | |
561 | |
562 static void | |
563 status_editor_custom_status_cb(GtkCellRendererToggle *renderer, gchar *path_str, gpointer data) | |
564 { | |
565 /* StatusEditor *dialog = (StatusEditor *)data; */ | |
566 | |
567 /* TODO: Need to allow user to set a custom status for the highlighted account, somehow */ | |
568 } | |
569 | |
570 static void | |
571 editor_title_changed_cb(GtkWidget *widget, gpointer user_data) | |
572 { | |
573 StatusEditor *dialog = user_data; | |
574 const gchar *text; | |
575 | |
576 text = gtk_entry_get_text(dialog->title); | |
577 | |
578 gtk_widget_set_sensitive(dialog->save_button, (*text != '\0')); | |
10418 | 579 } |
580 | |
581 static GtkWidget * | |
10419 | 582 create_status_type_menu(GaimStatusPrimitive type) |
10418 | 583 { |
10419 | 584 int i; |
10418 | 585 GtkWidget *dropdown; |
586 GtkWidget *menu; | |
587 GtkWidget *item; | |
588 | |
589 dropdown = gtk_option_menu_new(); | |
590 menu = gtk_menu_new(); | |
591 | |
10419 | 592 for (i = 0; i < GAIM_STATUS_NUM_PRIMITIVES; i++) |
593 { | |
594 item = gtk_menu_item_new_with_label(gaim_primitive_get_name_from_type(i)); | |
595 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); | |
596 gtk_widget_show(item); | |
597 } | |
10418 | 598 |
10419 | 599 gtk_menu_set_active(GTK_MENU(menu), type); |
10418 | 600 gtk_option_menu_set_menu(GTK_OPTION_MENU(dropdown), menu); |
601 gtk_widget_show(menu); | |
602 | |
603 return dropdown; | |
604 } | |
605 | |
606 static void | |
607 status_editor_add_columns(StatusEditor *dialog) | |
608 { | |
609 GtkCellRenderer *renderer; | |
610 GtkTreeViewColumn *column; | |
611 | |
612 /* Custom status column */ | |
613 renderer = gtk_cell_renderer_toggle_new(); | |
614 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(dialog->treeview), | |
615 -1, _("Custom status"), | |
616 renderer, | |
617 "active", STATUS_EDITOR_COLUMN_CUSTOM_STATUS, | |
618 NULL); | |
619 column = gtk_tree_view_get_column(GTK_TREE_VIEW(dialog->treeview), 1); | |
620 g_signal_connect(G_OBJECT(renderer), "toggled", | |
621 G_CALLBACK(status_editor_custom_status_cb), dialog); | |
622 | |
623 /* Screen Name column */ | |
624 column = gtk_tree_view_column_new(); | |
625 gtk_tree_view_column_set_resizable(column, TRUE); | |
626 gtk_tree_view_column_set_title(column, _("Screen Name")); | |
627 gtk_tree_view_insert_column(GTK_TREE_VIEW(dialog->treeview), column, -1); | |
628 gtk_tree_view_column_set_resizable(column, TRUE); | |
629 | |
630 /* Icon */ | |
631 renderer = gtk_cell_renderer_pixbuf_new(); | |
632 gtk_tree_view_column_pack_start(column, renderer, FALSE); | |
633 gtk_tree_view_column_add_attribute(column, renderer, "pixbuf", | |
634 STATUS_EDITOR_COLUMN_ICON); | |
635 | |
636 /* Screen Name */ | |
637 renderer = gtk_cell_renderer_text_new(); | |
638 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
639 gtk_tree_view_column_add_attribute(column, renderer, "text", | |
640 STATUS_EDITOR_COLUMN_SCREENNAME); | |
641 } | |
642 | |
643 static void | |
644 status_editor_set_account(GtkListStore *store, GaimAccount *account, GtkTreeIter *iter) | |
645 { | |
646 GdkPixbuf *pixbuf; | |
647 GdkPixbuf *scale; | |
648 | |
649 scale = NULL; | |
650 | |
10884 | 651 pixbuf = gaim_gtk_create_prpl_icon(account); |
10418 | 652 |
653 if (pixbuf != NULL) | |
654 { | |
655 scale = gdk_pixbuf_scale_simple(pixbuf, 16, 16, GDK_INTERP_BILINEAR); | |
656 | |
11251 | 657 if (gaim_account_is_disconnected(account)) |
10418 | 658 gdk_pixbuf_saturate_and_pixelate(scale, scale, 0.0, FALSE); |
659 } | |
660 | |
661 gtk_list_store_set(store, iter, | |
662 STATUS_EDITOR_COLUMN_ICON, scale, | |
663 STATUS_EDITOR_COLUMN_SCREENNAME, gaim_account_get_username(account), | |
664 -1); | |
665 | |
666 if (pixbuf != NULL) g_object_unref(G_OBJECT(pixbuf)); | |
667 if (scale != NULL) g_object_unref(G_OBJECT(scale)); | |
668 } | |
669 | |
670 static void | |
671 status_editor_add_account(StatusEditor *dialog, GaimAccount *account) | |
672 { | |
673 GtkTreeIter iter; | |
674 | |
675 gtk_list_store_append(dialog->model, &iter); | |
676 | |
677 status_editor_set_account(dialog->model, account, &iter); | |
678 } | |
679 | |
680 static void | |
681 status_editor_populate_list(StatusEditor *dialog) | |
682 { | |
683 GList *l; | |
684 | |
685 gtk_list_store_clear(dialog->model); | |
686 | |
687 for (l = gaim_accounts_get_all(); l != NULL; l = l->next) | |
688 status_editor_add_account(dialog, (GaimAccount *)l->data); | |
689 } | |
690 | |
691 void | |
10419 | 692 gaim_gtk_status_editor_show(GaimSavedStatus *status) |
10418 | 693 { |
694 StatusEditor *dialog; | |
695 GtkSizeGroup *sg; | |
696 GtkWidget *bbox; | |
697 GtkWidget *button; | |
698 GtkWidget *dbox; | |
699 GtkWidget *disclosure; | |
700 GtkWidget *dropdown; | |
701 GtkWidget *entry; | |
702 GtkWidget *frame; | |
703 GtkWidget *hbox; | |
704 GtkWidget *label; | |
705 GtkWidget *sw; | |
706 GtkWidget *text; | |
707 GtkWidget *toolbar; | |
708 GtkWidget *vbox; | |
709 GtkWidget *win; | |
710 | |
711 dialog = g_new0(StatusEditor, 1); | |
712 | |
10420 | 713 if (status != NULL) |
714 dialog->original_title = g_strdup(gaim_savedstatus_get_title(status)); | |
715 | |
10418 | 716 dialog->window = win = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
717 gtk_window_set_role(GTK_WINDOW(win), "status"); | |
718 gtk_window_set_title(GTK_WINDOW(win), _("Status")); | |
719 gtk_window_set_resizable(GTK_WINDOW(win), FALSE); | |
11243 | 720 gtk_container_set_border_width(GTK_CONTAINER(win), GAIM_HIG_BORDER); |
10418 | 721 |
722 g_signal_connect(G_OBJECT(win), "delete_event", | |
723 G_CALLBACK(status_editor_destroy_cb), dialog); | |
724 | |
725 /* Setup the vbox */ | |
11243 | 726 vbox = gtk_vbox_new(FALSE, GAIM_HIG_BORDER); |
10418 | 727 gtk_container_add(GTK_CONTAINER(win), vbox); |
728 gtk_widget_show(vbox); | |
729 | |
730 sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); | |
731 | |
732 /* Title */ | |
11243 | 733 hbox = gtk_hbox_new(FALSE, GAIM_HIG_BOX_SPACE); |
10418 | 734 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); |
735 gtk_widget_show(hbox); | |
736 | |
737 label = gtk_label_new_with_mnemonic(_("_Title:")); | |
738 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
739 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
740 gtk_widget_show(label); | |
741 gtk_size_group_add_widget(sg, label); | |
742 | |
743 entry = gtk_entry_new(); | |
10420 | 744 dialog->title = GTK_ENTRY(entry); |
10419 | 745 if (status != NULL) |
10420 | 746 gtk_entry_set_text(GTK_ENTRY(entry), dialog->original_title); |
10419 | 747 else |
748 gtk_entry_set_text(GTK_ENTRY(entry), _("Out of the office")); | |
10418 | 749 gtk_box_pack_start(GTK_BOX(hbox), entry, TRUE, TRUE, 0); |
750 gtk_widget_show(entry); | |
10420 | 751 g_signal_connect(G_OBJECT(entry), "changed", |
752 G_CALLBACK(editor_title_changed_cb), dialog); | |
10418 | 753 |
754 /* Status type */ | |
11243 | 755 hbox = gtk_hbox_new(FALSE, GAIM_HIG_BOX_SPACE); |
10418 | 756 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); |
757 gtk_widget_show(hbox); | |
758 | |
759 label = gtk_label_new_with_mnemonic(_("_Status:")); | |
760 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
761 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
762 gtk_widget_show(label); | |
763 gtk_size_group_add_widget(sg, label); | |
764 | |
10419 | 765 if (status != NULL) |
766 dropdown = create_status_type_menu(gaim_savedstatus_get_type(status)); | |
767 else | |
768 dropdown = create_status_type_menu(GAIM_STATUS_AWAY); | |
10420 | 769 dialog->type = GTK_OPTION_MENU(dropdown); |
10418 | 770 gtk_box_pack_start(GTK_BOX(hbox), dropdown, TRUE, TRUE, 0); |
771 gtk_widget_show(dropdown); | |
772 | |
773 /* Status message */ | |
11243 | 774 hbox = gtk_hbox_new(FALSE, GAIM_HIG_BOX_SPACE); |
10418 | 775 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); |
776 gtk_widget_show(hbox); | |
777 | |
778 label = gtk_label_new_with_mnemonic(_("_Message:")); | |
779 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
780 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
781 gtk_widget_show(label); | |
782 gtk_size_group_add_widget(sg, label); | |
783 | |
784 frame = gaim_gtk_create_imhtml(TRUE, &text, &toolbar); | |
10420 | 785 dialog->message = GTK_IMHTML(text); |
10418 | 786 gtk_box_pack_start(GTK_BOX(hbox), frame, TRUE, TRUE, 0); |
787 gtk_widget_show(frame); | |
788 | |
10574 | 789 if ((status != NULL) && (gaim_savedstatus_get_message(status) != NULL)) |
10419 | 790 gtk_imhtml_append_text(GTK_IMHTML(text), |
791 gaim_savedstatus_get_message(status), 0); | |
792 | |
10418 | 793 /* Custom status message disclosure */ |
794 disclosure = gaim_disclosure_new(_("Use a different status for some accounts"), | |
795 _("Use a different status for some accounts")); | |
796 gtk_box_pack_start(GTK_BOX(vbox), disclosure, FALSE, FALSE, 0); | |
797 gtk_widget_show(disclosure); | |
798 | |
799 /* Setup the box that the disclosure will cover */ | |
11243 | 800 dbox = gtk_vbox_new(FALSE, GAIM_HIG_CAT_SPACE); |
10418 | 801 gtk_box_pack_start(GTK_BOX(vbox), dbox, FALSE, FALSE, 0); |
802 gaim_disclosure_set_container(GAIM_DISCLOSURE(disclosure), dbox); | |
803 | |
804 /* Custom status message treeview */ | |
805 sw = gtk_scrolled_window_new(NULL, NULL); | |
806 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), | |
807 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); | |
808 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), | |
809 GTK_SHADOW_IN); | |
810 gtk_box_pack_start(GTK_BOX(dbox), sw, TRUE, TRUE, 0); | |
811 gtk_widget_show(sw); | |
812 | |
813 /* Create the list model */ | |
814 dialog->model = gtk_list_store_new(STATUS_EDITOR_NUM_COLUMNS, | |
815 G_TYPE_BOOLEAN, | |
816 GDK_TYPE_PIXBUF, G_TYPE_STRING); | |
817 | |
818 /* Create the treeview */ | |
819 dialog->treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(dialog->model)); | |
820 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(dialog->treeview), TRUE); | |
821 gtk_widget_set_size_request(dialog->treeview, 400, 250); | |
822 gtk_container_add(GTK_CONTAINER(sw), dialog->treeview); | |
823 gtk_widget_show(dialog->treeview); | |
824 | |
825 /* Add columns */ | |
826 status_editor_add_columns(dialog); | |
827 | |
828 /* Populate list */ | |
829 status_editor_populate_list(dialog); | |
830 | |
831 /* Button box */ | |
832 bbox = gtk_hbutton_box_new(); | |
11243 | 833 gtk_box_set_spacing(GTK_BOX(bbox), GAIM_HIG_BOX_SPACE); |
10418 | 834 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); |
835 gtk_box_pack_end(GTK_BOX(vbox), bbox, FALSE, TRUE, 0); | |
836 gtk_widget_show(bbox); | |
837 | |
838 /* Cancel button */ | |
839 button = gtk_button_new_from_stock(GTK_STOCK_CANCEL); | |
840 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
841 gtk_widget_show(button); | |
842 | |
843 g_signal_connect(G_OBJECT(button), "clicked", | |
844 G_CALLBACK(status_editor_cancel_cb), dialog); | |
845 | |
846 /* Save button */ | |
847 button = gtk_button_new_from_stock(GTK_STOCK_SAVE); | |
10420 | 848 dialog->save_button = button; |
10418 | 849 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); |
850 gtk_widget_show(button); | |
851 | |
852 g_signal_connect(G_OBJECT(button), "clicked", | |
853 G_CALLBACK(status_editor_save_cb), dialog); | |
854 | |
855 gtk_widget_show(win); | |
856 } | |
857 | |
858 | |
10421 | 859 /************************************************************************** |
10814
364a2ef907ae
[gaim-migrate @ 12468]
Luke Schierer <lschiere@pidgin.im>
parents:
10732
diff
changeset
|
860 * GTK+ saved status glue |
10421 | 861 **************************************************************************/ |
10418 | 862 |
863 void * | |
864 gaim_gtk_status_get_handle() | |
865 { | |
866 static int handle; | |
867 | |
868 return &handle; | |
869 } | |
870 | |
871 void | |
872 gaim_gtk_status_init(void) | |
873 { | |
874 gaim_prefs_add_none("/gaim/gtk/status"); | |
875 gaim_prefs_add_none("/gaim/gtk/status/dialog"); | |
876 gaim_prefs_add_int("/gaim/gtk/status/dialog/width", 550); | |
877 gaim_prefs_add_int("/gaim/gtk/status/dialog/height", 250); | |
878 } | |
879 | |
880 void | |
881 gaim_gtk_status_uninit(void) | |
882 { | |
883 gaim_gtk_status_window_hide(); | |
884 } |