Mercurial > pidgin
annotate src/gtkmain.c @ 13131:47ecef83e2e1
[gaim-migrate @ 15493]
A lot of our conversation code assumes that conv->account != NULL.
This is a completely invalid assumption. If you have a conversation
open on an account, and you delete the account, Gaim should leave the
conversation window open and set the account to NULL and handle
everything appropriately. Currently it does not, and that makes me
a little unhappy.
To reproduce this:
1. Open a conversation with someone
2. Delete the account that you're sending messages from
3. Watch the assertion failures scroll by in the debug window
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Mon, 06 Feb 2006 05:43:09 +0000 |
parents | 0e7f19583825 |
children | 812e2de69c90 |
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: | |
13089 | 175 gaim_print_utf8_to_console(stderr, 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]; |
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 | |
13089 | 483 #ifdef HAVE_SETLOCALE |
484 /* Locale initialization is not complete here. See gtk_init_check() */ | |
485 setlocale(LC_ALL, ""); | |
486 #endif | |
11080 | 487 |
10302 | 488 #if HAVE_SIGNAL_H |
12556
14e094d7568f
[gaim-migrate @ 14875]
Richard Laager <rlaager@wiktel.com>
parents:
12409
diff
changeset
|
489 |
14e094d7568f
[gaim-migrate @ 14875]
Richard Laager <rlaager@wiktel.com>
parents:
12409
diff
changeset
|
490 #ifndef DEBUG |
14e094d7568f
[gaim-migrate @ 14875]
Richard Laager <rlaager@wiktel.com>
parents:
12409
diff
changeset
|
491 /* We translate this here in case the crash breaks gettext. */ |
13089 | 492 segfault_message = g_strdup_printf(_( |
12556
14e094d7568f
[gaim-migrate @ 14875]
Richard Laager <rlaager@wiktel.com>
parents:
12409
diff
changeset
|
493 "Gaim has segfaulted and attempted to dump a core file.\n" |
14e094d7568f
[gaim-migrate @ 14875]
Richard Laager <rlaager@wiktel.com>
parents:
12409
diff
changeset
|
494 "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
|
495 "no fault of your own.\n\n" |
14e094d7568f
[gaim-migrate @ 14875]
Richard Laager <rlaager@wiktel.com>
parents:
12409
diff
changeset
|
496 "If you can reproduce the crash, please notify the gaim\n" |
14e094d7568f
[gaim-migrate @ 14875]
Richard Laager <rlaager@wiktel.com>
parents:
12409
diff
changeset
|
497 "developers by reporting a bug at\n" |
13089 | 498 "%sbug.php\n\n" |
12556
14e094d7568f
[gaim-migrate @ 14875]
Richard Laager <rlaager@wiktel.com>
parents:
12409
diff
changeset
|
499 "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
|
500 "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
|
501 "how to get the backtrace, please read the instructions at\n" |
13089 | 502 "%sgdb.php. If you need further\n" |
12556
14e094d7568f
[gaim-migrate @ 14875]
Richard Laager <rlaager@wiktel.com>
parents:
12409
diff
changeset
|
503 "assistance, please IM either SeanEgn or LSchiere (via AIM).\n" |
14e094d7568f
[gaim-migrate @ 14875]
Richard Laager <rlaager@wiktel.com>
parents:
12409
diff
changeset
|
504 "Contact information for Sean and Luke on other protocols is at\n" |
13089 | 505 "%scontactinfo.php.\n"), |
506 GAIM_WEBSITE, GAIM_WEBSITE, GAIM_WEBSITE | |
507 ); | |
12556
14e094d7568f
[gaim-migrate @ 14875]
Richard Laager <rlaager@wiktel.com>
parents:
12409
diff
changeset
|
508 #else |
14e094d7568f
[gaim-migrate @ 14875]
Richard Laager <rlaager@wiktel.com>
parents:
12409
diff
changeset
|
509 /* Don't mark this for translation. */ |
14e094d7568f
[gaim-migrate @ 14875]
Richard Laager <rlaager@wiktel.com>
parents:
12409
diff
changeset
|
510 segfault_message = g_strdup( |
14e094d7568f
[gaim-migrate @ 14875]
Richard Laager <rlaager@wiktel.com>
parents:
12409
diff
changeset
|
511 "Hi, user. We need to talk.\n" |
14e094d7568f
[gaim-migrate @ 14875]
Richard Laager <rlaager@wiktel.com>
parents:
12409
diff
changeset
|
512 "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
|
513 "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
|
514 "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
|
515 "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
|
516 "for the last time, it's just a rash!\n" |
12556
14e094d7568f
[gaim-migrate @ 14875]
Richard Laager <rlaager@wiktel.com>
parents:
12409
diff
changeset
|
517 ); |
14e094d7568f
[gaim-migrate @ 14875]
Richard Laager <rlaager@wiktel.com>
parents:
12409
diff
changeset
|
518 #endif |
14e094d7568f
[gaim-migrate @ 14875]
Richard Laager <rlaager@wiktel.com>
parents:
12409
diff
changeset
|
519 |
10302 | 520 /* Let's not violate any PLA's!!!! */ |
521 /* jseymour: whatever the fsck that means */ | |
522 /* Robot101: for some reason things like gdm like to block * | |
523 * useful signals like SIGCHLD, so we unblock all the ones we * | |
524 * declare a handler for. thanks JSeymour and Vann. */ | |
525 if (sigemptyset(&sigset)) { | |
526 snprintf(errmsg, BUFSIZ, "Warning: couldn't initialise empty signal set"); | |
527 perror(errmsg); | |
528 } | |
529 for(sig_indx = 0; catch_sig_list[sig_indx] != -1; ++sig_indx) { | |
530 if((prev_sig_disp = signal(catch_sig_list[sig_indx], sighandler)) == SIG_ERR) { | |
531 snprintf(errmsg, BUFSIZ, "Warning: couldn't set signal %d for catching", | |
532 catch_sig_list[sig_indx]); | |
533 perror(errmsg); | |
534 } | |
535 if(sigaddset(&sigset, catch_sig_list[sig_indx])) { | |
536 snprintf(errmsg, BUFSIZ, "Warning: couldn't include signal %d for unblocking", | |
537 catch_sig_list[sig_indx]); | |
538 perror(errmsg); | |
539 } | |
540 } | |
541 for(sig_indx = 0; ignore_sig_list[sig_indx] != -1; ++sig_indx) { | |
542 if((prev_sig_disp = signal(ignore_sig_list[sig_indx], SIG_IGN)) == SIG_ERR) { | |
543 snprintf(errmsg, BUFSIZ, "Warning: couldn't set signal %d to ignore", | |
544 ignore_sig_list[sig_indx]); | |
545 perror(errmsg); | |
546 } | |
547 } | |
548 | |
549 if (sigprocmask(SIG_UNBLOCK, &sigset, NULL)) { | |
550 snprintf(errmsg, BUFSIZ, "Warning: couldn't unblock signals"); | |
551 perror(errmsg); | |
10307 | 552 } |
10302 | 553 #endif |
554 | |
555 /* scan command-line options */ | |
556 opterr = 1; | |
557 while ((opt = getopt_long(argc, argv, | |
558 #ifndef _WIN32 | |
11795
f48e2acaa5d2
[gaim-migrate @ 14086]
Richard Laager <rlaager@wiktel.com>
parents:
11785
diff
changeset
|
559 "c:dhnl::s:v", |
10302 | 560 #else |
11795
f48e2acaa5d2
[gaim-migrate @ 14086]
Richard Laager <rlaager@wiktel.com>
parents:
11785
diff
changeset
|
561 "c:dhnl::v", |
10302 | 562 #endif |
563 long_options, NULL)) != -1) { | |
564 switch (opt) { | |
10323 | 565 case 'c': /* config dir */ |
566 g_free(opt_config_dir_arg); | |
567 opt_config_dir_arg = g_strdup(optarg); | |
10302 | 568 break; |
569 case 'd': /* debug */ | |
10307 | 570 debug_enabled = TRUE; |
10302 | 571 break; |
10323 | 572 case 'h': /* help */ |
573 opt_help = TRUE; | |
574 break; | |
575 case 'n': /* no autologin */ | |
576 opt_nologin = TRUE; | |
10302 | 577 break; |
10323 | 578 case 'l': /* login, option username */ |
579 opt_login = TRUE; | |
580 g_free(opt_login_arg); | |
581 if (optarg != NULL) | |
582 opt_login_arg = g_strdup(optarg); | |
10302 | 583 break; |
10320 | 584 case 's': /* use existing session ID */ |
10323 | 585 g_free(opt_session_arg); |
10320 | 586 opt_session_arg = g_strdup(optarg); |
587 break; | |
10323 | 588 case 'v': /* version */ |
589 opt_version = TRUE; | |
10320 | 590 break; |
10323 | 591 case '?': /* show terse help */ |
10302 | 592 default: |
10320 | 593 show_usage(argv[0], TRUE); |
10302 | 594 return 0; |
595 break; | |
596 } | |
597 } | |
598 | |
599 /* show help message */ | |
600 if (opt_help) { | |
10320 | 601 show_usage(argv[0], FALSE); |
10302 | 602 return 0; |
603 } | |
604 /* show version message */ | |
605 if (opt_version) { | |
10323 | 606 printf("Gaim %s\n", VERSION); |
10302 | 607 return 0; |
608 } | |
609 | |
10323 | 610 /* set a user-specified config directory */ |
611 if (opt_config_dir_arg != NULL) { | |
10871 | 612 gaim_util_set_user_dir(opt_config_dir_arg); |
10323 | 613 } |
614 | |
10448 | 615 /* |
616 * We're done piddling around with command line arguments. | |
617 * Fire up this baby. | |
618 */ | |
619 | |
620 gaim_debug_set_enabled(debug_enabled); | |
621 | |
10302 | 622 #ifdef _WIN32 |
10323 | 623 wgaim_init(hint); |
10302 | 624 #endif |
11067 | 625 |
12572
bf01b160ab0d
[gaim-migrate @ 14891]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12562
diff
changeset
|
626 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
|
627 gtk_rc_add_default_file(search_path); |
bf01b160ab0d
[gaim-migrate @ 14891]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12562
diff
changeset
|
628 g_free(search_path); |
bf01b160ab0d
[gaim-migrate @ 14891]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12562
diff
changeset
|
629 |
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 gui_check = gtk_init_check(&argc, &argv); |
bf01b160ab0d
[gaim-migrate @ 14891]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12562
diff
changeset
|
632 if (!gui_check) { |
bf01b160ab0d
[gaim-migrate @ 14891]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12562
diff
changeset
|
633 char *display = gdk_get_display(); |
bf01b160ab0d
[gaim-migrate @ 14891]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12562
diff
changeset
|
634 |
bf01b160ab0d
[gaim-migrate @ 14891]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12562
diff
changeset
|
635 printf("Gaim %s\n", VERSION); |
bf01b160ab0d
[gaim-migrate @ 14891]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12562
diff
changeset
|
636 |
bf01b160ab0d
[gaim-migrate @ 14891]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12562
diff
changeset
|
637 g_warning("cannot open display: %s", display ? display : "unset"); |
bf01b160ab0d
[gaim-migrate @ 14891]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12562
diff
changeset
|
638 g_free(display); |
bf01b160ab0d
[gaim-migrate @ 14891]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12562
diff
changeset
|
639 |
bf01b160ab0d
[gaim-migrate @ 14891]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12562
diff
changeset
|
640 return 1; |
bf01b160ab0d
[gaim-migrate @ 14891]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12562
diff
changeset
|
641 } |
bf01b160ab0d
[gaim-migrate @ 14891]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12562
diff
changeset
|
642 |
bf01b160ab0d
[gaim-migrate @ 14891]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12562
diff
changeset
|
643 #ifdef _WIN32 |
bf01b160ab0d
[gaim-migrate @ 14891]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12562
diff
changeset
|
644 /** 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
|
645 wgaim_gtkspell_init(); |
bf01b160ab0d
[gaim-migrate @ 14891]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12562
diff
changeset
|
646 #endif |
bf01b160ab0d
[gaim-migrate @ 14891]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12562
diff
changeset
|
647 |
10302 | 648 gaim_core_set_ui_ops(gaim_gtk_core_get_ui_ops()); |
649 gaim_eventloop_set_ui_ops(gaim_gtk_eventloop_get_ui_ops()); | |
650 | |
12342 | 651 /* |
652 * Set plugin search directories. Give priority to the plugins | |
653 * in user's home directory. | |
654 */ | |
10447 | 655 search_path = g_build_filename(gaim_user_dir(), "plugins", NULL); |
656 gaim_plugins_add_search_path(search_path); | |
657 g_free(search_path); | |
12342 | 658 gaim_plugins_add_search_path(LIBDIR); |
10447 | 659 |
10302 | 660 if (!gaim_core_init(GAIM_GTK_UI)) { |
661 fprintf(stderr, | |
662 "Initialization of the Gaim core failed. Dumping core.\n" | |
663 "Please report this!\n"); | |
664 abort(); | |
665 } | |
666 | |
10428 | 667 /* TODO: Move blist loading into gaim_blist_init() */ |
10302 | 668 gaim_set_blist(gaim_blist_new()); |
669 gaim_blist_load(); | |
670 | |
10433 | 671 /* TODO: Move prefs loading into gaim_prefs_init() */ |
10302 | 672 gaim_prefs_load(); |
673 gaim_prefs_update_old(); | |
674 gaim_gtk_prefs_update_old(); | |
675 | |
676 /* load plugins we had when we quit */ | |
677 gaim_plugins_load_saved("/gaim/gtk/plugins/loaded"); | |
678 | |
10433 | 679 /* TODO: Move pounces loading into gaim_pounces_init() */ |
10302 | 680 gaim_pounces_load(); |
681 | |
682 ui_main(); | |
683 | |
684 #ifdef USE_SM | |
12246 | 685 gaim_gtk_session_init(argv[0], opt_session_arg, opt_config_dir_arg); |
10302 | 686 #endif |
687 if (opt_session_arg != NULL) { | |
688 g_free(opt_session_arg); | |
689 opt_session_arg = NULL; | |
690 } | |
691 if (opt_config_dir_arg != NULL) { | |
692 g_free(opt_config_dir_arg); | |
693 opt_config_dir_arg = NULL; | |
694 } | |
695 | |
12011 | 696 /* |
697 * We want to show the blist early in the init process so the | |
698 * user feels warm and fuzzy (not cold and prickley). | |
699 */ | |
700 gaim_blist_show(); | |
701 | |
10302 | 702 if (gaim_prefs_get_bool("/gaim/gtk/debug/enabled")) |
703 gaim_gtk_debug_window_show(); | |
704 | |
705 if (opt_login) { | |
706 dologin_ret = dologin_named(opt_login_arg); | |
707 if (opt_login_arg != NULL) { | |
708 g_free(opt_login_arg); | |
709 opt_login_arg = NULL; | |
710 } | |
711 } | |
712 | |
11806 | 713 if (opt_nologin) |
714 { | |
715 /* Set all accounts to "offline" */ | |
716 GaimSavedStatus *saved_status; | |
13110 | 717 |
718 /* If we've used this type+message before, lookup the transient status */ | |
719 saved_status = gaim_savedstatus_find_by_type_and_message( | |
720 GAIM_STATUS_OFFLINE, NULL); | |
721 | |
722 /* If this type+message is unique then create a new transient saved status */ | |
723 if (saved_status == NULL) | |
724 saved_status = gaim_savedstatus_new(NULL, GAIM_STATUS_OFFLINE); | |
725 | |
726 /* Set the status for each account */ | |
11806 | 727 gaim_savedstatus_activate(saved_status); |
728 } | |
729 else | |
10738 | 730 { |
11348 | 731 /* Everything is good to go--sign on already */ |
12857
e5f780a6137b
[gaim-migrate @ 15208]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12846
diff
changeset
|
732 if (!gaim_prefs_get_bool("/core/savedstatus/startup_current_status")) |
e5f780a6137b
[gaim-migrate @ 15208]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12846
diff
changeset
|
733 gaim_savedstatus_activate(gaim_savedstatus_get_startup()); |
e5f780a6137b
[gaim-migrate @ 15208]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12846
diff
changeset
|
734 gaim_accounts_restore_current_statuses(); |
10738 | 735 } |
10302 | 736 |
11785 | 737 if (gaim_accounts_get_all_active() == NULL) |
11403 | 738 { |
10302 | 739 gaim_gtk_accounts_window_show(); |
10315 | 740 } |
10302 | 741 |
742 #ifdef HAVE_STARTUP_NOTIFICATION | |
743 startup_notification_complete(); | |
744 #endif | |
10320 | 745 |
10302 | 746 gtk_main(); |
10320 | 747 |
12562
e3b4abe7e0f8
[gaim-migrate @ 14881]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12556
diff
changeset
|
748 #if HAVE_SIGNAL_H |
12556
14e094d7568f
[gaim-migrate @ 14875]
Richard Laager <rlaager@wiktel.com>
parents:
12409
diff
changeset
|
749 g_free(segfault_message); |
12562
e3b4abe7e0f8
[gaim-migrate @ 14881]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12556
diff
changeset
|
750 #endif |
12556
14e094d7568f
[gaim-migrate @ 14875]
Richard Laager <rlaager@wiktel.com>
parents:
12409
diff
changeset
|
751 |
10302 | 752 #ifdef _WIN32 |
753 wgaim_cleanup(); | |
754 #endif | |
755 | |
756 return 0; | |
757 } |