Mercurial > pidgin
annotate src/main.c @ 4780:5d4243c013a2
[gaim-migrate @ 5100]
Mom! Sean's making me uneasy! Make him stop!
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Fri, 14 Mar 2003 23:46:32 +0000 |
parents | e4dda06a3143 |
children | 677d3cb193a1 |
rev | line source |
---|---|
4489 | 1 /* |
2 * gaim | |
3 * | |
4 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net> | |
5 * | |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or | |
9 * (at your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
19 * | |
20 */ | |
21 | |
22 #ifdef HAVE_CONFIG_H | |
23 #include <config.h> | |
24 #endif | |
25 #ifdef GAIM_PLUGINS | |
26 #ifndef _WIN32 | |
27 #include <dlfcn.h> | |
28 #endif | |
29 #endif /* GAIM_PLUGINS */ | |
30 #include <gtk/gtk.h> | |
31 #ifndef _WIN32 | |
32 #include <gdk/gdkx.h> | |
33 #include <unistd.h> | |
34 #include <sys/socket.h> | |
35 #include <netinet/in.h> | |
36 #include <arpa/inet.h> | |
37 #include <sys/un.h> | |
38 #include <sys/wait.h> | |
39 #endif /* !_WIN32 */ | |
40 #include <gdk/gdk.h> | |
41 #include <sys/types.h> | |
42 #include <sys/stat.h> | |
43 #include <errno.h> | |
44 #include <stdio.h> | |
45 #include <string.h> | |
46 #include <stdarg.h> | |
47 #include <stdlib.h> | |
48 #include <ctype.h> | |
49 #include "prpl.h" | |
4561 | 50 #include "sound.h" |
4489 | 51 #include "gaim.h" |
52 #include "gaim-socket.h" | |
4687 | 53 #include "gtklist.h" |
4489 | 54 #if HAVE_SIGNAL_H |
55 #include <signal.h> | |
56 #endif | |
57 #include "locale.h" | |
58 #include <getopt.h> | |
59 | |
60 #ifdef _WIN32 | |
61 #include "win32dep.h" | |
62 #endif | |
63 | |
64 static GtkWidget *name; | |
65 static GtkWidget *pass; | |
66 | |
67 GList *log_conversations = NULL; | |
68 GList *buddy_pounces = NULL; | |
69 GSList *away_messages = NULL; | |
70 GSList *message_queue = NULL; | |
71 GSList *unread_message_queue = NULL; | |
72 GSList *away_time_queue = NULL; | |
73 | |
74 GtkWidget *mainwindow = NULL; | |
75 | |
4561 | 76 |
4489 | 77 int opt_away = 0; |
4687 | 78 int docklet_count = 0; |
4489 | 79 char *opt_away_arg = NULL; |
80 char *opt_rcfile_arg = NULL; | |
81 int opt_debug = 0; | |
82 #ifdef _WIN32 | |
83 int opt_gdebug = 0; | |
84 #endif | |
85 | |
86 #if HAVE_SIGNAL_H | |
87 /* | |
88 * Lists of signals we wish to catch and those we wish to ignore. | |
89 * Each list terminated with -1 | |
90 */ | |
91 static int catch_sig_list[] = { | |
92 SIGSEGV, | |
93 SIGHUP, | |
94 SIGINT, | |
95 SIGTERM, | |
96 SIGQUIT, | |
97 SIGCHLD, | |
98 -1 | |
99 }; | |
100 | |
101 static int ignore_sig_list[] = { | |
102 SIGPIPE, | |
103 -1 | |
104 }; | |
105 #endif | |
106 | |
107 void do_quit() | |
108 { | |
109 /* captain's log, stardate... */ | |
110 system_log(log_quit, NULL, NULL, OPT_LOG_BUDDY_SIGNON | OPT_LOG_MY_SIGNON); | |
111 | |
112 /* the self destruct sequence has been initiated */ | |
113 plugin_event(event_quit); | |
114 | |
115 /* transmission ends */ | |
116 signoff_all(); | |
117 | |
118 /* record what we have before we blow it away... */ | |
119 save_prefs(); | |
120 | |
121 #ifdef GAIM_PLUGINS | |
122 /* jettison cargo */ | |
123 remove_all_plugins(); | |
124 #endif | |
125 | |
126 #ifdef USE_PERL | |
127 /* yup, perl too */ | |
128 perl_end(); | |
129 #endif | |
130 | |
131 #ifdef USE_SM | |
132 /* unplug */ | |
133 session_end(); | |
134 #endif | |
135 | |
136 /* and end it all... */ | |
137 gtk_main_quit(); | |
138 } | |
139 | |
4561 | 140 static guint snd_tmout = 0; |
4489 | 141 static gboolean sound_timeout(gpointer data) |
142 { | |
4561 | 143 gaim_sound_set_login_mute(FALSE); |
144 snd_tmout = 0; | |
4489 | 145 return FALSE; |
146 } | |
147 | |
148 /* we need to do this for Oscar because serv_login only starts the login | |
149 * process, it doesn't end there. gaim_setup will be called later from | |
150 * oscar.c, after the buddy list is made and serv_finish_login is called */ | |
151 void gaim_setup(struct gaim_connection *gc) | |
152 { | |
153 if ((sound_options & OPT_SOUND_LOGIN) && (sound_options & OPT_SOUND_SILENT_SIGNON)) { | |
4561 | 154 if(snd_tmout) { |
155 g_source_remove(snd_tmout); | |
156 } | |
157 gaim_sound_set_login_mute(TRUE); | |
4489 | 158 snd_tmout = g_timeout_add(10000, sound_timeout, NULL); |
159 } | |
160 } | |
161 | |
162 static gboolean domiddleclick(GtkWidget *w, GdkEventButton *event, gpointer null) | |
163 { | |
164 if (event->button != 2) | |
165 return FALSE; | |
166 | |
167 auto_login(); | |
168 return TRUE; | |
169 } | |
170 | |
171 static void dologin(GtkWidget *widget, GtkWidget *w) | |
172 { | |
4491 | 173 struct gaim_account *account; |
4489 | 174 const char *username = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(name)->entry)); |
175 const char *password = gtk_entry_get_text(GTK_ENTRY(pass)); | |
176 | |
177 if (!strlen(username)) { | |
178 do_error_dialog(_("Please enter your login."), NULL, GAIM_ERROR); | |
179 return; | |
180 } | |
181 | |
182 /* if there is more than one user of the same name, then fuck | |
183 * them, they just have to use the account editor to sign in | |
184 * the second one */ | |
185 | |
4491 | 186 account = gaim_account_find(username, -1); |
187 if (!account) | |
188 account = gaim_account_new(username, DEFAULT_PROTO, OPT_ACCT_REM_PASS); | |
189 g_snprintf(account->password, sizeof account->password, "%s", password); | |
4489 | 190 save_prefs(); |
4491 | 191 serv_login(account); |
4489 | 192 } |
193 | |
194 /* <name> is a comma-separated list of names, or NULL | |
195 if NULL and there is at least one user defined in .gaimrc, try to login. | |
196 if not NULL, parse <name> into separate strings, look up each one in | |
197 .gaimrc and, if it's there, try to login. | |
198 returns: 0 if successful | |
199 -1 if no user was found that had a saved password | |
200 */ | |
201 static int dologin_named(char *name) | |
202 { | |
4491 | 203 struct gaim_account *account; |
4489 | 204 char **names, **n; |
205 int retval = -1; | |
206 | |
207 if (name !=NULL) { /* list of names given */ | |
208 names = g_strsplit(name, ",", 32); | |
209 for (n = names; *n != NULL; n++) { | |
4491 | 210 account = gaim_account_find(*n, -1); |
211 if (account) { /* found a user */ | |
212 if (account->options & OPT_ACCT_REM_PASS) { | |
4489 | 213 retval = 0; |
4491 | 214 serv_login(account); |
4489 | 215 } |
216 } | |
217 } | |
218 g_strfreev(names); | |
219 } else { /* no name given, use default */ | |
4491 | 220 account = (struct gaim_account *)gaim_accounts->data; |
221 if (account->options & OPT_ACCT_REM_PASS) { | |
4489 | 222 retval = 0; |
4491 | 223 serv_login(account); |
4489 | 224 } |
225 } | |
226 | |
227 return retval; | |
228 } | |
229 | |
230 | |
231 static void doenter(GtkWidget *widget, GtkWidget *w) | |
232 { | |
233 if (widget == name) { | |
234 gtk_entry_set_text(GTK_ENTRY(pass), ""); | |
4635 | 235 gtk_editable_select_region(GTK_EDITABLE(GTK_COMBO(name)->entry), 0, 0); |
4489 | 236 gtk_widget_grab_focus(pass); |
237 } else if (widget == pass) { | |
238 dologin(widget, w); | |
239 } | |
240 } | |
241 | |
242 | |
243 static void combo_changed(GtkWidget *w, GtkWidget *combo) | |
244 { | |
245 const char *txt = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(combo)->entry)); | |
4491 | 246 struct gaim_account *account; |
4489 | 247 |
4491 | 248 account = gaim_account_find(txt, -1); |
4489 | 249 |
4491 | 250 if (account && account->options & OPT_ACCT_REM_PASS) { |
251 gtk_entry_set_text(GTK_ENTRY(pass), account->password); | |
4489 | 252 } else { |
253 gtk_entry_set_text(GTK_ENTRY(pass), ""); | |
254 } | |
255 } | |
256 | |
257 | |
258 static GList *combo_user_names() | |
259 { | |
4491 | 260 GSList *accts = gaim_accounts; |
4489 | 261 GList *tmp = NULL; |
4491 | 262 struct gaim_account *account; |
4489 | 263 |
4491 | 264 if (!accts) |
4489 | 265 return g_list_append(NULL, _("<New User>")); |
266 | |
4491 | 267 while (accts) { |
268 account = (struct gaim_account *)accts->data; | |
269 tmp = g_list_append(tmp, account->username); | |
270 accts = accts->next; | |
4489 | 271 } |
272 | |
273 return tmp; | |
274 } | |
275 | |
276 static void login_window_closed(GtkWidget *w, GdkEvent *ev, gpointer d) | |
277 { | |
278 if(docklet_count) { | |
279 #if _WIN32 | |
280 wgaim_systray_minimize(mainwindow); | |
281 #endif | |
282 gtk_widget_hide(mainwindow); | |
283 } else | |
284 do_quit(); | |
285 } | |
286 | |
287 void show_login() | |
288 { | |
289 GdkPixbuf *icon; | |
290 GtkWidget *image; | |
291 GtkWidget *vbox; | |
292 GtkWidget *button; | |
293 GtkWidget *hbox; | |
294 GtkWidget *label; | |
295 GtkWidget *vbox2; | |
296 GList *tmp; | |
297 | |
298 /* Do we already have a main window opened? If so, bring it back, baby... ribs... yeah */ | |
299 if (mainwindow) { | |
300 gtk_window_present(GTK_WINDOW(mainwindow)); | |
301 return; | |
302 } | |
303 | |
304 mainwindow = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
305 | |
306 gtk_window_set_role(GTK_WINDOW(mainwindow), "login"); | |
4635 | 307 gtk_window_set_resizable(GTK_WINDOW(mainwindow), FALSE); |
4703 | 308 gtk_window_set_title(GTK_WINDOW(mainwindow), _("Login")); |
4489 | 309 gtk_widget_realize(mainwindow); |
310 gdk_window_set_group(mainwindow->window, mainwindow->window); | |
311 gtk_container_set_border_width(GTK_CONTAINER(mainwindow), 5); | |
312 g_signal_connect(G_OBJECT(mainwindow), "delete_event", | |
313 G_CALLBACK(login_window_closed), mainwindow); | |
314 | |
315 | |
316 icon = gaim_pixbuf(NULL, "gaim.png"); | |
317 if (icon) { | |
318 gtk_window_set_icon(GTK_WINDOW(mainwindow), icon); | |
319 gdk_pixbuf_unref(icon); | |
320 } | |
321 | |
322 vbox = gtk_vbox_new(FALSE, 0); | |
323 gtk_container_add(GTK_CONTAINER(mainwindow), vbox); | |
324 | |
325 image = gaim_pixmap(NULL, "logo.png"); | |
326 gtk_box_pack_start(GTK_BOX(vbox), image, FALSE, FALSE, 0); | |
327 | |
328 vbox2 = gtk_vbox_new(FALSE, 0); | |
329 gtk_container_set_border_width(GTK_CONTAINER(vbox2), 5); | |
330 | |
331 label = gtk_label_new(_("Screen Name:")); | |
332 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
333 gtk_box_pack_start(GTK_BOX(vbox2), label, FALSE, FALSE, 0); | |
334 | |
335 name = gtk_combo_new(); | |
336 tmp = combo_user_names(); | |
337 gtk_combo_set_popdown_strings(GTK_COMBO(name), tmp); | |
338 g_list_free(tmp); | |
339 g_signal_connect(G_OBJECT(GTK_COMBO(name)->entry), "activate", | |
340 G_CALLBACK(doenter), mainwindow); | |
341 g_signal_connect(G_OBJECT(GTK_COMBO(name)->entry), "changed", | |
342 G_CALLBACK(combo_changed), name); | |
343 gtk_box_pack_start(GTK_BOX(vbox2), name, FALSE, TRUE, 0); | |
344 gtk_box_pack_start(GTK_BOX(vbox), vbox2, FALSE, TRUE, 0); | |
345 | |
346 vbox2 = gtk_vbox_new(FALSE, 0); | |
347 gtk_container_set_border_width(GTK_CONTAINER(vbox2), 5); | |
348 | |
349 label = gtk_label_new(_("Password:")); | |
350 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
351 gtk_box_pack_start(GTK_BOX(vbox2), label, FALSE, FALSE, 0); | |
352 | |
353 pass = gtk_entry_new(); | |
354 gtk_entry_set_visibility(GTK_ENTRY(pass), FALSE); | |
355 g_signal_connect(G_OBJECT(pass), "activate", | |
356 G_CALLBACK(doenter), mainwindow); | |
357 gtk_box_pack_start(GTK_BOX(vbox2), pass, FALSE, TRUE, 0); | |
358 gtk_box_pack_start(GTK_BOX(vbox), vbox2, FALSE, TRUE, 0); | |
359 | |
360 /* Now for the button box */ | |
361 hbox = gtk_hbox_new(TRUE, 0); | |
362 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 5); | |
363 | |
364 /* And now for the buttons */ | |
4589 | 365 button = gaim_pixbuf_button(_("Accounts"), "accounts.png", GAIM_BUTTON_VERTICAL); |
4489 | 366 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); |
367 g_signal_connect(G_OBJECT(button), "clicked", | |
368 G_CALLBACK(account_editor), mainwindow); | |
369 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
370 | |
371 #ifdef NO_MULTI | |
372 gtk_widget_set_sensitive(GTK_WIDGET(button), FALSE); | |
373 #endif | |
374 | |
4589 | 375 button = gaim_pixbuf_button(_("Settings"), "preferences.png", GAIM_BUTTON_VERTICAL); |
4489 | 376 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); |
377 g_signal_connect(G_OBJECT(button), "clicked", | |
378 G_CALLBACK(show_prefs), mainwindow); | |
379 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
380 | |
4589 | 381 button = gaim_pixbuf_button(_("Sign On"), "signon.png", GAIM_BUTTON_VERTICAL); |
4489 | 382 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); |
383 g_signal_connect(G_OBJECT(button), "clicked", | |
384 G_CALLBACK(dologin), mainwindow); | |
385 g_signal_connect(G_OBJECT(button), "button-press-event", G_CALLBACK(domiddleclick), NULL); | |
386 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
387 | |
388 #ifdef _WIN32 | |
389 /* Register newly created window with systray module */ | |
390 wgaim_created_loginwin(GTK_WIDGET(mainwindow)); | |
391 #endif | |
392 | |
393 /* Now grab the focus that we need */ | |
4491 | 394 if (gaim_accounts) { |
395 struct gaim_account *account = gaim_accounts->data; | |
396 if (account->options & OPT_ACCT_REM_PASS) { | |
4489 | 397 combo_changed(NULL, name); |
398 gtk_widget_grab_focus(button); | |
399 } else { | |
400 gtk_widget_grab_focus(pass); | |
401 } | |
402 } else { | |
403 gtk_widget_grab_focus(name); | |
404 } | |
405 | |
406 /* And raise the curtain! */ | |
407 gtk_widget_show_all(mainwindow); | |
408 | |
409 } | |
410 | |
411 #if HAVE_SIGNAL_H | |
412 void sighandler(int sig) | |
413 { | |
414 switch (sig) { | |
415 case SIGHUP: | |
416 debug_printf("caught signal %d\n", sig); | |
417 signoff_all(NULL, NULL); | |
418 break; | |
419 case SIGSEGV: | |
420 core_quit(); | |
421 #ifndef DEBUG | |
422 fprintf(stderr, "Gaim has segfaulted and attempted to dump a core file.\n" | |
423 "This is a bug in the software and has happened through\n" | |
424 "no fault of your own.\n\n" | |
425 "It is possible that this bug is already fixed in CVS.\n" | |
426 "You can get a tarball of CVS from the Gaim website, at\n" | |
427 WEBSITE "gaim-CVS.tar.gz.\n\n" | |
428 "If you are already using CVS, or can reproduce the crash\n" | |
429 "using the CVS version, please notify the gaim maintainers\n" | |
430 "by reporting a bug at\n" | |
431 WEBSITE "bug.php\n\n" | |
432 "Please make sure to specify what you were doing at the time,\n" | |
433 "and post the backtrace from the core file. If you do not know\n" | |
434 "how to get the backtrace, please get instructions at\n" | |
435 WEBSITE "gdb.php. If you need further\n" | |
436 "assistance, please IM either RobFlynn or SeanEgn and\n" | |
437 "they can help you.\n"); | |
438 #else | |
439 fprintf(stderr, "Oh no! Segmentation fault!\n"); | |
4703 | 440 /*g_on_error_query (g_get_prgname());*/ |
4489 | 441 exit(1); |
442 #endif | |
443 abort(); | |
444 break; | |
445 case SIGCHLD: | |
446 clean_pid(); | |
447 #if HAVE_SIGNAL_H | |
448 signal(SIGCHLD, sighandler); /* restore signal catching on this one! */ | |
449 #endif | |
450 break; | |
451 default: | |
452 debug_printf("caught signal %d\n", sig); | |
453 signoff_all(NULL, NULL); | |
454 #ifdef GAIM_PLUGINS | |
455 remove_all_plugins(); | |
456 #endif | |
457 if (gtk_main_level()) | |
458 gtk_main_quit(); | |
459 core_quit(); | |
460 exit(0); | |
461 } | |
462 } | |
463 #endif | |
464 | |
465 #ifndef _WIN32 | |
466 static gboolean socket_readable(GIOChannel *source, GIOCondition cond, gpointer ud) | |
467 { | |
468 guchar type; | |
469 guchar subtype; | |
470 guint32 len; | |
471 guchar *data; | |
472 guint32 x; | |
473 | |
474 debug_printf("Core says: "); | |
475 g_io_channel_read(source, &type, sizeof(type), &x); | |
476 if (x == 0) { | |
477 debug_printf("CORE IS GONE!\n"); | |
478 g_io_channel_close(source); | |
479 return FALSE; | |
480 } | |
481 debug_printf("%d ", type); | |
482 g_io_channel_read(source, &subtype, sizeof(subtype), &x); | |
483 if (x == 0) { | |
484 debug_printf("CORE IS GONE!\n"); | |
485 g_io_channel_close(source); | |
486 return FALSE; | |
487 } | |
488 debug_printf("%d ", subtype); | |
489 g_io_channel_read(source, (guchar *)&len, sizeof(len), &x); | |
490 if (x == 0) { | |
491 debug_printf("CORE IS GONE!\n"); | |
492 g_io_channel_close(source); | |
493 return FALSE; | |
494 } | |
495 debug_printf("(%d bytes)\n", len); | |
496 | |
497 data = g_malloc(len); | |
498 g_io_channel_read(source, data, len, &x); | |
499 if (x != len) { | |
500 debug_printf("CORE IS GONE! (read %d/%d bytes)\n", x, len); | |
501 g_free(data); | |
502 g_io_channel_close(source); | |
503 return FALSE; | |
504 } | |
505 | |
506 g_free(data); | |
507 return TRUE; | |
508 } | |
509 #endif /* _WIN32 */ | |
510 | |
511 static int ui_main() | |
512 { | |
513 #ifndef _WIN32 | |
514 GIOChannel *channel; | |
515 int UI_fd; | |
516 char name[256]; | |
517 GList *icons = NULL; | |
518 GdkPixbuf *icon = NULL; | |
519 char *icon_path; | |
520 #endif | |
521 if (current_smiley_theme == NULL) { | |
522 smiley_theme_probe(); | |
523 if (smiley_themes) { | |
524 struct smiley_theme *smile = smiley_themes->data; | |
525 load_smiley_theme(smile->path, TRUE); | |
526 } | |
527 } | |
528 | |
529 setup_stock(); | |
530 | |
531 #ifndef _WIN32 | |
532 /* use the nice PNG icon for all the windows */ | |
533 icon_path = g_build_filename(DATADIR, "pixmaps", "gaim.png", NULL); | |
534 icon = gdk_pixbuf_new_from_file(icon_path, NULL); | |
535 g_free(icon_path); | |
536 if (icon) { | |
537 icons = g_list_append(icons,icon); | |
538 gtk_window_set_default_icon_list(icons); | |
539 g_object_unref(G_OBJECT(icon)); | |
540 } else { | |
541 debug_printf("Failed to load icon from %s" G_DIR_SEPARATOR_S "pixmaps" G_DIR_SEPARATOR_S "gaim.png\n",DATADIR); | |
542 } | |
543 | |
544 g_snprintf(name, sizeof(name), "%s" G_DIR_SEPARATOR_S "gaim_%s.%d", g_get_tmp_dir(), g_get_user_name(), gaim_session); | |
545 UI_fd = gaim_connect_to_session(0); | |
546 if (UI_fd < 0) | |
547 return 1; | |
548 | |
549 channel = g_io_channel_unix_new(UI_fd); | |
550 g_io_add_watch(channel, G_IO_IN | G_IO_HUP | G_IO_ERR, socket_readable, NULL); | |
551 #endif | |
552 return 0; | |
553 } | |
554 | |
555 static void set_first_user(char *name) | |
556 { | |
4491 | 557 struct gaim_account *account; |
4489 | 558 |
4491 | 559 account = gaim_account_find(name, -1); |
4489 | 560 |
4491 | 561 if (!account) { /* new user */ |
562 account = g_new0(struct gaim_account, 1); | |
563 g_snprintf(account->username, sizeof(account->username), "%s", name); | |
564 account->protocol = DEFAULT_PROTO; | |
565 gaim_accounts = g_slist_prepend(gaim_accounts, account); | |
4489 | 566 } else { /* user already exists */ |
4491 | 567 gaim_accounts = g_slist_remove(gaim_accounts, account); |
568 gaim_accounts = g_slist_prepend(gaim_accounts, account); | |
4489 | 569 } |
570 save_prefs(); | |
571 } | |
572 | |
573 #ifdef _WIN32 | |
574 /* WIN32 print and log handlers */ | |
575 | |
576 static void gaim_dummy_print( const gchar* string ) { | |
577 return; | |
578 } | |
579 | |
580 static void gaim_dummy_log_handler (const gchar *domain, | |
581 GLogLevelFlags flags, | |
582 const gchar *msg, | |
583 gpointer user_data) { | |
584 return; | |
585 } | |
586 | |
587 static void gaim_log_handler (const gchar *domain, | |
588 GLogLevelFlags flags, | |
589 const gchar *msg, | |
590 gpointer user_data) { | |
591 debug_printf("%s - %s\n", domain, msg); | |
592 g_log_default_handler(domain, flags, msg, user_data); | |
593 } | |
594 #endif /* _WIN32 */ | |
595 | |
596 /* FUCKING GET ME A TOWEL! */ | |
597 #ifdef _WIN32 | |
598 int gaim_main(int argc, char *argv[]) | |
599 #else | |
600 int main(int argc, char *argv[]) | |
601 #endif | |
602 { | |
603 int opt_acct = 0, opt_help = 0, opt_version = 0, opt_login = 0, opt_nologin = 0, dologin_ret = -1; | |
604 char *opt_user_arg = NULL, *opt_login_arg = NULL; | |
605 char *opt_session_arg = NULL; | |
606 #if HAVE_SIGNAL_H | |
607 int sig_indx; /* for setting up signal catching */ | |
608 sigset_t sigset; | |
609 void (*prev_sig_disp)(); | |
610 #endif | |
611 int opt, opt_user = 0; | |
612 int i; | |
613 | |
614 struct option long_options[] = { | |
615 {"acct", no_argument, NULL, 'a'}, | |
616 /*{"away", optional_argument, NULL, 'w'}, */ | |
617 {"help", no_argument, NULL, 'h'}, | |
618 /*{"login", optional_argument, NULL, 'l'}, */ | |
619 {"loginwin", no_argument, NULL, 'n'}, | |
620 {"user", required_argument, NULL, 'u'}, | |
621 {"file", required_argument, NULL, 'f'}, | |
622 {"debug", no_argument, NULL, 'd'}, | |
623 {"version", no_argument, NULL, 'v'}, | |
624 {"session", required_argument, NULL, 's'}, | |
625 {0, 0, 0, 0} | |
626 }; | |
627 | |
628 #ifdef DEBUG | |
629 opt_debug = 1; | |
630 #endif | |
631 | |
632 #ifdef ENABLE_NLS | |
633 bindtextdomain(PACKAGE, LOCALEDIR); | |
634 bind_textdomain_codeset(PACKAGE, "UTF-8"); | |
635 textdomain(PACKAGE); | |
636 #endif | |
637 | |
638 #if HAVE_SIGNAL_H | |
639 /* Let's not violate any PLA's!!!! */ | |
640 /* jseymour: whatever the fsck that means */ | |
641 /* Robot101: for some reason things like gdm like to block * | |
642 * useful signals like SIGCHLD, so we unblock all the ones we * | |
643 * declare a handler for. thanks JSeymour and Vann. */ | |
644 if (sigemptyset(&sigset)) { | |
645 char errmsg[BUFSIZ]; | |
646 sprintf(errmsg, "Warning: couldn't initialise empty signal set"); | |
647 perror(errmsg); | |
648 } | |
649 for(sig_indx = 0; catch_sig_list[sig_indx] != -1; ++sig_indx) { | |
650 if((prev_sig_disp = signal(catch_sig_list[sig_indx], sighandler)) == SIG_ERR) { | |
651 char errmsg[BUFSIZ]; | |
652 sprintf(errmsg, "Warning: couldn't set signal %d for catching", | |
653 catch_sig_list[sig_indx]); | |
654 perror(errmsg); | |
655 } | |
656 if(sigaddset(&sigset, catch_sig_list[sig_indx])) { | |
657 char errmsg[BUFSIZ]; | |
658 sprintf(errmsg, "Warning: couldn't include signal %d for unblocking", | |
659 catch_sig_list[sig_indx]); | |
660 perror(errmsg); | |
661 } | |
662 } | |
663 for(sig_indx = 0; ignore_sig_list[sig_indx] != -1; ++sig_indx) { | |
664 if((prev_sig_disp = signal(ignore_sig_list[sig_indx], SIG_IGN)) == SIG_ERR) { | |
665 char errmsg[BUFSIZ]; | |
666 sprintf(errmsg, "Warning: couldn't set signal %d to ignore", | |
667 ignore_sig_list[sig_indx]); | |
668 perror(errmsg); | |
669 } | |
670 } | |
671 | |
672 if (sigprocmask(SIG_UNBLOCK, &sigset, NULL)) { | |
673 char errmsg[BUFSIZ]; | |
674 sprintf(errmsg, "Warning: couldn't unblock signals"); | |
675 perror(errmsg); | |
676 } | |
677 #endif | |
678 | |
679 for (i = 0; i < argc; i++) { | |
680 /* --login option */ | |
681 if (strstr(argv[i], "--l") == argv[i]) { | |
682 char *equals; | |
683 opt_login = 1; | |
684 if ((equals = strchr(argv[i], '=')) != NULL) { | |
685 /* --login=NAME */ | |
686 opt_login_arg = g_strdup(equals + 1); | |
687 if (strlen(opt_login_arg) == 0) { | |
688 g_free(opt_login_arg); | |
689 opt_login_arg = NULL; | |
690 } | |
691 } else if (i + 1 < argc && argv[i + 1][0] != '-') { | |
692 /* --login NAME */ | |
693 opt_login_arg = g_strdup(argv[i + 1]); | |
694 strcpy(argv[i + 1], " "); | |
695 } | |
696 strcpy(argv[i], " "); | |
697 } | |
698 /* -l option */ | |
699 else if (strstr(argv[i], "-l") == argv[i]) { | |
700 opt_login = 1; | |
701 if (strlen(argv[i]) > 2) { | |
702 /* -lNAME */ | |
703 opt_login_arg = g_strdup(argv[i] + 2); | |
704 } else if (i + 1 < argc && argv[i + 1][0] != '-') { | |
705 /* -l NAME */ | |
706 opt_login_arg = g_strdup(argv[i + 1]); | |
707 strcpy(argv[i + 1], " "); | |
708 } | |
709 strcpy(argv[i], " "); | |
710 } | |
711 /* --away option */ | |
712 else if (strstr(argv[i], "--aw") == argv[i]) { | |
713 char *equals; | |
714 opt_away = 1; | |
715 if ((equals = strchr(argv[i], '=')) != NULL) { | |
716 /* --away=MESG */ | |
717 opt_away_arg = g_strdup(equals + 1); | |
718 if (strlen(opt_away_arg) == 0) { | |
719 g_free(opt_away_arg); | |
720 opt_away_arg = NULL; | |
721 } | |
722 } else if (i + 1 < argc && argv[i + 1][0] != '-') { | |
723 /* --away MESG */ | |
724 opt_away_arg = g_strdup(argv[i + 1]); | |
725 strcpy(argv[i + 1], " "); | |
726 } | |
727 strcpy(argv[i], " "); | |
728 } | |
729 /* -w option */ | |
730 else if (strstr(argv[i], "-w") == argv[i]) { | |
731 opt_away = 1; | |
732 if (strlen(argv[i]) > 2) { | |
733 /* -wMESG */ | |
734 opt_away_arg = g_strdup(argv[i] + 2); | |
735 } else if (i + 1 < argc && argv[i + 1][0] != '-') { | |
736 /* -w MESG */ | |
737 opt_away_arg = g_strdup(argv[i + 1]); | |
738 strcpy(argv[i + 1], " "); | |
739 } | |
740 strcpy(argv[i], " "); | |
741 } | |
742 } | |
743 /* | |
744 if (opt_login) { | |
745 printf ("--login given with arg %s\n", | |
746 opt_login_arg ? opt_login_arg : "NULL"); | |
747 exit(0); | |
748 } | |
749 */ | |
750 | |
751 gtk_set_locale(); | |
752 gtk_init(&argc, &argv); | |
753 | |
754 /* scan command-line options */ | |
755 opterr = 1; | |
756 while ((opt = getopt_long(argc, argv, | |
757 #ifndef _WIN32 | |
758 "adhu:f:vns:", | |
759 #else | |
760 "adghu:f:vn", | |
761 #endif | |
762 long_options, NULL)) != -1) { | |
763 switch (opt) { | |
764 case 'u': /* set user */ | |
765 opt_user = 1; | |
766 opt_user_arg = g_strdup(optarg); | |
767 break; | |
768 case 'a': /* account editor */ | |
769 opt_acct = 1; | |
770 break; | |
771 case 'd': /* debug */ | |
772 opt_debug = 1; | |
773 break; | |
774 case 'f': | |
775 opt_rcfile_arg = g_strdup(optarg); | |
776 break; | |
777 case 's': /* use existing session ID */ | |
778 opt_session_arg = g_strdup(optarg); | |
779 break; | |
780 case 'v': /* version */ | |
781 opt_version = 1; | |
782 break; | |
783 case 'h': /* help */ | |
784 opt_help = 1; | |
785 break; | |
786 case 'n': /* don't autologin */ | |
787 opt_nologin = 1; | |
788 break; | |
789 #ifdef _WIN32 | |
790 case 'g': /* debug GTK and GLIB */ | |
791 opt_gdebug = 1; | |
792 break; | |
793 #endif | |
794 case '?': | |
795 default: | |
796 show_usage(1, argv[0]); | |
797 return 0; | |
798 break; | |
799 } | |
800 } | |
801 | |
802 #ifdef _WIN32 | |
803 /* We don't want a console window.. */ | |
804 /* | |
805 * Any calls to the glib logging functions, result in a call to AllocConsole(). | |
806 * ME and 98 will in such cases produce a console window (2000 not), despite | |
807 * being built as a windows app rather than a console app. So we should either | |
808 * ignore messages by setting dummy log handlers, or redirect messages. | |
809 * This requires setting handlers for all domains (any lib which uses g_logging). | |
810 */ | |
811 | |
812 g_log_set_handler (NULL, G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION, | |
813 (opt_gdebug ? gaim_log_handler : gaim_dummy_log_handler), | |
814 NULL); | |
815 g_log_set_handler ("Gdk", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION, | |
816 (opt_gdebug ? gaim_log_handler : gaim_dummy_log_handler), | |
817 NULL); | |
818 g_log_set_handler ("Gtk", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION, | |
819 (opt_gdebug ? gaim_log_handler : gaim_dummy_log_handler), | |
820 NULL); | |
821 g_log_set_handler ("GLib", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION, | |
822 (opt_gdebug ? gaim_log_handler : gaim_dummy_log_handler), | |
823 NULL); | |
824 g_log_set_handler ("GModule", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION, | |
825 (opt_gdebug ? gaim_log_handler : gaim_dummy_log_handler), | |
826 NULL); | |
827 g_log_set_handler ("GLib-GObject", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION, | |
828 (opt_gdebug ? gaim_log_handler : gaim_dummy_log_handler), | |
829 NULL); | |
830 g_log_set_handler ("GThread", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION, | |
831 (opt_gdebug ? gaim_log_handler : gaim_dummy_log_handler), | |
832 NULL); | |
833 | |
834 /* g_print also makes a call to AllocConsole(), therefore a handler needs to be | |
835 set here aswell */ | |
836 if(!opt_debug) | |
837 g_set_print_handler( gaim_dummy_print ); | |
838 | |
839 #endif | |
840 | |
841 /* show help message */ | |
842 if (opt_help) { | |
843 show_usage(0, argv[0]); | |
844 return 0; | |
845 } | |
846 /* show version message */ | |
847 if (opt_version) { | |
848 printf("Gaim %s\n",VERSION); | |
849 return 0; | |
850 } | |
851 | |
852 #if GAIM_PLUGINS || USE_PERL | |
853 gaim_probe_plugins(); | |
854 #endif | |
855 | |
856 #ifdef _WIN32 | |
857 /* Various win32 initializations */ | |
858 wgaim_init(); | |
859 #endif | |
860 | |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4687
diff
changeset
|
861 /* Set the UI operation structures. */ |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4687
diff
changeset
|
862 gaim_set_win_ui_ops(gaim_get_gtk_window_ui_ops()); |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4687
diff
changeset
|
863 gaim_set_xfer_ui_ops(gaim_get_gtk_xfer_ui_ops()); |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4687
diff
changeset
|
864 gaim_set_blist_ui_ops(gaim_get_gtk_blist_ui_ops()); |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4687
diff
changeset
|
865 |
4489 | 866 load_prefs(); |
867 core_main(); | |
868 ui_main(); | |
869 | |
870 #ifdef USE_SM | |
871 session_init(argv[0], opt_session_arg); | |
872 #endif | |
873 if (opt_session_arg != NULL) { | |
874 g_free(opt_session_arg); | |
875 opt_session_arg = NULL; | |
876 }; | |
877 | |
878 /* set the default username */ | |
879 if (opt_user_arg != NULL) { | |
880 set_first_user(opt_user_arg); | |
881 g_free(opt_user_arg); | |
882 opt_user_arg = NULL; | |
883 } | |
884 | |
885 if (misc_options & OPT_MISC_DEBUG) | |
886 show_debug(); | |
887 | |
888 static_proto_init(); | |
889 | |
890 /* deal with --login */ | |
891 if (opt_login) { | |
892 dologin_ret = dologin_named(opt_login_arg); | |
893 if (opt_login_arg != NULL) { | |
894 g_free(opt_login_arg); | |
895 opt_login_arg = NULL; | |
896 } | |
897 } | |
898 | |
899 if (!opt_acct && !opt_nologin && gaim_session == 0) | |
900 auto_login(); | |
901 | |
902 if (opt_acct) { | |
903 account_editor(NULL, NULL); | |
904 } else if ((dologin_ret == -1) && !connections) | |
905 show_login(); | |
906 | |
907 gtk_main(); | |
908 core_quit(); | |
4561 | 909 gaim_sound_quit(); |
4489 | 910 #ifdef _WIN32 |
911 wgaim_cleanup(); | |
912 #endif | |
913 return 0; | |
914 | |
915 } |