• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tderesources
 

tderesources

  • tderesources
resource.cpp
1/*
2 This file is part of libtderesources.
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 <kdebug.h>
25#include <tdeapplication.h>
26#include <tdeconfig.h>
27#include <tdelocale.h>
28#include "resource.h"
29
30using namespace KRES;
31
32class Resource::ResourcePrivate
33{
34 public:
35#ifdef TQT_THREAD_SUPPORT
36 TQMutex mMutex;
37#endif
38 int mOpenCount;
39 TQString mType;
40 TQString mIdentifier;
41 bool mReadOnly;
42 TQString mName;
43 bool mActive;
44 bool mIsOpen;
45};
46
47Resource::Resource( const TDEConfig* config )
48 : TQObject( 0, "" ), d( new ResourcePrivate )
49{
50 d->mOpenCount = 0;
51 d->mIsOpen = false;
52
53 if ( config ) {
54 d->mType = config->readEntry( "ResourceType" );
55 d->mName = config->readEntry( "ResourceName" );
56 d->mReadOnly = config->readBoolEntry( "ResourceIsReadOnly", false );
57 d->mActive = config->readBoolEntry( "ResourceIsActive", true );
58 d->mIdentifier = config->readEntry( "ResourceIdentifier" );
59 } else {
60 d->mType = "type";
61 d->mName = i18n("resource");
62 d->mReadOnly = false;
63 d->mActive = true;
64 d->mIdentifier = TDEApplication::randomString( 10 );
65 }
66}
67
68Resource::~Resource()
69{
70 delete d;
71 d = 0;
72}
73
74void Resource::writeConfig( TDEConfig* config )
75{
76 kdDebug(5650) << "Resource::writeConfig()" << endl;
77
78 config->writeEntry( "ResourceType", d->mType );
79 config->writeEntry( "ResourceName", d->mName );
80 config->writeEntry( "ResourceIsReadOnly", d->mReadOnly );
81 config->writeEntry( "ResourceIsActive", d->mActive );
82 config->writeEntry( "ResourceIdentifier", d->mIdentifier );
83}
84
85bool Resource::open()
86{
87 d->mIsOpen = true;
88#ifdef TQT_THREAD_SUPPORT
89 TQMutexLocker guard( &(d->mMutex) );
90#endif
91 if ( !d->mOpenCount ) {
92 kdDebug(5650) << "Opening resource " << resourceName() << endl;
93 d->mIsOpen = doOpen();
94 }
95 d->mOpenCount++;
96 return d->mIsOpen;
97}
98
99void Resource::close()
100{
101#ifdef TQT_THREAD_SUPPORT
102 TQMutexLocker guard( &(d->mMutex) );
103#endif
104 if ( !d->mOpenCount ) {
105 kdDebug(5650) << "ERROR: Resource " << resourceName() << " closed more times than previously opened" << endl;
106 return;
107 }
108 d->mOpenCount--;
109 if ( !d->mOpenCount ) {
110 kdDebug(5650) << "Closing resource " << resourceName() << endl;
111 doClose();
112 d->mIsOpen = false;
113 } else {
114 kdDebug(5650) << "Not yet closing resource " << resourceName() << ", open count = " << d->mOpenCount << endl;
115 }
116}
117
118bool Resource::isOpen() const
119{
120 return d->mIsOpen;
121}
122
123void Resource::setIdentifier( const TQString& identifier )
124{
125 d->mIdentifier = identifier;
126}
127
128TQString Resource::identifier() const
129{
130 return d->mIdentifier;
131}
132
133void Resource::setType( const TQString& type )
134{
135 d->mType = type;
136}
137
138TQString Resource::type() const
139{
140 return d->mType;
141}
142
143void Resource::setReadOnly( bool value )
144{
145 d->mReadOnly = value;
146}
147
148bool Resource::readOnly() const
149{
150 return d->mReadOnly;
151}
152
153void Resource::setResourceName( const TQString &name )
154{
155 d->mName = name;
156}
157
158TQString Resource::resourceName() const
159{
160 return d->mName;
161}
162
163void Resource::setActive( bool value )
164{
165 d->mActive = value;
166}
167
168bool Resource::isActive() const
169{
170 return d->mActive;
171}
172
173void Resource::dump() const
174{
175 kdDebug(5650) << "Resource:" << endl;
176 kdDebug(5650) << " Name: " << d->mName << endl;
177 kdDebug(5650) << " Identifier: " << d->mIdentifier << endl;
178 kdDebug(5650) << " Type: " << d->mType << endl;
179 kdDebug(5650) << " OpenCount: " << d->mOpenCount << endl;
180 kdDebug(5650) << " ReadOnly: " << ( d->mReadOnly ? "yes" : "no" ) << endl;
181 kdDebug(5650) << " Active: " << ( d->mActive ? "yes" : "no" ) << endl;
182 kdDebug(5650) << " IsOpen: " << ( d->mIsOpen ? "yes" : "no" ) << endl;
183}
184
185#include "resource.moc"
KRES::Resource::setReadOnly
virtual void setReadOnly(bool value)
Mark the resource as read-only.
Definition: resource.cpp:143
KRES::Resource::open
bool open()
Open this resource, if it not already open.
Definition: resource.cpp:85
KRES::Resource::~Resource
virtual ~Resource()
Destructor.
Definition: resource.cpp:68
KRES::Resource::isOpen
bool isOpen() const
Returns whether the resource is open or not.
Definition: resource.cpp:118
KRES::Resource::doClose
virtual void doClose()
Close this resource.
Definition: resource.h:374
KRES::Resource::dump
virtual void dump() const
Print resource information as debug output.
Definition: resource.cpp:173
KRES::Resource::setResourceName
virtual void setResourceName(const TQString &name)
Set the name of resource.
Definition: resource.cpp:153
KRES::Resource::isActive
bool isActive() const
Return true, if the resource is active.
Definition: resource.cpp:168
KRES::Resource::writeConfig
virtual void writeConfig(TDEConfig *config)
Write configuration information for this resource to a configuration file.
Definition: resource.cpp:74
KRES::Resource::type
TQString type() const
Returns the type of this resource.
Definition: resource.cpp:138
KRES::Resource::readOnly
virtual bool readOnly() const
Returns, if the resource is read-only.
Definition: resource.cpp:148
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:99
KRES::Resource::doOpen
virtual bool doOpen()
Open this resource.
Definition: resource.h:368
KRES::Resource::setActive
void setActive(bool active)
Sets, if the resource is active.
Definition: resource.cpp:163
KRES::Resource::identifier
TQString identifier() const
Returns a unique identifier.
Definition: resource.cpp:128
KRES::Resource::resourceName
virtual TQString resourceName() const
Returns the name of resource.
Definition: resource.cpp:158

tderesources

Skip menu "tderesources"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members

tderesources

Skip menu "tderesources"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tderesources by doxygen 1.9.4
This website is maintained by Timothy Pearson.