comparison gtk/win32/gtkwin32dep.c @ 14257:14933d9055a0

[gaim-migrate @ 16939] When a second instance of wingaim is started, bring the Buddy List into focus instead of popping up the "Already Running" message (if we can). committer: Tailor Script <tailor@pidgin.im>
author Daniel Atallah <daniel.atallah@gmail.com>
date Mon, 21 Aug 2006 04:06:33 +0000
parents ab8a105eff62
children 333989477bcd
comparison
equal deleted inserted replaced
14256:e7de1f6d9f35 14257:14933d9055a0
51 /* 51 /*
52 * GLOBALS 52 * GLOBALS
53 */ 53 */
54 HINSTANCE gaimexe_hInstance = 0; 54 HINSTANCE gaimexe_hInstance = 0;
55 HINSTANCE gtkgaimdll_hInstance = 0; 55 HINSTANCE gtkgaimdll_hInstance = 0;
56 HWND messagewin_hwnd;
56 57
57 /* 58 /*
58 * PUBLIC CODE 59 * PUBLIC CODE
59 */ 60 */
60 61
68 char buf[1024]; 69 char buf[1024];
69 int ret; 70 int ret;
70 71
71 if((fin = gzopen(in, "rb"))) { 72 if((fin = gzopen(in, "rb"))) {
72 if(!(fout = g_fopen(out, "wb"))) { 73 if(!(fout = g_fopen(out, "wb"))) {
73 gaim_debug(GAIM_DEBUG_ERROR, "wgaim_gz_decompress", "Error opening file: %s\n", out); 74 gaim_debug_error("gtkwgaim_gz_decompress", "Error opening file: %s\n", out);
74 gzclose(fin); 75 gzclose(fin);
75 return 0; 76 return 0;
76 } 77 }
77 } 78 }
78 else { 79 else {
79 gaim_debug(GAIM_DEBUG_ERROR, "wgaim_gz_decompress", "gzopen failed to open: %s\n", in); 80 gaim_debug_error("gtkwgaim_gz_decompress", "gzopen failed to open: %s\n", in);
80 return 0; 81 return 0;
81 } 82 }
82 83
83 while((ret = gzread(fin, buf, 1024))) { 84 while((ret = gzread(fin, buf, 1024))) {
84 if(fwrite(buf, 1, ret, fout) < ret) { 85 if(fwrite(buf, 1, ret, fout) < ret) {
85 gaim_debug(GAIM_DEBUG_ERROR, "wgaim_gz_decompress", "Error writing %d bytes to file\n", ret); 86 gaim_debug_error("wgaim_gz_decompress", "Error writing %d bytes to file\n", ret);
86 gzclose(fin); 87 gzclose(fin);
87 fclose(fout); 88 fclose(fout);
88 return 0; 89 return 0;
89 } 90 }
90 } 91 }
91 fclose(fout); 92 fclose(fout);
92 gzclose(fin); 93 gzclose(fin);
93 94
94 if(ret < 0) { 95 if(ret < 0) {
95 gaim_debug(GAIM_DEBUG_ERROR, "wgaim_gz_decompress", "gzread failed while reading: %s\n", in); 96 gaim_debug_error("gtkwgaim_gz_decompress", "gzread failed while reading: %s\n", in);
96 return 0; 97 return 0;
97 } 98 }
98 99
99 return 1; 100 return 1;
100 } 101 }
107 if(gtkwgaim_gz_decompress(filename, tmpfile)) { 108 if(gtkwgaim_gz_decompress(filename, tmpfile)) {
108 int ret; 109 int ret;
109 if(untar(tmpfile, destdir, UNTAR_FORCE | UNTAR_QUIET)) 110 if(untar(tmpfile, destdir, UNTAR_FORCE | UNTAR_QUIET))
110 ret = 1; 111 ret = 1;
111 else { 112 else {
112 gaim_debug(GAIM_DEBUG_ERROR, "wgaim_gz_untar", "Failure untaring %s\n", tmpfile); 113 gaim_debug_error("gtkwgaim_gz_untar", "Failure untaring %s\n", tmpfile);
113 ret = 0; 114 ret = 0;
114 } 115 }
115 g_unlink(tmpfile); 116 g_unlink(tmpfile);
116 return ret; 117 return ret;
117 } 118 }
118 else { 119 else {
119 gaim_debug(GAIM_DEBUG_ERROR, "wgaim_gz_untar", "Failed to gz decompress %s\n", filename); 120 gaim_debug_error("gtkwgaim_gz_untar", "Failed to gz decompress %s\n", filename);
120 return 0; 121 return 0;
121 } 122 }
122 } 123 }
123 124
124 void gtkwgaim_notify_uri(const char *uri) { 125 void gtkwgaim_notify_uri(const char *uri) {
139 wsinfo.lpVerb = L"open"; 140 wsinfo.lpVerb = L"open";
140 wsinfo.lpFile = w_uri; 141 wsinfo.lpFile = w_uri;
141 wsinfo.nShow = SW_SHOWNORMAL; 142 wsinfo.nShow = SW_SHOWNORMAL;
142 wsinfo.lpClass = L"http"; 143 wsinfo.lpClass = L"http";
143 144
144 gaim_debug(GAIM_DEBUG_INFO, "wgaim_notify_uri", "The wide uri is %s\n", uri);
145 if(!ShellExecuteExW(&wsinfo)) 145 if(!ShellExecuteExW(&wsinfo))
146 gaim_debug_error("wgaim", "Error opening URI: %s error: %d\n", 146 gaim_debug_error("gtkwgaim", "Error opening URI: %s error: %d\n",
147 uri, (int) wsinfo.hInstApp); 147 uri, (int) wsinfo.hInstApp);
148 148
149 g_free(w_uri); 149 g_free(w_uri);
150 } else { 150 } else {
151 SHELLEXECUTEINFOA sinfo; 151 SHELLEXECUTEINFOA sinfo;
160 sinfo.lpFile = locale_uri; 160 sinfo.lpFile = locale_uri;
161 sinfo.nShow = SW_SHOWNORMAL; 161 sinfo.nShow = SW_SHOWNORMAL;
162 sinfo.lpClass = "http"; 162 sinfo.lpClass = "http";
163 163
164 if(!ShellExecuteExA(&sinfo)) 164 if(!ShellExecuteExA(&sinfo))
165 gaim_debug_error("wgaim", "Error opening URI: %s error: %d\n", 165 gaim_debug_error("gtkwgaim", "Error opening URI: %s error: %d\n",
166 uri, (int) sinfo.hInstApp); 166 uri, (int) sinfo.hInstApp);
167 167
168 g_free(locale_uri); 168 g_free(locale_uri);
169 } 169 }
170 } 170 }
171
172 #define WM_FOCUS_REQUEST (WM_APP + 13)
173
174 static LRESULT CALLBACK message_window_handler(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
175
176 if (msg == WM_FOCUS_REQUEST) {
177 gaim_debug_info("gtkwgaim", "Got external Buddy List focus request.");
178 gaim_blist_set_visible(TRUE);
179 return TRUE;
180 }
181
182 return DefWindowProc(hwnd, msg, wparam, lparam);
183 }
184
185 static HWND wgaim_message_window_init(void) {
186 HWND win_hwnd;
187 WNDCLASSEX wcx;
188 LPCTSTR wname;
189
190 wname = TEXT("WingaimMsgWinCls");
191
192 wcx.cbSize = sizeof(wcx);
193 wcx.style = 0;
194 wcx.lpfnWndProc = message_window_handler;
195 wcx.cbClsExtra = 0;
196 wcx.cbWndExtra = 0;
197 wcx.hInstance = gtkwgaim_hinstance();
198 wcx.hIcon = NULL;
199 wcx.hCursor = NULL;
200 wcx.hbrBackground = NULL;
201 wcx.lpszMenuName = NULL;
202 wcx.lpszClassName = wname;
203 wcx.hIconSm = NULL;
204
205 RegisterClassEx(&wcx);
206
207 /* Create the window */
208 if(!(win_hwnd = CreateWindow(wname, TEXT("WingaimMsgWin"), 0, 0, 0, 0, 0,
209 NULL, NULL, gtkwgaim_hinstance(), 0))) {
210 gaim_debug_error("gtkwgaim",
211 "Unable to create message window.\n");
212 return NULL;
213 }
214
215 return win_hwnd;
216 }
217
171 218
172 void gtkwgaim_init(HINSTANCE hint) { 219 void gtkwgaim_init(HINSTANCE hint) {
173 gaim_debug_info("gtkwgaim", "gtkwgaim_init start\n"); 220 gaim_debug_info("gtkwgaim", "gtkwgaim_init start\n");
174 221
175 gaimexe_hInstance = hint; 222 gaimexe_hInstance = hint;
176 223
177 /* IdleTracker Initialization */ 224 /* IdleTracker Initialization */
178 if(!wgaim_set_idlehooks()) 225 if(!wgaim_set_idlehooks())
179 gaim_debug(GAIM_DEBUG_ERROR, "gtkwgaim", "Failed to initialize idle tracker\n"); 226 gaim_debug_error("gtkwgaim", "Failed to initialize idle tracker\n");
180 227
181 wgaim_gtkspell_init(); 228 wgaim_gtkspell_init();
182 gaim_debug_info("gtkwgaim", "GTK+ :%u.%u.%u\n", 229 gaim_debug_info("gtkwgaim", "GTK+ :%u.%u.%u\n",
183 gtk_major_version, gtk_minor_version, gtk_micro_version); 230 gtk_major_version, gtk_minor_version, gtk_micro_version);
184 231
185 gaim_debug(GAIM_DEBUG_INFO, "gtkwgaim", "gtkwgaim_init end\n"); 232 messagewin_hwnd = wgaim_message_window_init();
233
234 gaim_debug_info("gtkwgaim", "gtkwgaim_init end\n");
186 } 235 }
187 236
188 /* Windows Cleanup */ 237 /* Windows Cleanup */
189 238
190 void gtkwgaim_cleanup(void) { 239 void gtkwgaim_cleanup(void) {
191 gaim_debug(GAIM_DEBUG_INFO, "gtkwgaim", "gtkwgaim_cleanup\n"); 240 gaim_debug_info("gtkwgaim", "gtkwgaim_cleanup\n");
241
242 if(messagewin_hwnd)
243 DestroyWindow(messagewin_hwnd);
192 244
193 /* Idle tracker cleanup */ 245 /* Idle tracker cleanup */
194 wgaim_remove_idlehooks(); 246 wgaim_remove_idlehooks();
195 247
196 } 248 }