File indexing completed on 2024-05-12 16:39:36
0001 /* This file is part of the KDE project 0002 Copyright (C) 2005-2011 Jarosław Staniek <staniek@kde.org> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Library General Public 0006 License as published by the Free Software Foundation; either 0007 version 2 of the License, or (at your option) any later version. 0008 0009 This library is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 Library General Public License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this library; see the file COPYING.LIB. If not, write to 0016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 * Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #include "kexidbshortcutfile.h" 0021 #include <core/kexiprojectdata.h> 0022 #include <kexiutils/utils.h> 0023 #include <kexi_global.h> 0024 0025 #include <KDbConnectionData> 0026 0027 #include <QDebug> 0028 #include <QDir> 0029 0030 //! Version of the KexiDBShortcutFile format. 0031 #define KexiDBShortcutFile_version 3 0032 /* CHANGELOG: 0033 v1: initial version 0034 v2: "encryptedPassword" field added. 0035 For backward compatibility, it is not used if the connection data has been loaded from 0036 a file saved with version 1. In such cases unencrypted "password" field is used. 0037 v3: "name" for shortcuts to file-based databases is a full file path. 0038 If the file is within the user's home directory, the dir is replaced with $HOME, 0039 e.g. name=$HOME/mydb.kexi. Not compatible with earlier versions but in these 0040 versions only filename was stored so the file was generally inaccessible anyway. 0041 "lastOpened" field added of type date/time (ISO format). 0042 */ 0043 0044 //! @internal 0045 class Q_DECL_HIDDEN KexiDBShortcutFile::Private 0046 { 0047 public: 0048 Private() 0049 : isDatabaseShortcut(true) { 0050 } 0051 QString fileName; 0052 bool isDatabaseShortcut; 0053 }; 0054 0055 KexiDBShortcutFile::KexiDBShortcutFile(const QString& fileName) 0056 : d(new KexiDBShortcutFile::Private()) 0057 { 0058 d->fileName = QDir(fileName).absolutePath(); 0059 } 0060 0061 KexiDBShortcutFile::~KexiDBShortcutFile() 0062 { 0063 delete d; 0064 } 0065 0066 QString KexiDBShortcutFile::fileName() const 0067 { 0068 return d->fileName; 0069 } 0070 0071 //--------------------------------------------- 0072 0073 KexiDBConnShortcutFile::KexiDBConnShortcutFile(const QString& fileName) 0074 : KexiDBShortcutFile(fileName) 0075 { 0076 } 0077 0078 KexiDBConnShortcutFile::~KexiDBConnShortcutFile() 0079 { 0080 } 0081 0082 bool KexiDBConnShortcutFile::loadConnectionData(KDbConnectionData* data, QString* _groupKey) 0083 { 0084 Q_ASSERT(data); 0085 KexiProjectData pdata(*data); 0086 if (!pdata.load(fileName(), _groupKey)) { 0087 m_result = pdata.result(); 0088 return false; 0089 } 0090 *data = *pdata.connectionData(); 0091 return true; 0092 } 0093 0094 bool KexiDBConnShortcutFile::saveConnectionData(const KDbConnectionData& data, 0095 bool savePassword, QString* groupKey, bool overwriteFirstGroup) 0096 { 0097 KexiProjectData pdata(data); 0098 if (!pdata.save(fileName(), savePassword, groupKey, overwriteFirstGroup)) { 0099 m_result = pdata.result(); 0100 return false; 0101 } 0102 return true; 0103 }