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 
25 #include "gui/commongui.h"
26 #include "plugins/engineplugin.h"
27 #include "plugins/pluginloader.h"
28 #include "rconpassworddialog.h"
29 #include "serverapi/server.h"
30 #include "ui_rconpassworddialog.h"
31 
32 DClass<RconPasswordDialog> : public Ui::RconPasswordDialog
33 {
34 };
35 
36 DPointered(RconPasswordDialog)
37 
38 RconPasswordDialog::RconPasswordDialog(QWidget *parent, bool connection)
39  : QDialog(parent)
40 {
41  d->setupUi(this);
43  this->connect(d->cbHidePassword, SIGNAL(toggled(bool)), SLOT(setHidePassword(bool)));
44 
45  if (connection)
46  {
47  // Populate engines box.
48  d->engines->clear();
49  for (unsigned int i = 0; i < gPlugins->numPlugins(); i++)
50  {
51  const EnginePlugin *info = gPlugins->plugin(i)->info();
52  if (info->server(QHostAddress("localhost"), 0)->hasRcon())
53  d->engines->addItem(info->icon(), info->data()->name, i);
54  }
55  }
56  else
57  d->connectionBox->hide();
58 
59  d->cbHidePassword->setChecked(gConfig.doomseeker.bHidePasswords);
60 
61  // Adjust the size and prevent resizing.
62  adjustSize();
63  setMinimumHeight(height());
64  setMaximumHeight(height());
65 }
66 
67 RconPasswordDialog::~RconPasswordDialog()
68 {
69 }
70 
71 QString RconPasswordDialog::connectPassword() const
72 {
73  return d->lePassword->text();
74 }
75 
76 const EnginePlugin *RconPasswordDialog::selectedEngine() const
77 {
78  int pluginIndex = d->engines->itemData(d->engines->currentIndex()).toInt();
79  const PluginLoader::Plugin *plugin = gPlugins->plugin(pluginIndex);
80  if (plugin == nullptr)
81  return nullptr;
82 
83  return plugin->info();
84 }
85 
86 QString RconPasswordDialog::serverAddress() const
87 {
88  return d->leServerAddress->text();
89 }
90 
91 void RconPasswordDialog::setHidePassword(bool hide)
92 {
93  if (hide)
94  d->lePassword->setEchoMode(QLineEdit::Password);
95  else
96  d->lePassword->setEchoMode(QLineEdit::Normal);
97 }