Mercurial > pidgin
annotate finch/gntstatus.c @ 19753:3a339abc94c5
fixes #2682
committer: Luke Schierer <lschiere@pidgin.im>
author | Javier Fernández-Sanguino Peña <jfs@computer.org> |
---|---|
date | Wed, 12 Sep 2007 01:26:42 +0000 |
parents | 44b4e8bd759b |
children | 6a0d9fa477d4 6bf32c9e15a7 |
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 | |
19681
44b4e8bd759b
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19374
diff
changeset
|
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
15817 | 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.")); |
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); |
15817 | 303 return; |
304 } | |
305 | |
15822 | 306 find = purple_savedstatus_find(title); |
15817 | 307 if (find && find != edit->saved) |
308 { | |
15822 | 309 purple_notify_error(edit, _("Error"), _("Duplicate title"), |
15817 | 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); |
15817 | 312 return; |
313 } | |
314 | |
315 if (edit->saved == NULL) | |
316 { | |
15822 | 317 edit->saved = purple_savedstatus_new(title, prim); |
318 purple_savedstatus_set_message(edit->saved, message); | |
15817 | 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, | |
15822 | 323 purple_primitive_get_name_from_type(prim), message), NULL); |
15817 | 324 } |
325 else | |
326 { | |
15822 | 327 purple_savedstatus_set_title(edit->saved, title); |
328 purple_savedstatus_set_type(edit->saved, prim); | |
329 purple_savedstatus_set_message(edit->saved, message); | |
15817 | 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, | |
15822 | 334 purple_primitive_get_name_from_type(prim)); |
15817 | 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")) | |
15822 | 340 purple_savedstatus_activate(edit->saved); |
15817 | 341 |
342 gnt_widget_destroy(edit->window); | |
343 } | |
344 | |
345 static void | |
15822 | 346 add_substatus(EditStatus *edit, PurpleAccount *account) |
15817 | 347 { |
348 char *name; | |
349 const char *type = NULL, *message = NULL; | |
15822 | 350 PurpleSavedStatusSub *sub = NULL; |
15817 | 351 RowInfo *key; |
352 | |
353 if (!edit || !edit->tree) | |
354 return; | |
355 | |
356 if (edit->saved) | |
15822 | 357 sub = purple_savedstatus_get_substatus(edit->saved, account); |
15817 | 358 |
359 key = g_new0(RowInfo, 1); | |
360 key->account = account; | |
361 | |
362 if (sub) | |
363 { | |
15822 | 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); | |
15817 | 367 key->message = g_strdup(message); |
368 } | |
369 | |
15822 | 370 name = g_strdup_printf("%s (%s)", purple_account_get_username(account), |
371 purple_account_get_protocol_name(account)); | |
15817 | 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 { | |
15822 | 391 PurpleSavedStatus *saved = sub->parent->saved; |
15817 | 392 RowInfo *row = sub->key; |
393 const char *message; | |
15822 | 394 PurpleStatusType *type; |
15817 | 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. */ | |
15822 | 403 purple_savedstatus_set_substatus(saved, row->account, type, message); |
15817 | 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, | |
15822 | 407 purple_status_type_get_name(type)); |
15817 | 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; | |
15822 | 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; |
15817 | 422 char *name; |
423 RowInfo *selected = gnt_tree_get_selection_data(tree); | |
15822 | 424 PurpleAccount *account = selected->account; |
15817 | 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? */ | |
15822 | 433 purple_savedstatus_unset_substatus(edit->saved, account); |
15817 | 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) | |
15822 | 443 substatus = purple_savedstatus_get_substatus(edit->saved, account); |
15817 | 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); |
15817 | 453 |
454 box = gnt_hbox_new(FALSE); | |
455 gnt_box_add_widget(GNT_BOX(box), gnt_label_new(_("Account:"))); | |
15822 | 456 name = g_strdup_printf("%s (%s)", purple_account_get_username(account), |
457 purple_account_get_protocol_name(account)); | |
15817 | 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 | |
15822 | 469 for (iter = purple_account_get_status_types(account); iter; iter = iter->next) |
15817 | 470 { |
15822 | 471 PurpleStatusType *type = iter->data; |
472 if (!purple_status_type_is_user_settable(type)) | |
15817 | 473 continue; |
15822 | 474 gnt_combo_box_add_data(GNT_COMBO_BOX(combo), type, purple_status_type_get_name(type)); |
15817 | 475 } |
476 | |
477 box = gnt_hbox_new(FALSE); | |
478 gnt_box_add_widget(GNT_BOX(box), gnt_label_new(_("Message:"))); | |
15822 | 479 sub->message = entry = gnt_entry_new(substatus ? purple_savedstatus_substatus_get_message(substatus) : NULL); |
15817 | 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 | |
15822 | 503 void finch_savedstatus_edit(PurpleSavedStatus *saved) |
15817 | 504 { |
505 EditStatus *edit; | |
506 GntWidget *window, *box, *button, *entry, *combo, *label, *tree; | |
15822 | 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; |
15817 | 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); |
15817 | 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 | |
15822 | 540 edit->title = entry = gnt_entry_new(saved ? purple_savedstatus_get_title(saved) : NULL); |
15817 | 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); | |
15822 | 551 current = saved ? purple_savedstatus_get_type(saved) : PURPLE_STATUS_UNSET; |
552 for (i = 0; prims[i] != PURPLE_STATUS_UNSET; i++) | |
15817 | 553 { |
554 gnt_combo_box_add_data(GNT_COMBO_BOX(combo), GINT_TO_POINTER(prims[i]), | |
15822 | 555 purple_primitive_get_name_from_type(prims[i])); |
15817 | 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 | |
15822 | 565 edit->message = entry = gnt_entry_new(saved ? purple_savedstatus_get_message(saved) : NULL); |
15817 | 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 | |
15822 | 580 for (iter = purple_accounts_get_all(); iter; iter = iter->next) |
15817 | 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 |