-
Notifications
You must be signed in to change notification settings - Fork 0
/
kbugscontext.h
121 lines (100 loc) · 3.57 KB
/
kbugscontext.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#ifndef KBUGSCONTEXT_H
#define KBUGSCONTEXT_H
#include <QActionGroup>
#include <QDir>
#include <QDragEnterEvent>
#include <QDropEvent>
#include <QFileInfoList>
#include <QKeyEvent>
#include <QSettings>
#include <QStandardItem>
#include <QSystemTrayIcon>
#include <QWidget>
#include "include/yaml-cpp/yaml.h"
#include "kubeconfig.h"
namespace Ui {
class KBugsContext;
}
class KBugsContext : public QWidget {
Q_OBJECT
public:
explicit KBugsContext(QWidget* parent = nullptr);
~KBugsContext();
public:
void initUI();
void initTray();
void initListViewItemActions();
void storeSettings();
void restoreSettings(bool showWindow = false);
void addCtxToListWidget(const QFileInfoList& configs);
void clearCtxConfigForm();
void addCtxConfigToForm(const QString& path, const Context& ctx);
static QString toQString(const YAML::Node& node);
void addCtxModel(const QString& path, const Context& ctx);
void updateCtxModel(const int& index);
void updateCtxModel(const QString& newCtxName, const QString& newNameSpace,
const QString& newCluster, const QString& newUser);
void addTrayCtxMenuAction(const QStandardItem& ctxItem);
Context getCurCtx();
void saveKubeConfig(const QString& path, const YAML::Node& configNode);
void saveKubeConfig(const QString& path, const QString& ctxName);
void selectCtxItemByIndex(const int& index, const bool& clicked = true,
const bool& ignoredCheckIndex = false);
bool ctxIsEmpty();
void doAction(QString actionName);
void emitAddCtxs();
void dragEnterEvent(QDragEnterEvent* event);
void dropEvent(QDropEvent* event);
public:
QList<Context> parseConfigCtxs(const QString& path);
KubeConfig parseConfig(const QString& path);
QFileInfoList listDirConfigFiles(const QString& dir = "");
int findActionIndex(const QAction& action);
private:
void closeEvent(QCloseEvent* event);
void keyPressEvent(QKeyEvent* event);
void keyReleaseEvent(QKeyEvent* event);
signals:
void showCtxInMenuBar(const QString& label);
void addCtxs(const QStringList ctxs);
void ctxNameChanged(const int& ctxIndex, const QString& ctxName);
void curCtxIndexChanged(const int& ctxIndex);
private slots:
void on_revertCtxConfigBtn_clicked();
void on_applyCtxConfigBtn_clicked();
void on_changeKubeConfigDirBtn_clicked();
void on_toggleCtxCheckBox_toggled(bool checked);
void on_ctxListView_clicked(const QModelIndex& index,
const bool& ignoredCheckIndex = false);
void on_nameLineEdit_textChanged(const QString& arg1);
void on_clusterCombox_currentIndexChanged(int index);
void on_nameSpaceLineEdit_textChanged(const QString& arg1);
void on_clusterCombox_currentIndexChanged(const QString& arg1);
void on_userComboBox_currentIndexChanged(const QString& arg1);
void showListViewItemMenu(const QPoint&);
void switchCtx();
void switchCtx(const int& index);
void switchCtx(const QAction& action);
void execSwitchCtxCommand(const QString& path);
void showNormal();
void trayIsActived(QSystemTrayIcon::ActivationReason reason);
void toggleRevertAndApply();
void on_fromServerBtn_clicked();
private:
Ui::KBugsContext* ui;
QString kubeConfigDir = QDir::homePath() + "/.kube/config";
QStandardItemModel* ctxsModel;
QMenu* menu;
QSystemTrayIcon* tray;
QMenu* trayMenu;
QMenu* ctxMenu;
QAction* importKubeConfigFileAction;
QAction* manageCtxActions;
QAction* quitAction;
QActionGroup* ctxMenuActions;
QSettings settings;
QString curConfigPath;
int curCtxItemIndex = -1;
int lastActiveCtxIndex = -1;
};
#endif // KBUGSCONTEXT_H