summaryrefslogtreecommitdiffstats
path: root/kitchensync/libqopensync
diff options
context:
space:
mode:
Diffstat (limited to 'kitchensync/libqopensync')
-rw-r--r--kitchensync/libqopensync/Makefile.am19
-rw-r--r--kitchensync/libqopensync/callbackhandler.cpp191
-rw-r--r--kitchensync/libqopensync/callbackhandler.h90
-rw-r--r--kitchensync/libqopensync/conversion.cpp58
-rw-r--r--kitchensync/libqopensync/conversion.h56
-rw-r--r--kitchensync/libqopensync/engine.cpp67
-rw-r--r--kitchensync/libqopensync/engine.h72
-rw-r--r--kitchensync/libqopensync/environment.cpp172
-rw-r--r--kitchensync/libqopensync/environment.h199
-rw-r--r--kitchensync/libqopensync/filter.cpp55
-rw-r--r--kitchensync/libqopensync/filter.h64
-rw-r--r--kitchensync/libqopensync/group.cpp292
-rw-r--r--kitchensync/libqopensync/group.h217
-rw-r--r--kitchensync/libqopensync/member.cpp188
-rw-r--r--kitchensync/libqopensync/member.h129
-rw-r--r--kitchensync/libqopensync/plugin.cpp62
-rw-r--r--kitchensync/libqopensync/plugin.h67
-rw-r--r--kitchensync/libqopensync/result.cpp149
-rw-r--r--kitchensync/libqopensync/result.h126
-rw-r--r--kitchensync/libqopensync/syncchange.cpp159
-rw-r--r--kitchensync/libqopensync/syncchange.h116
-rw-r--r--kitchensync/libqopensync/syncmapping.cpp100
-rw-r--r--kitchensync/libqopensync/syncmapping.h59
-rw-r--r--kitchensync/libqopensync/syncupdates.cpp251
-rw-r--r--kitchensync/libqopensync/syncupdates.h157
25 files changed, 3115 insertions, 0 deletions
diff --git a/kitchensync/libqopensync/Makefile.am b/kitchensync/libqopensync/Makefile.am
new file mode 100644
index 000000000..2e12df6ca
--- /dev/null
+++ b/kitchensync/libqopensync/Makefile.am
@@ -0,0 +1,19 @@
+INCLUDES = -I$(top_srcdir)/kitchensync/src \
+ -I$(top_srcdir)/kitchensync \
+ -I$(top_srcdir) \
+ $(OPENSYNC_CFLAGS) \
+ $(OPENSYNCENGINE_CFLAGS) \
+ $(all_includes)
+
+lib_LTLIBRARIES = libqopensync.la
+
+libqopensync_la_SOURCES = callbackhandler.cpp conversion.cpp engine.cpp environment.cpp filter.cpp group.cpp \
+ member.cpp plugin.cpp result.cpp syncmapping.cpp syncupdates.cpp \
+ syncchange.cpp
+libqopensync_la_LDFLAGS = $(all_libraries) $(KDE_RPATH) -no-undefined
+libqopensync_la_LIBADD = $(LIB_KDEUI) $(OPENSYNC_LIBS) $(OPENSYNCENGINE_LIBS)
+
+METASOURCES = AUTO
+
+messages: rc.cpp
+ $(XGETTEXT) *.cpp *.h -o $(podir)/libqopensync.pot
diff --git a/kitchensync/libqopensync/callbackhandler.cpp b/kitchensync/libqopensync/callbackhandler.cpp
new file mode 100644
index 000000000..86f279f14
--- /dev/null
+++ b/kitchensync/libqopensync/callbackhandler.cpp
@@ -0,0 +1,191 @@
+/*
+ This file is part of libqopensync.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <osengine/engine.h>
+
+#include <libqopensync/engine.h>
+
+#include <qapplication.h>
+
+#include "callbackhandler.h"
+
+using namespace QSync;
+
+class CallbackHandler::ConflictEvent : public QCustomEvent
+{
+ public:
+ ConflictEvent( const SyncMapping& mapping )
+ : QCustomEvent( ConflictEventType ), mMapping( mapping )
+ {
+ }
+
+ SyncMapping mapping() const { return mMapping; }
+
+ private:
+ SyncMapping mMapping;
+};
+
+class CallbackHandler::ChangeEvent : public QCustomEvent
+{
+ public:
+ ChangeEvent( const SyncChangeUpdate& change )
+ : QCustomEvent( ChangeEventType ), mChange( change )
+ {
+ }
+
+ SyncChangeUpdate change() const { return mChange; }
+
+ private:
+ SyncChangeUpdate mChange;
+};
+
+class CallbackHandler::MappingEvent : public QCustomEvent
+{
+ public:
+ MappingEvent( const SyncMappingUpdate& mapping )
+ : QCustomEvent( MappingEventType ), mMapping( mapping )
+ {
+ }
+
+ SyncMappingUpdate mapping() const { return mMapping; }
+
+ private:
+ SyncMappingUpdate mMapping;
+};
+
+class CallbackHandler::EngineEvent : public QCustomEvent
+{
+ public:
+ EngineEvent( const SyncEngineUpdate& engine )
+ : QCustomEvent( EngineEventType ), mEngine( engine )
+ {
+ }
+
+ SyncEngineUpdate engine() const { return mEngine; }
+
+ private:
+ SyncEngineUpdate mEngine;
+};
+
+class CallbackHandler::MemberEvent : public QCustomEvent
+{
+ public:
+ MemberEvent( const SyncMemberUpdate& member )
+ : QCustomEvent( MemberEventType ), mMember( member )
+ {
+ }
+
+ SyncMemberUpdate member() const { return mMember; }
+
+ private:
+ SyncMemberUpdate mMember;
+};
+
+CallbackHandler::CallbackHandler()
+{
+}
+
+CallbackHandler::~CallbackHandler()
+{
+}
+
+void CallbackHandler::setEngine( Engine *engine )
+{
+ mEngine = engine;
+
+ osengine_set_conflict_callback( engine->mEngine, &conflict_callback, this );
+ osengine_set_changestatus_callback( engine->mEngine, &change_callback, this );
+ osengine_set_mappingstatus_callback( engine->mEngine, &mapping_callback, this );
+ osengine_set_enginestatus_callback( engine->mEngine, &engine_callback, this );
+ osengine_set_memberstatus_callback( engine->mEngine, &member_callback, this );
+}
+
+Engine* CallbackHandler::engine() const
+{
+ return mEngine;
+}
+
+void CallbackHandler::customEvent( QCustomEvent *event )
+{
+ if ( event->type() == static_cast<QEvent::Type>( ConflictEventType ) ) {
+ ConflictEvent *conflictEvent = static_cast<ConflictEvent*>( event );
+ emit conflict( conflictEvent->mapping() );
+ } else if ( event->type() == static_cast<QEvent::Type>( ChangeEventType ) ) {
+ ChangeEvent *changeEvent = static_cast<ChangeEvent*>( event );
+ emit change( changeEvent->change() );
+ } else if ( event->type() == static_cast<QEvent::Type>( MappingEventType ) ) {
+ MappingEvent *mappingEvent = static_cast<MappingEvent*>( event );
+ emit mapping( mappingEvent->mapping() );
+ } else if ( event->type() == static_cast<QEvent::Type>( EngineEventType ) ) {
+ EngineEvent *engineEvent = static_cast<EngineEvent*>( event );
+ emit engine( engineEvent->engine() );
+ } else if ( event->type() == static_cast<QEvent::Type>( MemberEventType ) ) {
+ MemberEvent *memberEvent = static_cast<MemberEvent*>( event );
+ emit member( memberEvent->member() );
+ }
+}
+
+void CallbackHandler::conflict_callback( OSyncEngine *engine, OSyncMapping *omapping, void *data )
+{
+ SyncMapping mapping( omapping, engine );
+
+ CallbackHandler *handler = static_cast<CallbackHandler*>( data );
+
+ QApplication::postEvent( handler, new ConflictEvent( mapping ) );
+}
+
+void CallbackHandler::change_callback( OSyncEngine*, OSyncChangeUpdate *update, void *data )
+{
+ SyncChangeUpdate change( update );
+
+ CallbackHandler *handler = static_cast<CallbackHandler*>( data );
+
+ QApplication::postEvent( handler, new ChangeEvent( change ) );
+}
+
+void CallbackHandler::mapping_callback( OSyncMappingUpdate *update, void *data )
+{
+ CallbackHandler *handler = static_cast<CallbackHandler*>( data );
+
+ SyncMappingUpdate mapping( update, handler->engine()->mEngine );
+
+ QApplication::postEvent( handler, new MappingEvent( mapping ) );
+}
+
+void CallbackHandler::engine_callback( OSyncEngine*, OSyncEngineUpdate *update, void *data )
+{
+ SyncEngineUpdate engine( update );
+
+ CallbackHandler *handler = static_cast<CallbackHandler*>( data );
+
+ QApplication::postEvent( handler, new EngineEvent( engine ) );
+}
+
+void CallbackHandler::member_callback( OSyncMemberUpdate *update, void *data )
+{
+ SyncMemberUpdate member( update );
+
+ CallbackHandler *handler = static_cast<CallbackHandler*>( data );
+
+ QApplication::postEvent( handler, new MemberEvent( member ) );
+}
+
+#include "callbackhandler.moc"
diff --git a/kitchensync/libqopensync/callbackhandler.h b/kitchensync/libqopensync/callbackhandler.h
new file mode 100644
index 000000000..a31132559
--- /dev/null
+++ b/kitchensync/libqopensync/callbackhandler.h
@@ -0,0 +1,90 @@
+/*
+ This file is part of libqopensync.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef QSYNC_CALLBACKHANDLER_H
+#define QSYNC_CALLBACKHANDLER_H
+
+#include <libqopensync/syncmapping.h>
+#include <libqopensync/syncupdates.h>
+
+#include <qobject.h>
+
+class OSyncEngine;
+class OSyncMapping;
+class OSyncChangeUpdate;
+class OSyncMappingUpdate;
+class OSyncEngineUpdate;
+class OSyncMemberUpdate;
+
+class QCustomEvent;
+
+namespace QSync {
+
+class Engine;
+
+class CallbackHandler : public QObject
+{
+ Q_OBJECT
+
+ public:
+ CallbackHandler();
+ ~CallbackHandler();
+
+ void setEngine( Engine *engine );
+ Engine* engine() const;
+
+ signals:
+ void conflict( QSync::SyncMapping mapping );
+ void change( const QSync::SyncChangeUpdate &update );
+ void mapping( const QSync::SyncMappingUpdate &update );
+ void engine( const QSync::SyncEngineUpdate &update );
+ void member( const QSync::SyncMemberUpdate &update );
+
+ protected:
+ virtual void customEvent( QCustomEvent *event );
+
+ private:
+ enum EventType {
+ ConflictEventType = 4044,
+ ChangeEventType,
+ MappingEventType,
+ EngineEventType,
+ MemberEventType
+ };
+
+ class ConflictEvent;
+ class ChangeEvent;
+ class MappingEvent;
+ class EngineEvent;
+ class MemberEvent;
+
+ static void conflict_callback( OSyncEngine*, OSyncMapping*, void* );
+ static void change_callback( OSyncEngine*, OSyncChangeUpdate*, void* );
+ static void mapping_callback( OSyncMappingUpdate*, void* );
+ static void engine_callback( OSyncEngine*, OSyncEngineUpdate*, void* );
+ static void member_callback( OSyncMemberUpdate*, void* );
+
+ Engine* mEngine;
+};
+
+}
+
+#endif
diff --git a/kitchensync/libqopensync/conversion.cpp b/kitchensync/libqopensync/conversion.cpp
new file mode 100644
index 000000000..bf4eb948a
--- /dev/null
+++ b/kitchensync/libqopensync/conversion.cpp
@@ -0,0 +1,58 @@
+/*
+ This file is part of libqopensync.
+
+ Copyright (c) 2006 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <opensync/opensync.h>
+
+#include "conversion.h"
+
+using namespace QSync;
+
+Conversion::Conversion()
+ : mEnvironment( 0 )
+{
+}
+
+Conversion::~Conversion()
+{
+}
+
+bool Conversion::isValid() const
+{
+ return mEnvironment != 0;
+}
+
+QStringList Conversion::objectTypes() const
+{
+ Q_ASSERT( mEnvironment );
+
+ OSyncFormatEnv *formatEnv = osync_conv_env_new( mEnvironment );
+ Q_ASSERT( formatEnv );
+
+ QStringList types;
+ for ( int i = 0; i < osync_conv_num_objtypes( formatEnv ); i++ ) {
+ OSyncObjType *type = osync_conv_nth_objtype( formatEnv, i );
+ types.append( QString::fromUtf8( osync_objtype_get_name( type ) ) );
+ }
+
+ osync_conv_env_free( formatEnv );
+
+ return types;
+}
diff --git a/kitchensync/libqopensync/conversion.h b/kitchensync/libqopensync/conversion.h
new file mode 100644
index 000000000..327f8b475
--- /dev/null
+++ b/kitchensync/libqopensync/conversion.h
@@ -0,0 +1,56 @@
+/*
+ This file is part of libqopensync.
+
+ Copyright (c) 2006 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef QSYNC_CONVERSION_H
+#define QSYNC_CONVERSION_H
+
+#include <qstringlist.h>
+
+class OSyncEnv;
+
+namespace QSync {
+
+class Conversion
+{
+ friend class Environment;
+
+ public:
+ Conversion();
+ ~Conversion();
+
+ /**
+ Returns whether the object is a valid conversion.
+ */
+ bool isValid() const;
+
+ /**
+ Returns the list of names of supported object types.
+ */
+ QStringList objectTypes() const;
+
+ private:
+ OSyncEnv *mEnvironment;
+};
+
+}
+
+#endif
+
diff --git a/kitchensync/libqopensync/engine.cpp b/kitchensync/libqopensync/engine.cpp
new file mode 100644
index 000000000..6d48c72ff
--- /dev/null
+++ b/kitchensync/libqopensync/engine.cpp
@@ -0,0 +1,67 @@
+/*
+ This file is part of libqopensync.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <opensync/opensync.h>
+#include <osengine/engine.h>
+
+#include "engine.h"
+
+using namespace QSync;
+
+Engine::Engine( const Group &group )
+{
+ OSyncError *error = 0;
+ mEngine = osengine_new( group.mGroup, &error );
+}
+
+Engine::~Engine()
+{
+ osengine_free( mEngine );
+ mEngine = 0;
+}
+
+Result Engine::initialize()
+{
+ OSyncError *error = 0;
+ if ( !osengine_init( mEngine, &error ) )
+ return Result( &error );
+ else
+ return Result();
+}
+
+void Engine::finalize()
+{
+ osengine_finalize( mEngine );
+}
+
+Result Engine::synchronize()
+{
+ OSyncError *error = 0;
+ if ( !osengine_synchronize( mEngine, &error ) )
+ return Result( &error );
+ else
+ return Result();
+}
+
+void Engine::abort()
+{
+ osengine_abort( mEngine );
+}
diff --git a/kitchensync/libqopensync/engine.h b/kitchensync/libqopensync/engine.h
new file mode 100644
index 000000000..e62a5f689
--- /dev/null
+++ b/kitchensync/libqopensync/engine.h
@@ -0,0 +1,72 @@
+/*
+ This file is part of libqopensync.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef QSYNC_ENGINE_H
+#define QSYNC_ENGINE_H
+
+#include <libqopensync/group.h>
+
+class OSyncEngine;
+
+namespace QSync {
+
+class Engine
+{
+ friend class CallbackHandler;
+
+ public:
+ /**
+ Constructs an engine .
+ */
+ Engine( const Group &group );
+
+ /**
+ Destroys the engine.
+ */
+ ~Engine();
+
+ /**
+ Initializes the engine.
+ */
+ Result initialize();
+
+ /**
+ Finalizes the engine.
+ */
+ void finalize();
+
+ /**
+ Starts the synchronization process.
+ */
+ Result synchronize();
+
+ /**
+ Stops the synchronization process.
+ */
+ void abort();
+
+ private:
+ OSyncEngine *mEngine;
+};
+
+}
+
+#endif
diff --git a/kitchensync/libqopensync/environment.cpp b/kitchensync/libqopensync/environment.cpp
new file mode 100644
index 000000000..d878c61d5
--- /dev/null
+++ b/kitchensync/libqopensync/environment.cpp
@@ -0,0 +1,172 @@
+/*
+ This file is part of libqopensync.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "environment.h"
+
+#include <opensync/opensync.h>
+
+using namespace QSync;
+
+Environment::Environment()
+{
+ mEnvironment = osync_env_new();
+}
+
+Environment::~Environment()
+{
+ osync_env_free( mEnvironment );
+}
+
+Environment::GroupIterator Environment::groupBegin()
+{
+ GroupIterator it( this );
+ it.mPos = 0;
+
+ return it;
+}
+
+Environment::GroupIterator Environment::groupEnd()
+{
+ GroupIterator it( this );
+ it.mPos = groupCount();
+
+ return it;
+}
+
+Environment::PluginIterator Environment::pluginBegin()
+{
+ PluginIterator it( this );
+ it.mPos = 0;
+
+ return it;
+}
+
+Environment::PluginIterator Environment::pluginEnd()
+{
+ PluginIterator it( this );
+ it.mPos = pluginCount();
+
+ return it;
+}
+
+Result Environment::initialize()
+{
+ OSyncError *error = 0;
+ if ( !osync_env_initialize( mEnvironment, &error ) )
+ return Result( &error );
+ else
+ return Result();
+}
+
+Result Environment::finalize()
+{
+ OSyncError *error = 0;
+ if ( !osync_env_finalize( mEnvironment, &error ) )
+ return Result( &error);
+ else
+ return Result();
+}
+
+int Environment::groupCount() const
+{
+ return osync_env_num_groups( mEnvironment );
+}
+
+Group Environment::groupAt( int pos ) const
+{
+ Group group;
+
+ if ( pos < 0 || pos >= groupCount() )
+ return group;
+
+ OSyncGroup *ogroup = osync_env_nth_group( mEnvironment, pos );
+ group.mGroup = ogroup;
+
+ return group;
+}
+
+Group Environment::groupByName( const QString &name ) const
+{
+ Group group;
+
+ OSyncGroup *ogroup = osync_env_find_group( mEnvironment, name.latin1() );
+ if ( ogroup )
+ group.mGroup = ogroup;
+
+ return group;
+}
+
+Group Environment::addGroup()
+{
+ Group group;
+
+ OSyncGroup *ogroup = osync_group_new( mEnvironment );
+ if ( ogroup )
+ group.mGroup = ogroup;
+
+ return group;
+}
+
+Result Environment::removeGroup( const Group &group )
+{
+ OSyncError *error = 0;
+ if ( !osync_group_delete( group.mGroup, &error ) )
+ return Result( &error );
+ else
+ return Result();
+}
+
+int Environment::pluginCount() const
+{
+ return osync_env_num_plugins( mEnvironment );
+}
+
+Plugin Environment::pluginAt( int pos ) const
+{
+ Plugin plugin;
+
+ if ( pos < 0 || pos >= pluginCount() )
+ return plugin;
+
+ OSyncPlugin *oplugin = osync_env_nth_plugin( mEnvironment, pos );
+ plugin.mPlugin = oplugin;
+
+ return plugin;
+}
+
+Plugin Environment::pluginByName( const QString &name ) const
+{
+ Plugin plugin;
+
+ OSyncPlugin *oplugin = osync_env_find_plugin( mEnvironment, name.latin1() );
+ if ( oplugin )
+ plugin.mPlugin = oplugin;
+
+ return plugin;
+}
+
+Conversion Environment::conversion() const
+{
+ Conversion conversion;
+ conversion.mEnvironment = mEnvironment;
+
+ return conversion;
+}
diff --git a/kitchensync/libqopensync/environment.h b/kitchensync/libqopensync/environment.h
new file mode 100644
index 000000000..f412a32c0
--- /dev/null
+++ b/kitchensync/libqopensync/environment.h
@@ -0,0 +1,199 @@
+/*
+ This file is part of libqopensync.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef OSYNC_ENVIRONMENT_H
+#define OSYNC_ENVIRONMENT_H
+
+#include <qstring.h>
+
+#include <libqopensync/group.h>
+#include <libqopensync/plugin.h>
+#include <libqopensync/result.h>
+#include <libqopensync/conversion.h>
+
+struct OSyncEnv;
+
+namespace QSync {
+
+class Environment
+{
+ public:
+ Environment();
+ ~Environment();
+
+ class GroupIterator
+ {
+ friend class Environment;
+
+ public:
+ GroupIterator( Environment *environment )
+ : mEnvironment( environment ), mPos( -1 )
+ {
+ }
+
+ GroupIterator( const GroupIterator &it )
+ {
+ mEnvironment = it.mEnvironment;
+ mPos = it.mPos;
+ }
+
+ Group operator*()
+ {
+ return mEnvironment->groupAt( mPos );
+ }
+
+ GroupIterator &operator++() { mPos++; return *this; }
+ GroupIterator &operator++( int ) { mPos++; return *this; }
+ GroupIterator &operator--() { mPos--; return *this; }
+ GroupIterator &operator--( int ) { mPos--; return *this; }
+ bool operator==( const GroupIterator &it ) { return mEnvironment == it.mEnvironment && mPos == it.mPos; }
+ bool operator!=( const GroupIterator &it ) { return mEnvironment == it.mEnvironment && mPos != it.mPos; }
+
+ private:
+ Environment *mEnvironment;
+ int mPos;
+ };
+
+ class PluginIterator
+ {
+ friend class Environment;
+
+ public:
+ PluginIterator( Environment *environment )
+ : mEnvironment( environment ), mPos( -1 )
+ {
+ }
+
+ PluginIterator( const PluginIterator &it )
+ {
+ mEnvironment = it.mEnvironment;
+ mPos = it.mPos;
+ }
+
+ Plugin operator*()
+ {
+ return mEnvironment->pluginAt( mPos );
+ }
+
+ PluginIterator &operator++() { mPos++; return *this; }
+ PluginIterator &operator++( int ) { mPos++; return *this; }
+ PluginIterator &operator--() { mPos--; return *this; }
+ PluginIterator &operator--( int ) { mPos--; return *this; }
+ bool operator==( const PluginIterator &it ) { return mEnvironment == it.mEnvironment && mPos == it.mPos; }
+ bool operator!=( const PluginIterator &it ) { return mEnvironment == it.mEnvironment && mPos != it.mPos; }
+
+ private:
+ Environment *mEnvironment;
+ int mPos;
+ };
+
+ /**
+ Returns an iterator pointing to the first item in the group list.
+ This iterator equals groupEnd() if the group list is empty.
+ */
+ GroupIterator groupBegin();
+
+ /**
+ Returns an iterator pointing past the last item in the group list.
+ This iterator equals groupBegin() if the group list is empty.
+ */
+ GroupIterator groupEnd();
+
+ /**
+ Returns an iterator pointing to the first item in the plugin list.
+ This iterator equals pluginEnd() if the group list is empty.
+ */
+ PluginIterator pluginBegin();
+
+ /**
+ Returns an iterator pointing past the last item in the plugin list.
+ This iterator equals pluginBegin() if the plugin list is empty.
+ */
+ PluginIterator pluginEnd();
+
+ /**
+ Initializes the environment ( e.g. loads the groups and plugins ).
+ Has to be called before the groups or plugins can be accessed.
+ */
+ Result initialize();
+
+ /**
+ Finalizes the environment ( e.g. unloads the groups and plugins ).
+ Should be the last call before the object is deleted.
+ */
+ Result finalize();
+
+ /**
+ Returns the number of groups.
+ */
+ int groupCount() const;
+
+ /**
+ Returns the group at position @param pos.
+ */
+ Group groupAt( int pos ) const;
+
+ /**
+ Returns a group by name or an invalid group when the group with this
+ name doesn't exists.
+ */
+ Group groupByName( const QString &name ) const;
+
+ /**
+ Adds a new group to the environment.
+
+ @returns the new group.
+ */
+ Group addGroup();
+
+ /**
+ Removes a group from the environment.
+ */
+ Result removeGroup( const Group &group );
+
+ /**
+ Returns the number of plugins.
+ */
+ int pluginCount() const;
+
+ /**
+ Returns the plugin at position @param pos.
+ */
+ Plugin pluginAt( int pos ) const;
+
+ /**
+ Returns a plugin by name or an invalid plugin when the plugin with this
+ name doesn't exists.
+ */
+ Plugin pluginByName( const QString &name ) const;
+
+ /**
+ Returns the conversion object of this environment.
+ */
+ Conversion conversion() const;
+
+ private:
+ OSyncEnv *mEnvironment;
+};
+
+}
+
+#endif
diff --git a/kitchensync/libqopensync/filter.cpp b/kitchensync/libqopensync/filter.cpp
new file mode 100644
index 000000000..fdfcf032f
--- /dev/null
+++ b/kitchensync/libqopensync/filter.cpp
@@ -0,0 +1,55 @@
+/*
+ This file is part of libqopensync.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <opensync/opensync.h>
+
+#include "filter.h"
+
+using namespace QSync;
+
+Filter::Filter()
+ : mFilter( 0 )
+{
+}
+
+Filter::~Filter()
+{
+}
+
+bool Filter::isValid() const
+{
+ return (mFilter != 0);
+}
+
+void Filter::setConfiguration( const QString &configuration )
+{
+ Q_ASSERT( mFilter );
+
+ osync_filter_set_config( mFilter, (const char*)configuration.utf8() );
+}
+
+QString Filter::configuration() const
+{
+ Q_ASSERT( mFilter );
+
+ return QString::fromUtf8( osync_filter_get_config( mFilter ) );
+}
+
diff --git a/kitchensync/libqopensync/filter.h b/kitchensync/libqopensync/filter.h
new file mode 100644
index 000000000..55e3099e1
--- /dev/null
+++ b/kitchensync/libqopensync/filter.h
@@ -0,0 +1,64 @@
+/*
+ This file is part of libqopensync.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef QSYNC_FILTER_H
+#define QSYNC_FILTER_H
+
+#include <qstring.h>
+
+class OSyncFilter;
+
+namespace QSync {
+
+class Filter
+{
+ friend class Group;
+
+ public:
+ Filter();
+ ~Filter();
+
+ /**
+ Returns whether the object is a valid filter.
+ */
+ bool isValid() const;
+
+ /**
+ Sets the configuration string of this filter. The format of
+ string is filter specific.
+ */
+ void setConfiguration( const QString &configuration );
+
+ /**
+ Returns the configuration string of this filter.
+ */
+ QString configuration() const;
+
+ bool operator==( const Filter &filter ) const { return mFilter == filter.mFilter; }
+
+ private:
+ OSyncFilter *mFilter;
+};
+
+}
+
+#endif
+
diff --git a/kitchensync/libqopensync/group.cpp b/kitchensync/libqopensync/group.cpp
new file mode 100644
index 000000000..75beab90c
--- /dev/null
+++ b/kitchensync/libqopensync/group.cpp
@@ -0,0 +1,292 @@
+/*
+ This file is part of libqopensync.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+/** hack includes **/
+#include <qdom.h>
+#include <qfile.h>
+/** hack includes **/
+
+#include <opensync/opensync.h>
+
+#include "conversion.h"
+#include "group.h"
+
+using namespace QSync;
+
+/**
+ This class is a quick hack for OpenSync 0.19 and 0.20 because
+ the engine doesn't stores the filter settings itself when calling
+ osync_group_set_objtype_enabled(), so we have to store it for every
+ group in a separated config file. This class encapsulates it.
+ */
+GroupConfig::GroupConfig()
+ : mGroup( 0 )
+{
+}
+
+QStringList GroupConfig::activeObjectTypes() const
+{
+ Q_ASSERT( mGroup );
+
+ const QString fileName = QString( "%1/filter.conf" ).arg( osync_group_get_configdir( mGroup ) );
+
+ QFile file( fileName );
+ if ( !file.open( IO_ReadOnly ) )
+ return QStringList();
+
+ QDomDocument document;
+
+ QString message;
+ if ( !document.setContent( &file, &message ) ) {
+ qDebug( "Error on loading %s: %s", fileName.latin1(), message.latin1() );
+ return QStringList();
+ }
+ file.close();
+
+ QStringList objectTypes;
+
+ QDomElement element = document.documentElement();
+ QDomNode node = element.firstChild();
+ while ( !node.isNull() ) {
+ QDomElement childElement = node.toElement();
+ if ( !childElement.isNull() )
+ objectTypes.append( childElement.tagName() );
+
+ node = node.nextSibling();
+ }
+
+ return objectTypes;
+}
+
+void GroupConfig::setActiveObjectTypes( const QStringList &objectTypes )
+{
+ Q_ASSERT( mGroup );
+
+ QDomDocument document( "Filter" );
+ document.appendChild( document.createProcessingInstruction(
+ "xml", "version=\"1.0\" encoding=\"UTF-8\"" ) );
+
+ QDomElement element = document.createElement( "filter" );
+ document.appendChild( element );
+
+ for ( uint i = 0; i < objectTypes.count(); ++i ) {
+ QDomElement entry = document.createElement( objectTypes[ i ] );
+ element.appendChild( entry );
+ }
+
+ const QString fileName = QString( "%1/filter.conf" ).arg( osync_group_get_configdir( mGroup ) );
+
+ QFile file( fileName );
+ if ( !file.open( IO_WriteOnly ) )
+ return;
+
+ QTextStream s( &file );
+ s.setEncoding( QTextStream::UnicodeUTF8 );
+ s << document.toString();
+ file.close();
+}
+
+
+Group::Group()
+ : mGroup( 0 )
+{
+}
+
+Group::~Group()
+{
+}
+
+bool Group::isValid() const
+{
+ return ( mGroup != 0 );
+}
+
+Group::Iterator Group::begin()
+{
+ Iterator it( this );
+ it.mPos = 0;
+
+ return it;
+}
+
+Group::Iterator Group::end()
+{
+ Iterator it( this );
+ it.mPos = memberCount();
+
+ return it;
+}
+
+void Group::setName( const QString &name )
+{
+ Q_ASSERT( mGroup );
+
+ osync_group_set_name( mGroup, name.latin1() );
+}
+
+QString Group::name() const
+{
+ Q_ASSERT( mGroup );
+
+ return QString::fromLatin1( osync_group_get_name( mGroup ) );
+}
+
+void Group::setLastSynchronization( const QDateTime &dateTime )
+{
+ Q_ASSERT( mGroup );
+
+ if ( dateTime.isValid() )
+ osync_group_set_last_synchronization( mGroup, dateTime.toTime_t() );
+}
+
+QDateTime Group::lastSynchronization() const
+{
+ Q_ASSERT( mGroup );
+
+ QDateTime dateTime;
+ time_t time = osync_group_get_last_synchronization( mGroup );
+ if ( time != 0 )
+ dateTime.setTime_t( time );
+
+ return dateTime;
+}
+
+Group::LockType Group::lock()
+{
+ Q_ASSERT( mGroup );
+
+ OSyncLockState state = osync_group_lock( mGroup );
+ switch ( state ) {
+ default:
+ case OSYNC_LOCK_OK:
+ return LockOk;
+ break;
+ case OSYNC_LOCKED:
+ return Locked;
+ break;
+ case OSYNC_LOCK_STALE:
+ return LockStale;
+ break;
+ }
+}
+
+void Group::unlock( bool removeFile )
+{
+ Q_ASSERT( mGroup );
+
+ osync_group_unlock( mGroup, removeFile );
+}
+
+Member Group::addMember()
+{
+ Q_ASSERT( mGroup );
+
+ OSyncMember *omember = osync_member_new( mGroup );
+
+ Member member;
+ member.mMember = omember;
+
+ save();
+
+ return member;
+}
+
+void Group::removeMember( const Member &member )
+{
+ Q_ASSERT( mGroup );
+
+ osync_group_remove_member( mGroup, member.mMember );
+}
+
+int Group::memberCount() const
+{
+ Q_ASSERT( mGroup );
+
+ return osync_group_num_members( mGroup );
+}
+
+Member Group::memberAt( int pos ) const
+{
+ Q_ASSERT( mGroup );
+
+ Member member;
+
+ if ( pos < 0 || pos >= memberCount() )
+ return member;
+
+ member.mMember = osync_group_nth_member( mGroup, pos );
+
+ return member;
+}
+
+int Group::filterCount() const
+{
+ Q_ASSERT( mGroup );
+
+ return osync_group_num_filters( mGroup );
+}
+
+Filter Group::filterAt( int pos )
+{
+ Q_ASSERT( mGroup );
+
+ Filter filter;
+
+ if ( pos < 0 || pos >= filterCount() )
+ return filter;
+
+ filter.mFilter = osync_group_nth_filter( mGroup, pos );
+
+ return filter;
+}
+
+Result Group::save()
+{
+ Q_ASSERT( mGroup );
+
+ OSyncError *error = 0;
+ if ( !osync_group_save( mGroup, &error ) )
+ return Result( &error );
+ else
+ return Result();
+}
+
+void Group::setObjectTypeEnabled( const QString &objectType, bool enabled )
+{
+ Q_ASSERT( mGroup );
+
+ osync_group_set_objtype_enabled( mGroup, objectType.utf8(), enabled );
+}
+
+bool Group::isObjectTypeEnabled( const QString &objectType ) const
+{
+ return osync_group_objtype_enabled( mGroup, objectType.utf8() );
+}
+
+GroupConfig Group::config() const
+{
+ Q_ASSERT( mGroup );
+
+ GroupConfig config;
+ config.mGroup = mGroup;
+
+ return config;
+}
diff --git a/kitchensync/libqopensync/group.h b/kitchensync/libqopensync/group.h
new file mode 100644
index 000000000..e03365dfe
--- /dev/null
+++ b/kitchensync/libqopensync/group.h
@@ -0,0 +1,217 @@
+/*
+ This file is part of libqopensync.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef QSYNC_GROUP_H
+#define QSYNC_GROUP_H
+
+#include <qdatetime.h>
+#include <qstringlist.h>
+
+#include <libqopensync/filter.h>
+#include <libqopensync/member.h>
+
+class OSyncGroup;
+
+namespace QSync {
+
+/**
+ @internal
+ */
+class GroupConfig
+{
+ friend class Group;
+
+ public:
+ GroupConfig();
+
+ QStringList activeObjectTypes() const;
+ void setActiveObjectTypes( const QStringList &objectTypes );
+
+ private:
+ OSyncGroup *mGroup;
+};
+
+
+class Group
+{
+ friend class Engine;
+ friend class Environment;
+
+ public:
+ enum LockType
+ {
+ LockOk,
+ Locked,
+ LockStale
+ };
+
+ Group();
+ ~Group();
+
+ /**
+ Returns whether the object is a valid group.
+ */
+ bool isValid() const;
+
+ class Iterator
+ {
+ friend class Group;
+
+ public:
+ Iterator( Group *group )
+ : mGroup( group ), mPos( -1 )
+ {
+ }
+
+ Iterator( const Iterator &it )
+ {
+ mGroup = it.mGroup;
+ mPos = it.mPos;
+ }
+
+ Member operator*()
+ {
+ return mGroup->memberAt( mPos );
+ }
+
+ Iterator &operator++() { mPos++; return *this; }
+ Iterator &operator++( int ) { mPos++; return *this; }
+ Iterator &operator--() { mPos--; return *this; }
+ Iterator &operator--( int ) { mPos--; return *this; }
+ bool operator==( const Iterator &it ) { return mGroup == it.mGroup && mPos == it.mPos; }
+ bool operator!=( const Iterator &it ) { return mGroup == it.mGroup && mPos != it.mPos; }
+
+ private:
+ Group *mGroup;
+ int mPos;
+ };
+
+ /**
+ Returns an iterator pointing to the first item in the member list.
+ This iterator equals end() if the member list is empty.
+ */
+ Iterator begin();
+
+ /**
+ Returns an iterator pointing past the last item in the member list.
+ This iterator equals begin() if the member list is empty.
+ */
+ Iterator end();
+
+ /**
+ Sets the name of the group.
+ */
+ void setName( const QString &name );
+
+ /**
+ Returns the name of the group.
+ */
+ QString name() const;
+
+ /**
+ Sets the time of the last successfull synchronization.
+ */
+ void setLastSynchronization( const QDateTime &dateTime );
+
+ /**
+ Returns the time of the last successfull synchronization.
+ */
+ QDateTime lastSynchronization() const;
+
+ /**
+ Locks the group.
+
+ @returns The the result of the locking request.
+ */
+ LockType lock();
+
+ /**
+ Unlocks the group.
+
+ @param removeFile Whether the lock file shall be removed.
+ */
+ void unlock( bool removeFile = true );
+
+ /**
+ Adds a new member to the group.
+
+ @returns the new member.
+ */
+ Member addMember();
+
+ /**
+ Removes a member from the group.
+ */
+ void removeMember( const Member &member );
+
+ /**
+ Returns the number of members.
+ */
+ int memberCount() const;
+
+ /**
+ Returns the member at position @param pos.
+ */
+ Member memberAt( int pos ) const;
+
+ /**
+ Returns the number of filters.
+ */
+ int filterCount() const;
+
+ /**
+ Returns the filter at position @param pos.
+ */
+ Filter filterAt( int pos );
+
+ /**
+ Set, if the object type with given name is enabled for synchronisation for
+ this group.
+ */
+ void setObjectTypeEnabled( const QString &objectType, bool enabled );
+
+ /**
+ Returns whether the object type with given name is enabled for synchronisation for
+ this group.
+ */
+ bool isObjectTypeEnabled( const QString &objectType ) const;
+
+ /**
+ Saves the configuration to hard disc.
+ */
+ Result save();
+
+ /**
+ Returns the config object of this group.
+
+ Note: This method is only available for OpenSync 0.19 and 0.20.
+ */
+ GroupConfig config() const;
+
+ bool operator==( const Group &group ) const { return mGroup == group.mGroup; }
+
+ private:
+ OSyncGroup *mGroup;
+};
+
+}
+
+#endif
diff --git a/kitchensync/libqopensync/member.cpp b/kitchensync/libqopensync/member.cpp
new file mode 100644
index 000000000..3ac24f0dc
--- /dev/null
+++ b/kitchensync/libqopensync/member.cpp
@@ -0,0 +1,188 @@
+/*
+ This file is part of libqopensync.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <opensync/opensync.h>
+#include <stdlib.h>
+
+#include "member.h"
+
+using namespace QSync;
+
+Member::Member()
+ : mMember( 0 )
+{
+}
+
+Member::~Member()
+{
+}
+
+bool Member::isValid() const
+{
+ OSyncError *error = 0;
+
+ if ( !mMember )
+ return false;
+
+ if ( !osync_member_instance_plugin( mMember, pluginName().utf8(), &error ) ) {
+ qDebug( "Plugin %s is not valid: %s", pluginName().latin1(), osync_error_print( &error ) );
+ osync_error_free( &error );
+ return false;
+ }
+
+ return true;
+}
+
+QString Member::configurationDirectory() const
+{
+ Q_ASSERT( mMember );
+
+ return QString::fromLatin1( osync_member_get_configdir( mMember ) );
+}
+
+QString Member::pluginName() const
+{
+ Q_ASSERT( mMember );
+
+ return QString::fromLatin1( osync_member_get_pluginname( mMember ) );
+}
+
+Plugin Member::plugin() const
+{
+ Q_ASSERT( mMember );
+
+ Plugin plugin;
+
+ OSyncPlugin *oplugin = osync_member_get_plugin( mMember );
+ if ( oplugin )
+ plugin.mPlugin = oplugin;
+
+ return plugin;
+}
+
+int Member::id() const
+{
+ Q_ASSERT( mMember );
+
+ return osync_member_get_id( mMember );
+}
+
+void Member::setName( const QString &name )
+{
+ Q_ASSERT( mMember );
+
+ osync_member_set_name( mMember, (const char*)name.utf8() );
+}
+
+QString Member::name() const
+{
+ Q_ASSERT( mMember );
+
+ return QString::fromUtf8( osync_member_get_name( mMember ) );
+}
+
+void Member::setConfiguration( const QByteArray &configurationData )
+{
+ Q_ASSERT( mMember );
+
+ osync_member_set_config( mMember, configurationData.data(), configurationData.size() );
+}
+
+Result Member::configuration( QByteArray &configurationData, bool useDefault )
+{
+ Q_ASSERT( mMember );
+
+ char *data;
+ int size;
+
+ OSyncError *error = 0;
+ osync_bool ok = false;
+ if ( useDefault )
+ ok = osync_member_get_config_or_default( mMember, &data, &size, &error );
+ else
+ ok = osync_member_get_config( mMember, &data, &size, &error );
+
+ if ( !ok ) {
+ return Result( &error );
+ } else {
+ configurationData.resize( size );
+ memcpy( configurationData.data(), data, size );
+
+ return Result();
+ }
+}
+
+Result Member::save()
+{
+ Q_ASSERT( mMember );
+
+ OSyncError *error = 0;
+ if ( !osync_member_save( mMember, &error ) )
+ return Result( &error );
+ else
+ return Result();
+}
+
+Result Member::instance( const Plugin &plugin )
+{
+ OSyncError *error = 0;
+ if ( !osync_member_instance_plugin( mMember, plugin.name().utf8(), &error ) )
+ return Result( &error );
+ else
+ return Result();
+}
+
+bool Member::operator==( const Member &member ) const
+{
+ return mMember == member.mMember;
+}
+
+QString Member::scanDevices( const QString &query )
+{
+ Q_ASSERT( mMember );
+
+ OSyncError *error = 0;
+ char *data = (char*)osync_member_call_plugin( mMember, "scan_devices", const_cast<char*>( query.utf8().data() ), &error );
+ if ( error != 0 ) {
+ osync_error_free( &error );
+ return QString();
+ } else {
+ QString xml = QString::fromUtf8( data );
+ free( data );
+ return xml;
+ }
+}
+
+bool Member::testConnection( const QString &configuration )
+{
+ Q_ASSERT( mMember );
+
+ OSyncError *error = 0;
+ int *result = (int*)osync_member_call_plugin( mMember, "test_connection", const_cast<char*>( configuration.utf8().data() ), &error );
+ if ( error != 0 ) {
+ osync_error_free( &error );
+ return false;
+ } else {
+ bool value = ( *result == 1 ? true : false );
+ free( result );
+ return value;
+ }
+}
diff --git a/kitchensync/libqopensync/member.h b/kitchensync/libqopensync/member.h
new file mode 100644
index 000000000..d0d883db3
--- /dev/null
+++ b/kitchensync/libqopensync/member.h
@@ -0,0 +1,129 @@
+/*
+ This file is part of libqopensync.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef QSYNC_MEMBER_H
+#define QSYNC_MEMBER_H
+
+#include <libqopensync/plugin.h>
+#include <libqopensync/result.h>
+#include <libqopensync/plugin.h>
+
+class OSyncMember;
+
+namespace QSync {
+
+class Member
+{
+ friend class Group;
+ friend class SyncChange;
+ friend class SyncMemberUpdate;
+
+ public:
+ Member();
+ ~Member();
+
+ /**
+ Returns whether the member object is valid.
+ */
+ bool isValid() const;
+
+ /**
+ Returns the configuration directory.
+ */
+ QString configurationDirectory() const;
+
+ /**
+ Returns the name of the plugin, the member belongs to.
+ */
+ QString pluginName() const;
+
+ /**
+ Returns the plugin, the member belongs to.
+ */
+ Plugin plugin() const;
+
+ /**
+ Returns the id of the plugin.
+ */
+ int id() const;
+
+ /**
+ Sets the name of this member.
+ */
+ void setName( const QString &name );
+
+ /**
+ Returns the name of this member.
+ */
+ QString name() const;
+
+ /**
+ Sets the configuration data as byte array. The developer has to decide the
+ type of the data ( e.g. xml, plain text, binary ).
+ */
+ void setConfiguration( const QByteArray &configurationData );
+
+ /**
+ Gets the configuration data as byte array. The developer has to decide the
+ type of the data ( e.g. xml, plain text, binary ).
+
+ @param useDefault If set to true, return default config, if no config
+ exists. If set to false, return error when no config
+ exists.
+
+ @returns The result of this operation.
+ */
+ Result configuration( QByteArray &configurationData,
+ bool useDefault = true );
+
+ /**
+ Saves the changes to the configuration to hard disc.
+ */
+ Result save();
+
+ /**
+ Make this member an instance of the given plugin.
+ */
+ Result instance( const Plugin & );
+
+ bool operator==( const Member& ) const;
+
+ /**
+ This method can be used to query the plugin for scanning devices.
+ The @param query is a plugin specific xml document as well as
+ the return value.
+ */
+ QString scanDevices( const QString &query );
+
+ /**
+ This method can be used to test whether the plugin can connect
+ to the device with the given configuration.
+ */
+ bool testConnection( const QString &configuration );
+
+ private:
+ OSyncMember *mMember;
+};
+
+}
+
+#endif
+
diff --git a/kitchensync/libqopensync/plugin.cpp b/kitchensync/libqopensync/plugin.cpp
new file mode 100644
index 000000000..d22a5f344
--- /dev/null
+++ b/kitchensync/libqopensync/plugin.cpp
@@ -0,0 +1,62 @@
+/*
+ This file is part of libqopensync.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <opensync/opensync.h>
+
+#include "plugin.h"
+
+using namespace QSync;
+
+Plugin::Plugin()
+ : mPlugin( 0 )
+{
+}
+
+Plugin::~Plugin()
+{
+}
+
+bool Plugin::isValid() const
+{
+ return ( mPlugin != 0 );
+}
+
+QString Plugin::name() const
+{
+ Q_ASSERT( mPlugin );
+
+ return QString::fromLatin1( osync_plugin_get_name( mPlugin ) );
+}
+
+QString Plugin::longName() const
+{
+ Q_ASSERT( mPlugin );
+
+ return QString::fromLatin1( osync_plugin_get_longname( mPlugin ) );
+}
+
+QString Plugin::description() const
+{
+ Q_ASSERT( mPlugin );
+
+ return QString::fromLatin1( osync_plugin_get_description( mPlugin ) );
+}
+
diff --git a/kitchensync/libqopensync/plugin.h b/kitchensync/libqopensync/plugin.h
new file mode 100644
index 000000000..e951dfffa
--- /dev/null
+++ b/kitchensync/libqopensync/plugin.h
@@ -0,0 +1,67 @@
+/*
+ This file is part of libqopensync.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef QSYNC_PLUGIN_H
+#define QSYNC_PLUGIN_H
+
+#include <qstring.h>
+
+class OSyncPlugin;
+
+namespace QSync {
+
+class Plugin
+{
+ friend class Environment;
+ friend class Member;
+
+ public:
+ Plugin();
+ ~Plugin();
+
+ /**
+ Returns whether the object is a valid plugin.
+ */
+ bool isValid() const;
+
+ /**
+ Returns the name of the plugin.
+ */
+ QString name() const;
+
+ /**
+ Returns the long name of the plugin.
+ */
+ QString longName() const;
+
+ /**
+ Returns the description of the plugin.
+ */
+ QString description() const;
+
+ private:
+ OSyncPlugin *mPlugin;
+};
+
+}
+
+#endif
+
diff --git a/kitchensync/libqopensync/result.cpp b/kitchensync/libqopensync/result.cpp
new file mode 100644
index 000000000..b46040418
--- /dev/null
+++ b/kitchensync/libqopensync/result.cpp
@@ -0,0 +1,149 @@
+/*
+ This file is part of libqopensync.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "result.h"
+
+#include <opensync/opensync.h>
+
+using namespace QSync;
+
+Result::Result()
+ : mType( NoError )
+{
+}
+
+Result::Result( Type type )
+ : mType( type )
+{
+}
+
+Result::Result( OSyncError **error, bool deleteError )
+{
+ OSyncErrorType otype = osync_error_get_type( error );
+ Type type;
+
+ switch ( otype ) {
+ case OSYNC_NO_ERROR:
+ type = NoError;
+ break;
+ default:
+ case OSYNC_ERROR_GENERIC:
+ type = GenericError;
+ break;
+ case OSYNC_ERROR_IO_ERROR:
+ type = IOError;
+ break;
+ case OSYNC_ERROR_NOT_SUPPORTED:
+ type = NotSupported;
+ break;
+ case OSYNC_ERROR_TIMEOUT:
+ type = Timeout;
+ break;
+ case OSYNC_ERROR_DISCONNECTED:
+ type = Disconnected;
+ break;
+ case OSYNC_ERROR_FILE_NOT_FOUND:
+ type = FileNotFound;
+ break;
+ case OSYNC_ERROR_EXISTS:
+ type = Exists;
+ break;
+ case OSYNC_ERROR_CONVERT:
+ type = Convert;
+ break;
+ case OSYNC_ERROR_MISCONFIGURATION:
+ type = Misconfiguration;
+ break;
+ case OSYNC_ERROR_INITIALIZATION:
+ type = Initialization;
+ break;
+ case OSYNC_ERROR_PARAMETER:
+ type = Parameter;
+ break;
+ case OSYNC_ERROR_EXPECTED:
+ type = Expected;
+ break;
+ case OSYNC_ERROR_NO_CONNECTION:
+ type = NoConnection;
+ break;
+ case OSYNC_ERROR_TEMPORARY:
+ type = Temporary;
+ break;
+ case OSYNC_ERROR_LOCKED:
+ type = Locked;
+ break;
+ case OSYNC_ERROR_PLUGIN_NOT_FOUND:
+ type = PluginNotFound;
+ break;
+ }
+
+ mType = type;
+ mName = QString::fromUtf8( osync_error_get_name( error ) );
+ mMessage = QString::fromUtf8( osync_error_print( error ) );
+
+ if ( deleteError )
+ osync_error_free( error );
+}
+
+Result::~Result()
+{
+}
+
+void Result::setName( const QString &name )
+{
+ mName = name;
+}
+
+QString Result::name() const
+{
+ return mName;
+}
+
+void Result::setMessage( const QString &message )
+{
+ mMessage = message;
+}
+
+QString Result::message() const
+{
+ return mMessage;
+}
+
+void Result::setType( Type type )
+{
+ mType = type;
+}
+
+Result::Type Result::type() const
+{
+ return mType;
+}
+
+bool Result::isError() const
+{
+ return mType != NoError;
+}
+
+Result::operator bool () const
+{
+ return ( mType != NoError );
+}
+
diff --git a/kitchensync/libqopensync/result.h b/kitchensync/libqopensync/result.h
new file mode 100644
index 000000000..c7cf13d70
--- /dev/null
+++ b/kitchensync/libqopensync/result.h
@@ -0,0 +1,126 @@
+/*
+ This file is part of libqopensync.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef QSYNC_RESULT_H
+#define QSYNC_RESULT_H
+
+#include <qstring.h>
+
+struct OSyncError;
+
+namespace QSync {
+
+class Result
+{
+ public:
+ /**
+ Result types.
+ */
+ enum Type {
+ NoError,
+ GenericError,
+ IOError,
+ NotSupported,
+ Timeout,
+ Disconnected,
+ FileNotFound,
+ Exists,
+ Convert,
+ Misconfiguration,
+ Initialization,
+ Parameter,
+ Expected,
+ NoConnection,
+ Temporary,
+ Locked,
+ PluginNotFound
+ };
+
+ /**
+ Constructs a NoError result.
+ */
+ Result();
+
+ /**
+ Constructs a result of the given type.
+ */
+ Result( Type type );
+
+ /**
+ Construct Result from OpenSync error object. Deletes the OpenSync error
+ object.
+ */
+ Result( OSyncError **, bool deleteError = true );
+
+ /**
+ Destroys the result.
+ */
+ ~Result();
+
+ /**
+ Sets the name of the result.
+ */
+ void setName( const QString &name );
+
+ /**
+ Returns the name of the result.
+ */
+ QString name() const;
+
+ /**
+ Sets the message text of the result.
+ */
+ void setMessage( const QString &message );
+
+ /**
+ Returns the message text of the result.
+ */
+ QString message() const;
+
+ /**
+ Sets the type of the result.
+ */
+ void setType( Type type );
+
+ /**
+ Returns the type of the result.
+ */
+ Type type() const;
+
+ /**
+ Reimplemented boolean operator.
+ */
+ operator bool () const;
+
+ /**
+ Return true, if this Result is an error, return false otherwise.
+ */
+ bool isError() const;
+
+ private:
+ QString mName;
+ QString mMessage;
+ Type mType;
+};
+
+}
+
+#endif
diff --git a/kitchensync/libqopensync/syncchange.cpp b/kitchensync/libqopensync/syncchange.cpp
new file mode 100644
index 000000000..f64ef6493
--- /dev/null
+++ b/kitchensync/libqopensync/syncchange.cpp
@@ -0,0 +1,159 @@
+/*
+ This file is part of libqopensync.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <opensync/file.h>
+#include <opensync/opensync.h>
+
+#include "syncchange.h"
+
+using namespace QSync;
+
+SyncChange::SyncChange()
+{
+}
+
+SyncChange::SyncChange( OSyncChange *change )
+{
+ mSyncChange = change;
+}
+
+SyncChange::~SyncChange()
+{
+}
+
+bool SyncChange::isValid() const
+{
+ return ( mSyncChange != 0 );
+}
+
+void SyncChange::setUid( const QString &uid )
+{
+ osync_change_set_uid( mSyncChange, uid.utf8() );
+}
+
+QString SyncChange::uid() const
+{
+ return QString::fromUtf8( osync_change_get_uid( mSyncChange ) );
+}
+
+void SyncChange::setHash( const QString &hash )
+{
+ osync_change_set_hash( mSyncChange, hash.utf8() );
+}
+
+QString SyncChange::hash() const
+{
+ return QString::fromUtf8( osync_change_get_hash( mSyncChange ) );
+}
+
+void SyncChange::setData( const QString &data )
+{
+ osync_change_set_data( mSyncChange, const_cast<char*>( data.utf8().data() ), data.utf8().size(), true );
+}
+
+QString SyncChange::data() const
+{
+ int size = osync_change_get_datasize( mSyncChange );
+
+ QString content;
+ if ( objectFormatName() == "file" ) {
+ fileFormat *format = (fileFormat*)osync_change_get_data( mSyncChange );
+ if ( format )
+ content = QString::fromUtf8( format->data, format->size );
+ } else
+ content = QString::fromUtf8( osync_change_get_data( mSyncChange ), size );
+
+ return content;
+}
+
+bool SyncChange::hasData() const
+{
+ return osync_change_has_data( mSyncChange );
+}
+
+QString SyncChange::objectFormatName() const
+{
+ OSyncObjFormat *format = osync_change_get_objformat( mSyncChange );
+ Q_ASSERT( format );
+
+ return QString::fromUtf8( osync_objformat_get_name( format ) );
+}
+
+Member SyncChange::member() const
+{
+ OSyncMember *omember = osync_change_get_member( mSyncChange );
+
+ Member m;
+ m.mMember = omember;
+
+ return m;
+}
+
+void SyncChange::setChangeType( Type changeType )
+{
+ OSyncChangeType ochangeType;
+
+ switch ( changeType ) {
+ case AddedChange:
+ ochangeType = CHANGE_ADDED;
+ break;
+ case UnmodifiedChange:
+ ochangeType = CHANGE_UNMODIFIED;
+ break;
+ case DeletedChange:
+ ochangeType = CHANGE_DELETED;
+ break;
+ case ModifiedChange:
+ ochangeType = CHANGE_MODIFIED;
+ break;
+ case UnknownChange:
+ default:
+ ochangeType = CHANGE_UNKNOWN;
+ break;
+ }
+
+ osync_change_set_changetype( mSyncChange, ochangeType );
+}
+
+SyncChange::Type SyncChange::changeType() const
+{
+ OSyncChangeType ochangeType = osync_change_get_changetype( mSyncChange );
+
+ switch ( ochangeType ) {
+ case CHANGE_ADDED:
+ return AddedChange;
+ break;
+ case CHANGE_UNMODIFIED:
+ return UnmodifiedChange;
+ break;
+ case CHANGE_DELETED:
+ return DeletedChange;
+ break;
+ case CHANGE_MODIFIED:
+ return ModifiedChange;
+ break;
+ case CHANGE_UNKNOWN:
+ default:
+ return UnknownChange;
+ break;
+ }
+}
+
diff --git a/kitchensync/libqopensync/syncchange.h b/kitchensync/libqopensync/syncchange.h
new file mode 100644
index 000000000..775d3a8ed
--- /dev/null
+++ b/kitchensync/libqopensync/syncchange.h
@@ -0,0 +1,116 @@
+/*
+ This file is part of libqopensync.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef QSYNC_SYNCCHANGE_H
+#define QSYNC_SYNCCHANGE_H
+
+#include <libqopensync/member.h>
+
+class OSyncChange;
+
+namespace QSync {
+
+class SyncChange
+{
+ friend class SyncMapping;
+
+ public:
+ enum Type
+ {
+ UnknownChange,
+ AddedChange,
+ UnmodifiedChange,
+ DeletedChange,
+ ModifiedChange
+ };
+
+ SyncChange();
+ SyncChange( OSyncChange* );
+ ~SyncChange();
+
+ /**
+ Returns whether it's a valid SyncChange.
+ */
+ bool isValid() const;
+
+ /**
+ Sets the uid of this change.
+ */
+ void setUid( const QString &uid );
+
+ /**
+ Returns the uid of this change.
+ */
+ QString uid() const;
+
+ /**
+ Sets the hash of this change.
+ */
+ void setHash( const QString &hash );
+
+ /**
+ Returns the hash of this change.
+ */
+ QString hash() const;
+
+ /**
+ Sets the data provided by the plugin.
+ */
+ void setData( const QString &data );
+
+ /**
+ Returns the data provided by the plugin.
+ */
+ QString data() const;
+
+ /**
+ Returns whether the change contains data.
+ */
+ bool hasData() const;
+
+ /**
+ Returns the object format name.
+ */
+ QString objectFormatName() const;
+
+ /**
+ Returns the parent member of this change.
+ */
+ Member member() const;
+
+ /**
+ Sets the change type.
+ */
+ void setChangeType( Type changeType );
+
+ /**
+ Returns the change type.
+ */
+ Type changeType() const;
+
+ private:
+ OSyncChange *mSyncChange;
+};
+
+}
+
+#endif
+
diff --git a/kitchensync/libqopensync/syncmapping.cpp b/kitchensync/libqopensync/syncmapping.cpp
new file mode 100644
index 000000000..8097c5482
--- /dev/null
+++ b/kitchensync/libqopensync/syncmapping.cpp
@@ -0,0 +1,100 @@
+/*
+ This file is part of libqopensync.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <qstring.h>
+#include <osengine/engine.h>
+
+#include "syncmapping.h"
+
+using namespace QSync;
+
+SyncMapping::SyncMapping()
+ : mEngine( 0 ), mMapping( 0 )
+{
+}
+
+SyncMapping::SyncMapping( OSyncMapping *mapping, OSyncEngine *engine )
+ : mEngine( engine ), mMapping( mapping )
+{
+}
+
+SyncMapping::~SyncMapping()
+{
+}
+
+bool SyncMapping::isValid() const
+{
+ return ( mEngine != 0 && mMapping != 0 );
+}
+
+long long SyncMapping::id() const
+{
+ Q_ASSERT( mMapping );
+
+ return osengine_mapping_get_id( mMapping );
+}
+
+void SyncMapping::duplicate()
+{
+ Q_ASSERT( mEngine );
+ Q_ASSERT( mMapping );
+
+ osengine_mapping_duplicate( mEngine, mMapping );
+}
+
+void SyncMapping::solve( const SyncChange &change )
+{
+ Q_ASSERT( mEngine );
+ Q_ASSERT( mMapping );
+ Q_ASSERT( change.isValid() );
+
+ osengine_mapping_solve( mEngine, mMapping, change.mSyncChange );
+}
+
+void SyncMapping::ignore()
+{
+ Q_ASSERT( mEngine );
+ Q_ASSERT( mMapping );
+
+ //TODO: error should be returned as Result
+ OSyncError *error = 0;
+ osengine_mapping_ignore_conflict( mEngine, mMapping, &error );
+}
+
+int SyncMapping::changesCount() const
+{
+ Q_ASSERT( mMapping );
+
+ return osengine_mapping_num_changes( mMapping );
+}
+
+SyncChange SyncMapping::changeAt( int pos )
+{
+ Q_ASSERT( mMapping );
+
+ if ( pos < 0 || pos >= osengine_mapping_num_changes( mMapping ) )
+ return SyncChange();
+
+ OSyncChange *ochange = osengine_mapping_nth_change( mMapping, pos );
+
+ return SyncChange( ochange );
+}
+
diff --git a/kitchensync/libqopensync/syncmapping.h b/kitchensync/libqopensync/syncmapping.h
new file mode 100644
index 000000000..6de67330a
--- /dev/null
+++ b/kitchensync/libqopensync/syncmapping.h
@@ -0,0 +1,59 @@
+/*
+ This file is part of libqopensync.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef QSYNC_SYNCMAPPING_H
+#define QSYNC_SYNCMAPPING_H
+
+#include <libqopensync/syncchange.h>
+
+class OSyncEngine;
+class OSyncMapping;
+
+namespace QSync {
+
+class SyncMapping
+{
+ friend class SyncMappingUpdate;
+
+ public:
+ SyncMapping();
+ SyncMapping( OSyncMapping*, OSyncEngine* );
+ ~SyncMapping();
+
+ bool isValid() const;
+
+ long long id() const;
+
+ void duplicate();
+ void solve( const SyncChange &change );
+ void ignore();
+
+ int changesCount() const;
+ SyncChange changeAt( int pos );
+
+ private:
+ OSyncEngine *mEngine;
+ OSyncMapping *mMapping;
+};
+
+}
+
+#endif
diff --git a/kitchensync/libqopensync/syncupdates.cpp b/kitchensync/libqopensync/syncupdates.cpp
new file mode 100644
index 000000000..653ccf7f3
--- /dev/null
+++ b/kitchensync/libqopensync/syncupdates.cpp
@@ -0,0 +1,251 @@
+/*
+ This file is part of libqopensync.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <osengine/engine.h>
+
+#include "syncupdates.h"
+
+using namespace QSync;
+
+SyncMemberUpdate::SyncMemberUpdate()
+{
+}
+
+SyncMemberUpdate::SyncMemberUpdate( OSyncMemberUpdate *update )
+{
+ switch ( update->type ) {
+ case MEMBER_CONNECTED:
+ mType = Connected;
+ break;
+ case MEMBER_SENT_CHANGES:
+ mType = SentChanges;
+ break;
+ case MEMBER_COMMITTED_ALL:
+ mType = CommittedAll;
+ break;
+ case MEMBER_DISCONNECTED:
+ mType = Disconnected;
+ break;
+ case MEMBER_CONNECT_ERROR:
+ mType = ConnectError;
+ break;
+ case MEMBER_GET_CHANGES_ERROR:
+ mType = GetChangesError;
+ break;
+ case MEMBER_COMMITTED_ALL_ERROR:
+ mType = CommittedAllError;
+ break;
+ case MEMBER_SYNC_DONE_ERROR:
+ mType = SyncDoneError;
+ break;
+ case MEMBER_DISCONNECT_ERROR:
+ mType = DisconnectedError;
+ break;
+ }
+
+ if ( update->error )
+ mResult = Result( &(update->error) );
+
+ mMember.mMember = update->member;
+}
+
+SyncMemberUpdate::~SyncMemberUpdate()
+{
+}
+
+SyncMemberUpdate::Type SyncMemberUpdate::type() const
+{
+ return mType;
+}
+
+Result SyncMemberUpdate::result() const
+{
+ return mResult;
+}
+
+Member SyncMemberUpdate::member() const
+{
+ return mMember;
+}
+
+
+SyncChangeUpdate::SyncChangeUpdate()
+{
+}
+
+SyncChangeUpdate::SyncChangeUpdate( OSyncChangeUpdate *update )
+{
+ switch ( update->type ) {
+ case CHANGE_RECEIVED:
+ mType = Received;
+ break;
+ case CHANGE_RECEIVED_INFO:
+ mType = ReceivedInfo;
+ break;
+ case CHANGE_SENT:
+ mType = Sent;
+ break;
+ case CHANGE_WRITE_ERROR:
+ mType = WriteError;
+ break;
+ case CHANGE_RECV_ERROR:
+ mType = ReceiveError;
+ break;
+ }
+
+ if ( update->error )
+ mResult = Result( &(update->error) );
+
+ mChange = SyncChange( update->change );
+ mMemberId = update->member_id;
+ mMappingId = update->mapping_id;
+}
+
+SyncChangeUpdate::~SyncChangeUpdate()
+{
+}
+
+SyncChangeUpdate::Type SyncChangeUpdate::type() const
+{
+ return mType;
+}
+
+Result SyncChangeUpdate::result() const
+{
+ return mResult;
+}
+
+SyncChange SyncChangeUpdate::change() const
+{
+ return mChange;
+}
+
+int SyncChangeUpdate::memberId() const
+{
+ return mMemberId;
+}
+
+int SyncChangeUpdate::mappingId() const
+{
+ return mMappingId;
+}
+
+SyncMappingUpdate::SyncMappingUpdate()
+{
+}
+
+SyncMappingUpdate::SyncMappingUpdate( OSyncMappingUpdate *update, OSyncEngine *engine )
+{
+ switch ( update->type ) {
+ case MAPPING_SOLVED:
+ mType = Solved;
+ break;
+ case MAPPING_SYNCED:
+ mType = Synced;
+ break;
+ case MAPPING_WRITE_ERROR:
+ mType = WriteError;
+ break;
+ }
+
+ if ( update->error )
+ mResult = Result( &(update->error) );
+
+ mWinner = update->winner;
+ mMapping.mEngine = engine;
+ mMapping.mMapping = update->mapping;
+}
+
+SyncMappingUpdate::~SyncMappingUpdate()
+{
+}
+
+SyncMappingUpdate::Type SyncMappingUpdate::type() const
+{
+ return mType;
+}
+
+Result SyncMappingUpdate::result() const
+{
+ return mResult;
+}
+
+long long int SyncMappingUpdate::winner() const
+{
+ return mWinner;
+}
+
+SyncMapping SyncMappingUpdate::mapping() const
+{
+ return mMapping;
+}
+
+SyncEngineUpdate::SyncEngineUpdate()
+{
+}
+
+SyncEngineUpdate::SyncEngineUpdate( OSyncEngineUpdate *update )
+{
+ switch ( update->type ) {
+ case ENG_ENDPHASE_CON:
+ mType = EndPhaseConnected;
+ break;
+ case ENG_ENDPHASE_READ:
+ mType = EndPhaseRead;
+ break;
+ case ENG_ENDPHASE_WRITE:
+ mType = EndPhaseWrite;
+ break;
+ case ENG_ENDPHASE_DISCON:
+ mType = EndPhaseDisconnected;
+ break;
+ case ENG_ERROR:
+ mType = Error;
+ break;
+ case ENG_SYNC_SUCCESSFULL:
+ mType = SyncSuccessfull;
+ break;
+ case ENG_PREV_UNCLEAN:
+ mType = PrevUnclean;
+ break;
+ case ENG_END_CONFLICTS:
+ mType = EndConflicts;
+ break;
+ }
+
+ if ( update->error )
+ mResult = Result( &(update->error) );
+}
+
+SyncEngineUpdate::~SyncEngineUpdate()
+{
+}
+
+SyncEngineUpdate::Type SyncEngineUpdate::type() const
+{
+ return mType;
+}
+
+Result SyncEngineUpdate::result() const
+{
+ return mResult;
+}
+
diff --git a/kitchensync/libqopensync/syncupdates.h b/kitchensync/libqopensync/syncupdates.h
new file mode 100644
index 000000000..14a2d9193
--- /dev/null
+++ b/kitchensync/libqopensync/syncupdates.h
@@ -0,0 +1,157 @@
+/*
+ This file is part of libqopensync.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef QSYNC_SYNCUPDATES_H
+#define QSYNC_SYNCUPDATES_H
+
+#include <libqopensync/member.h>
+#include <libqopensync/result.h>
+#include <libqopensync/syncchange.h>
+#include <libqopensync/syncmapping.h>
+
+class OSyncMemberUpdate;
+class OSyncChangeUpdate;
+class OSyncMappingUpdate;
+class OSyncEngineUpdate;
+class OSyncMemberUpdate;
+
+namespace QSync {
+
+class SyncMemberUpdate
+{
+ friend class CallbackHandler;
+
+ public:
+ enum Type {
+ Connected,
+ SentChanges,
+ CommittedAll,
+ Disconnected,
+ ConnectError,
+ GetChangesError,
+ CommittedAllError,
+ SyncDoneError,
+ DisconnectedError
+ };
+
+ SyncMemberUpdate();
+ SyncMemberUpdate( OSyncMemberUpdate* );
+ ~SyncMemberUpdate();
+
+ Type type() const;
+ Result result() const;
+ Member member() const;
+
+ private:
+ Type mType;
+ Result mResult;
+ Member mMember;
+};
+
+class SyncChangeUpdate
+{
+ friend class CallbackHandler;
+
+ public:
+ enum Type {
+ Received = 1,
+ ReceivedInfo,
+ Sent,
+ WriteError,
+ ReceiveError
+ };
+
+ SyncChangeUpdate();
+ SyncChangeUpdate( OSyncChangeUpdate* );
+ ~SyncChangeUpdate();
+
+ Type type() const;
+ Result result() const;
+ SyncChange change() const;
+ int memberId() const;
+ int mappingId() const;
+
+ private:
+ Type mType;
+ Result mResult;
+ SyncChange mChange;
+ int mMemberId;
+ int mMappingId;
+};
+
+class SyncMappingUpdate
+{
+ friend class CallbackHandler;
+
+ public:
+ enum Type {
+ Solved = 1,
+ Synced,
+ WriteError
+ };
+
+ SyncMappingUpdate();
+ SyncMappingUpdate( OSyncMappingUpdate*, OSyncEngine* );
+ ~SyncMappingUpdate();
+
+ Type type() const;
+ Result result() const;
+ long long int winner() const;
+ SyncMapping mapping() const;
+
+ private:
+ Type mType;
+ Result mResult;
+ long long int mWinner;
+ SyncMapping mMapping;
+};
+
+class SyncEngineUpdate
+{
+ friend class CallbackHandler;
+
+ public:
+ enum Type {
+ EndPhaseConnected = 1,
+ EndPhaseRead,
+ EndPhaseWrite,
+ EndPhaseDisconnected,
+ Error,
+ SyncSuccessfull,
+ PrevUnclean,
+ EndConflicts
+ };
+
+ SyncEngineUpdate();
+ SyncEngineUpdate( OSyncEngineUpdate* );
+ ~SyncEngineUpdate();
+
+ Type type() const;
+ Result result() const;
+
+ private:
+ Type mType;
+ Result mResult;
+};
+
+}
+
+#endif