diff options
author | Timothy Pearson <[email protected]> | 2013-01-26 13:17:50 -0600 |
---|---|---|
committer | Timothy Pearson <[email protected]> | 2013-01-26 13:17:50 -0600 |
commit | b363d2579af0a11b77e698aed2e1021c2233b644 (patch) | |
tree | f4a47b87354b7a6a3b266c8121bd8ddaeb7accaa /tderesources/lib | |
parent | 61bddfe3a7226b18c68a76124b727c736f431688 (diff) | |
download | tdepim-b363d2579af0a11b77e698aed2e1021c2233b644.tar.gz tdepim-b363d2579af0a11b77e698aed2e1021c2233b644.zip |
Rename a number of libraries and executables to avoid conflicts with KDE4
Diffstat (limited to 'tderesources/lib')
43 files changed, 5779 insertions, 0 deletions
diff --git a/tderesources/lib/CMakeLists.txt b/tderesources/lib/CMakeLists.txt new file mode 100644 index 000000000..0289f3e8a --- /dev/null +++ b/tderesources/lib/CMakeLists.txt @@ -0,0 +1,51 @@ +################################################# +# +# (C) 2010-2011 Serghei Amelian +# serghei (DOT) amelian (AT) gmail.com +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +include_directories( + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_SOURCE_DIR} + ${CMAKE_SOURCE_DIR}/libtdepim + ${TDE_INCLUDE_DIR} + ${TQT_INCLUDE_DIRS} +) + +link_directories( + ${TQT_LIBRARY_DIRS} +) + + +##### kgroupwarebase (shared) ################### + +tde_add_library( kgroupwarebase SHARED AUTOMOC + SOURCES + folderlister.cpp folderconfig.cpp folderlistview.cpp folderselectdialog.cpp + groupwaredataadaptor.cpp groupwaredownloadjob.cpp calendaradaptor.cpp + addressbookadaptor.cpp groupwareresourcejob.cpp groupwareuploadjob.cpp + kcal_resourcegroupwarebase.cpp kabc_resourcegroupwarebase.cpp + tderesources_groupwareprefs.kcfgc kcal_resourcegroupwarebaseconfig.cpp + kabc_resourcegroupwarebaseconfig.cpp kcal_cachesettingsdlg.cpp + VERSION 0.0.0 + LINK tdepim-shared + DESTINATION ${LIB_INSTALL_DIR} +) + + +##### kgroupwaredav (shared) #################### + +tde_add_library( kgroupwaredav SHARED AUTOMOC + SOURCES + davcalendaradaptor.cpp davaddressbookadaptor.cpp webdavhandler.cpp + davgroupwareglobals.cpp + VERSION 0.0.0 + LINK kgroupwarebase-shared + DESTINATION ${LIB_INSTALL_DIR} +) diff --git a/tderesources/lib/Makefile.am b/tderesources/lib/Makefile.am new file mode 100644 index 000000000..a430fd8b2 --- /dev/null +++ b/tderesources/lib/Makefile.am @@ -0,0 +1,35 @@ +INCLUDES = -I$(top_srcdir) $(all_includes) + +lib_LTLIBRARIES = libkgroupwarebase.la libkgroupwaredav.la + +libkgroupwarebase_la_SOURCES = folderlister.cpp folderconfig.cpp folderlistview.cpp folderselectdialog.cpp \ + groupwaredataadaptor.cpp groupwaredownloadjob.cpp \ + calendaradaptor.cpp addressbookadaptor.cpp groupwareresourcejob.cpp \ + groupwareuploadjob.cpp kcal_resourcegroupwarebase.cpp kabc_resourcegroupwarebase.cpp \ + tderesources_groupwareprefs.kcfgc \ + kcal_resourcegroupwarebaseconfig.cpp kabc_resourcegroupwarebaseconfig.cpp \ + kcal_cachesettingsdlg.cpp +libkgroupwarebase_la_LDFLAGS = $(all_libraries) -no-undefined +libkgroupwarebase_la_LIBADD = $(top_builddir)/libkcal/libkcal.la \ + $(top_builddir)/libtdepim/libtdepim.la + +libkgroupwaredav_la_SOURCES = davcalendaradaptor.cpp davaddressbookadaptor.cpp webdavhandler.cpp \ + davgroupwareglobals.cpp +libkgroupwaredav_la_LDFLAGS = $(all_libraries) -no-undefined +libkgroupwaredav_la_LIBADD = $(top_builddir)/libkcal/libkcal.la \ + $(top_builddir)/libtdepim/libtdepim.la libkgroupwarebase.la + +METASOURCES = AUTO + +### We use three (or more) namespaces here in here - KPIM, KABC and KCal. +### When using multiple "using namespace foo" declarations, namespaced +### definitions cannot be resolved properly; we could use namespace foo { } +### instead, but this breaks on TDEConfigXT generated code, which still uses +### "using namespace" and can't be fixed due to our backwards-compatibility +### requirements. This is only fatal when doing --enable-final, since only +### then do all the namespaces get mixed together. +KDE_OPTIONS = nofinal + +messages: rc.cpp + $(XGETTEXT) *.cpp -o $(podir)/tdepimresources.pot + diff --git a/tderesources/lib/TODO b/tderesources/lib/TODO new file mode 100644 index 000000000..30680dfe6 --- /dev/null +++ b/tderesources/lib/TODO @@ -0,0 +1,45 @@ +tderesources/lib (general): +=============== +-) http result code handling (404, 200, etc.) +-) conflict resolution +-) Error handling in the folder lister (cannot connect to host, timeout, etc.) +-) turn the flat folder list into a folder tree +-) Restore folder subscriptions on folder list refresh +-) If the user cancels, we need to reset the mUploadJob variable to 0 in the + abook resource. +-) if there's an item in the local cache that cannot be bound on the server and + in the idMapper, mark it as added and try to upload it on save! +-) reload libkcal resources in korganizer when config changes +-) Use the username / password entered into the config dlg. For some reason + each ioslave asks again with a password dialog... +-) If upload fails, mark the item as changed/added/deleted again +-) Don't ask immediately for uploading in korganizer, wait at least a + QTimer::singleShot +-) Better progress bar messages + + +tderesources/newexchange: +======================= +-) handling of errors returned in a valid dav response (Exchange) +-) recurrences on exchange +-) timezone for exchange +-) exdate on exchange +-) notifications from the server (old exchange resource has it!) +-) In Exchange abook: if an address is removed, store the empty string to the + server to delete the data from the server +-) Journal upload not working + + +tderesources/groupdav: +==================== +-) recurrences on ogo +-) uploading abook entries don't work (server doesn't implement it yet) +-) Overview and Calendar have the same items -> downloaded every time (same + uid, different href, only one of them can be in the local cache -> the other + one is downloaded and replaces the current item, so on next folder sync the + first item is downloaded again and replaces the other one...) + + +tderesources/blogging: +==================== +-) Upload of blog posts diff --git a/tderesources/lib/addressbookadaptor.cpp b/tderesources/lib/addressbookadaptor.cpp new file mode 100644 index 000000000..8cc28f67a --- /dev/null +++ b/tderesources/lib/addressbookadaptor.cpp @@ -0,0 +1,134 @@ +/* + This file is part of tdepim. + + Copyright (c) 2004 Cornelius Schumacher <[email protected]> + Copyright (c) 2004 Till Adam <[email protected]> + Copyright (c) 2005 Reinhold Kainhofer <[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 "addressbookadaptor.h" + +#include <kabc/addressee.h> +#include <kabc/vcardconverter.h> +#include <libtdepim/kabcresourcecached.h> +#include <kio/job.h> + + +using namespace KABC; + + +AddressBookUploadItem::AddressBookUploadItem( + KPIM::GroupwareDataAdaptor *adaptor, + KABC::Addressee addr, + GroupwareUploadItem::UploadType type ) + : GroupwareUploadItem( type ) +{ + mItemType = KPIM::FolderLister::Contact; + setUrl( addr.custom( adaptor->identifier(), "storagelocation" ) ); + setUid( addr.uid() ); + KABC::VCardConverter vcard; +#if defined(KABC_VCARD_ENCODING_FIX) + setData( vcard.createVCardRaw( addr ) ); +#else + setData( vcard.createVCard( addr ) ); +#endif +} + + + +AddressBookAdaptor::AddressBookAdaptor() +{ +} + +TQString AddressBookAdaptor::mimeType() const +{ + return "text/x-vcard"; +} + +bool AddressBookAdaptor::localItemExists( const TQString &localId ) +{ + KABC::Addressee a = mResource->findByUid( localId ); + return !a.isEmpty(); +} + +bool AddressBookAdaptor::localItemHasChanged( const TQString &localId ) +{ + KABC::Addressee::List addressees = mResource->deletedAddressees(); + KABC::Addressee::List::ConstIterator it; + for( it = addressees.begin(); it != addressees.end(); ++it ) { + if ( (*it).uid() == localId ) return true; + } + + addressees = mResource->changedAddressees(); + for( it = addressees.begin(); it != addressees.end(); ++it ) { + if ( (*it).uid() == localId ) return true; + } + + return false; +} + + +void AddressBookAdaptor::deleteItem( const TQString &localId ) +{ + KABC::Addressee a = mResource->findByUid( localId ); + if ( !a.isEmpty() ) { + mResource->removeAddressee( a ); + mResource->clearChange( a.uid() ); + } +} + +void AddressBookAdaptor::addItem( KABC::Addressee addr ) +{ + if ( !addr.isEmpty() ) { + addr.setResource( mResource ); + mResource->insertAddressee( addr ); + clearChange( addr.uid() ); + } +} + +void AddressBookAdaptor::addressbookItemDownloaded( KABC::Addressee addr, + const TQString &newLocalId, const KURL &remoteId, const TQString &fingerprint, + const TQString &storagelocation ) +{ + // remove the currently existing item from the cache + deleteItem( newLocalId ); + TQString localId = idMapper()->localId( remoteId.path() ); + if ( !localId.isEmpty() ) deleteItem( localId ); + + // add the new item + addr.insertCustom( identifier(), "storagelocation", storagelocation ); + if ( !localId.isEmpty() ) addr.setUid( localId ); + addItem( addr ); + + // update the fingerprint and the ids in the idMapper + idMapper()->removeRemoteId( localId ); + idMapper()->removeRemoteId( newLocalId ); + emit itemDownloaded( addr.uid(), remoteId, fingerprint ); +} + + +void AddressBookAdaptor::clearChange( const TQString &uid ) +{ + mResource->clearChange( uid ); +} + +KPIM::GroupwareUploadItem *AddressBookAdaptor::newUploadItem( + KABC::Addressee addr, KPIM::GroupwareUploadItem::UploadType type ) +{ + return new AddressBookUploadItem( this, addr, type ); +} diff --git a/tderesources/lib/addressbookadaptor.h b/tderesources/lib/addressbookadaptor.h new file mode 100644 index 000000000..b029ff60d --- /dev/null +++ b/tderesources/lib/addressbookadaptor.h @@ -0,0 +1,92 @@ + /* + This file is part of tdepim. + + Copyright (c) 2004 Cornelius Schumacher <[email protected]> + Copyright (c) 2004 Till Adam <[email protected]> + Copyright (c) 2005 Reinhold Kainhofer <[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 KABC_ADDRESSBOOKADAPTOR_H +#define KABC_ADDRESSBOOKADAPTOR_H + +#include "groupwaredataadaptor.h" + +#include <kabc/addressee.h> +#include <tdepimmacros.h> +#include <kurl.h> + +namespace KABC { +class ResourceCached; + +class AddressBookUploadItem : public KPIM::GroupwareUploadItem +{ + public: + AddressBookUploadItem( KPIM::GroupwareDataAdaptor *adaptor, + KABC::Addressee addr, UploadType type ); + virtual ~AddressBookUploadItem() {} + protected: + AddressBookUploadItem( UploadType type ) + : KPIM::GroupwareUploadItem( type ) {} +}; + +class KDE_EXPORT AddressBookAdaptor : public KPIM::GroupwareDataAdaptor +{ + public: + AddressBookAdaptor(); + + TQValueList<KPIM::FolderLister::ContentType> supportedTypes() + { + TQValueList<KPIM::FolderLister::ContentType> types; + types << KPIM::FolderLister::Contact; + return types; + } + + /** + Set resource. + */ + void setResource( KABC::ResourceCached *v ) + { + mResource = v; + } + /** + Get resource. See setResource(). + */ + KABC::ResourceCached *resource() const + { + return mResource; + } + + TQString mimeType() const; + bool localItemExists( const TQString &localId ); + bool localItemHasChanged( const TQString &localId ); + void deleteItem( const TQString &localId ); + void addItem( KABC::Addressee addr ); + void clearChange( const TQString &uid ); + + virtual KPIM::GroupwareUploadItem *newUploadItem( KABC::Addressee addr, + KPIM::GroupwareUploadItem::UploadType type ); + virtual void addressbookItemDownloaded( KABC::Addressee addr, + const TQString &newLocalId, const KURL &remoteId, + const TQString &fingerprint, const TQString &storagelocation ); + + private: + KABC::ResourceCached *mResource; +}; + +} + +#endif diff --git a/tderesources/lib/calendaradaptor.cpp b/tderesources/lib/calendaradaptor.cpp new file mode 100644 index 000000000..f2e255f0d --- /dev/null +++ b/tderesources/lib/calendaradaptor.cpp @@ -0,0 +1,150 @@ +/* + This file is part of tdepim. + + Copyright (c) 2004 Cornelius Schumacher <[email protected]> + Copyright (c) 2004 Till Adam <[email protected]> + Copyright (c) 2005 Reinhold Kainhofer <[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 "calendaradaptor.h" + +#include <libkcal/incidence.h> +#include <libkcal/calendar.h> +#include <libkcal/resourcecached.h> +#include <libkcal/icalformat.h> + +#include <kio/job.h> + +#include <kdebug.h> + +using namespace KCal; + + +CalendarUploadItem::CalendarUploadItem( CalendarAdaptor *adaptor, KCal::Incidence *incidence, KPIM::GroupwareUploadItem::UploadType type ) + : GroupwareUploadItem( type ) +{ + if ( incidence && adaptor ) { + if ( incidence->type() == "Event" ) mItemType = KPIM::FolderLister::Event; + else if ( incidence->type() == "Todo" ) mItemType = KPIM::FolderLister::Todo; + else if ( incidence->type() == "Journal" ) mItemType = KPIM::FolderLister::Journal; + + setUrl( incidence->customProperty( adaptor->identifier(), "storagelocation" ) ); + setUid( incidence->uid() ); + + ICalFormat format; + format.setTimeZone( adaptor->resource()->timeZoneId(), true ); + setData( format.toICalString( incidence ) ); + } +} + + + +CalendarAdaptor::CalendarAdaptor() +{ +} + +TQString CalendarAdaptor::mimeType() const +{ + return "text/calendar"; +} + +bool CalendarAdaptor::localItemExists( const TQString &localId ) +{ + KCal::Incidence *i = mResource->incidence( localId ); + return i; +} + +bool CalendarAdaptor::localItemHasChanged( const TQString &localId ) +{ + KCal::Incidence *i = mResource->incidence( localId ); + if ( !i ) return false; + + if ( !mResource->deletedIncidences().isEmpty() && + mResource->deletedIncidences().find( i ) + != mResource->deletedIncidences().end() ) + return true; + if ( !mResource->changedIncidences().isEmpty() && + mResource->changedIncidences().find( i ) + != mResource->changedIncidences().end() ) + return true; + + return false; +} + +void CalendarAdaptor::deleteItem( const TQString &localId ) +{ + mResource->disableChangeNotification(); + KCal::Incidence *i = mResource->incidence( localId ); + if ( i ) { + mResource->deleteIncidence( i ); + mResource->clearChange( i ); + } + mResource->enableChangeNotification(); +} + +void CalendarAdaptor::addItem( KCal::Incidence *i) +{ + if ( i ) { + mResource->disableChangeNotification(); + Incidence *existing = mResource->incidence( i->uid() ); + if ( existing ) { + mResource->deleteIncidence( i ); + } + mResource->addIncidence( i ); + mResource->clearChange( i ); + mResource->enableChangeNotification(); + } +} + + +void CalendarAdaptor::calendarItemDownloaded( KCal::Incidence *inc, + const TQString &newLocalId, const KURL &remoteId, const TQString &fingerprint, + const TQString &storagelocation ) +{ +kdDebug() << "CalendarAdaptor::calendarItemDownloaded, inc=" << inc->summary() << ", local=" << newLocalId << ", remote=" << remoteId.url() << ", fpr=" << fingerprint << ", storagelocation="<< storagelocation << endl; + // remove the currently existing item from the cache + deleteItem( newLocalId ); + TQString localId = idMapper()->localId( remoteId.path() ); + if ( !localId.isEmpty() ) deleteItem( localId ); + + // add the new item + inc->setCustomProperty( identifier(), "storagelocation", storagelocation ); + if ( !localId.isEmpty() ) inc->setUid( localId ); + addItem( inc ); + + // update the fingerprint and the ids in the idMapper + idMapper()->removeRemoteId( localId ); + idMapper()->removeRemoteId( newLocalId ); + + emit itemDownloaded( inc->uid(), remoteId, fingerprint ); +} + + +void CalendarAdaptor::clearChange( const TQString &uid ) +{ + KCal::Incidence *i = mResource->incidence( uid ); + mResource->clearChange( i ); +} + +KPIM::GroupwareUploadItem *CalendarAdaptor::newUploadItem( KCal::Incidence*it, + KPIM::GroupwareUploadItem::UploadType type ) +{ + return new CalendarUploadItem( this, it, type ); +} + +#include "calendaradaptor.moc" diff --git a/tderesources/lib/calendaradaptor.h b/tderesources/lib/calendaradaptor.h new file mode 100644 index 000000000..354a2795e --- /dev/null +++ b/tderesources/lib/calendaradaptor.h @@ -0,0 +1,110 @@ + /* + This file is part of tdepim. + + Copyright (c) 2004 Cornelius Schumacher <[email protected]> + Copyright (c) 2004 Till Adam <[email protected]> + Copyright (c) 2005 Reinhold Kainhofer <[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 KCAL_CALENDARADAPTOR_H +#define KCAL_CALENDARADAPTOR_H + +#include "groupwaredataadaptor.h" + + +#include <libkcal/incidence.h> +#include <tdepimmacros.h> +#include <kurl.h> + +namespace KPIM { +class GroupwareUploadItem; +} + +namespace KCal { +class ResourceCached; +class CalendarAdaptor; + +class CalendarUploadItem : public KPIM::GroupwareUploadItem +{ + public: + CalendarUploadItem( CalendarAdaptor *adaptor, KCal::Incidence *incidence, UploadType type ); + virtual ~CalendarUploadItem() {} + + protected: + CalendarUploadItem( UploadType type ) : KPIM::GroupwareUploadItem( type ) {} +}; + + +class KDE_EXPORT CalendarAdaptor : public KPIM::GroupwareDataAdaptor +{ + Q_OBJECT + + public: + CalendarAdaptor(); + + TQValueList<KPIM::FolderLister::ContentType> supportedTypes() + { + TQValueList<KPIM::FolderLister::ContentType> types; + types << KPIM::FolderLister::Event; + types << KPIM::FolderLister::Todo; + types << KPIM::FolderLister::Journal; + return types; + } + + /** + Set resource. + */ + void setResource( KCal::ResourceCached *v ) + { + mResource = v; + } + /** + Get resource. See setResource(). + */ + KCal::ResourceCached *resource() const + { + return mResource; + } + + virtual TQString mimeType() const; + bool localItemExists( const TQString &localId ); + bool localItemHasChanged( const TQString &localId ); + void deleteItem( const TQString &localId ); + void clearChange( const TQString &uid ); + + virtual KPIM::GroupwareUploadItem *newUploadItem( KCal::Incidence*it, + KPIM::GroupwareUploadItem::UploadType type ); + + public slots: + /** newLocalId is the new id that was (randomly) assigned to the item */ + virtual void calendarItemDownloaded( KCal::Incidence *inc, + const TQString &newLocalId, const KURL &remoteId, + const TQString &fingerprint, const TQString &storagelocation ); + + protected: + void addItem( KCal::Incidence *i ); + private: + KCal::ResourceCached *mResource; + + TQStringList mAddedItems; + TQStringList mChangedItems; + TQStringList mDeletedItems; +}; + +} + +#endif diff --git a/tderesources/lib/davaddressbookadaptor.cpp b/tderesources/lib/davaddressbookadaptor.cpp new file mode 100644 index 000000000..5b4a0a521 --- /dev/null +++ b/tderesources/lib/davaddressbookadaptor.cpp @@ -0,0 +1,61 @@ +/* + This file is part of tdepim. + + Copyright (c) 2004 Cornelius Schumacher <[email protected]> + Copyright (c) 2004 Till Adam <[email protected]> + Copyright (c) 2005 Reinhold Kainhofer <[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 "davaddressbookadaptor.h" +// #include "ogoglobals.h" +// #include "davgroupwareglobals.h" +// #include "webdavhandler.h" + +// #include <kabc/addressee.h> +// #include <kabc/vcardconverter.h> +// #include <kabcresourcecached.h> + +#include <kio/davjob.h> +// #include <kio/job.h> +#include <kdebug.h> + +using namespace KABC; + +void DavAddressBookAdaptor::interpretListFoldersJob( TDEIO::Job *job, KPIM::FolderLister */*folderLister*/ ) +{ + TDEIO::DavJob *davjob = dynamic_cast<TDEIO::DavJob*>( job ); + Q_ASSERT( davjob ); + if ( !davjob ) return; + + TQDomDocument doc = davjob->response(); + kdDebug(7000) << " Doc: " << doc.toString() << endl; + + TQDomElement docElement = doc.documentElement(); + TQDomNode n; + for( n = docElement.firstChild(); !n.isNull(); n = n.nextSibling() ) { + TQDomNode n2 = n.namedItem( "propstat" ); + TQDomNode n3 = n2.namedItem( "prop" ); + + KURL href( n.namedItem( "href" ).toElement().text() ); + TQString displayName = n3.namedItem( "displayname" ).toElement().text(); + KPIM::FolderLister::ContentType type = getContentType( n3 ); + + emit folderInfoRetrieved( href, displayName, type ); + emit folderSubitemRetrieved( href, getFolderHasSubs( n3 ) ); + } +} diff --git a/tderesources/lib/davaddressbookadaptor.h b/tderesources/lib/davaddressbookadaptor.h new file mode 100644 index 000000000..f0f6f39d2 --- /dev/null +++ b/tderesources/lib/davaddressbookadaptor.h @@ -0,0 +1,52 @@ + /* + This file is part of tdepim. + + Copyright (C) 2004 Reinhold Kainhofer <[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 KABC_DAVADDRESSBOOKADAPTOR_H +#define KCAL_DAVADDRESSBOOKADAPTOR_H + +#include "addressbookadaptor.h" +#include "folderlister.h" +#include <tqdom.h> +#include <tdepimmacros.h> + +namespace KABC { + +class KDE_EXPORT DavAddressBookAdaptor : public AddressBookAdaptor +{ + public: + DavAddressBookAdaptor() {} + + /** Interprets the results returned by the liste job (created by + createListFoldersJob(url) ). Typically, this adds an Entry to the mFolders list if + the job describes a folder of the appropriate type, by emitting + folderInfoRetrieved( href, displayName, type ). If the folder has + subfolders, just emit retrieveSubfolder( href ) for each of them. */ + virtual void interpretListFoldersJob( TDEIO::Job *job, KPIM::FolderLister *folderLister ); + /** Returns the type of folder retrieved in the dom node. Typically, you'll + compare the DAV:resourcetype property with some values. */ + virtual KPIM::FolderLister::ContentType getContentType( const TQDomNode &folderNode ) = 0; + /** Extract from the dav response whether the folder has subitems that need + to be examined */ + virtual bool getFolderHasSubs( const TQDomNode &folderNode ) = 0; +}; + +} + +#endif diff --git a/tderesources/lib/davcalendaradaptor.cpp b/tderesources/lib/davcalendaradaptor.cpp new file mode 100644 index 000000000..5d6be2da6 --- /dev/null +++ b/tderesources/lib/davcalendaradaptor.cpp @@ -0,0 +1,56 @@ +/* + This file is part of tdepim. + + Copyright (c) 2004 Reinhold Kainhofer <[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 "davcalendaradaptor.h" + +#include <kdebug.h> +#include <kio/davjob.h> +// #include <folderlister.h> + +// #include <tqdom.h> + +using namespace KCal; + +// TODO: This is exactly the same code as for the DavAddressBookAdaptor::interpretListFoldersJob! +// But as this emits a signal, it needs to be located inside a TQObject +void DavCalendarAdaptor::interpretListFoldersJob( TDEIO::Job *job, KPIM::FolderLister */*folderLister*/ ) +{ + TDEIO::DavJob *davjob = dynamic_cast<TDEIO::DavJob*>( job ); + Q_ASSERT( davjob ); + if ( !davjob ) return; + + TQDomDocument doc = davjob->response(); + kdDebug(7000) << " Doc: " << doc.toString() << endl; + + TQDomElement docElement = doc.documentElement(); + TQDomNode n; + for( n = docElement.firstChild(); !n.isNull(); n = n.nextSibling() ) { + TQDomNode n2 = n.namedItem( "propstat" ); + TQDomNode n3 = n2.namedItem( "prop" ); + + KURL href( n.namedItem( "href" ).toElement().text() ); + TQString displayName = n3.namedItem( "displayname" ).toElement().text(); + KPIM::FolderLister::ContentType type = getContentType( n3 ); + + emit folderInfoRetrieved( href, displayName, type ); + emit folderSubitemRetrieved( href, getFolderHasSubs( n3 ) ); + } +} diff --git a/tderesources/lib/davcalendaradaptor.h b/tderesources/lib/davcalendaradaptor.h new file mode 100644 index 000000000..998a9cc7d --- /dev/null +++ b/tderesources/lib/davcalendaradaptor.h @@ -0,0 +1,52 @@ + /* + This file is part of tdepim. + + Copyright (C) 2004 Reinhold Kainhofer <[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 KCAL_DAVCALENDARADAPTOR_H +#define KCAL_DAVCALENDARADAPTOR_H + +#include "calendaradaptor.h" +#include "folderlister.h" +#include <tqdom.h> +#include <tdepimmacros.h> + +namespace KCal { + +class KDE_EXPORT DavCalendarAdaptor : public CalendarAdaptor +{ + public: + DavCalendarAdaptor() {} + + /** Interprets the results returned by the liste job (created by + createListFoldersJob(url) ). Typically, this adds an Entry to the mFolders list if + the job describes a folder of the appropriate type, by emitting + folderInfoRetrieved( href, displayName, type ). If the folder has + subfolders, just emit retrieveSubfolder( href ) for each of them. */ + virtual void interpretListFoldersJob( TDEIO::Job *job, KPIM::FolderLister *folderLister ); + /** Returns the type of folder retrieved in the dom node. Typically, you'll + compare the DAV:resourcetype property with some values. */ + virtual KPIM::FolderLister::ContentType getContentType( const TQDomNode &folderNode ) = 0; + /** Extract from the dav response whether the folder has subitems that need + to be examined */ + virtual bool getFolderHasSubs( const TQDomNode &folderNode ) = 0; +}; + +} + +#endif diff --git a/tderesources/lib/davgroupwareglobals.cpp b/tderesources/lib/davgroupwareglobals.cpp new file mode 100644 index 000000000..5d9a37206 --- /dev/null +++ b/tderesources/lib/davgroupwareglobals.cpp @@ -0,0 +1,22 @@ +/* + This file is part of tdepim. + + Copyright (c) 2004-2005 Reinhold Kainhofer <[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 "davgroupwareglobals.h" diff --git a/tderesources/lib/davgroupwareglobals.h b/tderesources/lib/davgroupwareglobals.h new file mode 100644 index 000000000..67eb22801 --- /dev/null +++ b/tderesources/lib/davgroupwareglobals.h @@ -0,0 +1,30 @@ + /* + This file is part of tdepim. + + Copyright (c) 2004-2005 Reinhold Kainhofer <[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 DAVGROUPWAREGLOBALS_H +#define DAVGROUPWAREGLOBALS_H + +class DAVGroupwareGlobals +{ + public: + DAVGroupwareGlobals() {} +}; + +#endif diff --git a/tderesources/lib/folderconfig.cpp b/tderesources/lib/folderconfig.cpp new file mode 100644 index 000000000..20fa6fa1b --- /dev/null +++ b/tderesources/lib/folderconfig.cpp @@ -0,0 +1,173 @@ +/* + This file is part of libkcal. + + Copyright (c) 2004 Cornelius Schumacher <[email protected]> + Copyright (c) 2004 Till Adam <[email protected]> + Copyright (c) 2005 Reinhold Kainhofer <[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 "folderconfig.h" + +#include "folderlister.h" +#include "groupwaredataadaptor.h" +#include "folderlistview.h" + +#include <klistview.h> +#include <klocale.h> +#include <kdebug.h> +#include <kdialog.h> + +#include <tqlayout.h> +#include <tqgroupbox.h> +#include <tqpushbutton.h> +#include <tqcombobox.h> +#include <tqhbox.h> +#include <tqlabel.h> + +using namespace KPIM; + +FolderConfig::FolderConfig( TQWidget *parent ) + : TQWidget( parent ), mFolderLister( 0 ) +{ + TQBoxLayout *topLayout = new TQVBoxLayout( this ); + topLayout->addSpacing( KDialog::spacingHint() ); + + TQGroupBox *topBox = new TQGroupBox( 1, Qt::Horizontal, i18n("Folder Selection"), + this ); + topLayout->addWidget( topBox ); + + TQPushButton *button = new TQPushButton( i18n("Update Folder List"), topBox ); + connect( button, TQT_SIGNAL( clicked() ), TQT_SIGNAL( updateFoldersClicked() ) ); + + mFolderList = new FolderListView( topBox ); + +/* TQHBox *writeBox = new TQHBox( topBox ); + + new TQLabel( i18n("Write to:"), writeBox ); + + mWriteCombo = new TQComboBox( writeBox );*/ +} + +FolderConfig::~FolderConfig() +{ +} + +void FolderConfig::setFolderLister( FolderLister *f ) +{ + mFolderLister = f; + + TQValueList<FolderListView::Property> types; + TQValueList<FolderLister::ContentType> suptypes( mFolderLister->supportedTypes() ); + if ( suptypes.contains( FolderLister::Event ) ) types << FolderListView::Event; + if ( suptypes.contains( FolderLister::Todo ) ) types << FolderListView::Todo; + if ( suptypes.contains( FolderLister::Journal ) ) types << FolderListView::Journal; + if ( suptypes.contains( FolderLister::Contact ) ) types << FolderListView::Contact; + if ( suptypes.contains( FolderLister::All ) ) types << FolderListView::All; + if ( suptypes.contains( FolderLister::Unknown ) ) types << FolderListView::Unknown; + + mFolderList->setEnabledTypes( types ); + connect( mFolderLister, TQT_SIGNAL( foldersRead() ), TQT_SLOT( updateFolderList() ) ); +} + +void FolderConfig::retrieveFolderList( const KURL &url ) +{ + kdDebug(7000) << "FolderConfig::retrieveFolderList()" << endl; + if ( !mOldFolderListerURL.isEmpty() ) return; + + if ( mFolderLister->adaptor() ) { + mOldFolderListerURL = mFolderLister->adaptor()->baseURL(); + mFolderLister->adaptor()->setBaseURL( url ); + } + mFolderLister->retrieveFolders( url ); +} + +void FolderConfig::updateFolderList() +{ + mFolderList->clear(); + + TQStringList write; + + if ( !mOldFolderListerURL.isEmpty() && mFolderLister->adaptor() ) { + mFolderLister->adaptor()->setBaseURL( mOldFolderListerURL ); + mOldFolderListerURL = KURL(); + } + + FolderLister::Entry::List folders = mFolderLister->folders(); + FolderLister::Entry::List::ConstIterator it; + for( it = folders.begin(); it != folders.end(); ++it ) { + FolderListItem *item = new FolderListItem( mFolderList, (*it) ); + if ( mFolderLister->writeDestinationId( FolderLister::Event ) == (*it).id ) { + item->setDefault( FolderListView::Event ); + } + if ( mFolderLister->writeDestinationId( FolderLister::Todo ) == (*it).id ) { + item->setDefault( FolderListView::Todo ); + } + if ( mFolderLister->writeDestinationId( FolderLister::Journal ) == (*it).id ) { + item->setDefault( FolderListView::Journal ); + } + if ( mFolderLister->writeDestinationId( FolderLister::Contact ) == (*it).id ) { + item->setDefault( FolderListView::Contact ); + } + if ( mFolderLister->writeDestinationId( FolderLister::All ) == (*it).id ) { + item->setDefault( FolderListView::All ); + } + if ( mFolderLister->writeDestinationId( FolderLister::Unknown ) == (*it).id ) { + item->setDefault( FolderListView::Unknown ); + } + } +} + +void FolderConfig::saveSettings() +{ + TQPtrList<TQListViewItem> lst; + + FolderLister::Entry::List folders; + + TQListViewItemIterator it( mFolderList ); + while ( it.current() ) { + FolderListItem *item = dynamic_cast<FolderListItem *>( it.current() ); + if ( item ) { + FolderLister::Entry folder = item->folder(); + folder.active = item->isOn(); + folders.append( folder ); + if ( item->isDefault( FolderListView::Event ) ) { + mFolderLister->setWriteDestinationId( FolderLister::Event, folder.id ); + } + if ( item->isDefault( FolderListView::Todo ) ) { + mFolderLister->setWriteDestinationId( FolderLister::Todo, folder.id ); + } + if ( item->isDefault( FolderListView::Journal ) ) { + mFolderLister->setWriteDestinationId( FolderLister::Journal, folder.id ); + } + if ( item->isDefault( FolderListView::Contact ) ) { + mFolderLister->setWriteDestinationId( FolderLister::Contact, folder.id ); + } + if ( item->isDefault( FolderListView::All ) ) { + mFolderLister->setWriteDestinationId( FolderLister::All, folder.id ); + } + if ( item->isDefault( FolderListView::Unknown ) ) { + mFolderLister->setWriteDestinationId( FolderLister::Unknown, folder.id ); + } + } + ++it; + } + + mFolderLister->setFolders( folders ); +} + +#include "folderconfig.moc" diff --git a/tderesources/lib/folderconfig.h b/tderesources/lib/folderconfig.h new file mode 100644 index 000000000..36a8d31a0 --- /dev/null +++ b/tderesources/lib/folderconfig.h @@ -0,0 +1,66 @@ +/* + This file is part of libkcal. + + Copyright (c) 2004 Cornelius Schumacher <[email protected]> + Copyright (c) 2004 Till Adam <[email protected]> + Copyright (c) 2005 Reinhold Kainhofer <[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 KPIM_FOLDERCONFIG_H +#define KPIM_FOLDERCONFIG_H + +#include <kurl.h> +#include <tdepimmacros.h> +#include <tqwidget.h> + +// class KListView; +class TQComboBox; +class FolderListView; + +namespace KPIM { + +class FolderLister; + +class KDE_EXPORT FolderConfig : public TQWidget +{ + Q_OBJECT + + public: + FolderConfig( TQWidget *parent ); + ~FolderConfig(); + + void setFolderLister( FolderLister * ); + + void saveSettings(); + + public slots: + void updateFolderList(); + void retrieveFolderList( const KURL & ); + + signals: + void updateFoldersClicked(); + + private: + FolderListView *mFolderList; + + FolderLister *mFolderLister; + KURL mOldFolderListerURL; +}; + +} + +#endif diff --git a/tderesources/lib/folderlister.cpp b/tderesources/lib/folderlister.cpp new file mode 100644 index 000000000..6cb341acd --- /dev/null +++ b/tderesources/lib/folderlister.cpp @@ -0,0 +1,372 @@ +/* + This file is part of libkcal. + + Copyright (c) 2004 Cornelius Schumacher <[email protected]> + Copyright (c) 2004 Till Adam <[email protected]> + Copyright (c) 2004 Reinhold Kainhofer <[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 "folderlister.h" +#include "groupwaredataadaptor.h" +#include "tderesources_groupwareprefs.h" + +#include <kio/job.h> + +#include <kdebug.h> +#include <kconfig.h> +#include <tqstringlist.h> + +using namespace KPIM; + +FolderLister::FolderLister( Type type ) + : mType( type ), mAdaptor( 0 ) +{ +} + +void FolderLister::setFolders( const FolderLister::Entry::List &folders ) +{ + mFolders = folders; +} + +void FolderLister::setWriteDestinationId( KPIM::FolderLister::ContentType type, const TQString &id ) +{ + mWriteDestinationId[ type ] = id; +} + +TQString FolderLister::writeDestinationId( KPIM::FolderLister::ContentType type ) const +{ + if ( mWriteDestinationId.contains( type ) ) { + return mWriteDestinationId[type]; + } else if ( mWriteDestinationId.contains( KPIM::FolderLister::All ) ) { + return mWriteDestinationId[ KPIM::FolderLister::All ]; + } else if ( mWriteDestinationId.contains( KPIM::FolderLister::Unknown ) ) { + return mWriteDestinationId[ KPIM::FolderLister::Unknown ]; + } else return TQString(); +} + + +KURL::List FolderLister::activeFolderIds() const +{ + KURL::List ids; + + FolderLister::Entry::List::ConstIterator it; + for( it = mFolders.begin(); it != mFolders.end(); ++it ) { + if ( (*it).active ) { + ids.append( KURL((*it).id) ); + } + } + + return ids; +} + +bool FolderLister::isActive( const TQString &id ) const +{ + FolderLister::Entry::List::ConstIterator it; + for( it = mFolders.begin(); it != mFolders.end(); ++it ) { + if ( (*it).id == id ) return (*it).active; + } + return false; +} + +TQStringList FolderLister::contentTypeToStrings( ContentType type ) +{ +kdDebug() << "FolderLister::contentTypeToStrings( type=" << type << ")" << endl; + TQStringList cont; + if ( type == All ) { + cont << "All"; + } else if ( type == Unknown ) { + cont << "Unknown"; + } else { + if ( type & Contact ) cont << "Contact"; + if ( type & Event ) cont << "Event"; + if ( type & Todo ) cont << "Todo"; + if ( type & Journal ) cont << "Journal"; + if ( type & Message ) cont << "Message"; + if ( type & Memo ) cont << "Memo"; + if ( type & Folder ) cont << "Folder"; + } + return cont; +} + +FolderLister::ContentType FolderLister::contentTypeFromString( const TQString &type ) +{ + if ( type == "All" ) return All; + if ( type == "Contact" ) return Contact; + if ( type == "Event" ) return Event; + if ( type == "Todo" ) return Todo; + if ( type == "Journal" ) return Journal; + if ( type == "Message" ) return Message; + if ( type == "Memo" ) return Memo; + if ( type == "Folder" ) return Folder; + return Unknown; +} + +TQValueList<FolderLister::ContentType> FolderLister::supportedTypes() +{ + if ( adaptor() ) { + return adaptor()->supportedTypes(); + } else { + return TQValueList<ContentType>(); + } +} + + + +void FolderLister::readConfig( KPIM::GroupwarePrefsBase *newprefs ) +{ + kdDebug(7000) << "FolderLister::readConfig()" << endl; + mFolders.clear(); + + TQStringList active = newprefs->activeFolders(); + int nr = newprefs->folderNumber(); + + for ( int i=0; i<nr; ++i ) { + TQStringList l( newprefs->folder( i ) ); +// TQStringList l( cfgg.readListEntry( TQString("Folder%1").arg( i ) ) ); + Entry e; + if ( l.count()>0 ) { + e.id = l.first(); + l.pop_front(); + } + if ( l.count()>1 ) { + e.name = l.first(); + l.pop_front(); + } + e.type = Unknown; + for ( TQStringList::Iterator it = l.begin(); it != l.end(); ++it ) { + e.type = (FolderLister::ContentType)( e.type | contentTypeFromString( *it ) ); + } + if ( active.find( e.id ) != active.end() ) e.active = true; + mFolders.append( e ); + } + + TQStringList destinations( newprefs->defaultDestinations() ); + + #define readDestination(type) \ + if ( destinations.count()>0 ) { \ + mWriteDestinationId[ type ] = destinations.first(); \ + destinations.pop_front(); \ + } + readDestination( FolderLister::Event ); + readDestination( FolderLister::Todo ); + readDestination( FolderLister::Journal ); + readDestination( FolderLister::Contact ); + readDestination( FolderLister::All ); + readDestination( FolderLister::Unknown ); + #undef readDestination +} + +void FolderLister::writeConfig( GroupwarePrefsBase *newprefs ) +{ + TQStringList ids; + TQStringList names; + TQStringList active; + +// TDEConfigGroup cfgg( newprefs->config(), "Folders" ); + int nr = 0; + Entry::List::ConstIterator it; + for( it = mFolders.begin(); it != mFolders.end(); ++it ) { + TQStringList lst; + lst << (*it).id; + lst << (*it).name; + lst += contentTypeToStrings( (*it).type ); + newprefs->setFolder( nr, lst ); +// cfgg.writeEntry( TQString("Folder%1").arg( nr ), lst ); + if ( (*it).active ) active.append( (*it).id ); + nr++; + } + newprefs->setFolderNumber( nr ); + + newprefs->setActiveFolders( active ); + + TQStringList defaultFolders; + #define writeDestination(type) \ + if ( mWriteDestinationId.contains( type ) ) \ + defaultFolders << mWriteDestinationId[type]; \ + else defaultFolders << TQString(); + writeDestination( KPIM::FolderLister::Event ); + writeDestination( KPIM::FolderLister::Todo ); + writeDestination( KPIM::FolderLister::Journal ); + writeDestination( KPIM::FolderLister::Contact ); + writeDestination( KPIM::FolderLister::All ); + writeDestination( KPIM::FolderLister::Unknown ); + #undef writeDestination + + newprefs->setDefaultDestinations( defaultFolders ); +} + +void FolderLister::setAdaptor( KPIM::GroupwareDataAdaptor *adaptor ) +{ + if ( mAdaptor ) { + disconnect( mAdaptor, 0, this, 0 ); + } + mAdaptor = adaptor; + connect( mAdaptor, TQT_SIGNAL( folderInfoRetrieved( const KURL &, + const TQString &, KPIM::FolderLister::ContentType ) ), + this, TQT_SLOT( processFolderResult( const KURL &, const TQString &, + KPIM::FolderLister::ContentType ) ) ); + connect( mAdaptor, TQT_SIGNAL( folderSubitemRetrieved( const KURL &, bool ) ), + this, TQT_SLOT( folderSubitemRetrieved( const KURL &, bool ) ) ); +} + +void FolderLister::folderSubitemRetrieved( const KURL &url, bool isFolder ) +{ + if ( isFolder ) + doRetrieveFolder( url ); + else { + KURL u( url ) ; + u.setUser( TQString() ); + u.setPass( TQString() ); + mProcessedPathes.append( url.path(-1) ); + } +} + +void FolderLister::retrieveFolders( const KURL &u ) +{ +kdDebug()<<"FolderLister::retrieveFolders( "<<u.url()<<" )"<<endl; + mUrls.clear(); + mProcessedPathes.clear(); + bool firstRetrieve = mFolders.isEmpty(); + mFolders = defaultFolders(); + Entry::List::Iterator it = mFolders.begin(); + + for ( ; it != mFolders.end(); ++it ) { + if ( firstRetrieve ) { + (*it).active = true; + } else { + (*it).active = isActive( (*it).id ); + } + } + + doRetrieveFolder( u ); +} + +void FolderLister::doRetrieveFolder( const KURL &u ) +{ + kdDebug(7000) << "FolderLister::doRetrieveFolder: " << u.prettyURL() << endl; + + KURL url( u ); + if ( adaptor() ) adaptor()->adaptDownloadUrl( url ); + if ( mUrls.contains( url ) || mProcessedPathes.contains( url.path(-1) ) ) { + kdDebug()<<"Item "<<u.path(-1)<<" is already being downloaded "<<endl; + } else { + + TDEIO::Job *listjob = createListFoldersJob( url ); + if ( listjob ) { + mUrls.append( url ); + + kdDebug(7000) << "FolderLister::retrieveFolders: adjustedURL=" + << url.prettyURL() << endl; + connect( listjob, TQT_SIGNAL( result( TDEIO::Job * ) ), + TQT_SLOT( slotListJobResult( TDEIO::Job * ) ) ); + } else { + // TODO: Indicate a problem to the user! + kdWarning() << "Unable to create the folder list job for the url " + << url.prettyURL() << endl; + } + } + if ( mUrls.isEmpty() ) { + kdDebug()<<"No more URLS to download, emitting foldersRead()"<<endl; + emit foldersRead(); + } +} + +FolderLister::Entry::List FolderLister::defaultFolders() +{ + if ( adaptor() ) { + return adaptor()->defaultFolders(); + } else { + return Entry::List(); + } +} + +void FolderLister::processFolderResult( const KURL &href, + const TQString &displayName, + ContentType type ) +{ +kdDebug() << "FolderLister::processFolderResult( href=" << href.url() << ", displayName=" << displayName << ", type=" << int(type) << endl; + if ( ( mType == Calendar && ( type & ( Event | Todo |Journal) ) ) || + ( mType == AddressBook && (type & Contact ) ) ) { + + if ( !href.isEmpty() && !displayName.isEmpty() ) { + Entry entry; + entry.id = href.url(); + entry.name = displayName; + entry.type = type; + entry.active = isActive( entry.id ); + + mFolders.append( entry ); + } + kdDebug(7000) << "FOLDER: " << displayName << endl; +kdDebug()<<"mFolders.size="<<mFolders.size()<<endl; + } else { +kdDebug() << "Folder "<< href << " is not of correct type ("<<type<<")"<<endl; + } +} + +void FolderLister::slotListJobResult( TDEIO::Job *job ) +{ + kdDebug(7000) << "OpenGroupware::slotListJobResult(): " << endl; + kdDebug() << "URLS (" << mUrls.count() << "): " << mUrls.toStringList().join(" | ") << endl; + kdDebug() << "Processed URLS (" << mProcessedPathes.count() << "): " + << mProcessedPathes.join(" | ") << endl; + TDEIO::SimpleJob *j = dynamic_cast<TDEIO::SimpleJob*>(job); + if ( j ) { + mUrls.remove( j->url() ); + mProcessedPathes.append( j->url().path(-1) ); + } + + if ( job->error() ) { + kdError() << "Unable to retrieve folders." << endl; + } else { + interpretListFoldersJob( job ); + } + kdDebug() << "After URLS (" << mUrls.count() << "): " + << mUrls.toStringList().join(" | ") << endl; + kdDebug() << "After Processed URLS (" << mProcessedPathes.count() << "): " + << mProcessedPathes.join(" | ") << endl; + if ( mUrls.isEmpty() ) { + kdDebug()<<"No more URLS to download, emitting foldersRead()"<<endl; + emit foldersRead(); + } +} + +void FolderLister::interpretListFoldersJob( TDEIO::Job *job ) +{ + if ( adaptor() ) { + adaptor()->interpretListFoldersJob( job, this ); + } else { + // TODO: Error handling should show a message to the user! + kdError() << "The FolderLister does not have a GroupwareDataAdaptor, so " + "it cannot interpret the response!" << endl; + } +} + +TDEIO::Job *FolderLister::createListFoldersJob( const KURL &url ) +{ + if ( adaptor() ) { + return adaptor()->createListFoldersJob( url ); + } else { + // TODO: Error handling should show a message to the user! + kdError() << "The FolderLister does not have a GroupwareDataAdaptor, so " + "it cannot create the job for the folder list!" << endl; + return 0; + } +} + +#include "folderlister.moc" diff --git a/tderesources/lib/folderlister.h b/tderesources/lib/folderlister.h new file mode 100644 index 000000000..a1d3f2ebf --- /dev/null +++ b/tderesources/lib/folderlister.h @@ -0,0 +1,151 @@ +/* + This file is part of libkcal. + + Copyright (c) 2004 Cornelius Schumacher <[email protected]> + Copyright (c) 2004 Till Adam <[email protected]> + Copyright (c) 2004 Reinhold Kainhofer <[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 KPIM_FOLDERLISTER_H +#define KPIM_FOLDERLISTER_H + +// #include "tderesources_groupwareprefs.h" +/*#include "groupwareresourcejob.h"*/ +#include <kurl.h> +#include <tdepimmacros.h> + +#include <tqvaluelist.h> +#include <tqstring.h> +#include <tqstringlist.h> +#include <tqobject.h> + +namespace TDEIO { +class Job; +} + +class TDEConfig; + +namespace KPIM { + +class GroupwareDataAdaptor; +class GroupwarePrefsBase; + + +class KDE_EXPORT FolderLister : public TQObject +{ + Q_OBJECT + + public: + enum Type { AddressBook, Calendar }; + enum ContentType { + Contact=0x1, Event=0x2, Todo=0x4, Journal=0x8, + Message=0x10, Memo=0x20, Folder=0x40, + Incidences=Event|Todo|Journal, All=Contact|Incidences, + Unknown=0x000 + }; + + class Entry + { + public: + Entry() : active( false ) {} + + typedef TQValueList<Entry> List; + + TQString id; + TQString name; + ContentType type; + bool active; + }; + static TQStringList contentTypeToStrings( ContentType ); + ContentType contentTypeFromString( const TQString &type ); + + TQValueList<ContentType> supportedTypes(); + + FolderLister( Type ); + + /** Initialize the retrieval with given root URL */ + virtual void retrieveFolders( const KURL & ); + + void setFolders( const Entry::List & ); + Entry::List folders() const { return mFolders; } + + void setAdaptor( KPIM::GroupwareDataAdaptor *adaptor ); + GroupwareDataAdaptor* adaptor() const { return mAdaptor; } + + KURL::List activeFolderIds() const; + bool isActive( const TQString &id ) const; + + void setWriteDestinationId( KPIM::FolderLister::ContentType type, const TQString &dest ); + TQString writeDestinationId( KPIM::FolderLister::ContentType type ) const; + + void readConfig( KPIM::GroupwarePrefsBase *newprefs ); + void writeConfig( KPIM::GroupwarePrefsBase *newprefs ); + + + signals: + void foldersRead(); + + protected slots: + void slotListJobResult( TDEIO::Job * ); + /** Adds the folder with the given url and display name to the folder + * tree (if is has an appropriate type) */ + virtual void processFolderResult( const KURL &href, + const TQString &displayName, + KPIM::FolderLister::ContentType type ); + /** Retrieve information about the folder u. If it has sub-folders, it + descends into the hierarchy */ + virtual void doRetrieveFolder( const KURL &u ); + /** A subitem was detected. If it's a folder, we need to descend, otherwise + we just add the url to the list of processed URLs. */ + void folderSubitemRetrieved( const KURL &url, bool isFolder ); + + protected: + /** Creates the job to retrieve information about the folder at the given + url. It's results will be interpreted by interpretFolderResult + */ + virtual TDEIO::Job *createListFoldersJob( const KURL &url ); + /** Interprets the results returned by the liste job (created by + * createJob(url) ). The default implementation calls + * interpretFolderListJob of the GroupwareDataAdaptor. Typically, + * this adds an Entry to the mFolders list if the job describes a + * folder of the appropriate type, by calling processsFolderResult. + * If the folder has subfolders, just call doRetrieveFolder(url) + * recursively. */ + virtual void interpretListFoldersJob( TDEIO::Job *job ); + /** List of folders that will always be included (subfolders won't!). + * Usually this is not needed as you should traverse the whole folder + * tree starting from the user's root dir. */ + virtual Entry::List defaultFolders(); + /** Type of this folder lister (i.e. AddressBook or Calendar) */ + Type getType() const { return mType; } + + + protected: + Type mType; + KURL::List mUrls; + TQStringList mProcessedPathes; + Entry::List mFolders; + GroupwareDataAdaptor *mAdaptor; + private: + // TODO: We need multiple destinations for Events, Tasks and Journals + TQMap<KPIM::FolderLister::ContentType, TQString> mWriteDestinationId; + KURL mOldURL; +}; + +} + +#endif diff --git a/tderesources/lib/folderlistview.cpp b/tderesources/lib/folderlistview.cpp new file mode 100644 index 000000000..b29e61c9d --- /dev/null +++ b/tderesources/lib/folderlistview.cpp @@ -0,0 +1,296 @@ +/* This file is part of the KDE libraries + + Copyright (C) 2005 Reinhold Kainhofer <[email protected]> + + Taken in large parts from the kate highlighting list view kateschema.cpp: + Copyright (C) 2001-2003 Christoph Cullmann <[email protected]> + Copyright (C) 2002, 2003 Anders Lund <[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 version 2 as published by the Free Software Foundation. + + 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 "folderlistview.h" +#include "folderlister.h" + +#include <klistview.h> +#include <klocale.h> +#include <kiconloader.h> +#include <kpopupmenu.h> +#include <kdebug.h> + +#include <tqlistview.h> +#include <tqheader.h> +#include <tqpainter.h> + +static const int BoxSize = 16; + + +//BEGIN FolderListView +FolderListView::FolderListView( TQWidget *parent, const TQValueList<Property> &types ) + : KListView( parent ) +{ + setEnabledTypes( types ); + + connect( this, TQT_SIGNAL(mouseButtonPressed(int, TQListViewItem*, const TQPoint&, int)), + this, TQT_SLOT(slotMousePressed(int, TQListViewItem*, const TQPoint&, int)) ); + connect( this, TQT_SIGNAL(spacePressed(TQListViewItem*)), + this, TQT_SLOT(showPopupMenu(TQListViewItem*)) ); +} + +void FolderListView::setEnabledTypes( const TQValueList<Property> &types ) +{ +kdDebug() << "FolderListView::setEnabledTypes" << endl; + for ( int i = 0; i< columns(); ++i ) removeColumn( i ); + mTypes = types; + if ( !mTypes.contains( FolderName ) ) mTypes.prepend( FolderName ); + mColumnMap[FolderName] = addColumn( i18n("Folder") ); + mTypeMap[mColumnMap[FolderName]] = FolderName; + + + if ( mTypes.contains( Event ) ) { + mColumnMap[Event] = addColumn( i18n("Short column header meaning default for new events", "Events") ); + mTypeMap[mColumnMap[Event]] = Event; + } else mColumnMap[Event] = -1; + + if ( mTypes.contains( Todo ) ) { + mColumnMap[Todo] = addColumn( i18n("Short column header meaning default for new to-dos", "Todos") ); + mTypeMap[mColumnMap[Todo]] = Todo; + } else mColumnMap[Todo] = -1; + + if ( mTypes.contains( Journal ) ) { + mColumnMap[Journal] = addColumn( i18n("Short column header meaning default for new journals", "Journals") ); + mTypeMap[mColumnMap[Journal]] = Journal; + } else mColumnMap[Journal] = -1; + + if ( mTypes.contains( Contact ) ) { + mColumnMap[Contact] = addColumn( i18n("Short column header meaning default for new contacts", "Contacts") ); + mTypeMap[mColumnMap[Contact]] = Contact; + } else mColumnMap[Contact] = -1; + + if ( mTypes.contains( All ) ) { + mColumnMap[All] = addColumn( i18n("Short column header meaning default for all items", "All") ); + mTypeMap[mColumnMap[All]] = All; + } else mColumnMap[All] = -1; + + if ( mTypes.contains( Unknown ) ) { + mColumnMap[Unknown] = addColumn( i18n("Short column header meaning default for unknown new items", "Unknown") ); + mTypeMap[mColumnMap[Unknown]] = Unknown; + } else mColumnMap[Unknown] = -1; +} + +void FolderListView::showPopupMenu( FolderListItem *i, const TQPoint &globalPos ) +{ + if ( !i ) return; + KPIM::FolderLister::Entry folder( i->folder() ); + + KPopupMenu m( this ); + int id; + + m.insertTitle( folder.name, 9999 ); + id = m.insertItem( i18n("&Enabled"), this, TQT_SLOT(slotPopupHandler(int)), 0, FolderName ); + m.setItemChecked( id, i->isOn() ); + m.insertSeparator(); + + if ( ( folder.type & KPIM::FolderLister::Event ) && (mTypes.contains( Event ) ) ) { + id = m.insertItem( i18n("Default for New &Events"), this, TQT_SLOT(slotPopupHandler(int)), 0, Event ); + m.setItemChecked( id, i->isDefault( Event ) ); + } + if ( ( folder.type & KPIM::FolderLister::Todo ) && (mTypes.contains( Todo ) ) ) { + id = m.insertItem( i18n("Default for New &Todos"), this, TQT_SLOT(slotPopupHandler(int)), 0, Todo ); + m.setItemChecked( id, i->isDefault( Todo ) ); + } + if ( ( folder.type & KPIM::FolderLister::Journal ) && (mTypes.contains( Journal ) ) ) { + id = m.insertItem( i18n("Default for New &Journals"), this, TQT_SLOT(slotPopupHandler(int)), 0, Journal ); + m.setItemChecked( id, i->isDefault( Journal ) ); + } + if ( ( folder.type & KPIM::FolderLister::Contact ) && (mTypes.contains( Contact ) ) ) { + id = m.insertItem( i18n("Default for New &Contacts"), this, TQT_SLOT(slotPopupHandler(int)), 0, Contact ); + m.setItemChecked( id, i->isDefault( Contact ) ); + } + if ( ( folder.type == KPIM::FolderLister::All ) && (mTypes.contains( All ) ) ) { + id = m.insertItem( i18n("Default for All New &Items"), this, TQT_SLOT(slotPopupHandler(int)), 0, All ); + m.setItemChecked( id, i->isDefault( All ) ); + } + if ( ( folder.type == KPIM::FolderLister::Unknown ) && (mTypes.contains( Unknown ) ) ) { + id = m.insertItem( i18n("Default for &Unknown New Items"), this, TQT_SLOT(slotPopupHandler(int)), 0, Unknown ); + m.setItemChecked( id, i->isDefault( Unknown ) ); + } + + m.exec( globalPos ); +} + +void FolderListView::showPopupMenu( TQListViewItem *i ) +{ + if ( dynamic_cast<FolderListItem*>(i) ) + showPopupMenu( (FolderListItem*)i, viewport()->mapToGlobal(itemRect(i).topLeft()) ); +} + +void FolderListView::slotPopupHandler( int z ) +{ + ((FolderListItem*)currentItem())->changeProperty( (Property)z ); +} + +// Because TQListViewItem::activatePos() is going to become deprecated, +// and also because this attempt offers more control, I connect mousePressed to this. +void FolderListView::slotMousePressed(int btn, TQListViewItem* i, const TQPoint& pos, int c) +{ + if ( dynamic_cast<FolderListItem*>(i) ) { + if ( btn == Qt::RightButton ) { + showPopupMenu( (FolderListItem*)i, /*mapToGlobal(*/pos/*)*/ ); + } + else if ( btn == Qt::LeftButton && c > 0 ) { + // map pos to item/column and call FolderListItem::activate(col, pos) + ((FolderListItem*)i)->activate( c, viewport()->mapFromGlobal( pos ) - TQPoint( 0, itemRect(i).top() ) ); +// } else { +// KListView::slotMousePressed( btn, i, pos, c ); + } + } +} + +//END + +//BEGIN FolderListItem + +void FolderListItem::activate( int column, const TQPoint &localPos ) +{ + if ( !mFolderListView ) return; + TQListView *lv = listView(); + int x = 0; + for( int c = 0; c < column-1; c++ ) + x += lv->columnWidth( c ); + int w; + FolderListView::Property prop( mFolderListView->typeForColumn(column) ); + switch( prop ) { + case FolderListView::Event: + case FolderListView::Todo: + case FolderListView::Journal: + case FolderListView::Contact: + case FolderListView::All: + case FolderListView::Unknown: + w = BoxSize; + break; + default: + return; + } + if ( !TQRect( x, 0, w, BoxSize ).contains( localPos ) ) + changeProperty( prop ); +} + +void FolderListItem::changeProperty( FolderListView::Property p ) +{ +kdDebug() << "FolderListItem::changeProperty( " << p << ")" << endl; + if ( p == FolderListView::FolderName ) { +kdDebug() << "it's folderName" << endl; + setOn( !isOn() ); + } else if ( typeSupported( p ) ) { + TQListViewItemIterator it( listView() ); + while ( it.current() ) { + FolderListItem *item = dynamic_cast<FolderListItem*>( it.current() ); + if ( item ) { + item->setDefault( p, item==this ); + } + ++it; + } + } + listView()->triggerUpdate(); + ((FolderListView*)listView())->emitChanged(); +} + + +bool FolderListItem::typeSupported( FolderListView::Property prop ) +{ + return ( (prop==FolderListView::Event) && (mFolder.type & KPIM::FolderLister::Event) ) || + ( (prop==FolderListView::Todo) && (mFolder.type & KPIM::FolderLister::Todo) ) || + ( (prop==FolderListView::Journal)&& (mFolder.type & KPIM::FolderLister::Journal) ) || + ( (prop==FolderListView::Contact)&& (mFolder.type & KPIM::FolderLister::Contact) ) || + ( (prop==FolderListView::All) && (mFolder.type == KPIM::FolderLister::All) ) || + ( (prop==FolderListView::Unknown)&& (mFolder.type == KPIM::FolderLister::Unknown) ); +} + +bool FolderListItem::isDefault( FolderListView::Property prop ) +{ + if ( !typeSupported( prop ) || prop<0 || prop>=FolderListView::PROP_MAX ) return false; + else return mIsDefault[ prop ]; +} + +void FolderListItem::setDefault( FolderListView::Property prop, bool def ) +{ + if ( prop<0 || prop>=FolderListView::PROP_MAX ) return; + else mIsDefault[ prop ] = def; + +} + + +void FolderListItem::paintCell( TQPainter *p, const TQColorGroup &cg, int col, int width, int align ) +{ + if ( !p ) return; + + TQListView *lv = listView(); + Q_ASSERT( lv ); //### + if ( !lv ) return; + + // use a private color group and set the text/highlighted text colors +// TQColorGroup mcg = lv->viewport()->colorGroup(); + FolderListView::Property prop( mFolderListView->typeForColumn(col) ); + + if ( prop == FolderListView::FolderName ) { + // col 0 is drawn by the superclass method + super::paintCell( p, cg, col, width, align ); + return; + } else { + p->fillRect( 0, 0, width, height(), TQBrush( cg.base() ) ); + } + + int marg = lv->itemMargin(); + TQColor c; + + switch ( prop ) + { + case FolderListView::Event: + case FolderListView::Todo: + case FolderListView::Journal: + case FolderListView::Contact: + case FolderListView::All: + case FolderListView::Unknown: + { + if ( !typeSupported( prop ) ) break; + + int x = 0; + int y = (height() - BoxSize) / 2; + + if ( isEnabled() ) + p->setPen( TQPen( cg.text(), 1 ) ); + else + p->setPen( TQPen( lv->palette().color( TQPalette::Disabled, TQColorGroup::Text ), 1 ) ); + + p->drawEllipse( x+marg, y+2, BoxSize-4, BoxSize-4 ); + + if ( isDefault( prop ) ) { + if ( isEnabled() ) + p->setBrush( cg.text() ); + else + p->setBrush( lv->palette().color( TQPalette::Disabled, TQColorGroup::Text ) ); + p->drawEllipse( x + marg + 3, y + 5, BoxSize-10, BoxSize-10 ); + } + break; + } + default: + break; + } +} +//END + +#include "folderlistview.moc" +// kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/tderesources/lib/folderlistview.h b/tderesources/lib/folderlistview.h new file mode 100644 index 000000000..32f01199b --- /dev/null +++ b/tderesources/lib/folderlistview.h @@ -0,0 +1,130 @@ +/* This file is part of the KDE libraries + + Copyright (C) 2005 Reinhold Kainhofer <[email protected]> + + Taken in large parts from the kate highlighting list view kateschema.h: + Copyright (C) 2001-2003 Christoph Cullmann <[email protected]> + Copyright (C) 2002, 2003 Anders Lund <[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 version 2 as published by the Free Software Foundation. + + 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 FOLDERLISTVIEW_H +#define FOLDERLISTVIEW_H + +#include <klistview.h> +#include "folderlister.h" + +class FolderListItem; +class FolderListCaption; + + +/* + TQListView that automatically adds columns for FolderListItems for selecting + the default destination and a slot to edit the destinations using the keyboard. +*/ +class FolderListView : public KListView +{ + Q_OBJECT + + + friend class FolderListItem; + + public: + /* mainly for readability */ + enum Property { FolderName, Event, Todo, Journal, Contact, All, Unknown, PROP_MAX }; + + FolderListView( TQWidget *parent, const TQValueList<Property> &types = TQValueList<Property>() ); + ~FolderListView() {}; + + /* Display a popupmenu for item i at the specified global position, eventually with a title, + promoting the context name of that item */ + void showPopupMenu( FolderListItem *i, const TQPoint &globalPos ); + void emitChanged() { emit changed(); }; + void setEnabledTypes( const TQValueList<Property> &types ); + + int columnForType( Property prop ) const { if ( mColumnMap.contains(prop) ) return mColumnMap[prop]; else return -1;} + Property typeForColumn( int col ) const { if ( mTypeMap.contains( col ) ) return mTypeMap[col]; else return Unknown; } + + private slots: + /* Display a popupmenu for item i at item position */ + void showPopupMenu( TQListViewItem *i ); + /* call item to change a property, or display a menu */ + void slotMousePressed( int, TQListViewItem*, const TQPoint&, int ); + /* asks item to change the property in q */ + void slotPopupHandler( int z ); + + signals: + void changed(); + private: + TQValueList<Property> mTypes; + TQMap<Property,int> mColumnMap; + TQMap<int,Property> mTypeMap; +}; + +/* + TQListViewItem subclass to display/edit a folder on a groupware server. + Selection of default destinations will be done via radio items. +*/ +class FolderListItem : public TQCheckListItem +{ + typedef TQCheckListItem super; + public: + FolderListItem( FolderListItem *parent, const KPIM::FolderLister::Entry &folder ) + : TQCheckListItem( parent, folder.name, TQCheckListItem::CheckBoxController ), + mFolder( folder ), mFolderListView( parent?(parent->folderListView()):0 ) + { + setOn( mFolder.active ); + } + FolderListItem( FolderListView *listView, const KPIM::FolderLister::Entry &folder ) + : TQCheckListItem( listView, folder.name, + TQCheckListItem::CheckBoxController ), mFolder( folder ), mFolderListView( listView ) + { + setOn( mFolder.active ); + } + + KPIM::FolderLister::Entry folder() const + { + return mFolder; + } + + /* reimp */ +// int width ( const TQFontMetrics & fm, const TQListView * lv, int c ) const; + + bool typeSupported( FolderListView::Property prop ); + bool isDefault( FolderListView::Property prop ); + void setDefault( FolderListView::Property prop, bool def = true ); + + /* calls changeProperty() if it makes sense considering pos. */ + void activate( int column, const TQPoint &localPos ); + /* Sets this item as default for property p a */ + void changeProperty( FolderListView::Property p ); + + FolderListView *folderListView() const { return mFolderListView; } + + protected: + /* reimp */ + void paintCell(TQPainter *p, const TQColorGroup& cg, int col, int width, int align); + + private: + KPIM::FolderLister::Entry mFolder; + bool mIsDefault[FolderListView::PROP_MAX]; + FolderListView *mFolderListView; +}; + + +#endif + +// kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/tderesources/lib/folderselectdialog.cpp b/tderesources/lib/folderselectdialog.cpp new file mode 100644 index 000000000..9d0f48a5e --- /dev/null +++ b/tderesources/lib/folderselectdialog.cpp @@ -0,0 +1,88 @@ +/* + This file is part of tdepim. + + Copyright (c) 2008 Kevin Ottens <[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. + + In addition, as a special exception, the copyright holders give + permission to link the code of this program with any edition of + the TQt library by Trolltech AS, Norway (or with modified versions + of TQt that use the same license as TQt), and distribute linked + combinations including the two. You must obey the GNU General + Public License in all respects for all of the code used other than + TQt. If you modify this file, you may extend this exception to + your version of the file, but you are not obligated to do so. If + you do not wish to do so, delete this exception statement from + your version. +*/ + +#include "folderselectdialog.h" + +#include <tqlayout.h> +#include <tqlabel.h> + +using namespace KPIM; + +FolderSelectDialog::FolderSelectDialog( const TQString& caption, const TQString& label, + const TQStringList& list ) + : KDialogBase(0, 0, true, caption, Ok|Cancel, Ok, true) +{ + TQFrame* frame = makeMainWidget(); + TQVBoxLayout* layout = new TQVBoxLayout( frame, 0, spacingHint() ); + + TQLabel* labelWidget = new TQLabel( label, frame ); + layout->addWidget( labelWidget ); + + mListBox = new KListBox( frame ); + mListBox->insertStringList( list ); + mListBox->setSelected( 0, true ); + mListBox->ensureCurrentVisible(); + layout->addWidget( mListBox, 10 ); + + connect( mListBox, TQT_SIGNAL( doubleClicked( TQListBoxItem * ) ), + TQT_SLOT( slotOk() ) ); + connect( mListBox, TQT_SIGNAL( returnPressed( TQListBoxItem * ) ), + TQT_SLOT( slotOk() ) ); + + mListBox->setFocus(); + + layout->addStretch(); + + setMinimumWidth( 320 ); +} + +TQString FolderSelectDialog::getItem( const TQString &caption, const TQString &label, + const TQStringList& list ) +{ + FolderSelectDialog dlg( caption, label, list ); + + TQString result; + if ( dlg.exec() == Accepted ) + result = dlg.mListBox->currentText(); + + return result; +} + +void FolderSelectDialog::closeEvent(TQCloseEvent *event) +{ + event->ignore(); +} + +void FolderSelectDialog::reject() +{ +} + diff --git a/tderesources/lib/folderselectdialog.h b/tderesources/lib/folderselectdialog.h new file mode 100644 index 000000000..e33ac80a4 --- /dev/null +++ b/tderesources/lib/folderselectdialog.h @@ -0,0 +1,59 @@ +/* + This file is part of tdepim. + + Copyright (c) 2008 Kevin Ottens <[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. + + In addition, as a special exception, the copyright holders give + permission to link the code of this program with any edition of + the TQt library by Trolltech AS, Norway (or with modified versions + of TQt that use the same license as TQt), and distribute linked + combinations including the two. You must obey the GNU General + Public License in all respects for all of the code used other than + TQt. If you modify this file, you may extend this exception to + your version of the file, but you are not obligated to do so. If + you do not wish to do so, delete this exception statement from + your version. +*/ + +#ifndef FOLDERSELECTDIALOG_H +#define FOLDERSELECTDIALOG_H + +#include <kdialogbase.h> + +namespace KPIM { + +class FolderSelectDialog : public KDialogBase +{ +private: + FolderSelectDialog( const TQString& caption, const TQString& label, + const TQStringList& list ); + +public: + static TQString getItem( const TQString& caption, const TQString& label, + const TQStringList& list ); + +protected: + virtual void closeEvent(TQCloseEvent *event); + void reject(); +private: + KListBox* mListBox; +}; + +} + +#endif // FOLDERSELECTDIALOG_H diff --git a/tderesources/lib/groupwaredataadaptor.cpp b/tderesources/lib/groupwaredataadaptor.cpp new file mode 100644 index 000000000..85dacdaa8 --- /dev/null +++ b/tderesources/lib/groupwaredataadaptor.cpp @@ -0,0 +1,283 @@ +/* + This file is part of tdepim. + + Copyright (c) 2004 Cornelius Schumacher <[email protected]> + Copyright (c) 2004 Till Adam <[email protected]> + Copyright (c) 2005 Reinhold Kainhofer <[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 "groupwaredataadaptor.h" +#include <kdebug.h> +#include <kio/job.h> +#include <libemailfunctions/idmapper.h> + +using namespace KPIM; + +GroupwareUploadItem::GroupwareUploadItem( UploadType type ) : mItemType( KPIM::FolderLister::Unknown ), mType( type ) +{ +} + +KURL GroupwareUploadItem::adaptNewItemUrl( GroupwareDataAdaptor *adaptor, + const KURL &baseurl ) +{ +kdDebug()<<"GroupwareUploadItem::adaptNewItemUrl, baseurl=" << baseurl.url() << endl; + if ( adaptor ) { + TQString path( adaptor->defaultNewItemName( this ) ); +kdDebug() << "path=" << path << endl; + KURL u( baseurl ); + if ( path.isEmpty() ) return u; + else { + u.addPath( path ); +kdDebug() << "Final Path for new item: " << u.url() << endl; + return u; + } + } else return baseurl; +} + +TDEIO::TransferJob *GroupwareUploadItem::createRawUploadJob( + GroupwareDataAdaptor *adaptor, const KURL &/*baseurl*/ ) +{ + Q_ASSERT( adaptor ); + if ( !adaptor ) return 0; + const TQString dta = data(); + //kdDebug(7000) << "Uploading: " << data << endl; + KURL upUrl( url() ); + if ( adaptor ) + adaptor->adaptUploadUrl( upUrl ); + kdDebug(7000) << "Uploading to: " << upUrl.prettyURL() << endl; + TDEIO::TransferJob *job = TDEIO::storedPut( dta.utf8(), upUrl, -1, true, + false, false ); + job->addMetaData( "PropagateHttpHeader", "true" ); + if ( adaptor ) { + job->addMetaData( "customHTTPHeader", "Content-Type: " + adaptor->mimeType() ); + } + return job; +} + +TDEIO::TransferJob *GroupwareUploadItem::createUploadNewJob( + GroupwareDataAdaptor *adaptor, const KURL &baseurl ) +{ +kdDebug()<<"GroupwareUploadItem::createUploadNewJob, baseurl=" << baseurl.url() << endl; + setUrl( adaptNewItemUrl( adaptor, baseurl ) ); + TDEIO::TransferJob *job = createRawUploadJob( adaptor, baseurl ); + if ( job ) { + kdDebug() << "Adding If-None-Match " << endl; + TQString header; + if ( job->outgoingMetaData().contains("customHTTPHeader") ) { + header = job->outgoingMetaData()["customHTTPHeader"]; + header += "\r\n"; + } + header += "If-None-Match: *"; + job->addMetaData( "customHTTPHeader", header ); + } + return job; +} + +TDEIO::TransferJob *GroupwareUploadItem::createUploadJob( + GroupwareDataAdaptor *adaptor, const KURL &baseurl ) +{ +kdDebug()<<"GroupwareUploadItem::createUploadJob" << endl; + TDEIO::TransferJob *job = createRawUploadJob( adaptor, baseurl ); + if ( job && adaptor ) { + kdDebug()<<"Adding If-Match header: " << adaptor->idMapper()->fingerprint( uid() ) << endl; + TQString header; + if ( job->outgoingMetaData().contains("customHTTPHeader") ) { + header = job->outgoingMetaData()["customHTTPHeader"]; + header += "\r\n"; + } +kdDebug()<<"old HEADER: " << header << endl; + header += "If-Match: " + adaptor->idMapper()->fingerprint( uid() ); +kdDebug()<<"new HEADER: " << header << endl; + job->addMetaData( "customHTTPHeader", header ); + } + return job; +} + + +GroupwareDataAdaptor::GroupwareDataAdaptor() + : TQObject(), mFolderLister( 0 ), mIdMapper( 0 ) +{ +} + +GroupwareDataAdaptor::~GroupwareDataAdaptor() +{ +} + +void GroupwareDataAdaptor::setUserPassword( KURL &url ) +{ + kdDebug(5800) << "GroupwareDataAdaptor::setUserPassword, mUser=" + << mUser << endl; + url.setUser( mUser ); + url.setPass( mPassword ); +} + +FolderLister::Entry::List GroupwareDataAdaptor::defaultFolders() +{ + return FolderLister::Entry::List(); +} + +TDEIO::TransferJob *GroupwareDataAdaptor::createUploadJob( const KURL &url, + GroupwareUploadItem *item ) +{ + if ( item ) { + TDEIO::TransferJob *job = item->createUploadJob( this, url ); + setUidForJob( job, item->uid() ); + return job; + } else return 0; +} + +TDEIO::TransferJob *GroupwareDataAdaptor::createUploadNewJob( const KURL &url, + GroupwareUploadItem *item ) +{ +kdDebug()<<"GroupwareDataAdaptor::createUploadNewJob, url=" << url.url() << endl; + if ( item ) { + TDEIO::TransferJob *job = item->createUploadNewJob( this, url ); + setUidForJob( job, item->uid() ); + return job; + } else return 0; +} + +void GroupwareDataAdaptor::processDownloadListItem( const KURL &entry, + const TQString &newFingerprint, KPIM::FolderLister::ContentType type ) +{ + bool download = false; + const TQString &location = entry.path(); + + emit itemOnServer( entry ); + // if not locally present, download + const TQString &localId = idMapper()->localId( location ); + kdDebug(5800) << "Looking up remote: " << location + << " found: " << localId << endl; + if ( localId.isEmpty() || !localItemExists( localId ) ) { + //kdDebug(7000) << "Not locally present, download: " << location << endl; + download = true; + } else { + kdDebug(5800) << "Locally present " << endl; + // locally present, let's check if it's newer than what we have + const TQString &oldFingerprint = idMapper()->fingerprint( localId ); + if ( oldFingerprint != newFingerprint ) { + kdDebug(5800) << "Fingerprint changed old: " << oldFingerprint << + " new: " << newFingerprint << endl; + // something changed on the server, check if we also changed it locally + if ( localItemHasChanged( localId ) ) { + // TODO conflict resolution + kdDebug(5800) << "TODO conflict resolution" << endl; + download = true; + } else { + download = true; + } + } else { + kdDebug(5800) << "Fingerprint not changed, don't download this " << endl; + } + } + if ( download ) { + emit itemToDownload( entry, type ); + } +} + +bool GroupwareDataAdaptor::interpretRemoveJob( TDEIO::Job *job, const TQString &/*jobData*/ ) +{ + if ( !job ) return false; + TDEIO::DeleteJob *deljob = dynamic_cast<TDEIO::DeleteJob*>(job); + bool error = job->error(); + const TQString err = job->errorString(); + + if ( deljob ) { + KURL::List urls( deljob->urls() ); + for ( KURL::List::Iterator it = urls.begin(); it != urls.end(); ++it ) { + if ( error ) { + emit itemDeletionError( *it, err ); + } else { + // FIXME: Don't use TQString() here + emit itemDeleted( TQString(), *it ); + } + } + return true; + } else { + return false; + } +} + + +bool GroupwareDataAdaptor::interpretUploadJob( TDEIO::Job *job, const TQString &/*jobData*/ ) +{ + kdDebug(7000) << "GroupwareDataAdaptor::interpretUploadJob " << endl; + TDEIO::TransferJob *trfjob = dynamic_cast<TDEIO::TransferJob*>(job); + bool error = job->error(); + const TQString err = job->errorString(); + + if ( trfjob ) { + KURL url( trfjob->url() ); + if ( error ) { + emit itemUploadError( url, err ); + } else { + // We don't know the local id here (and we don't want to extract it from + // the idMapper, that's the task of the receiver + emit itemUploaded( uidFromJob( job ), url ); + } + return true; + } else { + return false; + } +} + +bool GroupwareDataAdaptor::interpretUploadNewJob( TDEIO::Job *job, const TQString &/*jobData*/ ) +{ +// TODO: How does the incidence mapper know the old/new ids??? + kdDebug(7000) << "GroupwareDataAdaptor::interpretUploadNewJob " << endl; + TDEIO::TransferJob *trfjob = dynamic_cast<TDEIO::TransferJob*>(job); + bool error = job->error(); + const TQString err = job->errorString(); + + if ( trfjob ) { + KURL url( trfjob->url() ); + if ( error ) { + emit itemUploadNewError( idMapper()->localId( url.path() ), err ); + } else { + // We don't know the local id here (and we don't want to extract it from + // the idMapper, that's the task of the receiver + emit itemUploadedNew( uidFromJob( job ), url ); + } + return true; + } else { + return false; + } +} + +TQString GroupwareDataAdaptor::uidFromJob( TDEIO::Job *job ) const +{ +kdDebug()<<"GroupwareDataAdaptor::uidFromJob( "<<job<<")"<<endl; + if ( mJobUIDMap.contains( job ) ) { + kdDebug()<<" Contained: "<< mJobUIDMap[job] << endl; + return mJobUIDMap[ job ]; + } else { + return TQString(); + } +} + +void GroupwareDataAdaptor::setUidForJob( TDEIO::Job *job, const TQString &uid ) +{ + if ( uid.isEmpty() ) { + mJobUIDMap.remove( job ); + } else { + mJobUIDMap[ job ] = uid; + } +} + + +#include "groupwaredataadaptor.moc" diff --git a/tderesources/lib/groupwaredataadaptor.h b/tderesources/lib/groupwaredataadaptor.h new file mode 100644 index 000000000..b7bd6e333 --- /dev/null +++ b/tderesources/lib/groupwaredataadaptor.h @@ -0,0 +1,364 @@ +/* + This file is part of tdepim. + + Copyright (c) 2004 Cornelius Schumacher <[email protected]> + Copyright (c) 2004 Till Adam <[email protected]> + Copyright (c) 2005 Reinhold Kainhofer <[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 KPIM_GROUPWAREDATAADAPTOR_H +#define KPIM_GROUPWAREDATAADAPTOR_H + +#include <groupwareresourcejob.h> +#include <folderlister.h> +#include <kurl.h> +#include <tqstring.h> +#include <libkcal/listbase.h> +#include <tqobject.h> +#include <tdepimmacros.h> + + +namespace TDEIO { +class TransferJob; +class Job; +} + +namespace KPIM { + +class FolderLister; +class IdMapper; +class GroupwareDataAdaptor; +//class GroupwareJob; + +class KDE_EXPORT GroupwareUploadItem +{ + public: + typedef KCal::ListBase<GroupwareUploadItem> List; + enum UploadType { + Added, + Changed, + Deleted + }; + + GroupwareUploadItem( UploadType type ); + virtual ~GroupwareUploadItem() {} + KURL url() const { return mUrl; } + void setUrl( const KURL &url ) { mUrl = url; } + + TQString uid() const { return mUid; } + void setUid( const TQString &uid ) { mUid = uid; } + + TQString fingerprint() const { return mFingerprint; } + void setFingerprint( const TQString &fpr ) { mFingerprint = fpr; } + + virtual TQString data() const { return mData; } + virtual void setData( const TQString &data ) { mData = data; } + virtual KURL adaptNewItemUrl( GroupwareDataAdaptor *adaptor, + const KURL &url ); + + virtual TDEIO::TransferJob *createRawUploadJob( + GroupwareDataAdaptor *adaptor, const KURL &url ); + virtual TDEIO::TransferJob *createUploadNewJob( + GroupwareDataAdaptor *adaptor, const KURL &url ); + virtual TDEIO::TransferJob *createUploadJob( GroupwareDataAdaptor *adaptor, + const KURL &url ); + virtual KPIM::FolderLister::ContentType itemType() { return mItemType; } + protected: + KPIM::FolderLister::ContentType mItemType; + private: + KURL mUrl; + TQString mUid; + TQString mData; + TQString mFingerprint; + UploadType mType; +}; + + +class KDE_EXPORT GroupwareDataAdaptor : public TQObject +{ +Q_OBJECT + + public: + GroupwareDataAdaptor(); + virtual ~GroupwareDataAdaptor(); + + void setFolderLister( FolderLister *folderLister ) + { + mFolderLister = folderLister; + } + FolderLister *folderLister() + { + return mFolderLister; + } + + /** + Set progress message shown by progress manager during download. It will + be interpreted as rich text, so it might have to be escaped. + */ + void setDownloadProgressMessage( const TQString &v ) + { + mDownloadProgressMessage = v; + } + /** + Get download progress message. See setDownloadProgressMessage(). + */ + TQString downloadProgressMessage() const + { + return mDownloadProgressMessage; + } + + /** + Set progress message shown by progress manager during upload. It will + be interpreted as rich text, so it might have to be escaped. + */ + void setUploadProgressMessage( const TQString &v ) + { + mUploadProgressMessage = v; + } + /** + Get upload progress message. See setUploadProgressMessage(). + */ + TQString uploadProgressMessage() const + { + return mUploadProgressMessage; + } + + /** + Set base URL. + */ + void setBaseURL( const KURL &url ) + { + mBaseURL = url; + } + /** + Get base URL. See setBaseURL(). + */ + KURL baseURL() const + { + return mBaseURL; + } + + /** + Set user name. + */ + void setUser( const TQString &v ) + { + mUser = v; + } + /** + Get user. See setUser(). + */ + TQString user() const + { + return mUser; + } + + /** + Set password of user. + */ + void setPassword( const TQString &v ) + { + mPassword = v; + } + /** + Get password. See setPassword(). + */ + TQString password() const + { + return mPassword; + } + + /** + Set id mapper. + */ + void setIdMapper( KPIM::IdMapper *v ) + { + mIdMapper = v; + } + /** + Get idMapper. See setIdMapper(). + */ + KPIM::IdMapper *idMapper() const + { + return mIdMapper; + } + + void setUserPassword( KURL &url ); + + /** Adapt the url for downloading. Sets the username and password and calls + * customAdaptDownloadUrl, which you can reimplement for custom adaptions. + */ + virtual void adaptDownloadUrl( KURL &url ) + { + setUserPassword( url ); + customAdaptDownloadUrl( url ); + } + /** Adapt the url for uploading. Sets the username and password and calls + * customAdaptUploadUrl, which you can reimplement for custom adaptions. */ + virtual void adaptUploadUrl( KURL &url ) + { + setUserPassword( url ); + customAdaptUploadUrl( url ); + } + /** Apply custom adaptions to the url for downloading. Reimplement this + * method if you want to use webdav:// instead of http:// URLs. */ + virtual void customAdaptDownloadUrl( KURL &/*url*/ ) {} + /** Apply custom adaptions to the url for uploading. Reimplement this + * method if you want to use webdav:// instead of http:// URLs. */ + virtual void customAdaptUploadUrl( KURL &/*url*/ ) {} + + /** Return the mime-type expected by the resource. */ + virtual TQString mimeType() const = 0; + /** Identifier of the Resource. Used for the custom fields where + resource-specific information is stored. */ + virtual TQCString identifier() const = 0; + + /** Returns whether the item with the given localId exists locally. */ + virtual bool localItemExists( const TQString &localId ) = 0; + /** Returns whether the item was changed locally since the last download + from the server. */ + virtual bool localItemHasChanged( const TQString &localId ) = 0; + /** Remove the item from the local cache. */ + virtual void deleteItem( const TQString &localId ) = 0; + + /** Removed the changed flag for the item with the given uid. */ + virtual void clearChange( const TQString &uid ) = 0; + + virtual FolderLister::Entry::List defaultFolders(); + virtual TQValueList<FolderLister::ContentType> supportedTypes() = 0; + virtual bool supports( FolderLister::ContentType type ) { + return supportedTypes().contains( type ); + } + + + // Creating jobs + /** Creates the TDEIO::Job for logging in to the server. This is only + * called if the GroupwareDataAdaptor::GWResNeedsLogin flag is set + * for the resource. */ + virtual TDEIO::Job *createLoginJob( const KURL &, const TQString &/*user*/, + const TQString &/*password*/ ) { return 0; } + /** Creates the TDEIO::Job for logging off the server. This is only + * called if the GroupwareDataAdaptor::GWResNeedsLogoff flag is set + * for the resource. */ + virtual TDEIO::Job *createLogoffJob( const KURL &, const TQString &/*user*/, + const TQString &/*password*/ ) { return 0; } + /** Creates the TDEIO::Job for listing all subfolders of the given url. */ + virtual TDEIO::Job *createListFoldersJob ( const KURL & ) = 0; + /** Creates the TDEIO::TransferJob for listing all items in the given url. */ + virtual TDEIO::TransferJob *createListItemsJob( const KURL & ) = 0; + /** Creates the TDEIO::TransferJob for downloading one given item. */ + virtual TDEIO::TransferJob *createDownloadJob( const KURL &, + FolderLister::ContentType ) = 0; + /** Creates the TDEIO::TransferJob for downloading a list of items items. */ + virtual TDEIO::TransferJob *createDownloadJob( const TQMap<KURL,FolderLister::ContentType> & ) { return 0; } + /** Create the job to remove the deletedItems from the server. The base + URL of the server is passed as uploadurl. */ + virtual TDEIO::Job *createRemoveJob( const KURL &, + const KPIM::GroupwareUploadItem::List &/*deletedItems*/ ) { return 0; } + /** Create the job to remove the item from the server. The base + URL of the server is passed as uploadurl. */ + virtual TDEIO::Job *createRemoveJob( const KURL &, + KPIM::GroupwareUploadItem */*deletedItem*/ ) { return 0; } + /** Create the job to change the item on the server (at the given URL) */ + virtual TDEIO::TransferJob *createUploadJob( const KURL &, + GroupwareUploadItem *item ); + /** Create the job to change the items on the server (at the given URL) */ + virtual TDEIO::TransferJob *createUploadJob( const KURL &, const GroupwareUploadItem::List &/*items*/ ) { return 0; } + /** Create the job to add the item to the server (at the given baseURL) */ + virtual TDEIO::TransferJob *createUploadNewJob( const KURL &, + GroupwareUploadItem *item ); + /** Create the job to add the items to the server (at the given baseURL) */ + virtual TDEIO::TransferJob *createUploadNewJob( const KURL &, const GroupwareUploadItem::List &/*items*/ ) { return 0; } + + + // Interpreting the result of the jobs + /** Extract the success information from the login job, created by + * createLoginJob. Return true, if the login was successfull, or false + * if the user could not be authenticated or something else went wrong. + * In that case the resource will not be marked as open. */ + virtual bool interpretLoginJobResult( TDEIO::Job * ) { return true; } + /** Extract the success information from the logoff job, created by + * createLogoffJob. */ + virtual bool interpretLogoffJobResult( TDEIO::Job * ) { return true; } + + virtual void interpretListFoldersJob( TDEIO::Job *, FolderLister *) = 0; + /** Extract the list of items on the server and the list of items to be + downloaded from the results of the job (the job was created by + createListitemsJob). */ + virtual bool interpretListItemsJob( TDEIO::Job *, const TQString &jobData ) = 0; + virtual bool interpretDownloadItemsJob( TDEIO::Job *job, const TQString &jobData ) = 0; + virtual bool interpretRemoveJob( TDEIO::Job *job, const TQString &jobData ); + virtual bool interpretUploadJob( TDEIO::Job *job, const TQString &/*jobData*/ ); + virtual bool interpretUploadNewJob( TDEIO::Job *job, const TQString &/*jobData*/ ); + + virtual void processDownloadListItem( const KURL &entry, + const TQString &newFingerprint, KPIM::FolderLister::ContentType type ); + /** Return the default file name for a new item. */ + virtual TQString defaultNewItemName( GroupwareUploadItem * ) + { + return TQString(); + } + virtual TQString uidFromJob( TDEIO::Job *job ) const; + virtual void setUidForJob( TDEIO::Job *job, const TQString &uid ); + + + enum { + GWResBatchCreate = 0x0001, + GWResBatchModify = 0x0002, + GWResBatchDelete = 0x0004, + GWResBatchRequest = 0x0008, + GWResHandleSingleIncidences = 0x0020, + GWResNeedsLogon = 0x0040, + GWResNeedsLogoff = 0x0080 + }; + virtual long flags() const = 0; + + + signals: + void folderInfoRetrieved( const KURL &href, const TQString &name, + KPIM::FolderLister::ContentType ); + void folderSubitemRetrieved( const KURL &, bool isFolder ); + + void itemToDownload( const KURL &remoteURL, KPIM::FolderLister::ContentType type ); + /** passed the whole remote url (including hostname) to the receiver */ + void itemOnServer( const KURL &remoteURL ); + + void itemDownloaded( const TQString &localID, const KURL &remoteURL, + const TQString &fingerprint ); + void itemDeleted( const TQString &localID, const KURL &remoteURL ); + void itemUploaded( const TQString &localID, const KURL &remoteURL ); + void itemUploadedNew( const TQString &localID, const KURL &remoteURL ); + + void itemDownloadError( const KURL &remoteURL, const TQString &error ); + void itemDeletionError( const KURL &remoteURL, const TQString &error ); + void itemUploadError( const KURL &remoteURL, const TQString &error ); + void itemUploadNewError( const TQString &localID, const TQString &error ); + + private: + FolderLister *mFolderLister; + TQString mDownloadProgressMessage; + TQString mUploadProgressMessage; + KURL mBaseURL; + TQString mUser; + TQString mPassword; + KPIM::IdMapper *mIdMapper; + TQMap<TDEIO::Job*,TQString> mJobUIDMap; +}; + +} + +#endif diff --git a/tderesources/lib/groupwaredownloadjob.cpp b/tderesources/lib/groupwaredownloadjob.cpp new file mode 100644 index 000000000..9104da847 --- /dev/null +++ b/tderesources/lib/groupwaredownloadjob.cpp @@ -0,0 +1,300 @@ +/* + This file is part of tdepim. + + Copyright (c) 2004 Cornelius Schumacher <[email protected]> + Copyright (c) 2004 Till Adam <[email protected]> + Copyright (c) 2005 Reinhold Kainhofer <[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 "groupwaredownloadjob.h" + +#include "folderlister.h" +#include "groupwaredataadaptor.h" + +#include <kdebug.h> +#include <klocale.h> +#include <kurl.h> +#include <kio/job.h> +#include <libemailfunctions/idmapper.h> +#include <libtdepim/progressmanager.h> + +using namespace KPIM; + +GroupwareDownloadJob::GroupwareDownloadJob( GroupwareDataAdaptor *adaptor ) + : GroupwareJob( adaptor ), mProgress(0), + mDownloadJob(0), mListEventsJob(0) +{ +} + +void GroupwareDownloadJob::run() +{ + kdDebug(5800) << "GroupwareDownloadJob::run()" << endl; + + if ( !adaptor() ) { + error( i18n("Unable to initialize the download job.") ); + return; + } + + if ( adaptor()->folderLister() ){ + mFoldersForDownload = adaptor()->folderLister()->activeFolderIds(); + } else { + // TODO: If we don't have a folder lister, use the base URL (e.g. if all + // communication goes through one script on the server + } + + mItemsForDownload.clear(); + mCurrentlyOnServer.clear(); + connect( adaptor(), TQT_SIGNAL( itemToDownload( const KURL &, KPIM::FolderLister::ContentType ) ), + TQT_SLOT( slotItemToDownload( const KURL &, KPIM::FolderLister::ContentType ) ) ); + connect( adaptor(), TQT_SIGNAL( itemOnServer( const KURL & ) ), + TQT_SLOT( slotItemOnServer( const KURL & ) ) ); + connect( adaptor(), TQT_SIGNAL( itemDownloaded( const TQString &, const KURL &, const TQString & ) ), + TQT_SLOT( slotItemDownloaded( const TQString &, const KURL &, const TQString & ) ) ); + connect( adaptor(), TQT_SIGNAL( itemDownloadError( const KURL &, const TQString & ) ), + TQT_SLOT( slotItemDownloadError( const KURL &, const TQString & ) ) ); + + mProgress = KPIM::ProgressManager::instance()->createProgressItem( + KPIM::ProgressManager::getUniqueID(), + adaptor()->downloadProgressMessage() ); + connect( mProgress, + TQT_SIGNAL( progressItemCanceled( KPIM::ProgressItem * ) ), + TQT_SLOT( cancelLoad() ) ); + + listItems(); +} + +void GroupwareDownloadJob::listItems() +{ + if ( mFoldersForDownload.isEmpty() ) { + if ( mProgress ) { + mProgress->setTotalItems( mItemsForDownload.count() + 1 ); + mProgress->setCompletedItems( 1 ); + mProgress->updateProgress(); + } + + /* Delete incidences no longer present on the server */ + deleteIncidencesGoneFromServer(); + downloadItem(); + } else { + + //kdDebug(7000) << "props: " << props.toString() << endl; + KURL url = mFoldersForDownload.front(); + mFoldersForDownload.pop_front(); + kdDebug(5800) << "listItems: " << url.url() << endl; + + adaptor()->adaptDownloadUrl( url ); + kdDebug(5800) << "listItems, after adaptDownloadUrl: " << url.url() << endl; + + kdDebug(5800) << "OpenGroupware::listIncidences(): " << url << endl; + + mListItemsData = TQString(); + mListEventsJob = adaptor()->createListItemsJob( url ); + + connect( mListEventsJob, TQT_SIGNAL( result( TDEIO::Job * ) ), + TQT_SLOT( slotListItemsResult( TDEIO::Job * ) ) ); + connect( mListEventsJob, TQT_SIGNAL( data( TDEIO::Job *, const TQByteArray & ) ), + TQT_SLOT( slotListItemsData( TDEIO::Job *, const TQByteArray & ) ) ); + } +} + + +void GroupwareDownloadJob::slotListItemsData( TDEIO::Job *, const TQByteArray &data ) +{ + kdDebug(5800) << "OpenGroupware::slotListItemsData()" << endl; + + mListItemsData.append( data.data() ); +} + + +void GroupwareDownloadJob::slotListItemsResult( TDEIO::Job *job ) +{ + kdDebug(5800) << "GroupwareDownloadJob::slotListItemsResult(): " << endl; + + if ( job->error() ) { + if ( mProgress ) { + mProgress->setComplete(); + mProgress = 0; + } + error( job->errorString() ); + } else { + adaptor()->interpretListItemsJob( job, mListItemsData ); + } + + mListItemsData = TQString(); + mListEventsJob = 0; + + listItems(); +} + +void GroupwareDownloadJob::deleteIncidencesGoneFromServer() +{ + TQMap<TQString, TQString> remoteIds( adaptor()->idMapper()->remoteIdMap() ); + KURL::List::ConstIterator it = mCurrentlyOnServer.begin(); + while ( it != mCurrentlyOnServer.end() ) { + remoteIds.remove( (*it).path() ); + ++it; + } + TQMap<TQString, TQString>::ConstIterator it2; + for (it2 = remoteIds.begin(); it2 != remoteIds.end(); ++it2) { + adaptor()->deleteItem( remoteIds[ it2.key() ] ); + } +} + +void GroupwareDownloadJob::downloadItem() +{ + kdDebug(7000) << " downloadItem " << endl; + if ( mItemsForDownload.isEmpty() ) { + if ( mProgress ) mProgress->setComplete(); + + mItemsForDownload.clear(); + mItemsDownloading.clear(); + mItemsDownloaded.clear(); + mItemsDownloadError.clear(); + + mProgress = 0; + success(); + } else { + if ( adaptor()->flags() & KPIM::GroupwareDataAdaptor::GWResBatchRequest ) { + mDownloadItemsData = TQString(); + mDownloadJob = adaptor()->createDownloadJob( mItemsForDownload ); + mItemsDownloading = mItemsForDownload; + mItemsForDownload.clear(); + } else { + // Download the first item of the list + TQMap<KURL,KPIM::FolderLister::ContentType>::Iterator it = mItemsForDownload.begin(); + KURL href( it.key() ); + KPIM::FolderLister::ContentType ctype = it.data(); + mItemsDownloading.insert( it.key(), it.data() ); + mItemsForDownload.remove( it.key() ); + + adaptor()->adaptDownloadUrl( href ); + mDownloadItemsData = TQString(); + + mDownloadJob = adaptor()->createDownloadJob( href, ctype ); + } + connect( mDownloadJob, TQT_SIGNAL( result( TDEIO::Job * ) ), + TQT_SLOT( slotDownloadItemResult( TDEIO::Job * ) ) ); + connect( mDownloadJob, TQT_SIGNAL( data( TDEIO::Job *, const TQByteArray & ) ), + TQT_SLOT( slotDownloadItemData( TDEIO::Job *, const TQByteArray & ) ) ); + } +} + +void GroupwareDownloadJob::slotDownloadItemResult( TDEIO::Job *job ) +{ + kdDebug(5800) << "GroupwareDownloadJob::slotDownloadItemResult(): " << endl; + + TDEIO::TransferJob *trfjob = dynamic_cast<TDEIO::TransferJob*>(job); + if ( !trfjob ) return; + + if ( job->error() ) { + error( job->errorString() ); + } else { + adaptor()->interpretDownloadItemsJob( job, mDownloadItemsData ); + } + + if ( mProgress ) { + mProgress->incCompletedItems(); + mProgress->updateProgress(); + } + mDownloadItemsData = TQString(); + mDownloadJob = 0; + + downloadItem(); +} + +void GroupwareDownloadJob::slotDownloadItemData( TDEIO::Job *, const TQByteArray &data ) +{ + kdDebug(5800) << "OpenGroupware::slotDownloadItemData()" << endl; + + mDownloadItemsData.append( TQString::fromUtf8( data.data(), data.size() ) ); +} + +void GroupwareDownloadJob::slotItemToDownload( const KURL &remoteURL, + KPIM::FolderLister::ContentType type ) +{ + KURL url( remoteURL ); + adaptor()->adaptDownloadUrl( url ); + if ( !mItemsForDownload.contains( url ) && + !mItemsDownloading.contains( url ) && + !mItemsDownloaded.contains( url ) ) { + mItemsForDownload.insert( url, type ); + } +} + + +void GroupwareDownloadJob::slotItemOnServer( const KURL &remoteURL ) +{ +kdDebug()<<"GroupwareDownloadJob::slotItemOnServer( " << remoteURL.url() << ")" << endl; + if ( !mCurrentlyOnServer.contains( remoteURL ) ) { + mCurrentlyOnServer.append( remoteURL ); + } +} + + +void GroupwareDownloadJob::slotItemDownloadError( const KURL &remoteURL, const TQString &/*error*/ ) +{ + // TODO: Error handling! + if ( mItemsDownloading.contains( remoteURL ) ) { + mItemsDownloadError[ remoteURL ] = mItemsDownloading[ remoteURL ]; + } else if ( mItemsForDownload.contains( remoteURL ) ) { + mItemsDownloadError[ remoteURL ] = mItemsForDownload[ remoteURL ]; + } +} + + +void GroupwareDownloadJob::slotItemDownloaded( const TQString &localID, + const KURL &remoteURL, const TQString &fingerprint ) +{ +kdDebug()<<"GroupwareDownloadJob::slotItemDownloaded( " << localID << ", " << remoteURL.url() << ", " << fingerprint << ")" << endl; + if ( mItemsForDownload.contains( remoteURL ) ) { + mItemsDownloaded[ remoteURL ] = mItemsForDownload[ remoteURL ]; + mItemsForDownload.remove( remoteURL ); + } + if ( mItemsDownloading.contains( remoteURL ) ) { + mItemsDownloaded[ remoteURL ] = mItemsDownloading[ remoteURL ]; + mItemsDownloading.remove( remoteURL ); + } + if ( !mItemsDownloaded.contains( remoteURL ) ) { + mItemsDownloaded[ remoteURL ] = KPIM::FolderLister::Unknown; + } + adaptor()->idMapper()->setRemoteId( localID, remoteURL.path() ); + adaptor()->idMapper()->setFingerprint( localID, fingerprint ); +} + + + +void GroupwareDownloadJob::kill() +{ + cancelLoad(); +} + + + +void GroupwareDownloadJob::cancelLoad() +{ + if ( mDownloadJob ) mDownloadJob->kill(); + mDownloadJob = 0; + if ( mListEventsJob ) mListEventsJob->kill(); + mListEventsJob = 0; + if ( mProgress ) mProgress->setComplete(); + + + mProgress = 0; +} + +#include "groupwaredownloadjob.moc" diff --git a/tderesources/lib/groupwaredownloadjob.h b/tderesources/lib/groupwaredownloadjob.h new file mode 100644 index 000000000..6cf3bf249 --- /dev/null +++ b/tderesources/lib/groupwaredownloadjob.h @@ -0,0 +1,95 @@ +/* + This file is part of tdepim. + + Copyright (c) 2004 Cornelius Schumacher <[email protected]> + Copyright (c) 2004 Till Adam <[email protected]> + Copyright (c) 2005 Reinhold Kainhofer <[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 KPIM_GROUPWAREDOWNLOADJOB_H +#define KPIM_GROUPWAREDOWNLOADJOB_H + +#include "groupwareresourcejob.h" +#include <tqstringlist.h> + +namespace TDEIO { + class Job; + class TransferJob; +} + +namespace KPIM { + +class GroupwareDataAdaptor; +class ProgressItem; + +/** + This class provides a resource for accessing a Groupware calendar with local caching. +*/ +class GroupwareDownloadJob : public GroupwareJob +{ + Q_OBJECT + + public: + GroupwareDownloadJob( GroupwareDataAdaptor *adaptor ); + + void kill(); + + protected: + void listItems(); + void deleteIncidencesGoneFromServer(); + void downloadItem(); + + protected slots: + void run(); + + void cancelLoad(); + + void slotListItemsResult( TDEIO::Job * ); + void slotListItemsData( TDEIO::Job *, const TQByteArray & ); + void slotDownloadItemResult( TDEIO::Job * ); + void slotDownloadItemData( TDEIO::Job *, const TQByteArray & ); + + void slotItemToDownload( const KURL &remoteURL, + KPIM::FolderLister::ContentType type ); + void slotItemOnServer( const KURL &remoteURL ); + void slotItemDownloaded( const TQString &localID, const KURL &remoteURL, + const TQString &fingerprint ); + void slotItemDownloadError( const KURL &remoteURL, const TQString &error ); + + private: + KURL::List mFoldersForDownload; + /** mCurrentlyOnServer is the list of pathes of all items on the server. + These pathes don't contain the server name! */ + KURL::List mCurrentlyOnServer; + + TQMap<KURL,KPIM::FolderLister::ContentType> mItemsForDownload; + TQMap<KURL,KPIM::FolderLister::ContentType> mItemsDownloading; + TQMap<KURL,KPIM::FolderLister::ContentType> mItemsDownloaded; + TQMap<KURL,KPIM::FolderLister::ContentType> mItemsDownloadError; + + KPIM::ProgressItem *mProgress; + + TDEIO::TransferJob *mDownloadJob; + TDEIO::TransferJob *mListEventsJob; + + TQString mListItemsData; + TQString mDownloadItemsData; +}; + +} + +#endif diff --git a/tderesources/lib/groupwareresourcejob.cpp b/tderesources/lib/groupwareresourcejob.cpp new file mode 100644 index 000000000..b7e4b57b0 --- /dev/null +++ b/tderesources/lib/groupwareresourcejob.cpp @@ -0,0 +1,59 @@ +/* + This file is part of tdepim. + + Copyright (c) 2004 Cornelius Schumacher <[email protected]> + Copyright (c) 2004 Till Adam <[email protected]> + Copyright (c) 2005 Reinhold Kainhofer <[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 "groupwareresourcejob.h" + +#include <tqtimer.h> + +using namespace KPIM; + +GroupwareJob::GroupwareJob( GroupwareDataAdaptor *adaptor ) + : mAdaptor( adaptor ) +{ + TQTimer::singleShot( 0, this, TQT_SLOT( run() ) ); +} + +bool GroupwareJob::error() const +{ + return !mErrorString.isNull(); +} + +TQString GroupwareJob::errorString() const +{ + return mErrorString; +} + +void GroupwareJob::success() +{ + mErrorString = TQString(); + emit( result( this ) ); +} + +void GroupwareJob::error( const TQString &errorString ) +{ + mErrorString = errorString; + emit( result( this ) ); +} + + +#include "groupwareresourcejob.moc" diff --git a/tderesources/lib/groupwareresourcejob.h b/tderesources/lib/groupwareresourcejob.h new file mode 100644 index 000000000..f2818f2cd --- /dev/null +++ b/tderesources/lib/groupwareresourcejob.h @@ -0,0 +1,69 @@ +/* + This file is part of tdepim. + + Copyright (c) 2004 Cornelius Schumacher <[email protected]> + Copyright (c) 2004 Till Adam <[email protected]> + Copyright (c) 2005 Reinhold Kainhofer <[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 KPIM_GROUPWAREJOB_H +#define KPIM_GROUPWAREJOB_H + +#include <tqobject.h> +#include <tqstring.h> +#include "folderlister.h" + +namespace KPIM { + +class GroupwareDataAdaptor; + +/** + This class provides a resource for accessing a Groupware kioslave-based + calendar. +*/ +class GroupwareJob : public TQObject +{ + Q_OBJECT + + public: + GroupwareJob( GroupwareDataAdaptor *adaptor ); + + bool error() const; + TQString errorString() const; + + virtual void kill() = 0; + + signals: + void result( KPIM::GroupwareJob * ); + + protected: + void success(); + void error( const TQString & ); + GroupwareDataAdaptor *adaptor() { return mAdaptor; } + const GroupwareDataAdaptor *adaptor() const { return mAdaptor; } + + protected slots: + virtual void run() = 0; + + private: + TQString mErrorString; + GroupwareDataAdaptor *mAdaptor; +}; + +} + +#endif diff --git a/tderesources/lib/groupwareuploadjob.cpp b/tderesources/lib/groupwareuploadjob.cpp new file mode 100644 index 000000000..cf46571fc --- /dev/null +++ b/tderesources/lib/groupwareuploadjob.cpp @@ -0,0 +1,485 @@ +/* + This file is part of tdepim. + + Copyright (c) 2004 Cornelius Schumacher <[email protected]> + Copyright (c) 2004 Till Adam <[email protected]> + Copyright (c) 2005 Reinhold Kainhofer <[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 "groupwareuploadjob.h" + +#include "folderlister.h" +#include "groupwaredataadaptor.h" + +#include <libemailfunctions/idmapper.h> +#include <libtdepim/progressmanager.h> + +#include <kdebug.h> +#include <kurl.h> +#include <kio/job.h> + +#include <tqstringlist.h> +#include <tqtimer.h> +#include <klocale.h> + +using namespace KPIM; + +GroupwareUploadJob::GroupwareUploadJob( GroupwareDataAdaptor *adaptor ) + : GroupwareJob( adaptor ), mUploadJob(0), + mDeletionJob(0), mUploadProgress(0) +{ +} + +void GroupwareUploadJob::run() +{ + deleteItem(); + mUploadProgress = KPIM::ProgressManager::instance()->createProgressItem( + KPIM::ProgressManager::getUniqueID(), + adaptor()->uploadProgressMessage() ); + connect( mUploadProgress, + TQT_SIGNAL( progressItemCanceled( KPIM::ProgressItem * ) ), + TQT_SLOT( cancelSave() ) ); + + connect( adaptor(), TQT_SIGNAL( itemDeletionError( const KURL &, const TQString & ) ), + TQT_SLOT( slotItemDeleteError( const KURL &, const TQString & ) ) ); + connect( adaptor(), TQT_SIGNAL( itemUploadError( const KURL &, const TQString & ) ), + TQT_SLOT( slotItemUploadError( const KURL &, const TQString & ) ) ); + connect( adaptor(), TQT_SIGNAL( itemUploadNewError( const TQString &, const TQString & ) ), + TQT_SLOT( slotItemUploadNewError( const TQString &, const TQString & ) ) ); + + connect( adaptor(), TQT_SIGNAL( itemDeleted( const TQString &, const KURL & ) ), + TQT_SLOT( slotItemDeleted( const TQString &, const KURL & ) ) ); + connect( adaptor(), TQT_SIGNAL( itemUploaded( const TQString &, const KURL & ) ), + TQT_SLOT( slotItemUploaded( const TQString &, const KURL & ) ) ); + connect( adaptor(), TQT_SIGNAL( itemUploadedNew( const TQString &, const KURL& ) ), + TQT_SLOT( slotItemUploadedNew( const TQString &, const KURL & ) ) ); + + + mUploadProgress->setTotalItems( mAddedItems.size() + mChangedItems.size() + + ((mChangedItems.isEmpty())?0:1) ); + mUploadProgress->updateProgress(); +} + + + +void GroupwareUploadJob::deleteItem() +{ + kdDebug(5800)<<"GroupwareUploadJob::deleteItem()"<<endl; + if ( mDeletedItems.isEmpty() ) { + TQTimer::singleShot( 0, this, TQT_SLOT( uploadItem() ) ); + } else { + kdDebug(7000) << " Deleting " << mDeletedItems.size() << " items from the server " << endl; + + KURL url( adaptor()->baseURL() ); + adaptor()->adaptUploadUrl( url ); + if ( adaptor()->flags() & KPIM::GroupwareDataAdaptor::GWResBatchDelete ) { +kdDebug() << "Using batch delete " << endl; + mDeletionJob = adaptor()->createRemoveJob( url, mDeletedItems ); + mItemsUploading += mDeletedItems; + mDeletedItems.clear(); + } else { +kdDebug() << "Not using batch delete " << endl; + KPIM::GroupwareUploadItem *item = mDeletedItems.front(); + mDeletionJob = adaptor()->createRemoveJob( url, item ); + mItemsUploading.append( mDeletedItems.front() ); + mDeletedItems.pop_front(); + } + + if ( mDeletionJob ) { + mDeletionJobData = TQString(); + connect( mDeletionJob, TQT_SIGNAL( result( TDEIO::Job* ) ), + TQT_SLOT( slotDeletionJobResult( TDEIO::Job* ) ) ); +// connect( mDeletionJob, TQT_SIGNAL( data( TDEIO::Job *, const TQByteArray & ) ), +// TQT_SLOT( slotDeletionJobData( TDEIO::Job *, const TQByteArray & ) ) ); + } else { + deleteItem(); + } + } +} + + + +void GroupwareUploadJob::slotDeletionJobData( TDEIO::Job *, const TQByteArray &data ) +{ + kdDebug(5800) << "OpenGroupware::slotDeletionData()" << endl; + + mDeletionJobData.append( data.data() ); +} + + + +void GroupwareUploadJob::slotDeletionJobResult( TDEIO::Job *job ) +{ + if ( job && adaptor() ) { + adaptor()->interpretRemoveJob( job, mDeletionJobData ); + } + mDeletionJob = 0; + TQTimer::singleShot( 0, this, TQT_SLOT( deleteItem() ) ); +} + + + +void GroupwareUploadJob::uploadItem() +{ + kdDebug(5800)<<"GroupwareUploadJob::uploadItem()"<<endl; + if ( mChangedItems.isEmpty() ) { + TQTimer::singleShot( 0, this, TQT_SLOT( uploadNewItem() ) ); + } else { + kdDebug(5800)<<"We still have "<<mChangedItems.count()<<" changed items to upload"<<endl; + + KURL url( adaptor()->baseURL() ); + adaptor()->adaptUploadUrl( url ); + if ( adaptor()->flags() & KPIM::GroupwareDataAdaptor::GWResBatchModify ) { +kdDebug() << "Using batch upload " << endl; + mUploadJob = adaptor()->createUploadJob( url, mChangedItems ); + mItemsUploading += mChangedItems; + mChangedItems.clear(); + } else { +kdDebug() << "Not using batch upload " << endl; + KPIM::GroupwareUploadItem *item = mChangedItems.front(); + mUploadJob = adaptor()->createUploadJob( url, item ); + mItemsUploading.append( mChangedItems.front() ); + mChangedItems.pop_front(); + } + + if ( mUploadJob ) { + mUploadJobData = TQString(); + connect( mUploadJob, TQT_SIGNAL( result( TDEIO::Job* ) ), + TQT_SLOT( slotUploadJobResult( TDEIO::Job* ) ) ); + connect( mUploadJob, TQT_SIGNAL( data( TDEIO::Job *, const TQByteArray & ) ), + TQT_SLOT( slotUploadJobData( TDEIO::Job *, const TQByteArray & ) ) ); + } else { + uploadItem(); + } + } +} + + +void GroupwareUploadJob::slotUploadJobData( TDEIO::Job *, const TQByteArray &data ) +{ + kdDebug(5800) << "OpenGroupware::slotUploadData()" << endl; + + mUploadJobData.append( data.data() ); +} + + + +void GroupwareUploadJob::slotUploadJobResult( TDEIO::Job *job ) +{ + if ( job && adaptor() ) { + adaptor()->interpretUploadJob( job, mUploadJobData ); + } + mUploadJob = 0; + TQTimer::singleShot( 0, this, TQT_SLOT( uploadItem() ) ); +} + + + + +void GroupwareUploadJob::uploadNewItem() +{ + kdDebug(5800)<<"GroupwareUploadJob::uploadNewItem()"<<endl; + if ( !mAddedItems.isEmpty() ) { + + if ( adaptor()->flags() & KPIM::GroupwareDataAdaptor::GWResBatchCreate ) { + KURL url( adaptor()->folderLister()->writeDestinationId( FolderLister::All ) ); + adaptor()->adaptUploadUrl( url ); +kdDebug() << "Using batch create to " << url.url() << endl; + mUploadJob = adaptor()->createUploadNewJob( url, mAddedItems ); + mItemsUploading += mAddedItems; + mAddedItems.clear(); + } else { + KPIM::GroupwareUploadItem *item = mAddedItems.front(); + KURL url( adaptor()->folderLister()->writeDestinationId( item->itemType() ) ); + adaptor()->adaptUploadUrl( url ); +kdDebug() << "Not using batch create to " << url.url() << " for item of type " << item->itemType() << endl; + if ( !url.isEmpty() ) { + mUploadJob = adaptor()->createUploadNewJob( url, item ); + mItemsUploading.append( mAddedItems.front() ); + } + mAddedItems.pop_front(); + } + + if ( mUploadJob ) { + mUploadNewJobData = TQString(); + connect( mUploadJob, TQT_SIGNAL( result( TDEIO::Job* ) ), + TQT_SLOT( slotUploadNewJobResult( TDEIO::Job* ) ) ); + connect( mUploadJob, TQT_SIGNAL( data( TDEIO::Job *, const TQByteArray & ) ), + TQT_SLOT( slotUploadNewJobData( TDEIO::Job *, const TQByteArray & ) ) ); + } else { + uploadNewItem(); + } + + } else { + kdDebug(5800)<<"We are finished uploading all items. Setting progress to completed."<<endl; + uploadCompleted(); + } +} + +void GroupwareUploadJob::slotUploadNewJobData( TDEIO::Job *, const TQByteArray &data ) +{ + kdDebug(5800) << "OpenGroupware::slotUploadNewJobData()" << endl; + + mUploadNewJobData.append( data.data() ); +} + + + +void GroupwareUploadJob::slotUploadNewJobResult( TDEIO::Job *job ) +{ + if ( job && adaptor() ) { + adaptor()->interpretUploadNewJob( job, mUploadNewJobData ); + } + mUploadJob = 0; + TQTimer::singleShot( 0, this, TQT_SLOT( uploadNewItem() ) ); +} + + +void GroupwareUploadJob::kill() +{ + cancelSave(); +} + +void GroupwareUploadJob::slotItemDeleted( const TQString &/*localId*/, const KURL &remoteURL ) +{ + kdDebug() << "GroupwareUploadJob::slotItemDeleted, removal successful: "<< remoteURL.url() << endl; + + const TQString &remote = remoteURL.path(); + const TQString &local = adaptor()->idMapper()->localId( remote ); + if ( !local.isEmpty() ) { + // TODO: Is the deleted status reset in the resource? + adaptor()->deleteItem( local ); + } + + KPIM::GroupwareUploadItem::List allit( mDeletedItems ); + allit += mItemsUploading; + allit += mItemsUploadError; + + KPIM::GroupwareUploadItem::List::Iterator it = allit.begin(); + for ( ; it != allit.end(); ++it ) { + if ( (*it)->url().path() == remoteURL.path() ) { +kdDebug()<<"Found it in the list!"<<endl; + KPIM::GroupwareUploadItem *item = (*it); + mDeletedItems.remove( item ); + mItemsUploading.remove( item ); + mItemsUploadError.remove( item ); + mItemsUploaded.append( item ); + } + } + + if ( mUploadProgress ) { + mUploadProgress->incCompletedItems(); + mUploadProgress->updateProgress(); + } +} + + + +void GroupwareUploadJob::slotItemUploaded( const TQString &/*localId*/, const KURL &remoteURL ) +{ + kdDebug() << "GroupwareUploadJob::slotItemUploaded, upload successful: "<< remoteURL.url() << endl; + + const TQString &remote = remoteURL.path(); + const TQString &local = adaptor()->idMapper()->localId( remote ); + if ( !local.isEmpty() ) { + // TODO: Is the deleted status reset in the resource? +// adaptor()->itemUploaded( local, remoteURL ); + } + + KPIM::GroupwareUploadItem::List allit( mChangedItems ); + allit += mAddedItems; + allit += mItemsUploading; + allit += mItemsUploadError; + + + KPIM::GroupwareUploadItem::List::Iterator it = allit.begin(); + for ( ; it != allit.end(); ++it ) { + if ( (*it)->url().path() == remoteURL.path() ) { +kdDebug()<<"Found it in the list!"<<endl; + KPIM::GroupwareUploadItem *item = (*it); + mChangedItems.remove( item ); + mAddedItems.remove( item ); + mItemsUploading.remove( item ); + mItemsUploadError.remove( item ); + mItemsUploaded.append( item ); + } + } + + if ( mUploadProgress ) { + mUploadProgress->incCompletedItems(); + mUploadProgress->updateProgress(); + } +} + + +void GroupwareUploadJob::slotItemUploadedNew( const TQString &localId, const KURL &remoteURL ) +{ + kdDebug() << "GroupwareUploadJob::slotItemUploadedNew, upload successful: "<< remoteURL.url() << endl; + + const TQString &remote = remoteURL.path(); + // TODO: For a new item this won't return anything, so we need to insert the + // local<=>remote id map when creating the upload job... And maybe + const TQString &local = adaptor()->idMapper()->localId( remote ); + if ( !localId.isEmpty() ) { + adaptor()->deleteItem( localId ); + } + if ( !local.isEmpty() ) { +// adaptor()->itemUploadedNew( local, remoteURL ); + } + + KPIM::GroupwareUploadItem::List allit( mChangedItems ); + allit += mAddedItems; + allit += mItemsUploading; + allit += mItemsUploadError; + + + KPIM::GroupwareUploadItem::List::Iterator it = allit.begin(); + for ( ; it != allit.end(); ++it ) { + if ( (*it)->url().path() == remoteURL.path() ) { +kdDebug()<<"Found it in the list!"<<endl; + KPIM::GroupwareUploadItem *item = (*it); + mChangedItems.remove( item ); + mAddedItems.remove( item ); + mItemsUploading.remove( item ); + mItemsUploadError.remove( item ); + mItemsUploaded.append( item ); + } + } + + if ( mUploadProgress ) { + mUploadProgress->incCompletedItems(); + mUploadProgress->updateProgress(); + } +} + +void GroupwareUploadJob::slotItemDeleteError( const KURL &remoteURL, const TQString &/*error*/ ) +{ + // TODO: Add to error list, remove from uploading and toUpload list + kdDebug() << "GroupwareUploadJob::slotItemDeleteError, removal not successful: "<< remoteURL.url() << endl; + KPIM::GroupwareUploadItem::List allit( mDeletedItems ); + allit += mItemsUploading; + allit += mItemsUploaded; + + KPIM::GroupwareUploadItem::List::Iterator it = allit.begin(); + for ( ; it != allit.end(); ++it ) { + if ( (*it)->url().path() == remoteURL.path() ) { +kdDebug()<<"Found it in the list!"<<endl; + KPIM::GroupwareUploadItem *item = (*it); + mDeletedItems.remove( item ); + mItemsUploaded.remove( item ); + mItemsUploading.remove( item ); + mItemsUploadError.append( item ); + } + } + + if ( mUploadProgress ) { + mUploadProgress->incCompletedItems(); + mUploadProgress->updateProgress(); + } +} + +void GroupwareUploadJob::slotItemUploadError( const KURL &remoteURL, const TQString &/*error*/ ) +{ + // TODO: Add to error list, remove from uploading and toUpload list + kdDebug() << "GroupwareUploadJob::slotItemUploadError, removal not successful: "<< remoteURL.url() << endl; + KPIM::GroupwareUploadItem::List allit( mChangedItems ); + allit += mItemsUploading; + allit += mItemsUploaded; + + KPIM::GroupwareUploadItem::List::Iterator it = allit.begin(); + for ( ; it != allit.end(); ++it ) { + if ( (*it)->url().path() == remoteURL.path() ) { +kdDebug()<<"Found it in the list!"<<endl; + KPIM::GroupwareUploadItem *item = (*it); + mChangedItems.remove( item ); + mItemsUploaded.remove( item ); + mItemsUploading.remove( item ); + mItemsUploadError.append( item ); + } + } + + if ( mUploadProgress ) { + mUploadProgress->incCompletedItems(); + mUploadProgress->updateProgress(); + } +} + +void GroupwareUploadJob::slotItemUploadNewError( const TQString &/*localID*/, const TQString &remoteURL ) +{ + kdDebug(5006) << "GroupwareUploadJob::slotItemUploadNewError, removal not successful: "<< remoteURL << endl; + KPIM::GroupwareUploadItem::List allit( mAddedItems ); + allit += mItemsUploading; + allit += mItemsUploaded; + const KURL &url( remoteURL ); + + KPIM::GroupwareUploadItem::List::Iterator it = allit.begin(); + for ( ; it != allit.end(); ++it ) { + if ( (*it)->url().path() == url.path() ) { +kdDebug()<<"Found it in the list!"<<endl; + KPIM::GroupwareUploadItem *item = (*it); + mAddedItems.remove( item ); + mItemsUploaded.remove( item ); + mItemsUploading.remove( item ); + mItemsUploadError.append( item ); + } + } + + if ( mUploadProgress ) { + mUploadProgress->incCompletedItems(); + mUploadProgress->updateProgress(); + } +} + + +void GroupwareUploadJob::cancelSave() +{ + if ( mUploadJob ) mUploadJob->kill(); + mUploadJob = 0; + if ( mUploadProgress ) mUploadProgress->setComplete(); + mUploadProgress = 0; +} + +void GroupwareUploadJob::uploadCompleted() +{ + if ( !mItemsUploadError.isEmpty() ) { + error( i18n("1 item could not be uploaded.", "%n items could not be uploaded.", mItemsUploadError.count() ) ); + } + KPIM::GroupwareUploadItem::List items( mAddedItems ); + items += mChangedItems; + items += mDeletedItems; + items += mItemsUploading; + items += mItemsUploaded; + items += mItemsUploadError; + + mAddedItems.clear(); + mChangedItems.clear(); + mDeletedItems.clear(); + mItemsUploading.clear(); + mItemsUploaded.clear(); + mItemsUploadError.clear(); + items.setAutoDelete( true ); + items.clear(); + + if ( mUploadProgress ) { + mUploadProgress->setComplete(); + mUploadProgress = 0; + } + success(); + +} +#include "groupwareuploadjob.moc" diff --git a/tderesources/lib/groupwareuploadjob.h b/tderesources/lib/groupwareuploadjob.h new file mode 100644 index 000000000..b3a0ff756 --- /dev/null +++ b/tderesources/lib/groupwareuploadjob.h @@ -0,0 +1,131 @@ +/* + This file is part of tdepim. + + Copyright (c) 2004 Cornelius Schumacher <[email protected]> + Copyright (c) 2004 Till Adam <[email protected]> + Copyright (c) 2005 Reinhold Kainhofer <[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 KPIM_GROUPWAREUPLOADJOB_H +#define KPIM_GROUPWAREUPLOADJOB_H + +#include "groupwareresourcejob.h" + +#include <kurl.h> +#include <tqstringlist.h> +#include <groupwaredataadaptor.h> + +namespace TDEIO { + class Job; + class TransferJob; + class DeleteJob; +} + +namespace KPIM { + +class GroupwareDataAdaptor; +class ProgressItem; + +/** + This class provides a resource for accessing a Groupware kioslave-based + calendar. +*/ +class GroupwareUploadJob : public GroupwareJob +{ + Q_OBJECT + + public: + GroupwareUploadJob( GroupwareDataAdaptor *adaptor ); + + KPIM::GroupwareUploadItem::List addedItems() const + { + return mAddedItems; + } + void setAddedItems( const KPIM::GroupwareUploadItem::List &items ) + { + mAddedItems = items; + } + KPIM::GroupwareUploadItem::List changedItems() const + { + return mChangedItems; + } + void setChangedItems( const KPIM::GroupwareUploadItem::List &items ) + { + mChangedItems = items; + } + KPIM::GroupwareUploadItem::List deletedItems() const + { + return mDeletedItems; + } + void setDeletedItems( const KPIM::GroupwareUploadItem::List &items ) + { + mDeletedItems = items; + } + + void kill(); + + protected slots: + void deleteItem(); + void uploadItem(); + void uploadNewItem(); + + protected slots: + void run(); + + void cancelSave(); + + void slotDeletionJobResult( TDEIO::Job *job ); + void slotDeletionJobData( TDEIO::Job *, const TQByteArray & ); + void slotUploadJobResult( TDEIO::Job *job ); + void slotUploadJobData( TDEIO::Job *, const TQByteArray & ); + void slotUploadNewJobResult( TDEIO::Job *job ); + void slotUploadNewJobData( TDEIO::Job *, const TQByteArray & ); + + void slotItemDeleted( const TQString &localID, const KURL &remoteURL ); + void slotItemUploaded( const TQString &localID, const KURL &remoteURL ); + void slotItemUploadedNew( const TQString &localID, const KURL &remoteURL ); + + void slotItemDeleteError( const KURL &remoteURL, const TQString &error ); + void slotItemUploadError( const KURL &remoteURL, const TQString &error ); + void slotItemUploadNewError( const TQString &localID, const TQString &error ); + + void uploadCompleted(); + + private: + KPIM::GroupwareUploadItem::List mAddedItems; + KPIM::GroupwareUploadItem::List mChangedItems; + KPIM::GroupwareUploadItem::List mDeletedItems; + + KPIM::GroupwareUploadItem::List mItemsUploading; + KPIM::GroupwareUploadItem::List mItemsUploaded; + KPIM::GroupwareUploadItem::List mItemsUploadError; + + TQString mDeletionJobData; + TQString mUploadJobData; + TQString mUploadNewJobData; + + TDEIO::TransferJob *mUploadJob; + TDEIO::Job *mDeletionJob; + KPIM::ProgressItem *mUploadProgress; + +}; + +} + +#endif + + diff --git a/tderesources/lib/kabc_resourcegroupwarebase.cpp b/tderesources/lib/kabc_resourcegroupwarebase.cpp new file mode 100644 index 000000000..87ca28cec --- /dev/null +++ b/tderesources/lib/kabc_resourcegroupwarebase.cpp @@ -0,0 +1,262 @@ +/* + This file is part of tdepim. + + Copyright (c) 2004 Cornelius Schumacher <[email protected]> + Copyright (c) 2004 Till Adam <[email protected]> + Copyright (C) 2005 Reinhold Kainhofer <[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 "kabc_resourcegroupwarebase.h" +#include "tderesources_groupwareprefs.h" + +#include "folderlister.h" +#include "addressbookadaptor.h" +#include "groupwaredownloadjob.h" +#include "groupwareuploadjob.h" + +#include <kabc/addressee.h> +#include <kabc/vcardconverter.h> +#include <klocale.h> + +using namespace KABC; + +ResourceGroupwareBase::ResourceGroupwareBase( const TDEConfig *config ) + : ResourceCached( config ), + mPrefs(0), mFolderLister(0), mAdaptor(0), mDownloadJob(0), mUploadJob(0) +{ + if ( config ) readConfig( config ); +} + +ResourceGroupwareBase::~ResourceGroupwareBase() +{ + delete mPrefs; + mPrefs = 0; +} + +KPIM::GroupwareDownloadJob *ResourceGroupwareBase::createDownloadJob( + AddressBookAdaptor *adaptor ) +{ + return new KPIM::GroupwareDownloadJob( adaptor ); +} + +KPIM::GroupwareUploadJob *ResourceGroupwareBase::createUploadJob( + AddressBookAdaptor *adaptor ) +{ + return new KPIM::GroupwareUploadJob( adaptor ); +} + +void ResourceGroupwareBase::setPrefs( KPIM::GroupwarePrefsBase *newprefs ) +{ + if ( !newprefs ) return; + if ( mPrefs ) delete mPrefs; + mPrefs = newprefs; + mPrefs->addGroupPrefix( identifier() ); + + mPrefs->readConfig(); + if ( mFolderLister ) mFolderLister->readConfig( mPrefs ); +} + +void ResourceGroupwareBase::setFolderLister( KPIM::FolderLister *folderLister ) +{ + if ( !folderLister ) return; + if ( mFolderLister ) delete mFolderLister; + mFolderLister = folderLister; + if ( mPrefs ) mFolderLister->readConfig( mPrefs ); + if ( mAdaptor ) { + mAdaptor->setFolderLister( mFolderLister ); + mFolderLister->setAdaptor( mAdaptor ); + } +} + +void ResourceGroupwareBase::setAdaptor( AddressBookAdaptor *adaptor ) +{ + if ( !adaptor ) return; + if ( mAdaptor ) delete mAdaptor; + mAdaptor = adaptor; + mAdaptor->setFolderLister( mFolderLister ); + if ( mFolderLister ) mFolderLister->setAdaptor( mAdaptor ); + mAdaptor->setDownloadProgressMessage( i18n("Downloading addressbook") ); + mAdaptor->setUploadProgressMessage( i18n("Uploading addressbook") ); + if ( prefs() ) { + mAdaptor->setBaseURL( prefs()->url() ); + mAdaptor->setUser( prefs()->user() ); + mAdaptor->setPassword( prefs()->password() ); + } + mAdaptor->setIdMapper( &idMapper() ); + mAdaptor->setResource( this ); +} + +void ResourceGroupwareBase::init() +{ + mDownloadJob = 0; +} + +KPIM::GroupwarePrefsBase *ResourceGroupwareBase::createPrefs() +{ + return new KPIM::GroupwarePrefsBase(); +} + + + +void ResourceGroupwareBase::readConfig( const TDEConfig */*config*/ ) +{ + kdDebug(5700) << "KABC::ResourceGroupwareBase::readConfig()" << endl; +// ResourceCached::readConfig( config ); + if ( mPrefs ) { + mPrefs->readConfig(); + if ( mFolderLister ) + mFolderLister->readConfig( mPrefs ); + } +} + +void ResourceGroupwareBase::writeConfig( TDEConfig *config ) +{ + Resource::writeConfig( config ); + + if ( mPrefs ) { + if ( mFolderLister ) + mFolderLister->writeConfig( mPrefs ); + mPrefs->writeConfig(); + } +} + +Ticket *ResourceGroupwareBase::requestSaveTicket() +{ + if ( !addressBook() ) { + kdDebug(5700) << "no addressbook" << endl; + return 0; + } + + return createTicket( this ); +} + +void ResourceGroupwareBase::releaseSaveTicket( Ticket *ticket ) +{ + delete ticket; +} + +bool ResourceGroupwareBase::doOpen() +{ + return true; +} + +void ResourceGroupwareBase::doClose() +{ + kdDebug(5800) << "ResourceGroupwareBase::doClose()" << endl; + + if ( mDownloadJob ) mDownloadJob->kill(); +} + +bool ResourceGroupwareBase::load() +{ + return asyncLoad(); +} + +bool ResourceGroupwareBase::asyncLoad() +{ + if ( mDownloadJob ) { + kdWarning() << "Download still in progress" << endl; + return false; + } + + mAddrMap.clear(); + loadCache(); + + mDownloadJob = createDownloadJob( mAdaptor ); + connect( mDownloadJob, TQT_SIGNAL( result( KPIM::GroupwareJob * ) ), + TQT_SLOT( slotDownloadJobResult( KPIM::GroupwareJob * ) ) ); + + return true; +} + +void ResourceGroupwareBase::slotDownloadJobResult( KPIM::GroupwareJob *job ) +{ + kdDebug(5800) << "ResourceGroupwareBase::slotJobResult(): " << endl; + + if ( job->error() ) { + kdError() << "job failed: " << job->errorString() << endl; + } else { + emit loadingFinished( this ); + if ( addressBook() ) + addressBook()->emitAddressBookChanged(); + } + + mDownloadJob = 0; +} + +bool ResourceGroupwareBase::save( Ticket *ticket ) +{ + return asyncSave( ticket ); +} + +bool ResourceGroupwareBase::asyncSave( Ticket* ) +{ + if ( mUploadJob ) { + // FIXME: If the user cancels, need to reset the mUploadJob variable to 0. + kdWarning() << "Upload still in progress." << endl; + return false; + } + + mUploadJob = createUploadJob( mAdaptor ); + connect( mUploadJob, TQT_SIGNAL( result( KPIM::GroupwareJob * ) ), + TQT_SLOT( slotUploadJobResult( KPIM::GroupwareJob * ) ) ); + + KABC::Addressee::List addr; + KABC::Addressee::List::Iterator it; + KPIM::GroupwareUploadItem::List addedItems, changedItems, deletedItems; + + addr = addedAddressees(); + for( it = addr.begin(); it != addr.end(); ++it ) { + addedItems.append( adaptor()->newUploadItem( *it, + KPIM::GroupwareUploadItem::Added ) ); + } + // TODO: Check if the item has changed on the server... + // In particular, check if the version we based our change on is still current + // on the server + addr = changedAddressees(); + for( it = addr.begin(); it != addr.end(); ++it ) { + changedItems.append( adaptor()->newUploadItem( *it, + KPIM::GroupwareUploadItem::Changed ) ); + } + addr = deletedAddressees(); + for( it = addr.begin(); it != addr.end(); ++it ) { + deletedItems.append( adaptor()->newUploadItem( *it, + KPIM::GroupwareUploadItem::Deleted ) ); + } + + mUploadJob->setAddedItems( addedItems ); + mUploadJob->setChangedItems( changedItems ); + mUploadJob->setDeletedItems( deletedItems ); + + return true; +} + +void ResourceGroupwareBase::slotUploadJobResult( KPIM::GroupwareJob *job ) +{ + kdDebug(5800) << "ResourceGroupwareBase::slotJobResult(): " << endl; + + if ( job->error() ) { + kdError() << "job failed: " << job->errorString() << endl; + } else { + // FIXME + } + + mUploadJob = 0; +} + + +#include "kabc_resourcegroupwarebase.moc" diff --git a/tderesources/lib/kabc_resourcegroupwarebase.h b/tderesources/lib/kabc_resourcegroupwarebase.h new file mode 100644 index 000000000..28ce5199e --- /dev/null +++ b/tderesources/lib/kabc_resourcegroupwarebase.h @@ -0,0 +1,99 @@ +/* + This file is part of tdepim. + + Copyright (c) 2004 Cornelius Schumacher <[email protected]> + Copyright (c) 2004 Till Adam <[email protected]> + Copyright (C) 2005 Reinhold Kainhofer <[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 KABC_RESOURCEGROUPWARE_H +#define KABC_RESOURCEGROUPWARE_H + +#include <kurl.h> +#include <kabcresourcecached.h> +#include <tdepimmacros.h> + +class TDEConfig; + +namespace KPIM { +class GroupwareJob; +class GroupwareDownloadJob; +class GroupwareUploadJob; +class FolderLister; +class GroupwarePrefsBase; +} + +namespace KABC { + +class AddressBookAdaptor; + +class KDE_EXPORT ResourceGroupwareBase : public ResourceCached +{ + Q_OBJECT + + + public: + ResourceGroupwareBase( const TDEConfig * ); + ~ResourceGroupwareBase(); + + void readConfig( const TDEConfig * ); + void writeConfig( TDEConfig * ); + + KPIM::GroupwarePrefsBase *prefs() const { return mPrefs; } + void setPrefs( KPIM::GroupwarePrefsBase *prefs ); + + KPIM::FolderLister *folderLister() const { return mFolderLister; } + void setFolderLister( KPIM::FolderLister *folderLister ); + + AddressBookAdaptor *adaptor() const { return mAdaptor; } + void setAdaptor( AddressBookAdaptor *adaptor ); + + bool doOpen(); + void doClose(); + + Ticket *requestSaveTicket(); + void releaseSaveTicket( Ticket* ); + + bool load(); + bool asyncLoad(); + bool save( Ticket * ); + bool asyncSave( Ticket * ); + + protected: + void init(); + + KPIM::GroupwarePrefsBase *createPrefs(); + virtual KPIM::GroupwareDownloadJob *createDownloadJob( + AddressBookAdaptor *adaptor ); + virtual KPIM::GroupwareUploadJob *createUploadJob( + AddressBookAdaptor *adaptor ); + + private slots: + void slotDownloadJobResult( KPIM::GroupwareJob * ); + void slotUploadJobResult( KPIM::GroupwareJob * ); + + private: + KPIM::GroupwarePrefsBase *mPrefs; + KPIM::FolderLister *mFolderLister; + AddressBookAdaptor *mAdaptor; + + KPIM::GroupwareDownloadJob *mDownloadJob; + KPIM::GroupwareUploadJob *mUploadJob; +}; + +} + +#endif diff --git a/tderesources/lib/kabc_resourcegroupwarebaseconfig.cpp b/tderesources/lib/kabc_resourcegroupwarebaseconfig.cpp new file mode 100644 index 000000000..4e4f05275 --- /dev/null +++ b/tderesources/lib/kabc_resourcegroupwarebaseconfig.cpp @@ -0,0 +1,117 @@ +/* + This file is part of tdepim. + + Copyright (c) 2004 Cornelius Schumacher <[email protected]> + Copyright (c) 2004 Till Adam <[email protected]> + Copyright (c) 2005 Reinhold Kainhofer <[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 "kabc_resourcegroupwarebaseconfig.h" + +#include "kabc_resourcegroupwarebase.h" +#include "tderesources_groupwareprefs.h" +#include "folderconfig.h" + +#include <kdebug.h> +#include <kdialog.h> +#include <klocale.h> +#include <klineedit.h> +#include <kurlrequester.h> + +#include <tqlabel.h> +#include <tqlayout.h> + +using namespace KABC; + +ResourceGroupwareBaseConfig::ResourceGroupwareBaseConfig( TQWidget* parent, const char* name ) + : KRES::ConfigWidget( parent, name ) +{ + TQGridLayout *mainLayout = new TQGridLayout( this, 7, 2, 0, KDialog::spacingHint() ); + + TQLabel *label = new TQLabel( i18n( "URL:" ), this ); + mURL = new KURLRequester( this ); + + mainLayout->addWidget( label, 0, 0 ); + mainLayout->addWidget( mURL, 0, 1 ); + + label = new TQLabel( i18n( "User:" ), this ); + mUser = new KLineEdit( this ); + + mainLayout->addWidget( label, 1, 0 ); + mainLayout->addWidget( mUser, 1, 1 ); + + label = new TQLabel( i18n( "Password:" ), this ); + mPassword = new KLineEdit( this ); + mPassword->setEchoMode( TQLineEdit::Password ); + + mainLayout->addWidget( label, 2, 0 ); + mainLayout->addWidget( mPassword, 2, 1 ); + + TQFrame *hline = new TQFrame( this ); + hline->setFrameStyle( TQFrame::HLine | TQFrame::Sunken ); + + mainLayout->addMultiCellWidget( hline, 3, 3, 0, 1 ); + + mFolderConfig = new KPIM::FolderConfig( this ); + connect( mFolderConfig, TQT_SIGNAL( updateFoldersClicked() ), + TQT_SLOT( updateFolders() ) ); + mainLayout->addMultiCellWidget( mFolderConfig, 4, 4, 0, 1 ); +} + +void ResourceGroupwareBaseConfig::loadSettings( KRES::Resource *res ) +{ + mResource = dynamic_cast<ResourceGroupwareBase*>( res ); + + if ( !mResource ) { + kdDebug(5700) << "ResourceGroupwareBaseConfig::loadSettings(): cast failed" << endl; + return; + } + + mURL->setURL( mResource->prefs()->url() ); + mUser->setText( mResource->prefs()->user() ); + mPassword->setText( mResource->prefs()->password() ); + + mFolderConfig->setFolderLister( mResource->folderLister() ); + mFolderConfig->updateFolderList(); +} + +void ResourceGroupwareBaseConfig::saveSettings( KRES::Resource *res ) +{ + ResourceGroupwareBase *resource = dynamic_cast<ResourceGroupwareBase*>( res ); + + if ( !resource ) { + kdDebug(5700) << "ResourceGroupwareBaseConfig::saveSettings(): cast failed" << endl; + return; + } + + resource->prefs()->setUrl( mURL->url() ); + resource->prefs()->setUser( mUser->text() ); + resource->prefs()->setPassword( mPassword->text() ); + + mFolderConfig->saveSettings(); +} + +void ResourceGroupwareBaseConfig::updateFolders() +{ + KURL url = mURL->url(); + url.setUser( mUser->text() ); + url.setPass( mPassword->text() ); + + mFolderConfig->retrieveFolderList( url ); +} + +#include "kabc_resourcegroupwarebaseconfig.moc" diff --git a/tderesources/lib/kabc_resourcegroupwarebaseconfig.h b/tderesources/lib/kabc_resourcegroupwarebaseconfig.h new file mode 100644 index 000000000..f505d9ceb --- /dev/null +++ b/tderesources/lib/kabc_resourcegroupwarebaseconfig.h @@ -0,0 +1,65 @@ +/* + This file is part of tdepim. + + Copyright (c) 2004 Cornelius Schumacher <[email protected]> + Copyright (c) 2004 Till Adam <[email protected]> + Copyright (c) 2005 Reinhold Kainhofer <[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 KABC_RESOURCEGROUPWAREBASECONFIG_H +#define KABC_RESOURCEGROUPWAREBASECONFIG_H + +#include <tderesources/configwidget.h> +#include <tdepimmacros.h> + +class KLineEdit; +class KURLRequester; + +namespace KPIM { +class FolderConfig; +} + +namespace KABC { + +class ResourceGroupwareBase; + +class KDE_EXPORT ResourceGroupwareBaseConfig : public KRES::ConfigWidget +{ + Q_OBJECT + + + public: + ResourceGroupwareBaseConfig( TQWidget* parent = 0, const char* name = 0 ); + + public slots: + void loadSettings( KRES::Resource* ); + void saveSettings( KRES::Resource* ); + + protected slots: + void updateFolders(); + + private: + KURLRequester *mURL; + KLineEdit *mUser; + KLineEdit *mPassword; + KPIM::FolderConfig *mFolderConfig; + + ResourceGroupwareBase *mResource; +}; + +} + +#endif diff --git a/tderesources/lib/kcal_cachesettingsdlg.cpp b/tderesources/lib/kcal_cachesettingsdlg.cpp new file mode 100644 index 000000000..3c2dbed17 --- /dev/null +++ b/tderesources/lib/kcal_cachesettingsdlg.cpp @@ -0,0 +1,89 @@ +/* + This file is part of tdepim. + + Copyright (c) 2004 Cornelius Schumacher <[email protected]> + Copyright (c) 2004 Till Adam <[email protected]> + Copyright (c) 2005 Reinhold Kainhofer <[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 "kcal_cachesettingsdlg.h" + +#include "kcal_resourcegroupwarebase.h" +#include "tderesources_groupwareprefs.h" + +#include <libkcal/resourcecachedconfig.h> + +#include <klocale.h> +#include <kdebug.h> +#include <klineedit.h> +#include <kdialog.h> + +#include <tqlabel.h> +#include <tqlayout.h> + + +using namespace KCal; + +CacheSettingsDialog::CacheSettingsDialog( TQWidget* parent, const char* name ) + : KDialogBase( parent, name, true, i18n("Resource Cache Settings"), KDialogBase::Close ) +{ + TQWidget *mainWidget = new TQWidget( this ); + setMainWidget( mainWidget ); + + TQGridLayout *mainLayout = new TQGridLayout( mainWidget, 2, 2 ); + mainLayout->setSpacing( KDialog::spacingHint() ); + + mReloadConfig = new KCal::ResourceCachedReloadConfig( mainWidget ); + mainLayout->addMultiCellWidget( mReloadConfig, 1, 3, 2, 2 ); + + mSaveConfig = new KCal::ResourceCachedSaveConfig( mainWidget ); + mainLayout->addMultiCellWidget( mSaveConfig, 4, 4, 2, 2 ); +} + +void CacheSettingsDialog::loadSettings( KRES::Resource *resource ) +{ + kdDebug(7000) << "KCal::CacheSettingsDialog::loadSettings()" << endl; + + ResourceGroupwareBase *res = static_cast<ResourceGroupwareBase *>( resource ); + if ( res ) { + if ( !res->prefs() ) { + kdError() << "No PREF" << endl; + return; + } + + mReloadConfig->loadSettings( res ); + mSaveConfig->loadSettings( res ); + + } else { + kdError(5700) << "CacheSettingsDialog::loadSettings(): " + "no ResourceGroupwareBase, cast failed" << endl; + } +} + +void CacheSettingsDialog::saveSettings( KRES::Resource *resource ) +{ + ResourceGroupwareBase *res = static_cast<ResourceGroupwareBase*>( resource ); + if ( res ) { + mReloadConfig->saveSettings( res ); + mSaveConfig->saveSettings( res ); + } else { + kdError(5700) << "CacheSettingsDialog::saveSettings(): " + "no ResourceGroupwareBase, cast failed" << endl; + } +} + +#include "kcal_cachesettingsdlg.moc" diff --git a/tderesources/lib/kcal_cachesettingsdlg.h b/tderesources/lib/kcal_cachesettingsdlg.h new file mode 100644 index 000000000..1a6b369ab --- /dev/null +++ b/tderesources/lib/kcal_cachesettingsdlg.h @@ -0,0 +1,60 @@ +/* + This file is part of tdepim. + + Copyright (c) 2004 Cornelius Schumacher <[email protected]> + Copyright (c) 2004 Till Adam <[email protected]> + Copyright (c) 2005 Reinhold Kainhofer <[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 KCAL_CACHESETTINGSDLG_H +#define KCAL_CACHESETTINGSDLG_H + +#include <kdialogbase.h> +#include <tdepimmacros.h> + + +namespace KRES { +class Resource; +} + +namespace KCal { + +class ResourceCachedReloadConfig; +class ResourceCachedSaveConfig; + +/** + Configuration widget for groupware kioslave resource. + @see KCalOpenGroupware +*/ +class KDE_EXPORT CacheSettingsDialog : public KDialogBase +{ + Q_OBJECT + + public: + CacheSettingsDialog( TQWidget *parent = 0, const char *name = 0 ); + + public slots: + virtual void loadSettings( KRES::Resource *resource ); + virtual void saveSettings( KRES::Resource *resource ); + + private: + KCal::ResourceCachedReloadConfig *mReloadConfig; + KCal::ResourceCachedSaveConfig *mSaveConfig; +}; + +} + +#endif diff --git a/tderesources/lib/kcal_resourcegroupwarebase.cpp b/tderesources/lib/kcal_resourcegroupwarebase.cpp new file mode 100644 index 000000000..bd459331a --- /dev/null +++ b/tderesources/lib/kcal_resourcegroupwarebase.cpp @@ -0,0 +1,410 @@ +/* + This file is part of tdepim. + + Copyright (c) 2004 Cornelius Schumacher <[email protected]> + Copyright (c) 2004 Till Adam <[email protected]> + Copyright (c) 2005 Reinhold Kainhofer <[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 "kcal_resourcegroupwarebase.h" +#include "tderesources_groupwareprefs.h" + +#include "libkcal/confirmsavedialog.h" +#include "folderlister.h" +#include "calendaradaptor.h" +#include "groupwaredownloadjob.h" +#include "groupwareuploadjob.h" + +#include <libkcal/icalformat.h> +#include <kio/job.h> +#include <klocale.h> + +#include <tqapplication.h> + +using namespace KCal; + +ResourceGroupwareBase::ResourceGroupwareBase() + : ResourceCached( 0 ), mPrefs(0), mFolderLister(0), + mLock( true ), mAdaptor(0), mDownloadJob(0), mUploadJob(0) +{ +} + +ResourceGroupwareBase::ResourceGroupwareBase( const TDEConfig *config ) + : ResourceCached( config ), mPrefs(0), mFolderLister(0), + mLock( true ), mAdaptor(0), mDownloadJob(0), mUploadJob(0) +{ + if ( config ) readConfig( config ); +} + +ResourceGroupwareBase::~ResourceGroupwareBase() +{ + disableChangeNotification(); + + delete mPrefs; + mPrefs = 0; +} + +KPIM::GroupwarePrefsBase *ResourceGroupwareBase::createPrefs() +{ + return new KPIM::GroupwarePrefsBase(); +} + + +bool ResourceGroupwareBase::addEvent( Event *event ) +{ + if ( adaptor() && ( adaptor()->supports( KPIM::FolderLister::Event ) || + adaptor()->supports( KPIM::FolderLister::All ) ) ) { + return ResourceCached::addEvent( event, TQString() ); + } else return false; +} + +bool ResourceGroupwareBase::addTodo( Todo *todo ) +{ + if ( adaptor() && ( adaptor()->supports( KPIM::FolderLister::Todo ) || + adaptor()->supports( KPIM::FolderLister::All ) ) ) { + return ResourceCached::addTodo( todo, TQString() ); + } else return false; +} + +bool ResourceGroupwareBase::addJournal( Journal *journal ) +{ + if ( adaptor() && ( adaptor()->supports( KPIM::FolderLister::Journal ) || + adaptor()->supports( KPIM::FolderLister::All ) ) ) { + return ResourceCached::addJournal( journal, TQString() ); + } else return false; +} + + +KPIM::GroupwareDownloadJob *ResourceGroupwareBase::createDownloadJob( + CalendarAdaptor *adaptor ) +{ + return new KPIM::GroupwareDownloadJob( adaptor ); +} + +KPIM::GroupwareUploadJob *ResourceGroupwareBase::createUploadJob( + CalendarAdaptor *adaptor ) +{ + return new KPIM::GroupwareUploadJob( adaptor ); +} + +void ResourceGroupwareBase::setPrefs( KPIM::GroupwarePrefsBase *newprefs ) +{ + if ( !newprefs ) return; + if ( mPrefs ) delete mPrefs; + mPrefs = newprefs; + mPrefs->addGroupPrefix( identifier() ); + + mPrefs->readConfig(); + if ( mFolderLister ) mFolderLister->readConfig( mPrefs ); +} + +void ResourceGroupwareBase::setFolderLister( KPIM::FolderLister *folderLister ) +{ + if ( !folderLister ) return; + if ( mFolderLister ) delete mFolderLister; + mFolderLister = folderLister; + if ( mPrefs ) mFolderLister->readConfig( mPrefs ); + if ( adaptor() ) { + adaptor()->setFolderLister( mFolderLister ); + mFolderLister->setAdaptor( adaptor() ); + } +} + +void ResourceGroupwareBase::setAdaptor( CalendarAdaptor *adaptor ) +{ + if ( !adaptor ) return; + if ( mAdaptor ) delete mAdaptor; + mAdaptor = adaptor; + mAdaptor->setFolderLister( mFolderLister ); + if ( mFolderLister ) mFolderLister->setAdaptor( mAdaptor ); + // TODO: Set the prgreess status in the up/download jobs, and set + // the resource name as the label. This should be done in the + // up/download jobs, but these don't have access to the resource's + // name, do they? +/* mAdaptor->setDownloadProgressMessage( i18n("Downloading calendar") ); + mAdaptor->setUploadProgressMessage( i18n("Uploading calendar") );*/ + if ( prefs() ) { + mAdaptor->setBaseURL( prefs()->url() ); + mAdaptor->setUser( prefs()->user() ); + mAdaptor->setPassword( prefs()->password() ); + } + mAdaptor->setIdMapper( &idMapper() ); + mAdaptor->setResource( this ); +} + +void ResourceGroupwareBase::init() +{ + mDownloadJob = 0; + mIsShowingError = false; + + enableChangeNotification(); +} + +KPIM::GroupwarePrefsBase *ResourceGroupwareBase::prefs() +{ + return mPrefs; +} + +void ResourceGroupwareBase::readConfig( const TDEConfig *config ) +{ + kdDebug(5800) << "KCal::ResourceGroupwareBase::readConfig()" << endl; + ResourceCached::readConfig( config ); + if ( mPrefs ) { + mPrefs->readConfig(); + if ( mFolderLister ) + mFolderLister->readConfig( mPrefs ); + } +} + +void ResourceGroupwareBase::writeConfig( TDEConfig *config ) +{ + kdDebug(5800) << "KCal::ResourceGroupwareBase::writeConfig()" << endl; + + ResourceCalendar::writeConfig( config ); + ResourceCached::writeConfig( config ); + + if ( mPrefs ) { + if ( mFolderLister ) + mFolderLister->writeConfig( mPrefs ); + mPrefs->writeConfig(); + } +} + +bool ResourceGroupwareBase::doOpen() +{ + if ( !adaptor() ) + return false; + if ( adaptor()->flags() & KPIM::GroupwareDataAdaptor::GWResNeedsLogon ) { + TDEIO::Job *loginJob = adaptor()->createLoginJob( prefs()->url(), prefs()->user(), prefs()->password() ); + if ( !loginJob ) { + return false; + } else { + mLoginFinished = false; + connect( loginJob, TQT_SIGNAL( result( TDEIO::Job * ) ), + TQT_SLOT( slotLoginJobResult( TDEIO::Job* ) ) ); + enter_loop(); + return mLoginFinished; + } + } + return true; +} + +// BEGIN:COPIED +// TODO: Get rid of this hack, which is copied from TDEIO::NetAccess, which is +// LGPL'ed and +// Copyright (C) 1997 Torben Weis ([email protected]) +// Copyright (C) 1998 Matthias Ettrich ([email protected]) +// Copyright (C) 1999 David Faure ([email protected]) +// If a troll sees this, he kills me +void tqt_enter_modal( TQWidget *widget ); +void tqt_leave_modal( TQWidget *widget ); + +void ResourceGroupwareBase::enter_loop() +{ + TQWidget dummy(0,0,WType_Dialog | WShowModal); + dummy.setFocusPolicy( TQ_NoFocus ); + tqt_enter_modal(&dummy); + tqApp->enter_loop(); + tqt_leave_modal(&dummy); +} +// END:COPIED + +void ResourceGroupwareBase::slotLoginJobResult( TDEIO::Job *job ) +{ + if ( !adaptor() ) return; + mLoginFinished = adaptor()->interpretLoginJobResult( job ); + tqApp->exit_loop(); +} + +void ResourceGroupwareBase::doClose() +{ + ResourceCached::doClose(); + if ( mDownloadJob ) mDownloadJob->kill(); + + if ( adaptor() && + adaptor()->flags() & KPIM::GroupwareDataAdaptor::GWResNeedsLogoff ) { + TDEIO::Job *logoffJob = adaptor()->createLogoffJob( prefs()->url(), prefs()->user(), prefs()->password() ); + connect( logoffJob, TQT_SIGNAL( result( TDEIO::Job * ) ), + TQT_SLOT( slotLogoffJobResult( TDEIO::Job* ) ) ); + // TODO: Do we really need to block while waiting for the job to return? + enter_loop(); + } +} + +void ResourceGroupwareBase::slotLogoffJobResult( TDEIO::Job *job ) +{ + if ( !adaptor() ) return; + adaptor()->interpretLogoffJobResult( job ); + // TODO: Do we really need to block while waiting for the job to return? + tqApp->exit_loop(); +} + +bool ResourceGroupwareBase::doLoad() +{ + kdDebug(5800) << "ResourceGroupwareBase::load()" << endl; + + if ( mIsShowingError ) { + kdDebug(5800) << "Still showing error" << endl; + return true; + } + + if ( mDownloadJob ) { + kdWarning() << "Download still in progress" << endl; + return false; + } + + mCalendar.close(); + clearChanges(); + disableChangeNotification(); + loadCache(); + enableChangeNotification(); + emit resourceChanged( this ); + + mDownloadJob = createDownloadJob( adaptor() ); + connect( mDownloadJob, TQT_SIGNAL( result( KPIM::GroupwareJob * ) ), + TQT_SLOT( slotDownloadJobResult( KPIM::GroupwareJob * ) ) ); + + return true; +} + +void ResourceGroupwareBase::slotDownloadJobResult( KPIM::GroupwareJob *job ) +{ + kdDebug(5800) << "ResourceGroupwareBase::slotJobResult(): " << endl; + + if ( job->error() ) { + mIsShowingError = true; + loadError( job->errorString() ); + mIsShowingError = false; + } else { + kdDebug(5800) << "Successfully downloaded data" << endl; + + clearChanges(); + saveCache(); + enableChangeNotification(); + + emit resourceChanged( this ); + emit resourceLoaded( this ); + } + + mDownloadJob = 0; +} + +bool ResourceGroupwareBase::doSave() +{ + kdDebug(5800) << "KCal::ResourceGroupwareBase::doSave()" << endl; + + saveCache(); + + if ( !hasChanges() ) { + kdDebug(5800) << "No changes" << endl; + return true; + } + // TODO: Implement confirming of single changes i.e. it should be possible + // to upload only certain changes and discard the rest. This is + // particularly important for resources like the blogging resource, + // where uploading would mean a republication of the blog, not only + // a modifications. + if ( !confirmSave() ) return false; + + mUploadJob = createUploadJob( adaptor() ); + connect( mUploadJob, TQT_SIGNAL( result( KPIM::GroupwareJob * ) ), + TQT_SLOT( slotUploadJobResult( KPIM::GroupwareJob * ) ) ); + + Incidence::List inc; + Incidence::List::Iterator it; + KPIM::GroupwareUploadItem::List addedItems, changedItems, deletedItems; + + inc = addedIncidences(); + for( it = inc.begin(); it != inc.end(); ++it ) { + addedItems.append( adaptor()->newUploadItem( *it, + KPIM::GroupwareUploadItem::Added ) ); + } + // TODO: Check if the item has changed on the server... + // In particular, check if the version we based our change on is still current + // on the server + inc = changedIncidences(); + for( it = inc.begin(); it != inc.end(); ++it ) { + changedItems.append( adaptor()->newUploadItem( *it, + KPIM::GroupwareUploadItem::Changed ) ); + } + inc = deletedIncidences(); + for( it = inc.begin(); it != inc.end(); ++it ) { + deletedItems.append( adaptor()->newUploadItem( *it, + KPIM::GroupwareUploadItem::Deleted ) ); + } + + mUploadJob->setAddedItems( addedItems ); + mUploadJob->setChangedItems( changedItems ); + mUploadJob->setDeletedItems( deletedItems ); + + // FIXME: Calling clearChanges() here is not the ideal way since the + // upload might fail, but there is no other place to call it... + clearChanges(); + return true; +} + +void ResourceGroupwareBase::slotUploadJobResult( KPIM::GroupwareJob *job ) +{ + kdDebug(5800) << "ResourceGroupwareBase::slotUploadJobResult(): " << endl; + + if ( job->error() ) { + mIsShowingError = true; + loadError( job->errorString() ); + mIsShowingError = false; + } else { + kdDebug(5800) << "Successfully uploaded data" << endl; + /* + * After the put the server might have expanded recurring events and will + * also change the uids of the uploaded events. Remove them from the cache + * and get the fresh delta and download. + */ + + if ( !mDownloadJob ) { + mDownloadJob = createDownloadJob( adaptor() ); + connect( mDownloadJob, TQT_SIGNAL( result( KPIM::GroupwareJob * ) ), + TQT_SLOT( slotDownloadJobResult( KPIM::GroupwareJob * ) ) ); + } else { + kdWarning() << k_funcinfo << "Download still in progress. " + "Can't happen. (TM)" << endl; + } + } + + mDownloadJob = 0; +} + +// FIXME: Put this into ResourceCached +bool ResourceGroupwareBase::confirmSave() +{ + if ( !hasChanges() ) return true; + + ConfirmSaveDialog dlg( resourceName(), 0 ); + + dlg.addIncidences( addedIncidences(), i18n("Added") ); + dlg.addIncidences( changedIncidences(), i18n("Changed") ); + dlg.addIncidences( deletedIncidences(), i18n("Deleted") ); + + int result = dlg.exec(); + return result == TQDialog::Accepted; +} + +KABC::Lock *ResourceGroupwareBase::lock() +{ + return &mLock; +} + +#include "kcal_resourcegroupwarebase.moc" diff --git a/tderesources/lib/kcal_resourcegroupwarebase.h b/tderesources/lib/kcal_resourcegroupwarebase.h new file mode 100644 index 000000000..f6b46dbf7 --- /dev/null +++ b/tderesources/lib/kcal_resourcegroupwarebase.h @@ -0,0 +1,119 @@ + /* + This file is part of tdepim. + + Copyright (c) 2004 Cornelius Schumacher <[email protected]> + Copyright (c) 2004 Till Adam <[email protected]> + Copyright (c) 2005 Reinhold Kainhofer <[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 KCAL_RESOURCEGROUPWAREBASE_H +#define KCAL_RESOURCEGROUPWAREBASE_H + +#include <kurl.h> +#include <libkcal/resourcecached.h> +#include <tdepimmacros.h> +#include <kabc/locknull.h> + +namespace TDEIO { +class Job; +} + +namespace KPIM { +class GroupwareJob; +class GroupwareDownloadJob; +class GroupwareUploadJob; +class FolderLister; +class GroupwarePrefsBase; +} + + +namespace KCal { + +class CalendarAdaptor; + +/** + This class provides a resource for accessing a Groupware kioslave-based + calendar. +*/ +class KDE_EXPORT ResourceGroupwareBase : public ResourceCached +{ + Q_OBJECT + + public: + ResourceGroupwareBase(); + + ResourceGroupwareBase( const TDEConfig * ); + virtual ~ResourceGroupwareBase(); + + void readConfig( const TDEConfig *config ); + void writeConfig( TDEConfig *config ); + + KPIM::GroupwarePrefsBase *prefs(); + KPIM::FolderLister *folderLister() { return mFolderLister; } + + bool doOpen(); + void doClose(); + + bool doLoad(); + bool doSave(); + + KABC::Lock *lock(); + + bool addEvent( Event *event ); + bool addTodo( Todo *todo ); + bool addJournal( Journal *journal ); + + protected: + void init(); + + bool confirmSave(); + + KPIM::GroupwarePrefsBase *createPrefs(); + void setPrefs( KPIM::GroupwarePrefsBase *prefs ); + void setFolderLister( KPIM::FolderLister *folderLister ); + void setAdaptor( CalendarAdaptor *adaptor ); + CalendarAdaptor *adaptor() const { return mAdaptor; } + + virtual KPIM::GroupwareDownloadJob *createDownloadJob( CalendarAdaptor *adaptor ); + virtual KPIM::GroupwareUploadJob *createUploadJob( CalendarAdaptor *adaptor ); + + protected slots: + void slotLoginJobResult( TDEIO::Job *job ); + void slotLogoffJobResult( TDEIO::Job *job ); + void slotDownloadJobResult( KPIM::GroupwareJob * ); + void slotUploadJobResult( KPIM::GroupwareJob * ); + + private: + void enter_loop(); + + KPIM::GroupwarePrefsBase *mPrefs; + KPIM::FolderLister *mFolderLister; + KABC::LockNull mLock; + CalendarAdaptor *mAdaptor; + + KPIM::GroupwareDownloadJob *mDownloadJob; + KPIM::GroupwareUploadJob *mUploadJob; + + bool mIsShowingError; + + bool mLoginFinished; // temp variable for the login job + +}; + +} + +#endif diff --git a/tderesources/lib/kcal_resourcegroupwarebaseconfig.cpp b/tderesources/lib/kcal_resourcegroupwarebaseconfig.cpp new file mode 100644 index 000000000..b654f8d0e --- /dev/null +++ b/tderesources/lib/kcal_resourcegroupwarebaseconfig.cpp @@ -0,0 +1,137 @@ +/* + This file is part of tdepim. + + Copyright (c) 2004 Cornelius Schumacher <[email protected]> + Copyright (c) 2004 Till Adam <[email protected]> + Copyright (c) 2005 Reinhold Kainhofer <[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 "kcal_resourcegroupwarebaseconfig.h" + +#include "kcal_cachesettingsdlg.h" +#include "kcal_resourcegroupwarebase.h" +#include "tderesources_groupwareprefs.h" +#include "folderconfig.h" + +#include <libkcal/resourcecachedconfig.h> + +#include <klocale.h> +#include <kdebug.h> +#include <klineedit.h> +#include <kdialog.h> +#include <kpushbutton.h> + +#include <tqlabel.h> +#include <tqlayout.h> +#include <tqhbox.h> + + +using namespace KCal; + +ResourceGroupwareBaseConfig::ResourceGroupwareBaseConfig( TQWidget* parent, + const char* name ) + : KRES::ConfigWidget( parent, name ) +{ + resize( 245, 115 ); + + TQGridLayout *mainLayout = new TQGridLayout( this, 2, 2 ); + mainLayout->setSpacing( KDialog::spacingHint() ); + + TQLabel *label = new TQLabel( i18n("URL:"), this ); + mainLayout->addWidget( label, 1, 0 ); + mUrl = new KLineEdit( this ); + mainLayout->addWidget( mUrl, 1, 1 ); + + label = new TQLabel( i18n("User:"), this ); + mainLayout->addWidget( label, 2, 0 ); + mUserEdit = new KLineEdit( this ); + mainLayout->addWidget( mUserEdit, 2, 1 ); + + label = new TQLabel( i18n("Password:"), this ); + mainLayout->addWidget( label, 3, 0 ); + mPasswordEdit = new KLineEdit( this ); + mainLayout->addWidget( mPasswordEdit, 3, 1 ); + mPasswordEdit->setEchoMode( KLineEdit::Password ); + + mFolderConfig = new KPIM::FolderConfig( this ); + connect( mFolderConfig, TQT_SIGNAL( updateFoldersClicked() ), + TQT_SLOT( updateFolders() ) ); + mainLayout->addMultiCellWidget( mFolderConfig, 4, 4, 0, 1 ); + + TQHBox *hBox = new TQHBox( this ); + mCacheSettingsButton = new KPushButton( i18n("Configure Cache Settings..."), hBox ); + mainLayout->addMultiCellWidget( hBox, 5, 5, 0, 1 ); + connect( mCacheSettingsButton, TQT_SIGNAL( clicked() ), + TQT_SLOT( showCacheSettings() ) ); + + mCacheDialog = new CacheSettingsDialog( this ); +} + +void ResourceGroupwareBaseConfig::loadSettings( KRES::Resource *resource ) +{ + kdDebug(7000) << "KCal::ResourceGroupwareBaseConfig::loadSettings()" << endl; + + ResourceGroupwareBase *res = static_cast<ResourceGroupwareBase *>( resource ); + if ( res ) { + if ( !res->prefs() ) { + kdError() << "No PREF" << endl; + return; + } + + mUrl->setText( res->prefs()->url() ); + mUserEdit->setText( res->prefs()->user() ); + mPasswordEdit->setText( res->prefs()->password() ); + if ( mCacheDialog ) mCacheDialog->loadSettings( res ); + + mFolderConfig->setFolderLister( res->folderLister() ); + mFolderConfig->updateFolderList(); + } else { + kdError(5700) << "KCalResourceGroupwareBaseConfig::loadSettings(): " + "no KCalOpenGroupware, cast failed" << endl; + } +} + +void ResourceGroupwareBaseConfig::saveSettings( KRES::Resource *resource ) +{ + ResourceGroupwareBase *res = static_cast<ResourceGroupwareBase*>( resource ); + if ( res ) { + res->prefs()->setUrl( mUrl->text() ); + res->prefs()->setUser( mUserEdit->text() ); + res->prefs()->setPassword( mPasswordEdit->text() ); + if ( mCacheDialog ) mCacheDialog->saveSettings( res ); + mFolderConfig->saveSettings(); + } else { + kdError(5700) << "KCalResourceGroupwareBaseConfig::saveSettings(): " + "no KCalOpenGroupware, cast failed" << endl; + } +} + +void ResourceGroupwareBaseConfig::updateFolders() +{ + KURL url = mUrl->text(); + url.setUser( mUserEdit->text() ); + url.setPass( mPasswordEdit->text() ); + + mFolderConfig->retrieveFolderList( url ); +} + +void ResourceGroupwareBaseConfig::showCacheSettings() +{ + if ( mCacheDialog ) mCacheDialog->exec(); +} + +#include "kcal_resourcegroupwarebaseconfig.moc" diff --git a/tderesources/lib/kcal_resourcegroupwarebaseconfig.h b/tderesources/lib/kcal_resourcegroupwarebaseconfig.h new file mode 100644 index 000000000..ab4f841a2 --- /dev/null +++ b/tderesources/lib/kcal_resourcegroupwarebaseconfig.h @@ -0,0 +1,74 @@ +/* + This file is part of tdepim. + + Copyright (c) 2004 Cornelius Schumacher <[email protected]> + Copyright (c) 2004 Till Adam <[email protected]> + Copyright (c) 2005 Reinhold Kainhofer <[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 KCAL_RESOURCEGROUPWAREBASECONFIG_H +#define KCAL_RESOURCEGROUPWAREBASECONFIG_H + +#include <tderesources/configwidget.h> +#include <tdepimmacros.h> + +class KPushButton; +class KLineEdit; + +namespace KPIM { +class FolderConfig; +} +namespace KRES { +class Resource; +} + +namespace KCal { + +class CacheSettingsDialog; + +/** + Configuration widget for groupware kioslave resource. + + @see KCalOpenGroupware +*/ +class KDE_EXPORT ResourceGroupwareBaseConfig : public KRES::ConfigWidget +{ + Q_OBJECT + + public: + ResourceGroupwareBaseConfig( TQWidget *parent = 0, const char *name = 0 ); + + public slots: + virtual void loadSettings( KRES::Resource *resource ); + virtual void saveSettings( KRES::Resource *resource ); + + protected slots: + void updateFolders(); + void showCacheSettings(); + + private: + KLineEdit *mUrl; + KLineEdit *mUserEdit; + KLineEdit *mPasswordEdit; + KPushButton *mCacheSettingsButton; + + CacheSettingsDialog *mCacheDialog; + KPIM::FolderConfig *mFolderConfig; +}; + +} + +#endif diff --git a/tderesources/lib/tderesources_groupwareprefs.kcfg b/tderesources/lib/tderesources_groupwareprefs.kcfg new file mode 100644 index 000000000..f44a6b5f9 --- /dev/null +++ b/tderesources/lib/tderesources_groupwareprefs.kcfg @@ -0,0 +1,56 @@ +<?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_groupwarerc"/> + <group name="General" > + <entry key="Url" type="String" > + <label>Server URL</label> + </entry> + <entry key="User" type="String" > + <label>User Name</label> + </entry> + <entry key="Password" type="String" > + <label>Password</label> + </entry> + </group> + <group name="Folders"> + <!--entry key="FolderIds" type="StringList"> + <label>All folder IDs on the server</label> + </entry> + <entry key="FolderNames" type="StringList"> + <label>All folder names on the server</label> + </entry--> + <entry key="ActiveFolders" type="StringList"> + <label>All active folders from the server</label> + </entry> + <entry key="FolderNumber" type="UInt"> + <label>Number of folders on the server and in the config file</label> + </entry> + <entry name="Folder$(nr)" type="StringList"> + <parameter name="nr" type="Int" max="100"/> + </entry> + <entry name="DefaultDestinations" type="StringList"> + <label>Default destinations for the various types</label> + <whatsthis>These are the default destinations for the different data +types in the following order: +Event, Todo, Journal, Contact, All, Unknown</whatsthis> +<!-- I tried using a parametrized entry using an enum, but the config +compiler from 3.3 is severely broken in that respect... --> +</entry> + <!--entry name="DefaultDestination$(Type)" type="String"> + <parameter name="Type" type="Enum"> + <values> + <value>Event</value> + <value>Todo</value> + <value>Journal</value> + <value>Contact</value> + <value>All</value> + <value>Unknown</value> + </values> + </parameter> + <default></default> + </entry--> + </group> +</kcfg> diff --git a/tderesources/lib/tderesources_groupwareprefs.kcfgc b/tderesources/lib/tderesources_groupwareprefs.kcfgc new file mode 100644 index 000000000..48350a09c --- /dev/null +++ b/tderesources/lib/tderesources_groupwareprefs.kcfgc @@ -0,0 +1,8 @@ +ClassName=GroupwarePrefsBase +File=tderesources_groupwareprefs.kcfg +GlobalEnums=false +IncludeFiles=libtdepim/kresourceprefs.h +Inherits=KResourcePrefs +Mutators=true +NameSpace=KPIM +Singleton=false diff --git a/tderesources/lib/webdavhandler.cpp b/tderesources/lib/webdavhandler.cpp new file mode 100644 index 000000000..fea7a0b16 --- /dev/null +++ b/tderesources/lib/webdavhandler.cpp @@ -0,0 +1,194 @@ +/* + This file is part of tdepim. + + Copyright (c) 2004 Cornelius Schumacher <[email protected]> + Copyright (c) 2004 Till Adam <[email protected]> + Copyright (c) 2005 Reinhold Kainhofer <[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 <tqdatetime.h> + +extern "C" { + #include <libical/ical.h> +} + + +#include "webdavhandler.h" + +WebdavHandler::WebdavHandler() +{ +} + + +KURL WebdavHandler::toDAV( const KURL& url ) +{ + KURL result( url ); + + if ( result.protocol() == "http" ) { + if ( result.port() == 443 ) { + // OpenGroupware.org returns 'http://server:443' instead of 'https://server' + result.setProtocol( "webdavs" ); + result.setPort( 0 ); + } else + result.setProtocol( "webdav" ); + } else if ( result.protocol() == "https" ) + result.setProtocol( "webdavs" ); + + return result; +} + + + +TQDomElement WebdavHandler::addElement( TQDomDocument &doc, TQDomNode &node, + const TQString &tag, const TQString &value ) +{ + TQDomElement el = doc.createElement( tag ); + node.appendChild( el ); + if ( !value.isNull() ) { + TQDomText txt = doc.createTextNode( value ); + el.appendChild( txt ); + } + return el; +} + +TQDomElement WebdavHandler::addElementNS( TQDomDocument &doc, TQDomNode &node, + const TQString &ns, const TQString &tag, const TQString &value ) +{ + TQDomElement el = doc.createElementNS( ns, tag ); + node.appendChild( el ); + if ( !value.isNull() ) { + TQDomText txt = doc.createTextNode( value ); + el.appendChild( txt ); + } + return el; +} + +TQDomElement WebdavHandler::addDavElement( TQDomDocument &doc, TQDomNode &node, + const TQString &tag, const TQString &value ) +{ + return addElementNS( doc, node, "DAV:", tag, value ); +} + +bool WebdavHandler::extractBool( const TQDomElement &node, const TQString &entry, bool &value ) +{ + TQDomElement element = node.namedItem( entry ).toElement(); + if ( !element.isNull() ) { + value = (element.text() != "0"); + return true; + } + return false; +} + +bool WebdavHandler::extractLong( const TQDomElement &node, const TQString &entry, long &value ) +{ + TQDomElement element = node.namedItem( entry ).toElement(); + if ( !element.isNull() ) { + value = element.text().toLong(); + return true; + } + return false; +} + +bool WebdavHandler::extractFloat( const TQDomElement &node, const TQString &entry, float &value ) +{ + TQDomElement element = node.namedItem( entry ).toElement(); + if ( !element.isNull() ) { + value = element.text().toFloat(); + return true; + } + return false; +} + +bool WebdavHandler::extractDateTime( const TQDomElement &node, const TQString &entry, TQDateTime &value ) +{ + TQDomElement element = node.namedItem( entry ).toElement(); + if ( !element.isNull() && !element.text().isEmpty() ) { + value = TQDateTime::fromString( element.text(), Qt::ISODate ); + return true; + } + return false; +} + +bool WebdavHandler::extractString( const TQDomElement &node, const TQString &entry, TQString &value ) +{ + TQDomElement element = node.namedItem( entry ).toElement(); + if ( !element.isNull() ) { + value = element.text(); + return true; + } + return false; +} + +bool WebdavHandler::extractStringList( const TQDomElement &node, const TQString &entry, TQStringList &value ) +{ + TQDomElement element = node.namedItem( entry ).toElement(); + if ( !element.isNull() ) { + value.clear(); + TQDomNodeList list = element.elementsByTagNameNS( "xml:", "v" ); + for( uint i=0; i < list.count(); i++ ) { + TQDomElement item = list.item(i).toElement(); + value.append( item.text() ); + } + return true; + } + return false; +} + + +const TQString WebdavHandler::getEtagFromHeaders( const TQString& headers ) +{ + int start = headers.find( "etag:", 0, false ); + if ( start < 0 ) return TQString(); + start += 6; + return headers.mid( start, headers.find( "\n", start ) - start ); +} + +//TODO: should not call libical functions directly -- better to make +// a new libkcal abstraction method. +TQDateTime WebdavHandler::utcAsZone( const TQDateTime& utc, const TQString& timeZoneId ) +{ + int daylight; + TQDateTime epoch; + epoch.setTime_t( 0 ); + time_t v = epoch.secsTo( utc ); + struct icaltimetype tt = + icaltime_from_timet_with_zone( v, 0 /*is_date*/, + icaltimezone_get_builtin_timezone( "UTC" ) ); + int offset = icaltimezone_get_utc_offset( + icaltimezone_get_builtin_timezone( timeZoneId.latin1() ), + &tt, &daylight ); +kdDebug() << "Calculated offset of: " << offset << " of timezone: " << timeZoneId << endl; + return utc.addSecs( offset ); +} + +//TODO: should not call libical functions directly -- better to make +// a new libkcal abstraction method. +TQDateTime WebdavHandler::zoneAsUtc( const TQDateTime& zone, const TQString& timeZoneId ) +{ + int daylight; + TQDateTime epoch; + epoch.setTime_t( 0 ); + time_t v = epoch.secsTo( zone ); + struct icaltimetype tt = icaltime_from_timet( v, 0 ); // 0: is_date=false + int offset = icaltimezone_get_utc_offset( + icaltimezone_get_builtin_timezone( timeZoneId.latin1() ), + &tt, &daylight ); + return zone.addSecs( - offset ); +} diff --git a/tderesources/lib/webdavhandler.h b/tderesources/lib/webdavhandler.h new file mode 100644 index 000000000..0bfb33e90 --- /dev/null +++ b/tderesources/lib/webdavhandler.h @@ -0,0 +1,78 @@ +/* + This file is part of tdepim. + + Copyright (c) 2004 Cornelius Schumacher <[email protected]> + Copyright (c) 2004 Till Adam <[email protected]> + Copyright (c) 2005 Reinhold Kainhofer <[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 WEBDAVHANDLER_H +#define WEBDAVHANDLER_H + +#include <tqstring.h> +#include <tqstringlist.h> +#include <tqdom.h> +#include <tqdatetime.h> +#include <kurl.h> +#include <tdepimmacros.h> + +class KDE_EXPORT WebdavHandler +{ + public: + WebdavHandler(); + + static KURL toDAV( const KURL& url ); + + + static TQDomElement addElementNS( TQDomDocument &doc, TQDomNode &node, + const TQString &ns, const TQString &tag, + const TQString &value = TQString() ); + static TQDomElement addElement( TQDomDocument &, TQDomNode &, + const TQString &tag, const TQString &value = TQString() ); + static TQDomElement addDavElement( TQDomDocument &, TQDomNode &, + const TQString &tag, const TQString &value = TQString() ); + + static bool extractBool( const TQDomElement &node, + const TQString &entry, bool &value ); + static bool extractLong( const TQDomElement &node, + const TQString &entry, long &value ); + static bool extractFloat( const TQDomElement &node, + const TQString &entry, float &value ); + static bool extractDateTime( const TQDomElement &node, + const TQString &entry, TQDateTime &value ); + static bool extractString( const TQDomElement &node, + const TQString &entry, TQString &value ); + static bool extractStringList( const TQDomElement &node, + const TQString &entry, TQStringList &value ); + + /** + * Returns the value of the "etag" header if it can be found in the headers. + */ + static const TQString getEtagFromHeaders( const TQString& ); + + + /** + * Return the representation of utc time in the time zone indicated by timeZoneId + */ + static TQDateTime utcAsZone( const TQDateTime& utc, const TQString& timeZoneId ); + + /** + * Return the UTC representation of local time in the time zone indicated by timeZoneId + */ + static TQDateTime zoneAsUtc( const TQDateTime& zone, const TQString& timeZoneId ); +}; + +#endif |