add ssh and dashboard buttons
parent
6cf65dcc86
commit
9b5ee04d5b
|
|
@ -1,5 +1,5 @@
|
||||||
HEADERS = window.h \
|
HEADERS = window.h \
|
||||||
cluster.h
|
cluster.h
|
||||||
SOURCES = main.cpp \
|
SOURCES = main.cpp \
|
||||||
cluster.cpp \
|
cluster.cpp \
|
||||||
window.cpp
|
window.cpp
|
||||||
|
|
@ -7,3 +7,18 @@ RESOURCES = systray.qrc
|
||||||
|
|
||||||
QT += widgets
|
QT += widgets
|
||||||
requires(qtConfig(combobox))
|
requires(qtConfig(combobox))
|
||||||
|
|
||||||
|
DISTFILES += \
|
||||||
|
LICENSE
|
||||||
|
|
||||||
|
# Enabling qtermwidget requires GPL-v2 license
|
||||||
|
#CONFIG += gpl_licensed
|
||||||
|
|
||||||
|
gpl_licensed {
|
||||||
|
win32: DEFINES += QT_NO_TERMWIDGET
|
||||||
|
|
||||||
|
unix: CONFIG += link_pkgconfig
|
||||||
|
unix: PKGCONFIG += qtermwidget5
|
||||||
|
} else {
|
||||||
|
DEFINES += QT_NO_TERMWIDGET
|
||||||
|
}
|
||||||
|
|
|
||||||
115
gui/window.cpp
115
gui/window.cpp
|
|
@ -78,6 +78,13 @@
|
||||||
#include <QHeaderView>
|
#include <QHeaderView>
|
||||||
#include <QFormLayout>
|
#include <QFormLayout>
|
||||||
#include <QDialogButtonBox>
|
#include <QDialogButtonBox>
|
||||||
|
#include <QStandardPaths>
|
||||||
|
|
||||||
|
#ifndef QT_NO_TERMWIDGET
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QMainWindow>
|
||||||
|
#include "qtermwidget.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
//! [0]
|
//! [0]
|
||||||
Window::Window()
|
Window::Window()
|
||||||
|
|
@ -87,6 +94,8 @@ Window::Window()
|
||||||
createActions();
|
createActions();
|
||||||
createTrayIcon();
|
createTrayIcon();
|
||||||
|
|
||||||
|
connect(sshButton, &QAbstractButton::clicked, this, &Window::sshConsole);
|
||||||
|
connect(dashboardButton, &QAbstractButton::clicked, this, &Window::dashboardBrowser);
|
||||||
connect(startButton, &QAbstractButton::clicked, this, &Window::startMinikube);
|
connect(startButton, &QAbstractButton::clicked, this, &Window::startMinikube);
|
||||||
connect(stopButton, &QAbstractButton::clicked, this, &Window::stopMinikube);
|
connect(stopButton, &QAbstractButton::clicked, this, &Window::stopMinikube);
|
||||||
connect(deleteButton, &QAbstractButton::clicked, this, &Window::deleteMinikube);
|
connect(deleteButton, &QAbstractButton::clicked, this, &Window::deleteMinikube);
|
||||||
|
|
@ -94,6 +103,8 @@ Window::Window()
|
||||||
connect(createButton, &QAbstractButton::clicked, this, &Window::initMachine);
|
connect(createButton, &QAbstractButton::clicked, this, &Window::initMachine);
|
||||||
connect(trayIcon, &QSystemTrayIcon::messageClicked, this, &Window::messageClicked);
|
connect(trayIcon, &QSystemTrayIcon::messageClicked, this, &Window::messageClicked);
|
||||||
|
|
||||||
|
dashboardProcess = 0;
|
||||||
|
|
||||||
QVBoxLayout *mainLayout = new QVBoxLayout;
|
QVBoxLayout *mainLayout = new QVBoxLayout;
|
||||||
mainLayout->addWidget(clusterGroupBox);
|
mainLayout->addWidget(clusterGroupBox);
|
||||||
setLayout(mainLayout);
|
setLayout(mainLayout);
|
||||||
|
|
@ -156,6 +167,16 @@ void Window::createActions()
|
||||||
connect(quitAction, &QAction::triggered, qApp, &QCoreApplication::quit);
|
connect(quitAction, &QAction::triggered, qApp, &QCoreApplication::quit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static QString minikubePath()
|
||||||
|
{
|
||||||
|
QString program = QStandardPaths::findExecutable("minikube");
|
||||||
|
if (program.isEmpty()) {
|
||||||
|
QStringList paths = { "/usr/local/bin" };
|
||||||
|
program = QStandardPaths::findExecutable("minikube", paths);
|
||||||
|
}
|
||||||
|
return program;
|
||||||
|
}
|
||||||
|
|
||||||
void Window::createTrayIcon()
|
void Window::createTrayIcon()
|
||||||
{
|
{
|
||||||
trayIconMenu = new QMenu(this);
|
trayIconMenu = new QMenu(this);
|
||||||
|
|
@ -319,19 +340,27 @@ void Window::createClusterGroupBox()
|
||||||
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"));
|
||||||
|
sshButton = new QPushButton(tr("SSH"));
|
||||||
|
dashboardButton = new QPushButton(tr("Dashboard"));
|
||||||
|
|
||||||
updateButtons();
|
updateButtons();
|
||||||
|
|
||||||
QHBoxLayout *clusterButtonLayout = new QHBoxLayout;
|
QHBoxLayout *topButtonLayout = new QHBoxLayout;
|
||||||
clusterButtonLayout->addWidget(startButton);
|
topButtonLayout->addWidget(createButton);
|
||||||
clusterButtonLayout->addWidget(stopButton);
|
topButtonLayout->addWidget(refreshButton);
|
||||||
clusterButtonLayout->addWidget(deleteButton);
|
topButtonLayout->addSpacing(340);
|
||||||
clusterButtonLayout->addWidget(refreshButton);
|
|
||||||
clusterButtonLayout->addWidget(createButton);
|
QHBoxLayout *bottomButtonLayout = new QHBoxLayout;
|
||||||
|
bottomButtonLayout->addWidget(startButton);
|
||||||
|
bottomButtonLayout->addWidget(stopButton);
|
||||||
|
bottomButtonLayout->addWidget(deleteButton);
|
||||||
|
bottomButtonLayout->addWidget(sshButton);
|
||||||
|
bottomButtonLayout->addWidget(dashboardButton);
|
||||||
|
|
||||||
QVBoxLayout *clusterLayout = new QVBoxLayout;
|
QVBoxLayout *clusterLayout = new QVBoxLayout;
|
||||||
|
clusterLayout->addLayout(topButtonLayout);
|
||||||
clusterLayout->addWidget(clusterListView);
|
clusterLayout->addWidget(clusterListView);
|
||||||
clusterLayout->addLayout(clusterButtonLayout);
|
clusterLayout->addLayout(bottomButtonLayout);
|
||||||
clusterGroupBox->setLayout(clusterLayout);
|
clusterGroupBox->setLayout(clusterLayout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -342,6 +371,8 @@ void Window::updateButtons()
|
||||||
startButton->setEnabled(false);
|
startButton->setEnabled(false);
|
||||||
stopButton->setEnabled(false);
|
stopButton->setEnabled(false);
|
||||||
deleteButton->setEnabled(false);
|
deleteButton->setEnabled(false);
|
||||||
|
sshButton->setEnabled(false);
|
||||||
|
dashboardButton->setEnabled(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
deleteButton->setEnabled(true);
|
deleteButton->setEnabled(true);
|
||||||
|
|
@ -349,6 +380,8 @@ void Window::updateButtons()
|
||||||
if (clusterHash.status() == "Running") {
|
if (clusterHash.status() == "Running") {
|
||||||
startButton->setEnabled(false);
|
startButton->setEnabled(false);
|
||||||
stopButton->setEnabled(true);
|
stopButton->setEnabled(true);
|
||||||
|
sshButton->setEnabled(true);
|
||||||
|
dashboardButton->setEnabled(true);
|
||||||
} else {
|
} else {
|
||||||
startButton->setEnabled(true);
|
startButton->setEnabled(true);
|
||||||
stopButton->setEnabled(false);
|
stopButton->setEnabled(false);
|
||||||
|
|
@ -374,7 +407,10 @@ bool Window::sendMinikubeCommand(QStringList cmds)
|
||||||
|
|
||||||
bool Window::sendMinikubeCommand(QStringList cmds, QString &text)
|
bool Window::sendMinikubeCommand(QStringList cmds, QString &text)
|
||||||
{
|
{
|
||||||
QString program = "minikube";
|
QString program = minikubePath();
|
||||||
|
if (program.isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
QStringList arguments;
|
QStringList arguments;
|
||||||
arguments << cmds;
|
arguments << cmds;
|
||||||
bool success;
|
bool success;
|
||||||
|
|
@ -418,6 +454,7 @@ void Window::askName()
|
||||||
form.addRow(&buttonBox);
|
form.addRow(&buttonBox);
|
||||||
|
|
||||||
int code = dialog.exec();
|
int code = dialog.exec();
|
||||||
|
profile = profileField.text();
|
||||||
if (code == QDialog::Accepted) {
|
if (code == QDialog::Accepted) {
|
||||||
QStringList arg = {"start", "-p", profile};
|
QStringList arg = {"start", "-p", profile};
|
||||||
sendMinikubeCommand(arg);
|
sendMinikubeCommand(arg);
|
||||||
|
|
@ -472,4 +509,66 @@ void Window::initMachine()
|
||||||
updateClusters();
|
updateClusters();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Window::sshConsole()
|
||||||
|
{
|
||||||
|
QString program = minikubePath();
|
||||||
|
#ifndef QT_NO_TERMWIDGET
|
||||||
|
QMainWindow *mainWindow = new QMainWindow();
|
||||||
|
int startnow = 0; // set shell program first
|
||||||
|
|
||||||
|
QTermWidget *console = new QTermWidget(startnow);
|
||||||
|
|
||||||
|
QFont font = QApplication::font();
|
||||||
|
font.setFamily("Monospace");
|
||||||
|
font.setPointSize(10);
|
||||||
|
|
||||||
|
console->setTerminalFont(font);
|
||||||
|
console->setColorScheme("Tango");
|
||||||
|
console->setShellProgram(program);
|
||||||
|
QStringList args = { "ssh" };
|
||||||
|
console->setArgs(args);
|
||||||
|
console->startShellProgram();
|
||||||
|
|
||||||
|
QObject::connect(console, SIGNAL(finished()), mainWindow, SLOT(close()));
|
||||||
|
|
||||||
|
mainWindow->setWindowTitle(nameLabel->text());
|
||||||
|
mainWindow->resize(800, 400);
|
||||||
|
mainWindow->setCentralWidget(console);
|
||||||
|
mainWindow->show();
|
||||||
|
#else
|
||||||
|
QString terminal = qEnvironmentVariable("TERMINAL");
|
||||||
|
if (terminal.isEmpty()) {
|
||||||
|
terminal = "x-terminal-emulator";
|
||||||
|
if (QStandardPaths::findExecutable(terminal).isEmpty()) {
|
||||||
|
terminal = "xterm";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList arguments = {"-e", QString("%1 ssh -p %2").arg(program, selectedCluster())};
|
||||||
|
QProcess *process = new QProcess(this);
|
||||||
|
process->start(QStandardPaths::findExecutable(terminal), arguments);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void Window::dashboardBrowser()
|
||||||
|
{
|
||||||
|
dashboardClose();
|
||||||
|
|
||||||
|
QString program = minikubePath();
|
||||||
|
QProcess *process = new QProcess(this);
|
||||||
|
QStringList arguments = {"dashboard", "-p", selectedCluster()};
|
||||||
|
process->start(program, arguments);
|
||||||
|
|
||||||
|
dashboardProcess = process;
|
||||||
|
dashboardProcess->waitForStarted();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Window::dashboardClose()
|
||||||
|
{
|
||||||
|
if (dashboardProcess) {
|
||||||
|
dashboardProcess->terminate();
|
||||||
|
dashboardProcess->waitForFinished();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -73,6 +73,7 @@ class QPushButton;
|
||||||
class QSpinBox;
|
class QSpinBox;
|
||||||
class QTextEdit;
|
class QTextEdit;
|
||||||
class QTableView;
|
class QTableView;
|
||||||
|
class QProcess;
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
#include "cluster.h"
|
#include "cluster.h"
|
||||||
|
|
@ -93,6 +94,7 @@ protected:
|
||||||
private slots:
|
private slots:
|
||||||
void messageClicked();
|
void messageClicked();
|
||||||
void updateButtons();
|
void updateButtons();
|
||||||
|
void dashboardClose();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void createActionGroupBox();
|
void createActionGroupBox();
|
||||||
|
|
@ -117,6 +119,11 @@ private:
|
||||||
QComboBox *driverComboBox;
|
QComboBox *driverComboBox;
|
||||||
QComboBox *containerRuntimeComboBox;
|
QComboBox *containerRuntimeComboBox;
|
||||||
void initMachine();
|
void initMachine();
|
||||||
|
void sshConsole();
|
||||||
|
void dashboardBrowser();
|
||||||
|
QPushButton *sshButton;
|
||||||
|
QPushButton *dashboardButton;
|
||||||
|
QProcess *dashboardProcess;
|
||||||
|
|
||||||
QPushButton *startButton;
|
QPushButton *startButton;
|
||||||
QPushButton *stopButton;
|
QPushButton *stopButton;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue