Line data Source code
1 : // SPDX-FileCopyrightText: 2016 Anne Jan Brouwer
2 : // SPDX-License-Identifier: GPL-3.0-or-later
3 : #ifndef SRC_MAINWINDOW_H_
4 : #define SRC_MAINWINDOW_H_
5 :
6 : #include "storemodel.h"
7 :
8 : #include <QFileSystemModel>
9 : #include <QItemSelectionModel>
10 : #include <QMainWindow>
11 : #include <QProcess>
12 : #include <QTimer>
13 :
14 : #if SINGLE_APP
15 : class SingleApplication;
16 : #else
17 : #define SingleApplication QApplication
18 : #endif
19 :
20 : #ifdef __APPLE__
21 : // http://doc.qt.io/qt-5/qkeysequence.html#qt_set_sequence_auto_mnemonic
22 : void qt_set_sequence_auto_mnemonic(bool b);
23 : #endif
24 :
25 : namespace Ui {
26 : class MainWindow;
27 : }
28 :
29 : /*!
30 : \class MainWindow
31 : \brief The MainWindow class does way too much, not only is it a switchboard,
32 : configuration handler and more, it's also the process-manager.
33 :
34 : This class could really do with an overhaul.
35 : */
36 : class QDialog;
37 : class QtPass;
38 : class TrayIcon;
39 : class MainWindow : public QMainWindow {
40 0 : Q_OBJECT
41 :
42 : public:
43 : explicit MainWindow(const QString &searchText = QString(),
44 : QWidget *parent = nullptr);
45 : ~MainWindow();
46 :
47 : void restoreWindow();
48 : void generateKeyPair(const QString &, QDialog *);
49 : void userDialog(const QString & = "");
50 : void config();
51 :
52 : void setUiElementsEnabled(bool state);
53 : void flashText(const QString &text, const bool isError,
54 : const bool isHtml = false);
55 :
56 : auto getCurrentTreeViewIndex() -> QModelIndex;
57 :
58 0 : auto getKeygenDialog() -> QDialog * { return this->keygen; }
59 : void cleanKeygenDialog();
60 :
61 : protected:
62 : void closeEvent(QCloseEvent *event);
63 : void keyPressEvent(QKeyEvent *event);
64 : void changeEvent(QEvent *event);
65 : auto eventFilter(QObject *obj, QEvent *event) -> bool;
66 :
67 : signals:
68 : void passShowHandlerFinished(const QString &output);
69 : void passGitInitNeeded();
70 : void generateGPGKeyPair(const QString &batch);
71 :
72 : public slots:
73 : void deselect();
74 :
75 : void messageAvailable(const QString &message);
76 : void critical(const QString &, const QString &);
77 :
78 : void executeWrapperStarted();
79 : void showStatusMessage(const QString &msg, int timeout = 2000);
80 : void passShowHandler(const QString &);
81 : void passOtpHandler(const QString &);
82 :
83 : void onPush();
84 : void on_treeView_clicked(const QModelIndex &index);
85 :
86 : void startReencryptPath();
87 : void endReencryptPath();
88 :
89 : private slots:
90 : void addPassword();
91 : void addFolder();
92 : void onEdit();
93 : void onDelete();
94 : void onOtp();
95 : void onUpdate(bool block = false);
96 : void onUsers();
97 : void onConfig();
98 : void on_treeView_doubleClicked(const QModelIndex &index);
99 : void clearPanel(bool notify = true);
100 : void on_lineEdit_textChanged(const QString &arg1);
101 : void on_lineEdit_returnPressed();
102 : #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
103 : void on_profileBox_currentIndexChanged(QString);
104 : #else
105 : void on_profileBox_currentTextChanged(const QString &);
106 : #endif
107 : void showContextMenu(const QPoint &pos);
108 : void showBrowserContextMenu(const QPoint &pos);
109 : void openFolder();
110 : void renameFolder();
111 : void editPassword(const QString &);
112 : void renamePassword();
113 : void focusInput();
114 : void copyPasswordFromTreeview();
115 : void passwordFromFileToClipboard(const QString &text);
116 : void onTimeoutSearch();
117 :
118 : private:
119 : QtPass *m_qtPass;
120 : QScopedPointer<Ui::MainWindow> ui;
121 : QFileSystemModel model;
122 : StoreModel proxyModel;
123 : QScopedPointer<QItemSelectionModel> selectionModel;
124 : QTimer clearPanelTimer, searchTimer;
125 : QDialog *keygen;
126 : QString currentDir;
127 : TrayIcon *tray;
128 :
129 : void initToolBarButtons();
130 : void initStatusBar();
131 :
132 : void updateText();
133 : void selectFirstFile();
134 : auto firstFile(QModelIndex parentIndex) -> QModelIndex;
135 : auto getFile(const QModelIndex &, bool) -> QString;
136 : void setPassword(const QString &, bool isNew = true);
137 :
138 : void updateProfileBox();
139 : void initTrayIcon();
140 : void destroyTrayIcon();
141 : void clearTemplateWidgets();
142 : void reencryptPath(QString dir);
143 : void addToGridLayout(int position, const QString &field,
144 : const QString &value);
145 :
146 : void updateGitButtonVisibility();
147 : void updateOtpButtonVisibility();
148 : void enableGitButtons(const bool &);
149 : };
150 :
151 : #endif // SRC_MAINWINDOW_H_
|