syncchange.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 <opensync/file.h>
23#include <opensync/opensync.h>
24
25#include "syncchange.h"
26
27using namespace QSync;
28
29SyncChange::SyncChange()
30{
31}
32
33SyncChange::SyncChange( OSyncChange *change )
34{
35 mSyncChange = change;
36}
37
38SyncChange::~SyncChange()
39{
40}
41
42bool SyncChange::isValid() const
43{
44 return ( mSyncChange != 0 );
45}
46
47void SyncChange::setUid( const TQString &uid )
48{
49 osync_change_set_uid( mSyncChange, uid.utf8() );
50}
51
52TQString SyncChange::uid() const
53{
54 return TQString::fromUtf8( osync_change_get_uid( mSyncChange ) );
55}
56
57void SyncChange::setHash( const TQString &hash )
58{
59 osync_change_set_hash( mSyncChange, hash.utf8() );
60}
61
62TQString SyncChange::hash() const
63{
64 return TQString::fromUtf8( osync_change_get_hash( mSyncChange ) );
65}
66
67void SyncChange::setData( const TQString &data )
68{
69 osync_change_set_data( mSyncChange, const_cast<char*>( data.utf8().data() ), data.utf8().size(), true );
70}
71
72TQString SyncChange::data() const
73{
74 int size = osync_change_get_datasize( mSyncChange );
75
76 TQString content;
77 if ( objectFormatName() == "file" ) {
78 fileFormat *format = (fileFormat*)osync_change_get_data( mSyncChange );
79 if ( format )
80 content = TQString::fromUtf8( format->data, format->size );
81 } else
82 content = TQString::fromUtf8( osync_change_get_data( mSyncChange ), size );
83
84 return content;
85}
86
87bool SyncChange::hasData() const
88{
89 return osync_change_has_data( mSyncChange );
90}
91
92TQString SyncChange::objectFormatName() const
93{
94 OSyncObjFormat *format = osync_change_get_objformat( mSyncChange );
95 Q_ASSERT( format );
96
97 return TQString::fromUtf8( osync_objformat_get_name( format ) );
98}
99
100Member SyncChange::member() const
101{
102 OSyncMember *omember = osync_change_get_member( mSyncChange );
103
104 Member m;
105 m.mMember = omember;
106
107 return m;
108}
109
110void SyncChange::setChangeType( Type changeType )
111{
112 OSyncChangeType ochangeType;
113
114 switch ( changeType ) {
115 case AddedChange:
116 ochangeType = CHANGE_ADDED;
117 break;
118 case UnmodifiedChange:
119 ochangeType = CHANGE_UNMODIFIED;
120 break;
121 case DeletedChange:
122 ochangeType = CHANGE_DELETED;
123 break;
124 case ModifiedChange:
125 ochangeType = CHANGE_MODIFIED;
126 break;
127 case UnknownChange:
128 default:
129 ochangeType = CHANGE_UNKNOWN;
130 break;
131 }
132
133 osync_change_set_changetype( mSyncChange, ochangeType );
134}
135
136SyncChange::Type SyncChange::changeType() const
137{
138 OSyncChangeType ochangeType = osync_change_get_changetype( mSyncChange );
139
140 switch ( ochangeType ) {
141 case CHANGE_ADDED:
142 return AddedChange;
143 break;
144 case CHANGE_UNMODIFIED:
145 return UnmodifiedChange;
146 break;
147 case CHANGE_DELETED:
148 return DeletedChange;
149 break;
150 case CHANGE_MODIFIED:
151 return ModifiedChange;
152 break;
153 case CHANGE_UNKNOWN:
154 default:
155 return UnknownChange;
156 break;
157 }
158}
159