-
Notifications
You must be signed in to change notification settings - Fork 12
/
DlgCreatePeer.h
110 lines (100 loc) · 3.42 KB
/
DlgCreatePeer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#ifndef DLGCREATEPEER_H
#define DLGCREATEPEER_H
#include <QDebug>
#include <QDialog>
#include <QObject>
#include <QtConcurrent/QtConcurrent>
#include "DlgNotification.h"
#include "SystemCallWrapper.h"
namespace Ui {
class DlgCreatePeer;
}
// This structure 'requirement' needed to check requirements for peer creataion
// how to use:
// status label = 'Checking the VirtualBox'
// error_notification = 'VirtualBox is not installed please install it from
// Components' notification_type = N_N_ABOUT error_label: 'virtualbox is not
// istalled'
struct requirement {
QString error_label;
QString status_label;
QString error_notification;
DlgNotification::NOTIFICATION_ACTION_TYPE notification_type;
bool (*checker_function)();
requirement(QString _error_label, QString _status_label,
QString _error_notification,
DlgNotification::NOTIFICATION_ACTION_TYPE _notification_type,
bool (*_checker_function)()) {
error_label = _error_label;
status_label = _status_label;
error_notification = _error_notification;
notification_type = _notification_type;
checker_function = _checker_function;
}
~requirement() {}
};
class DlgCreatePeer : public QDialog {
Q_OBJECT
public:
explicit DlgCreatePeer(QWidget *parent = nullptr);
~DlgCreatePeer();
QString create_dir(const QString &name);
QString peer_dir(const QString &name);
enum pass_err {
PASS_EMPTY = 0, // when empty password
PASS_SMALL, // when too small
PASS_INVALID, // when contains invalid symbols
PASS_FINE
};
bool m_password_state, m_password_confirm_state;
const QString BASE_PEER_FOLDER = "Subutai-peers";
private:
Ui::DlgCreatePeer *ui;
QAction *m_show_confirm_password_action;
QAction *m_show_password_action;
pass_err check_pass(QString pass);
void hide_err_labels();
void set_enabled_buttons(bool state);
void init_completed(system_call_wrapper_error_t res, QString dir, QString ram,
QString cpu, QString disk, int port);
bool check_configurations();
bool check_machine();
int reserve_new_port();
QRegExp m_invalid_chars;
std::vector<requirement> m_requirements_ls;
public slots:
void create_button_pressed();
};
// init peer executer
class InitPeer : public QObject {
Q_OBJECT
QString directory;
QString OS;
public:
InitPeer(QObject *parent = nullptr) : QObject(parent) {}
void init(const QString &directory, const QString &OS) {
this->directory = directory;
this->OS = OS;
}
void startWork() {
QThread *thread = new QThread();
connect(thread, &QThread::started, this, &InitPeer::execute_remote_command);
connect(this, &InitPeer::outputReceived, thread, &QThread::quit);
connect(thread, &QThread::finished, this, &InitPeer::deleteLater);
connect(thread, &QThread::finished, thread, &QThread::deleteLater);
this->moveToThread(thread);
thread->start();
}
void execute_remote_command() {
QFutureWatcher<system_call_wrapper_error_t> *watcher =
new QFutureWatcher<system_call_wrapper_error_t>(this);
QFuture<system_call_wrapper_error_t> res =
QtConcurrent::run(CSystemCallWrapper::vagrant_init, directory, OS);
connect(watcher, &QFutureWatcher<system_call_wrapper_error_t>::finished,
[this, res]() { emit this->outputReceived(res.result()); });
watcher->setFuture(res);
}
signals:
void outputReceived(system_call_wrapper_error_t res);
};
#endif // DLGCREATEPEER_H