Mercurial > pidgin.yaz
comparison plugins/win32/winprefs/winprefs.c @ 6409:752d0600b514
[gaim-migrate @ 6915]
Blist can now be docked, using Windows appbar features
committer: Tailor Script <tailor@pidgin.im>
author | Herman Bloggs <hermanator12002@yahoo.com> |
---|---|
date | Fri, 08 Aug 2003 01:05:03 +0000 |
parents | 5239a3b4ab33 |
children | 759a81390b36 |
comparison
equal
deleted
inserted
replaced
6408:90fc2199c156 | 6409:752d0600b514 |
---|---|
1 /* | 1 /* |
2 * winprefs.c | 2 * gaim - WinGaim Options Plugin |
3 * | 3 * |
4 * copyright (c) 1998-2002, Herman Bloggs <hermanator12002@yahoo.com> | 4 * File: winprefs.c |
5 * Date: December 12, 2002 | |
6 * Description: Gaim Plugin interface | |
7 * | |
8 * copyright (c) 2002-2003, Herman Bloggs <hermanator12002@yahoo.com> | |
5 * | 9 * |
6 * this program is free software; you can redistribute it and/or modify | 10 * this program is free software; you can redistribute it and/or modify |
7 * it under the terms of the gnu general public license as published by | 11 * it under the terms of the gnu general public license as published by |
8 * the free software foundation; either version 2 of the license, or | 12 * the free software foundation; either version 2 of the license, or |
9 * (at your option) any later version. | 13 * (at your option) any later version. |
19 * | 23 * |
20 */ | 24 */ |
21 #include <windows.h> | 25 #include <windows.h> |
22 #include <winreg.h> | 26 #include <winreg.h> |
23 #include <winerror.h> | 27 #include <winerror.h> |
28 #include <gdk/gdkwin32.h> | |
24 | 29 |
25 #include "internal.h" | 30 #include "internal.h" |
31 #include "gtkinternal.h" | |
26 | 32 |
27 #include "prefs.h" | 33 #include "prefs.h" |
28 #include "debug.h" | 34 #include "debug.h" |
29 | 35 |
30 #include "gtkplugin.h" | 36 #include "gtkplugin.h" |
31 #include "gtkutils.h" | 37 #include "gtkutils.h" |
38 #include "gtkblist.h" | |
39 #include "gtkappbar.h" | |
32 | 40 |
33 /* | 41 /* |
34 * MACROS & DEFINES | 42 * MACROS & DEFINES |
35 */ | 43 */ |
36 #define WINPREFS_PLUGIN_ID "gtk-win-prefs" | 44 #define WINPREFS_PLUGIN_ID "gtk-win-prefs" |
37 #define WINPREFS_VERSION 1 | |
38 | 45 |
39 /* | 46 /* |
40 * LOCALS | 47 * LOCALS |
41 */ | 48 */ |
42 static const char *OPT_WINPREFS_AUTOSTART="/plugins/gtk/win32/winprefs/auto_start"; | 49 static const char *OPT_WINPREFS_DBLIST_DOCKABLE = "/plugins/gtk/win32/winprefs/dblist_dockable"; |
50 static const char *OPT_WINPREFS_DBLIST_DOCKED = "/plugins/gtk/win32/winprefs/dblist_docked"; | |
51 static const char *OPT_WINPREFS_DBLIST_HEIGHT = "/plugins/gtk/win32/winprefs/dblist_height"; | |
52 static const char *OPT_WINPREFS_DBLIST_SIDE = "/plugins/gtk/win32/winprefs/dblist_side"; | |
53 static GaimPlugin *plugin_id = NULL; | |
54 static GtkAppBar *blist_ab = NULL; | |
55 static GtkWidget *blist = NULL; | |
43 | 56 |
44 /* | 57 /* |
45 * PROTOS | 58 * PROTOS |
46 */ | 59 */ |
60 static void blist_create_cb(); | |
47 | 61 |
48 /* | 62 /* |
49 * CODE | 63 * CODE |
50 */ | 64 */ |
51 | 65 |
52 static GtkWidget *wgaim_button(const char *text, const char *pref, GtkWidget *page) { | 66 /* UTIL */ |
67 | |
68 static GtkWidget *wgaim_button(const char *text, GtkWidget *page) { | |
53 GtkWidget *button; | 69 GtkWidget *button; |
54 button = gtk_check_button_new_with_mnemonic(text); | 70 button = gtk_check_button_new_with_mnemonic(text); |
55 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), gaim_prefs_get_bool(pref)); | |
56 gtk_box_pack_start(GTK_BOX(page), button, FALSE, FALSE, 0); | 71 gtk_box_pack_start(GTK_BOX(page), button, FALSE, FALSE, 0); |
57 gtk_widget_show(button); | 72 gtk_widget_show(button); |
58 return button; | 73 return button; |
59 } | 74 } |
75 | |
76 /* BLIST DOCKING */ | |
77 | |
78 static void blist_save_state() { | |
79 if(blist_ab && gaim_prefs_get_bool(OPT_WINPREFS_DBLIST_DOCKABLE)) { | |
80 if(blist_ab->docked) { | |
81 gaim_prefs_set_int(OPT_WINPREFS_DBLIST_HEIGHT, blist_ab->undocked_height); | |
82 gaim_prefs_set_int(OPT_WINPREFS_DBLIST_SIDE, blist_ab->side); | |
83 } | |
84 gaim_prefs_set_bool(OPT_WINPREFS_DBLIST_DOCKED, blist_ab->docked); | |
85 } | |
86 else | |
87 gaim_prefs_set_bool(OPT_WINPREFS_DBLIST_DOCKED, FALSE); | |
88 } | |
89 | |
90 static void blist_set_dockable(gboolean val) { | |
91 if(val) { | |
92 if(!blist_ab && blist) | |
93 blist_ab = gtk_appbar_add(blist); | |
94 } | |
95 else { | |
96 gtk_appbar_remove(blist_ab); | |
97 blist_ab = NULL; | |
98 } | |
99 } | |
100 | |
101 static void gaim_quit_cb() { | |
102 gaim_debug(GAIM_DEBUG_INFO, WINPREFS_PLUGIN_ID, "gaim_quit_cb: removing appbar\n"); | |
103 blist_save_state(); | |
104 blist_set_dockable(FALSE); | |
105 } | |
106 | |
107 static gboolean blist_create_cb_remove(gpointer data) { | |
108 gaim_signal_disconnect(plugin_id, event_signon, blist_create_cb); | |
109 return FALSE; | |
110 } | |
111 | |
112 static void blist_create_cb() { | |
113 gaim_debug(GAIM_DEBUG_INFO, WINPREFS_PLUGIN_ID, "event_signon\n"); | |
114 | |
115 blist = GAIM_GTK_BLIST(gaim_get_blist())->window; | |
116 if(gaim_prefs_get_bool(OPT_WINPREFS_DBLIST_DOCKABLE)) { | |
117 blist_set_dockable(TRUE); | |
118 if(gaim_prefs_get_bool(OPT_WINPREFS_DBLIST_DOCKED)) { | |
119 blist_ab->undocked_height = gaim_prefs_get_int(OPT_WINPREFS_DBLIST_HEIGHT); | |
120 gtk_appbar_dock(blist_ab, | |
121 gaim_prefs_get_int(OPT_WINPREFS_DBLIST_SIDE)); | |
122 } | |
123 } | |
124 /* removing here will cause a crash when going to next cb | |
125 in the gaim signal cb loop.. so process delayed. */ | |
126 g_idle_add(blist_create_cb_remove, NULL); | |
127 } | |
128 | |
129 | |
130 /* AUTOSTART */ | |
60 | 131 |
61 static int open_run_key(PHKEY phKey, REGSAM samDesired) { | 132 static int open_run_key(PHKEY phKey, REGSAM samDesired) { |
62 /* First try current user key (for WinNT & Win2k +), fall back to local machine */ | 133 /* First try current user key (for WinNT & Win2k +), fall back to local machine */ |
63 if(ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER, | 134 if(ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER, |
64 "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", | 135 "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", |
71 return 0; | 142 return 0; |
72 } | 143 } |
73 return 1; | 144 return 1; |
74 } | 145 } |
75 | 146 |
76 static void set_winprefs_option(GtkWidget *w, const char *key) { | 147 /* WIN PREFS GENERAL */ |
77 gaim_prefs_set_bool(key, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w))); | 148 |
78 if(key == OPT_WINPREFS_AUTOSTART) { | 149 static void winprefs_set_autostart(GtkWidget *w) { |
79 HKEY hKey; | 150 HKEY hKey; |
80 | 151 |
81 if(!open_run_key(&hKey, KEY_SET_VALUE)) | 152 if(!open_run_key(&hKey, KEY_SET_VALUE)) |
82 return; | 153 return; |
83 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w))) { | 154 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w))) { |
84 char buffer[1024]; | 155 char buffer[1024]; |
85 DWORD size; | 156 DWORD size; |
86 | 157 |
87 if((size = GetModuleFileName(wgaim_hinstance(), | 158 if((size = GetModuleFileName(wgaim_hinstance(), |
88 (LPBYTE)buffer, | 159 (LPBYTE)buffer, |
89 sizeof(buffer)))==0) { | 160 sizeof(buffer)))==0) { |
90 gaim_debug(GAIM_DEBUG_ERROR, WINPREFS_PLUGIN_ID, "GetModuleFileName Error.. Could not set Gaim autostart.\n"); | 161 gaim_debug(GAIM_DEBUG_ERROR, WINPREFS_PLUGIN_ID, "GetModuleFileName Error.. Could not set Gaim autostart.\n"); |
91 RegCloseKey(hKey); | 162 RegCloseKey(hKey); |
92 return; | 163 return; |
93 } | 164 } |
94 /* Now set value of new key */ | 165 /* Now set value of new key */ |
95 if(ERROR_SUCCESS != RegSetValueEx(hKey, | 166 if(ERROR_SUCCESS != RegSetValueEx(hKey, |
96 "Gaim", | 167 "Gaim", |
97 0, | 168 0, |
98 REG_SZ, | 169 REG_SZ, |
99 buffer, | 170 buffer, |
100 size)) | 171 size)) |
101 gaim_debug(GAIM_DEBUG_ERROR, WINPREFS_PLUGIN_ID, "Could not set registry key value\n"); | 172 gaim_debug(GAIM_DEBUG_ERROR, WINPREFS_PLUGIN_ID, "Could not set registry key value\n"); |
102 } | 173 } |
103 else { | 174 else { |
104 if(ERROR_SUCCESS != RegDeleteValue(hKey, "Gaim")) | 175 if(ERROR_SUCCESS != RegDeleteValue(hKey, "Gaim")) |
105 gaim_debug(GAIM_DEBUG_ERROR, WINPREFS_PLUGIN_ID, "Could not delete registry key value\n"); | 176 gaim_debug(GAIM_DEBUG_ERROR, WINPREFS_PLUGIN_ID, "Could not delete registry key value\n"); |
106 } | 177 } |
107 RegCloseKey(hKey); | 178 RegCloseKey(hKey); |
108 } | 179 } |
109 } | 180 |
181 static void winprefs_set_blist_dockable(GtkWidget *w) { | |
182 gaim_prefs_set_bool(OPT_WINPREFS_DBLIST_DOCKABLE, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w))); | |
183 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w)) ? blist_set_dockable(TRUE) : blist_set_dockable(FALSE); | |
184 } | |
185 | |
110 | 186 |
111 /* | 187 /* |
112 * EXPORTED FUNCTIONS | 188 * EXPORTED FUNCTIONS |
113 */ | 189 */ |
190 | |
191 gboolean plugin_load(GaimPlugin *plugin) { | |
192 plugin_id = plugin; | |
193 | |
194 /* blist docking init */ | |
195 if(!blist && gaim_get_blist() && GAIM_GTK_BLIST(gaim_get_blist())) { | |
196 blist = GAIM_GTK_BLIST(gaim_get_blist())->window; | |
197 if(gaim_prefs_get_bool(OPT_WINPREFS_DBLIST_DOCKABLE)) | |
198 blist_set_dockable(TRUE); | |
199 } | |
200 else | |
201 gaim_signal_connect(plugin, event_signon, blist_create_cb, NULL); | |
202 | |
203 gaim_signal_connect(plugin, event_quit, gaim_quit_cb, NULL); | |
204 | |
205 return TRUE; | |
206 } | |
207 | |
208 gboolean plugin_unload(GaimPlugin *plugin) { | |
209 blist_set_dockable(FALSE); | |
210 return TRUE; | |
211 } | |
212 | |
114 static GtkWidget* get_config_frame(GaimPlugin *plugin) { | 213 static GtkWidget* get_config_frame(GaimPlugin *plugin) { |
115 GtkWidget *ret; | 214 GtkWidget *ret; |
116 GtkWidget *button; | 215 GtkWidget *button; |
117 GtkWidget *vbox; | 216 GtkWidget *vbox; |
118 HKEY hKey; | 217 HKEY hKey; |
119 | 218 |
120 ret = gtk_vbox_new(FALSE, 18); | 219 ret = gtk_vbox_new(FALSE, 18); |
121 gtk_container_set_border_width (GTK_CONTAINER (ret), 12); | 220 gtk_container_set_border_width (GTK_CONTAINER (ret), 12); |
122 | 221 |
123 /* IM Convo trans options */ | |
124 vbox = gaim_gtk_make_frame (ret, _("Startup")); | 222 vbox = gaim_gtk_make_frame (ret, _("Startup")); |
125 button = wgaim_button(_("_Start Gaim on Windows startup"), OPT_WINPREFS_AUTOSTART, vbox); | 223 |
126 /* Set initial value */ | 224 /* Autostart */ |
225 button = wgaim_button(_("_Start Gaim on Windows startup"), vbox); | |
127 if(open_run_key(&hKey, KEY_QUERY_VALUE)) { | 226 if(open_run_key(&hKey, KEY_QUERY_VALUE)) { |
128 if(ERROR_SUCCESS == RegQueryValueEx(hKey, "Gaim", 0, NULL, NULL, NULL)) { | 227 if(ERROR_SUCCESS == RegQueryValueEx(hKey, "Gaim", 0, NULL, NULL, NULL)) { |
129 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE); | 228 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE); |
130 } | 229 } |
131 } | 230 } |
132 gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(set_winprefs_option), (void *)OPT_WINPREFS_AUTOSTART); | 231 gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(winprefs_set_autostart), NULL); |
232 | |
233 /* Dockable Blist */ | |
234 button = wgaim_button(_("_Dockable Buddy List"), vbox); | |
235 gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(winprefs_set_blist_dockable), NULL); | |
236 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), gaim_prefs_get_bool(OPT_WINPREFS_DBLIST_DOCKABLE)); | |
133 | 237 |
134 gtk_widget_show_all(ret); | 238 gtk_widget_show_all(ret); |
135 return ret; | 239 return ret; |
136 } | 240 } |
137 | 241 |
152 N_("WinGaim Options"), | 256 N_("WinGaim Options"), |
153 VERSION, | 257 VERSION, |
154 N_("Options specific to Windows Gaim."), | 258 N_("Options specific to Windows Gaim."), |
155 N_("Options specific to Windows Gaim."), | 259 N_("Options specific to Windows Gaim."), |
156 "Herman Bloggs <hermanator12002@yahoo.com>", | 260 "Herman Bloggs <hermanator12002@yahoo.com>", |
157 WEBSITE, | 261 GAIM_WEBSITE, |
158 NULL, | 262 plugin_load, |
159 NULL, | 263 plugin_unload, |
160 NULL, | 264 NULL, |
161 &ui_info, | 265 &ui_info, |
162 NULL | 266 NULL |
163 }; | 267 }; |
164 | 268 |
165 static void | 269 static void |
166 init_plugin(GaimPlugin *plugin) | 270 init_plugin(GaimPlugin *plugin) |
167 { | 271 { |
168 gaim_prefs_add_none("/plugins/gtk/win32"); | 272 gaim_prefs_add_none("/plugins/gtk/win32"); |
169 gaim_prefs_add_none("/plugins/gtk/win32/winprefs"); | 273 gaim_prefs_add_none("/plugins/gtk/win32/winprefs"); |
170 gaim_prefs_add_bool("/plugins/gtk/win32/winprefs/auto_start", FALSE); | 274 gaim_prefs_add_bool(OPT_WINPREFS_DBLIST_DOCKABLE, FALSE); |
275 gaim_prefs_add_bool(OPT_WINPREFS_DBLIST_DOCKED, FALSE); | |
276 gaim_prefs_add_int(OPT_WINPREFS_DBLIST_HEIGHT, 0); | |
277 gaim_prefs_add_int(OPT_WINPREFS_DBLIST_SIDE, 0); | |
171 } | 278 } |
172 | 279 |
173 GAIM_INIT_PLUGIN(winprefs, init_plugin, info) | 280 GAIM_INIT_PLUGIN(winprefs, init_plugin, info) |