Akonadi

transportresourcebase.cpp
1 /*
2  Copyright (c) 2009 Constantin Berzan <[email protected]>
3 
4  This library is free software; you can redistribute it and/or modify it
5  under the terms of the GNU Library General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or (at your
7  option) any later version.
8 
9  This library is distributed in the hope that it will be useful, but WITHOUT
10  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12  License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to the
16  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  02110-1301, USA.
18 */
19 
20 #include "transportresourcebase.h"
21 #include "transportresourcebase_p.h"
22 
23 #include <QDBusConnection>
24 #include "transportadaptor.h"
25 
26 #include "itemfetchjob.h"
27 #include "itemfetchscope.h"
28 
29 #include <QDBusConnection>
30 
31 using namespace Akonadi;
32 
33 TransportResourceBasePrivate::TransportResourceBasePrivate(TransportResourceBase *qq)
34  : QObject()
35  , q(qq)
36 {
37  new Akonadi__TransportAdaptor(this);
38  QDBusConnection::sessionBus().registerObject(QStringLiteral("/Transport"),
39  this, QDBusConnection::ExportAdaptors);
40 }
41 
42 void TransportResourceBasePrivate::send(Item::Id id)
43 {
44  ItemFetchJob *job = new ItemFetchJob(Item(id));
46  job->setProperty("id", QVariant(id));
47  connect(job, &KJob::result, this, &TransportResourceBasePrivate::fetchResult);
48 }
49 
50 void TransportResourceBasePrivate::fetchResult(KJob *job)
51 {
52  if (job->error()) {
53  const Item::Id id = job->property("id").toLongLong();
54  Q_EMIT transportResult(id, static_cast<int>(TransportResourceBase::TransportFailed), job->errorText());
55  return;
56  }
57 
58  ItemFetchJob *fetchJob = qobject_cast<ItemFetchJob *>(job);
59  Q_ASSERT(fetchJob);
60 
61  const Item item = fetchJob->items().at(0);
62  q->sendItem(item);
63 }
64 
66  : d(new TransportResourceBasePrivate(this))
67 {
68 }
69 
71 {
72  delete d;
73 }
74 
75 void TransportResourceBase::itemSent(const Item &item,
76  TransportResult result,
77  const QString &message)
78 {
79  Q_EMIT d->transportResult(item.id(), static_cast<int>(result), message);
80 }
81 
82 #include "moc_transportresourcebase_p.cpp"
qlonglong toLongLong(bool *ok) const const
bool registerObject(const QString &path, QObject *object, QDBusConnection::RegisterOptions options)
Resource implementing mail transport capability.
QDBusConnection sessionBus()
TransportResourceBase()
Creates a new transport resource base.
void fetchFullPayload(bool fetch=true)
Sets whether the full payload shall be fetched.
Item::List items() const
Returns the fetched items.
void itemSent(const Akonadi::Item &item, TransportResult result, const QString &message=QString())
This method marks the sending of the passed item as finished.
ItemFetchScope & fetchScope()
Returns the item fetch scope.
QVariant property(const char *name) const const
virtual ~TransportResourceBase()
Destroys the transport resource base.
TransportResult
Describes the result of the transport process.
Helper integration between Akonadi and Qt.
Job that fetches items from the Akonadi storage.
Definition: itemfetchjob.h:84
bool setProperty(const char *name, const QVariant &value)
void result(KJob *job)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
T qobject_cast(QObject *object)
Q_EMITQ_EMIT
QString errorText() const
int error() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Jun 5 2020 23:08:56 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.