2017-06-09 21:40:36 +00:00
|
|
|
/*
|
2018-11-22 10:47:31 +00:00
|
|
|
* Copyright (C) 2018 KeePassXC Team <team@keepassxc.org>
|
2010-08-24 20:26:52 +00:00
|
|
|
* Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
|
|
|
|
|
*
|
|
|
|
|
* 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
|
|
|
|
|
* the Free Software Foundation, either version 2 or (at your option)
|
|
|
|
|
* version 3 of the License.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef KEEPASSX_DATABASEWIDGET_H
|
|
|
|
|
#define KEEPASSX_DATABASEWIDGET_H
|
|
|
|
|
|
2018-03-31 20:01:30 +00:00
|
|
|
#include <QFileSystemWatcher>
|
2013-10-03 13:18:16 +00:00
|
|
|
#include <QStackedWidget>
|
2010-08-24 20:26:52 +00:00
|
|
|
|
2018-11-23 23:57:41 +00:00
|
|
|
#include "DatabaseOpenDialog.h"
|
2019-07-07 19:29:11 +00:00
|
|
|
#include "config-keepassx.h"
|
2015-01-21 16:19:05 +00:00
|
|
|
#include "gui/MessageWidget.h"
|
2017-01-09 00:33:21 +00:00
|
|
|
#include "gui/csvImport/CsvImportWizard.h"
|
2018-03-31 20:01:30 +00:00
|
|
|
#include "gui/entry/EntryModel.h"
|
2013-04-14 17:14:06 +00:00
|
|
|
|
2012-06-28 07:21:15 +00:00
|
|
|
class DatabaseOpenWidget;
|
2018-11-23 23:57:41 +00:00
|
|
|
class KeePass1OpenWidget;
|
2019-05-19 21:49:48 +00:00
|
|
|
class OpVaultOpenWidget;
|
2018-05-13 21:21:43 +00:00
|
|
|
class DatabaseSettingsDialog;
|
2020-02-01 13:42:34 +00:00
|
|
|
class ReportsDialog;
|
2010-08-24 20:26:52 +00:00
|
|
|
class Database;
|
2019-10-14 13:31:23 +00:00
|
|
|
class FileWatcher;
|
2010-10-06 17:40:50 +00:00
|
|
|
class EditEntryWidget;
|
2011-12-27 14:49:06 +00:00
|
|
|
class EditGroupWidget;
|
2010-10-06 17:40:50 +00:00
|
|
|
class Entry;
|
2010-08-24 20:26:52 +00:00
|
|
|
class EntryView;
|
2018-03-25 20:24:30 +00:00
|
|
|
class EntrySearcher;
|
2011-12-27 14:49:06 +00:00
|
|
|
class Group;
|
2010-08-24 20:26:52 +00:00
|
|
|
class GroupView;
|
2012-06-28 07:21:15 +00:00
|
|
|
class QFile;
|
2012-05-25 11:17:46 +00:00
|
|
|
class QMenu;
|
2014-05-17 09:16:27 +00:00
|
|
|
class QSplitter;
|
2016-11-03 01:01:02 +00:00
|
|
|
class QLabel;
|
2015-01-21 16:19:05 +00:00
|
|
|
class MessageWidget;
|
2018-10-09 01:11:44 +00:00
|
|
|
class EntryPreviewWidget;
|
2010-08-24 20:26:52 +00:00
|
|
|
|
2018-03-31 20:01:30 +00:00
|
|
|
namespace Ui
|
|
|
|
|
{
|
2015-01-21 16:19:05 +00:00
|
|
|
class SearchWidget;
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-06 17:40:50 +00:00
|
|
|
class DatabaseWidget : public QStackedWidget
|
2010-08-24 20:26:52 +00:00
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
2018-11-23 23:57:41 +00:00
|
|
|
friend class DatabaseOpenDialog;
|
|
|
|
|
|
2018-11-22 10:47:31 +00:00
|
|
|
enum class Mode
|
2012-04-24 23:32:05 +00:00
|
|
|
{
|
2012-04-25 18:22:55 +00:00
|
|
|
None,
|
2017-02-18 00:51:31 +00:00
|
|
|
ImportMode,
|
2012-04-25 18:22:55 +00:00
|
|
|
ViewMode,
|
2012-10-12 10:12:00 +00:00
|
|
|
EditMode,
|
|
|
|
|
LockedMode
|
2012-04-24 23:32:05 +00:00
|
|
|
};
|
|
|
|
|
|
2018-11-22 10:47:31 +00:00
|
|
|
explicit DatabaseWidget(QSharedPointer<Database> db, QWidget* parent = nullptr);
|
|
|
|
|
explicit DatabaseWidget(const QString& filePath, QWidget* parent = nullptr);
|
2021-05-31 14:40:20 +00:00
|
|
|
~DatabaseWidget() override;
|
2018-11-22 10:47:31 +00:00
|
|
|
|
2020-04-21 22:46:21 +00:00
|
|
|
void setFocus(Qt::FocusReason reason);
|
|
|
|
|
|
2018-11-22 10:47:31 +00:00
|
|
|
QSharedPointer<Database> database() const;
|
|
|
|
|
|
|
|
|
|
DatabaseWidget::Mode currentMode() const;
|
|
|
|
|
bool isLocked() const;
|
2020-03-06 03:59:07 +00:00
|
|
|
bool isSaving() const;
|
2020-05-22 01:43:00 +00:00
|
|
|
bool isSorted() const;
|
2018-11-22 10:47:31 +00:00
|
|
|
bool isSearchActive() const;
|
2020-04-21 22:46:21 +00:00
|
|
|
bool isEntryViewActive() const;
|
2019-10-20 22:28:58 +00:00
|
|
|
bool isEntryEditActive() const;
|
2019-12-13 03:40:17 +00:00
|
|
|
bool isGroupEditActive() const;
|
2018-11-22 10:47:31 +00:00
|
|
|
|
2016-11-03 01:01:02 +00:00
|
|
|
QString getCurrentSearch();
|
2018-11-22 10:47:31 +00:00
|
|
|
void refreshSearch();
|
|
|
|
|
|
|
|
|
|
GroupView* groupView();
|
|
|
|
|
EntryView* entryView();
|
|
|
|
|
|
2016-11-08 03:37:42 +00:00
|
|
|
Group* currentGroup() const;
|
2018-11-22 10:47:31 +00:00
|
|
|
bool canDeleteCurrentGroup() const;
|
|
|
|
|
bool isGroupSelected() const;
|
|
|
|
|
bool isRecycleBinSelected() const;
|
2014-05-15 20:53:59 +00:00
|
|
|
int numberOfSelectedEntries() const;
|
2020-05-22 01:43:00 +00:00
|
|
|
int currentEntryIndex() const;
|
2018-11-22 10:47:31 +00:00
|
|
|
|
2014-05-15 20:53:59 +00:00
|
|
|
QStringList customEntryAttributes() const;
|
2016-07-31 22:22:04 +00:00
|
|
|
bool isEditWidgetModified() const;
|
2015-01-11 15:20:59 +00:00
|
|
|
void clearAllWidgets();
|
2020-11-11 22:40:42 +00:00
|
|
|
Entry* currentSelectedEntry();
|
2015-05-12 19:54:39 +00:00
|
|
|
bool currentEntryHasTitle();
|
|
|
|
|
bool currentEntryHasUsername();
|
|
|
|
|
bool currentEntryHasPassword();
|
|
|
|
|
bool currentEntryHasUrl();
|
|
|
|
|
bool currentEntryHasNotes();
|
2017-04-13 10:05:36 +00:00
|
|
|
bool currentEntryHasTotp();
|
2018-05-10 13:12:36 +00:00
|
|
|
#ifdef WITH_XC_SSHAGENT
|
|
|
|
|
bool currentEntryHasSshKey();
|
|
|
|
|
#endif
|
2018-11-22 10:47:31 +00:00
|
|
|
|
|
|
|
|
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);
|
2011-12-27 14:49:06 +00:00
|
|
|
|
2017-02-24 17:43:15 +00:00
|
|
|
signals:
|
2018-11-22 10:47:31 +00:00
|
|
|
// relayed Database signals
|
|
|
|
|
void databaseFilePathChanged(const QString& oldPath, const QString& newPath);
|
|
|
|
|
void databaseModified();
|
|
|
|
|
void databaseSaved();
|
|
|
|
|
void databaseUnlocked();
|
2019-07-07 19:29:11 +00:00
|
|
|
void databaseLockRequested();
|
2018-11-22 10:47:31 +00:00
|
|
|
void databaseLocked();
|
|
|
|
|
|
2019-02-21 05:51:23 +00:00
|
|
|
// Emitted in replaceDatabase, may be caused by lock, reload, unlock, load.
|
|
|
|
|
void databaseReplaced(const QSharedPointer<Database>& oldDb, const QSharedPointer<Database>& newDb);
|
|
|
|
|
|
2012-04-11 18:35:52 +00:00
|
|
|
void closeRequest();
|
2012-04-25 18:22:55 +00:00
|
|
|
void currentModeChanged(DatabaseWidget::Mode mode);
|
2012-08-01 08:35:37 +00:00
|
|
|
void groupChanged();
|
|
|
|
|
void entrySelectionChanged();
|
2019-09-03 21:17:33 +00:00
|
|
|
void
|
|
|
|
|
requestOpenDatabase(const QString& filePath, bool inBackground, const QString& password, const QString& keyFile);
|
2018-11-22 10:47:31 +00:00
|
|
|
void databaseMerged(QSharedPointer<Database> mergedDb);
|
2012-08-01 08:35:37 +00:00
|
|
|
void groupContextMenuRequested(const QPoint& globalPos);
|
|
|
|
|
void entryContextMenuRequested(const QPoint& globalPos);
|
2014-05-17 16:05:02 +00:00
|
|
|
void listModeAboutToActivate();
|
2014-05-17 09:16:27 +00:00
|
|
|
void listModeActivated();
|
2014-05-17 16:05:02 +00:00
|
|
|
void searchModeAboutToActivate();
|
2014-05-17 09:16:27 +00:00
|
|
|
void searchModeActivated();
|
2017-10-28 18:14:45 +00:00
|
|
|
void mainSplitterSizesChanged();
|
2018-10-09 01:11:44 +00:00
|
|
|
void previewSplitterSizesChanged();
|
2017-12-23 07:40:00 +00:00
|
|
|
void entryViewStateChanged();
|
2018-03-20 03:16:22 +00:00
|
|
|
void clearSearch();
|
2015-01-05 09:50:04 +00:00
|
|
|
|
2017-02-24 17:43:15 +00:00
|
|
|
public slots:
|
2018-11-23 23:57:41 +00:00
|
|
|
bool lock();
|
2019-04-03 14:23:18 +00:00
|
|
|
bool save();
|
2018-11-23 23:57:41 +00:00
|
|
|
bool saveAs();
|
2020-05-09 03:48:03 +00:00
|
|
|
bool saveBackup();
|
2018-11-23 23:57:41 +00:00
|
|
|
|
2018-11-22 10:47:31 +00:00
|
|
|
void replaceDatabase(QSharedPointer<Database> db);
|
2011-12-27 15:04:59 +00:00
|
|
|
void createEntry();
|
2012-05-25 11:17:46 +00:00
|
|
|
void cloneEntry();
|
2018-12-24 23:15:46 +00:00
|
|
|
void deleteSelectedEntries();
|
2021-02-05 20:07:59 +00:00
|
|
|
void deleteEntries(QList<Entry*> entries, bool confirm = true);
|
2020-07-14 22:34:53 +00:00
|
|
|
void focusOnEntries(bool editIfFocused = false);
|
|
|
|
|
void focusOnGroups(bool editIfFocused = false);
|
2020-05-22 01:43:00 +00:00
|
|
|
void moveEntryUp();
|
|
|
|
|
void moveEntryDown();
|
2013-12-01 08:43:41 +00:00
|
|
|
void copyTitle();
|
2012-05-26 14:20:32 +00:00
|
|
|
void copyUsername();
|
|
|
|
|
void copyPassword();
|
2013-12-01 08:43:41 +00:00
|
|
|
void copyURL();
|
|
|
|
|
void copyNotes();
|
2012-10-23 22:15:23 +00:00
|
|
|
void copyAttribute(QAction* action);
|
2017-04-13 10:05:36 +00:00
|
|
|
void showTotp();
|
2018-10-19 18:42:49 +00:00
|
|
|
void showTotpKeyQrCode();
|
2017-04-13 10:05:36 +00:00
|
|
|
void copyTotp();
|
|
|
|
|
void setupTotp();
|
2018-05-10 13:12:36 +00:00
|
|
|
#ifdef WITH_XC_SSHAGENT
|
|
|
|
|
void addToAgent();
|
|
|
|
|
void removeFromAgent();
|
|
|
|
|
#endif
|
2020-11-11 22:40:42 +00:00
|
|
|
void performAutoType(const QString& sequence = {});
|
2020-06-22 10:50:45 +00:00
|
|
|
void performAutoTypeUsername();
|
|
|
|
|
void performAutoTypeUsernameEnter();
|
|
|
|
|
void performAutoTypePassword();
|
|
|
|
|
void performAutoTypePasswordEnter();
|
2012-07-27 16:38:52 +00:00
|
|
|
void openUrl();
|
2019-07-07 19:29:11 +00:00
|
|
|
void downloadSelectedFavicons();
|
|
|
|
|
void downloadAllFavicons();
|
2013-04-07 19:05:52 +00:00
|
|
|
void openUrlForEntry(Entry* entry);
|
2011-12-27 14:49:06 +00:00
|
|
|
void createGroup();
|
2012-05-25 11:17:46 +00:00
|
|
|
void deleteGroup();
|
2018-11-23 23:57:41 +00:00
|
|
|
void switchToMainView(bool previousDialogAccepted = false);
|
2011-12-27 14:49:06 +00:00
|
|
|
void switchToEntryEdit();
|
|
|
|
|
void switchToGroupEdit();
|
2019-06-18 20:58:47 +00:00
|
|
|
void sortGroupsAsc();
|
|
|
|
|
void sortGroupsDesc();
|
2020-07-01 23:16:40 +00:00
|
|
|
void switchToDatabaseSecurity();
|
|
|
|
|
void switchToDatabaseReports();
|
2012-04-19 14:20:20 +00:00
|
|
|
void switchToDatabaseSettings();
|
2018-11-22 10:47:31 +00:00
|
|
|
void switchToOpenDatabase();
|
2017-12-20 15:18:01 +00:00
|
|
|
void switchToOpenDatabase(const QString& filePath);
|
|
|
|
|
void switchToOpenDatabase(const QString& filePath, const QString& password, const QString& keyFile);
|
2018-05-13 21:21:43 +00:00
|
|
|
void switchToCsvImport(const QString& filePath);
|
2018-11-23 23:57:41 +00:00
|
|
|
void performUnlockDatabase(const QString& password, const QString& keyfile = {});
|
2017-01-09 00:33:21 +00:00
|
|
|
void csvImportFinished(bool accepted);
|
2017-12-20 15:18:01 +00:00
|
|
|
void switchToImportKeepass1(const QString& filePath);
|
2019-05-19 21:49:48 +00:00
|
|
|
void switchToImportOpVault(const QString& fileName);
|
2017-04-21 14:33:06 +00:00
|
|
|
void emptyRecycleBin();
|
2017-03-04 17:19:18 +00:00
|
|
|
|
2016-11-03 01:01:02 +00:00
|
|
|
// Search related slots
|
|
|
|
|
void search(const QString& searchtext);
|
|
|
|
|
void setSearchCaseSensitive(bool state);
|
2017-06-20 19:54:13 +00:00
|
|
|
void setSearchLimitGroup(bool state);
|
2016-11-03 01:01:02 +00:00
|
|
|
void endSearch();
|
2017-03-04 17:19:18 +00:00
|
|
|
|
2018-03-31 20:01:30 +00:00
|
|
|
void showMessage(const QString& text,
|
|
|
|
|
MessageWidget::MessageType type,
|
|
|
|
|
bool showClosebutton = true,
|
2017-10-19 18:46:09 +00:00
|
|
|
int autoHideTimeout = MessageWidget::DefaultAutoHideTimeout);
|
2017-12-25 13:53:22 +00:00
|
|
|
void showErrorMessage(const QString& errorMessage);
|
2015-01-21 16:19:05 +00:00
|
|
|
void hideMessage();
|
2010-08-24 20:26:52 +00:00
|
|
|
|
2018-11-22 10:47:31 +00:00
|
|
|
protected:
|
|
|
|
|
void closeEvent(QCloseEvent* event) override;
|
|
|
|
|
void showEvent(QShowEvent* event) override;
|
2020-04-21 22:46:21 +00:00
|
|
|
bool focusNextPrevChild(bool next) override;
|
2018-11-22 10:47:31 +00:00
|
|
|
|
2017-02-24 17:43:15 +00:00
|
|
|
private slots:
|
2013-04-14 17:14:06 +00:00
|
|
|
void entryActivationSignalReceived(Entry* entry, EntryModel::ModelColumn column);
|
2012-05-15 18:12:05 +00:00
|
|
|
void switchBackToEntryEdit();
|
2012-05-20 21:14:34 +00:00
|
|
|
void switchToHistoryView(Entry* entry);
|
2018-11-22 10:47:31 +00:00
|
|
|
void switchToEntryEdit(Entry*);
|
2011-12-27 15:04:59 +00:00
|
|
|
void switchToEntryEdit(Entry* entry, bool create);
|
2011-12-27 14:49:06 +00:00
|
|
|
void switchToGroupEdit(Group* entry, bool create);
|
2014-05-17 09:22:45 +00:00
|
|
|
void emitGroupContextMenuRequested(const QPoint& pos);
|
|
|
|
|
void emitEntryContextMenuRequested(const QPoint& pos);
|
2018-11-28 21:13:56 +00:00
|
|
|
void onEntryChanged(Entry* entry);
|
2020-04-21 22:46:21 +00:00
|
|
|
void onGroupChanged();
|
2019-01-25 12:20:39 +00:00
|
|
|
void onDatabaseModified();
|
2018-11-22 10:47:31 +00:00
|
|
|
void connectDatabaseSignals();
|
|
|
|
|
void loadDatabase(bool accepted);
|
2012-10-12 10:12:00 +00:00
|
|
|
void unlockDatabase(bool accepted);
|
2018-11-23 23:57:41 +00:00
|
|
|
void mergeDatabase(bool accepted);
|
2012-04-24 23:32:05 +00:00
|
|
|
void emitCurrentModeChanged();
|
2016-11-09 12:38:14 +00:00
|
|
|
// Database autoreload slots
|
|
|
|
|
void reloadDatabaseFile();
|
2018-03-22 21:56:05 +00:00
|
|
|
void restoreGroupEntryFocus(const QUuid& groupUuid, const QUuid& EntryUuid);
|
2010-10-06 17:40:50 +00:00
|
|
|
|
2010-08-24 20:26:52 +00:00
|
|
|
private:
|
2018-11-22 10:47:31 +00:00
|
|
|
int addChildWidget(QWidget* w);
|
2013-12-01 08:59:43 +00:00
|
|
|
void setClipboardTextAndMinimize(const QString& text);
|
2018-11-23 18:24:59 +00:00
|
|
|
void processAutoOpen();
|
2020-06-04 12:10:55 +00:00
|
|
|
void openDatabaseFromEntry(const Entry* entry, bool inBackground = true);
|
2019-07-07 19:29:11 +00:00
|
|
|
void performIconDownloads(const QList<Entry*>& entries, bool force = false);
|
2020-08-01 22:00:47 +00:00
|
|
|
bool performSave(QString& errorMessage, const QString& fileName = {});
|
2018-11-22 10:47:31 +00:00
|
|
|
|
|
|
|
|
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;
|
2019-03-07 15:57:13 +00:00
|
|
|
QPointer<QLabel> m_shareLabel;
|
2018-11-22 10:47:31 +00:00
|
|
|
QPointer<CsvImportWizard> m_csvImportWizard;
|
|
|
|
|
QPointer<EditEntryWidget> m_editEntryWidget;
|
|
|
|
|
QPointer<EditGroupWidget> m_editGroupWidget;
|
|
|
|
|
QPointer<EditEntryWidget> m_historyEditEntryWidget;
|
2020-02-01 13:42:34 +00:00
|
|
|
QPointer<ReportsDialog> m_reportsDialog;
|
2018-11-22 10:47:31 +00:00
|
|
|
QPointer<DatabaseSettingsDialog> m_databaseSettingDialog;
|
|
|
|
|
QPointer<DatabaseOpenWidget> m_databaseOpenWidget;
|
|
|
|
|
QPointer<KeePass1OpenWidget> m_keepass1OpenWidget;
|
2019-05-19 21:49:48 +00:00
|
|
|
QPointer<OpVaultOpenWidget> m_opVaultOpenWidget;
|
2018-11-22 10:47:31 +00:00
|
|
|
QPointer<GroupView> m_groupView;
|
|
|
|
|
QPointer<EntryView> m_entryView;
|
|
|
|
|
|
2018-11-23 23:57:41 +00:00
|
|
|
QScopedPointer<Group> m_newGroup;
|
|
|
|
|
QScopedPointer<Entry> m_newEntry;
|
2018-11-22 10:47:31 +00:00
|
|
|
QPointer<Group> m_newParent;
|
2018-10-01 14:26:24 +00:00
|
|
|
|
2018-03-22 21:56:05 +00:00
|
|
|
QUuid m_groupBeforeLock;
|
|
|
|
|
QUuid m_entryBeforeLock;
|
2016-11-03 01:01:02 +00:00
|
|
|
|
2019-04-03 14:23:18 +00:00
|
|
|
int m_saveAttempts;
|
|
|
|
|
|
2016-11-03 01:01:02 +00:00
|
|
|
// Search state
|
2021-05-28 01:50:15 +00:00
|
|
|
QScopedPointer<EntrySearcher> m_entrySearcher;
|
2016-11-03 01:01:02 +00:00
|
|
|
QString m_lastSearchText;
|
2017-06-20 19:54:13 +00:00
|
|
|
bool m_searchLimitGroup;
|
2016-11-08 03:52:32 +00:00
|
|
|
|
2016-11-11 22:58:47 +00:00
|
|
|
// Autoreload
|
2019-01-25 12:20:39 +00:00
|
|
|
bool m_blockAutoSave;
|
2010-08-24 20:26:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // KEEPASSX_DATABASEWIDGET_H
|