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

tdeabc

  • tdeabc
formatfactory.cpp
1 /*
2  This file is part of libtdeabc.
3  Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 
21 #include <kdebug.h>
22 #include <tdelocale.h>
23 #include <ksimpleconfig.h>
24 #include <kstandarddirs.h>
25 #include <kstaticdeleter.h>
26 
27 #include <tqfile.h>
28 
29 #include "vcardformatplugin.h"
30 
31 #include "formatfactory.h"
32 
33 using namespace TDEABC;
34 
35 FormatFactory *FormatFactory::mSelf = 0;
36 static KStaticDeleter<FormatFactory> factoryDeleter;
37 
38 FormatFactory *FormatFactory::self()
39 {
40  kdDebug(5700) << "FormatFactory::self()" << endl;
41 
42  if ( !mSelf )
43  factoryDeleter.setObject( mSelf, new FormatFactory );
44 
45  return mSelf;
46 }
47 
48 FormatFactory::FormatFactory()
49 {
50  mFormatList.setAutoDelete( true );
51 
52  // dummy entry for default format
53  FormatInfo *info = new FormatInfo;
54  info->library = "<NoLibrary>";
55  info->nameLabel = i18n( "vCard" );
56  info->descriptionLabel = i18n( "vCard Format" );
57  mFormatList.insert( "vcard", info );
58 
59  const TQStringList list = TDEGlobal::dirs()->findAllResources( "data" ,"tdeabc/formats/*.desktop", true, true );
60  for ( TQStringList::ConstIterator it = list.begin(); it != list.end(); ++it )
61  {
62  KSimpleConfig config( *it, true );
63 
64  if ( !config.hasGroup( "Misc" ) || !config.hasGroup( "Plugin" ) )
65  continue;
66 
67  info = new FormatInfo;
68 
69  config.setGroup( "Plugin" );
70  TQString type = config.readEntry( "Type" );
71  info->library = config.readEntry( "X-TDE-Library" );
72 
73  config.setGroup( "Misc" );
74  info->nameLabel = config.readEntry( "Name" );
75  info->descriptionLabel = config.readEntry( "Comment", i18n( "No description available." ) );
76 
77  mFormatList.insert( type, info );
78  }
79 }
80 
81 FormatFactory::~FormatFactory()
82 {
83  mFormatList.clear();
84 }
85 
86 TQStringList FormatFactory::formats()
87 {
88  TQStringList retval;
89 
90  // make sure 'vcard' is the first entry
91  retval << "vcard";
92 
93  TQDictIterator<FormatInfo> it( mFormatList );
94  for ( ; it.current(); ++it )
95  if ( it.currentKey() != "vcard" )
96  retval << it.currentKey();
97 
98  return retval;
99 }
100 
101 FormatInfo *FormatFactory::info( const TQString &type )
102 {
103  if ( type.isEmpty() )
104  return 0;
105  else
106  return mFormatList[ type ];
107 }
108 
109 FormatPlugin *FormatFactory::format( const TQString& type )
110 {
111  FormatPlugin *format = 0;
112 
113  if ( type.isEmpty() )
114  return 0;
115 
116  if ( type == "vcard" ) {
117  format = new VCardFormatPlugin;
118  format->setType( type );
119  format->setNameLabel( i18n( "vCard" ) );
120  format->setDescriptionLabel( i18n( "vCard Format" ) );
121  return format;
122  }
123 
124  FormatInfo *fi = mFormatList[ type ];
125  if (!fi)
126  return 0;
127  TQString libName = fi->library;
128 
129  KLibrary *library = openLibrary( libName );
130  if ( !library )
131  return 0;
132 
133  void *format_func = library->symbol( "format" );
134 
135  if ( format_func ) {
136  format = ((FormatPlugin* (*)())format_func)();
137  format->setType( type );
138  format->setNameLabel( fi->nameLabel );
139  format->setDescriptionLabel( fi->descriptionLabel );
140  } else {
141  kdDebug( 5700 ) << "'" << libName << "' is not a format plugin." << endl;
142  return 0;
143  }
144 
145  return format;
146 }
147 
148 
149 KLibrary *FormatFactory::openLibrary( const TQString& libName )
150 {
151  KLibrary *library = 0;
152 
153  TQString path = KLibLoader::findLibrary( TQFile::encodeName( libName ) );
154 
155  if ( path.isEmpty() ) {
156  kdDebug( 5700 ) << "No format plugin library was found!" << endl;
157  return 0;
158  }
159 
160  library = KLibLoader::self()->library( TQFile::encodeName( path ) );
161 
162  if ( !library ) {
163  kdDebug( 5700 ) << "Could not load library '" << libName << "'" << endl;
164  return 0;
165  }
166 
167  return library;
168 }
TDEABC::FormatFactory
Class for loading format plugins.
Definition: formatfactory.h:57
KStaticDeleter
kdDebug
kdbgstream kdDebug(int area=0)
TDEABC::FormatFactory::self
static FormatFactory * self()
Returns the global format factory.
Definition: formatfactory.cpp:38
KStaticDeleter::setObject
KDE_DEPRECATED type * setObject(type *obj, bool isArray=false)
TDEABC::FormatPlugin
Base class for address book formats.
Definition: formatplugin.h:42
TDEABC
static data, shared by ALL addressee objects
Definition: address.h:48
TDEGlobal::dirs
static TDEStandardDirs * dirs()
tdelocale.h
TDEStandardDirs::findAllResources
TQStringList findAllResources(const char *type, const TQString &filter=TQString::null, bool recursive=false, bool unique=false) const
KLibrary
TDEABC::FormatFactory::~FormatFactory
~FormatFactory()
Destructor.
Definition: formatfactory.cpp:81
TDEABC::FormatFactory::info
FormatInfo * info(const TQString &type)
Returns the info structure for a special type.
Definition: formatfactory.cpp:101
KLibLoader::library
virtual KLibrary * library(const char *libname)
KLibLoader::self
static KLibLoader * self()
TDEABC::FormatFactory::formats
TQStringList formats()
Returns a list of all available format types.
Definition: formatfactory.cpp:86
KLibLoader::findLibrary
static TQString findLibrary(const char *name, const TDEInstance *instance=TDEGlobal::instance())
KLibrary::symbol
void * symbol(const char *name) const
endl
kndbgstream & endl(kndbgstream &s)
KSimpleConfig
TDEABC::VCardFormatPlugin
Interface of vCard backend for address book.
Definition: vcardformatplugin.h:37
TDEABC::FormatFactory::format
FormatPlugin * format(const TQString &type)
Returns a pointer to a format object or a null pointer if format type doesn't exist.
Definition: formatfactory.cpp:109

tdeabc

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

tdeabc

Skip menu "tdeabc"
  • 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 tdeabc by doxygen 1.8.8
This website is maintained by Timothy Pearson.