Mercurial > pidgin.yaz
comparison plugins/win32/winprefs/winprefs.c @ 5795:0efc365eed6d
[gaim-migrate @ 6220]
Win32 pref updates. Thanks SimGuy!
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Sat, 07 Jun 2003 08:35:55 +0000 |
parents | 6d6ae91c5de7 |
children | 217d24d11b6e |
comparison
equal
deleted
inserted
replaced
5794:5e93fc46d1af | 5795:0efc365eed6d |
---|---|
21 #include <windows.h> | 21 #include <windows.h> |
22 #include <winreg.h> | 22 #include <winreg.h> |
23 #include <winerror.h> | 23 #include <winerror.h> |
24 #include "gaim.h" | 24 #include "gaim.h" |
25 #include "gtkplugin.h" | 25 #include "gtkplugin.h" |
26 #include "prefs.h" | |
26 #include "win32dep.h" | 27 #include "win32dep.h" |
27 | 28 |
28 /* | 29 /* |
29 * MACROS & DEFINES | 30 * MACROS & DEFINES |
30 */ | 31 */ |
31 #define WINPREFS_PLUGIN_ID "gaim-winprefs" | 32 #define WINPREFS_PLUGIN_ID "gaim-winprefs" |
32 #define WINPREFS_VERSION 1 | 33 #define WINPREFS_VERSION 1 |
33 | 34 |
34 /* Plugin options */ | |
35 #define OPT_WGAIM_AUTOSTART 0x00000001 | |
36 | |
37 /* | 35 /* |
38 * LOCALS | 36 * LOCALS |
39 */ | 37 */ |
40 guint winprefs_options=0; | 38 static const char *OPT_WINPREFS_AUTOSTART="/plugins/gtk/win32/winprefs/auto_start"; |
41 | 39 |
42 /* | 40 /* |
43 * PROTOS | 41 * PROTOS |
44 */ | 42 */ |
45 | 43 |
46 /* | 44 /* |
47 * CODE | 45 * CODE |
48 */ | 46 */ |
49 | 47 |
50 static GtkWidget *wgaim_button(const char *text, guint *options, int option, GtkWidget *page) { | 48 static GtkWidget *wgaim_button(const char *text, const char *pref, GtkWidget *page) { |
51 GtkWidget *button; | 49 GtkWidget *button; |
52 button = gtk_check_button_new_with_mnemonic(text); | 50 button = gtk_check_button_new_with_mnemonic(text); |
53 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), (*options & option)); | 51 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), gaim_prefs_get_bool(pref)); |
54 gtk_box_pack_start(GTK_BOX(page), button, FALSE, FALSE, 0); | 52 gtk_box_pack_start(GTK_BOX(page), button, FALSE, FALSE, 0); |
55 g_object_set_data(G_OBJECT(button), "options", options); | |
56 gtk_widget_show(button); | 53 gtk_widget_show(button); |
57 return button; | 54 return button; |
58 } | |
59 | |
60 static void write_options(FILE *f) { | |
61 fprintf(f, "options {\n"); | |
62 fprintf(f, "\twinprefs_options { %u }\n", winprefs_options); | |
63 fprintf(f, "}\n"); | |
64 } | |
65 | |
66 static void save_winprefs_prefs() { | |
67 FILE *f; | |
68 char buf[1024]; | |
69 | |
70 if (gaim_home_dir()) { | |
71 g_snprintf(buf, sizeof(buf), "%s" G_DIR_SEPARATOR_S ".gaim" G_DIR_SEPARATOR_S "winprefsrc", gaim_home_dir()); | |
72 } | |
73 else | |
74 return; | |
75 | |
76 if ((f = fopen(buf, "w"))) { | |
77 fprintf(f, "# winprefsrc v%d\n", WINPREFS_VERSION); | |
78 write_options(f); | |
79 fclose(f); | |
80 } | |
81 else | |
82 debug_printf("Error opening wintransrc\n"); | |
83 } | 55 } |
84 | 56 |
85 static int open_run_key(PHKEY phKey, REGSAM samDesired) { | 57 static int open_run_key(PHKEY phKey, REGSAM samDesired) { |
86 /* First try current user key (for WinNT & Win2k +), fall back to local machine */ | 58 /* First try current user key (for WinNT & Win2k +), fall back to local machine */ |
87 if(ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER, | 59 if(ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER, |
88 "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", | 60 "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", |
89 0, samDesired, phKey)); | 61 0, samDesired, phKey)); |
90 else if(ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, | 62 else if(ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, |
91 "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", | 63 "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", |
92 0, samDesired, phKey)); | 64 0, samDesired, phKey)); |
93 else { | 65 else { |
94 debug_printf("open_run_key: Could not open key for writing value\n"); | 66 gaim_debug(3, WINPREFS_PLUGIN_ID, "open_run_key: Could not open key for writing value\n"); |
95 return 0; | 67 return 0; |
96 } | 68 } |
97 return 1; | 69 return 1; |
98 } | 70 } |
99 | 71 |
100 static void set_winprefs_option(GtkWidget *w, int option) { | 72 static void set_winprefs_option(GtkWidget *w, const char *key) { |
101 winprefs_options ^= option; | 73 gaim_prefs_set_bool(key, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w))); |
102 save_winprefs_prefs(); | 74 if(key == OPT_WINPREFS_AUTOSTART) { |
103 | |
104 if(option == OPT_WGAIM_AUTOSTART) { | |
105 HKEY hKey; | 75 HKEY hKey; |
106 | 76 |
107 if(!open_run_key(&hKey, KEY_SET_VALUE)) | 77 if(!open_run_key(&hKey, KEY_SET_VALUE)) |
108 return; | 78 return; |
109 if(winprefs_options & OPT_WGAIM_AUTOSTART) { | 79 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w))) { |
110 char buffer[1024]; | 80 char buffer[1024]; |
111 DWORD size; | 81 DWORD size; |
112 | 82 |
113 if((size = GetModuleFileName(wgaim_hinstance(), | 83 if((size = GetModuleFileName(wgaim_hinstance(), |
114 (LPBYTE)buffer, | 84 (LPBYTE)buffer, |
115 sizeof(buffer)))==0) { | 85 sizeof(buffer)))==0) { |
116 debug_printf("GetModuleFileName Error.. Could not set Gaim autostart.\n"); | 86 gaim_debug(3, WINPREFS_PLUGIN_ID, "GetModuleFileName Error.. Could not set Gaim autostart.\n"); |
117 RegCloseKey(hKey); | 87 RegCloseKey(hKey); |
118 return; | 88 return; |
119 } | 89 } |
120 /* Now set value of new key */ | 90 /* Now set value of new key */ |
121 if(ERROR_SUCCESS != RegSetValueEx(hKey, | 91 if(ERROR_SUCCESS != RegSetValueEx(hKey, |
122 "Gaim", | 92 "Gaim", |
123 0, | 93 0, |
124 REG_SZ, | 94 REG_SZ, |
125 buffer, | 95 buffer, |
126 size)) | 96 size)) |
127 debug_printf("Could not set registry key value\n"); | 97 gaim_debug(3, WINPREFS_PLUGIN_ID, "Could not set registry key value\n"); |
128 } | 98 } |
129 else { | 99 else { |
130 if(ERROR_SUCCESS != RegDeleteValue(hKey, "Gaim")) | 100 if(ERROR_SUCCESS != RegDeleteValue(hKey, "Gaim")) |
131 debug_printf("Could not delete registry key value\n"); | 101 gaim_debug(3, WINPREFS_PLUGIN_ID, "Could not delete registry key value\n"); |
132 } | 102 } |
133 RegCloseKey(hKey); | 103 RegCloseKey(hKey); |
134 } | 104 } |
135 } | 105 } |
136 | 106 |
146 ret = gtk_vbox_new(FALSE, 18); | 116 ret = gtk_vbox_new(FALSE, 18); |
147 gtk_container_set_border_width (GTK_CONTAINER (ret), 12); | 117 gtk_container_set_border_width (GTK_CONTAINER (ret), 12); |
148 | 118 |
149 /* IM Convo trans options */ | 119 /* IM Convo trans options */ |
150 vbox = gaim_gtk_make_frame (ret, _("Startup")); | 120 vbox = gaim_gtk_make_frame (ret, _("Startup")); |
151 button = wgaim_button(_("_Start Gaim on Windows startup"), &winprefs_options, OPT_WGAIM_AUTOSTART, vbox); | 121 button = wgaim_button(_("_Start Gaim on Windows startup"), OPT_WINPREFS_AUTOSTART, vbox); |
152 /* Set initial value */ | 122 /* Set initial value */ |
153 if(open_run_key(&hKey, KEY_QUERY_VALUE)) { | 123 if(open_run_key(&hKey, KEY_QUERY_VALUE)) { |
154 if(ERROR_SUCCESS == RegQueryValueEx(hKey, "Gaim", 0, NULL, NULL, NULL)) { | 124 if(ERROR_SUCCESS == RegQueryValueEx(hKey, "Gaim", 0, NULL, NULL, NULL)) { |
155 winprefs_options ^= OPT_WGAIM_AUTOSTART; | |
156 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE); | 125 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE); |
157 } | 126 } |
158 } | 127 } |
159 gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(set_winprefs_option), (int *)OPT_WGAIM_AUTOSTART); | 128 gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(set_winprefs_option), (void *)OPT_WINPREFS_AUTOSTART); |
160 | 129 |
161 gtk_widget_show_all(ret); | 130 gtk_widget_show_all(ret); |
162 return ret; | 131 return ret; |
132 } | |
133 | |
134 static gboolean plugin_load(GaimPlugin *plugin) | |
135 { | |
136 gaim_prefs_add_none("/plugins/gtk/win32"); | |
137 gaim_prefs_add_none("/plugins/gtk/win32/winprefs"); | |
138 gaim_prefs_add_bool("/plugins/gtk/win32/winprefs/auto_start", FALSE); | |
139 | |
140 return TRUE; | |
163 } | 141 } |
164 | 142 |
165 static GaimGtkPluginUiInfo ui_info = | 143 static GaimGtkPluginUiInfo ui_info = |
166 { | 144 { |
167 get_config_frame | 145 get_config_frame |
180 VERSION, | 158 VERSION, |
181 N_("Options specific to Windows Gaim."), | 159 N_("Options specific to Windows Gaim."), |
182 N_("Options specific to Windows Gaim."), | 160 N_("Options specific to Windows Gaim."), |
183 "Herman Bloggs <hermanator12002@yahoo.com>", | 161 "Herman Bloggs <hermanator12002@yahoo.com>", |
184 WEBSITE, | 162 WEBSITE, |
185 NULL, | 163 plugin_load, |
186 NULL, | 164 NULL, |
187 NULL, | 165 NULL, |
188 &ui_info, | 166 &ui_info, |
189 NULL | 167 NULL |
190 }; | 168 }; |