syncmapping.cpp
1/*
2 This file is part of libqopensync.
3
4 Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library 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 GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
20*/
21
22#include <tqstring.h>
23#include <osengine/engine.h>
24
25#include "syncmapping.h"
26
27using namespace QSync;
28
29SyncMapping::SyncMapping()
30 : mEngine( 0 ), mMapping( 0 )
31{
32}
33
34SyncMapping::SyncMapping( OSyncMapping *mapping, OSyncEngine *engine )
35 : mEngine( engine ), mMapping( mapping )
36{
37}
38
39SyncMapping::~SyncMapping()
40{
41}
42
43bool SyncMapping::isValid() const
44{
45 return ( mEngine != 0 && mMapping != 0 );
46}
47
48long long SyncMapping::id() const
49{
50 Q_ASSERT( mMapping );
51
52 return osengine_mapping_get_id( mMapping );
53}
54
55void SyncMapping::duplicate()
56{
57 Q_ASSERT( mEngine );
58 Q_ASSERT( mMapping );
59
60 osengine_mapping_duplicate( mEngine, mMapping );
61}
62
63void SyncMapping::solve( const SyncChange &change )
64{
65 Q_ASSERT( mEngine );
66 Q_ASSERT( mMapping );
67 Q_ASSERT( change.isValid() );
68
69 osengine_mapping_solve( mEngine, mMapping, change.mSyncChange );
70}
71
72void SyncMapping::ignore()
73{
74 Q_ASSERT( mEngine );
75 Q_ASSERT( mMapping );
76
77 //TODO: error should be returned as Result
78 OSyncError *error = 0;
79 osengine_mapping_ignore_conflict( mEngine, mMapping, &error );
80}
81
82int SyncMapping::changesCount() const
83{
84 Q_ASSERT( mMapping );
85
86 return osengine_mapping_num_changes( mMapping );
87}
88
89SyncChange SyncMapping::changeAt( int pos )
90{
91 Q_ASSERT( mMapping );
92
93 if ( pos < 0 || pos >= osengine_mapping_num_changes( mMapping ) )
94 return SyncChange();
95
96 OSyncChange *ochange = osengine_mapping_nth_change( mMapping, pos );
97
98 return SyncChange( ochange );
99}
100