keepassxc/src/gui/DatabaseWidget.h

274 lines
8.4 KiB
C++
Raw Normal View History

2017-06-09 23:40:36 +02:00
/*
* Copyright (C) 2018 KeePassXC Team <team@keepassxc.org>
2010-08-24 22:26:52 +02: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 16:01:30 -04:00
#include <QFileSystemWatcher>
#include <QScopedPointer>
#include <QStackedWidget>
#include <QTimer>
2010-08-24 22:26:52 +02:00
2018-03-22 22:56:05 +01:00
#include "gui/entry/EntryModel.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 DatabaseSettingsDialog;
2010-08-24 22:26:52 +02:00
class Database;
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 KeePass1OpenWidget;
class QFile;
class QMenu;
class QSplitter;
class QLabel;
2012-10-12 12:12:00 +02:00
class UnlockDatabaseWidget;
class MessageWidget;
class EntryPreviewWidget;
class UnlockDatabaseDialog;
class QFileSystemWatcher;
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:
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();
QSharedPointer<Database> database() const;
bool lock();
void prepareUnlock();
bool save(int attempt = 0);
bool saveAs();
DatabaseWidget::Mode currentMode() 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 isRecycleBinSelected() const;
2014-05-15 22:53:59 +02:00
int numberOfSelectedEntries() const;
2014-05-15 22:53:59 +02:00
QStringList customEntryAttributes() const;
bool isEditWidgetModified() const;
bool isUsernamesHidden() const;
2018-03-21 21:52:57 -04:00
void setUsernamesHidden(bool hide);
bool isPasswordsHidden() const;
2018-03-21 21:52:57 -04:00
void setPasswordsHidden(bool hide);
void clearAllWidgets();
bool currentEntryHasFocus();
bool currentEntryHasTitle();
bool currentEntryHasUsername();
bool currentEntryHasPassword();
bool currentEntryHasUrl();
bool currentEntryHasNotes();
2017-04-13 07:05:36 -03:00
bool currentEntryHasTotp();
void blockAutoReload(bool block = true);
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();
2012-04-25 20:22:55 +02:00
void currentModeChanged(DatabaseWidget::Mode mode);
void groupChanged();
void entrySelectionChanged();
void databaseMerged(QSharedPointer<Database> mergedDb);
void groupContextMenuRequested(const QPoint& globalPos);
void entryContextMenuRequested(const QPoint& globalPos);
void pressedEntry(Entry* selectedEntry);
void pressedGroup(Group* selectedGroup);
void listModeAboutToActivate();
void listModeActivated();
void searchModeAboutToActivate();
void searchModeActivated();
void mainSplitterSizesChanged();
void previewSplitterSizesChanged();
void entryViewStateChanged();
void clearSearch();
public slots:
void replaceDatabase(QSharedPointer<Database> db);
2011-12-27 16:04:59 +01:00
void createEntry();
void cloneEntry();
2013-10-08 21:36:01 +02:00
void deleteEntries();
void setFocus();
void copyTitle();
void copyUsername();
void copyPassword();
void copyURL();
void copyNotes();
void copyAttribute(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 setupTotp();
2012-07-12 22:35:51 +02:00
void performAutoType();
void openUrl();
void openUrlForEntry(Entry* entry);
void createGroup();
void deleteGroup();
void onGroupChanged(Group* group);
void switchToView(bool accepted);
void switchToEntryEdit();
void switchToGroupEdit();
void switchToMasterKeyChange();
void switchToDatabaseSettings();
void switchToOpenDatabase();
void switchToOpenDatabase(const QString& filePath);
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);
2017-04-21 17:33:06 +03:00
void emptyRecycleBin();
// Search related slots
void search(const QString& searchtext);
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;
private slots:
void updateFilePath(const QString& filePath);
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 emitPressedGroup(Group* currentGroup);
void emitEntrySelectionChanged();
void connectDatabaseSignals();
void loadDatabase(bool accepted);
void mergeDatabase(bool accepted);
2012-10-12 12:12:00 +02:00
void unlockDatabase(bool accepted);
void emitCurrentModeChanged();
// Database autoreload slots
void onWatchedFileChanged();
void reloadDatabaseFile();
2018-03-22 22:56:05 +01:00
void restoreGroupEntryFocus(const QUuid& groupUuid, const QUuid& EntryUuid);
void unblockAutoReload();
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 setIconFromParent();
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;
2018-03-22 22:56:05 +01:00
QUuid m_groupBeforeLock;
QUuid m_entryBeforeLock;
QString m_databaseName;
QString m_databaseFileName;
// Search state
EntrySearcher* m_EntrySearcher;
QString m_lastSearchText;
bool m_searchLimitGroup;
// Autoreload
QFileSystemWatcher m_fileWatcher;
QTimer m_fileWatchTimer;
QTimer m_fileWatchUnblockTimer;
bool m_ignoreAutoReload;
2010-08-24 22:26:52 +02:00
};
#endif // KEEPASSX_DATABASEWIDGET_H