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

tderesources

  • tderesources
factory.cpp
1 /*
2  This file is part of libtderesources.
3 
4  Copyright (c) 2002 Tobias Koenig <tokoe@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 <tdelocale.h>
26 #include <ksimpleconfig.h>
27 #include <kstandarddirs.h>
28 #include <kstaticdeleter.h>
29 
30 #include <tqfile.h>
31 
32 #include "resource.h"
33 #include "factory.h"
34 
35 using namespace KRES;
36 
37 TQDict<Factory> *Factory::mSelves = 0;
38 static KStaticDeleter< TQDict<Factory> > staticDeleter;
39 
40 Factory *Factory::self( const TQString& resourceFamily )
41 {
42  kdDebug(5650) << "Factory::self()" << endl;
43 
44  Factory *factory = 0;
45  if ( !mSelves )
46  staticDeleter.setObject( mSelves, new TQDict<Factory> );
47 
48  factory = mSelves->find( resourceFamily );
49 
50  if ( !factory ) {
51  factory = new Factory( resourceFamily );
52  mSelves->insert( resourceFamily, factory );
53  }
54 
55  return factory;
56 }
57 
58 Factory::Factory( const TQString& resourceFamily ) :
59  mResourceFamily( resourceFamily )
60 {
61  TDETrader::OfferList plugins = TDETrader::self()->query( "TDEResources/Plugin", TQString( "[X-TDE-ResourceFamily] == '%1'" )
62  .arg( resourceFamily ) );
63  TDETrader::OfferList::ConstIterator it;
64  for ( it = plugins.begin(); it != plugins.end(); ++it ) {
65  TQVariant type = (*it)->property( "X-TDE-ResourceType" );
66  if ( !type.toString().isEmpty() )
67  mTypeMap.insert( type.toString(), *it );
68  }
69 }
70 
71 Factory::~Factory()
72 {
73 }
74 
75 TQStringList Factory::typeNames() const
76 {
77  return mTypeMap.keys();
78 }
79 
80 ConfigWidget *Factory::configWidget( const TQString& type, TQWidget *parent )
81 {
82  if ( type.isEmpty() || !mTypeMap.contains( type ) )
83  return 0;
84 
85  KService::Ptr ptr = mTypeMap[ type ];
86  KLibFactory *factory = KLibLoader::self()->factory( ptr->library().latin1() );
87  if ( !factory ) {
88  kdDebug(5650) << "KRES::Factory::configWidget(): Factory creation failed "
89  << KLibLoader::self()->lastErrorMessage() << endl;
90  return 0;
91  }
92 
93  PluginFactoryBase *pluginFactory = static_cast<PluginFactoryBase *>( factory );
94 
95  if ( !pluginFactory ) {
96  kdDebug(5650) << "KRES::Factory::configWidget(): no plugin factory."
97  << endl;
98  return 0;
99  }
100 
101  ConfigWidget *wdg = pluginFactory->configWidget( parent );
102  if ( !wdg ) {
103  kdDebug(5650) << "'" << ptr->library() << "' doesn't provide a ConfigWidget" << endl;
104  return 0;
105  }
106 
107  return wdg;
108 }
109 
110 TQString Factory::typeName( const TQString &type ) const
111 {
112  if ( type.isEmpty() || !mTypeMap.contains( type ) )
113  return TQString();
114 
115  KService::Ptr ptr = mTypeMap[ type ];
116  return ptr->name();
117 }
118 
119 TQString Factory::typeDescription( const TQString &type ) const
120 {
121  if ( type.isEmpty() || !mTypeMap.contains( type ) )
122  return TQString();
123 
124  KService::Ptr ptr = mTypeMap[ type ];
125  return ptr->comment();
126 }
127 
128 Resource *Factory::resource( const TQString& type, const TDEConfig *config )
129 {
130  kdDebug(5650) << "Factory::resource( " << type << ", config )" << endl;
131 
132  if ( type.isEmpty() || !mTypeMap.contains( type ) ) {
133  kdDebug(5650) << "Factory::resource() no such type " << type << endl;
134  return 0;
135  }
136 
137  KService::Ptr ptr = mTypeMap[ type ];
138  KLibFactory *factory = KLibLoader::self()->factory( ptr->library().latin1() );
139  if ( !factory ) {
140  kdDebug(5650) << "KRES::Factory::resource(): Factory creation failed "
141  << KLibLoader::self()->lastErrorMessage() << endl;
142  return 0;
143  }
144 
145  PluginFactoryBase *pluginFactory = static_cast<PluginFactoryBase *>( factory );
146 
147  if ( !pluginFactory ) {
148  kdDebug(5650) << "KRES::Factory::resource(): no plugin factory." << endl;
149  return 0;
150  }
151 
152  Resource *resource = pluginFactory->resource( config );
153  if ( !resource ) {
154  kdDebug(5650) << "'" << ptr->library() << "' is not a " + mResourceFamily +
155  " plugin." << endl;
156  return 0;
157  }
158 
159  resource->setType( type );
160 
161  return resource;
162 }
KRES::Factory::configWidget
ConfigWidget * configWidget(const TQString &type, TQWidget *parent=0)
Returns the config widget for the given resource type, or a null pointer if resource type doesn't exi...
Definition: factory.cpp:80
KRES::Factory::typeName
TQString typeName(const TQString &type) const
Returns the name for a special type.
Definition: factory.cpp:110
KRES::Factory::typeNames
TQStringList typeNames() const
Returns a list of all available resource types.
Definition: factory.cpp:75
KRES
Definition: configdialog.h:31
KRES::Resource
This class provides a resource which is managed in a general way.
Definition: resource.h:255
KRES::Factory::self
static Factory * self(const TQString &resourceFamily)
Returns the global resource factory.
Definition: factory.cpp:40
KRES::Factory::resource
Resource * resource(const TQString &type, const TDEConfig *config)
Returns a pointer to a resource object or a null pointer if resource type doesn't exist...
Definition: factory.cpp:128
KRES::Factory::typeDescription
TQString typeDescription(const TQString &type) const
Returns the description for a special type.
Definition: factory.cpp:119
KRES::Factory
Class for loading resource plugins.
Definition: factory.h:62

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
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tderesources by doxygen 1.8.8
This website is maintained by Timothy Pearson.