Mercurial > pidgin
annotate src/main.c @ 5696:0a20c8e1d2ca
[gaim-migrate @ 6117]
Account saving and (probably) modification works now, mostly.
committer: Tailor Script <tailor@pidgin.im>
| author | Christian Hammond <chipx86@chipx86.com> |
|---|---|
| date | Tue, 03 Jun 2003 08:51:07 +0000 |
| parents | b61520e71679 |
| children | 1d140b31d4b3 |
| 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" |
| 5684 | 51 #include "gtksound.h" |
| 4489 | 52 #include "gaim.h" |
| 53 #include "gaim-socket.h" | |
|
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5549
diff
changeset
|
54 #include "account.h" |
| 5440 | 55 #include "prefs.h" |
|
5436
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5435
diff
changeset
|
56 #include "notify.h" |
|
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5549
diff
changeset
|
57 #include "gtkaccount.h" |
|
5228
1a53330dfd34
[gaim-migrate @ 5598]
Christian Hammond <chipx86@chipx86.com>
parents:
5211
diff
changeset
|
58 #include "gtkblist.h" |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
59 #include "gtkdebug.h" |
|
5436
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5435
diff
changeset
|
60 #include "gtknotify.h" |
|
5492
a75a952d78db
[gaim-migrate @ 5888]
Christian Hammond <chipx86@chipx86.com>
parents:
5480
diff
changeset
|
61 #include "gtkrequest.h" |
| 5684 | 62 #include "gtksound.h" |
| 4489 | 63 #if HAVE_SIGNAL_H |
| 64 #include <signal.h> | |
| 65 #endif | |
| 66 #include "locale.h" | |
| 67 #include <getopt.h> | |
| 68 | |
| 69 #ifdef _WIN32 | |
| 70 #include "win32dep.h" | |
| 71 #endif | |
| 72 | |
| 73 static GtkWidget *name; | |
| 74 static GtkWidget *pass; | |
| 75 | |
| 76 GList *log_conversations = NULL; | |
| 77 GSList *away_messages = NULL; | |
| 78 GSList *message_queue = NULL; | |
| 79 GSList *unread_message_queue = NULL; | |
| 80 GSList *away_time_queue = NULL; | |
| 81 | |
| 82 GtkWidget *mainwindow = NULL; | |
| 83 | |
| 4561 | 84 |
| 4489 | 85 int opt_away = 0; |
| 4687 | 86 int docklet_count = 0; |
| 4489 | 87 char *opt_away_arg = NULL; |
| 88 char *opt_rcfile_arg = NULL; | |
| 89 int opt_debug = 0; | |
| 90 #ifdef _WIN32 | |
| 91 int opt_gdebug = 0; | |
| 92 #endif | |
| 93 | |
| 94 #if HAVE_SIGNAL_H | |
| 95 /* | |
| 96 * Lists of signals we wish to catch and those we wish to ignore. | |
| 97 * Each list terminated with -1 | |
| 98 */ | |
| 99 static int catch_sig_list[] = { | |
| 100 SIGSEGV, | |
| 101 SIGHUP, | |
| 102 SIGINT, | |
| 103 SIGTERM, | |
| 104 SIGQUIT, | |
| 105 SIGCHLD, | |
| 106 -1 | |
| 107 }; | |
| 108 | |
| 109 static int ignore_sig_list[] = { | |
| 110 SIGPIPE, | |
| 111 -1 | |
| 112 }; | |
| 113 #endif | |
| 114 | |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5032
diff
changeset
|
115 STATIC_PROTO_INIT |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5032
diff
changeset
|
116 |
| 4489 | 117 void do_quit() |
| 118 { | |
| 119 /* captain's log, stardate... */ | |
| 120 system_log(log_quit, NULL, NULL, OPT_LOG_BUDDY_SIGNON | OPT_LOG_MY_SIGNON); | |
| 121 | |
| 122 /* the self destruct sequence has been initiated */ | |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5032
diff
changeset
|
123 gaim_event_broadcast(event_quit); |
| 4489 | 124 |
| 125 /* transmission ends */ | |
|
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5549
diff
changeset
|
126 gaim_connections_disconnect_all(); |
| 4489 | 127 |
| 128 /* record what we have before we blow it away... */ | |
| 5534 | 129 gaim_prefs_sync(); |
|
5573
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
130 gaim_accounts_sync(); |
| 4489 | 131 |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
132 gaim_debug(GAIM_DEBUG_INFO, "main", "Unloading all plugins\n"); |
|
5242
fd81a00480ac
[gaim-migrate @ 5613]
Christian Hammond <chipx86@chipx86.com>
parents:
5228
diff
changeset
|
133 gaim_plugins_destroy_all(); |
| 4489 | 134 |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5032
diff
changeset
|
135 /* XXX */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5032
diff
changeset
|
136 #if 0 |
| 4489 | 137 #ifdef USE_PERL |
| 138 /* yup, perl too */ | |
| 139 perl_end(); | |
| 140 #endif | |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5032
diff
changeset
|
141 #endif |
| 4489 | 142 |
| 143 #ifdef USE_SM | |
| 144 /* unplug */ | |
| 145 session_end(); | |
| 146 #endif | |
| 147 | |
| 148 /* and end it all... */ | |
| 149 gtk_main_quit(); | |
| 150 } | |
| 151 | |
| 4561 | 152 static guint snd_tmout = 0; |
| 4489 | 153 static gboolean sound_timeout(gpointer data) |
| 154 { | |
| 5684 | 155 gaim_gtk_sound_set_login_mute(FALSE); |
| 4561 | 156 snd_tmout = 0; |
| 4489 | 157 return FALSE; |
| 158 } | |
| 159 | |
| 160 /* we need to do this for Oscar because serv_login only starts the login | |
| 161 * process, it doesn't end there. gaim_setup will be called later from | |
| 162 * oscar.c, after the buddy list is made and serv_finish_login is called */ | |
|
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5549
diff
changeset
|
163 void gaim_setup(GaimConnection *gc) |
| 4489 | 164 { |
| 5549 | 165 if (gaim_prefs_get_bool("/core/sound/login") && gaim_prefs_get_bool("/core/sound/silent_signon")) { |
| 4561 | 166 if(snd_tmout) { |
| 167 g_source_remove(snd_tmout); | |
| 168 } | |
| 5684 | 169 gaim_gtk_sound_set_login_mute(TRUE); |
| 4489 | 170 snd_tmout = g_timeout_add(10000, sound_timeout, NULL); |
| 171 } | |
| 172 } | |
| 173 | |
| 174 static gboolean domiddleclick(GtkWidget *w, GdkEventButton *event, gpointer null) | |
| 175 { | |
| 176 if (event->button != 2) | |
| 177 return FALSE; | |
| 178 | |
|
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5549
diff
changeset
|
179 /* TODO auto_login(); */ |
|
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5549
diff
changeset
|
180 |
| 4489 | 181 return TRUE; |
| 182 } | |
| 183 | |
| 184 static void dologin(GtkWidget *widget, GtkWidget *w) | |
| 185 { | |
|
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5549
diff
changeset
|
186 GaimAccount *account; |
| 4489 | 187 const char *username = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(name)->entry)); |
| 188 const char *password = gtk_entry_get_text(GTK_ENTRY(pass)); | |
| 189 | |
| 190 if (!strlen(username)) { | |
|
5436
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5435
diff
changeset
|
191 gaim_notify_error(NULL, NULL, _("Please enter your login."), NULL); |
| 4489 | 192 return; |
| 193 } | |
| 194 | |
| 195 /* if there is more than one user of the same name, then fuck | |
| 196 * them, they just have to use the account editor to sign in | |
| 197 * the second one */ | |
| 198 | |
| 4491 | 199 account = gaim_account_find(username, -1); |
|
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5549
diff
changeset
|
200 if (!account) { |
|
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5549
diff
changeset
|
201 account = gaim_account_new(username, GAIM_PROTO_DEFAULT); |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5032
diff
changeset
|
202 |
|
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5549
diff
changeset
|
203 gaim_account_set_remember_password(account, TRUE); |
|
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5549
diff
changeset
|
204 } |
|
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5549
diff
changeset
|
205 |
|
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5549
diff
changeset
|
206 gaim_account_set_password(account, password); |
|
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5549
diff
changeset
|
207 |
|
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5549
diff
changeset
|
208 gaim_account_connect(account); |
| 4489 | 209 } |
| 210 | |
| 211 /* <name> is a comma-separated list of names, or NULL | |
| 212 if NULL and there is at least one user defined in .gaimrc, try to login. | |
| 213 if not NULL, parse <name> into separate strings, look up each one in | |
| 214 .gaimrc and, if it's there, try to login. | |
| 215 returns: 0 if successful | |
| 216 -1 if no user was found that had a saved password | |
| 217 */ | |
| 218 static int dologin_named(char *name) | |
| 219 { | |
|
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5549
diff
changeset
|
220 GaimAccount *account; |
| 4489 | 221 char **names, **n; |
| 222 int retval = -1; | |
| 223 | |
| 224 if (name !=NULL) { /* list of names given */ | |
| 225 names = g_strsplit(name, ",", 32); | |
| 226 for (n = names; *n != NULL; n++) { | |
| 4491 | 227 account = gaim_account_find(*n, -1); |
| 228 if (account) { /* found a user */ | |
|
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5549
diff
changeset
|
229 if (gaim_account_get_remember_password(account)) { |
| 4489 | 230 retval = 0; |
| 4491 | 231 serv_login(account); |
| 4489 | 232 } |
| 233 } | |
| 234 } | |
| 235 g_strfreev(names); | |
| 236 } else { /* no name given, use default */ | |
|
5580
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5573
diff
changeset
|
237 account = (GaimAccount *)gaim_accounts_get_all()->data; |
|
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5549
diff
changeset
|
238 |
|
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5549
diff
changeset
|
239 if (gaim_account_get_remember_password(account)) { |
| 4489 | 240 retval = 0; |
| 4491 | 241 serv_login(account); |
| 4489 | 242 } |
| 243 } | |
| 244 | |
| 245 return retval; | |
| 246 } | |
| 247 | |
| 248 | |
| 249 static void doenter(GtkWidget *widget, GtkWidget *w) | |
| 250 { | |
| 251 if (widget == name) { | |
| 252 gtk_entry_set_text(GTK_ENTRY(pass), ""); | |
| 4635 | 253 gtk_editable_select_region(GTK_EDITABLE(GTK_COMBO(name)->entry), 0, 0); |
| 4489 | 254 gtk_widget_grab_focus(pass); |
| 255 } else if (widget == pass) { | |
| 256 dologin(widget, w); | |
| 257 } | |
| 258 } | |
| 259 | |
| 260 | |
| 261 static void combo_changed(GtkWidget *w, GtkWidget *combo) | |
| 262 { | |
| 263 const char *txt = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(combo)->entry)); | |
|
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5549
diff
changeset
|
264 GaimAccount *account; |
| 4489 | 265 |
| 4491 | 266 account = gaim_account_find(txt, -1); |
| 4489 | 267 |
|
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5549
diff
changeset
|
268 if (account && gaim_account_get_remember_password(account)) { |
| 4491 | 269 gtk_entry_set_text(GTK_ENTRY(pass), account->password); |
| 4489 | 270 } else { |
| 271 gtk_entry_set_text(GTK_ENTRY(pass), ""); | |
| 272 } | |
| 273 } | |
| 274 | |
| 275 | |
| 276 static GList *combo_user_names() | |
| 277 { | |
|
5580
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5573
diff
changeset
|
278 GList *accts = gaim_accounts_get_all(); |
| 4489 | 279 GList *tmp = NULL; |
|
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5549
diff
changeset
|
280 GaimAccount *account; |
| 4489 | 281 |
| 4491 | 282 if (!accts) |
| 4489 | 283 return g_list_append(NULL, _("<New User>")); |
| 284 | |
| 4491 | 285 while (accts) { |
|
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5549
diff
changeset
|
286 account = (GaimAccount *)accts->data; |
| 4491 | 287 tmp = g_list_append(tmp, account->username); |
| 288 accts = accts->next; | |
| 4489 | 289 } |
| 290 | |
| 291 return tmp; | |
| 292 } | |
| 293 | |
| 294 static void login_window_closed(GtkWidget *w, GdkEvent *ev, gpointer d) | |
| 295 { | |
| 296 if(docklet_count) { | |
|
4880
9b51c090236a
[gaim-migrate @ 5210]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4800
diff
changeset
|
297 #ifdef _WIN32 |
| 4489 | 298 wgaim_systray_minimize(mainwindow); |
| 299 #endif | |
| 300 gtk_widget_hide(mainwindow); | |
| 301 } else | |
| 302 do_quit(); | |
| 303 } | |
| 304 | |
| 305 void show_login() | |
| 306 { | |
| 307 GtkWidget *image; | |
| 308 GtkWidget *vbox; | |
| 309 GtkWidget *button; | |
| 310 GtkWidget *hbox; | |
| 311 GtkWidget *label; | |
| 312 GtkWidget *vbox2; | |
| 313 GList *tmp; | |
| 314 | |
| 315 /* Do we already have a main window opened? If so, bring it back, baby... ribs... yeah */ | |
| 316 if (mainwindow) { | |
| 317 gtk_window_present(GTK_WINDOW(mainwindow)); | |
| 318 return; | |
| 319 } | |
| 320 | |
| 321 mainwindow = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
| 322 | |
| 323 gtk_window_set_role(GTK_WINDOW(mainwindow), "login"); | |
| 4635 | 324 gtk_window_set_resizable(GTK_WINDOW(mainwindow), FALSE); |
| 4703 | 325 gtk_window_set_title(GTK_WINDOW(mainwindow), _("Login")); |
| 4489 | 326 gtk_widget_realize(mainwindow); |
| 327 gdk_window_set_group(mainwindow->window, mainwindow->window); | |
| 328 gtk_container_set_border_width(GTK_CONTAINER(mainwindow), 5); | |
| 329 g_signal_connect(G_OBJECT(mainwindow), "delete_event", | |
| 330 G_CALLBACK(login_window_closed), mainwindow); | |
| 331 | |
| 332 vbox = gtk_vbox_new(FALSE, 0); | |
| 333 gtk_container_add(GTK_CONTAINER(mainwindow), vbox); | |
| 334 | |
| 5024 | 335 image = gtk_image_new_from_stock(GAIM_STOCK_LOGO, gtk_icon_size_from_name(GAIM_ICON_SIZE_LOGO)); |
| 4489 | 336 gtk_box_pack_start(GTK_BOX(vbox), image, FALSE, FALSE, 0); |
| 337 | |
| 338 vbox2 = gtk_vbox_new(FALSE, 0); | |
| 339 gtk_container_set_border_width(GTK_CONTAINER(vbox2), 5); | |
| 340 | |
| 341 label = gtk_label_new(_("Screen Name:")); | |
| 342 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
| 343 gtk_box_pack_start(GTK_BOX(vbox2), label, FALSE, FALSE, 0); | |
| 344 | |
| 345 name = gtk_combo_new(); | |
| 346 tmp = combo_user_names(); | |
| 347 gtk_combo_set_popdown_strings(GTK_COMBO(name), tmp); | |
| 348 g_list_free(tmp); | |
| 349 g_signal_connect(G_OBJECT(GTK_COMBO(name)->entry), "activate", | |
| 350 G_CALLBACK(doenter), mainwindow); | |
| 351 g_signal_connect(G_OBJECT(GTK_COMBO(name)->entry), "changed", | |
| 352 G_CALLBACK(combo_changed), name); | |
| 353 gtk_box_pack_start(GTK_BOX(vbox2), name, FALSE, TRUE, 0); | |
| 354 gtk_box_pack_start(GTK_BOX(vbox), vbox2, FALSE, TRUE, 0); | |
| 355 | |
| 356 vbox2 = gtk_vbox_new(FALSE, 0); | |
| 357 gtk_container_set_border_width(GTK_CONTAINER(vbox2), 5); | |
| 358 | |
| 359 label = gtk_label_new(_("Password:")); | |
| 360 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
| 361 gtk_box_pack_start(GTK_BOX(vbox2), label, FALSE, FALSE, 0); | |
| 362 | |
| 363 pass = gtk_entry_new(); | |
| 364 gtk_entry_set_visibility(GTK_ENTRY(pass), FALSE); | |
| 365 g_signal_connect(G_OBJECT(pass), "activate", | |
| 366 G_CALLBACK(doenter), mainwindow); | |
| 367 gtk_box_pack_start(GTK_BOX(vbox2), pass, FALSE, TRUE, 0); | |
| 368 gtk_box_pack_start(GTK_BOX(vbox), vbox2, FALSE, TRUE, 0); | |
| 369 | |
| 370 /* Now for the button box */ | |
| 371 hbox = gtk_hbox_new(TRUE, 0); | |
| 372 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 5); | |
| 373 | |
| 374 /* And now for the buttons */ | |
| 5024 | 375 button = gaim_pixbuf_button_from_stock(_("Accounts"), GAIM_STOCK_ACCOUNTS, GAIM_BUTTON_VERTICAL); |
| 4489 | 376 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); |
| 377 g_signal_connect(G_OBJECT(button), "clicked", | |
|
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5549
diff
changeset
|
378 G_CALLBACK(gaim_gtk_account_dialog_show), mainwindow); |
| 4489 | 379 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); |
| 380 | |
| 381 #ifdef NO_MULTI | |
| 382 gtk_widget_set_sensitive(GTK_WIDGET(button), FALSE); | |
| 383 #endif | |
| 384 | |
| 5024 | 385 button = gaim_pixbuf_button_from_stock(_("Preferences"), GTK_STOCK_PREFERENCES, GAIM_BUTTON_VERTICAL); |
| 4489 | 386 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); |
| 387 g_signal_connect(G_OBJECT(button), "clicked", | |
|
5530
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5492
diff
changeset
|
388 G_CALLBACK(gaim_gtk_prefs_show), mainwindow); |
| 4489 | 389 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); |
| 390 | |
| 5024 | 391 button = gaim_pixbuf_button_from_stock(_("Sign On"), GAIM_STOCK_SIGN_ON, GAIM_BUTTON_VERTICAL); |
| 4489 | 392 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); |
| 393 g_signal_connect(G_OBJECT(button), "clicked", | |
| 394 G_CALLBACK(dologin), mainwindow); | |
| 395 g_signal_connect(G_OBJECT(button), "button-press-event", G_CALLBACK(domiddleclick), NULL); | |
| 396 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
| 397 | |
| 398 /* Now grab the focus that we need */ | |
|
5580
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5573
diff
changeset
|
399 if (gaim_accounts_get_all()) { |
|
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5573
diff
changeset
|
400 GaimAccount *account = gaim_accounts_get_all()->data; |
|
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5549
diff
changeset
|
401 |
|
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5549
diff
changeset
|
402 if (gaim_account_get_remember_password(account)) { |
| 4489 | 403 combo_changed(NULL, name); |
| 404 gtk_widget_grab_focus(button); | |
| 405 } else { | |
| 406 gtk_widget_grab_focus(pass); | |
| 407 } | |
| 408 } else { | |
| 409 gtk_widget_grab_focus(name); | |
| 410 } | |
| 411 | |
| 412 /* And raise the curtain! */ | |
| 413 gtk_widget_show_all(mainwindow); | |
| 414 | |
| 415 } | |
| 416 | |
| 417 #if HAVE_SIGNAL_H | |
| 418 void sighandler(int sig) | |
| 419 { | |
| 420 switch (sig) { | |
| 421 case SIGHUP: | |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
422 gaim_debug(GAIM_DEBUG_WARNING, "sighandler", |
|
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
423 "Caught signal %d\n", sig); |
|
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5549
diff
changeset
|
424 gaim_connections_disconnect_all(); |
| 4489 | 425 break; |
| 426 case SIGSEGV: | |
| 427 core_quit(); | |
| 428 #ifndef DEBUG | |
| 429 fprintf(stderr, "Gaim has segfaulted and attempted to dump a core file.\n" | |
| 430 "This is a bug in the software and has happened through\n" | |
| 431 "no fault of your own.\n\n" | |
| 432 "It is possible that this bug is already fixed in CVS.\n" | |
| 433 "You can get a tarball of CVS from the Gaim website, at\n" | |
| 434 WEBSITE "gaim-CVS.tar.gz.\n\n" | |
| 435 "If you are already using CVS, or can reproduce the crash\n" | |
| 436 "using the CVS version, please notify the gaim maintainers\n" | |
| 437 "by reporting a bug at\n" | |
| 438 WEBSITE "bug.php\n\n" | |
| 439 "Please make sure to specify what you were doing at the time,\n" | |
| 440 "and post the backtrace from the core file. If you do not know\n" | |
| 441 "how to get the backtrace, please get instructions at\n" | |
| 442 WEBSITE "gdb.php. If you need further\n" | |
| 443 "assistance, please IM either RobFlynn or SeanEgn and\n" | |
| 444 "they can help you.\n"); | |
| 445 #else | |
| 446 fprintf(stderr, "Oh no! Segmentation fault!\n"); | |
| 4703 | 447 /*g_on_error_query (g_get_prgname());*/ |
| 4489 | 448 exit(1); |
| 449 #endif | |
| 450 abort(); | |
| 451 break; | |
| 452 case SIGCHLD: | |
| 453 clean_pid(); | |
| 454 #if HAVE_SIGNAL_H | |
| 455 signal(SIGCHLD, sighandler); /* restore signal catching on this one! */ | |
| 456 #endif | |
| 457 break; | |
| 458 default: | |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
459 gaim_debug(GAIM_DEBUG_WARNING, "sighandler", |
|
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
460 "Caught signal %d\n", sig); |
|
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5549
diff
changeset
|
461 gaim_connections_disconnect_all(); |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5032
diff
changeset
|
462 |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5032
diff
changeset
|
463 gaim_plugins_unload_all(); |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5032
diff
changeset
|
464 |
| 4489 | 465 if (gtk_main_level()) |
| 466 gtk_main_quit(); | |
| 467 core_quit(); | |
| 468 exit(0); | |
| 469 } | |
| 470 } | |
| 471 #endif | |
| 472 | |
| 473 #ifndef _WIN32 | |
| 474 static gboolean socket_readable(GIOChannel *source, GIOCondition cond, gpointer ud) | |
| 475 { | |
| 476 guchar type; | |
| 477 guchar subtype; | |
| 478 guint32 len; | |
| 479 guchar *data; | |
| 480 guint32 x; | |
| 4793 | 481 GError *error; |
| 4489 | 482 |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
483 gaim_debug(GAIM_DEBUG_INFO, "core socket", "Core says: "); |
| 4793 | 484 g_io_channel_read_chars(source, &type, sizeof(type), &x, &error); |
| 485 if(error) | |
| 4800 | 486 g_error_free(error); |
| 4489 | 487 if (x == 0) { |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
488 gaim_debug(GAIM_DEBUG_ERROR, NULL, "CORE IS GONE!\n"); |
| 4793 | 489 g_io_channel_shutdown(source, TRUE, &error); |
| 490 if(error) | |
| 491 g_free(error); | |
| 4489 | 492 return FALSE; |
| 493 } | |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
494 gaim_debug(GAIM_DEBUG_INFO, NULL, "%d ", type); |
| 4793 | 495 g_io_channel_read_chars(source, &subtype, sizeof(subtype), &x, &error); |
| 496 if(error) | |
| 4800 | 497 g_error_free(error); |
| 4489 | 498 if (x == 0) { |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
499 gaim_debug(GAIM_DEBUG_ERROR, NULL, "CORE IS GONE!\n"); |
| 4793 | 500 g_io_channel_shutdown(source, TRUE, &error); |
| 501 if(error) | |
| 4800 | 502 g_error_free(error); |
| 4489 | 503 return FALSE; |
| 504 } | |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
505 |
|
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
506 gaim_debug(GAIM_DEBUG_INFO, NULL, "%d ", subtype); |
| 4793 | 507 g_io_channel_read_chars(source, (guchar *)&len, sizeof(len), &x, &error); |
| 508 if(error) | |
| 4800 | 509 g_error_free(error); |
| 4489 | 510 if (x == 0) { |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
511 gaim_debug(GAIM_DEBUG_ERROR, NULL, "CORE IS GONE!\n"); |
| 4793 | 512 g_io_channel_shutdown(source, TRUE, &error); |
| 513 if(error) | |
| 4800 | 514 g_error_free(error); |
| 4489 | 515 return FALSE; |
| 516 } | |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
517 |
|
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
518 gaim_debug(GAIM_DEBUG_INFO, NULL, "(%d bytes)\n", len); |
| 4489 | 519 |
| 520 data = g_malloc(len); | |
| 4793 | 521 g_io_channel_read_chars(source, data, len, &x, &error); |
| 522 if(error) | |
| 4800 | 523 g_error_free(error); |
| 4489 | 524 if (x != len) { |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
525 gaim_debug(GAIM_DEBUG_ERROR, "core socket", |
|
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
526 "CORE IS GONE! (read %d/%d bytes)\n", x, len); |
| 4489 | 527 g_free(data); |
| 4793 | 528 g_io_channel_shutdown(source, TRUE, &error); |
| 529 if(error) | |
| 4800 | 530 g_error_free(error); |
| 4489 | 531 return FALSE; |
| 532 } | |
| 533 | |
| 534 g_free(data); | |
| 535 return TRUE; | |
| 536 } | |
| 537 #endif /* _WIN32 */ | |
| 538 | |
| 539 static int ui_main() | |
| 540 { | |
| 541 #ifndef _WIN32 | |
| 542 GIOChannel *channel; | |
| 543 int UI_fd; | |
| 544 char name[256]; | |
| 545 GList *icons = NULL; | |
| 546 GdkPixbuf *icon = NULL; | |
| 547 char *icon_path; | |
| 548 #endif | |
| 4978 | 549 |
| 4489 | 550 if (current_smiley_theme == NULL) { |
| 551 smiley_theme_probe(); | |
| 552 if (smiley_themes) { | |
| 553 struct smiley_theme *smile = smiley_themes->data; | |
| 554 load_smiley_theme(smile->path, TRUE); | |
| 555 } | |
| 556 } | |
| 557 | |
| 5422 | 558 gaim_gtk_blist_setup_sort_methods(); |
| 4489 | 559 setup_stock(); |
| 560 | |
| 561 #ifndef _WIN32 | |
| 562 /* use the nice PNG icon for all the windows */ | |
| 5024 | 563 icon_path = g_build_filename(DATADIR, "pixmaps", "gaim", "icons", "online.png", NULL); |
| 4489 | 564 icon = gdk_pixbuf_new_from_file(icon_path, NULL); |
| 565 g_free(icon_path); | |
| 566 if (icon) { | |
| 567 icons = g_list_append(icons,icon); | |
| 568 gtk_window_set_default_icon_list(icons); | |
| 569 g_object_unref(G_OBJECT(icon)); | |
| 4978 | 570 g_list_free(icons); |
| 4489 | 571 } else { |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
572 gaim_debug(GAIM_DEBUG_ERROR, "ui_main", |
|
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
573 "Failed to load the default window icon!\n"); |
| 4489 | 574 } |
| 575 | |
| 576 g_snprintf(name, sizeof(name), "%s" G_DIR_SEPARATOR_S "gaim_%s.%d", g_get_tmp_dir(), g_get_user_name(), gaim_session); | |
| 577 UI_fd = gaim_connect_to_session(0); | |
| 578 if (UI_fd < 0) | |
| 579 return 1; | |
| 580 | |
| 581 channel = g_io_channel_unix_new(UI_fd); | |
| 582 g_io_add_watch(channel, G_IO_IN | G_IO_HUP | G_IO_ERR, socket_readable, NULL); | |
| 583 #endif | |
| 4978 | 584 |
| 4489 | 585 return 0; |
| 586 } | |
| 587 | |
| 588 static void set_first_user(char *name) | |
| 589 { | |
|
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5549
diff
changeset
|
590 GaimAccount *account; |
| 4489 | 591 |
| 4491 | 592 account = gaim_account_find(name, -1); |
| 4489 | 593 |
|
5580
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5573
diff
changeset
|
594 if (account == NULL) /* new user */ |
|
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5573
diff
changeset
|
595 account = gaim_account_new(name, GAIM_PROTO_DEFAULT); |
|
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5573
diff
changeset
|
596 |
|
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5573
diff
changeset
|
597 /* Place it as the first user. */ |
|
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5573
diff
changeset
|
598 gaim_accounts_reorder(account, 0); |
| 4489 | 599 } |
| 600 | |
| 601 #ifdef _WIN32 | |
| 602 /* WIN32 print and log handlers */ | |
| 603 | |
| 604 static void gaim_dummy_print( const gchar* string ) { | |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
605 return; |
| 4489 | 606 } |
| 607 | |
| 608 static void gaim_dummy_log_handler (const gchar *domain, | |
| 609 GLogLevelFlags flags, | |
| 610 const gchar *msg, | |
| 611 gpointer user_data) { | |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
612 return; |
| 4489 | 613 } |
| 614 | |
| 615 static void gaim_log_handler (const gchar *domain, | |
| 616 GLogLevelFlags flags, | |
| 617 const gchar *msg, | |
| 618 gpointer user_data) { | |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
619 gaim_debug(GAIM_DEBUG_MISC, "log", "%s - %s\n", domain, msg); |
| 4489 | 620 g_log_default_handler(domain, flags, msg, user_data); |
| 621 } | |
| 622 #endif /* _WIN32 */ | |
| 623 | |
| 624 /* FUCKING GET ME A TOWEL! */ | |
| 625 #ifdef _WIN32 | |
| 626 int gaim_main(int argc, char *argv[]) | |
| 627 #else | |
| 628 int main(int argc, char *argv[]) | |
| 629 #endif | |
| 630 { | |
| 631 int opt_acct = 0, opt_help = 0, opt_version = 0, opt_login = 0, opt_nologin = 0, dologin_ret = -1; | |
| 632 char *opt_user_arg = NULL, *opt_login_arg = NULL; | |
| 633 char *opt_session_arg = NULL; | |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5032
diff
changeset
|
634 char *plugin_search_paths[3]; |
| 4489 | 635 #if HAVE_SIGNAL_H |
| 636 int sig_indx; /* for setting up signal catching */ | |
| 637 sigset_t sigset; | |
| 638 void (*prev_sig_disp)(); | |
| 639 #endif | |
| 640 int opt, opt_user = 0; | |
| 641 int i; | |
| 642 | |
| 643 struct option long_options[] = { | |
| 644 {"acct", no_argument, NULL, 'a'}, | |
| 645 /*{"away", optional_argument, NULL, 'w'}, */ | |
| 646 {"help", no_argument, NULL, 'h'}, | |
| 647 /*{"login", optional_argument, NULL, 'l'}, */ | |
| 648 {"loginwin", no_argument, NULL, 'n'}, | |
| 649 {"user", required_argument, NULL, 'u'}, | |
| 650 {"file", required_argument, NULL, 'f'}, | |
| 651 {"debug", no_argument, NULL, 'd'}, | |
| 652 {"version", no_argument, NULL, 'v'}, | |
| 653 {"session", required_argument, NULL, 's'}, | |
| 654 {0, 0, 0, 0} | |
| 655 }; | |
| 656 | |
| 657 #ifdef DEBUG | |
| 658 opt_debug = 1; | |
| 659 #endif | |
| 660 | |
| 661 #ifdef ENABLE_NLS | |
| 662 bindtextdomain(PACKAGE, LOCALEDIR); | |
| 663 bind_textdomain_codeset(PACKAGE, "UTF-8"); | |
| 664 textdomain(PACKAGE); | |
| 665 #endif | |
| 666 | |
| 667 #if HAVE_SIGNAL_H | |
| 668 /* Let's not violate any PLA's!!!! */ | |
| 669 /* jseymour: whatever the fsck that means */ | |
| 670 /* Robot101: for some reason things like gdm like to block * | |
| 671 * useful signals like SIGCHLD, so we unblock all the ones we * | |
| 672 * declare a handler for. thanks JSeymour and Vann. */ | |
| 673 if (sigemptyset(&sigset)) { | |
| 674 char errmsg[BUFSIZ]; | |
| 5435 | 675 snprintf(errmsg, BUFSIZ, "Warning: couldn't initialise empty signal set"); |
| 4489 | 676 perror(errmsg); |
| 677 } | |
| 678 for(sig_indx = 0; catch_sig_list[sig_indx] != -1; ++sig_indx) { | |
| 679 if((prev_sig_disp = signal(catch_sig_list[sig_indx], sighandler)) == SIG_ERR) { | |
| 680 char errmsg[BUFSIZ]; | |
| 5435 | 681 snprintf(errmsg, BUFSIZ, "Warning: couldn't set signal %d for catching", |
| 4489 | 682 catch_sig_list[sig_indx]); |
| 683 perror(errmsg); | |
| 684 } | |
| 685 if(sigaddset(&sigset, catch_sig_list[sig_indx])) { | |
| 686 char errmsg[BUFSIZ]; | |
| 5435 | 687 snprintf(errmsg, BUFSIZ, "Warning: couldn't include signal %d for unblocking", |
| 4489 | 688 catch_sig_list[sig_indx]); |
| 689 perror(errmsg); | |
| 690 } | |
| 691 } | |
| 692 for(sig_indx = 0; ignore_sig_list[sig_indx] != -1; ++sig_indx) { | |
| 693 if((prev_sig_disp = signal(ignore_sig_list[sig_indx], SIG_IGN)) == SIG_ERR) { | |
| 694 char errmsg[BUFSIZ]; | |
| 5435 | 695 snprintf(errmsg, BUFSIZ, "Warning: couldn't set signal %d to ignore", |
| 4489 | 696 ignore_sig_list[sig_indx]); |
| 697 perror(errmsg); | |
| 698 } | |
| 699 } | |
| 700 | |
| 701 if (sigprocmask(SIG_UNBLOCK, &sigset, NULL)) { | |
| 702 char errmsg[BUFSIZ]; | |
| 5435 | 703 snprintf(errmsg, BUFSIZ, "Warning: couldn't unblock signals"); |
| 4489 | 704 perror(errmsg); |
| 705 } | |
| 706 #endif | |
| 707 | |
| 708 for (i = 0; i < argc; i++) { | |
| 709 /* --login option */ | |
| 710 if (strstr(argv[i], "--l") == argv[i]) { | |
| 711 char *equals; | |
| 712 opt_login = 1; | |
| 713 if ((equals = strchr(argv[i], '=')) != NULL) { | |
| 714 /* --login=NAME */ | |
| 715 opt_login_arg = g_strdup(equals + 1); | |
| 716 if (strlen(opt_login_arg) == 0) { | |
| 717 g_free(opt_login_arg); | |
| 718 opt_login_arg = NULL; | |
| 719 } | |
| 720 } else if (i + 1 < argc && argv[i + 1][0] != '-') { | |
| 721 /* --login NAME */ | |
| 722 opt_login_arg = g_strdup(argv[i + 1]); | |
| 723 strcpy(argv[i + 1], " "); | |
| 724 } | |
| 725 strcpy(argv[i], " "); | |
| 726 } | |
| 727 /* -l option */ | |
| 728 else if (strstr(argv[i], "-l") == argv[i]) { | |
| 729 opt_login = 1; | |
| 730 if (strlen(argv[i]) > 2) { | |
| 731 /* -lNAME */ | |
| 732 opt_login_arg = g_strdup(argv[i] + 2); | |
| 733 } else if (i + 1 < argc && argv[i + 1][0] != '-') { | |
| 734 /* -l NAME */ | |
| 735 opt_login_arg = g_strdup(argv[i + 1]); | |
| 736 strcpy(argv[i + 1], " "); | |
| 737 } | |
| 738 strcpy(argv[i], " "); | |
| 739 } | |
| 740 /* --away option */ | |
| 741 else if (strstr(argv[i], "--aw") == argv[i]) { | |
| 742 char *equals; | |
| 743 opt_away = 1; | |
| 744 if ((equals = strchr(argv[i], '=')) != NULL) { | |
| 745 /* --away=MESG */ | |
| 746 opt_away_arg = g_strdup(equals + 1); | |
| 747 if (strlen(opt_away_arg) == 0) { | |
| 748 g_free(opt_away_arg); | |
| 749 opt_away_arg = NULL; | |
| 750 } | |
| 751 } else if (i + 1 < argc && argv[i + 1][0] != '-') { | |
| 752 /* --away MESG */ | |
| 753 opt_away_arg = g_strdup(argv[i + 1]); | |
| 754 strcpy(argv[i + 1], " "); | |
| 755 } | |
| 756 strcpy(argv[i], " "); | |
| 757 } | |
| 758 /* -w option */ | |
| 759 else if (strstr(argv[i], "-w") == argv[i]) { | |
| 760 opt_away = 1; | |
| 761 if (strlen(argv[i]) > 2) { | |
| 762 /* -wMESG */ | |
| 763 opt_away_arg = g_strdup(argv[i] + 2); | |
| 764 } else if (i + 1 < argc && argv[i + 1][0] != '-') { | |
| 765 /* -w MESG */ | |
| 766 opt_away_arg = g_strdup(argv[i + 1]); | |
| 767 strcpy(argv[i + 1], " "); | |
| 768 } | |
| 769 strcpy(argv[i], " "); | |
| 770 } | |
| 771 } | |
| 772 /* | |
| 773 if (opt_login) { | |
| 774 printf ("--login given with arg %s\n", | |
| 775 opt_login_arg ? opt_login_arg : "NULL"); | |
| 776 exit(0); | |
| 777 } | |
| 778 */ | |
| 779 | |
| 780 gtk_set_locale(); | |
| 781 gtk_init(&argc, &argv); | |
| 782 | |
| 783 /* scan command-line options */ | |
| 784 opterr = 1; | |
| 785 while ((opt = getopt_long(argc, argv, | |
| 786 #ifndef _WIN32 | |
| 787 "adhu:f:vns:", | |
| 788 #else | |
| 789 "adghu:f:vn", | |
| 790 #endif | |
| 791 long_options, NULL)) != -1) { | |
| 792 switch (opt) { | |
| 793 case 'u': /* set user */ | |
| 794 opt_user = 1; | |
| 795 opt_user_arg = g_strdup(optarg); | |
| 796 break; | |
| 797 case 'a': /* account editor */ | |
| 798 opt_acct = 1; | |
| 799 break; | |
| 800 case 'd': /* debug */ | |
| 801 opt_debug = 1; | |
| 802 break; | |
| 803 case 'f': | |
| 804 opt_rcfile_arg = g_strdup(optarg); | |
| 805 break; | |
| 806 case 's': /* use existing session ID */ | |
| 807 opt_session_arg = g_strdup(optarg); | |
| 808 break; | |
| 809 case 'v': /* version */ | |
| 810 opt_version = 1; | |
| 811 break; | |
| 812 case 'h': /* help */ | |
| 813 opt_help = 1; | |
| 814 break; | |
| 815 case 'n': /* don't autologin */ | |
| 816 opt_nologin = 1; | |
| 817 break; | |
| 818 #ifdef _WIN32 | |
| 819 case 'g': /* debug GTK and GLIB */ | |
| 820 opt_gdebug = 1; | |
| 821 break; | |
| 822 #endif | |
| 823 case '?': | |
| 824 default: | |
| 825 show_usage(1, argv[0]); | |
| 826 return 0; | |
| 827 break; | |
| 828 } | |
| 829 } | |
| 830 | |
| 831 #ifdef _WIN32 | |
| 832 /* We don't want a console window.. */ | |
| 833 /* | |
| 834 * Any calls to the glib logging functions, result in a call to AllocConsole(). | |
| 835 * ME and 98 will in such cases produce a console window (2000 not), despite | |
| 836 * being built as a windows app rather than a console app. So we should either | |
| 837 * ignore messages by setting dummy log handlers, or redirect messages. | |
| 838 * This requires setting handlers for all domains (any lib which uses g_logging). | |
| 839 */ | |
| 840 | |
| 841 g_log_set_handler (NULL, G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION, | |
| 842 (opt_gdebug ? gaim_log_handler : gaim_dummy_log_handler), | |
| 843 NULL); | |
| 844 g_log_set_handler ("Gdk", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION, | |
| 845 (opt_gdebug ? gaim_log_handler : gaim_dummy_log_handler), | |
| 846 NULL); | |
| 847 g_log_set_handler ("Gtk", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION, | |
| 848 (opt_gdebug ? gaim_log_handler : gaim_dummy_log_handler), | |
| 849 NULL); | |
| 850 g_log_set_handler ("GLib", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION, | |
| 851 (opt_gdebug ? gaim_log_handler : gaim_dummy_log_handler), | |
| 852 NULL); | |
| 853 g_log_set_handler ("GModule", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION, | |
| 854 (opt_gdebug ? gaim_log_handler : gaim_dummy_log_handler), | |
| 855 NULL); | |
| 856 g_log_set_handler ("GLib-GObject", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION, | |
| 857 (opt_gdebug ? gaim_log_handler : gaim_dummy_log_handler), | |
| 858 NULL); | |
| 859 g_log_set_handler ("GThread", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION, | |
| 860 (opt_gdebug ? gaim_log_handler : gaim_dummy_log_handler), | |
| 861 NULL); | |
| 862 | |
| 863 /* g_print also makes a call to AllocConsole(), therefore a handler needs to be | |
| 864 set here aswell */ | |
| 865 if(!opt_debug) | |
| 866 g_set_print_handler( gaim_dummy_print ); | |
| 867 | |
| 868 #endif | |
| 869 | |
| 870 /* show help message */ | |
| 871 if (opt_help) { | |
| 872 show_usage(0, argv[0]); | |
| 873 return 0; | |
| 874 } | |
| 875 /* show version message */ | |
| 876 if (opt_version) { | |
| 877 printf("Gaim %s\n",VERSION); | |
| 878 return 0; | |
| 879 } | |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5032
diff
changeset
|
880 |
| 5684 | 881 gaim_prefs_init(); |
| 882 gaim_gtk_prefs_init(); | |
| 883 | |
| 884 /* This kind of has to be here.. sucks, but it's important. */ | |
| 885 gaim_set_debug_ui_ops(gaim_get_gtk_debug_ui_ops()); | |
| 886 gaim_gtk_debug_init(); | |
| 887 | |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
888 /* Set the UI operation structures. */ |
|
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
889 gaim_set_win_ui_ops(gaim_get_gtk_window_ui_ops()); |
|
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
890 gaim_set_xfer_ui_ops(gaim_get_gtk_xfer_ui_ops()); |
|
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
891 gaim_set_blist_ui_ops(gaim_get_gtk_blist_ui_ops()); |
|
5436
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5435
diff
changeset
|
892 gaim_set_notify_ui_ops(gaim_get_gtk_notify_ui_ops()); |
|
5480
f19620d8694f
[gaim-migrate @ 5876]
Christian Hammond <chipx86@chipx86.com>
parents:
5440
diff
changeset
|
893 gaim_set_request_ui_ops(gaim_get_gtk_request_ui_ops()); |
| 5684 | 894 gaim_set_sound_ui_ops(gaim_get_gtk_sound_ui_ops()); |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
895 |
|
5683
9befba33f7c8
[gaim-migrate @ 6102]
Christian Hammond <chipx86@chipx86.com>
parents:
5673
diff
changeset
|
896 gaim_proxy_init(); |
| 5684 | 897 gaim_sound_init(); |
|
5683
9befba33f7c8
[gaim-migrate @ 6102]
Christian Hammond <chipx86@chipx86.com>
parents:
5673
diff
changeset
|
898 |
|
5673
62f57ec16f29
[gaim-migrate @ 6091]
Christian Hammond <chipx86@chipx86.com>
parents:
5665
diff
changeset
|
899 gaim_gtk_conversation_init(); |
|
62f57ec16f29
[gaim-migrate @ 6091]
Christian Hammond <chipx86@chipx86.com>
parents:
5665
diff
changeset
|
900 |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5032
diff
changeset
|
901 plugin_search_paths[0] = LIBDIR; |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5032
diff
changeset
|
902 plugin_search_paths[1] = gaim_user_dir(); |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5032
diff
changeset
|
903 plugin_search_paths[2] = g_strdup_printf("%s/plugins", gaim_user_dir()); |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5032
diff
changeset
|
904 |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5032
diff
changeset
|
905 gaim_plugins_set_search_paths(sizeof(plugin_search_paths) / |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5032
diff
changeset
|
906 sizeof(*plugin_search_paths), |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5032
diff
changeset
|
907 plugin_search_paths); |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5032
diff
changeset
|
908 |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5032
diff
changeset
|
909 g_free(plugin_search_paths[2]); |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5032
diff
changeset
|
910 |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5032
diff
changeset
|
911 gaim_plugins_probe(NULL); |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5032
diff
changeset
|
912 |
|
5665
132a30783c3d
[gaim-migrate @ 6081]
Christian Hammond <chipx86@chipx86.com>
parents:
5642
diff
changeset
|
913 if (!gaim_prefs_load()) { |
|
132a30783c3d
[gaim-migrate @ 6081]
Christian Hammond <chipx86@chipx86.com>
parents:
5642
diff
changeset
|
914 load_prefs(); |
|
132a30783c3d
[gaim-migrate @ 6081]
Christian Hammond <chipx86@chipx86.com>
parents:
5642
diff
changeset
|
915 gaim_prefs_sync(); |
|
132a30783c3d
[gaim-migrate @ 6081]
Christian Hammond <chipx86@chipx86.com>
parents:
5642
diff
changeset
|
916 } |
|
132a30783c3d
[gaim-migrate @ 6081]
Christian Hammond <chipx86@chipx86.com>
parents:
5642
diff
changeset
|
917 |
|
132a30783c3d
[gaim-migrate @ 6081]
Christian Hammond <chipx86@chipx86.com>
parents:
5642
diff
changeset
|
918 |
|
5581
3a9b54f260e3
[gaim-migrate @ 5985]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
919 gaim_accounts_load(); |
|
3a9b54f260e3
[gaim-migrate @ 5985]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
920 |
| 4489 | 921 #ifdef _WIN32 |
| 922 /* Various win32 initializations */ | |
| 923 wgaim_init(); | |
| 924 #endif | |
| 925 | |
| 926 core_main(); | |
|
5032
cb700c07ee07
[gaim-migrate @ 5375]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
927 load_pounces(); |
| 4489 | 928 ui_main(); |
| 929 | |
| 930 #ifdef USE_SM | |
| 931 session_init(argv[0], opt_session_arg); | |
| 932 #endif | |
| 933 if (opt_session_arg != NULL) { | |
| 934 g_free(opt_session_arg); | |
| 935 opt_session_arg = NULL; | |
| 936 }; | |
| 937 | |
| 938 /* set the default username */ | |
| 939 if (opt_user_arg != NULL) { | |
| 940 set_first_user(opt_user_arg); | |
| 941 g_free(opt_user_arg); | |
| 942 opt_user_arg = NULL; | |
| 943 } | |
| 944 | |
| 5535 | 945 if (gaim_prefs_get_bool("/gaim/gtk/debug/enabled")) |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
946 gaim_gtk_debug_window_show(); |
| 4489 | 947 |
| 948 static_proto_init(); | |
| 949 | |
| 950 /* deal with --login */ | |
| 951 if (opt_login) { | |
| 952 dologin_ret = dologin_named(opt_login_arg); | |
| 953 if (opt_login_arg != NULL) { | |
| 954 g_free(opt_login_arg); | |
| 955 opt_login_arg = NULL; | |
| 956 } | |
| 957 } | |
| 958 | |
| 959 if (!opt_acct && !opt_nologin && gaim_session == 0) | |
|
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5549
diff
changeset
|
960 ; /* TODO auto_login(); */ |
| 4489 | 961 |
| 962 if (opt_acct) { | |
|
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5549
diff
changeset
|
963 gaim_gtk_account_dialog_show(); |
|
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5549
diff
changeset
|
964 } else if ((dologin_ret == -1) && !gaim_connections_get_all()) |
| 4489 | 965 show_login(); |
| 966 | |
| 967 gtk_main(); | |
| 968 core_quit(); | |
| 5684 | 969 gaim_sound_shutdown(); |
| 4489 | 970 #ifdef _WIN32 |
| 971 wgaim_cleanup(); | |
| 972 #endif | |
| 973 return 0; | |
| 974 | |
| 975 } |
