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