keepassxc/src/gui/DatabaseWidget.h

256 lines
8.1 KiB
C++
Raw Normal View History

2017-06-09 17:40:36 -04:00
/*
2010-08-24 16:26:52 -04:00
* Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
2017-06-09 17:40:36 -04:00
* Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
2010-08-24 16:26:52 -04: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
#include <QScopedPointer>
#include <QStackedWidget>
#include <QFileSystemWatcher>
#include <QTimer>
2010-08-24 16:26:52 -04:00
#include "core/Uuid.h"
2012-06-29 08:15:16 -04:00
#include "gui/entry/EntryModel.h"
#include "gui/MessageWidget.h"
#include "gui/csvImport/CsvImportWizard.h"
class ChangeMasterKeyWidget;
class DatabaseOpenWidget;
class DatabaseSettingsWidget;
2010-08-24 16:26:52 -04:00
class Database;
2010-10-06 13:40:50 -04:00
class EditEntryWidget;
class EditGroupWidget;
2010-10-06 13:40:50 -04:00
class Entry;
2010-08-24 16:26:52 -04:00
class EntryView;
class Group;
2010-08-24 16:26:52 -04:00
class GroupView;
class KeePass1OpenWidget;
class QFile;
class QMenu;
class QSplitter;
class QLabel;
2012-10-12 06:12:00 -04:00
class UnlockDatabaseWidget;
class MessageWidget;
class DetailsWidget;
class UnlockDatabaseDialog;
class QFileSystemWatcher;
2010-08-24 16:26:52 -04:00
namespace Ui {
class SearchWidget;
}
2010-10-06 13:40:50 -04:00
class DatabaseWidget : public QStackedWidget
2010-08-24 16:26:52 -04:00
{
Q_OBJECT
public:
enum Mode
{
2012-04-25 14:22:55 -04:00
None,
ImportMode,
2012-04-25 14:22:55 -04:00
ViewMode,
2012-10-12 06:12:00 -04:00
EditMode,
LockedMode
};
2015-07-24 12:28:12 -04:00
explicit DatabaseWidget(Database* db, QWidget* parent = nullptr);
~DatabaseWidget();
2012-07-06 13:21:19 -04:00
Database* database();
2014-05-15 16:53:59 -04:00
bool dbHasKey() const;
bool canDeleteCurrentGroup() const;
2014-05-15 16:53:59 -04:00
bool isInSearchMode() const;
QString getCurrentSearch();
Group* currentGroup() const;
int addWidget(QWidget* w);
void setCurrentIndex(int index);
2012-10-12 06:12:00 -04:00
void setCurrentWidget(QWidget* widget);
DatabaseWidget::Mode currentMode() const;
2012-10-12 06:12:00 -04:00
void lock();
void updateFilePath(const QString &filePath);
2014-05-15 16:53:59 -04:00
int numberOfSelectedEntries() const;
QStringList customEntryAttributes() const;
2014-05-17 05:21:50 -04:00
bool isGroupSelected() const;
bool isInEditMode() const;
bool isEditWidgetModified() const;
QList<int> mainSplitterSizes() const;
void setMainSplitterSizes(const QList<int>& sizes);
QList<int> detailSplitterSizes() const;
void setDetailSplitterSizes(const QList<int>& sizes);
bool isUsernamesHidden() const;
void setUsernamesHidden(const bool hide);
bool isPasswordsHidden() const;
void setPasswordsHidden(const bool hide);
QByteArray entryViewState() const;
bool setEntryViewState(const QByteArray& state) const;
void clearAllWidgets();
bool currentEntryHasTitle();
bool currentEntryHasUsername();
bool currentEntryHasPassword();
bool currentEntryHasUrl();
bool currentEntryHasNotes();
2017-04-13 06:05:36 -04:00
bool currentEntryHasTotp();
GroupView* groupView();
EntryView* entryView();
void showUnlockDialog();
void closeUnlockDialog();
void blockAutoReload(bool block = true);
void refreshSearch();
bool isRecycleBinSelected() const;
signals:
void closeRequest();
2012-04-25 14:22:55 -04:00
void currentModeChanged(DatabaseWidget::Mode mode);
void groupChanged();
void entrySelectionChanged();
void databaseChanged(Database* newDb, bool unsavedChanges);
void databaseMerged(Database* mergedDb);
void groupContextMenuRequested(const QPoint& globalPos);
void entryContextMenuRequested(const QPoint& globalPos);
void pressedEntry(Entry* selectedEntry);
void pressedGroup(Group* selectedGroup);
2012-10-12 06:12:00 -04:00
void unlockedDatabase();
void listModeAboutToActivate();
void listModeActivated();
void searchModeAboutToActivate();
void searchModeActivated();
void mainSplitterSizesChanged();
void detailSplitterSizesChanged();
void entryViewStateChanged();
void updateSearch(QString text);
public slots:
2011-12-27 10:04:59 -05:00
void createEntry();
void cloneEntry();
2013-10-08 15:36:01 -04:00
void deleteEntries();
void setFocus();
void copyTitle();
void copyUsername();
void copyPassword();
void copyURL();
void copyNotes();
void copyAttribute(QAction* action);
2017-04-13 06:05:36 -04:00
void showTotp();
void copyTotp();
void setupTotp();
2012-07-12 16:35:51 -04: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(bool disableCancel = false);
void switchToDatabaseSettings();
void switchToOpenDatabase(const QString& filePath);
void switchToOpenDatabase(const QString& filePath, const QString& password, const QString& keyFile);
void switchToImportCsv(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();
2017-04-21 10:33:06 -04:00
void emptyRecycleBin();
// Search related slots
void search(const QString& searchtext);
void setSearchCaseSensitive(bool state);
void setSearchLimitGroup(bool state);
void endSearch();
void showMessage(const QString& text, MessageWidget::MessageType type, bool showClosebutton = true,
int autoHideTimeout = MessageWidget::DefaultAutoHideTimeout);
2017-12-25 08:53:22 -05:00
void showErrorMessage(const QString& errorMessage);
void hideMessage();
2010-08-24 16:26:52 -04:00
private slots:
void entryActivationSignalReceived(Entry* entry, EntryModel::ModelColumn column);
2012-05-15 14:12:05 -04:00
void switchBackToEntryEdit();
2012-05-20 17:14:34 -04:00
void switchToHistoryView(Entry* entry);
void switchToEntryEdit(Entry* entry);
2011-12-27 10:04:59 -05:00
void switchToEntryEdit(Entry* entry, bool create);
void switchToGroupEdit(Group* entry, bool create);
void emitGroupContextMenuRequested(const QPoint& pos);
void emitEntryContextMenuRequested(const QPoint& pos);
void emitPressedEntry();
void emitPressedEntry(Entry* currentEntry);
void emitPressedGroup(Group* currentGroup);
void updateMasterKey(bool accepted);
void openDatabase(bool accepted);
void mergeDatabase(bool accepted);
2012-10-12 06:12:00 -04:00
void unlockDatabase(bool accepted);
void emitCurrentModeChanged();
// Database autoreload slots
void onWatchedFileChanged();
void reloadDatabaseFile();
void restoreGroupEntryFocus(Uuid groupUuid, Uuid EntryUuid);
void unblockAutoReload();
2010-10-06 13:40:50 -04:00
2010-08-24 16:26:52 -04:00
private:
2013-12-01 03:59:43 -05:00
void setClipboardTextAndMinimize(const QString& text);
void setIconFromParent();
void replaceDatabase(Database* db);
2013-12-01 03:59:43 -05:00
Database* m_db;
2010-10-06 13:40:50 -04:00
QWidget* m_mainWidget;
EditEntryWidget* m_editEntryWidget;
2012-05-15 14:12:05 -04:00
EditEntryWidget* m_historyEditEntryWidget;
EditGroupWidget* m_editGroupWidget;
ChangeMasterKeyWidget* m_changeMasterKeyWidget;
CsvImportWizard* m_csvImportWizard;
DatabaseSettingsWidget* m_databaseSettingsWidget;
DatabaseOpenWidget* m_databaseOpenWidget;
DatabaseOpenWidget* m_databaseOpenMergeWidget;
KeePass1OpenWidget* m_keepass1OpenWidget;
2012-10-12 06:12:00 -04:00
UnlockDatabaseWidget* m_unlockDatabaseWidget;
UnlockDatabaseDialog* m_unlockDatabaseDialog;
QSplitter* m_mainSplitter;
QSplitter* m_detailSplitter;
2010-08-24 16:26:52 -04:00
GroupView* m_groupView;
EntryView* m_entryView;
QLabel* m_searchingLabel;
Group* m_newGroup;
2011-12-27 10:04:59 -05:00
Entry* m_newEntry;
Group* m_newParent;
QString m_filePath;
Uuid m_groupBeforeLock;
Uuid m_entryBeforeLock;
MessageWidget* m_messageWidget;
DetailsWidget* m_detailsView;
// Search state
QString m_lastSearchText;
bool m_searchCaseSensitive;
bool m_searchLimitGroup;
2017-10-29 10:04:46 -04:00
// CSV import state
bool m_importingCsv;
// Autoreload
QFileSystemWatcher m_fileWatcher;
QTimer m_fileWatchTimer;
QTimer m_fileWatchUnblockTimer;
bool m_ignoreAutoReload;
bool m_databaseModified;
2010-08-24 16:26:52 -04:00
};
#endif // KEEPASSX_DATABASEWIDGET_H