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