Mercurial > pidgin
annotate src/gtkmain.c @ 11520:2fdd2bd7755a
[gaim-migrate @ 13765]
Fix Debian bug #326852, reported by Sean Finney
committer: Tailor Script <tailor@pidgin.im>
| author | Mark Doliner <mark@kingant.net> |
|---|---|
| date | Sun, 11 Sep 2005 18:29:17 +0000 |
| parents | 7fab28c991f3 |
| children | b47708f46a38 |
| 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" |
| 60 #include "gtkutils.h" | |
| 61 #include "gtkstock.h" | |
|
11475
7fab28c991f3
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11403
diff
changeset
|
62 #include "gtkwhiteboard.h" |
| 10302 | 63 |
| 64 #if HAVE_SIGNAL_H | |
| 65 # include <signal.h> | |
| 66 #endif | |
| 67 | |
| 68 #include <getopt.h> | |
| 69 | |
| 70 #ifdef HAVE_STARTUP_NOTIFICATION | |
| 71 # define SN_API_NOT_YET_FROZEN | |
| 72 # include <libsn/sn-launchee.h> | |
| 73 # include <gdk/gdkx.h> | |
| 74 #endif | |
| 75 | |
| 11055 | 76 |
| 77 | |
| 10302 | 78 #ifdef HAVE_STARTUP_NOTIFICATION |
| 79 static SnLauncheeContext *sn_context = NULL; | |
| 80 static SnDisplay *sn_display = NULL; | |
| 81 #endif | |
| 82 | |
| 10448 | 83 /* TODO: Get this out of here? */ |
| 10302 | 84 int docklet_count = 0; |
| 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 | |
| 218 if (current_smiley_theme == NULL) { | |
| 219 smiley_theme_probe(); | |
| 10323 | 220 if (smiley_themes != NULL) { |
| 10302 | 221 struct smiley_theme *smile = smiley_themes->data; |
| 222 load_smiley_theme(smile->path, TRUE); | |
| 223 } | |
| 224 } | |
| 225 | |
| 226 gaim_gtk_blist_setup_sort_methods(); | |
| 227 | |
| 228 #ifndef _WIN32 | |
| 229 /* use the nice PNG icon for all the windows */ | |
| 230 icon_path = g_build_filename(DATADIR, "pixmaps", "gaim", "icons", "online.png", NULL); | |
| 231 icon = gdk_pixbuf_new_from_file(icon_path, NULL); | |
| 232 g_free(icon_path); | |
| 233 if (icon) { | |
| 234 icons = g_list_append(icons,icon); | |
| 235 gtk_window_set_default_icon_list(icons); | |
| 236 g_object_unref(G_OBJECT(icon)); | |
| 237 g_list_free(icons); | |
| 238 } else { | |
| 10323 | 239 gaim_debug_error("ui_main", |
| 240 "Failed to load the default window icon!\n"); | |
| 10302 | 241 } |
| 242 #endif | |
| 243 | |
| 244 return 0; | |
| 245 } | |
| 246 | |
| 247 static void | |
| 248 debug_init(void) | |
| 249 { | |
| 250 gaim_debug_set_ui_ops(gaim_gtk_debug_get_ui_ops()); | |
| 251 gaim_gtk_debug_init(); | |
| 252 } | |
| 253 | |
| 254 static void | |
| 255 gaim_gtk_ui_init(void) | |
| 256 { | |
| 257 /* Set the UI operation structures. */ | |
| 258 gaim_accounts_set_ui_ops(gaim_gtk_accounts_get_ui_ops()); | |
| 259 gaim_conversations_set_win_ui_ops(gaim_gtk_conversations_get_win_ui_ops()); | |
| 260 gaim_xfers_set_ui_ops(gaim_gtk_xfers_get_ui_ops()); | |
| 261 gaim_blist_set_ui_ops(gaim_gtk_blist_get_ui_ops()); | |
| 262 gaim_notify_set_ui_ops(gaim_gtk_notify_get_ui_ops()); | |
| 263 gaim_privacy_set_ui_ops(gaim_gtk_privacy_get_ui_ops()); | |
| 264 gaim_request_set_ui_ops(gaim_gtk_request_get_ui_ops()); | |
| 265 gaim_sound_set_ui_ops(gaim_gtk_sound_get_ui_ops()); | |
| 266 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
|
267 gaim_whiteboard_set_ui_ops(gaim_gtk_whiteboard_get_ui_ops()); |
| 10302 | 268 |
| 269 gaim_gtk_stock_init(); | |
| 270 gaim_gtk_prefs_init(); | |
| 271 gaim_gtk_account_init(); | |
| 272 gaim_gtk_blist_init(); | |
| 10574 | 273 gaim_gtk_status_init(); |
| 10302 | 274 gaim_gtk_conversations_init(); |
| 275 gaim_gtk_pounces_init(); | |
| 276 gaim_gtk_privacy_init(); | |
| 277 gaim_gtk_xfers_init(); | |
| 278 gaim_gtk_roomlist_init(); | |
| 279 } | |
| 280 | |
| 281 static void | |
| 282 gaim_gtk_quit(void) | |
| 283 { | |
| 284 /* XXX? */ | |
| 285 /* YYY is there an XXX here? */ | |
| 286 | |
| 287 /* captain's log, stardate... */ | |
| 288 /* LOG system_log(log_quit, NULL, NULL, OPT_LOG_BUDDY_SIGNON | OPT_LOG_MY_SIGNON); */ | |
| 289 | |
| 290 #ifdef USE_SM | |
| 291 /* unplug */ | |
| 292 session_end(); | |
| 293 #endif | |
| 294 | |
| 295 /* Save the plugins we have loaded for next time. */ | |
| 296 gaim_gtk_plugins_save(); | |
| 297 | |
| 10574 | 298 /* Uninit */ |
| 299 gaim_gtk_conversations_uninit(); | |
| 300 gaim_gtk_status_uninit(); | |
| 301 gaim_gtk_blist_uninit(); | |
| 302 gaim_gtk_account_uninit(); | |
| 11010 | 303 gaim_gtk_xfers_uninit(); |
|
11033
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11010
diff
changeset
|
304 gaim_gtk_debug_uninit(); |
| 10574 | 305 |
| 10302 | 306 /* and end it all... */ |
| 307 gtk_main_quit(); | |
| 308 } | |
| 309 | |
| 310 static GaimCoreUiOps core_ops = | |
| 311 { | |
| 312 gaim_gtk_prefs_init, | |
| 313 debug_init, | |
| 314 gaim_gtk_ui_init, | |
| 315 gaim_gtk_quit | |
| 316 }; | |
| 317 | |
| 318 static GaimCoreUiOps * | |
| 319 gaim_gtk_core_get_ui_ops(void) | |
| 320 { | |
| 321 return &core_ops; | |
| 322 } | |
| 323 | |
| 324 static void | |
| 10320 | 325 show_usage(const char *name, gboolean terse) |
| 10302 | 326 { |
| 10320 | 327 char *text; |
| 328 char *text_conv; | |
| 329 GError *error = NULL; | |
| 10302 | 330 |
| 10320 | 331 if (terse) { |
| 332 text = g_strdup_printf(_("Gaim %s. Try `%s -h' for more information.\n"), VERSION, name); | |
| 333 } else { | |
| 334 text = g_strdup_printf(_("Gaim %s\n" | |
| 10302 | 335 "Usage: %s [OPTION]...\n\n" |
| 336 " -a, --acct display account editor window\n" | |
| 337 " -c, --config=DIR use DIR for config files\n" | |
| 338 " -d, --debug print debugging messages to stdout\n" | |
| 10320 | 339 " -h, --help display this help and exit\n" |
| 10323 | 340 " -n, --nologin don't automatically login\n" |
| 10320 | 341 " -l, --login[=NAME] automatically login (optional argument NAME specifies\n" |
| 342 " account(s) to use, seperated by commas)\n" | |
| 10323 | 343 " -v, --version display the current version and exit\n"), VERSION, name); |
| 10302 | 344 } |
| 345 | |
| 10320 | 346 /* tries to convert 'text' to users locale */ |
| 347 text_conv = g_locale_from_utf8(text, -1, NULL, NULL, &error); | |
| 348 if (text_conv != NULL) { | |
| 349 puts(text_conv); | |
| 350 g_free(text_conv); | |
| 10302 | 351 } |
| 10320 | 352 /* use 'text' as a fallback */ |
| 353 else { | |
| 354 g_warning("%s\n", error->message); | |
| 355 g_error_free(error); | |
| 356 puts(text); | |
| 357 } | |
| 358 g_free(text); | |
| 10302 | 359 } |
| 360 | |
| 361 #ifdef HAVE_STARTUP_NOTIFICATION | |
| 362 static void | |
| 363 sn_error_trap_push(SnDisplay *display, Display *xdisplay) | |
| 364 { | |
| 365 gdk_error_trap_push(); | |
| 366 } | |
| 367 | |
| 368 static void | |
| 369 sn_error_trap_pop(SnDisplay *display, Display *xdisplay) | |
| 370 { | |
| 371 gdk_error_trap_pop(); | |
| 372 } | |
| 373 | |
| 374 static void | |
| 375 startup_notification_complete(void) | |
| 376 { | |
| 377 Display *xdisplay; | |
| 378 | |
| 379 xdisplay = GDK_DISPLAY(); | |
| 380 sn_display = sn_display_new(xdisplay, | |
| 381 sn_error_trap_push, | |
| 382 sn_error_trap_pop); | |
| 383 sn_context = | |
| 384 sn_launchee_context_new_from_environment(sn_display, | |
| 385 DefaultScreen(xdisplay)); | |
| 386 | |
| 387 if (sn_context != NULL) | |
| 388 { | |
| 389 sn_launchee_context_complete(sn_context); | |
| 390 sn_launchee_context_unref(sn_context); | |
| 391 | |
| 392 sn_display_unref(sn_display); | |
| 393 } | |
| 394 } | |
| 395 #endif /* HAVE_STARTUP_NOTIFICATION */ | |
| 396 | |
| 397 #ifndef _WIN32 | |
| 398 static char *gaim_find_binary_location(void *symbol, void *data) | |
| 399 { | |
| 400 static char *fullname = NULL; | |
| 401 static gboolean first = TRUE; | |
| 402 | |
| 403 char *argv0 = data; | |
| 404 struct stat st; | |
| 405 char *basebuf, *linkbuf, *fullbuf; | |
| 406 | |
| 407 if (!first) | |
| 408 /* We've already been through this. */ | |
| 409 return strdup(fullname); | |
| 410 | |
| 411 first = FALSE; | |
| 412 | |
| 413 if (!argv0) | |
| 414 return NULL; | |
| 415 | |
| 416 | |
| 417 basebuf = g_find_program_in_path(argv0); | |
| 418 | |
| 419 /* But we still need to deal with symbolic links */ | |
|
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10581
diff
changeset
|
420 g_lstat(basebuf, &st); |
| 10302 | 421 while ((st.st_mode & S_IFLNK) == S_IFLNK) { |
| 422 linkbuf = g_malloc(1024); | |
| 423 readlink(basebuf, linkbuf, 1024); | |
| 424 if (linkbuf[0] == G_DIR_SEPARATOR) { | |
| 425 /* an absolute path */ | |
| 426 fullbuf = g_strdup(linkbuf); | |
| 427 } else { | |
| 428 char *dirbuf = g_path_get_dirname(basebuf); | |
| 429 /* a relative path */ | |
| 430 fullbuf = g_strdup_printf("%s%s%s", | |
| 431 dirbuf, G_DIR_SEPARATOR_S, | |
| 432 linkbuf); | |
| 433 g_free(dirbuf); | |
| 434 } | |
| 435 /* There's no memory leak here. Really! */ | |
| 436 g_free(linkbuf); | |
| 437 g_free(basebuf); | |
| 438 basebuf = fullbuf; | |
|
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10581
diff
changeset
|
439 g_lstat(basebuf, &st); |
| 10302 | 440 } |
| 441 | |
| 442 fullname = basebuf; | |
| 443 return strdup(fullname); | |
| 444 } | |
| 445 #endif /* #ifndef _WIN32 */ | |
| 446 | |
| 447 /* FUCKING GET ME A TOWEL! */ | |
| 448 #ifdef _WIN32 | |
| 449 int gaim_main(HINSTANCE hint, int argc, char *argv[]) | |
| 450 #else | |
| 451 int main(int argc, char *argv[]) | |
| 452 #endif | |
| 453 { | |
| 10323 | 454 gboolean opt_acct = FALSE; |
| 455 gboolean opt_help = FALSE; | |
| 456 gboolean opt_login = FALSE; | |
| 457 gboolean opt_nologin = FALSE; | |
| 458 gboolean opt_version = FALSE; | |
| 459 char *opt_config_dir_arg = NULL; | |
| 460 char *opt_login_arg = NULL; | |
| 461 char *opt_session_arg = NULL; | |
| 462 int dologin_ret = -1; | |
| 10447 | 463 char *search_path; |
| 10302 | 464 #if HAVE_SIGNAL_H |
| 465 int sig_indx; /* for setting up signal catching */ | |
| 466 sigset_t sigset; | |
| 467 void (*prev_sig_disp)(); | |
| 468 #endif | |
| 10323 | 469 int opt; |
| 10302 | 470 gboolean gui_check; |
| 10307 | 471 gboolean debug_enabled; |
| 10334 | 472 #if HAVE_SIGNAL_H |
| 10323 | 473 char errmsg[BUFSIZ]; |
| 10334 | 474 #endif |
| 10302 | 475 |
| 476 struct option long_options[] = { | |
| 10323 | 477 {"acct", no_argument, NULL, 'a'}, |
| 478 {"config", required_argument, NULL, 'c'}, | |
| 479 {"debug", no_argument, NULL, 'd'}, | |
| 480 {"help", no_argument, NULL, 'h'}, | |
| 481 {"login", optional_argument, NULL, 'l'}, | |
| 482 {"nologin", no_argument, NULL, 'n'}, | |
| 483 {"session", required_argument, NULL, 's'}, | |
| 484 {"version", no_argument, NULL, 'v'}, | |
| 10302 | 485 {0, 0, 0, 0} |
| 486 }; | |
| 487 | |
| 488 #ifdef DEBUG | |
| 10307 | 489 debug_enabled = TRUE; |
| 490 #else | |
| 491 debug_enabled = FALSE; | |
| 10302 | 492 #endif |
| 10307 | 493 |
| 10302 | 494 #ifndef _WIN32 |
| 495 br_set_locate_fallback_func(gaim_find_binary_location, argv[0]); | |
| 496 #endif | |
| 497 #ifdef ENABLE_NLS | |
| 498 bindtextdomain(PACKAGE, LOCALEDIR); | |
| 499 bind_textdomain_codeset(PACKAGE, "UTF-8"); | |
| 500 textdomain(PACKAGE); | |
| 501 #endif | |
| 502 | |
| 11080 | 503 |
| 10302 | 504 #if HAVE_SIGNAL_H |
| 505 /* Let's not violate any PLA's!!!! */ | |
| 506 /* jseymour: whatever the fsck that means */ | |
| 507 /* Robot101: for some reason things like gdm like to block * | |
| 508 * useful signals like SIGCHLD, so we unblock all the ones we * | |
| 509 * declare a handler for. thanks JSeymour and Vann. */ | |
| 510 if (sigemptyset(&sigset)) { | |
| 511 snprintf(errmsg, BUFSIZ, "Warning: couldn't initialise empty signal set"); | |
| 512 perror(errmsg); | |
| 513 } | |
| 514 for(sig_indx = 0; catch_sig_list[sig_indx] != -1; ++sig_indx) { | |
| 515 if((prev_sig_disp = signal(catch_sig_list[sig_indx], sighandler)) == SIG_ERR) { | |
| 516 snprintf(errmsg, BUFSIZ, "Warning: couldn't set signal %d for catching", | |
| 517 catch_sig_list[sig_indx]); | |
| 518 perror(errmsg); | |
| 519 } | |
| 520 if(sigaddset(&sigset, catch_sig_list[sig_indx])) { | |
| 521 snprintf(errmsg, BUFSIZ, "Warning: couldn't include signal %d for unblocking", | |
| 522 catch_sig_list[sig_indx]); | |
| 523 perror(errmsg); | |
| 524 } | |
| 525 } | |
| 526 for(sig_indx = 0; ignore_sig_list[sig_indx] != -1; ++sig_indx) { | |
| 527 if((prev_sig_disp = signal(ignore_sig_list[sig_indx], SIG_IGN)) == SIG_ERR) { | |
| 528 snprintf(errmsg, BUFSIZ, "Warning: couldn't set signal %d to ignore", | |
| 529 ignore_sig_list[sig_indx]); | |
| 530 perror(errmsg); | |
| 531 } | |
| 532 } | |
| 533 | |
| 534 if (sigprocmask(SIG_UNBLOCK, &sigset, NULL)) { | |
| 535 snprintf(errmsg, BUFSIZ, "Warning: couldn't unblock signals"); | |
| 536 perror(errmsg); | |
| 10307 | 537 } |
| 10302 | 538 #endif |
| 539 | |
|
10581
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
540 gui_check = gtk_init_check(&argc, &argv); |
|
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
541 if (!gui_check) { |
|
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
542 char *display = gdk_get_display(); |
|
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
543 |
|
11033
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11010
diff
changeset
|
544 printf("Gaim %s\n", VERSION); |
|
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11010
diff
changeset
|
545 |
|
10581
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
546 g_warning("cannot open display: %s", display ? display : "unset"); |
|
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
547 g_free(display); |
|
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
548 |
|
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
549 return 1; |
|
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
550 } |
|
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
551 |
| 10302 | 552 /* scan command-line options */ |
| 553 opterr = 1; | |
| 554 while ((opt = getopt_long(argc, argv, | |
| 555 #ifndef _WIN32 | |
| 10323 | 556 "ac:dhnl::s:v", |
| 10302 | 557 #else |
| 10323 | 558 "ac:dhnl::v", |
| 10302 | 559 #endif |
| 560 long_options, NULL)) != -1) { | |
| 561 switch (opt) { | |
| 562 case 'a': /* account editor */ | |
| 10323 | 563 opt_acct = TRUE; |
| 564 break; | |
| 565 case 'c': /* config dir */ | |
| 566 g_free(opt_config_dir_arg); | |
| 567 opt_config_dir_arg = g_strdup(optarg); | |
| 10302 | 568 break; |
| 569 case 'd': /* debug */ | |
| 10307 | 570 debug_enabled = TRUE; |
| 10302 | 571 break; |
| 10323 | 572 case 'h': /* help */ |
| 573 opt_help = TRUE; | |
| 574 break; | |
| 575 case 'n': /* no autologin */ | |
| 576 opt_nologin = TRUE; | |
| 10302 | 577 break; |
| 10323 | 578 case 'l': /* login, option username */ |
| 579 opt_login = TRUE; | |
| 580 g_free(opt_login_arg); | |
| 581 if (optarg != NULL) | |
| 582 opt_login_arg = g_strdup(optarg); | |
| 10302 | 583 break; |
| 10320 | 584 case 's': /* use existing session ID */ |
| 10323 | 585 g_free(opt_session_arg); |
| 10320 | 586 opt_session_arg = g_strdup(optarg); |
| 587 break; | |
| 10323 | 588 case 'v': /* version */ |
| 589 opt_version = TRUE; | |
| 10320 | 590 break; |
| 10323 | 591 case '?': /* show terse help */ |
| 10302 | 592 default: |
| 10320 | 593 show_usage(argv[0], TRUE); |
| 10302 | 594 return 0; |
| 595 break; | |
| 596 } | |
| 597 } | |
| 598 | |
| 599 /* show help message */ | |
| 600 if (opt_help) { | |
| 10320 | 601 show_usage(argv[0], FALSE); |
| 10302 | 602 return 0; |
| 603 } | |
| 604 /* show version message */ | |
| 605 if (opt_version) { | |
| 10323 | 606 printf("Gaim %s\n", VERSION); |
| 10302 | 607 return 0; |
| 608 } | |
| 609 | |
| 10323 | 610 /* set a user-specified config directory */ |
| 611 if (opt_config_dir_arg != NULL) { | |
| 10871 | 612 gaim_util_set_user_dir(opt_config_dir_arg); |
| 10323 | 613 } |
| 614 | |
| 10448 | 615 /* |
| 616 * We're done piddling around with command line arguments. | |
| 617 * Fire up this baby. | |
| 618 */ | |
| 619 | |
| 620 gaim_debug_set_enabled(debug_enabled); | |
| 621 | |
| 10302 | 622 #ifdef _WIN32 |
| 10323 | 623 wgaim_init(hint); |
| 10302 | 624 #endif |
| 11067 | 625 |
| 10302 | 626 gaim_core_set_ui_ops(gaim_gtk_core_get_ui_ops()); |
| 627 gaim_eventloop_set_ui_ops(gaim_gtk_eventloop_get_ui_ops()); | |
| 628 | |
| 10447 | 629 /* Set plugin search directories */ |
| 630 gaim_plugins_add_search_path(LIBDIR); | |
| 631 search_path = g_build_filename(gaim_user_dir(), "plugins", NULL); | |
| 632 gaim_plugins_add_search_path(search_path); | |
| 633 g_free(search_path); | |
| 634 | |
| 10302 | 635 if (!gaim_core_init(GAIM_GTK_UI)) { |
| 636 fprintf(stderr, | |
| 637 "Initialization of the Gaim core failed. Dumping core.\n" | |
| 638 "Please report this!\n"); | |
| 639 abort(); | |
| 640 } | |
| 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 | |
| 11348 | 684 if (!opt_acct && !opt_nologin) |
| 10738 | 685 { |
| 11348 | 686 /* Everything is good to go--sign on already */ |
| 687 gaim_accounts_restore_previous_statuses(); | |
| 10738 | 688 } |
| 10302 | 689 |
| 11403 | 690 if (opt_acct || (gaim_accounts_get_all_active() == NULL)) |
| 691 { | |
| 10302 | 692 gaim_gtk_accounts_window_show(); |
| 10315 | 693 } |
| 10302 | 694 |
| 695 #ifdef HAVE_STARTUP_NOTIFICATION | |
| 696 startup_notification_complete(); | |
| 697 #endif | |
| 10320 | 698 |
| 10302 | 699 gtk_main(); |
| 10320 | 700 |
| 10302 | 701 #ifdef _WIN32 |
| 702 wgaim_cleanup(); | |
| 703 #endif | |
| 704 | |
| 705 return 0; | |
| 706 } |
