Mercurial > pidgin
annotate src/gtksavedstatuses.c @ 12042:01ce8025a1d9
[gaim-migrate @ 14337]
Don't hardcode ~/.gaim. That wouldn't be right on Windows or if you're using -c. If anyone thinks this sucks, just revert it, I'm not attached to it.
committer: Tailor Script <tailor@pidgin.im>
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Fri, 11 Nov 2005 22:15:42 +0000 |
parents | 351f4dd75718 |
children | 3b52d94437f3 |
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 */ |
11832 | 494 button = gaim_pixbuf_button_from_stock(_("_Use"), GTK_STOCK_EXECUTE, |
495 GAIM_BUTTON_HORIZONTAL); | |
11811 | 496 dialog->use_button = button; |
497 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
498 gtk_widget_set_sensitive(button, FALSE); | |
499 gtk_widget_show(button); | |
500 | |
501 g_signal_connect(G_OBJECT(button), "clicked", | |
502 G_CALLBACK(status_window_use_cb), dialog); | |
503 | |
10421 | 504 /* Add button */ |
505 button = gtk_button_new_from_stock(GTK_STOCK_ADD); | |
506 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
507 gtk_widget_show(button); | |
508 | |
509 g_signal_connect(G_OBJECT(button), "clicked", | |
510 G_CALLBACK(status_window_add_cb), dialog); | |
511 | |
512 /* Modify button */ | |
513 button = gtk_button_new_from_stock(GAIM_STOCK_MODIFY); | |
514 dialog->modify_button = button; | |
515 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
516 gtk_widget_set_sensitive(button, FALSE); | |
517 gtk_widget_show(button); | |
518 | |
519 g_signal_connect(G_OBJECT(button), "clicked", | |
520 G_CALLBACK(status_window_modify_cb), dialog); | |
521 | |
522 /* Delete button */ | |
523 button = gtk_button_new_from_stock(GTK_STOCK_DELETE); | |
524 dialog->delete_button = button; | |
525 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
526 gtk_widget_set_sensitive(button, FALSE); | |
527 gtk_widget_show(button); | |
528 | |
529 g_signal_connect(G_OBJECT(button), "clicked", | |
530 G_CALLBACK(status_window_delete_cb), dialog); | |
531 | |
532 /* Close button */ | |
533 button = gtk_button_new_from_stock(GTK_STOCK_CLOSE); | |
534 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
535 gtk_widget_show(button); | |
536 | |
537 g_signal_connect(G_OBJECT(button), "clicked", | |
538 G_CALLBACK(status_window_close_cb), dialog); | |
539 | |
540 gtk_widget_show(win); | |
541 } | |
542 | |
543 void | |
544 gaim_gtk_status_window_hide(void) | |
545 { | |
546 if (status_window == NULL) | |
547 return; | |
548 | |
549 if (status_window->window != NULL) | |
550 gtk_widget_destroy(status_window->window); | |
551 | |
552 g_free(status_window); | |
553 status_window = NULL; | |
554 } | |
555 | |
556 | |
557 /************************************************************************** | |
558 * Status editor | |
559 **************************************************************************/ | |
10420 | 560 |
10418 | 561 static gboolean |
562 status_editor_destroy_cb(GtkWidget *widget, GdkEvent *event, gpointer user_data) | |
563 { | |
10574 | 564 StatusEditor *dialog = user_data; |
10418 | 565 |
10574 | 566 g_free(dialog->original_title); |
10418 | 567 g_free(dialog); |
568 | |
569 return FALSE; | |
570 } | |
571 | |
572 static void | |
573 status_editor_cancel_cb(GtkButton *button, gpointer user_data) | |
574 { | |
10574 | 575 StatusEditor *dialog = user_data; |
10418 | 576 |
577 gtk_widget_destroy(dialog->window); | |
578 | |
10574 | 579 g_free(dialog->original_title); |
10418 | 580 g_free(dialog); |
581 } | |
582 | |
583 static void | |
584 status_editor_save_cb(GtkButton *button, gpointer user_data) | |
585 { | |
10420 | 586 StatusEditor *dialog = user_data; |
587 const char *title; | |
588 GaimStatusPrimitive type; | |
589 char *message, *unformatted; | |
590 GaimSavedStatus *status; | |
591 | |
592 title = gtk_entry_get_text(dialog->title); | |
593 | |
594 /* | |
595 * If the title is already taken then show an error dialog and | |
596 * don't do anything. | |
597 */ | |
598 if ((gaim_savedstatus_find(title) != NULL) && | |
599 ((dialog->original_title == NULL) || (strcmp(title, dialog->original_title)))) | |
600 { | |
601 gaim_notify_error(NULL, NULL, _("Title already in use. You must " | |
602 "choose a unique title."), NULL); | |
603 return; | |
604 } | |
605 | |
606 type = gtk_option_menu_get_history(dialog->type); | |
607 message = gtk_imhtml_get_markup(dialog->message); | |
608 unformatted = gaim_markup_strip_html(message); | |
609 | |
610 /* | |
611 * If we're editing an existing status, remove the old one to | |
612 * make way for the modified one. | |
613 */ | |
614 if (dialog->original_title != NULL) | |
615 { | |
616 GtkTreeIter iter; | |
617 | |
618 gaim_savedstatus_delete(dialog->original_title); | |
619 | |
620 if (status_window_find_savedstatus(&iter, dialog->original_title)) | |
621 { | |
622 gtk_list_store_remove(status_window->model, &iter); | |
623 } | |
624 } | |
625 | |
626 status = gaim_savedstatus_new(title, type); | |
627 if (*unformatted != '\0') | |
628 gaim_savedstatus_set_message(status, message); | |
629 g_free(message); | |
630 g_free(unformatted); | |
631 | |
632 gtk_widget_destroy(dialog->window); | |
10574 | 633 g_free(dialog->original_title); |
10420 | 634 g_free(dialog); |
635 | |
636 add_status_to_saved_status_list(status_window->model, status); | |
637 } | |
638 | |
639 static void | |
640 status_editor_custom_status_cb(GtkCellRendererToggle *renderer, gchar *path_str, gpointer data) | |
641 { | |
642 /* StatusEditor *dialog = (StatusEditor *)data; */ | |
643 | |
644 /* TODO: Need to allow user to set a custom status for the highlighted account, somehow */ | |
645 } | |
646 | |
647 static void | |
648 editor_title_changed_cb(GtkWidget *widget, gpointer user_data) | |
649 { | |
650 StatusEditor *dialog = user_data; | |
651 const gchar *text; | |
652 | |
653 text = gtk_entry_get_text(dialog->title); | |
654 | |
655 gtk_widget_set_sensitive(dialog->save_button, (*text != '\0')); | |
10418 | 656 } |
657 | |
658 static GtkWidget * | |
10419 | 659 create_status_type_menu(GaimStatusPrimitive type) |
10418 | 660 { |
10419 | 661 int i; |
10418 | 662 GtkWidget *dropdown; |
663 GtkWidget *menu; | |
664 GtkWidget *item; | |
665 | |
666 dropdown = gtk_option_menu_new(); | |
667 menu = gtk_menu_new(); | |
668 | |
10419 | 669 for (i = 0; i < GAIM_STATUS_NUM_PRIMITIVES; i++) |
670 { | |
671 item = gtk_menu_item_new_with_label(gaim_primitive_get_name_from_type(i)); | |
672 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); | |
673 gtk_widget_show(item); | |
674 } | |
10418 | 675 |
10419 | 676 gtk_menu_set_active(GTK_MENU(menu), type); |
10418 | 677 gtk_option_menu_set_menu(GTK_OPTION_MENU(dropdown), menu); |
678 gtk_widget_show(menu); | |
679 | |
680 return dropdown; | |
681 } | |
682 | |
683 static void | |
684 status_editor_add_columns(StatusEditor *dialog) | |
685 { | |
686 GtkCellRenderer *renderer; | |
687 GtkTreeViewColumn *column; | |
688 | |
689 /* Custom status column */ | |
690 renderer = gtk_cell_renderer_toggle_new(); | |
691 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(dialog->treeview), | |
692 -1, _("Custom status"), | |
693 renderer, | |
694 "active", STATUS_EDITOR_COLUMN_CUSTOM_STATUS, | |
695 NULL); | |
696 column = gtk_tree_view_get_column(GTK_TREE_VIEW(dialog->treeview), 1); | |
697 g_signal_connect(G_OBJECT(renderer), "toggled", | |
698 G_CALLBACK(status_editor_custom_status_cb), dialog); | |
699 | |
700 /* Screen Name column */ | |
701 column = gtk_tree_view_column_new(); | |
702 gtk_tree_view_column_set_resizable(column, TRUE); | |
703 gtk_tree_view_column_set_title(column, _("Screen Name")); | |
704 gtk_tree_view_insert_column(GTK_TREE_VIEW(dialog->treeview), column, -1); | |
705 gtk_tree_view_column_set_resizable(column, TRUE); | |
706 | |
707 /* Icon */ | |
708 renderer = gtk_cell_renderer_pixbuf_new(); | |
709 gtk_tree_view_column_pack_start(column, renderer, FALSE); | |
710 gtk_tree_view_column_add_attribute(column, renderer, "pixbuf", | |
711 STATUS_EDITOR_COLUMN_ICON); | |
712 | |
713 /* Screen Name */ | |
714 renderer = gtk_cell_renderer_text_new(); | |
715 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
716 gtk_tree_view_column_add_attribute(column, renderer, "text", | |
717 STATUS_EDITOR_COLUMN_SCREENNAME); | |
718 } | |
719 | |
720 static void | |
721 status_editor_set_account(GtkListStore *store, GaimAccount *account, GtkTreeIter *iter) | |
722 { | |
723 GdkPixbuf *pixbuf; | |
724 GdkPixbuf *scale; | |
725 | |
726 scale = NULL; | |
727 | |
10884 | 728 pixbuf = gaim_gtk_create_prpl_icon(account); |
10418 | 729 |
730 if (pixbuf != NULL) | |
731 { | |
732 scale = gdk_pixbuf_scale_simple(pixbuf, 16, 16, GDK_INTERP_BILINEAR); | |
733 | |
11251 | 734 if (gaim_account_is_disconnected(account)) |
10418 | 735 gdk_pixbuf_saturate_and_pixelate(scale, scale, 0.0, FALSE); |
736 } | |
737 | |
738 gtk_list_store_set(store, iter, | |
739 STATUS_EDITOR_COLUMN_ICON, scale, | |
740 STATUS_EDITOR_COLUMN_SCREENNAME, gaim_account_get_username(account), | |
741 -1); | |
742 | |
743 if (pixbuf != NULL) g_object_unref(G_OBJECT(pixbuf)); | |
744 if (scale != NULL) g_object_unref(G_OBJECT(scale)); | |
745 } | |
746 | |
747 static void | |
748 status_editor_add_account(StatusEditor *dialog, GaimAccount *account) | |
749 { | |
750 GtkTreeIter iter; | |
751 | |
752 gtk_list_store_append(dialog->model, &iter); | |
753 | |
754 status_editor_set_account(dialog->model, account, &iter); | |
755 } | |
756 | |
757 static void | |
758 status_editor_populate_list(StatusEditor *dialog) | |
759 { | |
760 GList *l; | |
761 | |
762 gtk_list_store_clear(dialog->model); | |
763 | |
764 for (l = gaim_accounts_get_all(); l != NULL; l = l->next) | |
765 status_editor_add_account(dialog, (GaimAccount *)l->data); | |
766 } | |
767 | |
768 void | |
10419 | 769 gaim_gtk_status_editor_show(GaimSavedStatus *status) |
10418 | 770 { |
771 StatusEditor *dialog; | |
772 GtkSizeGroup *sg; | |
773 GtkWidget *bbox; | |
774 GtkWidget *button; | |
775 GtkWidget *dbox; | |
11735 | 776 GtkWidget *expander; |
10418 | 777 GtkWidget *dropdown; |
778 GtkWidget *entry; | |
779 GtkWidget *frame; | |
780 GtkWidget *hbox; | |
781 GtkWidget *label; | |
782 GtkWidget *sw; | |
783 GtkWidget *text; | |
784 GtkWidget *toolbar; | |
785 GtkWidget *vbox; | |
786 GtkWidget *win; | |
787 | |
788 dialog = g_new0(StatusEditor, 1); | |
789 | |
10420 | 790 if (status != NULL) |
791 dialog->original_title = g_strdup(gaim_savedstatus_get_title(status)); | |
792 | |
10418 | 793 dialog->window = win = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
794 gtk_window_set_role(GTK_WINDOW(win), "status"); | |
795 gtk_window_set_title(GTK_WINDOW(win), _("Status")); | |
796 gtk_window_set_resizable(GTK_WINDOW(win), FALSE); | |
11243 | 797 gtk_container_set_border_width(GTK_CONTAINER(win), GAIM_HIG_BORDER); |
10418 | 798 |
799 g_signal_connect(G_OBJECT(win), "delete_event", | |
800 G_CALLBACK(status_editor_destroy_cb), dialog); | |
801 | |
802 /* Setup the vbox */ | |
11243 | 803 vbox = gtk_vbox_new(FALSE, GAIM_HIG_BORDER); |
10418 | 804 gtk_container_add(GTK_CONTAINER(win), vbox); |
805 gtk_widget_show(vbox); | |
806 | |
807 sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); | |
808 | |
809 /* Title */ | |
11243 | 810 hbox = gtk_hbox_new(FALSE, GAIM_HIG_BOX_SPACE); |
10418 | 811 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); |
812 gtk_widget_show(hbox); | |
813 | |
814 label = gtk_label_new_with_mnemonic(_("_Title:")); | |
815 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
816 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
817 gtk_widget_show(label); | |
818 gtk_size_group_add_widget(sg, label); | |
819 | |
820 entry = gtk_entry_new(); | |
10420 | 821 dialog->title = GTK_ENTRY(entry); |
10419 | 822 if (status != NULL) |
10420 | 823 gtk_entry_set_text(GTK_ENTRY(entry), dialog->original_title); |
10418 | 824 gtk_box_pack_start(GTK_BOX(hbox), entry, TRUE, TRUE, 0); |
825 gtk_widget_show(entry); | |
10420 | 826 g_signal_connect(G_OBJECT(entry), "changed", |
827 G_CALLBACK(editor_title_changed_cb), dialog); | |
10418 | 828 |
829 /* Status type */ | |
11243 | 830 hbox = gtk_hbox_new(FALSE, GAIM_HIG_BOX_SPACE); |
10418 | 831 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); |
832 gtk_widget_show(hbox); | |
833 | |
834 label = gtk_label_new_with_mnemonic(_("_Status:")); | |
835 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
836 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
837 gtk_widget_show(label); | |
838 gtk_size_group_add_widget(sg, label); | |
839 | |
10419 | 840 if (status != NULL) |
841 dropdown = create_status_type_menu(gaim_savedstatus_get_type(status)); | |
842 else | |
843 dropdown = create_status_type_menu(GAIM_STATUS_AWAY); | |
10420 | 844 dialog->type = GTK_OPTION_MENU(dropdown); |
10418 | 845 gtk_box_pack_start(GTK_BOX(hbox), dropdown, TRUE, TRUE, 0); |
846 gtk_widget_show(dropdown); | |
847 | |
848 /* Status message */ | |
11243 | 849 hbox = gtk_hbox_new(FALSE, GAIM_HIG_BOX_SPACE); |
10418 | 850 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); |
851 gtk_widget_show(hbox); | |
852 | |
853 label = gtk_label_new_with_mnemonic(_("_Message:")); | |
854 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
855 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
856 gtk_widget_show(label); | |
857 gtk_size_group_add_widget(sg, label); | |
858 | |
859 frame = gaim_gtk_create_imhtml(TRUE, &text, &toolbar); | |
10420 | 860 dialog->message = GTK_IMHTML(text); |
10418 | 861 gtk_box_pack_start(GTK_BOX(hbox), frame, TRUE, TRUE, 0); |
862 gtk_widget_show(frame); | |
863 | |
10574 | 864 if ((status != NULL) && (gaim_savedstatus_get_message(status) != NULL)) |
10419 | 865 gtk_imhtml_append_text(GTK_IMHTML(text), |
866 gaim_savedstatus_get_message(status), 0); | |
867 | |
11735 | 868 /* Custom status message expander */ |
869 expander = gtk_expander_new_with_mnemonic(_("Use a _different status for some accounts")); | |
870 gtk_box_pack_start(GTK_BOX(vbox), expander, FALSE, FALSE, 0); | |
871 gtk_widget_show(expander); | |
10418 | 872 |
11735 | 873 /* Setup the box that the expander will cover */ |
11243 | 874 dbox = gtk_vbox_new(FALSE, GAIM_HIG_CAT_SPACE); |
11735 | 875 gtk_container_add(GTK_CONTAINER(expander), dbox); |
876 gtk_widget_show(dbox); | |
10418 | 877 |
878 /* Custom status message treeview */ | |
879 sw = gtk_scrolled_window_new(NULL, NULL); | |
880 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), | |
881 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); | |
882 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), | |
883 GTK_SHADOW_IN); | |
884 gtk_box_pack_start(GTK_BOX(dbox), sw, TRUE, TRUE, 0); | |
885 gtk_widget_show(sw); | |
886 | |
887 /* Create the list model */ | |
888 dialog->model = gtk_list_store_new(STATUS_EDITOR_NUM_COLUMNS, | |
889 G_TYPE_BOOLEAN, | |
890 GDK_TYPE_PIXBUF, G_TYPE_STRING); | |
891 | |
892 /* Create the treeview */ | |
893 dialog->treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(dialog->model)); | |
894 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(dialog->treeview), TRUE); | |
895 gtk_widget_set_size_request(dialog->treeview, 400, 250); | |
896 gtk_container_add(GTK_CONTAINER(sw), dialog->treeview); | |
897 gtk_widget_show(dialog->treeview); | |
898 | |
899 /* Add columns */ | |
900 status_editor_add_columns(dialog); | |
901 | |
902 /* Populate list */ | |
903 status_editor_populate_list(dialog); | |
904 | |
905 /* Button box */ | |
906 bbox = gtk_hbutton_box_new(); | |
11243 | 907 gtk_box_set_spacing(GTK_BOX(bbox), GAIM_HIG_BOX_SPACE); |
10418 | 908 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); |
909 gtk_box_pack_end(GTK_BOX(vbox), bbox, FALSE, TRUE, 0); | |
910 gtk_widget_show(bbox); | |
911 | |
912 /* Cancel button */ | |
913 button = gtk_button_new_from_stock(GTK_STOCK_CANCEL); | |
914 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
915 gtk_widget_show(button); | |
916 | |
917 g_signal_connect(G_OBJECT(button), "clicked", | |
918 G_CALLBACK(status_editor_cancel_cb), dialog); | |
919 | |
920 /* Save button */ | |
921 button = gtk_button_new_from_stock(GTK_STOCK_SAVE); | |
10420 | 922 dialog->save_button = button; |
10418 | 923 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); |
924 gtk_widget_show(button); | |
925 | |
926 g_signal_connect(G_OBJECT(button), "clicked", | |
927 G_CALLBACK(status_editor_save_cb), dialog); | |
928 | |
929 gtk_widget_show(win); | |
930 } | |
931 | |
932 | |
10421 | 933 /************************************************************************** |
10814
364a2ef907ae
[gaim-migrate @ 12468]
Luke Schierer <lschiere@pidgin.im>
parents:
10732
diff
changeset
|
934 * GTK+ saved status glue |
10421 | 935 **************************************************************************/ |
10418 | 936 |
937 void * | |
938 gaim_gtk_status_get_handle() | |
939 { | |
940 static int handle; | |
941 | |
942 return &handle; | |
943 } | |
944 | |
945 void | |
946 gaim_gtk_status_init(void) | |
947 { | |
948 gaim_prefs_add_none("/gaim/gtk/status"); | |
949 gaim_prefs_add_none("/gaim/gtk/status/dialog"); | |
950 gaim_prefs_add_int("/gaim/gtk/status/dialog/width", 550); | |
951 gaim_prefs_add_int("/gaim/gtk/status/dialog/height", 250); | |
952 } | |
953 | |
954 void | |
955 gaim_gtk_status_uninit(void) | |
956 { | |
957 gaim_gtk_status_window_hide(); | |
958 } |