File indexing completed on 2025-01-05 03:53:37
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2011-03-22 0007 * Description : a Iface C++ interface 0008 * 0009 * SPDX-FileCopyrightText: 2011-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0010 * SPDX-FileCopyrightText: 2011 by Alexandre Mendes <alex dot mendes1988 at gmail dot com> 0011 * 0012 * SPDX-License-Identifier: GPL-2.0-or-later 0013 * 0014 * ============================================================ */ 0015 0016 #ifndef DIGIKAM_MEDIAWIKI_UPLOAD_H 0017 #define DIGIKAM_MEDIAWIKI_UPLOAD_H 0018 0019 // Qt includes 0020 0021 #include <QIODevice> 0022 #include <QString> 0023 #include <QDateTime> 0024 #include <QNetworkCookieJar> 0025 #include <QUrl> 0026 0027 // Local includes 0028 0029 0030 #include "mediawiki_job.h" 0031 #include "mediawiki_queryinfo.h" 0032 0033 namespace MediaWiki 0034 { 0035 0036 class Iface; 0037 class UploadPrivate; 0038 0039 /** 0040 * @brief Upload job. 0041 * 0042 * Uses for upload files. 0043 */ 0044 class Upload : public Job 0045 { 0046 Q_OBJECT 0047 Q_DECLARE_PRIVATE(Upload) 0048 0049 public: 0050 0051 enum 0052 { 0053 /** 0054 * @brief An internal error occurred. 0055 */ 0056 InternalError= Job::UserDefinedError+1, 0057 /** 0058 * @brief The module is disabled. 0059 */ 0060 UploadDisabled, 0061 0062 /** 0063 * @brief The session key is invalid. 0064 */ 0065 InvalidSessionKey, 0066 0067 /** 0068 * @brief The current user can't upload. 0069 */ 0070 BadAccess, 0071 0072 /** 0073 * @brief A param is missing. 0074 */ 0075 ParamMissing, 0076 0077 /** 0078 * @brief No upload without logged in. 0079 */ 0080 MustBeLoggedIn, 0081 0082 /** 0083 * @brief 0084 */ 0085 FetchFileError, 0086 0087 /** 0088 * @brief No upload module set. 0089 */ 0090 NoModule, 0091 0092 /** 0093 * @brief The file submitted was empty. 0094 */ 0095 EmptyFile, 0096 0097 /** 0098 * @brief The file is missing an extension. 0099 */ 0100 ExtensionMissing, 0101 0102 /** 0103 * @brief The filename is too short. 0104 */ 0105 TooShortFilename, 0106 0107 /** 0108 * @brief Overwriting an existing file is not allowed. 0109 */ 0110 OverWriting, 0111 0112 /** 0113 * @brief Stashing temporary file failed. 0114 */ 0115 StashFailed 0116 }; 0117 0118 public: 0119 0120 /** 0121 * @brief Constructs an Upload job. 0122 * @param parent the QObject parent 0123 */ 0124 explicit Upload(Iface& MediaWiki, QObject* const parent = nullptr); 0125 0126 /** 0127 * @brief Destroys the Upload job. 0128 */ 0129 ~Upload() override; 0130 0131 /** 0132 * @brief Starts the job asynchronously. 0133 */ 0134 void start() override; 0135 0136 /** 0137 * @brief Set the target filename. 0138 * @param filename the filename 0139 */ 0140 void setFilename(const QString&); 0141 0142 /** 0143 * @brief Set the file. 0144 * @param file the file 0145 */ 0146 void setFile(QIODevice* const); 0147 0148 /** 0149 * @brief Set the upload comment. Also used as the initial page text for new files if text parameter not provided. 0150 * @param comment the comment 0151 */ 0152 void setComment(const QString&); 0153 0154 /** 0155 * @brief Set the information of the image. Use this template {{Information|Description=|Source=|Date=|Author=|Permission=|other_versions=}}. 0156 * @param text the text 0157 */ 0158 void setText(const QString&); 0159 0160 private Q_SLOTS: 0161 0162 void doWorkSendRequest(const Page& page); 0163 void doWorkProcessReply(); 0164 }; 0165 0166 } // namespace MediaWiki 0167 0168 #endif // UPLOAD_H