f3605f16d91c90c0c0c5531dcaf77ff1358a84f9
[vlp.git] / src / lgconfig / lgconfig.cpp
1 #include <QtGui/QApplication>
2 #include <QtGui/QMainWindow>
3 #include <Qt3Support/q3multilineedit.h>
4 #include <QtGui/QDialog>
5 #include <QtGui/QButtonGroup>
6 #include <QtGui/QLabel>
7 #include <QtGui/QLineEdit>
8 #include <Qt3Support/Q3ListBox>
9 #include <QtGui/QPushButton>
10 #include <QtGui/QRadioButton>
11 #include <QtCore/QList>
12 #include <QtCore/qfile.h>
13 #include <QtGui/qcombobox.h>
14 #include <QtGui/QToolTip>
15 #include <QtGui/QFont>
16 #include <QtGui/QPixmap>
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <unistd.h>
20
21 #include <libconfig.h>
22
23 #include "lgconfig.h"
24 #include "NodeListDialog.h"
25 #include "vlp/config.h"
26
27 namespace loglan {
28 namespace vlp {
29
30 QInstall::QInstall()
31 {
32         setupUi(this);
33
34         Nodes.clear();
35 }
36
37 void QInstall::on_actionConfigure_triggered()
38 {
39         dialog::NodeListDialog dialog(&Nodes, this);
40
41         if (dialog.exec()) {
42                 if (!Nodes.isEmpty()) {
43
44                         VLPEntry *pom;
45                         int i;
46                         char pomstr[255];
47
48                         QListIterator<VLPEntry *> nodesIterator(Nodes);
49
50                         while (nodesIterator.hasNext()) {
51                                 pom = nodesIterator.next();
52                                 i = Nodes.indexOf(pom);
53                                 sprintf(pomstr, "%s.cfg", pom->addr);
54
55                                 
56                                 loglan::vlp::Config config;
57
58                                 config.setProgramDir(pom->progdir);
59                                 config.setNodeNumber(pom->ID);
60                                 config.setConnectionType(
61                                         (pom->type == 0) ? EXPLICIT : REGISTER
62                                 );
63
64                                 std::vector<std::string> hosts;
65                                 for (auto node : Nodes) {
66                                         if (pom != node) {
67                                                 hosts.push_back(node->addr);
68                                         }
69                                 }
70                                 config.setHosts(hosts);
71
72                                 config.save(pomstr);
73
74 // TODO: add handling of homedir or remove it at all
75 //                              setting = config_setting_get_member(root, "homedir");
76 //                              if(!setting) {
77 //                                      setting = config_setting_add(root, "homedir", CONFIG_TYPE_STRING);
78 //                              }
79 //                              config_setting_set_string(setting, pom->homedir);
80
81
82                                 pom = Nodes.at(i);
83                         }
84                 }
85         }
86 }
87
88
89 void QInstall::on_actionQuit_triggered()
90 {
91         QApplication::instance()->quit();
92 }
93
94 }
95 }
96
97
98 int main(int argc, char **argv)
99 {
100         QApplication *app = new QApplication(argc,argv);
101         loglan::vlp::QInstall cfg;
102         cfg.show();
103         return app->exec();
104 }