23 #include "gui/configuration/irc/cfgircdefinenetworkdialog.h"
24 #include "irc/configuration/chatnetworkscfg.h"
25 #include "irc/configuration/ircconfig.h"
26 #include "irc/ircnetworkconnectioninfo.h"
27 #include "ircnetworkselectionbox.h"
28 #include "qtmetapointer.h"
29 #include "ui_ircnetworkselectionbox.h"
30 #include <QMessageBox>
32 DClass<IRCNetworkSelectionBox> :
public Ui::IRCNetworkSelectionBox
43 connect(d->cboNetwork, SIGNAL(currentIndexChanged(
int)), SLOT(networkChanged(
int)));
48 IRCNetworkSelectionBox::~IRCNetworkSelectionBox()
52 void IRCNetworkSelectionBox::accept()
58 void IRCNetworkSelectionBox::addNetworkToComboBox(
const IRCNetworkEntity &network)
60 d->cboNetwork->addItem(buildTitle(network), network.serializeQVariant());
63 QString IRCNetworkSelectionBox::buildTitle(
const IRCNetworkEntity &network)
const
68 void IRCNetworkSelectionBox::createNewNetwork()
71 if (dialog.exec() == QDialog::Accepted)
74 QList<IRCNetworkEntity> networks = cfg.networks();
75 networks << dialog.getNetworkEntity();
76 cfg.setNetworks(networks);
82 void IRCNetworkSelectionBox::editCurrentNetwork()
85 if (!network.isValid())
87 QMessageBox::critical(
this, tr(
"Doomseeker - edit IRC network"),
88 tr(
"Cannot edit as no valid network is selected."));
92 if (dialog.exec() == QDialog::Accepted)
95 if (replaceNetworkInConfig(network, editedNetwork))
96 updateCurrentNetwork(editedNetwork);
100 void IRCNetworkSelectionBox::fetchNetworks()
103 QList<IRCNetworkEntity> networks = cfg.networks();
104 std::sort(networks.begin(), networks.end());
105 d->cboNetwork->blockSignals(
true);
106 d->cboNetwork->clear();
110 addNetworkToComboBox(network);
114 if (lastUsedNetwork.isValid())
115 setNetworkMatchingDescriptionAsCurrent(lastUsedNetwork.
description());
118 d->cboNetwork->blockSignals(
false);
121 void IRCNetworkSelectionBox::initWidgets()
123 d->leAlternateNick->setText(gIRCConfig.personal.alternativeNickname);
124 d->leNick->setText(gIRCConfig.personal.nickname);
125 d->leRealName->setText(gIRCConfig.personal.fullName);
126 d->leUserName->setText(gIRCConfig.personal.userName);
134 networkEntity.setPassword(d->lePassword->text());
135 return networkEntity;
138 void IRCNetworkSelectionBox::networkChanged(
int index)
146 return networkAtRow(d->cboNetwork->currentIndex());
151 if (row < 0 || row >= d->cboNetwork->count())
153 return IRCNetworkEntity::deserializeQVariant(d->cboNetwork->itemData(row));
161 outInfo.
nick = d->leNick->text();
162 outInfo.
realName = d->leRealName->text();
163 outInfo.
userName = d->leUserName->text();
170 void IRCNetworkSelectionBox::setNetworkMatchingDescriptionAsCurrent(
const QString &description)
172 for (
int row = 0; row < d->cboNetwork->count(); ++row)
177 d->cboNetwork->setCurrentIndex(row);
183 void IRCNetworkSelectionBox::updateCurrentNetwork(
const IRCNetworkEntity &network)
185 d->cboNetwork->setItemText(d->cboNetwork->currentIndex(), buildTitle(network));
186 d->cboNetwork->setItemData(d->cboNetwork->currentIndex(), network.serializeQVariant());
190 void IRCNetworkSelectionBox::removeCurrentNetwork()
193 if (!network.isValid())
195 QMessageBox::critical(
this, tr(
"Doomseeker - remove IRC network"),
196 tr(
"Cannot remove as no valid network is selected."));
199 if (QMessageBox::question(
this, tr(
"Doomseeker - remove IRC network"),
200 tr(
"Are you sure you wish to remove network '%1'?").arg(network.
description()),
201 QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
215 void IRCNetworkSelectionBox::updateNetworkInfo()
219 d->leServerAddress->setText(network.
address());
220 d->spinPort->setValue(network.
port());
221 d->lePassword->setText(network.
password());
224 bool IRCNetworkSelectionBox::validate()
226 const static QString ERROR_TITLE = tr(
"IRC connection error");
229 if (connectionInfo.
nick.isEmpty())
231 QMessageBox::warning(
nullptr, ERROR_TITLE, tr(
"You must specify a nick."));
237 QMessageBox::warning(
nullptr, ERROR_TITLE, tr(
"You must specify a network address."));