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