diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | 460c52653ab0dcca6f19a4f492ed2c5e4e963ab0 (patch) | |
tree | 67208f7c145782a7e90b123b982ca78d88cc2c87 /kitchensync | |
download | tdepim-460c52653ab0dcca6f19a4f492ed2c5e4e963ab0.tar.gz tdepim-460c52653ab0dcca6f19a4f492ed2c5e4e963ab0.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kitchensync')
135 files changed, 12236 insertions, 0 deletions
diff --git a/kitchensync/Makefile.am b/kitchensync/Makefile.am new file mode 100644 index 000000000..f2bf61b45 --- /dev/null +++ b/kitchensync/Makefile.am @@ -0,0 +1,3 @@ +SUBDIRS = libqopensync src + +include $(top_srcdir)/admin/Doxyfile.am diff --git a/kitchensync/configure.in.bot b/kitchensync/configure.in.bot new file mode 100644 index 000000000..a612d1b78 --- /dev/null +++ b/kitchensync/configure.in.bot @@ -0,0 +1,8 @@ +if test "$HAVE_OPENSYNC" = 0 -o "$HAVE_OPENSYNC_ENGINE" = 0; then + echo "" + echo "You're missing a compatible version of libopensync." + echo "Version 0.19 or greater is needed." + echo "kitchensync will not be built." + echo "" + all_tests=bad +fi diff --git a/kitchensync/configure.in.in b/kitchensync/configure.in.in new file mode 100644 index 000000000..31bb902c6 --- /dev/null +++ b/kitchensync/configure.in.in @@ -0,0 +1,68 @@ +dnl configure.in.in for OpenSync based KitchenSync +dnl +dnl Copyright (C) 2005 Holger Hans Peter Freyther +dnl +dnl Based on KPilot's configure.in +dnl Copyright (C) 2000,2001 Adriaan de Groot +dnl +dnl This file is released under the terms of the GNU General Public +dnl Licence (GPL) Version 2. + + + +dnl we need PKG_CONFIG for doing these tests +AC_DEFUN([KITCHENSYNC_CHECK_OPENSYNC],[ +dnl AC_REQUIRE([PKG_CHECK_MODULES]) + +dnl Say what we're doing +AC_MSG_CHECKING(for opensync (for KitchenSync)) +AC_ARG_WITH(opensync, +[ --with-opensync=PATH set prefix for opensync files], +)dnl + +dnl change pkg_config_path if we have a OpenSync prefix +dnl and also set it to our prefix +if test -d "$with_opensync"; then + export PKG_CONFIG_PATH=${PKG_CONFIG_PATH}:/usr/lib/pkgconfig:$with_opensync/lib/pkgconfig +fi +export PKG_CONFIG_PATH=${PKG_CONFIG_PATH}:$prefix/lib/pkgconfig:/usr/local/lib/pkgconfig + + +HAVE_OPENSYNC=0 +HAVE_OPENSYNC_ENGINE=0 +PKG_CHECK_MODULES(OPENSYNC, opensync-1.0 >= 0.19, HAVE_OPENSYNC=1,HAVE_OPENSYNC=0) +PKG_CHECK_MODULES(OPENSYNCENGINE, osengine-1.0 >= 0.19, HAVE_OPENSYNC_ENGINE=1, HAVE_OPENSYNC_ENGINE=0) +PKG_CHECK_MODULES(LIBXML, libxml-2.0, , HAVE_OPENSYNC=0) +PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.6, , HAVE_OPENSYNC=0) + +if test -z "PKG_CONFIG"; then + AC_PATH_PROG(PKG_CONFIG, pkg-config, no) +fi + +if test "$PKG_CONFIG" != "no"; then + OPENSYNC_CONFIGDIR=`$PKG_CONFIG --variable=configdir "opensync-1.0"` + OPENSYNC_PLUGINDIR=`$PKG_CONFIG --variable=plugindir "opensync-1.0"` + OPENSYNC_FORMATSDIR=`$PKG_CONFIG --variable=formatsdir "opensync-1.0"` + OPENSYNC_HEADERDIR=`$PKG_CONFIG --variable=headerdir "opensync-1.0"` +fi + +AC_SUBST(OPENSYNC_CONFIGDIR) +AC_SUBST(OPENSYNC_PLUGINDIR) +AC_SUBST(OPENSYNC_FORMATSDIR) +AC_SUBST(OPENSYNC_HEADERDIR) + +dnl Check if we can compile KitchenSync +AM_CONDITIONAL(compile_kitchensync, test "$HAVE_OPENSYNC" = 1 -a "$HAVE_OPENSYNC_ENGINE" = 1) + +if test "$HAVE_OPENSYNC" = 1 -a "$HAVE_OPENSYNC_ENGINE" = 1 ; then + AC_MSG_RESULT([found]) +else + AC_MSG_RESULT([not found]) + DO_NOT_COMPILE="$DO_NOT_COMPILE kitchensync" +fi + +]) + + +dnl Check For OpenSync support +KITCHENSYNC_CHECK_OPENSYNC 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 <[email protected]> + + 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 <[email protected]> + + 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 <[email protected]> + + 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 <[email protected]> + + 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 <[email protected]> + + 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 <[email protected]> + + 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 <[email protected]> + + 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 <[email protected]> + + 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 <[email protected]> + + 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 <[email protected]> + + 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 <[email protected]> + + 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 <[email protected]> + + 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 <[email protected]> + + 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 <[email protected]> + + 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 <[email protected]> + + 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 <[email protected]> + + 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 <[email protected]> + + 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 <[email protected]> + + 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 <[email protected]> + + 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 <[email protected]> + + 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 <[email protected]> + + 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 <[email protected]> + + 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 <[email protected]> + + 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 <[email protected]> + + 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 diff --git a/kitchensync/opensyncdbus/Makefile.am b/kitchensync/opensyncdbus/Makefile.am new file mode 100644 index 000000000..9b1721f6e --- /dev/null +++ b/kitchensync/opensyncdbus/Makefile.am @@ -0,0 +1,10 @@ +INCLUDES = -I/usr/local/include/dbus-1.0/qt3 $(all_includes) \ + -I$(top_srcdir)/kitchensync + +bin_PROGRAMS = opensyncdbus + +opensyncdbus_SOURCES = dbusclient.cpp +opensyncdbus_LDADD = $(top_builddir)/kitchensync/libqopensync/libqopensync.la +opensyncdbus_LDFLAGS = -ldbus-1-qt3 -ldbus-1 $(all_libraries) $(KDE_RPATH) + +METASOURCES = AUTO diff --git a/kitchensync/opensyncdbus/README b/kitchensync/opensyncdbus/README new file mode 100644 index 000000000..e1aa1e3ce --- /dev/null +++ b/kitchensync/opensyncdbus/README @@ -0,0 +1,5 @@ +This directory contains opensyncdbus, a D-BUS frontend for OpenSync. It's a +daemon which provides a D-BUS interface for controlling OpenSync. + +To compile opensyncdbus you need the Qt3 bindings for D-BUS. +They are in SVN under branches/work/dbus-qt4-qt3backport/ diff --git a/kitchensync/opensyncdbus/dbusclient.cpp b/kitchensync/opensyncdbus/dbusclient.cpp new file mode 100644 index 000000000..fcf6eda30 --- /dev/null +++ b/kitchensync/opensyncdbus/dbusclient.cpp @@ -0,0 +1,273 @@ +/* + This file is part of KDE. + + Copyright (c) 2006 Cornelius Schumacher <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#include "dbusclient.h" + +#include <libqopensync/environment.h> +#include <libqopensync/group.h> + +#include <dbus/qdbuserror.h> +#include <dbus/qdbusconnection.h> +#include <dbus/qdbusmessage.h> +#include <dbus/qdbusproxy.h> + +#include <qapplication.h> +#include <qtimer.h> + +#include <iostream> + +OpenSyncService::OpenSyncService() + : mConnection( 0 ) +{ +} + +void OpenSyncService::setConnection( QDBusConnection *connection ) +{ + mConnection = connection; + mConnection->registerObject( "/ABC", this ); +} + +bool OpenSyncService::handleMethodCall( const QDBusMessage &message ) +{ + qDebug( "OpenSyncService::handleMethodCall()" ); + + qDebug( " Interface: %s", message.interface().latin1() ); + qDebug( " Path: %s", message.path().latin1() ); + qDebug( " Member: %s", message.member().latin1() ); + qDebug( " Sender: %s", message.sender().latin1() ); + + if ( message.interface() != "org.opensync.SyncEngine" ) return false; + + QDBusMessage reply; + + QString function = message.member(); + if ( function == "hello" ) { + reply = hello( message ); + } else if ( function == "randomNumber" ) { + reply = randomNumber( message ); + } else if ( function == "listGroups" ) { + reply = listGroups( message ); + } else if ( function == "listPlugins" ) { + reply = listPlugins( message ); + } else if ( function == "showGroup" ) { + reply = showGroup( message ); + } else if ( function == "showMember" ) { + reply = showMember( message ); + } else { + return false; + } + + mConnection->send( reply ); + + return true; +} + +QDBusMessage OpenSyncService::showMember( const QDBusMessage &message ) +{ + if ( message.count() != 2 ) { + return error( message, "arg_count", + QString("Wrong number of arguments. Expected 2, got %1.") + .arg( message.count() ) ); + } + + QString groupName = message[ 0 ].toString(); + if ( groupName.isEmpty() ) { + return error( message, "missing_arg", "Missing argument: group name." ); + } + + bool ok; + int memberId = message[ 1 ].toInt( &ok ); + if ( !ok ) { + return error( message, "missing_arg", "Missing argument: member id." ); + } + + QDBusMessage reply; + + QSync::Environment env; + QSync::Result result = env.initialize(); + if ( result.isError() ) { + return error( message, result.name(), result.message() ); + } else { + reply = QDBusMessage::methodReply( message ); + + QSync::Group group = env.groupByName( groupName ); + if ( !group.isValid() ) { + return error( message, "group_name", QString("Unknown group '%1'.") + .arg( groupName ) ); + } + + QSync::Member member = group.memberById( memberId ); + if ( !member.isValid() ) { + return error( message, "member_id", + QString("Unknown member id '%1' in group '%2'.").arg( groupName ) + .arg( memberId ) ); + } + + reply.append( memberId ); + reply.append( member.pluginName() ); + + env.finalize(); + } + + return reply; +} + + +QDBusMessage OpenSyncService::showGroup( const QDBusMessage &message ) +{ + if ( message.count() != 1 ) { + return error( message, "arg_count", + QString("Wrong number of arguments. Expected 1, got %1") + .arg( message.count() ) ); + } + + QString groupName = message[ 0 ].toString(); + if ( groupName.isEmpty() ) { + return error( message, "missing_arg", "Missing argument group name." ); + } + + QDBusMessage reply; + + QSync::Environment env; + QSync::Result result = env.initialize(); + if ( result.isError() ) { + return error( message, result.name(), result.message() ); + } else { + reply = QDBusMessage::methodReply( message ); + + QSync::Group group = env.groupByName( groupName ); + if ( !group.isValid() ) { + return error( message, "group_name", QString("Unknown group '%1'") + .arg( groupName ) ); + } + + QSync::Group::Iterator it( &group ); + for( it = group.begin(); it != group.end(); ++it ) { + QSync::Member member = *it; + reply.append( QVariant( member.id() ) ); + } + + env.finalize(); + } + + return reply; +} + +QDBusMessage OpenSyncService::error( const QDBusMessage &message, + const QString &errorCode, + const QString &errorMessage ) +{ + QDBusError error( "org.opensync." + errorCode, errorMessage ); + return QDBusMessage::methodError( message, error ); +} + +QDBusMessage OpenSyncService::listPlugins( const QDBusMessage &message ) +{ + QDBusMessage reply; + + QSync::Environment env; + QSync::Result result = env.initialize(); + if ( result.isError() ) { + QDBusError error( result.name(), result.message() ); + reply = QDBusMessage::methodError( message, error ); + } else { + reply = QDBusMessage::methodReply( message ); + + QSync::Environment::PluginIterator it( env.pluginBegin() ); + for ( ; it != env.pluginEnd(); ++it ) { + reply.append( QVariant( (*it).name() ) ); + } + + env.finalize(); + } + + return reply; +} + +QDBusMessage OpenSyncService::listGroups( const QDBusMessage &message ) +{ + QDBusMessage reply; + + QSync::Environment env; + QSync::Result result = env.initialize(); + if ( result.isError() ) { + QDBusError error( result.name(), result.message() ); + reply = QDBusMessage::methodError( message, error ); + } else { + reply = QDBusMessage::methodReply( message ); + + QSync::Environment::GroupIterator it( env.groupBegin() ); + for ( ; it != env.groupEnd(); ++it ) { + reply.append( QVariant( (*it).name() ) ); + } + + env.finalize(); + } + + return reply; +} + +QDBusMessage OpenSyncService::hello( const QDBusMessage &message ) +{ + QDBusMessage reply = QDBusMessage::methodReply( message ); + +// QDBusError error; +// reply = QDBusMessage::methodError( message, error ); + + reply.append( QVariant( QString( "Hello!" ) ) ); + + return reply; +} + +QDBusMessage OpenSyncService::randomNumber( const QDBusMessage &message ) +{ + QDBusMessage reply = QDBusMessage::methodReply( message ); + + int number = rand(); + + reply.append( QVariant( number ) ); + + return reply; +} + +int main( int argc, char *argv[] ) +{ + QApplication app(argc, argv); + + std::cout << "Hello" << std::endl; + + QDBusConnection connection = QDBusConnection::addConnection( + QDBusConnection::SessionBus ); + + if ( !connection.isConnected() ) { + qFatal("Cannot connect to session bus"); + } + + connection.requestName( "org.opensync.SyncEngine", + QDBusConnection::NoReplace ); + + OpenSyncService service; + service.setConnection( &connection ); + + return app.exec(); +} + +//#include "dbusclient.moc" diff --git a/kitchensync/opensyncdbus/dbusclient.h b/kitchensync/opensyncdbus/dbusclient.h new file mode 100644 index 000000000..5cd6635f7 --- /dev/null +++ b/kitchensync/opensyncdbus/dbusclient.h @@ -0,0 +1,56 @@ +/* + This file is part of KDE. + + Copyright (c) 2006 Cornelius Schumacher <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ +#ifndef DBUSCLIENT_H +#define DBUSCLIENT_H + +#include <qobject.h> + +#include <dbus/qdbusobject.h> + +class QDBusMessage; +class QDBusConnection; + +class OpenSyncService : public QDBusObjectBase +{ + public: + OpenSyncService(); + + void setConnection( QDBusConnection *connection ); + + protected: + virtual bool handleMethodCall( const QDBusMessage &message ); + + QDBusMessage hello( const QDBusMessage & ); + QDBusMessage randomNumber( const QDBusMessage & ); + + QDBusMessage listGroups( const QDBusMessage &message ); + QDBusMessage listPlugins( const QDBusMessage &message ); + QDBusMessage showGroup( const QDBusMessage &message ); + QDBusMessage showMember( const QDBusMessage &message ); + + QDBusMessage error( const QDBusMessage &, const QString &errorCode, + const QString &errorMessage ); + + private: + QDBusConnection *mConnection; +}; + +#endif diff --git a/kitchensync/src/Makefile.am b/kitchensync/src/Makefile.am new file mode 100644 index 000000000..7f94fc173 --- /dev/null +++ b/kitchensync/src/Makefile.am @@ -0,0 +1,52 @@ +SUBDIRS = about pics + +INCLUDES = -I$(top_srcdir)/kitchensync/src \ + -I$(top_srcdir)/kitchensync \ + -I$(top_srcdir)/libkdepim \ + -I$(top_srcdir) \ + $(all_includes) + +# Application +bin_PROGRAMS = kitchensync + +kitchensync_SOURCES = main.cpp mainwindow.cpp +kitchensync_LDFLAGS = $(KDE_RPATH) $(all_libraries) +kitchensync_LDADD = libkitchensync.la + +xdg_apps_DATA = kitchensync.desktop + +# Library +lib_LTLIBRARIES = libkitchensync.la + +libkitchensync_la_SOURCES = aboutpage.cpp mainwidget.cpp groupconfigdialog.cpp \ + groupconfig.cpp groupitem.cpp groupview.cpp memberconfig.cpp \ + syncprocess.cpp syncprocessmanager.cpp connectionwidgets.cpp \ + pluginpicker.cpp configgui.cpp configguiblank.cpp configguifile.cpp \ + memberinfo.cpp groupconfigcommon.cpp kwidgetlist.cpp \ + configguipalm.cpp conflictdialog.cpp singleconflictdialog.cpp \ + addresseediffalgo.cpp calendardiffalgo.cpp \ + htmldiffalgodisplay.cpp genericdiffalgo.cpp multiconflictdialog.cpp \ + configguiirmc.cpp \ + configguisyncmlobex.cpp configguisyncmlhttp.cpp configguiopie.cpp \ + configguignokii.cpp configguigcalendar.cpp configguildap.cpp configguigpe.cpp \ + configguijescs.cpp configguievo2.cpp configguimoto.cpp configguisynce.cpp \ + configguisunbird.cpp +libkitchensync_la_LDFLAGS = $(all_libraries) $(KDE_RPATH) -no-undefined +libkitchensync_la_LIBADD = $(LIB_KIO) $(LIB_KHTML) $(top_builddir)/kitchensync/libqopensync/libqopensync.la \ + $(LIB_KABC) $(top_builddir)/libkdepim/libkdepim.la $(top_builddir)/libkcal/libkcal.la + +# KPart +kde_module_LTLIBRARIES = libkitchensyncpart.la + +libkitchensyncpart_la_SOURCES = part.cpp +libkitchensyncpart_la_LDFLAGS = -module $(KDE_PLUGIN) $(KDE_RPATH) $(all_libraries) -no-undefined +libkitchensyncpart_la_LIBADD = $(LIB_KPARTS) libkitchensync.la + +# Resources +kitchensyncdatadir = $(kde_datadir)/kitchensync +kitchensyncdata_DATA = kitchensyncui.rc kitchensync_part.rc + +METASOURCES = AUTO + +messages: rc.cpp + $(XGETTEXT) *.cpp *.h -o $(podir)/kitchensync.pot diff --git a/kitchensync/src/about/Makefile.am b/kitchensync/src/about/Makefile.am new file mode 100644 index 000000000..6a4c77c59 --- /dev/null +++ b/kitchensync/src/about/Makefile.am @@ -0,0 +1,6 @@ +about_DATA = \ + top-right-kitchensync.png \ + main.html \ + kitchensync.css + +aboutdir = $(kde_datadir)/kitchensync/about diff --git a/kitchensync/src/about/kitchensync.css b/kitchensync/src/about/kitchensync.css new file mode 100644 index 000000000..18aa0ddcd --- /dev/null +++ b/kitchensync/src/about/kitchensync.css @@ -0,0 +1,30 @@ + +#headerR { + position: absolute; + right: 0px; + width: 430px; + height: 131px; + background-image: url(top-right-kontact.png); +} + +#title { + right: 125px; +} + +#tagline { + right: 125px; +} + +#boxCenter { + background-image: url(box-center-kontact.png); + background-repeat: no-repeat; + background-color: #dfe7f3; + background-position: bottom right; +} + +#subtext { + font-style: italic; +} + +/* vim:set sw=2 et nocindent smartindent: */ + diff --git a/kitchensync/src/about/main.html b/kitchensync/src/about/main.html new file mode 100644 index 000000000..2474a7fca --- /dev/null +++ b/kitchensync/src/about/main.html @@ -0,0 +1,66 @@ +<?xml version="1.0" encoding="utf-8"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> + +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> + <meta name="generator" content= + "HTML Tidy for Linux/x86 (vers 1st August 2004), see www.w3.org" /> + + <style type="text/css"> + /*<![CDATA[*/ + @import "%1"; /* kde_infopage.css */ + %1 /* maybe @import "kde_infopage_rtl.css"; */ + @import "kitchensync.css"; + body {font-size: %1px;} + /*]]>*/ + </style> + + <title>KitchenSync</title> +</head> + +<body> + <div id="header"> + <div id="headerL"/> + <div id="headerR"/> + + <div id="title"> + %2 <!-- KitchenSync --> + </div> + + <div id="tagline"> + %3 <!-- Catchphrase --> + </div> + </div> + + <!-- the bar --> + <div id="bar"> + <div id="barT"><div id="barTL"/><div id="barTR"/><div id="barTC"/></div> + <div id="barL"> + <div id="barR"> + <div id="barCenter" class="bar_text"> + %4<!-- KitchenSync is ... --> + </div> + </div> + </div> + <div id="barB"><div id="barBL"/><div id="barBR"/><div id="barBC"/></div> + </div> + + <!-- the main text box --> + <div id="box"> + <div id="boxT"><div id="boxTL"/><div id="boxTR"/><div id="boxTC"/></div> + <div id="boxL"> + <div id="boxR"> + <div id="boxCenter"> + <!--Welcome to KitchenSync--> + %5 + </div> + </div> + </div> + <div id="boxB"><div id="boxBL"/><div id="boxBR"/><div id="boxBC"/></div> + </div> + + <div id="footer"><div id="footerL"/><div id="footerR"/></div> +</body> +</html> +<!-- vim:set sw=2 et nocindent smartindent: --> diff --git a/kitchensync/src/about/top-right-kitchensync.png b/kitchensync/src/about/top-right-kitchensync.png Binary files differnew file mode 100644 index 000000000..bf15f38b5 --- /dev/null +++ b/kitchensync/src/about/top-right-kitchensync.png diff --git a/kitchensync/src/aboutpage.cpp b/kitchensync/src/aboutpage.cpp new file mode 100644 index 000000000..f8110c4d0 --- /dev/null +++ b/kitchensync/src/aboutpage.cpp @@ -0,0 +1,141 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2005 Tobias Koenig <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include <qfile.h> +#include <qlayout.h> + +#include <kaboutdata.h> +#include <kapplication.h> +#include <kdebug.h> +#include <khtml_part.h> +#include <khtmlview.h> +#include <kiconloader.h> +#include <klocale.h> +#include <krun.h> +#include <kstandarddirs.h> + +#include "aboutpage.h" + +static QString readFile( const QString &fileName ) +{ + QFile file( fileName ); + if ( !file.open( IO_ReadOnly ) ) { + kdDebug() << "Unable to open file '" << fileName << "'" << endl; + return QCString(); + } + + QString content = QString::fromUtf8( file.readAll() ); + + file.close(); + + return content; +} + +AboutPage::AboutPage( QWidget *parent ) + : QWidget( parent, "AboutPage" ) +{ + QVBoxLayout *layout = new QVBoxLayout( this ); + + QString location = locate( "data", "kitchensync/about/main.html" ); + QString content = readFile( location ); + content = content.arg( locate( "data", "libkdepim/about/kde_infopage.css" ) ); + if ( kapp->reverseLayout() ) + content = content.arg( "@import \"%1\";" ).arg( locate( "data", "libkdepim/about/kde_infopage_rtl.css" ) ); + else + content = content.arg( "" ); + + KHTMLPart *part = new KHTMLPart( this ); + layout->addWidget( part->view() ); + + part->begin( KURL( location ) ); + + QString appName( i18n( "KDE KitchenSync" ) ); + QString catchPhrase( i18n( "Get Synchronized!" ) ); + QString quickDescription( i18n( "The KDE Synchronization Tool" ) ); + + part->write( content.arg( QFont().pointSize() + 2 ).arg( appName ) + .arg( catchPhrase ).arg( quickDescription ).arg( htmlText() ) ); + part->end(); + + connect( part->browserExtension(), + SIGNAL( openURLRequest( const KURL&, const KParts::URLArgs& ) ), + SLOT( handleUrl( const KURL& ) ) ); + + connect( part->browserExtension(), + SIGNAL( createNewWindow( const KURL&, const KParts::URLArgs& ) ), + SLOT( handleUrl( const KURL& ) ) ); +} + +void AboutPage::handleUrl( const KURL &url ) +{ + if ( url.protocol() == "exec" ) { + if ( url.path() == "/addGroup" ) + emit addGroup(); + } else + new KRun( url, this ); +} + +QString AboutPage::htmlText() const +{ + KIconLoader *iconloader = KGlobal::iconLoader(); + int iconSize = iconloader->currentSize( KIcon::Desktop ); + + QString handbook_icon_path = iconloader->iconPath( "contents2", KIcon::Desktop ); + QString html_icon_path = iconloader->iconPath( "html", KIcon::Desktop ); + QString wizard_icon_path = iconloader->iconPath( "wizard", KIcon::Desktop ); + + QString info = i18n( "<h2 style='text-align:center; margin-top: 0px;'>Welcome to KitchenSync %1</h2>" + "<p>%1</p>" + "<table align=\"center\">" + "<tr><td><a href=\"%1\"><img width=\"%1\" height=\"%1\" src=\"%1\" /></a></td>" + "<td><a href=\"%1\">%1</a><br><span id=\"subtext\"><nobr>%1</td></tr>" + "<tr><td><a href=\"%1\"><img width=\"%1\" height=\"%1\" src=\"%1\" /></a></td>" + "<td><a href=\"%1\">%1</a><br><span id=\"subtext\"><nobr>%1</td></tr>" + "<tr><td><a href=\"%1\"><img width=\"%1\" height=\"%1\" src=\"%1\" /></a></td>" + "<td><a href=\"%1\">%1</a><br><span id=\"subtext\"><nobr>%1</td></tr>" + "</table>" ) + .arg( kapp->aboutData()->version() ) + .arg( i18n( "KitchenSync synchronizes your e-mail, addressbook, calendar, to-do list and more." ) ) + .arg( "help:/kitchensync" ) + .arg( iconSize ) + .arg( iconSize ) + .arg( handbook_icon_path ) + .arg( "help:/kitchensync" ) + .arg( i18n( "Read Manual" ) ) + .arg( i18n( "Learn more about KitchenSync and its components" ) ) + .arg( "http://pim.kde.org" ) + .arg( iconSize ) + .arg( iconSize ) + .arg( html_icon_path ) + .arg( "http://pim.kde.org" ) + .arg( i18n( "Visit KitchenSync Website" ) ) + .arg( i18n( "Access online resources and tutorials" ) ) + .arg( "exec:/addGroup" ) + .arg( iconSize ) + .arg( iconSize ) + .arg( wizard_icon_path ) + .arg( "exec:/addGroup" ) + .arg( i18n( "Add Synchronization Group" ) ) + .arg( i18n( "Create group of devices for synchronization" ) ); + + return info; +} + +#include "aboutpage.moc" diff --git a/kitchensync/src/aboutpage.h b/kitchensync/src/aboutpage.h new file mode 100644 index 000000000..d0bed85a0 --- /dev/null +++ b/kitchensync/src/aboutpage.h @@ -0,0 +1,45 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2005 Tobias Koenig <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef ABOUTPAGE_H +#define ABOUTPAGE_H + +#include <kurl.h> + +#include <qwidget.h> + +class AboutPage : public QWidget +{ + Q_OBJECT + + public: + AboutPage( QWidget *parent ); + + signals: + void addGroup(); + + private slots: + void handleUrl( const KURL& ); + + private: + QString htmlText() const; +}; + +#endif diff --git a/kitchensync/src/addresseediffalgo.cpp b/kitchensync/src/addresseediffalgo.cpp new file mode 100644 index 000000000..18b924b5a --- /dev/null +++ b/kitchensync/src/addresseediffalgo.cpp @@ -0,0 +1,157 @@ +/* + This file is part of libkdepim. + + Copyright (c) 2004 Tobias Koenig <[email protected]> + + 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 <kabc/vcardconverter.h> + +#include "addresseediffalgo.h" + +using namespace KSync; + +static bool compareString( const QString &left, const QString &right ) +{ + if ( left.isEmpty() && right.isEmpty() ) + return true; + else + return left == right; +} + +AddresseeDiffAlgo::AddresseeDiffAlgo( const KABC::Addressee &leftAddressee, + const KABC::Addressee &rightAddressee ) + : mLeftAddressee( leftAddressee ), mRightAddressee( rightAddressee ) +{ +} + +AddresseeDiffAlgo::AddresseeDiffAlgo( const QString &leftAddressee, + const QString &rightAddressee ) +{ + KABC::VCardConverter converter; + + mLeftAddressee = converter.parseVCard( leftAddressee ); + mRightAddressee = converter.parseVCard( rightAddressee ); +} + +void AddresseeDiffAlgo::run() +{ + begin(); + + if ( !compareString( mLeftAddressee.uid(), mRightAddressee.uid() ) ) + conflictField( KABC::Addressee::uidLabel(), mLeftAddressee.uid(), mRightAddressee.uid() ); + + if ( !compareString( mLeftAddressee.name(), mRightAddressee.name() ) ) + conflictField( KABC::Addressee::nameLabel(), mLeftAddressee.name(), mRightAddressee.name() ); + + if ( !compareString( mLeftAddressee.formattedName(), mRightAddressee.formattedName() ) ) + conflictField( KABC::Addressee::formattedNameLabel(), mLeftAddressee.formattedName(), mRightAddressee.formattedName() ); + + if ( !compareString( mLeftAddressee.familyName(), mRightAddressee.familyName() ) ) + conflictField( KABC::Addressee::familyNameLabel(), mLeftAddressee.familyName(), mRightAddressee.familyName() ); + + if ( !compareString( mLeftAddressee.givenName(), mRightAddressee.givenName() ) ) + conflictField( KABC::Addressee::givenNameLabel(), mLeftAddressee.givenName(), mRightAddressee.givenName() ); + + if ( !compareString( mLeftAddressee.additionalName(), mRightAddressee.additionalName() ) ) + conflictField( KABC::Addressee::additionalNameLabel(), mLeftAddressee.additionalName(), mRightAddressee.additionalName() ); + + if ( !compareString( mLeftAddressee.prefix(), mRightAddressee.prefix() ) ) + conflictField( KABC::Addressee::prefixLabel(), mLeftAddressee.prefix(), mRightAddressee.prefix() ); + + if ( !compareString( mLeftAddressee.suffix(), mRightAddressee.suffix() ) ) + conflictField( KABC::Addressee::suffixLabel(), mLeftAddressee.suffix(), mRightAddressee.suffix() ); + + if ( !compareString( mLeftAddressee.nickName(), mRightAddressee.nickName() ) ) + conflictField( KABC::Addressee::nickNameLabel(), mLeftAddressee.nickName(), mRightAddressee.nickName() ); + + if ( mLeftAddressee.birthday() != mRightAddressee.birthday() ) + conflictField( KABC::Addressee::birthdayLabel(), mLeftAddressee.birthday().toString(), + mRightAddressee.birthday().toString() ); + + if ( !compareString( mLeftAddressee.mailer(), mRightAddressee.mailer() ) ) + conflictField( KABC::Addressee::mailerLabel(), mLeftAddressee.mailer(), mRightAddressee.mailer() ); + + if ( mLeftAddressee.timeZone() != mRightAddressee.timeZone() ) + conflictField( KABC::Addressee::timeZoneLabel(), mLeftAddressee.timeZone().asString(), mRightAddressee.timeZone().asString() ); + + if ( mLeftAddressee.geo() != mRightAddressee.geo() ) + conflictField( KABC::Addressee::geoLabel(), mLeftAddressee.geo().asString(), mRightAddressee.geo().asString() ); + + if ( !compareString( mLeftAddressee.title(), mRightAddressee.title() ) ) + conflictField( KABC::Addressee::titleLabel(), mLeftAddressee.title(), mRightAddressee.title() ); + + if ( !compareString( mLeftAddressee.role(), mRightAddressee.role() ) ) + conflictField( KABC::Addressee::roleLabel(), mLeftAddressee.role(), mRightAddressee.role() ); + + if ( !compareString( mLeftAddressee.organization(), mRightAddressee.organization() ) ) + conflictField( KABC::Addressee::organizationLabel(), mLeftAddressee.organization(), mRightAddressee.organization() ); + + if ( !compareString( mLeftAddressee.note(), mRightAddressee.note() ) ) + conflictField( KABC::Addressee::noteLabel(), mLeftAddressee.note(), mRightAddressee.note() ); + + if ( !compareString( mLeftAddressee.productId(), mRightAddressee.productId() ) ) + conflictField( KABC::Addressee::productIdLabel(), mLeftAddressee.productId(), mRightAddressee.productId() ); + + if ( !compareString( mLeftAddressee.sortString(), mRightAddressee.sortString() ) ) + conflictField( KABC::Addressee::sortStringLabel(), mLeftAddressee.sortString(), mRightAddressee.sortString() ); + + if ( mLeftAddressee.secrecy() != mRightAddressee.secrecy() ) { + conflictField( KABC::Addressee::secrecyLabel(), mLeftAddressee.secrecy().asString(), mRightAddressee.secrecy().asString() ); + } + if ( mLeftAddressee.url()!= mRightAddressee.url() ) + conflictField( KABC::Addressee::urlLabel(), mLeftAddressee.url().prettyURL(), + mRightAddressee.url().prettyURL() ); + + if ( mLeftAddressee.logo() != mRightAddressee.logo() ) { + } + + if ( mLeftAddressee.photo() != mRightAddressee.photo() ) { + } + + diffList( "emails", mLeftAddressee.emails(), mRightAddressee.emails() ); + + diffList( "Phone Numbers", mLeftAddressee.phoneNumbers(), mRightAddressee.phoneNumbers() ); + diffList( "Addresses", mLeftAddressee.addresses(), mRightAddressee.addresses() ); + + end(); +} + +QString AddresseeDiffAlgo::toString( const KABC::PhoneNumber &number ) +{ + return number.number(); +} + +QString AddresseeDiffAlgo::toString( const KABC::Address &addr ) +{ + return addr.formattedAddress(); +} + +template <class L> +void AddresseeDiffAlgo::diffList( const QString &id, + const QValueList<L> &left, const QValueList<L> &right ) +{ + for ( uint i = 0; i < left.count(); ++i ) { + if ( right.find( left[ i ] ) == right.end() ) + additionalLeftField( id, toString( left[ i ] ) ); + } + + for ( uint i = 0; i < right.count(); ++i ) { + if ( left.find( right[ i ] ) == left.end() ) + additionalRightField( id, toString( right[ i ] ) ); + } +} diff --git a/kitchensync/src/addresseediffalgo.h b/kitchensync/src/addresseediffalgo.h new file mode 100644 index 000000000..6eef5a179 --- /dev/null +++ b/kitchensync/src/addresseediffalgo.h @@ -0,0 +1,53 @@ +/* + This file is part of libkdepim. + + Copyright (c) 2004 Tobias Koenig <[email protected]> + + 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 KSYNC_ADDRESSEEDIFFALGO_H +#define KSYNC_ADDRESSEEDIFFALGO_H + +#include <kabc/addressee.h> +#include <libkdepim/diffalgo.h> + +using namespace KPIM; + +namespace KSync { + +class AddresseeDiffAlgo : public DiffAlgo +{ + public: + AddresseeDiffAlgo( const KABC::Addressee &leftAddressee, const KABC::Addressee &rightAddressee ); + AddresseeDiffAlgo( const QString &leftAddressee, const QString &rightAddressee ); + + void run(); + + private: + template <class L> + void diffList( const QString &id, const QValueList<L> &left, const QValueList<L> &right ); + + QString toString( const KABC::PhoneNumber &number ); + QString toString( const KABC::Address &address ); + + KABC::Addressee mLeftAddressee; + KABC::Addressee mRightAddressee; +}; + +} + +#endif diff --git a/kitchensync/src/calendardiffalgo.cpp b/kitchensync/src/calendardiffalgo.cpp new file mode 100644 index 000000000..f7ef174a2 --- /dev/null +++ b/kitchensync/src/calendardiffalgo.cpp @@ -0,0 +1,217 @@ +/* + This file is part of libkdepim. + + Copyright (c) 2004 Tobias Koenig <[email protected]> + + 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 <klocale.h> + +#include <libkcal/kcalversion.h> + +#include "calendardiffalgo.h" + +using namespace KSync; + +#ifndef KDE_USE_FINAL +static bool compareString( const QString &left, const QString &right ) +{ + if ( left.isEmpty() && right.isEmpty() ) + return true; + else + return left == right; +} +#endif + +static QString toString( KCal::Attendee *attendee ) +{ + return attendee->name() + "<" + attendee->email() + ">"; +} + +static QString toString( KCal::Alarm * ) +{ + return QString::null; +} + +static QString toString( KCal::Incidence * ) +{ + return QString::null; +} + +static QString toString( KCal::Attachment * ) +{ + return QString::null; +} + +static QString toString( const QDate &date ) +{ + return date.toString(); +} + +static QString toString( const QDateTime &dateTime ) +{ + return dateTime.toString(); +} + +static QString toString( const QString str ) +{ + return str; +} + +static QString toString( bool value ) +{ + if ( value ) + return i18n( "Yes" ); + else + return i18n( "No" ); +} + +CalendarDiffAlgo::CalendarDiffAlgo( KCal::Incidence *leftIncidence, + KCal::Incidence *rightIncidence ) + : mLeftIncidence( leftIncidence ), mRightIncidence( rightIncidence ) +{ +} + +void CalendarDiffAlgo::run() +{ + begin(); + + diffIncidenceBase( mLeftIncidence, mRightIncidence ); + diffIncidence( mLeftIncidence, mRightIncidence ); + + KCal::Event *leftEvent = dynamic_cast<KCal::Event*>( mLeftIncidence ); + KCal::Event *rightEvent = dynamic_cast<KCal::Event*>( mRightIncidence ); + if ( leftEvent && rightEvent ) { + diffEvent( leftEvent, rightEvent ); + } else { + KCal::Todo *leftTodo = dynamic_cast<KCal::Todo*>( mLeftIncidence ); + KCal::Todo *rightTodo = dynamic_cast<KCal::Todo*>( mRightIncidence ); + if ( leftTodo && rightTodo ) { + diffTodo( leftTodo, rightTodo ); + } + } + + end(); +} + +void CalendarDiffAlgo::diffIncidenceBase( KCal::IncidenceBase *left, KCal::IncidenceBase *right ) +{ + diffList( i18n( "Attendees" ), left->attendees(), right->attendees() ); + + if ( left->dtStart() != right->dtStart() ) + conflictField( i18n( "Start time" ), left->dtStartStr(), right->dtStartStr() ); + + if ( !compareString( left->organizer().fullName(), right->organizer().fullName() ) ) + conflictField( i18n( "Organizer" ), left->organizer().fullName(), right->organizer().fullName() ); + + if ( !compareString( left->uid(), right->uid() ) ) + conflictField( i18n( "UID" ), left->uid(), right->uid() ); + + if ( left->doesFloat() != right->doesFloat() ) + conflictField( i18n( "Is floating" ), toString( left->doesFloat() ), toString( right->doesFloat() ) ); + + if ( left->hasDuration() != right->hasDuration() ) + conflictField( i18n( "Has duration" ), toString( left->hasDuration() ), toString( right->hasDuration() ) ); + + if ( left->duration() != right->duration() ) + conflictField( i18n( "Duration" ), QString::number( left->duration() ), QString::number( right->duration() ) ); +} + +void CalendarDiffAlgo::diffIncidence( KCal::Incidence *left, KCal::Incidence *right ) +{ + if ( !compareString( left->description(), right->description() ) ) + conflictField( i18n( "Description" ), left->description(), right->description() ); + + if ( !compareString( left->summary(), right->summary() ) ) + conflictField( i18n( "Summary" ), left->summary(), right->summary() ); + + if ( left->status() != right->status() ) + conflictField( i18n( "Status" ), left->statusStr(), right->statusStr() ); + + if ( left->secrecy() != right->secrecy() ) + conflictField( i18n( "Secrecy" ), toString( left->secrecy() ), toString( right->secrecy() ) ); + + if ( left->priority() != right->priority() ) + conflictField( i18n( "Priority" ), toString( left->priority() ), toString( right->priority() ) ); + + if ( !compareString( left->location(), right->location() ) ) + conflictField( i18n( "Location" ), left->location(), right->location() ); + + diffList( i18n( "Categories" ), left->categories(), right->categories() ); + diffList( i18n( "Alarms" ), left->alarms(), right->alarms() ); + diffList( i18n( "Resources" ), left->resources(), right->resources() ); + diffList( i18n( "Relations" ), left->relations(), right->relations() ); + diffList( i18n( "Attachments" ), left->attachments(), right->attachments() ); +#if LIBKCAL_IS_VERSION( 1, 3, 1 ) + diffList( i18n( "Exception Dates" ), left->recurrence()->exDates(), right->recurrence()->exDates() ); + diffList( i18n( "Exception Times" ), left->recurrence()->exDateTimes(), right->recurrence()->exDateTimes() ); +#endif + // TODO: recurrence dates and date/times, exrules, rrules + + if ( left->created() != right->created() ) + conflictField( i18n( "Created" ), left->created().toString(), right->created().toString() ); + + if ( !compareString( left->relatedToUid(), right->relatedToUid() ) ) + conflictField( i18n( "Related Uid" ), left->relatedToUid(), right->relatedToUid() ); +} + +void CalendarDiffAlgo::diffEvent( KCal::Event *left, KCal::Event *right ) +{ + if ( left->hasEndDate() != right->hasEndDate() ) + conflictField( i18n( "Has End Date" ), toString( left->hasEndDate() ), toString( right->hasEndDate() ) ); + + if ( left->dtEnd() != right->dtEnd() ) + conflictField( i18n( "End Date" ), left->dtEndStr(), right->dtEndStr() ); + + // TODO: check transparency +} + +void CalendarDiffAlgo::diffTodo( KCal::Todo *left, KCal::Todo *right ) +{ + if ( left->hasStartDate() != right->hasStartDate() ) + conflictField( i18n( "Has Start Date" ), toString( left->hasStartDate() ), toString( right->hasStartDate() ) ); + + if ( left->hasDueDate() != right->hasDueDate() ) + conflictField( i18n( "Has Due Date" ), toString( left->hasDueDate() ), toString( right->hasDueDate() ) ); + + if ( left->dtDue() != right->dtDue() ) + conflictField( i18n( "Due Date" ), left->dtDue().toString(), right->dtDue().toString() ); + + if ( left->hasCompletedDate() != right->hasCompletedDate() ) + conflictField( i18n( "Has Complete Date" ), toString( left->hasCompletedDate() ), toString( right->hasCompletedDate() ) ); + + if ( left->percentComplete() != right->percentComplete() ) + conflictField( i18n( "Complete" ), QString::number( left->percentComplete() ), QString::number( right->percentComplete() ) ); + + if ( left->completed() != right->completed() ) + conflictField( i18n( "Completed" ), toString( left->completed() ), toString( right->completed() ) ); +} + +template <class L> +void CalendarDiffAlgo::diffList( const QString &id, + const QValueList<L> &left, const QValueList<L> &right ) +{ + for ( uint i = 0; i < left.count(); ++i ) { + if ( right.find( left[ i ] ) == right.end() ) + additionalLeftField( id, toString( left[ i ] ) ); + } + + for ( uint i = 0; i < right.count(); ++i ) { + if ( left.find( right[ i ] ) == left.end() ) + additionalRightField( id, toString( right[ i ] ) ); + } +} diff --git a/kitchensync/src/calendardiffalgo.h b/kitchensync/src/calendardiffalgo.h new file mode 100644 index 000000000..fbfb92daa --- /dev/null +++ b/kitchensync/src/calendardiffalgo.h @@ -0,0 +1,55 @@ +/* + This file is part of libkdepim. + + Copyright (c) 2004 Tobias Koenig <[email protected]> + + 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 KSYNC_CALENDARDIFFALGO_H +#define KSYNC_CALENDARDIFFALGO_H + +#include <libkcal/event.h> +#include <libkcal/todo.h> +#include <libkdepim/diffalgo.h> + +using namespace KPIM; + +namespace KSync { + +class CalendarDiffAlgo : public DiffAlgo +{ + public: + CalendarDiffAlgo( KCal::Incidence *leftIncidence, KCal::Incidence *rightIncidence ); + + void run(); + + private: + template <class L> + void diffList( const QString &id, const QValueList<L> &left, const QValueList<L> &right ); + + void diffIncidenceBase( KCal::IncidenceBase*, KCal::IncidenceBase* ); + void diffIncidence( KCal::Incidence*, KCal::Incidence* ); + void diffEvent( KCal::Event*, KCal::Event* ); + void diffTodo( KCal::Todo*, KCal::Todo* ); + + KCal::Incidence *mLeftIncidence; + KCal::Incidence *mRightIncidence; +}; + +} + +#endif diff --git a/kitchensync/src/configgui.cpp b/kitchensync/src/configgui.cpp new file mode 100644 index 000000000..c57b4d991 --- /dev/null +++ b/kitchensync/src/configgui.cpp @@ -0,0 +1,135 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2005 Cornelius Schumacher <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#include "configgui.h" + + +#include "configguiblank.h" +#include "configguifile.h" +#include "configguignokii.h" +#include "configguigpe.h" +#include "configguiirmc.h" +#include "configguildap.h" +#include "configguiopie.h" +#include "configguipalm.h" +#include "configguisyncmlhttp.h" +#include "configguisyncmlobex.h" +#include "configguigcalendar.h" +#include "configguijescs.h" +#include "configguievo2.h" +#include "configguimoto.h" +#include "configguisynce.h" +#include "configguisunbird.h" + +#include "memberinfo.h" + +#include <kdialog.h> +#include <klocale.h> +#include <klineedit.h> + +#include <qlayout.h> +#include <qlabel.h> +#include <qtextedit.h> + +ConfigGui::ConfigGui( const QSync::Member &member, QWidget *parent ) + : QWidget( parent ), mMember( member ) +{ + mTopLayout = new QVBoxLayout( this ); + mTopLayout->setSpacing( KDialog::spacingHint() ); + mTopLayout->setMargin( KDialog::marginHint() ); + + QBoxLayout *nameLayout = new QHBoxLayout( mTopLayout ); + + QLabel *label = new QLabel( i18n("Name:"), this ); + nameLayout->addWidget( label ); + + mNameEdit = new KLineEdit( this ); + nameLayout->addWidget( mNameEdit ); +} + +void ConfigGui::setInstanceName( const QString &t ) +{ + mNameEdit->setText( t ); +} + +QString ConfigGui::instanceName() const +{ + return mNameEdit->text(); +} + +ConfigGui *ConfigGui::Factory::create( const QSync::Member &member, + QWidget *parent ) +{ + QString name = member.pluginName(); + if ( name == "file-sync" ) { + return new ConfigGuiFile( member, parent ); + } else if ( name == "palm-sync" ) { + return new ConfigGuiPalm( member, parent ); + } else if ( name == "irmc-sync" ) { + return new ConfigGuiIRMC( member, parent ); + } else if ( name == "syncml-obex-client" ) { + return new ConfigGuiSyncmlObex( member, parent ); + } else if ( name == "syncml-http-server" ) { + return new ConfigGuiSyncmlHttp( member, parent ); + } else if ( name == "opie-sync" ) { + return new ConfigGuiOpie( member, parent ); + } else if ( name == "gnokii-sync" ) { + return new ConfigGuiGnokii( member, parent ); + } else if ( name == "gpe-sync" ) { + return new ConfigGuiGpe( member, parent ); + } else if ( name == "google-calendar" ) { + return new ConfigGuiGoogleCalendar( member, parent ); + } else if ( name == "ldap-sync" ) { + return new ConfigGuiLdap( member, parent ); + } else if ( name == "kdepim-sync" ) { + return new ConfigGuiBlank( member, parent ); + } else if ( name == "jescs-sync" ) { + return new ConfigGuiJescs( member, parent ); + } else if ( name == "evo2-sync" ) { + return new ConfigGuiEvo2( member, parent ); + } else if ( name == "moto-sync" ) { + return new ConfigGuiMoto( member, parent ); + } else if ( name == "synce-plugin" ) { + return new ConfigGuiSynce( member, parent ); + } else if ( name == "sunbird-sync" ) { + return new ConfigGuiSunbird( member, parent ); + } else { + return new ConfigGuiXml( member, parent ); + } +} + + +ConfigGuiXml::ConfigGuiXml( const QSync::Member &member, QWidget *parent ) + : ConfigGui( member, parent ) +{ + mTextEdit = new QTextEdit( this ); + topLayout()->addWidget( mTextEdit ); +} + +void ConfigGuiXml::load( const QString &xml ) +{ + mTextEdit->setText( xml ); +} + +QString ConfigGuiXml::save() const +{ + return mTextEdit->text(); +} diff --git a/kitchensync/src/configgui.h b/kitchensync/src/configgui.h new file mode 100644 index 000000000..0423be715 --- /dev/null +++ b/kitchensync/src/configgui.h @@ -0,0 +1,72 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2005 Cornelius Schumacher <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ +#ifndef CONFIGGUI_H +#define CONFIGGUI_H + +#include <libqopensync/member.h> + +#include <qwidget.h> + +class QBoxLayout; +class KLineEdit; +class QTextEdit; + +class ConfigGui : public QWidget +{ + public: + ConfigGui( const QSync::Member &, QWidget *parent ); + + class Factory + { + public: + static ConfigGui *create( const QSync::Member &, QWidget *parent ); + }; + + void setInstanceName( const QString & ); + QString instanceName() const; + + virtual void load( const QString &xml ) = 0; + virtual QString save() const = 0; + + QSync::Member member() const { return mMember; } + + QBoxLayout *topLayout() const { return mTopLayout; } + + private: + QSync::Member mMember; + + QBoxLayout *mTopLayout; + KLineEdit *mNameEdit; +}; + +class ConfigGuiXml : public ConfigGui +{ + public: + ConfigGuiXml( const QSync::Member &, QWidget *parent ); + + void load( const QString & ); + QString save() const; + + private: + QTextEdit *mTextEdit; +}; + +#endif diff --git a/kitchensync/src/configguiblank.cpp b/kitchensync/src/configguiblank.cpp new file mode 100644 index 000000000..e3f7dbbc1 --- /dev/null +++ b/kitchensync/src/configguiblank.cpp @@ -0,0 +1,44 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2006 Daniel Gollub <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#include "configguiblank.h" + +#include <klocale.h> + +#include <qlabel.h> +#include <qlayout.h> + +ConfigGuiBlank::ConfigGuiBlank( const QSync::Member &member, QWidget *parent ) + : ConfigGui( member, parent ) +{ + QLabel *label = new QLabel( i18n( "This member/plugin needs no configuration." ), this ); + topLayout()->addWidget( label ); +} + +void ConfigGuiBlank::load( const QString& ) +{ +} + +QString ConfigGuiBlank::save() const +{ + QString xml = "<config></config>"; + return xml; +} diff --git a/kitchensync/src/configguiblank.h b/kitchensync/src/configguiblank.h new file mode 100644 index 000000000..692d470e3 --- /dev/null +++ b/kitchensync/src/configguiblank.h @@ -0,0 +1,35 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2006 Daniel Gollub <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ +#ifndef CONFIGGUIBLANK_H +#define CONFIGGUIBLANK_H + +#include "configgui.h" + +class ConfigGuiBlank : public ConfigGui +{ + public: + ConfigGuiBlank( const QSync::Member &member, QWidget *parent = 0 ); + + void load( const QString &xml ); + QString save() const; +}; + +#endif diff --git a/kitchensync/src/configguievo2.cpp b/kitchensync/src/configguievo2.cpp new file mode 100644 index 000000000..a8856c1e8 --- /dev/null +++ b/kitchensync/src/configguievo2.cpp @@ -0,0 +1,91 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2007 Anirudh Ramesh <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#include "configguievo2.h" + +#include <qdom.h> +#include <qlabel.h> +#include <qlayout.h> +#include <qstring.h> + +#include <kurlrequester.h> +#include <kurl.h> +#include <kfile.h> +#include <kdialog.h> +#include <klocale.h> + +ConfigGuiEvo2::ConfigGuiEvo2( const QSync::Member &member, QWidget *parent ) + : ConfigGui( member, parent ) +{ + initGUI(); +} + +void ConfigGuiEvo2::load( const QString &xml ) +{ + QDomDocument doc; + doc.setContent( xml ); + QDomElement docElement = doc.documentElement(); + QDomNode node; + for( node = docElement.firstChild(); !node.isNull(); node = node.nextSibling() ) { + QDomElement element = node.toElement(); + if ( element.tagName() == "address_path" ) { + mAddressPath->setURL( element.text() ); + } else if ( element.tagName() == "calendar_path" ) { + mCalendarPath->setURL( element.text() ) ; + } else if ( element.tagName() == "tasks_path" ) { + mTasksPath->setURL( element.text() ); + } + } +} + +QString ConfigGuiEvo2::save() const +{ + QString config = "<config>\n"; + + config += QString( "<address_path>%1</address_path>\n" ).arg( mAddressPath->url() ); + config += QString( "<calendar_path>%1</calendar_path>\n" ).arg( mCalendarPath->url() ); + config += QString( "<tasks_path>%1</tasks_path>\n" ).arg( mTasksPath->url() ); + + config += "</config>"; + + return config; +} + +void ConfigGuiEvo2::initGUI() +{ + QGridLayout *layout = new QGridLayout( topLayout(), 12, 3, KDialog::spacingHint() ); + layout->setMargin( KDialog::marginHint() ); + + layout->addWidget( new QLabel( i18n( "Address Book location:" ), this ), 0, 0 ); + mAddressPath = new KURLRequester( this ); + mAddressPath->setMode( KFile::Directory ); + layout->addMultiCellWidget( mAddressPath, 0, 0, 1, 2 ); + + layout->addWidget( new QLabel( i18n( "Calendar location:" ), this ), 1, 0 ); + mCalendarPath = new KURLRequester( this ); + mCalendarPath->setMode( KFile::Directory ); + layout->addMultiCellWidget( mCalendarPath, 1, 1, 1, 2 ); + + layout->addWidget( new QLabel( i18n( "Task list location:" ), this ), 2, 0 ); + mTasksPath = new KURLRequester( this ); + mTasksPath->setMode( KFile::Directory ); + layout->addMultiCellWidget( mTasksPath, 2, 2, 1, 2 ); +} diff --git a/kitchensync/src/configguievo2.h b/kitchensync/src/configguievo2.h new file mode 100644 index 000000000..f9e7ad19e --- /dev/null +++ b/kitchensync/src/configguievo2.h @@ -0,0 +1,46 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2007 Anirudh Ramesh <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#ifndef CONFIGGUIEVO2_H +#define CONFIGGUIEVO2_H + +#include "configgui.h" + +class KURLRequester; + +class ConfigGuiEvo2 : public ConfigGui +{ + public: + ConfigGuiEvo2( const QSync::Member &, QWidget *parent ); + + void load( const QString &xml ); + + QString save() const; + + private: + void initGUI(); + + KURLRequester *mAddressPath; + KURLRequester *mCalendarPath; + KURLRequester *mTasksPath; +}; + +#endif diff --git a/kitchensync/src/configguifile.cpp b/kitchensync/src/configguifile.cpp new file mode 100644 index 000000000..e7974ecb6 --- /dev/null +++ b/kitchensync/src/configguifile.cpp @@ -0,0 +1,81 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2005 Cornelius Schumacher <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#include "configguifile.h" + +#include <kurlrequester.h> +#include <klocale.h> +#include <kdialog.h> + +#include <qlayout.h> +#include <qcheckbox.h> +#include <qlabel.h> +#include <qdom.h> + +ConfigGuiFile::ConfigGuiFile( const QSync::Member &member, QWidget *parent ) + : ConfigGui( member, parent ) +{ + QBoxLayout *filenameLayout = new QHBoxLayout( topLayout() ); + + QLabel *label = new QLabel( i18n("Directory name:"), this ); + filenameLayout->addWidget( label ); + + mFilename = new KURLRequester( this ); + mFilename->setMode( KFile::Directory | KFile::LocalOnly ); + filenameLayout->addWidget( mFilename ); + + QBoxLayout *recursiveLayout = new QHBoxLayout( topLayout() ); + + mRecursive = new QCheckBox( i18n("Sync all subdirectories"), this ); + recursiveLayout->addWidget( mRecursive ); + + topLayout()->addStretch( 1 ); +} + +void ConfigGuiFile::load( const QString &xml ) +{ + QDomDocument doc; + doc.setContent( xml ); + QDomElement docElement = doc.documentElement(); + QDomNode n; + for( n = docElement.firstChild(); !n.isNull(); n = n.nextSibling() ) { + QDomElement e = n.toElement(); + if ( e.tagName() == "path" ) { + mFilename->setURL( e.text() ); + } else if ( e.tagName() == "recursive" ) { + mRecursive->setChecked( e.text() == "TRUE" ); + } + } +} + +QString ConfigGuiFile::save() const +{ + QString xml; + xml = "<config>"; + xml += "<path>" + mFilename->url() + "</path>"; + xml += "<recursive>"; + if ( mRecursive->isChecked() ) xml += "TRUE"; + else xml += "FALSE"; + xml += "</recursive>"; + xml += "</config>"; + + return xml; +} diff --git a/kitchensync/src/configguifile.h b/kitchensync/src/configguifile.h new file mode 100644 index 000000000..6da034f57 --- /dev/null +++ b/kitchensync/src/configguifile.h @@ -0,0 +1,42 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2005 Cornelius Schumacher <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ +#ifndef CONFIGGUIFILE_H +#define CONFIGGUIFILE_H + +#include "configgui.h" + +class KURLRequester; +class QCheckBox; + +class ConfigGuiFile : public ConfigGui +{ + public: + ConfigGuiFile( const QSync::Member &, QWidget *parent ); + + void load( const QString &xml ); + QString save() const; + + private: + KURLRequester *mFilename; + QCheckBox *mRecursive; +}; + +#endif diff --git a/kitchensync/src/configguigcalendar.cpp b/kitchensync/src/configguigcalendar.cpp new file mode 100644 index 000000000..0434de789 --- /dev/null +++ b/kitchensync/src/configguigcalendar.cpp @@ -0,0 +1,103 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2005 Cornelius Schumacher <[email protected]> + Copyright (c) 2006 Eduardo Habkost <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#include "configguigcalendar.h" + +#include <klocale.h> + +#include <qlayout.h> +#include <qlabel.h> +#include <qdom.h> +#include <qlineedit.h> + +ConfigGuiGoogleCalendar::ConfigGuiGoogleCalendar( const QSync::Member &member, QWidget *parent ) + : ConfigGui( member, parent ) +{ + QBoxLayout *userLayout = new QHBoxLayout( topLayout() ); + + QLabel *userLbl= new QLabel( i18n("Username:"), this ); + userLayout->addWidget(userLbl); + + mUsername = new QLineEdit(this); + userLayout->addWidget(mUsername); + + + QBoxLayout *passLayout = new QHBoxLayout( topLayout() ); + + QLabel *passLbl = new QLabel( i18n("Password:"), this ); + passLayout->addWidget(passLbl); + + mPassword = new QLineEdit(this); + mPassword->setEchoMode(QLineEdit::Password); + passLayout->addWidget(mPassword); + + topLayout()->addWidget(new QLabel( i18n("Please notice that currently the password is stored as plain text in the plugin configuration file"), this )); + + QBoxLayout *urlLayout = new QHBoxLayout( topLayout() ); + QLabel *urlLbl = new QLabel( i18n("Calendar URL:"), this ); + urlLayout->addWidget(urlLbl); + + mUrl = new QLineEdit(this); + urlLayout->addWidget(mUrl); + + topLayout()->addStretch( 1 ); +} + +void ConfigGuiGoogleCalendar::load( const QString &xml ) +{ + QDomDocument doc; + doc.setContent( xml ); + QDomElement docElement = doc.documentElement(); + QDomNode n; + for( n = docElement.firstChild(); !n.isNull(); n = n.nextSibling() ) { + QDomElement e = n.toElement(); + if ( e.tagName() == "username" ) { + mUsername->setText(e.text()); + } else if ( e.tagName() == "password" ) { + mPassword->setText(e.text()); + } else if ( e.tagName() == "url" ) { + mUrl->setText(e.text()); + } + } +} + +QString ConfigGuiGoogleCalendar::save() const +{ + QDomDocument doc; + QDomElement root = doc.createElement("config"); + doc.appendChild(root); + + QDomElement un = doc.createElement("username"); + root.appendChild(un); + un.appendChild(doc.createTextNode(mUsername->text())); + + QDomElement pass = doc.createElement("password"); + root.appendChild(pass); + pass.appendChild(doc.createTextNode(mPassword->text())); + + QDomElement url = doc.createElement("url"); + root.appendChild(url); + url.appendChild(doc.createTextNode(mUrl->text())); + + //TODO: Implement me! + return doc.toString(); +} diff --git a/kitchensync/src/configguigcalendar.h b/kitchensync/src/configguigcalendar.h new file mode 100644 index 000000000..e87eb300d --- /dev/null +++ b/kitchensync/src/configguigcalendar.h @@ -0,0 +1,43 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2005 Cornelius Schumacher <[email protected]> + Copyright (c) 2006 Eduardo Habkost <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ +#ifndef CONFIGGUIGCALENDAR_H +#define CONFIGGUIGCALENDAR_H + +#include "configgui.h" + +class QLineEdit; + +class ConfigGuiGoogleCalendar : public ConfigGui +{ + public: + ConfigGuiGoogleCalendar( const QSync::Member &, QWidget *parent ); + + void load( const QString &xml ); + QString save() const; + + private: + QLineEdit *mUsername; + QLineEdit *mPassword; + QLineEdit *mUrl; +}; + +#endif diff --git a/kitchensync/src/configguignokii.cpp b/kitchensync/src/configguignokii.cpp new file mode 100644 index 000000000..1379f5e5a --- /dev/null +++ b/kitchensync/src/configguignokii.cpp @@ -0,0 +1,223 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2006 David Förster <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#include "configguignokii.h" + +#include <klocale.h> +#include <kdialog.h> +#include <kcombobox.h> + +#include <kdebug.h> + +#include <qlayout.h> +#include <qlabel.h> +#include <qlineedit.h> +#include <qcombobox.h> +#include <qdom.h> +#include <qvbox.h> + +ConfigGuiGnokii::ConfigGuiGnokii( const QSync::Member &member, QWidget *parent ) + : ConfigGui( member, parent ) +{ + QGridLayout *layout = new QGridLayout( topLayout() ); + + // Model + QLabel *label = new QLabel( i18n("Model:"), this ); + layout->addWidget( label, 0, 0 ); + + mModel = new KComboBox( true, this ); + layout->addWidget( mModel, 0, 1 ); + mModel->insertItem( "2110" ); + mModel->insertItem( "3110" ); + mModel->insertItem( "6110" ); + mModel->insertItem( "6110" ); + mModel->insertItem( "6160" ); + mModel->insertItem( "6230" ); + mModel->insertItem( "6230i" ); + mModel->insertItem( "6510" ); + mModel->insertItem( "7110" ); + mModel->insertItem( "AT" ); + // This one requires the gnapplet and rfcomm_channel + mModel->insertItem( "3650" ); + mModel->insertItem( "6600" ); + mModel->insertItem( "gnapplet" ); + mModel->insertItem( "symbian" ); + mModel->insertItem( "sx1" ); + + connect( mModel, SIGNAL (activated( int ) ), + this, SLOT( slotModelChanged () ) ); + + // Connection + label = new QLabel( i18n("Connection:"), this ); + layout->addWidget( label, 1, 0 ); + + mConnection = new QComboBox( this ); + layout->addWidget( mConnection, 1, 1 ); + + connect( mConnection, SIGNAL (activated( int ) ), + this, SLOT( slotConnectionChanged ( int ) ) ); + + // this is a list of all connection types accepted by the gnokii-sync plugin + mConnectionTypes.append( ConnectionType( "bluetooth", i18n( "Bluetooth" ) ) ); + mConnectionTypes.append( ConnectionType( "irda", i18n( "IrDA" ) ) ); + mConnectionTypes.append( ConnectionType( "serial", i18n( "Serial" ) ) ); + mConnectionTypes.append( ConnectionType( "infrared", i18n( "Infrared" ) ) ); + mConnectionTypes.append( ConnectionType( "tcp", i18n( "TCP" ) ) ); + mConnectionTypes.append( ConnectionType( "dku2", i18n( "USB (nokia_dku2)" ) ) ); + mConnectionTypes.append( ConnectionType( "dku2libusb", i18n( "USB (libusb)" ) ) ); + mConnectionTypes.append( ConnectionType( "dau9p", i18n( "Serial (DAU9P cable)" ) ) ); + mConnectionTypes.append( ConnectionType( "dlr3p", i18n( "Serial (DLR3P cable)" ) ) ); + mConnectionTypes.append( ConnectionType( "tekram", i18n( "Tekram Ir-Dongle" ) ) ); + mConnectionTypes.append( ConnectionType( "m2bus", i18n( "Serial (M2BUS protocol)" ) ) ); + + ConnectionTypeList::ConstIterator it; + for ( it = mConnectionTypes.begin(); it != mConnectionTypes.end(); it++ ) { + mConnection->insertItem( (*it).second ); + } + + QVBox *connectionWidget = new QVBox( this ); + connectionWidget->setMargin( KDialog::marginHint() ); + connectionWidget->setSpacing( 5 ); + + mBluetooth = new BluetoothWidget( connectionWidget ); + mBluetooth->hide(); + + layout->addMultiCellWidget( connectionWidget, 2, 2, 0, 1 ); + + // Port + mPortLabel = new QLabel( i18n("Port:"), this ); + layout->addWidget( mPortLabel, 2, 0 ); + mPortLabel->hide(); + + mPort = new KComboBox( true, this ); + layout->addWidget( mPort, 2, 1 ); + mPort->hide(); + + mPort->insertItem( "/dev/ircomm0" ); + mPort->insertItem( "/dev/ircomm1" ); + mPort->insertItem( "/dev/ttyS0" ); + mPort->insertItem( "/dev/ttyS1" ); + mPort->insertItem( "/dev/ttyUSB0" ); + mPort->insertItem( "/dev/ttyUSB1" ); + + layout->setColStretch( 1, 1 ); + + topLayout()->addStretch( 1 ); +} + +void ConfigGuiGnokii::slotConnectionChanged( int nth ) +{ + mPort->hide(); + mPortLabel->hide(); + mBluetooth->hide(); + + // Bluetooth + if ( nth == 0 ) { + mBluetooth->show(); + slotModelChanged(); + + if ( !mPort->currentText().isEmpty() ) + mBluetooth->setAddress( mPort->currentText() ); + + // dku2libusb + } else if ( nth == 6 ) { + // No widget needed. + } else { + mPort->show(); + mPortLabel->show(); + } + +} + +void ConfigGuiGnokii::slotModelChanged() +{ + mBluetooth->hideChannel(); + + if ( mModel->currentText() == "gnapplet" + || mModel->currentText() == "symbian" + || mModel->currentText() == "3650" + || mModel->currentText() == "6600" + || mModel->currentText() == "sx1") + mBluetooth->showChannel(); + else + mBluetooth->setChannel(""); +} + +void ConfigGuiGnokii::load( const QString &xml ) +{ + QDomDocument doc; + doc.setContent( xml ); + QDomElement docElement = doc.documentElement(); + QDomNode n; + for( n = docElement.firstChild(); !n.isNull(); n = n.nextSibling() ) { + QDomElement e = n.toElement(); + if ( e.tagName() == "connection" ) { + for ( uint i = 0; i < mConnectionTypes.count(); i++ ) { + if ( mConnectionTypes[i].first == e.text()) { + mConnection->setCurrentItem( i ); + slotConnectionChanged( i ); + break; + } + } + } else if ( e.tagName() == "port" ) { + mPort->setCurrentText( e.text() ); + } else if ( e.tagName() == "model" ) { + mModel->setCurrentText( e.text() ); + } else if ( e.tagName() == "rfcomm_channel" ) { + mBluetooth->setChannel( e.text() ); + mBluetooth->showChannel(); + } + } +} + +QString ConfigGuiGnokii::save() const +{ + QString xml; + xml = "<config>"; + + ConnectionTypeList::ConstIterator it; + for ( it = mConnectionTypes.begin(); it != mConnectionTypes.end(); it++ ) { + if ( mConnection->currentText() == (*it).second ) { + xml += "<connection>" + (*it).first + "</connection>"; + break; + } + } + + if ( (*it).first == "bluetooth" ) + xml += "<port>" + mBluetooth->address() + "</port>"; + else if ( (*it).first == "dku2libusb" ) + xml += "<port>" + QString("FF:FF:FF:FF:FF:FF") + "</port>"; // Only place holder for libgnokii + else + xml += "<port>" + mPort->currentText() + "</port>"; + + // model + xml += "<model>" + mModel->currentText() + "</model>"; + + // rfcomm_channel + if ( !mBluetooth->channel().isNull() ) + xml += "<rfcomm_channel>" + mBluetooth->channel() + "</rfcomm_channel>"; + + xml += "</config>"; + + return xml; +} + +#include "configguignokii.moc" diff --git a/kitchensync/src/configguignokii.h b/kitchensync/src/configguignokii.h new file mode 100644 index 000000000..6f413a4c1 --- /dev/null +++ b/kitchensync/src/configguignokii.h @@ -0,0 +1,62 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2006 David Förster <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ +#ifndef CONFIGGUIGNOKII_H +#define CONFIGGUIGNOKII_H + +#include "configgui.h" +#include "connectionwidgets.h" + +#include <qvaluelist.h> +#include <qpair.h> + +class QLabel; +class QLineEdit; +class QComboBox; + +class ConfigGuiGnokii : public ConfigGui +{ + Q_OBJECT + + public: + ConfigGuiGnokii( const QSync::Member &, QWidget *parent ); + + void load( const QString &xml ); + QString save() const; + + private: + QComboBox *mConnection; + KComboBox *mPort; + QLabel *mPortLabel; + KComboBox *mModel; + + BluetoothWidget *mBluetooth; + + typedef QPair<QString, QString> ConnectionType; + typedef QValueList<ConnectionType> ConnectionTypeList; + ConnectionTypeList mConnectionTypes; + + protected slots: + void slotConnectionChanged( int nth ); + void slotModelChanged(); + +}; + +#endif diff --git a/kitchensync/src/configguigpe.cpp b/kitchensync/src/configguigpe.cpp new file mode 100644 index 000000000..4b71c766a --- /dev/null +++ b/kitchensync/src/configguigpe.cpp @@ -0,0 +1,103 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2007 Tobias Koenig <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#include "configguigpe.h" + +#include <qcheckbox.h> +#include <qdom.h> +#include <qlabel.h> +#include <qlayout.h> +#include <qspinbox.h> + +#include <kcombobox.h> +#include <kdialog.h> +#include <klineedit.h> +#include <klocale.h> + +ConfigGuiGpe::ConfigGuiGpe( const QSync::Member &member, QWidget *parent ) + : ConfigGui( member, parent ) +{ + initGUI(); + + mConnectionMode->insertItem( i18n( "Local" ) ); + mConnectionMode->insertItem( i18n( "Ssh" ) ); +} + +void ConfigGuiGpe::load( const QString &xml ) +{ + QDomDocument doc; + doc.setContent( xml ); + QDomElement docElement = doc.documentElement(); + QDomNode node; + for( node = docElement.firstChild(); !node.isNull(); node = node.nextSibling() ) { + QDomElement element = node.toElement(); + if ( element.tagName() == "use_local" ) { + if ( element.text().toInt() == 1 ) + mConnectionMode->setCurrentItem( 0 ); + else + mConnectionMode->setCurrentItem( 1 ); + } else if ( element.tagName() == "handheld_ip" ) { + mIP->setText( element.text() ); + } else if ( element.tagName() == "handheld_port" ) { + mPort->setValue( element.text().toInt() ); + } else if ( element.tagName() == "handheld_user" ) { + mUser->setText( element.text() ); + } + } +} + +QString ConfigGuiGpe::save() const +{ + QString config = "<config>"; + + config += QString( "<use_local>%1</use_local>" ).arg( mConnectionMode->currentItem() == 0 ); + config += QString( "<use_ssh>%1</use_ssh>" ).arg( mConnectionMode->currentItem() == 1 ); + config += QString( "<handheld_ip>%1</handheld_ip>" ).arg( mIP->text() ); + config += QString( "<handheld_port>%1</handheld_port>" ).arg( mPort->value() ); + config += QString( "<handheld_user>%1</handheld_user>" ).arg( mUser->text() ); + + config += "</config>"; + + return config; +} + +void ConfigGuiGpe::initGUI() +{ + QGridLayout *layout = new QGridLayout( topLayout(), 12, 4, KDialog::spacingHint() ); + layout->setMargin( KDialog::marginHint() ); + + layout->addWidget( new QLabel( i18n( "Connection Mode:" ), this ), 0, 0 ); + mConnectionMode = new KComboBox( this ); + layout->addMultiCellWidget( mConnectionMode, 0, 0, 0, 3 ); + + layout->addWidget( new QLabel( i18n( "IP Address:" ), this ), 1, 0 ); + mIP = new KLineEdit( this ); + mIP->setInputMask( "000.000.000.000" ); + layout->addWidget( mIP, 1, 1 ); + + layout->addWidget( new QLabel( i18n( "Port:" ), this ), 1, 2, Qt::AlignRight ); + mPort = new QSpinBox( 1, 65536, 1, this ); + layout->addWidget( mPort, 1, 3 ); + + layout->addWidget( new QLabel( i18n( "User:" ), this ), 2, 0 ); + mUser = new KLineEdit( this ); + layout->addMultiCellWidget( mUser, 2, 2, 1, 3 ); +} diff --git a/kitchensync/src/configguigpe.h b/kitchensync/src/configguigpe.h new file mode 100644 index 000000000..48f66674e --- /dev/null +++ b/kitchensync/src/configguigpe.h @@ -0,0 +1,50 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2007 Tobias Koenig <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#ifndef CONFIGGUIGPE_H +#define CONFIGGUIGPE_H + +#include "configgui.h" + +class QSpinBox; + +class KComboBox; +class KLineEdit; + +class ConfigGuiGpe : public ConfigGui +{ + public: + ConfigGuiGpe( const QSync::Member &, QWidget *parent ); + + void load( const QString &xml ); + QString save() const; + + private: + void initGUI(); + + KComboBox *mConnectionMode; + + KLineEdit *mIP; + QSpinBox *mPort; + KLineEdit *mUser; +}; + +#endif diff --git a/kitchensync/src/configguiirmc.cpp b/kitchensync/src/configguiirmc.cpp new file mode 100644 index 000000000..54d837b68 --- /dev/null +++ b/kitchensync/src/configguiirmc.cpp @@ -0,0 +1,192 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2005 Tobias Koenig <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#include <kcombobox.h> +#include <kdialog.h> +#include <kglobal.h> +#include <kiconloader.h> +#include <kinputdialog.h> +#include <klineedit.h> +#include <klocale.h> +#include <kmessagebox.h> + +#include <kdebug.h> + +#include <qapplication.h> +#include <qeventloop.h> +#include <qlabel.h> +#include <qlayout.h> +#include <qpushbutton.h> +#include <qspinbox.h> +#include <qtabwidget.h> +#include <qtooltip.h> +#include <qvbox.h> + +#include "configguiirmc.h" + +ConfigGuiIRMC::ConfigGuiIRMC( const QSync::Member &member, QWidget *parent ) + : ConfigGui( member, parent ) +{ + initGUI(); + + mConnectionType->insertItem( i18n( "Bluetooth" ) ); + mConnectionType->insertItem( i18n( "InfraRed (IR)" ) ); + mConnectionType->insertItem( i18n( "Cable" ) ); + + connect( mConnectionType, SIGNAL( activated( int ) ), + this, SLOT( connectionTypeChanged( int ) ) ); + + connectionTypeChanged( 0 ); +} + +void ConfigGuiIRMC::load( const QString &xml ) +{ + QDomDocument doc; + doc.setContent( xml ); + QDomElement docElement = doc.documentElement(); + QDomNode node; + for ( node = docElement.firstChild(); !node.isNull(); node = node.nextSibling() ) { + QDomElement element = node.toElement(); + if ( element.tagName() == "connectmedium" ) { + if ( element.text() == "bluetooth" ) { + mConnectionType->setCurrentItem( 0 ); + connectionTypeChanged( 0 ); + } else if ( element.text() == "ir" ) { + mConnectionType->setCurrentItem( 1 ); + connectionTypeChanged( 1 ); + } else if ( element.text() == "cable" ) { + mConnectionType->setCurrentItem( 2 ); + connectionTypeChanged( 2 ); + } + } else if (element.tagName() == "btunit" ) { + mBluetoothWidget->setAddress( element.text() ); + } else if (element.tagName() == "btchannel" ) { + mBluetoothWidget->setChannel( element.text() ); + } else if (element.tagName() == "donttellsync" ) { + mDontTellSync->setChecked( element.text() == "true" ); + } + + + } + + mIRWidget->load( docElement ); + mCableWidget->load( docElement ); +} + +QString ConfigGuiIRMC::save() const +{ + QDomDocument doc; + QDomElement config = doc.createElement( "config" ); + doc.appendChild( config ); + + QDomElement element = doc.createElement( "connectmedium" ); + if ( mConnectionType->currentItem() == 0 ) + element.appendChild( doc.createTextNode( "bluetooth" ) ); + if ( mConnectionType->currentItem() == 1 ) + element.appendChild( doc.createTextNode( "ir" ) ); + if ( mConnectionType->currentItem() == 2 ) + element.appendChild( doc.createTextNode( "cable" ) ); + + config.appendChild( element ); + + if ( mConnectionType->currentItem() == 0 ) { + QDomElement btunit = doc.createElement( "btunit" ); + if ( !mBluetoothWidget->address().isEmpty() ) + btunit.appendChild( doc.createTextNode( mBluetoothWidget->address() ) ); + + QDomElement btchannel = doc.createElement( "btchannel" ); + if ( !mBluetoothWidget->channel().isEmpty() ) + btchannel.appendChild( doc.createTextNode( mBluetoothWidget->channel() ) ); + + config.appendChild( btunit ); + config.appendChild( btchannel ); + } + + if ( mDontTellSync->isChecked() ) { + QDomElement dontellsync = doc.createElement( "donttellsync" ); + dontellsync.appendChild( doc.createTextNode( "true" ) ); + config.appendChild( dontellsync ); + } + + mIRWidget->save( doc, config ); + mCableWidget->save( doc, config ); + + return doc.toString(); +} + +void ConfigGuiIRMC::connectionTypeChanged( int type ) +{ + mBluetoothWidget->hide(); + mIRWidget->hide(); + mCableWidget->hide(); + + if ( type == 0 ) + mBluetoothWidget->show(); + else if ( type == 1 ) + mIRWidget->show(); + else + mCableWidget->show(); +} + +void ConfigGuiIRMC::initGUI() +{ + QTabWidget *tabWidget = new QTabWidget( this ); + topLayout()->addWidget( tabWidget ); + + QVBox *connectionWidget = new QVBox( tabWidget ); + connectionWidget->setMargin( KDialog::marginHint() ); + connectionWidget->setSpacing( 5 ); + + tabWidget->addTab( connectionWidget, i18n( "Connection" ) ); + + mConnectionType = new KComboBox( connectionWidget ); + QToolTip::add( mConnectionType, i18n( "Select your connection type." ) ); + + mBluetoothWidget = new BluetoothWidget( connectionWidget ); + mBluetoothWidget->hide(); + + mIRWidget = new IRWidget( connectionWidget ); + mIRWidget->hide(); + + mCableWidget = new CableWidget( connectionWidget ); + mCableWidget->hide(); + + connectionWidget->setStretchFactor( mBluetoothWidget, 1 ); + connectionWidget->setStretchFactor( mIRWidget, 1 ); + connectionWidget->setStretchFactor( mCableWidget, 1 ); + + QVBox *optionsWidget = new QVBox( tabWidget ); + optionsWidget->setMargin( KDialog::marginHint() ); + optionsWidget->setSpacing( 5 ); + + tabWidget->addTab( optionsWidget, i18n( "Options" ) ); + + QHBox *optionBox = new QHBox( optionsWidget ); + optionBox->setSpacing( KDialog::spacingHint() ); + + QLabel *label = new QLabel( i18n( "Don't send OBEX UUID (IRMC-SYNC)" ), optionBox ); + mDontTellSync = new QCheckBox( optionBox ); + QToolTip::add( mDontTellSync, i18n( "Don't send OBEX UUID while connecting. Needed for older IrMC based mobile phones." ) ); + label->setBuddy( mDontTellSync ); + +} + +#include "configguiirmc.moc" diff --git a/kitchensync/src/configguiirmc.h b/kitchensync/src/configguiirmc.h new file mode 100644 index 000000000..a50051679 --- /dev/null +++ b/kitchensync/src/configguiirmc.h @@ -0,0 +1,61 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2005 Tobias Koenig <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#ifndef CONFIGGUIIRMC_H +#define CONFIGGUIIRMC_H + +#include <qcheckbox.h> +#include <qdom.h> + +#include "configgui.h" +#include "connectionwidgets.h" + +class KComboBox; +class KLineEdit; +class QCheckBox; +class QPushButton; +class QSpinBox; + +class ConfigGuiIRMC : public ConfigGui +{ + Q_OBJECT + + public: + ConfigGuiIRMC( const QSync::Member &, QWidget *parent ); + + void load( const QString &xml ); + QString save() const; + + protected slots: + void connectionTypeChanged( int type ); + + private: + void initGUI(); + + KComboBox *mConnectionType; + QCheckBox *mDontTellSync; + + BluetoothWidget *mBluetoothWidget; + IRWidget *mIRWidget; + CableWidget *mCableWidget; +}; + +#endif diff --git a/kitchensync/src/configguijescs.cpp b/kitchensync/src/configguijescs.cpp new file mode 100644 index 000000000..6a66e8590 --- /dev/null +++ b/kitchensync/src/configguijescs.cpp @@ -0,0 +1,98 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2007 Anirudh Ramesh <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#include "configguijescs.h" + +#include <qcheckbox.h> +#include <qdom.h> +#include <qlabel.h> +#include <qlayout.h> + +#include <klineedit.h> +#include <kdialog.h> +#include <klocale.h> + +ConfigGuiJescs::ConfigGuiJescs( const QSync::Member &member, QWidget *parent ) + : ConfigGui( member, parent ) +{ + initGUI(); +} + +void ConfigGuiJescs::load( const QString &xml ) +{ + QDomDocument doc; + doc.setContent( xml ); + QDomElement docElement = doc.documentElement(); + QDomNode node; + for( node = docElement.firstChild(); !node.isNull(); node = node.nextSibling() ) { + QDomElement element = node.toElement(); + if ( element.tagName() == "url" ) { + mUrl->setText( element.text() ); + } else if ( element.tagName() == "username" ) { + mUsername->setText( element.text() ); + } else if ( element.tagName() == "password" ) { + mPassword->setText( element.text() ); + } else if ( element.tagName() == "del_notify" ) { + mDelNotify->setChecked( element.text() == "1" ); + } + } +} + +QString ConfigGuiJescs::save() const +{ + int delNotifyState; + QString config = "<config>\n"; + + config += QString( "<url>%1</url>\n" ).arg( mUrl->text() ); + config += QString( "<username>%1</username>\n" ).arg( mUsername->text() ); + config += QString( "<password>%1</password>\n" ).arg( mPassword->text() ); + if ( mDelNotify->isChecked() ) { delNotifyState = 1; + } else { delNotifyState = 0; + } + config += QString( "<del_notify>%1</del_notify>\n" ).arg( delNotifyState ); + + config += "</config>"; + + return config; +} + +void ConfigGuiJescs::initGUI() +{ + QGridLayout *layout = new QGridLayout( topLayout(), 12, 3, KDialog::spacingHint() ); + layout->setMargin( KDialog::marginHint() ); + + layout->addWidget( new QLabel( i18n( "URL:" ), this ), 0, 0 ); + mUrl = new KLineEdit( this ); + layout->addMultiCellWidget( mUrl, 0, 0, 1, 2 ); + + layout->addWidget( new QLabel( i18n( "Username:" ), this ), 1, 0 ); + mUsername = new KLineEdit( this ); + layout->addMultiCellWidget( mUsername, 1, 1, 1, 2 ); + + layout->addWidget( new QLabel( i18n( "Password:" ), this ), 2, 0 ); + mPassword = new KLineEdit( this ); + mPassword->setEchoMode( KLineEdit::Password ); + layout->addMultiCellWidget( mPassword, 2, 2, 1, 2 ); + + mDelNotify = new QCheckBox( this ); + mDelNotify->setText( "Notify attendees about event/task deletion" ); + layout->addMultiCellWidget( mDelNotify, 3, 3, 0, 2 ); +} diff --git a/kitchensync/src/configguijescs.h b/kitchensync/src/configguijescs.h new file mode 100644 index 000000000..4e56376bb --- /dev/null +++ b/kitchensync/src/configguijescs.h @@ -0,0 +1,48 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2007 Anirudh Ramesh <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#ifndef CONFIGGUIJESCS_H +#define CONFIGGUIJESCS_H + +#include "configgui.h" + +class KLineEdit; +class QCheckBox; + +class ConfigGuiJescs : public ConfigGui +{ + public: + ConfigGuiJescs( const QSync::Member &, QWidget *parent ); + + void load( const QString &xml ); + + QString save() const; + + private: + void initGUI(); + + KLineEdit *mUrl; + KLineEdit *mUsername; + KLineEdit *mPassword; + QCheckBox *mDelNotify; +}; + +#endif diff --git a/kitchensync/src/configguildap.cpp b/kitchensync/src/configguildap.cpp new file mode 100644 index 000000000..ce4881156 --- /dev/null +++ b/kitchensync/src/configguildap.cpp @@ -0,0 +1,153 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2007 Tobias Koenig <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#include "configguildap.h" + +#include <qcheckbox.h> +#include <qdom.h> +#include <qlabel.h> +#include <qlayout.h> +#include <qspinbox.h> + +#include <kcombobox.h> +#include <kdialog.h> +#include <klineedit.h> +#include <klocale.h> + +ConfigGuiLdap::ConfigGuiLdap( const QSync::Member &member, QWidget *parent ) + : ConfigGui( member, parent ) +{ + initGUI(); + + mSearchScope->insertItem( i18n( "Base" ) ); + mSearchScope->insertItem( i18n( "One" ) ); + mSearchScope->insertItem( i18n( "Sub" ) ); +} + +void ConfigGuiLdap::load( const QString &xml ) +{ + QDomDocument doc; + doc.setContent( xml ); + QDomElement docElement = doc.documentElement(); + QDomNode node; + for( node = docElement.firstChild(); !node.isNull(); node = node.nextSibling() ) { + QDomElement element = node.toElement(); + if ( element.tagName() == "servername" ) { + mLdapWidget->setHost( element.text() ); + } else if ( element.tagName() == "serverport" ) { + mLdapWidget->setPort( element.text().toInt() ); + } else if ( element.tagName() == "binddn" ) { + mLdapWidget->setBindDN( element.text() ); + } else if ( element.tagName() == "password" ) { + mLdapWidget->setPassword( element.text() ); + } else if ( element.tagName() == "anonymous" ) { + mLdapWidget->setAuthAnon( element.text().toInt() == 1 ); + } else if ( element.tagName() == "searchbase" ) { + mLdapWidget->setDn( element.text() ); + } else if ( element.tagName() == "searchfilter" ) { + mLdapWidget->setFilter( element.text() ); + } else if ( element.tagName() == "storebase" ) { + mLdapWidget->setDn( element.text() ); + } else if ( element.tagName() == "keyattr" ) { + mKeyAttribute->setText( element.text() ); + } else if ( element.tagName() == "scope" ) { + QStringList list; + list << "base" << "one" << "sub"; + for ( uint i = 0; i < list.count(); ++i ) + if ( list[ i ] == element.text() ) + mSearchScope->setCurrentItem( i ); + + } else if ( element.tagName() == "authmech" ) { + if ( element.text() == "SIMPLE" ) { + mLdapWidget->setAuthSimple( true ); + } + } else if ( element.tagName() == "encryption" ) { + mEncryption->setChecked( element.text().toInt() == 1 ); + } else if ( element.tagName() == "ldap_read" ) { + mReadLdap->setChecked( element.text().toInt() == 1 ); + } else if ( element.tagName() == "ldap_write" ) { + mWriteLdap->setChecked( element.text().toInt() == 1 ); + } + } +} + +QString ConfigGuiLdap::save() const +{ + QString config = "<config>\n"; + + config += QString( "<servername>%1</servername>\n" ).arg( mLdapWidget->host() ); + config += QString( "<serverport>%1</serverport>\n" ).arg( mLdapWidget->port() ); + config += QString( "<binddn>%1</binddn>\n" ).arg( mLdapWidget->bindDN() ); + config += QString( "<password>%1</password>\n" ).arg( mLdapWidget->password() ); + config += QString( "<anonymous>%1</anonymous>\n" ).arg( mLdapWidget->isAuthAnon() ? "1" : "0" ); + config += QString( "<searchbase>%1</searchbase>\n" ).arg( mLdapWidget->dn() ); + config += QString( "<searchfilter>%1</searchfilter>\n" ).arg( mLdapWidget->filter() ); + config += QString( "<storebase>%1</storebase>\n" ).arg( mLdapWidget->dn() ); + config += QString( "<keyattr>%1</keyattr>\n" ).arg( mKeyAttribute->text() ); + + QStringList scopes; + scopes << "base" << "one" << "sub"; + + config += QString( "<scope>%1</scope>\n" ).arg( scopes[ mSearchScope->currentItem() ] ); + + config += QString( "<authmech>SIMPLE</authmech>\n" ); + config += QString( "<encryption>%1</encryption>\n" ).arg( mEncryption->isChecked() ? "1" : "0" ); + + config += QString( "<ldap_read>%1</ldap_read>\n" ).arg( mReadLdap->isChecked() ? "1" : "0" ); + config += QString( "<ldap_write>%1</ldap_write>\n" ).arg( mWriteLdap->isChecked() ? "1" : "0" ); + + config += "</config>"; + + return config; +} + +void ConfigGuiLdap::initGUI() +{ + QGridLayout *layout = new QGridLayout( topLayout(), 12, 4, KDialog::spacingHint() ); + layout->setMargin( KDialog::marginHint() ); + + mLdapWidget = new KABC::LdapConfigWidget( KABC::LdapConfigWidget::W_HOST | + KABC::LdapConfigWidget::W_PORT | + KABC::LdapConfigWidget::W_USER | + KABC::LdapConfigWidget::W_PASS | + KABC::LdapConfigWidget::W_BINDDN | + KABC::LdapConfigWidget::W_DN | + KABC::LdapConfigWidget::W_FILTER | + KABC::LdapConfigWidget::W_AUTHBOX, this ); + + mKeyAttribute = new KLineEdit( this ); + mSearchScope = new KComboBox( this ); + mEncryption = new QCheckBox( i18n( "Use encryption" ), this ); + mReadLdap = new QCheckBox( i18n( "Load data from LDAP" ), this ); + mWriteLdap = new QCheckBox( i18n( "Save data to LDAP" ), this ); + + layout->addMultiCellWidget( mLdapWidget, 0, 9, 0, 3 ); + layout->addWidget( new QLabel( i18n( "Key Attribute:" ), this ), 10, 0 ); + layout->addMultiCellWidget( mKeyAttribute, 10, 10, 1, 2 ); + layout->addWidget( new QLabel( i18n( "Search Scope:" ), this ), 11, 0 ); + layout->addMultiCellWidget( mSearchScope, 11, 11, 1, 2 ); + layout->addWidget( mEncryption, 12, 0 ); + layout->addWidget( mReadLdap, 13, 0 ); + layout->addWidget( mWriteLdap, 13, 3 ); + +} + +#include "configguildap.moc" diff --git a/kitchensync/src/configguildap.h b/kitchensync/src/configguildap.h new file mode 100644 index 000000000..e02d7ab68 --- /dev/null +++ b/kitchensync/src/configguildap.h @@ -0,0 +1,58 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2007 Tobias Koenig <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#ifndef CONFIGGUILDAP_H +#define CONFIGGUILDAP_H + +#include "configgui.h" +#include "kabc/ldapconfigwidget.h" + +class QCheckBox; +class QLabel; +class QSpinBox; + +class KABC::LdapConfigWidget; +class KComboBox; +class KLineEdit; + +class ConfigGuiLdap : public ConfigGui +{ + Q_OBJECT + + public: + ConfigGuiLdap( const QSync::Member &, QWidget *parent ); + + void load( const QString &xml ); + QString save() const; + + private: + void initGUI(); + + KABC::LdapConfigWidget *mLdapWidget; + KLineEdit *mKeyAttribute; + KComboBox *mSearchScope; + QCheckBox *mEncryption; + QCheckBox *mReadLdap; + QCheckBox *mWriteLdap; + +}; + +#endif diff --git a/kitchensync/src/configguimoto.cpp b/kitchensync/src/configguimoto.cpp new file mode 100644 index 000000000..80c493dca --- /dev/null +++ b/kitchensync/src/configguimoto.cpp @@ -0,0 +1,71 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2007 Anirudh Ramesh <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#include "configguimoto.h" + +#include <qdom.h> +#include <qlabel.h> +#include <qlayout.h> + +#include <klineedit.h> +#include <kdialog.h> +#include <klocale.h> + +ConfigGuiMoto::ConfigGuiMoto( const QSync::Member &member, QWidget *parent ) + : ConfigGui( member, parent ) +{ + initGUI(); +} + +void ConfigGuiMoto::load( const QString &xml ) +{ + QDomDocument doc; + doc.setContent( xml ); + QDomElement docElement = doc.documentElement(); + QDomNode node; + for( node = docElement.firstChild(); !node.isNull(); node = node.nextSibling() ) { + QDomElement element = node.toElement(); + if ( element.tagName() == "device" ) { + mDeviceString->setText( element.text() ); + } + } +} + +QString ConfigGuiMoto::save() const +{ + QString config = "<config>\n"; + + config += QString( "<device>%1</device>\n" ).arg( mDeviceString->text() ); + + config += "</config>"; + + return config; +} + +void ConfigGuiMoto::initGUI() +{ + QGridLayout *layout = new QGridLayout( topLayout(), 12, 3, KDialog::spacingHint() ); + layout->setMargin( KDialog::marginHint() ); + + layout->addWidget( new QLabel( i18n( "Device String:" ), this ), 0, 0 ); + mDeviceString = new KLineEdit( this ); + layout->addMultiCellWidget( mDeviceString, 0, 0, 1, 2 ); +} diff --git a/kitchensync/src/configguimoto.h b/kitchensync/src/configguimoto.h new file mode 100644 index 000000000..54afcb759 --- /dev/null +++ b/kitchensync/src/configguimoto.h @@ -0,0 +1,43 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2007 Anirudh Ramesh <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#ifndef CONFIGGUIMOTO_H +#define CONFIGGUIMOTO_H + +#include "configgui.h" + +class KLineEdit; + +class ConfigGuiMoto : public ConfigGui +{ + public: + ConfigGuiMoto( const QSync::Member &, QWidget *parent ); + + void load( const QString &xml ); + QString save() const; + + private: + void initGUI(); + + KLineEdit *mDeviceString; +}; + +#endif diff --git a/kitchensync/src/configguiopie.cpp b/kitchensync/src/configguiopie.cpp new file mode 100644 index 000000000..6d0a5d80c --- /dev/null +++ b/kitchensync/src/configguiopie.cpp @@ -0,0 +1,135 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2006 Tobias Koenig <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#include "configguiopie.h" + +#include <klocale.h> + +#include <qcombobox.h> +#include <qdom.h> +#include <qlabel.h> +#include <qlayout.h> +#include <qlineedit.h> +#include <qspinbox.h> + +ConfigGuiOpie::ConfigGuiOpie( const QSync::Member &member, QWidget *parent ) + : ConfigGui( member, parent ) +{ + QGridLayout *layout = new QGridLayout( topLayout() ); + + QLabel *label = new QLabel( i18n("Device IP:"), this ); + layout->addWidget( label, 0, 0 ); + + mDeviceIP = new QLineEdit( this ); + mDeviceIP->setInputMask( "000.000.000.000" ); + label->setBuddy( mDeviceIP ); + layout->addWidget( mDeviceIP, 0, 1 ); + + label = new QLabel( i18n("Device Type:"), this ); + layout->addWidget( label, 1, 0 ); + + mDeviceType = new QComboBox( this ); + label->setBuddy( mDeviceType ); + layout->addWidget( mDeviceType, 1, 1 ); + + label = new QLabel( i18n("Username:"), this ); + layout->addWidget( label, 2, 0 ); + + mUserName = new QLineEdit( this ); + label->setBuddy( mUserName ); + layout->addWidget( mUserName, 2, 1 ); + + label = new QLabel( i18n("Password:"), this ); + layout->addWidget( label, 3, 0 ); + + mPassword = new QLineEdit( this ); + mPassword->setEchoMode( QLineEdit::Password ); + label->setBuddy( mPassword ); + layout->addWidget( mPassword, 3, 1 ); + + label = new QLabel( i18n("Protocol:"), this ); + layout->addWidget( label, 4, 0 ); + + mConnectionType = new QComboBox( this ); + label->setBuddy( mConnectionType ); + layout->addWidget( mConnectionType, 4, 1 ); + + label = new QLabel( i18n("Port:"), this ); + layout->addWidget( label, 5, 0 ); + + mPort = new QSpinBox( this ); + mPort->setRange( 0, 65335 ); + label->setBuddy( mPort ); + layout->addWidget( mPort, 5, 1 ); + + mDeviceType->insertItem( i18n("Opie/OpenZaurus") ); + mDeviceType->insertItem( i18n("Qtopia2") ); + + mConnectionType->insertItem( i18n("SCP") ); + mConnectionType->insertItem( i18n("FTP") ); + + topLayout()->addStretch( 1 ); +} + +void ConfigGuiOpie::load( const QString &xml ) +{ + QDomDocument doc; + doc.setContent( xml ); + QDomElement docElement = doc.documentElement(); + QDomNode n; + for( n = docElement.firstChild(); !n.isNull(); n = n.nextSibling() ) { + QDomElement e = n.toElement(); + if ( e.tagName() == "username" ) { + mUserName->setText( e.text() ); + } else if ( e.tagName() == "password" ) { + mPassword->setText( e.text() ); + } else if ( e.tagName() == "url" ) { + mDeviceIP->setText( e.text() ); + } else if ( e.tagName() == "port" ) { + mPort->setValue( e.text().toInt() ); + } else if ( e.tagName() == "device" ) { + if ( e.text() == "opie" ) + mDeviceType->setCurrentItem( 0 ); + else + mDeviceType->setCurrentItem( 1 ); + } else if ( e.tagName() == "conntype" ) { + if ( e.text() == "scp" ) + mConnectionType->setCurrentItem( 0 ); + else + mConnectionType->setCurrentItem( 1 ); + } + } +} + +QString ConfigGuiOpie::save() const +{ + QString xml; + xml = "<config>"; + xml += "<username>" + mUserName->text() + "</username>"; + xml += "<password>" + mPassword->text() + "</password>"; + xml += "<url>" + mDeviceIP->text() + "</url>"; + xml += "<device>" + QString( mDeviceType->currentItem() == 0 ? "opie" : "qtopia2" ) + "</device>"; + xml += "<port>" + QString::number( mPort->value() ) + "</port>"; + xml += "<conntype>" + QString( mConnectionType->currentItem() == 0 ? "scp" : "ftp" ) + "</conntype>"; + xml += "</config>"; + + return xml; +} diff --git a/kitchensync/src/configguiopie.h b/kitchensync/src/configguiopie.h new file mode 100644 index 000000000..671526d6d --- /dev/null +++ b/kitchensync/src/configguiopie.h @@ -0,0 +1,47 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2006 Tobias Koenig <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ +#ifndef CONFIGGUIOPIE_H +#define CONFIGGUIOPIE_H + +#include "configgui.h" + +class QComboBox; +class QLineEdit; +class QSpinBox; + +class ConfigGuiOpie : public ConfigGui +{ + public: + ConfigGuiOpie( const QSync::Member &, QWidget *parent ); + + void load( const QString &xml ); + QString save() const; + + private: + QLineEdit *mDeviceIP; + QComboBox *mDeviceType; + QLineEdit *mUserName; + QLineEdit *mPassword; + QComboBox *mConnectionType; + QSpinBox *mPort; +}; + +#endif diff --git a/kitchensync/src/configguipalm.cpp b/kitchensync/src/configguipalm.cpp new file mode 100644 index 000000000..de18e92c2 --- /dev/null +++ b/kitchensync/src/configguipalm.cpp @@ -0,0 +1,200 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2005 Tobias Koenig <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#include <kcombobox.h> +#include <kdialog.h> +#include <klineedit.h> +#include <klocale.h> + +#include <qbuttongroup.h> +#include <qcheckbox.h> +#include <qdom.h> +#include <qlabel.h> +#include <qlayout.h> +#include <qradiobutton.h> +#include <qspinbox.h> +#include <qtabwidget.h> + +#include "configguipalm.h" + +ConfigGuiPalm::ConfigGuiPalm( const QSync::Member &member, QWidget *parent ) + : ConfigGui( member, parent ) +{ + initGUI(); + + mDevice->insertItem( "/dev/pilot" ); + mDevice->insertItem( "/dev/ttyUSB0" ); + mDevice->insertItem( "/dev/ttyUSB1" ); + mDevice->insertItem( "/dev/ttyUSB2" ); + mDevice->insertItem( "/dev/ttyUSB3" ); + + mSpeed->insertItem( "9600" ); + mSpeed->insertItem( "19200" ); + mSpeed->insertItem( "38400" ); + mSpeed->insertItem( "57600" ); + mSpeed->insertItem( "115200" ); +} + +void ConfigGuiPalm::load( const QString &xml ) +{ + QDomDocument doc; + doc.setContent( xml ); + QDomElement docElement = doc.documentElement(); + QDomNode node; + for( node = docElement.firstChild(); !node.isNull(); node = node.nextSibling() ) { + QDomElement element = node.toElement(); + if ( element.tagName() == "sockaddr" ) { + mDevice->setCurrentText( element.text() ); + } else if ( element.tagName() == "speed" ) { + mSpeed->setCurrentText( element.text() ); + } else if ( element.tagName() == "timeout" ) { + mTimeout->setValue( element.text().toInt() ); + } else if ( element.tagName() == "username" ) { + mUserName->setText( element.text() ); + } else if ( element.tagName() == "mismatch" ) { + switch ( element.text().toInt() ) { + case 0: + mSyncAlways->setChecked( true ); + break; + case 2: + mSyncAbort->setChecked( true ); + break; + case 1: + default: + mSyncAsk->setChecked( true ); + break; + } + } else if ( element.tagName() == "popup" ) { + mPopup->setChecked( element.text() == "1" ); + } + } +} + +QString ConfigGuiPalm::save() const +{ + QString config = "<config>"; + + config += "<sockaddr>" + mDevice->currentText() + "</sockaddr>"; + config += "<username>" + mUserName->text() + "</username>"; + config += "<timeout>" + QString::number( mTimeout->value() ) + "</timeout>"; + config += "<type>0</type>"; + config += "<speed>" + mSpeed->currentText() + "</speed>"; + config += "<id>0</id>"; + config += "<codepage>cp1252</codepage>"; + config += "<popup>" + QString( mPopup->isChecked() ? "1" : "0" ) + "</popup>"; + + QString popup; + if ( mSyncAlways->isChecked() ) + popup = "0"; + else if ( mSyncAsk->isChecked() ) + popup = "1"; + else if ( mSyncAbort->isChecked() ) + popup = "2"; + + config += "<mismatch>" + popup + "</mismatch>"; + + config += "</config>"; + + return config; +} + +void ConfigGuiPalm::initGUI() +{ + QFont boldFont = font(); + boldFont.setBold( true ); + + QTabWidget *tabWidget = new QTabWidget( this ); + + QWidget *connectionWidget = new QWidget( tabWidget ); + QVBoxLayout *connectionLayout = new QVBoxLayout( connectionWidget, + KDialog::marginHint(), KDialog::spacingHint() ); + + QLabel *label = new QLabel( i18n( "Connection" ), connectionWidget ); + label->setFont( boldFont ); + connectionLayout->addWidget( label ); + + QGridLayout *gridLayout = new QGridLayout( connectionLayout, 3, 2, KDialog::spacingHint() ); + gridLayout->setMargin( KDialog::marginHint() ); + + gridLayout->addWidget( new QLabel( i18n( "Port:" ), connectionWidget ), 0, 0 ); + gridLayout->addWidget( new QLabel( i18n( "Speed:" ), connectionWidget ), 1, 0 ); + gridLayout->addWidget( new QLabel( i18n( "Timeout:" ), connectionWidget ), 2, 0 ); + + mDevice = new KComboBox( true, connectionWidget ); + mSpeed = new KComboBox( connectionWidget ); + mTimeout = new QSpinBox( 1, 60, 1, connectionWidget ); + mTimeout->setSuffix( i18n( " sec" ) ); + + gridLayout->addWidget( mDevice, 0, 1 ); + gridLayout->addWidget( mSpeed, 1, 1 ); + gridLayout->addWidget( mTimeout, 2, 1 ); + gridLayout->setColStretch( 1, 1 ); + + label = new QLabel( i18n( "User" ), connectionWidget ); + label->setFont( boldFont ); + connectionLayout->addWidget( label ); + + gridLayout = new QGridLayout( connectionLayout, 1, 2, KDialog::spacingHint() ); + gridLayout->setMargin( KDialog::marginHint() ); + + gridLayout->addWidget( new QLabel( i18n( "Username:" ), connectionWidget ), 0, 0 ); + + mUserName = new KLineEdit( connectionWidget ); + gridLayout->addWidget( mUserName, 0, 1 ); + + label = new QLabel( i18n( "What to do if Username does not match" ), connectionWidget ); + label->setFont( boldFont ); + connectionLayout->addWidget( label ); + + gridLayout = new QGridLayout( connectionLayout, 1, 2, KDialog::spacingHint() ); + gridLayout->setMargin( KDialog::marginHint() ); + + QButtonGroup *buttonGroup = new QButtonGroup( 1, Qt::Horizontal, connectionWidget ); + buttonGroup->setExclusive( true ); + buttonGroup->setFrameStyle( QFrame::NoFrame ); + mSyncAlways = new QRadioButton( i18n( "Sync Anyway" ), buttonGroup ); + mSyncAsk = new QRadioButton( i18n( "Ask What To Do" ), buttonGroup ); + mSyncAbort = new QRadioButton( i18n( "Abort Sync" ), buttonGroup ); + + gridLayout->addMultiCellWidget( buttonGroup, 0, 0, 0, 1 ); + + connectionLayout->addStretch( 1 ); + tabWidget->addTab( connectionWidget, i18n( "Connection" ) ); + + QWidget *optionWidget = new QWidget( tabWidget ); + QVBoxLayout *optionLayout = new QVBoxLayout( optionWidget, + KDialog::marginHint(), KDialog::spacingHint() ); + + label = new QLabel( i18n( "Hotsync Notification" ), optionWidget ); + label->setFont( boldFont ); + optionLayout->addWidget( label ); + + gridLayout = new QGridLayout( optionLayout, 1, 2, KDialog::spacingHint() ); + gridLayout->setMargin( KDialog::marginHint() ); + + mPopup = new QCheckBox( i18n( "Popup when interaction is required" ), optionWidget ); + gridLayout->addMultiCellWidget( mPopup, 0, 0, 0, 1 ); + + optionLayout->addStretch( 1 ); + tabWidget->addTab( optionWidget, i18n( "Options" ) ); + + topLayout()->addWidget( tabWidget ); +} diff --git a/kitchensync/src/configguipalm.h b/kitchensync/src/configguipalm.h new file mode 100644 index 000000000..212ef61a6 --- /dev/null +++ b/kitchensync/src/configguipalm.h @@ -0,0 +1,59 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2005 Tobias Koenig <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#ifndef CONFIGGUIPALM_H +#define CONFIGGUIPALM_H + +#include "configgui.h" + +class KComboBox; +class KLineEdit; +class QCheckBox; +class QRadioButton; +class QSpinBox; + +class ConfigGuiPalm : public ConfigGui +{ + public: + ConfigGuiPalm( const QSync::Member &, QWidget *parent ); + + void load( const QString &xml ); + QString save() const; + + private: + void initGUI(); + + KComboBox *mDevice; + KComboBox *mSpeed; + QSpinBox *mTimeout; + + KLineEdit *mUserName; + + QRadioButton *mSyncAlways; + QRadioButton *mSyncAsk; + QRadioButton *mSyncAbort; + + QCheckBox *mPopup; + KComboBox *mVerbosity; + KComboBox *mCodePage; +}; + +#endif diff --git a/kitchensync/src/configguisunbird.cpp b/kitchensync/src/configguisunbird.cpp new file mode 100644 index 000000000..7b09cd50c --- /dev/null +++ b/kitchensync/src/configguisunbird.cpp @@ -0,0 +1,367 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2007 Tobias Koenig <[email protected]> + Copyright (c) 2007 Anirudh Ramesh <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#include "configguisunbird.h" + +#include <qdom.h> +#include <qtabwidget.h> +#include <qlabel.h> +#include <qlayout.h> +#include <qbuttongroup.h> +#include <qcheckbox.h> +#include <qsizepolicy.h> +#include <qptrlist.h> +#include <qspinbox.h> +#include <qwidget.h> + +#include <kurlrequester.h> +#include <klineedit.h> +#include <kpushbutton.h> +#include <kdialog.h> +#include <klocale.h> +#include <kfile.h> + +ConfigGuiSunbird::ConfigGuiSunbird( const QSync::Member &member, QWidget *parent ) + : ConfigGui( member, parent ) +{ + QTabWidget *tabWidget = new QTabWidget( this ); + topLayout()->addWidget( tabWidget ); + + mLocalWidget = new QWidget( tabWidget ); + mLocalLayout = new QVBoxLayout( mLocalWidget, KDialog::spacingHint() ); + + mWebdavWidget = new QWidget( tabWidget ); + mWebdavLayout = new QVBoxLayout( mWebdavWidget, KDialog::spacingHint() ); + + tabWidget->addTab( mLocalWidget, i18n( "Local Calendars" ) ); + tabWidget->addTab( mWebdavWidget, i18n( "WebDAV Calendars" ) ); + + KPushButton *mLocalAddButton = new KPushButton( mLocalWidget ); + mLocalAddButton->setText( i18n( "Add new calendar" ) ); + mLocalAddButton->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) ); + mLocalLayout->addWidget( mLocalAddButton ); + connect( mLocalAddButton, SIGNAL( clicked() ), + this, SLOT( addLocalCalendar() ) ); + + KPushButton *mWebdavAddButton = new KPushButton( mWebdavWidget ); + mWebdavAddButton->setText( i18n( "Add new calendar" ) ); + mWebdavAddButton->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) ); + mWebdavLayout->addWidget( mWebdavAddButton ); + connect( mWebdavAddButton, SIGNAL( clicked() ), + this, SLOT( addWebdavCalendar() ) ); + + mLocalSpacer = new QSpacerItem( 20, 40, QSizePolicy::Expanding ); + mLocalLayout->addItem( mLocalSpacer ); + mWebdavSpacer = new QSpacerItem( 20, 40, QSizePolicy::Expanding ); + mWebdavLayout->addItem( mWebdavSpacer ); +} + +void ConfigGuiSunbird::load( const QString &xml ) +{ + QString path; + QString url; + QString username; + QString password; + QString defaultcal; + QString days; + + QDomDocument doc; + doc.setContent( xml ); + QDomElement docElement = doc.documentElement(); + QDomNode node; + for( node = docElement.firstChild(); !node.isNull(); node = node.nextSibling() ) { + QDomElement element = node.toElement(); + if ( element.tagName() == "file" ) { + QDomAttr pathAttr = element.attributeNode( "path" ); + path = pathAttr.value(); + QDomAttr defaultAttr = element.attributeNode( "default" ); + defaultcal = defaultAttr.value(); + QDomAttr daysAttr = element.attributeNode( "deletedaysold" ); + days = daysAttr.value(); + + LocalCalendar *cal = new LocalCalendar( path, defaultcal, days, mLocalWidget ); + mLocalLayout->removeItem( mLocalSpacer ); + cal->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + mLocalLayout->addWidget( cal ); + mLocalLayout->addItem( mLocalSpacer ); + mLocalList.append( cal ); + + connect( cal, SIGNAL( deleteRequest( LocalCalendar* ) ), SLOT( delLocalCalendar( LocalCalendar* ) ) ); + cal->show(); + } else if ( element.tagName() == "webdav" ) { + QDomAttr urlAttr = element.attributeNode( "url" ); + url = urlAttr.value(); + QDomAttr unameAttr = element.attributeNode( "username" ); + username = unameAttr.value(); + QDomAttr pwordAttr = element.attributeNode( "password" ); + password = pwordAttr.value(); + QDomAttr defaultAttr = element.attributeNode( "default" ); + defaultcal = defaultAttr.value(); + QDomAttr daysAttr = element.attributeNode( "deletedaysold" ); + days = daysAttr.value(); + + WebdavCalendar *cal = new WebdavCalendar( username, password, + url, defaultcal, days, mWebdavWidget ); + mWebdavLayout->removeItem( mWebdavSpacer ); + cal->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + mWebdavLayout->addWidget( cal ); + mWebdavLayout->addItem( mWebdavSpacer ); + mWebdavList.append( cal ); + + connect( cal, SIGNAL( deleteRequest( WebdavCalendar* ) ), SLOT( delWebdavCalendar( WebdavCalendar* ) ) ); + cal->show(); + } + } +} + +QString ConfigGuiSunbird::save() const +{ + QString config = "<config>\n"; + + for ( uint i = 0; i < mLocalList.count(); ++i ) { + LocalCalendar *lcal = mLocalList[ i ]; + config += QString( "<file " ); + config += QString( "path=\"%1\" " ).arg( lcal->mPathRequester->url() ); + + if ( lcal->mDaysCheckBox->isChecked() ) { + config += QString( "deletedaysold=\"%1\" " ).arg( lcal->mDaysSpinBox->value() ); + } + if ( lcal->mDefaultCheckBox->isChecked() ) { + config += QString( "default=\"1\" " ); + } + config += QString( "/>\n" ); + } + + for ( uint i = 0; i < mWebdavList.count(); ++i ) { + WebdavCalendar *wcal = mWebdavList[ i ]; + config += QString( "<webdav " ); + config += QString( "username=\"%1\" " ).arg( wcal->mUsername->text() ); + config += QString( "password=\"%1\" " ).arg( wcal->mPassword->text() ); + config += QString( "url=\"%1\" " ).arg( wcal->mUrl->text() ); + + if ( wcal->mDaysCheckBox->isChecked() ) { + config += QString( "deletedaysold=\"%1\" " ).arg( wcal->mDaysSpinBox->value() ); + } + if ( wcal->mDefaultCheckBox->isChecked() ) { + config += QString( "default=\"1\" " ); + } + config += QString( "/>\n" ); + } + config += "</config>"; + + return config; +} + +void ConfigGuiSunbird::addLocalCalendar() +{ + LocalCalendar *cal = new LocalCalendar( mLocalWidget ); + mLocalLayout->removeItem( mLocalSpacer ); + cal->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + mLocalLayout->addWidget( cal ); + mLocalLayout->addItem( mLocalSpacer ); + mLocalList.append( cal ); + + connect( cal, SIGNAL( deleteRequest( LocalCalendar* ) ), SLOT( delLocalCalendar( LocalCalendar* ) ) ); + cal->show(); +} + +void ConfigGuiSunbird::delLocalCalendar( LocalCalendar *calendar ) +{ + mLocalList.remove( calendar ); + calendar->deleteLater(); +} + +void ConfigGuiSunbird::addWebdavCalendar() +{ + WebdavCalendar *cal = new WebdavCalendar( mWebdavWidget ); + mWebdavLayout->removeItem( mWebdavSpacer ); + cal->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + mWebdavLayout->addWidget( cal ); + mWebdavLayout->addItem( mWebdavSpacer ); + mWebdavList.append( cal ); + + connect( cal, SIGNAL( deleteRequest( WebdavCalendar* ) ), SLOT( delWebdavCalendar( WebdavCalendar* ) ) ); + cal->show(); +} + +void ConfigGuiSunbird::delWebdavCalendar( WebdavCalendar *calendar ) +{ + mWebdavList.remove( calendar ); + calendar->deleteLater(); +} + +LocalCalendar::LocalCalendar( QWidget *parent ) + : QWidget( parent ) +{ + initGui(); +} + +LocalCalendar::LocalCalendar( const QString &path, const QString &defaultcal, const QString &days, QWidget *parent ) + : QWidget( parent ) +{ + initGui(); + + mPathRequester->setURL( path ); + mDefaultCheckBox->setChecked( defaultcal.toInt() == 1 ); + + if ( !days.isEmpty() ) { + mDaysCheckBox->setChecked( true ); + mDaysSpinBox->setEnabled( true ); + mDaysSpinBox->setValue( days.toInt() ); + } +} + +void LocalCalendar::initGui() +{ + QBoxLayout *bottomLayout = new QHBoxLayout(); + + mDaysCheckBox = new QCheckBox( this ); + mDaysCheckBox->setText( i18n( "Sync only events newer than" ) ); + + mDaysSpinBox = new QSpinBox( this ); + mDaysSpinBox->setDisabled( true ); + mDaysSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) ); + + connect( mDaysCheckBox, SIGNAL( toggled( bool ) ), + this, SLOT( toggleDays( bool ) ) ); + + bottomLayout->addWidget( mDaysCheckBox ); + bottomLayout->addWidget( mDaysSpinBox ); + bottomLayout->addWidget( new QLabel( i18n( "day(s)" ), this ) ); + + QGridLayout *localLayout = new QGridLayout( this ); + + mPathRequester = new KURLRequester( this ); + + KPushButton *removeButton = new KPushButton( this ); + removeButton->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) ); + removeButton->setText( i18n( "Remove" ) ); + connect( removeButton, SIGNAL( clicked() ), + this, SLOT( deleteWidget() ) ); + + mDefaultCheckBox = new QCheckBox( this ); + mDefaultCheckBox->setText( i18n( "Set as Default" ) ); + + localLayout->addItem( new QSpacerItem( 40, 20, QSizePolicy::Expanding ), 0, 0 ); + localLayout->addWidget( new QLabel( i18n( "Location:" ), this ), 1, 0 ); + localLayout->addWidget( mPathRequester, 1, 1 ); + localLayout->addItem( new QSpacerItem( 40, 20, QSizePolicy::Fixed ), 1, 2 ); + localLayout->addWidget( removeButton, 1, 3 ); + localLayout->addMultiCellLayout( bottomLayout, 2, 2, 0, 2 ); + localLayout->addWidget( mDefaultCheckBox, 2, 3 ); +} + +void LocalCalendar::deleteWidget() +{ + emit deleteRequest( this ); +} + +WebdavCalendar::WebdavCalendar( QWidget *parent ) + : QWidget( parent ) +{ + initGui(); +}; + +WebdavCalendar::WebdavCalendar( const QString &username, const QString &password, const QString &url, + const QString &defaultcal, const QString &days, QWidget *parent ) + : QWidget( parent ) +{ + initGui(); + + mUsername->setText( username ); + mPassword->setText( password ); + mUrl->setText( url ); + mDefaultCheckBox->setChecked( defaultcal.toInt() == 1 ); + + if ( !days.isEmpty() ) { + mDaysCheckBox->setChecked( true ); + mDaysSpinBox->setEnabled( true ); + mDaysSpinBox->setValue( days.toInt() ); + } +} + +void WebdavCalendar::initGui() +{ + QBoxLayout *bottomLayout = new QHBoxLayout(); + + mDaysCheckBox = new QCheckBox( this ); + mDaysCheckBox->setText( i18n( "Sync only events newer than" ) ); + + mDaysSpinBox = new QSpinBox( this ); + mDaysSpinBox->setDisabled( true ); + mDaysSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) ); + + connect( mDaysCheckBox, SIGNAL( toggled( bool ) ), + this, SLOT( toggleDays( bool ) ) ); + + bottomLayout->addWidget( mDaysCheckBox ); + bottomLayout->addWidget( mDaysSpinBox ); + bottomLayout->addWidget( new QLabel( i18n( "day(s)" ), this ) ); + + QGridLayout *webdavLayout = new QGridLayout(); + + mUrl = new KLineEdit( this ); + mUsername = new KLineEdit( this ); + mPassword = new KLineEdit( this ); + mPassword->setEchoMode( KLineEdit::Password ); + + KPushButton *removeButton = new KPushButton( this ); + removeButton->setText( i18n( "Remove" ) ); + connect( removeButton, SIGNAL( clicked() ), + this, SLOT( deleteWidget() ) ); + + mDefaultCheckBox = new QCheckBox( this ); + mDefaultCheckBox->setText( i18n( "Set as Default" ) ); + + webdavLayout->addWidget( new QLabel( i18n( "Location:" ), this ), 0, 0 ); + webdavLayout->addWidget( mUrl, 0, 1 ); + webdavLayout->addItem( new QSpacerItem( 40, 20, QSizePolicy::Fixed ), 0, 2 ); + webdavLayout->addWidget( removeButton, 0, 3 ); + webdavLayout->addMultiCellLayout( bottomLayout, 1, 1, 0, 1 ); + webdavLayout->addWidget( mDefaultCheckBox, 1, 3 ); + + QGridLayout *mainLayout = new QGridLayout( this ); + mainLayout->addItem( new QSpacerItem( 40, 20, QSizePolicy::Fixed ), 0, 0 ); + mainLayout->addMultiCellLayout( webdavLayout, 1, 1, 0, 4 ); + mainLayout->addWidget( new QLabel( i18n( "Username:" ), this ), 2, 0 ); + mainLayout->addWidget( mUsername, 2, 1 ); + mainLayout->addItem( new QSpacerItem( 40, 20, QSizePolicy::Fixed ), 2, 2 ); + mainLayout->addWidget( new QLabel( i18n( "Password:" ), this ), 2, 3 ); + mainLayout->addWidget( mPassword, 2, 4 ); +} + +void WebdavCalendar::deleteWidget() +{ + emit deleteRequest( this ); +} + +void LocalCalendar::toggleDays( bool state ) +{ + mDaysSpinBox->setEnabled( state ); +} + +void WebdavCalendar::toggleDays( bool state ) +{ + mDaysSpinBox->setEnabled( state ); +} + +#include "configguisunbird.moc" diff --git a/kitchensync/src/configguisunbird.h b/kitchensync/src/configguisunbird.h new file mode 100644 index 000000000..df69417f7 --- /dev/null +++ b/kitchensync/src/configguisunbird.h @@ -0,0 +1,130 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2007 Tobias Koenig <[email protected]> + Copyright (c) 2007 Anirudh Ramesh <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#ifndef CONFIGGUISUNBIRD_H +#define CONFIGGUISUNBIRD_H + +#include "configgui.h" + +class QWidget; +class QSpinBox; +class QCheckBox; +class QVBoxLayout; +class QSpacerItem; +class QSignalMapper; + +class KURLRequester; +class KPushButton; +class KLineEdit; + +class LocalCalendar : public QWidget +{ + Q_OBJECT + + public: + LocalCalendar( QWidget *parent = 0 ); + LocalCalendar( const QString &path, + const QString &defaultcal, + const QString &days, QWidget *parent = 0 ); + + KURLRequester *mPathRequester; + QCheckBox *mDaysCheckBox; + QSpinBox *mDaysSpinBox; + QCheckBox *mDefaultCheckBox; + + signals: + void deleteRequest( LocalCalendar* ); + + private slots: + void deleteWidget(); + void toggleDays( bool days ); + + private: + void initGui(); +}; + +class WebdavCalendar : public QWidget +{ + Q_OBJECT + + public: + WebdavCalendar( QWidget *parent = 0 ); + WebdavCalendar( const QString &username, + const QString &password, + const QString &url, + const QString &defaultcal, + const QString &days, QWidget *parent = 0 ); + + KLineEdit *mUrl; + QCheckBox *mDaysCheckBox; + QSpinBox *mDaysSpinBox; + QCheckBox *mDefaultCheckBox; + KLineEdit *mUsername; + KLineEdit *mPassword; + + signals: + void deleteRequest( WebdavCalendar* ); + + private slots: + void deleteWidget(); + void toggleDays( bool state ); + + private: + void initGui(); +}; + +class ConfigGuiSunbird : public ConfigGui +{ + Q_OBJECT + + public: + ConfigGuiSunbird( const QSync::Member &, QWidget *parent ); + + void load( const QString &xml ); + + QString save() const; + + public slots: + void addLocalCalendar(); + void addWebdavCalendar(); + + void delLocalCalendar( LocalCalendar* ); + void delWebdavCalendar( WebdavCalendar* ); + + private: + QValueList<LocalCalendar*> mLocalList; + QValueList<WebdavCalendar*> mWebdavList; + + QWidget *mLocalWidget; + QWidget *mWebdavWidget; + + QVBoxLayout *mLocalLayout; + QVBoxLayout *mWebdavLayout; + + KPushButton *mLocalAddButton; + KPushButton *mWebdavAddButton; + + QSpacerItem *mLocalSpacer; + QSpacerItem *mWebdavSpacer; +}; + +#endif diff --git a/kitchensync/src/configguisynce.cpp b/kitchensync/src/configguisynce.cpp new file mode 100644 index 000000000..43b509a46 --- /dev/null +++ b/kitchensync/src/configguisynce.cpp @@ -0,0 +1,93 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2007 Anirudh Ramesh <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#include "configguisynce.h" + +#include <qdom.h> +#include <qlabel.h> +#include <qlayout.h> +#include <qcheckbox.h> + +#include <klineedit.h> +#include <kdialog.h> +#include <klocale.h> + +ConfigGuiSynce::ConfigGuiSynce( const QSync::Member &member, QWidget *parent ) + : ConfigGui( member, parent ) +{ + initGUI(); +} + +void ConfigGuiSynce::load( const QString &xml ) +{ + QDomDocument doc; + doc.setContent( xml ); + QDomElement docElement = doc.documentElement(); + QDomNode node; + for( node = docElement.firstChild(); !node.isNull(); node = node.nextSibling() ) { + QDomElement element = node.toElement(); + if ( element.tagName() == "contact" ) { + mContacts->setChecked( element.text().toInt() == 1 ); + } else if ( element.tagName() == "todos" ) { + mTodos->setChecked( element.text().toInt() == 1 ); + } else if ( element.tagName() == "calendar" ) { + mCalendar->setChecked( element.text().toInt() == 1 ); + } else if ( element.tagName() == "file" ) { + mFile->setText( element.text() ); + } + } +} + +QString ConfigGuiSynce::save() const +{ + QString config = "<config>\n"; + + config += QString( "<contact>%1</contact>\n" ).arg( mContacts->isChecked() ? "1" : "0" ); + config += QString( "<todos>%1</todos>\n" ).arg( mTodos->isChecked() ? "1" : "0" ); + config += QString( "<calendar>%1</calendar>\n" ).arg( mCalendar->isChecked() ? "1" : "0" ); + config += QString( "<file>%1</file>\n" ).arg( mFile->text() ); + + config += "</config>"; + + return config; +} + +void ConfigGuiSynce::initGUI() +{ + QGridLayout *layout = new QGridLayout( topLayout(), 12, 2, KDialog::spacingHint() ); + layout->setMargin( KDialog::marginHint() ); + + mContacts = new QCheckBox( this ); + mContacts->setText( "Sync Contacts" ); + layout->addMultiCellWidget( mContacts, 0, 0, 0, 1 ); + + mTodos = new QCheckBox( this ); + mTodos->setText( "Sync \'Todo\' items" ); + layout->addMultiCellWidget( mTodos, 1, 1, 0, 1 ); + + mCalendar = new QCheckBox( this ); + mCalendar->setText( "Sync Calendar" ); + layout->addMultiCellWidget( mCalendar, 2, 2, 0, 1 ); + + layout->addWidget( new QLabel( i18n( "File:" ), this ), 3, 0 ); + mFile = new KLineEdit( this ); + layout->addWidget( mFile, 3, 1 ); +} diff --git a/kitchensync/src/configguisynce.h b/kitchensync/src/configguisynce.h new file mode 100644 index 000000000..07835572e --- /dev/null +++ b/kitchensync/src/configguisynce.h @@ -0,0 +1,49 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2007 Anirudh Ramesh <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#ifndef CONFIGGUISYNCE_H +#define CONFIGGUISYNCE_H + +#include "configgui.h" + +class QCheckBox; + +class KLineEdit; + +class ConfigGuiSynce : public ConfigGui +{ + public: + ConfigGuiSynce( const QSync::Member &, QWidget *parent ); + + void load( const QString &xml ); + + QString save() const; + + private: + void initGUI(); + + QCheckBox *mContacts; + QCheckBox *mTodos; + QCheckBox *mCalendar; + KLineEdit *mFile; +}; + +#endif diff --git a/kitchensync/src/configguisyncmlhttp.cpp b/kitchensync/src/configguisyncmlhttp.cpp new file mode 100644 index 000000000..63a073c90 --- /dev/null +++ b/kitchensync/src/configguisyncmlhttp.cpp @@ -0,0 +1,227 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2005 Cornelius Schumacher <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#include "configguisyncmlhttp.h" + +#include <kcombobox.h> +#include <kdialog.h> +#include <klineedit.h> +#include <klocale.h> +#include <kurlrequester.h> + +#include <qcheckbox.h> +#include <qdom.h> +#include <qlabel.h> +#include <qlayout.h> +#include <qspinbox.h> +#include <qtabwidget.h> +#include <qvbox.h> + +ConfigGuiSyncmlHttp::ConfigGuiSyncmlHttp( const QSync::Member &member, QWidget *parent ) + : ConfigGui( member, parent ), mUrl( 0 ), mPort( 0 ) +{ + + QTabWidget *tabWidget = new QTabWidget( this ); + topLayout()->addWidget( tabWidget ); + + // Connection + QWidget *connectionWidget = new QWidget( tabWidget ); + QVBoxLayout *connectionLayout = new QVBoxLayout( connectionWidget, + KDialog::marginHint(), KDialog::spacingHint() ); + + tabWidget->addTab( connectionWidget, i18n( "Connection" ) ); + + mGridLayout = new QGridLayout( connectionLayout ); + + QLabel *label = new QLabel( i18n("Port:"), connectionWidget ); + mGridLayout->addWidget( label, 0, 0 ); + + mPort = new QSpinBox( connectionWidget ); + mPort->setMinValue( 1 ); + mPort->setMaxValue( 65536 ); + mGridLayout->addWidget( mPort, 0, 1 ); + + // Database + QWidget *databaseWidget = new QWidget( tabWidget ); + QVBoxLayout *databaseLayout = new QVBoxLayout( databaseWidget, + KDialog::marginHint(), KDialog::spacingHint() ); + + tabWidget->addTab( databaseWidget, i18n( "Databases" ) ); + + mGridLayout = new QGridLayout( databaseLayout ); + addLineEdit( databaseWidget, i18n("Contact Database:"), &mContactDb, 0 ); + addLineEdit( databaseWidget, i18n("Calendar Database:"), &mCalendarDb, 1 ); + addLineEdit( databaseWidget, i18n("Note Database:"), &mNoteDb, 2 ); + + mContactDb->insertItem( "addressbook" ); + mContactDb->insertItem( "contacts" ); + + mCalendarDb->insertItem( "agenda" ); + mCalendarDb->insertItem( "calendar" ); + + mNoteDb->insertItem( "notes" ); + + + // Options + QWidget *optionWidget = new QWidget( tabWidget ); + QVBoxLayout *optionLayout = new QVBoxLayout( optionWidget, + KDialog::marginHint(), KDialog::spacingHint() ); + + tabWidget->addTab( optionWidget, i18n( "Options" ) ); + + mGridLayout = new QGridLayout( optionLayout ); + + label = new QLabel( i18n("User name:"), optionWidget ); + mGridLayout->addWidget( label, 0, 0 ); + + mUsername = new KLineEdit( optionWidget ); + mGridLayout->addWidget( mUsername, 0, 1 ); + + label = new QLabel( i18n("Password:"), optionWidget ); + mGridLayout->addWidget( label, 1, 0 ); + + mPassword = new KLineEdit( optionWidget ); + mPassword->setEchoMode( QLineEdit::Password ); + mGridLayout->addWidget( mPassword, 1, 1 ); + + + mUseStringTable = new QCheckBox( i18n("Use String Table"), optionWidget ); + mGridLayout->addMultiCellWidget( mUseStringTable, 2, 2, 0, 1 ); + + mOnlyReplace = new QCheckBox( i18n("Only Replace Entries"), optionWidget ); + mGridLayout->addMultiCellWidget( mOnlyReplace, 3, 3, 0, 1 ); + + // Url + label = new QLabel( i18n("URL:"), optionWidget ); + mGridLayout->addWidget( label, 4, 0 ); + + mUrl = new KLineEdit( optionWidget ); + mGridLayout->addWidget( mUrl, 4, 1 ); + + // recvLimit + label = new QLabel( i18n("Receive Limit:"), optionWidget ); + mGridLayout->addWidget( label, 5, 0 ); + + mRecvLimit = new QSpinBox( optionWidget ); + mRecvLimit->setMinValue( 1 ); + mRecvLimit->setMaxValue( 65536 ); + mGridLayout->addWidget( mRecvLimit, 5, 1 ); + + // maxObjSize + label = new QLabel( i18n("Maximum Object Size"), optionWidget ); + mGridLayout->addWidget( label, 6, 0 ); + + mMaxObjSize = new QSpinBox( optionWidget ); + mMaxObjSize->setMinValue( 1 ); + mMaxObjSize->setMaxValue( 65536 ); + mGridLayout->addWidget( mMaxObjSize, 6, 1 ); + + topLayout()->addStretch( 1 ); +} + +void ConfigGuiSyncmlHttp::addLineEdit( QWidget *parent, const QString &text, KComboBox **edit, int row ) +{ + QLabel *label = new QLabel( text, parent); + mGridLayout->addWidget( label, row, 0 ); + + *edit = new KComboBox( true, parent ); + mGridLayout->addWidget( *edit, row, 1 ); +} + +void ConfigGuiSyncmlHttp::load( const QString &xml ) +{ + QDomDocument document; + document.setContent( xml ); + + QDomElement docElement = document.documentElement(); + QDomNode node; + + for ( node = docElement.firstChild(); !node.isNull(); node = node.nextSibling() ) { + QDomElement element = node.toElement(); + if ( element.tagName() == "username" ) { + mUsername->setText( element.text() ); + } else if ( element.tagName() == "password" ) { + mPassword->setText( element.text() ); + } else if ( element.tagName() == "url" ) { + if ( mUrl ) + mUrl->setText( element.text() ); + } else if ( element.tagName() == "port" ) { + if ( mPort ) + mPort->setValue( element.text().toInt() ); + } else if ( element.tagName() == "recvLimit" ) { + if ( mRecvLimit ) + mRecvLimit->setValue( element.text().toInt() ); + } else if ( element.tagName() == "maxObjSize" ) { + if ( mMaxObjSize ) + mMaxObjSize->setValue( element.text().toInt() ); + } else if ( element.tagName() == "usestringtable" ) { + mUseStringTable->setChecked( element.text() == "1" ); + } else if ( element.tagName() == "onlyreplace" ) { + mOnlyReplace->setChecked( element.text() == "1" ); + } else if ( element.tagName() == "contact_db" ) { + mContactDb->setCurrentText( element.text() ); + } else if ( element.tagName() == "calendar_db" ) { + mCalendarDb->setCurrentText( element.text() ); + } else if ( element.tagName() == "note_db" ) { + mNoteDb->setCurrentText( element.text() ); + } + } +} + +QString ConfigGuiSyncmlHttp::save() const +{ + QString xml; + xml = "<config>\n"; + xml += "<username>" + mUsername->text() + "</username>\n"; + xml += "<password>" + mPassword->text() + "</password>\n"; + + xml += "<url>" + mUrl->text() + "</url>\n"; + xml += "<port>" + QString::number( mPort->value() ) + "</port>\n"; + // Receive Limit + xml += "<recvLimit>" + QString::number( mRecvLimit->value() ) + "</recvLimit>\n"; + + // Maximal Object Size + xml += "<maxObjSize>" + QString::number( mMaxObjSize->value() ) + "</maxObjSize>\n"; + + xml += "<usestringtable>"; + if ( mUseStringTable->isChecked() ) + xml += "1"; + else + xml += "0"; + xml += "</usestringtable>\n"; + + xml += "<onlyreplace>"; + if ( mOnlyReplace->isChecked() ) + xml += "1"; + else + xml += "0"; + xml += "</onlyreplace>\n"; + + xml += "<contact_db>" + mContactDb->currentText() + "</contact_db>\n"; + xml += "<calendar_db>" + mCalendarDb->currentText() + "</calendar_db>\n"; + xml += "<note_db>" + mNoteDb->currentText() + "</note_db>\n"; + xml += "</config>"; + + return xml; +} + +#include "configguisyncmlhttp.moc" + diff --git a/kitchensync/src/configguisyncmlhttp.h b/kitchensync/src/configguisyncmlhttp.h new file mode 100644 index 000000000..2cbcfc40a --- /dev/null +++ b/kitchensync/src/configguisyncmlhttp.h @@ -0,0 +1,67 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2005 Cornelius Schumacher <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ +#ifndef CONFIGGUISYNCML_H +#define CONFIGGUISYNCML_H + +#include <qdom.h> + +#include "configgui.h" + +class QCheckBox; +class QComboBox; +class QGridLayout; +class QSpinBox; +class KComboBox; +class KLineEdit; + +class ConfigGuiSyncmlHttp : public ConfigGui +{ + + Q_OBJECT + + public: + ConfigGuiSyncmlHttp( const QSync::Member &, QWidget *parent ); + + void load( const QString &xml ); + QString save() const; + + private: + QGridLayout *mGridLayout; + + KLineEdit *mUsername; + KLineEdit *mPassword; + KLineEdit *mUrl; + QSpinBox *mPort; + QCheckBox *mUseStringTable; + QCheckBox *mOnlyReplace; + + QSpinBox *mRecvLimit; + QSpinBox *mMaxObjSize; + + KComboBox *mContactDb; + KComboBox *mCalendarDb; + KComboBox *mNoteDb; + + protected slots: + void addLineEdit( QWidget *parent, const QString &text, KComboBox **edit, int row ); +}; + +#endif diff --git a/kitchensync/src/configguisyncmlobex.cpp b/kitchensync/src/configguisyncmlobex.cpp new file mode 100644 index 000000000..488a0d944 --- /dev/null +++ b/kitchensync/src/configguisyncmlobex.cpp @@ -0,0 +1,320 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2005 Cornelius Schumacher <[email protected]> + Copyright (c) 2006 Daniel Gollub <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#include "configguisyncmlobex.h" + +#include <kcombobox.h> +#include <kdialog.h> +#include <klineedit.h> +#include <klocale.h> +#include <kurlrequester.h> + +#include <qlayout.h> +#include <qcheckbox.h> +#include <qcombobox.h> +#include <qlabel.h> +#include <qdom.h> +#include <qspinbox.h> +#include <qtabwidget.h> +#include <qvbox.h> + +ConfigGuiSyncmlObex::ConfigGuiSyncmlObex( const QSync::Member &member, QWidget *parent ) + : ConfigGui( member, parent ) +{ + QTabWidget *tabWidget = new QTabWidget( this ); + topLayout()->addWidget( tabWidget ); + + // Connection + QVBox *connectionWidget = new QVBox( this ); + connectionWidget->setMargin( KDialog::marginHint() ); + connectionWidget->setSpacing( 5 ); + + tabWidget->addTab( connectionWidget, i18n( "Connection" ) ); + + mConnection = new KComboBox( connectionWidget ); + + connect( mConnection, SIGNAL (activated( int ) ), + this, SLOT( slotConnectionChanged ( int ) ) ); + + mConnectionTypes.append( ConnectionType( 2, i18n( "Bluetooth" ) ) ); + mConnectionTypes.append( ConnectionType( 5, i18n( "USB" ) ) ); + + ConnectionTypeList::ConstIterator it; + for ( it = mConnectionTypes.begin(); it != mConnectionTypes.end(); it++ ) + mConnection->insertItem( (*it).second ); + + mBluetooth = new BluetoothWidget( connectionWidget ); + mBluetooth->hide(); + + mUsb = new UsbWidget( connectionWidget ); + mUsb->hide(); + + connectionWidget->setStretchFactor( mBluetooth, 1 ); + connectionWidget->setStretchFactor( mUsb, 1 ); + + // Databases + QWidget *databaseWidget = new QWidget( tabWidget ); + QVBoxLayout *databaseLayout = new QVBoxLayout( databaseWidget, + KDialog::marginHint(), KDialog::spacingHint() ); + + tabWidget->addTab( databaseWidget, i18n( "Databases" ) ); + + mGridLayout = new QGridLayout( databaseLayout ); + addLineEdit( databaseWidget, i18n("Contact Database:"), &mContactDb, 0 ); + addLineEdit( databaseWidget, i18n("Calendar Database:"), &mCalendarDb, 1 ); + addLineEdit( databaseWidget, i18n("Note Database:"), &mNoteDb, 2 ); + + mContactDb->insertItem( "addressbook" ); + mContactDb->insertItem( "contacts" ); + + mCalendarDb->insertItem( "agenda" ); + mCalendarDb->insertItem( "calendar" ); + + mNoteDb->insertItem( "notes" ); + + // Options + QWidget *optionsWidget = new QWidget( tabWidget ); + QVBoxLayout *optionsLayout = new QVBoxLayout( optionsWidget, + KDialog::marginHint(), KDialog::spacingHint() ); + + tabWidget->addTab( optionsWidget, i18n( "Options" ) ); + + mGridLayout = new QGridLayout( optionsLayout ); + + QLabel *label = new QLabel( i18n("User name:"), optionsWidget ); + mGridLayout->addWidget( label, 0, 0 ); + + mUsername = new KLineEdit( optionsWidget ); + mGridLayout->addWidget( mUsername, 0, 1 ); + + label = new QLabel( i18n("Password:"), optionsWidget ); + mGridLayout->addWidget( label, 1, 0 ); + + mPassword = new KLineEdit( optionsWidget ); + mPassword->setEchoMode( QLineEdit::Password ); + mGridLayout->addWidget( mPassword, 1, 1 ); + + mUseStringTable = new QCheckBox( i18n("Use String Table"), optionsWidget ); + mGridLayout->addMultiCellWidget( mUseStringTable, 2, 2, 0, 1 ); + + mOnlyReplace = new QCheckBox( i18n("Only Replace Entries"), optionsWidget ); + mGridLayout->addMultiCellWidget( mOnlyReplace, 3, 3, 0, 1 ); + + // SynML Version + label = new QLabel( i18n("SyncML Version:"), optionsWidget ); + mGridLayout->addWidget( label, 4, 0 ); + + mSyncmlVersion = new QComboBox( optionsWidget ); + mGridLayout->addWidget( mSyncmlVersion, 4, 1 ); + + mSyncmlVersions.append( SyncmlVersion( 0, i18n( "1.0" ) ) ); + mSyncmlVersions.append( SyncmlVersion( 1, i18n( "1.1" ) ) ); + mSyncmlVersions.append( SyncmlVersion( 2, i18n( "1.2" ) ) ); + + SyncmlVersionList::ConstIterator itVersion; + for ( itVersion = mSyncmlVersions.begin(); itVersion != mSyncmlVersions.end(); itVersion++ ) + mSyncmlVersion->insertItem( (*itVersion).second ); + + // WBXML + mWbxml = new QCheckBox( i18n("WAP Binary XML"), optionsWidget ); + mGridLayout->addMultiCellWidget( mWbxml, 12, 12, 0, 1 ); + + // Identifier + label = new QLabel( i18n("Software Identifier:"), optionsWidget ); + mGridLayout->addWidget( label, 13, 0 ); + + mIdentifier = new KComboBox( true, optionsWidget ); + mGridLayout->addWidget( mIdentifier, 13, 1 ); + + mIdentifier->insertItem( "" ); + mIdentifier->insertItem( "PC Suite" ); + + // recvLimit + label = new QLabel( i18n("Receive Limit:"), optionsWidget ); + mGridLayout->addWidget( label, 14, 0 ); + + mRecvLimit = new QSpinBox( optionsWidget ); + mRecvLimit->setMinValue( 1 ); + mRecvLimit->setMaxValue( 65536 ); + mGridLayout->addWidget( mRecvLimit, 14, 1 ); + + // maxObjSize + label = new QLabel( i18n("Maximum Object Size"), optionsWidget ); + mGridLayout->addWidget( label, 15, 0 ); + + mMaxObjSize = new QSpinBox( optionsWidget ); + mMaxObjSize->setMinValue( 1 ); + mMaxObjSize->setMaxValue( 65536 ); + mGridLayout->addWidget( mMaxObjSize, 15, 1 ); + + topLayout()->addStretch( 1 ); +} + +void ConfigGuiSyncmlObex::slotConnectionChanged( int pos ) +{ + mUsb->hide(); + mBluetooth->hide(); + + if ( pos == 0 ) + mBluetooth->show(); + else if ( pos == 1 ) + mUsb->show(); +} + +void ConfigGuiSyncmlObex::load( const QString &xml ) +{ + QDomDocument document; + document.setContent( xml ); + + QDomElement docElement = document.documentElement(); + + QDomNode node; + for( node = docElement.firstChild(); !node.isNull(); node = node.nextSibling() ) { + QDomElement element = node.toElement(); + if ( element.tagName() == "username" ) { + mUsername->setText( element.text() ); + } else if ( element.tagName() == "password" ) { + mPassword->setText( element.text() ); + } else if ( element.tagName() == "type" ) { + for ( uint i = 0; i < mConnectionTypes.count(); i++ ) { + if ( mConnectionTypes[i].first == element.text().toInt() ) { + mConnection->setCurrentItem( i ); + slotConnectionChanged( i ); + break; + } + } + } else if ( element.tagName() == "version" ) { + for ( uint i = 0; i < mSyncmlVersions.count(); i++ ) { + if ( mSyncmlVersions[i].first == element.text().toInt() ) { + mSyncmlVersion->setCurrentItem( i ); + break; + } + } + } else if ( element.tagName() == "bluetooth_address" ) { + if ( mBluetooth ) mBluetooth->setAddress( element.text() ); + } else if ( element.tagName() == "bluetooth_channel" ) { + if ( mBluetooth ) mBluetooth->setChannel( element.text() ); + } else if ( element.tagName() == "identifier" ) { + if ( mIdentifier ) mIdentifier->setCurrentText( element.text() ); + } else if ( element.tagName() == "interface" ) { + if ( mUsb ) mUsb->setInterface( element.text().toInt() ); + } else if ( element.tagName() == "wbxml" ) { + if ( mWbxml) mWbxml->setChecked( element.text() == "1" ); + } else if ( element.tagName() == "recvLimit" ) { + if ( mRecvLimit ) mRecvLimit->setValue( element.text().toInt() ); + } else if ( element.tagName() == "maxObjSize" ) { + if ( mMaxObjSize ) mMaxObjSize->setValue( element.text().toInt() ); + } else if ( element.tagName() == "usestringtable" ) { + mUseStringTable->setChecked( element.text() == "1" ); + } else if ( element.tagName() == "onlyreplace" ) { + mOnlyReplace->setChecked( element.text() == "1" ); + } else if ( element.tagName() == "contact_db" ) { + mContactDb->setCurrentText( element.text() ); + } else if ( element.tagName() == "calendar_db" ) { + mCalendarDb->setCurrentText( element.text() ); + } else if ( element.tagName() == "note_db" ) { + mNoteDb->setCurrentText( element.text() ); + } + } +} + +QString ConfigGuiSyncmlObex::save() const +{ + QString xml; + xml = "<config>\n"; + xml += "<username>" + mUsername->text() + "</username>\n"; + xml += "<password>" + mPassword->text() + "</password>\n"; + ConnectionTypeList::ConstIterator it; + for ( it = mConnectionTypes.begin(); it != mConnectionTypes.end(); it++ ) { + if ( mConnection->currentText() == (*it).second ) { + xml += "<type>" + QString("%1").arg((*it).first) + "</type>\n"; + break; + } + } + + // Bluetooth Address + xml += "<bluetooth_address>" + mBluetooth->address() + "</bluetooth_address>\n"; + + // Bluetooth Channel + xml += "<bluetooth_channel>" + mBluetooth->channel() + "</bluetooth_channel>\n"; + + // USB Interface + xml += "<interface>" + QString::number( mUsb->interface() ) +"</interface>\n"; + + // SyncML Version + SyncmlVersionList::ConstIterator itVersion; + for ( itVersion = mSyncmlVersions.begin(); itVersion != mSyncmlVersions.end(); itVersion++ ) { + if ( mSyncmlVersion->currentText() == (*itVersion).second ) { + xml += "<version>" + QString("%1").arg((*itVersion).first) + "</version>\n"; + break; + } + } + + // (Software) Identifier + xml += "<identifier>" + mIdentifier->currentText() + "</identifier>\n"; + + // WBXML + xml += "<wbxml>"; + if ( mWbxml->isChecked() ) + xml += "1"; + else + xml += "0"; + xml += "</wbxml>\n"; + + // Receive Limit + xml += "<recvLimit>" + QString::number( mRecvLimit->value() ) + "</recvLimit>\n"; + + // Maximal Object Size + xml += "<maxObjSize>" + QString::number( mMaxObjSize->value() ) + "</maxObjSize>\n"; + + xml += "<usestringtable>"; + if ( mUseStringTable->isChecked() ) + xml += "1"; + else + xml += "0"; + xml += "</usestringtable>\n"; + + xml += "<onlyreplace>"; + if ( mOnlyReplace->isChecked() ) + xml += "1"; + else + xml += "0"; + xml += "</onlyreplace>\n"; + + xml += "<contact_db>" + mContactDb->currentText() + "</contact_db>\n"; + xml += "<calendar_db>" + mCalendarDb->currentText() + "</calendar_db>\n"; + xml += "<note_db>" + mNoteDb->currentText() + "</note_db>\n"; + xml += "</config>"; + + return xml; +} + +void ConfigGuiSyncmlObex::addLineEdit( QWidget *parent, const QString &text, KComboBox **edit, int row ) +{ + QLabel *label = new QLabel( text, parent ); + mGridLayout->addWidget( label, row, 0 ); + + *edit = new KComboBox( true, parent ); + mGridLayout->addWidget( *edit, row, 1 ); +} + +#include "configguisyncmlobex.moc" diff --git a/kitchensync/src/configguisyncmlobex.h b/kitchensync/src/configguisyncmlobex.h new file mode 100644 index 000000000..a10d06a52 --- /dev/null +++ b/kitchensync/src/configguisyncmlobex.h @@ -0,0 +1,87 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2005 Cornelius Schumacher <[email protected]> + Copyright (c) 2006 Daniel Gollub <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ +#ifndef CONFIGGUISYNCMLOBEX_H +#define CONFIGGUISYNCMLOBEX_H + +#include <qdom.h> + +#include "configgui.h" +#include "connectionwidgets.h" + +class QCheckBox; +class QComboBox; +class QGridLayout; +class QSpinBox; +class KComboBox; +class KLineEdit; +class KURLRequester; + +class ConfigGuiSyncmlObex : public ConfigGui +{ + Q_OBJECT + + public: + ConfigGuiSyncmlObex( const QSync::Member &, QWidget *parent = 0 ); + + void load( const QString &xml ); + QString save() const; + + public slots: + void slotConnectionChanged( int pos ); + + private: + // Connection + typedef QPair<int, QString> ConnectionType; + typedef QValueList<ConnectionType> ConnectionTypeList; + ConnectionTypeList mConnectionTypes; + + QComboBox *mConnection; + BluetoothWidget *mBluetooth; + UsbWidget *mUsb; + + // Options + typedef QPair<int, QString> SyncmlVersion; + typedef QValueList<SyncmlVersion> SyncmlVersionList; + SyncmlVersionList mSyncmlVersions; + + QStringList mIdentiferList; + KLineEdit *mUsername; + KLineEdit *mPassword; + QCheckBox *mUseStringTable; + QCheckBox *mOnlyReplace; + QSpinBox *mRecvLimit; + QSpinBox *mMaxObjSize; + QComboBox *mSyncmlVersion; + KComboBox *mIdentifier; + QCheckBox *mWbxml; + + QGridLayout *mGridLayout; + + KComboBox *mContactDb; + KComboBox *mCalendarDb; + KComboBox *mNoteDb; + + protected slots: + void addLineEdit( QWidget *parent, const QString &text, KComboBox **edit, int row ); +}; + +#endif diff --git a/kitchensync/src/conflictdialog.cpp b/kitchensync/src/conflictdialog.cpp new file mode 100644 index 000000000..a021e121a --- /dev/null +++ b/kitchensync/src/conflictdialog.cpp @@ -0,0 +1,26 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2005 Tobias Koenig <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "conflictdialog.h" + +ConflictDialog::ConflictDialog( QSync::SyncMapping &mapping, QWidget *parent ) + : QDialog( parent ), mMapping( mapping ) +{ +} diff --git a/kitchensync/src/conflictdialog.h b/kitchensync/src/conflictdialog.h new file mode 100644 index 000000000..9718f4c65 --- /dev/null +++ b/kitchensync/src/conflictdialog.h @@ -0,0 +1,40 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2005 Tobias Koenig <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef CONFLICTDIALOG_H +#define CONFLICTDIALOG_H + +#include <qdialog.h> + +#include <libqopensync/syncmapping.h> + +/** + Base class for SingleConflictDialog and MultiConflictDialog. + */ +class ConflictDialog : public QDialog +{ + public: + ConflictDialog( QSync::SyncMapping &mapping, QWidget *parent ); + + protected: + QSync::SyncMapping mMapping; +}; + +#endif diff --git a/kitchensync/src/connectionwidgets.cpp b/kitchensync/src/connectionwidgets.cpp new file mode 100644 index 000000000..76d2297b7 --- /dev/null +++ b/kitchensync/src/connectionwidgets.cpp @@ -0,0 +1,227 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2005 Tobias Koenig <[email protected]> + Copyright (c) 2006 Daniel Gollub <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include <kcombobox.h> +#include <kdialog.h> +#include <kglobal.h> +#include <kiconloader.h> +#include <kinputdialog.h> +#include <klineedit.h> +#include <klocale.h> +#include <kmessagebox.h> + +#include <qapplication.h> +#include <qeventloop.h> +#include <qlabel.h> +#include <qlayout.h> +#include <qpushbutton.h> +#include <qspinbox.h> +#include <qtabwidget.h> +#include <qtooltip.h> +#include <qvbox.h> + +#include "connectionwidgets.h" + +BluetoothWidget::BluetoothWidget( QWidget *parent ) + : QWidget( parent ) +{ + QGridLayout *layout = new QGridLayout( this ); + + mAddress = new KLineEdit( this ); + mAddress->setInputMask( ">NN:NN:NN:NN:NN:NN;" ); + layout->addWidget( mAddress, 1, 0 ); + + QLabel *label = new QLabel( i18n( "Bluetooth address:" ), this ); + label->setBuddy( mAddress ); + layout->addWidget( label, 0, 0 ); + + mChannel = new KLineEdit( this ); + layout->addWidget( mChannel, 1, 1 ); + + mChannelLabel = new QLabel( i18n( "Channel:" ), this ); + mChannelLabel->setBuddy( mChannel ); + layout->addWidget( mChannelLabel, 0, 1 ); + + layout->setRowStretch( 2, 1 ); +} + +void BluetoothWidget::hideChannel() +{ + mChannelLabel->hide(); + mChannel->hide(); +} + +void BluetoothWidget::showChannel() +{ + mChannelLabel->show(); + mChannel->show(); +} + +void BluetoothWidget::setAddress( const QString address ) +{ + mAddress->setText( address ); +} + +void BluetoothWidget::setChannel( const QString channel ) +{ + if ( mChannel ) + mChannel->setText( channel ); +} + +QString BluetoothWidget::address() const +{ + return mAddress->text(); +} + +QString BluetoothWidget::channel() const +{ + if ( mChannel->text().isEmpty() ) + return QString(); + + return mChannel->text(); +} + +// FIXME - Only IrMC specific +IRWidget::IRWidget( QWidget *parent ) + : QWidget( parent ) +{ + QGridLayout *layout = new QGridLayout( this, 3, 3, 11, 3 ); + + mDevice = new KLineEdit( this ); + mSerialNumber = new KLineEdit( this ); + + layout->addWidget( mDevice, 1, 0 ); + layout->addWidget( mSerialNumber, 1, 1 ); + + QLabel *label = new QLabel( i18n( "Device Name:" ), this ); + label->setBuddy( mDevice ); + layout->addWidget( label, 0, 0 ); + + label = new QLabel( i18n( "Serial Number:" ), this ); + label->setBuddy( mSerialNumber ); + layout->addWidget( label, 0, 1 ); + + layout->setRowStretch( 2, 1 ); +} + +void IRWidget::load( const QDomElement &parent ) +{ + QDomNode node; + for ( node = parent.firstChild(); !node.isNull(); node = node.nextSibling() ) { + QDomElement element = node.toElement(); + if ( element.tagName() == "irname" ) + mDevice->setText( element.text() ); + else if ( element.tagName() == "irserial" ) + mSerialNumber->setText( element.text() ); + } +} + +void IRWidget::save( QDomDocument &doc, QDomElement &parent ) +{ + QDomElement element = doc.createElement( "irname" ); + element.appendChild( doc.createTextNode( mDevice->text() ) ); + parent.appendChild( element ); + + element = doc.createElement( "irserial" ); + element.appendChild( doc.createTextNode( mSerialNumber->text() ) ); + parent.appendChild( element ); +} + +// FIXME - Only IrMC specific +CableWidget::CableWidget( QWidget *parent ) + : QWidget( parent ) +{ + QGridLayout *layout = new QGridLayout( this, 3, 2, 11, 3 ); + + mManufacturer = new KComboBox( this ); + mDevice = new KComboBox( true, this ); + + layout->addWidget( mManufacturer, 0, 1 ); + layout->addWidget( mDevice, 1, 1 ); + + QLabel *label = new QLabel( i18n( "Device Manufacturer:" ), this ); + label->setBuddy( mManufacturer ); + layout->addWidget( label, 0, 0 ); + + label = new QLabel( i18n( "Device:" ), this ); + label->setBuddy( mDevice ); + layout->addWidget( label, 1, 0 ); + + layout->setRowStretch( 2, 1 ); + + mManufacturer->insertItem( i18n( "SonyEricsson/Ericsson" ) ); + mManufacturer->insertItem( i18n( "Siemens" ) ); + + mDevice->insertItem( "/dev/ttyS0" ); + mDevice->insertItem( "/dev/ttyS1" ); + mDevice->insertItem( "/dev/ttyUSB0" ); + mDevice->insertItem( "/dev/ttyUSB1" ); +} + +void CableWidget::load( const QDomElement &parent ) +{ + QDomNode node; + for ( node = parent.firstChild(); !node.isNull(); node = node.nextSibling() ) { + QDomElement element = node.toElement(); + if ( element.tagName() == "cabletype" ) + mManufacturer->setCurrentItem( element.text().toInt() ); + else if ( element.tagName() == "cabledev" ) + mDevice->setCurrentText( element.text() ); + } +} + +void CableWidget::save( QDomDocument &doc, QDomElement &parent ) +{ + QDomElement element = doc.createElement( "cabletype" ); + element.appendChild( doc.createTextNode( QString::number( mManufacturer->currentItem() ) ) ); + parent.appendChild( element ); + + element = doc.createElement( "cabledev" ); + element.appendChild( doc.createTextNode( mDevice->currentText() ) ); + parent.appendChild( element ); +} + +UsbWidget::UsbWidget( QWidget *parent ) + : QWidget( parent ) +{ + QGridLayout *layout = new QGridLayout( this, 3, 2, 11, 3); + + mInterface = new QSpinBox( this ); + layout->addWidget( mInterface, 0, 1 ); + + QLabel *label = new QLabel( i18n( "USB Interface:" ), this ); + label->setBuddy( mInterface ); + layout->addWidget( label, 0, 0 ); + + layout->setRowStretch( 2, 1 ); +} + +void UsbWidget::setInterface( int interface ) +{ + mInterface->setValue( interface ); +} + +int UsbWidget::interface() const +{ + return mInterface->value(); +} + +#include "connectionwidgets.moc" diff --git a/kitchensync/src/connectionwidgets.h b/kitchensync/src/connectionwidgets.h new file mode 100644 index 000000000..cb7dfb428 --- /dev/null +++ b/kitchensync/src/connectionwidgets.h @@ -0,0 +1,99 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2005 Tobias Koenig <[email protected]> + Copyright (c) 2006 Daniel Gollub <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#ifndef CONNECTIONWIDGETS_H +#define CONNECTIONWIDGETS_H + +#include <qdom.h> + +#include "configgui.h" + +class QCheckBox; +class QLabel; +class QPushButton; +class QSpinBox; + +class KComboBox; +class KLineEdit; + +class BluetoothWidget : public QWidget +{ + Q_OBJECT + + public: + BluetoothWidget( QWidget *parent ); + + void hideChannel(); + void showChannel(); + + void setAddress( const QString address ); + void setChannel( const QString channel ); + QString address() const; + QString channel() const; + + private: + KLineEdit *mAddress; + KLineEdit *mChannel; + QLabel *mChannelLabel; +}; + +class IRWidget : public QWidget +{ + Q_OBJECT + + public: + IRWidget( QWidget *parent ); + + void load( const QDomElement& ); + void save( QDomDocument&, QDomElement& ); + + private: + KLineEdit *mDevice; + KLineEdit *mSerialNumber; +}; + +class CableWidget : public QWidget +{ + public: + CableWidget( QWidget *parent ); + + void load( const QDomElement& ); + void save( QDomDocument&, QDomElement& ); + + private: + KComboBox *mManufacturer; + KComboBox *mDevice; +}; + +class UsbWidget : public QWidget +{ + public: + UsbWidget( QWidget *parent ); + + int interface() const; + void setInterface( int interface ); + + private: + QSpinBox *mInterface; +}; + +#endif // CONNECTIONWIDGETS_H diff --git a/kitchensync/src/genericdiffalgo.cpp b/kitchensync/src/genericdiffalgo.cpp new file mode 100644 index 000000000..9c03360e9 --- /dev/null +++ b/kitchensync/src/genericdiffalgo.cpp @@ -0,0 +1,70 @@ +/* + This file is part of libkdepim. + + Copyright (c) 2004 Tobias Koenig <[email protected]> + + 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 <qstringlist.h> + +#include <klocale.h> + +#include "genericdiffalgo.h" + +using namespace KSync; + +#define MAX( a, b ) ( a > b ? a : b ) + +#ifndef KDE_USE_FINAL +// With --enable-final, we get the (identical) compareString from +// addresseediffalgo.cpp +static bool compareString( const QString &left, const QString &right ) +{ + if ( left.isEmpty() && right.isEmpty() ) + return true; + else + return left == right; +} +#endif + +GenericDiffAlgo::GenericDiffAlgo( const QString &leftData, const QString &rightData ) + : mLeftData( leftData ), mRightData( rightData ) +{ +} + +void GenericDiffAlgo::run() +{ + begin(); + + QStringList leftList = QStringList::split( '\n', mLeftData, true ); + QStringList rightList = QStringList::split( '\n', mRightData, true ); + + uint lines = MAX( leftList.count(), rightList.count() ); + for ( uint i = 0; i < lines; ++i ) { + if ( i < leftList.count() && i < rightList.count() ) { + if ( !compareString( leftList[ i ], rightList[ i ] ) ) + conflictField( i18n( "Line %1" ).arg( i ), leftList[ i ], rightList[ i ] ); + } else if ( i < leftList.count() && i >= rightList.count() ) { + additionalLeftField( i18n( "Line %1" ).arg( i ), leftList[ i ] ); + } else if ( i >= leftList.count() && i < rightList.count() ) { + additionalRightField( i18n( "Line %1" ).arg( i ), rightList[ i ] ); + } + } + + end(); +} + diff --git a/kitchensync/src/genericdiffalgo.h b/kitchensync/src/genericdiffalgo.h new file mode 100644 index 000000000..64f4a4404 --- /dev/null +++ b/kitchensync/src/genericdiffalgo.h @@ -0,0 +1,45 @@ +/* + This file is part of libkdepim. + + Copyright (c) 2004 Tobias Koenig <[email protected]> + + 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 KSYNC_GENERICDIFFALGO_H +#define KSYNC_GENERICDIFFALGO_H + +#include <libkdepim/diffalgo.h> + +using namespace KPIM; + +namespace KSync { + +class GenericDiffAlgo : public DiffAlgo +{ + public: + GenericDiffAlgo( const QString &left, const QString &right ); + + void run(); + + private: + QString mLeftData; + QString mRightData; +}; + +} + +#endif diff --git a/kitchensync/src/groupconfig.cpp b/kitchensync/src/groupconfig.cpp new file mode 100644 index 000000000..2ad4af631 --- /dev/null +++ b/kitchensync/src/groupconfig.cpp @@ -0,0 +1,179 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2005 Cornelius Schumacher <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "groupconfig.h" + +#include "groupconfigcommon.h" +#include "memberconfig.h" +#include "memberinfo.h" +#include "pluginpicker.h" +#include "syncprocess.h" +#include "syncprocessmanager.h" + +#include <libqopensync/group.h> +#include <libqopensync/plugin.h> + +#include <kdialog.h> +#include <kiconloader.h> +#include <kjanuswidget.h> +#include <klocale.h> +#include <kmessagebox.h> + + +#include <qlabel.h> +#include <qlayout.h> +#include <qpushbutton.h> + +GroupConfig::GroupConfig( QWidget *parent ) + : QWidget( parent ) +{ + QBoxLayout *topLayout = new QVBoxLayout( this ); + topLayout->setSpacing( KDialog::spacingHint() ); + + QFrame *titleFrame = new QFrame( this ); + topLayout->addWidget( titleFrame ); + + titleFrame->setPaletteForegroundColor( colorGroup().light() ); + titleFrame->setPaletteBackgroundColor( colorGroup().mid() ); + + QBoxLayout *nameLayout = new QHBoxLayout( titleFrame ); + nameLayout->setMargin( 4 ); + + QPixmap icon = KGlobal::iconLoader()->loadIcon( "kontact_summary", + KIcon::Desktop ); + + QLabel *iconLabel = new QLabel( titleFrame ); + iconLabel->setPixmap( icon ); + nameLayout->addWidget( iconLabel ); + + nameLayout->addSpacing( 8 ); + + QLabel *label = new QLabel( i18n("Group:"), titleFrame ); + QFont font = label->font(); + font.setBold( true ); + font.setPointSize( font.pointSize() + 2 ); + label->setFont( font ); + nameLayout->addWidget( label ); + + mNameLabel = new QLabel( titleFrame ); + font = mNameLabel->font(); + font.setBold( true ); + font.setPointSize( font.pointSize() + 2 ); + mNameLabel->setFont( font ); + nameLayout->addWidget( mNameLabel ); + + nameLayout->addStretch( 1 ); + + mMemberView = new KJanusWidget( this, 0, KJanusWidget::IconList ); + topLayout->addWidget( mMemberView ); + + QBoxLayout *buttonLayout = new QHBoxLayout( topLayout ); + + QPushButton *addButton = new QPushButton( i18n("Add Member..."), this ); + connect( addButton, SIGNAL( clicked() ), SLOT( addMember() ) ); + buttonLayout->addWidget( addButton ); + + buttonLayout->addStretch( 1 ); + + icon = KGlobal::iconLoader()->loadIcon( "bookmark", KIcon::Desktop ); + QFrame *page = mMemberView->addPage( i18n("Group"), + i18n("General Group Settings"), icon ); + QBoxLayout *pageLayout = new QVBoxLayout( page ); + + mCommonConfig = new GroupConfigCommon( page ); + pageLayout->addWidget( mCommonConfig ); +} + +void GroupConfig::setSyncProcess( SyncProcess *process ) +{ + mProcess = process; + + mNameLabel->setText( mProcess->group().name() ); + mCommonConfig->setSyncProcess( mProcess ); + + updateMembers(); +} + +void GroupConfig::updateMembers() +{ + QValueList<MemberConfig *>::ConstIterator memberIt; + for ( memberIt = mMemberConfigs.begin(); memberIt != mMemberConfigs.end(); ++memberIt ) + (*memberIt)->saveData(); + + QValueList<QFrame *>::ConstIterator it2; + for ( it2 = mConfigPages.begin(); it2 != mConfigPages.end(); ++it2 ) { + mMemberView->removePage( *it2 ); + delete *it2; + } + mConfigPages.clear(); + mMemberConfigs.clear(); + + QSync::Group group = mProcess->group(); + QSync::Group::Iterator it( group.begin() ); + for ( ; it != group.end(); ++it ) { + QSync::Member member = *it; + MemberInfo mi( member ); + QFrame *page = mMemberView->addPage( mi.name(), + QString( "%1 (%2)" ).arg( mi.name() ).arg(member.pluginName()), mi.desktopIcon() ); + + QBoxLayout *pageLayout = new QVBoxLayout( page ); + mConfigPages.append( page ); + + MemberConfig *memberConfig = new MemberConfig( page, member ); + mMemberConfigs.append( memberConfig ); + pageLayout->addWidget( memberConfig ); + + memberConfig->loadData(); + } +} + +void GroupConfig::saveConfig() +{ + mProcess->group().save(); + + QValueList<MemberConfig *>::ConstIterator it; + for ( it = mMemberConfigs.begin(); it != mMemberConfigs.end(); ++it ) + (*it)->saveData(); + + mCommonConfig->save(); + + mProcess->reinitEngine(); +} + +void GroupConfig::addMember() +{ + QSync::Plugin plugin = PluginPickerDialog::getPlugin( this ); + + if ( plugin.isValid() ) { + QSync::Result result = SyncProcessManager::self()->addMember( mProcess, plugin ); + if ( result.isError() ) { + KMessageBox::error( this, i18n("Error adding member %1\n%2\nType: %3") + .arg( plugin.name() ).arg( result.message() ).arg( result.type() ) ); + } else { + updateMembers(); + + // select last (added) page + int index = mMemberView->pageIndex( mConfigPages.last() ); + mMemberView->showPage( index ); + } + } +} + +#include "groupconfig.moc" diff --git a/kitchensync/src/groupconfig.h b/kitchensync/src/groupconfig.h new file mode 100644 index 000000000..d46d64575 --- /dev/null +++ b/kitchensync/src/groupconfig.h @@ -0,0 +1,62 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2005 Cornelius Schumacher <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ +#ifndef GROUPCONFIG_H +#define GROUPCONFIG_H + +#include <qwidget.h> +#include <qvaluelist.h> + +class QFrame; +class QLabel; +class KJanusWidget; + +class GroupConfigCommon; +class MemberConfig; +class SyncProcess; + +class GroupConfig : public QWidget +{ + Q_OBJECT + + public: + GroupConfig( QWidget *parent ); + + void setSyncProcess( SyncProcess *process ); + + void updateMembers(); + + void saveConfig(); + + protected slots: + void addMember(); + + private: + QLabel *mNameLabel; + + KJanusWidget *mMemberView; + + SyncProcess *mProcess; + + GroupConfigCommon *mCommonConfig; + QValueList<MemberConfig *> mMemberConfigs; + QValueList<QFrame *> mConfigPages; +}; + +#endif diff --git a/kitchensync/src/groupconfigcommon.cpp b/kitchensync/src/groupconfigcommon.cpp new file mode 100644 index 000000000..d5b0bd1c1 --- /dev/null +++ b/kitchensync/src/groupconfigcommon.cpp @@ -0,0 +1,158 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2005 Cornelius Schumacher <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + + +#include <kdialog.h> +#include <klineedit.h> +#include <klocale.h> +#include <kdebug.h> + +#include <qlabel.h> +#include <qlayout.h> +#include <qcheckbox.h> + +#include <libqopensync/group.h> +#include <libqopensync/conversion.h> +#include <libqopensync/environment.h> + +#include "syncprocess.h" +#include "syncprocessmanager.h" + +#include "groupconfigcommon.h" + +ObjectTypeSelector::ObjectTypeSelector( QWidget *parent ) + : QWidget( parent ) +{ + QGridLayout *layout = new QGridLayout( this ); + layout->setMargin( 0 ); + + const QSync::Conversion conversion = SyncProcessManager::self()->environment()->conversion(); + + QMap<QString, QString> objectTypeMap; + objectTypeMap.insert( "contact", i18n( "Contacts" ) ); + objectTypeMap.insert( "event", i18n( "Events" ) ); + objectTypeMap.insert( "todo", i18n( "To-dos" ) ); + objectTypeMap.insert( "note", i18n( "Notes" ) ); + + QStringList objectTypes = conversion.objectTypes(); + + // reorder the entries so that contact and event are the first one + qHeapSort( objectTypes ); + + QStringList reoderedObjectTypes, stack; + for ( uint i = 0; i < objectTypes.count(); ++i ) { + if ( objectTypes[ i ] == "contact" || objectTypes[ i ] == "event" ) + reoderedObjectTypes.append( objectTypes[ i ] ); + else + stack.append( objectTypes[ i ] ); + } + reoderedObjectTypes += stack; + + QStringList::ConstIterator it; + + int row = 0; + int col = 0; + for( it = reoderedObjectTypes.begin(); it != reoderedObjectTypes.end(); ++it ) { + QString objectType = *it; + + // Don't display object type "data". Object type "data" is a kind of wildcard - so don't filter * + if ( objectType == "data" ) + continue; + + QCheckBox *objectCheckBox = new QCheckBox( objectTypeMap[ objectType ], this ); + layout->addWidget( objectCheckBox, row, col ); + mObjectTypeChecks.insert( objectType, objectCheckBox ); + + col++; + if ( (row == 0 && col == 2) || col == 3 ) { + col = 0; + row++; + } + } +} + +void ObjectTypeSelector::load( const QSync::Group &group ) +{ + const QSync::GroupConfig config = group.config(); + + const QStringList objectTypes = config.activeObjectTypes(); + + // Enable everything on the inital load + bool initialLoad = false; + if ( objectTypes.isEmpty() ) + initialLoad = true; + + QMap<QString, QCheckBox*>::ConstIterator it; + for( it = mObjectTypeChecks.begin(); it != mObjectTypeChecks.end(); ++it ) { + QCheckBox *check = it.data(); + check->setChecked( objectTypes.contains( it.key() ) || initialLoad ); + } +} + +void ObjectTypeSelector::save( QSync::Group group ) +{ + QStringList objectTypes; + + QMap<QString,QCheckBox *>::ConstIterator it; + for( it = mObjectTypeChecks.begin(); it != mObjectTypeChecks.end(); ++it ) { + QCheckBox *check = it.data(); + if ( check->isChecked() ) + objectTypes.append( it.key() ); + } + + // Always add object type "data" + objectTypes.append( "data" ); + + QSync::GroupConfig config = group.config(); + config.setActiveObjectTypes( objectTypes ); +} + +GroupConfigCommon::GroupConfigCommon( QWidget *parent ) + : QWidget( parent ) +{ + QGridLayout *layout = new QGridLayout( this, 2, 2, KDialog::marginHint(), KDialog::spacingHint() ); + + layout->addWidget( new QLabel( i18n( "Name:" ), this ), 0, 0 ); + + mGroupName = new KLineEdit( this ); + layout->addWidget( mGroupName, 0, 1 ); + + layout->addWidget( new QLabel( i18n( "Object Types to be Synchronized:"), this ), 1, 0, Qt::AlignTop ); + + mObjectTypeSelector = new ObjectTypeSelector( this ); + layout->addWidget( mObjectTypeSelector, 1, 1 ); + + layout->setRowStretch( 2, 1 ); +} + +void GroupConfigCommon::setSyncProcess( SyncProcess *syncProcess ) +{ + mSyncProcess = syncProcess; + + mGroupName->setText( mSyncProcess->group().name() ); + mObjectTypeSelector->load( mSyncProcess->group() ); +} + +void GroupConfigCommon::save() +{ + mSyncProcess->group().setName( mGroupName->text() ); + mObjectTypeSelector->save( mSyncProcess->group() ); +} diff --git a/kitchensync/src/groupconfigcommon.h b/kitchensync/src/groupconfigcommon.h new file mode 100644 index 000000000..b28499aa0 --- /dev/null +++ b/kitchensync/src/groupconfigcommon.h @@ -0,0 +1,60 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2005 Cornelius Schumacher <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ +#ifndef GROUPCONFIGCOMMON_H +#define GROUPCONFIGCOMMON_H + +#include <qwidget.h> +#include <qmap.h> + +#include <libqopensync/group.h> + +class KLineEdit; +class SyncProcess; +class QCheckBox; + +class ObjectTypeSelector : public QWidget +{ + public: + ObjectTypeSelector( QWidget *parent ); + + void load( const QSync::Group &group ); + void save( QSync::Group group ); + + private: + QMap<QString,QCheckBox *> mObjectTypeChecks; +}; + +class GroupConfigCommon : public QWidget +{ + public: + GroupConfigCommon( QWidget *parent ); + + void setSyncProcess( SyncProcess *syncProcess ); + void save(); + + private: + KLineEdit *mGroupName; + ObjectTypeSelector *mObjectTypeSelector; + + SyncProcess *mSyncProcess; +}; + +#endif diff --git a/kitchensync/src/groupconfigdialog.cpp b/kitchensync/src/groupconfigdialog.cpp new file mode 100644 index 000000000..868915da2 --- /dev/null +++ b/kitchensync/src/groupconfigdialog.cpp @@ -0,0 +1,57 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2005 Cornelius Schumacher <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "groupconfigdialog.h" + +#include "groupconfig.h" + +#include <klocale.h> + +#include <qlayout.h> + +GroupConfigDialog::GroupConfigDialog( QWidget *parent, SyncProcess *process ) + : KDialogBase( parent, 0, true, i18n("Configure Synchronization Group"), + Ok ) +{ + QFrame *topFrame = makeMainWidget(); + + QBoxLayout *topLayout = new QVBoxLayout( topFrame ); + + mConfigWidget = new GroupConfig( topFrame ); + topLayout->addWidget( mConfigWidget ); + + mConfigWidget->setSyncProcess( process ); + + setInitialSize( configDialogSize( "size_groupconfigdialog" ) ); +} + +GroupConfigDialog::~GroupConfigDialog() +{ + saveDialogSize( "size_groupconfigdialog" ); +} + +void GroupConfigDialog::slotOk() +{ + mConfigWidget->saveConfig(); + + accept(); +} + +#include "groupconfigdialog.moc" diff --git a/kitchensync/src/groupconfigdialog.h b/kitchensync/src/groupconfigdialog.h new file mode 100644 index 000000000..10000b960 --- /dev/null +++ b/kitchensync/src/groupconfigdialog.h @@ -0,0 +1,43 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2005 Cornelius Schumacher <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ +#ifndef GROUPCONFIGDIALOG_H +#define GROUPCONFIGDIALOG_H + +#include <kdialogbase.h> + +class GroupConfig; +class SyncProcess; + +class GroupConfigDialog : public KDialogBase +{ + Q_OBJECT + + public: + GroupConfigDialog( QWidget *parent, SyncProcess * ); + ~GroupConfigDialog(); + + protected slots: + void slotOk(); + + private: + GroupConfig *mConfigWidget; +}; + +#endif diff --git a/kitchensync/src/groupitem.cpp b/kitchensync/src/groupitem.cpp new file mode 100644 index 000000000..bd5a8821d --- /dev/null +++ b/kitchensync/src/groupitem.cpp @@ -0,0 +1,389 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2005 Tobias Koenig <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include <kapplication.h> +#include <kdialog.h> +#include <kglobal.h> +#include <kglobalsettings.h> +#include <kiconloader.h> +#include <klocale.h> +#include <kpassivepopup.h> +#include <kurllabel.h> + +#include <qlabel.h> +#include <qlayout.h> +#include <qpixmap.h> +#include <qprogressbar.h> +#include <qvbox.h> + +#include "memberinfo.h" +#include "multiconflictdialog.h" +#include "singleconflictdialog.h" +#include "syncprocessmanager.h" + +#include "groupitem.h" + +GroupItem::GroupItem( KWidgetList *parent, SyncProcess *process ) + : KWidgetListItem( parent ), mSyncProcess( process ), + mCallbackHandler( new QSync::CallbackHandler ), + mProcessedItems( 0 ), mMaxProcessedItems( 0 ), + mSynchronizing( false ) +{ + QFont boldFont; + boldFont.setBold( true ); + boldFont.setPointSize( boldFont.pointSize() + 2 ); + + QGridLayout *layout = new QGridLayout( this, 4, 4, KDialog::marginHint(), KDialog::spacingHint() ); + + mBox = new QVBox( this ); + mBox->setMargin( 5 ); + mProgressBar = new QProgressBar( this ); + mProgressBar->setTotalSteps( 100 ); + + mTime = new QLabel( this ); + mSyncAction = new KURLLabel( "exec:/sync", i18n( "Synchronize Now" ), this ); + mConfigureAction = new KURLLabel( "exec:/config", i18n( "Configure" ), this ); + + // header + QHBox* hbox = new QHBox( this ); + hbox->setMargin( 2 ); + + static QPixmap icon; + if ( icon.isNull() ) + icon = KGlobal::iconLoader()->loadIcon( "kontact_summary", KIcon::Desktop ); + + mIcon = new QLabel( hbox ); + mIcon->setPixmap( icon ); + mIcon->setFixedSize( mIcon->sizeHint() ); + mIcon->setPaletteBackgroundColor( colorGroup().mid() ); + + mGroupName = new QLabel( hbox ); + mGroupName->setAlignment( AlignLeft | AlignVCenter ); + mGroupName->setIndent( KDialog::spacingHint() ); + mGroupName->setFont( boldFont ); + mGroupName->setPaletteForegroundColor( colorGroup().light() ); + mGroupName->setPaletteBackgroundColor( colorGroup().mid() ); + + mStatus = new QLabel( hbox ); + mStatus->setAlignment( Qt::AlignRight ); + mStatus->setAlignment( AlignRight | AlignVCenter ); + mStatus->setIndent( KDialog::spacingHint() ); + mStatus->setFont( boldFont ); + mStatus->setPaletteForegroundColor( colorGroup().light() ); + mStatus->setPaletteBackgroundColor( colorGroup().mid() ); + mStatus->setText( i18n( "Ready" ) ); + + hbox->setPaletteBackgroundColor( colorGroup().mid() ); + hbox->setMaximumHeight( hbox->minimumSizeHint().height() ); + + layout->addMultiCellWidget( hbox, 0, 0, 0, 3 ); + layout->addMultiCellWidget( mBox, 1, 1, 0, 3 ); + layout->addWidget( mTime, 2, 0 ); + layout->addWidget( mSyncAction, 2, 1 ); + layout->addWidget( mConfigureAction, 2, 2 ); + layout->addWidget( mProgressBar, 2, 3 ); + layout->setColStretch( 0, 1 ); + layout->setRowStretch( 3, 1 ); + + setPaletteBackgroundColor( kapp->palette().active().base() ); + + connect( mCallbackHandler, SIGNAL( conflict( QSync::SyncMapping ) ), + this, SLOT( conflict( QSync::SyncMapping ) ) ); + connect( mCallbackHandler, SIGNAL( change( const QSync::SyncChangeUpdate& ) ), + this, SLOT( change( const QSync::SyncChangeUpdate& ) ) ); + connect( mCallbackHandler, SIGNAL( mapping( const QSync::SyncMappingUpdate& ) ), + this, SLOT( mapping( const QSync::SyncMappingUpdate& ) ) ); + connect( mCallbackHandler, SIGNAL( engine( const QSync::SyncEngineUpdate& ) ), + this, SLOT( engine( const QSync::SyncEngineUpdate& ) ) ); + connect( mCallbackHandler, SIGNAL( member( const QSync::SyncMemberUpdate& ) ), + this, SLOT( member( const QSync::SyncMemberUpdate& ) ) ); + connect( mSyncAction, SIGNAL( leftClickedURL() ), + this, SLOT( synchronize() ) ); + connect( mConfigureAction, SIGNAL( leftClickedURL() ), + this, SLOT( configure() ) ); + connect( mSyncProcess, SIGNAL( engineChanged( QSync::Engine* ) ), + this, SLOT( engineChanged( QSync::Engine* ) ) ); + + mCallbackHandler->setEngine( mSyncProcess->engine() ); + + setSelectionForegroundColor( KGlobalSettings::textColor() ); + setSelectionBackgroundColor( KGlobalSettings::alternateBackgroundColor() ); + + update(); +} + +GroupItem::~GroupItem() +{ + delete mCallbackHandler; + mCallbackHandler = 0; +} + +void GroupItem::update() +{ + clear(); + + mGroupName->setText( i18n( "Group: %1" ).arg( mSyncProcess->group().name() ) ); + + QDateTime dateTime = mSyncProcess->group().lastSynchronization(); + if ( dateTime.isValid() ) + mTime->setText( i18n( "Last synchronized on: %1" ).arg( KGlobal::locale()->formatDateTime( dateTime ) ) ); + else + mTime->setText( i18n( "Not synchronized yet" ) ); + + mProgressBar->reset(); + mProgressBar->hide(); + + QSync::Group group = mSyncProcess->group(); + QSync::Group::Iterator memberIt( group.begin() ); + QSync::Group::Iterator memberEndIt( group.end() ); + + for ( ; memberIt != memberEndIt; ++memberIt ) { + MemberItem *item = new MemberItem( mBox, mSyncProcess, *memberIt ); + item->show(); + item->setStatusMessage( i18n( "Ready" ) ); + mMemberItems.append( item ); + } +} + +void GroupItem::clear() +{ + mGroupName->setText( QString() ); + + QValueList<MemberItem*>::Iterator it; + for ( it = mMemberItems.begin(); it != mMemberItems.end(); ++it ) + delete *it; + + mMemberItems.clear(); +} + +void GroupItem::conflict( QSync::SyncMapping mapping ) +{ + if ( mapping.changesCount() == 2 ) { + SingleConflictDialog dlg( mapping, this ); + dlg.exec(); + } else { + MultiConflictDialog dlg( mapping, this ); + dlg.exec(); + } +} + +void GroupItem::change( const QSync::SyncChangeUpdate &update ) +{ + switch ( update.type() ) { + case QSync::SyncChangeUpdate::Received: + mProcessedItems++; + mStatus->setText( i18n( "%1 entries read" ).arg( mProcessedItems ) ); + break; + case QSync::SyncChangeUpdate::ReceivedInfo: + mStatus->setText( i18n( "Receive information" ) ); + break; + case QSync::SyncChangeUpdate::Sent: + mProcessedItems--; + mStatus->setText( i18n( "%1 entries written" ).arg( mMaxProcessedItems - mProcessedItems ) ); + + mProgressBar->show(); + + { + int progress = 100; + if ( mMaxProcessedItems != 0 ) + progress = (mProcessedItems * 100) / mMaxProcessedItems; + + if ( progress < 0 ) + progress = 0; + + mProgressBar->setProgress( 100 - progress ); + } + break; + case QSync::SyncChangeUpdate::WriteError: + mStatus->setText( i18n( "Error" ) ); + KPassivePopup::message( update.result().message(), this ); + break; + case QSync::SyncChangeUpdate::ReceiveError: + mStatus->setText( i18n( "Error" ) ); + KPassivePopup::message( update.result().message(), this ); + break; + default: + mStatus->setText( QString() ); + break; + } +} + +void GroupItem::mapping( const QSync::SyncMappingUpdate& ) +{ +} + +void GroupItem::engine( const QSync::SyncEngineUpdate &update ) +{ + switch ( update.type() ) { + case QSync::SyncEngineUpdate::EndPhaseConnected: + mStatus->setText( i18n( "Connected" ) ); + mProgressBar->setProgress( 0 ); + mSynchronizing = true; + mSyncAction->setText( "Abort Synchronization" ); + break; + case QSync::SyncEngineUpdate::EndPhaseRead: + mStatus->setText( i18n( "Data read" ) ); + break; + case QSync::SyncEngineUpdate::EndPhaseWrite: + mStatus->setText( i18n( "Data written" ) ); + mProgressBar->setProgress( 100 ); + mProcessedItems = mMaxProcessedItems = 0; + break; + case QSync::SyncEngineUpdate::EndPhaseDisconnected: + mStatus->setText( i18n( "Disconnected" ) ); + break; + case QSync::SyncEngineUpdate::Error: + mStatus->setText( i18n( "Synchronization failed" ) ); + KPassivePopup::message( update.result().message(), this ); + this->update(); + + mSynchronizing = false; + mSyncAction->setText( i18n( "Synchronize Now" ) ); + break; + case QSync::SyncEngineUpdate::SyncSuccessfull: + mStatus->setText( i18n( "Successfully synchronized" ) ); + mSyncProcess->group().setLastSynchronization( QDateTime::currentDateTime() ); + mSyncProcess->group().save(); + this->update(); + + mSynchronizing = false; + mSyncAction->setText( i18n( "Synchronize Now" ) ); + break; + case QSync::SyncEngineUpdate::PrevUnclean: + mStatus->setText( i18n( "Previous synchronization failed" ) ); + break; + case QSync::SyncEngineUpdate::EndConflicts: + mStatus->setText( i18n( "Conflicts solved" ) ); + mMaxProcessedItems = mProcessedItems; + break; + default: + mStatus->setText( QString() ); + break; + } +} + +void GroupItem::member( const QSync::SyncMemberUpdate &update ) +{ + QValueList<MemberItem*>::Iterator it; + for ( it = mMemberItems.begin(); it != mMemberItems.end(); ++it ) { + if ( (*it)->member() == update.member() ) { + switch ( update.type() ) { + case QSync::SyncMemberUpdate::Connected: + (*it)->setStatusMessage( i18n( "Connected" ) ); + break; + case QSync::SyncMemberUpdate::SentChanges: + (*it)->setStatusMessage( i18n( "Changes read" ) ); + break; + case QSync::SyncMemberUpdate::CommittedAll: + (*it)->setStatusMessage( i18n( "Changes written" ) ); + break; + case QSync::SyncMemberUpdate::Disconnected: + (*it)->setStatusMessage( i18n( "Disconnected" ) ); + break; + case QSync::SyncMemberUpdate::ConnectError: + (*it)->setStatusMessage( i18n( "Error: %1" ).arg( update.result().message() ) ); + break; + case QSync::SyncMemberUpdate::GetChangesError: + (*it)->setStatusMessage( i18n( "Error: %1" ).arg( update.result().message() ) ); + break; + case QSync::SyncMemberUpdate::CommittedAllError: + (*it)->setStatusMessage( i18n( "Error: %1" ).arg( update.result().message() ) ); + break; + case QSync::SyncMemberUpdate::SyncDoneError: + (*it)->setStatusMessage( i18n( "Error: %1" ).arg( update.result().message() ) ); + break; + case QSync::SyncMemberUpdate::DisconnectedError: + (*it)->setStatusMessage( i18n( "Error: %1" ).arg( update.result().message() ) ); + break; + default: + break; + } + + return; + } + } +} + +void GroupItem::synchronize() +{ + if ( !mSynchronizing ) + emit synchronizeGroup( mSyncProcess ); + else + emit abortSynchronizeGroup( mSyncProcess ); +} + +void GroupItem::configure() +{ + emit configureGroup( mSyncProcess ); + + this->update(); +} + +void GroupItem::engineChanged( QSync::Engine *engine ) +{ + Q_ASSERT( engine ); + + mCallbackHandler->setEngine( engine ); + + this->update(); +} + +MemberItem::MemberItem( QWidget *parent, SyncProcess *process, + const QSync::Member &member ) + : QWidget( parent ), mSyncProcess( process ), mMember( member ) +{ + QFont boldFont; + boldFont.setBold( true ); + + MemberInfo mi( member ); + + QPixmap icon = mi.smallIcon(); + + QSync::Plugin plugin = member.plugin(); + + QVBoxLayout *layout = new QVBoxLayout( this ); + + QHBox* box = new QHBox( this ); + box->setMargin( 5 ); + box->setSpacing( 6 ); + layout->addWidget( box ); + + mIcon = new QLabel( box ); + mIcon->setPixmap( icon ); + mIcon->setAlignment( Qt::AlignTop ); + mIcon->setFixedWidth( mIcon->sizeHint().width() ); + + QVBox *nameBox = new QVBox( box ); + mMemberName = new QLabel( nameBox ); + mMemberName->setFont( boldFont ); + mDescription = new QLabel( nameBox ); + + mStatus = new QLabel( box ); + + mMemberName->setText( member.name() ); + mDescription->setText( plugin.longName() ); +} + +void MemberItem::setStatusMessage( const QString &msg ) +{ + mStatus->setText( msg ); +} + +#include "groupitem.moc" diff --git a/kitchensync/src/groupitem.h b/kitchensync/src/groupitem.h new file mode 100644 index 000000000..a18ca1d83 --- /dev/null +++ b/kitchensync/src/groupitem.h @@ -0,0 +1,111 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2005 Tobias Koenig <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef GROUPITEM_H +#define GROUPITEM_H + +#include "syncprocess.h" + +#include <libqopensync/callbackhandler.h> + +#include <kwidgetlist.h> + +namespace QSync { +class Engine; +} + +class MemberItem; +class KURLLabel; +class QLabel; +class QProgressBar; +class QVBox; + +class GroupItem : public KWidgetListItem +{ + Q_OBJECT + + public: + GroupItem( KWidgetList*, SyncProcess *syncProcess ); + ~GroupItem(); + + SyncProcess *syncProcess() const { return mSyncProcess; } + + void update(); + + void clear(); + + signals: + void synchronizeGroup( SyncProcess *syncProcess ); + void abortSynchronizeGroup( SyncProcess *syncProcess ); + void configureGroup( SyncProcess *syncProcess ); + + protected slots: + void conflict( QSync::SyncMapping ); + void change( const QSync::SyncChangeUpdate& ); + void mapping( const QSync::SyncMappingUpdate& ); + void engine( const QSync::SyncEngineUpdate& ); + void member( const QSync::SyncMemberUpdate& ); + + void synchronize(); + void configure(); + + void engineChanged( QSync::Engine *engine ); + + private: + SyncProcess *mSyncProcess; + QSync::CallbackHandler *mCallbackHandler; + QValueList<MemberItem*> mMemberItems; + + QLabel *mIcon; + QLabel *mGroupName; + QLabel *mStatus; + QLabel *mTime; + KURLLabel *mSyncAction; + KURLLabel *mConfigureAction; + QVBox *mBox; + QProgressBar *mProgressBar; + + int mProcessedItems; + int mMaxProcessedItems; + bool mSynchronizing; +}; + +class MemberItem : public QWidget +{ + public: + MemberItem( QWidget *parent, SyncProcess *syncProcess, + const QSync::Member &member ); + + SyncProcess* syncProcess() const { return mSyncProcess; } + QSync::Member member() const { return mMember; } + + void setStatusMessage( const QString &msg ); + + private: + SyncProcess *mSyncProcess; + QSync::Member mMember; + + QLabel *mIcon; + QLabel *mMemberName; + QLabel *mDescription; + QLabel *mStatus; +}; + +#endif diff --git a/kitchensync/src/groupview.cpp b/kitchensync/src/groupview.cpp new file mode 100644 index 000000000..b0c061e84 --- /dev/null +++ b/kitchensync/src/groupview.cpp @@ -0,0 +1,99 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2005 Cornelius Schumacher <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include <qlayout.h> + +#include "aboutpage.h" +#include "groupitem.h" +#include "syncprocessmanager.h" + +#include "groupview.h" + +GroupView::GroupView( QWidget *parent ) + : QWidget( parent ), mAboutPage( 0 ) +{ + mLayout = new QVBoxLayout( this ); + + mWidgetList = new KWidgetList( this ); + + mLayout->addWidget( mWidgetList ); +} + +SyncProcess* GroupView::selectedSyncProcess() const +{ + GroupItem *item = static_cast<GroupItem*>( mWidgetList->selectedItem() ); + if ( item ) + return item->syncProcess(); + else + return 0; +} + +void GroupView::clear() +{ + mWidgetList->clear(); +} + +void GroupView::updateView() +{ + clear(); + + if ( SyncProcessManager::self()->count() == 0 ) { + mWidgetList->hide(); + + if ( !mAboutPage ) { + mAboutPage = new AboutPage( this ); + mLayout->addWidget( mAboutPage ); + + connect( mAboutPage, SIGNAL( addGroup() ), SIGNAL( addGroup() ) ); + } + + mAboutPage->show(); + + } else { + if ( mAboutPage ) + mAboutPage->hide(); + mWidgetList->show(); + } + + for ( int i = 0; i < SyncProcessManager::self()->count(); ++i ) { + SyncProcess *process = SyncProcessManager::self()->at( i ); + + GroupItem *item = new GroupItem( mWidgetList, process ); + connect( item, SIGNAL( synchronizeGroup( SyncProcess* ) ), + SIGNAL( synchronizeGroup( SyncProcess* ) ) ); + connect( item, SIGNAL( abortSynchronizeGroup( SyncProcess* ) ), + SIGNAL( abortSynchronizeGroup( SyncProcess* ) ) ); + connect( item, SIGNAL( configureGroup( SyncProcess* ) ), + SIGNAL( configureGroup( SyncProcess* ) ) ); + + mWidgetList->appendItem( item ); + } +} + +void GroupView::updateSyncProcess( SyncProcess *syncProcess ) +{ + for ( int i = 0; i < (int)mWidgetList->count(); ++i ) { + GroupItem *item = static_cast<GroupItem*>( mWidgetList->item( i ) ); + if ( item && item->syncProcess() == syncProcess ) + item->update(); + } +} + +#include "groupview.moc" diff --git a/kitchensync/src/groupview.h b/kitchensync/src/groupview.h new file mode 100644 index 000000000..7aba895a1 --- /dev/null +++ b/kitchensync/src/groupview.h @@ -0,0 +1,57 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2005 Cornelius Schumacher <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ +#ifndef GROUPVIEW_H +#define GROUPVIEW_H + +#include <kwidgetlist.h> + +class AboutPage; +class SyncProcess; +class QVBoxLayout; + +class GroupView : public QWidget +{ + Q_OBJECT + + public: + GroupView( QWidget *parent ); + + SyncProcess* selectedSyncProcess() const; + + void clear(); + + public slots: + void updateView(); + void updateSyncProcess( SyncProcess *process ); + + signals: + void addGroup(); + void synchronizeGroup( SyncProcess *syncProcess ); + void abortSynchronizeGroup( SyncProcess *syncProcess ); + void configureGroup( SyncProcess *syncProcess ); + + private: + AboutPage *mAboutPage; + KWidgetList *mWidgetList; + + QVBoxLayout *mLayout; +}; + +#endif diff --git a/kitchensync/src/htmldiffalgodisplay.cpp b/kitchensync/src/htmldiffalgodisplay.cpp new file mode 100644 index 000000000..b3b1bf819 --- /dev/null +++ b/kitchensync/src/htmldiffalgodisplay.cpp @@ -0,0 +1,97 @@ +/* + This file is part of libkdepim. + + Copyright (c) 2004 Tobias Koenig <[email protected]> + + 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 <kglobalsettings.h> + +#include "htmldiffalgodisplay.h" + +using namespace KSync; + +static QString textToHTML( const QString &text ) +{ + return QStyleSheet::convertFromPlainText( text ); +} + +HTMLDiffAlgoDisplay::HTMLDiffAlgoDisplay( QWidget *parent ) + : KTextBrowser( parent ) +{ + setWrapPolicy( QTextEdit::AtWordBoundary ); + setVScrollBarMode( QScrollView::AlwaysOff ); + setHScrollBarMode( QScrollView::AlwaysOff ); +} + +void HTMLDiffAlgoDisplay::begin() +{ + clear(); + mText = ""; + + mText.append( "<html>" ); + mText.append( QString( "<body text=\"%1\" bgcolor=\"%2\">" ) + .arg( KGlobalSettings::textColor().name() ) + .arg( KGlobalSettings::baseColor().name() ) ); + + mText.append( "<center><table>" ); + mText.append( QString( "<tr><th></th><th align=\"center\">%1</th><td> </td><th align=\"center\">%2</th></tr>" ) + .arg( mLeftTitle ) + .arg( mRightTitle ) ); +} + +void HTMLDiffAlgoDisplay::end() +{ + mText.append( "</table></center>" + "</body>" + "</html>" ); + + setText( mText ); +} + +void HTMLDiffAlgoDisplay::setLeftSourceTitle( const QString &title ) +{ + mLeftTitle = title; +} + +void HTMLDiffAlgoDisplay::setRightSourceTitle( const QString &title ) +{ + mRightTitle = title; +} + +void HTMLDiffAlgoDisplay::additionalLeftField( const QString &id, const QString &value ) +{ + mText.append( QString( "<tr><td align=\"right\"><b>%1:</b></td><td bgcolor=\"#9cff83\">%2</td><td></td><td></td></tr>" ) + .arg( id ) + .arg( textToHTML( value ) ) ); +} + +void HTMLDiffAlgoDisplay::additionalRightField( const QString &id, const QString &value ) +{ + mText.append( QString( "<tr><td align=\"right\"><b>%1:</b></td><td></td><td></td><td bgcolor=\"#9cff83\">%2</td></tr>" ) + .arg( id ) + .arg( textToHTML( value ) ) ); +} + +void HTMLDiffAlgoDisplay::conflictField( const QString &id, const QString &leftValue, + const QString &rightValue ) +{ + mText.append( QString( "<tr><td align=\"right\"><b>%1:</b></td><td bgcolor=\"#ff8686\">%2</td><td></td><td bgcolor=\"#ff8686\">%3</td></tr>" ) + .arg( id ) + .arg( textToHTML( leftValue ) ) + .arg( textToHTML( rightValue ) ) ); +} diff --git a/kitchensync/src/htmldiffalgodisplay.h b/kitchensync/src/htmldiffalgodisplay.h new file mode 100644 index 000000000..e35e5eb40 --- /dev/null +++ b/kitchensync/src/htmldiffalgodisplay.h @@ -0,0 +1,54 @@ +/* + This file is part of libkdepim. + + Copyright (c) 2004 Tobias Koenig <[email protected]> + + 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 KSYNC_HTMLDIFFALGODISPLAY_H +#define KSYNC_HTMLDIFFALGODISPLAY_H + +#include <ktextbrowser.h> +#include <libkdepim/diffalgo.h> + +using namespace KPIM; + +namespace KSync { + +class HTMLDiffAlgoDisplay : virtual public DiffAlgoDisplay, public KTextBrowser +{ + public: + HTMLDiffAlgoDisplay( QWidget *parent ); + + void begin(); + void end(); + void setLeftSourceTitle( const QString &title ); + void setRightSourceTitle( const QString &title ); + void additionalLeftField( const QString &id, const QString &value ); + void additionalRightField( const QString &id, const QString &value ); + void conflictField( const QString &id, const QString &leftValue, + const QString &rightValue ); + + private: + QString mLeftTitle; + QString mRightTitle; + QString mText; +}; + +} + +#endif diff --git a/kitchensync/src/kitchensync.desktop b/kitchensync/src/kitchensync.desktop new file mode 100644 index 000000000..e7df319b5 --- /dev/null +++ b/kitchensync/src/kitchensync.desktop @@ -0,0 +1,61 @@ +[Desktop Entry] +Name=KitchenSync +Name[pt]=KitchenSyncFilter +Name[sv]=Kitchensync +GenericName=Synchronization +GenericName[af]=Sinkronisasie +GenericName[bg]=Синхронизация +GenericName[ca]=Sincronització +GenericName[cs]=Synchronizace +GenericName[cy]=Cydamseriad +GenericName[da]=Synkronisering +GenericName[de]=Abgleich +GenericName[el]=Συγχρονισμός +GenericName[eo]=Sinkronigo +GenericName[es]=Sincronización +GenericName[et]=Sünkroniseerimine +GenericName[eu]=Sinkronizazioa +GenericName[fa]=همگامی +GenericName[fi]=Synkronointi +GenericName[fr]=Synchronisation +GenericName[fy]=Syngronisaasje +GenericName[ga]=Sioncrónú +GenericName[gl]=Sincronización +GenericName[he]=סינכרון +GenericName[hu]=Szinkronizáció +GenericName[is]=Samstilling +GenericName[it]=Sincronizzazione +GenericName[ja]=同期 +GenericName[ka]=სინქრონიზაცია +GenericName[kk]=Қадамдастыру +GenericName[km]=ការធ្វើសមកាលកម្ម +GenericName[lt]=Sinchronizacija +GenericName[ms]=Segerakan +GenericName[nb]=Synkronisering +GenericName[nds]=Synkroniseren +GenericName[nl]=Synchronisatie +GenericName[nn]=Synkronisering +GenericName[pl]=Synchronizacja +GenericName[pt]=Sincronização +GenericName[pt_BR]=Gerenciador de Sincronização +GenericName[ru]=Синхронизация +GenericName[sk]=Synchronizácia +GenericName[sl]=Usklajevanje +GenericName[sr]=Синхронизација +GenericName[sr@Latn]=Sinhronizacija +GenericName[sv]=Synkronisering +GenericName[ta]=கூட்டிணைப்பு +GenericName[tr]=Senkronizasyon +GenericName[uk]=Синхронізація +GenericName[zh_CN]=同步 +Exec=kitchensync +Icon=kitchensync +Type=Application +DocPath=kitchensync/index.html +Terminal=false +X-KDE-StartupNotify=true +X-DCOP-ServiceType=Unique +X-DCOP-ServiceName=kitchensync +ServiceTypes=KParts/ReadOnlyPart +X-KDE-Library=libkitchensyncpart +Categories=Qt;KDE;Utility;X-KDE-Utilities-PIM; diff --git a/kitchensync/src/kitchensync_part.rc b/kitchensync/src/kitchensync_part.rc new file mode 100644 index 000000000..03a13ba6b --- /dev/null +++ b/kitchensync/src/kitchensync_part.rc @@ -0,0 +1,22 @@ +<!DOCTYPE kpartgui> +<kpartgui name="kitchensync" version="1"> + <MenuBar> + <Menu name="file"> + <Action name="sync" /> + </Menu> + + <Menu name="groups"><text>&Groups</text> + <Action name="add_group" /> + <Action name="edit_group" /> + <Action name="delete_group" /> + </Menu> + </MenuBar> + + <ToolBar name="mainToolBar"><text>Main</text> + <Action name="sync" /> + <Separator /> + <Action name="add_group" /> + <Action name="edit_group" /> + <Action name="delete_group" /> + </ToolBar> +</kpartgui> diff --git a/kitchensync/src/kitchensyncui.rc b/kitchensync/src/kitchensyncui.rc new file mode 100644 index 000000000..df2e49be0 --- /dev/null +++ b/kitchensync/src/kitchensyncui.rc @@ -0,0 +1,22 @@ +<!DOCTYPE kpartgui> +<kpartgui name="kitchensync" version="2"> + <MenuBar> + <Menu name="file"> + <Action name="sync" /> + </Menu> + + <Menu name="groups"><text>&Groups</text> + <Action name="add_group" /> + <Action name="edit_group" /> + <Action name="delete_group" /> + </Menu> + </MenuBar> + + <ToolBar name="mainToolBar"><text>Main</text> + <Action name="sync" /> + <Separator /> + <Action name="add_group" /> + <Action name="edit_group" /> + <Action name="delete_group" /> + </ToolBar> +</kpartgui> diff --git a/kitchensync/src/kwidgetlist.cpp b/kitchensync/src/kwidgetlist.cpp new file mode 100644 index 000000000..450a719e8 --- /dev/null +++ b/kitchensync/src/kwidgetlist.cpp @@ -0,0 +1,305 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2005 Tobias Koenig <[email protected]> + + 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 <qvbox.h> + +#include <kglobalsettings.h> + +#include "kwidgetlist.h" + +class KWidgetList::Private +{ + public: + Private() + : mSelectedItem( 0 ) + { + } + + QValueList<KWidgetListItem*> mItems; + KWidgetListItem *mSelectedItem; + QVBox *mBox; +}; + +KWidgetList::KWidgetList( QWidget *parent, const char *name ) + : QScrollView( parent, name ), + d( new Private ) +{ + d->mBox = new QVBox( viewport() ); + addChild( d->mBox ); + + setResizePolicy( AutoOneFit ); + setFocusPolicy( QWidget::StrongFocus ); + + viewport()->setFocus(); +} + +KWidgetList::~KWidgetList() +{ + clear(); + + delete d; + d = 0; +} + +uint KWidgetList::count() const +{ + return d->mItems.count(); +} + +void KWidgetList::appendItem( KWidgetListItem *item ) +{ + if ( !item ) + return; + + if ( !d->mItems.contains( item ) ) { + d->mItems.append( item ); + item->reparent( d->mBox, 0, QPoint( 0, 0 ), true ); + item->setSelected( false ); + item->installEventFilter( this ); + + if ( d->mItems.count() == 1 ) { + d->mSelectedItem = item; + } else { + if ( !d->mSelectedItem ) + setSelected( item ); + else + d->mSelectedItem->setSelected( true ); + } + } +} + +void KWidgetList::removeItem( int index ) +{ + if ( index < 0 || index >= (int)d->mItems.count() ) + return; + + KWidgetListItem *item = d->mItems[ index ]; + d->mItems.remove( item ); + + if ( d->mSelectedItem == item ) { + // TODO: smarter selection + if ( !d->mItems.isEmpty() ) + setSelected( d->mItems.first() ); + else + d->mSelectedItem = 0; + } + + delete item; + + if ( d->mItems.count() == 1 ) + d->mItems.first()->setSelected( false ); +} + +void KWidgetList::takeItem( KWidgetListItem *item ) +{ + d->mItems.remove( item ); + item->reparent( 0, 0, QPoint( 0, 0 ) ); + item->removeEventFilter( this ); + item->hide(); + + if ( d->mSelectedItem == item ) { + // TODO: smarter selection + if ( !d->mItems.isEmpty() ) + setSelected( d->mItems.first() ); + else + d->mSelectedItem = 0; + } +} + +void KWidgetList::setSelected( KWidgetListItem *item ) +{ + if ( !item ) + return; + + if ( d->mItems.contains( item ) == 0 ) + return; + + if ( d->mSelectedItem ) + d->mSelectedItem->setSelected( false ); + + item->setSelected( true ); + d->mSelectedItem = item; +} + +void KWidgetList::setSelected( int index ) +{ + setSelected( item( index ) ); +} + +bool KWidgetList::isSelected( KWidgetListItem *item ) const +{ + return ( d->mSelectedItem == item ); +} + +bool KWidgetList::isSelected( int index ) const +{ + return isSelected( item( index ) ); +} + +KWidgetListItem *KWidgetList::selectedItem() const +{ + return d->mSelectedItem; +} + +KWidgetListItem *KWidgetList::item( int index ) const +{ + if ( index < 0 || index >= (int)d->mItems.count() ) + return 0; + else + return d->mItems[ index ]; +} + +int KWidgetList::index( KWidgetListItem *item ) const +{ + return d->mItems.findIndex( item ); +} + +void KWidgetList::clear() +{ + QValueList<KWidgetListItem*>::Iterator it; + for ( it = d->mItems.begin(); it != d->mItems.end(); ++it ) + delete *it; + + d->mItems.clear(); + + d->mSelectedItem = 0; +} + +void KWidgetList::setFocus() +{ + viewport()->setFocus(); +} + +bool KWidgetList::eventFilter( QObject *object, QEvent *event ) +{ + if ( event->type() == QEvent::MouseButtonPress ) { + QMouseEvent *mouseEvent = static_cast<QMouseEvent*>( event ); + if ( mouseEvent->button() & LeftButton ) { + QValueList<KWidgetListItem*>::Iterator it; + for ( it = d->mItems.begin(); it != d->mItems.end(); ++it ) { + if ( *it == object ) { + if ( d->mItems.count() != 1 ) { + setSelected( *it ); + emit selectionChanged( *it ); + } + return true; + } + } + } + } else if ( event->type() == QEvent::MouseButtonDblClick ) { + QValueList<KWidgetListItem*>::Iterator it; + for ( it = d->mItems.begin(); it != d->mItems.end(); ++it ) { + if ( *it == object ) { + if ( d->mItems.count() != 1 ) { + setSelected( *it ); + emit doubleClicked( *it ); + } + return true; + } + } + } else if ( event->type() == QEvent::KeyPress ) { + QKeyEvent *keyEvent = static_cast<QKeyEvent*>( event ); + if ( keyEvent->key() == Qt::Key_Up ) { + if ( d->mSelectedItem == 0 ) { + if ( !d->mItems.isEmpty() ) { + setSelected( d->mItems.first() ); + return true; + } + } + + for ( int i = 0; i < (int)d->mItems.count(); ++i ) { + if ( d->mItems[ i ] == d->mSelectedItem ) { + if ( ( i - 1 ) >= 0 ) { + setSelected( d->mItems[ i - 1 ] ); + return true; + } + } + } + return true; + } else if ( keyEvent->key() == Qt::Key_Down ) { + if ( d->mSelectedItem == 0 ) { + if ( !d->mItems.isEmpty() ) { + setSelected( d->mItems.last() ); + return true; + } + } + + for ( int i = 0; i < (int)d->mItems.count(); ++i ) + if ( d->mItems[ i ] == d->mSelectedItem ) { + if ( ( i + 1 ) < (int)d->mItems.count() ) { + setSelected( d->mItems[ i + 1 ] ); + return true; + } + } + return true; + } + } + + return QScrollView::eventFilter( object, event ); +} + +KWidgetListItem::KWidgetListItem( KWidgetList *parent, const char *name ) + : QWidget( parent, name ) +{ + mForegroundColor = KGlobalSettings::textColor(); + mBackgroundColor = KGlobalSettings::baseColor(); + mSelectionForegroundColor = KGlobalSettings::highlightedTextColor(); + mSelectionBackgroundColor = KGlobalSettings::highlightColor(); + + setFocusPolicy( QWidget::StrongFocus ); +} + +KWidgetListItem::~KWidgetListItem() +{ +} + +void KWidgetListItem::setSelected( bool select ) +{ + if ( select ) { + setPaletteForegroundColor( mSelectionForegroundColor ); + setPaletteBackgroundColor( mSelectionBackgroundColor ); + } else { + setPaletteForegroundColor( mForegroundColor ); + setPaletteBackgroundColor( mBackgroundColor ); + } +} + +void KWidgetListItem::setForegroundColor( const QColor &color ) +{ + mForegroundColor = color; +} + +void KWidgetListItem::setBackgroundColor( const QColor &color ) +{ + mBackgroundColor = color; +} + +void KWidgetListItem::setSelectionForegroundColor( const QColor &color ) +{ + mSelectionForegroundColor = color; +} + +void KWidgetListItem::setSelectionBackgroundColor( const QColor &color ) +{ + mSelectionBackgroundColor = color; +} + +#include "kwidgetlist.moc" diff --git a/kitchensync/src/kwidgetlist.h b/kitchensync/src/kwidgetlist.h new file mode 100644 index 000000000..59567b7d5 --- /dev/null +++ b/kitchensync/src/kwidgetlist.h @@ -0,0 +1,90 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2005 Tobias Koenig <[email protected]> + + 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 KWIDGETLIST_H +#define KWIDGETLIST_H + +#include <qscrollview.h> + +class KWidgetListItem; + +class KWidgetList : public QScrollView +{ + Q_OBJECT + + public: + KWidgetList( QWidget *parent = 0, const char *name = 0 ); + ~KWidgetList(); + + uint count() const; + + void appendItem( KWidgetListItem *item ); + void removeItem( int index ); + void takeItem( KWidgetListItem *item ); + + void setSelected( KWidgetListItem *item ); + void setSelected( int index ); + + bool isSelected( KWidgetListItem *item ) const; + bool isSelected( int index ) const; + + KWidgetListItem *selectedItem() const; + KWidgetListItem *item( int index ) const; + + int index( KWidgetListItem *item ) const; + + virtual bool eventFilter( QObject *object, QEvent *event ); + + public slots: + void clear(); + virtual void setFocus(); + + signals: + void selectionChanged( KWidgetListItem *item ); + void doubleClicked( KWidgetListItem *item ); + + private: + class Private; + Private *d; +}; + +class KWidgetListItem : public QWidget +{ + public: + KWidgetListItem( KWidgetList *parent, const char *name = 0 ); + ~KWidgetListItem(); + + void setSelected( bool selected ); + + protected: + void setForegroundColor( const QColor& ); + void setBackgroundColor( const QColor& ); + void setSelectionForegroundColor( const QColor& ); + void setSelectionBackgroundColor( const QColor& ); + + private: + QColor mForegroundColor; + QColor mBackgroundColor; + QColor mSelectionForegroundColor; + QColor mSelectionBackgroundColor; +}; + +#endif diff --git a/kitchensync/src/main.cpp b/kitchensync/src/main.cpp new file mode 100644 index 000000000..e93ad26e7 --- /dev/null +++ b/kitchensync/src/main.cpp @@ -0,0 +1,58 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2005 Tobias Koenig <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include <kdebug.h> +#include <kaboutdata.h> +#include <kcmdlineargs.h> +#include <kuniqueapplication.h> +#include <stdlib.h> + +#include "mainwidget.h" +#include "mainwindow.h" + +static KCmdLineOptions options[] = +{ + KCmdLineLastOption +}; + +int main( int argc, char **argv ) +{ + KAboutData *about = MainWidget::aboutData(); + + KCmdLineArgs::init( argc, argv, about ); + KCmdLineArgs::addCmdLineOptions( options ); + KUniqueApplication::addCmdLineOptions(); + + KUniqueApplication::addCmdLineOptions(); + + if( !KUniqueApplication::start() ) { + kdDebug() << "kitchensync already runs." << endl; + exit( 0 ); + }; + + KUniqueApplication app; + + KGlobal::locale()->insertCatalogue( "libkcal" ); + + MainWindow *mainWindow = new MainWindow; + mainWindow->show(); + + app.exec(); +} diff --git a/kitchensync/src/mainwidget.cpp b/kitchensync/src/mainwidget.cpp new file mode 100644 index 000000000..683436364 --- /dev/null +++ b/kitchensync/src/mainwidget.cpp @@ -0,0 +1,191 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2005 Tobias Koenig <[email protected]> + Copyright (c) 2005 Cornelius Schumacher <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "mainwidget.h" + +#include "groupconfigdialog.h" +#include "groupview.h" +#include "syncprocess.h" +#include "syncprocessmanager.h" + +#include <libqopensync/environment.h> + +#include <kaboutdata.h> +#include <kaction.h> +#include <kdebug.h> +#include <kinputdialog.h> +#include <klistview.h> +#include <klocale.h> +#include <kmessagebox.h> +#include <kstdaction.h> +#include <kxmlguiclient.h> + +#include <qlayout.h> + +MainWidget::MainWidget( KXMLGUIClient *guiClient, QWidget *widget, const char *name ) + : QWidget( widget, name ), mGUIClient( guiClient ) +{ + initGUI(); + initActions(); + + /** apply object type filter hack **/ + int count = SyncProcessManager::self()->count(); + for ( int i = 0; i < count; ++i ) { + SyncProcessManager::self()->at( i )->applyObjectTypeFilter(); + } + /** apply object type filter hack **/ + + mGroupView->updateView(); + + connect( SyncProcessManager::self(), SIGNAL( changed() ), + mGroupView, SLOT( updateView() ) ); + connect( SyncProcessManager::self(), SIGNAL( syncProcessChanged( SyncProcess* ) ), + mGroupView, SLOT( updateSyncProcess( SyncProcess* ) ) ); + + enableActions(); +} + +MainWidget::~MainWidget() +{ +} + +KXMLGUIClient *MainWidget::guiClient() const +{ + return mGUIClient; +} + +KAboutData *MainWidget::aboutData() +{ + KAboutData *about = new KAboutData( "kitchensync", I18N_NOOP( "KitchenSync" ), + "0.1", I18N_NOOP( "The KDE Syncing Application" ), + KAboutData::License_GPL_V2, + I18N_NOOP( "(c) 2005, The KDE PIM Team" ) ); + about->addAuthor( "Tobias Koenig", I18N_NOOP( "Current maintainer" ), "[email protected]" ); + about->addAuthor( "Cornelius Schumacher", 0, "[email protected]" ); + + return about; +} + +void MainWidget::initGUI() +{ + QVBoxLayout *topLayout = new QVBoxLayout( this ); + + mGroupView = new GroupView( this ); + topLayout->addWidget( mGroupView ); + + connect( mGroupView, SIGNAL( addGroup() ), SLOT( addGroup() ) ); + connect( mGroupView, SIGNAL( synchronizeGroup( SyncProcess* ) ), + SLOT( sync( SyncProcess* ) ) ); + connect( mGroupView, SIGNAL( abortSynchronizeGroup( SyncProcess* ) ), + SLOT( abortSync( SyncProcess* ) ) ); + connect( mGroupView, SIGNAL( configureGroup( SyncProcess* ) ), + SLOT( editGroup( SyncProcess* ) ) ); +} + +void MainWidget::initActions() +{ + mActionSynchronize = new KAction( i18n("Synchronize"), "hotsync", 0, this, SLOT( sync() ), + mGUIClient->actionCollection(), "sync" ); + mActionAddGroup = new KAction( i18n("Add Group..."), "filenew", 0, this, SLOT( addGroup() ), + mGUIClient->actionCollection(), "add_group" ); + mActionDeleteGroup = new KAction( i18n("Delete Group..."), "editdelete", 0, this, SLOT( deleteGroup() ), + mGUIClient->actionCollection(), "delete_group" ); + mActionEditGroup = new KAction( i18n("Edit Group..."), "edit", 0, this, SLOT( editGroup() ), + mGUIClient->actionCollection(), "edit_group" ); +} + +void MainWidget::enableActions() +{ + bool state = ( SyncProcessManager::self()->count() > 0 ); + + mActionSynchronize->setEnabled( state ); + mActionDeleteGroup->setEnabled( state ); + mActionEditGroup->setEnabled( state ); +} + +void MainWidget::addGroup() +{ + bool ok; + QString name = KInputDialog::getText( i18n("Create Synchronization Group"), + i18n("Name for new synchronization group."), QString::null, &ok, this ); + if ( ok ) { + SyncProcessManager::self()->addGroup( name ); + enableActions(); + + SyncProcess *process = SyncProcessManager::self()->byGroupName( name ); + if ( process ) + editGroup( process ); + } +} + +void MainWidget::deleteGroup() +{ + SyncProcess *syncProcess = mGroupView->selectedSyncProcess(); + if ( syncProcess ) { + int result = KMessageBox::warningContinueCancel( this, + i18n("Delete synchronization group '%1'?").arg( syncProcess->group().name() ) ); + if ( result == KMessageBox::Continue ) { + SyncProcessManager::self()->remove( syncProcess ); + enableActions(); + } + } +} + +void MainWidget::editGroup() +{ + editGroup( mGroupView->selectedSyncProcess() ); +} + +void MainWidget::editGroup( SyncProcess *syncProcess ) +{ + if ( syncProcess ) { + GroupConfigDialog dlg( this, syncProcess ); + dlg.exec(); + + enableActions(); + } +} + +void MainWidget::sync() +{ + sync( mGroupView->selectedSyncProcess() ); +} + +void MainWidget::sync( SyncProcess *syncProcess ) +{ + if ( syncProcess ) { + syncProcess->reinitEngine(); + QSync::Result result = syncProcess->engine()->synchronize(); + if ( result ) { + qDebug( "%s", result.message().latin1() ); + } else { + qDebug( "synchronization worked" ); + } + } +} + +void MainWidget::abortSync( SyncProcess *syncProcess ) +{ + if ( syncProcess ) + syncProcess->engine()->abort(); +} + +#include "mainwidget.moc" diff --git a/kitchensync/src/mainwidget.h b/kitchensync/src/mainwidget.h new file mode 100644 index 000000000..3bbfcb5cd --- /dev/null +++ b/kitchensync/src/mainwidget.h @@ -0,0 +1,73 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2005 Tobias Koenig <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ +#ifndef MAINWIDGET_H +#define MAINWIDGET_H + +#include <libqopensync/engine.h> +#include <kdemacros.h> + +#include <qwidget.h> + +class KAboutData; +class KAction; +class KXMLGUIClient; +class GroupView; +class SyncProcess; +class SyncProcessManager; + +namespace QSync { +class Environment; +} + +class KDE_EXPORT MainWidget : public QWidget +{ + Q_OBJECT + public: + MainWidget( KXMLGUIClient *guiClient, QWidget *widget = 0, const char *name = 0 ); + ~MainWidget(); + + virtual KXMLGUIClient *guiClient() const; + static KAboutData *aboutData(); + + public slots: + void addGroup(); + void deleteGroup(); + void editGroup(); + void editGroup( SyncProcess *syncProcess ); + + void sync(); + void sync( SyncProcess *syncProcess ); + void abortSync( SyncProcess *syncProcess ); + + private: + void initGUI(); + void initActions(); + void enableActions(); + + KXMLGUIClient *mGUIClient; + KAction *mActionSynchronize; + KAction *mActionAddGroup; + KAction *mActionDeleteGroup; + KAction *mActionEditGroup; + + GroupView *mGroupView; +}; + +#endif diff --git a/kitchensync/src/mainwindow.cpp b/kitchensync/src/mainwindow.cpp new file mode 100644 index 000000000..2426b11dc --- /dev/null +++ b/kitchensync/src/mainwindow.cpp @@ -0,0 +1,61 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2005 Tobias Koenig <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include <kaction.h> +#include <klocale.h> +#include <kstdaction.h> +#include <ktoolbar.h> + +#include "mainwidget.h" + +#include "mainwindow.h" + +MainWindow::MainWindow() + : KMainWindow( 0 ) +{ + setWFlags( getWFlags() | WGroupLeader ); + + setCaption( i18n( "PIM Synchronization" ) ); + + mWidget = new MainWidget( this, this, "MainWidget" ); + + setCentralWidget( mWidget ); + + initActions(); + + createGUI( "kitchensyncui.rc", false ); + createGUI( 0 ); + + toolBar()->setIconText( KToolBar::IconTextBottom ); + + resize( 760, 530 ); // initial size + setAutoSaveSettings(); +} + +MainWindow::~MainWindow() +{ +} + +void MainWindow::initActions() +{ + KStdAction::quit( this, SLOT( close() ), actionCollection() ); +} + +#include "mainwindow.moc" diff --git a/kitchensync/src/mainwindow.h b/kitchensync/src/mainwindow.h new file mode 100644 index 000000000..653227181 --- /dev/null +++ b/kitchensync/src/mainwindow.h @@ -0,0 +1,46 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2005 Tobias Koenig <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include <kmainwindow.h> + +class MainWidget; + +/** + This class serves as the main window for Kitchensync. It handles the + menus, toolbars, and status bars. + */ +class MainWindow : public KMainWindow +{ + Q_OBJECT + + public: + MainWindow(); + virtual ~MainWindow(); + + private: + void initActions(); + + MainWidget *mWidget; +}; + +#endif diff --git a/kitchensync/src/memberconfig.cpp b/kitchensync/src/memberconfig.cpp new file mode 100644 index 000000000..932830cd8 --- /dev/null +++ b/kitchensync/src/memberconfig.cpp @@ -0,0 +1,79 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2005 Cornelius Schumacher <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "memberconfig.h" + +#include "configgui.h" +#include "memberinfo.h" + +#include <klocale.h> +#include <kmessagebox.h> + +#include <qlabel.h> +#include <qlayout.h> +#include <qtabwidget.h> + +MemberConfig::MemberConfig( QWidget *parent, const QSync::Member &member ) + : QWidget( parent ), mMember( member ) +{ + QBoxLayout *topLayout = new QVBoxLayout( this ); + + mGui = ConfigGui::Factory::create( member, this ); + topLayout->addWidget( mGui ); +} + +MemberConfig::~MemberConfig() +{ +} + +void MemberConfig::loadData() +{ + QByteArray cfg; + QSync::Result error = mMember.configuration( cfg ); + + if ( error ) { + KMessageBox::error( this, + i18n("Unable to read config from plugin '%1':\n%2") + .arg( mMember.pluginName() ).arg( error.message() ) ); + } else { + QString txt = QString::fromUtf8( cfg.data(), cfg.size() ); + mGui->load( txt ); + MemberInfo mi( mMember ); + mGui->setInstanceName( mi.name() ); + } +} + +void MemberConfig::saveData() +{ + QString txt = mGui->save(); + + if ( txt.isEmpty() ) { + KMessageBox::sorry( this, i18n("Configuration of %1 is empty.").arg( mMember.pluginName() ) ); + } else { + QByteArray cfg = txt.utf8(); + cfg.truncate(cfg.size() - 1); /* discard NUL terminator */ + mMember.setConfiguration( cfg ); + mMember.setName( mGui->instanceName() ); + // TODO: Check for save() error. + mMember.save(); + } +} + +#include "memberconfig.moc" diff --git a/kitchensync/src/memberconfig.h b/kitchensync/src/memberconfig.h new file mode 100644 index 000000000..5bb46b8ff --- /dev/null +++ b/kitchensync/src/memberconfig.h @@ -0,0 +1,47 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2005 Cornelius Schumacher <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ +#ifndef MEMBERCONFIG_H +#define MEMBERCONFIG_H + +#include <libqopensync/member.h> + +#include <qwidget.h> + +class QTextEdit; +class ConfigGui; + +class MemberConfig : public QWidget +{ + Q_OBJECT + + public: + MemberConfig( QWidget *parent, const QSync::Member & ); + ~MemberConfig(); + + void loadData(); + void saveData(); + + private: + QSync::Member mMember; + + ConfigGui *mGui; +}; + +#endif diff --git a/kitchensync/src/memberinfo.cpp b/kitchensync/src/memberinfo.cpp new file mode 100644 index 000000000..be43991fd --- /dev/null +++ b/kitchensync/src/memberinfo.cpp @@ -0,0 +1,99 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2005 Cornelius Schumacher <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#include "memberinfo.h" + +#include <kglobal.h> +#include <kiconloader.h> +#include <klocale.h> + +MemberInfo::MemberInfo( const QSync::Member &member ) + : mMember( member ) +{ +} + +QPixmap MemberInfo::smallIcon() const +{ + return KGlobal::iconLoader()->loadIcon( iconName(), KIcon::Small ); +} + +QPixmap MemberInfo::desktopIcon() const +{ + return KGlobal::iconLoader()->loadIcon( iconName(), KIcon::Desktop ); +} + +QString MemberInfo::iconName() const +{ + return pluginIconName( mMember.pluginName() ); +} + +QString MemberInfo::name() const +{ + static QMap<QString, QString> nameMap; + if ( nameMap.isEmpty() ) { + nameMap.insert( "file-sync", i18n( "File" ) ); + nameMap.insert( "palm-sync", i18n( "Palm" ) ); + nameMap.insert( "kdepim-sync", i18n( "KDE PIM" ) ); + nameMap.insert( "kio-sync", i18n( "Remote File" ) ); + nameMap.insert( "irmc-sync", i18n( "Mobile Phone" ) ); + nameMap.insert( "evo2-sync", i18n( "Evolution" ) ); + nameMap.insert( "opie-sync", i18n( "Handheld" ) ); + nameMap.insert( "ldap-sync", i18n( "LDAP" ) ); + nameMap.insert( "syncml-obex-client", i18n( "Mobile Phone" ) ); + nameMap.insert( "syncml-http-server", i18n( "Mobile Phone" ) ); + nameMap.insert( "moto-sync", i18n( "Mobile Phone" ) ); + nameMap.insert( "gnokii-sync", i18n( "Mobile Phone" ) ); + nameMap.insert( "google-calendar", i18n( "Google Calendar" ) ); + nameMap.insert( "gpe-sync", i18n( "Handheld" ) ); + nameMap.insert( "sunbird-sync", i18n( "Sunbird Calendar" ) ); + nameMap.insert( "jescs-sync", i18n( "Java Enterprise System Calendar" ) ); + nameMap.insert( "synce-plugin", i18n( "WinCE Devices" ) ); + } + + if ( mMember.name().isEmpty() ) + return nameMap[ mMember.pluginName() ] + " (" + QString::number( mMember.id() ) + ") "; + else + return mMember.name(); +} + +QString MemberInfo::pluginIconName( const QString &pluginName ) +{ + if ( pluginName == "file-sync" ) return "folder"; + if ( pluginName == "palm-sync" ) return "pda_black"; + if ( pluginName == "kdepim-sync" ) return "kontact"; + if ( pluginName == "kio-sync" ) return "network"; + if ( pluginName == "irmc-sync" ) return "mobile_phone"; + if ( pluginName == "evo2-sync" ) return "evolution"; + if ( pluginName == "opie-sync" ) return "pda_blue"; + if ( pluginName == "synce-plugin" ) return "pda_blue"; + if ( pluginName == "ldap-sync" ) return "contents2"; + if ( pluginName == "syncml-obex-client" ) return "mobile_phone"; + if ( pluginName == "syncml-http-server" ) return "pda_blue"; + if ( pluginName == "moto-sync" ) return "mobile_phone"; + if ( pluginName == "gnokii-sync" ) return "mobile_phone"; + if ( pluginName == "google-calendar" ) return "www"; + if ( pluginName == "gpe-sync" ) return "pda_blue"; + if ( pluginName == "sunbird-sync" ) return "www"; + if ( pluginName == "jescs-sync" ) return "www"; + + + return QString::null; +} diff --git a/kitchensync/src/memberinfo.h b/kitchensync/src/memberinfo.h new file mode 100644 index 000000000..2ec35cfaa --- /dev/null +++ b/kitchensync/src/memberinfo.h @@ -0,0 +1,47 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2005 Cornelius Schumacher <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ +#ifndef MEMBERINFO_H +#define MEMBERINFO_H + +#include <libqopensync/member.h> + +#include <qstring.h> +#include <qpixmap.h> + +class MemberInfo +{ + public: + MemberInfo( const QSync::Member &member ); + + QPixmap smallIcon() const; + QPixmap desktopIcon() const; + + QString iconName() const; + + QString name() const; + + static QString pluginIconName( const QString &pluginName ); + + private: + QSync::Member mMember; +}; + +#endif diff --git a/kitchensync/src/multiconflictdialog.cpp b/kitchensync/src/multiconflictdialog.cpp new file mode 100644 index 000000000..996ef08af --- /dev/null +++ b/kitchensync/src/multiconflictdialog.cpp @@ -0,0 +1,141 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2005 Tobias Koenig <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include <kdialog.h> +#include <klocale.h> +#include <kwidgetlist.h> + +#include <qlabel.h> +#include <qlayout.h> +#include <qpushbutton.h> + +#include "memberinfo.h" + +#include "multiconflictdialog.h" + +class ChangeItem : public KWidgetListItem +{ + public: + ChangeItem( KWidgetList *parent, const QSync::SyncChange &change ) + : KWidgetListItem( parent ), + mChange( change ) + { + QGridLayout *layout = new QGridLayout( this, 2, 1, KDialog::marginHint(), KDialog::spacingHint() ); + + MemberInfo mi( change.member() ); + layout->addWidget( new QLabel( mi.name(), this ), 0, 0 ); + + QString type; + switch ( change.changeType() ) { + case QSync::SyncChange::UnknownChange: + type = i18n( "Unknown" ); + break; + case QSync::SyncChange::AddedChange: + type = i18n( "Added" ); + break; + case QSync::SyncChange::DeletedChange: + type = i18n( "Deleted" ); + break; + case QSync::SyncChange::ModifiedChange: + type = i18n( "Modified" ); + break; + case QSync::SyncChange::UnmodifiedChange: + default: + type = i18n( "Unmodified" ); + break; + } + + layout->addWidget( new QLabel( type, this ), 1, 0 ); + } + + QSync::SyncChange change() const { return mChange; } + + private: + QSync::SyncChange mChange; +}; + +MultiConflictDialog::MultiConflictDialog( QSync::SyncMapping &mapping, QWidget *parent ) + : ConflictDialog( mapping, parent ) +{ + initGUI(); + + for ( int i = 0; i < mMapping.changesCount(); ++i ) { + QSync::SyncChange change = mMapping.changeAt( i ); + if ( change.isValid() ) { + ChangeItem *item = new ChangeItem( mWidgetList, change ); + mWidgetList->appendItem( item ); + } + } + + mWidgetList->setFocus(); +} + +MultiConflictDialog::~MultiConflictDialog() +{ +} + +void MultiConflictDialog::useSelectedChange() +{ + ChangeItem *item = static_cast<ChangeItem*>( mWidgetList->selectedItem() ); + if ( !item ) + return; + + mMapping.solve( item->change() ); + + accept(); +} + +void MultiConflictDialog::duplicateChange() +{ + mMapping.duplicate(); + + accept(); +} + +void MultiConflictDialog::ignoreChange() +{ + mMapping.ignore(); + + accept(); +} + +void MultiConflictDialog::initGUI() +{ + QGridLayout *layout = new QGridLayout( this, 3, 3, KDialog::marginHint(), KDialog::spacingHint() ); + + layout->addMultiCellWidget( new QLabel( i18n( "A conflict has appeared, please solve it manually." ), this ), 0, 0, 0, 2 ); + + mWidgetList = new KWidgetList( this ); + layout->addMultiCellWidget( mWidgetList, 1, 1, 0, 2 ); + + QPushButton *button = new QPushButton( i18n( "Use Selected Item" ), this ); + connect( button, SIGNAL( clicked() ), SLOT( useSelectedChange() ) ); + layout->addWidget( button, 2, 0 ); + + button = new QPushButton( i18n( "Duplicate Items" ), this ); + connect( button, SIGNAL( clicked() ), SLOT( duplicateChange() ) ); + layout->addWidget( button, 2, 1 ); + + button = new QPushButton( i18n( "Ignore Conflict" ), this ); + connect( button, SIGNAL( clicked() ), SLOT( ignoreChange() ) ); + layout->addWidget( button, 2, 2 ); +} + +#include "multiconflictdialog.moc" diff --git a/kitchensync/src/multiconflictdialog.h b/kitchensync/src/multiconflictdialog.h new file mode 100644 index 000000000..d98fb927b --- /dev/null +++ b/kitchensync/src/multiconflictdialog.h @@ -0,0 +1,47 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2005 Tobias Koenig <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef MULTICONFLICTDIALOG_H +#define MULTICONFLICTDIALOG_H + +#include "conflictdialog.h" + +class KWidgetList; + +class MultiConflictDialog : public ConflictDialog +{ + Q_OBJECT + + public: + MultiConflictDialog( QSync::SyncMapping &mapping, QWidget *parent ); + ~MultiConflictDialog(); + + private slots: + void useSelectedChange(); + void duplicateChange(); + void ignoreChange(); + + private: + void initGUI(); + + KWidgetList *mWidgetList; +}; + +#endif diff --git a/kitchensync/src/part.cpp b/kitchensync/src/part.cpp new file mode 100644 index 000000000..e0d65cf40 --- /dev/null +++ b/kitchensync/src/part.cpp @@ -0,0 +1,89 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2005 Tobias Koenig <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include <qlayout.h> +#include <qvbox.h> + +#include <kaction.h> +#include <kapplication.h> +#include <kdebug.h> +#include <kiconloader.h> +#include <kinstance.h> +#include <klocale.h> +#include <kparts/genericfactory.h> + +#include "mainwidget.h" + +#include "part.h" + +typedef KParts::GenericFactory< KitchenSyncPart > KitchenSyncFactory; +K_EXPORT_COMPONENT_FACTORY( libkitchensyncpart, KitchenSyncFactory ) + +KitchenSyncPart::KitchenSyncPart( QWidget *parentWidget, const char *widgetName, + QObject *parent, const char *name, + const QStringList& ) + : KParts::ReadOnlyPart( parent, name ) +{ + setInstance( KitchenSyncFactory::instance() ); + + QVBox *canvas = new QVBox( parentWidget, widgetName ); + setWidget( canvas ); + + new MainWidget( this, canvas ); + + KGlobal::iconLoader()->addAppDir( "kitchensync" ); + + setXMLFile( "kitchensync_part.rc" ); +} + +KitchenSyncPart::~KitchenSyncPart() +{ + closeURL(); +} + +KAboutData *KitchenSyncPart::createAboutData() +{ + return MainWidget::aboutData(); +} + +void KitchenSyncPart::exit() +{ + delete this; +} + +bool KitchenSyncPart::openURL( const KURL &url ) +{ + emit setWindowCaption( url.prettyURL() ); + + return true; +} + +bool KitchenSyncPart::openFile() +{ + return true; +} + +void KitchenSyncPart::guiActivateEvent( KParts::GUIActivateEvent *e ) +{ + KParts::ReadOnlyPart::guiActivateEvent( e ); +} + +#include "part.moc" + diff --git a/kitchensync/src/part.h b/kitchensync/src/part.h new file mode 100644 index 000000000..f51ddd158 --- /dev/null +++ b/kitchensync/src/part.h @@ -0,0 +1,49 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2005 Tobias Koenig <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef PART_H +#define PART_H + +#include <kparts/event.h> +#include <kparts/factory.h> +#include <kparts/part.h> + +class KAboutData; + +class KitchenSyncPart: public KParts::ReadOnlyPart +{ + Q_OBJECT + + public: + KitchenSyncPart( QWidget *parentWidget, const char *widgetName, + QObject *parent, const char *name, const QStringList& ); + virtual ~KitchenSyncPart(); + + static KAboutData *createAboutData(); + + virtual void exit(); + virtual bool openURL( const KURL &url ); + + protected: + virtual bool openFile(); + virtual void guiActivateEvent( KParts::GUIActivateEvent* ); +}; + +#endif diff --git a/kitchensync/src/pics/Makefile.am b/kitchensync/src/pics/Makefile.am new file mode 100644 index 000000000..ddb7cc451 --- /dev/null +++ b/kitchensync/src/pics/Makefile.am @@ -0,0 +1,4 @@ +kitchensyncicondir = $(kde_datadir)/kitchensync/icons +kitchensyncicon_ICON = hotsync mobile_phone + +KDE_ICON = kitchensync diff --git a/kitchensync/src/pics/cr128-app-mobile_phone.png b/kitchensync/src/pics/cr128-app-mobile_phone.png Binary files differnew file mode 100644 index 000000000..732327e2b --- /dev/null +++ b/kitchensync/src/pics/cr128-app-mobile_phone.png diff --git a/kitchensync/src/pics/cr16-action-hotsync.png b/kitchensync/src/pics/cr16-action-hotsync.png Binary files differnew file mode 100644 index 000000000..bdcaf824e --- /dev/null +++ b/kitchensync/src/pics/cr16-action-hotsync.png diff --git a/kitchensync/src/pics/cr16-app-mobile_phone.png b/kitchensync/src/pics/cr16-app-mobile_phone.png Binary files differnew file mode 100644 index 000000000..3bfa3627c --- /dev/null +++ b/kitchensync/src/pics/cr16-app-mobile_phone.png diff --git a/kitchensync/src/pics/cr22-action-hotsync.png b/kitchensync/src/pics/cr22-action-hotsync.png Binary files differnew file mode 100644 index 000000000..11eceb43b --- /dev/null +++ b/kitchensync/src/pics/cr22-action-hotsync.png diff --git a/kitchensync/src/pics/cr32-action-hotsync.png b/kitchensync/src/pics/cr32-action-hotsync.png Binary files differnew file mode 100644 index 000000000..8316a1612 --- /dev/null +++ b/kitchensync/src/pics/cr32-action-hotsync.png diff --git a/kitchensync/src/pics/cr32-app-mobile_phone.png b/kitchensync/src/pics/cr32-app-mobile_phone.png Binary files differnew file mode 100644 index 000000000..161108041 --- /dev/null +++ b/kitchensync/src/pics/cr32-app-mobile_phone.png diff --git a/kitchensync/src/pics/cr48-action-hotsync.png b/kitchensync/src/pics/cr48-action-hotsync.png Binary files differnew file mode 100644 index 000000000..dfc98ff41 --- /dev/null +++ b/kitchensync/src/pics/cr48-action-hotsync.png diff --git a/kitchensync/src/pics/cr48-app-mobile_phone.png b/kitchensync/src/pics/cr48-app-mobile_phone.png Binary files differnew file mode 100644 index 000000000..82049813d --- /dev/null +++ b/kitchensync/src/pics/cr48-app-mobile_phone.png diff --git a/kitchensync/src/pics/cr64-app-mobile_phone.png b/kitchensync/src/pics/cr64-app-mobile_phone.png Binary files differnew file mode 100644 index 000000000..527771f73 --- /dev/null +++ b/kitchensync/src/pics/cr64-app-mobile_phone.png diff --git a/kitchensync/src/pics/hi16-app-kitchensync.png b/kitchensync/src/pics/hi16-app-kitchensync.png Binary files differnew file mode 100644 index 000000000..bdcaf824e --- /dev/null +++ b/kitchensync/src/pics/hi16-app-kitchensync.png diff --git a/kitchensync/src/pics/hi22-app-kitchensync.png b/kitchensync/src/pics/hi22-app-kitchensync.png Binary files differnew file mode 100644 index 000000000..11eceb43b --- /dev/null +++ b/kitchensync/src/pics/hi22-app-kitchensync.png diff --git a/kitchensync/src/pics/hi32-app-kitchensync.png b/kitchensync/src/pics/hi32-app-kitchensync.png Binary files differnew file mode 100644 index 000000000..8316a1612 --- /dev/null +++ b/kitchensync/src/pics/hi32-app-kitchensync.png diff --git a/kitchensync/src/pics/hi48-app-kitchensync.png b/kitchensync/src/pics/hi48-app-kitchensync.png Binary files differnew file mode 100644 index 000000000..dfc98ff41 --- /dev/null +++ b/kitchensync/src/pics/hi48-app-kitchensync.png diff --git a/kitchensync/src/pluginpicker.cpp b/kitchensync/src/pluginpicker.cpp new file mode 100644 index 000000000..5fe4b5e81 --- /dev/null +++ b/kitchensync/src/pluginpicker.cpp @@ -0,0 +1,136 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2005 Cornelius Schumacher <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#include "pluginpicker.h" + +#include "memberinfo.h" +#include "syncprocessmanager.h" + +#include <libqopensync/environment.h> + +#include <kdialog.h> +#include <kglobal.h> +#include <kiconloader.h> +#include <klocale.h> + +#include <qlabel.h> +#include <qlayout.h> + +PluginItem::PluginItem( KWidgetList *list, const QSync::Plugin &plugin ) + : KWidgetListItem( list ), mPlugin( plugin ) +{ + QString iconName = MemberInfo::pluginIconName( mPlugin.name() ); + QGridLayout *layout = new QGridLayout( this, 2, 2, KDialog::marginHint(), KDialog::spacingHint() ); + + QLabel *icon = new QLabel( this ); + icon->setPixmap( KGlobal::iconLoader()->loadIcon( iconName, KIcon::Desktop ) ); + icon->setFixedSize( icon->sizeHint() ); + + QLabel *name = new QLabel( plugin.longName(), this ); + QLabel *description = new QLabel( plugin.description(), this ); + + QFont font = name->font(); + font.setBold( true ); + name->setFont( font ); + + layout->addWidget( icon, 0, 0 ); + layout->addWidget( name, 0, 1 ); + layout->addWidget( description, 1, 1 ); +} + + +PluginPicker::PluginPicker( QWidget *parent ) + : QWidget( parent ) +{ + QBoxLayout *layout = new QVBoxLayout( this ); + + mPluginList = new KWidgetList( this ); + layout->addWidget( mPluginList ); + + connect( mPluginList, SIGNAL( doubleClicked( KWidgetListItem* ) ), + SIGNAL( selected() ) ); + + updatePluginList(); + + mPluginList->setFocus(); +} + +void PluginPicker::updatePluginList() +{ + mPluginList->clear(); + + QSync::Environment *env = SyncProcessManager::self()->environment(); + + QSync::Environment::PluginIterator it( env->pluginBegin() ); + for( ; it != env->pluginEnd(); ++it ) { + QSync::Plugin plugin = *it; + mPluginList->appendItem( new PluginItem( mPluginList, plugin ) ); + } +} + +QSync::Plugin PluginPicker::selectedPlugin() const +{ + PluginItem *item = static_cast<PluginItem *>( mPluginList->selectedItem() ); + if ( item ) return item->plugin(); + else return QSync::Plugin(); +} + + +PluginPickerDialog::PluginPickerDialog( QWidget *parent ) + : KDialogBase( parent, 0, true, i18n("Select Member Type"), Ok | Cancel ) +{ + QFrame *topFrame = makeMainWidget(); + + QBoxLayout *topLayout = new QVBoxLayout( topFrame ); + + mPicker = new PluginPicker( topFrame ); + topLayout->addWidget( mPicker ); + + connect( mPicker, SIGNAL( selected() ), SLOT( slotOk() ) ); + + setInitialSize( QSize( 460, 380 ) ); +} + +QSync::Plugin PluginPickerDialog::selectedPlugin() const +{ + return mPicker->selectedPlugin(); +} + +QSync::Plugin PluginPickerDialog::getPlugin( QWidget *parent ) +{ + PluginPickerDialog dlg( parent ); + if ( dlg.exec() ) + return dlg.selectedPlugin(); + else + return QSync::Plugin(); +} + +void PluginPickerDialog::slotOk() +{ + accept(); +} + +void PluginPickerDialog::slotCancel() +{ + reject(); +} + +#include "pluginpicker.moc" diff --git a/kitchensync/src/pluginpicker.h b/kitchensync/src/pluginpicker.h new file mode 100644 index 000000000..39630f448 --- /dev/null +++ b/kitchensync/src/pluginpicker.h @@ -0,0 +1,80 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2005 Cornelius Schumacher <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ +#ifndef PLUGINPICKER_H +#define PLUGINPICKER_H + +#include <libqopensync/plugin.h> + +#include <kdialogbase.h> +#include <kwidgetlist.h> + +#include <qwidget.h> + +class PluginItem : public KWidgetListItem +{ + public: + PluginItem( KWidgetList *, const QSync::Plugin & ); + + QSync::Plugin plugin() const { return mPlugin; } + + private: + QSync::Plugin mPlugin; +}; + +class PluginPicker : public QWidget +{ + Q_OBJECT + + public: + PluginPicker( QWidget *parent ); + + QSync::Plugin selectedPlugin() const; + + signals: + void selected(); + + protected: + void updatePluginList(); + + private: + KWidgetList *mPluginList; +}; + +class PluginPickerDialog : public KDialogBase +{ + Q_OBJECT + + public: + PluginPickerDialog( QWidget *parent ); + + QSync::Plugin selectedPlugin() const; + + static QSync::Plugin getPlugin( QWidget *parent ); + + protected slots: + void slotOk(); + void slotCancel(); + + private: + PluginPicker *mPicker; +}; + +#endif diff --git a/kitchensync/src/singleconflictdialog.cpp b/kitchensync/src/singleconflictdialog.cpp new file mode 100644 index 000000000..53acba799 --- /dev/null +++ b/kitchensync/src/singleconflictdialog.cpp @@ -0,0 +1,123 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2005 Tobias Koenig <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include <kdialog.h> +#include <klocale.h> + +#include <qlabel.h> +#include <qlayout.h> +#include <qpushbutton.h> + +#include "addresseediffalgo.h" +#include "genericdiffalgo.h" +#include "htmldiffalgodisplay.h" +#include "memberinfo.h" + +#include "singleconflictdialog.h" + +SingleConflictDialog::SingleConflictDialog( QSync::SyncMapping &mapping, QWidget *parent ) + : ConflictDialog( mapping, parent ), mDiffAlgo( 0 ) +{ + initGUI(); + + QString format = mapping.changeAt( 0 ).objectFormatName(); + QSync::SyncChange leftChange = mapping.changeAt( 0 ); + QSync::SyncChange rightChange = mapping.changeAt( 1 ); + + if ( format == "file" ) { + mDiffAlgo = new KSync::GenericDiffAlgo( leftChange.data(), rightChange.data() ); + } else if ( format == "vcard" ) { + } else if ( format == "calendar" ) { + } else if ( format == "xml-contact" ) { + mDiffAlgo = new KSync::AddresseeDiffAlgo( leftChange.data(), rightChange.data() ); + } + + MemberInfo miLeft( leftChange.member() ); + mDiffAlgoDisplay->setLeftSourceTitle( miLeft.name() ); + MemberInfo miRight( rightChange.member() ); + mDiffAlgoDisplay->setRightSourceTitle( miRight.name() ); + + if ( mDiffAlgo ) { + mDiffAlgo->addDisplay( mDiffAlgoDisplay ); + mDiffAlgo->run(); + } +} + +SingleConflictDialog::~SingleConflictDialog() +{ + delete mDiffAlgo; + mDiffAlgo = 0; +} + +void SingleConflictDialog::useFirstChange() +{ + mMapping.solve( mMapping.changeAt( 0 ) ); + + accept(); +} + +void SingleConflictDialog::useSecondChange() +{ + mMapping.solve( mMapping.changeAt( 1 ) ); + + accept(); +} + +void SingleConflictDialog::duplicateChange() +{ + mMapping.duplicate(); + + accept(); +} + +void SingleConflictDialog::ignoreChange() +{ + mMapping.ignore(); + + accept(); +} + +void SingleConflictDialog::initGUI() +{ + QGridLayout *layout = new QGridLayout( this, 3, 4, KDialog::marginHint(), KDialog::spacingHint() ); + + layout->addMultiCellWidget( new QLabel( i18n( "A conflict has appeared, please solve it manually." ), this ), 0, 0, 0, 3 ); + mDiffAlgoDisplay = new KSync::HTMLDiffAlgoDisplay( this ); + + layout->addMultiCellWidget( mDiffAlgoDisplay, 1, 1, 0, 3 ); + + QPushButton *button = new QPushButton( i18n( "Use Item" ), this ); + connect( button, SIGNAL( clicked() ), SLOT( useFirstChange() ) ); + layout->addWidget( button, 2, 0 ); + + button = new QPushButton( i18n( "Duplicate Items" ), this ); + connect( button, SIGNAL( clicked() ), SLOT( duplicateChange() ) ); + layout->addWidget( button, 2, 1 ); + + button = new QPushButton( i18n( "Ignore Conflict" ), this ); + connect( button, SIGNAL( clicked() ), SLOT( ignoreChange() ) ); + layout->addWidget( button, 2, 2 ); + + button = new QPushButton( i18n( "Use Item" ), this ); + connect( button, SIGNAL( clicked() ), SLOT( useSecondChange() ) ); + layout->addWidget( button, 2, 3 ); +} + +#include "singleconflictdialog.moc" diff --git a/kitchensync/src/singleconflictdialog.h b/kitchensync/src/singleconflictdialog.h new file mode 100644 index 000000000..75e083895 --- /dev/null +++ b/kitchensync/src/singleconflictdialog.h @@ -0,0 +1,54 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2005 Tobias Koenig <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef SINGLECONFLICTDIALOG_H +#define SINGLECONFLICTDIALOG_H + +#include "conflictdialog.h" +#include <libkdepim/diffalgo.h> + +using namespace KPIM; + +namespace KSync { +class HTMLDiffAlgoDisplay; +} + +class SingleConflictDialog : public ConflictDialog +{ + Q_OBJECT + + public: + SingleConflictDialog( QSync::SyncMapping &mapping, QWidget *parent ); + ~SingleConflictDialog(); + + private slots: + void useFirstChange(); + void useSecondChange(); + void duplicateChange(); + void ignoreChange(); + + private: + void initGUI(); + + DiffAlgo *mDiffAlgo; + KSync::HTMLDiffAlgoDisplay *mDiffAlgoDisplay; +}; + +#endif diff --git a/kitchensync/src/syncprocess.cpp b/kitchensync/src/syncprocess.cpp new file mode 100644 index 000000000..b52cc6db4 --- /dev/null +++ b/kitchensync/src/syncprocess.cpp @@ -0,0 +1,108 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2005 Tobias Koenig <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include <libqopensync/engine.h> +#include <libqopensync/environment.h> + +#include <kdebug.h> +#include <klocale.h> + +#include "syncprocess.h" +#include "syncprocessmanager.h" + +using namespace QSync; + +SyncProcess::SyncProcess( const QSync::Group &group ) + : QObject( 0, "SyncProcess" ) +{ + mGroup = group; + mEngine = new QSync::Engine( mGroup ); + + Result result = mEngine->initialize(); + if ( result.isError() ) + kdDebug() << "SyncProcess::SyncProcess: " << result.message() << endl; +} + +SyncProcess::~SyncProcess() +{ + mEngine->finalize(); + + delete mEngine; + mEngine = 0; +} + +QString SyncProcess::groupStatus() const +{ + return i18n( "Ready" ); +} + +QString SyncProcess::memberStatus( const QSync::Member& ) const +{ + return i18n( "Ready" ); +} + +QSync::Result SyncProcess::addMember( const QSync::Plugin &plugin ) +{ + QSync::Member member = mGroup.addMember(); + QSync::Result result = member.instance( plugin ); + + if ( !result.isError() ) + mGroup.save(); + + return result; +} + +void SyncProcess::reinitEngine() +{ + mEngine->finalize(); + delete mEngine; + mEngine = new QSync::Engine( mGroup ); + Result result = mEngine->initialize(); + if ( result.isError() ) + kdDebug() << "SyncProcess::reinitEngine: " << result.message() << endl; + + applyObjectTypeFilter(); + + emit engineChanged( mEngine ); +} + +void SyncProcess::applyObjectTypeFilter() +{ + const QSync::Conversion conversion = SyncProcessManager::self()->environment()->conversion(); + const QStringList objectTypes = conversion.objectTypes(); + const QStringList activeObjectTypes = mGroup.config().activeObjectTypes(); + + for ( uint i = 0; i < objectTypes.count(); ++i ) { + if ( activeObjectTypes.contains( objectTypes[ i ] ) ) { + kdDebug() << "Enabled object type: " << objectTypes[ i ] << endl; + /* + * This is not required. Also this lead to filtering problems when sync with "file-sync". + * Uncomment this line again when OpenSync is fixed! + * + * mGroup.setObjectTypeEnabled( objectTypes[ i ], true ); + */ + } else { + kdDebug() << "Disabled object type: " << objectTypes[ i ] << endl; + mGroup.setObjectTypeEnabled( objectTypes[ i ], false ); + } + } +} + +#include "syncprocess.moc" diff --git a/kitchensync/src/syncprocess.h b/kitchensync/src/syncprocess.h new file mode 100644 index 000000000..5b70a4b49 --- /dev/null +++ b/kitchensync/src/syncprocess.h @@ -0,0 +1,64 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2005 Tobias Koenig <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef SYNCPROCESS_H +#define SYNCPROCESS_H + +#include <qobject.h> + +#include <libqopensync/group.h> + +namespace QSync { +class Engine; +} + +class SyncProcess : public QObject +{ + Q_OBJECT + + public: + SyncProcess( const QSync::Group &group ); + ~SyncProcess(); + + QSync::Group group() const { return mGroup; } + QSync::Engine* engine() const { return mEngine; } + + QString groupStatus() const; + QString memberStatus( const QSync::Member &member ) const; + + QSync::Result addMember( const QSync::Plugin &plugin ); + + void reinitEngine(); + + /** apply object type filter hack **/ + void applyObjectTypeFilter(); + + signals: + /** + This signal is emitted whenever the engine has changed ( reinitialized ). + */ + void engineChanged( QSync::Engine *engine ); + + private: + QSync::Group mGroup; + QSync::Engine *mEngine; +}; + +#endif diff --git a/kitchensync/src/syncprocessmanager.cpp b/kitchensync/src/syncprocessmanager.cpp new file mode 100644 index 000000000..f2cb1ab0a --- /dev/null +++ b/kitchensync/src/syncprocessmanager.cpp @@ -0,0 +1,172 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2005 Cornelius Schumacher <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#include "syncprocessmanager.h" + +#include "syncprocess.h" + +#include <libqopensync/environment.h> + +#include <kstaticdeleter.h> +#include <kmessagebox.h> +#include <klocale.h> + +static KStaticDeleter<SyncProcessManager> selfDeleter; + +SyncProcessManager *SyncProcessManager::mSelf = 0; + +SyncProcessManager *SyncProcessManager::self() +{ + if ( !mSelf ) { + selfDeleter.setObject( mSelf, new SyncProcessManager() ); + } + return mSelf; +} + +SyncProcessManager::SyncProcessManager() +{ + mEnvironment = new QSync::Environment; + QSync::Result result = mEnvironment->initialize(); + if ( result.isError() ) { + KMessageBox::error( 0, i18n("Error initializing OpenSync.\n%1") + .arg( result.message() ) ); + } else { + init( mEnvironment ); + } +} + +SyncProcessManager::~SyncProcessManager() +{ + QValueList<SyncProcess*>::Iterator it; + for ( it = mProcesses.begin(); it != mProcesses.end(); ++it ) + delete *it; + + mProcesses.clear(); + + mEnvironment->finalize(); + delete mEnvironment; +} + +int SyncProcessManager::count() const +{ + return mProcesses.count(); +} + +SyncProcess* SyncProcessManager::at( int pos ) const +{ + if ( pos < 0 || pos >= (int)mProcesses.count() ) + return 0; + + return mProcesses[ pos ]; +} + +SyncProcess* SyncProcessManager::byGroup( const QSync::Group &group ) +{ + QValueList<SyncProcess*>::Iterator it; + for ( it = mProcesses.begin(); it != mProcesses.end(); ++it ) + if ( (*it)->group() == group ) + return *it; + + return 0; +} + +SyncProcess* SyncProcessManager::byGroupName( const QString &name ) +{ + QValueList<SyncProcess*>::Iterator it; + for ( it = mProcesses.begin(); it != mProcesses.end(); ++it ) + if ( (*it)->group().name() == name ) + return *it; + + return 0; +} + +void SyncProcessManager::addGroup( const QString &name ) +{ + SyncProcess* process = byGroupName( name ); + if ( !process ) { + QSync::Group group = mEnvironment->addGroup(); + group.setName( name ); + group.save(); + + mProcesses.append( new SyncProcess( group ) ); + + emit changed(); + } else + qDebug( "Try to add duplicate" ); +} + +void SyncProcessManager::remove( SyncProcess *syncProcess ) +{ + if ( syncProcess ) { + mProcesses.remove( syncProcess ); + const QSync::Group group = syncProcess->group(); + delete syncProcess; + + mEnvironment->removeGroup( group ); + + emit changed(); + } +} + +void SyncProcessManager::init( QSync::Environment *environment ) +{ + QSync::Environment::GroupIterator it( environment->groupBegin() ); + for ( ; it != environment->groupEnd(); ++it ) { + /** + * We check whether the group is valid before we append them + * to mProcesses. That avoids crashes if the plugin of one of + * the members isn't loaded (e.g. not installed). + */ + const QSync::Group group = *it; + int count = group.memberCount(); + + bool isValid = true; + for ( int i = 0; i < count; ++i ) { + const QSync::Member member = group.memberAt( i ); + + if ( !member.isValid() ) { + isValid = false; + break; + } + } + + if ( isValid ) + mProcesses.append( new SyncProcess( *it ) ); + } + + emit changed(); +} + +QSync::Result SyncProcessManager::addMember( SyncProcess *process, + const QSync::Plugin &plugin ) +{ + Q_ASSERT( process ); + + QSync::Result result = process->addMember( plugin ); + if ( !result.isError() ) { + process->group().save(); + emit syncProcessChanged( process ); + } + + return result; +} + +#include "syncprocessmanager.moc" diff --git a/kitchensync/src/syncprocessmanager.h b/kitchensync/src/syncprocessmanager.h new file mode 100644 index 000000000..488312939 --- /dev/null +++ b/kitchensync/src/syncprocessmanager.h @@ -0,0 +1,100 @@ +/* + This file is part of KitchenSync. + + Copyright (c) 2005 Cornelius Schumacher <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ +#ifndef SYNCPROCESSMANAGER_H +#define SYNCPROCESSMANAGER_H + +#include <qobject.h> + +#include <libqopensync/group.h> + +namespace QSync { +class Environment; +} + +class SyncProcess; + +class SyncProcessManager : public QObject +{ + Q_OBJECT + public: + static SyncProcessManager *self(); + + /** + Destroys the SyncProcessList. + */ + ~SyncProcessManager(); + + /** + Return OpenSync Environment. + */ + QSync::Environment *environment() const { return mEnvironment; } + + /** + Returns the number of SyncProcesses. + */ + int count() const; + + /** + Returns the SyncProcess at position @param pos. + */ + SyncProcess* at( int pos ) const; + + /** + Returns the SyncProcess with the given @param group. + */ + SyncProcess* byGroup( const QSync::Group &group ); + + /** + Returns the SyncProcess with the given group @param name. + */ + SyncProcess* byGroupName( const QString &name ); + + /** + Adds a group with given @param name. + */ + void addGroup( const QString &name ); + + /** + Removes the given @param sync process. + */ + void remove( SyncProcess *syncProcess ); + + /** + Adds @param plugin instance as member to the group of @param process. + */ + QSync::Result addMember( SyncProcess *process, const QSync::Plugin &plugin ); + + signals: + void changed(); + void syncProcessChanged( SyncProcess *process ); + + private: + SyncProcessManager(); + + void init( QSync::Environment *environment ); + + QValueList<SyncProcess*> mProcesses; + QSync::Environment *mEnvironment; + + static SyncProcessManager *mSelf; +}; + +#endif |