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