Skip to content

Commit

Permalink
Major refactor of item handling code
Browse files Browse the repository at this point in the history
The new implementation moves all actions specific to item type into a
dedicated set of classes. This way the core resource code is generic and
doesn't have to worry about type-specific actions.
  • Loading branch information
KrissN committed Feb 1, 2016
1 parent a01edaf commit c60be7f
Show file tree
Hide file tree
Showing 34 changed files with 1,310 additions and 216 deletions.
16 changes: 14 additions & 2 deletions CMakeLists.txt
Expand Up @@ -52,12 +52,24 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/ewsclient)
add_definitions(-DTRANSLATION_DOMAIN=\"akonadi_ews_resource\")

set(ewsresource_SRCS
calendar/ewscalendarhandler.cpp
calendar/ewsfetchcalendardetailjob.cpp
calendar/ewsmodifycalendarjob.cpp
contact/ewscontacthandler.cpp
contact/ewsfetchcontactdetailjob.cpp
contact/ewsmodifycontactjob.cpp
mail/ewsfetchmaildetailjob.cpp
mail/ewsmailhandler.cpp
mail/ewsmodifymailjob.cpp
task/ewsfetchtaskdetailjob.cpp
task/ewsmodifytaskjob.cpp
task/ewstaskhandler.cpp
configdialog.cpp
ewsfetchfoldersjob.cpp
ewsfetchitemsjob.cpp
ewsfetchitemdetailjob.cpp
ewsfetchmaildetailjob.cpp
ewsfetchcalendardetailjob.cpp
ewsitemhandler.cpp
ewsmodifyitemjob.cpp
ewsresource.cpp
ewssubscriptionmanager.cpp)

Expand Down
73 changes: 73 additions & 0 deletions calendar/ewscalendarhandler.cpp
@@ -0,0 +1,73 @@
/* This file is part of Akonadi EWS Resource
Copyright (C) 2015-2016 Krzysztof Nowicki <krissn@op.pl>
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 "ewscalendarhandler.h"

#include <KCalCore/Event>

#include "ewsfetchcalendardetailjob.h"
#include "ewsmodifycalendarjob.h"

using namespace Akonadi;

EwsCalendarHandler::EwsCalendarHandler()
{
}

EwsCalendarHandler::~EwsCalendarHandler()
{
}

EwsItemHandler *EwsCalendarHandler::factory()
{
return new EwsCalendarHandler();
}

EwsFetchItemDetailJob *EwsCalendarHandler::fetchItemDetailJob(EwsClient &client, QObject *parent,
const Akonadi::Collection &collection)
{
return new EwsFetchCalendarDetailJob(client, parent, collection);
}

void EwsCalendarHandler::setSeenFlag(Item &item, bool value)
{
Q_UNUSED(item)
Q_UNUSED(value)
}

QString EwsCalendarHandler::mimeType()
{
return KCalCore::Event::eventMimeType();
}

bool EwsCalendarHandler::setItemPayload(Akonadi::Item &item, const EwsItem &ewsItem)
{
Q_UNUSED(item)
Q_UNUSED(ewsItem)

return true;
}

EwsModifyItemJob *EwsCalendarHandler::modifyItemJob(EwsClient& client, const Akonadi::Item &item,
const QSet<QByteArray> &parts, QObject *parent)
{
return new EwsModifyCalendarJob(client, item, parts, parent);
}

EWS_DECLARE_ITEM_HANDLER(EwsCalendarHandler, EwsItemTypeCalendarItem)
43 changes: 43 additions & 0 deletions calendar/ewscalendarhandler.h
@@ -0,0 +1,43 @@
/* This file is part of Akonadi EWS Resource
Copyright (C) 2015-2016 Krzysztof Nowicki <krissn@op.pl>
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 EWSCALENDARHANDLER_H
#define EWSCALENDARHANDLER_H

#include "ewsitemhandler.h"

class EwsCalendarHandler : public EwsItemHandler
{
public:
EwsCalendarHandler();
virtual ~EwsCalendarHandler();

virtual EwsFetchItemDetailJob *fetchItemDetailJob(EwsClient &client, QObject *parent,
const Akonadi::Collection &collection) Q_DECL_OVERRIDE;
virtual void setSeenFlag(Akonadi::Item &item, bool value) Q_DECL_OVERRIDE;
virtual QString mimeType() Q_DECL_OVERRIDE;
virtual bool setItemPayload(Akonadi::Item &item, const EwsItem &ewsItem) Q_DECL_OVERRIDE;
virtual EwsModifyItemJob *modifyItemJob(EwsClient& client, const Akonadi::Item &item,
const QSet<QByteArray> &parts, QObject *parent) Q_DECL_OVERRIDE;

static EwsItemHandler *factory();
private:
};

#endif
Expand Up @@ -236,12 +236,6 @@ void EwsFetchCalendarDetailJob::exceptionItemsFetched(KJob *job)
emitResult();
}

EwsFetchItemDetailJob *EwsFetchCalendarDetailJob::factory(EwsClient &client, QObject *parent,
const Akonadi::Collection &collection)
{
return new EwsFetchCalendarDetailJob(client, parent, collection);
}

/*
* This method does its best to convert the timezone found in the EWS calendar event to a IANA
* timezone. This is a cumbersome process as there is no guarantee that the
Expand Down Expand Up @@ -301,5 +295,3 @@ void EwsFetchCalendarDetailJob::convertTimezone(KDateTime &currentTime, QString

currentTime = resultDt;
}

EWS_DECLARE_FETCH_ITEM_DETAIL_JOB(EwsFetchCalendarDetailJob, EwsItemTypeCalendarItem)
Expand Up @@ -30,7 +30,6 @@ class EwsFetchCalendarDetailJob : public EwsFetchItemDetailJob
public:
EwsFetchCalendarDetailJob(EwsClient &client, QObject *parent, const Akonadi::Collection &collection);
virtual ~EwsFetchCalendarDetailJob();
static EwsFetchItemDetailJob *factory(EwsClient &client, QObject *parent, const Akonadi::Collection &collection);
protected:
virtual void processItems(const QList<EwsGetItemRequest::Response> &responses) Q_DECL_OVERRIDE;
void convertTimezone(KDateTime &currentTime, QString msTimezone, QString culture);
Expand Down
37 changes: 37 additions & 0 deletions calendar/ewsmodifycalendarjob.cpp
@@ -0,0 +1,37 @@
/* This file is part of Akonadi EWS Resource
Copyright (C) 2015-2016 Krzysztof Nowicki <krissn@op.pl>
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 "ewsmodifycalendarjob.h"

#include "ewsclient_debug.h"

EwsModifyCalendarJob::EwsModifyCalendarJob(EwsClient& client, const Akonadi::Item &item,
const QSet<QByteArray> &parts, QObject *parent)
: EwsModifyItemJob(client, item, parts, parent)
{
}
EwsModifyCalendarJob::~EwsModifyCalendarJob()
{
}

void EwsModifyCalendarJob::start()
{
qCWarning(EWSRES_LOG) << QStringLiteral("Calendar item modification not implemented!");
emitResult();
}
35 changes: 35 additions & 0 deletions calendar/ewsmodifycalendarjob.h
@@ -0,0 +1,35 @@
/* This file is part of Akonadi EWS Resource
Copyright (C) 2015-2016 Krzysztof Nowicki <krissn@op.pl>
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 EWSMODIFYCALENDARJOB_H
#define EWSMODIFYCALENDARJOB_H

#include "ewsmodifyitemjob.h"

class EwsModifyCalendarJob : public EwsModifyItemJob
{
Q_OBJECT
public:
EwsModifyCalendarJob(EwsClient& client, const Akonadi::Item &item, const QSet<QByteArray> &parts,
QObject *parent);
virtual ~EwsModifyCalendarJob();
virtual void start() Q_DECL_OVERRIDE;
};

#endif
74 changes: 74 additions & 0 deletions contact/ewscontacthandler.cpp
@@ -0,0 +1,74 @@
/* This file is part of Akonadi EWS Resource
Copyright (C) 2015-2016 Krzysztof Nowicki <krissn@op.pl>
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 "ewscontacthandler.h"

#include <KContacts/Addressee>
#include <KContacts/ContactGroup>

#include "ewsfetchcontactdetailjob.h"
#include "ewsmodifycontactjob.h"

using namespace Akonadi;

EwsContactHandler::EwsContactHandler()
{
}

EwsContactHandler::~EwsContactHandler()
{
}

EwsItemHandler *EwsContactHandler::factory()
{
return new EwsContactHandler();
}

EwsFetchItemDetailJob *EwsContactHandler::fetchItemDetailJob(EwsClient &client, QObject *parent,
const Akonadi::Collection &collection)
{
return new EwsFetchContactDetailJob(client, parent, collection);
}

void EwsContactHandler::setSeenFlag(Item &item, bool value)
{
Q_UNUSED(item)
Q_UNUSED(value)
}

QString EwsContactHandler::mimeType()
{
return KContacts::Addressee::mimeType();
}

bool EwsContactHandler::setItemPayload(Akonadi::Item &item, const EwsItem &ewsItem)
{
Q_UNUSED(item)
Q_UNUSED(ewsItem)

return true;
}

EwsModifyItemJob *EwsContactHandler::modifyItemJob(EwsClient& client, const Akonadi::Item &item,
const QSet<QByteArray> &parts, QObject *parent)
{
return new EwsModifyContactJob(client, item, parts, parent);
}

EWS_DECLARE_ITEM_HANDLER(EwsContactHandler, EwsItemTypeTask)
43 changes: 43 additions & 0 deletions contact/ewscontacthandler.h
@@ -0,0 +1,43 @@
/* This file is part of Akonadi EWS Resource
Copyright (C) 2015-2016 Krzysztof Nowicki <krissn@op.pl>
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 EWSCONTACTHANDLER_H
#define EWSCONTACTHANDLER_H

#include "ewsitemhandler.h"

class EwsContactHandler : public EwsItemHandler
{
public:
EwsContactHandler();
virtual ~EwsContactHandler();

virtual EwsFetchItemDetailJob *fetchItemDetailJob(EwsClient &client, QObject *parent,
const Akonadi::Collection &collection) Q_DECL_OVERRIDE;
virtual void setSeenFlag(Akonadi::Item &item, bool value) Q_DECL_OVERRIDE;
virtual QString mimeType() Q_DECL_OVERRIDE;
virtual bool setItemPayload(Akonadi::Item &item, const EwsItem &ewsItem) Q_DECL_OVERRIDE;
virtual EwsModifyItemJob *modifyItemJob(EwsClient& client, const Akonadi::Item &item,
const QSet<QByteArray> &parts, QObject *parent) Q_DECL_OVERRIDE;

static EwsItemHandler *factory();
private:
};

#endif

0 comments on commit c60be7f

Please sign in to comment.