mysocials-core 1.0

src/datatypes/account.h

00001 #ifndef ACCOUNT_H
00002 #define ACCOUNT_H
00003 
00004 #include <QObject>
00005 #include <QDomDocument>
00006 #include <QFile>
00007 #include <QDebug>
00008 #include <QDir>
00009 #include <QMetaType>
00010 #include <QtConcurrentRun>
00011 
00012 #include "qtransport.h"
00013 #include "friend.h"
00014 #include "utils/utils.h"
00015 #include "datatypes/message.h"
00016 
00017 // the name of file which profile was stored
00018 #define FILE_ACCOUNT_DATA "profile.xml"
00019 
00020 // XML root node for profile
00021 #define NODE_ACCOUNT_ROOT "profile"
00022 
00023 // XML node for storing library name
00024 #define NODE_ACCOUNT_LIBRARY "library"
00025 
00026 // XML node for storing driver settings
00027 #define NODE_ACCOUNT_SETTINGS "settings"
00028 
00029 #define FILE_FRIENDS_DATA "friends.xml"
00030 
00031 #define NODE_FRIENDS_ROOT "friendsList"
00032 
00033 #define FILE_INBOX_DATA "/messages_inbox.xml"
00034 
00035 #define FILE_OUTBOX_DATA "/messages_outbox.xml"
00036 
00037 #define NODE_MESSAGES_ROOT "messageList"
00038 
00039 #define FILE_DRAFTS_DATA "/drafts.xml"
00040 
00041 /*
00042  * class for account information storage.
00043  */
00044 class Account: public QObject
00045 {
00046     Q_OBJECT
00047 
00048 private:
00049     FriendList friends; // list of loaded friends.
00050     AlbumList albums; // list of my albums.
00051     MessageList inboxMessages; // list of inbox messages.
00052     MessageList outboxMessages; // list of outbox messages.
00053     MessageList draftMessages; // list of drafts of messages.
00054     QString settings; // account settings. Uses in driver.
00055     QString oldSettings; // old account settings. Used if user didn't work with application
00056 
00057     // user account data
00058     Friend profile;
00059 
00060     // true if first request is success, otherwise false
00061     bool isLibraryInit;
00062 
00063 public:
00064     Account(QString libraryName);
00065     Account(QString libraryName, QString accountId);
00066     ~Account();
00067 
00068     QTransport *transport; // interface of used driver.
00069 
00070     bool ready() const; // check status of Account
00071 
00072     void saveAccount(); // store account settings.
00073     static Account* loadAccount(const QString& accountId); // load account from storage.
00074 
00075     // get friend list or load it from cache file.
00076     FriendList getFriendList();
00077 
00078     // set friend list and store it to cache file.
00079     void setFriendList(const FriendList& list);
00080 
00081     QString accountId() const;
00082 
00083     QString serviceName() const;
00084 
00090     AlbumList getAlbumList();
00091 
00097     void setAlbumList(const AlbumList& list);
00098 
00099     MessageList getInboxMessageList();
00100 
00101     void setInboxMessageList(const MessageList&);
00102 
00103     MessageList getOutboxMessageList();
00104 
00105     void setOutboxMessageList(const MessageList&);
00106 
00107     void setDraftMessages(const MessageList&);
00108 
00109     MessageList getDraftMessages();
00110 
00111     Friend getProfile(const bool isNeedUpdate);
00112 
00113     void setProfile(const Friend& profile);
00114 
00121     void setProxy(const QString& proxyHost, const int proxyPort);
00122 
00123     // checks that it is a first request
00124     bool isFirstRequest;
00125 
00126     // true if first request is success, otherwise false
00127     bool isNetworkEnabled;
00128 
00129 private slots:
00130     void gotSettings(QString accountId, QString settings);
00131 };
00132 
00133 typedef QList<Account *> AccountList;
00134 
00135 Q_DECLARE_METATYPE(Account *)
00136 
00137 #endif // ACCOUNT_H