mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-07-26 00:05:34 -04:00
parent
4807ec3368
commit
05c41c083e
11 changed files with 170 additions and 19 deletions
|
@ -68,6 +68,7 @@ set(keepassx_SOURCES
|
||||||
gui/GroupModel.cpp
|
gui/GroupModel.cpp
|
||||||
gui/GroupView.cpp
|
gui/GroupView.cpp
|
||||||
gui/IconModels.cpp
|
gui/IconModels.cpp
|
||||||
|
gui/KeePass1OpenDialog.cpp
|
||||||
gui/MainWindow.cpp
|
gui/MainWindow.cpp
|
||||||
keys/CompositeKey.cpp
|
keys/CompositeKey.cpp
|
||||||
keys/FileKey.cpp
|
keys/FileKey.cpp
|
||||||
|
|
|
@ -235,15 +235,9 @@ Database* KeePass1Reader::readDatabase(QIODevice* device, const QString& passwor
|
||||||
return db.take();
|
return db.take();
|
||||||
}
|
}
|
||||||
|
|
||||||
Database* KeePass1Reader::readDatabase(const QString& filename, const QString& password,
|
Database* KeePass1Reader::readDatabase(QIODevice* device, const QString& password,
|
||||||
const QString& keyfileName)
|
const QString& keyfileName)
|
||||||
{
|
{
|
||||||
QFile dbFile(filename);
|
|
||||||
if (!dbFile.open(QFile::ReadOnly)) {
|
|
||||||
raiseError(dbFile.errorString());
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
QScopedPointer<QFile> keyFile;
|
QScopedPointer<QFile> keyFile;
|
||||||
if (!keyfileName.isEmpty()) {
|
if (!keyfileName.isEmpty()) {
|
||||||
keyFile.reset(new QFile(keyfileName));
|
keyFile.reset(new QFile(keyfileName));
|
||||||
|
@ -253,14 +247,28 @@ Database* KeePass1Reader::readDatabase(const QString& filename, const QString& p
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QScopedPointer<Database> db(readDatabase(&dbFile, password, keyFile.data()));
|
QScopedPointer<Database> db(readDatabase(device, password, keyFile.data()));
|
||||||
|
|
||||||
|
return db.take();
|
||||||
|
}
|
||||||
|
|
||||||
|
Database* KeePass1Reader::readDatabase(const QString& filename, const QString& password,
|
||||||
|
const QString& keyfileName)
|
||||||
|
{
|
||||||
|
QFile dbFile(filename);
|
||||||
|
if (!dbFile.open(QFile::ReadOnly)) {
|
||||||
|
raiseError(dbFile.errorString());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Database* db = readDatabase(&dbFile, password, keyfileName);
|
||||||
|
|
||||||
if (dbFile.error() != QFile::NoError) {
|
if (dbFile.error() != QFile::NoError) {
|
||||||
raiseError(dbFile.errorString());
|
raiseError(dbFile.errorString());
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return db.take();
|
return db;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KeePass1Reader::hasError()
|
bool KeePass1Reader::hasError()
|
||||||
|
|
|
@ -36,6 +36,8 @@ public:
|
||||||
KeePass1Reader();
|
KeePass1Reader();
|
||||||
Database* readDatabase(QIODevice* device, const QString& password,
|
Database* readDatabase(QIODevice* device, const QString& password,
|
||||||
QIODevice* keyfileDevice);
|
QIODevice* keyfileDevice);
|
||||||
|
Database* readDatabase(QIODevice* device, const QString& password,
|
||||||
|
const QString& keyfileName);
|
||||||
Database* readDatabase(const QString& filename, const QString& password,
|
Database* readDatabase(const QString& filename, const QString& password,
|
||||||
const QString& keyfileName);
|
const QString& keyfileName);
|
||||||
bool hasError();
|
bool hasError();
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
#include "keys/FileKey.h"
|
#include "keys/FileKey.h"
|
||||||
#include "keys/PasswordKey.h"
|
#include "keys/PasswordKey.h"
|
||||||
|
|
||||||
DatabaseOpenDialog::DatabaseOpenDialog(QFile* file, QString filename, QWidget* parent)
|
DatabaseOpenDialog::DatabaseOpenDialog(QFile* file, const QString& filename, QWidget* parent)
|
||||||
: QDialog(parent)
|
: QDialog(parent)
|
||||||
, m_ui(new Ui::DatabaseOpenDialog())
|
, m_ui(new Ui::DatabaseOpenDialog())
|
||||||
, m_db(0)
|
, m_db(0)
|
||||||
|
|
|
@ -35,25 +35,28 @@ class DatabaseOpenDialog : public QDialog
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit DatabaseOpenDialog(QFile* file, QString filename, QWidget* parent = 0);
|
DatabaseOpenDialog(QFile* file, const QString& filename, QWidget* parent = 0);
|
||||||
~DatabaseOpenDialog();
|
~DatabaseOpenDialog();
|
||||||
Database* database();
|
Database* database();
|
||||||
void enterKey(const QString& pw, const QString& keyFile);
|
void enterKey(const QString& pw, const QString& keyFile);
|
||||||
|
|
||||||
|
protected Q_SLOTS:
|
||||||
|
virtual void openDatabase();
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void openDatabase();
|
|
||||||
void togglePassword(bool checked);
|
void togglePassword(bool checked);
|
||||||
void activatePassword();
|
void activatePassword();
|
||||||
void activateKeyFile();
|
void activateKeyFile();
|
||||||
void setOkButtonEnabled();
|
void setOkButtonEnabled();
|
||||||
void browseKeyFile();
|
void browseKeyFile();
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
const QScopedPointer<Ui::DatabaseOpenDialog> m_ui;
|
const QScopedPointer<Ui::DatabaseOpenDialog> m_ui;
|
||||||
Database* m_db;
|
Database* m_db;
|
||||||
QFile* const m_file;
|
QFile* const m_file;
|
||||||
const QString m_filename;
|
const QString m_filename;
|
||||||
|
|
||||||
|
private:
|
||||||
Q_DISABLE_COPY(DatabaseOpenDialog)
|
Q_DISABLE_COPY(DatabaseOpenDialog)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -24,11 +24,12 @@
|
||||||
#include "core/Database.h"
|
#include "core/Database.h"
|
||||||
#include "core/Group.h"
|
#include "core/Group.h"
|
||||||
#include "core/Metadata.h"
|
#include "core/Metadata.h"
|
||||||
#include "gui/DatabaseWidget.h"
|
|
||||||
#include "gui/FileDialog.h"
|
|
||||||
#include "gui/EntryView.h"
|
|
||||||
#include "gui/GroupView.h"
|
|
||||||
#include "gui/DatabaseOpenDialog.h"
|
#include "gui/DatabaseOpenDialog.h"
|
||||||
|
#include "gui/DatabaseWidget.h"
|
||||||
|
#include "gui/EntryView.h"
|
||||||
|
#include "gui/FileDialog.h"
|
||||||
|
#include "gui/GroupView.h"
|
||||||
|
#include "gui/KeePass1OpenDialog.h"
|
||||||
|
|
||||||
DatabaseManagerStruct::DatabaseManagerStruct()
|
DatabaseManagerStruct::DatabaseManagerStruct()
|
||||||
: file(0)
|
: file(0)
|
||||||
|
@ -115,6 +116,30 @@ void DatabaseTabWidget::openDatabaseDialog(const QString& pw, const QString& key
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DatabaseTabWidget::importKeePass1Database()
|
||||||
|
{
|
||||||
|
QString fileName = fileDialog()->getOpenFileName(this, tr("Open KeePass 1 database"), QString(),
|
||||||
|
tr("KeePass 1 database") + " (*.kdb);;" + tr("All files (*)"));
|
||||||
|
|
||||||
|
if (fileName.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QScopedPointer<QFile> file(new QFile(fileName));
|
||||||
|
// TODO: error handling
|
||||||
|
if (!file->open(QIODevice::ReadOnly)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_curDbStruct.modified = true;
|
||||||
|
|
||||||
|
m_curKeyDialog = new KeePass1OpenDialog(file.take(), fileName, m_window);
|
||||||
|
connect(m_curKeyDialog, SIGNAL(accepted()), SLOT(openDatabaseRead()));
|
||||||
|
connect(m_curKeyDialog, SIGNAL(rejected()), SLOT(openDatabaseCleanup()));
|
||||||
|
m_curKeyDialog->setModal(true);
|
||||||
|
m_curKeyDialog->show();
|
||||||
|
}
|
||||||
|
|
||||||
void DatabaseTabWidget::openDatabaseRead()
|
void DatabaseTabWidget::openDatabaseRead()
|
||||||
{
|
{
|
||||||
Database* db = m_curKeyDialog->database();
|
Database* db = m_curKeyDialog->database();
|
||||||
|
|
|
@ -56,6 +56,7 @@ public:
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void newDatabase();
|
void newDatabase();
|
||||||
void openDatabase();
|
void openDatabase();
|
||||||
|
void importKeePass1Database();
|
||||||
void saveDatabase(int index = -1);
|
void saveDatabase(int index = -1);
|
||||||
void saveDatabaseAs(int index = -1);
|
void saveDatabaseAs(int index = -1);
|
||||||
bool closeDatabase(int index = -1);
|
bool closeDatabase(int index = -1);
|
||||||
|
|
67
src/gui/KeePass1OpenDialog.cpp
Normal file
67
src/gui/KeePass1OpenDialog.cpp
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2012 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "KeePass1OpenDialog.h"
|
||||||
|
|
||||||
|
#include <QtCore/QFile>
|
||||||
|
#include <QtCore/QFileInfo>
|
||||||
|
#include <QtGui/QMessageBox>
|
||||||
|
|
||||||
|
#include "ui_DatabaseOpenDialog.h"
|
||||||
|
#include "core/Database.h"
|
||||||
|
#include "core/Metadata.h"
|
||||||
|
#include "format/KeePass1Reader.h"
|
||||||
|
|
||||||
|
KeePass1OpenDialog::KeePass1OpenDialog(QFile* file, const QString& filename, QWidget* parent)
|
||||||
|
: DatabaseOpenDialog(file, filename, parent)
|
||||||
|
{
|
||||||
|
setWindowTitle(tr("Import KeePass1 database"));
|
||||||
|
}
|
||||||
|
|
||||||
|
KeePass1OpenDialog::~KeePass1OpenDialog()
|
||||||
|
{
|
||||||
|
delete m_file;
|
||||||
|
}
|
||||||
|
|
||||||
|
void KeePass1OpenDialog::openDatabase()
|
||||||
|
{
|
||||||
|
KeePass1Reader reader;
|
||||||
|
|
||||||
|
QString password;
|
||||||
|
QString keyFileName;
|
||||||
|
|
||||||
|
if (m_ui->checkPassword->isChecked()) {
|
||||||
|
password = m_ui->editPassword->text();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_ui->checkKeyFile->isChecked()) {
|
||||||
|
keyFileName = m_ui->comboKeyFile->currentText();
|
||||||
|
}
|
||||||
|
|
||||||
|
m_file->reset();
|
||||||
|
m_db = reader.readDatabase(m_file, password, keyFileName);
|
||||||
|
|
||||||
|
if (m_db) {
|
||||||
|
m_db->metadata()->setName(QFileInfo(m_filename).completeBaseName());
|
||||||
|
accept();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
QMessageBox::warning(this, tr("Error"), tr("Unable to open the database.\n%1")
|
||||||
|
.arg(reader.errorString()));
|
||||||
|
m_ui->editPassword->clear();
|
||||||
|
}
|
||||||
|
}
|
33
src/gui/KeePass1OpenDialog.h
Normal file
33
src/gui/KeePass1OpenDialog.h
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2012 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef KEEPASSX_KEEPASS1OPENDIALOG_H
|
||||||
|
#define KEEPASSX_KEEPASS1OPENDIALOG_H
|
||||||
|
|
||||||
|
#include "gui/DatabaseOpenDialog.h"
|
||||||
|
|
||||||
|
class KeePass1OpenDialog : public DatabaseOpenDialog
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit KeePass1OpenDialog(QFile* file, const QString& filename, QWidget* parent = 0);
|
||||||
|
~KeePass1OpenDialog();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void openDatabase();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // KEEPASSX_KEEPASS1OPENDIALOG_H
|
|
@ -58,20 +58,24 @@ MainWindow::MainWindow()
|
||||||
SLOT(changeMasterKey()));
|
SLOT(changeMasterKey()));
|
||||||
connect(m_ui->actionChangeDatabaseSettings, SIGNAL(triggered()), m_ui->tabWidget,
|
connect(m_ui->actionChangeDatabaseSettings, SIGNAL(triggered()), m_ui->tabWidget,
|
||||||
SLOT(changeDatabaseSettings()));
|
SLOT(changeDatabaseSettings()));
|
||||||
|
connect(m_ui->actionImportKeePass1, SIGNAL(triggered()), m_ui->tabWidget,
|
||||||
|
SLOT(importKeePass1Database()));
|
||||||
|
connect(m_ui->actionQuit, SIGNAL(triggered()), SLOT(close()));
|
||||||
|
connect(m_ui->actionAbout, SIGNAL(triggered()), SLOT(showAboutDialog()));
|
||||||
|
|
||||||
connect(m_ui->actionEntryNew, SIGNAL(triggered()), m_ui->tabWidget,
|
connect(m_ui->actionEntryNew, SIGNAL(triggered()), m_ui->tabWidget,
|
||||||
SLOT(createEntry()));
|
SLOT(createEntry()));
|
||||||
connect(m_ui->actionEntryEdit, SIGNAL(triggered()), m_ui->tabWidget,
|
connect(m_ui->actionEntryEdit, SIGNAL(triggered()), m_ui->tabWidget,
|
||||||
SLOT(editEntry()));
|
SLOT(editEntry()));
|
||||||
connect(m_ui->actionEntryDelete, SIGNAL(triggered()), m_ui->tabWidget,
|
connect(m_ui->actionEntryDelete, SIGNAL(triggered()), m_ui->tabWidget,
|
||||||
SLOT(deleteEntry()));
|
SLOT(deleteEntry()));
|
||||||
|
|
||||||
connect(m_ui->actionGroupNew, SIGNAL(triggered()), m_ui->tabWidget,
|
connect(m_ui->actionGroupNew, SIGNAL(triggered()), m_ui->tabWidget,
|
||||||
SLOT(createGroup()));
|
SLOT(createGroup()));
|
||||||
connect(m_ui->actionGroupEdit, SIGNAL(triggered()), m_ui->tabWidget,
|
connect(m_ui->actionGroupEdit, SIGNAL(triggered()), m_ui->tabWidget,
|
||||||
SLOT(editGroup()));
|
SLOT(editGroup()));
|
||||||
connect(m_ui->actionGroupDelete, SIGNAL(triggered()), m_ui->tabWidget,
|
connect(m_ui->actionGroupDelete, SIGNAL(triggered()), m_ui->tabWidget,
|
||||||
SLOT(deleteGroup()));
|
SLOT(deleteGroup()));
|
||||||
connect(m_ui->actionQuit, SIGNAL(triggered()), SLOT(close()));
|
|
||||||
connect(m_ui->actionAbout, SIGNAL(triggered()), SLOT(showAboutDialog()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
|
|
|
@ -52,6 +52,8 @@
|
||||||
<addaction name="actionChangeMasterKey"/>
|
<addaction name="actionChangeMasterKey"/>
|
||||||
<addaction name="actionChangeDatabaseSettings"/>
|
<addaction name="actionChangeDatabaseSettings"/>
|
||||||
<addaction name="separator"/>
|
<addaction name="separator"/>
|
||||||
|
<addaction name="actionImportKeePass1"/>
|
||||||
|
<addaction name="separator"/>
|
||||||
<addaction name="actionQuit"/>
|
<addaction name="actionQuit"/>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QMenu" name="menuHelp">
|
<widget class="QMenu" name="menuHelp">
|
||||||
|
@ -209,6 +211,11 @@
|
||||||
<string>Database settings</string>
|
<string>Database settings</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
<action name="actionImportKeePass1">
|
||||||
|
<property name="text">
|
||||||
|
<string>Import KeePass 1 database</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue