23 #include "configuration/passwordscfg.h"
24 #include "gui/commongui.h"
25 #include "gui/configuration/irc/cfgircdefinenetworkdialog.h"
26 #include "irc/configuration/chatnetworkscfg.h"
27 #include "irc/configuration/ircconfig.h"
28 #include "irc/ircnetworkconnectioninfo.h"
29 #include "ircnetworkselectionbox.h"
30 #include "qtmetapointer.h"
31 #include "ui_ircnetworkselectionbox.h"
32 #include <QMessageBox>
34 DClass<IRCNetworkSelectionBox> :
public Ui::IRCNetworkSelectionBox
46 connect(d->cboNetwork, SIGNAL(currentIndexChanged(
int)), SLOT(networkChanged(
int)));
51 IRCNetworkSelectionBox::~IRCNetworkSelectionBox()
55 void IRCNetworkSelectionBox::accept()
61 void IRCNetworkSelectionBox::addNetworkToComboBox(
const IRCNetworkEntity &network)
63 d->cboNetwork->addItem(buildTitle(network), network.serializeQVariant());
66 QString IRCNetworkSelectionBox::buildTitle(
const IRCNetworkEntity &network)
const
71 void IRCNetworkSelectionBox::createNewNetwork()
74 if (dialog.exec() == QDialog::Accepted)
77 QList<IRCNetworkEntity> networks = cfg.networks();
78 networks << dialog.getNetworkEntity();
79 cfg.setNetworks(networks);
85 void IRCNetworkSelectionBox::editCurrentNetwork()
88 if (!network.isValid())
90 QMessageBox::critical(
this, tr(
"Doomseeker - edit IRC network"),
91 tr(
"Cannot edit as no valid network is selected."));
95 if (dialog.exec() == QDialog::Accepted)
98 if (replaceNetworkInConfig(network, editedNetwork))
99 updateCurrentNetwork(editedNetwork);
103 void IRCNetworkSelectionBox::fetchNetworks()
106 QList<IRCNetworkEntity> networks = cfg.networks();
107 std::sort(networks.begin(), networks.end());
108 d->cboNetwork->blockSignals(
true);
109 d->cboNetwork->clear();
113 addNetworkToComboBox(network);
117 if (lastUsedNetwork.isValid())
118 setNetworkMatchingDescriptionAsCurrent(lastUsedNetwork.
description());
121 d->cboNetwork->blockSignals(
false);
124 void IRCNetworkSelectionBox::initWidgets()
126 d->leAlternateNick->setText(gIRCConfig.personal.alternativeNickname);
127 d->leNick->setText(gIRCConfig.personal.nickname);
128 d->leRealName->setText(gIRCConfig.personal.fullName);
129 d->leUserName->setText(gIRCConfig.personal.userName);
132 setHidePassword(passCfg.isHidingPasswords());
140 networkEntity.setPassword(d->lePassword->text());
141 return networkEntity;
144 void IRCNetworkSelectionBox::networkChanged(
int index)
152 return networkAtRow(d->cboNetwork->currentIndex());
157 if (row < 0 || row >= d->cboNetwork->count())
159 return IRCNetworkEntity::deserializeQVariant(d->cboNetwork->itemData(row));
167 outInfo.
nick = d->leNick->text();
168 outInfo.
realName = d->leRealName->text();
169 outInfo.
userName = d->leUserName->text();
176 void IRCNetworkSelectionBox::setHidePassword(
bool hide)
178 d->cbHidePassword->blockSignals(
true);
179 d->cbHidePassword->setChecked(hide);
180 d->cbHidePassword->blockSignals(
false);
181 d->lePassword->setEchoMode(hide ? QLineEdit::Password : QLineEdit::Normal);
184 void IRCNetworkSelectionBox::setNetworkMatchingDescriptionAsCurrent(
const QString &description)
186 for (
int row = 0; row < d->cboNetwork->count(); ++row)
191 d->cboNetwork->setCurrentIndex(row);
197 void IRCNetworkSelectionBox::updateCurrentNetwork(
const IRCNetworkEntity &network)
199 d->cboNetwork->setItemText(d->cboNetwork->currentIndex(), buildTitle(network));
200 d->cboNetwork->setItemData(d->cboNetwork->currentIndex(), network.serializeQVariant());
204 void IRCNetworkSelectionBox::removeCurrentNetwork()
207 if (!network.isValid())
209 QMessageBox::critical(
this, tr(
"Doomseeker - remove IRC network"),
210 tr(
"Cannot remove as no valid network is selected."));
213 if (QMessageBox::question(
this, tr(
"Doomseeker - remove IRC network"),
214 tr(
"Are you sure you wish to remove network '%1'?").arg(network.
description()),
215 QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
229 void IRCNetworkSelectionBox::updateNetworkInfo()
233 d->leServerAddress->setText(network.
address());
234 d->spinPort->setValue(network.
port());
235 d->lePassword->setText(network.
password());
238 bool IRCNetworkSelectionBox::validate()
240 const static QString ERROR_TITLE = tr(
"IRC connection error");
243 if (connectionInfo.
nick.isEmpty())
245 QMessageBox::warning(
nullptr, ERROR_TITLE, tr(
"You must specify a nick."));
251 QMessageBox::warning(
nullptr, ERROR_TITLE, tr(
"You must specify a network address."));