Sat, 07 Jun 2003 09:09:11 +0000
[gaim-migrate @ 6223]
<SimGuy> it was partly my stupidity :)
| 4134 | 1 | /* |
| 2 | * winprefs.c | |
| 3 | * | |
| 4 | * copyright (c) 1998-2002, Herman Bloggs <hermanator12002@yahoo.com> | |
| 5 | * | |
| 6 | * 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 | |
| 8 | * the free software foundation; either version 2 of the license, or | |
| 9 | * (at your option) any later version. | |
| 10 | * | |
| 11 | * this program is distributed in the hope that it will be useful, | |
| 12 | * but without any warranty; without even the implied warranty of | |
| 13 | * merchantability or fitness for a particular purpose. see the | |
| 14 | * gnu general public license for more details. | |
| 15 | * | |
| 16 | * you should have received a copy of the gnu general public license | |
| 17 | * along with this program; if not, write to the free software | |
| 18 | * foundation, inc., 59 temple place, suite 330, boston, ma 02111-1307 usa | |
| 19 | * | |
| 20 | */ | |
| 21 | #include <windows.h> | |
| 22 | #include <winreg.h> | |
| 23 | #include <winerror.h> | |
| 24 | #include "gaim.h" | |
|
5224
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
25 | #include "gtkplugin.h" |
| 5795 | 26 | #include "prefs.h" |
| 4134 | 27 | #include "win32dep.h" |
| 28 | ||
| 29 | /* | |
| 30 | * MACROS & DEFINES | |
| 31 | */ | |
|
5224
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
32 | #define WINPREFS_PLUGIN_ID "gaim-winprefs" |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
33 | #define WINPREFS_VERSION 1 |
| 4134 | 34 | |
| 35 | /* | |
| 36 | * LOCALS | |
| 37 | */ | |
| 5795 | 38 | static const char *OPT_WINPREFS_AUTOSTART="/plugins/gtk/win32/winprefs/auto_start"; |
| 4134 | 39 | |
| 40 | /* | |
| 41 | * PROTOS | |
| 42 | */ | |
| 43 | ||
| 44 | /* | |
| 45 | * CODE | |
| 46 | */ | |
| 47 | ||
| 5795 | 48 | static GtkWidget *wgaim_button(const char *text, const char *pref, GtkWidget *page) { |
| 49 | GtkWidget *button; | |
|
5749
538a4a7b41ad
[gaim-migrate @ 6174]
Herman Bloggs <herman@bluedigits.com>
parents:
5224
diff
changeset
|
50 | button = gtk_check_button_new_with_mnemonic(text); |
| 5795 | 51 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), gaim_prefs_get_bool(pref)); |
| 52 | gtk_box_pack_start(GTK_BOX(page), button, FALSE, FALSE, 0); | |
|
5749
538a4a7b41ad
[gaim-migrate @ 6174]
Herman Bloggs <herman@bluedigits.com>
parents:
5224
diff
changeset
|
53 | gtk_widget_show(button); |
| 5795 | 54 | return button; |
| 4134 | 55 | } |
| 56 | ||
| 57 | static int open_run_key(PHKEY phKey, REGSAM samDesired) { | |
| 5795 | 58 | /* First try current user key (for WinNT & Win2k +), fall back to local machine */ |
| 59 | if(ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER, | |
| 4134 | 60 | "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", |
| 61 | 0, samDesired, phKey)); | |
| 62 | else if(ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, | |
| 63 | "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", | |
| 64 | 0, samDesired, phKey)); | |
| 65 | else { | |
| 5795 | 66 | gaim_debug(3, WINPREFS_PLUGIN_ID, "open_run_key: Could not open key for writing value\n"); |
| 4134 | 67 | return 0; |
| 68 | } | |
| 69 | return 1; | |
| 70 | } | |
| 71 | ||
| 5795 | 72 | static void set_winprefs_option(GtkWidget *w, const char *key) { |
| 73 | gaim_prefs_set_bool(key, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w))); | |
| 74 | if(key == OPT_WINPREFS_AUTOSTART) { | |
| 4134 | 75 | HKEY hKey; |
| 76 | ||
| 77 | if(!open_run_key(&hKey, KEY_SET_VALUE)) | |
| 78 | return; | |
| 5795 | 79 | if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w))) { |
| 4134 | 80 | char buffer[1024]; |
| 81 | DWORD size; | |
| 82 | ||
| 83 | if((size = GetModuleFileName(wgaim_hinstance(), | |
| 84 | (LPBYTE)buffer, | |
| 85 | sizeof(buffer)))==0) { | |
| 5795 | 86 | gaim_debug(3, WINPREFS_PLUGIN_ID, "GetModuleFileName Error.. Could not set Gaim autostart.\n"); |
| 4134 | 87 | RegCloseKey(hKey); |
| 88 | return; | |
| 89 | } | |
| 90 | /* Now set value of new key */ | |
| 91 | if(ERROR_SUCCESS != RegSetValueEx(hKey, | |
| 92 | "Gaim", | |
| 93 | 0, | |
| 94 | REG_SZ, | |
| 95 | buffer, | |
| 96 | size)) | |
| 5795 | 97 | gaim_debug(3, WINPREFS_PLUGIN_ID, "Could not set registry key value\n"); |
| 4134 | 98 | } |
| 99 | else { | |
| 100 | if(ERROR_SUCCESS != RegDeleteValue(hKey, "Gaim")) | |
| 5795 | 101 | gaim_debug(3, WINPREFS_PLUGIN_ID, "Could not delete registry key value\n"); |
| 4134 | 102 | } |
| 103 | RegCloseKey(hKey); | |
| 104 | } | |
| 105 | } | |
| 106 | ||
| 107 | /* | |
| 108 | * EXPORTED FUNCTIONS | |
| 109 | */ | |
|
5224
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
110 | static GtkWidget* get_config_frame(GaimPlugin *plugin) { |
| 4134 | 111 | GtkWidget *ret; |
| 112 | GtkWidget *button; | |
| 113 | GtkWidget *vbox; | |
| 114 | HKEY hKey; | |
| 115 | ||
| 116 | ret = gtk_vbox_new(FALSE, 18); | |
| 117 | gtk_container_set_border_width (GTK_CONTAINER (ret), 12); | |
| 118 | ||
| 119 | /* IM Convo trans options */ | |
|
5749
538a4a7b41ad
[gaim-migrate @ 6174]
Herman Bloggs <herman@bluedigits.com>
parents:
5224
diff
changeset
|
120 | vbox = gaim_gtk_make_frame (ret, _("Startup")); |
| 5795 | 121 | button = wgaim_button(_("_Start Gaim on Windows startup"), OPT_WINPREFS_AUTOSTART, vbox); |
| 4134 | 122 | /* Set initial value */ |
| 123 | if(open_run_key(&hKey, KEY_QUERY_VALUE)) { | |
| 124 | if(ERROR_SUCCESS == RegQueryValueEx(hKey, "Gaim", 0, NULL, NULL, NULL)) { | |
| 125 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE); | |
| 126 | } | |
| 127 | } | |
| 5795 | 128 | gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(set_winprefs_option), (void *)OPT_WINPREFS_AUTOSTART); |
| 4134 | 129 | |
| 130 | gtk_widget_show_all(ret); | |
| 131 | return ret; | |
| 132 | } | |
|
5224
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
133 | |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
134 | static GaimGtkPluginUiInfo ui_info = |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
135 | { |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
136 | get_config_frame |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
137 | }; |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
138 | |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
139 | static GaimPluginInfo info = |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
140 | { |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
141 | 2, |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
142 | GAIM_PLUGIN_STANDARD, |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
143 | GAIM_GTK_PLUGIN_TYPE, |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
144 | 0, |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
145 | NULL, |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
146 | GAIM_PRIORITY_DEFAULT, |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
147 | WINPREFS_PLUGIN_ID, |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
148 | N_("WinGaim Options"), |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
149 | VERSION, |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
150 | N_("Options specific to Windows Gaim."), |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
151 | N_("Options specific to Windows Gaim."), |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
152 | "Herman Bloggs <hermanator12002@yahoo.com>", |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
153 | WEBSITE, |
|
5798
d60e39f7fa1d
[gaim-migrate @ 6223]
Christian Hammond <chipx86@chipx86.com>
parents:
5795
diff
changeset
|
154 | NULL, |
|
5224
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
155 | NULL, |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
156 | NULL, |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
157 | &ui_info, |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
158 | NULL |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
159 | }; |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
160 | |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
161 | static void |
|
5798
d60e39f7fa1d
[gaim-migrate @ 6223]
Christian Hammond <chipx86@chipx86.com>
parents:
5795
diff
changeset
|
162 | init_plugin(GaimPlugin *plugin) |
|
5224
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
163 | { |
|
5798
d60e39f7fa1d
[gaim-migrate @ 6223]
Christian Hammond <chipx86@chipx86.com>
parents:
5795
diff
changeset
|
164 | gaim_prefs_add_none("/plugins/gtk/win32"); |
|
d60e39f7fa1d
[gaim-migrate @ 6223]
Christian Hammond <chipx86@chipx86.com>
parents:
5795
diff
changeset
|
165 | gaim_prefs_add_none("/plugins/gtk/win32/winprefs"); |
|
d60e39f7fa1d
[gaim-migrate @ 6223]
Christian Hammond <chipx86@chipx86.com>
parents:
5795
diff
changeset
|
166 | gaim_prefs_add_bool("/plugins/gtk/win32/winprefs/auto_start", FALSE); |
|
5224
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
167 | } |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
168 | |
|
5798
d60e39f7fa1d
[gaim-migrate @ 6223]
Christian Hammond <chipx86@chipx86.com>
parents:
5795
diff
changeset
|
169 | GAIM_INIT_PLUGIN(winprefs, init_plugin, info); |