disconnectedIcon = QIcon(":/22x22/actions/network-disconnect");
currentId = 0;
- setEnabled(false); // need a core connection!
+ setEnabled(Client::isConnected()); // need a core connection!
setWidgetStates();
connect(Client::instance(), SIGNAL(coreConnectionStateChanged(bool)), this, SLOT(coreConnectionStateChanged(bool)));
connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), this, SLOT(clientNetworkAdded(NetworkId)));
}
void NetworksSettingsPage::setItemState(NetworkId id, QListWidgetItem *item) {
- if(!item) item = networkItem(id);
+ if(!item && !(item = networkItem(id))) return;
const Network *net = Client::network(id);
if(!net || net->isInitialized()) item->setFlags(item->flags() | Qt::ItemIsEnabled);
else item->setFlags(item->flags() & ~Qt::ItemIsEnabled);
item->setIcon(disconnectedIcon);
}
if(net) {
+ bool select = false;
// check if we already have another net of this name in the list, and replace it
QList<QListWidgetItem *> items = ui.networkList->findItems(net->networkName(), Qt::MatchExactly);
if(items.count()) {
foreach(QListWidgetItem *i, items) {
NetworkId oldid = i->data(Qt::UserRole).value<NetworkId>();
if(oldid > 0) continue; // only locally created nets should be replaced
- if(oldid == currentId) item->setSelected(true);
- delete ui.networkList->takeItem(ui.networkList->row(i));
+ if(oldid == currentId) select = true;
+ int row = ui.networkList->row(i);
+ if(row >= 0) delete ui.networkList->takeItem(row);
networkInfos.remove(oldid);
break;
}
}
item->setText(net->networkName());
+ if(select) item->setSelected(true);
}
}
void NetworksSettingsPage::on_addNetwork_clicked() {
QStringList existing;
for(int i = 0; i < ui.networkList->count(); i++) existing << ui.networkList->item(i)->text();
- NetworkEditDlgNew dlg(QString(), existing, this);
+ NetworkEditDlg dlg(QString(), existing, this);
if(dlg.exec() == QDialog::Accepted) {
NetworkId id;
for(id = 1; id <= networkInfos.count(); id++) {
if(ui.networkList->selectedItems().count()) {
NetworkId netid = ui.networkList->selectedItems()[0]->data(Qt::UserRole).value<NetworkId>();
int ret = QMessageBox::question(this, tr("Delete Network?"),
- tr("Do you really want to delete the network \"%1\" and all related settings, including the backlog?"
- "<br><br><em>NOTE: Backlog deletion hasn't actually been implemented yet.</em>").arg(networkInfos[netid].networkName),
+ tr("Do you really want to delete the network \"%1\" and all related settings, including the backlog?").arg(networkInfos[netid].networkName),
QMessageBox::Yes|QMessageBox::No, QMessageBox::No);
if(ret == QMessageBox::Yes) {
currentId = 0;
QString old = ui.networkList->selectedItems()[0]->text();
QStringList existing;
for(int i = 0; i < ui.networkList->count(); i++) existing << ui.networkList->item(i)->text();
- NetworkEditDlgNew dlg(old, existing, this);
+ NetworkEditDlg dlg(old, existing, this);
if(dlg.exec() == QDialog::Accepted) {
ui.networkList->selectedItems()[0]->setText(dlg.networkName());
NetworkId netid = ui.networkList->selectedItems()[0]->data(Qt::UserRole).value<NetworkId>();
void NetworksSettingsPage::on_addServer_clicked() {
if(currentId == 0) return;
- ServerEditDlgNew dlg(QVariantMap(), this);
+ ServerEditDlg dlg(QVariantMap(), this);
if(dlg.exec() == QDialog::Accepted) {
networkInfos[currentId].serverList.append(dlg.serverData());
displayNetwork(currentId);
void NetworksSettingsPage::on_editServer_clicked() {
if(currentId == 0) return;
int cur = ui.serverList->currentRow();
- ServerEditDlgNew dlg(networkInfos[currentId].serverList[cur], this);
+ ServerEditDlg dlg(networkInfos[currentId].serverList[cur], this);
if(dlg.exec() == QDialog::Accepted) {
networkInfos[currentId].serverList[cur] = dlg.serverData();
displayNetwork(currentId);
* NetworkEditDlg
*************************************************************************/
-NetworkEditDlgNew::NetworkEditDlgNew(const QString &old, const QStringList &exist, QWidget *parent) : QDialog(parent), existing(exist) {
+NetworkEditDlg::NetworkEditDlg(const QString &old, const QStringList &exist, QWidget *parent) : QDialog(parent), existing(exist) {
ui.setupUi(this);
if(old.isEmpty()) {
} else ui.networkEdit->setText(old);
}
-QString NetworkEditDlgNew::networkName() const {
+QString NetworkEditDlg::networkName() const {
return ui.networkEdit->text();
}
-void NetworkEditDlgNew::on_networkEdit_textChanged(const QString &text) {
+void NetworkEditDlg::on_networkEdit_textChanged(const QString &text) {
ui.buttonBox->button(QDialogButtonBox::Ok)->setDisabled(text.isEmpty() || existing.contains(text));
}
* ServerEditDlg
*************************************************************************/
-ServerEditDlgNew::ServerEditDlgNew(const QVariant &_serverData, QWidget *parent) : QDialog(parent) {
+ServerEditDlg::ServerEditDlg(const QVariant &_serverData, QWidget *parent) : QDialog(parent) {
ui.setupUi(this);
QVariantMap serverData = _serverData.toMap();
if(serverData.count()) {
ui.password->setText(serverData["Password"].toString());
ui.useSSL->setChecked(serverData["UseSSL"].toBool());
} else {
- ui.port->setValue(Global::defaultPort);
+ ui.port->setValue(6667);
}
on_host_textChanged();
}
-QVariant ServerEditDlgNew::serverData() const {
+QVariant ServerEditDlg::serverData() const {
QVariantMap _serverData;
_serverData["Host"] = ui.host->text();
_serverData["Port"] = ui.port->value();
return _serverData;
}
-void ServerEditDlgNew::on_host_textChanged() {
+void ServerEditDlg::on_host_textChanged() {
ui.buttonBox->button(QDialogButtonBox::Ok)->setDisabled(ui.host->text().isEmpty());
}