File indexing completed on 2025-01-19 03:53:14
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2018-06-29 0007 * Description : a tool to export images to Twitter social network 0008 * 0009 * SPDX-FileCopyrightText: 2018 by Tarek Talaat <tarektalaat93 at gmail dot com> 0010 * 0011 * SPDX-License-Identifier: GPL-2.0-or-later 0012 * 0013 * ============================================================ */ 0014 0015 #ifndef DIGIKAM_TWITTER_TALKER_H 0016 #define DIGIKAM_TWITTER_TALKER_H 0017 0018 // Qt includes 0019 0020 #include <QList> 0021 #include <QPair> 0022 #include <QString> 0023 #include <QNetworkReply> 0024 0025 // OAuth2 library includes 0026 0027 #if defined(Q_CC_CLANG) 0028 # pragma clang diagnostic push 0029 # pragma clang diagnostic ignored "-Wextra-semi" 0030 #endif 0031 0032 #include "o2.h" 0033 #include "o0globals.h" 0034 #include "o1twitter.h" 0035 0036 #if defined(Q_CC_CLANG) 0037 # pragma clang diagnostic pop 0038 #endif 0039 0040 // Local includes 0041 0042 #include "twitteritem.h" 0043 #include "dmetadata.h" 0044 0045 using namespace Digikam; 0046 0047 namespace DigikamGenericTwitterPlugin 0048 { 0049 0050 class TwTalker : public QObject 0051 { 0052 Q_OBJECT 0053 0054 public: 0055 0056 explicit TwTalker(QWidget* const parent); 0057 ~TwTalker() override; 0058 0059 public: 0060 0061 void link(); 0062 void unLink(); 0063 void getUserName(); 0064 bool authenticated(); 0065 void cancel(); 0066 bool addPhoto(const QString& imgPath, const QString& uploadFolder, bool rescale, int maxDim, int imageQuality); 0067 void listFolders(const QString& path = QString()); 0068 void createFolder(QString& path); 0069 void setAccessToken(const QString& token); 0070 QMap<QString, QString> ParseUrlParameters(const QString& url); 0071 void createTweet(const QString& mediaId); 0072 0073 bool addPhotoSingleUpload(const QString& imgPath); 0074 0075 bool addPhotoInit(const QString& imgPath); 0076 bool addPhotoAppend(const QString& mediaId, int segmentIndex=0); 0077 bool addPhotoFinalize(const QString& mediaId); 0078 0079 Q_SIGNALS: 0080 0081 void signalBusy(bool val); 0082 void signalLinkingSucceeded(); 0083 void signalLinkingFailed(); 0084 void signalSetUserName(const QString& msg); 0085 void signalListAlbumsFailed(const QString& msg); 0086 void signalListAlbumsDone(const QList<QPair<QString, QString> >& list); 0087 void signalCreateFolderFailed(const QString& msg); 0088 void signalCreateFolderSucceeded(); 0089 void signalAddPhotoFailed(const QString& msg); 0090 void signalAddPhotoSucceeded(); 0091 void twitterLinkingSucceeded(); 0092 void twitterLinkingFailed(); 0093 0094 private Q_SLOTS: 0095 0096 void slotLinkingFailed(); 0097 void slotLinkingSucceeded(); 0098 void slotOpenBrowser(const QUrl& url); 0099 void slotFinished(QNetworkReply* reply); 0100 0101 void slotCheckUploadStatus(); 0102 0103 private: 0104 0105 void parseResponseUserName(const QByteArray& data); 0106 void parseResponseListFolders(const QByteArray& data); 0107 void parseResponseCreateFolder(const QByteArray& data); 0108 void parseResponseAddPhoto(const QByteArray& data); 0109 void parseResponseAddPhotoInit(const QByteArray& data); 0110 void parseResponseAddPhotoAppend(const QByteArray& data, int segmentIndex); 0111 void parseResponseAddPhotoFinalize(const QByteArray& data); 0112 void parseResponseCreateTweet(const QByteArray& data); 0113 void parseCheckUploadStatus(const QByteArray& data); 0114 0115 private: 0116 0117 class Private; 0118 Private* const d; 0119 }; 0120 0121 } // namespace DigikamGenericTwitterPlugin 0122 0123 #endif // DIGIKAM_TWITTER_TALKER_H