Mercurial > pidgin.yaz
annotate src/gtkmain.c @ 12259:0c82fd31628b
[gaim-migrate @ 14561]
Small typo fix.
committer: Tailor Script <tailor@pidgin.im>
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Tue, 29 Nov 2005 22:58:26 +0000 |
parents | b7a51e68d0b8 |
children | 3ef381cdc47e |
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()); |
10302 | 262 |
263 gaim_gtk_stock_init(); | |
264 gaim_gtk_prefs_init(); | |
265 gaim_gtk_account_init(); | |
266 gaim_gtk_blist_init(); | |
10574 | 267 gaim_gtk_status_init(); |
10302 | 268 gaim_gtk_conversations_init(); |
269 gaim_gtk_pounces_init(); | |
270 gaim_gtk_privacy_init(); | |
271 gaim_gtk_xfers_init(); | |
272 gaim_gtk_roomlist_init(); | |
12030
7165a7a444da
[gaim-migrate @ 14323]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12024
diff
changeset
|
273 #ifdef HAVE_VV |
12024 | 274 gaim_gtk_media_init(); |
275 #endif | |
11907 | 276 gaim_gtk_idle_init(); |
10302 | 277 } |
278 | |
279 static void | |
280 gaim_gtk_quit(void) | |
281 { | |
282 #ifdef USE_SM | |
283 /* unplug */ | |
12246 | 284 gaim_gtk_session_end(); |
10302 | 285 #endif |
286 | |
287 /* Save the plugins we have loaded for next time. */ | |
288 gaim_gtk_plugins_save(); | |
289 | |
10574 | 290 /* Uninit */ |
291 gaim_gtk_conversations_uninit(); | |
292 gaim_gtk_status_uninit(); | |
293 gaim_gtk_blist_uninit(); | |
294 gaim_gtk_account_uninit(); | |
11010 | 295 gaim_gtk_xfers_uninit(); |
11033
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11010
diff
changeset
|
296 gaim_gtk_debug_uninit(); |
11907 | 297 gaim_gtk_idle_uninit(); |
10574 | 298 |
10302 | 299 /* and end it all... */ |
300 gtk_main_quit(); | |
301 } | |
302 | |
303 static GaimCoreUiOps core_ops = | |
304 { | |
305 gaim_gtk_prefs_init, | |
306 debug_init, | |
307 gaim_gtk_ui_init, | |
308 gaim_gtk_quit | |
309 }; | |
310 | |
311 static GaimCoreUiOps * | |
312 gaim_gtk_core_get_ui_ops(void) | |
313 { | |
314 return &core_ops; | |
315 } | |
316 | |
317 static void | |
10320 | 318 show_usage(const char *name, gboolean terse) |
10302 | 319 { |
10320 | 320 char *text; |
321 char *text_conv; | |
322 GError *error = NULL; | |
10302 | 323 |
10320 | 324 if (terse) { |
325 text = g_strdup_printf(_("Gaim %s. Try `%s -h' for more information.\n"), VERSION, name); | |
326 } else { | |
327 text = g_strdup_printf(_("Gaim %s\n" | |
10302 | 328 "Usage: %s [OPTION]...\n\n" |
329 " -c, --config=DIR use DIR for config files\n" | |
330 " -d, --debug print debugging messages to stdout\n" | |
10320 | 331 " -h, --help display this help and exit\n" |
10323 | 332 " -n, --nologin don't automatically login\n" |
10320 | 333 " -l, --login[=NAME] automatically login (optional argument NAME specifies\n" |
11673
922d0483ca88
[gaim-migrate @ 13959]
Richard Laager <rlaager@wiktel.com>
parents:
11581
diff
changeset
|
334 " account(s) to use, separated by commas)\n" |
10323 | 335 " -v, --version display the current version and exit\n"), VERSION, name); |
10302 | 336 } |
337 | |
10320 | 338 /* tries to convert 'text' to users locale */ |
339 text_conv = g_locale_from_utf8(text, -1, NULL, NULL, &error); | |
340 if (text_conv != NULL) { | |
341 puts(text_conv); | |
342 g_free(text_conv); | |
10302 | 343 } |
10320 | 344 /* use 'text' as a fallback */ |
345 else { | |
346 g_warning("%s\n", error->message); | |
347 g_error_free(error); | |
348 puts(text); | |
349 } | |
350 g_free(text); | |
10302 | 351 } |
352 | |
353 #ifdef HAVE_STARTUP_NOTIFICATION | |
354 static void | |
355 sn_error_trap_push(SnDisplay *display, Display *xdisplay) | |
356 { | |
357 gdk_error_trap_push(); | |
358 } | |
359 | |
360 static void | |
361 sn_error_trap_pop(SnDisplay *display, Display *xdisplay) | |
362 { | |
363 gdk_error_trap_pop(); | |
364 } | |
365 | |
366 static void | |
367 startup_notification_complete(void) | |
368 { | |
369 Display *xdisplay; | |
370 | |
371 xdisplay = GDK_DISPLAY(); | |
372 sn_display = sn_display_new(xdisplay, | |
373 sn_error_trap_push, | |
374 sn_error_trap_pop); | |
375 sn_context = | |
376 sn_launchee_context_new_from_environment(sn_display, | |
377 DefaultScreen(xdisplay)); | |
378 | |
379 if (sn_context != NULL) | |
380 { | |
381 sn_launchee_context_complete(sn_context); | |
382 sn_launchee_context_unref(sn_context); | |
383 | |
384 sn_display_unref(sn_display); | |
385 } | |
386 } | |
387 #endif /* HAVE_STARTUP_NOTIFICATION */ | |
388 | |
389 #ifndef _WIN32 | |
390 static char *gaim_find_binary_location(void *symbol, void *data) | |
391 { | |
392 static char *fullname = NULL; | |
393 static gboolean first = TRUE; | |
394 | |
395 char *argv0 = data; | |
396 struct stat st; | |
397 char *basebuf, *linkbuf, *fullbuf; | |
398 | |
399 if (!first) | |
400 /* We've already been through this. */ | |
401 return strdup(fullname); | |
402 | |
403 first = FALSE; | |
404 | |
405 if (!argv0) | |
406 return NULL; | |
407 | |
408 | |
409 basebuf = g_find_program_in_path(argv0); | |
410 | |
411 /* But we still need to deal with symbolic links */ | |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10581
diff
changeset
|
412 g_lstat(basebuf, &st); |
10302 | 413 while ((st.st_mode & S_IFLNK) == S_IFLNK) { |
414 linkbuf = g_malloc(1024); | |
415 readlink(basebuf, linkbuf, 1024); | |
416 if (linkbuf[0] == G_DIR_SEPARATOR) { | |
417 /* an absolute path */ | |
418 fullbuf = g_strdup(linkbuf); | |
419 } else { | |
420 char *dirbuf = g_path_get_dirname(basebuf); | |
421 /* a relative path */ | |
422 fullbuf = g_strdup_printf("%s%s%s", | |
423 dirbuf, G_DIR_SEPARATOR_S, | |
424 linkbuf); | |
425 g_free(dirbuf); | |
426 } | |
427 /* There's no memory leak here. Really! */ | |
428 g_free(linkbuf); | |
429 g_free(basebuf); | |
430 basebuf = fullbuf; | |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10581
diff
changeset
|
431 g_lstat(basebuf, &st); |
10302 | 432 } |
433 | |
434 fullname = basebuf; | |
435 return strdup(fullname); | |
436 } | |
437 #endif /* #ifndef _WIN32 */ | |
438 | |
439 /* FUCKING GET ME A TOWEL! */ | |
440 #ifdef _WIN32 | |
441 int gaim_main(HINSTANCE hint, int argc, char *argv[]) | |
442 #else | |
443 int main(int argc, char *argv[]) | |
444 #endif | |
445 { | |
10323 | 446 gboolean opt_help = FALSE; |
447 gboolean opt_login = FALSE; | |
448 gboolean opt_nologin = FALSE; | |
449 gboolean opt_version = FALSE; | |
450 char *opt_config_dir_arg = NULL; | |
451 char *opt_login_arg = NULL; | |
452 char *opt_session_arg = NULL; | |
453 int dologin_ret = -1; | |
10447 | 454 char *search_path; |
10302 | 455 #if HAVE_SIGNAL_H |
456 int sig_indx; /* for setting up signal catching */ | |
457 sigset_t sigset; | |
458 void (*prev_sig_disp)(); | |
459 #endif | |
10323 | 460 int opt; |
10302 | 461 gboolean gui_check; |
10307 | 462 gboolean debug_enabled; |
10334 | 463 #if HAVE_SIGNAL_H |
10323 | 464 char errmsg[BUFSIZ]; |
10334 | 465 #endif |
10302 | 466 |
467 struct option long_options[] = { | |
10323 | 468 {"config", required_argument, NULL, 'c'}, |
469 {"debug", no_argument, NULL, 'd'}, | |
470 {"help", no_argument, NULL, 'h'}, | |
471 {"login", optional_argument, NULL, 'l'}, | |
472 {"nologin", no_argument, NULL, 'n'}, | |
473 {"session", required_argument, NULL, 's'}, | |
474 {"version", no_argument, NULL, 'v'}, | |
10302 | 475 {0, 0, 0, 0} |
476 }; | |
477 | |
478 #ifdef DEBUG | |
10307 | 479 debug_enabled = TRUE; |
480 #else | |
481 debug_enabled = FALSE; | |
10302 | 482 #endif |
10307 | 483 |
10302 | 484 #ifndef _WIN32 |
485 br_set_locate_fallback_func(gaim_find_binary_location, argv[0]); | |
486 #endif | |
487 #ifdef ENABLE_NLS | |
488 bindtextdomain(PACKAGE, LOCALEDIR); | |
489 bind_textdomain_codeset(PACKAGE, "UTF-8"); | |
490 textdomain(PACKAGE); | |
491 #endif | |
492 | |
11080 | 493 |
10302 | 494 #if HAVE_SIGNAL_H |
495 /* Let's not violate any PLA's!!!! */ | |
496 /* jseymour: whatever the fsck that means */ | |
497 /* Robot101: for some reason things like gdm like to block * | |
498 * useful signals like SIGCHLD, so we unblock all the ones we * | |
499 * declare a handler for. thanks JSeymour and Vann. */ | |
500 if (sigemptyset(&sigset)) { | |
501 snprintf(errmsg, BUFSIZ, "Warning: couldn't initialise empty signal set"); | |
502 perror(errmsg); | |
503 } | |
504 for(sig_indx = 0; catch_sig_list[sig_indx] != -1; ++sig_indx) { | |
505 if((prev_sig_disp = signal(catch_sig_list[sig_indx], sighandler)) == SIG_ERR) { | |
506 snprintf(errmsg, BUFSIZ, "Warning: couldn't set signal %d for catching", | |
507 catch_sig_list[sig_indx]); | |
508 perror(errmsg); | |
509 } | |
510 if(sigaddset(&sigset, catch_sig_list[sig_indx])) { | |
511 snprintf(errmsg, BUFSIZ, "Warning: couldn't include signal %d for unblocking", | |
512 catch_sig_list[sig_indx]); | |
513 perror(errmsg); | |
514 } | |
515 } | |
516 for(sig_indx = 0; ignore_sig_list[sig_indx] != -1; ++sig_indx) { | |
517 if((prev_sig_disp = signal(ignore_sig_list[sig_indx], SIG_IGN)) == SIG_ERR) { | |
518 snprintf(errmsg, BUFSIZ, "Warning: couldn't set signal %d to ignore", | |
519 ignore_sig_list[sig_indx]); | |
520 perror(errmsg); | |
521 } | |
522 } | |
523 | |
524 if (sigprocmask(SIG_UNBLOCK, &sigset, NULL)) { | |
525 snprintf(errmsg, BUFSIZ, "Warning: couldn't unblock signals"); | |
526 perror(errmsg); | |
10307 | 527 } |
10302 | 528 #endif |
529 | |
12202
17be9401e167
[gaim-migrate @ 14504]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12187
diff
changeset
|
530 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
|
531 gtk_rc_add_default_file(search_path); |
17be9401e167
[gaim-migrate @ 14504]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12187
diff
changeset
|
532 g_free(search_path); |
17be9401e167
[gaim-migrate @ 14504]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12187
diff
changeset
|
533 |
10581
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
534 gui_check = gtk_init_check(&argc, &argv); |
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
535 if (!gui_check) { |
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
536 char *display = gdk_get_display(); |
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
537 |
11033
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11010
diff
changeset
|
538 printf("Gaim %s\n", VERSION); |
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11010
diff
changeset
|
539 |
10581
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
540 g_warning("cannot open display: %s", display ? display : "unset"); |
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
541 g_free(display); |
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
542 |
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
543 return 1; |
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
544 } |
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
545 |
10302 | 546 /* scan command-line options */ |
547 opterr = 1; | |
548 while ((opt = getopt_long(argc, argv, | |
549 #ifndef _WIN32 | |
11795
f48e2acaa5d2
[gaim-migrate @ 14086]
Richard Laager <rlaager@wiktel.com>
parents:
11785
diff
changeset
|
550 "c:dhnl::s:v", |
10302 | 551 #else |
11795
f48e2acaa5d2
[gaim-migrate @ 14086]
Richard Laager <rlaager@wiktel.com>
parents:
11785
diff
changeset
|
552 "c:dhnl::v", |
10302 | 553 #endif |
554 long_options, NULL)) != -1) { | |
555 switch (opt) { | |
10323 | 556 case 'c': /* config dir */ |
557 g_free(opt_config_dir_arg); | |
558 opt_config_dir_arg = g_strdup(optarg); | |
10302 | 559 break; |
560 case 'd': /* debug */ | |
10307 | 561 debug_enabled = TRUE; |
10302 | 562 break; |
10323 | 563 case 'h': /* help */ |
564 opt_help = TRUE; | |
565 break; | |
566 case 'n': /* no autologin */ | |
567 opt_nologin = TRUE; | |
10302 | 568 break; |
10323 | 569 case 'l': /* login, option username */ |
570 opt_login = TRUE; | |
571 g_free(opt_login_arg); | |
572 if (optarg != NULL) | |
573 opt_login_arg = g_strdup(optarg); | |
10302 | 574 break; |
10320 | 575 case 's': /* use existing session ID */ |
10323 | 576 g_free(opt_session_arg); |
10320 | 577 opt_session_arg = g_strdup(optarg); |
578 break; | |
10323 | 579 case 'v': /* version */ |
580 opt_version = TRUE; | |
10320 | 581 break; |
10323 | 582 case '?': /* show terse help */ |
10302 | 583 default: |
10320 | 584 show_usage(argv[0], TRUE); |
10302 | 585 return 0; |
586 break; | |
587 } | |
588 } | |
589 | |
590 /* show help message */ | |
591 if (opt_help) { | |
10320 | 592 show_usage(argv[0], FALSE); |
10302 | 593 return 0; |
594 } | |
595 /* show version message */ | |
596 if (opt_version) { | |
10323 | 597 printf("Gaim %s\n", VERSION); |
10302 | 598 return 0; |
599 } | |
600 | |
10323 | 601 /* set a user-specified config directory */ |
602 if (opt_config_dir_arg != NULL) { | |
10871 | 603 gaim_util_set_user_dir(opt_config_dir_arg); |
10323 | 604 } |
605 | |
10448 | 606 /* |
607 * We're done piddling around with command line arguments. | |
608 * Fire up this baby. | |
609 */ | |
610 | |
611 gaim_debug_set_enabled(debug_enabled); | |
612 | |
10302 | 613 #ifdef _WIN32 |
10323 | 614 wgaim_init(hint); |
10302 | 615 #endif |
11067 | 616 |
10302 | 617 gaim_core_set_ui_ops(gaim_gtk_core_get_ui_ops()); |
618 gaim_eventloop_set_ui_ops(gaim_gtk_eventloop_get_ui_ops()); | |
619 | |
10447 | 620 /* Set plugin search directories */ |
621 gaim_plugins_add_search_path(LIBDIR); | |
622 search_path = g_build_filename(gaim_user_dir(), "plugins", NULL); | |
623 gaim_plugins_add_search_path(search_path); | |
624 g_free(search_path); | |
625 | |
10302 | 626 if (!gaim_core_init(GAIM_GTK_UI)) { |
627 fprintf(stderr, | |
628 "Initialization of the Gaim core failed. Dumping core.\n" | |
629 "Please report this!\n"); | |
630 abort(); | |
631 } | |
632 | |
10428 | 633 /* TODO: Move blist loading into gaim_blist_init() */ |
10302 | 634 gaim_set_blist(gaim_blist_new()); |
635 gaim_blist_load(); | |
636 | |
10433 | 637 /* TODO: Move prefs loading into gaim_prefs_init() */ |
10302 | 638 gaim_prefs_load(); |
639 gaim_prefs_update_old(); | |
640 gaim_gtk_prefs_update_old(); | |
641 | |
642 /* load plugins we had when we quit */ | |
643 gaim_plugins_load_saved("/gaim/gtk/plugins/loaded"); | |
644 | |
10433 | 645 /* TODO: Move pounces loading into gaim_pounces_init() */ |
10302 | 646 gaim_pounces_load(); |
647 | |
648 ui_main(); | |
649 | |
650 #ifdef USE_SM | |
12246 | 651 gaim_gtk_session_init(argv[0], opt_session_arg, opt_config_dir_arg); |
10302 | 652 #endif |
653 if (opt_session_arg != NULL) { | |
654 g_free(opt_session_arg); | |
655 opt_session_arg = NULL; | |
656 } | |
657 if (opt_config_dir_arg != NULL) { | |
658 g_free(opt_config_dir_arg); | |
659 opt_config_dir_arg = NULL; | |
660 } | |
661 | |
12011 | 662 /* |
663 * We want to show the blist early in the init process so the | |
664 * user feels warm and fuzzy (not cold and prickley). | |
665 */ | |
666 gaim_blist_show(); | |
667 | |
10302 | 668 if (gaim_prefs_get_bool("/gaim/gtk/debug/enabled")) |
669 gaim_gtk_debug_window_show(); | |
670 | |
671 if (opt_login) { | |
672 dologin_ret = dologin_named(opt_login_arg); | |
673 if (opt_login_arg != NULL) { | |
674 g_free(opt_login_arg); | |
675 opt_login_arg = NULL; | |
676 } | |
677 } | |
678 | |
11806 | 679 if (opt_nologin) |
680 { | |
681 /* Set all accounts to "offline" */ | |
682 GaimSavedStatus *saved_status; | |
683 saved_status = gaim_savedstatus_find(_("Default")); | |
684 if (saved_status == NULL) | |
685 saved_status = gaim_savedstatus_new(_("Default"), GAIM_STATUS_OFFLINE); | |
686 else | |
687 gaim_savedstatus_set_type(saved_status, GAIM_STATUS_OFFLINE); | |
688 gaim_savedstatus_activate(saved_status); | |
689 } | |
690 else | |
10738 | 691 { |
11348 | 692 /* Everything is good to go--sign on already */ |
693 gaim_accounts_restore_previous_statuses(); | |
10738 | 694 } |
10302 | 695 |
11785 | 696 if (gaim_accounts_get_all_active() == NULL) |
11403 | 697 { |
10302 | 698 gaim_gtk_accounts_window_show(); |
10315 | 699 } |
10302 | 700 |
701 #ifdef HAVE_STARTUP_NOTIFICATION | |
702 startup_notification_complete(); | |
703 #endif | |
10320 | 704 |
10302 | 705 gtk_main(); |
10320 | 706 |
10302 | 707 #ifdef _WIN32 |
708 wgaim_cleanup(); | |
709 #endif | |
710 | |
711 return 0; | |
712 } |