Akonadi

partfetcher.h
1 /*
2  SPDX-FileCopyrightText: 2009 Stephen Kelly <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #pragma once
8 
9 #include <KJob>
10 
11 #include "akonadicore_export.h"
12 
13 #include <memory>
14 
15 class QModelIndex;
16 
17 namespace Akonadi
18 {
19 class Item;
20 class PartFetcherPrivate;
21 
22 /**
23  * @short Convenience class for getting payload parts from an Akonadi Model.
24  *
25  * This class can be used to retrieve individual payload parts from an EntityTreeModel,
26  * and fetch them asynchronously from the Akonadi storage if necessary.
27  *
28  * The requested part is emitted though the partFetched signal.
29  *
30  * Example:
31  *
32  * @code
33  *
34  * const QModelIndex index = view->selectionModel()->currentIndex();
35  *
36  * PartFetcher *fetcher = new PartFetcher( index, Akonadi::MessagePart::Envelope );
37  * connect( fetcher, SIGNAL(result(KJob*)), SLOT(fetchResult(KJob*)) );
38  * fetcher->start();
39  *
40  * ...
41  *
42  * MyClass::fetchResult( KJob *job )
43  * {
44  * if ( job->error() ) {
45  * qDebug() << job->errorText();
46  * return;
47  * }
48  *
49  * PartFetcher *fetcher = qobject_cast<PartFetcher*>( job );
50  *
51  * const Item item = fetcher->item();
52  * // do something with the item
53  * }
54  *
55  * @endcode
56  *
57  * @author Stephen Kelly <[email protected]>
58  * @since 4.4
59  */
60 class AKONADICORE_EXPORT PartFetcher : public KJob
61 {
62  Q_OBJECT
63 
64 public:
65  /**
66  * Creates a new part fetcher.
67  *
68  * @param index The index of the item to fetch the part from.
69  * @param partName The name of the payload part to fetch.
70  * @param parent The parent object.
71  */
72  PartFetcher(const QModelIndex &index, const QByteArray &partName, QObject *parent = nullptr);
73 
74  /**
75  * Destroys the part fetcher.
76  */
77  ~PartFetcher() override;
78 
79  /**
80  * Starts the fetch operation.
81  */
82  void start() override;
83 
84  /**
85  * Returns the index of the item the part was fetched from.
86  */
87  QModelIndex index() const;
88 
89  /**
90  * Returns the name of the part that has been fetched.
91  */
92  QByteArray partName() const;
93 
94  /**
95  * Returns the item that contains the fetched payload part.
96  */
97  Item item() const;
98 
99 private:
100  /// @cond PRIVATE
101  Q_DECLARE_PRIVATE(Akonadi::PartFetcher)
102  std::unique_ptr<PartFetcherPrivate> const d_ptr;
103 
104  /// @endcond
105 };
106 
107 }
108 
Q_SCRIPTABLE Q_NOREPLY void start()
Convenience class for getting payload parts from an Akonadi Model.
Definition: partfetcher.h:60
Represents a PIM item stored in Akonadi storage.
Definition: item.h:104
Helper integration between Akonadi and Qt.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Jun 25 2022 06:00:32 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.