kitchensync
syncprocess.cpp
00001 /* 00002 This file is part of KitchenSync. 00003 00004 Copyright (c) 2005 Tobias Koenig <tokoe@kde.org> 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 00011 This program 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 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 */ 00020 00021 #include <libqopensync/engine.h> 00022 #include <libqopensync/environment.h> 00023 00024 #include <kdebug.h> 00025 #include <klocale.h> 00026 00027 #include "syncprocess.h" 00028 #include "syncprocessmanager.h" 00029 00030 using namespace QSync; 00031 00032 SyncProcess::SyncProcess( const QSync::Group &group ) 00033 : QObject( 0, "SyncProcess" ) 00034 { 00035 mGroup = group; 00036 mEngine = new QSync::Engine( mGroup ); 00037 00038 Result result = mEngine->initialize(); 00039 if ( result.isError() ) 00040 kdDebug() << "SyncProcess::SyncProcess: " << result.message() << endl; 00041 } 00042 00043 SyncProcess::~SyncProcess() 00044 { 00045 mEngine->finalize(); 00046 00047 delete mEngine; 00048 mEngine = 0; 00049 } 00050 00051 QString SyncProcess::groupStatus() const 00052 { 00053 return i18n( "Ready" ); 00054 } 00055 00056 QString SyncProcess::memberStatus( const QSync::Member& ) const 00057 { 00058 return i18n( "Ready" ); 00059 } 00060 00061 QSync::Result SyncProcess::addMember( const QSync::Plugin &plugin ) 00062 { 00063 QSync::Member member = mGroup.addMember(); 00064 QSync::Result result = member.instance( plugin ); 00065 00066 if ( !result.isError() ) 00067 mGroup.save(); 00068 00069 return result; 00070 } 00071 00072 void SyncProcess::reinitEngine() 00073 { 00074 mEngine->finalize(); 00075 delete mEngine; 00076 mEngine = new QSync::Engine( mGroup ); 00077 Result result = mEngine->initialize(); 00078 if ( result.isError() ) 00079 kdDebug() << "SyncProcess::reinitEngine: " << result.message() << endl; 00080 00081 applyObjectTypeFilter(); 00082 00083 emit engineChanged( mEngine ); 00084 } 00085 00086 void SyncProcess::applyObjectTypeFilter() 00087 { 00088 const QSync::Conversion conversion = SyncProcessManager::self()->environment()->conversion(); 00089 const QStringList objectTypes = conversion.objectTypes(); 00090 const QStringList activeObjectTypes = mGroup.config().activeObjectTypes(); 00091 00092 for ( uint i = 0; i < objectTypes.count(); ++i ) { 00093 if ( activeObjectTypes.contains( objectTypes[ i ] ) ) { 00094 kdDebug() << "Enabled object type: " << objectTypes[ i ] << endl; 00095 /* 00096 * This is not required. Also this lead to filtering problems when sync with "file-sync". 00097 * Uncomment this line again when OpenSync is fixed! 00098 * 00099 * mGroup.setObjectTypeEnabled( objectTypes[ i ], true ); 00100 */ 00101 } else { 00102 kdDebug() << "Disabled object type: " << objectTypes[ i ] << endl; 00103 mGroup.setObjectTypeEnabled( objectTypes[ i ], false ); 00104 } 00105 } 00106 } 00107 00108 #include "syncprocess.moc"