Mercurial > pidgin.yaz
annotate src/gtksavedstatuses.c @ 11802:2e3a6dcebaf3
[gaim-migrate @ 14093]
This should be it for the // -> /* */ for the doodle/whiteboard stuff. This could use a bit of cleaning yet....
committer: Tailor Script <tailor@pidgin.im>
author | Gary Kramlich <grim@reaperworld.com> |
---|---|
date | Mon, 24 Oct 2005 22:45:24 +0000 |
parents | 8cb75ba77f9d |
children | 924c6ba240e6 |
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 | |
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 | |
11780 | 209 #if !GTK_CHECK_VERSION(2,2,0) |
210 static void | |
211 get_selected_helper(GtkTreeModel *model, GtkTreePath *path, | |
212 GtkTreeIter *iter, gpointer user_data) | |
213 { | |
214 *((gboolean *)user_data) = TRUE; | |
215 } | |
216 #endif | |
217 | |
10421 | 218 static void |
219 status_selected_cb(GtkTreeSelection *sel, gpointer user_data) | |
220 { | |
221 StatusWindow *dialog = user_data; | |
222 gboolean selected = FALSE; | |
223 | |
224 #if GTK_CHECK_VERSION(2,2,0) | |
225 selected = (gtk_tree_selection_count_selected_rows(sel) > 0); | |
226 #else | |
227 gtk_tree_selection_selected_foreach(sel, get_selected_helper, &selected); | |
228 #endif | |
229 | |
230 gtk_widget_set_sensitive(dialog->modify_button, selected); | |
231 gtk_widget_set_sensitive(dialog->delete_button, selected); | |
232 } | |
233 | |
234 static void | |
235 add_status_to_saved_status_list(GtkListStore *model, GaimSavedStatus *saved_status) | |
236 { | |
237 GtkTreeIter iter; | |
238 const char *title; | |
239 const char *type; | |
240 char *message; | |
241 | |
11651 | 242 if (gaim_savedstatus_is_transient(saved_status)) |
243 return; | |
244 | |
10421 | 245 title = gaim_savedstatus_get_title(saved_status); |
246 type = gaim_primitive_get_name_from_type(gaim_savedstatus_get_type(saved_status)); | |
247 message = gaim_markup_strip_html(gaim_savedstatus_get_message(saved_status)); | |
248 | |
249 gtk_list_store_append(model, &iter); | |
250 gtk_list_store_set(model, &iter, | |
251 STATUS_WINDOW_COLUMN_TITLE, title, | |
252 STATUS_WINDOW_COLUMN_TYPE, type, | |
253 STATUS_WINDOW_COLUMN_MESSAGE, message, | |
254 -1); | |
255 free(message); | |
256 } | |
257 | |
258 static void | |
259 populate_saved_status_list(StatusWindow *dialog) | |
260 { | |
261 const GList *saved_statuses; | |
262 | |
263 gtk_list_store_clear(dialog->model); | |
264 | |
265 for (saved_statuses = gaim_savedstatuses_get_all(); saved_statuses != NULL; | |
266 saved_statuses = g_list_next(saved_statuses)) | |
267 { | |
268 add_status_to_saved_status_list(dialog->model, saved_statuses->data); | |
269 } | |
270 } | |
271 | |
10435 | 272 static gboolean |
273 search_func(GtkTreeModel *model, gint column, const gchar *key, GtkTreeIter *iter, gpointer search_data) | |
274 { | |
10439 | 275 gboolean result; |
276 char *haystack; | |
10435 | 277 |
278 gtk_tree_model_get(model, iter, column, &haystack, -1); | |
279 | |
10439 | 280 result = (gaim_strcasestr(haystack, key) == NULL); |
281 | |
282 g_free(haystack); | |
283 | |
284 return result; | |
10435 | 285 } |
286 | |
10421 | 287 static GtkWidget * |
288 create_saved_status_list(StatusWindow *dialog) | |
289 { | |
290 GtkWidget *sw; | |
291 GtkWidget *treeview; | |
292 GtkTreeSelection *sel; | |
293 GtkTreeViewColumn *column; | |
294 GtkCellRenderer *renderer; | |
295 | |
296 /* Create the scrolled window */ | |
297 sw = gtk_scrolled_window_new(0, 0); | |
298 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), | |
299 GTK_POLICY_AUTOMATIC, | |
300 GTK_POLICY_ALWAYS); | |
301 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), | |
302 GTK_SHADOW_IN); | |
303 gtk_widget_show(sw); | |
304 | |
305 /* Create the list model */ | |
306 dialog->model = gtk_list_store_new(STATUS_WINDOW_NUM_COLUMNS, | |
307 G_TYPE_STRING, | |
308 G_TYPE_STRING, | |
309 G_TYPE_STRING); | |
310 | |
311 /* Create the treeview */ | |
312 treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(dialog->model)); | |
313 dialog->treeview = treeview; | |
314 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(treeview), TRUE); | |
315 | |
316 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); | |
317 gtk_tree_selection_set_mode(sel, GTK_SELECTION_MULTIPLE); | |
318 g_signal_connect(G_OBJECT(sel), "changed", | |
319 G_CALLBACK(status_selected_cb), dialog); | |
320 | |
321 gtk_container_add(GTK_CONTAINER(sw), treeview); | |
322 gtk_widget_show(treeview); | |
323 | |
324 /* Add columns */ | |
325 column = gtk_tree_view_column_new(); | |
326 gtk_tree_view_column_set_title(column, _("Title")); | |
327 gtk_tree_view_column_set_resizable(column, TRUE); | |
11548 | 328 gtk_tree_view_column_set_min_width(column, 100); |
10421 | 329 gtk_tree_view_column_set_sort_column_id(column, |
330 STATUS_WINDOW_COLUMN_TITLE); | |
331 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); | |
332 renderer = gtk_cell_renderer_text_new(); | |
333 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
334 gtk_tree_view_column_add_attribute(column, renderer, "text", | |
335 STATUS_WINDOW_COLUMN_TITLE); | |
11548 | 336 #if GTK_CHECK_VERSION(2,6,0) |
337 g_object_set(renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL); | |
338 #endif | |
10421 | 339 |
340 column = gtk_tree_view_column_new(); | |
341 gtk_tree_view_column_set_title(column, _("Type")); | |
342 gtk_tree_view_column_set_resizable(column, TRUE); | |
343 gtk_tree_view_column_set_sort_column_id(column, | |
344 STATUS_WINDOW_COLUMN_TYPE); | |
345 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); | |
346 renderer = gtk_cell_renderer_text_new(); | |
347 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
348 gtk_tree_view_column_add_attribute(column, renderer, "text", | |
349 STATUS_WINDOW_COLUMN_TYPE); | |
350 | |
351 column = gtk_tree_view_column_new(); | |
352 gtk_tree_view_column_set_title(column, _("Message")); | |
353 gtk_tree_view_column_set_resizable(column, TRUE); | |
354 gtk_tree_view_column_set_sort_column_id(column, | |
355 STATUS_WINDOW_COLUMN_MESSAGE); | |
356 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); | |
357 renderer = gtk_cell_renderer_text_new(); | |
358 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
359 gtk_tree_view_column_add_attribute(column, renderer, "text", | |
360 STATUS_WINDOW_COLUMN_MESSAGE); | |
10435 | 361 #if GTK_CHECK_VERSION(2,6,0) |
10502 | 362 g_object_set(renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL); |
10435 | 363 #endif |
364 | |
365 /* Enable CTRL+F searching */ | |
366 gtk_tree_view_set_search_column(GTK_TREE_VIEW(treeview), STATUS_WINDOW_COLUMN_TITLE); | |
367 gtk_tree_view_set_search_equal_func(GTK_TREE_VIEW(treeview), search_func, NULL, NULL); | |
10421 | 368 |
10422 | 369 /* Sort the title column by default */ |
370 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(dialog->model), | |
371 STATUS_WINDOW_COLUMN_TITLE, | |
372 GTK_SORT_ASCENDING); | |
373 | |
10421 | 374 /* Populate list */ |
375 populate_saved_status_list(dialog); | |
376 | |
377 return sw; | |
378 } | |
379 | |
380 static gboolean | |
381 configure_cb(GtkWidget *widget, GdkEventConfigure *event, StatusWindow *dialog) | |
382 { | |
383 if (GTK_WIDGET_VISIBLE(widget)) { | |
384 gaim_prefs_set_int("/gaim/gtk/status/dialog/width", event->width); | |
385 gaim_prefs_set_int("/gaim/gtk/status/dialog/height", event->height); | |
386 } | |
387 | |
388 return FALSE; | |
389 } | |
390 | |
391 void | |
392 gaim_gtk_status_window_show(void) | |
393 { | |
394 StatusWindow *dialog; | |
395 GtkWidget *bbox; | |
396 GtkWidget *button; | |
397 GtkWidget *list; | |
398 GtkWidget *vbox; | |
399 GtkWidget *win; | |
400 int width, height; | |
401 | |
402 if (status_window != NULL) { | |
403 gtk_window_present(GTK_WINDOW(status_window->window)); | |
404 return; | |
405 } | |
406 | |
407 status_window = dialog = g_new0(StatusWindow, 1); | |
408 | |
409 width = gaim_prefs_get_int("/gaim/gtk/status/dialog/width"); | |
410 height = gaim_prefs_get_int("/gaim/gtk/status/dialog/height"); | |
411 | |
412 dialog->window = win = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
413 gtk_window_set_default_size(GTK_WINDOW(win), width, height); | |
414 gtk_window_set_role(GTK_WINDOW(win), "statuses"); | |
415 gtk_window_set_title(GTK_WINDOW(win), _("Saved Statuses")); | |
11243 | 416 gtk_container_set_border_width(GTK_CONTAINER(win), GAIM_HIG_BORDER); |
10421 | 417 |
418 g_signal_connect(G_OBJECT(win), "delete_event", | |
419 G_CALLBACK(status_window_destroy_cb), dialog); | |
420 g_signal_connect(G_OBJECT(win), "configure_event", | |
421 G_CALLBACK(configure_cb), dialog); | |
422 | |
423 /* Setup the vbox */ | |
11243 | 424 vbox = gtk_vbox_new(FALSE, GAIM_HIG_BORDER); |
10421 | 425 gtk_container_add(GTK_CONTAINER(win), vbox); |
426 gtk_widget_show(vbox); | |
427 | |
428 /* List of saved status states */ | |
429 list = create_saved_status_list(dialog); | |
430 gtk_box_pack_start(GTK_BOX(vbox), list, TRUE, TRUE, 0); | |
431 | |
432 /* Button box. */ | |
433 bbox = gtk_hbutton_box_new(); | |
11243 | 434 gtk_box_set_spacing(GTK_BOX(bbox), GAIM_HIG_BOX_SPACE); |
10421 | 435 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); |
436 gtk_box_pack_end(GTK_BOX(vbox), bbox, FALSE, TRUE, 0); | |
437 gtk_widget_show(bbox); | |
438 | |
439 /* Add button */ | |
440 button = gtk_button_new_from_stock(GTK_STOCK_ADD); | |
441 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
442 gtk_widget_show(button); | |
443 | |
444 g_signal_connect(G_OBJECT(button), "clicked", | |
445 G_CALLBACK(status_window_add_cb), dialog); | |
446 | |
447 /* Modify button */ | |
448 button = gtk_button_new_from_stock(GAIM_STOCK_MODIFY); | |
449 dialog->modify_button = button; | |
450 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
451 gtk_widget_set_sensitive(button, FALSE); | |
452 gtk_widget_show(button); | |
453 | |
454 g_signal_connect(G_OBJECT(button), "clicked", | |
455 G_CALLBACK(status_window_modify_cb), dialog); | |
456 | |
457 /* Delete button */ | |
458 button = gtk_button_new_from_stock(GTK_STOCK_DELETE); | |
459 dialog->delete_button = button; | |
460 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
461 gtk_widget_set_sensitive(button, FALSE); | |
462 gtk_widget_show(button); | |
463 | |
464 g_signal_connect(G_OBJECT(button), "clicked", | |
465 G_CALLBACK(status_window_delete_cb), dialog); | |
466 | |
467 /* Close button */ | |
468 button = gtk_button_new_from_stock(GTK_STOCK_CLOSE); | |
469 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
470 gtk_widget_show(button); | |
471 | |
472 g_signal_connect(G_OBJECT(button), "clicked", | |
473 G_CALLBACK(status_window_close_cb), dialog); | |
474 | |
475 gtk_widget_show(win); | |
476 } | |
477 | |
478 void | |
479 gaim_gtk_status_window_hide(void) | |
480 { | |
481 if (status_window == NULL) | |
482 return; | |
483 | |
484 if (status_window->window != NULL) | |
485 gtk_widget_destroy(status_window->window); | |
486 | |
487 g_free(status_window); | |
488 status_window = NULL; | |
489 } | |
490 | |
491 | |
492 /************************************************************************** | |
493 * Status editor | |
494 **************************************************************************/ | |
10420 | 495 |
10418 | 496 static gboolean |
497 status_editor_destroy_cb(GtkWidget *widget, GdkEvent *event, gpointer user_data) | |
498 { | |
10574 | 499 StatusEditor *dialog = user_data; |
10418 | 500 |
10574 | 501 g_free(dialog->original_title); |
10418 | 502 g_free(dialog); |
503 | |
504 return FALSE; | |
505 } | |
506 | |
507 static void | |
508 status_editor_cancel_cb(GtkButton *button, gpointer user_data) | |
509 { | |
10574 | 510 StatusEditor *dialog = user_data; |
10418 | 511 |
512 gtk_widget_destroy(dialog->window); | |
513 | |
10574 | 514 g_free(dialog->original_title); |
10418 | 515 g_free(dialog); |
516 } | |
517 | |
518 static void | |
519 status_editor_save_cb(GtkButton *button, gpointer user_data) | |
520 { | |
10420 | 521 StatusEditor *dialog = user_data; |
522 const char *title; | |
523 GaimStatusPrimitive type; | |
524 char *message, *unformatted; | |
525 GaimSavedStatus *status; | |
526 | |
527 title = gtk_entry_get_text(dialog->title); | |
528 | |
529 /* | |
530 * If the title is already taken then show an error dialog and | |
531 * don't do anything. | |
532 */ | |
533 if ((gaim_savedstatus_find(title) != NULL) && | |
534 ((dialog->original_title == NULL) || (strcmp(title, dialog->original_title)))) | |
535 { | |
536 gaim_notify_error(NULL, NULL, _("Title already in use. You must " | |
537 "choose a unique title."), NULL); | |
538 return; | |
539 } | |
540 | |
541 type = gtk_option_menu_get_history(dialog->type); | |
542 message = gtk_imhtml_get_markup(dialog->message); | |
543 unformatted = gaim_markup_strip_html(message); | |
544 | |
545 /* | |
546 * If we're editing an existing status, remove the old one to | |
547 * make way for the modified one. | |
548 */ | |
549 if (dialog->original_title != NULL) | |
550 { | |
551 GtkTreeIter iter; | |
552 | |
553 gaim_savedstatus_delete(dialog->original_title); | |
554 | |
555 if (status_window_find_savedstatus(&iter, dialog->original_title)) | |
556 { | |
557 gtk_list_store_remove(status_window->model, &iter); | |
558 } | |
559 } | |
560 | |
561 status = gaim_savedstatus_new(title, type); | |
562 if (*unformatted != '\0') | |
563 gaim_savedstatus_set_message(status, message); | |
564 g_free(message); | |
565 g_free(unformatted); | |
566 | |
567 gtk_widget_destroy(dialog->window); | |
10574 | 568 g_free(dialog->original_title); |
10420 | 569 g_free(dialog); |
570 | |
571 add_status_to_saved_status_list(status_window->model, status); | |
572 } | |
573 | |
574 static void | |
575 status_editor_custom_status_cb(GtkCellRendererToggle *renderer, gchar *path_str, gpointer data) | |
576 { | |
577 /* StatusEditor *dialog = (StatusEditor *)data; */ | |
578 | |
579 /* TODO: Need to allow user to set a custom status for the highlighted account, somehow */ | |
580 } | |
581 | |
582 static void | |
583 editor_title_changed_cb(GtkWidget *widget, gpointer user_data) | |
584 { | |
585 StatusEditor *dialog = user_data; | |
586 const gchar *text; | |
587 | |
588 text = gtk_entry_get_text(dialog->title); | |
589 | |
590 gtk_widget_set_sensitive(dialog->save_button, (*text != '\0')); | |
10418 | 591 } |
592 | |
593 static GtkWidget * | |
10419 | 594 create_status_type_menu(GaimStatusPrimitive type) |
10418 | 595 { |
10419 | 596 int i; |
10418 | 597 GtkWidget *dropdown; |
598 GtkWidget *menu; | |
599 GtkWidget *item; | |
600 | |
601 dropdown = gtk_option_menu_new(); | |
602 menu = gtk_menu_new(); | |
603 | |
10419 | 604 for (i = 0; i < GAIM_STATUS_NUM_PRIMITIVES; i++) |
605 { | |
606 item = gtk_menu_item_new_with_label(gaim_primitive_get_name_from_type(i)); | |
607 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); | |
608 gtk_widget_show(item); | |
609 } | |
10418 | 610 |
10419 | 611 gtk_menu_set_active(GTK_MENU(menu), type); |
10418 | 612 gtk_option_menu_set_menu(GTK_OPTION_MENU(dropdown), menu); |
613 gtk_widget_show(menu); | |
614 | |
615 return dropdown; | |
616 } | |
617 | |
618 static void | |
619 status_editor_add_columns(StatusEditor *dialog) | |
620 { | |
621 GtkCellRenderer *renderer; | |
622 GtkTreeViewColumn *column; | |
623 | |
624 /* Custom status column */ | |
625 renderer = gtk_cell_renderer_toggle_new(); | |
626 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(dialog->treeview), | |
627 -1, _("Custom status"), | |
628 renderer, | |
629 "active", STATUS_EDITOR_COLUMN_CUSTOM_STATUS, | |
630 NULL); | |
631 column = gtk_tree_view_get_column(GTK_TREE_VIEW(dialog->treeview), 1); | |
632 g_signal_connect(G_OBJECT(renderer), "toggled", | |
633 G_CALLBACK(status_editor_custom_status_cb), dialog); | |
634 | |
635 /* Screen Name column */ | |
636 column = gtk_tree_view_column_new(); | |
637 gtk_tree_view_column_set_resizable(column, TRUE); | |
638 gtk_tree_view_column_set_title(column, _("Screen Name")); | |
639 gtk_tree_view_insert_column(GTK_TREE_VIEW(dialog->treeview), column, -1); | |
640 gtk_tree_view_column_set_resizable(column, TRUE); | |
641 | |
642 /* Icon */ | |
643 renderer = gtk_cell_renderer_pixbuf_new(); | |
644 gtk_tree_view_column_pack_start(column, renderer, FALSE); | |
645 gtk_tree_view_column_add_attribute(column, renderer, "pixbuf", | |
646 STATUS_EDITOR_COLUMN_ICON); | |
647 | |
648 /* Screen Name */ | |
649 renderer = gtk_cell_renderer_text_new(); | |
650 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
651 gtk_tree_view_column_add_attribute(column, renderer, "text", | |
652 STATUS_EDITOR_COLUMN_SCREENNAME); | |
653 } | |
654 | |
655 static void | |
656 status_editor_set_account(GtkListStore *store, GaimAccount *account, GtkTreeIter *iter) | |
657 { | |
658 GdkPixbuf *pixbuf; | |
659 GdkPixbuf *scale; | |
660 | |
661 scale = NULL; | |
662 | |
10884 | 663 pixbuf = gaim_gtk_create_prpl_icon(account); |
10418 | 664 |
665 if (pixbuf != NULL) | |
666 { | |
667 scale = gdk_pixbuf_scale_simple(pixbuf, 16, 16, GDK_INTERP_BILINEAR); | |
668 | |
11251 | 669 if (gaim_account_is_disconnected(account)) |
10418 | 670 gdk_pixbuf_saturate_and_pixelate(scale, scale, 0.0, FALSE); |
671 } | |
672 | |
673 gtk_list_store_set(store, iter, | |
674 STATUS_EDITOR_COLUMN_ICON, scale, | |
675 STATUS_EDITOR_COLUMN_SCREENNAME, gaim_account_get_username(account), | |
676 -1); | |
677 | |
678 if (pixbuf != NULL) g_object_unref(G_OBJECT(pixbuf)); | |
679 if (scale != NULL) g_object_unref(G_OBJECT(scale)); | |
680 } | |
681 | |
682 static void | |
683 status_editor_add_account(StatusEditor *dialog, GaimAccount *account) | |
684 { | |
685 GtkTreeIter iter; | |
686 | |
687 gtk_list_store_append(dialog->model, &iter); | |
688 | |
689 status_editor_set_account(dialog->model, account, &iter); | |
690 } | |
691 | |
692 static void | |
693 status_editor_populate_list(StatusEditor *dialog) | |
694 { | |
695 GList *l; | |
696 | |
697 gtk_list_store_clear(dialog->model); | |
698 | |
699 for (l = gaim_accounts_get_all(); l != NULL; l = l->next) | |
700 status_editor_add_account(dialog, (GaimAccount *)l->data); | |
701 } | |
702 | |
703 void | |
10419 | 704 gaim_gtk_status_editor_show(GaimSavedStatus *status) |
10418 | 705 { |
706 StatusEditor *dialog; | |
707 GtkSizeGroup *sg; | |
708 GtkWidget *bbox; | |
709 GtkWidget *button; | |
710 GtkWidget *dbox; | |
11735 | 711 GtkWidget *expander; |
10418 | 712 GtkWidget *dropdown; |
713 GtkWidget *entry; | |
714 GtkWidget *frame; | |
715 GtkWidget *hbox; | |
716 GtkWidget *label; | |
717 GtkWidget *sw; | |
718 GtkWidget *text; | |
719 GtkWidget *toolbar; | |
720 GtkWidget *vbox; | |
721 GtkWidget *win; | |
722 | |
723 dialog = g_new0(StatusEditor, 1); | |
724 | |
10420 | 725 if (status != NULL) |
726 dialog->original_title = g_strdup(gaim_savedstatus_get_title(status)); | |
727 | |
10418 | 728 dialog->window = win = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
729 gtk_window_set_role(GTK_WINDOW(win), "status"); | |
730 gtk_window_set_title(GTK_WINDOW(win), _("Status")); | |
731 gtk_window_set_resizable(GTK_WINDOW(win), FALSE); | |
11243 | 732 gtk_container_set_border_width(GTK_CONTAINER(win), GAIM_HIG_BORDER); |
10418 | 733 |
734 g_signal_connect(G_OBJECT(win), "delete_event", | |
735 G_CALLBACK(status_editor_destroy_cb), dialog); | |
736 | |
737 /* Setup the vbox */ | |
11243 | 738 vbox = gtk_vbox_new(FALSE, GAIM_HIG_BORDER); |
10418 | 739 gtk_container_add(GTK_CONTAINER(win), vbox); |
740 gtk_widget_show(vbox); | |
741 | |
742 sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); | |
743 | |
744 /* Title */ | |
11243 | 745 hbox = gtk_hbox_new(FALSE, GAIM_HIG_BOX_SPACE); |
10418 | 746 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); |
747 gtk_widget_show(hbox); | |
748 | |
749 label = gtk_label_new_with_mnemonic(_("_Title:")); | |
750 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
751 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
752 gtk_widget_show(label); | |
753 gtk_size_group_add_widget(sg, label); | |
754 | |
755 entry = gtk_entry_new(); | |
10420 | 756 dialog->title = GTK_ENTRY(entry); |
10419 | 757 if (status != NULL) |
10420 | 758 gtk_entry_set_text(GTK_ENTRY(entry), dialog->original_title); |
10418 | 759 gtk_box_pack_start(GTK_BOX(hbox), entry, TRUE, TRUE, 0); |
760 gtk_widget_show(entry); | |
10420 | 761 g_signal_connect(G_OBJECT(entry), "changed", |
762 G_CALLBACK(editor_title_changed_cb), dialog); | |
10418 | 763 |
764 /* Status type */ | |
11243 | 765 hbox = gtk_hbox_new(FALSE, GAIM_HIG_BOX_SPACE); |
10418 | 766 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); |
767 gtk_widget_show(hbox); | |
768 | |
769 label = gtk_label_new_with_mnemonic(_("_Status:")); | |
770 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
771 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
772 gtk_widget_show(label); | |
773 gtk_size_group_add_widget(sg, label); | |
774 | |
10419 | 775 if (status != NULL) |
776 dropdown = create_status_type_menu(gaim_savedstatus_get_type(status)); | |
777 else | |
778 dropdown = create_status_type_menu(GAIM_STATUS_AWAY); | |
10420 | 779 dialog->type = GTK_OPTION_MENU(dropdown); |
10418 | 780 gtk_box_pack_start(GTK_BOX(hbox), dropdown, TRUE, TRUE, 0); |
781 gtk_widget_show(dropdown); | |
782 | |
783 /* Status message */ | |
11243 | 784 hbox = gtk_hbox_new(FALSE, GAIM_HIG_BOX_SPACE); |
10418 | 785 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); |
786 gtk_widget_show(hbox); | |
787 | |
788 label = gtk_label_new_with_mnemonic(_("_Message:")); | |
789 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
790 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
791 gtk_widget_show(label); | |
792 gtk_size_group_add_widget(sg, label); | |
793 | |
794 frame = gaim_gtk_create_imhtml(TRUE, &text, &toolbar); | |
10420 | 795 dialog->message = GTK_IMHTML(text); |
10418 | 796 gtk_box_pack_start(GTK_BOX(hbox), frame, TRUE, TRUE, 0); |
797 gtk_widget_show(frame); | |
798 | |
10574 | 799 if ((status != NULL) && (gaim_savedstatus_get_message(status) != NULL)) |
10419 | 800 gtk_imhtml_append_text(GTK_IMHTML(text), |
801 gaim_savedstatus_get_message(status), 0); | |
802 | |
11735 | 803 /* Custom status message expander */ |
804 expander = gtk_expander_new_with_mnemonic(_("Use a _different status for some accounts")); | |
805 gtk_box_pack_start(GTK_BOX(vbox), expander, FALSE, FALSE, 0); | |
806 gtk_widget_show(expander); | |
10418 | 807 |
11735 | 808 /* Setup the box that the expander will cover */ |
11243 | 809 dbox = gtk_vbox_new(FALSE, GAIM_HIG_CAT_SPACE); |
11735 | 810 gtk_container_add(GTK_CONTAINER(expander), dbox); |
811 gtk_widget_show(dbox); | |
10418 | 812 |
813 /* Custom status message treeview */ | |
814 sw = gtk_scrolled_window_new(NULL, NULL); | |
815 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), | |
816 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); | |
817 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), | |
818 GTK_SHADOW_IN); | |
819 gtk_box_pack_start(GTK_BOX(dbox), sw, TRUE, TRUE, 0); | |
820 gtk_widget_show(sw); | |
821 | |
822 /* Create the list model */ | |
823 dialog->model = gtk_list_store_new(STATUS_EDITOR_NUM_COLUMNS, | |
824 G_TYPE_BOOLEAN, | |
825 GDK_TYPE_PIXBUF, G_TYPE_STRING); | |
826 | |
827 /* Create the treeview */ | |
828 dialog->treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(dialog->model)); | |
829 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(dialog->treeview), TRUE); | |
830 gtk_widget_set_size_request(dialog->treeview, 400, 250); | |
831 gtk_container_add(GTK_CONTAINER(sw), dialog->treeview); | |
832 gtk_widget_show(dialog->treeview); | |
833 | |
834 /* Add columns */ | |
835 status_editor_add_columns(dialog); | |
836 | |
837 /* Populate list */ | |
838 status_editor_populate_list(dialog); | |
839 | |
840 /* Button box */ | |
841 bbox = gtk_hbutton_box_new(); | |
11243 | 842 gtk_box_set_spacing(GTK_BOX(bbox), GAIM_HIG_BOX_SPACE); |
10418 | 843 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); |
844 gtk_box_pack_end(GTK_BOX(vbox), bbox, FALSE, TRUE, 0); | |
845 gtk_widget_show(bbox); | |
846 | |
847 /* Cancel button */ | |
848 button = gtk_button_new_from_stock(GTK_STOCK_CANCEL); | |
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_cancel_cb), dialog); | |
854 | |
855 /* Save button */ | |
856 button = gtk_button_new_from_stock(GTK_STOCK_SAVE); | |
10420 | 857 dialog->save_button = button; |
10418 | 858 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); |
859 gtk_widget_show(button); | |
860 | |
861 g_signal_connect(G_OBJECT(button), "clicked", | |
862 G_CALLBACK(status_editor_save_cb), dialog); | |
863 | |
864 gtk_widget_show(win); | |
865 } | |
866 | |
867 | |
10421 | 868 /************************************************************************** |
10814
364a2ef907ae
[gaim-migrate @ 12468]
Luke Schierer <lschiere@pidgin.im>
parents:
10732
diff
changeset
|
869 * GTK+ saved status glue |
10421 | 870 **************************************************************************/ |
10418 | 871 |
872 void * | |
873 gaim_gtk_status_get_handle() | |
874 { | |
875 static int handle; | |
876 | |
877 return &handle; | |
878 } | |
879 | |
880 void | |
881 gaim_gtk_status_init(void) | |
882 { | |
883 gaim_prefs_add_none("/gaim/gtk/status"); | |
884 gaim_prefs_add_none("/gaim/gtk/status/dialog"); | |
885 gaim_prefs_add_int("/gaim/gtk/status/dialog/width", 550); | |
886 gaim_prefs_add_int("/gaim/gtk/status/dialog/height", 250); | |
887 } | |
888 | |
889 void | |
890 gaim_gtk_status_uninit(void) | |
891 { | |
892 gaim_gtk_status_window_hide(); | |
893 } |