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

addonsList #27

Merged
merged 6 commits into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion minikube.pro
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
HEADERS = src/window.h \
src/addon.h \
src/addonsview.h \
src/advancedview.h \
src/basicview.h \
src/cluster.h \
Expand All @@ -16,6 +18,8 @@ HEADERS = src/window.h \
src/tray.h \
src/updater.h
SOURCES = src/main.cpp \
src/addon.cpp \
src/addonsview.cpp \
src/advancedview.cpp \
src/basicview.cpp \
src/cluster.cpp \
Expand All @@ -25,7 +29,6 @@ SOURCES = src/main.cpp \
src/fonts.cpp \
src/hyperkit.cpp \
src/logger.cpp \
src/mount.cpp \
src/operator.cpp \
src/paths.cpp \
src/progresswindow.cpp \
Expand Down
87 changes: 87 additions & 0 deletions src/addon.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
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 "addon.h"

void AddonModel::setAddonList(const AddonList &addons)
{
beginResetModel();
addonList = addons;
endResetModel();
}

int AddonModel::rowCount(const QModelIndex &) const
{
return addonList.count();
}

int AddonModel::columnCount(const QModelIndex &) const
{
return 3;
}

QVariant AddonModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();

if (index.row() >= addonList.size())
return QVariant();
if (index.column() >= 3)
return QVariant();

if (role == Qt::TextAlignmentRole) {
switch (index.column()) {
case 0:
return QVariant(Qt::AlignLeft | Qt::AlignVCenter);
case 1:
return QVariant(Qt::AlignRight | Qt::AlignVCenter);
case 2:
return QVariant(Qt::AlignHCenter | Qt::AlignVCenter);
}
}
if (role == Qt::DisplayRole) {
Addon addon = addonList.at(index.row());
switch (index.column()) {
case 0:
return addon.name();
case 1:
return addon.status();
case 2:
return addon.status() == "enabled" ? "Disable" : "Enable";
}
}
return QVariant();
}

QVariant AddonModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (role != Qt::DisplayRole)
return QVariant();

if (orientation == Qt::Horizontal) {
switch (section) {
case 0:
return tr("Name");
case 1:
return tr("Status");
case 2:
return tr("Action");
}
}

return QVariant(); // QStringLiteral("Row %1").arg(section);
}
58 changes: 58 additions & 0 deletions src/addon.h
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.
*/

#ifndef ADDON_H
#define ADDON_H

#include <QAbstractListModel>

class Addon
{
public:
Addon(QString name, QString status) : m_name(name), m_status(status) {};
Addon() : Addon("", "") {};
QString name() const { return m_name; }
QString status() const { return m_status; }

private:
QString m_name;
QString m_status;
};

typedef QList<Addon> AddonList;

class AddonModel : public QAbstractListModel
{
Q_OBJECT

public:
AddonModel(const AddonList &addons, QObject *parent = nullptr)
: QAbstractListModel(parent), addonList(addons)
{
}

void setAddonList(const AddonList &addons);
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role) const override;
QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const override;

private:
AddonList addonList;
};

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

#include <QVBoxLayout>
#include <QHeaderView>
#include <QDialog>

AddonsView::AddonsView(QIcon icon)
{
m_icon = icon;
m_dialog = new QDialog(m_parent);
m_dialog->setWindowTitle(tr("Addons List"));
m_dialog->setWindowIcon(m_icon);
m_dialog->setFixedWidth(600);
m_dialog->setModal(true);

AddonList addons;
m_addonModel = new AddonModel(addons);

addonListView = new QTableView();
addonListView->setModel(m_addonModel);
addonListView->setSelectionMode(QAbstractItemView::NoSelection);
addonListView->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
addonListView->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch);
addonListView->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Stretch);

refreshButton = new QPushButton(tr("Refresh"));
QVBoxLayout *bottomLayout = new QVBoxLayout;
bottomLayout->addWidget(refreshButton);
QVBoxLayout *addonsLayout = new QVBoxLayout;
addonsLayout->addWidget(addonListView);
addonsLayout->addLayout(bottomLayout);
m_dialog->setLayout(addonsLayout);

connect(refreshButton, &QAbstractButton::clicked, this, &AddonsView::refresh);
}

void AddonsView::updateAddonsTable(AddonList addonList)
{
m_addonModel->setAddonList(addonList);
buttonList = new QList<QPushButton>();
for (int i = 0; i < addonList.size(); i++) {
Addon addon = addonList[i];
QString addonName = addon.name();
QString action = addon.status() == "enabled" ? "disable" : "enable";
QPushButton *button = new QPushButton();
connect(button, &QPushButton::clicked,
[this, addonName, action] { emit addonClicked(addonName, action); });
addonListView->setIndexWidget(addonListView->model()->index(i, 2), button);
}
}

void AddonsView::display()
{
m_dialog->exec();
}
48 changes: 48 additions & 0 deletions src/addonsview.h
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.
*/

#ifndef ADDONSVIEW_H
#define ADDONSVIEW_H

#include "addon.h"

#include <QPushButton>
#include <QTableView>

class AddonsView : public QObject
{
Q_OBJECT

public:
explicit AddonsView(QIcon icon);
QTableView *addonListView;
void update(Addon addon);
void updateAddonsTable(AddonList addonList);
void display();
signals:
void refresh();
void addonClicked(QString addonName, QString action);

private:
QIcon m_icon;
AddonModel *m_addonModel;
QPushButton *refreshButton;
QDialog *m_dialog;
QDialog *m_parent;
QList<QPushButton> *buttonList;
};

#endif // ADDONSVIEW_H
3 changes: 0 additions & 3 deletions src/advancedview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@ limitations under the License.
#include <QDialog>
#include <QDialogButtonBox>
#include <QFormLayout>
#include <QHBoxLayout>
#include <QHeaderView>
#include <QLabel>
#include <QLineEdit>
#include <QTableView>

AdvancedView::AdvancedView(QIcon icon)
{
Expand Down
2 changes: 1 addition & 1 deletion src/advancedview.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ limitations under the License.
#include "cluster.h"

#include <QLabel>
#include <QObject>
#include <QPushButton>
#include <QTableView>

Expand Down Expand Up @@ -71,6 +70,7 @@ public slots:
QPushButton *createButton;
QLabel *loading;
ClusterModel *m_clusterModel;

QIcon m_icon;
};

Expand Down
11 changes: 5 additions & 6 deletions src/basicview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ limitations under the License.
#include "fonts.h"
#include "constants.h"

#include <QDebug>
#include <QFont>
#include <QFontDatabase>
#include <QToolTip>
#include <QVBoxLayout>
#include <QLabel>
#include <QDialog>
#include <QFormLayout>
#include <QDialogButtonBox>
Expand Down Expand Up @@ -51,6 +45,7 @@ BasicView::BasicView(QIcon icon)
tunnelButton = new QPushButton(tr("tunnel"));
sshButton = new QPushButton("SSH");
dashboardButton = new QPushButton(tr("dashboard"));
addonsButton = new QPushButton(tr("addons"));
advancedButton = new QPushButton(tr("cluster list"));

Fonts::setFontAwesome(startButton);
Expand Down Expand Up @@ -81,6 +76,7 @@ BasicView::BasicView(QIcon icon)
buttonLayoutRow2->addWidget(tunnelButton);
buttonLayoutRow2->addWidget(sshButton);
buttonLayoutRow2->addWidget(dashboardButton);
buttonLayoutRow2->addWidget(addonsButton);
buttonLayoutRow2->addWidget(advancedButton);

QVBoxLayout *BasicLayout = new QVBoxLayout;
Expand All @@ -102,6 +98,7 @@ BasicView::BasicView(QIcon icon)
connect(tunnelButton, &QAbstractButton::clicked, this, &BasicView::tunnel);
connect(sshButton, &QAbstractButton::clicked, this, &BasicView::ssh);
connect(dashboardButton, &QAbstractButton::clicked, this, &BasicView::dashboard);
connect(addonsButton, &QAbstractButton::clicked, this, &BasicView::addons);
connect(advancedButton, &QAbstractButton::clicked, this, &BasicView::advanced);
}

Expand Down Expand Up @@ -160,6 +157,7 @@ void BasicView::update(Cluster cluster)
pauseButton->setEnabled(isRunning || isPaused);
deleteButton->setEnabled(exists);
dashboardButton->setEnabled(isRunning);
addonsButton->setEnabled(isRunning);
#if __linux__ || __APPLE__
dockerEnvButton->setEnabled(isRunning || isPaused);
sshButton->setEnabled(isRunning || isPaused);
Expand Down Expand Up @@ -194,6 +192,7 @@ void BasicView::disableButtons()
mountButton->setEnabled(false);
sshButton->setEnabled(false);
dashboardButton->setEnabled(false);
addonsButton->setEnabled(false);
advancedButton->setEnabled(false);
refreshButton->setEnabled(false);
}
Expand Down
Loading