1 /* ============================================================ 2 * 3 * This file is a part of digiKam project 4 * https://www.digikam.org 5 * 6 * Date : 2018-07-03 7 * Description : Web Service authentication container. 8 * 9 * Copyright (C) 2018 by Thanh Trung Dinh <dinhthanhtrung1996 at gmail dot com> 10 * 11 * This program is free software; you can redistribute it 12 * and/or modify it under the terms of the GNU General 13 * Public License as published by the Free Software Foundation; 14 * either version 2, or (at your option) any later version. 15 * 16 * This program is distributed in the hope that it will be useful, 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 * GNU General Public License for more details. 20 * 21 * ============================================================ */ 22 23 #ifndef DIGIKAM_WS_AUTHENTICATION_H 24 #define DIGIKAM_WS_AUTHENTICATION_H 25 26 // Qt includes 27 28 #include <QtGlobal> 29 #include <QString> 30 #include <QUrl> 31 #include <QWidget> 32 #include <QMap> 33 #include <QSettings> 34 #include <QStringList> 35 #include <QList> 36 37 // Local includes 38 39 #include "dinfointerface.h" 40 #include "wssettings.h" 41 #include "wsitem.h" 42 43 using namespace Digikam; 44 45 namespace DigikamGenericUnifiedPlugin 46 { 47 48 class WSAuthentication : public QObject 49 { 50 Q_OBJECT 51 52 public: 53 54 explicit WSAuthentication(QWidget* const parent, DInfoInterface* const iface=0); 55 ~WSAuthentication(); 56 57 /* 58 * Return selected web service by user 59 */ 60 QString webserviceName(); 61 62 /* 63 * Create appropriate album dialog (filling form for creating new album). 64 * Create appropriate talker for selected web service by user. 65 */ 66 void createTalker(WSSettings::WebService ws, const QString& serviceName=QString()); 67 /* 68 * Wrapper of talker->cancel() 69 */ 70 void cancelTalker(); 71 72 /* 73 * Wrapper of talker->authenticate() 74 */ 75 void authenticate(); 76 /* 77 * Wrapper of talker->reauthenticate() 78 */ 79 void reauthenticate(); 80 /* 81 * Wrapper of talker->linked() 82 */ 83 bool authenticated() const; 84 85 /* 86 * Get image title, comment -> concat all and return a string. 87 */ 88 QString getImageCaption(const QString& fileName); 89 /* 90 * Image processing before uploading (compress, reformat, add/remove metadata) 91 */ 92 void prepareForUpload(); 93 94 /* 95 * Return number of images to upload 96 */ 97 unsigned int numberItemsUpload(); 98 /* 99 * Upload photo to web service (one at a time). 100 * This method is called for the first time in startTransfer. 101 * Then each time a photo is uploaded successfully, this method 102 * will be called in slotAddPhotoDone(...) 103 */ 104 void uploadNextPhoto(); 105 /* 106 * Begin transferring photos by calling uploadNextPhoto() 107 */ 108 void startTransfer(); 109 110 private: 111 112 /* 113 * Parse albums list to a map of pairs <album_id, content> and a list of 114 * albums at the very top level (root of other albums). 115 */ 116 void parseTreeFromListAlbums(const QList <WSAlbum>& albumsList, 117 QMap<QString, AlbumSimplified>& albumTree, 118 QStringList& rootAlbums); 119 120 Q_SIGNALS: 121 122 /* 123 * Connect WSTalker to WSAuthentication 124 */ 125 void signalOpenBrowser(const QUrl&); 126 void signalCloseBrowser(); 127 void signalAuthenticationComplete(bool); 128 129 /* 130 * Connect WSAuthenticationPage to WSAuthentication 131 */ 132 void signalResponseTokenReceived(const QMap<QString, QString>&); 133 134 /* 135 * Connect WSAuthentication to WSImagePage 136 */ 137 void signalCreateAlbumDone(int errCode, const QString& errMsg, const QString& newAlbumId); 138 void signalListAlbumsDone(const QMap<QString, AlbumSimplified>&, const QStringList&, const QString&); 139 140 /* 141 * Connect WSAuthentication to WSFinalPage 142 */ 143 void signalProgress(int); 144 void signalMessage(const QString&, bool); 145 void signalDone(); 146 147 public Q_SLOTS: 148 149 /* 150 * Cancel talker and purge temporary files 151 */ 152 void slotCancel(); 153 154 /* 155 * Request from WSImagePage 156 */ 157 void slotNewAlbumRequest(); 158 void slotListAlbumsRequest(); 159 160 /* 161 * Handle signals for these functionalities from Talker 162 */ 163 void slotListAlbumsDone(int errCode, const QString& errMsg, const QList<WSAlbum>& albumsList); 164 void slotAddPhotoDone(int errCode, const QString& errMsg); 165 166 private: 167 168 class Private; 169 Private* const d; 170 }; 171 172 } // namespace DigikamGenericUnifiedPlugin 173 174 #endif // DIGIKAM_WS_AUTHENTICATION_H 175