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