File indexing completed on 2025-01-05 03:53:25

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2008-12-26
0007  * Description : a tool to export items to Facebook web service
0008  *
0009  * SPDX-FileCopyrightText: 2008-2009 by Luka Renko <lure at kubuntu dot org>
0010  * SPDX-FileCopyrightText: 2008-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0011  * SPDX-FileCopyrightText: 2018      by Thanh Trung Dinh <dinhthanhtrung1996 at gmail dot com>
0012  *
0013  * SPDX-License-Identifier: GPL-2.0-or-later
0014  *
0015  * ============================================================ */
0016 
0017 #ifndef DIGIKAM_FB_TALKER_H
0018 #define DIGIKAM_FB_TALKER_H
0019 
0020 // Qt includes
0021 
0022 #include <QList>
0023 #include <QString>
0024 #include <QTime>
0025 #include <QObject>
0026 #include <QUrl>
0027 #include <QNetworkReply>
0028 #include <QMap>
0029 
0030 // Local includes
0031 
0032 #include "fbitem.h"
0033 
0034 class QDomElement;
0035 
0036 namespace DigikamGenericFaceBookPlugin
0037 {
0038 
0039 class FbTalker : public QObject
0040 {
0041     Q_OBJECT
0042 
0043 public:
0044 
0045     explicit FbTalker(QWidget* const parent);
0046     ~FbTalker();
0047 
0048     void    link();
0049     void    unlink();
0050     bool    linked();
0051     void    cancel();
0052 
0053     FbUser  getUser() const;
0054 
0055     void    logout();
0056 
0057     void    listAlbums(long long userID = 0);
0058 
0059     void    createAlbum(const FbAlbum& album);
0060 
0061     void    addPhoto(const QString& imgPath, const QString& albumID,
0062                      const QString& caption);
0063 
0064     void    readSettings();
0065     void    writeSettings();
0066 
0067 Q_SIGNALS:
0068 
0069     void    signalBusy(bool val);
0070     void    signalListAlbumsDone(int errCode, const QString& errMsg, const QList <FbAlbum>& albumsList);
0071     void    signalCreateAlbumDone(int errCode, const QString& errMsg, const QString& newAlbumId);
0072     void    signalAddPhotoDone(int errCode, const QString& errMsg);
0073     void    signalLoginProgress(int step, int maxStep = 0, const QString& label = QString());
0074     void    signalLoginDone(int errCode, const QString& errMsg);
0075     void    linkingSucceeded();
0076 
0077 private:
0078 
0079     void    getLoggedInUser();
0080 
0081     QString errorToText(int errCode, const QString& errMsg);
0082     int     parseErrorResponse(const QDomElement& e, QString& errMsg);
0083     void    parseResponseGetLoggedInUser(const QByteArray& data);
0084     void    parseResponseAddPhoto(const QByteArray& data);
0085     void    parseResponseCreateAlbum(const QByteArray& data);
0086     void    parseResponseListAlbums(const QByteArray& data);
0087     void    parseResponseLogoutUser();
0088 
0089 private Q_SLOTS:
0090 
0091     void    slotLinkingSucceeded();
0092     void    slotCatchUrl(const QUrl& url);
0093     void    slotFinished(QNetworkReply* reply);
0094 
0095 private:
0096 
0097     class Private;
0098     Private* const d;
0099 };
0100 
0101 } // namespace DigikamGenericFaceBookPlugin
0102 
0103 #endif // DIGIKAM_FB_TALKER_H