Skip to content

Commit

Permalink
finish implementing settings
Browse files Browse the repository at this point in the history
  • Loading branch information
spowelljr committed Mar 9, 2023
1 parent dab4fb2 commit 962d468
Show file tree
Hide file tree
Showing 13 changed files with 187 additions and 27 deletions.
4 changes: 4 additions & 0 deletions minikube.pro
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ HEADERS = src/window.h \
src/paths.h \
src/progresswindow.h \
src/serviceview.h \
src/setting.h \
src/settings.h \
src/tray.h \
src/updater.h
SOURCES = src/main.cpp \
Expand All @@ -33,6 +35,8 @@ SOURCES = src/main.cpp \
src/paths.cpp \
src/progresswindow.cpp \
src/serviceview.cpp \
src/setting.cpp \
src/settings.cpp \
src/tray.cpp \
src/updater.cpp \
src/window.cpp
Expand Down
24 changes: 17 additions & 7 deletions src/basicview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ void BasicView::disableButtons()

void BasicView::askMount()
{

QDialog dialog;
dialog.setWindowIcon(m_icon);
dialog.setModal(true);
Expand Down Expand Up @@ -276,7 +275,6 @@ void BasicView::askMount()

void BasicView::askSettings()
{

QDialog dialog;
dialog.setWindowIcon(m_icon);
dialog.setModal(true);
Expand All @@ -286,19 +284,31 @@ void BasicView::askSettings()
QDialogButtonBox buttonBox(Qt::Horizontal, &dialog);
QLineEdit binaryPath(&dialog);
QCheckBox warnCloseCheck(&dialog);
binaryPath.setText(m_setting.minikubeBinaryPath());
warnCloseCheck.setChecked(m_setting.skipWarningOnClose());

form.addRow(new QLabel(tr("path to minikube binary")), &binaryPath);
form.addRow(new QLabel(tr("skip warn runs in background on close")), &warnCloseCheck);
form.addRow(new QLabel(tr("Path to minikube binary")), &binaryPath);
form.addRow(new QLabel(tr("Skip warn runs in background on close")), &warnCloseCheck);

buttonBox.addButton(QString(tr("save")), QDialogButtonBox::AcceptRole);
buttonBox.addButton(QString(tr("Save")), QDialogButtonBox::AcceptRole);
buttonBox.addButton(QString(tr("Cancel")), QDialogButtonBox::RejectRole);
form.addRow(&buttonBox);

connect(&buttonBox, &QDialogButtonBox::accepted, &dialog, &QDialog::accept);
connect(&buttonBox, &QDialogButtonBox::rejected, &dialog, &QDialog::reject);

int code = dialog.exec();
if (code == QDialog::Accepted) {
emit sendSettings(binaryPath.text(), false);
if (code != QDialog::Accepted) {
return;
}
Setting *s = new Setting();
s->setMinikubeBinaryPath(binaryPath.text());
s->setSkipWarningOnClose(warnCloseCheck.isChecked());
m_setting = *s;
emit saveSettings(*s);
}

void BasicView::receivedSettings(Setting s)
{
m_setting = s;
}
6 changes: 5 additions & 1 deletion src/basicview.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ limitations under the License.

#include "cluster.h"
#include "mount.h"
#include "setting.h"

#include <QPushButton>
#include <QLabel>
#include <QSettings>

class BasicView : public QObject
{
Expand All @@ -34,6 +36,7 @@ class BasicView : public QObject
void updateMounts(MountList ms);
void disableButtons();
void setFont(QFont font, QWidget *wid);
void receivedSettings(Setting s);
signals:
void start();
void stop();
Expand All @@ -46,7 +49,7 @@ class BasicView : public QObject
void dashboard();
void advanced();
void mount(QString, QString);
void sendSettings(QString, bool);
void saveSettings(Setting s);
void closeMount();
void tunnel();
void addons();
Expand All @@ -71,6 +74,7 @@ class BasicView : public QObject
QPushButton *exitButton;
QIcon m_icon;
MountList m_mountList;
Setting m_setting;
void askMount();
void askSettings();
};
Expand Down
1 change: 0 additions & 1 deletion src/errormessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ ErrorMessage::ErrorMessage(QDialog *parent, QIcon icon)
void ErrorMessage::error(QString errorCode, QString advice, QString message, QString url,
QString issues)
{

m_dialog = new QDialog(m_parent);
m_dialog->setWindowTitle(tr("minikube start failed"));
m_dialog->setWindowIcon(m_icon);
Expand Down
23 changes: 10 additions & 13 deletions src/operator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@ limitations under the License.
#include <QPushButton>
#include <QStandardPaths>
#include <QDebug>
#include <QSettings>

Operator::Operator(AdvancedView *advancedView, BasicView *basicView, ServiceView *serviceView,
AddonsView *addonsView, CommandRunner *commandRunner, ErrorMessage *errorMessage,
ProgressWindow *progressWindow, Tray *tray, HyperKit *hyperKit, Updater *updater,
QStackedWidget *stackedWidget, QDialog *parent)
Settings *settings, QStackedWidget *stackedWidget, QDialog *parent)
{
m_advancedView = advancedView;
m_basicView = basicView;
Expand All @@ -41,6 +40,7 @@ Operator::Operator(AdvancedView *advancedView, BasicView *basicView, ServiceView
m_tray = tray;
m_hyperKit = hyperKit;
m_updater = updater;
m_settings = settings;
m_stackedWidget = stackedWidget;
m_parent = parent;
m_isBasicView = true;
Expand All @@ -56,7 +56,7 @@ Operator::Operator(AdvancedView *advancedView, BasicView *basicView, ServiceView
connect(m_basicView, &BasicView::addons, this, &Operator::displayAddons);
connect(m_basicView, &BasicView::mount, this, &Operator::mount);
connect(m_basicView, &BasicView::closeMount, this, &Operator::mountClose);
connect(m_basicView, &BasicView::sendSettings, this, &Operator::updateSettings);
connect(m_basicView, &BasicView::saveSettings, this, &Operator::updateSettings);
connect(m_basicView, &BasicView::tunnel, this, &Operator::tunnel);
connect(m_basicView, &BasicView::ssh, this, &Operator::sshConsole);
connect(m_basicView, &BasicView::dashboard, this, &Operator::dashboardBrowser);
Expand Down Expand Up @@ -100,6 +100,7 @@ Operator::Operator(AdvancedView *advancedView, BasicView *basicView, ServiceView
connect(m_addonsView, &AddonsView::addonClicked, this, &Operator::addonsEnableDisable);

updateClusters();
getSettings();
}

QStringList Operator::getCurrentClusterFlags()
Expand Down Expand Up @@ -460,19 +461,15 @@ void Operator::dockerEnv()
#endif
}

void Operator::updateSettings(QString binPath, bool warnOnClose)
void Operator::updateSettings(Setting s)
{
m_settings->updateSettings(s);
}

QDir dir = QDir(QDir::homePath() + "/.minikube-gui");
if (!dir.exists()) {
dir.mkpath(".");
}
// Create a QSettings object with an INI file format and a specific filename
QSettings settings(dir.filePath("config.ini"), QSettings::IniFormat);
void Operator::getSettings()
{

// Write a value to the settings file
settings.setValue("minikube-binary-path", binPath);
settings.setValue("warn-background-on-close", warnOnClose);
m_basicView->receivedSettings(m_settings->getSettings());
}

void Operator::mount(QString src, QString dest)
Expand Down
9 changes: 7 additions & 2 deletions src/operator.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ limitations under the License.
#include "tray.h"
#include "updater.h"
#include "mount.h"
#include "settings.h"

#include <QStackedWidget>
#include <QSettings>

class Operator : public QObject
{
Expand All @@ -39,7 +42,7 @@ class Operator : public QObject
Operator(AdvancedView *advancedView, BasicView *basicView, ServiceView *serviceView,
AddonsView *addonsView, CommandRunner *commandRunner, ErrorMessage *errorMessage,
ProgressWindow *progressWindow, Tray *tray, HyperKit *hyperKit, Updater *updater,
QStackedWidget *stackedWidget, QDialog *parent);
Settings *settings, QStackedWidget *stackedWidget, QDialog *parent);

public slots:
void startMinikube();
Expand Down Expand Up @@ -72,7 +75,8 @@ private slots:
void dockerEnv();
void updateServices();
void mount(QString, QString);
void updateSettings(QString, bool);
void updateSettings(Setting s);
void getSettings();
void tunnelClean();
void tunnel();
void addonsEnableDisable(QString addonName, QString action);
Expand All @@ -98,6 +102,7 @@ private slots:
Tray *m_tray;
HyperKit *m_hyperKit;
Updater *m_updater;
Settings *m_settings;
bool m_isBasicView;
QProcess *dashboardProcess;
QProcess *mountProcess;
Expand Down
1 change: 0 additions & 1 deletion src/serviceview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ ServiceView::ServiceView(QDialog *parent, QIcon icon)

void ServiceView::displayTable(QString svcCmdOutput)
{

m_dialog = new QDialog(m_parent);
m_dialog->setWindowTitle(tr("Service List"));
m_dialog->setWindowIcon(m_icon);
Expand Down
19 changes: 19 additions & 0 deletions src/setting.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
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 "setting.h"

Setting::Setting() { }
36 changes: 36 additions & 0 deletions src/setting.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
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 SETTING_H
#define SETTING_H

#include <QString>

class Setting
{
public:
Setting();
QString minikubeBinaryPath() const { return m_minikubeBinaryPath; }
void setMinikubeBinaryPath(QString m) { m_minikubeBinaryPath = m; }
bool skipWarningOnClose() const { return m_skipWarningOnClose; }
void setSkipWarningOnClose(bool w) { m_skipWarningOnClose = w; }

private:
QString m_minikubeBinaryPath;
bool m_skipWarningOnClose;
};

#endif // SETTING_H
45 changes: 45 additions & 0 deletions src/settings.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
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 "settings.h"

#include <QSettings>
#include <QDir>

Settings::Settings()
{
QDir dir = QDir(QDir::homePath() + "/.minikube-gui");
if (!dir.exists()) {
dir.mkpath(".");
}
m_configPath = dir.filePath("config.ini");
}

void Settings::updateSettings(Setting s)
{
QSettings settings(m_configPath, QSettings::IniFormat);
settings.setValue("minikube-binary-path", s.minikubeBinaryPath());
settings.setValue("skip-warning-on-close", s.skipWarningOnClose());
}

Setting Settings::getSettings()
{
QSettings *s = new QSettings(m_configPath, QSettings::IniFormat);
Setting *setting = new Setting();
setting->setMinikubeBinaryPath(s->value("minikube-binary-path").toString());
setting->setSkipWarningOnClose(s->value("skip-warning-on-close").toBool());
return *setting;
}
39 changes: 39 additions & 0 deletions src/settings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
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 SETTINGS_H
#define SETTINGS_H

#include "setting.h"

#include <QObject>
#include <QDir>

class Settings : public QObject
{
Q_OBJECT

public:
Settings();
Setting getSettings();
void updateSettings(Setting setting);
signals:

private:
QString m_configPath;
};

#endif // SETTINGS_H
6 changes: 4 additions & 2 deletions src/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ Window::Window()
tray = new Tray(*trayIconIcon);
hyperKit = new HyperKit(*trayIconIcon);
updater = new Updater(this, version, *trayIconIcon);
settings = new Settings();

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

stackedWidget->addWidget(basicView->basicView);
stackedWidget->addWidget(advancedView->advancedView);
Expand All @@ -80,7 +81,8 @@ void Window::closeEvent(QCloseEvent *event)
return;
}
#endif
if (tray->isVisible()) {
bool skipWarning = settings->getSettings().skipWarningOnClose();
if (tray->isVisible() && !skipWarning) {
QMessageBox::information(this, "minikube",
tr("minikube will minimize to the "
"system tray. To terminate the program, "
Expand Down
1 change: 1 addition & 0 deletions src/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class Window : public QDialog
Tray *tray;
HyperKit *hyperKit;
Updater *updater;
Settings *settings;
QVBoxLayout *layout;
Logger *logger;
};
Expand Down

0 comments on commit 962d468

Please sign in to comment.