• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepimlibs API Reference
  • KDE Home
  • Contact Us
 

kresources

  • sources
  • kde-4.12
  • kdepimlibs
  • kresources
resource.cpp
1 /*
2  This file is part of libkresources.
3 
4  Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
5  Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org>
6  Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Library General Public
10  License as published by the Free Software Foundation; either
11  version 2 of the License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Library General Public License for more details.
17 
18  You should have received a copy of the GNU Library General Public License
19  along with this library; see the file COPYING.LIB. If not, write to
20  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  Boston, MA 02110-1301, USA.
22 */
23 
24 #include "resource.h"
25 
26 #include <kdebug.h>
27 #include <krandom.h>
28 #include <kconfig.h>
29 #include <klocalizedstring.h>
30 #include <kconfiggroup.h>
31 
32 using namespace KRES;
33 
34 class Resource::ResourcePrivate
35 {
36  public:
37 #ifdef QT_THREAD_SUPPORT
38  QMutex mMutex;
39 #endif
40  int mOpenCount;
41  QString mType;
42  QString mIdentifier;
43  bool mReadOnly;
44  QString mName;
45  bool mActive;
46  bool mIsOpen;
47 };
48 
49 /*
50 Resource::Resource( const KConfig* config )
51  : QObject( 0 ), d( new ResourcePrivate )
52 {
53  d->mOpenCount = 0;
54  d->mIsOpen = false;
55 
56  if ( config ) {
57  d->mType = config->readEntry( "ResourceType" );
58  d->mName = config->readEntry( "ResourceName" );
59  d->mReadOnly = config->readEntry("ResourceIsReadOnly", false);
60  d->mActive = config->readEntry("ResourceIsActive", true);
61  d->mIdentifier = config->readEntry( "ResourceIdentifier" );
62  } else {
63  d->mType = "type";
64  d->mName = i18n("resource");
65  d->mReadOnly = false;
66  d->mActive = true;
67  d->mIdentifier = KRandom::randomString( 10 );
68  }
69 }
70 */
71 
72 Resource::Resource()
73  : QObject( 0 ), d( new ResourcePrivate )
74 {
75  d->mOpenCount = 0;
76  d->mIsOpen = false;
77 
78  d->mType = QLatin1String("type");
79  d->mName = i18n( "resource" );
80  d->mReadOnly = false;
81  d->mActive = true;
82  d->mIdentifier = KRandom::randomString( 10 );
83 }
84 
85 Resource::Resource( const KConfigGroup &group )
86  : QObject( 0 ), d( new ResourcePrivate )
87 {
88  d->mOpenCount = 0;
89  d->mIsOpen = false;
90 
91  d->mType = group.readEntry( "ResourceType" );
92  d->mName = group.readEntry( "ResourceName" );
93  d->mReadOnly = group.readEntry( "ResourceIsReadOnly", false );
94  d->mActive = group.readEntry( "ResourceIsActive", true );
95  d->mIdentifier = group.readEntry( "ResourceIdentifier" );
96 }
97 
98 Resource::~Resource()
99 {
100  delete d;
101 }
102 
103 void Resource::writeConfig( KConfigGroup &group )
104 {
105  kDebug();
106 
107  group.writeEntry( "ResourceType", d->mType );
108  group.writeEntry( "ResourceName", d->mName );
109  group.writeEntry( "ResourceIsReadOnly", d->mReadOnly );
110  group.writeEntry( "ResourceIsActive", d->mActive );
111  group.writeEntry( "ResourceIdentifier", d->mIdentifier );
112 }
113 
114 bool Resource::open()
115 {
116  d->mIsOpen = true;
117 #ifdef QT_THREAD_SUPPORT
118  QMutexLocker guard( &( d->mMutex ) );
119 #endif
120  if ( !d->mOpenCount ) {
121  kDebug() << "Opening resource" << resourceName();
122  d->mIsOpen = doOpen();
123  }
124  d->mOpenCount++;
125  return d->mIsOpen;
126 }
127 
128 void Resource::close()
129 {
130 #ifdef QT_THREAD_SUPPORT
131  QMutexLocker guard( &( d->mMutex ) );
132 #endif
133  if ( !d->mOpenCount ) {
134  kDebug() << "ERROR: Resource" << resourceName()
135  << " closed more times than previously opened";
136  return;
137  }
138  d->mOpenCount--;
139  if ( !d->mOpenCount ) {
140  kDebug() << "Closing resource" << resourceName();
141  doClose();
142  d->mIsOpen = false;
143  } else {
144  kDebug() << "Not yet closing resource" << resourceName()
145  << ", open count =" << d->mOpenCount;
146  }
147 }
148 
149 bool Resource::isOpen() const
150 {
151  return d->mIsOpen;
152 }
153 
154 void Resource::setIdentifier( const QString &identifier )
155 {
156  d->mIdentifier = identifier;
157 }
158 
159 QString Resource::identifier() const
160 {
161  return d->mIdentifier;
162 }
163 
164 void Resource::setType( const QString &type )
165 {
166  d->mType = type;
167 }
168 
169 QString Resource::type() const
170 {
171  return d->mType;
172 }
173 
174 void Resource::setReadOnly( bool value )
175 {
176  d->mReadOnly = value;
177 }
178 
179 bool Resource::readOnly() const
180 {
181  return d->mReadOnly;
182 }
183 
184 void Resource::setResourceName( const QString &name )
185 {
186  d->mName = name;
187 }
188 
189 QString Resource::resourceName() const
190 {
191  return d->mName;
192 }
193 
194 void Resource::setActive( bool value )
195 {
196  d->mActive = value;
197 }
198 
199 bool Resource::isActive() const
200 {
201  return d->mActive;
202 }
203 
204 void Resource::dump() const
205 {
206  kDebug() << "Resource:";
207  kDebug() << " Name:" << d->mName;
208  kDebug() << " Identifier:" << d->mIdentifier;
209  kDebug() << " Type:" << d->mType;
210  kDebug() << " OpenCount:" << d->mOpenCount;
211  kDebug() << " ReadOnly:" << ( d->mReadOnly ? "yes" : "no" );
212  kDebug() << " Active:" << ( d->mActive ? "yes" : "no" );
213  kDebug() << " IsOpen:" << ( d->mIsOpen ? "yes" : "no" );
214 }
215 
216 bool Resource::doOpen()
217 {
218  return true;
219 }
220 
221 void Resource::doClose()
222 {
223 }
224 
225 QObject *PluginFactoryBase::createObject( QObject *parent,
226  const char *className,
227  const QStringList &args )
228 {
229  Q_UNUSED( parent );
230  Q_UNUSED( className );
231  Q_UNUSED( args );
232  return 0;
233 }
234 
KRES::Resource::writeConfig
virtual void writeConfig(KConfigGroup &group)
Write configuration information for this resource to a configuration file.
Definition: resource.cpp:103
KRES::Resource::doClose
virtual void doClose()
Close this resource.
Definition: resource.cpp:221
KRES::Resource::Resource
Resource()
Constructor.
Definition: resource.cpp:72
KRES::Resource::open
bool open()
Open this resource, if it not already open.
Definition: resource.cpp:114
KRES::Resource::dump
virtual void dump() const
Print resource information as debug output.
Definition: resource.cpp:204
KRES::Resource::setType
void setType(const QString &type)
Sets the resource type.
Definition: resource.cpp:164
KRES::Resource::~Resource
virtual ~Resource()
Destructor.
Definition: resource.cpp:98
KRES::Resource::setIdentifier
void setIdentifier(const QString &identifier)
Sets the resource unique identifier.
Definition: resource.cpp:154
KRES::Resource::identifier
QString identifier() const
Returns a unique identifier.
Definition: resource.cpp:159
KRES::Resource::isActive
bool isActive() const
Return true, if the resource is active.
Definition: resource.cpp:199
KRES::Resource::type
QString type() const
Returns the type of this resource.
Definition: resource.cpp:169
KRES::Resource::readOnly
virtual bool readOnly() const
Returns, if the resource is read-only.
Definition: resource.cpp:179
KRES::Resource::setResourceName
virtual void setResourceName(const QString &name)
Set the name of resource.
Definition: resource.cpp:184
KRES::Resource::resourceName
virtual QString resourceName() const
Returns the name of resource.
Definition: resource.cpp:189
KRES::Resource::setActive
void setActive(bool active)
Sets, if the resource is active.
Definition: resource.cpp:194
KRES::Resource::isOpen
bool isOpen() const
Returns whether the resource is open or not.
Definition: resource.cpp:149
KRES::Resource::doOpen
virtual bool doOpen()
Open this resource.
Definition: resource.cpp:216
KRES::Resource::setReadOnly
virtual void setReadOnly(bool value)
Mark the resource as read-only.
Definition: resource.cpp:174
KRES::Resource::close
void close()
Decrease the open count of this object, and if the count reaches zero, close this resource by calling...
Definition: resource.cpp:128
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:00:19 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kresources

Skip menu "kresources"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Related Pages

kdepimlibs API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal