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