syncchange.cpp
00001 /* 00002 This file is part of libqopensync. 00003 00004 Copyright (c) 2005 Tobias Koenig <tokoe@kde.org> 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Library General Public 00008 License as published by the Free Software Foundation; either 00009 version 2 of the License, or (at your option) any later version. 00010 00011 This library 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 GNU 00014 Library General Public License for more details. 00015 00016 You should have received a copy of the GNU Library General Public License 00017 along with this library; see the file COPYING.LIB. If not, write to 00018 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 Boston, MA 02110-1301, USA. 00020 */ 00021 00022 #include <opensync/file.h> 00023 #include <opensync/opensync.h> 00024 00025 #include "syncchange.h" 00026 00027 using namespace QSync; 00028 00029 SyncChange::SyncChange() 00030 { 00031 } 00032 00033 SyncChange::SyncChange( OSyncChange *change ) 00034 { 00035 mSyncChange = change; 00036 } 00037 00038 SyncChange::~SyncChange() 00039 { 00040 } 00041 00042 bool SyncChange::isValid() const 00043 { 00044 return ( mSyncChange != 0 ); 00045 } 00046 00047 void SyncChange::setUid( const TQString &uid ) 00048 { 00049 osync_change_set_uid( mSyncChange, uid.utf8() ); 00050 } 00051 00052 TQString SyncChange::uid() const 00053 { 00054 return TQString::fromUtf8( osync_change_get_uid( mSyncChange ) ); 00055 } 00056 00057 void SyncChange::setHash( const TQString &hash ) 00058 { 00059 osync_change_set_hash( mSyncChange, hash.utf8() ); 00060 } 00061 00062 TQString SyncChange::hash() const 00063 { 00064 return TQString::fromUtf8( osync_change_get_hash( mSyncChange ) ); 00065 } 00066 00067 void SyncChange::setData( const TQString &data ) 00068 { 00069 osync_change_set_data( mSyncChange, const_cast<char*>( data.utf8().data() ), data.utf8().size(), true ); 00070 } 00071 00072 TQString SyncChange::data() const 00073 { 00074 int size = osync_change_get_datasize( mSyncChange ); 00075 00076 TQString content; 00077 if ( objectFormatName() == "file" ) { 00078 fileFormat *format = (fileFormat*)osync_change_get_data( mSyncChange ); 00079 if ( format ) 00080 content = TQString::fromUtf8( format->data, format->size ); 00081 } else 00082 content = TQString::fromUtf8( osync_change_get_data( mSyncChange ), size ); 00083 00084 return content; 00085 } 00086 00087 bool SyncChange::hasData() const 00088 { 00089 return osync_change_has_data( mSyncChange ); 00090 } 00091 00092 TQString SyncChange::objectFormatName() const 00093 { 00094 OSyncObjFormat *format = osync_change_get_objformat( mSyncChange ); 00095 Q_ASSERT( format ); 00096 00097 return TQString::fromUtf8( osync_objformat_get_name( format ) ); 00098 } 00099 00100 Member SyncChange::member() const 00101 { 00102 OSyncMember *omember = osync_change_get_member( mSyncChange ); 00103 00104 Member m; 00105 m.mMember = omember; 00106 00107 return m; 00108 } 00109 00110 void SyncChange::setChangeType( Type changeType ) 00111 { 00112 OSyncChangeType ochangeType; 00113 00114 switch ( changeType ) { 00115 case AddedChange: 00116 ochangeType = CHANGE_ADDED; 00117 break; 00118 case UnmodifiedChange: 00119 ochangeType = CHANGE_UNMODIFIED; 00120 break; 00121 case DeletedChange: 00122 ochangeType = CHANGE_DELETED; 00123 break; 00124 case ModifiedChange: 00125 ochangeType = CHANGE_MODIFIED; 00126 break; 00127 case UnknownChange: 00128 default: 00129 ochangeType = CHANGE_UNKNOWN; 00130 break; 00131 } 00132 00133 osync_change_set_changetype( mSyncChange, ochangeType ); 00134 } 00135 00136 SyncChange::Type SyncChange::changeType() const 00137 { 00138 OSyncChangeType ochangeType = osync_change_get_changetype( mSyncChange ); 00139 00140 switch ( ochangeType ) { 00141 case CHANGE_ADDED: 00142 return AddedChange; 00143 break; 00144 case CHANGE_UNMODIFIED: 00145 return UnmodifiedChange; 00146 break; 00147 case CHANGE_DELETED: 00148 return DeletedChange; 00149 break; 00150 case CHANGE_MODIFIED: 00151 return ModifiedChange; 00152 break; 00153 case CHANGE_UNKNOWN: 00154 default: 00155 return UnknownChange; 00156 break; 00157 } 00158 } 00159