Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/keepassxreboot/keepassxc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFelix Geyer <debfx@fobos.de>2011-12-26 04:21:29 +0400
committerFelix Geyer <debfx@fobos.de>2011-12-26 04:21:29 +0400
commitf90831b8095a51aca87be9dfea5c75520f3baa58 (patch)
tree363d41dc14e042c8d401ec62f50af63b4e89ce00 /src
parentdc0de8caf20270013b7f168502afdc3abd9aec25 (diff)
Use an own FileDialog class instead of QFileDialog.
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/gui/DatabaseManager.cpp10
-rw-r--r--src/gui/FileDialog.cpp86
-rw-r--r--src/gui/FileDialog.h46
-rw-r--r--src/gui/KeyOpenDialog.cpp4
5 files changed, 140 insertions, 7 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index c888f9538..d8630f0db 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -51,6 +51,7 @@ set(keepassx_SOURCES
gui/EditEntryWidget.cpp
gui/EntryModel.cpp
gui/EntryView.cpp
+ gui/FileDialog.cpp
gui/GroupModel.cpp
gui/GroupView.cpp
gui/KeyOpenDialog.cpp
diff --git a/src/gui/DatabaseManager.cpp b/src/gui/DatabaseManager.cpp
index 0f6ac0f6c..e187d4f26 100644
--- a/src/gui/DatabaseManager.cpp
+++ b/src/gui/DatabaseManager.cpp
@@ -18,13 +18,13 @@
#include "DatabaseManager.h"
#include <QtCore/QFileInfo>
-#include <QtGui/QFileDialog>
#include <QtGui/QTabWidget>
#include "core/Database.h"
#include "core/Metadata.h"
#include "format/KeePass2XmlReader.h"
#include "gui/DatabaseWidget.h"
+#include "gui/FileDialog.h"
#include "gui/KeyOpenDialog.h"
DatabaseManagerStruct::DatabaseManagerStruct()
@@ -53,8 +53,8 @@ void DatabaseManager::newDatabase()
void DatabaseManager::openDatabase()
{
- QString fileName = QFileDialog::getOpenFileName(m_window, tr("Open database"), QString(),
- tr("KeePass 2 Database").append(" (*.kdbx)"));
+ QString fileName = fileDialog()->getOpenFileName(m_window, tr("Open database"), QString(),
+ tr("KeePass 2 Database").append(" (*.kdbx)"));
if (!fileName.isEmpty()) {
openDatabase(fileName);
}
@@ -134,8 +134,8 @@ void DatabaseManager::saveDatabase(Database* db)
void DatabaseManager::saveDatabaseAs(Database* db)
{
- QString fileName = QFileDialog::getSaveFileName(m_window, tr("Save database as"),
- QString(), tr("KeePass 2 Database").append(" (*.kdbx)"));
+ QString fileName = fileDialog()->getSaveFileName(m_window, tr("Save database as"),
+ QString(), tr("KeePass 2 Database").append(" (*.kdbx)"));
if (!fileName.isEmpty()) {
DatabaseManagerStruct& dbStruct = m_dbList[db];
diff --git a/src/gui/FileDialog.cpp b/src/gui/FileDialog.cpp
new file mode 100644
index 000000000..aa18aeb79
--- /dev/null
+++ b/src/gui/FileDialog.cpp
@@ -0,0 +1,86 @@
+/*
+ * 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/>.
+ */
+
+#include "FileDialog.h"
+
+#include "core/Config.h"
+
+QString FileDialog::getOpenFileName(QWidget* parent, const QString& caption, QString dir,
+ const QString& filter, QString* selectedFilter, QFileDialog::Options options)
+{
+ if (!m_nextFileName.isEmpty()) {
+ QString result = m_nextFileName;
+ m_nextFileName = "";
+ return result;
+ }
+ else {
+ if (dir.isEmpty()) {
+ dir = config()->get("LastDir").toString();
+ }
+
+ QString result = QFileDialog::getOpenFileName(parent, caption, dir, filter, selectedFilter, options);
+
+ if (!result.isEmpty()) {
+ config()->set("LastDir", QFileInfo(result).absolutePath());
+ }
+
+ return result;
+ }
+}
+
+QString FileDialog::getSaveFileName(QWidget* parent, const QString& caption, QString dir,
+ const QString& filter, QString* selectedFilter, QFileDialog::Options options)
+{
+ if (!m_nextFileName.isEmpty()) {
+ QString result = m_nextFileName;
+ m_nextFileName = "";
+ return result;
+ }
+ else {
+ if (dir.isEmpty()) {
+ dir = config()->get("LastDir").toString();
+ }
+
+ QString result = QFileDialog::getSaveFileName(parent, caption, dir, filter, selectedFilter, options);
+
+ if (!result.isEmpty()) {
+ config()->set("LastDir", QFileInfo(result).absolutePath());
+ }
+
+ return result;
+ }
+}
+
+void FileDialog::setNextFileName(const QString& fileName)
+{
+ m_nextFileName = fileName;
+}
+
+FileDialog::FileDialog()
+{
+}
+
+FileDialog* fileDialog()
+{
+ static FileDialog* instance(0);
+
+ if (!instance) {
+ instance = new FileDialog();
+ }
+
+ return instance;
+}
diff --git a/src/gui/FileDialog.h b/src/gui/FileDialog.h
new file mode 100644
index 000000000..5e0acd458
--- /dev/null
+++ b/src/gui/FileDialog.h
@@ -0,0 +1,46 @@
+/*
+ * 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/>.
+ */
+
+#ifndef KEEPASSX_FILEDIALOG_H
+#define KEEPASSX_FILEDIALOG_H
+
+#include <QtGui/QFileDialog>
+
+class FileDialog
+{
+public:
+ QString getOpenFileName(QWidget* parent = 0, const QString& caption = QString(), QString dir = QString(),
+ const QString& filter = QString(), QString* selectedFilter = 0, QFileDialog::Options options = 0);
+ QString getSaveFileName(QWidget* parent = 0, const QString& caption = QString(), QString dir = QString(),
+ const QString& filter = QString(), QString* selectedFilter = 0, QFileDialog::Options options = 0);
+
+ /**
+ * Sets the result of the next get* method call.
+ * Use only for testing.
+ */
+ void setNextFileName(const QString& fileName);
+
+private:
+ FileDialog();
+ QString m_nextFileName;
+
+ friend FileDialog* fileDialog();
+};
+
+FileDialog* fileDialog();
+
+#endif // KEEPASSX_FILEDIALOG_H
diff --git a/src/gui/KeyOpenDialog.cpp b/src/gui/KeyOpenDialog.cpp
index c28ee825b..95631c3a4 100644
--- a/src/gui/KeyOpenDialog.cpp
+++ b/src/gui/KeyOpenDialog.cpp
@@ -18,10 +18,10 @@
#include "KeyOpenDialog.h"
#include "ui_KeyOpenDialog.h"
-#include <QtGui/QFileDialog>
#include <QtGui/QMessageBox>
#include "core/Config.h"
+#include "gui/FileDialog.h"
#include "keys/FileKey.h"
#include "keys/PasswordKey.h"
@@ -116,7 +116,7 @@ void KeyOpenDialog::setOkButtonEnabled()
void KeyOpenDialog::browseKeyFile()
{
QString filters = QString("%1 (*);;%2 (*.key)").arg(tr("All files"), tr("Key files"));
- QString filename = QFileDialog::getOpenFileName(this, tr("Select key file"), QString(), filters);
+ QString filename = fileDialog()->getOpenFileName(this, tr("Select key file"), QString(), filters);
if (!filename.isEmpty()) {
m_ui->comboKeyFile->lineEdit()->setText(filename);