Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add service list to gui #26

Merged
merged 15 commits into from
Feb 13, 2023
2 changes: 2 additions & 0 deletions minikube.pro
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ HEADERS = src/window.h \
src/operator.h \
src/paths.h \
src/progresswindow.h \
src/serviceView.h \
spowelljr marked this conversation as resolved.
Show resolved Hide resolved
src/tray.h \
src/updater.h
SOURCES = src/main.cpp \
Expand All @@ -28,6 +29,7 @@ SOURCES = src/main.cpp \
src/operator.cpp \
src/paths.cpp \
src/progresswindow.cpp \
src/serviceView.cpp \
src/tray.cpp \
src/updater.cpp \
src/window.cpp
Expand Down
17 changes: 12 additions & 5 deletions src/basicview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,14 @@ BasicView::BasicView(QIcon icon)
stopButton = new QPushButton(Constants::stopIcon);
pauseButton = new QPushButton(Constants::pauseIcon);
deleteButton = new QPushButton(Constants::deleteIcon);
refreshButton = new QPushButton(tr("Refresh GUI"));
refreshButton = new QPushButton(tr("refresh gui"));
dockerEnvButton = new QPushButton("docker-env");
serviceButton = new QPushButton("service");
mountButton = new QPushButton(tr("mount"));
tunnelButton = new QPushButton(tr("tunnel"));
sshButton = new QPushButton("SSH");
dashboardButton = new QPushButton(tr("Dashboard"));
advancedButton = new QPushButton(tr("Multi-cluster View"));
dashboardButton = new QPushButton(tr("dashboard"));
advancedButton = new QPushButton(tr("cluster list"));

Fonts::setFontAwesome(startButton);
Fonts::setFontAwesome(stopButton);
Expand All @@ -75,6 +76,7 @@ BasicView::BasicView(QIcon icon)
QVBoxLayout *buttonLayoutRow2 = new QVBoxLayout;
buttonLayoutRow2->addWidget(refreshButton);
buttonLayoutRow2->addWidget(dockerEnvButton);
buttonLayoutRow2->addWidget(serviceButton);
buttonLayoutRow2->addWidget(mountButton);
buttonLayoutRow2->addWidget(tunnelButton);
buttonLayoutRow2->addWidget(sshButton);
Expand All @@ -95,6 +97,7 @@ BasicView::BasicView(QIcon icon)
connect(deleteButton, &QAbstractButton::clicked, this, &BasicView::delete_);
connect(refreshButton, &QAbstractButton::clicked, this, &BasicView::refresh);
connect(dockerEnvButton, &QAbstractButton::clicked, this, &BasicView::dockerEnv);
connect(serviceButton, &QPushButton::clicked, this, &BasicView::service);
connect(mountButton, &QAbstractButton::clicked, this, &BasicView::askMount);
connect(tunnelButton, &QAbstractButton::clicked, this, &BasicView::tunnel);
connect(sshButton, &QAbstractButton::clicked, this, &BasicView::ssh);
Expand Down Expand Up @@ -152,14 +155,16 @@ void BasicView::update(Cluster cluster)
bool isRunning = cluster.status() == "Running";
bool isPaused = cluster.status() == "Paused";
topStatus->setText(cluster.status());
serviceButton->setEnabled(isRunning || isPaused);
stopButton->setEnabled(isRunning || isPaused);
pauseButton->setEnabled(isRunning || isPaused);
mountButton->setEnabled(isRunning || isPaused);
tunnelButton->setEnabled(isRunning || isPaused);
deleteButton->setEnabled(exists);
dashboardButton->setEnabled(isRunning);
#if __linux__ || __APPLE__
dockerEnvButton->setEnabled(isRunning);
sshButton->setEnabled(exists);
dockerEnvButton->setEnabled(isRunning || isPaused);
sshButton->setEnabled(isRunning || isPaused);
#else
spowelljr marked this conversation as resolved.
Show resolved Hide resolved
dockerEnvButton->setEnabled(false);
sshButton->setEnabled(false);
Expand All @@ -182,6 +187,8 @@ void BasicView::disableButtons()
deleteButton->setEnabled(false);
pauseButton->setEnabled(false);
dockerEnvButton->setEnabled(false);
serviceButton->setEnabled(false);
tunnelButton->setEnabled(false);
mountButton->setEnabled(false);
sshButton->setEnabled(false);
dashboardButton->setEnabled(false);
Expand Down
2 changes: 2 additions & 0 deletions src/basicview.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class BasicView : public QObject
void delete_();
void refresh();
void dockerEnv();
void service();
void ssh();
void dashboard();
void advanced();
Expand All @@ -57,6 +58,7 @@ class BasicView : public QObject
QPushButton *deleteButton;
QPushButton *refreshButton;
QPushButton *dockerEnvButton;
QPushButton *serviceButton;
QPushButton *mountButton;
QPushButton *tunnelButton;
QPushButton *sshButton;
Expand Down
10 changes: 10 additions & 0 deletions src/commandrunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,13 @@ void CommandRunner::requestClusters()
executeMinikubeCommand(args);
}

void CommandRunner::requestServiceList()
spowelljr marked this conversation as resolved.
Show resolved Hide resolved
{
m_command = "service";
QStringList args = { "service", "list" };
executeMinikubeCommand(args);
}

void CommandRunner::executionCompleted()
{
m_isRunning = false;
Expand All @@ -288,6 +295,9 @@ void CommandRunner::executionCompleted()
ClusterList clusterList = jsonToClusterList(output);
emit updatedClusters(clusterList);
}
if (cmd == "service") {
emit updatedServices(output);
}
}

void CommandRunner::errorReady()
Expand Down
2 changes: 2 additions & 0 deletions src/commandrunner.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class CommandRunner : public QObject
void dashboardMinikube(QStringList args, QProcess *process);
void stopCommand();
void requestClusters();
void requestServiceList();
bool isRunning();

signals:
Expand All @@ -54,6 +55,7 @@ class CommandRunner : public QObject
void output(QString text);
void error(QStringList args, QString text);
void updatedClusters(ClusterList clusterList);
void updatedServices(QString);
void startCommandStarting();

private slots:
Expand Down
3 changes: 2 additions & 1 deletion src/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ limitations under the License.
class Constants
{
public:
const static int basicViewHeight = 300;
// golden ration
const static int basicViewHeight = 405;
const static int basicViewWidth = 250;
static const QString startIcon;
static const QString stopIcon;
Expand Down
21 changes: 17 additions & 4 deletions src/operator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ limitations under the License.
#include <QStandardPaths>
#include <QDebug>

Operator::Operator(AdvancedView *advancedView, BasicView *basicView, CommandRunner *commandRunner,
ErrorMessage *errorMessage, ProgressWindow *progressWindow, Tray *tray,
HyperKit *hyperKit, Updater *updater, QStackedWidget *stackedWidget,
QDialog *parent)
Operator::Operator(AdvancedView *advancedView, BasicView *basicView, ServiceView *serviceView,
CommandRunner *commandRunner, ErrorMessage *errorMessage,
ProgressWindow *progressWindow, Tray *tray, HyperKit *hyperKit, Updater *updater,
QStackedWidget *stackedWidget, QDialog *parent)
{
m_advancedView = advancedView;
m_basicView = basicView;
m_serviceView = serviceView;
m_commandRunner = commandRunner;
m_errorMessage = errorMessage;
m_progressWindow = progressWindow;
Expand All @@ -49,6 +50,7 @@ Operator::Operator(AdvancedView *advancedView, BasicView *basicView, CommandRunn
connect(m_basicView, &BasicView::delete_, this, &Operator::deleteMinikube);
connect(m_basicView, &BasicView::refresh, this, &Operator::updateClusters);
connect(m_basicView, &BasicView::dockerEnv, this, &Operator::dockerEnv);
connect(m_basicView, &BasicView::service, this, &Operator::updateServices);
connect(m_basicView, &BasicView::mount, this, &Operator::mount);
connect(m_basicView, &BasicView::closeMount, this, &Operator::mountClose);
connect(m_basicView, &BasicView::tunnel, this, &Operator::tunnel);
Expand All @@ -74,6 +76,7 @@ Operator::Operator(AdvancedView *advancedView, BasicView *basicView, CommandRunn
connect(m_commandRunner, &CommandRunner::output, this, &Operator::commandOutput);
connect(m_commandRunner, &CommandRunner::error, this, &Operator::commandError);
connect(m_commandRunner, &CommandRunner::updatedClusters, this, &Operator::clustersReceived);
connect(m_commandRunner, &CommandRunner::updatedServices, this, &Operator::servicesReceived);
connect(m_commandRunner, &CommandRunner::startCommandStarting, this,
&Operator::startCommandStarting);

Expand Down Expand Up @@ -186,6 +189,11 @@ void Operator::updateClusters()
m_commandRunner->requestClusters();
}

void Operator::updateServices()
{
m_commandRunner->requestServiceList();
}

void Operator::clustersReceived(ClusterList clusterList)
{
m_clusterList = clusterList;
Expand All @@ -196,6 +204,11 @@ void Operator::clustersReceived(ClusterList clusterList)
m_updater->checkForUpdates();
}

void Operator::servicesReceived(QString svcTable)
{
m_serviceView->displayTable(svcTable);
}

void Operator::updateButtons()
{
Cluster cluster = selectedCluster();
Expand Down
12 changes: 9 additions & 3 deletions src/operator.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ limitations under the License.

#include "advancedview.h"
#include "basicview.h"
#include "serviceView.h"
#include "serviceView.h"
spowelljr marked this conversation as resolved.
Show resolved Hide resolved
#include "cluster.h"
#include "commandrunner.h"
#include "errormessage.h"
Expand All @@ -34,9 +36,10 @@ class Operator : public QObject
Q_OBJECT

public:
Operator(AdvancedView *advancedView, BasicView *basicView, CommandRunner *commandRunner,
ErrorMessage *errorMessage, ProgressWindow *progressWindow, Tray *tray,
HyperKit *hyperKit, Updater *updater, QStackedWidget *stackedWidget, QDialog *parent);
Operator(AdvancedView *advancedView, BasicView *basicView, ServiceView *serviceView,
CommandRunner *commandRunner, ErrorMessage *errorMessage,
ProgressWindow *progressWindow, Tray *tray, HyperKit *hyperKit, Updater *updater,
QStackedWidget *stackedWidget, QDialog *parent);

public slots:
void startMinikube();
Expand All @@ -55,6 +58,7 @@ private slots:
void createCluster(QStringList args);
void updateButtons();
void clustersReceived(ClusterList clusterList);
void servicesReceived(QString);
void startCommandStarting();

private:
Expand All @@ -64,6 +68,7 @@ private slots:
Cluster selectedCluster();
void sshConsole();
void dockerEnv();
void updateServices();
void mount(QString, QString);
void tunnelClean();
void tunnel();
Expand All @@ -78,6 +83,7 @@ private slots:

AdvancedView *m_advancedView;
BasicView *m_basicView;
ServiceView *m_serviceView;
CommandRunner *m_commandRunner;
ErrorMessage *m_errorMessage;
ProgressWindow *m_progressWindow;
Expand Down
58 changes: 58 additions & 0 deletions src/serviceView.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
Copyright 2023 The Kubernetes Authors All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#include "serviceView.h"

#include <QDialogButtonBox>
#include <QDir>
#include <QFormLayout>
#include <QLabel>
#include <QTextEdit>
#include <QTextOption>
spowelljr marked this conversation as resolved.
Show resolved Hide resolved

#include <QDialogButtonBox>
#include <QDir>
#include <QFormLayout>
#include <QLabel>
#include <QTextEdit>
#include <QTextOption>
medyagh marked this conversation as resolved.
Show resolved Hide resolved

ServiceView::ServiceView(QDialog *parent, QIcon icon)
{
m_parent = parent;
m_icon = icon;
}

void ServiceView::displayTable(QString svcCmdOutput)
{

m_dialog = new QDialog(m_parent);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
m_dialog = new QDialog(m_parent);
QDialog dialog = new QDialog(m_parent);

This doesn't need to be a class wide variable as the variable isn't used outside this function.

m_dialog->setWindowTitle(tr("Service List"));
m_dialog->setWindowIcon(m_icon);
m_dialog->setFixedWidth(600);
m_dialog->setModal(true);
QFormLayout form(m_dialog);
QLabel *tableLbl = new QLabel();
tableLbl->setOpenExternalLinks(true);
tableLbl->setWordWrap(true);
tableLbl->setText(svcCmdOutput);
form.addRow(tableLbl);
QDialogButtonBox buttonBox(Qt::Horizontal, m_dialog);
buttonBox.addButton(QString(tr("OK")), QDialogButtonBox::AcceptRole);
connect(&buttonBox, &QDialogButtonBox::accepted, m_dialog, &QDialog::accept);
form.addRow(&buttonBox);
m_dialog->exec();
}
25 changes: 25 additions & 0 deletions src/serviceView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef SERVICEVIEW_H
spowelljr marked this conversation as resolved.
Show resolved Hide resolved
#define SERVICEVIEW_H

#include <QObject>
#include <QPushButton>
#include <QLabel>
#include <QString>
spowelljr marked this conversation as resolved.
Show resolved Hide resolved
#include <QDialog>

class ServiceView : public QObject
{
Q_OBJECT

public:
explicit ServiceView(QDialog *parent, QIcon icon);

void displayTable(QString);

private:
QDialog *m_dialog;
QIcon m_icon;
QDialog *m_parent;
};

#endif // SERVICEVIEW_H
6 changes: 4 additions & 2 deletions src/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ limitations under the License.
#include "paths.h"
#include "fonts.h"
#include "constants.h"
#include "serviceView.h"

#ifndef QT_NO_SYSTEMTRAYICON

Expand Down Expand Up @@ -69,15 +70,16 @@ Window::Window()
logger = new Logger();
commandRunner = new CommandRunner(this, logger);
basicView = new BasicView(*trayIconIcon);
serviceView = new ServiceView(this, *trayIconIcon);
advancedView = new AdvancedView(*trayIconIcon);
errorMessage = new ErrorMessage(this, *trayIconIcon);
progressWindow = new ProgressWindow(this, *trayIconIcon);
tray = new Tray(*trayIconIcon);
hyperKit = new HyperKit(*trayIconIcon);
updater = new Updater(version, *trayIconIcon);

op = new Operator(advancedView, basicView, commandRunner, errorMessage, progressWindow, tray,
hyperKit, updater, stackedWidget, this);
op = new Operator(advancedView, basicView, serviceView, commandRunner, errorMessage,
progressWindow, tray, hyperKit, updater, stackedWidget, this);

stackedWidget->addWidget(basicView->basicView);
stackedWidget->addWidget(advancedView->advancedView);
Expand Down
2 changes: 2 additions & 0 deletions src/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ QT_END_NAMESPACE

#include "advancedview.h"
#include "basicview.h"
#include "serviceView.h"
#include "errormessage.h"
#include "hyperkit.h"
#include "logger.h"
Expand Down Expand Up @@ -79,6 +80,7 @@ class Window : public QDialog
void notifyUpdate(QString latest, QString link);

BasicView *basicView;
ServiceView *serviceView;
AdvancedView *advancedView;
Operator *op;
CommandRunner *commandRunner;
Expand Down