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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
/*
This file is part of the KDE libraries
Copyright (C) 2003 Charles Samuels <charles@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
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 KDATACOLLECTION_H
#define KDATACOLLECTION_H
#include <tqstring.h>
#include <tqstringlist.h>
class KConfig;
/**
* This class allows you to have a set of files. Some of which can be included
* with your application, and some can be created by your users.
* Examples of a use for this function can be:
*<ul>
* <li>Noatun's Equalizer preset: Each Equalizer preset is in its own XML
* file, and the user can delete, create new ones, and modify old ones</li>
*</ul>
*
*<pre>
* KDataCollection profiles("appname/ui_profiles");
* TQStringList letUserSelectOne = profiles.names();
* TQString fileToOpen = profiles.file(theOneUserSelected);
* TQString fileToWriteTo = profiles.saveFile(theOneUserSelected);
*</pre>
*
* @author Charles Samuels <charles@kde.org>
**/
class KDataCollection
{
KConfig *mConfig;
TQString mGroup, mEntry, mDir;
const char *mDatadir;
struct Private;
Private *d;
public:
/**
* constructor. This gives you most control over the destination of
* settings, @p dir is the second argument to locate(datadir, ...)
*
* @param datadir is what is passed to locate, this is "appdata" by default
**/
KDataCollection(
KConfig *config, const TQString &group, const TQString &entry,
const char *datadir, const TQString &dir
);
/**
* constructor. This gives you most control over the destination of
* settings, @p dir is the second argument to locate("appdata", ...)
**/
KDataCollection(
KConfig *config, const TQString &group, const TQString &entry,
const TQString &dir
);
/**
* constructor. The entry in the KConfig group will be named the same as
* @p dir.
*
* otherwise the same as the previous function
**/
KDataCollection(
KConfig *config, const TQString &group,
const TQString &dir
);
/**
* constructor. The group will be "KDataCollection", The entry in the
* KConfig group will be named the same as
* @p dir.
*
* otherwise the same as the previous function
**/
KDataCollection(KConfig *config, const TQString &dir);
/**
* constructor. the KConfig is assumed to be TDEGlobal::config()
*
* otherwise the same as the previous function
**/
KDataCollection(const TQString &dir);
/**
* returns a list of existant, non hidden files
**/
TQStringList names() const;
/**
* deletes the file if it is in TDEHOME, or marks it as hidden if it's a
* system file
**/
void remove(const TQString &name);
/**
* @returns the filename for a file named @p name, if @p create
* is true, it will create the file if it doesn't exist, if @p create is false,
* it will return an empty string, unless the file already exists
*
* if you want to modify this file, you should use saveFile instead
**/
TQString file(const TQString &name, bool create=true);
/**
* @returns the filename for a file you can save into. If @p create is
* false, it'll return an empty string if the file doesn't already exist in
* TDEHOME
*
* This function will not create the file, only return what the name is in
* theory.
*
* It will not return a file if the Kiosk framework claims that it's
* restricted
**/
TQString saveFile(const TQString &name, bool create=true);
private:
void init(
KConfig *config, const TQString &group, const TQString &entry,
const char *datadir, const TQString &dir
);
};
#endif
|