]> Some of my projects - anidbudpclient.git/commitdiff
Add EPISODE command.
authorAPTX <marek321@gmail.com>
Tue, 28 Feb 2012 20:47:03 +0000 (21:47 +0100)
committerAPTX <marek321@gmail.com>
Tue, 28 Feb 2012 20:47:03 +0000 (21:47 +0100)
anidbudpclient.pro
episodecommand.cpp [new file with mode: 0644]
episodecommand.h [new file with mode: 0644]

index e53759cc7b35b9d63239db35d7ec216693b6e1de..de82abf48567db91c8feb8a98c192645418c21b4 100644 (file)
@@ -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 (file)
index 0000000..025db69
--- /dev/null
@@ -0,0 +1,203 @@
+#include "episodecommand.h"
+
+#include <QStringList>
+
+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 (file)
index 0000000..dac14f7
--- /dev/null
@@ -0,0 +1,100 @@
+#ifndef EPISODECOMMAND_H
+#define EPISODECOMMAND_H
+
+#include "abstractcommand.h"
+
+#include <QDateTime>
+
+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