Mercurial > pidgin
annotate src/gtkmain.c @ 10959:b6cafdeda2a8
[gaim-migrate @ 12761]
this actually saves me some work I thought I had to do
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Wed, 01 Jun 2005 01:26:08 +0000 |
parents | 6240d7fd5b2c |
children | 9fe9c7e00666 |
rev | line source |
---|---|
10302 | 1 /* |
2 * gaim | |
3 * | |
4 * Gaim is the legal property of its developers, whose names are too numerous | |
5 * to list here. Please refer to the COPYRIGHT file distributed with this | |
6 * source distribution. | |
7 * | |
8 * This program is free software; you can redistribute it and/or modify | |
9 * it under the terms of the GNU General Public License as published by | |
10 * the Free Software Foundation; either version 2 of the License, or | |
11 * (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, | |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 * GNU General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU General Public License | |
19 * along with this program; if not, write to the Free Software | |
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 * | |
22 */ | |
23 | |
24 #include "internal.h" | |
25 #include "gtkgaim.h" | |
26 | |
27 #include "account.h" | |
28 #include "conversation.h" | |
29 #include "core.h" | |
30 #include "debug.h" | |
31 #include "eventloop.h" | |
32 #include "ft.h" | |
33 #include "log.h" | |
34 #include "notify.h" | |
35 #include "prefs.h" | |
36 #include "prpl.h" | |
37 #include "pounce.h" | |
38 #include "sound.h" | |
39 #include "status.h" | |
40 #include "util.h" | |
41 | |
42 #include "gtkaccount.h" | |
43 #include "gtkblist.h" | |
44 #include "gtkconn.h" | |
45 #include "gtkconv.h" | |
46 #include "gtkdebug.h" | |
47 #include "gtkdialogs.h" | |
48 #include "gtkeventloop.h" | |
49 #include "gtkft.h" | |
50 #include "gtknotify.h" | |
51 #include "gtkplugin.h" | |
52 #include "gtkpounce.h" | |
53 #include "gtkprefs.h" | |
54 #include "gtkprivacy.h" | |
55 #include "gtkrequest.h" | |
56 #include "gtkroomlist.h" | |
10574 | 57 #include "gtksavedstatuses.h" |
10302 | 58 #include "gtksound.h" |
59 #include "gtkutils.h" | |
60 #include "gtkstock.h" | |
61 | |
62 #if HAVE_SIGNAL_H | |
63 # include <signal.h> | |
64 #endif | |
65 | |
66 #include <getopt.h> | |
67 | |
68 #ifdef HAVE_STARTUP_NOTIFICATION | |
69 # define SN_API_NOT_YET_FROZEN | |
70 # include <libsn/sn-launchee.h> | |
71 # include <gdk/gdkx.h> | |
72 #endif | |
73 | |
74 #ifdef HAVE_STARTUP_NOTIFICATION | |
75 static SnLauncheeContext *sn_context = NULL; | |
76 static SnDisplay *sn_display = NULL; | |
77 #endif | |
78 | |
10448 | 79 /* TODO: Get this out of here? */ |
10302 | 80 int docklet_count = 0; |
81 | |
82 #if HAVE_SIGNAL_H | |
83 /* | |
84 * Lists of signals we wish to catch and those we wish to ignore. | |
85 * Each list terminated with -1 | |
86 */ | |
87 static int catch_sig_list[] = { | |
88 SIGSEGV, | |
89 SIGHUP, | |
90 SIGINT, | |
91 SIGTERM, | |
92 SIGQUIT, | |
93 SIGCHLD, | |
94 -1 | |
95 }; | |
96 | |
97 static int ignore_sig_list[] = { | |
98 SIGPIPE, | |
99 -1 | |
100 }; | |
101 #endif | |
102 | |
10323 | 103 static int |
104 dologin_named(const char *name) | |
10302 | 105 { |
106 GaimAccount *account; | |
10323 | 107 char **names; |
108 int i; | |
109 int ret = -1; | |
10302 | 110 |
10323 | 111 if (name != NULL) { /* list of names given */ |
112 names = g_strsplit(name, ",", 64); | |
113 for (i = 0; names[i] != NULL; i++) { | |
114 account = gaim_accounts_find(names[i], NULL); | |
115 if (account != NULL) { /* found a user */ | |
116 ret = 0; | |
10738 | 117 gaim_account_connect(account); |
10302 | 118 } |
119 } | |
120 g_strfreev(names); | |
10323 | 121 } else { /* no name given, use the first account */ |
10302 | 122 account = (GaimAccount *)gaim_accounts_get_all()->data; |
10323 | 123 ret = 0; |
10738 | 124 gaim_account_connect(account); |
10302 | 125 } |
126 | |
10323 | 127 return ret; |
10302 | 128 } |
129 | |
10333 | 130 #if HAVE_SIGNAL_H |
10302 | 131 static void |
132 clean_pid(void) | |
133 { | |
134 int status; | |
135 pid_t pid; | |
136 | |
137 do { | |
138 pid = waitpid(-1, &status, WNOHANG); | |
139 } while (pid != 0 && pid != (pid_t)-1); | |
10334 | 140 |
141 if ((pid == (pid_t) - 1) && (errno != ECHILD)) { | |
10302 | 142 char errmsg[BUFSIZ]; |
143 snprintf(errmsg, BUFSIZ, "Warning: waitpid() returned %d", pid); | |
144 perror(errmsg); | |
145 } | |
146 } | |
147 | |
10871 | 148 static void |
10323 | 149 sighandler(int sig) |
10302 | 150 { |
151 switch (sig) { | |
152 case SIGHUP: | |
10323 | 153 gaim_debug_warning("sighandler", "Caught signal %d\n", sig); |
10302 | 154 gaim_connections_disconnect_all(); |
155 break; | |
156 case SIGSEGV: | |
157 #ifndef DEBUG | |
158 fprintf(stderr, "Gaim has segfaulted and attempted to dump a core file.\n" | |
159 "This is a bug in the software and has happened through\n" | |
160 "no fault of your own.\n\n" | |
161 "It is possible that this bug is already fixed in CVS.\n" | |
10323 | 162 "If you can reproduce the crash, please notify the gaim\n" |
10302 | 163 "maintainers by reporting a bug at\n" |
164 GAIM_WEBSITE "bug.php\n\n" | |
165 "Please make sure to specify what you were doing at the time,\n" | |
166 "and post the backtrace from the core file. If you do not know\n" | |
167 "how to get the backtrace, please get instructions at\n" | |
168 GAIM_WEBSITE "gdb.php. If you need further\n" | |
10638
222b53ee74f3
[gaim-migrate @ 12135]
Luke Schierer <lschiere@pidgin.im>
parents:
10589
diff
changeset
|
169 "assistance, please IM either SeanEgn or LSchiere and\n" |
10302 | 170 "they can help you.\n"); |
171 #else | |
172 fprintf(stderr, "Hi, user. We need to talk.\n" | |
173 "I think something's gone wrong here. It's probably my fault.\n" | |
174 "No, really, it's not you... it's me... no no no, I think we get along well\n" | |
175 "it's just that.... well, I want to see other people. I... what?!? NO! I haven't\n" | |
176 "been cheating on you!! How many times do you want me to tell you?! And for the\n" | |
177 "last time, it's just a rash!\n"); | |
178 /*g_on_error_query (g_get_prgname());*/ | |
179 #endif | |
180 abort(); | |
181 break; | |
182 case SIGCHLD: | |
183 clean_pid(); | |
184 signal(SIGCHLD, sighandler); /* restore signal catching on this one! */ | |
185 break; | |
186 default: | |
10323 | 187 gaim_debug_warning("sighandler", "Caught signal %d\n", sig); |
10302 | 188 gaim_connections_disconnect_all(); |
189 | |
190 gaim_plugins_unload_all(); | |
191 | |
192 if (gtk_main_level()) | |
193 gtk_main_quit(); | |
194 exit(0); | |
195 } | |
196 } | |
197 #endif | |
198 | |
10323 | 199 static int |
200 ui_main() | |
10302 | 201 { |
202 #ifndef _WIN32 | |
203 GList *icons = NULL; | |
204 GdkPixbuf *icon = NULL; | |
205 char *icon_path; | |
206 #endif | |
207 | |
208 if (current_smiley_theme == NULL) { | |
209 smiley_theme_probe(); | |
10323 | 210 if (smiley_themes != NULL) { |
10302 | 211 struct smiley_theme *smile = smiley_themes->data; |
212 load_smiley_theme(smile->path, TRUE); | |
213 } | |
214 } | |
215 | |
216 gaim_gtk_blist_setup_sort_methods(); | |
217 | |
218 #ifndef _WIN32 | |
219 /* use the nice PNG icon for all the windows */ | |
220 icon_path = g_build_filename(DATADIR, "pixmaps", "gaim", "icons", "online.png", NULL); | |
221 icon = gdk_pixbuf_new_from_file(icon_path, NULL); | |
222 g_free(icon_path); | |
223 if (icon) { | |
224 icons = g_list_append(icons,icon); | |
225 gtk_window_set_default_icon_list(icons); | |
226 g_object_unref(G_OBJECT(icon)); | |
227 g_list_free(icons); | |
228 } else { | |
10323 | 229 gaim_debug_error("ui_main", |
230 "Failed to load the default window icon!\n"); | |
10302 | 231 } |
232 #endif | |
233 | |
234 return 0; | |
235 } | |
236 | |
237 static void | |
238 debug_init(void) | |
239 { | |
240 gaim_debug_set_ui_ops(gaim_gtk_debug_get_ui_ops()); | |
241 gaim_gtk_debug_init(); | |
242 } | |
243 | |
244 static void | |
245 gaim_gtk_ui_init(void) | |
246 { | |
247 /* Set the UI operation structures. */ | |
248 gaim_accounts_set_ui_ops(gaim_gtk_accounts_get_ui_ops()); | |
249 gaim_conversations_set_win_ui_ops(gaim_gtk_conversations_get_win_ui_ops()); | |
250 gaim_xfers_set_ui_ops(gaim_gtk_xfers_get_ui_ops()); | |
251 gaim_blist_set_ui_ops(gaim_gtk_blist_get_ui_ops()); | |
252 gaim_notify_set_ui_ops(gaim_gtk_notify_get_ui_ops()); | |
253 gaim_privacy_set_ui_ops(gaim_gtk_privacy_get_ui_ops()); | |
254 gaim_request_set_ui_ops(gaim_gtk_request_get_ui_ops()); | |
255 gaim_sound_set_ui_ops(gaim_gtk_sound_get_ui_ops()); | |
256 gaim_connections_set_ui_ops(gaim_gtk_connections_get_ui_ops()); | |
257 | |
258 gaim_gtk_stock_init(); | |
259 gaim_gtk_prefs_init(); | |
260 gaim_gtk_account_init(); | |
261 gaim_gtk_blist_init(); | |
10574 | 262 gaim_gtk_status_init(); |
10302 | 263 gaim_gtk_conversations_init(); |
264 gaim_gtk_pounces_init(); | |
265 gaim_gtk_privacy_init(); | |
266 gaim_gtk_xfers_init(); | |
267 gaim_gtk_roomlist_init(); | |
268 } | |
269 | |
270 static void | |
271 gaim_gtk_quit(void) | |
272 { | |
273 /* XXX? */ | |
274 /* YYY is there an XXX here? */ | |
275 | |
276 /* captain's log, stardate... */ | |
277 /* LOG system_log(log_quit, NULL, NULL, OPT_LOG_BUDDY_SIGNON | OPT_LOG_MY_SIGNON); */ | |
278 | |
279 #ifdef USE_SM | |
280 /* unplug */ | |
281 session_end(); | |
282 #endif | |
283 | |
284 /* Save the plugins we have loaded for next time. */ | |
285 gaim_gtk_plugins_save(); | |
286 | |
10574 | 287 /* Uninit */ |
288 gaim_gtk_conversations_uninit(); | |
289 gaim_gtk_status_uninit(); | |
290 gaim_gtk_blist_uninit(); | |
291 gaim_gtk_account_uninit(); | |
292 | |
10302 | 293 /* and end it all... */ |
294 gtk_main_quit(); | |
295 } | |
296 | |
297 static GaimCoreUiOps core_ops = | |
298 { | |
299 gaim_gtk_prefs_init, | |
300 debug_init, | |
301 gaim_gtk_ui_init, | |
302 gaim_gtk_quit | |
303 }; | |
304 | |
305 static GaimCoreUiOps * | |
306 gaim_gtk_core_get_ui_ops(void) | |
307 { | |
308 return &core_ops; | |
309 } | |
310 | |
311 static void | |
10320 | 312 show_usage(const char *name, gboolean terse) |
10302 | 313 { |
10320 | 314 char *text; |
315 char *text_conv; | |
316 GError *error = NULL; | |
10302 | 317 |
10320 | 318 if (terse) { |
319 text = g_strdup_printf(_("Gaim %s. Try `%s -h' for more information.\n"), VERSION, name); | |
320 } else { | |
321 text = g_strdup_printf(_("Gaim %s\n" | |
10302 | 322 "Usage: %s [OPTION]...\n\n" |
323 " -a, --acct display account editor window\n" | |
324 " -c, --config=DIR use DIR for config files\n" | |
325 " -d, --debug print debugging messages to stdout\n" | |
10320 | 326 " -h, --help display this help and exit\n" |
10323 | 327 " -n, --nologin don't automatically login\n" |
10320 | 328 " -l, --login[=NAME] automatically login (optional argument NAME specifies\n" |
329 " account(s) to use, seperated by commas)\n" | |
10323 | 330 " -v, --version display the current version and exit\n"), VERSION, name); |
10302 | 331 } |
332 | |
10320 | 333 /* tries to convert 'text' to users locale */ |
334 text_conv = g_locale_from_utf8(text, -1, NULL, NULL, &error); | |
335 if (text_conv != NULL) { | |
336 puts(text_conv); | |
337 g_free(text_conv); | |
10302 | 338 } |
10320 | 339 /* use 'text' as a fallback */ |
340 else { | |
341 g_warning("%s\n", error->message); | |
342 g_error_free(error); | |
343 puts(text); | |
344 } | |
345 g_free(text); | |
10302 | 346 } |
347 | |
348 #ifdef HAVE_STARTUP_NOTIFICATION | |
349 static void | |
350 sn_error_trap_push(SnDisplay *display, Display *xdisplay) | |
351 { | |
352 gdk_error_trap_push(); | |
353 } | |
354 | |
355 static void | |
356 sn_error_trap_pop(SnDisplay *display, Display *xdisplay) | |
357 { | |
358 gdk_error_trap_pop(); | |
359 } | |
360 | |
361 static void | |
362 startup_notification_complete(void) | |
363 { | |
364 Display *xdisplay; | |
365 | |
366 xdisplay = GDK_DISPLAY(); | |
367 sn_display = sn_display_new(xdisplay, | |
368 sn_error_trap_push, | |
369 sn_error_trap_pop); | |
370 sn_context = | |
371 sn_launchee_context_new_from_environment(sn_display, | |
372 DefaultScreen(xdisplay)); | |
373 | |
374 if (sn_context != NULL) | |
375 { | |
376 sn_launchee_context_complete(sn_context); | |
377 sn_launchee_context_unref(sn_context); | |
378 | |
379 sn_display_unref(sn_display); | |
380 } | |
381 } | |
382 #endif /* HAVE_STARTUP_NOTIFICATION */ | |
383 | |
384 #ifndef _WIN32 | |
385 static char *gaim_find_binary_location(void *symbol, void *data) | |
386 { | |
387 static char *fullname = NULL; | |
388 static gboolean first = TRUE; | |
389 | |
390 char *argv0 = data; | |
391 struct stat st; | |
392 char *basebuf, *linkbuf, *fullbuf; | |
393 | |
394 if (!first) | |
395 /* We've already been through this. */ | |
396 return strdup(fullname); | |
397 | |
398 first = FALSE; | |
399 | |
400 if (!argv0) | |
401 return NULL; | |
402 | |
403 | |
404 basebuf = g_find_program_in_path(argv0); | |
405 | |
406 /* But we still need to deal with symbolic links */ | |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10581
diff
changeset
|
407 g_lstat(basebuf, &st); |
10302 | 408 while ((st.st_mode & S_IFLNK) == S_IFLNK) { |
409 linkbuf = g_malloc(1024); | |
410 readlink(basebuf, linkbuf, 1024); | |
411 if (linkbuf[0] == G_DIR_SEPARATOR) { | |
412 /* an absolute path */ | |
413 fullbuf = g_strdup(linkbuf); | |
414 } else { | |
415 char *dirbuf = g_path_get_dirname(basebuf); | |
416 /* a relative path */ | |
417 fullbuf = g_strdup_printf("%s%s%s", | |
418 dirbuf, G_DIR_SEPARATOR_S, | |
419 linkbuf); | |
420 g_free(dirbuf); | |
421 } | |
422 /* There's no memory leak here. Really! */ | |
423 g_free(linkbuf); | |
424 g_free(basebuf); | |
425 basebuf = fullbuf; | |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10581
diff
changeset
|
426 g_lstat(basebuf, &st); |
10302 | 427 } |
428 | |
429 fullname = basebuf; | |
430 return strdup(fullname); | |
431 } | |
432 #endif /* #ifndef _WIN32 */ | |
433 | |
434 /* FUCKING GET ME A TOWEL! */ | |
435 #ifdef _WIN32 | |
436 int gaim_main(HINSTANCE hint, int argc, char *argv[]) | |
437 #else | |
438 int main(int argc, char *argv[]) | |
439 #endif | |
440 { | |
10323 | 441 gboolean opt_acct = FALSE; |
442 gboolean opt_help = FALSE; | |
443 gboolean opt_login = FALSE; | |
444 gboolean opt_nologin = FALSE; | |
445 gboolean opt_version = FALSE; | |
446 char *opt_config_dir_arg = NULL; | |
447 char *opt_login_arg = NULL; | |
448 char *opt_session_arg = NULL; | |
449 int dologin_ret = -1; | |
10447 | 450 char *search_path; |
10302 | 451 #if HAVE_SIGNAL_H |
452 int sig_indx; /* for setting up signal catching */ | |
453 sigset_t sigset; | |
454 void (*prev_sig_disp)(); | |
455 #endif | |
10323 | 456 int opt; |
10302 | 457 gboolean gui_check; |
10307 | 458 gboolean debug_enabled; |
10334 | 459 #if HAVE_SIGNAL_H |
10323 | 460 char errmsg[BUFSIZ]; |
10334 | 461 #endif |
10302 | 462 |
463 struct option long_options[] = { | |
10323 | 464 {"acct", no_argument, NULL, 'a'}, |
465 {"config", required_argument, NULL, 'c'}, | |
466 {"debug", no_argument, NULL, 'd'}, | |
467 {"help", no_argument, NULL, 'h'}, | |
468 {"login", optional_argument, NULL, 'l'}, | |
469 {"nologin", no_argument, NULL, 'n'}, | |
470 {"session", required_argument, NULL, 's'}, | |
471 {"version", no_argument, NULL, 'v'}, | |
10302 | 472 {0, 0, 0, 0} |
473 }; | |
474 | |
475 #ifdef DEBUG | |
10307 | 476 debug_enabled = TRUE; |
477 #else | |
478 debug_enabled = FALSE; | |
10302 | 479 #endif |
10307 | 480 |
10302 | 481 #ifndef _WIN32 |
482 br_set_locate_fallback_func(gaim_find_binary_location, argv[0]); | |
483 #endif | |
484 #ifdef ENABLE_NLS | |
485 bindtextdomain(PACKAGE, LOCALEDIR); | |
486 bind_textdomain_codeset(PACKAGE, "UTF-8"); | |
487 textdomain(PACKAGE); | |
488 #endif | |
489 | |
490 #if HAVE_SIGNAL_H | |
491 /* Let's not violate any PLA's!!!! */ | |
492 /* jseymour: whatever the fsck that means */ | |
493 /* Robot101: for some reason things like gdm like to block * | |
494 * useful signals like SIGCHLD, so we unblock all the ones we * | |
495 * declare a handler for. thanks JSeymour and Vann. */ | |
496 if (sigemptyset(&sigset)) { | |
497 snprintf(errmsg, BUFSIZ, "Warning: couldn't initialise empty signal set"); | |
498 perror(errmsg); | |
499 } | |
500 for(sig_indx = 0; catch_sig_list[sig_indx] != -1; ++sig_indx) { | |
501 if((prev_sig_disp = signal(catch_sig_list[sig_indx], sighandler)) == SIG_ERR) { | |
502 snprintf(errmsg, BUFSIZ, "Warning: couldn't set signal %d for catching", | |
503 catch_sig_list[sig_indx]); | |
504 perror(errmsg); | |
505 } | |
506 if(sigaddset(&sigset, catch_sig_list[sig_indx])) { | |
507 snprintf(errmsg, BUFSIZ, "Warning: couldn't include signal %d for unblocking", | |
508 catch_sig_list[sig_indx]); | |
509 perror(errmsg); | |
510 } | |
511 } | |
512 for(sig_indx = 0; ignore_sig_list[sig_indx] != -1; ++sig_indx) { | |
513 if((prev_sig_disp = signal(ignore_sig_list[sig_indx], SIG_IGN)) == SIG_ERR) { | |
514 snprintf(errmsg, BUFSIZ, "Warning: couldn't set signal %d to ignore", | |
515 ignore_sig_list[sig_indx]); | |
516 perror(errmsg); | |
517 } | |
518 } | |
519 | |
520 if (sigprocmask(SIG_UNBLOCK, &sigset, NULL)) { | |
521 snprintf(errmsg, BUFSIZ, "Warning: couldn't unblock signals"); | |
522 perror(errmsg); | |
10307 | 523 } |
10302 | 524 #endif |
525 | |
10581
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
526 gui_check = gtk_init_check(&argc, &argv); |
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
527 if (!gui_check) { |
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
528 char *display = gdk_get_display(); |
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
529 |
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
530 g_warning("cannot open display: %s", display ? display : "unset"); |
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
531 g_free(display); |
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
532 |
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
533 return 1; |
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
534 } |
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
535 |
10302 | 536 /* scan command-line options */ |
537 opterr = 1; | |
538 while ((opt = getopt_long(argc, argv, | |
539 #ifndef _WIN32 | |
10323 | 540 "ac:dhnl::s:v", |
10302 | 541 #else |
10323 | 542 "ac:dhnl::v", |
10302 | 543 #endif |
544 long_options, NULL)) != -1) { | |
545 switch (opt) { | |
546 case 'a': /* account editor */ | |
10323 | 547 opt_acct = TRUE; |
548 break; | |
549 case 'c': /* config dir */ | |
550 g_free(opt_config_dir_arg); | |
551 opt_config_dir_arg = g_strdup(optarg); | |
10302 | 552 break; |
553 case 'd': /* debug */ | |
10307 | 554 debug_enabled = TRUE; |
10302 | 555 break; |
10323 | 556 case 'h': /* help */ |
557 opt_help = TRUE; | |
558 break; | |
559 case 'n': /* no autologin */ | |
560 opt_nologin = TRUE; | |
10302 | 561 break; |
10323 | 562 case 'l': /* login, option username */ |
563 opt_login = TRUE; | |
564 g_free(opt_login_arg); | |
565 if (optarg != NULL) | |
566 opt_login_arg = g_strdup(optarg); | |
10302 | 567 break; |
10320 | 568 case 's': /* use existing session ID */ |
10323 | 569 g_free(opt_session_arg); |
10320 | 570 opt_session_arg = g_strdup(optarg); |
571 break; | |
10323 | 572 case 'v': /* version */ |
573 opt_version = TRUE; | |
10320 | 574 break; |
10323 | 575 case '?': /* show terse help */ |
10302 | 576 default: |
10320 | 577 show_usage(argv[0], TRUE); |
10302 | 578 return 0; |
579 break; | |
580 } | |
581 } | |
582 | |
583 /* show help message */ | |
584 if (opt_help) { | |
10320 | 585 show_usage(argv[0], FALSE); |
10302 | 586 return 0; |
587 } | |
588 /* show version message */ | |
589 if (opt_version) { | |
10323 | 590 printf("Gaim %s\n", VERSION); |
10302 | 591 return 0; |
592 } | |
593 | |
10323 | 594 /* set a user-specified config directory */ |
595 if (opt_config_dir_arg != NULL) { | |
10871 | 596 gaim_util_set_user_dir(opt_config_dir_arg); |
10323 | 597 } |
598 | |
10448 | 599 /* |
600 * We're done piddling around with command line arguments. | |
601 * Fire up this baby. | |
602 */ | |
603 | |
604 gaim_debug_set_enabled(debug_enabled); | |
605 | |
10302 | 606 #ifdef _WIN32 |
10323 | 607 wgaim_init(hint); |
10302 | 608 #endif |
609 gaim_core_set_ui_ops(gaim_gtk_core_get_ui_ops()); | |
610 gaim_eventloop_set_ui_ops(gaim_gtk_eventloop_get_ui_ops()); | |
611 | |
10447 | 612 /* Set plugin search directories */ |
613 gaim_plugins_add_search_path(LIBDIR); | |
614 search_path = g_build_filename(gaim_user_dir(), "plugins", NULL); | |
615 gaim_plugins_add_search_path(search_path); | |
616 g_free(search_path); | |
617 | |
10302 | 618 if (!gaim_core_init(GAIM_GTK_UI)) { |
619 fprintf(stderr, | |
620 "Initialization of the Gaim core failed. Dumping core.\n" | |
621 "Please report this!\n"); | |
622 abort(); | |
623 } | |
624 | |
10428 | 625 /* TODO: Move blist loading into gaim_blist_init() */ |
10302 | 626 gaim_set_blist(gaim_blist_new()); |
627 gaim_blist_load(); | |
628 | |
10433 | 629 /* TODO: Move prefs loading into gaim_prefs_init() */ |
10302 | 630 gaim_prefs_load(); |
631 gaim_prefs_update_old(); | |
632 gaim_gtk_prefs_update_old(); | |
633 | |
634 /* load plugins we had when we quit */ | |
635 gaim_plugins_load_saved("/gaim/gtk/plugins/loaded"); | |
636 | |
10433 | 637 /* TODO: Move pounces loading into gaim_pounces_init() */ |
10302 | 638 gaim_pounces_load(); |
639 | |
640 ui_main(); | |
641 | |
642 #ifdef USE_SM | |
643 session_init(argv[0], opt_session_arg, opt_config_dir_arg); | |
644 #endif | |
645 if (opt_session_arg != NULL) { | |
646 g_free(opt_session_arg); | |
647 opt_session_arg = NULL; | |
648 } | |
649 if (opt_config_dir_arg != NULL) { | |
650 g_free(opt_config_dir_arg); | |
651 opt_config_dir_arg = NULL; | |
652 } | |
653 | |
654 if (gaim_prefs_get_bool("/gaim/gtk/debug/enabled")) | |
655 gaim_gtk_debug_window_show(); | |
656 | |
10323 | 657 gaim_blist_show(); |
658 | |
10302 | 659 if (opt_login) { |
660 dologin_ret = dologin_named(opt_login_arg); | |
661 if (opt_login_arg != NULL) { | |
662 g_free(opt_login_arg); | |
663 opt_login_arg = NULL; | |
664 } | |
665 } | |
666 | |
10738 | 667 if (!opt_acct && opt_nologin) |
668 { | |
669 /* TODO: Need to disable all accounts or set them all to offline */ | |
670 } | |
10302 | 671 |
10323 | 672 if (opt_acct || (gaim_accounts_get_all() == NULL)) { |
10302 | 673 gaim_gtk_accounts_window_show(); |
10315 | 674 } |
10302 | 675 |
676 #ifdef HAVE_STARTUP_NOTIFICATION | |
677 startup_notification_complete(); | |
678 #endif | |
10320 | 679 |
10302 | 680 gtk_main(); |
10320 | 681 |
10302 | 682 #ifdef _WIN32 |
683 wgaim_cleanup(); | |
684 #endif | |
685 | |
686 return 0; | |
687 } |