summaryrefslogtreecommitdiffstats
path: root/tderesources/carddav
diff options
context:
space:
mode:
Diffstat (limited to 'tderesources/carddav')
-rw-r--r--tderesources/carddav/CMakeLists.txt54
-rw-r--r--tderesources/carddav/ConfigureChecks.cmake30
-rw-r--r--tderesources/carddav/Makefile.am35
-rw-r--r--tderesources/carddav/config.cpp168
-rw-r--r--tderesources/carddav/config.h81
-rw-r--r--tderesources/carddav/configwidgets.cpp247
-rw-r--r--tderesources/carddav/configwidgets.h101
-rw-r--r--tderesources/carddav/export.h56
-rw-r--r--tderesources/carddav/job.cpp110
-rw-r--r--tderesources/carddav/job.h176
-rw-r--r--tderesources/carddav/kabc_carddav.desktop52
-rw-r--r--tderesources/carddav/plugin.cpp47
-rw-r--r--tderesources/carddav/preferences.cpp239
-rw-r--r--tderesources/carddav/preferences.h155
-rw-r--r--tderesources/carddav/prefsskel.kcfg30
-rw-r--r--tderesources/carddav/prefsskel.kcfgc7
-rw-r--r--tderesources/carddav/reader.cpp63
-rw-r--r--tderesources/carddav/reader.h91
-rw-r--r--tderesources/carddav/resource.cpp683
-rw-r--r--tderesources/carddav/resource.h227
-rw-r--r--tderesources/carddav/uninstall.desktop2
-rw-r--r--tderesources/carddav/writer.cpp106
-rw-r--r--tderesources/carddav/writer.h109
23 files changed, 2869 insertions, 0 deletions
diff --git a/tderesources/carddav/CMakeLists.txt b/tderesources/carddav/CMakeLists.txt
new file mode 100644
index 00000000..36e086b4
--- /dev/null
+++ b/tderesources/carddav/CMakeLists.txt
@@ -0,0 +1,54 @@
+#################################################
+#
+# (C) 2010-2011 Serghei Amelian
+# serghei (DOT) amelian (AT) gmail.com
+#
+# Improvements and feedback are welcome
+#
+# This file is released under GPL >= 2
+#
+#################################################
+
+include( ConfigureChecks.cmake )
+
+include_directories(
+ ${CMAKE_CURRENT_BINARY_DIR}
+ ${CMAKE_SOURCE_DIR}
+ ${CMAKE_SOURCE_DIR}/libtdepim
+ ${TDE_INCLUDE_DIR}
+ ${TQT_INCLUDE_DIRS}
+ ${CARDDAV_INCLUDE_DIRS}
+)
+
+link_directories(
+ ${TQT_LIBRARY_DIRS}
+ ${CARDDAV_LIBRARY_DIRS}
+)
+
+
+##### other data ################################
+
+install(
+ FILES kabc_carddav.desktop
+ DESTINATION ${SERVICES_INSTALL_DIR}/tderesources/kabc )
+
+
+##### kabc_carddav (module) #####################
+
+tde_add_kpart( kabc_carddav AUTOMOC
+ SOURCES plugin.cpp
+ LINK kabc_carddav-shared
+ DESTINATION ${PLUGIN_INSTALL_DIR}
+)
+
+
+##### kabc_carddav (shared) #####################
+
+tde_add_library( kabc_carddav SHARED AUTOMOC
+ SOURCES
+ resource.cpp config.cpp configwidgets.cpp preferences.cpp job.cpp
+ reader.cpp writer.cpp prefsskel.kcfgc
+ VERSION 1.0.0
+ LINK tdepim-shared ${CARDDAV_LIBRARIES}
+ DESTINATION ${LIB_INSTALL_DIR}
+)
diff --git a/tderesources/carddav/ConfigureChecks.cmake b/tderesources/carddav/ConfigureChecks.cmake
new file mode 100644
index 00000000..62582fe9
--- /dev/null
+++ b/tderesources/carddav/ConfigureChecks.cmake
@@ -0,0 +1,30 @@
+#################################################
+#
+# (C) 2010-2011 Serghei Amelian
+# serghei (DOT) amelian (AT) gmail.com
+#
+# Improvements and feedback are welcome
+#
+# This file is released under GPL >= 2
+#
+#################################################
+
+# libcarddav
+pkg_search_module( CARDDAV libcarddav )
+if( CARDDAV_FOUND )
+ execute_process(
+ COMMAND pkg-config libcarddav --variable=pkgincludedir
+ OUTPUT_VARIABLE _incdir
+ RESULT_VARIABLE _result
+ OUTPUT_STRIP_TRAILING_WHITESPACE )
+ execute_process(
+ COMMAND pkg-config libcarddav --variable=pkglibdir
+ OUTPUT_VARIABLE _libdir
+ RESULT_VARIABLE _result
+ OUTPUT_STRIP_TRAILING_WHITESPACE )
+ list( APPEND CARDDAV_INCLUDE_DIRS ${_incdir} )
+ list( APPEND CARDDAV_LIBRARY_DIRS ${_libdir} )
+ list( APPEND CARDDAV_LIBRARIES carddav )
+else( )
+ tde_message_fatal( "libcarddav is requested, but was not found on your system" )
+endif( )
diff --git a/tderesources/carddav/Makefile.am b/tderesources/carddav/Makefile.am
new file mode 100644
index 00000000..b82849df
--- /dev/null
+++ b/tderesources/carddav/Makefile.am
@@ -0,0 +1,35 @@
+INCLUDES = -I$(top_srcdir) $(all_includes)
+
+lib_LTLIBRARIES = libkabc_carddav.la
+
+libkabc_carddav_la_SOURCES = resource.cpp \
+ config.cpp \
+ configwidgets.cpp \
+ preferences.cpp \
+ job.cpp \
+ reader.cpp \
+ writer.cpp \
+ prefsskel.kcfgc
+libkabc_carddav_la_LDFLAGS = $(KDE_RPATH) $(all_libraries) \
+ -version-info 1:0:0 -no-undefined
+libkabc_carddav_la_LIBADD = \
+ $(top_builddir)/libtdepim/libtdepim.la \
+ $(top_builddir)/libkcal/libkcal.la \
+ -lkabc \
+ -lcarddav
+libkabc_carddav_la_COMPILE_FIRST = prefsskel.h
+
+kde_module_LTLIBRARIES = kabc_carddav.la
+
+kabc_carddav_la_SOURCES = plugin.cpp
+kabc_carddav_la_LDFLAGS = $(all_libraries) -module -no-undefined $(KDE_PLUGIN)
+kabc_carddav_la_LIBADD = libkabc_carddav.la
+kabc_carddav_la_COMPILE_FIRST = prefsskel.h
+
+kabc_servicedir = $(kde_servicesdir)/tderesources/kabc
+kabc_service_DATA = kabc_carddav.desktop
+
+METASOURCES = AUTO
+
+messages: rc.cpp
+ $(XGETTEXT) *.cpp -o $(podir)/kres_carddav.pot
diff --git a/tderesources/carddav/config.cpp b/tderesources/carddav/config.cpp
new file mode 100644
index 00000000..9b01eb5d
--- /dev/null
+++ b/tderesources/carddav/config.cpp
@@ -0,0 +1,168 @@
+/*=========================================================================
+| KCardDAV
+|--------------------------------------------------------------------------
+| (c) 2010 Timothy Pearson
+|
+| This project is released under the GNU General Public License.
+| Please see the file COPYING for more details.
+|--------------------------------------------------------------------------
+| Configuration and properties dialog
+ ========================================================================*/
+
+/*=========================================================================
+| INCLUDES
+ ========================================================================*/
+
+#include "resource.h"
+#include "config.h"
+#include "configwidgets.h"
+
+#include <kcombobox.h>
+#include <kdebug.h>
+#include <kdialog.h>
+#include <klocale.h>
+#include <klineedit.h>
+#include <klistview.h>
+#include <kurlrequester.h>
+
+#include <tqlabel.h>
+#include <tqlayout.h>
+#include <tqcheckbox.h>
+
+/*=========================================================================
+| NAMESPACE
+ ========================================================================*/
+
+using namespace KABC;
+
+/*=========================================================================
+| CONSTANTS
+ ========================================================================*/
+
+/*=========================================================================
+| STATIC METHODS
+ ========================================================================*/
+
+ResourceCardDav* ResourceCardDavConfig::getCardDavResource(KRES::Resource* resource) {
+ ResourceCardDav *res = dynamic_cast<ResourceCardDav *>( resource );
+ if (!res) {
+ kdDebug() << "invalid resource type" << '\n';
+ }
+
+ return res;
+}
+
+CardDavPrefs* ResourceCardDavConfig::getPrefs(ResourceCardDav* res) {
+ CardDavPrefs* p = NULL;
+
+ if (res) {
+ p = res->prefs();
+ if (!p) {
+ kdDebug() << "CardDAV: res->prefs() returned NULL" << '\n';
+ }
+ }
+
+ return p;
+}
+
+/*=========================================================================
+| CONSTRUCTOR / DESTRUCTOR
+ ========================================================================*/
+
+ResourceCardDavConfig::ResourceCardDavConfig( TQWidget *parent )
+ : KRES::ConfigWidget( parent )
+{
+ setupUI();
+}
+
+/*=========================================================================
+| METHODS
+ ========================================================================*/
+
+void ResourceCardDavConfig::loadSettings( KRES::Resource *resource ) {
+ ResourceCardDav* res = getCardDavResource(resource);
+ CardDavPrefs* p = getPrefs(res);
+ if (NULL != p) {
+ mUrl->setText(p->url());
+ mUsername->setText(p->username());
+ mRememberPassword->setChecked(p->rememberPassword());
+ mPassword->setText(p->password());
+ mUseUriNotUID->setChecked(p->useURI());
+
+ mReloadConfig->loadSettings(res);
+ mSaveConfig->loadSettings(res);
+ }
+}
+
+void ResourceCardDavConfig::saveSettings( KRES::Resource *resource ) {
+ ResourceCardDav* res = getCardDavResource(resource);
+ if (NULL != res) {
+ mReloadConfig->saveSettings(res);
+ mSaveConfig->saveSettings(res);
+
+ CardDavPrefs* p = getPrefs(res);
+ if (NULL != p) {
+ p->setUrl(mUrl->text());
+ p->setUsername(mUsername->text());
+ p->setRememberPassword(mRememberPassword->isChecked());
+ p->setPassword(mPassword->text());
+ p->setUseURI(mUseUriNotUID->isChecked());
+ }
+ }
+}
+
+void ResourceCardDavConfig::setupUI() {
+ TQVBoxLayout *vertical = new TQVBoxLayout(this);
+
+ TQGridLayout *mainLayout = new TQGridLayout( this );
+
+ // URL
+ TQLabel *label = new TQLabel( i18n( "URL:" ), this );
+ mUrl = new TQLineEdit( this );
+ mainLayout->addWidget( label, 1, 0 );
+ mainLayout->addWidget( mUrl, 1, 1 );
+
+ // Username
+ label = new TQLabel( i18n( "Username:" ), this );
+ mUsername = new TQLineEdit( this );
+ mainLayout->addWidget( label, 2, 0 );
+ mainLayout->addWidget( mUsername, 2, 1 );
+
+ // Password
+ label = new TQLabel( i18n( "Password:" ), this );
+ mPassword = new TQLineEdit( this );
+ mPassword->setEchoMode( TQLineEdit::Password );
+ mainLayout->addWidget( label, 3, 0 );
+ mainLayout->addWidget( mPassword, 3, 1 );
+
+ // Remember password checkbox
+ mRememberPassword = new TQCheckBox( i18n("Remember password"), this );
+ mainLayout->addWidget(mRememberPassword, 4, 1);
+
+ mUseUriNotUID = new TQCheckBox( i18n( "Use URI instead of UID when modifying existing contacts" ), this );
+ mainLayout->addWidget( mUseUriNotUID, 5, 1 );
+
+ // configs
+ TQHBoxLayout* horizontal = new TQHBoxLayout(this);
+
+ // Reload config
+ mReloadConfig = new CardDavReloadConfig(this);
+ horizontal->addWidget(mReloadConfig);
+
+ // Save config
+ mSaveConfig = new CardDavSaveConfig(this);
+ horizontal->addWidget(mSaveConfig);
+
+ // FIXME: This feature does not work; hide the UI elements for later use
+ mRememberPassword->hide();
+ label->hide();
+ mPassword->hide();
+
+ // combining layouts
+ vertical->addLayout(mainLayout);
+ vertical->addLayout(horizontal);
+}
+
+#include "config.moc"
+
+// EOF ========================================================================
diff --git a/tderesources/carddav/config.h b/tderesources/carddav/config.h
new file mode 100644
index 00000000..7cac4094
--- /dev/null
+++ b/tderesources/carddav/config.h
@@ -0,0 +1,81 @@
+/*=========================================================================
+| KCardDAV
+|--------------------------------------------------------------------------
+| (c) 2010 Timothy Pearson
+|
+| This project is released under the GNU General Public License.
+| Please see the file COPYING for more details.
+|--------------------------------------------------------------------------
+| Configuration and properties dialog
+ ========================================================================*/
+
+#ifndef KABC_RESOURCECARDDAVCONFIG_H
+#define KABC_RESOURCECARDDAVCONFIG_H
+
+/*=========================================================================
+| INCLUDES
+ ========================================================================*/
+
+#include "resource.h"
+
+#include <kdemacros.h>
+#include <tderesources/configwidget.h>
+
+class TQLineEdit;
+class TQCheckBox;
+
+namespace KABC {
+
+class CardDavReloadConfig;
+class CardDavSaveConfig;
+
+/*=========================================================================
+| CLASS
+ ========================================================================*/
+
+/**
+ * Configuration widget for CardDAV resource.
+ */
+class KDE_EXPORT ResourceCardDavConfig : public KRES::ConfigWidget
+{
+ Q_OBJECT
+
+
+public:
+
+ ResourceCardDavConfig(TQWidget *parent = 0);
+
+public slots:
+
+ virtual void loadSettings(KRES::Resource *resource);
+ virtual void saveSettings(KRES::Resource *resource);
+
+protected:
+
+ virtual void setupUI();
+
+private:
+
+ TQLineEdit *mUrl;
+ TQLineEdit *mUsername;
+ TQLineEdit *mPassword;
+ TQCheckBox *mRememberPassword;
+ TQCheckBox *mUseUriNotUID;
+ CardDavReloadConfig* mReloadConfig;
+ CardDavSaveConfig* mSaveConfig;
+
+ static ResourceCardDav* getCardDavResource(KRES::Resource* res);
+
+ /**
+ * Returns preferences of the given ResourceCardDav object.
+ * @param res resource object.
+ * @return if preferences object is obtained successfully, it's returned. Otherwise, NULL is returned.
+ */
+ static CardDavPrefs* getPrefs(ResourceCardDav* res);
+};
+
+} // namespace KABC
+
+
+#endif // KABC_RESOURCECARDDAVCONFIG_H
+
diff --git a/tderesources/carddav/configwidgets.cpp b/tderesources/carddav/configwidgets.cpp
new file mode 100644
index 00000000..b2d505df
--- /dev/null
+++ b/tderesources/carddav/configwidgets.cpp
@@ -0,0 +1,247 @@
+/*=========================================================================
+| KABCDAV
+|--------------------------------------------------------------------------
+| (c) 2010 Timothy Pearson
+|
+| This project is released under the GNU General Public License.
+| Please see the file COPYING for more details.
+|--------------------------------------------------------------------------
+| Automatic Reload / Automatic Save configuration widgets.
+| The code is mostly taken from resourcecachedconfig.h/cpp files from
+| the kcal library and changed to meet our requirements.
+| The original copyright is below.
+ ========================================================================*/
+/*
+ This file is part of the kcal library.
+
+ Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "configwidgets.h"
+
+#include <kabcresourcecached.h>
+
+#include <klocale.h>
+#include <kdebug.h>
+
+#include <tqlabel.h>
+#include <tqlayout.h>
+#include <tqcheckbox.h>
+#include <tqradiobutton.h>
+#include <tqspinbox.h>
+#include <tqbuttongroup.h>
+#include <tqgroupbox.h>
+#include <tqhbox.h>
+
+using namespace KABC;
+
+//@cond PRIVATE
+class CardDavConfigPrivate
+{
+ public:
+ CardDavConfigPrivate()
+ : mGroup( 0 ),
+ mIntervalSpin( 0 ) {}
+
+ TQButtonGroup *mGroup;
+ TQSpinBox *mIntervalSpin;
+};
+
+class CardDavReloadConfig::Private
+ : public CardDavConfigPrivate
+{
+};
+
+class CardDavSaveConfig::Private
+ : public CardDavConfigPrivate
+{
+};
+//@endcond
+
+CardDavReloadConfig::CardDavReloadConfig( TQWidget *parent )
+ : TQWidget( parent ), d( new KABC::CardDavReloadConfig::Private() )
+{
+ TQBoxLayout *topLayout = new TQVBoxLayout( this );
+
+ //TQGroupBox *groupBox = new TQGroupBox( i18nc( "@title:group", "Automatic Reload" ), this );
+ TQGroupBox *groupBox = new TQGroupBox( i18n( "Automatic Reload" ), this );
+ topLayout->addWidget( groupBox );
+
+ TQRadioButton *noAutomaticReload =
+ new TQRadioButton(
+ //i18nc( "@option:radio never reload the cache", "Never" ), groupBox );
+ i18n( "Never" ), groupBox );
+ TQRadioButton *automaticReloadOnStartup =
+ new TQRadioButton(
+ //i18nc( "@option:radio reload the cache on startup", "Only on startup" ), groupBox );
+ i18n( "Only on startup" ), groupBox );
+ TQRadioButton *intervalRadio =
+ new TQRadioButton(
+// i18nc( "@option:radio reload the cache at regular intervals",
+// "Regular interval" ), groupBox );
+ i18n( "Regular interval" ), groupBox );
+
+ d->mGroup = new TQButtonGroup( this );
+ d->mGroup->hide();
+ d->mGroup->insert( intervalRadio, 2 );
+ d->mGroup->insert( automaticReloadOnStartup, 1 );
+ d->mGroup->insert( noAutomaticReload, 0 );
+
+ connect( intervalRadio, TQT_SIGNAL( toggled( bool ) ),
+ TQT_SLOT( slotIntervalToggled( bool ) ) );
+
+ TQHBox *intervalBox = new TQHBox( groupBox );
+ //new TQLabel( i18nc( "@label:spinbox", "Interval in minutes:" ), intervalBox );
+ new TQLabel( i18n( "Interval in minutes:" ), intervalBox );
+ d->mIntervalSpin = new TQSpinBox( intervalBox );
+ d->mIntervalSpin->setRange( 1, 900 );
+ d->mIntervalSpin->setEnabled( false );
+
+ groupBox->setColumnLayout(1, Qt::Vertical);
+ TQVBoxLayout *vbox = new TQVBoxLayout(groupBox->layout());
+ vbox->addWidget(intervalRadio);
+ vbox->addWidget(intervalBox);
+ vbox->addWidget(automaticReloadOnStartup);
+ vbox->addWidget(noAutomaticReload);
+ vbox->addStretch(1);
+}
+
+CardDavReloadConfig::~CardDavReloadConfig()
+{
+ delete d;
+}
+
+void CardDavReloadConfig::loadSettings( ResourceCached *resource )
+{
+ d->mIntervalSpin->setValue( resource->reloadInterval() );
+ d->mGroup->setButton( resource->reloadPolicy() );
+}
+
+void CardDavReloadConfig::saveSettings( ResourceCached *resource )
+{
+ resource->setReloadInterval( d->mIntervalSpin->value() );
+ resource->setReloadPolicy( d->mGroup->selectedId() );
+}
+
+void CardDavReloadConfig::slotIntervalToggled( bool checked )
+{
+ if ( checked ) {
+ d->mIntervalSpin->setEnabled( true );
+ } else {
+ d->mIntervalSpin->setEnabled( false );
+ }
+}
+
+CardDavSaveConfig::CardDavSaveConfig( TQWidget *parent )
+ : TQWidget( parent ), d( new KABC::CardDavSaveConfig::Private() )
+{
+ TQBoxLayout *topLayout = new TQVBoxLayout( this );
+
+ //TQGroupBox *groupBox = new TQGroupBox( i18nc( "@title:group", "Automatic Save" ), this );
+ TQGroupBox *groupBox = new TQGroupBox( i18n( "Automatic Save" ), this );
+ d->mGroup = new TQButtonGroup( this );
+ d->mGroup->hide();
+ topLayout->addWidget( groupBox );
+
+ TQRadioButton *never =
+ new TQRadioButton(
+ //i18nc( "@option:radio never save the cache automatically", "Never" ), groupBox );
+ i18n( "Never" ), groupBox );
+ TQRadioButton *onExit =
+ new TQRadioButton(
+ //i18nc( "@option:radio save the cache on exit", "Only on exit" ), groupBox );
+ i18n( "Only on exit" ), groupBox );
+
+ TQRadioButton *intervalRadio =
+ new TQRadioButton(
+ //i18nc( "@option:radio save the cache at regular intervals", "Regular interval" ), groupBox );
+ i18n( "Regular interval" ), groupBox );
+
+ d->mGroup = new TQButtonGroup( this );
+ d->mGroup->hide();
+ d->mGroup->insert( never, 0 );
+ d->mGroup->insert( onExit, 1 );
+ d->mGroup->insert( intervalRadio, 2 );
+
+ connect( intervalRadio, TQT_SIGNAL( toggled( bool ) ),
+ TQT_SLOT( slotIntervalToggled( bool ) ) );
+
+ TQHBox *intervalBox = new TQHBox( groupBox );
+ //new TQLabel( i18nc( "@label:spinbox", "Interval in minutes:" ), intervalBox );
+ new TQLabel( i18n( "Interval in minutes:" ), intervalBox );
+ d->mIntervalSpin = new TQSpinBox( intervalBox );
+ d->mIntervalSpin->setRange( 1, 900 );
+ d->mIntervalSpin->setEnabled( false );
+
+ TQRadioButton *delay =
+ new TQRadioButton(
+// i18nc( "@option:radio save the cache after some delay",
+// "Delayed after changes" ), groupBox );
+ i18n( "Delayed after changes" ), groupBox );
+ TQRadioButton *every =
+ new TQRadioButton(
+// i18nc( "@option:radio save the cache after every modification",
+// "Immediately after changes" ), groupBox );
+ i18n( "Immediately after changes" ), groupBox );
+ d->mGroup->insert( delay, 3 );
+ d->mGroup->insert( every, 4 );
+
+ // hide unwanted widgets. They may be useful in future, so don't delete them for now.
+ intervalRadio->hide();
+ intervalBox->hide();
+
+ groupBox->setColumnLayout(1, Qt::Vertical);
+ TQVBoxLayout *vbox = new TQVBoxLayout(groupBox->layout());
+ vbox->addWidget(delay);
+ vbox->addWidget(every);
+ vbox->addWidget(intervalRadio);
+ vbox->addWidget(intervalBox);
+ vbox->addWidget(onExit);
+ vbox->addWidget(never);
+ vbox->addStretch(1);
+}
+
+CardDavSaveConfig::~CardDavSaveConfig()
+{
+ delete d;
+}
+
+void CardDavSaveConfig::loadSettings( ResourceCached *resource )
+{
+ d->mIntervalSpin->setValue( resource->saveInterval() );
+ d->mGroup->setButton( resource->savePolicy() );
+}
+
+void CardDavSaveConfig::saveSettings( ResourceCached *resource )
+{
+ resource->setSaveInterval( d->mIntervalSpin->value() );
+ resource->setSavePolicy( d->mGroup->selectedId() );
+}
+
+void CardDavSaveConfig::slotIntervalToggled( bool checked )
+{
+ if ( checked ) {
+ d->mIntervalSpin->setEnabled( true );
+ } else {
+ d->mIntervalSpin->setEnabled( false );
+ }
+}
+
+#include "configwidgets.moc"
+
+// EOF ========================================================================
diff --git a/tderesources/carddav/configwidgets.h b/tderesources/carddav/configwidgets.h
new file mode 100644
index 00000000..9f45579d
--- /dev/null
+++ b/tderesources/carddav/configwidgets.h
@@ -0,0 +1,101 @@
+/*=========================================================================
+| KABCDAV
+|--------------------------------------------------------------------------
+| (c) 2010 Timothy Pearson
+|
+| This project is released under the GNU General Public License.
+| Please see the file COPYING for more details.
+|--------------------------------------------------------------------------
+| Automatic Reload / Automatic Save configuration widgets.
+| The code is mostly taken from resourcecachedconfig.h/cpp files from
+| the kcal library and changed to meet our requirements.
+| The original copyright is below.
+ ========================================================================*/
+/*
+ This file is part of the kcal library.
+
+ Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+#ifndef KCARDDAV_AUTOWIDGETS_H
+#define KCARDDAV_AUTOWIDGETS_H
+
+#include <tqwidget.h>
+#include <kdemacros.h>
+
+namespace KABC {
+
+class ResourceCached;
+
+/**
+ Configuration widget for reload policy
+
+ @see ResourceCached
+*/
+class KDE_EXPORT CardDavReloadConfig : public TQWidget
+{
+ Q_OBJECT
+
+ public:
+ explicit CardDavReloadConfig( TQWidget *parent = 0 );
+ ~CardDavReloadConfig();
+ public slots:
+ void loadSettings( ResourceCached *resource );
+ void saveSettings( ResourceCached *resource );
+
+ protected slots:
+ void slotIntervalToggled( bool );
+
+ private:
+ //@cond PRIVATE
+ //TQ_DISABLE_COPY( CardDavReloadConfig )
+ class Private;
+ Private *const d;
+ //@endcond
+};
+
+/**
+ Configuration widget for save policy
+
+ @see ResourceCached
+*/
+class KDE_EXPORT CardDavSaveConfig : public TQWidget
+{
+ Q_OBJECT
+
+ public:
+ explicit CardDavSaveConfig( TQWidget *parent = 0 );
+ ~CardDavSaveConfig();
+
+ public slots:
+ void loadSettings( ResourceCached *resource );
+ void saveSettings( ResourceCached *resource );
+
+ protected slots:
+ void slotIntervalToggled( bool );
+
+ private:
+ //@cond PRIVATE
+ //TQ_DISABLE_COPY( CardDavSaveConfig )
+ class Private;
+ Private *const d;
+ //@endcond
+};
+
+}
+
+#endif // KCARDDAV_AUTOWIDGETS_H
diff --git a/tderesources/carddav/export.h b/tderesources/carddav/export.h
new file mode 100644
index 00000000..c439f53f
--- /dev/null
+++ b/tderesources/carddav/export.h
@@ -0,0 +1,56 @@
+/*=========================================================================
+| KCalDAV
+|--------------------------------------------------------------------------
+| (c) 2010 Timothy Pearson
+| (c) 2009 Kumaran Santhanam (initial KDE4 version)
+|
+| This project is released under the GNU General Public License.
+| Please see the file COPYING for more details.
+|--------------------------------------------------------------------------
+| Some support macros.
+| The code is mostly taken from KDE source files.
+| The original copyright is below.
+ ========================================================================*/
+/* This file is part of the KDE project
+ Copyright (C) 2008 Jarosław Staniek <staniek@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef KRESOURCES_TDEPIM_EXPORT_H
+#define KRESOURCES_TDEPIM_EXPORT_H
+
+/** Exports a function returning tderesources plugin factory, for resource class @a resourceclass,
+ * @a resourceconfigclass config class and @a catalog catalog.
+ */
+#define EXPORT_KRESOURCES_PLUGIN( resourceclass, resourceconfigclass, catalog ) \
+ typedef KRES::PluginFactory< resourceclass, resourceconfigclass > FactoryBase; \
+ class Factory : public FactoryBase { \
+ public: Factory() { TDEGlobal::locale()->insertCatalogue(catalog); } \
+ }; \
+ K_EXPORT_PLUGIN( Factory )
+
+/** Like EXPORT_KRESOURCES_PLUGIN but allows to specify two catalogs.
+ */
+#define EXPORT_KRESOURCES_PLUGIN2( resourceclass, resourceconfigclass, catalog1, catalog2 ) \
+ typedef KRES::PluginFactory< resourceclass, resourceconfigclass > FactoryBase; \
+ class Factory : public FactoryBase { \
+ public: Factory() { TDEGlobal::locale()->insertCatalogue(catalog1); \
+ TDEGlobal::locale()->insertCatalogue(catalog2); } \
+ }; \
+ K_EXPORT_PLUGIN( Factory )
+
+#endif
diff --git a/tderesources/carddav/job.cpp b/tderesources/carddav/job.cpp
new file mode 100644
index 00000000..9c288650
--- /dev/null
+++ b/tderesources/carddav/job.cpp
@@ -0,0 +1,110 @@
+/*=========================================================================
+| KCardDAV
+|--------------------------------------------------------------------------
+| (c) 2010 Timothy Pearson
+|
+| This project is released under the GNU General Public License.
+| Please see the file COPYING for more details.
+|--------------------------------------------------------------------------
+| Job class for accessing remote address books.
+ ========================================================================*/
+
+/*=========================================================================
+| INCLUDES
+ ========================================================================*/
+
+#include "job.h"
+#include <kdebug.h>
+#include <klocale.h>
+
+#include <tqmutex.h>
+
+#define log(s) kdDebug() << s << '\n';
+
+/*=========================================================================
+| NAMESPACE
+ ========================================================================*/
+
+using namespace KABC;
+
+/*=========================================================================
+| STATIC
+ ========================================================================*/
+
+/*=========================================================================
+| CONSTRUCTOR AND DESTRUCTOR
+ ========================================================================*/
+
+CardDavJob::CardDavJob(const TQString& url) : mUseURI(false) {
+ cleanJob();
+ setUrl(url);
+}
+
+CardDavJob::~CardDavJob() {
+}
+
+
+/*=========================================================================
+| METHODS
+ ========================================================================*/
+
+void CardDavJob::enableCarddavDebug(runtime_info* rt) {
+ if (rt && rt->options) {
+ rt->options->debug = 0; // if debug = 1, it causes major CPU overhead
+ rt->options->verify_ssl_certificate = FALSE;
+ }
+}
+
+void CardDavJob::setErrorString(const TQString& err, const long number) {
+ mError = true;
+ mErrorString = err;
+ mErrorNumber = number;
+}
+
+void CardDavJob::processError(const carddav_error* err) {
+ TQString error_string;
+
+ long code = err->code;
+
+ if (-401 == code) { // unauthorized
+ error_string = i18n("Unauthorized. Username or password incorrect.");
+ } else if (-599 <= code && code <= -300) {
+ error_string = i18n("HTTP error %1. Maybe, URL is not a CardDAV resource.").arg(-code);
+ } else {
+ error_string = err->str;
+ }
+
+ setErrorString(error_string, code);
+}
+
+
+void CardDavJob::run() {
+ log("cleaning job");
+ cleanJob();
+
+ int res = OK;
+
+ runtime_info* carddav_runtime = carddav_get_runtime_info();
+
+#ifdef KABCDAV_DEBUG
+ log("setting debug carddav options");
+ enableCarddavDebug(carddav_runtime);
+#endif // KABCDAV_DEBUG
+
+ log("running job");
+ res = runJob(carddav_runtime);
+
+ if (OK != res) {
+ log("job failed");
+ processError(carddav_runtime->error);
+ }
+
+ carddav_free_runtime_info(&carddav_runtime);
+
+ // Signal done
+ // 1000 is read, 1001 is write
+ if (type() == 0) TQApplication::postEvent ( parent(), new TQEvent( static_cast<TQEvent::Type>(1000) ) );
+ if (type() == 1) TQApplication::postEvent ( parent(), new TQEvent( static_cast<TQEvent::Type>(1001) ) );
+}
+
+// EOF ========================================================================
diff --git a/tderesources/carddav/job.h b/tderesources/carddav/job.h
new file mode 100644
index 00000000..52a04bc7
--- /dev/null
+++ b/tderesources/carddav/job.h
@@ -0,0 +1,176 @@
+/*=========================================================================
+| KCardDAV
+|--------------------------------------------------------------------------
+| (c) 2010 Timothy Pearson
+|
+| This project is released under the GNU General Public License.
+| Please see the file COPYING for more details.
+|--------------------------------------------------------------------------
+| Job class for accessing remote address books.
+ ========================================================================*/
+
+/*=========================================================================
+| INCLUDES
+ ========================================================================*/
+
+#ifndef KABCDAV_JOB_H
+#define KABCDAV_JOB_H
+
+#include <tqthread.h>
+#include <tqstring.h>
+#include <tqdatetime.h>
+#include <tqapplication.h>
+
+extern "C" {
+ #include <carddav.h>
+}
+
+namespace KABC {
+
+/*=========================================================================
+| CLASS
+ ========================================================================*/
+
+/**
+ * Calendar job.
+ */
+class CardDavJob : public TQThread {
+
+public:
+
+ /**
+ * @param url URL to load.
+ */
+ CardDavJob(const TQString& url = TQString());
+
+ virtual ~CardDavJob();
+
+ /**
+ * Sets a new URL to load.
+ */
+ virtual void setUrl(const TQString& s) {
+ mUrl = s;
+ }
+
+ /**
+ * Sets whether to use UID (false) or URI (true) as an object's unique identifier
+ */
+ virtual void setUseURI(bool b) {
+ mUseURI = b;
+ }
+
+ /**
+ * Sets the parent qobject.
+ */
+ virtual void setParent(TQObject *s) {
+ mParent = s;
+ }
+
+ /**
+ * Sets the type (0==read, 1==write)
+ */
+ virtual void setType(int s) {
+ mType = s;
+ }
+
+ /**
+ * @return URL to load.
+ */
+ virtual TQString url() const {
+ return mUrl;
+ }
+
+ /**
+ * @return whether to use UID (false) or URI (true) as an object's unique identifier
+ */
+ virtual bool getUseURI() {
+ return mUseURI;
+ }
+
+ /**
+ * @return parent object
+ */
+ virtual TQObject *parent() {
+ return mParent;
+ }
+
+ /**
+ * @return type
+ */
+ virtual int type() {
+ return mType;
+ }
+
+ /**
+ * @return true if downloading process failed.
+ */
+ virtual bool error() const {
+ return mError;
+ }
+
+ /**
+ * @return an error string.
+ */
+ virtual TQString errorString() const {
+ return mErrorString;
+ }
+
+ /**
+ * @return an error number.
+ */
+ virtual long errorNumber() const {
+ return mErrorNumber;
+ }
+
+protected:
+
+ virtual void run();
+
+ /**
+ * Main run method for jobs. Jobs should not override run() method.
+ * Instead of this they should override this one.
+ * @param carddavRuntime specific libcarddav runtime information. This pointer should not be saved for the usage
+ * outside of runJob.
+ * @return libcarddav response code (see CARDDAV_RESPONSE)
+ */
+ virtual int runJob(runtime_info* carddavRuntime) = 0;
+
+ /**
+ * Some cleaning. Jobs may (and usually should) override this method.
+ */
+ virtual void cleanJob() {
+ mError = false;
+ mErrorString = "";
+ mErrorNumber = 0;
+ }
+
+ /**
+ * Sets an error string to @p err. Also sets an error flag.
+ */
+ void setErrorString(const TQString& str, const long number);
+
+ /**
+ * Process an error.
+ * Subclasses can overwrite this method, if some special error message handling
+ * should be done. Call setErrorString() to set the error after processing is done.
+ * @param err error structure.
+ */
+ virtual void processError(const carddav_error* err);
+
+private:
+
+ TQString mUrl;
+ bool mError;
+ TQString mErrorString;
+ long mErrorNumber;
+ TQObject *mParent;
+ int mType;
+ bool mUseURI;
+
+ void enableCarddavDebug(runtime_info*);
+};
+
+} // namespace KABC
+
+#endif // KABCDAV_JOB_H
+
diff --git a/tderesources/carddav/kabc_carddav.desktop b/tderesources/carddav/kabc_carddav.desktop
new file mode 100644
index 00000000..585d11b3
--- /dev/null
+++ b/tderesources/carddav/kabc_carddav.desktop
@@ -0,0 +1,52 @@
+[Desktop Entry]
+Name=CardDAV Server (e.g. Zimbra Contacts)
+Name[af]=CardDAV bediener (bv. Zimbra Contacts)
+Name[bg]=Сървър CardDAV (e.g. Zimbra Contacts)
+Name[br]=Servijer CardDAV (e.g. Zimbra Contacts)
+Name[ca]=Servidor CardDAV (p.ex. Zimbra Contacts)
+Name[cs]=CardDAV server (např. Zimbra Contacts)
+Name[da]=CardDAV-server (f.eks. Zimbra Contacts)
+Name[de]=CardDAV-Server (z. B. Zimbra Contacts)
+Name[el]=Εξυπηρετητής CardDAV (π.χ. Zimbra Contacts)
+Name[es]=Servidor CardDAV (por ejemplo, Zimbra Contacts)
+Name[et]=CardDAV server (nt. Zimbra Contacts)
+Name[eu]=CardDAV zerbitzaria (adib. Zimbra Contacts)
+Name[fa]=کارساز CardDAV (مثلاً Zimbra Contacts)
+Name[fi]=CardDAV-palvelin (esim. Zimbra Contacts)
+Name[fr]=CardDAV Serveur (ex. Zimbra Contacts)
+Name[fy]=CardDAV-tsjinner (Zimbra Contacts)
+Name[ga]=Freastalaí CardDAV (m.sh. Zimbra Contacts)
+Name[gl]=Servidor CardDAV (e.g. Zimbra Contacts)
+Name[hu]=CardDAV-kiszolgáló (pl. Zimbra Contacts)
+Name[is]=CardDAV þjónn (t.d. Zimbra Contacts)
+Name[it]=Server CardDAV (per es. Zimbra Contacts)
+Name[ja]=CardDAV サーバ (例 Zimbra Contacts)
+Name[ka]=სერვერი CardDAV (მაგ., Zimbra Contacts)
+Name[kk]=CardDAV сервері (мысалы Zimbra Contacts)
+Name[km]=ម៉ាស៊ីន​បម្រើ CardDAV (ឧ. Zimbra Contacts)
+Name[lt]=CardDAV serveris (pvz.: Zimbra Contacts)
+Name[ms]=Pelayan CardDAV (misalnya Zimbra Contacts)
+Name[nb]=CardDAV-tjener (f.eks. Zimbra Contacts)
+Name[nds]=CardDAV-Server (t.B. Zimbra Contacts)
+Name[ne]=समूह DAV सर्भर (जस्तै: खुला ग्रुपवेयर)
+Name[nl]=CardDAV-server (Zimbra Contacts)
+Name[nn]=CardDAV-tenar (t.d. Zimbra Contacts)
+Name[pl]=Serwer CardDAV (np. Zimbra Contacts)
+Name[pt]=Servidor CardDAV (por exemplo Zimbra Contacts)
+Name[pt_BR]=Servidor GroupDav (p. ex. Zimbra Contacts)
+Name[ru]=Сервер CardDAV (например, Zimbra Contacts)
+Name[sk]=CardDAV Server (napr. Zimbra Contacts)
+Name[sl]=Strežnik CardDAV (npr. Zimbra Contacts)
+Name[sr]=CardDAV сервер (нпр. Zimbra Contacts)
+Name[sr@Latn]=CardDAV server (npr. Zimbra Contacts)
+Name[sv]=CardDAV-server (t.ex. Zimbra Contacts)
+Name[ta]=CardDAV சேவகன் (e.g. Zimbra Contacts)
+Name[tr]=CardDAV Sunucusu (ör. Zimbra Contacts)
+Name[uk]=Сервер CardDAV (напр., Zimbra Contacts)
+Name[zh_CN]=CardDAV 服务器(如 Zimbra Contacts)
+Name[zh_TW]=CardDAV 伺服器 (如: Zimbra Contacts)
+X-TDE-Library=kabc_carddav
+Type=Service
+ServiceTypes=KResources/Plugin
+X-TDE-ResourceFamily=contact
+X-TDE-ResourceType=carddav
diff --git a/tderesources/carddav/plugin.cpp b/tderesources/carddav/plugin.cpp
new file mode 100644
index 00000000..d0c4724f
--- /dev/null
+++ b/tderesources/carddav/plugin.cpp
@@ -0,0 +1,47 @@
+/*=========================================================================
+| KCardDAV
+|--------------------------------------------------------------------------
+| (c) 2010 Timothy Pearson
+|
+| This project is released under the GNU General Public License.
+| Please see the file COPYING for more details.
+|--------------------------------------------------------------------------
+| CardDAV resource factory.
+ ========================================================================*/
+
+/*=========================================================================
+| INCLUDES
+ ========================================================================*/
+
+#include "resource.h"
+#include "config.h"
+#include "export.h"
+
+#include <kglobal.h>
+#include <klocale.h>
+
+/*=========================================================================
+| NAMESPACE
+ ========================================================================*/
+
+using namespace KABC;
+
+/*=========================================================================
+| CLASS
+ ========================================================================*/
+
+// Creates the resource factory.
+
+typedef KRES::PluginFactory<ResourceCardDav, ResourceCardDavConfig> CardDavFactory;
+
+extern "C"
+{
+ void *init_kabc_carddav()
+ {
+ TDEGlobal::locale()->insertCatalogue( "tdepimresources" );
+ TDEGlobal::locale()->insertCatalogue( "kres_caldav" );
+ return new CardDavFactory;
+ }
+}
+
+// EOF ========================================================================
diff --git a/tderesources/carddav/preferences.cpp b/tderesources/carddav/preferences.cpp
new file mode 100644
index 00000000..1846ae92
--- /dev/null
+++ b/tderesources/carddav/preferences.cpp
@@ -0,0 +1,239 @@
+/*=========================================================================
+| KABCDAV
+|--------------------------------------------------------------------------
+| (c) 2010 Timothy Pearson
+|
+| This project is released under the GNU General Public License.
+| Please see the file COPYING for more details.
+|--------------------------------------------------------------------------
+| CardDAV resource preferences class.
+ ========================================================================*/
+
+/*=========================================================================
+| INCLUDES
+ ========================================================================*/
+
+#include "preferences.h"
+
+#include <tdewallet.h>
+#include <tqstring.h>
+#include <tqurl.h>
+#include <kdebug.h>
+
+/*=========================================================================
+| NAMESPACES
+ ========================================================================*/
+
+using namespace KABC;
+using namespace KWallet;
+
+/*=========================================================================
+| CONSTANTS
+ ========================================================================*/
+
+const TQString CardDavPrefs::NO_PASSWORD = "";
+const TQString CardDavPrefs::WALLET_FOLDER = "CardDAV resource";
+const TQString CardDavPrefs::WALLET_PWD_SUFFIX = ":carddav_password";
+
+/*=========================================================================
+| METHODS
+ ========================================================================*/
+
+bool CardDavPrefs::setWalletFolder(const TQString& folder) {
+ bool ret = true;
+
+ if (!mNoWallet && NULL != mWallet) {
+ if (!mWallet->hasFolder(folder)) {
+ if (!mWallet->createFolder(folder)) {
+ ret = false;
+ kdWarning() << "can't create the wallet folder for CardDAV passwords";
+ }
+ }
+ if (!mWallet->setFolder(folder)) {
+ ret = false;
+ kdWarning() << "can't set the wallet folder for CardDAV passwords";
+ }
+ } else {
+ // the wallet is inaccessible or not configured
+ ret = false;
+ }
+
+ return ret;
+}
+
+Wallet* CardDavPrefs::getWallet() {
+ Wallet* ret = NULL;
+
+ if (!mNoWallet) {
+ // the wallet is not marked as inaccessible
+
+ if (NULL == mWallet) {
+ kdDebug() << "creating wallet for " + mPrefix << '\n';
+
+ mWallet = Wallet::openWallet(Wallet::NetworkWallet(), 0);
+ if (NULL == mWallet) {
+ mNoWallet = true; // can't open the wallet, mark it inaccessible
+ kdWarning() << "can't create a wallet for CardDAV passwords";
+ } else {
+ if (setWalletFolder(WALLET_FOLDER)) {
+ // reserved
+ } else {
+ // can't set the wallet folder, remove the wallet and mark it inaccessible
+ kdWarning() << "can't set the walet folder for CardDAV passwords";
+ removeWallet(true);
+ }
+ }
+ }
+
+ ret = mWallet;
+ }
+
+ return ret;
+}
+
+void CardDavPrefs::removeWallet(bool noWallet) {
+ delete mWallet;
+ mWallet = NULL;
+ mNoWallet = noWallet;
+}
+
+void CardDavPrefs::addPrefix(const TQString& prefix) {
+ TDEConfigSkeletonItem::List itemList = items();
+ TDEConfigSkeletonItem::List::Iterator it;
+
+ for ( it = itemList.begin(); it != itemList.end(); ++it ) {
+ (*it)->setGroup( prefix + ':' + (*it)->group() );
+ }
+}
+
+bool CardDavPrefs::writePasswordToWallet(const TQString& password) {
+
+ Wallet* w = getWallet();
+
+ bool ret = false;
+ if (NULL != w) {
+ int rc = w->writePassword(mPrefix + WALLET_PWD_SUFFIX, password);
+ if (0 != rc) {
+ kdWarning() << "CardDAV: can't write password to the wallet";
+ } else {
+ ret = true;
+ }
+ }
+
+ return ret;
+}
+
+bool CardDavPrefs::readPasswordFromWallet(TQString& password) {
+ Wallet* w = getWallet();
+
+ bool ret = false;
+ if (NULL != w) {
+ TQString p;
+ int rc = w->readPassword(mPrefix + WALLET_PWD_SUFFIX, p);
+ if (0 == rc) {
+ //CardDavPrefsSkel::setPassword(p);
+ password = p;
+ ret = true;
+ } else {
+ kdWarning() << "CardDAV: can't read password from the wallet";
+ password = NO_PASSWORD;
+ }
+ }
+
+ return ret;
+}
+
+bool CardDavPrefs::removePasswordFromWallet() {
+
+ Wallet* w = getWallet();
+
+ bool ret = false;
+ if (NULL != w) {
+ int rc = w->removeEntry(mPrefix + WALLET_PWD_SUFFIX);
+ if (0 == rc) {
+ ret = true;
+ } else {
+ kdWarning() << "CardDAV: can't remove password from the wallet";
+ }
+ }
+
+ return ret;
+}
+
+void CardDavPrefs::setPassword(const TQString& p) {
+
+ mPassword = p;
+
+ if (rememberPassword()) {
+ writePasswordToWallet(p);
+ }
+}
+
+TQString CardDavPrefs::password() {
+ if (NO_PASSWORD == mPassword) {
+ readPasswordFromWallet(mPassword);
+ }
+ return mPassword;
+}
+
+TQString CardDavPrefs::getusername() {
+ return username();
+}
+
+void CardDavPrefs::setRememberPassword(bool v) {
+ kdDebug() << "remember: " << v << '\n';
+
+ CardDavPrefsSkel::setRememberPassword(v);
+
+ if (!v) {
+ // we should not remember password. If there is one already stored, it must be removed.
+ kdDebug() << "removing password from wallet" << '\n';
+ removePasswordFromWallet();
+ }
+}
+
+void CardDavPrefs::writeConfig() {
+ CardDavPrefsSkel::writeConfig();
+}
+
+void CardDavPrefs::readConfig() {
+
+ CardDavPrefsSkel::readConfig();
+
+ // the password is not in config file, try to restore it from the wallet.
+ /*if (rememberPassword()) {
+ readPasswordFromWallet();
+ }*/
+}
+
+bool CardDavPrefs::getUseURI() {
+ return useURI();
+}
+
+TQString CardDavPrefs::getFullUrl() {
+
+ TQUrl t(url());
+ TQString safeURL;
+ int firstAt;
+
+ t.setUser(username());
+ t.setPassword(password());
+
+ safeURL = t.toString();
+
+ firstAt = safeURL.find("@") + 1;
+ while (safeURL.find("@", firstAt) != -1) {
+ safeURL.replace(safeURL.find("@", firstAt), 1, "%40");
+ }
+
+ // Unencode the username, as Zimbra stupidly rejects the %40
+ safeURL.replace("%40", "@");
+
+ // Encode any spaces, as libcarddav stupidly fails otherwise
+ safeURL.replace(" ", "%20");
+
+ return safeURL;
+}
+
+// EOF ========================================================================
+
diff --git a/tderesources/carddav/preferences.h b/tderesources/carddav/preferences.h
new file mode 100644
index 00000000..96a6377d
--- /dev/null
+++ b/tderesources/carddav/preferences.h
@@ -0,0 +1,155 @@
+/*=========================================================================
+| KCardDAV
+|--------------------------------------------------------------------------
+| (c) 2010 Timothy Pearson
+|
+| This project is released under the GNU General Public License.
+| Please see the file COPYING for more details.
+|--------------------------------------------------------------------------
+| CardDAV resource preferences class.
+ ========================================================================*/
+
+/*=========================================================================
+| INCLUDES
+ ========================================================================*/
+
+#ifndef KABC_CARDDAVPREFS_H
+#define KABC_CARDDAVPREFS_H
+
+#include "prefsskel.h"
+
+#include <tdewallet.h>
+#include <kdebug.h>
+
+class TQString;
+
+namespace KABC {
+
+/*=========================================================================
+| CLASS
+ ========================================================================*/
+
+/**
+ * This class provides access to ResourceCardDav preferences.
+ * It inherits auto-generated CardDavPrefsSkel class to add password-handling code.
+ * KWallet is used for storing passwords.
+ * It also adds code to allow multiple CardDAV resources to store settings in the same
+ * config file.
+ */
+class CardDavPrefs : public CardDavPrefsSkel {
+
+public:
+
+ /**
+ * @param prefix Unique prefix of the resource instance (use identifier() method).
+ */
+ CardDavPrefs(const TQString& prefix)
+ : mWallet(NULL)
+ , mNoWallet(false)
+ , mPrefix(prefix)
+ , mPassword(NO_PASSWORD)
+ {
+ addPrefix(prefix);
+ }
+
+ virtual ~CardDavPrefs() {
+ kdDebug() << "removing wallet" << '\n';
+ removeWallet();
+ }
+
+ virtual void writeConfig();
+ virtual void readConfig();
+
+ /**
+ * Sets a new password. Also, if remember password flag is true,
+ * remembers the password in the wallet. So, if you want the password
+ * to be properly saved, call this method after ensuring the remember flag
+ * is set.
+ */
+ void setPassword(const TQString& p);
+
+ /**
+ * Returns password. The password is taken from the wallet.
+ * May return an empty string, if there is no password available.
+ */
+ TQString password();
+
+ /**
+ * Returns the username.
+ */
+ TQString getusername();
+
+ void setRememberPassword(bool v);
+
+ /**
+ * @return A full URL to connect to CardDAV server (including username and password).
+ */
+ TQString getFullUrl();
+
+ bool getUseURI();
+
+protected:
+
+ /**
+ * Add an unique prefix to TDEConfigGroup, so that different instances of the resource
+ * can use the same config file.
+ * @param prefix Unique prefix of the resource instance.
+ */
+ void addPrefix(const TQString& prefix);
+
+ /**
+ * Returns the wallet or NULL, if the wallet can't be obtained.
+ */
+ KWallet::Wallet* getWallet();
+
+ /**
+ * Tries to set a working folder for the wallet. If the wallet is not configured yet, does nothing.
+ * @param folder the wallet working folder
+ * @return true, if the folder has been set, and false otherwise.
+ */
+ bool setWalletFolder(const TQString& folder);
+
+ /**
+ * Removes the wallet. If @p noWallet is set, the wallet has been marked inaccessible, so that subsequent
+ * getWallet calls will not try to recreate it.
+ */
+ void removeWallet(bool noWallet = false);
+
+ /**
+ * Wrire password to the wallet.
+ * @param password password to write
+ * @return true on success, false on failure
+ */
+ bool writePasswordToWallet(const TQString& password);
+
+ /**
+ * Extracts password from the wallet.
+ * @param password a variable to save read password to.
+ * @return true on success, false on failure
+ */
+ bool readPasswordFromWallet(TQString& password);
+
+ /**
+ * Clears password in the wallet.
+ * @return true on success, false on failure
+ */
+ bool removePasswordFromWallet();
+
+private:
+
+ static const TQString NO_PASSWORD;
+ static const TQString WALLET_FOLDER;
+ static const TQString WALLET_PWD_SUFFIX;
+
+ KWallet::Wallet* mWallet;
+ bool mNoWallet;
+
+ TQString mPrefix;
+ TQString mPassword;
+};
+
+} // namespace KABC
+
+#endif // KABC_CARDDAVPREFS_H
+
+
diff --git a/tderesources/carddav/prefsskel.kcfg b/tderesources/carddav/prefsskel.kcfg
new file mode 100644
index 00000000..054a31b5
--- /dev/null
+++ b/tderesources/carddav/prefsskel.kcfg
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
+ http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
+ <kcfgfile name="tderesources_caldavrc" />
+ <group name="General" >
+
+ <entry key="Url" type="String" >
+ <label>URL</label>
+ </entry>
+
+ <entry key="Username" type="String">
+ <label>User Name</label>
+ </entry>
+
+<!-- <entry key="Password" type="String" >
+ <label>Password</label>
+ </entry>-->
+
+ <entry key="RememberPassword" type="Bool" >
+ <label>Remember password</label>
+ </entry>
+
+ <entry key="UseURI" type="Bool" >
+ <label>Use URI instead of UID</label>
+ </entry>
+
+ </group>
+</kcfg>
diff --git a/tderesources/carddav/prefsskel.kcfgc b/tderesources/carddav/prefsskel.kcfgc
new file mode 100644
index 00000000..12ca40ce
--- /dev/null
+++ b/tderesources/carddav/prefsskel.kcfgc
@@ -0,0 +1,7 @@
+# Code generation options for kconfig_compiler
+File=prefsskel.kcfg
+ClassName=CardDavPrefsSkel
+NameSpace=KABC
+Singleton=false
+Mutators=true
+GlobalEnums=true
diff --git a/tderesources/carddav/reader.cpp b/tderesources/carddav/reader.cpp
new file mode 100644
index 00000000..62645535
--- /dev/null
+++ b/tderesources/carddav/reader.cpp
@@ -0,0 +1,63 @@
+/*=========================================================================
+| KABCDAV
+|--------------------------------------------------------------------------
+| (c) 2010 Timothy Pearson
+|
+| This project is released under the GNU General Public License.
+| Please see the file COPYING for more details.
+|--------------------------------------------------------------------------
+| Remote address book loading.
+ ========================================================================*/
+
+/*=========================================================================
+| INCLUDES
+ ========================================================================*/
+
+#include "reader.h"
+#include <kdebug.h>
+#include <string>
+
+/*=========================================================================
+| NAMESPACE
+ ========================================================================*/
+
+using namespace KABC;
+
+/*=========================================================================
+| METHODS
+ ========================================================================*/
+
+void CardDavReader::cleanJob() {
+ CardDavJob::cleanJob();
+ mData = "";
+}
+
+int CardDavReader::runJob(runtime_info* RT) {
+ kdDebug() << "reader::run, url: " << url() << '\n';
+
+ response* result = carddav_get_response();
+ CARDDAV_RESPONSE res = OK;
+
+ kdDebug() << "getting all objects" << '\n';
+ if (getUseURI() == false)
+ res = carddav_getall_object(result, std::string(url().ascii()).c_str(), RT);
+ else
+ res = carddav_getall_object_by_uri(result, std::string(url().ascii()).c_str(), RT);
+
+ if (OK == res) {
+ kdDebug() << "success" << '\n';
+ if (result->msg) {
+ mData = result->msg;
+ } else {
+ kdDebug() << "empty collection" << '\n';
+ // empty collection
+ mData = "";
+ }
+ }
+
+ carddav_free_response(&result);
+
+ return res;
+}
+
+// EOF ========================================================================
diff --git a/tderesources/carddav/reader.h b/tderesources/carddav/reader.h
new file mode 100644
index 00000000..181d4eb6
--- /dev/null
+++ b/tderesources/carddav/reader.h
@@ -0,0 +1,91 @@
+/*=========================================================================
+| KABCDAV
+|--------------------------------------------------------------------------
+| (c) 2010 Timothy Pearson
+|
+| This project is released under the GNU General Public License.
+| Please see the file COPYING for more details.
+|--------------------------------------------------------------------------
+| Remote address book loading class.
+ ========================================================================*/
+
+/*=========================================================================
+| INCLUDES
+ ========================================================================*/
+
+#ifndef KABCDAV_LOADER_H
+#define KABCDAV_LOADER_H
+
+#include "job.h"
+
+#include <tqstring.h>
+#include <tqdatetime.h>
+
+namespace KABC {
+
+/*=========================================================================
+| CLASS
+ ========================================================================*/
+
+/**
+ * Calendar Reader.
+ */
+class CardDavReader : public CardDavJob {
+
+public:
+
+ /**
+ * @param url URL to load.
+ */
+ CardDavReader(const TQString& url = TQString()) :
+ CardDavJob(url)
+ , mGetAll(true)
+ {
+ }
+
+ /**
+ * Sets a time range. Only event between @p start and @p end will be loaded.
+ * This method call disables the effect of setGetAll() call.
+ * setGetAll() call disables the effect of this method.
+ */
+ void setRange(const TQDateTime& start, const TQDateTime& end) {
+ mGetAll = false;
+ mTimeStart = start;
+ mTimeEnd = end;
+ }
+
+ /**
+ * Sets the flag to load all events from the remote calendar.
+ * This method call disables the effect of setRange() call.
+ * setGetAll() call disables the effect of this method.
+ */
+ void setGetAll() {
+ mGetAll = true;
+ }
+
+ /**
+ * @return downloaded calendar data in iCal format.
+ */
+ TQString data() const {
+ return mData;
+ }
+
+protected:
+
+ virtual int runJob(runtime_info* caldavRuntime);
+
+ virtual void cleanJob();
+
+private:
+
+ TQString mData;
+ bool mGetAll;
+ TQDateTime mTimeStart;
+ TQDateTime mTimeEnd;
+
+};
+
+} // namespace KABC
+
+#endif // KABCDAV_LOADER_H
+
diff --git a/tderesources/carddav/resource.cpp b/tderesources/carddav/resource.cpp
new file mode 100644
index 00000000..dae91c32
--- /dev/null
+++ b/tderesources/carddav/resource.cpp
@@ -0,0 +1,683 @@
+/*=========================================================================
+| KCardDAV
+|--------------------------------------------------------------------------
+| (c) 2010 Timothy Pearson
+|
+| This project is released under the GNU General Public License.
+| Please see the file COPYING for more details.
+|--------------------------------------------------------------------------
+| Main interface to the KResource system.
+ ========================================================================*/
+
+/*=========================================================================
+| INCLUDES
+ ========================================================================*/
+
+#include <string.h>
+#include <unistd.h>
+
+#include <tqurl.h>
+#include <tqmessagebox.h>
+#include <tqapplication.h>
+#include <tqeventloop.h>
+
+#include <kabc/addressee.h>
+#include <kabc/vcardconverter.h>
+
+#include <klocale.h>
+#include <kpassdlg.h>
+
+#include <tqdatetime.h>
+#include <tqmutex.h>
+#include <tqthread.h>
+#include <tqtimer.h>
+
+#ifdef KCARDDAV_DEBUG
+ #include <tqfile.h>
+#endif
+
+#include "resource.h"
+#include "reader.h"
+#include "writer.h"
+
+/*=========================================================================
+| NAMESPACE
+ ========================================================================*/
+
+using namespace KABC;
+
+/*=========================================================================
+| CONSTANTS
+ ========================================================================*/
+
+const unsigned long ResourceCardDav::TERMINATION_WAITING_TIME = 3 * 1000; // 3 seconds
+const int ResourceCardDav::CACHE_DAYS = 90;
+
+const int ResourceCardDav::DEFAULT_RELOAD_INTERVAL = 10;
+const int ResourceCardDav::DEFAULT_SAVE_INTERVAL = 10;
+const int ResourceCardDav::DEFAULT_RELOAD_POLICY = ResourceCached::ReloadInterval;
+const int ResourceCardDav::DEFAULT_SAVE_POLICY = ResourceCached::SaveDelayed;
+
+/*=========================================================================
+| UTILITY
+ ========================================================================*/
+
+#define log(s) kdDebug() << identifier() << ": " << (s) << '\n';
+
+/*=========================================================================
+| CONSTRUCTOR / DESTRUCTOR
+ ========================================================================*/
+
+ResourceCardDav::ResourceCardDav( const TDEConfig *config ) :
+ ResourceCached(config)
+ , readLockout(false)
+ , mAllWritesComplete(false)
+ , mLock(true)
+ , mPrefs(NULL)
+ , mLoader(NULL)
+ , mWriter(NULL)
+ , mProgress(NULL)
+ , mLoadingQueueReady(true)
+ , mWritingQueueReady(true)
+ , mWriteRetryTimer(NULL)
+{
+ log("ResourceCardDav(config)");
+ init();
+
+ if ( config ) {
+ readConfig( config );
+ }
+}
+
+ResourceCardDav::~ResourceCardDav() {
+ log("jobs termination");
+
+ if (mWriteRetryTimer != NULL) {
+ mWriteRetryTimer->stop(); // Unfortunately we cannot do anything at this point; if this timer is still running something is seriously wrong
+ }
+
+ if (mLoader) {
+ readLockout = true;
+ mLoader->terminate();
+ mLoader->wait(TERMINATION_WAITING_TIME);
+ mLoadingQueueReady = true;
+ }
+
+ while ((mWriter->running() == true) || (mWritingQueue.isEmpty() == false) || !mWritingQueueReady) {
+ readLockout = true;
+ sleep(1);
+ tqApp->processEvents(TQEventLoop::ExcludeUserInput);
+ }
+
+ if (mWriter) {
+ mWriter->terminate();
+ }
+
+ log("waiting for jobs terminated");
+
+ if (mWriter) {
+ mWriter->wait(TERMINATION_WAITING_TIME);
+ }
+
+ log("deleting jobs");
+
+ delete mLoader;
+ delete mWriter;
+
+ log("deleting preferences");
+
+ delete mPrefs;
+}
+
+bool ResourceCardDav::isSaving() {
+ doSave();
+ return (((mWriteRetryTimer != NULL) ? 1 : 0) || (mWriter->running() == true) || (mWritingQueue.isEmpty() == false) || !mWritingQueueReady || readLockout);
+}
+
+/*=========================================================================
+| GENERAL METHODS
+ ========================================================================*/
+
+bool ResourceCardDav::load() {
+ bool syncCache = true;
+
+ if ((mLoadingQueueReady == false) || (mLoadingQueue.isEmpty() == false) || (mLoader->running() == true) || (isSaving() == true)) {
+ return true; // Silently fail; the user has obviously not responded to a dialog and we don't need to pop up more of them!
+ }
+
+ log(TQString("doLoad(%1)").arg(syncCache));
+
+ // FIXME KABC
+ //clearCache();
+
+ log("loading from cache");
+ //disableChangeNotification();
+ loadCache();
+ //enableChangeNotification();
+ clearChanges();
+ addressBook()->emitAddressBookChanged();
+ emit loadingFinished( this );
+
+ log("starting download job");
+ startLoading(mPrefs->getFullUrl());
+
+ return true;
+}
+
+bool ResourceCardDav::doSave() {
+ bool syncCache = true;
+
+ log(TQString("doSave(%1)").arg(syncCache));
+
+ if (!hasChanges()) {
+ log("no changes");
+ return true;
+ }
+
+ log("saving cache");
+ saveCache();
+
+ // Delete any queued read jobs
+ mLoadingQueue.clear();
+
+ // See if there is a running read thread and terminate it
+ if (mLoader->running() == true) {
+ mLoader->terminate();
+ mLoader->wait(TERMINATION_WAITING_TIME);
+ mLoadingQueueReady = true;
+ }
+
+ log("start writing job");
+ if (startWriting(mPrefs->getFullUrl()) == true) {
+ log("clearing changes");
+ // FIXME: Calling clearChanges() here is not the ideal way since the
+ // upload might fail, but there is no other place to call it...
+ clearChanges();
+ if (mWriteRetryTimer != NULL) {
+ if (mWriteRetryTimer->isActive() == false) {
+ disconnect( mWriteRetryTimer, TQT_SIGNAL(timeout()), this, TQT_SLOT(doSave()) );
+ delete mWriteRetryTimer;
+ mWriteRetryTimer = NULL;
+ }
+ }
+ return true;
+ }
+ else return true; // We do not need to alert the user to this transient failure; a timer has been started to retry the save
+}
+
+
+bool ResourceCardDav::save( Ticket* ticket ) {
+ // To suppress warning about doSave() method hides ResourceCached::doSave(Ticket)
+ //return ResourceCached::doSave();
+ return doSave();
+}
+
+KABC::Lock* ResourceCardDav::lock() {
+ log("lock()");
+ return &mLock;
+}
+
+void ResourceCardDav::readConfig( const TDEConfig *config ) {
+ log("readConfig");
+ mPrefs->readConfig();
+ // FIXME KABC
+ //ResourceCached::readConfig(config);
+}
+
+void ResourceCardDav::writeConfig( TDEConfig *config ) {
+ log("writeConfig()");
+ Resource::writeConfig(config);
+ mPrefs->writeConfig();
+ ResourceCached::writeConfig(config);
+}
+
+CardDavPrefs* ResourceCardDav::createPrefs() const {
+ log("createPrefs()");
+ CardDavPrefs* p = new CardDavPrefs(identifier());
+ return p;
+}
+
+void ResourceCardDav::init() {
+// // default settings
+// setReloadInterval(DEFAULT_RELOAD_INTERVAL);
+// setReloadPolicy(DEFAULT_RELOAD_POLICY);
+// setSaveInterval(DEFAULT_SAVE_INTERVAL);
+// setSavePolicy(DEFAULT_SAVE_POLICY);
+
+ // creating preferences
+ mPrefs = createPrefs();
+
+ // creating reader/writer instances
+ mLoader = new CardDavReader;
+ mWriter = new CardDavWriter;
+
+ // creating jobs
+ // TQt4 handles this quite differently, as shown below,
+ // whereas TQt3 needs events (see ::event())
+// connect(mLoader, TQT_SIGNAL(finished()), this, TQT_SLOT(loadFinished()));
+// connect(mWriter, TQT_SIGNAL(finished()), this, TQT_SLOT(writingFinished()));
+
+ setType("ResourceCardDav");
+}
+
+void ResourceCardDav::ensureReadOnlyFlagHonored() {
+ //disableChangeNotification();
+
+ // FIXME KABC
+ //Incidence::List inc( rawIncidences() );
+ //setIncidencesReadOnly(inc, readOnly());
+
+ //enableChangeNotification();
+
+ if (addressBook() != NULL) {
+ addressBook()->emitAddressBookChanged();
+ }
+}
+
+void ResourceCardDav::setReadOnly(bool v) {
+ KRES::Resource::setReadOnly(v);
+ log("ensuring read only flag honored");
+ ensureReadOnlyFlagHonored();
+}
+
+void ResourceCardDav::updateProgressBar(int direction) {
+ int current_queued_events;
+ static int original_queued_events;
+
+ // See if anything is in the queues
+ current_queued_events = mWritingQueue.count() + mLoadingQueue.count();
+ if ((direction == 0) && (mLoader->running() == true)) current_queued_events++;
+ if ((direction == 1) && (mWriter->running() == true)) current_queued_events++;
+ if (current_queued_events > original_queued_events) {
+ original_queued_events = current_queued_events;
+ }
+
+ if (current_queued_events == 0) {
+ if ( mProgress != NULL) {
+ mProgress->setComplete();
+ mProgress = NULL;
+ original_queued_events = 0;
+ }
+ }
+ else {
+ if (mProgress == NULL) {
+ if (direction == 0) mProgress = KPIM::ProgressManager::createProgressItem(KPIM::ProgressManager::getUniqueID(), i18n("Downloading Contacts") );
+ if (direction == 1) mProgress = KPIM::ProgressManager::createProgressItem(KPIM::ProgressManager::getUniqueID(), i18n("Uploading Contacts") );
+ }
+ mProgress->setProgress( ((((float)original_queued_events-(float)current_queued_events)*100)/(float)original_queued_events) );
+ }
+}
+
+/*=========================================================================
+| READING METHODS
+ ========================================================================*/
+
+void ResourceCardDav::loadingQueuePush(const LoadingTask *task) {
+ if ((mLoadingQueue.isEmpty() == true) && (mLoader->running() == false)) {
+ mLoadingQueue.enqueue(task);
+ updateProgressBar(0);
+ loadingQueuePop();
+ }
+}
+
+void ResourceCardDav::loadingQueuePop() {
+ if (!mLoadingQueueReady || mLoadingQueue.isEmpty() || (isSaving() == true)) {
+ return;
+ }
+
+ if (!mLoader) {
+ log("loader == NULL");
+ return;
+ }
+
+ // Loading queue and mLoadingQueueReady flag are not shared resources, i.e. only one thread has an access to them.
+ // That's why no mutexes are required.
+ LoadingTask *t = mLoadingQueue.head();
+
+ mLoader->setUrl(t->url);
+ mLoader->setParent(this);
+ mLoader->setType(0);
+ mLoader->setUseURI(mPrefs->getUseURI());
+
+ mLoadingQueueReady = false;
+
+ log("starting actual download job");
+ mLoader->start(TQThread::LowestPriority);
+
+ // if all ok, removing the task from the queue
+ mLoadingQueue.dequeue();
+ updateProgressBar(0);
+
+ delete t;
+}
+
+void ResourceCardDav::startLoading(const TQString& url) {
+ LoadingTask *t = new LoadingTask;
+ t->url = url;
+ loadingQueuePush(t);
+}
+
+void ResourceCardDav::loadFinished() {
+ CardDavReader* loader = mLoader;
+
+ log("load finished");
+
+ if (!loader) {
+ log("loader is NULL");
+ return;
+ }
+
+ if (loader->error()) {
+ if (loader->errorNumber() == -401) {
+ if (NULL != mPrefs) {
+ TQCString newpass;
+ if (KPasswordDialog::getPassword (newpass, TQString("<b>") + i18n("Remote authorization required") + TQString("</b><p>") + i18n("Please input the password for") + TQString(" ") + mPrefs->getusername(), NULL) != 1) {
+ log("load error: " + loader->errorString() );
+ addressBook()->error(TQString("[%1] ").arg(abs(loader->errorNumber())) + loader->errorString());
+ }
+ else {
+ // Set new password and try again
+ mPrefs->setPassword(TQString(newpass));
+ startLoading(mPrefs->getFullUrl());
+ }
+ }
+ else {
+ log("load error: " + loader->errorString() );
+ addressBook()->error(TQString("[%1] ").arg(abs(loader->errorNumber())) + loader->errorString());
+ }
+ }
+ else {
+ log("load error: " + loader->errorString() );
+ addressBook()->error(TQString("[%1] ").arg(abs(loader->errorNumber())) + loader->errorString());
+ }
+ } else {
+ log("successful load");
+ TQString data = loader->data();
+
+ if (!data.isNull() && !data.isEmpty()) {
+ data.replace("\r\n", "\n"); // to avoid \r\n becomes \n\n after the next line
+ data.replace('\r', '\n');
+
+ log("trying to parse...");
+ if (parseData(data)) {
+ log("... parsing is ok");
+ log("clearing changes");
+ //enableChangeNotification();
+ clearChanges();
+ addressBook()->emitAddressBookChanged();
+ emit loadingFinished( this );
+ }
+ }
+ }
+
+ // Loading queue and mLoadingQueueReady flag are not shared resources, i.e. only one thread has an access to them.
+ // That's why no mutexes are required.
+ mLoader->terminate();
+ mLoader->wait(TERMINATION_WAITING_TIME);
+ mLoadingQueueReady = true;
+ updateProgressBar(0);
+ loadingQueuePop();
+}
+
+bool ResourceCardDav::checkData(const TQString& data) {
+ log("checking the data");
+
+ KABC::VCardConverter converter;
+ bool ret = true;
+ KABC::VCardConverter conv;
+ Addressee::List addressees = conv.parseVCards( data );
+ if (addressees.isEmpty() == true) {
+ ret = false;
+ }
+
+ return ret;
+}
+
+bool ResourceCardDav::parseData(const TQString& data) {
+ log("parseData()");
+
+ bool ret = true;
+
+ // check if the data is OK
+ // May be it's not efficient (parsing is done twice), but it should be safe
+ if (!checkData(data)) {
+ addressBook()->error(i18n("Parsing calendar data failed."));
+ return false;
+ }
+
+ // FIXME KABC
+ //log("clearing cache");
+ //clearCache();
+
+ //disableChangeNotification();
+
+ log("actually parsing the data");
+
+ KABC::VCardConverter conv;
+ Addressee::List addressees = conv.parseVCards( data );
+ Addressee::List::ConstIterator it;
+ for( it = addressees.begin(); it != addressees.end(); ++it ) {
+ KABC::Addressee addr = *it;
+ if ( !addr.isEmpty() ) {
+ addr.setResource( this );
+
+ insertAddressee( addr );
+ clearChange( addr );
+ }
+ }
+
+ // debug code here -------------------------------------------------------
+#ifdef KCARDDAV_DEBUG
+ const TQString fout_path = "/tmp/kcarddav_download_" + identifier() + ".tmp";
+
+ TQFile fout(fout_path);
+ if (fout.open(IO_WriteOnly | IO_Append)) {
+ TQTextStream sout(&fout);
+ sout << "---------- " << resourceName() << ": --------------------------------\n";
+ sout << data << "\n";
+ fout.close();
+ } else {
+ addressBook()->error(i18n("can't open file"));
+ }
+#endif // KCARDDAV_DEBUG
+ // end of debug code ----------------------------------------------------
+
+ //enableChangeNotification();
+
+ if (ret) {
+ log("parsing is ok");
+ //if ( !noReadOnlyOnLoad() && readOnly() ) {
+ if ( readOnly() ) {
+ log("ensuring read only flag honored");
+ ensureReadOnlyFlagHonored();
+ }
+ log("cleaning up cache");
+ cleanUpCache( addressees );
+ log("saving to cache");
+ saveCache();
+ }
+
+ return ret;
+}
+
+/*=========================================================================
+| WRITING METHODS
+ ========================================================================*/
+
+Ticket *ResourceCardDav::requestSaveTicket()
+{
+ if ( !addressBook() ) {
+ kdDebug(5700) << "no addressbook" << endl;
+ return 0;
+ }
+
+ return createTicket( this );
+}
+
+void ResourceCardDav::releaseSaveTicket( Ticket *ticket )
+{
+ delete ticket;
+}
+
+void ResourceCardDav::writingQueuePush(const WritingTask *task) {
+// printf("task->added: %s\n\r", task->added.ascii());
+// printf("task->deleted: %s\n\r", task->deleted.ascii());
+// printf("task->changed: %s\n\r", task->changed.ascii());
+ mWritingQueue.enqueue(task);
+ updateProgressBar(1);
+ writingQueuePop();
+}
+
+void ResourceCardDav::writingQueuePop() {
+ if (!mWritingQueueReady || mWritingQueue.isEmpty()) {
+ return;
+ }
+
+ if (!mWriter) {
+ log("writer == NULL");
+ return;
+ }
+
+ // Writing queue and mWritingQueueReady flag are not shared resources, i.e. only one thread has an access to them.
+ // That's why no mutexes are required.
+ WritingTask *t = mWritingQueue.head();
+
+ log("writingQueuePop: url = " + t->url);
+
+ mWriter->setUrl(t->url);
+ mWriter->setParent(this);
+ mWriter->setType(1);
+ mWriter->setUseURI(mPrefs->getUseURI());
+
+#ifdef KCARDDAV_DEBUG
+ const TQString fout_path = "/tmp/kcarddav_upload_" + identifier() + ".tmp";
+
+ TQFile fout(fout_path);
+ if (fout.open(IO_WriteOnly | IO_Append)) {
+ TQTextStream sout(&fout);
+ sout << "---------- " << resourceName() << ": --------------------------------\n";
+ sout << "================== Added:\n" << t->added << "\n";
+ sout << "================== Changed:\n" << t->changed << "\n";
+ sout << "================== Deleted:\n" << t->deleted << "\n";
+ fout.close();
+ } else {
+ addressBook()->error(i18n("can't open file"));
+ }
+#endif // debug
+
+ mWriter->setAddedObjects(t->added);
+ mWriter->setChangedObjects(t->changed);
+ mWriter->setDeletedObjects(t->deleted);
+
+ mWritingQueueReady = false;
+
+ log("starting actual write job");
+ mWriter->start(TQThread::LowestPriority);
+
+ // if all ok, remove the task from the queue
+ mWritingQueue.dequeue();
+ updateProgressBar(1);
+
+ delete t;
+}
+
+bool ResourceCardDav::event ( TQEvent * e ) {
+ if (e->type() == 1000) {
+ // Read done
+ loadFinished();
+ return TRUE;
+ }
+ else if (e->type() == 1001) {
+ // Write done
+ writingFinished();
+ return TRUE;
+ }
+ else return FALSE;
+}
+
+bool ResourceCardDav::startWriting(const TQString& url) {
+ log("startWriting: url = " + url);
+
+ WritingTask *t = new WritingTask;
+ KABC::VCardConverter converter;
+
+ // WARNING: This will segfault if a separate read or write thread
+ // modifies the calendar with clearChanges() or similar
+ // Before these calls are made any existing read (and maybe write) threads should be finished
+ if ((mLoader->running() == true) || (mLoadingQueue.isEmpty() == false) || (mWriter->running() == true) || (mWritingQueue.isEmpty() == false)) {
+ if (mWriteRetryTimer == NULL) {
+ mWriteRetryTimer = new TQTimer(this);
+ connect( mWriteRetryTimer, TQT_SIGNAL(timeout()), TQT_SLOT(doSave()) );
+ }
+ mWriteRetryTimer->start(1000, TRUE);
+ return false;
+ }
+
+ KABC::Addressee::List added = addedAddressees();
+ KABC::Addressee::List changed = changedAddressees();
+ KABC::Addressee::List deleted = deletedAddressees();
+
+ t->url = url;
+ // FIXME KABC
+ t->added = converter.createVCards(added); // This crashes when an event is added from the remote server and save() is subsequently called
+ t->changed = converter.createVCards(changed);
+ t->deleted = converter.createVCards(deleted);
+
+ writingQueuePush(t);
+
+ return true;
+}
+
+void ResourceCardDav::writingFinished() {
+ log("writing finished");
+
+ if (!mWriter) {
+ log("mWriter is NULL");
+ return;
+ }
+
+ if (mWriter->error() && (abs(mWriter->errorNumber()) != 207)) {
+ if (mWriter->errorNumber() == -401) {
+ if (NULL != mPrefs) {
+ TQCString newpass;
+ if (KPasswordDialog::getPassword (newpass, TQString("<b>") + i18n("Remote authorization required") + TQString("</b><p>") + i18n("Please input the password for") + TQString(" ") + mPrefs->getusername(), NULL) != 1) {
+ log("write error: " + mWriter->errorString());
+ addressBook()->error(TQString("[%1] ").arg(abs(mWriter->errorNumber())) + mWriter->errorString());
+ }
+ else {
+ // Set new password and try again
+ mPrefs->setPassword(TQString(newpass));
+ startWriting(mPrefs->getFullUrl());
+ }
+ }
+ else {
+ log("write error: " + mWriter->errorString());
+ addressBook()->error(TQString("[%1] ").arg(abs(mWriter->errorNumber())) + mWriter->errorString());
+ }
+ }
+ else {
+ log("write error: " + mWriter->errorString());
+ addressBook()->error(TQString("[%1] ").arg(abs(mWriter->errorNumber())) + mWriter->errorString());
+ }
+ } else {
+ log("success");
+ // is there something to do here?
+ }
+
+ // Writing queue and mWritingQueueReady flag are not shared resources, i.e. only one thread has an access to them.
+ // That's why no mutexes are required.
+ mWriter->terminate();
+ mWriter->wait(TERMINATION_WAITING_TIME);
+ mWritingQueueReady = true;
+ updateProgressBar(1);
+ writingQueuePop();
+
+ // If a URI is required we will need to retrieve it from the server after the new record is committed...
+ if (mPrefs->getUseURI() == true) {
+ startLoading(mPrefs->getFullUrl());
+ }
+}
+
+#include "resource.moc"
+
+// EOF ========================================================================
diff --git a/tderesources/carddav/resource.h b/tderesources/carddav/resource.h
new file mode 100644
index 00000000..cf5090e5
--- /dev/null
+++ b/tderesources/carddav/resource.h
@@ -0,0 +1,227 @@
+/*=========================================================================
+| KCardDAV
+|--------------------------------------------------------------------------
+| (c) 2010 Timothy Pearson
+|
+| This project is released under the GNU General Public License.
+| Please see the file COPYING for more details.
+|--------------------------------------------------------------------------
+| Main interface to the KResource system.
+ ========================================================================*/
+
+/*=========================================================================
+| INCLUDES
+ ========================================================================*/
+
+#ifndef KABC_RESOURCECARDDAV_H
+#define KABC_RESOURCECARDDAV_H
+
+#include "preferences.h"
+#include <tqthread.h>
+#include <tqptrqueue.h>
+
+#include <kabcresourcecached.h>
+#include <libtdepim/progressmanager.h>
+
+#include <kabc/locknull.h>
+
+#include <tdepimmacros.h>
+#include <kconfig.h>
+
+namespace KABC {
+
+class CardDavReader;
+class CardDavWriter;
+
+/*=========================================================================
+| CLASS
+ ========================================================================*/
+
+/**
+ * This class provides a resource for accessing calendars via CardDAV protocol.
+ */
+class KDE_EXPORT ResourceCardDav : public ResourceCached
+{
+ Q_OBJECT
+
+
+public:
+
+ explicit ResourceCardDav( const TDEConfig *config );
+ virtual ~ResourceCardDav();
+
+ void readConfig( const TDEConfig *config );
+ void writeConfig( TDEConfig *config );
+
+ virtual Ticket *requestSaveTicket();
+ virtual void releaseSaveTicket( Ticket* );
+
+ /**
+ * @return This resource preferences.
+ */
+ CardDavPrefs* prefs() {
+ return mPrefs;
+ }
+
+ /**
+ * @return This resource preferences.
+ */
+ const CardDavPrefs* prefs() const {
+ return mPrefs;
+ }
+
+ virtual void setReadOnly(bool v);
+
+ bool isSaving();
+
+protected slots:
+
+ void loadFinished();
+
+ virtual bool doSave();
+
+ void writingFinished();
+
+protected:
+
+ struct LoadingTask {
+ TQString url;
+ };
+
+ struct WritingTask {
+ TQString url;
+ TQString added;
+ TQString changed;
+ TQString deleted;
+ };
+
+
+// virtual bool doLoad( bool syncCache );
+// virtual bool doSave( bool syncCache );
+
+ virtual bool load();
+
+ virtual bool save( Ticket* ticket );
+
+ virtual KABC::Lock* lock();
+
+ /**
+ * Creates prefs and configures them.
+ * @return a newly created preferences object. It should be removed by the caller.
+ */
+ CardDavPrefs* createPrefs() const;
+
+ /**
+ * Initializes internal state.
+ * Particulary, sets save and reload policies to default values,
+ * creates writing and reading jobs and preferences objects.
+ */
+ void init();
+
+ /**
+ * Updates the progress bar
+ */
+ void updateProgressBar(int direction);
+
+ /**
+ * Initiates calendar loading process.
+ * @param url URL to load calendar data from.
+ */
+ void startLoading(const TQString& url);
+
+ /**
+ * Checks if the data is correct and can be parsed.
+ * @param data ical string to check.
+ * @return true if the data is correct, false otherwise.
+ */
+ bool checkData(const TQString& data);
+
+ /**
+ * Parses the data and adds events to the calendar.
+ * @param data calendar data.
+ * @return true on success, false on fail.
+ */
+ bool parseData(const TQString& data);
+
+ /**
+ * Initiates calendar writing process.
+ * @param url URL to save calendar data to.
+ * @return true if write was queued successfully, false if not
+ */
+ bool startWriting(const TQString& url);
+
+ /**
+ * Ensures incidences' read-only states are the same as the calendar's read-only state.
+ */
+ void ensureReadOnlyFlagHonored();
+
+ /**
+ * If the loading queue is empty or the loader is not ready, does nothing.
+ * Otherwise, pops a head element and starts a loading process for it.
+ */
+ void loadingQueuePop();
+
+ /**
+ * Pushes the given loading task to the loading queue.
+ * Then calls loadingQueuePop.
+ */
+ void loadingQueuePush(const LoadingTask *task);
+
+ /**
+ * If the writing queue is empty or the writer is not ready, does nothing.
+ * Otherwise, pops a head element and starts a writing process for it.
+ */
+ void writingQueuePop();
+
+ /**
+ * Pushes the given writing task to the writing queue.
+ * Then calls writingQueuePop.
+ */
+ void writingQueuePush(const WritingTask *task);
+
+ virtual bool event ( TQEvent * e );
+
+private:
+
+ // constants: =============================================================
+
+ /// Termination waiting time in milliseconds. Used to terminate job threads.
+ static const unsigned long TERMINATION_WAITING_TIME;
+
+ /**
+ * Resource caches only events which are from the interval [-CACHE_DAYS, CACHE_DAYS].
+ */
+ static const int CACHE_DAYS;
+
+ static const int DEFAULT_RELOAD_INTERVAL;
+ static const int DEFAULT_SAVE_INTERVAL;
+ static const int DEFAULT_RELOAD_POLICY;
+ static const int DEFAULT_SAVE_POLICY;
+
+ bool readLockout;
+ bool mAllWritesComplete;
+
+ // members: ===============================================================
+
+ KABC::LockNull mLock;
+ CardDavPrefs* mPrefs;
+ CardDavReader* mLoader;
+ CardDavWriter* mWriter;
+ KPIM::ProgressItem *mProgress;
+
+ bool mLoadingQueueReady;
+ TQPtrQueue<LoadingTask> mLoadingQueue;
+
+ bool mWritingQueueReady;
+ TQPtrQueue<WritingTask> mWritingQueue;
+
+ TQTimer *mWriteRetryTimer;
+
+};
+
+
+
+} // namespace KABC
+
+#endif // KABC_RESOURCECARDDAV_H
+
diff --git a/tderesources/carddav/uninstall.desktop b/tderesources/carddav/uninstall.desktop
new file mode 100644
index 00000000..e1e3e173
--- /dev/null
+++ b/tderesources/carddav/uninstall.desktop
@@ -0,0 +1,2 @@
+[Desktop Entry]
+Hidden=true
diff --git a/tderesources/carddav/writer.cpp b/tderesources/carddav/writer.cpp
new file mode 100644
index 00000000..68bf126d
--- /dev/null
+++ b/tderesources/carddav/writer.cpp
@@ -0,0 +1,106 @@
+/*=========================================================================
+| KABCDAV
+|--------------------------------------------------------------------------
+| (c) 2010 Timothy Pearson
+|
+| This project is released under the GNU General Public License.
+| Please see the file COPYING for more details.
+|--------------------------------------------------------------------------
+| Remote address book writing class.
+ ========================================================================*/
+
+/*=========================================================================
+| INCLUDES
+ ========================================================================*/
+
+#include "writer.h"
+#include <kdebug.h>
+#include <string>
+
+/*=========================================================================
+| DEFINES
+ ========================================================================*/
+
+// Use carddav_modify_object() function.
+// If it's not set, a pair of carddav_delete_object/carddav_add_object
+// is used for modifying objects.
+// It's done, because, for some reason, Zimbra returns an error
+// on carddav_modify_object.
+//#define USE_CARDDAV_MODIFY
+
+/*=========================================================================
+| NAMESPACE
+ ========================================================================*/
+
+using namespace KABC;
+
+/*=========================================================================
+| METHODS
+ ========================================================================*/
+
+void CardDavWriter::cleanJob() {
+ CardDavJob::cleanJob();
+}
+
+int CardDavWriter::runJob(runtime_info* RT) {
+ kdDebug() << "writer::run, url: " << url() << "\n";
+
+ int res = OK;
+
+ kdDebug() << "pushing added objects" << '\n';
+ res = pushObjects(mAdded, carddav_add_object, OK, RT);
+ if (OK == res) {
+#ifdef USE_CARDDAV_MODIFY
+ kdDebug() << "pushing changed objects" << '\n';
+ if (getUseURI() == false)
+ res = pushObjects(mChanged, carddav_modify_object, OK, RT);
+ else
+ res = pushObjects(mChanged, carddav_modify_object_by_uri, OK, RT);
+ if (OK == res) {
+ kdDebug() << "pushing deleted objects" << '\n';
+ while (mDeleted.contains("BEGIN:VCARD", TRUE) > 0) {
+ int endLocation = mDeleted.find("END:VCARD", 0, TRUE);
+ TQString deletedCurSeq = mDeleted.mid(0, endLocation+9);
+ mDeleted = mDeleted.remove(0, endLocation+9);
+ if (getUseURI() == false)
+ res = pushObjects(deletedCurSeq, carddav_delete_object, OK, RT);
+ else
+ res = pushObjects(deletedCurSeq, carddav_delete_object_by_uri, OK, RT);
+ }
+ }
+#else // if USE_CARDDAV_MODIFY
+ kdDebug() << "pushing changed objects (delete)" << '\n';
+ if (getUseURI() == false)
+ res = pushObjects(mChanged, carddav_delete_object, OK, RT);
+ else
+ res = pushObjects(mChanged, carddav_delete_object_by_uri, OK, RT);
+ if (OK == res) {
+ kdDebug() << "pushing changed objects (add)" << '\n';
+ if (getUseURI() == false)
+ res = pushObjects(mChanged, carddav_add_object, OK, RT);
+ else
+ res = pushObjects(mChanged, carddav_add_object, OK, RT);
+ if (OK == res) {
+ kdDebug() << "pushing deleted objects" << '\n';
+ while (mDeleted.contains("BEGIN:VCARD", TRUE) > 0) {
+ int endLocation = mDeleted.find("END:VCARD", 0, TRUE);
+ TQString deletedCurSeq = mDeleted.mid(0, endLocation+9);
+ mDeleted = mDeleted.remove(0, endLocation+9);
+ if (getUseURI() == false)
+ res = pushObjects(deletedCurSeq, carddav_delete_object, OK, RT);
+ else
+ res = pushObjects(deletedCurSeq, carddav_delete_object_by_uri, OK, RT);
+ }
+ }
+ }
+#endif // if USE_CARDDAV_MODIFY
+ }
+
+ if (OK != res) {
+ clearObjects();
+ }
+
+ return res;
+}
+
+// EOF ========================================================================
diff --git a/tderesources/carddav/writer.h b/tderesources/carddav/writer.h
new file mode 100644
index 00000000..4af3fe36
--- /dev/null
+++ b/tderesources/carddav/writer.h
@@ -0,0 +1,109 @@
+/*=========================================================================
+| KCardDAV
+|--------------------------------------------------------------------------
+| (c) 2010 Timothy Pearson
+|
+| This project is released under the GNU General Public License.
+| Please see the file COPYING for more details.
+|--------------------------------------------------------------------------
+| Remote address book writing class.
+ ========================================================================*/
+
+/*=========================================================================
+| INCLUDES
+ ========================================================================*/
+
+#ifndef KCARDDAV_WRITER_H
+#define KCARDDAV_WRITER_H
+
+#include "job.h"
+
+#include <string>
+#include <tqstring.h>
+#include <tqdatetime.h>
+
+namespace KABC {
+
+/*=========================================================================
+| CLASS
+ ========================================================================*/
+
+/**
+ * Calendar writer.
+ */
+class CardDavWriter : public CardDavJob {
+
+public:
+
+ /**
+ * @param url URL to load.
+ */
+ CardDavWriter(const TQString& url = TQString()) :
+ CardDavJob(url)
+ {
+ clearObjects();
+ }
+
+ /**
+ * Sets the information about added incidences writer should send to server.
+ * @param s icalendar-formatted string consists of all added incidences plus necessary calendar info.
+ * May be an empty string, which means there is no added incidences to send.
+ */
+ void setAddedObjects(const TQString& s) {
+ mAdded = s;
+ }
+
+ /**
+ * Sets the information about changed incidences writer should send to server.
+ * @param s icalendar-formatted string consists of all changed incidences plus necessary calendar info.
+ * May be an empty string, which means there is no changed incidences to send.
+ */
+ void setChangedObjects(const TQString& s) {
+ mChanged = s;
+ }
+
+ /**
+ * Sets the information about deleted incidences writer should send to server.
+ * @param s icalendar-formatted string consists of all deleted incidences plus necessary calendar info.
+ * May be an empty string, which means there is no deleted incidences to send.
+ */
+ void setDeletedObjects(const TQString& s) {
+ mDeleted = s;
+ }
+
+ /**
+ * Clear all the information previously set.
+ */
+ void clearObjects() {
+ setAddedObjects("");
+ setChangedObjects("");
+ setDeletedObjects("");
+ }
+
+protected:
+
+ virtual int runJob(runtime_info* caldavRuntime);
+
+ virtual void cleanJob();
+
+ /// Just a wrapper above libcaldav functions.
+ template<typename Operation>
+ int pushObjects(const TQString& data, Operation op, int okCode, runtime_info* RT) {
+ int r = okCode;
+ if (!data.isNull() && !data.isEmpty()) {
+ r = op(std::string(data.ascii()).c_str(), std::string(url().ascii()).c_str(), RT);
+ }
+ return r;
+ }
+
+private:
+
+ TQString mAdded;
+ TQString mChanged;
+ TQString mDeleted;
+};
+
+} // namespace KABC
+
+#endif // KCARDDAV_WRITER_H
+