Mercurial > pidgin
annotate src/gtkmain.c @ 10703:a7486f12e56f
[gaim-migrate @ 12286]
Some kind of Gtk 2.4 support, it may not be implemented exactly how we want
it eventually, but it helps crazy people help us out. Thanks to Nathan
Fredrickson for doing the real work.
committer: Tailor Script <tailor@pidgin.im>
author | Stu Tomlinson <stu@nosnilmot.com> |
---|---|
date | Sun, 20 Mar 2005 01:23:06 +0000 |
parents | 222b53ee74f3 |
children | 55af3fa46329 |
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; | |
10404 | 117 gaim_account_connect(account, gaim_account_get_status(account, "online")); |
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; |
10404 | 124 gaim_account_connect(account, gaim_account_get_status(account, "online")); |
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 | |
10323 | 148 void |
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; |
10302 | 459 gchar *gaimrc, *accountsxml; |
10334 | 460 #if HAVE_SIGNAL_H |
10323 | 461 char errmsg[BUFSIZ]; |
10334 | 462 #endif |
10302 | 463 |
464 struct option long_options[] = { | |
10323 | 465 {"acct", no_argument, NULL, 'a'}, |
466 {"config", required_argument, NULL, 'c'}, | |
467 {"debug", no_argument, NULL, 'd'}, | |
468 {"help", no_argument, NULL, 'h'}, | |
469 {"login", optional_argument, NULL, 'l'}, | |
470 {"nologin", no_argument, NULL, 'n'}, | |
471 {"session", required_argument, NULL, 's'}, | |
472 {"version", no_argument, NULL, 'v'}, | |
10302 | 473 {0, 0, 0, 0} |
474 }; | |
475 | |
476 #ifdef DEBUG | |
10307 | 477 debug_enabled = TRUE; |
478 #else | |
479 debug_enabled = FALSE; | |
10302 | 480 #endif |
10307 | 481 |
10302 | 482 #ifndef _WIN32 |
483 br_set_locate_fallback_func(gaim_find_binary_location, argv[0]); | |
484 #endif | |
485 #ifdef ENABLE_NLS | |
486 bindtextdomain(PACKAGE, LOCALEDIR); | |
487 bind_textdomain_codeset(PACKAGE, "UTF-8"); | |
488 textdomain(PACKAGE); | |
489 #endif | |
490 | |
491 #if HAVE_SIGNAL_H | |
492 /* Let's not violate any PLA's!!!! */ | |
493 /* jseymour: whatever the fsck that means */ | |
494 /* Robot101: for some reason things like gdm like to block * | |
495 * useful signals like SIGCHLD, so we unblock all the ones we * | |
496 * declare a handler for. thanks JSeymour and Vann. */ | |
497 if (sigemptyset(&sigset)) { | |
498 snprintf(errmsg, BUFSIZ, "Warning: couldn't initialise empty signal set"); | |
499 perror(errmsg); | |
500 } | |
501 for(sig_indx = 0; catch_sig_list[sig_indx] != -1; ++sig_indx) { | |
502 if((prev_sig_disp = signal(catch_sig_list[sig_indx], sighandler)) == SIG_ERR) { | |
503 snprintf(errmsg, BUFSIZ, "Warning: couldn't set signal %d for catching", | |
504 catch_sig_list[sig_indx]); | |
505 perror(errmsg); | |
506 } | |
507 if(sigaddset(&sigset, catch_sig_list[sig_indx])) { | |
508 snprintf(errmsg, BUFSIZ, "Warning: couldn't include signal %d for unblocking", | |
509 catch_sig_list[sig_indx]); | |
510 perror(errmsg); | |
511 } | |
512 } | |
513 for(sig_indx = 0; ignore_sig_list[sig_indx] != -1; ++sig_indx) { | |
514 if((prev_sig_disp = signal(ignore_sig_list[sig_indx], SIG_IGN)) == SIG_ERR) { | |
515 snprintf(errmsg, BUFSIZ, "Warning: couldn't set signal %d to ignore", | |
516 ignore_sig_list[sig_indx]); | |
517 perror(errmsg); | |
518 } | |
519 } | |
520 | |
521 if (sigprocmask(SIG_UNBLOCK, &sigset, NULL)) { | |
522 snprintf(errmsg, BUFSIZ, "Warning: couldn't unblock signals"); | |
523 perror(errmsg); | |
10307 | 524 } |
10302 | 525 #endif |
526 | |
10581
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
527 gui_check = gtk_init_check(&argc, &argv); |
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
528 if (!gui_check) { |
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
529 char *display = gdk_get_display(); |
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
530 |
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
531 g_warning("cannot open display: %s", display ? display : "unset"); |
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
532 g_free(display); |
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
533 |
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
534 return 1; |
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
535 } |
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
536 |
10302 | 537 /* scan command-line options */ |
538 opterr = 1; | |
539 while ((opt = getopt_long(argc, argv, | |
540 #ifndef _WIN32 | |
10323 | 541 "ac:dhnl::s:v", |
10302 | 542 #else |
10323 | 543 "ac:dhnl::v", |
10302 | 544 #endif |
545 long_options, NULL)) != -1) { | |
546 switch (opt) { | |
547 case 'a': /* account editor */ | |
10323 | 548 opt_acct = TRUE; |
549 break; | |
550 case 'c': /* config dir */ | |
551 g_free(opt_config_dir_arg); | |
552 opt_config_dir_arg = g_strdup(optarg); | |
10302 | 553 break; |
554 case 'd': /* debug */ | |
10307 | 555 debug_enabled = TRUE; |
10302 | 556 break; |
10323 | 557 case 'h': /* help */ |
558 opt_help = TRUE; | |
559 break; | |
560 case 'n': /* no autologin */ | |
561 opt_nologin = TRUE; | |
10302 | 562 break; |
10323 | 563 case 'l': /* login, option username */ |
564 opt_login = TRUE; | |
565 g_free(opt_login_arg); | |
566 if (optarg != NULL) | |
567 opt_login_arg = g_strdup(optarg); | |
10302 | 568 break; |
10320 | 569 case 's': /* use existing session ID */ |
10323 | 570 g_free(opt_session_arg); |
10320 | 571 opt_session_arg = g_strdup(optarg); |
572 break; | |
10323 | 573 case 'v': /* version */ |
574 opt_version = TRUE; | |
10320 | 575 break; |
10323 | 576 case '?': /* show terse help */ |
10302 | 577 default: |
10320 | 578 show_usage(argv[0], TRUE); |
10302 | 579 return 0; |
580 break; | |
581 } | |
582 } | |
583 | |
584 /* show help message */ | |
585 if (opt_help) { | |
10320 | 586 show_usage(argv[0], FALSE); |
10302 | 587 return 0; |
588 } | |
589 /* show version message */ | |
590 if (opt_version) { | |
10323 | 591 printf("Gaim %s\n", VERSION); |
10302 | 592 return 0; |
593 } | |
594 | |
10323 | 595 /* set a user-specified config directory */ |
596 if (opt_config_dir_arg != NULL) { | |
597 set_gaim_user_dir(opt_config_dir_arg); | |
598 } | |
599 | |
10448 | 600 /* |
601 * We're done piddling around with command line arguments. | |
602 * Fire up this baby. | |
603 */ | |
604 | |
605 gaim_debug_set_enabled(debug_enabled); | |
606 | |
10302 | 607 #ifdef _WIN32 |
10323 | 608 wgaim_init(hint); |
10302 | 609 #endif |
610 gaim_core_set_ui_ops(gaim_gtk_core_get_ui_ops()); | |
611 gaim_eventloop_set_ui_ops(gaim_gtk_eventloop_get_ui_ops()); | |
612 | |
10447 | 613 /* Set plugin search directories */ |
614 gaim_plugins_add_search_path(LIBDIR); | |
615 gaim_plugins_add_search_path(gaim_user_dir()); | |
616 search_path = g_build_filename(gaim_user_dir(), "plugins", NULL); | |
617 gaim_plugins_add_search_path(search_path); | |
618 g_free(search_path); | |
619 | |
10302 | 620 if (!gaim_core_init(GAIM_GTK_UI)) { |
621 fprintf(stderr, | |
622 "Initialization of the Gaim core failed. Dumping core.\n" | |
623 "Please report this!\n"); | |
624 abort(); | |
625 } | |
626 | |
10428 | 627 /* TODO: Remove this check. Maybe in 2005. --KingAnt, 25 Jul 2004 */ |
10302 | 628 gaimrc = g_build_filename(gaim_home_dir(), ".gaimrc", NULL); |
629 accountsxml = g_build_filename(gaim_user_dir(), "accounts.xml", NULL); | |
630 if (g_file_test(gaimrc, G_FILE_TEST_EXISTS) && | |
10428 | 631 !g_file_test(accountsxml, G_FILE_TEST_EXISTS)) |
632 { | |
633 gaim_notify_error(NULL, NULL, _("Unable to load preferences"), | |
634 _("Gaim was not able to load your preferences " | |
635 "because they are stored in an old format " | |
636 "that is no longer used. Please reconfigure " | |
637 "your settings using the Preferences window.")); | |
10302 | 638 } |
639 g_free(gaimrc); | |
640 g_free(accountsxml); | |
641 | |
10428 | 642 /* TODO: Move blist loading into gaim_blist_init() */ |
10302 | 643 gaim_set_blist(gaim_blist_new()); |
644 gaim_blist_load(); | |
645 | |
10433 | 646 /* TODO: Move prefs loading into gaim_prefs_init() */ |
10302 | 647 gaim_prefs_load(); |
648 gaim_prefs_update_old(); | |
649 gaim_gtk_prefs_update_old(); | |
650 | |
651 /* load plugins we had when we quit */ | |
652 gaim_plugins_load_saved("/gaim/gtk/plugins/loaded"); | |
653 | |
10433 | 654 /* TODO: Move pounces loading into gaim_pounces_init() */ |
10302 | 655 gaim_pounces_load(); |
656 | |
657 ui_main(); | |
658 | |
659 #ifdef USE_SM | |
660 session_init(argv[0], opt_session_arg, opt_config_dir_arg); | |
661 #endif | |
662 if (opt_session_arg != NULL) { | |
663 g_free(opt_session_arg); | |
664 opt_session_arg = NULL; | |
665 } | |
666 if (opt_config_dir_arg != NULL) { | |
667 g_free(opt_config_dir_arg); | |
668 opt_config_dir_arg = NULL; | |
669 } | |
670 | |
671 if (gaim_prefs_get_bool("/gaim/gtk/debug/enabled")) | |
672 gaim_gtk_debug_window_show(); | |
673 | |
10323 | 674 gaim_blist_show(); |
675 | |
10302 | 676 if (opt_login) { |
677 dologin_ret = dologin_named(opt_login_arg); | |
678 if (opt_login_arg != NULL) { | |
679 g_free(opt_login_arg); | |
680 opt_login_arg = NULL; | |
681 } | |
682 } | |
683 | |
684 if (!opt_acct && !opt_nologin) | |
685 gaim_accounts_auto_login(GAIM_GTK_UI); | |
686 | |
10323 | 687 if (opt_acct || (gaim_accounts_get_all() == NULL)) { |
10302 | 688 gaim_gtk_accounts_window_show(); |
10315 | 689 } |
10302 | 690 |
691 #ifdef HAVE_STARTUP_NOTIFICATION | |
692 startup_notification_complete(); | |
693 #endif | |
10320 | 694 |
10302 | 695 gtk_main(); |
10320 | 696 |
10302 | 697 #ifdef _WIN32 |
698 wgaim_cleanup(); | |
699 #endif | |
700 | |
701 return 0; | |
702 } |