mysocials-core 1.0
|
00001 00007 #ifndef SERVICEMGR_H 00008 #define SERVICEMGR_H 00009 00010 #include <QObject> 00011 #include <QList> 00012 #include <QFile> 00013 #include <QDebug> 00014 #include <QDomDocument> 00015 #include <QtConcurrentRun> 00016 #include <QMetaType> 00017 #include <QHash> 00018 #include <QDomNode> 00019 #include <QtNetwork/QNetworkProxy> 00020 #include <QUrl> 00021 #include <QSettings> 00022 00023 #include "datatypes/account.h" 00024 #include "datatypes/driverinfo.h" 00025 #include "datatypes/qerrormessage.h" 00026 #include "datatypes/message.h" 00027 #include "utils/utils.h" 00028 #include "mysocials_global.h" 00029 00033 #define FILE_ACCOUNTS_LIST "/accounts.xml" 00034 00040 #define FILE_SETTINGS "/%1_settings.xml" 00041 00045 #define NO_PROXY "no-proxy" 00046 00050 #define SYSTEM_PROXY "system-proxy" 00051 00055 #define USER_PROXY "user-proxy" 00056 00057 #define NODE_ACCOUNTS_ROOT "profiles" 00058 #define NODE_ACCOUNT "profile" 00059 00060 #define SETTINGS_PROXY "proxy" 00061 #define SETTINGS_PROXYPORT "proxy-port" 00062 #define SETTINGS_PROXYHOST "proxy-host" 00063 #define SETTINGS_AUTOROTATE "auto-rotate" 00064 #define SETTINGS_MULTIPANEL "multipanel" 00065 00072 class mysocials_EXPORT ServiceMgr : public QObject 00073 { 00074 Q_OBJECT 00075 00076 public: 00082 ServiceMgr(QObject *parent = 0); 00083 00089 ServiceMgr(const ServiceMgr& src); 00090 00094 ~ServiceMgr(); 00095 00113 Friend getProfile(const QString& accountId, const QString& ownerId, const bool isNeedUpdate, const bool useSignal, const bool isFullProfile); 00114 00130 Friend getProfile(const PhotoComment& comment, const bool isNeedUpdate, const bool useSignal); 00131 00141 FriendList getFriends(const bool isNeedUpdate, const bool useSignal); 00142 00154 AlbumList getAlbums(const Friend& curFriend, const bool isNeedUpdate, const bool useSignal); 00155 00167 AlbumList getAlbums(const Album& al, const bool isNeedUpdate, const bool useSignal); 00168 00178 AlbumList getAlbums(bool isNeedUpdate, const bool useSignal); 00179 00194 PhotoList getPhotos(const Album& curAlbum, const bool isNeedUpdate, const bool useSignal); 00195 00210 PhotoList getPhotos(const Photo& curPhoto, const bool isNeedUpdate, const bool useSignal); 00211 00223 PhotoCommentList getComments(const Photo& curPhoto, const bool isNeedUpdate, const bool useSignal); 00224 00234 bool sendComment(const Photo& curPhoto, const QString& comment); 00235 00245 MessageList getInboxMessages(const bool isNeedUpdate, const bool useSignal); 00246 00256 MessageList getOutboxMessages(const bool isNeedUpdate, const bool useSignal); 00257 00268 void deleteMessage(const Message& msg); 00269 00284 bool sendMessage(const QString& accountId, const QString& ownerId, 00285 const QString& title, const QString& message); 00286 00294 bool readMessage(const QString& accountId, const QString& messageId); 00295 00301 AccountList getAccounts(); 00302 00310 void addAccount(QString accountName, DriverInfo *driver); 00311 00319 void deleteAccount(Account *oldAcc); 00320 00328 Account *account(QString accountId); 00329 00339 void downloadPhotos(Photo startPhoto, int nearest); 00340 00341 QString downloadPhoto(Photo curPhoto); 00342 00356 void uploadPhoto(QString accountId, QString albumId, QString file, QString description); 00357 00369 void uploadPhoto(const Album album, QString file, QString description); 00370 00375 enum ProxyType { 00376 NoProxy, 00377 SystemProxy, 00378 UserProxy 00379 }; 00380 00386 QSettings *settings; 00387 00393 void updateDriverSettings(); 00394 00403 QList<DriverInfo*> getDrivers(); 00404 00414 PhotoList getPhotosForAlbum(Photo curPhoto); 00415 00427 PhotoList getPhotosForAlbum(Account *curAcc, Photo curPhoto); 00428 00434 void clearCache(); 00435 00445 QEventFeedList getFeed(QEventFeed::FeedType type, const bool isNeedUpdate, const bool useSignal); 00446 00447 QEventFeedList getFeed(Account *acc, QEventFeed::FeedType type, const bool isNeedUpdate, const bool useSignal); 00448 00449 int getNumThreadsFriendUpdate() const { return this->friendsUpdate;} 00450 00451 int getNumThreadsAlbumUpdate() const { return this->albumsUpdate;} 00452 00453 int getNumThreadsPhotoUpdate() const { return this->photosUpdate;} 00454 00455 int getNumThreadsFeedUpdate() const { return this->feedsUpdate;} 00456 00457 private: 00461 AccountList accounts; 00462 00466 QHash<QString, QFuture<void> > threads; 00467 00472 void loadAccounts(); 00473 00478 void loadSettings(); 00479 00484 void storeSettings(); 00485 00490 void cleanThreads(); 00491 00497 void connectToTransport(Account *account); 00498 00499 int friendsUpdate; 00501 int albumsUpdate; 00503 int photosUpdate; 00505 int feedsUpdate; 00507 int inboxMessagesUpdate; 00509 int outboxMessagesUpdate; 00511 // Current filtered friver 00512 DriverInfo* filteredDriver; 00513 bool isSkipFriendListUpdate; 00515 // Check whether AccountInfo filtered 00516 bool isServiceFiltered(const Account* info) const; 00517 00518 signals: 00528 void updateFriends(FriendList list, bool isLastUpdate); 00529 00541 void updateAlbumList(Friend owner, AlbumList list, bool isLastUpdate); 00542 00560 void updatePhotoList(QString accountId, QString ownerId, QString albumId, PhotoList list, bool isLastUpdate); 00561 00573 void updatePhotoCommentList(QString photoId, PhotoCommentList list); 00574 00586 void updateInboxMessageList(MessageList list, bool isLastUpdate); 00587 00599 void updateOutboxMessageList(MessageList list, bool isLastUpdate); 00600 00612 void updateAccounts(QString accountId, AccountList list); 00613 00625 void errorOccured(QString errMsg, QTransport::Action action, bool isMajor); 00626 00634 void updateProfile(Friend profile); 00635 00644 void photoUploaded(QString accountId, QString albumId, QString local_file_name, QString photoId); 00652 void messageSent(QString ownerId, QString title, QString message); 00653 00663 void messageDeleted(QString messageId); 00664 00676 void updateFeed(QEventFeedList list, QEventFeed::FeedType type, bool isLastUpdate); 00677 00678 private slots: 00686 void gotFriends(QString accountid, FriendList, bool isLastUpdate); 00695 void gotAlbumList(QString accountid, QString friendId, AlbumList, bool isLastUpdate); 00705 void gotPhotoList(QString accountid, QString friendId, QString albumId, PhotoList, bool isLastUpdate); 00713 void gotInboxMessageList(QString accountId, MessageList, bool isLastUpdate); 00721 void gotOutboxMessageList(QString accountId, MessageList, bool isLastUpdate); 00729 void gotProfile(QString accountId, QString reqOwnerId, Friend profile); 00739 void gotComments(QString accountId, QString ownerId, QString albumId, QString photoId, PhotoCommentList list); 00745 void storeAccounts(QString accountId, AccountList list); 00746 00757 void gotEventFeed(QString accountId, QEventFeedList list, 00758 QEventFeed::FeedType type, bool isLastUpdate); 00766 void gotErrorMsg(QString accountId, QErrorMessage msg, QTransport::Action acc); 00767 00768 public slots: 00769 void changeFilteredService(DriverInfo* driverInfo); 00770 00775 void disableSkipFriendListUpdate(); 00776 }; 00777 00778 Q_DECLARE_METATYPE(ServiceMgr::ProxyType) 00779 00780 #endif // SERVICEMGR_H