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/passwordscfg.h"
24 #include "gui/commongui.h"
25 #include "plugins/engineplugin.h"
26 #include "plugins/pluginloader.h"
27 #include "rconpassworddialog.h"
28 #include "serverapi/server.h"
29 #include "ui_rconpassworddialog.h"
30 
31 DClass<RconPasswordDialog> : public Ui::RconPasswordDialog
32 {
33 };
34 
35 DPointered(RconPasswordDialog)
36 
37 RconPasswordDialog::RconPasswordDialog(QWidget *parent, bool connection)
38  : QDialog(parent)
39 {
40  d->setupUi(this);
42  this->connect(d->cbHidePassword, SIGNAL(toggled(bool)), SLOT(setHidePassword(bool)));
43 
44  if (connection)
45  {
46  // Populate engines box.
47  d->engines->clear();
48  for (unsigned int i = 0; i < gPlugins->numPlugins(); i++)
49  {
50  const EnginePlugin *info = gPlugins->plugin(i)->info();
51  if (info->server(QHostAddress("localhost"), 0)->hasRcon())
52  d->engines->addItem(info->icon(), info->data()->name, i);
53  }
54  }
55  else
56  d->connectionBox->hide();
57 
58  PasswordsCfg passCfg;
59  setHidePassword(passCfg.isHidingPasswords());
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  d->cbHidePassword->blockSignals(true);
94  d->cbHidePassword->setChecked(hide);
95  d->cbHidePassword->blockSignals(false);
96  d->lePassword->setEchoMode(hide ? QLineEdit::Password : QLineEdit::Normal);
97 }