Sun, 03 Aug 2003 09:47:15 +0000
[gaim-migrate @ 6864]
Lots of Makefile.am and configure.ac fixes from Robot101. Doumo arigatou,
Mr. Roboto!
committer: Christian Hammond <chipx86@chipx86.com>
| 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> | |
|
5912
32619a71edd2
[gaim-migrate @ 6344]
Herman Bloggs <herman@bluedigits.com>
parents:
5854
diff
changeset
|
24 | |
|
32619a71edd2
[gaim-migrate @ 6344]
Herman Bloggs <herman@bluedigits.com>
parents:
5854
diff
changeset
|
25 | #include "internal.h" |
|
32619a71edd2
[gaim-migrate @ 6344]
Herman Bloggs <herman@bluedigits.com>
parents:
5854
diff
changeset
|
26 | |
|
32619a71edd2
[gaim-migrate @ 6344]
Herman Bloggs <herman@bluedigits.com>
parents:
5854
diff
changeset
|
27 | #include "prefs.h" |
|
32619a71edd2
[gaim-migrate @ 6344]
Herman Bloggs <herman@bluedigits.com>
parents:
5854
diff
changeset
|
28 | #include "debug.h" |
|
32619a71edd2
[gaim-migrate @ 6344]
Herman Bloggs <herman@bluedigits.com>
parents:
5854
diff
changeset
|
29 | |
|
5224
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
30 | #include "gtkplugin.h" |
|
5912
32619a71edd2
[gaim-migrate @ 6344]
Herman Bloggs <herman@bluedigits.com>
parents:
5854
diff
changeset
|
31 | #include "gtkutils.h" |
| 4134 | 32 | |
| 33 | /* | |
| 34 | * MACROS & DEFINES | |
| 35 | */ | |
| 5854 | 36 | #define WINPREFS_PLUGIN_ID "gtk-win-prefs" |
|
5224
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
37 | #define WINPREFS_VERSION 1 |
| 4134 | 38 | |
| 39 | /* | |
| 40 | * LOCALS | |
| 41 | */ | |
| 5795 | 42 | static const char *OPT_WINPREFS_AUTOSTART="/plugins/gtk/win32/winprefs/auto_start"; |
| 4134 | 43 | |
| 44 | /* | |
| 45 | * PROTOS | |
| 46 | */ | |
| 47 | ||
| 48 | /* | |
| 49 | * CODE | |
| 50 | */ | |
| 51 | ||
| 5795 | 52 | static GtkWidget *wgaim_button(const char *text, const char *pref, GtkWidget *page) { |
| 53 | GtkWidget *button; | |
|
5749
538a4a7b41ad
[gaim-migrate @ 6174]
Herman Bloggs <herman@bluedigits.com>
parents:
5224
diff
changeset
|
54 | button = gtk_check_button_new_with_mnemonic(text); |
| 5795 | 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); | |
|
5749
538a4a7b41ad
[gaim-migrate @ 6174]
Herman Bloggs <herman@bluedigits.com>
parents:
5224
diff
changeset
|
57 | gtk_widget_show(button); |
| 5795 | 58 | return button; |
| 4134 | 59 | } |
| 60 | ||
| 61 | static int open_run_key(PHKEY phKey, REGSAM samDesired) { | |
| 5795 | 62 | /* First try current user key (for WinNT & Win2k +), fall back to local machine */ |
| 63 | if(ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER, | |
| 4134 | 64 | "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", |
| 65 | 0, samDesired, phKey)); | |
| 66 | else if(ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, | |
| 67 | "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", | |
| 68 | 0, samDesired, phKey)); | |
| 69 | else { | |
| 5854 | 70 | gaim_debug(GAIM_DEBUG_ERROR, WINPREFS_PLUGIN_ID, "open_run_key: Could not open key for writing value\n"); |
| 4134 | 71 | return 0; |
| 72 | } | |
| 73 | return 1; | |
| 74 | } | |
| 75 | ||
| 5795 | 76 | static void set_winprefs_option(GtkWidget *w, const char *key) { |
| 77 | gaim_prefs_set_bool(key, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w))); | |
| 78 | if(key == OPT_WINPREFS_AUTOSTART) { | |
| 4134 | 79 | HKEY hKey; |
| 80 | ||
| 81 | if(!open_run_key(&hKey, KEY_SET_VALUE)) | |
| 82 | return; | |
| 5795 | 83 | if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w))) { |
| 4134 | 84 | char buffer[1024]; |
| 85 | DWORD size; | |
| 86 | ||
| 87 | if((size = GetModuleFileName(wgaim_hinstance(), | |
| 88 | (LPBYTE)buffer, | |
| 89 | sizeof(buffer)))==0) { | |
| 5854 | 90 | gaim_debug(GAIM_DEBUG_ERROR, WINPREFS_PLUGIN_ID, "GetModuleFileName Error.. Could not set Gaim autostart.\n"); |
| 4134 | 91 | RegCloseKey(hKey); |
| 92 | return; | |
| 93 | } | |
| 94 | /* Now set value of new key */ | |
| 95 | if(ERROR_SUCCESS != RegSetValueEx(hKey, | |
| 96 | "Gaim", | |
| 97 | 0, | |
| 98 | REG_SZ, | |
| 99 | buffer, | |
| 100 | size)) | |
| 5854 | 101 | gaim_debug(GAIM_DEBUG_ERROR, WINPREFS_PLUGIN_ID, "Could not set registry key value\n"); |
| 4134 | 102 | } |
| 103 | else { | |
| 104 | if(ERROR_SUCCESS != RegDeleteValue(hKey, "Gaim")) | |
| 5854 | 105 | gaim_debug(GAIM_DEBUG_ERROR, WINPREFS_PLUGIN_ID, "Could not delete registry key value\n"); |
| 4134 | 106 | } |
| 107 | RegCloseKey(hKey); | |
| 108 | } | |
| 109 | } | |
| 110 | ||
| 111 | /* | |
| 112 | * EXPORTED FUNCTIONS | |
| 113 | */ | |
|
5224
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
114 | static GtkWidget* get_config_frame(GaimPlugin *plugin) { |
| 4134 | 115 | GtkWidget *ret; |
| 116 | GtkWidget *button; | |
| 117 | GtkWidget *vbox; | |
| 118 | HKEY hKey; | |
| 119 | ||
| 120 | ret = gtk_vbox_new(FALSE, 18); | |
| 121 | gtk_container_set_border_width (GTK_CONTAINER (ret), 12); | |
| 122 | ||
| 123 | /* IM Convo trans options */ | |
|
5749
538a4a7b41ad
[gaim-migrate @ 6174]
Herman Bloggs <herman@bluedigits.com>
parents:
5224
diff
changeset
|
124 | vbox = gaim_gtk_make_frame (ret, _("Startup")); |
| 5795 | 125 | button = wgaim_button(_("_Start Gaim on Windows startup"), OPT_WINPREFS_AUTOSTART, vbox); |
| 4134 | 126 | /* Set initial value */ |
| 127 | if(open_run_key(&hKey, KEY_QUERY_VALUE)) { | |
| 128 | if(ERROR_SUCCESS == RegQueryValueEx(hKey, "Gaim", 0, NULL, NULL, NULL)) { | |
| 129 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE); | |
| 130 | } | |
| 131 | } | |
| 5795 | 132 | gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(set_winprefs_option), (void *)OPT_WINPREFS_AUTOSTART); |
| 4134 | 133 | |
| 134 | gtk_widget_show_all(ret); | |
| 135 | return ret; | |
| 136 | } | |
|
5224
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 | static GaimGtkPluginUiInfo ui_info = |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
139 | { |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
140 | get_config_frame |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
141 | }; |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
142 | |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
143 | static GaimPluginInfo info = |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
144 | { |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
145 | 2, |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
146 | GAIM_PLUGIN_STANDARD, |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
147 | GAIM_GTK_PLUGIN_TYPE, |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
148 | 0, |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
149 | NULL, |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
150 | GAIM_PRIORITY_DEFAULT, |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
151 | WINPREFS_PLUGIN_ID, |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
152 | N_("WinGaim Options"), |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
153 | VERSION, |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
154 | N_("Options specific to Windows Gaim."), |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
155 | N_("Options specific to Windows Gaim."), |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
156 | "Herman Bloggs <hermanator12002@yahoo.com>", |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
157 | WEBSITE, |
|
5798
d60e39f7fa1d
[gaim-migrate @ 6223]
Christian Hammond <chipx86@chipx86.com>
parents:
5795
diff
changeset
|
158 | NULL, |
|
5224
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
159 | NULL, |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
160 | NULL, |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
161 | &ui_info, |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
162 | NULL |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
163 | }; |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
164 | |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
165 | static void |
|
5798
d60e39f7fa1d
[gaim-migrate @ 6223]
Christian Hammond <chipx86@chipx86.com>
parents:
5795
diff
changeset
|
166 | init_plugin(GaimPlugin *plugin) |
|
5224
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
167 | { |
|
5798
d60e39f7fa1d
[gaim-migrate @ 6223]
Christian Hammond <chipx86@chipx86.com>
parents:
5795
diff
changeset
|
168 | gaim_prefs_add_none("/plugins/gtk/win32"); |
|
d60e39f7fa1d
[gaim-migrate @ 6223]
Christian Hammond <chipx86@chipx86.com>
parents:
5795
diff
changeset
|
169 | gaim_prefs_add_none("/plugins/gtk/win32/winprefs"); |
|
d60e39f7fa1d
[gaim-migrate @ 6223]
Christian Hammond <chipx86@chipx86.com>
parents:
5795
diff
changeset
|
170 | 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
|
171 | } |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
172 | |
| 6063 | 173 | GAIM_INIT_PLUGIN(winprefs, init_plugin, info) |