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