Commit 245b8f4b authored by Martin Straka's avatar Martin Straka

Updated download message list task (add counters and download messages)

parent 0f01e7a1
......@@ -123,19 +123,25 @@ bool IsdsWrapper::syncSingleAccount(const QVariant &acntModelVariant,
msgType = tr("sent");
}
emit statusBarTextChanged(tr("%1: downloading %2").arg(userName).arg(msgType), true, true);
emit statusBarTextChanged(tr("%1: downloading %2").arg(userName).arg(msgType),
true, true);
AccountListModel *accountModel =
AccountListModel::fromVariant(acntModelVariant);
MessageListModel *messageModel =
MessageListModel::fromVariant(msgModelVariant);
/* Create download message list task and run it */
TaskDownloadMessageList *task;
task = new (std::nothrow) TaskDownloadMessageList(
m_isdsSession.isdsCtxMap[userName], &m_netLayer, &m_dbWrapper,
msgDirect, (globSet.downloadOnlyNewMsgs) ? DOWNLOAD_NEW_MESSAGES : DOWNLOAD_ALL_MESSAGES,
1, MESSAGE_LIST_LIMIT);
1, MESSAGE_LIST_LIMIT, &m_workPool, messageModel, accountModel,
globSet.downloadCompleteMsgs, globSet.dbsLocation);
task->setAutoDelete(false);
m_workPool.runSingle(task);
/* Results from task */
QList<qint64> msgIds = task->m_msgIds;
const QString statusBarText = task->m_statusBarText;
bool success = TaskDownloadMessageList::DL_SUCCESS == task->m_result;
delete task;
......@@ -149,48 +155,6 @@ bool IsdsWrapper::syncSingleAccount(const QVariant &acntModelVariant,
emit statusBarTextChanged(statusBarText, false, true);
}
/* Update message counters in the accout list */
AccountListModel *accountModel =
AccountListModel::fromVariant(acntModelVariant);
if (accountModel == Q_NULLPTR) {
qWarning("%s", "Cannot access account model.");
} else {
MessageDb *msgDb = globMessageDbsPtr->accessMessageDb(
globSet.dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (msgDb != Q_NULLPTR) {
if (msgDirect == Messages::TYPE_RECEIVED) {
accountModel->updateCounters(userName,
msgDb->getCntOfNewMsgs(MessageDb::TYPE_RECEIVED),
msgDb->getMessageCount(MessageDb::TYPE_RECEIVED),
-1, -1);
} else {
accountModel->updateCounters(userName,
-1, -1,
msgDb->getCntOfNewMsgs(MessageDb::TYPE_SENT),
msgDb->getMessageCount(MessageDb::TYPE_SENT));
}
}
}
/* Download complete messages (create and insert tasks to worker pool) */
if (globSet.downloadCompleteMsgs) {
MessageListModel *messageModel =
MessageListModel::fromVariant(msgModelVariant);
if (messageModel == Q_NULLPTR) {
qWarning("%s", "Cannot access message model.");
}
foreach (qint64 msgId, msgIds) {
TaskDownloadMessage *task;
task = new (std::nothrow) TaskDownloadMessage(
m_isdsSession.isdsCtxMap[userName], &m_netLayer,
&m_dbWrapper, msgId, msgDirect, messageModel);
task->setAutoDelete(true);
m_workPool.assignLo(task, WorkerPool::APPEND);
}
}
return success;
}
......
......@@ -25,14 +25,16 @@
#include "src/net/isds_const.h"
#include "src/net/xml_layer.h"
#include "src/worker/pool.h" /* List with whole messages. */
#include "src/worker/task_download_message.h"
#include "src/worker/task_download_message_list.h"
#include "src/sqlite/message_db_container.h"
TaskDownloadMessageList::TaskDownloadMessageList(IsdsSession::IsdsContext &ctx,
NetLayer *netLayer, DbWrapper *dbWrapper, enum Messages::MessageType msgDirect,
uint dmStatusFilter, uint dmOffset, uint dmLimit)
uint dmStatusFilter, uint dmOffset, uint dmLimit, WorkerPool *workPool,
MessageListModel *messageModel, AccountListModel *accountModel,
bool downloadCompleteMsgs, const QString &dbsLocation)
: m_result(DL_ERR),
m_msgIds(),
m_statusBarText(),
m_ctx(ctx),
m_netLayer(netLayer),
......@@ -40,7 +42,12 @@ TaskDownloadMessageList::TaskDownloadMessageList(IsdsSession::IsdsContext &ctx,
m_msgDirect(msgDirect),
m_dmStatusFilter(dmStatusFilter),
m_dmOffset(dmOffset),
m_dmLimit(dmLimit)
m_dmLimit(dmLimit),
m_workPool(workPool),
m_messageModel(messageModel),
m_accountModel(accountModel),
m_downloadCompleteMsgs(downloadCompleteMsgs),
m_dbsLocation(dbsLocation)
{
}
......@@ -74,8 +81,9 @@ void TaskDownloadMessageList::run(void)
logDebugLv1NL("%s", "-----------------------------------------------");
m_result = downloadMessageList(m_ctx, m_netLayer, m_dbWrapper,
m_msgDirect, m_dmStatusFilter, m_dmOffset, m_dmLimit, m_msgIds,
m_statusBarText);
m_msgDirect, m_dmStatusFilter, m_dmOffset, m_dmLimit,
m_workPool, m_messageModel, m_accountModel, m_downloadCompleteMsgs,
m_dbsLocation, m_statusBarText);
/* ### Worker task end. ### */
......@@ -86,7 +94,10 @@ void TaskDownloadMessageList::run(void)
enum TaskDownloadMessageList::Result TaskDownloadMessageList::downloadMessageList(
IsdsSession::IsdsContext &ctx, NetLayer *netLayer, DbWrapper *dbWrapper,
enum Messages::MessageType msgDirect, uint dmStatusFilter,
uint dmOffset, uint dmLimit, QList<qint64> &msgIds, QString &statusBarText)
uint dmOffset, uint dmLimit, WorkerPool *workPool,
MessageListModel *messageModel, AccountListModel *accountModel,
bool downloadCompleteMsgs, const QString &dbsLocation,
QString &statusBarText)
{
if (ctx.username.isEmpty()) {
Q_ASSERT(0);
......@@ -155,9 +166,41 @@ enum TaskDownloadMessageList::Result TaskDownloadMessageList::downloadMessageLis
}
}
/* Return message ID list for additional download of complete messages */
foreach (const Messages::Message &msg, messages) {
msgIds.append(msg.dmID);
/* Update message counters in the account list */
if (accountModel == Q_NULLPTR) {
qWarning("%s", "Cannot access account model.");
} else {
MessageDb *msgDb = globMessageDbsPtr->accessMessageDb(
dbsLocation, ctx.username,
AccountListModel::globAccounts[ctx.username].storeToDisk());
if (msgDb != Q_NULLPTR) {
if (msgDirect == Messages::TYPE_RECEIVED) {
accountModel->updateCounters(ctx.username,
msgDb->getCntOfNewMsgs(MessageDb::TYPE_RECEIVED),
msgDb->getMessageCount(MessageDb::TYPE_RECEIVED),
-1, -1);
} else {
accountModel->updateCounters(ctx.username,
-1, -1,
msgDb->getCntOfNewMsgs(MessageDb::TYPE_SENT),
msgDb->getMessageCount(MessageDb::TYPE_SENT));
}
}
}
/* Download complete messages (create and insert tasks to worker pool) */
if (downloadCompleteMsgs) {
if (messageModel == Q_NULLPTR) {
qWarning("%s", "Cannot access message model.");
}
foreach (const Messages::Message &msg, messages) {
TaskDownloadMessage *task;
task = new (std::nothrow) TaskDownloadMessage(ctx,
netLayer, dbWrapper, msg.dmID, msgDirect,
messageModel);
task->setAutoDelete(true);
workPool->assignLo(task, WorkerPool::APPEND);
}
}
return DL_SUCCESS;
......
......@@ -26,12 +26,16 @@
#include <QString>
#include "src/messages.h"
#include "src/models/accountmodel.h"
#include "src/models/messagemodel.h"
#include "src/net/isds_session.h"
#include "src/net/db_wrapper.h"
#include "src/net/net_layer.h"
#include "src/messages.h"
#include "src/worker/pool.h"
#include "src/worker/task.h"
/*!
* @brief Task describing download message list.
*/
......@@ -58,11 +62,18 @@ public:
* @param[in] dmStatusFilter Dowanlod message status filter.
* @param[in] dmOffset Message download offset.
* @param[in] dmLimit Message list length limit.
* @param[in] workPool Pointer to workpool (worker).
* @param[in] messageModel Pointer to message list.
* @param[in] accountModel Pointer to account list.
* @param[in] downloadCompleteMsgs Download complete messages.
* @param[in] dbsLocation Database loacation.
*/
explicit TaskDownloadMessageList(IsdsSession::IsdsContext &ctx,
NetLayer *netLayer, DbWrapper *dbWrapper,
enum Messages::MessageType msgDirect, uint dmStatusFilter,
uint dmOffset, uint dmLimit);
uint dmOffset, uint dmLimit, WorkerPool *workPool,
MessageListModel *messageModel, AccountListModel *accountModel,
bool downloadCompleteMsgs, const QString &dbsLocation);
/*!
* @brief Performs actual message list download.
......@@ -80,6 +91,11 @@ public:
* @param[in] dmStatusFilter Dowanlod message status filter.
* @param[in] dmOffset Message download offset.
* @param[in] dmLimit Message list length limit.
* @param[in] workPool Pointer to workpool (worker).
* @param[in] messageModel Pointer to message list.
* @param[in] accountModel Pointer to account list.
* @param[in] downloadCompleteMsgs Download complete messages.
* @param[in] dbsLocation Database loacation.
* @param[out] msgIds Message ID list (for download of complete messages).
* @param[out] statusBarText Text about new messages for status bar.
......@@ -89,11 +105,12 @@ public:
enum Result downloadMessageList(IsdsSession::IsdsContext &ctx,
NetLayer *netLayer, DbWrapper *dbWrapper,
enum Messages::MessageType msgDirect, uint dmStatusFilter,
uint dmOffset, uint dmLimit, QList<qint64> &msgIds,
uint dmOffset, uint dmLimit, WorkerPool *workPool,
MessageListModel *messageModel, AccountListModel *accountModel,
bool downloadCompleteMsgs, const QString &dbsLocation,
QString &statusBarText);
enum Result m_result; /*!< Return state. */
QList<qint64> m_msgIds; /*!< Return message ID list. */
QString m_statusBarText; /*!< Return text about new messages for status bar. */
private:
......@@ -110,6 +127,11 @@ private:
uint m_dmStatusFilter; /*!< Defines type of messages to be downloaded. */
uint m_dmOffset; /*!< Message download offset. */
uint m_dmLimit; /*!< List length limit. */
WorkerPool *m_workPool; /*!< Pointer to workpool (worker). */
MessageListModel *m_messageModel; /*!< Pointer to message list. */
AccountListModel *m_accountModel; /*!< Pointer to account list. */
bool m_downloadCompleteMsgs; /*!< Download complete messages. */
const QString m_dbsLocation; /*!< Database loacation. */
};
#endif /* _TASK_DOWNLOAD_MESSAGE_LIST_H_ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment