mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-10-01 01:26:01 -04:00
Rename DatabaseManager to DatabaseTabWidget and turn it into a QTabWidget.
This commit is contained in:
parent
752c720226
commit
4cb8cffe3f
@ -46,7 +46,7 @@ set(keepassx_SOURCES
|
||||
format/KeePass2Writer.cpp
|
||||
format/KeePass2XmlReader.cpp
|
||||
format/KeePass2XmlWriter.cpp
|
||||
gui/DatabaseManager.cpp
|
||||
gui/DatabaseTabWidget.cpp
|
||||
gui/DatabaseWidget.cpp
|
||||
gui/EditEntryWidget.cpp
|
||||
gui/EditGroupWidget.cpp
|
||||
@ -72,7 +72,7 @@ set(keepassx_MOC
|
||||
core/Entry.h
|
||||
core/Group.h
|
||||
core/Metadata.h
|
||||
gui/DatabaseManager.h
|
||||
gui/DatabaseTabWidget.h
|
||||
gui/DatabaseWidget.h
|
||||
gui/EditEntryWidget.h
|
||||
gui/EditGroupWidget.h
|
||||
|
@ -15,7 +15,7 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "DatabaseManager.h"
|
||||
#include "DatabaseTabWidget.h"
|
||||
|
||||
#include <QtCore/QFileInfo>
|
||||
#include <QtGui/QTabWidget>
|
||||
@ -37,24 +37,24 @@ DatabaseManagerStruct::DatabaseManagerStruct()
|
||||
{
|
||||
}
|
||||
|
||||
DatabaseManager::DatabaseManager(QTabWidget* tabWidget)
|
||||
: m_tabWidget(tabWidget)
|
||||
, m_window(tabWidget->window())
|
||||
DatabaseTabWidget::DatabaseTabWidget(QWidget* parent)
|
||||
: QTabWidget(parent)
|
||||
, m_window(parent->window())
|
||||
{
|
||||
connect(m_tabWidget, SIGNAL(tabCloseRequested(int)), SLOT(closeDatabase(int)));
|
||||
connect(m_tabWidget, SIGNAL(currentChanged(int)), SLOT(emitEntrySelectionChanged()));
|
||||
connect(this, SIGNAL(tabCloseRequested(int)), SLOT(closeDatabase(int)));
|
||||
connect(this, SIGNAL(currentChanged(int)), SLOT(emitEntrySelectionChanged()));
|
||||
}
|
||||
|
||||
void DatabaseManager::newDatabase()
|
||||
void DatabaseTabWidget::newDatabase()
|
||||
{
|
||||
DatabaseManagerStruct dbStruct;
|
||||
Database* db = new Database();
|
||||
dbStruct.dbWidget = new DatabaseWidget(db, m_tabWidget);
|
||||
dbStruct.dbWidget = new DatabaseWidget(db, this);
|
||||
|
||||
insertDatabase(db, dbStruct);
|
||||
}
|
||||
|
||||
void DatabaseManager::openDatabase()
|
||||
void DatabaseTabWidget::openDatabase()
|
||||
{
|
||||
QString fileName = fileDialog()->getOpenFileName(m_window, tr("Open database"), QString(),
|
||||
tr("KeePass 2 Database").append(" (*.kdbx)"));
|
||||
@ -63,7 +63,7 @@ void DatabaseManager::openDatabase()
|
||||
}
|
||||
}
|
||||
|
||||
void DatabaseManager::openDatabase(const QString& fileName)
|
||||
void DatabaseTabWidget::openDatabase(const QString& fileName)
|
||||
{
|
||||
QScopedPointer<QFile> file(new QFile(fileName));
|
||||
// TODO error handling
|
||||
@ -84,7 +84,7 @@ void DatabaseManager::openDatabase(const QString& fileName)
|
||||
openDatabaseDialog();
|
||||
}
|
||||
|
||||
void DatabaseManager::openDatabaseDialog()
|
||||
void DatabaseTabWidget::openDatabaseDialog()
|
||||
{
|
||||
m_curKeyDialog = new KeyOpenDialog(m_curDbStruct.fileName, m_window);
|
||||
connect(m_curKeyDialog, SIGNAL(accepted()), SLOT(openDatabaseRead()));
|
||||
@ -93,7 +93,7 @@ void DatabaseManager::openDatabaseDialog()
|
||||
m_curKeyDialog->show();
|
||||
}
|
||||
|
||||
void DatabaseManager::openDatabaseRead()
|
||||
void DatabaseTabWidget::openDatabaseRead()
|
||||
{
|
||||
m_curDbStruct.file->reset();
|
||||
Database* db = m_reader.readDatabase(m_curDbStruct.file, m_curKeyDialog->key());
|
||||
@ -104,13 +104,13 @@ void DatabaseManager::openDatabaseRead()
|
||||
openDatabaseDialog();
|
||||
}
|
||||
else {
|
||||
m_curDbStruct.dbWidget = new DatabaseWidget(db, m_tabWidget);
|
||||
m_curDbStruct.dbWidget = new DatabaseWidget(db, this);
|
||||
insertDatabase(db, m_curDbStruct);
|
||||
m_curDbStruct = DatabaseManagerStruct();
|
||||
}
|
||||
}
|
||||
|
||||
void DatabaseManager::openDatabaseCleanup()
|
||||
void DatabaseTabWidget::openDatabaseCleanup()
|
||||
{
|
||||
delete m_curKeyDialog;
|
||||
m_curKeyDialog = 0;
|
||||
@ -121,7 +121,7 @@ void DatabaseManager::openDatabaseCleanup()
|
||||
m_curDbStruct = DatabaseManagerStruct();
|
||||
}
|
||||
|
||||
void DatabaseManager::emitEntrySelectionChanged()
|
||||
void DatabaseTabWidget::emitEntrySelectionChanged()
|
||||
{
|
||||
DatabaseWidget* dbWidget = currentDatabaseWidget();
|
||||
|
||||
@ -133,7 +133,7 @@ void DatabaseManager::emitEntrySelectionChanged()
|
||||
Q_EMIT entrySelectionChanged(isSingleEntrySelected);
|
||||
}
|
||||
|
||||
void DatabaseManager::closeDatabase(Database* db)
|
||||
void DatabaseTabWidget::closeDatabase(Database* db)
|
||||
{
|
||||
Q_ASSERT(db);
|
||||
|
||||
@ -146,12 +146,12 @@ void DatabaseManager::closeDatabase(Database* db)
|
||||
int index = databaseIndex(db);
|
||||
Q_ASSERT(index != -1);
|
||||
|
||||
m_tabWidget->removeTab(index);
|
||||
removeTab(index);
|
||||
delete dbStruct.dbWidget;
|
||||
delete db;
|
||||
}
|
||||
|
||||
void DatabaseManager::saveDatabase(Database* db)
|
||||
void DatabaseTabWidget::saveDatabase(Database* db)
|
||||
{
|
||||
DatabaseManagerStruct& dbStruct = m_dbList[db];
|
||||
|
||||
@ -170,7 +170,7 @@ void DatabaseManager::saveDatabase(Database* db)
|
||||
}
|
||||
}
|
||||
|
||||
void DatabaseManager::saveDatabaseAs(Database* db)
|
||||
void DatabaseTabWidget::saveDatabaseAs(Database* db)
|
||||
{
|
||||
DatabaseManagerStruct& dbStruct = m_dbList[db];
|
||||
QString oldFileName;
|
||||
@ -197,53 +197,53 @@ void DatabaseManager::saveDatabaseAs(Database* db)
|
||||
}
|
||||
}
|
||||
|
||||
void DatabaseManager::closeDatabase(int index)
|
||||
void DatabaseTabWidget::closeDatabase(int index)
|
||||
{
|
||||
if (index == -1) {
|
||||
index = m_tabWidget->currentIndex();
|
||||
index = currentIndex();
|
||||
}
|
||||
|
||||
closeDatabase(indexDatabase(index));
|
||||
}
|
||||
|
||||
void DatabaseManager::saveDatabase(int index)
|
||||
void DatabaseTabWidget::saveDatabase(int index)
|
||||
{
|
||||
if (index == -1) {
|
||||
index = m_tabWidget->currentIndex();
|
||||
index = currentIndex();
|
||||
}
|
||||
|
||||
saveDatabase(indexDatabase(index));
|
||||
}
|
||||
|
||||
void DatabaseManager::saveDatabaseAs(int index)
|
||||
void DatabaseTabWidget::saveDatabaseAs(int index)
|
||||
{
|
||||
if (index == -1) {
|
||||
index = m_tabWidget->currentIndex();
|
||||
index = currentIndex();
|
||||
}
|
||||
saveDatabaseAs(indexDatabase(index));
|
||||
}
|
||||
|
||||
void DatabaseManager::createEntry()
|
||||
void DatabaseTabWidget::createEntry()
|
||||
{
|
||||
currentDatabaseWidget()->createEntry();
|
||||
}
|
||||
|
||||
void DatabaseManager::editEntry()
|
||||
void DatabaseTabWidget::editEntry()
|
||||
{
|
||||
currentDatabaseWidget()->switchToEntryEdit();
|
||||
}
|
||||
|
||||
void DatabaseManager::createGroup()
|
||||
void DatabaseTabWidget::createGroup()
|
||||
{
|
||||
currentDatabaseWidget()->createGroup();
|
||||
}
|
||||
|
||||
void DatabaseManager::editGroup()
|
||||
void DatabaseTabWidget::editGroup()
|
||||
{
|
||||
currentDatabaseWidget()->switchToGroupEdit();
|
||||
}
|
||||
|
||||
void DatabaseManager::updateTabName(Database* db)
|
||||
void DatabaseTabWidget::updateTabName(Database* db)
|
||||
{
|
||||
int index = databaseIndex(db);
|
||||
Q_ASSERT(index != -1);
|
||||
@ -262,7 +262,7 @@ void DatabaseManager::updateTabName(Database* db)
|
||||
tabName = db->metadata()->name();
|
||||
}
|
||||
|
||||
m_tabWidget->setTabToolTip(index, dbStruct.fileName);
|
||||
setTabToolTip(index, dbStruct.fileName);
|
||||
}
|
||||
else {
|
||||
if (db->metadata()->name().isEmpty()) {
|
||||
@ -273,18 +273,18 @@ void DatabaseManager::updateTabName(Database* db)
|
||||
}
|
||||
}
|
||||
|
||||
m_tabWidget->setTabText(index, tabName);
|
||||
setTabText(index, tabName);
|
||||
}
|
||||
|
||||
int DatabaseManager::databaseIndex(Database* db)
|
||||
int DatabaseTabWidget::databaseIndex(Database* db)
|
||||
{
|
||||
QWidget* dbWidget = m_dbList.value(db).dbWidget;
|
||||
return m_tabWidget->indexOf(dbWidget);
|
||||
return indexOf(dbWidget);
|
||||
}
|
||||
|
||||
Database* DatabaseManager::indexDatabase(int index)
|
||||
Database* DatabaseTabWidget::indexDatabase(int index)
|
||||
{
|
||||
QWidget* dbWidget = m_tabWidget->widget(index);
|
||||
QWidget* dbWidget = widget(index);
|
||||
|
||||
QHashIterator<Database*, DatabaseManagerStruct> i(m_dbList);
|
||||
while (i.hasNext()) {
|
||||
@ -297,22 +297,22 @@ Database* DatabaseManager::indexDatabase(int index)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void DatabaseManager::insertDatabase(Database* db, const DatabaseManagerStruct& dbStruct)
|
||||
void DatabaseTabWidget::insertDatabase(Database* db, const DatabaseManagerStruct& dbStruct)
|
||||
{
|
||||
m_dbList.insert(db, dbStruct);
|
||||
|
||||
m_tabWidget->addTab(dbStruct.dbWidget, "");
|
||||
addTab(dbStruct.dbWidget, "");
|
||||
updateTabName(db);
|
||||
int index = databaseIndex(db);
|
||||
m_tabWidget->setCurrentIndex(index);
|
||||
setCurrentIndex(index);
|
||||
|
||||
connect(db->metadata(), SIGNAL(nameTextChanged(Database*)), SLOT(updateTabName(Database*)));
|
||||
connect(dbStruct.dbWidget->entryView(), SIGNAL(entrySelectionChanged()), SLOT(emitEntrySelectionChanged()));
|
||||
}
|
||||
|
||||
DatabaseWidget* DatabaseManager::currentDatabaseWidget()
|
||||
DatabaseWidget* DatabaseTabWidget::currentDatabaseWidget()
|
||||
{
|
||||
Database* db = indexDatabase(m_tabWidget->currentIndex());
|
||||
Database* db = indexDatabase(currentIndex());
|
||||
if (db) {
|
||||
return m_dbList[db].dbWidget;
|
||||
}
|
@ -20,6 +20,7 @@
|
||||
|
||||
#include <QtCore/QHash>
|
||||
#include <QtCore/QObject>
|
||||
#include <QtGui/QTabWidget>
|
||||
|
||||
#include "format/KeePass2Reader.h"
|
||||
#include "format/KeePass2Writer.h"
|
||||
@ -40,12 +41,12 @@ struct DatabaseManagerStruct
|
||||
bool readOnly;
|
||||
};
|
||||
|
||||
class DatabaseManager : public QObject
|
||||
class DatabaseTabWidget : public QTabWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
DatabaseManager(QTabWidget* tabWidget);
|
||||
DatabaseTabWidget(QWidget* parent);
|
||||
void openDatabase(const QString& fileName);
|
||||
void saveDatabase(Database* db);
|
||||
void saveDatabaseAs(Database* db);
|
||||
@ -78,7 +79,6 @@ private:
|
||||
Database* indexDatabase(int index);
|
||||
void insertDatabase(Database* db, const DatabaseManagerStruct& dbStruct);
|
||||
|
||||
QTabWidget* m_tabWidget;
|
||||
QWidget* m_window;
|
||||
KeePass2Reader m_reader;
|
||||
KeePass2Writer m_writer;
|
@ -20,7 +20,6 @@
|
||||
|
||||
#include "core/Database.h"
|
||||
#include "core/Metadata.h"
|
||||
#include "gui/DatabaseManager.h"
|
||||
#include "gui/DatabaseWidget.h"
|
||||
|
||||
MainWindow::MainWindow()
|
||||
@ -28,21 +27,19 @@ MainWindow::MainWindow()
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
|
||||
m_dbManager = new DatabaseManager(m_ui->tabWidget);
|
||||
|
||||
connect(m_ui->tabWidget, SIGNAL(currentChanged(int)), SLOT(currentTabChanged(int)));
|
||||
connect(m_dbManager, SIGNAL(entrySelectionChanged(bool)), m_ui->actionEntryEdit, SLOT(setEnabled(bool)));
|
||||
connect(m_dbManager, SIGNAL(entrySelectionChanged(bool)), m_ui->actionEntryDelete, SLOT(setEnabled(bool)));
|
||||
connect(m_ui->tabWidget, SIGNAL(entrySelectionChanged(bool)), m_ui->actionEntryEdit, SLOT(setEnabled(bool)));
|
||||
connect(m_ui->tabWidget, SIGNAL(entrySelectionChanged(bool)), m_ui->actionEntryDelete, SLOT(setEnabled(bool)));
|
||||
|
||||
connect(m_ui->actionDatabaseNew, SIGNAL(triggered()), m_dbManager, SLOT(newDatabase()));
|
||||
connect(m_ui->actionDatabaseOpen, SIGNAL(triggered()), m_dbManager, SLOT(openDatabase()));
|
||||
connect(m_ui->actionDatabaseSave, SIGNAL(triggered()), m_dbManager, SLOT(saveDatabase()));
|
||||
connect(m_ui->actionDatabaseSaveAs, SIGNAL(triggered()), m_dbManager, SLOT(saveDatabaseAs()));
|
||||
connect(m_ui->actionDatabaseClose, SIGNAL(triggered()), m_dbManager, SLOT(closeDatabase()));
|
||||
connect(m_ui->actionEntryNew, SIGNAL(triggered()), m_dbManager, SLOT(createEntry()));
|
||||
connect(m_ui->actionEntryEdit, SIGNAL(triggered()), m_dbManager, SLOT(editEntry()));
|
||||
connect(m_ui->actionGroupNew, SIGNAL(triggered()), m_dbManager, SLOT(createGroup()));
|
||||
connect(m_ui->actionGroupEdit, SIGNAL(triggered()), m_dbManager, SLOT(editGroup()));
|
||||
connect(m_ui->actionDatabaseNew, SIGNAL(triggered()), m_ui->tabWidget, SLOT(newDatabase()));
|
||||
connect(m_ui->actionDatabaseOpen, SIGNAL(triggered()), m_ui->tabWidget, SLOT(openDatabase()));
|
||||
connect(m_ui->actionDatabaseSave, SIGNAL(triggered()), m_ui->tabWidget, SLOT(saveDatabase()));
|
||||
connect(m_ui->actionDatabaseSaveAs, SIGNAL(triggered()), m_ui->tabWidget, SLOT(saveDatabaseAs()));
|
||||
connect(m_ui->actionDatabaseClose, SIGNAL(triggered()), m_ui->tabWidget, SLOT(closeDatabase()));
|
||||
connect(m_ui->actionEntryNew, SIGNAL(triggered()), m_ui->tabWidget, SLOT(createEntry()));
|
||||
connect(m_ui->actionEntryEdit, SIGNAL(triggered()), m_ui->tabWidget, SLOT(editEntry()));
|
||||
connect(m_ui->actionGroupNew, SIGNAL(triggered()), m_ui->tabWidget, SLOT(createGroup()));
|
||||
connect(m_ui->actionGroupEdit, SIGNAL(triggered()), m_ui->tabWidget, SLOT(editGroup()));
|
||||
connect(m_ui->actionQuit, SIGNAL(triggered()), SLOT(close()));
|
||||
}
|
||||
|
||||
|
@ -20,8 +20,6 @@
|
||||
|
||||
#include <QtGui/QMainWindow>
|
||||
|
||||
class Database;
|
||||
class DatabaseManager;
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
}
|
||||
@ -39,7 +37,6 @@ private Q_SLOTS:
|
||||
|
||||
private:
|
||||
QScopedPointer<Ui::MainWindow> m_ui;
|
||||
DatabaseManager* m_dbManager;
|
||||
|
||||
Q_DISABLE_COPY(MainWindow)
|
||||
};
|
||||
|
@ -16,7 +16,7 @@
|
||||
<widget class="QWidget" name="centralwidget">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QTabWidget" name="tabWidget">
|
||||
<widget class="DatabaseTabWidget" name="tabWidget">
|
||||
<property name="currentIndex">
|
||||
<number>-1</number>
|
||||
</property>
|
||||
@ -36,7 +36,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>21</height>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuFile">
|
||||
@ -188,6 +188,14 @@
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>DatabaseTabWidget</class>
|
||||
<extends>QTabWidget</extends>
|
||||
<header>gui/DatabaseTabWidget.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
Loading…
Reference in New Issue
Block a user