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