summaryrefslogtreecommitdiffstats
path: root/kexi/core/kexidbshortcutfile.h
blob: 3dfa9c13dab42ccda0b10090a669c027ee043a68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/* This file is part of the KDE project
   Copyright (C) 2005 Jaroslaw Staniek <js@iidea.pl>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library 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
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
*/

#ifndef KEXIDBSHORTCUTFILE_H
#define KEXIDBSHORTCUTFILE_H

#include <qstring.h>

class KexiProjectData;
namespace KexiDB { class ConnectionData; }

/*! Loads and saves information for a "shortcut to a connection" file containing 
 connection information with database name (i.e. ProjectData). 
 This is implementation for handling .KEXIS files. 
 See http://www.kexi-project.org/wiki/wikiview/index.php?KexiMimeTypes_DataSaving_Loading
*/
class KEXICORE_EXPORT KexiDBShortcutFile
{
	public:
		/*! Creates a new object for \a fileName. */
		KexiDBShortcutFile( const QString& fileName );

		~KexiDBShortcutFile();

		/*! Loads project data (with connection data) into \a data.
		 Database name and caption can be set there but these are optional. 
		 \a groupKey, if provided will be set to a group key,
		 so you can later use it in saveConnectionData(). 
		 \return true on success. */
		bool loadProjectData(KexiProjectData& data, QString* groupKey = 0);

		/*! Saves project data \a data (with connection data) to a shortcut file. 
		 If \a storePassword is true, password will be saved in the file,
		 even if data.connectionData()->savePassword is false. 
		 Existing data is merged with new data. \a groupKey is reused, if specified. 
		 If \a overwriteFirstGroup is true (the default) first found group will be overwritten 
		 instead of creating of a new unique group. This mode is usable for updating .kexic files 
		 containing single connection data, what's used for storing connections repository. 
		 \return true on success. */
		bool saveProjectData(const KexiProjectData& data, bool savePassword, 
			QString* groupKey = 0, bool overwriteFirstGroup = true);

		//! \return filename provided on this object's construction. */
		QString fileName() const;

	protected:
		class Private;
		Private *d;
};

/*! Loads and saves information for a "shortcut" file containing 
 connection information (i.e. KexiDB::ConnectionData). 
 This is implementation for handling .KEXIC files.
 See http://www.kexi-project.org/wiki/wikiview/index.php?KexiMimeTypes_DataSaving_Loading
*/
class KEXICORE_EXPORT KexiDBConnShortcutFile : protected KexiDBShortcutFile
{
	public:
		/*! Creates a new object for \a fileName. */
		KexiDBConnShortcutFile( const QString& fileName );

		~KexiDBConnShortcutFile();

		/*! Loads connection data into \a data.
		 \a groupKey, if provided will be set to a group key,
		 so you can later use it in saveConnectionData(). 
		 \return true on success. */
		bool loadConnectionData(KexiDB::ConnectionData& data, QString* groupKey = 0);

		/*! Saves connection data \a data to a shortcut file. 
		 If \a storePassword is true, password will be saved in the file,
		 even if data.savePassword is false. 
		 Existing data is merged with new data. \a groupKey is reused, if specified. 
		 If \a overwriteFirstGroup is true (the default) first found group will be overwritten 
		 instead of creating of a new unique group. This mode is usable for updating .kexic files 
		 containing single connection data, what's used for storing connections repository.
		 \return true on success. */
		bool saveConnectionData(const KexiDB::ConnectionData& data, 
			bool savePassword, QString* groupKey = 0, bool overwriteFirstGroup = true);

		//! \return filename provided on this object's construction. */
		QString fileName() const { return KexiDBShortcutFile::fileName(); }

	protected:
};

#if 0
//! Loads and saves information for a sef of "shortcut to a connection" file containing 
//! connection information (i.e. KexiDBConnectionSet). 
//! This is implementation for handling .KEXIC files.
//! The set is loaded from files found using 
//! KGlobal::dirs()->findAllResources("data", "kexi/connections/*.kexic").
class KexiDBConnSetShortcutFiles
{
	public:
		KexiDBConnSetShortcutFiles();

		/*! Loads connection data into \a set. The set is cleared before loading. 
		 \retuirn true on successful loading. */
		static bool loadConnectionDataSet(KexiDBConnectionSet& set);

		/*! Saves a set of connection data \a set to a shortcut files. 
		 Existing files are overwritten with a new data. 
		 \retuirn true on successful saving. */
		static bool saveConnectionDataSet(const KexiDBConnectionSet& set);
}
#endif
#endif