From: APTX Date: Sun, 10 Oct 2010 15:16:34 +0000 (+0200) Subject: Add VoteCommand. It's not tested yet. X-Git-Url: https://gitweb.aptx.org/?a=commitdiff_plain;h=7cd2330f77835dd5bd29229147e9eb394eea6e80;p=anidbudpclient.git Add VoteCommand. It's not tested yet. --- diff --git a/anidbudpclient.pro b/anidbudpclient.pro index de9edaf..eabee97 100644 --- a/anidbudpclient.pro +++ b/anidbudpclient.pro @@ -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 index 0000000..019b431 --- /dev/null +++ b/include/AniDBUdpClient/VoteCommand @@ -0,0 +1 @@ +#include "../../votecommand.h" \ No newline at end of file diff --git a/votecommand.cpp b/votecommand.cpp new file mode 100644 index 0000000..1bb28c6 --- /dev/null +++ b/votecommand.cpp @@ -0,0 +1,156 @@ +#include "votecommand.h" + +namespace AniDBUdpClient { + +VoteCommand::VoteCommand() +{ + init(); +} + +VoteCommand::VoteCommand(VoteType voteType, int id, int value, int epno) +{ + init(); + m_voteType = voteType; + m_id = id; + m_value = value; + m_epno = epno; +} + +VoteCommand::VoteCommand(VoteType voteType, const QString &name, int value, int epno) +{ + init(); + m_voteType = voteType; + m_name = name; + m_value = value; + m_epno = epno; +} + +VoteCommand::VoteType VoteCommand::voteType() const +{ + return m_voteType; +} + +void VoteCommand::setVoteType(VoteType voteType) +{ + m_voteType = voteType; +} + + +int VoteCommand::value() const +{ + return m_value; +} + +void VoteCommand::setValue(int value) +{ + m_value = value; +} + + +int VoteCommand::id() const +{ + return m_id; +} + +void VoteCommand::setId(int id) +{ + m_id = id; +} + + +QString VoteCommand::name() const +{ + return m_name; +} + +void VoteCommand::setName(const QString &name) +{ + m_name = name; +} + + +int VoteCommand::epno() const +{ + return m_epno; +} + +void VoteCommand::setEpno(int epno) +{ + m_epno = epno; +} + + +bool VoteCommand::waitForResult() const +{ + return true; +} + +Command VoteCommand::rawCommand() const +{ + Command cmd; + + cmd.first = "VOTE"; + + cmd.second["type"] = m_voteType; + + if (m_id != 0) + cmd.second["id"] = m_id; + else if (!m_name.isEmpty()) + cmd.second["name"] = m_name; + else + cmd.second["id"] = 0; + + int value = (m_value > 0 && m_value < 100) + || m_value > 1000 ? 0 : m_value; + + cmd.second["value"] = value; + + if (m_epno != 0) + cmd.second["epno"] = m_epno; + + return cmd; +} + +void VoteCommand::init() +{ + m_voteType = AnimeVote; + m_id = 0; + m_value = 0; + m_epno = 0; +} + +// === + +QString VoteReply::entityName() const +{ + return m_entityName; +} + +int VoteReply::value() const +{ + return m_value; +} + +AniDBUdpClient::VoteCommand::VoteType VoteReply::voteType() const +{ + return m_voteType; +} + +int VoteReply::entityId() const +{ + return m_entityId; +} + +void VoteReply::setRawReply(ReplyCode replyCode, const QString &reply) +{ + AbstractReply::setRawReply(replyCode, reply); +} + +void VoteReply::init() +{ + m_value = 0; + m_voteType = VoteCommand::AnimeVote; + m_entityId = 0; +} + +} // namespace AniDBUdpClient diff --git a/votecommand.h b/votecommand.h new file mode 100644 index 0000000..f115382 --- /dev/null +++ b/votecommand.h @@ -0,0 +1,88 @@ +#ifndef VOTECOMMAND_H +#define VOTECOMMAND_H + +#include "abstractcommand.h" + +namespace AniDBUdpClient { + +class VoteReply; + +class ANIDBUDPCLIENTSHARED_EXPORT VoteCommand : public AbstractCommand +{ + +public: + + enum VoteType + { + AnimeVote = 1, + AnimeTempVote = 2, + GroupVote = 3, + }; + + typedef VoteReply ReplyType; + + VoteCommand(); + VoteCommand(VoteType type, int id, int value, int epno = 0); + VoteCommand(VoteType type, const QString &name, int value, int epno = 0); + + VoteType voteType() const; + void setVoteType(VoteType voteType); + + int value() const; + void setValue(int value); + + int id() const; + void setId(int id); + + QString name() const; + void setName(const QString &name); + + int epno() const; + void setEpno(int epno); + + bool waitForResult() const; + Command rawCommand() const; + +private: + void init(); + + VoteType m_voteType; + int m_value; + + int m_id; + QString m_name; + int m_epno; +}; + +class ANIDBUDPCLIENTSHARED_EXPORT VoteReply : public AbstractReply +{ + Q_OBJECT + REPLY_DEFINITION_HELPER2(Vote) + + Q_PROPERTY(QString entityName READ entityName); + Q_PROPERTY(int value READ value); +// Q_PROPERTY(AniDBUdpClient::VoteCommand::VoteType voteType READ voteType); + Q_PROPERTY(int entityId READ entityId); + +public: + QString entityName() const; + int value() const; + AniDBUdpClient::VoteCommand::VoteType voteType() const; + int entityId() const; + + void setRawReply(ReplyCode replyCode, const QString &reply); + +private: + void init(); + + QString m_entityName; + int m_value; + VoteCommand::VoteType m_voteType; + int m_entityId; + +}; + + +} // namespace AniDBUdpClient + +#endif // VOTECOMMAND_H