keepassxc/src/gui/DatabaseWidget.h

317 lines
10 KiB
C++
Raw Normal View History

2017-06-09 23:40:36 +02:00
/*
2010-08-24 22:26:52 +02:00
* Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
* Copyright (C) 2021 KeePassXC Team <team@keepassxc.org>
2010-08-24 22:26:52 +02:00
*
* 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 16:01:30 -04:00
#include <QFileSystemWatcher>
#include <QListView>
#include <QStackedWidget>
2010-08-24 22:26:52 +02:00
#include "DatabaseOpenDialog.h"
#include "config-keepassx.h"
#include "gui/MessageWidget.h"
#include "gui/csvImport/CsvImportWizard.h"
2018-03-31 16:01:30 -04:00
#include "gui/entry/EntryModel.h"
class DatabaseOpenWidget;
class KeePass1OpenWidget;
class OpVaultOpenWidget;
class DatabaseSettingsDialog;
class ReportsDialog;
2010-08-24 22:26:52 +02:00
class Database;
class FileWatcher;
2010-10-06 19:40:50 +02:00
class EditEntryWidget;
class EditGroupWidget;
2010-10-06 19:40:50 +02:00
class Entry;
2010-08-24 22:26:52 +02:00
class EntryView;
class EntrySearcher;
class Group;
2010-08-24 22:26:52 +02:00
class GroupView;
class QFile;
class QMenu;
class QSplitter;
class QLabel;
class MessageWidget;
class EntryPreviewWidget;
class TagView;
2010-08-24 22:26:52 +02:00
2018-03-31 16:01:30 -04:00
namespace Ui
{
class SearchWidget;
}
2010-10-06 19:40:50 +02:00
class DatabaseWidget : public QStackedWidget
2010-08-24 22:26:52 +02:00
{
Q_OBJECT
public:
friend class DatabaseOpenDialog;
enum class Mode
{
2012-04-25 20:22:55 +02:00
None,
ImportMode,
2012-04-25 20:22:55 +02:00
ViewMode,
2012-10-12 12:12:00 +02:00
EditMode,
LockedMode
};
explicit DatabaseWidget(QSharedPointer<Database> db, QWidget* parent = nullptr);
explicit DatabaseWidget(const QString& filePath, QWidget* parent = nullptr);
~DatabaseWidget() override;
void setFocus(Qt::FocusReason reason);
QSharedPointer<Database> database() const;
DatabaseWidget::Mode currentMode() const;
bool isLocked() const;
bool isSaving() const;
bool isSorted() const;
bool isSearchActive() const;
bool isEntryViewActive() const;
bool isEntryEditActive() const;
bool isGroupEditActive() const;
QString getCurrentSearch();
void refreshSearch();
GroupView* groupView();
EntryView* entryView();
Group* currentGroup() const;
2021-02-15 17:10:02 +02:00
bool canCloneCurrentGroup() const;
bool canDeleteCurrentGroup() const;
bool isGroupSelected() const;
bool isRecycleBinSelected() const;
2014-05-15 22:53:59 +02:00
int numberOfSelectedEntries() const;
int currentEntryIndex() const;
2014-05-15 22:53:59 +02:00
QStringList customEntryAttributes() const;
bool isEditWidgetModified() const;
void clearAllWidgets();
Entry* currentSelectedEntry();
bool currentEntryHasTitle();
bool currentEntryHasUsername();
bool currentEntryHasPassword();
bool currentEntryHasUrl();
bool currentEntryHasNotes();
2017-04-13 07:05:36 -03:00
bool currentEntryHasTotp();
2018-05-10 16:12:36 +03:00
#ifdef WITH_XC_SSHAGENT
bool currentEntryHasSshKey();
#endif
QByteArray entryViewState() const;
bool setEntryViewState(const QByteArray& state) const;
QHash<Config::ConfigKey, QList<int>> splitterSizes() const;
void setSplitterSizes(const QHash<Config::ConfigKey, QList<int>>& sizes);
void setSearchStringForAutoType(const QString& search);
signals:
// relayed Database signals
void databaseFilePathChanged(const QString& oldPath, const QString& newPath);
void databaseModified();
void databaseSaved();
void databaseUnlocked();
void databaseLockRequested();
void databaseLocked();
// Emitted in replaceDatabase, may be caused by lock, reload, unlock, load.
void databaseReplaced(const QSharedPointer<Database>& oldDb, const QSharedPointer<Database>& newDb);
void closeRequest();
2012-04-25 20:22:55 +02:00
void currentModeChanged(DatabaseWidget::Mode mode);
void groupChanged();
void entrySelectionChanged();
void
requestOpenDatabase(const QString& filePath, bool inBackground, const QString& password, const QString& keyFile);
void databaseMerged(QSharedPointer<Database> mergedDb);
void groupContextMenuRequested(const QPoint& globalPos);
void entryContextMenuRequested(const QPoint& globalPos);
void listModeAboutToActivate();
void listModeActivated();
void searchModeAboutToActivate();
void searchModeActivated();
void splitterSizesChanged();
void entryViewStateChanged();
void clearSearch();
void requestGlobalAutoType(const QString& search);
void requestSearch(const QString& search);
public slots:
bool lock();
bool save();
bool saveAs();
bool saveBackup();
void replaceDatabase(QSharedPointer<Database> db);
2011-12-27 16:04:59 +01:00
void createEntry();
void cloneEntry();
void deleteSelectedEntries();
2021-11-10 01:09:30 +01:00
void restoreSelectedEntries();
FdoSecrets: Major Refactor and Code Consolidation (#5747) * Fixes #3837 * Change objects to use DBusMgr rather than separate adaptors - Update all DBus invokable methods to new parameter order - Change all usage of DBusReturn to simpler DBusResult - Use DBusMgr to handle path and service registration - Remove adaptor/* - Set path in DBusObject - Unregister service when service is destroyed - Restore handling of invalid QVariant in prompt complete signal - Clean up meta type registration - Move dbus related file together - Convert to QSharedPointer as much as possible - Fix mapping of the Delete method - Handle dbus property get all * Add per-client states - Move cipher negotiation to DBusClient - Show list of clients instead of sessions in the settings page - Add settings for confirmation of accessing items - Fix infinite recursion when client disconnected - Use optional explicit DBusClient parameter instead. This makes accessing the client info in an async context explicit, and thus prevent accidental assertions in prompts. * Improve User Interface - Add per-item access confirmation (if enabled) - Remove the "disable for site" button for the access control dialog - Improve the text on the settings page to be more consistent - Fix disconnect buttons in settings page not working - Make the unlock prompt method nonblocking * Fix and cleanup unit tests - Use QTRY_COMPARE when checking signal spies, as dbus signals are threaded - Fixes in meta type registration and type conversion - Remove QStringLiteral in COMPARE macros, making diff output readable - Add testing for remembering auth decision
2021-02-05 15:07:59 -05:00
void deleteEntries(QList<Entry*> entries, bool confirm = true);
void focusOnEntries(bool editIfFocused = false);
void focusOnGroups(bool editIfFocused = false);
void moveEntryUp();
void moveEntryDown();
void copyTitle();
void copyUsername();
void copyPassword();
void copyURL();
void copyNotes();
void copyAttribute(QAction* action);
void filterByTag();
void setTag(QAction* action);
2017-04-13 07:05:36 -03:00
void showTotp();
void showTotpKeyQrCode();
2017-04-13 07:05:36 -03:00
void copyTotp();
void copyPasswordTotp();
2017-04-13 07:05:36 -03:00
void setupTotp();
2018-05-10 16:12:36 +03:00
#ifdef WITH_XC_SSHAGENT
void addToAgent();
void removeFromAgent();
#endif
void performAutoType(const QString& sequence = {});
void performAutoTypeUsername();
void performAutoTypeUsernameEnter();
void performAutoTypePassword();
void performAutoTypePasswordEnter();
2021-06-28 14:44:14 +03:00
void performAutoTypeTOTP();
void openUrl();
void downloadSelectedFavicons();
void downloadAllFavicons();
void downloadFaviconInBackground(Entry* entry);
void openUrlForEntry(Entry* entry);
void createGroup();
2021-02-15 17:10:02 +02:00
void cloneGroup();
void deleteGroup();
void switchToMainView(bool previousDialogAccepted = false);
void switchToEntryEdit();
void switchToGroupEdit();
void sortGroupsAsc();
void sortGroupsDesc();
void switchToDatabaseSecurity();
void switchToDatabaseReports();
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 performUnlockDatabase(const QString& password, const QString& keyfile = {});
void csvImportFinished(bool accepted);
void switchToImportKeepass1(const QString& filePath);
void switchToImportOpVault(const QString& fileName);
2017-04-21 17:33:06 +03:00
void emptyRecycleBin();
// Search related slots
void search(const QString& searchtext);
void saveSearch(const QString& searchtext);
void deleteSearch(const QString& name);
void setSearchCaseSensitive(bool state);
void setSearchLimitGroup(bool state);
void endSearch();
2018-03-31 16:01:30 -04:00
void showMessage(const QString& text,
MessageWidget::MessageType type,
bool showClosebutton = true,
int autoHideTimeout = MessageWidget::DefaultAutoHideTimeout);
2017-12-25 15:53:22 +02:00
void showErrorMessage(const QString& errorMessage);
void hideMessage();
2010-08-24 22:26:52 +02:00
protected:
void closeEvent(QCloseEvent* event) override;
void showEvent(QShowEvent* event) override;
bool focusNextPrevChild(bool next) override;
private slots:
void entryActivationSignalReceived(Entry* entry, EntryModel::ModelColumn column);
2012-05-15 20:12:05 +02:00
void switchBackToEntryEdit();
2012-05-20 23:14:34 +02:00
void switchToHistoryView(Entry* entry);
void switchToEntryEdit(Entry*);
2011-12-27 16:04:59 +01:00
void switchToEntryEdit(Entry* entry, bool create);
void switchToGroupEdit(Group* entry, bool create);
void emitGroupContextMenuRequested(const QPoint& pos);
void emitEntryContextMenuRequested(const QPoint& pos);
void onEntryChanged(Entry* entry);
void onGroupChanged();
void onDatabaseModified();
void connectDatabaseSignals();
void loadDatabase(bool accepted);
2012-10-12 12:12:00 +02:00
void unlockDatabase(bool accepted);
void mergeDatabase(bool accepted);
void emitCurrentModeChanged();
// Database autoreload slots
void reloadDatabaseFile();
2018-03-22 22:56:05 +01:00
void restoreGroupEntryFocus(const QUuid& groupUuid, const QUuid& EntryUuid);
2010-10-06 19:40:50 +02:00
2010-08-24 22:26:52 +02:00
private:
int addChildWidget(QWidget* w);
2013-12-01 09:59:43 +01:00
void setClipboardTextAndMinimize(const QString& text);
void processAutoOpen();
void openDatabaseFromEntry(const Entry* entry, bool inBackground = true);
void performIconDownloads(const QList<Entry*>& entries, bool force = false, bool downloadInBackground = false);
bool performSave(QString& errorMessage, const QString& fileName = {});
QSharedPointer<Database> m_db;
QPointer<QWidget> m_mainWidget;
QPointer<QSplitter> m_mainSplitter;
QPointer<QSplitter> m_groupSplitter;
QPointer<MessageWidget> m_messageWidget;
QPointer<EntryPreviewWidget> m_previewView;
QPointer<QSplitter> m_previewSplitter;
QPointer<QLabel> m_searchingLabel;
QPointer<QLabel> m_shareLabel;
QPointer<CsvImportWizard> m_csvImportWizard;
QPointer<EditEntryWidget> m_editEntryWidget;
QPointer<EditGroupWidget> m_editGroupWidget;
QPointer<EditEntryWidget> m_historyEditEntryWidget;
QPointer<ReportsDialog> m_reportsDialog;
QPointer<DatabaseSettingsDialog> m_databaseSettingDialog;
QPointer<DatabaseOpenWidget> m_databaseOpenWidget;
QPointer<KeePass1OpenWidget> m_keepass1OpenWidget;
QPointer<OpVaultOpenWidget> m_opVaultOpenWidget;
QPointer<GroupView> m_groupView;
QPointer<TagView> m_tagView;
QPointer<EntryView> m_entryView;
QScopedPointer<Group> m_newGroup;
QScopedPointer<Entry> m_newEntry;
QPointer<Group> m_newParent;
2018-03-22 22:56:05 +01:00
QUuid m_groupBeforeLock;
QUuid m_entryBeforeLock;
int m_saveAttempts;
// Search state
QScopedPointer<EntrySearcher> m_entrySearcher;
QString m_lastSearchText;
QString m_nextSearchLabelText;
bool m_searchLimitGroup;
// Autoreload
bool m_blockAutoSave;
// Auto-Type related
QString m_searchStringForAutoType;
2010-08-24 22:26:52 +02:00
};
#endif // KEEPASSX_DATABASEWIDGET_H