<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en_US" xml:lang="en_US"> <head> <title>kresources: The KDE Resource library (kresources)</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Style-Type" content="text/css" /> <meta http-equiv="pics-label" content='(pics-1.1 "http://www.icra.org/ratingsv02.html" comment "ICRAonline DE v2.0" l gen true for "http://www.kde.org" r (nz 1 vz 1 lz 1 oz 1 cb 1) "http://www.rsac.org/ratingsv01.html" l gen true for "http://www.kde.org" r (n 0 s 0 v 0 l 0))' /> <meta name="trademark" content="KDE e.V." /> <meta name="description" content="K Desktop Environment Homepage, KDE.org" /> <meta name="MSSmartTagsPreventParsing" content="true" /> <meta name="robots" content="all" /> <link rel="shortcut icon" href="../../favicon.ico" /> <link rel="stylesheet" media="screen" type="text/css" title="APIDOX" href="doxygen.css" /> </head> <body> <div id="nav_header_top" align="right"> <a href="#content" class="doNotDisplay" accesskey="2">Skip to main content ::</a> <a href="../.."><img id="nav_header_logo" alt="Home" align="left" src="../../kde_gear_64.png" border="0" /></a> <span class="doNotDisplay">::</span> <div id="nav_header_title" align="left">KDE API Reference</div> </div> <div id="nav_header_bottom" align="right"> <span class="doNotDisplay">:: <a href="#navigation" accesskey="5">Skip to Link Menu</a><br/></span> <div id="nav_header_bottom_right" style="text-align: left;"> / <a href="../..">API Reference</a> / <a href=".">kresources</a> </div> </div> <table id="main" border="0" cellpadding="0" cellspacing="0" width="100%"> <tr> <td valign="top" class="menuheader" height="0"></td> <td id="contentcolumn" valign="top" rowspan="2" > <div id="content" style="padding-top: 0px;"><div style="width:100%; margin: 0px; padding: 0px;"> <a name="content"></a> <!-- Generated by Doxygen 1.7.4 --> </div> <div class="header"> <div class="headertitle"> <div class="title">The KDE <a class="el" href="classKRES_1_1Resource.html" title="This class provides a resource which is managed in a general way.">Resource</a> library </div> </div> </div> <div class="contents"> <div class="textblock"><p>The KDE <a class="el" href="classKRES_1_1Resource.html" title="This class provides a resource which is managed in a general way.">Resource</a> framework can be used to manage resources of different types, organized in families. The <a class="el" href="classKRES_1_1Resource.html" title="This class provides a resource which is managed in a general way.">Resource</a> framework is for example used for addressbook resources in libkabc and for calendar resources in libkcal.</p> <p>When you want to use the framework for a new family, you need to </p> <ul> <li> Define a name for your resource family </li> <li> subclass <a class="el" href="classKRES_1_1Resource.html" title="This class provides a resource which is managed in a general way.">Resource</a> and add the fields and method that are needed in your application </li> <li> If needed, override the doOpen() and doClose() methods. </li> <li> In your application, you can use ResourceManager to keep track of the resources in your family, and you can use ResourceSelectDialog to let the user select a single resource. </li> </ul> <p>When you want to add a new resource type to an existing resource family, you need to </p> <ul> <li> Further subclass the family-specific <a class="el" href="classKRES_1_1Resource.html" title="This class provides a resource which is managed in a general way.">Resource</a> to implement resource type-specific operation </li> <li> Subclass ResourceConfigWidget to provide a configuration widget for your new resource type </li> <li> Provide a .desktop file so that the new resource type can be found automatically by the ResourceManager </li> </ul> <p>Example:</p> <p><b>resourceexample.h</b>: </p> <div class="fragment"><pre class="fragment"><span class="preprocessor">#include <kconfig.h></span> <span class="preprocessor">#include <kresources/resource.h></span> <span class="keyword">class </span>ResourceExample : <span class="keyword">public</span> KRES::Resource { <span class="keyword">public</span>: ResourceExample( <span class="keyword">const</span> KConfig * ); ~ResourceExample(); <span class="keywordtype">void</span> writeConfig( KConfig *config ); <span class="keyword">private</span>: <a class="codeRef" href="qstring.html">QString</a> mLocation; <a class="codeRef" href="qstring.html">QString</a> mPassword; } </pre></div><p><b>resourceexample.cpp</b>: </p> <div class="fragment"><pre class="fragment"><span class="preprocessor">#include <kconfig.h></span> <span class="preprocessor">#include "resourceexample.h"</span> ResourceExample::ResourceExample( <span class="keyword">const</span> KConfig *config ) : Resource( config ) { <span class="keywordflow">if</span> ( config ) { mLocation = config->readPathEntry( <span class="stringliteral">"Location"</span> ); mPassword = KStringHandler::obscure( config->readEntry( <span class="stringliteral">"Password"</span> ) ); } <span class="keywordflow">else</span> { mLocation = <span class="stringliteral">""</span>; <span class="comment">// Or some sensible default</span> mPassword = <span class="stringliteral">""</span>; } } <span class="keywordtype">void</span> ResourceExample::writeConfig( KConfig *config ) { <a class="code" href="classKRES_1_1Resource.html#a1dd01b89702931d060d87332001e77d4" title="Write configuration information for this resource to a configuration file.">KRES::Resource::writeConfig</a>( config ); config->writePathEntry( <span class="stringliteral">"Location"</span>, mLocation ); config->writeEntry( <span class="stringliteral">"Password"</span>, KStringHandler::obscure( mPassword ) ); } <span class="keyword">extern</span> <span class="stringliteral">"C"</span> { KRES::ResourceExample *config_widget( <a class="codeRef" href="qwidget.html">QWidget</a> *parent ) { <span class="keywordflow">return</span> <span class="keyword">new</span> ResourceExampleConfig( parent, <span class="stringliteral">"Configure Example Resource"</span> ); } <a class="code" href="classKRES_1_1Resource.html" title="This class provides a resource which is managed in a general way.">KRES::Resource</a> *resource( <span class="keyword">const</span> KConfig *config ) { <span class="keywordflow">return</span> <span class="keyword">new</span> ResourceExample( config ); } } </pre></div><p><b>resourceexampleconfig.h</b>: </p> <div class="fragment"><pre class="fragment"><span class="preprocessor">#include <klineedit.h></span> <span class="preprocessor">#include <kresources/resourceconfigwidget.h></span> <span class="preprocessor">#include "resourceexample.h"</span> <span class="keyword">class </span>ResourceExampleConfig : <span class="keyword">public</span> KRES::ResourceConfigWidget { Q_OBJECT <span class="keyword">public</span>: ResourceExampleConfig( <a class="codeRef" href="qwidget.html">QWidget</a> *parent = 0, <span class="keyword">const</span> <span class="keywordtype">char</span> *name = 0 ); <span class="keyword">public</span> slots: <span class="keyword">virtual</span> <span class="keywordtype">void</span> loadSettings( <a class="code" href="classKRES_1_1Resource.html" title="This class provides a resource which is managed in a general way.">KRES::Resource</a> *resource); <span class="keyword">virtual</span> <span class="keywordtype">void</span> saveSettings( <a class="code" href="classKRES_1_1Resource.html" title="This class provides a resource which is managed in a general way.">KRES::Resource</a> *resource ); <span class="keyword">private</span>: KLineEdit *mLocationEdit; KLineEdit *mPasswordEdit; }; </pre></div><p><b>resourceexampleconfig.cpp</b>: </p> <div class="fragment"><pre class="fragment"><span class="preprocessor">#include <qlayout.h></span> <span class="preprocessor">#include <qlabel.h></span> <span class="preprocessor">#include <kresources/resourceconfigwidget.h></span> <span class="preprocessor">#include "resourceexample.h"</span> <span class="preprocessor">#include "resourceexampleconfig.h"</span> ResourceExampleConfig::ResourceExampleConfig( <a class="codeRef" href="qwidget.html">QWidget</a> *parent, <span class="keyword">const</span> <span class="keywordtype">char</span> *name ) : KRES::ResourceConfigWidget( parent, name ) { <a class="codeRef" href="qgridlayout.html">QGridLayout</a> *mainLayout = <span class="keyword">new</span> <a class="codeRef" href="qgridlayout.html">QGridLayout</a>( <span class="keyword">this</span>, 2, 2 ); <a class="codeRef" href="qlabel.html">QLabel</a> *label = <span class="keyword">new</span> <a class="codeRef" href="qlabel.html">QLabel</a>( i18n( <span class="stringliteral">"Location:"</span> ), <span class="keyword">this</span> ); mHostEdit = <span class="keyword">new</span> KLineEdit( <span class="keyword">this</span> ); mainLayout-><a class="codeRef" href="qgridlayout.html#addWidget">addWidget</a>( label, 1, 0 ); mainLayout-><a class="codeRef" href="qgridlayout.html#addWidget">addWidget</a>( mHostEdit, 1, 1 ); label = <span class="keyword">new</span> <a class="codeRef" href="qlabel.html">QLabel</a>( i18n( <span class="stringliteral">"Password:"</span> ), <span class="keyword">this</span> ); mPasswordEdit = <span class="keyword">new</span> KLineEdit( <span class="keyword">this</span> ); mPasswordEdit->setEchoMode( QLineEdit::Password ); mainLayout-><a class="codeRef" href="qgridlayout.html#addWidget">addWidget</a>( label, 2, 0 ); mainLayout-><a class="codeRef" href="qgridlayout.html#addWidget">addWidget</a>( mPasswordEdit, 2, 1 ); } <span class="keywordtype">void</span> ResourceExampleConfig::loadSettings( <a class="code" href="classKRES_1_1Resource.html" title="This class provides a resource which is managed in a general way.">KRES::Resource</a> *resource ) { ResourceExample *res = <span class="keyword">dynamic_cast<</span>ResourceExample *<span class="keyword">></span>( resource ); <span class="keywordflow">if</span> ( res ) { mHostEdit->setText( res->host() ); mPasswordEdit->setText( res->password() ); } <span class="keywordflow">else</span> kdDebug() << <span class="stringliteral">"ERROR: ResourceExampleConfig::loadSettings(): no ResourceExample, cast failed"</span> << endl; } <span class="keywordtype">void</span> ResourceExampleConfig::saveSettings( <a class="code" href="classKRES_1_1Resource.html" title="This class provides a resource which is managed in a general way.">KRES::Resource</a> *resource ) { ResourceExample *res = <span class="keyword">dynamic_cast<</span>ResourceExample *<span class="keyword">></span>( resource ); <span class="keywordflow">if</span> ( res ) { res->setHost( mHostEdit->text() ); res->setPassword( mPasswordEdit->text() ); } <span class="keywordflow">else</span> kdDebug() << <span class="stringliteral">"ERROR: ResourceExampleConfig::saveSettings(): no ResourceExample, cast failed"</span> << endl; } </pre></div><p><b>resourceexample.desktop</b>: </p> <div class="fragment"><pre class="fragment">[Desktop Entry] Type=Service [Misc] Encoding=UTF-8 Name=Example Resource [Plugin] Type=exchange X-KDE-Library=resourceexample </pre></div><p><b>Makefile.am</b> </p> <div class="fragment"><pre class="fragment">kde_module_LTLIBRARIES = resourceexample.la resourceexample_la_SOURCES = resourceexample.cpp resourceexampleconfig.cpp resourceexample_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) resourceexample_la_LIBADD = -lkresources servicedir = $(kde_datadir)/resources/example service_DATA = resourceexample.desktop </pre></div> </div></div> </div></div> </td> </tr> <tr> <td valign="top" id="leftmenu" width="25%"> <a name="navigation"></a> <div class="menu_box"><h2>kresources</h2> <div class="nav_list"> <ul><li><a href="index.html">Main Page</a></li><li><a href="hierarchy.html">Class Hierarchy</a></li><li><a href="classes.html">Alphabetical List</a></li><li><a href="annotated.html">Class List</a></li><li><a href="files.html">File List</a></li><li><a href="functions.html">Class Members</a></li></ul> <!-- <h2>Class Picker</h2> <div style="text-align: center;"> <form name="guideform"> <select name="guidelinks" style="width:100%;" onChange="window.location=document.guideform.guidelinks.options[document.guideform.guidelinks.selectedIndex].value"> <option value="annotated.html">-- Choose --</option> <option value="classKRES_1_1Factory.html">kres::factory</option>, <option value="classKRES_1_1Manager.html">kres::manager</option>, <option value="classKRES_1_1Manager_1_1ActiveIterator.html">kres::manager::activeiterator</option>, <option value="classKRES_1_1Manager_1_1Iterator.html">kres::manager::iterator</option>, <option value="classKRES_1_1ManagerObserver.html">kres::managerobserver</option>, <option value="classKRES_1_1Resource.html">kres::resource</option>, <option value="classKRES_1_1SelectDialog.html">kres::selectdialog</option>, </select> </form> </div> --> </div></div> <div class="menu_box"><h2>API Dox</h2> <div class="nav_list"> <ul> <li><a href="../../arts/html/index.html">arts</a></li><li><a href="../../dcop/html/index.html">dcop</a></li><li><a href="../../dnssd/html/index.html">dnssd</a></li><li><a href="../../interfaces/html/index.html">interfaces</a></li><li> <a href="../../interfaces/kimproxy/interface/html/index.html">interface</a></li><li> <a href="../../interfaces/kimproxy/library/html/index.html">library</a></li><li> <a href="../../interfaces/kspeech/html/index.html">kspeech</a></li><li> <a href="../../interfaces/ktexteditor/html/index.html">ktexteditor</a></li><li><a href="../../kabc/html/index.html">kabc</a></li><li><a href="../../kate/html/index.html">kate</a></li><li><a href="../../kcmshell/html/index.html">kcmshell</a></li><li><a href="../../kdecore/html/index.html">kdecore</a></li><li><a href="../../kded/html/index.html">kded</a></li><li><a href="../../kdefx/html/index.html">kdefx</a></li><li><a href="../../kdeprint/html/index.html">kdeprint</a></li><li><a href="../../kdesu/html/index.html">kdesu</a></li><li><a href="../../kdeui/html/index.html">kdeui</a></li><li><a href="../../kdoctools/html/index.html">kdoctools</a></li><li><a href="../../khtml/html/index.html">khtml</a></li><li><a href="../../kimgio/html/index.html">kimgio</a></li><li><a href="../../kinit/html/index.html">kinit</a></li><li><a href="../../kio/html/index.html">kio</a></li><li> <a href="../../kio/bookmarks/html/index.html">bookmarks</a></li><li> <a href="../../kio/httpfilter/html/index.html">httpfilter</a></li><li> <a href="../../kio/kfile/html/index.html">kfile</a></li><li> <a href="../../kio/kio/html/index.html">kio</a></li><li> <a href="../../kio/kioexec/html/index.html">kioexec</a></li><li> <a href="../../kio/kpasswdserver/html/index.html">kpasswdserver</a></li><li> <a href="../../kio/kssl/html/index.html">kssl</a></li><li><a href="../../kioslave/html/index.html">kioslave</a></li><li> <a href="../../kioslave/http/html/index.html">http</a></li><li><a href="../../kjs/html/index.html">kjs</a></li><li><a href="../../kmdi/html/index.html">kmdi</a></li><li> <a href="../../kmdi/kmdi/html/index.html">kmdi</a></li><li><a href="../../knewstuff/html/index.html">knewstuff</a></li><li><a href="../../kparts/html/index.html">kparts</a></li><li><a href="../../kresources/html/index.html">kresources</a></li><li><a href="../../kspell2/html/index.html">kspell2</a></li><li><a href="../../kunittest/html/index.html">kunittest</a></li><li><a href="../../kutils/html/index.html">kutils</a></li><li><a href="../../kwallet/html/index.html">kwallet</a></li><li><a href="../../libkmid/html/index.html">libkmid</a></li><li><a href="../../libkscreensaver/html/index.html">libkscreensaver</a></li> </ul></div></div> </td> </tr> </table> <span class="doNotDisplay"> <a href="http://www.kde.org/" accesskey="8">KDE Home</a> | <a href="http://accessibility.kde.org/" accesskey="9">KDE Accessibility Home</a> | <a href="http://www.kde.org/media/accesskeys.php" accesskey="0">Description of Access Keys</a> </span> <div style="height: 8px"></div> <div id="footer"> <div id="footer_left"> Maintained by <a href="mailto:groot@kde.org">Adriaan de Groot</a> and <a href="mailto:winter@kde.org">Allen Winter</a>. <br/> KDE and K Desktop Environment are trademarks of <a href="http://www.kde.org/areas/kde-ev/" title="Homepage of the KDE non-profit Organization">KDE e.V.</a> | <a href="http://www.kde.org/contact/impressum.php">Legal</a> </div> <div id="footer_right"><img src="/media/images/footer_right.png" style="margin: 0px" alt="" /></div> </div> <!-- WARNING: DO NOT SEND MAIL TO THE FOLLOWING EMAIL ADDRESS! YOU WILL BE BLOCKED INSTANTLY AND PERMANENTLY! <a href="mailto:aaaatrap-425acc3b5374943f@kde.org">Block me</a> WARNING END --> </body> </html>