Commit 22bc09c6 authored by Sergio Martins's avatar Sergio Martins

Remove duplicated code from the calendar dateengine.

This was using a copy of kdepim/calendarsupport stuff.
The calendaring libs are now in kdepimlibs and are much more stable
and nicer.

REVIEW: 109245
parent 7182bd33
......@@ -173,7 +173,7 @@ set_package_properties(Akonadi PROPERTIES DESCRIPTION "An extensible cross-deskt
PURPOSE "Required to build certain Plasma DataEngines (Akonadi, Calendar)"
)
macro_optional_find_package(KdepimLibs 4.5.60 QUIET CONFIG)
macro_optional_find_package(KdepimLibs 4.10.68 QUIET CONFIG)
set_package_properties(KdepimLibs PROPERTIES DESCRIPTION "The KDEPIM libraries"
URL "http://pim.kde.org"
TYPE OPTIONAL
......
......@@ -15,13 +15,6 @@ if(Akonadi_FOUND)
ADD_DEFINITIONS(-DAKONADI_FOUND)
set(calendar_engine_srcs ${calendar_engine_srcs}
eventdatacontainer.cpp
# taken from kdepim/akonadi/kcal as long as it's not yet exported:
akonadi/calendar.cpp
akonadi/calendarmodel.cpp
akonadi/calfilterproxymodel.cpp
akonadi/utils.cpp
akonadi/blockalarmsattribute.cpp
akonadi/collectionselection.cpp
)
endif(Akonadi_FOUND)
......@@ -40,6 +33,7 @@ target_link_libraries(
if(Akonadi_FOUND)
target_link_libraries(
plasma_engine_calendar
akonadi-calendar
${KDE4_AKONADI_LIBS}
${KDEPIMLIBS_AKONADI_KCAL_LIBS}
)
......
These files have been copied from trunk kdepim/calendarsupport as at 2011-02-27 and should be kept in sync for bug fixes.
Note that the exports have been removed from the headers, but no other changes have been made.
These classes will be moved from kdepim to kdepimlibs in KDE SC 4.7 and this copy should be deleted when this happens. At this time it is recommended to move the calendar events dataengine logic into the akonadi dataengine.
/*
Copyright (C) 2010 Klarälvdalens Datakonsult AB,
a KDAB Group company, info@kdab.net,
author Tobias Koenig <tokoe@kdab.com>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#include "blockalarmsattribute.h"
#include <QtCore/QByteArray>
using namespace CalendarSupport;
BlockAlarmsAttribute::BlockAlarmsAttribute()
{
}
BlockAlarmsAttribute::~BlockAlarmsAttribute()
{
}
QByteArray BlockAlarmsAttribute::type() const
{
return "BlockAlarmsAttribute";
}
BlockAlarmsAttribute* BlockAlarmsAttribute::clone() const
{
return new BlockAlarmsAttribute();
}
QByteArray BlockAlarmsAttribute::serialized() const
{
return QByteArray();
}
void BlockAlarmsAttribute::deserialize( const QByteArray &data )
{
Q_ASSERT( data.isEmpty() );
Q_UNUSED( data );
}
/*
Copyright (C) 2010 Klarälvdalens Datakonsult AB,
a KDAB Group company, info@kdab.net,
author Tobias Koenig <tokoe@kdab.com>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#ifndef CALENDARSUPPORT_BLOCKALARMSATTRIBUTE_H
#define CALENDARSUPPORT_BLOCKALARMSATTRIBUTE_H
#include <akonadi/attribute.h>
namespace CalendarSupport {
/**
* @short An Attribute that marks that alarms from an calendar collection are blocked.
*
* A calendar collection which has this attribute set won't be evaluated by korgac and
* therefor its alarms won't be used.
*
* @author Tobias Koenig <tokoe@kdab.com>
* @see Akonadi::Attribute
*/
class BlockAlarmsAttribute : public Akonadi::Attribute
{
public:
/**
* Creates a new block alarms attribute.
*/
BlockAlarmsAttribute();
/**
* Destroys the block alarms attribute.
*/
~BlockAlarmsAttribute();
/**
* Reimplemented from Attribute
*/
QByteArray type() const;
/**
* Reimplemented from Attribute
*/
BlockAlarmsAttribute* clone() const;
/**
* Reimplemented from Attribute
*/
QByteArray serialized() const;
/**
* Reimplemented from Attribute
*/
void deserialize( const QByteArray &data );
};
}
#endif
This diff is collapsed.
/*
Copyright (c) 2009 KDAB
Authors: Sebastian Sauer <sebsauer@kdab.net>
Till Adam <till@kdab.net>
Frank Osterfeld <frank@kdab.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef CALENDARSUPPORT_CALENDAR_P_H
#define CALENDARSUPPORT_CALENDAR_P_H
#include "calendar.h"
#include "calfilterproxymodel.h"
#include <Akonadi/Collection>
#include <KCalCore/CalFilter>
#include <KCalCore/ICalTimeZones>
#include <QObject>
namespace CalendarSupport {
class CalendarCollection : public QObject
{
Q_OBJECT
public:
Calendar *m_calendar;
Akonadi::Collection m_collection;
CalendarCollection( Calendar *calendar, const Akonadi::Collection &collection )
: QObject(), m_calendar(calendar), m_collection(collection)
{
}
~CalendarCollection()
{
}
};
struct UnseenItem
{
Akonadi::Entity::Id collection;
QString uid;
bool operator<( const UnseenItem &other ) const
{
if ( collection != other.collection ) {
return collection < other.collection;
}
return uid < other.uid;
}
};
class Calendar::Private : public QObject
{
Q_OBJECT
private:
void removeItemFromMaps( const Akonadi::Item &item );
Calendar *const q;
public:
explicit Private( QAbstractItemModel *treeModel, QAbstractItemModel *model, Calendar *q );
~Private();
enum UpdateMode {
DontCare,
AssertExists,
AssertNew
};
void updateItem( const Akonadi::Item &item, UpdateMode mode );
void itemChanged( const Akonadi::Item &item );
void assertInvariants() const;
void appendVirtualItems( Akonadi::Item::List &itemList );
//CalendarBase begin
KDateTime::Spec timeZoneIdSpec( const QString &timeZoneId, bool view );
QString mProductId;
KCalCore::Person mOwner;
KCalCore::ICalTimeZones *mTimeZones; // collection of time zones used in this calendar
KCalCore::ICalTimeZone mBuiltInTimeZone; // cached time zone lookup
KCalCore::ICalTimeZone mBuiltInViewTimeZone; // cached viewing time zone lookup
KDateTime::Spec mTimeSpec;
mutable KDateTime::Spec mViewTimeSpec;
bool mModified;
bool mNewObserver;
bool mObserversEnabled;
QList<CalendarObserver*> mObservers;
KCalCore::CalFilter *mDefaultFilter;
//CalendarBase end
QAbstractItemModel *m_treeModel;
QAbstractItemModel *m_model;
CalFilterProxyModel *m_filterProxy;
QHash<Akonadi::Item::Id, Akonadi::Item> m_itemMap; // akonadi id to items
QHash<Akonadi::Entity::Id, Akonadi::Collection> m_collectionMap; // akonadi id to collections
// child to parent map, for already cached parents
QHash<Akonadi::Item::Id, Akonadi::Item::Id> m_childToParent;
//parent to children map for alread cached children
QHash<Akonadi::Item::Id, QList<Akonadi::Item::Id> > m_parentToChildren;
QMap<UnseenItem, Akonadi::Item::Id> m_uidToItemId;
// child to parent map, unknown/not cached parent items
QHash<Akonadi::Item::Id, UnseenItem> m_childToUnseenParent;
QMap<UnseenItem, QList<Akonadi::Item::Id> > m_unseenParentToChildren;
// on start dates/due dates of non-recurring, single-day Incidences
QMultiHash<QString, Akonadi::Item::Id> m_itemIdsForDate;
QHash<Akonadi::Item::Id, QString> m_itemDateForItemId;
// From search folders.
QHash<Akonadi::Item::Id, QList<Akonadi::Item> > m_virtualItems;
void clear();
void readFromModel();
public Q_SLOTS:
void itemsAdded( const Akonadi::Item::List &items );
void itemsRemoved( const Akonadi::Item::List &items );
void collectionsAdded( const Akonadi::Collection::List &collections );
void collectionsRemoved( const Akonadi::Collection::List &collections );
void rowsInserted( const QModelIndex &index, int start, int end );
void rowsAboutToBeRemoved( const QModelIndex &index, int start, int end );
void rowsInsertedInTreeModel( const QModelIndex &index, int start, int end );
void rowsAboutToBeRemovedInTreeModel( const QModelIndex &index, int start, int end );
void dataChangedInTreeModel( const QModelIndex &topLeft, const QModelIndex &bottomRight );
void layoutChanged();
void modelReset();
void dataChanged( const QModelIndex &topLeft, const QModelIndex &bottomRight );
void onRowsMovedInTreeModel( const QModelIndex &sourceParent, int sourceStart, int sourceEnd,
const QModelIndex &destinationParent, int destinationRow );
};
}
#endif
/*
Copyright (c) 2008 Bruno Virlet <bvirlet@kdemail.net>
2009 KDAB; Author: Frank Osterfeld <osterfeld@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#include "calendarmodel.h"
#include "utils.h"
#include <Akonadi/ChangeRecorder>
#include <Akonadi/ItemFetchScope>
#include <KDateTime>
#include <KIconLoader>
#include <KLocale>
#include <QPixmap>
using namespace CalendarSupport;
class CalendarModel::Private
{
public:
explicit Private( CalendarModel *qq )
:q( qq )
{
}
private:
CalendarModel *const q;
};
CalendarModel::CalendarModel( Akonadi::ChangeRecorder *monitor, QObject *parent )
: EntityTreeModel( monitor, parent ),
d( new Private( this ) )
{
monitor->itemFetchScope().fetchAllAttributes( true );
}
CalendarModel::~CalendarModel()
{
delete d;
}
static KDateTime primaryDateForIncidence( const Akonadi::Item &item )
{
if ( const KCalCore::Todo::Ptr t = CalendarSupport::todo( item ) ) {
return t->hasDueDate() ? t->dtDue() : KDateTime();
}
if ( const KCalCore::Event::Ptr e = CalendarSupport::event( item ) ) {
return ( !e->recurs() && !e->isMultiDay() ) ? e->dtStart() : KDateTime();
}
if ( const KCalCore::Journal::Ptr j = CalendarSupport::journal( item ) ) {
return j->dtStart();
}
return KDateTime();
}
QVariant CalendarModel::entityData( const Akonadi::Item &item, int column, int role ) const
{
const KCalCore::Incidence::Ptr incidence = CalendarSupport::incidence( item );
if ( !incidence ) {
return QVariant();
}
switch( role ) {
case Qt::DecorationRole:
if ( column != Summary ) {
return QVariant();
}
if ( incidence->type() == KCalCore::IncidenceBase::TypeTodo ) {
return SmallIcon( QLatin1String( "view-pim-tasks" ) );
}
if ( incidence->type() == KCalCore::IncidenceBase::TypeJournal ) {
return SmallIcon( QLatin1String( "view-pim-journal" ) );
}
if ( incidence->type() == KCalCore::IncidenceBase::TypeEvent ) {
return SmallIcon( QLatin1String( "view-calendar" ) );
}
return SmallIcon( QLatin1String( "network-wired" ) );
case Qt::DisplayRole:
switch( column ) {
case Summary:
return incidence->summary();
case DateTimeStart:
return incidence->dtStart().toString();
case DateTimeEnd:
return incidence->dateTime( KCalCore::Incidence::RoleEndTimeZone ).toString();
case DateTimeDue:
if ( KCalCore::Todo::Ptr todo = CalendarSupport::todo( item ) ) {
return todo->dtDue().toString();
} else {
return QVariant();
}
case Priority:
if ( KCalCore::Todo::Ptr todo = CalendarSupport::todo( item ) ) {
return todo->priority();
} else {
return QVariant();
}
case PercentComplete:
if ( KCalCore::Todo::Ptr todo = CalendarSupport::todo( item ) ) {
return todo->percentComplete();
} else {
return QVariant();
}
case PrimaryDate:
return primaryDateForIncidence( item ).toString();
case Type:
return incidence->type();
default:
break;
}
case SortRole:
switch( column ) {
case Summary:
return incidence->summary();
case DateTimeStart:
return incidence->dtStart().toUtc().dateTime();
case DateTimeEnd:
return incidence->dateTime( KCalCore::Incidence::RoleEndTimeZone ).toUtc().dateTime();
case DateTimeDue:
if ( KCalCore::Todo::Ptr todo = CalendarSupport::todo( item ) ) {
return todo->dtDue().toUtc().dateTime();
} else {
return QVariant();
}
case PrimaryDate:
return primaryDateForIncidence( item ).toUtc().dateTime();
case Priority:
if ( KCalCore::Todo::Ptr todo = CalendarSupport::todo( item ) ) {
return todo->priority();
} else {
return QVariant();
}
case PercentComplete:
if ( KCalCore::Todo::Ptr todo = CalendarSupport::todo( item ) ) {
return todo->percentComplete();
} else {
return QVariant();
}
case Type:
return incidence->type();
default:
break;
}
return QVariant();
case RecursRole:
return incidence->recurs();
default:
return QVariant();
}
return QVariant();
}
QVariant CalendarModel::entityData( const Akonadi::Collection &collection,
int column, int role ) const
{
return EntityTreeModel::entityData( collection, column, role );
}
int CalendarModel::entityColumnCount( EntityTreeModel::HeaderGroup headerSet ) const
{
if ( headerSet == EntityTreeModel::ItemListHeaders ) {
return ItemColumnCount;
} else {
return CollectionColumnCount;
}
}
QVariant CalendarModel::entityHeaderData( int section, Qt::Orientation orientation,
int role, EntityTreeModel::HeaderGroup headerSet ) const
{
if ( role != Qt::DisplayRole || orientation != Qt::Horizontal ) {
return QVariant();
}
if ( headerSet == EntityTreeModel::ItemListHeaders ) {
switch( section ) {
case Summary:
return i18nc( "@title:column calendar event summary", "Summary" );
case DateTimeStart:
return i18nc( "@title:column calendar event start date and time", "Start Date and Time" );
case DateTimeEnd:
return i18nc( "@title:column calendar event end date and time", "End Date and Time" );
case Type:
return i18nc( "@title:column calendar event type", "Type" );
case DateTimeDue:
return i18nc( "@title:column todo item due date and time", "Due Date and Time" );
case Priority:
return i18nc( "@title:column todo item priority", "Priority" );
case PercentComplete:
return i18nc( "@title:column todo item completion in percent", "Complete" );
default:
return QVariant();
}
}
if ( headerSet == EntityTreeModel::CollectionTreeHeaders ) {
switch ( section ) {
case CollectionTitle:
return i18nc( "@title:column calendar title", "Calendar" );
default:
return QVariant();
}
}
return QVariant();
}
/*
Copyright (c) 2009 KDAB
Author: Frank Osterfeld <osterfeld@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your