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