File indexing completed on 2024-11-10 04:40:31
0001 /* 0002 SPDX-FileCopyrightText: 2009 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "akonadicore_export.h" 0010 #include "job.h" 0011 0012 namespace Akonadi 0013 { 0014 class ResourceSelectJobPrivate; 0015 0016 /** 0017 * @internal 0018 * 0019 * @short Job that selects a resource context for remote identifier based operations. 0020 * 0021 * This job selects a resource context that is used whenever remote identifier 0022 * based operations ( e.g. fetch items or collections by remote identifier ) are 0023 * executed. 0024 * 0025 * Example: 0026 * 0027 * @code 0028 * 0029 * using namespace Akonadi; 0030 * 0031 * // Find out the akonadi id of the item with the remote id 'd1627013c6d5a2e7bb58c12560c27047' 0032 * // that is stored in the resource with identifier 'my_mail_resource' 0033 * 0034 * Session *m_resourceSession = new Session( "resourceSession" ); 0035 * 0036 * ResourceSelectJob *job = new ResourceSelectJob( "my_mail_resource", resourceSession ); 0037 * 0038 * connect( job, SIGNAL(result(KJob*)), SLOT(resourceSelected(KJob*)) ); 0039 * ... 0040 * 0041 * void resourceSelected( KJob *job ) 0042 * { 0043 * if ( job->error() ) 0044 * return; 0045 * 0046 * Item item; 0047 * item.setRemoteIdentifier( "d1627013c6d5a2e7bb58c12560c27047" ); 0048 * 0049 * ItemFetchJob *fetchJob = new ItemFetchJob( item, m_resourceSession ); 0050 * connect( fetchJob, SIGNAL(result(KJob*)), SLOT(itemFetched(KJob*)) ); 0051 * } 0052 * 0053 * void itemFetched( KJob *job ) 0054 * { 0055 * if ( job->error() ) 0056 * return; 0057 * 0058 * const Item item = job->items().at(0); 0059 * 0060 * qDebug() << "Remote id" << item.remoteId() << "has akonadi id" << item.id(); 0061 * } 0062 * 0063 * @endcode 0064 * 0065 * @author Volker Krause <vkrause@kde.org> 0066 */ 0067 class AKONADICORE_EXPORT ResourceSelectJob : public Job 0068 { 0069 Q_OBJECT 0070 public: 0071 /** 0072 * Selects the specified resource for all following remote identifier 0073 * based operations in the same session. 0074 * 0075 * @param identifier The resource identifier, or any empty string to reset 0076 * the selection. 0077 * @param parent The parent object. 0078 */ 0079 explicit ResourceSelectJob(const QString &identifier, QObject *parent = nullptr); 0080 0081 protected: 0082 void doStart() override; 0083 bool doHandleResponse(qint64 tag, const Protocol::CommandPtr &response) override; 0084 0085 private: 0086 /// @cond PRIVATE 0087 Q_DECLARE_PRIVATE(ResourceSelectJob) 0088 /// @endcond 0089 }; 0090 0091 }