INCLUDEPATH += $$PWD/include
DEPENDPATH += $$PWD
LIBS += -lanidbudpclient
-LIBS += -L$$DESTDIR
+LIBS += -L$$DESTDIR -L$$PWD/build
hash.cpp \\r
hashproducer.cpp \\r
hashconsumer.cpp \\r
- clientcommandmodel.cpp\r
+ clientsentcommandsmodel.cpp \\r
+ clientqueuedcommandsmodel.cpp\r
\r
HEADERS += client.h \\r
anidbudpclient_global.h \\r
hashproducer.h \\r
hashconsumer.h \\r
circularbuffer.h \\r
- clientcommandmodel.h\r
+ clientsentcommandsmodel.h \\r
+ clientqueuedcommandsmodel.h\r
\r
CONV_HEADERS += include/AniDBUdpClient/Client \\r
include/AniDBUdpClient/AbstractCommand \\r
include/AniDBUdpClient/VoteCommand \\r
include/AniDBUdpClient/UptimeCommand \\r
include/AniDBUdpClient/File \\r
- include/AniDBUdpClient/Hash\r
+ include/AniDBUdpClient/Hash \\r
+ include/AniDBUdpClient/ClientSentCommandsModel \\r
+ include/AniDBUdpClient/ClientQueuedCommandsModel\r
#ifndef ANIDBUDPCLIENT_GLOBAL_H
#define ANIDBUDPCLIENT_GLOBAL_H
+#include <QtCore/QtGlobal>
#include <QObject>
#include <QMetaType>
#include <QFileInfo>
if (!controlCommandQueue.isEmpty())
{
qDebug() << "Sending Control Command";
- sendCommand(controlCommandQueue.dequeue(), true);
+ AbstractReply *cmd = controlCommandQueue.dequeue();
+ emit model_queuedCommandRemoved(0);
+ sendCommand(cmd, true);
emit commandSent();
return;
}
emit queueEmpty();
return;
}
- sendCommand(commandQueue.dequeue());
+
+ AbstractReply *cmd = commandQueue.dequeue();
+ emit model_queuedCommandRemoved(controlCommandQueue.size());
+ sendCommand(cmd);
+
emit commandSent();
}
if (sentCommandOrder.head() == commandId)
{
sentCommandOrder.dequeue();
+ emit model_sentCommandRemoved(0);
if (sentCommandOrder.isEmpty())
{
// If the reply is not for the first command sent,
// then there is no need to change the replyTimeoutTimer
// NOTE: even though this is linear search, the command should always be among the first few.
- sentCommandOrder.removeOne(commandId);
+ int index = sentCommandOrder.indexOf(commandId);
+ if (index != -1)
+ {
+ sentCommandOrder.removeAt(index);
+ emit model_sentCommandRemoved(index);
+ }
}
bool controlCommand = cmd->controlCommand();
Q_ASSERT(!sentCommandOrder.isEmpty());
QByteArray commandId = sentCommandOrder.dequeue();
+ emit model_sentCommandRemoved(0);
+
qDebug() << commandId << "timed out";
if (!sentCommandOrder.isEmpty())
if (first)
{
commandQueue.push_front(command);
+ emit model_queuedCommandAdded(controlCommandQueue.size());
}
else
{
commandQueue.enqueue(command);
+ emit model_queuedCommandAdded(controlCommandQueue.size() + commandQueue.size() - 1);
}
emit startSending();
if (first)
{
controlCommandQueue.push_front(command);
+ emit model_queuedCommandAdded(0);
}
else
{
controlCommandQueue.enqueue(command);
+ emit model_queuedCommandAdded(controlCommandQueue.size() - 1);
}
emit startSending();
sentCommands[commandId] = command;
sentCommandOrder.enqueue(commandId);
+ emit model_sentCommandAdded(sentCommandOrder.size() - 1);
if (!replyTimeoutTimer->isActive())
{
#include <QHostInfo>
#include <QVariantMap>
-#include "anidbudpclient_global.h"
#include "authcommand.h"
class QStateMachine;
class ANIDBUDPCLIENTSHARED_EXPORT Client : public QObject
{
friend class AbstractReply;
- friend class ClientCommandModel;
+ friend class ClientQueuedCommandsModel;
+ friend class ClientSentCommandsModel;
Q_OBJECT
Q_ENUMS(AniDBUdpClient::State AniDBUdpClient::Error AniDBUdpClient::IdlePolicy AniDBUdpClient::ReplyCode);
private:
template<typename T> typename T::ReplyType *createReply(const T &command, QObject *parent = 0)
{
- return new T::ReplyType(command, nextCommandId(), this, parent);
+ return new typename T::ReplyType(command, nextCommandId(), this, parent);
}
public slots:
void connectionError();
+ void model_queuedCommandAdded(int index);
+ void model_queuedCommandRemoved(int index);
+ void model_sentCommandAdded(int index);
+ void model_sentCommandRemoved(int index);
+
private slots:
void enterErrorState();
void enterDisconnectedState();
+++ /dev/null
-#include "clientcommandmodel.h"\r
-\r
-#include "client.h"\r
-\r
-namespace AniDBUdpClient {\r
-\r
-ClientCommandModel::ClientCommandModel(Client *client, QObject *parent) :\r
- QAbstractTableModel(parent), m_client(client)\r
-{\r
-}\r
-\r
-Client *ClientCommandModel::client() const\r
-{\r
- return m_client;\r
-}\r
-\r
-void ClientCommandModel::setClient(Client *client)\r
-{\r
- beginResetModel();\r
- m_client = client;\r
- endResetModel();\r
-}\r
-\r
-int ClientCommandModel::rowCount(const QModelIndex &/*parent*/) const\r
-{\r
- if (!m_client)\r
- return 0;\r
- return m_client->sentCommands.count();\r
-}\r
-\r
-int ClientCommandModel::columnCount(const QModelIndex &/*parent*/) const\r
-{\r
- return 3;\r
-}\r
-\r
-QVariant ClientCommandModel::headerData(int section, Qt::Orientation orientation, int role) const\r
-{\r
- if (role != Qt::DisplayRole)\r
- return QVariant();\r
-\r
- if (orientation == Qt::Vertical)\r
- return section + 1;\r
-\r
- switch (section)\r
- {\r
- case 0:\r
- return tr("Time Sent");\r
- case 1:\r
- return tr("Command");\r
- case 2:\r
- return tr("Arguments");\r
- }\r
-\r
- return QVariant();\r
-}\r
-\r
-QVariant ClientCommandModel::data(const QModelIndex &index, int role) const\r
-{\r
- if (role != Qt::DisplayRole)\r
- return QVariant();\r
-\r
- AbstractReply *currentReply = m_client->sentCommands[m_client->sentCommandOrder[index.row()]];\r
-\r
- switch (index.column())\r
- {\r
- case 0:\r
- return currentReply->timeSent();\r
- case 1:\r
- return currentReply->command().rawCommand().first;\r
- case 2:\r
- return currentReply->command().rawCommand().second;\r
- }\r
- return QVariant();\r
-}\r
-\r
-\r
-void ClientCommandModel::commandAdded(int index)\r
-{\r
- beginInsertRows(QModelIndex(), index, index + 1);\r
- endInsertRows();\r
-}\r
-\r
-void ClientCommandModel::commandRemoved(int index)\r
-{\r
- beginRemoveRows(QModelIndex(), index, index + 1);\r
- endRemoveRows();\r
-}\r
-\r
-} // namespace AniDBUdpClient\r
--- /dev/null
+#include "clientqueuedcommandsmodel.h"\r
+\r
+#include "client.h"\r
+\r
+namespace AniDBUdpClient {\r
+\r
+ClientQueuedCommandsModel::ClientQueuedCommandsModel(Client *client, QObject *parent) :\r
+ m_client(0), QAbstractTableModel(parent)\r
+{\r
+ setClient(client);\r
+}\r
+\r
+Client *ClientQueuedCommandsModel::client() const\r
+{\r
+ return m_client;\r
+}\r
+\r
+void ClientQueuedCommandsModel::setClient(Client *client)\r
+{\r
+ if (m_client)\r
+ disconnect(m_client, 0, this, 0);\r
+\r
+ beginResetModel();\r
+ if (client)\r
+ {\r
+ connect(client, SIGNAL(model_queuedCommandAdded(int)), this, SLOT(commandAdded(int)));\r
+ connect(client, SIGNAL(model_queuedCommandRemoved(int)), this, SLOT(commandRemoved(int)));\r
+ }\r
+ m_client = client;\r
+ endResetModel();\r
+}\r
+\r
+int ClientQueuedCommandsModel::rowCount(const QModelIndex &/*parent*/) const\r
+{\r
+ if (!m_client)\r
+ return 0;\r
+ return m_client->controlCommandQueue.count() + m_client->commandQueue.count();\r
+}\r
+\r
+int ClientQueuedCommandsModel::columnCount(const QModelIndex &/*parent*/) const\r
+{\r
+ return 3;\r
+}\r
+\r
+QVariant ClientQueuedCommandsModel::headerData(int section, Qt::Orientation orientation, int role) const\r
+{\r
+ if (role != Qt::DisplayRole)\r
+ return QVariant();\r
+\r
+ if (orientation == Qt::Vertical)\r
+ {\r
+ return section + 1;\r
+ }\r
+\r
+ switch (section)\r
+ {\r
+ case 0:\r
+ return tr("Control command");\r
+ case 1:\r
+ return tr("Command");\r
+ case 2:\r
+ return tr("Arguments");\r
+ }\r
+\r
+ return QVariant();\r
+}\r
+\r
+QVariant ClientQueuedCommandsModel::data(const QModelIndex &index, int role) const\r
+{\r
+ if (role != Qt::DisplayRole)\r
+ return QVariant();\r
+\r
+ AbstractReply *currentReply;\r
+ if (index.row() < m_client->controlCommandQueue.count())\r
+ currentReply = m_client->controlCommandQueue.at(index.row());\r
+ else\r
+ currentReply = m_client->commandQueue.at(index.row() - m_client->controlCommandQueue.count());\r
+\r
+ switch (index.column())\r
+ {\r
+ case 0:\r
+ return currentReply->controlCommand() ? tr("Yes") : tr("No");\r
+ case 1:\r
+ return currentReply->command().rawCommand().first;\r
+ case 2:\r
+ {\r
+ Command rawCommand = currentReply->command().rawCommand();\r
+ QString s = QString("(%1) ").arg(rawCommand.second.count());\r
+ for (QVariantMap::const_iterator i = rawCommand.second.constBegin(); i != rawCommand.second.constEnd(); ++i)\r
+ {\r
+ s += QString("%1=%2; ").arg(i.key(), i.value().toString());\r
+ }\r
+ return s;\r
+ }\r
+ }\r
+ return QVariant();\r
+}\r
+\r
+\r
+void ClientQueuedCommandsModel::commandAdded(int index)\r
+{\r
+ beginInsertRows(QModelIndex(), index, index);\r
+ endInsertRows();\r
+}\r
+\r
+void ClientQueuedCommandsModel::commandRemoved(int index)\r
+{\r
+ beginRemoveRows(QModelIndex(), index, index);\r
+ endRemoveRows();\r
+}\r
+\r
+} // namespace AniDBUdpClient\r
--- /dev/null
+#ifndef CLIENTQUEUEDCOMMANDSMODEL_H\r
+#define CLIENTQUEUEDCOMMANDSMODEL_H\r
+\r
+#include "anidbudpclient_global.h"\r
+\r
+#include <QAbstractTableModel>\r
+\r
+namespace AniDBUdpClient {\r
+\r
+class Client;\r
+\r
+class ANIDBUDPCLIENTSHARED_EXPORT ClientQueuedCommandsModel : public QAbstractTableModel\r
+{\r
+ Q_OBJECT\r
+public:\r
+ explicit ClientQueuedCommandsModel(Client *client, QObject *parent = 0);\r
+\r
+ Client *client() const;\r
+ void setClient(Client *client);\r
+\r
+ int rowCount(const QModelIndex &parent = QModelIndex()) const;\r
+ int columnCount(const QModelIndex &/*parent*/) const;\r
+\r
+ QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;\r
+ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;\r
+\r
+signals:\r
+\r
+private slots:\r
+ void commandAdded(int index);\r
+ void commandRemoved(int index);\r
+\r
+private:\r
+\r
+ Client *m_client;\r
+};\r
+\r
+} // namespace AniDBUdpClient\r
+\r
+#endif // CLIENTQUEUEDCOMMANDSMODEL_H\r
--- /dev/null
+#include "clientsentcommandsmodel.h"\r
+\r
+#include "client.h"\r
+\r
+namespace AniDBUdpClient {\r
+\r
+ClientSentCommandsModel::ClientSentCommandsModel(Client *client, QObject *parent) :\r
+ m_client(0), QAbstractTableModel(parent)\r
+{\r
+ setClient(client);\r
+}\r
+\r
+Client *ClientSentCommandsModel::client() const\r
+{\r
+ return m_client;\r
+}\r
+\r
+void ClientSentCommandsModel::setClient(Client *client)\r
+{\r
+ if (m_client)\r
+ disconnect(m_client, 0, this, 0);\r
+\r
+ beginResetModel();\r
+ if (client)\r
+ {\r
+ connect(client, SIGNAL(model_sentCommandAdded(int)), this, SLOT(commandAdded(int)));\r
+ connect(client, SIGNAL(model_sentCommandRemoved(int)), this, SLOT(commandRemoved(int)));\r
+ }\r
+ m_client = client;\r
+ endResetModel();\r
+}\r
+\r
+int ClientSentCommandsModel::rowCount(const QModelIndex &/*parent*/) const\r
+{\r
+ if (!m_client)\r
+ return 0;\r
+ return m_client->sentCommandOrder.count();\r
+}\r
+\r
+int ClientSentCommandsModel::columnCount(const QModelIndex &/*parent*/) const\r
+{\r
+ return 3;\r
+}\r
+\r
+QVariant ClientSentCommandsModel::headerData(int section, Qt::Orientation orientation, int role) const\r
+{\r
+ if (role != Qt::DisplayRole)\r
+ return QVariant();\r
+\r
+ if (orientation == Qt::Vertical)\r
+ {\r
+ return section + 1;\r
+ }\r
+\r
+ switch (section)\r
+ {\r
+ case 0:\r
+ return tr("Time Sent");\r
+ case 1:\r
+ return tr("Command");\r
+ case 2:\r
+ return tr("Arguments");\r
+ }\r
+\r
+ return QVariant();\r
+}\r
+\r
+QVariant ClientSentCommandsModel::data(const QModelIndex &index, int role) const\r
+{\r
+ if (role != Qt::DisplayRole)\r
+ return QVariant();\r
+\r
+ AbstractReply *currentReply = m_client->sentCommands[m_client->sentCommandOrder[index.row()]];\r
+\r
+ switch (index.column())\r
+ {\r
+ case 0:\r
+ return currentReply->timeSent();\r
+ case 1:\r
+ return currentReply->command().rawCommand().first;\r
+ case 2:\r
+ {\r
+ Command rawCommand = currentReply->command().rawCommand();\r
+ QString s = QString("(%1) ").arg(rawCommand.second.count());\r
+ for (QVariantMap::const_iterator i = rawCommand.second.constBegin(); i != rawCommand.second.constEnd(); ++i)\r
+ {\r
+ s += QString("%1=%2; ").arg(i.key(), i.value().toString());\r
+ }\r
+ return s;\r
+ }\r
+ }\r
+ return QVariant();\r
+}\r
+\r
+\r
+void ClientSentCommandsModel::commandAdded(int index)\r
+{\r
+ beginInsertRows(QModelIndex(), index, index);\r
+ endInsertRows();\r
+}\r
+\r
+void ClientSentCommandsModel::commandRemoved(int index)\r
+{\r
+ beginRemoveRows(QModelIndex(), index, index);\r
+ endRemoveRows();\r
+}\r
+\r
+} // namespace AniDBUdpClient\r
\r
class Client;\r
\r
-class ANIDBUDPCLIENTSHARED_EXPORT ClientCommandModel : public QAbstractTableModel\r
+class ANIDBUDPCLIENTSHARED_EXPORT ClientSentCommandsModel : public QAbstractTableModel\r
{\r
Q_OBJECT\r
public:\r
- explicit ClientCommandModel(Client *client = 0, QObject *parent = 0);\r
+ explicit ClientSentCommandsModel(Client *client = 0, QObject *parent = 0);\r
\r
Client *client() const;\r
void setClient(Client *client);\r
\r
signals:\r
\r
-public slots:\r
-\r
-private:\r
+private slots:\r
void commandAdded(int index);\r
void commandRemoved(int index);\r
\r
+private:\r
+\r
Client *m_client;\r
};\r
\r
--- /dev/null
+#include "../../clientqueuedcommandsmodel.h"
\ No newline at end of file
--- /dev/null
+#include "../../clientsentcommandsmodel.h"
\ No newline at end of file