Mercurial > pidgin.yaz
annotate src/gtkmain.c @ 11403:f5b14ad58722
[gaim-migrate @ 13638]
We used to show the accounts list if we didn't have any accounts.
Now we show it if we don't have any enabled accounts (or if we have
no accounts at all).
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Thu, 01 Sep 2005 02:46:16 +0000 |
parents | efb358543b1d |
children | 7fab28c991f3 |
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 | |
11055 | 74 |
75 | |
10302 | 76 #ifdef HAVE_STARTUP_NOTIFICATION |
77 static SnLauncheeContext *sn_context = NULL; | |
78 static SnDisplay *sn_display = NULL; | |
79 #endif | |
80 | |
10448 | 81 /* TODO: Get this out of here? */ |
10302 | 82 int docklet_count = 0; |
83 | |
84 #if HAVE_SIGNAL_H | |
85 /* | |
86 * Lists of signals we wish to catch and those we wish to ignore. | |
87 * Each list terminated with -1 | |
88 */ | |
89 static int catch_sig_list[] = { | |
90 SIGSEGV, | |
91 SIGHUP, | |
92 SIGINT, | |
93 SIGTERM, | |
94 SIGQUIT, | |
95 SIGCHLD, | |
96 -1 | |
97 }; | |
98 | |
99 static int ignore_sig_list[] = { | |
100 SIGPIPE, | |
101 -1 | |
102 }; | |
103 #endif | |
104 | |
10323 | 105 static int |
106 dologin_named(const char *name) | |
10302 | 107 { |
108 GaimAccount *account; | |
10323 | 109 char **names; |
110 int i; | |
111 int ret = -1; | |
10302 | 112 |
10323 | 113 if (name != NULL) { /* list of names given */ |
114 names = g_strsplit(name, ",", 64); | |
115 for (i = 0; names[i] != NULL; i++) { | |
116 account = gaim_accounts_find(names[i], NULL); | |
117 if (account != NULL) { /* found a user */ | |
118 ret = 0; | |
10738 | 119 gaim_account_connect(account); |
10302 | 120 } |
121 } | |
122 g_strfreev(names); | |
10323 | 123 } else { /* no name given, use the first account */ |
10302 | 124 account = (GaimAccount *)gaim_accounts_get_all()->data; |
10323 | 125 ret = 0; |
10738 | 126 gaim_account_connect(account); |
10302 | 127 } |
128 | |
10323 | 129 return ret; |
10302 | 130 } |
131 | |
10333 | 132 #if HAVE_SIGNAL_H |
10302 | 133 static void |
134 clean_pid(void) | |
135 { | |
136 int status; | |
137 pid_t pid; | |
138 | |
139 do { | |
140 pid = waitpid(-1, &status, WNOHANG); | |
141 } while (pid != 0 && pid != (pid_t)-1); | |
10334 | 142 |
143 if ((pid == (pid_t) - 1) && (errno != ECHILD)) { | |
10302 | 144 char errmsg[BUFSIZ]; |
145 snprintf(errmsg, BUFSIZ, "Warning: waitpid() returned %d", pid); | |
146 perror(errmsg); | |
147 } | |
148 } | |
149 | |
10871 | 150 static void |
10323 | 151 sighandler(int sig) |
10302 | 152 { |
153 switch (sig) { | |
154 case SIGHUP: | |
10323 | 155 gaim_debug_warning("sighandler", "Caught signal %d\n", sig); |
10302 | 156 gaim_connections_disconnect_all(); |
157 break; | |
158 case SIGSEGV: | |
159 #ifndef DEBUG | |
160 fprintf(stderr, "Gaim has segfaulted and attempted to dump a core file.\n" | |
161 "This is a bug in the software and has happened through\n" | |
162 "no fault of your own.\n\n" | |
163 "It is possible that this bug is already fixed in CVS.\n" | |
10323 | 164 "If you can reproduce the crash, please notify the gaim\n" |
10302 | 165 "maintainers by reporting a bug at\n" |
166 GAIM_WEBSITE "bug.php\n\n" | |
167 "Please make sure to specify what you were doing at the time,\n" | |
168 "and post the backtrace from the core file. If you do not know\n" | |
169 "how to get the backtrace, please get instructions at\n" | |
170 GAIM_WEBSITE "gdb.php. If you need further\n" | |
10638
222b53ee74f3
[gaim-migrate @ 12135]
Luke Schierer <lschiere@pidgin.im>
parents:
10589
diff
changeset
|
171 "assistance, please IM either SeanEgn or LSchiere and\n" |
10302 | 172 "they can help you.\n"); |
173 #else | |
174 fprintf(stderr, "Hi, user. We need to talk.\n" | |
175 "I think something's gone wrong here. It's probably my fault.\n" | |
176 "No, really, it's not you... it's me... no no no, I think we get along well\n" | |
177 "it's just that.... well, I want to see other people. I... what?!? NO! I haven't\n" | |
178 "been cheating on you!! How many times do you want me to tell you?! And for the\n" | |
179 "last time, it's just a rash!\n"); | |
180 /*g_on_error_query (g_get_prgname());*/ | |
181 #endif | |
182 abort(); | |
183 break; | |
184 case SIGCHLD: | |
185 clean_pid(); | |
186 signal(SIGCHLD, sighandler); /* restore signal catching on this one! */ | |
187 break; | |
188 default: | |
10323 | 189 gaim_debug_warning("sighandler", "Caught signal %d\n", sig); |
10302 | 190 gaim_connections_disconnect_all(); |
191 | |
192 gaim_plugins_unload_all(); | |
193 | |
194 if (gtk_main_level()) | |
195 gtk_main_quit(); | |
196 exit(0); | |
197 } | |
198 } | |
199 #endif | |
200 | |
10323 | 201 static int |
202 ui_main() | |
10302 | 203 { |
204 #ifndef _WIN32 | |
205 GList *icons = NULL; | |
206 GdkPixbuf *icon = NULL; | |
207 char *icon_path; | |
208 #endif | |
209 | |
210 if (current_smiley_theme == NULL) { | |
211 smiley_theme_probe(); | |
10323 | 212 if (smiley_themes != NULL) { |
10302 | 213 struct smiley_theme *smile = smiley_themes->data; |
214 load_smiley_theme(smile->path, TRUE); | |
215 } | |
216 } | |
217 | |
218 gaim_gtk_blist_setup_sort_methods(); | |
219 | |
220 #ifndef _WIN32 | |
221 /* use the nice PNG icon for all the windows */ | |
222 icon_path = g_build_filename(DATADIR, "pixmaps", "gaim", "icons", "online.png", NULL); | |
223 icon = gdk_pixbuf_new_from_file(icon_path, NULL); | |
224 g_free(icon_path); | |
225 if (icon) { | |
226 icons = g_list_append(icons,icon); | |
227 gtk_window_set_default_icon_list(icons); | |
228 g_object_unref(G_OBJECT(icon)); | |
229 g_list_free(icons); | |
230 } else { | |
10323 | 231 gaim_debug_error("ui_main", |
232 "Failed to load the default window icon!\n"); | |
10302 | 233 } |
234 #endif | |
235 | |
236 return 0; | |
237 } | |
238 | |
239 static void | |
240 debug_init(void) | |
241 { | |
242 gaim_debug_set_ui_ops(gaim_gtk_debug_get_ui_ops()); | |
243 gaim_gtk_debug_init(); | |
244 } | |
245 | |
246 static void | |
247 gaim_gtk_ui_init(void) | |
248 { | |
249 /* Set the UI operation structures. */ | |
250 gaim_accounts_set_ui_ops(gaim_gtk_accounts_get_ui_ops()); | |
251 gaim_conversations_set_win_ui_ops(gaim_gtk_conversations_get_win_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()); | |
259 | |
260 gaim_gtk_stock_init(); | |
261 gaim_gtk_prefs_init(); | |
262 gaim_gtk_account_init(); | |
263 gaim_gtk_blist_init(); | |
10574 | 264 gaim_gtk_status_init(); |
10302 | 265 gaim_gtk_conversations_init(); |
266 gaim_gtk_pounces_init(); | |
267 gaim_gtk_privacy_init(); | |
268 gaim_gtk_xfers_init(); | |
269 gaim_gtk_roomlist_init(); | |
270 } | |
271 | |
272 static void | |
273 gaim_gtk_quit(void) | |
274 { | |
275 /* XXX? */ | |
276 /* YYY is there an XXX here? */ | |
277 | |
278 /* captain's log, stardate... */ | |
279 /* LOG system_log(log_quit, NULL, NULL, OPT_LOG_BUDDY_SIGNON | OPT_LOG_MY_SIGNON); */ | |
280 | |
281 #ifdef USE_SM | |
282 /* unplug */ | |
283 session_end(); | |
284 #endif | |
285 | |
286 /* Save the plugins we have loaded for next time. */ | |
287 gaim_gtk_plugins_save(); | |
288 | |
10574 | 289 /* Uninit */ |
290 gaim_gtk_conversations_uninit(); | |
291 gaim_gtk_status_uninit(); | |
292 gaim_gtk_blist_uninit(); | |
293 gaim_gtk_account_uninit(); | |
11010 | 294 gaim_gtk_xfers_uninit(); |
11033
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11010
diff
changeset
|
295 gaim_gtk_debug_uninit(); |
10574 | 296 |
10302 | 297 /* and end it all... */ |
298 gtk_main_quit(); | |
299 } | |
300 | |
301 static GaimCoreUiOps core_ops = | |
302 { | |
303 gaim_gtk_prefs_init, | |
304 debug_init, | |
305 gaim_gtk_ui_init, | |
306 gaim_gtk_quit | |
307 }; | |
308 | |
309 static GaimCoreUiOps * | |
310 gaim_gtk_core_get_ui_ops(void) | |
311 { | |
312 return &core_ops; | |
313 } | |
314 | |
315 static void | |
10320 | 316 show_usage(const char *name, gboolean terse) |
10302 | 317 { |
10320 | 318 char *text; |
319 char *text_conv; | |
320 GError *error = NULL; | |
10302 | 321 |
10320 | 322 if (terse) { |
323 text = g_strdup_printf(_("Gaim %s. Try `%s -h' for more information.\n"), VERSION, name); | |
324 } else { | |
325 text = g_strdup_printf(_("Gaim %s\n" | |
10302 | 326 "Usage: %s [OPTION]...\n\n" |
327 " -a, --acct display account editor window\n" | |
328 " -c, --config=DIR use DIR for config files\n" | |
329 " -d, --debug print debugging messages to stdout\n" | |
10320 | 330 " -h, --help display this help and exit\n" |
10323 | 331 " -n, --nologin don't automatically login\n" |
10320 | 332 " -l, --login[=NAME] automatically login (optional argument NAME specifies\n" |
333 " account(s) to use, seperated by commas)\n" | |
10323 | 334 " -v, --version display the current version and exit\n"), VERSION, name); |
10302 | 335 } |
336 | |
10320 | 337 /* tries to convert 'text' to users locale */ |
338 text_conv = g_locale_from_utf8(text, -1, NULL, NULL, &error); | |
339 if (text_conv != NULL) { | |
340 puts(text_conv); | |
341 g_free(text_conv); | |
10302 | 342 } |
10320 | 343 /* use 'text' as a fallback */ |
344 else { | |
345 g_warning("%s\n", error->message); | |
346 g_error_free(error); | |
347 puts(text); | |
348 } | |
349 g_free(text); | |
10302 | 350 } |
351 | |
352 #ifdef HAVE_STARTUP_NOTIFICATION | |
353 static void | |
354 sn_error_trap_push(SnDisplay *display, Display *xdisplay) | |
355 { | |
356 gdk_error_trap_push(); | |
357 } | |
358 | |
359 static void | |
360 sn_error_trap_pop(SnDisplay *display, Display *xdisplay) | |
361 { | |
362 gdk_error_trap_pop(); | |
363 } | |
364 | |
365 static void | |
366 startup_notification_complete(void) | |
367 { | |
368 Display *xdisplay; | |
369 | |
370 xdisplay = GDK_DISPLAY(); | |
371 sn_display = sn_display_new(xdisplay, | |
372 sn_error_trap_push, | |
373 sn_error_trap_pop); | |
374 sn_context = | |
375 sn_launchee_context_new_from_environment(sn_display, | |
376 DefaultScreen(xdisplay)); | |
377 | |
378 if (sn_context != NULL) | |
379 { | |
380 sn_launchee_context_complete(sn_context); | |
381 sn_launchee_context_unref(sn_context); | |
382 | |
383 sn_display_unref(sn_display); | |
384 } | |
385 } | |
386 #endif /* HAVE_STARTUP_NOTIFICATION */ | |
387 | |
388 #ifndef _WIN32 | |
389 static char *gaim_find_binary_location(void *symbol, void *data) | |
390 { | |
391 static char *fullname = NULL; | |
392 static gboolean first = TRUE; | |
393 | |
394 char *argv0 = data; | |
395 struct stat st; | |
396 char *basebuf, *linkbuf, *fullbuf; | |
397 | |
398 if (!first) | |
399 /* We've already been through this. */ | |
400 return strdup(fullname); | |
401 | |
402 first = FALSE; | |
403 | |
404 if (!argv0) | |
405 return NULL; | |
406 | |
407 | |
408 basebuf = g_find_program_in_path(argv0); | |
409 | |
410 /* But we still need to deal with symbolic links */ | |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10581
diff
changeset
|
411 g_lstat(basebuf, &st); |
10302 | 412 while ((st.st_mode & S_IFLNK) == S_IFLNK) { |
413 linkbuf = g_malloc(1024); | |
414 readlink(basebuf, linkbuf, 1024); | |
415 if (linkbuf[0] == G_DIR_SEPARATOR) { | |
416 /* an absolute path */ | |
417 fullbuf = g_strdup(linkbuf); | |
418 } else { | |
419 char *dirbuf = g_path_get_dirname(basebuf); | |
420 /* a relative path */ | |
421 fullbuf = g_strdup_printf("%s%s%s", | |
422 dirbuf, G_DIR_SEPARATOR_S, | |
423 linkbuf); | |
424 g_free(dirbuf); | |
425 } | |
426 /* There's no memory leak here. Really! */ | |
427 g_free(linkbuf); | |
428 g_free(basebuf); | |
429 basebuf = fullbuf; | |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10581
diff
changeset
|
430 g_lstat(basebuf, &st); |
10302 | 431 } |
432 | |
433 fullname = basebuf; | |
434 return strdup(fullname); | |
435 } | |
436 #endif /* #ifndef _WIN32 */ | |
437 | |
438 /* FUCKING GET ME A TOWEL! */ | |
439 #ifdef _WIN32 | |
440 int gaim_main(HINSTANCE hint, int argc, char *argv[]) | |
441 #else | |
442 int main(int argc, char *argv[]) | |
443 #endif | |
444 { | |
10323 | 445 gboolean opt_acct = FALSE; |
446 gboolean opt_help = FALSE; | |
447 gboolean opt_login = FALSE; | |
448 gboolean opt_nologin = FALSE; | |
449 gboolean opt_version = FALSE; | |
450 char *opt_config_dir_arg = NULL; | |
451 char *opt_login_arg = NULL; | |
452 char *opt_session_arg = NULL; | |
453 int dologin_ret = -1; | |
10447 | 454 char *search_path; |
10302 | 455 #if HAVE_SIGNAL_H |
456 int sig_indx; /* for setting up signal catching */ | |
457 sigset_t sigset; | |
458 void (*prev_sig_disp)(); | |
459 #endif | |
10323 | 460 int opt; |
10302 | 461 gboolean gui_check; |
10307 | 462 gboolean debug_enabled; |
10334 | 463 #if HAVE_SIGNAL_H |
10323 | 464 char errmsg[BUFSIZ]; |
10334 | 465 #endif |
10302 | 466 |
467 struct option long_options[] = { | |
10323 | 468 {"acct", no_argument, NULL, 'a'}, |
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 | |
10323 | 547 "ac:dhnl::s:v", |
10302 | 548 #else |
10323 | 549 "ac:dhnl::v", |
10302 | 550 #endif |
551 long_options, NULL)) != -1) { | |
552 switch (opt) { | |
553 case 'a': /* account editor */ | |
10323 | 554 opt_acct = TRUE; |
555 break; | |
556 case 'c': /* config dir */ | |
557 g_free(opt_config_dir_arg); | |
558 opt_config_dir_arg = g_strdup(optarg); | |
10302 | 559 break; |
560 case 'd': /* debug */ | |
10307 | 561 debug_enabled = TRUE; |
10302 | 562 break; |
10323 | 563 case 'h': /* help */ |
564 opt_help = TRUE; | |
565 break; | |
566 case 'n': /* no autologin */ | |
567 opt_nologin = TRUE; | |
10302 | 568 break; |
10323 | 569 case 'l': /* login, option username */ |
570 opt_login = TRUE; | |
571 g_free(opt_login_arg); | |
572 if (optarg != NULL) | |
573 opt_login_arg = g_strdup(optarg); | |
10302 | 574 break; |
10320 | 575 case 's': /* use existing session ID */ |
10323 | 576 g_free(opt_session_arg); |
10320 | 577 opt_session_arg = g_strdup(optarg); |
578 break; | |
10323 | 579 case 'v': /* version */ |
580 opt_version = TRUE; | |
10320 | 581 break; |
10323 | 582 case '?': /* show terse help */ |
10302 | 583 default: |
10320 | 584 show_usage(argv[0], TRUE); |
10302 | 585 return 0; |
586 break; | |
587 } | |
588 } | |
589 | |
590 /* show help message */ | |
591 if (opt_help) { | |
10320 | 592 show_usage(argv[0], FALSE); |
10302 | 593 return 0; |
594 } | |
595 /* show version message */ | |
596 if (opt_version) { | |
10323 | 597 printf("Gaim %s\n", VERSION); |
10302 | 598 return 0; |
599 } | |
600 | |
10323 | 601 /* set a user-specified config directory */ |
602 if (opt_config_dir_arg != NULL) { | |
10871 | 603 gaim_util_set_user_dir(opt_config_dir_arg); |
10323 | 604 } |
605 | |
10448 | 606 /* |
607 * We're done piddling around with command line arguments. | |
608 * Fire up this baby. | |
609 */ | |
610 | |
611 gaim_debug_set_enabled(debug_enabled); | |
612 | |
10302 | 613 #ifdef _WIN32 |
10323 | 614 wgaim_init(hint); |
10302 | 615 #endif |
11067 | 616 |
10302 | 617 gaim_core_set_ui_ops(gaim_gtk_core_get_ui_ops()); |
618 gaim_eventloop_set_ui_ops(gaim_gtk_eventloop_get_ui_ops()); | |
619 | |
10447 | 620 /* Set plugin search directories */ |
621 gaim_plugins_add_search_path(LIBDIR); | |
622 search_path = g_build_filename(gaim_user_dir(), "plugins", NULL); | |
623 gaim_plugins_add_search_path(search_path); | |
624 g_free(search_path); | |
625 | |
10302 | 626 if (!gaim_core_init(GAIM_GTK_UI)) { |
627 fprintf(stderr, | |
628 "Initialization of the Gaim core failed. Dumping core.\n" | |
629 "Please report this!\n"); | |
630 abort(); | |
631 } | |
632 | |
10428 | 633 /* TODO: Move blist loading into gaim_blist_init() */ |
10302 | 634 gaim_set_blist(gaim_blist_new()); |
635 gaim_blist_load(); | |
636 | |
10433 | 637 /* TODO: Move prefs loading into gaim_prefs_init() */ |
10302 | 638 gaim_prefs_load(); |
639 gaim_prefs_update_old(); | |
640 gaim_gtk_prefs_update_old(); | |
641 | |
642 /* load plugins we had when we quit */ | |
643 gaim_plugins_load_saved("/gaim/gtk/plugins/loaded"); | |
644 | |
10433 | 645 /* TODO: Move pounces loading into gaim_pounces_init() */ |
10302 | 646 gaim_pounces_load(); |
647 | |
648 ui_main(); | |
649 | |
650 #ifdef USE_SM | |
651 session_init(argv[0], opt_session_arg, opt_config_dir_arg); | |
652 #endif | |
653 if (opt_session_arg != NULL) { | |
654 g_free(opt_session_arg); | |
655 opt_session_arg = NULL; | |
656 } | |
657 if (opt_config_dir_arg != NULL) { | |
658 g_free(opt_config_dir_arg); | |
659 opt_config_dir_arg = NULL; | |
660 } | |
661 | |
662 if (gaim_prefs_get_bool("/gaim/gtk/debug/enabled")) | |
663 gaim_gtk_debug_window_show(); | |
664 | |
10323 | 665 gaim_blist_show(); |
666 | |
10302 | 667 if (opt_login) { |
668 dologin_ret = dologin_named(opt_login_arg); | |
669 if (opt_login_arg != NULL) { | |
670 g_free(opt_login_arg); | |
671 opt_login_arg = NULL; | |
672 } | |
673 } | |
674 | |
11348 | 675 if (!opt_acct && !opt_nologin) |
10738 | 676 { |
11348 | 677 /* Everything is good to go--sign on already */ |
678 gaim_accounts_restore_previous_statuses(); | |
10738 | 679 } |
10302 | 680 |
11403 | 681 if (opt_acct || (gaim_accounts_get_all_active() == NULL)) |
682 { | |
10302 | 683 gaim_gtk_accounts_window_show(); |
10315 | 684 } |
10302 | 685 |
686 #ifdef HAVE_STARTUP_NOTIFICATION | |
687 startup_notification_complete(); | |
688 #endif | |
10320 | 689 |
10302 | 690 gtk_main(); |
10320 | 691 |
10302 | 692 #ifdef _WIN32 |
693 wgaim_cleanup(); | |
694 #endif | |
695 | |
696 return 0; | |
697 } |