]> Some of my projects - aniplayer-old.git/commitdiff
- First compiling code.
authorAPTX <marek321@gmail.com>
Sat, 29 May 2010 15:47:32 +0000 (17:47 +0200)
committerAPTX <marek321@gmail.com>
Sat, 29 May 2010 15:47:32 +0000 (17:47 +0200)
23 files changed:
lib/anidbudpclient/abstractcommand.cpp
lib/anidbudpclient/abstractcommand.h
lib/anidbudpclient/authcommand.cpp
lib/anidbudpclient/authcommand.h
lib/anidbudpclient/client.cpp
lib/anidbudpclient/client.h
lib/anidbudpclient/file.cpp
lib/anidbudpclient/file.h
lib/anidbudpclient/filecommand.cpp
lib/anidbudpclient/filecommand.h
lib/anidbudpclient/hash.h
lib/anidbudpclient/logoutcommand.cpp
lib/anidbudpclient/logoutcommand.h
lib/anidbudpclient/mylistaddcommand.cpp
lib/anidbudpclient/mylistaddcommand.h
lib/anidbudpclient/mylistcommand.cpp
lib/anidbudpclient/mylistcommand.h
lib/anidbudpclient/rawcommand.cpp
lib/anidbudpclient/rawcommand.h
lib/anidbudpclient/uptimecommand.cpp
lib/anidbudpclient/uptimecommand.h
src/videowindow.cpp
src/videowindow.h

index 915e715093e4977100fffe73524a19a9a92279e2..6c2eb08cb3a1ce11477cac845e34d82d2db15532 100644 (file)
@@ -2,14 +2,12 @@
 
 namespace AniDBUdpClient {
 
-AbstractCommand::AbstractCommand(QObject *parent) : QObject(parent)
+AbstractCommand::AbstractCommand()
 {
-       m_replyCode = UNKNOWN_REPLY;
 }
 
 AbstractCommand::~AbstractCommand()
 {
-
 }
 
 Command AbstractCommand::rawCommand() const
@@ -27,21 +25,44 @@ bool AbstractCommand::requiresSession() const
        return true;
 }
 
-void AbstractCommand::setRawReply(ReplyCode replyCode, const QString &reply, Client *client)
+// ===
+
+AbstractReply::AbstractReply(const QByteArray &id, Client *client, QObject *parent) : QObject(parent)
+{
+       m_replyCode = UNKNOWN_REPLY;
+       m_id = id;
+       m_client = client;
+}
+
+AbstractReply::~AbstractReply()
+{
+
+}
+
+const AbstractCommand &AbstractReply::command() const
+{
+       return m_command;
+}
+
+void AbstractReply::setRawReply(ReplyCode replyCode, const QString &reply)
 {
-       Q_UNUSED(client);
        m_replyCode = replyCode;
        m_rawReply = reply;
 }
 
-QString AbstractCommand::rawReply() const
+QString AbstractReply::rawReply() const
 {
        return m_rawReply;
 }
 
-ReplyCode AbstractCommand::replyCode() const
+ReplyCode AbstractReply::replyCode() const
 {
        return m_replyCode;
 }
 
+QByteArray AbstractReply::id() const
+{
+       return m_id;
+}
+
 } // namespace AniDBUdpClient
index 8a2dc2a20a09ccc7dc566a56c4775cd5e64bbbc7..e8b386f4e6d09359c3e83997833bf255be6b243f 100644 (file)
@@ -14,26 +14,62 @@ class Client;
 
 typedef QPair<QString, QVariantMap> Command;
 
-class ANIDBUDPCLIENTSHARED_EXPORT AbstractCommand : public QObject
-{
-       Q_OBJECT
-
-       Q_PROPERTY(ReplyCode replyCode READ replyCode);
+class AbstractReply;
 
+class ANIDBUDPCLIENTSHARED_EXPORT AbstractCommand
+{
+       friend class Client;
 public:
-
-       AbstractCommand(QObject *parent = 0);
+       typedef AbstractReply ReplyType;
+       AbstractCommand();
        virtual ~AbstractCommand();
 
        virtual Command rawCommand() const;
 
        virtual bool waitForResult() const;
        virtual bool requiresSession() const;
+};
+
+#define REPLY_DEFINITION_HELPER(name) \
+               friend class Client; \
+       public: \
+               typedef name##Command CommandType; \
+       private: \
+               CommandType m_command; \
+               Client *m_client; \
+               name##Reply(const CommandType command, const QByteArray &id, Client *client, QObject *parent) : m_command(command), m_client(client), AbstractReply(id, client, parent) {} \
+               inline const CommandType &command() const { return m_command; }
+
+#define REPLY_DEFINITION_HELPER2(name) \
+               friend class Client; \
+       public: \
+               typedef name##Command CommandType; \
+       private: \
+               CommandType m_command; \
+               Client *m_client; \
+               name##Reply(const CommandType command, const QByteArray &id, Client *client, QObject *parent) : m_command(command), m_client(client), AbstractReply(id, client, parent) {init();} \
+               inline const CommandType &command() const { return m_command; }
+
+class ANIDBUDPCLIENTSHARED_EXPORT AbstractReply : public QObject
+{
+       Q_OBJECT
+
+       Q_PROPERTY(QByteArray id READ id);
+       Q_PROPERTY(ReplyCode replyCode READ replyCode);
+
+public:
+       typedef AbstractCommand CommandType;
 
-       virtual void setRawReply(ReplyCode replyCode, const QString &reply, Client *client);
+       AbstractReply(const QByteArray &id, Client *client, QObject *parent = 0);
+       virtual ~AbstractReply();
+
+       const CommandType &command() const;
+
+       virtual void setRawReply(ReplyCode replyCode, const QString &reply);
        virtual QString rawReply() const;
 
        virtual ReplyCode replyCode() const;
+       virtual QByteArray id() const;
 
 signals:
        void replyReady(bool success = false);
@@ -41,11 +77,12 @@ signals:
 protected:
        QString m_rawReply;
        ReplyCode m_replyCode;
+       QByteArray m_id;
+       Client *m_client;
+
+       AbstractCommand m_command;
 };
 
 } // namespace AniDBUdpClient
 
-#include <QScriptEngine>
-Q_SCRIPT_DECLARE_QMETAOBJECT(AniDBUdpClient::AbstractCommand, QObject*);
-
 #endif // ABSTRACTCOMMAND_H
index dab0e881d430b14b8ae4dc5b88d933d416e9fd49..6153b66ee74e7dadf58e474fd5505ff94124a9eb 100644 (file)
@@ -4,15 +4,16 @@
 
 namespace AniDBUdpClient {
 
-AuthCommand::AuthCommand(QObject *parent) : AbstractCommand(parent)
+AuthCommand::AuthCommand() : AbstractCommand()
 {
        m_compression = false;
 }
 
-AuthCommand::AuthCommand(const QString &user, const QString &pass, QObject *parent) : AbstractCommand(parent)
+AuthCommand::AuthCommand(const QString &user, const QString &pass) : AbstractCommand()
 {
        m_user = user;
        m_pass = pass;
+       m_compression = false;
 }
 
 QString AuthCommand::user() const
@@ -45,21 +46,6 @@ void AuthCommand::setCompression(bool compress)
        m_compression = compress;
 }
 
-QString AuthCommand::sessionId() const
-{
-       return m_sessionId;
-}
-
-QString AuthCommand::errorString() const
-{
-       return m_errorString;
-}
-
-void AuthCommand::clearError()
-{
-       m_errorString = "";
-}
-
 bool AuthCommand::waitForResult() const
 {
        return true;
@@ -86,10 +72,27 @@ Command AuthCommand::rawCommand() const
        return command;
 }
 
-void AuthCommand::setRawReply(ReplyCode replyCode, const QString &reply, Client *client)
+// ===
+
+QString AuthReply::sessionId() const
+{
+       return m_sessionId;
+}
+
+QString AuthReply::errorString() const
+{
+       return m_errorString;
+}
+
+void AuthReply::clearError()
+{
+       m_errorString = "";
+}
+
+void AuthReply::setRawReply(ReplyCode replyCode, const QString &reply)
 {
 qDebug() << replyCode;
-       AbstractCommand::setRawReply(replyCode, reply, client);
+       AbstractReply::setRawReply(replyCode, reply);
 
        switch(replyCode)
        {
index b085318a1b4a8c449ed3848c1b7a96582e996bbf..806e5edb74706ed9d80b45539aecc68e4c13c7a6 100644 (file)
@@ -1,55 +1,67 @@
-#ifndef AUTHCOMMAND_H
-#define AUTHCOMMAND_H
-
-#include "abstractcommand.h"
-
-namespace AniDBUdpClient {
-
-class AuthCommand : public AbstractCommand
-{
-       Q_OBJECT
-
-       Q_PROPERTY(QString user READ user WRITE setUser);
-       Q_PROPERTY(QString pass READ pass WRITE setPass);
-       Q_PROPERTY(bool compression READ compression WRITE setCompression);
-
-       Q_PROPERTY(QString sessionId READ sessionId);
-       Q_PROPERTY(QString errorString READ errorString RESET clearError);
-
-public:
-       AuthCommand(QObject *parent = 0);
-       AuthCommand(const QString &user, const QString &pass, QObject *parent = 0);
-
-       QString user() const;
-       void setUser(const QString &user);
-
-       QString pass() const;
-       void setPass(const QString &pass);
-
-       bool compression() const;
-       void setCompression(bool compress);
-
-
-       QString sessionId() const;
-       QString errorString() const;
-       void clearError();
-
-
-       bool waitForResult() const;
-       bool requiresSession() const;
-
-       Command rawCommand() const;
-       void setRawReply(ReplyCode replyCode, const QString &reply, Client *client);
-
-private:
-       QString m_user;
-       QString m_pass;
-       QString m_sessionId;
-       QString m_errorString;
-
-       bool m_compression;
-};
-
-} // namespace AniDBUdpClient
-
-#endif // AUTHCOMMAND_H
+#ifndef AUTHCOMMAND_H\r
+#define AUTHCOMMAND_H\r
+\r
+#include "abstractcommand.h"\r
+\r
+namespace AniDBUdpClient {\r
+\r
+class AuthReply;\r
+\r
+class AuthCommand : public AbstractCommand\r
+{\r
+/*\r
+       Q_PROPERTY(QString user READ user WRITE setUser);\r
+       Q_PROPERTY(QString pass READ pass WRITE setPass);\r
+       Q_PROPERTY(bool compression READ compression WRITE setCompression);\r
+*/\r
+public:\r
+       typedef AuthReply ReplyType;\r
+       AuthCommand();\r
+       AuthCommand(const QString &user, const QString &pass);\r
+\r
+       QString user() const;\r
+       void setUser(const QString &user);\r
+\r
+       QString pass() const;\r
+       void setPass(const QString &pass);\r
+\r
+       bool compression() const;\r
+       void setCompression(bool compress);\r
+\r
+\r
+       bool waitForResult() const;\r
+       bool requiresSession() const;\r
+\r
+       Command rawCommand() const;\r
+\r
+private:\r
+       QString m_user;\r
+       QString m_pass;\r
+\r
+       bool m_compression;\r
+};\r
+\r
+class AuthReply : public AbstractReply\r
+{\r
+       Q_OBJECT\r
+       REPLY_DEFINITION_HELPER(Auth)\r
+\r
+       Q_PROPERTY(QString sessionId READ sessionId);\r
+       Q_PROPERTY(QString errorString READ errorString RESET clearError);\r
+\r
+public:\r
+\r
+       QString sessionId() const;\r
+       QString errorString() const;\r
+       void clearError();\r
+\r
+       void setRawReply(ReplyCode replyCode, const QString &reply);\r
+\r
+private:\r
+       QString m_sessionId;\r
+       QString m_errorString;\r
+};\r
+\r
+} // namespace AniDBUdpClient\r
+\r
+#endif // AUTHCOMMAND_H\r
index 38d9172185064f79527626ee32d5989a35c6163e..929a879638c5a8cfaed279fbedad552b4cf140c9 100644 (file)
@@ -44,12 +44,6 @@ qDebug() << "Api instance init!";
        m_host = "api.anidb.info";
        m_hostPort = 9000;
 
-       authCommand = new AuthCommand(this);
-       QObject::connect(authCommand, SIGNAL(replyReady(bool)), this, SLOT(doAuthenticate(bool)));
-
-       logoutCommand = new LogoutCommand(this);
-       uptimeCommand = new UptimeCommand(this);
-
        setFloodInterval(3);
 
        stateMachine = new QStateMachine(this);
@@ -138,10 +132,10 @@ Client::~Client()
 
        foreach (CommandData *cmd, sentCommands)
        {
-               if (!cmd->command->waitForResult())
+               if (!cmd->command->command().waitForResult())
                {
                        // Send CLIENT_DESTROYED to indicate that no real reply will come.
-                       cmd->command->setRawReply(CLIENT_DESTROYED, "", this);
+                       cmd->command->setRawReply(CLIENT_DESTROYED, "");
                }
        }
 
@@ -150,7 +144,7 @@ Client::~Client()
                while (commandTimer->isActive())
                        QCoreApplication::processEvents();
 
-               sendCommand(new LogoutCommand, true);
+               sendCommand(createReply(LogoutCommand()), true);
                socket->waitForBytesWritten(5);
        }
 
@@ -191,32 +185,32 @@ void Client::setLocalPort(quint16 port)
 
 QString Client::user() const
 {
-       return m_user;
+       return authCommand.user();
 }
 
 void Client::setUser(const QString &user)
 {
-       m_user = user;
+       authCommand.setUser(user);
 }
 
 QString Client::pass() const
 {
-       return m_pass;
+       return authCommand.pass();
 }
 
 void Client::setPass(const QString &pass)
 {
-       m_pass = pass;
+       authCommand.setPass(pass);
 }
 
 bool Client::compression() const
 {
-       return m_compression;
+       return authCommand.compression();
 }
 
 void Client::setCompression(bool compress)
 {
-       m_compression = compress;
+       authCommand.setCompression(compress);
 }
 
 int Client::floodInterval() const
@@ -314,11 +308,7 @@ qDebug() << "Entering Authenticating State";
 
        if (m_sessionId.isEmpty())
        {
-               authCommand->setUser(m_user);
-               authCommand->setPass(m_pass);
-               authCommand->setCompression(m_compression);
-
-               enqueueControlCommand(authCommand, true);
+               enqueueControlCommand(createReply(authCommand), true);
                return;
        }
        emit authenticated();
@@ -330,13 +320,13 @@ qDebug() << "doAuthenticate init";
        if (success)
        {
 qDebug() << "success!";
-               m_sessionId = authCommand->sessionId().toUtf8();
+               m_sessionId = authReply->sessionId().toUtf8();
                emit authenticated();
                return;
        }
 
        m_error = AuthenticationError;
-       m_errorString = authCommand->errorString();
+       m_errorString = authReply->errorString();
 
        emit connectionError();
 }
@@ -399,7 +389,7 @@ qDebug() << m_idlePolicy;
                        idleTimer->start(UDP_API_INACTIVITY_UPDATE * 1000);
                break;
                case ImmediateLogoutIdlePolicy:
-                       enqueueControlCommand(logoutCommand);
+                       enqueueControlCommand(logoutReply);
                break;
                default:
                break;
@@ -421,7 +411,7 @@ qDebug() << "Entering IdleTiemout State";
                        m_sessionId = "";
                break;
                case KeepAliveIdlePolicy:
-                       enqueueControlCommand(uptimeCommand);
+                       enqueueControlCommand(uptimeReply);
                default:
                break;
        }
@@ -449,7 +439,7 @@ qDebug() << "Entering Recieve State";
                        continue;
                }
 
-               if (m_compression && tmp.mid(0, 2) == "00")
+               if (authCommand.compression() && tmp.mid(0, 2) == "00")
                {
 qDebug() << "COMPRESSED DATAGRAM = " << tmp;
                        tmp = qUncompress(tmp);
@@ -527,7 +517,7 @@ qDebug() << "COMPRESSED DATAGRAM = " << tmp;
                }
 
                CommandData *commandData = sentCommands.take(commandId);
-               AbstractCommand *cmd = commandData->command;
+               AbstractReply *cmd = commandData->command;
                bool controlCommand = commandData->controlCommand;
                delete commandData;
 
@@ -582,7 +572,7 @@ qDebug() << "LOGIN FIRST required, authing";
                // tag + space + replyCode + space = 5 + 1 + 3 + 1
                reply = reply.mid(10);
 
-               cmd->setRawReply(replyCode, reply, this);
+               cmd->setRawReply(replyCode, reply);
 continueLoop:
                ;
        }
@@ -602,31 +592,31 @@ void Client::clearCommandQueue()
        // Delete all unsent commands that are managed by the client.
        while (!controlCommandQueue.isEmpty())
        {
-               AbstractCommand *cmd = commandQueue.dequeue();
-               if (!cmd->waitForResult())
+               AbstractReply *reply = commandQueue.dequeue();
+               if (!reply->command().waitForResult())
                {
                        // These would be deleted anyway
-                       delete cmd;
+                       delete reply;
                }
                else
                {
                        // Send CLIENT_DESTROYED to indicate that no real reply will come.
-                       cmd->setRawReply(CLIENT_DESTROYED, "", this);
+                       reply->setRawReply(CLIENT_DESTROYED, "");
                }
        }
 
        while (!commandQueue.isEmpty())
        {
-               AbstractCommand *cmd = commandQueue.dequeue();
-               if (!cmd->waitForResult())
+               AbstractReply *reply = commandQueue.dequeue();
+               if (!reply->command().waitForResult())
                {
                        // These would be deleted anyway
-                       delete cmd;
+                       delete reply;
                }
                else
                {
                        // Send CLIENT_DESTROYED to indicate that no real reply will come.
-                       cmd->setRawReply(CLIENT_DESTROYED, "", this);
+                       reply->setRawReply(CLIENT_DESTROYED, "");
                }
        }
 }
@@ -662,7 +652,7 @@ qDebug() << "Disconnecting" << (graceful ? "gracefully" : "");
        emit startDisconnecting();
 }
 
-void Client::send(AbstractCommand *command)
+void Client::send(AbstractReply *command)
 {
        connect();
 
@@ -673,18 +663,19 @@ void Client::send(AbstractCommand *command)
 void Client::sendRaw(QByteArray command)
 {
 qDebug() << QString("Sending RAW command: %1").arg(command.constData());
-       enqueueCommand(new RawCommand(command));
+       enqueueCommand(createReply(RawCommand(command)));
 }
 
-void Client::cancel(AbstractCommand *command)
+void Client::cancel(AbstractReply *reply)
 {
-       commandQueue.removeAll(command);
+       commandQueue.removeAll(reply);
+       sentCommands.remove(reply->id());
 }
 
 void Client::logout()
 {
        if (!m_sessionId.isEmpty())
-               enqueueControlCommand(logoutCommand);
+               enqueueControlCommand(logoutReply);
 }
 
 void Client::commandTimeout(const QByteArray &commandId)
@@ -707,7 +698,7 @@ qDebug() << commandId << "timed out";
        emit sendFailed();
 }
 
-void Client::enqueueCommand(AbstractCommand *command, bool first)
+void Client::enqueueCommand(AbstractReply *command, bool first)
 {
        if (first)
        {
@@ -721,7 +712,7 @@ void Client::enqueueCommand(AbstractCommand *command, bool first)
        emit startSending();
 }
 
-void Client::enqueueControlCommand(AbstractCommand *command, bool first)
+void Client::enqueueControlCommand(AbstractReply *command, bool first)
 {
        if (first)
        {
@@ -735,9 +726,9 @@ void Client::enqueueControlCommand(AbstractCommand *command, bool first)
        emit startSending();
 }
 
-void Client::sendCommand(AbstractCommand *command, bool controlCommand)
+void Client::sendCommand(AbstractReply *command, bool controlCommand)
 {
-       if (m_sessionId.isEmpty() && command->requiresSession())
+       if (m_sessionId.isEmpty() && command->command().requiresSession())
        {
                if (controlCommand)
                        enqueueControlCommand(command, true);
@@ -747,10 +738,10 @@ void Client::sendCommand(AbstractCommand *command, bool controlCommand)
                return;
        }
 
-       Command cmdPair = command->rawCommand();
+       Command cmdPair = command->command().rawCommand();
        QByteArray datagram = buildCmd(cmdPair.first, cmdPair.second);
 
-       QByteArray commandId = nextCommandId();
+       QByteArray commandId = command->id();
 
        datagram += datagram.contains(" ") ? "&" : " ";
        datagram += "tag=" + commandId;
@@ -774,7 +765,7 @@ qDebug() << QString("SENDING datagram:\n\t%1\nto: %2 ([%3]:%4)")
 
 void Client::removeDeletedFromQueue()
 {
-       AbstractCommand *cmd = (AbstractCommand *) sender();
+       AbstractReply *cmd = (AbstractReply *) sender();
        cancel(cmd);
 }
 
@@ -823,7 +814,7 @@ qDebug() << QString("Generated id %1").arg(result.constData());
 
 Client *Client::m_instance = 0;
 
-CommandData::CommandData(AbstractCommand *command, const QByteArray &commandId, bool controlCommand) : QObject()
+CommandData::CommandData(AbstractReply *command, const QByteArray &commandId, bool controlCommand) : QObject()
 {
        this->command = command;
        this->controlCommand = controlCommand;
index 854938fbdcdba796f071a6d60c28a1c0500c1125..87aabbdaee51c32fedaea1cd16ff456fd1f29a5c 100644 (file)
@@ -22,18 +22,18 @@ class QTimer;
 namespace AniDBUdpClient {
 
 class AbstractCommand;
-class AuthCommand;
-class LogoutCommand;
-class UptimeCommand;
+class LogoutReply;
+class UptimeReply;
 
 class CommandData;
 
 class ANIDBUDPCLIENTSHARED_EXPORT Client : public QObject
 {
        friend class CommandData;
+       friend class AbstractReply;
 
        Q_OBJECT
-       Q_ENUMS(AniDBUdpClient::State AniDBUdpClient::Error AniDBUdpClient::IdlePolicy AniDBUdpClientReplyCode);
+       Q_ENUMS(AniDBUdpClient::State AniDBUdpClient::Error AniDBUdpClient::IdlePolicy AniDBUdpClient::ReplyCode);
 
        Q_PROPERTY(QString host READ host WRITE setHost);
        Q_PROPERTY(quint16 hostPort READ hostPort WRITE setHostPort);
@@ -101,9 +101,25 @@ public slots:
        */
        void disconnect(bool graceful = false);
 
-       void send(AbstractCommand *command);
+public:
+       template<typename T> typename T::ReplyType *send(const T &command, QObject *parent = 0)
+       {
+               typename T::ReplyType *reply = createReply(command, parent);
+               send(reply);
+               return reply;
+       }
+
+private:
+       template<typename T> typename T::ReplyType *createReply(const T &command, QObject *parent = 0)
+       {
+               return new T::ReplyType(command, nextCommandId(), this, parent);
+       }
+public slots:
+
+       void send(AbstractReply *reply);
+
        void sendRaw(QByteArray command);
-       void cancel(AbstractCommand *command);
+       void cancel(AbstractReply *command);
 
 signals:
 
@@ -153,9 +169,9 @@ private slots:
        void removeDeletedFromQueue();
 
 private:
-       void enqueueCommand(AbstractCommand *command, bool first = false);
-       void enqueueControlCommand(AbstractCommand *command, bool first = false);
-       void sendCommand(AbstractCommand *command, bool controlCommand = false);
+       void enqueueCommand(AbstractReply *command, bool first = false);
+       void enqueueControlCommand(AbstractReply *command, bool first = false);
+       void sendCommand(AbstractReply *command, bool controlCommand = false);
 
 
        QByteArray buildCmd(const QString &cmd, const QVariantMap &args);
@@ -165,8 +181,8 @@ private:
        QTimer *idleTimer;
        QTimer *replyTimeoutTimer;
 
-       QQueue<AbstractCommand *> commandQueue;
-       QQueue<AbstractCommand *> controlCommandQueue;
+       QQueue<AbstractReply *> commandQueue;
+       QQueue<AbstractReply *> controlCommandQueue;
        QMap<QByteArray, CommandData *> sentCommands;
        QUdpSocket *socket;
 
@@ -180,12 +196,6 @@ private:
 
        int m_floodInterval;
 
-       // Auth params
-       QString m_user;
-       QString m_pass;
-
-       bool m_compression;
-
        QByteArray m_sessionId;
 
        // Misc params
@@ -197,9 +207,10 @@ private:
 
        int commandsTimedOut;
 
-       AuthCommand *authCommand;
-       LogoutCommand *logoutCommand;
-       UptimeCommand *uptimeCommand;
+       AuthCommand authCommand;
+       AuthReply *authReply;
+       LogoutReply *logoutReply;
+       UptimeReply *uptimeReply;
 
        static Client *m_instance;
 
@@ -235,12 +246,12 @@ class CommandData : QObject
 
        Q_OBJECT
 public:
-       AbstractCommand *command;
+       AbstractReply *command;
        bool controlCommand;
        QByteArray commandId;
        QTimer timer;
 
-       CommandData(AbstractCommand *command, const QByteArray &commandId, bool controlCommand = false);
+       CommandData(AbstractReply *command, const QByteArray &commandId, bool controlCommand = false);
 signals:
        void timeout(QByteArray commandId);
 private slots:
index e27592bafab50d8469a4c059286e1c51e53dccae..a8532cefb5108324714621f7a44fba1a0266eed6 100644 (file)
@@ -21,15 +21,15 @@ File::File(const QFileInfo &file, QObject *parent) : QObject(parent)
 
 File::~File()
 {
-       if (fileCommand)
+       if (fileReply)
        {
-               delete fileCommand;
-               fileCommand = 0;
+               delete fileReply;
+               fileReply = 0;
        }
-       if (addCommand)
+       if (addReply)
        {
-               delete addCommand;
-               addCommand = 0;
+               delete addReply;
+               addReply = 0;
        }
        if (hashResult)
        {
@@ -150,17 +150,17 @@ qDebug() << "finishRenaming";
                return;
        }
 
-       QString name = fileCommand->value(FileAnimeFlag::RomajiName).toString();
+       QString name = fileReply->value(FileAnimeFlag::RomajiName).toString();
        if (name.isEmpty())
-               name = fileCommand->value(FileAnimeFlag::EnglishName).toString();
+               name = fileReply->value(FileAnimeFlag::EnglishName).toString();
 
        QString newFileName = tr("%1 - %2 - %3 - [%4](%5).%6")
                                           .arg(name)
-                                          .arg(fileCommand->value(FileAnimeFlag::EpNo).toString())
-                                          .arg(fileCommand->value(FileAnimeFlag::EpName).toString())
-                                          .arg(fileCommand->value(FileAnimeFlag::GroupShortName).toString())
-                                          .arg(fileCommand->value(FileFlag::Crc32).toString())
-                                          .arg(fileCommand->value(FileFlag::FileType).toString());
+                                          .arg(fileReply->value(FileAnimeFlag::EpNo).toString())
+                                          .arg(fileReply->value(FileAnimeFlag::EpName).toString())
+                                          .arg(fileReply->value(FileAnimeFlag::GroupShortName).toString())
+                                          .arg(fileReply->value(FileFlag::Crc32).toString())
+                                          .arg(fileReply->value(FileFlag::FileType).toString());
 
        newFileName.replace('"', "'");
        newFileName.replace(QRegExp("[\\/]"), "-");
@@ -284,24 +284,23 @@ qDebug() << "startRenaming";
                return;
        }
 
-       if (fileCommand)
-               delete fileCommand;
-
-       fileCommand = new FileCommand(m_ed2k,
-                                                                 size(),
-                                                                 FileFlag::Crc32
-                                                                 | FileFlag::FileType
-                                                                 | FileFlag::Lid,
-                                                                 FileAnimeFlag::EnglishName
-                                                                 | FileAnimeFlag::RomajiName
-                                                                 | FileAnimeFlag::KanjiName
-                                                                 | FileAnimeFlag::EpNo
-                                                                 | FileAnimeFlag::EpName
-                                                                 | FileAnimeFlag::GroupShortName,
-                                                                 this);
-
-       connect(fileCommand, SIGNAL(replyReady(bool)), this, SLOT(finishRenaming(bool)));
-       Client::instance()->send(fileCommand);
+       if (fileReply)
+               delete fileReply;
+
+       FileCommand fileCommand(m_ed2k,
+                                                 size(),
+                                                 FileFlag::Crc32
+                                                 | FileFlag::FileType
+                                                 | FileFlag::Lid,
+                                                 FileAnimeFlag::EnglishName
+                                                 | FileAnimeFlag::RomajiName
+                                                 | FileAnimeFlag::KanjiName
+                                                 | FileAnimeFlag::EpNo
+                                                 | FileAnimeFlag::EpName
+                                                 | FileAnimeFlag::GroupShortName);
+       fileReply = Client::instance()->send(fileCommand);
+       connect(fileReply, SIGNAL(replyReady(bool)), this, SLOT(finishRenaming(bool)));
+
        updateStatus(Renaming, InProgress);
 }
 
@@ -313,15 +312,17 @@ void File::startAdding()
                return;
        }
 
-       if (addCommand)
-               delete addCommand;
+       if (addReply)
+               delete addReply;
+
+       MyListAddCommand addCommand(m_ed2k, size(), false);
+       addCommand.setState(StateOnHdd);
+
+       addReply = Client::instance()->send(addCommand);
 
-       addCommand = new MyListAddCommand(m_ed2k, size(), false);
-       addCommand->setState(StateOnHdd);
+       connect(addReply, SIGNAL(replyReady(bool)), this, SLOT(finishAdding(bool)));
 
-       connect(addCommand, SIGNAL(replyReady(bool)), this, SLOT(finishAdding(bool)));
 
-       Client::instance()->send(addCommand);
        updateStatus(Adding, InProgress);
 }
 
@@ -337,8 +338,8 @@ void File::startMarking()
 void File::init()
 {
        hashResult = 0;
-       fileCommand = 0;
-       addCommand = 0;
+       fileReply = 0;
+       addReply = 0;
        m_hashingState = m_renamingState = m_addingState = m_markingState = NotStarted;
        notWorking = true;
 
index db61f0a91d8fd0b9439ae825a74514b59b192015..9118a0d8e2519fda8fcc18fd0dc15a37aecf5dd1 100644 (file)
@@ -112,8 +112,8 @@ private:
        ActionState m_markingState;
 
        HashResult *hashResult;
-       FileCommand *fileCommand;
-       MyListAddCommand *addCommand;
+       FileReply *fileReply;
+       MyListAddReply *addReply;
 
 };
 
index bf3c51f6ae30a26953a19136980b1626f42c6273..5dcf719d0645577fa381451d71ac8e666639781f 100644 (file)
@@ -6,12 +6,12 @@
 
 namespace AniDBUdpClient {
 
-FileCommand::FileCommand(QObject *parent) : AbstractCommand(parent)
+FileCommand::FileCommand() : AbstractCommand()
 {
        init();
 }
 
-FileCommand::FileCommand(int fid, FileFlags fmask, FileAnimeFlags amask, QObject *parent) : AbstractCommand(parent)
+FileCommand::FileCommand(int fid, FileFlags fmask, FileAnimeFlags amask) : AbstractCommand()
 {
        init();
        m_fid = fid;
@@ -19,7 +19,7 @@ FileCommand::FileCommand(int fid, FileFlags fmask, FileAnimeFlags amask, QObject
        m_amask = amask;
 }
 
-FileCommand::FileCommand(const QByteArray &ed2k, qint64 size, FileFlags fmask, FileAnimeFlags amask, QObject *parent) : AbstractCommand(parent)
+FileCommand::FileCommand(const QByteArray &ed2k, qint64 size, FileFlags fmask, FileAnimeFlags amask) : AbstractCommand()
 {
        init();
        m_ed2k = ed2k;
@@ -28,7 +28,7 @@ FileCommand::FileCommand(const QByteArray &ed2k, qint64 size, FileFlags fmask, F
        m_amask = amask;
 }
 
-FileCommand::FileCommand(const QString &aname, const QString &gname, int epno, FileFlags fmask, FileAnimeFlags amask, QObject *parent) : AbstractCommand(parent)
+FileCommand::FileCommand(const QString &aname, const QString &gname, int epno, FileFlags fmask, FileAnimeFlags amask) : AbstractCommand()
 {
        init();
        m_aname = aname;
@@ -38,7 +38,7 @@ FileCommand::FileCommand(const QString &aname, const QString &gname, int epno, F
        m_amask = amask;
 }
 
-FileCommand::FileCommand(const QString &aname, int gid, int epno, FileFlags fmask, FileAnimeFlags amask, QObject *parent) : AbstractCommand(parent)
+FileCommand::FileCommand(const QString &aname, int gid, int epno, FileFlags fmask, FileAnimeFlags amask) : AbstractCommand()
 {
        init();
        m_aname = aname;
@@ -48,7 +48,7 @@ FileCommand::FileCommand(const QString &aname, int gid, int epno, FileFlags fmas
        m_amask = amask;
 }
 
-FileCommand::FileCommand(int aid, const QString &gname, int epno, FileFlags fmask, FileAnimeFlags amask, QObject *parent) : AbstractCommand(parent)
+FileCommand::FileCommand(int aid, const QString &gname, int epno, FileFlags fmask, FileAnimeFlags amask) : AbstractCommand()
 {
        init();
        m_aid = aid;
@@ -58,7 +58,7 @@ FileCommand::FileCommand(int aid, const QString &gname, int epno, FileFlags fmas
        m_amask = amask;
 }
 
-FileCommand::FileCommand(int aid, int gid, int epno, FileFlags fmask, FileAnimeFlags amask, QObject *parent) : AbstractCommand(parent)
+FileCommand::FileCommand(int aid, int gid, int epno, FileFlags fmask, FileAnimeFlags amask) : AbstractCommand()
 {
        init();
        m_aid = aid;
@@ -169,16 +169,6 @@ void FileCommand::setAmask(FileAnimeFlags amask)
        m_amask = amask;
 }
 
-QVariant FileCommand::value(FileFlags f) const
-{
-       return fileFlagData.value(f);
-}
-
-QVariant FileCommand::value(FileAnimeFlags f) const
-{
-       return fileAnimeFlagData.value(f);
-}
-
 bool FileCommand::waitForResult() const
 {
        return true;
@@ -241,10 +231,39 @@ Command FileCommand::rawCommand() const
        return cmd;
 }
 
+void FileCommand::init()
+{
+       m_fid = 0;
+       m_aid = 0;
+       m_gid = 0;
+
+       m_size = 0;
+       m_epno = 0;
+
+       m_fmask = FileFlags(0);
+       m_amask = AnimeFlags(0);
+}
+
+// ===
 
-void FileCommand::setRawReply(ReplyCode replyCode, const QString &reply, Client *client)
+int FileReply::fid() const
 {
-       AbstractCommand::setRawReply(replyCode, reply, client);
+       return m_fid;
+}
+
+QVariant FileReply::value(FileFlags f) const
+{
+       return fileFlagData.value(f);
+}
+
+QVariant FileReply::value(FileAnimeFlags f) const
+{
+       return fileAnimeFlagData.value(f);
+}
+
+void FileReply::setRawReply(ReplyCode replyCode, const QString &reply)
+{
+       AbstractReply::setRawReply(replyCode, reply);
 
        switch (replyCode)
        {
@@ -263,7 +282,7 @@ void FileCommand::setRawReply(ReplyCode replyCode, const QString &reply, Client
        }
 }
 
-void FileCommand::readReplyData(const QString &reply)
+void FileReply::readReplyData(const QString &reply)
 {
        QString d = reply.mid(reply.indexOf('\n')).trimmed();
 qDebug() << d;
@@ -271,7 +290,7 @@ qDebug() << d;
 qDebug() << parts;
        m_fid = parts[0].toInt();
 
-       if (m_fmask == 0 && m_amask == 0)
+       if (command().fmask() == 0 && command().amask() == 0)
        {
                fileFlagData.insert(FileFlag::Aid,                              parts[1].toInt());
                fileFlagData.insert(FileFlag::Eid,                              parts[2].toInt());
@@ -286,7 +305,7 @@ qDebug() << parts;
        int partNo = 1;
        for (int i = 0, flag = 1 << 31; i < 32; ++i, flag = (flag >> 1) & ~(1 << 31))
        {
-               if (m_fmask & flag)
+               if (command().fmask() & flag)
                {
                        if (partNo >= parts.size())
                        {
@@ -300,7 +319,7 @@ qDebug() << "Not enough parts in reply.";
 
        for (int i = 0, flag = 1 << 31; i < 32; ++i, flag = (flag >> 1) & ~(1 << 31))
        {
-               if (m_amask & flag)
+               if (command().amask() & flag)
                {
                        if (partNo >= parts.size())
                        {
@@ -313,17 +332,9 @@ qDebug() << "Not enough parts in reply.";
        }
 }
 
-void FileCommand::init()
+void FileReply::init()
 {
        m_fid = 0;
-       m_aid = 0;
-       m_gid = 0;
-
-       m_size = 0;
-       m_epno = 0;
-
-       m_fmask = FileFlags(0);
-       m_amask = AnimeFlags(0);
 }
 
 } // namespace AniDBUdpClient
index 7fdef4b825ffe3aed7ff6d3ac0f6a45e3079f549..dabc761533a9e4d6d97d94715762be61364701cc 100644 (file)
-#ifndef FILECOMMAND_H
-#define FILECOMMAND_H
-
-#include "anidbudpclient_global.h"
-#include "abstractcommand.h"
-
-#include <QVariant>
-
-namespace AniDBUdpClient {
-
-class ANIDBUDPCLIENTSHARED_EXPORT FileCommand : public AbstractCommand
-{
-       Q_OBJECT
-
-       Q_PROPERTY(int fid READ fid WRITE setFid);
-
-       Q_PROPERTY(QByteArray ed2k READ ed2k WRITE setEd2k);
-       Q_PROPERTY(qint64 size READ size WRITE setSize);
-
-       Q_PROPERTY(QString aname READ aname WRITE setAname);
-       Q_PROPERTY(int aid READ aid WRITE setAid);
-       Q_PROPERTY(QString gname READ gname WRITE setGname);
-       Q_PROPERTY(int gid READ gid WRITE setGid);
-       Q_PROPERTY(int epno READ epno WRITE setEpno);
-
-       Q_PROPERTY(FileFlags fmask READ fmask WRITE setFmask);
-       Q_PROPERTY(FileAnimeFlags amask READ amask WRITE setAmask);
-
-public:
-       FileCommand(QObject *parent = 0);
-       FileCommand(int fid, FileFlags fmask = FileFlags(0), FileAnimeFlags = FileAnimeFlags(0), QObject *parent = 0);
-       FileCommand(const QByteArray &ed2k, qint64 size, FileFlags fmask = FileFlags(0), FileAnimeFlags = FileAnimeFlags(0), QObject *parent = 0);
-       FileCommand(const QString &aname, const QString &gname, int epno, FileFlags fmask = FileFlags(0), FileAnimeFlags = FileAnimeFlags(0), QObject *parent = 0);
-       FileCommand(const QString &aname, int gid, int epno, FileFlags fmask = FileFlags(0), FileAnimeFlags = FileAnimeFlags(0), QObject *parent = 0);
-       FileCommand(int aid, const QString &gname, int epno, FileFlags fmask = FileFlags(0), FileAnimeFlags = FileAnimeFlags(0), QObject *parent = 0);
-       FileCommand(int aid, int gid, int epno, FileFlags fmask = FileFlags(0), FileAnimeFlags = FileAnimeFlags(0), QObject *parent = 0);
-
-       int fid() const;
-       void setFid(int fid);
-
-       QByteArray ed2k() const;
-       void setEd2k(const QByteArray &ed2k);
-       qint64 size() const;
-       void setSize(qint64 size);
-
-       QString aname() const;
-       void setAname(const QString &aname);
-       int aid() const;
-       void setAid(int aid);
-       QString gname() const;
-       void setGname(const QString &gname);
-       int gid() const;
-       void setGid(int gid);
-       int epno() const;
-       void setEpno(int epno);
-
-       FileFlags fmask() const;
-       void setFmask(FileFlags fmask);
-       FileAnimeFlags amask() const;
-       void setAmask(FileAnimeFlags amask);
-
-
-       QVariant value(FileFlags f) const;
-       QVariant value(FileAnimeFlags f) const;
-
-
-       bool waitForResult() const;
-       Command rawCommand() const;
-       void setRawReply(ReplyCode replyCode, const QString &reply, Client *client);
-
-
-private:
-       void readReplyData(const QString &reply);
-       void init();
-
-       int m_fid;
-
-       QByteArray m_ed2k;
-       qint64 m_size;
-
-       QString m_aname;
-       int m_aid;
-       QString m_gname;
-       int m_gid;
-       int m_epno;
-
-       FileFlags m_fmask;
-       FileAnimeFlags m_amask;
-
-       QMap<FileFlags, QVariant> fileFlagData;
-       QMap<FileAnimeFlags, QVariant> fileAnimeFlagData;
-};
-
-} // namespace AniDBUdpClient
-
-#include <QScriptEngine>
-Q_SCRIPT_DECLARE_QMETAOBJECT(AniDBUdpClient::FileCommand, QObject*);
-
-#endif // FILECOMMAND_H
+#ifndef FILECOMMAND_H\r
+#define FILECOMMAND_H\r
+\r
+#include "anidbudpclient_global.h"\r
+#include "abstractcommand.h"\r
+\r
+#include <QVariant>\r
+\r
+namespace AniDBUdpClient {\r
+\r
+class FileReply;\r
+\r
+class ANIDBUDPCLIENTSHARED_EXPORT FileCommand : public AbstractCommand\r
+{\r
+/*\r
+       Q_PROPERTY(int fid READ fid WRITE setFid);\r
+\r
+       Q_PROPERTY(QByteArray ed2k READ ed2k WRITE setEd2k);\r
+       Q_PROPERTY(qint64 size READ size WRITE setSize);\r
+\r
+       Q_PROPERTY(QString aname READ aname WRITE setAname);\r
+       Q_PROPERTY(int aid READ aid WRITE setAid);\r
+       Q_PROPERTY(QString gname READ gname WRITE setGname);\r
+       Q_PROPERTY(int gid READ gid WRITE setGid);\r
+       Q_PROPERTY(int epno READ epno WRITE setEpno);\r
+\r
+       Q_PROPERTY(FileFlags fmask READ fmask WRITE setFmask);\r
+       Q_PROPERTY(FileAnimeFlags amask READ amask WRITE setAmask);\r
+*/\r
+public:\r
+       typedef FileReply ReplyType;\r
+       FileCommand();\r
+       FileCommand(int fid, FileFlags fmask = FileFlags(0), FileAnimeFlags = FileAnimeFlags(0));\r
+       FileCommand(const QByteArray &ed2k, qint64 size, FileFlags fmask = FileFlags(0), FileAnimeFlags = FileAnimeFlags(0));\r
+       FileCommand(const QString &aname, const QString &gname, int epno, FileFlags fmask = FileFlags(0), FileAnimeFlags = FileAnimeFlags(0));\r
+       FileCommand(const QString &aname, int gid, int epno, FileFlags fmask = FileFlags(0), FileAnimeFlags = FileAnimeFlags(0));\r
+       FileCommand(int aid, const QString &gname, int epno, FileFlags fmask = FileFlags(0), FileAnimeFlags = FileAnimeFlags(0));\r
+       FileCommand(int aid, int gid, int epno, FileFlags fmask = FileFlags(0), FileAnimeFlags = FileAnimeFlags(0));\r
+\r
+       int fid() const;\r
+       void setFid(int fid);\r
+\r
+       QByteArray ed2k() const;\r
+       void setEd2k(const QByteArray &ed2k);\r
+       qint64 size() const;\r
+       void setSize(qint64 size);\r
+\r
+       QString aname() const;\r
+       void setAname(const QString &aname);\r
+       int aid() const;\r
+       void setAid(int aid);\r
+       QString gname() const;\r
+       void setGname(const QString &gname);\r
+       int gid() const;\r
+       void setGid(int gid);\r
+       int epno() const;\r
+       void setEpno(int epno);\r
+\r
+       FileFlags fmask() const;\r
+       void setFmask(FileFlags fmask);\r
+       FileAnimeFlags amask() const;\r
+       void setAmask(FileAnimeFlags amask);\r
+\r
+       bool waitForResult() const;\r
+       Command rawCommand() const;\r
+\r
+private:\r
+       void init();\r
+\r
+       int m_fid;\r
+\r
+       QByteArray m_ed2k;\r
+       qint64 m_size;\r
+\r
+       QString m_aname;\r
+       int m_aid;\r
+       QString m_gname;\r
+       int m_gid;\r
+       int m_epno;\r
+\r
+       FileFlags m_fmask;\r
+       FileAnimeFlags m_amask;\r
+};\r
+\r
+class ANIDBUDPCLIENTSHARED_EXPORT FileReply : public AbstractReply\r
+{\r
+       Q_OBJECT\r
+       REPLY_DEFINITION_HELPER2(File)\r
+\r
+       Q_PROPERTY(int fid READ fid);\r
+\r
+public:\r
+       int fid() const;\r
+\r
+       QVariant value(FileFlags f) const;\r
+       QVariant value(FileAnimeFlags f) const;\r
+\r
+       void setRawReply(ReplyCode replyCode, const QString &reply);\r
+\r
+private:\r
+       void readReplyData(const QString &reply);\r
+       void init();\r
+\r
+       int m_fid;\r
+\r
+       QMap<FileFlags, QVariant> fileFlagData;\r
+       QMap<FileAnimeFlags, QVariant> fileAnimeFlagData;\r
+};\r
+\r
+} // namespace AniDBUdpClient\r
+\r
+#endif // FILECOMMAND_H\r
index 0e834c2037a38ba2c0cdc8b4e06d0072f815d074..232a2aa9f7dbdc4a791ec6cccd47683abd68b1ab 100644 (file)
@@ -63,7 +63,7 @@ private:
        static Hash *m_instance;
 };
 
-class HashRequest
+class ANIDBUDPCLIENTSHARED_EXPORT HashRequest
 {
 public:
        HashRequest(const QFileInfo &fileInfo = QFileInfo());
@@ -78,7 +78,7 @@ private:
        QFileInfo m_fileInfo;
 };
 
-class HashResult : public QObject
+class ANIDBUDPCLIENTSHARED_EXPORT HashResult : public QObject
 {
        friend class Hash;
 
index dfac7a104ee5205a9273528fa40c990f3c3a00b4..63372f7d6690b76b272027dc72e81ad50f839bb1 100644 (file)
@@ -2,7 +2,7 @@
 
 namespace AniDBUdpClient {
 
-LogoutCommand::LogoutCommand(QObject *parent) : AbstractCommand(parent)
+LogoutCommand::LogoutCommand() : AbstractCommand()
 {
 }
 
index 949556125283825ea46ce85d3627aa1fbfa6f5c4..f3afab5479cc69563dff4244f20a232c4e58bd89 100644 (file)
@@ -5,14 +5,24 @@
 
 namespace AniDBUdpClient {
 
+class LogoutReply;
+
 class ANIDBUDPCLIENTSHARED_EXPORT LogoutCommand : public AbstractCommand
 {
-       Q_OBJECT
 public:
-       LogoutCommand(QObject *parent = 0);
+       typedef LogoutReply ReplyType;
+
+       LogoutCommand();
        Command rawCommand() const;
 };
 
+class ANIDBUDPCLIENTSHARED_EXPORT LogoutReply : public AbstractReply
+{
+       Q_OBJECT
+       REPLY_DEFINITION_HELPER(Logout)
+public:
+};
+
 } // namespace AniDBUdpClient
 
 #endif // LOGOUTCOMMAND_H
index 583d08a0730ee4b24b6afdbf9a576af80b3ad726..a22f0a6037bffc839eab5babb7d4c3040fbd372f 100644 (file)
 namespace AniDBUdpClient {
 
 
-MyListAddCommand::MyListAddCommand(int fid, bool edit, QObject *parent) : AbstractCommand(parent)
+MyListAddCommand::MyListAddCommand(int fid, bool edit) : AbstractCommand()
 {
        init();
        m_fid = fid;
        m_edit = edit;
 }
 
-MyListAddCommand::MyListAddCommand(const QByteArray &ed2k, qint64 size, bool edit, QObject *parent) : AbstractCommand(parent)
+MyListAddCommand::MyListAddCommand(const QByteArray &ed2k, qint64 size, bool edit) : AbstractCommand()
 {
        init();
        m_ed2k = ed2k;
@@ -26,7 +26,7 @@ MyListAddCommand::MyListAddCommand(const QByteArray &ed2k, qint64 size, bool edi
        m_edit = edit;
 }
 
-MyListAddCommand::MyListAddCommand(int lid, QObject *parent) : AbstractCommand(parent)
+MyListAddCommand::MyListAddCommand(int lid) : AbstractCommand()
 {
        init();
        m_lid = lid;
@@ -218,16 +218,32 @@ Command MyListAddCommand::rawCommand() const
        return cmd;
 }
 
-void MyListAddCommand::setRawReply(ReplyCode replyCode, const QString &reply, Client *client)
+void MyListAddCommand::init()
+{
+       m_fid = 0;
+       m_lid = 0;
+
+       m_state = StateUnknown;
+       m_viewed = Unset;
+}
+
+// ===
+
+int MyListAddReply::lid() const
+{
+       return m_lid;
+}
+
+void MyListAddReply::setRawReply(ReplyCode replyCode, const QString &reply)
 {
-       AbstractCommand::setRawReply(replyCode, reply, client);
+       AbstractReply::setRawReply(replyCode, reply);
 
        switch (replyCode)
        {
                case MYLIST_ENTRY_ADDED:
                {
                        QString lid = reply.mid(reply.indexOf('\n')).trimmed();
-                       if (!m_edit)
+                       if (!command().edit())
                        {
                                m_lid = lid.toInt();
                        }
@@ -248,175 +264,9 @@ void MyListAddCommand::setRawReply(ReplyCode replyCode, const QString &reply, Cl
        }
 }
 
-
-void MyListAddCommand::init()
+void MyListAddReply::init()
 {
-       m_fid = 0;
        m_lid = 0;
-
-       m_state = StateUnknown;
-       m_viewed = Unset;
-}
-
-
-// ===================================================================================
-
-
-MylistAddCommand::MylistAddCommand(QString file, QObject *parent) : AbstractCommand(parent)
-{
-       m_file = file;
-       m_size = QFileInfo(file).size();
-       mylistId = 0;
-
-       connect(&futureWatcher, SIGNAL(finished()), this, SLOT(completeHash()));
-}
-
-QString MylistAddCommand::file() const
-{
-       return m_file;
-}
-
-QByteArray MylistAddCommand::ed2kHash() const
-{
-       return m_ed2k;
-}
-
-qint64 MylistAddCommand::fileSize() const
-{
-       return m_size;
-}
-
-bool MylistAddCommand::markWatched() const
-{
-       return m_markWatched;
-}
-
-void MylistAddCommand::setMarkWatched(bool mark)
-{
-       m_markWatched = mark;
-}
-
-bool MylistAddCommand::waitForResult() const
-{
-       return true;
-}
-
-Command MylistAddCommand::rawCommand() const
-{
-       Command command;
-       switch (mylistId)
-       {
-               case 0:
-                       command.first = "MYLIST";
-                       command.second["size"] = m_size;
-                       command.second["ed2k"] = m_ed2k.constData();
-                       return command;
-               break;
-               case -1:
-                       command.first = "MYLISTADD";
-                       command.second["size"] = m_size;
-                       command.second["ed2k"] = m_ed2k.constData();
-                       command.second["state"] = 1;
-                       command.second["viewed"] = m_markWatched;
-                       return command;
-               break;
-               default:
-                       command.first = "MYLISTADD";
-                       command.second["lid"] = mylistId;
-                       command.second["viewed"] = m_markWatched;
-                       command.second["edit"] = 1;
-                       return command;
-               break;
-       }
-}
-
-void MylistAddCommand::setRawReply(ReplyCode replyCode, const QString &reply, Client *client)
-{
-       AbstractCommand::setRawReply(replyCode, reply, client);
-
-       switch (mylistId)
-       {
-               case 0:
-                       switch(replyCode)
-                       {
-                               case MYLIST:
-                               {
-                                       QString reply = m_rawReply.mid(m_rawReply.indexOf("\n"));
-                                       QStringList parts = reply.split('|', QString::KeepEmptyParts);
-qDebug() << "PARTS" << parts;
-                                       mylistId = parts[0].toInt();
-qDebug() << "Mylist ID: " << mylistId;
-                                       if (!mylistId)
-                                       {
-qDebug() << "FAILED to read Mylist ID";
-                                               emit replyReady(false);
-                                       }
-                                       client->send(this);
-                               }
-                               break;
-                               default:
-                                       mylistId = -1;
-                                       client->send(this);
-                               break;
-                       }
-               break;
-               default:
-                       switch(replyCode)
-                       {
-                               case MYLIST_ENTRY_ADDED:
-                               case MYLIST_ENTRY_EDITED:
-                               case FILE_ALREADY_IN_MYLIST:
-                                       emit replyReady(true);
-                               break;
-                               default:
-                                       emit replyReady(false);
-                               break;
-                       }
-               break;
-       }
-}
-
-void MylistAddCommand::hash()
-{
-       t.start();
-       future = QtConcurrent::run(this, &MylistAddCommand::doHash, m_file);
-       futureWatcher.setFuture(future);
-}
-
-void MylistAddCommand::completeHash()
-{
-       if (!future.isFinished())
-       {
-qDebug() << "WTF?";
-               return;
-       }
-       m_ed2k = QByteArray(future);
-       emit hashComplete();
-       qDebug() << "Time:" << t.elapsed();
-}
-
-QByteArray MylistAddCommand::doHash(QString file)
-{
-qDebug() << "hash thread init";
-       QThread::currentThread()->setPriority(QThread::LowPriority);
-
-       QFile f(file);
-       if (!f.open(QIODevice::ReadOnly))
-               return QByteArray();
-
-       QCryptographicHash ed2k(QCryptographicHash::Md4);
-       char *data = new char[ED2K_PART_SIZE];
-       int size;
-       while (!f.atEnd())
-       {
-               size = f.read(data, ED2K_PART_SIZE);
-               ed2k.addData(QCryptographicHash::hash(QByteArray(data, size), QCryptographicHash::Md4));
-//qDebug() << "hashing...";
-       }
-       f.close();
-       delete[] data;
-qDebug() << "hashing... complete!";
-       return ed2k.result().toHex();
 }
 
 } // namespace AniDBUdpClient
index ce737f6f9e655dde88dc1690bccce6e403040ffe..0187487cc91bc1fc0e428b3d7e635fa2cccffc48 100644 (file)
@@ -9,12 +9,13 @@
 
 namespace AniDBUdpClient {
 
+class MyListAddReply;
+
 class ANIDBUDPCLIENTSHARED_EXPORT MyListAddCommand : public AbstractCommand
 {
+/*
        Q_ENUMS(ViewedState);
 
-       Q_OBJECT
-
        Q_PROPERTY(int fid READ fid WRITE setFid);
        Q_PROPERTY(int lid READ lid WRITE setLid);
 
@@ -29,18 +30,18 @@ class ANIDBUDPCLIENTSHARED_EXPORT MyListAddCommand : public AbstractCommand
        Q_PROPERTY(QString source READ source WRITE setSource);
        Q_PROPERTY(QString storage READ storage WRITE setStorage);
        Q_PROPERTY(QString other READ other WRITE setOther);
-
+*/
 public:
-
+       typedef MyListAddReply ReplyType;
        enum ViewedState {
                Unset = -1,
                NotViewed = 0,
                Viewed = 1,
        };
 
-       MyListAddCommand(int fid, bool edit, QObject *parent = 0);
-       MyListAddCommand(const QByteArray &ed2k, qint64 size, bool edit, QObject *parent = 0);
-       explicit MyListAddCommand(int lid, QObject *parent = 0);
+       MyListAddCommand(int fid, bool edit);
+       MyListAddCommand(const QByteArray &ed2k, qint64 size, bool edit);
+       explicit MyListAddCommand(int lid);
 
        int fid() const;
        void setFid(int fid);
@@ -76,13 +77,10 @@ public:
        QString other() const;
        void setOther(QString other);
 
-
        bool waitForResult() const;
 
        Command rawCommand() const;
 
-       void setRawReply(ReplyCode replyCode, const QString &reply, Client *client);
-
 private:
        void init();
 
@@ -102,51 +100,22 @@ private:
        QString m_other;
 };
 
-class ANIDBUDPCLIENTSHARED_EXPORT MylistAddCommand : public AbstractCommand
+class ANIDBUDPCLIENTSHARED_EXPORT MyListAddReply : public AbstractReply
 {
        Q_OBJECT
+       REPLY_DEFINITION_HELPER2(MyListAdd)
 
-public:
-       MylistAddCommand(QString file, QObject *parent = 0);
-
-       QString file() const;
-       QByteArray ed2kHash() const;
-       qint64 fileSize() const;
-
-       bool markWatched() const;
-       void setMarkWatched(bool mark);
-
+       Q_PROPERTY(int lid READ lid);
 
-       bool waitForResult() const;
-
-       Command rawCommand() const;
-
-       void setRawReply(ReplyCode replyCode, const QString &reply, Client *client);
-
-       void hash();
-
-signals:
-       void hashComplete();
+public:
+       int lid() const;
 
-private slots:
-       void completeHash();
+       void setRawReply(ReplyCode replyCode, const QString &reply);
 
 private:
-       QByteArray doHash(QString file);
-       QFuture<QByteArray> future;
-       QFutureWatcher<QByteArray> futureWatcher;
-
-       bool m_markWatched;
-
-       qint64 m_size;
-       QByteArray m_ed2k;
-       QString m_file;
-
-       int mylistId;
-
-       static const qint64 ED2K_PART_SIZE = 9728000;
+       void init();
 
-       QTime t;
+       int m_lid;
 };
 
 } // namespace AniDBUdpClient
index 4e1c566561c55bc0df1204fa931a0fcadeca52ac..a37bef14b1d8bf94b316472380c0e9dd2538792c 100644 (file)
-#include "mylistcommand.h"
-
-#include <QStringList>
-
-namespace AniDBUdpClient {
-
-MyListCommand::MyListCommand(QObject *parent) : AbstractCommand(parent)
-{
-       init();
-}
-
-MyListCommand::MyListCommand(int lid, QObject *parent) : AbstractCommand(parent)
-{
-       init();
-       m_lid = lid;
-}
-
-MyListCommand::MyListCommand(int fid, bool isFid, QObject *parent) : AbstractCommand(parent)
-{
-       Q_UNUSED(isFid);
-       init();
-       m_fid = fid;
-}
-
-MyListCommand::MyListCommand(const QByteArray &ed2k, qint64 size, QObject *parent) : AbstractCommand(parent)
-{
-       init();
-       m_ed2k = ed2k;
-       m_size = size;
-}
-
-MyListCommand::MyListCommand(const QString &aname, const QString &gname, int epno, QObject *parent) : AbstractCommand(parent)
-{
-       init();
-       m_aname = aname;
-       m_gname = gname;
-       m_epno = epno;
-}
-
-MyListCommand::MyListCommand(const QString &aname, int gid, int epno, QObject *parent) : AbstractCommand(parent)
-{
-       init();
-       m_aname = aname;
-       m_gid = gid;
-       m_epno = epno;
-}
-
-MyListCommand::MyListCommand(int aid, const QString &gname, int epno, QObject *parent) : AbstractCommand(parent)
-{
-       init();
-       m_aid = aid;
-       m_gname = gname;
-       m_epno = epno;
-}
-
-MyListCommand::MyListCommand(int aid, int gid, int epno, QObject *parent) : AbstractCommand(parent)
-{
-       init();
-       m_aid = aid;
-       m_gid = gid;
-       m_epno = epno;
-}
-
-int MyListCommand::lid() const
-{
-       return m_lid;
-}
-
-void MyListCommand::setLid(int lid)
-{
-       m_lid = lid;
-}
-
-int MyListCommand::fid() const
-{
-       return m_fid;
-}
-
-void MyListCommand::setFid(int fid)
-{
-       m_fid = fid;
-}
-
-QByteArray MyListCommand::ed2k() const
-{
-       return m_ed2k;
-}
-
-void MyListCommand::setEd2k(const QByteArray &ed2k)
-{
-       m_ed2k = ed2k;
-}
-
-qint64 MyListCommand::size() const
-{
-       return m_size;
-}
-
-void MyListCommand::setSize(qint64 size)
-{
-       m_size = size;
-}
-
-QString MyListCommand::aname() const
-{
-       return m_aname;
-}
-
-void MyListCommand::setAname(const QString &aname)
-{
-       m_aname = aname;
-}
-
-int MyListCommand::aid() const
-{
-       return m_aid;
-}
-
-void MyListCommand::setAid(int aid)
-{
-       m_aid = aid;
-}
-
-QString MyListCommand::gname() const
-{
-       return m_gname;
-}
-
-void MyListCommand::setGname(const QString &gname)
-{
-       m_gname = gname;
-}
-
-int MyListCommand::gid() const
-{
-       return m_gid;
-}
-
-void MyListCommand::setGid(int gid)
-{
-       m_gid = gid;
-}
-
-
-int MyListCommand::epno() const
-{
-       return m_epno;
-}
-
-void MyListCommand::setEpno(int epno)
-{
-       m_epno = epno;
-}
-
-bool MyListCommand::isValid() const
-{
-       return m_lid || m_fid || m_aid
-                       || !m_aname.isEmpty()
-                       || (!m_ed2k.isEmpty() && m_size);
-}
-
-int MyListCommand::eid() const
-{
-       return m_eid;
-}
-
-QDateTime MyListCommand::date() const
-{
-       return m_date;
-}
-
-State MyListCommand::state() const
-{
-       return m_state;
-}
-
-QDateTime MyListCommand::viewDate() const
-{
-       return m_viewDate;
-}
-
-QString MyListCommand::storage() const
-{
-       return m_storage;
-}
-
-QString MyListCommand::source() const
-{
-       return m_source;
-}
-
-QString MyListCommand::other() const
-{
-       return m_other;
-}
-
-FileState MyListCommand::fileState() const
-{
-       return m_fileState;
-}
-
-QStringList MyListCommand::multipleEntries() const
-{
-       return m_multipleEntries;
-}
-
-bool MyListCommand::waitForResult() const
-{
-       return true;
-}
-
-Command MyListCommand::rawCommand() const
-{
-       Command cmd;
-
-       cmd.first = "MYLIST";
-
-       if (m_lid)
-       {
-               cmd.second["lid"] = m_lid;
-       }
-       else if (m_fid)
-       {
-               cmd.second["fid"] = m_fid;
-       }
-       else if (!m_ed2k.isEmpty() && m_size)
-       {
-               cmd.second["ed2k"] = m_ed2k;
-               cmd.second["size"] = m_size;
-       }
-       else if (!m_aname.isEmpty())
-       {
-               cmd.second["aname"] = m_aname;
-               if (!m_gname.isEmpty() && m_epno)
-               {
-                       cmd.second["gname"] = m_gname;
-                       cmd.second["epno"] = m_epno;
-               }
-               else if (m_gid && m_epno)
-               {
-                       cmd.second["gid"] = m_gid;
-                       cmd.second["epno"] = m_epno;
-               }
-       }
-       else if (m_aid)
-       {
-               cmd.second["aid"] = m_aid;
-               if (!m_gname.isEmpty() && m_epno)
-               {
-                       cmd.second["gname"] = m_gname;
-                       cmd.second["epno"] = m_epno;
-               }
-               else if (m_gid && m_epno)
-               {
-                       cmd.second["gid"] = m_gid;
-                       cmd.second["epno"] = m_epno;
-               }
-       }
-       else
-       {
-               // TODO WTF NOW?!?
-       }
-       return cmd;
-}
-
-void MyListCommand::setRawReply(ReplyCode replyCode, const QString &reply, Client *client)
-{
-       AbstractCommand::setRawReply(replyCode, reply, client);
-
-       switch (replyCode)
-       {
-               case MYLIST:
-               {
-                       QStringList parts = reply.mid(reply.indexOf("\n")).split('|', QString::KeepEmptyParts);
-                       bool ok;
-                       m_lid = parts[0].toInt(&ok, 10);
-                       m_fid = parts[1].toInt(&ok, 10);
-                       m_eid = parts[2].toInt(&ok, 10);
-                       m_aid = parts[3].toInt(&ok, 10);
-                       m_gid = parts[4].toInt(&ok, 10);
-                       m_date = QDateTime::fromTime_t(parts[5].toUInt(&ok, 10));
-                       m_state = State(parts[6].toInt(&ok, 10));
-                       m_viewDate = QDateTime::fromTime_t(parts[7].toUInt(&ok, 10));
-                       m_storage = parts[8];
-                       m_source = parts[9];
-                       m_other = parts[10];
-                       m_fileState = FileState(parts[11].toInt(&ok, 10));
-                       emit replyReady(true);
-               }
-               break;
-               case MULTIPLE_MYLIST_ENTRIES:
-               {
-                       m_multipleEntries = reply.mid(reply.indexOf("\n")).split('|', QString::KeepEmptyParts);
-                       emit replyReady(true);
-               }
-               break;
-               case NO_SUCH_ENTRY:
-               default:
-                       emit replyReady(false);
-               break;
-       }
-}
-
-void MyListCommand::init()
-{
-       m_lid = 0;
-       m_fid = 0;
-       m_aid = 0;
-       m_gid = 0;
-       m_eid = 0;
-
-       m_size = 0;
-       m_epno = 0;
-
-       m_state = State(0);
-       m_fileState = FileState(0);
-}
-
-} // namespace AniDBUdpClient
+#include "mylistcommand.h"\r
+\r
+#include <QStringList>\r
+\r
+namespace AniDBUdpClient {\r
+\r
+MyListCommand::MyListCommand() : AbstractCommand()\r
+{\r
+       init();\r
+}\r
+\r
+MyListCommand::MyListCommand(int lid) : AbstractCommand()\r
+{\r
+       init();\r
+       m_lid = lid;\r
+}\r
+\r
+MyListCommand::MyListCommand(int fid, bool isFid) : AbstractCommand()\r
+{\r
+       Q_UNUSED(isFid);\r
+       init();\r
+       m_fid = fid;\r
+}\r
+\r
+MyListCommand::MyListCommand(const QByteArray &ed2k, qint64 size) : AbstractCommand()\r
+{\r
+       init();\r
+       m_ed2k = ed2k;\r
+       m_size = size;\r
+}\r
+\r
+MyListCommand::MyListCommand(const QString &aname, const QString &gname, int epno) : AbstractCommand()\r
+{\r
+       init();\r
+       m_aname = aname;\r
+       m_gname = gname;\r
+       m_epno = epno;\r
+}\r
+\r
+MyListCommand::MyListCommand(const QString &aname, int gid, int epno) : AbstractCommand()\r
+{\r
+       init();\r
+       m_aname = aname;\r
+       m_gid = gid;\r
+       m_epno = epno;\r
+}\r
+\r
+MyListCommand::MyListCommand(int aid, const QString &gname, int epno) : AbstractCommand()\r
+{\r
+       init();\r
+       m_aid = aid;\r
+       m_gname = gname;\r
+       m_epno = epno;\r
+}\r
+\r
+MyListCommand::MyListCommand(int aid, int gid, int epno) : AbstractCommand()\r
+{\r
+       init();\r
+       m_aid = aid;\r
+       m_gid = gid;\r
+       m_epno = epno;\r
+}\r
+\r
+int MyListCommand::lid() const\r
+{\r
+       return m_lid;\r
+}\r
+\r
+void MyListCommand::setLid(int lid)\r
+{\r
+       m_lid = lid;\r
+}\r
+\r
+int MyListCommand::fid() const\r
+{\r
+       return m_fid;\r
+}\r
+\r
+void MyListCommand::setFid(int fid)\r
+{\r
+       m_fid = fid;\r
+}\r
+\r
+QByteArray MyListCommand::ed2k() const\r
+{\r
+       return m_ed2k;\r
+}\r
+\r
+void MyListCommand::setEd2k(const QByteArray &ed2k)\r
+{\r
+       m_ed2k = ed2k;\r
+}\r
+\r
+qint64 MyListCommand::size() const\r
+{\r
+       return m_size;\r
+}\r
+\r
+void MyListCommand::setSize(qint64 size)\r
+{\r
+       m_size = size;\r
+}\r
+\r
+QString MyListCommand::aname() const\r
+{\r
+       return m_aname;\r
+}\r
+\r
+void MyListCommand::setAname(const QString &aname)\r
+{\r
+       m_aname = aname;\r
+}\r
+\r
+int MyListCommand::aid() const\r
+{\r
+       return m_aid;\r
+}\r
+\r
+void MyListCommand::setAid(int aid)\r
+{\r
+       m_aid = aid;\r
+}\r
+\r
+QString MyListCommand::gname() const\r
+{\r
+       return m_gname;\r
+}\r
+\r
+void MyListCommand::setGname(const QString &gname)\r
+{\r
+       m_gname = gname;\r
+}\r
+\r
+int MyListCommand::gid() const\r
+{\r
+       return m_gid;\r
+}\r
+\r
+void MyListCommand::setGid(int gid)\r
+{\r
+       m_gid = gid;\r
+}\r
+\r
+\r
+int MyListCommand::epno() const\r
+{\r
+       return m_epno;\r
+}\r
+\r
+void MyListCommand::setEpno(int epno)\r
+{\r
+       m_epno = epno;\r
+}\r
+\r
+bool MyListCommand::isValid() const\r
+{\r
+       return m_lid || m_fid || m_aid\r
+                       || !m_aname.isEmpty()\r
+                       || (!m_ed2k.isEmpty() && m_size);\r
+}\r
+\r
+bool MyListCommand::waitForResult() const\r
+{\r
+       return true;\r
+}\r
+\r
+Command MyListCommand::rawCommand() const\r
+{\r
+       Command cmd;\r
+\r
+       cmd.first = "MYLIST";\r
+\r
+       if (m_lid)\r
+       {\r
+               cmd.second["lid"] = m_lid;\r
+       }\r
+       else if (m_fid)\r
+       {\r
+               cmd.second["fid"] = m_fid;\r
+       }\r
+       else if (!m_ed2k.isEmpty() && m_size)\r
+       {\r
+               cmd.second["ed2k"] = m_ed2k;\r
+               cmd.second["size"] = m_size;\r
+       }\r
+       else if (!m_aname.isEmpty())\r
+       {\r
+               cmd.second["aname"] = m_aname;\r
+               if (!m_gname.isEmpty() && m_epno)\r
+               {\r
+                       cmd.second["gname"] = m_gname;\r
+                       cmd.second["epno"] = m_epno;\r
+               }\r
+               else if (m_gid && m_epno)\r
+               {\r
+                       cmd.second["gid"] = m_gid;\r
+                       cmd.second["epno"] = m_epno;\r
+               }\r
+       }\r
+       else if (m_aid)\r
+       {\r
+               cmd.second["aid"] = m_aid;\r
+               if (!m_gname.isEmpty() && m_epno)\r
+               {\r
+                       cmd.second["gname"] = m_gname;\r
+                       cmd.second["epno"] = m_epno;\r
+               }\r
+               else if (m_gid && m_epno)\r
+               {\r
+                       cmd.second["gid"] = m_gid;\r
+                       cmd.second["epno"] = m_epno;\r
+               }\r
+       }\r
+       else\r
+       {\r
+               // TODO WTF NOW?!?\r
+       }\r
+       return cmd;\r
+}\r
+\r
+void MyListCommand::init()\r
+{\r
+       m_lid = 0;\r
+       m_fid = 0;\r
+       m_aid = 0;\r
+       m_gid = 0;\r
+\r
+       m_size = 0;\r
+       m_epno = 0;\r
+}\r
+\r
+\r
+// ===\r
+\r
+int MyListReply::lid() const\r
+{\r
+       return m_lid;\r
+}\r
+\r
+int MyListReply::fid() const\r
+{\r
+       return m_fid;\r
+}\r
+\r
+int MyListReply::aid() const\r
+{\r
+       return m_aid;\r
+}\r
+\r
+\r
+int MyListReply::gid() const\r
+{\r
+       return m_gid;\r
+}\r
+\r
+\r
+int MyListReply::eid() const\r
+{\r
+       return m_eid;\r
+}\r
+\r
+QDateTime MyListReply::date() const\r
+{\r
+       return m_date;\r
+}\r
+\r
+State MyListReply::state() const\r
+{\r
+       return m_state;\r
+}\r
+\r
+QDateTime MyListReply::viewDate() const\r
+{\r
+       return m_viewDate;\r
+}\r
+\r
+QString MyListReply::storage() const\r
+{\r
+       return m_storage;\r
+}\r
+\r
+QString MyListReply::source() const\r
+{\r
+       return m_source;\r
+}\r
+\r
+QString MyListReply::other() const\r
+{\r
+       return m_other;\r
+}\r
+\r
+FileState MyListReply::fileState() const\r
+{\r
+       return m_fileState;\r
+}\r
+\r
+QStringList MyListReply::multipleEntries() const\r
+{\r
+       return m_multipleEntries;\r
+}\r
+\r
+void MyListReply::setRawReply(ReplyCode replyCode, const QString &reply)\r
+{\r
+       AbstractReply::setRawReply(replyCode, reply);\r
+\r
+       switch (replyCode)\r
+       {\r
+               case MYLIST:\r
+               {\r
+                       QStringList parts = reply.mid(reply.indexOf("\n")).split('|', QString::KeepEmptyParts);\r
+                       bool ok;\r
+                       m_lid = parts[0].toInt(&ok, 10);\r
+                       m_fid = parts[1].toInt(&ok, 10);\r
+                       m_eid = parts[2].toInt(&ok, 10);\r
+                       m_aid = parts[3].toInt(&ok, 10);\r
+                       m_gid = parts[4].toInt(&ok, 10);\r
+                       m_date = QDateTime::fromTime_t(parts[5].toUInt(&ok, 10));\r
+                       m_state = State(parts[6].toInt(&ok, 10));\r
+                       m_viewDate = QDateTime::fromTime_t(parts[7].toUInt(&ok, 10));\r
+                       m_storage = parts[8];\r
+                       m_source = parts[9];\r
+                       m_other = parts[10];\r
+                       m_fileState = FileState(parts[11].toInt(&ok, 10));\r
+                       emit replyReady(true);\r
+               }\r
+               break;\r
+               case MULTIPLE_MYLIST_ENTRIES:\r
+               {\r
+                       m_multipleEntries = reply.mid(reply.indexOf("\n")).split('|', QString::KeepEmptyParts);\r
+                       emit replyReady(true);\r
+               }\r
+               break;\r
+               case NO_SUCH_ENTRY:\r
+               default:\r
+                       emit replyReady(false);\r
+               break;\r
+       }\r
+}\r
+\r
+void MyListReply::init()\r
+{\r
+       m_lid = 0;\r
+       m_fid = 0;\r
+       m_aid = 0;\r
+       m_gid = 0;\r
+       m_eid = 0;\r
+\r
+       m_state = State(0);\r
+       m_fileState = FileState(0);\r
+}\r
+\r
+} // namespace AniDBUdpClient\r
index 7d8487e7d7df362def49f62e53d585d4f64d665e..336b1bf6c35a7adc73103247412bcc95adf9f17e 100644 (file)
-#ifndef MYLISTCOMMAND_H
-#define MYLISTCOMMAND_H
-
-#include "anidbudpclient_global.h"
-#include "abstractcommand.h"
-
-#include <QDateTime>
-#include <QStringList>
-
-namespace AniDBUdpClient {
-
-class ANIDBUDPCLIENTSHARED_EXPORT MyListCommand : public AbstractCommand
-{
-       Q_OBJECT
-       
-       Q_PROPERTY(int lid READ lid WRITE setLid);
-       Q_PROPERTY(int fid READ fid WRITE setFid);
-       
-       Q_PROPERTY(QByteArray ed2k READ ed2k WRITE setEd2k);
-       Q_PROPERTY(qint64 size READ size WRITE setSize);
-
-       Q_PROPERTY(QString aname READ aname WRITE setAname);
-       Q_PROPERTY(int aid READ aid WRITE setAid);
-       Q_PROPERTY(QString gname READ gname WRITE setGname);
-       Q_PROPERTY(int gid READ gid WRITE setGid);
-       Q_PROPERTY(int epno READ epno WRITE setEpno);
-
-       Q_PROPERTY(bool valid READ isValid);
-
-       Q_PROPERTY(int eid READ eid);
-       Q_PROPERTY(QDateTime date READ date);
-       Q_PROPERTY(State state READ state);
-       Q_PROPERTY(QDateTime viewDate READ viewDate);
-       Q_PROPERTY(QString storage READ storage);
-       Q_PROPERTY(QString source READ source);
-       Q_PROPERTY(QString other READ other);
-       Q_PROPERTY(FileState fileState READ fileState);
-
-       Q_PROPERTY(QStringList multipleEntries READ multipleEntries);
-
-public:
-       MyListCommand(QObject *parent = 0);
-       MyListCommand(int lid, QObject *parent = 0);
-       MyListCommand(int fid, bool isFid, QObject *parent = 0);
-       MyListCommand(const QByteArray &ed2k, qint64 size, QObject *parent = 0);
-       MyListCommand(const QString &aname, const QString &gname, int epno, QObject *parent = 0);
-       MyListCommand(const QString &aname, int gid, int epno, QObject *parent = 0);
-       MyListCommand(int aid, const QString &gname, int epno, QObject *parent = 0);
-       MyListCommand(int aid, int gid, int epno, QObject *parent = 0);
-
-       int lid() const;
-       void setLid(int lid);
-       int fid() const;
-       void setFid(int fid);
-
-       QByteArray ed2k() const;
-       void setEd2k(const QByteArray &ed2k);
-       qint64 size() const;
-       void setSize(qint64 size);
-
-       QString aname() const;
-       void setAname(const QString &aname);
-       int aid() const;
-       void setAid(int aid);
-       QString gname() const;
-       void setGname(const QString &gname);
-       int gid() const;
-       void setGid(int gid);
-       int epno() const;
-       void setEpno(int epno);
-
-       bool isValid() const;
-
-
-       int eid() const;
-       QDateTime date() const;
-       State state() const;
-       QDateTime viewDate() const;
-       QString storage() const;
-       QString source() const;
-       QString other() const;
-       FileState fileState() const;
-
-       QStringList multipleEntries() const;
-
-       bool waitForResult() const;
-       Command rawCommand() const;
-       void setRawReply(ReplyCode replyCode, const QString &reply, Client *client);
-
-private:
-       void init();
-
-       int m_lid;
-       int m_fid;
-
-       QByteArray m_ed2k;
-       qint64 m_size;
-
-       QString m_aname;
-       int m_aid;
-       QString m_gname;
-       int m_gid;
-       int m_epno;
-
-       int m_eid;
-       QDateTime m_date;
-       State m_state;
-       QDateTime m_viewDate;
-       QString m_storage;
-       QString m_source;
-       QString m_other;
-       FileState m_fileState;
-
-       QStringList m_multipleEntries;
-
-};
-
-} // namespace AniDBUdpClient
-
-#include <QScriptEngine>
-Q_SCRIPT_DECLARE_QMETAOBJECT(AniDBUdpClient::MyListCommand, QObject*);
-
-#endif // MYLISTCOMMAND_H
+#ifndef MYLISTCOMMAND_H\r
+#define MYLISTCOMMAND_H\r
+\r
+#include "anidbudpclient_global.h"\r
+#include "abstractcommand.h"\r
+\r
+#include <QDateTime>\r
+#include <QStringList>\r
+\r
+namespace AniDBUdpClient {\r
+\r
+class MyListReply;\r
+\r
+class ANIDBUDPCLIENTSHARED_EXPORT MyListCommand : public AbstractCommand\r
+{\r
+public:\r
+       typedef MyListReply ReplyType;\r
+       MyListCommand();\r
+       MyListCommand(int lid);\r
+       MyListCommand(int fid, bool isFid);\r
+       MyListCommand(const QByteArray &ed2k, qint64 size);\r
+       MyListCommand(const QString &aname, const QString &gname, int epno);\r
+       MyListCommand(const QString &aname, int gid, int epno);\r
+       MyListCommand(int aid, const QString &gname, int epno);\r
+       MyListCommand(int aid, int gid, int epno);\r
+\r
+       int lid() const;\r
+       void setLid(int lid);\r
+       int fid() const;\r
+       void setFid(int fid);\r
+\r
+       QByteArray ed2k() const;\r
+       void setEd2k(const QByteArray &ed2k);\r
+       qint64 size() const;\r
+       void setSize(qint64 size);\r
+\r
+       QString aname() const;\r
+       void setAname(const QString &aname);\r
+       int aid() const;\r
+       void setAid(int aid);\r
+       QString gname() const;\r
+       void setGname(const QString &gname);\r
+       int gid() const;\r
+       void setGid(int gid);\r
+       int epno() const;\r
+       void setEpno(int epno);\r
+\r
+       bool isValid() const;\r
+\r
+       bool waitForResult() const;\r
+       Command rawCommand() const;\r
+       void setRawReply(ReplyCode replyCode, const QString &reply, Client *client);\r
+\r
+private:\r
+       void init();\r
+\r
+       int m_lid;\r
+       int m_fid;\r
+\r
+       QByteArray m_ed2k;\r
+       qint64 m_size;\r
+\r
+       QString m_aname;\r
+       int m_aid;\r
+       QString m_gname;\r
+       int m_gid;\r
+       int m_epno;\r
+\r
+};\r
+\r
+class ANIDBUDPCLIENTSHARED_EXPORT MyListReply : public AbstractReply\r
+{\r
+       Q_OBJECT\r
+       REPLY_DEFINITION_HELPER2(MyList)\r
+\r
+       Q_PROPERTY(int lid READ lid);\r
+       Q_PROPERTY(int fid READ fid);\r
+\r
+       Q_PROPERTY(int aid READ aid);\r
+       Q_PROPERTY(int gid READ gid);\r
+\r
+       Q_PROPERTY(int eid READ eid);\r
+       Q_PROPERTY(QDateTime date READ date);\r
+       Q_PROPERTY(State state READ state);\r
+       Q_PROPERTY(QDateTime viewDate READ viewDate);\r
+       Q_PROPERTY(QString storage READ storage);\r
+       Q_PROPERTY(QString source READ source);\r
+       Q_PROPERTY(QString other READ other);\r
+       Q_PROPERTY(FileState fileState READ fileState);\r
+\r
+       Q_PROPERTY(QStringList multipleEntries READ multipleEntries);\r
+\r
+public:\r
+\r
+       int lid() const;\r
+       int fid() const;\r
+\r
+       int aid() const;\r
+       int gid() const;\r
+\r
+\r
+       int eid() const;\r
+       QDateTime date() const;\r
+       State state() const;\r
+       QDateTime viewDate() const;\r
+       QString storage() const;\r
+       QString source() const;\r
+       QString other() const;\r
+       FileState fileState() const;\r
+\r
+       QStringList multipleEntries() const;\r
+\r
+       void setRawReply(ReplyCode replyCode, const QString &reply);\r
+\r
+private:\r
+       void init();\r
+\r
+       int m_lid;\r
+       int m_fid;\r
+\r
+       int m_aid;\r
+       int m_gid;\r
+       int m_epno;\r
+\r
+       int m_eid;\r
+       QDateTime m_date;\r
+       State m_state;\r
+       QDateTime m_viewDate;\r
+       QString m_storage;\r
+       QString m_source;\r
+       QString m_other;\r
+       FileState m_fileState;\r
+\r
+       QStringList m_multipleEntries;\r
+\r
+};\r
+\r
+} // namespace AniDBUdpClient\r
+\r
+#endif // MYLISTCOMMAND_H\r
index 982ac878d934806e24499fb53ecd4384253b658b..50f7660fb6414ec4b868fad4f08ad7be13b92760 100644 (file)
@@ -2,7 +2,7 @@
 
 namespace AniDBUdpClient {
 
-RawCommand::RawCommand(const QString &command, QObject *parent) : AbstractCommand(parent)
+RawCommand::RawCommand(const QString &command) : AbstractCommand()
 {
        m_command = command;
 }
index fb18ab469d56dc913854d3906e28d159c3aa0307..0795cc56030b5e6e9958b3c76752a7d1ea53116f 100644 (file)
@@ -5,12 +5,13 @@
 
 namespace AniDBUdpClient {
 
+class RawReply;
+
 class ANIDBUDPCLIENTSHARED_EXPORT RawCommand : public AbstractCommand
 {
-       Q_OBJECT
-
 public:
-       RawCommand(const QString &command, QObject *parent = 0);
+       typedef RawReply ReplyType;
+       RawCommand(const QString &command);
 
        Command rawCommand() const;
 
@@ -18,6 +19,13 @@ private:
        QString m_command;
 };
 
+class ANIDBUDPCLIENTSHARED_EXPORT RawReply : public AbstractReply
+{
+       Q_OBJECT
+       REPLY_DEFINITION_HELPER(Raw)
+public:
+};
+
 } // namespace AniDBUdpClient
 
 #endif // RAWCOMMAND_H
index 503a7a3cbc6efd3ecd1fb60a429f09d3f0e9a4ab..b4c05f6e00c41e6cf5f69665b98ded5ae3a8f34c 100644 (file)
@@ -2,14 +2,8 @@
 
 namespace AniDBUdpClient {
 
-UptimeCommand::UptimeCommand(QObject *parent) : AbstractCommand(parent)
+UptimeCommand::UptimeCommand() : AbstractCommand()
 {
-       m_uptime = 0;
-}
-
-int UptimeCommand::uptime()
-{
-       return m_uptime;
 }
 
 Command UptimeCommand::rawCommand() const
@@ -19,7 +13,14 @@ Command UptimeCommand::rawCommand() const
        return command;
 }
 
-void UptimeCommand::setRawReply(ReplyCode replyCode, const QString &reply, Client *client)
+// ==
+
+int UptimeReply::uptime()
+{
+       return m_uptime;
+}
+
+void UptimeReply::setRawReply(ReplyCode replyCode, const QString &reply, Client *client)
 {
        Q_UNUSED(client);
 
@@ -42,4 +43,9 @@ void UptimeCommand::setRawReply(ReplyCode replyCode, const QString &reply, Clien
        }
 }
 
+void UptimeReply::init()
+{
+       m_uptime = 0;
+}
+
 } // namespace AniDBUdpClient
index b71b88f6bbdca748bea6e5e0c267545296703d9f..7b3aaa2cbd8b560919cac8dafaee0744a5563385 100644 (file)
@@ -5,26 +5,35 @@
 
 namespace AniDBUdpClient {
 
+class UptimeReply;
+
 class ANIDBUDPCLIENTSHARED_EXPORT UptimeCommand : public AbstractCommand
+{
+public:
+       typedef UptimeReply ReplyType;
+       UptimeCommand();
+
+       Command rawCommand() const;
+};
+
+class ANIDBUDPCLIENTSHARED_EXPORT UptimeReply : public AbstractReply
 {
        Q_OBJECT
+       REPLY_DEFINITION_HELPER2(Uptime)
 
        Q_PROPERTY(int uptime READ uptime);
 public:
-       UptimeCommand(QObject *parent = 0);
 
        int uptime();
 
-       Command rawCommand() const;
        void setRawReply(ReplyCode replyCode, const QString &reply, Client *client);
 
 private:
+       void init();
        int m_uptime;
 };
 
-} // namespace AniDBUdpClient
 
-#include <QScriptEngine>
-Q_SCRIPT_DECLARE_QMETAOBJECT(AniDBUdpClient::UptimeCommand, QObject*);
+} // namespace AniDBUdpClient
 
 #endif // UPTIMECOMMAND_H
index cb8276a6dfe03007bb0061c63ef87e1092bde0fc..2945a546324ac584b2e5247ab98f4abd47a08618 100644 (file)
@@ -49,7 +49,7 @@ VideoWindow::VideoWindow(QWidget *parent) : QMainWindow(parent)
 
 #ifndef NO_ANIDBUDPCLIENT
        anidb = AniDBUdpClient::Client::instance();
-       addCommand = 0;
+       addReply = 0;
        m_marked = true;
        m_automark = 0;
 #endif
@@ -403,10 +403,11 @@ qDebug() << "Media changed state from" << oldstate << "to" << newstate;
                                resizeToVideo();
 #endif
 #ifndef NO_ANIDBUDPCLIENT
-                       if (!m_marked)
-                               addCommand->deleteLater();
+/*                     if (!m_marked)
+                               addReply->deleteLater();
 
-                       addCommand = new AniDBUdpClient::MylistAddCommand(videoPlayer->currentFile(), this);
+                       addReply = new AniDBUdpClient::MylistAddCommand(videoPlayer->currentFile(), this);
+*/
                        m_marked = false;
 #endif
                        break;
@@ -537,44 +538,46 @@ void VideoWindow::moveWithMenu()
 #ifndef NO_ANIDBUDPCLIENT
 void VideoWindow::markWatched()
 {
-       if (!addCommand)
+       if (addReply != 0)
        {
                menu->showMessage("File already Marked");
                return;
        }
        menu->showMessage("Hashing file");
+       AniDBUdpClient::HashRequest hashRequest(videoPlayer->currentFile());
 
-       connect(addCommand, SIGNAL(hashComplete()), this, SLOT(doMarkWatched()));
-       addCommand->setMarkWatched(true);
-qDebug() << "hashing file...";
-       addCommand->hash();
-       addCommand = 0;
+       AniDBUdpClient::HashResult *hashResult = AniDBUdpClient::Hash::instance()->hashFile(hashRequest);
+       qDebug() << "hashing file...";
+       connect(hashResult, SIGNAL(resultReady()), this, SLOT(doMarkWatched()));
 }
 
 void VideoWindow::doMarkWatched()
 {
-       AniDBUdpClient::MylistAddCommand *cmd = qobject_cast<AniDBUdpClient::MylistAddCommand *>(sender());
-       if (!cmd)
+       AniDBUdpClient::HashResult *hashResult = qobject_cast<AniDBUdpClient::HashResult *>(sender());
+       if (!hashResult)
                return;
+       AniDBUdpClient::MyListAddCommand addCommand(hashResult->hash(), QFileInfo(videoPlayer->currentFile()).size(), false);
+       AniDBUdpClient::MyListAddReply *addReply = anidb->send(addCommand);
+       connect(addReply, SIGNAL(replyReady(bool)), this, SLOT(showMarkResult(bool)));
+       connect(addReply, SIGNAL(replyReady(bool)), this, SLOT(deleteLater()));
 
-       connect(cmd, SIGNAL(replyReady(bool)), this, SLOT(showMarkResult(bool)));
-       anidb->send(cmd);
-       menu->showMessage(tr("Marking file %1").arg(cmd->file()));
+       menu->showMessage(tr("Marking file %1").arg(hashResult->fileInfo().fileName()));
+       hashResult->deleteLater();
 }
 
 void VideoWindow::showMarkResult(bool success)
 {
-       AniDBUdpClient::MylistAddCommand *cmd = qobject_cast<AniDBUdpClient::MylistAddCommand *>(sender());
+       AniDBUdpClient::MyListAddReply *cmd = qobject_cast<AniDBUdpClient::MyListAddReply *>(sender());
        if (!cmd)
                return;
 
        if (success)
        {
-               menu->showMessage(tr("File %1 marked watched").arg(cmd->file()));
+               menu->showMessage(tr("File marked watched"));
        }
        else
        {
-               menu->showMessage(tr("Failed to mark file %1").arg(cmd->file()));
+               menu->showMessage(tr("Failed to mark file"));
        }
        cmd->deleteLater();
 }
index f835645579613d7ece93d232d4e88ac559e960bf..7fa0052275d64ec53626dbf3985a2c66c7e4e6da 100644 (file)
@@ -37,7 +37,7 @@ class DirectoryPlaylist;
 #ifndef NO_ANIDBUDPCLIENT
 namespace AniDBUdpClient {
        class Client;
-       class MylistAddCommand;
+       class MyListAddReply;
 }
 #endif
 
@@ -156,7 +156,7 @@ private:
        bool m_marked;
        bool m_automarkable;
        AniDBUdpClient::Client *anidb;
-       AniDBUdpClient::MylistAddCommand *addCommand;
+       AniDBUdpClient::MyListAddReply *addReply;
 #endif
 
        DirectoryPlaylist *playlist;