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 \
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
21 changes: 15 additions & 6 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,17 +155,21 @@ 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);
deleteButton->setEnabled(exists);
dashboardButton->setEnabled(isRunning);
#if __linux__ || __APPLE__
dockerEnvButton->setEnabled(isRunning);
sshButton->setEnabled(exists);
dockerEnvButton->setEnabled(isRunning || isPaused);
sshButton->setEnabled(isRunning || isPaused);
mountButton->setEnabled(isRunning || isPaused);
tunnelButton->setEnabled(isRunning || isPaused);
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't have to be done in this PR, but we should make a variable called isRunningOrPaused instead of repeatedly doing isRunning || isPaused

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good idea

#else
dockerEnvButton->setEnabled(false);
sshButton->setEnabled(false);
mountButton->setEnabled(false);
tunnelButton->setEnabled(false);
#endif
pauseButton->setText(getPauseLabel(isPaused));
pauseButton->setToolTip(getPauseToolTip(isPaused));
Expand All @@ -182,6 +189,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(QString pName)
{
m_command = "service";
QStringList args = { "-p", pName, "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(QString profName);
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(selectedClusterName());
}

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
11 changes: 8 additions & 3 deletions src/operator.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ limitations under the License.

#include "advancedview.h"
#include "basicview.h"
#include "serviceview.h"
#include "cluster.h"
#include "commandrunner.h"
#include "errormessage.h"
Expand All @@ -34,9 +35,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 +57,7 @@ private slots:
void createCluster(QStringList args);
void updateButtons();
void clustersReceived(ClusterList clusterList);
void servicesReceived(QString);
void startCommandStarting();

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

AdvancedView *m_advancedView;
BasicView *m_basicView;
ServiceView *m_serviceView;
CommandRunner *m_commandRunner;
ErrorMessage *m_errorMessage;
ProgressWindow *m_progressWindow;
Expand Down
48 changes: 48 additions & 0 deletions src/serviceview.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
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 <QFormLayout>
#include <QLabel>

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

void ServiceView::displayTable(QString svcCmdOutput)
{

m_dialog = new QDialog(m_parent);
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);
Comment on lines +38 to +41
Copy link
Member

Choose a reason for hiding this comment

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

Not required, but going forward you can pass a QString to the QLabel constructor and it will pass the QString to setText in the constructor.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good to know thanks

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();
}
40 changes: 40 additions & 0 deletions src/serviceview.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
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.
*/

#ifndef SERVICEVIEW_H
#define SERVICEVIEW_H

#include <QObject>
#include <QIcon>
#include <QString>
#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