comparison src/buddy.c @ 3472:d33ec392a5e1

[gaim-migrate @ 3523] Rob McQueen went and removed all the GTK version preprocessor statements. Thanks! committer: Tailor Script <tailor@pidgin.im>
author Sean Egan <seanegan@gmail.com>
date Thu, 29 Aug 2002 21:40:08 +0000
parents 7a3f16a375a5
children cfbdfe334975
comparison
equal deleted inserted replaced
3471:7fb93ecd631c 3472:d33ec392a5e1
20 */ 20 */
21 21
22 #ifdef HAVE_CONFIG_H 22 #ifdef HAVE_CONFIG_H
23 #include <config.h> 23 #include <config.h>
24 #endif 24 #endif
25 #ifdef USE_APPLET
26 #include <gnome.h>
27 #include <applet-widget.h>
28 #include "applet.h"
29 #endif /* USE_APPLET */
30 #ifdef GAIM_PLUGINS 25 #ifdef GAIM_PLUGINS
31 #include <dlfcn.h> 26 #include <dlfcn.h>
32 #endif /* GAIM_PLUGINS */ 27 #endif /* GAIM_PLUGINS */
33 #include <string.h> 28 #include <string.h>
34 #include <stdio.h> 29 #include <stdio.h>
39 #include <unistd.h> 34 #include <unistd.h>
40 #include <ctype.h> 35 #include <ctype.h>
41 36
42 #include <gdk/gdkkeysyms.h> 37 #include <gdk/gdkkeysyms.h>
43 #include <gtk/gtk.h> 38 #include <gtk/gtk.h>
44 #include <gdk/gdkx.h>
45 #include "prpl.h" 39 #include "prpl.h"
46 #include "gaim.h" 40 #include "gaim.h"
47 #include "pixmaps/login_icon.xpm" 41 #include "pixmaps/login_icon.xpm"
48 #include "pixmaps/logout_icon.xpm" 42 #include "pixmaps/logout_icon.xpm"
49 #include "pixmaps/no_icon.xpm" 43 #include "pixmaps/no_icon.xpm"
59 #if defined(GAIM_PLUGINS) || defined(USE_PERL) 53 #if defined(GAIM_PLUGINS) || defined(USE_PERL)
60 #include "pixmaps/plugins_small.xpm" 54 #include "pixmaps/plugins_small.xpm"
61 #endif 55 #endif
62 #include "pixmaps/prefs_small.xpm" 56 #include "pixmaps/prefs_small.xpm"
63 #include "pixmaps/search_small.xpm" 57 #include "pixmaps/search_small.xpm"
64 #ifdef USE_APPLET
65 #include "pixmaps/close_small.xpm" 58 #include "pixmaps/close_small.xpm"
66 #else
67 #include "pixmaps/exit_small.xpm" 59 #include "pixmaps/exit_small.xpm"
68 #endif
69 #include "pixmaps/pounce_small.xpm" 60 #include "pixmaps/pounce_small.xpm"
70 #include "pixmaps/about_small.xpm" 61 #include "pixmaps/about_small.xpm"
71 62
72 #include "pixmaps/tmp_send.xpm" 63 #include "pixmaps/tmp_send.xpm"
73 #include "pixmaps/send_small.xpm" 64 #include "pixmaps/send_small.xpm"
93 GtkWidget *blist = NULL; 84 GtkWidget *blist = NULL;
94 GtkWidget *bpmenu; 85 GtkWidget *bpmenu;
95 GtkWidget *buddies; 86 GtkWidget *buddies;
96 87
97 typedef struct _GtkTreePixmaps GtkTreePixmaps; 88 typedef struct _GtkTreePixmaps GtkTreePixmaps;
98
99 89
100 struct buddy_show { 90 struct buddy_show {
101 GtkWidget *item; 91 GtkWidget *item;
102 GtkWidget *pix; 92 GtkWidget *pix;
103 GtkWidget *label; 93 GtkWidget *label;
117 GtkWidget *tree; 107 GtkWidget *tree;
118 GSList *members; 108 GSList *members;
119 char *name; 109 char *name;
120 }; 110 };
121 static GSList *shows = NULL; 111 static GSList *shows = NULL;
112
113 static gboolean blist_hidden;
114 static int docklet_refcount = 0;
122 115
123 /* Predefine some functions */ 116 /* Predefine some functions */
124 static void new_bp_callback(GtkWidget *w, struct buddy *bs); 117 static void new_bp_callback(GtkWidget *w, struct buddy *bs);
125 static struct group_show *find_group_show(char *group); 118 static struct group_show *find_group_show(char *group);
126 static struct buddy_show *find_buddy_show(struct group_show *gs, char *name); 119 static struct buddy_show *find_buddy_show(struct group_show *gs, char *name);
519 gtk_notebook_set_tab_pos(GTK_NOTEBOOK(blist_notebook), GTK_POS_TOP); 512 gtk_notebook_set_tab_pos(GTK_NOTEBOOK(blist_notebook), GTK_POS_TOP);
520 513
521 } 514 }
522 515
523 516
524 #ifdef USE_APPLET
525 gint applet_destroy_buddy(GtkWidget *widget, GdkEvent *event, gpointer *data)
526 {
527 applet_buddy_show = FALSE;
528 gtk_widget_hide(blist);
529 return (TRUE);
530 }
531
532 #endif
533
534 static int handle_click_group(GtkWidget *widget, GdkEventButton *event, struct group *g) 517 static int handle_click_group(GtkWidget *widget, GdkEventButton *event, struct group *g)
535 { 518 {
536 if (event->type == GDK_2BUTTON_PRESS) { 519 if (event->type == GDK_2BUTTON_PRESS) {
537 if (GTK_TREE_ITEM(widget)->expanded) 520 if (GTK_TREE_ITEM(widget)->expanded)
538 gtk_tree_item_collapse(GTK_TREE_ITEM(widget)); 521 gtk_tree_item_collapse(GTK_TREE_ITEM(widget));
1416 show_import_dialog(); 1399 show_import_dialog();
1417 } 1400 }
1418 1401
1419 void do_quit() 1402 void do_quit()
1420 { 1403 {
1421 #ifdef USE_APPLET
1422 applet = NULL;
1423 #endif
1424
1425 /* first we tell those who have requested it we're quitting */ 1404 /* first we tell those who have requested it we're quitting */
1426 plugin_event(event_quit, 0, 0, 0, 0); 1405 plugin_event(event_quit, 0, 0, 0, 0);
1427 1406
1428 signoff_all(); 1407 signoff_all();
1429 #ifdef GAIM_PLUGINS 1408 #ifdef GAIM_PLUGINS
2014 } 1993 }
2015 1994
2016 return g; 1995 return g;
2017 } 1996 }
2018 1997
1998 /* used by this file, and by iconaway.so */
2019 void hide_buddy_list() { 1999 void hide_buddy_list() {
2020 if (blist) 2000 if (!blist) return;
2021 XIconifyWindow(GDK_DISPLAY(), 2001 if (!connections || docklet_refcount) {
2022 GDK_WINDOW_XWINDOW(blist->window), 2002 gtk_widget_hide(blist);
2023 ((_XPrivDisplay)GDK_DISPLAY())->default_screen); 2003 } else {
2024 } 2004 gtk_window_iconify(GTK_WINDOW(blist));
2025 2005 }
2006 blist_hidden = TRUE;
2007 }
2008
2009 /* shared code... not in lschiere/faceprint tree though. oh well */
2010 static void move_buddy_list() {
2011 if (blist_options & OPT_BLIST_SAVED_WINDOWS) {
2012 if (blist_pos.width != 0) { /* Sanity check! */
2013 gtk_widget_set_uposition(blist, blist_pos.x - blist_pos.xoff,
2014 blist_pos.y - blist_pos.yoff);
2015 gtk_widget_set_usize(blist, blist_pos.width, blist_pos.height);
2016 }
2017 }
2018 }
2019
2020 /* mostly used by code in this file */
2026 void unhide_buddy_list() { 2021 void unhide_buddy_list() {
2027 if (blist) 2022 if (!blist) return;
2028 gdk_window_show(blist->window); 2023 gtk_window_present(GTK_WINDOW(blist));
2024 move_buddy_list();
2025 blist_hidden = FALSE;
2026 }
2027
2028 /* used by the docklet */
2029 void toggle_buddy_list() {
2030 if (blist_hidden) {
2031 unhide_buddy_list();
2032 } else {
2033 hide_buddy_list();
2034 }
2035 }
2036
2037 /* for the delete_event handler */
2038 static void close_buddy_list() {
2039 if (docklet_refcount) {
2040 hide_buddy_list();
2041 } else {
2042 do_quit();
2043 }
2044 }
2045
2046 void docklet_add() {
2047 docklet_refcount++;
2048 printf("docklet_refcount: %d\n",docklet_refcount);
2049 }
2050
2051 void docklet_remove() {
2052 if (docklet_refcount) {
2053 docklet_refcount--;
2054 }
2055 printf("docklet_refcount: %d\n",docklet_refcount);
2056 if (!docklet_refcount) {
2057 if (connections) {
2058 unhide_buddy_list();
2059 } else {
2060 gtk_window_present(GTK_WINDOW(mainwindow));
2061 }
2062 }
2029 } 2063 }
2030 2064
2031 static gint log_timeout(struct buddy_show *b) 2065 static gint log_timeout(struct buddy_show *b)
2032 { 2066 {
2033 /* this part is really just a bad hack because of a bug I can't find */ 2067 /* this part is really just a bad hack because of a bug I can't find */
2203 gtk_label_set(GTK_LABEL(bs->idle), ""); 2237 gtk_label_set(GTK_LABEL(bs->idle), "");
2204 if (blist_options & OPT_BLIST_SHOW_IDLETIME) 2238 if (blist_options & OPT_BLIST_SHOW_IDLETIME)
2205 gtk_widget_show(bs->idle); 2239 gtk_widget_show(bs->idle);
2206 2240
2207 style = gtk_style_new(); 2241 style = gtk_style_new();
2208 #if !GTK_CHECK_VERSION(1,3,0)
2209 gdk_font_unref(gtk_style_get_font(style));
2210 #endif
2211 gtk_style_set_font(style, gdk_font_ref(gtk_style_get_font(bs->label->style))); 2242 gtk_style_set_font(style, gdk_font_ref(gtk_style_get_font(bs->label->style)));
2212 for (i = 0; i < 5; i++) 2243 for (i = 0; i < 5; i++)
2213 style->fg[i] = bs->idle->style->fg[i]; 2244 style->fg[i] = bs->idle->style->fg[i];
2214 if ((blist_options & OPT_BLIST_GREY_IDLERS) && (b->idle)) { 2245 if ((blist_options & OPT_BLIST_GREY_IDLERS) && (b->idle)) {
2215 style->fg[GTK_STATE_NORMAL].red = 2246 style->fg[GTK_STATE_NORMAL].red =
2411 int x, y, width, height; 2442 int x, y, width, height;
2412 int save = 0; 2443 int save = 0;
2413 gdk_window_get_position(blist->window, &x, &y); 2444 gdk_window_get_position(blist->window, &x, &y);
2414 gdk_window_get_size(blist->window, &width, &height); 2445 gdk_window_get_size(blist->window, &width, &height);
2415 2446
2416 #ifdef USE_APPLET 2447 /* fixme: docklet *
2417 if (applet_buddy_show){ 2448 * if (applet_buddy_show){ */
2418 #endif
2419 2449
2420 if (e->send_event) { /* Is a position event */ 2450 if (e->send_event) { /* Is a position event */
2421 if (blist_pos.x != x || blist_pos.y != y) 2451 if (blist_pos.x != x || blist_pos.y != y)
2422 save = 1; 2452 save = 1;
2423 blist_pos.x = x; 2453 blist_pos.x = x;
2433 } 2463 }
2434 2464
2435 if (save) 2465 if (save)
2436 save_prefs(); 2466 save_prefs();
2437 2467
2438 #ifdef USE_APPLET
2439 }
2440 #endif
2441
2442 } 2468 }
2443 2469
2444 2470
2445 /******************************************************************* 2471 /*******************************************************************
2446 * 2472 *
2624 GtkWidget *label; 2650 GtkWidget *label;
2625 GtkWidget *bbox; 2651 GtkWidget *bbox;
2626 GtkWidget *tbox; 2652 GtkWidget *tbox;
2627 2653
2628 if (blist) { 2654 if (blist) {
2629 gtk_widget_show(blist); 2655 unhide_buddy_list;
2630 return; 2656 return;
2631 } 2657 }
2632 2658
2633 #ifdef USE_APPLET
2634 GAIM_DIALOG(blist);
2635 #else
2636 blist = gtk_window_new(GTK_WINDOW_TOPLEVEL); 2659 blist = gtk_window_new(GTK_WINDOW_TOPLEVEL);
2637 #endif
2638 2660
2639 gtk_window_set_wmclass(GTK_WINDOW(blist), "buddy_list", "Gaim"); 2661 gtk_window_set_wmclass(GTK_WINDOW(blist), "buddy_list", "Gaim");
2640 2662
2641 gtk_widget_realize(blist); 2663 gtk_widget_realize(blist);
2642 aol_icon(blist->window); 2664 aol_icon(blist->window);
2673 GTK_SIGNAL_FUNC(show_export_dialog), 0, 0, 0); */ 2695 GTK_SIGNAL_FUNC(show_export_dialog), 0, 0, 0); */
2674 gaim_separator(menu); 2696 gaim_separator(menu);
2675 gaim_new_item_with_pixmap(menu, _("Signoff"), logout_menu_xpm, 2697 gaim_new_item_with_pixmap(menu, _("Signoff"), logout_menu_xpm,
2676 GTK_SIGNAL_FUNC(signoff_all), (void*)1, 'd', GDK_CONTROL_MASK, "Ctl+D"); 2698 GTK_SIGNAL_FUNC(signoff_all), (void*)1, 'd', GDK_CONTROL_MASK, "Ctl+D");
2677 2699
2678 #ifndef USE_APPLET 2700 gaim_new_item_with_pixmap(menu, _("Hide"), close_small_xpm,
2701 GTK_SIGNAL_FUNC(hide_buddy_list), NULL, 'h', GDK_CONTROL_MASK, "Ctl+H");
2702
2679 gaim_new_item_with_pixmap(menu, _("Quit"), exit_small_xpm, 2703 gaim_new_item_with_pixmap(menu, _("Quit"), exit_small_xpm,
2680 GTK_SIGNAL_FUNC(do_quit), NULL, 'q', GDK_CONTROL_MASK, "Ctl+Q"); 2704 GTK_SIGNAL_FUNC(do_quit), NULL, 'q', GDK_CONTROL_MASK, "Ctl+Q");
2681 #else
2682 gaim_new_item_with_pixmap(menu, _("Close"), close_small_xpm,
2683 GTK_SIGNAL_FUNC(applet_destroy_buddy), NULL, 'x', GDK_CONTROL_MASK, "Ctl+X");
2684 #endif
2685 2705
2686 menu = gtk_menu_new(); 2706 menu = gtk_menu_new();
2687 2707
2688 menuitem = gaim_new_item(NULL, _("Tools")); 2708 menuitem = gaim_new_item(NULL, _("Tools"));
2689 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), menu); 2709 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), menu);
2876 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0); 2896 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
2877 gtk_box_pack_start(GTK_BOX(vbox), notebook, TRUE, TRUE, 0); 2897 gtk_box_pack_start(GTK_BOX(vbox), notebook, TRUE, TRUE, 0);
2878 2898
2879 gtk_container_add(GTK_CONTAINER(blist), vbox); 2899 gtk_container_add(GTK_CONTAINER(blist), vbox);
2880 2900
2881 #ifndef USE_APPLET 2901 gtk_signal_connect(GTK_OBJECT(blist), "delete_event", GTK_SIGNAL_FUNC(close_buddy_list),
2882 gtk_signal_connect(GTK_OBJECT(blist), "delete_event", GTK_SIGNAL_FUNC(do_quit), blist);
2883 #else
2884 gtk_signal_connect(GTK_OBJECT(blist), "delete_event", GTK_SIGNAL_FUNC(applet_destroy_buddy),
2885 NULL); 2902 NULL);
2886 #endif
2887 2903
2888 gtk_signal_connect(GTK_OBJECT(blist), "configure_event", GTK_SIGNAL_FUNC(move_blist_window), 2904 gtk_signal_connect(GTK_OBJECT(blist), "configure_event", GTK_SIGNAL_FUNC(move_blist_window),
2889 NULL); 2905 NULL);
2890 2906
2891 2907
2895 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(tbox), 2911 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(tbox),
2896 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); 2912 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
2897 2913
2898 2914
2899 gtk_window_set_title(GTK_WINDOW(blist), _("Gaim - Buddy List")); 2915 gtk_window_set_title(GTK_WINDOW(blist), _("Gaim - Buddy List"));
2900 2916 move_buddy_list();
2901 if (blist_options & OPT_BLIST_SAVED_WINDOWS) { 2917 blist_hidden = FALSE;
2902 if (blist_pos.width != 0) { /* Sanity check! */
2903 gtk_widget_set_uposition(blist, blist_pos.x - blist_pos.xoff,
2904 blist_pos.y - blist_pos.yoff);
2905 gtk_widget_set_usize(blist, blist_pos.width, blist_pos.height);
2906 }
2907 }
2908 } 2918 }
2909 2919
2910 void refresh_buddy_window() 2920 void refresh_buddy_window()
2911 { 2921 {
2912 build_edit_tree(); 2922 build_edit_tree();