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()
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."));
QString userName
User name sent in /user command.
QString alternateNick
Alternate nickname in case if ' nick ' is taken when connecting.
unsigned short port() const
Port of the server or network to connect to.
const QString & description() const
A short, human-readable description for the network. (Preferably a single word).
IRCNetworkEntity network() const
Extracts network specified in this dialog.
QString nick
Original nickname. This variable will always store the current nickname of the client.
Struct containing information about client's connection to the IRC server.
bool replaceNetwork(const QString &oldDescription, const IRCNetworkEntity &newNetwork, QWidget *errorDisplayParentWidget)
Replace network definition in config and move around log files.
QString realName
User's real name. Optional.
IRCNetworkEntity networkEntity
Information about the network to which we will connect.
Data structure that describes and defines a connection to an IRC network or server.
void removeNetwork(const IRCNetworkEntity &network)
Remove network definition from config.
const QString & password() const
Password for the server or network. Ignored if empty.
const QString & address() const
Address of the server or network to connect to.