Mercurial > pidgin
annotate src/gtksavedstatuses.c @ 14032:49e020487c82
[gaim-migrate @ 16634]
Do not waste too much unnecessary memory.
committer: Tailor Script <tailor@pidgin.im>
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Sat, 05 Aug 2006 04:07:52 +0000 |
parents | f1dd1555b39c |
children |
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 | |
12080 | 43 /* |
44 * TODO: Should attach to the account-deleted and account-added signals | |
45 * and update the GtkListStores in any StatusEditor windows that | |
46 * may be open. | |
47 */ | |
48 | |
49 /** | |
50 * These are used for the GtkTreeView when you're scrolling through | |
51 * all your saved statuses. | |
52 */ | |
10418 | 53 enum |
54 { | |
10421 | 55 STATUS_WINDOW_COLUMN_TITLE, |
56 STATUS_WINDOW_COLUMN_TYPE, | |
57 STATUS_WINDOW_COLUMN_MESSAGE, | |
13178 | 58 /** A hidden column containing a pointer to the editor for this saved status. */ |
13144
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
59 STATUS_WINDOW_COLUMN_WINDOW, |
10421 | 60 STATUS_WINDOW_NUM_COLUMNS |
61 }; | |
62 | |
12080 | 63 /** |
64 * These is used for the GtkTreeView containing the list of accounts | |
65 * at the bottom of the window when you're editing a particular | |
66 * saved status. | |
67 */ | |
10421 | 68 enum |
69 { | |
13178 | 70 /** A hidden column containing a pointer to the GaimAccount. */ |
12080 | 71 STATUS_EDITOR_COLUMN_ACCOUNT, |
13178 | 72 /** A hidden column containing a pointer to the editor for this substatus. */ |
13144
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
73 STATUS_EDITOR_COLUMN_WINDOW, |
12080 | 74 STATUS_EDITOR_COLUMN_ENABLE_SUBSTATUS, |
10418 | 75 STATUS_EDITOR_COLUMN_ICON, |
76 STATUS_EDITOR_COLUMN_SCREENNAME, | |
12080 | 77 /** A hidden column containing the ID of this GaimStatusType. */ |
78 STATUS_EDITOR_COLUMN_STATUS_ID, | |
79 STATUS_EDITOR_COLUMN_STATUS_NAME, | |
80 STATUS_EDITOR_COLUMN_STATUS_MESSAGE, | |
10418 | 81 STATUS_EDITOR_NUM_COLUMNS |
82 }; | |
83 | |
12080 | 84 /** |
85 * These are used in the GtkComboBox to select the specific | |
86 * GaimStatusType when setting a substatus for a particular saved | |
87 * status. | |
88 */ | |
89 enum | |
90 { | |
91 SUBSTATUS_COLUMN_ICON, | |
92 /** A hidden column containing the ID of this GaimStatusType. */ | |
93 SUBSTATUS_COLUMN_STATUS_ID, | |
94 SUBSTATUS_COLUMN_STATUS_NAME, | |
95 SUBSTATUS_NUM_COLUMNS | |
96 }; | |
97 | |
10421 | 98 typedef struct |
10418 | 99 { |
10421 | 100 GtkWidget *window; |
101 GtkListStore *model; | |
102 GtkWidget *treeview; | |
11811 | 103 GtkWidget *use_button; |
10421 | 104 GtkWidget *modify_button; |
105 GtkWidget *delete_button; | |
106 } StatusWindow; | |
10418 | 107 |
108 typedef struct | |
109 { | |
110 GtkWidget *window; | |
111 GtkListStore *model; | |
112 GtkWidget *treeview; | |
12329 | 113 GtkButton *saveanduse_button; |
114 GtkButton *save_button; | |
10420 | 115 |
116 gchar *original_title; | |
117 GtkEntry *title; | |
118 GtkOptionMenu *type; | |
119 GtkIMHtml *message; | |
10418 | 120 } StatusEditor; |
121 | |
12080 | 122 typedef struct |
123 { | |
124 StatusEditor *status_editor; | |
125 GaimAccount *account; | |
126 | |
127 GtkWidget *window; | |
128 GtkListStore *model; | |
129 GtkComboBox *box; | |
130 GtkIMHtml *message; | |
131 GtkIMHtmlToolbar *toolbar; | |
132 } SubStatusEditor; | |
133 | |
10418 | 134 static StatusWindow *status_window = NULL; |
135 | |
10421 | 136 |
137 /************************************************************************** | |
138 * Status window | |
139 **************************************************************************/ | |
140 | |
141 static gboolean | |
142 status_window_find_savedstatus(GtkTreeIter *iter, const char *title) | |
143 { | |
13144
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
144 GtkTreeModel *model; |
10439 | 145 char *cur; |
10421 | 146 |
13178 | 147 if ((status_window == NULL) || (title == NULL)) |
13144
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
148 return FALSE; |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
149 |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
150 model = GTK_TREE_MODEL(status_window->model); |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
151 |
10421 | 152 if (!gtk_tree_model_get_iter_first(model, iter)) |
153 return FALSE; | |
154 | |
13178 | 155 do { |
10421 | 156 gtk_tree_model_get(model, iter, STATUS_WINDOW_COLUMN_TITLE, &cur, -1); |
157 if (!strcmp(title, cur)) | |
10439 | 158 { |
159 g_free(cur); | |
10421 | 160 return TRUE; |
10439 | 161 } |
162 g_free(cur); | |
13178 | 163 } while (gtk_tree_model_iter_next(model, iter)); |
10421 | 164 |
165 return FALSE; | |
166 } | |
167 | |
168 static gboolean | |
169 status_window_destroy_cb(GtkWidget *widget, GdkEvent *event, gpointer user_data) | |
170 { | |
171 StatusWindow *dialog = user_data; | |
172 | |
173 dialog->window = NULL; | |
174 gaim_gtk_status_window_hide(); | |
175 | |
176 return FALSE; | |
177 } | |
178 | |
11888 | 179 #if !GTK_CHECK_VERSION(2,2,0) |
180 static void | |
181 count_selected_helper(GtkTreeModel *model, GtkTreePath *path, | |
182 GtkTreeIter *iter, gpointer user_data) | |
183 { | |
184 (*(gint *)user_data)++; | |
185 } | |
186 | |
187 static void | |
188 list_selected_helper(GtkTreeModel *model, GtkTreePath *path, | |
189 GtkTreeIter *iter, gpointer user_data) | |
190 { | |
11889 | 191 GList **list = (GList **)user_data; |
192 *list = g_list_append(*list, gtk_tree_path_copy(path)); | |
11888 | 193 } |
194 #endif | |
195 | |
10421 | 196 static void |
11811 | 197 status_window_use_cb(GtkButton *button, StatusWindow *dialog) |
198 { | |
199 GtkTreeSelection *selection; | |
200 GtkTreeIter iter; | |
11889 | 201 GList *list = NULL; |
11888 | 202 int num_selected = 0; |
11811 | 203 |
204 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dialog->treeview)); | |
205 | |
11888 | 206 #if GTK_CHECK_VERSION(2,2,0) |
207 num_selected = gtk_tree_selection_count_selected_rows(selection); | |
208 #else | |
209 gtk_tree_selection_selected_foreach(selection, count_selected_helper, &num_selected); | |
210 #endif | |
211 if (num_selected != 1) | |
11811 | 212 /* |
213 * This shouldn't happen because the "Use" button should have | |
214 * been grayed out. Oh well. | |
215 */ | |
216 return; | |
217 | |
11888 | 218 #if GTK_CHECK_VERSION(2,2,0) |
11811 | 219 list = gtk_tree_selection_get_selected_rows(selection, NULL); |
11888 | 220 #else |
221 gtk_tree_selection_selected_foreach(selection, list_selected_helper, &list); | |
222 #endif | |
11811 | 223 |
224 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(dialog->model), | |
225 &iter, list->data)) | |
226 { | |
12080 | 227 gchar *title; |
228 GaimSavedStatus *saved_status; | |
11811 | 229 gtk_tree_model_get(GTK_TREE_MODEL(dialog->model), &iter, |
12080 | 230 STATUS_WINDOW_COLUMN_TITLE, &title, |
11811 | 231 -1); |
12080 | 232 saved_status = gaim_savedstatus_find(title); |
233 g_free(title); | |
11811 | 234 gaim_savedstatus_activate(saved_status); |
235 } | |
236 | |
237 g_list_foreach(list, (GFunc)gtk_tree_path_free, NULL); | |
238 g_list_free(list); | |
239 } | |
240 | |
241 static void | |
10421 | 242 status_window_add_cb(GtkButton *button, gpointer user_data) |
243 { | |
13175 | 244 gaim_gtk_status_editor_show(FALSE, NULL); |
10421 | 245 } |
246 | |
247 static void | |
248 status_window_modify_foreach(GtkTreeModel *model, GtkTreePath *path, | |
249 GtkTreeIter *iter, gpointer user_data) | |
250 { | |
12080 | 251 gchar *title; |
252 GaimSavedStatus *saved_status; | |
10421 | 253 |
12080 | 254 gtk_tree_model_get(model, iter, STATUS_WINDOW_COLUMN_TITLE, &title, -1); |
255 saved_status = gaim_savedstatus_find(title); | |
256 g_free(title); | |
13175 | 257 gaim_gtk_status_editor_show(TRUE, saved_status); |
10421 | 258 } |
259 | |
260 static void | |
261 status_window_modify_cb(GtkButton *button, gpointer user_data) | |
262 { | |
263 StatusWindow *dialog = user_data; | |
264 GtkTreeSelection *selection; | |
265 | |
266 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dialog->treeview)); | |
267 | |
268 gtk_tree_selection_selected_foreach(selection, status_window_modify_foreach, user_data); | |
269 } | |
270 | |
271 static void | |
272 status_window_delete_confirm_cb(char *title) | |
273 { | |
274 GtkTreeIter iter; | |
275 | |
276 if (status_window_find_savedstatus(&iter, title)) | |
277 gtk_list_store_remove(status_window->model, &iter); | |
278 | |
279 gaim_savedstatus_delete(title); | |
280 | |
281 g_free(title); | |
282 } | |
283 | |
284 static void | |
285 status_window_delete_foreach(GtkTreeModel *model, GtkTreePath *path, | |
286 GtkTreeIter *iter, gpointer user_data) | |
287 { | |
10439 | 288 char *title; |
12237 | 289 char *buf; |
10421 | 290 |
291 gtk_tree_model_get(model, iter, STATUS_WINDOW_COLUMN_TITLE, &title, -1); | |
292 | |
12237 | 293 buf = g_strdup_printf(_("Are you sure you want to delete %s?"), title); |
12888
03f690fcb78e
[gaim-migrate @ 15241]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12856
diff
changeset
|
294 gaim_request_action(status_window, NULL, buf, NULL, 0, title, 2, |
10421 | 295 _("Delete"), status_window_delete_confirm_cb, |
296 _("Cancel"), g_free); | |
297 g_free(buf); | |
298 } | |
299 | |
300 static void | |
301 status_window_delete_cb(GtkButton *button, gpointer user_data) | |
302 { | |
303 StatusWindow *dialog = user_data; | |
304 GtkTreeSelection *selection; | |
305 | |
306 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dialog->treeview)); | |
307 | |
308 gtk_tree_selection_selected_foreach(selection, status_window_delete_foreach, user_data); | |
309 } | |
310 | |
311 static void | |
312 status_window_close_cb(GtkButton *button, gpointer user_data) | |
313 { | |
314 gaim_gtk_status_window_hide(); | |
315 } | |
316 | |
317 static void | |
318 status_selected_cb(GtkTreeSelection *sel, gpointer user_data) | |
319 { | |
320 StatusWindow *dialog = user_data; | |
11888 | 321 int num_selected = 0; |
10421 | 322 |
323 #if GTK_CHECK_VERSION(2,2,0) | |
11811 | 324 num_selected = gtk_tree_selection_count_selected_rows(sel); |
10421 | 325 #else |
11888 | 326 gtk_tree_selection_selected_foreach(sel, count_selected_helper, &num_selected); |
10421 | 327 #endif |
328 | |
11811 | 329 gtk_widget_set_sensitive(dialog->use_button, (num_selected == 1)); |
330 gtk_widget_set_sensitive(dialog->modify_button, (num_selected > 0)); | |
331 gtk_widget_set_sensitive(dialog->delete_button, (num_selected > 0)); | |
10421 | 332 } |
333 | |
334 static void | |
335 add_status_to_saved_status_list(GtkListStore *model, GaimSavedStatus *saved_status) | |
336 { | |
337 GtkTreeIter iter; | |
338 const char *title; | |
339 const char *type; | |
340 char *message; | |
341 | |
11651 | 342 if (gaim_savedstatus_is_transient(saved_status)) |
343 return; | |
344 | |
10421 | 345 title = gaim_savedstatus_get_title(saved_status); |
346 type = gaim_primitive_get_name_from_type(gaim_savedstatus_get_type(saved_status)); | |
347 message = gaim_markup_strip_html(gaim_savedstatus_get_message(saved_status)); | |
348 | |
349 gtk_list_store_append(model, &iter); | |
350 gtk_list_store_set(model, &iter, | |
351 STATUS_WINDOW_COLUMN_TITLE, title, | |
352 STATUS_WINDOW_COLUMN_TYPE, type, | |
353 STATUS_WINDOW_COLUMN_MESSAGE, message, | |
354 -1); | |
355 free(message); | |
356 } | |
357 | |
358 static void | |
359 populate_saved_status_list(StatusWindow *dialog) | |
360 { | |
361 const GList *saved_statuses; | |
362 | |
363 gtk_list_store_clear(dialog->model); | |
364 | |
365 for (saved_statuses = gaim_savedstatuses_get_all(); saved_statuses != NULL; | |
366 saved_statuses = g_list_next(saved_statuses)) | |
367 { | |
12199 | 368 add_status_to_saved_status_list(dialog->model, saved_statuses->data); |
10421 | 369 } |
370 } | |
371 | |
10435 | 372 static gboolean |
373 search_func(GtkTreeModel *model, gint column, const gchar *key, GtkTreeIter *iter, gpointer search_data) | |
374 { | |
10439 | 375 gboolean result; |
376 char *haystack; | |
10435 | 377 |
378 gtk_tree_model_get(model, iter, column, &haystack, -1); | |
379 | |
10439 | 380 result = (gaim_strcasestr(haystack, key) == NULL); |
381 | |
382 g_free(haystack); | |
383 | |
384 return result; | |
10435 | 385 } |
386 | |
12162
5e24b8e49522
[gaim-migrate @ 14463]
Richard Laager <rlaager@wiktel.com>
parents:
12080
diff
changeset
|
387 static void |
12173
81c63578aa39
[gaim-migrate @ 14475]
Richard Laager <rlaager@wiktel.com>
parents:
12162
diff
changeset
|
388 savedstatus_activated_cb(GtkTreeView *view, GtkTreePath *path, GtkTreeViewColumn *column, StatusWindow *dialog) |
12162
5e24b8e49522
[gaim-migrate @ 14463]
Richard Laager <rlaager@wiktel.com>
parents:
12080
diff
changeset
|
389 { |
12173
81c63578aa39
[gaim-migrate @ 14475]
Richard Laager <rlaager@wiktel.com>
parents:
12162
diff
changeset
|
390 status_window_modify_cb(NULL, dialog); |
12162
5e24b8e49522
[gaim-migrate @ 14463]
Richard Laager <rlaager@wiktel.com>
parents:
12080
diff
changeset
|
391 } |
5e24b8e49522
[gaim-migrate @ 14463]
Richard Laager <rlaager@wiktel.com>
parents:
12080
diff
changeset
|
392 |
10421 | 393 static GtkWidget * |
394 create_saved_status_list(StatusWindow *dialog) | |
395 { | |
396 GtkWidget *sw; | |
397 GtkWidget *treeview; | |
398 GtkTreeSelection *sel; | |
399 GtkTreeViewColumn *column; | |
400 GtkCellRenderer *renderer; | |
401 | |
402 /* Create the scrolled window */ | |
403 sw = gtk_scrolled_window_new(0, 0); | |
404 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), | |
405 GTK_POLICY_AUTOMATIC, | |
406 GTK_POLICY_ALWAYS); | |
407 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), | |
408 GTK_SHADOW_IN); | |
409 | |
410 /* Create the list model */ | |
411 dialog->model = gtk_list_store_new(STATUS_WINDOW_NUM_COLUMNS, | |
412 G_TYPE_STRING, | |
413 G_TYPE_STRING, | |
13144
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
414 G_TYPE_STRING, |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
415 G_TYPE_POINTER); |
10421 | 416 |
417 /* Create the treeview */ | |
418 treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(dialog->model)); | |
419 dialog->treeview = treeview; | |
420 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(treeview), TRUE); | |
12162
5e24b8e49522
[gaim-migrate @ 14463]
Richard Laager <rlaager@wiktel.com>
parents:
12080
diff
changeset
|
421 g_signal_connect(G_OBJECT(treeview), "row-activated", |
12173
81c63578aa39
[gaim-migrate @ 14475]
Richard Laager <rlaager@wiktel.com>
parents:
12162
diff
changeset
|
422 G_CALLBACK(savedstatus_activated_cb), dialog); |
10421 | 423 |
424 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); | |
425 gtk_tree_selection_set_mode(sel, GTK_SELECTION_MULTIPLE); | |
426 g_signal_connect(G_OBJECT(sel), "changed", | |
427 G_CALLBACK(status_selected_cb), dialog); | |
428 | |
429 gtk_container_add(GTK_CONTAINER(sw), treeview); | |
430 | |
431 /* Add columns */ | |
432 column = gtk_tree_view_column_new(); | |
433 gtk_tree_view_column_set_title(column, _("Title")); | |
434 gtk_tree_view_column_set_resizable(column, TRUE); | |
11548 | 435 gtk_tree_view_column_set_min_width(column, 100); |
10421 | 436 gtk_tree_view_column_set_sort_column_id(column, |
437 STATUS_WINDOW_COLUMN_TITLE); | |
438 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); | |
439 renderer = gtk_cell_renderer_text_new(); | |
440 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
441 gtk_tree_view_column_add_attribute(column, renderer, "text", | |
442 STATUS_WINDOW_COLUMN_TITLE); | |
11548 | 443 #if GTK_CHECK_VERSION(2,6,0) |
444 g_object_set(renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL); | |
445 #endif | |
10421 | 446 |
447 column = gtk_tree_view_column_new(); | |
448 gtk_tree_view_column_set_title(column, _("Type")); | |
449 gtk_tree_view_column_set_resizable(column, TRUE); | |
450 gtk_tree_view_column_set_sort_column_id(column, | |
451 STATUS_WINDOW_COLUMN_TYPE); | |
452 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); | |
453 renderer = gtk_cell_renderer_text_new(); | |
454 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
455 gtk_tree_view_column_add_attribute(column, renderer, "text", | |
456 STATUS_WINDOW_COLUMN_TYPE); | |
457 | |
458 column = gtk_tree_view_column_new(); | |
459 gtk_tree_view_column_set_title(column, _("Message")); | |
460 gtk_tree_view_column_set_resizable(column, TRUE); | |
461 gtk_tree_view_column_set_sort_column_id(column, | |
462 STATUS_WINDOW_COLUMN_MESSAGE); | |
463 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); | |
464 renderer = gtk_cell_renderer_text_new(); | |
465 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
466 gtk_tree_view_column_add_attribute(column, renderer, "text", | |
467 STATUS_WINDOW_COLUMN_MESSAGE); | |
10435 | 468 #if GTK_CHECK_VERSION(2,6,0) |
10502 | 469 g_object_set(renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL); |
10435 | 470 #endif |
471 | |
472 /* Enable CTRL+F searching */ | |
473 gtk_tree_view_set_search_column(GTK_TREE_VIEW(treeview), STATUS_WINDOW_COLUMN_TITLE); | |
474 gtk_tree_view_set_search_equal_func(GTK_TREE_VIEW(treeview), search_func, NULL, NULL); | |
10421 | 475 |
10422 | 476 /* Sort the title column by default */ |
477 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(dialog->model), | |
478 STATUS_WINDOW_COLUMN_TITLE, | |
479 GTK_SORT_ASCENDING); | |
480 | |
10421 | 481 /* Populate list */ |
482 populate_saved_status_list(dialog); | |
483 | |
13199 | 484 gtk_widget_show_all(sw); |
485 | |
10421 | 486 return sw; |
487 } | |
488 | |
489 static gboolean | |
490 configure_cb(GtkWidget *widget, GdkEventConfigure *event, StatusWindow *dialog) | |
491 { | |
13178 | 492 if (GTK_WIDGET_VISIBLE(widget)) |
493 { | |
10421 | 494 gaim_prefs_set_int("/gaim/gtk/status/dialog/width", event->width); |
495 gaim_prefs_set_int("/gaim/gtk/status/dialog/height", event->height); | |
496 } | |
497 | |
498 return FALSE; | |
499 } | |
500 | |
501 void | |
502 gaim_gtk_status_window_show(void) | |
503 { | |
504 StatusWindow *dialog; | |
505 GtkWidget *bbox; | |
506 GtkWidget *button; | |
507 GtkWidget *list; | |
508 GtkWidget *vbox; | |
509 GtkWidget *win; | |
510 int width, height; | |
511 | |
13178 | 512 if (status_window != NULL) |
513 { | |
10421 | 514 gtk_window_present(GTK_WINDOW(status_window->window)); |
515 return; | |
516 } | |
517 | |
518 status_window = dialog = g_new0(StatusWindow, 1); | |
519 | |
520 width = gaim_prefs_get_int("/gaim/gtk/status/dialog/width"); | |
521 height = gaim_prefs_get_int("/gaim/gtk/status/dialog/height"); | |
522 | |
523 dialog->window = win = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
524 gtk_window_set_default_size(GTK_WINDOW(win), width, height); | |
525 gtk_window_set_role(GTK_WINDOW(win), "statuses"); | |
526 gtk_window_set_title(GTK_WINDOW(win), _("Saved Statuses")); | |
11243 | 527 gtk_container_set_border_width(GTK_CONTAINER(win), GAIM_HIG_BORDER); |
10421 | 528 |
529 g_signal_connect(G_OBJECT(win), "delete_event", | |
530 G_CALLBACK(status_window_destroy_cb), dialog); | |
531 g_signal_connect(G_OBJECT(win), "configure_event", | |
532 G_CALLBACK(configure_cb), dialog); | |
533 | |
534 /* Setup the vbox */ | |
11243 | 535 vbox = gtk_vbox_new(FALSE, GAIM_HIG_BORDER); |
10421 | 536 gtk_container_add(GTK_CONTAINER(win), vbox); |
537 | |
538 /* List of saved status states */ | |
539 list = create_saved_status_list(dialog); | |
540 gtk_box_pack_start(GTK_BOX(vbox), list, TRUE, TRUE, 0); | |
541 | |
542 /* Button box. */ | |
543 bbox = gtk_hbutton_box_new(); | |
11243 | 544 gtk_box_set_spacing(GTK_BOX(bbox), GAIM_HIG_BOX_SPACE); |
10421 | 545 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); |
546 gtk_box_pack_end(GTK_BOX(vbox), bbox, FALSE, TRUE, 0); | |
547 | |
11811 | 548 /* Use button */ |
11832 | 549 button = gaim_pixbuf_button_from_stock(_("_Use"), GTK_STOCK_EXECUTE, |
550 GAIM_BUTTON_HORIZONTAL); | |
11811 | 551 dialog->use_button = button; |
552 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
553 gtk_widget_set_sensitive(button, FALSE); | |
554 | |
555 g_signal_connect(G_OBJECT(button), "clicked", | |
556 G_CALLBACK(status_window_use_cb), dialog); | |
557 | |
10421 | 558 /* Add button */ |
559 button = gtk_button_new_from_stock(GTK_STOCK_ADD); | |
560 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
561 | |
562 g_signal_connect(G_OBJECT(button), "clicked", | |
563 G_CALLBACK(status_window_add_cb), dialog); | |
564 | |
565 /* Modify button */ | |
566 button = gtk_button_new_from_stock(GAIM_STOCK_MODIFY); | |
567 dialog->modify_button = button; | |
568 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
569 gtk_widget_set_sensitive(button, FALSE); | |
570 | |
571 g_signal_connect(G_OBJECT(button), "clicked", | |
572 G_CALLBACK(status_window_modify_cb), dialog); | |
573 | |
574 /* Delete button */ | |
575 button = gtk_button_new_from_stock(GTK_STOCK_DELETE); | |
576 dialog->delete_button = button; | |
577 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
578 gtk_widget_set_sensitive(button, FALSE); | |
579 | |
580 g_signal_connect(G_OBJECT(button), "clicked", | |
581 G_CALLBACK(status_window_delete_cb), dialog); | |
582 | |
583 /* Close button */ | |
584 button = gtk_button_new_from_stock(GTK_STOCK_CLOSE); | |
585 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
586 | |
587 g_signal_connect(G_OBJECT(button), "clicked", | |
588 G_CALLBACK(status_window_close_cb), dialog); | |
589 | |
13199 | 590 gtk_widget_show_all(win); |
10421 | 591 } |
592 | |
593 void | |
594 gaim_gtk_status_window_hide(void) | |
595 { | |
596 if (status_window == NULL) | |
597 return; | |
598 | |
599 if (status_window->window != NULL) | |
600 gtk_widget_destroy(status_window->window); | |
601 | |
12888
03f690fcb78e
[gaim-migrate @ 15241]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12856
diff
changeset
|
602 gaim_request_close_with_handle(status_window); |
03f690fcb78e
[gaim-migrate @ 15241]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12856
diff
changeset
|
603 gaim_notify_close_with_handle(status_window); |
10421 | 604 g_free(status_window); |
605 status_window = NULL; | |
606 } | |
607 | |
608 | |
609 /************************************************************************** | |
610 * Status editor | |
611 **************************************************************************/ | |
10420 | 612 |
13178 | 613 static void substatus_editor_cancel_cb(GtkButton *button, gpointer user_data); |
614 | |
13144
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
615 static void |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
616 status_editor_remove_dialog(StatusEditor *dialog) |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
617 { |
13178 | 618 GtkTreeModel *model; |
13144
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
619 GtkTreeIter iter; |
13178 | 620 |
621 /* Remove the reference to this dialog from our parent's list store */ | |
622 if (status_window_find_savedstatus(&iter, dialog->original_title)) | |
623 { | |
13144
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
624 gtk_list_store_set(status_window->model, &iter, |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
625 STATUS_WINDOW_COLUMN_WINDOW, NULL, |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
626 -1); |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
627 } |
13178 | 628 |
629 /* Close any substatus editors that may be open */ | |
630 model = GTK_TREE_MODEL(dialog->model); | |
631 if (gtk_tree_model_get_iter_first(model, &iter)) | |
632 { | |
633 do { | |
634 SubStatusEditor *substatus_dialog; | |
635 | |
636 gtk_tree_model_get(model, &iter, | |
637 STATUS_EDITOR_COLUMN_WINDOW, &substatus_dialog, | |
638 -1); | |
639 if (substatus_dialog != NULL) | |
640 { | |
641 gtk_list_store_set(dialog->model, &iter, | |
642 STATUS_EDITOR_COLUMN_WINDOW, NULL, | |
643 -1); | |
644 substatus_editor_cancel_cb(NULL, substatus_dialog); | |
645 } | |
646 } while (gtk_tree_model_iter_next(model, &iter)); | |
647 } | |
13144
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
648 } |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
649 |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
650 |
10418 | 651 static gboolean |
652 status_editor_destroy_cb(GtkWidget *widget, GdkEvent *event, gpointer user_data) | |
653 { | |
10574 | 654 StatusEditor *dialog = user_data; |
10418 | 655 |
13144
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
656 status_editor_remove_dialog(dialog); |
10574 | 657 g_free(dialog->original_title); |
10418 | 658 g_free(dialog); |
659 | |
660 return FALSE; | |
661 } | |
662 | |
663 static void | |
664 status_editor_cancel_cb(GtkButton *button, gpointer user_data) | |
665 { | |
10574 | 666 StatusEditor *dialog = user_data; |
10418 | 667 |
13144
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
668 status_editor_remove_dialog(dialog); |
10418 | 669 gtk_widget_destroy(dialog->window); |
10574 | 670 g_free(dialog->original_title); |
10418 | 671 g_free(dialog); |
672 } | |
673 | |
674 static void | |
12329 | 675 status_editor_ok_cb(GtkButton *button, gpointer user_data) |
10418 | 676 { |
10420 | 677 StatusEditor *dialog = user_data; |
678 const char *title; | |
679 GaimStatusPrimitive type; | |
680 char *message, *unformatted; | |
12080 | 681 GaimSavedStatus *saved_status = NULL; |
682 GtkTreeModel *model; | |
683 GtkTreeIter iter; | |
10420 | 684 |
685 title = gtk_entry_get_text(dialog->title); | |
686 | |
687 /* | |
12329 | 688 * If we're saving this status, and the title is already taken |
689 * then show an error dialog and don't do anything. | |
10420 | 690 */ |
12329 | 691 if (((button == dialog->saveanduse_button) || (button == dialog->save_button)) && |
692 (gaim_savedstatus_find(title) != NULL) && | |
10420 | 693 ((dialog->original_title == NULL) || (strcmp(title, dialog->original_title)))) |
694 { | |
12888
03f690fcb78e
[gaim-migrate @ 15241]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12856
diff
changeset
|
695 gaim_notify_error(status_window, NULL, _("Title already in use. You must " |
10420 | 696 "choose a unique title."), NULL); |
697 return; | |
698 } | |
699 | |
12726
868d574dd83e
[gaim-migrate @ 15070]
Richard Laager <rlaager@wiktel.com>
parents:
12693
diff
changeset
|
700 type = gtk_option_menu_get_history(dialog->type) + (GAIM_STATUS_UNSET + 1); |
10420 | 701 message = gtk_imhtml_get_markup(dialog->message); |
702 unformatted = gaim_markup_strip_html(message); | |
703 | |
704 /* | |
13175 | 705 * If we're editing an old status, then lookup the old status. |
706 * Note: It is possible that it has been deleted or renamed | |
707 * or something, and no longer exists. | |
10420 | 708 */ |
709 if (dialog->original_title != NULL) | |
710 { | |
711 GtkTreeIter iter; | |
712 | |
12080 | 713 saved_status = gaim_savedstatus_find(dialog->original_title); |
10420 | 714 |
715 if (status_window_find_savedstatus(&iter, dialog->original_title)) | |
716 gtk_list_store_remove(status_window->model, &iter); | |
717 } | |
718 | |
12080 | 719 if (saved_status == NULL) |
720 { | |
721 /* This is a new status */ | |
12329 | 722 if ((button == dialog->saveanduse_button) |
723 || (button == dialog->save_button)) | |
724 saved_status = gaim_savedstatus_new(title, type); | |
725 else | |
726 saved_status = gaim_savedstatus_new(NULL, type); | |
12080 | 727 } |
728 else | |
729 { | |
730 /* Modify the old status */ | |
731 if (strcmp(title, dialog->original_title)) | |
732 gaim_savedstatus_set_title(saved_status, title); | |
733 gaim_savedstatus_set_type(saved_status, type); | |
734 } | |
735 | |
12951
9eaf101af7a7
[gaim-migrate @ 15304]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12888
diff
changeset
|
736 if (*unformatted == '\0') |
9eaf101af7a7
[gaim-migrate @ 15304]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12888
diff
changeset
|
737 gaim_savedstatus_set_message(saved_status, NULL); |
9eaf101af7a7
[gaim-migrate @ 15304]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12888
diff
changeset
|
738 else |
12080 | 739 gaim_savedstatus_set_message(saved_status, message); |
740 | |
741 /* Set any substatuses */ | |
742 model = GTK_TREE_MODEL(dialog->model); | |
13178 | 743 if (gtk_tree_model_get_iter_first(model, &iter)) |
744 { | |
13144
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
745 do { |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
746 GaimAccount *account; |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
747 gboolean enabled; |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
748 char *id; |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
749 char *message; |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
750 GaimStatusType *type; |
12080 | 751 |
752 gtk_tree_model_get(model, &iter, | |
753 STATUS_EDITOR_COLUMN_ACCOUNT, &account, | |
754 STATUS_EDITOR_COLUMN_ENABLE_SUBSTATUS, &enabled, | |
755 STATUS_EDITOR_COLUMN_STATUS_ID, &id, | |
756 STATUS_EDITOR_COLUMN_STATUS_MESSAGE, &message, | |
757 -1); | |
758 if (enabled) | |
759 { | |
760 type = gaim_account_get_status_type(account, id); | |
761 gaim_savedstatus_set_substatus(saved_status, account, type, message); | |
762 } | |
13835 | 763 else |
764 { | |
765 gaim_savedstatus_unset_substatus(saved_status, account); | |
766 } | |
12080 | 767 g_free(id); |
768 g_free(message); | |
13144
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
769 } while (gtk_tree_model_iter_next(model, &iter)); |
12080 | 770 } |
771 | |
10420 | 772 g_free(message); |
773 g_free(unformatted); | |
774 | |
13178 | 775 status_editor_remove_dialog(dialog); |
10420 | 776 gtk_widget_destroy(dialog->window); |
10574 | 777 g_free(dialog->original_title); |
10420 | 778 |
12080 | 779 if (status_window != NULL) |
12199 | 780 add_status_to_saved_status_list(status_window->model, saved_status); |
12329 | 781 |
13010 | 782 /* If they clicked on "Save & Use" or "Use," then activate the status */ |
783 if (button != dialog->save_button) | |
12329 | 784 gaim_savedstatus_activate(saved_status); |
13178 | 785 |
13172
12d960995cdc
[gaim-migrate @ 15535]
Richard Laager <rlaager@wiktel.com>
parents:
13144
diff
changeset
|
786 g_free(dialog); |
10420 | 787 } |
788 | |
789 static void | |
790 editor_title_changed_cb(GtkWidget *widget, gpointer user_data) | |
791 { | |
792 StatusEditor *dialog = user_data; | |
793 const gchar *text; | |
794 | |
795 text = gtk_entry_get_text(dialog->title); | |
796 | |
12329 | 797 gtk_widget_set_sensitive(GTK_WIDGET(dialog->saveanduse_button), (*text != '\0')); |
798 gtk_widget_set_sensitive(GTK_WIDGET(dialog->save_button), (*text != '\0')); | |
10418 | 799 } |
800 | |
801 static GtkWidget * | |
10419 | 802 create_status_type_menu(GaimStatusPrimitive type) |
10418 | 803 { |
10419 | 804 int i; |
10418 | 805 GtkWidget *dropdown; |
806 GtkWidget *menu; | |
807 GtkWidget *item; | |
808 | |
809 dropdown = gtk_option_menu_new(); | |
810 menu = gtk_menu_new(); | |
811 | |
12693
07d6cc1b5a98
[gaim-migrate @ 15036]
Richard Laager <rlaager@wiktel.com>
parents:
12329
diff
changeset
|
812 for (i = GAIM_STATUS_UNSET + 1; i < GAIM_STATUS_NUM_PRIMITIVES; i++) |
10419 | 813 { |
814 item = gtk_menu_item_new_with_label(gaim_primitive_get_name_from_type(i)); | |
815 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); | |
816 } | |
10418 | 817 |
12693
07d6cc1b5a98
[gaim-migrate @ 15036]
Richard Laager <rlaager@wiktel.com>
parents:
12329
diff
changeset
|
818 gtk_menu_set_active(GTK_MENU(menu), type - (GAIM_STATUS_UNSET + 1)); |
10418 | 819 gtk_option_menu_set_menu(GTK_OPTION_MENU(dropdown), menu); |
13199 | 820 gtk_widget_show_all(menu); |
10418 | 821 |
822 return dropdown; | |
823 } | |
824 | |
12080 | 825 static void edit_substatus(StatusEditor *status_editor, GaimAccount *account); |
826 | |
827 static void | |
828 edit_substatus_cb(GtkTreeView *tv, GtkTreePath *path, GtkTreeViewColumn *col, gpointer user_data) | |
829 { | |
830 StatusEditor *dialog = user_data; | |
831 GtkTreeIter iter; | |
832 GaimAccount *account; | |
833 | |
834 gtk_tree_model_get_iter(GTK_TREE_MODEL(dialog->model), &iter, path); | |
835 gtk_tree_model_get(GTK_TREE_MODEL(dialog->model), &iter, | |
836 STATUS_EDITOR_COLUMN_ACCOUNT, &account, | |
837 -1); | |
838 | |
839 edit_substatus(dialog, account); | |
840 } | |
841 | |
842 static void | |
843 status_editor_substatus_cb(GtkCellRendererToggle *renderer, gchar *path_str, gpointer data) | |
844 { | |
845 StatusEditor *dialog = (StatusEditor *)data; | |
846 GtkTreeIter iter; | |
847 gboolean enabled; | |
848 GaimAccount *account; | |
849 | |
850 gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(dialog->model), &iter, path_str); | |
851 gtk_tree_model_get(GTK_TREE_MODEL(dialog->model), &iter, | |
852 STATUS_EDITOR_COLUMN_ACCOUNT, &account, | |
853 STATUS_EDITOR_COLUMN_ENABLE_SUBSTATUS, &enabled, | |
854 -1); | |
855 | |
856 enabled = !enabled; | |
857 | |
858 if (enabled) | |
859 { | |
860 edit_substatus(dialog, account); | |
861 } | |
862 else | |
863 { | |
864 /* Remove the substatus */ | |
865 gtk_list_store_set(dialog->model, &iter, | |
866 STATUS_EDITOR_COLUMN_ENABLE_SUBSTATUS, enabled, | |
867 STATUS_EDITOR_COLUMN_STATUS_ID, NULL, | |
868 STATUS_EDITOR_COLUMN_STATUS_NAME, NULL, | |
869 STATUS_EDITOR_COLUMN_STATUS_MESSAGE, NULL, | |
870 -1); | |
871 } | |
872 } | |
873 | |
10418 | 874 static void |
875 status_editor_add_columns(StatusEditor *dialog) | |
876 { | |
877 GtkCellRenderer *renderer; | |
878 GtkTreeViewColumn *column; | |
879 | |
12080 | 880 /* Enable Different status column */ |
10418 | 881 renderer = gtk_cell_renderer_toggle_new(); |
882 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(dialog->treeview), | |
12080 | 883 -1, _("Different"), |
10418 | 884 renderer, |
12080 | 885 "active", STATUS_EDITOR_COLUMN_ENABLE_SUBSTATUS, |
10418 | 886 NULL); |
887 g_signal_connect(G_OBJECT(renderer), "toggled", | |
12080 | 888 G_CALLBACK(status_editor_substatus_cb), dialog); |
10418 | 889 |
890 /* Screen Name column */ | |
891 column = gtk_tree_view_column_new(); | |
892 gtk_tree_view_column_set_resizable(column, TRUE); | |
893 gtk_tree_view_column_set_title(column, _("Screen Name")); | |
894 gtk_tree_view_insert_column(GTK_TREE_VIEW(dialog->treeview), column, -1); | |
895 gtk_tree_view_column_set_resizable(column, TRUE); | |
896 | |
897 /* Icon */ | |
898 renderer = gtk_cell_renderer_pixbuf_new(); | |
899 gtk_tree_view_column_pack_start(column, renderer, FALSE); | |
900 gtk_tree_view_column_add_attribute(column, renderer, "pixbuf", | |
901 STATUS_EDITOR_COLUMN_ICON); | |
902 | |
903 /* Screen Name */ | |
904 renderer = gtk_cell_renderer_text_new(); | |
905 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
906 gtk_tree_view_column_add_attribute(column, renderer, "text", | |
907 STATUS_EDITOR_COLUMN_SCREENNAME); | |
12080 | 908 |
909 /* Status column */ | |
910 column = gtk_tree_view_column_new(); | |
911 gtk_tree_view_column_set_resizable(column, TRUE); | |
912 gtk_tree_view_column_set_title(column, _("Status")); | |
913 gtk_tree_view_insert_column(GTK_TREE_VIEW(dialog->treeview), column, -1); | |
914 gtk_tree_view_column_set_resizable(column, TRUE); | |
915 renderer = gtk_cell_renderer_text_new(); | |
916 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
917 gtk_tree_view_column_add_attribute(column, renderer, "text", | |
918 STATUS_EDITOR_COLUMN_STATUS_NAME); | |
919 | |
920 /* Message column */ | |
921 column = gtk_tree_view_column_new(); | |
922 gtk_tree_view_column_set_resizable(column, TRUE); | |
923 gtk_tree_view_column_set_title(column, _("Message")); | |
924 gtk_tree_view_insert_column(GTK_TREE_VIEW(dialog->treeview), column, -1); | |
925 gtk_tree_view_column_set_resizable(column, TRUE); | |
926 renderer = gtk_cell_renderer_text_new(); | |
927 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
928 gtk_tree_view_column_add_attribute(column, renderer, "text", | |
929 STATUS_EDITOR_COLUMN_STATUS_MESSAGE); | |
930 | |
931 g_signal_connect(G_OBJECT(dialog->treeview), "row-activated", | |
932 G_CALLBACK(edit_substatus_cb), dialog); | |
10418 | 933 } |
934 | |
935 static void | |
12080 | 936 status_editor_set_account(GtkListStore *store, GaimAccount *account, |
937 GtkTreeIter *iter, GaimSavedStatusSub *substatus) | |
10418 | 938 { |
939 GdkPixbuf *pixbuf; | |
12080 | 940 const char *id = NULL, *name = NULL, *message = NULL; |
10418 | 941 |
13090 | 942 pixbuf = gaim_gtk_create_prpl_icon(account, 0.5); |
943 if ((pixbuf != NULL) && !gaim_account_is_connected(account)) | |
10418 | 944 { |
13090 | 945 gdk_pixbuf_saturate_and_pixelate(pixbuf, pixbuf, 0.0, FALSE); |
10418 | 946 } |
947 | |
12080 | 948 if (substatus != NULL) |
949 { | |
950 const GaimStatusType *type; | |
951 | |
952 type = gaim_savedstatus_substatus_get_type(substatus); | |
953 id = gaim_status_type_get_id(type); | |
954 name = gaim_status_type_get_name(type); | |
955 if (gaim_status_type_get_attr(type, "message")) | |
956 message = gaim_savedstatus_substatus_get_message(substatus); | |
957 } | |
958 | |
10418 | 959 gtk_list_store_set(store, iter, |
12080 | 960 STATUS_EDITOR_COLUMN_ACCOUNT, account, |
961 STATUS_EDITOR_COLUMN_ENABLE_SUBSTATUS, (substatus != NULL), | |
13090 | 962 STATUS_EDITOR_COLUMN_ICON, pixbuf, |
10418 | 963 STATUS_EDITOR_COLUMN_SCREENNAME, gaim_account_get_username(account), |
12080 | 964 STATUS_EDITOR_COLUMN_STATUS_ID, id, |
965 STATUS_EDITOR_COLUMN_STATUS_NAME, name, | |
966 STATUS_EDITOR_COLUMN_STATUS_MESSAGE, message, | |
10418 | 967 -1); |
968 | |
13090 | 969 if (pixbuf != NULL) |
970 g_object_unref(G_OBJECT(pixbuf)); | |
10418 | 971 } |
972 | |
973 static void | |
12080 | 974 status_editor_add_account(StatusEditor *dialog, GaimAccount *account, |
975 GaimSavedStatusSub *substatus) | |
10418 | 976 { |
977 GtkTreeIter iter; | |
978 | |
979 gtk_list_store_append(dialog->model, &iter); | |
980 | |
12080 | 981 status_editor_set_account(dialog->model, account, &iter, substatus); |
10418 | 982 } |
983 | |
984 static void | |
12080 | 985 status_editor_populate_list(StatusEditor *dialog, GaimSavedStatus *saved_status) |
10418 | 986 { |
12080 | 987 GList *iter; |
988 GaimSavedStatusSub *substatus; | |
10418 | 989 |
990 gtk_list_store_clear(dialog->model); | |
991 | |
12080 | 992 for (iter = gaim_accounts_get_all(); iter != NULL; iter = iter->next) |
993 { | |
994 GaimAccount *account = (GaimAccount *)iter->data; | |
995 | |
996 if (saved_status != NULL) | |
997 substatus = gaim_savedstatus_get_substatus(saved_status, account); | |
998 else | |
999 substatus = NULL; | |
1000 | |
1001 status_editor_add_account(dialog, account, substatus); | |
1002 } | |
10418 | 1003 } |
1004 | |
1005 void | |
13175 | 1006 gaim_gtk_status_editor_show(gboolean edit, GaimSavedStatus *saved_status) |
10418 | 1007 { |
13144
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1008 GtkTreeIter iter; |
10418 | 1009 StatusEditor *dialog; |
1010 GtkSizeGroup *sg; | |
1011 GtkWidget *bbox; | |
1012 GtkWidget *button; | |
1013 GtkWidget *dbox; | |
11735 | 1014 GtkWidget *expander; |
10418 | 1015 GtkWidget *dropdown; |
1016 GtkWidget *entry; | |
1017 GtkWidget *frame; | |
1018 GtkWidget *hbox; | |
1019 GtkWidget *label; | |
1020 GtkWidget *sw; | |
1021 GtkWidget *text; | |
1022 GtkWidget *toolbar; | |
1023 GtkWidget *vbox; | |
1024 GtkWidget *win; | |
13141
39e7014cb687
[gaim-migrate @ 15504]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13090
diff
changeset
|
1025 GList *focus_chain = NULL; |
10418 | 1026 |
13175 | 1027 if (edit) |
1028 { | |
1029 g_return_if_fail(saved_status != NULL); | |
1030 g_return_if_fail(!gaim_savedstatus_is_transient(saved_status)); | |
1031 } | |
1032 | |
13144
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1033 /* Find a possible window for this saved status and present it */ |
13178 | 1034 if (edit && status_window_find_savedstatus(&iter, gaim_savedstatus_get_title(saved_status))) |
13175 | 1035 { |
1036 gtk_tree_model_get(GTK_TREE_MODEL(status_window->model), &iter, | |
1037 STATUS_WINDOW_COLUMN_WINDOW, &dialog, | |
1038 -1); | |
1039 if (dialog != NULL) | |
1040 { | |
1041 gtk_window_present(GTK_WINDOW(dialog->window)); | |
1042 return; | |
13144
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1043 } |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1044 } |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1045 |
10418 | 1046 dialog = g_new0(StatusEditor, 1); |
13178 | 1047 if (edit && status_window_find_savedstatus(&iter, gaim_savedstatus_get_title(saved_status))) |
13175 | 1048 { |
13144
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1049 gtk_list_store_set(status_window->model, &iter, |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1050 STATUS_WINDOW_COLUMN_WINDOW, dialog, |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1051 -1); |
13175 | 1052 } |
10418 | 1053 |
13175 | 1054 if (edit) |
12080 | 1055 dialog->original_title = g_strdup(gaim_savedstatus_get_title(saved_status)); |
10420 | 1056 |
10418 | 1057 dialog->window = win = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
1058 gtk_window_set_role(GTK_WINDOW(win), "status"); | |
1059 gtk_window_set_title(GTK_WINDOW(win), _("Status")); | |
1060 gtk_window_set_resizable(GTK_WINDOW(win), FALSE); | |
11243 | 1061 gtk_container_set_border_width(GTK_CONTAINER(win), GAIM_HIG_BORDER); |
10418 | 1062 |
1063 g_signal_connect(G_OBJECT(win), "delete_event", | |
1064 G_CALLBACK(status_editor_destroy_cb), dialog); | |
1065 | |
1066 /* Setup the vbox */ | |
11243 | 1067 vbox = gtk_vbox_new(FALSE, GAIM_HIG_BORDER); |
10418 | 1068 gtk_container_add(GTK_CONTAINER(win), vbox); |
1069 | |
1070 sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); | |
1071 | |
1072 /* Title */ | |
11243 | 1073 hbox = gtk_hbox_new(FALSE, GAIM_HIG_BOX_SPACE); |
10418 | 1074 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); |
1075 | |
1076 label = gtk_label_new_with_mnemonic(_("_Title:")); | |
1077 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
1078 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
1079 gtk_size_group_add_widget(sg, label); | |
1080 | |
1081 entry = gtk_entry_new(); | |
10420 | 1082 dialog->title = GTK_ENTRY(entry); |
13175 | 1083 if ((saved_status != NULL) |
1084 && !gaim_savedstatus_is_transient(saved_status) | |
1085 && (gaim_savedstatus_get_title(saved_status) != NULL)) | |
1086 gtk_entry_set_text(GTK_ENTRY(entry), gaim_savedstatus_get_title(saved_status)); | |
10418 | 1087 gtk_box_pack_start(GTK_BOX(hbox), entry, TRUE, TRUE, 0); |
10420 | 1088 g_signal_connect(G_OBJECT(entry), "changed", |
1089 G_CALLBACK(editor_title_changed_cb), dialog); | |
10418 | 1090 |
1091 /* Status type */ | |
11243 | 1092 hbox = gtk_hbox_new(FALSE, GAIM_HIG_BOX_SPACE); |
10418 | 1093 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); |
1094 | |
1095 label = gtk_label_new_with_mnemonic(_("_Status:")); | |
1096 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
1097 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
1098 gtk_size_group_add_widget(sg, label); | |
1099 | |
12080 | 1100 if (saved_status != NULL) |
1101 dropdown = create_status_type_menu(gaim_savedstatus_get_type(saved_status)); | |
10419 | 1102 else |
1103 dropdown = create_status_type_menu(GAIM_STATUS_AWAY); | |
10420 | 1104 dialog->type = GTK_OPTION_MENU(dropdown); |
10418 | 1105 gtk_box_pack_start(GTK_BOX(hbox), dropdown, TRUE, TRUE, 0); |
1106 | |
1107 /* Status message */ | |
11243 | 1108 hbox = gtk_hbox_new(FALSE, GAIM_HIG_BOX_SPACE); |
10418 | 1109 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); |
1110 | |
1111 label = gtk_label_new_with_mnemonic(_("_Message:")); | |
1112 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
1113 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
1114 gtk_size_group_add_widget(sg, label); | |
1115 | |
13280
3de53fe8345f
[gaim-migrate @ 15646]
Richard Laager <rlaager@wiktel.com>
parents:
13199
diff
changeset
|
1116 frame = gaim_gtk_create_imhtml(TRUE, &text, &toolbar, NULL); |
10420 | 1117 dialog->message = GTK_IMHTML(text); |
10418 | 1118 gtk_box_pack_start(GTK_BOX(hbox), frame, TRUE, TRUE, 0); |
13141
39e7014cb687
[gaim-migrate @ 15504]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13090
diff
changeset
|
1119 focus_chain = g_list_prepend(focus_chain, dialog->message); |
39e7014cb687
[gaim-migrate @ 15504]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13090
diff
changeset
|
1120 gtk_container_set_focus_chain(GTK_CONTAINER(hbox), focus_chain); |
10418 | 1121 |
12080 | 1122 if ((saved_status != NULL) && (gaim_savedstatus_get_message(saved_status) != NULL)) |
10419 | 1123 gtk_imhtml_append_text(GTK_IMHTML(text), |
12080 | 1124 gaim_savedstatus_get_message(saved_status), 0); |
10419 | 1125 |
12080 | 1126 /* Different status message expander */ |
11735 | 1127 expander = gtk_expander_new_with_mnemonic(_("Use a _different status for some accounts")); |
1128 gtk_box_pack_start(GTK_BOX(vbox), expander, FALSE, FALSE, 0); | |
10418 | 1129 |
11735 | 1130 /* Setup the box that the expander will cover */ |
11243 | 1131 dbox = gtk_vbox_new(FALSE, GAIM_HIG_CAT_SPACE); |
11735 | 1132 gtk_container_add(GTK_CONTAINER(expander), dbox); |
10418 | 1133 |
12080 | 1134 /* Different status message treeview */ |
10418 | 1135 sw = gtk_scrolled_window_new(NULL, NULL); |
1136 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), | |
1137 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); | |
1138 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), | |
1139 GTK_SHADOW_IN); | |
1140 gtk_box_pack_start(GTK_BOX(dbox), sw, TRUE, TRUE, 0); | |
1141 | |
1142 /* Create the list model */ | |
1143 dialog->model = gtk_list_store_new(STATUS_EDITOR_NUM_COLUMNS, | |
12080 | 1144 G_TYPE_POINTER, |
13144
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1145 G_TYPE_POINTER, |
10418 | 1146 G_TYPE_BOOLEAN, |
12080 | 1147 GDK_TYPE_PIXBUF, |
1148 G_TYPE_STRING, | |
1149 G_TYPE_STRING, | |
1150 G_TYPE_STRING, | |
1151 G_TYPE_STRING); | |
10418 | 1152 |
1153 /* Create the treeview */ | |
1154 dialog->treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(dialog->model)); | |
1155 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(dialog->treeview), TRUE); | |
1156 gtk_widget_set_size_request(dialog->treeview, 400, 250); | |
1157 gtk_container_add(GTK_CONTAINER(sw), dialog->treeview); | |
1158 | |
1159 /* Add columns */ | |
1160 status_editor_add_columns(dialog); | |
1161 | |
1162 /* Populate list */ | |
12080 | 1163 status_editor_populate_list(dialog, saved_status); |
10418 | 1164 |
13193 | 1165 /* Expand the treeview if we have substatuses */ |
1166 gtk_expander_set_expanded(GTK_EXPANDER(expander), | |
1167 (saved_status != NULL) && gaim_savedstatus_has_substatuses(saved_status)); | |
1168 | |
10418 | 1169 /* Button box */ |
1170 bbox = gtk_hbutton_box_new(); | |
11243 | 1171 gtk_box_set_spacing(GTK_BOX(bbox), GAIM_HIG_BOX_SPACE); |
10418 | 1172 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); |
1173 gtk_box_pack_end(GTK_BOX(vbox), bbox, FALSE, TRUE, 0); | |
1174 | |
1175 /* Cancel button */ | |
1176 button = gtk_button_new_from_stock(GTK_STOCK_CANCEL); | |
1177 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
1178 | |
1179 g_signal_connect(G_OBJECT(button), "clicked", | |
1180 G_CALLBACK(status_editor_cancel_cb), dialog); | |
1181 | |
12329 | 1182 /* Use button */ |
1183 button = gaim_pixbuf_button_from_stock(_("_Use"), GTK_STOCK_EXECUTE, | |
1184 GAIM_BUTTON_HORIZONTAL); | |
10418 | 1185 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); |
12329 | 1186 |
1187 g_signal_connect(G_OBJECT(button), "clicked", | |
1188 G_CALLBACK(status_editor_ok_cb), dialog); | |
1189 | |
1190 /* Save & Use button */ | |
1191 button = gaim_pixbuf_button_from_stock(_("Sa_ve & Use"), GTK_STOCK_OK, | |
1192 GAIM_BUTTON_HORIZONTAL); | |
1193 dialog->saveanduse_button = GTK_BUTTON(button); | |
1194 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
1195 if (dialog->original_title == NULL) | |
12080 | 1196 gtk_widget_set_sensitive(button, FALSE); |
10418 | 1197 |
1198 g_signal_connect(G_OBJECT(button), "clicked", | |
12329 | 1199 G_CALLBACK(status_editor_ok_cb), dialog); |
1200 | |
1201 /* Save button */ | |
1202 button = gtk_button_new_from_stock(GTK_STOCK_SAVE); | |
1203 dialog->save_button = GTK_BUTTON(button); | |
1204 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
1205 if (dialog->original_title == NULL) | |
1206 gtk_widget_set_sensitive(button, FALSE); | |
1207 | |
1208 g_signal_connect(G_OBJECT(button), "clicked", | |
1209 G_CALLBACK(status_editor_ok_cb), dialog); | |
10418 | 1210 |
13199 | 1211 gtk_widget_show_all(win); |
10418 | 1212 } |
1213 | |
1214 | |
10421 | 1215 /************************************************************************** |
12080 | 1216 * SubStatus editor |
1217 **************************************************************************/ | |
1218 | |
1219 static void | |
1220 substatus_selection_changed_cb(GtkComboBox *box, gpointer user_data) | |
1221 { | |
1222 SubStatusEditor *select = user_data; | |
1223 GtkTreeIter iter; | |
1224 char *id; | |
1225 GaimStatusType *type; | |
1226 | |
1227 if (!gtk_combo_box_get_active_iter(box, &iter)) | |
1228 return; | |
1229 gtk_tree_model_get(GTK_TREE_MODEL(select->model), &iter, | |
1230 SUBSTATUS_COLUMN_STATUS_ID, &id, | |
1231 -1); | |
13178 | 1232 type = gaim_account_get_status_type(select->account, id); |
12080 | 1233 g_free(id); |
1234 | |
1235 if (gaim_status_type_get_attr(type, "message") == NULL) | |
1236 { | |
1237 gtk_widget_set_sensitive(GTK_WIDGET(select->message), FALSE); | |
1238 gtk_widget_set_sensitive(GTK_WIDGET(select->toolbar), FALSE); | |
1239 } | |
1240 else | |
1241 { | |
1242 gtk_widget_set_sensitive(GTK_WIDGET(select->message), TRUE); | |
1243 gtk_widget_set_sensitive(GTK_WIDGET(select->toolbar), TRUE); | |
1244 } | |
1245 } | |
1246 | |
1247 static gboolean | |
1248 status_editor_find_account_in_treemodel(GtkTreeIter *iter, | |
1249 StatusEditor *status_editor, | |
1250 GaimAccount *account) | |
1251 { | |
1252 GtkTreeModel *model; | |
1253 GaimAccount *cur; | |
1254 | |
1255 g_return_val_if_fail(status_editor != NULL, FALSE); | |
1256 g_return_val_if_fail(account != NULL, FALSE); | |
1257 | |
1258 model = GTK_TREE_MODEL(status_editor->model); | |
1259 | |
1260 if (!gtk_tree_model_get_iter_first(model, iter)) | |
1261 return FALSE; | |
1262 | |
13178 | 1263 do { |
12080 | 1264 gtk_tree_model_get(model, iter, STATUS_EDITOR_COLUMN_ACCOUNT, &cur, -1); |
1265 if (cur == account) | |
1266 return TRUE; | |
13178 | 1267 } while (gtk_tree_model_iter_next(model, iter)); |
12080 | 1268 |
1269 return FALSE; | |
1270 } | |
1271 | |
12246 | 1272 static void |
13144
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1273 substatus_editor_remove_dialog(SubStatusEditor *dialog) |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1274 { |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1275 GtkTreeIter iter; |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1276 |
13178 | 1277 if (status_editor_find_account_in_treemodel(&iter, dialog->status_editor, dialog->account)) |
1278 { | |
1279 /* Remove the reference to this dialog from our parent's list store */ | |
13144
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1280 gtk_list_store_set(dialog->status_editor->model, &iter, |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1281 STATUS_EDITOR_COLUMN_WINDOW, NULL, |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1282 -1); |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1283 } |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1284 } |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1285 |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1286 static gboolean |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1287 substatus_editor_destroy_cb(GtkWidget *widget, GdkEvent *event, gpointer user_data) |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1288 { |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1289 SubStatusEditor *dialog = user_data; |
13178 | 1290 |
13144
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1291 substatus_editor_remove_dialog(dialog); |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1292 g_free(dialog); |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1293 |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1294 return FALSE; |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1295 } |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1296 |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1297 static void |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1298 substatus_editor_cancel_cb(GtkButton *button, gpointer user_data) |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1299 { |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1300 SubStatusEditor *dialog = user_data; |
13178 | 1301 |
13144
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1302 substatus_editor_remove_dialog(dialog); |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1303 gtk_widget_destroy(dialog->window); |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1304 g_free(dialog); |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1305 } |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1306 |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1307 |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1308 static void |
12080 | 1309 substatus_editor_ok_cb(GtkButton *button, gpointer user_data) |
1310 { | |
1311 SubStatusEditor *dialog = user_data; | |
1312 StatusEditor *status_editor; | |
1313 GtkTreeIter iter; | |
1314 GaimStatusType *type; | |
1315 char *id = NULL; | |
1316 char *message = NULL; | |
1317 const char *name = NULL; | |
1318 | |
13178 | 1319 if (!gtk_combo_box_get_active_iter(dialog->box, &iter)) |
1320 { | |
12856
be1cd5952a48
[gaim-migrate @ 15207]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12823
diff
changeset
|
1321 gtk_widget_destroy(dialog->window); |
be1cd5952a48
[gaim-migrate @ 15207]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12823
diff
changeset
|
1322 g_free(dialog); |
be1cd5952a48
[gaim-migrate @ 15207]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12823
diff
changeset
|
1323 return; |
be1cd5952a48
[gaim-migrate @ 15207]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12823
diff
changeset
|
1324 } |
be1cd5952a48
[gaim-migrate @ 15207]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12823
diff
changeset
|
1325 |
12080 | 1326 gtk_tree_model_get(GTK_TREE_MODEL(dialog->model), &iter, |
1327 SUBSTATUS_COLUMN_STATUS_ID, &id, | |
1328 -1); | |
13178 | 1329 type = gaim_account_get_status_type(dialog->account, id); |
12080 | 1330 if (gaim_status_type_get_attr(type, "message") != NULL) |
1331 message = gtk_imhtml_get_text(GTK_IMHTML(dialog->message), NULL, NULL); | |
1332 name = gaim_status_type_get_name(type); | |
1333 | |
1334 status_editor = dialog->status_editor; | |
1335 | |
13178 | 1336 if (status_editor_find_account_in_treemodel(&iter, status_editor, dialog->account)) |
12080 | 1337 { |
1338 gtk_list_store_set(status_editor->model, &iter, | |
1339 STATUS_EDITOR_COLUMN_ENABLE_SUBSTATUS, TRUE, | |
1340 STATUS_EDITOR_COLUMN_STATUS_ID, id, | |
1341 STATUS_EDITOR_COLUMN_STATUS_NAME, name, | |
1342 STATUS_EDITOR_COLUMN_STATUS_MESSAGE, message, | |
13144
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1343 STATUS_EDITOR_COLUMN_WINDOW, NULL, |
12080 | 1344 -1); |
1345 } | |
1346 | |
1347 gtk_widget_destroy(dialog->window); | |
1348 g_free(id); | |
1349 g_free(message); | |
1350 g_free(dialog); | |
1351 } | |
1352 | |
1353 static void | |
1354 edit_substatus(StatusEditor *status_editor, GaimAccount *account) | |
1355 { | |
1356 char *tmp; | |
1357 SubStatusEditor *dialog; | |
1358 GtkSizeGroup *sg; | |
1359 GtkWidget *bbox; | |
1360 GtkWidget *button; | |
1361 GtkWidget *combo; | |
1362 GtkWidget *hbox; | |
1363 GtkWidget *frame; | |
1364 GtkWidget *label; | |
1365 GtkWidget *text; | |
1366 GtkWidget *toolbar; | |
1367 GtkWidget *vbox; | |
1368 GtkWidget *win; | |
1369 GtkTreeIter iter; | |
1370 GtkCellRenderer *rend; | |
13194 | 1371 const char *status_id = NULL; |
12080 | 1372 const GList *list; |
1373 gboolean select = FALSE; | |
1374 | |
1375 g_return_if_fail(status_editor != NULL); | |
1376 g_return_if_fail(account != NULL); | |
1377 | |
13144
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1378 status_editor_find_account_in_treemodel(&iter, status_editor, account); |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1379 gtk_tree_model_get(GTK_TREE_MODEL(status_editor->model), &iter, |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1380 STATUS_EDITOR_COLUMN_WINDOW, &dialog, |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1381 -1); |
13178 | 1382 if (dialog != NULL) |
1383 { | |
13144
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1384 gtk_window_present(GTK_WINDOW(dialog->window)); |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1385 return; |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1386 } |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1387 |
12080 | 1388 dialog = g_new0(SubStatusEditor, 1); |
13144
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1389 gtk_list_store_set(status_editor->model, &iter, |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1390 STATUS_EDITOR_COLUMN_WINDOW, dialog, |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1391 -1); |
12080 | 1392 dialog->status_editor = status_editor; |
13178 | 1393 dialog->account = account; |
12080 | 1394 |
1395 dialog->window = win = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
1396 gtk_window_set_role(GTK_WINDOW(win), "substatus"); | |
1397 tmp = g_strdup_printf(_("Status for %s"), gaim_account_get_username(account)); | |
1398 gtk_window_set_title(GTK_WINDOW(win), tmp); | |
1399 g_free(tmp); | |
1400 gtk_window_set_resizable(GTK_WINDOW(win), FALSE); | |
1401 gtk_container_set_border_width(GTK_CONTAINER(win), GAIM_HIG_BORDER); | |
1402 | |
1403 g_signal_connect(G_OBJECT(win), "delete_event", | |
1404 G_CALLBACK(substatus_editor_destroy_cb), dialog); | |
1405 | |
1406 /* Setup the vbox */ | |
1407 vbox = gtk_vbox_new(FALSE, GAIM_HIG_BORDER); | |
1408 gtk_container_add(GTK_CONTAINER(win), vbox); | |
1409 | |
1410 sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); | |
1411 | |
1412 /* Status type */ | |
1413 hbox = gtk_hbox_new(FALSE, GAIM_HIG_BOX_SPACE); | |
1414 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
1415 | |
1416 label = gtk_label_new_with_mnemonic(_("_Status:")); | |
1417 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
1418 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
1419 gtk_size_group_add_widget(sg, label); | |
1420 | |
1421 dialog->model = gtk_list_store_new(SUBSTATUS_NUM_COLUMNS, | |
1422 GDK_TYPE_PIXBUF, | |
1423 G_TYPE_STRING, | |
1424 G_TYPE_STRING); | |
1425 combo = gtk_combo_box_new_with_model(GTK_TREE_MODEL(dialog->model)); | |
1426 dialog->box = GTK_COMBO_BOX(combo); | |
1427 | |
1428 rend = GTK_CELL_RENDERER(gtk_cell_renderer_pixbuf_new()); | |
1429 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), rend, FALSE); | |
1430 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), rend, | |
1431 "pixbuf", SUBSTATUS_COLUMN_ICON, NULL); | |
1432 | |
1433 rend = GTK_CELL_RENDERER(gtk_cell_renderer_text_new()); | |
1434 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), rend, TRUE); | |
1435 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), rend, | |
1436 "text", SUBSTATUS_COLUMN_STATUS_NAME, NULL); | |
1437 | |
1438 g_signal_connect(G_OBJECT(combo), "changed", | |
1439 G_CALLBACK(substatus_selection_changed_cb), dialog); | |
1440 | |
1441 gtk_box_pack_start(GTK_BOX(hbox), combo, FALSE, FALSE, 0); | |
1442 | |
1443 /* Status mesage */ | |
1444 hbox = gtk_hbox_new(FALSE, GAIM_HIG_BOX_SPACE); | |
1445 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
1446 | |
1447 label = gtk_label_new_with_mnemonic(_("_Message:")); | |
1448 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
1449 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
1450 gtk_size_group_add_widget(sg, label); | |
1451 | |
13280
3de53fe8345f
[gaim-migrate @ 15646]
Richard Laager <rlaager@wiktel.com>
parents:
13199
diff
changeset
|
1452 frame = gaim_gtk_create_imhtml(TRUE, &text, &toolbar, NULL); |
12080 | 1453 dialog->message = GTK_IMHTML(text); |
1454 dialog->toolbar = GTK_IMHTMLTOOLBAR(toolbar); | |
1455 gtk_box_pack_start(GTK_BOX(hbox), frame, TRUE, TRUE, 0); | |
1456 | |
1457 /* Button box */ | |
1458 bbox = gtk_hbutton_box_new(); | |
1459 gtk_box_set_spacing(GTK_BOX(bbox), GAIM_HIG_BOX_SPACE); | |
1460 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); | |
1461 gtk_box_pack_end(GTK_BOX(vbox), bbox, FALSE, TRUE, 0); | |
1462 | |
1463 /* Cancel button */ | |
1464 button = gtk_button_new_from_stock(GTK_STOCK_CANCEL); | |
1465 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
1466 | |
1467 g_signal_connect(G_OBJECT(button), "clicked", | |
1468 G_CALLBACK(substatus_editor_cancel_cb), dialog); | |
1469 | |
1470 /* OK button */ | |
1471 button = gtk_button_new_from_stock(GTK_STOCK_OK); | |
1472 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
1473 | |
1474 g_signal_connect(G_OBJECT(button), "clicked", | |
1475 G_CALLBACK(substatus_editor_ok_cb), dialog); | |
1476 | |
1477 /* Seed the input widgets with the current values */ | |
1478 /* TODO: Get the current values from our parent's list store, not the saved_status! */ | |
1479 if (status_editor->original_title != NULL) | |
1480 { | |
1481 GaimSavedStatus *saved_status = NULL; | |
1482 GaimSavedStatusSub *substatus = NULL; | |
1483 | |
1484 saved_status = gaim_savedstatus_find(status_editor->original_title); | |
1485 if (saved_status != NULL) | |
1486 substatus = gaim_savedstatus_get_substatus(saved_status, account); | |
1487 | |
1488 if (substatus != NULL) | |
1489 { | |
1490 gtk_imhtml_append_text(dialog->message, | |
1491 gaim_savedstatus_substatus_get_message(substatus), | |
1492 0); | |
13194 | 1493 status_id = gaim_status_type_get_id(gaim_savedstatus_substatus_get_type(substatus)); |
12080 | 1494 } |
13194 | 1495 /* TODO: Else get the generic status type from our parent */ |
12080 | 1496 } |
1497 | |
1498 for (list = gaim_account_get_status_types(account); list; list = list->next) | |
1499 { | |
1500 GaimStatusType *status_type; | |
13090 | 1501 GdkPixbuf *pixbuf; |
12080 | 1502 const char *id, *name; |
1503 | |
1504 status_type = list->data; | |
13010 | 1505 |
1506 /* Only allow users to select statuses that are flagged as "user settable" */ | |
1507 if (!gaim_status_type_is_user_settable(status_type)) | |
1508 continue; | |
1509 | |
12080 | 1510 id = gaim_status_type_get_id(status_type); |
13090 | 1511 pixbuf = gaim_gtk_create_prpl_icon_with_status(account, status_type, 0.5); |
12080 | 1512 name = gaim_status_type_get_name(status_type); |
1513 | |
1514 gtk_list_store_append(dialog->model, &iter); | |
1515 gtk_list_store_set(dialog->model, &iter, | |
13090 | 1516 SUBSTATUS_COLUMN_ICON, pixbuf, |
12080 | 1517 SUBSTATUS_COLUMN_STATUS_ID, id, |
1518 SUBSTATUS_COLUMN_STATUS_NAME, name, | |
1519 -1); | |
13090 | 1520 if (pixbuf != NULL) |
1521 g_object_unref(pixbuf); | |
13194 | 1522 if ((status_id != NULL) && !strcmp(status_id, id)) |
12080 | 1523 { |
1524 gtk_combo_box_set_active_iter(GTK_COMBO_BOX(combo), &iter); | |
1525 select = TRUE; | |
1526 } | |
1527 } | |
1528 | |
1529 if (!select) | |
1530 gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0); | |
1531 | |
13199 | 1532 gtk_widget_show_all(win); |
12080 | 1533 } |
1534 | |
12329 | 1535 |
12195 | 1536 /************************************************************************** |
1537 * Utilities * | |
1538 **************************************************************************/ | |
1539 | |
12246 | 1540 static void |
1541 status_menu_cb(GtkComboBox *widget, void(*callback)(GaimSavedStatus*)) | |
12195 | 1542 { |
12237 | 1543 GtkTreeIter iter; |
1544 gchar *title = NULL; | |
1545 | |
1546 if (!gtk_combo_box_get_active_iter(widget, &iter)) | |
1547 return; | |
1548 | |
1549 gtk_tree_model_get(gtk_combo_box_get_model(widget), &iter, | |
1550 STATUS_WINDOW_COLUMN_TITLE, &title, -1); | |
1551 callback(gaim_savedstatus_find(title)); | |
1552 g_free(title); | |
12195 | 1553 } |
1554 | |
12817 | 1555 static gint |
1556 saved_status_sort_alphabetically_func(gconstpointer a, gconstpointer b) | |
1557 { | |
1558 const GaimSavedStatus *saved_status_a = a; | |
1559 const GaimSavedStatus *saved_status_b = b; | |
12823
292a846fdeea
[gaim-migrate @ 15171]
Richard Laager <rlaager@wiktel.com>
parents:
12817
diff
changeset
|
1560 return g_utf8_collate(gaim_savedstatus_get_title(saved_status_a), |
12817 | 1561 gaim_savedstatus_get_title(saved_status_b)); |
1562 } | |
1563 | |
12195 | 1564 GtkWidget *gaim_gtk_status_menu(GaimSavedStatus *current_status, GCallback callback) |
1565 { | |
1566 GtkWidget *combobox; | |
12817 | 1567 GList *sorted, *cur; |
12195 | 1568 int i; |
1569 int index = -1; | |
12329 | 1570 |
12199 | 1571 combobox = gtk_combo_box_new_text(); |
12329 | 1572 |
12817 | 1573 sorted = g_list_copy((GList *)gaim_savedstatuses_get_all()); |
1574 sorted = g_list_sort(sorted, saved_status_sort_alphabetically_func); | |
1575 for (cur = sorted, i = 0; | |
1576 cur != NULL; | |
1577 cur = g_list_next(cur)) | |
12329 | 1578 { |
12817 | 1579 GaimSavedStatus *status = (GaimSavedStatus *)cur->data; |
13178 | 1580 if (!gaim_savedstatus_is_transient(status)) |
1581 { | |
12329 | 1582 gtk_combo_box_append_text(GTK_COMBO_BOX(combobox), |
12199 | 1583 gaim_savedstatus_get_title(status)); |
1584 if (status == current_status) | |
1585 index = i; | |
1586 i++; | |
1587 } | |
12195 | 1588 } |
12817 | 1589 g_list_free(sorted); |
12246 | 1590 |
12195 | 1591 gtk_combo_box_set_active(GTK_COMBO_BOX(combobox), index); |
1592 g_signal_connect(G_OBJECT(combobox), "changed", G_CALLBACK(status_menu_cb), callback); | |
12329 | 1593 |
12195 | 1594 return combobox; |
1595 } | |
1596 | |
12080 | 1597 |
1598 /************************************************************************** | |
10814
364a2ef907ae
[gaim-migrate @ 12468]
Luke Schierer <lschiere@pidgin.im>
parents:
10732
diff
changeset
|
1599 * GTK+ saved status glue |
10421 | 1600 **************************************************************************/ |
10418 | 1601 |
1602 void * | |
13014 | 1603 gaim_gtk_status_get_handle(void) |
10418 | 1604 { |
1605 static int handle; | |
1606 | |
1607 return &handle; | |
1608 } | |
1609 | |
1610 void | |
1611 gaim_gtk_status_init(void) | |
1612 { | |
1613 gaim_prefs_add_none("/gaim/gtk/status"); | |
1614 gaim_prefs_add_none("/gaim/gtk/status/dialog"); | |
1615 gaim_prefs_add_int("/gaim/gtk/status/dialog/width", 550); | |
1616 gaim_prefs_add_int("/gaim/gtk/status/dialog/height", 250); | |
1617 } | |
1618 | |
1619 void | |
1620 gaim_gtk_status_uninit(void) | |
1621 { | |
1622 gaim_gtk_status_window_hide(); | |
1623 } |