Mercurial > pidgin.yaz
annotate src/gtksavedstatuses.c @ 13808:34d086c78a0d
[gaim-migrate @ 16234]
Use libxml2 on win32 too.
This increases the installer size by ~400K (oh well).
committer: Tailor Script <tailor@pidgin.im>
author | Daniel Atallah <daniel.atallah@gmail.com> |
---|---|
date | Thu, 08 Jun 2006 15:13:39 +0000 |
parents | b76c6de0c3b5 |
children | f1dd1555b39c |
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 } | |
763 g_free(id); | |
764 g_free(message); | |
13144
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
765 } while (gtk_tree_model_iter_next(model, &iter)); |
12080 | 766 } |
767 | |
10420 | 768 g_free(message); |
769 g_free(unformatted); | |
770 | |
13178 | 771 status_editor_remove_dialog(dialog); |
10420 | 772 gtk_widget_destroy(dialog->window); |
10574 | 773 g_free(dialog->original_title); |
10420 | 774 |
12080 | 775 if (status_window != NULL) |
12199 | 776 add_status_to_saved_status_list(status_window->model, saved_status); |
12329 | 777 |
13010 | 778 /* If they clicked on "Save & Use" or "Use," then activate the status */ |
779 if (button != dialog->save_button) | |
12329 | 780 gaim_savedstatus_activate(saved_status); |
13178 | 781 |
13172
12d960995cdc
[gaim-migrate @ 15535]
Richard Laager <rlaager@wiktel.com>
parents:
13144
diff
changeset
|
782 g_free(dialog); |
10420 | 783 } |
784 | |
785 static void | |
786 editor_title_changed_cb(GtkWidget *widget, gpointer user_data) | |
787 { | |
788 StatusEditor *dialog = user_data; | |
789 const gchar *text; | |
790 | |
791 text = gtk_entry_get_text(dialog->title); | |
792 | |
12329 | 793 gtk_widget_set_sensitive(GTK_WIDGET(dialog->saveanduse_button), (*text != '\0')); |
794 gtk_widget_set_sensitive(GTK_WIDGET(dialog->save_button), (*text != '\0')); | |
10418 | 795 } |
796 | |
797 static GtkWidget * | |
10419 | 798 create_status_type_menu(GaimStatusPrimitive type) |
10418 | 799 { |
10419 | 800 int i; |
10418 | 801 GtkWidget *dropdown; |
802 GtkWidget *menu; | |
803 GtkWidget *item; | |
804 | |
805 dropdown = gtk_option_menu_new(); | |
806 menu = gtk_menu_new(); | |
807 | |
12693
07d6cc1b5a98
[gaim-migrate @ 15036]
Richard Laager <rlaager@wiktel.com>
parents:
12329
diff
changeset
|
808 for (i = GAIM_STATUS_UNSET + 1; i < GAIM_STATUS_NUM_PRIMITIVES; i++) |
10419 | 809 { |
810 item = gtk_menu_item_new_with_label(gaim_primitive_get_name_from_type(i)); | |
811 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); | |
812 } | |
10418 | 813 |
12693
07d6cc1b5a98
[gaim-migrate @ 15036]
Richard Laager <rlaager@wiktel.com>
parents:
12329
diff
changeset
|
814 gtk_menu_set_active(GTK_MENU(menu), type - (GAIM_STATUS_UNSET + 1)); |
10418 | 815 gtk_option_menu_set_menu(GTK_OPTION_MENU(dropdown), menu); |
13199 | 816 gtk_widget_show_all(menu); |
10418 | 817 |
818 return dropdown; | |
819 } | |
820 | |
12080 | 821 static void edit_substatus(StatusEditor *status_editor, GaimAccount *account); |
822 | |
823 static void | |
824 edit_substatus_cb(GtkTreeView *tv, GtkTreePath *path, GtkTreeViewColumn *col, gpointer user_data) | |
825 { | |
826 StatusEditor *dialog = user_data; | |
827 GtkTreeIter iter; | |
828 GaimAccount *account; | |
829 | |
830 gtk_tree_model_get_iter(GTK_TREE_MODEL(dialog->model), &iter, path); | |
831 gtk_tree_model_get(GTK_TREE_MODEL(dialog->model), &iter, | |
832 STATUS_EDITOR_COLUMN_ACCOUNT, &account, | |
833 -1); | |
834 | |
835 edit_substatus(dialog, account); | |
836 } | |
837 | |
838 static void | |
839 status_editor_substatus_cb(GtkCellRendererToggle *renderer, gchar *path_str, gpointer data) | |
840 { | |
841 StatusEditor *dialog = (StatusEditor *)data; | |
842 GtkTreeIter iter; | |
843 gboolean enabled; | |
844 GaimAccount *account; | |
845 | |
846 gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(dialog->model), &iter, path_str); | |
847 gtk_tree_model_get(GTK_TREE_MODEL(dialog->model), &iter, | |
848 STATUS_EDITOR_COLUMN_ACCOUNT, &account, | |
849 STATUS_EDITOR_COLUMN_ENABLE_SUBSTATUS, &enabled, | |
850 -1); | |
851 | |
852 enabled = !enabled; | |
853 | |
854 if (enabled) | |
855 { | |
856 edit_substatus(dialog, account); | |
857 } | |
858 else | |
859 { | |
860 /* Remove the substatus */ | |
861 gtk_list_store_set(dialog->model, &iter, | |
862 STATUS_EDITOR_COLUMN_ENABLE_SUBSTATUS, enabled, | |
863 STATUS_EDITOR_COLUMN_STATUS_ID, NULL, | |
864 STATUS_EDITOR_COLUMN_STATUS_NAME, NULL, | |
865 STATUS_EDITOR_COLUMN_STATUS_MESSAGE, NULL, | |
866 -1); | |
867 } | |
868 } | |
869 | |
10418 | 870 static void |
871 status_editor_add_columns(StatusEditor *dialog) | |
872 { | |
873 GtkCellRenderer *renderer; | |
874 GtkTreeViewColumn *column; | |
875 | |
12080 | 876 /* Enable Different status column */ |
10418 | 877 renderer = gtk_cell_renderer_toggle_new(); |
878 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(dialog->treeview), | |
12080 | 879 -1, _("Different"), |
10418 | 880 renderer, |
12080 | 881 "active", STATUS_EDITOR_COLUMN_ENABLE_SUBSTATUS, |
10418 | 882 NULL); |
883 g_signal_connect(G_OBJECT(renderer), "toggled", | |
12080 | 884 G_CALLBACK(status_editor_substatus_cb), dialog); |
10418 | 885 |
886 /* Screen Name column */ | |
887 column = gtk_tree_view_column_new(); | |
888 gtk_tree_view_column_set_resizable(column, TRUE); | |
889 gtk_tree_view_column_set_title(column, _("Screen Name")); | |
890 gtk_tree_view_insert_column(GTK_TREE_VIEW(dialog->treeview), column, -1); | |
891 gtk_tree_view_column_set_resizable(column, TRUE); | |
892 | |
893 /* Icon */ | |
894 renderer = gtk_cell_renderer_pixbuf_new(); | |
895 gtk_tree_view_column_pack_start(column, renderer, FALSE); | |
896 gtk_tree_view_column_add_attribute(column, renderer, "pixbuf", | |
897 STATUS_EDITOR_COLUMN_ICON); | |
898 | |
899 /* Screen Name */ | |
900 renderer = gtk_cell_renderer_text_new(); | |
901 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
902 gtk_tree_view_column_add_attribute(column, renderer, "text", | |
903 STATUS_EDITOR_COLUMN_SCREENNAME); | |
12080 | 904 |
905 /* Status column */ | |
906 column = gtk_tree_view_column_new(); | |
907 gtk_tree_view_column_set_resizable(column, TRUE); | |
908 gtk_tree_view_column_set_title(column, _("Status")); | |
909 gtk_tree_view_insert_column(GTK_TREE_VIEW(dialog->treeview), column, -1); | |
910 gtk_tree_view_column_set_resizable(column, TRUE); | |
911 renderer = gtk_cell_renderer_text_new(); | |
912 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
913 gtk_tree_view_column_add_attribute(column, renderer, "text", | |
914 STATUS_EDITOR_COLUMN_STATUS_NAME); | |
915 | |
916 /* Message column */ | |
917 column = gtk_tree_view_column_new(); | |
918 gtk_tree_view_column_set_resizable(column, TRUE); | |
919 gtk_tree_view_column_set_title(column, _("Message")); | |
920 gtk_tree_view_insert_column(GTK_TREE_VIEW(dialog->treeview), column, -1); | |
921 gtk_tree_view_column_set_resizable(column, TRUE); | |
922 renderer = gtk_cell_renderer_text_new(); | |
923 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
924 gtk_tree_view_column_add_attribute(column, renderer, "text", | |
925 STATUS_EDITOR_COLUMN_STATUS_MESSAGE); | |
926 | |
927 g_signal_connect(G_OBJECT(dialog->treeview), "row-activated", | |
928 G_CALLBACK(edit_substatus_cb), dialog); | |
10418 | 929 } |
930 | |
931 static void | |
12080 | 932 status_editor_set_account(GtkListStore *store, GaimAccount *account, |
933 GtkTreeIter *iter, GaimSavedStatusSub *substatus) | |
10418 | 934 { |
935 GdkPixbuf *pixbuf; | |
12080 | 936 const char *id = NULL, *name = NULL, *message = NULL; |
10418 | 937 |
13090 | 938 pixbuf = gaim_gtk_create_prpl_icon(account, 0.5); |
939 if ((pixbuf != NULL) && !gaim_account_is_connected(account)) | |
10418 | 940 { |
13090 | 941 gdk_pixbuf_saturate_and_pixelate(pixbuf, pixbuf, 0.0, FALSE); |
10418 | 942 } |
943 | |
12080 | 944 if (substatus != NULL) |
945 { | |
946 const GaimStatusType *type; | |
947 | |
948 type = gaim_savedstatus_substatus_get_type(substatus); | |
949 id = gaim_status_type_get_id(type); | |
950 name = gaim_status_type_get_name(type); | |
951 if (gaim_status_type_get_attr(type, "message")) | |
952 message = gaim_savedstatus_substatus_get_message(substatus); | |
953 } | |
954 | |
10418 | 955 gtk_list_store_set(store, iter, |
12080 | 956 STATUS_EDITOR_COLUMN_ACCOUNT, account, |
957 STATUS_EDITOR_COLUMN_ENABLE_SUBSTATUS, (substatus != NULL), | |
13090 | 958 STATUS_EDITOR_COLUMN_ICON, pixbuf, |
10418 | 959 STATUS_EDITOR_COLUMN_SCREENNAME, gaim_account_get_username(account), |
12080 | 960 STATUS_EDITOR_COLUMN_STATUS_ID, id, |
961 STATUS_EDITOR_COLUMN_STATUS_NAME, name, | |
962 STATUS_EDITOR_COLUMN_STATUS_MESSAGE, message, | |
10418 | 963 -1); |
964 | |
13090 | 965 if (pixbuf != NULL) |
966 g_object_unref(G_OBJECT(pixbuf)); | |
10418 | 967 } |
968 | |
969 static void | |
12080 | 970 status_editor_add_account(StatusEditor *dialog, GaimAccount *account, |
971 GaimSavedStatusSub *substatus) | |
10418 | 972 { |
973 GtkTreeIter iter; | |
974 | |
975 gtk_list_store_append(dialog->model, &iter); | |
976 | |
12080 | 977 status_editor_set_account(dialog->model, account, &iter, substatus); |
10418 | 978 } |
979 | |
980 static void | |
12080 | 981 status_editor_populate_list(StatusEditor *dialog, GaimSavedStatus *saved_status) |
10418 | 982 { |
12080 | 983 GList *iter; |
984 GaimSavedStatusSub *substatus; | |
10418 | 985 |
986 gtk_list_store_clear(dialog->model); | |
987 | |
12080 | 988 for (iter = gaim_accounts_get_all(); iter != NULL; iter = iter->next) |
989 { | |
990 GaimAccount *account = (GaimAccount *)iter->data; | |
991 | |
992 if (saved_status != NULL) | |
993 substatus = gaim_savedstatus_get_substatus(saved_status, account); | |
994 else | |
995 substatus = NULL; | |
996 | |
997 status_editor_add_account(dialog, account, substatus); | |
998 } | |
10418 | 999 } |
1000 | |
1001 void | |
13175 | 1002 gaim_gtk_status_editor_show(gboolean edit, GaimSavedStatus *saved_status) |
10418 | 1003 { |
13144
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1004 GtkTreeIter iter; |
10418 | 1005 StatusEditor *dialog; |
1006 GtkSizeGroup *sg; | |
1007 GtkWidget *bbox; | |
1008 GtkWidget *button; | |
1009 GtkWidget *dbox; | |
11735 | 1010 GtkWidget *expander; |
10418 | 1011 GtkWidget *dropdown; |
1012 GtkWidget *entry; | |
1013 GtkWidget *frame; | |
1014 GtkWidget *hbox; | |
1015 GtkWidget *label; | |
1016 GtkWidget *sw; | |
1017 GtkWidget *text; | |
1018 GtkWidget *toolbar; | |
1019 GtkWidget *vbox; | |
1020 GtkWidget *win; | |
13141
39e7014cb687
[gaim-migrate @ 15504]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13090
diff
changeset
|
1021 GList *focus_chain = NULL; |
10418 | 1022 |
13175 | 1023 if (edit) |
1024 { | |
1025 g_return_if_fail(saved_status != NULL); | |
1026 g_return_if_fail(!gaim_savedstatus_is_transient(saved_status)); | |
1027 } | |
1028 | |
13144
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1029 /* Find a possible window for this saved status and present it */ |
13178 | 1030 if (edit && status_window_find_savedstatus(&iter, gaim_savedstatus_get_title(saved_status))) |
13175 | 1031 { |
1032 gtk_tree_model_get(GTK_TREE_MODEL(status_window->model), &iter, | |
1033 STATUS_WINDOW_COLUMN_WINDOW, &dialog, | |
1034 -1); | |
1035 if (dialog != NULL) | |
1036 { | |
1037 gtk_window_present(GTK_WINDOW(dialog->window)); | |
1038 return; | |
13144
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1039 } |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1040 } |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1041 |
10418 | 1042 dialog = g_new0(StatusEditor, 1); |
13178 | 1043 if (edit && status_window_find_savedstatus(&iter, gaim_savedstatus_get_title(saved_status))) |
13175 | 1044 { |
13144
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1045 gtk_list_store_set(status_window->model, &iter, |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1046 STATUS_WINDOW_COLUMN_WINDOW, dialog, |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1047 -1); |
13175 | 1048 } |
10418 | 1049 |
13175 | 1050 if (edit) |
12080 | 1051 dialog->original_title = g_strdup(gaim_savedstatus_get_title(saved_status)); |
10420 | 1052 |
10418 | 1053 dialog->window = win = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
1054 gtk_window_set_role(GTK_WINDOW(win), "status"); | |
1055 gtk_window_set_title(GTK_WINDOW(win), _("Status")); | |
1056 gtk_window_set_resizable(GTK_WINDOW(win), FALSE); | |
11243 | 1057 gtk_container_set_border_width(GTK_CONTAINER(win), GAIM_HIG_BORDER); |
10418 | 1058 |
1059 g_signal_connect(G_OBJECT(win), "delete_event", | |
1060 G_CALLBACK(status_editor_destroy_cb), dialog); | |
1061 | |
1062 /* Setup the vbox */ | |
11243 | 1063 vbox = gtk_vbox_new(FALSE, GAIM_HIG_BORDER); |
10418 | 1064 gtk_container_add(GTK_CONTAINER(win), vbox); |
1065 | |
1066 sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); | |
1067 | |
1068 /* Title */ | |
11243 | 1069 hbox = gtk_hbox_new(FALSE, GAIM_HIG_BOX_SPACE); |
10418 | 1070 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); |
1071 | |
1072 label = gtk_label_new_with_mnemonic(_("_Title:")); | |
1073 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
1074 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
1075 gtk_size_group_add_widget(sg, label); | |
1076 | |
1077 entry = gtk_entry_new(); | |
10420 | 1078 dialog->title = GTK_ENTRY(entry); |
13175 | 1079 if ((saved_status != NULL) |
1080 && !gaim_savedstatus_is_transient(saved_status) | |
1081 && (gaim_savedstatus_get_title(saved_status) != NULL)) | |
1082 gtk_entry_set_text(GTK_ENTRY(entry), gaim_savedstatus_get_title(saved_status)); | |
10418 | 1083 gtk_box_pack_start(GTK_BOX(hbox), entry, TRUE, TRUE, 0); |
10420 | 1084 g_signal_connect(G_OBJECT(entry), "changed", |
1085 G_CALLBACK(editor_title_changed_cb), dialog); | |
10418 | 1086 |
1087 /* Status type */ | |
11243 | 1088 hbox = gtk_hbox_new(FALSE, GAIM_HIG_BOX_SPACE); |
10418 | 1089 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); |
1090 | |
1091 label = gtk_label_new_with_mnemonic(_("_Status:")); | |
1092 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
1093 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
1094 gtk_size_group_add_widget(sg, label); | |
1095 | |
12080 | 1096 if (saved_status != NULL) |
1097 dropdown = create_status_type_menu(gaim_savedstatus_get_type(saved_status)); | |
10419 | 1098 else |
1099 dropdown = create_status_type_menu(GAIM_STATUS_AWAY); | |
10420 | 1100 dialog->type = GTK_OPTION_MENU(dropdown); |
10418 | 1101 gtk_box_pack_start(GTK_BOX(hbox), dropdown, TRUE, TRUE, 0); |
1102 | |
1103 /* Status message */ | |
11243 | 1104 hbox = gtk_hbox_new(FALSE, GAIM_HIG_BOX_SPACE); |
10418 | 1105 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); |
1106 | |
1107 label = gtk_label_new_with_mnemonic(_("_Message:")); | |
1108 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
1109 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
1110 gtk_size_group_add_widget(sg, label); | |
1111 | |
13280
3de53fe8345f
[gaim-migrate @ 15646]
Richard Laager <rlaager@wiktel.com>
parents:
13199
diff
changeset
|
1112 frame = gaim_gtk_create_imhtml(TRUE, &text, &toolbar, NULL); |
10420 | 1113 dialog->message = GTK_IMHTML(text); |
10418 | 1114 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
|
1115 focus_chain = g_list_prepend(focus_chain, dialog->message); |
39e7014cb687
[gaim-migrate @ 15504]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13090
diff
changeset
|
1116 gtk_container_set_focus_chain(GTK_CONTAINER(hbox), focus_chain); |
10418 | 1117 |
12080 | 1118 if ((saved_status != NULL) && (gaim_savedstatus_get_message(saved_status) != NULL)) |
10419 | 1119 gtk_imhtml_append_text(GTK_IMHTML(text), |
12080 | 1120 gaim_savedstatus_get_message(saved_status), 0); |
10419 | 1121 |
12080 | 1122 /* Different status message expander */ |
11735 | 1123 expander = gtk_expander_new_with_mnemonic(_("Use a _different status for some accounts")); |
1124 gtk_box_pack_start(GTK_BOX(vbox), expander, FALSE, FALSE, 0); | |
10418 | 1125 |
11735 | 1126 /* Setup the box that the expander will cover */ |
11243 | 1127 dbox = gtk_vbox_new(FALSE, GAIM_HIG_CAT_SPACE); |
11735 | 1128 gtk_container_add(GTK_CONTAINER(expander), dbox); |
10418 | 1129 |
12080 | 1130 /* Different status message treeview */ |
10418 | 1131 sw = gtk_scrolled_window_new(NULL, NULL); |
1132 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), | |
1133 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); | |
1134 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), | |
1135 GTK_SHADOW_IN); | |
1136 gtk_box_pack_start(GTK_BOX(dbox), sw, TRUE, TRUE, 0); | |
1137 | |
1138 /* Create the list model */ | |
1139 dialog->model = gtk_list_store_new(STATUS_EDITOR_NUM_COLUMNS, | |
12080 | 1140 G_TYPE_POINTER, |
13144
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1141 G_TYPE_POINTER, |
10418 | 1142 G_TYPE_BOOLEAN, |
12080 | 1143 GDK_TYPE_PIXBUF, |
1144 G_TYPE_STRING, | |
1145 G_TYPE_STRING, | |
1146 G_TYPE_STRING, | |
1147 G_TYPE_STRING); | |
10418 | 1148 |
1149 /* Create the treeview */ | |
1150 dialog->treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(dialog->model)); | |
1151 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(dialog->treeview), TRUE); | |
1152 gtk_widget_set_size_request(dialog->treeview, 400, 250); | |
1153 gtk_container_add(GTK_CONTAINER(sw), dialog->treeview); | |
1154 | |
1155 /* Add columns */ | |
1156 status_editor_add_columns(dialog); | |
1157 | |
1158 /* Populate list */ | |
12080 | 1159 status_editor_populate_list(dialog, saved_status); |
10418 | 1160 |
13193 | 1161 /* Expand the treeview if we have substatuses */ |
1162 gtk_expander_set_expanded(GTK_EXPANDER(expander), | |
1163 (saved_status != NULL) && gaim_savedstatus_has_substatuses(saved_status)); | |
1164 | |
10418 | 1165 /* Button box */ |
1166 bbox = gtk_hbutton_box_new(); | |
11243 | 1167 gtk_box_set_spacing(GTK_BOX(bbox), GAIM_HIG_BOX_SPACE); |
10418 | 1168 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); |
1169 gtk_box_pack_end(GTK_BOX(vbox), bbox, FALSE, TRUE, 0); | |
1170 | |
1171 /* Cancel button */ | |
1172 button = gtk_button_new_from_stock(GTK_STOCK_CANCEL); | |
1173 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
1174 | |
1175 g_signal_connect(G_OBJECT(button), "clicked", | |
1176 G_CALLBACK(status_editor_cancel_cb), dialog); | |
1177 | |
12329 | 1178 /* Use button */ |
1179 button = gaim_pixbuf_button_from_stock(_("_Use"), GTK_STOCK_EXECUTE, | |
1180 GAIM_BUTTON_HORIZONTAL); | |
10418 | 1181 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); |
12329 | 1182 |
1183 g_signal_connect(G_OBJECT(button), "clicked", | |
1184 G_CALLBACK(status_editor_ok_cb), dialog); | |
1185 | |
1186 /* Save & Use button */ | |
1187 button = gaim_pixbuf_button_from_stock(_("Sa_ve & Use"), GTK_STOCK_OK, | |
1188 GAIM_BUTTON_HORIZONTAL); | |
1189 dialog->saveanduse_button = GTK_BUTTON(button); | |
1190 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
1191 if (dialog->original_title == NULL) | |
12080 | 1192 gtk_widget_set_sensitive(button, FALSE); |
10418 | 1193 |
1194 g_signal_connect(G_OBJECT(button), "clicked", | |
12329 | 1195 G_CALLBACK(status_editor_ok_cb), dialog); |
1196 | |
1197 /* Save button */ | |
1198 button = gtk_button_new_from_stock(GTK_STOCK_SAVE); | |
1199 dialog->save_button = GTK_BUTTON(button); | |
1200 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
1201 if (dialog->original_title == NULL) | |
1202 gtk_widget_set_sensitive(button, FALSE); | |
1203 | |
1204 g_signal_connect(G_OBJECT(button), "clicked", | |
1205 G_CALLBACK(status_editor_ok_cb), dialog); | |
10418 | 1206 |
13199 | 1207 gtk_widget_show_all(win); |
10418 | 1208 } |
1209 | |
1210 | |
10421 | 1211 /************************************************************************** |
12080 | 1212 * SubStatus editor |
1213 **************************************************************************/ | |
1214 | |
1215 static void | |
1216 substatus_selection_changed_cb(GtkComboBox *box, gpointer user_data) | |
1217 { | |
1218 SubStatusEditor *select = user_data; | |
1219 GtkTreeIter iter; | |
1220 char *id; | |
1221 GaimStatusType *type; | |
1222 | |
1223 if (!gtk_combo_box_get_active_iter(box, &iter)) | |
1224 return; | |
1225 gtk_tree_model_get(GTK_TREE_MODEL(select->model), &iter, | |
1226 SUBSTATUS_COLUMN_STATUS_ID, &id, | |
1227 -1); | |
13178 | 1228 type = gaim_account_get_status_type(select->account, id); |
12080 | 1229 g_free(id); |
1230 | |
1231 if (gaim_status_type_get_attr(type, "message") == NULL) | |
1232 { | |
1233 gtk_widget_set_sensitive(GTK_WIDGET(select->message), FALSE); | |
1234 gtk_widget_set_sensitive(GTK_WIDGET(select->toolbar), FALSE); | |
1235 } | |
1236 else | |
1237 { | |
1238 gtk_widget_set_sensitive(GTK_WIDGET(select->message), TRUE); | |
1239 gtk_widget_set_sensitive(GTK_WIDGET(select->toolbar), TRUE); | |
1240 } | |
1241 } | |
1242 | |
1243 static gboolean | |
1244 status_editor_find_account_in_treemodel(GtkTreeIter *iter, | |
1245 StatusEditor *status_editor, | |
1246 GaimAccount *account) | |
1247 { | |
1248 GtkTreeModel *model; | |
1249 GaimAccount *cur; | |
1250 | |
1251 g_return_val_if_fail(status_editor != NULL, FALSE); | |
1252 g_return_val_if_fail(account != NULL, FALSE); | |
1253 | |
1254 model = GTK_TREE_MODEL(status_editor->model); | |
1255 | |
1256 if (!gtk_tree_model_get_iter_first(model, iter)) | |
1257 return FALSE; | |
1258 | |
13178 | 1259 do { |
12080 | 1260 gtk_tree_model_get(model, iter, STATUS_EDITOR_COLUMN_ACCOUNT, &cur, -1); |
1261 if (cur == account) | |
1262 return TRUE; | |
13178 | 1263 } while (gtk_tree_model_iter_next(model, iter)); |
12080 | 1264 |
1265 return FALSE; | |
1266 } | |
1267 | |
12246 | 1268 static void |
13144
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1269 substatus_editor_remove_dialog(SubStatusEditor *dialog) |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1270 { |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1271 GtkTreeIter iter; |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1272 |
13178 | 1273 if (status_editor_find_account_in_treemodel(&iter, dialog->status_editor, dialog->account)) |
1274 { | |
1275 /* 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
|
1276 gtk_list_store_set(dialog->status_editor->model, &iter, |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1277 STATUS_EDITOR_COLUMN_WINDOW, NULL, |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1278 -1); |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1279 } |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1280 } |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1281 |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1282 static gboolean |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1283 substatus_editor_destroy_cb(GtkWidget *widget, GdkEvent *event, gpointer user_data) |
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 SubStatusEditor *dialog = user_data; |
13178 | 1286 |
13144
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1287 substatus_editor_remove_dialog(dialog); |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1288 g_free(dialog); |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1289 |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1290 return FALSE; |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1291 } |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1292 |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1293 static void |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1294 substatus_editor_cancel_cb(GtkButton *button, gpointer user_data) |
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 SubStatusEditor *dialog = user_data; |
13178 | 1297 |
13144
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1298 substatus_editor_remove_dialog(dialog); |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1299 gtk_widget_destroy(dialog->window); |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1300 g_free(dialog); |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1301 } |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1302 |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1303 |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1304 static void |
12080 | 1305 substatus_editor_ok_cb(GtkButton *button, gpointer user_data) |
1306 { | |
1307 SubStatusEditor *dialog = user_data; | |
1308 StatusEditor *status_editor; | |
1309 GtkTreeIter iter; | |
1310 GaimStatusType *type; | |
1311 char *id = NULL; | |
1312 char *message = NULL; | |
1313 const char *name = NULL; | |
1314 | |
13178 | 1315 if (!gtk_combo_box_get_active_iter(dialog->box, &iter)) |
1316 { | |
12856
be1cd5952a48
[gaim-migrate @ 15207]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12823
diff
changeset
|
1317 gtk_widget_destroy(dialog->window); |
be1cd5952a48
[gaim-migrate @ 15207]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12823
diff
changeset
|
1318 g_free(dialog); |
be1cd5952a48
[gaim-migrate @ 15207]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12823
diff
changeset
|
1319 return; |
be1cd5952a48
[gaim-migrate @ 15207]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12823
diff
changeset
|
1320 } |
be1cd5952a48
[gaim-migrate @ 15207]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12823
diff
changeset
|
1321 |
12080 | 1322 gtk_tree_model_get(GTK_TREE_MODEL(dialog->model), &iter, |
1323 SUBSTATUS_COLUMN_STATUS_ID, &id, | |
1324 -1); | |
13178 | 1325 type = gaim_account_get_status_type(dialog->account, id); |
12080 | 1326 if (gaim_status_type_get_attr(type, "message") != NULL) |
1327 message = gtk_imhtml_get_text(GTK_IMHTML(dialog->message), NULL, NULL); | |
1328 name = gaim_status_type_get_name(type); | |
1329 | |
1330 status_editor = dialog->status_editor; | |
1331 | |
13178 | 1332 if (status_editor_find_account_in_treemodel(&iter, status_editor, dialog->account)) |
12080 | 1333 { |
1334 gtk_list_store_set(status_editor->model, &iter, | |
1335 STATUS_EDITOR_COLUMN_ENABLE_SUBSTATUS, TRUE, | |
1336 STATUS_EDITOR_COLUMN_STATUS_ID, id, | |
1337 STATUS_EDITOR_COLUMN_STATUS_NAME, name, | |
1338 STATUS_EDITOR_COLUMN_STATUS_MESSAGE, message, | |
13144
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1339 STATUS_EDITOR_COLUMN_WINDOW, NULL, |
12080 | 1340 -1); |
1341 } | |
1342 | |
1343 gtk_widget_destroy(dialog->window); | |
1344 g_free(id); | |
1345 g_free(message); | |
1346 g_free(dialog); | |
1347 } | |
1348 | |
1349 static void | |
1350 edit_substatus(StatusEditor *status_editor, GaimAccount *account) | |
1351 { | |
1352 char *tmp; | |
1353 SubStatusEditor *dialog; | |
1354 GtkSizeGroup *sg; | |
1355 GtkWidget *bbox; | |
1356 GtkWidget *button; | |
1357 GtkWidget *combo; | |
1358 GtkWidget *hbox; | |
1359 GtkWidget *frame; | |
1360 GtkWidget *label; | |
1361 GtkWidget *text; | |
1362 GtkWidget *toolbar; | |
1363 GtkWidget *vbox; | |
1364 GtkWidget *win; | |
1365 GtkTreeIter iter; | |
1366 GtkCellRenderer *rend; | |
13194 | 1367 const char *status_id = NULL; |
12080 | 1368 const GList *list; |
1369 gboolean select = FALSE; | |
1370 | |
1371 g_return_if_fail(status_editor != NULL); | |
1372 g_return_if_fail(account != NULL); | |
1373 | |
13144
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1374 status_editor_find_account_in_treemodel(&iter, status_editor, account); |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1375 gtk_tree_model_get(GTK_TREE_MODEL(status_editor->model), &iter, |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1376 STATUS_EDITOR_COLUMN_WINDOW, &dialog, |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1377 -1); |
13178 | 1378 if (dialog != NULL) |
1379 { | |
13144
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1380 gtk_window_present(GTK_WINDOW(dialog->window)); |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1381 return; |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1382 } |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1383 |
12080 | 1384 dialog = g_new0(SubStatusEditor, 1); |
13144
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1385 gtk_list_store_set(status_editor->model, &iter, |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1386 STATUS_EDITOR_COLUMN_WINDOW, dialog, |
e90e8655290d
[gaim-migrate @ 15507]
Richard Laager <rlaager@wiktel.com>
parents:
13141
diff
changeset
|
1387 -1); |
12080 | 1388 dialog->status_editor = status_editor; |
13178 | 1389 dialog->account = account; |
12080 | 1390 |
1391 dialog->window = win = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
1392 gtk_window_set_role(GTK_WINDOW(win), "substatus"); | |
1393 tmp = g_strdup_printf(_("Status for %s"), gaim_account_get_username(account)); | |
1394 gtk_window_set_title(GTK_WINDOW(win), tmp); | |
1395 g_free(tmp); | |
1396 gtk_window_set_resizable(GTK_WINDOW(win), FALSE); | |
1397 gtk_container_set_border_width(GTK_CONTAINER(win), GAIM_HIG_BORDER); | |
1398 | |
1399 g_signal_connect(G_OBJECT(win), "delete_event", | |
1400 G_CALLBACK(substatus_editor_destroy_cb), dialog); | |
1401 | |
1402 /* Setup the vbox */ | |
1403 vbox = gtk_vbox_new(FALSE, GAIM_HIG_BORDER); | |
1404 gtk_container_add(GTK_CONTAINER(win), vbox); | |
1405 | |
1406 sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); | |
1407 | |
1408 /* Status type */ | |
1409 hbox = gtk_hbox_new(FALSE, GAIM_HIG_BOX_SPACE); | |
1410 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
1411 | |
1412 label = gtk_label_new_with_mnemonic(_("_Status:")); | |
1413 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
1414 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
1415 gtk_size_group_add_widget(sg, label); | |
1416 | |
1417 dialog->model = gtk_list_store_new(SUBSTATUS_NUM_COLUMNS, | |
1418 GDK_TYPE_PIXBUF, | |
1419 G_TYPE_STRING, | |
1420 G_TYPE_STRING); | |
1421 combo = gtk_combo_box_new_with_model(GTK_TREE_MODEL(dialog->model)); | |
1422 dialog->box = GTK_COMBO_BOX(combo); | |
1423 | |
1424 rend = GTK_CELL_RENDERER(gtk_cell_renderer_pixbuf_new()); | |
1425 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), rend, FALSE); | |
1426 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), rend, | |
1427 "pixbuf", SUBSTATUS_COLUMN_ICON, NULL); | |
1428 | |
1429 rend = GTK_CELL_RENDERER(gtk_cell_renderer_text_new()); | |
1430 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), rend, TRUE); | |
1431 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), rend, | |
1432 "text", SUBSTATUS_COLUMN_STATUS_NAME, NULL); | |
1433 | |
1434 g_signal_connect(G_OBJECT(combo), "changed", | |
1435 G_CALLBACK(substatus_selection_changed_cb), dialog); | |
1436 | |
1437 gtk_box_pack_start(GTK_BOX(hbox), combo, FALSE, FALSE, 0); | |
1438 | |
1439 /* Status mesage */ | |
1440 hbox = gtk_hbox_new(FALSE, GAIM_HIG_BOX_SPACE); | |
1441 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
1442 | |
1443 label = gtk_label_new_with_mnemonic(_("_Message:")); | |
1444 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
1445 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
1446 gtk_size_group_add_widget(sg, label); | |
1447 | |
13280
3de53fe8345f
[gaim-migrate @ 15646]
Richard Laager <rlaager@wiktel.com>
parents:
13199
diff
changeset
|
1448 frame = gaim_gtk_create_imhtml(TRUE, &text, &toolbar, NULL); |
12080 | 1449 dialog->message = GTK_IMHTML(text); |
1450 dialog->toolbar = GTK_IMHTMLTOOLBAR(toolbar); | |
1451 gtk_box_pack_start(GTK_BOX(hbox), frame, TRUE, TRUE, 0); | |
1452 | |
1453 /* Button box */ | |
1454 bbox = gtk_hbutton_box_new(); | |
1455 gtk_box_set_spacing(GTK_BOX(bbox), GAIM_HIG_BOX_SPACE); | |
1456 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); | |
1457 gtk_box_pack_end(GTK_BOX(vbox), bbox, FALSE, TRUE, 0); | |
1458 | |
1459 /* Cancel button */ | |
1460 button = gtk_button_new_from_stock(GTK_STOCK_CANCEL); | |
1461 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
1462 | |
1463 g_signal_connect(G_OBJECT(button), "clicked", | |
1464 G_CALLBACK(substatus_editor_cancel_cb), dialog); | |
1465 | |
1466 /* OK button */ | |
1467 button = gtk_button_new_from_stock(GTK_STOCK_OK); | |
1468 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
1469 | |
1470 g_signal_connect(G_OBJECT(button), "clicked", | |
1471 G_CALLBACK(substatus_editor_ok_cb), dialog); | |
1472 | |
1473 /* Seed the input widgets with the current values */ | |
1474 /* TODO: Get the current values from our parent's list store, not the saved_status! */ | |
1475 if (status_editor->original_title != NULL) | |
1476 { | |
1477 GaimSavedStatus *saved_status = NULL; | |
1478 GaimSavedStatusSub *substatus = NULL; | |
1479 | |
1480 saved_status = gaim_savedstatus_find(status_editor->original_title); | |
1481 if (saved_status != NULL) | |
1482 substatus = gaim_savedstatus_get_substatus(saved_status, account); | |
1483 | |
1484 if (substatus != NULL) | |
1485 { | |
1486 gtk_imhtml_append_text(dialog->message, | |
1487 gaim_savedstatus_substatus_get_message(substatus), | |
1488 0); | |
13194 | 1489 status_id = gaim_status_type_get_id(gaim_savedstatus_substatus_get_type(substatus)); |
12080 | 1490 } |
13194 | 1491 /* TODO: Else get the generic status type from our parent */ |
12080 | 1492 } |
1493 | |
1494 for (list = gaim_account_get_status_types(account); list; list = list->next) | |
1495 { | |
1496 GaimStatusType *status_type; | |
13090 | 1497 GdkPixbuf *pixbuf; |
12080 | 1498 const char *id, *name; |
1499 | |
1500 status_type = list->data; | |
13010 | 1501 |
1502 /* Only allow users to select statuses that are flagged as "user settable" */ | |
1503 if (!gaim_status_type_is_user_settable(status_type)) | |
1504 continue; | |
1505 | |
12080 | 1506 id = gaim_status_type_get_id(status_type); |
13090 | 1507 pixbuf = gaim_gtk_create_prpl_icon_with_status(account, status_type, 0.5); |
12080 | 1508 name = gaim_status_type_get_name(status_type); |
1509 | |
1510 gtk_list_store_append(dialog->model, &iter); | |
1511 gtk_list_store_set(dialog->model, &iter, | |
13090 | 1512 SUBSTATUS_COLUMN_ICON, pixbuf, |
12080 | 1513 SUBSTATUS_COLUMN_STATUS_ID, id, |
1514 SUBSTATUS_COLUMN_STATUS_NAME, name, | |
1515 -1); | |
13090 | 1516 if (pixbuf != NULL) |
1517 g_object_unref(pixbuf); | |
13194 | 1518 if ((status_id != NULL) && !strcmp(status_id, id)) |
12080 | 1519 { |
1520 gtk_combo_box_set_active_iter(GTK_COMBO_BOX(combo), &iter); | |
1521 select = TRUE; | |
1522 } | |
1523 } | |
1524 | |
1525 if (!select) | |
1526 gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0); | |
1527 | |
13199 | 1528 gtk_widget_show_all(win); |
12080 | 1529 } |
1530 | |
12329 | 1531 |
12195 | 1532 /************************************************************************** |
1533 * Utilities * | |
1534 **************************************************************************/ | |
1535 | |
12246 | 1536 static void |
1537 status_menu_cb(GtkComboBox *widget, void(*callback)(GaimSavedStatus*)) | |
12195 | 1538 { |
12237 | 1539 GtkTreeIter iter; |
1540 gchar *title = NULL; | |
1541 | |
1542 if (!gtk_combo_box_get_active_iter(widget, &iter)) | |
1543 return; | |
1544 | |
1545 gtk_tree_model_get(gtk_combo_box_get_model(widget), &iter, | |
1546 STATUS_WINDOW_COLUMN_TITLE, &title, -1); | |
1547 callback(gaim_savedstatus_find(title)); | |
1548 g_free(title); | |
12195 | 1549 } |
1550 | |
12817 | 1551 static gint |
1552 saved_status_sort_alphabetically_func(gconstpointer a, gconstpointer b) | |
1553 { | |
1554 const GaimSavedStatus *saved_status_a = a; | |
1555 const GaimSavedStatus *saved_status_b = b; | |
12823
292a846fdeea
[gaim-migrate @ 15171]
Richard Laager <rlaager@wiktel.com>
parents:
12817
diff
changeset
|
1556 return g_utf8_collate(gaim_savedstatus_get_title(saved_status_a), |
12817 | 1557 gaim_savedstatus_get_title(saved_status_b)); |
1558 } | |
1559 | |
12195 | 1560 GtkWidget *gaim_gtk_status_menu(GaimSavedStatus *current_status, GCallback callback) |
1561 { | |
1562 GtkWidget *combobox; | |
12817 | 1563 GList *sorted, *cur; |
12195 | 1564 int i; |
1565 int index = -1; | |
12329 | 1566 |
12199 | 1567 combobox = gtk_combo_box_new_text(); |
12329 | 1568 |
12817 | 1569 sorted = g_list_copy((GList *)gaim_savedstatuses_get_all()); |
1570 sorted = g_list_sort(sorted, saved_status_sort_alphabetically_func); | |
1571 for (cur = sorted, i = 0; | |
1572 cur != NULL; | |
1573 cur = g_list_next(cur)) | |
12329 | 1574 { |
12817 | 1575 GaimSavedStatus *status = (GaimSavedStatus *)cur->data; |
13178 | 1576 if (!gaim_savedstatus_is_transient(status)) |
1577 { | |
12329 | 1578 gtk_combo_box_append_text(GTK_COMBO_BOX(combobox), |
12199 | 1579 gaim_savedstatus_get_title(status)); |
1580 if (status == current_status) | |
1581 index = i; | |
1582 i++; | |
1583 } | |
12195 | 1584 } |
12817 | 1585 g_list_free(sorted); |
12246 | 1586 |
12195 | 1587 gtk_combo_box_set_active(GTK_COMBO_BOX(combobox), index); |
1588 g_signal_connect(G_OBJECT(combobox), "changed", G_CALLBACK(status_menu_cb), callback); | |
12329 | 1589 |
12195 | 1590 return combobox; |
1591 } | |
1592 | |
12080 | 1593 |
1594 /************************************************************************** | |
10814
364a2ef907ae
[gaim-migrate @ 12468]
Luke Schierer <lschiere@pidgin.im>
parents:
10732
diff
changeset
|
1595 * GTK+ saved status glue |
10421 | 1596 **************************************************************************/ |
10418 | 1597 |
1598 void * | |
13014 | 1599 gaim_gtk_status_get_handle(void) |
10418 | 1600 { |
1601 static int handle; | |
1602 | |
1603 return &handle; | |
1604 } | |
1605 | |
1606 void | |
1607 gaim_gtk_status_init(void) | |
1608 { | |
1609 gaim_prefs_add_none("/gaim/gtk/status"); | |
1610 gaim_prefs_add_none("/gaim/gtk/status/dialog"); | |
1611 gaim_prefs_add_int("/gaim/gtk/status/dialog/width", 550); | |
1612 gaim_prefs_add_int("/gaim/gtk/status/dialog/height", 250); | |
1613 } | |
1614 | |
1615 void | |
1616 gaim_gtk_status_uninit(void) | |
1617 { | |
1618 gaim_gtk_status_window_hide(); | |
1619 } |