kitchensync

konnector.cpp

00001 /*
00002     This file is part of KitchenSync.
00003 
00004     Copyright (c) 2002 Holger Freyther <zecke@handhelds.org>
00005     Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
00006 
00007     This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Library General Public
00009     License as published by the Free Software Foundation; either
00010     version 2 of the License, or (at your option) any later version.
00011 
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     Library General Public License for more details.
00016 
00017     You should have received a copy of the GNU Library General Public License
00018     along with this library; see the file COPYING.LIB.  If not, write to
00019     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020     Boston, MA 02110-1301, USA.
00021 */
00022 
00023 #include "konnector.h"
00024 
00025 #include "filter.h"
00026 #include "filtermanager.h"
00027 #include "konnectorinfo.h"
00028 
00029 #include <kmdcodec.h>
00030 #include <kdebug.h>
00031 #include <libkdepim/progressmanager.h>
00032 
00033 #include <qdir.h>
00034 
00035 using namespace KPIM;
00036 using namespace KSync;
00037 
00038 Konnector::Konnector( const KConfig *config )
00039   : KRES::Resource( config )
00040 {
00041   /* default storage path */
00042   m_sPath = QDir::homeDirPath() + "/.kitchensync/meta/";
00043 }
00044 
00045 Konnector::~Konnector()
00046 {
00047   for ( KSync::Filter::List::Iterator it = m_filterList.begin();
00048         it != m_filterList.end(); ++it )
00049     delete *it;
00050 
00051   m_filterList.clear();
00052 }
00053 
00054 void Konnector::initDefaultFilters()
00055 {
00056   const QStringList types = supportedFilterTypes();
00057 
00058   QStringList::ConstIterator it;
00059   for ( it = types.begin(); it != types.end(); ++it ) {
00060     Filter *filter = FilterManager::self()->create( *it );
00061     if ( filter )
00062       addFilter( filter );
00063   }
00064 }
00065 
00066 void Konnector::writeConfig( KConfig *config )
00067 {
00068   KRES::Resource::writeConfig( config );
00069 }
00070 
00071 void Konnector::add( const QString& res )
00072 {
00073     m_resources << res;
00074 }
00075 
00076 void Konnector::remove( const QString& res )
00077 {
00078     m_resources.remove( res );
00079 }
00080 
00081 QStringList Konnector::resources() const
00082 {
00083     return m_resources;
00084 }
00085 
00086 bool Konnector::isConnected() const
00087 {
00088     return info().isConnected();
00089 }
00090 
00091 QStringList Konnector::builtIn() const
00092 {
00093     return QStringList();
00094 }
00095 
00096 QString Konnector::storagePath()const
00097 {
00098   return m_sPath;
00099 }
00100 
00101 void Konnector::setStoragePath( const QString& path )
00102 {
00103   m_sPath = path;
00104   emit storagePathChanged( m_sPath );
00105 }
00106 
00107 KPIM::ProgressItem* Konnector::progressItem( const QString &msg )
00108 {
00109   ProgressItem *item = ProgressManager::instance()->createProgressItem(
00110                        ProgressManager::getUniqueID(), msg );
00111 
00112   connect( item, SIGNAL( progressItemCanceled(KPIM::ProgressItem* ) ),
00113            SLOT( progressItemCanceled( KPIM::ProgressItem* ) ) );
00114 
00115   return item;
00116 }
00117 
00118 void Konnector::progressItemCanceled( ProgressItem *item )
00119 {
00120   item->setComplete();
00121 }
00122 
00134 void Konnector::appendSyncee( Syncee* ap )
00135 {
00136   delete ap;
00137 /* DEFAULT NO IMPLEMENTATION */
00138 }
00139 
00147 QString Konnector::generateMD5Sum( const QString& base )
00148 {
00149   KMD5 sum( base.local8Bit() );
00150   QString str = QString::fromLatin1( sum.hexDigest().data() );
00151 
00152   return str;
00153 }
00154 
00160 void Konnector::purgeRemovedEntries( Syncee* sync )
00161 {
00162   QPtrList<SyncEntry> lst = sync->removed();
00163   SyncEntry* entry;
00164 
00165   for ( entry = lst.first(); entry; entry = lst.next() ) {
00166     kdDebug() << "purgeRemoved Entries " << entry->id() << " " << entry->name() << endl;
00167     sync->removeEntry( entry );
00168   }
00169 
00170 
00171   lst.setAutoDelete( true );
00172   lst.clear();
00173 }
00174 
00175 void Konnector::addFilter( KSync::Filter* filter )
00176 {
00177   m_filterList.append( filter );
00178 }
00179 
00180 void Konnector::removeFilter( KSync::Filter* filter )
00181 {
00182   m_filterList.remove( filter );
00183 }
00184 
00185 KSync::Filter::List Konnector::filters() const
00186 {
00187   return m_filterList;
00188 }
00189 
00190 KSync::Filter* Konnector::filter( const QString &type )
00191 {
00192   Filter::List::Iterator it;
00193   for ( it = m_filterList.begin(); it != m_filterList.end(); ++it )
00194     if ( (*it)->type() == type )
00195       return *it;
00196 
00197   return 0;
00198 }
00199 
00200 /*
00201  * Now apply the Filter
00202  */
00203 void Konnector::applyFilters( FilterMode mode )
00204 {
00205   SynceeList lst = syncees();
00206 
00207   /*
00208    * anyway to do that without the if in front? and without
00209    * checking the mode each time?
00210    */
00211   if ( mode == FilterBeforeSync ) {
00212     for ( SynceeList::Iterator syncIt = lst.begin(); syncIt != lst.end(); ++syncIt )
00213       for ( Filter::List::Iterator filtIt = m_filterList.begin(); filtIt != m_filterList.end(); ++filtIt )
00214         if ( (*filtIt)->supports( *syncIt ) )
00215           (*filtIt)->convert( *syncIt );
00216   } else if ( mode == FilterAfterSync ) {
00217     for ( SynceeList::Iterator syncIt = lst.begin(); syncIt != lst.end(); ++syncIt )
00218       for ( Filter::List::Iterator filtIt = m_filterList.begin(); filtIt != m_filterList.end(); ++filtIt )
00219         if ( (*filtIt)->supports( *syncIt ) )
00220           (*filtIt)->reconvert( *syncIt );
00221   }
00222 }
00223 
00224 #include "konnector.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys