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