Code formatting of lgconfig
authorRafał Długołęcki <rafal@dlugolecki.net.pl>
Sat, 30 Jan 2016 00:47:12 +0000 (01:47 +0100)
committerRafał Długołęcki <rafal@dlugolecki.net.pl>
Sat, 30 Jan 2016 00:47:12 +0000 (01:47 +0100)
src/lgconfig/lgconfig.cpp
src/lgconfig/lgconfig.h

index f167848b5af6e8dd61ff1e31d90168b26fbe60d4..b8036db4797d5ba8163eccb1edbb22af1b6608fe 100644 (file)
@@ -36,85 +36,96 @@ QInstall::QInstall()
 
 bool QInstall::check_id(int id)
 {
-       VLPEntry *node;
        QListIterator<VLPEntry *> 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<VLPEntry *> 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<VLPEntry *> 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<VLPEntry *> nodesIterator(Nodes);
-                       
+
                        while (nodesIterator.hasNext()) {
                                pom = nodesIterator.next();
                                i = Nodes.indexOf(pom);
index 4036391e1e7fbcc62828f82a592a2ace619fd0f4..bdd2ae24fa39cd360fb7638c778409576eae81df 100644 (file)
@@ -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();