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