File indexing completed on 2024-05-26 05:14:15
0001 /* 0002 SPDX-FileCopyrightText: 2009 Stephen Kelly <steveire@gmail.com> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <KJob> 0010 0011 #include "akonadicore_export.h" 0012 0013 #include <memory> 0014 0015 class QModelIndex; 0016 0017 namespace Akonadi 0018 { 0019 class Item; 0020 class PartFetcherPrivate; 0021 0022 /** 0023 * @short Convenience class for getting payload parts from an Akonadi Model. 0024 * 0025 * This class can be used to retrieve individual payload parts from an EntityTreeModel, 0026 * and fetch them asynchronously from the Akonadi storage if necessary. 0027 * 0028 * The requested part is emitted though the partFetched signal. 0029 * 0030 * Example: 0031 * 0032 * @code 0033 * 0034 * const QModelIndex index = view->selectionModel()->currentIndex(); 0035 * 0036 * PartFetcher *fetcher = new PartFetcher( index, Akonadi::MessagePart::Envelope ); 0037 * connect( fetcher, SIGNAL(result(KJob*)), SLOT(fetchResult(KJob*)) ); 0038 * fetcher->start(); 0039 * 0040 * ... 0041 * 0042 * MyClass::fetchResult( KJob *job ) 0043 * { 0044 * if ( job->error() ) { 0045 * qDebug() << job->errorText(); 0046 * return; 0047 * } 0048 * 0049 * PartFetcher *fetcher = qobject_cast<PartFetcher*>( job ); 0050 * 0051 * const Item item = fetcher->item(); 0052 * // do something with the item 0053 * } 0054 * 0055 * @endcode 0056 * 0057 * @author Stephen Kelly <steveire@gmail.com> 0058 * @since 4.4 0059 */ 0060 class AKONADICORE_EXPORT PartFetcher : public KJob 0061 { 0062 Q_OBJECT 0063 0064 public: 0065 /** 0066 * Creates a new part fetcher. 0067 * 0068 * @param index The index of the item to fetch the part from. 0069 * @param partName The name of the payload part to fetch. 0070 * @param parent The parent object. 0071 */ 0072 PartFetcher(const QModelIndex &index, const QByteArray &partName, QObject *parent = nullptr); 0073 0074 /** 0075 * Destroys the part fetcher. 0076 */ 0077 ~PartFetcher() override; 0078 0079 /** 0080 * Starts the fetch operation. 0081 */ 0082 void start() override; 0083 0084 /** 0085 * Returns the index of the item the part was fetched from. 0086 */ 0087 QModelIndex index() const; 0088 0089 /** 0090 * Returns the name of the part that has been fetched. 0091 */ 0092 QByteArray partName() const; 0093 0094 /** 0095 * Returns the item that contains the fetched payload part. 0096 */ 0097 Item item() const; 0098 0099 private: 0100 /// @cond PRIVATE 0101 Q_DECLARE_PRIVATE(Akonadi::PartFetcher) 0102 std::unique_ptr<PartFetcherPrivate> const d_ptr; 0103 0104 /// @endcond 0105 }; 0106 0107 }