comparison src/gtkmain.c @ 10315:deec4b58d516

[gaim-migrate @ 11515] Login Window 1998 -- 2004 committer: Tailor Script <tailor@pidgin.im>
author Sean Egan <seanegan@gmail.com>
date Sat, 04 Dec 2004 18:51:56 +0000
parents 2ac21bf20e04
children 2b0f39e264ea
comparison
equal deleted inserted replaced
10314:0a561b6ef7ec 10315:deec4b58d516
76 #ifdef HAVE_STARTUP_NOTIFICATION 76 #ifdef HAVE_STARTUP_NOTIFICATION
77 static SnLauncheeContext *sn_context = NULL; 77 static SnLauncheeContext *sn_context = NULL;
78 static SnDisplay *sn_display = NULL; 78 static SnDisplay *sn_display = NULL;
79 #endif 79 #endif
80 80
81 GtkWidget *mainwindow = NULL;
82
83 int opt_away = 0; 81 int opt_away = 0;
84 int docklet_count = 0; 82 int docklet_count = 0;
85 char *opt_away_arg = NULL; 83 char *opt_away_arg = NULL;
86 84
87 #if HAVE_SIGNAL_H 85 #if HAVE_SIGNAL_H
124 gaim_gtk_sound_set_login_mute(TRUE); 122 gaim_gtk_sound_set_login_mute(TRUE);
125 snd_tmout = gaim_timeout_add(10000, sound_timeout, NULL); 123 snd_tmout = gaim_timeout_add(10000, sound_timeout, NULL);
126 } 124 }
127 } 125 }
128 126
129 static gboolean domiddleclick(GtkWidget *w, GdkEventButton *event, gpointer null)
130 {
131 if (event->button != 2)
132 return FALSE;
133
134 gaim_accounts_auto_login(GAIM_GTK_UI);
135
136 return TRUE;
137 }
138
139 static void dologin(GtkWidget *widget, GtkWidget *w)
140 {
141 GaimAccount *account;
142 GtkWidget *item;
143 const char *password = gtk_entry_get_text(GTK_ENTRY(pass));
144
145 item = gtk_menu_get_active(GTK_MENU(gtk_option_menu_get_menu(GTK_OPTION_MENU(name))));
146 account = g_object_get_data(G_OBJECT(item), "account");
147
148 if (!account) {
149 gaim_notify_error(NULL, NULL, _("Please create an account."), NULL);
150 return;
151 }
152
153 gaim_account_set_password(account, (*password != '\0') ? password : NULL);
154
155 gaim_account_connect(account);
156 }
157
158 /* <name> is a comma-separated list of names, or NULL
159 if NULL and there is at least one user defined in .gaimrc, try to login.
160 if not NULL, parse <name> into separate strings, look up each one in
161 .gaimrc and, if it's there, try to login.
162 returns: 0 if successful
163 -1 if no user was found that had a saved password
164 */
165 static int dologin_named(char *name) 127 static int dologin_named(char *name)
166 { 128 {
167 GaimAccount *account; 129 GaimAccount *account;
168 char **names, **n; 130 char **names, **n;
169 int retval = -1; 131 int retval = -1;
183 retval = 0; 145 retval = 0;
184 gaim_account_connect(account); 146 gaim_account_connect(account);
185 } 147 }
186 148
187 return retval; 149 return retval;
188 }
189
190
191 static void combo_changed(GtkWidget *menu, GaimAccount *account, gpointer data)
192 {
193 if (account && gaim_account_get_remember_password(account)) {
194 gtk_entry_set_text(GTK_ENTRY(pass), account->password);
195 } else {
196 gtk_entry_set_text(GTK_ENTRY(pass), "");
197 }
198 }
199
200
201 static void login_window_closed(GtkWidget *w, GdkEvent *ev, gpointer d)
202 {
203 if(docklet_count) {
204 #ifdef _WIN32
205 wgaim_systray_minimize(mainwindow);
206 #endif
207 gtk_widget_hide(mainwindow);
208 } else
209 gaim_core_quit();
210 }
211
212 void show_login()
213 {
214 GtkWidget *image;
215 GtkWidget *vbox;
216 GtkWidget *button;
217 GtkWidget *hbox;
218 GtkWidget *label;
219 GtkWidget *vbox2;
220
221 /* Do we already have a main window opened? If so, bring it back, baby... ribs... yeah */
222 if (mainwindow) {
223 gtk_window_present(GTK_WINDOW(mainwindow));
224 return;
225 }
226
227 mainwindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
228
229 gtk_window_set_role(GTK_WINDOW(mainwindow), "login");
230 gtk_window_set_resizable(GTK_WINDOW(mainwindow), FALSE);
231 gtk_window_set_title(GTK_WINDOW(mainwindow), _("Login"));
232 gtk_container_set_border_width(GTK_CONTAINER(mainwindow), 5);
233 g_signal_connect(G_OBJECT(mainwindow), "delete_event",
234 G_CALLBACK(login_window_closed), mainwindow);
235
236 vbox = gtk_vbox_new(FALSE, 0);
237 gtk_container_add(GTK_CONTAINER(mainwindow), vbox);
238
239 image = gtk_image_new_from_stock(GAIM_STOCK_LOGO, gtk_icon_size_from_name(GAIM_ICON_SIZE_LOGO));
240 gtk_box_pack_start(GTK_BOX(vbox), image, FALSE, FALSE, 0);
241
242 vbox2 = gtk_vbox_new(FALSE, 0);
243 gtk_container_set_border_width(GTK_CONTAINER(vbox2), 5);
244
245 /* why isn't there a gtk_label_new_with_markup? */
246 label = gtk_label_new(NULL);
247 gtk_label_set_markup_with_mnemonic(GTK_LABEL(label), _("<b>_Account:</b>"));
248 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
249 gtk_box_pack_start(GTK_BOX(vbox2), label, FALSE, FALSE, 0);
250
251 name = gaim_gtk_account_option_menu_new(NULL, TRUE, G_CALLBACK(combo_changed), NULL, NULL);
252 gtk_label_set_mnemonic_widget(GTK_LABEL(label), name);
253
254 gtk_box_pack_start(GTK_BOX(vbox2), name, FALSE, TRUE, 0);
255 gtk_box_pack_start(GTK_BOX(vbox), vbox2, FALSE, TRUE, 0);
256
257 vbox2 = gtk_vbox_new(FALSE, 0);
258 gtk_container_set_border_width(GTK_CONTAINER(vbox2), 5);
259
260 label = gtk_label_new(NULL);
261 gtk_label_set_markup_with_mnemonic(GTK_LABEL(label), _("<b>_Password:</b>"));
262 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
263 gtk_box_pack_start(GTK_BOX(vbox2), label, FALSE, FALSE, 0);
264
265 pass = gtk_entry_new();
266 gtk_label_set_mnemonic_widget(GTK_LABEL(label), pass);
267 gtk_entry_set_visibility(GTK_ENTRY(pass), FALSE);
268 g_signal_connect(G_OBJECT(pass), "activate",
269 G_CALLBACK(dologin), mainwindow);
270 gtk_box_pack_start(GTK_BOX(vbox2), pass, FALSE, TRUE, 0);
271 gtk_box_pack_start(GTK_BOX(vbox), vbox2, FALSE, TRUE, 0);
272
273 /* Now for the button box */
274 hbox = gtk_hbox_new(TRUE, 0);
275 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 5);
276
277 /* And now for the buttons */
278 button = gaim_pixbuf_button_from_stock(_("A_ccounts"), GAIM_STOCK_ACCOUNTS, GAIM_BUTTON_VERTICAL);
279 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
280 g_signal_connect(G_OBJECT(button), "clicked",
281 G_CALLBACK(gaim_gtk_accounts_window_show), mainwindow);
282 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
283
284 button = gaim_pixbuf_button_from_stock(_("P_references"), GTK_STOCK_PREFERENCES, GAIM_BUTTON_VERTICAL);
285 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
286 g_signal_connect(G_OBJECT(button), "clicked",
287 G_CALLBACK(gaim_gtk_prefs_show), mainwindow);
288 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
289
290 button = gaim_pixbuf_button_from_stock(_("_Log in"), GAIM_STOCK_SIGN_ON, GAIM_BUTTON_VERTICAL);
291 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
292 g_signal_connect(G_OBJECT(button), "clicked",
293 G_CALLBACK(dologin), mainwindow);
294 g_signal_connect(G_OBJECT(button), "button-press-event", G_CALLBACK(domiddleclick), NULL);
295 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
296
297 /* Now grab the focus that we need */
298 if (gaim_accounts_get_all()) {
299 GaimAccount *account = gaim_accounts_get_all()->data;
300
301 if (gaim_account_get_remember_password(account)) {
302 combo_changed(NULL, account, NULL);
303 gtk_widget_grab_focus(button);
304 } else {
305 gtk_widget_grab_focus(pass);
306 }
307 } else {
308 gaim_gtk_accounts_window_show();
309 gtk_widget_grab_focus(button);
310 }
311
312 /* And raise the curtain! */
313 gtk_widget_show_all(mainwindow);
314
315 } 150 }
316 151
317 static void 152 static void
318 clean_pid(void) 153 clean_pid(void)
319 { 154 {
952 } 787 }
953 788
954 if (!opt_acct && !opt_nologin) 789 if (!opt_acct && !opt_nologin)
955 gaim_accounts_auto_login(GAIM_GTK_UI); 790 gaim_accounts_auto_login(GAIM_GTK_UI);
956 791
792 gaim_blist_show();
793
957 if (opt_acct) { 794 if (opt_acct) {
958 gaim_gtk_accounts_window_show(); 795 gaim_gtk_accounts_window_show();
959 } else if ((dologin_ret == -1) && !gaim_connections_get_all()) 796 }
960 show_login();
961 797
962 #ifdef HAVE_STARTUP_NOTIFICATION 798 #ifdef HAVE_STARTUP_NOTIFICATION
963 startup_notification_complete(); 799 startup_notification_complete();
964 #endif 800 #endif
965 gtk_main(); 801 gtk_main();