Mercurial > pidgin
annotate finch/gntpounce.c @ 21726:56f78bc6c53e
More catching up on things, from 8548e491a5b470d5665cb1cf87a7b0caaa3c87a5:
"Fix all our calls to fcntl(listenfd, F_SETFL, O_NONBLOCK);
fcntl() with F_SETFL overwrites the old flags with the new ones, so
you should call fcntl() with F_GETFL, then OR that value with
O_NONBLOCK before setting the flags. We've been doing this
wrong for a long time and it hasn't seemed to hurt anything,
but I thought it would be good to fix it."
author | Stu Tomlinson <stu@nosnilmot.com> |
---|---|
date | Sun, 02 Dec 2007 17:33:03 +0000 |
parents | 665e04562de0 |
children | 16ff37f64e29 60f5abc6cf0c |
rev | line source |
---|---|
15817 | 1 /** |
2 * @file gntpounce.c GNT Buddy Pounce 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 */ | |
27 #include <gnt.h> | |
28 #include <gntbox.h> | |
29 #include <gntbutton.h> | |
30 #include <gntcheckbox.h> | |
31 #include <gntcombobox.h> | |
32 #include <gntentry.h> | |
33 #include <gntlabel.h> | |
34 #include <gntline.h> | |
35 #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:
18345
diff
changeset
|
36 #include <gntutils.h> |
7ee0e0597a26
Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18345
diff
changeset
|
37 |
15817 | 38 #include "internal.h" |
15822 | 39 #include "finch.h" |
15817 | 40 |
41 #include "account.h" | |
42 #include "conversation.h" | |
43 #include "debug.h" | |
44 #include "notify.h" | |
45 #include "prpl.h" | |
46 #include "request.h" | |
47 #include "server.h" | |
48 #include "util.h" | |
49 | |
50 #include "gntpounce.h" | |
51 | |
52 | |
53 typedef struct | |
54 { | |
55 /* Pounce data */ | |
15822 | 56 PurplePounce *pounce; |
57 PurpleAccount *account; | |
15817 | 58 |
59 /* The window */ | |
60 GntWidget *window; | |
61 | |
62 /* Pounce on Whom */ | |
63 GntWidget *account_menu; | |
64 GntWidget *buddy_entry; | |
65 | |
66 /* Pounce options */ | |
67 GntWidget *on_away; | |
68 | |
69 /* Pounce When Buddy... */ | |
70 GntWidget *signon; | |
71 GntWidget *signoff; | |
72 GntWidget *away; | |
73 GntWidget *away_return; | |
74 GntWidget *idle; | |
75 GntWidget *idle_return; | |
76 GntWidget *typing; | |
77 GntWidget *typed; | |
78 GntWidget *stop_typing; | |
79 GntWidget *message_recv; | |
80 | |
81 /* Action */ | |
82 GntWidget *open_win; | |
83 GntWidget *popup; | |
84 GntWidget *popup_entry; | |
85 GntWidget *send_msg; | |
86 GntWidget *send_msg_entry; | |
87 GntWidget *exec_cmd; | |
88 GntWidget *exec_cmd_entry; | |
89 GntWidget *play_sound; | |
90 | |
91 GntWidget *save_pounce; | |
92 | |
93 /* Buttons */ | |
94 GntWidget *save_button; | |
95 | |
15822 | 96 } PurpleGntPounceDialog; |
15817 | 97 |
98 typedef struct | |
99 { | |
100 GntWidget *window; | |
101 GntWidget *tree; | |
102 GntWidget *modify_button; | |
103 GntWidget *delete_button; | |
104 } PouncesManager; | |
105 | |
106 static PouncesManager *pounces_manager = NULL; | |
107 | |
108 /************************************************************************** | |
109 * Callbacks | |
110 **************************************************************************/ | |
111 static gint | |
15822 | 112 delete_win_cb(GntWidget *w, PurpleGntPounceDialog *dialog) |
15817 | 113 { |
114 gnt_widget_destroy(dialog->window); | |
115 g_free(dialog); | |
116 | |
117 return TRUE; | |
118 } | |
119 | |
120 static void | |
15822 | 121 cancel_cb(GntWidget *w, PurpleGntPounceDialog *dialog) |
15817 | 122 { |
123 gnt_widget_destroy(dialog->window); | |
124 } | |
125 | |
126 static void | |
15822 | 127 add_pounce_to_treeview(GntTree *tree, PurplePounce *pounce) |
15817 | 128 { |
15822 | 129 PurpleAccount *account; |
15817 | 130 const char *pouncer; |
131 const char *pouncee; | |
132 | |
15822 | 133 account = purple_pounce_get_pouncer(pounce); |
134 pouncer = purple_account_get_username(account); | |
135 pouncee = purple_pounce_get_pouncee(pounce); | |
15817 | 136 gnt_tree_add_row_last(tree, pounce, |
137 gnt_tree_create_row(tree, pouncer, pouncee), NULL); | |
138 } | |
139 | |
140 static void | |
141 populate_pounces_list(PouncesManager *dialog) | |
142 { | |
18118
ab6d2763b8d8
Re-fix the DBus list handling code by killing const GList* / const GSList*
Richard Laager <rlaager@wiktel.com>
parents:
18063
diff
changeset
|
143 GList *pounces; |
15817 | 144 |
145 gnt_tree_remove_all(GNT_TREE(dialog->tree)); | |
146 | |
18137
323272a9bb65
Fix #1574. (Pidgin and Finch show each other's pounces, interact in
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18118
diff
changeset
|
147 for (pounces = purple_pounces_get_all_for_ui(FINCH_UI); pounces != NULL; |
323272a9bb65
Fix #1574. (Pidgin and Finch show each other's pounces, interact in
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18118
diff
changeset
|
148 pounces = g_list_delete_link(pounces, pounces)) |
15817 | 149 { |
150 add_pounce_to_treeview(GNT_TREE(dialog->tree), pounces->data); | |
151 } | |
152 } | |
153 | |
154 static void | |
155 update_pounces(void) | |
156 { | |
157 /* Rebuild the pounces list if the pounces manager is open */ | |
158 if (pounces_manager != NULL) | |
159 { | |
160 populate_pounces_list(pounces_manager); | |
161 } | |
162 } | |
163 | |
164 static void | |
15822 | 165 signed_on_off_cb(PurpleConnection *gc, gpointer user_data) |
15817 | 166 { |
167 update_pounces(); | |
168 } | |
169 | |
170 static void | |
21279
47118f6062e9
Enable auto-complete in the pounce dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21244
diff
changeset
|
171 setup_buddy_list_suggestion(GntEntry *entry, gboolean offline) |
47118f6062e9
Enable auto-complete in the pounce dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21244
diff
changeset
|
172 { |
47118f6062e9
Enable auto-complete in the pounce dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21244
diff
changeset
|
173 PurpleBlistNode *node = purple_blist_get_root(); |
47118f6062e9
Enable auto-complete in the pounce dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21244
diff
changeset
|
174 for (; node; node = purple_blist_node_next(node, offline)) { |
47118f6062e9
Enable auto-complete in the pounce dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21244
diff
changeset
|
175 if (!PURPLE_BLIST_NODE_IS_BUDDY(node)) |
47118f6062e9
Enable auto-complete in the pounce dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21244
diff
changeset
|
176 continue; |
47118f6062e9
Enable auto-complete in the pounce dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21244
diff
changeset
|
177 gnt_entry_add_suggest(entry, purple_buddy_get_name((PurpleBuddy*)node)); |
47118f6062e9
Enable auto-complete in the pounce dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21244
diff
changeset
|
178 } |
47118f6062e9
Enable auto-complete in the pounce dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21244
diff
changeset
|
179 } |
47118f6062e9
Enable auto-complete in the pounce dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21244
diff
changeset
|
180 |
47118f6062e9
Enable auto-complete in the pounce dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21244
diff
changeset
|
181 static void |
15822 | 182 save_pounce_cb(GntWidget *w, PurpleGntPounceDialog *dialog) |
15817 | 183 { |
184 const char *name; | |
185 const char *message, *command, *reason; | |
15822 | 186 PurplePounceEvent events = PURPLE_POUNCE_NONE; |
187 PurplePounceOption options = PURPLE_POUNCE_OPTION_NONE; | |
15817 | 188 |
189 name = gnt_entry_get_text(GNT_ENTRY(dialog->buddy_entry)); | |
190 | |
191 if (*name == '\0') | |
192 { | |
15822 | 193 purple_notify_error(NULL, NULL, |
15817 | 194 _("Please enter a buddy to pounce."), NULL); |
195 return; | |
196 } | |
197 | |
198 /* Options */ | |
199 if (gnt_check_box_get_checked(GNT_CHECK_BOX(dialog->on_away))) | |
15822 | 200 options |= PURPLE_POUNCE_OPTION_AWAY; |
15817 | 201 |
202 /* Events */ | |
203 if (gnt_check_box_get_checked(GNT_CHECK_BOX(dialog->signon))) | |
15822 | 204 events |= PURPLE_POUNCE_SIGNON; |
15817 | 205 |
206 if (gnt_check_box_get_checked(GNT_CHECK_BOX(dialog->signoff))) | |
15822 | 207 events |= PURPLE_POUNCE_SIGNOFF; |
15817 | 208 |
209 if (gnt_check_box_get_checked(GNT_CHECK_BOX(dialog->away))) | |
15822 | 210 events |= PURPLE_POUNCE_AWAY; |
15817 | 211 |
212 if (gnt_check_box_get_checked(GNT_CHECK_BOX(dialog->away_return))) | |
15822 | 213 events |= PURPLE_POUNCE_AWAY_RETURN; |
15817 | 214 |
215 if (gnt_check_box_get_checked(GNT_CHECK_BOX(dialog->idle))) | |
15822 | 216 events |= PURPLE_POUNCE_IDLE; |
15817 | 217 |
218 if (gnt_check_box_get_checked(GNT_CHECK_BOX(dialog->idle_return))) | |
15822 | 219 events |= PURPLE_POUNCE_IDLE_RETURN; |
15817 | 220 |
221 if (gnt_check_box_get_checked(GNT_CHECK_BOX(dialog->typing))) | |
15822 | 222 events |= PURPLE_POUNCE_TYPING; |
15817 | 223 |
224 if (gnt_check_box_get_checked(GNT_CHECK_BOX(dialog->typed))) | |
15822 | 225 events |= PURPLE_POUNCE_TYPED; |
15817 | 226 |
227 if (gnt_check_box_get_checked(GNT_CHECK_BOX(dialog->stop_typing))) | |
15822 | 228 events |= PURPLE_POUNCE_TYPING_STOPPED; |
15817 | 229 |
230 if (gnt_check_box_get_checked(GNT_CHECK_BOX(dialog->message_recv))) | |
15822 | 231 events |= PURPLE_POUNCE_MESSAGE_RECEIVED; |
15817 | 232 |
233 /* Data fields */ | |
234 message = gnt_entry_get_text(GNT_ENTRY(dialog->send_msg_entry)); | |
235 command = gnt_entry_get_text(GNT_ENTRY(dialog->exec_cmd_entry)); | |
236 reason = gnt_entry_get_text(GNT_ENTRY(dialog->popup_entry)); | |
237 | |
238 if (*reason == '\0') reason = NULL; | |
239 if (*message == '\0') message = NULL; | |
240 if (*command == '\0') command = NULL; | |
241 | |
242 if (dialog->pounce == NULL) { | |
15822 | 243 dialog->pounce = purple_pounce_new(FINCH_UI, dialog->account, |
15817 | 244 name, events, options); |
245 } else { | |
15822 | 246 purple_pounce_set_events(dialog->pounce, events); |
247 purple_pounce_set_options(dialog->pounce, options); | |
248 purple_pounce_set_pouncer(dialog->pounce, dialog->account); | |
249 purple_pounce_set_pouncee(dialog->pounce, name); | |
15817 | 250 } |
251 | |
252 /* Actions */ | |
15822 | 253 purple_pounce_action_set_enabled(dialog->pounce, "open-window", |
15817 | 254 gnt_check_box_get_checked(GNT_CHECK_BOX(dialog->open_win))); |
15822 | 255 purple_pounce_action_set_enabled(dialog->pounce, "popup-notify", |
15817 | 256 gnt_check_box_get_checked(GNT_CHECK_BOX(dialog->popup))); |
15822 | 257 purple_pounce_action_set_enabled(dialog->pounce, "send-message", |
15817 | 258 gnt_check_box_get_checked(GNT_CHECK_BOX(dialog->send_msg))); |
15822 | 259 purple_pounce_action_set_enabled(dialog->pounce, "execute-command", |
15817 | 260 gnt_check_box_get_checked(GNT_CHECK_BOX(dialog->exec_cmd))); |
15822 | 261 purple_pounce_action_set_enabled(dialog->pounce, "play-beep", |
15817 | 262 gnt_check_box_get_checked(GNT_CHECK_BOX(dialog->play_sound))); |
263 | |
15822 | 264 purple_pounce_action_set_attribute(dialog->pounce, "send-message", |
15817 | 265 "message", message); |
15822 | 266 purple_pounce_action_set_attribute(dialog->pounce, "execute-command", |
15817 | 267 "command", command); |
15822 | 268 purple_pounce_action_set_attribute(dialog->pounce, "popup-notify", |
15817 | 269 "reason", reason); |
270 | |
271 /* Set the defaults for next time. */ | |
16424
4999bbc52881
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents:
16287
diff
changeset
|
272 purple_prefs_set_bool("/finch/pounces/default_actions/open-window", |
15817 | 273 gnt_check_box_get_checked(GNT_CHECK_BOX(dialog->open_win))); |
16424
4999bbc52881
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents:
16287
diff
changeset
|
274 purple_prefs_set_bool("/finch/pounces/default_actions/popup-notify", |
15817 | 275 gnt_check_box_get_checked(GNT_CHECK_BOX(dialog->popup))); |
16424
4999bbc52881
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents:
16287
diff
changeset
|
276 purple_prefs_set_bool("/finch/pounces/default_actions/send-message", |
15817 | 277 gnt_check_box_get_checked(GNT_CHECK_BOX(dialog->send_msg))); |
16424
4999bbc52881
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents:
16287
diff
changeset
|
278 purple_prefs_set_bool("/finch/pounces/default_actions/execute-command", |
15817 | 279 gnt_check_box_get_checked(GNT_CHECK_BOX(dialog->exec_cmd))); |
16424
4999bbc52881
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents:
16287
diff
changeset
|
280 purple_prefs_set_bool("/finch/pounces/default_actions/play-beep", |
15817 | 281 gnt_check_box_get_checked(GNT_CHECK_BOX(dialog->play_sound))); |
282 | |
15822 | 283 purple_pounce_set_save(dialog->pounce, |
15817 | 284 gnt_check_box_get_checked(GNT_CHECK_BOX(dialog->save_pounce))); |
285 | |
15822 | 286 purple_pounce_set_pouncer(dialog->pounce, |
287 (PurpleAccount *)gnt_combo_box_get_selected_data(GNT_COMBO_BOX(dialog->account_menu))); | |
15817 | 288 |
289 update_pounces(); | |
290 | |
291 gnt_widget_destroy(dialog->window); | |
292 } | |
293 | |
294 | |
295 void | |
15822 | 296 finch_pounce_editor_show(PurpleAccount *account, const char *name, |
297 PurplePounce *cur_pounce) | |
15817 | 298 { |
15822 | 299 PurpleGntPounceDialog *dialog; |
15817 | 300 GntWidget *window; |
301 GntWidget *bbox; | |
16287
776bf7979b4f
Line up the event-checkboxes in the pounce dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
302 GntWidget *hbox, *vbox; |
15817 | 303 GntWidget *button; |
304 GntWidget *combo; | |
18063
926ccb104da0
disapproval of revision '1411afd7660760db59966c3a9f18e2adab8eb27e'
Richard Laager <rlaager@wiktel.com>
parents:
18058
diff
changeset
|
305 GList *list; |
15817 | 306 |
307 g_return_if_fail((cur_pounce != NULL) || | |
308 (account != NULL) || | |
15822 | 309 (purple_accounts_get_all() != NULL)); |
15817 | 310 |
15822 | 311 dialog = g_new0(PurpleGntPounceDialog, 1); |
15817 | 312 |
313 if (cur_pounce != NULL) { | |
314 dialog->pounce = cur_pounce; | |
15822 | 315 dialog->account = purple_pounce_get_pouncer(cur_pounce); |
15817 | 316 } else if (account != NULL) { |
317 dialog->pounce = NULL; | |
318 dialog->account = account; | |
319 } else { | |
18063
926ccb104da0
disapproval of revision '1411afd7660760db59966c3a9f18e2adab8eb27e'
Richard Laager <rlaager@wiktel.com>
parents:
18058
diff
changeset
|
320 GList *connections = purple_connections_get_all(); |
15822 | 321 PurpleConnection *gc; |
15817 | 322 |
323 if (connections != NULL) { | |
15822 | 324 gc = (PurpleConnection *)connections->data; |
325 dialog->account = purple_connection_get_account(gc); | |
15817 | 326 } else |
15822 | 327 dialog->account = purple_accounts_get_all()->data; |
15817 | 328 |
329 dialog->pounce = NULL; | |
330 } | |
331 | |
332 /* Create the window. */ | |
333 dialog->window = window = gnt_vbox_new(FALSE); | |
334 gnt_box_set_pad(GNT_BOX(window), 0); | |
335 gnt_box_set_toplevel(GNT_BOX(window), TRUE); | |
336 gnt_box_set_alignment(GNT_BOX(window), GNT_ALIGN_LEFT); | |
337 gnt_box_set_title(GNT_BOX(window), | |
338 (cur_pounce == NULL | |
339 ? _("New Buddy Pounce") : _("Edit Buddy Pounce"))); | |
340 | |
341 g_signal_connect(G_OBJECT(window), "destroy", | |
342 G_CALLBACK(delete_win_cb), dialog); | |
343 | |
344 gnt_box_add_widget(GNT_BOX(window), gnt_label_new_with_format(_("Pounce Who"), GNT_TEXT_FLAG_BOLD)); | |
345 | |
346 /* Account: */ | |
347 gnt_box_add_widget(GNT_BOX(window), gnt_label_new(_("Account:"))); | |
348 dialog->account_menu = combo = gnt_combo_box_new(); | |
15822 | 349 list = purple_accounts_get_all(); |
15817 | 350 for (; list; list = list->next) |
351 { | |
15822 | 352 PurpleAccount *account; |
15817 | 353 char *text; |
354 | |
355 account = list->data; | |
356 text = g_strdup_printf("%s (%s)", | |
15822 | 357 purple_account_get_username(account), |
358 purple_account_get_protocol_name(account)); | |
15817 | 359 gnt_combo_box_add_data(GNT_COMBO_BOX(combo), account, text); |
360 g_free(text); | |
361 } | |
362 if (dialog->account) | |
363 gnt_combo_box_set_selected(GNT_COMBO_BOX(combo), dialog->account); | |
364 | |
365 gnt_box_add_widget(GNT_BOX(window), combo); | |
366 | |
367 /* Buddy: */ | |
368 hbox = gnt_hbox_new(FALSE); | |
369 gnt_box_add_widget(GNT_BOX(hbox), gnt_label_new(_("Buddy name:"))); | |
370 | |
371 dialog->buddy_entry = gnt_entry_new(NULL); | |
372 gnt_box_add_widget(GNT_BOX(hbox), dialog->buddy_entry); | |
373 | |
21279
47118f6062e9
Enable auto-complete in the pounce dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21244
diff
changeset
|
374 setup_buddy_list_suggestion(GNT_ENTRY(dialog->buddy_entry), TRUE); |
47118f6062e9
Enable auto-complete in the pounce dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21244
diff
changeset
|
375 |
15817 | 376 gnt_box_add_widget(GNT_BOX(window), hbox); |
377 | |
378 if (cur_pounce != NULL) { | |
379 gnt_entry_set_text(GNT_ENTRY(dialog->buddy_entry), | |
15822 | 380 purple_pounce_get_pouncee(cur_pounce)); |
15817 | 381 } else if (name != NULL) { |
382 gnt_entry_set_text(GNT_ENTRY(dialog->buddy_entry), name); | |
383 } | |
384 | |
16287
776bf7979b4f
Line up the event-checkboxes in the pounce dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
385 /* Create the event frame */ |
15817 | 386 gnt_box_add_widget(GNT_BOX(window), gnt_line_new(FALSE)); |
387 gnt_box_add_widget(GNT_BOX(window), gnt_label_new_with_format(_("Pounce When Buddy..."), GNT_TEXT_FLAG_BOLD)); | |
388 | |
389 dialog->signon = gnt_check_box_new(_("Signs on")); | |
390 dialog->signoff = gnt_check_box_new(_("Signs off")); | |
391 dialog->away = gnt_check_box_new(_("Goes away")); | |
392 dialog->away_return = gnt_check_box_new(_("Returns from away")); | |
393 dialog->idle = gnt_check_box_new(_("Becomes idle")); | |
394 dialog->idle_return = gnt_check_box_new(_("Is no longer idle")); | |
395 dialog->typing = gnt_check_box_new(_("Starts typing")); | |
396 dialog->typed = gnt_check_box_new(_("Pauses while typing")); | |
397 dialog->stop_typing = gnt_check_box_new(_("Stops typing")); | |
398 dialog->message_recv = gnt_check_box_new(_("Sends a message")); | |
399 | |
16287
776bf7979b4f
Line up the event-checkboxes in the pounce dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
400 hbox = gnt_hbox_new(TRUE); |
15817 | 401 gnt_box_set_pad(GNT_BOX(hbox), 2); |
16287
776bf7979b4f
Line up the event-checkboxes in the pounce dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
402 |
776bf7979b4f
Line up the event-checkboxes in the pounce dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
403 vbox = gnt_vbox_new(FALSE); |
776bf7979b4f
Line up the event-checkboxes in the pounce dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
404 gnt_box_set_pad(GNT_BOX(vbox), 0); |
776bf7979b4f
Line up the event-checkboxes in the pounce dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
405 gnt_box_add_widget(GNT_BOX(hbox), vbox); |
776bf7979b4f
Line up the event-checkboxes in the pounce dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
406 |
776bf7979b4f
Line up the event-checkboxes in the pounce dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
407 gnt_box_add_widget(GNT_BOX(vbox), dialog->signon); |
776bf7979b4f
Line up the event-checkboxes in the pounce dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
408 gnt_box_add_widget(GNT_BOX(vbox), dialog->away); |
776bf7979b4f
Line up the event-checkboxes in the pounce dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
409 gnt_box_add_widget(GNT_BOX(vbox), dialog->idle); |
776bf7979b4f
Line up the event-checkboxes in the pounce dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
410 gnt_box_add_widget(GNT_BOX(vbox), dialog->typing); |
776bf7979b4f
Line up the event-checkboxes in the pounce dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
411 gnt_box_add_widget(GNT_BOX(vbox), dialog->stop_typing); |
776bf7979b4f
Line up the event-checkboxes in the pounce dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
412 |
776bf7979b4f
Line up the event-checkboxes in the pounce dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
413 vbox = gnt_vbox_new(FALSE); |
776bf7979b4f
Line up the event-checkboxes in the pounce dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
414 gnt_box_set_pad(GNT_BOX(vbox), 0); |
776bf7979b4f
Line up the event-checkboxes in the pounce dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
415 gnt_box_add_widget(GNT_BOX(hbox), vbox); |
776bf7979b4f
Line up the event-checkboxes in the pounce dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
416 |
776bf7979b4f
Line up the event-checkboxes in the pounce dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
417 gnt_box_add_widget(GNT_BOX(vbox), dialog->signoff); |
776bf7979b4f
Line up the event-checkboxes in the pounce dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
418 gnt_box_add_widget(GNT_BOX(vbox), dialog->away_return); |
776bf7979b4f
Line up the event-checkboxes in the pounce dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
419 gnt_box_add_widget(GNT_BOX(vbox), dialog->idle_return); |
776bf7979b4f
Line up the event-checkboxes in the pounce dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
420 gnt_box_add_widget(GNT_BOX(vbox), dialog->typed); |
776bf7979b4f
Line up the event-checkboxes in the pounce dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
421 gnt_box_add_widget(GNT_BOX(vbox), dialog->message_recv); |
776bf7979b4f
Line up the event-checkboxes in the pounce dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
422 |
15817 | 423 gnt_box_add_widget(GNT_BOX(window), hbox); |
424 | |
425 /* Create the "Action" frame. */ | |
426 gnt_box_add_widget(GNT_BOX(window), gnt_line_new(FALSE)); | |
427 gnt_box_add_widget(GNT_BOX(window), gnt_label_new_with_format(_("Action"), GNT_TEXT_FLAG_BOLD)); | |
428 | |
429 dialog->open_win = gnt_check_box_new(_("Open an IM window")); | |
430 dialog->popup = gnt_check_box_new(_("Pop up a notification")); | |
431 dialog->send_msg = gnt_check_box_new(_("Send a message")); | |
432 dialog->exec_cmd = gnt_check_box_new(_("Execute a command")); | |
433 dialog->play_sound = gnt_check_box_new(_("Play a sound")); | |
434 | |
435 dialog->send_msg_entry = gnt_entry_new(NULL); | |
436 dialog->exec_cmd_entry = gnt_entry_new(NULL); | |
437 dialog->popup_entry = gnt_entry_new(NULL); | |
438 dialog->exec_cmd_entry = gnt_entry_new(NULL); | |
439 | |
440 hbox = gnt_hbox_new(FALSE); | |
441 gnt_box_add_widget(GNT_BOX(hbox), dialog->open_win); | |
442 gnt_box_add_widget(GNT_BOX(window), hbox); | |
443 hbox = gnt_hbox_new(FALSE); | |
444 gnt_box_add_widget(GNT_BOX(hbox), dialog->popup); | |
445 gnt_box_add_widget(GNT_BOX(hbox), dialog->popup_entry); | |
446 gnt_box_add_widget(GNT_BOX(window), hbox); | |
447 hbox = gnt_hbox_new(FALSE); | |
448 gnt_box_add_widget(GNT_BOX(hbox), dialog->send_msg); | |
449 gnt_box_add_widget(GNT_BOX(hbox), dialog->send_msg_entry); | |
450 gnt_box_add_widget(GNT_BOX(window), hbox); | |
451 hbox = gnt_hbox_new(FALSE); | |
452 gnt_box_add_widget(GNT_BOX(hbox), dialog->exec_cmd); | |
453 gnt_box_add_widget(GNT_BOX(hbox), dialog->exec_cmd_entry); | |
454 gnt_box_add_widget(GNT_BOX(window), hbox); | |
455 hbox = gnt_hbox_new(FALSE); | |
456 gnt_box_add_widget(GNT_BOX(hbox), dialog->play_sound); | |
457 gnt_box_add_widget(GNT_BOX(window), hbox); | |
458 | |
459 gnt_box_add_widget(GNT_BOX(window), gnt_line_new(FALSE)); | |
460 gnt_box_add_widget(GNT_BOX(window), gnt_label_new_with_format(_("Options"), GNT_TEXT_FLAG_BOLD)); | |
461 dialog->on_away = gnt_check_box_new(_("Pounce only when my status is not available")); | |
462 gnt_box_add_widget(GNT_BOX(window), dialog->on_away); | |
463 dialog->save_pounce = gnt_check_box_new(_("Recurring")); | |
464 gnt_box_add_widget(GNT_BOX(window), dialog->save_pounce); | |
465 | |
466 | |
467 gnt_box_add_widget(GNT_BOX(window), gnt_line_new(FALSE)); | |
468 /* Now the button box! */ | |
19374
d65ce3df5be2
Make some of the dialogs look and behave more like each other.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18511
diff
changeset
|
469 bbox = gnt_hbox_new(FALSE); |
15817 | 470 |
471 /* Cancel button */ | |
472 button = gnt_button_new(_("Cancel")); | |
473 gnt_box_add_widget(GNT_BOX(bbox), button); | |
474 g_signal_connect(G_OBJECT(button), "activate", | |
475 G_CALLBACK(cancel_cb), dialog); | |
476 | |
477 /* Save button */ | |
478 dialog->save_button = button = gnt_button_new(_("Save")); | |
479 gnt_box_add_widget(GNT_BOX(bbox), button); | |
480 g_signal_connect(G_OBJECT(button), "activate", | |
481 G_CALLBACK(save_pounce_cb), dialog); | |
482 | |
483 gnt_box_add_widget(GNT_BOX(window), bbox); | |
484 | |
485 | |
486 /* Set the values of stuff. */ | |
487 if (cur_pounce != NULL) | |
488 { | |
15822 | 489 PurplePounceEvent events = purple_pounce_get_events(cur_pounce); |
490 PurplePounceOption options = purple_pounce_get_options(cur_pounce); | |
15817 | 491 const char *value; |
492 | |
493 /* Options */ | |
494 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->on_away), | |
15822 | 495 (options & PURPLE_POUNCE_OPTION_AWAY)); |
15817 | 496 |
497 /* Events */ | |
498 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->signon), | |
15822 | 499 (events & PURPLE_POUNCE_SIGNON)); |
15817 | 500 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->signoff), |
15822 | 501 (events & PURPLE_POUNCE_SIGNOFF)); |
15817 | 502 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->away), |
15822 | 503 (events & PURPLE_POUNCE_AWAY)); |
15817 | 504 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->away_return), |
15822 | 505 (events & PURPLE_POUNCE_AWAY_RETURN)); |
15817 | 506 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->idle), |
15822 | 507 (events & PURPLE_POUNCE_IDLE)); |
15817 | 508 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->idle_return), |
15822 | 509 (events & PURPLE_POUNCE_IDLE_RETURN)); |
15817 | 510 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->typing), |
15822 | 511 (events & PURPLE_POUNCE_TYPING)); |
15817 | 512 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->typed), |
15822 | 513 (events & PURPLE_POUNCE_TYPED)); |
15817 | 514 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->stop_typing), |
15822 | 515 (events & PURPLE_POUNCE_TYPING_STOPPED)); |
15817 | 516 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->message_recv), |
15822 | 517 (events & PURPLE_POUNCE_MESSAGE_RECEIVED)); |
15817 | 518 |
519 /* Actions */ | |
520 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->open_win), | |
15822 | 521 purple_pounce_action_is_enabled(cur_pounce, "open-window")); |
15817 | 522 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->popup), |
15822 | 523 purple_pounce_action_is_enabled(cur_pounce, "popup-notify")); |
15817 | 524 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->send_msg), |
15822 | 525 purple_pounce_action_is_enabled(cur_pounce, "send-message")); |
15817 | 526 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->exec_cmd), |
15822 | 527 purple_pounce_action_is_enabled(cur_pounce, "execute-command")); |
15817 | 528 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->play_sound), |
15822 | 529 purple_pounce_action_is_enabled(cur_pounce, "play-beep")); |
15817 | 530 |
531 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->save_pounce), | |
15822 | 532 purple_pounce_get_save(cur_pounce)); |
15817 | 533 |
15822 | 534 if ((value = purple_pounce_action_get_attribute(cur_pounce, |
15817 | 535 "send-message", |
536 "message")) != NULL) | |
537 { | |
538 gnt_entry_set_text(GNT_ENTRY(dialog->send_msg_entry), value); | |
539 } | |
540 | |
15822 | 541 if ((value = purple_pounce_action_get_attribute(cur_pounce, |
15817 | 542 "popup-notify", |
543 "reason")) != NULL) | |
544 { | |
545 gnt_entry_set_text(GNT_ENTRY(dialog->popup_entry), value); | |
546 } | |
547 | |
15822 | 548 if ((value = purple_pounce_action_get_attribute(cur_pounce, |
15817 | 549 "execute-command", |
550 "command")) != NULL) | |
551 { | |
552 gnt_entry_set_text(GNT_ENTRY(dialog->exec_cmd_entry), value); | |
553 } | |
554 } | |
555 else | |
556 { | |
15822 | 557 PurpleBuddy *buddy = NULL; |
15817 | 558 |
559 if (name != NULL) | |
15822 | 560 buddy = purple_find_buddy(account, name); |
15817 | 561 |
562 /* Set some defaults */ | |
563 if (buddy == NULL) { | |
564 gnt_check_box_set_checked( | |
565 GNT_CHECK_BOX(dialog->signon), TRUE); | |
566 } else { | |
15822 | 567 if (!PURPLE_BUDDY_IS_ONLINE(buddy)) { |
15817 | 568 gnt_check_box_set_checked( |
569 GNT_CHECK_BOX(dialog->signon), TRUE); | |
570 } else { | |
571 gboolean default_set = FALSE; | |
15822 | 572 PurplePresence *presence = purple_buddy_get_presence(buddy); |
15817 | 573 |
15822 | 574 if (purple_presence_is_idle(presence)) |
15817 | 575 { |
576 gnt_check_box_set_checked( | |
577 GNT_CHECK_BOX(dialog->idle_return), TRUE); | |
578 | |
579 default_set = TRUE; | |
580 } | |
581 | |
15822 | 582 if (!purple_presence_is_available(presence)) |
15817 | 583 { |
584 gnt_check_box_set_checked( | |
585 GNT_CHECK_BOX(dialog->away_return), TRUE); | |
586 | |
587 default_set = TRUE; | |
588 } | |
589 | |
590 if (!default_set) | |
591 { | |
592 gnt_check_box_set_checked( | |
593 GNT_CHECK_BOX(dialog->signon), TRUE); | |
594 } | |
595 } | |
596 } | |
597 | |
598 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->open_win), | |
16424
4999bbc52881
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents:
16287
diff
changeset
|
599 purple_prefs_get_bool("/finch/pounces/default_actions/open-window")); |
15817 | 600 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->popup), |
16424
4999bbc52881
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents:
16287
diff
changeset
|
601 purple_prefs_get_bool("/finch/pounces/default_actions/popup-notify")); |
15817 | 602 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->send_msg), |
16424
4999bbc52881
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents:
16287
diff
changeset
|
603 purple_prefs_get_bool("/finch/pounces/default_actions/send-message")); |
15817 | 604 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->exec_cmd), |
16424
4999bbc52881
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents:
16287
diff
changeset
|
605 purple_prefs_get_bool("/finch/pounces/default_actions/execute-command")); |
15817 | 606 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->play_sound), |
16424
4999bbc52881
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents:
16287
diff
changeset
|
607 purple_prefs_get_bool("/finch/pounces/default_actions/play-beep")); |
15817 | 608 } |
609 | |
610 gnt_widget_show(window); | |
611 } | |
612 | |
613 | |
614 | |
615 static gboolean | |
616 pounces_manager_destroy_cb(GntWidget *widget, gpointer user_data) | |
617 { | |
618 PouncesManager *dialog = user_data; | |
619 | |
620 dialog->window = NULL; | |
621 finch_pounces_manager_hide(); | |
622 | |
623 return FALSE; | |
624 } | |
625 | |
626 | |
627 static void | |
628 pounces_manager_add_cb(GntButton *button, gpointer user_data) | |
629 { | |
19374
d65ce3df5be2
Make some of the dialogs look and behave more like each other.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18511
diff
changeset
|
630 if (purple_accounts_get_all() == NULL) { |
d65ce3df5be2
Make some of the dialogs look and behave more like each other.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18511
diff
changeset
|
631 purple_notify_error(NULL, _("Cannot create pounce"), |
d65ce3df5be2
Make some of the dialogs look and behave more like each other.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18511
diff
changeset
|
632 _("You do not have any accounts."), |
d65ce3df5be2
Make some of the dialogs look and behave more like each other.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18511
diff
changeset
|
633 _("You must create an account first before you can create a pounce.")); |
d65ce3df5be2
Make some of the dialogs look and behave more like each other.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18511
diff
changeset
|
634 return; |
d65ce3df5be2
Make some of the dialogs look and behave more like each other.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18511
diff
changeset
|
635 } |
15817 | 636 finch_pounce_editor_show(NULL, NULL, NULL); |
637 } | |
638 | |
639 | |
640 static void | |
641 pounces_manager_modify_cb(GntButton *button, gpointer user_data) | |
642 { | |
643 PouncesManager *dialog = user_data; | |
15822 | 644 PurplePounce *pounce = gnt_tree_get_selection_data(GNT_TREE(dialog->tree)); |
19374
d65ce3df5be2
Make some of the dialogs look and behave more like each other.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18511
diff
changeset
|
645 if (pounce) |
d65ce3df5be2
Make some of the dialogs look and behave more like each other.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18511
diff
changeset
|
646 finch_pounce_editor_show(NULL, NULL, pounce); |
15817 | 647 } |
648 | |
649 static void | |
15822 | 650 pounces_manager_delete_confirm_cb(PurplePounce *pounce) |
15817 | 651 { |
652 gnt_tree_remove(GNT_TREE(pounces_manager->tree), pounce); | |
653 | |
15822 | 654 purple_request_close_with_handle(pounce); |
655 purple_pounce_destroy(pounce); | |
15817 | 656 } |
657 | |
658 | |
659 static void | |
660 pounces_manager_delete_cb(GntButton *button, gpointer user_data) | |
661 { | |
662 PouncesManager *dialog = user_data; | |
15822 | 663 PurplePounce *pounce; |
664 PurpleAccount *account; | |
15817 | 665 const char *pouncer, *pouncee; |
666 char *buf; | |
667 | |
15822 | 668 pounce = (PurplePounce *)gnt_tree_get_selection_data(GNT_TREE(dialog->tree)); |
19374
d65ce3df5be2
Make some of the dialogs look and behave more like each other.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18511
diff
changeset
|
669 if (pounce == NULL) |
d65ce3df5be2
Make some of the dialogs look and behave more like each other.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18511
diff
changeset
|
670 return; |
d65ce3df5be2
Make some of the dialogs look and behave more like each other.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18511
diff
changeset
|
671 |
15822 | 672 account = purple_pounce_get_pouncer(pounce); |
673 pouncer = purple_account_get_username(account); | |
674 pouncee = purple_pounce_get_pouncee(pounce); | |
15817 | 675 buf = g_strdup_printf(_("Are you sure you want to delete the pounce on %s for %s?"), pouncee, pouncer); |
21099
51cf02dbdb0e
disapproval of revision 'c484d979c4fda4433a9633ff8b69bd8a395c9479'
Richard Laager <rlaager@wiktel.com>
parents:
21095
diff
changeset
|
676 purple_request_action(pounce, NULL, buf, NULL, 0, |
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:
16424
diff
changeset
|
677 account, pouncee, NULL, |
21099
51cf02dbdb0e
disapproval of revision 'c484d979c4fda4433a9633ff8b69bd8a395c9479'
Richard Laager <rlaager@wiktel.com>
parents:
21095
diff
changeset
|
678 pounce, 2, |
15817 | 679 _("Delete"), pounces_manager_delete_confirm_cb, |
680 _("Cancel"), NULL); | |
681 g_free(buf); | |
682 } | |
683 | |
684 static void | |
685 pounces_manager_close_cb(GntButton *button, gpointer user_data) | |
686 { | |
687 finch_pounces_manager_hide(); | |
688 } | |
689 | |
690 | |
691 void | |
692 finch_pounces_manager_show(void) | |
693 { | |
694 PouncesManager *dialog; | |
695 GntWidget *bbox; | |
696 GntWidget *button; | |
697 GntWidget *tree; | |
698 GntWidget *win; | |
699 | |
700 if (pounces_manager != NULL) { | |
18345
2d4df5ef0090
If the action-windows are already there, then bring them to front when
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18137
diff
changeset
|
701 gnt_window_present(pounces_manager->window); |
15817 | 702 return; |
703 } | |
704 | |
705 pounces_manager = dialog = g_new0(PouncesManager, 1); | |
706 | |
707 dialog->window = win = gnt_vbox_new(FALSE); | |
708 gnt_box_set_toplevel(GNT_BOX(win), TRUE); | |
709 gnt_box_set_title(GNT_BOX(win), _("Buddy Pounces")); | |
710 gnt_box_set_pad(GNT_BOX(win), 0); | |
711 | |
712 g_signal_connect(G_OBJECT(win), "destroy", | |
713 G_CALLBACK(pounces_manager_destroy_cb), dialog); | |
714 | |
715 /* List of saved buddy pounces */ | |
716 dialog->tree = tree = GNT_WIDGET(gnt_tree_new_with_columns(2)); | |
717 gnt_tree_set_column_titles(GNT_TREE(tree), "Account", "Pouncee", NULL); | |
718 gnt_tree_set_show_title(GNT_TREE(tree), TRUE); | |
719 | |
720 gnt_box_add_widget(GNT_BOX(win), tree); | |
721 | |
722 /* Button box. */ | |
19374
d65ce3df5be2
Make some of the dialogs look and behave more like each other.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18511
diff
changeset
|
723 bbox = gnt_hbox_new(FALSE); |
15817 | 724 |
725 /* Add button */ | |
726 button = gnt_button_new(_("Add")); | |
727 gnt_box_add_widget(GNT_BOX(bbox), button); | |
18511
7ee0e0597a26
Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18345
diff
changeset
|
728 gnt_util_set_trigger_widget(tree, GNT_KEY_INS, button); |
15817 | 729 |
730 g_signal_connect(G_OBJECT(button), "activate", | |
731 G_CALLBACK(pounces_manager_add_cb), dialog); | |
732 | |
733 /* Modify button */ | |
734 button = gnt_button_new(_("Modify")); | |
735 dialog->modify_button = button; | |
736 gnt_box_add_widget(GNT_BOX(bbox), button); | |
737 | |
738 g_signal_connect(G_OBJECT(button), "activate", | |
739 G_CALLBACK(pounces_manager_modify_cb), dialog); | |
740 | |
741 /* Delete button */ | |
742 button = gnt_button_new(_("Delete")); | |
743 dialog->delete_button = button; | |
744 gnt_box_add_widget(GNT_BOX(bbox), button); | |
18511
7ee0e0597a26
Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18345
diff
changeset
|
745 gnt_util_set_trigger_widget(tree, GNT_KEY_DEL, button); |
15817 | 746 |
747 g_signal_connect(G_OBJECT(button), "activate", | |
748 G_CALLBACK(pounces_manager_delete_cb), dialog); | |
749 | |
750 /* Close button */ | |
751 button = gnt_button_new(_("Close")); | |
752 gnt_box_add_widget(GNT_BOX(bbox), button); | |
753 gnt_widget_show(button); | |
754 | |
755 g_signal_connect(G_OBJECT(button), "activate", | |
756 G_CALLBACK(pounces_manager_close_cb), dialog); | |
757 | |
758 gnt_box_add_widget(GNT_BOX(win), bbox); | |
759 | |
760 gnt_widget_show(win); | |
761 populate_pounces_list(pounces_manager); | |
762 } | |
763 | |
764 void | |
765 finch_pounces_manager_hide(void) | |
766 { | |
767 if (pounces_manager == NULL) | |
768 return; | |
769 | |
770 if (pounces_manager->window != NULL) | |
771 gnt_widget_destroy(pounces_manager->window); | |
772 | |
15822 | 773 purple_signals_disconnect_by_handle(pounces_manager); |
15817 | 774 |
775 g_free(pounces_manager); | |
776 pounces_manager = NULL; | |
777 } | |
778 | |
779 static void | |
15822 | 780 pounce_cb(PurplePounce *pounce, PurplePounceEvent events, void *data) |
15817 | 781 { |
15822 | 782 PurpleConversation *conv; |
783 PurpleAccount *account; | |
784 PurpleBuddy *buddy; | |
15817 | 785 const char *pouncee; |
786 const char *alias; | |
787 | |
15822 | 788 pouncee = purple_pounce_get_pouncee(pounce); |
789 account = purple_pounce_get_pouncer(pounce); | |
15817 | 790 |
15822 | 791 buddy = purple_find_buddy(account, pouncee); |
15817 | 792 if (buddy != NULL) |
793 { | |
15822 | 794 alias = purple_buddy_get_alias(buddy); |
15817 | 795 if (alias == NULL) |
796 alias = pouncee; | |
797 } | |
798 else | |
799 alias = pouncee; | |
800 | |
15822 | 801 if (purple_pounce_action_is_enabled(pounce, "open-window")) |
15817 | 802 { |
15822 | 803 conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, pouncee, account); |
15817 | 804 |
805 if (conv == NULL) | |
15822 | 806 conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, account, pouncee); |
15817 | 807 } |
808 | |
15822 | 809 if (purple_pounce_action_is_enabled(pounce, "popup-notify")) |
15817 | 810 { |
811 char *tmp; | |
812 const char *name_shown; | |
813 const char *reason; | |
15822 | 814 reason = purple_pounce_action_get_attribute(pounce, "popup-notify", |
15817 | 815 "reason"); |
816 | |
817 /* | |
818 * Here we place the protocol name in the pounce dialog to lessen | |
819 * confusion about what protocol a pounce is for. | |
820 */ | |
821 tmp = g_strdup_printf( | |
15822 | 822 (events & PURPLE_POUNCE_TYPING) ? |
15817 | 823 _("%s has started typing to you (%s)") : |
15822 | 824 (events & PURPLE_POUNCE_TYPED) ? |
15817 | 825 _("%s has paused while typing to you (%s)") : |
15822 | 826 (events & PURPLE_POUNCE_SIGNON) ? |
15817 | 827 _("%s has signed on (%s)") : |
15822 | 828 (events & PURPLE_POUNCE_IDLE_RETURN) ? |
15817 | 829 _("%s has returned from being idle (%s)") : |
15822 | 830 (events & PURPLE_POUNCE_AWAY_RETURN) ? |
15817 | 831 _("%s has returned from being away (%s)") : |
15822 | 832 (events & PURPLE_POUNCE_TYPING_STOPPED) ? |
15817 | 833 _("%s has stopped typing to you (%s)") : |
15822 | 834 (events & PURPLE_POUNCE_SIGNOFF) ? |
15817 | 835 _("%s has signed off (%s)") : |
15822 | 836 (events & PURPLE_POUNCE_IDLE) ? |
15817 | 837 _("%s has become idle (%s)") : |
15822 | 838 (events & PURPLE_POUNCE_AWAY) ? |
15817 | 839 _("%s has gone away. (%s)") : |
15822 | 840 (events & PURPLE_POUNCE_MESSAGE_RECEIVED) ? |
15817 | 841 _("%s has sent you a message. (%s)") : |
842 _("Unknown pounce event. Please report this!"), | |
15822 | 843 alias, purple_account_get_protocol_name(account)); |
15817 | 844 |
845 /* | |
846 * Ok here is where I change the second argument, title, from | |
847 * NULL to the account alias if we have it or the account | |
848 * name if that's all we have | |
849 */ | |
15822 | 850 if ((name_shown = purple_account_get_alias(account)) == NULL) |
851 name_shown = purple_account_get_username(account); | |
15817 | 852 |
853 if (reason == NULL) | |
854 { | |
15822 | 855 purple_notify_info(NULL, name_shown, tmp, purple_date_format_full(NULL)); |
15817 | 856 } |
857 else | |
858 { | |
15822 | 859 char *tmp2 = g_strdup_printf("%s\n\n%s", reason, purple_date_format_full(NULL)); |
860 purple_notify_info(NULL, name_shown, tmp, tmp2); | |
15817 | 861 g_free(tmp2); |
862 } | |
863 g_free(tmp); | |
864 } | |
865 | |
15822 | 866 if (purple_pounce_action_is_enabled(pounce, "send-message")) |
15817 | 867 { |
868 const char *message; | |
869 | |
15822 | 870 message = purple_pounce_action_get_attribute(pounce, "send-message", |
15817 | 871 "message"); |
872 | |
873 if (message != NULL) | |
874 { | |
15822 | 875 conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, pouncee, account); |
15817 | 876 |
877 if (conv == NULL) | |
15822 | 878 conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, account, pouncee); |
15817 | 879 |
15822 | 880 purple_conversation_write(conv, NULL, message, |
881 PURPLE_MESSAGE_SEND, time(NULL)); | |
15817 | 882 |
883 serv_send_im(account->gc, (char *)pouncee, (char *)message, 0); | |
884 } | |
885 } | |
886 | |
15822 | 887 if (purple_pounce_action_is_enabled(pounce, "execute-command")) |
15817 | 888 { |
889 const char *command; | |
890 | |
15822 | 891 command = purple_pounce_action_get_attribute(pounce, |
15817 | 892 "execute-command", "command"); |
893 | |
894 if (command != NULL) | |
895 { | |
896 char *localecmd = g_locale_from_utf8(command, -1, NULL, | |
897 NULL, NULL); | |
898 | |
899 if (localecmd != NULL) | |
900 { | |
901 int pid = fork(); | |
902 | |
903 if (pid == 0) { | |
904 char *args[4]; | |
905 | |
906 args[0] = "sh"; | |
907 args[1] = "-c"; | |
908 args[2] = (char *)localecmd; | |
909 args[3] = NULL; | |
910 | |
911 execvp(args[0], args); | |
912 | |
913 _exit(0); | |
914 } | |
915 g_free(localecmd); | |
916 } | |
917 } | |
918 } | |
919 | |
15822 | 920 if (purple_pounce_action_is_enabled(pounce, "play-beep")) |
15817 | 921 { |
922 beep(); | |
923 } | |
924 } | |
925 | |
926 static void | |
15822 | 927 free_pounce(PurplePounce *pounce) |
15817 | 928 { |
929 update_pounces(); | |
930 } | |
931 | |
932 static void | |
15822 | 933 new_pounce(PurplePounce *pounce) |
15817 | 934 { |
15822 | 935 purple_pounce_action_register(pounce, "open-window"); |
936 purple_pounce_action_register(pounce, "popup-notify"); | |
937 purple_pounce_action_register(pounce, "send-message"); | |
938 purple_pounce_action_register(pounce, "execute-command"); | |
939 purple_pounce_action_register(pounce, "play-beep"); | |
15817 | 940 |
941 update_pounces(); | |
942 } | |
943 | |
944 void * | |
945 finch_pounces_get_handle() | |
946 { | |
947 static int handle; | |
948 | |
949 return &handle; | |
950 } | |
951 | |
952 void | |
953 finch_pounces_init(void) | |
954 { | |
15822 | 955 purple_pounces_register_handler(FINCH_UI, pounce_cb, new_pounce, |
15817 | 956 free_pounce); |
957 | |
16424
4999bbc52881
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents:
16287
diff
changeset
|
958 purple_prefs_add_none("/finch/pounces"); |
4999bbc52881
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents:
16287
diff
changeset
|
959 purple_prefs_add_none("/finch/pounces/default_actions"); |
4999bbc52881
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents:
16287
diff
changeset
|
960 purple_prefs_add_bool("/finch/pounces/default_actions/open-window", |
15817 | 961 FALSE); |
16424
4999bbc52881
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents:
16287
diff
changeset
|
962 purple_prefs_add_bool("/finch/pounces/default_actions/popup-notify", |
15817 | 963 TRUE); |
16424
4999bbc52881
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents:
16287
diff
changeset
|
964 purple_prefs_add_bool("/finch/pounces/default_actions/send-message", |
15817 | 965 FALSE); |
16424
4999bbc52881
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents:
16287
diff
changeset
|
966 purple_prefs_add_bool("/finch/pounces/default_actions/execute-command", |
15817 | 967 FALSE); |
16424
4999bbc52881
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents:
16287
diff
changeset
|
968 purple_prefs_add_bool("/finch/pounces/default_actions/play-beep", |
15817 | 969 FALSE); |
16424
4999bbc52881
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents:
16287
diff
changeset
|
970 purple_prefs_add_none("/finch/pounces/dialog"); |
15817 | 971 |
15822 | 972 purple_signal_connect(purple_connections_get_handle(), "signed-on", |
15817 | 973 finch_pounces_get_handle(), |
15822 | 974 PURPLE_CALLBACK(signed_on_off_cb), NULL); |
975 purple_signal_connect(purple_connections_get_handle(), "signed-off", | |
15817 | 976 finch_pounces_get_handle(), |
15822 | 977 PURPLE_CALLBACK(signed_on_off_cb), NULL); |
15817 | 978 } |
979 | |
20299
62d0c7885618
applied changes from 2dc8fc60a9db3bce83fb319e9406ec3c01575911
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
20074
diff
changeset
|
980 static void |
62d0c7885618
applied changes from 2dc8fc60a9db3bce83fb319e9406ec3c01575911
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
20074
diff
changeset
|
981 dummy_pounce_cb(PurplePounce *pounce, PurplePounceEvent events, void *data) |
62d0c7885618
applied changes from 2dc8fc60a9db3bce83fb319e9406ec3c01575911
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
20074
diff
changeset
|
982 { |
62d0c7885618
applied changes from 2dc8fc60a9db3bce83fb319e9406ec3c01575911
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
20074
diff
changeset
|
983 } |
62d0c7885618
applied changes from 2dc8fc60a9db3bce83fb319e9406ec3c01575911
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
20074
diff
changeset
|
984 |
15817 | 985 /* XXX: There's no such thing in pidgin. Perhaps there should be? */ |
986 void finch_pounces_uninit() | |
987 { | |
20299
62d0c7885618
applied changes from 2dc8fc60a9db3bce83fb319e9406ec3c01575911
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
20074
diff
changeset
|
988 purple_pounces_register_handler(FINCH_UI, dummy_pounce_cb, NULL, NULL); |
15817 | 989 |
15822 | 990 purple_signals_disconnect_by_handle(finch_pounces_get_handle()); |
15817 | 991 } |
992 |