summaryrefslogtreecommitdiffabout
authorulf69 <ulf69>2004-06-29 05:03:25 (UTC)
committer ulf69 <ulf69>2004-06-29 05:03:25 (UTC)
commit0538ac1cc17ad4249d27d686b4bc7e80663f475f (patch) (unidiff)
treeabf571d0e2640bbb7ce14818a376ad980492ea05
parent61ef87224517601f8754dd9da1b521a7b0094558 (diff)
downloadkdepimpi-0538ac1cc17ad4249d27d686b4bc7e80663f475f.zip
kdepimpi-0538ac1cc17ad4249d27d686b4bc7e80663f475f.tar.gz
kdepimpi-0538ac1cc17ad4249d27d686b4bc7e80663f475f.tar.bz2
*** empty log message ***
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/stdaddressbook.cpp22
-rw-r--r--microkde/kdecore/klibloader.cpp24
2 files changed, 22 insertions, 24 deletions
diff --git a/kabc/stdaddressbook.cpp b/kabc/stdaddressbook.cpp
index f9fc70b..8faaaef 100644
--- a/kabc/stdaddressbook.cpp
+++ b/kabc/stdaddressbook.cpp
@@ -1,249 +1,233 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
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/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27#ifndef DESKTOP_VERSION
28#include <qpe/global.h>
29#else
30
31#include <qdir.h>
32#endif
33#ifdef KAB_EMBEDDED
34 27
28/*US
35#include <stdlib.h> 29#include <stdlib.h>
36#else //KAB_EMBEDDED
37 30
38#include <stdlib.h>
39
40//US#include <kresources/manager.h>
41#include <kapplication.h> 31#include <kapplication.h>
42#include <kcrash.h> 32#include <kcrash.h>
43#include <ksimpleconfig.h> 33#include <ksimpleconfig.h>
44 34*/
45
46#endif //KAB_EMBEDDED
47 35
48#include "resource.h" 36#include "resource.h"
49#include <kresources/manager.h> 37#include <kresources/manager.h>
50#include <kdebug.h> 38#include <kdebug.h>
51#include <klocale.h> 39#include <klocale.h>
52#include <kstaticdeleter.h> 40#include <kstaticdeleter.h>
53#include <kstandarddirs.h> 41#include <kstandarddirs.h>
54 42
55#include "stdaddressbook.h" 43#include "stdaddressbook.h"
56 44
57using namespace KABC; 45using namespace KABC;
58 46
59StdAddressBook *StdAddressBook::mSelf = 0; 47StdAddressBook *StdAddressBook::mSelf = 0;
60bool StdAddressBook::mAutomaticSave = true; 48bool StdAddressBook::mAutomaticSave = true;
61 49
62static KStaticDeleter<StdAddressBook> addressBookDeleter; 50static KStaticDeleter<StdAddressBook> addressBookDeleter;
63 51
64QString StdAddressBook::fileName() 52QString StdAddressBook::fileName()
65{ 53{
66 return locateLocal( "data", "kabc/std.vcf" ); 54 return locateLocal( "data", "kabc/std.vcf" );
67} 55}
68 56
69QString StdAddressBook::directoryName() 57QString StdAddressBook::directoryName()
70{ 58{
71 qDebug("StdAddressBook::directoryName() WILL FAIL OR NOT" );
72 return locateLocal( "data", "kabc/stdvcf" ); 59 return locateLocal( "data", "kabc/stdvcf" );
73} 60}
74 61
75void StdAddressBook::handleCrash() 62void StdAddressBook::handleCrash()
76{ 63{
77 StdAddressBook::self()->cleanUp(); 64 StdAddressBook::self()->cleanUp();
78} 65}
79 66
80StdAddressBook *StdAddressBook::self() 67StdAddressBook *StdAddressBook::self()
81{ 68{
82 69
83 if ( !mSelf ) 70 if ( !mSelf )
84 { 71 {
85 QString appdir = StdAddressBook::setTempAppDir(); 72 QString appdir = StdAddressBook::setTempAppDir();
86 73
87 kdDebug(5700) << "StdAddressBook::self()" << endl; 74 kdDebug(5700) << "StdAddressBook::self()" << endl;
88// US im am not sure why I have to use the other format here?? 75// US im am not sure why I have to use the other format here??
89#ifdef KAB_EMBEDDED 76#ifdef KAB_EMBEDDED
90 mSelf = addressBookDeleter.setObject( new StdAddressBook ); 77 mSelf = addressBookDeleter.setObject( new StdAddressBook );
91#else //KAB_EMBEDDED 78#else //KAB_EMBEDDED
92 addressBookDeleter.setObject( mSelf, new StdAddressBook ); 79 addressBookDeleter.setObject( mSelf, new StdAddressBook );
93#endif //KAB_EMBEDDED 80#endif //KAB_EMBEDDED
94 KStandardDirs::setAppDir( appdir ); 81 KStandardDirs::setAppDir( appdir );
95 } 82 }
96 83
97 return mSelf; 84 return mSelf;
98} 85}
99 86
100QString StdAddressBook::setTempAppDir() 87QString StdAddressBook::setTempAppDir()
101{ 88{
102 QString appDIR = KStandardDirs::appDir(); 89 QString appDIR = KStandardDirs::appDir();
103#ifdef DESKTOP_VERSION 90#ifdef DESKTOP_VERSION
104 QString appdir = QDir::homeDirPath(); 91 QString appdir = QDir::homeDirPath();
105 if ( appdir.right(1) == "\\" || appdir.right(1) == "/" ) 92 if ( appdir.right(1) == "\\" || appdir.right(1) == "/" )
106 appdir += "kaddressbook/"; 93 appdir += "kaddressbook/";
107 else 94 else
108 appdir += "/kaddressbook/"; 95 appdir += "/kaddressbook/";
109 KStandardDirs::setAppDir( QDir::convertSeparators( appdir )); 96 KStandardDirs::setAppDir( QDir::convertSeparators( appdir ));
110#else 97#else
111 KStandardDirs::setAppDir( Global::applicationFileName( "kaddressbook", "" ) ); 98 KStandardDirs::setAppDir( Global::applicationFileName( "kaddressbook", "" ) );
112#endif 99#endif
113 100
114 return appDIR; 101 return appDIR;
115} 102}
116StdAddressBook *StdAddressBook::self( bool onlyFastResources ) 103StdAddressBook *StdAddressBook::self( bool onlyFastResources )
117{ 104{
118 105
119 if ( !mSelf ) 106 if ( !mSelf )
120 { 107 {
121 QString appdir =StdAddressBook::setTempAppDir(); 108 QString appdir =StdAddressBook::setTempAppDir();
122#ifdef KAB_EMBEDDED 109#ifdef KAB_EMBEDDED
123 mSelf = addressBookDeleter.setObject( new StdAddressBook( onlyFastResources ) ); 110 mSelf = addressBookDeleter.setObject( new StdAddressBook( onlyFastResources ) );
124#else //KAB_EMBEDDED 111#else //KAB_EMBEDDED
125 addressBookDeleter.setObject( mSelf, new StdAddressBook( onlyFastResources ) ); 112 addressBookDeleter.setObject( mSelf, new StdAddressBook( onlyFastResources ) );
126#endif //KAB_EMBEDDED 113#endif //KAB_EMBEDDED
127 KStandardDirs::setAppDir( appdir ); 114 KStandardDirs::setAppDir( appdir );
128 } 115 }
129 return mSelf; 116 return mSelf;
130} 117}
131 118
132StdAddressBook::StdAddressBook() 119StdAddressBook::StdAddressBook()
133//US : AddressBook( "kabcrc" ) 120//US : AddressBook( "kabcrc" )
134 : AddressBook( locateLocal( "config", "kabcrc") ) 121 : AddressBook( locateLocal( "config", "kabcrc") )
135{ 122{
136 123
137 init( false ); 124 init( false );
138} 125}
139 126
140StdAddressBook::StdAddressBook( bool onlyFastResources ) 127StdAddressBook::StdAddressBook( bool onlyFastResources )
141//US : AddressBook( "kabcrc" ) 128//US : AddressBook( "kabcrc" )
142 : AddressBook( locateLocal( "config", "kabcrc") ) 129 : AddressBook( locateLocal( "config", "kabcrc") )
143{ 130{
144 131
145 init( onlyFastResources ); 132 init( onlyFastResources );
146} 133}
147 134
148StdAddressBook::~StdAddressBook() 135StdAddressBook::~StdAddressBook()
149{ 136{
150 if ( mAutomaticSave ) 137 if ( mAutomaticSave )
151 save(); 138 save();
152} 139}
153 140
154void StdAddressBook::init( bool ) 141void StdAddressBook::init( bool )
155{ 142{
156 KRES::Manager<Resource> *manager = resourceManager(); 143 KRES::Manager<Resource> *manager = resourceManager();
157 KRES::Manager<Resource>::ActiveIterator it; 144 KRES::Manager<Resource>::ActiveIterator it;
158 145
159 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { 146 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
160 (*it)->setAddressBook( this ); 147 (*it)->setAddressBook( this );
161 if ( !(*it)->open() ) 148 if ( !(*it)->open() )
162 error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); 149 error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) );
163 } 150 }
164 151
165 Resource *res = standardResource(); 152 Resource *res = standardResource();
166 if ( !res ) { 153 if ( !res ) {
167 res = manager->createResource( "file" ); 154 res = manager->createResource( "file" );
168 if ( res ) 155 if ( res )
169 { 156 {
170 addResource( res ); 157 addResource( res );
171 } 158 }
172 else 159 else
173 kdDebug(5700) << "No resource available!!!" << endl; 160 kdDebug(5700) << "No resource available!!!" << endl;
174 } 161 }
175 162
176 setStandardResource( res ); 163 setStandardResource( res );
177 manager->writeConfig(); 164 manager->writeConfig();
178 165
179 load(); 166 load();
180} 167}
181 168
182bool StdAddressBook::save() 169bool StdAddressBook::save()
183{ 170{
184 kdDebug(5700) << "StdAddressBook::save()" << endl; 171 kdDebug(5700) << "StdAddressBook::save()" << endl;
185 172
186 bool ok = true; 173 bool ok = true;
187 AddressBook *ab = self(); 174 AddressBook *ab = self();
188 175
189 ab->deleteRemovedAddressees(); 176 ab->deleteRemovedAddressees();
190 177
191 KRES::Manager<Resource>::ActiveIterator it; 178 KRES::Manager<Resource>::ActiveIterator it;
192 KRES::Manager<Resource> *manager = ab->resourceManager(); 179 KRES::Manager<Resource> *manager = ab->resourceManager();
193 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { 180 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
194 if ( !(*it)->readOnly() && (*it)->isOpen() ) { 181 if ( !(*it)->readOnly() && (*it)->isOpen() ) {
195 Ticket *ticket = ab->requestSaveTicket( *it ); 182 Ticket *ticket = ab->requestSaveTicket( *it );
196// qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); 183// qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() );
197 if ( !ticket ) { 184 if ( !ticket ) {
198 ab->error( i18n( "Unable to save to resource '%1'. It is locked." ) 185 ab->error( i18n( "Unable to save to resource '%1'. It is locked." )
199 .arg( (*it)->resourceName() ) ); 186 .arg( (*it)->resourceName() ) );
200 return false; 187 return false;
201 } 188 }
202 189
203 if ( !ab->save( ticket ) ) 190 if ( !ab->save( ticket ) )
204 ok = false; 191 ok = false;
205 } 192 }
206 } 193 }
207 194
208 return ok; 195 return ok;
209} 196}
210 197
211void StdAddressBook::close() 198void StdAddressBook::close()
212{ 199{
213//US destructObject is not defined on my system???. Is setObject(0) the same ??? 200//US destructObject is not defined on my system???. Is setObject(0) the same ???
214#ifndef KAB_EMBEDDED 201//US addressBookDeleter.destructObject();
215 addressBookDeleter.destructObject();
216#else //KAB_EMBEDDED
217 addressBookDeleter.setObject(0); 202 addressBookDeleter.setObject(0);
218#endif //KAB_EMBEDDED
219 203
220} 204}
221 205
222void StdAddressBook::setAutomaticSave( bool enable ) 206void StdAddressBook::setAutomaticSave( bool enable )
223{ 207{
224 mAutomaticSave = enable; 208 mAutomaticSave = enable;
225} 209}
226 210
227bool StdAddressBook::automaticSave() 211bool StdAddressBook::automaticSave()
228{ 212{
229 return mAutomaticSave; 213 return mAutomaticSave;
230} 214}
231 215
232// should get const for 4.X 216// should get const for 4.X
233Addressee StdAddressBook::whoAmI() 217Addressee StdAddressBook::whoAmI()
234{ 218{
235//US KConfig config( "kabcrc" ); 219//US KConfig config( "kabcrc" );
236 KConfig config( locateLocal("config", "kabcrc") ); 220 KConfig config( locateLocal("config", "kabcrc") );
237 config.setGroup( "General" ); 221 config.setGroup( "General" );
238 222
239 return findByUid( config.readEntry( "WhoAmI" ) ); 223 return findByUid( config.readEntry( "WhoAmI" ) );
240} 224}
241 225
242void StdAddressBook::setWhoAmI( const Addressee &addr ) 226void StdAddressBook::setWhoAmI( const Addressee &addr )
243{ 227{
244//US KConfig config( "kabcrc" ); 228//US KConfig config( "kabcrc" );
245 KConfig config( locateLocal("config", "kabcrc") ); 229 KConfig config( locateLocal("config", "kabcrc") );
246 config.setGroup( "General" ); 230 config.setGroup( "General" );
247 231
248 config.writeEntry( "WhoAmI", addr.uid() ); 232 config.writeEntry( "WhoAmI", addr.uid() );
249} 233}
diff --git a/microkde/kdecore/klibloader.cpp b/microkde/kdecore/klibloader.cpp
index 1410308..130cc7c 100644
--- a/microkde/kdecore/klibloader.cpp
+++ b/microkde/kdecore/klibloader.cpp
@@ -64,193 +64,194 @@ template class QAsciiDict<KLibrary>;
64# define LT_GLOBAL 0 64# define LT_GLOBAL 0
65#endif 65#endif
66*/ 66*/
67 67
68/*US 68/*US
69extern "C" { 69extern "C" {
70extern int lt_dlopen_flag; 70extern int lt_dlopen_flag;
71} 71}
72*/ 72*/
73 73
74KLibFactory::KLibFactory( QObject* parent, const char* name ) 74KLibFactory::KLibFactory( QObject* parent, const char* name )
75 : QObject( parent, name ) 75 : QObject( parent, name )
76{ 76{
77} 77}
78 78
79KLibFactory::~KLibFactory() 79KLibFactory::~KLibFactory()
80{ 80{
81// kdDebug(150) << "Deleting KLibFactory " << this << endl; 81// kdDebug(150) << "Deleting KLibFactory " << this << endl;
82} 82}
83 83
84QObject* KLibFactory::create( QObject* parent, const char* name, const char* classname, const QStringList &args ) 84QObject* KLibFactory::create( QObject* parent, const char* name, const char* classname, const QStringList &args )
85{ 85{
86 QObject* obj = createObject( parent, name, classname, args ); 86 QObject* obj = createObject( parent, name, classname, args );
87 if ( obj ) 87 if ( obj )
88 emit objectCreated( obj ); 88 emit objectCreated( obj );
89 return obj; 89 return obj;
90} 90}
91 91
92 92
93QObject* KLibFactory::createObject( QObject*, const char*, const char*, const QStringList &) 93QObject* KLibFactory::createObject( QObject*, const char*, const char*, const QStringList &)
94{ 94{
95 return 0; 95 return 0;
96} 96}
97 97
98 98
99// ----------------------------------------------- 99// -----------------------------------------------
100 100
101//US KLibrary::KLibrary( const QString& libname, const QString& filename, void * handle ) 101//US KLibrary::KLibrary( const QString& libname, const QString& filename, void * handle )
102KLibrary::KLibrary( const QString& libname, const QString& filename, QLibrary* handle ) 102KLibrary::KLibrary( const QString& libname, const QString& filename, QLibrary* handle )
103{ 103{
104 /* Make sure, we have a KLibLoader */ 104 /* Make sure, we have a KLibLoader */
105 (void) KLibLoader::self(); 105 (void) KLibLoader::self();
106 m_libname = libname; 106 m_libname = libname;
107 m_filename = filename; 107 m_filename = filename;
108 m_handle = handle; 108 m_handle = handle;
109 m_factory = 0; 109 m_factory = 0;
110 m_timer = 0; 110 m_timer = 0;
111} 111}
112 112
113KLibrary::~KLibrary() 113KLibrary::~KLibrary()
114{ 114{
115// kdDebug(150) << "Deleting KLibrary " << this << " " << m_libname << endl; 115// kdDebug(150) << "Deleting KLibrary " << this << " " << m_libname << endl;
116 if ( m_timer && m_timer->isActive() ) 116 if ( m_timer && m_timer->isActive() )
117 m_timer->stop(); 117 m_timer->stop();
118 118
119 // If any object is remaining, delete 119 // If any object is remaining, delete
120 if ( m_objs.count() > 0 ) 120 if ( m_objs.count() > 0 )
121 { 121 {
122 QPtrListIterator<QObject> it( m_objs ); 122 QPtrListIterator<QObject> it( m_objs );
123 for ( ; it.current() ; ++it ) 123 for ( ; it.current() ; ++it )
124 { 124 {
125 kdDebug(150) << "Factory still has object " << it.current() << " " << it.current()->name () << " Library = " << m_libname << endl; 125 kdDebug(150) << "Factory still has object " << it.current() << " " << it.current()->name () << " Library = " << m_libname << endl;
126 disconnect( it.current(), SIGNAL( destroyed() ), 126 disconnect( it.current(), SIGNAL( destroyed() ),
127 this, SLOT( slotObjectDestroyed() ) ); 127 this, SLOT( slotObjectDestroyed() ) );
128 } 128 }
129 m_objs.setAutoDelete(true); 129 m_objs.setAutoDelete(true);
130 m_objs.clear(); 130 m_objs.clear();
131 } 131 }
132 132
133 if ( m_factory ) { 133 if ( m_factory ) {
134 //kdDebug(150) << " ... deleting the factory " << m_factory << endl; 134 //kdDebug(150) << " ... deleting the factory " << m_factory << endl;
135 delete m_factory; 135 delete m_factory;
136 } 136 }
137} 137}
138 138
139QString KLibrary::name() const 139QString KLibrary::name() const
140{ 140{
141 return m_libname; 141 return m_libname;
142} 142}
143 143
144QString KLibrary::fileName() const 144QString KLibrary::fileName() const
145{ 145{
146 return m_filename; 146 return m_filename;
147} 147}
148 148
149KLibFactory* KLibrary::factory() 149KLibFactory* KLibrary::factory()
150{ 150{
151 if ( m_factory ) 151 if ( m_factory )
152 return m_factory; 152 return m_factory;
153 153
154 QCString symname; 154 QCString symname;
155 symname.sprintf("init_%s", name().latin1() ); 155 symname.sprintf("init_%s", name().latin1() );
156 156
157 void* sym = symbol( symname ); 157 void* sym = symbol( symname );
158 if ( !sym ) 158 if ( !sym )
159 { 159 {
160 kdWarning(150) << "KLibrary: The library " << name() << " does not offer an init_" << name() << " function" << endl; 160 qDebug("KLibrary: The library %s does not offer an %s function", name().latin1(), symname.data());
161 kdWarning(150) << "KLibrary: The library " << name().latin1() << " does not offer an init_" << name().latin1() << " function" << endl;
161 return 0; 162 return 0;
162 } 163 }
163 164
164 typedef KLibFactory* (*t_func)(); 165 typedef KLibFactory* (*t_func)();
165 t_func func = (t_func)sym; 166 t_func func = (t_func)sym;
166 m_factory = func(); 167 m_factory = func();
167 168
168 if( !m_factory ) 169 if( !m_factory )
169 { 170 {
170 kdWarning(150) << "KLibrary: The library " << name() << " does not offer a KDE compatible factory" << endl; 171 kdWarning(150) << "KLibrary: The library " << name() << " does not offer a KDE compatible factory" << endl;
171 return 0; 172 return 0;
172 } 173 }
173 174
174 connect( m_factory, SIGNAL( objectCreated( QObject * ) ), 175 connect( m_factory, SIGNAL( objectCreated( QObject * ) ),
175 this, SLOT( slotObjectCreated( QObject * ) ) ); 176 this, SLOT( slotObjectCreated( QObject * ) ) );
176 177
177 return m_factory; 178 return m_factory;
178} 179}
179 180
180void* KLibrary::symbol( const char* symname ) const 181void* KLibrary::symbol( const char* symname ) const
181{ 182{
182//US void* sym = lt_dlsym( (lt_dlhandle) m_handle, symname ); 183//US void* sym = lt_dlsym( (lt_dlhandle) m_handle, symname );
183 void* sym = m_handle->resolve( symname ); 184 void* sym = m_handle->resolve( symname );
184 if ( !sym ) 185 if ( !sym )
185 { 186 {
186//US kdWarning(150) << "KLibrary: " << lt_dlerror() << endl; 187//US kdWarning(150) << "KLibrary: " << lt_dlerror() << endl;
187 kdWarning(150) << "KLibrary: " << m_libname << ", symbol:" << symname << " not found " << endl; 188 kdWarning(150) << "KLibrary: " << m_libname << ", symbol:" << symname << " not found " << endl;
188 return 0; 189 return 0;
189 } 190 }
190 191
191 return sym; 192 return sym;
192} 193}
193 194
194bool KLibrary::hasSymbol( const char* symname ) const 195bool KLibrary::hasSymbol( const char* symname ) const
195{ 196{
196//US void* sym = lt_dlsym( (lt_dlhandle) m_handle, symname ); 197//US void* sym = lt_dlsym( (lt_dlhandle) m_handle, symname );
197 void* sym = m_handle->resolve( symname ); 198 void* sym = m_handle->resolve( symname );
198 return (sym != 0L ); 199 return (sym != 0L );
199} 200}
200 201
201void KLibrary::unload() const 202void KLibrary::unload() const
202{ 203{
203 if (KLibLoader::s_self) 204 if (KLibLoader::s_self)
204 KLibLoader::s_self->unloadLibrary(QFile::encodeName(name())); 205 KLibLoader::s_self->unloadLibrary(QFile::encodeName(name()));
205} 206}
206 207
207void KLibrary::slotObjectCreated( QObject *obj ) 208void KLibrary::slotObjectCreated( QObject *obj )
208{ 209{
209 if ( !obj ) 210 if ( !obj )
210 return; 211 return;
211 212
212 if ( m_timer && m_timer->isActive() ) 213 if ( m_timer && m_timer->isActive() )
213 m_timer->stop(); 214 m_timer->stop();
214 215
215 if ( m_objs.containsRef( obj ) ) 216 if ( m_objs.containsRef( obj ) )
216 return; // we know this object already 217 return; // we know this object already
217 218
218 connect( obj, SIGNAL( destroyed() ), 219 connect( obj, SIGNAL( destroyed() ),
219 this, SLOT( slotObjectDestroyed() ) ); 220 this, SLOT( slotObjectDestroyed() ) );
220 221
221 m_objs.append( obj ); 222 m_objs.append( obj );
222} 223}
223 224
224void KLibrary::slotObjectDestroyed() 225void KLibrary::slotObjectDestroyed()
225{ 226{
226 m_objs.removeRef( sender() ); 227 m_objs.removeRef( sender() );
227 228
228 if ( m_objs.count() == 0 ) 229 if ( m_objs.count() == 0 )
229 { 230 {
230// kdDebug(150) << "KLibrary: shutdown timer for " << name() << " started!" 231// kdDebug(150) << "KLibrary: shutdown timer for " << name() << " started!"
231// << endl; 232// << endl;
232 233
233 if ( !m_timer ) 234 if ( !m_timer )
234 { 235 {
235 m_timer = new QTimer( this, "klibrary_shutdown_timer" ); 236 m_timer = new QTimer( this, "klibrary_shutdown_timer" );
236 connect( m_timer, SIGNAL( timeout() ), 237 connect( m_timer, SIGNAL( timeout() ),
237 this, SLOT( slotTimeout() ) ); 238 this, SLOT( slotTimeout() ) );
238 } 239 }
239 240
240 // as long as it's not stable make the timeout short, for debugging 241 // as long as it's not stable make the timeout short, for debugging
241 // pleasure (matz) 242 // pleasure (matz)
242 //m_timer->start( 1000*60, true ); 243 //m_timer->start( 1000*60, true );
243 m_timer->start( 1000*10, true ); 244 m_timer->start( 1000*10, true );
244 } 245 }
245} 246}
246 247
247void KLibrary::slotTimeout() 248void KLibrary::slotTimeout()
248{ 249{
249 if ( m_objs.count() != 0 ) 250 if ( m_objs.count() != 0 )
250 return; 251 return;
251 252
252 /* Don't go through KLibLoader::unloadLibrary(), because that uses the 253 /* Don't go through KLibLoader::unloadLibrary(), because that uses the
253 ref counter, but this timeout means to unconditionally close this library 254 ref counter, but this timeout means to unconditionally close this library
254 The destroyed() signal will take care to remove us from all lists. 255 The destroyed() signal will take care to remove us from all lists.
255 */ 256 */
256 delete this; 257 delete this;
@@ -275,281 +276,294 @@ public:
275 QString name; 276 QString name;
276 QString filename; 277 QString filename;
277}; 278};
278 279
279//US KLibWrapPrivate::KLibWrapPrivate(KLibrary *l, lt_dlhandle h) 280//US KLibWrapPrivate::KLibWrapPrivate(KLibrary *l, lt_dlhandle h)
280KLibWrapPrivate::KLibWrapPrivate(KLibrary *l, QLibrary* h) 281KLibWrapPrivate::KLibWrapPrivate(KLibrary *l, QLibrary* h)
281 : lib(l), ref_count(1), handle(h), name(l->name()), filename(l->fileName()) 282 : lib(l), ref_count(1), handle(h), name(l->name()), filename(l->fileName())
282{ 283{
283 unload_mode = UNKNOWN; 284 unload_mode = UNKNOWN;
284/*US 285/*US
285 if (lt_dlsym(handle, "__kde_do_not_unload") != 0) { 286 if (lt_dlsym(handle, "__kde_do_not_unload") != 0) {
286// kdDebug(150) << "Will not unload " << name << endl; 287// kdDebug(150) << "Will not unload " << name << endl;
287 unload_mode = DONT_UNLOAD; 288 unload_mode = DONT_UNLOAD;
288 } else if (lt_dlsym(handle, "__kde_do_unload") != 0) { 289 } else if (lt_dlsym(handle, "__kde_do_unload") != 0) {
289 unload_mode = UNLOAD; 290 unload_mode = UNLOAD;
290 } 291 }
291*/ 292*/
292//US use instead: 293//US use instead:
293 if (h->resolve("__kde_do_not_unload") != 0) { 294 if (h->resolve("__kde_do_not_unload") != 0) {
294// kdDebug(150) << "Will not unload " << name << endl; 295// kdDebug(150) << "Will not unload " << name << endl;
295 unload_mode = DONT_UNLOAD; 296 unload_mode = DONT_UNLOAD;
296 } else if (h->resolve("__kde_do_unload") != 0) { 297 } else if (h->resolve("__kde_do_unload") != 0) {
297 unload_mode = UNLOAD; 298 unload_mode = UNLOAD;
298 } 299 }
299} 300}
300 301
301class KLibLoaderPrivate 302class KLibLoaderPrivate
302{ 303{
303public: 304public:
304 QPtrList<KLibWrapPrivate> loaded_stack; 305 QPtrList<KLibWrapPrivate> loaded_stack;
305 QPtrList<KLibWrapPrivate> pending_close; 306 QPtrList<KLibWrapPrivate> pending_close;
306 enum {UNKNOWN, UNLOAD, DONT_UNLOAD} unload_mode; 307 enum {UNKNOWN, UNLOAD, DONT_UNLOAD} unload_mode;
307 308
308 QString errorMessage; 309 QString errorMessage;
309}; 310};
310 311
311KLibLoader* KLibLoader::s_self = 0; 312KLibLoader* KLibLoader::s_self = 0;
312 313
313KLibLoader* KLibLoader::self() 314KLibLoader* KLibLoader::self()
314{ 315{
315 if ( !s_self ) 316 if ( !s_self )
316 s_self = new KLibLoader; 317 s_self = new KLibLoader;
317 return s_self; 318 return s_self;
318} 319}
319 320
320void KLibLoader::cleanUp() 321void KLibLoader::cleanUp()
321{ 322{
322 if ( !s_self ) 323 if ( !s_self )
323 return; 324 return;
324 325
325 delete s_self; 326 delete s_self;
326 s_self = 0; 327 s_self = 0;
327} 328}
328 329
329KLibLoader::KLibLoader( QObject* parent, const char* name ) 330KLibLoader::KLibLoader( QObject* parent, const char* name )
330 : QObject( parent, name ) 331 : QObject( parent, name )
331{ 332{
332 s_self = this; 333 s_self = this;
333 d = new KLibLoaderPrivate; 334 d = new KLibLoaderPrivate;
334//US lt_dlinit(); 335//US lt_dlinit();
335 d->unload_mode = KLibLoaderPrivate::UNKNOWN; 336 d->unload_mode = KLibLoaderPrivate::UNKNOWN;
336 if (getenv("KDE_NOUNLOAD") != 0) 337 if (getenv("KDE_NOUNLOAD") != 0)
337 d->unload_mode = KLibLoaderPrivate::DONT_UNLOAD; 338 d->unload_mode = KLibLoaderPrivate::DONT_UNLOAD;
338 else if (getenv("KDE_DOUNLOAD") != 0) 339 else if (getenv("KDE_DOUNLOAD") != 0)
339 d->unload_mode = KLibLoaderPrivate::UNLOAD; 340 d->unload_mode = KLibLoaderPrivate::UNLOAD;
340 d->loaded_stack.setAutoDelete( true ); 341 d->loaded_stack.setAutoDelete( true );
341} 342}
342 343
343KLibLoader::~KLibLoader() 344KLibLoader::~KLibLoader()
344{ 345{
345// kdDebug(150) << "Deleting KLibLoader " << this << " " << name() << endl; 346// kdDebug(150) << "Deleting KLibLoader " << this << " " << name() << endl;
346 347
347 QAsciiDictIterator<KLibWrapPrivate> it( m_libs ); 348 QAsciiDictIterator<KLibWrapPrivate> it( m_libs );
348 for (; it.current(); ++it ) 349 for (; it.current(); ++it )
349 { 350 {
350 kdDebug(150) << "The KLibLoader contains the library " << it.current()->name 351 kdDebug(150) << "The KLibLoader contains the library " << it.current()->name
351 << " (" << it.current()->lib << ")" << endl; 352 << " (" << it.current()->lib << ")" << endl;
352 d->pending_close.append(it.current()); 353 d->pending_close.append(it.current());
353 } 354 }
354 355
355 close_pending(0); 356 close_pending(0);
356 357
357 delete d; 358 delete d;
358} 359}
359 360
360//static 361//static
361QString KLibLoader::findLibrary( const char * name/*US , const KInstance * instance*/ ) 362QString KLibLoader::findLibrary( const char * name/*US , const KInstance * instance*/ )
362{ 363{
363 QCString libname( name ); 364 QCString libname( name );
364 365
365 // only append ".la" if there is no extension 366 // only append ".la" if there is no extension
366 // this allows to load non-libtool libraries as well 367 // this allows to load non-libtool libraries as well
367 // (mhk, 20000228) 368 // (mhk, 20000228)
368 int pos = libname.findRev('/'); 369 int pos = libname.findRev('/');
369 if (pos < 0) 370 if (pos < 0)
370 pos = 0; 371 pos = 0;
371 if (libname.find('.', pos) < 0) 372/*US
373 if (libname.find('.', pos) < 0) {
372 libname += ".la"; 374 libname += ".la";
375 }
376*/
377//US in the microedition we work only with shared libraries.
378 if (libname.find('.', pos) < 0) {
379 libname += ".so";
380 }
373 381
374 // only look up the file if it is not an absolute filename 382 // only look up the file if it is not an absolute filename
375 // (mhk, 20000228) 383 // (mhk, 20000228)
376 QString libfile; 384 QString libfile;
377 if (libname[0] == '/') 385 if (libname[0] == '/')
378 libfile = libname; 386 libfile = libname;
379 else 387 else
380 { 388 {
389//US at this point the libname must exist as real filesname. No expansions will be made later
390// in findResources. Because of that we prepend the lib prefix here to the name
391//US I add also the "lib" prefix. I do not how could this could have worked before without it?
392 libname.insert(pos, "lib");
393
394
381//US libfile = instance->dirs()->findResource( "module", libname ); 395//US libfile = instance->dirs()->findResource( "module", libname );
382 libfile = KGlobal::dirs()->findResource( "module", libname ); 396 libfile = KGlobal::dirs()->findResource( "module", libname );
383 if ( libfile.isEmpty() ) 397 if ( libfile.isEmpty() )
384 { 398 {
385//US libfile = instance->dirs()->findResource( "lib", libname ); 399//US libfile = instance->dirs()->findResource( "lib", libname );
386 libfile = KGlobal::dirs()->findResource( "lib", libname ); 400 libfile = KGlobal::dirs()->findResource( "lib", libname );
387#ifndef NDEBUG 401#ifndef NDEBUG
388 if ( !libfile.isEmpty() && libname.left(3) == "lib" ) // don't warn for kdeinit modules 402 if ( !libfile.isEmpty() && libname.left(3) == "lib" ) // don't warn for kdeinit modules
389 kdDebug(150) << "library " << libname << " not found under 'module' but under 'lib'" << endl; 403 kdDebug(150) << "library " << libname << " not found under 'module' but under 'lib'" << endl;
390#endif 404#endif
391 } 405 }
392 if ( libfile.isEmpty() ) 406 if ( libfile.isEmpty() )
393 { 407 {
394#ifndef NDEBUG 408#ifndef NDEBUG
395 kdDebug(150) << "library=" << libname << ": No file names " << libname.data() << " found in paths." << endl; 409 kdDebug(150) << "library=" << libname << ": No file names " << libname.data() << " found in paths." << endl;
396#endif 410#endif
397 self()->d->errorMessage = i18n("Library files for \"%1\" not found in paths").arg(libname); 411 self()->d->errorMessage = i18n("Library files for \"%1\" not found in paths").arg(libname);
412
413 qDebug("KLibLoader::library could not find library: %s", libname.data());
414
398 } 415 }
399 else 416 else
400 self()->d->errorMessage = QString::null; 417 self()->d->errorMessage = QString::null;
401 } 418 }
402 return libfile; 419 return libfile;
403} 420}
404 421
405 422
406KLibrary* KLibLoader::globalLibrary( const char *name ) 423KLibrary* KLibLoader::globalLibrary( const char *name )
407{ 424{
408KLibrary *tmp; 425KLibrary *tmp;
409/*US 426/*US
410int olt_dlopen_flag = lt_dlopen_flag; 427int olt_dlopen_flag = lt_dlopen_flag;
411 428
412 lt_dlopen_flag |= LT_GLOBAL; 429 lt_dlopen_flag |= LT_GLOBAL;
413 kdDebug(150) << "Loading the next library global with flag " 430 kdDebug(150) << "Loading the next library global with flag "
414 << lt_dlopen_flag 431 << lt_dlopen_flag
415 << "." << endl; 432 << "." << endl;
416*/ 433*/
417 tmp = library(name); 434 tmp = library(name);
418/*US 435/*US
419 lt_dlopen_flag = olt_dlopen_flag; 436 lt_dlopen_flag = olt_dlopen_flag;
420*/ 437*/
421return tmp; 438return tmp;
422} 439}
423 440
424 441
425KLibrary* KLibLoader::library( const char *name ) 442KLibrary* KLibLoader::library( const char *name )
426{ 443{
427 if (!name) 444 if (!name)
428 return 0; 445 return 0;
429 446
430 KLibWrapPrivate* wrap = m_libs[name]; 447 KLibWrapPrivate* wrap = m_libs[name];
431 if (wrap) { 448 if (wrap) {
432 /* Nothing to do to load the library. */ 449 /* Nothing to do to load the library. */
433 wrap->ref_count++; 450 wrap->ref_count++;
434 return wrap->lib; 451 return wrap->lib;
435 } 452 }
436 453
437 /* Test if this library was loaded at some time, but got 454 /* Test if this library was loaded at some time, but got
438 unloaded meanwhile, whithout being dlclose()'ed. */ 455 unloaded meanwhile, whithout being dlclose()'ed. */
439 QPtrListIterator<KLibWrapPrivate> it(d->loaded_stack); 456 QPtrListIterator<KLibWrapPrivate> it(d->loaded_stack);
440 for (; it.current(); ++it) { 457 for (; it.current(); ++it) {
441 if (it.current()->name == name) 458 if (it.current()->name == name)
442 wrap = it.current(); 459 wrap = it.current();
443 } 460 }
444 461
445 if (wrap) { 462 if (wrap) {
446 d->pending_close.removeRef(wrap); 463 d->pending_close.removeRef(wrap);
447 if (!wrap->lib) { 464 if (!wrap->lib) {
448 /* This lib only was in loaded_stack, but not in m_libs. */ 465 /* This lib only was in loaded_stack, but not in m_libs. */
449 wrap->lib = new KLibrary( name, wrap->filename, wrap->handle ); 466 wrap->lib = new KLibrary( name, wrap->filename, wrap->handle );
450 } 467 }
451 wrap->ref_count++; 468 wrap->ref_count++;
452 } else { 469 } else {
453 QString libfile = findLibrary( name ); 470 QString libfile = findLibrary( name );
454 if ( libfile.isEmpty() ) 471 if ( libfile.isEmpty() )
455 return 0; 472 return 0;
456 473
457 const QString & qpeDir = QPEApplication::qpeDir();
458 libfile = qpeDir + libfile;
459//US QLibrary *lib = new QLibrary( qpeDir + "/plugins/korganizer/libopiekabc.so", QLibrary::Immediately );
460 QLibrary *qlib = new QLibrary( libfile.latin1(), QLibrary::Immediately ); 474 QLibrary *qlib = new QLibrary( libfile.latin1(), QLibrary::Immediately );
461 475
462//US lt_dlhandle handle = lt_dlopen( libfile.latin1() ); 476//US lt_dlhandle handle = lt_dlopen( libfile.latin1() );
463//US if ( !handle ) 477//US if ( !handle )
464 if ( !qlib ) 478 if ( !qlib )
465 { 479 {
466//US const char* errmsg = lt_dlerror(); 480//US const char* errmsg = lt_dlerror();
467 char* errmsg; 481 char* errmsg;
468 sprintf(errmsg, "KLibLoader::library could not load library: %s", libfile.latin1()); 482 sprintf(errmsg, "KLibLoader::library could not load library: %s", libfile.latin1());
469 qDebug(errmsg); 483 qDebug(errmsg);
470 484
471 if(errmsg) 485 if(errmsg)
472 d->errorMessage = QString::fromLatin1(errmsg); 486 d->errorMessage = QString::fromLatin1(errmsg);
473 else 487 else
474 d->errorMessage = QString::null; 488 d->errorMessage = QString::null;
475 kdWarning(150) << "library=" << name << ": file=" << libfile << ": " << d->errorMessage << endl; 489 kdWarning(150) << "library=" << name << ": file=" << libfile << ": " << d->errorMessage << endl;
476 return 0; 490 return 0;
477 } 491 }
478 else 492 else
479 d->errorMessage = QString::null; 493 d->errorMessage = QString::null;
480 494
481 KLibrary *lib = new KLibrary( name, libfile, qlib ); 495 KLibrary *lib = new KLibrary( name, libfile, qlib );
482 wrap = new KLibWrapPrivate(lib, qlib); 496 wrap = new KLibWrapPrivate(lib, qlib);
483 d->loaded_stack.prepend(wrap); 497 d->loaded_stack.prepend(wrap);
484 } 498 }
485 m_libs.insert( name, wrap ); 499 m_libs.insert( name, wrap );
486 500
487 connect( wrap->lib, SIGNAL( destroyed() ), 501 connect( wrap->lib, SIGNAL( destroyed() ),
488 this, SLOT( slotLibraryDestroyed() ) ); 502 this, SLOT( slotLibraryDestroyed() ) );
489 503
490 return wrap->lib; 504 return wrap->lib;
491} 505}
492 506
493QString KLibLoader::lastErrorMessage() const 507QString KLibLoader::lastErrorMessage() const
494{ 508{
495 return d->errorMessage; 509 return d->errorMessage;
496} 510}
497 511
498void KLibLoader::unloadLibrary( const char *libname ) 512void KLibLoader::unloadLibrary( const char *libname )
499{ 513{
500 KLibWrapPrivate *wrap = m_libs[ libname ]; 514 KLibWrapPrivate *wrap = m_libs[ libname ];
501 if (!wrap) 515 if (!wrap)
502 return; 516 return;
503 if (--wrap->ref_count) 517 if (--wrap->ref_count)
504 return; 518 return;
505 519
506// kdDebug(150) << "closing library " << libname << endl; 520// kdDebug(150) << "closing library " << libname << endl;
507 521
508 m_libs.remove( libname ); 522 m_libs.remove( libname );
509 523
510 disconnect( wrap->lib, SIGNAL( destroyed() ), 524 disconnect( wrap->lib, SIGNAL( destroyed() ),
511 this, SLOT( slotLibraryDestroyed() ) ); 525 this, SLOT( slotLibraryDestroyed() ) );
512 close_pending( wrap ); 526 close_pending( wrap );
513} 527}
514 528
515KLibFactory* KLibLoader::factory( const char* name ) 529KLibFactory* KLibLoader::factory( const char* name )
516{ 530{
517 KLibrary* lib = library( name ); 531 KLibrary* lib = library( name );
518 if ( !lib ) 532 if ( !lib )
519 return 0; 533 return 0;
520 534
521 return lib->factory(); 535 return lib->factory();
522} 536}
523 537
524void KLibLoader::slotLibraryDestroyed() 538void KLibLoader::slotLibraryDestroyed()
525{ 539{
526 const KLibrary *lib = static_cast<const KLibrary *>( sender() ); 540 const KLibrary *lib = static_cast<const KLibrary *>( sender() );
527 541
528 QAsciiDictIterator<KLibWrapPrivate> it( m_libs ); 542 QAsciiDictIterator<KLibWrapPrivate> it( m_libs );
529 for (; it.current(); ++it ) 543 for (; it.current(); ++it )
530 if ( it.current()->lib == lib ) 544 if ( it.current()->lib == lib )
531 { 545 {
532 KLibWrapPrivate *wrap = it.current(); 546 KLibWrapPrivate *wrap = it.current();
533 wrap->lib = 0; /* the KLibrary object is already away */ 547 wrap->lib = 0; /* the KLibrary object is already away */
534 m_libs.remove( it.currentKey() ); 548 m_libs.remove( it.currentKey() );
535 close_pending( wrap ); 549 close_pending( wrap );
536 return; 550 return;
537 } 551 }
538} 552}
539 553
540void KLibLoader::close_pending(KLibWrapPrivate *wrap) 554void KLibLoader::close_pending(KLibWrapPrivate *wrap)
541{ 555{
542 if (wrap && !d->pending_close.containsRef( wrap )) 556 if (wrap && !d->pending_close.containsRef( wrap ))
543 d->pending_close.append( wrap ); 557 d->pending_close.append( wrap );
544 558
545 /* First delete all KLibrary objects in pending_close, but _don't_ unload 559 /* First delete all KLibrary objects in pending_close, but _don't_ unload
546 the DSO behind it. */ 560 the DSO behind it. */
547 QPtrListIterator<KLibWrapPrivate> it(d->pending_close); 561 QPtrListIterator<KLibWrapPrivate> it(d->pending_close);
548 for (; it.current(); ++it) { 562 for (; it.current(); ++it) {
549 wrap = it.current(); 563 wrap = it.current();
550 if (wrap->lib) { 564 if (wrap->lib) {
551 disconnect( wrap->lib, SIGNAL( destroyed() ), 565 disconnect( wrap->lib, SIGNAL( destroyed() ),
552 this, SLOT( slotLibraryDestroyed() ) ); 566 this, SLOT( slotLibraryDestroyed() ) );
553 delete wrap->lib; 567 delete wrap->lib;
554 wrap->lib = 0; 568 wrap->lib = 0;
555 } 569 }