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