-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapplication.cpp
More file actions
118 lines (100 loc) · 3.81 KB
/
application.cpp
File metadata and controls
118 lines (100 loc) · 3.81 KB
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
111
112
113
114
115
116
117
118
#include "application.h"
#include "ui_application.h"
#include "button.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
//初始化
this->setWindowTitle("rainstorm");
this->button_count = 0;
this->button_group = new QButtonGroup(this);
this->profile = new ProFileA(PROFILE_NAME);
//菜单栏
QMenuBar* menu_bar = new QMenuBar(this);
QMenu* menu = menu_bar->addMenu("管理");
//全部开启
QAction *power_on_all = menu->addAction("全部开启");
connect(power_on_all, &QAction::triggered, this, &MainWindow::PowerOnAllVirtualMachine);
//全部关闭
QAction *power_off_all = menu->addAction("全部关闭");
connect(power_off_all, &QAction::triggered, this, &MainWindow::PowerOffAllViatualMachine);
//添加虚拟机
QAction *add_virtual_machine = menu->addAction("添加虚拟机");
connect(add_virtual_machine, &QAction::triggered, this, &MainWindow::AddVirtualMachine);
this->setMenuBar(menu_bar);
//加载配置文件
std::list<std::string> sections = this->profile->ReadPrivateProfileSectionNames();
for(std::string §ion : sections)
{
std::map<std::string, std::string> res = this->profile->ReadProfileSectionsA(section);
std::string path = res["FilePath"];
std::string host = res["Host"];
std::string port = res["Port"];
//创建按钮
VirtualMachineControl *contorl = new VirtualMachineControl(path.c_str(), this);
ui->stackedWidget->addWidget(contorl);
Button *button = new Button(contorl, path.c_str(), section.c_str(), host.c_str(), port.c_str(), ui, this);
connect(button, &QPushButton::clicked, this, &MainWindow::SwitchVirtualMachine);
ui->verticalLayout->addWidget(button, this->button_count);
ui->verticalLayout->addStretch();
this->button_group->addButton(button);
this->button_count++;
}
return;
}
MainWindow::~MainWindow()
{
delete ui;
delete profile;
}
void MainWindow::AddVirtualMachine()
{
//打开对话框
Dialog dialog(this);
dialog.setWindowTitle("添加");
dialog.exec();
if(dialog.Legal()){
QString path = dialog.GetPath();
QString name = path.section("/", -1).section(".", 0, 0);
QString host = dialog.GetHost();
QString port = dialog.GetPort();
//保存配置文件
this->profile->WriteProfileStringsA(name.toLatin1().data(), "FilePath", path.toLatin1().data());
this->profile->WriteProfileStringsA(name.toLatin1().data(), "Host", host.toLatin1().data());
this->profile->WriteProfileStringsA(name.toLatin1().data(), "Port", port.toLatin1().data());
//创建按钮
VirtualMachineControl *contorl = new VirtualMachineControl(path, this);
ui->stackedWidget->addWidget(contorl);
Button *button = new Button(contorl, path, name, host, port, ui, this);
connect(button, &QPushButton::clicked, this, &MainWindow::SwitchVirtualMachine);
this->button_group->addButton(button);
ui->verticalLayout->addWidget(button, this->button_count);
this->button_count++;
}
ui->statusbar->showMessage("添加成功", 3000);
return;
}
void MainWindow::PowerOnAllVirtualMachine()
{
for(QWidget* item: this->button_group->buttons()){
Button *button = static_cast<Button*>(item);
button->PowerOnVirtualMachine();
}
return;
}
void MainWindow::PowerOffAllViatualMachine()
{
for(QWidget* item: this->button_group->buttons()){
Button *button = static_cast<Button*>(item);
button->PowerOffVirtualMachine();
}
return;
}
void MainWindow::SwitchVirtualMachine()
{
Button *btn = static_cast<Button *>(sender());
ui->stackedWidget->setCurrentWidget(btn->m_control);
return;
}