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