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 "plugins/engineplugin.h"
25 #include "plugins/pluginloader.h"
26 #include "rconpassworddialog.h"
27 #include "serverapi/server.h"
28 #include "ui_rconpassworddialog.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  d->connectionBox->hide();
55 
56  d->cbHidePassword->setChecked(gConfig.doomseeker.bHidePasswords);
57 
58  // Adjust the size and prevent resizing.
59  adjustSize();
60  setMinimumHeight(height());
61  setMaximumHeight(height());
62 }
63 
64 RconPasswordDialog::~RconPasswordDialog()
65 {
66 }
67 
68 QString RconPasswordDialog::connectPassword() const
69 {
70  return d->lePassword->text();
71 }
72 
73 const EnginePlugin *RconPasswordDialog::selectedEngine() const
74 {
75  int pluginIndex = d->engines->itemData(d->engines->currentIndex()).toInt();
76  const PluginLoader::Plugin *plugin = gPlugins->plugin(pluginIndex);
77  if (plugin == nullptr)
78  return nullptr;
79 
80  return plugin->info();
81 }
82 
83 QString RconPasswordDialog::serverAddress() const
84 {
85  return d->leServerAddress->text();
86 }
87 
88 void RconPasswordDialog::setHidePassword(bool hide)
89 {
90  if (hide)
91  d->lePassword->setEchoMode(QLineEdit::Password);
92  else
93  d->lePassword->setEchoMode(QLineEdit::Normal);
94 }
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.