23 #include "ircnetworkselectionbox.h" 24 #include "ui_ircnetworkselectionbox.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 "qtmetapointer.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()
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))
99 updateCurrentNetwork(editedNetwork);
104 void IRCNetworkSelectionBox::fetchNetworks()
107 QList<IRCNetworkEntity> networks = cfg.networks();
109 d->cboNetwork->blockSignals(
true);
110 d->cboNetwork->clear();
114 addNetworkToComboBox(network);
118 if (lastUsedNetwork.isValid())
120 setNetworkMatchingDescriptionAsCurrent(lastUsedNetwork.
description());
124 d->cboNetwork->blockSignals(
false);
127 void IRCNetworkSelectionBox::initWidgets()
129 d->leAlternateNick->setText(gIRCConfig.personal.alternativeNickname);
130 d->leNick->setText(gIRCConfig.personal.nickname);
131 d->leRealName->setText(gIRCConfig.personal.fullName);
132 d->leUserName->setText(gIRCConfig.personal.userName);
140 networkEntity.setPassword(d->lePassword->text());
141 return networkEntity;
144 void IRCNetworkSelectionBox::networkChanged(
int index)
154 return networkAtRow(d->cboNetwork->currentIndex());
159 if (row < 0 || row >= d->cboNetwork->count())
163 return IRCNetworkEntity::deserializeQVariant(d->cboNetwork->itemData(row));
171 outInfo.
nick = d->leNick->text();
172 outInfo.
realName = d->leRealName->text();
173 outInfo.
userName = d->leUserName->text();
180 void IRCNetworkSelectionBox::setNetworkMatchingDescriptionAsCurrent(
const QString &description)
182 for (
int row = 0; row < d->cboNetwork->count(); ++row)
187 d->cboNetwork->setCurrentIndex(row);
193 void IRCNetworkSelectionBox::updateCurrentNetwork(
const IRCNetworkEntity &network)
195 d->cboNetwork->setItemText(d->cboNetwork->currentIndex(), buildTitle(network));
196 d->cboNetwork->setItemData(d->cboNetwork->currentIndex(), network.serializeQVariant());
200 void IRCNetworkSelectionBox::removeCurrentNetwork()
203 if (!network.isValid())
205 QMessageBox::critical(
this, tr(
"Doomseeker - remove IRC network"),
206 tr(
"Cannot remove as no valid network is selected."));
209 if (QMessageBox::question(
this, tr(
"Doomseeker - remove IRC network"),
210 tr(
"Are you sure you wish to remove network '%1'?").arg(network.
description()),
211 QMessageBox::Yes | QMessageBox::No)
226 void IRCNetworkSelectionBox::updateNetworkInfo()
230 d->leServerAddress->setText(network.
address());
231 d->spinPort->setValue(network.
port());
232 d->lePassword->setText(network.
password());
235 bool IRCNetworkSelectionBox::validate()
237 const static QString ERROR_TITLE = tr(
"IRC connection error");
240 if (connectionInfo.
nick.isEmpty())
242 QMessageBox::warning(NULL, ERROR_TITLE, tr(
"You must specify a nick."));
248 QMessageBox::warning(NULL, 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.