passwordmanager/gui/mainwindow.h

155 lines
4.3 KiB
C
Raw Normal View History

2016-08-29 20:21:24 +02:00
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "./passwordgeneratordialog.h"
#include <passwordfile/io/passwordfile.h>
#include <c++utilities/io/binaryreader.h>
#include <c++utilities/io/binarywriter.h>
#include <QMainWindow>
#include <QMap>
#include <memory>
QT_FORWARD_DECLARE_CLASS(QCloseEvent)
QT_FORWARD_DECLARE_CLASS(QTreeWidgetItem)
QT_FORWARD_DECLARE_CLASS(QUndoStack)
QT_FORWARD_DECLARE_CLASS(QUndoView)
QT_FORWARD_DECLARE_CLASS(QSettings)
#define PASSWORD_MANAGER_ENUM_CLASS enum class
2016-08-29 20:21:24 +02:00
namespace Io {
PASSWORD_MANAGER_ENUM_CLASS EntryType : int;
PASSWORD_MANAGER_ENUM_CLASS FieldType : int;
2017-09-29 17:17:12 +02:00
} // namespace Io
#undef PASSWORD_MANAGER_ENUM_CLASS
2016-08-29 20:21:24 +02:00
2019-06-10 22:44:59 +02:00
namespace QtUtilities {
2016-08-29 20:21:24 +02:00
class RecentMenuManager;
class AboutDialog;
class SettingsDialog;
class QtSettings;
2019-06-10 22:44:59 +02:00
} // namespace QtUtilities
2016-08-29 20:21:24 +02:00
namespace QtGui {
class FieldModel;
class EntryModel;
class EntryFilterModel;
namespace Ui {
class MainWindow;
}
2017-05-01 03:26:04 +02:00
class MainWindow : public QMainWindow {
2016-08-29 20:21:24 +02:00
Q_OBJECT
2017-05-01 03:26:04 +02:00
2016-08-29 20:21:24 +02:00
public:
2019-06-10 22:44:59 +02:00
explicit MainWindow(QSettings &settings, QtUtilities::QtSettings *qtSettings = nullptr, QWidget *parent = nullptr);
2018-03-14 00:15:12 +01:00
~MainWindow() override;
2016-08-29 20:21:24 +02:00
QString selectedFieldsString() const;
2020-03-08 14:09:56 +01:00
public Q_SLOTS:
2016-08-29 20:21:24 +02:00
// file management
bool openFile(const QString &path);
void createFile(const QString &path, const QString &password);
void createFile(const QString &path);
bool createFile();
void changePassword();
bool saveFile();
void exportFile();
bool closeFile();
// show dialogs
void showOpenFileDialog();
void showSaveFileDialog();
void showSettingsDialog();
void showAboutDialog();
void showPassowrdGeneratorDialog();
void showUndoView();
2020-09-04 00:54:34 +02:00
public:
bool openFile(const QString &path, Io::PasswordFileOpenFlags openFlags); // can not be a slot in Qt 6 without further effort, see QTBUG-86424
2016-08-29 20:21:24 +02:00
protected:
bool event(QEvent *event) override;
2018-03-14 00:15:12 +01:00
bool eventFilter(QObject *obj, QEvent *event) override;
void closeEvent(QCloseEvent *event) override;
void timerEvent(QTimerEvent *event) override;
2016-08-29 20:21:24 +02:00
2020-03-08 14:09:56 +01:00
private Q_SLOTS:
2016-08-29 20:21:24 +02:00
// file management
bool showFile();
// account/categories management
void addAccount();
void addCategory();
void addEntry(Io::EntryType type);
void removeEntry();
void applyFilter(const QString &filterText);
// row management
void accountSelected(const QModelIndex &selected, const QModelIndex &);
void insertRow();
void removeRows();
void markAsPasswordField();
void markAsNormalField();
void setFieldType(Io::FieldType fieldType);
void setPasswordVisibility(QAction *selectedAction);
void insertFields(const QString &fieldsString);
void copyFieldsForXMilliSeconds(int x = 5000);
void copyFields();
void insertFieldsFromClipboard();
// showing context menus
void showTreeViewContextMenu(const QPoint &pos);
void showTableViewContextMenu(const QPoint &pos);
2016-08-29 20:21:24 +02:00
// other
2018-12-21 01:14:41 +01:00
void showFileDetails();
2016-08-29 20:21:24 +02:00
void showContainingDirectory();
void clearClipboard();
void setSomethingChanged();
void setSomethingChanged(bool somethingChanged);
void updateStyleSheet();
2016-08-29 20:21:24 +02:00
2017-05-01 03:26:04 +02:00
private:
2016-08-29 20:21:24 +02:00
// showing conditional messages/prompts
bool askForCreatingFile();
bool showNoFileOpened();
bool showNoAccount();
// other
void updateUiStatus();
void updateWindowTitle();
void applyDefaultExpanding(const QModelIndex &parent);
2018-12-21 01:14:41 +01:00
Io::PasswordFileSaveFlags saveOptions() const;
2016-08-29 20:21:24 +02:00
std::unique_ptr<Ui::MainWindow> m_ui;
Io::PasswordFile m_file;
FieldModel *m_fieldModel;
EntryModel *m_entryModel;
EntryFilterModel *m_entryFilterModel;
QUndoStack *m_undoStack;
QUndoView *m_undoView;
bool m_somethingChanged;
2018-12-18 23:17:55 +01:00
Io::PasswordFileOpenFlags m_openFlags;
2016-08-29 20:21:24 +02:00
bool m_dontUpdateSelection;
int m_clearClipboardTimer;
2019-06-10 22:44:59 +02:00
QtUtilities::RecentMenuManager *m_recentMgr;
QtUtilities::AboutDialog *m_aboutDlg;
2016-08-29 20:21:24 +02:00
QSettings &m_settings;
2019-06-10 22:44:59 +02:00
QtUtilities::QtSettings *m_qtSettings;
QtUtilities::SettingsDialog *m_settingsDlg;
2016-08-29 20:21:24 +02:00
};
2018-01-26 15:51:34 +01:00
/*!
* \brief Opens a file with the specified \a path and updates all widgets to show its contents.
* \returns Returns true on success; otherwise false
*/
inline bool MainWindow::openFile(const QString &path)
{
2018-12-18 23:17:55 +01:00
return openFile(path, Io::PasswordFileOpenFlags::Default);
2018-01-26 15:51:34 +01:00
}
2017-09-29 17:17:12 +02:00
} // namespace QtGui
2016-08-29 20:21:24 +02:00
#endif // MAINWINDOW_H