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"
|
|
41
|
|
42 #include "gtkaccount.h"
|
|
43 #include "gtkblist.h"
|
|
44 #include "gtkconn.h"
|
|
45 #include "gtkconv.h"
|
|
46 #include "gtkdebug.h"
|
|
47 #include "gtkdialogs.h"
|
|
48 #include "gtkeventloop.h"
|
|
49 #include "gtkft.h"
|
|
50 #include "gtknotify.h"
|
|
51 #include "gtkplugin.h"
|
|
52 #include "gtkpounce.h"
|
|
53 #include "gtkprefs.h"
|
|
54 #include "gtkprivacy.h"
|
|
55 #include "gtkrequest.h"
|
|
56 #include "gtkroomlist.h"
|
|
57 #include "gtksound.h"
|
|
58 #include "gtkutils.h"
|
|
59 #include "gtkstock.h"
|
|
60
|
|
61 #if HAVE_SIGNAL_H
|
|
62 # include <signal.h>
|
|
63 #endif
|
|
64
|
|
65 #include <getopt.h>
|
|
66
|
|
67 #ifdef HAVE_STARTUP_NOTIFICATION
|
|
68 # define SN_API_NOT_YET_FROZEN
|
|
69 # include <libsn/sn-launchee.h>
|
|
70 # include <gdk/gdkx.h>
|
|
71 #endif
|
|
72
|
|
73 #ifdef HAVE_STARTUP_NOTIFICATION
|
|
74 static SnLauncheeContext *sn_context = NULL;
|
|
75 static SnDisplay *sn_display = NULL;
|
|
76 #endif
|
|
77
|
|
78 int opt_away = 0;
|
|
79 int docklet_count = 0;
|
|
80 char *opt_away_arg = NULL;
|
|
81
|
|
82 #if HAVE_SIGNAL_H
|
|
83 /*
|
|
84 * Lists of signals we wish to catch and those we wish to ignore.
|
|
85 * Each list terminated with -1
|
|
86 */
|
|
87 static int catch_sig_list[] = {
|
|
88 SIGSEGV,
|
|
89 SIGHUP,
|
|
90 SIGINT,
|
|
91 SIGTERM,
|
|
92 SIGQUIT,
|
|
93 SIGCHLD,
|
|
94 -1
|
|
95 };
|
|
96
|
|
97 static int ignore_sig_list[] = {
|
|
98 SIGPIPE,
|
|
99 -1
|
|
100 };
|
|
101 #endif
|
|
102
|
|
103 static guint snd_tmout = 0;
|
|
104 static gboolean sound_timeout(gpointer data)
|
|
105 {
|
|
106 gaim_gtk_sound_set_login_mute(FALSE);
|
|
107 snd_tmout = 0;
|
|
108 return FALSE;
|
|
109 }
|
|
110
|
|
111 /* we need to do this for Oscar because serv_login only starts the login
|
|
112 * process, it doesn't end there. gaim_setup will be called later from
|
|
113 * oscar.c, after the buddy list is made and serv_finish_login is called */
|
|
114 void gaim_setup(GaimConnection *gc)
|
|
115 {
|
|
116 if (gaim_prefs_get_bool("/gaim/gtk/sound/enabled/login")) {
|
|
117 if (snd_tmout)
|
|
118 g_source_remove(snd_tmout);
|
|
119 gaim_gtk_sound_set_login_mute(TRUE);
|
|
120 snd_tmout = gaim_timeout_add(10000, sound_timeout, NULL);
|
|
121 }
|
|
122 }
|
|
123
|
|
124 static int dologin_named(char *name)
|
|
125 {
|
|
126 GaimAccount *account;
|
|
127 char **names, **n;
|
|
128 int retval = -1;
|
|
129
|
|
130 if (name !=NULL) { /* list of names given */
|
|
131 names = g_strsplit(name, ",", 32);
|
|
132 for (n = names; *n != NULL; n++) {
|
|
133 account = gaim_accounts_find(*n, NULL);
|
|
134 if (account) { /* found a user */
|
|
135 retval = 0;
|
|
136 gaim_account_connect(account);
|
|
137 }
|
|
138 }
|
|
139 g_strfreev(names);
|
|
140 } else { /* no name given, use default */
|
|
141 account = (GaimAccount *)gaim_accounts_get_all()->data;
|
|
142 retval = 0;
|
|
143 gaim_account_connect(account);
|
|
144 }
|
|
145
|
|
146 return retval;
|
|
147 }
|
|
148
|
|
149 static void
|
|
150 clean_pid(void)
|
|
151 {
|
|
152 #ifndef _WIN32
|
|
153 int status;
|
|
154 pid_t pid;
|
|
155
|
|
156 do {
|
|
157 pid = waitpid(-1, &status, WNOHANG);
|
|
158 } while (pid != 0 && pid != (pid_t)-1);
|
|
159 if(pid == (pid_t)-1 && errno != ECHILD) {
|
|
160 char errmsg[BUFSIZ];
|
|
161 snprintf(errmsg, BUFSIZ, "Warning: waitpid() returned %d", pid);
|
|
162 perror(errmsg);
|
|
163 }
|
|
164 #endif
|
|
165 }
|
|
166
|
|
167 #if HAVE_SIGNAL_H
|
|
168 void sighandler(int sig)
|
|
169 {
|
|
170 switch (sig) {
|
|
171 case SIGHUP:
|
|
172 gaim_debug(GAIM_DEBUG_WARNING, "sighandler",
|
|
173 "Caught signal %d\n", sig);
|
|
174 gaim_connections_disconnect_all();
|
|
175 break;
|
|
176 case SIGSEGV:
|
|
177 #ifndef DEBUG
|
|
178 fprintf(stderr, "Gaim has segfaulted and attempted to dump a core file.\n"
|
|
179 "This is a bug in the software and has happened through\n"
|
|
180 "no fault of your own.\n\n"
|
|
181 "It is possible that this bug is already fixed in CVS.\n"
|
|
182 "If you can reproduce the crash, please notify the gaim\n"
|
|
183 "maintainers by reporting a bug at\n"
|
|
184 GAIM_WEBSITE "bug.php\n\n"
|
|
185 "Please make sure to specify what you were doing at the time,\n"
|
|
186 "and post the backtrace from the core file. If you do not know\n"
|
|
187 "how to get the backtrace, please get instructions at\n"
|
|
188 GAIM_WEBSITE "gdb.php. If you need further\n"
|
|
189 "assistance, please IM either RobFlynn or SeanEgn and\n"
|
|
190 "they can help you.\n");
|
|
191 #else
|
|
192 fprintf(stderr, "Hi, user. We need to talk.\n"
|
|
193 "I think something's gone wrong here. It's probably my fault.\n"
|
|
194 "No, really, it's not you... it's me... no no no, I think we get along well\n"
|
|
195 "it's just that.... well, I want to see other people. I... what?!? NO! I haven't\n"
|
|
196 "been cheating on you!! How many times do you want me to tell you?! And for the\n"
|
|
197 "last time, it's just a rash!\n");
|
|
198 /*g_on_error_query (g_get_prgname());*/
|
|
199 #endif
|
|
200 abort();
|
|
201 break;
|
|
202 case SIGCHLD:
|
|
203 clean_pid();
|
|
204 #if HAVE_SIGNAL_H
|
|
205 signal(SIGCHLD, sighandler); /* restore signal catching on this one! */
|
|
206 #endif
|
|
207 break;
|
|
208 default:
|
|
209 gaim_debug(GAIM_DEBUG_WARNING, "sighandler",
|
|
210 "Caught signal %d\n", sig);
|
|
211 gaim_connections_disconnect_all();
|
|
212
|
|
213 gaim_plugins_unload_all();
|
|
214
|
|
215 if (gtk_main_level())
|
|
216 gtk_main_quit();
|
|
217 exit(0);
|
|
218 }
|
|
219 }
|
|
220 #endif
|
|
221
|
|
222 static int ui_main()
|
|
223 {
|
|
224 #ifndef _WIN32
|
|
225 GList *icons = NULL;
|
|
226 GdkPixbuf *icon = NULL;
|
|
227 char *icon_path;
|
|
228 #endif
|
|
229
|
|
230 if (current_smiley_theme == NULL) {
|
|
231 smiley_theme_probe();
|
|
232 if (smiley_themes) {
|
|
233 struct smiley_theme *smile = smiley_themes->data;
|
|
234 load_smiley_theme(smile->path, TRUE);
|
|
235 }
|
|
236 }
|
|
237
|
|
238 gaim_gtk_blist_setup_sort_methods();
|
|
239
|
|
240 #ifndef _WIN32
|
|
241 /* use the nice PNG icon for all the windows */
|
|
242 icon_path = g_build_filename(DATADIR, "pixmaps", "gaim", "icons", "online.png", NULL);
|
|
243 icon = gdk_pixbuf_new_from_file(icon_path, NULL);
|
|
244 g_free(icon_path);
|
|
245 if (icon) {
|
|
246 icons = g_list_append(icons,icon);
|
|
247 gtk_window_set_default_icon_list(icons);
|
|
248 g_object_unref(G_OBJECT(icon));
|
|
249 g_list_free(icons);
|
|
250 } else {
|
|
251 gaim_debug(GAIM_DEBUG_ERROR, "ui_main",
|
|
252 "Failed to load the default window icon!\n");
|
|
253 }
|
|
254 #endif
|
|
255
|
|
256 return 0;
|
|
257 }
|
|
258
|
|
259 static void set_first_user(const char *name)
|
|
260 {
|
|
261 GaimAccount *account;
|
|
262
|
|
263 account = gaim_accounts_find(name, NULL);
|
|
264
|
|
265 /* Place it as the first user. */
|
|
266 if (account != NULL)
|
|
267 gaim_accounts_reorder(account, 0);
|
|
268 }
|
|
269
|
|
270 static void
|
|
271 debug_init(void)
|
|
272 {
|
|
273 gaim_debug_set_ui_ops(gaim_gtk_debug_get_ui_ops());
|
|
274 gaim_gtk_debug_init();
|
|
275 }
|
|
276
|
|
277 static void
|
|
278 gaim_gtk_ui_init(void)
|
|
279 {
|
|
280 /* Set the UI operation structures. */
|
|
281 gaim_accounts_set_ui_ops(gaim_gtk_accounts_get_ui_ops());
|
|
282 gaim_conversations_set_win_ui_ops(gaim_gtk_conversations_get_win_ui_ops());
|
|
283 gaim_xfers_set_ui_ops(gaim_gtk_xfers_get_ui_ops());
|
|
284 gaim_blist_set_ui_ops(gaim_gtk_blist_get_ui_ops());
|
|
285 gaim_notify_set_ui_ops(gaim_gtk_notify_get_ui_ops());
|
|
286 gaim_privacy_set_ui_ops(gaim_gtk_privacy_get_ui_ops());
|
|
287 gaim_request_set_ui_ops(gaim_gtk_request_get_ui_ops());
|
|
288 gaim_sound_set_ui_ops(gaim_gtk_sound_get_ui_ops());
|
|
289 gaim_connections_set_ui_ops(gaim_gtk_connections_get_ui_ops());
|
|
290
|
|
291 gaim_gtk_stock_init();
|
|
292 gaim_gtk_prefs_init();
|
|
293 gaim_gtk_account_init();
|
|
294 gaim_gtk_blist_init();
|
|
295 gaim_gtk_conversations_init();
|
|
296 gaim_gtk_pounces_init();
|
|
297 gaim_gtk_privacy_init();
|
|
298 gaim_gtk_xfers_init();
|
|
299 gaim_gtk_roomlist_init();
|
|
300 }
|
|
301
|
|
302 static void
|
|
303 gaim_gtk_quit(void)
|
|
304 {
|
|
305 /* XXX? */
|
|
306 /* YYY is there an XXX here? */
|
|
307
|
|
308 /* captain's log, stardate... */
|
|
309 /* LOG system_log(log_quit, NULL, NULL, OPT_LOG_BUDDY_SIGNON | OPT_LOG_MY_SIGNON); */
|
|
310
|
|
311 #ifdef USE_SM
|
|
312 /* unplug */
|
|
313 session_end();
|
|
314 #endif
|
|
315
|
|
316 /* Save the plugins we have loaded for next time. */
|
|
317 gaim_gtk_plugins_save();
|
|
318
|
|
319 /* and end it all... */
|
|
320 gtk_main_quit();
|
|
321 }
|
|
322
|
|
323 static GaimCoreUiOps core_ops =
|
|
324 {
|
|
325 gaim_gtk_prefs_init,
|
|
326 debug_init,
|
|
327 gaim_gtk_ui_init,
|
|
328 gaim_gtk_quit
|
|
329 };
|
|
330
|
|
331 static GaimCoreUiOps *
|
|
332 gaim_gtk_core_get_ui_ops(void)
|
|
333 {
|
|
334 return &core_ops;
|
|
335 }
|
|
336
|
|
337 static void
|
|
338 show_usage(int mode, const char *name)
|
|
339 {
|
|
340 char *text=NULL;
|
|
341
|
|
342 switch (mode) {
|
|
343 case 0: /* full help text */
|
|
344 text=g_strdup_printf(_("Gaim %s\n"
|
|
345 "Usage: %s [OPTION]...\n\n"
|
|
346 " -a, --acct display account editor window\n"
|
|
347 " -w, --away[=MESG] make away on signon (optional argument MESG specifies\n"
|
|
348 " name of away message to use)\n"
|
|
349 " -l, --login[=NAME] automatically login (optional argument NAME specifies\n"
|
|
350 " account(s) to use, seperated by commas)\n"
|
|
351 " -n, --loginwin don't automatically login; show login window\n"
|
|
352 " -u, --user=NAME use account NAME\n"
|
|
353 " -c, --config=DIR use DIR for config files\n"
|
|
354 " -d, --debug print debugging messages to stdout\n"
|
|
355 " -v, --version display the current version and exit\n"
|
|
356 " -h, --help display this help and exit\n"), VERSION, name);
|
|
357 break;
|
|
358 case 1: /* short message */
|
|
359 text=g_strdup_printf(_("Gaim %s. Try `%s -h' for more information.\n"), VERSION, name);
|
|
360 break;
|
|
361 }
|
|
362
|
|
363 if(text) {
|
|
364 char *text_conv;
|
|
365 GError *error=NULL;
|
|
366
|
|
367 /* tries to convert 'text' to users locale */
|
|
368 text_conv=g_locale_from_utf8(text,-1,NULL,NULL,&error);
|
|
369 if(text_conv) {
|
|
370 puts(text_conv);
|
|
371 g_free(text_conv);
|
|
372 }
|
|
373 /* use 'text' as a fallback */
|
|
374 else {
|
|
375 g_warning("%s\n", error->message);
|
|
376 g_error_free(error);
|
|
377 puts(text);
|
|
378 }
|
|
379 g_free(text);
|
|
380 }
|
|
381 }
|
|
382
|
|
383 #ifdef HAVE_STARTUP_NOTIFICATION
|
|
384 static void
|
|
385 sn_error_trap_push(SnDisplay *display, Display *xdisplay)
|
|
386 {
|
|
387 gdk_error_trap_push();
|
|
388 }
|
|
389
|
|
390 static void
|
|
391 sn_error_trap_pop(SnDisplay *display, Display *xdisplay)
|
|
392 {
|
|
393 gdk_error_trap_pop();
|
|
394 }
|
|
395
|
|
396 static void
|
|
397 startup_notification_complete(void)
|
|
398 {
|
|
399 Display *xdisplay;
|
|
400
|
|
401 xdisplay = GDK_DISPLAY();
|
|
402 sn_display = sn_display_new(xdisplay,
|
|
403 sn_error_trap_push,
|
|
404 sn_error_trap_pop);
|
|
405 sn_context =
|
|
406 sn_launchee_context_new_from_environment(sn_display,
|
|
407 DefaultScreen(xdisplay));
|
|
408
|
|
409 if (sn_context != NULL)
|
|
410 {
|
|
411 sn_launchee_context_complete(sn_context);
|
|
412 sn_launchee_context_unref(sn_context);
|
|
413
|
|
414 sn_display_unref(sn_display);
|
|
415 }
|
|
416 }
|
|
417 #endif /* HAVE_STARTUP_NOTIFICATION */
|
|
418
|
|
419 #ifndef _WIN32
|
|
420 static char *gaim_find_binary_location(void *symbol, void *data)
|
|
421 {
|
|
422 static char *fullname = NULL;
|
|
423 static gboolean first = TRUE;
|
|
424
|
|
425 char *argv0 = data;
|
|
426 struct stat st;
|
|
427 char *basebuf, *linkbuf, *fullbuf;
|
|
428
|
|
429 if (!first)
|
|
430 /* We've already been through this. */
|
|
431 return strdup(fullname);
|
|
432
|
|
433 first = FALSE;
|
|
434
|
|
435 if (!argv0)
|
|
436 return NULL;
|
|
437
|
|
438
|
|
439 basebuf = g_find_program_in_path(argv0);
|
|
440
|
|
441 /* But we still need to deal with symbolic links */
|
|
442 lstat(basebuf, &st);
|
|
443 while ((st.st_mode & S_IFLNK) == S_IFLNK) {
|
|
444 linkbuf = g_malloc(1024);
|
|
445 readlink(basebuf, linkbuf, 1024);
|
|
446 if (linkbuf[0] == G_DIR_SEPARATOR) {
|
|
447 /* an absolute path */
|
|
448 fullbuf = g_strdup(linkbuf);
|
|
449 } else {
|
|
450 char *dirbuf = g_path_get_dirname(basebuf);
|
|
451 /* a relative path */
|
|
452 fullbuf = g_strdup_printf("%s%s%s",
|
|
453 dirbuf, G_DIR_SEPARATOR_S,
|
|
454 linkbuf);
|
|
455 g_free(dirbuf);
|
|
456 }
|
|
457 /* There's no memory leak here. Really! */
|
|
458 g_free(linkbuf);
|
|
459 g_free(basebuf);
|
|
460 basebuf = fullbuf;
|
|
461 lstat(basebuf, &st);
|
|
462 }
|
|
463
|
|
464 fullname = basebuf;
|
|
465 return strdup(fullname);
|
|
466 }
|
|
467 #endif /* #ifndef _WIN32 */
|
|
468
|
|
469 /* FUCKING GET ME A TOWEL! */
|
|
470 #ifdef _WIN32
|
|
471 int gaim_main(HINSTANCE hint, int argc, char *argv[])
|
|
472 #else
|
|
473 int main(int argc, char *argv[])
|
|
474 #endif
|
|
475 {
|
|
476 int opt_acct = 0, opt_help = 0, opt_version = 0, opt_login = 0, opt_nologin = 0, dologin_ret = -1;
|
|
477 char *opt_user_arg = NULL, *opt_login_arg = NULL;
|
|
478 char *opt_session_arg = NULL, *opt_config_dir_arg = NULL;
|
|
479 char *plugin_search_paths[3];
|
|
480 #if HAVE_SIGNAL_H
|
|
481 int sig_indx; /* for setting up signal catching */
|
|
482 sigset_t sigset;
|
|
483 void (*prev_sig_disp)();
|
|
484 #endif
|
|
485 int opt, opt_user = 0;
|
|
486 int i;
|
|
487 gboolean gui_check;
|
10307
|
488 gboolean debug_enabled;
|
10302
|
489 gchar *gaimrc, *accountsxml;
|
|
490
|
|
491 struct option long_options[] = {
|
|
492 {"acct", no_argument, NULL, 'a'},
|
|
493 /*{"away", optional_argument, NULL, 'w'}, */
|
|
494 {"help", no_argument, NULL, 'h'},
|
|
495 /*{"login", optional_argument, NULL, 'l'}, */
|
|
496 {"loginwin", no_argument, NULL, 'n'},
|
|
497 {"user", required_argument, NULL, 'u'},
|
|
498 {"config", required_argument, NULL, 'c'},
|
|
499 {"debug", no_argument, NULL, 'd'},
|
|
500 {"version", no_argument, NULL, 'v'},
|
|
501 {"session", required_argument, NULL, 's'},
|
|
502 {0, 0, 0, 0}
|
|
503 };
|
|
504
|
|
505 #ifdef DEBUG
|
10307
|
506 debug_enabled = TRUE;
|
|
507 #else
|
|
508 debug_enabled = FALSE;
|
10302
|
509 #endif
|
10307
|
510
|
10302
|
511 #ifndef _WIN32
|
|
512 br_set_locate_fallback_func(gaim_find_binary_location, argv[0]);
|
|
513 #endif
|
|
514 #ifdef ENABLE_NLS
|
|
515 bindtextdomain(PACKAGE, LOCALEDIR);
|
|
516 bind_textdomain_codeset(PACKAGE, "UTF-8");
|
|
517 textdomain(PACKAGE);
|
|
518 #endif
|
|
519
|
|
520 #if HAVE_SIGNAL_H
|
|
521 /* Let's not violate any PLA's!!!! */
|
|
522 /* jseymour: whatever the fsck that means */
|
|
523 /* Robot101: for some reason things like gdm like to block *
|
|
524 * useful signals like SIGCHLD, so we unblock all the ones we *
|
|
525 * declare a handler for. thanks JSeymour and Vann. */
|
|
526 if (sigemptyset(&sigset)) {
|
|
527 char errmsg[BUFSIZ];
|
|
528 snprintf(errmsg, BUFSIZ, "Warning: couldn't initialise empty signal set");
|
|
529 perror(errmsg);
|
|
530 }
|
|
531 for(sig_indx = 0; catch_sig_list[sig_indx] != -1; ++sig_indx) {
|
|
532 if((prev_sig_disp = signal(catch_sig_list[sig_indx], sighandler)) == SIG_ERR) {
|
|
533 char errmsg[BUFSIZ];
|
|
534 snprintf(errmsg, BUFSIZ, "Warning: couldn't set signal %d for catching",
|
|
535 catch_sig_list[sig_indx]);
|
|
536 perror(errmsg);
|
|
537 }
|
|
538 if(sigaddset(&sigset, catch_sig_list[sig_indx])) {
|
|
539 char errmsg[BUFSIZ];
|
|
540 snprintf(errmsg, BUFSIZ, "Warning: couldn't include signal %d for unblocking",
|
|
541 catch_sig_list[sig_indx]);
|
|
542 perror(errmsg);
|
|
543 }
|
|
544 }
|
|
545 for(sig_indx = 0; ignore_sig_list[sig_indx] != -1; ++sig_indx) {
|
|
546 if((prev_sig_disp = signal(ignore_sig_list[sig_indx], SIG_IGN)) == SIG_ERR) {
|
|
547 char errmsg[BUFSIZ];
|
|
548 snprintf(errmsg, BUFSIZ, "Warning: couldn't set signal %d to ignore",
|
|
549 ignore_sig_list[sig_indx]);
|
|
550 perror(errmsg);
|
|
551 }
|
|
552 }
|
|
553
|
|
554 if (sigprocmask(SIG_UNBLOCK, &sigset, NULL)) {
|
|
555 char errmsg[BUFSIZ];
|
|
556 snprintf(errmsg, BUFSIZ, "Warning: couldn't unblock signals");
|
|
557 perror(errmsg);
|
10307
|
558 }
|
10302
|
559 #endif
|
|
560
|
|
561 for (i = 0; i < argc; i++) {
|
|
562 /* --login option */
|
|
563 if (strstr(argv[i], "--l") == argv[i]) {
|
|
564 char *equals;
|
|
565 opt_login = 1;
|
|
566 if ((equals = strchr(argv[i], '=')) != NULL) {
|
|
567 /* --login=NAME */
|
|
568 opt_login_arg = g_strdup(equals + 1);
|
|
569 if (strlen(opt_login_arg) == 0) {
|
|
570 g_free(opt_login_arg);
|
|
571 opt_login_arg = NULL;
|
|
572 }
|
|
573 } else if (i + 1 < argc && argv[i + 1][0] != '-') {
|
|
574 /* --login NAME */
|
|
575 opt_login_arg = g_strdup(argv[i + 1]);
|
|
576 strcpy(argv[i + 1], " ");
|
|
577 }
|
|
578 strcpy(argv[i], " ");
|
|
579 }
|
|
580 /* -l option */
|
|
581 else if (strstr(argv[i], "-l") == argv[i]) {
|
|
582 opt_login = 1;
|
|
583 if (strlen(argv[i]) > 2) {
|
|
584 /* -lNAME */
|
|
585 opt_login_arg = g_strdup(argv[i] + 2);
|
|
586 } else if (i + 1 < argc && argv[i + 1][0] != '-') {
|
|
587 /* -l NAME */
|
|
588 opt_login_arg = g_strdup(argv[i + 1]);
|
|
589 strcpy(argv[i + 1], " ");
|
|
590 }
|
|
591 strcpy(argv[i], " ");
|
|
592 }
|
|
593 /* --away option */
|
|
594 else if (strstr(argv[i], "--aw") == argv[i]) {
|
|
595 char *equals;
|
|
596 opt_away = 1;
|
|
597 if ((equals = strchr(argv[i], '=')) != NULL) {
|
|
598 /* --away=MESG */
|
|
599 opt_away_arg = g_strdup(equals + 1);
|
|
600 if (strlen(opt_away_arg) == 0) {
|
|
601 g_free(opt_away_arg);
|
|
602 opt_away_arg = NULL;
|
|
603 }
|
|
604 } else if (i + 1 < argc && argv[i + 1][0] != '-') {
|
|
605 /* --away MESG */
|
|
606 opt_away_arg = g_strdup(argv[i + 1]);
|
|
607 strcpy(argv[i + 1], " ");
|
|
608 }
|
|
609 strcpy(argv[i], " ");
|
|
610 }
|
|
611 /* -w option */
|
|
612 else if (strstr(argv[i], "-w") == argv[i]) {
|
|
613 opt_away = 1;
|
|
614 if (strlen(argv[i]) > 2) {
|
|
615 /* -wMESG */
|
|
616 opt_away_arg = g_strdup(argv[i] + 2);
|
|
617 } else if (i + 1 < argc && argv[i + 1][0] != '-') {
|
|
618 /* -w MESG */
|
|
619 opt_away_arg = g_strdup(argv[i + 1]);
|
|
620 strcpy(argv[i + 1], " ");
|
|
621 }
|
|
622 strcpy(argv[i], " ");
|
|
623 }
|
|
624 }
|
|
625 /*
|
|
626 if (opt_login) {
|
|
627 printf ("--login given with arg %s\n",
|
|
628 opt_login_arg ? opt_login_arg : "NULL");
|
|
629 exit(0);
|
|
630 }
|
|
631 */
|
|
632
|
|
633 gui_check = gtk_init_check(&argc, &argv);
|
|
634
|
|
635 /* scan command-line options */
|
|
636 opterr = 1;
|
|
637 while ((opt = getopt_long(argc, argv,
|
|
638 #ifndef _WIN32
|
10307
|
639 "adhu:c:vns:",
|
10302
|
640 #else
|
10307
|
641 "adhu:c:vn",
|
10302
|
642 #endif
|
|
643 long_options, NULL)) != -1) {
|
|
644 switch (opt) {
|
|
645 case 'u': /* set user */
|
|
646 opt_user = 1;
|
|
647 opt_user_arg = g_strdup(optarg);
|
|
648 break;
|
|
649 case 'a': /* account editor */
|
|
650 opt_acct = 1;
|
|
651 break;
|
|
652 case 'd': /* debug */
|
10307
|
653 debug_enabled = TRUE;
|
10302
|
654 break;
|
|
655 case 'c': /* use specified config dir */
|
|
656 set_gaim_user_dir(optarg);
|
|
657 opt_config_dir_arg = g_strdup(optarg);
|
|
658 break;
|
|
659 case 's': /* use existing session ID */
|
|
660 opt_session_arg = g_strdup(optarg);
|
|
661 break;
|
|
662 case 'v': /* version */
|
|
663 opt_version = 1;
|
|
664 break;
|
|
665 case 'h': /* help */
|
|
666 opt_help = 1;
|
|
667 break;
|
|
668 case 'n': /* don't autologin */
|
|
669 opt_nologin = 1;
|
|
670 break;
|
|
671 case '?':
|
|
672 default:
|
|
673 show_usage(1, argv[0]);
|
|
674 return 0;
|
|
675 break;
|
|
676 }
|
|
677 }
|
|
678
|
|
679 /* show help message */
|
|
680 if (opt_help) {
|
|
681 show_usage(0, argv[0]);
|
|
682 return 0;
|
|
683 }
|
|
684 /* show version message */
|
|
685 if (opt_version) {
|
|
686 printf("Gaim %s\n",VERSION);
|
|
687 return 0;
|
|
688 }
|
|
689
|
|
690 if (!gui_check) {
|
|
691 char *display = gdk_get_display();
|
|
692
|
|
693 g_warning("cannot open display: %s", display ? display : "unset");
|
|
694 g_free(display);
|
|
695
|
|
696 return 1;
|
|
697 }
|
|
698
|
|
699 #ifdef _WIN32
|
|
700 wgaim_init(hint);
|
|
701 #endif
|
|
702 gaim_core_set_ui_ops(gaim_gtk_core_get_ui_ops());
|
|
703 gaim_eventloop_set_ui_ops(gaim_gtk_eventloop_get_ui_ops());
|
|
704
|
|
705 if (!gaim_core_init(GAIM_GTK_UI)) {
|
|
706 fprintf(stderr,
|
|
707 "Initialization of the Gaim core failed. Dumping core.\n"
|
|
708 "Please report this!\n");
|
|
709 abort();
|
|
710 }
|
|
711
|
10307
|
712 gaim_debug_set_enabled(debug_enabled);
|
|
713
|
10302
|
714 plugin_search_paths[0] = g_strdup(LIBDIR);
|
|
715 plugin_search_paths[1] = gaim_user_dir();
|
|
716 plugin_search_paths[2] = g_build_filename(gaim_user_dir(), "plugins", NULL);
|
|
717
|
|
718 gaim_plugins_set_search_paths(sizeof(plugin_search_paths) /
|
|
719 sizeof(*plugin_search_paths),
|
|
720 plugin_search_paths);
|
|
721
|
|
722 g_free(plugin_search_paths[0]);
|
|
723 g_free(plugin_search_paths[2]);
|
|
724
|
|
725 gaim_plugins_probe(NULL);
|
|
726
|
|
727 /* XXX - Remove this check. Maybe in 2005. --KingAnt, 25 Jul 2004 */
|
|
728 gaimrc = g_build_filename(gaim_home_dir(), ".gaimrc", NULL);
|
|
729 accountsxml = g_build_filename(gaim_user_dir(), "accounts.xml", NULL);
|
|
730 if (g_file_test(gaimrc, G_FILE_TEST_EXISTS) &&
|
|
731 !g_file_test(accountsxml, G_FILE_TEST_EXISTS)) {
|
|
732 gaim_notify_error(NULL, NULL, _("Unable to load preferences"), _("Gaim was not able to load your preferences because they are stored in an old format that is no longer used. Please reconfigure your settings using the Preferences window."));
|
|
733 }
|
|
734 g_free(gaimrc);
|
|
735 g_free(accountsxml);
|
|
736
|
|
737 gaim_accounts_load();
|
|
738
|
|
739 gaim_set_blist(gaim_blist_new());
|
|
740 gaim_blist_load();
|
|
741
|
|
742 gaim_prefs_load();
|
|
743 gaim_prefs_update_old();
|
|
744 gaim_gtk_prefs_update_old();
|
|
745
|
|
746 /* load plugins we had when we quit */
|
|
747 gaim_plugins_load_saved("/gaim/gtk/plugins/loaded");
|
|
748
|
|
749 gaim_pounces_load();
|
|
750 gaim_statuses_load();
|
|
751
|
|
752 ui_main();
|
|
753
|
|
754 #ifdef USE_SM
|
|
755 session_init(argv[0], opt_session_arg, opt_config_dir_arg);
|
|
756 #endif
|
|
757 if (opt_session_arg != NULL) {
|
|
758 g_free(opt_session_arg);
|
|
759 opt_session_arg = NULL;
|
|
760 }
|
10307
|
761
|
10302
|
762 if (opt_config_dir_arg != NULL) {
|
|
763 g_free(opt_config_dir_arg);
|
|
764 opt_config_dir_arg = NULL;
|
|
765 }
|
|
766
|
|
767 /* set the default username */
|
|
768 if (opt_user_arg != NULL) {
|
|
769 set_first_user(opt_user_arg);
|
|
770 g_free(opt_user_arg);
|
|
771 opt_user_arg = NULL;
|
|
772 }
|
|
773
|
|
774 if (gaim_prefs_get_bool("/gaim/gtk/debug/enabled"))
|
|
775 gaim_gtk_debug_window_show();
|
|
776
|
|
777 /* deal with --login */
|
|
778 if (opt_login) {
|
|
779 dologin_ret = dologin_named(opt_login_arg);
|
|
780 if (opt_login_arg != NULL) {
|
|
781 g_free(opt_login_arg);
|
|
782 opt_login_arg = NULL;
|
|
783 }
|
|
784 }
|
|
785
|
|
786 if (!opt_acct && !opt_nologin)
|
|
787 gaim_accounts_auto_login(GAIM_GTK_UI);
|
|
788
|
10315
|
789 gaim_blist_show();
|
|
790
|
10302
|
791 if (opt_acct) {
|
|
792 gaim_gtk_accounts_window_show();
|
10315
|
793 }
|
10302
|
794
|
|
795 #ifdef HAVE_STARTUP_NOTIFICATION
|
|
796 startup_notification_complete();
|
|
797 #endif
|
|
798 gtk_main();
|
|
799 gaim_sound_shutdown();
|
|
800 #ifdef _WIN32
|
|
801 wgaim_cleanup();
|
|
802 #endif
|
|
803
|
|
804
|
|
805 return 0;
|
|
806
|
|
807 }
|