mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-08-08 22:42:34 -04:00
Refactor Database and Database widgets (#2491)
The Database, DatabaseWidget, and DatabaseTabWidget classes share many responsibilities in inconsistent ways resulting in impenetrable and unmaintainable code and a diverse set of bugs and architecture restrictions. This patch reworks the architecture, responsibilities of, and dependencies between these classes. The core changes are: * Move loading and saving logic from widgets into the Database class * Get rid of the DatabaseManagerStruct and move all the information contained in it into the Database * Let database objects keep track of modifications and dirty/clean state instead of handing this to external widgets * Move GUI interactions for loading and saving from the DatabaseTabWidget into the DatabaseWidget (resolves #2494 as a side-effect) * Heavily clean up DatabaseTabWidget and degrade it to a slightly glorified QTabWidget * Use QSharedPointers for all Database objects * Remove the modifiedImmediate signal and replace it with a markAsModified() method * Implement proper tabName() method instead of reading back titles from GUI widgets (resolves #1389 and its duplicates #2146 #855) * Fix unwanted AES-KDF downgrade if database uses Argon2 and has CustomData * Improve code This patch is also the first major step towards solving issues #476 and #2322.
This commit is contained in:
parent
917c4cc18b
commit
d612cad09a
115 changed files with 2116 additions and 2165 deletions
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* Copyright (C) 2018 KeePassXC Team <team@keepassxc.org>
|
||||
* Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
|
||||
* Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -29,7 +29,6 @@
|
|||
#include "gui/csvImport/CsvImportWizard.h"
|
||||
#include "gui/entry/EntryModel.h"
|
||||
|
||||
class ChangeMasterKeyWidget;
|
||||
class DatabaseOpenWidget;
|
||||
class DatabaseSettingsDialog;
|
||||
class Database;
|
||||
|
@ -61,7 +60,7 @@ class DatabaseWidget : public QStackedWidget
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum Mode
|
||||
enum class Mode
|
||||
{
|
||||
None,
|
||||
ImportMode,
|
||||
|
@ -70,35 +69,39 @@ public:
|
|||
LockedMode
|
||||
};
|
||||
|
||||
explicit DatabaseWidget(Database* db, QWidget* parent = nullptr);
|
||||
explicit DatabaseWidget(QSharedPointer<Database> db, QWidget* parent = nullptr);
|
||||
explicit DatabaseWidget(const QString& filePath, QWidget* parent = nullptr);
|
||||
~DatabaseWidget();
|
||||
Database* database();
|
||||
bool dbHasKey() const;
|
||||
bool canDeleteCurrentGroup() const;
|
||||
bool isInSearchMode() const;
|
||||
QString getCurrentSearch();
|
||||
Group* currentGroup() const;
|
||||
int addWidget(QWidget* w);
|
||||
void setCurrentIndex(int index);
|
||||
void setCurrentWidget(QWidget* widget);
|
||||
|
||||
QSharedPointer<Database> database() const;
|
||||
|
||||
bool lock();
|
||||
void prepareUnlock();
|
||||
bool save(int attempt = 0);
|
||||
bool saveAs();
|
||||
|
||||
DatabaseWidget::Mode currentMode() const;
|
||||
void lock();
|
||||
void updateFilePath(const QString& filePath);
|
||||
int numberOfSelectedEntries() const;
|
||||
QStringList customEntryAttributes() const;
|
||||
bool isLocked() const;
|
||||
bool isSearchActive() const;
|
||||
|
||||
QString getCurrentSearch();
|
||||
void refreshSearch();
|
||||
|
||||
GroupView* groupView();
|
||||
EntryView* entryView();
|
||||
|
||||
Group* currentGroup() const;
|
||||
bool canDeleteCurrentGroup() const;
|
||||
bool isGroupSelected() const;
|
||||
bool isInEditMode() const;
|
||||
bool isRecycleBinSelected() const;
|
||||
int numberOfSelectedEntries() const;
|
||||
|
||||
QStringList customEntryAttributes() const;
|
||||
bool isEditWidgetModified() const;
|
||||
QList<int> mainSplitterSizes() const;
|
||||
void setMainSplitterSizes(const QList<int>& sizes);
|
||||
QList<int> previewSplitterSizes() const;
|
||||
void setPreviewSplitterSizes(const QList<int>& sizes);
|
||||
bool isUsernamesHidden() const;
|
||||
void setUsernamesHidden(bool hide);
|
||||
bool isPasswordsHidden() const;
|
||||
void setPasswordsHidden(bool hide);
|
||||
QByteArray entryViewState() const;
|
||||
bool setEntryViewState(const QByteArray& state) const;
|
||||
void clearAllWidgets();
|
||||
bool currentEntryHasFocus();
|
||||
bool currentEntryHasTitle();
|
||||
|
@ -107,31 +110,33 @@ public:
|
|||
bool currentEntryHasUrl();
|
||||
bool currentEntryHasNotes();
|
||||
bool currentEntryHasTotp();
|
||||
GroupView* groupView();
|
||||
EntryView* entryView();
|
||||
void showUnlockDialog();
|
||||
void closeUnlockDialog();
|
||||
|
||||
void blockAutoReload(bool block = true);
|
||||
void refreshSearch();
|
||||
bool isRecycleBinSelected() const;
|
||||
QString getDatabaseName() const;
|
||||
void setDatabaseName(const QString& databaseName);
|
||||
QString getDatabaseFileName() const;
|
||||
void setDatabaseFileName(const QString& databaseFileName);
|
||||
|
||||
QByteArray entryViewState() const;
|
||||
bool setEntryViewState(const QByteArray& state) const;
|
||||
QList<int> mainSplitterSizes() const;
|
||||
void setMainSplitterSizes(const QList<int>& sizes);
|
||||
QList<int> previewSplitterSizes() const;
|
||||
void setPreviewSplitterSizes(const QList<int>& sizes);
|
||||
|
||||
signals:
|
||||
// relayed Database signals
|
||||
void databaseFilePathChanged(const QString& oldPath, const QString& newPath);
|
||||
void databaseModified();
|
||||
void databaseSaved();
|
||||
void databaseUnlocked();
|
||||
void databaseLocked();
|
||||
|
||||
void closeRequest();
|
||||
void currentModeChanged(DatabaseWidget::Mode mode);
|
||||
void groupChanged();
|
||||
void entrySelectionChanged();
|
||||
void databaseChanged(Database* newDb, bool unsavedChanges);
|
||||
void databaseMerged(Database* mergedDb);
|
||||
void databaseMerged(QSharedPointer<Database> mergedDb);
|
||||
void groupContextMenuRequested(const QPoint& globalPos);
|
||||
void entryContextMenuRequested(const QPoint& globalPos);
|
||||
void pressedEntry(Entry* selectedEntry);
|
||||
void pressedGroup(Group* selectedGroup);
|
||||
void unlockedDatabase();
|
||||
void lockedDatabase();
|
||||
void listModeAboutToActivate();
|
||||
void listModeActivated();
|
||||
void searchModeAboutToActivate();
|
||||
|
@ -142,6 +147,7 @@ signals:
|
|||
void clearSearch();
|
||||
|
||||
public slots:
|
||||
void replaceDatabase(QSharedPointer<Database> db);
|
||||
void createEntry();
|
||||
void cloneEntry();
|
||||
void deleteEntries();
|
||||
|
@ -167,15 +173,13 @@ public slots:
|
|||
void switchToGroupEdit();
|
||||
void switchToMasterKeyChange();
|
||||
void switchToDatabaseSettings();
|
||||
void switchToOpenDatabase();
|
||||
void switchToOpenDatabase(const QString& filePath);
|
||||
void switchToOpenDatabase(const QString& filePath, const QString& password, const QString& keyFile);
|
||||
void switchToCsvImport(const QString& filePath);
|
||||
void csvImportFinished(bool accepted);
|
||||
void switchToOpenMergeDatabase(const QString& filePath);
|
||||
void switchToOpenMergeDatabase(const QString& filePath, const QString& password, const QString& keyFile);
|
||||
void switchToImportKeepass1(const QString& filePath);
|
||||
void databaseModified();
|
||||
void databaseSaved();
|
||||
void emptyRecycleBin();
|
||||
|
||||
// Search related slots
|
||||
|
@ -191,18 +195,24 @@ public slots:
|
|||
void showErrorMessage(const QString& errorMessage);
|
||||
void hideMessage();
|
||||
|
||||
protected:
|
||||
void closeEvent(QCloseEvent* event) override;
|
||||
void showEvent(QShowEvent* event) override;
|
||||
|
||||
private slots:
|
||||
void updateFilePath(const QString& filePath);
|
||||
void entryActivationSignalReceived(Entry* entry, EntryModel::ModelColumn column);
|
||||
void switchBackToEntryEdit();
|
||||
void switchToHistoryView(Entry* entry);
|
||||
void switchToEntryEdit(Entry* entry);
|
||||
void switchToEntryEdit(Entry*);
|
||||
void switchToEntryEdit(Entry* entry, bool create);
|
||||
void switchToGroupEdit(Group* entry, bool create);
|
||||
void emitGroupContextMenuRequested(const QPoint& pos);
|
||||
void emitEntryContextMenuRequested(const QPoint& pos);
|
||||
void emitPressedGroup(Group* currentGroup);
|
||||
void emitEntrySelectionChanged();
|
||||
void openDatabase(bool accepted);
|
||||
void connectDatabaseSignals();
|
||||
void loadDatabase(bool accepted);
|
||||
void mergeDatabase(bool accepted);
|
||||
void unlockDatabase(bool accepted);
|
||||
void emitCurrentModeChanged();
|
||||
|
@ -213,36 +223,38 @@ private slots:
|
|||
void unblockAutoReload();
|
||||
|
||||
private:
|
||||
int addChildWidget(QWidget* w);
|
||||
void setClipboardTextAndMinimize(const QString& text);
|
||||
void setIconFromParent();
|
||||
void replaceDatabase(Database* db);
|
||||
|
||||
QPointer<Database> m_db;
|
||||
QWidget* m_mainWidget;
|
||||
EditEntryWidget* m_editEntryWidget;
|
||||
EditEntryWidget* m_historyEditEntryWidget;
|
||||
EditGroupWidget* m_editGroupWidget;
|
||||
ChangeMasterKeyWidget* m_changeMasterKeyWidget;
|
||||
CsvImportWizard* m_csvImportWizard;
|
||||
DatabaseSettingsDialog* m_databaseSettingDialog;
|
||||
DatabaseOpenWidget* m_databaseOpenWidget;
|
||||
DatabaseOpenWidget* m_databaseOpenMergeWidget;
|
||||
KeePass1OpenWidget* m_keepass1OpenWidget;
|
||||
UnlockDatabaseWidget* m_unlockDatabaseWidget;
|
||||
UnlockDatabaseDialog* m_unlockDatabaseDialog;
|
||||
QSplitter* m_mainSplitter;
|
||||
QSplitter* m_previewSplitter;
|
||||
GroupView* m_groupView;
|
||||
EntryView* m_entryView;
|
||||
QLabel* m_searchingLabel;
|
||||
Group* m_newGroup;
|
||||
Entry* m_newEntry;
|
||||
Group* m_newParent;
|
||||
QString m_filePath;
|
||||
QSharedPointer<Database> m_db;
|
||||
|
||||
QPointer<QWidget> m_mainWidget;
|
||||
QPointer<QSplitter> m_mainSplitter;
|
||||
QPointer<MessageWidget> m_messageWidget;
|
||||
QPointer<EntryPreviewWidget> m_previewView;
|
||||
QPointer<QSplitter> m_previewSplitter;
|
||||
QPointer<QLabel> m_searchingLabel;
|
||||
QPointer<CsvImportWizard> m_csvImportWizard;
|
||||
QPointer<EditEntryWidget> m_editEntryWidget;
|
||||
QPointer<EditGroupWidget> m_editGroupWidget;
|
||||
QPointer<EditEntryWidget> m_historyEditEntryWidget;
|
||||
QPointer<DatabaseSettingsDialog> m_databaseSettingDialog;
|
||||
QPointer<DatabaseOpenWidget> m_databaseOpenWidget;
|
||||
QPointer<DatabaseOpenWidget> m_databaseOpenMergeWidget;
|
||||
QPointer<KeePass1OpenWidget> m_keepass1OpenWidget;
|
||||
QPointer<UnlockDatabaseWidget> m_unlockDatabaseWidget;
|
||||
QPointer<UnlockDatabaseDialog> m_unlockDatabaseDialog;
|
||||
QPointer<GroupView> m_groupView;
|
||||
QPointer<EntryView> m_entryView;
|
||||
|
||||
QPointer<Group> m_newGroup;
|
||||
QPointer<Entry> m_newEntry;
|
||||
QPointer<Group> m_newParent;
|
||||
|
||||
QUuid m_groupBeforeLock;
|
||||
QUuid m_entryBeforeLock;
|
||||
MessageWidget* m_messageWidget;
|
||||
EntryPreviewWidget* m_previewView;
|
||||
|
||||
QString m_databaseName;
|
||||
QString m_databaseFileName;
|
||||
|
||||
|
@ -251,15 +263,11 @@ private:
|
|||
QString m_lastSearchText;
|
||||
bool m_searchLimitGroup;
|
||||
|
||||
// CSV import state
|
||||
bool m_importingCsv;
|
||||
|
||||
// Autoreload
|
||||
QFileSystemWatcher m_fileWatcher;
|
||||
QTimer m_fileWatchTimer;
|
||||
QTimer m_fileWatchUnblockTimer;
|
||||
bool m_ignoreAutoReload;
|
||||
bool m_databaseModified;
|
||||
};
|
||||
|
||||
#endif // KEEPASSX_DATABASEWIDGET_H
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue