2011-11-13 08:55:20 -05:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2011 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/>.
|
|
|
|
*/
|
|
|
|
|
2012-01-11 12:12:41 -05:00
|
|
|
#ifndef KEEPASSX_DATABASETABWIDGET_H
|
|
|
|
#define KEEPASSX_DATABASETABWIDGET_H
|
2011-11-13 08:55:20 -05:00
|
|
|
|
2013-10-03 09:18:16 -04:00
|
|
|
#include <QHash>
|
|
|
|
#include <QTabWidget>
|
2011-11-13 08:55:20 -05:00
|
|
|
|
|
|
|
#include "format/KeePass2Writer.h"
|
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-07-22 11:01:12 -04:00
|
|
|
class QLockFile;
|
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;
|
2015-05-10 16:46:04 -04:00
|
|
|
QLockFile* lockFile;
|
2012-07-08 04:15:05 -04:00
|
|
|
QString filePath;
|
|
|
|
QString canonicalFilePath;
|
2011-12-26 13:17:11 -05:00
|
|
|
QString fileName;
|
2012-07-06 12:50:52 -04:00
|
|
|
bool saveToFilename;
|
2011-11-13 08:55:20 -05:00
|
|
|
bool modified;
|
|
|
|
bool readOnly;
|
|
|
|
};
|
|
|
|
|
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);
|
2012-06-29 17:40:51 -04:00
|
|
|
~DatabaseTabWidget();
|
2012-04-24 05:47:16 -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;
|
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();
|
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);
|
2012-07-14 13:09:28 -04:00
|
|
|
void performGlobalAutoType();
|
2012-10-12 06:12:00 -04:00
|
|
|
void lockDatabases();
|
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:
|
2015-01-11 10:20:59 -05:00
|
|
|
bool saveDatabase(Database* db);
|
|
|
|
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-05-28 12:38:33 -04:00
|
|
|
DatabaseManagerStruct indexDatabaseManagerStruct(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
|
|
|
|
|
|
|
KeePass2Writer m_writer;
|
|
|
|
QHash<Database*, DatabaseManagerStruct> m_dbList;
|
2014-05-17 05:16:27 -04:00
|
|
|
DatabaseWidgetStateSync* m_dbWidgetSateSync;
|
2011-11-13 08:55:20 -05:00
|
|
|
};
|
|
|
|
|
2012-01-11 12:12:41 -05:00
|
|
|
#endif // KEEPASSX_DATABASETABWIDGET_H
|