From: Rafał Długołęcki Date: Sat, 30 Jan 2016 00:47:12 +0000 (+0100) Subject: Code formatting of lgconfig X-Git-Tag: 3.4-b1~15 X-Git-Url: https://git.dlugolecki.net.pl/?a=commitdiff_plain;h=c4807f0a3bb9f6cbcdbcb00f1d401b8d3a1c2b02;p=vlp.git Code formatting of lgconfig --- diff --git a/src/lgconfig/lgconfig.cpp b/src/lgconfig/lgconfig.cpp index f167848..b8036db 100644 --- a/src/lgconfig/lgconfig.cpp +++ b/src/lgconfig/lgconfig.cpp @@ -36,85 +36,96 @@ QInstall::QInstall() bool QInstall::check_id(int id) { - VLPEntry *node; QListIterator nodesIterator(Nodes); + VLPEntry *node = NULL; while (nodesIterator.hasNext()) { node = nodesIterator.next(); if (node->ID == id) - return FALSE; + return false; } - return TRUE; + return true; } -bool QInstall::check_addr(char *addr) +bool QInstall::check_addr(QString addr) { - VLPEntry *node; QListIterator nodesIterator(Nodes); + VLPEntry *node = NULL; while (nodesIterator.hasNext()) { node = nodesIterator.next(); - if (strcmp(node->addr, addr) == 0) - return FALSE; + if (node->addr == addr) + return false; } - return TRUE; + return true; } void QInstall::AddNode() { dialog::AddNodeDialog dialog(this); - VLPEntry *pom; - if (dialog.exec()) { - pom = new VLPEntry; - pom->ID = dialog.getNodeNumber(); - if (check_id(pom->ID)) { - strcpy(pom->addr, dialog.getIPAddress().toStdString().c_str()); - if (check_addr(pom->addr)) { + int nodeId = dialog.getNodeNumber(); + QString ipAddress = dialog.getIPAddress(); + if (check_id(nodeId)) { + if (check_addr(ipAddress)) { + + VLPEntry *pom = new VLPEntry; + pom->ID = nodeId; if (dialog.getConnectionType() == "Explicit") { - pom->type=0; + pom->type = 0; } + strcpy(pom->addr, ipAddress.toStdString().c_str()); strcpy(pom->progdir, dialog.getProgramsDirectory().toStdString().c_str()); strcpy(pom->homedir, dialog.getVLPDirectory().toStdString().c_str()); - Nodes.append(pom); QString info; info.sprintf("Node: %d\tAddr: %s\tHome dir: %s", - pom->ID, pom->addr, pom->homedir + pom->ID, + pom->addr, + pom->homedir ); - nodelist->insertItem(info); strcpy(pom->item, info.toStdString().c_str()); - } else { - QMessageBox::warning(this, "Error!", "Only one VLP on a single computer!", "Ok"); + + nodelist->insertItem(info); + Nodes.append(pom); } - } else { - QMessageBox::warning(this, "Error!", "ID must be unique!", "Ok"); + else { + QMessageBox::warning(this, "Error!", "Only one VLP on a single computer!", QMessageBox::Ok); + } + } + else { + QMessageBox::warning(this, "Error!", "ID must be unique!", QMessageBox::Ok); } } } void QInstall::DelNode() { - char pom[255]; - VLPEntry *vpom; - if (nodelist->currentItem() >= 0) { - strcpy(pom, nodelist->text(nodelist->currentItem()).toStdString().c_str()); + VLPEntry *node = NULL; + QString currentNodeInfo = nodelist->text(nodelist->currentItem()); QListIterator nodesIterator(Nodes); while (nodesIterator.hasNext()) { - vpom = nodesIterator.next(); - if (strcmp(pom, vpom->item) == 0) + node = nodesIterator.next(); + if (currentNodeInfo == node->item) { break; + } } - if (vpom != NULL) - if (QMessageBox::question(this, "Delete VLP", "Are you sure?", "Yes", "No")) { + + if (node != NULL) { + if (QMessageBox::question(this, + "Delete VLP", + "Are you sure?", + QMessageBox::Ok | QMessageBox::Cancel + ) == QMessageBox::Ok) { nodelist->removeItem(nodelist->currentItem()); - Nodes.removeOne(vpom); + Nodes.removeOne(node); } + } } } @@ -160,7 +171,7 @@ void QInstall::on_actionConfigure_triggered() if (dlg.exec()) { if (!Nodes.isEmpty()) { QListIterator nodesIterator(Nodes); - + while (nodesIterator.hasNext()) { pom = nodesIterator.next(); i = Nodes.indexOf(pom); diff --git a/src/lgconfig/lgconfig.h b/src/lgconfig/lgconfig.h index 4036391..bdd2ae2 100644 --- a/src/lgconfig/lgconfig.h +++ b/src/lgconfig/lgconfig.h @@ -49,7 +49,7 @@ public: * @param addr address of the node to search for * @return true if node with specified address has been found, false otherwise */ - bool check_addr(char * addr); + bool check_addr(QString addr); public slots: void AddNode();