Akonadi

transportresourcebase.cpp
1 /*
2  SPDX-FileCopyrightText: 2009 Constantin Berzan <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "transportresourcebase.h"
8 #include "transportresourcebase_p.h"
9 
10 #include "transportadaptor.h"
11 #include <QDBusConnection>
12 
13 #include "itemfetchjob.h"
14 #include "itemfetchscope.h"
15 
16 #include <QDBusConnection>
17 
18 using namespace Akonadi;
19 
20 TransportResourceBasePrivate::TransportResourceBasePrivate(TransportResourceBase *qq)
21  : q(qq)
22 {
23  new Akonadi__TransportAdaptor(this);
24  QDBusConnection::sessionBus().registerObject(QStringLiteral("/Transport"), this, QDBusConnection::ExportAdaptors);
25 }
26 
27 void TransportResourceBasePrivate::send(Item::Id id)
28 {
29  auto job = new ItemFetchJob(Item(id));
30  job->fetchScope().fetchFullPayload();
31  job->setProperty("id", QVariant(id));
32  connect(job, &KJob::result, this, &TransportResourceBasePrivate::fetchResult);
33 }
34 
35 void TransportResourceBasePrivate::fetchResult(KJob *job)
36 {
37  if (job->error()) {
38  const Item::Id id = job->property("id").toLongLong();
39  Q_EMIT transportResult(id, static_cast<int>(TransportResourceBase::TransportFailed), job->errorText());
40  return;
41  }
42 
43  auto fetchJob = qobject_cast<ItemFetchJob *>(job);
44  Q_ASSERT(fetchJob);
45 
46  const Item item = fetchJob->items().at(0);
47  q->sendItem(item);
48 }
49 
51  : d(new TransportResourceBasePrivate(this))
52 {
53 }
54 
56 
58 {
59  Q_EMIT d->transportResult(item.id(), static_cast<int>(result), message);
60 }
61 
62 #include "moc_transportresourcebase_p.cpp"
virtual ~TransportResourceBase()
Destroys the transport resource base.
void result(KJob *job)
bool registerObject(const QString &path, QObject *object, QDBusConnection::RegisterOptions options)
qlonglong toLongLong(bool *ok) const const
TransportResult
Describes the result of the transport process.
qint64 Id
Describes the unique id type.
Definition: item.h:110
@ TransportFailed
The transport process failed.
QDBusConnection sessionBus()
Resource implementing mail transport capability.
QString errorText() const
void itemSent(const Akonadi::Item &item, TransportResult result, const QString &message=QString())
This method marks the sending of the passed item as finished.
Id id() const
Returns the unique identifier of the item.
Definition: item.cpp:63
TransportResourceBase()
Creates a new transport resource base.
Job that fetches items from the Akonadi storage.
Definition: itemfetchjob.h:69
int error() const
QString message
Represents a PIM item stored in Akonadi storage.
Definition: item.h:104
QVariant property(const char *name) const const
Helper integration between Akonadi and Qt.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Jul 2 2022 06:41:49 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.