Commit 6fd9d0ef authored by Sergio Martins's avatar Sergio Martins
Browse files

Port away from CalendarSupport::Calendar and CalendarAdaptor.

parent 6b9474b9
......@@ -27,8 +27,6 @@ set(calendarsupport_LIB_SRCS
collectionselection.cpp
daterangefilterproxymodel.cpp
eventarchiver.cpp
freebusydownloadjob.cpp
freebusymanager.cpp
groupware.cpp
identitymanager.cpp
incidenceattachmentmodel.cpp
......@@ -39,7 +37,6 @@ set(calendarsupport_LIB_SRCS
mailclient.cpp
mailscheduler.cpp
nepomukcalendar.cpp
publishdialog.cpp
utils.cpp
next/akonadicalendar.cpp
......@@ -60,8 +57,6 @@ if(NOT WINCE)
)
endif()
kde4_add_ui_files(calendarsupport_LIB_SRCS publishdialog_base.ui)
kde4_add_kcfg_files(calendarsupport_LIB_SRCS kcalprefs_base.kcfgc)
# qt4_add_dbus_interface(calendarsupport_LIB_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/org.freedesktop.Akonadi.CalendarSearchAgent.xml calendarsearchinterface)
......
......@@ -54,7 +54,7 @@
using namespace CalendarSupport;
ArchiveDialog::ArchiveDialog( CalendarSupport::Calendar *cal,
ArchiveDialog::ArchiveDialog( const Akonadi::ETMCalendar::Ptr &cal,
Akonadi::IncidenceChanger *changer,
QWidget *parent )
: KDialog (parent)
......
......@@ -25,6 +25,7 @@
#include "calendarsupport_export.h"
#include <akonadi/calendar/etmcalendar.h>
#include <KDialog>
class KComboBox;
......@@ -38,18 +39,18 @@ class QRadioButton;
namespace Akonadi {
class IncidenceChanger;
class ETMCalendar;
}
namespace CalendarSupport {
class Calendar;
class CALENDARSUPPORT_EXPORT ArchiveDialog : public KDialog
{
Q_OBJECT
public:
explicit ArchiveDialog( CalendarSupport::Calendar *calendar,
Akonadi::IncidenceChanger *changer, QWidget *parent=0 );
ArchiveDialog( const Akonadi::ETMCalendar::Ptr &calendar,
Akonadi::IncidenceChanger *changer,
QWidget *parent = 0 );
~ArchiveDialog();
signals:
......@@ -74,7 +75,7 @@ class CALENDARSUPPORT_EXPORT ArchiveDialog : public KDialog
QCheckBox *mEvents;
QCheckBox *mTodos;
Akonadi::IncidenceChanger *mChanger;
CalendarSupport::Calendar *mCalendar;
Akonadi::ETMCalendar::Ptr mCalendar;
};
}
......
......@@ -26,28 +26,26 @@
// - makeChildrenIndependent
#include "calendarutils.h"
#include "calendar.h"
#include "incidencechanger.h"
#include "utils.h"
#include <KCalCore/Incidence>
#include <akonadi/calendar/etmcalendar.h>
#include <akonadi/calendar/incidencechanger.h>
#include <KLocalizedString>
#include <KMessageBox>
using namespace Akonadi;
using namespace CalendarSupport;
using namespace KCalCore;
/// CalendarUtilsPrivate
struct MultiChange {
Item parent;
QVector<Item::Id> children;
Akonadi::Item parent;
QVector<Akonadi::Item::Id> children;
bool success;
explicit MultiChange( const Item &parent = Item() )
explicit MultiChange( const Akonadi::Item &parent = Akonadi::Item() )
: parent( parent ),
success( true )
{}
......@@ -63,17 +61,17 @@ struct CalendarUtilsPrivate
{
public:
/// Methods
CalendarUtilsPrivate( Calendar *calendar, CalendarUtils *qq );
void handleChangeFinish( const Akonadi::Item &oldInc,
const Akonadi::Item &newInc,
CalendarSupport::IncidenceChanger::WhatChanged,
bool success );
CalendarUtilsPrivate( const Akonadi::ETMCalendar::Ptr &calendar, CalendarUtils *qq );
void handleChangeFinish( int changeId,
const Akonadi::Item &item,
Akonadi::IncidenceChanger::ResultCode resultCode,
const QString &errorString );
bool purgeCompletedSubTodos( const Akonadi::Item &todoItem, bool &allPurged );
bool purgeCompletedSubTodos( const KCalCore::Todo::Ptr &todo, bool &allPurged );
/// Members
Calendar *mCalendar;
IncidenceChanger *mChanger;
Akonadi::ETMCalendar::Ptr mCalendar;
Akonadi::IncidenceChanger *mChanger;
MultiChange mMultiChange;
private:
......@@ -83,28 +81,28 @@ struct CalendarUtilsPrivate
}
CalendarUtilsPrivate::CalendarUtilsPrivate( Calendar *calendar, CalendarUtils *qq )
CalendarUtilsPrivate::CalendarUtilsPrivate( const Akonadi::ETMCalendar::Ptr &calendar, CalendarUtils *qq )
: mCalendar( calendar ),
mChanger( new IncidenceChanger( calendar, qq ) ),
mChanger( new Akonadi::IncidenceChanger( qq ) ),
q_ptr( qq )
{
Q_Q( CalendarUtils );
Q_ASSERT( mCalendar );
q->connect( mChanger,
SIGNAL(incidenceChangeFinished(Akonadi::Item,Akonadi::Item,CalendarSupport::IncidenceChanger::WhatChanged,bool)),
SLOT(handleChangeFinish(Akonadi::Item,Akonadi::Item,CalendarSupport::IncidenceChanger::WhatChanged,bool)) );
SIGNAL(modifyFinished(int,Akonadi::Item,Akonadi::IncidenceChanger::ResultCode,QString)),
SLOT(handleChangeFinish(int,Akonadi::Item,Akonadi::IncidenceChanger::ResultCode,QString)) );
}
void CalendarUtilsPrivate::handleChangeFinish( const Akonadi::Item &oldInc,
const Akonadi::Item &newInc,
CalendarSupport::IncidenceChanger::WhatChanged,
bool success )
void CalendarUtilsPrivate::handleChangeFinish( int,
const Akonadi::Item &item,
Akonadi::IncidenceChanger::ResultCode resultCode,
const QString &errorString )
{
Q_Q( CalendarUtils );
const bool success = resultCode == Akonadi::IncidenceChanger::ResultCodeSuccess;
if ( mMultiChange.inProgress() ) {
mMultiChange.children.remove( mMultiChange.children.indexOf( newInc.id() ) );
mMultiChange.children.remove( mMultiChange.children.indexOf( item.id() ) );
mMultiChange.success = mMultiChange.success && success;
// Are we still in progress?
......@@ -127,33 +125,31 @@ void CalendarUtilsPrivate::handleChangeFinish( const Akonadi::Item &oldInc,
} else {
if ( success ) {
kDebug() << "Change finished";
emit q->actionFinished( newInc );
emit q->actionFinished( item );
} else {
kDebug() << "Change failed";
// TODO: Let incidence changer return a useful message.
emit q->actionFailed( oldInc, QString() );
emit q->actionFailed( Akonadi::Item(), errorString );
}
}
}
bool CalendarUtilsPrivate::purgeCompletedSubTodos( const Akonadi::Item &todoItem, bool &allPurged )
bool CalendarUtilsPrivate::purgeCompletedSubTodos( const KCalCore::Todo::Ptr &todo, bool &allPurged )
{
const Todo::Ptr todo = CalendarSupport::todo( todoItem );
if ( !todo ) {
return true;
}
bool deleteThisTodo = true;
Akonadi::Item::List subTodos = mCalendar->findChildren( todoItem );
Akonadi::Item::List subTodos = mCalendar->childItems( todo->uid() );
foreach ( const Akonadi::Item &item, subTodos ) {
if ( CalendarSupport::hasTodo( item ) ) {
deleteThisTodo &= purgeCompletedSubTodos( item, allPurged );
deleteThisTodo &= purgeCompletedSubTodos( item.payload<KCalCore::Todo::Ptr>(), allPurged );
}
}
if ( deleteThisTodo ) {
if ( todo->isCompleted() ) {
if ( !mChanger->deleteIncidence( todoItem, 0 ) ) {
if ( !mChanger->deleteIncidence( mCalendar->item( todo->uid() ), 0 ) ) {
allPurged = false;
}
} else {
......@@ -169,7 +165,7 @@ bool CalendarUtilsPrivate::purgeCompletedSubTodos( const Akonadi::Item &todoItem
/// CalendarUtils
CalendarUtils::CalendarUtils( Calendar *calendar, QObject *parent )
CalendarUtils::CalendarUtils( const Akonadi::ETMCalendar::Ptr &calendar, QObject *parent )
: QObject( parent ),
d_ptr( new CalendarUtilsPrivate( calendar, this ) )
{
......@@ -181,7 +177,7 @@ CalendarUtils::~CalendarUtils()
delete d_ptr;
}
Calendar *CalendarUtils::calendar() const
Akonadi::ETMCalendar::Ptr CalendarUtils::calendar() const
{
Q_D( const CalendarUtils );
return d->mCalendar;
......@@ -192,10 +188,6 @@ bool CalendarUtils::makeIndependent( const Akonadi::Item &item )
Q_D( CalendarUtils );
Q_ASSERT( item.isValid() );
if ( d->mChanger->changeInProgress( item.id() ) ) {
return false;
}
if ( d->mMultiChange.inProgress() && !d->mMultiChange.children.contains( item.id() ) ) {
return false;
}
......@@ -206,11 +198,8 @@ bool CalendarUtils::makeIndependent( const Akonadi::Item &item )
}
Incidence::Ptr oldInc( inc->clone() );
inc->setRelatedTo( 0 );
// HACK: This is not a widget, so pass 0 for now
return d->mChanger->changeIncidence( oldInc, item,
CalendarSupport::IncidenceChanger::RELATION_MODIFIED,
0 );
inc->setRelatedTo( QString() );
return d->mChanger->modifyIncidence( item, oldInc );
}
bool CalendarUtils::makeChildrenIndependent( const Akonadi::Item &item )
......@@ -218,32 +207,21 @@ bool CalendarUtils::makeChildrenIndependent( const Akonadi::Item &item )
Q_D( CalendarUtils );
Q_ASSERT( item.isValid() );
// Is the current item being changed atm?
if ( d->mChanger->changeInProgress( item.id() ) ) {
return false;
}
if ( d->mMultiChange.inProgress() ) {
return false;
}
const Incidence::Ptr inc = CalendarSupport::incidence( item );
const Akonadi::Item::List subIncs = d->mCalendar->findChildren( item );
const Akonadi::Item::List subIncs = d->mCalendar->childItems( item.id() );
if ( !inc || subIncs.isEmpty() ) {
return false;
}
// First make sure that no changes are in progress for one of the incs
foreach ( const Item &subInc, subIncs ) {
if ( d->mChanger->changeInProgress( subInc.id() ) ) {
return false;
}
}
d->mMultiChange = MultiChange( item );
bool allStarted = true;
foreach ( const Item &subInc, subIncs ) {
foreach ( const Akonadi::Item &subInc, subIncs ) {
d->mMultiChange.children.append( subInc.id() );
allStarted = allStarted && makeIndependent( subInc );
}
......@@ -262,21 +240,18 @@ void CalendarUtils::purgeCompletedTodos()
Q_D( CalendarUtils );
bool allDeleted = true;
// startMultiModify( i18n( "Purging completed to-dos" ) );
Akonadi::Item::List todos = calendar()->rawTodos();
Akonadi::Item::List rootTodos;
Akonadi::Item::List::ConstIterator it;
Akonadi::Item::List::ConstIterator end = todos.constEnd();
for ( it = todos.constBegin(); it != end; ++it ) {
Todo::Ptr aTodo = CalendarSupport::todo( *it );
if ( aTodo && aTodo->relatedTo().isEmpty() ) { // top level todo //REVIEW(AKONADI_PORT)
rootTodos.append( *it );
KCalCore::Todo::List todos = calendar()->rawTodos();
KCalCore::Todo::List rootTodos;
foreach ( const KCalCore::Todo::Ptr &todo, todos ) {
if ( todo && todo->relatedTo().isEmpty() ) { // top level todo //REVIEW(AKONADI_PORT)
rootTodos.append( todo );
}
}
end = rootTodos.constEnd();
// now that we have a list of all root todos, check them and their children
for ( it = rootTodos.constBegin(); it != end; ++it ) {
d->purgeCompletedSubTodos( *it, allDeleted );
foreach ( const KCalCore::Todo::Ptr &todo, rootTodos ) {
d->purgeCompletedSubTodos( todo, allDeleted );
}
// endMultiModify();
......
......@@ -25,6 +25,7 @@
#include "calendarsupport_export.h"
#include <Akonadi/Collection>
#include <akonadi/calendar/etmcalendar.h>
#include <QtCore/QObject>
......@@ -34,7 +35,6 @@ namespace Akonadi {
namespace CalendarSupport {
class Calendar;
class CalendarUtilsPrivate;
/** Some calendar/Incidence related utilitly methods.
......@@ -50,14 +50,14 @@ class CALENDARSUPPORT_EXPORT CalendarUtils : public QObject
* Creates a new CalendarUtils instance. The instance does not take owner ship
* over the Calendar.
*/
explicit CalendarUtils( Calendar *calendar, QObject *parent = 0 );
explicit CalendarUtils( const Akonadi::ETMCalendar::Ptr &calendar, QObject *parent = 0 );
~CalendarUtils();
/**
* Returns the Caledar on which this utils class is operating.
*/
Calendar *calendar() const;
Akonadi::ETMCalendar::Ptr calendar() const;
/**
* Makes the incidence from @param item independent from its parent. Returns
......@@ -90,10 +90,10 @@ class CALENDARSUPPORT_EXPORT CalendarUtils : public QObject
Q_DECLARE_PRIVATE( CalendarUtils )
Q_PRIVATE_SLOT( d_ptr,
void handleChangeFinish( Akonadi::Item,
Akonadi::Item,
CalendarSupport::IncidenceChanger::WhatChanged,
bool ) )
void handleChangeFinish( int changeId,
const Akonadi::Item &item,
Akonadi::IncidenceChanger::ResultCode resultCode,
const QString &errorString ) )
};
}
......
......@@ -57,19 +57,19 @@ EventArchiver::~EventArchiver()
{
}
void EventArchiver::runOnce( CalendarSupport::Calendar *calendar,
void EventArchiver::runOnce( const Akonadi::ETMCalendar::Ptr &calendar,
Akonadi::IncidenceChanger *changer,
const QDate &limitDate, QWidget *widget )
{
run( calendar, changer, limitDate, widget, true, true );
}
void EventArchiver::runAuto( CalendarSupport::Calendar *calendar,
void EventArchiver::runAuto( const Akonadi::ETMCalendar::Ptr &calendar,
Akonadi::IncidenceChanger *changer,
QWidget *widget, bool withGUI )
{
QDate limitDate( QDate::currentDate() );
int expiryTime = KCalPrefs::instance()->mExpiryTime;
const int expiryTime = KCalPrefs::instance()->mExpiryTime;
switch ( KCalPrefs::instance()->mExpiryUnit ) {
case KCalPrefs::UnitDays: // Days
limitDate = limitDate.addDays( -expiryTime );
......@@ -86,15 +86,15 @@ void EventArchiver::runAuto( CalendarSupport::Calendar *calendar,
run( calendar, changer, limitDate, widget, withGUI, false );
}
void EventArchiver::run( CalendarSupport::Calendar *calendar,
void EventArchiver::run( const Akonadi::ETMCalendar::Ptr &calendar,
Akonadi::IncidenceChanger *changer,
const QDate &limitDate, QWidget *widget,
bool withGUI, bool errorIfNone )
{
// We need to use rawEvents, otherwise events hidden by filters will not be archived.
Akonadi::Item::List events;
Akonadi::Item::List todos;
Akonadi::Item::List journals;
KCalCore::Event::List events;
KCalCore::Todo::List todos;
KCalCore::Journal::List journals;
if ( KCalPrefs::instance()->mArchiveEvents ) {
events = calendar->rawEvents(
......@@ -105,21 +105,17 @@ void EventArchiver::run( CalendarSupport::Calendar *calendar,
true );
}
if ( KCalPrefs::instance()->mArchiveTodos ) {
Akonadi::Item::List t = calendar->rawTodos();
Akonadi::Item::List::ConstIterator it;
Akonadi::Item::List::ConstIterator end( t.constEnd() );
KCalCore::Todo::List rawTodos = calendar->rawTodos();
for ( it = t.constBegin(); it != end; ++it ) {
const Todo::Ptr todo = CalendarSupport::todo( *it );
foreach( const KCalCore::Todo::Ptr &todo, rawTodos ) {
Q_ASSERT( todo );
if ( isSubTreeComplete( calendar, todo, limitDate ) ) {
todos.append( *it );
todos.append( todo );
}
}
}
const Akonadi::Item::List incidences =
CalendarSupport::Calendar::mergeIncidenceList( events, todos, journals );
const KCalCore::Incidence::List incidences = calendar->mergeIncidenceList( events, todos, journals );
kDebug() << "archiving incidences before" << limitDate
<< " ->" << incidences.count() <<" incidences found.";
......@@ -135,7 +131,7 @@ void EventArchiver::run( CalendarSupport::Calendar *calendar,
switch ( KCalPrefs::instance()->mArchiveAction ) {
case KCalPrefs::actionDelete:
deleteIncidences( changer, limitDate, widget, incidences, withGUI );
deleteIncidences( changer, limitDate, widget, calendar->itemList( incidences ), withGUI );
break;
case KCalPrefs::actionArchive:
archiveIncidences( calendar, changer, limitDate, widget, incidences, withGUI );
......@@ -145,45 +141,43 @@ void EventArchiver::run( CalendarSupport::Calendar *calendar,
void EventArchiver::deleteIncidences( Akonadi::IncidenceChanger *changer,
const QDate &limitDate, QWidget *widget,
const Akonadi::Item::List &incidences, bool withGUI )
const Akonadi::Item::List &items, bool withGUI )
{
QStringList incidenceStrs;
Akonadi::Item::List::ConstIterator it;
Akonadi::Item::List::ConstIterator end( incidences.constEnd() );
for ( it = incidences.constBegin(); it != end; ++it ) {
Akonadi::Item::List::ConstIterator end( items.constEnd() );
for ( it = items.constBegin(); it != end; ++it ) {
incidenceStrs.append( CalendarSupport::incidence( *it )->summary() );
}
if ( withGUI ) {
int result = KMessageBox::warningContinueCancelList(
widget,
i18n( "Delete all items before %1 without saving?\n"
"The following items will be deleted:",
KGlobal::locale()->formatDate( limitDate ) ),
incidenceStrs,
i18n( "Delete Old Items" ), KStandardGuiItem::del() );
const int result = KMessageBox::warningContinueCancelList(
widget,
i18n( "Delete all items before %1 without saving?\n"
"The following items will be deleted:",
KGlobal::locale()->formatDate( limitDate ) ),
incidenceStrs,
i18n( "Delete Old Items" ), KStandardGuiItem::del() );
if ( result != KMessageBox::Continue ) {
return;
}
}
for ( it = incidences.constBegin(); it != incidences.constEnd(); ++it ) {
changer->deleteIncidence( *it, widget );
} // TODO: emit only after hearing back from incidence changer
changer->deleteIncidences( items, /**parent=*/widget );
// TODO: emit only after hearing back from incidence changer
emit eventsDeleted();
}
void EventArchiver::archiveIncidences( CalendarSupport::Calendar *calendar,
void EventArchiver::archiveIncidences( const Akonadi::ETMCalendar::Ptr &calendar,
Akonadi::IncidenceChanger *changer,
const QDate &limitDate, QWidget *widget,
const Akonadi::Item::List &incidences, bool withGUI )
const KCalCore::Incidence::List &incidences, bool withGUI )
{
Q_UNUSED( limitDate );
Q_UNUSED( withGUI );
CalendarSupport::CalendarAdaptor::Ptr cal(
new CalendarSupport::CalendarAdaptor( calendar, widget ) );
FileStorage storage( cal );
FileStorage storage( calendar );
QString tmpFileName;
// KSaveFile cannot be called with an open File Handle on Windows.
......@@ -220,12 +214,12 @@ void EventArchiver::archiveIncidences( CalendarSupport::Calendar *calendar,
// remain. This is not really efficient, but there is no other easy way.
QStringList uids;
Incidence::List allIncidences = archiveCalendar->rawIncidences();
foreach ( const Akonadi::Item &item, incidences ) {
uids.append( CalendarSupport::incidence(item)->uid() );
foreach ( const KCalCore::Incidence::Ptr &incidence, incidences ) {
uids.append( incidence->uid() );
}
foreach ( const Incidence::Ptr inc, allIncidences ) {
if ( !uids.contains( inc->uid() ) ) {
archiveCalendar->deleteIncidence( inc );
foreach ( const KCalCore::Incidence::Ptr &incidence, allIncidences ) {
if ( !uids.contains( incidence->uid() ) ) {
archiveCalendar->deleteIncidence( incidence );
}
}
......@@ -291,7 +285,8 @@ void EventArchiver::archiveIncidences( CalendarSupport::Calendar *calendar,
changer->startAtomicOperation( i18n( "Archiving events" ) );
// Delete archived events from calendar
foreach ( const Akonadi::Item &item, incidences ) {
Akonadi::Item::List items = calendar->itemList( incidences );
foreach ( const Akonadi::Item &item, items ) {
changer->deleteIncidence( item, widget );
} // TODO: emit only after hearing back from incidence changer
changer->endAtomicOperation();
......@@ -299,7 +294,7 @@ void EventArchiver::archiveIncidences( CalendarSupport::Calendar *calendar,
emit eventsDeleted();
}
bool EventArchiver::isSubTreeComplete( CalendarSupport::Calendar *calendar,
bool EventArchiver::isSubTreeComplete( const Akonadi::ETMCalendar::Ptr &calendar,
const Todo::Ptr &todo,
const QDate &limitDate,
QStringList checkedUids ) const
......@@ -316,14 +311,11 @@ bool EventArchiver::isSubTreeComplete( CalendarSupport::Calendar *calendar,
}
checkedUids.append( todo->uid() );
const Akonadi::Item item = calendar->itemForIncidenceUid( todo->uid() );
Akonadi::Item::List relations = calendar->findChildren( item );
foreach ( const Akonadi::Item &item, relations ) {
if ( CalendarSupport::hasTodo( item ) ) {
const Todo::Ptr t = CalendarSupport::todo( item );
if ( !isSubTreeComplete( calendar, t, limitDate, checkedUids ) ) {
return false;
}
KCalCore::Incidence::List childs = calendar->childIncidences( todo->uid() );
foreach ( const KCalCore::Incidence::Ptr &incidence, childs ) {
const Todo::Ptr t = incidence.dynamicCast<KCalCore::Todo>();
if ( t && !isSubTreeComplete( calendar, t, limitDate, checkedUids ) ) {
return false;
}
}
......
......@@ -27,7 +27,7 @@
#include "calendarsupport_export.h"
#include <Akonadi/Item>
#include <akonadi/calendar/etmcalendar.h>
#include <KCalCore/Event>
#include <KCalCore/Todo>
......@@ -40,7 +40,6 @@ namespace Akonadi {
}