23 #include "gui/commongui.h"
24 #include "gui/configuration/irc/cfgircdefinenetworkdialog.h"
25 #include "irc/configuration/chatnetworkscfg.h"
26 #include "irc/configuration/ircconfig.h"
27 #include "irc/ircnetworkconnectioninfo.h"
28 #include "ircnetworkselectionbox.h"
29 #include "qtmetapointer.h"
30 #include "ui_ircnetworkselectionbox.h"
31 #include <QMessageBox>
33 DClass<IRCNetworkSelectionBox> :
public Ui::IRCNetworkSelectionBox
45 connect(d->cboNetwork, SIGNAL(currentIndexChanged(
int)), SLOT(networkChanged(
int)));
50 IRCNetworkSelectionBox::~IRCNetworkSelectionBox()
54 void IRCNetworkSelectionBox::accept()
60 void IRCNetworkSelectionBox::addNetworkToComboBox(
const IRCNetworkEntity &network)
62 d->cboNetwork->addItem(buildTitle(network), network.serializeQVariant());
65 QString IRCNetworkSelectionBox::buildTitle(
const IRCNetworkEntity &network)
const
70 void IRCNetworkSelectionBox::createNewNetwork()
73 if (dialog.exec() == QDialog::Accepted)
76 QList<IRCNetworkEntity> networks = cfg.networks();
77 networks << dialog.getNetworkEntity();
78 cfg.setNetworks(networks);
84 void IRCNetworkSelectionBox::editCurrentNetwork()
87 if (!network.isValid())
89 QMessageBox::critical(
this, tr(
"Doomseeker - edit IRC network"),
90 tr(
"Cannot edit as no valid network is selected."));
94 if (dialog.exec() == QDialog::Accepted)
97 if (replaceNetworkInConfig(network, editedNetwork))
98 updateCurrentNetwork(editedNetwork);
102 void IRCNetworkSelectionBox::fetchNetworks()
105 QList<IRCNetworkEntity> networks = cfg.networks();
106 std::sort(networks.begin(), networks.end());
107 d->cboNetwork->blockSignals(
true);
108 d->cboNetwork->clear();
112 addNetworkToComboBox(network);
116 if (lastUsedNetwork.isValid())
117 setNetworkMatchingDescriptionAsCurrent(lastUsedNetwork.
description());
120 d->cboNetwork->blockSignals(
false);
123 void IRCNetworkSelectionBox::initWidgets()
125 d->leAlternateNick->setText(gIRCConfig.personal.alternativeNickname);
126 d->leNick->setText(gIRCConfig.personal.nickname);
127 d->leRealName->setText(gIRCConfig.personal.fullName);
128 d->leUserName->setText(gIRCConfig.personal.userName);
136 networkEntity.setPassword(d->lePassword->text());
137 return networkEntity;
140 void IRCNetworkSelectionBox::networkChanged(
int index)
148 return networkAtRow(d->cboNetwork->currentIndex());
153 if (row < 0 || row >= d->cboNetwork->count())
155 return IRCNetworkEntity::deserializeQVariant(d->cboNetwork->itemData(row));
163 outInfo.
nick = d->leNick->text();
164 outInfo.
realName = d->leRealName->text();
165 outInfo.
userName = d->leUserName->text();
172 void IRCNetworkSelectionBox::setNetworkMatchingDescriptionAsCurrent(
const QString &description)
174 for (
int row = 0; row < d->cboNetwork->count(); ++row)
179 d->cboNetwork->setCurrentIndex(row);
185 void IRCNetworkSelectionBox::updateCurrentNetwork(
const IRCNetworkEntity &network)
187 d->cboNetwork->setItemText(d->cboNetwork->currentIndex(), buildTitle(network));
188 d->cboNetwork->setItemData(d->cboNetwork->currentIndex(), network.serializeQVariant());
192 void IRCNetworkSelectionBox::removeCurrentNetwork()
195 if (!network.isValid())
197 QMessageBox::critical(
this, tr(
"Doomseeker - remove IRC network"),
198 tr(
"Cannot remove as no valid network is selected."));
201 if (QMessageBox::question(
this, tr(
"Doomseeker - remove IRC network"),
202 tr(
"Are you sure you wish to remove network '%1'?").arg(network.
description()),
203 QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
217 void IRCNetworkSelectionBox::updateNetworkInfo()
221 d->leServerAddress->setText(network.
address());
222 d->spinPort->setValue(network.
port());
223 d->lePassword->setText(network.
password());
226 bool IRCNetworkSelectionBox::validate()
228 const static QString ERROR_TITLE = tr(
"IRC connection error");
231 if (connectionInfo.
nick.isEmpty())
233 QMessageBox::warning(
nullptr, ERROR_TITLE, tr(
"You must specify a nick."));
239 QMessageBox::warning(
nullptr, ERROR_TITLE, tr(
"You must specify a network address."));