123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- #ifndef NETSOUL_H
- #define NETSOUL_H
-
- #include <QObject>
- #include <QTcpSocket>
- #include <QRegExp>
- #include <QCryptographicHash>
- #include <QByteArray>
- #include <QUrl>
- #include <QMetaEnum>
- #include <QTimer>
- #include <QDateTime>
- #include <QDebug>
- #include <QStringList>
- #include "epimafia_global.h"
- #include "epimafia.h"
-
- class NSListUsersEmitter;
-
- class EPIMAFIASHARED_EXPORT NetSoul : public QObject
- {
- Q_OBJECT
- public:
- enum State
- {
- Disconnected,
- HostLookUp,
- Connecting,
- Connected,
- LoggingIn,
- LoggedIn,
- Disconnecting,
- NetworkError,
- ProtocolError,
- BadLogin
- };
- Q_ENUMS(State)
-
- enum UserState
- {
- UserStateNotSet,
- UnknownState,
- Actif,
- Away,
- Lock,
- Logout,
- Login
- };
- Q_ENUMS(UserState)
-
- struct User
- {
- QString id;
- QString login;
- QString ip;
- QString location;
- QString promo;
- UserState state;
- QString stateString;
- QString data;
- };
- typedef QList<NetSoul::User> Users;
-
- struct Message
- {
- User from;
- QString message;
- };
-
- enum Command
- {
- NoCommand,
- Whois,
- ChangeStatus,
- AddToWatchList,
- Ping,
- ListUsers,
- SendMessage
- };
- Q_ENUMS(Command)
-
-
- explicit NetSoul(QObject *parent = 0);
- QAbstractSocket::SocketError getLastNetworkError();
- QString getId() const;
- EpiUser getEpiUser() const;
- User getUser() const;
- NetSoul::State getState() const;
-
- static UserState getUserStateFromString(QString state);
- static QString getStringFromUserState(UserState state);
- static QString getDecodedString(QString enc);
- static QString getEncodedString(QString dec);
- static QString getStringFromState(State state);
-
- signals:
- void stateChanged(NetSoul::State);
- void userDataChanged(NetSoul::User);
- void newMessage(NetSoul::Message);
- void unknownCommand(QString);
-
- public slots:
- void setLocation(QString l);
- void setLogin(EpiUser user);
- void login();
- void login(EpiUser user);
- void logout();
- void setUserState(NetSoul::UserState state);
- void whois(QString user);
- void whois(QStringList users);
- void addToWatchList(QString user);
- void addToWatchList(QStringList users);
- void listUsers(QObject *receiver, const char *member, QString user = QString());
- void sendMessage(QString user, QString location, QString message);
- void sendMessage(NetSoul::User user, QString message);
-
- private slots:
- void socketConnected();
- void socketDisconnected();
- void socketError(QAbstractSocket::SocketError e);
- void socketReadyRead();
- void socketHostFound();
- void setState(State s);
- void protError();
- void startTimeout();
- void startTimeout(int t);
- void stopTimeout();
- void write(QString c);
- void write(QString c, int t);
- void timedout();
- void nextCommand();
- void addCommand(QString cmd, Command command);
- void addCommand(QString cmd, Command command, int t);
- void commandFinished();
-
- private:
- struct NextCommand
- {
- QString commandString;
- Command commandName;
- int timeout;
- };
-
- static int m_defaultTimeout;
-
- QTcpSocket* m_sock;
- EpiUser m_epiUser;
- User m_user;
- QString m_location;
- State m_state;
- UserState m_userState;
- QAbstractSocket::SocketError m_lastNetworkError;
- QString m_buf;
- QTimer* m_timeout;
- QString m_id;
- Command m_currentCmd;
- QList<NextCommand> m_nextCommands;
- QList<NSListUsersEmitter*> m_listEmitters;
- QString m_data;
-
- };
- Q_DECLARE_METATYPE(NetSoul::User)
-
- class NSListUsersEmitter : public QObject
- {
- Q_OBJECT
- public:
- NSListUsersEmitter(QObject* p = 0) : QObject(p) {}
-
- signals:
- void listed(NetSoul::Users);
-
- public slots:
- void emitList(NetSoul::Users users);
- };
-
- QDebug EPIMAFIASHARED_EXPORT operator<< (QDebug, NetSoul::Command&);
- QDebug EPIMAFIASHARED_EXPORT operator<< (QDebug, NetSoul::State&);
- QDebug EPIMAFIASHARED_EXPORT operator<< (QDebug, NetSoul::UserState&);
- QDebug EPIMAFIASHARED_EXPORT operator<< (QDebug, NetSoul::User&);
-
- #endif // NETSOUL_H
|