Mercurial > pidgin
annotate src/gtkmain.c @ 11124:00a2a480fc0c
[gaim-migrate @ 13180]
Oopps...should build now.
committer: Tailor Script <tailor@pidgin.im>
| author | John H. Kelm <johnkelm@gmail.com> |
|---|---|
| date | Tue, 19 Jul 2005 00:04:44 +0000 |
| parents | f54740547c95 |
| children | ebb02ea3c789 |
| 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 #ifdef HAVE_DBUS |
| 75 # include "dbus-server.h" | |
| 76 #endif | |
| 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 */ |
| 10302 | 127 account = (GaimAccount *)gaim_accounts_get_all()->data; |
| 10323 | 128 ret = 0; |
| 10738 | 129 gaim_account_connect(account); |
| 10302 | 130 } |
| 131 | |
| 10323 | 132 return ret; |
| 10302 | 133 } |
| 134 | |
| 10333 | 135 #if HAVE_SIGNAL_H |
| 10302 | 136 static void |
| 137 clean_pid(void) | |
| 138 { | |
| 139 int status; | |
| 140 pid_t pid; | |
| 141 | |
| 142 do { | |
| 143 pid = waitpid(-1, &status, WNOHANG); | |
| 144 } while (pid != 0 && pid != (pid_t)-1); | |
| 10334 | 145 |
| 146 if ((pid == (pid_t) - 1) && (errno != ECHILD)) { | |
| 10302 | 147 char errmsg[BUFSIZ]; |
| 148 snprintf(errmsg, BUFSIZ, "Warning: waitpid() returned %d", pid); | |
| 149 perror(errmsg); | |
| 150 } | |
| 151 } | |
| 152 | |
| 10871 | 153 static void |
| 10323 | 154 sighandler(int sig) |
| 10302 | 155 { |
| 156 switch (sig) { | |
| 157 case SIGHUP: | |
| 10323 | 158 gaim_debug_warning("sighandler", "Caught signal %d\n", sig); |
| 10302 | 159 gaim_connections_disconnect_all(); |
| 160 break; | |
| 161 case SIGSEGV: | |
| 162 #ifndef DEBUG | |
| 163 fprintf(stderr, "Gaim has segfaulted and attempted to dump a core file.\n" | |
| 164 "This is a bug in the software and has happened through\n" | |
| 165 "no fault of your own.\n\n" | |
| 166 "It is possible that this bug is already fixed in CVS.\n" | |
| 10323 | 167 "If you can reproduce the crash, please notify the gaim\n" |
| 10302 | 168 "maintainers by reporting a bug at\n" |
| 169 GAIM_WEBSITE "bug.php\n\n" | |
| 170 "Please make sure to specify what you were doing at the time,\n" | |
| 171 "and post the backtrace from the core file. If you do not know\n" | |
| 172 "how to get the backtrace, please get instructions at\n" | |
| 173 GAIM_WEBSITE "gdb.php. If you need further\n" | |
|
10638
222b53ee74f3
[gaim-migrate @ 12135]
Luke Schierer <lschiere@pidgin.im>
parents:
10589
diff
changeset
|
174 "assistance, please IM either SeanEgn or LSchiere and\n" |
| 10302 | 175 "they can help you.\n"); |
| 176 #else | |
| 177 fprintf(stderr, "Hi, user. We need to talk.\n" | |
| 178 "I think something's gone wrong here. It's probably my fault.\n" | |
| 179 "No, really, it's not you... it's me... no no no, I think we get along well\n" | |
| 180 "it's just that.... well, I want to see other people. I... what?!? NO! I haven't\n" | |
| 181 "been cheating on you!! How many times do you want me to tell you?! And for the\n" | |
| 182 "last time, it's just a rash!\n"); | |
| 183 /*g_on_error_query (g_get_prgname());*/ | |
| 184 #endif | |
| 185 abort(); | |
| 186 break; | |
| 187 case SIGCHLD: | |
| 188 clean_pid(); | |
| 189 signal(SIGCHLD, sighandler); /* restore signal catching on this one! */ | |
| 190 break; | |
| 191 default: | |
| 10323 | 192 gaim_debug_warning("sighandler", "Caught signal %d\n", sig); |
| 10302 | 193 gaim_connections_disconnect_all(); |
| 194 | |
| 195 gaim_plugins_unload_all(); | |
| 196 | |
| 197 if (gtk_main_level()) | |
| 198 gtk_main_quit(); | |
| 199 exit(0); | |
| 200 } | |
| 201 } | |
| 202 #endif | |
| 203 | |
| 10323 | 204 static int |
| 205 ui_main() | |
| 10302 | 206 { |
| 207 #ifndef _WIN32 | |
| 208 GList *icons = NULL; | |
| 209 GdkPixbuf *icon = NULL; | |
| 210 char *icon_path; | |
| 211 #endif | |
| 212 | |
| 213 if (current_smiley_theme == NULL) { | |
| 214 smiley_theme_probe(); | |
| 10323 | 215 if (smiley_themes != NULL) { |
| 10302 | 216 struct smiley_theme *smile = smiley_themes->data; |
| 217 load_smiley_theme(smile->path, TRUE); | |
| 218 } | |
| 219 } | |
| 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()); | |
| 262 | |
| 263 gaim_gtk_stock_init(); | |
| 264 gaim_gtk_prefs_init(); | |
| 265 gaim_gtk_account_init(); | |
| 266 gaim_gtk_blist_init(); | |
| 10574 | 267 gaim_gtk_status_init(); |
| 10302 | 268 gaim_gtk_conversations_init(); |
| 269 gaim_gtk_pounces_init(); | |
| 270 gaim_gtk_privacy_init(); | |
| 271 gaim_gtk_xfers_init(); | |
| 272 gaim_gtk_roomlist_init(); | |
| 273 } | |
| 274 | |
| 275 static void | |
| 276 gaim_gtk_quit(void) | |
| 277 { | |
| 278 /* XXX? */ | |
| 279 /* YYY is there an XXX here? */ | |
| 280 | |
| 281 /* captain's log, stardate... */ | |
| 282 /* LOG system_log(log_quit, NULL, NULL, OPT_LOG_BUDDY_SIGNON | OPT_LOG_MY_SIGNON); */ | |
| 283 | |
| 284 #ifdef USE_SM | |
| 285 /* unplug */ | |
| 286 session_end(); | |
| 287 #endif | |
| 288 | |
| 289 /* Save the plugins we have loaded for next time. */ | |
| 290 gaim_gtk_plugins_save(); | |
| 291 | |
| 10574 | 292 /* Uninit */ |
| 293 gaim_gtk_conversations_uninit(); | |
| 294 gaim_gtk_status_uninit(); | |
| 295 gaim_gtk_blist_uninit(); | |
| 296 gaim_gtk_account_uninit(); | |
| 11010 | 297 gaim_gtk_xfers_uninit(); |
|
11033
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11010
diff
changeset
|
298 gaim_gtk_debug_uninit(); |
| 10574 | 299 |
| 10302 | 300 /* and end it all... */ |
| 301 gtk_main_quit(); | |
| 302 } | |
| 303 | |
| 304 static GaimCoreUiOps core_ops = | |
| 305 { | |
| 306 gaim_gtk_prefs_init, | |
| 307 debug_init, | |
| 308 gaim_gtk_ui_init, | |
| 309 gaim_gtk_quit | |
| 310 }; | |
| 311 | |
| 312 static GaimCoreUiOps * | |
| 313 gaim_gtk_core_get_ui_ops(void) | |
| 314 { | |
| 315 return &core_ops; | |
| 316 } | |
| 317 | |
| 318 static void | |
| 10320 | 319 show_usage(const char *name, gboolean terse) |
| 10302 | 320 { |
| 10320 | 321 char *text; |
| 322 char *text_conv; | |
| 323 GError *error = NULL; | |
| 10302 | 324 |
| 10320 | 325 if (terse) { |
| 326 text = g_strdup_printf(_("Gaim %s. Try `%s -h' for more information.\n"), VERSION, name); | |
| 327 } else { | |
| 328 text = g_strdup_printf(_("Gaim %s\n" | |
| 10302 | 329 "Usage: %s [OPTION]...\n\n" |
| 330 " -a, --acct display account editor window\n" | |
| 331 " -c, --config=DIR use DIR for config files\n" | |
| 332 " -d, --debug print debugging messages to stdout\n" | |
| 10320 | 333 " -h, --help display this help and exit\n" |
| 10323 | 334 " -n, --nologin don't automatically login\n" |
| 10320 | 335 " -l, --login[=NAME] automatically login (optional argument NAME specifies\n" |
| 336 " account(s) to use, seperated by commas)\n" | |
| 10323 | 337 " -v, --version display the current version and exit\n"), VERSION, name); |
| 10302 | 338 } |
| 339 | |
| 10320 | 340 /* tries to convert 'text' to users locale */ |
| 341 text_conv = g_locale_from_utf8(text, -1, NULL, NULL, &error); | |
| 342 if (text_conv != NULL) { | |
| 343 puts(text_conv); | |
| 344 g_free(text_conv); | |
| 10302 | 345 } |
| 10320 | 346 /* use 'text' as a fallback */ |
| 347 else { | |
| 348 g_warning("%s\n", error->message); | |
| 349 g_error_free(error); | |
| 350 puts(text); | |
| 351 } | |
| 352 g_free(text); | |
| 10302 | 353 } |
| 354 | |
| 355 #ifdef HAVE_STARTUP_NOTIFICATION | |
| 356 static void | |
| 357 sn_error_trap_push(SnDisplay *display, Display *xdisplay) | |
| 358 { | |
| 359 gdk_error_trap_push(); | |
| 360 } | |
| 361 | |
| 362 static void | |
| 363 sn_error_trap_pop(SnDisplay *display, Display *xdisplay) | |
| 364 { | |
| 365 gdk_error_trap_pop(); | |
| 366 } | |
| 367 | |
| 368 static void | |
| 369 startup_notification_complete(void) | |
| 370 { | |
| 371 Display *xdisplay; | |
| 372 | |
| 373 xdisplay = GDK_DISPLAY(); | |
| 374 sn_display = sn_display_new(xdisplay, | |
| 375 sn_error_trap_push, | |
| 376 sn_error_trap_pop); | |
| 377 sn_context = | |
| 378 sn_launchee_context_new_from_environment(sn_display, | |
| 379 DefaultScreen(xdisplay)); | |
| 380 | |
| 381 if (sn_context != NULL) | |
| 382 { | |
| 383 sn_launchee_context_complete(sn_context); | |
| 384 sn_launchee_context_unref(sn_context); | |
| 385 | |
| 386 sn_display_unref(sn_display); | |
| 387 } | |
| 388 } | |
| 389 #endif /* HAVE_STARTUP_NOTIFICATION */ | |
| 390 | |
| 391 #ifndef _WIN32 | |
| 392 static char *gaim_find_binary_location(void *symbol, void *data) | |
| 393 { | |
| 394 static char *fullname = NULL; | |
| 395 static gboolean first = TRUE; | |
| 396 | |
| 397 char *argv0 = data; | |
| 398 struct stat st; | |
| 399 char *basebuf, *linkbuf, *fullbuf; | |
| 400 | |
| 401 if (!first) | |
| 402 /* We've already been through this. */ | |
| 403 return strdup(fullname); | |
| 404 | |
| 405 first = FALSE; | |
| 406 | |
| 407 if (!argv0) | |
| 408 return NULL; | |
| 409 | |
| 410 | |
| 411 basebuf = g_find_program_in_path(argv0); | |
| 412 | |
| 413 /* But we still need to deal with symbolic links */ | |
|
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10581
diff
changeset
|
414 g_lstat(basebuf, &st); |
| 10302 | 415 while ((st.st_mode & S_IFLNK) == S_IFLNK) { |
| 416 linkbuf = g_malloc(1024); | |
| 417 readlink(basebuf, linkbuf, 1024); | |
| 418 if (linkbuf[0] == G_DIR_SEPARATOR) { | |
| 419 /* an absolute path */ | |
| 420 fullbuf = g_strdup(linkbuf); | |
| 421 } else { | |
| 422 char *dirbuf = g_path_get_dirname(basebuf); | |
| 423 /* a relative path */ | |
| 424 fullbuf = g_strdup_printf("%s%s%s", | |
| 425 dirbuf, G_DIR_SEPARATOR_S, | |
| 426 linkbuf); | |
| 427 g_free(dirbuf); | |
| 428 } | |
| 429 /* There's no memory leak here. Really! */ | |
| 430 g_free(linkbuf); | |
| 431 g_free(basebuf); | |
| 432 basebuf = fullbuf; | |
|
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10581
diff
changeset
|
433 g_lstat(basebuf, &st); |
| 10302 | 434 } |
| 435 | |
| 436 fullname = basebuf; | |
| 437 return strdup(fullname); | |
| 438 } | |
| 439 #endif /* #ifndef _WIN32 */ | |
| 440 | |
| 441 /* FUCKING GET ME A TOWEL! */ | |
| 442 #ifdef _WIN32 | |
| 443 int gaim_main(HINSTANCE hint, int argc, char *argv[]) | |
| 444 #else | |
| 445 int main(int argc, char *argv[]) | |
| 446 #endif | |
| 447 { | |
| 10323 | 448 gboolean opt_acct = FALSE; |
| 449 gboolean opt_help = FALSE; | |
| 450 gboolean opt_login = FALSE; | |
| 451 gboolean opt_nologin = FALSE; | |
| 452 gboolean opt_version = FALSE; | |
| 453 char *opt_config_dir_arg = NULL; | |
| 454 char *opt_login_arg = NULL; | |
| 455 char *opt_session_arg = NULL; | |
| 456 int dologin_ret = -1; | |
| 10447 | 457 char *search_path; |
| 10302 | 458 #if HAVE_SIGNAL_H |
| 459 int sig_indx; /* for setting up signal catching */ | |
| 460 sigset_t sigset; | |
| 461 void (*prev_sig_disp)(); | |
| 462 #endif | |
| 10323 | 463 int opt; |
| 10302 | 464 gboolean gui_check; |
| 10307 | 465 gboolean debug_enabled; |
| 10334 | 466 #if HAVE_SIGNAL_H |
| 10323 | 467 char errmsg[BUFSIZ]; |
| 10334 | 468 #endif |
| 10302 | 469 |
| 470 struct option long_options[] = { | |
| 10323 | 471 {"acct", no_argument, NULL, 'a'}, |
| 472 {"config", required_argument, NULL, 'c'}, | |
| 473 {"debug", no_argument, NULL, 'd'}, | |
| 474 {"help", no_argument, NULL, 'h'}, | |
| 475 {"login", optional_argument, NULL, 'l'}, | |
| 476 {"nologin", no_argument, NULL, 'n'}, | |
| 477 {"session", required_argument, NULL, 's'}, | |
| 478 {"version", no_argument, NULL, 'v'}, | |
| 10302 | 479 {0, 0, 0, 0} |
| 480 }; | |
| 481 | |
| 482 #ifdef DEBUG | |
| 10307 | 483 debug_enabled = TRUE; |
| 484 #else | |
| 485 debug_enabled = FALSE; | |
| 10302 | 486 #endif |
| 10307 | 487 |
| 10302 | 488 #ifndef _WIN32 |
| 489 br_set_locate_fallback_func(gaim_find_binary_location, argv[0]); | |
| 490 #endif | |
| 491 #ifdef ENABLE_NLS | |
| 492 bindtextdomain(PACKAGE, LOCALEDIR); | |
| 493 bind_textdomain_codeset(PACKAGE, "UTF-8"); | |
| 494 textdomain(PACKAGE); | |
| 495 #endif | |
| 496 | |
| 11080 | 497 |
| 10302 | 498 #if HAVE_SIGNAL_H |
| 499 /* Let's not violate any PLA's!!!! */ | |
| 500 /* jseymour: whatever the fsck that means */ | |
| 501 /* Robot101: for some reason things like gdm like to block * | |
| 502 * useful signals like SIGCHLD, so we unblock all the ones we * | |
| 503 * declare a handler for. thanks JSeymour and Vann. */ | |
| 504 if (sigemptyset(&sigset)) { | |
| 505 snprintf(errmsg, BUFSIZ, "Warning: couldn't initialise empty signal set"); | |
| 506 perror(errmsg); | |
| 507 } | |
| 508 for(sig_indx = 0; catch_sig_list[sig_indx] != -1; ++sig_indx) { | |
| 509 if((prev_sig_disp = signal(catch_sig_list[sig_indx], sighandler)) == SIG_ERR) { | |
| 510 snprintf(errmsg, BUFSIZ, "Warning: couldn't set signal %d for catching", | |
| 511 catch_sig_list[sig_indx]); | |
| 512 perror(errmsg); | |
| 513 } | |
| 514 if(sigaddset(&sigset, catch_sig_list[sig_indx])) { | |
| 515 snprintf(errmsg, BUFSIZ, "Warning: couldn't include signal %d for unblocking", | |
| 516 catch_sig_list[sig_indx]); | |
| 517 perror(errmsg); | |
| 518 } | |
| 519 } | |
| 520 for(sig_indx = 0; ignore_sig_list[sig_indx] != -1; ++sig_indx) { | |
| 521 if((prev_sig_disp = signal(ignore_sig_list[sig_indx], SIG_IGN)) == SIG_ERR) { | |
| 522 snprintf(errmsg, BUFSIZ, "Warning: couldn't set signal %d to ignore", | |
| 523 ignore_sig_list[sig_indx]); | |
| 524 perror(errmsg); | |
| 525 } | |
| 526 } | |
| 527 | |
| 528 if (sigprocmask(SIG_UNBLOCK, &sigset, NULL)) { | |
| 529 snprintf(errmsg, BUFSIZ, "Warning: couldn't unblock signals"); | |
| 530 perror(errmsg); | |
| 10307 | 531 } |
| 10302 | 532 #endif |
| 533 | |
|
10581
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
534 gui_check = gtk_init_check(&argc, &argv); |
|
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
535 if (!gui_check) { |
|
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
536 char *display = gdk_get_display(); |
|
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
537 |
|
11033
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11010
diff
changeset
|
538 printf("Gaim %s\n", VERSION); |
|
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11010
diff
changeset
|
539 |
|
10581
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
540 g_warning("cannot open display: %s", display ? display : "unset"); |
|
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
541 g_free(display); |
|
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
542 |
|
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
543 return 1; |
|
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
544 } |
|
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
545 |
| 10302 | 546 /* scan command-line options */ |
| 547 opterr = 1; | |
| 548 while ((opt = getopt_long(argc, argv, | |
| 549 #ifndef _WIN32 | |
| 10323 | 550 "ac:dhnl::s:v", |
| 10302 | 551 #else |
| 10323 | 552 "ac:dhnl::v", |
| 10302 | 553 #endif |
| 554 long_options, NULL)) != -1) { | |
| 555 switch (opt) { | |
| 556 case 'a': /* account editor */ | |
| 10323 | 557 opt_acct = TRUE; |
| 558 break; | |
| 559 case 'c': /* config dir */ | |
| 560 g_free(opt_config_dir_arg); | |
| 561 opt_config_dir_arg = g_strdup(optarg); | |
| 10302 | 562 break; |
| 563 case 'd': /* debug */ | |
| 10307 | 564 debug_enabled = TRUE; |
| 10302 | 565 break; |
| 10323 | 566 case 'h': /* help */ |
| 567 opt_help = TRUE; | |
| 568 break; | |
| 569 case 'n': /* no autologin */ | |
| 570 opt_nologin = TRUE; | |
| 10302 | 571 break; |
| 10323 | 572 case 'l': /* login, option username */ |
| 573 opt_login = TRUE; | |
| 574 g_free(opt_login_arg); | |
| 575 if (optarg != NULL) | |
| 576 opt_login_arg = g_strdup(optarg); | |
| 10302 | 577 break; |
| 10320 | 578 case 's': /* use existing session ID */ |
| 10323 | 579 g_free(opt_session_arg); |
| 10320 | 580 opt_session_arg = g_strdup(optarg); |
| 581 break; | |
| 10323 | 582 case 'v': /* version */ |
| 583 opt_version = TRUE; | |
| 10320 | 584 break; |
| 10323 | 585 case '?': /* show terse help */ |
| 10302 | 586 default: |
| 10320 | 587 show_usage(argv[0], TRUE); |
| 10302 | 588 return 0; |
| 589 break; | |
| 590 } | |
| 591 } | |
| 592 | |
| 593 /* show help message */ | |
| 594 if (opt_help) { | |
| 10320 | 595 show_usage(argv[0], FALSE); |
| 10302 | 596 return 0; |
| 597 } | |
| 598 /* show version message */ | |
| 599 if (opt_version) { | |
| 10323 | 600 printf("Gaim %s\n", VERSION); |
| 10302 | 601 return 0; |
| 602 } | |
| 603 | |
| 10323 | 604 /* set a user-specified config directory */ |
| 605 if (opt_config_dir_arg != NULL) { | |
| 10871 | 606 gaim_util_set_user_dir(opt_config_dir_arg); |
| 10323 | 607 } |
| 608 | |
| 10448 | 609 /* |
| 610 * We're done piddling around with command line arguments. | |
| 611 * Fire up this baby. | |
| 612 */ | |
| 613 | |
| 614 gaim_debug_set_enabled(debug_enabled); | |
| 615 | |
| 10302 | 616 #ifdef _WIN32 |
| 10323 | 617 wgaim_init(hint); |
| 10302 | 618 #endif |
| 11067 | 619 |
| 620 #ifdef HAVE_DBUS | |
| 11080 | 621 gaim_dbus_init(); |
| 11067 | 622 #endif |
| 623 | |
| 10302 | 624 gaim_core_set_ui_ops(gaim_gtk_core_get_ui_ops()); |
| 625 gaim_eventloop_set_ui_ops(gaim_gtk_eventloop_get_ui_ops()); | |
| 626 | |
| 10447 | 627 /* Set plugin search directories */ |
| 628 gaim_plugins_add_search_path(LIBDIR); | |
| 629 search_path = g_build_filename(gaim_user_dir(), "plugins", NULL); | |
| 630 gaim_plugins_add_search_path(search_path); | |
| 631 g_free(search_path); | |
| 632 | |
| 10302 | 633 if (!gaim_core_init(GAIM_GTK_UI)) { |
| 634 fprintf(stderr, | |
| 635 "Initialization of the Gaim core failed. Dumping core.\n" | |
| 636 "Please report this!\n"); | |
| 637 abort(); | |
| 638 } | |
| 639 | |
| 10428 | 640 /* TODO: Move blist loading into gaim_blist_init() */ |
| 10302 | 641 gaim_set_blist(gaim_blist_new()); |
| 642 gaim_blist_load(); | |
| 643 | |
| 10433 | 644 /* TODO: Move prefs loading into gaim_prefs_init() */ |
| 10302 | 645 gaim_prefs_load(); |
| 646 gaim_prefs_update_old(); | |
| 647 gaim_gtk_prefs_update_old(); | |
| 648 | |
| 649 /* load plugins we had when we quit */ | |
| 650 gaim_plugins_load_saved("/gaim/gtk/plugins/loaded"); | |
| 651 | |
| 10433 | 652 /* TODO: Move pounces loading into gaim_pounces_init() */ |
| 10302 | 653 gaim_pounces_load(); |
| 654 | |
| 655 ui_main(); | |
| 656 | |
| 657 #ifdef USE_SM | |
| 658 session_init(argv[0], opt_session_arg, opt_config_dir_arg); | |
| 659 #endif | |
| 660 if (opt_session_arg != NULL) { | |
| 661 g_free(opt_session_arg); | |
| 662 opt_session_arg = NULL; | |
| 663 } | |
| 664 if (opt_config_dir_arg != NULL) { | |
| 665 g_free(opt_config_dir_arg); | |
| 666 opt_config_dir_arg = NULL; | |
| 667 } | |
| 668 | |
| 669 if (gaim_prefs_get_bool("/gaim/gtk/debug/enabled")) | |
| 670 gaim_gtk_debug_window_show(); | |
| 671 | |
| 10323 | 672 gaim_blist_show(); |
| 673 | |
| 10302 | 674 if (opt_login) { |
| 675 dologin_ret = dologin_named(opt_login_arg); | |
| 676 if (opt_login_arg != NULL) { | |
| 677 g_free(opt_login_arg); | |
| 678 opt_login_arg = NULL; | |
| 679 } | |
| 680 } | |
| 681 | |
| 10738 | 682 if (!opt_acct && opt_nologin) |
| 683 { | |
| 684 /* TODO: Need to disable all accounts or set them all to offline */ | |
| 685 } | |
| 10302 | 686 |
| 10323 | 687 if (opt_acct || (gaim_accounts_get_all() == NULL)) { |
| 10302 | 688 gaim_gtk_accounts_window_show(); |
| 10315 | 689 } |
| 10302 | 690 |
| 691 #ifdef HAVE_STARTUP_NOTIFICATION | |
| 692 startup_notification_complete(); | |
| 693 #endif | |
| 10320 | 694 |
|
11033
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11010
diff
changeset
|
695 gaim_debug_register_category("sighandler"); |
|
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11010
diff
changeset
|
696 gaim_debug_register_category("ui_main"); |
|
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11010
diff
changeset
|
697 |
|
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11010
diff
changeset
|
698 /* XXX These don't really belong here, but I don't have a better place for |
|
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11010
diff
changeset
|
699 * them right now */ |
|
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11010
diff
changeset
|
700 gaim_debug_register_category("gtkimhtml"); |
|
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11010
diff
changeset
|
701 gaim_debug_register_category("gtk_imhtml_tip"); |
|
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11010
diff
changeset
|
702 gaim_debug_register_category("html clipboard"); |
|
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11010
diff
changeset
|
703 /* #if 0'ed out for Windows stuff |
|
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11010
diff
changeset
|
704 gaim_debug_register_category("imhtml clipboard"); |
|
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11010
diff
changeset
|
705 */ |
|
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11010
diff
changeset
|
706 gaim_debug_register_category("imgstore"); |
|
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11010
diff
changeset
|
707 gaim_debug_register_category("pluginpref"); |
|
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11010
diff
changeset
|
708 gaim_debug_register_category("request"); |
|
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11010
diff
changeset
|
709 gaim_debug_register_category("roomlist"); |
|
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11010
diff
changeset
|
710 /* gtkutils.c */ |
|
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11010
diff
changeset
|
711 gaim_debug_register_category("accels"); |
|
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11010
diff
changeset
|
712 gaim_debug_register_category("gtkspell"); |
|
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11010
diff
changeset
|
713 /* These are from util.c */ |
|
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11010
diff
changeset
|
714 gaim_debug_register_category("build_dir"); |
|
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11010
diff
changeset
|
715 gaim_debug_register_category("gaim_mkstemp"); |
|
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11010
diff
changeset
|
716 gaim_debug_register_category("gaim_str_add_cr"); |
|
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11010
diff
changeset
|
717 gaim_debug_register_category("gaim_url_fetch"); |
|
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11010
diff
changeset
|
718 gaim_debug_register_category("gaim_utf8_strcasecmp"); |
|
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11010
diff
changeset
|
719 gaim_debug_register_category("parse_content_len"); |
|
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11010
diff
changeset
|
720 gaim_debug_register_category("program_is_valid"); |
|
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11010
diff
changeset
|
721 gaim_debug_register_category("util"); |
|
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11010
diff
changeset
|
722 /* These only show up once */ |
|
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11010
diff
changeset
|
723 gaim_debug_register_category("gtknotify"); |
|
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11010
diff
changeset
|
724 gaim_debug_register_category("gtksound"); |
|
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11010
diff
changeset
|
725 gaim_debug_register_category("prpl"); |
|
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11010
diff
changeset
|
726 gaim_debug_register_category("server"); |
|
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11010
diff
changeset
|
727 gaim_debug_register_category("stringref"); |
|
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11010
diff
changeset
|
728 |
| 11055 | 729 #ifdef HAVE_DBUS |
| 11080 | 730 gaim_dbus_connect(gaim_dbus_object); |
| 11055 | 731 #endif |
| 732 | |
| 10302 | 733 gtk_main(); |
| 10320 | 734 |
| 10302 | 735 #ifdef _WIN32 |
| 736 wgaim_cleanup(); | |
| 737 #endif | |
| 738 | |
| 739 return 0; | |
| 740 } |
