author | ulf69 <ulf69> | 2004-06-29 05:22:05 (UTC) |
---|---|---|
committer | ulf69 <ulf69> | 2004-06-29 05:22:05 (UTC) |
commit | 6cbf4bfe5ee3b706d7b50324b5300db76eef89d6 (patch) (unidiff) | |
tree | 4b5056541b3a83b2c936543782d9a7caac8e22ac | |
parent | beccf25496b482fa9eccd41f13c07e67e32f3a52 (diff) | |
download | kdepimpi-6cbf4bfe5ee3b706d7b50324b5300db76eef89d6.zip kdepimpi-6cbf4bfe5ee3b706d7b50324b5300db76eef89d6.tar.gz kdepimpi-6cbf4bfe5ee3b706d7b50324b5300db76eef89d6.tar.bz2 |
*** empty log message ***
-rw-r--r-- | kabc/formatfactory.cpp | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/kabc/formatfactory.cpp b/kabc/formatfactory.cpp index 2b073d7..f107ebf 100644 --- a/kabc/formatfactory.cpp +++ b/kabc/formatfactory.cpp | |||
@@ -28,74 +28,80 @@ | |||
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 | ||
34 | using namespace KABC; | 34 | using namespace KABC; |
35 | 35 | ||
36 | FormatFactory *FormatFactory::mSelf = 0; | 36 | FormatFactory *FormatFactory::mSelf = 0; |
37 | static KStaticDeleter<FormatFactory> factoryDeleter; | 37 | static KStaticDeleter<FormatFactory> factoryDeleter; |
38 | 38 | ||
39 | FormatFactory *FormatFactory::self() | 39 | FormatFactory *FormatFactory::self() |
40 | { | 40 | { |
41 | kdDebug(5700) << "FormatFactory::self()" << endl; | 41 | kdDebug(5700) << "FormatFactory::self()" << endl; |
42 | 42 | ||
43 | if ( !mSelf ) { | 43 | if ( !mSelf ) { |
44 | #ifdef KAB_EMBEDDED | 44 | //US factoryDeleter.setObject( mSelf, new FormatFactory ); |
45 | mSelf = factoryDeleter.setObject( new FormatFactory ); | 45 | mSelf = factoryDeleter.setObject( new FormatFactory ); |
46 | #else //KAB_EMBEDDED | ||
47 | factoryDeleter.setObject( mSelf, new FormatFactory ); | ||
48 | #endif //KAB_EMBEDDED | ||
49 | |||
50 | } | 46 | } |
51 | return mSelf; | 47 | return mSelf; |
52 | } | 48 | } |
53 | 49 | ||
54 | FormatFactory::FormatFactory() | 50 | FormatFactory::FormatFactory() |
55 | { | 51 | { |
56 | mFormatList.setAutoDelete( true ); | 52 | mFormatList.setAutoDelete( true ); |
57 | 53 | ||
58 | // dummy entry for default format | 54 | // dummy entry for default format |
59 | FormatInfo *info = new FormatInfo; | 55 | FormatInfo *info = new FormatInfo; |
60 | info->library = "<NoLibrary>"; | 56 | info->library = "<NoLibrary>"; |
61 | info->nameLabel = i18n( "vCard" ); | 57 | info->nameLabel = i18n( "vCard" ); |
62 | info->descriptionLabel = i18n( "vCard Format" ); | 58 | info->descriptionLabel = i18n( "vCard Format" ); |
63 | mFormatList.insert( "vcard", info ); | 59 | mFormatList.insert( "vcard", info ); |
64 | 60 | ||
61 | /*US lets enter all resources directly instead of using teh desktopfiles. | ||
62 | |||
65 | QStringList list = KGlobal::dirs()->findAllResources( "data" ,"kabc/formats/*.desktop", true, true ); | 63 | QStringList list = KGlobal::dirs()->findAllResources( "data" ,"kabc/formats/*.desktop", true, true ); |
66 | for ( QStringList::ConstIterator it = list.begin(); it != list.end(); ++it ) | 64 | for ( QStringList::ConstIterator it = list.begin(); it != list.end(); ++it ) |
67 | { | 65 | { |
68 | //US KSimpleConfig config( *it, true ); | 66 | //US KSimpleConfig config( *it, true ); |
69 | KConfig config( *it ); | 67 | KConfig config( *it ); |
70 | 68 | ||
71 | if ( !config.hasGroup( "Misc" ) || !config.hasGroup( "Plugin" ) ) | 69 | if ( !config.hasGroup( "Misc" ) || !config.hasGroup( "Plugin" ) ) |
72 | continue; | 70 | continue; |
73 | 71 | ||
74 | info = new FormatInfo; | 72 | info = new FormatInfo; |
75 | 73 | ||
76 | config.setGroup( "Plugin" ); | 74 | config.setGroup( "Plugin" ); |
77 | QString type = config.readEntry( "Type" ); | 75 | QString type = config.readEntry( "Type" ); |
78 | info->library = config.readEntry( "X-KDE-Library" ); | 76 | info->library = config.readEntry( "X-KDE-Library" ); |
79 | 77 | ||
80 | config.setGroup( "Misc" ); | 78 | config.setGroup( "Misc" ); |
81 | info->nameLabel = config.readEntry( "Name" ); | 79 | info->nameLabel = config.readEntry( "Name" ); |
82 | info->descriptionLabel = config.readEntry( "Comment", i18n( "No description available." ) ); | 80 | info->descriptionLabel = config.readEntry( "Comment", i18n( "No description available." ) ); |
83 | 81 | ||
84 | mFormatList.insert( type, info ); | 82 | mFormatList.insert( type, info ); |
85 | } | 83 | } |
84 | */ | ||
85 | //US we already have vcard as default format. | ||
86 | info = new FormatInfo; | ||
87 | info->library = i18n("microkabcformat_binary"); | ||
88 | info->nameLabel = i18n( "Binary" ); | ||
89 | info->descriptionLabel = i18n( "No description available." ); | ||
90 | mFormatList.insert( "binary", info ); | ||
91 | |||
86 | } | 92 | } |
87 | 93 | ||
88 | FormatFactory::~FormatFactory() | 94 | FormatFactory::~FormatFactory() |
89 | { | 95 | { |
90 | mFormatList.clear(); | 96 | mFormatList.clear(); |
91 | } | 97 | } |
92 | 98 | ||
93 | QStringList FormatFactory::formats() | 99 | QStringList FormatFactory::formats() |
94 | { | 100 | { |
95 | QStringList retval; | 101 | QStringList retval; |
96 | 102 | ||
97 | // make sure 'vcard' is the first entry | 103 | // make sure 'vcard' is the first entry |
98 | retval << "vcard"; | 104 | retval << "vcard"; |
99 | 105 | ||
100 | QDictIterator<FormatInfo> it( mFormatList ); | 106 | QDictIterator<FormatInfo> it( mFormatList ); |
101 | for ( ; it.current(); ++it ) | 107 | for ( ; it.current(); ++it ) |
@@ -109,59 +115,54 @@ FormatInfo *FormatFactory::info( const QString &type ) | |||
109 | { | 115 | { |
110 | if ( type.isEmpty() ) | 116 | if ( type.isEmpty() ) |
111 | return 0; | 117 | return 0; |
112 | else | 118 | else |
113 | return mFormatList[ type ]; | 119 | return mFormatList[ type ]; |
114 | } | 120 | } |
115 | 121 | ||
116 | FormatPlugin *FormatFactory::format( const QString& type ) | 122 | FormatPlugin *FormatFactory::format( const QString& type ) |
117 | { | 123 | { |
118 | FormatPlugin *format = 0; | 124 | FormatPlugin *format = 0; |
119 | 125 | ||
120 | if ( type.isEmpty() ) | 126 | if ( type.isEmpty() ) |
121 | return 0; | 127 | return 0; |
122 | 128 | ||
123 | if ( type == "vcard" ) { | 129 | if ( type == "vcard" ) { |
124 | format = new VCardFormatPlugin; | 130 | format = new VCardFormatPlugin; |
125 | /* // LR | ||
126 | format->setType( type ); | 131 | format->setType( type ); |
127 | format->setNameLabel( i18n( "vCard" ) ); | 132 | format->setNameLabel( i18n( "vCard" ) ); |
128 | format->setDescriptionLabel( i18n( "vCard Format" ) ); | 133 | format->setDescriptionLabel( i18n( "vCard Format" ) ); |
129 | */ | ||
130 | return format; | 134 | return format; |
131 | } | 135 | } |
132 | 136 | ||
133 | FormatInfo *fi = mFormatList[ type ]; | 137 | FormatInfo *fi = mFormatList[ type ]; |
134 | if (!fi) | 138 | if (!fi) |
135 | return 0; | 139 | return 0; |
136 | QString libName = fi->library; | 140 | QString libName = fi->library; |
137 | #ifndef DESKTOP_VERSION | 141 | #ifndef DESKTOP_VERSION |
138 | KLibrary *library = openLibrary( libName ); | 142 | KLibrary *library = openLibrary( libName ); |
139 | if ( !library ) | 143 | if ( !library ) |
140 | return 0; | 144 | return 0; |
141 | 145 | ||
142 | void *format_func = library->symbol( "format" ); | 146 | void *format_func = library->symbol( "format"); |
143 | 147 | ||
144 | if ( format_func ) { | 148 | if ( format_func ) { |
145 | format = ((FormatPlugin* (*)())format_func)(); | 149 | format = ((FormatPlugin* (*)())format_func)(); |
146 | // LR | ||
147 | /* | ||
148 | format->setType( type ); | 150 | format->setType( type ); |
149 | format->setNameLabel( fi->nameLabel ); | 151 | format->setNameLabel( fi->nameLabel ); |
150 | format->setDescriptionLabel( fi->descriptionLabel ); | 152 | format->setDescriptionLabel( fi->descriptionLabel ); |
151 | */ | ||
152 | } else { | 153 | } else { |
153 | kdDebug( 5700 ) << "'" << libName << "' is not a format plugin." << endl; | 154 | kdDebug( 5700 ) << "'" << libName << "' is not a format plugin." << endl; |
154 | return 0; | 155 | return 0; |
155 | } | 156 | } |
156 | #endif | 157 | #endif |
157 | return format; | 158 | return format; |
158 | } | 159 | } |
159 | 160 | ||
160 | #ifndef DESKTOP_VERSION | 161 | #ifndef DESKTOP_VERSION |
161 | KLibrary *FormatFactory::openLibrary( const QString& libName ) | 162 | KLibrary *FormatFactory::openLibrary( const QString& libName ) |
162 | { | 163 | { |
163 | KLibrary *library = 0; | 164 | KLibrary *library = 0; |
164 | 165 | ||
165 | QString path = KLibLoader::findLibrary( QFile::encodeName( libName ) ); | 166 | QString path = KLibLoader::findLibrary( QFile::encodeName( libName ) ); |
166 | 167 | ||
167 | if ( path.isEmpty() ) { | 168 | if ( path.isEmpty() ) { |