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 #if QT_VERSION >= 0x040700
00024 # include <QElapsedTimer>
00025 #else
00026 # include <QTime>
00027 #endif
00028
00029 #include "mysocials_driver.h"
00030
00031 #include "datatypes/driverinfo.h"
00032 #include "datatypes/photo.h"
00033 #include "datatypes/album.h"
00034 #include "datatypes/friend.h"
00035 #include "datatypes/message.h"
00036 #include "datatypes/qeventfeed.h"
00037 #include "datatypes/qerrormessage.h"
00038 #include "datatypes/qattachment.h"
00039
00045 struct MethodElement
00046 {
00047 QString className;
00048 QString functionName;
00049 };
00050
00056 class QTransport : public QObject
00057 {
00058 Q_OBJECT
00059 public:
00065 enum Action
00066 {
00067 getListMethodsAction,
00068 getProfileAction,
00069 getListFriendsAction,
00070 deleteFriendAction,
00071 getSettingsAction,
00072 setSettingsAction,
00073 getMessagesAction,
00074 sendMessageAction,
00075 readMessageAction,
00076 deleteMessageAction,
00077 getPhotoAction,
00078 uploadPhotoAction,
00079 getListPhotosAction,
00080 getCommentsAction,
00081 sendCommentAction,
00082 getListAlbumsAction,
00083 getFeedAction
00084 };
00085
00086 bool checkFunction(const QString &usedClass, const QString &usedFunction) const;
00087
00088 private:
00089
00090 QLibrary *driver;
00091
00092
00093 struct msa_module *driverModule;
00094
00095
00096 int activeRequests;
00097
00098
00099 bool needShutdown;
00100
00101
00102 bool isLibraryInit;
00103
00104 #if QT_VERSION >= 0x040700
00105 QElapsedTimer timer;
00106 #else
00107 QTime timer;
00108 #endif
00109
00110
00111
00112 QList<MethodElement> registerdFunctions;
00113
00114 QDomDocument createRequest(const QString& usedClass, const QString& usedFunction, const bool noAuthorize = false) const;
00115 QDomDocument createRequest(const QString& usedClass, const QString& usedFunction, const bool noAuthorize,
00116 const QString& content) const;
00117 QDomDocument sendRequest(const QDomDocument& doc, Action acc);
00118
00119 bool checkFunction(const QString& usedClass, const QString& usedFunction, Action acc) const;
00120 bool checkBadResponse(const QDomDocument& resp, Action acc);
00121 bool checkGoodResponse(const QDomDocument& resp, Action acc);
00122
00123 void getSettings();
00124
00125 void getMethods();
00126
00127 QAttachment loadAttachment(const QDomElement& node);
00128
00133 MessageList getInbox();
00134
00139 MessageList getOutbox();
00140
00145 MessageList getThreadList();
00146
00147 public:
00148 QTransport(QString libName, QString accName, QObject *parent = 0);
00149 ~QTransport();
00150
00154 QString accountId;
00155
00159 QString libraryName;
00160
00161 QString serviceName() const;
00162
00163 static QString generateFileName(const QString& path, const QString& url);
00164
00165 DriverInfo *getDriverInfo();
00166 static DriverInfo *getDriverInfo(QString libraryPath);
00167
00168 void init(QString proxyHost, uint proxyPort);
00169 void setSettings(QString settings);
00170 void close();
00171 bool ready();
00172
00178 void getProfile();
00179
00187 void getProfile(const QString& ownerId);
00188
00189 void getFriends(bool alsoLoadIcons);
00190 bool deleteFriend(QString ownerId);
00191 bool deleteFriend(Friend owner);
00192
00193 void getAlbums(QString ownedId, bool alsoLoadIcons);
00194 void getPhotos(QString ownerId, QString albumId, bool alsoLoadIcons);
00195 void getPhotoComments(Photo photo);
00196 bool sendPhotoComment(Photo photo, QString comment);
00197 bool uploadPhoto(QString accountId, QString albumId, QString file_name, QString description);
00198 bool uploadPhoto(Album al, QString local_file_name, QString description);
00199 bool downloadPhoto(QString url, QString local_file_name);
00200 void downloadPhotoList(PhotoList list, Photo curPhoto, int nearest);
00201
00207 void getMessages();
00208 bool sendMessage(QString ownerId, QString title, QString message);
00209 bool sendMessage(Friend owner, QString title, QString message);
00210 bool readMessage(QString messageId);
00211 bool readMessage(Message msg);
00212 bool deleteMessage(QString messageId);
00213 bool deleteMessage(Message msg);
00214
00220 void getFeed(QEventFeed::FeedType type);
00221
00222 signals:
00223 void albumsReceived(QString accountid, QString friendId, AlbumList, bool isLastUpdate);
00224 void photosReceived(QString accountid, QString friendId, QString albumId, PhotoList, bool isLastUpdate);
00225 void photoUploaded(QString accountId, QString albumId, QString local_file_name, QString photoId);
00226 void commentsReceived(QString accountId, QString friendId, QString albumId, QString photoId, PhotoCommentList list);
00227
00228 void friendsReceived(QString accountid, FriendList, bool isLastUpdate);
00229 void friendDeleted(QString accountId, QString friendId);
00230
00231 void settingsReceived(QString accountid, QString) const;
00232 void profileReceived(QString accountId, QString reqOwnerId, Friend data);
00233
00234 void messagesReceived(QString accountId, MessageList list, bool isLastUpdate);
00235 void messageSended(QString accountId, QString ownerId, QString title, QString text);
00236 void messageReaded(QString accountId, QString messageId);
00237 void messageDeleted(QString accountId, QString messageId);
00238
00239 void errorOccurred(QString accountId, QErrorMessage msg, QTransport::Action acc) const;
00240
00241 void eventFeedReceived(QString accountId, QEventFeedList list, QEventFeed::FeedType type, bool isLastUpdate);
00242 };
00243
00244
00245
00246
00247
00248 #if 0
00249 class QTransport
00250 {
00251 #define DRV_SETT_ERROR QT_TR_NOOP("Unable to save settings")
00252 #define DRV_AUTH_ERROR QT_TR_NOOP("Authorization problem")
00253 #define DRV_AUTH_CANCEL QT_TR_NOOP("Authorization canceled")
00254 #define DRV_REQ_ERROR QT_TR_NOOP("Unable to perform request")
00255 #define DRV_SERVER_BUSY QT_TR_NOOP("Server busy")
00256 #define DRV_REQ_PARAM QT_TR_NOOP("One of the parameters missing or invalid")
00257 #define DRV_CAPT_ERROR QT_TR_NOOP("Captcha")
00258 #define DRV_RESP_ERROR QT_TR_NOOP("Bad response from server")
00259 #define DRV_NETW_ERROR QT_TR_NOOP("Network problem")
00260 #define DRV_MESS_LEN QT_TR_NOOP("Empty message")
00261 #define DRV_ACCESS_ERROR QT_TR_NOOP("Operation prohibited by privacy")
00262 #define DRV_SERVER_ERROR QT_TR_NOOP("Internal Server Error")
00263 #define DRV_FILE_SAVE_ERROR QT_TR_NOOP("Can't save file")
00264 QT_TR_NOOP("male")
00265 QT_TR_NOOP("female")
00266
00267
00268 QT_TR_NOOP("Incorrect signature")
00269 };
00270 #endif
00271
00272 #endif // QTRANSPORT_H