kitchensync

syncprocess.cpp
1/*
2 This file is part of KitchenSync.
3
4 Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19*/
20
21#include <libqopensync/engine.h>
22#include <libqopensync/environment.h>
23
24#include <kdebug.h>
25#include <tdelocale.h>
26
27#include "syncprocess.h"
28#include "syncprocessmanager.h"
29
30using namespace QSync;
31
32SyncProcess::SyncProcess( const QSync::Group &group )
33 : TQObject( 0, "SyncProcess" )
34{
35 mGroup = group;
36 mEngine = new QSync::Engine( mGroup );
37
38 Result result = mEngine->initialize();
39 if ( result.isError() )
40 kdDebug() << "SyncProcess::SyncProcess: " << result.message() << endl;
41}
42
43SyncProcess::~SyncProcess()
44{
45 mEngine->finalize();
46
47 delete mEngine;
48 mEngine = 0;
49}
50
51TQString SyncProcess::groupStatus() const
52{
53 return i18n( "Ready" );
54}
55
56TQString SyncProcess::memberStatus( const QSync::Member& ) const
57{
58 return i18n( "Ready" );
59}
60
61QSync::Result SyncProcess::addMember( const QSync::Plugin &plugin )
62{
63 QSync::Member member = mGroup.addMember();
64 QSync::Result result = member.instance( plugin );
65
66 if ( !result.isError() )
67 mGroup.save();
68
69 return result;
70}
71
72void SyncProcess::reinitEngine()
73{
74 mEngine->finalize();
75 delete mEngine;
76 mEngine = new QSync::Engine( mGroup );
77 Result result = mEngine->initialize();
78 if ( result.isError() )
79 kdDebug() << "SyncProcess::reinitEngine: " << result.message() << endl;
80
81 applyObjectTypeFilter();
82
83 emit engineChanged( mEngine );
84}
85
86void SyncProcess::applyObjectTypeFilter()
87{
88 const QSync::Conversion conversion = SyncProcessManager::self()->environment()->conversion();
89 const TQStringList objectTypes = conversion.objectTypes();
90 const TQStringList activeObjectTypes = mGroup.config().activeObjectTypes();
91
92 for ( uint i = 0; i < objectTypes.count(); ++i ) {
93 if ( activeObjectTypes.contains( objectTypes[ i ] ) ) {
94 kdDebug() << "Enabled object type: " << objectTypes[ i ] << endl;
95 /*
96 * This is not required. Also this lead to filtering problems when sync with "file-sync".
97 * Uncomment this line again when OpenSync is fixed!
98 *
99 * mGroup.setObjectTypeEnabled( objectTypes[ i ], true );
100 */
101 } else {
102 kdDebug() << "Disabled object type: " << objectTypes[ i ] << endl;
103 mGroup.setObjectTypeEnabled( objectTypes[ i ], false );
104 }
105 }
106}
107
108#include "syncprocess.moc"