• Skip to content
  • Skip to link menu
KDE 4.0 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • Sitemap
  • Contact Us
 

kresources

resource.cpp

00001 /*
00002     This file is part of libkresources.
00003 
00004     Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
00005     Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org>
00006     Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
00007 
00008     This library is free software; you can redistribute it and/or
00009     modify it under the terms of the GNU Library General Public
00010     License as published by the Free Software Foundation; either
00011     version 2 of the License, or (at your option) any later version.
00012 
00013     This library is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016     Library General Public License for more details.
00017 
00018     You should have received a copy of the GNU Library General Public License
00019     along with this library; see the file COPYING.LIB.  If not, write to
00020     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00021     Boston, MA 02110-1301, USA.
00022 */
00023 
00024 #include "resource.h"
00025 #include <kdebug.h>
00026 #include <krandom.h>
00027 #include <kconfig.h>
00028 #include <klocale.h>
00029 #include <kconfiggroup.h>
00030 
00031 using namespace KRES;
00032 
00033 class Resource::ResourcePrivate
00034 {
00035   public:
00036 #ifdef QT_THREAD_SUPPORT
00037     QMutex mMutex;
00038 #endif
00039     int mOpenCount;
00040     QString mType;
00041     QString mIdentifier;
00042     bool mReadOnly;
00043     QString mName;
00044     bool mActive;
00045     bool mIsOpen;
00046 };
00047 
00048 /*
00049 Resource::Resource( const KConfig* config )
00050   : QObject( 0 ), d( new ResourcePrivate )
00051 {
00052   d->mOpenCount = 0;
00053   d->mIsOpen = false;
00054 
00055   if ( config ) {
00056     d->mType = config->readEntry( "ResourceType" );
00057     d->mName = config->readEntry( "ResourceName" );
00058     d->mReadOnly = config->readEntry("ResourceIsReadOnly", false);
00059     d->mActive = config->readEntry("ResourceIsActive", true);
00060     d->mIdentifier = config->readEntry( "ResourceIdentifier" );
00061   } else {
00062     d->mType = "type";
00063     d->mName = i18n("resource");
00064     d->mReadOnly = false;
00065     d->mActive = true;
00066     d->mIdentifier = KRandom::randomString( 10 );
00067   }
00068 }
00069 */
00070 
00071 Resource::Resource()
00072   : QObject( 0 ), d( new ResourcePrivate )
00073 {
00074   d->mOpenCount = 0;
00075   d->mIsOpen = false;
00076 
00077   d->mType = "type";
00078   d->mName = i18n( "resource" );
00079   d->mReadOnly = false;
00080   d->mActive = true;
00081   d->mIdentifier = KRandom::randomString( 10 );
00082 }
00083 
00084 Resource::Resource( const KConfigGroup &group )
00085   : QObject( 0 ), d( new ResourcePrivate )
00086 {
00087   d->mOpenCount = 0;
00088   d->mIsOpen = false;
00089 
00090   d->mType = group.readEntry( "ResourceType" );
00091   d->mName = group.readEntry( "ResourceName" );
00092   d->mReadOnly = group.readEntry( "ResourceIsReadOnly", false );
00093   d->mActive = group.readEntry( "ResourceIsActive", true );
00094   d->mIdentifier = group.readEntry( "ResourceIdentifier" );
00095 }
00096 
00097 Resource::~Resource()
00098 {
00099   delete d;
00100 }
00101 
00102 void Resource::writeConfig( KConfigGroup &group )
00103 {
00104   kDebug(5650) << "Resource::writeConfig()";
00105 
00106   group.writeEntry( "ResourceType", d->mType );
00107   group.writeEntry( "ResourceName", d->mName );
00108   group.writeEntry( "ResourceIsReadOnly", d->mReadOnly );
00109   group.writeEntry( "ResourceIsActive", d->mActive );
00110   group.writeEntry( "ResourceIdentifier", d->mIdentifier );
00111 }
00112 
00113 bool Resource::open()
00114 {
00115   d->mIsOpen = true;
00116 #ifdef QT_THREAD_SUPPORT
00117   QMutexLocker guard( &(d->mMutex) );
00118 #endif
00119   if ( !d->mOpenCount ) {
00120     kDebug(5650) << "Opening resource" << resourceName();
00121     d->mIsOpen = doOpen();
00122   }
00123   d->mOpenCount++;
00124   return d->mIsOpen;
00125 }
00126 
00127 void Resource::close()
00128 {
00129 #ifdef QT_THREAD_SUPPORT
00130   QMutexLocker guard( &(d->mMutex) );
00131 #endif
00132   if ( !d->mOpenCount ) {
00133     kDebug(5650) << "ERROR: Resource" << resourceName()
00134                  << "closed more times than previously opened";
00135     return;
00136   }
00137   d->mOpenCount--;
00138   if ( !d->mOpenCount ) {
00139     kDebug(5650) << "Closing resource" << resourceName();
00140     doClose();
00141     d->mIsOpen = false;
00142   } else {
00143     kDebug(5650) << "Not yet closing resource" << resourceName()
00144                  << ", open count =" << d->mOpenCount;
00145   }
00146 }
00147 
00148 bool Resource::isOpen() const
00149 {
00150   return d->mIsOpen;
00151 }
00152 
00153 void Resource::setIdentifier( const QString& identifier )
00154 {
00155   d->mIdentifier = identifier;
00156 }
00157 
00158 QString Resource::identifier() const
00159 {
00160   return d->mIdentifier;
00161 }
00162 
00163 void Resource::setType( const QString& type )
00164 {
00165   d->mType = type;
00166 }
00167 
00168 QString Resource::type() const
00169 {
00170   return d->mType;
00171 }
00172 
00173 void Resource::setReadOnly( bool value )
00174 {
00175   d->mReadOnly = value;
00176 }
00177 
00178 bool Resource::readOnly() const
00179 {
00180   return d->mReadOnly;
00181 }
00182 
00183 void Resource::setResourceName( const QString &name )
00184 {
00185   d->mName = name;
00186 }
00187 
00188 QString Resource::resourceName() const
00189 {
00190   return d->mName;
00191 }
00192 
00193 void Resource::setActive( bool value )
00194 {
00195   d->mActive = value;
00196 }
00197 
00198 bool Resource::isActive() const
00199 {
00200   return d->mActive;
00201 }
00202 
00203 void Resource::dump() const
00204 {
00205   kDebug(5650) << "Resource:";
00206   kDebug(5650) << "  Name:" << d->mName;
00207   kDebug(5650) << "  Identifier:" << d->mIdentifier;
00208   kDebug(5650) << "  Type:" << d->mType;
00209   kDebug(5650) << "  OpenCount:" << d->mOpenCount;
00210   kDebug(5650) << "  ReadOnly:" << ( d->mReadOnly ? "yes" : "no" );
00211   kDebug(5650) << "  Active:" << ( d->mActive ? "yes" : "no" );
00212   kDebug(5650) << "  IsOpen:" << ( d->mIsOpen ? "yes" : "no" );
00213 }
00214 
00215 bool Resource::doOpen()
00216 {
00217   return true;
00218 }
00219 
00220 void Resource::doClose()
00221 {
00222 }
00223 
00224 QObject *PluginFactoryBase::createObject( QObject *parent,
00225                                           const char *className,
00226                                           const QStringList &args )
00227 {
00228   Q_UNUSED( parent );
00229   Q_UNUSED( className );
00230   Q_UNUSED( args );
00231   return 0;
00232 }
00233 
00234 #include "resource.moc"

kresources

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

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • kabc
  • kblog
  • kcal
  • kimap
  • kioslave
  •   imap4
  •   mbox
  • kldap
  • kmime
  • kpimidentities
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.5.5
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal