AuthDialog.cpp

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////////////
00002 //    Scorched3D (c) 2000-2009
00003 //
00004 //    This file is part of Scorched3D.
00005 //
00006 //    Scorched3D is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    Scorched3D is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with Scorched3D; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 ////////////////////////////////////////////////////////////////////////////////
00020 
00021 #include <dialogs/AuthDialog.h>
00022 #include <graph/OptionsDisplay.h>
00023 #include <GLW/GLWTextButton.h>
00024 #include <GLW/GLWWindowManager.h>
00025 #include <client/ClientParams.h>
00026 #include <client/ClientConnectionAuthHandler.h>
00027 
00028 AuthDialog *AuthDialog::instance_ = 0;
00029 
00030 AuthDialog *AuthDialog::instance()
00031 {
00032         if (!instance_)
00033         {
00034                 instance_ = new AuthDialog;
00035         }
00036         return instance_;
00037 }
00038 
00039 AuthDialog::AuthDialog() :
00040         GLWWindow("", 10.0f, 10.0f, 300.0f, 70.0f, eSmallTitle, ""),
00041         auth_(0)
00042 {
00043         needCentered_ = true;
00044 }
00045 
00046 AuthDialog::~AuthDialog()
00047 {
00048 }
00049 
00050 void AuthDialog::display()
00051 {
00052         GLWWindow::display();
00053 
00054         clear();
00055 
00056         addWidget(
00057                 new GLWLabel(0.0f, 0.0f, LANG_RESOURCE("AUTH_LINE", "This server requires authentication.")), 
00058                 0, SpaceAll, 10.0f);
00059 
00060         GLWPanel *inputPanel = new GLWPanel(0.0f, 0.0f, 0.0f, 0.0f, false, false);
00061 
00062         username_ = 0;
00063         if (auth_ & eNameRequired)
00064         {
00065                 username_ = new GLWTextBox(0.0f, 0.0f, 200.0f,
00066                         LANG_STRING(ClientParams::instance()->getUserName()));
00067                 inputPanel->addWidget(new GLWLabel(0.0f, 0.0f, LANG_RESOURCE("USER_NAME_LABEL", "User Name :")));
00068                 inputPanel->addWidget(username_, 0, SpaceLeft | SpaceTop, 10.0f);
00069         }
00070         password_ = 0;
00071         if (auth_ & ePasswordRequired)
00072         {
00073                 password_ = new GLWTextBox(0.0f, 0.0f, 200.0f, 
00074                         LANG_STRING(ClientParams::instance()->getPassword()), GLWTextBox::eFlagPassword);
00075                 inputPanel->addWidget(new GLWLabel(0.0f, 0.0f, LANG_RESOURCE("PASSWORD_LABEL", "Password :")));
00076                 inputPanel->addWidget(password_, 0, SpaceLeft | SpaceTop, 10.0f);
00077         }
00078         inputPanel->setGridWidth(2);
00079         inputPanel->setLayout(GLWPanel::LayoutGrid);
00080         addWidget(inputPanel, 0, SpaceAll, 10.0f);
00081 
00082         GLWPanel *buttonPanel = new GLWPanel(0.0f, 0.0f, 0.0f, 0.0f, false, false);
00083         GLWButton *cancelButton = new GLWTextButton(LANG_RESOURCE("CANCEL", "Cancel"), 95, 10, 105, this, 
00084                 GLWButton::ButtonFlagCancel | GLWButton::ButtonFlagCenterX);
00085         cancelId_ = cancelButton->getId();
00086         buttonPanel->addWidget(cancelButton, 0, SpaceRight, 10.0f);
00087         GLWButton *okButton = new GLWTextButton(LANG_RESOURCE("OK", "Ok"), 235, 10, 55, this, 
00088                 GLWButton::ButtonFlagOk | GLWButton::ButtonFlagCenterX);
00089         okId_ = okButton->getId();
00090         buttonPanel->addWidget(okButton);
00091         buttonPanel->setLayout(GLWPanel::LayoutHorizontal);
00092         addWidget(buttonPanel, 0, SpaceAll, 10.0f);
00093 
00094 
00095         setLayout(GLWPanel::LayoutVerticle);
00096         layout();
00097 }
00098 
00099 void AuthDialog::buttonDown(unsigned int id)
00100 {
00101         GLWWindowManager::instance()->hideWindow(getId());
00102         if (id == okId_)
00103         {
00104                 if (username_) 
00105                         ClientParams::instance()->setUserName(username_->getText().c_str());
00106                 if (password_) 
00107                         ClientParams::instance()->setPassword(password_->getText().c_str());
00108 
00109                 ClientConnectionAuthHandler::instance()->sendAuth();
00110         }
00111         else
00112         {
00113                 ClientConnectionAuthHandler::instance()->cancelAuth();
00114         }
00115 }

Generated on Mon Feb 16 15:14:37 2009 for Scorched3D by  doxygen 1.5.3