Fri, 20 Aug 2004 03:44:46 +0000
[gaim-migrate @ 10656]
"ixes sending declines when we would decline a request
to an MSN file xfer.
Fixes accidentally having 2 xfers of the same file in
the transfer dialog when sending through MSN and SILC.
Fixes crash when cancelling MSN file transfers.
Should fix crash when removing old MSN transfers from
the xfer window in MSN.
Fixes MSN crash when the remote side sends a decline
after we've canceled locally." --Dave West
committer: Luke Schierer <lschiere@pidgin.im>
|
6278
d0cd8645bf90
[gaim-migrate @ 6777]
Herman Bloggs <herman@bluedigits.com>
parents:
6261
diff
changeset
|
1 | /* |
| 6209 | 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 <windows.h> | |
| 26 | #include <gdk/gdkwin32.h> | |
| 27 | #include <gdk/gdk.h> | |
| 28 | ||
| 29 | #include "internal.h" | |
| 30 | #include "gtkblist.h" | |
| 31 | #include "gtkprefs.h" | |
| 32 | #include "debug.h" | |
| 33 | ||
| 34 | #include "gaim.h" | |
|
9709
2e73f176cc80
[gaim-migrate @ 10570]
Mark Doliner <markdoliner@pidgin.im>
parents:
6894
diff
changeset
|
35 | #include "gtkdialogs.h" |
| 6209 | 36 | |
| 37 | #include "resource.h" | |
| 38 | #include "MinimizeToTray.h" | |
| 39 | #include "docklet.h" | |
| 40 | ||
| 41 | /* | |
| 42 | * DEFINES, MACROS & DATA TYPES | |
| 43 | */ | |
|
6261
cd2f10dfd8b5
[gaim-migrate @ 6757]
Herman Bloggs <herman@bluedigits.com>
parents:
6260
diff
changeset
|
44 | #define GAIM_SYSTRAY_HINT _("Gaim") |
|
cd2f10dfd8b5
[gaim-migrate @ 6757]
Herman Bloggs <herman@bluedigits.com>
parents:
6260
diff
changeset
|
45 | #define GAIM_SYSTRAY_DISCONN_HINT _("Gaim - Signed off") |
|
cd2f10dfd8b5
[gaim-migrate @ 6757]
Herman Bloggs <herman@bluedigits.com>
parents:
6260
diff
changeset
|
46 | #define GAIM_SYSTRAY_AWAY_HINT _("Gaim - Away") |
| 6209 | 47 | #define WM_TRAYMESSAGE WM_USER /* User defined WM Message */ |
| 48 | ||
| 49 | /* | |
| 50 | * LOCALS | |
| 51 | */ | |
| 52 | static HWND systray_hwnd=0; | |
| 53 | static HICON sysicon_disconn=0; | |
| 54 | static HICON sysicon_conn=0; | |
| 55 | static HICON sysicon_away=0; | |
| 56 | static HICON sysicon_pend=0; | |
| 57 | static HICON sysicon_awypend=0; | |
|
6894
8c6e286b079d
[gaim-migrate @ 7441]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
58 | static HICON sysicon_blank=0; |
| 6209 | 59 | static NOTIFYICONDATA wgaim_nid; |
| 60 | ||
| 61 | ||
| 62 | static LRESULT CALLBACK systray_mainmsg_handler(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { | |
| 63 | static UINT taskbarRestartMsg; /* static here means value is kept across multiple calls to this func */ | |
| 64 | ||
| 65 | switch(msg) { | |
| 66 | case WM_CREATE: | |
|
6425
3e86c949c98a
[gaim-migrate @ 6933]
Herman Bloggs <herman@bluedigits.com>
parents:
6278
diff
changeset
|
67 | gaim_debug(GAIM_DEBUG_INFO, "tray icon", "WM_CREATE\n"); |
| 6209 | 68 | taskbarRestartMsg = RegisterWindowMessage("TaskbarCreated"); |
| 69 | break; | |
| 70 | ||
| 71 | case WM_TIMER: | |
|
6425
3e86c949c98a
[gaim-migrate @ 6933]
Herman Bloggs <herman@bluedigits.com>
parents:
6278
diff
changeset
|
72 | gaim_debug(GAIM_DEBUG_INFO, "tray icon", "WM_TIMER\n"); |
| 6209 | 73 | break; |
| 74 | ||
| 75 | case WM_DESTROY: | |
|
6425
3e86c949c98a
[gaim-migrate @ 6933]
Herman Bloggs <herman@bluedigits.com>
parents:
6278
diff
changeset
|
76 | gaim_debug(GAIM_DEBUG_INFO, "tray icon", "WM_DESTROY\n"); |
| 6209 | 77 | break; |
| 78 | ||
| 79 | case WM_TRAYMESSAGE: | |
| 80 | { | |
| 81 | int type = 0; | |
| 82 | ||
| 83 | /* We'll use Double Click - Single click over on linux */ | |
| 84 | if( lparam == WM_LBUTTONDBLCLK ) | |
| 85 | type = 1; | |
| 86 | else if( lparam == WM_MBUTTONUP ) | |
| 87 | type = 2; | |
| 88 | else if( lparam == WM_RBUTTONUP ) | |
| 89 | type = 3; | |
| 90 | else | |
| 91 | break; | |
| 92 | ||
| 93 | docklet_clicked(type); | |
| 94 | break; | |
| 95 | } | |
| 96 | default: | |
| 97 | if (msg == taskbarRestartMsg) { | |
| 98 | /* explorer crashed and left us hanging... | |
| 99 | This will put the systray icon back in it's place, when it restarts */ | |
| 100 | Shell_NotifyIcon(NIM_ADD,&wgaim_nid); | |
| 101 | } | |
| 102 | break; | |
| 103 | }/* end switch */ | |
| 104 | ||
| 105 | return DefWindowProc(hwnd, msg, wparam, lparam); | |
| 106 | } | |
| 107 | ||
| 108 | /* Create hidden window to process systray messages */ | |
| 109 | static HWND systray_create_hiddenwin() { | |
| 110 | WNDCLASSEX wcex; | |
| 111 | TCHAR wname[32]; | |
| 112 | ||
| 113 | strcpy(wname, "GaimWin"); | |
| 114 | ||
| 115 | wcex.cbSize = sizeof(WNDCLASSEX); | |
| 116 | ||
| 117 | wcex.style = 0; | |
| 118 | wcex.lpfnWndProc = (WNDPROC)systray_mainmsg_handler; | |
| 119 | wcex.cbClsExtra = 0; | |
| 120 | wcex.cbWndExtra = 0; | |
| 121 | wcex.hInstance = wgaim_hinstance(); | |
| 122 | wcex.hIcon = NULL; | |
| 123 | wcex.hCursor = NULL, | |
| 124 | wcex.hbrBackground = NULL; | |
| 125 | wcex.lpszMenuName = NULL; | |
| 126 | wcex.lpszClassName = wname; | |
| 127 | wcex.hIconSm = NULL; | |
| 128 | ||
| 129 | RegisterClassEx(&wcex); | |
| 130 | ||
| 131 | // Create the window | |
| 132 | return (CreateWindow(wname, "", 0, 0, 0, 0, 0, GetDesktopWindow(), NULL, wgaim_hinstance(), 0)); | |
| 133 | } | |
| 134 | ||
| 135 | static void systray_init_icon(HWND hWnd, HICON icon) { | |
| 136 | char* locenc=NULL; | |
| 137 | ||
| 138 | ZeroMemory(&wgaim_nid,sizeof(wgaim_nid)); | |
| 139 | wgaim_nid.cbSize=sizeof(NOTIFYICONDATA); | |
| 140 | wgaim_nid.hWnd=hWnd; | |
| 141 | wgaim_nid.uID=0; | |
| 142 | wgaim_nid.uFlags=NIF_ICON | NIF_MESSAGE | NIF_TIP; | |
| 143 | wgaim_nid.uCallbackMessage=WM_TRAYMESSAGE; | |
| 144 | wgaim_nid.hIcon=icon; | |
| 145 | locenc=g_locale_from_utf8(GAIM_SYSTRAY_DISCONN_HINT, -1, NULL, NULL, NULL); | |
| 146 | strcpy(wgaim_nid.szTip, locenc); | |
| 147 | g_free(locenc); | |
| 148 | Shell_NotifyIcon(NIM_ADD,&wgaim_nid); | |
| 149 | docklet_embedded(); | |
| 150 | } | |
| 151 | ||
| 152 | static void systray_change_icon(HICON icon, char* text) { | |
| 153 | char *locenc=NULL; | |
| 154 | wgaim_nid.hIcon = icon; | |
|
6894
8c6e286b079d
[gaim-migrate @ 7441]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
155 | if(text) { |
|
8c6e286b079d
[gaim-migrate @ 7441]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
156 | locenc = g_locale_from_utf8(text, -1, NULL, NULL, NULL); |
|
8c6e286b079d
[gaim-migrate @ 7441]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
157 | lstrcpy(wgaim_nid.szTip, locenc); |
|
8c6e286b079d
[gaim-migrate @ 7441]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
158 | g_free(locenc); |
|
8c6e286b079d
[gaim-migrate @ 7441]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
159 | } |
| 6209 | 160 | Shell_NotifyIcon(NIM_MODIFY,&wgaim_nid); |
| 161 | } | |
| 162 | ||
| 163 | static void systray_remove_nid(void) { | |
| 164 | Shell_NotifyIcon(NIM_DELETE,&wgaim_nid); | |
| 165 | } | |
| 166 | ||
| 167 | static void wgaim_tray_update_icon(enum docklet_status icon) { | |
| 168 | switch (icon) { | |
| 169 | case offline: | |
| 170 | systray_change_icon(sysicon_disconn, GAIM_SYSTRAY_DISCONN_HINT); | |
| 171 | break; | |
| 172 | case offline_connecting: | |
| 173 | case online_connecting: | |
| 174 | break; | |
| 175 | case online: | |
| 176 | systray_change_icon(sysicon_conn, GAIM_SYSTRAY_HINT); | |
| 177 | break; | |
| 178 | case online_pending: | |
| 179 | systray_change_icon(sysicon_pend, GAIM_SYSTRAY_HINT); | |
| 180 | break; | |
| 181 | case away: | |
| 182 | systray_change_icon(sysicon_away, GAIM_SYSTRAY_AWAY_HINT); | |
| 183 | break; | |
| 184 | case away_pending: | |
| 185 | systray_change_icon(sysicon_awypend, GAIM_SYSTRAY_AWAY_HINT); | |
| 186 | break; | |
| 187 | } | |
| 188 | } | |
| 189 | ||
|
6894
8c6e286b079d
[gaim-migrate @ 7441]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
190 | static void wgaim_tray_blank_icon() { |
|
8c6e286b079d
[gaim-migrate @ 7441]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
191 | systray_change_icon(sysicon_blank, NULL); |
|
8c6e286b079d
[gaim-migrate @ 7441]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
192 | } |
|
8c6e286b079d
[gaim-migrate @ 7441]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
193 | |
| 6209 | 194 | static void wgaim_tray_create() { |
| 195 | /* dummy window to process systray messages */ | |
| 196 | systray_hwnd = systray_create_hiddenwin(); | |
| 197 | ||
| 198 | /* Load icons, and init systray notify icon */ | |
| 199 | sysicon_disconn = (HICON)LoadImage(wgaim_hinstance(), MAKEINTRESOURCE(GAIM_OFFLINE_TRAY_ICON), IMAGE_ICON, 16, 16, 0); | |
| 200 | sysicon_conn = (HICON)LoadImage(wgaim_hinstance(), MAKEINTRESOURCE(GAIM_TRAY_ICON), IMAGE_ICON, 16, 16, 0); | |
| 201 | sysicon_away = (HICON)LoadImage(wgaim_hinstance(), MAKEINTRESOURCE(GAIM_AWAY_TRAY_ICON), IMAGE_ICON, 16, 16, 0); | |
| 202 | sysicon_pend = (HICON)LoadImage(wgaim_hinstance(), MAKEINTRESOURCE(GAIM_PEND_TRAY_ICON), IMAGE_ICON, 16, 16, 0); | |
| 203 | sysicon_awypend = (HICON)LoadImage(wgaim_hinstance(), MAKEINTRESOURCE(GAIM_AWAYPEND_TRAY_ICON), IMAGE_ICON, 16, 16, 0); | |
|
6894
8c6e286b079d
[gaim-migrate @ 7441]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
204 | sysicon_blank = (HICON)LoadImage(wgaim_hinstance(), MAKEINTRESOURCE(GAIM_BLANK_TRAY_ICON), IMAGE_ICON, 16, 16, 0); |
| 6209 | 205 | |
| 206 | /* Create icon in systray */ | |
| 207 | systray_init_icon(systray_hwnd, sysicon_disconn); | |
| 208 | gaim_debug(GAIM_DEBUG_INFO, "tray icon", "created\n"); | |
| 209 | } | |
| 210 | ||
| 211 | static void wgaim_tray_destroy() { | |
| 212 | systray_remove_nid(); | |
| 213 | DestroyWindow(systray_hwnd); | |
| 214 | docklet_remove(TRUE); | |
| 215 | } | |
| 216 | ||
| 217 | static struct docklet_ui_ops wgaim_tray_ops = | |
| 218 | { | |
| 219 | wgaim_tray_create, | |
| 220 | wgaim_tray_destroy, | |
|
6894
8c6e286b079d
[gaim-migrate @ 7441]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
221 | wgaim_tray_update_icon, |
|
8c6e286b079d
[gaim-migrate @ 7441]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
222 | wgaim_tray_blank_icon |
| 6209 | 223 | }; |
| 224 | ||
| 225 | /* Used by docklet's plugin load func */ | |
| 226 | void docklet_ui_init() { | |
| 227 | docklet_set_ui_ops(&wgaim_tray_ops); | |
| 228 | } |