From c1dce8abb01c3e0e1e41b71a2ece929218d70630 Mon Sep 17 00:00:00 2001 From: APTX Date: Tue, 28 Feb 2012 21:47:03 +0100 Subject: [PATCH] Add EPISODE command. --- anidbudpclient.pro | 6 +- episodecommand.cpp | 203 +++++++++++++++++++++++++++++++++++++++++++++ episodecommand.h | 100 ++++++++++++++++++++++ 3 files changed, 307 insertions(+), 2 deletions(-) create mode 100644 episodecommand.cpp create mode 100644 episodecommand.h diff --git a/anidbudpclient.pro b/anidbudpclient.pro index e53759c..de82abf 100644 --- a/anidbudpclient.pro +++ b/anidbudpclient.pro @@ -39,7 +39,8 @@ SOURCES += client.cpp \ clientqueuedcommandsmodel.cpp \ filerenamedelegate.cpp \ clientinterface.cpp \ - myliststate.cpp + myliststate.cpp \ + episodecommand.cpp HEADERS += client.h \ anidbudpclient_global.h \ @@ -63,7 +64,8 @@ HEADERS += client.h \ clientqueuedcommandsmodel.h \ filerenamedelegate.h \ clientinterface.h \ - myliststate.h + myliststate.h \ + episodecommand.h CONV_HEADERS += include/AniDBUdpClient/Client \ include/AniDBUdpClient/AbstractCommand \ diff --git a/episodecommand.cpp b/episodecommand.cpp new file mode 100644 index 0000000..025db69 --- /dev/null +++ b/episodecommand.cpp @@ -0,0 +1,203 @@ +#include "episodecommand.h" + +#include + +namespace AniDBUdpClient { + +EpisodeCommand::EpisodeCommand() +{ + init(); +} + +EpisodeCommand::EpisodeCommand(int eid) +{ + init(); + m_eid = eid; +} + +EpisodeCommand::EpisodeCommand(const QString &aname, int epno) +{ + init(); + m_aname = aname; + m_epno = epno; +} + +EpisodeCommand::EpisodeCommand(int aid, int epno) +{ + init(); + m_aid = aid; + m_epno = epno; +} + +int EpisodeCommand::eid() const +{ + return m_eid; +} + +void EpisodeCommand::setEid(int eid) +{ + m_eid = eid; +} + +int EpisodeCommand::aid() const +{ + return m_aid; +} + +void EpisodeCommand::setAid(int aid) +{ + m_aid = aid; +} + +int EpisodeCommand::epno() const +{ + return m_epno; +} + +void EpisodeCommand::setEpno(int epno) +{ + m_epno = epno; +} + +QString EpisodeCommand::aname() const +{ + return m_aname; +} + +void EpisodeCommand::setAname(const QString &aname) +{ + m_aname = aname; +} + +bool EpisodeCommand::isValid() const +{ + return m_eid || (m_aid && m_epno) || (!m_aname.isEmpty() && m_epno); +} + +bool EpisodeCommand::waitForResult() const +{ + return true; +} + +Command EpisodeCommand::rawCommand() const +{ + Command cmd; + cmd.first = "EPISODE"; + + if (m_eid) + { + cmd.second["eid"] = m_eid; + } + else if (m_aid && m_epno) + { + cmd.second["aid"] = m_aid; + cmd.second["epno"] = m_epno; + } + else if (!m_aname.isEmpty() && m_epno) + { + cmd.second["aname"] = m_aname; + cmd.second["epno"] = m_epno; + } + return cmd; +} + +void EpisodeCommand::init() +{ + m_eid = 0; + m_aid = 0; + m_epno = 0; +} + +// ----- + +int EpisodeReply::eid() const +{ + return m_eid; +} +int EpisodeReply::aid() const +{ + return m_aid; +} +int EpisodeReply::length() const +{ + return m_length; +} +double EpisodeReply::rating() const +{ + return m_rating; +} +int EpisodeReply::votes() const +{ + return m_votes; +} +QString EpisodeReply::epno() const +{ + return m_epno; +} +QString EpisodeReply::titleEnglish() const +{ + return m_titleEnglish; +} +QString EpisodeReply::titleRomaji() const +{ + return m_titleRomaji; +} +QString EpisodeReply::titleKanji() const +{ + return m_titleKanji; +} + +QDateTime EpisodeReply::airDate() const +{ + return m_airDate; +} + +void EpisodeReply::setRawReply(ReplyCode replyCode, const QString &reply) +{ + AbstractReply::setRawReply(replyCode, reply); + + switch (replyCode) + { + case EPISODE: + { + QStringList parts = reply.mid(reply.indexOf("\n")).split('|', QString::KeepEmptyParts); + if (parts.count() < 10) + { + signalReplyReady(false); + return; + } + bool ok; + m_eid = parts[0].toInt(&ok, 10); + m_aid = parts[1].toInt(&ok, 10); + m_length = parts[2].toInt(&ok, 10); + m_rating = parts[3].toDouble(&ok) / 1000; + m_votes = parts[4].toInt(&ok, 10); + m_epno = parts[5].toInt(&ok, 10); + m_titleEnglish = parts[6]; + m_titleRomaji = parts[7]; + m_titleKanji = parts[8]; + m_airDate = QDateTime::fromTime_t(parts[9].toUInt(&ok, 10)); + signalReplyReady(true); + } + break; + case NO_SUCH_EPISODE: + default: + { + signalReplyReady(false); + } + break; + } +} + +void EpisodeReply::init() +{ + m_eid = 0; + m_aid = 0; + m_length = 0; + m_rating = 0; + m_votes = 0; +} + + + +} // namespace AniDBUdpClient diff --git a/episodecommand.h b/episodecommand.h new file mode 100644 index 0000000..dac14f7 --- /dev/null +++ b/episodecommand.h @@ -0,0 +1,100 @@ +#ifndef EPISODECOMMAND_H +#define EPISODECOMMAND_H + +#include "abstractcommand.h" + +#include + +namespace AniDBUdpClient { + +class EpisodeReply; + +class ANIDBUDPCLIENTSHARED_EXPORT EpisodeCommand : public AbstractCommand +{ + //Q_PROPERTY(int eid READ eid WRITE setEid) + //Q_PROPERTY(int aid READ aid WRITE setAid) + //Q_PROPERTY(int epno READ epno WRITE setEpno) + //Q_PROPERTY(int aname READ aname WRITE setAname) + +public: + typedef EpisodeReply ReplyType; + EpisodeCommand(); + explicit EpisodeCommand(int eid); + EpisodeCommand(const QString &aname, int epno); + EpisodeCommand(int aid, int epno); + + + int eid() const; + void setEid(int eid); + + int aid() const; + void setAid(int aid); + + int epno() const; + void setEpno(int epno); + + QString aname() const; + void setAname(const QString &aname); + + bool isValid() const; + + bool waitForResult() const; + Command rawCommand() const; + +private: + void init(); + + int m_eid; + int m_aid; + int m_epno; + QString m_aname; +}; + +class ANIDBUDPCLIENTSHARED_EXPORT EpisodeReply : public AbstractReply +{ + Q_OBJECT + REPLY_DEFINITION_HELPER2(Episode) + + Q_PROPERTY(int eid READ eid) + Q_PROPERTY(int aid READ aid) + Q_PROPERTY(int length READ length) + Q_PROPERTY(double rating READ rating) + Q_PROPERTY(int votes READ votes) + Q_PROPERTY(QString epno READ epno) + Q_PROPERTY(QString titleEnglish READ titleEnglish) + Q_PROPERTY(QString titleRomaji READ titleRomaji) + Q_PROPERTY(QString titleKanji READ titleKanji) + Q_PROPERTY(QDateTime airDate READ airDate) + +public: + int eid() const; + int aid() const; + int length() const; + double rating() const; + int votes() const; + QString epno() const; + QString titleEnglish() const; + QString titleRomaji() const; + QString titleKanji() const; + QDateTime airDate() const; + + void setRawReply(ReplyCode replyCode, const QString &reply); + +private: + void init(); + + int m_eid; + int m_aid; + int m_length; + double m_rating; + int m_votes; + QString m_epno; + QString m_titleEnglish; + QString m_titleRomaji; + QString m_titleKanji; + QDateTime m_airDate; +}; + +} // namespace AniDBUdpClient + +#endif // EPISODECOMMAND_H -- 2.52.0