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