]> Some of my projects - aniplayer-old.git/commitdiff
- Add MyList command
authorAPTX <APTX@.(none)>
Mon, 3 Aug 2009 17:30:24 +0000 (19:30 +0200)
committerAPTX <APTX@.(none)>
Mon, 3 Aug 2009 17:30:24 +0000 (19:30 +0200)
lib/anidbudpclient/abstractcommand.h
lib/anidbudpclient/anidbudpclient.pro
lib/anidbudpclient/mylistcommand.cpp [new file with mode: 0644]
lib/anidbudpclient/mylistcommand.h [new file with mode: 0644]

index 5cbbad224e1dc2edcc60fa7cc3836050ac2acb22..630f2bc0c2b90363f5ffc23c4dc09ae2b0ebba37 100644 (file)
@@ -13,7 +13,7 @@ typedef QPair<QString, QVariantMap> Command;
 class ANIDBUDPCLIENTSHARED_EXPORT AbstractCommand : public QObject
 {
        Q_OBJECT
-       Q_ENUMS(ReplyCode);
+       Q_ENUMS(ReplyCode State FileState);
 
        Q_PROPERTY(ReplyCode replyCode READ replyCode);
 
@@ -155,6 +155,26 @@ public:
                API_VIOLATION                           = 666, //a
        };
 
+       enum State {
+               Unknown = 0,
+               OnHdd = 1,
+               OnCd = 2,
+               Deleted = 3
+       };
+
+       enum FileState {
+               Normal = 0,
+               Corrupted = 1,
+               SelfEdited = 2,
+               SelfRipped = 10,
+               OnDVD = 11,
+               OnVHS = 12,
+               OnTV = 13,
+               InTheatres = 14,
+               Streamed = 15,
+               Other = 100
+       };
+
        AbstractCommand(QObject *parent = 0);
        virtual ~AbstractCommand();
 
index f6aeaccf1d76c68fa0465af10860ee1657395113..e0c60afa52a0565f38a5e19c477c0b19f07b74f5 100644 (file)
@@ -23,7 +23,8 @@ SOURCES += anidbudpclient.cpp \
     rawcommand.cpp \
     mylistaddcommand.cpp \
     logoutcommand.cpp \
-    uptimecommand.cpp
+    uptimecommand.cpp \
+    mylistcommand.cpp
 HEADERS += anidbudpclient.h \
     anidbudpclient_global.h \
     abstractcommand.h \
@@ -31,5 +32,6 @@ HEADERS += anidbudpclient.h \
     rawcommand.h \
     mylistaddcommand.h \
     logoutcommand.h \
-    uptimecommand.h
+    uptimecommand.h \
+    mylistcommand.h
 include(../../lib/qtstatemachine/src/qtstatemachine.pri)
diff --git a/lib/anidbudpclient/mylistcommand.cpp b/lib/anidbudpclient/mylistcommand.cpp
new file mode 100644 (file)
index 0000000..bab42c5
--- /dev/null
@@ -0,0 +1,313 @@
+#include "mylistcommand.h"
+
+#include <QStringList>
+
+MyListCommand::MyListCommand(QObject *parent) : AbstractCommand(parent)
+{
+       init();
+}
+
+MyListCommand::MyListCommand(int lid, QObject *parent) : AbstractCommand(parent)
+{
+       init();
+       m_lid = lid;
+}
+
+MyListCommand::MyListCommand(int fid, bool isFid, QObject *parent) : AbstractCommand(parent)
+{
+       Q_UNUSED(isFid);
+       init();
+       m_fid = fid;
+}
+
+MyListCommand::MyListCommand(const QByteArray &ed2k, qint64 size, QObject *parent) : AbstractCommand(parent)
+{
+       init();
+       m_ed2k = ed2k;
+       m_size = size;
+}
+
+MyListCommand::MyListCommand(const QString &aname, const QString &gname, int epno, QObject *parent) : AbstractCommand(parent)
+{
+       init();
+       m_aname = aname;
+       m_gname = gname;
+       m_epno = epno;
+}
+
+MyListCommand::MyListCommand(const QString &aname, int gid, int epno, QObject *parent) : AbstractCommand(parent)
+{
+       init();
+       m_aname = aname;
+       m_gid = gid;
+       m_epno = epno;
+}
+
+MyListCommand::MyListCommand(int aid, const QString &gname, int epno, QObject *parent) : AbstractCommand(parent)
+{
+       m_aid = aid;
+       m_gname = gname;
+       m_epno = epno;
+}
+
+MyListCommand::MyListCommand(int aid, int gid, int epno, QObject *parent) : AbstractCommand(parent)
+{
+       m_aid = aid;
+       m_gid = gid;
+       m_epno = epno;
+}
+
+int MyListCommand::lid() const
+{
+       return m_lid;
+}
+
+void MyListCommand::setLid(int lid)
+{
+       m_lid = lid;
+}
+
+int MyListCommand::fid() const
+{
+       return m_fid;
+}
+
+void MyListCommand::setFid(int fid)
+{
+       m_fid = fid;
+}
+
+QByteArray MyListCommand::ed2k() const
+{
+       return m_ed2k;
+}
+
+void MyListCommand::setEd2k(const QByteArray &ed2k)
+{
+       m_ed2k = ed2k;
+}
+
+qint64 MyListCommand::size() const
+{
+       return m_size;
+}
+
+void MyListCommand::setSize(qint64 size)
+{
+       m_size = size;
+}
+
+QString MyListCommand::aname() const
+{
+       return m_aname;
+}
+
+void MyListCommand::setAname(const QString &aname)
+{
+       m_aname = aname;
+}
+
+int MyListCommand::aid() const
+{
+       return m_aid;
+}
+
+void MyListCommand::setAid(int aid)
+{
+       m_aid = aid;
+}
+
+QString MyListCommand::gname() const
+{
+       return m_gname;
+}
+
+void MyListCommand::setGname(const QString &gname)
+{
+       m_gname = gname;
+}
+
+int MyListCommand::gid() const
+{
+       return m_gid;
+}
+
+void MyListCommand::setGid(int gid)
+{
+       m_gid = gid;
+}
+
+
+int MyListCommand::epno() const
+{
+       return m_epno;
+}
+
+void MyListCommand::setEpno(int epno)
+{
+       m_epno = epno;
+}
+
+bool MyListCommand::isValid() const
+{
+       return m_lid || m_fid || m_aid
+                       || !m_aname.isEmpty()
+                       || (!m_ed2k.isEmpty() && m_size);
+}
+
+int MyListCommand::eid() const
+{
+       return m_eid;
+}
+
+QDateTime MyListCommand::date() const
+{
+       return m_date;
+}
+
+AbstractCommand::State MyListCommand::state() const
+{
+       return m_state;
+}
+
+QDateTime MyListCommand::viewDate() const
+{
+       return m_viewDate;
+}
+
+QString MyListCommand::storage() const
+{
+       return m_storage;
+}
+
+QString MyListCommand::source() const
+{
+       return m_source;
+}
+
+QString MyListCommand::other() const
+{
+       return m_other;
+}
+
+AbstractCommand::FileState MyListCommand::fileState() const
+{
+       return m_fileState;
+}
+
+QStringList MyListCommand::multipleEntries() const
+{
+       return m_multipleEntries;
+}
+
+bool MyListCommand::waitForResult() const
+{
+       return true;
+}
+
+Command MyListCommand::rawCommand() const
+{
+       Command cmd;
+
+       cmd.first = "MYLIST";
+
+       if (m_lid)
+       {
+               cmd.second["lid"] = m_lid;
+       }
+       else if (m_fid)
+       {
+               cmd.second["fid"] = m_fid;
+       }
+       else if (!m_ed2k.isEmpty() && m_size)
+       {
+               cmd.second["ed2k"] = m_ed2k;
+               cmd.second["size"] = m_size;
+       }
+       else if (!m_aname.isEmpty())
+       {
+               cmd.second["aname"] = m_aname;
+               if (!m_gname.isEmpty() && m_epno)
+               {
+                       cmd.second["gname"] = m_gname;
+                       cmd.second["epno"] = m_epno;
+               }
+               else if (m_gid && m_epno)
+               {
+                       cmd.second["gid"] = m_gid;
+                       cmd.second["epno"] = m_epno;
+               }
+       }
+       else if (m_aid)
+       {
+               cmd.second["aid"] = m_aid;
+               if (!m_gname.isEmpty() && m_epno)
+               {
+                       cmd.second["gname"] = m_gname;
+                       cmd.second["epno"] = m_epno;
+               }
+               else if (m_gid && m_epno)
+               {
+                       cmd.second["gid"] = m_gid;
+                       cmd.second["epno"] = m_epno;
+               }
+       }
+       else
+       {
+               // TODO WTF NOW?!?
+       }
+       return cmd;
+}
+
+void MyListCommand::setRawReply(ReplyCode replyCode, const QString &reply, AniDBUdpClient *client)
+{
+       AbstractCommand::setRawReply(replyCode, reply, client);
+
+       switch (replyCode)
+       {
+               case MYLIST:
+               {
+                       QStringList parts = reply.mid(reply.indexOf("\n")).split('|', QString::KeepEmptyParts);
+                       bool ok;
+                       m_lid = parts[0].toInt(&ok, 10);
+                       m_fid = parts[1].toInt(&ok, 10);
+                       m_eid = parts[2].toInt(&ok, 10);
+                       m_aid = parts[3].toInt(&ok, 10);
+                       m_gid = parts[4].toInt(&ok, 10);
+                       m_date = QDateTime::fromTime_t(parts[5].toUInt(&ok, 10));
+                       m_state = State(parts[6].toInt(&ok, 10));
+                       m_viewDate = QDateTime::fromTime_t(parts[7].toUInt(&ok, 10));
+                       m_storage = parts[8];
+                       m_source = parts[9];
+                       m_other = parts[10];
+                       m_fileState = FileState(parts[11].toInt(&ok, 10));
+                       emit replyReady(true);
+               }
+               break;
+               case MULTIPLE_MYLIST_ENTRIES:
+               {
+                       m_multipleEntries = reply.mid(reply.indexOf("\n")).split('|', QString::KeepEmptyParts);
+                       emit replyReady(true);
+               }
+               break;
+               case NO_SUCH_ENTRY:
+               default:
+                       emit replyReady(false);
+               break;
+       }
+}
+
+void MyListCommand::init()
+{
+       m_lid = 0;
+       m_fid = 0;
+       m_aid = 0;
+       m_gid = 0;
+       m_eid = 0;
+
+       m_size = 0;
+       m_epno = 0;
+
+       m_state = State(0);
+       m_fileState = FileState(0);
+}
diff --git a/lib/anidbudpclient/mylistcommand.h b/lib/anidbudpclient/mylistcommand.h
new file mode 100644 (file)
index 0000000..b842d47
--- /dev/null
@@ -0,0 +1,114 @@
+#ifndef MYLISTCOMMAND_H
+#define MYLISTCOMMAND_H
+
+#include <QDateTime>
+#include <QStringList>
+
+#include "abstractcommand.h"
+
+class ANIDBUDPCLIENTSHARED_EXPORT MyListCommand : public AbstractCommand
+{
+       Q_OBJECT
+       
+       Q_PROPERTY(int lid READ lid WRITE setLid);
+       Q_PROPERTY(int fid READ fid WRITE setFid);
+       
+       Q_PROPERTY(QByteArray ed2k READ ed2k WRITE setEd2k);
+       Q_PROPERTY(qint64 size READ size WRITE setSize);
+
+       Q_PROPERTY(QString aname READ aname WRITE setAname);
+       Q_PROPERTY(int aid READ aid WRITE setAid);
+       Q_PROPERTY(QString gname READ gname WRITE setGname);
+       Q_PROPERTY(int gid READ gid WRITE setGid);
+       Q_PROPERTY(int epno READ epno WRITE setEpno);
+
+       Q_PROPERTY(bool valid READ isValid);
+
+       Q_PROPERTY(int eid READ eid);
+       Q_PROPERTY(QDateTime date READ date);
+       Q_PROPERTY(State state READ state);
+       Q_PROPERTY(QDateTime viewDate READ viewDate);
+       Q_PROPERTY(QString storage READ storage);
+       Q_PROPERTY(QString source READ source);
+       Q_PROPERTY(QString other READ other);
+       Q_PROPERTY(FileState fileState READ fileState);
+
+       Q_PROPERTY(QStringList multipleEntries READ multipleEntries);
+public:
+       MyListCommand(QObject *parent = 0);
+       MyListCommand(int lid, QObject *parent = 0);
+       MyListCommand(int fid, bool isFid, QObject *parent = 0);
+       MyListCommand(const QByteArray &ed2k, qint64 size, QObject *parent = 0);
+       MyListCommand(const QString &aname, const QString &gname, int epno, QObject *parent = 0);
+       MyListCommand(const QString &aname, int gid, int epno, QObject *parent = 0);
+       MyListCommand(int aid, const QString &gname, int epno, QObject *parent = 0);
+       MyListCommand(int aid, int gid, int epno, QObject *parent = 0);
+
+       int lid() const;
+       void setLid(int lid);
+       int fid() const;
+       void setFid(int fid);
+
+       QByteArray ed2k() const;
+       void setEd2k(const QByteArray &ed2k);
+       qint64 size() const;
+       void setSize(qint64 size);
+
+       QString aname() const;
+       void setAname(const QString &aname);
+       int aid() const;
+       void setAid(int aid);
+       QString gname() const;
+       void setGname(const QString &gname);
+       int gid() const;
+       void setGid(int gid);
+       int epno() const;
+       void setEpno(int epno);
+
+       bool isValid() const;
+
+
+       int eid() const;
+       QDateTime date() const;
+       State state() const;
+       QDateTime viewDate() const;
+       QString storage() const;
+       QString source() const;
+       QString other() const;
+       FileState fileState() const;
+
+       QStringList multipleEntries() const;
+
+       bool waitForResult() const;
+       Command rawCommand() const;
+       void setRawReply(ReplyCode replyCode, const QString &reply, AniDBUdpClient *client);
+
+private:
+       void init();
+
+       int m_lid;
+       int m_fid;
+
+       QByteArray m_ed2k;
+       qint64 m_size;
+
+       QString m_aname;
+       int m_aid;
+       QString m_gname;
+       int m_gid;
+       int m_epno;
+
+       int m_eid;
+       QDateTime m_date;
+       State m_state;
+       QDateTime m_viewDate;
+       QString m_storage;
+       QString m_source;
+       QString m_other;
+       FileState m_fileState;
+
+       QStringList m_multipleEntries;
+
+};
+
+#endif // MYLISTCOMMAND_H