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"
|
|
28 #include "request.h"
|
|
29 #include "savedstatuses.h"
|
|
30 #include "status.h"
|
|
31 #include "util.h"
|
|
32
|
|
33 #include "gtkblist.h"
|
|
34 #include "gtkgaim.h"
|
|
35 #include "gtkgaim-disclosure.h"
|
|
36 #include "gtkimhtml.h"
|
|
37 #include "gtkimhtmltoolbar.h"
|
|
38 #include "gtksavedstatuses.h"
|
|
39 #include "gtkstock.h"
|
|
40 #include "gtkutils.h"
|
|
41
|
|
42 enum
|
|
43 {
|
|
44 STATUS_EDITOR_COLUMN_CUSTOM_STATUS,
|
|
45 STATUS_EDITOR_COLUMN_ICON,
|
|
46 STATUS_EDITOR_COLUMN_SCREENNAME,
|
|
47 STATUS_EDITOR_NUM_COLUMNS
|
|
48 };
|
|
49
|
|
50 enum
|
|
51 {
|
|
52 STATUS_WINDOW_COLUMN_TITLE,
|
|
53 STATUS_WINDOW_COLUMN_MESSAGE,
|
|
54 STATUS_WINDOW_NUM_COLUMNS
|
|
55 };
|
|
56
|
|
57 typedef struct
|
|
58 {
|
|
59 GtkWidget *window;
|
|
60 GtkListStore *model;
|
|
61 GtkWidget *treeview;
|
|
62 } StatusEditor;
|
|
63
|
|
64 typedef struct
|
|
65 {
|
|
66 GtkWidget *window;
|
|
67 GtkListStore *model;
|
|
68 GtkWidget *treeview;
|
|
69 GtkWidget *modify_button;
|
|
70 GtkWidget *delete_button;
|
|
71 } StatusWindow;
|
|
72
|
|
73 static StatusWindow *status_window = NULL;
|
|
74
|
|
75 static gboolean
|
|
76 status_editor_destroy_cb(GtkWidget *widget, GdkEvent *event, gpointer user_data)
|
|
77 {
|
|
78 StatusWindow *dialog = user_data;
|
|
79
|
|
80 g_free(dialog);
|
|
81
|
|
82 return FALSE;
|
|
83 }
|
|
84
|
|
85 static void
|
|
86 status_editor_cancel_cb(GtkButton *button, gpointer user_data)
|
|
87 {
|
|
88 StatusWindow *dialog = user_data;
|
|
89
|
|
90 gtk_widget_destroy(dialog->window);
|
|
91
|
|
92 g_free(dialog);
|
|
93 }
|
|
94
|
|
95 static void
|
|
96 status_editor_save_cb(GtkButton *button, gpointer user_data)
|
|
97 {
|
|
98 /* TODO: Save the status */
|
|
99 }
|
|
100
|
|
101 static GtkWidget *
|
10419
|
102 create_status_type_menu(GaimStatusPrimitive type)
|
10418
|
103 {
|
10419
|
104 int i;
|
10418
|
105 GtkWidget *dropdown;
|
|
106 GtkWidget *menu;
|
|
107 GtkWidget *item;
|
|
108
|
|
109 dropdown = gtk_option_menu_new();
|
|
110 menu = gtk_menu_new();
|
|
111
|
10419
|
112 for (i = 0; i < GAIM_STATUS_NUM_PRIMITIVES; i++)
|
|
113 {
|
|
114 item = gtk_menu_item_new_with_label(gaim_primitive_get_name_from_type(i));
|
|
115 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
|
|
116 gtk_widget_show(item);
|
|
117 }
|
10418
|
118
|
10419
|
119 gtk_menu_set_active(GTK_MENU(menu), type);
|
10418
|
120 gtk_option_menu_set_menu(GTK_OPTION_MENU(dropdown), menu);
|
|
121 gtk_widget_show(menu);
|
|
122
|
|
123 return dropdown;
|
|
124 }
|
|
125
|
|
126 static void
|
|
127 status_editor_custom_status_cb(GtkCellRendererToggle *renderer, gchar *path_str, gpointer data)
|
|
128 {
|
|
129 /* StatusEditor *dialog = (StatusEditor *)data; */
|
|
130
|
|
131 /* TODO: Need to allow user to set a custom status for the highlighted account, somehow */
|
|
132 }
|
|
133
|
|
134 static void
|
|
135 status_editor_add_columns(StatusEditor *dialog)
|
|
136 {
|
|
137 GtkCellRenderer *renderer;
|
|
138 GtkTreeViewColumn *column;
|
|
139
|
|
140 /* Custom status column */
|
|
141 renderer = gtk_cell_renderer_toggle_new();
|
|
142 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(dialog->treeview),
|
|
143 -1, _("Custom status"),
|
|
144 renderer,
|
|
145 "active", STATUS_EDITOR_COLUMN_CUSTOM_STATUS,
|
|
146 NULL);
|
|
147 column = gtk_tree_view_get_column(GTK_TREE_VIEW(dialog->treeview), 1);
|
|
148 g_signal_connect(G_OBJECT(renderer), "toggled",
|
|
149 G_CALLBACK(status_editor_custom_status_cb), dialog);
|
|
150
|
|
151 /* Screen Name column */
|
|
152 column = gtk_tree_view_column_new();
|
|
153 gtk_tree_view_column_set_resizable(column, TRUE);
|
|
154 gtk_tree_view_column_set_title(column, _("Screen Name"));
|
|
155 gtk_tree_view_insert_column(GTK_TREE_VIEW(dialog->treeview), column, -1);
|
|
156 gtk_tree_view_column_set_resizable(column, TRUE);
|
|
157
|
|
158 /* Icon */
|
|
159 renderer = gtk_cell_renderer_pixbuf_new();
|
|
160 gtk_tree_view_column_pack_start(column, renderer, FALSE);
|
|
161 gtk_tree_view_column_add_attribute(column, renderer, "pixbuf",
|
|
162 STATUS_EDITOR_COLUMN_ICON);
|
|
163
|
|
164 /* Screen Name */
|
|
165 renderer = gtk_cell_renderer_text_new();
|
|
166 gtk_tree_view_column_pack_start(column, renderer, TRUE);
|
|
167 gtk_tree_view_column_add_attribute(column, renderer, "text",
|
|
168 STATUS_EDITOR_COLUMN_SCREENNAME);
|
|
169 }
|
|
170
|
|
171 static void
|
|
172 status_editor_set_account(GtkListStore *store, GaimAccount *account, GtkTreeIter *iter)
|
|
173 {
|
|
174 GdkPixbuf *pixbuf;
|
|
175 GdkPixbuf *scale;
|
|
176
|
|
177 scale = NULL;
|
|
178
|
|
179 pixbuf = create_prpl_icon(account);
|
|
180
|
|
181 if (pixbuf != NULL)
|
|
182 {
|
|
183 scale = gdk_pixbuf_scale_simple(pixbuf, 16, 16, GDK_INTERP_BILINEAR);
|
|
184
|
|
185 if (!gaim_account_is_connected(account))
|
|
186 gdk_pixbuf_saturate_and_pixelate(scale, scale, 0.0, FALSE);
|
|
187 }
|
|
188
|
|
189 gtk_list_store_set(store, iter,
|
|
190 STATUS_EDITOR_COLUMN_ICON, scale,
|
|
191 STATUS_EDITOR_COLUMN_SCREENNAME, gaim_account_get_username(account),
|
|
192 -1);
|
|
193
|
|
194 if (pixbuf != NULL) g_object_unref(G_OBJECT(pixbuf));
|
|
195 if (scale != NULL) g_object_unref(G_OBJECT(scale));
|
|
196 }
|
|
197
|
|
198 static void
|
|
199 status_editor_add_account(StatusEditor *dialog, GaimAccount *account)
|
|
200 {
|
|
201 GtkTreeIter iter;
|
|
202
|
|
203 gtk_list_store_append(dialog->model, &iter);
|
|
204
|
|
205 status_editor_set_account(dialog->model, account, &iter);
|
|
206 }
|
|
207
|
|
208 static void
|
|
209 status_editor_populate_list(StatusEditor *dialog)
|
|
210 {
|
|
211 GList *l;
|
|
212
|
|
213 gtk_list_store_clear(dialog->model);
|
|
214
|
|
215 for (l = gaim_accounts_get_all(); l != NULL; l = l->next)
|
|
216 status_editor_add_account(dialog, (GaimAccount *)l->data);
|
|
217 }
|
|
218
|
|
219 void
|
10419
|
220 gaim_gtk_status_editor_show(GaimSavedStatus *status)
|
10418
|
221 {
|
|
222 StatusEditor *dialog;
|
|
223 GtkSizeGroup *sg;
|
|
224 GtkWidget *bbox;
|
|
225 GtkWidget *button;
|
|
226 GtkWidget *dbox;
|
|
227 GtkWidget *disclosure;
|
|
228 GtkWidget *dropdown;
|
|
229 GtkWidget *entry;
|
|
230 GtkWidget *frame;
|
|
231 GtkWidget *hbox;
|
|
232 GtkWidget *label;
|
|
233 GtkWidget *sep;
|
|
234 GtkWidget *sw;
|
|
235 GtkWidget *text;
|
|
236 GtkWidget *toolbar;
|
|
237 GtkWidget *vbox;
|
|
238 GtkWidget *win;
|
|
239
|
|
240 dialog = g_new0(StatusEditor, 1);
|
|
241
|
|
242 dialog->window = win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
|
243 gtk_window_set_role(GTK_WINDOW(win), "status");
|
|
244 gtk_window_set_title(GTK_WINDOW(win), _("Status"));
|
|
245 gtk_window_set_resizable(GTK_WINDOW(win), FALSE);
|
|
246 gtk_container_set_border_width(GTK_CONTAINER(win), 12);
|
|
247
|
|
248 g_signal_connect(G_OBJECT(win), "delete_event",
|
|
249 G_CALLBACK(status_editor_destroy_cb), dialog);
|
|
250
|
|
251 /* Setup the vbox */
|
|
252 vbox = gtk_vbox_new(FALSE, 12);
|
|
253 gtk_container_add(GTK_CONTAINER(win), vbox);
|
|
254 gtk_widget_show(vbox);
|
|
255
|
|
256 sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
|
|
257
|
|
258 /* Title */
|
|
259 hbox = gtk_hbox_new(FALSE, 6);
|
|
260 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
|
|
261 gtk_widget_show(hbox);
|
|
262
|
|
263 label = gtk_label_new_with_mnemonic(_("_Title:"));
|
|
264 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
|
|
265 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
|
|
266 gtk_widget_show(label);
|
|
267 gtk_size_group_add_widget(sg, label);
|
|
268
|
|
269 entry = gtk_entry_new();
|
10419
|
270 if (status != NULL)
|
|
271 gtk_entry_set_text(GTK_ENTRY(entry), gaim_savedstatus_get_title(status));
|
|
272 else
|
|
273 gtk_entry_set_text(GTK_ENTRY(entry), _("Out of the office"));
|
10418
|
274 gtk_box_pack_start(GTK_BOX(hbox), entry, TRUE, TRUE, 0);
|
|
275 gtk_widget_show(entry);
|
|
276
|
|
277 /* Status type */
|
|
278 hbox = gtk_hbox_new(FALSE, 6);
|
|
279 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
|
|
280 gtk_widget_show(hbox);
|
|
281
|
|
282 label = gtk_label_new_with_mnemonic(_("_Status:"));
|
|
283 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
|
|
284 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
|
|
285 gtk_widget_show(label);
|
|
286 gtk_size_group_add_widget(sg, label);
|
|
287
|
10419
|
288 if (status != NULL)
|
|
289 dropdown = create_status_type_menu(gaim_savedstatus_get_type(status));
|
|
290 else
|
|
291 dropdown = create_status_type_menu(GAIM_STATUS_AWAY);
|
10418
|
292 gtk_box_pack_start(GTK_BOX(hbox), dropdown, TRUE, TRUE, 0);
|
|
293 gtk_widget_show(dropdown);
|
|
294
|
|
295 /* Status message */
|
|
296 hbox = gtk_hbox_new(FALSE, 6);
|
|
297 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
|
|
298 gtk_widget_show(hbox);
|
|
299
|
|
300 label = gtk_label_new_with_mnemonic(_("_Message:"));
|
|
301 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
|
|
302 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
|
|
303 gtk_widget_show(label);
|
|
304 gtk_size_group_add_widget(sg, label);
|
|
305
|
|
306 frame = gaim_gtk_create_imhtml(TRUE, &text, &toolbar);
|
|
307 gtk_box_pack_start(GTK_BOX(hbox), frame, TRUE, TRUE, 0);
|
|
308 gtk_widget_show(frame);
|
|
309
|
10419
|
310 if (status != NULL)
|
|
311 gtk_imhtml_append_text(GTK_IMHTML(text),
|
|
312 gaim_savedstatus_get_message(status), 0);
|
|
313
|
10418
|
314 /* Custom status message disclosure */
|
|
315 disclosure = gaim_disclosure_new(_("Use a different status for some accounts"),
|
|
316 _("Use a different status for some accounts"));
|
|
317 gtk_box_pack_start(GTK_BOX(vbox), disclosure, FALSE, FALSE, 0);
|
|
318 gtk_widget_show(disclosure);
|
|
319
|
|
320 /* Setup the box that the disclosure will cover */
|
|
321 dbox = gtk_vbox_new(FALSE, 18);
|
|
322 gtk_box_pack_start(GTK_BOX(vbox), dbox, FALSE, FALSE, 0);
|
|
323 gaim_disclosure_set_container(GAIM_DISCLOSURE(disclosure), dbox);
|
|
324
|
|
325 /* Custom status message treeview */
|
|
326 sw = gtk_scrolled_window_new(NULL, NULL);
|
|
327 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
|
|
328 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
|
|
329 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw),
|
|
330 GTK_SHADOW_IN);
|
|
331 gtk_box_pack_start(GTK_BOX(dbox), sw, TRUE, TRUE, 0);
|
|
332 gtk_widget_show(sw);
|
|
333
|
|
334 /* Create the list model */
|
|
335 dialog->model = gtk_list_store_new(STATUS_EDITOR_NUM_COLUMNS,
|
|
336 G_TYPE_BOOLEAN,
|
|
337 GDK_TYPE_PIXBUF, G_TYPE_STRING);
|
|
338
|
|
339 /* Create the treeview */
|
|
340 dialog->treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(dialog->model));
|
|
341 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(dialog->treeview), TRUE);
|
|
342 gtk_widget_set_size_request(dialog->treeview, 400, 250);
|
|
343 gtk_container_add(GTK_CONTAINER(sw), dialog->treeview);
|
|
344 gtk_widget_show(dialog->treeview);
|
|
345
|
|
346 /* Add columns */
|
|
347 status_editor_add_columns(dialog);
|
|
348
|
|
349 /* Populate list */
|
|
350 status_editor_populate_list(dialog);
|
|
351
|
|
352 /* Separator */
|
|
353 sep = gtk_hseparator_new();
|
|
354 gtk_box_pack_start(GTK_BOX(vbox), sep, FALSE, FALSE, 0);
|
|
355 gtk_widget_show(sep);
|
|
356
|
|
357 /* Button box */
|
|
358 bbox = gtk_hbutton_box_new();
|
|
359 gtk_box_set_spacing(GTK_BOX(bbox), 6);
|
|
360 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END);
|
|
361 gtk_box_pack_end(GTK_BOX(vbox), bbox, FALSE, TRUE, 0);
|
|
362 gtk_widget_show(bbox);
|
|
363
|
|
364 /* Cancel button */
|
|
365 button = gtk_button_new_from_stock(GTK_STOCK_CANCEL);
|
|
366 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0);
|
|
367 gtk_widget_show(button);
|
|
368
|
|
369 g_signal_connect(G_OBJECT(button), "clicked",
|
|
370 G_CALLBACK(status_editor_cancel_cb), dialog);
|
|
371
|
|
372 /* Save button */
|
|
373 /* TODO: This button needs to be made sensitive when the title box contains text */
|
|
374 button = gtk_button_new_from_stock(GTK_STOCK_SAVE);
|
|
375 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0);
|
|
376 gtk_widget_set_sensitive(button, FALSE);
|
|
377 gtk_widget_show(button);
|
|
378
|
|
379 g_signal_connect(G_OBJECT(button), "clicked",
|
|
380 G_CALLBACK(status_editor_save_cb), dialog);
|
|
381
|
|
382 gtk_widget_show(win);
|
|
383 }
|
|
384
|
|
385 static gboolean
|
|
386 status_window_find_savedstatus(GtkTreeIter *iter, const char *title)
|
|
387 {
|
|
388 GtkTreeModel *model = GTK_TREE_MODEL(status_window->model);
|
|
389 const char *cur;
|
|
390
|
|
391 if (!gtk_tree_model_get_iter_first(model, iter))
|
|
392 return FALSE;
|
|
393
|
|
394 gtk_tree_model_get(model, iter, STATUS_WINDOW_COLUMN_TITLE, &cur, -1);
|
|
395 if (!strcmp(title, cur))
|
|
396 return TRUE;
|
|
397
|
|
398 while (gtk_tree_model_iter_next(model, iter))
|
|
399 {
|
|
400 gtk_tree_model_get(model, iter, STATUS_WINDOW_COLUMN_TITLE, &cur, -1);
|
|
401 if (!strcmp(title, cur))
|
|
402 return TRUE;
|
|
403 }
|
|
404
|
|
405 return FALSE;
|
|
406 }
|
|
407
|
|
408 static gboolean
|
|
409 status_window_destroy_cb(GtkWidget *widget, GdkEvent *event, gpointer user_data)
|
|
410 {
|
|
411 StatusWindow *dialog = user_data;
|
|
412
|
|
413 dialog->window = NULL;
|
|
414 gaim_gtk_status_window_hide();
|
|
415
|
|
416 return FALSE;
|
|
417 }
|
|
418
|
|
419 static void
|
|
420 status_window_add_cb(GtkButton *button, gpointer user_data)
|
|
421 {
|
10419
|
422 gaim_gtk_status_editor_show(NULL);
|
10418
|
423 }
|
|
424
|
|
425 static void
|
|
426 status_window_modify_foreach(GtkTreeModel *model, GtkTreePath *path,
|
|
427 GtkTreeIter *iter, gpointer user_data)
|
|
428 {
|
|
429 const char *title;
|
10419
|
430 GaimSavedStatus *status;
|
10418
|
431
|
|
432 gtk_tree_model_get(model, iter, STATUS_WINDOW_COLUMN_TITLE, &title, -1);
|
|
433
|
10419
|
434 status = gaim_savedstatus_find(title);
|
|
435 gaim_gtk_status_editor_show(status);
|
10418
|
436 }
|
|
437
|
|
438 static void
|
|
439 status_window_modify_cb(GtkButton *button, gpointer user_data)
|
|
440 {
|
|
441 StatusWindow *dialog = user_data;
|
|
442 GtkTreeSelection *selection;
|
|
443
|
|
444 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dialog->treeview));
|
|
445
|
|
446 gtk_tree_selection_selected_foreach(selection, status_window_modify_foreach, user_data);
|
|
447 }
|
|
448
|
|
449 static void
|
|
450 status_window_delete_confirm_cb(char *title)
|
|
451 {
|
|
452 GtkTreeIter iter;
|
|
453
|
|
454 if (status_window_find_savedstatus(&iter, title))
|
|
455 gtk_list_store_remove(status_window->model, &iter);
|
|
456
|
10419
|
457 gaim_savedstatus_delete(title);
|
10418
|
458
|
|
459 g_free(title);
|
|
460 }
|
|
461
|
|
462 static void
|
|
463 status_window_delete_foreach(GtkTreeModel *model, GtkTreePath *path,
|
|
464 GtkTreeIter *iter, gpointer user_data)
|
|
465 {
|
|
466 const char *title;
|
|
467 char *buf;
|
|
468
|
|
469 gtk_tree_model_get(model, iter, STATUS_WINDOW_COLUMN_TITLE, &title, -1);
|
|
470
|
|
471 buf = g_strdup_printf(_("Are you sure you want to delete %s?"), title);
|
|
472 gaim_request_action(NULL, NULL, buf, NULL, 0, g_strdup(title), 2,
|
|
473 _("Delete"), status_window_delete_confirm_cb,
|
|
474 _("Cancel"), g_free);
|
|
475 g_free(buf);
|
|
476 }
|
|
477
|
|
478 static void
|
|
479 status_window_delete_cb(GtkButton *button, gpointer user_data)
|
|
480 {
|
|
481 StatusWindow *dialog = user_data;
|
|
482 GtkTreeSelection *selection;
|
|
483
|
|
484 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dialog->treeview));
|
|
485
|
|
486 gtk_tree_selection_selected_foreach(selection, status_window_delete_foreach, user_data);
|
|
487 }
|
|
488
|
|
489 static void
|
|
490 status_window_close_cb(GtkButton *button, gpointer user_data)
|
|
491 {
|
|
492 gaim_gtk_status_window_hide();
|
|
493 }
|
|
494
|
|
495 static void
|
|
496 status_selected_cb(GtkTreeSelection *sel, gpointer user_data)
|
|
497 {
|
|
498 StatusWindow *dialog = user_data;
|
|
499 gboolean selected = FALSE;
|
|
500
|
|
501 #if GTK_CHECK_VERSION(2,2,0)
|
|
502 selected = (gtk_tree_selection_count_selected_rows(sel) > 0);
|
|
503 #else
|
|
504 gtk_tree_selection_selected_foreach(sel, get_selected_helper, &selected);
|
|
505 #endif
|
|
506
|
|
507 gtk_widget_set_sensitive(dialog->modify_button, selected);
|
|
508 gtk_widget_set_sensitive(dialog->delete_button, selected);
|
|
509 }
|
|
510
|
|
511 static void
|
|
512 populate_saved_status_list(StatusWindow *dialog)
|
|
513 {
|
|
514 GtkTreeIter iter;
|
|
515 const GList *saved_statuses;
|
10419
|
516 GaimSavedStatus *saved_status;
|
10418
|
517 char *message;
|
|
518
|
|
519 gtk_list_store_clear(dialog->model);
|
|
520
|
|
521 for (saved_statuses = gaim_savedstatuses_get_all(); saved_statuses != NULL;
|
|
522 saved_statuses = g_list_next(saved_statuses))
|
|
523 {
|
10419
|
524 saved_status = (GaimSavedStatus *)saved_statuses->data;
|
|
525 message = gaim_markup_strip_html(gaim_savedstatus_get_message(saved_status));
|
10418
|
526 if (strlen(message) > 70)
|
|
527 strcpy(&message[68], "...");
|
|
528
|
|
529 gtk_list_store_append(dialog->model, &iter);
|
|
530 gtk_list_store_set(dialog->model, &iter,
|
10419
|
531 STATUS_WINDOW_COLUMN_TITLE, gaim_savedstatus_get_title(saved_status),
|
10418
|
532 STATUS_WINDOW_COLUMN_MESSAGE, message,
|
|
533 -1);
|
|
534 free(message);
|
|
535 }
|
|
536 }
|
|
537
|
|
538 static GtkWidget *
|
|
539 create_saved_status_list(StatusWindow *dialog)
|
|
540 {
|
|
541 GtkWidget *sw;
|
|
542 GtkWidget *treeview;
|
|
543 GtkTreeSelection *sel;
|
|
544 GtkTreeViewColumn *column;
|
|
545 GtkCellRenderer *renderer;
|
|
546
|
|
547 /* Create the scrolled window */
|
|
548 sw = gtk_scrolled_window_new(0, 0);
|
|
549 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
|
|
550 GTK_POLICY_AUTOMATIC,
|
|
551 GTK_POLICY_ALWAYS);
|
|
552 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw),
|
|
553 GTK_SHADOW_IN);
|
|
554 gtk_widget_show(sw);
|
|
555
|
|
556 /* Create the list model */
|
|
557 dialog->model = gtk_list_store_new(STATUS_WINDOW_NUM_COLUMNS,
|
|
558 G_TYPE_STRING,
|
|
559 G_TYPE_STRING);
|
|
560
|
|
561 /* Create the treeview */
|
|
562 treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(dialog->model));
|
|
563 dialog->treeview = treeview;
|
|
564 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(treeview), TRUE);
|
|
565
|
|
566 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview));
|
|
567 gtk_tree_selection_set_mode(sel, GTK_SELECTION_MULTIPLE);
|
|
568 g_signal_connect(G_OBJECT(sel), "changed",
|
|
569 G_CALLBACK(status_selected_cb), dialog);
|
|
570
|
|
571 gtk_container_add(GTK_CONTAINER(sw), treeview);
|
|
572 gtk_widget_show(treeview);
|
|
573
|
|
574
|
|
575 /* Add columns */
|
|
576 column = gtk_tree_view_column_new();
|
|
577 gtk_tree_view_column_set_title(column, _("Title"));
|
|
578 gtk_tree_view_column_set_resizable(column, TRUE);
|
|
579 gtk_tree_view_column_set_sort_column_id(column,
|
|
580 STATUS_WINDOW_COLUMN_TITLE);
|
|
581 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
|
|
582 renderer = gtk_cell_renderer_text_new();
|
|
583 gtk_tree_view_column_pack_start(column, renderer, TRUE);
|
|
584 gtk_tree_view_column_add_attribute(column, renderer, "text",
|
|
585 STATUS_WINDOW_COLUMN_TITLE);
|
|
586
|
|
587 column = gtk_tree_view_column_new();
|
|
588 gtk_tree_view_column_set_title(column, _("Message"));
|
|
589 gtk_tree_view_column_set_resizable(column, TRUE);
|
|
590 gtk_tree_view_column_set_sort_column_id(column,
|
|
591 STATUS_WINDOW_COLUMN_MESSAGE);
|
|
592 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
|
|
593 renderer = gtk_cell_renderer_text_new();
|
|
594 gtk_tree_view_column_pack_start(column, renderer, TRUE);
|
|
595 gtk_tree_view_column_add_attribute(column, renderer, "text",
|
|
596 STATUS_WINDOW_COLUMN_MESSAGE);
|
|
597
|
|
598 /* Populate list */
|
|
599 populate_saved_status_list(dialog);
|
|
600
|
|
601 return sw;
|
|
602 }
|
|
603
|
|
604 static gboolean
|
|
605 configure_cb(GtkWidget *widget, GdkEventConfigure *event, StatusWindow *dialog)
|
|
606 {
|
|
607 if (GTK_WIDGET_VISIBLE(widget)) {
|
|
608 gaim_prefs_set_int("/gaim/gtk/status/dialog/width", event->width);
|
|
609 gaim_prefs_set_int("/gaim/gtk/status/dialog/height", event->height);
|
|
610 }
|
|
611
|
|
612 return FALSE;
|
|
613 }
|
|
614
|
|
615 void
|
|
616 gaim_gtk_status_window_show(void)
|
|
617 {
|
|
618 StatusWindow *dialog;
|
|
619 GtkWidget *bbox;
|
|
620 GtkWidget *button;
|
|
621 GtkWidget *list;
|
|
622 GtkWidget *sep;
|
|
623 GtkWidget *vbox;
|
|
624 GtkWidget *win;
|
|
625 int width, height;
|
|
626
|
|
627 if (status_window != NULL) {
|
|
628 gtk_window_present(GTK_WINDOW(status_window->window));
|
|
629 return;
|
|
630 }
|
|
631
|
|
632 status_window = dialog = g_new0(StatusWindow, 1);
|
|
633
|
|
634 width = gaim_prefs_get_int("/gaim/gtk/status/dialog/width");
|
|
635 height = gaim_prefs_get_int("/gaim/gtk/status/dialog/height");
|
|
636
|
|
637 dialog->window = win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
|
638 gtk_window_set_default_size(GTK_WINDOW(win), width, height);
|
|
639 gtk_window_set_role(GTK_WINDOW(win), "statuses");
|
|
640 gtk_window_set_title(GTK_WINDOW(win), _("Saved Statuses"));
|
|
641 gtk_container_set_border_width(GTK_CONTAINER(win), 12);
|
|
642
|
|
643 g_signal_connect(G_OBJECT(win), "delete_event",
|
|
644 G_CALLBACK(status_window_destroy_cb), dialog);
|
|
645 g_signal_connect(G_OBJECT(win), "configure_event",
|
|
646 G_CALLBACK(configure_cb), dialog);
|
|
647
|
|
648 /* Setup the vbox */
|
|
649 vbox = gtk_vbox_new(FALSE, 12);
|
|
650 gtk_container_add(GTK_CONTAINER(win), vbox);
|
|
651 gtk_widget_show(vbox);
|
|
652
|
|
653 /* List of saved status states */
|
|
654 list = create_saved_status_list(dialog);
|
|
655 gtk_box_pack_start(GTK_BOX(vbox), list, TRUE, TRUE, 0);
|
|
656
|
|
657 /* Separator... */
|
|
658 sep = gtk_hseparator_new();
|
|
659 gtk_box_pack_start(GTK_BOX(vbox), sep, FALSE, FALSE, 0);
|
|
660 gtk_widget_show(sep);
|
|
661
|
|
662 /* Button box. */
|
|
663 bbox = gtk_hbutton_box_new();
|
|
664 gtk_box_set_spacing(GTK_BOX(bbox), 6);
|
|
665 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END);
|
|
666 gtk_box_pack_end(GTK_BOX(vbox), bbox, FALSE, TRUE, 0);
|
|
667 gtk_widget_show(bbox);
|
|
668
|
|
669 /* Add button */
|
|
670 button = gtk_button_new_from_stock(GTK_STOCK_ADD);
|
|
671 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0);
|
|
672 gtk_widget_show(button);
|
|
673
|
|
674 g_signal_connect(G_OBJECT(button), "clicked",
|
|
675 G_CALLBACK(status_window_add_cb), dialog);
|
|
676
|
|
677 /* Modify button */
|
|
678 button = gtk_button_new_from_stock(GAIM_STOCK_MODIFY);
|
|
679 dialog->modify_button = button;
|
|
680 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0);
|
|
681 gtk_widget_set_sensitive(button, FALSE);
|
|
682 gtk_widget_show(button);
|
|
683
|
|
684 g_signal_connect(G_OBJECT(button), "clicked",
|
|
685 G_CALLBACK(status_window_modify_cb), dialog);
|
|
686
|
|
687 /* Delete button */
|
|
688 button = gtk_button_new_from_stock(GTK_STOCK_DELETE);
|
|
689 dialog->delete_button = button;
|
|
690 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0);
|
|
691 gtk_widget_set_sensitive(button, FALSE);
|
|
692 gtk_widget_show(button);
|
|
693
|
|
694 g_signal_connect(G_OBJECT(button), "clicked",
|
|
695 G_CALLBACK(status_window_delete_cb), dialog);
|
|
696
|
|
697 /* Close button */
|
|
698 button = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
|
|
699 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0);
|
|
700 gtk_widget_show(button);
|
|
701
|
|
702 g_signal_connect(G_OBJECT(button), "clicked",
|
|
703 G_CALLBACK(status_window_close_cb), dialog);
|
|
704
|
|
705 gtk_widget_show(win);
|
|
706 }
|
|
707
|
|
708 void
|
|
709 gaim_gtk_status_window_hide(void)
|
|
710 {
|
|
711 if (status_window == NULL)
|
|
712 return;
|
|
713
|
|
714 if (status_window->window != NULL)
|
|
715 gtk_widget_destroy(status_window->window);
|
|
716
|
|
717 g_free(status_window);
|
|
718 status_window = NULL;
|
|
719 }
|
|
720
|
|
721 void *
|
|
722 gaim_gtk_status_get_handle()
|
|
723 {
|
|
724 static int handle;
|
|
725
|
|
726 return &handle;
|
|
727 }
|
|
728
|
|
729 void
|
|
730 gaim_gtk_status_init(void)
|
|
731 {
|
|
732 gaim_prefs_add_none("/gaim/gtk/status");
|
|
733 gaim_prefs_add_none("/gaim/gtk/status/dialog");
|
|
734 gaim_prefs_add_int("/gaim/gtk/status/dialog/width", 550);
|
|
735 gaim_prefs_add_int("/gaim/gtk/status/dialog/height", 250);
|
|
736 }
|
|
737
|
|
738 void
|
|
739 gaim_gtk_status_uninit(void)
|
|
740 {
|
|
741 gaim_gtk_status_window_hide();
|
|
742 }
|