rconpassworddialog.cpp
1 //------------------------------------------------------------------------------
2 // rconpassworddialog.cpp
3 //------------------------------------------------------------------------------
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301 USA
19 //
20 //------------------------------------------------------------------------------
21 // Copyright (C) 2009 Braden "Blzut3" Obrzut <admin@maniacsvault.net>
22 //------------------------------------------------------------------------------
23 #include "configuration/doomseekerconfig.h"
24 #include "rconpassworddialog.h"
25 #include "ui_rconpassworddialog.h"
26 #include "plugins/engineplugin.h"
27 #include "plugins/pluginloader.h"
28 #include "serverapi/server.h"
29 
30 DClass<RconPasswordDialog> : public Ui::RconPasswordDialog
31 {
32 };
33 
34 DPointered(RconPasswordDialog)
35 
36 RconPasswordDialog::RconPasswordDialog(QWidget *parent, bool connection)
37 : QDialog(parent)
38 {
39  d->setupUi(this);
40  this->connect(d->cbHidePassword, SIGNAL(toggled(bool)), SLOT(setHidePassword(bool)));
41 
42  if (connection)
43  {
44  // Populate engines box.
45  d->engines->clear();
46  for(unsigned int i = 0;i < gPlugins->numPlugins();i++)
47  {
48  const EnginePlugin* info = gPlugins->plugin(i)->info();
49  if (info->server(QHostAddress("localhost"), 0)->hasRcon())
50  d->engines->addItem(info->icon(), info->data()->name, i);
51  }
52  }
53  else
54  {
55  d->connectionBox->hide();
56  }
57 
58  d->cbHidePassword->setChecked(gConfig.doomseeker.bHidePasswords);
59 
60  // Adjust the size and prevent resizing.
61  adjustSize();
62  setMinimumHeight(height());
63  setMaximumHeight(height());
64 }
65 
66 RconPasswordDialog::~RconPasswordDialog()
67 {
68 }
69 
70 QString RconPasswordDialog::connectPassword() const
71 {
72  return d->lePassword->text();
73 }
74 
75 const EnginePlugin *RconPasswordDialog::selectedEngine() const
76 {
77  int pluginIndex = d->engines->itemData(d->engines->currentIndex()).toInt();
78  const PluginLoader::Plugin *plugin = gPlugins->plugin(pluginIndex);
79  if(plugin == NULL)
80  return NULL;
81 
82  return plugin->info();
83 }
84 
85 QString RconPasswordDialog::serverAddress() const
86 {
87  return d->leServerAddress->text();
88 }
89 
90 void RconPasswordDialog::setHidePassword(bool hide)
91 {
92  if (hide)
93  d->lePassword->setEchoMode(QLineEdit::Password);
94  else
95  d->lePassword->setEchoMode(QLineEdit::Normal);
96 }
virtual ServerPtr server(const QHostAddress &address, unsigned short port) const
Creates an instance of server object from this plugin.
EnginePlugin * info() const
Main plugin interface.