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