Mercurial > pidgin.yaz
annotate finch/gntstatus.c @ 19486:3321a2136a94
propagate from branch 'im.pidgin.soc.2007.xmpp' (head f6a67901e79d8d35e6bf30f0766b2417740090b7)
to branch 'im.pidgin.pidgin' (head 9a6fe0cb4c5141137e31d52c12a408d9056ec6fc)
author | Evan Schoenberg <evan.s@dreskin.net> |
---|---|
date | Mon, 27 Aug 2007 23:44:39 +0000 |
parents | d65ce3df5be2 |
children | 44b4e8bd759b 315151da0dc6 |
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> | |
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> |
15818 | 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 |
15818 | 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 { | |
15823 | 50 PurpleSavedStatus *saved; |
15818 | 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 { | |
15823 | 61 PurpleAccount *account; |
62 const PurpleStatusType *type; | |
15818 | 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; |
15818 | 89 |
15823 | 90 for (list = purple_savedstatuses_get_all(); list; list = list->next) |
15818 | 91 { |
15823 | 92 PurpleSavedStatus *saved = list->data; |
15818 | 93 const char *title, *type, *message; |
94 | |
15823 | 95 if (purple_savedstatus_is_transient(saved)) |
15818 | 96 continue; |
97 | |
15823 | 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 */ | |
15818 | 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 | |
15823 | 108 really_delete_status(PurpleSavedStatus *saved) |
15818 | 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 | |
15823 | 125 purple_savedstatus_delete(purple_savedstatus_get_title(saved)); |
15818 | 126 } |
127 | |
128 static void | |
129 ask_before_delete(GntWidget *button, gpointer null) | |
130 { | |
131 char *ask; | |
15823 | 132 PurpleSavedStatus *saved; |
15818 | 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\""), | |
15823 | 138 purple_savedstatus_get_title(saved)); |
15818 | 139 |
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
|
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); |
15818 | 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 | |
15823 | 153 purple_savedstatus_activate(gnt_tree_get_selection_data(GNT_TREE(statuses.tree))); |
15818 | 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); |
15818 | 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 } |
15818 | 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); |
15818 | 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); |
15818 | 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); |
15818 | 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 | |
15823 | 226 destroy_substatus_win(PurpleAccount *account, EditSubStatus *sub, gpointer null) |
15818 | 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); | |
15823 | 244 purple_notify_close_with_handle(edit); |
15818 | 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; |
15818 | 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)) { | |
15823 | 257 purple_savedstatus_set_substatus(edit->saved, key->account, key->type, key->message); |
15818 | 258 } |
259 } | |
260 } | |
261 | |
262 | |
263 static void | |
264 use_trans_status_cb(GntWidget *button, EditStatus *edit) | |
265 { | |
266 const char *message; | |
15823 | 267 PurpleStatusPrimitive prim; |
268 PurpleSavedStatus *saved; | |
15818 | 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 | |
15823 | 273 saved = purple_savedstatus_find_transient_by_type_and_message(prim, message); |
15818 | 274 if (saved == NULL) { |
15823 | 275 saved = purple_savedstatus_new(NULL, prim); |
15818 | 276 edit->saved = saved; |
277 set_substatuses(edit); | |
278 } | |
15823 | 279 purple_savedstatus_set_message(saved, message); |
280 purple_savedstatus_activate(saved); | |
15818 | 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; | |
15823 | 288 PurpleStatusPrimitive prim; |
289 PurpleSavedStatus *find; | |
15818 | 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 { | |
15823 | 300 purple_notify_error(edit, _("Error"), _("Invalid title"), |
15818 | 301 _("Please enter a non-empty title for the status.")); |
19374
d65ce3df5be2
Make some of the dialogs look and behave more like each other.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18511
diff
changeset
|
302 gnt_box_give_focus_to_child(GNT_BOX(edit->window), edit->title); |
15818 | 303 return; |
304 } | |
305 | |
15823 | 306 find = purple_savedstatus_find(title); |
15818 | 307 if (find && find != edit->saved) |
308 { | |
15823 | 309 purple_notify_error(edit, _("Error"), _("Duplicate title"), |
15818 | 310 _("Please enter a different title for the status.")); |
19374
d65ce3df5be2
Make some of the dialogs look and behave more like each other.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18511
diff
changeset
|
311 gnt_box_give_focus_to_child(GNT_BOX(edit->window), edit->title); |
15818 | 312 return; |
313 } | |
314 | |
315 if (edit->saved == NULL) | |
316 { | |
15823 | 317 edit->saved = purple_savedstatus_new(title, prim); |
318 purple_savedstatus_set_message(edit->saved, message); | |
15818 | 319 set_substatuses(edit); |
320 if (statuses.tree) | |
321 gnt_tree_add_row_last(GNT_TREE(statuses.tree), edit->saved, | |
322 gnt_tree_create_row(GNT_TREE(statuses.tree), title, | |
15823 | 323 purple_primitive_get_name_from_type(prim), message), NULL); |
15818 | 324 } |
325 else | |
326 { | |
15823 | 327 purple_savedstatus_set_title(edit->saved, title); |
328 purple_savedstatus_set_type(edit->saved, prim); | |
329 purple_savedstatus_set_message(edit->saved, message); | |
15818 | 330 if (statuses.tree) |
331 { | |
332 gnt_tree_change_text(GNT_TREE(statuses.tree), edit->saved, 0, title); | |
333 gnt_tree_change_text(GNT_TREE(statuses.tree), edit->saved, 1, | |
15823 | 334 purple_primitive_get_name_from_type(prim)); |
15818 | 335 gnt_tree_change_text(GNT_TREE(statuses.tree), edit->saved, 2, message); |
336 } | |
337 } | |
338 | |
339 if (g_object_get_data(G_OBJECT(button), "use")) | |
15823 | 340 purple_savedstatus_activate(edit->saved); |
15818 | 341 |
342 gnt_widget_destroy(edit->window); | |
343 } | |
344 | |
345 static void | |
15823 | 346 add_substatus(EditStatus *edit, PurpleAccount *account) |
15818 | 347 { |
348 char *name; | |
349 const char *type = NULL, *message = NULL; | |
15823 | 350 PurpleSavedStatusSub *sub = NULL; |
15818 | 351 RowInfo *key; |
352 | |
353 if (!edit || !edit->tree) | |
354 return; | |
355 | |
356 if (edit->saved) | |
15823 | 357 sub = purple_savedstatus_get_substatus(edit->saved, account); |
15818 | 358 |
359 key = g_new0(RowInfo, 1); | |
360 key->account = account; | |
361 | |
362 if (sub) | |
363 { | |
15823 | 364 key->type = purple_savedstatus_substatus_get_type(sub); |
365 type = purple_status_type_get_name(key->type); | |
366 message = purple_savedstatus_substatus_get_message(sub); | |
15818 | 367 key->message = g_strdup(message); |
368 } | |
369 | |
15823 | 370 name = g_strdup_printf("%s (%s)", purple_account_get_username(account), |
371 purple_account_get_protocol_name(account)); | |
15818 | 372 gnt_tree_add_choice(GNT_TREE(edit->tree), key, |
373 gnt_tree_create_row(GNT_TREE(edit->tree), | |
374 name, type ? type : "", message ? message : ""), NULL, NULL); | |
375 | |
376 if (sub) | |
377 gnt_tree_set_choice(GNT_TREE(edit->tree), key, TRUE); | |
378 g_free(name); | |
379 } | |
380 | |
381 static void | |
382 substatus_window_destroy_cb(GntWidget *window, EditSubStatus *sub) | |
383 { | |
384 g_hash_table_remove(sub->parent->hash, sub->key->account); | |
385 g_free(sub); | |
386 } | |
387 | |
388 static void | |
389 save_substatus_cb(GntWidget *widget, EditSubStatus *sub) | |
390 { | |
15823 | 391 PurpleSavedStatus *saved = sub->parent->saved; |
15818 | 392 RowInfo *row = sub->key; |
393 const char *message; | |
15823 | 394 PurpleStatusType *type; |
15818 | 395 |
396 type = gnt_combo_box_get_selected_data(GNT_COMBO_BOX(sub->type)); | |
397 message = gnt_entry_get_text(GNT_ENTRY(sub->message)); | |
398 | |
399 row->type = type; | |
400 row->message = g_strdup(message); | |
401 | |
402 if (saved) /* Save the substatus if the savedstatus actually exists. */ | |
15823 | 403 purple_savedstatus_set_substatus(saved, row->account, type, message); |
15818 | 404 |
405 gnt_tree_set_choice(GNT_TREE(sub->parent->tree), row, TRUE); | |
406 gnt_tree_change_text(GNT_TREE(sub->parent->tree), row, 1, | |
15823 | 407 purple_status_type_get_name(type)); |
15818 | 408 gnt_tree_change_text(GNT_TREE(sub->parent->tree), row, 2, message); |
409 | |
410 gnt_widget_destroy(sub->window); | |
411 } | |
412 | |
413 static gboolean | |
414 popup_substatus(GntTree *tree, const char *key, EditStatus *edit) | |
415 { | |
416 if (key[0] == ' ' && key[1] == 0) | |
417 { | |
418 EditSubStatus *sub; | |
419 GntWidget *window, *combo, *entry, *box, *button, *l; | |
15823 | 420 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
|
421 GList *iter; |
15818 | 422 char *name; |
423 RowInfo *selected = gnt_tree_get_selection_data(tree); | |
15823 | 424 PurpleAccount *account = selected->account; |
15818 | 425 |
426 if (gnt_tree_get_choice(tree, selected)) | |
427 { | |
428 /* There was a savedstatus for this account. Now remove it. */ | |
429 g_free(selected->message); | |
430 selected->type = NULL; | |
431 selected->message = NULL; | |
432 /* XXX: should we really be saving it right now? */ | |
15823 | 433 purple_savedstatus_unset_substatus(edit->saved, account); |
15818 | 434 gnt_tree_change_text(tree, account, 1, NULL); |
435 gnt_tree_change_text(tree, account, 2, NULL); | |
436 return FALSE; | |
437 } | |
438 | |
439 if (g_hash_table_lookup(edit->hash, account)) | |
440 return TRUE; | |
441 | |
442 if (edit->saved) | |
15823 | 443 substatus = purple_savedstatus_get_substatus(edit->saved, account); |
15818 | 444 |
445 sub = g_new0(EditSubStatus, 1); | |
446 sub->parent = edit; | |
447 sub->key = selected; | |
448 | |
449 sub->window = window = gnt_vbox_new(FALSE); | |
450 gnt_box_set_toplevel(GNT_BOX(window), TRUE); | |
451 gnt_box_set_title(GNT_BOX(window), _("Substatus")); /* XXX: a better title */ | |
19374
d65ce3df5be2
Make some of the dialogs look and behave more like each other.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18511
diff
changeset
|
452 gnt_box_set_alignment(GNT_BOX(window), GNT_ALIGN_MID); |
15818 | 453 |
454 box = gnt_hbox_new(FALSE); | |
455 gnt_box_add_widget(GNT_BOX(box), gnt_label_new(_("Account:"))); | |
15823 | 456 name = g_strdup_printf("%s (%s)", purple_account_get_username(account), |
457 purple_account_get_protocol_name(account)); | |
15818 | 458 gnt_box_add_widget(GNT_BOX(box), gnt_label_new(name)); |
459 g_free(name); | |
460 gnt_box_add_widget(GNT_BOX(window), box); | |
461 | |
462 box = gnt_hbox_new(FALSE); | |
463 gnt_box_add_widget(GNT_BOX(box), (l = gnt_label_new(_("Status:")))); | |
464 gnt_widget_set_size(l, 0, 1); /* I don't like having to do this */ | |
465 sub->type = combo = gnt_combo_box_new(); | |
466 gnt_box_add_widget(GNT_BOX(box), combo); | |
467 gnt_box_add_widget(GNT_BOX(window), box); | |
468 | |
15823 | 469 for (iter = purple_account_get_status_types(account); iter; iter = iter->next) |
15818 | 470 { |
15823 | 471 PurpleStatusType *type = iter->data; |
472 if (!purple_status_type_is_user_settable(type)) | |
15818 | 473 continue; |
15823 | 474 gnt_combo_box_add_data(GNT_COMBO_BOX(combo), type, purple_status_type_get_name(type)); |
15818 | 475 } |
476 | |
477 box = gnt_hbox_new(FALSE); | |
478 gnt_box_add_widget(GNT_BOX(box), gnt_label_new(_("Message:"))); | |
15823 | 479 sub->message = entry = gnt_entry_new(substatus ? purple_savedstatus_substatus_get_message(substatus) : NULL); |
15818 | 480 gnt_box_add_widget(GNT_BOX(box), entry); |
481 gnt_box_add_widget(GNT_BOX(window), box); | |
482 | |
483 box = gnt_hbox_new(FALSE); | |
484 button = gnt_button_new(_("Cancel")); | |
485 g_signal_connect_swapped(G_OBJECT(button), "activate", G_CALLBACK(gnt_widget_destroy), window); | |
486 gnt_box_add_widget(GNT_BOX(box), button); | |
487 button = gnt_button_new(_("Save")); | |
488 g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(save_substatus_cb), sub); | |
489 gnt_box_add_widget(GNT_BOX(box), button); | |
490 gnt_box_add_widget(GNT_BOX(window), box); | |
491 | |
492 gnt_widget_show(window); | |
493 | |
494 g_hash_table_insert(edit->hash, account, sub); | |
495 | |
496 g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(substatus_window_destroy_cb), sub); | |
497 | |
498 return TRUE; | |
499 } | |
500 return FALSE; | |
501 } | |
502 | |
15823 | 503 void finch_savedstatus_edit(PurpleSavedStatus *saved) |
15818 | 504 { |
505 EditStatus *edit; | |
506 GntWidget *window, *box, *button, *entry, *combo, *label, *tree; | |
15823 | 507 PurpleStatusPrimitive prims[] = {PURPLE_STATUS_AVAILABLE, PURPLE_STATUS_AWAY, |
508 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
|
509 GList *iter; |
15818 | 510 int i; |
511 | |
512 if (saved) | |
513 { | |
514 GList *iter; | |
515 for (iter = edits; iter; iter = iter->next) | |
516 { | |
517 edit = iter->data; | |
518 if (edit->saved == saved) | |
519 return; | |
520 } | |
521 } | |
522 | |
523 edit = g_new0(EditStatus, 1); | |
524 edit->saved = saved; | |
525 edit->window = window = gnt_vbox_new(FALSE); | |
526 gnt_box_set_toplevel(GNT_BOX(window), TRUE); | |
527 gnt_box_set_title(GNT_BOX(window), _("Edit Status")); | |
528 gnt_box_set_fill(GNT_BOX(window), TRUE); | |
19374
d65ce3df5be2
Make some of the dialogs look and behave more like each other.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18511
diff
changeset
|
529 gnt_box_set_alignment(GNT_BOX(window), GNT_ALIGN_MID); |
15818 | 530 gnt_box_set_pad(GNT_BOX(window), 0); |
531 | |
532 edits = g_list_append(edits, edit); | |
533 | |
534 /* Title */ | |
535 box = gnt_hbox_new(FALSE); | |
536 gnt_box_set_alignment(GNT_BOX(box), GNT_ALIGN_LEFT); | |
537 gnt_box_add_widget(GNT_BOX(window), box); | |
538 gnt_box_add_widget(GNT_BOX(box), gnt_label_new(_("Title"))); | |
539 | |
15823 | 540 edit->title = entry = gnt_entry_new(saved ? purple_savedstatus_get_title(saved) : NULL); |
15818 | 541 gnt_box_add_widget(GNT_BOX(box), entry); |
542 | |
543 /* Type */ | |
544 box = gnt_hbox_new(FALSE); | |
545 gnt_box_add_widget(GNT_BOX(window), box); | |
546 gnt_box_add_widget(GNT_BOX(box), label = gnt_label_new(_("Status"))); | |
547 gnt_widget_set_size(label, 0, 1); | |
548 | |
549 edit->type = combo = gnt_combo_box_new(); | |
550 gnt_box_add_widget(GNT_BOX(box), combo); | |
15823 | 551 current = saved ? purple_savedstatus_get_type(saved) : PURPLE_STATUS_UNSET; |
552 for (i = 0; prims[i] != PURPLE_STATUS_UNSET; i++) | |
15818 | 553 { |
554 gnt_combo_box_add_data(GNT_COMBO_BOX(combo), GINT_TO_POINTER(prims[i]), | |
15823 | 555 purple_primitive_get_name_from_type(prims[i])); |
15818 | 556 if (prims[i] == current) |
557 gnt_combo_box_set_selected(GNT_COMBO_BOX(combo), GINT_TO_POINTER(current)); | |
558 } | |
559 | |
560 /* Message */ | |
561 box = gnt_hbox_new(FALSE); | |
562 gnt_box_add_widget(GNT_BOX(window), box); | |
563 gnt_box_add_widget(GNT_BOX(box), gnt_label_new(_("Message"))); | |
564 | |
15823 | 565 edit->message = entry = gnt_entry_new(saved ? purple_savedstatus_get_message(saved) : NULL); |
15818 | 566 gnt_box_add_widget(GNT_BOX(window), entry); |
567 | |
568 gnt_box_add_widget(GNT_BOX(window), gnt_hline_new()); | |
569 gnt_box_add_widget(GNT_BOX(window), gnt_label_new(_("Use different status for following accounts"))); | |
570 | |
571 edit->hash = g_hash_table_new(g_direct_hash, g_direct_equal); | |
572 edit->tree = tree = gnt_tree_new_with_columns(3); | |
573 gnt_box_add_widget(GNT_BOX(window), tree); | |
574 gnt_tree_set_show_title(GNT_TREE(tree), TRUE); | |
575 gnt_tree_set_column_titles(GNT_TREE(tree), _("Account"), _("Status"), _("Message")); | |
576 gnt_tree_set_col_width(GNT_TREE(tree), 0, 30); | |
577 gnt_tree_set_col_width(GNT_TREE(tree), 1, 10); | |
578 gnt_tree_set_col_width(GNT_TREE(tree), 2, 30); | |
579 | |
15823 | 580 for (iter = purple_accounts_get_all(); iter; iter = iter->next) |
15818 | 581 { |
582 add_substatus(edit, iter->data); | |
583 } | |
584 | |
585 g_signal_connect(G_OBJECT(tree), "key_pressed", G_CALLBACK(popup_substatus), edit); | |
586 | |
587 /* The buttons */ | |
588 box = gnt_hbox_new(FALSE); | |
589 gnt_box_add_widget(GNT_BOX(window), box); | |
590 | |
591 /* Use */ | |
592 button = gnt_button_new(_("Use")); | |
593 gnt_box_add_widget(GNT_BOX(box), button); | |
594 g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(use_trans_status_cb), edit); | |
595 | |
596 /* Save */ | |
597 button = gnt_button_new(_("Save")); | |
598 gnt_box_add_widget(GNT_BOX(box), button); | |
599 g_object_set_data(G_OBJECT(button), "use", NULL); | |
600 g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(save_savedstatus_cb), edit); | |
601 | |
602 /* Save & Use */ | |
603 button = gnt_button_new(_("Save & Use")); | |
604 gnt_box_add_widget(GNT_BOX(box), button); | |
605 g_object_set_data(G_OBJECT(button), "use", GINT_TO_POINTER(TRUE)); | |
606 g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(save_savedstatus_cb), edit); | |
607 | |
608 /* Cancel */ | |
609 button = gnt_button_new(_("Cancel")); | |
610 gnt_box_add_widget(GNT_BOX(box), button); | |
611 g_signal_connect_swapped(G_OBJECT(button), "activate", | |
612 G_CALLBACK(gnt_widget_destroy), window); | |
613 | |
614 g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(update_edit_list), edit); | |
615 | |
616 gnt_widget_show(window); | |
617 } | |
618 |