gtklogin._pike
Go to the documentation of this file.
1 /* Copyright (C) 2000-2004 Thomas Bopp, Thorsten Hampel, Ludger Merkens
2  * Copyright (C) 2003-2004 Martin Baehr
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * $Id: gtklogin.pike,v 1.1 2008/03/31 13:39:57 exodusd Exp $
19  */
20 class gtklogin {
21 public:
22 
23 
24 
25 
26 void do_login(array w, object widget)
27 {
28  string name = w[1]->get_text();
29  string passwd = w[2]->get_text()||"";
30 
31  if(w[3](name, passwd, @w[4..] )) // login successfull
32  {
33  w[0]->unmap();
34  destruct(w[0]);
35  }
36  else
37  GTK.Alert("login failed");
38 }
39 
40 string _(string message)
41 {
42  return message;
43 }
44 
45 void get_login(string label, string username, mixed ... args)
46 {
47 
48  werror("get_login, %O\n", args);
49  object pwin, plabel, pentry, llabel, lentry;
50  object pbox, lbox, ok, cancel, vbox, frame, bbox;
51  object tbox;
52 
53  pwin = GTK.Window( GTK.WINDOW_TOPLEVEL );
54  pwin->realize();
55  pwin->set_policy(1,1,0);
56  pwin->set_title(_("sTeam application launcher ")+label);
57  pwin->set_usize(300, 150);
58  frame = GTK.Frame(_("Enter login for ")+label);
59 
60  llabel = GTK.Label(_("Username: "));
61  lentry = GTK.Entry();
62  vbox = GTK.Vbox(0,0);
63  vbox->border_width(5);
64  vbox->set_spacing(5);
65 
66  lbox = GTK.Hbox(0,0);
67  lbox->pack_start(llabel,0,0,0);
68  lbox->pack_end(lentry,1,1,1);
69  vbox->pack_start(lbox,0,0,0);
70 
71  username && lentry->set_text(username);
72  plabel = GTK.Label(_("Password: "));
73  pentry = GTK.Entry();
74  pentry->set_visibility(0);
75  pbox = GTK.Hbox(0,0);
76  pbox->pack_start(plabel,0,0,0);
77  pbox->pack_end(pentry,1,1,1);
78  vbox->pack_start(pbox,0,0,0);
79 
80  !username&&lentry->signal_connect("activate", do_login,
81  ({ pwin, lentry, pentry, @args }));
82  pentry->signal_connect("activate", do_login,
83  ({ pwin, lentry, pentry, @args }));
84  ok = GTK.Button(_("Login"));
85  cancel = GTK.Button(_("Cancel"));
86  ok->signal_connect("clicked", do_login, ({ pwin, lentry, pentry, @args }));
87 
88  cancel->signal_connect("clicked", exit, 0);
89 
90  bbox = GTK.HbuttonBox();
91  bbox->set_spacing(4)
92  ->set_layout(GTK.BUTTONBOX_SPREAD)
93  ->pack_start(ok, 0,0,0)
94  ->pack_end(cancel, 0,0,0);
95 
96  vbox->pack_end(bbox,0,0,0);
97 
98  frame->add(vbox);
99  frame->border_width(5);
100 
101  tbox = GTK.Vbox(0,0);
102  tbox->pack_start(frame, 1,1,1);
103  pwin->add(tbox);
104  pwin->show_all();
105 }
106 
107 
108 
109 };