task_download_message_list.h 5.27 KB
Newer Older
1
/*
2
 * Copyright (C) 2014-2019 CZ.NIC
3 4 5 6 7 8 9 10 11 12 13 14
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
15
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 17 18 19 20 21 22 23
 *
 * In addition, as a special exception, the copyright holders give
 * permission to link the code of portions of this program with the
 * OpenSSL library under certain conditions as described in each
 * individual source file, and distribute linked combinations including
 * the two.
 */

24
#pragma once
25 26 27

#include <QString>

28
#include "src/datovka_shared/worker/pool.h"
29 30 31
#include "src/messages.h"
#include "src/models/accountmodel.h"
#include "src/models/messagemodel.h"
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
#include "src/net/isds_session.h"
#include "src/net/net_layer.h"
#include "src/worker/task.h"

/*!
 * @brief Task describing download message list.
 */
class TaskDownloadMessageList : public Task {
public:
	/*!
	 * @brief Return state describing what happened.
	 */
	enum Result {
		DL_SUCCESS, /*!< Operation was successful. */
		DL_ISDS_ERROR, /*!< Error communicating with ISDS. */
		DL_XML_ERROR, /*!< Error xml parse. */
		DL_DB_INS_ERR, /*!< Error inserting into database. */
		DL_ERR /*!< Other error. */
	};

	/*!
	 * @brief Constructor.
	 *
55 56 57 58 59 60 61 62 63 64 65 66 67
	 * @param[in] ctx Account isds context (include username).
	 * @param[in] netLayer Pointer to network manager.
	 * @param[in] msgDirect Received or sent message.
	 * @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[in] saveZfo Save ZFO to local storage.
	 * @param[in] isTestAccount True if account is ISDS testing.
68 69
	 */
	explicit TaskDownloadMessageList(IsdsSession::IsdsContext &ctx,
70
	    NetLayer *netLayer,
71
	    enum Messages::MessageType msgDirect, uint dmStatusFilter,
72 73
	    uint dmOffset, uint dmLimit, WorkerPool *workPool,
	    MessageListModel *messageModel, AccountListModel *accountModel,
74 75
	    bool downloadCompleteMsgs, const QString &dbsLocation,
	    bool saveZfo, bool isTestAccount);
76 77

	/*!
78
	 * @brief Performs actual message list download.
79 80 81 82 83 84 85
	 */
	virtual
	void run(void) Q_DECL_OVERRIDE;

	/*!
	 * @brief Download message list from ISDS for given account.
	 *
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
	 * @param[in] ctx Account isds context (include username).
	 * @param[in] netLayer Pointer to network manager.
	 * @param[in] msgDirect Received or sent message.
	 * @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[in] saveZfo Save ZFO to local storage.
	 * @param[in] isTestAccount True if account is ISDS testing.
	 * @param[out] msgIds Message ID list (for download of complete messages).
	 * @param[out] statusBarText Text about new messages for status bar.
101

102 103 104 105
	 * @return Error state.
	 */
	static
	enum Result downloadMessageList(IsdsSession::IsdsContext &ctx,
106
	    NetLayer *netLayer,
107
	    enum Messages::MessageType msgDirect, uint dmStatusFilter,
108 109 110
	    uint dmOffset, uint dmLimit, WorkerPool *workPool,
	    MessageListModel *messageModel, AccountListModel *accountModel,
	    bool downloadCompleteMsgs, const QString &dbsLocation,
111
	    bool saveZfo, bool isTestAccount, QString &statusBarText);
112 113

	enum Result m_result; /*!< Return state. */
114
	QString m_statusBarText; /*!< Return text about new messages for status bar. */
115 116 117 118 119 120 121 122 123 124 125 126 127 128

private:
	/*!
	 * Disable copy and assignment.
	 */
	TaskDownloadMessageList(const TaskDownloadMessageList &);
	TaskDownloadMessageList &operator=(const TaskDownloadMessageList &);

	IsdsSession::IsdsContext m_ctx; /*!< Account isds context. */
	NetLayer *m_netLayer; /*!< Pointer to network manager to send request. */
	enum Messages::MessageType m_msgDirect; /*!< Sent or received list. */
	uint m_dmStatusFilter; /*!< Defines type of messages to be downloaded. */
	uint m_dmOffset; /*!< Message download offset. */
	uint m_dmLimit; /*!< List length limit. */
129 130 131 132 133
	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. */
134 135
	bool m_saveZfo; /*!< Save ZFO to local storage. */
	bool m_isTestAccount; /*!< True if account is ISDS testing. */
136
};