Mercurial > pidgin.yaz
comparison console/gntgaim.c @ 13911:b210409cdc56
[gaim-migrate @ 16410]
Change some colors for terminals that don't support customizing colors.
Make taskbar behave properly when moving a window.
Read startup options from command-line (copy-paste from gtkgaim [sic]).
I am doing #define _GNU_SOURCE and #include <getopt.h> ... I don't know
if that's alright. So now you can specify a location to read config files
from.
committer: Tailor Script <tailor@pidgin.im>
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Mon, 03 Jul 2006 02:27:41 +0000 |
parents | cc60d0861337 |
children | 9309d27d780c |
comparison
equal
deleted
inserted
replaced
13910:6c907830a45f | 13911:b210409cdc56 |
---|---|
16 #include "whiteboard.h" | 16 #include "whiteboard.h" |
17 | 17 |
18 #include "gntgaim.h" | 18 #include "gntgaim.h" |
19 #include "gntui.h" | 19 #include "gntui.h" |
20 | 20 |
21 #define _GNU_SOURCE | |
22 #include <getopt.h> | |
23 | |
21 /* Anything IO-related is directly copied from gtkgaim's source tree */ | 24 /* Anything IO-related is directly copied from gtkgaim's source tree */ |
22 | 25 |
23 static GaimCoreUiOps core_ops = | 26 static GaimCoreUiOps core_ops = |
24 { | 27 { |
25 NULL, /*gaim_gtk_prefs_init,*/ | 28 NULL, /*gaim_gtk_prefs_init,*/ |
101 | 104 |
102 channel = g_io_channel_unix_new(fd); | 105 channel = g_io_channel_unix_new(fd); |
103 closure->result = g_io_add_watch_full(channel, G_PRIORITY_DEFAULT, cond, | 106 closure->result = g_io_add_watch_full(channel, G_PRIORITY_DEFAULT, cond, |
104 gaim_gtk_io_invoke, closure, gaim_gtk_io_destroy); | 107 gaim_gtk_io_invoke, closure, gaim_gtk_io_destroy); |
105 | 108 |
106 #if 0 | |
107 gaim_debug(GAIM_DEBUG_MISC, "gtk_eventloop", | |
108 "CLOSURE: adding input watcher %d for fd %d\n", | |
109 closure->result, fd); | |
110 #endif | |
111 | |
112 g_io_channel_unref(channel); | 109 g_io_channel_unref(channel); |
113 return closure->result; | 110 return closure->result; |
114 } | 111 } |
115 | 112 |
116 static GaimEventLoopUiOps eventloop_ops = | 113 static GaimEventLoopUiOps eventloop_ops = |
127 return &eventloop_ops; | 124 return &eventloop_ops; |
128 } | 125 } |
129 | 126 |
130 /* This is mostly copied from gtkgaim's source tree */ | 127 /* This is mostly copied from gtkgaim's source tree */ |
131 static void | 128 static void |
132 init_libgaim() | 129 show_usage(const char *name, gboolean terse) |
130 { | |
131 char *text; | |
132 | |
133 if (terse) { | |
134 text = g_strdup_printf(_("Gaim %s. Try `%s -h' for more information.\n"), VERSION, name); | |
135 } else { | |
136 text = g_strdup_printf(_("Gaim %s\n" | |
137 "Usage: %s [OPTION]...\n\n" | |
138 " -c, --config=DIR use DIR for config files\n" | |
139 " -d, --debug print debugging messages to stdout\n" | |
140 " -h, --help display this help and exit\n" | |
141 " -n, --nologin don't automatically login\n" | |
142 " -v, --version display the current version and exit\n"), VERSION, name); | |
143 } | |
144 | |
145 gaim_print_utf8_to_console(stdout, text); | |
146 g_free(text); | |
147 } | |
148 | |
149 static int | |
150 init_libgaim(int argc, char **argv) | |
133 { | 151 { |
134 char *path; | 152 char *path; |
135 | 153 int opt; |
154 gboolean opt_help = FALSE; | |
155 gboolean opt_nologin = FALSE; | |
156 gboolean opt_version = FALSE; | |
157 char *opt_config_dir_arg = NULL; | |
158 char *opt_session_arg = NULL; | |
159 gboolean debug_enabled; | |
160 | |
161 struct option long_options[] = { | |
162 {"config", required_argument, NULL, 'c'}, | |
163 {"debug", no_argument, NULL, 'd'}, | |
164 {"help", no_argument, NULL, 'h'}, | |
165 {"nologin", no_argument, NULL, 'n'}, | |
166 {"session", required_argument, NULL, 's'}, | |
167 {"version", no_argument, NULL, 'v'}, | |
168 {0, 0, 0, 0} | |
169 }; | |
170 | |
171 /* scan command-line options */ | |
172 opterr = 1; | |
173 while ((opt = getopt_long(argc, argv, | |
174 #ifndef _WIN32 | |
175 "c:dhn::s:v", | |
176 #else | |
177 "c:dhn::v", | |
178 #endif | |
179 long_options, NULL)) != -1) { | |
180 switch (opt) { | |
181 case 'c': /* config dir */ | |
182 g_free(opt_config_dir_arg); | |
183 opt_config_dir_arg = g_strdup(optarg); | |
184 break; | |
185 case 'd': /* debug */ | |
186 debug_enabled = TRUE; | |
187 break; | |
188 case 'h': /* help */ | |
189 opt_help = TRUE; | |
190 break; | |
191 case 'n': /* no autologin */ | |
192 opt_nologin = TRUE; | |
193 break; | |
194 case 's': /* use existing session ID */ | |
195 g_free(opt_session_arg); | |
196 opt_session_arg = g_strdup(optarg); | |
197 break; | |
198 case 'v': /* version */ | |
199 opt_version = TRUE; | |
200 break; | |
201 case '?': /* show terse help */ | |
202 default: | |
203 show_usage(argv[0], TRUE); | |
204 return 0; | |
205 break; | |
206 } | |
207 } | |
208 | |
209 /* show help message */ | |
210 if (opt_help) { | |
211 show_usage(argv[0], FALSE); | |
212 return 0; | |
213 } | |
214 /* show version message */ | |
215 if (opt_version) { | |
216 printf("Gaim %s\n", VERSION); | |
217 return 0; | |
218 } | |
219 | |
220 /* set a user-specified config directory */ | |
221 if (opt_config_dir_arg != NULL) { | |
222 gaim_util_set_user_dir(opt_config_dir_arg); | |
223 } | |
224 | |
225 /* | |
226 * We're done piddling around with command line arguments. | |
227 * Fire up this baby. | |
228 */ | |
229 | |
230 /* Because we don't want debug-messages to show up and corrup the display */ | |
136 gaim_debug_set_enabled(FALSE); | 231 gaim_debug_set_enabled(FALSE); |
137 | 232 |
138 gaim_core_set_ui_ops(gnt_core_get_ui_ops()); | 233 gaim_core_set_ui_ops(gnt_core_get_ui_ops()); |
139 gaim_eventloop_set_ui_ops(gnt_eventloop_get_ui_ops()); | 234 gaim_eventloop_set_ui_ops(gnt_eventloop_get_ui_ops()); |
140 | |
141 gaim_util_set_user_dir("/tmp/tmp/"); /* XXX: */ | |
142 | 235 |
143 path = g_build_filename(gaim_user_dir(), "plugins", NULL); | 236 path = g_build_filename(gaim_user_dir(), "plugins", NULL); |
144 gaim_plugins_add_search_path(path); | 237 gaim_plugins_add_search_path(path); |
145 g_free(path); | 238 g_free(path); |
239 | |
146 gaim_plugins_add_search_path("/usr/local/lib/gaim"); /* XXX: */ | 240 gaim_plugins_add_search_path("/usr/local/lib/gaim"); /* XXX: */ |
147 | 241 |
148 if (!gaim_core_init(GAIM_GNT_UI)) | 242 if (!gaim_core_init(GAIM_GNT_UI)) |
149 { | 243 { |
150 fprintf(stderr, "OOPSSS!!\n"); | 244 fprintf(stderr, |
245 "Initialization of the Gaim core failed. Dumping core.\n" | |
246 "Please report this!\n"); | |
151 abort(); | 247 abort(); |
152 } | 248 } |
153 | 249 |
154 /* TODO: Move blist loading into gaim_blist_init() */ | 250 /* TODO: Move blist loading into gaim_blist_init() */ |
155 gaim_set_blist(gaim_blist_new()); | 251 gaim_set_blist(gaim_blist_new()); |
158 /* TODO: Move prefs loading into gaim_prefs_init() */ | 254 /* TODO: Move prefs loading into gaim_prefs_init() */ |
159 gaim_prefs_load(); | 255 gaim_prefs_load(); |
160 gaim_prefs_update_old(); | 256 gaim_prefs_update_old(); |
161 | 257 |
162 /* load plugins we had when we quit */ | 258 /* load plugins we had when we quit */ |
163 gaim_plugins_load_saved("/gaim/gtk/plugins/loaded"); | 259 gaim_plugins_load_saved("/gaim/gnt/plugins/loaded"); |
164 | 260 |
165 /* TODO: Move pounces loading into gaim_pounces_init() */ | 261 /* TODO: Move pounces loading into gaim_pounces_init() */ |
166 gaim_pounces_load(); | 262 gaim_pounces_load(); |
167 | 263 |
264 if (opt_nologin) | |
265 { | |
266 /* Set all accounts to "offline" */ | |
267 GaimSavedStatus *saved_status; | |
268 | |
269 /* If we've used this type+message before, lookup the transient status */ | |
270 saved_status = gaim_savedstatus_find_transient_by_type_and_message( | |
271 GAIM_STATUS_OFFLINE, NULL); | |
272 | |
273 /* If this type+message is unique then create a new transient saved status */ | |
274 if (saved_status == NULL) | |
275 saved_status = gaim_savedstatus_new(NULL, GAIM_STATUS_OFFLINE); | |
276 | |
277 /* Set the status for each account */ | |
278 gaim_savedstatus_activate(saved_status); | |
279 } | |
280 else | |
281 { | |
282 /* Everything is good to go--sign on already */ | |
283 if (!gaim_prefs_get_bool("/core/savedstatus/startup_current_status")) | |
284 gaim_savedstatus_activate(gaim_savedstatus_get_startup()); | |
285 gaim_accounts_restore_current_statuses(); | |
286 } | |
287 | |
288 return 1; | |
168 } | 289 } |
169 | 290 |
170 int main(int argc, char **argv) | 291 int main(int argc, char **argv) |
171 { | 292 { |
172 /* XXX: Don't puke */ | 293 /* XXX: Don't puke */ |
173 freopen(".error", "w", stderr); | 294 freopen(".error", "w", stderr); |
174 | 295 |
175 /* Initialize the libgaim stuff */ | 296 /* Initialize the libgaim stuff */ |
176 init_libgaim(); | 297 if (!init_libgaim(argc, argv)) |
177 | 298 return 0; |
178 /* Enable the accounts and restore the status */ | |
179 gaim_accounts_restore_current_statuses(); | |
180 | 299 |
181 /* Initialize and run the UI */ | 300 /* Initialize and run the UI */ |
182 init_gnt_ui(); | 301 init_gnt_ui(); |
183 | 302 |
184 gaim_core_quit(); | 303 gaim_core_quit(); |