2011-11-13 08:55:20 -05:00
|
|
|
/*
|
2018-02-04 07:18:59 -05:00
|
|
|
* Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
|
|
|
|
* Copyright (C) 2011 Felix Geyer <debfx@fobos.de>
|
2011-11-13 08:55:20 -05:00
|
|
|
*
|
2018-02-04 07:18:59 -05: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.
|
2011-11-13 08:55:20 -05:00
|
|
|
*
|
2018-02-04 07:18:59 -05:00
|
|
|
* 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.
|
2011-11-13 08:55:20 -05:00
|
|
|
*
|
2018-02-04 07:18:59 -05:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2011-11-13 08:55:20 -05:00
|
|
|
*/
|
|
|
|
|
2012-01-11 12:12:41 -05:00
|
|
|
#ifndef KEEPASSX_DATABASETABWIDGET_H
|
|
|
|
#define KEEPASSX_DATABASETABWIDGET_H
|
2011-11-13 08:55:20 -05:00
|
|
|
|
2018-03-31 16:01:30 -04:00
|
|
|
#include <QFileInfo>
|
2013-10-03 09:18:16 -04:00
|
|
|
#include <QHash>
|
|
|
|
#include <QTabWidget>
|
2011-11-13 08:55:20 -05:00
|
|
|
|
2012-04-24 19:32:05 -04:00
|
|
|
#include "gui/DatabaseWidget.h"
|
2015-01-21 11:19:05 -05:00
|
|
|
#include "gui/MessageWidget.h"
|
2011-11-13 08:55:20 -05:00
|
|
|
|
2011-12-27 09:49:06 -05:00
|
|
|
class DatabaseWidget;
|
2014-05-17 05:16:27 -04:00
|
|
|
class DatabaseWidgetStateSync;
|
2012-06-28 03:21:15 -04:00
|
|
|
class DatabaseOpenWidget;
|
2011-11-13 08:55:20 -05:00
|
|
|
class QFile;
|
2015-01-21 11:19:05 -05:00
|
|
|
class MessageWidget;
|
2011-11-13 08:55:20 -05:00
|
|
|
|
|
|
|
struct DatabaseManagerStruct
|
|
|
|
{
|
|
|
|
DatabaseManagerStruct();
|
|
|
|
|
2011-12-27 09:49:06 -05:00
|
|
|
DatabaseWidget* dbWidget;
|
2017-11-26 16:58:54 -05:00
|
|
|
QFileInfo fileInfo;
|
2011-11-13 08:55:20 -05:00
|
|
|
bool modified;
|
|
|
|
bool readOnly;
|
2018-01-17 20:13:13 -05:00
|
|
|
int saveAttempts;
|
2011-11-13 08:55:20 -05:00
|
|
|
};
|
|
|
|
|
2012-04-21 12:39:09 -04:00
|
|
|
Q_DECLARE_TYPEINFO(DatabaseManagerStruct, Q_MOVABLE_TYPE);
|
|
|
|
|
2011-12-30 12:43:24 -05:00
|
|
|
class DatabaseTabWidget : public QTabWidget
|
2011-11-13 08:55:20 -05:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2015-07-24 12:28:12 -04:00
|
|
|
explicit DatabaseTabWidget(QWidget* parent = nullptr);
|
2018-02-04 07:18:59 -05:00
|
|
|
~DatabaseTabWidget() override;
|
2018-03-31 16:01:30 -04:00
|
|
|
void openDatabase(const QString& fileName, const QString& pw = QString(), const QString& keyFile = QString());
|
2016-11-07 22:37:42 -05:00
|
|
|
void mergeDatabase(const QString& fileName);
|
2011-12-29 14:03:20 -05:00
|
|
|
DatabaseWidget* currentDatabaseWidget();
|
2014-05-15 16:53:59 -04:00
|
|
|
bool hasLockableDatabases() const;
|
2018-10-19 14:44:08 -04:00
|
|
|
DatabaseManagerStruct indexDatabaseManagerStruct(int index);
|
2011-11-13 08:55:20 -05:00
|
|
|
|
2012-05-27 17:01:14 -04:00
|
|
|
static const int LastDatabasesCount;
|
|
|
|
|
2017-03-10 09:58:42 -05:00
|
|
|
public slots:
|
2011-11-16 12:47:17 -05:00
|
|
|
void newDatabase();
|
2011-11-13 08:55:20 -05:00
|
|
|
void openDatabase();
|
2017-01-08 19:33:21 -05:00
|
|
|
void importCsv();
|
2016-11-07 22:37:42 -05:00
|
|
|
void mergeDatabase();
|
2012-05-12 04:08:41 -04:00
|
|
|
void importKeePass1Database();
|
2015-01-11 10:20:59 -05:00
|
|
|
bool saveDatabase(int index = -1);
|
|
|
|
bool saveDatabaseAs(int index = -1);
|
2015-07-14 16:14:34 -04:00
|
|
|
void exportToCsv();
|
2012-04-11 14:35:52 -04:00
|
|
|
bool closeDatabase(int index = -1);
|
|
|
|
void closeDatabaseFromSender();
|
|
|
|
bool closeAllDatabases();
|
2012-01-13 11:52:37 -05:00
|
|
|
void changeMasterKey();
|
2012-04-19 10:20:20 -04:00
|
|
|
void changeDatabaseSettings();
|
2012-05-28 12:38:33 -04:00
|
|
|
bool readOnly(int index = -1);
|
2017-10-24 13:23:55 -04:00
|
|
|
bool canSave(int index = -1);
|
2017-03-20 22:29:36 -04:00
|
|
|
bool isModified(int index = -1);
|
2012-07-14 13:09:28 -04:00
|
|
|
void performGlobalAutoType();
|
2012-10-12 06:12:00 -04:00
|
|
|
void lockDatabases();
|
2018-02-05 07:25:16 -05:00
|
|
|
void relockPendingDatabase();
|
2017-03-21 22:01:44 -04:00
|
|
|
QString databasePath(int index = -1);
|
2011-11-13 08:55:20 -05:00
|
|
|
|
2017-03-10 09:58:42 -05:00
|
|
|
signals:
|
2012-04-21 16:02:12 -04:00
|
|
|
void tabNameChanged();
|
2013-03-24 18:21:59 -04:00
|
|
|
void databaseWithFileClosed(QString filePath);
|
2014-05-17 05:16:27 -04:00
|
|
|
void activateDatabaseChanged(DatabaseWidget* dbWidget);
|
2016-10-08 12:55:05 -04:00
|
|
|
void databaseLocked(DatabaseWidget* dbWidget);
|
|
|
|
void databaseUnlocked(DatabaseWidget* dbWidget);
|
2015-01-21 11:19:05 -05:00
|
|
|
void messageGlobal(const QString&, MessageWidget::MessageType type);
|
|
|
|
void messageTab(const QString&, MessageWidget::MessageType type);
|
|
|
|
void messageDismissGlobal();
|
|
|
|
void messageDismissTab();
|
2012-01-13 11:52:37 -05:00
|
|
|
|
2017-03-10 09:58:42 -05:00
|
|
|
private slots:
|
2011-11-13 08:55:20 -05:00
|
|
|
void updateTabName(Database* db);
|
2012-10-12 06:12:00 -04:00
|
|
|
void updateTabNameFromDbSender();
|
|
|
|
void updateTabNameFromDbWidgetSender();
|
2012-04-11 14:35:52 -04:00
|
|
|
void modified();
|
2012-04-20 05:29:31 -04:00
|
|
|
void toggleTabbar();
|
2016-11-11 17:58:47 -05:00
|
|
|
void changeDatabase(Database* newDb, bool unsavedChanges);
|
2014-05-17 05:16:27 -04:00
|
|
|
void emitActivateDatabaseChanged();
|
2016-10-08 12:55:05 -04:00
|
|
|
void emitDatabaseUnlockedFromDbWidgetSender();
|
2011-12-29 13:01:58 -05:00
|
|
|
|
2011-11-13 08:55:20 -05:00
|
|
|
private:
|
2018-05-13 17:21:43 -04:00
|
|
|
Database* execNewDatabaseWizard();
|
2017-11-26 16:58:54 -05:00
|
|
|
bool saveDatabase(Database* db, QString filePath = "");
|
2015-01-11 10:20:59 -05:00
|
|
|
bool saveDatabaseAs(Database* db);
|
2012-04-11 14:35:52 -04:00
|
|
|
bool closeDatabase(Database* db);
|
2012-06-29 17:40:51 -04:00
|
|
|
void deleteDatabase(Database* db);
|
2011-11-13 08:55:20 -05:00
|
|
|
int databaseIndex(Database* db);
|
|
|
|
Database* indexDatabase(int index);
|
2012-04-11 14:35:52 -04:00
|
|
|
Database* databaseFromDatabaseWidget(DatabaseWidget* dbWidget);
|
2011-11-16 12:47:17 -05:00
|
|
|
void insertDatabase(Database* db, const DatabaseManagerStruct& dbStruct);
|
2012-05-27 17:01:14 -04:00
|
|
|
void updateLastDatabases(const QString& filename);
|
2015-07-24 12:28:12 -04:00
|
|
|
void connectDatabase(Database* newDb, Database* oldDb = nullptr);
|
2011-11-13 08:55:20 -05:00
|
|
|
|
|
|
|
QHash<Database*, DatabaseManagerStruct> m_dbList;
|
2018-02-04 07:18:59 -05:00
|
|
|
QPointer<DatabaseWidgetStateSync> m_dbWidgetStateSync;
|
2018-02-05 07:25:16 -05:00
|
|
|
QPointer<DatabaseWidget> m_dbPendingLock;
|
2011-11-13 08:55:20 -05:00
|
|
|
};
|
|
|
|
|
2012-01-11 12:12:41 -05:00
|
|
|
#endif // KEEPASSX_DATABASETABWIDGET_H
|