bin_lgconfig_SOURCES = \
src/lgconfig/lgconfig.cpp \
src/lgconfig/lgconfig.moc.cpp \
- src/lgconfig/AddNodeDialog.cpp
+ src/lgconfig/AddNodeDialog.cpp \
+ src/lgconfig/NodeListDialog.cpp \
+ src/lgconfig/NodeListDialog.moc.cpp
bin_lgconfig_CPPFLAGS = $(bin_lgconfig_CFLAGS)
bin_lgconfig_LDADD = $(bin_lgconfig_LIBS) -lconfig++
bin_logedit_HEADERS = \
src/lgconfig/lgconfig.h \
src/lgconfig/ui/VLPConfigWindow.h \
- src/lgconfig/ui/dialogs/AddNodeDialog.h
+ src/lgconfig/ui/dialogs/AddNodeDialog.h \
+ src/lgconfig/ui/dialogs/NodeListDialog.h
src/lgconfig/lgconfig.moc.cpp: \
src/lgconfig/ui/VLPConfigWindow.h \
- src/lgconfig/ui/dialogs/AddNodeDialog.h
+ src/lgconfig/ui/dialogs/AddNodeDialog.h \
+ src/lgconfig/ui/dialogs/NodeListDialog.h
$(MOC) src/lgconfig/lgconfig.h -o src/lgconfig/lgconfig.moc.cpp
+src/lgconfig/NodeListDialog.moc.cpp: \
+ src/lgconfig/ui/dialogs/NodeListDialog.h
+ $(MOC) src/lgconfig/NodeListDialog.h -o src/lgconfig/NodeListDialog.moc.cpp
+
src/lgconfig/ui/VLPConfigWindow.h:
uic src/lgconfig/ui/VLPConfigWindow.ui -o src/lgconfig/ui/VLPConfigWindow.h
src/lgconfig/ui/dialogs/AddNodeDialog.h:
uic src/lgconfig/ui/dialogs/AddNodeDialog.ui -o src/lgconfig/ui/dialogs/AddNodeDialog.h
+src/lgconfig/ui/dialogs/NodeListDialog.h:
+ uic src/lgconfig/ui/dialogs/NodeListDialog.ui -o src/lgconfig/ui/dialogs/NodeListDialog.h
+
clean-lgconfig-extra:
rm -f src/lgconfig/*.moc.cpp
rm -f src/lgconfig/ui/*.h
--- /dev/null
+#include <QtGui/QListWidgetItem>
+#include <QtGui/QMessageBox>
+
+#include "lgconfig.h" /* VLPEntry */
+#include "NodeListDialog.h"
+#include "AddNodeDialog.h"
+
+namespace loglan {
+namespace vlp {
+namespace dialog {
+
+NodeListDialog::NodeListDialog(QList<VLPEntry*> *nodes, QWidget * parent)
+ : QDialog(parent)
+{
+ setupUi(this);
+
+ _nodes = nodes;
+
+ connect(saveButton, SIGNAL(clicked()), this, SLOT(accept()));
+ connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
+}
+
+NodeListDialog::~NodeListDialog()
+{
+}
+
+bool NodeListDialog::check_id(int id)
+{
+ QListIterator<VLPEntry *> nodesIterator(*_nodes);
+ VLPEntry *node = NULL;
+
+ while (nodesIterator.hasNext()) {
+ node = nodesIterator.next();
+ if (node->ID == id)
+ return false;
+ }
+ return true;
+}
+
+bool NodeListDialog::check_addr(QString addr)
+{
+ QListIterator<VLPEntry *> nodesIterator(*_nodes);
+ VLPEntry *node = NULL;
+
+ while (nodesIterator.hasNext()) {
+ node = nodesIterator.next();
+ if (node->addr == addr)
+ return false;
+ }
+ return true;
+}
+
+void NodeListDialog::on_addButton_clicked()
+{
+ dialog::AddNodeDialog dialog(this);
+
+ if (dialog.exec()) {
+ int nodeId = dialog.getNodeNumber();
+ QString ipAddress = dialog.getIPAddress();
+ if (check_id(nodeId)) {
+ if (check_addr(ipAddress)) {
+
+ VLPEntry *vlpEntry = new VLPEntry;
+ vlpEntry->ID = nodeId;
+ if (dialog.getConnectionType() == "Explicit") {
+ vlpEntry->type = 0;
+ }
+ strcpy(vlpEntry->addr, ipAddress.toStdString().c_str());
+ strcpy(vlpEntry->progdir, dialog.getProgramsDirectory().toStdString().c_str());
+ strcpy(vlpEntry->homedir, dialog.getVLPDirectory().toStdString().c_str());
+
+ QString info;
+ info.sprintf("Node: %d\tAddr: %s\tHome dir: %s",
+ vlpEntry->ID,
+ vlpEntry->addr,
+ vlpEntry->homedir
+ );
+
+ strcpy(vlpEntry->item, info.toStdString().c_str());
+
+ QListWidgetItem * listWidgetItem = new QListWidgetItem;
+ listWidgetItem->setText(info);
+ nodeList->addItem(listWidgetItem);
+ _nodes->append(vlpEntry);
+ }
+ 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 NodeListDialog::removeNodes(QList<QListWidgetItem *> selectedNodes)
+{
+ QListIterator<VLPEntry *> nodesIterator(*_nodes);
+
+ fprintf(stderr, " > Removing nodes\n");
+ for (auto selectedItem : selectedNodes) {
+ fprintf(stderr, " > Selected item\n");
+ VLPEntry *node = NULL;
+ QString selectedNodeInfo = selectedItem->text();
+
+ while (nodesIterator.hasNext()) {
+ node = nodesIterator.next();
+ if (selectedNodeInfo == node->item) {
+ fprintf(stderr, " - found\n");
+ break;
+ }
+ }
+ if (node != NULL) {
+ fprintf(stderr, " - removed\n");
+ int row = nodeList->row(selectedItem);
+ delete nodeList->takeItem(row);
+ _nodes->removeOne(node);
+ }
+ }
+}
+
+void NodeListDialog::on_deleteButton_clicked()
+{
+ if (nodeList->selectedItems().size() > 0) {
+ if (QMessageBox::question(this,
+ "Delete VLP",
+ "Are you sure?",
+ QMessageBox::Ok | QMessageBox::Cancel
+ ) == QMessageBox::Ok) {
+ removeNodes(nodeList->selectedItems());
+ }
+ }
+}
+
+void NodeListDialog::on_saveButton_clicked()
+{
+
+}
+
+void NodeListDialog::on_cancelButton_clicked()
+{
+}
+
+
+}
+}
+}
--- /dev/null
+#ifndef _VLP_LGCONFIG_NODELISTDIALOG_H
+#define _VLP_LGCONFIG_NODELISTDIALOG_H
+
+#include <QtGui/QDialog>
+#include <QtCore/QString>
+#include <QtCore/QList>
+
+#include "lgconfig.h" /* VLPEntry */
+
+#include "ui/dialogs/NodeListDialog.h"
+
+namespace loglan {
+namespace vlp {
+namespace dialog {
+
+/**
+ * Program Node List Dialog class
+ * Displays dialog for configuring nodes
+ */
+class NodeListDialog : public QDialog, private Ui::NodeListDialog {
+ Q_OBJECT
+private:
+ QList<VLPEntry*> *_nodes;
+public:
+ /**
+ * Class constructor
+ *
+ * @param nodes actual list of nodes to init dialog with
+ * @param parent parent widget for this dialog
+ */
+ NodeListDialog(QList<VLPEntry*> *nodes, QWidget * parent = 0);
+
+ /**
+ * Class destuctor
+ */
+ ~NodeListDialog();
+
+ /**
+ * Checks if node with specified id already exists
+ *
+ * @param id ID of the node to search for
+ * @return true if node with specified ID has been found, false otherwise
+ */
+ bool check_id(int id);
+
+ /**
+ * Checks if node with specified address already exists
+ *
+ * @param addr address of the node to search for
+ * @return true if node with specified address has been found, false otherwise
+ */
+ bool check_addr(QString addr);
+
+private:
+ /**
+ * Removes list of nodes from the list widget
+ */
+ void removeNodes(QList<QListWidgetItem *> selectedNodes);
+
+private slots:
+ void on_addButton_clicked();
+ void on_deleteButton_clicked();
+ void on_saveButton_clicked();
+ void on_cancelButton_clicked();
+};
+
+}
+}
+}
+
+#endif /* _VLP_EDITOR_PROGRAMSTRUCTUREDIALOG_H */
#include <QtGui/QToolTip>
#include <QtGui/QFont>
#include <QtGui/QPixmap>
-#include <QtGui/QMessageBox>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <libconfig.h>
#include "lgconfig.h"
-#include "AddNodeDialog.h"
+#include "NodeListDialog.h"
namespace loglan {
namespace vlp {
Nodes.clear();
}
-bool QInstall::check_id(int id)
-{
- QListIterator<VLPEntry *> nodesIterator(Nodes);
- VLPEntry *node = NULL;
-
- while (nodesIterator.hasNext()) {
- node = nodesIterator.next();
- if (node->ID == id)
- return false;
- }
- return true;
-}
-
-bool QInstall::check_addr(QString addr)
-{
- QListIterator<VLPEntry *> nodesIterator(Nodes);
- VLPEntry *node = NULL;
-
- while (nodesIterator.hasNext()) {
- node = nodesIterator.next();
- if (node->addr == addr)
- return false;
- }
- return true;
-}
-
-void QInstall::AddNode()
-{
- dialog::AddNodeDialog dialog(this);
-
- if (dialog.exec()) {
- 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;
- }
- strcpy(pom->addr, ipAddress.toStdString().c_str());
- strcpy(pom->progdir, dialog.getProgramsDirectory().toStdString().c_str());
- strcpy(pom->homedir, dialog.getVLPDirectory().toStdString().c_str());
-
- QString info;
- info.sprintf("Node: %d\tAddr: %s\tHome dir: %s",
- pom->ID,
- pom->addr,
- pom->homedir
- );
-
- strcpy(pom->item, info.toStdString().c_str());
-
- nodelist->insertItem(info);
- Nodes.append(pom);
- }
- 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()
-{
- if (nodelist->currentItem() >= 0) {
- VLPEntry *node = NULL;
- QString currentNodeInfo = nodelist->text(nodelist->currentItem());
-
- QListIterator<VLPEntry *> nodesIterator(Nodes);
-
- while (nodesIterator.hasNext()) {
- node = nodesIterator.next();
- if (currentNodeInfo == node->item) {
- break;
- }
- }
-
- if (node != NULL) {
- if (QMessageBox::question(this,
- "Delete VLP",
- "Are you sure?",
- QMessageBox::Ok | QMessageBox::Cancel
- ) == QMessageBox::Ok) {
- nodelist->removeItem(nodelist->currentItem());
- Nodes.removeOne(node);
- }
- }
- }
-}
-
void QInstall::on_actionConfigure_triggered()
{
- QDialog dlg(this);
- QLabel *tmpQLabel;
- QPushButton *addbtn, *delbtn, *okbtn, *cancelbtn;
+ dialog::NodeListDialog dialog(&Nodes, this);
+
VLPEntry *pom;
int i;
char pomstr[255];
- //dlg.setStyle(WindowsStyle);
- nodelist = new Q3ListBox(&dlg);
- nodelist->setGeometry(20, 40, 480, 160);
-
- tmpQLabel = new QLabel(&dlg);
- tmpQLabel->setGeometry(20, 10, 100, 30);
- tmpQLabel->setText("Nodes:");
-
- addbtn = new QPushButton(&dlg);
- addbtn->setGeometry(30, 210, 100, 30);
- addbtn->setText("Add VLP");
- connect(addbtn, SIGNAL(clicked()), this, SLOT(AddNode()));
-
- delbtn = new QPushButton(&dlg);
- delbtn->setGeometry(150, 210, 100, 30);
- delbtn->setText("Del VLP");
- connect(delbtn, SIGNAL(clicked()), this, SLOT(DelNode()));
-
- okbtn = new QPushButton(&dlg);
- okbtn->setGeometry(270, 210, 100, 30);
- okbtn->setText("Save files");
- connect(okbtn, SIGNAL(clicked()), &dlg, SLOT(accept()));
-
- cancelbtn = new QPushButton(&dlg);
- cancelbtn->setGeometry(390, 210, 100, 30);
- cancelbtn->setText("Cancel");
- connect(cancelbtn, SIGNAL(clicked()), &dlg, SLOT(reject()));
-
- dlg.resize(520, 260);
-
- if (dlg.exec()) {
+ if (dialog.exec()) {
if (!Nodes.isEmpty()) {
QListIterator<VLPEntry *> nodesIterator(Nodes);
class QInstall: public QMainWindow, private Ui::VLPConfigWindow {
Q_OBJECT
public:
- Q3ListBox *nodelist;
QList<VLPEntry*> Nodes;
/**
*/
QInstall();
- /**
- * Checks if node with specified id already exists
- *
- * @param id ID of the node to search for
- * @return true if node with specified ID has been found, false otherwise
- */
- bool check_id(int id);
-
- /**
- * Checks if node with specified address already exists
- *
- * @param addr address of the node to search for
- * @return true if node with specified address has been found, false otherwise
- */
- bool check_addr(QString addr);
-
-public slots:
- void AddNode();
- void DelNode();
-
private slots:
void on_actionConfigure_triggered();
void on_actionQuit_triggered();
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>NodeListDialog</class>
+ <widget class="QDialog" name="NodeListDialog">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>508</width>
+ <height>212</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Dialog</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_2">
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="QListWidget" name="nodeList">
+ <property name="minimumSize">
+ <size>
+ <width>400</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="selectionMode">
+ <enum>QAbstractItemView::MultiSelection</enum>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QPushButton" name="addButton">
+ <property name="text">
+ <string>Add</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="deleteButton">
+ <property name="text">
+ <string>Delete</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="saveButton">
+ <property name="text">
+ <string>Save</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="verticalSpacer">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QPushButton" name="cancelButton">
+ <property name="text">
+ <string>Cancel</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>