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 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->clear();
113 addNetworkToComboBox(network);
117 if (lastUsedNetwork.isValid())
119 setNetworkMatchingDescriptionAsCurrent(lastUsedNetwork.
description());
125 void IRCNetworkSelectionBox::initWidgets()
127 d->leAlternateNick->setText(gIRCConfig.personal.alternativeNickname);
128 d->leNick->setText(gIRCConfig.personal.nickname);
129 d->leRealName->setText(gIRCConfig.personal.fullName);
137 networkEntity.setPassword(d->lePassword->text());
138 return networkEntity;
141 void IRCNetworkSelectionBox::networkChanged(
int index)
151 return networkAtRow(d->cboNetwork->currentIndex());
156 if (row < 0 || row >= d->cboNetwork->count())
160 return IRCNetworkEntity::deserializeQVariant(d->cboNetwork->itemData(row));
168 outInfo.
nick = d->leNick->text();
169 outInfo.
realName = d->leRealName->text();
176 void IRCNetworkSelectionBox::setNetworkMatchingDescriptionAsCurrent(
const QString &description)
178 for (
int row = 0; row < d->cboNetwork->count(); ++row)
183 d->cboNetwork->setCurrentIndex(row);
189 void IRCNetworkSelectionBox::updateCurrentNetwork(
const IRCNetworkEntity &network)
191 d->cboNetwork->setItemText(d->cboNetwork->currentIndex(), buildTitle(network));
192 d->cboNetwork->setItemData(d->cboNetwork->currentIndex(), network.serializeQVariant());
202 void IRCNetworkSelectionBox::updateNetworkInfo()
206 d->leServerAddress->setText(network.
address());
207 d->spinPort->setValue(network.
port());
208 d->lePassword->setText(network.
password());
211 bool IRCNetworkSelectionBox::validate()
213 const static QString ERROR_TITLE = tr(
"IRC connection error");
216 if (connectionInfo.
nick.isEmpty())
218 QMessageBox::warning(NULL, ERROR_TITLE, tr(
"You must specify a nick."));
224 QMessageBox::warning(NULL, ERROR_TITLE, tr(
"You must specify a network address."));
unsigned short port() const
Port of the server or network to connect to.
Struct containing information about client's connection to the IRC server.
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.
IRCNetworkEntity networkEntity
Information about the network to which we will connect.
bool replaceNetwork(const QString &oldDescription, const IRCNetworkEntity &newNetwork, QWidget *errorDisplayParentWidget)
Replace network definition in config and move around log files.
Data structure that describes and defines a connection to an IRC network or server.
QString realName
User's real name. Optional.
const QString & password() const
Password for the server or network. Ignored if empty.
QString alternateNick
Alternate nickname in case if ' nick ' is taken when connecting.
const QString & address() const
Address of the server or network to connect to.
QString nick
Original nickname. This variable will always store the current nickname of the client.