File indexing completed on 2024-04-28 03:56:27
0001 /* 0002 SPDX-FileCopyrightText: 2023 Aleix Pol Gonzalez <aleixpol@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.1-or-later 0005 */ 0006 0007 #ifndef KNEWSTUFF3_TRANSACTION_H 0008 #define KNEWSTUFF3_TRANSACTION_H 0009 0010 #include <QObject> 0011 #include <memory> 0012 0013 #include "entry.h" 0014 #include "errorcode.h" 0015 0016 #include "knewstuffcore_export.h" 0017 0018 namespace KNSCore 0019 { 0020 class EngineBase; 0021 class TransactionPrivate; 0022 0023 /** 0024 * KNewStuff Transaction 0025 * 0026 * Exposes different actions that can be done on an entry and means to track them to completion. 0027 * 0028 * To create a Transaction we should call one of the static methods that 0029 * represent the different actions we can take. These will return the Transaction 0030 * and we can use it to track mesages, the entries' states and eventually its 0031 * completion using the @m finished signal. 0032 * 0033 * The Transaction will delete itself once it has finished. 0034 * 0035 * @since 6.0 0036 */ 0037 class KNEWSTUFFCORE_EXPORT Transaction : public QObject 0038 { 0039 Q_OBJECT 0040 public: 0041 ~Transaction() override; 0042 0043 /** 0044 * Performs an install on the given @p entry from the @p engine. 0045 * 0046 * @param linkId specifies which of the assets we want to see installed. 0047 * @returns a Transaction object that we can use to track the progress to completion 0048 */ 0049 static Transaction *install(EngineBase *engine, const Entry &entry, int linkId = 1); 0050 0051 /** 0052 * Uninstalls the given @p entry from the @p engine. 0053 * 0054 * It reverses the step done when @m install was called. 0055 * @returns a Transaction object that we can use to track the progress to completion 0056 */ 0057 static Transaction *uninstall(EngineBase *engine, const Entry &entry); 0058 0059 /** 0060 * Adopt the @p entry from @p engine using the adoption command. 0061 * 0062 * For more information, see the documentation about AdoptionCommand from 0063 * the knsrc file. 0064 */ 0065 static Transaction *adopt(EngineBase *engine, const Entry &entry); 0066 0067 /** 0068 * @returns true as soon as the Transaction is completed as it gets ready to 0069 * clean itself up 0070 */ 0071 bool isFinished() const; 0072 0073 Q_SIGNALS: 0074 void finished(); 0075 0076 /** 0077 * Provides the @p message to update our users about how the Transaction progressed 0078 */ 0079 void signalMessage(const QString &message); 0080 0081 /** 0082 * Informs about how the @p entry has changed 0083 * 0084 * @param event nature of the change 0085 */ 0086 void signalEntryEvent(const KNSCore::Entry &entry, KNSCore::Entry::EntryEvent event); 0087 0088 /** 0089 * Fires in the case of any critical or serious errors, such as network or API problems. 0090 * @param errorCode Represents the specific type of error which has occurred 0091 * @param message A human-readable message which can be shown to the end user 0092 * @param metadata Any additional data which might be hepful to further work out the details of the error (see KNSCore::Entry::ErrorCode for the 0093 * metadata details) 0094 * @see KNSCore::Entry::ErrorCode 0095 */ 0096 void signalErrorCode(KNSCore::ErrorCode::ErrorCode errorCode, const QString &message, const QVariant &metadata); 0097 0098 private: 0099 Transaction(const KNSCore::Entry &entry, EngineBase *engine); 0100 void downloadLinkLoaded(const KNSCore::Entry &entry); 0101 0102 std::unique_ptr<TransactionPrivate> d; 0103 }; 0104 0105 } 0106 0107 #endif