summaryrefslogtreecommitdiffstats
path: root/kexi/core/kexidbconnectionset.h
blob: fc831cdcdc991e269ee991fc4971164d85b670d8 (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
/* This file is part of the KDE project
   Copyright (C) 2003,2005 Jaroslaw Staniek <js@iidea.pl>

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

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

#ifndef KEXIDBCONNSET_H
#define KEXIDBCONNSET_H

#include <tqstring.h>
#include <kexidb/connectiondata.h>

class KexiDBConnectionSetPrivate;

/*! Stores information about multiple connection-data items. */
class KEXICORE_EXPORT KexiDBConnectionSet : public TQObject
{
public:
	KexiDBConnectionSet();
	~KexiDBConnectionSet();

	/*! Loads connection data set from storage, currently from 
	 .kexic files saved in dirs returned by 
	 KStandardDirs::findDirs("data", "connections") */
	void load();

	/*! Adds \a data as connection data. 
	 \a data will be owned by a KexiDBConnectionSet object. 
	 If \a filename is not empty, it will be kept for use in saveConnectionData(). 
	 saveConnectionData() is called automatically, if there's no \a filename provided 
	 or the filename is already used, a new unique will be generated. 
	 \return true on successful creating corresponding .kexic file */
	bool addConnectionData(KexiDB::ConnectionData *data, const TQString& filename = TQString());

	/*! Saves changes made to \a oldData to a file which name has been provided by addConnectionData(). 
	 This function does nothing if \a oldData hasn't been added to this set. 
	 \return true on success (data is then copied from \a newData to \a oldData) */
	bool saveConnectionData(KexiDB::ConnectionData *oldData, KexiDB::ConnectionData *newData);

	/*! Removed \a data from this set. 
	 \return true on successful removing of corresponding .kexic file */
	bool removeConnectionData(KexiDB::ConnectionData *data);

	/*! \return the list of connection data items. */
	const KexiDB::ConnectionData::List& list() const;

	/*! \return a filename of a connection data file for \a data. */
	TQString fileNameForConnectionData(KexiDB::ConnectionData *data) const;

	/*! \return a connection data for a .kexic shortcut filename. 
	 0 is returned if the filename does not match. */
	KexiDB::ConnectionData* connectionDataForFileName(const TQString& fileName) const;

private:
	/*! Removes all connection data items from this set. */
	void clear();
	void addConnectionDataInternal(KexiDB::ConnectionData *data, const TQString& filename);
	void removeConnectionDataInternal(KexiDB::ConnectionData *data);

	KexiDBConnectionSetPrivate *d;
};

#endif // KEXIDBCONNSET_H