File indexing completed on 2024-05-05 08:54:28
0001 /** =========================================================== 0002 * @file 0003 * 0004 * This file is a part of KDE project 0005 * <a href="https://commits.kde.org/libmediawiki">libmediawiki</a> 0006 * 0007 * @date 2011-03-22 0008 * @brief a MediaWiki C++ interface for KDE 0009 * 0010 * @author Copyright (C) 2011-2012 by Gilles Caulier 0011 * <a href="mailto:caulier dot gilles at gmail dot com">caulier dot gilles at gmail dot com</a> 0012 * @author Copyright (C) 2011 by Alexandre Mendes 0013 * <a href="mailto:alex dot mendes1988 at gmail dot com">alex dot mendes1988 at gmail dot com</a> 0014 * 0015 * This program is free software; you can redistribute it 0016 * and/or modify it under the terms of the GNU General 0017 * Public License as published by the Free Software Foundation; 0018 * either version 2, or (at your option) 0019 * any later version. 0020 * 0021 * This program is distributed in the hope that it will be useful, 0022 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0023 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0024 * GNU General Public License for more details. 0025 * 0026 * ============================================================ */ 0027 0028 #ifndef MEDIAWIKI_UPLOAD_H 0029 #define MEDIAWIKI_UPLOAD_H 0030 0031 // Qt includes 0032 0033 #include <QIODevice> 0034 #include <QString> 0035 #include <QDateTime> 0036 #include <QNetworkCookieJar> 0037 #include <QUrl> 0038 0039 // Local includes 0040 0041 #include "mediawiki_export.h" 0042 #include "job.h" 0043 #include "queryinfo.h" 0044 0045 namespace mediawiki 0046 { 0047 0048 class MediaWiki; 0049 class UploadPrivate; 0050 0051 /** 0052 * @brief Upload job. 0053 * 0054 * Uses for upload files. 0055 */ 0056 class MEDIAWIKI_EXPORT Upload : public Job 0057 { 0058 Q_OBJECT 0059 Q_DECLARE_PRIVATE(Upload) 0060 0061 public: 0062 0063 enum 0064 { 0065 /** 0066 * @brief An internal error occurred. 0067 */ 0068 InternalError= Job::UserDefinedError+1, 0069 /** 0070 * @brief The module is disabled. 0071 */ 0072 UploadDisabled, 0073 0074 /** 0075 * @brief The session key is invalid. 0076 */ 0077 InvalidSessionKey, 0078 0079 /** 0080 * @brief The current user can't upload. 0081 */ 0082 BadAccess, 0083 0084 /** 0085 * @brief A param is missing. 0086 */ 0087 ParamMissing, 0088 0089 /** 0090 * @brief No upload without logged in. 0091 */ 0092 MustBeLoggedIn, 0093 0094 /** 0095 * @brief 0096 */ 0097 FetchFileError, 0098 0099 /** 0100 * @brief No upload module set. 0101 */ 0102 NoModule, 0103 0104 /** 0105 * @brief The file submitted was empty. 0106 */ 0107 EmptyFile, 0108 0109 /** 0110 * @brief The file is missing an extension. 0111 */ 0112 ExtensionMissing, 0113 0114 /** 0115 * @brief The filename is too short. 0116 */ 0117 TooShortFilename, 0118 0119 /** 0120 * @brief Overwriting an existing file is not allowed. 0121 */ 0122 OverWriting, 0123 0124 /** 0125 * @brief Stashing temporary file failed. 0126 */ 0127 StashFailed 0128 }; 0129 0130 public: 0131 0132 /** 0133 * @brief Constructs an Upload job. 0134 * @param parent the QObject parent 0135 */ 0136 Upload(MediaWiki& mediawiki, QObject* const parent = nullptr); 0137 0138 /** 0139 * @brief Destroys the Upload job. 0140 */ 0141 ~Upload() override; 0142 0143 /** 0144 * @brief Starts the job asynchronously. 0145 */ 0146 void start() override; 0147 0148 /** 0149 * @brief Set the target filename. 0150 * @param filename the filename 0151 */ 0152 void setFilename(const QString&); 0153 0154 /** 0155 * @brief Set the file. 0156 * @param file the file 0157 */ 0158 void setFile(QIODevice* const); 0159 0160 /** 0161 * @brief Set the upload comment. Also used as the initial page text for new files if text parameter not provided. 0162 * @param comment the comment 0163 */ 0164 void setComment(const QString&); 0165 0166 /** 0167 * @brief Set the information of the image. Use this template {{Information|Description=|Source=|Date=|Author=|Permission=|other_versions=}}. 0168 * @param text the text 0169 */ 0170 void setText(const QString&); 0171 0172 private Q_SLOTS: 0173 0174 void doWorkSendRequest(Page page); 0175 void doWorkProcessReply(); 0176 }; 0177 0178 } // namespace mediawiki 0179 0180 #endif // UPLOAD_H