# HG changeset patch # User Daniel Atallah # Date 1197592888 0 # Node ID 85fcbd3b9d32b0fe33f10ead169153ed8cfb5bb4 # Parent f123ad1ada0073d12f344d0195ca305f0723bd40 This is a great patch from Lee Roach to make Pidgin on win32 deal with system suspend / resume. It seems to work really well, hopefully this'll make some folks happy. If something doesn't work right, it is probably my fault. Fixes #480. diff -r f123ad1ada00 -r 85fcbd3b9d32 pidgin/win32/gtkwin32dep.c --- a/pidgin/win32/gtkwin32dep.c Fri Dec 14 00:38:22 2007 +0000 +++ b/pidgin/win32/gtkwin32dep.c Fri Dec 14 00:41:28 2007 +0000 @@ -40,6 +40,7 @@ #include "debug.h" #include "notify.h" +#include "network.h" #include "resource.h" #include "idletrack.h" @@ -51,6 +52,7 @@ #include "gtkwin32dep.h" #include "win32dep.h" #include "gtkconv.h" +#include "gtkconn.h" #include "util.h" #include "wspell.h" @@ -64,6 +66,7 @@ typedef BOOL (CALLBACK* LPFNFLASHWINDOWEX)(PFLASHWINFO); static LPFNFLASHWINDOWEX MyFlashWindowEx = NULL; +static gboolean pwm_handles_connections = TRUE; /* @@ -202,6 +205,43 @@ #define PIDGIN_WM_FOCUS_REQUEST (WM_APP + 13) #define PIDGIN_WM_PROTOCOL_HANDLE (WM_APP + 14) +static void* +winpidgin_netconfig_changed_cb(void *data) +{ + pwm_handles_connections = FALSE; + + return NULL; +} + +static void* +winpidgin_get_handle(void) +{ + static int handle; + + return &handle; +} + +static gboolean +winpidgin_pwm_reconnect() +{ + purple_signal_disconnect(purple_network_get_handle(), "network-configuration-changed", + winpidgin_get_handle(), PURPLE_CALLBACK(winpidgin_netconfig_changed_cb)); + + if (pwm_handles_connections == TRUE) { + PurpleConnectionUiOps *ui_ops = pidgin_connections_get_ui_ops(); + + purple_debug_info("winpidgin", "Resumed from standby, reconnecting accounts.\n"); + + if (ui_ops != NULL && ui_ops->network_connected != NULL) + ui_ops->network_connected(); + } else { + purple_debug_info("winpidgin", "Resumed from standby, gtkconn will handle reconnecting.\n"); + pwm_handles_connections = TRUE; + } + + return FALSE; +} + static LRESULT CALLBACK message_window_handler(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { if (msg == PIDGIN_WM_FOCUS_REQUEST) { @@ -213,6 +253,28 @@ purple_debug_info("winpidgin", "Got protocol handler request: %s\n", proto_msg ? proto_msg : ""); purple_got_protocol_handler_uri(proto_msg); return TRUE; + } else if (msg == WM_POWERBROADCAST) { + if (wparam == PBT_APMQUERYSUSPEND) { + purple_debug_info("winpidgin", "Windows requesting permission to suspend.\n"); + return TRUE; + } else if (wparam == PBT_APMSUSPEND) { + PurpleConnectionUiOps *ui_ops = pidgin_connections_get_ui_ops(); + + purple_debug_info("winpidgin", "Entering system standby, disconnecting accounts.\n"); + + if (ui_ops != NULL && ui_ops->network_disconnected != NULL) + ui_ops->network_disconnected(); + + purple_signal_connect(purple_network_get_handle(), "network-configuration-changed", winpidgin_get_handle(), + PURPLE_CALLBACK(winpidgin_netconfig_changed_cb), NULL); + + return TRUE; + } else if (wparam == PBT_APMRESUMESUSPEND) { + purple_debug_info("winpidgin", "Resuming from system standby.\n"); + /* TODO: It seems like it'd be wise to use the NLA message, if possible, instead of this. */ + purple_timeout_add_seconds(1, winpidgin_pwm_reconnect, NULL); + return TRUE; + } } return DefWindowProc(hwnd, msg, wparam, lparam); @@ -242,7 +304,7 @@ /* Create the window */ if(!(win_hwnd = CreateWindow(wname, TEXT("WinpidginMsgWin"), 0, 0, 0, 0, 0, - HWND_MESSAGE, NULL, winpidgin_exe_hinstance(), 0))) { + NULL, NULL, winpidgin_exe_hinstance(), 0))) { purple_debug_error("winpidgin", "Unable to create message window.\n"); return NULL;