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