Mercurial > pidgin.yaz
annotate src/gtkmain.c @ 11735:8d7c99f20e4c
[gaim-migrate @ 14026]
Switch from using our old GaimGtkDisclosure widget to using the official
GtkExpander widget. It works better and should make us look more uniform
with other gtk apps.
To maintain compatability with gtk < 2.4, I grabbed the gtkexpander.c
and gtkexpander.h files from gtk+ CVS. I haven't tested compiling on
a computer with gtk < 2.4 yet, so it's possible we'll need to get more
stuff from gtk+ CVS.
For future reference, gtkexpander.h was not modified, and gtkexpander.c
was only modified to check if version is > 2.4 then do nothing. I also
changed the #includes to use <> instead of ""
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Sun, 23 Oct 2005 03:24:53 +0000 |
parents | 922d0483ca88 |
children | c90676803a1a |
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" | |
51 #include "gtknotify.h" | |
52 #include "gtkplugin.h" | |
53 #include "gtkpounce.h" | |
54 #include "gtkprefs.h" | |
55 #include "gtkprivacy.h" | |
56 #include "gtkrequest.h" | |
57 #include "gtkroomlist.h" | |
10574 | 58 #include "gtksavedstatuses.h" |
10302 | 59 #include "gtksound.h" |
11525 | 60 #include "gtkthemes.h" |
10302 | 61 #include "gtkutils.h" |
62 #include "gtkstock.h" | |
11475
7fab28c991f3
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11403
diff
changeset
|
63 #include "gtkwhiteboard.h" |
10302 | 64 |
65 #if HAVE_SIGNAL_H | |
66 # include <signal.h> | |
67 #endif | |
68 | |
69 #include <getopt.h> | |
70 | |
71 #ifdef HAVE_STARTUP_NOTIFICATION | |
72 # define SN_API_NOT_YET_FROZEN | |
73 # include <libsn/sn-launchee.h> | |
74 # include <gdk/gdkx.h> | |
75 #endif | |
76 | |
11055 | 77 |
78 | |
10302 | 79 #ifdef HAVE_STARTUP_NOTIFICATION |
80 static SnLauncheeContext *sn_context = NULL; | |
81 static SnDisplay *sn_display = NULL; | |
82 #endif | |
83 | |
10448 | 84 /* TODO: Get this out of here? */ |
10302 | 85 int docklet_count = 0; |
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(); | |
273 } | |
274 | |
275 static void | |
276 gaim_gtk_quit(void) | |
277 { | |
278 /* XXX? */ | |
279 /* YYY is there an XXX here? */ | |
280 | |
281 /* captain's log, stardate... */ | |
282 /* LOG system_log(log_quit, NULL, NULL, OPT_LOG_BUDDY_SIGNON | OPT_LOG_MY_SIGNON); */ | |
283 | |
284 #ifdef USE_SM | |
285 /* unplug */ | |
286 session_end(); | |
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 " -a, --acct display account editor window\n" | |
331 " -c, --config=DIR use DIR for config files\n" | |
332 " -d, --debug print debugging messages to stdout\n" | |
10320 | 333 " -h, --help display this help and exit\n" |
10323 | 334 " -n, --nologin don't automatically login\n" |
10320 | 335 " -l, --login[=NAME] automatically login (optional argument NAME specifies\n" |
11673
922d0483ca88
[gaim-migrate @ 13959]
Richard Laager <rlaager@wiktel.com>
parents:
11581
diff
changeset
|
336 " account(s) to use, separated by commas)\n" |
10323 | 337 " -v, --version display the current version and exit\n"), VERSION, name); |
10302 | 338 } |
339 | |
10320 | 340 /* tries to convert 'text' to users locale */ |
341 text_conv = g_locale_from_utf8(text, -1, NULL, NULL, &error); | |
342 if (text_conv != NULL) { | |
343 puts(text_conv); | |
344 g_free(text_conv); | |
10302 | 345 } |
10320 | 346 /* use 'text' as a fallback */ |
347 else { | |
348 g_warning("%s\n", error->message); | |
349 g_error_free(error); | |
350 puts(text); | |
351 } | |
352 g_free(text); | |
10302 | 353 } |
354 | |
355 #ifdef HAVE_STARTUP_NOTIFICATION | |
356 static void | |
357 sn_error_trap_push(SnDisplay *display, Display *xdisplay) | |
358 { | |
359 gdk_error_trap_push(); | |
360 } | |
361 | |
362 static void | |
363 sn_error_trap_pop(SnDisplay *display, Display *xdisplay) | |
364 { | |
365 gdk_error_trap_pop(); | |
366 } | |
367 | |
368 static void | |
369 startup_notification_complete(void) | |
370 { | |
371 Display *xdisplay; | |
372 | |
373 xdisplay = GDK_DISPLAY(); | |
374 sn_display = sn_display_new(xdisplay, | |
375 sn_error_trap_push, | |
376 sn_error_trap_pop); | |
377 sn_context = | |
378 sn_launchee_context_new_from_environment(sn_display, | |
379 DefaultScreen(xdisplay)); | |
380 | |
381 if (sn_context != NULL) | |
382 { | |
383 sn_launchee_context_complete(sn_context); | |
384 sn_launchee_context_unref(sn_context); | |
385 | |
386 sn_display_unref(sn_display); | |
387 } | |
388 } | |
389 #endif /* HAVE_STARTUP_NOTIFICATION */ | |
390 | |
391 #ifndef _WIN32 | |
392 static char *gaim_find_binary_location(void *symbol, void *data) | |
393 { | |
394 static char *fullname = NULL; | |
395 static gboolean first = TRUE; | |
396 | |
397 char *argv0 = data; | |
398 struct stat st; | |
399 char *basebuf, *linkbuf, *fullbuf; | |
400 | |
401 if (!first) | |
402 /* We've already been through this. */ | |
403 return strdup(fullname); | |
404 | |
405 first = FALSE; | |
406 | |
407 if (!argv0) | |
408 return NULL; | |
409 | |
410 | |
411 basebuf = g_find_program_in_path(argv0); | |
412 | |
413 /* But we still need to deal with symbolic links */ | |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10581
diff
changeset
|
414 g_lstat(basebuf, &st); |
10302 | 415 while ((st.st_mode & S_IFLNK) == S_IFLNK) { |
416 linkbuf = g_malloc(1024); | |
417 readlink(basebuf, linkbuf, 1024); | |
418 if (linkbuf[0] == G_DIR_SEPARATOR) { | |
419 /* an absolute path */ | |
420 fullbuf = g_strdup(linkbuf); | |
421 } else { | |
422 char *dirbuf = g_path_get_dirname(basebuf); | |
423 /* a relative path */ | |
424 fullbuf = g_strdup_printf("%s%s%s", | |
425 dirbuf, G_DIR_SEPARATOR_S, | |
426 linkbuf); | |
427 g_free(dirbuf); | |
428 } | |
429 /* There's no memory leak here. Really! */ | |
430 g_free(linkbuf); | |
431 g_free(basebuf); | |
432 basebuf = fullbuf; | |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10581
diff
changeset
|
433 g_lstat(basebuf, &st); |
10302 | 434 } |
435 | |
436 fullname = basebuf; | |
437 return strdup(fullname); | |
438 } | |
439 #endif /* #ifndef _WIN32 */ | |
440 | |
441 /* FUCKING GET ME A TOWEL! */ | |
442 #ifdef _WIN32 | |
443 int gaim_main(HINSTANCE hint, int argc, char *argv[]) | |
444 #else | |
445 int main(int argc, char *argv[]) | |
446 #endif | |
447 { | |
10323 | 448 gboolean opt_acct = FALSE; |
449 gboolean opt_help = FALSE; | |
450 gboolean opt_login = FALSE; | |
451 gboolean opt_nologin = FALSE; | |
452 gboolean opt_version = FALSE; | |
453 char *opt_config_dir_arg = NULL; | |
454 char *opt_login_arg = NULL; | |
455 char *opt_session_arg = NULL; | |
456 int dologin_ret = -1; | |
10447 | 457 char *search_path; |
10302 | 458 #if HAVE_SIGNAL_H |
459 int sig_indx; /* for setting up signal catching */ | |
460 sigset_t sigset; | |
461 void (*prev_sig_disp)(); | |
462 #endif | |
10323 | 463 int opt; |
10302 | 464 gboolean gui_check; |
10307 | 465 gboolean debug_enabled; |
10334 | 466 #if HAVE_SIGNAL_H |
10323 | 467 char errmsg[BUFSIZ]; |
10334 | 468 #endif |
10302 | 469 |
470 struct option long_options[] = { | |
10323 | 471 {"acct", no_argument, NULL, 'a'}, |
472 {"config", required_argument, NULL, 'c'}, | |
473 {"debug", no_argument, NULL, 'd'}, | |
474 {"help", no_argument, NULL, 'h'}, | |
475 {"login", optional_argument, NULL, 'l'}, | |
476 {"nologin", no_argument, NULL, 'n'}, | |
477 {"session", required_argument, NULL, 's'}, | |
478 {"version", no_argument, NULL, 'v'}, | |
10302 | 479 {0, 0, 0, 0} |
480 }; | |
481 | |
482 #ifdef DEBUG | |
10307 | 483 debug_enabled = TRUE; |
484 #else | |
485 debug_enabled = FALSE; | |
10302 | 486 #endif |
10307 | 487 |
10302 | 488 #ifndef _WIN32 |
489 br_set_locate_fallback_func(gaim_find_binary_location, argv[0]); | |
490 #endif | |
491 #ifdef ENABLE_NLS | |
492 bindtextdomain(PACKAGE, LOCALEDIR); | |
493 bind_textdomain_codeset(PACKAGE, "UTF-8"); | |
494 textdomain(PACKAGE); | |
495 #endif | |
496 | |
11080 | 497 |
10302 | 498 #if HAVE_SIGNAL_H |
499 /* Let's not violate any PLA's!!!! */ | |
500 /* jseymour: whatever the fsck that means */ | |
501 /* Robot101: for some reason things like gdm like to block * | |
502 * useful signals like SIGCHLD, so we unblock all the ones we * | |
503 * declare a handler for. thanks JSeymour and Vann. */ | |
504 if (sigemptyset(&sigset)) { | |
505 snprintf(errmsg, BUFSIZ, "Warning: couldn't initialise empty signal set"); | |
506 perror(errmsg); | |
507 } | |
508 for(sig_indx = 0; catch_sig_list[sig_indx] != -1; ++sig_indx) { | |
509 if((prev_sig_disp = signal(catch_sig_list[sig_indx], sighandler)) == SIG_ERR) { | |
510 snprintf(errmsg, BUFSIZ, "Warning: couldn't set signal %d for catching", | |
511 catch_sig_list[sig_indx]); | |
512 perror(errmsg); | |
513 } | |
514 if(sigaddset(&sigset, catch_sig_list[sig_indx])) { | |
515 snprintf(errmsg, BUFSIZ, "Warning: couldn't include signal %d for unblocking", | |
516 catch_sig_list[sig_indx]); | |
517 perror(errmsg); | |
518 } | |
519 } | |
520 for(sig_indx = 0; ignore_sig_list[sig_indx] != -1; ++sig_indx) { | |
521 if((prev_sig_disp = signal(ignore_sig_list[sig_indx], SIG_IGN)) == SIG_ERR) { | |
522 snprintf(errmsg, BUFSIZ, "Warning: couldn't set signal %d to ignore", | |
523 ignore_sig_list[sig_indx]); | |
524 perror(errmsg); | |
525 } | |
526 } | |
527 | |
528 if (sigprocmask(SIG_UNBLOCK, &sigset, NULL)) { | |
529 snprintf(errmsg, BUFSIZ, "Warning: couldn't unblock signals"); | |
530 perror(errmsg); | |
10307 | 531 } |
10302 | 532 #endif |
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 | |
10323 | 550 "ac:dhnl::s:v", |
10302 | 551 #else |
10323 | 552 "ac:dhnl::v", |
10302 | 553 #endif |
554 long_options, NULL)) != -1) { | |
555 switch (opt) { | |
556 case 'a': /* account editor */ | |
10323 | 557 opt_acct = TRUE; |
558 break; | |
559 case 'c': /* config dir */ | |
560 g_free(opt_config_dir_arg); | |
561 opt_config_dir_arg = g_strdup(optarg); | |
10302 | 562 break; |
563 case 'd': /* debug */ | |
10307 | 564 debug_enabled = TRUE; |
10302 | 565 break; |
10323 | 566 case 'h': /* help */ |
567 opt_help = TRUE; | |
568 break; | |
569 case 'n': /* no autologin */ | |
570 opt_nologin = TRUE; | |
10302 | 571 break; |
10323 | 572 case 'l': /* login, option username */ |
573 opt_login = TRUE; | |
574 g_free(opt_login_arg); | |
575 if (optarg != NULL) | |
576 opt_login_arg = g_strdup(optarg); | |
10302 | 577 break; |
10320 | 578 case 's': /* use existing session ID */ |
10323 | 579 g_free(opt_session_arg); |
10320 | 580 opt_session_arg = g_strdup(optarg); |
581 break; | |
10323 | 582 case 'v': /* version */ |
583 opt_version = TRUE; | |
10320 | 584 break; |
10323 | 585 case '?': /* show terse help */ |
10302 | 586 default: |
10320 | 587 show_usage(argv[0], TRUE); |
10302 | 588 return 0; |
589 break; | |
590 } | |
591 } | |
592 | |
593 /* show help message */ | |
594 if (opt_help) { | |
10320 | 595 show_usage(argv[0], FALSE); |
10302 | 596 return 0; |
597 } | |
598 /* show version message */ | |
599 if (opt_version) { | |
10323 | 600 printf("Gaim %s\n", VERSION); |
10302 | 601 return 0; |
602 } | |
603 | |
10323 | 604 /* set a user-specified config directory */ |
605 if (opt_config_dir_arg != NULL) { | |
10871 | 606 gaim_util_set_user_dir(opt_config_dir_arg); |
10323 | 607 } |
608 | |
10448 | 609 /* |
610 * We're done piddling around with command line arguments. | |
611 * Fire up this baby. | |
612 */ | |
613 | |
614 gaim_debug_set_enabled(debug_enabled); | |
615 | |
10302 | 616 #ifdef _WIN32 |
10323 | 617 wgaim_init(hint); |
10302 | 618 #endif |
11067 | 619 |
10302 | 620 gaim_core_set_ui_ops(gaim_gtk_core_get_ui_ops()); |
621 gaim_eventloop_set_ui_ops(gaim_gtk_eventloop_get_ui_ops()); | |
622 | |
10447 | 623 /* Set plugin search directories */ |
624 gaim_plugins_add_search_path(LIBDIR); | |
625 search_path = g_build_filename(gaim_user_dir(), "plugins", NULL); | |
626 gaim_plugins_add_search_path(search_path); | |
627 g_free(search_path); | |
628 | |
10302 | 629 if (!gaim_core_init(GAIM_GTK_UI)) { |
630 fprintf(stderr, | |
631 "Initialization of the Gaim core failed. Dumping core.\n" | |
632 "Please report this!\n"); | |
633 abort(); | |
634 } | |
635 | |
10428 | 636 /* TODO: Move blist loading into gaim_blist_init() */ |
10302 | 637 gaim_set_blist(gaim_blist_new()); |
638 gaim_blist_load(); | |
639 | |
10433 | 640 /* TODO: Move prefs loading into gaim_prefs_init() */ |
10302 | 641 gaim_prefs_load(); |
642 gaim_prefs_update_old(); | |
643 gaim_gtk_prefs_update_old(); | |
644 | |
645 /* load plugins we had when we quit */ | |
646 gaim_plugins_load_saved("/gaim/gtk/plugins/loaded"); | |
647 | |
10433 | 648 /* TODO: Move pounces loading into gaim_pounces_init() */ |
10302 | 649 gaim_pounces_load(); |
650 | |
651 ui_main(); | |
652 | |
653 #ifdef USE_SM | |
654 session_init(argv[0], opt_session_arg, opt_config_dir_arg); | |
655 #endif | |
656 if (opt_session_arg != NULL) { | |
657 g_free(opt_session_arg); | |
658 opt_session_arg = NULL; | |
659 } | |
660 if (opt_config_dir_arg != NULL) { | |
661 g_free(opt_config_dir_arg); | |
662 opt_config_dir_arg = NULL; | |
663 } | |
664 | |
665 if (gaim_prefs_get_bool("/gaim/gtk/debug/enabled")) | |
666 gaim_gtk_debug_window_show(); | |
667 | |
10323 | 668 gaim_blist_show(); |
669 | |
10302 | 670 if (opt_login) { |
671 dologin_ret = dologin_named(opt_login_arg); | |
672 if (opt_login_arg != NULL) { | |
673 g_free(opt_login_arg); | |
674 opt_login_arg = NULL; | |
675 } | |
676 } | |
677 | |
11348 | 678 if (!opt_acct && !opt_nologin) |
10738 | 679 { |
11348 | 680 /* Everything is good to go--sign on already */ |
681 gaim_accounts_restore_previous_statuses(); | |
10738 | 682 } |
10302 | 683 |
11403 | 684 if (opt_acct || (gaim_accounts_get_all_active() == NULL)) |
685 { | |
10302 | 686 gaim_gtk_accounts_window_show(); |
10315 | 687 } |
10302 | 688 |
689 #ifdef HAVE_STARTUP_NOTIFICATION | |
690 startup_notification_complete(); | |
691 #endif | |
10320 | 692 |
10302 | 693 gtk_main(); |
10320 | 694 |
10302 | 695 #ifdef _WIN32 |
696 wgaim_cleanup(); | |
697 #endif | |
698 | |
699 return 0; | |
700 } |