add pause buttons
parent
91237df9bf
commit
4b94f9830d
|
|
@ -79,6 +79,7 @@ public:
|
||||||
void setCpus(int cpus) { m_cpus = cpus; }
|
void setCpus(int cpus) { m_cpus = cpus; }
|
||||||
int memory() const { return m_memory; }
|
int memory() const { return m_memory; }
|
||||||
void setMemory(int memory) { m_memory = memory; }
|
void setMemory(int memory) { m_memory = memory; }
|
||||||
|
bool isEmpty() { return m_name.isEmpty(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_name;
|
QString m_name;
|
||||||
|
|
|
||||||
154
gui/window.cpp
154
gui/window.cpp
|
|
@ -129,6 +129,7 @@ void Window::createBasicView()
|
||||||
{
|
{
|
||||||
basicStartButton = new QPushButton(tr("Start"));
|
basicStartButton = new QPushButton(tr("Start"));
|
||||||
basicStopButton = new QPushButton(tr("Stop"));
|
basicStopButton = new QPushButton(tr("Stop"));
|
||||||
|
basicPauseButton = new QPushButton(tr("Pause"));
|
||||||
basicDeleteButton = new QPushButton(tr("Delete"));
|
basicDeleteButton = new QPushButton(tr("Delete"));
|
||||||
basicRefreshButton = new QPushButton(tr("Refresh"));
|
basicRefreshButton = new QPushButton(tr("Refresh"));
|
||||||
basicSSHButton = new QPushButton(tr("SSH"));
|
basicSSHButton = new QPushButton(tr("SSH"));
|
||||||
|
|
@ -140,6 +141,7 @@ void Window::createBasicView()
|
||||||
catBox->setLayout(buttonLayout);
|
catBox->setLayout(buttonLayout);
|
||||||
buttonLayout->addWidget(basicStartButton);
|
buttonLayout->addWidget(basicStartButton);
|
||||||
buttonLayout->addWidget(basicStopButton);
|
buttonLayout->addWidget(basicStopButton);
|
||||||
|
buttonLayout->addWidget(basicPauseButton);
|
||||||
buttonLayout->addWidget(basicDeleteButton);
|
buttonLayout->addWidget(basicDeleteButton);
|
||||||
buttonLayout->addWidget(basicRefreshButton);
|
buttonLayout->addWidget(basicRefreshButton);
|
||||||
buttonLayout->addWidget(basicSSHButton);
|
buttonLayout->addWidget(basicSSHButton);
|
||||||
|
|
@ -152,6 +154,7 @@ void Window::createBasicView()
|
||||||
connect(basicDashboardButton, &QAbstractButton::clicked, this, &Window::dashboardBrowser);
|
connect(basicDashboardButton, &QAbstractButton::clicked, this, &Window::dashboardBrowser);
|
||||||
connect(basicStartButton, &QAbstractButton::clicked, this, &Window::startSelectedMinikube);
|
connect(basicStartButton, &QAbstractButton::clicked, this, &Window::startSelectedMinikube);
|
||||||
connect(basicStopButton, &QAbstractButton::clicked, this, &Window::stopMinikube);
|
connect(basicStopButton, &QAbstractButton::clicked, this, &Window::stopMinikube);
|
||||||
|
connect(basicPauseButton, &QAbstractButton::clicked, this, &Window::pauseOrUnpauseMinikube);
|
||||||
connect(basicDeleteButton, &QAbstractButton::clicked, this, &Window::deleteMinikube);
|
connect(basicDeleteButton, &QAbstractButton::clicked, this, &Window::deleteMinikube);
|
||||||
connect(basicRefreshButton, &QAbstractButton::clicked, this, &Window::updateClusters);
|
connect(basicRefreshButton, &QAbstractButton::clicked, this, &Window::updateClusters);
|
||||||
connect(advancedViewButton, &QAbstractButton::clicked, this, &Window::toAdvancedView);
|
connect(advancedViewButton, &QAbstractButton::clicked, this, &Window::toAdvancedView);
|
||||||
|
|
@ -177,6 +180,7 @@ void Window::createAdvancedView()
|
||||||
connect(dashboardButton, &QAbstractButton::clicked, this, &Window::dashboardBrowser);
|
connect(dashboardButton, &QAbstractButton::clicked, this, &Window::dashboardBrowser);
|
||||||
connect(startButton, &QAbstractButton::clicked, this, &Window::startSelectedMinikube);
|
connect(startButton, &QAbstractButton::clicked, this, &Window::startSelectedMinikube);
|
||||||
connect(stopButton, &QAbstractButton::clicked, this, &Window::stopMinikube);
|
connect(stopButton, &QAbstractButton::clicked, this, &Window::stopMinikube);
|
||||||
|
connect(pauseButton, &QAbstractButton::clicked, this, &Window::pauseOrUnpauseMinikube);
|
||||||
connect(deleteButton, &QAbstractButton::clicked, this, &Window::deleteMinikube);
|
connect(deleteButton, &QAbstractButton::clicked, this, &Window::deleteMinikube);
|
||||||
connect(refreshButton, &QAbstractButton::clicked, this, &Window::updateClusters);
|
connect(refreshButton, &QAbstractButton::clicked, this, &Window::updateClusters);
|
||||||
connect(createButton, &QAbstractButton::clicked, this, &Window::initMachine);
|
connect(createButton, &QAbstractButton::clicked, this, &Window::initMachine);
|
||||||
|
|
@ -274,29 +278,43 @@ void Window::startMinikube(QStringList moreArgs)
|
||||||
|
|
||||||
void Window::startSelectedMinikube()
|
void Window::startSelectedMinikube()
|
||||||
{
|
{
|
||||||
QStringList args = { "-p", selectedCluster() };
|
QStringList args = { "-p", selectedClusterName() };
|
||||||
return startMinikube(args);
|
return startMinikube(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::stopMinikube()
|
void Window::stopMinikube()
|
||||||
{
|
{
|
||||||
QStringList args = { "stop", "-p", selectedCluster() };
|
QStringList args = { "stop", "-p", selectedClusterName() };
|
||||||
|
sendMinikubeCommand(args);
|
||||||
|
updateClusters();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Window::pauseMinikube()
|
||||||
|
{
|
||||||
|
QStringList args = { "pause", "-p", selectedClusterName() };
|
||||||
|
sendMinikubeCommand(args);
|
||||||
|
updateClusters();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Window::unpauseMinikube()
|
||||||
|
{
|
||||||
|
QStringList args = { "unpause", "-p", selectedClusterName() };
|
||||||
sendMinikubeCommand(args);
|
sendMinikubeCommand(args);
|
||||||
updateClusters();
|
updateClusters();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::deleteMinikube()
|
void Window::deleteMinikube()
|
||||||
{
|
{
|
||||||
QStringList args = { "delete", "-p", selectedCluster() };
|
QStringList args = { "delete", "-p", selectedClusterName() };
|
||||||
sendMinikubeCommand(args);
|
sendMinikubeCommand(args);
|
||||||
updateClusters();
|
updateClusters();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::updateClusters()
|
void Window::updateClusters()
|
||||||
{
|
{
|
||||||
QString cluster = selectedCluster();
|
QString cluster = selectedClusterName();
|
||||||
clusterModel->setClusters(getClusters());
|
clusterModel->setClusters(getClusters());
|
||||||
setSelectedCluster(cluster);
|
setSelectedClusterName(cluster);
|
||||||
updateButtons();
|
updateButtons();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -376,7 +394,7 @@ Cluster Window::createClusterObject(QJsonObject obj)
|
||||||
return cluster;
|
return cluster;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Window::selectedCluster()
|
QString Window::selectedClusterName()
|
||||||
{
|
{
|
||||||
if (isBasicView) {
|
if (isBasicView) {
|
||||||
return "minikube";
|
return "minikube";
|
||||||
|
|
@ -389,7 +407,7 @@ QString Window::selectedCluster()
|
||||||
return variant.toString();
|
return variant.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::setSelectedCluster(QString cluster)
|
void Window::setSelectedClusterName(QString cluster)
|
||||||
{
|
{
|
||||||
QAbstractItemModel *model = clusterListView->model();
|
QAbstractItemModel *model = clusterListView->model();
|
||||||
QModelIndex start = model->index(0, 0);
|
QModelIndex start = model->index(0, 0);
|
||||||
|
|
@ -417,12 +435,13 @@ void Window::createClusterGroupBox()
|
||||||
clusterListView->horizontalHeader()->setSectionResizeMode(3, QHeaderView::ResizeToContents);
|
clusterListView->horizontalHeader()->setSectionResizeMode(3, QHeaderView::ResizeToContents);
|
||||||
clusterListView->horizontalHeader()->setSectionResizeMode(4, QHeaderView::ResizeToContents);
|
clusterListView->horizontalHeader()->setSectionResizeMode(4, QHeaderView::ResizeToContents);
|
||||||
clusterListView->horizontalHeader()->setSectionResizeMode(5, QHeaderView::ResizeToContents);
|
clusterListView->horizontalHeader()->setSectionResizeMode(5, QHeaderView::ResizeToContents);
|
||||||
setSelectedCluster("default");
|
setSelectedClusterName("default");
|
||||||
|
|
||||||
connect(clusterListView, SIGNAL(clicked(QModelIndex)), this, SLOT(updateButtons()));
|
connect(clusterListView, SIGNAL(clicked(QModelIndex)), this, SLOT(updateButtons()));
|
||||||
|
|
||||||
startButton = new QPushButton(tr("Start"));
|
startButton = new QPushButton(tr("Start"));
|
||||||
stopButton = new QPushButton(tr("Stop"));
|
stopButton = new QPushButton(tr("Stop"));
|
||||||
|
pauseButton = new QPushButton(tr("Pause"));
|
||||||
deleteButton = new QPushButton(tr("Delete"));
|
deleteButton = new QPushButton(tr("Delete"));
|
||||||
refreshButton = new QPushButton(tr("Refresh"));
|
refreshButton = new QPushButton(tr("Refresh"));
|
||||||
createButton = new QPushButton(tr("Create"));
|
createButton = new QPushButton(tr("Create"));
|
||||||
|
|
@ -440,6 +459,7 @@ void Window::createClusterGroupBox()
|
||||||
QHBoxLayout *bottomButtonLayout = new QHBoxLayout;
|
QHBoxLayout *bottomButtonLayout = new QHBoxLayout;
|
||||||
bottomButtonLayout->addWidget(startButton);
|
bottomButtonLayout->addWidget(startButton);
|
||||||
bottomButtonLayout->addWidget(stopButton);
|
bottomButtonLayout->addWidget(stopButton);
|
||||||
|
bottomButtonLayout->addWidget(pauseButton);
|
||||||
bottomButtonLayout->addWidget(deleteButton);
|
bottomButtonLayout->addWidget(deleteButton);
|
||||||
bottomButtonLayout->addWidget(sshButton);
|
bottomButtonLayout->addWidget(sshButton);
|
||||||
bottomButtonLayout->addWidget(dashboardButton);
|
bottomButtonLayout->addWidget(dashboardButton);
|
||||||
|
|
@ -460,66 +480,74 @@ void Window::updateButtons()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::updateBasicButtons()
|
Cluster Window::selectedCluster()
|
||||||
{
|
{
|
||||||
Cluster *cluster = new Cluster();
|
QString clusterName = selectedClusterName();
|
||||||
ClusterList list = getClusters();
|
if (clusterName.isEmpty()) {
|
||||||
for (int i = 0; i < list.length(); i++) {
|
return Cluster();
|
||||||
Cluster curr = list[i];
|
|
||||||
if (curr.name() != "minikube") {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
cluster = &curr;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
bool exists = cluster->name() == "minikube";
|
|
||||||
bool isRunning = exists && cluster->status() == "Running";
|
|
||||||
basicStartButton->setEnabled(isRunning == false);
|
|
||||||
basicStopButton->setEnabled(isRunning == true);
|
|
||||||
basicDeleteButton->setEnabled(exists == true);
|
|
||||||
basicDashboardButton->setEnabled(isRunning == true);
|
|
||||||
#if __linux__
|
|
||||||
basicSSHButton->setEnabled(isRunning == true);
|
|
||||||
#else
|
|
||||||
basicSSHButton->setEnabled(false);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void Window::updateAdvancedButtons()
|
|
||||||
{
|
|
||||||
QString cluster = selectedCluster();
|
|
||||||
if (cluster.isEmpty()) {
|
|
||||||
startButton->setEnabled(false);
|
|
||||||
stopButton->setEnabled(false);
|
|
||||||
deleteButton->setEnabled(false);
|
|
||||||
sshButton->setEnabled(false);
|
|
||||||
dashboardButton->setEnabled(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
deleteButton->setEnabled(true);
|
|
||||||
Cluster clusterHash = getClusterHash()[cluster];
|
|
||||||
if (clusterHash.status() == "Running") {
|
|
||||||
startButton->setEnabled(false);
|
|
||||||
stopButton->setEnabled(true);
|
|
||||||
#if __linux__
|
|
||||||
sshButton->setEnabled(true);
|
|
||||||
#endif
|
|
||||||
dashboardButton->setEnabled(true);
|
|
||||||
} else {
|
|
||||||
startButton->setEnabled(true);
|
|
||||||
stopButton->setEnabled(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ClusterHash Window::getClusterHash()
|
|
||||||
{
|
|
||||||
ClusterList clusters = getClusters();
|
ClusterList clusters = getClusters();
|
||||||
ClusterHash clusterHash;
|
ClusterHash clusterHash;
|
||||||
for (int i = 0; i < clusters.size(); i++) {
|
for (int i = 0; i < clusters.size(); i++) {
|
||||||
Cluster cluster = clusters.at(i);
|
Cluster cluster = clusters.at(i);
|
||||||
clusterHash[cluster.name()] = cluster;
|
clusterHash[cluster.name()] = cluster;
|
||||||
}
|
}
|
||||||
return clusterHash;
|
return clusterHash[clusterName];
|
||||||
|
}
|
||||||
|
|
||||||
|
void Window::updateBasicButtons()
|
||||||
|
{
|
||||||
|
Cluster cluster = selectedCluster();
|
||||||
|
bool exists = !cluster.isEmpty();
|
||||||
|
bool isRunning = cluster.status() == "Running";
|
||||||
|
bool isPaused = cluster.status() == "Paused";
|
||||||
|
basicStopButton->setEnabled(isRunning || isPaused);
|
||||||
|
basicPauseButton->setEnabled(isRunning || isPaused);
|
||||||
|
basicDeleteButton->setEnabled(exists);
|
||||||
|
basicDashboardButton->setEnabled(isRunning);
|
||||||
|
#if __linux__
|
||||||
|
basicSSHButton->setEnabled(exists);
|
||||||
|
#else
|
||||||
|
basicSSHButton->setEnabled(false);
|
||||||
|
#endif
|
||||||
|
QString pauseLabel = tr("Pause");
|
||||||
|
if (isPaused) {
|
||||||
|
pauseLabel = tr("Unpause");
|
||||||
|
}
|
||||||
|
basicPauseButton->setText(pauseLabel);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Window::pauseOrUnpauseMinikube()
|
||||||
|
{
|
||||||
|
Cluster cluster = selectedCluster();
|
||||||
|
if (cluster.status() == "Paused") {
|
||||||
|
unpauseMinikube();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pauseMinikube();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Window::updateAdvancedButtons()
|
||||||
|
{
|
||||||
|
Cluster cluster = selectedCluster();
|
||||||
|
bool exists = !cluster.isEmpty();
|
||||||
|
bool isRunning = cluster.status() == "Running";
|
||||||
|
bool isPaused = cluster.status() == "Paused";
|
||||||
|
startButton->setEnabled(exists);
|
||||||
|
stopButton->setEnabled(isRunning || isPaused);
|
||||||
|
pauseButton->setEnabled(isRunning || isPaused);
|
||||||
|
deleteButton->setEnabled(exists);
|
||||||
|
dashboardButton->setEnabled(isRunning);
|
||||||
|
#if __linux__
|
||||||
|
sshButton->setEnabled(exists);
|
||||||
|
#else
|
||||||
|
sshButton->setEnabled(false);
|
||||||
|
#endif
|
||||||
|
QString pauseLabel = tr("Pause");
|
||||||
|
if (isPaused) {
|
||||||
|
pauseLabel = tr("Unpause");
|
||||||
|
}
|
||||||
|
pauseButton->setText(pauseLabel);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Window::sendMinikubeCommand(QStringList cmds)
|
bool Window::sendMinikubeCommand(QStringList cmds)
|
||||||
|
|
@ -749,7 +777,7 @@ void Window::sshConsole()
|
||||||
console->setTerminalFont(font);
|
console->setTerminalFont(font);
|
||||||
console->setColorScheme("Tango");
|
console->setColorScheme("Tango");
|
||||||
console->setShellProgram(program);
|
console->setShellProgram(program);
|
||||||
QStringList args = { "ssh", "-p", selectedCluster() };
|
QStringList args = { "ssh", "-p", selectedClusterName() };
|
||||||
console->setArgs(args);
|
console->setArgs(args);
|
||||||
console->startShellProgram();
|
console->startShellProgram();
|
||||||
|
|
||||||
|
|
@ -768,7 +796,7 @@ void Window::sshConsole()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList arguments = { "-e", QString("%1 ssh -p %2").arg(program, selectedCluster()) };
|
QStringList arguments = { "-e", QString("%1 ssh -p %2").arg(program, selectedClusterName()) };
|
||||||
QProcess *process = new QProcess(this);
|
QProcess *process = new QProcess(this);
|
||||||
process->start(QStandardPaths::findExecutable(terminal), arguments);
|
process->start(QStandardPaths::findExecutable(terminal), arguments);
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -780,7 +808,7 @@ void Window::dashboardBrowser()
|
||||||
|
|
||||||
QString program = minikubePath();
|
QString program = minikubePath();
|
||||||
QProcess *process = new QProcess(this);
|
QProcess *process = new QProcess(this);
|
||||||
QStringList arguments = { "dashboard", "-p", selectedCluster() };
|
QStringList arguments = { "dashboard", "-p", selectedClusterName() };
|
||||||
process->start(program, arguments);
|
process->start(program, arguments);
|
||||||
|
|
||||||
dashboardProcess = process;
|
dashboardProcess = process;
|
||||||
|
|
|
||||||
17
gui/window.h
17
gui/window.h
|
|
@ -113,14 +113,9 @@ private:
|
||||||
void createBasicView();
|
void createBasicView();
|
||||||
void toBasicView();
|
void toBasicView();
|
||||||
void updateBasicButtons();
|
void updateBasicButtons();
|
||||||
void basicStartMinikube();
|
|
||||||
void basicStopMinikube();
|
|
||||||
void basicDeleteMinikube();
|
|
||||||
void basicRefreshMinikube();
|
|
||||||
void basicSSHMinikube();
|
|
||||||
void basicDashboardMinikube();
|
|
||||||
QPushButton *basicStartButton;
|
QPushButton *basicStartButton;
|
||||||
QPushButton *basicStopButton;
|
QPushButton *basicStopButton;
|
||||||
|
QPushButton *basicPauseButton;
|
||||||
QPushButton *basicDeleteButton;
|
QPushButton *basicDeleteButton;
|
||||||
QPushButton *basicRefreshButton;
|
QPushButton *basicRefreshButton;
|
||||||
QPushButton *basicSSHButton;
|
QPushButton *basicSSHButton;
|
||||||
|
|
@ -133,6 +128,7 @@ private:
|
||||||
void updateAdvancedButtons();
|
void updateAdvancedButtons();
|
||||||
QPushButton *startButton;
|
QPushButton *startButton;
|
||||||
QPushButton *stopButton;
|
QPushButton *stopButton;
|
||||||
|
QPushButton *pauseButton;
|
||||||
QPushButton *deleteButton;
|
QPushButton *deleteButton;
|
||||||
QPushButton *refreshButton;
|
QPushButton *refreshButton;
|
||||||
QPushButton *createButton;
|
QPushButton *createButton;
|
||||||
|
|
@ -141,9 +137,9 @@ private:
|
||||||
QGroupBox *clusterGroupBox;
|
QGroupBox *clusterGroupBox;
|
||||||
|
|
||||||
// Cluster table
|
// Cluster table
|
||||||
QString selectedCluster();
|
QString selectedClusterName();
|
||||||
void setSelectedCluster(QString cluster);
|
void setSelectedClusterName(QString cluster);
|
||||||
ClusterHash getClusterHash();
|
Cluster selectedCluster();
|
||||||
ClusterList getClusters();
|
ClusterList getClusters();
|
||||||
void updateClusters();
|
void updateClusters();
|
||||||
ClusterModel *clusterModel;
|
ClusterModel *clusterModel;
|
||||||
|
|
@ -160,6 +156,9 @@ private:
|
||||||
void startMinikube(QStringList args);
|
void startMinikube(QStringList args);
|
||||||
void startSelectedMinikube();
|
void startSelectedMinikube();
|
||||||
void stopMinikube();
|
void stopMinikube();
|
||||||
|
void pauseMinikube();
|
||||||
|
void unpauseMinikube();
|
||||||
|
void pauseOrUnpauseMinikube();
|
||||||
void deleteMinikube();
|
void deleteMinikube();
|
||||||
bool sendMinikubeCommand(QStringList cmds);
|
bool sendMinikubeCommand(QStringList cmds);
|
||||||
bool sendMinikubeCommand(QStringList cmds, QString &text);
|
bool sendMinikubeCommand(QStringList cmds, QString &text);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue