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