mysocials-core 1.0

src/qtransport.h

Go to the documentation of this file.
00001 #ifndef QTRANSPORT_H
00002 #define QTRANSPORT_H
00003 
00016 #include <QObject>
00017 #include <QLibrary>
00018 #include <QDebug>
00019 #include <QDomDocument>
00020 #include <QDomElement>
00021 #include <QDateTime>
00022 
00023 #include "mysocials_driver.h"
00024 
00025 #include "datatypes/driverinfo.h"
00026 #include "datatypes/photo.h"
00027 #include "datatypes/album.h"
00028 #include "datatypes/friend.h"
00029 #include "datatypes/message.h"
00030 #include "datatypes/qeventfeed.h"
00031 #include "datatypes/qerrormessage.h"
00032 #include "datatypes/qattachment.h"
00033 
00039 struct MethodElement
00040 {
00041     QString className; 
00042     QString functionName; 
00043 };
00044 
00050 class QTransport : public QObject
00051 {
00052     Q_OBJECT
00053 public:
00059     enum Action
00060     {
00061         getListMethodsAction, 
00062         getProfileAction, 
00063         getListFriendsAction, 
00064         deleteFriendAction, 
00065         getSettingsAction, 
00066         setSettingsAction, 
00067         getOutboxMessagesAction, 
00068         getInboxMessagesAction, 
00069         sendMessageAction, 
00070         readMessageAction, 
00071         deleteMessageAction, 
00072         getPhotoAction, 
00073         uploadPhotoAction, 
00074         getListPhotosAction, 
00075         getCommentsAction, 
00076         sendCommentAction, 
00077         getListAlbumsAction, 
00078         getFeedAction 
00079     };
00080 
00081 private:
00082     // Pointer to social network driver library
00083     QLibrary *driver;
00084 
00085     // profile settings in library
00086     struct msa_module *driverModule;
00087 
00088     // count of active requests
00089     int activeRequests;
00090 
00091     // true if driver must shuutdown
00092     bool needShutdown;
00093 
00094     // true if library init well
00095     bool isLibraryInit;
00096 
00097     // list of registered functions
00098     QList<MethodElement> registerdFunctions;
00099 
00100     QDomDocument createRequest(const QString& usedClass, const QString& usedFunction, const bool noAuthorize = false) const;
00101     QDomDocument createRequest(const QString& usedClass, const QString& usedFunction, const bool noAuthorize,
00102                                const QString& content) const;
00103     QDomDocument sendRequest(const QDomDocument& doc, Action acc);
00104 
00105     bool checkFunction(const QString& usedClass, const QString& usedFunction, Action acc) const;
00106     bool checkBadResponse(const QDomDocument& resp, Action acc);
00107     bool checkGoodResponse(const QDomDocument& resp, Action acc);
00108 
00109     void getSettings();
00110 
00111     void getMethods();
00112 
00113     QAttachment loadAttachment(const QDomElement& node);
00114 
00115 public:
00116     QTransport(QString libName, QString accName, QObject *parent = 0);
00117     ~QTransport();
00118 
00122     QString accountId;
00123 
00127     QString libraryName;
00128 
00129     QString serviceName() const;
00130 
00131     QString generateFileName(const QString& path, const QString& url) const;
00132 
00133     DriverInfo *getDriverInfo();
00134     static DriverInfo *getDriverInfo(QString libraryPath);
00135 
00136     void init(QString proxyHost, uint proxyPort);
00137     void setSettings(QString settings);
00138     void close();
00139     bool ready();
00140 
00146     void getProfile();
00147 
00155     void getProfile(const QString& ownerId);
00156 
00157     void getFriends();
00158     bool deleteFriend(QString ownerId);
00159     bool deleteFriend(Friend owner);
00160 
00161     void getAlbums(QString ownedId);
00162     void getPhotos(QString ownerId, QString albumId);
00163     void getPhotoComments(Photo photo);
00164     bool sendPhotoComment(Photo photo, QString comment);
00165     bool uploadPhoto(QString accountId, QString albumId, QString file_name, QString description);
00166     bool uploadPhoto(Album al, QString local_file_name, QString description);
00167     bool downloadPhoto(QString url, QString local_file_name);
00168     void downloadPhotoList(PhotoList list, Photo curPhoto, int nearest);
00169 
00170     void getInbox();
00171     void getOutbox();
00172     void getThreadList();
00173     bool sendMessage(QString ownerId, QString title, QString message);
00174     bool sendMessage(Friend owner, QString title, QString message);
00175     bool readMessage(QString messageId);
00176     bool readMessage(Message msg);
00177     bool deleteMessage(QString messageId);
00178     bool deleteMessage(Message msg);
00179 
00185     void getFeed(QEventFeed::FeedType type);
00186 
00187 signals:
00188     void albumsReceived(QString accountid, QString friendId, AlbumList, bool isLastUpdate);
00189     void photosReceived(QString accountid, QString friendId, QString albumId, PhotoList, bool isLastUpdate);
00190     void photoUploaded(QString accountId, QString albumId, QString local_file_name, QString photoId);
00191     void commentsReceived(QString accountId, QString friendId, QString albumId, QString photoId, PhotoCommentList list);
00192 
00193     void friendsReceived(QString accountid, FriendList, bool isLastUpdate);
00194     void friendDeleted(QString accountId, QString friendId);
00195 
00196     void settingsReceived(QString accountid, QString) const;
00197     void profileReceived(QString accountId, QString reqOwnerId, Friend data);
00198 
00199     void inboxMessagesReceived(QString accountId, MessageList list, bool isLastUpdate);
00200     void outboxMessagesReceived(QString accountId, MessageList list, bool isLastUpdate);
00201     void messageSended(QString accountId, QString ownerId, QString title, QString text);
00202     void messageReaded(QString accountId, QString messageId);
00203     void messageDeleted(QString accountId, QString messageId);
00204 
00205     void errorOccurred(QString accountId, QErrorMessage msg, QTransport::Action acc) const;
00206 
00207     void eventFeedReceived(QString accountId, QEventFeedList list, QEventFeed::FeedType type, bool isLastUpdate);
00208 };
00209 
00210 // the next part of code defines standard messages that returns from driver.
00211 // It's need for correct translation.
00212 // Prease upgrade it if possible.
00213 
00214 #if 0
00215 class QTransport
00216 {
00217 #define DRV_SETT_ERROR QT_TR_NOOP("Unable to save settings")
00218 #define DRV_AUTH_ERROR QT_TR_NOOP("Authorization problem")
00219 #define DRV_AUTH_CANCEL QT_TR_NOOP("Authorization canceled")
00220 #define DRV_REQ_ERROR QT_TR_NOOP("Unable to perform request")
00221 #define DRV_SERVER_BUSY QT_TR_NOOP("Server busy")
00222 #define DRV_REQ_PARAM QT_TR_NOOP("One of the parameters missing or invalid")
00223 #define DRV_CAPT_ERROR QT_TR_NOOP("Captcha")
00224 #define DRV_RESP_ERROR QT_TR_NOOP("Bad response from server")
00225 #define DRV_NETW_ERROR QT_TR_NOOP("Network problem")
00226 #define DRV_MESS_LEN QT_TR_NOOP("Empty message")
00227 #define DRV_ACCESS_ERROR QT_TR_NOOP("Operation prohibited by privacy")
00228 #define DRV_SERVER_ERROR QT_TR_NOOP("Internal Server Error")
00229 #define DRV_FILE_SAVE_ERROR QT_TR_NOOP("Can't save file")
00230 
00231 // from libvkontakte - errors.xml
00232 QT_TR_NOOP("Incorrect signature")
00233 };
00234 #endif
00235 
00236 #endif // QTRANSPORT_H