1
/* This file is part of the KDE project
2
Copyright (C) 2005-2011 Jarosław Staniek <staniek@kde.org>
4
This library is free software; you can redistribute it and/or
5
modify it under the terms of the GNU Library General Public
6
License as published by the Free Software Foundation; either
7
version 2 of the License, or (at your option) any later version.
9
This library is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
Library General Public License for more details.
14
You should have received a copy of the GNU Library General Public License
15
along with this library; see the file COPYING.LIB. If not, write to
16
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
* Boston, MA 02110-1301, USA.
20
#include "kexidbshortcutfile.h"
21
#include <core/kexiprojectdata.h>
22
#include <kexiutils/utils.h>
23
#include <kexi_global.h>
25
#include <KDbConnectionData>
30
//! Version of the KexiDBShortcutFile format.
31
#define KexiDBShortcutFile_version 3
34
v2: "encryptedPassword" field added.
35
For backward compatibility, it is not used if the connection data has been loaded from
36
a file saved with version 1. In such cases unencrypted "password" field is used.
37
v3: "name" for shortcuts to file-based databases is a full file path.
38
If the file is within the user's home directory, the dir is replaced with $HOME,
39
e.g. name=$HOME/mydb.kexi. Not compatible with earlier versions but in these
40
versions only filename was stored so the file was generally inaccessible anyway.
41
"lastOpened" field added of type date/time (ISO format).
45
class KexiDBShortcutFile::Private
49
: isDatabaseShortcut(true) {
52
bool isDatabaseShortcut;
55
KexiDBShortcutFile::KexiDBShortcutFile(const QString& fileName)
56
: d(new KexiDBShortcutFile::Private())
58
d->fileName = QDir(fileName).absolutePath();
61
KexiDBShortcutFile::~KexiDBShortcutFile()
66
QString KexiDBShortcutFile::fileName() const
71
//---------------------------------------------
73
KexiDBConnShortcutFile::KexiDBConnShortcutFile(const QString& fileName)
74
: KexiDBShortcutFile(fileName)
78
KexiDBConnShortcutFile::~KexiDBConnShortcutFile()
82
bool KexiDBConnShortcutFile::loadConnectionData(KDbConnectionData* data, QString* _groupKey)
85
KexiProjectData pdata(*data);
86
if (!pdata.load(fileName(), _groupKey)) {
87
m_result = pdata.result();
90
*data = *pdata.connectionData();
94
bool KexiDBConnShortcutFile::saveConnectionData(const KDbConnectionData& data,
95
bool savePassword, QString* groupKey, bool overwriteFirstGroup)
97
KexiProjectData pdata(data);
98
if (!pdata.save(fileName(), savePassword, groupKey, overwriteFirstGroup)) {
99
m_result = pdata.result();