]> Some of my projects - anidbudpclient.git/commitdiff
Add VoteCommand. It's not tested yet.
authorAPTX <marek321@gmail.com>
Sun, 10 Oct 2010 15:16:34 +0000 (17:16 +0200)
committerAPTX <marek321@gmail.com>
Sun, 10 Oct 2010 15:16:34 +0000 (17:16 +0200)
anidbudpclient.pro
include/AniDBUdpClient/VoteCommand [new file with mode: 0644]
votecommand.cpp [new file with mode: 0644]
votecommand.h [new file with mode: 0644]

index de9edaf4157759c30518f6d84392fcaa730d9767..eabee97cce7270052230e15a529e5e3cf6a5713f 100644 (file)
@@ -26,6 +26,7 @@ SOURCES += client.cpp \
     uptimecommand.cpp \
        mylistcommand.cpp \
        filecommand.cpp \
+       votecommand.cpp \
        file.cpp \
     hash.cpp \
     hashproducer.cpp \
@@ -41,6 +42,7 @@ HEADERS += client.h \
     uptimecommand.h \
        mylistcommand.h \
        filecommand.h \
+       votecommand.h \
        file.h \
     hash.h \
     hashproducer.h \
@@ -53,7 +55,7 @@ CONV_HEADERS += include/AniDBUdpClient/Client \
     include/AniDBUdpClient/MyListCommand \
     include/AniDBUdpClient/MyListAddCommand \
        include/AniDBUdpClient/FileCommand \
-       include/AniDBUdpClient/File \
+       include/AniDBUdpClient/VoteCommand \
        include/AniDBUdpClient/UptimeCommand \
-       include/AniDBUdpClient/Hash \
-    include/AniDBUdpClient/UptimeCommand \
+       include/AniDBUdpClient/File \
+       include/AniDBUdpClient/Hash
diff --git a/include/AniDBUdpClient/VoteCommand b/include/AniDBUdpClient/VoteCommand
new file mode 100644 (file)
index 0000000..019b431
--- /dev/null
@@ -0,0 +1 @@
+#include "../../votecommand.h"
\ No newline at end of file
diff --git a/votecommand.cpp b/votecommand.cpp
new file mode 100644 (file)
index 0000000..1bb28c6
--- /dev/null
@@ -0,0 +1,156 @@
+#include "votecommand.h"\r
+\r
+namespace AniDBUdpClient {\r
+\r
+VoteCommand::VoteCommand()\r
+{\r
+       init();\r
+}\r
+\r
+VoteCommand::VoteCommand(VoteType voteType, int id, int value, int epno)\r
+{\r
+       init();\r
+       m_voteType = voteType;\r
+       m_id = id;\r
+       m_value = value;\r
+       m_epno = epno;\r
+}\r
+\r
+VoteCommand::VoteCommand(VoteType voteType, const QString &name, int value, int epno)\r
+{\r
+       init();\r
+       m_voteType = voteType;\r
+       m_name = name;\r
+       m_value = value;\r
+       m_epno = epno;\r
+}\r
+\r
+VoteCommand::VoteType VoteCommand::voteType() const\r
+{\r
+       return m_voteType;\r
+}\r
+\r
+void VoteCommand::setVoteType(VoteType voteType)\r
+{\r
+       m_voteType = voteType;\r
+}\r
+\r
+\r
+int VoteCommand::value() const\r
+{\r
+       return m_value;\r
+}\r
+\r
+void VoteCommand::setValue(int value)\r
+{\r
+       m_value = value;\r
+}\r
+\r
+\r
+int VoteCommand::id() const\r
+{\r
+       return m_id;\r
+}\r
+\r
+void VoteCommand::setId(int id)\r
+{\r
+       m_id = id;\r
+}\r
+\r
+\r
+QString VoteCommand::name() const\r
+{\r
+       return m_name;\r
+}\r
+\r
+void VoteCommand::setName(const QString &name)\r
+{\r
+       m_name = name;\r
+}\r
+\r
+\r
+int VoteCommand::epno() const\r
+{\r
+       return m_epno;\r
+}\r
+\r
+void VoteCommand::setEpno(int epno)\r
+{\r
+       m_epno = epno;\r
+}\r
+\r
+\r
+bool VoteCommand::waitForResult() const\r
+{\r
+       return true;\r
+}\r
+\r
+Command VoteCommand::rawCommand() const\r
+{\r
+       Command cmd;\r
+\r
+       cmd.first = "VOTE";\r
+\r
+       cmd.second["type"] = m_voteType;\r
+\r
+       if (m_id != 0)\r
+               cmd.second["id"] = m_id;\r
+       else if (!m_name.isEmpty())\r
+               cmd.second["name"] = m_name;\r
+       else\r
+               cmd.second["id"] = 0;\r
+\r
+       int value = (m_value > 0 && m_value < 100)\r
+                               || m_value > 1000 ? 0 : m_value;\r
+\r
+       cmd.second["value"] = value;\r
+\r
+       if (m_epno != 0)\r
+               cmd.second["epno"] = m_epno;\r
+\r
+       return cmd;\r
+}\r
+\r
+void VoteCommand::init()\r
+{\r
+       m_voteType = AnimeVote;\r
+       m_id = 0;\r
+       m_value = 0;\r
+       m_epno = 0;\r
+}\r
+\r
+// ===\r
+\r
+QString VoteReply::entityName() const\r
+{\r
+       return m_entityName;\r
+}\r
+\r
+int VoteReply::value() const\r
+{\r
+       return m_value;\r
+}\r
+\r
+AniDBUdpClient::VoteCommand::VoteType VoteReply::voteType() const\r
+{\r
+       return m_voteType;\r
+}\r
+\r
+int VoteReply::entityId() const\r
+{\r
+       return m_entityId;\r
+}\r
+\r
+void VoteReply::setRawReply(ReplyCode replyCode, const QString &reply)\r
+{\r
+       AbstractReply::setRawReply(replyCode, reply);\r
+}\r
+\r
+void VoteReply::init()\r
+{\r
+       m_value = 0;\r
+       m_voteType = VoteCommand::AnimeVote;\r
+       m_entityId = 0;\r
+}\r
+\r
+} // namespace AniDBUdpClient\r
diff --git a/votecommand.h b/votecommand.h
new file mode 100644 (file)
index 0000000..f115382
--- /dev/null
@@ -0,0 +1,88 @@
+#ifndef VOTECOMMAND_H\r
+#define VOTECOMMAND_H\r
+\r
+#include "abstractcommand.h"\r
+\r
+namespace AniDBUdpClient {\r
+\r
+class VoteReply;\r
+\r
+class ANIDBUDPCLIENTSHARED_EXPORT VoteCommand : public AbstractCommand\r
+{\r
+\r
+public:\r
+\r
+       enum VoteType\r
+       {\r
+               AnimeVote               = 1,\r
+               AnimeTempVote   = 2,\r
+               GroupVote               = 3,\r
+       };\r
+\r
+       typedef VoteReply ReplyType;\r
+\r
+       VoteCommand();\r
+       VoteCommand(VoteType type, int id, int value, int epno = 0);\r
+       VoteCommand(VoteType type, const QString &name, int value, int epno = 0);\r
+\r
+       VoteType voteType() const;\r
+       void setVoteType(VoteType voteType);\r
+\r
+       int value() const;\r
+       void setValue(int value);\r
+\r
+       int id() const;\r
+       void setId(int id);\r
+\r
+       QString name() const;\r
+       void setName(const QString &name);\r
+\r
+       int epno() const;\r
+       void setEpno(int epno);\r
+\r
+       bool waitForResult() const;\r
+       Command rawCommand() const;\r
+\r
+private:\r
+       void init();\r
+\r
+       VoteType m_voteType;\r
+       int m_value;\r
+\r
+       int m_id;\r
+       QString m_name;\r
+       int m_epno;\r
+};\r
+\r
+class ANIDBUDPCLIENTSHARED_EXPORT VoteReply : public AbstractReply\r
+{\r
+       Q_OBJECT\r
+       REPLY_DEFINITION_HELPER2(Vote)\r
+\r
+       Q_PROPERTY(QString entityName READ entityName);\r
+       Q_PROPERTY(int value READ value);\r
+//     Q_PROPERTY(AniDBUdpClient::VoteCommand::VoteType voteType READ voteType);\r
+       Q_PROPERTY(int entityId READ entityId);\r
+\r
+public:\r
+       QString entityName() const;\r
+       int value() const;\r
+       AniDBUdpClient::VoteCommand::VoteType voteType() const;\r
+       int entityId() const;\r
+\r
+       void setRawReply(ReplyCode replyCode, const QString &reply);\r
+\r
+private:\r
+       void init();\r
+\r
+       QString m_entityName;\r
+       int m_value;\r
+       VoteCommand::VoteType m_voteType;\r
+       int m_entityId;\r
+\r
+};\r
+\r
+\r
+} // namespace AniDBUdpClient\r
+\r
+#endif // VOTECOMMAND_H\r