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
00030 class ServiceFilter;
00031 class FilterManager;
00032
00036 #define FILE_ACCOUNTS_LIST "/accounts.xml"
00037
00043 #define FILE_SETTINGS "/%1_settings.xml"
00044
00048 #define NO_PROXY "no-proxy"
00049
00053 #define SYSTEM_PROXY "system-proxy"
00054
00058 #define USER_PROXY "user-proxy"
00059
00060 #define NODE_ACCOUNTS_ROOT "profiles"
00061 #define NODE_ACCOUNT "profile"
00062
00063 #define SETTINGS_PROXY "proxy"
00064 #define SETTINGS_PROXYPORT "proxy-port"
00065 #define SETTINGS_PROXYHOST "proxy-host"
00066 #define SETTINGS_AUTOROTATE "auto-rotate"
00067 #define SETTINGS_MULTIPANEL "multipanel"
00068
00075 class mysocials_EXPORT ServiceMgr : public QObject
00076 {
00077 Q_OBJECT
00078
00079 public:
00085 ServiceMgr(QObject *parent = 0);
00086
00092 ServiceMgr(const ServiceMgr& src);
00093
00097 ~ServiceMgr();
00098
00116 Friend getProfile(const QString& accountId, const QString& ownerId, const bool isNeedUpdate, const bool useSignal, const bool isFullProfile);
00117
00133 Friend getProfile(const PhotoComment& comment, const bool isNeedUpdate, const bool useSignal);
00134
00135 Friend getMyProfile(bool isNeedUpdate);
00136
00146 FriendList getFriends(const bool isNeedUpdate, const bool useSignal);
00147
00159 AlbumList getAlbums(const Friend& curFriend, const bool isNeedUpdate, const bool useSignal);
00160
00172 AlbumList getAlbums(const Album& al, const bool isNeedUpdate, const bool useSignal);
00173
00183 AlbumList getAlbums(bool isNeedUpdate, const bool useSignal);
00184
00199 PhotoList getPhotos(const Album& curAlbum, const bool isNeedUpdate, const bool useSignal, const bool loadIcons);
00200
00215 PhotoList getPhotos(const Photo& curPhoto, const bool isNeedUpdate, const bool useSignal, const bool loadIcons);
00216
00228 PhotoCommentList getComments(const Photo& curPhoto, const bool isNeedUpdate, const bool useSignal);
00229
00239 bool sendComment(const Photo& curPhoto, const QString& comment);
00240
00250 MessageList getMessages(const bool isNeedUpdate, const bool useSignal);
00251
00262 bool deleteMessage(const Message& msg);
00263
00264 bool canSendMessage(const QString& accountId);
00265
00280 bool sendMessage(const QString& accountId, const QString& ownerId,
00281 const QString& title, const QString& message);
00282
00290 bool readMessage(const QString& accountId, const QString& messageId);
00291
00297 AccountList getAccounts();
00298
00306 void addAccount(QString accountName, DriverInfo *driver);
00307
00315 void deleteAccount(Account *oldAcc);
00316
00324 Account *account(QString accountId);
00325
00335 void downloadPhotos(Photo startPhoto, int nearest);
00336
00337 QString downloadPhoto(Photo curPhoto);
00338
00352 void uploadPhoto(QString accountId, QString albumId, QString file, QString description);
00353
00365 void uploadPhoto(const Album album, QString file, QString description);
00366
00371 enum ProxyType {
00372 NoProxy,
00373 SystemProxy,
00374 UserProxy
00375 };
00376
00382 QSettings *settings;
00383
00389 void updateDriverSettings();
00390
00399 QList<DriverInfo*> getDrivers();
00400
00410 PhotoList getPhotosForAlbum(Photo curPhoto);
00411
00423 PhotoList getPhotosForAlbum(Account *curAcc, Photo curPhoto);
00424
00430 void clearCache();
00431
00441 QEventFeedList getFeed(QEventFeed::FeedType type, const bool isNeedUpdate, const bool useSignal);
00442
00443 QEventFeedList getFeed(Account *acc, QEventFeed::FeedType type, const bool isNeedUpdate, const bool useSignal);
00444
00445 int getNumThreadsFriendUpdate() const { return this->friendsUpdate;}
00446
00447 int getNumThreadsAlbumUpdate() const { return this->albumsUpdate;}
00448
00449 int getNumThreadsPhotoUpdate() const { return this->photosUpdate;}
00450
00451 int getNumThreadsFeedUpdate() const { return this->feedsUpdate;}
00452
00453 FilterManager* filterManager() const;
00454 ServiceFilter* serviceFilter() const;
00455
00456 private:
00460 AccountList accounts;
00461
00465 QHash<QString, QFuture<void> > threads;
00466
00471 void loadAccounts();
00472
00477 void loadSettings();
00478
00483 void storeSettings();
00484
00489 void cleanThreads();
00490
00496 void connectToTransport(Account *account);
00497
00498 int friendsUpdate;
00500 int albumsUpdate;
00502 int photosUpdate;
00504 int feedsUpdate;
00506 int messagesUpdate;
00508 bool isSkipFriendListUpdate;
00509 FriendList cachedFriendList;
00511 QList<DriverInfo*> cachedDriverList;
00514
00515 DriverInfo* filteredDriver;
00516 ServiceFilter* serviceFilter_;
00517 FilterManager* filterManager_;
00518 void createFilter();
00519
00520
00521 bool isServiceFiltered(const Account* info) const;
00522
00523 signals:
00533 void updateFriends(FriendList list, bool isLastUpdate);
00534
00546 void updateAlbumList(Friend owner, AlbumList list, bool isLastUpdate);
00547
00565 void updatePhotoList(QString accountId, QString ownerId, QString albumId, PhotoList list, bool isLastUpdate);
00566
00578 void updatePhotoCommentList(QString photoId, PhotoCommentList list);
00579
00591 void updateMessageList(MessageList list, bool isLastUpdate);
00592
00604 void updateAccounts(QString accountId, AccountList list);
00605
00617 void errorOccured(QString errMsg, QTransport::Action action, bool isMajor);
00618
00626 void updateProfile(Friend profile);
00627
00636 void photoUploaded(QString accountId, QString albumId, QString local_file_name, QString photoId);
00644 void messageSent(QString ownerId, QString title, QString message);
00645
00655 void messageDeleted(QString messageId);
00656
00668 void updateFeed(QEventFeedList list, QEventFeed::FeedType type, bool isLastUpdate);
00669
00670 private slots:
00678 void gotFriends(QString accountid, FriendList, bool isLastUpdate);
00687 void gotAlbumList(QString accountid, QString friendId, AlbumList, bool isLastUpdate);
00697 void gotPhotoList(QString accountid, QString friendId, QString albumId, PhotoList, bool isLastUpdate);
00705 void gotMessageList(QString accountId, MessageList, bool isLastUpdate);
00713 void gotProfile(QString accountId, QString reqOwnerId, Friend profile);
00723 void gotComments(QString accountId, QString ownerId, QString albumId, QString photoId, PhotoCommentList list);
00729 void storeAccounts(QString accountId, AccountList list);
00730
00741 void gotEventFeed(QString accountId, QEventFeedList list,
00742 QEventFeed::FeedType type, bool isLastUpdate);
00750 void gotErrorMsg(QString accountId, QErrorMessage msg, QTransport::Action acc);
00751
00752 public slots:
00753 void changeFilteredService(DriverInfo* driverInfo);
00754 void updateData(int type = -1);
00759 void disableSkipFriendListUpdate();
00760 };
00761
00762 Q_DECLARE_METATYPE(ServiceMgr::ProxyType)
00763
00764 #endif // SERVICEMGR_H