Projects
Kolab:Winterfell
libkolab
Log In
Username
Password
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
Expand all
Collapse all
Changes of Revision 40
View file
libkolab.spec
Changed
@@ -31,7 +31,7 @@ Name: libkolab %endif -Version: 2.0 +Version: 3.0.0 Release: 0.1.dev20150112.gitf0f953aa%{?dist} Summary: Kolab Object Handling Library
View file
debian.changelog
Changed
@@ -1,3 +1,9 @@ +libkolab (3.0~dev20151230-0~kolab16) unstable; urgency=low + + * New 3.0 release + + -- Christian Mollekopf <mollekopf@kolabsys.com> Wed, 03 Mar 2021 09:09:09 +0100 + libkolab (2.0~dev20151230-0~kolab16) unstable; urgency=low * Bump release
View file
debian.control
Changed
@@ -6,15 +6,16 @@ Build-Depends: cmake, debhelper, + libcurl4-gnutls-dev, libboost-dev, - libboost-program-options-dev, libboost-thread-dev, libboost-system-dev, - libcalendaring-dev (>= 4.9.1), - libcurl4-gnutls-dev, libkolabxml-dev (>= 1.0), libossp-uuid-dev, - libqt4-dev, + qtbase5-dev, + libkf5coreaddons-dev, + libkf5calendarcore-dev, + libkf5mime-dev, libxerces-c-dev, php-cgi | php5-cli, php-dev | php5-dev, @@ -30,7 +31,7 @@ Standards-Version: 3.9.3 Homepage: http://git.kolab.org/libkolab -Package: libkolab2 +Package: libkolab3 Architecture: any Depends: ${misc:Depends}, ${shlibs:Depends}, libkolabxml1v5 (>= 1.0) Conflicts: libkolab0 @@ -53,10 +54,9 @@ Package: php-kolab Architecture: any -Depends: libkolab2 (>= ${binary:Version}), +Depends: libkolab3 (>= ${binary:Version}), php-kolabformat, ucf, - libcalendaring (>= 4.9.1), ${php:Depends}, ${misc:Depends}, ${shlibs:Depends} @@ -72,7 +72,7 @@ Package: python-kolab Architecture: any Section: python -Depends: libkolab2 (= ${binary:Version}), +Depends: libkolab3 (= ${binary:Version}), python, ${misc:Depends}, ${shlibs:Depends} @@ -87,8 +87,7 @@ Package: libkolab-dev Section: libdevel Architecture: any -Depends: libkolab2 (= ${binary:Version}), - libcalendaring-dev (>= 4.9.1), +Depends: libkolab3 (= ${binary:Version}), ${misc:Depends} Conflicts: libkolab-kde-dev Description: Development package for Kolab library
View file
debian.rules
Changed
@@ -28,7 +28,7 @@ echo "" >> debian/control ; \ echo "Package: plesk-php$${shver}-kolab" >> debian/control ; \ echo "Architecture: amd64" >> debian/control ; \ - echo "Depends: libkolab2, plesk-php$${shver}" >> debian/control ; \ + echo "Depends: libkolab3, plesk-php$${shver}" >> debian/control ; \ echo "Provides: php-bindings-libkolab" >> debian/control ; \ echo "Description: Kolab library bindings for Plesk PHP $${version}" >> debian/control ; \ echo "" >> debian/control ; \ @@ -78,8 +78,8 @@ fi ; \ dh_auto_configure --builddirectory php-$${version} -- \ -DLIB_INSTALL_DIR=/usr/lib \ + -DBoost_NO_BOOST_CMAKE=TRUE \ -DSWIG=/usr/bin/swig \ - -DUSE_LIBCALENDARING=ON \ -DPHP_BINDINGS=ON \ -DPHP_INCLUDE_DIR=$$(/opt/plesk/php/$${version}/bin/php-config --include-dir) \ -DPHP_CONFIG_EXECUTABLE=/opt/plesk/php/$${version}/bin/php-config \ @@ -97,13 +97,13 @@ dh_auto_configure -- \ -DLIB_INSTALL_DIR=/usr/lib \ + -DBoost_NO_BOOST_CMAKE=TRUE \ -DPHP_BINDINGS=ON \ -DPHP_INSTALL_DIR=$(PHPEXT) \ -DPHP_EXECUTABLE=$(PHPBIN) \ -DPHP_INCLUDE_DIR=$(PHPINC) \ -DPYTHON_BINDINGS=ON \ - -DPYTHON_INSTALL_DIR=$(PYTHON_SITEARCH) \ - -DUSE_LIBCALENDARING=ON + -DPYTHON_INSTALL_DIR=$(PYTHON_SITEARCH) override_dh_install: # Install the PHP modules manually, because they depend on PHP the API version,
View file
debian.tar.gz/libkolab-kde-dev.install
Deleted
@@ -1,3 +0,0 @@ -usr/lib/libkolab-kde.so -usr/lib/cmake/Libkolab/*.cmake -usr/include/kolab/*.h
View file
debian.tar.gz/libkolab-kde2.install
Deleted
@@ -1,2 +0,0 @@ -usr/lib/libkolab-kde.so.0 -usr/lib/libkolab-kde.so.0.*
View file
debian.tar.gz/libkolab-kde2.lintian-overrides
Deleted
@@ -1,9 +0,0 @@ -# hardening-check --verbose libkolab-dev.so.0 reports -# Fortify Source functions: no, only unprotected functions found! -# unprotected: memmove -# unprotected: memcpy -# Neither memmove nor memcpy occur in the source code, -# so overriding this warning -libkolab-kde0 binary: hardening-no-fortify-functions -# Using shlibs for now -libkolab-kde0 binary: no-symbols-control-file
View file
debian.tar.gz/libkolab-kde2.shlibs
Deleted
@@ -1,1 +0,0 @@ -libkolab-kde 2 libkolab-kde2 (>= 2.0)
View file
debian.tar.gz/libkolab2.install
Deleted
@@ -1,2 +0,0 @@ -usr/lib/libkolab.so.2 -usr/lib/libkolab.so.2.*
View file
debian.tar.gz/libkolab2.lintian-overrides
Deleted
@@ -1,9 +0,0 @@ -# hardening-check --verbose libkolab.so.0 reports -# Fortify Source functions: no, only unprotected functions found! -# unprotected: memmove -# unprotected: memcpy -# Neither memmove nor memcpy occur in the source code, -# so overriding this warning -libkolab2 binary: hardening-no-fortify-functions -# Using shlibs for now -libkolab2 binary: no-symbols-control-file
View file
debian.tar.gz/libkolab2.shlibs
Deleted
@@ -1,1 +0,0 @@ -libkolab 2 libkolab2 (>= 2)
View file
debian.tar.gz/libkolab3.install
Added
@@ -0,0 +1,2 @@ +usr/lib/libkolab.so.3 +usr/lib/libkolab.so.3.*
View file
debian.tar.gz/libkolab3.lintian-overrides
Added
@@ -0,0 +1,9 @@ +# hardening-check --verbose libkolab.so.0 reports +# Fortify Source functions: no, only unprotected functions found! +# unprotected: memmove +# unprotected: memcpy +# Neither memmove nor memcpy occur in the source code, +# so overriding this warning +libkolab3 binary: hardening-no-fortify-functions +# Using shlibs for now +libkolab3 binary: no-symbols-control-file
View file
debian.tar.gz/libkolab3.shlibs
Added
@@ -0,0 +1,1 @@ +libkolab 3 libkolab3 (>= 3)
View file
libkolab-2.0.tar.gz/conversion/kabcconversion.cpp
Deleted
@@ -1,894 +0,0 @@ -/* - * Copyright (C) 2011 Christian Mollekopf <mollekopf@kolabsys.com> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include "kabcconversion.h" - -#include "commonconversion.h" -#include <kdebug.h> -#include <qbuffer.h> -#include <qimagereader.h> -#include "kolabformat/errorhandler.h" - - - -namespace Kolab { - namespace Conversion { - - //The following was copied from kdepim/libkleo/kleo/enum.h,.cpp - enum CryptoMessageFormat { - InlineOpenPGPFormat = 1, - OpenPGPMIMEFormat = 2, - SMIMEFormat = 4, - SMIMEOpaqueFormat = 8, - AnyOpenPGP = InlineOpenPGPFormat|OpenPGPMIMEFormat, - AnySMIME = SMIMEOpaqueFormat|SMIMEFormat, - AutoFormat = AnyOpenPGP|AnySMIME - }; - - enum EncryptionPreference { - UnknownPreference = 0, - NeverEncrypt = 1, - AlwaysEncrypt = 2, - AlwaysEncryptIfPossible = 3, - AlwaysAskForEncryption = 4, - AskWheneverPossible = 5, - MaxEncryptionPreference = AskWheneverPossible - }; - - enum SigningPreference { - UnknownSigningPreference = 0, - NeverSign = 1, - AlwaysSign = 2, - AlwaysSignIfPossible = 3, - AlwaysAskForSigning = 4, - AskSigningWheneverPossible = 5, - MaxSigningPreference = AskSigningWheneverPossible - }; - - static const struct { - CryptoMessageFormat format; - const char * displayName; - const char * configName; - } cryptoMessageFormats[] = { - { InlineOpenPGPFormat, - ("Inline OpenPGP (deprecated)"), - "inline openpgp" }, - { OpenPGPMIMEFormat, - ("OpenPGP/MIME"), - "openpgp/mime" }, - { SMIMEFormat, - ("S/MIME"), - "s/mime" }, - { SMIMEOpaqueFormat, - ("S/MIME Opaque"), - "s/mime opaque" }, - }; - static const unsigned int numCryptoMessageFormats - = sizeof cryptoMessageFormats / sizeof *cryptoMessageFormats ; - - const char * cryptoMessageFormatToString( CryptoMessageFormat f ) { - if ( f == AutoFormat ) - return "auto"; - for ( unsigned int i = 0 ; i < numCryptoMessageFormats ; ++i ) - if ( f == cryptoMessageFormats[i].format ) - return cryptoMessageFormats[i].configName; - return 0; - } - - QStringList cryptoMessageFormatsToStringList( unsigned int f ) { - QStringList result; - for ( unsigned int i = 0 ; i < numCryptoMessageFormats ; ++i ) - if ( f & cryptoMessageFormats[i].format ) - result.push_back( cryptoMessageFormats[i].configName ); - return result; - } - - - CryptoMessageFormat stringToCryptoMessageFormat( const QString & s ) { - const QString t = s.toLower(); - for ( unsigned int i = 0 ; i < numCryptoMessageFormats ; ++i ) - if ( t == cryptoMessageFormats[i].configName ) - return cryptoMessageFormats[i].format; - return AutoFormat; - } - - unsigned int stringListToCryptoMessageFormats( const QStringList & sl ) { - unsigned int result = 0; - for ( QStringList::const_iterator it = sl.begin() ; it != sl.end() ; ++it ) - result |= stringToCryptoMessageFormat( *it ); - return result; - } - - // For the config values used below, see also kaddressbook/editors/cryptowidget.cpp - - const char* encryptionPreferenceToString( EncryptionPreference pref ) - { - switch( pref ) { - case UnknownPreference: - return 0; - case NeverEncrypt: - return "never"; - case AlwaysEncrypt: - return "always"; - case AlwaysEncryptIfPossible: - return "alwaysIfPossible"; - case AlwaysAskForEncryption: - return "askAlways"; - case AskWheneverPossible: - return "askWhenPossible"; - } - return 0; // keep the compiler happy - } - - EncryptionPreference stringToEncryptionPreference( const QString& str ) - { - if ( str == "never" ) - return NeverEncrypt; - if ( str == "always" ) - return AlwaysEncrypt; - if ( str == "alwaysIfPossible" ) - return AlwaysEncryptIfPossible; - if ( str == "askAlways" ) - return AlwaysAskForEncryption; - if ( str == "askWhenPossible" ) - return AskWheneverPossible; - return UnknownPreference; - } - - const char* signingPreferenceToString( SigningPreference pref ) - { - switch( pref ) { - case UnknownSigningPreference: - return 0; - case NeverSign: - return "never"; - case AlwaysSign: - return "always"; - case AlwaysSignIfPossible: - return "alwaysIfPossible"; - case AlwaysAskForSigning: - return "askAlways"; - case AskSigningWheneverPossible: - return "askWhenPossible"; - } - return 0; // keep the compiler happy - } - - SigningPreference stringToSigningPreference( const QString& str ) - { - if ( str == "never" ) - return NeverSign; - if ( str == "always" ) - return AlwaysSign; - if ( str == "alwaysIfPossible" ) - return AlwaysSignIfPossible; - if ( str == "askAlways" ) - return AlwaysAskForSigning; - if ( str == "askWhenPossible" ) - return AskSigningWheneverPossible; - return UnknownSigningPreference; - } - - - -int fromAddressType(int kabcType, bool &pref) -{ - int type = 0; - if (kabcType & KABC::Address::Dom) { - Warning() << "domestic address is not supported"; - } - if (kabcType & KABC::Address::Intl) { - Warning() << "international address is not supported"; - } - if (kabcType & KABC::Address::Pref) { - pref = true; - } - if (kabcType & KABC::Address::Postal) { - Warning() << "postal address is not supported"; - } - if (kabcType & KABC::Address::Parcel) { - Warning() << "parcel is not supported"; - } - if (kabcType & KABC::Address::Home) { - type |= Kolab::Address::Home; - } - if (kabcType & KABC::Address::Work) { - type |= Kolab::Address::Work; - } - return type; -} - -KABC::Address::Type toAddressType(int types, bool pref) -{ - KABC::Address::Type type = 0; - if (pref) { - type |= KABC::Address::Pref; - } - if (types & Kolab::Address::Home) { - type |= KABC::Address::Home; - } - if (types & Kolab::Address::Work) { - type |= KABC::Address::Work; - } - return type; -} - -int fromPhoneType(int kabcType, bool &pref) -{ - int type = 0; - if (kabcType & KABC::PhoneNumber::Home) { - type |= Kolab::Telephone::Home; - } - if (kabcType & KABC::PhoneNumber::Work) { - type |= Kolab::Telephone::Work; - } - if (kabcType & KABC::PhoneNumber::Msg) { - type |= Kolab::Telephone::Text; - } - if (kabcType & KABC::PhoneNumber::Pref) { - pref = true; - } - if (kabcType & KABC::PhoneNumber::Voice) { - type |= Kolab::Telephone::Voice; - } - if (kabcType & KABC::PhoneNumber::Fax) { - type |= Kolab::Telephone::Fax; - } - if (kabcType & KABC::PhoneNumber::Cell) { - type |= Kolab::Telephone::Cell; - } - if (kabcType & KABC::PhoneNumber::Video) { - type |= Kolab::Telephone::Video; - } - if (kabcType & KABC::PhoneNumber::Bbs) { - Warning() << "mailbox number is not supported"; - } - if (kabcType & KABC::PhoneNumber::Modem) { - Warning() << "modem is not supported"; - } - if (kabcType & KABC::PhoneNumber::Car) { - type |= Kolab::Telephone::Car; - } - if (kabcType & KABC::PhoneNumber::Isdn) { - Warning() << "isdn number is not supported"; - } - if (kabcType & KABC::PhoneNumber::Pcs) { - type |= Kolab::Telephone::Text; - } - if (kabcType & KABC::PhoneNumber::Pager) { - type |= Kolab::Telephone::Pager; - } - return type; -} - -KABC::PhoneNumber::Type toPhoneType(int types, bool pref) -{ - KABC::PhoneNumber::Type type = 0; - if (types & Kolab::Telephone::Home) { - type |= KABC::PhoneNumber::Home; - } - if (types & Kolab::Telephone::Work) { - type |= KABC::PhoneNumber::Work; - } - if (types & Kolab::Telephone::Text) { - type |= KABC::PhoneNumber::Msg; - } - if (pref) { - type |= KABC::PhoneNumber::Pref; - } - if (types & Kolab::Telephone::Voice) { - type |= KABC::PhoneNumber::Voice; - } - if (types & Kolab::Telephone::Fax) { - type |= KABC::PhoneNumber::Fax; - } - if (types & Kolab::Telephone::Cell) { - type |= KABC::PhoneNumber::Cell; - } - if (types & Kolab::Telephone::Video) { - type |= KABC::PhoneNumber::Video; - } - if (types & Kolab::Telephone::Car) { - type |= KABC::PhoneNumber::Car; - } - if (types & Kolab::Telephone::Text) { - type |= KABC::PhoneNumber::Pcs; - } - if (types & Kolab::Telephone::Pager) { - type |= KABC::PhoneNumber::Pager; - } - return type; -} - -std::string fromPicture(const KABC::Picture &pic, std::string &mimetype) -{ - QByteArray input; - QBuffer buffer( &input ); - buffer.open( QIODevice::WriteOnly ); - QImage img; - - - if ( pic.isIntern() ) { - if ( !pic.data().isNull() ) { - img = pic.data(); - } - } else if ( !pic.url().isEmpty() ) { - QString tmpFile; - kWarning() << "external pictures are currently not supported"; - //FIXME add kio support to libcalendaring or use libcurl -// if ( KIO::NetAccess::download( pic.url(), tmpFile, 0 /*no widget known*/ ) ) { -// img.load( tmpFile ); -// KIO::NetAccess::removeTempFile( tmpFile ); -// } - } - if (img.isNull()) { - Error() << "invalid picture"; - return std::string(); - } - if ( !img.hasAlphaChannel() ) { - if (!img.save( &buffer, "JPEG" )) { - Error() << "error on jpeg save"; - return std::string(); - } - mimetype = "image/jpeg"; - } else { - if (!img.save( &buffer, "PNG" )) { - Error() << "error on png save"; - return std::string(); - } - mimetype = "image/png"; - } - return std::string(input.data(), input.size()); -} - -KABC::Picture toPicture(const std::string &data, const std::string &mimetype) { - QImage img; - bool ret = false; - QByteArray type(mimetype.data(), mimetype.size()); - type = type.split('/').last(); // extract "jpeg" from "image/jpeg" - if (QImageReader::supportedImageFormats().contains(type)) { - ret = img.loadFromData(QByteArray::fromRawData(data.data(), data.size()), type.constData()); - } else { - ret = img.loadFromData(QByteArray::fromRawData(data.data(), data.size())); - } - if (!ret) { - Warning() << "failed to load picture"; - return KABC::Picture(); - } - - KABC::Picture logo(img); - if (logo.isEmpty()) { - Warning() << "failed to read picture"; - return KABC::Picture(); - } - return logo; -} - -template <typename T> -void setCustom(const std::string &value, const std::string &id, T &object) -{ - std::vector <Kolab::CustomProperty > properties = object.customProperties(); - properties.push_back(CustomProperty(id, value)); - object.setCustomProperties(properties); -} - -template <typename T> -std::string getCustom(const std::string &id, T &object) -{ - const std::vector <Kolab::CustomProperty > &properties = object.customProperties(); - foreach(const Kolab::CustomProperty &prop, properties) { - if (prop.identifier == id) { - return prop.value; - } - } - return std::string(); -} - -static QString emailTypesToStringList(int emailTypes) { - QStringList types; - if (emailTypes & Kolab::Email::Home) { - types << "home"; - } - if (emailTypes & Kolab::Email::Work) { - types << "work"; - } - return types.join(","); -} - -static int emailTypesFromStringlist(const QString &types) { - int emailTypes = Kolab::Email::NoType; - if (types.contains("home")) { - emailTypes |= Kolab::Email::Home; - } - if (types.contains("work")) { - emailTypes |= Kolab::Email::Work; - } - return emailTypes; -} - -KABC::Addressee toKABC(const Kolab::Contact &contact) -{ - KABC::Addressee addressee; - addressee.setUid(fromStdString(contact.uid())); - addressee.setCategories(toStringList(contact.categories())); - //addressee.setName(fromStdString(contact.name()));//This one is only for compatiblity (and results in a non-existing name property) - addressee.setFormattedName(fromStdString(contact.name())); //This on corresponds to fn - - const Kolab::NameComponents &nc = contact.nameComponents(); - if (!nc.surnames().empty()) { - addressee.setFamilyName(fromStdString(nc.surnames().front())); - } - if (!nc.given().empty()) { - addressee.setGivenName(fromStdString(nc.given().front())); - } - if (!nc.additional().empty()) { - addressee.setAdditionalName(fromStdString(nc.additional().front())); - } - if (!nc.prefixes().empty()) { - addressee.setPrefix(fromStdString(nc.prefixes().front())); - } - if (!nc.suffixes().empty()) { - addressee.setSuffix(fromStdString(nc.suffixes().front())); - } - - addressee.setNote(fromStdString(contact.note())); - - addressee.setSecrecy(KABC::Secrecy::Public); //We don't have any privacy setting in xCard - - - QString preferredEmail; - - if (!contact.emailAddresses().empty()) { - QStringList emails; - foreach( const Kolab::Email &email, contact.emailAddresses()) { - emails << fromStdString(email.address()); - const QString types = emailTypesToStringList(email.types()); - if (!types.isEmpty()) { - addressee.insertCustom(QLatin1String("KOLAB"), QString::fromLatin1("EmailTypes%1").arg(fromStdString(email.address())), types); - } - } - addressee.setEmails(emails); - if ((contact.emailAddressPreferredIndex() >= 0) && (contact.emailAddressPreferredIndex() < static_cast<int>(contact.emailAddresses().size()))) { - preferredEmail = fromStdString(contact.emailAddresses().at(contact.emailAddressPreferredIndex()).address()); - } else { - preferredEmail = fromStdString(contact.emailAddresses().at(0).address()); - } - addressee.insertEmail(preferredEmail, true); - } - - if (!contact.freeBusyUrl().empty()) { - if (preferredEmail.isEmpty()) { - Error() << "f/b url is set but no email address available, skipping"; - } else { - addressee.insertCustom("KOLAB", "FreebusyUrl", fromStdString(contact.freeBusyUrl())); - } - } - - if (!contact.nickNames().empty()) { - addressee.setNickName(fromStdString(contact.nickNames().at(0))); //TODO support multiple - } - - if (contact.bDay().isValid()) { - addressee.setBirthday(toDate(contact.bDay()).dateTime()); - } - if (!contact.titles().empty()) { - addressee.setTitle(fromStdString(contact.titles().at(0))); //TODO support multiple - } - if (!contact.urls().empty()) { - addressee.setUrl(fromStdString(contact.urls().at(0).url())); //TODO support multiple - foreach(const Kolab::Url &u, contact.urls()) { - if (u.type() == Kolab::Url::Blog) { - addressee.insertCustom("KADDRESSBOOK", "BlogFeed", fromStdString(u.url())); - } - } - } - - - if (!contact.affiliations().empty()) { - //Storing only a const reference leads to segfaults. No idea why. - const Kolab::Affiliation aff = contact.affiliations().at(0); //TODO support multiple - if (!aff.organisation().empty()) { - addressee.setOrganization(fromStdString(aff.organisation())); - } - if (!aff.organisationalUnits().empty()) { - addressee.setDepartment(fromStdString(aff.organisationalUnits().at(0))); //TODO support multiple - } - if (!aff.roles().empty()) { - addressee.setRole(fromStdString(aff.roles().at(0))); //TODO support multiple - } - if (!aff.logo().empty()) { - addressee.setLogo(toPicture(aff.logo(), aff.logoMimetype())); - } - foreach(const Kolab::Related &related, aff.relateds()) { - if (related.type() != Kolab::Related::Text) { - Error() << "invalid relation type"; - continue; - } - if (related.relationTypes() & Kolab::Related::Assistant) { - addressee.insertCustom(QLatin1String("KADDRESSBOOK"), QLatin1String("X-AssistantsName"), fromStdString(related.text())); - } - if (related.relationTypes() & Kolab::Related::Manager) { - addressee.insertCustom(QLatin1String("KADDRESSBOOK"), QLatin1String("X-ManagersName"), fromStdString(related.text())); - } - } - foreach(const Kolab::Address &address, aff.addresses()) { - addressee.insertCustom(QLatin1String("KADDRESSBOOK"), QLatin1String("X-Office"), fromStdString(address.label())); //TODO support proper addresses - } - } - const std::string &prof = getCustom("X-Profession", contact); - if (!prof.empty()) { - addressee.insertCustom(QLatin1String("KADDRESSBOOK"), QLatin1String("X-Profession"), fromStdString(prof)); - } - - const std::string &adrBook = getCustom("X-AddressBook", contact); - if (!adrBook.empty()) { - addressee.insertCustom(QLatin1String("KADDRESSBOOK"), QLatin1String("X-AddressBook"), fromStdString(prof)); - } - - if (!contact.photo().empty()) { - addressee.setPhoto(toPicture(contact.photo(), contact.photoMimetype())); - } - - if (!contact.telephones().empty()) { - int index = 0; - foreach(const Kolab::Telephone &tel, contact.telephones()) { - bool pref = false; - if (index == contact.telephonesPreferredIndex()) { - pref = true; - } - KABC::PhoneNumber number(fromStdString(tel.number()), toPhoneType(tel.types(), pref)); - index++; - addressee.insertPhoneNumber(number); - } - } - - if (!contact.addresses().empty()) { - int index = 0; - foreach(const Kolab::Address &a, contact.addresses()) { - bool pref = false; - if (index == contact.addressPreferredIndex()) { - pref = true; - } - KABC::Address adr(toAddressType(a.types(), pref)); - adr.setLabel(fromStdString(a.label())); - adr.setStreet(fromStdString(a.street())); - adr.setLocality(fromStdString(a.locality())); - adr.setRegion(fromStdString(a.region())); - adr.setPostalCode(fromStdString(a.code())); - adr.setCountry(fromStdString(a.country())); - - index++; - addressee.insertAddress(adr); - } - } - - if (contact.anniversary().isValid()) { - addressee.insertCustom(QLatin1String("KADDRESSBOOK"), QLatin1String("X-Anniversary"), toDate(contact.anniversary()).toString(KDateTime::ISODate)); - } - - if (!contact.imAddresses().empty()) { - addressee.insertCustom(QLatin1String("KADDRESSBOOK"), QLatin1String("X-IMAddress"),fromStdString(contact.imAddresses()[0])); //TODO support multiple - } - - if (!contact.relateds().empty()) { - foreach(const Kolab::Related &rel, contact.relateds()) { - if (rel.type() != Kolab::Related::Text) { - Error() << "relation type not supported"; - continue; - } - if (rel.relationTypes() & Kolab::Related::Spouse) { - addressee.insertCustom(QLatin1String("KADDRESSBOOK"), QLatin1String("X-SpousesName"),fromStdString(rel.text())); //TODO support multiple - } else { - Warning() << "relation not supported"; - continue; - } - } - } - - return addressee; -} - -Kolab::Contact fromKABC(const KABC::Addressee &addressee) -{ - int prefNum = -1; - int prefCounter = -1; - Kolab::Contact c; - c.setUid(toStdString(addressee.uid())); - c.setCategories(fromStringList(addressee.categories())); - c.setName(toStdString(addressee.formattedName())); - Kolab::NameComponents nc; - nc.setSurnames(std::vector<std::string>() << toStdString(addressee.familyName())); - nc.setGiven(std::vector<std::string>() << toStdString(addressee.givenName())); - nc.setAdditional(std::vector<std::string>() << toStdString(addressee.additionalName())); - nc.setPrefixes(std::vector<std::string>() << toStdString(addressee.prefix())); - nc.setSuffixes(std::vector<std::string>() << toStdString(addressee.suffix())); - c.setNameComponents(nc); - - c.setNote(toStdString(addressee.note())); - c.setFreeBusyUrl(toStdString(addressee.custom("KOLAB", QString("FreebusyUrl")))); - - if (!addressee.title().isEmpty()) { - c.setTitles(std::vector<std::string>() << toStdString(addressee.title())); - } - - Kolab::Affiliation businessAff; - businessAff.setOrganisation(toStdString(addressee.organization())); - if (!addressee.department().isEmpty()) { - Debug() << addressee.department() << addressee.department().toLatin1() << addressee.department().toUtf8(); - businessAff.setOrganisationalUnits(std::vector<std::string>() << toStdString(addressee.department())); - } - - if (!addressee.logo().isEmpty()) { - std::string logoMimetype; - const std::string &logo = fromPicture(addressee.logo(), logoMimetype); - businessAff.setLogo(logo, logoMimetype); - } - if (!addressee.role().isEmpty()) { - businessAff.setRoles(std::vector<std::string>() << toStdString(addressee.role())); - } - const QString &office = addressee.custom(QLatin1String("KADDRESSBOOK"), QLatin1String("X-Office")); - if (!office.isEmpty()) { - Kolab::Address a; - a.setTypes(Kolab::Address::Work); - a.setLabel(toStdString(addressee.custom(QLatin1String("KADDRESSBOOK"), QLatin1String("X-Office")))); - businessAff.setAddresses(std::vector<Kolab::Address>() << a); - } - - std::vector<Kolab::Related> relateds; - const QString &manager = addressee.custom(QLatin1String("KADDRESSBOOK"), QLatin1String("X-ManagersName")); - if (!manager.isEmpty()) { - relateds.push_back(Kolab::Related(Kolab::Related::Text, toStdString(manager), Kolab::Related::Manager)); - } - const QString &assistant = addressee.custom(QLatin1String("KADDRESSBOOK"), QLatin1String("X-AssistantsName")); - if (!assistant.isEmpty()) { - relateds.push_back(Kolab::Related(Kolab::Related::Text, toStdString(assistant), Kolab::Related::Assistant)); - } - if (!relateds.empty()) { - businessAff.setRelateds(relateds); - } - if (!(businessAff == Kolab::Affiliation())) { - c.setAffiliations(std::vector<Kolab::Affiliation>() << businessAff); - } - - std::vector<Kolab::Url> urls; - if (!addressee.url().isEmpty()) { - urls.push_back(Kolab::Url(toStdString(addressee.url().url()))); - } - const QString &blogUrl = addressee.custom(QLatin1String("KADDRESSBOOK"), QLatin1String("BlogFeed")); - if (!blogUrl.isEmpty()) { - urls.push_back(Kolab::Url(toStdString(blogUrl), Kolab::Url::Blog)); - } - c.setUrls(urls); - - std::vector<Kolab::Address> addresses; - prefNum = -1; - prefCounter = -1; - foreach(const KABC::Address &a, addressee.addresses()) { - Kolab::Address adr; - bool pref = false; - adr.setTypes(fromAddressType(a.type(), pref)); - prefCounter++; - if (pref) { - prefNum = prefCounter; - } - adr.setLabel(toStdString(a.label())); - adr.setStreet(toStdString(a.street())); - adr.setLocality(toStdString(a.locality())); - adr.setRegion(toStdString(a.region())); - adr.setCode(toStdString(a.postalCode())); - adr.setCountry(toStdString(a.country())); - addresses.push_back(adr); - } - c.setAddresses(addresses, prefNum); - - if (!addressee.nickName().isEmpty()) { - c.setNickNames(std::vector<std::string>() << toStdString(addressee.nickName())); - } - - const QString &spouse = addressee.custom(QLatin1String("KADDRESSBOOK"), QLatin1String("X-SpousesName")); - if (!spouse.isEmpty()) { - c.setRelateds(std::vector<Kolab::Related>() << Kolab::Related(Kolab::Related::Text, toStdString(spouse), Kolab::Related::Spouse)); - } - c.setBDay(fromDate(KDateTime(addressee.birthday(), KDateTime::ClockTime))); - c.setAnniversary(fromDate(KDateTime(QDate::fromString( addressee.custom(QLatin1String("KADDRESSBOOK"), QLatin1String("X-Anniversary")), Qt::ISODate ), KDateTime::ClockTime))); - if (!addressee.photo().isEmpty()) { - std::string mimetype; - const std::string &photo = fromPicture(addressee.photo(), mimetype); - c.setPhoto(photo, mimetype); - } - //TODO -// c.setGender(); -// c.setLanguages(); - - std::vector <Kolab::Telephone> phones; - prefNum = -1; - prefCounter = -1; - foreach (const KABC::PhoneNumber &n, addressee.phoneNumbers()) { - Kolab::Telephone p; - p.setNumber(toStdString(n.number())); - bool pref = false; - p.setTypes(fromPhoneType(n.type(), pref)); - prefCounter++; - if (pref) { - prefNum = prefCounter; - } - phones.push_back(p); - } - c.setTelephones(phones, prefNum); - - const QString &imAddress = addressee.custom(QLatin1String("KADDRESSBOOK"), QLatin1String("X-IMAddress")); - if (!imAddress.isEmpty()) { - c.setIMaddresses(std::vector<std::string>() << toStdString(imAddress), 0); - } - - int prefEmail = -1; - int count = 0; - std::vector<Kolab::Email> emails; - foreach(const QString &e, addressee.emails()) { - if ((prefEmail == -1) && (e == addressee.preferredEmail())) { - prefEmail = count; - } - count++; - emails.push_back(Kolab::Email(toStdString(e), emailTypesFromStringlist(addressee.custom(QLatin1String("KOLAB"), QString::fromLatin1("EmailTypes%1").arg(e))))); - } - c.setEmailAddresses(emails, prefEmail); - if (addressee.geo().isValid()) { - c.setGPSpos(std::vector<Kolab::Geo>() << Kolab::Geo(addressee.geo().latitude(), addressee.geo().longitude())); - } - - Kolab::Crypto crypto; - - const QStringList protocolPrefs = addressee.custom( "KADDRESSBOOK", "CRYPTOPROTOPREF" ).split( ',', QString::SkipEmptyParts ); - const uint cryptoFormats = stringListToCryptoMessageFormats( protocolPrefs ); - int formats = 0; - if (cryptoFormats & InlineOpenPGPFormat) { - formats |= Kolab::Crypto::PGPinline; - } - if (cryptoFormats & OpenPGPMIMEFormat) { - formats |= Kolab::Crypto::PGPmime; - } - if (cryptoFormats & SMIMEFormat) { - formats |= Kolab::Crypto::SMIME; - } - if (cryptoFormats & SMIMEOpaqueFormat) { - formats |= Kolab::Crypto::SMIMEopaque; - } - crypto.setAllowed(formats); - - Kolab::Crypto::CryptoPref signPref = Kolab::Crypto::Ask; - switch (stringToSigningPreference(addressee.custom( "KADDRESSBOOK", "CRYPTOSIGNPREF" ) )) { - case NeverSign: - signPref = Kolab::Crypto::Never; - break; - case AlwaysSign: - signPref = Kolab::Crypto::Always; - break; - case AlwaysSignIfPossible: - signPref = Kolab::Crypto::IfPossible; - break; - case AlwaysAskForSigning: - case AskSigningWheneverPossible: - signPref = Kolab::Crypto::Ask; - break; - default: - signPref = Kolab::Crypto::Ask; - } - crypto.setSignPref(signPref); - - Kolab::Crypto::CryptoPref encryptPref = Kolab::Crypto::Ask; - switch (stringToSigningPreference(addressee.custom( "KADDRESSBOOK", "CRYPTOENCRYPTPREF" ) )) { - case NeverEncrypt: - encryptPref = Kolab::Crypto::Never; - break; - case AlwaysEncrypt: - encryptPref = Kolab::Crypto::Always; - break; - case AlwaysEncryptIfPossible: - encryptPref = Kolab::Crypto::IfPossible; - break; - case AlwaysAskForEncryption: - case AskWheneverPossible: - encryptPref = Kolab::Crypto::Ask; - break; - default: - encryptPref = Kolab::Crypto::Ask; - } - crypto.setEncryptPref(encryptPref); - - c.setCrypto(crypto); - - - //FIXME the keys are most certainly worng, look at cryptopageplugin.cpp - std::vector<Kolab::Key> keys; - const std::string &pgpkey = toStdString(addressee.custom( "KADDRESSBOOK", "OPENPGPFP" )); - if (!pgpkey.empty()) { - keys.push_back(Kolab::Key(pgpkey, Kolab::Key::PGP)); - } - const std::string &smimekey = toStdString(addressee.custom( "KADDRESSBOOK", "SMIMEFP" )); - if (!smimekey.empty()) { - keys.push_back(Kolab::Key(smimekey, Kolab::Key::PKCS7_MIME)); - } - c.setKeys(keys); - - - if (!addressee.sound().isEmpty()) { - Warning() << "sound is not supported"; - } - - const std::string &profession = toStdString(addressee.custom( "KADDRESSBOOK", "X-Profession" )); - if (!profession.empty()) { - setCustom(profession, "X-Profession", c); - } - - const std::string &adrBook = toStdString(addressee.custom( "KADDRESSBOOK", "X-AddressBook" )); - if (!adrBook.empty()) { - setCustom(adrBook, "X-AddressBook", c); - } - - //TODO preserve all custom properties (also such which are unknown to us) - - return c; -} - -DistList fromKABC(const KABC::ContactGroup &cg) -{ - DistList dl; - dl.setName(toStdString(cg.name())); - dl.setUid(toStdString(cg.id())); - - std::vector <Kolab::ContactReference > members; - for (unsigned int i = 0; i < cg.dataCount(); i++) { - const KABC::ContactGroup::Data &data = cg.data(i); - members.push_back(Kolab::ContactReference(Kolab::ContactReference::EmailReference, toStdString(data.email()), toStdString(data.name()))); - } - for (unsigned int i = 0; i < cg.contactReferenceCount(); i++) { - const KABC::ContactGroup::ContactReference &ref = cg.contactReference(i); - members.push_back(Kolab::ContactReference(Kolab::ContactReference::UidReference, toStdString(ref.uid()))); - } - - if (cg.contactGroupReferenceCount() > 0) { - kWarning() << "Tried to save contact group references, which should have been resolved already"; - } - - dl.setMembers(members); - - return dl; -} - -KABC::ContactGroup toKABC(const DistList &dl) -{ - KABC::ContactGroup cg(fromStdString(dl.name())); - cg.setId(fromStdString(dl.uid())); - foreach(const Kolab::ContactReference &m, dl.members()) { - switch (m.type()) { - case Kolab::ContactReference::EmailReference: - cg.append(KABC::ContactGroup::Data(fromStdString(m.name()), fromStdString(m.email()))); - break; - case Kolab::ContactReference::UidReference: - cg.append(KABC::ContactGroup::ContactReference(fromStdString(m.uid()))); - break; - default: - Error() << "invalid contact reference"; - } - } - - return cg; -} - - - } //Namespace -} //Namespace
View file
libkolab-2.0.tar.gz/conversion/kabcconversion.h
Deleted
@@ -1,43 +0,0 @@ -/* - * Copyright (C) 2012 Christian Mollekopf <mollekopf@kolabsys.com> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. -*/ - -#ifndef KOLABKABCCONVERSION_H -#define KOLABKABCCONVERSION_H - -#include "kolab_export.h" - -#include <kolabcontact.h> -#include <kabc/addressee.h> -#include <kabc/contactgroup.h> - -namespace Kolab { - /** - * Conversion of Kolab-Containers to/from KABC Containers. - * - */ - namespace Conversion { - - KOLAB_EXPORT KABC::Addressee toKABC(const Kolab::Contact &); - KOLAB_EXPORT Kolab::Contact fromKABC(const KABC::Addressee &); - - KOLAB_EXPORT KABC::ContactGroup toKABC(const Kolab::DistList &); - KOLAB_EXPORT Kolab::DistList fromKABC(const KABC::ContactGroup &); - - }; -}; - -#endif
View file
libkolab-2.0.tar.gz/conversion/kolabconversion.cpp
Deleted
@@ -1,120 +0,0 @@ -/* - * Copyright (C) 2012 Christian Mollekopf <mollekopf@kolabsys.com> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - - -#include "kolabconversion.h" -#include "commonconversion.h" -#include <akonadi/notes/noteutils.h> - -namespace Kolab { - namespace Conversion { - -Note fromNote(const KMime::Message::Ptr &m) -{ - Akonadi::NoteUtils::NoteMessageWrapper note(m); - Note n; - n.setSummary(toStdString(note.title())); - n.setDescription(toStdString(note.text())); - KDateTime created = note.creationDate(); - created.setTimeSpec(KDateTime::UTC); - n.setCreated(fromDate(created)); - -// #if KDEPIMLIBS_VERSION >= 0x040840 -#ifdef KDEPIMLIBS_VERSION_DEVEL - n.setUid(toStdString(note.uid())); - KDateTime lastModified = note.lastModifiedDate(); - lastModified.setTimeSpec(KDateTime::UTC); - n.setLastModified(fromDate(lastModified)); - - switch (note.classification()) { - case Akonadi::NoteUtils::NoteMessageWrapper::Confidential: - n.setClassification(Kolab::ClassConfidential); - break; - case Akonadi::NoteUtils::NoteMessageWrapper::Private: - n.setClassification(Kolab::ClassPrivate); - break; - default: - n.setClassification(Kolab::ClassPublic); - } - - std::vector<Kolab::CustomProperty> customs; - QMap<QString, QString> &customsMap = note.custom(); - for (QMap <QString, QString >::const_iterator it = customsMap.constBegin(); it != customsMap.constEnd(); it ++) { - customs.push_back(Kolab::CustomProperty(toStdString(it.key()), toStdString(it.value()))); - } - n.setCustomProperties(customs); - - std::vector<Kolab::Attachment> attachments; - foreach(const Akonadi::NoteUtils::Attachment &a, note.attachments()) { - Kolab::Attachment attachment; - if (a.url().isValid()) { - attachment.setUri(toStdString(a.url().toString()), toStdString(a.mimetype())); - } else { - attachment.setData(toStdString(QString(a.data())), toStdString(a.mimetype())); - } - attachment.setLabel(toStdString(a.label())); - attachments.push_back(attachment); - } - n.setAttachments(attachments); - -#endif - return n; -} - -KMime::Message::Ptr toNote(const Note &n) -{ - Akonadi::NoteUtils::NoteMessageWrapper note; - note.setTitle(fromStdString(n.summary())); - note.setText(fromStdString(n.description())); - note.setFrom("kolab@kde4"); - note.setCreationDate(toDate(n.created())); -#ifdef KDEPIMLIBS_VERSION_DEVEL - note.setUid(fromStdString(n.uid())); - note.setLastModifiedDate(toDate(n.lastModified())); - switch (n.classification()) { - case Kolab::ClassPrivate: - note.setClassification(Akonadi::NoteUtils::NoteMessageWrapper::Private); - break; - case Kolab::ClassConfidential: - note.setClassification(Akonadi::NoteUtils::NoteMessageWrapper::Confidential); - break; - default: - note.setClassification(Akonadi::NoteUtils::NoteMessageWrapper::Public); - } - - foreach (const Kolab::Attachment &a, n.attachments()) { - if (!a.uri().empty()) { - Akonadi::NoteUtils::Attachment attachment(QUrl(fromStdString(a.uri())), fromStdString(a.mimetype())); - attachment.setLabel(fromStdString(a.label())); - note.attachments().append(attachment); - } else { - Akonadi::NoteUtils::Attachment attachment(fromStdString(a.data()).toLatin1(), fromStdString(a.mimetype())); - attachment.setLabel(fromStdString(a.label())); - note.attachments().append(attachment); - } - } - foreach (const Kolab::CustomProperty &a, n.customProperties()) { - note.custom().insert(fromStdString(a.identifier), fromStdString(a.value)); - } -#endif - return note.message(); -} - - - } -} -
View file
libkolab-2.0.tar.gz/conversion/kolabconversion.h
Deleted
@@ -1,39 +0,0 @@ -/* - * Copyright (C) 2012 Christian Mollekopf <mollekopf@kolabsys.com> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef KOLABCONVERSION_H -#define KOLABCONVERSION_H - -#include "kolab_export.h" - -#include <kolabnote.h> -#include <kmime/kmime_message.h> - -namespace Kolab { - /** - * Conversion of Kolab-Containers to/from KDE Containers. - * - */ - namespace Conversion { - - KOLAB_EXPORT KMime::Message::Ptr toNote(const Kolab::Note &); - KOLAB_EXPORT Kolab::Note fromNote(const KMime::Message::Ptr &); - - }; -}; - -#endif
View file
libkolab-2.0.tar.gz/freebusy
Deleted
-(directory)
View file
libkolab-2.0.tar.gz/freebusy/CMakeLists.txt
Deleted
@@ -1,3 +0,0 @@ -set (FREEBUSY_SRCS - ${CMAKE_CURRENT_SOURCE_DIR}/freebusy.cpp - PARENT_SCOPE)
View file
libkolab-2.0.tar.gz/freebusy/freebusy.cpp
Deleted
@@ -1,321 +0,0 @@ -/* - * Copyright (C) 2012 Christian Mollekopf <mollekopf@kolabsys.com> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - - -#include "freebusy.h" -#include "conversion/kcalconversion.h" -#include "conversion/commonconversion.h" -#include "libkolab-version.h" -#include <kcalcore/freebusy.h> -#include <kcalcore/icalformat.h> -#include <kdebug.h> -#include <quuid.h> - - -// namespace KCalCore { -// struct KCalFreebusy -// { -// -// void init( const Event::List &eventList, const KDateTime &start, const KDateTime &end ) -// { -// mDtStart = start.toUtc(); -// mDtEnd = end.toUtc(); -// -// // Loops through every event in the calendar -// Event::List::ConstIterator it; -// for ( it = eventList.constBegin(); it != eventList.constEnd(); ++it ) { -// Event::Ptr event = *it; -// -// // If this event is transparent it shouldn't be in the freebusy list. -// if ( event->transparency() == Event::Transparent ) { -// continue; -// } -// -// if ( event->hasRecurrenceId() ) { -// continue; //TODO apply special period exception (duration could be different) -// } -// -// const KDateTime eventStart = event->dtStart().toUtc(); -// const KDateTime eventEnd = event->dtEnd().toUtc(); -// -// if ( event->recurs() ) { -// const KCalCore::Duration duration( eventStart, eventEnd ); -// const KCalCore::DateTimeList list = event->recurrence()->timesInInterval(start, end); -// foreach (const KDateTime &dt, list) { -// const KDateTime utc = dt.toUtc(); -// addLocalPeriod(utc, duration.end(utc) ); -// } -// } else { -// addLocalPeriod( eventStart, eventEnd ); -// } -// } -// -// // q->sortList(); -// } -// -// bool addLocalPeriod( -// const KDateTime &eventStart, -// const KDateTime &eventEnd ) -// { -// KDateTime tmpStart; -// KDateTime tmpEnd; -// -// //Check to see if the start *or* end of the event is -// //between the start and end of the freebusy dates. -// if ( !( ( ( mDtStart.secsTo( eventStart ) >= 0 ) && -// ( eventStart.secsTo( mDtEnd ) >= 0 ) ) || -// ( ( mDtStart.secsTo( eventEnd ) >= 0 ) && -// ( eventEnd.secsTo( mDtEnd ) >= 0 ) ) ) ) { -// qDebug() << "out of scope"; -// return false; -// } -// -// // qDebug() << eventStart.date().toString() << eventStart.time().toString() << mDtStart.toString(); -// if ( eventStart < mDtStart ) { //eventStart is before start -// // qDebug() << "use start"; -// tmpStart = mDtStart; -// } else { -// tmpStart = eventStart; -// } -// -// qDebug() << eventEnd.date().toString() << eventEnd.time().toString() << mDtEnd.toString(); -// if ( eventEnd > mDtEnd ) { //event end is after dtEnd -// // qDebug() << "use end"; -// tmpEnd = mDtEnd; -// } else { -// tmpEnd = eventEnd; -// } -// -// // qDebug() << "########## " << tmpStart.isValid(); -// Q_ASSERT(tmpStart.isValid()); -// Q_ASSERT(tmpEnd.isValid()); -// // qDebug() << tmpStart.date().toString() << tmpStart.time().toString() << tmpStart.toString(); -// -// FreeBusyPeriod p( tmpStart, tmpEnd ); -// mBusyPeriods.append( p ); -// -// return true; -// } -// -// KDateTime mDtStart; -// KDateTime mDtEnd; // end datetime -// FreeBusyPeriod::List mBusyPeriods; // list of periods -// -// }; -// -// } // Namespace - - - - - - - -namespace Kolab { - namespace FreebusyUtils { - -static QString createUuid() -{ - const QString uuid = QUuid::createUuid().toString(); - return uuid.mid(1, uuid.size()-2); -} - -Kolab::Period addLocalPeriod( const KDateTime &eventStart, const KDateTime &eventEnd, const KDateTime &mDtStart, const KDateTime &mDtEnd) -{ - KDateTime tmpStart; - KDateTime tmpEnd; - - //Check to see if the start *or* end of the event is - //between the start and end of the freebusy dates. - if ( !( ( ( mDtStart <= eventStart) && - ( eventStart <= mDtEnd ) ) || - ( ( mDtStart <= eventEnd ) && - ( eventEnd <= mDtEnd ) ) ) ) { - qDebug() << "event is not within the fb range, skipping"; - return Kolab::Period(); - } - - if ( eventStart < mDtStart ) { //eventStart is before start - tmpStart = mDtStart; - } else { - tmpStart = eventStart; - } - -// qDebug() << eventEnd.date().toString() << eventEnd.time().toString() << mDtEnd.toString(); - if ( eventEnd > mDtEnd ) { //event end is after dtEnd - tmpEnd = mDtEnd; - } else { - tmpEnd = eventEnd; - } - Q_ASSERT(tmpStart.isValid()); - Q_ASSERT(tmpEnd.isValid()); - if (tmpStart.isDateOnly()) { - tmpStart.setTime(QTime(0,0,0,0)); - } - if (tmpEnd.isDateOnly()) { - tmpEnd.setTime(QTime(23,59,59,999)); //The window is inclusive - } - return Kolab::Period(Kolab::Conversion::fromDate(tmpStart), Kolab::Conversion::fromDate(tmpEnd)); -} - -Freebusy generateFreeBusy(const std::vector< Event >& events, const cDateTime& startDate, const cDateTime& endDate) -{ - QList<KCalCore::Event::Ptr> list; - foreach (const Kolab::Event &e, events) { - list.append(Kolab::Conversion::toKCalCore(e)); - } - KCalCore::Person::Ptr person(new KCalCore::Person("dummyname", "dummyemail")); - return generateFreeBusy(list, Kolab::Conversion::toDate(startDate), Kolab::Conversion::toDate(endDate), person); -} - -Freebusy generateFreeBusy(const QList<KCalCore::Event::Ptr>& events, const KDateTime& startDate, const KDateTime& endDate, const KCalCore::Person::Ptr &organizer) -{ - /* - * TODO the conversion of date-only values to date-time is only necessary because xCal doesn't allow date only. iCalendar doesn't seem to make this restriction so it looks like a bug. - */ - KDateTime start = startDate.toUtc(); - if (start.isDateOnly()) { - start.setTime(QTime(0,0,0,0)); - } - KDateTime end = endDate.toUtc(); - if (end.isDateOnly()) { - end.addDays(1); - end.setTime(QTime(0,0,0,0)); //The window is inclusive - } - - //TODO try to merge that with KCalCore::Freebusy - std::vector<Kolab::FreebusyPeriod> freebusyPeriods; - Q_FOREACH (KCalCore::Event::Ptr event, events) { - // If this event is transparent it shouldn't be in the freebusy list. - if ( event->transparency() == KCalCore::Event::Transparent ) { - continue; - } - - if ( event->hasRecurrenceId() ) { - continue; //TODO apply special period exception (duration could be different) - } - - const KDateTime eventStart = event->dtStart().toUtc(); - const KDateTime eventEnd = event->dtEnd().toUtc(); - - std::vector <Kolab::Period> periods; - if ( event->recurs() ) { - const KCalCore::Duration duration( eventStart, eventEnd ); - const KCalCore::DateTimeList list = event->recurrence()->timesInInterval(start, end); - Q_FOREACH (const KDateTime &dt, list) { - const KDateTime utc = dt.toUtc(); - const Kolab::Period &period = addLocalPeriod(utc, duration.end(utc), start, end); - if (period.isValid()) { - periods.push_back(period); - } - } - } else { - const Kolab::Period &period = addLocalPeriod(eventStart, eventEnd, start, end); - if (period.isValid()) { - periods.push_back(period); - } - } - if (!periods.empty()) { - Kolab::FreebusyPeriod period; - period.setPeriods(periods); - //TODO get busy type from event (out-of-office, tentative) - period.setType(Kolab::FreebusyPeriod::Busy); - period.setEvent(Kolab::Conversion::toStdString(event->uid()), Kolab::Conversion::toStdString(event->summary()), Kolab::Conversion::toStdString(event->location())); - freebusyPeriods.push_back(period); - } - } - - Kolab::Freebusy freebusy; - - freebusy.setStart(Kolab::Conversion::fromDate(start)); - freebusy.setEnd(Kolab::Conversion::fromDate(end)); - freebusy.setPeriods(freebusyPeriods); - freebusy.setUid(createUuid().toStdString()); - freebusy.setTimestamp(Kolab::Conversion::fromDate(KDateTime::currentUtcDateTime())); - if (organizer) { - freebusy.setOrganizer(ContactReference(Kolab::ContactReference::EmailReference, Kolab::Conversion::toStdString(organizer->email()), Kolab::Conversion::toStdString(organizer->name()))); - } - - return freebusy; -} - -Freebusy aggregateFreeBusy(const std::vector< Freebusy >& fbList, const std::string &organizerEmail, const std::string &organizerName, bool simple) -{ - std::vector <Kolab::FreebusyPeriod > periods; - - KDateTime start; - KDateTime end; - Q_FOREACH (const Freebusy &fb, fbList) { - - const KDateTime &tmpStart = Kolab::Conversion::toDate(fb.start()); - if (!start.isValid() || tmpStart < start) { - start = tmpStart; - } - const KDateTime &tmpEnd = Kolab::Conversion::toDate(fb.end()); - if (!end.isValid() || tmpEnd > end) { - end = tmpEnd; - } - - Q_FOREACH (const Kolab::FreebusyPeriod &period, fb.periods()) { - Kolab::FreebusyPeriod simplifiedPeriod; - simplifiedPeriod.setPeriods(period.periods()); - simplifiedPeriod.setType(period.type()); - if (!simple) { //Don't copy and reset to avoid unintentional information leaking into simple lists - simplifiedPeriod.setEvent(period.eventSummary(), period.eventUid(), period.eventLocation()); - } - periods.push_back(simplifiedPeriod); - } - } - - Freebusy aggregateFB; - - aggregateFB.setStart(Kolab::Conversion::fromDate(start)); - aggregateFB.setEnd(Kolab::Conversion::fromDate(end)); - aggregateFB.setPeriods(periods); - aggregateFB.setUid(createUuid().toStdString()); - aggregateFB.setTimestamp(Kolab::Conversion::fromDate(KDateTime::currentUtcDateTime())); - aggregateFB.setOrganizer(ContactReference(Kolab::ContactReference::EmailReference, organizerEmail, organizerName)); - return aggregateFB; -} - -std::string toIFB(const Kolab::Freebusy &freebusy) -{ - KCalCore::FreeBusy::Ptr fb(new KCalCore::FreeBusy(Kolab::Conversion::toDate(freebusy.start()), Kolab::Conversion::toDate(freebusy.end()))); - KCalCore::FreeBusyPeriod::List list; - Q_FOREACH (const Kolab::FreebusyPeriod &fbPeriod, freebusy.periods()) { - Q_FOREACH (const Kolab::Period &p, fbPeriod.periods()) { - KCalCore::FreeBusyPeriod period(Kolab::Conversion::toDate(p.start), Kolab::Conversion::toDate(p.end)); -// period.setSummary("summary"); Doesn't even work. X-SUMMARY is read though (just not written out) - //TODO - list.append(period); - - } - } - fb->addPeriods(list); - - fb->setUid(QString::fromStdString(freebusy.uid())); - fb->setOrganizer(KCalCore::Person::Ptr(new KCalCore::Person(Conversion::fromStdString(freebusy.organizer().name()), Conversion::fromStdString(freebusy.organizer().email())))); - fb->setLastModified(Kolab::Conversion::toDate(freebusy.timestamp())); - - KCalCore::ICalFormat format; - format.setApplication("libkolab", LIBKOLAB_LIB_VERSION_STRING); - QString data = format.createScheduleMessage( fb, KCalCore::iTIPPublish ); - return Conversion::toStdString(data); -} - - } -}
View file
libkolab-2.0.tar.gz/freebusy/freebusy.h
Deleted
@@ -1,39 +0,0 @@ -/* - * Copyright (C) 2012 Christian Mollekopf <mollekopf@kolabsys.com> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - - -#ifndef FREEBUSY_H -#define FREEBUSY_H - -#include "kolab_export.h" -#include <kolabevent.h> -#include <kolabfreebusy.h> -#include <kcalcore/event.h> - -namespace Kolab { - namespace FreebusyUtils { - -KOLAB_EXPORT Freebusy generateFreeBusy(const QList<KCalCore::Event::Ptr>& events, const KDateTime& startDate, const KDateTime& endDate, const KCalCore::Person::Ptr &organizer); -KOLAB_EXPORT std::string toIFB(const Kolab::Freebusy &); - -Kolab::Freebusy generateFreeBusy(const std::vector<Kolab::Event> &events, const Kolab::cDateTime &startDate, const Kolab::cDateTime &endDate); -KOLAB_EXPORT Kolab::Freebusy aggregateFreeBusy(const std::vector<Kolab::Freebusy> &fbs, const std::string &organizerEmail, const std::string &organizerName, bool simple = true); - - } -} - -#endif // FREEBUSY_H
View file
libkolab-2.0.tar.gz/icalendar
Deleted
-(directory)
View file
libkolab-2.0.tar.gz/icalendar/CMakeLists.txt
Deleted
@@ -1,15 +0,0 @@ - -set (ICALENDAR_SRCS - ${CMAKE_CURRENT_SOURCE_DIR}/icalendar.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/imip.cpp - PARENT_SCOPE) - -if(PYTHON_BINDINGS) - message("building python bindings") - add_subdirectory(python) -endif(PYTHON_BINDINGS) - -if(PHP_BINDINGS) - message("building php bindings") - add_subdirectory(php) -endif(PHP_BINDINGS)
View file
libkolab-2.0.tar.gz/icalendar/icalendar.cpp
Deleted
@@ -1,197 +0,0 @@ -/* - <one line to give the library's name and an idea of what it does.> - Copyright (C) 2012 Christian Mollekopf <chrigi_1@fastmail.fm> - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - - -#include "icalendar.h" -#include "imip.h" -#include "libkolab-version.h" -#include <conversion/kcalconversion.h> -#include <conversion/commonconversion.h> -#include <mime/mimeutils.h> -#include <kcalcore/event.h> -#include <kcalcore/memorycalendar.h> -#include <kcalcore/icalformat.h> -#include <kmime/kmime_message.h> -// #include <klocalizedstring.h> -#include <kdebug.h> -#include <iostream> - -namespace Kolab { - -std::string toICal(const std::vector<Event> &events) -{ - KCalCore::Calendar::Ptr calendar(new KCalCore::MemoryCalendar(Kolab::Conversion::getTimeSpec(true, std::string()))); - foreach (const Event &event, events) { - KCalCore::Event::Ptr kcalEvent = Conversion::toKCalCore(event); - if (!kcalEvent->created().isValid()) { - kcalEvent->setCreated(KDateTime::currentUtcDateTime()); //sets dtstamp - } - calendar->addEvent(kcalEvent); - foreach(const Event &exception, event.exceptions()) { - KCalCore::Event::Ptr kcalException = Conversion::toKCalCore(exception); - if (!kcalException->created().isValid()) { - kcalException->setCreated(KDateTime::currentUtcDateTime()); //sets dtstamp - } - calendar->addEvent(kcalException); - } - } - KCalCore::ICalFormat format; - format.setApplication("libkolab", LIBKOLAB_LIB_VERSION_STRING); -// qDebug() << format.createScheduleMessage(calendar->events().first(), KCalCore::iTIPRequest); - return Conversion::toStdString(format.toString(calendar)); - -} - -std::vector< Event > fromICalEvents(const std::string &input) -{ - KCalCore::Calendar::Ptr calendar(new KCalCore::MemoryCalendar(Kolab::Conversion::getTimeSpec(true, std::string()))); - KCalCore::ICalFormat format; - format.setApplication("libkolab", LIBKOLAB_LIB_VERSION_STRING); - format.fromString(calendar, Conversion::fromStdString(input)); - std::vector<Event> events; - QMap< QString, int > uidMap; - foreach (const KCalCore::Event::Ptr &event, calendar->events()) { - Event e = Conversion::fromKCalCore(*event); - if (!e.recurrenceID().isValid()) { - if (uidMap.contains(event->uid())) { - e.setExceptions(events.at(uidMap[event->uid()]).exceptions()); - events[uidMap[event->uid()]] = e; - } else { - events.push_back(e); - uidMap.insert(event->uid(), events.size()-1); - } - } else { - if (!uidMap.contains(event->uid())) { - Event e; - e.setUid(""); - events.push_back(e); - uidMap.insert(event->uid(), events.size()-1); - } - std::vector<Event> exceptions = events.at( uidMap[event->uid()]).exceptions(); - exceptions.push_back(e); - events.at(uidMap[event->uid()]).setExceptions(exceptions); - } - } - return events; -} - -ITipHandler::ITipHandler() -: mMethod(iTIPNoMethod) -{ -} - - -ITipHandler::ITipMethod mapFromKCalCore(KCalCore::iTIPMethod method) -{ - Q_ASSERT((int)KCalCore::iTIPPublish == (int)ITipHandler::iTIPPublish); - Q_ASSERT((int)KCalCore::iTIPNoMethod == (int)ITipHandler::iTIPNoMethod); - return static_cast<ITipHandler::ITipMethod>(method); -} - -KCalCore::iTIPMethod mapToKCalCore(ITipHandler::ITipMethod method) -{ - Q_ASSERT((int)KCalCore::iTIPPublish == (int)ITipHandler::iTIPPublish); - Q_ASSERT((int)KCalCore::iTIPNoMethod == (int)ITipHandler::iTIPNoMethod); - return static_cast<KCalCore::iTIPMethod>(method); -} - - -std::string ITipHandler::toITip(const Event &event, ITipHandler::ITipMethod method) const -{ - KCalCore::ICalFormat format; - format.setApplication("libkolab", LIBKOLAB_LIB_VERSION_STRING); - KCalCore::iTIPMethod m = mapToKCalCore(method); - if (m == KCalCore::iTIPNoMethod) { - return std::string(); - } -// kDebug() << event.start(). -/* TODO - * DTSTAMP is created - * CREATED is current timestamp - * LASTMODIFIED is lastModified - * - * Double check if that is correct. - * - * I think DTSTAMP should be the current timestamp, and CREATED should be the creation date. - */ - KCalCore::Event::Ptr e = Conversion::toKCalCore(event); - return Conversion::toStdString(format.createScheduleMessage(e, m)); -} - - -std::vector< Event > ITipHandler::fromITip(const std::string &string) -{ - KCalCore::Calendar::Ptr calendar(new KCalCore::MemoryCalendar(KDateTime::Spec(KDateTime::UTC))); - KCalCore::ICalFormat format; - KCalCore::ScheduleMessage::Ptr msg= format.parseScheduleMessage(calendar, Conversion::fromStdString(string)); - KCalCore::Event::Ptr event = msg->event().dynamicCast<KCalCore::Event>(); - std::vector< Event > events; - events.push_back(Conversion::fromKCalCore(*event)); - mMethod = mapFromKCalCore(msg->method()); - return events; -} - -ITipHandler::ITipMethod ITipHandler::method() const -{ - return mMethod; -} - -std::string ITipHandler::toIMip(const Event &event , ITipHandler::ITipMethod m, std::string from, bool bccMe) const -{ - KCalCore::Event::Ptr e = Conversion::toKCalCore(event); -// e->recurrence()->addRDateTime(e->dtStart()); //FIXME The createScheduleMessage converts everything to utc without a recurrence. - KCalCore::ICalFormat format; - format.setApplication("libkolab", LIBKOLAB_LIB_VERSION_STRING); - KCalCore::iTIPMethod method = mapToKCalCore(m); - const QString &messageText = format.createScheduleMessage( e, method ); - //This code is mostly from MailScheduler::performTransaction - if ( method == KCalCore::iTIPRequest || - method == KCalCore::iTIPCancel || - method == KCalCore::iTIPAdd || - method == KCalCore::iTIPDeclineCounter ) { - return Conversion::toStdString(QString(mailAttendees(e, bccMe, messageText))); - } else { - QString subject; - if ( e && method == KCalCore::iTIPCounter ) { - subject = QString( "Counter proposal: %1" ).arg(e->summary()); - } - return Conversion::toStdString(QString(mailOrganizer( e, Conversion::fromStdString(from), bccMe, messageText, subject))); - } - return std::string(); -} - -std::vector< Event > ITipHandler::fromIMip(const std::string &input) -{ - KMime::Message::Ptr msg = KMime::Message::Ptr(new KMime::Message); - msg->setContent( Conversion::fromStdString(input).toUtf8() ); - msg->parse(); - msg->content(KMime::ContentIndex()); - - KMime::Content *c = Kolab::Mime::findContentByType(msg, "text/calendar"); - if (!c) { - qWarning() << "could not find text/calendar part"; - return std::vector< Event >(); - } - return fromITip(Conversion::toStdString(QString(c->decodedContent()))); -} - - - - -}
View file
libkolab-2.0.tar.gz/icalendar/icalendar.h
Deleted
@@ -1,80 +0,0 @@ -/* - <one line to give the library's name and an idea of what it does.> - Copyright (C) 2012 Christian Mollekopf <chrigi_1@fastmail.fm> - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - - -#ifndef ICALENDAR_H -#define ICALENDAR_H - -#ifndef SWIG -#include "kolab_export.h" -#else -/* No export/import SWIG interface files */ -#define KOLAB_EXPORT -#endif - -#include <kolabevent.h> - -namespace Kolab { - - /** - * Takes a list of events and writes them to an iCal object. - * - */ - KOLAB_EXPORT std::string toICal(const std::vector<Kolab::Event> &); - /** - * Takes an iCal object and returns the contained events. - */ - KOLAB_EXPORT std::vector<Kolab::Event> fromICalEvents(const std::string &); - - class KOLAB_EXPORT ITipHandler { - public: - ITipHandler(); - enum ITipMethod { - iTIPPublish, /**< Event, to-do, journal or freebusy posting */ - iTIPRequest, /**< Event, to-do or freebusy scheduling request */ - iTIPReply, /**< Event, to-do or freebusy reply to request */ - iTIPAdd, /**< Event, to-do or journal additional property request */ - iTIPCancel, /**< Event, to-do or journal cancellation notice */ - iTIPRefresh, /**< Event or to-do description update request */ - iTIPCounter, /**< Event or to-do submit counter proposal */ - iTIPDeclineCounter,/**< Event or to-do decline a counter proposal */ - iTIPNoMethod /**< No method */ - }; - - std::string toIMip(const Kolab::Event &, ITipMethod, std::string from, bool bbcMe = false) const; - std::vector<Kolab::Event> fromIMip(const std::string &); - - /** - * Create iTip message from single event - */ - std::string toITip(const Kolab::Event &, ITipMethod) const; - - /** - * Parse iTip message with a single event - */ - std::vector<Kolab::Event> fromITip(const std::string &); - ITipMethod method() const; - private: - ITipMethod mMethod; - }; - - -} - -#endif // ICALENDAR_H
View file
libkolab-2.0.tar.gz/icalendar/icalendar.i
Deleted
@@ -1,13 +0,0 @@ -%{ - /* This macro ensures that return vectors remain a vector also in python and are not converted to tuples */ - #define SWIG_PYTHON_EXTRA_NATIVE_CONTAINERS - - #include "icalendar.h" -%} - -%include "std_string.i" - -%import(module="kolabformat") <kolabevent.h> -%import "../shared.i" - -%include "icalendar.h" \ No newline at end of file
View file
libkolab-2.0.tar.gz/icalendar/imip.cpp
Deleted
@@ -1,239 +0,0 @@ -/* - <one line to give the library's name and an idea of what it does.> - Copyright (C) 2012 Christian Mollekopf <chrigi_1@fastmail.fm> - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - - -#include "imip.h" - -#include <kcalutils/incidenceformatter.h> -#include <kpimutils/email.h> -#include <kmime/kmime_message.h> -#include <QDebug> -// #include <klocalizedstring.h> -#include <ksystemtimezone.h> -#include <kdebug.h> - -/* - * The code in here is copy paste work from kdepim/calendarsupport. - * - * We need to refactor the code there and move the relevant parts to kdepimlibs to make it reusable. - * - * - */ - -//From MailClient::send -KMime::Message::Ptr createMessage( const QString &from, const QString &_to, - const QString &cc, const QString &subject, - const QString &body, bool hidden, bool bccMe, - const QString &attachment/*, const QString &mailTransport */) -{ - Q_UNUSED( hidden ); - - const bool outlookConformInvitation = false; - QString userAgent = "libkolab"; - - // We must have a recipients list for most MUAs. Thus, if the 'to' list - // is empty simply use the 'from' address as the recipient. - QString to = _to; - if ( to.isEmpty() ) { - to = from; - } - kDebug() << "\nFrom:" << from - << "\nTo:" << to - << "\nCC:" << cc - << "\nSubject:" << subject << "\nBody: \n" << body - << "\nAttachment:\n" << attachment - /*<< "\nmailTransport: " << mailTransport*/; - - // Now build the message we like to send. The message KMime::Message::Ptr instance - // will be the root message that has 2 additional message. The body itself and - // the attached cal.ics calendar file. - KMime::Message::Ptr message = KMime::Message::Ptr( new KMime::Message ); - message->contentTransferEncoding()->clear(); // 7Bit, decoded. - - // Set the headers - message->userAgent()->fromUnicodeString(userAgent, "utf-8" ); - message->from()->fromUnicodeString( from, "utf-8" ); - message->to()->fromUnicodeString( to, "utf-8" ); - message->cc()->fromUnicodeString( cc, "utf-8" ); - if( bccMe ) { - message->bcc()->fromUnicodeString( from, "utf-8" ); //from==me, right? - } - message->date()->setDateTime( KDateTime::currentLocalDateTime() ); - message->subject()->fromUnicodeString( subject, "utf-8" ); - - if ( outlookConformInvitation ) { - message->contentType()->setMimeType( "text/calendar" ); - message->contentType()->setCharset( "utf-8" ); - message->contentType()->setName( QLatin1String( "cal.ics" ), "utf-8" ); - message->contentType()->setParameter( QLatin1String( "method" ), QLatin1String( "request" ) ); - - if ( !attachment.isEmpty() ) { - KMime::Headers::ContentDisposition *disposition = - new KMime::Headers::ContentDisposition( message.get() ); - disposition->setDisposition( KMime::Headers::CDinline ); - message->setHeader( disposition ); - message->contentTransferEncoding()->setEncoding( KMime::Headers::CEquPr ); - message->setBody( KMime::CRLFtoLF( attachment.toUtf8() ) ); - } - } else { - // We need to set following 4 lines by hand else KMime::Content::addContent - // will create a new Content instance for us to attach the main message - // what we don't need cause we already have the main message instance where - // 2 additional messages are attached. - KMime::Headers::ContentType *ct = message->contentType(); - ct->setMimeType( "multipart/mixed" ); - ct->setBoundary( KMime::multiPartBoundary() ); - ct->setCategory( KMime::Headers::CCcontainer ); - - // Set the first multipart, the body message. - KMime::Content *bodyMessage = new KMime::Content; - KMime::Headers::ContentDisposition *bodyDisposition = - new KMime::Headers::ContentDisposition( bodyMessage ); - bodyDisposition->setDisposition( KMime::Headers::CDinline ); - bodyMessage->contentType()->setMimeType( "text/plain" ); - bodyMessage->contentType()->setCharset( "utf-8" ); - bodyMessage->contentTransferEncoding()->setEncoding( KMime::Headers::CEquPr ); - bodyMessage->setBody( KMime::CRLFtoLF( body.toUtf8() ) ); - message->addContent( bodyMessage ); - - // Set the sedcond multipart, the attachment. - if ( !attachment.isEmpty() ) { - KMime::Content *attachMessage = new KMime::Content; - KMime::Headers::ContentDisposition *attachDisposition = - new KMime::Headers::ContentDisposition( attachMessage ); - attachDisposition->setDisposition( KMime::Headers::CDattachment ); - attachMessage->contentType()->setMimeType( "text/calendar" ); - attachMessage->contentType()->setCharset( "utf-8" ); - attachMessage->contentType()->setName( QLatin1String( "cal.ics" ), "utf-8" ); - attachMessage->contentType()->setParameter( QLatin1String( "method" ), - QLatin1String( "request" ) ); - attachMessage->setHeader( attachDisposition ); - attachMessage->contentTransferEncoding()->setEncoding( KMime::Headers::CEquPr ); - attachMessage->setBody( KMime::CRLFtoLF( attachment.toUtf8() ) ); - message->addContent( attachMessage ); - } - } - - // Job done, attach the both multiparts and assemble the message. - message->assemble(); - return message; -} - -//From MailClient::mailAttendees -QByteArray mailAttendees( const KCalCore::IncidenceBase::Ptr &incidence, -// const KPIMIdentities::Identity &identity, - bool bccMe, const QString &attachment - /*const QString &mailTransport */) -{ - KCalCore::Attendee::List attendees = incidence->attendees(); - if ( attendees.isEmpty() ) { - kWarning() << "There are no attendees to e-mail"; - return QByteArray(); - } - - const QString from = incidence->organizer()->fullName(); - const QString organizerEmail = incidence->organizer()->email(); - - QStringList toList; - QStringList ccList; - const int numberOfAttendees( attendees.count() ); - for ( int i=0; i<numberOfAttendees; ++i ) { - KCalCore::Attendee::Ptr a = attendees.at(i); - - const QString email = a->email(); - if ( email.isEmpty() ) { - continue; - } - - // In case we (as one of our identities) are the organizer we are sending - // this mail. We could also have added ourselves as an attendee, in which - // case we don't want to send ourselves a notification mail. - if ( organizerEmail == email ) { - continue; - } - - // Build a nice address for this attendee including the CN. - QString tname, temail; - const QString username = KPIMUtils::quoteNameIfNecessary( a->name() ); - // ignore the return value from extractEmailAddressAndName() because - // it will always be false since tusername does not contain "@domain". - KPIMUtils::extractEmailAddressAndName( username, temail/*byref*/, tname/*byref*/ ); - tname += QLatin1String( " <" ) + email + QLatin1Char( '>' ); - - // Optional Participants and Non-Participants are copied on the email - if ( a->role() == KCalCore::Attendee::OptParticipant || - a->role() == KCalCore::Attendee::NonParticipant ) { - ccList << tname; - } else { - toList << tname; - } - } - if( toList.isEmpty() && ccList.isEmpty() ) { - // Not really to be called a groupware meeting, eh - kWarning() << "There are really no attendees to e-mail"; - return QByteArray(); - } - QString to; - if ( !toList.isEmpty() ) { - to = toList.join( QLatin1String( ", " ) ); - } - QString cc; - if ( !ccList.isEmpty() ) { - cc = ccList.join( QLatin1String( ", " ) ); - } - - QString subject; - if ( incidence->type() != KCalCore::Incidence::TypeFreeBusy ) { - KCalCore::Incidence::Ptr inc = incidence.staticCast<KCalCore::Incidence>(); - subject = inc->summary(); - } else { - subject = QString( "Free Busy Object" ); - } - - const QString body = - KCalUtils::IncidenceFormatter::mailBodyStr( incidence, KSystemTimeZones::local() ); - - return createMessage(/* identity, */from, to, cc, subject, body, false, - bccMe, attachment/*, mailTransport */)->encodedContent(); -} - -QByteArray mailOrganizer( const KCalCore::IncidenceBase::Ptr &incidence, -// const KPIMIdentities::Identity &identity, - const QString &from, bool bccMe, - const QString &attachment, - const QString &sub/*, const QString &mailTransport*/ ) -{ - const QString to = incidence->organizer()->fullName(); - QString subject = sub; - - if ( incidence->type() != KCalCore::Incidence::TypeFreeBusy ) { - KCalCore::Incidence::Ptr inc = incidence.staticCast<KCalCore::Incidence>(); - if ( subject.isEmpty() ) { - subject = inc->summary(); - } - } else { - subject = QString( "Free Busy Message" ); - } - - QString body = KCalUtils::IncidenceFormatter::mailBodyStr( incidence, KSystemTimeZones::local() ); - - return createMessage( /*identity, */from, to, QString(), subject, body, false, - bccMe, attachment/*, mailTransport */)->encodedContent(); -} -
View file
libkolab-2.0.tar.gz/icalendar/imip.h
Deleted
@@ -1,34 +0,0 @@ -/* - <one line to give the library's name and an idea of what it does.> - Copyright (C) 2012 Christian Mollekopf <chrigi_1@fastmail.fm> - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - - -#ifndef IMIP_H -#define IMIP_H -#include <QByteArray> -#include <kcalcore/incidencebase.h> - -QByteArray mailAttendees( const KCalCore::IncidenceBase::Ptr &incidence, - bool bccMe, const QString &attachment ); - -QByteArray mailOrganizer( const KCalCore::IncidenceBase::Ptr &incidence, - const QString &from, bool bccMe, - const QString &attachment, - const QString &sub ); - -#endif // IMIP_H
View file
libkolab-2.0.tar.gz/icalendar/php
Deleted
-(directory)
View file
libkolab-2.0.tar.gz/icalendar/php/CMakeLists.txt
Deleted
@@ -1,4 +0,0 @@ -#Generate PHP wrapper -include_directories(../) -include(SWIGUtils) -generatePHPBindings(kolabicalendar ../icalendar.i)
View file
libkolab-2.0.tar.gz/icalendar/python
Deleted
-(directory)
View file
libkolab-2.0.tar.gz/icalendar/python/CMakeLists.txt
Deleted
@@ -1,3 +0,0 @@ -include_directories(../) -include(SWIGUtils) -generatePythonBindings(icalendar ../icalendar.i)
View file
libkolab-2.0.tar.gz/kolabformat/kolabobject.cpp
Deleted
@@ -1,858 +0,0 @@ -/* - * Copyright (C) 2012 Christian Mollekopf <mollekopf@kolabsys.com> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - - -#include "kolabobject.h" -#include "v2helpers.h" -#include "kolabdefinitions.h" -#include "errorhandler.h" -#include "libkolab-version.h" - -#include <kolabbase.h> -#include <kolabformatV2/journal.h> -#include <kolabformatV2/task.h> -#include <kolabformatV2/event.h> -#include <kolabformatV2/contact.h> -#include <kolabformatV2/distributionlist.h> -#include <kolabformatV2/note.h> -#include <mime/mimeutils.h> -#include <conversion/kcalconversion.h> -#include <conversion/kabcconversion.h> -#include <conversion/kolabconversion.h> -#include <conversion/commonconversion.h> -#include <akonadi/notes/noteutils.h> -#include <kolabformat.h> - - -namespace Kolab { - - -static inline QString eventKolabType() { return QString::fromLatin1(KOLAB_TYPE_EVENT); }; -static inline QString todoKolabType() { return QString::fromLatin1(KOLAB_TYPE_TASK); }; -static inline QString journalKolabType() { return QString::fromLatin1(KOLAB_TYPE_JOURNAL); }; -static inline QString contactKolabType() { return QString::fromLatin1(KOLAB_TYPE_CONTACT); }; -static inline QString distlistKolabType() { return QString::fromLatin1(KOLAB_TYPE_DISTLIST); } -static inline QString distlistKolabTypeCompat() { return QString::fromLatin1(KOLAB_TYPE_DISTLIST_V2); } -static inline QString noteKolabType() { return QString::fromLatin1(KOLAB_TYPE_NOTE); } -static inline QString configurationKolabType() { return QString::fromLatin1(KOLAB_TYPE_CONFIGURATION); } -static inline QString dictKolabType() { return QString::fromLatin1(KOLAB_TYPE_DICT); } -static inline QString freebusyKolabType() { return QString::fromLatin1(KOLAB_TYPE_FREEBUSY); } -static inline QString relationKolabType() { return QString::fromLatin1(KOLAB_TYPE_RELATION); } - -static inline QString xCalMimeType() { return QString::fromLatin1(MIME_TYPE_XCAL); }; -static inline QString xCardMimeType() { return QString::fromLatin1(MIME_TYPE_XCARD); }; -static inline QString kolabMimeType() { return QString::fromLatin1(MIME_TYPE_KOLAB); }; - -KCalCore::Event::Ptr readV2EventXML(const QByteArray& xmlData, QStringList& attachments) -{ - return fromXML<KCalCore::Event::Ptr, KolabV2::Event>(xmlData, attachments); -} - -QString ownUrlDecode(QByteArray encodedParam) -{ - encodedParam.replace('+', ' '); - return QUrl::fromPercentEncoding(encodedParam); -} - -RelationMember parseMemberUrl(const QString &string) -{ - if (string.startsWith("urn:uuid:")) { - RelationMember member; - member.gid = string.mid(9); - return member; - } - QUrl url(QUrl::fromEncoded(string.toLatin1())); - QList<QByteArray> path; - Q_FOREACH(const QByteArray &fragment, url.encodedPath().split('/')) { - path.append(ownUrlDecode(fragment).toUtf8()); - } - // qDebug() << path; - bool isShared = false; - int start = path.indexOf("user"); - if (start < 0) { - start = path.indexOf("shared"); - isShared = true; - } - if (start < 0) { - Warning() << "Couldn't find \"user\" or \"shared\" in path: " << path; - return RelationMember(); - } - path = path.mid(start + 1); - if (path.size() < 2) { - Warning() << "Incomplete path: " << path; - return RelationMember(); - } - RelationMember member; - if (!isShared) { - member.user = path.takeFirst(); - } - member.uid = path.takeLast().toLong(); - member.mailbox = path; - member.messageId = ownUrlDecode(url.encodedQueryItemValue("message-id")); - member.subject = ownUrlDecode(url.encodedQueryItemValue("subject")); - member.date = ownUrlDecode(url.encodedQueryItemValue("date")); - // qDebug() << member.uid << member.mailbox; - return member; -} - -static QByteArray join(const QList<QByteArray> &list, const QByteArray &c) -{ - QByteArray result; - Q_FOREACH (const QByteArray &a, list) { - result += a + c; - } - result.chop(c.size()); - return result; -} - -QString generateMemberUrl(const RelationMember &member) -{ - if (!member.gid.isEmpty()) { - return QString("urn:uuid:%1").arg(member.gid); - } - QUrl url; - url.setScheme("imap"); - QList<QByteArray> path; - path << "/"; - if (!member.user.isEmpty()) { - path << "user"; - path << QUrl::toPercentEncoding(member.user.toLatin1()); - } else { - path << "shared"; - } - Q_FOREACH(const QByteArray &mb, member.mailbox) { - path << QUrl::toPercentEncoding(mb); - } - path << QByteArray::number(member.uid); - url.setEncodedPath("/" + join(path, "/")); - - QList<QPair<QByteArray, QByteArray> > queryItems; - queryItems.append(qMakePair(QString::fromLatin1("message-id").toLatin1(), QUrl::toPercentEncoding(member.messageId))); - queryItems.append(qMakePair(QString::fromLatin1("subject").toLatin1(), QUrl::toPercentEncoding(member.subject))); - queryItems.append(qMakePair(QString::fromLatin1("date").toLatin1(), QUrl::toPercentEncoding(member.date))); - url.setEncodedQueryItems(queryItems); - - return QString::fromLatin1(url.toEncoded()); -} - -//@cond PRIVATE -class KolabObjectReader::Private -{ -public: - Private() - : mObjectType( InvalidObject ), - mVersion( KolabV3 ), - mOverrideObjectType(InvalidObject), - mDoOverrideVersion(false) - { - mAddressee = KABC::Addressee(); - } - - ObjectType readKolabV2(const KMime::Message::Ptr &msg, Kolab::ObjectType objectType); - ObjectType readKolabV3(const KMime::Message::Ptr &msg, Kolab::ObjectType objectType); - - KCalCore::Incidence::Ptr mIncidence; - KABC::Addressee mAddressee; - KABC::ContactGroup mContactGroup; - KMime::Message::Ptr mNote; - QStringList mDictionary; - QString mDictionaryLanguage; - ObjectType mObjectType; - Version mVersion; - Kolab::Freebusy mFreebusy; - ObjectType mOverrideObjectType; - Version mOverrideVersion; - bool mDoOverrideVersion; - -#ifdef HAVE_RELATION_H - Akonadi::Relation mRelation; -#endif -#ifdef HAVE_TAG_H - Akonadi::Tag mTag; - QStringList mTagMembers; -#endif -}; -//@endcond - -KolabObjectReader::KolabObjectReader() -: d( new KolabObjectReader::Private ) -{ -} - -KolabObjectReader::KolabObjectReader(const KMime::Message::Ptr& msg) -: d( new KolabObjectReader::Private ) -{ - parseMimeMessage(msg); -} - -KolabObjectReader::~KolabObjectReader() -{ - delete d; -} - -void KolabObjectReader::setObjectType(ObjectType type) -{ - d->mOverrideObjectType = type; -} - -void KolabObjectReader::setVersion(Version version) -{ - d->mOverrideVersion = version; - d->mDoOverrideVersion = true; -} - -Kolab::ObjectType getObjectType(const QString &type) -{ - if (type == eventKolabType()) { - return EventObject; - } else if (type == todoKolabType()) { - return TodoObject; - } else if (type == journalKolabType()) { - return JournalObject; - } else if (type == contactKolabType()) { - return ContactObject; - } else if (type == distlistKolabType() || type == distlistKolabTypeCompat()) { - return DistlistObject; - } else if (type == noteKolabType()) { - return NoteObject; - } else if (type == freebusyKolabType()) { - return FreebusyObject; - } else if (type.contains(dictKolabType())) { //Previous versions appended the language to the type - return DictionaryConfigurationObject; - } else if (type == relationKolabType()) { - return RelationConfigurationObject; - } - Warning() << "Unknown object type: " << type; - return Kolab::InvalidObject; -} - -QByteArray getTypeString(Kolab::ObjectType type) -{ - switch (type) { - case EventObject: - return KOLAB_TYPE_EVENT; - case TodoObject: - return KOLAB_TYPE_TASK; - case JournalObject: - return KOLAB_TYPE_JOURNAL; - case FreebusyObject: - return KOLAB_TYPE_FREEBUSY; - case ContactObject: - return KOLAB_TYPE_CONTACT; - case DistlistObject: - return KOLAB_TYPE_DISTLIST; - case NoteObject: - return KOLAB_TYPE_NOTE; - case DictionaryConfigurationObject: - return KOLAB_TYPE_CONFIGURATION; - case RelationConfigurationObject: - return KOLAB_TYPE_RELATION; - default: - Critical() << "unknown type "<< type; - } - return QByteArray(); -} - -QByteArray getMimeType(Kolab::ObjectType type) -{ - switch (type) { - case EventObject: - case TodoObject: - case JournalObject: - case FreebusyObject: - return MIME_TYPE_XCAL; - case ContactObject: - case DistlistObject: - return MIME_TYPE_XCARD; - case NoteObject: - case DictionaryConfigurationObject: - case RelationConfigurationObject: - return MIME_TYPE_KOLAB; - default: - Critical() << "unknown type "<< type; - } - return QByteArray(); -} - -Kolab::ObjectType detectType(const KMime::Message::Ptr &msg) -{ - Q_FOREACH(const QByteArray &type, Mime::getContentMimeTypeList(msg)) { - Kolab::ObjectType t = getObjectType(type); //works for v2 types - if (t != InvalidObject) { - return t; - } - } - return InvalidObject; -} - -void printMessageDebugInfo(const KMime::Message::Ptr &msg) -{ - //TODO replace by Debug stream for Mimemessage - Debug() << "MessageId: " << msg->messageID()->asUnicodeString(); - Debug() << "Subject: " << msg->subject()->asUnicodeString(); -// Debug() << msg->encodedContent(); -} - -ObjectType KolabObjectReader::Private::readKolabV2(const KMime::Message::Ptr &msg, Kolab::ObjectType objectType) -{ - if (objectType == DictionaryConfigurationObject) { - KMime::Content *xmlContent = Mime::findContentByType( msg, "application/xml" ); - if ( !xmlContent ) { - Critical() << "no application/xml part found"; - printMessageDebugInfo(msg); - return InvalidObject; - } - const QByteArray &xmlData = xmlContent->decodedContent(); - mDictionary = readLegacyDictionaryConfiguration(xmlData, mDictionaryLanguage); - mObjectType = objectType; - return mObjectType; - } - KMime::Content *xmlContent = Mime::findContentByType( msg, getTypeString(objectType) ); - if ( !xmlContent ) { - Critical() << "no part with type" << getTypeString(objectType) << " found"; - printMessageDebugInfo(msg); - return InvalidObject; - } - const QByteArray &xmlData = xmlContent->decodedContent(); - Q_ASSERT(!xmlData.isEmpty()); - QStringList attachments; - - switch (objectType) { - case EventObject: - mIncidence = fromXML<KCalCore::Event::Ptr, KolabV2::Event>(xmlData, attachments); - break; - case TodoObject: - mIncidence = fromXML<KCalCore::Todo::Ptr, KolabV2::Task>(xmlData, attachments); - break; - case JournalObject: - mIncidence = fromXML<KCalCore::Journal::Ptr, KolabV2::Journal>(xmlData, attachments); - break; - case ContactObject: - mAddressee = addresseeFromKolab(xmlData, msg); - break; - case DistlistObject: - mContactGroup = contactGroupFromKolab(xmlData); - break; - case NoteObject: - mNote = noteFromKolab(xmlData, msg->date()->dateTime()); - break; - default: - CRITICAL("no kolab object found "); - break; - } - if (!mIncidence.isNull()) { -// kDebug() << "v2 attachments " << attachments.size() << d->mIncidence->attachments().size(); - mIncidence->clearAttachments(); - Mime::getAttachments(mIncidence, attachments, msg); - if (mIncidence->attachments().size() != attachments.size()) { - Error() << "Could not extract all attachments. " << mIncidence->attachments().size() << " out of " << attachments.size(); - } - } - if (ErrorHandler::errorOccured()) { - printMessageDebugInfo(msg); - return InvalidObject; - } - mObjectType = objectType; - return mObjectType; -} - -ObjectType KolabObjectReader::Private::readKolabV3(const KMime::Message::Ptr &msg, Kolab::ObjectType objectType) -{ - KMime::Content * const xmlContent = Mime::findContentByType( msg, getMimeType(objectType) ); - if ( !xmlContent ) { - Critical() << "no " << getMimeType(objectType) << " part found"; - printMessageDebugInfo(msg); - return InvalidObject; - } - const QByteArray &content = xmlContent->decodedContent(); - const std::string xml = std::string(content.data(), content.size()); - switch (objectType) { - case EventObject: { - const Kolab::Event & event = Kolab::readEvent(xml, false); - mIncidence = Kolab::Conversion::toKCalCore(event); - } - break; - case TodoObject: { - const Kolab::Todo & event = Kolab::readTodo(xml, false); - mIncidence = Kolab::Conversion::toKCalCore(event); - } - break; - case JournalObject: { - const Kolab::Journal & event = Kolab::readJournal(xml, false); - mIncidence = Kolab::Conversion::toKCalCore(event); - } - break; - case ContactObject: { - const Kolab::Contact &contact = Kolab::readContact(xml, false); - mAddressee = Kolab::Conversion::toKABC(contact); //TODO extract attachments - } - break; - case DistlistObject: { - const Kolab::DistList &distlist = Kolab::readDistlist(xml, false); - mContactGroup = Kolab::Conversion::toKABC(distlist); - } - break; - case NoteObject: { - const Kolab::Note ¬e = Kolab::readNote(xml, false); - mNote = Kolab::Conversion::toNote(note); - } - break; - case DictionaryConfigurationObject: { - const Kolab::Configuration &configuration = Kolab::readConfiguration(xml, false); - const Kolab::Dictionary &dictionary = configuration.dictionary(); - mDictionary.clear(); - foreach (const std::string &entry, dictionary.entries()) { - mDictionary.append(Conversion::fromStdString(entry)); - } - mDictionaryLanguage = Conversion::fromStdString(dictionary.language()); - } - break; - case FreebusyObject: { - const Kolab::Freebusy &fb = Kolab::readFreebusy(xml, false); - mFreebusy = fb; - } - break; -#ifdef HAVE_TAG_H - case RelationConfigurationObject: { - const Kolab::Configuration &configuration = Kolab::readConfiguration(xml, false); - const Kolab::Relation &relation = configuration.relation(); - - if (relation.type() == "tag") { - mTag = Akonadi::Tag(); - mTag.setName(Conversion::fromStdString(relation.name())); - mTag.setGid(Conversion::fromStdString(configuration.uid()).toLatin1()); -#ifdef KDEPIMLIBS_HAS_GENERIC_TAG - mTag.setType(Akonadi::Tag::GENERIC); -#else - mTag.setType(Akonadi::Tag::PLAIN); -#endif - mTagMembers.reserve(relation.members().size()); - foreach (const std::string &member, relation.members()) { - mTagMembers << Conversion::fromStdString(member); - } - } else if (relation.type() == "generic") { -#ifdef HAVE_RELATION_H - if (relation.members().size() == 2) { - mRelation = Akonadi::Relation(); - mRelation.setRemoteId(Conversion::fromStdString(configuration.uid()).toLatin1()); - mRelation.setType(Akonadi::Relation::GENERIC); - - mTagMembers.reserve(relation.members().size()); - foreach (const std::string &member, relation.members()) { - mTagMembers << Conversion::fromStdString(member); - } - } else { - Critical() << "generic relation had wrong number of members:" << relation.members().size(); - printMessageDebugInfo(msg); - } -#endif - } else { - Critical() << "unknown configuration object type" << relation.type(); - printMessageDebugInfo(msg); - } - } - break; -#endif - default: - Critical() << "no kolab object found "; - printMessageDebugInfo(msg); - break; - } - - if (!mIncidence.isNull()) { -// kDebug() << "getting attachments"; - Mime::getAttachmentsById(mIncidence, msg); - } - ErrorHandler::handleLibkolabxmlErrors(); - if (ErrorHandler::errorOccured()) { - printMessageDebugInfo(msg); - return InvalidObject; - } - mObjectType = objectType; - return mObjectType; -} - -ObjectType KolabObjectReader::parseMimeMessage(const KMime::Message::Ptr &msg) -{ - ErrorHandler::clearErrors(); - d->mObjectType = InvalidObject; - if (msg->contents().isEmpty()) { - Critical() << "message has no contents (we likely failed to parse it correctly)"; - printMessageDebugInfo(msg); - return InvalidObject; - } - Kolab::ObjectType objectType = InvalidObject; - if (d->mOverrideObjectType == InvalidObject) { - if (KMime::Headers::Base *xKolabHeader = msg->getHeaderByType(X_KOLAB_TYPE_HEADER)) { - objectType = getObjectType(xKolabHeader->asUnicodeString().trimmed()); - } else { - Warning() << "could not find the X-Kolab-Type Header, trying autodetection" ; - //This works only for v2 messages atm. - objectType = detectType(msg); - } - } else { - objectType = d->mOverrideObjectType; - } - if (objectType == InvalidObject) { - Critical() << "unable to detect object type"; - printMessageDebugInfo(msg); - return InvalidObject; - } - - if (!d->mDoOverrideVersion) { - KMime::Headers::Base *xKolabVersion = msg->getHeaderByType(X_KOLAB_MIME_VERSION_HEADER); - if (!xKolabVersion) { - //For backwards compatibility to development versions, can be removed in future versions - xKolabVersion = msg->getHeaderByType(X_KOLAB_MIME_VERSION_HEADER_COMPAT); - } - if (!xKolabVersion || xKolabVersion->asUnicodeString() == KOLAB_VERSION_V2) { - d->mVersion = KolabV2; - } else { - if (xKolabVersion->asUnicodeString() != KOLAB_VERSION_V3) { //TODO version compatibility check? - Warning() << "Kolab Version Header available but not on the same version as the implementation: " << xKolabVersion->asUnicodeString(); - } - d->mVersion = KolabV3; - } - } else { - d->mVersion = d->mOverrideVersion; - } - - if (d->mVersion == KolabV2) { - return d->readKolabV2(msg, objectType); - } - return d->readKolabV3(msg, objectType); -} - -Version KolabObjectReader::getVersion() const -{ - return d->mVersion; -} - -ObjectType KolabObjectReader::getType() const -{ - return d->mObjectType; -} - -KCalCore::Event::Ptr KolabObjectReader::getEvent() const -{ - return d->mIncidence.dynamicCast<KCalCore::Event>(); -} - -KCalCore::Todo::Ptr KolabObjectReader::getTodo() const -{ - return d->mIncidence.dynamicCast<KCalCore::Todo>(); -} - -KCalCore::Journal::Ptr KolabObjectReader::getJournal() const -{ - return d->mIncidence.dynamicCast<KCalCore::Journal>(); -} - -KCalCore::Incidence::Ptr KolabObjectReader::getIncidence() const -{ - return d->mIncidence; -} - -KABC::Addressee KolabObjectReader::getContact() const -{ - return d->mAddressee; -} - -KABC::ContactGroup KolabObjectReader::getDistlist() const -{ - return d->mContactGroup; -} - -KMime::Message::Ptr KolabObjectReader::getNote() const -{ - return d->mNote; -} - -QStringList KolabObjectReader::getDictionary(QString& lang) const -{ - lang = d->mDictionaryLanguage; - return d->mDictionary; -} - -Freebusy KolabObjectReader::getFreebusy() const -{ - return d->mFreebusy; -} - -#ifdef HAVE_TAG_H -bool KolabObjectReader::isTag() const -{ - return !d->mTag.gid().isEmpty(); -} - -Akonadi::Tag KolabObjectReader::getTag() const -{ - return d->mTag; -} - -QStringList KolabObjectReader::getTagMembers() const -{ - return d->mTagMembers; -} -#endif - -#ifdef HAVE_RELATION_H -bool KolabObjectReader::isRelation() const -{ - return d->mRelation.isValid(); -} - -Akonadi::Relation KolabObjectReader::getRelation() const -{ - return d->mRelation; -} -#endif - - -//Normalize incidences before serializing them -KCalCore::Incidence::Ptr normalizeIncidence(KCalCore::Incidence::Ptr original) -{ - KCalCore::Incidence::Ptr i = KCalCore::Incidence::Ptr(original->clone()); //We copy to avoid destructive writing - Q_FOREACH (KCalCore::Attachment::Ptr attachment, i->attachments()) { - attachment->setUri(QString::fromLatin1("cid:")+QString::fromLatin1(KMime::uniqueString() + '@' + "kolab.resource.akonadi")); //Serialize the attachment as attachment with uri, referencing the created mime-part - } - return i; -} -/* -KABC::Addressee normalizeContact(const KABC::Addressee &a) -{ - KABC::Addressee addresee = a; - Q_FOREACH (KCalCore::Attachment::Ptr attachment, addresee.photo()) { - attachment->setUri(QString::fromLatin1("cid:")+QString::fromLatin1(KMime::uniqueString() + '@' + "kolab.resource.akonadi")); //Serialize the attachment as attachment with uri, referencing the created mime-part - } - return i; -}*/ - -QString getProductId(const QString &pId) -{ - if (pId.isEmpty()) { - return LIBKOLAB_LIB_VERSION_STRING; - } - return pId+" "+LIBKOLAB_LIB_VERSION_STRING; -} - -KMime::Message::Ptr KolabObjectWriter::writeEvent(const KCalCore::Event::Ptr &i, Version v, const QString &productId, const QString &tz) -{ - ErrorHandler::clearErrors(); - if (!i) { - Critical() << "passed a null pointer"; - return KMime::Message::Ptr(); - } - Q_ASSERT(!i.isNull()); - if (v == KolabV3) { - KCalCore::Event::Ptr ic = normalizeIncidence(i).dynamicCast<KCalCore::Event>(); - const Kolab::Event &incidence = Kolab::Conversion::fromKCalCore(*ic); - const std::string &v3String = Kolab::writeEvent(incidence, std::string(getProductId(productId).toUtf8().constData())); - ErrorHandler::handleLibkolabxmlErrors(); - return Mime::createMessage(ic, xCalMimeType(), eventKolabType(), QString::fromUtf8(v3String.c_str()).toUtf8(), true, getProductId(productId)); - } - const QString &xml = KolabV2::Event::eventToXML(i, tz); - return Mime::createMessage(i, eventKolabType(), eventKolabType(), xml.toUtf8(), false, getProductId(productId)); -} - -KMime::Message::Ptr KolabObjectWriter::writeTodo(const KCalCore::Todo::Ptr &i, Version v, const QString &productId, const QString &tz) -{ - ErrorHandler::clearErrors(); - if (!i) { - Critical() << "passed a null pointer"; - return KMime::Message::Ptr(); - } - Q_ASSERT(!i.isNull()); - if (v == KolabV3) { - KCalCore::Todo::Ptr ic = normalizeIncidence(i).dynamicCast<KCalCore::Todo>(); - const Kolab::Todo &incidence = Kolab::Conversion::fromKCalCore(*ic); - const std::string &v3String = Kolab::writeTodo(incidence, Conversion::toStdString(getProductId(productId))); - ErrorHandler::handleLibkolabxmlErrors(); - return Mime::createMessage(ic, xCalMimeType(), todoKolabType(), Conversion::fromStdString(v3String).toUtf8(), true, getProductId(productId)); - } - const QString &xml = KolabV2::Task::taskToXML(i, tz); - return Mime::createMessage(i, todoKolabType(), todoKolabType(), xml.toUtf8(), false, getProductId(productId)); -} - -KMime::Message::Ptr KolabObjectWriter::writeJournal(const KCalCore::Journal::Ptr &i, Version v, const QString &productId, const QString &tz) -{ - ErrorHandler::clearErrors(); - if (!i) { - Critical() << "passed a null pointer"; - return KMime::Message::Ptr(); - } - Q_ASSERT(!i.isNull()); - if (v == KolabV3) { - KCalCore::Journal::Ptr ic = normalizeIncidence(i).dynamicCast<KCalCore::Journal>(); - const Kolab::Journal &incidence = Kolab::Conversion::fromKCalCore(*ic); - const std::string &v3String = Kolab::writeJournal(incidence, Conversion::toStdString(getProductId(productId))); - ErrorHandler::handleLibkolabxmlErrors(); - return Mime::createMessage(ic, xCalMimeType(), journalKolabType(), Conversion::fromStdString(v3String).toUtf8(), true, getProductId(productId)); - } - const QString &xml = KolabV2::Journal::journalToXML(i, tz); - return Mime::createMessage(i, journalKolabType(), journalKolabType(), xml.toUtf8(), false, getProductId(productId)); -} - -KMime::Message::Ptr KolabObjectWriter::writeIncidence(const KCalCore::Incidence::Ptr &i, Version v, const QString& productId, const QString& tz) -{ - if (!i) { - Critical() << "passed a null pointer"; - return KMime::Message::Ptr(); - } - switch (i->type()) { - case KCalCore::IncidenceBase::TypeEvent: - return writeEvent(i.dynamicCast<KCalCore::Event>(),v,productId,tz); - case KCalCore::IncidenceBase::TypeTodo: - return writeTodo(i.dynamicCast<KCalCore::Todo>(),v,productId,tz); - case KCalCore::IncidenceBase::TypeJournal: - return writeJournal(i.dynamicCast<KCalCore::Journal>(),v,productId,tz); - default: - Critical() << "unknown incidence type"; - } - return KMime::Message::Ptr(); -} - - -KMime::Message::Ptr KolabObjectWriter::writeContact(const KABC::Addressee &addressee, Version v, const QString &productId) -{ - ErrorHandler::clearErrors(); - if (v == KolabV3) { - const Kolab::Contact &contact = Kolab::Conversion::fromKABC(addressee); - const std::string &v3String = Kolab::writeContact(contact, Conversion::toStdString(getProductId(productId))); - ErrorHandler::handleLibkolabxmlErrors(); - return Mime::createMessage(addressee, xCardMimeType(), contactKolabType(), Conversion::fromStdString(v3String).toUtf8(), true, getProductId(productId)); - } - KolabV2::Contact contact(&addressee); - return contactToKolabFormat(contact, getProductId(productId)); -} - -KMime::Message::Ptr KolabObjectWriter::writeDistlist(const KABC::ContactGroup &distlist, Version v, const QString &productId) -{ - ErrorHandler::clearErrors(); - if (v == KolabV3) { - const Kolab::DistList &dist = Kolab::Conversion::fromKABC(distlist); - const std::string &v3String = Kolab::writeDistlist(dist, Conversion::toStdString(getProductId(productId))); - ErrorHandler::handleLibkolabxmlErrors(); - return Mime::createMessage(Conversion::fromStdString(dist.uid()), xCardMimeType(), distlistKolabType(), Conversion::fromStdString(v3String).toUtf8(), true, getProductId(productId)); - } - KolabV2::DistributionList d(&distlist); - return distListToKolabFormat(d, getProductId(productId)); -} - -KMime::Message::Ptr KolabObjectWriter::writeNote(const KMime::Message::Ptr ¬e, Version v, const QString &productId) -{ - ErrorHandler::clearErrors(); - if (!note) { - Critical() << "passed a null pointer"; - return KMime::Message::Ptr(); - } - Q_ASSERT(note.get()); - if (v == KolabV3) { - const Kolab::Note &n = Kolab::Conversion::fromNote(note); - const std::string &v3String = Kolab::writeNote(n, Conversion::toStdString(getProductId(productId))); - ErrorHandler::handleLibkolabxmlErrors(); - return Mime::createMessage(Conversion::fromStdString(n.uid()), kolabMimeType(), noteKolabType(), Conversion::fromStdString(v3String).toUtf8(), true, getProductId(productId)); - } - return noteToKolab(note, getProductId(productId)); -} - -KMime::Message::Ptr KolabObjectWriter::writeDictionary(const QStringList &entries, const QString& lang, Version v, const QString& productId) -{ - ErrorHandler::clearErrors(); - if (v != KolabV3) { - Critical() << "only v3 implementation available"; - } - - Kolab::Dictionary dictionary(Conversion::toStdString(lang)); - std::vector <std::string> ent; - foreach (const QString &e, entries) { - ent.push_back(Conversion::toStdString(e)); - } - dictionary.setEntries(ent); - Kolab::Configuration configuration(dictionary); //TODO preserve creation/lastModified date - const std::string &v3String = Kolab::writeConfiguration(configuration, Conversion::toStdString(getProductId(productId))); - ErrorHandler::handleLibkolabxmlErrors(); - return Mime::createMessage(Conversion::fromStdString(configuration.uid()), kolabMimeType(), dictKolabType(), Conversion::fromStdString(v3String).toUtf8(), true, getProductId(productId)); -} - -KMime::Message::Ptr KolabObjectWriter::writeFreebusy(const Freebusy &freebusy, Version v, const QString& productId) -{ - ErrorHandler::clearErrors(); - if (v != KolabV3) { - Critical() << "only v3 implementation available"; - } - const std::string &v3String = Kolab::writeFreebusy(freebusy, Conversion::toStdString(getProductId(productId))); - ErrorHandler::handleLibkolabxmlErrors(); - return Mime::createMessage(Conversion::fromStdString(freebusy.uid()), xCalMimeType(), freebusyKolabType(), Conversion::fromStdString(v3String).toUtf8(), true, getProductId(productId)); -} - -#ifdef HAVE_TAG_H -KMime::Message::Ptr writeRelationHelper(const Kolab::Relation &relation, const QByteArray &uid, const QString &productId) -{ - Kolab::Configuration configuration(relation); //TODO preserve creation/lastModified date - configuration.setUid(uid.constData()); - const std::string &v3String = Kolab::writeConfiguration(configuration, Conversion::toStdString(getProductId(productId))); - ErrorHandler::handleLibkolabxmlErrors(); - return Mime::createMessage(Conversion::fromStdString(configuration.uid()), kolabMimeType(), relationKolabType(), Conversion::fromStdString(v3String).toUtf8(), true, getProductId(productId)); -} - -KMime::Message::Ptr KolabObjectWriter::writeTag(const Akonadi::Tag &tag, const QStringList &members, Version v, const QString &productId) -{ - ErrorHandler::clearErrors(); - if (v != KolabV3) { - Critical() << "only v3 implementation available"; - } - - Kolab::Relation relation(Conversion::toStdString(tag.name()), "tag"); - std::vector<std::string> m; - m.reserve(members.count()); - foreach (const QString &member, members) { - m.push_back(Conversion::toStdString(member)); - } - relation.setMembers(m); - - return writeRelationHelper(relation, tag.gid(), productId); -} -#endif - -#ifdef HAVE_RELATION_H -KMime::Message::Ptr KolabObjectWriter::writeRelation(const Akonadi::Relation &relation, const QStringList &items, Version v, const QString &productId) -{ - ErrorHandler::clearErrors(); - if (v != KolabV3) { - Critical() << "only v3 implementation available"; - } - - if (items.size() != 2) { - Critical() << "Wrong number of members for generic relation."; - return KMime::Message::Ptr(); - } - - Kolab::Relation kolabRelation(std::string(), "generic"); - std::vector<std::string> m; - m.reserve(2); - m.push_back(Conversion::toStdString(items.at(0))); - m.push_back(Conversion::toStdString(items.at(1))); - kolabRelation.setMembers(m); - - return writeRelationHelper(kolabRelation, relation.remoteId(), productId); -} -#endif - - -}; //Namespace -
View file
libkolab-2.0.tar.gz/kolabformat/kolabobject.h
Deleted
@@ -1,157 +0,0 @@ -/* - * Copyright (C) 2012 Christian Mollekopf <mollekopf@kolabsys.com> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef KOLABOBJECT_H -#define KOLABOBJECT_H - -#include <kolab_export.h> - -#include <libkolab_config.h> - -#ifdef HAVE_TAG_H -#include <akonadi/item.h> -#include <akonadi/tag.h> -#endif -#ifdef HAVE_RELATION_H -#include <akonadi/relation.h> -#endif -#include <kabc/addressee.h> -#include <kabc/contactgroup.h> -#include <kcalcore/incidence.h> -#include <kcalcore/event.h> -#include <kcalcore/journal.h> -#include <kcalcore/todo.h> -#include <kmime/kmime_message.h> - -#include "kolabdefinitions.h" - -namespace Kolab { - -class Freebusy; - - -KOLAB_EXPORT KCalCore::Event::Ptr readV2EventXML(const QByteArray &xmlData, QStringList &attachments); - -struct KOLAB_EXPORT RelationMember { - QString messageId; - QString subject; - QString date; - QList<QByteArray> mailbox; - QString user; - qint64 uid; - QString gid; -}; -KOLAB_EXPORT RelationMember parseMemberUrl(const QString &url); -KOLAB_EXPORT QString generateMemberUrl(const RelationMember &url); - -/** - * Class to read Kolab Mime files - * - * It implements the Kolab specifics of Mime message handling. - * This class is not reusable and only meant to read a single object. - * Parse the mime message and then call the correct getter, based on the type - * - */ -class KOLAB_EXPORT KolabObjectReader { -public: - KolabObjectReader(); - explicit KolabObjectReader(const KMime::Message::Ptr &msg); - ~KolabObjectReader(); - - ObjectType parseMimeMessage(const KMime::Message::Ptr &msg); - - /** - * Set to override the autodetected object type, before parsing the message. - */ - void setObjectType(ObjectType); - - /** - * Set to override the autodetected version, before parsing the message. - */ - void setVersion(Version); - - /** - * Returns the Object type of the parsed kolab object. - */ - ObjectType getType() const; - /** - * Returns the kolab-format version of the parsed kolab object. - */ - Version getVersion() const; - - /** - * Getter to get the retrieved object. - * Only the correct one will return a valid object. - * - * Use getType() to determine the correct one to call. - */ - KCalCore::Event::Ptr getEvent() const; - KCalCore::Todo::Ptr getTodo() const; - KCalCore::Journal::Ptr getJournal() const; - KCalCore::Incidence::Ptr getIncidence() const; - KABC::Addressee getContact() const; - KABC::ContactGroup getDistlist() const; - KMime::Message::Ptr getNote() const; - QStringList getDictionary(QString &lang) const; - Freebusy getFreebusy() const; -#ifdef HAVE_TAG_H - bool isTag() const; - Akonadi::Tag getTag() const; - QStringList getTagMembers() const; -#endif -#ifdef HAVE_RELATION_H - bool isRelation() const; - Akonadi::Relation getRelation() const; -#endif - -private: - //@cond PRIVATE - KolabObjectReader(const KolabObjectReader &other); - KolabObjectReader &operator=(const KolabObjectReader &rhs); - class Private; - Private *const d; - //@endcond -}; - -/** - * Class to write Kolab Mime files - * - */ -class KOLAB_EXPORT KolabObjectWriter { -public: - - static KMime::Message::Ptr writeEvent(const KCalCore::Event::Ptr &, Version v = KolabV3, const QString &productId = QString(), const QString &tz = QString()); - static KMime::Message::Ptr writeTodo(const KCalCore::Todo::Ptr &, Version v = KolabV3, const QString &productId = QString(),const QString &tz = QString()); - static KMime::Message::Ptr writeJournal(const KCalCore::Journal::Ptr &, Version v = KolabV3, const QString &productId = QString(),const QString &tz = QString()); - static KMime::Message::Ptr writeIncidence(const KCalCore::Incidence::Ptr &, Version v = KolabV3, const QString &productId = QString(),const QString &tz = QString()); - static KMime::Message::Ptr writeContact(const KABC::Addressee &, Version v = KolabV3, const QString &productId = QString()); - static KMime::Message::Ptr writeDistlist(const KABC::ContactGroup &, Version v = KolabV3, const QString &productId = QString()); - static KMime::Message::Ptr writeNote(const KMime::Message::Ptr &, Version v = KolabV3, const QString &productId = QString()); - static KMime::Message::Ptr writeDictionary(const QStringList &, const QString &lang, Version v = KolabV3, const QString &productId = QString()); - static KMime::Message::Ptr writeFreebusy(const Kolab::Freebusy &, Version v = KolabV3, const QString &productId = QString()); -#ifdef HAVE_TAG_H - static KMime::Message::Ptr writeTag(const Akonadi::Tag &, const QStringList &items, Version v = KolabV3, const QString &productId = QString()); -#endif -#ifdef HAVE_RELATION_H - static KMime::Message::Ptr writeRelation(const Akonadi::Relation &, const QStringList &items, Version v = KolabV3, const QString &productId = QString()); -#endif - -}; - -} //Namespace - -#endif // KOLABOBJECT_H
View file
libkolab-2.0.tar.gz/kolabformat/mimeobject.cpp
Deleted
@@ -1,162 +0,0 @@ -/* - * Copyright (C) 2012 Sofia Balicka <balicka@kolabsys.com> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include "mimeobject.h" -#include "conversion/kcalconversion.h" -#include "conversion/kolabconversion.h" -#include "conversion/kabcconversion.h" -#include "kolabformat/kolabobject.h" -#include <QString> - -namespace Kolab -{ - -MIMEObject::MIMEObject() -{ - -} - -std::string MIMEObject::writeEvent(const Event &event, Version version, const std::string &productId) -{ - - KCalCore::Event::Ptr KEvent = Conversion::toKCalCore(event); - - KMime::Message::Ptr msg = KolabObjectWriter().writeEvent(KEvent, version, QString::fromStdString(productId)); - msg->assemble(); - - return msg->encodedContent().data(); -} - -Event MIMEObject::readEvent(const std::string &s) -{ - - KMime::Message::Ptr msg(new KMime::Message); - msg->setContent(QByteArray(s.c_str())); - msg->parse(); - - KCalCore::Event::Ptr event = KolabObjectReader(msg).getEvent(); - - return Conversion::fromKCalCore(*event); -} - -std::string MIMEObject::writeTodo(const Todo &todo, Version version, const std::string &productId){ - KCalCore::Todo::Ptr kTodo = Conversion::toKCalCore(todo); - - KMime::Message::Ptr msg = KolabObjectWriter().writeTodo(kTodo, version, QString::fromStdString(productId)); - msg->assemble(); - - return msg->encodedContent().data(); -} - - -Todo MIMEObject::readTodo(const std::string &s){ - - KMime::Message::Ptr msg(new KMime::Message); - msg->setContent(QByteArray(s.c_str())); - msg->parse(); - - KCalCore::Todo::Ptr todo = KolabObjectReader(msg).getTodo(); - - return Conversion::fromKCalCore(*todo); -} - - -std::string MIMEObject::writeJournal(const Journal &journal, Version version, const std::string &productId){ - KCalCore::Journal::Ptr kJournal = Conversion::toKCalCore(journal); - - KMime::Message::Ptr msg = KolabObjectWriter().writeJournal(kJournal, version, QString::fromStdString(productId)); - msg->assemble(); - - return msg->encodedContent().data(); -} - - -Journal MIMEObject::readJournal(const std::string &s){ - - KMime::Message::Ptr msg(new KMime::Message); - msg->setContent(QByteArray(s.c_str())); - msg->parse(); - - KCalCore::Journal::Ptr journal = KolabObjectReader(msg).getJournal(); - - return Conversion::fromKCalCore(*journal); -} - -std::string MIMEObject::writeNote(const Note ¬e, Version version, const std::string &productId){ - KMime::Message::Ptr kNote = Conversion::toNote(note); - - KMime::Message::Ptr msg = KolabObjectWriter().writeNote(kNote, version, QString::fromStdString(productId)); - msg->assemble(); - - return msg->encodedContent().data(); -} - - -Note MIMEObject::readNote(const std::string &s){ - - KMime::Message::Ptr msg(new KMime::Message); - msg->setContent(QByteArray(s.c_str())); - msg->parse(); - - KMime::Message::Ptr note = KolabObjectReader(msg).getNote(); - - return Conversion::fromNote(note); -} - -std::string MIMEObject::writeContact(const Contact &contact, Version version, const std::string &productId){ - KABC::Addressee kContact = Conversion::toKABC(contact); - - KMime::Message::Ptr msg = KolabObjectWriter().writeContact(kContact, version, QString::fromStdString(productId)); - msg->assemble(); - - return msg->encodedContent().data(); -} - - -Contact MIMEObject::readContact(const std::string &s){ - - KMime::Message::Ptr msg(new KMime::Message); - msg->setContent(QByteArray(s.c_str())); - msg->parse(); - - KABC::Addressee contact = KolabObjectReader(msg).getContact(); - - return Conversion::fromKABC(contact); -} - -std::string MIMEObject::writeDistlist(const DistList &distlist, Version version, const std::string &productId){ - KABC::ContactGroup kDistlist = Conversion::toKABC(distlist); - - KMime::Message::Ptr msg = KolabObjectWriter().writeDistlist(kDistlist, version, QString::fromStdString(productId)); - msg->assemble(); - - return msg->encodedContent().data(); -} - - -DistList MIMEObject::readDistlist(const std::string &s){ - - KMime::Message::Ptr msg(new KMime::Message); - msg->setContent(QByteArray(s.c_str())); - msg->parse(); - - KABC::ContactGroup distlist = KolabObjectReader(msg).getDistlist(); - - return Conversion::fromKABC(distlist); -} -} -
View file
libkolab-2.0.tar.gz/kolabformat/mimeobject.h
Deleted
@@ -1,60 +0,0 @@ -/* - * Copyright (C) 2012 Sofia Balicka <balicka@kolabsys.com> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef MIMEOBJECT_H -#define MIMEOBJECT_H - -#ifndef SWIG -#include "kolab_export.h" -#else -/* No export/import SWIG interface files */ -#define KOLAB_EXPORT -#endif - -#include <kolabformat.h> -#include "kolabdefinitions.h" - - -namespace Kolab -{ - -class KOLAB_EXPORT MIMEObject -{ -public: - MIMEObject(); - - std::string writeEvent(const Kolab::Event &event, Version version, const std::string &productId = std::string()); - Kolab::Event readEvent(const std::string &s); - - std::string writeTodo(const Kolab::Todo &todo, Version version, const std::string &productId = std::string()); - Kolab::Todo readTodo(const std::string &s); - - std::string writeJournal(const Kolab::Journal &journal, Version version, const std::string &productId = std::string()); - Kolab::Journal readJournal(const std::string &s); - - std::string writeNote(const Kolab::Note ¬e, Version version, const std::string &productId = std::string()); - Kolab::Note readNote(const std::string &s); - - std::string writeContact(const Kolab::Contact &contact, Version version, const std::string &productId = std::string()); - Kolab::Contact readContact(const std::string &s); - - std::string writeDistlist(const Kolab::DistList &distlist, Version version, const std::string &productId = std::string()); - Kolab::DistList readDistlist(const std::string &s); - -}; -} -#endif
View file
libkolab-2.0.tar.gz/kolabformat/v2helpers.cpp
Deleted
@@ -1,279 +0,0 @@ -/* - * Copyright (C) 2012 Christian Mollekopf <mollekopf@kolabsys.com> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include "v2helpers.h" - -#include "kolabdefinitions.h" - -#include "kolabformatV2/kolabbase.h" -#include "kolabformatV2/journal.h" -#include "kolabformatV2/task.h" -#include "kolabformatV2/event.h" -#include "kolabformatV2/contact.h" -#include "kolabformatV2/distributionlist.h" -#include "kolabformatV2/note.h" -#include "mime/mimeutils.h" -#include "kolabformat/errorhandler.h" - -#include <kabc/contactgroup.h> - -#include <qdom.h> -#include <kdebug.h> -#include <qbuffer.h> -#include <akonadi/notes/noteutils.h> - -namespace Kolab { - -static QImage getPicture(const QString &pictureAttachmentName, const KMime::Message::Ptr &data, QByteArray &type) -{ - if (!data) { - Critical() << "empty message"; - return QImage(); - } - KMime::Content *imgContent = Mime::findContentByName(data, pictureAttachmentName/*"kolab-picture.png"*/, type); - if (!imgContent) { - Warning() << "could not find picture: " << pictureAttachmentName; - return QImage(); - } - QByteArray imgData = imgContent->decodedContent(); - QBuffer buffer(&imgData); - buffer.open(QIODevice::ReadOnly); - QImage image; - bool success = false; - if (type == "image/jpeg") { - success = image.load(&buffer, "JPEG"); - //FIXME I tried getting the code to interpret the picture as PNG, but the VCard implementation writes it as JPEG anyways... -// if (success) { -// QByteArray pic; -// QBuffer b(&pic); -// b.open(QIODevice::ReadWrite); -// Q_ASSERT(image.save(&b, "PNG")); -// b.close(); -// Debug() << pic.toBase64(); -// QBuffer b2(&pic); -// b2.open(QIODevice::ReadOnly); -// success = image.load(&b2, "PNG"); -// b2.close(); -// Q_ASSERT(success); -// } - } else { - type = "image/png"; - success = image.load(&buffer, "PNG"); - } - buffer.close(); - if (!success) { - Warning() << "failed to load picture"; - } - return image; -} - -KABC::Addressee addresseeFromKolab( const QByteArray &xmlData, const KMime::Message::Ptr &data) -{ - if (!data) { - Critical() << "empty message"; - return KABC::Addressee(); - } - KABC::Addressee addressee; -// Debug() << "xmlData " << xmlData; - KolabV2::Contact contact(QString::fromUtf8(xmlData)); - QByteArray type; - const QString &pictureAttachmentName = contact.pictureAttachmentName(); - if (!pictureAttachmentName.isEmpty()) { - const QImage &img = getPicture(pictureAttachmentName, data, type); - contact.setPicture(img, type); - } - - const QString &logoAttachmentName = contact.logoAttachmentName(); - if (!logoAttachmentName.isEmpty()) { - contact.setLogo(getPicture(logoAttachmentName, data, type), type); - } - - const QString &soundAttachmentName = contact.soundAttachmentName(); - if (!soundAttachmentName.isEmpty()) { - QByteArray type; - KMime::Content *content = Mime::findContentByName(data, soundAttachmentName/*"sound"*/, type); - if (content) { - const QByteArray &sData = content->decodedContent(); - contact.setSound(sData); - } else { - Warning() << "could not find sound: " << soundAttachmentName; - } - } - contact.saveTo(&addressee); - return addressee; -} - -KABC::Addressee addresseeFromKolab(const QByteArray &xmlData, QString &pictureAttachmentName, QString &logoAttachmentName, QString &soundAttachmentName) -{ - KABC::Addressee addressee; - KolabV2::Contact contact(QString::fromUtf8(xmlData)); - pictureAttachmentName = contact.pictureAttachmentName(); - logoAttachmentName = contact.logoAttachmentName(); - soundAttachmentName = contact.soundAttachmentName(); - contact.saveTo(&addressee); - return addressee; -} - -static QByteArray createPicture(const QImage &img, const QString &/*format*/, QString &type) -{ - QByteArray pic; - QBuffer buffer(&pic); - buffer.open(QIODevice::WriteOnly); - type = "image/png"; - //FIXME it's not possible to save jpegs lossless, so we always use png. otherwise we would compress the image on every write. -// if (format == "image/jpeg") { -// type = "image/jpeg"; -// img.save(&buffer, "JPEG"); -// } else { - img.save(&buffer, "PNG"); -// } - buffer.close(); - return pic; -} - -KMime::Message::Ptr contactToKolabFormat(const KolabV2::Contact& contact, const QString &productId) -{ - KMime::Message::Ptr message = Mime::createMessage( KOLAB_TYPE_CONTACT, false, productId ); - if (!message) { - Critical() << "empty message"; - return KMime::Message::Ptr(); - } - message->subject()->fromUnicodeString( contact.uid(), "utf-8" ); - message->from()->fromUnicodeString( contact.fullEmail(), "utf-8" ); - - KMime::Content* content = Mime::createMainPart( KOLAB_TYPE_CONTACT, contact.saveXML().toUtf8() ); - message->addContent( content ); - - if ( !contact.picture().isNull() ) { - QString type; - const QByteArray &pic = createPicture(contact.picture(), contact.pictureFormat(), type); - content = Mime::createAttachmentPart(QByteArray(), type, /*"kolab-picture.png"*/contact.pictureAttachmentName(), pic ); - message->addContent(content); - } - - if ( !contact.logo().isNull() ) { - QString type; - const QByteArray &pic = createPicture(contact.logo(), contact.logoFormat(), type); - content = Mime::createAttachmentPart(QByteArray(), type, /*"kolab-logo.png"*/contact.logoAttachmentName(), pic ); - message->addContent(content); - } - - if ( !contact.sound().isEmpty() ) { - content = Mime::createAttachmentPart(QByteArray(), "audio/unknown", /*"sound"*/contact.soundAttachmentName(), contact.sound() ); - message->addContent(content); - } - - message->assemble(); - return message; -} - -KABC::ContactGroup contactGroupFromKolab(const QByteArray &xmlData) -{ - KABC::ContactGroup contactGroup; - // kDebug() << "xmlData " << xmlData; - KolabV2::DistributionList distList(QString::fromUtf8(xmlData)); - distList.saveTo(&contactGroup); - return contactGroup; -} - -KMime::Message::Ptr distListToKolabFormat(const KolabV2::DistributionList& distList, const QString &productId) -{ - KMime::Message::Ptr message = Mime::createMessage( KOLAB_TYPE_DISTLIST_V2, false, productId ); - if (!message) { - Critical() << "empty message"; - return KMime::Message::Ptr(); - } - message->subject()->fromUnicodeString( distList.uid(), "utf-8" ); - message->from()->fromUnicodeString( distList.uid(), "utf-8" ); - - KMime::Content* content = Mime::createMainPart( KOLAB_TYPE_DISTLIST_V2, distList.saveXML().toUtf8() ); - message->addContent( content ); - - message->assemble(); - return message; -} - -KMime::Message::Ptr noteFromKolab(const QByteArray &xmlData, const KDateTime &creationDate) -{ - KolabV2::Note j; - if ( !j.load( xmlData ) ) { - Warning() << "failed to read note"; - return KMime::Message::Ptr(); - } - - Akonadi::NoteUtils::NoteMessageWrapper note; - note.setTitle(j.summary()); - note.setText(j.body().toUtf8()); - note.setFrom("kolab@kde4"); - note.setCreationDate(creationDate); - return note.message(); -} - -KMime::Message::Ptr noteToKolab(const KMime::Message::Ptr& msg, const QString &productId) -{ - if (!msg) { - Critical() << "empty message"; - return KMime::Message::Ptr(); - } - Akonadi::NoteUtils::NoteMessageWrapper note(msg); - return Mime::createMessage(note.title(), KOLAB_TYPE_NOTE, KOLAB_TYPE_NOTE, noteToKolabXML(msg), false, productId); -} - -QByteArray noteToKolabXML(const KMime::Message::Ptr& msg) -{ - if (!msg) { - Critical() << "empty message"; - return QByteArray(); - } - Akonadi::NoteUtils::NoteMessageWrapper note(msg); - KolabV2::Note j; - j.setSummary( note.title() ); - j.setBody( note.text() ); - return j.saveXML().toUtf8(); -} - -QStringList readLegacyDictionaryConfiguration(const QByteArray &xmlData, QString &language) -{ - QStringList dictionary; - const QDomDocument xmlDoc = KolabV2::KolabBase::loadDocument( QString::fromUtf8(xmlData) ); //TODO extract function from V2 format - if ( xmlDoc.isNull() ) { - Error() << "Failed to read the xml document"; - return QStringList(); - } - - QDomElement top = xmlDoc.documentElement(); - - if ( top.tagName() != "configuration" ) { - qWarning( "XML error: Top tag was %s instead of the expected configuration", - top.tagName().toAscii().data() ); - return QStringList(); - } - - for ( QDomNode n = top.firstChild(); !n.isNull(); n = n.nextSibling() ) { - if ( n.isComment() || !n.isElement() ) - continue; - QDomElement e = n.toElement(); - if (e.tagName() == "language") { - language = e.text(); - } else if (e.tagName() == "e") { - dictionary.append(e.text()); - } - } - return dictionary; -} - -}
View file
libkolab-2.0.tar.gz/kolabformat/v2helpers.h
Deleted
@@ -1,96 +0,0 @@ -/* - * Copyright (C) 2012 Christian Mollekopf <mollekopf@kolabsys.com> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef V2HELPERS_H -#define V2HELPERS_H - -#include "kolabdefinitions.h" - -#include "kolabformatV2/kolabbase.h" -#include "kolabformatV2/journal.h" -#include "kolabformatV2/task.h" -#include "kolabformatV2/event.h" -#include "kolabformatV2/contact.h" -#include "kolabformatV2/distributionlist.h" -#include "kolabformatV2/note.h" -#include "mime/mimeutils.h" -#include "kolabformat/errorhandler.h" - -#include <kabc/contactgroup.h> - -#include <qdom.h> -#include <qbuffer.h> -#include <akonadi/notes/noteutils.h> - -namespace Kolab { - - -/* - * Parse XML, create KCalCore container and extract attachments - */ -template <typename KCalPtr, typename Container> -static KCalPtr fromXML(const QByteArray &xmlData, QStringList &attachments) -{ - const QDomDocument xmlDoc = KolabV2::KolabBase::loadDocument( QString::fromUtf8(xmlData) ); //TODO extract function from V2 format - if ( xmlDoc.isNull() ) { - Critical() << "Failed to read the xml document"; - return KCalPtr(); - } - const KCalPtr i = Container::fromXml( xmlDoc, QString() ); //For parsing we don't need the timezone, so we don't set one - Q_ASSERT ( i ); - QDomNodeList nodes = xmlDoc.elementsByTagName("inline-attachment"); - for (int i = 0; i < nodes.size(); i++ ) { - attachments.append(nodes.at(i).toElement().text()); - } - return i; -} - -template <typename IncidencePtr, typename Converter> -static inline IncidencePtr incidenceFromKolabImpl( const KMime::Message::Ptr &data, const QByteArray &mimetype, const QString &timezoneId ) -{ - KMime::Content *xmlContent = Mime::findContentByType( data, mimetype ); - if ( !xmlContent ) { - Critical() << "couldn't find part"; - return IncidencePtr(); - } - const QByteArray &xmlData = xmlContent->decodedContent(); - - QStringList attachments; - IncidencePtr ptr = fromXML<IncidencePtr, Converter>(xmlData, attachments); //TODO do we care about timezone? - Mime::getAttachments(ptr, attachments, data); - - return ptr; -} - -KABC::Addressee addresseeFromKolab( const QByteArray &xmlData, const KMime::Message::Ptr &data); -KABC::Addressee addresseeFromKolab( const QByteArray &xmlData, QString &pictureAttachmentName, QString &logoAttachmentName, QString &soundAttachmentName); - -KMime::Message::Ptr contactToKolabFormat(const KolabV2::Contact& contact, const QString &productId); - -KABC::ContactGroup contactGroupFromKolab(const QByteArray &xmlData); - -KMime::Message::Ptr distListToKolabFormat(const KolabV2::DistributionList& distList, const QString &productId); -KMime::Message::Ptr noteFromKolab(const QByteArray &xmlData, const KDateTime &creationDate); - -KMime::Message::Ptr noteToKolab(const KMime::Message::Ptr& msg, const QString &productId); -QByteArray noteToKolabXML(const KMime::Message::Ptr& msg); - -QStringList readLegacyDictionaryConfiguration(const QByteArray &xmlData, QString &language); - -} - -#endif
View file
libkolab-2.0.tar.gz/kolabformatV2
Deleted
-(directory)
View file
libkolab-2.0.tar.gz/kolabformatV2/CMakeLists.txt
Deleted
@@ -1,12 +0,0 @@ - -set( kolabformatv2_SRCS - ${CMAKE_CURRENT_SOURCE_DIR}/kolabbase.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/contact.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/distributionlist.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/event.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/task.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/journal.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/incidence.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/note.cpp -# kolabformatv2.cpp - PARENT_SCOPE)
View file
libkolab-2.0.tar.gz/kolabformatV2/contact.cpp
Deleted
@@ -1,1214 +0,0 @@ -/* - This file is part of libkabc and/or kaddressbook. - Copyright (c) 2004 Klarälvdalens Datakonsult AB - <info@klaralvdalens-datakonsult.se> - - 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 Qt library by Trolltech AS, Norway (or with modified versions - of Qt that use the same license as Qt), 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 - Qt. 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 "contact.h" - -#include <kabc/addressee.h> -#include <kdebug.h> -#include <QFile> -#include <float.h> - -using namespace KolabV2; - -static const char* s_pictureAttachmentName = "kolab-picture.png"; -static const char* s_logoAttachmentName = "kolab-logo.png"; -static const char* s_soundAttachmentName = "sound"; -static const char* s_unhandledTagAppName = "KOLABUNHANDLED"; // no hyphens in appnames! - -// saving (addressee->xml) -Contact::Contact( const KABC::Addressee* addr ) - : mHasGeo( false ) -{ - setFields( addr ); -} - -// loading (xml->addressee) -Contact::Contact( const QString& xml ) - : mHasGeo( false ) -{ - load( xml ); -} - -Contact::~Contact() -{ -} - -void Contact::setGivenName( const QString& name ) -{ - mGivenName = name; -} - -QString Contact::givenName() const -{ - return mGivenName; -} - -void Contact::setMiddleNames( const QString& names ) -{ - mMiddleNames = names; -} - -QString Contact::middleNames() const -{ - return mMiddleNames; -} - -void Contact::setLastName( const QString& name ) -{ - mLastName = name; -} - -QString Contact::lastName() const -{ - return mLastName; -} - -void Contact::setFullName( const QString& name ) -{ - mFullName = name; -} - -QString Contact::fullName() const -{ - return mFullName; -} - -void Contact::setInitials( const QString& initials ) -{ - mInitials = initials; -} - -QString Contact::initials() const -{ - return mInitials; -} - -void Contact::setPrefix( const QString& prefix ) -{ - mPrefix = prefix; -} - -QString Contact::prefix() const -{ - return mPrefix; -} - -void Contact::setSuffix( const QString& suffix ) -{ - mSuffix = suffix; -} - -QString Contact::suffix() const -{ - return mSuffix; -} - -void Contact::setRole( const QString& role ) -{ - mRole = role; -} - -QString Contact::role() const -{ - return mRole; -} - -void Contact::setFreeBusyUrl( const QString& fbUrl ) -{ - mFreeBusyUrl = fbUrl; -} - -QString Contact::freeBusyUrl() const -{ - return mFreeBusyUrl; -} - -void Contact::setOrganization( const QString& organization ) -{ - mOrganization = organization; -} - -QString Contact::organization() const -{ - return mOrganization; -} - -void Contact::setWebPage( const QString& url ) -{ - mWebPage = url; -} - -QString Contact::webPage() const -{ - return mWebPage; -} - -void Contact::setIMAddress( const QString& imAddress ) -{ - mIMAddress = imAddress; -} - -QString Contact::imAddress() const -{ - return mIMAddress; -} - -void Contact::setDepartment( const QString& department ) -{ - mDepartment = department; -} - -QString Contact::department() const -{ - return mDepartment; -} - -void Contact::setOfficeLocation( const QString& location ) -{ - mOfficeLocation = location; -} - -QString Contact::officeLocation() const -{ - return mOfficeLocation; -} - -void Contact::setProfession( const QString& profession ) -{ - mProfession = profession; -} - -QString Contact::profession() const -{ - return mProfession; -} - -void Contact::setTitle( const QString& title ) -{ - mTitle = title; -} - -QString Contact::title() const -{ - return mTitle; -} - -void Contact::setManagerName( const QString& name ) -{ - mManagerName = name; -} - -QString Contact::managerName() const -{ - return mManagerName; -} - -void Contact::setAssistant( const QString& name ) -{ - mAssistant = name; -} - -QString Contact::assistant() const -{ - return mAssistant; -} - -void Contact::setNickName( const QString& name ) -{ - mNickName = name; -} - -QString Contact::nickName() const -{ - return mNickName; -} - -void Contact::setSpouseName( const QString& name ) -{ - mSpouseName = name; -} - -QString Contact::spouseName() const -{ - return mSpouseName; -} - -void Contact::setBirthday( const QDate& date ) -{ - mBirthday = date; -} - -QDate Contact::birthday() const -{ - return mBirthday; -} - -void Contact::setAnniversary( const QDate& date ) -{ - mAnniversary = date; -} - -QDate Contact::anniversary() const -{ - return mAnniversary; -} - -void Contact::setChildren( const QString& children ) -{ - mChildren = children; -} - -QString Contact::children() const -{ - return mChildren; -} - -void Contact::setGender( const QString& gender ) -{ - mGender = gender; -} - -QString Contact::gender() const -{ - return mGender; -} - -void Contact::setLanguage( const QString& language ) -{ - mLanguage = language; -} - -QString Contact::language() const -{ - return mLanguage; -} - -void Contact::addPhoneNumber( const PhoneNumber& number ) -{ - mPhoneNumbers.append( number ); -} - -QList<Contact::PhoneNumber>& Contact::phoneNumbers() -{ - return mPhoneNumbers; -} - -const QList<Contact::PhoneNumber>& Contact::phoneNumbers() const -{ - return mPhoneNumbers; -} - -void Contact::addEmail( const Email& email ) -{ - mEmails.append( email ); -} - -QList<Contact::Email>& Contact::emails() -{ - return mEmails; -} - -QString Contact::fullEmail() const -{ - return mFullEmail; -} - -const QList<Contact::Email>& Contact::emails() const -{ - return mEmails; -} - -void Contact::addAddress( const Contact::Address& address ) -{ - mAddresses.append( address ); -} - -QList<Contact::Address>& Contact::addresses() -{ - return mAddresses; -} - -const QList<Contact::Address>& Contact::addresses() const -{ - return mAddresses; -} - -void Contact::setPreferredAddress( const QString& address ) -{ - mPreferredAddress = address; -} - -QString Contact::preferredAddress() const -{ - return mPreferredAddress; -} - -bool Contact::loadNameAttribute( QDomElement& element ) -{ - for ( QDomNode n = element.firstChild(); !n.isNull(); n = n.nextSibling() ) { - if ( n.isComment() ) - continue; - if ( n.isElement() ) { - QDomElement e = n.toElement(); - QString tagName = e.tagName(); - - if ( tagName == "given-name" ) - setGivenName( e.text() ); - else if ( tagName == "middle-names" ) - setMiddleNames( e.text() ); - else if ( tagName == "last-name" ) - setLastName( e.text() ); - else if ( tagName == "full-name" ) - setFullName( e.text() ); - else if ( tagName == "initials" ) - setInitials( e.text() ); - else if ( tagName == "prefix" ) - setPrefix( e.text() ); - else if ( tagName == "suffix" ) - setSuffix( e.text() ); - else - // TODO: Unhandled tag - save for later storage - kDebug() <<"Warning: Unhandled tag" << e.tagName(); - } else - kDebug() <<"Node is not a comment or an element???"; - } - - return true; -} - -void Contact::saveNameAttribute( QDomElement& element ) const -{ - QDomElement e = element.ownerDocument().createElement( "name" ); - element.appendChild( e ); - - writeString( e, "given-name", givenName() ); - writeString( e, "middle-names", middleNames() ); - writeString( e, "last-name", lastName() ); - writeString( e, "full-name", fullName() ); - writeString( e, "initials", initials() ); - writeString( e, "prefix", prefix() ); - writeString( e, "suffix", suffix() ); -} - -bool Contact::loadPhoneAttribute( QDomElement& element ) -{ - PhoneNumber number; - for ( QDomNode n = element.firstChild(); !n.isNull(); n = n.nextSibling() ) { - if ( n.isComment() ) - continue; - if ( n.isElement() ) { - QDomElement e = n.toElement(); - QString tagName = e.tagName(); - - if ( tagName == "type" ) - number.type = e.text(); - else if ( tagName == "number" ) - number.number = e.text(); - else - // TODO: Unhandled tag - save for later storage - kDebug() <<"Warning: Unhandled tag" << e.tagName(); - } else - kDebug() <<"Node is not a comment or an element???"; - } - - addPhoneNumber( number ); - return true; -} - -void Contact::savePhoneAttributes( QDomElement& element ) const -{ - QList<PhoneNumber>::ConstIterator it = mPhoneNumbers.constBegin(); - for ( ; it != mPhoneNumbers.constEnd(); ++it ) { - QDomElement e = element.ownerDocument().createElement( "phone" ); - element.appendChild( e ); - const PhoneNumber& p = *it; - writeString( e, "type", p.type ); - writeString( e, "number", p.number ); - } -} - -void Contact::saveEmailAttributes( QDomElement& element ) const -{ - QList<Email>::ConstIterator it = mEmails.constBegin(); - for ( ; it != mEmails.constEnd(); ++it ) - saveEmailAttribute( element, *it ); -} - -void Contact::loadCustomAttributes( QDomElement& element ) -{ - Custom custom; - custom.app = element.attribute( "app" ); - custom.name = element.attribute( "name" ); - custom.value = element.attribute( "value" ); - mCustomList.append( custom ); -} - -void Contact::saveCustomAttributes( QDomElement& element ) const -{ - QList<Custom>::ConstIterator it = mCustomList.constBegin(); - for ( ; it != mCustomList.constEnd(); ++it ) { - Q_ASSERT( !(*it).name.isEmpty() ); - if ( (*it).app == s_unhandledTagAppName ) { - writeString( element, (*it).name, (*it).value ); - } else { - // Let's use attributes so that other tag-preserving-code doesn't need sub-elements - QDomElement e = element.ownerDocument().createElement( "x-custom" ); - element.appendChild( e ); - e.setAttribute( "app", (*it).app ); - e.setAttribute( "name", (*it).name ); - e.setAttribute( "value", (*it).value ); - } - } -} - -bool Contact::loadAddressAttribute( QDomElement& element ) -{ - Address address; - - for ( QDomNode n = element.firstChild(); !n.isNull(); n = n.nextSibling() ) { - if ( n.isComment() ) - continue; - if ( n.isElement() ) { - QDomElement e = n.toElement(); - QString tagName = e.tagName(); - - if ( tagName == "type" ) - address.type = e.text(); - else if ( tagName == "x-kde-type" ) - address.kdeAddressType = e.text().toInt(); - else if ( tagName == "street" ) - address.street = e.text(); - else if ( tagName == "pobox" ) - address.pobox = e.text(); - else if ( tagName == "locality" ) - address.locality = e.text(); - else if ( tagName == "region" ) - address.region = e.text(); - else if ( tagName == "postal-code" ) - address.postalCode = e.text(); - else if ( tagName == "country" ) - address.country = e.text(); - else - // TODO: Unhandled tag - save for later storage - kDebug() <<"Warning: Unhandled tag" << e.tagName(); - } else - kDebug() <<"Node is not a comment or an element???"; - } - - addAddress( address ); - return true; -} - -void Contact::saveAddressAttributes( QDomElement& element ) const -{ - QList<Address>::ConstIterator it = mAddresses.constBegin(); - for ( ; it != mAddresses.constEnd(); ++it ) { - QDomElement e = element.ownerDocument().createElement( "address" ); - element.appendChild( e ); - const Address& a = *it; - writeString( e, "type", a.type ); - writeString( e, "x-kde-type", QString::number( a.kdeAddressType ) ); - if ( !a.street.isEmpty() ) - writeString( e, "street", a.street ); - if ( !a.pobox.isEmpty() ) - writeString( e, "pobox", a.pobox ); - if ( !a.locality.isEmpty() ) - writeString( e, "locality", a.locality ); - if ( !a.region.isEmpty() ) - writeString( e, "region", a.region ); - if ( !a.postalCode.isEmpty() ) - writeString( e, "postal-code", a.postalCode ); - if ( !a.country.isEmpty() ) - writeString( e, "country", a.country ); - } -} - -bool Contact::loadAttribute( QDomElement& element ) -{ - const QString tagName = element.tagName(); - switch ( tagName[0].toLatin1() ) { - case 'a': - if ( tagName == "address" ) - return loadAddressAttribute( element ); - if ( tagName == "assistant" ) { - setAssistant( element.text() ); - return true; - } - if ( tagName == "anniversary" ) { - if ( !element.text().isEmpty() ) - setAnniversary( stringToDate( element.text() ) ); - return true; - } - break; - case 'b': - if ( tagName == "birthday" ) { - if ( !element.text().isEmpty() ) - setBirthday( stringToDate( element.text() ) ); - return true; - } - break; - case 'c': - if ( tagName == "children" ) { - setChildren( element.text() ); - return true; - } - break; - case 'd': - if ( tagName == "department" ) { - setDepartment( element.text() ); - return true; - } - break; - case 'e': - if ( tagName == "email" ) { - Email email; - if ( loadEmailAttribute( element, email ) ) { - addEmail( email ); - return true; - } else - return false; - } - break; - case 'f': - if ( tagName == "free-busy-url" ) { - setFreeBusyUrl( element.text() ); - return true; - } - break; - case 'g': - if ( tagName == "gender" ) { - setGender( element.text() ); - return true; - } - break; - case 'i': - if ( tagName == "im-address" ) { - setIMAddress( element.text() ); - return true; - } - break; - case 'j': - if ( tagName == "job-title" ) { - // see saveAttributes: <job-title> is mapped to the Role field - setTitle( element.text() ); - return true; - } - break; - case 'l': - if ( tagName == "language" ) { - setLanguage( element.text() ); - return true; - } - if ( tagName == "latitude" ) { - setLatitude( element.text().toFloat() ); - mHasGeo = true; - return true; - } - if ( tagName == "longitude" ) { - setLongitude( element.text().toFloat() ); - mHasGeo = true; - } - break; - case 'm': - if ( tagName == "manager-name" ) { - setManagerName( element.text() ); - return true; - } - case 'n': - if ( tagName == "name" ) - return loadNameAttribute( element ); - if ( tagName == "nick-name" ) { - setNickName( element.text() ); - return true; - } - break; - case 'o': - if ( tagName == "organization" ) { - setOrganization( element.text() ); - return true; - } - if ( tagName == "office-location" ) { - setOfficeLocation( element.text() ); - return true; - } - break; - case 'p': - if ( tagName == "profession" ) { - setProfession( element.text() ); - return true; - } - if ( tagName == "picture" ) { - mPictureAttachmentName = element.text(); - return true; - } - if ( tagName == "phone" ) { - return loadPhoneAttribute( element ); - return true; - } - if ( tagName == "preferred-address" ) { - setPreferredAddress( element.text() ); - return true; - } - break; - case 'r': - if ( tagName == "role" ) { - setRole( element.text() ); - return true; - } - break; - case 's': - if ( tagName == "spouse-name" ) { - setSpouseName( element.text() ); - return true; - } - break; - case 'x': - if ( tagName == "x-logo" ) { - mLogoAttachmentName = element.text(); - return true; - } - if ( tagName == "x-sound" ) { - mSoundAttachmentName = element.text(); - return true; - } - if ( tagName == "x-custom" ) { - loadCustomAttributes( element ); - return true; - } - if ( tagName == "x-title" ) { - setTitle( element.text() ); - return true; - } - break; - case 'w': - if ( tagName == "web-page" ) { - setWebPage( element.text() ); - return true; - } - break; - default: - break; - } - return KolabBase::loadAttribute( element ); -} - -bool Contact::saveAttributes( QDomElement& element ) const -{ - // Save the base class elements - KolabBase::saveAttributes( element ); - saveNameAttribute( element ); - writeString( element, "free-busy-url", freeBusyUrl() ); - writeString( element, "organization", organization() ); - writeString( element, "web-page", webPage() ); - writeString( element, "im-address", imAddress() ); - writeString( element, "department", department() ); - writeString( element, "office-location", officeLocation() ); - writeString( element, "profession", profession() ); - writeString( element, "role", role() ); - writeString( element, "job-title", title() ); - writeString( element, "manager-name", managerName() ); - writeString( element, "assistant", assistant() ); - writeString( element, "nick-name", nickName() ); - writeString( element, "spouse-name", spouseName() ); - writeString( element, "birthday", dateToString( birthday() ) ); - writeString( element, "anniversary", dateToString( anniversary() ) ); - if ( !picture().isNull() ) - writeString( element, "picture", mPictureAttachmentName ); - if ( !logo().isNull() ) - writeString( element, "x-logo", mLogoAttachmentName ); - if ( !sound().isNull() ) - writeString( element, "x-sound", mSoundAttachmentName ); - writeString( element, "children", children() ); - writeString( element, "gender", gender() ); - writeString( element, "language", language() ); - savePhoneAttributes( element ); - saveEmailAttributes( element ); - saveAddressAttributes( element ); - writeString( element, "preferred-address", preferredAddress() ); - if ( mHasGeo ) { - writeString( element, "latitude", QString::number( latitude(), 'g', DBL_DIG ) ); - writeString( element, "longitude", QString::number( longitude(), 'g', DBL_DIG ) ); - } - saveCustomAttributes( element ); - - return true; -} - -bool Contact::loadXML( const QDomDocument& document ) -{ - QDomElement top = document.documentElement(); - - if ( top.tagName() != "contact" ) { - qWarning( "XML error: Top tag was %s instead of the expected contact", - top.tagName().toAscii().data() ); - return false; - } - - for ( QDomNode n = top.firstChild(); !n.isNull(); n = n.nextSibling() ) { - if ( n.isComment() ) - continue; - if ( n.isElement() ) { - QDomElement e = n.toElement(); - if ( !loadAttribute( e ) ) { - // Unhandled tag - save for later storage - //kDebug() <<"Saving unhandled tag" << e.tagName(); - Custom c; - c.app = s_unhandledTagAppName; - c.name = e.tagName(); - c.value = e.text(); - mCustomList.append( c ); - } - } else - kDebug() <<"Node is not a comment or an element???"; - } - - return true; -} - -QString Contact::saveXML() const -{ - QDomDocument document = domTree(); - QDomElement element = document.createElement("contact" ); - element.setAttribute( "version", "1.0" ); - saveAttributes( element ); - document.appendChild( element ); - return document.toString(); -} - -static QString addressTypeToString( int /*KABC::Address::Type*/ type ) -{ - if ( type & KABC::Address::Home ) - return "home"; - if ( type & KABC::Address::Work ) - return "business"; - return "other"; -} - -static int addressTypeFromString( const QString& type ) -{ - if ( type == "home" ) - return KABC::Address::Home; - if ( type == "business" ) - return KABC::Address::Work; - // well, this shows "other" in the editor, which is what we want... - return KABC::Address::Dom | KABC::Address::Intl | KABC::Address::Postal | KABC::Address::Parcel; -} - -static QStringList phoneTypeToString( KABC::PhoneNumber::Type type ) -{ - // KABC has a bitfield, i.e. the same phone number can be used for work and home - // and fax and cellphone etc. etc. - // So when saving we need to create as many tags as bits that were set. - QStringList types; - if ( type & KABC::PhoneNumber::Fax ) { - if ( type & KABC::PhoneNumber::Home ) - types << "homefax"; - else // assume work -- if ( type & KABC::PhoneNumber::Work ) - types << "businessfax"; - type = type & ~KABC::PhoneNumber::Home; - type = type & ~KABC::PhoneNumber::Work; - } - - // To support both "home1" and "home2", map Home+Pref to home1 - if ( ( type & KABC::PhoneNumber::Home ) && ( type & KABC::PhoneNumber::Pref ) ) - { - types << "home1"; - type = type & ~KABC::PhoneNumber::Home; - type = type & ~KABC::PhoneNumber::Pref; - } - // To support both "business1" and "business2", map Work+Pref to business1 - if ( ( type & KABC::PhoneNumber::Work ) && ( type & KABC::PhoneNumber::Pref ) ) - { - types << "business1"; - type = type & ~KABC::PhoneNumber::Work; - type = type & ~KABC::PhoneNumber::Pref; - } - - - if ( type & KABC::PhoneNumber::Home ) - types << "home2"; - if ( type & KABC::PhoneNumber::Msg ) // Msg==messaging - types << "company"; - if ( type & KABC::PhoneNumber::Work ) - types << "business2"; - if ( type & KABC::PhoneNumber::Pref ) - types << "primary"; - if ( type & KABC::PhoneNumber::Voice ) - types << "callback"; // ## - if ( type & KABC::PhoneNumber::Cell ) - types << "mobile"; - if ( type & KABC::PhoneNumber::Video ) - types << "radio"; // ## - if ( type & KABC::PhoneNumber::Bbs ) - types << "ttytdd"; - if ( type & KABC::PhoneNumber::Modem ) - types << "telex"; // # - if ( type & KABC::PhoneNumber::Car ) - types << "car"; - if ( type & KABC::PhoneNumber::Isdn ) - types << "isdn"; - if ( type & KABC::PhoneNumber::Pcs ) - types << "assistant"; // ## Assistant is e.g. secretary - if ( type & KABC::PhoneNumber::Pager ) - types << "pager"; - return types; -} - -static KABC::PhoneNumber::Type phoneTypeFromString( const QString& type ) -{ - if ( type == "homefax" ) - return KABC::PhoneNumber::Home | KABC::PhoneNumber::Fax; - if ( type == "businessfax" ) - return KABC::PhoneNumber::Work | KABC::PhoneNumber::Fax; - if ( type == "business1" ) - return KABC::PhoneNumber::Work | KABC::PhoneNumber::Pref; - if ( type == "business2" ) - return KABC::PhoneNumber::Work; - if ( type == "home1" ) - return KABC::PhoneNumber::Home | KABC::PhoneNumber::Pref; - if ( type == "home2" ) - return KABC::PhoneNumber::Home; - if ( type == "company" ) - return KABC::PhoneNumber::Msg; - if ( type == "primary" ) - return KABC::PhoneNumber::Pref; - if ( type == "callback" ) - return KABC::PhoneNumber::Voice; - if ( type == "mobile" ) - return KABC::PhoneNumber::Cell; - if ( type == "radio" ) - return KABC::PhoneNumber::Video; - if ( type == "ttytdd" ) - return KABC::PhoneNumber::Bbs; - if ( type == "telex" ) - return KABC::PhoneNumber::Modem; - if ( type == "car" ) - return KABC::PhoneNumber::Car; - if ( type == "isdn" ) - return KABC::PhoneNumber::Isdn; - if ( type == "assistant" ) - return KABC::PhoneNumber::Pcs; - if ( type == "pager" ) - return KABC::PhoneNumber::Pager; - return KABC::PhoneNumber::Home; // whatever -} - -static const char* s_knownCustomFields[] = { - "X-IMAddress", - "X-Office", - "X-Profession", - "X-ManagersName", - "X-AssistantsName", - "X-SpousesName", - "X-Anniversary", - "DistributionList", - 0 -}; - - -// The saving is addressee -> Contact -> xml, this is the first part -void Contact::setFields( const KABC::Addressee* addressee ) -{ - KolabBase::setFields( addressee ); - - setGivenName( addressee->givenName() ); - setMiddleNames( addressee->additionalName() ); - setLastName( addressee->familyName() ); - setFullName( addressee->formattedName() ); - setPrefix( addressee->prefix() ); - setSuffix( addressee->suffix() ); - setOrganization( addressee->organization() ); - setWebPage( addressee->url().url() ); - setIMAddress( addressee->custom( "KADDRESSBOOK", "X-IMAddress" ) ); - setDepartment( addressee->department()); - setOfficeLocation( addressee->custom( "KADDRESSBOOK", "X-Office" ) ); - setProfession( addressee->custom( "KADDRESSBOOK", "X-Profession" ) ); - setRole( addressee->role() ); - setTitle( addressee->title() ); - setManagerName( addressee->custom( "KADDRESSBOOK", "X-ManagersName" ) ); - setAssistant( addressee->custom( "KADDRESSBOOK", "X-AssistantsName" ) ); - setNickName( addressee->nickName() ); - setSpouseName( addressee->custom( "KADDRESSBOOK", "X-SpousesName" ) ); - if ( !addressee->birthday().isNull() ) - setBirthday( addressee->birthday().date() ); - const QString& anniversary = addressee->custom( "KADDRESSBOOK", "X-Anniversary" ); - if ( !anniversary.isEmpty() ) - setAnniversary( stringToDate( anniversary ) ); - - const QStringList emails = addressee->emails(); - // Conversion problem here: - // KABC::Addressee has only one full name and N addresses, but the XML format - // has N times (fullname+address). So we just copy the fullname over and ignore it on loading. - for ( QStringList::ConstIterator it = emails.constBegin(); it != emails.constEnd(); ++it ) { - Email email; - email.displayName = fullName(); - email.smtpAddress = *it; - addEmail( email ); - } - - // save formatted full email for later usage - mFullEmail = addressee->fullEmail(); - - // Now the real-world addresses - QString preferredAddress = "home"; - const KABC::Address::List addresses = addressee->addresses(); - for ( KABC::Address::List::ConstIterator it = addresses.constBegin() ; it != addresses.constEnd(); ++it ) { - Address address; - address.kdeAddressType = (*it).type(); - address.type = addressTypeToString( address.kdeAddressType ); - address.street = (*it).street(); - address.pobox = (*it).postOfficeBox(); - address.locality = (*it).locality(); - address.region = (*it).region(); - address.postalCode = (*it).postalCode(); - address.country = (*it).country(); - // ## TODO not in the XML format: extended address info. - // ## KDE-specific tags? Or hiding those fields? Or adding a warning? - addAddress( address ); - if ( address.kdeAddressType & KABC::Address::Pref ) { - preferredAddress = address.type; // home, business or other - } - } - setPreferredAddress( preferredAddress ); - - const KABC::PhoneNumber::List phones = addressee->phoneNumbers(); - for ( KABC::PhoneNumber::List::ConstIterator it = phones.constBegin(); it != phones.constEnd(); ++it ) { - // Create a tag per phone type set in the bitfield - QStringList types = phoneTypeToString( (*it).type() ); - for( QStringList::ConstIterator typit = types.constBegin(); typit != types.constEnd(); ++typit ) { - PhoneNumber phoneNumber; - phoneNumber.type = *typit; - phoneNumber.number = (*it).number(); - addPhoneNumber( phoneNumber ); - } - } - - setPicture( loadPictureFromAddressee( addressee->photo() ), addressee->photo().type() ); - mPictureAttachmentName = addressee->custom( "KOLAB", "PictureAttachmentName" ); - if ( mPictureAttachmentName.isEmpty() ) - mPictureAttachmentName = s_pictureAttachmentName; - - setLogo( loadPictureFromAddressee( addressee->logo() ), addressee->logo().type() ); - mLogoAttachmentName = addressee->custom( "KOLAB", "LogoAttachmentName" ); - if ( mLogoAttachmentName.isEmpty() ) - mLogoAttachmentName = s_logoAttachmentName; - - setSound( loadSoundFromAddressee( addressee->sound() ) ); - mSoundAttachmentName = addressee->custom( "KOLAB", "SoundAttachmentName" ); - if ( mSoundAttachmentName.isEmpty() ) - mSoundAttachmentName = s_soundAttachmentName; - - if ( addressee->geo().isValid() ) { - setLatitude( addressee->geo().latitude() ); - setLongitude( addressee->geo().longitude() ); - mHasGeo = true; - } - - // Other KADDRESSBOOK custom fields than those already handled - // (includes e.g. crypto settings, and extra im addresses) - QStringList knownCustoms; - for ( const char** p = s_knownCustomFields; *p; ++p ) - knownCustoms << QString::fromLatin1( *p ); - QStringList customs = addressee->customs(); - for( QStringList::ConstIterator it = customs.constBegin(); it != customs.constEnd(); ++it ) { - // KABC::Addressee doesn't offer a real way to iterate over customs, other than splitting strings ourselves - // The format is "app-name:value". - int pos = (*it).indexOf( '-' ); - if ( pos == -1 ) continue; - QString app = (*it).left( pos ); - if ( app == "KOLAB" ) continue; - QString name = (*it).mid( pos + 1 ); - pos = name.indexOf( ':' ); - if ( pos == -1 ) continue; - QString value = name.mid( pos + 1 ); - name = name.left( pos ); - if ( !knownCustoms.contains( name ) ) { - //kDebug() <<"app=" << app <<" name=" << name <<" value=" << value; - Custom c; - if ( app != "KADDRESSBOOK" ) // that's the default - c.app = app; - c.name = name; - c.value = value; - mCustomList.append( c ); - } - } - - const QString url = addressee->custom("KOLAB", "FreebusyUrl"); - if ( !url.isEmpty() ) { - setFreeBusyUrl( url ); - } - - // Those fields, although defined in Addressee, are not used in KDE - // (e.g. not visible in kaddressbook/addresseeeditorwidget.cpp) - // So it doesn't matter much if we don't have them in the XML. - // mailer, timezone, productId, sortString, agent, rfc2426 name() - - // Things KAddressBook can't handle, so they are saved as unhandled tags: - // initials, children, gender, language -} - - -// The loading is: xml -> Contact -> addressee, this is the second part -void Contact::saveTo( KABC::Addressee* addressee ) -{ - // TODO: This needs the same set of TODOs as the setFields method - KolabBase::saveTo( addressee ); - - addressee->setGivenName( givenName() ); - addressee->setAdditionalName( middleNames() ); - addressee->setFamilyName( lastName() ); - addressee->setFormattedName( fullName() ); - addressee->setPrefix( prefix() ); - addressee->setSuffix( suffix() ); - addressee->setOrganization( organization() ); - addressee->setUrl( webPage() ); - addressee->insertCustom( "KADDRESSBOOK", "X-IMAddress", imAddress() ); - addressee->setDepartment( department() ); - addressee->insertCustom( "KADDRESSBOOK", "X-Office", officeLocation() ); - addressee->insertCustom( "KADDRESSBOOK", "X-Profession", profession() ); - addressee->setRole( role() ); - addressee->setTitle( title() ); - addressee->insertCustom( "KADDRESSBOOK", "X-ManagersName", managerName() ); - addressee->insertCustom( "KADDRESSBOOK", "X-AssistantsName", assistant() ); - addressee->setNickName( nickName() ); - addressee->insertCustom( "KADDRESSBOOK", "X-SpousesName", spouseName() ); - if ( birthday().isValid() ) - addressee->setBirthday( QDateTime( birthday() ) ); - - if ( anniversary().isValid() ) - addressee->insertCustom( "KADDRESSBOOK", "X-Anniversary", - dateToString( anniversary() ) ); - else - addressee->removeCustom( "KADDRESSBOOK", "X-Anniversary" ); - - addressee->insertCustom( "KOLAB", "FreebusyUrl", freeBusyUrl() ); - - // We need to store both the original attachment name and the picture data into the addressee. - // This is important, otherwise we would save the image under another attachment name w/o deleting the original one! - if ( !mPicture.isNull() ) { - KABC::Picture picture( mPicture ); - addressee->setPhoto( picture ); - } - // Note that we must save the filename in all cases, so that removing the picture - // actually deletes the attachment. - addressee->insertCustom( "KOLAB", "PictureAttachmentName", mPictureAttachmentName ); - if ( !mLogo.isNull() ) { - KABC::Picture picture( mLogo ); - addressee->setLogo( picture ); - } - addressee->insertCustom( "KOLAB", "LogoAttachmentName", mLogoAttachmentName ); - if ( !mSound.isNull() ) - addressee->setSound( KABC::Sound( mSound ) ); - addressee->insertCustom( "KOLAB", "SoundAttachmentName", mSoundAttachmentName ); - - if ( mHasGeo ) - addressee->setGeo( KABC::Geo( mLatitude, mLongitude ) ); - - QStringList emailAddresses; - for ( QList<Email>::ConstIterator it = mEmails.constBegin(); it != mEmails.constEnd(); ++it ) { - // we can't do anything with (*it).displayName - emailAddresses.append( (*it).smtpAddress ); - } - addressee->setEmails( emailAddresses ); - - for ( QList<Address>::ConstIterator it = mAddresses.constBegin(); it != mAddresses.constEnd(); ++it ) { - KABC::Address address; - int type = (*it).kdeAddressType; - if ( type == -1 ) { // no kde-specific type available - type = addressTypeFromString( (*it).type ); - if ( (*it).type == mPreferredAddress ) - type |= KABC::Address::Pref; - } - address.setType( static_cast<KABC::Address::Type>(type) ); - address.setStreet( (*it).street ); - address.setPostOfficeBox( (*it).pobox ); - address.setLocality( (*it).locality ); - address.setRegion( (*it).region ); - address.setPostalCode( (*it).postalCode ); - address.setCountry( (*it).country ); - addressee->insertAddress( address ); - } - - for ( QList<PhoneNumber>::ConstIterator it = mPhoneNumbers.constBegin(); it != mPhoneNumbers.constEnd(); ++it ) { - KABC::PhoneNumber number; - number.setType( phoneTypeFromString( (*it).type ) ); - number.setNumber( (*it).number ); - addressee->insertPhoneNumber( number ); - } - - for( QList<Custom>::ConstIterator it = mCustomList.constBegin(); it != mCustomList.constEnd(); ++it ) { - QString app = (*it).app.isEmpty() ? QString::fromLatin1( "KADDRESSBOOK" ) : (*it).app; - addressee->insertCustom( app, (*it).name, (*it).value ); - } - //kDebug() << addressee->customs(); -} - -QImage Contact::loadPictureFromAddressee( const KABC::Picture& picture ) -{ - QImage img; - if ( !picture.isIntern() && !picture.url().isEmpty() ) { - QString tmpFile; - kWarning() << "external pictures are currently not supported"; - //FIXME add kio support to libcalendaring or use libcurl -// if ( KIO::NetAccess::download( picture.url(), tmpFile, 0 /*no widget known*/ ) ) { -// img.load( tmpFile ); -// KIO::NetAccess::removeTempFile( tmpFile ); -// } - } else - img = picture.data(); - return img; -} - -QByteArray KolabV2::Contact::loadSoundFromAddressee( const KABC::Sound& sound ) -{ - QByteArray data; - if ( !sound.isIntern() && !sound.url().isEmpty() ) { - QString tmpFile; -// if ( KIO::NetAccess::download( sound.url(), tmpFile, 0 /*no widget known*/ ) ) { -// QFile f( tmpFile ); -// if ( f.open( QIODevice::ReadOnly ) ) { -// data = f.readAll(); -// f.close(); -// } -// KIO::NetAccess::removeTempFile( tmpFile ); -// } - } else - data = sound.data(); - return data; -} - -QString KolabV2::Contact::productID() const -{ - // TODO: When KAB has the version number in a header file, don't hardcode (Bo) - // Or we could use Addressee::productID? (David) - return "KAddressBook 3.3, Kolab resource"; -}
View file
libkolab-2.0.tar.gz/kolabformatV2/contact.h
Deleted
@@ -1,278 +0,0 @@ -/* - This file is part of libkabc and/or kaddressbook. - Copyright (c) 2002 - 2004 Klarälvdalens Datakonsult AB - <info@klaralvdalens-datakonsult.se> - - 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 Qt library by Trolltech AS, Norway (or with modified versions - of Qt that use the same license as Qt), 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 - Qt. 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 KOLABV2CONTACT_H -#define KOLABV2CONTACT_H - -#include "kolabbase.h" -#include <qimage.h> - -namespace KABC { - class Addressee; - class Picture; - class Sound; -} - -namespace KolabV2 { - -class Contact : public KolabBase { -public: - struct PhoneNumber { - public: - QString type; - QString number; - }; - - struct Address { - public: - Address() : kdeAddressType( -1 ) - { - } - int kdeAddressType; // KABC::Address::Type - QString type; // kolab-compliant address type: home, work or other - QString street; - QString pobox; - QString locality; - QString region; - QString postalCode; - QString country; - }; - - explicit Contact( const KABC::Addressee* address ); - Contact( const QString& xml ); - ~Contact(); - - void saveTo( KABC::Addressee* address ); - - QString type() const { return "Contact"; } - - void setGivenName( const QString& name ); - QString givenName() const; - - void setMiddleNames( const QString& names ); - QString middleNames() const; - - void setLastName( const QString& name ); - QString lastName() const; - - void setFullName( const QString& name ); - QString fullName() const; - - void setInitials( const QString& initials ); - QString initials() const; - - void setPrefix( const QString& prefix ); - QString prefix() const; - - void setSuffix( const QString& suffix ); - QString suffix() const; - - void setRole( const QString& role ); - QString role() const; - - void setFreeBusyUrl( const QString& fbUrl ); - QString freeBusyUrl() const; - - void setOrganization( const QString& organization ); - QString organization() const; - - void setWebPage( const QString& url ); - QString webPage() const; - - void setIMAddress( const QString& imAddress ); - QString imAddress() const; - - void setDepartment( const QString& department ); - QString department() const; - - void setOfficeLocation( const QString& location ); - QString officeLocation() const; - - void setProfession( const QString& profession ); - QString profession() const; - - void setTitle( const QString& title ); - QString title() const; - - void setManagerName( const QString& name ); - QString managerName() const; - - void setAssistant( const QString& name ); - QString assistant() const; - - void setNickName( const QString& name ); - QString nickName() const; - - void setSpouseName( const QString& name ); - QString spouseName() const; - - void setBirthday( const QDate& date ); - QDate birthday() const; - - void setAnniversary( const QDate& date ); - QDate anniversary() const; - - void setPicture( const QImage& image, const QString &format) { mPicture = image; mPictureFormat = format; } - QString pictureAttachmentName() const { return mPictureAttachmentName; } - QString pictureFormat() const { return mPictureFormat; } - QImage picture() const { return mPicture; } - - void setLogo( const QImage& image, const QString &format ) { mLogo = image; mLogoFormat = format; } - QString logoAttachmentName() const { return mLogoAttachmentName; } - QString logoFormat() const { return mLogoFormat; } - QImage logo() const { return mLogo; } - - void setSound( const QByteArray& sound ) { mSound = sound; } - QString soundAttachmentName() const { return mSoundAttachmentName; } - QByteArray sound() const { return mSound; } - - void setChildren( const QString& children ); - QString children() const; - - void setGender( const QString& gender ); - QString gender() const; - - void setLanguage( const QString& language ); - QString language() const; - - void addPhoneNumber( const PhoneNumber& number ); - QList<PhoneNumber>& phoneNumbers(); - const QList<PhoneNumber>& phoneNumbers() const; - - void addEmail( const Email& email ); - QList<Email>& emails(); - const QList<Email>& emails() const; - - QString fullEmail() const; - - void addAddress( const Address& address ); - QList<Address>& addresses(); - const QList<Address>& addresses() const; - - // which address is preferred: home or business or other - void setPreferredAddress( const QString& address ); - QString preferredAddress() const; - - float latitude() const { return mLatitude; } - void setLatitude( float latitude ) { mLatitude = latitude; } - - float longitude() const { return mLongitude; } - void setLongitude( float longitude ) { mLongitude = longitude; } - - // Load the attributes of this class - bool loadAttribute( QDomElement& ); - - // Save the attributes of this class - bool saveAttributes( QDomElement& ) const; - - // Load this note by reading the XML file - bool loadXML( const QDomDocument& xml ); - - // Serialize this note to an XML string - QString saveXML() const; - -protected: - void setFields( const KABC::Addressee* ); - -private: - bool loadNameAttribute( QDomElement& element ); - void saveNameAttribute( QDomElement& element ) const; - - bool loadPhoneAttribute( QDomElement& element ); - void savePhoneAttributes( QDomElement& element ) const; - - void saveEmailAttributes( QDomElement& element ) const; - - bool loadAddressAttribute( QDomElement& element ); - void saveAddressAttributes( QDomElement& element ) const; - - void loadCustomAttributes( QDomElement& element ); - void saveCustomAttributes( QDomElement& element ) const; - - QImage loadPictureFromAddressee( const KABC::Picture& picture ); - - QByteArray loadSoundFromAddressee( const KABC::Sound& sound ); - - QString productID() const; - - QString mGivenName; - QString mMiddleNames; - QString mLastName; - QString mFullName; - QString mInitials; - QString mPrefix; - QString mSuffix; - QString mRole; - QString mFreeBusyUrl; - QString mOrganization; - QString mWebPage; - QString mIMAddress; - QString mDepartment; - QString mOfficeLocation; - QString mProfession; - QString mTitle; - QString mManagerName; - QString mAssistant; - QString mNickName; - QString mSpouseName; - QDate mBirthday; - QDate mAnniversary; - QImage mPicture; - QString mPictureFormat; - QImage mLogo; - QString mLogoFormat; - QByteArray mSound; - QString mPictureAttachmentName; - QString mLogoAttachmentName; - QString mSoundAttachmentName; - QString mChildren; - QString mGender; - QString mLanguage; - QList<PhoneNumber> mPhoneNumbers; - QList<Email> mEmails; - QString mFullEmail; - QList<Address> mAddresses; - QString mPreferredAddress; - float mLatitude; - float mLongitude; - bool mHasGeo; - struct Custom { - QString app; - QString name; - QString value; - }; - QList<Custom> mCustomList; -}; - -} - -#endif // KOLABCONTACT_H
View file
libkolab-2.0.tar.gz/kolabformatV2/distributionlist.cpp
Deleted
@@ -1,231 +0,0 @@ -/* - This file is part of Akonadi KolabProxy. - Copyright (c) 2009 Kevin Krammer <kevin.krammer@gmx.at> - - 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 Qt library by Trolltech AS, Norway (or with modified versions - of Qt that use the same license as Qt), 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 - Qt. 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 "distributionlist.h" - -#include <kabc/addressee.h> -#include <kabc/contactgroup.h> -#include <kdebug.h> - -using namespace KolabV2; - -static const char* s_unhandledTagAppName = "KOLABUNHANDLED"; // no hyphens in appnames! - -// saving (contactgroup->xml) -DistributionList::DistributionList( const KABC::ContactGroup* contactGroup ) -{ - setFields( contactGroup ); -} - -// loading (xml->contactgroup) -DistributionList::DistributionList( const QString& xml ) -{ - load( xml ); -} - -DistributionList::~DistributionList() -{ -} - -void DistributionList::setName( const QString& name ) -{ - mName = name; -} - -QString DistributionList::name() const -{ - return mName; -} - -void KolabV2::DistributionList::loadDistrListMember( const QDomElement& element ) -{ - Member member; - for ( QDomNode n = element.firstChild(); !n.isNull(); n = n.nextSibling() ) { - if ( n.isComment() ) - continue; - if ( n.isElement() ) { - QDomElement e = n.toElement(); - QString tagName = e.tagName(); - if ( tagName == "display-name" ) - member.displayName = e.text(); - else if ( tagName == "smtp-address" ) - member.email = e.text(); - else if ( tagName == "uid" ) - member.uid = e.text(); - } - } - mDistrListMembers.append( member ); -} - -void DistributionList::saveDistrListMembers( QDomElement& element ) const -{ - QList<Member>::ConstIterator it = mDistrListMembers.constBegin(); - for( ; it != mDistrListMembers.constEnd(); ++it ) { - QDomElement e = element.ownerDocument().createElement( "member" ); - element.appendChild( e ); - const Member& m = *it; - if (!m.uid.isEmpty()) { - writeString( e, "uid", m.uid ); - } else { - writeString( e, "display-name", m.displayName ); - writeString( e, "smtp-address", m.email ); - } - } -} - -bool DistributionList::loadAttribute( QDomElement& element ) -{ - const QString tagName = element.tagName(); - switch ( tagName[0].toLatin1() ) { - case 'd': - if ( tagName == "display-name" ) { - setName( element.text() ); - return true; - } - break; - case 'm': - if ( tagName == "member" ) { - loadDistrListMember( element ); - return true; - } - break; - default: - break; - } - return KolabBase::loadAttribute( element ); -} - -bool DistributionList::saveAttributes( QDomElement& element ) const -{ - // Save the base class elements - KolabBase::saveAttributes( element ); - writeString( element, "display-name", name() ); - saveDistrListMembers( element ); - - return true; -} - -bool DistributionList::loadXML( const QDomDocument& document ) -{ - QDomElement top = document.documentElement(); - - if ( top.tagName() != "distribution-list" ) { - qWarning( "XML error: Top tag was %s instead of the expected distribution-list", - top.tagName().toAscii().data() ); - return false; - } - - - for ( QDomNode n = top.firstChild(); !n.isNull(); n = n.nextSibling() ) { - if ( n.isComment() ) - continue; - if ( n.isElement() ) { - QDomElement e = n.toElement(); - if ( !loadAttribute( e ) ) { - // Unhandled tag - save for later storage - //kDebug() <<"Saving unhandled tag" << e.tagName(); - Custom c; - c.app = s_unhandledTagAppName; - c.name = e.tagName(); - c.value = e.text(); - mCustomList.append( c ); - } - } else - kDebug() <<"Node is not a comment or an element???"; - } - - return true; -} - -QString DistributionList::saveXML() const -{ - QDomDocument document = domTree(); - QDomElement element = document.createElement( "distribution-list" ); - element.setAttribute( "version", "1.0" ); - saveAttributes( element ); - document.appendChild( element ); - return document.toString(); -} - -QString DistributionList::productID() const -{ - // TODO should we get name/version from desktop file? - return QLatin1String( "Akonadi Kolab Proxy" ); -} - -// The saving is contactgroup -> DistributionList -> xml, this is the first part -void DistributionList::setFields( const KABC::ContactGroup* contactGroup ) -{ - KolabBase::setFields( contactGroup ); - - setName( contactGroup->name() ); - - // explicit contact data - for ( uint index = 0; index < contactGroup->dataCount(); ++index ) { - const KABC::ContactGroup::Data& data = contactGroup->data( index ); - - Member m; - m.displayName = data.name(); - m.email = data.email(); - - mDistrListMembers.append( m ); - } - for ( uint index = 0; index < contactGroup->contactReferenceCount(); ++index ) { - const KABC::ContactGroup::ContactReference& data = contactGroup->contactReference( index ); - - Member m; - m.uid = data.uid(); - - mDistrListMembers.append( m ); - } - if (contactGroup->contactGroupReferenceCount() > 0) { - kWarning() << "Tried to save contact group references, which should have been resolved already"; - } -} - -// The loading is: xml -> DistributionList -> contactgroup, this is the second part -void DistributionList::saveTo( KABC::ContactGroup* contactGroup ) -{ - KolabBase::saveTo( contactGroup ); - - contactGroup->setName( name() ); - - QList<Member>::ConstIterator mit = mDistrListMembers.constBegin(); - for ( ; mit != mDistrListMembers.constEnd(); ++mit ) { - if (!(*mit).uid.isEmpty()) { - contactGroup->append(KABC::ContactGroup::ContactReference( (*mit).uid )); - } else { - contactGroup->append(KABC::ContactGroup::Data( (*mit).displayName, (*mit).email )); - } - } -} - -// kate: space-indent on; indent-width 2; replace-tabs on;
View file
libkolab-2.0.tar.gz/kolabformatV2/distributionlist.h
Deleted
@@ -1,97 +0,0 @@ -/* - This file is part of Akonadi KolabProxy - Copyright (c) 2009 <kevin.krammer@gmx.at> - - 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 Qt library by Trolltech AS, Norway (or with modified versions - of Qt that use the same license as Qt), 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 - Qt. 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 KOLABV2DISTRIBUTIONLIST_H -#define KOLABV2DISTRIBUTIONLIST_H - -#include "kolabbase.h" - -namespace KABC { - class ContactGroup; -} - -namespace KolabV2 { - -class DistributionList : public KolabBase { -public: - explicit DistributionList( const KABC::ContactGroup* contactGroup ); - DistributionList( const QString& xml ); - ~DistributionList(); - - void saveTo( KABC::ContactGroup* contactGroup ); - - QString type() const { return "DistributionList"; } - - void setName( const QString& name ); - QString name() const; - - // Load the attributes of this class - bool loadAttribute( QDomElement& ); - - // Save the attributes of this class - bool saveAttributes( QDomElement& ) const; - - // Load this note by reading the XML file - bool loadXML( const QDomDocument& xml ); - - // Serialize this note to an XML string - QString saveXML() const; - - QString productID() const; - -protected: - void setFields( const KABC::ContactGroup* ); - -private: - void loadDistrListMember( const QDomElement& element ); - void saveDistrListMembers( QDomElement& element ) const; - - QString mName; - - struct Custom { - QString app; - QString name; - QString value; - }; - QList<Custom> mCustomList; - - struct Member { - QString displayName; - QString email; - QString uid; - }; - QList<Member> mDistrListMembers; -}; - -} - -#endif // KOLABDISTRIBUTIONLIST_H -// kate: space-indent on; indent-width 2; replace-tabs on;
View file
libkolab-2.0.tar.gz/kolabformatV2/event.cpp
Deleted
@@ -1,221 +0,0 @@ -/* - This file is part of the kolab resource - the implementation of the - Kolab storage format. See www.kolab.org for documentation on this. - - Copyright (c) 2004 Bo Thorsen <bo@sonofthor.dk> - - 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 Qt library by Trolltech AS, Norway (or with modified versions - of Qt that use the same license as Qt), 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 - Qt. 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 "event.h" - -#include <kcalcore/event.h> -#include <kdebug.h> - -using namespace KolabV2; - - -KCalCore::Event::Ptr Event::fromXml( const QDomDocument& xmlDoc, const QString& tz) -{ - Event event( tz ); - event.loadXML( xmlDoc ); - KCalCore::Event::Ptr kcalEvent( new KCalCore::Event() ); - event.saveTo( kcalEvent ); - return kcalEvent; -} - -QString Event::eventToXML( const KCalCore::Event::Ptr &kcalEvent, const QString& tz ) -{ - Event event( tz, kcalEvent ); - return event.saveXML(); -} - -Event::Event( const QString& tz, const KCalCore::Event::Ptr &event ) - : Incidence( tz, event ), - mShowTimeAs( KCalCore::Event::Opaque ), mHasEndDate( false ) -{ - if ( event ) { - setFields( event ); - } -} - -Event::~Event() -{ -} - -void Event::setTransparency( KCalCore::Event::Transparency transparency ) -{ - mShowTimeAs = transparency; -} - -KCalCore::Event::Transparency Event::transparency() const -{ - return mShowTimeAs; -} - -void Event::setEndDate( const KDateTime& date ) -{ - mEndDate = date; - mHasEndDate = true; - if ( mFloatingStatus == AllDay ) - kDebug() <<"ERROR: Time on end date but no time on the event"; - mFloatingStatus = HasTime; -} - -void Event::setEndDate( const QDate& date ) -{ - mEndDate = KDateTime( date ); - mHasEndDate = true; - if ( mFloatingStatus == HasTime ) - kDebug() <<"ERROR: No time on end date but time on the event"; - mFloatingStatus = AllDay; -} - -void Event::setEndDate( const QString& endDate ) -{ - if ( endDate.length() > 10 ) - // This is a date + time - setEndDate( stringToDateTime( endDate ) ); - else - // This is only a date - setEndDate( stringToDate( endDate ) ); -} - -KDateTime Event::endDate() const -{ - return mEndDate; -} - -bool Event::loadAttribute( QDomElement& element ) -{ - // This method doesn't handle the color-label tag yet - QString tagName = element.tagName(); - - if ( tagName == "show-time-as" ) { - // TODO: Support tentative and outofoffice - if ( element.text() == "free" ) - setTransparency( KCalCore::Event::Transparent ); - else - setTransparency( KCalCore::Event::Opaque ); - } else if ( tagName == "end-date" ) - setEndDate( element.text() ); - else - return Incidence::loadAttribute( element ); - - // We handled this - return true; -} - -bool Event::saveAttributes( QDomElement& element ) const -{ - // Save the base class elements - Incidence::saveAttributes( element ); - - // TODO: Support tentative and outofoffice - if ( transparency() == KCalCore::Event::Transparent ) - writeString( element, "show-time-as", "free" ); - else - writeString( element, "show-time-as", "busy" ); - if ( mHasEndDate ) { - if ( mFloatingStatus == HasTime ) - writeString( element, "end-date", dateTimeToString( endDate() ) ); - else - writeString( element, "end-date", dateToString( endDate().date() ) ); - } - - return true; -} - - -bool Event::loadXML( const QDomDocument& document ) -{ - QDomElement top = document.documentElement(); - - if ( top.tagName() != "event" ) { - qWarning( "XML error: Top tag was %s instead of the expected event", - top.tagName().toAscii().data() ); - return false; - } - - for ( QDomNode n = top.firstChild(); !n.isNull(); n = n.nextSibling() ) { - if ( n.isComment() ) - continue; - if ( n.isElement() ) { - QDomElement e = n.toElement(); - loadAttribute( e ); - } else - kDebug() <<"Node is not a comment or an element???"; - } - - return true; -} - -QString Event::saveXML() const -{ - QDomDocument document = domTree(); - QDomElement element = document.createElement( "event" ); - element.setAttribute( "version", "1.0" ); - saveAttributes( element ); - document.appendChild( element ); - return document.toString(); -} - -void Event::setFields( const KCalCore::Event::Ptr &event ) -{ - Incidence::setFields( event ); - - // note: if hasEndDate() is false and hasDuration() is true - // dtEnd() returns start+duration - if ( event->hasEndDate() || event->hasDuration() ) { - if ( event->allDay() ) { - // This is an all-day event. Don't timezone move this one - mFloatingStatus = AllDay; - setEndDate( event->dtEnd().date() ); - } else { - mFloatingStatus = HasTime; - setEndDate( localToUTC( event->dtEnd() ) ); - } - } else { - mHasEndDate = false; - } - setTransparency( event->transparency() ); -} - -void Event::saveTo( const KCalCore::Event::Ptr &event ) -{ - Incidence::saveTo( event ); - - event->setHasEndDate( mHasEndDate ); - if ( mHasEndDate ) { - if ( mFloatingStatus == AllDay ) - // This is an all-day event. Don't timezone move this one - event->setDtEnd( endDate() ); - else - event->setDtEnd( utcToLocal( endDate() ) ); - } - event->setTransparency( transparency() ); -}
View file
libkolab-2.0.tar.gz/kolabformatV2/event.h
Deleted
@@ -1,101 +0,0 @@ -/* - This file is part of the kolab resource - the implementation of the - Kolab storage format. See www.kolab.org for documentation on this. - - Copyright (c) 2004 Bo Thorsen <bo@sonofthor.dk> - - 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 Qt library by Trolltech AS, Norway (or with modified versions - of Qt that use the same license as Qt), 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 - Qt. 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 KOLABV2_EVENT_H -#define KOLABV2_EVENT_H - -#include "incidence.h" - -#include <kcalcore/event.h> - -class QDomElement; - - -namespace KolabV2 { - -/** - * This class represents an event, and knows how to load/save it - * from/to XML, and from/to a KCalCore::Event. - * The instances of this class are temporary, only used to convert - * one to the other. - */ -class Event : public Incidence { -public: - /// Use this to parse an xml string to a event entry - /// The caller is responsible for deleting the returned event - static KCalCore::Event::Ptr fromXml( const QDomDocument& xmlDoc, const QString& tz); - - /// Use this to get an xml string describing this event entry - static QString eventToXML( const KCalCore::Event::Ptr &, const QString& tz ); - - /// Create a event object and - explicit Event( const QString& tz, - const KCalCore::Event::Ptr &event = KCalCore::Event::Ptr() ); - virtual ~Event(); - - void saveTo( const KCalCore::Event::Ptr &event ); - - virtual QString type() const { return "Event"; } - - virtual void setTransparency( KCalCore::Event::Transparency transparency ); - virtual KCalCore::Event::Transparency transparency() const; - - virtual void setEndDate( const KDateTime& date ); - virtual void setEndDate( const QDate& date ); - virtual void setEndDate( const QString& date ); - virtual KDateTime endDate() const; - - // Load the attributes of this class - virtual bool loadAttribute( QDomElement& ); - - // Save the attributes of this class - virtual bool saveAttributes( QDomElement& ) const; - - // Load this event by reading the XML file - virtual bool loadXML( const QDomDocument& xml ); - - // Serialize this event to an XML string - virtual QString saveXML() const; - -protected: - // Read all known fields from this ical incidence - void setFields( const KCalCore::Event::Ptr & ); - - KCalCore::Event::Transparency mShowTimeAs; - KDateTime mEndDate; - bool mHasEndDate; -}; - -} - -#endif // KOLAB_EVENT_H
View file
libkolab-2.0.tar.gz/kolabformatV2/incidence.cpp
Deleted
@@ -1,1025 +0,0 @@ -/* - This file is part of the kolab resource - the implementation of the - Kolab storage format. See www.kolab.org for documentation on this. - - Copyright (c) 2004 Bo Thorsen <bo@sonofthor.dk> - - 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 Qt library by Trolltech AS, Norway (or with modified versions - of Qt that use the same license as Qt), 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 - Qt. 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 "incidence.h" -#include "libkolab-version.h" - -#include <QList> - -#include <kcalcore/journal.h> -#include <kdebug.h> -#include <kurl.h> - -#include <QBitArray> -#include <string> -#include <boost/algorithm/string.hpp> - -using namespace KolabV2; - -Incidence::Incidence( const QString& tz, const KCalCore::Incidence::Ptr &incidence ) - : KolabBase( tz ), mFloatingStatus( Unset ), mHasAlarm( false ), mPriority( 0 ) -{ - Q_UNUSED( incidence ); -} - -Incidence::~Incidence() -{ -} - -void Incidence::setPriority( int priority ) -{ - mPriority = priority; -} - -int Incidence::priority() const -{ - return mPriority; -} - -void Incidence::setSummary( const QString& summary ) -{ - mSummary = summary; -} - -QString Incidence::summary() const -{ - return mSummary; -} - -void Incidence::setLocation( const QString& location ) -{ - mLocation = location; -} - -QString Incidence::location() const -{ - return mLocation; -} - -void Incidence::setOrganizer( const Email& organizer ) -{ - mOrganizer = organizer; -} - -KolabBase::Email Incidence::organizer() const -{ - return mOrganizer; -} - -void Incidence::setStartDate( const KDateTime& startDate ) -{ - mStartDate = startDate; - if ( mFloatingStatus == AllDay ) - kDebug() <<"ERROR: Time on start date but no time on the event"; - mFloatingStatus = HasTime; -} - -void Incidence::setStartDate( const QDate& startDate ) -{ - mStartDate = KDateTime( startDate ); - if ( mFloatingStatus == HasTime ) - kDebug() <<"ERROR: No time on start date but time on the event"; - mFloatingStatus = AllDay; -} - -void Incidence::setStartDate( const QString& startDate ) -{ - if ( startDate.length() > 10 ) - // This is a date + time - setStartDate( stringToDateTime( startDate ) ); - else - // This is only a date - setStartDate( stringToDate( startDate ) ); -} - -KDateTime Incidence::startDate() const -{ - return mStartDate; -} - -void Incidence::setAlarm( float alarm ) -{ - mAlarm = alarm; - mHasAlarm = true; -} - -float Incidence::alarm() const -{ - return mAlarm; -} - -Incidence::Recurrence Incidence::recurrence() const -{ - return mRecurrence; -} - -void Incidence::addAttendee( const Attendee& attendee ) -{ - mAttendees.append( attendee ); -} - -QList<Incidence::Attendee>& Incidence::attendees() -{ - return mAttendees; -} - -const QList<Incidence::Attendee>& Incidence::attendees() const -{ - return mAttendees; -} - -void Incidence::setInternalUID( const QString& iuid ) -{ - mInternalUID = iuid; -} - -QString Incidence::internalUID() const -{ - return mInternalUID; -} - -bool Incidence::loadAttendeeAttribute( QDomElement& element, - Attendee& attendee ) -{ - for ( QDomNode n = element.firstChild(); !n.isNull(); n = n.nextSibling() ) { - if ( n.isComment() ) - continue; - if ( n.isElement() ) { - QDomElement e = n.toElement(); - QString tagName = e.tagName(); - - if ( tagName == "display-name" ) - attendee.displayName = e.text(); - else if ( tagName == "smtp-address" ) - attendee.smtpAddress = e.text(); - else if ( tagName == "status" ) - attendee.status = e.text(); - else if ( tagName == "request-response" ) - // This sets reqResp to false, if the text is "false". Otherwise it - // sets it to true. This means the default setting is true. - attendee.requestResponse = ( e.text().toLower() != "false" ); - else if ( tagName == "invitation-sent" ) - // Like above, only this defaults to false - attendee.invitationSent = ( e.text().toLower() != "true" ); - else if ( tagName == "role" ) - attendee.role = e.text(); - else if ( tagName == "delegated-to" ) - attendee.delegate = e.text(); - else if ( tagName == "delegated-from" ) - attendee.delegator = e.text(); - else - // TODO: Unhandled tag - save for later storage - kDebug() <<"Warning: Unhandled tag" << e.tagName(); - } else - kDebug() <<"Node is not a comment or an element???"; - } - - return true; -} - -void Incidence::saveAttendeeAttribute( QDomElement& element, - const Attendee& attendee ) const -{ - QDomElement e = element.ownerDocument().createElement( "attendee" ); - element.appendChild( e ); - writeString( e, "display-name", attendee.displayName ); - writeString( e, "smtp-address", attendee.smtpAddress ); - writeString( e, "status", attendee.status ); - writeString( e, "request-response", - ( attendee.requestResponse ? "true" : "false" ) ); - writeString( e, "invitation-sent", - ( attendee.invitationSent ? "true" : "false" ) ); - writeString( e, "role", attendee.role ); - writeString( e, "delegated-to", attendee.delegate ); - writeString( e, "delegated-from", attendee.delegator ); -} - -void Incidence::saveAttendees( QDomElement& element ) const -{ - foreach ( const Attendee& attendee, mAttendees ) - saveAttendeeAttribute( element, attendee ); -} - -void Incidence::saveAttachments( QDomElement& element ) const -{ - foreach ( KCalCore::Attachment::Ptr a, mAttachments ) { - if ( a->isUri() ) { - writeString( element, "link-attachment", a->uri() ); - } else if ( a->isBinary() ) { - writeString( element, "inline-attachment", a->label() ); - } - } -} - -void Incidence::saveAlarms( QDomElement& element ) const -{ - if ( mAlarms.isEmpty() ) return; - - QDomElement list = element.ownerDocument().createElement( "advanced-alarms" ); - element.appendChild( list ); - foreach ( KCalCore::Alarm::Ptr a, mAlarms ) { - QDomElement e = list.ownerDocument().createElement( "alarm" ); - list.appendChild( e ); - - writeString( e, "enabled", a->enabled() ? "1" : "0" ); - if ( a->hasStartOffset() ) { - writeString( e, "start-offset", QString::number( a->startOffset().asSeconds()/60 ) ); - } - if ( a->hasEndOffset() ) { - writeString( e, "end-offset", QString::number( a->endOffset().asSeconds()/60 ) ); - } - if ( a->repeatCount() ) { - writeString( e, "repeat-count", QString::number( a->repeatCount() ) ); - writeString( e, "repeat-interval", QString::number( a->snoozeTime().asSeconds() ) ); - } - - switch ( a->type() ) { - case KCalCore::Alarm::Invalid: - break; - case KCalCore::Alarm::Display: - e.setAttribute( "type", "display" ); - writeString( e, "text", a->text() ); - break; - case KCalCore::Alarm::Procedure: - e.setAttribute( "type", "procedure" ); - writeString( e, "program", a->programFile() ); - writeString( e, "arguments", a->programArguments() ); - break; - case KCalCore::Alarm::Email: - { - e.setAttribute( "type", "email" ); - QDomElement addresses = e.ownerDocument().createElement( "addresses" ); - e.appendChild( addresses ); - foreach ( const KCalCore::Person::Ptr &person, a->mailAddresses() ) { - writeString( addresses, "address", person->fullName() ); - } - writeString( e, "subject", a->mailSubject() ); - writeString( e, "mail-text", a->mailText() ); - QDomElement attachments = e.ownerDocument().createElement( "attachments" ); - e.appendChild( attachments ); - foreach ( const QString &attachment, a->mailAttachments() ) { - writeString( attachments, "attachment", attachment ); - } - break; - } - case KCalCore::Alarm::Audio: - e.setAttribute( "type", "audio" ); - writeString( e, "file", a->audioFile() ); - break; - default: - kWarning() << "Unhandled alarm type:" << a->type(); - break; - } - } -} - -void Incidence::saveRecurrence( QDomElement& element ) const -{ - QDomElement e = element.ownerDocument().createElement( "recurrence" ); - element.appendChild( e ); - e.setAttribute( "cycle", mRecurrence.cycle ); - if ( !mRecurrence.type.isEmpty() ) - e.setAttribute( "type", mRecurrence.type ); - writeString( e, "interval", QString::number( mRecurrence.interval ) ); - foreach ( const QString& recurrence, mRecurrence.days ) { - writeString( e, "day", recurrence ); - } - if ( !mRecurrence.dayNumber.isEmpty() ) - writeString( e, "daynumber", mRecurrence.dayNumber ); - if ( !mRecurrence.month.isEmpty() ) - writeString( e, "month", mRecurrence.month ); - if ( !mRecurrence.rangeType.isEmpty() ) { - QDomElement range = element.ownerDocument().createElement( "range" ); - e.appendChild( range ); - range.setAttribute( "type", mRecurrence.rangeType ); - QDomText t = element.ownerDocument().createTextNode( mRecurrence.range ); - range.appendChild( t ); - } - foreach ( const QDate& date, mRecurrence.exclusions ) { - writeString( e, "exclusion", dateToString( date ) ); - } -} - -void Incidence::loadRecurrence( const QDomElement& element ) -{ - mRecurrence.interval = 0; - mRecurrence.cycle = element.attribute( "cycle" ); - mRecurrence.type = element.attribute( "type" ); - for ( QDomNode n = element.firstChild(); !n.isNull(); n = n.nextSibling() ) { - if ( n.isComment() ) - continue; - if ( n.isElement() ) { - QDomElement e = n.toElement(); - QString tagName = e.tagName(); - if ( tagName == "interval" ) { - //kolab/issue4229, sometimes the interval value can be empty - if ( e.text().isEmpty() || e.text().toInt() <= 0 ) { - mRecurrence.interval = 1; - } else { - mRecurrence.interval = e.text().toInt(); - } - } - else if ( tagName == "day" ) // can be present multiple times - mRecurrence.days.append( e.text() ); - else if ( tagName == "daynumber" ) - mRecurrence.dayNumber = e.text(); - else if ( tagName == "month" ) - mRecurrence.month = e.text(); - else if ( tagName == "range" ) { - mRecurrence.rangeType = e.attribute( "type" ); - mRecurrence.range = e.text(); - } else if ( tagName == "exclusion" ) { - std::string exclusionDate = e.text().toStdString(); - // need to fix the date, eg. 2013-1-1 to ISO format 2013-01-01 - if (exclusionDate.length() != 10) { - std::vector<std::string> strs; - boost::split(strs, exclusionDate, boost::is_any_of("-")); - char buff[100]; - sprintf(buff, "%04d-%02d-%02d", - QString::fromStdString(strs[0]).toInt(), - QString::fromStdString(strs[1]).toInt(), - QString::fromStdString(strs[2]).toInt() - ); - exclusionDate = buff; - } - mRecurrence.exclusions.append( stringToDate( QString::fromStdString(exclusionDate) ) ); - } else - // TODO: Unhandled tag - save for later storage - kDebug() <<"Warning: Unhandled tag" << e.tagName(); - } - } -} - -static void loadAddressesHelper( const QDomElement& element, const KCalCore::Alarm::Ptr &a ) -{ - for ( QDomNode n = element.firstChild(); !n.isNull(); n = n.nextSibling() ) { - if ( n.isComment() ) - continue; - if ( n.isElement() ) { - QDomElement e = n.toElement(); - QString tagName = e.tagName(); - - if ( tagName == "address" ) { - a->addMailAddress( KCalCore::Person::fromFullName( e.text() ) ); - } else { - kWarning() << "Unhandled tag" << tagName; - } - } - } -} - -static void loadAttachmentsHelper( const QDomElement& element, const KCalCore::Alarm::Ptr &a ) -{ - for ( QDomNode n = element.firstChild(); !n.isNull(); n = n.nextSibling() ) { - if ( n.isComment() ) - continue; - if ( n.isElement() ) { - QDomElement e = n.toElement(); - QString tagName = e.tagName(); - - if ( tagName == "attachment" ) { - a->addMailAttachment( e.text() ); - } else { - kWarning() << "Unhandled tag" << tagName; - } - } - } -} - -static void loadAlarmHelper( const QDomElement& element, const KCalCore::Alarm::Ptr &a ) -{ - for ( QDomNode n = element.firstChild(); !n.isNull(); n = n.nextSibling() ) { - if ( n.isComment() ) - continue; - if ( n.isElement() ) { - QDomElement e = n.toElement(); - QString tagName = e.tagName(); - - if ( tagName == "start-offset" ) { - a->setStartOffset( e.text().toInt()*60 ); - } else if ( tagName == "end-offset" ) { - a->setEndOffset( e.text().toInt()*60 ); - } else if ( tagName == "repeat-count" ) { - a->setRepeatCount( e.text().toInt() ); - } else if ( tagName == "repeat-interval" ) { - a->setSnoozeTime( e.text().toInt() ); - } else if ( tagName == "text" ) { - a->setText( e.text() ); - } else if ( tagName == "program" ) { - a->setProgramFile( e.text() ); - } else if ( tagName == "arguments" ) { - a->setProgramArguments( e.text() ); - } else if ( tagName == "addresses" ) { - loadAddressesHelper( e, a ); - } else if ( tagName == "subject" ) { - a->setMailSubject( e.text() ); - } else if ( tagName == "mail-text" ) { - a->setMailText( e.text() ); - } else if ( tagName == "attachments" ) { - loadAttachmentsHelper( e, a ); - } else if ( tagName == "file" ) { - a->setAudioFile( e.text() ); - } else if ( tagName == "enabled" ) { - a->setEnabled( e.text().toInt() != 0 ); - } else { - kWarning() << "Unhandled tag" << tagName; - } - } - } -} - -void Incidence::loadAlarms( const QDomElement& element ) -{ - for ( QDomNode n = element.firstChild(); !n.isNull(); n = n.nextSibling() ) { - if ( n.isComment() ) - continue; - if ( n.isElement() ) { - QDomElement e = n.toElement(); - QString tagName = e.tagName(); - - if ( tagName == "alarm" ) { - KCalCore::Alarm::Ptr a = KCalCore::Alarm::Ptr( new KCalCore::Alarm( 0 ) ); - a->setEnabled( true ); // default to enabled, unless some XML attribute says otherwise. - QString type = e.attribute( "type" ); - if ( type == "display" ) { - a->setType( KCalCore::Alarm::Display ); - } else if ( type == "procedure" ) { - a->setType( KCalCore::Alarm::Procedure ); - } else if ( type == "email" ) { - a->setType( KCalCore::Alarm::Email ); - } else if ( type == "audio" ) { - a->setType( KCalCore::Alarm::Audio ); - } else { - kWarning() << "Unhandled alarm type:" << type; - } - - loadAlarmHelper( e, a ); - mAlarms << a; - } else { - kWarning() << "Unhandled tag" << tagName; - } - } - } -} - -bool Incidence::loadAttribute( QDomElement& element ) -{ - QString tagName = element.tagName(); - - if ( tagName == "priority" ) { - bool ok; - int p = element.text().toInt( &ok ); - if ( !ok || p < 1 || p > 9 ) { - kWarning() << "Invalid \"priority\" value:" << element.text(); - } else { - setPriority( p ); - } - } else if ( tagName == "x-kcal-priority" ) { //for backwards compat - bool ok; - int p = element.text().toInt( &ok ); - if ( !ok || p < 0 || p > 9 ) { - kWarning() << "Invalid \"x-kcal-priority\" value:" << element.text(); - } else { - if ( priority() == 0 ) { - setPriority(p); - } - } - } else if ( tagName == "summary" ) - setSummary( element.text() ); - else if ( tagName == "location" ) - setLocation( element.text() ); - else if ( tagName == "organizer" ) { - Email email; - if ( loadEmailAttribute( element, email ) ) { - setOrganizer( email ); - return true; - } else - return false; - } else if ( tagName == "start-date" ) - setStartDate( element.text() ); - else if ( tagName == "recurrence" ) - loadRecurrence( element ); - else if ( tagName == "attendee" ) { - Attendee attendee; - if ( loadAttendeeAttribute( element, attendee ) ) { - addAttendee( attendee ); - return true; - } else - return false; - } else if ( tagName == "link-attachment" ) { - mAttachments.push_back( KCalCore::Attachment::Ptr( new KCalCore::Attachment( element.text() ) ) ); - } else if ( tagName == "alarm" ) - // Alarms should be minutes before. Libkcal uses event time + alarm time - setAlarm( - element.text().toInt() ); - else if ( tagName == "advanced-alarms" ) - loadAlarms( element ); - else if ( tagName == "x-kde-internaluid" ) - setInternalUID( element.text() ); - else if ( tagName == "x-custom" ) { - loadCustomAttributes( element ); - } else if ( tagName == "inline-attachment" ) { - // we handle that separately later on, so no need to create a KolabUnhandled entry for it - } else { - bool ok = KolabBase::loadAttribute( element ); - if ( !ok ) { - // Unhandled tag - save for later storage - kDebug() <<"Saving unhandled tag" << element.tagName(); - Custom c; - c.key = QByteArray( "X-KDE-KolabUnhandled-" ) + element.tagName().toLatin1(); - c.value = element.text(); - mCustomList.append( c ); - } - } - // We handled this - return true; -} - -bool Incidence::saveAttributes( QDomElement& element ) const -{ - // Save the base class elements - KolabBase::saveAttributes( element ); - - if (priority() != 0) { - writeString( element, "priority", QString::number( priority() ) ); - } - - if ( mFloatingStatus == HasTime ) - writeString( element, "start-date", dateTimeToString( startDate() ) ); - else - writeString( element, "start-date", dateToString( startDate().date() ) ); - writeString( element, "summary", summary() ); - writeString( element, "location", location() ); - saveEmailAttribute( element, organizer(), "organizer" ); - if ( !mRecurrence.cycle.isEmpty() ) - saveRecurrence( element ); - saveAttendees( element ); - saveAttachments( element ); - if ( mHasAlarm ) { - // Alarms should be minutes before. Libkcal uses event time + alarm time - int alarmTime = qRound( -alarm() ); - writeString( element, "alarm", QString::number( alarmTime ) ); - } - saveAlarms( element ); - writeString( element, "x-kde-internaluid", internalUID() ); - saveCustomAttributes( element ); - return true; -} - -void Incidence::saveCustomAttributes( QDomElement& element ) const -{ - foreach ( const Custom& custom, mCustomList ) { - QString key( custom.key ); - Q_ASSERT( !key.isEmpty() ); - if ( key.startsWith( QLatin1String( "X-KDE-KolabUnhandled-" ) ) ) { - key = key.mid( strlen( "X-KDE-KolabUnhandled-" ) ); - writeString( element, key, custom.value ); - } else { - // Let's use attributes so that other tag-preserving-code doesn't need sub-elements - QDomElement e = element.ownerDocument().createElement( "x-custom" ); - element.appendChild( e ); - e.setAttribute( "key", key ); - e.setAttribute( "value", custom.value ); - } - } -} - -void Incidence::loadCustomAttributes( QDomElement& element ) -{ - Custom custom; - custom.key = element.attribute( "key" ).toLatin1(); - custom.value = element.attribute( "value" ); - mCustomList.append( custom ); -} - -static KCalCore::Attendee::PartStat attendeeStringToStatus( const QString& s ) -{ - if ( s == "none" ) - return KCalCore::Attendee::NeedsAction; - if ( s == "tentative" ) - return KCalCore::Attendee::Tentative; - if ( s == "declined" ) - return KCalCore::Attendee::Declined; - if ( s == "delegated" ) - return KCalCore::Attendee::Delegated; - - // Default: - return KCalCore::Attendee::Accepted; -} - -static QString attendeeStatusToString( KCalCore::Attendee::PartStat status ) -{ - switch( status ) { - case KCalCore::Attendee::NeedsAction: - return "none"; - case KCalCore::Attendee::Accepted: - return "accepted"; - case KCalCore::Attendee::Declined: - return "declined"; - case KCalCore::Attendee::Tentative: - return "tentative"; - case KCalCore::Attendee::Delegated: - return "delegated"; - case KCalCore::Attendee::Completed: - case KCalCore::Attendee::InProcess: - // These don't have any meaning in the Kolab format, so just use: - return "accepted"; - default: - // Default for the case that there are more added later: - return "accepted"; - } -} - -static KCalCore::Attendee::Role attendeeStringToRole( const QString& s ) -{ - if ( s == "optional" ) - return KCalCore::Attendee::OptParticipant; - if ( s == "resource" ) - return KCalCore::Attendee::NonParticipant; - return KCalCore::Attendee::ReqParticipant; -} - -static QString attendeeRoleToString( KCalCore::Attendee::Role role ) -{ - switch( role ) { - case KCalCore::Attendee::ReqParticipant: - return "required"; - case KCalCore::Attendee::OptParticipant: - return "optional"; - case KCalCore::Attendee::Chair: - // We don't have the notion of chair, so use - return "required"; - case KCalCore::Attendee::NonParticipant: - // In Kolab, a non-participant is a resource - return "resource"; - } - - // Default for the case that there are more added later: - return "required"; -} - -static const char *s_weekDayName[] = -{ - "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday" -}; - -static const char *s_monthName[] = -{ - "january", "february", "march", "april", "may", "june", "july", - "august", "september", "october", "november", "december" -}; - -void Incidence::setRecurrence( KCalCore::Recurrence* recur ) -{ - mRecurrence.interval = recur->frequency(); - switch ( recur->recurrenceType() ) { - case KCalCore::Recurrence::rMinutely: // Not handled by the kolab XML - mRecurrence.cycle = "minutely"; - break; - case KCalCore::Recurrence::rHourly: // Not handled by the kolab XML - mRecurrence.cycle = "hourly"; - break; - case KCalCore::Recurrence::rDaily: - mRecurrence.cycle = "daily"; - break; - case KCalCore::Recurrence::rWeekly: // every X weeks - mRecurrence.cycle = "weekly"; - { - QBitArray arr = recur->days(); - for ( uint idx = 0 ; idx < 7 ; ++idx ) - if ( arr.testBit( idx ) ) - mRecurrence.days.append( s_weekDayName[idx] ); - } - break; - case KCalCore::Recurrence::rMonthlyPos: { - mRecurrence.cycle = "monthly"; - mRecurrence.type = "weekday"; - QList<KCalCore::RecurrenceRule::WDayPos> monthPositions = recur->monthPositions(); - if ( !monthPositions.isEmpty() ) { - KCalCore::RecurrenceRule::WDayPos monthPos = monthPositions.first(); - // TODO: Handle multiple days in the same week - mRecurrence.dayNumber = QString::number( monthPos.pos() ); - mRecurrence.days.append( s_weekDayName[ monthPos.day()-1 ] ); - // Not (properly) handled(?): monthPos.negative (nth days before end of month) - } - break; - } - case KCalCore::Recurrence::rMonthlyDay: { - mRecurrence.cycle = "monthly"; - mRecurrence.type = "daynumber"; - QList<int> monthDays = recur->monthDays(); - // ####### Kolab XML limitation: only the first month day is used - if ( !monthDays.isEmpty() ) - mRecurrence.dayNumber = QString::number( monthDays.first() ); - break; - } - case KCalCore::Recurrence::rYearlyMonth: // (day n of Month Y) - { - mRecurrence.cycle = "yearly"; - mRecurrence.type = "monthday"; - QList<int> rmd = recur->yearDates(); - int day = !rmd.isEmpty() ? rmd.first() : recur->startDate().day(); - mRecurrence.dayNumber = QString::number( day ); - QList<int> months = recur->yearMonths(); - if ( !months.isEmpty() ) - mRecurrence.month = s_monthName[ months.first() - 1 ]; // #### Kolab XML limitation: only one month specified - break; - } - case KCalCore::Recurrence::rYearlyDay: // YearlyDay (day N of the year). Not supported by Outlook - mRecurrence.cycle = "yearly"; - mRecurrence.type = "yearday"; - mRecurrence.dayNumber = QString::number( recur->yearDays().first() ); - break; - case KCalCore::Recurrence::rYearlyPos: // (weekday X of week N of month Y) - mRecurrence.cycle = "yearly"; - mRecurrence.type = "weekday"; - QList<int> months = recur->yearMonths(); - if ( !months.isEmpty() ) - mRecurrence.month = s_monthName[ months.first() - 1 ]; // #### Kolab XML limitation: only one month specified - QList<KCalCore::RecurrenceRule::WDayPos> monthPositions = recur->yearPositions(); - if ( !monthPositions.isEmpty() ) { - KCalCore::RecurrenceRule::WDayPos monthPos = monthPositions.first(); - // TODO: Handle multiple days in the same week - mRecurrence.dayNumber = QString::number( monthPos.pos() ); - mRecurrence.days.append( s_weekDayName[ monthPos.day()-1 ] ); - - //mRecurrence.dayNumber = QString::number( *recur->yearNums().getFirst() ); - // Not handled: monthPos.negative (nth days before end of month) - } - break; - } - int howMany = recur->duration(); - if ( howMany > 0 ) { - mRecurrence.rangeType = "number"; - mRecurrence.range = QString::number( howMany ); - } else if ( howMany == 0 ) { - mRecurrence.rangeType = "date"; - mRecurrence.range = dateToString( recur->endDate() ); - } else { - mRecurrence.rangeType = "none"; - } -} - -void Incidence::setFields( const KCalCore::Incidence::Ptr &incidence ) -{ - KolabBase::setFields( incidence ); - - setPriority( incidence->priority() ); - if ( incidence->allDay() ) { - // This is a all-day event. Don't timezone move this one - mFloatingStatus = AllDay; - setStartDate( incidence->dtStart().date() ); - } else { - mFloatingStatus = HasTime; - setStartDate( localToUTC( incidence->dtStart() ) ); - } - - setSummary( incidence->summary() ); - setLocation( incidence->location() ); - - // Alarm - mHasAlarm = false; // Will be set to true, if we actually have one - if ( incidence->hasEnabledAlarms() ) { - const KCalCore::Alarm::List& alarms = incidence->alarms(); - if ( !alarms.isEmpty() ) { - const KCalCore::Alarm::Ptr alarm = alarms.first(); - if ( alarm->hasStartOffset() ) { - int dur = alarm->startOffset().asSeconds(); - setAlarm( (float)dur / 60.0 ); - } - } - } - - if (incidence->organizer()) { - Email org( incidence->organizer()->name(), incidence->organizer()->email() ); - setOrganizer( org ); - } - - // Attendees: - KCalCore::Attendee::List attendees = incidence->attendees(); - foreach ( KCalCore::Attendee::Ptr kcalAttendee, attendees ) { - Attendee attendee; - - attendee.displayName = kcalAttendee->name(); - attendee.smtpAddress = kcalAttendee->email(); - attendee.status = attendeeStatusToString( kcalAttendee->status() ); - attendee.requestResponse = kcalAttendee->RSVP(); - // TODO: KCalCore::Attendee::mFlag is not accessible - // attendee.invitationSent = kcalAttendee->mFlag; - // DF: Hmm? mFlag is set to true and never used at all.... Did you mean another field? - attendee.role = attendeeRoleToString( kcalAttendee->role() ); - attendee.delegate = kcalAttendee->delegate(); - attendee.delegator = kcalAttendee->delegator(); - - addAttendee( attendee ); - } - - mAttachments.clear(); - - // Attachments - KCalCore::Attachment::List attachments = incidence->attachments(); - foreach ( KCalCore::Attachment::Ptr a, attachments ) { - mAttachments.push_back( a ); - } - - mAlarms.clear(); - - // Alarms - KCalCore::Alarm::List alarms = incidence->alarms(); - foreach ( KCalCore::Alarm::Ptr a, alarms ) { - mAlarms.push_back( a ); - } - - if ( incidence->recurs() ) { - setRecurrence( incidence->recurrence() ); - mRecurrence.exclusions = incidence->recurrence()->exDates(); - } - - // Handle the scheduling ID - if ( incidence->schedulingID() == incidence->uid() ) { - // There is no scheduling ID - setInternalUID( QString::null ); //krazy:exclude=nullstrassign for old broken gcc - } else { - // We've internally been using a different uid, so save that as the - // temporary (internal) uid and restore the original uid, the one that - // is used in the folder and the outside world - setUid( incidence->schedulingID() ); - setInternalUID( incidence->uid() ); - } - - // Unhandled tags and other custom properties (see libkcal/customproperties.h) - const QMap<QByteArray, QString> map = incidence->customProperties(); - QMap<QByteArray, QString>::ConstIterator cit = map.begin(); - for ( ; cit != map.end() ; ++cit ) { - Custom c; - c.key = cit.key(); - c.value = cit.value(); - mCustomList.append( c ); - } -} - -static QBitArray daysListToBitArray( const QStringList& days ) -{ - QBitArray arr( 7 ); - arr.fill( false ); - foreach ( const QString& day, days ) { - for ( uint i = 0; i < 7 ; ++i ) - if ( day == s_weekDayName[i] ) - arr.setBit( i, true ); - } - return arr; -} - - -void Incidence::saveTo( const KCalCore::Incidence::Ptr &incidence ) -{ - KolabBase::saveTo( incidence ); - - incidence->setPriority( priority() ); - if ( mFloatingStatus == AllDay ) { - // This is an all-day event. Don't timezone move this one - incidence->setDtStart( startDate() ); - incidence->setAllDay( true ); - } else { - incidence->setDtStart( utcToLocal( startDate() ) ); - incidence->setAllDay( false ); - } - - incidence->setSummary( summary() ); - incidence->setLocation( location() ); - - if ( mHasAlarm && mAlarms.isEmpty() ) { - KCalCore::Alarm::Ptr alarm = incidence->newAlarm(); - alarm->setStartOffset( qRound( mAlarm * 60.0 ) ); - alarm->setEnabled( true ); - alarm->setType( KCalCore::Alarm::Display ); - } else if ( !mAlarms.isEmpty() ) { - foreach ( KCalCore::Alarm::Ptr a, mAlarms ) { - a->setParent( incidence.data() ); - incidence->addAlarm( a ); - } - } - - if ( organizer().displayName.isEmpty() ) - incidence->setOrganizer( organizer().smtpAddress ); - else - incidence->setOrganizer( organizer().displayName + '<' - + organizer().smtpAddress + '>' ); - - incidence->clearAttendees(); - foreach ( const Attendee& attendee, mAttendees ) { - KCalCore::Attendee::PartStat status = attendeeStringToStatus( attendee.status ); - KCalCore::Attendee::Role role = attendeeStringToRole( attendee.role ); - KCalCore::Attendee::Ptr a( new KCalCore::Attendee( attendee.displayName, - attendee.smtpAddress, - attendee.requestResponse, - status, role ) ); - a->setDelegate( attendee.delegate ); - a->setDelegator( attendee.delegator ); - incidence->addAttendee( a ); - } - - incidence->clearAttachments(); - foreach ( KCalCore::Attachment::Ptr a, mAttachments ) { - // TODO should we copy? - incidence->addAttachment( a ); - } - - if ( !mRecurrence.cycle.isEmpty() ) { - KCalCore::Recurrence* recur = incidence->recurrence(); // yeah, this creates it - // done below recur->setFrequency( mRecurrence.interval ); - if ( mRecurrence.cycle == "minutely" ) { - recur->setMinutely( mRecurrence.interval ); - } else if ( mRecurrence.cycle == "hourly" ) { - recur->setHourly( mRecurrence.interval ); - } else if ( mRecurrence.cycle == "daily" ) { - recur->setDaily( mRecurrence.interval ); - } else if ( mRecurrence.cycle == "weekly" ) { - QBitArray rDays = daysListToBitArray( mRecurrence.days ); - recur->setWeekly( mRecurrence.interval, rDays ); - } else if ( mRecurrence.cycle == "monthly" ) { - recur->setMonthly( mRecurrence.interval ); - if ( mRecurrence.type == "weekday" ) { - recur->addMonthlyPos( mRecurrence.dayNumber.toInt(), daysListToBitArray( mRecurrence.days ) ); - } else if ( mRecurrence.type == "daynumber" ) { - recur->addMonthlyDate( mRecurrence.dayNumber.toInt() ); - } else kWarning() <<"Unhandled monthly recurrence type" << mRecurrence.type; - } else if ( mRecurrence.cycle == "yearly" ) { - recur->setYearly( mRecurrence.interval ); - if ( mRecurrence.type == "monthday" ) { - recur->addYearlyDate( mRecurrence.dayNumber.toInt() ); - for ( int i = 0; i < 12; ++i ) - if ( s_monthName[ i ] == mRecurrence.month ) - recur->addYearlyMonth( i+1 ); - } else if ( mRecurrence.type == "yearday" ) { - recur->addYearlyDay( mRecurrence.dayNumber.toInt() ); - } else if ( mRecurrence.type == "weekday" ) { - for ( int i = 0; i < 12; ++i ) - if ( s_monthName[ i ] == mRecurrence.month ) - recur->addYearlyMonth( i+1 ); - recur->addYearlyPos( mRecurrence.dayNumber.toInt(), daysListToBitArray( mRecurrence.days ) ); - } else kWarning() <<"Unhandled yearly recurrence type" << mRecurrence.type; - } else kWarning() <<"Unhandled recurrence cycle" << mRecurrence.cycle; - - if ( mRecurrence.rangeType == "number" ) { - recur->setDuration( mRecurrence.range.toInt() ); - } else if ( mRecurrence.rangeType == "date" ) { - recur->setEndDate( stringToDate( mRecurrence.range ) ); - } // "none" is default since tje set*ly methods set infinite recurrence - - incidence->recurrence()->setExDates( mRecurrence.exclusions ); - - } - /* If we've stored a uid to be used internally instead of the real one - * (to deal with duplicates of events in different folders) before, then - * restore it, so it does not change. Keep the original uid around for - * scheduling purposes. */ - if ( !internalUID().isEmpty() ) { - incidence->setUid( internalUID() ); - incidence->setSchedulingID( uid() ); - } - - foreach ( const Custom& custom, mCustomList ) { - incidence->setNonKDECustomProperty( custom.key, custom.value ); - } - -} - -QString Incidence::productID() const -{ - return QString( "%1, Kolab resource" ).arg( LIBKOLAB_LIB_VERSION_STRING ); -} - -// Unhandled KCalCore::Incidence fields: -// revision, status (unused), attendee.uid, -// mComments, mReadOnly -
View file
libkolab-2.0.tar.gz/kolabformatV2/incidence.h
Deleted
@@ -1,172 +0,0 @@ -/* - This file is part of the kolab resource - the implementation of the - Kolab storage format. See www.kolab.org for documentation on this. - - Copyright (c) 2004 Bo Thorsen <bo@sonofthor.dk> - - 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 Qt library by Trolltech AS, Norway (or with modified versions - of Qt that use the same license as Qt), 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 - Qt. 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 KOLABV2_INCIDENCE_H -#define KOLABV2_INCIDENCE_H - -#include <kcalcore/incidence.h> - -#include "kolabbase.h" - -class QDomElement; - -namespace KolabV2 { - -/** - * This abstract class represents an incidence which has the shared - * fields, of events and tasks and knows how to load/save these - * from/to XML, and from/to a KCalCore::Incidence. - */ -class Incidence : public KolabBase { -public: - struct Recurrence { - QString cycle; - QString type; - int interval; - QStringList days; // list of days-of-the-week - QString dayNumber; - QString month; - QString rangeType; - QString range; // date or number or nothing - QList<QDate> exclusions; - }; - - struct Attendee : Email { - Attendee() : requestResponse( true ), invitationSent( false ) {} - QString status; - bool requestResponse; - bool invitationSent; - QString role; - QString delegate; - QString delegator; - }; - - explicit Incidence( const QString& tz, const KCalCore::Incidence::Ptr &incidence = KCalCore::Incidence::Ptr() ); - -public: - virtual ~Incidence(); - - void saveTo( const KCalCore::Incidence::Ptr &incidence ); - - virtual void setPriority( int priority ); - virtual int priority() const; - - virtual void setSummary( const QString& summary ); - virtual QString summary() const; - - virtual void setLocation( const QString& location ); - virtual QString location() const; - - virtual void setOrganizer( const Email& organizer ); - virtual Email organizer() const; - - virtual void setStartDate( const KDateTime& startDate ); - virtual void setStartDate( const QDate& startDate ); - virtual void setStartDate( const QString& startDate ); - virtual KDateTime startDate() const; - - virtual void setAlarm( float alarm ); - virtual float alarm() const; - - virtual void setRecurrence( KCalCore::Recurrence* recur ); - virtual Recurrence recurrence() const; - - virtual void addAttendee( const Attendee& attendee ); - QList<Attendee>& attendees(); - const QList<Attendee>& attendees() const; - - virtual QString type() const { return "Incidence"; } - /** - * The internal uid is used as the uid inside KOrganizer whenever - * two or more events with the same uid appear, which KOrganizer - * can't handle. To avoid keep that interal uid from changing all the - * time, it is persisted in the XML between a save and the next load. - */ - void setInternalUID( const QString& iuid ); - QString internalUID() const; - - // Load the attributes of this class - virtual bool loadAttribute( QDomElement& ); - - // Save the attributes of this class - virtual bool saveAttributes( QDomElement& ) const; - -protected: - enum FloatingStatus { Unset, AllDay, HasTime }; - - // Read all known fields from this ical incidence - void setFields( const KCalCore::Incidence::Ptr & ); - - bool loadAttendeeAttribute( QDomElement&, Attendee& ); - void saveAttendeeAttribute( QDomElement& element, - const Attendee& attendee ) const; - void saveAttendees( QDomElement& element ) const; - void saveAttachments( QDomElement& element ) const; - - void loadAlarms( const QDomElement& element ); - void saveAlarms( QDomElement& element ) const; - - void loadRecurrence( const QDomElement& element ); - void saveRecurrence( QDomElement& element ) const; - void saveCustomAttributes( QDomElement& element ) const; - void loadCustomAttributes( QDomElement& element ); - - QString productID() const; - - QString mSummary; - QString mLocation; - Email mOrganizer; - KDateTime mStartDate; - FloatingStatus mFloatingStatus; - float mAlarm; - bool mHasAlarm; - Recurrence mRecurrence; - QList<Attendee> mAttendees; - QList<KCalCore::Alarm::Ptr> mAlarms; - QList<KCalCore::Attachment::Ptr> mAttachments; - QString mInternalUID; - - struct Custom { - QByteArray key; - QString value; - }; - QList<Custom> mCustomList; - - // This is the KCal priority, not the Kolab priority. - // See kcalPriorityToKolab() and kolabPrioritytoKCal(). - int mPriority; -}; - -} - -#endif // KOLAB_INCIDENCE_H
View file
libkolab-2.0.tar.gz/kolabformatV2/journal.cpp
Deleted
@@ -1,184 +0,0 @@ -/* - This file is part of the kolab resource - the implementation of the - Kolab storage format. See www.kolab.org for documentation on this. - - Copyright (c) 2004 Bo Thorsen <bo@sonofthor.dk> - - 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 Qt library by Trolltech AS, Norway (or with modified versions - of Qt that use the same license as Qt), 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 - Qt. 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 "journal.h" -#include "libkolab-version.h" - -#include <kdebug.h> - -using namespace KolabV2; - - -KCalCore::Journal::Ptr Journal::fromXml( const QDomDocument& xmlDoc, const QString& tz ) -{ - Journal journal( tz ); - journal.loadXML( xmlDoc ); - KCalCore::Journal::Ptr kcalJournal( new KCalCore::Journal() ); - journal.saveTo( kcalJournal ); - return kcalJournal; -} - -QString Journal::journalToXML( const KCalCore::Journal::Ptr &kcalJournal, const QString& tz ) -{ - Journal journal( tz, kcalJournal ); - return journal.saveXML(); -} - -Journal::Journal( const QString& tz, const KCalCore::Journal::Ptr &journal ) - : KolabBase( tz ) -{ - if ( journal ) { - setFields( journal ); - } -} - -Journal::~Journal() -{ -} - -void Journal::setSummary( const QString& summary ) -{ - mSummary = summary; -} - -QString Journal::summary() const -{ - return mSummary; -} - -void Journal::setStartDate( const KDateTime& startDate ) -{ - mStartDate = startDate; -} - -KDateTime Journal::startDate() const -{ - return mStartDate; -} - -void Journal::setEndDate( const KDateTime& endDate ) -{ - mEndDate = endDate; -} - -KDateTime Journal::endDate() const -{ - return mEndDate; -} - -bool Journal::loadAttribute( QDomElement& element ) -{ - QString tagName = element.tagName(); - - if ( tagName == "summary" ) - setSummary( element.text() ); - else if ( tagName == "start-date" ) - setStartDate( stringToDateTime( element.text() ) ); - else - // Not handled here - return KolabBase::loadAttribute( element ); - - // We handled this - return true; -} - -bool Journal::saveAttributes( QDomElement& element ) const -{ - // Save the base class elements - KolabBase::saveAttributes( element ); - - writeString( element, "summary", summary() ); - writeString( element, "start-date", dateTimeToString( startDate() ) ); - - return true; -} - - -bool Journal::loadXML( const QDomDocument& document ) -{ - QDomElement top = document.documentElement(); - - if ( top.tagName() != "journal" ) { - qWarning( "XML error: Top tag was %s instead of the expected Journal", - top.tagName().toAscii().data() ); - return false; - } - - for ( QDomNode n = top.firstChild(); !n.isNull(); n = n.nextSibling() ) { - if ( n.isComment() ) - continue; - if ( n.isElement() ) { - QDomElement e = n.toElement(); - if ( !loadAttribute( e ) ) { - // Unhandled tag - save for later storage - //qDebug( "Unhandled tag: %s", e.toCString().data() ); - } - } else - qDebug( "Node is not a comment or an element???" ); - } - - return true; -} - -QString Journal::saveXML() const -{ - QDomDocument document = domTree(); - QDomElement element = document.createElement( "journal" ); - element.setAttribute( "version", "1.0" ); - saveAttributes( element ); - document.appendChild( element ); - return document.toString(); -} - -void Journal::saveTo( const KCalCore::Journal::Ptr &journal ) -{ - KolabBase::saveTo( journal ); - - journal->setSummary( summary() ); - journal->setDtStart( utcToLocal( startDate() ) ); -} - -void Journal::setFields( const KCalCore::Journal::Ptr &journal ) -{ - // Set baseclass fields - KolabBase::setFields( journal ); - - // Set our own fields - setSummary( journal->summary() ); - setStartDate( localToUTC( journal->dtStart() ) ); -} - -QString Journal::productID() const -{ - return QString::fromLatin1(LIBKOLAB_LIB_VERSION_STRING) + ", Kolab resource"; -}
View file
libkolab-2.0.tar.gz/kolabformatV2/journal.h
Deleted
@@ -1,101 +0,0 @@ -/* - This file is part of the kolab resource - the implementation of the - Kolab storage format. See www.kolab.org for documentation on this. - - Copyright (c) 2004 Bo Thorsen <bo@sonofthor.dk> - - 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 Qt library by Trolltech AS, Norway (or with modified versions - of Qt that use the same license as Qt), 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 - Qt. 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 KOLABV2_JOURNAL_H -#define KOLABV2_JOURNAL_H - -#include <kcalcore/journal.h> - -#include "kolabbase.h" - -class QDomElement; - -namespace KolabV2 { - -/** - * This class represents a journal entry, and knows how to load/save it - * from/to XML, and from/to a KCalCore::Journal. - * The instances of this class are temporary, only used to convert - * one to the other. - */ -class Journal : public KolabBase { -public: - /// Use this to parse an xml string to a journal entry - /// The caller is responsible for deleting the returned journal - static KCalCore::Journal::Ptr fromXml( const QDomDocument& xmlDoc, const QString& tz ); - - /// Use this to get an xml string describing this journal entry - static QString journalToXML( const KCalCore::Journal::Ptr &, const QString& tz ); - - explicit Journal( const QString& tz, const KCalCore::Journal::Ptr &journal = KCalCore::Journal::Ptr() ); - virtual ~Journal(); - - virtual QString type() const { return "Journal"; } - - void saveTo( const KCalCore::Journal::Ptr &journal ); - - virtual void setSummary( const QString& summary ); - virtual QString summary() const; - - virtual void setStartDate( const KDateTime& startDate ); - virtual KDateTime startDate() const; - - virtual void setEndDate( const KDateTime& endDate ); - virtual KDateTime endDate() const; - - // Load the attributes of this class - virtual bool loadAttribute( QDomElement& ); - - // Save the attributes of this class - virtual bool saveAttributes( QDomElement& ) const; - - // Load this journal by reading the XML file - virtual bool loadXML( const QDomDocument& xml ); - - // Serialize this journal to an XML string - virtual QString saveXML() const; - -protected: - // Read all known fields from this ical journal - void setFields( const KCalCore::Journal::Ptr & ); - - QString productID() const; - - QString mSummary; - KDateTime mStartDate; - KDateTime mEndDate; -}; - -} - -#endif // KOLAB_JOURNAL_H
View file
libkolab-2.0.tar.gz/kolabformatV2/kolabbase.cpp
Deleted
@@ -1,500 +0,0 @@ -/* - This file is part of the kolab resource - the implementation of the - Kolab storage format. See www.kolab.org for documentation on this. - - Copyright (c) 2004 Bo Thorsen <bo@sonofthor.dk> - - 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 Qt library by Trolltech AS, Norway (or with modified versions - of Qt that use the same license as Qt), 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 - Qt. 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 "kolabbase.h" - -#include <kabc/addressee.h> -#include <kabc/contactgroup.h> -#include <kcalcore/incidence.h> -#include <kcalcore/journal.h> -#include <ksystemtimezone.h> -#include <kdebug.h> - -using namespace KolabV2; - -KolabBase::KolabBase( const QString& tz ) - : mCreationDate( QDateTime::currentDateTime() ), - mLastModified( KDateTime::currentUtcDateTime() ), - mSensitivity( Public ), - mTimeZone( KSystemTimeZones::zone( tz ) ), - mHasPilotSyncId( false ), mHasPilotSyncStatus( false ) -{ -} - -KolabBase::~KolabBase() -{ -} - -void KolabBase::setFields( const KCalCore::Incidence::Ptr &incidence ) -{ - // So far unhandled KCalCore::IncidenceBase fields: - // mPilotID, mSyncStatus, mFloats - - setUid( incidence->uid() ); - setBody( incidence->description() ); - setCategories( incidence->categoriesStr() ); - setCreationDate( localToUTC( incidence->created() ) ); - setLastModified( incidence->lastModified() ); - setSensitivity( static_cast<Sensitivity>( incidence->secrecy() ) ); - // TODO: Attachments -} - -void KolabBase::saveTo( const KCalCore::Incidence::Ptr &incidence ) const -{ - incidence->setUid( uid() ); - incidence->setDescription( body() ); - incidence->setCategories( categories() ); - incidence->setCreated( utcToLocal( creationDate() ) ); - incidence->setLastModified( lastModified() ); - switch( sensitivity() ) { - case 1: - incidence->setSecrecy( KCalCore::Incidence::SecrecyPrivate ); - break; - case 2: - incidence->setSecrecy( KCalCore::Incidence::SecrecyConfidential ); - break; - default: - incidence->setSecrecy( KCalCore::Incidence::SecrecyPublic ); - break; - } - - // TODO: Attachments -} - -void KolabBase::setFields( const KABC::Addressee* addressee ) -{ - // An addressee does not have a creation date, so somehow we should - // make one, if this is a new entry - - setUid( addressee->uid() ); - setBody( addressee->note() ); - setCategories( addressee->categories().join( "," ) ); - - // Set creation-time and last-modification-time - const QString creationString = addressee->custom( "KOLAB", "CreationDate" ); - kDebug() <<"Creation time string:" << creationString; - KDateTime creationDate; - if ( creationString.isEmpty() ) { - creationDate = KDateTime::currentDateTime(KDateTime::Spec( mTimeZone ) ); - kDebug() <<"Creation date set to current time"; - } - else { - creationDate = stringToDateTime( creationString ); - kDebug() <<"Creation date loaded"; - } - KDateTime modified = KDateTime( addressee->revision(), mTimeZone ); - if ( !modified.isValid() ) - modified = KDateTime::currentUtcDateTime(); - setLastModified( modified ); - if ( modified < creationDate ) { - // It's not possible that the modification date is earlier than creation - creationDate = modified; - kDebug() <<"Creation date set to modification date"; - } - setCreationDate( creationDate ); - const QString newCreationDate = dateTimeToString( creationDate ); - if ( creationString != newCreationDate ) { - // We modified the creation date, so store it for future reference - const_cast<KABC::Addressee*>( addressee ) - ->insertCustom( "KOLAB", "CreationDate", newCreationDate ); - kDebug() <<"Creation date modified. New one:" << newCreationDate; - } - - switch( addressee->secrecy().type() ) { - case KABC::Secrecy::Private: - setSensitivity( Private ); - break; - case KABC::Secrecy::Confidential: - setSensitivity( Confidential ); - break; - default: - setSensitivity( Public ); - } - - // TODO: Attachments -} - -void KolabBase::saveTo( KABC::Addressee* addressee ) const -{ - addressee->setUid( uid() ); - addressee->setNote( body() ); - addressee->setCategories( categories().split( ',', QString::SkipEmptyParts ) ); - addressee->setRevision( lastModified().toZone( mTimeZone ).dateTime() ); - addressee->insertCustom( "KOLAB", "CreationDate", - dateTimeToString( creationDate() ) ); - - switch( sensitivity() ) { - case Private: - addressee->setSecrecy( KABC::Secrecy( KABC::Secrecy::Private ) ); - break; - case Confidential: - addressee->setSecrecy( KABC::Secrecy( KABC::Secrecy::Confidential ) ); - break; - default: - addressee->setSecrecy( KABC::Secrecy( KABC::Secrecy::Public ) ); - break; - } - // TODO: Attachments -} - -void KolabBase::setFields( const KABC::ContactGroup* contactGroup ) -{ - // A contactgroup does not have a creation date, so somehow we should - // make one, if this is a new entry - - setUid( contactGroup->id() ); - - // Set creation-time and last-modification-time - KDateTime creationDate = KDateTime::currentDateTime( KDateTime::Spec( mTimeZone ) ); - kDebug() <<"Creation date set to current time"; - - KDateTime modified = KDateTime::currentUtcDateTime(); - setLastModified( modified ); - if ( modified < creationDate ) { - // It's not possible that the modification date is earlier than creation - creationDate = modified; - kDebug() <<"Creation date set to modification date"; - } - setCreationDate( creationDate ); -} - -void KolabBase::saveTo( KABC::ContactGroup* contactGroup ) const -{ - contactGroup->setId( uid() ); -} - -void KolabBase::setUid( const QString& uid ) -{ - mUid = uid; -} - -QString KolabBase::uid() const -{ - return mUid; -} - -void KolabBase::setBody( const QString& body ) -{ - mBody = body; -} - -QString KolabBase::body() const -{ - return mBody; -} - -void KolabBase::setCategories( const QString& categories ) -{ - mCategories = categories; -} - -QString KolabBase::categories() const -{ - return mCategories; -} - -void KolabBase::setCreationDate( const KDateTime& date ) -{ - mCreationDate = date; -} - -KDateTime KolabBase::creationDate() const -{ - return mCreationDate; -} - -void KolabBase::setLastModified( const KDateTime& date ) -{ - mLastModified = date; -} - -KDateTime KolabBase::lastModified() const -{ - return mLastModified; -} - -void KolabBase::setSensitivity( Sensitivity sensitivity ) -{ - mSensitivity = sensitivity; -} - -KolabBase::Sensitivity KolabBase::sensitivity() const -{ - return mSensitivity; -} - -void KolabBase::setPilotSyncId( unsigned long id ) -{ - mHasPilotSyncId = true; - mPilotSyncId = id; -} - -bool KolabBase::hasPilotSyncId() const -{ - return mHasPilotSyncId; -} - -unsigned long KolabBase::pilotSyncId() const -{ - return mPilotSyncId; -} - -void KolabBase::setPilotSyncStatus( int status ) -{ - mHasPilotSyncStatus = true; - mPilotSyncStatus = status; -} - -bool KolabBase::hasPilotSyncStatus() const -{ - return mHasPilotSyncStatus; -} - -int KolabBase::pilotSyncStatus() const -{ - return mPilotSyncStatus; -} - -bool KolabBase::loadEmailAttribute( QDomElement& element, Email& email ) -{ - for ( QDomNode n = element.firstChild(); !n.isNull(); n = n.nextSibling() ) { - if ( n.isComment() ) - continue; - if ( n.isElement() ) { - QDomElement e = n.toElement(); - const QString tagName = e.tagName(); - - if ( tagName == "display-name" ) - email.displayName = e.text(); - else if ( tagName == "smtp-address" ) - email.smtpAddress = e.text(); - else - // TODO: Unhandled tag - save for later storage - kDebug() <<"Warning: Unhandled tag" << e.tagName(); - } else - kDebug() <<"Node is not a comment or an element???"; - } - - return true; -} - -void KolabBase::saveEmailAttribute( QDomElement& element, const Email& email, - const QString& tagName ) const -{ - QDomElement e = element.ownerDocument().createElement( tagName ); - element.appendChild( e ); - writeString( e, "display-name", email.displayName ); - writeString( e, "smtp-address", email.smtpAddress ); -} - -bool KolabBase::loadAttribute( QDomElement& element ) -{ - const QString tagName = element.tagName(); - switch ( tagName[0].toLatin1() ) { - case 'u': - if ( tagName == "uid" ) { - setUid( element.text() ); - return true; - } - break; - case 'b': - if ( tagName == "body" ) { - setBody( element.text() ); - return true; - } - break; - case 'c': - if ( tagName == "categories" ) { - setCategories( element.text() ); - return true; - } - if ( tagName == "creation-date" ) { - setCreationDate( stringToDateTime( element.text() ) ); - return true; - } - break; - case 'l': - if ( tagName == "last-modification-date" ) { - setLastModified( stringToDateTime( element.text() ) ); - return true; - } - break; - case 's': - if ( tagName == "sensitivity" ) { - setSensitivity( stringToSensitivity( element.text() ) ); - return true; - } - break; - case 'p': - if ( tagName == "product-id" ) - return true; // ignore this field - if ( tagName == "pilot-sync-id" ) { - setPilotSyncId( element.text().toULong() ); - return true; - } - if ( tagName == "pilot-sync-status" ) { - setPilotSyncStatus( element.text().toInt() ); - return true; - } - break; - default: - break; - } - return false; -} - -bool KolabBase::saveAttributes( QDomElement& element ) const -{ - writeString( element, "product-id", productID() ); - writeString( element, "uid", uid() ); - writeString( element, "body", body() ); - writeString( element, "categories", categories() ); - writeString( element, "creation-date", dateTimeToString( creationDate().toUtc() ) ); - writeString( element, "last-modification-date", dateTimeToString( lastModified().toUtc() ) ); - writeString( element, "sensitivity", sensitivityToString( sensitivity() ) ); - if ( hasPilotSyncId() ) - writeString( element, "pilot-sync-id", QString::number( pilotSyncId() ) ); - if ( hasPilotSyncStatus() ) - writeString( element, "pilot-sync-status", QString::number( pilotSyncStatus() ) ); - return true; -} - -bool KolabBase::load( const QString& xml ) -{ - const QDomDocument document = loadDocument( xml ); - if ( document.isNull() ) - return false; - // XML file loaded into tree. Now parse it - return loadXML( document ); -} - -QDomDocument KolabBase::loadDocument( const QString& xmlData ) -{ - QString errorMsg; - int errorLine, errorColumn; - QDomDocument document; - bool ok = document.setContent( xmlData, &errorMsg, &errorLine, &errorColumn ); - - if ( !ok ) { - qWarning( "Error loading document: %s, line %d, column %d", qPrintable( errorMsg ), errorLine, errorColumn ); - return QDomDocument(); - } - - return document; -} - -QDomDocument KolabBase::domTree() -{ - QDomDocument document; - - QString p = "version=\"1.0\" encoding=\"UTF-8\""; - document.appendChild(document.createProcessingInstruction( "xml", p ) ); - - return document; -} - - -QString KolabBase::dateTimeToString( const KDateTime& time ) -{ - return time.toString( KDateTime::ISODate ); -} - -QString KolabBase::dateToString( const QDate& date ) -{ - return date.toString( Qt::ISODate ); -} - -KDateTime KolabBase::stringToDateTime( const QString& _date ) -{ - const QString date( _date ); - return KDateTime::fromString( date, KDateTime::ISODate ); -} - -QDate KolabBase::stringToDate( const QString& date ) -{ - return QDate::fromString( date, Qt::ISODate ); -} - -QString KolabBase::sensitivityToString( Sensitivity s ) -{ - switch( s ) { - case Private: return "private"; - case Confidential: return "confidential"; - case Public: return "public"; - } - - return "What what what???"; -} - -KolabBase::Sensitivity KolabBase::stringToSensitivity( const QString& s ) -{ - if ( s == "private" ) - return Private; - if ( s == "confidential" ) - return Confidential; - return Public; -} - -QString KolabBase::colorToString( const QColor& color ) -{ - // Color is in the format "#RRGGBB" - return color.name(); -} - -QColor KolabBase::stringToColor( const QString& s ) -{ - return QColor( s ); -} - -void KolabBase::writeString( QDomElement& element, const QString& tag, - const QString& tagString ) -{ - if ( !tagString.isEmpty() ) { - QDomElement e = element.ownerDocument().createElement( tag ); - QDomText t = element.ownerDocument().createTextNode( tagString ); - e.appendChild( t ); - element.appendChild( e ); - } -} - -KDateTime KolabBase::localToUTC( const KDateTime& time ) const -{ - return time.toUtc(); -} - -KDateTime KolabBase::utcToLocal( const KDateTime& time ) const -{ - KDateTime dt = time; - dt.setTimeSpec( KDateTime::UTC ); - return dt; -}
View file
libkolab-2.0.tar.gz/kolabformatV2/kolabbase.h
Deleted
@@ -1,183 +0,0 @@ -/* - This file is part of the kolab resource - the implementation of the - Kolab storage format. See www.kolab.org for documentation on this. - - Copyright (c) 2004 Bo Thorsen <bo@sonofthor.dk> - - 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 Qt library by Trolltech AS, Norway (or with modified versions - of Qt that use the same license as Qt), 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 - Qt. 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 KOLABV2BASE_H -#define KOLABV2BASE_H - - -#include <kcalcore/incidence.h> - -#include <kdatetime.h> -#include <ktimezone.h> - -#include <QColor> -#include <qdom.h> - -namespace KABC { - class Addressee; - class ContactGroup; -} - -namespace KolabV2 { - -class KolabBase { -public: - struct Email { - public: - Email( const QString& name = QString(), - const QString& email = QString() ) - : displayName( name ), smtpAddress( email ) - { - } - - QString displayName; - QString smtpAddress; - }; - - enum Sensitivity { Public = 0, Private = 1, Confidential = 2 }; - - explicit KolabBase( const QString& time_zone = QString() ); - virtual ~KolabBase(); - - // Return a string identifying this type - virtual QString type() const = 0; - - virtual void setUid( const QString& uid ); - virtual QString uid() const; - - virtual void setBody( const QString& body ); - virtual QString body() const; - - virtual void setCategories( const QString& categories ); - virtual QString categories() const; - - virtual void setCreationDate( const KDateTime& date ); - virtual KDateTime creationDate() const; - - virtual void setLastModified( const KDateTime& date ); - virtual KDateTime lastModified() const; - - virtual void setSensitivity( Sensitivity sensitivity ); - virtual Sensitivity sensitivity() const; - - virtual void setPilotSyncId( unsigned long id ); - virtual bool hasPilotSyncId() const; - virtual unsigned long pilotSyncId() const; - - virtual void setPilotSyncStatus( int status ); - virtual bool hasPilotSyncStatus() const; - virtual int pilotSyncStatus() const; - - // String - Date conversion methods - static QString dateTimeToString( const KDateTime& time ); - static QString dateToString( const QDate& date ); - static KDateTime stringToDateTime( const QString& time ); - static QDate stringToDate( const QString& date ); - - // String - Sensitivity conversion methods - static QString sensitivityToString( Sensitivity ); - static Sensitivity stringToSensitivity( const QString& ); - - // String - Color conversion methods - static QString colorToString( const QColor& ); - static QColor stringToColor( const QString& ); - - // Load this object by reading the XML file - bool load( const QString& xml ); - static QDomDocument loadDocument( const QString& xmlData ); - - // Load this QDomDocument - virtual bool loadXML( const QDomDocument& xml ) = 0; - - // Serialize this object to an XML string - virtual QString saveXML() const = 0; - -protected: - /// Read all known fields from this ical incidence - void setFields( const KCalCore::Incidence::Ptr & ); - - /// Save all known fields into this ical incidence - void saveTo( const KCalCore::Incidence::Ptr & ) const; - - /// Read all known fields from this contact - void setFields( const KABC::Addressee* ); - - /// Save all known fields into this contact - void saveTo( KABC::Addressee* ) const; - - /// Read all known fields from this contact group - void setFields( const KABC::ContactGroup* ); - - /// Save all known fields into this contact groupd - void saveTo( KABC::ContactGroup* ) const; - - // This just makes the initial dom tree with version and doctype - static QDomDocument domTree(); - - bool loadEmailAttribute( QDomElement& element, Email& email ); - - void saveEmailAttribute( QDomElement& element, const Email& email, - const QString& tagName = "email" ) const; - - // Load the attributes of this class - virtual bool loadAttribute( QDomElement& ); - - // Save the attributes of this class - virtual bool saveAttributes( QDomElement& ) const; - - // Return the product ID - virtual QString productID() const = 0; - - // Write a string tag - static void writeString( QDomElement&, const QString&, const QString& ); - - KDateTime localToUTC( const KDateTime& time ) const; - KDateTime utcToLocal( const KDateTime& time ) const; - - QString mUid; - QString mBody; - QString mCategories; - KDateTime mCreationDate; - KDateTime mLastModified; - Sensitivity mSensitivity; - KTimeZone mTimeZone; - - // KPilot synchronization stuff - bool mHasPilotSyncId, mHasPilotSyncStatus; - unsigned long mPilotSyncId; - int mPilotSyncStatus; -}; - -} - -#endif // KOLABBASE_H
View file
libkolab-2.0.tar.gz/kolabformatV2/note.cpp
Deleted
@@ -1,230 +0,0 @@ -/* - This file is part of the kolab resource - the implementation of the - Kolab storage format. See www.kolab.org for documentation on this. - - Copyright (c) 2004 Bo Thorsen <bo@sonofthor.dk> - - 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 Qt library by Trolltech AS, Norway (or with modified versions - of Qt that use the same license as Qt), 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 - Qt. 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 "note.h" -#include "libkolab-version.h" - -#include <kcalcore/journal.h> -#include <kdebug.h> - -using namespace KolabV2; - - -KCalCore::Journal::Ptr Note::xmlToJournal( const QString& xml ) -{ - Note note; - note.load( xml ); - KCalCore::Journal::Ptr journal( new KCalCore::Journal() ); - note.saveTo( journal ); - return journal; -} - -QString Note::journalToXML( const KCalCore::Journal::Ptr &journal ) -{ - Note note( journal ); - return note.saveXML(); -} - -Note::Note( const KCalCore::Journal::Ptr &journal ) : mRichText( false ) -{ - if ( journal ) - setFields( journal ); -} - -Note::~Note() -{ -} - -void Note::setSummary( const QString& summary ) -{ - mSummary = summary; -} - -QString Note::summary() const -{ - return mSummary; -} - -void Note::setBackgroundColor( const QColor& bgColor ) -{ - mBackgroundColor = bgColor; -} - -QColor Note::backgroundColor() const -{ - return mBackgroundColor; -} - -void Note::setForegroundColor( const QColor& fgColor ) -{ - mForegroundColor = fgColor; -} - -QColor Note::foregroundColor() const -{ - return mForegroundColor; -} - -void Note::setRichText( bool richText ) -{ - mRichText = richText; -} - -bool Note::richText() const -{ - return mRichText; -} - -bool Note::loadAttribute( QDomElement& element ) -{ - QString tagName = element.tagName(); - if ( tagName == "summary" ) - setSummary( element.text() ); - else if ( tagName == "foreground-color" ) - setForegroundColor( stringToColor( element.text() ) ); - else if ( tagName == "background-color" ) - setBackgroundColor( stringToColor( element.text() ) ); - else if ( tagName == "knotes-richtext" ) - mRichText = ( element.text() == "true" ); - else - return KolabBase::loadAttribute( element ); - - // We handled this - return true; -} - -bool Note::saveAttributes( QDomElement& element ) const -{ - // Save the base class elements - KolabBase::saveAttributes( element ); - - // Save the elements -#if 0 - QDomComment c = element.ownerDocument().createComment( "Note specific attributes" ); - element.appendChild( c ); -#endif - - writeString( element, "summary", summary() ); - if ( foregroundColor().isValid() ) - writeString( element, "foreground-color", colorToString( foregroundColor() ) ); - if ( backgroundColor().isValid() ) - writeString( element, "background-color", colorToString( backgroundColor() ) ); - writeString( element, "knotes-richtext", mRichText ? "true" : "false" ); - - return true; -} - - -bool Note::loadXML( const QDomDocument& document ) -{ - QDomElement top = document.documentElement(); - - if ( top.tagName() != "note" ) { - qWarning( "XML error: Top tag was %s instead of the expected note", - top.tagName().toAscii().data() ); - return false; - } - - for ( QDomNode n = top.firstChild(); !n.isNull(); n = n.nextSibling() ) { - if ( n.isComment() ) - continue; - if ( n.isElement() ) { - QDomElement e = n.toElement(); - if ( !loadAttribute( e ) ) - // TODO: Unhandled tag - save for later storage - kDebug() <<"Warning: Unhandled tag" << e.tagName(); - } else - kDebug() <<"Node is not a comment or an element???"; - } - - return true; -} - -QString Note::saveXML() const -{ - QDomDocument document = domTree(); - QDomElement element = document.createElement( "note" ); - element.setAttribute( "version", "1.0" ); - saveAttributes( element ); - document.appendChild( element ); - return document.toString(); -} - -void Note::setFields( const KCalCore::Journal::Ptr &journal ) -{ - KolabBase::setFields( journal ); - - setSummary( journal->summary() ); - - QString property = journal->customProperty( "KNotes", "BgColor" ); - if ( !property.isEmpty() ) { - setBackgroundColor( property ); - } else { - setBackgroundColor( "yellow" ); - } - - property = journal->customProperty( "KNotes", "FgColor" ); - if ( !property.isEmpty() ) { - setForegroundColor( property ); - } else { - setForegroundColor( "black" ); - } - - property = journal->customProperty( "KNotes", "RichText" ); - if ( !property.isEmpty() ) { - setRichText( property == "true" ? true : false ); - } else { - setRichText( "false" ); - } -} - -void Note::saveTo( const KCalCore::Journal::Ptr &journal ) -{ - KolabBase::saveTo( journal ); - - // TODO: background and foreground - journal->setSummary( summary() ); - if ( foregroundColor().isValid() ) - journal->setCustomProperty( "KNotes", "FgColor", - colorToString( foregroundColor() ) ); - if ( backgroundColor().isValid() ) - journal->setCustomProperty( "KNotes", "BgColor", - colorToString( backgroundColor() ) ); - journal->setCustomProperty( "KNotes", "RichText", - richText() ? "true" : "false" ); -} - -QString Note::productID() const -{ - return QString( "KNotes %1, Kolab resource" ).arg( LIBKOLAB_LIB_VERSION_STRING ); -}
View file
libkolab-2.0.tar.gz/kolabformatV2/note.h
Deleted
@@ -1,109 +0,0 @@ -/* - This file is part of the kolab resource - the implementation of the - Kolab storage format. See www.kolab.org for documentation on this. - - Copyright (c) 2004 Bo Thorsen <bo@sonofthor.dk> - - 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 Qt library by Trolltech AS, Norway (or with modified versions - of Qt that use the same license as Qt), 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 - Qt. 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 KOLABV2_NOTE_H -#define KOLABV2_NOTE_H - -#include <kcalcore/journal.h> - -#include "kolabbase.h" - -class QDomElement; - -namespace KolabV2 { - -/** - * This class represents a note, and knows how to load/save it - * from/to XML, and from/to a KCalCore::Journal. - * The instances of this class are temporary, only used to convert - * one to the other. - */ -class Note : public KolabBase { -public: - /// Use this to parse an xml string to a journal entry - /// The caller is responsible for deleting the returned journal - static KCalCore::Journal::Ptr xmlToJournal( const QString& xml ); - - /// Use this to get an xml string describing this journal entry - static QString journalToXML( const KCalCore::Journal::Ptr & ); - - /// Create a note object and - explicit Note( const KCalCore::Journal::Ptr &journal = KCalCore::Journal::Ptr() ); - virtual ~Note(); - - void saveTo( const KCalCore::Journal::Ptr &journal ); - - virtual QString type() const { return "Note"; } - - virtual void setSummary( const QString& summary ); - virtual QString summary() const; - - virtual void setBackgroundColor( const QColor& bgColor ); - virtual QColor backgroundColor() const; - - virtual void setForegroundColor( const QColor& fgColor ); - virtual QColor foregroundColor() const; - - virtual void setRichText( bool richText ); - virtual bool richText() const; - - // Load the attributes of this class - virtual bool loadAttribute( QDomElement& ); - - // Save the attributes of this class - virtual bool saveAttributes( QDomElement& ) const; - - // Load this note by reading the XML file - virtual bool loadXML( const QDomDocument& xml ); - - // Serialize this note to an XML string - virtual QString saveXML() const; - -protected: - // Read all known fields from this ical incidence - void setFields( const KCalCore::Journal::Ptr & ); - - // Save all known fields into this ical incidence - void saveTo( const KCalCore::Incidence::Ptr & ) const; - - QString productID() const; - - QString mSummary; - QColor mBackgroundColor; - QColor mForegroundColor; - bool mRichText; -}; - -} - -#endif // KOLAB_NOTE_H
View file
libkolab-2.0.tar.gz/kolabformatV2/task.cpp
Deleted
@@ -1,349 +0,0 @@ -/* - This file is part of the kolab resource - the implementation of the - Kolab storage format. See www.kolab.org for documentation on this. - - Copyright (c) 2004 Bo Thorsen <bo@sonofthor.dk> - - 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 Qt library by Trolltech AS, Norway (or with modified versions - of Qt that use the same license as Qt), 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 - Qt. 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 "task.h" - -#include <kcalcore/todo.h> -#include <kdebug.h> - -using namespace KolabV2; - -KCalCore::Todo::Ptr Task::fromXml( const QDomDocument& xmlDoc, const QString& tz ) -{ - Task task( tz ); - task.loadXML( xmlDoc ); - KCalCore::Todo::Ptr todo( new KCalCore::Todo() ); - task.saveTo( todo ); - return todo; -} - -QString Task::taskToXML( const KCalCore::Todo::Ptr &todo, const QString& tz ) -{ - Task task( tz, todo ); - return task.saveXML(); -} - -Task::Task( const QString& tz, const KCalCore::Todo::Ptr &task ) - : Incidence( tz, task ), - mPercentCompleted( 0 ), - mStatus( KCalCore::Incidence::StatusNone ), - mHasStartDate( false ), mHasDueDate( false ), - mHasCompletedDate( false ) -{ - if ( task ) { - setFields( task ); - } -} - -Task::~Task() -{ -} - -void Task::setPercentCompleted( int percent ) -{ - mPercentCompleted = percent; -} - -int Task::percentCompleted() const -{ - return mPercentCompleted; -} - -void Task::setStatus( KCalCore::Incidence::Status status ) -{ - mStatus = status; -} - -KCalCore::Incidence::Status Task::status() const -{ - return mStatus; -} - -void Task::setParent( const QString& parentUid ) -{ - mParent = parentUid; -} - -QString Task::parent() const -{ - return mParent; -} - -void Task::setDueDate( const KDateTime &date ) -{ - mDueDate = date; - mHasDueDate = true; -} - -void Task::setDueDate( const QDate &date ) -{ - mDueDate = KDateTime( date ); - mHasDueDate = true; - mFloatingStatus = AllDay; -} - -void Task::setDueDate( const QString &date ) -{ - if ( date.length() > 10 ) { - // This is a date + time - setDueDate( stringToDateTime( date ) ); - } else { - // This is only a date - setDueDate( stringToDate( date ) ); - } -} - -KDateTime Task::dueDate() const -{ - return mDueDate; -} - -void Task::setHasStartDate( bool v ) -{ - mHasStartDate = v; -} - -bool Task::hasStartDate() const -{ - return mHasStartDate; -} - -bool Task::hasDueDate() const -{ - return mHasDueDate; -} - -void Task::setCompletedDate( const KDateTime& date ) -{ - mCompletedDate = date; - mHasCompletedDate = true; -} - -KDateTime Task::completedDate() const -{ - return mCompletedDate; -} - -bool Task::hasCompletedDate() const -{ - return mHasCompletedDate; -} - -bool Task::loadAttribute( QDomElement& element ) -{ - QString tagName = element.tagName(); - - if ( tagName == "completed" ) { - bool ok; - int percent = element.text().toInt( &ok ); - if ( !ok || percent < 0 || percent > 100 ) - percent = 0; - setPercentCompleted( percent ); - } else if ( tagName == "status" ) { - if ( element.text() == "in-progress" ) - setStatus( KCalCore::Incidence::StatusInProcess ); - else if ( element.text() == "completed" ) - setStatus( KCalCore::Incidence::StatusCompleted ); - else if ( element.text() == "waiting-on-someone-else" ) - setStatus( KCalCore::Incidence::StatusNeedsAction ); - else if ( element.text() == "deferred" ) - // Guessing a status here - setStatus( KCalCore::Incidence::StatusCanceled ); - else - // Default - setStatus( KCalCore::Incidence::StatusNone ); - } else if ( tagName == "due-date" ) { - setDueDate( element.text() ); - } else if ( tagName == "parent" ) { - setParent( element.text() ); - } else if ( tagName == "x-completed-date" ) { - setCompletedDate( stringToDateTime( element.text() ) ); - } else if ( tagName == "start-date" ) { - setHasStartDate( true ); - setStartDate( element.text() ); - } else - return Incidence::loadAttribute( element ); - - // We handled this - return true; -} - -bool Task::saveAttributes( QDomElement& element ) const -{ - // Save the base class elements - Incidence::saveAttributes( element ); - - writeString( element, "completed", QString::number( percentCompleted() ) ); - - switch( status() ) { - case KCalCore::Incidence::StatusInProcess: - writeString( element, "status", "in-progress" ); - break; - case KCalCore::Incidence::StatusCompleted: - writeString( element, "status", "completed" ); - break; - case KCalCore::Incidence::StatusNeedsAction: - writeString( element, "status", "waiting-on-someone-else" ); - break; - case KCalCore::Incidence::StatusCanceled: - writeString( element, "status", "deferred" ); - break; - case KCalCore::Incidence::StatusNone: - writeString( element, "status", "not-started" ); - break; - case KCalCore::Incidence::StatusTentative: - case KCalCore::Incidence::StatusConfirmed: - case KCalCore::Incidence::StatusDraft: - case KCalCore::Incidence::StatusFinal: - case KCalCore::Incidence::StatusX: - // All of these are saved as StatusNone. - writeString( element, "status", "not-started" ); - break; - } - - if ( hasDueDate() ) { - if ( mFloatingStatus == HasTime ) { - writeString( element, "due-date", dateTimeToString( dueDate() ) ); - } else { - writeString( element, "due-date", dateToString( dueDate().date() ) ); - } - } - - if ( !parent().isNull() ) { - writeString( element, "parent", parent() ); - } - - if ( hasCompletedDate() && percentCompleted() == 100 ) { - writeString( element, "x-completed-date", dateTimeToString( completedDate() ) ); - } - - return true; -} - - -bool Task::loadXML( const QDomDocument& document ) -{ - QDomElement top = document.documentElement(); - - if ( top.tagName() != "task" ) { - qWarning( "XML error: Top tag was %s instead of the expected task", - top.tagName().toAscii().data() ); - return false; - } - setHasStartDate( false ); // todo's don't necessarily have one - - for ( QDomNode n = top.firstChild(); !n.isNull(); n = n.nextSibling() ) { - if ( n.isComment() ) - continue; - if ( n.isElement() ) { - QDomElement e = n.toElement(); - if ( !loadAttribute( e ) ) - // TODO: Unhandled tag - save for later storage - kDebug() <<"Warning: Unhandled tag" << e.tagName(); - } else - kDebug() <<"Node is not a comment or an element???"; - } - - return true; -} - -QString Task::saveXML() const -{ - QDomDocument document = domTree(); - QDomElement element = document.createElement( "task" ); - element.setAttribute( "version", "1.0" ); - saveAttributes( element ); - if ( !hasStartDate() && startDate().isValid() ) { - // events and journals always have a start date, but tasks don't. - // Remove the entry done by the inherited save above, because we - // don't have one. - QDomNodeList l = element.elementsByTagName( "start-date" ); - Q_ASSERT( l.count() == 1 ); - element.removeChild( l.item( 0 ) ); - } - document.appendChild( element ); - return document.toString(); -} - -void Task::setFields( const KCalCore::Todo::Ptr &task ) -{ - Incidence::setFields( task ); - - setPercentCompleted( task->percentComplete() ); - setStatus( task->status() ); - setHasStartDate( task->hasStartDate() ); - - if ( task->hasDueDate() ) { - if ( task->allDay() ) { - // This is a floating task. Don't timezone move this one - mFloatingStatus = AllDay; - setDueDate( KDateTime( task->dtDue().date() ) ); - } else { - mFloatingStatus = HasTime; - setDueDate( localToUTC( task->dtDue() ) ); - } - } else { - mHasDueDate = false; - } - - if ( !task->relatedTo().isEmpty() ) { - setParent( task->relatedTo() ); - } else{ - setParent( QString() ); - } - - if ( task->hasCompletedDate() && task->percentComplete() == 100 ) { - setCompletedDate( localToUTC( task->completed() ) ); - } else { - mHasCompletedDate = false; - } -} - -void Task::saveTo( const KCalCore::Todo::Ptr &task ) -{ - Incidence::saveTo( task ); - - task->setPercentComplete( percentCompleted() ); - task->setStatus( status() ); - task->setHasStartDate( hasStartDate() ); - task->setHasDueDate( hasDueDate() ); - if ( hasDueDate() ) - task->setDtDue( utcToLocal( dueDate() ) ); - - if ( !parent().isEmpty() ) { - task->setRelatedTo( parent() ); - } - - if ( hasCompletedDate() && task->percentComplete() == 100 ) - task->setCompleted( utcToLocal( mCompletedDate ) ); -}
View file
libkolab-2.0.tar.gz/kolabformatV2/task.h
Deleted
@@ -1,127 +0,0 @@ -/* - This file is part of the kolab resource - the implementation of the - Kolab storage format. See www.kolab.org for documentation on this. - - Copyright (c) 2004 Bo Thorsen <bo@sonofthor.dk> - - 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 Qt library by Trolltech AS, Norway (or with modified versions - of Qt that use the same license as Qt), 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 - Qt. 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 KOLABV2_TASK_H -#define KOLABV2_TASK_H - -#include "incidence.h" - -#include <kcalcore/todo.h> -#include <kcalcore/incidence.h> - -class QDomElement; - -namespace KCal { - class ResourceKolab; -} - -namespace KolabV2 { - -/** - * This class represents a task, and knows how to load/save it - * from/to XML, and from/to a KCalCore::Todo. - * The instances of this class are temporary, only used to convert - * one to the other. - */ -class Task : public Incidence { -public: - /// Use this to parse an xml string to a task entry - /// The caller is responsible for deleting the returned task - static KCalCore::Todo::Ptr fromXml( const QDomDocument& xmlDoc, const QString& tz/*, KCalCore::ResourceKolab *res = 0, - const QString& subResource = QString(), quint32 sernum = 0 */); - - /// Use this to get an xml string describing this task entry - static QString taskToXML( const KCalCore::Todo::Ptr &, const QString& tz ); - - explicit Task( /*KCalCore::ResourceKolab *res, const QString& subResource, quint32 sernum,*/ - const QString& tz, const KCalCore::Todo::Ptr &todo = KCalCore::Todo::Ptr() ); - virtual ~Task(); - - virtual QString type() const { return "Task"; } - - void saveTo( const KCalCore::Todo::Ptr &todo ); - - virtual void setPercentCompleted( int percent ); - virtual int percentCompleted() const; - - virtual void setStatus( KCalCore::Incidence::Status status ); - virtual KCalCore::Incidence::Status status() const; - - virtual void setParent( const QString& parentUid ); - virtual QString parent() const; - - virtual void setHasStartDate( bool ); - virtual bool hasStartDate() const; - - virtual void setDueDate( const KDateTime& date ); - virtual void setDueDate( const QString &date ); - virtual void setDueDate( const QDate &date ); - virtual KDateTime dueDate() const; - virtual bool hasDueDate() const; - - virtual void setCompletedDate( const KDateTime& date ); - virtual KDateTime completedDate() const; - virtual bool hasCompletedDate() const; - - // Load the attributes of this class - virtual bool loadAttribute( QDomElement& ); - - // Save the attributes of this class - virtual bool saveAttributes( QDomElement& ) const; - - // Load this task by reading the XML file - virtual bool loadXML( const QDomDocument& xml ); - - // Serialize this task to an XML string - virtual QString saveXML() const; - -protected: - // Read all known fields from this ical todo - void setFields( const KCalCore::Todo::Ptr & ); - - int mPercentCompleted; - KCalCore::Incidence::Status mStatus; - QString mParent; - - bool mHasStartDate; - - bool mHasDueDate; - KDateTime mDueDate; - - bool mHasCompletedDate; - KDateTime mCompletedDate; -}; - -} - -#endif // KOLAB_TASK_H
View file
libkolab-2.0.tar.gz/libkolab_config.h.in
Deleted
@@ -1,6 +0,0 @@ -/* This file is generated from libkolab_config.h.cmake. */ - -/* Whether akonadi/tag.h exists. */ -#cmakedefine HAVE_TAG_H 1 -/* Whether akonadi/relation.h exists. */ -#cmakedefine HAVE_RELATION_H 1
View file
libkolab-2.0.tar.gz/tests/benchmark.cpp
Deleted
@@ -1,91 +0,0 @@ -/* - * Copyright (C) 2011 Christian Mollekopf <mollekopf@kolabsys.com> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include "benchmark.h" -#include "kolabformatV2/event.h" -#include "conversion/kcalconversion.h" -#include <kmime/kmime_message.h> -#include <kolabformat.h> -#include <kdebug.h> -#include "testutils.h" - -KMime::Message::Ptr readMimeFile( const QString &fileName ) -{ - QFile file( fileName ); - file.open( QFile::ReadOnly ); - const QByteArray data = file.readAll(); - Q_ASSERT( !data.isEmpty() ); - - KMime::Message *msg = new KMime::Message; - msg->setContent( data ); - msg->parse(); - return KMime::Message::Ptr(msg); -} - -KMime::Content* findContentByType(const KMime::Message::Ptr &data, const QByteArray &type) -{ - const KMime::Content::List list = data->contents(); - Q_FOREACH(KMime::Content *c, list) { - if (c->contentType()->mimeType() == type) - return c; - } - return 0; - -} - -void BenchmarkTests::parsingBenchmarkComparison_data() -{ - QTest::addColumn<bool>("v2Parser"); - QTest::newRow("v2") << true; - QTest::newRow("v3") << false; -} - -void BenchmarkTests::parsingBenchmarkComparison() -{ - const KMime::Message::Ptr kolabItem = readMimeFile( TESTFILEDIR+QString::fromLatin1("/v2/event/complex.ics.mime") ); - KMime::Content *xmlContent = findContentByType( kolabItem, "application/x-vnd.kolab.event" ); - QVERIFY ( xmlContent ); - const QByteArray xmlData = xmlContent->decodedContent(); - // qDebug() << xmlData; - const QDomDocument xmlDoc = KolabV2::Event::loadDocument( QString::fromUtf8(xmlData) ); - QVERIFY ( !xmlDoc.isNull() ); - const KCalCore::Event::Ptr i = KolabV2::Event::fromXml( xmlDoc, QString::fromLatin1("Europe/Berlin") ); - QVERIFY ( i ); - const Kolab::Event &event = Kolab::Conversion::fromKCalCore(*i); - const std::string &v3String = Kolab::writeEvent(event); - - QFETCH(bool, v2Parser); - - // Kolab::readEvent(v3String, false); //init parser (doesn't really change the results it seems) - // qDebug() << QString::fromUtf8(xmlData); - // qDebug() << "------------------------------------------------------------------------------------"; - // qDebug() << QString::fromStdString(v3String); - if (v2Parser) { - QBENCHMARK { - KolabV2::Event::fromXml( KolabV2::Event::loadDocument( QString::fromUtf8(xmlData) ), QString::fromLatin1("Europe/Berlin") ); - } - } else { - QBENCHMARK { - Kolab::readEvent(v3String, false); - } - } -} - - -QTEST_MAIN( BenchmarkTests ) - -#include "benchmark.moc"
View file
libkolab-2.0.tar.gz/tests/debugstreamtest.cpp
Deleted
@@ -1,56 +0,0 @@ -/* - * Copyright (C) 2012 Christian Mollekopf <mollekopf@kolabsys.com> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include "debugstreamtest.h" - -#include "kolabformat/errorhandler.h" - -#include <QTest> - -void DebugStreamTest::testDebugstream() -{ - Error() << "test1"; - Error() << "test2" << "bla" << 3 << QMap<QString, int>(); - QCOMPARE(Kolab::ErrorHandler::instance().getErrors().size(), 2); - QVERIFY(Kolab::ErrorHandler::instance().getErrors().first().message.contains("test1")); - QCOMPARE(Kolab::ErrorHandler::instance().getErrors().first().severity, Kolab::ErrorHandler::Error); - QVERIFY(Kolab::ErrorHandler::instance().getErrors().last().message.contains("bla")); -} - -void DebugStreamTest::testDebugNotLogged() -{ - Kolab::ErrorHandler::instance().clear(); - Debug() << "test1"; - QCOMPARE(Kolab::ErrorHandler::instance().getErrors().size(), 0); -} - -void DebugStreamTest::testHasError() -{ - Debug() << "test1"; - QCOMPARE(Kolab::ErrorHandler::errorOccured(), false); - Warning() << "test1"; - QCOMPARE(Kolab::ErrorHandler::errorOccured(), false); - Error() << "test1"; - QCOMPARE(Kolab::ErrorHandler::errorOccured(), true); - Kolab::ErrorHandler::clearErrors(); - QCOMPARE(Kolab::ErrorHandler::errorOccured(), false); -} - - -QTEST_MAIN( DebugStreamTest ) - -#include "debugstreamtest.moc" \ No newline at end of file
View file
libkolab-2.0.tar.gz/tests/debugstreamtest.h
Deleted
@@ -1,32 +0,0 @@ -/* - * Copyright (C) 2012 Christian Mollekopf <mollekopf@kolabsys.com> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef DEBUGSTREAMTEST_H -#define DEBUGSTREAMTEST_H - -#include <QObject> - -class DebugStreamTest: public QObject -{ - Q_OBJECT -private slots: - void testDebugstream(); - void testDebugNotLogged(); - void testHasError(); -}; - -#endif // DEBUGSTREAMTEST_H
View file
libkolab-2.0.tar.gz/tests/formattest.cpp
Deleted
@@ -1,489 +0,0 @@ -/* - * Copyright (C) 2012 Christian Mollekopf <mollekopf@kolabsys.com> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include "formattest.h" - -#include <QTest> -#include <QFile> -#include <QDebug> -#include <qprocess.h> -#include <qtemporaryfile.h> -#include <QBuffer> -#include <kdebug.h> -#include <ksystemtimezone.h> -#include <kolabcontainers.h> -#include <kolabformat.h> - -#include <kcalcore/icalformat.h> -#include <kabc/vcardconverter.h> -#include <kabc/contactgrouptool.h> -#include <akonadi/notes/noteutils.h> - -#include "testutils.h" -#include "kolabformat/kolabobject.h" -#include "kolabformat/errorhandler.h" -#include "kolabformat/kolabdefinitions.h" - -static bool compareMimeMessage( const KMime::Message::Ptr &msg, const KMime::Message::Ptr &expectedMsg ) -{ - // headers - KCOMPARE( msg->subject()->asUnicodeString(), expectedMsg->subject()->asUnicodeString() ); - if ( msg->from()->isEmpty() || expectedMsg->from()->isEmpty() ) { - KCOMPARE( msg->from()->asUnicodeString(), expectedMsg->from()->asUnicodeString() ); - } else { - KCOMPARE( msg->from()->mailboxes().first().address(), expectedMsg->from()->mailboxes().first().address() ); // matching address is enough, we don't need a display name - } - KCOMPARE( msg->contentType()->mimeType(), expectedMsg->contentType()->mimeType() ); - KCOMPARE( msg->headerByType( X_KOLAB_TYPE_HEADER )->as7BitString(), expectedMsg->headerByType( X_KOLAB_TYPE_HEADER )->as7BitString() ); - // date contains conversion time... - // KCOMPARE( msg->date()->asUnicodeString(), expectedMsg->date()->asUnicodeString() ); - - // body parts - KCOMPARE( msg->contents().size(), expectedMsg->contents().size() ); - for ( int i = 0; i < msg->contents().size(); ++i ) { - KMime::Content *part = msg->contents().at( i ); - KMime::Content *expectedPart = expectedMsg->contents().at( i ); - - // part headers - KCOMPARE( part->contentType()->mimeType(), expectedPart->contentType()->mimeType() ); - KCOMPARE( part->contentDisposition()->filename(), expectedPart->contentDisposition()->filename() ); - - KCOMPARE( part->decodedContent().isEmpty(), false ); - - QString content(part->decodedContent()); - normalizeMimemessage(content); - QString expected(expectedPart->decodedContent()); - normalizeMimemessage(expected); -// showDiff(expected, content); - - // part content - KCOMPARE( content.simplified(), expected.simplified() ); - } - return true; -} - -void FormatTest::initTestCase() -{ - QVERIFY2(KSystemTimeZones::isTimeZoneDaemonAvailable(), "Timezone support is required for this test. Either use libcalendaring or make sure KTimeZoned is available"); -} - -void FormatTest::testIncidence_data() -{ - QTest::addColumn<Kolab::Version>( "version" ); - QTest::addColumn<Kolab::ObjectType>( "type" ); - QTest::addColumn<QString>( "icalFileName" ); - QTest::addColumn<QString>( "mimeFileName" ); - - QTest::newRow( "v2eventSimple" ) << Kolab::KolabV2 << Kolab::EventObject << getPath("v2/event/simple.ics") << getPath("v2/event/simple.ics.mime"); - QTest::newRow( "v2eventComplex" ) << Kolab::KolabV2 << Kolab::EventObject << getPath("v2/event/complex.ics") << getPath("v2/event/complex.ics.mime"); - QTest::newRow( "v2eventAttachment" ) << Kolab::KolabV2 << Kolab::EventObject << getPath("v2/event/attachment.ics") << getPath("v2/event/attachment.ics.mime"); - QTest::newRow( "v2eventAllday" ) << Kolab::KolabV2 << Kolab::EventObject << getPath("v2/event/allday.ics") << getPath("v2/event/allday.ics.mime"); - QTest::newRow( "v2eventUtf8Attachment" ) << Kolab::KolabV2 << Kolab::EventObject << getPath("v2/event/attachmentUtf8.ics") << getPath("v2/event/attachmentUtf8.ics.mime"); - //The following test just fails because we have a nicer mime message output than horde -// QTest::newRow( "v2eventHorde" ) << Kolab::KolabV2 << Kolab::EventObject << getPath("v2/event/horde.ics") << getPath("v2/event/horde.ics.mime"); - QTest::newRow( "v2todoSimple" ) << Kolab::KolabV2 << Kolab::TodoObject << getPath("v2/task/simple.ics") << getPath("v2/task/simple.ics.mime"); - QTest::newRow( "v2todoComplex" ) << Kolab::KolabV2 << Kolab::TodoObject << getPath("v2/task/complex.ics") << getPath("v2/task/complex.ics.mime"); - QTest::newRow( "v2todoPrio1" ) << Kolab::KolabV2 << Kolab::TodoObject << getPath("v2/task/prioritytest1.ics") << getPath("v2/task/prioritytest1.ics.mime"); - QTest::newRow( "v2todoPrio2" ) << Kolab::KolabV2 << Kolab::TodoObject << getPath("v2/task/prioritytest2.ics") << getPath("v2/task/prioritytest2.ics.mime"); - QTest::newRow( "v2journalSimple" ) << Kolab::KolabV2 << Kolab::JournalObject << getPath("v2/journal/simple.ics") << getPath("v2/journal/simple.ics.mime"); - QTest::newRow( "v2journalComplex" ) << Kolab::KolabV2 << Kolab::JournalObject << getPath("v2/journal/complex.ics") << getPath("v2/journal/complex.ics.mime"); - - QTest::newRow( "v3eventSimple" ) << Kolab::KolabV3 << Kolab::EventObject << getPath("v3/event/simple.ics") << getPath("v3/event/simple.ics.mime"); - QTest::newRow( "v3eventComplex" ) << Kolab::KolabV3 << Kolab::EventObject << getPath("v3/event/complex.ics") << getPath("v3/event/complex.ics.mime"); - QTest::newRow( "v3todoSimple" ) << Kolab::KolabV3 << Kolab::TodoObject << getPath("v3/task/simple.ics") << getPath("v3/task/simple.ics.mime"); - QTest::newRow( "v3todoComplex" ) << Kolab::KolabV3 << Kolab::TodoObject << getPath("v3/task/complex.ics") << getPath("v3/task/complex.ics.mime"); - QTest::newRow( "v3journalSimple" ) << Kolab::KolabV3 << Kolab::JournalObject << getPath("v3/journal/simple.ics") << getPath("v3/journal/simple.ics.mime"); - QTest::newRow( "v3journalComplex" ) << Kolab::KolabV3 << Kolab::JournalObject << getPath("v3/journal/complex.ics") << getPath("v3/journal/complex.ics.mime"); - QTest::newRow( "v3utf8quotedPrintable" ) << Kolab::KolabV3 << Kolab::EventObject << getPath("v3/event/utf8.ics") << getPath("v3/event/utf8quotedPrintable.ics.mime"); - QTest::newRow( "v3utf8base64" ) << Kolab::KolabV3 << Kolab::EventObject << getPath("v3/event/utf8.ics") << getPath("v3/event/utf8base64.ics.mime"); - QTest::newRow( "v3utf88bit" ) << Kolab::KolabV3 << Kolab::EventObject << getPath("v3/event/utf8.ics") << getPath("v3/event/utf88bit.ics.mime"); -} - - -void FormatTest::testIncidence() -{ - QFETCH( Kolab::Version, version ); - QFETCH( Kolab::ObjectType, type ); - QFETCH( QString, icalFileName ); //To compare - QFETCH( QString, mimeFileName ); //For parsing - - //Parse mime message - bool ok = false; - const KMime::Message::Ptr &msg = readMimeFile( mimeFileName, ok ); - QVERIFY(ok); - Kolab::KolabObjectReader reader; - Kolab::ObjectType t = reader.parseMimeMessage(msg); - QCOMPARE(t, type); - QCOMPARE(reader.getVersion(), version); - QCOMPARE(Kolab::ErrorHandler::instance().error(), Kolab::ErrorHandler::Debug); - - KCalCore::Incidence::Ptr convertedIncidence = reader.getIncidence(); - - //Parse ICalFile for comparison - QFile icalFile( icalFileName ); - QVERIFY( icalFile.open( QFile::ReadOnly ) ); - KCalCore::ICalFormat format; - KCalCore::Incidence::Ptr realIncidence( format.fromString( QString::fromUtf8( icalFile.readAll() ) ) ); - - // fix up the converted incidence for comparisson - normalizeIncidence(convertedIncidence); - normalizeIncidence(realIncidence); - - // recurrence objects are created on demand, but KCalCore::Incidence::operator==() doesn't take that into account - // so make sure both incidences have one - realIncidence->recurrence(); - convertedIncidence->recurrence(); - - realIncidence->setLastModified(convertedIncidence->lastModified()); - - //The following test is just for debugging and not really relevant - if ( *(realIncidence.data()) != *(convertedIncidence.data()) ) { - showDiff(format.toString( realIncidence ), format.toString( convertedIncidence )); - } - QVERIFY( *(realIncidence.data()) == *(convertedIncidence.data()) ); - - - //Write - Kolab::overrideTimestamp(Kolab::cDateTime(2012, 5, 5, 5,5,5, true)); - KMime::Message::Ptr convertedMime = Kolab::KolabObjectWriter::writeIncidence(realIncidence, version); - - if ( !compareMimeMessage( convertedMime, msg )) { - showDiff(msg->encodedContent(), convertedMime->encodedContent()); - QVERIFY( false ); - } - QCOMPARE(Kolab::ErrorHandler::instance().error(), Kolab::ErrorHandler::Debug); -} - - -enum TestMode { - ReadOnly, - ReadWrite -}; -Q_DECLARE_METATYPE(TestMode); - -void FormatTest::testContact_data() -{ - QTest::addColumn<Kolab::Version>( "version" ); - QTest::addColumn<Kolab::ObjectType>( "type" ); - QTest::addColumn<QString>( "vcardFileName" ); - QTest::addColumn<QString>( "mimeFileName" ); - QTest::addColumn<TestMode>( "mode" ); - - QTest::newRow( "v2contactSimple" ) << Kolab::KolabV2 << Kolab::ContactObject << getPath("v2/contacts/simple.vcf") << getPath("v2/contacts/simple.vcf.mime") << ReadWrite; - //FIXME Reference files needs to be adjusted due to fix in how pictures are stored -// QTest::newRow( "v2contactComplex" ) << Kolab::KolabV2 << Kolab::ContactObject << getPath("v2/contacts/complex.vcf") << getPath("v2/contacts/complex.vcf.mime") << ReadWrite; - QTest::newRow( "v2contactAddress" ) << Kolab::KolabV2 << Kolab::ContactObject << getPath("v2/contacts/address.vcf") << getPath("v2/contacts/address.vcf.mime") << ReadWrite; - QTest::newRow( "v2contactBug238996" ) << Kolab::KolabV2 << Kolab::ContactObject << getPath("v2/contacts/bug238996.vcf") << getPath("v2/contacts/bug238996.vcf.mime") << ReadWrite; - QTest::newRow( "v2contactDisplayname" ) << Kolab::KolabV2 << Kolab::ContactObject << getPath("v2/contacts/displayname.vcf") << getPath("v2/contacts/displayname.vcf.mime") << ReadWrite; - QTest::newRow( "v2contactEmails" ) << Kolab::KolabV2 << Kolab::ContactObject << getPath("v2/contacts/emails.vcf") << getPath("v2/contacts/emails.vcf.mime") << ReadWrite; - QTest::newRow( "v2contactPhonenumbers" ) << Kolab::KolabV2 << Kolab::ContactObject << getPath("v2/contacts/phonenumbers.vcf") << getPath("v2/contacts/phonenumbers.vcf.mime") << ReadWrite; - // FIXME Reference files needs to be adjusted due to fix in how pictures are stored -// QTest::newRow( "v2contactPicture" ) << Kolab::KolabV2 << Kolab::ContactObject << getPath("v2/contacts/picture.vcf") << getPath("v2/contacts/picture.vcf.mime") << ReadWrite; - //FIXME the following test fails because the vcard implementation always writes jpeg (which is lossy). The reference vcf file is therefore probably also not really useful -// QTest::newRow( "v2pictureJPGHorde" ) << Kolab::KolabV2 << Kolab::ContactObject << getPath("v2/contacts/pictureJPGHorde.vcf") << getPath("v2/contacts/pictureJPGHorde.vcf.mime"); - - QTest::newRow( "v3contactSimple" ) << Kolab::KolabV3 << Kolab::ContactObject << getPath("v3/contacts/simple.vcf") << getPath("v3/contacts/simple.vcf.mime") << ReadWrite; - QTest::newRow( "v3contactComplex" ) << Kolab::KolabV3 << Kolab::ContactObject << getPath("v3/contacts/complex.vcf") << getPath("v3/contacts/complex.vcf.mime") << ReadWrite; - QTest::newRow( "v3contactPng" ) << Kolab::KolabV3 << Kolab::ContactObject << getPath("v3/readonly/png.vcf") << getPath("v3/readonly/png.vcf.mime") << ReadOnly; -} - -bool comparePictureToReference(const QImage &picture) -{ - QImage img(getPath("picture.jpg")); - QByteArray pic; - QBuffer buffer(&pic); - buffer.open(QIODevice::WriteOnly); - img.save(&buffer, "JPEG"); - buffer.close(); - - QByteArray pic2; - QBuffer buffer2(&pic2); - buffer2.open(QIODevice::WriteOnly); - picture.save(&buffer2, "JPEG"); - buffer2.close(); - - if(pic.toBase64() != pic2.toBase64()) { - qDebug() << pic.toBase64(); - qDebug() << pic2.toBase64(); - return false; - } - return true; -} - -void FormatTest::testContact() -{ - QFETCH( Kolab::Version, version ); - QFETCH( Kolab::ObjectType, type ); - QFETCH( QString, vcardFileName ); //To compare - QFETCH( QString, mimeFileName ); //For parsing - QFETCH( TestMode, mode ); //For parsing - - //Parse mime message - bool ok = false; - const KMime::Message::Ptr &msg = readMimeFile( mimeFileName, ok ); - QVERIFY(ok); - Kolab::KolabObjectReader reader; - Kolab::ObjectType t = reader.parseMimeMessage(msg); - QCOMPARE(t, type); - QCOMPARE(reader.getVersion(), version); - QCOMPARE(Kolab::ErrorHandler::instance().error(), Kolab::ErrorHandler::Debug); - - KABC::Addressee convertedAddressee = reader.getContact(); - QVERIFY(!convertedAddressee.isEmpty()); - - //Parse vcard - QFile vcardFile( vcardFileName ); - QVERIFY( vcardFile.open( QFile::ReadOnly ) ); - KABC::VCardConverter converter; - const QByteArray &c = vcardFile.readAll(); - KABC::Addressee realAddressee = converter.parseVCard( c ); - - // fix up the converted addressee for comparisson - convertedAddressee.setName( realAddressee.name() ); // name() apparently is something strange - if (version == Kolab::KolabV2) { //No creation date in xcal - QVERIFY( !convertedAddressee.custom( "KOLAB", "CreationDate" ).isEmpty() ); - convertedAddressee.removeCustom( "KOLAB", "CreationDate" ); // that's conversion time !? - } else { - normalizeContact(convertedAddressee); - normalizeContact(realAddressee); - } - QVERIFY( normalizePhoneNumbers( convertedAddressee, realAddressee ) ); // phone number ids are random - QVERIFY( normalizeAddresses( convertedAddressee, realAddressee ) ); // same here -// QCOMPARE(realAddressee.photo().type(), convertedAddressee.photo().type()); - if (realAddressee != convertedAddressee) { - showDiff(converter.createVCard(realAddressee), converter.createVCard(convertedAddressee)); - } - QCOMPARE( realAddressee, convertedAddressee ); - - //Write - if (mode == ReadWrite) { - Kolab::overrideTimestamp(Kolab::cDateTime(2012, 5, 5, 5,5,5, true)); - const KMime::Message::Ptr &convertedMime = Kolab::KolabObjectWriter::writeContact(realAddressee, version); - - if ( !compareMimeMessage( convertedMime, msg )) { - QString expected = msg->encodedContent(); - normalizeMimemessage(expected); - QString converted = convertedMime->encodedContent(); - normalizeMimemessage(converted); - showDiff(expected, converted); - QVERIFY( false ); - } - } - QCOMPARE(Kolab::ErrorHandler::instance().error(), Kolab::ErrorHandler::Debug); -} - -void FormatTest::testDistlist_data() -{ - QTest::addColumn<Kolab::Version>( "version" ); - QTest::addColumn<Kolab::ObjectType>( "type" ); - QTest::addColumn<QString>( "vcardFileName" ); - QTest::addColumn<QString>( "mimeFileName" ); - - QTest::newRow( "v3distlistSimple" ) << Kolab::KolabV3 << Kolab::DistlistObject << getPath("v3/contacts/distlist.vcf") << getPath("v3/contacts/distlist.vcf.mime"); -} - -void FormatTest::testDistlist() -{ - QFETCH( Kolab::Version, version ); - QFETCH( Kolab::ObjectType, type ); - QFETCH( QString, vcardFileName ); //To compare - QFETCH( QString, mimeFileName ); //For parsing - - //Parse mime message - bool ok = false; - const KMime::Message::Ptr &msg = readMimeFile( mimeFileName, ok ); - QVERIFY(ok); - Kolab::KolabObjectReader reader; - Kolab::ObjectType t = reader.parseMimeMessage(msg); - QCOMPARE(t, type); - QCOMPARE(reader.getVersion(), version); - QCOMPARE(Kolab::ErrorHandler::instance().error(), Kolab::ErrorHandler::Debug); - - KABC::ContactGroup convertedAddressee = reader.getDistlist(); - - //Parse vcard - QFile vcardFile( vcardFileName ); - QVERIFY( vcardFile.open( QFile::ReadOnly ) ); - KABC::VCardConverter converter; - QByteArray c = vcardFile.readAll(); - QBuffer data(&c); - data.open(QIODevice::ReadOnly); - - KABC::ContactGroup realAddressee; - KABC::ContactGroupTool::convertFromXml( &data, realAddressee ); - - { - QBuffer expected; - expected.open(QIODevice::WriteOnly); - KABC::ContactGroupTool::convertToXml(realAddressee, &expected); - - QBuffer converted; - converted.open(QIODevice::WriteOnly); - KABC::ContactGroupTool::convertToXml(convertedAddressee, &converted); - - showDiff(expected.buffer(), converted.buffer()); - } - QCOMPARE( realAddressee, convertedAddressee ); - - //Write - const KMime::Message::Ptr &convertedMime = Kolab::KolabObjectWriter::writeDistlist(realAddressee, version); - - if ( !compareMimeMessage( convertedMime, msg )) { - QString expected = msg->encodedContent(); - normalizeMimemessage(expected); - QString converted = convertedMime->encodedContent(); - normalizeMimemessage(converted); - showDiff(expected, converted); - QVERIFY( false ); - } - QCOMPARE(Kolab::ErrorHandler::instance().error(), Kolab::ErrorHandler::Debug); -} - -void FormatTest::testNote_data() -{ - QTest::addColumn<Kolab::Version>( "version" ); - QTest::addColumn<Kolab::ObjectType>( "type" ); - QTest::addColumn<QString>( "noteFileName" ); - QTest::addColumn<QString>( "mimeFileName" ); - - QTest::newRow( "v3noteSimple" ) << Kolab::KolabV3 << Kolab::NoteObject << getPath("v3/note/note.mime") << getPath("v3/note/note.mime.mime"); -} - - -void FormatTest::testNote() -{ - QFETCH( Kolab::Version, version ); - QFETCH( Kolab::ObjectType, type ); - QFETCH( QString, noteFileName ); //To compare - QFETCH( QString, mimeFileName ); //For parsing - - //Parse mime message - bool ok = false; - const KMime::Message::Ptr &msg = readMimeFile( mimeFileName, ok ); - QVERIFY(ok); - Kolab::KolabObjectReader reader; - Kolab::ObjectType t = reader.parseMimeMessage(msg); - QCOMPARE(t, type); - QCOMPARE(reader.getVersion(), version); - QCOMPARE(Kolab::ErrorHandler::instance().error(), Kolab::ErrorHandler::Debug); - - KMime::Message::Ptr convertedNote = reader.getNote(); - QVERIFY(convertedNote.get()); - - //Parse note - const KMime::Message::Ptr &realNote = readMimeFile( noteFileName, ok ); - QVERIFY(ok); - QVERIFY(realNote.get()); - - QString expected = realNote->encodedContent(); - normalizeMimemessage(expected); - QString converted = convertedNote->encodedContent(); - normalizeMimemessage(converted); - showDiff(expected, converted); - - //Write - const KMime::Message::Ptr &convertedMime = Kolab::KolabObjectWriter::writeNote(realNote, version); - QVERIFY(convertedMime.get()); - QVERIFY(msg.get()); - - QString expected2 = msg->encodedContent(); - normalizeMimemessage(expected2); - QString converted2 = convertedMime->encodedContent(); - normalizeMimemessage(converted2); - showDiff(expected2, converted2); - - QCOMPARE(Kolab::ErrorHandler::instance().error(), Kolab::ErrorHandler::Debug); -} - - -//This function exists only to generate the reference files, it's not a real test. -void FormatTest::generateMimefile() -{ -// QFile icalFile( getPath("v3/journal/complex.ics") ); -// QVERIFY( icalFile.open( QFile::ReadOnly ) ); -// KCalCore::ICalFormat format; -// const KCalCore::Incidence::Ptr realIncidence( format.fromString( QString::fromUtf8( icalFile.readAll() ) ) ); -// -// QString result; -// QTextStream s(&result); -// Kolab::overrideTimestamp(Kolab::cDateTime(2012, 5, 5, 5,5,5, true)); -// Kolab::KolabObjectWriter::writeIncidence(realIncidence, Kolab::KolabV3)->toStream(s); - -// QFile vcardFile( getPath("v3/contacts/complex.vcf") ); -// QVERIFY( vcardFile.open( QFile::ReadOnly ) ); -// KABC::VCardConverter converter; -// const KABC::Addressee realAddressee = converter.parseVCard( vcardFile.readAll() ); -// -// kDebug() << realAddressee.photo().data(); -// -// QString result; -// QTextStream s(&result); -// Kolab::overrideTimestamp(Kolab::cDateTime(2012, 5, 5, 5,5,5, true)); -// Kolab::KolabObjectWriter::writeContact(realAddressee, Kolab::KolabV3)->toStream(s); - -// kDebug() << result; -} - -void FormatTest::generateVCard() -{ -// bool ok = false; -// const KMime::Message::Ptr &msg = readMimeFile( QString::fromLatin1("../")+getPath("v2/contacts/pictureJPGHorde.vcf.mime"), ok ); -// qDebug() << msg->encodedContent(); -// Kolab::KolabObjectReader reader; -// Kolab::ObjectType t = reader.parseMimeMessage(msg); -// -// KABC::Addressee convertedAddressee = reader.getContact(); -// KABC::VCardConverter converter; -// qDebug() << converter.createVCard(convertedAddressee); - -// bool ok = false; -// const KMime::Message::Ptr &msg = readMimeFile( getPath("v3/contacts/distlist.vcf.mime"), ok ); -// qDebug() << msg->encodedContent(); -// Kolab::KolabObjectReader reader; -// Kolab::ObjectType t = reader.parseMimeMessage(msg); -// -// KABC::ContactGroup convertedAddressee = reader.getDistlist(); -// QBuffer buf; -// buf.open(QIODevice::WriteOnly); -// KABC::ContactGroupTool::convertToXml(convertedAddressee, &buf); -// qDebug() << buf.buffer(); -} - -//Pseudo test to show that JPG is always lossy, even with quality set to 100 -void FormatTest::proveJPGisLossy() -{ -// QImage img(getPath("picture.jpg")); -// QByteArray pic; -// QBuffer buffer(&pic); -// buffer.open(QIODevice::WriteOnly); -// img.save(&buffer, "JPEG"); -// buffer.close(); -// qDebug() << pic.toBase64(); -// -// QImage img2; -// QByteArray pic2; -// QBuffer buffer2(&pic2); -// img2.loadFromData(pic); -// img2.save(&buffer2, "JPEG"); -// buffer2.close(); -// qDebug() << pic2.toBase64(); - -} - -QTEST_MAIN( FormatTest ) - -#include "formattest.moc"
View file
libkolab-2.0.tar.gz/tests/formattest.h
Deleted
@@ -1,73 +0,0 @@ -/* - * Copyright (C) 2012 Christian Mollekopf <mollekopf@kolabsys.com> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - - -#ifndef FORMATTEST_H -#define FORMATTEST_H -#include <QObject> - -/** - * Test complete serialization from mime message to KCalCore/KABC containers. - * - * The .ics .vcf files serve as reference, under the assumption that the iCal/vCard implementations don't have bugs. - * - * The .ics.mime/.vcf.mime messages are first used to test parsing, and then to compare the result after serialization. - * The mime files are of course just a snapshot of how it is thought that the result should be. - * The files may have bugs themselves and will need to be updated to reflect future changes. - * - * kompare (the kde diff tool) is launched if a test fails to show you the difference between expected and actual conversion. - * Comment the code if you don't want it. - * - * Note that some parts of the mime message are not compared, but show up in kompare as difference: - * * Date-Header - * * Content-Type-Header - * * next-part markers - * * Content-ID Header - * - * These are safe to be ignored as they are randomly generated. - * - * To generate the reference files, you can write the vcf/ics by hand and generate the mime message from that one (using the generateMimefile() function). - * You may need to sort some things manually (addresses/phonenumbers), and generally check manually if everything is as it should be. - * The test will then remain to ensure the same for future versions. - * - */ -class FormatTest: public QObject -{ - Q_OBJECT -private slots: - - void initTestCase(); - - void testIncidence_data(); - void testIncidence(); - - void testContact_data(); - void testContact(); - - void testDistlist_data(); - void testDistlist(); - - void testNote_data(); - void testNote(); - - //Some pseudo tests and helper functions - void generateMimefile(); - void generateVCard(); - void proveJPGisLossy(); -}; - -#endif // FORMATTEST_H
View file
libkolab-2.0.tar.gz/tests/freebusytest.cpp
Deleted
@@ -1,168 +0,0 @@ -/* - * Copyright (C) 2012 Christian Mollekopf <mollekopf@kolabsys.com> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - - -#include "freebusytest.h" -#include "testutils.h" -#include "testhelpers.h" - -#include <QTest> -#include "freebusy/freebusy.h" -#include <kolabfreebusy.h> - -#include <iostream> - - -void FreebusyTest::testFB_data() -{ - QTest::addColumn<Kolab::cDateTime>( "start" ); - QTest::addColumn<Kolab::cDateTime>( "end" ); - QTest::addColumn< std::vector<Kolab::Event> >( "events" ); - QTest::addColumn< std::vector<Kolab::FreebusyPeriod> >( "output" ); - - - //UTC check - { - Kolab::Period p1(Kolab::cDateTime(2011,10,6,12,1,1,true), Kolab::cDateTime(2011,10,7,12,1,1,true)); - Kolab::Period p2(Kolab::cDateTime(2011,10,8,12,1,1,true), Kolab::cDateTime(2011,10,9,12,1,1,true)); - Kolab::Period p3(Kolab::cDateTime(2011,10,10,12,1,1,true), Kolab::cDateTime(2011,10,11,12,1,1,true)); - - std::vector<Kolab::Event> events; - events.push_back(createEvent(p1.start, p1.end)); - events.push_back(createEvent(p2.start, p2.end)); - events.push_back(createEvent(p3.start, p3.end)); - - Kolab::FreebusyPeriod period1; - period1.setType(Kolab::FreebusyPeriod::Busy); - period1.setEvent(events.at(0).uid(), events.at(0).summary(), events.at(0).location()); - period1.setPeriods(std::vector<Kolab::Period>() << p1); - - Kolab::FreebusyPeriod period2; - period2.setType(Kolab::FreebusyPeriod::Busy); - period2.setEvent(events.at(1).uid(), events.at(1).summary(), events.at(1).location()); - period2.setPeriods(std::vector<Kolab::Period>() << p2); - - Kolab::FreebusyPeriod period3; - period3.setType(Kolab::FreebusyPeriod::Busy); - period3.setEvent(events.at(2).uid(), events.at(2).summary(), events.at(2).location()); - period3.setPeriods(std::vector<Kolab::Period>() << p3); - - { - std::vector<Kolab::FreebusyPeriod> output; - output.push_back(period1); - output.push_back(period2); - output.push_back(period3); - - QTest::newRow( "simple utc" ) << Kolab::cDateTime(2010, 1, 1,1,1,1,true) << Kolab::cDateTime(2012, 1, 1,1,1,1,true) << events << output; - } - - { - std::vector<Kolab::FreebusyPeriod> output; - output.push_back(period2); - output.push_back(period3); - - QTest::newRow( "limit utc below" ) << Kolab::cDateTime(2011,10,8,12,1,1,true) << Kolab::cDateTime(2012, 1, 1,1,1,1,true) << events << output; - } - { - std::vector<Kolab::FreebusyPeriod> output; - output.push_back(period1); - output.push_back(period2); - - QTest::newRow( "limit utc above" ) << Kolab::cDateTime(2010, 1, 1,1,1,1,true) << Kolab::cDateTime(2011,10,9,12,1,1,true) << events << output; - } - } - { - Kolab::Event event; - event.setUid(QUuid::createUuid().toString().toStdString()); - event.setStart(Kolab::cDateTime(2011,1,1,0,0,0,true)); - event.setEnd(Kolab::cDateTime(2011,1,1,1,0,0,true)); - Kolab::RecurrenceRule rrule; - rrule.setFrequency(Kolab::RecurrenceRule::Daily); - rrule.setInterval(1); - rrule.setCount(2); - event.setRecurrenceRule(rrule); - - std::vector<Kolab::Event> events; - events.push_back(event); - - std::vector<Kolab::FreebusyPeriod> output; - Kolab::FreebusyPeriod period1; - period1.setType(Kolab::FreebusyPeriod::Busy); - period1.setEvent(event.uid(), event.summary(), event.location()); - period1.setPeriods(std::vector<Kolab::Period>() << Kolab::Period(Kolab::cDateTime(2011,1,1,0,0,0,true), Kolab::cDateTime(2011,1,1,1,0,0,true)) - << Kolab::Period(Kolab::cDateTime(2011,1,2,0,0,0,true), Kolab::cDateTime(2011,1,2,1,0,0,true)) - ); - output.push_back(period1); - - QTest::newRow( "fullday recurrence" ) << Kolab::cDateTime(2010, 1, 1,1,1,1,true) << Kolab::cDateTime(2012,10,9,12,1,1,true) << events << output; - } -} - - -void FreebusyTest::testFB() -{ - QFETCH(Kolab::cDateTime, start); - QFETCH(Kolab::cDateTime, end); - QFETCH(std::vector<Kolab::Event>, events); - QFETCH(std::vector<Kolab::FreebusyPeriod>, output); - - Kolab::Freebusy fb = Kolab::FreebusyUtils::generateFreeBusy(events, start, end); - - QCOMPARE((int)fb.periods().size(), (int)output.size()); - for (std::size_t i = 0; i<output.size(); i++) { - std::cout << i; - QCOMPARE(fb.periods().at(i), output.at(i)); - } - - std::cout << Kolab::FreebusyUtils::toIFB(fb); -} - -// void FreebusyTest::testHonorTimeFrame() -// { -// -// Kolab::Period p1(Kolab::cDateTime(2011,10,6,12,1,1,true), Kolab::cDateTime(2011,10,8,12,1,1,true)); -// Kolab::Period p2(Kolab::cDateTime(2011,10,7,12,1,1,true), Kolab::cDateTime(2011,10,10,12,1,1,true)); -// Kolab::Period p3(Kolab::cDateTime(2011,10,9,12,1,1,true), Kolab::cDateTime(2011,10,11,12,1,1,true)); -// -// std::vector<Kolab::Event> events; -// events.push_back(createEvent(p1.start, p1.end)); -// events.push_back(createEvent(p2.start, p2.end)); -// events.push_back(createEvent(p3.start, p3.end)); -// -// Kolab::FreebusyPeriod period1; -// period1.setType(Kolab::FreebusyPeriod::Busy); -// period1.setPeriods(std::vector<Kolab::Period>() << p1); -// -// Kolab::FreebusyPeriod period2; -// period2.setType(Kolab::FreebusyPeriod::Busy); -// period2.setPeriods(std::vector<Kolab::Period>() << p2); -// -// Kolab::FreebusyPeriod period3; -// period3.setType(Kolab::FreebusyPeriod::Busy); -// period3.setPeriods(std::vector<Kolab::Period>() << p3); -// -// -// Kolab::Freebusy fb = Kolab::FreebusyUtils::generateFreeBusy(events, Kolab::cDateTime(2010, 1, 1,1,1,1,true), Kolab::cDateTime(2012, 1, 1,1,1,1,true)); -// QCOMPARE((int)fb.periods().size(), 3); -// QCOMPARE(fb.periods().at(0), period1); -// QCOMPARE(fb.periods().at(1), period2); -// QCOMPARE(fb.periods().at(2), period3); -// } - -QTEST_MAIN( FreebusyTest ) - -#include "freebusytest.moc" \ No newline at end of file
View file
libkolab-2.0.tar.gz/tests/freebusytest.h
Deleted
@@ -1,32 +0,0 @@ -/* - * Copyright (C) 2012 Christian Mollekopf <mollekopf@kolabsys.com> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - - -#ifndef FREEBUSYTEST_H -#define FREEBUSYTEST_H -#include <QObject> - -class FreebusyTest: public QObject -{ - Q_OBJECT -private slots: - - void testFB_data(); - void testFB(); -}; - -#endif // FREEBUSYTEST_H
View file
libkolab-2.0.tar.gz/tests/icalendartest.cpp
Deleted
@@ -1,152 +0,0 @@ -/* - * Copyright (C) 2012 Christian Mollekopf <mollekopf@kolabsys.com> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - - -#include "icalendartest.h" - -#include <QTest> -#include <kolabevent.h> - -#include "icalendar/icalendar.h" - -#include "testhelpers.h" -#include "testutils.h" -#include <kolabformat/kolabobject.h> - -void ICalendarTest::testFromICalEvent() -{ - std::vector<Kolab::Event> events; - Kolab::Event ev1; - ev1.setStart(Kolab::cDateTime(2011,10,10,12,1,1,true)); - ev1.setEnd(Kolab::cDateTime(2011,10,11,12,1,1,true)); - events.push_back(ev1); - const std::vector<Kolab::Event> &result = Kolab::fromICalEvents(Kolab::toICal(events)); - qDebug() << QString::fromStdString(Kolab::toICal(result)); -} - -void ICalendarTest::testFromICalEventWithExceptions() -{ - QFile icalFile( getPath("v3/event/exceptions.ics") ); - QVERIFY( icalFile.open( QFile::ReadOnly ) ); - std::vector<Kolab::Event> events = Kolab::fromICalEvents(icalFile.readAll().constData()); - QCOMPARE((int)events.size(), 1); - Kolab::Event out = events.at(0); - QCOMPARE((int)out.exceptions().size(), 2); -} - -void ICalendarTest::testFromICalEventErrorsWithSameID() -{ - /* This is not a really usecase, it should make sure, - * that the underlying KCalCore strips out events with same uid/or recurrenceID. - * 2015/02/18: KCaclCore is only returns one event with one exception for the icalFile - * testdata/v3/event/errorswithsameid.ics - */ - QFile icalFile( getPath("v3/event/errorswithsameid.ics") ); - QVERIFY( icalFile.open( QFile::ReadOnly ) ); - std::vector<Kolab::Event> events = Kolab::fromICalEvents(icalFile.readAll().constData()); - QCOMPARE((int)events.size(), 1); - Kolab::Event out = events.at(0); - QCOMPARE((int)out.exceptions().size(), 1); -} - -void ICalendarTest::testReadWriteForEventWithExceptions() -{ - std::vector<Kolab::Event> events; - Kolab::Event ev1; - ev1.setUid("uid"); - ev1.setStart(Kolab::cDateTime(2011,10,10,12,1,1,true)); - ev1.setEnd(Kolab::cDateTime(2011,10,11,12,1,1,true)); - std::vector<Kolab::Event> exceptions; - Kolab::Event ex1; - ex1.setUid(ev1.uid()); - ex1.setRecurrenceID(Kolab::cDateTime(2011,10,11,12,1,1,true), true); - exceptions.push_back(ex1); - ev1.setExceptions(exceptions); - Kolab::RecurrenceRule rrule; - rrule.setInterval(1); - rrule.setFrequency(Kolab::RecurrenceRule::Daily); - ev1.setRecurrenceRule(rrule); - events.push_back(ev1); - const std::vector<Kolab::Event> &result = Kolab::fromICalEvents(Kolab::toICal(events)); - Kolab::Event out = result.at(0); - QCOMPARE((int)result.size(), 1); - QCOMPARE((int)out.exceptions().size(), 1); - QCOMPARE(out.exceptions().at(0).recurrenceID(), ex1.recurrenceID()); - QCOMPARE(out.exceptions().at(0).thisAndFuture(), true); -} - -void ICalendarTest::testToICal() -{ - std::vector<Kolab::Event> events; - Kolab::Event ev1; - ev1.setStart(Kolab::cDateTime(2011,10,10,12,1,1,true)); - ev1.setEnd(Kolab::cDateTime(2011,10,11,12,1,1,true)); - events.push_back(ev1); - events.push_back(ev1); - qDebug() << QString::fromStdString(Kolab::toICal(events)); -} - -void ICalendarTest::testToITip() -{ - Kolab::ITipHandler handler; - Kolab::Event ev1; - ev1.setStart(Kolab::cDateTime(2011,10,10,12,1,1,true)); - ev1.setEnd(Kolab::cDateTime(2011,10,11,12,1,1,true)); - ev1.setLastModified(Kolab::cDateTime(2011,10,11,12,1,2,true)); - ev1.setCreated(Kolab::cDateTime(2011,10,11,12,1,3,true)); - - qDebug() << QString::fromStdString(handler.toITip(ev1, Kolab::ITipHandler::iTIPRequest)); - -} - -void ICalendarTest::testToIMip() -{ - Kolab::ITipHandler handler; - Kolab::Event ev1; - ev1.setStart(Kolab::cDateTime("Europe/Zurich",2011,10,10,12,1,1)); - ev1.setEnd(Kolab::cDateTime("Europe/Zurich",2012,5,5,3,4,4)); - ev1.setLastModified(Kolab::cDateTime(2011,10,11,12,1,2,true)); - ev1.setCreated(Kolab::cDateTime(2011,10,11,12,1,3,true)); - - std::vector <Kolab::Attendee > attendees; - attendees.push_back(Kolab::Attendee(Kolab::ContactReference("email1@test.org", "name1", "uid1"))); - attendees.push_back(Kolab::Attendee (Kolab::ContactReference("email2@test.org", "name2", "uid2"))); - ev1.setAttendees(attendees); - - ev1.setOrganizer(Kolab::ContactReference("organizer@test.org", "organizer", "uid3")); - ev1.setSummary("summary"); - - const std::string mimeResult = handler.toIMip(ev1, Kolab::ITipHandler::iTIPRequest, "test@test.com"); - qDebug() << QString::fromStdString(mimeResult); - qDebug() << QString::fromStdString(handler.toIMip(ev1, Kolab::ITipHandler::iTIPReply, "test@test.com")); - - const std::vector<Kolab::Event> &eventResult = handler.fromIMip(mimeResult); - -// qDebug() << QString::fromStdString(Kolab::toICal(eventResult)); - - QCOMPARE((int)eventResult.size(), 1); - QEXPECT_FAIL("", "to imip converts dates to utc", Continue); - QCOMPARE(eventResult.front().start(), ev1.start()); - QEXPECT_FAIL("", "to imip converts dates to utc", Continue); - QCOMPARE(eventResult.front().end(), ev1.end()); -} - - - -QTEST_MAIN( ICalendarTest ) - -#include "icalendartest.moc"
View file
libkolab-2.0.tar.gz/tests/icalendartest.h
Deleted
@@ -1,38 +0,0 @@ -/* - * Copyright (C) 2012 Christian Mollekopf <mollekopf@kolabsys.com> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef ICALENDARTEST_H -#define ICALENDARTEST_H -#include <QObject> - -class ICalendarTest: public QObject -{ - Q_OBJECT -private slots: - -// void testEventConflict_data(); - void testToICal(); - void testFromICalEvent(); - void testFromICalEventWithExceptions(); - void testReadWriteForEventWithExceptions(); - void testFromICalEventErrorsWithSameID(); - - void testToITip(); - void testToIMip(); -}; - -#endif // ICALENDARTEST_H
View file
libkolab-2.0.tar.gz/tests/kolabobjecttest.cpp
Deleted
@@ -1,174 +0,0 @@ -/* - * Copyright (C) 2012 Christian Mollekopf <mollekopf@kolabsys.com> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include "kolabobjecttest.h" - -#include <QTest> - -#include "kolabformat/kolabobject.h" -#include <kdebug.h> -#include <kolabformat/errorhandler.h> - -void KolabObjectTest::preserveLatin1() -{ - KCalCore::Event::Ptr event(new KCalCore::Event()); - QString summary(QLatin1String("äöü%@$£é¤¼²°")); - event->setSummary(summary); - QCOMPARE(event->summary(), summary); - //std::cout << event->summary().toStdString() << std::endl; - KMime::Message::Ptr msg = Kolab::KolabObjectWriter::writeEvent(event); -// kDebug() << msg->encodedContent(); - KCalCore::Event::Ptr readEvent = Kolab::KolabObjectReader(msg).getEvent(); - QVERIFY(readEvent); -// std::cout << readEvent->summary().toStdString() << std::endl; - QCOMPARE(readEvent->summary(), summary); -} - -void KolabObjectTest::preserveUnicode() -{ - KCalCore::Event::Ptr event(new KCalCore::Event()); - QString summary(QString::fromUtf8("€Š�ـأبـ☺")); - event->setSummary(summary); - QCOMPARE(event->summary(), summary); -// std::cout << event->summary().toStdString() << std::endl; - KMime::Message::Ptr msg = Kolab::KolabObjectWriter::writeEvent(event); -// kDebug() << msg->encodedContent(); - KCalCore::Event::Ptr readEvent = Kolab::KolabObjectReader(msg).getEvent(); - QVERIFY(readEvent); -// std::cout << readEvent->summary().toStdString() << std::endl; - QCOMPARE(readEvent->summary(), summary); -} - -void KolabObjectTest::dontCrashWithEmptyOrganizer() -{ - KCalCore::Event::Ptr event(new KCalCore::Event()); - event->setOrganizer(KCalCore::Person::Ptr()); - event->setDtStart(KDateTime(QDate(2012,11,11))); - Kolab::KolabObjectWriter::writeEvent(event, Kolab::KolabV2); - QCOMPARE(Kolab::ErrorHandler::instance().error(), Kolab::ErrorHandler::Debug); - Kolab::KolabObjectWriter::writeEvent(event); - qDebug() << Kolab::ErrorHandler::instance().error(); - QCOMPARE(Kolab::ErrorHandler::instance().error(), Kolab::ErrorHandler::Debug); -} - - -void KolabObjectTest::dontCrashWithEmptyIncidence() -{ - Kolab::KolabObjectWriter::writeEvent(KCalCore::Event::Ptr()); - QCOMPARE(Kolab::ErrorHandler::instance().error(), Kolab::ErrorHandler::Critical); - Kolab::KolabObjectWriter::writeTodo(KCalCore::Todo::Ptr()); - QCOMPARE(Kolab::ErrorHandler::instance().error(), Kolab::ErrorHandler::Critical); - Kolab::KolabObjectWriter::writeJournal(KCalCore::Journal::Ptr()); - QCOMPARE(Kolab::ErrorHandler::instance().error(), Kolab::ErrorHandler::Critical); - Kolab::KolabObjectWriter::writeIncidence(KCalCore::Event::Ptr()); - QCOMPARE(Kolab::ErrorHandler::instance().error(), Kolab::ErrorHandler::Critical); - Kolab::KolabObjectWriter::writeNote(KMime::Message::Ptr()); - QCOMPARE(Kolab::ErrorHandler::instance().error(), Kolab::ErrorHandler::Critical); -} - -void KolabObjectTest::parseRelationMembers() -{ - { - QString memberString("imap:///user/jan.aachen%40lhm.klab.cc/INBOX/20?message-id=%3Cf06aa3345a25005380b47547ad161d36%40lhm.klab.cc%3E&subject=Re%3A+test&date=Tue%2C+12+Aug+2014+20%3A42%3A59+%2B0200"); - Kolab::RelationMember member = Kolab::parseMemberUrl(memberString); - - QString result = Kolab::generateMemberUrl(member); - qDebug() << result; - result.replace(QLatin1String("%20"),QLatin1String("+")); - QCOMPARE(result, memberString); - } - - //user namespace by uid - { - - Kolab::RelationMember member; - member.uid = 20; - member.mailbox = QList<QByteArray>() << "INBOX"; - member.user = "john.doe@example.org"; - member.messageId = "messageid"; - member.date = "date"; - member.subject = "subject"; - QString url = Kolab::generateMemberUrl(member); - qDebug() << url; - Kolab::RelationMember result = Kolab::parseMemberUrl(url); - QCOMPARE(result.uid, member.uid); - QCOMPARE(result.mailbox, member.mailbox); - QCOMPARE(result.user, member.user); - QCOMPARE(result.messageId, member.messageId); - QCOMPARE(result.date, member.date); - QCOMPARE(result.subject, member.subject); - } - - //shared namespace by uid - { - - Kolab::RelationMember member; - member.uid = 20; - member.mailbox = QList<QByteArray>() << "foo" << "bar"; - member.messageId = "messageid"; - member.date = "date"; - member.subject = "subject"; - QString url = Kolab::generateMemberUrl(member); - qDebug() << url; - Kolab::RelationMember result = Kolab::parseMemberUrl(url); - QCOMPARE(result.uid, member.uid); - QCOMPARE(result.mailbox, member.mailbox); - QVERIFY(result.user.isEmpty()); - QCOMPARE(result.messageId, member.messageId); - QCOMPARE(result.date, member.date); - QCOMPARE(result.subject, member.subject); - } - - //by uuid/gid - { - - Kolab::RelationMember member; - member.gid = "fooobar"; - QString url = Kolab::generateMemberUrl(member); - qDebug() << url; - Kolab::RelationMember result = Kolab::parseMemberUrl(url); - QCOMPARE(result.gid, member.gid); - } - - // chars to en/decode - { - - Kolab::RelationMember member; - member.uid = 20; - member.mailbox = QList<QByteArray>() << "spaces in folders" << "+^,:@"; - member.user = "john.doe:^@example.org"; - member.messageId = "messageid+^,:@"; - member.date = "date+^,:@"; - member.subject = "subject+^,:@"; - - QString url = Kolab::generateMemberUrl(member); - qDebug() << url; - Kolab::RelationMember result = Kolab::parseMemberUrl(url); - QCOMPARE(result.uid, member.uid); - QCOMPARE(result.mailbox, member.mailbox); - QCOMPARE(result.user, member.user); - QCOMPARE(result.messageId, member.messageId); - QCOMPARE(result.date, member.date); - QCOMPARE(result.subject, member.subject); - } -} - - - -QTEST_MAIN( KolabObjectTest ) - -#include "kolabobjecttest.moc"
View file
libkolab-2.0.tar.gz/tests/kolabobjecttest.h
Deleted
@@ -1,33 +0,0 @@ -/* - * Copyright (C) 2012 Christian Mollekopf <mollekopf@kolabsys.com> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef KOLABOBJECTTEST_H -#define KOLABOBJECTTEST_H -#include <QObject> - -class KolabObjectTest: public QObject -{ - Q_OBJECT -private slots: - void preserveLatin1(); - void preserveUnicode(); - void dontCrashWithEmptyOrganizer(); - void dontCrashWithEmptyIncidence(); - void parseRelationMembers(); -}; - -#endif // KOLABOBJECTTEST_H
View file
libkolab-2.0.tar.gz/tests/legacyformattest.cpp
Deleted
@@ -1,58 +0,0 @@ -/* - * Copyright (C) 2012 Christian Mollekopf <mollekopf@kolabsys.com> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include "legacyformattest.h" -#include "kolabformat/xmlobject.h" -#include "kolabformat/errorhandler.h" -#include "testutils.h" - -#include <QTest> -#include <fstream> -#include <sstream> - -void V2Test::testReadDistlistUID() -{ - std::ifstream t((TESTFILEDIR.toStdString()+"v2/contacts/distlistWithUID.xml").c_str()); - std::stringstream buffer; - buffer << t.rdbuf(); - - Kolab::XMLObject xo; - const Kolab::DistList distlist = xo.readDistlist(buffer.str(), Kolab::KolabV2); - foreach (const Kolab::ContactReference &contact, distlist.members()) { - QVERIFY(!contact.uid().empty()); - } - QVERIFY(!Kolab::ErrorHandler::errorOccured()); -} - -void V2Test::testWriteDistlistUID() -{ - Kolab::DistList distlist; - distlist.setUid("uid"); - distlist.setName("name"); - std::vector<Kolab::ContactReference> members; - members.push_back(Kolab::ContactReference(Kolab::ContactReference::UidReference, "memberuid", "membername")); - distlist.setMembers(members); - - Kolab::XMLObject xo; - const std::string xml = xo.writeDistlist(distlist, Kolab::KolabV2); - QVERIFY(QString::fromStdString(xml).contains("memberuid")); - QVERIFY(!Kolab::ErrorHandler::errorOccured()); -} - -QTEST_MAIN( V2Test ) - -#include "legacyformattest.moc" \ No newline at end of file
View file
libkolab-2.0.tar.gz/tests/legacyformattest.h
Deleted
@@ -1,31 +0,0 @@ -/* - * Copyright (C) 2012 Christian Mollekopf <mollekopf@kolabsys.com> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef V2TEST_H -#define V2TEST_H - -#include <QObject> - -class V2Test: public QObject -{ - Q_OBJECT -private slots: - void testReadDistlistUID(); - void testWriteDistlistUID(); -}; - -#endif // V2TEST_H
View file
libkolab-2.0.tar.gz/tests/mimeobjecttest.cpp
Deleted
@@ -1,148 +0,0 @@ -/* - * Copyright (C) 2012 Sofia Balicka <balicka@kolabsys.com> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include <QTest> -#include "mimeobjecttest.h" -#include "kolabformat/kolabobject.h" -#include "testutils.h" -#include "kolabformat/mimeobject.h" -#include <fstream> -#include <sstream> -#include <QString> -#include <ksystemtimezone.h> - -void MIMEObjectTest::initTestCase() -{ - QVERIFY2(KSystemTimeZones::isTimeZoneDaemonAvailable(), "Timezone support is required for this test. Either use libcalendaring or make sure KTimeZoned is available"); -} - -void MIMEObjectTest::testEvent(){ - - Kolab::MIMEObject mimeobject; - - std::ifstream t((TESTFILEDIR.toStdString()+"v3/event/simple.ics.mime").c_str()); - std::stringstream buffer; - buffer << t.rdbuf(); - - Kolab::Event event = mimeobject.readEvent(buffer.str()); - - std::string message = mimeobject.writeEvent(event, Kolab::KolabV3); - - QString qMessage = QString::fromStdString(message); - QString input = QString::fromStdString(buffer.str()); - - normalizeMimemessage(qMessage); - normalizeMimemessage(input); - - QCOMPARE(input.simplified(), qMessage.simplified()); -} -/* -void MIMEObjectTest::testTodo(){ - -} -*/ - -void MIMEObjectTest::testJournal(){ - - Kolab::MIMEObject mimeobject; - - std::ifstream t((TESTFILEDIR.toStdString()+"v3/journal/simple.ics.mime").c_str()); - std::stringstream buffer; - buffer << t.rdbuf(); - - Kolab::Journal journal = mimeobject.readJournal(buffer.str()); - - std::string message = mimeobject.writeJournal(journal, Kolab::KolabV3); - - QString qMessage = QString::fromStdString(message); - QString input = QString::fromStdString(buffer.str()); - - normalizeMimemessage(qMessage); - normalizeMimemessage(input); - - QCOMPARE(input.simplified(), qMessage.simplified()); - -} - -void MIMEObjectTest::testNote(){ - - Kolab::MIMEObject mimeobject; - - std::ifstream t((TESTFILEDIR.toStdString()+"v3/note/note.mime.mime").c_str()); - std::stringstream buffer; - buffer << t.rdbuf(); - - Kolab::Note note = mimeobject.readNote(buffer.str()); - - std::string message = mimeobject.writeNote(note, Kolab::KolabV3); - - QString qMessage = QString::fromStdString(message); - QString input = QString::fromStdString(buffer.str()); - - normalizeMimemessage(qMessage); - normalizeMimemessage(input); - - QCOMPARE(input.simplified(), qMessage.simplified()); - -} - -void MIMEObjectTest::testContact(){ - - Kolab::MIMEObject mimeobject; - - std::ifstream t((TESTFILEDIR.toStdString()+"v3/contacts/simple.vcf.mime").c_str()); - std::stringstream buffer; - buffer << t.rdbuf(); - - Kolab::Contact contact = mimeobject.readContact(buffer.str()); - - std::string message = mimeobject.writeContact(contact, Kolab::KolabV3); - - QString qMessage = QString::fromStdString(message); - QString input = QString::fromStdString(buffer.str()); - - normalizeMimemessage(qMessage); - normalizeMimemessage(input); - - QCOMPARE(input.simplified(), qMessage.simplified()); - -} - -void MIMEObjectTest::testDistlist(){ - - Kolab::MIMEObject mimeobject; - - std::ifstream t((TESTFILEDIR.toStdString()+"v3/contacts/distlist.vcf.mime").c_str()); - std::stringstream buffer; - buffer << t.rdbuf(); - - Kolab::DistList distlist = mimeobject.readDistlist(buffer.str()); - - std::string message = mimeobject.writeDistlist(distlist, Kolab::KolabV3); - - QString qMessage = QString::fromStdString(message); - QString input = QString::fromStdString(buffer.str()); - - normalizeMimemessage(qMessage); - normalizeMimemessage(input); - - QCOMPARE(input.simplified(), qMessage.simplified()); - -} -QTEST_MAIN( MIMEObjectTest ) - -#include "mimeobjecttest.moc"
View file
libkolab-2.0.tar.gz/tests/mimeobjecttest.h
Deleted
@@ -1,35 +0,0 @@ -/* - * Copyright (C) 2012 Sofia Balicka <balicka@kolabsys.com> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef MIMEOBJECTTEST_H -#define MIMEOBJECTTEST_H -#include <QObject> - -class MIMEObjectTest: public QObject -{ - Q_OBJECT - -private slots: - void initTestCase(); - void testEvent(); - void testJournal(); - void testNote(); - void testContact(); - void testDistlist(); -}; -#endif // MIMEOBJECTTEST_H -
View file
libkolab-2.0.tar.gz/tests/upgradetest.cpp
Deleted
@@ -1,188 +0,0 @@ -/* - * Copyright (C) 2012 Christian Mollekopf <mollekopf@kolabsys.com> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - - -#include "upgradetest.h" - -#include <QTest> -#include <kolabcontainers.h> -#include <kolabformat.h> -#include <kolabformat/errorhandler.h> - -#include "testutils.h" -#include "kolabformat/kolabobject.h" -#include <conversion/commonconversion.h> -#include <kcalcore/icalformat.h> -#include <kabc/vcardconverter.h> - -void UpgradeTest::testIncidence_data() -{ - QTest::addColumn<Kolab::ObjectType>( "type" ); - QTest::addColumn<QString>( "filename" ); - QTest::addColumn<bool>( "forceType" ); - - // QTest::newRow( "v2contactSimple" ) << Kolab::KolabV2 << Kolab::ContactObject << TESTFILEDIR+QString::fromLatin1("v2/contacts/simple.vcf") << TESTFILEDIR+QString::fromLatin1("v2/contacts/simple.vcf.mime"); - QTest::newRow( "v2eventSimple" ) << Kolab::EventObject << TESTFILEDIR+QString::fromLatin1("v2/event/simple.ics.mime") << false; - QTest::newRow( "v2eventComplex" ) << Kolab::EventObject << TESTFILEDIR+QString::fromLatin1("v2/event/complex.ics.mime") << false; - QTest::newRow( "v2eventAllday" ) << Kolab::EventObject << TESTFILEDIR+QString::fromLatin1("v2/event/allday.ics.mime") << false; - QTest::newRow( "v2eventAttachment" ) << Kolab::EventObject << TESTFILEDIR+QString::fromLatin1("v2/event/attachment.ics.mime") << false; - QTest::newRow( "v2eventHorde" ) << Kolab::EventObject << TESTFILEDIR+QString::fromLatin1("v2/event/horde.ics.mime") << false; - - //Still broken, although it seems that rather the event comparison is implemented wrong (not using equals) - QTest::newRow( "v2taskSimple" ) << Kolab::TodoObject << TESTFILEDIR+QString::fromLatin1("v2/task/simple.ics.mime") << false; - QTest::newRow( "v2taskComplex" ) << Kolab::TodoObject << TESTFILEDIR+QString::fromLatin1("v2/task/complex.ics.mime") << false; - QTest::newRow( "v2taskPrio1" ) << Kolab::TodoObject << TESTFILEDIR+QString::fromLatin1("v2/task/prioritytest1.ics.mime") << false; - QTest::newRow( "v2taskPrio2" ) << Kolab::TodoObject << TESTFILEDIR+QString::fromLatin1("v2/task/prioritytest2.ics.mime") << false; - - QTest::newRow( "v2journalSimple" ) << Kolab::JournalObject << TESTFILEDIR+QString::fromLatin1("v2/journal/simple.ics.mime") << false; - QTest::newRow( "v2journalComplex" ) << Kolab::JournalObject << TESTFILEDIR+QString::fromLatin1("v2/journal/complex.ics.mime") << false; - - QTest::newRow( "v2eventSimple_missingTypeHeader" ) << Kolab::EventObject << TESTFILEDIR+QString::fromLatin1("v2/event/simple_missingTypeHeader.ics.mime") << true; - QTest::newRow( "v2eventis8859-1" ) << Kolab::EventObject << TESTFILEDIR+QString::fromLatin1("v2/event/iso8859-1.mime") << false; - -} - -void UpgradeTest::testIncidence() -{ - QFETCH( Kolab::ObjectType, type ); - QFETCH( QString, filename ); //To compare - QFETCH( bool, forceType ); - - bool ok = false; - const KMime::Message::Ptr &msg = readMimeFile( filename, ok ); - QVERIFY(ok); - Kolab::KolabObjectReader reader; - if (forceType) { - reader.setObjectType(type); - } - Kolab::ObjectType t = reader.parseMimeMessage(msg); - QCOMPARE(t, type); - QCOMPARE(reader.getVersion(), Kolab::KolabV2); - QCOMPARE(Kolab::ErrorHandler::instance().error(), Kolab::ErrorHandler::Debug); - - - KCalCore::Incidence::Ptr v2result = reader.getIncidence(); - QVERIFY(!v2result.isNull()); - - //write KCalCore V3 - KMime::Message::Ptr v3message = Kolab::KolabObjectWriter::writeIncidence(v2result, Kolab::KolabV3); - QVERIFY(Kolab::error() == Kolab::NoError); -// kDebug() << v3message->encodedContent(); - //load KCalCore V3 - Kolab::KolabObjectReader reader2; - QCOMPARE(reader2.parseMimeMessage(v3message), type); - KCalCore::Incidence::Ptr v3result = reader2.getIncidence(); - QVERIFY(!v3result.isNull()); - normalizeIncidence(v2result); - //We have to override the last modified time with a specific value, so we normalize the input to the same - normalizeIncidence(v3result); - kDebug() <<"--------------------------------------------------------"; - KCalCore::ICalFormat format; - const QString v2 = format.toString( v2result ); - const QString v3 = format.toString( v3result ); - if ( *v2result != *v3result ) { - showDiff(v2, v3); -// qDebug() << "V2: " << v2; -// qDebug() << "V3: " << v3; - } - QVERIFY(!v2.isEmpty()); - QVERIFY(!v3.isEmpty()); - QCOMPARE(v2, v3); - kDebug() <<"--------------------------------------------------------"; - -// if (v2result->type() == KCalCore::IncidenceBase::TypeTodo) { -// KCalCore::Todo::Ptr t1 = v2result.dynamicCast<KCalCore::Todo>(); -// KCalCore::Todo::Ptr t2 = v3result.dynamicCast<KCalCore::Todo>(); -// QCOMPARE(t1->percentComplete(), t2->percentComplete()); -// QCOMPARE(t1->priority(), t2->priority()); -// QCOMPARE(t1->uid(), t2->uid()); -// QCOMPARE(t1->dtStart(), t2->dtStart()); -// QCOMPARE(t1->dtDue(), t2->dtDue()); -// QCOMPARE(*t1->organizer().data(), *t2->organizer().data()); -// QCOMPARE(t1->uid(), t2->uid()); -// QCOMPARE(t1->allDay(), t2->allDay()); -// QCOMPARE(t1->duration(), t2->duration()); -// QCOMPARE(t1->hasDuration(), t2->hasDuration()); -// qDebug() << "V2: " << v2; -// } - //Test comparator - QCOMPARE(*v2result, *v3result); - QCOMPARE(Kolab::ErrorHandler::instance().error(), Kolab::ErrorHandler::Debug); -} - -void UpgradeTest::testContact_data() -{ - QTest::addColumn<Kolab::ObjectType>( "type" ); - QTest::addColumn<QString>( "filename" ); - - QTest::newRow( "v2contactSimple" )<< Kolab::ContactObject << TESTFILEDIR+QString::fromLatin1("v2/contacts/simple.vcf.mime"); - QTest::newRow( "v2contactComplex" )<< Kolab::ContactObject << TESTFILEDIR+QString::fromLatin1("v2/contacts/complex.vcf.mime"); - QTest::newRow( "v2contactAddress" )<< Kolab::ContactObject << TESTFILEDIR+QString::fromLatin1("v2/contacts/address.vcf.mime"); - QTest::newRow( "v2contactBug238996" )<< Kolab::ContactObject << TESTFILEDIR+QString::fromLatin1("v2/contacts/bug238996.vcf.mime"); - QTest::newRow( "v2contactDisplayname" )<< Kolab::ContactObject << TESTFILEDIR+QString::fromLatin1("v2/contacts/displayname.vcf.mime"); - QTest::newRow( "v2contactEmails" )<< Kolab::ContactObject << TESTFILEDIR+QString::fromLatin1("v2/contacts/emails.vcf.mime"); - QTest::newRow( "v2contactPhonenumber" )<< Kolab::ContactObject << TESTFILEDIR+QString::fromLatin1("v2/contacts/phonenumbers.vcf.mime"); - QTest::newRow( "v2contactPicture" )<< Kolab::ContactObject << TESTFILEDIR+QString::fromLatin1("v2/contacts/picture.vcf.mime"); - QTest::newRow( "v2iso8859-1" )<< Kolab::ContactObject << TESTFILEDIR+QString::fromLatin1("v2/contacts/iso8859-1.mime"); - -} - - -void UpgradeTest::testContact() -{ - QFETCH( Kolab::ObjectType, type ); - QFETCH( QString, filename ); - - //Parse mime message - bool ok = false; - const KMime::Message::Ptr &msg = readMimeFile( filename, ok ); - QVERIFY(ok); - Kolab::KolabObjectReader reader; - Kolab::ObjectType t = reader.parseMimeMessage(msg); - QCOMPARE(t, type); - QCOMPARE(reader.getVersion(), Kolab::KolabV2); - QCOMPARE(Kolab::ErrorHandler::instance().error(), Kolab::ErrorHandler::Debug); - - KABC::Addressee v2Addressee = reader.getContact(); - QVERIFY(!v2Addressee.isEmpty()); - - //Write - const KMime::Message::Ptr &v3message = Kolab::KolabObjectWriter::writeContact(v2Addressee, Kolab::KolabV3); - - //load V3 - Kolab::KolabObjectReader reader2; - QCOMPARE(reader2.parseMimeMessage(v3message), type); - KABC::Addressee v3result = reader2.getContact(); - QVERIFY(!v3result.isEmpty()); - - normalizeContact(v2Addressee); - QVERIFY( normalizePhoneNumbers( v3result, v2Addressee ) ); // phone number ids are random - QVERIFY( normalizeAddresses( v3result, v2Addressee ) ); // same here - - KABC::VCardConverter converter; - if ( v2Addressee != v3result ) { - showDiff(converter.createVCard(v2Addressee), converter.createVCard(v3result)); - QVERIFY( false ); - } - QCOMPARE(Kolab::ErrorHandler::instance().error(), Kolab::ErrorHandler::Debug); -} - - -QTEST_MAIN( UpgradeTest ) - -#include "upgradetest.moc" -
View file
libkolab-2.0.tar.gz/tests/upgradetest.h
Deleted
@@ -1,48 +0,0 @@ -/* - * Copyright (C) 2012 Christian Mollekopf <mollekopf@kolabsys.com> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - - -#ifndef UPGRADETEST_H -#define UPGRADETEST_H - -#include <QObject> - -/** - * Test format upgrade from v2 to v3 - * - * - Parse using v2 implementeation - * - Serialize and reparse using v3 implementeation - * - Compare results - * - * This ensures that all properties which are interpreted by the v2 implementation can be serialized and deserialized by the v3 implementation. - * - * Depends on serialization used for comparison to be correct (i.e. the ical implementation). - */ - -class UpgradeTest: public QObject -{ - Q_OBJECT -private slots: - - void testIncidence_data(); - void testIncidence(); - - void testContact_data(); - void testContact(); -}; - -#endif // UPGRADETEST_H
View file
libkolab-2.0.tar.gz/tests/xmlobjecttest.cpp
Deleted
@@ -1,65 +0,0 @@ -/* - * Copyright (C) 2012 Christian Mollekopf <mollekopf@kolabsys.com> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include "xmlobjecttest.h" - -#include <QTest> -#include <iostream> - -#include "kolabformat/xmlobject.h" - -void XMLObjectTest::testEvent() -{ - Kolab::Event event; - event.setStart(Kolab::cDateTime(2012,01,01)); - - Kolab::XMLObject xmlobject; - const std::string output = xmlobject.writeEvent(event, Kolab::KolabV2, "productid"); - QVERIFY(!output.empty()); - std::cout << output; - - const Kolab::Event resultEvent = xmlobject.readEvent(output, Kolab::KolabV2); - QVERIFY(resultEvent.isValid()); - -} - -void XMLObjectTest::testDontCrash() -{ - Kolab::XMLObject ob; - ob.writeEvent(Kolab::Event(), Kolab::KolabV2, ""); - ob.writeTodo(Kolab::Todo(), Kolab::KolabV2, ""); - ob.writeJournal(Kolab::Journal(), Kolab::KolabV2, ""); - ob.writeFreebusy(Kolab::Freebusy(), Kolab::KolabV2, ""); - ob.writeContact(Kolab::Contact(), Kolab::KolabV2, ""); - ob.writeDistlist(Kolab::DistList(), Kolab::KolabV2, ""); - ob.writeNote(Kolab::Note(), Kolab::KolabV2, ""); - ob.writeConfiguration(Kolab::Configuration(), Kolab::KolabV2, ""); - - ob.readEvent("", Kolab::KolabV2); - ob.readTodo("", Kolab::KolabV2); - ob.readJournal("", Kolab::KolabV2); - ob.readFreebusy("", Kolab::KolabV2); - ob.readContact("", Kolab::KolabV2); - ob.readDistlist("", Kolab::KolabV2); - ob.readNote("", Kolab::KolabV2); - ob.readConfiguration("", Kolab::KolabV2); - -} - -QTEST_MAIN( XMLObjectTest ) - -#include "xmlobjecttest.moc"
View file
libkolab-2.0.tar.gz/tests/xmlobjecttest.h
Deleted
@@ -1,31 +0,0 @@ -/* - * Copyright (C) 2012 Christian Mollekopf <mollekopf@kolabsys.com> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef XMLOBJECTTEST_H -#define XMLOBJECTTEST_H - -#include <QObject> - -class XMLObjectTest: public QObject -{ - Q_OBJECT -private slots: - void testEvent(); - void testDontCrash(); -}; - -#endif // XMLOBJECTTEST_H
View file
libkolab-2.0.tar.gz/utils
Deleted
-(directory)
View file
libkolab-2.0.tar.gz/utils/CMakeLists.txt
Deleted
@@ -1,5 +0,0 @@ - -find_package(Boost REQUIRED COMPONENTS program_options) - -add_executable(kolabformatchecker kolabformatchecker.cpp) -target_link_libraries(kolabformatchecker kolab ${Boost_LIBRARIES})
View file
libkolab-2.0.tar.gz/utils/kolabformatchecker.cpp
Deleted
@@ -1,109 +0,0 @@ -/* - * Copyright (C) 2012 Sofia Balicka <balicka@kolabsys.com> - * Copyright (C) 2013 Christian Mollekopf <mollekopf@kolabsys.com> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include <boost/program_options.hpp> -#include <iostream> -#include <string> -#include <vector> -#include <QString> -#include <QFile> -#include <kolabformat.h> -#include "kolabformat/errorhandler.h" -#include "kolabformat/kolabobject.h" - -namespace po = boost::program_options; -using namespace std; - -KMime::Message::Ptr readMimeFile( const QString &fileName, bool &ok) -{ - QFile file( fileName ); - ok = file.open( QFile::ReadOnly ); - if (!ok) { - cout << "failed to open file: " << fileName.toStdString() << endl;; - return KMime::Message::Ptr(); - } - const QByteArray data = file.readAll(); - KMime::Message::Ptr msg = KMime::Message::Ptr(new KMime::Message); - msg->setContent( KMime::CRLFtoLF(data) ); - msg->parse(); - return msg; -} - -int main(int argc, char *argv[]) -{ - // Declare the supported options. - po::options_description desc("Allowed options"); - desc.add_options() - ("help", "produce help message") - ("input-file", po::value<std::vector<std::string> >(), "input files") - ; - - po::positional_options_description p; - p.add("input-file", -1); - - po::variables_map vm; - po::store(po::command_line_parser(argc, argv). - options(desc).positional(p).run(), vm); - po::notify(vm); - - if (vm.count("help")) { - cout << desc << "\n"; - return 1; - } - - vector<string> inputFiles; - if (vm.count("input-file")) { - inputFiles = vm["input-file"].as< vector<string> >(); - } else { - cout << "Specify input-file\n"; - return -1; - } - - int returnValue = 0; - - cout << endl; - - for(vector<string>::const_iterator it = inputFiles.begin(); - it != inputFiles.end(); it++){ - - cout << "File: " << *it << endl; - - bool ok; - KMime::Message::Ptr message = readMimeFile( QString::fromStdString(*it), ok); - - if(!ok){ - returnValue = -1; - cout << endl; - continue; - } - - Kolab::KolabObjectReader reader(message); - - if (Kolab::ErrorHandler::errorOccured()){ - cout << "Errors occured during parsing." << endl; - returnValue = -1; - } else { - cout << "Parsed message without error." << endl; - } - - cout << endl; - } - - return returnValue; -} -
View file
libkolab-3.0.0.tar.gz/.arcconfig
Added
@@ -0,0 +1,6 @@ +{ + "phabricator.uri" : "https://git.kolab.org/", + "arc.land.onto.default" : "master", + "immutable_history" : true +} +
View file
libkolab-2.0.tar.gz/CMakeLists.txt -> libkolab-3.0.0.tar.gz/CMakeLists.txt
Changed
@@ -1,12 +1,10 @@ project(Libkolab) -cmake_minimum_required(VERSION 2.6.4) +cmake_minimum_required(VERSION 2.8.9) -option( BUILD_TESTS "Build the tests" TRUE ) -option( BUILD_TOOLS "Build the tools" TRUE ) -option( PYTHON_BINDINGS "Build bindings for python" FALSE ) -option( PHP_BINDINGS "Build bindings for php" FALSE ) -option( USE_LIBCALENDARING "Use libcalendaring" FALSE ) +option(BUILD_TESTS "Build the tests" TRUE) +option(PYTHON_BINDINGS "Build bindings for python" FALSE) +option(PHP_BINDINGS "Build bindings for php" FALSE) set(Libkolab_MODULE_DIR ${Libkolab_SOURCE_DIR}/cmake/modules) set(CMAKE_MODULE_PATH ${Libkolab_MODULE_DIR}) @@ -31,19 +29,19 @@ # 0.1.0 (first release) # 0.1.1 (patch release for 0.1.0) # 0.2 (0.2 development version towards 0.2.0) -set(Libkolab_VERSION_MAJOR 2) +set(Libkolab_VERSION_MAJOR 3) set(Libkolab_VERSION_MINOR 0) # Enable the full x.y.z version only for release versions -#set(Libkolab_VERSION_PATCH 1) -#set(Libkolab_VERSION ${Libkolab_VERSION_MAJOR}.${Libkolab_VERSION_MINOR}.${Libkolab_VERSION_PATCH} ) -set(Libkolab_VERSION ${Libkolab_VERSION_MAJOR}.${Libkolab_VERSION_MINOR} ) +set(Libkolab_VERSION_PATCH 0) +#set(Libkolab_VERSION ${Libkolab_VERSION_MAJOR}.${Libkolab_VERSION_MINOR}.${Libkolab_VERSION_PATCH}) +set(Libkolab_VERSION ${Libkolab_VERSION_MAJOR}.${Libkolab_VERSION_MINOR}) set(Libkolab_VERSION_STRING ${CMAKE_PROJECT_NAME}-${Libkolab_VERSION}) # set up install directories. set(LIB_INSTALL_DIR lib${LIB_SUFFIX} CACHE STRING "The directories where to install libraries to") set(INCLUDE_INSTALL_DIR include CACHE STRING "The directory where to install headers to") set(INCLUDE_INSTALL_DIR ${INCLUDE_INSTALL_DIR}/kolab) -set(CMAKECONFIG_INSTALL_DIR ${LIB_INSTALL_DIR}/cmake/Libkolab ) +set(CMAKECONFIG_INSTALL_DIR ${LIB_INSTALL_DIR}/cmake/Libkolab) # Make relative paths absolute (needed later on) foreach(p LIB INCLUDE CMAKECONFIG) @@ -55,150 +53,82 @@ include(MacroLogFeature) +find_package(Qt5 REQUIRED Core Xml) + + # Do the building -find_package(Libkolabxml 1.1 REQUIRED) -macro_log_feature(Libkolabxml_FOUND "Libkolabxml" "Kolab XML Format 3 serializing library" "http://git.kolab.org/libkolabxml/" TRUE "1.0" "Required for reading/writing Kolab XML Objects") +find_package(Libkolabxml 1.1.1 REQUIRED) +macro_log_feature(Libkolabxml_FOUND "Libkolabxml" "Kolab XML Format 3 serializing library" "https://git.kolab.org/diffusion/LKX/" TRUE "1.1.1" "Required for reading/writing Kolab XML Objects") -find_package(Qt4 4.6.0 REQUIRED) +set(QT_REQUIRED_VERSION "5.9.0") -if (USE_LIBCALENDARING) - find_package(Libcalendaring) - macro_log_feature(LIBCALENDARING_FOUND "Libcalendaring" "KDE Calendaring-Dependencies Library" "http://git.kolab.org/libcalendaring/" TRUE "" "Required if KDE libraries are not available.") -else() - find_package(KDE4 4.8 REQUIRED) - find_package(KdepimLibs 4.8 REQUIRED) +if (Qt5_POSITION_INDEPENDENT_CODE) + #Requires cmake 2.8.9 (same as -fPIC on gcc) + set(CMAKE_POSITION_INDEPENDENT_CODE ON) endif() +include(FindPackageHandleStandardArgs) + +find_package(KF5CoreAddons CONFIG REQUIRED) +find_package(KF5CalendarCore "5.12.1" CONFIG REQUIRED) +find_package(KF5Mime "4.84.0" CONFIG REQUIRED) + find_package(SWIG) #Show summary of found libraries macro_display_feature_log() -# add_definitions( -DKDEPIMLIBS_VERSION=((${KdepimLibs_VERSION_MAJOR}<<16)|(${KdepimLibs_VERSION_MINOR}<<8)|(${KDEPIMLIBS_VERSION_PATCH})) ) -add_definitions( -DKDEPIMLIBS_VERSION_MAJOR=${KdepimLibs_VERSION_MAJOR} ) -add_definitions( -DKDEPIMLIBS_VERSION_MINOR=${KdepimLibs_VERSION_MINOR} ) -add_definitions( -DKDEPIMLIBS_VERSION_PATCH=${KdepimLibs_VERSION_PATCH} ) - -#Tag::GENERIC is only available at the moment at the kolab/integration branches -if (KDEPIMLIBS_HAS_GENERIC_TAG) - add_definitions( -DKDEPIMLIBS_HAS_GENERIC_TAG) -endif() - -if("${KdepimLibs_VERSION}" VERSION_GREATER "4.8.40" OR USE_LIBCALENDARING) - add_definitions(-DKDEPIMLIBS_VERSION_DEVEL) -endif() - -if ("${KdepimLibs_VERSION}" VERSION_GREATER "4.11.52") - add_definitions( -DLIBCALENDARING_DURATION_DECLARED) -endif() - -if(CMAKE_COMPILER_IS_GNUCXX) - if(NOT MINGW) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") - endif() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wnon-virtual-dtor -Wno-long-long -ansi -Wundef -Wcast-align -Wchar-subscripts -Wall -W -Wpointer-arith -Wformat-security -fno-exceptions -DQT_NO_EXCEPTIONS -fno-common -Woverloaded-virtual -fno-threadsafe-statics -fvisibility=hidden -Werror=return-type -fvisibility-inlines-hidden -fexceptions -UQT_NO_EXCEPTIONS -g") -endif() - +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wnon-virtual-dtor -Wno-long-long -ansi -Wundef -Wcast-align -Wchar-subscripts -Wall -W -Wpointer-arith -Wformat-security -fno-exceptions -DQT_NO_EXCEPTIONS -fno-common -Woverloaded-virtual -fno-threadsafe-statics -fvisibility=hidden -Werror=return-type -fvisibility-inlines-hidden -fexceptions -UQT_NO_EXCEPTIONS -fPIC -g -std=c++11") # message("${CMAKE_CXX_FLAGS}") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DQT_NO_DEBUG") -if (USE_LIBCALENDARING) - set( KDE_INCLUDES ${Libcalendaring_INCLUDE_DIRS} ) - set( KDE_LIBRARIES ${Libcalendaring_LIBRARIES} ) - message("${Libcalendaring_INCLUDE_DIRS} ${Libcalendaring_LIBRARIES}") -else() - set( KDE_INCLUDES ${KDEPIMLIBS_INCLUDE_DIRS} ${KDE4_INCLUDES} ) - set( KDE_LIBRARIES - ${KDEPIMLIBS_KCALCORE_LIBS} - ${KDEPIMLIBS_KABC_LIBS} - ${KDEPIMLIBS_KMIME_LIBS} - ${KDEPIMLIBS_AKONADI_LIBS} - ${KDEPIMLIBS_AKONADI_NOTES_LIBS} - ${KDEPIMLIBS_KCALUTILS_LIBS} - ${KDEPIMLIBS_KPIMUTILS_LIBS} - ${KDE4_KDECORE_LIBS} - ${KDE4_KIO_LIBS} - ) -endif() - -find_package(Boost REQUIRED) - -include_directories( +include_directories( ${QT_INCLUDES} - ${KDE_INCLUDES} ${CMAKE_BINARY_DIR} - ${Boost_INCLUDE_DIRS} - ${CMAKE_CURRENT_SOURCE_DIR}/kolabformatV2 ${Libkolabxml_INCLUDES} ./ ) configure_file(libkolab-version.h.cmake "${CMAKE_BINARY_DIR}/libkolab-version.h" @ONLY) -set(CMAKE_REQUIRED_FLAGS ${CMAKE_CXX_FLAGS}) -set(CMAKE_REQUIRED_INCLUDES "/opt/devel/kolab/include/") -# include(CheckIncludeFileCXX) -# check_include_file_cxx(akonadi/tag.h HAVE_TAG_H) -#check_include_file_cxx doesn't work for some reason, so we use find_path instead. -#we have to make sure that we only search in KDE_INCLUDES though, to not accidentally include a system akonadi/tag.h -#when we're searching for one in libcalendaring. -find_path(HAVE_TAG_H akonadi/tag.h PATHS ${KDE_INCLUDES} NO_DEFAULT_PATH NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_PATH NO_CMAKE_ENVIRONMENT_PATH) -find_path(HAVE_RELATION_H akonadi/relation.h PATHS ${KDE_INCLUDES} NO_DEFAULT_PATH NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_PATH NO_CMAKE_ENVIRONMENT_PATH) -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libkolab_config.h.in ${CMAKE_CURRENT_BINARY_DIR}/libkolab_config.h) - -add_subdirectory(kolabformatV2) add_subdirectory(conversion) add_subdirectory(calendaring) -add_subdirectory(icalendar) -add_subdirectory(freebusy) -if (BUILD_TOOLS) - add_subdirectory(utils) -endif() -QT4_WRAP_CPP(CALENDARING_MOC calendaring/event.h) -# QT4_WRAP_CPP(CONVERSION_MOC conversion/qtevent.h conversion/qtduration.h) +QT5_WRAP_CPP(CALENDARING_MOC calendaring/event.h) set(KOLAB_SRCS - kolabformat/kolabobject.cpp kolabformat/xmlobject.cpp kolabformat/formathelpers.cpp kolabformat/errorhandler.cpp - kolabformat/v2helpers.cpp - kolabformat/mimeobject.cpp mime/mimeutils.cpp ${CONVERSION_SRCS} ${kolabformatv2_SRCS} ${CALENDARING_SRCS} - ${ICALENDAR_SRCS} - ${CALENDARING_MOC} - ${CONVERSION_MOC} - ${FREEBUSY_SRCS} ) set(KOLAB_LINK_LIBRARIES ${Libkolabxml_LIBRARIES} - ${QT_QTCORE_LIBRARY} - ${QT_QTXML_LIBRARY} - ${QT_QTGUI_LIBRARY} - ${KDE_LIBRARIES} + KF5::CalendarCore + KF5::Mime + Qt5::Core + Qt5::Xml ) -if (BUILD_TOOLS OR BUILD_TESTS) - add_library(kolab_static STATIC ${KOLAB_SRCS}) - target_link_libraries(kolab_static ${KOLAB_LINK_LIBRARIES}) -endif() - if(BUILD_TESTS) + find_package(Qt5Test REQUIRED) + #for tests only enable_testing() + add_library(kolab_static STATIC ${KOLAB_SRCS}) + target_link_libraries(kolab_static ${KOLAB_LINK_LIBRARIES} Qt5::Test) add_subdirectory(tests) endif(BUILD_TESTS) add_library(kolab SHARED ${KOLAB_SRCS}) target_link_libraries(kolab ${KOLAB_LINK_LIBRARIES}) set_target_properties(kolab PROPERTIES VERSION ${Libkolab_VERSION} - SOVERSION ${Libkolab_VERSION_MAJOR} ) + SOVERSION ${Libkolab_VERSION_MAJOR}) -install(TARGETS kolab EXPORT LibkolabExport +install(TARGETS kolab EXPORT LibkolabExport RUNTIME DESTINATION ${BIN_INSTALL_DIR} LIBRARY DESTINATION ${LIB_INSTALL_DIR} ARCHIVE DESTINATION ${LIB_INSTALL_DIR} @@ -208,15 +138,9 @@ kolab_export.h kolabformat/kolabdefinitions.h kolabformat/formathelpers.h - kolabformat/kolabobject.h kolabformat/errorhandler.h kolabformat/xmlobject.h - kolabformat/mimeobject.h - ${CMAKE_CURRENT_BINARY_DIR}/libkolab_config.h - conversion/kcalconversion.h - conversion/kabcconversion.h conversion/commonconversion.h - freebusy/freebusy.h DESTINATION ${INCLUDE_INSTALL_DIR} ) @@ -225,13 +149,13 @@ #Assemble the full relative path. This will be used in the LibkolabConfig.cmake, which will be installed in CMAKECONFIG_INSTALL_DIR set(CONF_INCLUDE_DIRS "\${Libkolab_CMAKE_DIR}/${REL_INCLUDE_DIR}") -install(EXPORT LibkolabExport DESTINATION ${CMAKECONFIG_INSTALL_DIR} FILE LibkolabTargets.cmake ) +install(EXPORT LibkolabExport DESTINATION ${CMAKECONFIG_INSTALL_DIR} FILE LibkolabTargets.cmake) -configure_file(${Libkolab_MODULE_DIR}/LibkolabConfig.cmake.in ${Libkolab_BINARY_DIR}/LibkolabConfig.cmake @ONLY ) -configure_file(${Libkolab_MODULE_DIR}/LibkolabConfigVersion.cmake.in ${Libkolab_BINARY_DIR}/LibkolabConfigVersion.cmake @ONLY ) +configure_file(${Libkolab_MODULE_DIR}/LibkolabConfig.cmake.in ${Libkolab_BINARY_DIR}/LibkolabConfig.cmake @ONLY) +configure_file(${Libkolab_MODULE_DIR}/LibkolabConfigVersion.cmake.in ${Libkolab_BINARY_DIR}/LibkolabConfigVersion.cmake @ONLY) # Install these two files into the same directory as the generated exports-file. install(FILES ${Libkolab_BINARY_DIR}/LibkolabConfig.cmake ${Libkolab_BINARY_DIR}/LibkolabConfigVersion.cmake - DESTINATION ${CMAKECONFIG_INSTALL_DIR} ) + DESTINATION ${CMAKECONFIG_INSTALL_DIR}) include(SWIGUtils)
View file
libkolab-2.0.tar.gz/calendaring/calendaring.cpp -> libkolab-3.0.0.tar.gz/calendaring/calendaring.cpp
Changed
@@ -19,8 +19,10 @@ #include <kcalcore/event.h> #include <kcalcore/todo.h> -#include <Qt/qdebug.h> +#include <qdebug.h> #include <kolabevent.h> +#include <QDate> +#include <QTimeZone> #include "conversion/kcalconversion.h" #include "conversion/commonconversion.h" @@ -29,58 +31,58 @@ namespace Calendaring { -bool conflicts(const Kolab::Event &e1, const Kolab::Event &e2) -{ - KCalCore::Event::Ptr k1 = Kolab::Conversion::toKCalCore(e1); - KCalCore::Event::Ptr k2 = Kolab::Conversion::toKCalCore(e2); - if (k2->dtEnd().compare(k1->dtStart()) == KDateTime::Before) { - return false; - } else if (k1->dtEnd().compare(k2->dtStart()) == KDateTime::Before) { - return false; - } - return true; -} +// bool conflicts(const Kolab::Event &e1, const Kolab::Event &e2) +// { +// KCalCore::Event::Ptr k1 = Kolab::Conversion::toKCalCore(e1); +// KCalCore::Event::Ptr k2 = Kolab::Conversion::toKCalCore(e2); +// if (k2->dtEnd() > k1->dtStart()) { +// return false; +// } else if (k1->dtEnd() > k2->dtStart()) { +// return false; +// } +// return true; +// } -std::vector< std::vector< Event > > getConflictingSets(const std::vector< Event > &events, const std::vector< Event > &events2) -{ - std::vector< std::vector< Kolab::Event > > ret; - for(std::size_t i = 0; i < events.size(); i++) { - std::vector<Kolab::Event> set; - const Kolab::Event &event = events.at(i); - set.push_back(event); - for(std::size_t q = i+1; q < events.size(); q++) { - const Kolab::Event &e2 = events.at(q); - if (conflicts(event, e2)) { - set.push_back(e2); - } - } - for(std::size_t m = 0; m < events2.size(); m++) { - const Kolab::Event &e2 = events2.at(m); - if (conflicts(event, e2)) { - set.push_back(e2); - } - } - if (set.size() > 1) { - ret.push_back(set); - } - } - return ret; -} +// std::vector< std::vector< Event > > getConflictingSets(const std::vector< Event > &events, const std::vector< Event > &events2) +// { +// std::vector< std::vector< Kolab::Event > > ret; +// for(std::size_t i = 0; i < events.size(); i++) { +// std::vector<Kolab::Event> set; +// const Kolab::Event &event = events.at(i); +// set.push_back(event); +// for(std::size_t q = i+1; q < events.size(); q++) { +// const Kolab::Event &e2 = events.at(q); +// if (conflicts(event, e2)) { +// set.push_back(e2); +// } +// } +// for(std::size_t m = 0; m < events2.size(); m++) { +// const Kolab::Event &e2 = events2.at(m); +// if (conflicts(event, e2)) { +// set.push_back(e2); +// } +// } +// if (set.size() > 1) { +// ret.push_back(set); +// } +// } +// return ret; +// } -std::vector<Kolab::cDateTime> timeInInterval(const Kolab::Event &e, const Kolab::cDateTime &start, const Kolab::cDateTime &end) -{ - KCalCore::Event::Ptr k = Kolab::Conversion::toKCalCore(e); - KCalCore::DateTimeList list = k->recurrence()->timesInInterval(Kolab::Conversion::toDate(start), Kolab::Conversion::toDate(end)); - std::vector<Kolab::cDateTime> dtList; - foreach(const KDateTime &dt, list) { - dtList.push_back(Kolab::Conversion::fromDate(dt)); - } - return dtList; -} +// std::vector<Kolab::cDateTime> timeInInterval(const Kolab::Event &e, const Kolab::cDateTime &start, const Kolab::cDateTime &end) +// { +// KCalCore::Event::Ptr k = Kolab::Conversion::toKCalCore(e); +// KCalCore::DateTimeList list = k->recurrence()->timesInInterval(Kolab::Conversion::toDate(start), Kolab::Conversion::toDate(end)); +// std::vector<Kolab::cDateTime> dtList; +// foreach(const QDateTime &dt, list) { +// dtList.push_back(Kolab::Conversion::fromDate(dt)); +// } +// return dtList; +// } Calendar::Calendar() -: mCalendar(new KCalCore::MemoryCalendar(Kolab::Conversion::getTimeSpec(true, std::string()))) //Always utc as it doesn't change anything anyways +: mCalendar(new KCalCore::MemoryCalendar(QTimeZone::utc())) //Always utc as it doesn't change anything anyways { } @@ -95,9 +97,9 @@ std::vector<Kolab::Event> Calendar::getEvents(const Kolab::cDateTime& start, const Kolab::cDateTime& end, bool sort) { - const KDateTime s = Kolab::Conversion::toDate(start); - const KDateTime e = Kolab::Conversion::toDate(end); - const KDateTime::Spec timeSpec = s.timeSpec(); + const QDateTime s = Kolab::Conversion::toDate(start); + const QDateTime e = Kolab::Conversion::toDate(end); + const QTimeZone timeSpec = s.timeZone(); KCalCore::Event::List list = mCalendar->events(s.date(), e.date(), timeSpec, true); if (sort) { list = mCalendar->sortEvents(list, KCalCore::EventSortStartDate, KCalCore::SortDirectionAscending); @@ -105,7 +107,7 @@ std::vector<Kolab::Event> eventlist; foreach (const KCalCore::Event::Ptr &event, list) { //We have to filter the list by time - if (event->dtEnd().compare(s) != KDateTime::Before && e.compare(event->dtStart()) != KDateTime::Before) { + if (event->dtEnd() >= s && event->dtStart() <= e) { eventlist.push_back(Kolab::Conversion::fromKCalCore(*event)); } } @@ -114,4 +116,4 @@ } //Namespace -} //Namespace \ No newline at end of file +} //Namespace
View file
libkolab-2.0.tar.gz/calendaring/calendaring.h -> libkolab-3.0.0.tar.gz/calendaring/calendaring.h
Changed
@@ -27,36 +27,11 @@ #include <kcalcore/event.h> #include <kcalcore/memorycalendar.h> -#include <boost/scoped_ptr.hpp> #include <kolabevent.h> +#include <QSharedPointer> namespace Kolab { namespace Calendaring { -/** - * Returns true if the events conflict (overlap) - * Start and end date/time is inclusive. - * - * Does not take recurrences into account. - */ -KOLAB_EXPORT bool conflicts(const Kolab::Event &, const Kolab::Event &); - -/** - * Returns sets of the events which are directly conflicting with each other. - * The same event may appear in multiple sets. - * Non-conflicting events are not returned. - * conflicts() is used for conflict detection. - * - * If the second list is given, each event from the first list is additionally checked against each event of the second set. - * Conflicts within the second list are not detected. - * - * The checked event from the first list comes always first in the returned set. - */ -KOLAB_EXPORT std::vector< std::vector<Kolab::Event> > getConflictingSets(const std::vector<Kolab::Event> &, const std::vector<Kolab::Event> & = std::vector<Kolab::Event>()); - -/** - * Returns the dates in which the event recurs within the specified timespan. - */ -KOLAB_EXPORT std::vector<Kolab::cDateTime> timeInInterval(const Kolab::Event &, const Kolab::cDateTime &start, const Kolab::cDateTime &end); /** * In-Memory Calendar Cache @@ -77,7 +52,7 @@ private: Calendar(const Calendar &); void operator=(const Calendar &); - boost::scoped_ptr<KCalCore::MemoryCalendar> mCalendar; + QSharedPointer<KCalCore::MemoryCalendar> mCalendar; }; }; //Namespace
View file
libkolab-2.0.tar.gz/calendaring/calendaring.i -> libkolab-3.0.0.tar.gz/calendaring/calendaring.i
Changed
@@ -13,7 +13,7 @@ %import "../shared.i" %rename(EventCal) Kolab::Calendaring::Event; -%rename(KolabCalendar) Kolab::Calendaring::Calendar; +/* %rename(KolabCalendar) Kolab::Calendaring::Calendar; */ -%include "../calendaring/calendaring.h" +/* %include "../calendaring/calendaring.h" */ %include "../calendaring/event.h"
View file
libkolab-2.0.tar.gz/calendaring/datetimeutils.cpp -> libkolab-3.0.0.tar.gz/calendaring/datetimeutils.cpp
Changed
@@ -18,14 +18,14 @@ #include "datetimeutils.h" #include <qdebug.h> -#include <ksystemtimezone.h> +#include <QTimeZone> #include "conversion/commonconversion.h" namespace Kolab { namespace DateTimeUtils { std::string getLocalTimezone() { - const QString tz = KSystemTimeZones::local().name(); + const QString tz = QTimeZone::systemTimeZoneId(); return tz.toStdString(); }
View file
libkolab-2.0.tar.gz/calendaring/event.cpp -> libkolab-3.0.0.tar.gz/calendaring/event.cpp
Changed
@@ -17,8 +17,9 @@ #include "event.h" -#include <icalendar/icalendar.h> -#include <kolabformat/kolabobject.h> + +#include <QDebug> + #include <conversion/kcalconversion.h> #include <conversion/commonconversion.h> @@ -26,6 +27,7 @@ #include <kolabformat.h> #include <kolabevent_p.h> + namespace Kolab { namespace Calendaring { @@ -61,73 +63,6 @@ return Kolab::writeEvent(*this); } -bool Event::fromMime(const std::string &input) -{ - KMime::Message::Ptr msg = KMime::Message::Ptr(new KMime::Message); - msg->setContent( KMime::CRLFtoLF(Kolab::Conversion::fromStdString(input).toUtf8()) ); - msg->parse(); - msg->content(KMime::ContentIndex()); - KolabObjectReader reader(msg); - if (reader.getType() != EventObject) { - std::cout << "not an event "; - return false; - } - const Kolab::Event &e = Kolab::Conversion::fromKCalCore(*reader.getEvent()); - Kolab::Event::operator=(e); - return true; -} - -std::string Event::toMime() const -{ - return std::string(QString(KolabObjectWriter::writeEvent(Kolab::Conversion::toKCalCore(*this))->encodedContent()).toUtf8().constData()); -} - - -bool Event::fromICal(const std::string &input) -{ - std::vector<Kolab::Event> list = fromICalEvents(input); - if (list.size() != 1) { - std::cout << "invalid number of events: " << list.size(); - return false; - } - Kolab::Event::operator=(list.at(0)); - return true; -} - -std::string Event::toICal() const -{ - std::vector<Kolab::Event> list; - list.push_back(*this); - return Kolab::toICal(list); -} - -bool Event::fromIMip(const std::string &input) -{ - std::vector<Kolab::Event> list = mITipHandler.fromIMip(input); - if (list.size() != 1) { - std::cout << "invalid number of events: " << list.size(); - return false; - } - Kolab::Event::operator=(list.at(0)); - return true; -} - -std::string Event::toIMip(ITipMethod method) const -{ - std::vector<Kolab::Event> list; - list.push_back(*this); - return mITipHandler.toIMip(*this, static_cast<ITipHandler::ITipMethod>(method), organizer().email()); -} - -Calendaring::Event::ITipMethod Event::getSchedulingMethod() const -{ - Q_ASSERT((int)iTIPPublish == (int)ITipHandler::iTIPPublish); - Q_ASSERT((int)iTIPNoMethod == (int)ITipHandler::iTIPNoMethod); - return static_cast<ITipMethod>(mITipHandler.method()); -} - - - bool contains(const Kolab::ContactReference &delegatorRef, const std::vector <Kolab::ContactReference > &list) { foreach (const Kolab::ContactReference &ref, list) { @@ -209,10 +144,12 @@ cDateTime Calendaring::Event::getNextOccurence(const cDateTime &date) { KCalCore::Event::Ptr event = Kolab::Conversion::toKCalCore(*this); + qWarning() << "Converted start " << event->dtStart() << Kolab::Conversion::toDate(date); if (!event->recurs()) { return cDateTime(); } - const KDateTime nextDate = event->recurrence()->getNextDateTime(Kolab::Conversion::toDate(date)); + const QDateTime nextDate = event->recurrence()->getNextDateTime(Kolab::Conversion::toDate(date)); + qWarning() << "Next date " << nextDate; return Kolab::Conversion::fromDate(nextDate); } @@ -220,7 +157,7 @@ cDateTime Calendaring::Event::getOccurenceEndDate(const cDateTime &startDate) { KCalCore::Event::Ptr event = Kolab::Conversion::toKCalCore(*this); - const KDateTime start = Kolab::Conversion::toDate(startDate); + const QDateTime start = Kolab::Conversion::toDate(startDate); return Kolab::Conversion::fromDate(event->endDateForStart(start)); } @@ -230,7 +167,7 @@ if (!event->recurs()) { return cDateTime(); } - const KDateTime endDate = event->recurrence()->endDateTime(); + const QDateTime endDate = event->recurrence()->endDateTime(); return Kolab::Conversion::fromDate(endDate); }
View file
libkolab-2.0.tar.gz/calendaring/event.h -> libkolab-3.0.0.tar.gz/calendaring/event.h
Changed
@@ -22,7 +22,6 @@ #ifndef SWIG #include "kolab_export.h" -#include <icalendar/icalendar.h> #else /* No export/import SWIG interface files */ #define KOLAB_EXPORT @@ -45,37 +44,6 @@ std::string write() const; - bool fromMime(const std::string &); - - /** - * Convert to kolab mime format. - */ - std::string toMime() const; - - enum ITipMethod { - iTIPPublish, /**< Event, to-do, journal or freebusy posting */ - iTIPRequest, /**< Event, to-do or freebusy scheduling request */ - iTIPReply, /**< Event, to-do or freebusy reply to request */ - iTIPAdd, /**< Event, to-do or journal additional property request */ - iTIPCancel, /**< Event, to-do or journal cancellation notice */ - iTIPRefresh, /**< Event or to-do description update request */ - iTIPCounter, /**< Event or to-do submit counter proposal */ - iTIPDeclineCounter,/**< Event or to-do decline a counter proposal */ - iTIPNoMethod /**< No method */ - }; - - bool fromICal(const std::string &); - std::string toICal() const; - - bool fromIMip(const std::string &); - std::string toIMip(ITipMethod method) const; - - /** - * Returns the scheduling method from the last fromIMip call - */ - ITipMethod getSchedulingMethod() const; - - /** * Updates the delegators and delegatees of the event. * @@ -113,7 +81,6 @@ private: Kolab::Attendee *getAttendee(const ContactReference &); - Kolab::ITipHandler mITipHandler; }; };
View file
libkolab-2.0.tar.gz/conversion/CMakeLists.txt -> libkolab-3.0.0.tar.gz/conversion/CMakeLists.txt
Changed
@@ -1,8 +1,7 @@ set (CONVERSION_SRCS - ${CMAKE_CURRENT_SOURCE_DIR}/kcalconversion.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/kabcconversion.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/kcalconversion.cpp ${CMAKE_CURRENT_SOURCE_DIR}/commonconversion.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/kolabconversion.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/timezoneconverter.cpp PARENT_SCOPE) + ${CMAKE_CURRENT_SOURCE_DIR}/timezoneconverter.cpp + PARENT_SCOPE)
View file
libkolab-2.0.tar.gz/conversion/commonconversion.cpp -> libkolab-3.0.0.tar.gz/conversion/commonconversion.cpp
Changed
@@ -20,65 +20,79 @@ #include <kolabformat/errorhandler.h> #include <iostream> -#include <ksystemtimezone.h> -#include <kdebug.h> +// #include <KTimeZone> +// #include <KSystemTimeZones> #include <QUrl> +#include <QTimeZone> namespace Kolab { namespace Conversion { -KDateTime::Spec getTimeSpec(bool isUtc, const std::string& timezone) +QTimeZone getTimeSpec(const std::string& timezone) { - if (isUtc) { //UTC - return KDateTime::Spec(KDateTime::UTC); - } if (timezone.empty()) { //Floating - return KDateTime::Spec(KDateTime::ClockTime); + return QTimeZone{}; + // return QDateTime::Spec(Qt::LocalTime); } - //Timezone //Convert non-olson timezones if necessary const QString normalizedTz = TimezoneConverter::normalizeTimezone(QString::fromStdString(timezone)); - KTimeZone tz = KSystemTimeZones::zone(normalizedTz); //Needs ktimezoned (timezone daemon running) http://api.kde.org/4.x-api/kdelibs-apidocs/kdecore/html/classKSystemTimeZones.html - if (!tz.isValid()) { + if (!QTimeZone::isTimeZoneIdAvailable(normalizedTz.toLatin1())) { Warning() << "invalid timezone: " << QString::fromStdString(timezone) << ", assuming floating time"; - if (!KSystemTimeZones::isTimeZoneDaemonAvailable()) { - Error() << "ktimezoned is not available and required for timezone interpretation"; - } - return KDateTime::Spec(KDateTime::ClockTime); + // return QDateTime::Spec(Qt::LocalTime); + return QTimeZone{}; } - return KDateTime::Spec(tz); + //FIXME convert this to a proper KTimeZone + + return QTimeZone(normalizedTz.toLatin1()); } -KDateTime toDate(const Kolab::cDateTime &dt) +QDateTime toDate(const Kolab::cDateTime &dt) { - KDateTime date; if (!dt.isValid()) { //We rely on this codepath, so it's not an error // qDebug() << "invalid datetime converted"; - return KDateTime(); + return QDateTime(); } if (dt.isDateOnly()) { //Date only - date.setDateOnly(true); - date.setDate(QDate(dt.year(), dt.month(), dt.day())); - date.setTimeSpec(KDateTime::Spec(KDateTime::ClockTime)); + //FIXME + // date.setDateOnly(true); + return QDateTime(QDate(dt.year(), dt.month(), dt.day())); + // date.setTimeSpec(Qt::LocalTime); + } + + QDateTime date; + date.setDate(QDate(dt.year(), dt.month(), dt.day())); + date.setTime(QTime(dt.hour(), dt.minute(), dt.second())); + if (dt.isUTC()) { + qWarning() << "Converting utc"; + date.setTimeSpec(Qt::UTC); + // date.setTimeZone(QTimeZone::utc()); + } else if (!dt.timezone().empty()) { + qWarning() << "Converting timezone"; + date.setTimeZone(getTimeSpec(dt.timezone())); } else { - date.setDate(QDate(dt.year(), dt.month(), dt.day())); - date.setTime(QTime(dt.hour(), dt.minute(), dt.second())); - date.setTimeSpec(getTimeSpec(dt.isUTC(), dt.timezone())); + qWarning() << "Converting localtime"; + date.setTimeSpec(Qt::LocalTime); + //We apparently can't have what used to be called floating time, so set the timezone to utc. + // date.setTimeZone(QTimeZone::utc()); + qWarning() << "Converting localtime" << date.timeZone(); } - Q_ASSERT(date.timeSpec().isValid()); + // Q_ASSERT(date.timeSpec().isValid()); Q_ASSERT(date.isValid()); return date; } -cDateTime fromDate(const KDateTime &dt) +cDateTime fromDate(const QDateTime &dt) { + qWarning() << dt; if (!dt.isValid()) { // qDebug() << "invalid datetime converted"; return cDateTime(); } + qWarning() << "From " << dt; cDateTime date; - if (dt.isDateOnly()) { //Date only + if (!dt.time().isValid()) { //Date only + qWarning() << "invalid datetime"; const QDate &d = dt.date(); date.setDate(d.year(), d.month(), d.day()); } else { @@ -86,27 +100,34 @@ date.setDate(d.year(), d.month(), d.day()); const QTime &t = dt.time(); date.setTime(t.hour(), t.minute(), t.second()); - if (dt.timeType() == KDateTime::UTC) { //UTC + if (dt.timeSpec() == Qt::UTC) { //UTC date.setUTC(true); - } else if (dt.timeType() == KDateTime::OffsetFromUTC) { - const KDateTime utcDate = dt.toUtc(); + qWarning() << "From utc"; + } else if (dt.timeSpec() == Qt::OffsetFromUTC) { + const QDateTime utcDate = dt.toUTC(); const QDate &d = utcDate.date(); date.setDate(d.year(), d.month(), d.day()); const QTime &t = utcDate.time(); date.setTime(t.hour(), t.minute(), t.second()); date.setUTC(true); - } else if (dt.timeType() == KDateTime::TimeZone) { //Timezone - //TODO handle local timezone? - //Convert non-olson timezones if necessary - const QString timezone = TimezoneConverter::normalizeTimezone(dt.timeZone().name()); - if (!timezone.isEmpty()) { - date.setTimezone(toStdString(timezone)); - } else { - Warning() << "invalid timezone: " << dt.timeZone().name() << ", assuming floating time"; - return date; - } - } else if (dt.timeType() != KDateTime::ClockTime) { - Error() << "invalid timespec, assuming floating time. Type: " << dt.timeType() << "dt: " << dt.toString(); + } else if (dt.timeSpec() == Qt::TimeZone) { //Timezone + qWarning() << "From timezone"; + //Not actually a timezone + // if (dt.timeZone().id().toLower() == "utc") { + // date.setUTC(true); + // } else { + //Convert non-olson timezones if necessary + const QString timezone = TimezoneConverter::normalizeTimezone(dt.timeZone().id()); + if (!timezone.isEmpty()) { + date.setTimezone(toStdString(timezone)); + } else { + Warning() << "invalid timezone: " << dt.timeZone().id() << ", assuming floating time"; + return date; + } + // } + } else if (dt.timeSpec() != Qt::LocalTime) { + qWarning() << "From localtime"; + Error() << "invalid timespec, assuming floating time. Type: " << dt.timeSpec() << "dt: " << dt.toString(); return date; } } @@ -146,27 +167,37 @@ std::string fromMailto(const QUrl &mailtoUri, std::string &name) { - const std::string &decoded = toStdString(mailtoUri.toString()); + const QPair<std::string, std::string> pair = fromMailto(toStdString(mailtoUri.toString())); + name = pair.second; + return pair.first; +} + +QPair<std::string, std::string> fromMailto(const std::string &mailto) +{ + qWarning() << "fromMailto" << mailto; + const std::string &decoded = toStdString(QUrl::fromPercentEncoding(QByteArray(mailto.c_str()))); + + qWarning() << "fromMailto decoded" << decoded; if (decoded.substr(0, 7).compare("mailto:")) { - WARNING("no mailto address"); - std::cout << decoded << std::endl; - return decoded; + // WARNING("no mailto address"); + // std::cout << decoded << std::endl; + return qMakePair(decoded, std::string()); } std::size_t begin = decoded.find('<',7); if (begin == std::string::npos) { WARNING("no mailto address"); std::cout << decoded << std::endl; - return decoded; + return qMakePair(decoded, std::string()); } std::size_t end = decoded.find('>', begin); if (end == std::string::npos) { WARNING("no mailto address"); std::cout << decoded << std::endl; - return decoded; + return qMakePair(decoded, std::string()); } - name = decoded.substr(7, begin-7); - const std::string &email = decoded.substr(begin+1, end-begin-1); - return email; + const std::string name = decoded.substr(7, begin-7); + const std::string email = decoded.substr(begin+1, end-begin-1); + return qMakePair(email, name); } }
View file
libkolab-2.0.tar.gz/conversion/commonconversion.h -> libkolab-3.0.0.tar.gz/conversion/commonconversion.h
Changed
@@ -20,24 +20,28 @@ #include "kolab_export.h" -#include <kdatetime.h> #include <QStringList> +#include <QDateTime> +#include <QUrl> #include <kolabcontainers.h> namespace Kolab { namespace Conversion { - KOLAB_EXPORT KDateTime toDate(const Kolab::cDateTime &dt); - KOLAB_EXPORT cDateTime fromDate(const KDateTime &dt); + //FIXME handle somehow? + KOLAB_EXPORT QDateTime toDate(const Kolab::cDateTime &dt); + // KOLAB_EXPORT QDateTime toDateTime(const Kolab::cDateTime &dt); + KOLAB_EXPORT cDateTime fromDate(const QDateTime &dt); QStringList toStringList(const std::vector<std::string> &l); std::vector<std::string> fromStringList(const QStringList &l); /** * Returns a UTC, Floating Time or Timezone */ - KDateTime::Spec getTimeSpec(bool isUtc, const std::string &timezone); + // QDateTime::Spec getTimeSpec(bool isUtc, const std::string &timezone); QUrl toMailto(const std::string &email, const std::string &name = std::string()); std::string fromMailto(const QUrl &mailtoUri, std::string &name); + QPair<std::string, std::string> fromMailto(const std::string &mailto); inline std::string toStdString(const QString &s) { @@ -52,4 +56,4 @@ }; }; -#endif \ No newline at end of file +#endif
View file
libkolab-2.0.tar.gz/conversion/kcalconversion.cpp -> libkolab-3.0.0.tar.gz/conversion/kcalconversion.cpp
Changed
@@ -22,6 +22,7 @@ #include <QtCore/QVector> #include <QtCore/QDebug> #include <QUrl> +#include <QDate> #include <vector> #include "kolabformat/errorhandler.h" @@ -273,53 +274,65 @@ i.setRevision(e.sequence()); i.setSecrecy(toSecrecy(e.classification())); i.setCategories(toStringList(e.categories())); - + if (e.start().isValid()) { + + qWarning() << "Setting start" << toDate(e.start()); i.setDtStart(toDate(e.start())); + if (e.start().isDateOnly()) { + i.setAllDay(true); + } } i.setSummary(fromStdString(e.summary())); //TODO detect richtext i.setDescription(fromStdString(e.description())); //TODO detect richtext i.setStatus(toStatus(e.status())); foreach (const Kolab::Attendee a, e.attendees()) { + //FIXME percent encoding? /* * KCalCore always sets a UID if empty, but that's just a pointer, and not the uid of a real contact. * Since that means the semantics of the two are different, we have to store the kolab uid as a custom property. */ - KCalCore::Attendee::Ptr attendee = KCalCore::Attendee::Ptr(new KCalCore::Attendee(fromStdString(a.contact().name()), - fromStdString(a.contact().email()), - a.rsvp(), - toPartStat(a.partStat()), - toRole(a.role()) )); + // QUrl::fromPercentEncoding( + qWarning() << "Name " << fromStdString(a.contact().name()) << " EMail " << fromStdString(a.contact().email()); + KCalCore::Attendee attendee(fromStdString(a.contact().name()), + fromStdString(a.contact().email()), + a.rsvp(), + toPartStat(a.partStat()), + toRole(a.role()) ); if (!a.contact().uid().empty()) { //TODO Identify contact from addressbook based on uid - attendee->customProperties().setNonKDECustomProperty(CUSTOM_KOLAB_CONTACT_UUID, fromStdString(a.contact().uid())); + attendee.customProperties().setNonKDECustomProperty(CUSTOM_KOLAB_CONTACT_UUID, fromStdString(a.contact().uid())); } if (!a.delegatedTo().empty()) { if (a.delegatedTo().size() > 1) { WARNING("multiple delegatees are not supported"); } - attendee->setDelegate(toMailto(a.delegatedTo().front().email(), a.delegatedTo().front().name()).toString()); + + qWarning() << "delegated from " << toMailto(a.delegatedTo().front().email(), a.delegatedTo().front().name()).toString(); + attendee.setDelegate(toMailto(a.delegatedTo().front().email(), a.delegatedTo().front().name()).toString()); } if (!a.delegatedFrom().empty()) { if (a.delegatedFrom().size() > 1) { WARNING("multiple delegators are not supported"); } - attendee->setDelegator(toMailto(a.delegatedFrom().front().email(), a.delegatedFrom().front().name()).toString()); + qWarning() << "delegator from " << toMailto(a.delegatedFrom().front().email(), a.delegatedFrom().front().name()).toString(); + attendee.setDelegator(toMailto(a.delegatedFrom().front().email(), a.delegatedFrom().front().name()).toString()); } - if (!a.cutype() != CutypeIndividual) { - attendee->customProperties().setNonKDECustomProperty(CUSTOM_KOLAB_CONTACT_CUTYPE, QString::number(a.cutype())); + if (a.cutype() != CutypeIndividual) { + attendee.customProperties().setNonKDECustomProperty(CUSTOM_KOLAB_CONTACT_CUTYPE, QString::number(a.cutype())); } + // qWarning() << attendee; i.addAttendee(attendee); } foreach (const Kolab::Attachment a, e.attachments()) { - KCalCore::Attachment::Ptr ptr; + KCalCore::Attachment ptr; if (!a.uri().empty()) { - ptr = KCalCore::Attachment::Ptr(new KCalCore::Attachment(fromStdString(a.uri()), fromStdString(a.mimetype()))); + ptr = KCalCore::Attachment(fromStdString(a.uri()), fromStdString(a.mimetype())); } else { - ptr = KCalCore::Attachment::Ptr(new KCalCore::Attachment(QByteArray::fromRawData(a.data().c_str(), a.data().size()), fromStdString(a.mimetype()))); + ptr = KCalCore::Attachment(QByteArray::fromRawData(a.data().c_str(), a.data().size()).toBase64(), fromStdString(a.mimetype())); } if (!a.label().empty()) { - ptr->setLabel(fromStdString(a.label())); + ptr.setLabel(fromStdString(a.label())); } i.addAttachment(ptr); } @@ -352,23 +365,25 @@ i.setDescription(toStdString(e.description())); i.setStatus(fromStatus(e.status())); std::vector<Kolab::Attendee> attendees; - foreach (const KCalCore::Attendee::Ptr ptr, e.attendees()) { - const QString &uid = ptr->customProperties().nonKDECustomProperty(CUSTOM_KOLAB_CONTACT_UUID); - Kolab::Attendee a(Kolab::ContactReference(toStdString(ptr->email()), toStdString(ptr->name()), toStdString(uid))); - a.setRSVP(ptr->RSVP()); - a.setPartStat(fromPartStat(ptr->status())); - a.setRole(fromRole(ptr->role())); - if (!ptr->delegate().isEmpty()) { + foreach (const KCalCore::Attendee attendee, e.attendees()) { + const QString &uid = attendee.customProperties().nonKDECustomProperty(CUSTOM_KOLAB_CONTACT_UUID); + Kolab::Attendee a(Kolab::ContactReference(toStdString(attendee.email()), toStdString(attendee.name()), toStdString(uid))); + a.setRSVP(attendee.RSVP()); + a.setPartStat(fromPartStat(attendee.status())); + a.setRole(fromRole(attendee.role())); + if (!attendee.delegate().isEmpty()) { std::string name; - const std::string &email = fromMailto(ptr->delegate(), name); + const std::string &email = fromMailto(QUrl(attendee.delegate()), name); + qWarning() << "delegate Email " << email << " EMail " << name << attendee.delegate(); a.setDelegatedTo(std::vector<Kolab::ContactReference>() << Kolab::ContactReference(email, name)); } - if (!ptr->delegator().isEmpty()) { + if (!attendee.delegator().isEmpty()) { std::string name; - const std::string &email = fromMailto(ptr->delegator(), name); + const std::string &email = fromMailto(QUrl(attendee.delegator()), name); + qWarning() << "delegated from " << email << " EMail " << name << attendee.delegator(); a.setDelegatedFrom(std::vector<Kolab::ContactReference>() << Kolab::ContactReference(email, name)); } - const QString &cutype = ptr->customProperties().nonKDECustomProperty(CUSTOM_KOLAB_CONTACT_CUTYPE); + const QString &cutype = attendee.customProperties().nonKDECustomProperty(CUSTOM_KOLAB_CONTACT_CUTYPE); if (!cutype.isEmpty()) { a.setCutype(static_cast<Kolab::Cutype>(cutype.toInt())); } @@ -377,14 +392,14 @@ } i.setAttendees(attendees); std::vector<Kolab::Attachment> attachments; - foreach (const KCalCore::Attachment::Ptr &ptr, e.attachments()) { + foreach (const KCalCore::Attachment &ptr, e.attachments()) { Kolab::Attachment a; - if (ptr->isUri()) { - a.setUri(toStdString(ptr->uri()), toStdString(ptr->mimeType())); + if (ptr.isUri()) { + a.setUri(toStdString(ptr.uri()), toStdString(ptr.mimeType())); } else { - a.setData(std::string(ptr->decodedData().data(), ptr->decodedData().size()), toStdString(ptr->mimeType())); + a.setData(std::string(ptr.decodedData().data(), ptr.decodedData().size()), toStdString(ptr.mimeType())); } - a.setLabel(toStdString(ptr->label())); + a.setLabel(toStdString(ptr.label())); attachments.push_back(a); } i.setAttachments(attachments); @@ -529,6 +544,7 @@ if (rrule.end().isValid()) { rec->setEndDateTime(toDate(rrule.end())); //TODO date/datetime setEndDate(). With date-only the start date has to be taken into account. + qWarning() << "Set end date time" << toDate(rrule.end()); } else { rec->setDuration(rrule.count()); } @@ -563,19 +579,17 @@ } } foreach (const Kolab::cDateTime &dt, event.recurrenceDates()) { - const KDateTime &date = toDate(dt); - if (date.isDateOnly()) { - e.recurrence()->addRDate(date.date()); + if (dt.isDateOnly()) { + e.recurrence()->addRDate(toDate(dt).date()); } else { - e.recurrence()->addRDateTime(date); + e.recurrence()->addRDateTime(toDate(dt)); } } foreach (const Kolab::cDateTime &dt, event.exceptionDates()) { - const KDateTime &date = toDate(dt); - if (date.isDateOnly()) { - e.recurrence()->addExDate(date.date()); + if (dt.isDateOnly()) { + e.recurrence()->addExDate(toDate(dt).date()); } else { - e.recurrence()->addExDateTime(date); + e.recurrence()->addExDateTime(toDate(dt)); } } @@ -625,20 +639,20 @@ i.setRecurrenceRule(rrule); std::vector<Kolab::cDateTime> rdates; - foreach (const KDateTime &dt, rec->rDateTimes()) { + foreach (const QDateTime &dt, rec->rDateTimes()) { rdates.push_back(fromDate(dt)); } foreach (const QDate &dt, rec->rDates()) { - rdates.push_back(fromDate(KDateTime(dt))); + rdates.push_back(fromDate(QDateTime(dt))); } i.setRecurrenceDates(rdates); std::vector<Kolab::cDateTime> exdates; - foreach (const KDateTime &dt, rec->exDateTimes()) { + foreach (const QDateTime &dt, rec->exDateTimes()) { exdates.push_back(fromDate(dt)); } foreach (const QDate &dt, rec->exDates()) { - exdates.push_back(fromDate(KDateTime(dt))); + exdates.push_back(fromDate(QDateTime(dt))); } i.setExceptionDates(exdates); @@ -655,7 +669,7 @@ i.setLocation(fromStdString(e.location())); //TODO detect richtext } if (e.organizer().isValid()) { - i.setOrganizer(KCalCore::Person::Ptr(new KCalCore::Person(fromStdString(e.organizer().name()), fromStdString(e.organizer().email())))); //TODO handle uid too + i.setOrganizer(KCalCore::Person(fromStdString(e.organizer().name()), fromStdString(e.organizer().email()))); //TODO handle uid too } if (!e.url().empty()) { i.setNonKDECustomProperty(CUSTOM_KOLAB_URL, fromStdString(e.url())); @@ -671,7 +685,7 @@ case Kolab::Alarm::EMailAlarm: { KCalCore::Person::List receipents; foreach (Kolab::ContactReference c ,a.attendees()) { - KCalCore::Person::Ptr person = KCalCore::Person::Ptr(new KCalCore::Person(fromStdString(c.name()), fromStdString(c.email()))); + KCalCore::Person person(fromStdString(c.name()), fromStdString(c.email())); receipents.append(person); } alarm->setEmailAlarm(fromStdString(a.summary()), fromStdString(a.description()), receipents); @@ -709,8 +723,8 @@ { i.setPriority(fromPriority(e.priority())); i.setLocation(toStdString(e.location())); - if (e.organizer() && !e.organizer()->email().isEmpty()) { - i.setOrganizer(Kolab::ContactReference(Kolab::ContactReference::EmailReference, toStdString(e.organizer()->email()), toStdString(e.organizer()->name()))); //TODO handle uid too + if (!e.organizer().email().isEmpty()) { + i.setOrganizer(Kolab::ContactReference(Kolab::ContactReference::EmailReference, toStdString(e.organizer().email()), toStdString(e.organizer().name()))); //TODO handle uid too } i.setUrl(toStdString(e.nonKDECustomProperty(CUSTOM_KOLAB_URL))); i.setRecurrenceID(fromDate(e.recurrenceId()), e.thisAndFuture()); @@ -730,8 +744,8 @@ break; case KCalCore::Alarm::Email: { std::vector<Kolab::ContactReference> receipents; - foreach(const KCalCore::Person::Ptr &p, a->mailAddresses()) { - receipents.push_back(Kolab::ContactReference(toStdString(p->email()), toStdString(p->name()))); + foreach(const KCalCore::Person &p, a->mailAddresses()) { + receipents.push_back(Kolab::ContactReference(toStdString(p.email()), toStdString(p.name()))); } alarm = Kolab::Alarm(toStdString(a->mailSubject()), toStdString(a->mailText()), receipents); }
View file
libkolab-2.0.tar.gz/conversion/kcalconversion.h -> libkolab-3.0.0.tar.gz/conversion/kcalconversion.h
Changed
@@ -43,8 +43,8 @@ KOLAB_EXPORT KCalCore::Journal::Ptr toKCalCore(const Kolab::Journal &); KOLAB_EXPORT Kolab::Journal fromKCalCore(const KCalCore::Journal &); - KOLAB_EXPORT KDateTime toDate(const Kolab::cDateTime &dt); - KOLAB_EXPORT cDateTime fromDate(const KDateTime &dt); + KOLAB_EXPORT QDateTime toDate(const Kolab::cDateTime &dt); + KOLAB_EXPORT cDateTime fromDate(const QDateTime &dt); }; };
View file
libkolab-2.0.tar.gz/conversion/timezoneconverter.cpp -> libkolab-3.0.0.tar.gz/conversion/timezoneconverter.cpp
Changed
@@ -16,20 +16,19 @@ */ #include "timezoneconverter.h" -#include <ktimezone.h> -#include <ksystemtimezone.h> -#include <kdebug.h> #include <QRegExp> #include <QStringList> #include "kolabformat/errorhandler.h" +#include <QTimeZone> QString TimezoneConverter::normalizeTimezone(const QString& tz) { - KTimeZone timezone = KSystemTimeZones::zone(tz); //Needs ktimezoned (timezone daemon running) http://api.kde.org/4.x-api/kdelibs-apidocs/kdecore/html/classKSystemTimeZones.html - if (timezone.isValid()) { + if (QTimeZone::isTimeZoneIdAvailable(tz.toLatin1())) { return tz; - } else if (!KSystemTimeZones::isTimeZoneDaemonAvailable()) { - Error() << "ktimezoned is not available and required for timezone interpretation"; + } + auto normalizedId = QTimeZone::windowsIdToDefaultIanaId(tz.toLatin1()); + if (!normalizedId.isEmpty()) { + return normalizedId; } //We're dealing with an invalid or unknown timezone, try to parse it QString guessedTimezone = fromCityName(tz); @@ -39,15 +38,6 @@ if (guessedTimezone.isEmpty()) { guessedTimezone = fromGMTOffsetTimezone(tz); } -// if (guessedTimezone.isEmpty()) { -// //slower but also finds outdated zones -// timezone = KSystemTimeZones::readZone(tz); -// if (timezone.isValid()) { -// //This thinks all kinds of shit is valid, including /etc/localtime. Let's verify again. -// qDebug() << "found " << tz; -// return tz; -// } -// } Debug() << "Guessed timezone and found: " << guessedTimezone; return guessedTimezone; } @@ -60,14 +50,12 @@ QString TimezoneConverter::fromCityName(const QString& tz) { - const KTimeZones::ZoneMap zones = KSystemTimeZones::zones(); - KTimeZones::ZoneMap::const_iterator it = zones.constBegin(); + const auto zones = QTimeZone::availableTimeZoneIds(); QHash<QString, QString> countryMap; - for(;it != zones.constEnd(); it++) { - const QString cityName = it.key().split('/').last(); -// kDebug() << it.key() << it.value().name() << cityName; + for (auto zone : zones) { + const QString cityName = zone.split('/').last(); Q_ASSERT(!countryMap.contains(cityName)); - countryMap.insert(cityName, it.key()); + countryMap.insert(cityName, zone); } QRegExp locationFinder("\\b([a-zA-Z])+\\b", Qt::CaseSensitive, QRegExp::RegExp2); @@ -78,9 +66,9 @@ ++pos; } const QString location = locationFinder.capturedTexts().first(); -// kDebug() << "location " << location; + qDebug() << "location " << location; if (countryMap.contains(location)) { -// kDebug() << "found match " << countryMap.value(location); + qDebug() << "found match " << countryMap.value(location); return countryMap.value(location); } }
View file
libkolab-2.0.tar.gz/kolab_export.h -> libkolab-3.0.0.tar.gz/kolab_export.h
Changed
@@ -25,6 +25,7 @@ //Workaround for qt not defining Q_DECL_IMPORT as it should #if defined(Q_OS_LINUX) +# undef Q_DECL_IMPORT # define Q_DECL_IMPORT __attribute__((visibility("default"))) #endif
View file
libkolab-2.0.tar.gz/kolabformat/errorhandler.h -> libkolab-3.0.0.tar.gz/kolabformat/errorhandler.h
Changed
@@ -19,7 +19,7 @@ #ifndef ERRORHANDLER_H #define ERRORHANDLER_H -#include <kolab_export.h> +#include "kolab_export.h" #include <QString> #include <QList>
View file
libkolab-2.0.tar.gz/kolabformat/formathelpers.cpp -> libkolab-3.0.0.tar.gz/kolabformat/formathelpers.cpp
Changed
@@ -1,5 +1,4 @@ #include "formathelpers.h" -#include <klocalizedstring.h> #include "kolabdefinitions.h" namespace Kolab { @@ -9,14 +8,14 @@ const char *label; } folderTypeData[] = { { KOLAB_FOLDER_TYPE_MAIL, "" }, - { KOLAB_FOLDER_TYPE_CONTACT, I18N_NOOP( "Contacts" ) }, - { KOLAB_FOLDER_TYPE_EVENT, I18N_NOOP( "Calendar" ) }, - { KOLAB_FOLDER_TYPE_TASK, I18N_NOOP( "Tasks" ) }, - { KOLAB_FOLDER_TYPE_JOURNAL, I18N_NOOP( "Journal" ) }, - { KOLAB_FOLDER_TYPE_NOTE, I18N_NOOP( "Notes" ) }, - { KOLAB_FOLDER_TYPE_CONFIGURATION, I18N_NOOP( "Configuration" ) }, - { KOLAB_FOLDER_TYPE_FREEBUSY, I18N_NOOP( "Freebusy" ) }, - { KOLAB_FOLDER_TYPE_FILE, I18N_NOOP( "Files" ) } + { KOLAB_FOLDER_TYPE_CONTACT, "Contacts" }, + { KOLAB_FOLDER_TYPE_EVENT, "Calendar" }, + { KOLAB_FOLDER_TYPE_TASK, "Tasks" }, + { KOLAB_FOLDER_TYPE_JOURNAL, "Journal" }, + { KOLAB_FOLDER_TYPE_NOTE, "Notes" }, + { KOLAB_FOLDER_TYPE_CONFIGURATION, "Configuration" }, + { KOLAB_FOLDER_TYPE_FREEBUSY, "Freebusy" }, + { KOLAB_FOLDER_TYPE_FILE, "Files" } }; static const int numFolderTypeData = sizeof folderTypeData / sizeof *folderTypeData; @@ -78,8 +77,7 @@ FolderType guessFolderTypeFromName(const std::string& name) { for ( int i = 0; i < numFolderTypeData; ++i ) { - if ( name == i18n( folderTypeData[ i ].label ).toStdString() || - name == folderTypeData[ i ].label ) { + if ( name == folderTypeData[ i ].label ) { return static_cast<FolderType>( i ); } } @@ -89,7 +87,7 @@ std::string nameForFolderType(FolderType type) { Q_ASSERT( type >= 0 && type < LastType ); - return i18n( folderTypeData[ type ].label ).toStdString(); + return {folderTypeData[ type ].label}; } }
View file
libkolab-2.0.tar.gz/kolabformat/kolabobject.i -> libkolab-3.0.0.tar.gz/kolabformat/kolabobject.i
Changed
@@ -4,7 +4,6 @@ #include "../kolabformat/xmlobject.h" #include "../kolabformat/kolabdefinitions.h" - #include "../kolabformat/mimeobject.h" %} %include "std_string.i" @@ -15,4 +14,3 @@ %include "../kolabformat/xmlobject.h" %include "../kolabformat/kolabdefinitions.h" -%include "../kolabformat/mimeobject.h"
View file
libkolab-2.0.tar.gz/kolabformat/xmlobject.cpp -> libkolab-3.0.0.tar.gz/kolabformat/xmlobject.cpp
Changed
@@ -16,12 +16,11 @@ */ #include "xmlobject.h" -#include "v2helpers.h" -#include "kolabformatV2/event.h" -#include "conversion/kcalconversion.h" -#include "conversion/kolabconversion.h" -#include "conversion/commonconversion.h" -#include "conversion/kabcconversion.h" +// #include "conversion/kcalconversion.h" +// #include "conversion/kolabconversion.h" +// #include "conversion/commonconversion.h" +// #include "conversion/kabcconversion.h" +#include "kolabformat/errorhandler.h" #include <QUuid> namespace Kolab { @@ -41,8 +40,8 @@ { return mWrittenUID; } - -std::vector< std::string > XMLObject::getAttachments() const + +std::vector<std::string> XMLObject::getAttachments() const { return mAttachments; } @@ -51,98 +50,56 @@ { mWrittenUID.clear(); if (version == KolabV2) { - const KCalCore::Event::Ptr i = Conversion::toKCalCore(event); - if (!i) { - Critical() << "invalid incidence"; - return std::string(); - } - if (i->uid().isEmpty()) { - i->setUid(createUuid()); - } - mWrittenUID = Conversion::toStdString(i->uid()); - //The timezone is used for created and last modified dates - const QString &xml = KolabV2::Event::eventToXML(i, QLatin1String("UTC")); - return Conversion::toStdString(xml); + Critical() << "KolabV2 is not supported."; + return {}; } const std::string result = Kolab::writeEvent(event, productId); mWrittenUID = Kolab::getSerializedUID(); + ErrorHandler::handleLibkolabxmlErrors(); return result; } Event XMLObject::readEvent(const std::string& s, Version version) { if (version == KolabV2) { - QStringList attachments; - const KCalCore::Event::Ptr event = Kolab::fromXML<KCalCore::Event::Ptr, KolabV2::Event>(QString::fromUtf8(s.c_str()).toUtf8(), attachments); - if (!event || Kolab::ErrorHandler::errorOccured()) { - Critical() << "failed to read xml"; - return Event(); - } - mAttachments.clear(); - foreach (const QString &attachment, attachments) { - mAttachments.push_back(Conversion::toStdString(attachment)); - } - return Conversion::fromKCalCore(*event); + Critical() << "KolabV2 is not supported."; + return {}; } - return Kolab::readEvent(s, false); + const Kolab::Event event = Kolab::readEvent(s, false); + ErrorHandler::handleLibkolabxmlErrors(); + return event; } std::string XMLObject::writeTodo(const Todo &event, Version version, const std::string& productId) { mWrittenUID.clear(); if (version == KolabV2) { - const KCalCore::Todo::Ptr i = Conversion::toKCalCore(event); - if (!i) { - Critical() << "invalid incidence"; - return std::string(); - } - if (i->uid().isEmpty()) { - i->setUid(createUuid()); - } - mWrittenUID = Conversion::toStdString(i->uid()); - //The timezone is used for created and last modified dates - const QString &xml = KolabV2::Task::taskToXML(i, QLatin1String("UTC")); - return Conversion::toStdString(xml); + Critical() << "KolabV2 is not supported."; + return {}; } const std::string result = Kolab::writeTodo(event, productId); mWrittenUID = Kolab::getSerializedUID(); + ErrorHandler::handleLibkolabxmlErrors(); return result; } Todo XMLObject::readTodo(const std::string& s, Version version) { if (version == KolabV2) { - QStringList attachments; - const KCalCore::Todo::Ptr event = Kolab::fromXML<KCalCore::Todo::Ptr, KolabV2::Task>(QString::fromUtf8(s.c_str()).toUtf8(), attachments); - if (!event || Kolab::ErrorHandler::errorOccured()) { - Error() << "failed to read xml"; - return Todo(); - } - mAttachments.clear(); - foreach (const QString &attachment, attachments) { - mAttachments.push_back(Conversion::toStdString(attachment)); - } - return Conversion::fromKCalCore(*event); + Critical() << "KolabV2 is not supported."; + return {}; } - return Kolab::readTodo(s, false); + const Kolab::Todo todo = Kolab::readTodo(s, false); + ErrorHandler::handleLibkolabxmlErrors(); + return todo; } std::string XMLObject::writeJournal(const Journal &event, Version version, const std::string& productId) { mWrittenUID.clear(); if (version == KolabV2) { - const KCalCore::Journal::Ptr i = Conversion::toKCalCore(event); - if (!i) { - Critical() << "invalid journal"; - return std::string(); - } - if (i->uid().isEmpty()) { - i->setUid(createUuid()); - } - mWrittenUID = Conversion::toStdString(i->uid()); - //The timezone is used for created and last modified dates - const QString &xml = KolabV2::Journal::journalToXML(i, QLatin1String("UTC")); - return Conversion::toStdString(xml); + Critical() << "KolabV2 is not supported."; + return {}; } const std::string result = Kolab::writeJournal(event, productId); mWrittenUID = Kolab::getSerializedUID(); @@ -152,19 +109,12 @@ Journal XMLObject::readJournal(const std::string& s, Version version) { if (version == KolabV2) { - QStringList attachments; - const KCalCore::Journal::Ptr event = Kolab::fromXML<KCalCore::Journal::Ptr, KolabV2::Journal>(QString::fromUtf8(s.c_str()).toUtf8(), attachments); - if (!event || Kolab::ErrorHandler::errorOccured()) { - Critical() << "failed to read xml"; - return Journal(); - } - mAttachments.clear(); - foreach (const QString &attachment, attachments) { - mAttachments.push_back(Conversion::toStdString(attachment)); - } - return Conversion::fromKCalCore(*event); + Critical() << "KolabV2 is not supported."; + return {}; } - return Kolab::readJournal(s, false); + const Kolab::Journal journal = Kolab::readJournal(s, false); + ErrorHandler::handleLibkolabxmlErrors(); + return journal; } std::string XMLObject::writeFreebusy(const Freebusy &event, Version version, const std::string& productId) @@ -172,7 +122,7 @@ mWrittenUID.clear(); if (version != KolabV3) { Critical() << "only v3 implementation available"; - return std::string(); + return {}; } const std::string result = Kolab::writeFreebusy(event, productId); mWrittenUID = Kolab::getSerializedUID(); @@ -205,114 +155,85 @@ Contact XMLObject::readContact(const std::string& s, Version version) { - if (version == KolabV2) { - const QByteArray xmlData(s.c_str(), s.size()); - QString pictureAttachmentName; - QString logoAttachmentName; - QString soundAttachmentName; - const KABC::Addressee addressee = addresseeFromKolab(xmlData, pictureAttachmentName, logoAttachmentName, soundAttachmentName); - mPictureAttachmentName = Conversion::toStdString(pictureAttachmentName); - mLogoAttachmentName = Conversion::toStdString(logoAttachmentName); - mSoundAttachmentName = Conversion::toStdString(soundAttachmentName); - return Conversion::fromKABC(addressee); + if (version == KolabV2) { + Critical() << "KolabV2 is not supported."; + return {}; } - return Kolab::readContact(s, false); + const Kolab::Contact contact = Kolab::readContact(s, false); + ErrorHandler::handleLibkolabxmlErrors(); + return contact; } std::string XMLObject::writeContact(const Contact &contact, Version version, const std::string& productId) { mWrittenUID.clear(); if (version == KolabV2) { - //FIXME attachment names are hardcoded for now - KABC::Addressee addressee = Conversion::toKABC(contact); - if (addressee.uid().isEmpty()) { - addressee.setUid(createUuid()); - } - mWrittenUID = Conversion::toStdString(addressee.uid()); - const KolabV2::Contact contact(&addressee); - return Conversion::toStdString(contact.saveXML()); + Critical() << "KolabV2 is not supported."; + return {}; } const std::string result = Kolab::writeContact(contact, productId); mWrittenUID = Kolab::getSerializedUID(); + ErrorHandler::handleLibkolabxmlErrors(); return result; } DistList XMLObject::readDistlist(const std::string& s, Version version) { - if (version == KolabV2) { - const QByteArray xmlData(s.c_str(), s.size()); - const KABC::ContactGroup contactGroup = contactGroupFromKolab(xmlData); - return Conversion::fromKABC(contactGroup); + if (version == KolabV2) { + Critical() << "KolabV2 is not supported."; + return {}; } - return Kolab::readDistlist(s, false); + const Kolab::DistList distlist = Kolab::readDistlist(s, false); + ErrorHandler::handleLibkolabxmlErrors(); + return distlist; } std::string XMLObject::writeDistlist(const DistList &distlist, Version version, const std::string& productId) { mWrittenUID.clear(); if (version == KolabV2) { - KABC::ContactGroup contactGroup = Conversion::toKABC(distlist); - if (contactGroup.id().isEmpty()) { - contactGroup.setId(createUuid()); - } - mWrittenUID = Conversion::toStdString(contactGroup.id()); - const KolabV2::DistributionList d(&contactGroup); - return Conversion::toStdString(d.saveXML()); + Critical() << "KolabV2 is not supported."; + return {}; } const std::string result = Kolab::writeDistlist(distlist, productId); mWrittenUID = Kolab::getSerializedUID(); + ErrorHandler::handleLibkolabxmlErrors(); return result; } Note XMLObject::readNote(const std::string& s, Version version) { if (version == KolabV2) { - const KMime::Message::Ptr msg = noteFromKolab(QByteArray(s.c_str(), s.length()), KDateTime()); - if (!msg || Kolab::ErrorHandler::errorOccured()) { - Critical() << "failed to read xml"; - return Note(); - } - return Conversion::fromNote(msg); + Critical() << "KolabV2 is not supported."; + return {}; } - return Kolab::readNote(s, false); + const Kolab::Note note = Kolab::readNote(s, false); + ErrorHandler::handleLibkolabxmlErrors(); + return note; } std::string XMLObject::writeNote(const Note ¬e, Version version, const std::string& productId) { mWrittenUID.clear(); if (version == KolabV2) { - Note noteWithUID = note; - if (noteWithUID.uid().empty()) { - noteWithUID.setUid(Conversion::toStdString(createUuid())); - } - mWrittenUID = noteWithUID.uid(); - const KMime::Message::Ptr n = Conversion::toNote(noteWithUID); - const QByteArray &xml = noteToKolabXML(n); - return std::string(xml.constData()); + Critical() << "KolabV2 is not supported."; + return {}; } const std::string result = Kolab::writeNote(note, productId); mWrittenUID = Kolab::getSerializedUID(); + ErrorHandler::handleLibkolabxmlErrors(); return result; } Configuration XMLObject::readConfiguration(const std::string& s, Version version) { if (version == KolabV2) { - QString lang; - const QStringList dict = readLegacyDictionaryConfiguration(QByteArray(s.c_str(), s.length()), lang); - if (lang.isEmpty()) { - Critical() << "not a dictionary or not a v2 configuration object"; - return Kolab::Configuration(); - } - std::vector<std::string> entries; - foreach (const QString e, dict) { - entries.push_back(Conversion::toStdString(e)); - } - Kolab::Dictionary dictionary(Conversion::toStdString(lang)); - dictionary.setEntries(entries); - return Configuration(dictionary); + Critical() << "KolabV2 is not supported."; + return {}; } - return Kolab::readConfiguration(s, false); + const Kolab::Configuration configuration = Kolab::readConfiguration(s, false); + ErrorHandler::handleLibkolabxmlErrors(); + return configuration; } std::string XMLObject::writeConfiguration(const Configuration &configuration, Version version, const std::string& productId) @@ -324,6 +245,7 @@ } const std::string result = Kolab::writeConfiguration(configuration, productId); mWrittenUID = Kolab::getSerializedUID(); + ErrorHandler::handleLibkolabxmlErrors(); return result; } @@ -333,7 +255,9 @@ Critical() << "only v3 implementation available"; return File(); } - return Kolab::readFile(s, false); + const Kolab::File file = Kolab::readFile(s, false); + ErrorHandler::handleLibkolabxmlErrors(); + return file; } std::string XMLObject::writeFile(const File &file, Version version, const std::string& productId) @@ -345,6 +269,7 @@ } const std::string result = Kolab::writeFile(file, productId); mWrittenUID = Kolab::getSerializedUID(); + ErrorHandler::handleLibkolabxmlErrors(); return result; }
View file
libkolab-2.0.tar.gz/kolabformat/xmlobject.h -> libkolab-3.0.0.tar.gz/kolabformat/xmlobject.h
Changed
@@ -26,6 +26,7 @@ #endif #include <kolabformat.h> +#include <string> #include "kolabdefinitions.h"
View file
libkolab-2.0.tar.gz/mime/mimeutils.cpp -> libkolab-3.0.0.tar.gz/mime/mimeutils.cpp
Changed
@@ -19,10 +19,10 @@ #include <quuid.h> #include <QtCore/qfile.h> #include <qdom.h> -#include <kdebug.h> -#include <kabc/addressee.h> +// #include <kdatetime.h> #include "kolabformat/kolabdefinitions.h" #include "kolabformat/errorhandler.h" +#include <kolabformat.h> #include "libkolab-version.h" namespace Kolab { @@ -65,7 +65,7 @@ } Q_ASSERT(!data->contents().isEmpty()); Q_FOREACH(KMime::Content *c, data->contents()) { -// kDebug() << "searching: " << c->contentID()->identifier(); +// qDebug() << "searching: " << c->contentID()->identifier(); if ( c->contentID()->identifier() == id ) { type = c->contentType()->mimeType(); name = c->contentType()->name(); @@ -93,84 +93,35 @@ return cid.right(cid.size()-4); } -KMime::Message::Ptr createMessage(const KCalCore::Incidence::Ptr &incidencePtr, const QString &mimetype, const QString &xKolabType, const QByteArray &xml, bool v3, const QString &productId) +KMime::Message::Ptr createMessage(const QByteArray &mimetype, const QByteArray &xKolabType, const QByteArray &xml, bool v3, const QByteArray &productId, + const QByteArray &fromEmail, const QString &fromName, const QString &subject) { - KMime::Message::Ptr message = createMessage( xKolabType, v3, productId ); - if (!incidencePtr) { - Error() << "invalid incidence passed in"; - message->assemble(); - return message; - } - if ( incidencePtr->organizer() && !incidencePtr->organizer()->email().isEmpty()) { - message->from()->addAddress( incidencePtr->organizer()->email().toUtf8(), incidencePtr->organizer()->name() ); - } - message->subject()->fromUnicodeString( incidencePtr->uid(), "utf-8" ); - - KMime::Content *content = createMainPart( mimetype, xml ); - message->addContent( content ); - - Q_FOREACH (KCalCore::Attachment::Ptr attachment, incidencePtr->attachments()) { - //Serialize the attachment as attachment with uri, referencing the created mime-part - if (v3 && !attachment->uri().contains("cid:")) { - //onyl by url, skip - continue; - } - message->addContent( createAttachmentPart(fromCid(attachment->uri()).toLatin1(), attachment->mimeType(), attachment->label(), attachment->decodedData() ) ); - } - - message->assemble(); + KMime::Message::Ptr message = createMessage(xKolabType, v3, productId); + message->subject()->fromUnicodeString(subject, "utf-8"); + if (!fromEmail.isEmpty()) { + KMime::Types::Mailbox mb; + mb.setName(fromName); + mb.setAddress(fromEmail); + message->from()->addAddress(mb); + } + message->addContent(createMainPart(mimetype, xml)); return message; } -KMime::Message::Ptr createMessage(const KABC::Addressee &contact, const QString &mimetype, const QString &xKolabType, const QByteArray &xml, bool v3, const QString &prodid) +KMime::Message::Ptr createMessage(const std::string &mimetype, const std::string &xKolabType, const std::string &xml, bool v3, const std::string &productId, + const std::string &fromEmail, const std::string &fromName, const std::string &subject) { - KMime::Message::Ptr message = Mime::createMessage( xKolabType, v3, prodid ); - message->subject()->fromUnicodeString( contact.uid(), "utf-8" ); - message->from()->fromUnicodeString( contact.fullEmail(), "utf-8" ); - - KMime::Content* content = Mime::createMainPart( mimetype, xml ); - message->addContent( content ); - -// TODO add pictures as separate mimeparts -// if ( !contact.picture().isNull() ) { -// QByteArray pic; -// QBuffer buffer(&pic); -// buffer.open(QIODevice::WriteOnly); -// contact.picture().save(&buffer, "PNG"); -// buffer.close(); -// -// content = Mime::createAttachmentPart(QByteArray(), "image/png", "kolab-picture.png", pic ); -// message->addContent(content); -// } -// -// if ( !contact.logo().isNull() ) { -// QByteArray pic; -// QBuffer buffer(&pic); -// buffer.open(QIODevice::WriteOnly); -// contact.logo().save(&buffer, "PNG"); -// buffer.close(); -// -// content = Mime::createAttachmentPart(QByteArray(), "image/png", "kolab-logo.png", pic ); -// message->addContent(content); -// } -// -// if ( !contact.sound().isEmpty() ) { -// content = Mime::createAttachmentPart(QByteArray(), "audio/unknown", "sound", contact.sound() ); -// message->addContent(content); -// } - - message->assemble(); - return message; + return createMessage(QByteArray(mimetype.c_str()), QByteArray(xKolabType.c_str()), QByteArray(xml.c_str()), v3, QByteArray(productId.data()), QByteArray(fromEmail.c_str()), QString::fromStdString(fromName), QString::fromStdString(subject)); } KMime::Message::Ptr createMessage(const QString &subject, const QString &mimetype, const QString &xKolabType, const QByteArray &xml, bool v3, const QString &prodid) { - KMime::Message::Ptr message = createMessage( xKolabType, v3, prodid ); + KMime::Message::Ptr message = createMessage( xKolabType.toLatin1(), v3, prodid.toLatin1() ); if (!subject.isEmpty()) { message->subject()->fromUnicodeString( subject, "utf-8" ); } - KMime::Content *content = createMainPart( mimetype, xml ); + KMime::Content *content = createMainPart( mimetype.toLatin1(), xml ); message->addContent( content ); message->assemble(); @@ -198,106 +149,87 @@ } -KMime::Message::Ptr createMessage(const QString& xKolabType, bool v3, const QString &prodid) +KMime::Message::Ptr createMessage(const QByteArray& xKolabType, bool v3, const QByteArray &prodid) { - KMime::Message::Ptr message( new KMime::Message ); - message->date()->setDateTime( KDateTime::currentUtcDateTime() ); - KMime::Headers::Generic *h = new KMime::Headers::Generic( X_KOLAB_TYPE_HEADER, message.get(), xKolabType, "utf-8" ); - message->appendHeader( h ); + KMime::Message::Ptr message(new KMime::Message); + message->date()->setDateTime(QDateTime::currentDateTimeUtc()); + KMime::Headers::Generic* h = new KMime::Headers::Generic(X_KOLAB_TYPE_HEADER); + h->fromUnicodeString(xKolabType, "utf-8"); + message->appendHeader(h); if (v3) { - KMime::Headers::Generic *vh = new KMime::Headers::Generic( X_KOLAB_MIME_VERSION_HEADER, message.get(), KOLAB_VERSION_V3, "utf-8" ); - message->appendHeader( vh ); - } - message->userAgent()->from7BitString( prodid.toLatin1() ); - message->contentType()->setMimeType( "multipart/mixed" ); - message->contentType()->setBoundary( KMime::multiPartBoundary() ); - - message->addContent( createExplanationPart(v3) ); + KMime::Headers::Generic* hv3 = new KMime::Headers::Generic(X_KOLAB_MIME_VERSION_HEADER); + hv3->fromUnicodeString(KOLAB_VERSION_V3, "utf-8"); + message->appendHeader(hv3); + } + message->userAgent()->from7BitString(prodid); + message->contentType()->setMimeType("multipart/mixed"); + message->contentType()->setBoundary(KMime::multiPartBoundary()); + message->addContent(createExplanationPart(v3)); return message; } -KMime::Content* createMainPart(const QString& mimeType, const QByteArray& decodedContent) +KMime::Content* createMainPart(const QByteArray& mimeType, const QByteArray& decodedContent) { KMime::Content* content = new KMime::Content(); - content->contentType()->setMimeType( mimeType.toLatin1() ); - content->contentType()->setName( KOLAB_OBJECT_FILENAME, "us-ascii" ); + content->contentType()->setMimeType(mimeType); + content->contentType()->setName(KOLAB_OBJECT_FILENAME, "us-ascii"); content->contentTransferEncoding()->setEncoding( KMime::Headers::CEquPr ); content->contentDisposition()->setDisposition( KMime::Headers::CDattachment ); content->contentDisposition()->setFilename( KOLAB_OBJECT_FILENAME ); - content->setBody( decodedContent ); + content->setBody(decodedContent); return content; } -KMime::Content* createAttachmentPart(const QByteArray& cid, const QString& mimeType, const QString& fileName, const QByteArray& decodedContent) +KMime::Content* createAttachmentPart(const QByteArray& cid, const QByteArray& mimeType, const QString& fileName, const QByteArray& base64EncodedContent) { KMime::Content* content = new KMime::Content(); if (!cid.isEmpty()) { content->contentID()->setIdentifier( cid ); } - content->contentType()->setMimeType( mimeType.toLatin1() ); + content->contentType()->setMimeType( mimeType ); content->contentType()->setName( fileName, "utf-8" ); content->contentTransferEncoding()->setEncoding( KMime::Headers::CEbase64 ); content->contentDisposition()->setDisposition( KMime::Headers::CDattachment ); content->contentDisposition()->setFilename( fileName ); - content->setBody( decodedContent ); + content->setBody( base64EncodedContent ); return content; } -void getAttachments(KCalCore::Incidence::Ptr incidence, const QStringList &attachments, const KMime::Message::Ptr &mimeData) +Kolab::Attachment getAttachment(const std::string &id, const KMime::Message::Ptr &mimeData) { - if (!incidence) { - Error() << "Invalid incidence"; - return; - } -// kDebug() << "getting " << attachments.size() << "attachments"; -// kDebug() << mimeData->encodedContent(); - foreach (const QString &name, attachments) { - QByteArray type; - KMime::Content *content = findContentByName(mimeData, name, type); - if (!content) { // guard against malformed events with non-existent attachments - Warning() << "could not find attachment: "<< name.toUtf8() << type; - continue; - } - const QByteArray c = content->decodedContent().toBase64(); -// Debug() << c; - KCalCore::Attachment::Ptr attachment( new KCalCore::Attachment( c, QString::fromLatin1( type ) ) ); - attachment->setLabel( name ); - incidence->addAttachment(attachment); - Debug() << "ATTACHMENT NAME" << name << type; - } + if (!QString::fromStdString(id).contains("cid:")) { + Error() << "not a cid reference"; + return Kolab::Attachment(); + } + QByteArray type; + QString name; + KMime::Content *content = findContentById(mimeData, fromCid(QString::fromStdString(id)).toLatin1(), type, name); + if (!content) { // guard against malformed events with non-existent attachments + Error() << "could not find attachment: "<< name << type; + return Kolab::Attachment(); + } + // Debug() << id << content->decodedContent().toBase64().toStdString(); + Kolab::Attachment attachment; + attachment.setData(content->decodedContent().toStdString(), type.toStdString()); + attachment.setLabel(name.toStdString()); + return attachment; } -void getAttachmentsById(KCalCore::Incidence::Ptr incidence, const KMime::Message::Ptr &mimeData) +Kolab::Attachment getAttachmentByName(const QString &name, const KMime::Message::Ptr &mimeData) { - if (!incidence) { - Error() << "Invalid incidence"; - return; - } -// kDebug() << "getting " << attachments.size() << "attachments"; -// kDebug() << mimeData->encodedContent(); - - foreach(KCalCore::Attachment::Ptr attachment, incidence->attachments()) { - Debug() << attachment->uri(); - if (!attachment->uri().contains("cid:")) { - continue; - } - //It's a referenced attachmant, extract it - QByteArray type; - QString name; - KMime::Content *content = findContentById(mimeData, fromCid(attachment->uri()).toLatin1(), type, name); - if (!content) { // guard against malformed events with non-existent attachments - Error() << "could not find attachment: "<< name << type; - continue; - } - attachment->setUri(QString()); - attachment->setData(content->decodedContent().toBase64()); - attachment->setMimeType(type); - attachment->setLabel(name); - } + QByteArray type; + KMime::Content *content = findContentByName(mimeData, name, type); + if (!content) { // guard against malformed events with non-existent attachments + Warning() << "could not find attachment: "<< name.toUtf8() << type; + return Kolab::Attachment(); + } + Kolab::Attachment attachment; + attachment.setData(content->decodedContent().toStdString(), type.toStdString()); + attachment.setLabel(name.toStdString()); + return attachment; } - }; //Namespace }; //Namespace
View file
libkolab-2.0.tar.gz/mime/mimeutils.h -> libkolab-3.0.0.tar.gz/mime/mimeutils.h
Changed
@@ -20,13 +20,12 @@ #include "kolab_export.h" -#include <kcalcore/incidence.h> -#include <kcalcore/event.h> #include <kmime/kmime_message.h> -#include <kabc/addressee.h> + class QDomDocument; namespace Kolab { + class Attachment; namespace Mime { KMime::Content* findContentByName(const KMime::Message::Ptr &data, const QString &name, QByteArray &type); @@ -38,20 +37,22 @@ * * Set the attachments listed in @param attachments on @param incidence from @param mimeData */ -//v2 -void getAttachments(KCalCore::Incidence::Ptr incidence, const QStringList &attachments, const KMime::Message::Ptr &mimeData); -//v3 -void getAttachmentsById(KCalCore::Incidence::Ptr incidence, const KMime::Message::Ptr &mimeData); +Kolab::Attachment getAttachment(const std::string &id, const KMime::Message::Ptr &mimeData); +Kolab::Attachment getAttachmentByName(const QString &name, const KMime::Message::Ptr &mimeData); + +KMime::Message::Ptr createMessage(const QByteArray &mimetype, const QByteArray &xKolabType, const QByteArray &xml, bool v3, const QByteArray &productId, + const QByteArray &fromEmail, const QString &fromName, const QString &subject); +KMime::Message::Ptr createMessage(const std::string &mimetype, const std::string &xKolabType, const std::string &xml, bool v3, const std::string &productId, + const std::string &fromEmail, const std::string &fromName, const std::string &subject); ///Generic serializing functions -KMime::Message::Ptr createMessage(const KCalCore::Incidence::Ptr &incidencePtr, const QString &mimetype, const QString &xKolabType, const QByteArray &xml, bool v3, const QString &prodid); -KMime::Message::Ptr createMessage(const KABC::Addressee &contact, const QString &mimetype, const QString &xKolabType, const QByteArray &xml, bool v3, const QString &prodid); KMime::Message::Ptr createMessage(const QString &subject, const QString &mimetype, const QString &xKolabType, const QByteArray &xml, bool v3, const QString &prodid); +KMime::Message::Ptr createMessage(const QByteArray& mimeType, bool v3, const QByteArray &prodid); KMime::Content* createExplanationPart(); -KMime::Message::Ptr createMessage(const QString& mimeType, bool v3, const QString &prodid); -KMime::Content* createMainPart(const QString& mimeType, const QByteArray& decodedContent); -KMime::Content* createAttachmentPart(const QByteArray &cid, const QString& mimeType, const QString& fileName, const QByteArray& decodedContent); +KMime::Content* createMainPart(const QByteArray& mimeType, const QByteArray& decodedContent); +KMime::Content* createAttachmentPart(const QByteArray& cid, const QByteArray& mimeType, const QString& fileName, const QByteArray& decodedContent); +QString fromCid(const QString &cid); }; }; //Namespace
View file
libkolab-2.0.tar.gz/tests/CMakeLists.txt -> libkolab-3.0.0.tar.gz/tests/CMakeLists.txt
Changed
@@ -2,29 +2,18 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR}) add_definitions(-DTEST_DATA_PATH="${CMAKE_CURRENT_SOURCE_DIR}") +set(CMAKE_AUTOMOC ON) +set(CMAKE_INCLUDE_CURRENT_DIR ON) + macro(addTest TEST_NAME) - QT4_AUTOMOC(${TEST_NAME}.cpp) add_executable(${TEST_NAME} ${TEST_NAME}.cpp) - target_link_libraries(${TEST_NAME} ${QT_QTTEST_LIBRARY} kolab_static) + target_link_libraries(${TEST_NAME} Qt5::Test kolab_static) add_test(${TEST_NAME} ${CMAKE_CURRENT_BINARY_DIR}/${TEST_NAME}) endmacro() -QT4_AUTOMOC(benchmark.cpp) -add_executable(benchmarktest benchmark.cpp) -target_link_libraries(benchmarktest ${QT_QTTEST_LIBRARY} kolab_static) - -addTest(formattest) -addTest(upgradetest) addTest(kcalconversiontest) addTest(calendaringtest) -addTest(icalendartest) -addTest(freebusytest) -addTest(kolabobjecttest) addTest(timezonetest) -addTest(mimeobjecttest) -addTest(xmlobjecttest) -addTest(debugstreamtest) -addTest(legacyformattest) if(PHP_BINDINGS) find_path(PHP_KOLABFORMAT_PATH NAMES kolabformat.php PATHS /usr/local/lib/php/modules /usr/lib/php/modules PATH_SUFFIXES lib/php/modules lib64/php/modules)
View file
libkolab-2.0.tar.gz/tests/calendaringtest.cpp -> libkolab-3.0.0.tar.gz/tests/calendaringtest.cpp
Changed
@@ -19,10 +19,8 @@ #include "calendaringtest.h" #include <QTest> -#include <ksystemtimezone.h> #include <kolabevent.h> #include <iostream> -#include <calendaring/calendaring.h> #include <calendaring/event.h> #include <calendaring/datetimeutils.h> @@ -44,7 +42,6 @@ void CalendaringTest::initTestCase() { - QVERIFY2(KSystemTimeZones::isTimeZoneDaemonAvailable(), "Timezone support is required for this test. Either use libcalendaring or make sure KTimeZoned is available"); } void CalendaringTest::testCalendaringEvent() @@ -64,260 +61,6 @@ QCOMPARE(calEvent2.uid(), calEvent3.uid()); } -void CalendaringTest::testEventConflict_data() -{ - QTest::addColumn<Kolab::Event>( "e1" ); - QTest::addColumn<Kolab::Event>( "e2" ); - QTest::addColumn<bool>( "result" ); - { - Kolab::Event e1; - e1.setStart(Kolab::cDateTime(2011,10,10,12,1,1,true)); - e1.setEnd(Kolab::cDateTime(2011,10,11,12,1,1,true)); - - Kolab::Event e2; - e2.setStart(Kolab::cDateTime(2011,11,10,12,1,1,true)); - e2.setEnd(Kolab::cDateTime(2011,11,11,12,1,1,true)); - - QTest::newRow( "after" ) << e1 << e2 << false; - } - - { - Kolab::Event e1; - e1.setStart(Kolab::cDateTime(2011,10,10,12,1,1,true)); - e1.setEnd(Kolab::cDateTime(2011,10,11,12,1,1,true)); - - Kolab::Event e2; - e2.setStart(Kolab::cDateTime(2011,9,10,12,1,1,true)); - e2.setEnd(Kolab::cDateTime(2011,9,11,12,1,1,true)); - - QTest::newRow( "before" ) << e1 << e2 << false; - } - - { - Kolab::Event e1; - e1.setStart(Kolab::cDateTime(2011,10,10,12,1,1,true)); - e1.setEnd(Kolab::cDateTime(2011,10,11,12,1,1,true)); - - Kolab::Event e2; - e2.setStart(Kolab::cDateTime(2011,10,10,12,1,1,true)); - e2.setEnd(Kolab::cDateTime(2011,10,11,12,1,1,true)); - - QTest::newRow( "conflict" ) << e1 << e2 << true; - } - - { - Kolab::Event e1; - e1.setStart(Kolab::cDateTime("Europe/Zurich", 2011,10,10,6,1,1)); - e1.setEnd(Kolab::cDateTime("Europe/Zurich", 2011,10,10,6,1,2)); - - Kolab::Event e2; - e2.setStart(Kolab::cDateTime("Asia/Dubai",2011,10,10,6,1,1)); - e2.setEnd(Kolab::cDateTime("Asia/Dubai",2011,10,10,6,1,2)); - - QTest::newRow( "tz non-conflict" ) << e1 << e2 << false; - } - - { - Kolab::Event e1; - e1.setStart(Kolab::cDateTime("Europe/Berlin", 2011,10,10,6,1,1)); - e1.setEnd(Kolab::cDateTime("Europe/Berlin", 2011,10,10,6,1,2)); - - Kolab::Event e2; - e2.setStart(Kolab::cDateTime("Europe/Zurich",2011,10,10,6,1,1)); - e2.setEnd(Kolab::cDateTime("Europe/Zurich",2011,10,10,6,1,2)); - - QTest::newRow( "tz conflict" ) << e1 << e2 << true; - } -} - -void CalendaringTest::testEventConflict() -{ - QFETCH(Kolab::Event, e1); - QFETCH(Kolab::Event, e2); - QFETCH(bool, result); - QCOMPARE(Kolab::Calendaring::conflicts(e1,e2), result); -} - -void CalendaringTest::testEventConflictSet() -{ - std::vector<Kolab::Event> events; - events.push_back(createEvent(Kolab::cDateTime(2011,10,6,12,1,1,true), Kolab::cDateTime(2011,10,8,12,1,1,true))); - events.push_back(createEvent(Kolab::cDateTime(2011,10,7,12,1,1,true), Kolab::cDateTime(2011,10,10,12,1,1,true))); - events.push_back(createEvent(Kolab::cDateTime(2011,10,9,12,1,1,true), Kolab::cDateTime(2011,10,11,12,1,1,true))); - const std::vector< std::vector<Kolab::Event> > &result = Kolab::Calendaring::getConflictingSets(events); - - std::vector< std::vector<Kolab::Event> > expectedResult; - std::vector<Kolab::Event> r1; - r1.push_back(createEvent(Kolab::cDateTime(2011,10,6,12,1,1,true), Kolab::cDateTime(2011,10,8,12,1,1,true))); - r1.push_back(createEvent(Kolab::cDateTime(2011,10,7,12,1,1,true), Kolab::cDateTime(2011,10,10,12,1,1,true))); - expectedResult.push_back(r1); - std::vector<Kolab::Event> r2; - r2.push_back(createEvent(Kolab::cDateTime(2011,10,7,12,1,1,true), Kolab::cDateTime(2011,10,10,12,1,1,true))); - r2.push_back(createEvent(Kolab::cDateTime(2011,10,9,12,1,1,true), Kolab::cDateTime(2011,10,11,12,1,1,true))); - expectedResult.push_back(r2); - - for (std::size_t i = 0; i < result.size(); i++) { - const std::vector<Kolab::Event> &list = result.at(i); - - qDebug() << "---------_Set--------------"; - foreach(const Kolab::Event &event, list) { - qDebug() << QTest::toString(event.start()) << QTest::toString(event.end()); - } - compareEvents(result.at(i), expectedResult.at(i)); - } -} - -void CalendaringTest::testTimesInInterval_data() -{ - QTest::addColumn<Kolab::Event>( "event" ); - QTest::addColumn<Kolab::cDateTime>( "start" ); - QTest::addColumn<Kolab::cDateTime>( "end" ); - QTest::addColumn< std::vector<Kolab::cDateTime> >( "result" ); - { - { - Kolab::Event event; - event.setStart(Kolab::cDateTime(2011,1,1,1,1,1,true)); - event.setEnd(Kolab::cDateTime(2011,1,1,2,1,1,true)); - Kolab::RecurrenceRule rrule; - rrule.setFrequency(Kolab::RecurrenceRule::Daily); - rrule.setInterval(1); - rrule.setCount(5); - event.setRecurrenceRule(rrule); - - std::vector<Kolab::cDateTime> result; - result.push_back(Kolab::cDateTime(2011,1,1,1,1,1,true)); - result.push_back(Kolab::cDateTime(2011,1,2,1,1,1,true)); - result.push_back(Kolab::cDateTime(2011,1,3,1,1,1,true)); - result.push_back(Kolab::cDateTime(2011,1,4,1,1,1,true)); - result.push_back(Kolab::cDateTime(2011,1,5,1,1,1,true)); - QTest::newRow( "simple" ) << event << Kolab::cDateTime(2011,1,1,1,1,1,true) << Kolab::cDateTime(2011,1,5,1,1,1,true) << result; - } - } -} - -void CalendaringTest::testTimesInInterval() -{ - QFETCH(Kolab::Event, event); - QFETCH(Kolab::cDateTime, start); - QFETCH(Kolab::cDateTime, end); - QFETCH(std::vector<Kolab::cDateTime>, result); - QCOMPARE(Kolab::Calendaring::timeInInterval(event,start, end), result); -} - -void CalendaringTest::testTimesInIntervalBenchmark() -{ - Kolab::Event event; - event.setStart(Kolab::cDateTime(2011,1,1,1,1,1)); - event.setEnd(Kolab::cDateTime(2011,1,1,2,1,1)); - Kolab::RecurrenceRule rrule; - rrule.setFrequency(Kolab::RecurrenceRule::Daily); - rrule.setInterval(1); - rrule.setCount(500); - event.setRecurrenceRule(rrule); - - QBENCHMARK { - Kolab::Calendaring::timeInInterval(event, Kolab::cDateTime(2011,1,1,1,1,1), Kolab::cDateTime(2013,1,1,1,1,1)); - } - const std::vector<Kolab::cDateTime> &result = Kolab::Calendaring::timeInInterval(event, Kolab::cDateTime(2011,1,1,1,1,1), Kolab::cDateTime(2013,1,1,1,1,1)); - QVERIFY(result.size() == 500); -// qDebug() << QTest::toString(result); -} - -void CalendaringTest::testCalendar_data() -{ - QTest::addColumn< std::vector<Kolab::Event> >( "inputevents" ); - QTest::addColumn<Kolab::cDateTime>( "start" ); - QTest::addColumn<Kolab::cDateTime>( "end" ); - QTest::addColumn< std::vector<Kolab::Event> >( "expectedResult" ); - - { - std::vector<Kolab::Event> inputevents; - for (int day = 1; day < 28; day++) { - for (int hour = 1; hour < 20; hour+=2) { - inputevents.push_back(createEvent(Kolab::cDateTime(2012,5,day,hour,4,4, true), Kolab::cDateTime(2012,5,day,hour+1,4,4, true))); - } - } - std::vector<Kolab::Event> expectedResult; - expectedResult.push_back(createEvent(Kolab::cDateTime(2012,5,5,3,4,4, true), Kolab::cDateTime(2012,5,5,3+1,4,4, true))); - expectedResult.push_back(createEvent(Kolab::cDateTime(2012,5,5,5,4,4, true), Kolab::cDateTime(2012,5,5,5+1,4,4, true))); - expectedResult.push_back(createEvent(Kolab::cDateTime(2012,5,5,7,4,4, true), Kolab::cDateTime(2012,5,5,7+1,4,4, true))); - expectedResult.push_back(createEvent(Kolab::cDateTime(2012,5,5,9,4,4, true), Kolab::cDateTime(2012,5,5,9+1,4,4, true))); - expectedResult.push_back(createEvent(Kolab::cDateTime(2012,5,5,11,4,4, true), Kolab::cDateTime(2012,5,5,11+1,4,4, true))); - expectedResult.push_back(createEvent(Kolab::cDateTime(2012,5,5,13,4,4, true), Kolab::cDateTime(2012,5,5,13+1,4,4, true))); - expectedResult.push_back(createEvent(Kolab::cDateTime(2012,5,5,15,4,4, true), Kolab::cDateTime(2012,5,5,15+1,4,4, true))); - expectedResult.push_back(createEvent(Kolab::cDateTime(2012,5,5,17,4,4, true), Kolab::cDateTime(2012,5,5,17+1,4,4, true))); - expectedResult.push_back(createEvent(Kolab::cDateTime(2012,5,5,19,4,4, true), Kolab::cDateTime(2012,5,5,19+1,4,4, true))); - expectedResult.push_back(createEvent(Kolab::cDateTime(2012,5,6,1,4,4, true), Kolab::cDateTime(2012,5,6,1+1,4,4, true))); - expectedResult.push_back(createEvent(Kolab::cDateTime(2012,5,6,3,4,4, true), Kolab::cDateTime(2012,5,6,3+1,4,4, true))); - QTest::newRow( "simple" ) << inputevents << Kolab::cDateTime(2012,5,5,4,4,4, true) << Kolab::cDateTime(2012,5,6,4,4,4, true) << expectedResult; - } - - { //Start and end time inclusive - std::vector<Kolab::Event> inputevents; - inputevents.push_back(createEvent(Kolab::cDateTime(2012,5,5,1,4,4, true), Kolab::cDateTime(2012,5,5,1+1,4,4, true))); - inputevents.push_back(createEvent(Kolab::cDateTime(2012,5,5,3,4,4, true), Kolab::cDateTime(2012,5,5,3+1,4,4, true))); - inputevents.push_back(createEvent(Kolab::cDateTime(2012,5,5,5,4,4, true), Kolab::cDateTime(2012,5,5,5+1,4,4, true))); - inputevents.push_back(createEvent(Kolab::cDateTime(2012,5,5,7,4,4, true), Kolab::cDateTime(2012,5,5,7+1,4,4, true))); - inputevents.push_back(createEvent(Kolab::cDateTime(2012,5,5,9,4,4, true), Kolab::cDateTime(2012,5,5,9+1,4,4, true))); - - std::vector<Kolab::Event> expectedResult; - expectedResult.push_back(createEvent(Kolab::cDateTime(2012,5,5,3,4,4, true), Kolab::cDateTime(2012,5,5,3+1,4,4, true))); - expectedResult.push_back(createEvent(Kolab::cDateTime(2012,5,5,5,4,4, true), Kolab::cDateTime(2012,5,5,5+1,4,4, true))); - expectedResult.push_back(createEvent(Kolab::cDateTime(2012,5,5,7,4,4, true), Kolab::cDateTime(2012,5,5,7+1,4,4, true))); - QTest::newRow( "startEndTimeInclusive" ) << inputevents << Kolab::cDateTime(2012,5,5,3,4,4, true) << Kolab::cDateTime(2012,5,5,7,4,4, true) << expectedResult; - } - - { //Start and end time inclusive (floating time) - std::vector<Kolab::Event> inputevents; - inputevents.push_back(createEvent(Kolab::cDateTime(2012,5,5,1,4,4, false), Kolab::cDateTime(2012,5,5,1+1,4,4, false))); - inputevents.push_back(createEvent(Kolab::cDateTime(2012,5,5,3,4,4, false), Kolab::cDateTime(2012,5,5,3+1,4,4, false))); - inputevents.push_back(createEvent(Kolab::cDateTime(2012,5,5,5,4,4, false), Kolab::cDateTime(2012,5,5,5+1,4,4, false))); - inputevents.push_back(createEvent(Kolab::cDateTime(2012,5,5,7,4,4, false), Kolab::cDateTime(2012,5,5,7+1,4,4, false))); - inputevents.push_back(createEvent(Kolab::cDateTime(2012,5,5,9,4,4, false), Kolab::cDateTime(2012,5,5,9+1,4,4, false))); - - std::vector<Kolab::Event> expectedResult; - expectedResult.push_back(createEvent(Kolab::cDateTime(2012,5,5,3,4,4, false), Kolab::cDateTime(2012,5,5,3+1,4,4, false))); - expectedResult.push_back(createEvent(Kolab::cDateTime(2012,5,5,5,4,4, false), Kolab::cDateTime(2012,5,5,5+1,4,4, false))); - expectedResult.push_back(createEvent(Kolab::cDateTime(2012,5,5,7,4,4, false), Kolab::cDateTime(2012,5,5,7+1,4,4, false))); - QTest::newRow( "startEndTimeInclusive" ) << inputevents << Kolab::cDateTime(2012,5,5,3,4,4, false) << Kolab::cDateTime(2012,5,5,7,4,4, false) << expectedResult; - } - - { //Start and end time inclusive (timezone) - std::vector<Kolab::Event> inputevents; - inputevents.push_back(createEvent(Kolab::cDateTime("Europe/Zurich",2012,5,5,1,4,4), Kolab::cDateTime("Europe/Zurich",2012,5,5,1+1,4,4))); - inputevents.push_back(createEvent(Kolab::cDateTime("Europe/Zurich",2012,5,5,3,4,4), Kolab::cDateTime("Europe/Zurich",2012,5,5,3+1,4,4))); - inputevents.push_back(createEvent(Kolab::cDateTime("Europe/Zurich",2012,5,5,5,4,4), Kolab::cDateTime("Europe/Zurich",2012,5,5,5+1,4,4))); - inputevents.push_back(createEvent(Kolab::cDateTime("Europe/Zurich",2012,5,5,7,4,4), Kolab::cDateTime("Europe/Zurich",2012,5,5,7+1,4,4))); - inputevents.push_back(createEvent(Kolab::cDateTime("Europe/Zurich",2012,5,5,9,4,4), Kolab::cDateTime("Europe/Zurich",2012,5,5,9+1,4,4))); - - std::vector<Kolab::Event> expectedResult; - expectedResult.push_back(createEvent(Kolab::cDateTime("Europe/Zurich",2012,5,5,3,4,4), Kolab::cDateTime("Europe/Zurich",2012,5,5,3+1,4,4))); - expectedResult.push_back(createEvent(Kolab::cDateTime("Europe/Zurich",2012,5,5,5,4,4), Kolab::cDateTime("Europe/Zurich",2012,5,5,5+1,4,4))); - expectedResult.push_back(createEvent(Kolab::cDateTime("Europe/Zurich",2012,5,5,7,4,4), Kolab::cDateTime("Europe/Zurich",2012,5,5,7+1,4,4))); - QTest::newRow( "startEndTimeInclusive" ) << inputevents << Kolab::cDateTime("Europe/Zurich",2012,5,5,3,4,4) << Kolab::cDateTime("Europe/Zurich",2012,5,5,7,4,4) << expectedResult; - } - -} - -void CalendaringTest::testCalendar() -{ - - QFETCH(std::vector<Kolab::Event>, inputevents); - QFETCH(Kolab::cDateTime, start); - QFETCH(Kolab::cDateTime, end); - QFETCH(std::vector<Kolab::Event>, expectedResult); - - Kolab::Calendaring::Calendar cal; - foreach (const Kolab::Event &event, inputevents) { - cal.addEvent(event); - } - const std::vector<Kolab::Event> result = cal.getEvents(start, end, true); - foreach (const Kolab::Event &event, result) { - qDebug() << QTest::toString(event.start()) << QTest::toString(event.end()); - } - compareEvents(result, expectedResult); -} - void CalendaringTest::delegationTest() { Kolab::Calendaring::Event event; @@ -349,52 +92,15 @@ //TODO write an actual test } -void CalendaringTest::testICal() -{ - Kolab::Calendaring::Event event; - event.setStart(Kolab::cDateTime("Europe/Zurich",2012,5,5,3,4,4)); - const std::string &result = event.toICal(); - //TODO write an actual test - event.setStart(Kolab::cDateTime(1,1,1)); - event.fromICal(result); - QCOMPARE(event.start(), Kolab::cDateTime("Europe/Zurich",2012,5,5,3,4,4)); -} - -void CalendaringTest::testMime() -{ - Kolab::Calendaring::Event event; - event.setStart(Kolab::cDateTime("Europe/Zurich",2012,5,5,3,4,4)); - std::cout << event.toMime(); - const std::string &result = event.toMime(); - event.setStart(Kolab::cDateTime(1,1,1)); - event.fromMime(result); - QCOMPARE(event.start(), Kolab::cDateTime("Europe/Zurich",2012,5,5,3,4,4)); -} - -void CalendaringTest::testIMip() -{ - Kolab::Calendaring::Event event; - Kolab::Attendee att1(Kolab::ContactReference("email1", "name1", "uid1")); - - std::vector <Kolab::Attendee > attendees; - attendees.push_back(att1); - event.setAttendees(attendees); - event.setOrganizer(Kolab::ContactReference("organizer@test.org", "organizer", "uid3")); - event.setSummary("summary"); - event.setStart(Kolab::cDateTime("Europe/Zurich",2012,5,5,3,4,4)); - const std::string &result = event.toIMip(Kolab::Calendaring::Event::iTIPRequest); - event.setStart(Kolab::cDateTime(1,1,1)); - event.fromIMip(result); - QEXPECT_FAIL("", "returns UTC instead of local timezone", Continue); - QCOMPARE(event.start(), Kolab::cDateTime("Europe/Zurich",2012,5,5,3,4,4)); - QCOMPARE(event.getSchedulingMethod(), Kolab::Calendaring::Event::iTIPRequest); -} - void CalendaringTest::testRecurrence() { + //FIXME this is currently broken for floating or utc, + //because KCalendarCore::RecurrenceRule::getNextDate implicitly + //converts to the timezone of dtstart, which defaults to the local + //timezone if none is set. Kolab::Calendaring::Event event; - event.setStart(Kolab::cDateTime(2011,1,1,1,1,1)); - event.setEnd(Kolab::cDateTime(2011,1,1,2,1,1)); + event.setStart(Kolab::cDateTime("Europe/Zurich", 2011,1,1,1,1,1)); + event.setEnd(Kolab::cDateTime("Europe/Zurich", 2011,1,1,2,1,1)); Kolab::RecurrenceRule rrule; rrule.setFrequency(Kolab::RecurrenceRule::Daily); rrule.setInterval(1); @@ -404,11 +110,11 @@ Kolab::cDateTime previousDate = event.start(); for (int i = 0; i < 9; i++) { const Kolab::cDateTime nextDate = event.getNextOccurence(previousDate); -// qDebug() << QTest::toString(nextDate); - QCOMPARE(nextDate, Kolab::cDateTime(previousDate.year(), previousDate.month(), previousDate.day()+1, previousDate.hour(), previousDate.minute(), previousDate.second())); + qDebug() << QTest::toString(nextDate); + QCOMPARE(nextDate, Kolab::cDateTime("Europe/Zurich", previousDate.year(), previousDate.month(), previousDate.day()+1, previousDate.hour(), previousDate.minute(), previousDate.second())); const Kolab::cDateTime endDate = event.getOccurenceEndDate(nextDate); // qDebug() << QTest::toString(endDate); - QCOMPARE(endDate, Kolab::cDateTime(nextDate.year(), nextDate.month(), nextDate.day(), event.end().hour(), event.end().minute(), event.end().second())); + QCOMPARE(endDate, Kolab::cDateTime("Europe/Zurich", nextDate.year(), nextDate.month(), nextDate.day(), event.end().hour(), event.end().minute(), event.end().second())); previousDate = nextDate; }
View file
libkolab-2.0.tar.gz/tests/calendaringtest.h -> libkolab-3.0.0.tar.gz/tests/calendaringtest.h
Changed
@@ -28,23 +28,23 @@ void testCalendaringEvent(); - void testEventConflict_data(); - void testEventConflict(); + // void testEventConflict_data(); + // void testEventConflict(); - void testEventConflictSet(); + // void testEventConflictSet(); - void testTimesInInterval_data(); - void testTimesInInterval(); - void testTimesInIntervalBenchmark(); + // void testTimesInInterval_data(); + // void testTimesInInterval(); + // void testTimesInIntervalBenchmark(); - void testCalendar_data(); - void testCalendar(); + // void testCalendar_data(); + // void testCalendar(); void delegationTest(); - void testMime(); - void testICal(); - void testIMip(); + // void testMime(); + // void testICal(); + // void testIMip(); void testRecurrence();
View file
libkolab-2.0.tar.gz/tests/kcalconversiontest.cpp -> libkolab-3.0.0.tar.gz/tests/kcalconversiontest.cpp
Changed
@@ -16,23 +16,29 @@ */ #include "kcalconversiontest.h" -#include <contact.h> +#include <QTimeZone> #include <QtCore/QObject> #include <QtTest/QtTest> -#include <ksystemtimezone.h> #include <kolabcontact.h> #include <kcalcore/recurrence.h> -#include <kabc/addressee.h> #include "conversion/kcalconversion.h" #include "conversion/kcalconversion.cpp" -#include "conversion/kabcconversion.h" #include "testhelpers.h" using namespace Kolab::Conversion; template <typename T> +void compareVectors(const QVector<T> &list, const QVector<T> &other) +{ + QCOMPARE(list.size(), other.size()); + for (int i = 0 ; i < list.size(); i++) { + QCOMPARE(list.at(i), other.at(i)); + } +} + +template <typename T> void comparePointerVectors(const QVector<T> &list, const QVector<T> &other) { QCOMPARE(list.size(), other.size()); @@ -45,39 +51,38 @@ { QCOMPARE(list.size(), other.size()); for (int i = 0 ; i < list.size(); i++) { - KCalCore::Attendee::Ptr at1 = list.at(i).constCast<KCalCore::Attendee>(); - at1->setUid(QString()); - KCalCore::Attendee::Ptr at2 = other.at(i).constCast<KCalCore::Attendee>(); - at2->setUid(QString()); - QCOMPARE(*at1, *at2); + KCalCore::Attendee at1 = list.at(i); + at1.setUid(QString()); + KCalCore::Attendee at2 = other.at(i); + at2.setUid(QString()); + QCOMPARE(at1, at2); } } void KCalConversionTest::initTestCase() { - QVERIFY2(KSystemTimeZones::isTimeZoneDaemonAvailable(), "Timezone support is required for this test. Either use libcalendaring or make sure KTimeZoned is available"); } void KCalConversionTest::testDate_data() { QTest::addColumn<Kolab::cDateTime>( "input" ); - QTest::addColumn<KDateTime>( "result" ); + QTest::addColumn<QDateTime>( "result" ); - QTest::newRow( "datetime with tz" ) << Kolab::cDateTime("Europe/Zurich",2006,1,8,12,0,0) << KDateTime(QDate(2006, 1, 8), QTime(12, 0, 0), KSystemTimeZones::zone("Europe/Zurich")); - QTest::newRow( "floating datetime" ) << Kolab::cDateTime(2006,1,8,12,0,0, false) << KDateTime(QDate(2006, 1, 8), QTime(12, 0, 0), KDateTime::Spec(KDateTime::ClockTime)); - QTest::newRow( "utc datetime" ) << Kolab::cDateTime(2006,1,8,12,0,0, true) << KDateTime(KDateTime(QDate(2006, 1, 8), QTime(12, 0, 0), KDateTime::UTC)); - QTest::newRow( "date only" ) << Kolab::cDateTime(2006,1,8) << KDateTime(QDate(2006, 1, 8)); + QTest::newRow( "datetime with tz" ) << Kolab::cDateTime("Europe/Zurich",2006,1,8,12,0,0) << QDateTime(QDate(2006, 1, 8), QTime(12, 0, 0), QTimeZone("Europe/Zurich")); + QTest::newRow( "floating datetime" ) << Kolab::cDateTime(2006,1,8,12,0,0, false) << QDateTime(QDate(2006, 1, 8), QTime(12, 0, 0), Qt::LocalTime); + QTest::newRow( "utc datetime" ) << Kolab::cDateTime(2006,1,8,12,0,0, true) << QDateTime(QDateTime(QDate(2006, 1, 8), QTime(12, 0, 0), Qt::UTC)); + QTest::newRow( "date only" ) << Kolab::cDateTime(2006,1,8, 0, 0, 0) << QDateTime(QDate(2006, 1, 8)); } void KCalConversionTest::testDate() { QFETCH(Kolab::cDateTime, input); - QFETCH(KDateTime, result); - - const KDateTime &r = Kolab::Conversion::toDate(input); + QFETCH(QDateTime, result); + qWarning() << "expected result" << result; + const QDateTime &r = Kolab::Conversion::toDate(input); QCOMPARE(r, result); - + qWarning() << "toDate" << r; const Kolab::cDateTime &r2 = Kolab::Conversion::fromDate(result); QCOMPARE(r2, input); } @@ -114,22 +119,23 @@ void KCalConversionTest::testDateTZ_data() { QTest::addColumn<Kolab::cDateTime>( "input" ); - QTest::addColumn<KDateTime>( "result" ); + QTest::addColumn<QDateTime>( "result" ); - QTest::newRow( "berlin" ) << Kolab::cDateTime("Europe/Berlin",2006,1,8,12,0,0) << KDateTime(QDate(2006, 1, 8), QTime(12, 0, 0), KSystemTimeZones::zone("Europe/Berlin")); + QTest::newRow( "berlin" ) << Kolab::cDateTime("Europe/Berlin",2006,1,8,12,0,0) << QDateTime(QDate(2006, 1, 8), QTime(12, 0, 0), QTimeZone("Europe/Berlin")); } void KCalConversionTest::testDateTZ() { QFETCH(Kolab::cDateTime, input); - QFETCH(KDateTime, result); + QFETCH(QDateTime, result); - const KDateTime &r = Kolab::Conversion::toDate(input); - QCOMPARE(result.timeZone().name(), QString::fromStdString(input.timezone())); - QCOMPARE(r.timeZone().currentOffset(), result.timeZone().currentOffset()); + const QDateTime &r = Kolab::Conversion::toDate(input); + //FIXME + QCOMPARE(result.timeZone().id(), QString::fromStdString(input.timezone()).toLatin1()); + // QCOMPARE(r.timeZone().currentOffset(), result.timeZone().currentOffset()); - const Kolab::cDateTime &r2 = Kolab::Conversion::fromDate(result); - QCOMPARE(QString::fromStdString(r2.timezone()), result.timeZone().name()); + // const Kolab::cDateTime &r2 = Kolab::Conversion::fromDate(result); + // QCOMPARE(QString::fromStdString(r2.timezone()), result.timeZone().name()); } @@ -186,17 +192,17 @@ kcal.setPriority(3); kcal.setStatus(KCalCore::Incidence::StatusConfirmed); kcal.setLocation("location"); - kcal.setOrganizer(KCalCore::Person::Ptr(new KCalCore::Person("organizer", "organizer@email"))); + kcal.setOrganizer(KCalCore::Person("organizer", "organizer@email")); //Url kcal.setNonKDECustomProperty("X-KOLAB-URL", "http://test.org"); - KCalCore::Attendee::Ptr att(new KCalCore::Attendee("attendee", "attendee@email", false, KCalCore::Attendee::NeedsAction, KCalCore::Attendee::ReqParticipant)); - att->setDelegate("mailto:delegatee<delegatee@email>"); - att->setDelegator("mailto:delegator<delegator@email>"); + KCalCore::Attendee att("attendee", "attendee@email", false, KCalCore::Attendee::NeedsAction, KCalCore::Attendee::ReqParticipant); + att.setDelegate("mailto:delegatee<delegatee@email>"); + att.setDelegator("mailto:delegator<delegator@email>"); kcal.addAttendee(att); - kcal.addAttachment(KCalCore::Attachment::Ptr(new KCalCore::Attachment(QString("uri"), "mimetype/mime"))); + kcal.addAttachment(KCalCore::Attachment(QString("uri"), "mimetype/mime")); KCalCore::Alarm::Ptr alarm = KCalCore::Alarm::Ptr(new KCalCore::Alarm(&kcal)); KCalCore::Person::List addressees; - addressees.append(KCalCore::Person::Ptr(new KCalCore::Person("name", "email@email"))); + addressees.append(KCalCore::Person("name", "email@email")); alarm->setEmailAlarm("subject", "text", addressees, QStringList()); //No support for attachments kcal.addAlarm(alarm); //TODO alarms @@ -373,7 +379,7 @@ QCOMPARE(e->dtEnd(), kcal.dtEnd()); QCOMPARE(e->duration(), kcal.duration()); QCOMPARE(e->transparency(), kcal.transparency()); - QCOMPARE(*e->recurrence(), *kcal.recurrence()); + // QCOMPARE(*e->recurrence(), *kcal.recurrence()); QCOMPARE(e->recurrenceId(), kcal.recurrenceId()); QCOMPARE(e->thisAndFuture(), kcal.thisAndFuture()); QCOMPARE(e->recurrenceType(), kcal.recurrenceType()); @@ -382,14 +388,14 @@ QCOMPARE(e->priority(), kcal.priority()); QCOMPARE(e->status(), kcal.status()); QCOMPARE(e->location(), kcal.location()); - QCOMPARE(e->organizer()->name(), kcal.organizer()->name()); - QCOMPARE(e->organizer()->email(), kcal.organizer()->email()); + QCOMPARE(e->organizer().name(), kcal.organizer().name()); + QCOMPARE(e->organizer().email(), kcal.organizer().email()); QCOMPARE(e->nonKDECustomProperty("X-KOLAB-URL"), kcal.nonKDECustomProperty("X-KOLAB-URL")); //otherwise we'd break the customProperties comparison e->removeNonKDECustomProperty("X-KOLAB-URL"); kcal.removeNonKDECustomProperty("X-KOLAB-URL"); - compareAttendeesVectors(e->attendees(), kcal.attendees()); - comparePointerVectors(e->attachments(), kcal.attachments()); + // compareAttendeesVectors(e->attendees(), kcal.attendees()); + compareVectors(e->attachments(), kcal.attachments()); // QCOMPARE(e->alarms(), kcal.alarms()); //TODO QCOMPARE(e->customProperties(), kcal.customProperties()); @@ -404,16 +410,16 @@ QCOMPARE(b.sequence(), kolab.sequence()); QCOMPARE(b.classification(), kolab.classification()); QCOMPARE(b.categories(), kolab.categories()); - QCOMPARE(b.start(), kolab.start()); - QCOMPARE(b.end(), kolab.end()); + // QCOMPARE(b.start(), kolab.start()); + // QCOMPARE(b.end(), kolab.end()); QCOMPARE(b.duration(), kolab.duration()); QCOMPARE(b.transparency(), kolab.transparency()); - QCOMPARE(b.recurrenceRule(), kolab.recurrenceRule()); + // QCOMPARE(b.recurrenceRule(), kolab.recurrenceRule()); QCOMPARE(b.recurrenceID(), kolab.recurrenceID()); QCOMPARE(b.thisAndFuture(), kolab.thisAndFuture()); - QCOMPARE(b.recurrenceDates(), kolab.recurrenceDates()); - QCOMPARE(b.exceptionDates(), kolab.exceptionDates()); + // QCOMPARE(b.recurrenceDates(), kolab.recurrenceDates()); + // QCOMPARE(b.exceptionDates(), kolab.exceptionDates()); QCOMPARE(b.summary(), kolab.summary()); QCOMPARE(b.description(), kolab.description()); @@ -515,93 +521,6 @@ QCOMPARE(b.summary(), kolab.summary()); } -void KCalConversionTest::testContactConversion_data() -{ - QTest::addColumn<KABC::Addressee>( "kcal" ); - QTest::addColumn<Kolab::Contact>( "kolab" ); - - { - KABC::Addressee kcal; - kcal.setUid("uid"); - kcal.setFormattedName("name"); - - Kolab::Contact kolab; - kolab.setUid("uid"); - kolab.setName("name"); - - QTest::newRow("basic") << kcal << kolab; - } - { - KABC::Addressee kcal; - kcal.setUid("uid"); - kcal.setFormattedName("name"); - kcal.setBirthday(QDateTime(QDate(2012,2,2))); - - //Because QDateTime doesn't know date-only values we always end up with a date-time - Kolab::Contact kolab; - kolab.setUid("uid"); - kolab.setName("name"); - kolab.setBDay(Kolab::cDateTime(2012,2,2,0,0,0)); - - QTest::newRow("bday") << kcal << kolab; - } - { - KABC::Addressee kcal; - kcal.setUid("uid"); - //The first address is always the preferred - kcal.setEmails(QStringList() << "email1@example.org" << "email2@example.org"); - kcal.insertCustom("KOLAB", "EmailTypesemail1@example.org", "home,work"); - - Kolab::Contact kolab; - kolab.setUid("uid"); - - Kolab::Email email1("email1@example.org", Kolab::Email::Work|Kolab::Email::Home); - Kolab::Email email2("email2@example.org"); - - std::vector<Kolab::Email> emails; - emails.push_back(email1); - emails.push_back(email2); - kolab.setEmailAddresses(emails, 0); - - QTest::newRow("emailTypesAndPreference") << kcal << kolab; - } -} - - -void KCalConversionTest::testContactConversion() -{ - QFETCH(KABC::Addressee, kcal); - QFETCH(Kolab::Contact, kolab); - - const KABC::Addressee &e = toKABC(kolab); - - QCOMPARE(e.uid(), kcal.uid()); - QCOMPARE(e.formattedName(), kcal.formattedName()); - QCOMPARE(e.emails(), kcal.emails()); - QCOMPARE(e.preferredEmail(), kcal.preferredEmail()); - foreach (const QString &mail, e.emails()) { - QCOMPARE(e.custom(QLatin1String("KOLAB"), QString::fromLatin1("EmailTypes%1").arg(mail)), kcal.custom(QLatin1String("KOLAB"), QString::fromLatin1("EmailTypes%1").arg(mail))); - } - QCOMPARE(e.birthday(), kcal.birthday()); - - const Kolab::Contact &b = fromKABC(kcal); - QCOMPARE(b.uid(), kolab.uid()); - QCOMPARE(b.name(), kolab.name()); - QCOMPARE(b.emailAddresses(), kolab.emailAddresses()); - QCOMPARE(b.emailAddressPreferredIndex(), kolab.emailAddressPreferredIndex()); - QCOMPARE(b.bDay(), kolab.bDay()); -} - - -// void KCalConversionTest::BenchmarkRoundtripKCAL() -// { -// const Kolab::Event &event = Kolab::readEvent(TEST_DATA_PATH "/testfiles/icalEvent.xml", true); -// std::string result = Kolab::writeEvent(event); -// QBENCHMARK { -// Kolab::Conversion::toKCalCore(Kolab::readEvent(result, false)); -// } -// } - QTEST_MAIN( KCalConversionTest ) #include "kcalconversiontest.moc"
View file
libkolab-2.0.tar.gz/tests/kcalconversiontest.h -> libkolab-3.0.0.tar.gz/tests/kcalconversiontest.h
Changed
@@ -42,12 +42,9 @@ void testJournalConversion_data(); void testJournalConversion(); - void testContactConversion_data(); - void testContactConversion(); - void testDateTZ_data(); void testDateTZ(); }; -#endif \ No newline at end of file +#endif
View file
libkolab-2.0.tar.gz/tests/testfiles/v2/contacts/address.vcf.mime -> libkolab-3.0.0.tar.gz/tests/testfiles/v2/contacts/address.vcf.mime
Changed
@@ -1,6 +1,6 @@ Date: Tue, 01 Sep 2009 10:56:10 +0200 X-Kolab-Type: application/x-vnd.kolab.contact -User-Agent: Akonadi Kolab Proxy Resource +User-Agent: Libkolab-3.0.0 Content-Type: multipart/mixed; boundary="nextPart3449010.4rJ2gEvUCK" Subject: TX1vqbIUlB MIME-Version: 1.0
View file
libkolab-2.0.tar.gz/tests/testfiles/v2/contacts/bug238996.vcf.mime -> libkolab-3.0.0.tar.gz/tests/testfiles/v2/contacts/bug238996.vcf.mime
Changed
@@ -1,6 +1,6 @@ Date: Mon, 31 Aug 2009 18:23:30 +0200 X-Kolab-Type: application/x-vnd.kolab.contact -User-Agent: Libkolab-x.x.x +User-Agent: Libkolab-3.0.0 Content-Type: multipart/mixed; boundary="nextPart3762459.HDmZFN3AqE" Subject: Huu5X7hfYy From: Firstname Lastname <first@email.org>
View file
libkolab-2.0.tar.gz/tests/testfiles/v2/contacts/complex.vcf.mime -> libkolab-3.0.0.tar.gz/tests/testfiles/v2/contacts/complex.vcf.mime
Changed
@@ -1,6 +1,6 @@ Date: Mon, 31 Aug 2009 18:23:30 +0200 X-Kolab-Type: application/x-vnd.kolab.contact -User-Agent: Akonadi Kolab Proxy Resource +User-Agent: Libkolab-3.0.0 Content-Type: multipart/mixed; boundary="nextPart3762459.HDmZFN3AqE" Subject: Huu5X7hfYy From: Firstname Lastname <first@email.org>
View file
libkolab-2.0.tar.gz/tests/testfiles/v2/contacts/displayname.vcf.mime -> libkolab-3.0.0.tar.gz/tests/testfiles/v2/contacts/displayname.vcf.mime
Changed
@@ -1,6 +1,6 @@ Date: Tue, 01 Sep 2009 09:15:59 +0200 X-Kolab-Type: application/x-vnd.kolab.contact -User-Agent: Akonadi Kolab Proxy Resource +User-Agent: Libkolab-3.0.0 Content-Type: multipart/mixed; boundary="nextPart1671573.1jqa7tTDaI" Subject: sWDhiG62Ea MIME-Version: 1.0
View file
libkolab-2.0.tar.gz/tests/testfiles/v2/contacts/emails.vcf.mime -> libkolab-3.0.0.tar.gz/tests/testfiles/v2/contacts/emails.vcf.mime
Changed
@@ -1,6 +1,6 @@ Date: Tue, 01 Sep 2009 13:13:40 +0200 X-Kolab-Type: application/x-vnd.kolab.contact -User-Agent: Akonadi Kolab Proxy Resource +User-Agent: Libkolab-3.0.0 Content-Type: multipart/mixed; boundary="nextPart2497845.VQRhqsHbKY" Subject: zj77MLHTiw From: Email Addresses <first@email.org>
View file
libkolab-2.0.tar.gz/tests/testfiles/v2/contacts/phonenumbers.vcf.mime -> libkolab-3.0.0.tar.gz/tests/testfiles/v2/contacts/phonenumbers.vcf.mime
Changed
@@ -1,6 +1,6 @@ Date: Tue, 01 Sep 2009 10:20:52 +0200 X-Kolab-Type: application/x-vnd.kolab.contact -User-Agent: Akonadi Kolab Proxy Resource +User-Agent: Libkolab-3.0.0 Content-Type: multipart/mixed; boundary="nextPart5288440.YZXQeyvXcV" Subject: DskcKTX5C5 MIME-Version: 1.0
View file
libkolab-2.0.tar.gz/tests/testfiles/v2/contacts/picture.vcf.mime -> libkolab-3.0.0.tar.gz/tests/testfiles/v2/contacts/picture.vcf.mime
Changed
@@ -1,6 +1,6 @@ Date: Tue, 01 Sep 2009 09:50:04 +0200 X-Kolab-Type: application/x-vnd.kolab.contact -User-Agent: Akonadi Kolab Proxy Resource +User-Agent: Libkolab-3.0.0 Content-Type: multipart/mixed; boundary="nextPart3467792.lKc2nMLyO8" Subject: DVd76P1FDJ MIME-Version: 1.0
View file
libkolab-2.0.tar.gz/tests/testfiles/v2/contacts/simple.vcf.mime -> libkolab-3.0.0.tar.gz/tests/testfiles/v2/contacts/simple.vcf.mime
Changed
@@ -1,6 +1,6 @@ Date: Mon, 31 Aug 2009 14:39:35 +0200 X-Kolab-Type: application/x-vnd.kolab.contact -User-Agent: Akonadi Kolab Proxy Resource +User-Agent: Libkolab-3.0.0 Content-Type: multipart/mixed; boundary="nextPart8293045.ykzvriC3IH" Subject: 4xuyC0cyjV From: Volker Krause <vkrause@kde.org>
View file
libkolab-2.0.tar.gz/tests/testfiles/v2/event/allday.ics.mime -> libkolab-3.0.0.tar.gz/tests/testfiles/v2/event/allday.ics.mime
Changed
@@ -1,6 +1,6 @@ Date: Tue, 01 Sep 2009 15:15:20 +0200 X-Kolab-Type: application/x-vnd.kolab.event -User-Agent: Akonadi Kolab Proxy Resource +User-Agent: Libkolab-3.0.0 Content-Type: multipart/mixed; boundary="nextPart2050770.69HWcxcYtE" Subject: KOrganizer-1256760206.500 MIME-Version: 1.0
View file
libkolab-2.0.tar.gz/tests/testfiles/v2/event/attachment.ics.mime -> libkolab-3.0.0.tar.gz/tests/testfiles/v2/event/attachment.ics.mime
Changed
@@ -1,6 +1,6 @@ Date: Tue, 01 Sep 2009 14:58:47 +0200 X-Kolab-Type: application/x-vnd.kolab.event -User-Agent: Akonadi Kolab Proxy Resource +User-Agent: Libkolab-3.0.0 Content-Type: multipart/mixed; boundary="nextPart3083467.JSZapPgxdJ" Subject: KOrganizer-1181687251.384 MIME-Version: 1.0
View file
libkolab-2.0.tar.gz/tests/testfiles/v2/event/complex.ics.mime -> libkolab-3.0.0.tar.gz/tests/testfiles/v2/event/complex.ics.mime
Changed
@@ -1,6 +1,6 @@ Date: Tue, 01 Sep 2009 14:53:03 +0200 X-Kolab-Type: application/x-vnd.kolab.event -User-Agent: Akonadi Kolab Proxy Resource +User-Agent: Libkolab-3.0.0 Content-Type: multipart/mixed; boundary="nextPart1532650.N5Q3PfLWqK" Subject: KOrganizer-1687167952.818 MIME-Version: 1.0
View file
libkolab-2.0.tar.gz/tests/testfiles/v2/event/iso8859-1.mime -> libkolab-3.0.0.tar.gz/tests/testfiles/v2/event/iso8859-1.mime
Changed
@@ -1,6 +1,6 @@ Date: Tue, 01 Sep 2009 13:36:50 +0200 X-Kolab-Type: application/x-vnd.kolab.event -User-Agent: Akonadi Kolab Proxy Resource +User-Agent: Libkolab-3.0.0 Content-Type: multipart/mixed; boundary="nextPart3915010.RBqxP67orN" Subject: KOrganizer-1353608432.168 MIME-Version: 1.0
View file
libkolab-2.0.tar.gz/tests/testfiles/v2/event/simple.ics.mime -> libkolab-3.0.0.tar.gz/tests/testfiles/v2/event/simple.ics.mime
Changed
@@ -1,6 +1,6 @@ Date: Tue, 01 Sep 2009 13:36:50 +0200 X-Kolab-Type: application/x-vnd.kolab.event -User-Agent: Akonadi Kolab Proxy Resource +User-Agent: Libkolab-3.0.0 Content-Type: multipart/mixed; boundary="nextPart3915010.RBqxP67orN" Subject: KOrganizer-1353608432.168 MIME-Version: 1.0
View file
libkolab-2.0.tar.gz/tests/testfiles/v2/event/simple_missingTypeHeader.ics.mime -> libkolab-3.0.0.tar.gz/tests/testfiles/v2/event/simple_missingTypeHeader.ics.mime
Changed
@@ -1,5 +1,5 @@ Date: Tue, 01 Sep 2009 13:36:50 +0200 -User-Agent: Akonadi Kolab Proxy Resource +User-Agent: Libkolab-3.0.0 Content-Type: multipart/mixed; boundary="nextPart3915010.RBqxP67orN" Subject: KOrganizer-1353608432.168 MIME-Version: 1.0
View file
libkolab-2.0.tar.gz/tests/testfiles/v2/journal/complex.ics.mime -> libkolab-3.0.0.tar.gz/tests/testfiles/v2/journal/complex.ics.mime
Changed
@@ -1,6 +1,6 @@ Date: Tue, 01 Sep 2009 17:00:13 +0200 X-Kolab-Type: application/x-vnd.kolab.journal -User-Agent: Akonadi Kolab Proxy Resource +User-Agent: Libkolab-3.0.0 Content-Type: multipart/mixed; boundary="nextPart1324738.3KhudssxDn" Subject: KOrganizer-2037616327.585 MIME-Version: 1.0
View file
libkolab-2.0.tar.gz/tests/testfiles/v2/journal/simple.ics.mime -> libkolab-3.0.0.tar.gz/tests/testfiles/v2/journal/simple.ics.mime
Changed
@@ -1,6 +1,6 @@ Date: Tue, 01 Sep 2009 16:58:01 +0200 X-Kolab-Type: application/x-vnd.kolab.journal -User-Agent: Akonadi Kolab Proxy Resource +User-Agent: Libkolab-3.0.0 Content-Type: multipart/mixed; boundary="nextPart5948088.KInc4Inoe4" Subject: KOrganizer-1941104064.609 MIME-Version: 1.0
View file
libkolab-2.0.tar.gz/tests/testfiles/v2/task/complex.ics.mime -> libkolab-3.0.0.tar.gz/tests/testfiles/v2/task/complex.ics.mime
Changed
@@ -1,6 +1,6 @@ Date: Tue, 01 Sep 2009 15:39:19 +0200 X-Kolab-Type: application/x-vnd.kolab.task -User-Agent: Akonadi Kolab Proxy Resource +User-Agent: Libkolab-3.0.0 Content-Type: multipart/mixed; boundary="nextPart1580071.CkrsaYjaUZ" Subject: KOrganizer-396756838.184 MIME-Version: 1.0
View file
libkolab-2.0.tar.gz/tests/testfiles/v2/task/prioritytest1.ics.mime -> libkolab-3.0.0.tar.gz/tests/testfiles/v2/task/prioritytest1.ics.mime
Changed
@@ -1,6 +1,6 @@ Date: Tue, 01 Sep 2009 15:17:09 +0200 X-Kolab-Type: application/x-vnd.kolab.task -User-Agent: Akonadi Kolab Proxy Resource +User-Agent: Libkolab-3.0.0 Content-Type: multipart/mixed; boundary="nextPart1959111.QQxQ0WGgtU" Subject: KOrganizer-2105012348.490 MIME-Version: 1.0
View file
libkolab-2.0.tar.gz/tests/testfiles/v2/task/prioritytest2.ics.mime -> libkolab-3.0.0.tar.gz/tests/testfiles/v2/task/prioritytest2.ics.mime
Changed
@@ -1,6 +1,6 @@ Date: Tue, 01 Sep 2009 15:17:09 +0200 X-Kolab-Type: application/x-vnd.kolab.task -User-Agent: Akonadi Kolab Proxy Resource +User-Agent: Libkolab-3.0.0 Content-Type: multipart/mixed; boundary="nextPart1959111.QQxQ0WGgtU" Subject: KOrganizer-2105012348.490 MIME-Version: 1.0
View file
libkolab-2.0.tar.gz/tests/testfiles/v2/task/simple.ics.mime -> libkolab-3.0.0.tar.gz/tests/testfiles/v2/task/simple.ics.mime
Changed
@@ -1,6 +1,6 @@ Date: Tue, 01 Sep 2009 15:17:09 +0200 X-Kolab-Type: application/x-vnd.kolab.task -User-Agent: Akonadi Kolab Proxy Resource +User-Agent: Libkolab-3.0.0 Content-Type: multipart/mixed; boundary="nextPart1959111.QQxQ0WGgtU" Subject: KOrganizer-2105012348.490 MIME-Version: 1.0
View file
libkolab-2.0.tar.gz/tests/testfiles/v3/note/note.mime.mime -> libkolab-3.0.0.tar.gz/tests/testfiles/v3/note/note.mime.mime
Changed
@@ -22,7 +22,7 @@ Content-Disposition: attachment; filename="kolab.xml" <?xml version=3D"1.0" encoding=3D"UTF-8" standalone=3D"no" ?> -<note xmlns=3D"http://kolab.org" version=3D"3.0dev1"> +<note xmlns=3D"http://kolab.org" version=3D"3.0"> <uid>c04ad759-ff7f-0000-e12b-a41f537f0000</uid>
View file
libkolab-2.0.tar.gz/tests/testhelpers.h -> libkolab-3.0.0.tar.gz/tests/testhelpers.h
Changed
@@ -18,7 +18,7 @@ #ifndef TESTHELPERS_H #define TESTHELPERS_H -#include <contact.h> +// #include <contact.h> #include <QtCore/QObject> #include <QtTest/QtTest> @@ -26,7 +26,6 @@ #include <kcalcore/event.h> #include <kcalcore/todo.h> #include <kcalcore/journal.h> -#include <kabc/addressee.h> #include <kolabformat.h> @@ -45,10 +44,6 @@ Q_DECLARE_METATYPE(KCalCore::Todo); Q_DECLARE_METATYPE(KCalCore::Journal); -#ifndef LIBCALENDARING_DURATION_DECLARED - Q_DECLARE_METATYPE(KCalCore::Duration); -#endif - namespace QTest { template<> @@ -57,33 +52,33 @@ QByteArray ba = "Kolab::cDateTime("; ba += QByteArray::number(dt.year()) + ", " + QByteArray::number(dt.month())+ ", " + QByteArray::number(dt.day()) + ", "; ba += QByteArray::number(dt.hour()) + ", " + QByteArray::number(dt.minute()) + ", " + QByteArray::number(dt.second())+ ", "; - ba += QString(dt.isUTC()?QString("UTC"):QString("TZ: "+QString::fromStdString(dt.timezone()))).toAscii(); + ba += QByteArray(dt.isUTC()?QByteArray("UTC"):QByteArray("TZ: "+QByteArray::fromStdString(dt.timezone()))); ba += ")"; return qstrdup(ba.data()); } - template<> - char *toString(const KDateTime &dt) - { - QByteArray ba = "KDateTime("; - ba += dt.toString().toAscii(); - ba += dt.timeZone().name(); - ba += ")"; - return qstrdup(ba.data()); - } + // template<> + // char *toString(const QDateTime &dt) + // { + // QByteArray ba = "QDateTime("; + // ba += dt.toString().toAscii(); + // ba += dt.timeZone().name().toAscii(); + // ba += ")"; + // return qstrdup(ba.data()); + // } template<> char *toString(const KCalCore::Attendee &at) { QByteArray ba = "Attendee("; - ba += at.name().toAscii() + ", "; - ba += at.email().toAscii() + ", "; - ba += QString::number(at.role()) + ", "; - ba += QString::number(at.status()) + ", "; - ba += QString::number(at.RSVP()) + ", "; - ba += at.delegate().toAscii() + ", "; - ba += at.delegator().toAscii() + ", "; - ba += at.uid().toAscii() + ", "; + ba += at.name().toLatin1() + ", "; + ba += at.email().toLatin1() + ", "; + ba += QByteArray::number(at.role()) + ", "; + ba += QByteArray::number(at.status()) + ", "; + ba += QByteArray::number(at.RSVP()) + ", "; + ba += at.delegate().toLatin1() + ", "; + ba += at.delegator().toLatin1() + ", "; + ba += at.uid().toLatin1() + ", "; ba += ")"; return qstrdup(ba.data()); } @@ -94,7 +89,7 @@ { QByteArray ba = "QList<int>("; foreach(int i, l) { - ba += QString::number(i) + ", "; + ba += QByteArray::number(i) + ", "; } ba += ")"; return qstrdup(ba.data()); @@ -105,8 +100,8 @@ { QByteArray ba = "QList<int>("; foreach(const KCalCore::RecurrenceRule::WDayPos &i, l) { - ba += QString::number(i.pos()) + " "; - ba += QString::number(i.day()) + ", "; + ba += QByteArray::number(i.pos()) + " "; + ba += QByteArray::number(i.day()) + ", "; } ba += ")"; return qstrdup(ba.data()); @@ -117,7 +112,7 @@ { QByteArray ba = "KCalCore::DateList("; foreach(const QDate &i, l) { - ba += i.toString(); + ba += i.toString().toLatin1(); } ba += ")"; return qstrdup(ba.data()); @@ -127,7 +122,7 @@ char *toString(const KCalCore::DateTimeList &l) { QByteArray ba = "KCalCore::DateTimeList("; - foreach(const KDateTime &i, l) { + foreach(const QDateTime &i, l) { ba += toString(i); } ba += ")"; @@ -137,7 +132,7 @@ template<> char *toString(const KCalCore::Recurrence &at) { - at.dump(); + // at.dump(); KCalCore::RecurrenceRule *r = at.defaultRRule(); QByteArray ba; if (!r) { @@ -147,9 +142,9 @@ Q_ASSERT(at.rRules().size() == 1); ba += "Recurrence("; - ba += QString::number(r->recurrenceType()) + "\n"; - ba += QString::number(r->frequency()) + "\n"; - ba += QString::number(r->duration()) + "\n"; + ba += QByteArray::number(r->recurrenceType()) + "\n"; + ba += QByteArray::number(r->frequency()) + "\n"; + ba += QByteArray::number(r->duration()) + "\n"; ba += QByteArray(toString(r->startDt())) + "\n"; ba += QByteArray(toString(r->endDt())) + "\n"; ba += QByteArray(toString(r->bySeconds())) + "\n"; @@ -174,10 +169,10 @@ { QByteArray ba; ba += "KolabRecurrenceRule("; - ba += QString::number(at.weekStart()) + "\n"; - ba += QString::number(at.frequency()) + "\n"; - ba += QString::number(at.interval()) + "\n"; - ba += QString::number(at.count()) + "\n"; + ba += QByteArray::number(at.weekStart()) + "\n"; + ba += QByteArray::number(at.frequency()) + "\n"; + ba += QByteArray::number(at.interval()) + "\n"; + ba += QByteArray::number(at.count()) + "\n"; ba += QByteArray(toString(at.end())) + "\n"; ba += QByteArray(toString(at.bysecond())) + "\n"; ba += QByteArray(toString(at.byminute())) + "\n"; @@ -196,8 +191,8 @@ { QByteArray ba; ba += "KCalCore::Duration("; - ba += QString::number(d.isDaily()) + ", "; - ba += QString::number(d.value()) + " "; + ba += QByteArray::number(d.isDaily()) + ", "; + ba += QByteArray::number(d.value()) + " "; ba += ")"; return qstrdup(ba.data()); } @@ -206,9 +201,9 @@ char *toString(const Kolab::ContactReference &a) { QByteArray ba = "Kolab::ContactReference("; - ba += QString::fromStdString(a.email()).toAscii()+ ", "; - ba += QString::fromStdString(a.name()).toAscii()+ ", "; - ba += QString::fromStdString(a.uid()).toAscii(); + ba += QByteArray::fromStdString(a.email()) + ", "; + ba += QByteArray::fromStdString(a.name()) + ", "; + ba += QByteArray::fromStdString(a.uid()); ba += ")"; return qstrdup(ba.data()); } @@ -228,12 +223,12 @@ char *toString(const Kolab::Attendee &a) { QByteArray ba = "Kolab::Attendee("; - ba += QString::fromStdString(a.contact().email()).toAscii() + "\n"; - ba += QString::fromStdString(a.contact().name()).toAscii()+ "\n"; + ba += QByteArray::fromStdString(a.contact().email()) + "\n"; + ba += QByteArray::fromStdString(a.contact().name()) + "\n"; ba += QByteArray::number(a.partStat()) + "\n"; ba += QByteArray::number(a.role()) + "\n"; ba += QByteArray::number(a.rsvp()) + "\n"; - ba += QString::fromStdString(a.contact().uid()).toAscii()+"\n"; + ba += QByteArray::fromStdString(a.contact().uid())+"\n"; ba += QByteArray(toString(a.delegatedTo()))+"\n"; ba += QByteArray(toString(a.delegatedFrom()))+ "\n"; ba += QByteArray::number(a.cutype())+ "\n"; @@ -257,8 +252,8 @@ char *toString(const Kolab::CustomProperty &a) { QByteArray ba = "Kolab::CustomProperty("; - ba += QString::fromStdString(a.identifier).toAscii()+ ", "; - ba += QString::fromStdString(a.value).toAscii(); + ba += QByteArray::fromStdString(a.identifier) + ", "; + ba += QByteArray::fromStdString(a.value); ba += ")"; return qstrdup(ba.data()); } @@ -299,10 +294,10 @@ char *toString(const Kolab::FreebusyPeriod &p) { QByteArray ba = "Kolab::FreebusyPeriod("; - ba += QString::number(p.type())+ "\n"; - ba += QString::fromStdString(p.eventUid())+ "\n"; - ba += QString::fromStdString(p.eventLocation())+ "\n"; - ba += QString::fromStdString(p.eventSummary())+ "\n"; + ba += QByteArray::number(p.type())+ "\n"; + ba += QByteArray::fromStdString(p.eventUid())+ "\n"; + ba += QByteArray::fromStdString(p.eventLocation())+ "\n"; + ba += QByteArray::fromStdString(p.eventSummary())+ "\n"; ba += QByteArray(toString(p.periods()))+ "\n"; ba += ")"; return qstrdup(ba.data()); @@ -314,11 +309,11 @@ QByteArray ba = "Kolab::Duration"; ba += p.isNegative() ? "-": "+"; ba += "("; - ba += QString::number(p.weeks())+ ", "; - ba += QString::number(p.days())+ ", "; - ba += QString::number(p.hours())+ ", "; - ba += QString::number(p.minutes())+ ", "; - ba += QString::number(p.seconds()); + ba += QByteArray::number(p.weeks())+ ", "; + ba += QByteArray::number(p.days())+ ", "; + ba += QByteArray::number(p.hours())+ ", "; + ba += QByteArray::number(p.minutes())+ ", "; + ba += QByteArray::number(p.seconds()); ba += ")"; return qstrdup(ba.data()); }
View file
libkolab-2.0.tar.gz/tests/testutils.h -> libkolab-3.0.0.tar.gz/tests/testutils.h
Changed
@@ -21,20 +21,19 @@ #include <qtemporaryfile.h> #include <qprocess.h> #include <quuid.h> -#include <kdebug.h> #include <kolabevent.h> #include <kmime/kmime_message.h> -#include "kolabformat/kolabobject.h" +// #include "kolabformat/kolabobject.h" -Q_DECLARE_METATYPE(Kolab::ObjectType); -Q_DECLARE_METATYPE(Kolab::Version); +// Q_DECLARE_METATYPE(Kolab::ObjectType); +// Q_DECLARE_METATYPE(Kolab::Version); #define KCOMPARE(actual, expected) \ do {\ if ( !(actual == expected) ) { \ - qDebug() << __FILE__ << ':' << __LINE__ << "Actual: " #actual ": " << actual << "\nExpceted: " #expected ": " << expected; \ + qDebug() << __FILE__ << ':' << __LINE__ << "Actual: " #actual ": " << actual << "\nExpected: " #expected ": " << expected; \ return false; \ } \ } while (0) @@ -42,6 +41,19 @@ #endif +#define DIFFCOMPARE(actual, expected) \ +do {\ + if ( !(actual.simplified() == expected.simplified()) ) { \ + qDebug() << "Content not the same."; \ + showDiff(expected, actual); \ + QTest::qFail("Compared versions differ.", __FILE__, __LINE__); \ + return; \ + } \ +} while (0) + +#define TESTVALUE(type, name)\ + *static_cast<type *>(QTest::qData(#name, ::qMetaTypeId<type >())) + const QString TESTFILEDIR = QString::fromLatin1(TEST_DATA_PATH "/testfiles/"); QString getPath(const char *file) { @@ -51,27 +63,31 @@ void showDiff(const QString &expected, const QString &converted) { if (expected.isEmpty() || converted.isEmpty()) { - kWarning() << "files are emtpy"; + qWarning() << "files are emtpy"; return; } if (expected == converted) { - kWarning() << "contents are the same"; + qWarning() << "contents are the same"; return; } - // QTemporaryFile expectedFile("expectedFile"); - // QTemporaryFile convertedFile("convertedFile"); - // if (expectedFile.open() && convertedFile.open()) { - // expectedFile.write(expected.toLatin1()); - // convertedFile.write(converted.toLatin1()); - // expectedFile.close(); - // convertedFile.close(); - // QProcess::execute("kompare", QStringList() << "-c" << expectedFile.fileName() << convertedFile.fileName()); - // } else { - // kWarning() << "files are not open"; - // } - - qDebug() << "EXPECTED: " << expected; - qDebug() << "CONVERTED: " << converted; + + bool showDiff = true; + if (showDiff) { + QTemporaryFile expectedFile("expectedFile"); + QTemporaryFile convertedFile("convertedFile"); + if (expectedFile.open() && convertedFile.open()) { + expectedFile.write(expected.toLatin1()); + convertedFile.write(converted.toLatin1()); + expectedFile.close(); + convertedFile.close(); + QProcess::execute("kdiff3", QStringList() << expectedFile.fileName() << convertedFile.fileName()); + } else { + qWarning() << "files are not open"; + } + } else { + qDebug() << "EXPECTED: " << expected; + qDebug() << "CONVERTED: " << converted; + } } KMime::Message::Ptr readMimeFile( const QString &fileName, bool &ok) @@ -80,7 +96,7 @@ QFile file( fileName ); ok = file.open( QFile::ReadOnly ); if (!ok) { - kWarning() << "failed to open file: " << fileName; + qWarning() << "failed to open file: " << fileName; return KMime::Message::Ptr(); } const QByteArray data = file.readAll(); @@ -100,36 +116,51 @@ content.replace(QRegExp("\\bLibkolab-\\d.\\d\\b", Qt::CaseSensitive), "Libkolab-x.x.x"); content.replace(QRegExp("\\bLibkolabxml-\\d.\\d\\b", Qt::CaseSensitive), "Libkolabxml-x.x.x"); content.replace(QRegExp("<uri>cid:*@kolab.resource.akonadi</uri>", Qt::CaseSensitive, QRegExp::Wildcard), "<uri>cid:id@kolab.resource.akonadi</uri>"); + content.replace(QRegExp("Content-ID: <*@kolab.resource.akonadi>", Qt::CaseSensitive, QRegExp::Wildcard), "Content-ID: <id@kolab.resource.akonadi>"); content.replace(QRegExp("<uri>mailto:*</uri>", Qt::CaseSensitive, QRegExp::Wildcard), "<uri>mailto:</uri>"); content.replace(QRegExp("<cal-address>mailto:*</cal-address>", Qt::CaseSensitive, QRegExp::Wildcard), "<cal-address>mailto:</cal-address>"); content.replace(QRegExp("<uri>data:*</uri>", Qt::CaseSensitive, QRegExp::Wildcard), "<uri>data:</uri>"); content.replace(QRegExp("<last-modification-date>*</last-modification-date>", Qt::CaseSensitive, QRegExp::Wildcard), "<last-modification-date></last-modification-date>"); + //We no longer support pobox, so remove pobox lines + content.replace(QRegExp("<pobox>*</pobox>", Qt::CaseSensitive, QRegExp::Wildcard), ""); content.replace(QRegExp("<timestamp>*</timestamp>", Qt::CaseSensitive, QRegExp::Wildcard), "<timestamp></timestamp>"); content.replace(QRegExp("<x-kolab-version>*</x-kolab-version>", Qt::CaseSensitive, QRegExp::Wildcard), "<x-kolab-version></x-kolab-version>"); content.replace(QRegExp("--nextPart\\S*", Qt::CaseSensitive), "--part"); content.replace(QRegExp("\\bboundary=\"nextPart[^\\n]*", Qt::CaseSensitive), "boundary"); content.replace(QRegExp("Date[^\\n]*", Qt::CaseSensitive), "Date"); + //The sort order of the attributes in kolabV2 is unpredictable + content.replace(QRegExp("<x-custom*/>", Qt::CaseSensitive, QRegExp::Wildcard), "<x-custom/>"); + //quoted-printable encoding changes where the linebreaks are every now and then (an all are valid), so we remove the linebreaks + content.replace(QRegExp("=\\n", Qt::CaseSensitive), ""); } +//QString normalizeVCardMessage(QString content) +//{ +// //The encoding changes every now and then +// content.replace(QRegExp("ENCODING=b;TYPE=png:*", Qt::CaseSensitive, QRegExp::Wildcard), "ENCODING=b;TYPE=png:picturedata"); +// return content; +//} -//Normalize incidences for comparison -void normalizeIncidence( KCalCore::Incidence::Ptr incidence) -{ - //The UID is not persistent (it's just the internal pointer), therefore we clear it - //TODO make sure that the UID does really not need to be persistent - foreach(KCalCore::Attendee::Ptr attendee, incidence->attendees()) { - attendee->setUid(QString()); - } - //FIXME even if hasDueDate can differ, it shouldn't because it breaks equality. Check why they differ in the first place. - if ( incidence->type() == KCalCore::IncidenceBase::TypeTodo ) { - KCalCore::Todo::Ptr todo = incidence.dynamicCast<KCalCore::Todo>(); - Q_ASSERT(todo.data()); - if ( !todo->hasDueDate() && !todo->hasStartDate() ) - todo->setAllDay( false ); // all day has no meaning if there are no start and due dates but may differ nevertheless - } -} +//Normalize incidences for comparison +//void normalizeIncidence( KCalCore::Incidence::Ptr incidence) +//{ +// //The UID is not persistent (it's just the internal pointer), therefore we clear it +// //TODO make sure that the UID does really not need to be persistent +// ////FIXME +// foreach(KCalCore::Attendee attendee, incidence->attendees()) { +// attendee.setUid(QString()); +// } + +// //FIXME even if hasDueDate can differ, it shouldn't because it breaks equality. Check why they differ in the first place. +// if ( incidence->type() == KCalCore::IncidenceBase::TypeTodo ) { +// KCalCore::Todo::Ptr todo = incidence.dynamicCast<KCalCore::Todo>(); +// Q_ASSERT(todo.data()); +// if ( !todo->hasDueDate() && !todo->hasStartDate() ) +// todo->setAllDay( false ); // all day has no meaning if there are no start and due dates but may differ nevertheless +// } +//} template <template <typename> class Op, typename T> static bool LexicographicalCompare( const T &_x, const T &_y ) @@ -142,75 +173,75 @@ return op( x.toString(), y.toString() ); } -bool normalizePhoneNumbers( KABC::Addressee &addressee, KABC::Addressee &refAddressee ) -{ - KABC::PhoneNumber::List phoneNumbers = addressee.phoneNumbers(); - KABC::PhoneNumber::List refPhoneNumbers = refAddressee.phoneNumbers(); - if ( phoneNumbers.size() != refPhoneNumbers.size() ) - return false; - std::sort( phoneNumbers.begin(), phoneNumbers.end(), LexicographicalCompare<std::less, KABC::PhoneNumber> ); - std::sort( refPhoneNumbers.begin(), refPhoneNumbers.end(), LexicographicalCompare<std::less, KABC::PhoneNumber> ); - - for ( int i = 0; i < phoneNumbers.size(); ++i ) { - KABC::PhoneNumber phoneNumber = phoneNumbers.at( i ); - const KABC::PhoneNumber refPhoneNumber = refPhoneNumbers.at( i ); - KCOMPARE( LexicographicalCompare<std::equal_to>( phoneNumber, refPhoneNumber ), true ); - addressee.removePhoneNumber( phoneNumber ); - phoneNumber.setId( refPhoneNumber.id() ); - addressee.insertPhoneNumber( phoneNumber ); - //Make sure that both have the same sorted order - refAddressee.removePhoneNumber( refPhoneNumber ); - refAddressee.insertPhoneNumber( refPhoneNumber ); - } -// for ( int i = 0; i < phoneNumbers.size(); ++i ) { -// kDebug() << "--------------------------------------"; -// kDebug() << addressee.phoneNumbers().at(i).toString(); -// kDebug() << refAddressee.phoneNumbers().at(i).toString(); -// } - - return true; -} - -bool normalizeAddresses( KABC::Addressee &addressee, const KABC::Addressee &refAddressee ) -{ - KABC::Address::List addresses = addressee.addresses(); - KABC::Address::List refAddresses = refAddressee.addresses(); - if ( addresses.size() != refAddresses.size() ) - return false; - std::sort( addresses.begin(), addresses.end(), LexicographicalCompare<std::less, KABC::Address> ); - std::sort( refAddresses.begin(), refAddresses.end(), LexicographicalCompare<std::less, KABC::Address> ); - - for ( int i = 0; i < addresses.size(); ++i ) { - KABC::Address address = addresses.at( i ); - const KABC::Address refAddress = refAddresses.at( i ); - KCOMPARE( LexicographicalCompare<std::equal_to>( address, refAddress ), true ); - addressee.removeAddress( address ); - address.setId( refAddress.id() ); - addressee.insertAddress( address ); - } - - return true; -} - -void normalizeContact(KABC::Addressee &addressee) -{ - KABC::Address::List addresses = addressee.addresses(); +//bool normalizePhoneNumbers( KContacts::Addressee &addressee, KContacts::Addressee &refAddressee ) +//{ +// KContacts::PhoneNumber::List phoneNumbers = addressee.phoneNumbers(); +// KContacts::PhoneNumber::List refPhoneNumbers = refAddressee.phoneNumbers(); +// if ( phoneNumbers.size() != refPhoneNumbers.size() ) +// return false; +// std::sort( phoneNumbers.begin(), phoneNumbers.end(), LexicographicalCompare<std::less, KContacts::PhoneNumber> ); +// std::sort( refPhoneNumbers.begin(), refPhoneNumbers.end(), LexicographicalCompare<std::less, KContacts::PhoneNumber> ); + +// for ( int i = 0; i < phoneNumbers.size(); ++i ) { +// KContacts::PhoneNumber phoneNumber = phoneNumbers.at( i ); +// const KContacts::PhoneNumber refPhoneNumber = refPhoneNumbers.at( i ); +// KCOMPARE( LexicographicalCompare<std::equal_to>( phoneNumber, refPhoneNumber ), true ); +// addressee.removePhoneNumber( phoneNumber ); +// phoneNumber.setId( refPhoneNumber.id() ); +// addressee.insertPhoneNumber( phoneNumber ); +// //Make sure that both have the same sorted order +// refAddressee.removePhoneNumber( refPhoneNumber ); +// refAddressee.insertPhoneNumber( refPhoneNumber ); +// } +//// for ( int i = 0; i < phoneNumbers.size(); ++i ) { +//// qDebug() << "--------------------------------------"; +//// qDebug() << addressee.phoneNumbers().at(i).toString(); +//// qDebug() << refAddressee.phoneNumbers().at(i).toString(); +//// } + +// return true; +//} + +//bool normalizeAddresses( KContacts::Addressee &addressee, const KContacts::Addressee &refAddressee ) +//{ +// KContacts::Address::List addresses = addressee.addresses(); +// KContacts::Address::List refAddresses = refAddressee.addresses(); +// if ( addresses.size() != refAddresses.size() ) +// return false; +// std::sort( addresses.begin(), addresses.end(), LexicographicalCompare<std::less, KContacts::Address> ); +// std::sort( refAddresses.begin(), refAddresses.end(), LexicographicalCompare<std::less, KContacts::Address> ); + +// for ( int i = 0; i < addresses.size(); ++i ) { +// KContacts::Address address = addresses.at( i ); +// const KContacts::Address refAddress = refAddresses.at( i ); +// KCOMPARE( LexicographicalCompare<std::equal_to>( address, refAddress ), true ); +// addressee.removeAddress( address ); +// address.setId( refAddress.id() ); +// addressee.insertAddress( address ); +// } + +// return true; +//} + +//void normalizeContact(KContacts::Addressee &addressee) +//{ +// KContacts::Address::List addresses = addressee.addresses(); - foreach(KABC::Address a, addresses) { - addressee.removeAddress(a); - a.setPostOfficeBox(QString()); //Not supported anymore - addressee.insertAddress(a); - } - addressee.setSound(KABC::Sound()); //Sound is not supported +// foreach(KContacts::Address a, addresses) { +// addressee.removeAddress(a); +// a.setPostOfficeBox(QString()); //Not supported anymore +// addressee.insertAddress(a); +// } +// addressee.setSound(KContacts::Sound()); //Sound is not supported - addressee.removeCustom("KOLAB", "CreationDate"); //The creation date is no longer existing +// addressee.removeCustom("KOLAB", "CreationDate"); //The creation date is no longer existing - //Attachment names are no longer required because we identify the parts by cid and no longer by name - addressee.removeCustom("KOLAB", "LogoAttachmentName"); - addressee.removeCustom("KOLAB", "PictureAttachmentName"); - addressee.removeCustom("KOLAB", "SoundAttachmentName"); +// //Attachment names are no longer required because we identify the parts by cid and no longer by name +// addressee.removeCustom("KOLAB", "LogoAttachmentName"); +// addressee.removeCustom("KOLAB", "PictureAttachmentName"); +// addressee.removeCustom("KOLAB", "SoundAttachmentName"); -} +//} Kolab::Event createEvent(const Kolab::cDateTime &start, const Kolab::cDateTime &end) {
View file
libkolab-2.0.tar.gz/tests/timezonetest.cpp -> libkolab-3.0.0.tar.gz/tests/timezonetest.cpp
Changed
@@ -18,45 +18,17 @@ #include "timezonetest.h" #include <conversion/timezoneconverter.h> #include <conversion/commonconversion.h> -#include <kolabformat/kolabobject.h> +// #include <kolabformat/kolabobject.h> #include <kolabformat/errorhandler.h> #include "testutils.h" #include <QTest> -// #include <unicode/uversion.h> -// #include <unicode/timezone.h> -// #include <iostream> -#include <kdebug.h> #include <kcalcore/event.h> #include <kcalcore/icalformat.h> -#include <ksystemtimezone.h> - -// void icuFoo() -// { -// icu::UnicodeString s; -// UErrorCode error; -// // icu::TimeZone::getCanonicalID("GMT+01.00) Sarajevo/Warsaw/Zagreb", s, error); -// // icu::TimeZone::getCanonicalID(icu::UnicodeString::fromUTF8("Europe/Zurich"), s, error); -// icu::TimeZone::getCanonicalID(icu::UnicodeString::fromUTF8("GMT+01.00"), s, error); -// std::string cs; -// s.toUTF8String(cs); -// std::cout << "This is the new timezone: " << cs << std::endl << u_errorName(error) << std::endl; -// // -// // -// // icu::TimeZone *tz = icu::TimeZone::createTimeZone("GMT-8:00"); -// // icu::UnicodeString result; -// // tz->getDisplayName(result); -// // std::string stringresult; -// // result.toUTF8String(stringresult); -// // std::cout << stringresult; -// -// // icu::TimeZone *tz = icu::TimeZone::getStaticClassID(); -// -// } +#include <QTimeZone> void TimezoneTest::initTestCase() { - QVERIFY2(KSystemTimeZones::isTimeZoneDaemonAvailable(), "Timezone support is required for this test. Either use libcalendaring or make sure KTimeZoned is available"); } void TimezoneTest::testFromName() @@ -95,22 +67,22 @@ TimezoneConverter converter; QFETCH(QString, timezone); const QString tz = converter.normalizeTimezone(timezone); - kDebug() << tz; + qDebug() << tz; QVERIFY(!tz.isEmpty()); QVERIFY(tz != timezone); } -void TimezoneTest::testKolabObjectWriter() -{ - KCalCore::Event::Ptr event(new KCalCore::Event()); - event->setOrganizer(KCalCore::Person::Ptr()); - event->setDtStart(KDateTime(QDate(2012,11,11), QTime(1,1), KDateTime::Spec(KTimeZone("(GMT+01:00) West Central Africa")))); - KMime::Message::Ptr msg = Kolab::KolabObjectWriter::writeEvent(event); - Kolab::KolabObjectReader reader(msg); - KCalCore::Event::Ptr result = reader.getEvent(); - kDebug() << result->dtStart().timeZone().name(); - QCOMPARE(result->dtStart().timeZone().name(), KTimeZone(QLatin1String("Africa/Lagos")).name()); -} +// void TimezoneTest::testKolabObjectWriter() +// { +// KCalCore::Event::Ptr event(new KCalCore::Event()); +// event->setOrganizer(KCalCore::Person::Ptr()); +// event->setDtStart(QDateTime(QDate(2012,11,11), QTime(1,1), QTimeZone("(GMT+01:00) West Central Africa"))); +// KMime::Message::Ptr msg = Kolab::KolabObjectWriter::writeEvent(event); +// Kolab::KolabObjectReader reader(msg); +// KCalCore::Event::Ptr result = reader.getEvent(); +// qDebug() << result->dtStart().timeZone().name(); +// QCOMPARE(result->dtStart().timeZone().name(), QTimeZone(QLatin1String("Africa/Lagos")).id()); +// } // void TimezoneTest::testKolabObjectReader() // { @@ -130,7 +102,7 @@ // QCOMPARE(Kolab::ErrorHandler::instance().error(), Kolab::ErrorHandler::Debug); // // KCalCore::Incidence::Ptr convertedIncidence = reader.getIncidence(); -// kDebug() << "read incidence"; +// qDebug() << "read incidence"; // // //Parse ICalFile for comparison // QFile icalFile( icalFileName ); @@ -159,7 +131,7 @@ void TimezoneTest::testFindLegacyTimezone() { const QString normalized = TimezoneConverter::normalizeTimezone("US/Pacific"); - kDebug() << normalized; + qDebug() << normalized; QEXPECT_FAIL("", "Currently broken", Continue); QVERIFY(!normalized.isEmpty()); } @@ -167,20 +139,14 @@ void TimezoneTest::testIgnoreInvalidTimezone() { const QString normalized = TimezoneConverter::normalizeTimezone("FOOOOBAR"); - kDebug() << normalized; + qDebug() << normalized; QVERIFY(normalized.isEmpty()); } -void TimezoneTest::testTimezoneDaemonAvailable() -{ - //With KDE it should be available and with libcalendaring it should return true - QVERIFY(KSystemTimeZones::isTimeZoneDaemonAvailable()); -} - void TimezoneTest::testUTCOffset() { const Kolab::cDateTime expected(2013, 10, 23, 2, 0 ,0, true); - const KDateTime input(KDateTime::fromString("2013-10-23T04:00:00+02:00", KDateTime::RFC3339Date)); + const QDateTime input(QDateTime::fromString("2013-10-23T04:00:00+02:00", Qt::ISODate)); const Kolab::cDateTime result = Kolab::Conversion::fromDate(input); QVERIFY(!Kolab::ErrorHandler::instance().errorOccured()); QCOMPARE(result, expected); @@ -188,24 +154,25 @@ void TimezoneTest::localTimezone() { + // { + // const Kolab::cDateTime result = Kolab::Conversion::fromDate(QDateTime(QDate(2013, 10, 10), QTime(2, 0, 0), Qt::LocalZone)); + // QVERIFY(!result.timezone().empty()); + // QVERIFY(!Kolab::ErrorHandler::instance().errorOccured()); + // } { - const Kolab::cDateTime result = Kolab::Conversion::fromDate(KDateTime(QDate(2013, 10, 10), QTime(2, 0, 0), KDateTime::LocalZone)); - QVERIFY(!result.timezone().empty()); - QVERIFY(!Kolab::ErrorHandler::instance().errorOccured()); - } - { - const Kolab::cDateTime result = Kolab::Conversion::fromDate(KDateTime(QDate(2013, 10, 10), QTime(2, 0, 0), KDateTime::ClockTime)); + const Kolab::cDateTime result = Kolab::Conversion::fromDate(QDateTime(QDate(2013, 10, 10), QTime(2, 0, 0), Qt::LocalTime)); + QVERIFY(result.timezone().empty()); QVERIFY(!Kolab::ErrorHandler::instance().errorOccured()); } { - const Kolab::cDateTime result = Kolab::Conversion::fromDate(KDateTime(QDate(2013, 10, 10), QTime(2, 0, 0), KDateTime::TimeZone)); + const Kolab::cDateTime result = Kolab::Conversion::fromDate(QDateTime(QDate(2013, 10, 10), QTime(2, 0, 0), Qt::TimeZone)); QVERIFY(result.timezone().empty()); QVERIFY(!Kolab::ErrorHandler::instance().errorOccured()); } { - KDateTime dt(QDate(2013, 10, 10), QTime(2, 0, 0), KTimeZone("/etc/localzone")); + QDateTime dt(QDate(2013, 10, 10), QTime(2, 0, 0), QTimeZone("/etc/localzone")); const Kolab::cDateTime result = Kolab::Conversion::fromDate(dt); - kDebug() << result.timezone(); + qDebug() << result.timezone(); QVERIFY(result.timezone().empty()); QVERIFY(!Kolab::ErrorHandler::instance().errorOccured()); }
View file
libkolab-2.0.tar.gz/tests/timezonetest.h -> libkolab-3.0.0.tar.gz/tests/timezonetest.h
Changed
@@ -31,11 +31,8 @@ void testFromName(); void testFromHardcodedList_data(); void testFromHardcodedList(); - void testKolabObjectWriter(); - // void testKolabObjectReader(); void testFindLegacyTimezone(); void testIgnoreInvalidTimezone(); - void testTimezoneDaemonAvailable(); void testUTCOffset(); void localTimezone(); };
View file
libkolab.dsc
Changed
@@ -1,8 +1,8 @@ Format: 1.0 Source: libkolab -Binary: libkolab2, php-kolab, python-kolab, libkolab-dev +Binary: libkolab3, php-kolab, python-kolab, libkolab-dev Architecture: any -Version: 2.0~dev20151230-0~kolab16 +Version: 3.0~dev20151230-0~kolab16 Maintainer: Jeroen van Meeuwen <vanmeeuwen@kolabsys.com> Uploaders: Jeroen van Meeuwen <vanmeeuwen@kolabsys.com> Homepage: http://git.kolab.org/libkolab @@ -10,15 +10,16 @@ Build-Depends: cmake, debhelper, + libcurl4-gnutls-dev, libboost-dev, - libboost-program-options-dev, libboost-thread-dev, libboost-system-dev, - libcalendaring-dev (>= 4.9.1), - libcurl4-gnutls-dev, libkolabxml-dev (>= 1.0), libossp-uuid-dev, - libqt4-dev, + qtbase5-dev, + libkf5coreaddons-dev, + libkf5calendarcore-dev, + libkf5mime-dev, libxerces-c-dev, php-cgi | php5-cli, php-dev | php5-dev, @@ -36,5 +37,5 @@ php-kolab deb libs optional python-kolab deb python optional Files: - 00000000000000000000000000000000 0 libkolab-2.0.tar.gz + 00000000000000000000000000000000 0 libkolab-3.0.0.tar.gz 00000000000000000000000000000000 0 debian.tar.gz
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.