File indexing completed on 2025-01-05 03:53:44
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2018-07-03 0007 * Description : Web Service authentication container. 0008 * 0009 * SPDX-FileCopyrightText: 2018 by Thanh Trung Dinh <dinhthanhtrung1996 at gmail dot com> 0010 * 0011 * SPDX-License-Identifier: GPL-2.0-or-later 0012 * 0013 * ============================================================ */ 0014 0015 #ifndef DIGIKAM_WS_AUTHENTICATION_H 0016 #define DIGIKAM_WS_AUTHENTICATION_H 0017 0018 // Qt includes 0019 0020 #include <QtGlobal> 0021 #include <QString> 0022 #include <QUrl> 0023 #include <QWidget> 0024 #include <QMap> 0025 #include <QSettings> 0026 #include <QStringList> 0027 #include <QList> 0028 0029 // Local includes 0030 0031 #include "dinfointerface.h" 0032 #include "wssettings.h" 0033 #include "wsitem.h" 0034 0035 using namespace Digikam; 0036 0037 namespace DigikamGenericUnifiedPlugin 0038 { 0039 0040 class WSAuthentication : public QObject 0041 { 0042 Q_OBJECT 0043 0044 public: 0045 0046 explicit WSAuthentication(QWidget* const parent, DInfoInterface* const iface=0); 0047 ~WSAuthentication(); 0048 0049 /* 0050 * Return selected web service by user 0051 */ 0052 QString webserviceName(); 0053 0054 /* 0055 * Create appropriate album dialog (filling form for creating new album). 0056 * Create appropriate talker for selected web service by user. 0057 */ 0058 void createTalker(WSSettings::WebService ws, const QString& serviceName=QString()); 0059 /* 0060 * Wrapper of talker->cancel() 0061 */ 0062 void cancelTalker(); 0063 0064 /* 0065 * Wrapper of talker->authenticate() 0066 */ 0067 void authenticate(); 0068 /* 0069 * Wrapper of talker->reauthenticate() 0070 */ 0071 void reauthenticate(); 0072 /* 0073 * Wrapper of talker->linked() 0074 */ 0075 bool authenticated() const; 0076 0077 /* 0078 * Get image title, comment -> concat all and return a string. 0079 */ 0080 QString getImageCaption(const QString& fileName); 0081 /* 0082 * Image processing before uploading (compress, reformat, add/remove metadata) 0083 */ 0084 void prepareForUpload(); 0085 0086 /* 0087 * Return number of images to upload 0088 */ 0089 unsigned int numberItemsUpload(); 0090 /* 0091 * Upload photo to web service (one at a time). 0092 * This method is called for the first time in startTransfer. 0093 * Then each time a photo is uploaded successfully, this method 0094 * will be called in slotAddPhotoDone(...) 0095 */ 0096 void uploadNextPhoto(); 0097 /* 0098 * Begin transferring photos by calling uploadNextPhoto() 0099 */ 0100 void startTransfer(); 0101 0102 private: 0103 0104 /* 0105 * Parse albums list to a map of pairs <album_id, content> and a list of 0106 * albums at the very top level (root of other albums). 0107 */ 0108 void parseTreeFromListAlbums(const QList <WSAlbum>& albumsList, 0109 QMap<QString, AlbumSimplified>& albumTree, 0110 QStringList& rootAlbums); 0111 0112 Q_SIGNALS: 0113 0114 /* 0115 * Connect WSTalker to WSAuthentication 0116 */ 0117 void signalOpenBrowser(const QUrl&); 0118 void signalCloseBrowser(); 0119 void signalAuthenticationComplete(bool); 0120 0121 /* 0122 * Connect WSAuthenticationPage to WSAuthentication 0123 */ 0124 void signalResponseTokenReceived(const QMap<QString, QString>&); 0125 0126 /* 0127 * Connect WSAuthentication to WSImagePage 0128 */ 0129 void signalCreateAlbumDone(int errCode, const QString& errMsg, const QString& newAlbumId); 0130 void signalListAlbumsDone(const QMap<QString, AlbumSimplified>&, const QStringList&, const QString&); 0131 0132 /* 0133 * Connect WSAuthentication to WSFinalPage 0134 */ 0135 void signalProgress(int); 0136 void signalMessage(const QString&, bool); 0137 void signalDone(); 0138 0139 public Q_SLOTS: 0140 0141 /* 0142 * Cancel talker and purge temporary files 0143 */ 0144 void slotCancel(); 0145 0146 /* 0147 * Request from WSImagePage 0148 */ 0149 void slotNewAlbumRequest(); 0150 void slotListAlbumsRequest(); 0151 0152 /* 0153 * Handle signals for these functionalities from Talker 0154 */ 0155 void slotListAlbumsDone(int errCode, const QString& errMsg, const QList<WSAlbum>& albumsList); 0156 void slotAddPhotoDone(int errCode, const QString& errMsg); 0157 0158 private: 0159 0160 class Private; 0161 Private* const d; 0162 }; 0163 0164 } // namespace DigikamGenericUnifiedPlugin 0165 0166 #endif // DIGIKAM_WS_AUTHENTICATION_H