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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
/***************************************************************************
* Copyright (C) 2004 by Alexander Dymo <adymo@kdevelop.org> *
* *
* 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 General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#include "profile.h"
#include <tqdir.h>
#include <tqfileinfo.h>
#include <kdebug.h>
#include <kstandarddirs.h>
#include <tdeconfig.h>
#include <tdeio/netaccess.h>
Profile::Profile(Profile *parent, const TQString &name)
:m_parent(parent), m_name(name)
{
if (m_parent)
m_parent->addChildProfile(this);
TQString profileConfig = locate("data", "tdevelop/profiles" + dirName() + "/profile.config");
TDEConfig config(profileConfig);
config.setGroup("Information");
m_genericName = config.readEntry("GenericName");
m_description = config.readEntry("Description");
config.setGroup("Properties");
m_properties = config.readListEntry("List");
config.setGroup("Enable");
m_explicitEnable = config.readListEntry("List");
config.setGroup("Disable");
m_explicitDisable = config.readListEntry("List");
}
Profile::Profile(Profile *parent, const TQString &name, const TQString &genericName, const TQString &description)
:m_parent(parent), m_name(name), m_genericName(genericName), m_description(description)
{
if (m_parent)
m_parent->addChildProfile(this);
save();
}
Profile::~Profile()
{
for (TQValueList<Profile*>::iterator it = m_children.begin(); it != m_children.end(); ++it)
delete *it;
}
void Profile::addChildProfile(Profile *profile)
{
m_children.append(profile);
}
void Profile::removeChildProfile(Profile *profile)
{
m_children.remove(profile);
}
TQString Profile::dirName() const
{
if (m_parent)
return m_parent->dirName() + "/" + m_name;
else
return "/"/* + m_name*/;
}
void Profile::save()
{
TQString profileConfig = locateLocal("data", "tdevelop/profiles" + dirName() + "/profile.config");
TDEConfig config(profileConfig);
config.setGroup("Information");
config.writeEntry("GenericName", m_genericName);
config.writeEntry("Description", m_description);
config.setGroup("Properties");
config.writeEntry("List", m_properties);
config.setGroup("Enable");
config.writeEntry("List", m_explicitEnable);
config.setGroup("Disable");
config.writeEntry("List", m_explicitDisable);
config.sync();
}
Profile::EntryList Profile::list(List type)
{
EntryList parentList;
if (m_parent)
parentList = m_parent->list(type);
EntryList list = parentList;
for (EntryList::iterator it = list.begin(); it != list.end(); ++it)
(*it).derived = true;
TQStringList &personalList = listByType(type);
for (TQStringList::const_iterator it = personalList.begin(); it != personalList.end(); ++it)
list.append(Entry(*it, false));
return list;
}
void Profile::addEntry(List type, const TQString &value)
{
TQStringList &list = listByType(type);
if (!list.contains(value))
list.append(value);
}
void Profile::removeEntry(List type, const TQString &value)
{
TQStringList &list = listByType(type);
list.remove(value);
}
void Profile::clearList( List type )
{
switch (type)
{
case Properties:
m_properties.clear();
case ExplicitEnable:
m_explicitEnable.clear();
case ExplicitDisable:
m_explicitDisable.clear();
}
}
TQStringList &Profile::listByType(List type)
{
switch (type) {
case Properties:
return m_properties;
case ExplicitEnable:
return m_explicitEnable;
case ExplicitDisable:
default:
return m_explicitDisable;
}
}
bool Profile::hasInEntryList(EntryList &list, TQString value)
{
for (EntryList::const_iterator it = list.constBegin(); it != list.constEnd(); ++it)
if ((*it).name == value)
return true;
return false;
}
bool Profile::remove()
{
TQStringList dirs = TDEGlobal::dirs()->findDirs("data", "tdevelop/profiles" + dirName());
if ((dirs.count() == 1) && dirs[0].startsWith(TQDir::homeDirPath()))
return TDEIO::NetAccess::del(KURL::fromPathOrURL(dirs[0]), 0);
return false;
}
void Profile::detachFromParent()
{
if (m_parent)
m_parent->removeChildProfile(this);
}
KURL::List Profile::resources(const TQString &nameFilter)
{
TQStringList resources;
TQStringList resourceDirs = TDEGlobal::dirs()->resourceDirs("data");
for (TQStringList::const_iterator it = resourceDirs.begin(); it != resourceDirs.end(); ++it)
{
TQString dir = *it;
dir = dir + "tdevelop/profiles" + dirName();
TQDir d(dir);
const TQFileInfoList *infoList = d.entryInfoList(nameFilter, TQDir::Files);
if (!infoList)
continue;
for (TQFileInfoList::const_iterator infoIt = infoList->constBegin();
infoIt != infoList->constEnd(); ++ infoIt)
resources.append((*infoIt)->absFilePath());
}
return KURL::List(resources);
}
void Profile::addResource(const KURL &url)
{
TQString saveLocation = TDEGlobal::dirs()->saveLocation("data", "tdevelop/profiles"+dirName(), true);
TDEIO::NetAccess::file_copy(url, KURL::fromPathOrURL(saveLocation), -1, true);
}
|