-
Notifications
You must be signed in to change notification settings - Fork 1
/
gtkblist.c
8278 lines (6947 loc) · 254 KB
/
gtkblist.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* @file gtkblist.c GTK+ BuddyList API
* @ingroup pidgin
*/
/* pidgin
*
* Pidgin is the legal property of its developers, whose names are too numerous
* to list here. Please refer to the COPYRIGHT file distributed with this
* source distribution.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
*
*/
#include "internal.h"
#include "pidgin.h"
#include "account.h"
#include "connection.h"
#include "core.h"
#include "debug.h"
#include "notify.h"
#include "prpl.h"
#include "prefs.h"
#include "plugin.h"
#include "request.h"
#include "signals.h"
#include "pidginstock.h"
#include "theme-loader.h"
#include "theme-manager.h"
#include "util.h"
#include "gtkaccount.h"
#include "gtkblist.h"
#include "gtkcellrendererexpander.h"
#include "gtkcertmgr.h"
#include "gtkconv.h"
#include "gtkdebug.h"
#include "gtkdialogs.h"
#include "gtkft.h"
#include "gtklog.h"
#include "gtkmenutray.h"
#include "gtkpounce.h"
#include "gtkplugin.h"
#include "gtkprefs.h"
#include "gtkprivacy.h"
#include "gtkroomlist.h"
#include "gtkstatusbox.h"
#include "gtkscrollbook.h"
#include "gtksmiley.h"
#include "gtkblist-theme.h"
#include "gtkblist-theme-loader.h"
#include "gtkutils.h"
#include "pidgin/minidialog.h"
#include "pidgin/pidgintooltip.h"
#include <gdk/gdkkeysyms.h>
#include <gtk/gtk.h>
#include <gdk/gdk.h>
typedef struct
{
PurpleAccount *account;
GtkWidget *window;
GtkBox *vbox;
GtkWidget *account_menu;
GtkSizeGroup *sg;
} PidginBlistRequestData;
typedef struct
{
PidginBlistRequestData rq_data;
GtkWidget *combo;
GtkWidget *entry;
GtkWidget *entry_for_alias;
GtkWidget *entry_for_invite;
} PidginAddBuddyData;
typedef struct
{
PidginBlistRequestData rq_data;
gchar *default_chat_name;
GList *entries;
} PidginChatData;
typedef struct
{
PidginChatData chat_data;
GtkWidget *alias_entry;
GtkWidget *group_combo;
GtkWidget *autojoin;
GtkWidget *persistent;
} PidginAddChatData;
typedef struct
{
/** Used to hold error minidialogs. Gets packed
* inside PidginBuddyList.error_buttons
*/
PidginScrollBook *error_scrollbook;
/** Pointer to the mini-dialog about having signed on elsewhere, if one
* is showing; @c NULL otherwise.
*/
PidginMiniDialog *signed_on_elsewhere;
PidginBlistTheme *current_theme;
guint select_page_timeout; /**< The timeout for pidgin_blist_select_notebook_page_cb */
} PidginBuddyListPrivate;
#define PIDGIN_BUDDY_LIST_GET_PRIVATE(list) \
((PidginBuddyListPrivate *)((list)->priv))
static GtkWidget *accountmenu = NULL;
static guint visibility_manager_count = 0;
static GdkVisibilityState gtk_blist_visibility = GDK_VISIBILITY_UNOBSCURED;
static gboolean gtk_blist_focused = FALSE;
static gboolean editing_blist = FALSE;
static GList *pidgin_blist_sort_methods = NULL;
static struct pidgin_blist_sort_method *current_sort_method = NULL;
static void sort_method_none(PurpleBlistNode *node, PurpleBuddyList *blist, GtkTreeIter groupiter, GtkTreeIter *cur, GtkTreeIter *iter);
static void sort_method_alphabetical(PurpleBlistNode *node, PurpleBuddyList *blist, GtkTreeIter groupiter, GtkTreeIter *cur, GtkTreeIter *iter);
static void sort_method_status(PurpleBlistNode *node, PurpleBuddyList *blist, GtkTreeIter groupiter, GtkTreeIter *cur, GtkTreeIter *iter);
static void sort_method_log_activity(PurpleBlistNode *node, PurpleBuddyList *blist, GtkTreeIter groupiter, GtkTreeIter *cur, GtkTreeIter *iter);
static PidginBuddyList *gtkblist = NULL;
static GList *groups_tree(void);
static gboolean pidgin_blist_refresh_timer(PurpleBuddyList *list);
static void pidgin_blist_update_buddy(PurpleBuddyList *list, PurpleBlistNode *node, gboolean status_change);
static void pidgin_blist_selection_changed(GtkTreeSelection *selection, gpointer data);
static void pidgin_blist_update(PurpleBuddyList *list, PurpleBlistNode *node);
static void pidgin_blist_update_group(PurpleBuddyList *list, PurpleBlistNode *node);
static void pidgin_blist_update_contact(PurpleBuddyList *list, PurpleBlistNode *node);
static char *pidgin_get_tooltip_text(PurpleBlistNode *node, gboolean full);
static const char *item_factory_translate_func (const char *path, gpointer func_data);
static gboolean get_iter_from_node(PurpleBlistNode *node, GtkTreeIter *iter);
static gboolean buddy_is_displayable(PurpleBuddy *buddy);
static void redo_buddy_list(PurpleBuddyList *list, gboolean remove, gboolean rerender);
static void pidgin_blist_collapse_contact_cb(GtkWidget *w, PurpleBlistNode *node);
static char *pidgin_get_group_title(PurpleBlistNode *gnode, gboolean expanded);
static void pidgin_blist_expand_contact_cb(GtkWidget *w, PurpleBlistNode *node);
static void set_urgent(void);
typedef enum {
PIDGIN_BLIST_NODE_HAS_PENDING_MESSAGE = 1 << 0, /* Whether there's pending message in a conversation */
PIDGIN_BLIST_CHAT_HAS_PENDING_MESSAGE_WITH_NICK = 1 << 1, /* Whether there's a pending message in a chat that mentions our nick */
} PidginBlistNodeFlags;
typedef struct _pidgin_blist_node {
GtkTreeRowReference *row;
gboolean contact_expanded;
gboolean recent_signonoff;
gint recent_signonoff_timer;
struct {
PurpleConversation *conv;
time_t last_message; /* timestamp for last displayed message */
PidginBlistNodeFlags flags;
} conv;
} PidginBlistNode;
/***************************************************
* Callbacks *
***************************************************/
static gboolean gtk_blist_visibility_cb(GtkWidget *w, GdkEventVisibility *event, gpointer data)
{
GdkVisibilityState old_state = gtk_blist_visibility;
gtk_blist_visibility = event->state;
if (gtk_blist_visibility == GDK_VISIBILITY_FULLY_OBSCURED &&
old_state != GDK_VISIBILITY_FULLY_OBSCURED) {
/* no longer fully obscured */
pidgin_blist_refresh_timer(purple_get_blist());
}
/* continue to handle event normally */
return FALSE;
}
static gboolean gtk_blist_window_state_cb(GtkWidget *w, GdkEventWindowState *event, gpointer data)
{
if(event->changed_mask & GDK_WINDOW_STATE_WITHDRAWN) {
if(event->new_window_state & GDK_WINDOW_STATE_WITHDRAWN)
purple_prefs_set_bool(PIDGIN_PREFS_ROOT "/blist/list_visible", FALSE);
else {
purple_prefs_set_bool(PIDGIN_PREFS_ROOT "/blist/list_visible", TRUE);
pidgin_blist_refresh_timer(purple_get_blist());
}
}
if(event->changed_mask & GDK_WINDOW_STATE_MAXIMIZED) {
if(event->new_window_state & GDK_WINDOW_STATE_MAXIMIZED)
purple_prefs_set_bool(PIDGIN_PREFS_ROOT "/blist/list_maximized", TRUE);
else
purple_prefs_set_bool(PIDGIN_PREFS_ROOT "/blist/list_maximized", FALSE);
}
/* Refresh gtkblist if un-iconifying */
if (event->changed_mask & GDK_WINDOW_STATE_ICONIFIED){
if (!(event->new_window_state & GDK_WINDOW_STATE_ICONIFIED))
pidgin_blist_refresh_timer(purple_get_blist());
}
return FALSE;
}
static gboolean gtk_blist_delete_cb(GtkWidget *w, GdkEventAny *event, gpointer data)
{
if(visibility_manager_count)
purple_blist_set_visible(FALSE);
else
purple_core_quit();
/* we handle everything, event should not propogate further */
return TRUE;
}
static gboolean gtk_blist_configure_cb(GtkWidget *w, GdkEventConfigure *event, gpointer data)
{
/* unfortunately GdkEventConfigure ignores the window gravity, but *
* the only way we have of setting the position doesn't. we have to *
* call get_position because it does pay attention to the gravity. *
* this is inefficient and I agree it sucks, but it's more likely *
* to work correctly. - Robot101 */
gint x, y;
/* check for visibility because when we aren't visible, this will *
* give us bogus (0,0) coordinates. - xOr */
if (GTK_WIDGET_VISIBLE(w))
gtk_window_get_position(GTK_WINDOW(w), &x, &y);
else
return FALSE; /* carry on normally */
#ifdef _WIN32
/* Workaround for GTK+ bug # 169811 - "configure_event" is fired
* when the window is being maximized */
if (gdk_window_get_state(w->window)
& GDK_WINDOW_STATE_MAXIMIZED) {
return FALSE;
}
#endif
/* don't save if nothing changed */
if (x == purple_prefs_get_int(PIDGIN_PREFS_ROOT "/blist/x") &&
y == purple_prefs_get_int(PIDGIN_PREFS_ROOT "/blist/y") &&
event->width == purple_prefs_get_int(PIDGIN_PREFS_ROOT "/blist/width") &&
event->height == purple_prefs_get_int(PIDGIN_PREFS_ROOT "/blist/height")) {
return FALSE; /* carry on normally */
}
/* don't save off-screen positioning */
if (x + event->width < 0 ||
y + event->height < 0 ||
x > gdk_screen_width() ||
y > gdk_screen_height()) {
return FALSE; /* carry on normally */
}
/* ignore changes when maximized */
if(purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/blist/list_maximized"))
return FALSE;
/* store the position */
purple_prefs_set_int(PIDGIN_PREFS_ROOT "/blist/x", x);
purple_prefs_set_int(PIDGIN_PREFS_ROOT "/blist/y", y);
purple_prefs_set_int(PIDGIN_PREFS_ROOT "/blist/width", event->width);
purple_prefs_set_int(PIDGIN_PREFS_ROOT "/blist/height", event->height);
/* continue to handle event normally */
return FALSE;
}
static void gtk_blist_menu_info_cb(GtkWidget *w, PurpleBuddy *b)
{
PurpleAccount *account = purple_buddy_get_account(b);
pidgin_retrieve_user_info(purple_account_get_connection(account),
purple_buddy_get_name(b));
}
static void gtk_blist_menu_im_cb(GtkWidget *w, PurpleBuddy *b)
{
pidgin_dialogs_im_with_user(purple_buddy_get_account(b),
purple_buddy_get_name(b));
}
#ifdef USE_VV
static void gtk_blist_menu_audio_call_cb(GtkWidget *w, PurpleBuddy *b)
{
purple_prpl_initiate_media(purple_buddy_get_account(b),
purple_buddy_get_name(b), PURPLE_MEDIA_AUDIO);
}
static void gtk_blist_menu_video_call_cb(GtkWidget *w, PurpleBuddy *b)
{
/* if the buddy supports both audio and video, start a combined call,
otherwise start a pure video session */
if (purple_prpl_get_media_caps(purple_buddy_get_account(b),
purple_buddy_get_name(b)) &
PURPLE_MEDIA_CAPS_AUDIO_VIDEO) {
purple_prpl_initiate_media(purple_buddy_get_account(b),
purple_buddy_get_name(b), PURPLE_MEDIA_AUDIO | PURPLE_MEDIA_VIDEO);
} else {
purple_prpl_initiate_media(purple_buddy_get_account(b),
purple_buddy_get_name(b), PURPLE_MEDIA_VIDEO);
}
}
#endif
static void gtk_blist_menu_send_file_cb(GtkWidget *w, PurpleBuddy *b)
{
PurpleAccount *account = purple_buddy_get_account(b);
serv_send_file(purple_account_get_connection(account),
purple_buddy_get_name(b), NULL);
}
static void gtk_blist_menu_move_to_cb(GtkWidget *w, PurpleBlistNode *node)
{
PurpleGroup *group = g_object_get_data(G_OBJECT(w), "groupnode");
purple_blist_add_contact((PurpleContact *)node, group, NULL);
}
static void gtk_blist_menu_autojoin_cb(GtkWidget *w, PurpleChat *chat)
{
purple_blist_node_set_bool((PurpleBlistNode*)chat, "gtk-autojoin",
gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(w)));
}
static void gtk_blist_menu_persistent_cb(GtkWidget *w, PurpleChat *chat)
{
purple_blist_node_set_bool((PurpleBlistNode*)chat, "gtk-persistent",
gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(w)));
}
static PurpleConversation *
find_conversation_with_buddy(PurpleBuddy *buddy)
{
PidginBlistNode *ui = purple_blist_node_get_ui_data(PURPLE_BLIST_NODE(buddy));
if (ui)
return ui->conv.conv;
return purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM,
purple_buddy_get_name(buddy),
purple_buddy_get_account(buddy));
}
static void gtk_blist_join_chat(PurpleChat *chat)
{
PurpleAccount *account;
PurpleConversation *conv;
PurplePluginProtocolInfo *prpl_info;
GHashTable *components;
const char *name;
char *chat_name;
account = purple_chat_get_account(chat);
prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(purple_find_prpl(purple_account_get_protocol_id(account)));
components = purple_chat_get_components(chat);
if (prpl_info && prpl_info->get_chat_name)
chat_name = prpl_info->get_chat_name(components);
else
chat_name = NULL;
if (chat_name)
name = chat_name;
else
name = purple_chat_get_name(chat);
conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, name,
account);
if (conv != NULL) {
pidgin_conv_attach_to_conversation(conv);
purple_conversation_present(conv);
}
serv_join_chat(purple_account_get_connection(account), components);
g_free(chat_name);
}
static void gtk_blist_menu_join_cb(GtkWidget *w, PurpleChat *chat)
{
gtk_blist_join_chat(chat);
}
static void gtk_blist_renderer_editing_cancelled_cb(GtkCellRenderer *renderer, PurpleBuddyList *list)
{
editing_blist = FALSE;
g_object_set(G_OBJECT(renderer), "editable", FALSE, NULL);
pidgin_blist_refresh(list);
}
static void gtk_blist_renderer_editing_started_cb(GtkCellRenderer *renderer,
GtkCellEditable *editable,
gchar *path_str,
gpointer user_data)
{
GtkTreeIter iter;
GtkTreePath *path = NULL;
PurpleBlistNode *node;
const char *text = NULL;
path = gtk_tree_path_new_from_string (path_str);
gtk_tree_model_get_iter (GTK_TREE_MODEL(gtkblist->treemodel), &iter, path);
gtk_tree_path_free (path);
gtk_tree_model_get(GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &node, -1);
switch (purple_blist_node_get_type(node)) {
case PURPLE_BLIST_CONTACT_NODE:
text = purple_contact_get_alias(PURPLE_CONTACT(node));
break;
case PURPLE_BLIST_BUDDY_NODE:
text = purple_buddy_get_alias(PURPLE_BUDDY(node));
break;
case PURPLE_BLIST_GROUP_NODE:
text = purple_group_get_name(PURPLE_GROUP(node));
break;
case PURPLE_BLIST_CHAT_NODE:
text = purple_chat_get_name(PURPLE_CHAT(node));
break;
default:
g_return_if_reached();
}
if (GTK_IS_ENTRY (editable)) {
GtkEntry *entry = GTK_ENTRY (editable);
gtk_entry_set_text(entry, text);
}
editing_blist = TRUE;
}
static void
gtk_blist_do_personize(GList *merges)
{
PurpleBlistNode *contact = NULL;
int max = 0;
GList *tmp;
/* First, we find the contact to merge the rest of the buddies into.
* This will be the contact with the most buddies in it; ties are broken
* by which contact is higher in the list
*/
for (tmp = merges; tmp; tmp = tmp->next) {
PurpleBlistNode *node = tmp->data;
PurpleBlistNode *b;
PurpleBlistNodeType type;
int i = 0;
type = purple_blist_node_get_type(node);
if (type == PURPLE_BLIST_BUDDY_NODE) {
node = purple_blist_node_get_parent(node);
type = purple_blist_node_get_type(node);
}
if (type != PURPLE_BLIST_CONTACT_NODE)
continue;
for (b = purple_blist_node_get_first_child(node);
b;
b = purple_blist_node_get_sibling_next(b))
{
i++;
}
if (i > max) {
contact = node;
max = i;
}
}
if (contact == NULL)
return;
/* Merge all those buddies into this contact */
for (tmp = merges; tmp; tmp = tmp->next) {
PurpleBlistNode *node = tmp->data;
if (purple_blist_node_get_type(node) == PURPLE_BLIST_BUDDY_NODE)
node = purple_blist_node_get_parent(node);
if (node == contact)
continue;
purple_blist_merge_contact((PurpleContact *)node, contact);
}
/* And show the expanded contact, so the people know what's going on */
pidgin_blist_expand_contact_cb(NULL, contact);
g_list_free(merges);
}
static void
gtk_blist_auto_personize(PurpleBlistNode *group, const char *alias)
{
PurpleBlistNode *contact;
PurpleBlistNode *buddy;
GList *merges = NULL;
int i = 0;
char *a = g_utf8_casefold(alias, -1);
for (contact = purple_blist_node_get_first_child(group);
contact != NULL;
contact = purple_blist_node_get_sibling_next(contact)) {
char *node_alias;
if (purple_blist_node_get_type(contact) != PURPLE_BLIST_CONTACT_NODE)
continue;
node_alias = g_utf8_casefold(purple_contact_get_alias((PurpleContact *)contact), -1);
if (node_alias && !g_utf8_collate(node_alias, a)) {
merges = g_list_append(merges, contact);
i++;
g_free(node_alias);
continue;
}
g_free(node_alias);
for (buddy = purple_blist_node_get_first_child(contact);
buddy;
buddy = purple_blist_node_get_sibling_next(buddy))
{
if (purple_blist_node_get_type(buddy) != PURPLE_BLIST_BUDDY_NODE)
continue;
node_alias = g_utf8_casefold(purple_buddy_get_alias(PURPLE_BUDDY(buddy)), -1);
if (node_alias && !g_utf8_collate(node_alias, a)) {
merges = g_list_append(merges, buddy);
i++;
g_free(node_alias);
break;
}
g_free(node_alias);
}
}
g_free(a);
if (i > 1)
{
char *msg = g_strdup_printf(ngettext("You have %d contact named %s. Would you like to merge them?", "You currently have %d contacts named %s. Would you like to merge them?", i), i, alias);
purple_request_action(NULL, NULL, msg, _("Merging these contacts will cause them to share a single entry on the buddy list and use a single conversation window. "
"You can separate them again by choosing 'Expand' from the contact's context menu"), 0, NULL, NULL, NULL,
merges, 2, _("_Yes"), PURPLE_CALLBACK(gtk_blist_do_personize), _("_No"), PURPLE_CALLBACK(g_list_free));
g_free(msg);
} else
g_list_free(merges);
}
static void gtk_blist_renderer_edited_cb(GtkCellRendererText *text_rend, char *arg1,
char *arg2, PurpleBuddyList *list)
{
GtkTreeIter iter;
GtkTreePath *path;
PurpleBlistNode *node;
PurpleGroup *dest;
editing_blist = FALSE;
path = gtk_tree_path_new_from_string (arg1);
gtk_tree_model_get_iter (GTK_TREE_MODEL(gtkblist->treemodel), &iter, path);
gtk_tree_path_free (path);
gtk_tree_model_get(GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &node, -1);
gtk_tree_view_set_enable_search (GTK_TREE_VIEW(gtkblist->treeview), TRUE);
g_object_set(G_OBJECT(gtkblist->text_rend), "editable", FALSE, NULL);
switch (purple_blist_node_get_type(node))
{
case PURPLE_BLIST_CONTACT_NODE:
{
PurpleContact *contact = PURPLE_CONTACT(node);
struct _pidgin_blist_node *gtknode =
(struct _pidgin_blist_node *)purple_blist_node_get_ui_data(node);
/*
* XXX Using purple_contact_get_alias here breaks because we
* specifically want to check the contact alias only (i.e. not
* the priority buddy, which purple_contact_get_alias does).
* Adding yet another get_alias is evil, so figure this out
* later :-P
*/
if (contact->alias || gtknode->contact_expanded) {
purple_blist_alias_contact(contact, arg2);
gtk_blist_auto_personize(purple_blist_node_get_parent(node), arg2);
} else {
PurpleBuddy *buddy = purple_contact_get_priority_buddy(contact);
purple_blist_alias_buddy(buddy, arg2);
serv_alias_buddy(buddy);
gtk_blist_auto_personize(purple_blist_node_get_parent(node), arg2);
}
}
break;
case PURPLE_BLIST_BUDDY_NODE:
{
PurpleGroup *group = purple_buddy_get_group(PURPLE_BUDDY(node));
purple_blist_alias_buddy(PURPLE_BUDDY(node), arg2);
serv_alias_buddy(PURPLE_BUDDY(node));
gtk_blist_auto_personize(PURPLE_BLIST_NODE(group), arg2);
}
break;
case PURPLE_BLIST_GROUP_NODE:
dest = purple_find_group(arg2);
if (dest != NULL && purple_utf8_strcasecmp(arg2, purple_group_get_name(PURPLE_GROUP(node)))) {
pidgin_dialogs_merge_groups(PURPLE_GROUP(node), arg2);
} else {
purple_blist_rename_group(PURPLE_GROUP(node), arg2);
}
break;
case PURPLE_BLIST_CHAT_NODE:
purple_blist_alias_chat(PURPLE_CHAT(node), arg2);
break;
default:
break;
}
pidgin_blist_refresh(list);
}
static void
chat_components_edit_ok(PurpleChat *chat, PurpleRequestFields *allfields)
{
GList *groups, *fields;
for (groups = purple_request_fields_get_groups(allfields); groups; groups = groups->next) {
fields = purple_request_field_group_get_fields(groups->data);
for (; fields; fields = fields->next) {
PurpleRequestField *field = fields->data;
const char *id;
char *val;
id = purple_request_field_get_id(field);
if (purple_request_field_get_type(field) == PURPLE_REQUEST_FIELD_INTEGER)
val = g_strdup_printf("%d", purple_request_field_int_get_value(field));
else
val = g_strdup(purple_request_field_string_get_value(field));
if (!val) {
g_hash_table_remove(purple_chat_get_components(chat), id);
} else {
g_hash_table_replace(purple_chat_get_components(chat), g_strdup(id), val); /* val should not be free'd */
}
}
}
}
static void chat_components_edit(GtkWidget *w, PurpleBlistNode *node)
{
PurpleRequestFields *fields = purple_request_fields_new();
PurpleRequestFieldGroup *group = purple_request_field_group_new(NULL);
PurpleRequestField *field;
GList *parts, *iter;
struct proto_chat_entry *pce;
PurpleConnection *gc;
PurpleChat *chat = (PurpleChat*)node;
purple_request_fields_add_group(fields, group);
gc = purple_account_get_connection(purple_chat_get_account(chat));
parts = PURPLE_PLUGIN_PROTOCOL_INFO(purple_connection_get_prpl(gc))->chat_info(gc);
for (iter = parts; iter; iter = iter->next) {
pce = iter->data;
if (pce->is_int) {
int val;
const char *str = g_hash_table_lookup(purple_chat_get_components(chat), pce->identifier);
if (!str || sscanf(str, "%d", &val) != 1)
val = pce->min;
field = purple_request_field_int_new(pce->identifier, pce->label, val);
} else {
field = purple_request_field_string_new(pce->identifier, pce->label,
g_hash_table_lookup(purple_chat_get_components(chat), pce->identifier), FALSE);
if (pce->secret)
purple_request_field_string_set_masked(field, TRUE);
}
if (pce->required)
purple_request_field_set_required(field, TRUE);
purple_request_field_group_add_field(group, field);
g_free(pce);
}
g_list_free(parts);
purple_request_fields(NULL, _("Edit Chat"), NULL, _("Please update the necessary fields."),
fields, _("Save"), G_CALLBACK(chat_components_edit_ok), _("Cancel"), NULL,
NULL, NULL, NULL,
chat);
}
static void gtk_blist_menu_alias_cb(GtkWidget *w, PurpleBlistNode *node)
{
GtkTreeIter iter;
GtkTreePath *path;
if (!(get_iter_from_node(node, &iter))) {
/* This is either a bug, or the buddy is in a collapsed contact */
node = purple_blist_node_get_parent(node);
if (!get_iter_from_node(node, &iter))
/* Now it's definitely a bug */
return;
}
pidgin_blist_tooltip_destroy();
path = gtk_tree_model_get_path(GTK_TREE_MODEL(gtkblist->treemodel), &iter);
g_object_set(G_OBJECT(gtkblist->text_rend), "editable", TRUE, NULL);
gtk_tree_view_set_enable_search (GTK_TREE_VIEW(gtkblist->treeview), FALSE);
gtk_widget_grab_focus(gtkblist->treeview);
gtk_tree_view_set_cursor_on_cell(GTK_TREE_VIEW(gtkblist->treeview), path,
gtkblist->text_column, gtkblist->text_rend, TRUE);
gtk_tree_path_free(path);
}
static void gtk_blist_menu_bp_cb(GtkWidget *w, PurpleBuddy *b)
{
pidgin_pounce_editor_show(purple_buddy_get_account(b),
purple_buddy_get_name(b), NULL);
}
static void gtk_blist_menu_showlog_cb(GtkWidget *w, PurpleBlistNode *node)
{
PurpleLogType type;
PurpleAccount *account;
char *name = NULL;
pidgin_set_cursor(gtkblist->window, GDK_WATCH);
if (PURPLE_BLIST_NODE_IS_BUDDY(node)) {
PurpleBuddy *b = (PurpleBuddy*) node;
type = PURPLE_LOG_IM;
name = g_strdup(purple_buddy_get_name(b));
account = purple_buddy_get_account(b);
} else if (PURPLE_BLIST_NODE_IS_CHAT(node)) {
PurpleChat *c = PURPLE_CHAT(node);
PurplePluginProtocolInfo *prpl_info = NULL;
type = PURPLE_LOG_CHAT;
account = purple_chat_get_account(c);
prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(purple_find_prpl(purple_account_get_protocol_id(account)));
if (prpl_info && prpl_info->get_chat_name) {
name = prpl_info->get_chat_name(purple_chat_get_components(c));
}
} else if (PURPLE_BLIST_NODE_IS_CONTACT(node)) {
pidgin_log_show_contact(PURPLE_CONTACT(node));
pidgin_clear_cursor(gtkblist->window);
return;
} else {
pidgin_clear_cursor(gtkblist->window);
/* This callback should not have been registered for a node
* that doesn't match the type of one of the blocks above. */
g_return_if_reached();
}
if (name && account) {
pidgin_log_show(type, name, account);
pidgin_clear_cursor(gtkblist->window);
}
g_free(name);
}
static void gtk_blist_menu_showoffline_cb(GtkWidget *w, PurpleBlistNode *node)
{
if (PURPLE_BLIST_NODE_IS_BUDDY(node))
{
purple_blist_node_set_bool(node, "show_offline",
!purple_blist_node_get_bool(node, "show_offline"));
pidgin_blist_update(purple_get_blist(), node);
}
else if (PURPLE_BLIST_NODE_IS_CONTACT(node))
{
PurpleBlistNode *bnode;
gboolean setting = !purple_blist_node_get_bool(node, "show_offline");
purple_blist_node_set_bool(node, "show_offline", setting);
for (bnode = purple_blist_node_get_first_child(node);
bnode != NULL;
bnode = purple_blist_node_get_sibling_next(bnode))
{
purple_blist_node_set_bool(bnode, "show_offline", setting);
pidgin_blist_update(purple_get_blist(), bnode);
}
} else if (PURPLE_BLIST_NODE_IS_GROUP(node)) {
PurpleBlistNode *cnode, *bnode;
gboolean setting = !purple_blist_node_get_bool(node, "show_offline");
purple_blist_node_set_bool(node, "show_offline", setting);
for (cnode = purple_blist_node_get_first_child(node);
cnode != NULL;
cnode = purple_blist_node_get_sibling_next(cnode))
{
purple_blist_node_set_bool(cnode, "show_offline", setting);
for (bnode = purple_blist_node_get_first_child(cnode);
bnode != NULL;
bnode = purple_blist_node_get_sibling_next(bnode))
{
purple_blist_node_set_bool(bnode, "show_offline", setting);
pidgin_blist_update(purple_get_blist(), bnode);
}
}
}
}
static void gtk_blist_show_systemlog_cb(void)
{
pidgin_syslog_show();
}
static void gtk_blist_show_onlinehelp_cb(void)
{
purple_notify_uri(NULL, PURPLE_WEBSITE "documentation");
}
static void
do_join_chat(PidginChatData *data)
{
if (data)
{
GHashTable *components =
g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
GList *tmp;
PurpleChat *chat;
for (tmp = data->entries; tmp != NULL; tmp = tmp->next)
{
if (g_object_get_data(tmp->data, "is_spin"))
{
g_hash_table_replace(components,
g_strdup(g_object_get_data(tmp->data, "identifier")),
g_strdup_printf("%d",
gtk_spin_button_get_value_as_int(tmp->data)));
}
else
{
g_hash_table_replace(components,
g_strdup(g_object_get_data(tmp->data, "identifier")),
g_strdup(gtk_entry_get_text(tmp->data)));
}
}
chat = purple_chat_new(data->rq_data.account, NULL, components);
gtk_blist_join_chat(chat);
purple_blist_remove_chat(chat);
}
}
static void
do_joinchat(GtkWidget *dialog, int id, PidginChatData *info)
{
switch(id)
{
case GTK_RESPONSE_OK:
do_join_chat(info);
break;
case 1:
pidgin_roomlist_dialog_show_with_account(info->rq_data.account);
return;
break;
}
gtk_widget_destroy(GTK_WIDGET(dialog));
g_list_free(info->entries);
g_free(info);
}
/*
* Check the values of all the text entry boxes. If any required input
* strings are empty then don't allow the user to click on "OK."
*/
static void
set_sensitive_if_input_cb(GtkWidget *entry, gpointer user_data)
{
PurplePluginProtocolInfo *prpl_info;
PurpleConnection *gc;
PidginChatData *data;
GList *tmp;
const char *text;
gboolean required;
gboolean sensitive = TRUE;
data = user_data;
for (tmp = data->entries; tmp != NULL; tmp = tmp->next)
{
if (!g_object_get_data(tmp->data, "is_spin"))
{
required = GPOINTER_TO_INT(g_object_get_data(tmp->data, "required"));
text = gtk_entry_get_text(tmp->data);
if (required && (*text == '\0'))
sensitive = FALSE;
}
}
gtk_dialog_set_response_sensitive(GTK_DIALOG(data->rq_data.window), GTK_RESPONSE_OK, sensitive);
gc = purple_account_get_connection(data->rq_data.account);
prpl_info = (gc != NULL) ? PURPLE_PLUGIN_PROTOCOL_INFO(gc->prpl) : NULL;
sensitive = (prpl_info != NULL && prpl_info->roomlist_get_list != NULL);
gtk_dialog_set_response_sensitive(GTK_DIALOG(data->rq_data.window), 1, sensitive);
}
static void
pidgin_blist_update_privacy_cb(PurpleBuddy *buddy)
{
struct _pidgin_blist_node *ui_data = purple_blist_node_get_ui_data(PURPLE_BLIST_NODE(buddy));
if (ui_data == NULL || ui_data->row == NULL)
return;
pidgin_blist_update_buddy(purple_get_blist(), PURPLE_BLIST_NODE(buddy), TRUE);
}
static gboolean
chat_account_filter_func(PurpleAccount *account)
{
PurpleConnection *gc = purple_account_get_connection(account);
PurplePluginProtocolInfo *prpl_info = NULL;
if (gc == NULL)
return FALSE;
prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(gc->prpl);
return (prpl_info->chat_info != NULL);
}
gboolean
pidgin_blist_joinchat_is_showable()
{
GList *c;
PurpleConnection *gc;
for (c = purple_connections_get_all(); c != NULL; c = c->next) {
gc = c->data;
if (chat_account_filter_func(purple_connection_get_account(gc)))
return TRUE;
}
return FALSE;
}
static GtkWidget *
make_blist_request_dialog(PidginBlistRequestData *data, PurpleAccount *account,
const char *title, const char *window_role, const char *label_text,
GCallback callback_func, PurpleFilterAccountFunc filter_func,
GCallback response_cb)
{
GtkWidget *label;
GtkWidget *img;
GtkWidget *hbox;
GtkWidget *vbox;
GtkWindow *blist_window;
PidginBuddyList *gtkblist;
data->account = account;
img = gtk_image_new_from_stock(PIDGIN_STOCK_DIALOG_QUESTION,
gtk_icon_size_from_name(PIDGIN_ICON_SIZE_TANGO_HUGE));
gtkblist = PIDGIN_BLIST(purple_get_blist());
blist_window = gtkblist ? GTK_WINDOW(gtkblist->window) : NULL;
data->window = gtk_dialog_new_with_buttons(title,
blist_window, GTK_DIALOG_NO_SEPARATOR,
NULL);
gtk_window_set_transient_for(GTK_WINDOW(data->window), blist_window);
gtk_dialog_set_default_response(GTK_DIALOG(data->window), GTK_RESPONSE_OK);
gtk_container_set_border_width(GTK_CONTAINER(data->window), PIDGIN_HIG_BOX_SPACE);
gtk_window_set_resizable(GTK_WINDOW(data->window), FALSE);
gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(data->window)->vbox), PIDGIN_HIG_BORDER);
gtk_container_set_border_width(GTK_CONTAINER(GTK_DIALOG(data->window)->vbox), PIDGIN_HIG_BOX_SPACE);
gtk_window_set_role(GTK_WINDOW(data->window), window_role);
hbox = gtk_hbox_new(FALSE, PIDGIN_HIG_BORDER);
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(data->window)->vbox), hbox);