Fri, 18 Jul 2003 03:46:42 +0000
[gaim-migrate @ 6695]
trayicon-*.* -> docklet-*.*
| 6209 | 1 | /* |
| 2 | * System tray icon (aka docklet) plugin for Gaim | |
| 3 | * | |
| 4 | * Copyright (C) 2002-3 Robert McQueen <robot101@debian.org> | |
| 5 | * Copyright (C) 2003 Herman Bloggs <hermanator12002@yahoo.com> | |
| 6 | * Inspired by a similar plugin by: | |
| 7 | * John (J5) Palmieri <johnp@martianrock.com> | |
| 8 | * | |
| 9 | * This program is free software; you can redistribute it and/or | |
| 10 | * modify it under the terms of the GNU General Public License as | |
| 11 | * published by the Free Software Foundation; either version 2 of the | |
| 12 | * License, or (at your option) any later version. | |
| 13 | * | |
| 14 | * This program is distributed in the hope that it will be useful, but | |
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 17 | * General Public License for more details. | |
| 18 | * | |
| 19 | * You should have received a copy of the GNU General Public License | |
| 20 | * along with this program; if not, write to the Free Software | |
| 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
| 22 | * 02111-1307, USA. | |
| 23 | */ | |
| 24 | ||
| 25 | #include "internal.h" | |
| 26 | #include "debug.h" | |
| 27 | #include "stock.h" | |
| 28 | ||
| 29 | #include "gaim.h" | |
| 30 | #include "ui.h" | |
| 31 | ||
| 32 | #include "eggtrayicon.h" | |
| 33 | #include "docklet.h" | |
| 34 | ||
| 35 | /* globals */ | |
| 36 | static EggTrayIcon *docklet = NULL; | |
| 37 | static GtkWidget *image = NULL; | |
| 38 | ||
| 39 | /* protos */ | |
| 40 | static void docklet_x11_create(); | |
| 41 | ||
| 42 | static gboolean | |
| 43 | docklet_x11_create_cb() | |
| 44 | { | |
| 45 | docklet_x11_create(); | |
| 46 | ||
| 47 | return FALSE; /* for when we're called by the glib idle handler */ | |
| 48 | } | |
| 49 | ||
| 50 | static void | |
| 51 | docklet_x11_embedded_cb(GtkWidget *widget, void *data) | |
| 52 | { | |
| 53 | gaim_debug(GAIM_DEBUG_INFO, "tray icon", "embedded\n"); | |
| 54 | ||
| 55 | docklet_embedded(); | |
| 56 | } | |
| 57 | ||
| 58 | static void | |
| 59 | docklet_x11_destroyed_cb(GtkWidget *widget, void *data) | |
| 60 | { | |
| 61 | gaim_debug(GAIM_DEBUG_INFO, "tray icon", "destroyed\n"); | |
| 62 | ||
| 63 | docklet_remove(TRUE); | |
| 64 | ||
| 65 | g_object_unref(G_OBJECT(docklet)); | |
| 66 | docklet = NULL; | |
| 67 | ||
| 68 | g_idle_add(docklet_x11_create_cb, &handle); | |
| 69 | } | |
| 70 | ||
| 71 | static void | |
| 72 | docklet_x11_clicked_cb(GtkWidget *button, GdkEventButton *event, void *data) | |
| 73 | { | |
| 74 | if (event->type != GDK_BUTTON_PRESS) | |
| 75 | return; | |
| 76 | ||
| 77 | docklet_clicked(event->button); | |
| 78 | } | |
| 79 | ||
| 80 | static void | |
| 81 | docklet_x11_update_icon(enum docklet_status icon) | |
| 82 | { | |
| 83 | const gchar *icon_name = NULL; | |
| 84 | ||
| 85 | switch (icon) { | |
| 86 | case offline: | |
| 87 | icon_name = GAIM_STOCK_ICON_OFFLINE; | |
| 88 | break; | |
| 89 | case offline_connecting: | |
| 90 | case online_connecting: | |
| 91 | icon_name = GAIM_STOCK_ICON_CONNECT; | |
| 92 | break; | |
| 93 | case online: | |
| 94 | icon_name = GAIM_STOCK_ICON_ONLINE; | |
| 95 | break; | |
| 96 | case online_pending: | |
| 97 | icon_name = GAIM_STOCK_ICON_ONLINE_MSG; | |
| 98 | break; | |
| 99 | case away: | |
| 100 | icon_name = GAIM_STOCK_ICON_AWAY; | |
| 101 | break; | |
| 102 | case away_pending: | |
| 103 | icon_name = GAIM_STOCK_ICON_AWAY_MSG; | |
| 104 | break; | |
| 105 | } | |
| 106 | ||
| 107 | gtk_image_set_from_stock(GTK_IMAGE(image), icon_name, GTK_ICON_SIZE_LARGE_TOOLBAR); | |
| 108 | } | |
| 109 | ||
| 110 | static void | |
| 111 | docklet_x11_destroy() | |
| 112 | { | |
| 113 | docklet_remove(GTK_WIDGET_VISIBLE(docklet)); | |
| 114 | ||
| 115 | g_signal_handlers_disconnect_by_func(G_OBJECT(docklet), G_CALLBACK(docklet_x11_destroyed_cb), NULL); | |
| 116 | gtk_widget_destroy(GTK_WIDGET(docklet)); | |
| 117 | ||
| 118 | g_object_unref(G_OBJECT(docklet)); | |
| 119 | docklet = NULL; | |
| 120 | ||
| 121 | gaim_debug(GAIM_DEBUG_INFO, "tray icon", "destroyed\n"); | |
| 122 | } | |
| 123 | ||
| 124 | static void | |
| 125 | docklet_x11_create() | |
| 126 | { | |
| 127 | GtkWidget *box; | |
| 128 | ||
| 129 | if (docklet) { | |
| 130 | /* if this is being called when a tray icon exists, it's because | |
| 131 | something messed up. try destroying it before we proceed, | |
| 132 | although docklet_refcount may be all hosed. hopefully won't happen. */ | |
| 133 | gaim_debug(GAIM_DEBUG_WARNING, "tray icon", "trying to create icon but it already exists?\n"); | |
| 134 | docklet_x11_destroy(); | |
| 135 | } | |
| 136 | ||
| 137 | docklet = egg_tray_icon_new("Gaim"); | |
| 138 | box = gtk_event_box_new(); | |
| 139 | image = gtk_image_new(); | |
| 140 | ||
| 141 | g_signal_connect(G_OBJECT(docklet), "embedded", G_CALLBACK(docklet_x11_embedded_cb), NULL); | |
| 142 | g_signal_connect(G_OBJECT(docklet), "destroy", G_CALLBACK(docklet_x11_destroyed_cb), NULL); | |
| 143 | g_signal_connect(G_OBJECT(box), "button-press-event", G_CALLBACK(docklet_x11_clicked_cb), NULL); | |
| 144 | ||
| 145 | gtk_container_add(GTK_CONTAINER(box), image); | |
| 146 | gtk_container_add(GTK_CONTAINER(docklet), box); | |
| 147 | gtk_widget_show_all(GTK_WIDGET(docklet)); | |
| 148 | ||
| 149 | /* ref the docklet before we bandy it about the place */ | |
| 150 | g_object_ref(G_OBJECT(docklet)); | |
| 151 | ||
| 152 | gaim_debug(GAIM_DEBUG_INFO, "tray icon", "created\n"); | |
| 153 | } | |
| 154 | ||
| 155 | static struct docklet_ui_ops ui_ops = | |
| 156 | { | |
| 157 | docklet_x11_create, | |
| 158 | docklet_x11_destroy, | |
| 159 | docklet_x11_update_icon | |
| 160 | }; | |
| 161 | ||
| 162 | void | |
| 163 | docklet_ui_init() | |
| 164 | { | |
| 165 | docklet_set_ui_ops(&ui_ops); | |
| 166 | } |