From: APTX Date: Sun, 13 May 2012 17:30:50 +0000 (+0200) Subject: Add AnimeCommand (unfinished) X-Git-Url: https://gitweb.tyo.aptx.org/?a=commitdiff_plain;h=ac5ac83f71e0eafeef220feaac05321c8a3337ee;p=anidbudpclient.git Add AnimeCommand (unfinished) --- diff --git a/anidbudpclient.pro b/anidbudpclient.pro index de82abf..30f3308 100644 --- a/anidbudpclient.pro +++ b/anidbudpclient.pro @@ -40,7 +40,8 @@ SOURCES += client.cpp \ filerenamedelegate.cpp \ clientinterface.cpp \ myliststate.cpp \ - episodecommand.cpp + episodecommand.cpp \ + animecommand.cpp HEADERS += client.h \ anidbudpclient_global.h \ @@ -65,7 +66,8 @@ HEADERS += client.h \ filerenamedelegate.h \ clientinterface.h \ myliststate.h \ - episodecommand.h + episodecommand.h \ + animecommand.h CONV_HEADERS += include/AniDBUdpClient/Client \ include/AniDBUdpClient/AbstractCommand \ diff --git a/animecommand.cpp b/animecommand.cpp new file mode 100644 index 0000000..b4d352b --- /dev/null +++ b/animecommand.cpp @@ -0,0 +1,123 @@ +#include "animecommand.h" + +#include + +namespace AniDBUdpClient { + +AnimeCommand::AnimeCommand() +{ + init(); +} + +AnimeCommand::AnimeCommand(int aid, AnimeFlags amask) +{ + init(); + m_aid = aid; + m_amask = amask; +} + +AnimeCommand::AnimeCommand(const QString &aname, AnimeFlags amask) +{ + init(); + m_aname = aname; + m_amask = amask; +} + +int AnimeCommand::aid() const +{ + return m_aid; +} + +void AnimeCommand::setAid(int aid) +{ + m_aid = aid; +} + +AnimeFlags AnimeCommand::amask() const +{ + return m_amask; +} + +void AnimeCommand::amask(AnimeFlags amask) +{ + m_amask = amask; +} + +QString AnimeCommand::aname() const +{ + return m_aname; +} + +void AnimeCommand::setAname(const QString &aname) +{ + m_aname = aname; +} + +bool AnimeCommand::isValid() const +{ + return m_aid || !m_aname.isEmpty(); + // amask doesn't need to be checked as all invalid bits are removed +} + +bool AnimeCommand::waitForResult() const +{ + return true; +} + +Command AnimeCommand::rawCommand() const +{ + Command cmd; + cmd.first = "ANIME"; + + if (m_aid) + cmd.second["aid"] = m_aid; + else if (!m_aname.isEmpty()) + cmd.second["aname"] = m_aname; + + if (m_amask) + cmd.second["amask"] = QString::number(m_amask & AnimeFlag::AllData, 16) + .rightJustified(14, QLatin1Char('0'));; + + return cmd; +} + +void AnimeCommand::init() +{ + m_aid = 0; + m_amask = 0; +} + +QVariant AnimeReply::value(AnimeFlags f) const +{ + return animeFlagData.value(f); +} + +void AnimeReply::setRawReply(ReplyCode replyCode, const QString &reply) +{ + AbstractReply::setRawReply(replyCode, reply); + + switch (replyCode) + { + case ANIME: + readReplyData(reply); + signalReplyReady(true); + break; + case NO_SUCH_ANIME: + default: + signalReplyReady(false); + break; + } +} + +void AnimeReply::readReplyData(const QString &reply) +{ + QString d = reply.mid(reply.indexOf('\n')).trimmed(); + QStringList parts = d.split('|', QString::KeepEmptyParts); + +} + +void AnimeReply::init() +{ +} + +} // namespace AniDBUdpClient diff --git a/animecommand.h b/animecommand.h new file mode 100644 index 0000000..1a56a1f --- /dev/null +++ b/animecommand.h @@ -0,0 +1,64 @@ +#ifndef ANIMECOMMAND_H +#define ANIMECOMMAND_H + +#include "abstractcommand.h" + +namespace AniDBUdpClient { + +class AnimeReply; + +class ANIDBUDPCLIENTSHARED_EXPORT AnimeCommand : 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 AnimeReply ReplyType; + AnimeCommand(); + explicit AnimeCommand(int aid, AnimeFlags amask = 0); + explicit AnimeCommand(const QString &aname, AnimeFlags amask = 0); + + int aid() const; + void setAid(int aid); + + AnimeFlags amask() const; + void amask(AnimeFlags amask); + + QString aname() const; + void setAname(const QString &aname); + + bool isValid() const; + + bool waitForResult() const; + Command rawCommand() const; + +private: + void init(); + + int m_aid; + AnimeFlags m_amask; + QString m_aname; +}; + +class ANIDBUDPCLIENTSHARED_EXPORT AnimeReply : public AbstractReply +{ + Q_OBJECT + REPLY_DEFINITION_HELPER2(Anime) + +public: + QVariant value(AnimeFlags f) const; + + void setRawReply(ReplyCode replyCode, const QString &reply); + +private: + void readReplyData(const QString &reply); + void init(); + + QMap animeFlagData; +}; + +} // namespace AniDBUdpClient + +#endif // ANIMECOMMAND_H