Sat, 26 Apr 2003 14:55:40 +0000
[gaim-migrate @ 5594]
Update for new plugin api
| 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" |
| 4134 | 26 | #include "win32dep.h" |
| 27 | ||
| 28 | /* | |
| 29 | * MACROS & DEFINES | |
| 30 | */ | |
|
5224
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
31 | #define WINPREFS_PLUGIN_ID "gaim-winprefs" |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
32 | #define WINPREFS_VERSION 1 |
| 4134 | 33 | |
| 34 | /* Plugin options */ | |
| 35 | #define OPT_WGAIM_AUTOSTART 0x00000001 | |
| 36 | ||
| 37 | /* | |
| 38 | * LOCALS | |
| 39 | */ | |
| 40 | guint winprefs_options=0; | |
| 41 | ||
| 42 | /* | |
| 43 | * PROTOS | |
| 44 | */ | |
| 45 | extern GtkWidget *gaim_button(const char*, guint*, int, GtkWidget*); | |
| 46 | ||
| 47 | /* | |
| 48 | * CODE | |
| 49 | */ | |
| 50 | ||
| 51 | static void write_options(FILE *f) { | |
| 52 | fprintf(f, "options {\n"); | |
| 53 | fprintf(f, "\twinprefs_options { %u }\n", winprefs_options); | |
| 54 | fprintf(f, "}\n"); | |
| 55 | } | |
| 56 | ||
| 57 | static void save_winprefs_prefs() { | |
| 58 | FILE *f; | |
| 59 | char buf[1024]; | |
| 60 | ||
| 61 | if (gaim_home_dir()) { | |
| 62 | g_snprintf(buf, sizeof(buf), "%s" G_DIR_SEPARATOR_S ".gaim" G_DIR_SEPARATOR_S "winprefsrc", gaim_home_dir()); | |
| 63 | } | |
| 64 | else | |
| 65 | return; | |
| 66 | ||
| 67 | if ((f = fopen(buf, "w"))) { | |
| 68 | fprintf(f, "# winprefsrc v%d\n", WINPREFS_VERSION); | |
| 69 | write_options(f); | |
| 70 | fclose(f); | |
| 71 | } | |
| 72 | else | |
| 73 | debug_printf("Error opening wintransrc\n"); | |
| 74 | } | |
| 75 | ||
| 76 | static int open_run_key(PHKEY phKey, REGSAM samDesired) { | |
| 77 | /* First try current user key (for WinNT & Win2k +), fall back to local machine */ | |
| 78 | if(ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER, | |
| 79 | "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", | |
| 80 | 0, samDesired, phKey)); | |
| 81 | else if(ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, | |
| 82 | "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", | |
| 83 | 0, samDesired, phKey)); | |
| 84 | else { | |
| 85 | debug_printf("open_run_key: Could not open key for writing value\n"); | |
| 86 | return 0; | |
| 87 | } | |
| 88 | return 1; | |
| 89 | } | |
| 90 | ||
| 91 | static void set_winprefs_option(GtkWidget *w, int option) { | |
| 92 | winprefs_options ^= option; | |
| 93 | save_winprefs_prefs(); | |
| 94 | ||
| 95 | if(option == OPT_WGAIM_AUTOSTART) { | |
| 96 | HKEY hKey; | |
| 97 | ||
| 98 | if(!open_run_key(&hKey, KEY_SET_VALUE)) | |
| 99 | return; | |
| 100 | if(winprefs_options & OPT_WGAIM_AUTOSTART) { | |
| 101 | char buffer[1024]; | |
| 102 | DWORD size; | |
| 103 | ||
| 104 | if((size = GetModuleFileName(wgaim_hinstance(), | |
| 105 | (LPBYTE)buffer, | |
| 106 | sizeof(buffer)))==0) { | |
| 107 | debug_printf("GetModuleFileName Error.. Could not set Gaim autostart.\n"); | |
| 108 | RegCloseKey(hKey); | |
| 109 | return; | |
| 110 | } | |
| 111 | /* Now set value of new key */ | |
| 112 | if(ERROR_SUCCESS != RegSetValueEx(hKey, | |
| 113 | "Gaim", | |
| 114 | 0, | |
| 115 | REG_SZ, | |
| 116 | buffer, | |
| 117 | size)) | |
| 118 | debug_printf("Could not set registry key value\n"); | |
| 119 | } | |
| 120 | else { | |
| 121 | if(ERROR_SUCCESS != RegDeleteValue(hKey, "Gaim")) | |
| 122 | debug_printf("Could not delete registry key value\n"); | |
| 123 | } | |
| 124 | RegCloseKey(hKey); | |
| 125 | } | |
| 126 | } | |
| 127 | ||
| 128 | /* | |
| 129 | * EXPORTED FUNCTIONS | |
| 130 | */ | |
|
5224
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
131 | static GtkWidget* get_config_frame(GaimPlugin *plugin) { |
| 4134 | 132 | GtkWidget *ret; |
| 133 | GtkWidget *button; | |
| 134 | GtkWidget *vbox; | |
| 135 | HKEY hKey; | |
| 136 | ||
| 137 | ret = gtk_vbox_new(FALSE, 18); | |
| 138 | gtk_container_set_border_width (GTK_CONTAINER (ret), 12); | |
| 139 | ||
| 140 | /* IM Convo trans options */ | |
| 141 | vbox = make_frame (ret, _("Startup")); | |
| 142 | button = gaim_button(_("_Start Gaim on Windows startup"), &winprefs_options, OPT_WGAIM_AUTOSTART, vbox); | |
| 143 | /* Set initial value */ | |
| 144 | if(open_run_key(&hKey, KEY_QUERY_VALUE)) { | |
| 145 | if(ERROR_SUCCESS == RegQueryValueEx(hKey, "Gaim", 0, NULL, NULL, NULL)) { | |
| 146 | winprefs_options ^= OPT_WGAIM_AUTOSTART; | |
| 147 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE); | |
| 148 | } | |
| 149 | } | |
| 150 | gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(set_winprefs_option), (int *)OPT_WGAIM_AUTOSTART); | |
| 151 | ||
| 152 | gtk_widget_show_all(ret); | |
| 153 | return ret; | |
| 154 | } | |
|
5224
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
155 | |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
156 | static GaimGtkPluginUiInfo ui_info = |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
157 | { |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
158 | get_config_frame |
|
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 GaimPluginInfo info = |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
162 | { |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
163 | 2, |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
164 | GAIM_PLUGIN_STANDARD, |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
165 | GAIM_GTK_PLUGIN_TYPE, |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
166 | 0, |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
167 | NULL, |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
168 | GAIM_PRIORITY_DEFAULT, |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
169 | WINPREFS_PLUGIN_ID, |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
170 | N_("WinGaim Options"), |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
171 | VERSION, |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
172 | N_("Options specific to Windows Gaim."), |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
173 | N_("Options specific to Windows Gaim."), |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
174 | "Herman Bloggs <hermanator12002@yahoo.com>", |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
175 | WEBSITE, |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
176 | NULL, |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
177 | NULL, |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
178 | NULL, |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
179 | &ui_info, |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
180 | NULL |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
181 | }; |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
182 | |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
183 | static void |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
184 | __init_plugin(GaimPlugin *plugin) |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
185 | { |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
186 | } |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
187 | |
|
8cb89f5b912a
[gaim-migrate @ 5594]
Herman Bloggs <herman@bluedigits.com>
parents:
4606
diff
changeset
|
188 | GAIM_INIT_PLUGIN(winprefs, __init_plugin, info); |