• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • KDevelop Shell Profiles Library
 

KDevelop Shell Profiles Library

  • src
  • profileengine
  • lib
profile.cpp
1 /***************************************************************************
2  * Copyright (C) 2004 by Alexander Dymo <adymo@kdevelop.org> *
3  * *
4  * This program is free software; you can redistribute it and/or modify *
5  * it under the terms of the GNU Library General Public License as *
6  * published by the Free Software Foundation; either version 2 of the *
7  * License, or (at your option) any later version. *
8  * *
9  * This program 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 *
12  * GNU General Public License for more details. *
13  * *
14  * You should have received a copy of the GNU Library General Public *
15  * License along with this program; if not, write to the *
16  * Free Software Foundation, Inc., *
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18  ***************************************************************************/
19 #include "profile.h"
20 
21 #include <tqdir.h>
22 #include <tqfileinfo.h>
23 
24 #include <kdebug.h>
25 #include <kstandarddirs.h>
26 #include <tdeconfig.h>
27 #include <tdeio/netaccess.h>
28 
29 Profile::Profile(Profile *parent, const TQString &name)
30  :m_parent(parent), m_name(name)
31 {
32  if (m_parent)
33  m_parent->addChildProfile(this);
34 
35  TQString profileConfig = locate("data", "tdevelop/profiles" + dirName() + "/profile.config");
36  TDEConfig config(profileConfig);
37 
38  config.setGroup("Information");
39  m_genericName = config.readEntry("GenericName");
40  m_description = config.readEntry("Description");
41 
42  config.setGroup("Properties");
43  m_properties = config.readListEntry("List");
44 
45  config.setGroup("Enable");
46  m_explicitEnable = config.readListEntry("List");
47 
48  config.setGroup("Disable");
49  m_explicitDisable = config.readListEntry("List");
50 }
51 
52 Profile::Profile(Profile *parent, const TQString &name, const TQString &genericName, const TQString &description)
53  :m_parent(parent), m_name(name), m_genericName(genericName), m_description(description)
54 {
55  if (m_parent)
56  m_parent->addChildProfile(this);
57  save();
58 }
59 
60 Profile::~Profile()
61 {
62  for (TQValueList<Profile*>::iterator it = m_children.begin(); it != m_children.end(); ++it)
63  delete *it;
64 }
65 
66 void Profile::addChildProfile(Profile *profile)
67 {
68  m_children.append(profile);
69 }
70 
71 void Profile::removeChildProfile(Profile *profile)
72 {
73  m_children.remove(profile);
74 }
75 
76 TQString Profile::dirName() const
77 {
78  if (m_parent)
79  return m_parent->dirName() + "/" + m_name;
80  else
81  return "/"/* + m_name*/;
82 }
83 
84 void Profile::save()
85 {
86  TQString profileConfig = locateLocal("data", "tdevelop/profiles" + dirName() + "/profile.config");
87  TDEConfig config(profileConfig);
88 
89  config.setGroup("Information");
90  config.writeEntry("GenericName", m_genericName);
91  config.writeEntry("Description", m_description);
92 
93  config.setGroup("Properties");
94  config.writeEntry("List", m_properties);
95 
96  config.setGroup("Enable");
97  config.writeEntry("List", m_explicitEnable);
98 
99  config.setGroup("Disable");
100  config.writeEntry("List", m_explicitDisable);
101 
102  config.sync();
103 }
104 
105 Profile::EntryList Profile::list(List type)
106 {
107  EntryList parentList;
108  if (m_parent)
109  parentList = m_parent->list(type);
110  EntryList list = parentList;
111  for (EntryList::iterator it = list.begin(); it != list.end(); ++it)
112  (*it).derived = true;
113  TQStringList &personalList = listByType(type);
114  for (TQStringList::const_iterator it = personalList.begin(); it != personalList.end(); ++it)
115  list.append(Entry(*it, false));
116  return list;
117 }
118 
119 void Profile::addEntry(List type, const TQString &value)
120 {
121  TQStringList &list = listByType(type);
122  if (!list.contains(value))
123  list.append(value);
124 }
125 
126 void Profile::removeEntry(List type, const TQString &value)
127 {
128  TQStringList &list = listByType(type);
129  list.remove(value);
130 }
131 
132 void Profile::clearList( List type )
133 {
134  switch (type)
135  {
136  case Properties:
137  m_properties.clear();
138  case ExplicitEnable:
139  m_explicitEnable.clear();
140  case ExplicitDisable:
141  m_explicitDisable.clear();
142  }
143 }
144 
145 TQStringList &Profile::listByType(List type)
146 {
147  switch (type) {
148  case Properties:
149  return m_properties;
150  case ExplicitEnable:
151  return m_explicitEnable;
152  case ExplicitDisable:
153  default:
154  return m_explicitDisable;
155  }
156 }
157 
158 bool Profile::hasInEntryList(EntryList &list, TQString value)
159 {
160  for (EntryList::const_iterator it = list.constBegin(); it != list.constEnd(); ++it)
161  if ((*it).name == value)
162  return true;
163  return false;
164 }
165 
166 bool Profile::remove()
167 {
168  TQStringList dirs = TDEGlobal::dirs()->findDirs("data", "tdevelop/profiles" + dirName());
169  if ((dirs.count() == 1) && dirs[0].startsWith(TQDir::homeDirPath()))
170  return TDEIO::NetAccess::del(KURL::fromPathOrURL(dirs[0]), 0);
171  return false;
172 }
173 
174 void Profile::detachFromParent()
175 {
176  if (m_parent)
177  m_parent->removeChildProfile(this);
178 }
179 
180 KURL::List Profile::resources(const TQString &nameFilter)
181 {
182  TQStringList resources;
183  TQStringList resourceDirs = TDEGlobal::dirs()->resourceDirs("data");
184  for (TQStringList::const_iterator it = resourceDirs.begin(); it != resourceDirs.end(); ++it)
185  {
186  TQString dir = *it;
187  dir = dir + "tdevelop/profiles" + dirName();
188 
189  TQDir d(dir);
190  const TQFileInfoList *infoList = d.entryInfoList(nameFilter, TQDir::Files);
191  if (!infoList)
192  continue;
193  for (TQFileInfoList::const_iterator infoIt = infoList->constBegin();
194  infoIt != infoList->constEnd(); ++ infoIt)
195  resources.append((*infoIt)->absFilePath());
196  }
197 
198  return KURL::List(resources);
199 }
200 
201 void Profile::addResource(const KURL &url)
202 {
203  TQString saveLocation = TDEGlobal::dirs()->saveLocation("data", "tdevelop/profiles"+dirName(), true);
204  TDEIO::NetAccess::file_copy(url, KURL::fromPathOrURL(saveLocation), -1, true);
205 }
Profile::List
List
Lists which are held by a profile.
Definition: profile.h:42
Profile::Properties
X-TDevelop-Properties defined for this profile.
Definition: profile.h:43
Profile::ExplicitDisable
A list of explicitly disabled plugins (names).
Definition: profile.h:45
Profile::ExplicitEnable
A list of explicitly enabled plugins (names).
Definition: profile.h:44
Profile
KDevelop profile.
Definition: profile.h:30

KDevelop Shell Profiles Library

Skip menu "KDevelop Shell Profiles Library"
  • Main Page
  • Alphabetical List
  • Class List
  • File List
  • Class Members

KDevelop Shell Profiles Library

Skip menu "KDevelop Shell Profiles Library"
  • buildtools
  •   lib
  •     base
  •     parsers
  •       autotools
  •       qmake
  •     widgets
  •   api
  • languages
  •   lib
  •     debugger
  •     designer_integration
  •     interfaces
  • lib
  •   catalog
  •   interfaces
  •     extensions
  •     external
  •     extras
  •   util
  •   widgets
  •     propeditor
  • parts
  •   documentation
  •     interfaces
  • src
  •   profileengine
  •     lib
Generated for KDevelop Shell Profiles Library by doxygen 1.8.13
This website is maintained by Timothy Pearson.