Mercurial > pidgin
comparison src/win32/systray.c @ 5376:a93c92572106
[gaim-migrate @ 5752]
Fix for freeze on startup.. errant g_free.
committer: Tailor Script <tailor@pidgin.im>
author | Herman Bloggs <hermanator12002@yahoo.com> |
---|---|
date | Thu, 15 May 2003 15:36:32 +0000 |
parents | fa63b4c784b9 |
children | fb0a5b872e6a |
comparison
equal
deleted
inserted
replaced
5375:d8ebee2f749c | 5376:a93c92572106 |
---|---|
57 static SYSTRAY_STATE st_state=SYSTRAY_STATE_OFFLINE; | 57 static SYSTRAY_STATE st_state=SYSTRAY_STATE_OFFLINE; |
58 static HMENU systray_menu=0; | 58 static HMENU systray_menu=0; |
59 static HMENU systray_away_menu=0; | 59 static HMENU systray_away_menu=0; |
60 /* UTF-8 to locale conversion */ | 60 /* UTF-8 to locale conversion */ |
61 gchar *locenc=NULL; | 61 gchar *locenc=NULL; |
62 static gsize bread=0; | |
63 static gsize bwrite=0; | |
64 | 62 |
65 /* | 63 /* |
66 * GLOBALS | 64 * GLOBALS |
67 */ | 65 */ |
68 extern GtkWidget *imaway; | 66 extern GtkWidget *imaway; |
98 systray_away_menu = 0; | 96 systray_away_menu = 0; |
99 } | 97 } |
100 systray_away_menu = CreatePopupMenu(); | 98 systray_away_menu = CreatePopupMenu(); |
101 while (awy && (item_count <= SYSTRAY_CMND_SET_AWY+MAX_AWY_MESSAGES)) { | 99 while (awy && (item_count <= SYSTRAY_CMND_SET_AWY+MAX_AWY_MESSAGES)) { |
102 a = (struct away_message *)awy->data; | 100 a = (struct away_message *)awy->data; |
103 locenc = g_locale_from_utf8(a->name, -1, &bread, &bwrite, NULL); | 101 locenc = g_locale_from_utf8(a->name, -1, NULL, NULL, NULL); |
104 AppendMenu(systray_away_menu, MF_STRING, item_count, locenc); | 102 AppendMenu(systray_away_menu, MF_STRING, item_count, locenc); |
105 g_free(locenc); | 103 g_free(locenc); |
106 awy = g_slist_next(awy); | 104 awy = g_slist_next(awy); |
107 item_count+=1; | 105 item_count+=1; |
108 } | 106 } |
109 AppendMenu(systray_away_menu, MF_SEPARATOR, 0, 0); | 107 AppendMenu(systray_away_menu, MF_SEPARATOR, 0, 0); |
110 locenc = g_locale_from_utf8(_("New"), -1, &bread, &bwrite, NULL); | 108 locenc = g_locale_from_utf8(_("New"), -1, NULL, NULL, NULL); |
111 AppendMenu(systray_away_menu, MF_STRING, SYSTRAY_CMND_SET_AWY_NEW, locenc); | 109 AppendMenu(systray_away_menu, MF_STRING, SYSTRAY_CMND_SET_AWY_NEW, locenc); |
112 g_free(locenc); | 110 g_free(locenc); |
113 return systray_away_menu; | 111 return systray_away_menu; |
114 } | 112 } |
115 | 113 |
121 /* Different menus depending on signed on/off state */ | 119 /* Different menus depending on signed on/off state */ |
122 if(connected) { | 120 if(connected) { |
123 /* If signoff item dosn't exist.. create it */ | 121 /* If signoff item dosn't exist.. create it */ |
124 if(!IsMenuItem(systray_menu, SYSTRAY_CMND_SIGNOFF)) { | 122 if(!IsMenuItem(systray_menu, SYSTRAY_CMND_SIGNOFF)) { |
125 DeleteMenu(systray_menu, SYSTRAY_CMND_SIGNON, MF_BYCOMMAND); | 123 DeleteMenu(systray_menu, SYSTRAY_CMND_SIGNON, MF_BYCOMMAND); |
126 locenc = g_locale_from_utf8(_("Signoff"), -1, &bread, &bwrite, NULL); | 124 locenc = g_locale_from_utf8(_("Signoff"), -1, NULL, NULL, NULL); |
127 InsertMenu(systray_menu, SYSTRAY_CMND_MENU_EXIT, | 125 InsertMenu(systray_menu, SYSTRAY_CMND_MENU_EXIT, |
128 MF_BYCOMMAND | MF_STRING, SYSTRAY_CMND_SIGNOFF, locenc); | 126 MF_BYCOMMAND | MF_STRING, SYSTRAY_CMND_SIGNOFF, locenc); |
129 g_free(locenc); | 127 g_free(locenc); |
130 } | 128 } |
131 /* if away menu exists, remove and rebuild it */ | 129 /* if away menu exists, remove and rebuild it */ |
132 if(systray_away_menu) { | 130 if(systray_away_menu) { |
133 if(!DeleteMenu(systray_menu, (UINT)systray_away_menu, MF_BYCOMMAND)) | 131 if(!DeleteMenu(systray_menu, (UINT)systray_away_menu, MF_BYCOMMAND)) |
134 debug_printf("Error using DeleteMenu\n"); | 132 debug_printf("Error using DeleteMenu\n"); |
135 } | 133 } |
136 locenc = g_locale_from_utf8(_("Set Away Message"), -1, &bread, &bwrite, NULL); | 134 locenc = g_locale_from_utf8(_("Set Away Message"), -1, NULL, NULL, NULL); |
137 InsertMenu(systray_menu, SYSTRAY_CMND_PREFS, | 135 InsertMenu(systray_menu, SYSTRAY_CMND_PREFS, |
138 MF_BYCOMMAND | MF_POPUP | MF_STRING, (UINT)systray_create_awy_menu(), | 136 MF_BYCOMMAND | MF_POPUP | MF_STRING, (UINT)systray_create_awy_menu(), |
139 locenc); | 137 locenc); |
140 g_free(locenc); | 138 g_free(locenc); |
141 EnableMenuItem(systray_menu, SYSTRAY_CMND_AUTOLOGIN, MF_GRAYED); | 139 EnableMenuItem(systray_menu, SYSTRAY_CMND_AUTOLOGIN, MF_GRAYED); |
142 /* If away, put "I'm Back" option in menu */ | 140 /* If away, put "I'm Back" option in menu */ |
143 if(st_state == SYSTRAY_STATE_AWAY) { | 141 if(st_state == SYSTRAY_STATE_AWAY) { |
144 if(!IsMenuItem(systray_menu, SYSTRAY_CMND_BACK)) { | 142 if(!IsMenuItem(systray_menu, SYSTRAY_CMND_BACK)) { |
145 locenc = g_locale_from_utf8(_("I'm Back"), -1, &bread, &bwrite, NULL); | 143 locenc = g_locale_from_utf8(_("I'm Back"), -1, NULL, NULL, NULL); |
146 InsertMenu(systray_menu, (UINT)systray_away_menu, | 144 InsertMenu(systray_menu, (UINT)systray_away_menu, |
147 MF_BYCOMMAND | MF_STRING, SYSTRAY_CMND_BACK, | 145 MF_BYCOMMAND | MF_STRING, SYSTRAY_CMND_BACK, |
148 locenc); | 146 locenc); |
149 g_free(locenc); | 147 g_free(locenc); |
150 } | 148 } |
154 } | 152 } |
155 } else { | 153 } else { |
156 /* If signon item dosn't exist.. create it */ | 154 /* If signon item dosn't exist.. create it */ |
157 if(!IsMenuItem(systray_menu, SYSTRAY_CMND_SIGNON)) { | 155 if(!IsMenuItem(systray_menu, SYSTRAY_CMND_SIGNON)) { |
158 DeleteMenu(systray_menu, SYSTRAY_CMND_SIGNOFF, MF_BYCOMMAND); | 156 DeleteMenu(systray_menu, SYSTRAY_CMND_SIGNOFF, MF_BYCOMMAND); |
159 locenc = g_locale_from_utf8(_("Sign On"), -1, &bread, &bwrite, NULL); | 157 locenc = g_locale_from_utf8(_("Sign On"), -1, NULL, NULL, NULL); |
160 InsertMenu(systray_menu, SYSTRAY_CMND_MENU_EXIT, | 158 InsertMenu(systray_menu, SYSTRAY_CMND_MENU_EXIT, |
161 MF_BYCOMMAND | MF_STRING, SYSTRAY_CMND_SIGNON, locenc); | 159 MF_BYCOMMAND | MF_STRING, SYSTRAY_CMND_SIGNON, locenc); |
162 g_free(locenc); | 160 g_free(locenc); |
163 } | 161 } |
164 EnableMenuItem(systray_menu, SYSTRAY_CMND_AUTOLOGIN, MF_ENABLED); | 162 EnableMenuItem(systray_menu, SYSTRAY_CMND_AUTOLOGIN, MF_ENABLED); |
306 | 304 |
307 static void systray_create_menu(void) { | 305 static void systray_create_menu(void) { |
308 /* create popup menu */ | 306 /* create popup menu */ |
309 if((systray_menu = CreatePopupMenu())) { | 307 if((systray_menu = CreatePopupMenu())) { |
310 if(!AppendMenu(systray_menu, MF_STRING, SYSTRAY_CMND_PREFS, | 308 if(!AppendMenu(systray_menu, MF_STRING, SYSTRAY_CMND_PREFS, |
311 (locenc=g_locale_from_utf8(_("Preferences"), -1, &bread, &bwrite, NULL)))) | 309 (locenc=g_locale_from_utf8(_("Preferences"), -1, NULL, NULL, NULL)))) |
312 debug_printf("AppendMenu error: %ld\n", GetLastError()); | 310 debug_printf("AppendMenu error: %ld\n", GetLastError()); |
313 g_free(locenc); | 311 g_free(locenc); |
314 if(!AppendMenu(systray_menu, MF_STRING, SYSTRAY_CMND_AUTOLOGIN, | 312 if(!AppendMenu(systray_menu, MF_STRING, SYSTRAY_CMND_AUTOLOGIN, |
315 (locenc=g_locale_from_utf8(_("Auto-login"), -1, &bread, &bwrite, NULL)))) | 313 (locenc=g_locale_from_utf8(_("Auto-login"), -1, NULL, NULL, NULL)))) |
316 debug_printf("AppendMenu error: %ld\n", GetLastError()); | 314 debug_printf("AppendMenu error: %ld\n", GetLastError()); |
317 g_free(locenc); | 315 g_free(locenc); |
318 if(!AppendMenu(systray_menu, MF_SEPARATOR, 0, 0)) | 316 if(!AppendMenu(systray_menu, MF_SEPARATOR, 0, 0)) |
319 debug_printf("AppendMenu error: %ld\n", GetLastError()); | 317 debug_printf("AppendMenu error: %ld\n", GetLastError()); |
320 g_free(locenc); | |
321 if(!AppendMenu(systray_menu, MF_STRING, SYSTRAY_CMND_MENU_EXIT, | 318 if(!AppendMenu(systray_menu, MF_STRING, SYSTRAY_CMND_MENU_EXIT, |
322 (locenc=g_locale_from_utf8(_("Exit"), -1, &bread, &bwrite, NULL)))) | 319 (locenc=g_locale_from_utf8(_("Exit"), -1, NULL, NULL, NULL)))) |
323 debug_printf("AppendMenu error: %ld\n", GetLastError()); | 320 debug_printf("AppendMenu error: %ld\n", GetLastError()); |
324 g_free(locenc); | 321 g_free(locenc); |
325 } else | 322 } else |
326 debug_printf("CreatePopupMenu error: %ld\n", GetLastError()); | 323 debug_printf("CreatePopupMenu error: %ld\n", GetLastError()); |
327 } | 324 } |
332 wgaim_nid.hWnd=hWnd; | 329 wgaim_nid.hWnd=hWnd; |
333 wgaim_nid.uID=0; | 330 wgaim_nid.uID=0; |
334 wgaim_nid.uFlags=NIF_ICON | NIF_MESSAGE | NIF_TIP; | 331 wgaim_nid.uFlags=NIF_ICON | NIF_MESSAGE | NIF_TIP; |
335 wgaim_nid.uCallbackMessage=WM_TRAYMESSAGE; | 332 wgaim_nid.uCallbackMessage=WM_TRAYMESSAGE; |
336 wgaim_nid.hIcon=icon; | 333 wgaim_nid.hIcon=icon; |
337 locenc=g_locale_from_utf8(GAIM_SYSTRAY_DISCONN_HINT, -1, &bread, &bwrite, NULL); | 334 locenc=g_locale_from_utf8(GAIM_SYSTRAY_DISCONN_HINT, -1, NULL, NULL, NULL); |
338 strcpy(wgaim_nid.szTip, locenc); | 335 strcpy(wgaim_nid.szTip, locenc); |
339 g_free(locenc); | 336 g_free(locenc); |
340 Shell_NotifyIcon(NIM_ADD,&wgaim_nid); | 337 Shell_NotifyIcon(NIM_ADD,&wgaim_nid); |
341 } | 338 } |
342 | 339 |
343 static void systray_change_icon(HICON icon, char* text) { | 340 static void systray_change_icon(HICON icon, char* text) { |
344 wgaim_nid.hIcon = icon; | 341 wgaim_nid.hIcon = icon; |
345 locenc = g_locale_from_utf8(text, -1, &bread, &bwrite, NULL); | 342 locenc = g_locale_from_utf8(text, -1, NULL, NULL, NULL); |
346 lstrcpy(wgaim_nid.szTip, locenc); | 343 lstrcpy(wgaim_nid.szTip, locenc); |
347 g_free(locenc); | 344 g_free(locenc); |
348 Shell_NotifyIcon(NIM_MODIFY,&wgaim_nid); | 345 Shell_NotifyIcon(NIM_MODIFY,&wgaim_nid); |
349 } | 346 } |
350 | 347 |