Mercurial > pidgin.yaz
annotate src/gtkmain.c @ 11830:9cd233ea2799
[gaim-migrate @ 14121]
Removing a g_free() I added during my first rewrite of the font_size stuff. It doesn't belong there any more.
committer: Tailor Script <tailor@pidgin.im>
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Wed, 26 Oct 2005 01:48:33 +0000 |
parents | 7584d802f0ac |
children | 8913546c6a4e |
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 " -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 | |
10581
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
531 gui_check = gtk_init_check(&argc, &argv); |
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
532 if (!gui_check) { |
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
533 char *display = gdk_get_display(); |
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
534 |
11033
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11010
diff
changeset
|
535 printf("Gaim %s\n", VERSION); |
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11010
diff
changeset
|
536 |
10581
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
537 g_warning("cannot open display: %s", display ? display : "unset"); |
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
538 g_free(display); |
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
539 |
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
540 return 1; |
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
541 } |
59a2807e10bb
[gaim-migrate @ 11981]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10574
diff
changeset
|
542 |
10302 | 543 /* scan command-line options */ |
544 opterr = 1; | |
545 while ((opt = getopt_long(argc, argv, | |
546 #ifndef _WIN32 | |
11795
f48e2acaa5d2
[gaim-migrate @ 14086]
Richard Laager <rlaager@wiktel.com>
parents:
11785
diff
changeset
|
547 "c:dhnl::s:v", |
10302 | 548 #else |
11795
f48e2acaa5d2
[gaim-migrate @ 14086]
Richard Laager <rlaager@wiktel.com>
parents:
11785
diff
changeset
|
549 "c:dhnl::v", |
10302 | 550 #endif |
551 long_options, NULL)) != -1) { | |
552 switch (opt) { | |
10323 | 553 case 'c': /* config dir */ |
554 g_free(opt_config_dir_arg); | |
555 opt_config_dir_arg = g_strdup(optarg); | |
10302 | 556 break; |
557 case 'd': /* debug */ | |
10307 | 558 debug_enabled = TRUE; |
10302 | 559 break; |
10323 | 560 case 'h': /* help */ |
561 opt_help = TRUE; | |
562 break; | |
563 case 'n': /* no autologin */ | |
564 opt_nologin = TRUE; | |
10302 | 565 break; |
10323 | 566 case 'l': /* login, option username */ |
567 opt_login = TRUE; | |
568 g_free(opt_login_arg); | |
569 if (optarg != NULL) | |
570 opt_login_arg = g_strdup(optarg); | |
10302 | 571 break; |
10320 | 572 case 's': /* use existing session ID */ |
10323 | 573 g_free(opt_session_arg); |
10320 | 574 opt_session_arg = g_strdup(optarg); |
575 break; | |
10323 | 576 case 'v': /* version */ |
577 opt_version = TRUE; | |
10320 | 578 break; |
10323 | 579 case '?': /* show terse help */ |
10302 | 580 default: |
10320 | 581 show_usage(argv[0], TRUE); |
10302 | 582 return 0; |
583 break; | |
584 } | |
585 } | |
586 | |
587 /* show help message */ | |
588 if (opt_help) { | |
10320 | 589 show_usage(argv[0], FALSE); |
10302 | 590 return 0; |
591 } | |
592 /* show version message */ | |
593 if (opt_version) { | |
10323 | 594 printf("Gaim %s\n", VERSION); |
10302 | 595 return 0; |
596 } | |
597 | |
10323 | 598 /* set a user-specified config directory */ |
599 if (opt_config_dir_arg != NULL) { | |
10871 | 600 gaim_util_set_user_dir(opt_config_dir_arg); |
10323 | 601 } |
602 | |
10448 | 603 /* |
604 * We're done piddling around with command line arguments. | |
605 * Fire up this baby. | |
606 */ | |
607 | |
608 gaim_debug_set_enabled(debug_enabled); | |
609 | |
10302 | 610 #ifdef _WIN32 |
10323 | 611 wgaim_init(hint); |
10302 | 612 #endif |
11067 | 613 |
10302 | 614 gaim_core_set_ui_ops(gaim_gtk_core_get_ui_ops()); |
615 gaim_eventloop_set_ui_ops(gaim_gtk_eventloop_get_ui_ops()); | |
616 | |
10447 | 617 /* Set plugin search directories */ |
618 gaim_plugins_add_search_path(LIBDIR); | |
619 search_path = g_build_filename(gaim_user_dir(), "plugins", NULL); | |
620 gaim_plugins_add_search_path(search_path); | |
621 g_free(search_path); | |
622 | |
10302 | 623 if (!gaim_core_init(GAIM_GTK_UI)) { |
624 fprintf(stderr, | |
625 "Initialization of the Gaim core failed. Dumping core.\n" | |
626 "Please report this!\n"); | |
627 abort(); | |
628 } | |
629 | |
10428 | 630 /* TODO: Move blist loading into gaim_blist_init() */ |
10302 | 631 gaim_set_blist(gaim_blist_new()); |
632 gaim_blist_load(); | |
633 | |
10433 | 634 /* TODO: Move prefs loading into gaim_prefs_init() */ |
10302 | 635 gaim_prefs_load(); |
636 gaim_prefs_update_old(); | |
637 gaim_gtk_prefs_update_old(); | |
638 | |
639 /* load plugins we had when we quit */ | |
640 gaim_plugins_load_saved("/gaim/gtk/plugins/loaded"); | |
641 | |
10433 | 642 /* TODO: Move pounces loading into gaim_pounces_init() */ |
10302 | 643 gaim_pounces_load(); |
644 | |
645 ui_main(); | |
646 | |
647 #ifdef USE_SM | |
648 session_init(argv[0], opt_session_arg, opt_config_dir_arg); | |
649 #endif | |
650 if (opt_session_arg != NULL) { | |
651 g_free(opt_session_arg); | |
652 opt_session_arg = NULL; | |
653 } | |
654 if (opt_config_dir_arg != NULL) { | |
655 g_free(opt_config_dir_arg); | |
656 opt_config_dir_arg = NULL; | |
657 } | |
658 | |
659 if (gaim_prefs_get_bool("/gaim/gtk/debug/enabled")) | |
660 gaim_gtk_debug_window_show(); | |
661 | |
10323 | 662 gaim_blist_show(); |
663 | |
10302 | 664 if (opt_login) { |
665 dologin_ret = dologin_named(opt_login_arg); | |
666 if (opt_login_arg != NULL) { | |
667 g_free(opt_login_arg); | |
668 opt_login_arg = NULL; | |
669 } | |
670 } | |
671 | |
11806 | 672 if (opt_nologin) |
673 { | |
674 /* Set all accounts to "offline" */ | |
675 GaimSavedStatus *saved_status; | |
676 saved_status = gaim_savedstatus_find(_("Default")); | |
677 if (saved_status == NULL) | |
678 saved_status = gaim_savedstatus_new(_("Default"), GAIM_STATUS_OFFLINE); | |
679 else | |
680 gaim_savedstatus_set_type(saved_status, GAIM_STATUS_OFFLINE); | |
681 gaim_prefs_set_string("/core/status/current", _("Default")); | |
682 gaim_savedstatus_activate(saved_status); | |
683 } | |
684 else | |
10738 | 685 { |
11348 | 686 /* Everything is good to go--sign on already */ |
687 gaim_accounts_restore_previous_statuses(); | |
10738 | 688 } |
10302 | 689 |
11785 | 690 if (gaim_accounts_get_all_active() == NULL) |
11403 | 691 { |
10302 | 692 gaim_gtk_accounts_window_show(); |
10315 | 693 } |
10302 | 694 |
695 #ifdef HAVE_STARTUP_NOTIFICATION | |
696 startup_notification_complete(); | |
697 #endif | |
10320 | 698 |
10302 | 699 gtk_main(); |
10320 | 700 |
10302 | 701 #ifdef _WIN32 |
702 wgaim_cleanup(); | |
703 #endif | |
704 | |
705 return 0; | |
706 } |