summaryrefslogtreecommitdiffstats
path: root/knights/dlg_login.cpp
blob: d468c12970de047821e1f7e4d053551e60596de6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/***************************************************************************
                          dlg_login.cpp  -  description
                             -------------------
    begin                : Sat Sep 29 2001
    copyright            : (C) 2003 by Troy Corbin Jr.
    email                : tcorbin@users.sourceforge.net
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include "dlg_login.moc"

dlg_login::dlg_login(TQWidget *parent, const char *name, resource *rsrc) :
  KDialogBase(parent, name, TRUE, i18n("Login Prompt"), Help|Ok|Cancel, Ok,TRUE )
{
	serverList::Iterator i;
	serverList::Iterator currentServer;
	int counter = 0;

	myResource = rsrc;

  BOX_Parent = makeVBoxMainWidget();

	/* Select which server to connect to */
	GROUP_Select_Server = new TQGroupBox( 1, TQt::Vertical, i18n( "Select Server" ), BOX_Parent );

	COMBO_Select_Server = new KComboBox ( GROUP_Select_Server );
	COMBO_Select_Server->setEditable( FALSE );

	/* fill the combobox with servers */
	for(i = myResource->servers.begin(); i != myResource->servers.end(); i++)
	{
		COMBO_Select_Server->insertItem((*i).Name);
		if((*i).CurrentRef == TRUE)
		{
    	COMBO_Select_Server->setCurrentItem(counter);
			currentServer = i;
		}
		counter++;
	}
	/* connect to right signal to the combobox */
	connect( COMBO_Select_Server, TQ_SIGNAL( activated(const TQString &) ), this, TQ_SLOT( slotUpdateUser(const TQString &) ) );

	GROUP_Username = new TQGroupBox( 1, TQt::Horizontal, i18n("User info"), BOX_Parent);
	BOX_ALIGN = new TQHBox( GROUP_Username );
  BOX_TEXT = new TQVBox( BOX_ALIGN );
  TEXT_Login = new TQLabel( BOX_TEXT );
  TEXT_Password = new TQLabel( BOX_TEXT );

  TEXT_Login->setText( i18n("Login:") );
  TEXT_Password->setText( i18n("Password:") );

  BOX_EDIT = new TQVBox( BOX_ALIGN );
  EDIT_Login = new KLineEdit( BOX_EDIT );
  EDIT_Password = new KLineEdit( BOX_EDIT );

  CHECKBOX_GUEST = new TQCheckBox(i18n("Log in as guest"), GROUP_Username);

  EDIT_Password->setEchoMode( TQLineEdit::Password );

  connect(CHECKBOX_GUEST, TQ_SIGNAL(toggled(bool)), this, TQ_SLOT(slotGuestToggle(bool)));

  /* Init the buttons */
  showButtonCancel( TRUE );
  showButtonOK( TRUE );
  showButton( Help, TRUE );

  enableButtonCancel( TRUE );
  enableButtonOK( TRUE );
  enableButton( Help, TRUE );
  setButtonOKText( i18n("Login"), i18n("Log in to the chess server using this name and password.") );
	setButtonCancelText(  i18n("Cancel"), i18n("Abort logging into the server") );
  setHelp("prefs");
  disableResize();
  show();
	/* make sure the username for the default server is displayed */
	slotUpdateUser((*currentServer).Name);
}
///////////////////////////////////////
//
//  dlg_login::~dlg_login
//
///////////////////////////////////////
dlg_login::~dlg_login()
{
}
///////////////////////////////////////
//
//  dlg_login::slotOk
//
///////////////////////////////////////
void dlg_login::slotOk( void )
{
  if(BOX_ALIGN->isEnabled())
  {
    emit login(EDIT_Login->text(), EDIT_Password->text());
  }
  else
  {
    emit login("guest", "");
  }
	emit okClicked();
  slotDelayedDestruct();
}

///////////////////////////////////////
//
//  dlg_login::slotGuestToggle
//
///////////////////////////////////////
void dlg_login::slotGuestToggle( bool on )
{
  BOX_ALIGN->setEnabled(!on);
}

///////////////////////////////////////
//
//  dlg_login::slotUpdateUser
//
///////////////////////////////////////
void dlg_login::slotUpdateUser(const TQString &name)
{
	/* this function retrieves the correct serverResource from
		 the resources and uses that to fill in the username and
		 password fields */
	serverList::Iterator i;

	for(i = myResource->servers.begin(); i != myResource->servers.end(); i++)
	{
		if((*i).CurrentRef)
		{
    	(*i).CurrentRef = FALSE;
		}
		if((*i).Name == name )
		{
			(*i).CurrentRef = TRUE;
			EDIT_Login->setText((*i).UserName);
   		EDIT_Password->setText((*i).Password);
			server = &(*i);
		}
	}
}

///////////////////////////////////////
//
//  dlg_login::slotUpdateUser
//
///////////////////////////////////////
void dlg_login::disableServerSelect()
{
	COMBO_Select_Server->setEnabled(false);
}