Mercurial > pidgin.yaz
annotate src/gtkmain.c @ 12190:ffedae3d3156
[gaim-migrate @ 14492]
Reverted logo.png. Trying out some new colors.
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Tue, 22 Nov 2005 18:56:53 +0000 |
parents | c4c612b8a648 |
children | 17be9401e167 |
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" | |
12024 | 51 #include "gtkmedia.h" |
11907 | 52 #include "gtkidle.h" |
10302 | 53 #include "gtknotify.h" |
54 #include "gtkplugin.h" | |
55 #include "gtkpounce.h" | |
56 #include "gtkprefs.h" | |
57 #include "gtkprivacy.h" | |
58 #include "gtkrequest.h" | |
59 #include "gtkroomlist.h" | |
10574 | 60 #include "gtksavedstatuses.h" |
10302 | 61 #include "gtksound.h" |
11525 | 62 #include "gtkthemes.h" |
10302 | 63 #include "gtkutils.h" |
64 #include "gtkstock.h" | |
11475
7fab28c991f3
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11403
diff
changeset
|
65 #include "gtkwhiteboard.h" |
10302 | 66 |
67 #if HAVE_SIGNAL_H | |
68 # include <signal.h> | |
69 #endif | |
70 | |
71 #include <getopt.h> | |
72 | |
73 #ifdef HAVE_STARTUP_NOTIFICATION | |
74 # define SN_API_NOT_YET_FROZEN | |
75 # include <libsn/sn-launchee.h> | |
76 # include <gdk/gdkx.h> | |
77 #endif | |
78 | |
11055 | 79 |
80 | |
10302 | 81 #ifdef HAVE_STARTUP_NOTIFICATION |
82 static SnLauncheeContext *sn_context = NULL; | |
83 static SnDisplay *sn_display = NULL; | |
84 #endif | |
85 | |
86 #if HAVE_SIGNAL_H | |
87 /* | |
88 * Lists of signals we wish to catch and those we wish to ignore. | |
89 * Each list terminated with -1 | |
90 */ | |
91 static int catch_sig_list[] = { | |
92 SIGSEGV, | |
93 SIGHUP, | |
94 SIGINT, | |
95 SIGTERM, | |
96 SIGQUIT, | |
97 SIGCHLD, | |
98 -1 | |
99 }; | |
100 | |
101 static int ignore_sig_list[] = { | |
102 SIGPIPE, | |
103 -1 | |
104 }; | |
105 #endif | |
106 | |
10323 | 107 static int |
108 dologin_named(const char *name) | |
10302 | 109 { |
110 GaimAccount *account; | |
10323 | 111 char **names; |
112 int i; | |
113 int ret = -1; | |
10302 | 114 |
10323 | 115 if (name != NULL) { /* list of names given */ |
116 names = g_strsplit(name, ",", 64); | |
117 for (i = 0; names[i] != NULL; i++) { | |
118 account = gaim_accounts_find(names[i], NULL); | |
119 if (account != NULL) { /* found a user */ | |
120 ret = 0; | |
10738 | 121 gaim_account_connect(account); |
10302 | 122 } |
123 } | |
124 g_strfreev(names); | |
10323 | 125 } else { /* no name given, use the first account */ |
11520 | 126 GList *accounts; |
127 | |
128 accounts = gaim_accounts_get_all(); | |
129 if (accounts != NULL) | |
130 { | |
131 account = (GaimAccount *)accounts->data; | |
132 ret = 0; | |
133 gaim_account_connect(account); | |
134 } | |
10302 | 135 } |
136 | |
10323 | 137 return ret; |
10302 | 138 } |
139 | |
10333 | 140 #if HAVE_SIGNAL_H |
10302 | 141 static void |
142 clean_pid(void) | |
143 { | |
144 int status; | |
145 pid_t pid; | |
146 | |
147 do { | |
148 pid = waitpid(-1, &status, WNOHANG); | |
149 } while (pid != 0 && pid != (pid_t)-1); | |
10334 | 150 |
151 if ((pid == (pid_t) - 1) && (errno != ECHILD)) { | |
10302 | 152 char errmsg[BUFSIZ]; |
153 snprintf(errmsg, BUFSIZ, "Warning: waitpid() returned %d", pid); | |
154 perror(errmsg); | |
155 } | |
156 } | |
157 | |
10871 | 158 static void |
10323 | 159 sighandler(int sig) |
10302 | 160 { |
161 switch (sig) { | |
162 case SIGHUP: | |
10323 | 163 gaim_debug_warning("sighandler", "Caught signal %d\n", sig); |
10302 | 164 gaim_connections_disconnect_all(); |
165 break; | |
166 case SIGSEGV: | |
167 #ifndef DEBUG | |
168 fprintf(stderr, "Gaim has segfaulted and attempted to dump a core file.\n" | |
169 "This is a bug in the software and has happened through\n" | |
170 "no fault of your own.\n\n" | |
171 "It is possible that this bug is already fixed in CVS.\n" | |
10323 | 172 "If you can reproduce the crash, please notify the gaim\n" |
10302 | 173 "maintainers by reporting a bug at\n" |
174 GAIM_WEBSITE "bug.php\n\n" | |
175 "Please make sure to specify what you were doing at the time,\n" | |
176 "and post the backtrace from the core file. If you do not know\n" | |
177 "how to get the backtrace, please get instructions at\n" | |
178 GAIM_WEBSITE "gdb.php. If you need further\n" | |
10638
222b53ee74f3
[gaim-migrate @ 12135]
Luke Schierer <lschiere@pidgin.im>
parents:
10589
diff
changeset
|
179 "assistance, please IM either SeanEgn or LSchiere and\n" |
10302 | 180 "they can help you.\n"); |
181 #else | |
182 fprintf(stderr, "Hi, user. We need to talk.\n" | |
183 "I think something's gone wrong here. It's probably my fault.\n" | |
184 "No, really, it's not you... it's me... no no no, I think we get along well\n" | |
185 "it's just that.... well, I want to see other people. I... what?!? NO! I haven't\n" | |
186 "been cheating on you!! How many times do you want me to tell you?! And for the\n" | |
187 "last time, it's just a rash!\n"); | |
188 /*g_on_error_query (g_get_prgname());*/ | |
189 #endif | |
190 abort(); | |
191 break; | |
192 case SIGCHLD: | |
193 clean_pid(); | |
194 signal(SIGCHLD, sighandler); /* restore signal catching on this one! */ | |
195 break; | |
196 default: | |
10323 | 197 gaim_debug_warning("sighandler", "Caught signal %d\n", sig); |
10302 | 198 gaim_connections_disconnect_all(); |
199 | |
200 gaim_plugins_unload_all(); | |
201 | |
202 if (gtk_main_level()) | |
203 gtk_main_quit(); | |
204 exit(0); | |
205 } | |
206 } | |
207 #endif | |
208 | |
10323 | 209 static int |
210 ui_main() | |
10302 | 211 { |
212 #ifndef _WIN32 | |
213 GList *icons = NULL; | |
214 GdkPixbuf *icon = NULL; | |
215 char *icon_path; | |
216 #endif | |
217 | |
11525 | 218 gaim_gtkthemes_init(); |
10302 | 219 |
220 gaim_gtk_blist_setup_sort_methods(); | |
221 | |
222 #ifndef _WIN32 | |
223 /* use the nice PNG icon for all the windows */ | |
224 icon_path = g_build_filename(DATADIR, "pixmaps", "gaim", "icons", "online.png", NULL); | |
225 icon = gdk_pixbuf_new_from_file(icon_path, NULL); | |
226 g_free(icon_path); | |
227 if (icon) { | |
228 icons = g_list_append(icons,icon); | |
229 gtk_window_set_default_icon_list(icons); | |
230 g_object_unref(G_OBJECT(icon)); | |
231 g_list_free(icons); | |
232 } else { | |
10323 | 233 gaim_debug_error("ui_main", |
234 "Failed to load the default window icon!\n"); | |
10302 | 235 } |
236 #endif | |
237 | |
238 return 0; | |
239 } | |
240 | |
241 static void | |
242 debug_init(void) | |
243 { | |
244 gaim_debug_set_ui_ops(gaim_gtk_debug_get_ui_ops()); | |
245 gaim_gtk_debug_init(); | |
246 } | |
247 | |
248 static void | |
249 gaim_gtk_ui_init(void) | |
250 { | |
251 /* Set the UI operation structures. */ | |
252 gaim_accounts_set_ui_ops(gaim_gtk_accounts_get_ui_ops()); | |
253 gaim_xfers_set_ui_ops(gaim_gtk_xfers_get_ui_ops()); | |
254 gaim_blist_set_ui_ops(gaim_gtk_blist_get_ui_ops()); | |
255 gaim_notify_set_ui_ops(gaim_gtk_notify_get_ui_ops()); | |
256 gaim_privacy_set_ui_ops(gaim_gtk_privacy_get_ui_ops()); | |
257 gaim_request_set_ui_ops(gaim_gtk_request_get_ui_ops()); | |
258 gaim_sound_set_ui_ops(gaim_gtk_sound_get_ui_ops()); | |
259 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
|
260 gaim_whiteboard_set_ui_ops(gaim_gtk_whiteboard_get_ui_ops()); |
10302 | 261 |
262 gaim_gtk_stock_init(); | |
263 gaim_gtk_prefs_init(); | |
264 gaim_gtk_account_init(); | |
265 gaim_gtk_blist_init(); | |
10574 | 266 gaim_gtk_status_init(); |
10302 | 267 gaim_gtk_conversations_init(); |
268 gaim_gtk_pounces_init(); | |
269 gaim_gtk_privacy_init(); | |
270 gaim_gtk_xfers_init(); | |
271 gaim_gtk_roomlist_init(); | |
12030
7165a7a444da
[gaim-migrate @ 14323]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12024
diff
changeset
|
272 #ifdef HAVE_VV |
12024 | 273 gaim_gtk_media_init(); |
274 #endif | |
11907 | 275 gaim_gtk_idle_init(); |
10302 | 276 } |
277 | |
278 static void | |
279 gaim_gtk_quit(void) | |
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(); |
11907 | 296 gaim_gtk_idle_uninit(); |
10574 | 297 |
10302 | 298 /* and end it all... */ |
299 gtk_main_quit(); | |
300 } | |
301 | |
302 static GaimCoreUiOps core_ops = | |
303 { | |
304 gaim_gtk_prefs_init, | |
305 debug_init, | |
306 gaim_gtk_ui_init, | |
307 gaim_gtk_quit | |
308 }; | |
309 | |
310 static GaimCoreUiOps * | |
311 gaim_gtk_core_get_ui_ops(void) | |
312 { | |
313 return &core_ops; | |
314 } | |
315 | |
316 static void | |
10320 | 317 show_usage(const char *name, gboolean terse) |
10302 | 318 { |
10320 | 319 char *text; |
320 char *text_conv; | |
321 GError *error = NULL; | |
10302 | 322 |
10320 | 323 if (terse) { |
324 text = g_strdup_printf(_("Gaim %s. Try `%s -h' for more information.\n"), VERSION, name); | |
325 } else { | |
326 text = g_strdup_printf(_("Gaim %s\n" | |
10302 | 327 "Usage: %s [OPTION]...\n\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" |
11673
922d0483ca88
[gaim-migrate @ 13959]
Richard Laager <rlaager@wiktel.com>
parents:
11581
diff
changeset
|
333 " account(s) to use, separated 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_help = FALSE; |
446 gboolean opt_login = FALSE; | |
447 gboolean opt_nologin = FALSE; | |
448 gboolean opt_version = FALSE; | |
449 char *opt_config_dir_arg = NULL; | |
450 char *opt_login_arg = NULL; | |
451 char *opt_session_arg = NULL; | |
452 int dologin_ret = -1; | |
10447 | 453 char *search_path; |
10302 | 454 #if HAVE_SIGNAL_H |
455 int sig_indx; /* for setting up signal catching */ | |
456 sigset_t sigset; | |
457 void (*prev_sig_disp)(); | |
458 #endif | |
10323 | 459 int opt; |
10302 | 460 gboolean gui_check; |
10307 | 461 gboolean debug_enabled; |
10334 | 462 #if HAVE_SIGNAL_H |
10323 | 463 char errmsg[BUFSIZ]; |
10334 | 464 #endif |
10302 | 465 |
466 struct option long_options[] = { | |
10323 | 467 {"config", required_argument, NULL, 'c'}, |
468 {"debug", no_argument, NULL, 'd'}, | |
469 {"help", no_argument, NULL, 'h'}, | |
470 {"login", optional_argument, NULL, 'l'}, | |
471 {"nologin", no_argument, NULL, 'n'}, | |
472 {"session", required_argument, NULL, 's'}, | |
473 {"version", no_argument, NULL, 'v'}, | |
10302 | 474 {0, 0, 0, 0} |
475 }; | |
476 | |
477 #ifdef DEBUG | |
10307 | 478 debug_enabled = TRUE; |
479 #else | |
480 debug_enabled = FALSE; | |
10302 | 481 #endif |
10307 | 482 |
10302 | 483 #ifndef _WIN32 |
484 br_set_locate_fallback_func(gaim_find_binary_location, argv[0]); | |
485 #endif | |
486 #ifdef ENABLE_NLS | |
487 bindtextdomain(PACKAGE, LOCALEDIR); | |
488 bind_textdomain_codeset(PACKAGE, "UTF-8"); | |
489 textdomain(PACKAGE); | |
490 #endif | |
491 | |
11080 | 492 |
10302 | 493 #if HAVE_SIGNAL_H |
494 /* Let's not violate any PLA's!!!! */ | |
495 /* jseymour: whatever the fsck that means */ | |
496 /* Robot101: for some reason things like gdm like to block * | |
497 * useful signals like SIGCHLD, so we unblock all the ones we * | |
498 * declare a handler for. thanks JSeymour and Vann. */ | |
499 if (sigemptyset(&sigset)) { | |
500 snprintf(errmsg, BUFSIZ, "Warning: couldn't initialise empty signal set"); | |
501 perror(errmsg); | |
502 } | |
503 for(sig_indx = 0; catch_sig_list[sig_indx] != -1; ++sig_indx) { | |
504 if((prev_sig_disp = signal(catch_sig_list[sig_indx], sighandler)) == SIG_ERR) { | |
505 snprintf(errmsg, BUFSIZ, "Warning: couldn't set signal %d for catching", | |
506 catch_sig_list[sig_indx]); | |
507 perror(errmsg); | |
508 } | |
509 if(sigaddset(&sigset, catch_sig_list[sig_indx])) { | |
510 snprintf(errmsg, BUFSIZ, "Warning: couldn't include signal %d for unblocking", | |
511 catch_sig_list[sig_indx]); | |
512 perror(errmsg); | |
513 } | |
514 } | |
515 for(sig_indx = 0; ignore_sig_list[sig_indx] != -1; ++sig_indx) { | |
516 if((prev_sig_disp = signal(ignore_sig_list[sig_indx], SIG_IGN)) == SIG_ERR) { | |
517 snprintf(errmsg, BUFSIZ, "Warning: couldn't set signal %d to ignore", | |
518 ignore_sig_list[sig_indx]); | |
519 perror(errmsg); | |
520 } | |
521 } | |
522 | |
523 if (sigprocmask(SIG_UNBLOCK, &sigset, NULL)) { | |
524 snprintf(errmsg, BUFSIZ, "Warning: couldn't unblock signals"); | |
525 perror(errmsg); | |
10307 | 526 } |
10302 | 527 #endif |
528 | |
10581
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
529 gui_check = gtk_init_check(&argc, &argv); |
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
530 if (!gui_check) { |
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
531 char *display = gdk_get_display(); |
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
532 |
11033
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11010
diff
changeset
|
533 printf("Gaim %s\n", VERSION); |
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11010
diff
changeset
|
534 |
10581
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
535 g_warning("cannot open display: %s", display ? display : "unset"); |
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
536 g_free(display); |
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
537 |
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
538 return 1; |
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 |
10302 | 541 /* scan command-line options */ |
542 opterr = 1; | |
543 while ((opt = getopt_long(argc, argv, | |
544 #ifndef _WIN32 | |
11795
f48e2acaa5d2
[gaim-migrate @ 14086]
Richard Laager <rlaager@wiktel.com>
parents:
11785
diff
changeset
|
545 "c:dhnl::s:v", |
10302 | 546 #else |
11795
f48e2acaa5d2
[gaim-migrate @ 14086]
Richard Laager <rlaager@wiktel.com>
parents:
11785
diff
changeset
|
547 "c:dhnl::v", |
10302 | 548 #endif |
549 long_options, NULL)) != -1) { | |
550 switch (opt) { | |
10323 | 551 case 'c': /* config dir */ |
552 g_free(opt_config_dir_arg); | |
553 opt_config_dir_arg = g_strdup(optarg); | |
10302 | 554 break; |
555 case 'd': /* debug */ | |
10307 | 556 debug_enabled = TRUE; |
10302 | 557 break; |
10323 | 558 case 'h': /* help */ |
559 opt_help = TRUE; | |
560 break; | |
561 case 'n': /* no autologin */ | |
562 opt_nologin = TRUE; | |
10302 | 563 break; |
10323 | 564 case 'l': /* login, option username */ |
565 opt_login = TRUE; | |
566 g_free(opt_login_arg); | |
567 if (optarg != NULL) | |
568 opt_login_arg = g_strdup(optarg); | |
10302 | 569 break; |
10320 | 570 case 's': /* use existing session ID */ |
10323 | 571 g_free(opt_session_arg); |
10320 | 572 opt_session_arg = g_strdup(optarg); |
573 break; | |
10323 | 574 case 'v': /* version */ |
575 opt_version = TRUE; | |
10320 | 576 break; |
10323 | 577 case '?': /* show terse help */ |
10302 | 578 default: |
10320 | 579 show_usage(argv[0], TRUE); |
10302 | 580 return 0; |
581 break; | |
582 } | |
583 } | |
584 | |
585 /* show help message */ | |
586 if (opt_help) { | |
10320 | 587 show_usage(argv[0], FALSE); |
10302 | 588 return 0; |
589 } | |
590 /* show version message */ | |
591 if (opt_version) { | |
10323 | 592 printf("Gaim %s\n", VERSION); |
10302 | 593 return 0; |
594 } | |
595 | |
10323 | 596 /* set a user-specified config directory */ |
597 if (opt_config_dir_arg != NULL) { | |
10871 | 598 gaim_util_set_user_dir(opt_config_dir_arg); |
10323 | 599 } |
600 | |
10448 | 601 /* |
602 * We're done piddling around with command line arguments. | |
603 * Fire up this baby. | |
604 */ | |
605 | |
606 gaim_debug_set_enabled(debug_enabled); | |
607 | |
10302 | 608 #ifdef _WIN32 |
10323 | 609 wgaim_init(hint); |
10302 | 610 #endif |
11067 | 611 |
10302 | 612 gaim_core_set_ui_ops(gaim_gtk_core_get_ui_ops()); |
613 gaim_eventloop_set_ui_ops(gaim_gtk_eventloop_get_ui_ops()); | |
614 | |
10447 | 615 /* Set plugin search directories */ |
616 gaim_plugins_add_search_path(LIBDIR); | |
617 search_path = g_build_filename(gaim_user_dir(), "plugins", NULL); | |
618 gaim_plugins_add_search_path(search_path); | |
619 g_free(search_path); | |
620 | |
10302 | 621 if (!gaim_core_init(GAIM_GTK_UI)) { |
622 fprintf(stderr, | |
623 "Initialization of the Gaim core failed. Dumping core.\n" | |
624 "Please report this!\n"); | |
625 abort(); | |
626 } | |
627 | |
10428 | 628 /* TODO: Move blist loading into gaim_blist_init() */ |
10302 | 629 gaim_set_blist(gaim_blist_new()); |
630 gaim_blist_load(); | |
631 | |
10433 | 632 /* TODO: Move prefs loading into gaim_prefs_init() */ |
10302 | 633 gaim_prefs_load(); |
634 gaim_prefs_update_old(); | |
635 gaim_gtk_prefs_update_old(); | |
636 | |
637 /* load plugins we had when we quit */ | |
638 gaim_plugins_load_saved("/gaim/gtk/plugins/loaded"); | |
639 | |
10433 | 640 /* TODO: Move pounces loading into gaim_pounces_init() */ |
10302 | 641 gaim_pounces_load(); |
642 | |
643 ui_main(); | |
644 | |
645 #ifdef USE_SM | |
646 session_init(argv[0], opt_session_arg, opt_config_dir_arg); | |
647 #endif | |
648 if (opt_session_arg != NULL) { | |
649 g_free(opt_session_arg); | |
650 opt_session_arg = NULL; | |
651 } | |
652 if (opt_config_dir_arg != NULL) { | |
653 g_free(opt_config_dir_arg); | |
654 opt_config_dir_arg = NULL; | |
655 } | |
656 | |
12011 | 657 /* |
658 * We want to show the blist early in the init process so the | |
659 * user feels warm and fuzzy (not cold and prickley). | |
660 */ | |
661 gaim_blist_show(); | |
662 | |
10302 | 663 if (gaim_prefs_get_bool("/gaim/gtk/debug/enabled")) |
664 gaim_gtk_debug_window_show(); | |
665 | |
666 if (opt_login) { | |
667 dologin_ret = dologin_named(opt_login_arg); | |
668 if (opt_login_arg != NULL) { | |
669 g_free(opt_login_arg); | |
670 opt_login_arg = NULL; | |
671 } | |
672 } | |
673 | |
11806 | 674 if (opt_nologin) |
675 { | |
676 /* Set all accounts to "offline" */ | |
677 GaimSavedStatus *saved_status; | |
678 saved_status = gaim_savedstatus_find(_("Default")); | |
679 if (saved_status == NULL) | |
680 saved_status = gaim_savedstatus_new(_("Default"), GAIM_STATUS_OFFLINE); | |
681 else | |
682 gaim_savedstatus_set_type(saved_status, GAIM_STATUS_OFFLINE); | |
683 gaim_savedstatus_activate(saved_status); | |
684 } | |
685 else | |
10738 | 686 { |
11348 | 687 /* Everything is good to go--sign on already */ |
688 gaim_accounts_restore_previous_statuses(); | |
10738 | 689 } |
10302 | 690 |
11785 | 691 if (gaim_accounts_get_all_active() == NULL) |
11403 | 692 { |
10302 | 693 gaim_gtk_accounts_window_show(); |
10315 | 694 } |
10302 | 695 |
696 #ifdef HAVE_STARTUP_NOTIFICATION | |
697 startup_notification_complete(); | |
698 #endif | |
10320 | 699 |
10302 | 700 gtk_main(); |
10320 | 701 |
10302 | 702 #ifdef _WIN32 |
703 wgaim_cleanup(); | |
704 #endif | |
705 | |
706 return 0; | |
707 } |