| 66 |
65 |
| 67 /* |
66 /* |
| 68 * PUBLIC CODE |
67 * PUBLIC CODE |
| 69 */ |
68 */ |
| 70 |
69 |
| 71 HINSTANCE gtkwgaim_hinstance(void) { |
70 HINSTANCE winpidgin_hinstance(void) { |
| 72 return gaimexe_hInstance; |
71 return exe_hInstance; |
| 73 } |
72 } |
| 74 |
73 |
| 75 int gtkwgaim_gz_decompress(const char* in, const char* out) { |
74 int winpidgin_gz_decompress(const char* in, const char* out) { |
| 76 gzFile fin; |
75 gzFile fin; |
| 77 FILE *fout; |
76 FILE *fout; |
| 78 char buf[1024]; |
77 char buf[1024]; |
| 79 int ret; |
78 int ret; |
| 80 |
79 |
| 81 if((fin = gzopen(in, "rb"))) { |
80 if((fin = gzopen(in, "rb"))) { |
| 82 if(!(fout = g_fopen(out, "wb"))) { |
81 if(!(fout = g_fopen(out, "wb"))) { |
| 83 gaim_debug_error("gtkwgaim_gz_decompress", "Error opening file: %s\n", out); |
82 gaim_debug_error("winpidgin_gz_decompress", "Error opening file: %s\n", out); |
| 84 gzclose(fin); |
83 gzclose(fin); |
| 85 return 0; |
84 return 0; |
| 86 } |
85 } |
| 87 } |
86 } |
| 88 else { |
87 else { |
| 89 gaim_debug_error("gtkwgaim_gz_decompress", "gzopen failed to open: %s\n", in); |
88 gaim_debug_error("winpidgin_gz_decompress", "gzopen failed to open: %s\n", in); |
| 90 return 0; |
89 return 0; |
| 91 } |
90 } |
| 92 |
91 |
| 93 while((ret = gzread(fin, buf, 1024))) { |
92 while((ret = gzread(fin, buf, 1024))) { |
| 94 if(fwrite(buf, 1, ret, fout) < ret) { |
93 if(fwrite(buf, 1, ret, fout) < ret) { |
| 100 } |
99 } |
| 101 fclose(fout); |
100 fclose(fout); |
| 102 gzclose(fin); |
101 gzclose(fin); |
| 103 |
102 |
| 104 if(ret < 0) { |
103 if(ret < 0) { |
| 105 gaim_debug_error("gtkwgaim_gz_decompress", "gzread failed while reading: %s\n", in); |
104 gaim_debug_error("winpidgin_gz_decompress", "gzread failed while reading: %s\n", in); |
| 106 return 0; |
105 return 0; |
| 107 } |
106 } |
| 108 |
107 |
| 109 return 1; |
108 return 1; |
| 110 } |
109 } |
| 111 |
110 |
| 112 int gtkwgaim_gz_untar(const char* filename, const char* destdir) { |
111 int winpidgin_gz_untar(const char* filename, const char* destdir) { |
| 113 char tmpfile[_MAX_PATH]; |
112 char tmpfile[_MAX_PATH]; |
| 114 char template[]="wgaimXXXXXX"; |
113 char template[]="wpidginXXXXXX"; |
| 115 |
114 |
| 116 sprintf(tmpfile, "%s%s%s", g_get_tmp_dir(), G_DIR_SEPARATOR_S, _mktemp(template)); |
115 sprintf(tmpfile, "%s%s%s", g_get_tmp_dir(), G_DIR_SEPARATOR_S, _mktemp(template)); |
| 117 if(gtkwgaim_gz_decompress(filename, tmpfile)) { |
116 if(winpidgin_gz_decompress(filename, tmpfile)) { |
| 118 int ret; |
117 int ret; |
| 119 if(untar(tmpfile, destdir, UNTAR_FORCE | UNTAR_QUIET)) |
118 if(untar(tmpfile, destdir, UNTAR_FORCE | UNTAR_QUIET)) |
| 120 ret = 1; |
119 ret = 1; |
| 121 else { |
120 else { |
| 122 gaim_debug_error("gtkwgaim_gz_untar", "Failure untarring %s\n", tmpfile); |
121 gaim_debug_error("winpidgin_gz_untar", "Failure untarring %s\n", tmpfile); |
| 123 ret = 0; |
122 ret = 0; |
| 124 } |
123 } |
| 125 g_unlink(tmpfile); |
124 g_unlink(tmpfile); |
| 126 return ret; |
125 return ret; |
| 127 } |
126 } |
| 128 else { |
127 else { |
| 129 gaim_debug_error("gtkwgaim_gz_untar", "Failed to gz decompress %s\n", filename); |
128 gaim_debug_error("winpidgin_gz_untar", "Failed to gz decompress %s\n", filename); |
| 130 return 0; |
129 return 0; |
| 131 } |
130 } |
| 132 } |
131 } |
| 133 |
132 |
| 134 void gtkwgaim_shell_execute(const char *target, const char *verb, const char *clazz) { |
133 void winpidgin_shell_execute(const char *target, const char *verb, const char *clazz) { |
| 135 |
134 |
| 136 g_return_if_fail(target != NULL); |
135 g_return_if_fail(target != NULL); |
| 137 g_return_if_fail(verb != NULL); |
136 g_return_if_fail(verb != NULL); |
| 138 |
137 |
| 139 if (G_WIN32_HAVE_WIDECHAR_API()) { |
138 if (G_WIN32_HAVE_WIDECHAR_API()) { |
| 176 sinfo.fMask |= SEE_MASK_CLASSNAME; |
175 sinfo.fMask |= SEE_MASK_CLASSNAME; |
| 177 sinfo.lpClass = clazz; |
176 sinfo.lpClass = clazz; |
| 178 } |
177 } |
| 179 |
178 |
| 180 if(!ShellExecuteExA(&sinfo)) |
179 if(!ShellExecuteExA(&sinfo)) |
| 181 gaim_debug_error("gtkwgaim", "Error opening URI: %s error: %d\n", |
180 gaim_debug_error("winpidgin", "Error opening URI: %s error: %d\n", |
| 182 target, (int) sinfo.hInstApp); |
181 target, (int) sinfo.hInstApp); |
| 183 |
182 |
| 184 g_free(locale_uri); |
183 g_free(locale_uri); |
| 185 } |
184 } |
| 186 |
185 |
| 187 } |
186 } |
| 188 |
187 |
| 189 void gtkwgaim_notify_uri(const char *uri) { |
188 void winpidgin_notify_uri(const char *uri) { |
| 190 /* We'll allow whatever URI schemes are supported by the |
189 /* We'll allow whatever URI schemes are supported by the |
| 191 * default http browser. |
190 * default http browser. |
| 192 */ |
191 */ |
| 193 gtkwgaim_shell_execute(uri, "open", "http"); |
192 winpidgin_shell_execute(uri, "open", "http"); |
| 194 } |
193 } |
| 195 |
194 |
| 196 #define WM_FOCUS_REQUEST (WM_APP + 13) |
195 #define WM_FOCUS_REQUEST (WM_APP + 13) |
| 197 |
196 |
| 198 static LRESULT CALLBACK message_window_handler(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { |
197 static LRESULT CALLBACK message_window_handler(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { |
| 199 |
198 |
| 200 if (msg == WM_FOCUS_REQUEST) { |
199 if (msg == WM_FOCUS_REQUEST) { |
| 201 gaim_debug_info("gtkwgaim", "Got external Buddy List focus request."); |
200 gaim_debug_info("winpidgin", "Got external Buddy List focus request."); |
| 202 gaim_blist_set_visible(TRUE); |
201 gaim_blist_set_visible(TRUE); |
| 203 return TRUE; |
202 return TRUE; |
| 204 } |
203 } |
| 205 |
204 |
| 206 return DefWindowProc(hwnd, msg, wparam, lparam); |
205 return DefWindowProc(hwnd, msg, wparam, lparam); |
| 207 } |
206 } |
| 208 |
207 |
| 209 static HWND wgaim_message_window_init(void) { |
208 static HWND winpidgin_message_window_init(void) { |
| 210 HWND win_hwnd; |
209 HWND win_hwnd; |
| 211 WNDCLASSEX wcx; |
210 WNDCLASSEX wcx; |
| 212 LPCTSTR wname; |
211 LPCTSTR wname; |
| 213 |
212 |
| 214 wname = TEXT("WingaimMsgWinCls"); |
213 wname = TEXT("WinpidginMsgWinCls"); |
| 215 |
214 |
| 216 wcx.cbSize = sizeof(wcx); |
215 wcx.cbSize = sizeof(wcx); |
| 217 wcx.style = 0; |
216 wcx.style = 0; |
| 218 wcx.lpfnWndProc = message_window_handler; |
217 wcx.lpfnWndProc = message_window_handler; |
| 219 wcx.cbClsExtra = 0; |
218 wcx.cbClsExtra = 0; |
| 220 wcx.cbWndExtra = 0; |
219 wcx.cbWndExtra = 0; |
| 221 wcx.hInstance = gtkwgaim_hinstance(); |
220 wcx.hInstance = winpidgin_hinstance(); |
| 222 wcx.hIcon = NULL; |
221 wcx.hIcon = NULL; |
| 223 wcx.hCursor = NULL; |
222 wcx.hCursor = NULL; |
| 224 wcx.hbrBackground = NULL; |
223 wcx.hbrBackground = NULL; |
| 225 wcx.lpszMenuName = NULL; |
224 wcx.lpszMenuName = NULL; |
| 226 wcx.lpszClassName = wname; |
225 wcx.lpszClassName = wname; |
| 227 wcx.hIconSm = NULL; |
226 wcx.hIconSm = NULL; |
| 228 |
227 |
| 229 RegisterClassEx(&wcx); |
228 RegisterClassEx(&wcx); |
| 230 |
229 |
| 231 /* Create the window */ |
230 /* Create the window */ |
| 232 if(!(win_hwnd = CreateWindow(wname, TEXT("WingaimMsgWin"), 0, 0, 0, 0, 0, |
231 if(!(win_hwnd = CreateWindow(wname, TEXT("WinpidginMsgWin"), 0, 0, 0, 0, 0, |
| 233 NULL, NULL, gtkwgaim_hinstance(), 0))) { |
232 NULL, NULL, winpidgin_hinstance(), 0))) { |
| 234 gaim_debug_error("gtkwgaim", |
233 gaim_debug_error("winpidgin", |
| 235 "Unable to create message window.\n"); |
234 "Unable to create message window.\n"); |
| 236 return NULL; |
235 return NULL; |
| 237 } |
236 } |
| 238 |
237 |
| 239 return win_hwnd; |
238 return win_hwnd; |
| 240 } |
239 } |
| 241 |
240 |
| 242 static gboolean stop_flashing(GtkWidget *widget, GdkEventFocus *event, gpointer data) { |
241 static gboolean stop_flashing(GtkWidget *widget, GdkEventFocus *event, gpointer data) { |
| 243 GtkWindow *window = data; |
242 GtkWindow *window = data; |
| 244 gtkwgaim_window_flash(window, FALSE); |
243 winpidgin_window_flash(window, FALSE); |
| 245 return FALSE; |
244 return FALSE; |
| 246 } |
245 } |
| 247 |
246 |
| 248 void |
247 void |
| 249 gtkwgaim_window_flash(GtkWindow *window, gboolean flash) { |
248 winpidgin_window_flash(GtkWindow *window, gboolean flash) { |
| 250 GdkWindow * gdkwin; |
249 GdkWindow * gdkwin; |
| 251 |
250 |
| 252 g_return_if_fail(window != NULL); |
251 g_return_if_fail(window != NULL); |
| 253 |
252 |
| 254 gdkwin = GTK_WIDGET(window)->window; |
253 gdkwin = GTK_WIDGET(window)->window; |
| 276 } else |
275 } else |
| 277 FlashWindow(GDK_WINDOW_HWND(gdkwin), flash); |
276 FlashWindow(GDK_WINDOW_HWND(gdkwin), flash); |
| 278 } |
277 } |
| 279 |
278 |
| 280 void |
279 void |
| 281 gtkwgaim_conv_blink(GaimConversation *conv, GaimMessageFlags flags) { |
280 winpidgin_conv_blink(GaimConversation *conv, GaimMessageFlags flags) { |
| 282 PidginWindow *win; |
281 PidginWindow *win; |
| 283 GtkWindow *window; |
282 GtkWindow *window; |
| 284 |
283 |
| 285 /* Don't flash for our own messages or system messages */ |
284 /* Don't flash for our own messages or system messages */ |
| 286 if(flags & GAIM_MESSAGE_SEND || flags & GAIM_MESSAGE_SYSTEM) |
285 if(flags & GAIM_MESSAGE_SEND || flags & GAIM_MESSAGE_SYSTEM) |
| 287 return; |
286 return; |
| 288 |
287 |
| 289 if(conv == NULL) { |
288 if(conv == NULL) { |
| 290 gaim_debug_info("gtkwgaim", "No conversation found to blink.\n"); |
289 gaim_debug_info("winpidgin", "No conversation found to blink.\n"); |
| 291 return; |
290 return; |
| 292 } |
291 } |
| 293 |
292 |
| 294 win = pidgin_conv_get_window(PIDGIN_CONVERSATION(conv)); |
293 win = pidgin_conv_get_window(PIDGIN_CONVERSATION(conv)); |
| 295 if(win == NULL) { |
294 if(win == NULL) { |
| 296 gaim_debug_info("gtkwgaim", "No conversation windows found to blink.\n"); |
295 gaim_debug_info("winpidgin", "No conversation windows found to blink.\n"); |
| 297 return; |
296 return; |
| 298 } |
297 } |
| 299 window = GTK_WINDOW(win->window); |
298 window = GTK_WINDOW(win->window); |
| 300 |
299 |
| 301 gtkwgaim_window_flash(window, TRUE); |
300 winpidgin_window_flash(window, TRUE); |
| 302 /* Stop flashing when window receives focus */ |
301 /* Stop flashing when window receives focus */ |
| 303 g_signal_connect(G_OBJECT(window), "focus-in-event", |
302 g_signal_connect(G_OBJECT(window), "focus-in-event", |
| 304 G_CALLBACK(stop_flashing), window); |
303 G_CALLBACK(stop_flashing), window); |
| 305 } |
304 } |
| 306 |
305 |
| 307 static gboolean |
306 static gboolean |
| 308 gtkwgaim_conv_im_blink(GaimAccount *account, const char *who, char **message, |
307 winpidgin_conv_im_blink(GaimAccount *account, const char *who, char **message, |
| 309 GaimConversation *conv, GaimMessageFlags flags, void *data) |
308 GaimConversation *conv, GaimMessageFlags flags, void *data) |
| 310 { |
309 { |
| 311 if (gaim_prefs_get_bool("/gaim/gtk/win32/blink_im")) |
310 if (gaim_prefs_get_bool("/gaim/gtk/win32/blink_im")) |
| 312 gtkwgaim_conv_blink(conv, flags); |
311 winpidgin_conv_blink(conv, flags); |
| 313 return FALSE; |
312 return FALSE; |
| 314 } |
313 } |
| 315 |
314 |
| 316 void gtkwgaim_init(HINSTANCE hint) { |
315 void winpidgin_init(HINSTANCE hint) { |
| 317 |
316 |
| 318 gaim_debug_info("gtkwgaim", "gtkwgaim_init start\n"); |
317 gaim_debug_info("winpidgin", "winpidgin_init start\n"); |
| 319 |
318 |
| 320 gaimexe_hInstance = hint; |
319 exe_hInstance = hint; |
| 321 |
320 |
| 322 /* IdleTracker Initialization */ |
321 /* IdleTracker Initialization */ |
| 323 if(!wgaim_set_idlehooks()) |
322 if(!winpidgin_set_idlehooks()) |
| 324 gaim_debug_error("gtkwgaim", "Failed to initialize idle tracker\n"); |
323 gaim_debug_error("winpidgin", "Failed to initialize idle tracker\n"); |
| 325 |
324 |
| 326 wpidginspell_init(); |
325 wpidginspell_init(); |
| 327 gaim_debug_info("gtkwgaim", "GTK+ :%u.%u.%u\n", |
326 gaim_debug_info("winpidgin", "GTK+ :%u.%u.%u\n", |
| 328 gtk_major_version, gtk_minor_version, gtk_micro_version); |
327 gtk_major_version, gtk_minor_version, gtk_micro_version); |
| 329 |
328 |
| 330 messagewin_hwnd = wgaim_message_window_init(); |
329 messagewin_hwnd = winpidgin_message_window_init(); |
| 331 |
330 |
| 332 MyFlashWindowEx = (LPFNFLASHWINDOWEX) wgaim_find_and_loadproc("user32.dll", "FlashWindowEx"); |
331 MyFlashWindowEx = (LPFNFLASHWINDOWEX) wgaim_find_and_loadproc("user32.dll", "FlashWindowEx"); |
| 333 |
332 |
| 334 gaim_debug_info("gtkwgaim", "gtkwgaim_init end\n"); |
333 gaim_debug_info("winpidgin", "winpidgin_init end\n"); |
| 335 } |
334 } |
| 336 |
335 |
| 337 void gtkwgaim_post_init(void) { |
336 void winpidgin_post_init(void) { |
| 338 |
337 |
| 339 gaim_prefs_add_none("/gaim/gtk/win32"); |
338 gaim_prefs_add_none("/gaim/gtk/win32"); |
| 340 gaim_prefs_add_bool("/gaim/gtk/win32/blink_im", TRUE); |
339 gaim_prefs_add_bool("/gaim/gtk/win32/blink_im", TRUE); |
| 341 |
340 |
| 342 gaim_signal_connect(pidgin_conversations_get_handle(), |
341 gaim_signal_connect(pidgin_conversations_get_handle(), |
| 343 "displaying-im-msg", >kwin32_handle, GAIM_CALLBACK(gtkwgaim_conv_im_blink), |
342 "displaying-im-msg", >kwin32_handle, GAIM_CALLBACK(winpidgin_conv_im_blink), |
| 344 NULL); |
343 NULL); |
| 345 |
344 |
| 346 } |
345 } |
| 347 |
346 |
| 348 /* Windows Cleanup */ |
347 /* Windows Cleanup */ |
| 349 |
348 |
| 350 void gtkwgaim_cleanup(void) { |
349 void winpidgin_cleanup(void) { |
| 351 gaim_debug_info("gtkwgaim", "gtkwgaim_cleanup\n"); |
350 gaim_debug_info("winpidgin", "winpidgin_cleanup\n"); |
| 352 |
351 |
| 353 if(messagewin_hwnd) |
352 if(messagewin_hwnd) |
| 354 DestroyWindow(messagewin_hwnd); |
353 DestroyWindow(messagewin_hwnd); |
| 355 |
354 |
| 356 /* Idle tracker cleanup */ |
355 /* Idle tracker cleanup */ |
| 357 wgaim_remove_idlehooks(); |
356 winpidgin_remove_idlehooks(); |
| 358 |
357 |
| 359 } |
358 } |
| 360 |
359 |
| 361 /* DLL initializer */ |
360 /* DLL initializer */ |
| 362 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { |
361 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { |
| 363 gtkgaimdll_hInstance = hinstDLL; |
362 dll_hInstance = hinstDLL; |
| 364 return TRUE; |
363 return TRUE; |
| 365 } |
364 } |
| 366 |
365 |
| 367 typedef HMONITOR WINAPI gaim_MonitorFromWindow(HWND, DWORD); |
366 typedef HMONITOR WINAPI _MonitorFromWindow(HWND, DWORD); |
| 368 typedef BOOL WINAPI gaim_GetMonitorInfo(HMONITOR, LPMONITORINFO); |
367 typedef BOOL WINAPI _GetMonitorInfo(HMONITOR, LPMONITORINFO); |
| 369 |
368 |
| 370 static gboolean |
369 static gboolean |
| 371 get_WorkingAreaRectForWindow(HWND hwnd, RECT *workingAreaRc) { |
370 get_WorkingAreaRectForWindow(HWND hwnd, RECT *workingAreaRc) { |
| 372 static gaim_MonitorFromWindow *the_MonitorFromWindow; |
371 static _MonitorFromWindow *the_MonitorFromWindow; |
| 373 static gaim_GetMonitorInfo *the_GetMonitorInfo; |
372 static _GetMonitorInfo *the_GetMonitorInfo; |
| 374 static gboolean initialized = FALSE; |
373 static gboolean initialized = FALSE; |
| 375 |
374 |
| 376 HMONITOR monitor; |
375 HMONITOR monitor; |
| 377 MONITORINFO info; |
376 MONITORINFO info; |
| 378 |
377 |
| 379 if(!initialized) { |
378 if(!initialized) { |
| 380 the_MonitorFromWindow = (gaim_MonitorFromWindow*) |
379 the_MonitorFromWindow = (_MonitorFromWindow*) |
| 381 wgaim_find_and_loadproc("user32", "MonitorFromWindow"); |
380 wgaim_find_and_loadproc("user32", "MonitorFromWindow"); |
| 382 the_GetMonitorInfo = (gaim_GetMonitorInfo*) |
381 the_GetMonitorInfo = (_GetMonitorInfo*) |
| 383 wgaim_find_and_loadproc("user32", "GetMonitorInfoA"); |
382 wgaim_find_and_loadproc("user32", "GetMonitorInfoA"); |
| 384 initialized = TRUE; |
383 initialized = TRUE; |
| 385 } |
384 } |
| 386 |
385 |
| 387 if(!the_MonitorFromWindow) |
386 if(!the_MonitorFromWindow) |