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/>.
|
|
|
|
*/
|
|
|
|
|
2011-12-30 12:43:24 -05:00
|
|
|
#include "DatabaseTabWidget.h"
|
2011-11-13 08:55:20 -05:00
|
|
|
|
|
|
|
#include <QtCore/QFileInfo>
|
|
|
|
#include <QtGui/QTabWidget>
|
2012-04-11 14:35:52 -04:00
|
|
|
#include <QtGui/QMessageBox>
|
2011-11-13 08:55:20 -05:00
|
|
|
|
|
|
|
#include "core/Database.h"
|
|
|
|
#include "core/Metadata.h"
|
|
|
|
#include "gui/DatabaseWidget.h"
|
2011-12-25 19:21:29 -05:00
|
|
|
#include "gui/FileDialog.h"
|
2011-12-29 13:01:58 -05:00
|
|
|
#include "gui/EntryView.h"
|
2011-12-27 09:49:06 -05:00
|
|
|
#include "gui/GroupView.h"
|
2012-04-05 12:31:12 -04:00
|
|
|
#include "gui/DatabaseOpenDialog.h"
|
2011-11-13 08:55:20 -05:00
|
|
|
|
|
|
|
DatabaseManagerStruct::DatabaseManagerStruct()
|
|
|
|
: file(0)
|
|
|
|
, dbWidget(0)
|
|
|
|
, modified(false)
|
|
|
|
, readOnly(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-12-30 12:43:24 -05:00
|
|
|
DatabaseTabWidget::DatabaseTabWidget(QWidget* parent)
|
|
|
|
: QTabWidget(parent)
|
|
|
|
, m_window(parent->window())
|
2011-11-13 08:55:20 -05:00
|
|
|
{
|
2011-12-30 12:43:24 -05:00
|
|
|
connect(this, SIGNAL(tabCloseRequested(int)), SLOT(closeDatabase(int)));
|
|
|
|
connect(this, SIGNAL(currentChanged(int)), SLOT(emitEntrySelectionChanged()));
|
2011-11-13 08:55:20 -05:00
|
|
|
}
|
|
|
|
|
2012-04-20 05:29:31 -04:00
|
|
|
void DatabaseTabWidget::toggleTabbar() {
|
|
|
|
if (count() > 1) {
|
|
|
|
if (!tabBar()->isVisible()) {
|
|
|
|
tabBar()->show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (tabBar()->isVisible()) {
|
|
|
|
tabBar()->hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-30 12:43:24 -05:00
|
|
|
void DatabaseTabWidget::newDatabase()
|
2011-11-16 12:47:17 -05:00
|
|
|
{
|
|
|
|
DatabaseManagerStruct dbStruct;
|
|
|
|
Database* db = new Database();
|
2011-12-30 12:43:24 -05:00
|
|
|
dbStruct.dbWidget = new DatabaseWidget(db, this);
|
2011-11-16 12:47:17 -05:00
|
|
|
|
|
|
|
insertDatabase(db, dbStruct);
|
2012-04-11 14:35:52 -04:00
|
|
|
|
|
|
|
dbStruct.dbWidget->switchToMasterKeyChange();
|
2011-11-16 12:47:17 -05:00
|
|
|
}
|
|
|
|
|
2011-12-30 12:43:24 -05:00
|
|
|
void DatabaseTabWidget::openDatabase()
|
2011-11-13 08:55:20 -05:00
|
|
|
{
|
2011-12-25 19:21:29 -05:00
|
|
|
QString fileName = fileDialog()->getOpenFileName(m_window, tr("Open database"), QString(),
|
|
|
|
tr("KeePass 2 Database").append(" (*.kdbx)"));
|
2011-11-13 08:55:20 -05:00
|
|
|
if (!fileName.isEmpty()) {
|
|
|
|
openDatabase(fileName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-30 12:43:24 -05:00
|
|
|
void DatabaseTabWidget::openDatabase(const QString& fileName)
|
2011-11-13 08:55:20 -05:00
|
|
|
{
|
|
|
|
QScopedPointer<QFile> file(new QFile(fileName));
|
2011-12-24 13:22:42 -05:00
|
|
|
// TODO error handling
|
2011-11-13 08:55:20 -05:00
|
|
|
if (!file->open(QIODevice::ReadWrite)) {
|
|
|
|
if (!file->open(QIODevice::ReadOnly)) {
|
|
|
|
// can only open read-only
|
2011-12-26 13:17:11 -05:00
|
|
|
m_curDbStruct.readOnly = true;
|
2011-11-13 08:55:20 -05:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// can't open
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-26 13:17:11 -05:00
|
|
|
m_curDbStruct.file = file.take();
|
|
|
|
m_curDbStruct.fileName = QFileInfo(fileName).absoluteFilePath();
|
2011-11-13 08:55:20 -05:00
|
|
|
|
2011-12-26 13:17:11 -05:00
|
|
|
openDatabaseDialog();
|
|
|
|
}
|
2011-11-13 08:55:20 -05:00
|
|
|
|
2011-12-30 12:43:24 -05:00
|
|
|
void DatabaseTabWidget::openDatabaseDialog()
|
2011-12-26 13:17:11 -05:00
|
|
|
{
|
2012-04-05 13:03:55 -04:00
|
|
|
m_curKeyDialog = new DatabaseOpenDialog(m_curDbStruct.file, m_curDbStruct.fileName, m_window);
|
2011-12-26 13:17:11 -05:00
|
|
|
connect(m_curKeyDialog, SIGNAL(accepted()), SLOT(openDatabaseRead()));
|
|
|
|
connect(m_curKeyDialog, SIGNAL(rejected()), SLOT(openDatabaseCleanup()));
|
|
|
|
m_curKeyDialog->setModal(true);
|
|
|
|
m_curKeyDialog->show();
|
|
|
|
}
|
2011-11-13 08:55:20 -05:00
|
|
|
|
2011-12-30 12:43:24 -05:00
|
|
|
void DatabaseTabWidget::openDatabaseRead()
|
2011-12-26 13:17:11 -05:00
|
|
|
{
|
2012-04-05 13:03:55 -04:00
|
|
|
Database* db = m_curKeyDialog->database();
|
|
|
|
|
2011-12-26 13:17:11 -05:00
|
|
|
delete m_curKeyDialog;
|
|
|
|
m_curKeyDialog = 0;
|
2011-11-13 08:55:20 -05:00
|
|
|
|
2012-04-05 13:03:55 -04:00
|
|
|
m_curDbStruct.dbWidget = new DatabaseWidget(db, this);
|
|
|
|
insertDatabase(db, m_curDbStruct);
|
|
|
|
m_curDbStruct = DatabaseManagerStruct();
|
2011-12-26 13:17:11 -05:00
|
|
|
}
|
|
|
|
|
2011-12-30 12:43:24 -05:00
|
|
|
void DatabaseTabWidget::openDatabaseCleanup()
|
2011-12-26 13:17:11 -05:00
|
|
|
{
|
|
|
|
delete m_curKeyDialog;
|
|
|
|
m_curKeyDialog = 0;
|
|
|
|
|
|
|
|
if (m_curDbStruct.file) {
|
|
|
|
delete m_curDbStruct.file;
|
|
|
|
}
|
|
|
|
m_curDbStruct = DatabaseManagerStruct();
|
2011-11-13 08:55:20 -05:00
|
|
|
}
|
|
|
|
|
2011-12-30 12:43:24 -05:00
|
|
|
void DatabaseTabWidget::emitEntrySelectionChanged()
|
2011-12-29 13:01:58 -05:00
|
|
|
{
|
2011-12-29 14:03:20 -05:00
|
|
|
DatabaseWidget* dbWidget = currentDatabaseWidget();
|
2011-12-29 13:01:58 -05:00
|
|
|
|
|
|
|
bool isSingleEntrySelected = false;
|
2011-12-29 14:03:20 -05:00
|
|
|
if (dbWidget) {
|
|
|
|
isSingleEntrySelected = dbWidget->entryView()->isSingleEntrySelected();
|
2011-12-29 13:01:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
Q_EMIT entrySelectionChanged(isSingleEntrySelected);
|
|
|
|
}
|
|
|
|
|
2012-04-11 14:35:52 -04:00
|
|
|
bool DatabaseTabWidget::closeDatabase(Database* db)
|
2011-11-13 08:55:20 -05:00
|
|
|
{
|
|
|
|
Q_ASSERT(db);
|
|
|
|
|
|
|
|
const DatabaseManagerStruct& dbStruct = m_dbList.value(db);
|
|
|
|
int index = databaseIndex(db);
|
|
|
|
Q_ASSERT(index != -1);
|
2012-04-21 14:36:26 -04:00
|
|
|
|
|
|
|
QString dbName = tabText(index);
|
|
|
|
if (dbName.right(1) == "*") {
|
|
|
|
dbName.chop(1);
|
|
|
|
}
|
|
|
|
if (dbStruct.dbWidget->currentIndex() != 0) {
|
|
|
|
QMessageBox::StandardButton result =
|
|
|
|
QMessageBox::question(
|
|
|
|
this, tr("Close?"),
|
|
|
|
tr("\"%1\" is in edit mode.\nClose anyway?").arg(dbName),
|
|
|
|
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
|
|
|
|
if (result == QMessageBox::No) {
|
|
|
|
return false;
|
2012-04-11 12:40:52 -04:00
|
|
|
}
|
2012-04-21 14:36:26 -04:00
|
|
|
}
|
|
|
|
if (dbStruct.modified) {
|
2012-04-11 14:35:52 -04:00
|
|
|
QMessageBox::StandardButton result =
|
|
|
|
QMessageBox::question(
|
|
|
|
this, tr("Save changes?"),
|
2012-04-11 12:40:52 -04:00
|
|
|
tr("\"%1\" was modified.\nSave changes?").arg(dbName),
|
2012-04-11 14:35:52 -04:00
|
|
|
QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, QMessageBox::Yes);
|
|
|
|
if (result == QMessageBox::Yes) {
|
|
|
|
saveDatabase(db);
|
|
|
|
}
|
|
|
|
else if (result == QMessageBox::Cancel) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2011-11-13 08:55:20 -05:00
|
|
|
|
2011-12-30 12:43:24 -05:00
|
|
|
removeTab(index);
|
2012-04-20 05:29:31 -04:00
|
|
|
toggleTabbar();
|
2012-04-11 14:35:52 -04:00
|
|
|
m_dbList.remove(db);
|
|
|
|
delete dbStruct.file;
|
2011-11-13 08:55:20 -05:00
|
|
|
delete dbStruct.dbWidget;
|
|
|
|
delete db;
|
2012-04-11 14:35:52 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DatabaseTabWidget::closeAllDatabases() {
|
|
|
|
while (!m_dbList.isEmpty()) {
|
|
|
|
if (!closeDatabase()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
2011-11-13 08:55:20 -05:00
|
|
|
}
|
|
|
|
|
2011-12-30 12:43:24 -05:00
|
|
|
void DatabaseTabWidget::saveDatabase(Database* db)
|
2011-11-16 12:47:17 -05:00
|
|
|
{
|
|
|
|
DatabaseManagerStruct& dbStruct = m_dbList[db];
|
|
|
|
|
|
|
|
// TODO ensure that the data is actually written to disk
|
2011-12-24 13:22:42 -05:00
|
|
|
if (dbStruct.file) {
|
|
|
|
dbStruct.file->reset();
|
|
|
|
m_writer.writeDatabase(dbStruct.file, db);
|
|
|
|
dbStruct.file->resize(dbStruct.file->pos());
|
|
|
|
dbStruct.file->flush();
|
2011-11-16 12:47:17 -05:00
|
|
|
|
2011-12-24 13:22:42 -05:00
|
|
|
dbStruct.modified = false;
|
|
|
|
updateTabName(db);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
saveDatabaseAs(db);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-30 12:43:24 -05:00
|
|
|
void DatabaseTabWidget::saveDatabaseAs(Database* db)
|
2011-12-24 13:22:42 -05:00
|
|
|
{
|
2011-12-26 14:08:26 -05:00
|
|
|
DatabaseManagerStruct& dbStruct = m_dbList[db];
|
2011-12-28 13:05:31 -05:00
|
|
|
QString oldFileName;
|
|
|
|
if (dbStruct.file) {
|
2011-12-26 14:08:26 -05:00
|
|
|
oldFileName = dbStruct.fileName;
|
2011-12-28 13:05:31 -05:00
|
|
|
}
|
2011-12-25 19:21:29 -05:00
|
|
|
QString fileName = fileDialog()->getSaveFileName(m_window, tr("Save database as"),
|
2011-12-26 14:08:26 -05:00
|
|
|
oldFileName, tr("KeePass 2 Database").append(" (*.kdbx)"));
|
2011-12-24 13:22:42 -05:00
|
|
|
if (!fileName.isEmpty()) {
|
2012-04-11 14:34:08 -04:00
|
|
|
QFile* oldFile = dbStruct.file;
|
2011-12-24 13:22:42 -05:00
|
|
|
QScopedPointer<QFile> file(new QFile(fileName));
|
|
|
|
// TODO error handling
|
|
|
|
if (!file->open(QIODevice::ReadWrite)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
dbStruct.file = file.take();
|
|
|
|
// TODO ensure that the data is actually written to disk
|
|
|
|
m_writer.writeDatabase(dbStruct.file, db);
|
|
|
|
dbStruct.file->flush();
|
2012-04-11 14:34:08 -04:00
|
|
|
delete oldFile;
|
2011-12-24 13:22:42 -05:00
|
|
|
|
|
|
|
dbStruct.modified = false;
|
2011-12-26 13:17:11 -05:00
|
|
|
dbStruct.fileName = QFileInfo(fileName).absoluteFilePath();
|
2011-12-24 13:22:42 -05:00
|
|
|
updateTabName(db);
|
|
|
|
}
|
2011-11-16 12:47:17 -05:00
|
|
|
}
|
|
|
|
|
2012-04-11 14:35:52 -04:00
|
|
|
bool DatabaseTabWidget::closeDatabase(int index)
|
2011-11-13 08:55:20 -05:00
|
|
|
{
|
2011-11-16 12:47:17 -05:00
|
|
|
if (index == -1) {
|
2011-12-30 12:43:24 -05:00
|
|
|
index = currentIndex();
|
2011-11-16 12:47:17 -05:00
|
|
|
}
|
|
|
|
|
2012-04-11 14:35:52 -04:00
|
|
|
return closeDatabase(indexDatabase(index));
|
|
|
|
}
|
|
|
|
|
|
|
|
void DatabaseTabWidget::closeDatabaseFromSender()
|
|
|
|
{
|
|
|
|
Q_ASSERT(sender());
|
|
|
|
DatabaseWidget* dbWidget = static_cast<DatabaseWidget*>(sender());
|
|
|
|
Database* db = databaseFromDatabaseWidget(dbWidget);
|
|
|
|
closeDatabase(db);
|
2011-11-13 08:55:20 -05:00
|
|
|
}
|
|
|
|
|
2011-12-30 12:43:24 -05:00
|
|
|
void DatabaseTabWidget::saveDatabase(int index)
|
2011-11-16 12:47:17 -05:00
|
|
|
{
|
|
|
|
if (index == -1) {
|
2011-12-30 12:43:24 -05:00
|
|
|
index = currentIndex();
|
2011-11-16 12:47:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
saveDatabase(indexDatabase(index));
|
|
|
|
}
|
|
|
|
|
2011-12-30 12:43:24 -05:00
|
|
|
void DatabaseTabWidget::saveDatabaseAs(int index)
|
2011-12-24 13:22:42 -05:00
|
|
|
{
|
|
|
|
if (index == -1) {
|
2011-12-30 12:43:24 -05:00
|
|
|
index = currentIndex();
|
2011-12-24 13:22:42 -05:00
|
|
|
}
|
|
|
|
saveDatabaseAs(indexDatabase(index));
|
|
|
|
}
|
|
|
|
|
2012-01-13 11:52:37 -05:00
|
|
|
void DatabaseTabWidget::changeMasterKey()
|
|
|
|
{
|
|
|
|
currentDatabaseWidget()->switchToMasterKeyChange();
|
|
|
|
}
|
|
|
|
|
2012-04-19 10:20:20 -04:00
|
|
|
void DatabaseTabWidget::changeDatabaseSettings()
|
|
|
|
{
|
|
|
|
currentDatabaseWidget()->switchToDatabaseSettings();
|
|
|
|
}
|
|
|
|
|
2011-12-30 12:43:24 -05:00
|
|
|
void DatabaseTabWidget::createEntry()
|
2011-12-27 10:04:59 -05:00
|
|
|
{
|
2011-12-29 14:03:20 -05:00
|
|
|
currentDatabaseWidget()->createEntry();
|
2011-12-27 10:04:59 -05:00
|
|
|
}
|
|
|
|
|
2011-12-30 12:43:24 -05:00
|
|
|
void DatabaseTabWidget::editEntry()
|
2011-12-29 13:01:58 -05:00
|
|
|
{
|
2011-12-29 14:03:20 -05:00
|
|
|
currentDatabaseWidget()->switchToEntryEdit();
|
2011-12-29 13:01:58 -05:00
|
|
|
}
|
|
|
|
|
2012-04-18 14:08:54 -04:00
|
|
|
void DatabaseTabWidget::deleteEntry()
|
|
|
|
{
|
|
|
|
currentDatabaseWidget()->deleteEntry();
|
|
|
|
}
|
|
|
|
|
2011-12-30 12:43:24 -05:00
|
|
|
void DatabaseTabWidget::createGroup()
|
2011-12-27 09:49:06 -05:00
|
|
|
{
|
2011-12-29 14:03:20 -05:00
|
|
|
currentDatabaseWidget()->createGroup();
|
2011-12-27 09:49:06 -05:00
|
|
|
}
|
|
|
|
|
2011-12-30 12:43:24 -05:00
|
|
|
void DatabaseTabWidget::editGroup()
|
2011-12-27 09:49:06 -05:00
|
|
|
{
|
2011-12-29 14:03:20 -05:00
|
|
|
currentDatabaseWidget()->switchToGroupEdit();
|
2011-12-27 09:49:06 -05:00
|
|
|
}
|
|
|
|
|
2012-04-21 13:06:28 -04:00
|
|
|
void DatabaseTabWidget::deleteGroup()
|
|
|
|
{
|
|
|
|
currentDatabaseWidget()->deleteGroup();
|
|
|
|
}
|
|
|
|
|
2011-12-30 12:43:24 -05:00
|
|
|
void DatabaseTabWidget::updateTabName(Database* db)
|
2011-11-13 08:55:20 -05:00
|
|
|
{
|
|
|
|
int index = databaseIndex(db);
|
|
|
|
Q_ASSERT(index != -1);
|
|
|
|
|
|
|
|
const DatabaseManagerStruct& dbStruct = m_dbList.value(db);
|
|
|
|
|
|
|
|
QString tabName;
|
2011-11-16 12:47:17 -05:00
|
|
|
|
|
|
|
if (dbStruct.file) {
|
2011-12-25 13:47:41 -05:00
|
|
|
QFileInfo fileInfo(*dbStruct.file);
|
2011-11-16 12:47:17 -05:00
|
|
|
|
|
|
|
if (db->metadata()->name().isEmpty()) {
|
2011-12-25 13:47:41 -05:00
|
|
|
tabName = fileInfo.fileName();
|
2011-11-16 12:47:17 -05:00
|
|
|
}
|
|
|
|
else {
|
2011-12-25 13:47:41 -05:00
|
|
|
tabName = db->metadata()->name();
|
2011-11-16 12:47:17 -05:00
|
|
|
}
|
2011-12-25 13:47:41 -05:00
|
|
|
|
2011-12-30 12:43:24 -05:00
|
|
|
setTabToolTip(index, dbStruct.fileName);
|
2011-11-13 08:55:20 -05:00
|
|
|
}
|
|
|
|
else {
|
2011-11-16 12:47:17 -05:00
|
|
|
if (db->metadata()->name().isEmpty()) {
|
|
|
|
tabName = tr("New database");
|
|
|
|
}
|
|
|
|
else {
|
2011-12-25 13:47:41 -05:00
|
|
|
tabName = QString("%1 [%2]").arg(db->metadata()->name(), tr("New database"));
|
2011-11-16 12:47:17 -05:00
|
|
|
}
|
2011-11-13 08:55:20 -05:00
|
|
|
}
|
2012-04-11 14:35:52 -04:00
|
|
|
if (dbStruct.modified) {
|
|
|
|
tabName.append("*");
|
|
|
|
}
|
2011-12-30 12:43:24 -05:00
|
|
|
setTabText(index, tabName);
|
2011-11-13 08:55:20 -05:00
|
|
|
}
|
|
|
|
|
2011-12-30 12:43:24 -05:00
|
|
|
int DatabaseTabWidget::databaseIndex(Database* db)
|
2011-11-13 08:55:20 -05:00
|
|
|
{
|
|
|
|
QWidget* dbWidget = m_dbList.value(db).dbWidget;
|
2011-12-30 12:43:24 -05:00
|
|
|
return indexOf(dbWidget);
|
2011-11-13 08:55:20 -05:00
|
|
|
}
|
|
|
|
|
2011-12-30 12:43:24 -05:00
|
|
|
Database* DatabaseTabWidget::indexDatabase(int index)
|
2011-11-13 08:55:20 -05:00
|
|
|
{
|
2011-12-30 12:43:24 -05:00
|
|
|
QWidget* dbWidget = widget(index);
|
2011-11-13 08:55:20 -05:00
|
|
|
|
|
|
|
QHashIterator<Database*, DatabaseManagerStruct> i(m_dbList);
|
|
|
|
while (i.hasNext()) {
|
|
|
|
i.next();
|
|
|
|
if (i.value().dbWidget == dbWidget) {
|
|
|
|
return i.key();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2011-11-16 12:47:17 -05:00
|
|
|
|
2012-04-11 14:35:52 -04:00
|
|
|
Database* DatabaseTabWidget::databaseFromDatabaseWidget(DatabaseWidget* dbWidget)
|
|
|
|
{
|
|
|
|
QHashIterator<Database*, DatabaseManagerStruct> i(m_dbList);
|
|
|
|
while (i.hasNext()) {
|
|
|
|
i.next();
|
|
|
|
if (i.value().dbWidget == dbWidget) {
|
|
|
|
return i.key();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-12-30 12:43:24 -05:00
|
|
|
void DatabaseTabWidget::insertDatabase(Database* db, const DatabaseManagerStruct& dbStruct)
|
2011-11-16 12:47:17 -05:00
|
|
|
{
|
|
|
|
m_dbList.insert(db, dbStruct);
|
|
|
|
|
2011-12-30 12:43:24 -05:00
|
|
|
addTab(dbStruct.dbWidget, "");
|
2012-04-20 05:29:31 -04:00
|
|
|
toggleTabbar();
|
2011-11-16 12:47:17 -05:00
|
|
|
updateTabName(db);
|
2011-12-24 18:56:04 -05:00
|
|
|
int index = databaseIndex(db);
|
2011-12-30 12:43:24 -05:00
|
|
|
setCurrentIndex(index);
|
2011-11-16 12:47:17 -05:00
|
|
|
|
|
|
|
connect(db->metadata(), SIGNAL(nameTextChanged(Database*)), SLOT(updateTabName(Database*)));
|
2011-12-29 13:01:58 -05:00
|
|
|
connect(dbStruct.dbWidget->entryView(), SIGNAL(entrySelectionChanged()), SLOT(emitEntrySelectionChanged()));
|
2012-04-11 14:35:52 -04:00
|
|
|
connect(dbStruct.dbWidget, SIGNAL(closeRequest()), SLOT(closeDatabase()));
|
|
|
|
connect(db, SIGNAL(modified()), SLOT(modified()));
|
2012-04-18 09:38:31 -04:00
|
|
|
connect(dbStruct.dbWidget, SIGNAL(currentChanged(int)), this, SIGNAL(currentWidgetIndexChanged(int)));
|
2011-11-16 12:47:17 -05:00
|
|
|
}
|
2011-12-29 14:03:20 -05:00
|
|
|
|
2011-12-30 12:43:24 -05:00
|
|
|
DatabaseWidget* DatabaseTabWidget::currentDatabaseWidget()
|
2011-12-29 14:03:20 -05:00
|
|
|
{
|
2011-12-30 12:43:24 -05:00
|
|
|
Database* db = indexDatabase(currentIndex());
|
2011-12-29 14:03:20 -05:00
|
|
|
if (db) {
|
|
|
|
return m_dbList[db].dbWidget;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2012-04-11 14:35:52 -04:00
|
|
|
|
|
|
|
void DatabaseTabWidget::modified()
|
|
|
|
{
|
|
|
|
Q_ASSERT(sender());
|
|
|
|
Database* db = static_cast<Database*>(sender());
|
|
|
|
DatabaseManagerStruct& dbStruct = m_dbList[db];
|
|
|
|
if (!dbStruct.modified) {
|
|
|
|
dbStruct.modified = true;
|
|
|
|
updateTabName(db);
|
|
|
|
}
|
|
|
|
}
|