kitchensync Library API Documentation

konnectormanager.cpp

00001 /* 00002 This file is part of KitchenSync. 00003 00004 Copyright (c) 2002 Holger Freyther <zecke@handhelds.org> 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Library General Public 00008 License as published by the Free Software Foundation; either 00009 version 2 of the License, or (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Library General Public License for more details. 00015 00016 You should have received a copy of the GNU Library General Public License 00017 along with this library; see the file COPYING.LIB. If not, write to 00018 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00019 Boston, MA 02111-1307, USA. 00020 */ 00021 00022 #include <qdir.h> 00023 00024 #include <kapplication.h> 00025 #include <kdebug.h> 00026 #include <kparts/componentfactory.h> 00027 #include <kstandarddirs.h> 00028 00029 #include "configpart.h" 00030 #include "konnectorinfo.h" 00031 00032 #include "konnectormanager.h" 00033 00034 using namespace KSync; 00035 00036 static KStaticDeleter<KonnectorManager> deleter; 00037 KonnectorManager* KonnectorManager::m_self = 0; 00038 00039 KonnectorManager::KonnectorManager() 00040 : KRES::Manager<Konnector>( "konnector" ) 00041 { 00042 m_auto = false; 00043 m_filter.setAutoDelete( true ); 00044 m_konnectors.setAutoDelete( true ); 00045 00046 readConfig(); 00047 00048 connectSignals(); 00049 } 00050 00051 KonnectorManager::~KonnectorManager() 00052 { 00053 } 00054 00055 KonnectorManager* KonnectorManager::self() 00056 { 00057 if ( !m_self ) deleter.setObject( m_self, new KonnectorManager() ); 00058 00059 return m_self; 00060 } 00061 00062 Device::ValueList KonnectorManager::query() 00063 { 00064 return allDevices(); 00065 } 00066 00067 Konnector *KonnectorManager::load( const Device& dev ) 00068 { 00069 Konnector *plugin = KParts::ComponentFactory:: 00070 createInstanceFromLibrary<Konnector>( dev.library().local8Bit(), this ); 00071 if ( !plugin ) return 0; 00072 00073 connect( plugin, SIGNAL( synceesRead( Konnector * ) ), 00074 SLOT( slotSync( Konnector * ) ) ); 00075 connect( plugin, SIGNAL( sig_progress( Konnector *, const Progress & ) ), 00076 SLOT( slotProgress( Konnector *, const Progress & ) ) ); 00077 connect( plugin, SIGNAL( sig_error( Konnector *, const Error & ) ), 00078 SLOT( slotError( Konnector *, const Error& ) ) ); 00079 connect( plugin, SIGNAL( sig_downloaded( Konnector *, const SynceeList & ) ), 00080 SLOT( slotDownloaded( Konnector *, const SynceeList & ) ) ); 00081 00082 m_konnectors.append( plugin ); 00083 00084 return plugin; 00085 } 00086 00087 Konnector *KonnectorManager::load( const QString& deviceName ) 00088 { 00089 return load( find( deviceName ) ); 00090 } 00091 00092 bool KonnectorManager::unload( Konnector *k ) 00093 { 00094 return m_konnectors.remove( k ); 00095 } 00096 00097 bool KonnectorManager::autoLoadFilter() const 00098 { 00099 return m_auto; 00100 } 00101 00102 void KonnectorManager::setAutoLoadFilter( bool aut ) 00103 { 00104 m_auto = aut; 00105 } 00106 00107 void KonnectorManager::add( Filter* filter) 00108 { 00109 m_filAdded.append( filter ); 00110 } 00111 00112 void KonnectorManager::deleteFilter( Filter* filter) 00113 { 00114 m_filAdded.remove( filter ); // autoDelete is on! 00115 } 00116 00117 const Filter::PtrList KonnectorManager::filters() 00118 { 00119 return m_filAdded; 00120 } 00121 00122 void KonnectorManager::write( Konnector * /*plugin*/, const SynceeList & ) 00123 { 00124 // Konnectors should be directly called. 00125 #if 0 00126 kdDebug(5201) << "KonnectorManager::write" << endl; 00127 if ( !plugin ) { 00128 kdDebug(5201) << " Did not contain the plugin " << endl; 00129 emit error( plugin, StdError::konnectorDoesNotExist() ); 00130 emit progress( plugin, StdProgress::done() ); 00131 return; 00132 } 00133 kdDebug(5201) << "Konnector: " << plugin->info().name() << endl; 00134 plugin->writeSyncees(); 00135 #endif 00136 } 00137 00138 /* 00139 * find all available desktop files 00140 * we'll find the kitchensync dir 00141 * and then parse each .desktop file 00142 */ 00143 Device::ValueList KonnectorManager::allDevices() 00144 { 00145 m_devices.clear(); // clean up first 00146 00147 QStringList list = KGlobal::dirs()->findDirs("data", "kitchensync" ); 00148 00149 /* for each dir */ 00150 for (QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { 00151 QDir dir( (*it), "*.desktop" ); // data dir of kitchensync + .desktop as a filter 00152 QStringList files = dir.entryList(); 00153 00154 QStringList::Iterator fileIt; 00155 /* for each file */ 00156 for (fileIt = files.begin(); fileIt != files.end(); ++fileIt ) 00157 m_devices.append( parseDevice( (*it) + (*fileIt ) ) ); 00158 } 00159 return m_devices; 00160 } 00161 00162 Device KonnectorManager::parseDevice( const QString &path ) 00163 { 00164 KService service( path ); 00165 00166 QString name = service.name(); 00167 QString lib = service.library(); 00168 QString group = service.property( QString::fromLatin1("Group" ) ).toString(); 00169 QString vendo = service.property( QString::fromLatin1("Vendor") ).toString(); 00170 QString id = service.property( QString::fromLatin1("Id" ) ).toString(); 00171 00172 kdDebug(5201) << "Id " << id << " " << name << endl; 00173 00174 return Device(name, group, vendo, lib, id ); 00175 } 00176 00177 Device KonnectorManager::find( const QString& device ) 00178 { 00179 Device dev; 00180 if ( m_devices.isEmpty() ) return dev; 00181 00182 Device::ValueList::Iterator it; 00183 for ( it = m_devices.begin(); it != m_devices.end(); ++it ) { 00184 if ( (*it).identify() == device ) { 00185 dev = (*it); 00186 break; 00187 } 00188 } 00189 return dev; 00190 } 00191 00192 void KonnectorManager::slotSync( Konnector *k, const SynceeList & list ) 00193 { 00194 const SynceeList & unknown = findUnknown( list ); 00195 filter( unknown, list ); 00196 emit sync( k, list ); 00197 } 00198 00199 void KonnectorManager::slotProgress( Konnector *k, const Progress &pro ) 00200 { 00201 emit progress( k, pro ); 00202 } 00203 00204 void KonnectorManager::slotError( Konnector *k, const Error &err ) 00205 { 00206 emit error( k, err ); 00207 } 00208 00209 void KonnectorManager::slotDownloaded( Konnector *k, const SynceeList & list) 00210 { 00211 const SynceeList & unknown = findUnknown( list ); 00212 filter( unknown, list ); 00213 emit downloaded( k, list ); 00214 } 00215 00216 /* 00217 * FIXME Cornelius take a look here when you want to implement 00218 * a generic KIO <-> Konnector FileBridge 00219 * The KIO Konnector only retrieves data and the Filter 00220 * filters for example the AddressBook or any other data... 00221 * 00222 * FIXME use filters!!!! 00223 */ 00224 void KonnectorManager::filter( const SynceeList & /*lst*/, 00225 const SynceeList & /*real*/ ) 00226 { 00227 kdError() << "KonnectorManager::filter() not implemented" << endl; 00228 } 00229 00230 SynceeList KonnectorManager::findUnknown( const SynceeList & ) 00231 { 00232 #if 0 00233 lst.setAutoDelete( false ); 00234 const SynceeList & list; 00235 Syncee* syn; 00236 for ( syn = lst.first(); syn; syn = lst.next() ) { 00237 if ( syn->type() == QString::fromLatin1("UnknownSyncEntry") ) { 00238 lst.remove( syn ); // setAutoDelete should be false 00239 list.append( syn ); 00240 } 00241 } 00242 return list; 00243 #endif 00244 return SynceeList(); 00245 } 00246 00247 void KonnectorManager::connectSignals() 00248 { 00249 Iterator it; 00250 for( it = begin(); it != end(); ++it ) { 00251 connect( *it, SIGNAL( synceesRead( Konnector * ) ), 00252 SIGNAL( synceesRead( Konnector * ) ) ); 00253 connect( *it, SIGNAL( synceeReadError( Konnector * ) ), 00254 SIGNAL( synceeReadError( Konnector * ) ) ); 00255 connect( *it, SIGNAL( synceesWritten( Konnector * ) ), 00256 SIGNAL( synceesWritten( Konnector * ) ) ); 00257 connect( *it, SIGNAL( synceeWriteError( Konnector * ) ), 00258 SIGNAL( synceeWriteError( Konnector * ) ) ); 00259 } 00260 } 00261 00262 #include "konnectormanager.moc"
KDE Logo
This file is part of the documentation for kitchensync Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Aug 27 12:50:48 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003