minikube/gui/window.cpp

1192 lines
38 KiB
C++
Raw Normal View History

2022-02-24 23:02:53 +00:00
/****************************************************************************
**
2022-03-02 21:14:10 +00:00
** Copyright 2022 The Kubernetes Authors All rights reserved.
**
** Copyright (C) 2021 Anders F Björklund
2022-02-24 23:02:53 +00:00
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, you may use this file under the terms of the BSD license
** as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of The Qt Company Ltd nor the names of its
** contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "window.h"
#ifndef QT_NO_SYSTEMTRAYICON
#include <QAction>
#include <QCheckBox>
#include <QComboBox>
#include <QCoreApplication>
#include <QCloseEvent>
#include <QGroupBox>
#include <QLabel>
#include <QLineEdit>
#include <QMenu>
#include <QPushButton>
#include <QSpinBox>
#include <QTextEdit>
#include <QVBoxLayout>
#include <QMessageBox>
#include <QProcess>
#include <QDebug>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QTableView>
#include <QHeaderView>
#include <QFormLayout>
#include <QDialogButtonBox>
2022-03-02 23:43:14 +00:00
#include <QStandardPaths>
2022-04-08 18:43:14 +00:00
#include <QDir>
#include <QFontDialog>
2022-04-15 18:43:32 +00:00
#include <QStackedWidget>
#include <QProcessEnvironment>
2022-05-03 23:24:51 +00:00
#include <QNetworkAccessManager>
2022-03-02 23:43:14 +00:00
#ifndef QT_NO_TERMWIDGET
#include <QApplication>
#include <QMainWindow>
#include "qtermwidget.h"
#endif
2022-02-24 23:02:53 +00:00
2022-05-03 23:24:51 +00:00
const QVersionNumber version = QVersionNumber::fromString("0.0.1");
2022-02-24 23:02:53 +00:00
Window::Window()
{
trayIconIcon = new QIcon(":/images/minikube.png");
checkForMinikube();
2022-04-15 18:43:32 +00:00
isBasicView = true;
stackedWidget = new QStackedWidget;
QVBoxLayout *layout = new QVBoxLayout;
dashboardProcess = 0;
2022-03-02 21:32:33 +00:00
createClusterGroupBox();
2022-02-24 23:02:53 +00:00
createActions();
createTrayIcon();
2022-04-15 18:43:32 +00:00
createBasicView();
createAdvancedView();
trayIcon->show();
updateButtons();
layout->addWidget(stackedWidget);
setLayout(layout);
2022-05-04 22:57:05 +00:00
resize(200, 275);
2022-04-15 18:43:32 +00:00
setWindowTitle(tr("minikube"));
setWindowIcon(*trayIconIcon);
2022-05-03 23:24:51 +00:00
checkForUpdates();
2022-04-15 18:43:32 +00:00
}
QProcessEnvironment Window::setMacEnv()
{
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
QString path = env.value("PATH");
env.insert("PATH", path + ":/usr/local/bin");
return env;
}
2022-04-15 18:43:32 +00:00
void Window::createBasicView()
{
2022-05-04 22:57:05 +00:00
QWidget *basicView = new QWidget();
2022-04-15 18:43:32 +00:00
basicStartButton = new QPushButton(tr("Start"));
basicStopButton = new QPushButton(tr("Stop"));
2022-04-25 20:34:04 +00:00
basicPauseButton = new QPushButton(tr("Pause"));
2022-04-15 18:43:32 +00:00
basicDeleteButton = new QPushButton(tr("Delete"));
basicRefreshButton = new QPushButton(tr("Refresh"));
basicSSHButton = new QPushButton(tr("SSH"));
basicDashboardButton = new QPushButton(tr("Dashboard"));
QPushButton *advancedViewButton = new QPushButton(tr("Advanced View"));
QVBoxLayout *buttonLayout = new QVBoxLayout;
2022-05-04 22:57:05 +00:00
basicView->setLayout(buttonLayout);
2022-04-15 18:43:32 +00:00
buttonLayout->addWidget(basicStartButton);
buttonLayout->addWidget(basicStopButton);
2022-04-25 20:34:04 +00:00
buttonLayout->addWidget(basicPauseButton);
2022-04-15 18:43:32 +00:00
buttonLayout->addWidget(basicDeleteButton);
buttonLayout->addWidget(basicRefreshButton);
buttonLayout->addWidget(basicSSHButton);
buttonLayout->addWidget(basicDashboardButton);
buttonLayout->addWidget(advancedViewButton);
2022-05-04 22:57:05 +00:00
basicView->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
stackedWidget->addWidget(basicView);
2022-04-15 18:43:32 +00:00
connect(basicSSHButton, &QAbstractButton::clicked, this, &Window::sshConsole);
connect(basicDashboardButton, &QAbstractButton::clicked, this, &Window::dashboardBrowser);
connect(basicStartButton, &QAbstractButton::clicked, this, &Window::startSelectedMinikube);
connect(basicStopButton, &QAbstractButton::clicked, this, &Window::stopMinikube);
2022-04-25 20:34:04 +00:00
connect(basicPauseButton, &QAbstractButton::clicked, this, &Window::pauseOrUnpauseMinikube);
2022-04-15 18:43:32 +00:00
connect(basicDeleteButton, &QAbstractButton::clicked, this, &Window::deleteMinikube);
2022-04-26 23:49:43 +00:00
connect(basicRefreshButton, &QAbstractButton::clicked, this, &Window::updateClustersTable);
2022-04-15 18:43:32 +00:00
connect(advancedViewButton, &QAbstractButton::clicked, this, &Window::toAdvancedView);
}
void Window::toAdvancedView()
{
isBasicView = false;
stackedWidget->setCurrentIndex(1);
2022-05-04 22:57:05 +00:00
resize(670, 400);
2022-04-26 23:49:43 +00:00
updateButtons();
2022-04-15 18:43:32 +00:00
}
void Window::toBasicView()
{
isBasicView = true;
stackedWidget->setCurrentIndex(0);
2022-05-04 22:57:05 +00:00
resize(200, 275);
2022-04-26 23:49:43 +00:00
updateButtons();
2022-04-15 18:43:32 +00:00
}
void Window::createAdvancedView()
{
2022-03-02 23:43:14 +00:00
connect(sshButton, &QAbstractButton::clicked, this, &Window::sshConsole);
connect(dashboardButton, &QAbstractButton::clicked, this, &Window::dashboardBrowser);
2022-04-06 22:28:18 +00:00
connect(startButton, &QAbstractButton::clicked, this, &Window::startSelectedMinikube);
2022-02-24 23:02:53 +00:00
connect(stopButton, &QAbstractButton::clicked, this, &Window::stopMinikube);
2022-04-25 20:34:04 +00:00
connect(pauseButton, &QAbstractButton::clicked, this, &Window::pauseOrUnpauseMinikube);
2022-02-24 23:02:53 +00:00
connect(deleteButton, &QAbstractButton::clicked, this, &Window::deleteMinikube);
2022-04-26 23:49:43 +00:00
connect(refreshButton, &QAbstractButton::clicked, this, &Window::updateClustersTable);
2022-02-24 23:02:53 +00:00
connect(createButton, &QAbstractButton::clicked, this, &Window::initMachine);
2022-05-04 22:57:05 +00:00
advancedView->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
stackedWidget->addWidget(advancedView);
2022-02-24 23:02:53 +00:00
}
void Window::setVisible(bool visible)
{
minimizeAction->setEnabled(visible);
restoreAction->setEnabled(!visible);
QDialog::setVisible(visible);
}
void Window::closeEvent(QCloseEvent *event)
{
2022-04-28 19:48:25 +00:00
#if __APPLE__
2022-02-24 23:02:53 +00:00
if (!event->spontaneous() || !isVisible()) {
return;
}
#endif
if (trayIcon->isVisible()) {
QMessageBox::information(this, tr("Systray"),
tr("The program will keep running in the "
"system tray. To terminate the program, "
"choose <b>Quit</b> in the context menu "
"of the system tray entry."));
hide();
event->ignore();
}
}
void Window::messageClicked()
{
QMessageBox::information(0, tr("Systray"),
tr("Sorry, I already gave what help I could.\n"
"Maybe you should try asking a human?"));
}
void Window::createActions()
{
minimizeAction = new QAction(tr("Mi&nimize"), this);
connect(minimizeAction, &QAction::triggered, this, &QWidget::hide);
restoreAction = new QAction(tr("&Restore"), this);
connect(restoreAction, &QAction::triggered, this, &Window::restoreWindow);
2022-02-24 23:02:53 +00:00
quitAction = new QAction(tr("&Quit"), this);
connect(quitAction, &QAction::triggered, qApp, &QCoreApplication::quit);
2022-04-26 19:43:41 +00:00
startAction = new QAction(tr("Start"), this);
connect(startAction, &QAction::triggered, this, &Window::startSelectedMinikube);
pauseAction = new QAction(tr("Pause"), this);
connect(pauseAction, &QAction::triggered, this, &Window::pauseOrUnpauseMinikube);
stopAction = new QAction(tr("Stop"), this);
connect(stopAction, &QAction::triggered, this, &Window::stopMinikube);
2022-04-27 22:05:59 +00:00
statusAction = new QAction(tr("Status:"), this);
statusAction->setEnabled(false);
}
void Window::updateStatus(Cluster cluster)
{
QString status = cluster.status();
if (status.isEmpty()) {
status = "Stopped";
}
statusAction->setText("Status: " + status);
2022-02-24 23:02:53 +00:00
}
2022-04-25 22:23:27 +00:00
void Window::iconActivated(QSystemTrayIcon::ActivationReason reason)
{
switch (reason) {
case QSystemTrayIcon::Trigger:
case QSystemTrayIcon::DoubleClick:
Window::restoreWindow();
break;
default:;
}
}
void Window::restoreWindow()
{
2022-04-25 22:23:27 +00:00
bool wasVisible = isVisible();
QWidget::showNormal();
2022-04-25 22:23:27 +00:00
activateWindow();
if (wasVisible) {
return;
}
// without this delay window doesn't render until updateClusters() completes
delay();
2022-04-26 23:49:43 +00:00
updateClustersTable();
}
2022-04-25 22:23:27 +00:00
void Window::delay()
{
QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
}
2022-03-02 23:43:14 +00:00
static QString minikubePath()
{
QString program = QStandardPaths::findExecutable("minikube");
if (program.isEmpty()) {
QStringList paths = { "/usr/local/bin" };
program = QStandardPaths::findExecutable("minikube", paths);
}
return program;
}
2022-02-24 23:02:53 +00:00
void Window::createTrayIcon()
{
trayIconMenu = new QMenu(this);
2022-04-27 22:05:59 +00:00
trayIconMenu->addAction(statusAction);
trayIconMenu->addSeparator();
2022-04-26 19:43:41 +00:00
trayIconMenu->addAction(startAction);
trayIconMenu->addAction(pauseAction);
trayIconMenu->addAction(stopAction);
trayIconMenu->addSeparator();
2022-02-24 23:02:53 +00:00
trayIconMenu->addAction(minimizeAction);
trayIconMenu->addAction(restoreAction);
trayIconMenu->addSeparator();
trayIconMenu->addAction(quitAction);
trayIcon = new QSystemTrayIcon(this);
trayIcon->setContextMenu(trayIconMenu);
trayIcon->setIcon(*trayIconIcon);
2022-04-25 22:23:27 +00:00
connect(trayIcon, &QSystemTrayIcon::activated, this, &Window::iconActivated);
2022-02-24 23:02:53 +00:00
}
2022-04-06 22:28:18 +00:00
void Window::startMinikube(QStringList moreArgs)
2022-02-24 23:02:53 +00:00
{
QString text;
2022-04-06 22:28:18 +00:00
QStringList args = { "start", "-o", "json" };
args << moreArgs;
2022-05-05 22:55:20 +00:00
bool success = sendMinikubeStart(args, text);
#if __APPLE__
2022-05-04 22:13:33 +00:00
hyperkitPermissionFix(args, text);
#endif
2022-04-26 23:49:43 +00:00
updateClustersTable();
if (success) {
return;
}
outputFailedStart(text);
2022-02-24 23:02:53 +00:00
}
2022-04-06 22:28:18 +00:00
void Window::startSelectedMinikube()
{
2022-04-25 20:34:04 +00:00
QStringList args = { "-p", selectedClusterName() };
2022-04-06 22:28:18 +00:00
return startMinikube(args);
}
2022-02-24 23:02:53 +00:00
void Window::stopMinikube()
{
2022-04-25 20:34:04 +00:00
QStringList args = { "stop", "-p", selectedClusterName() };
sendMinikubeCommand(args);
2022-04-26 23:49:43 +00:00
updateClustersTable();
2022-04-25 20:34:04 +00:00
}
void Window::pauseMinikube()
{
QStringList args = { "pause", "-p", selectedClusterName() };
sendMinikubeCommand(args);
2022-04-26 23:49:43 +00:00
updateClustersTable();
2022-04-25 20:34:04 +00:00
}
void Window::unpauseMinikube()
{
QStringList args = { "unpause", "-p", selectedClusterName() };
2022-02-24 23:02:53 +00:00
sendMinikubeCommand(args);
2022-04-26 23:49:43 +00:00
updateClustersTable();
2022-02-24 23:02:53 +00:00
}
void Window::deleteMinikube()
{
2022-04-25 20:34:04 +00:00
QStringList args = { "delete", "-p", selectedClusterName() };
2022-02-24 23:02:53 +00:00
sendMinikubeCommand(args);
2022-04-26 23:49:43 +00:00
updateClustersTable();
2022-02-24 23:02:53 +00:00
}
2022-04-26 23:49:43 +00:00
void Window::updateClustersTable()
2022-02-24 23:02:53 +00:00
{
showLoading();
2022-04-25 20:34:04 +00:00
QString cluster = selectedClusterName();
2022-04-26 23:49:43 +00:00
updateClusterList();
clusterModel->setClusters(clusterList);
2022-04-25 20:34:04 +00:00
setSelectedClusterName(cluster);
2022-02-24 23:02:53 +00:00
updateButtons();
loading->setHidden(true);
clusterListView->setEnabled(true);
hideLoading();
}
void Window::showLoading()
{
clusterListView->setEnabled(false);
loading->setHidden(false);
loading->raise();
int width = getCenter(loading->width(), clusterListView->width());
int height = getCenter(loading->height(), clusterListView->height());
loading->move(width, height);
delay();
}
void Window::hideLoading()
{
loading->setHidden(true);
clusterListView->setEnabled(true);
}
int Window::getCenter(int widgetSize, int parentSize)
{
return parentSize / 2 - widgetSize / 2;
2022-02-24 23:02:53 +00:00
}
2022-04-26 23:49:43 +00:00
void Window::updateClusterList()
2022-02-24 23:02:53 +00:00
{
2022-03-02 21:32:33 +00:00
ClusterList clusters;
2022-03-02 23:53:42 +00:00
QStringList args = { "profile", "list", "-o", "json" };
2022-02-24 23:02:53 +00:00
QString text;
2022-04-15 18:43:32 +00:00
sendMinikubeCommand(args, text);
2022-02-24 23:02:53 +00:00
QStringList lines;
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
2022-04-15 18:43:32 +00:00
lines = text.split("\n", Qt::SkipEmptyParts);
2022-02-24 23:02:53 +00:00
#else
2022-04-15 18:43:32 +00:00
lines = text.split("\n", QString::SkipEmptyParts);
2022-02-24 23:02:53 +00:00
#endif
for (int i = 0; i < lines.size(); i++) {
QString line = lines.at(i);
QJsonParseError error;
QJsonDocument json = QJsonDocument::fromJson(line.toUtf8(), &error);
if (json.isNull()) {
qDebug() << error.errorString();
continue;
}
2022-04-15 18:43:32 +00:00
if (!json.isObject()) {
continue;
}
QJsonObject par = json.object();
2022-04-28 20:30:42 +00:00
QJsonArray valid = par["valid"].toArray();
QJsonArray invalid = par["invalid"].toArray();
for (int i = 0; i < valid.size(); i++) {
QJsonObject obj = valid[i].toObject();
Cluster cluster = createClusterObject(obj);
clusters << cluster;
2022-04-15 18:43:32 +00:00
}
2022-04-28 20:30:42 +00:00
for (int i = 0; i < invalid.size(); i++) {
QJsonObject obj = invalid[i].toObject();
2022-04-15 18:43:32 +00:00
Cluster cluster = createClusterObject(obj);
2022-04-28 20:30:42 +00:00
cluster.setStatus("Invalid");
2022-04-15 18:43:32 +00:00
clusters << cluster;
2022-02-24 23:02:53 +00:00
}
}
2022-04-26 23:49:43 +00:00
clusterList = clusters;
2022-02-24 23:02:53 +00:00
}
2022-04-15 18:43:32 +00:00
Cluster Window::createClusterObject(QJsonObject obj)
{
QString name;
if (obj.contains("Name")) {
name = obj["Name"].toString();
}
Cluster cluster(name);
if (obj.contains("Status")) {
QString status = obj["Status"].toString();
cluster.setStatus(status);
}
if (!obj.contains("Config")) {
return cluster;
}
QJsonObject config = obj["Config"].toObject();
if (config.contains("CPUs")) {
int cpus = config["CPUs"].toInt();
cluster.setCpus(cpus);
}
if (config.contains("Memory")) {
int memory = config["Memory"].toInt();
cluster.setMemory(memory);
}
if (config.contains("Driver")) {
QString driver = config["Driver"].toString();
cluster.setDriver(driver);
}
if (!config.contains("KubernetesConfig")) {
return cluster;
}
QJsonObject k8sConfig = config["KubernetesConfig"].toObject();
if (k8sConfig.contains("ContainerRuntime")) {
QString containerRuntime = k8sConfig["ContainerRuntime"].toString();
cluster.setContainerRuntime(containerRuntime);
}
if (k8sConfig.contains("KubernetesVersion")) {
QString k8sVersion = k8sConfig["KubernetesVersion"].toString();
cluster.setK8sVersion(k8sVersion);
}
2022-04-15 18:43:32 +00:00
return cluster;
}
2022-04-25 20:34:04 +00:00
QString Window::selectedClusterName()
2022-02-24 23:02:53 +00:00
{
2022-04-15 18:43:32 +00:00
if (isBasicView) {
return "minikube";
}
2022-03-02 21:32:33 +00:00
QModelIndex index = clusterListView->currentIndex();
2022-04-26 23:49:43 +00:00
QVariant variant = index.siblingAtColumn(0).data(Qt::DisplayRole);
2022-02-24 23:02:53 +00:00
if (variant.isNull()) {
return QString();
}
return variant.toString();
}
2022-04-25 20:34:04 +00:00
void Window::setSelectedClusterName(QString cluster)
2022-02-24 23:02:53 +00:00
{
2022-03-02 21:32:33 +00:00
QAbstractItemModel *model = clusterListView->model();
2022-02-24 23:02:53 +00:00
QModelIndex start = model->index(0, 0);
2022-03-02 21:32:33 +00:00
QModelIndexList index = model->match(start, Qt::DisplayRole, cluster);
2022-02-24 23:02:53 +00:00
if (index.size() == 0) {
return;
}
2022-03-02 21:32:33 +00:00
clusterListView->setCurrentIndex(index[0]);
2022-02-24 23:02:53 +00:00
}
2022-03-02 21:32:33 +00:00
void Window::createClusterGroupBox()
2022-02-24 23:02:53 +00:00
{
2022-05-04 22:57:05 +00:00
advancedView = new QWidget();
2022-02-24 23:02:53 +00:00
2022-04-26 23:49:43 +00:00
updateClusterList();
ClusterList clusters = clusterList;
2022-03-02 21:32:33 +00:00
clusterModel = new ClusterModel(clusters);
2022-02-24 23:02:53 +00:00
2022-03-02 21:32:33 +00:00
clusterListView = new QTableView();
clusterListView->setModel(clusterModel);
clusterListView->setSelectionMode(QAbstractItemView::SingleSelection);
clusterListView->setSelectionBehavior(QAbstractItemView::SelectRows);
clusterListView->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
clusterListView->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
clusterListView->horizontalHeader()->setSectionResizeMode(2, QHeaderView::ResizeToContents);
clusterListView->horizontalHeader()->setSectionResizeMode(3, QHeaderView::ResizeToContents);
clusterListView->horizontalHeader()->setSectionResizeMode(4, QHeaderView::ResizeToContents);
clusterListView->horizontalHeader()->setSectionResizeMode(5, QHeaderView::ResizeToContents);
clusterListView->horizontalHeader()->setSectionResizeMode(6, QHeaderView::ResizeToContents);
2022-04-25 20:34:04 +00:00
setSelectedClusterName("default");
2022-02-24 23:02:53 +00:00
2022-03-02 21:32:33 +00:00
connect(clusterListView, SIGNAL(clicked(QModelIndex)), this, SLOT(updateButtons()));
2022-02-24 23:02:53 +00:00
startButton = new QPushButton(tr("Start"));
stopButton = new QPushButton(tr("Stop"));
2022-04-25 20:34:04 +00:00
pauseButton = new QPushButton(tr("Pause"));
2022-02-24 23:02:53 +00:00
deleteButton = new QPushButton(tr("Delete"));
refreshButton = new QPushButton(tr("Refresh"));
createButton = new QPushButton(tr("Create"));
2022-03-02 23:43:14 +00:00
sshButton = new QPushButton(tr("SSH"));
dashboardButton = new QPushButton(tr("Dashboard"));
2022-04-15 18:43:32 +00:00
QPushButton *basicViewButton = new QPushButton(tr("Basic View"));
connect(basicViewButton, &QAbstractButton::clicked, this, &Window::toBasicView);
2022-02-24 23:02:53 +00:00
2022-03-02 23:43:14 +00:00
QHBoxLayout *topButtonLayout = new QHBoxLayout;
topButtonLayout->addWidget(createButton);
topButtonLayout->addWidget(refreshButton);
2022-04-15 18:43:32 +00:00
topButtonLayout->addWidget(basicViewButton);
2022-03-02 23:43:14 +00:00
topButtonLayout->addSpacing(340);
QHBoxLayout *bottomButtonLayout = new QHBoxLayout;
bottomButtonLayout->addWidget(startButton);
bottomButtonLayout->addWidget(stopButton);
2022-04-25 20:34:04 +00:00
bottomButtonLayout->addWidget(pauseButton);
2022-03-02 23:43:14 +00:00
bottomButtonLayout->addWidget(deleteButton);
bottomButtonLayout->addWidget(sshButton);
bottomButtonLayout->addWidget(dashboardButton);
2022-03-02 21:32:33 +00:00
QVBoxLayout *clusterLayout = new QVBoxLayout;
2022-03-02 23:43:14 +00:00
clusterLayout->addLayout(topButtonLayout);
2022-03-02 21:32:33 +00:00
clusterLayout->addWidget(clusterListView);
2022-03-02 23:43:14 +00:00
clusterLayout->addLayout(bottomButtonLayout);
2022-05-04 22:57:05 +00:00
advancedView->setLayout(clusterLayout);
QFont *loadingFont = new QFont();
loadingFont->setPointSize(30);
loading = new QLabel("Loading...");
loading->setFont(*loadingFont);
loading->setParent(clusterListView);
loading->setHidden(true);
2022-02-24 23:02:53 +00:00
}
void Window::updateButtons()
2022-04-15 18:43:32 +00:00
{
2022-04-26 19:43:41 +00:00
Cluster cluster = selectedCluster();
2022-04-15 18:43:32 +00:00
if (isBasicView) {
2022-04-26 19:43:41 +00:00
updateBasicButtons(cluster);
2022-04-15 18:43:32 +00:00
} else {
2022-04-26 19:43:41 +00:00
updateAdvancedButtons(cluster);
}
updateTrayActions(cluster);
2022-04-27 22:05:59 +00:00
updateStatus(cluster);
2022-04-26 19:43:41 +00:00
}
void Window::updateTrayActions(Cluster cluster)
{
bool isRunning = cluster.status() == "Running";
bool isPaused = cluster.status() == "Paused";
pauseAction->setEnabled(isRunning || isPaused);
stopAction->setEnabled(isRunning || isPaused);
2022-04-26 23:49:43 +00:00
pauseAction->setText(getPauseLabel(isRunning));
startAction->setText(getStartLabel(isRunning));
2022-04-15 18:43:32 +00:00
}
2022-04-25 20:34:04 +00:00
Cluster Window::selectedCluster()
{
QString clusterName = selectedClusterName();
if (clusterName.isEmpty()) {
return Cluster();
}
2022-04-26 23:49:43 +00:00
ClusterList clusters = clusterList;
2022-04-25 20:34:04 +00:00
ClusterHash clusterHash;
for (int i = 0; i < clusters.size(); i++) {
Cluster cluster = clusters.at(i);
clusterHash[cluster.name()] = cluster;
}
return clusterHash[clusterName];
}
2022-04-26 19:43:41 +00:00
void Window::updateBasicButtons(Cluster cluster)
2022-04-15 18:43:32 +00:00
{
2022-04-25 20:34:04 +00:00
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);
2022-04-28 19:48:25 +00:00
#if __linux__ || __APPLE__
2022-04-25 20:34:04 +00:00
basicSSHButton->setEnabled(exists);
2022-04-15 18:43:32 +00:00
#else
basicSSHButton->setEnabled(false);
#endif
2022-04-26 23:49:43 +00:00
basicPauseButton->setText(getPauseLabel(isPaused));
basicStartButton->setText(getStartLabel(isRunning));
}
QString Window::getPauseLabel(bool isPaused)
{
2022-04-25 20:34:04 +00:00
if (isPaused) {
2022-04-26 23:49:43 +00:00
return tr("Unpause");
2022-04-25 20:34:04 +00:00
}
2022-04-26 23:49:43 +00:00
return tr("Pause");
}
QString Window::getStartLabel(bool isRunning)
{
if (isRunning) {
return tr("Reload");
}
return tr("Start");
2022-04-15 18:43:32 +00:00
}
2022-04-25 20:34:04 +00:00
void Window::pauseOrUnpauseMinikube()
2022-02-24 23:02:53 +00:00
{
2022-04-25 20:34:04 +00:00
Cluster cluster = selectedCluster();
if (cluster.status() == "Paused") {
unpauseMinikube();
2022-02-24 23:02:53 +00:00
return;
}
2022-04-25 20:34:04 +00:00
pauseMinikube();
2022-02-24 23:02:53 +00:00
}
2022-04-26 19:43:41 +00:00
void Window::updateAdvancedButtons(Cluster cluster)
2022-02-24 23:02:53 +00:00
{
2022-04-25 20:34:04 +00:00
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);
2022-04-28 19:48:25 +00:00
#if __linux__ || __APPLE__
2022-04-25 20:34:04 +00:00
sshButton->setEnabled(exists);
#else
sshButton->setEnabled(false);
#endif
2022-04-26 23:49:43 +00:00
pauseButton->setText(getPauseLabel(isPaused));
startButton->setText(getStartLabel(isRunning));
2022-02-24 23:02:53 +00:00
}
bool Window::sendMinikubeCommand(QStringList cmds)
{
QString text;
return sendMinikubeCommand(cmds, text);
}
bool Window::sendMinikubeCommand(QStringList cmds, QString &text)
{
2022-03-02 23:43:14 +00:00
QString program = minikubePath();
if (program.isEmpty()) {
return false;
}
2022-04-18 22:53:51 +00:00
QStringList arguments = { "--user", "minikube-gui" };
2022-02-24 23:02:53 +00:00
arguments << cmds;
QProcess *process = new QProcess(this);
#if __APPLE__
if (env.isEmpty()) {
env = setMacEnv();
}
process->setProcessEnvironment(env);
#endif
2022-02-24 23:02:53 +00:00
process->start(program, arguments);
this->setCursor(Qt::WaitCursor);
bool timedOut = process->waitForFinished(300 * 1000);
int exitCode = process->exitCode();
bool success = !timedOut && exitCode == 0;
2022-02-24 23:02:53 +00:00
this->unsetCursor();
text = process->readAllStandardOutput();
2022-02-24 23:02:53 +00:00
if (success) {
} else {
2022-04-15 18:43:32 +00:00
qDebug() << text;
2022-02-24 23:02:53 +00:00
qDebug() << process->readAllStandardError();
}
delete process;
return success;
}
2022-05-05 22:55:20 +00:00
bool Window::sendMinikubeStart(QStringList cmds, QString &text)
{
QString program = minikubePath();
if (program.isEmpty()) {
return false;
}
QStringList arguments = { "--user", "minikube-gui" };
arguments << cmds;
QProcess *process = new QProcess(this);
connect(process, &QProcess::readyReadStandardOutput,
[process, this]() { startStep(process->readAllStandardOutput()); });
startProcess = process;
#if __APPLE__
if (env.isEmpty()) {
env = setMacEnv();
}
startProcess->setProcessEnvironment(env);
#endif
this->setCursor(Qt::WaitCursor);
startProcess->start(program, arguments);
startProgress();
while (startProcess->state() != QProcess::NotRunning) {
delay();
}
endProgress();
int exitCode = startProcess->exitCode();
bool success = exitCode == 0;
this->unsetCursor();
text = startProcess->readAllStandardOutput();
if (success) {
} else {
qDebug() << text;
qDebug() << startProcess->readAllStandardError();
}
delete startProcess;
return success;
}
void Window::startProgress()
{
progressDialog = new QDialog(this);
progressDialog->resize(300, 150);
progressDialog->setWindowTitle(tr("minikube start Progress"));
progressDialog->setWindowIcon(*trayIconIcon);
progressDialog->setWindowFlags(Qt::FramelessWindowHint);
progressDialog->setModal(true);
QVBoxLayout form(progressDialog);
progressText = new QLabel();
progressText->setText("Starting...");
progressText->setWordWrap(true);
form.addWidget(progressText);
progressBar.setMaximum(19);
form.addWidget(&progressBar);
QPushButton *cancel = new QPushButton(tr("Cancel"));
connect(cancel, &QAbstractButton::clicked, startProcess, &QProcess::kill);
form.addWidget(cancel);
progressDialog->open();
}
void Window::endProgress()
{
progressDialog->hide();
progressBar.setValue(0);
}
void Window::startStep(QString step)
{
QStringList lines;
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
lines = step.split("\n", Qt::SkipEmptyParts);
#else
lines = step.split("\n", QString::SkipEmptyParts);
#endif
for (int i = 0; i < lines.size(); i++) {
QJsonDocument json = QJsonDocument::fromJson(lines[i].toUtf8());
QJsonObject object = json.object();
QString type = object["type"].toString();
if (type != "io.k8s.sigs.minikube.step") {
return;
}
QJsonObject data = object["data"].toObject();
QString stringStep = data["currentstep"].toString();
int currStep = stringStep.toInt();
QString message = data["message"].toString();
progressBar.setValue(currStep);
progressText->setText(message);
}
}
2022-02-24 23:02:53 +00:00
static QString profile = "minikube";
static int cpus = 2;
static int memory = 2400;
static QString driver = "";
static QString containerRuntime = "";
2022-04-22 20:38:04 +00:00
static QString k8sVersion = "";
2022-02-24 23:02:53 +00:00
void Window::askName()
{
QDialog dialog;
2022-03-02 21:32:33 +00:00
dialog.setWindowTitle(tr("Create minikube Cluster"));
dialog.setWindowIcon(*trayIconIcon);
2022-02-24 23:02:53 +00:00
dialog.setModal(true);
QFormLayout form(&dialog);
QDialogButtonBox buttonBox(Qt::Horizontal, &dialog);
QLineEdit profileField(profile, &dialog);
form.addRow(new QLabel(tr("Profile")), &profileField);
buttonBox.addButton(QString(tr("Use Default Values")), QDialogButtonBox::AcceptRole);
connect(&buttonBox, &QDialogButtonBox::accepted, &dialog, &QDialog::accept);
buttonBox.addButton(QString(tr("Set Custom Values")), QDialogButtonBox::RejectRole);
connect(&buttonBox, &QDialogButtonBox::rejected, &dialog, &QDialog::reject);
form.addRow(&buttonBox);
int code = dialog.exec();
2022-03-02 23:43:14 +00:00
profile = profileField.text();
2022-02-24 23:02:53 +00:00
if (code == QDialog::Accepted) {
2022-04-06 22:28:18 +00:00
QStringList args = { "-p", profile };
startMinikube(args);
2022-02-24 23:02:53 +00:00
} else if (code == QDialog::Rejected) {
askCustom();
}
}
void Window::askCustom()
{
QDialog dialog;
2022-03-02 21:32:33 +00:00
dialog.setWindowTitle(tr("Set Cluster Values"));
dialog.setWindowIcon(*trayIconIcon);
2022-02-24 23:02:53 +00:00
dialog.setModal(true);
QFormLayout form(&dialog);
driverComboBox = new QComboBox;
2022-04-22 20:38:04 +00:00
driverComboBox->addItems({ "docker", "virtualbox", "vmware", "podman" });
2022-03-03 17:50:47 +00:00
#if __linux__
driverComboBox->addItem("kvm2");
#elif __APPLE__
2022-04-22 20:38:04 +00:00
driverComboBox->addItems({ "hyperkit", "parallels" });
2022-03-03 17:50:47 +00:00
#else
driverComboBox->addItem("hyperv");
#endif
2022-02-24 23:02:53 +00:00
form.addRow(new QLabel(tr("Driver")), driverComboBox);
containerRuntimeComboBox = new QComboBox;
2022-04-22 20:38:04 +00:00
containerRuntimeComboBox->addItems({ "docker", "containerd", "crio" });
2022-02-24 23:02:53 +00:00
form.addRow(new QLabel(tr("Container Runtime")), containerRuntimeComboBox);
2022-04-22 20:38:04 +00:00
k8sVersionComboBox = new QComboBox;
k8sVersionComboBox->addItems({ "stable", "latest", "none" });
form.addRow(new QLabel(tr("Kubernetes Version")), k8sVersionComboBox);
2022-02-24 23:02:53 +00:00
QLineEdit cpuField(QString::number(cpus), &dialog);
form.addRow(new QLabel(tr("CPUs")), &cpuField);
QLineEdit memoryField(QString::number(memory), &dialog);
form.addRow(new QLabel(tr("Memory")), &memoryField);
QDialogButtonBox buttonBox(Qt::Horizontal, &dialog);
buttonBox.addButton(QString(tr("Create")), QDialogButtonBox::AcceptRole);
connect(&buttonBox, &QDialogButtonBox::accepted, &dialog, &QDialog::accept);
buttonBox.addButton(QString(tr("Cancel")), QDialogButtonBox::RejectRole);
connect(&buttonBox, &QDialogButtonBox::rejected, &dialog, &QDialog::reject);
form.addRow(&buttonBox);
int code = dialog.exec();
if (code == QDialog::Accepted) {
driver = driverComboBox->itemText(driverComboBox->currentIndex());
2022-03-02 23:53:42 +00:00
containerRuntime =
containerRuntimeComboBox->itemText(containerRuntimeComboBox->currentIndex());
2022-04-22 20:38:04 +00:00
k8sVersion = k8sVersionComboBox->itemText(k8sVersionComboBox->currentIndex());
if (k8sVersion == "none") {
k8sVersion = "v0.0.0";
}
2022-02-24 23:02:53 +00:00
cpus = cpuField.text().toInt();
memory = memoryField.text().toInt();
2022-04-06 22:28:18 +00:00
QStringList args = { "-p",
2022-03-02 23:53:42 +00:00
profile,
"--driver",
driver,
"--container-runtime",
containerRuntime,
2022-04-22 20:38:04 +00:00
"--kubernetes-version",
k8sVersion,
2022-03-02 23:53:42 +00:00
"--cpus",
QString::number(cpus),
"--memory",
2022-04-06 22:32:17 +00:00
QString::number(memory) };
2022-04-06 22:28:18 +00:00
startMinikube(args);
}
}
2022-04-06 22:32:17 +00:00
void Window::outputFailedStart(QString text)
{
QStringList lines;
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
lines = text.split("\n", Qt::SkipEmptyParts);
#else
lines = text.split("\n", QString::SkipEmptyParts);
#endif
for (int i = 0; i < lines.size(); i++) {
QString line = lines.at(i);
QJsonParseError error;
QJsonDocument json = QJsonDocument::fromJson(line.toUtf8(), &error);
if (json.isNull() || !json.isObject()) {
continue;
}
QJsonObject par = json.object();
QJsonObject data = par["data"].toObject();
if (!data.contains("exitcode")) {
continue;
}
QString advice = data["advice"].toString();
QString message = data["message"].toString();
QString name = data["name"].toString();
QString url = data["url"].toString();
QString issues = data["issues"].toString();
QDialog dialog;
dialog.setWindowTitle(tr("minikube start failed"));
dialog.setWindowIcon(*trayIconIcon);
dialog.setFixedWidth(600);
dialog.setModal(true);
QFormLayout form(&dialog);
2022-04-08 18:43:14 +00:00
createLabel("Error Code", name, &form, false);
createLabel("Advice", advice, &form, false);
2022-05-04 22:57:05 +00:00
QTextEdit *errorMessage = new QTextEdit();
errorMessage->setText(message);
errorMessage->setWordWrapMode(QTextOption::WrapAnywhere);
2022-04-28 22:06:13 +00:00
int pointSize = errorMessage->font().pointSize();
errorMessage->setFont(QFont("Courier", pointSize));
errorMessage->setAutoFillBackground(true);
2022-05-04 22:57:05 +00:00
errorMessage->setReadOnly(true);
form.addRow(errorMessage);
2022-04-08 18:43:14 +00:00
createLabel("Link to documentation", url, &form, true);
createLabel("Link to related issue", issues, &form, true);
QLabel *fileLabel = new QLabel(this);
fileLabel->setOpenExternalLinks(true);
fileLabel->setWordWrap(true);
QString logFile = QDir::homePath() + "/.minikube/logs/lastStart.txt";
fileLabel->setText("<a href='file:///" + logFile + "'>View log file</a>");
form.addRow(fileLabel);
QDialogButtonBox buttonBox(Qt::Horizontal, &dialog);
buttonBox.addButton(QString(tr("OK")), QDialogButtonBox::AcceptRole);
connect(&buttonBox, &QDialogButtonBox::accepted, &dialog, &QDialog::accept);
form.addRow(&buttonBox);
dialog.exec();
2022-02-24 23:02:53 +00:00
}
}
2022-04-08 18:45:08 +00:00
QLabel *Window::createLabel(QString title, QString text, QFormLayout *form, bool isLink)
2022-04-08 18:43:14 +00:00
{
QLabel *label = new QLabel(this);
if (!text.isEmpty()) {
form->addRow(label);
}
if (isLink) {
label->setOpenExternalLinks(true);
text = "<a href='" + text + "'>" + text + "</a>";
}
label->setWordWrap(true);
label->setText(title + ": " + text);
return label;
}
2022-02-24 23:02:53 +00:00
void Window::initMachine()
{
askName();
2022-04-26 23:49:43 +00:00
updateClustersTable();
2022-02-24 23:02:53 +00:00
}
2022-03-02 23:43:14 +00:00
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);
2022-04-25 20:34:04 +00:00
QStringList args = { "ssh", "-p", selectedClusterName() };
2022-03-02 23:43:14 +00:00
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();
2022-04-28 19:48:25 +00:00
#elif __APPLE__
QString command = program + " ssh -p " + selectedClusterName();
2022-05-03 23:24:51 +00:00
QStringList arguments = { "-e", "tell app \"Terminal\"", "-e", "activate",
"-e", "do script \"" + command + "\"", "-e", "end tell" };
2022-04-28 19:48:25 +00:00
QProcess *process = new QProcess(this);
process->start("/usr/bin/osascript", arguments);
2022-03-02 23:43:14 +00:00
#else
QString terminal = qEnvironmentVariable("TERMINAL");
if (terminal.isEmpty()) {
terminal = "x-terminal-emulator";
if (QStandardPaths::findExecutable(terminal).isEmpty()) {
terminal = "xterm";
}
}
2022-04-25 20:34:04 +00:00
QStringList arguments = { "-e", QString("%1 ssh -p %2").arg(program, selectedClusterName()) };
2022-03-02 23:43:14 +00:00
QProcess *process = new QProcess(this);
process->start(QStandardPaths::findExecutable(terminal), arguments);
#endif
}
#if __APPLE__
2022-05-04 22:13:33 +00:00
bool Window::hyperkitPermissionFix(QStringList args, QString text)
{
if (!text.contains("docker-machine-driver-hyperkit needs to run with elevated permissions")) {
return false;
}
if (!showHyperKitMessage()) {
return false;
}
hyperkitPermission();
return sendMinikubeCommand(args, text);
}
void Window::hyperkitPermission()
{
QString command = "sudo chown root:wheel ~/.minikube/bin/docker-machine-driver-hyperkit && "
"sudo chmod u+s ~/.minikube/bin/docker-machine-driver-hyperkit && exit";
QStringList arguments = { "-e", "tell app \"Terminal\"",
"-e", "set w to do script \"" + command + "\"",
"-e", "activate",
"-e", "repeat",
"-e", "delay 0.1",
"-e", "if not busy of w then exit repeat",
"-e", "end repeat",
"-e", "end tell" };
QProcess *process = new QProcess(this);
process->start("/usr/bin/osascript", arguments);
process->waitForFinished(-1);
}
2022-05-04 22:13:33 +00:00
bool Window::showHyperKitMessage()
{
2022-05-04 22:13:33 +00:00
QMessageBox msgBox;
msgBox.setWindowTitle(tr("HyperKit Permissions Required"));
msgBox.setWindowIcon(*trayIconIcon);
msgBox.setModal(true);
msgBox.setText(tr("The HyperKit driver requires a one-time sudo permission.\n\nIf you'd like "
"to proceed, press OK and then enter your password into the terminal prompt, "
"the start will resume after."));
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Ok);
int code = msgBox.exec();
return code == QMessageBox::Ok;
}
#endif
2022-03-02 23:43:14 +00:00
void Window::dashboardBrowser()
{
dashboardClose();
QString program = minikubePath();
QProcess *process = new QProcess(this);
2022-04-25 20:34:04 +00:00
QStringList arguments = { "dashboard", "-p", selectedClusterName() };
2022-03-02 23:43:14 +00:00
process->start(program, arguments);
dashboardProcess = process;
dashboardProcess->waitForStarted();
}
void Window::dashboardClose()
{
if (dashboardProcess) {
dashboardProcess->terminate();
dashboardProcess->waitForFinished();
}
}
void Window::checkForMinikube()
{
QString program = minikubePath();
if (!program.isEmpty()) {
return;
}
QDialog dialog;
dialog.setWindowTitle(tr("minikube"));
dialog.setWindowIcon(*trayIconIcon);
dialog.setModal(true);
QFormLayout form(&dialog);
QLabel *message = new QLabel(this);
message->setText("minikube was not found on the path.\nPlease follow the install instructions "
"below to install minikube first.\n");
form.addWidget(message);
QLabel *link = new QLabel(this);
link->setOpenExternalLinks(true);
link->setText("<a "
"href='https://minikube.sigs.k8s.io/docs/start/'>https://minikube.sigs.k8s.io/"
"docs/start/</a>");
form.addWidget(link);
QDialogButtonBox buttonBox(Qt::Horizontal, &dialog);
buttonBox.addButton(QString(tr("OK")), QDialogButtonBox::AcceptRole);
connect(&buttonBox, &QDialogButtonBox::accepted, &dialog, &QDialog::accept);
form.addRow(&buttonBox);
dialog.exec();
exit(EXIT_FAILURE);
}
2022-05-03 23:24:51 +00:00
void Window::checkForUpdates()
{
QString releases = getRequest("https://storage.googleapis.com/minikube-gui/releases.json");
QJsonObject latestRelease =
QJsonDocument::fromJson(releases.toUtf8()).array().first().toObject();
QString latestReleaseVersion = latestRelease["name"].toString();
QVersionNumber latestReleaseVersionNumber = QVersionNumber::fromString(latestReleaseVersion);
if (version >= latestReleaseVersionNumber) {
return;
}
QJsonObject links = latestRelease["links"].toObject();
2022-05-03 23:34:32 +00:00
QString key;
2022-05-03 23:24:51 +00:00
#if __linux__
2022-05-03 23:34:32 +00:00
key = "linux";
2022-05-03 23:24:51 +00:00
#elif __APPLE__
2022-05-03 23:34:32 +00:00
key = "darwin";
2022-05-03 23:24:51 +00:00
#else
2022-05-03 23:34:32 +00:00
key = "windows";
2022-05-03 23:24:51 +00:00
#endif
2022-05-03 23:34:32 +00:00
QString link = links[key].toString();
2022-05-03 23:24:51 +00:00
notifyUpdate(latestReleaseVersion, link);
}
void Window::notifyUpdate(QString latest, QString link)
{
QDialog dialog;
dialog.setWindowTitle(tr("minikube GUI Update Available"));
dialog.setWindowIcon(*trayIconIcon);
dialog.setModal(true);
QFormLayout form(&dialog);
QLabel *msgLabel = new QLabel(this);
msgLabel->setText("Version " + latest
+ " of minikube GUI is now available!\n\nDownload the update from:");
form.addWidget(msgLabel);
QLabel *linkLabel = new QLabel(this);
linkLabel->setOpenExternalLinks(true);
linkLabel->setText("<a href=\"" + link + "\">" + link + "</a>");
form.addWidget(linkLabel);
QDialogButtonBox buttonBox(Qt::Horizontal, &dialog);
buttonBox.addButton(QString(tr("OK")), QDialogButtonBox::AcceptRole);
connect(&buttonBox, &QDialogButtonBox::accepted, &dialog, &QDialog::accept);
form.addRow(&buttonBox);
dialog.exec();
}
QString Window::getRequest(QString url)
{
QNetworkAccessManager *manager = new QNetworkAccessManager();
QObject::connect(manager, &QNetworkAccessManager::finished, this, [=](QNetworkReply *reply) {
if (reply->error()) {
qDebug() << reply->errorString();
}
});
QNetworkReply *resp = manager->get(QNetworkRequest(QUrl(url)));
QEventLoop loop;
connect(resp, &QNetworkReply::finished, &loop, &QEventLoop::quit);
loop.exec();
return resp->readAll();
}
2022-02-24 23:02:53 +00:00
#endif