summaryrefslogtreecommitdiffabout
path: root/kabc/formatfactory.cpp
Unidiff
Diffstat (limited to 'kabc/formatfactory.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/formatfactory.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/kabc/formatfactory.cpp b/kabc/formatfactory.cpp
index 3ae1c27..cbb97a2 100644
--- a/kabc/formatfactory.cpp
+++ b/kabc/formatfactory.cpp
@@ -9,173 +9,173 @@
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 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 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21#include <kdebug.h> 21#include <kdebug.h>
22#include <klocale.h> 22#include <klocale.h>
23#include <ksimpleconfig.h> 23#include <ksimpleconfig.h>
24#include <kstandarddirs.h> 24#include <kstandarddirs.h>
25#include <kstaticdeleter.h> 25#include <kstaticdeleter.h>
26 26
27#include <qfile.h> 27#include <qfile.h>
28#include <qstringlist.h> 28#include <qstringlist.h>
29 29
30#include "vcardformatplugin.h" 30#include "vcardformatplugin.h"
31 31
32#include "formatfactory.h" 32#include "formatfactory.h"
33 33
34using namespace KABC; 34using namespace KABC;
35 35
36FormatFactory *FormatFactory::mSelf = 0; 36FormatFactory *FormatFactory::mSelf = 0;
37static KStaticDeleter<FormatFactory> factoryDeleter; 37static KStaticDeleter<FormatFactory> factoryDeleter;
38 38
39FormatFactory *FormatFactory::self() 39FormatFactory *FormatFactory::self()
40{ 40{
41 if ( !mSelf ) { 41 if ( !mSelf ) {
42//US factoryDeleter.setObject( mSelf, new FormatFactory ); 42//US factoryDeleter.setObject( mSelf, new FormatFactory );
43 mSelf = factoryDeleter.setObject( new FormatFactory ); 43 mSelf = factoryDeleter.setObject( new FormatFactory );
44 } 44 }
45 return mSelf; 45 return mSelf;
46} 46}
47 47
48FormatFactory::FormatFactory() 48FormatFactory::FormatFactory()
49{ 49{
50 mFormatList.setAutoDelete( true ); 50 mFormatList.setAutoDelete( true );
51 51
52 // dummy entry for default format 52 // dummy entry for default format
53 FormatInfo *info = new FormatInfo; 53 FormatInfo *info = new FormatInfo;
54 info->library = "<NoLibrary>"; 54 info->library = "<NoLibrary>";
55 info->nameLabel = i18n( "vCard" ); 55 info->nameLabel = i18n( "vCard" );
56 info->descriptionLabel = i18n( "vCard Format" ); 56 info->descriptionLabel = i18n( "vCard Format" );
57 mFormatList.insert( "vcard", info ); 57 mFormatList.insert( "vcard", info );
58 58
59#if 0 59#if 0
60US lets enter all resources directly instead of using teh desktopfiles. 60US lets enter all resources directly instead of using teh desktopfiles.
61 61
62 QStringList list = KGlobal::dirs()->findAllResources( "data" ,"kabc/formats/*.desktop", true, true ); 62 QStringList list = KGlobal::dirs()->findAllResources( "data" ,"kabc/formats/*.desktop", true, true );
63 for ( QStringList::ConstIterator it = list.begin(); it != list.end(); ++it ) 63 for ( QStringList::ConstIterator it = list.begin(); it != list.end(); ++it )
64 { 64 {
65//US KSimpleConfig config( *it, true ); 65//US KSimpleConfig config( *it, true );
66 KConfig config( *it ); 66 KConfig config( *it );
67 67
68 if ( !config.hasGroup( "Misc" ) || !config.hasGroup( "Plugin" ) ) 68 if ( !config.hasGroup( "Misc" ) || !config.hasGroup( "Plugin" ) )
69 continue; 69 continue;
70 70
71 info = new FormatInfo; 71 info = new FormatInfo;
72 72
73 config.setGroup( "Plugin" ); 73 config.setGroup( "Plugin" );
74 QString type = config.readEntry( "Type" ); 74 QString type = config.readEntry( "Type" );
75 info->library = config.readEntry( "X-KDE-Library" ); 75 info->library = config.readEntry( "X-KDE-Library" );
76 76
77 config.setGroup( "Misc" ); 77 config.setGroup( "Misc" );
78 info->nameLabel = config.readEntry( "Name" ); 78 info->nameLabel = config.readEntry( "Name" );
79 info->descriptionLabel = config.readEntry( "Comment", i18n( "No description available." ) ); 79 info->descriptionLabel = config.readEntry( "Comment", i18n( "No description available." ) );
80 80
81 mFormatList.insert( type, info ); 81 mFormatList.insert( type, info );
82 } 82 }
83#endif 83#endif
84 //US we already have vcard as default format. 84 //US we already have vcard as default format.
85 info = new FormatInfo; 85 info = new FormatInfo;
86 info->library = i18n("microkabcformat_binary"); 86 info->library = i18n("microkabcformat_binary");
87 info->nameLabel = i18n( "Binary" ); 87 info->nameLabel = i18n( "Binary" );
88 info->descriptionLabel = i18n( "No description available." ); 88 info->descriptionLabel = i18n( "No description available." );
89 mFormatList.insert( "binary", info ); 89 mFormatList.insert( "binary", info );
90 90
91} 91}
92 92
93FormatFactory::~FormatFactory() 93FormatFactory::~FormatFactory()
94{ 94{
95 mFormatList.clear(); 95 mFormatList.clear();
96} 96}
97 97
98QStringList FormatFactory::formats() 98QStringList FormatFactory::formats()
99{ 99{
100 QStringList retval; 100 QStringList retval;
101 101
102 // make sure 'vcard' is the first entry 102 // make sure 'vcard' is the first entry
103 retval << "vcard"; 103 retval << "vcard";
104 104
105 QDictIterator<FormatInfo> it( mFormatList ); 105 Q3DictIterator<FormatInfo> it( mFormatList );
106 for ( ; it.current(); ++it ) 106 for ( ; it.current(); ++it )
107 if ( it.currentKey() != "vcard" ) 107 if ( it.currentKey() != "vcard" )
108 retval << it.currentKey(); 108 retval << it.currentKey();
109 109
110 return retval; 110 return retval;
111} 111}
112 112
113FormatInfo *FormatFactory::info( const QString &type ) 113FormatInfo *FormatFactory::info( const QString &type )
114{ 114{
115 if ( type.isEmpty() ) 115 if ( type.isEmpty() )
116 return 0; 116 return 0;
117 else 117 else
118 return mFormatList[ type ]; 118 return mFormatList[ type ];
119} 119}
120 120
121FormatPlugin *FormatFactory::format( const QString& type ) 121FormatPlugin *FormatFactory::format( const QString& type )
122{ 122{
123 FormatPlugin *format = 0; 123 FormatPlugin *format = 0;
124 124
125 if ( type.isEmpty() ) 125 if ( type.isEmpty() )
126 return 0; 126 return 0;
127 127
128 if ( type == "vcard" ) { 128 if ( type == "vcard" ) {
129 format = new VCardFormatPlugin; 129 format = new VCardFormatPlugin;
130 format->setType( type ); 130 format->setType( type );
131 format->setNameLabel( i18n( "vCard" ) ); 131 format->setNameLabel( i18n( "vCard" ) );
132 format->setDescriptionLabel( i18n( "vCard Format" ) ); 132 format->setDescriptionLabel( i18n( "vCard Format" ) );
133 return format; 133 return format;
134 } 134 }
135 135
136 FormatInfo *fi = mFormatList[ type ]; 136 FormatInfo *fi = mFormatList[ type ];
137 if (!fi) 137 if (!fi)
138 return 0; 138 return 0;
139 QString libName = fi->library; 139 QString libName = fi->library;
140#ifndef DESKTOP_VERSION 140#ifndef DESKTOP_VERSION
141 KLibrary *library = openLibrary( libName ); 141 KLibrary *library = openLibrary( libName );
142 if ( !library ) 142 if ( !library )
143 return 0; 143 return 0;
144 144
145 void *format_func = library->symbol( "format"); 145 void *format_func = library->symbol( "format");
146 146
147 if ( format_func ) { 147 if ( format_func ) {
148 format = ((FormatPlugin* (*)())format_func)(); 148 format = ((FormatPlugin* (*)())format_func)();
149 format->setType( type ); 149 format->setType( type );
150 format->setNameLabel( fi->nameLabel ); 150 format->setNameLabel( fi->nameLabel );
151 format->setDescriptionLabel( fi->descriptionLabel ); 151 format->setDescriptionLabel( fi->descriptionLabel );
152 } else { 152 } else {
153 kdDebug( 5700 ) << "'" << libName << "' is not a format plugin." << endl; 153 kdDebug( 5700 ) << "'" << libName << "' is not a format plugin." << endl;
154 return 0; 154 return 0;
155 } 155 }
156#endif 156#endif
157 return format; 157 return format;
158} 158}
159 159
160#ifndef DESKTOP_VERSION 160#ifndef DESKTOP_VERSION
161KLibrary *FormatFactory::openLibrary( const QString& libName ) 161KLibrary *FormatFactory::openLibrary( const QString& libName )
162{ 162{
163 KLibrary *library = 0; 163 KLibrary *library = 0;
164 164
165 QString path = KLibLoader::findLibrary( QFile::encodeName( libName ) ); 165 QString path = KLibLoader::findLibrary( QFile::encodeName( libName ) );
166 166
167 if ( path.isEmpty() ) { 167 if ( path.isEmpty() ) {
168 kdDebug( 5700 ) << "No format plugin library was found!" << endl; 168 kdDebug( 5700 ) << "No format plugin library was found!" << endl;
169 return 0; 169 return 0;
170 } 170 }
171 171
172 library = KLibLoader::self()->library( QFile::encodeName( path ) ); 172 library = KLibLoader::self()->library( QFile::encodeName( path ) );
173 173
174 if ( !library ) { 174 if ( !library ) {
175 kdDebug( 5700 ) << "Could not load library '" << libName << "'" << endl; 175 kdDebug( 5700 ) << "Could not load library '" << libName << "'" << endl;
176 return 0; 176 return 0;
177 } 177 }
178 178
179 return library; 179 return library;
180} 180}
181#endif 181#endif