Mercurial > pidgin.yaz
annotate finch/gntstatus.c @ 23962:78c64f7c598f
Some Makefile cleanups to remove generated files from Lee Roach. Fixes #6609.
author | Daniel Atallah <daniel.atallah@gmail.com> |
---|---|
date | Sun, 31 Aug 2008 17:29:40 +0000 |
parents | dccfd999ffe7 |
children | 60f5abc6cf0c |
rev | line source |
---|---|
15818 | 1 /** |
2 * @file gntstatus.c GNT Status API | |
16194
0f0832c13fcb
Rename the Doxygen group from gntui to finch and define the finch group
Richard Laager <rlaager@wiktel.com>
parents:
15871
diff
changeset
|
3 * @ingroup finch |
20074
6bf32c9e15a7
remove gpl boilerplate from doxygen docs
Sean Egan <seanegan@gmail.com>
parents:
19680
diff
changeset
|
4 */ |
6bf32c9e15a7
remove gpl boilerplate from doxygen docs
Sean Egan <seanegan@gmail.com>
parents:
19680
diff
changeset
|
5 |
6bf32c9e15a7
remove gpl boilerplate from doxygen docs
Sean Egan <seanegan@gmail.com>
parents:
19680
diff
changeset
|
6 /* finch |
15818 | 7 * |
15871
66dff3dfdea6
Re-sed the copyright notices so they don't all talk about Purple.
Richard Laager <rlaager@wiktel.com>
parents:
15823
diff
changeset
|
8 * Finch is the legal property of its developers, whose names are too numerous |
15818 | 9 * to list here. Please refer to the COPYRIGHT file distributed with this |
10 * source distribution. | |
11 * | |
12 * This program is free software; you can redistribute it and/or modify | |
13 * it under the terms of the GNU General Public License as published by | |
14 * the Free Software Foundation; either version 2 of the License, or | |
15 * (at your option) any later version. | |
16 * | |
17 * This program is distributed in the hope that it will be useful, | |
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 * GNU General Public License for more details. | |
21 * | |
22 * You should have received a copy of the GNU General Public License | |
23 * along with this program; if not, write to the Free Software | |
19680
44b4e8bd759b
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19374
diff
changeset
|
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
15818 | 25 */ |
26 #include <gnt.h> | |
27 #include <gntbox.h> | |
28 #include <gntbutton.h> | |
29 #include <gntcombobox.h> | |
30 #include <gntentry.h> | |
31 #include <gntlabel.h> | |
32 #include <gntline.h> | |
33 #include <gnttree.h> | |
18511
7ee0e0597a26
Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
34 #include <gntutils.h> |
15818 | 35 |
18210
b8572b937c09
#include reorganizations to allow compiling with glib < 2.8 using the
Stu Tomlinson <stu@nosnilmot.com>
parents:
18118
diff
changeset
|
36 #include "finch.h" |
b8572b937c09
#include reorganizations to allow compiling with glib < 2.8 using the
Stu Tomlinson <stu@nosnilmot.com>
parents:
18118
diff
changeset
|
37 |
15818 | 38 #include <notify.h> |
39 #include <request.h> | |
40 | |
41 #include "gntstatus.h" | |
42 | |
43 static struct | |
44 { | |
45 GntWidget *window; | |
46 GntWidget *tree; | |
47 } statuses; | |
48 | |
49 typedef struct | |
50 { | |
15823 | 51 PurpleSavedStatus *saved; |
15818 | 52 GntWidget *window; |
53 GntWidget *title; | |
54 GntWidget *type; | |
55 GntWidget *message; | |
56 GntWidget *tree; | |
57 GHashTable *hash; /* list of windows for substatuses */ | |
58 } EditStatus; | |
59 | |
60 typedef struct | |
61 { | |
15823 | 62 PurpleAccount *account; |
63 const PurpleStatusType *type; | |
15818 | 64 char *message; |
65 } RowInfo; | |
66 | |
67 typedef struct | |
68 { | |
69 GntWidget *window; | |
70 GntWidget *type; | |
71 GntWidget *message; | |
72 | |
73 EditStatus *parent; | |
74 RowInfo *key; | |
75 } EditSubStatus; | |
76 | |
77 static GList *edits; /* List of opened edit-status dialogs */ | |
78 | |
79 static void | |
80 reset_status_window(GntWidget *widget, gpointer null) | |
81 { | |
82 statuses.window = NULL; | |
83 statuses.tree = NULL; | |
84 } | |
85 | |
86 static void | |
87 populate_statuses(GntTree *tree) | |
88 { | |
18118
ab6d2763b8d8
Re-fix the DBus list handling code by killing const GList* / const GSList*
Richard Laager <rlaager@wiktel.com>
parents:
18063
diff
changeset
|
89 GList *list; |
15818 | 90 |
15823 | 91 for (list = purple_savedstatuses_get_all(); list; list = list->next) |
15818 | 92 { |
15823 | 93 PurpleSavedStatus *saved = list->data; |
15818 | 94 const char *title, *type, *message; |
95 | |
15823 | 96 if (purple_savedstatus_is_transient(saved)) |
15818 | 97 continue; |
98 | |
15823 | 99 title = purple_savedstatus_get_title(saved); |
100 type = purple_primitive_get_name_from_type(purple_savedstatus_get_type(saved)); | |
101 message = purple_savedstatus_get_message(saved); /* XXX: Strip possible markups */ | |
15818 | 102 |
103 gnt_tree_add_row_last(tree, saved, | |
104 gnt_tree_create_row(tree, title, type, message), NULL); | |
105 } | |
106 } | |
107 | |
108 static void | |
15823 | 109 really_delete_status(PurpleSavedStatus *saved) |
15818 | 110 { |
111 GList *iter; | |
112 | |
113 for (iter = edits; iter; iter = iter->next) | |
114 { | |
115 EditStatus *edit = iter->data; | |
116 if (edit->saved == saved) | |
117 { | |
118 gnt_widget_destroy(edit->window); | |
119 break; | |
120 } | |
121 } | |
122 | |
123 if (statuses.tree) | |
124 gnt_tree_remove(GNT_TREE(statuses.tree), saved); | |
125 | |
15823 | 126 purple_savedstatus_delete(purple_savedstatus_get_title(saved)); |
15818 | 127 } |
128 | |
129 static void | |
130 ask_before_delete(GntWidget *button, gpointer null) | |
131 { | |
132 char *ask; | |
15823 | 133 PurpleSavedStatus *saved; |
15818 | 134 |
135 g_return_if_fail(statuses.tree != NULL); | |
136 | |
137 saved = gnt_tree_get_selection_data(GNT_TREE(statuses.tree)); | |
138 ask = g_strdup_printf(_("Are you sure you want to delete \"%s\""), | |
15823 | 139 purple_savedstatus_get_title(saved)); |
15818 | 140 |
21570
dccfd999ffe7
merge of '76c07fcb434a2a7aa289734bb221c171a376d73b'
Evan Schoenberg <evan.s@dreskin.net>
parents:
21244
diff
changeset
|
141 purple_request_action(saved, _("Delete Status"), ask, NULL, 0, |
16442
08db93bbd798
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evan.s@dreskin.net>
parents:
16194
diff
changeset
|
142 NULL, NULL, NULL, |
21570
dccfd999ffe7
merge of '76c07fcb434a2a7aa289734bb221c171a376d73b'
Evan Schoenberg <evan.s@dreskin.net>
parents:
21244
diff
changeset
|
143 saved, 2, |
16442
08db93bbd798
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evan.s@dreskin.net>
parents:
16194
diff
changeset
|
144 _("Delete"), really_delete_status, |
08db93bbd798
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evan.s@dreskin.net>
parents:
16194
diff
changeset
|
145 _("Cancel"), NULL); |
15818 | 146 g_free(ask); |
147 } | |
148 | |
149 static void | |
150 use_savedstatus_cb(GntWidget *widget, gpointer null) | |
151 { | |
152 g_return_if_fail(statuses.tree != NULL); | |
153 | |
15823 | 154 purple_savedstatus_activate(gnt_tree_get_selection_data(GNT_TREE(statuses.tree))); |
15818 | 155 } |
156 | |
157 static void | |
158 edit_savedstatus_cb(GntWidget *widget, gpointer null) | |
159 { | |
160 g_return_if_fail(statuses.tree != NULL); | |
161 | |
162 finch_savedstatus_edit(gnt_tree_get_selection_data(GNT_TREE(statuses.tree))); | |
163 } | |
164 | |
165 void finch_savedstatus_show_all() | |
166 { | |
167 GntWidget *window, *tree, *box, *button; | |
18404
9a0f99ea664d
Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18345
diff
changeset
|
168 int widths[] = {25, 12, 35}; |
18345
2d4df5ef0090
If the action-windows are already there, then bring them to front when
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18210
diff
changeset
|
169 if (statuses.window) { |
2d4df5ef0090
If the action-windows are already there, then bring them to front when
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18210
diff
changeset
|
170 gnt_window_present(statuses.window); |
15818 | 171 return; |
18345
2d4df5ef0090
If the action-windows are already there, then bring them to front when
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18210
diff
changeset
|
172 } |
15818 | 173 |
174 statuses.window = window = gnt_vbox_new(FALSE); | |
175 gnt_box_set_toplevel(GNT_BOX(window), TRUE); | |
176 gnt_box_set_title(GNT_BOX(window), _("Saved Statuses")); | |
177 gnt_box_set_fill(GNT_BOX(window), FALSE); | |
178 gnt_box_set_alignment(GNT_BOX(window), GNT_ALIGN_MID); | |
179 gnt_box_set_pad(GNT_BOX(window), 0); | |
180 | |
181 /* XXX: Add some sorting function to sort alphabetically, perhaps */ | |
182 statuses.tree = tree = gnt_tree_new_with_columns(3); | |
183 gnt_tree_set_column_titles(GNT_TREE(tree), _("Title"), _("Type"), _("Message")); | |
184 gnt_tree_set_show_title(GNT_TREE(tree), TRUE); | |
18404
9a0f99ea664d
Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18345
diff
changeset
|
185 gnt_tree_set_column_width_ratio(GNT_TREE(tree), widths); |
9a0f99ea664d
Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18345
diff
changeset
|
186 gnt_widget_set_size(tree, 72, 0); |
15818 | 187 gnt_box_add_widget(GNT_BOX(window), tree); |
188 | |
189 populate_statuses(GNT_TREE(tree)); | |
190 | |
191 box = gnt_hbox_new(FALSE); | |
192 gnt_box_add_widget(GNT_BOX(window), box); | |
193 | |
194 button = gnt_button_new(_("Use")); | |
195 gnt_box_add_widget(GNT_BOX(box), button); | |
196 g_signal_connect(G_OBJECT(button), "activate", | |
197 G_CALLBACK(use_savedstatus_cb), NULL); | |
198 | |
199 button = gnt_button_new(_("Add")); | |
200 gnt_box_add_widget(GNT_BOX(box), button); | |
18511
7ee0e0597a26
Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
201 gnt_util_set_trigger_widget(tree, GNT_KEY_INS, button); |
15818 | 202 g_signal_connect_swapped(G_OBJECT(button), "activate", |
203 G_CALLBACK(finch_savedstatus_edit), NULL); | |
204 | |
205 button = gnt_button_new(_("Edit")); | |
206 gnt_box_add_widget(GNT_BOX(box), button); | |
207 g_signal_connect(G_OBJECT(button), "activate", | |
208 G_CALLBACK(edit_savedstatus_cb), NULL); | |
209 | |
210 button = gnt_button_new(_("Delete")); | |
211 gnt_box_add_widget(GNT_BOX(box), button); | |
18511
7ee0e0597a26
Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
212 gnt_util_set_trigger_widget(tree, GNT_KEY_DEL, button); |
15818 | 213 g_signal_connect(G_OBJECT(button), "activate", |
214 G_CALLBACK(ask_before_delete), NULL); | |
215 | |
216 button = gnt_button_new(_("Close")); | |
217 gnt_box_add_widget(GNT_BOX(box), button); | |
218 g_signal_connect_swapped(G_OBJECT(button), "activate", | |
219 G_CALLBACK(gnt_widget_destroy), window); | |
220 | |
221 g_signal_connect(G_OBJECT(window), "destroy", | |
222 G_CALLBACK(reset_status_window), NULL); | |
223 gnt_widget_show(window); | |
224 } | |
225 | |
226 static void | |
15823 | 227 destroy_substatus_win(PurpleAccount *account, EditSubStatus *sub, gpointer null) |
15818 | 228 { |
229 gnt_widget_destroy(sub->window); /* the "destroy" callback will remove entry from the hashtable */ | |
230 } | |
231 | |
232 static void | |
233 free_key(gpointer key, gpointer n) | |
234 { | |
235 RowInfo *row = key; | |
236 g_free(row->message); | |
237 g_free(key); | |
238 } | |
239 | |
240 | |
241 static void | |
242 update_edit_list(GntWidget *widget, EditStatus *edit) | |
243 { | |
244 edits = g_list_remove(edits, edit); | |
15823 | 245 purple_notify_close_with_handle(edit); |
15818 | 246 g_hash_table_foreach(edit->hash, (GHFunc)destroy_substatus_win, NULL); |
247 g_list_foreach((GList*)gnt_tree_get_rows(GNT_TREE(edit->tree)), free_key, NULL); | |
248 g_free(edit); | |
249 } | |
250 | |
251 static void | |
252 set_substatuses(EditStatus *edit) | |
253 { | |
18118
ab6d2763b8d8
Re-fix the DBus list handling code by killing const GList* / const GSList*
Richard Laager <rlaager@wiktel.com>
parents:
18063
diff
changeset
|
254 GList *iter; |
15818 | 255 for (iter = gnt_tree_get_rows(GNT_TREE(edit->tree)); iter; iter = iter->next) { |
256 RowInfo *key = iter->data; | |
257 if (gnt_tree_get_choice(GNT_TREE(edit->tree), key)) { | |
15823 | 258 purple_savedstatus_set_substatus(edit->saved, key->account, key->type, key->message); |
15818 | 259 } |
260 } | |
261 } | |
262 | |
263 | |
264 static void | |
265 use_trans_status_cb(GntWidget *button, EditStatus *edit) | |
266 { | |
267 const char *message; | |
15823 | 268 PurpleStatusPrimitive prim; |
269 PurpleSavedStatus *saved; | |
15818 | 270 |
271 message = gnt_entry_get_text(GNT_ENTRY(edit->message)); | |
272 prim = GPOINTER_TO_INT(gnt_combo_box_get_selected_data(GNT_COMBO_BOX(edit->type))); | |
273 | |
15823 | 274 saved = purple_savedstatus_find_transient_by_type_and_message(prim, message); |
15818 | 275 if (saved == NULL) { |
15823 | 276 saved = purple_savedstatus_new(NULL, prim); |
15818 | 277 edit->saved = saved; |
278 set_substatuses(edit); | |
279 } | |
15823 | 280 purple_savedstatus_set_message(saved, message); |
281 purple_savedstatus_activate(saved); | |
15818 | 282 gnt_widget_destroy(edit->window); |
283 } | |
284 | |
285 static void | |
286 save_savedstatus_cb(GntWidget *button, EditStatus *edit) | |
287 { | |
288 const char *title, *message; | |
15823 | 289 PurpleStatusPrimitive prim; |
290 PurpleSavedStatus *find; | |
15818 | 291 |
292 title = gnt_entry_get_text(GNT_ENTRY(edit->title)); | |
293 message = gnt_entry_get_text(GNT_ENTRY(edit->message)); | |
294 if (!message || !*message) | |
295 message = NULL; | |
296 | |
297 prim = GPOINTER_TO_INT(gnt_combo_box_get_selected_data(GNT_COMBO_BOX(edit->type))); | |
298 | |
299 if (!title || !*title) | |
300 { | |
15823 | 301 purple_notify_error(edit, _("Error"), _("Invalid title"), |
15818 | 302 _("Please enter a non-empty title for the status.")); |
19374
d65ce3df5be2
Make some of the dialogs look and behave more like each other.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18511
diff
changeset
|
303 gnt_box_give_focus_to_child(GNT_BOX(edit->window), edit->title); |
15818 | 304 return; |
305 } | |
306 | |
15823 | 307 find = purple_savedstatus_find(title); |
15818 | 308 if (find && find != edit->saved) |
309 { | |
15823 | 310 purple_notify_error(edit, _("Error"), _("Duplicate title"), |
15818 | 311 _("Please enter a different title for the status.")); |
19374
d65ce3df5be2
Make some of the dialogs look and behave more like each other.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18511
diff
changeset
|
312 gnt_box_give_focus_to_child(GNT_BOX(edit->window), edit->title); |
15818 | 313 return; |
314 } | |
315 | |
316 if (edit->saved == NULL) | |
317 { | |
15823 | 318 edit->saved = purple_savedstatus_new(title, prim); |
319 purple_savedstatus_set_message(edit->saved, message); | |
15818 | 320 set_substatuses(edit); |
321 if (statuses.tree) | |
322 gnt_tree_add_row_last(GNT_TREE(statuses.tree), edit->saved, | |
323 gnt_tree_create_row(GNT_TREE(statuses.tree), title, | |
15823 | 324 purple_primitive_get_name_from_type(prim), message), NULL); |
15818 | 325 } |
326 else | |
327 { | |
15823 | 328 purple_savedstatus_set_title(edit->saved, title); |
329 purple_savedstatus_set_type(edit->saved, prim); | |
330 purple_savedstatus_set_message(edit->saved, message); | |
15818 | 331 if (statuses.tree) |
332 { | |
333 gnt_tree_change_text(GNT_TREE(statuses.tree), edit->saved, 0, title); | |
334 gnt_tree_change_text(GNT_TREE(statuses.tree), edit->saved, 1, | |
15823 | 335 purple_primitive_get_name_from_type(prim)); |
15818 | 336 gnt_tree_change_text(GNT_TREE(statuses.tree), edit->saved, 2, message); |
337 } | |
338 } | |
339 | |
340 if (g_object_get_data(G_OBJECT(button), "use")) | |
15823 | 341 purple_savedstatus_activate(edit->saved); |
15818 | 342 |
343 gnt_widget_destroy(edit->window); | |
344 } | |
345 | |
346 static void | |
15823 | 347 add_substatus(EditStatus *edit, PurpleAccount *account) |
15818 | 348 { |
349 char *name; | |
350 const char *type = NULL, *message = NULL; | |
15823 | 351 PurpleSavedStatusSub *sub = NULL; |
15818 | 352 RowInfo *key; |
353 | |
354 if (!edit || !edit->tree) | |
355 return; | |
356 | |
357 if (edit->saved) | |
15823 | 358 sub = purple_savedstatus_get_substatus(edit->saved, account); |
15818 | 359 |
360 key = g_new0(RowInfo, 1); | |
361 key->account = account; | |
362 | |
363 if (sub) | |
364 { | |
15823 | 365 key->type = purple_savedstatus_substatus_get_type(sub); |
366 type = purple_status_type_get_name(key->type); | |
367 message = purple_savedstatus_substatus_get_message(sub); | |
15818 | 368 key->message = g_strdup(message); |
369 } | |
370 | |
15823 | 371 name = g_strdup_printf("%s (%s)", purple_account_get_username(account), |
372 purple_account_get_protocol_name(account)); | |
15818 | 373 gnt_tree_add_choice(GNT_TREE(edit->tree), key, |
374 gnt_tree_create_row(GNT_TREE(edit->tree), | |
375 name, type ? type : "", message ? message : ""), NULL, NULL); | |
376 | |
377 if (sub) | |
378 gnt_tree_set_choice(GNT_TREE(edit->tree), key, TRUE); | |
379 g_free(name); | |
380 } | |
381 | |
382 static void | |
383 substatus_window_destroy_cb(GntWidget *window, EditSubStatus *sub) | |
384 { | |
385 g_hash_table_remove(sub->parent->hash, sub->key->account); | |
386 g_free(sub); | |
387 } | |
388 | |
389 static void | |
390 save_substatus_cb(GntWidget *widget, EditSubStatus *sub) | |
391 { | |
15823 | 392 PurpleSavedStatus *saved = sub->parent->saved; |
15818 | 393 RowInfo *row = sub->key; |
394 const char *message; | |
15823 | 395 PurpleStatusType *type; |
15818 | 396 |
397 type = gnt_combo_box_get_selected_data(GNT_COMBO_BOX(sub->type)); | |
398 message = gnt_entry_get_text(GNT_ENTRY(sub->message)); | |
399 | |
400 row->type = type; | |
401 row->message = g_strdup(message); | |
402 | |
403 if (saved) /* Save the substatus if the savedstatus actually exists. */ | |
15823 | 404 purple_savedstatus_set_substatus(saved, row->account, type, message); |
15818 | 405 |
406 gnt_tree_set_choice(GNT_TREE(sub->parent->tree), row, TRUE); | |
407 gnt_tree_change_text(GNT_TREE(sub->parent->tree), row, 1, | |
15823 | 408 purple_status_type_get_name(type)); |
15818 | 409 gnt_tree_change_text(GNT_TREE(sub->parent->tree), row, 2, message); |
410 | |
411 gnt_widget_destroy(sub->window); | |
412 } | |
413 | |
414 static gboolean | |
415 popup_substatus(GntTree *tree, const char *key, EditStatus *edit) | |
416 { | |
417 if (key[0] == ' ' && key[1] == 0) | |
418 { | |
419 EditSubStatus *sub; | |
420 GntWidget *window, *combo, *entry, *box, *button, *l; | |
15823 | 421 PurpleSavedStatusSub *substatus = NULL; |
18118
ab6d2763b8d8
Re-fix the DBus list handling code by killing const GList* / const GSList*
Richard Laager <rlaager@wiktel.com>
parents:
18063
diff
changeset
|
422 GList *iter; |
15818 | 423 char *name; |
424 RowInfo *selected = gnt_tree_get_selection_data(tree); | |
15823 | 425 PurpleAccount *account = selected->account; |
15818 | 426 |
427 if (gnt_tree_get_choice(tree, selected)) | |
428 { | |
429 /* There was a savedstatus for this account. Now remove it. */ | |
430 g_free(selected->message); | |
431 selected->type = NULL; | |
432 selected->message = NULL; | |
433 /* XXX: should we really be saving it right now? */ | |
15823 | 434 purple_savedstatus_unset_substatus(edit->saved, account); |
15818 | 435 gnt_tree_change_text(tree, account, 1, NULL); |
436 gnt_tree_change_text(tree, account, 2, NULL); | |
437 return FALSE; | |
438 } | |
439 | |
440 if (g_hash_table_lookup(edit->hash, account)) | |
441 return TRUE; | |
442 | |
443 if (edit->saved) | |
15823 | 444 substatus = purple_savedstatus_get_substatus(edit->saved, account); |
15818 | 445 |
446 sub = g_new0(EditSubStatus, 1); | |
447 sub->parent = edit; | |
448 sub->key = selected; | |
449 | |
450 sub->window = window = gnt_vbox_new(FALSE); | |
451 gnt_box_set_toplevel(GNT_BOX(window), TRUE); | |
452 gnt_box_set_title(GNT_BOX(window), _("Substatus")); /* XXX: a better title */ | |
19374
d65ce3df5be2
Make some of the dialogs look and behave more like each other.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18511
diff
changeset
|
453 gnt_box_set_alignment(GNT_BOX(window), GNT_ALIGN_MID); |
15818 | 454 |
455 box = gnt_hbox_new(FALSE); | |
456 gnt_box_add_widget(GNT_BOX(box), gnt_label_new(_("Account:"))); | |
15823 | 457 name = g_strdup_printf("%s (%s)", purple_account_get_username(account), |
458 purple_account_get_protocol_name(account)); | |
15818 | 459 gnt_box_add_widget(GNT_BOX(box), gnt_label_new(name)); |
460 g_free(name); | |
461 gnt_box_add_widget(GNT_BOX(window), box); | |
462 | |
463 box = gnt_hbox_new(FALSE); | |
464 gnt_box_add_widget(GNT_BOX(box), (l = gnt_label_new(_("Status:")))); | |
465 gnt_widget_set_size(l, 0, 1); /* I don't like having to do this */ | |
466 sub->type = combo = gnt_combo_box_new(); | |
467 gnt_box_add_widget(GNT_BOX(box), combo); | |
468 gnt_box_add_widget(GNT_BOX(window), box); | |
469 | |
15823 | 470 for (iter = purple_account_get_status_types(account); iter; iter = iter->next) |
15818 | 471 { |
15823 | 472 PurpleStatusType *type = iter->data; |
473 if (!purple_status_type_is_user_settable(type)) | |
15818 | 474 continue; |
15823 | 475 gnt_combo_box_add_data(GNT_COMBO_BOX(combo), type, purple_status_type_get_name(type)); |
15818 | 476 } |
477 | |
478 box = gnt_hbox_new(FALSE); | |
479 gnt_box_add_widget(GNT_BOX(box), gnt_label_new(_("Message:"))); | |
15823 | 480 sub->message = entry = gnt_entry_new(substatus ? purple_savedstatus_substatus_get_message(substatus) : NULL); |
15818 | 481 gnt_box_add_widget(GNT_BOX(box), entry); |
482 gnt_box_add_widget(GNT_BOX(window), box); | |
483 | |
484 box = gnt_hbox_new(FALSE); | |
485 button = gnt_button_new(_("Cancel")); | |
486 g_signal_connect_swapped(G_OBJECT(button), "activate", G_CALLBACK(gnt_widget_destroy), window); | |
487 gnt_box_add_widget(GNT_BOX(box), button); | |
488 button = gnt_button_new(_("Save")); | |
489 g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(save_substatus_cb), sub); | |
490 gnt_box_add_widget(GNT_BOX(box), button); | |
491 gnt_box_add_widget(GNT_BOX(window), box); | |
492 | |
493 gnt_widget_show(window); | |
494 | |
495 g_hash_table_insert(edit->hash, account, sub); | |
496 | |
497 g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(substatus_window_destroy_cb), sub); | |
498 | |
499 return TRUE; | |
500 } | |
501 return FALSE; | |
502 } | |
503 | |
15823 | 504 void finch_savedstatus_edit(PurpleSavedStatus *saved) |
15818 | 505 { |
506 EditStatus *edit; | |
507 GntWidget *window, *box, *button, *entry, *combo, *label, *tree; | |
15823 | 508 PurpleStatusPrimitive prims[] = {PURPLE_STATUS_AVAILABLE, PURPLE_STATUS_AWAY, |
509 PURPLE_STATUS_INVISIBLE, PURPLE_STATUS_OFFLINE, PURPLE_STATUS_UNSET}, current; | |
18063
926ccb104da0
disapproval of revision '1411afd7660760db59966c3a9f18e2adab8eb27e'
Richard Laager <rlaager@wiktel.com>
parents:
18058
diff
changeset
|
510 GList *iter; |
15818 | 511 int i; |
512 | |
513 if (saved) | |
514 { | |
515 GList *iter; | |
516 for (iter = edits; iter; iter = iter->next) | |
517 { | |
518 edit = iter->data; | |
519 if (edit->saved == saved) | |
520 return; | |
521 } | |
522 } | |
523 | |
524 edit = g_new0(EditStatus, 1); | |
525 edit->saved = saved; | |
526 edit->window = window = gnt_vbox_new(FALSE); | |
527 gnt_box_set_toplevel(GNT_BOX(window), TRUE); | |
528 gnt_box_set_title(GNT_BOX(window), _("Edit Status")); | |
529 gnt_box_set_fill(GNT_BOX(window), TRUE); | |
19374
d65ce3df5be2
Make some of the dialogs look and behave more like each other.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18511
diff
changeset
|
530 gnt_box_set_alignment(GNT_BOX(window), GNT_ALIGN_MID); |
15818 | 531 gnt_box_set_pad(GNT_BOX(window), 0); |
532 | |
533 edits = g_list_append(edits, edit); | |
534 | |
535 /* Title */ | |
536 box = gnt_hbox_new(FALSE); | |
537 gnt_box_set_alignment(GNT_BOX(box), GNT_ALIGN_LEFT); | |
538 gnt_box_add_widget(GNT_BOX(window), box); | |
539 gnt_box_add_widget(GNT_BOX(box), gnt_label_new(_("Title"))); | |
540 | |
15823 | 541 edit->title = entry = gnt_entry_new(saved ? purple_savedstatus_get_title(saved) : NULL); |
15818 | 542 gnt_box_add_widget(GNT_BOX(box), entry); |
543 | |
544 /* Type */ | |
545 box = gnt_hbox_new(FALSE); | |
546 gnt_box_add_widget(GNT_BOX(window), box); | |
547 gnt_box_add_widget(GNT_BOX(box), label = gnt_label_new(_("Status"))); | |
548 gnt_widget_set_size(label, 0, 1); | |
549 | |
550 edit->type = combo = gnt_combo_box_new(); | |
551 gnt_box_add_widget(GNT_BOX(box), combo); | |
15823 | 552 current = saved ? purple_savedstatus_get_type(saved) : PURPLE_STATUS_UNSET; |
553 for (i = 0; prims[i] != PURPLE_STATUS_UNSET; i++) | |
15818 | 554 { |
555 gnt_combo_box_add_data(GNT_COMBO_BOX(combo), GINT_TO_POINTER(prims[i]), | |
15823 | 556 purple_primitive_get_name_from_type(prims[i])); |
15818 | 557 if (prims[i] == current) |
558 gnt_combo_box_set_selected(GNT_COMBO_BOX(combo), GINT_TO_POINTER(current)); | |
559 } | |
560 | |
561 /* Message */ | |
562 box = gnt_hbox_new(FALSE); | |
563 gnt_box_add_widget(GNT_BOX(window), box); | |
564 gnt_box_add_widget(GNT_BOX(box), gnt_label_new(_("Message"))); | |
565 | |
15823 | 566 edit->message = entry = gnt_entry_new(saved ? purple_savedstatus_get_message(saved) : NULL); |
15818 | 567 gnt_box_add_widget(GNT_BOX(window), entry); |
568 | |
569 gnt_box_add_widget(GNT_BOX(window), gnt_hline_new()); | |
570 gnt_box_add_widget(GNT_BOX(window), gnt_label_new(_("Use different status for following accounts"))); | |
571 | |
572 edit->hash = g_hash_table_new(g_direct_hash, g_direct_equal); | |
573 edit->tree = tree = gnt_tree_new_with_columns(3); | |
574 gnt_box_add_widget(GNT_BOX(window), tree); | |
575 gnt_tree_set_show_title(GNT_TREE(tree), TRUE); | |
576 gnt_tree_set_column_titles(GNT_TREE(tree), _("Account"), _("Status"), _("Message")); | |
577 gnt_tree_set_col_width(GNT_TREE(tree), 0, 30); | |
578 gnt_tree_set_col_width(GNT_TREE(tree), 1, 10); | |
579 gnt_tree_set_col_width(GNT_TREE(tree), 2, 30); | |
580 | |
15823 | 581 for (iter = purple_accounts_get_all(); iter; iter = iter->next) |
15818 | 582 { |
583 add_substatus(edit, iter->data); | |
584 } | |
585 | |
586 g_signal_connect(G_OBJECT(tree), "key_pressed", G_CALLBACK(popup_substatus), edit); | |
587 | |
588 /* The buttons */ | |
589 box = gnt_hbox_new(FALSE); | |
590 gnt_box_add_widget(GNT_BOX(window), box); | |
591 | |
592 /* Use */ | |
593 button = gnt_button_new(_("Use")); | |
594 gnt_box_add_widget(GNT_BOX(box), button); | |
595 g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(use_trans_status_cb), edit); | |
596 | |
597 /* Save */ | |
598 button = gnt_button_new(_("Save")); | |
599 gnt_box_add_widget(GNT_BOX(box), button); | |
600 g_object_set_data(G_OBJECT(button), "use", NULL); | |
601 g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(save_savedstatus_cb), edit); | |
602 | |
603 /* Save & Use */ | |
604 button = gnt_button_new(_("Save & Use")); | |
605 gnt_box_add_widget(GNT_BOX(box), button); | |
606 g_object_set_data(G_OBJECT(button), "use", GINT_TO_POINTER(TRUE)); | |
607 g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(save_savedstatus_cb), edit); | |
608 | |
609 /* Cancel */ | |
610 button = gnt_button_new(_("Cancel")); | |
611 gnt_box_add_widget(GNT_BOX(box), button); | |
612 g_signal_connect_swapped(G_OBJECT(button), "activate", | |
613 G_CALLBACK(gnt_widget_destroy), window); | |
614 | |
615 g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(update_edit_list), edit); | |
616 | |
617 gnt_widget_show(window); | |
618 } | |
619 |