Warning, file /graphics/kipi-plugins/facebook/fbtalker.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /* ============================================================
0002  *
0003  * This file is a part of KDE project
0004  *
0005  *
0006  * Date        : 2008-12-26
0007  * Description : a kipi plugin to export images to Facebook web service
0008  *
0009  * Copyright (C) 2008-2009 by Luka Renko <lure at kubuntu dot org>
0010  *
0011  * This program is free software; you can redistribute it
0012  * and/or modify it under the terms of the GNU General
0013  * Public License as published by the Free Software Foundation;
0014  * either version 2, or (at your option) any later version.
0015  *
0016  * This program is distributed in the hope that it will be useful,
0017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0019  * GNU General Public License for more details.
0020  *
0021  * ============================================================ */
0022 
0023 #ifndef FBTALKER_H
0024 #define FBTALKER_H
0025 
0026 // Qt includes
0027 
0028 #include <QList>
0029 #include <QString>
0030 #include <QTime>
0031 #include <QObject>
0032 #include <QUrl>
0033 #include <QNetworkReply>
0034 #include <QNetworkAccessManager>
0035 
0036 // local includes
0037 
0038 #include "fbitem.h"
0039 
0040 class QDomElement;
0041 class QDialog;
0042 
0043 namespace KIPIFacebookPlugin
0044 {
0045 
0046 class FbTalker : public QObject
0047 {
0048     Q_OBJECT
0049 
0050 public:
0051 
0052     FbTalker(QWidget* const parent);
0053     ~FbTalker();
0054 
0055     QString      getAccessToken()    const;
0056     unsigned int getSessionExpires() const;
0057 
0058     FbUser  getUser() const;
0059 
0060     bool    loggedIn() const;
0061     void    cancel();
0062     void    authenticate(const QString& accessToken,  unsigned int sessionExpires);
0063     void    exchangeSession(const QString& sessionKey);
0064     void    logout();
0065 
0066     void    listAlbums(long long userID = 0);
0067 
0068     void    createAlbum(const FbAlbum& album);
0069 
0070     bool    addPhoto(const QString& imgPath, const QString& albumID,
0071                      const QString& caption);
0072 
0073 Q_SIGNALS:
0074 
0075     void signalBusy(bool val);
0076     void signalLoginProgress(int step, int maxStep = 0, const QString& label = QString());
0077     void signalLoginDone(int errCode, const QString& errMsg);
0078     void signalAddPhotoDone(int errCode, const QString& errMsg);
0079     void signalCreateAlbumDone(int errCode, const QString& errMsg, const QString &newAlbumID);
0080     void signalListAlbumsDone(int errCode, const QString& errMsg, const QList <FbAlbum>& albumsList);
0081 
0082 private:
0083 
0084     enum State
0085     {
0086         FB_GETLOGGEDINUSER = 0,
0087         FB_LISTALBUMS,
0088         FB_CREATEALBUM,
0089         FB_ADDPHOTO,
0090         FB_EXCHANGESESSION
0091     };
0092 
0093 private:
0094 
0095     //QString getApiSig(const QMap<QString, QString>& args);
0096     QString getCallString(const QMap<QString, QString>& args);
0097     void    authenticationDone(int errCode, const QString& errMsg);
0098     void    doOAuth();
0099     void    getLoggedInUser();
0100 
0101     QString errorToText(int errCode, const QString& errMsg);
0102     int parseErrorResponse(const QDomElement& e, QString& errMsg);
0103     void parseExchangeSession(const QByteArray& data);
0104     void parseResponseGetLoggedInUser(const QByteArray& data);
0105     void parseResponseAddPhoto(const QByteArray& data);
0106     void parseResponseCreateAlbum(const QByteArray& data);
0107     void parseResponseListAlbums(const QByteArray& data);
0108 
0109 private Q_SLOTS:
0110 
0111     void slotFinished(QNetworkReply* reply);
0112     void slotAccept();
0113     void slotReject();
0114 
0115 private:
0116 
0117     QDialog*               m_dialog;
0118     QWidget*               m_parent;
0119 
0120     QByteArray             m_buffer;
0121 
0122     QUrl                   m_apiURL;
0123     QString                m_apiVersion;
0124     QString                m_secretKey;
0125     QString                m_appID;
0126 
0127     bool                   m_loginInProgress;
0128     QString                m_accessToken;
0129 
0130     /* Session expiration
0131      * 0 = doesn't expire or has been invalidated; rest = time of expiry
0132      */
0133     unsigned int           m_sessionExpires;
0134     QTime                  m_callID;
0135 
0136     FbUser                 m_user;
0137 
0138     QNetworkAccessManager* m_netMngr;
0139 
0140     QNetworkReply*         m_reply;
0141 
0142     State                  m_state;
0143 };
0144 
0145 } // namespace KIPIFacebookPlugin
0146 
0147 #endif /* FBTALKER_H */