Mercurial > pidgin.yaz
annotate finch/gntstatus.c @ 16484:f6acb38ae250
Make sure you back up your .gaim directoy. And fix a compile error in perl. I think it's the right way.
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Fri, 27 Apr 2007 02:29:55 +0000 |
parents | 08db93bbd798 |
children | 4ca97b26a8fb |
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> | |
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 |
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
|
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); |
15818 | 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 | |
15823 | 151 purple_savedstatus_activate(gnt_tree_get_selection_data(GNT_TREE(statuses.tree))); |
15818 | 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 | |
15823 | 220 destroy_substatus_win(PurpleAccount *account, EditSubStatus *sub, gpointer null) |
15818 | 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); | |
15823 | 238 purple_notify_close_with_handle(edit); |
15818 | 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)) { | |
15823 | 251 purple_savedstatus_set_substatus(edit->saved, key->account, key->type, key->message); |
15818 | 252 } |
253 } | |
254 } | |
255 | |
256 | |
257 static void | |
258 use_trans_status_cb(GntWidget *button, EditStatus *edit) | |
259 { | |
260 const char *message; | |
15823 | 261 PurpleStatusPrimitive prim; |
262 PurpleSavedStatus *saved; | |
15818 | 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 | |
15823 | 267 saved = purple_savedstatus_find_transient_by_type_and_message(prim, message); |
15818 | 268 if (saved == NULL) { |
15823 | 269 saved = purple_savedstatus_new(NULL, prim); |
15818 | 270 edit->saved = saved; |
271 set_substatuses(edit); | |
272 } | |
15823 | 273 purple_savedstatus_set_message(saved, message); |
274 purple_savedstatus_activate(saved); | |
15818 | 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; | |
15823 | 282 PurpleStatusPrimitive prim; |
283 PurpleSavedStatus *find; | |
15818 | 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 { | |
15823 | 294 purple_notify_error(edit, _("Error"), _("Invalid title"), |
15818 | 295 _("Please enter a non-empty title for the status.")); |
296 return; | |
297 } | |
298 | |
15823 | 299 find = purple_savedstatus_find(title); |
15818 | 300 if (find && find != edit->saved) |
301 { | |
15823 | 302 purple_notify_error(edit, _("Error"), _("Duplicate title"), |
15818 | 303 _("Please enter a different title for the status.")); |
304 return; | |
305 } | |
306 | |
307 if (edit->saved == NULL) | |
308 { | |
15823 | 309 edit->saved = purple_savedstatus_new(title, prim); |
310 purple_savedstatus_set_message(edit->saved, message); | |
15818 | 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, | |
15823 | 315 purple_primitive_get_name_from_type(prim), message), NULL); |
15818 | 316 } |
317 else | |
318 { | |
15823 | 319 purple_savedstatus_set_title(edit->saved, title); |
320 purple_savedstatus_set_type(edit->saved, prim); | |
321 purple_savedstatus_set_message(edit->saved, message); | |
15818 | 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, | |
15823 | 326 purple_primitive_get_name_from_type(prim)); |
15818 | 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")) | |
15823 | 332 purple_savedstatus_activate(edit->saved); |
15818 | 333 |
334 gnt_widget_destroy(edit->window); | |
335 } | |
336 | |
337 static void | |
15823 | 338 add_substatus(EditStatus *edit, PurpleAccount *account) |
15818 | 339 { |
340 char *name; | |
341 const char *type = NULL, *message = NULL; | |
15823 | 342 PurpleSavedStatusSub *sub = NULL; |
15818 | 343 RowInfo *key; |
344 | |
345 if (!edit || !edit->tree) | |
346 return; | |
347 | |
348 if (edit->saved) | |
15823 | 349 sub = purple_savedstatus_get_substatus(edit->saved, account); |
15818 | 350 |
351 key = g_new0(RowInfo, 1); | |
352 key->account = account; | |
353 | |
354 if (sub) | |
355 { | |
15823 | 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); | |
15818 | 359 key->message = g_strdup(message); |
360 } | |
361 | |
15823 | 362 name = g_strdup_printf("%s (%s)", purple_account_get_username(account), |
363 purple_account_get_protocol_name(account)); | |
15818 | 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 { | |
15823 | 383 PurpleSavedStatus *saved = sub->parent->saved; |
15818 | 384 RowInfo *row = sub->key; |
385 const char *message; | |
15823 | 386 PurpleStatusType *type; |
15818 | 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. */ | |
15823 | 395 purple_savedstatus_set_substatus(saved, row->account, type, message); |
15818 | 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, | |
15823 | 399 purple_status_type_get_name(type)); |
15818 | 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; | |
15823 | 412 PurpleSavedStatusSub *substatus = NULL; |
15818 | 413 const GList *iter; |
414 char *name; | |
415 RowInfo *selected = gnt_tree_get_selection_data(tree); | |
15823 | 416 PurpleAccount *account = selected->account; |
15818 | 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? */ | |
15823 | 425 purple_savedstatus_unset_substatus(edit->saved, account); |
15818 | 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) | |
15823 | 435 substatus = purple_savedstatus_get_substatus(edit->saved, account); |
15818 | 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:"))); | |
15823 | 447 name = g_strdup_printf("%s (%s)", purple_account_get_username(account), |
448 purple_account_get_protocol_name(account)); | |
15818 | 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 | |
15823 | 460 for (iter = purple_account_get_status_types(account); iter; iter = iter->next) |
15818 | 461 { |
15823 | 462 PurpleStatusType *type = iter->data; |
463 if (!purple_status_type_is_user_settable(type)) | |
15818 | 464 continue; |
15823 | 465 gnt_combo_box_add_data(GNT_COMBO_BOX(combo), type, purple_status_type_get_name(type)); |
15818 | 466 } |
467 | |
468 box = gnt_hbox_new(FALSE); | |
469 gnt_box_add_widget(GNT_BOX(box), gnt_label_new(_("Message:"))); | |
15823 | 470 sub->message = entry = gnt_entry_new(substatus ? purple_savedstatus_substatus_get_message(substatus) : NULL); |
15818 | 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 | |
15823 | 494 void finch_savedstatus_edit(PurpleSavedStatus *saved) |
15818 | 495 { |
496 EditStatus *edit; | |
497 GntWidget *window, *box, *button, *entry, *combo, *label, *tree; | |
15823 | 498 PurpleStatusPrimitive prims[] = {PURPLE_STATUS_AVAILABLE, PURPLE_STATUS_AWAY, |
499 PURPLE_STATUS_INVISIBLE, PURPLE_STATUS_OFFLINE, PURPLE_STATUS_UNSET}, current; | |
15818 | 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 | |
15823 | 531 edit->title = entry = gnt_entry_new(saved ? purple_savedstatus_get_title(saved) : NULL); |
15818 | 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); | |
15823 | 542 current = saved ? purple_savedstatus_get_type(saved) : PURPLE_STATUS_UNSET; |
543 for (i = 0; prims[i] != PURPLE_STATUS_UNSET; i++) | |
15818 | 544 { |
545 gnt_combo_box_add_data(GNT_COMBO_BOX(combo), GINT_TO_POINTER(prims[i]), | |
15823 | 546 purple_primitive_get_name_from_type(prims[i])); |
15818 | 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 | |
15823 | 556 edit->message = entry = gnt_entry_new(saved ? purple_savedstatus_get_message(saved) : NULL); |
15818 | 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 | |
15823 | 571 for (iter = purple_accounts_get_all(); iter; iter = iter->next) |
15818 | 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 |