~ubuntu-branches/debian/sid/kexi/sid

« back to all changes in this revision

Viewing changes to src/core/kexidbshortcutfile.cpp

  • Committer: Package Import Robot
  • Author(s): Pino Toscano
  • Date: 2017-06-24 20:10:10 UTC
  • Revision ID: package-import@ubuntu.com-20170624201010-5lrzd5r2vwthwifp
Tags: upstream-3.0.1.1
Import upstream version 3.0.1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of the KDE project
 
2
   Copyright (C) 2005-2011 Jarosław Staniek <staniek@kde.org>
 
3
 
 
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.
 
8
 
 
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.
 
13
 
 
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.
 
18
*/
 
19
 
 
20
#include "kexidbshortcutfile.h"
 
21
#include <core/kexiprojectdata.h>
 
22
#include <kexiutils/utils.h>
 
23
#include <kexi_global.h>
 
24
 
 
25
#include <KDbConnectionData>
 
26
 
 
27
#include <QDebug>
 
28
#include <QDir>
 
29
 
 
30
//! Version of the KexiDBShortcutFile format.
 
31
#define KexiDBShortcutFile_version 3
 
32
/* CHANGELOG:
 
33
 v1: initial version
 
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).
 
42
*/
 
43
 
 
44
//! @internal
 
45
class KexiDBShortcutFile::Private
 
46
{
 
47
public:
 
48
    Private()
 
49
            : isDatabaseShortcut(true) {
 
50
    }
 
51
    QString fileName;
 
52
    bool isDatabaseShortcut;
 
53
};
 
54
 
 
55
KexiDBShortcutFile::KexiDBShortcutFile(const QString& fileName)
 
56
        : d(new KexiDBShortcutFile::Private())
 
57
{
 
58
    d->fileName = QDir(fileName).absolutePath();
 
59
}
 
60
 
 
61
KexiDBShortcutFile::~KexiDBShortcutFile()
 
62
{
 
63
    delete d;
 
64
}
 
65
 
 
66
QString KexiDBShortcutFile::fileName() const
 
67
{
 
68
    return d->fileName;
 
69
}
 
70
 
 
71
//---------------------------------------------
 
72
 
 
73
KexiDBConnShortcutFile::KexiDBConnShortcutFile(const QString& fileName)
 
74
        : KexiDBShortcutFile(fileName)
 
75
{
 
76
}
 
77
 
 
78
KexiDBConnShortcutFile::~KexiDBConnShortcutFile()
 
79
{
 
80
}
 
81
 
 
82
bool KexiDBConnShortcutFile::loadConnectionData(KDbConnectionData* data, QString* _groupKey)
 
83
{
 
84
    Q_ASSERT(data);
 
85
    KexiProjectData pdata(*data);
 
86
    if (!pdata.load(fileName(), _groupKey)) {
 
87
        m_result = pdata.result();
 
88
        return false;
 
89
    }
 
90
    *data = *pdata.connectionData();
 
91
    return true;
 
92
}
 
93
 
 
94
bool KexiDBConnShortcutFile::saveConnectionData(const KDbConnectionData& data,
 
95
        bool savePassword, QString* groupKey, bool overwriteFirstGroup)
 
96
{
 
97
    KexiProjectData pdata(data);
 
98
    if (!pdata.save(fileName(), savePassword, groupKey, overwriteFirstGroup)) {
 
99
        m_result = pdata.result();
 
100
        return false;
 
101
    }
 
102
    return true;
 
103
}