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
|
|
|
|
|
2013-10-03 09:18:16 -04:00
|
|
|
#include <QScopedPointer>
|
|
|
|
#include <QStackedWidget>
|
2016-11-09 07:38:14 -05:00
|
|
|
#include <QFileSystemWatcher>
|
|
|
|
#include <QTimer>
|
2010-08-24 16:26:52 -04:00
|
|
|
|
2015-01-11 10:20:59 -05:00
|
|
|
#include "core/Uuid.h"
|
2012-06-29 08:15:16 -04:00
|
|
|
|
2013-04-14 13:14:06 -04:00
|
|
|
#include "gui/entry/EntryModel.h"
|
2015-01-21 11:19:05 -05:00
|
|
|
#include "gui/MessageWidget.h"
|
2017-01-08 19:33:21 -05:00
|
|
|
#include "gui/csvImport/CsvImportWizard.h"
|
2013-04-14 13:14:06 -04:00
|
|
|
|
2012-01-13 11:52:37 -05:00
|
|
|
class ChangeMasterKeyWidget;
|
2012-06-28 03:21:15 -04:00
|
|
|
class DatabaseOpenWidget;
|
2012-04-19 10:20:20 -04:00
|
|
|
class DatabaseSettingsWidget;
|
2010-08-24 16:26:52 -04:00
|
|
|
class Database;
|
2010-10-06 13:40:50 -04:00
|
|
|
class EditEntryWidget;
|
2011-12-27 09:49:06 -05:00
|
|
|
class EditGroupWidget;
|
2010-10-06 13:40:50 -04:00
|
|
|
class Entry;
|
2010-08-24 16:26:52 -04:00
|
|
|
class EntryView;
|
2011-12-27 09:49:06 -05:00
|
|
|
class Group;
|
2010-08-24 16:26:52 -04:00
|
|
|
class GroupView;
|
2012-06-28 03:21:15 -04:00
|
|
|
class KeePass1OpenWidget;
|
|
|
|
class QFile;
|
2012-05-25 07:17:46 -04:00
|
|
|
class QMenu;
|
2014-05-17 05:16:27 -04:00
|
|
|
class QSplitter;
|
2016-11-02 21:01:02 -04:00
|
|
|
class QLabel;
|
2012-10-12 06:12:00 -04:00
|
|
|
class UnlockDatabaseWidget;
|
2015-01-21 11:19:05 -05:00
|
|
|
class MessageWidget;
|
2017-08-17 15:02:21 -04:00
|
|
|
class DetailsWidget;
|
2016-11-11 16:26:07 -05:00
|
|
|
class UnlockDatabaseDialog;
|
2016-11-09 07:38:14 -05:00
|
|
|
class QFileSystemWatcher;
|
2010-08-24 16:26:52 -04:00
|
|
|
|
2015-01-21 11:19:05 -05: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:
|
2012-04-24 19:32:05 -04:00
|
|
|
enum Mode
|
|
|
|
{
|
2012-04-25 14:22:55 -04:00
|
|
|
None,
|
2017-02-17 19:51:31 -05:00
|
|
|
ImportMode,
|
2012-04-25 14:22:55 -04:00
|
|
|
ViewMode,
|
2012-10-12 06:12:00 -04:00
|
|
|
EditMode,
|
|
|
|
LockedMode
|
2012-04-24 19:32:05 -04:00
|
|
|
};
|
|
|
|
|
2015-07-24 12:28:12 -04:00
|
|
|
explicit DatabaseWidget(Database* db, QWidget* parent = nullptr);
|
2012-05-19 05:53:32 -04:00
|
|
|
~DatabaseWidget();
|
2012-07-06 13:21:19 -04:00
|
|
|
Database* database();
|
2014-05-15 16:53:59 -04:00
|
|
|
bool dbHasKey() const;
|
2014-05-15 16:56:36 -04:00
|
|
|
bool canDeleteCurrentGroup() const;
|
2014-05-15 16:53:59 -04:00
|
|
|
bool isInSearchMode() const;
|
2016-11-02 21:01:02 -04:00
|
|
|
QString getCurrentSearch();
|
2016-11-07 22:37:42 -05:00
|
|
|
Group* currentGroup() const;
|
2012-04-24 04:51:22 -04:00
|
|
|
int addWidget(QWidget* w);
|
|
|
|
void setCurrentIndex(int index);
|
2012-10-12 06:12:00 -04:00
|
|
|
void setCurrentWidget(QWidget* widget);
|
2014-05-15 16:51:13 -04:00
|
|
|
DatabaseWidget::Mode currentMode() const;
|
2012-10-12 06:12:00 -04:00
|
|
|
void lock();
|
2017-12-20 10:18:01 -05:00
|
|
|
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;
|
2014-05-15 16:51:13 -04:00
|
|
|
bool isInEditMode() const;
|
2016-07-31 18:22:04 -04:00
|
|
|
bool isEditWidgetModified() const;
|
2017-10-28 14:14:45 -04:00
|
|
|
QList<int> mainSplitterSizes() const;
|
|
|
|
void setMainSplitterSizes(const QList<int>& sizes);
|
|
|
|
QList<int> detailSplitterSizes() const;
|
|
|
|
void setDetailSplitterSizes(const QList<int>& sizes);
|
2018-01-16 07:20:45 -05:00
|
|
|
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;
|
2015-01-11 10:20:59 -05:00
|
|
|
void clearAllWidgets();
|
2015-05-12 15:54:39 -04:00
|
|
|
bool currentEntryHasTitle();
|
|
|
|
bool currentEntryHasUsername();
|
|
|
|
bool currentEntryHasPassword();
|
|
|
|
bool currentEntryHasUrl();
|
|
|
|
bool currentEntryHasNotes();
|
2017-04-13 06:05:36 -04:00
|
|
|
bool currentEntryHasTotp();
|
2016-11-07 22:37:42 -05:00
|
|
|
GroupView* groupView();
|
|
|
|
EntryView* entryView();
|
2016-11-11 16:26:07 -05:00
|
|
|
void showUnlockDialog();
|
|
|
|
void closeUnlockDialog();
|
2017-02-24 12:43:15 -05:00
|
|
|
void blockAutoReload(bool block = true);
|
2017-02-27 20:25:56 -05:00
|
|
|
void refreshSearch();
|
2017-04-21 06:49:32 -04:00
|
|
|
bool isRecycleBinSelected() const;
|
2011-12-27 09:49:06 -05:00
|
|
|
|
2017-02-24 12:43:15 -05:00
|
|
|
signals:
|
2012-04-11 14:35:52 -04:00
|
|
|
void closeRequest();
|
2012-04-25 14:22:55 -04:00
|
|
|
void currentModeChanged(DatabaseWidget::Mode mode);
|
2012-08-01 04:35:37 -04:00
|
|
|
void groupChanged();
|
|
|
|
void entrySelectionChanged();
|
2016-11-11 17:58:47 -05:00
|
|
|
void databaseChanged(Database* newDb, bool unsavedChanges);
|
2016-11-07 22:37:42 -05:00
|
|
|
void databaseMerged(Database* mergedDb);
|
2012-08-01 04:35:37 -04:00
|
|
|
void groupContextMenuRequested(const QPoint& globalPos);
|
|
|
|
void entryContextMenuRequested(const QPoint& globalPos);
|
2017-08-17 15:02:21 -04:00
|
|
|
void pressedEntry(Entry* selectedEntry);
|
|
|
|
void pressedGroup(Group* selectedGroup);
|
2012-10-12 06:12:00 -04:00
|
|
|
void unlockedDatabase();
|
2014-05-17 12:05:02 -04:00
|
|
|
void listModeAboutToActivate();
|
2014-05-17 05:16:27 -04:00
|
|
|
void listModeActivated();
|
2014-05-17 12:05:02 -04:00
|
|
|
void searchModeAboutToActivate();
|
2014-05-17 05:16:27 -04:00
|
|
|
void searchModeActivated();
|
2017-10-28 14:14:45 -04:00
|
|
|
void mainSplitterSizesChanged();
|
|
|
|
void detailSplitterSizesChanged();
|
2017-12-23 02:40:00 -05:00
|
|
|
void entryViewStateChanged();
|
2016-11-02 21:01:02 -04:00
|
|
|
void updateSearch(QString text);
|
2015-01-05 04:50:04 -05:00
|
|
|
|
2017-02-24 12:43:15 -05:00
|
|
|
public slots:
|
2011-12-27 10:04:59 -05:00
|
|
|
void createEntry();
|
2012-05-25 07:17:46 -04:00
|
|
|
void cloneEntry();
|
2013-10-08 15:36:01 -04:00
|
|
|
void deleteEntries();
|
2016-12-22 02:21:52 -05:00
|
|
|
void setFocus();
|
2013-12-01 03:43:41 -05:00
|
|
|
void copyTitle();
|
2012-05-26 10:20:32 -04:00
|
|
|
void copyUsername();
|
|
|
|
void copyPassword();
|
2013-12-01 03:43:41 -05:00
|
|
|
void copyURL();
|
|
|
|
void copyNotes();
|
2012-10-23 18:15:23 -04:00
|
|
|
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();
|
2012-07-27 12:38:52 -04:00
|
|
|
void openUrl();
|
2013-04-07 15:05:52 -04:00
|
|
|
void openUrlForEntry(Entry* entry);
|
2011-12-27 09:49:06 -05:00
|
|
|
void createGroup();
|
2012-05-25 07:17:46 -04:00
|
|
|
void deleteGroup();
|
2016-11-28 19:02:21 -05:00
|
|
|
void onGroupChanged(Group* group);
|
2016-11-07 22:37:42 -05:00
|
|
|
void switchToView(bool accepted);
|
2011-12-27 09:49:06 -05:00
|
|
|
void switchToEntryEdit();
|
|
|
|
void switchToGroupEdit();
|
2017-02-16 17:18:04 -05:00
|
|
|
void switchToMasterKeyChange(bool disableCancel = false);
|
2012-04-19 10:20:20 -04:00
|
|
|
void switchToDatabaseSettings();
|
2017-12-20 10:18:01 -05:00
|
|
|
void switchToOpenDatabase(const QString& filePath);
|
|
|
|
void switchToOpenDatabase(const QString& filePath, const QString& password, const QString& keyFile);
|
|
|
|
void switchToImportCsv(const QString& filePath);
|
2017-01-08 19:33:21 -05:00
|
|
|
void csvImportFinished(bool accepted);
|
2017-12-20 10:18:01 -05:00
|
|
|
void switchToOpenMergeDatabase(const QString& filePath);
|
|
|
|
void switchToOpenMergeDatabase(const QString& filePath, const QString& password, const QString& keyFile);
|
|
|
|
void switchToImportKeepass1(const QString& filePath);
|
2016-11-11 17:58:47 -05:00
|
|
|
void databaseModified();
|
|
|
|
void databaseSaved();
|
2017-04-21 10:33:06 -04:00
|
|
|
void emptyRecycleBin();
|
2017-03-04 12:19:18 -05:00
|
|
|
|
2016-11-02 21:01:02 -04:00
|
|
|
// Search related slots
|
|
|
|
void search(const QString& searchtext);
|
|
|
|
void setSearchCaseSensitive(bool state);
|
2017-06-20 15:54:13 -04:00
|
|
|
void setSearchLimitGroup(bool state);
|
2016-11-02 21:01:02 -04:00
|
|
|
void endSearch();
|
2017-03-04 12:19:18 -05:00
|
|
|
|
2017-10-19 14:46:09 -04:00
|
|
|
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);
|
2015-01-21 11:19:05 -05:00
|
|
|
void hideMessage();
|
2010-08-24 16:26:52 -04:00
|
|
|
|
2017-02-24 12:43:15 -05:00
|
|
|
private slots:
|
2013-04-14 13:14:06 -04:00
|
|
|
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);
|
2011-12-27 09:49:06 -05:00
|
|
|
void switchToEntryEdit(Entry* entry);
|
2011-12-27 10:04:59 -05:00
|
|
|
void switchToEntryEdit(Entry* entry, bool create);
|
2011-12-27 09:49:06 -05:00
|
|
|
void switchToGroupEdit(Group* entry, bool create);
|
2014-05-17 05:22:45 -04:00
|
|
|
void emitGroupContextMenuRequested(const QPoint& pos);
|
|
|
|
void emitEntryContextMenuRequested(const QPoint& pos);
|
2017-08-17 15:02:21 -04:00
|
|
|
void emitPressedEntry();
|
|
|
|
void emitPressedEntry(Entry* currentEntry);
|
|
|
|
void emitPressedGroup(Group* currentGroup);
|
2012-01-13 11:52:37 -05:00
|
|
|
void updateMasterKey(bool accepted);
|
2012-06-28 03:21:15 -04:00
|
|
|
void openDatabase(bool accepted);
|
2016-11-07 22:37:42 -05:00
|
|
|
void mergeDatabase(bool accepted);
|
2012-10-12 06:12:00 -04:00
|
|
|
void unlockDatabase(bool accepted);
|
2012-04-24 19:32:05 -04:00
|
|
|
void emitCurrentModeChanged();
|
2016-11-09 07:38:14 -05:00
|
|
|
// Database autoreload slots
|
|
|
|
void onWatchedFileChanged();
|
|
|
|
void reloadDatabaseFile();
|
2017-01-24 22:17:16 -05:00
|
|
|
void restoreGroupEntryFocus(Uuid groupUuid, Uuid EntryUuid);
|
2017-02-24 12:43:15 -05:00
|
|
|
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);
|
2014-04-14 17:20:24 -04:00
|
|
|
void setIconFromParent();
|
2015-01-11 10:20:59 -05:00
|
|
|
void replaceDatabase(Database* db);
|
2013-12-01 03:59:43 -05:00
|
|
|
|
2012-06-28 03:21:15 -04:00
|
|
|
Database* m_db;
|
2010-10-06 13:40:50 -04:00
|
|
|
QWidget* m_mainWidget;
|
2011-12-27 09:49:06 -05:00
|
|
|
EditEntryWidget* m_editEntryWidget;
|
2012-05-15 14:12:05 -04:00
|
|
|
EditEntryWidget* m_historyEditEntryWidget;
|
2011-12-27 09:49:06 -05:00
|
|
|
EditGroupWidget* m_editGroupWidget;
|
2012-01-13 11:52:37 -05:00
|
|
|
ChangeMasterKeyWidget* m_changeMasterKeyWidget;
|
2017-01-08 19:33:21 -05:00
|
|
|
CsvImportWizard* m_csvImportWizard;
|
2012-04-19 10:20:20 -04:00
|
|
|
DatabaseSettingsWidget* m_databaseSettingsWidget;
|
2012-06-28 03:21:15 -04:00
|
|
|
DatabaseOpenWidget* m_databaseOpenWidget;
|
2016-11-07 22:37:42 -05:00
|
|
|
DatabaseOpenWidget* m_databaseOpenMergeWidget;
|
2012-06-28 03:21:15 -04:00
|
|
|
KeePass1OpenWidget* m_keepass1OpenWidget;
|
2012-10-12 06:12:00 -04:00
|
|
|
UnlockDatabaseWidget* m_unlockDatabaseWidget;
|
2016-11-11 16:26:07 -05:00
|
|
|
UnlockDatabaseDialog* m_unlockDatabaseDialog;
|
2017-10-28 14:14:45 -04:00
|
|
|
QSplitter* m_mainSplitter;
|
2017-08-17 15:02:21 -04:00
|
|
|
QSplitter* m_detailSplitter;
|
2010-08-24 16:26:52 -04:00
|
|
|
GroupView* m_groupView;
|
|
|
|
EntryView* m_entryView;
|
2016-11-02 21:01:02 -04:00
|
|
|
QLabel* m_searchingLabel;
|
2011-12-27 09:49:06 -05:00
|
|
|
Group* m_newGroup;
|
2011-12-27 10:04:59 -05:00
|
|
|
Entry* m_newEntry;
|
|
|
|
Group* m_newParent;
|
2017-12-20 10:18:01 -05:00
|
|
|
QString m_filePath;
|
2015-01-11 10:20:59 -05:00
|
|
|
Uuid m_groupBeforeLock;
|
2017-01-24 22:17:16 -05:00
|
|
|
Uuid m_entryBeforeLock;
|
2015-01-21 11:19:05 -05:00
|
|
|
MessageWidget* m_messageWidget;
|
2017-08-17 15:02:21 -04:00
|
|
|
DetailsWidget* m_detailsView;
|
2016-11-02 21:01:02 -04:00
|
|
|
|
|
|
|
// Search state
|
|
|
|
QString m_lastSearchText;
|
|
|
|
bool m_searchCaseSensitive;
|
2017-06-20 15:54:13 -04:00
|
|
|
bool m_searchLimitGroup;
|
2016-11-07 22:52:32 -05:00
|
|
|
|
2017-10-29 10:04:46 -04:00
|
|
|
// CSV import state
|
|
|
|
bool m_importingCsv;
|
|
|
|
|
2016-11-11 17:58:47 -05:00
|
|
|
// Autoreload
|
2016-11-09 07:38:14 -05:00
|
|
|
QFileSystemWatcher m_fileWatcher;
|
|
|
|
QTimer m_fileWatchTimer;
|
2017-02-24 12:43:15 -05:00
|
|
|
QTimer m_fileWatchUnblockTimer;
|
|
|
|
bool m_ignoreAutoReload;
|
2016-11-11 17:58:47 -05:00
|
|
|
bool m_databaseModified;
|
2010-08-24 16:26:52 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // KEEPASSX_DATABASEWIDGET_H
|