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