From 0369cb5dc2e5dae4acdb0753c3b309ef874c96ae Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 20 May 2014 13:18:47 +0300 Subject: Move downloadstatus into separate file. --- src/net/download.cpp | 14 +++++++------- src/net/download.h | 15 +++------------ src/net/downloadstatus.h | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 19 deletions(-) create mode 100644 src/net/downloadstatus.h (limited to 'src/net') diff --git a/src/net/download.cpp b/src/net/download.cpp index 4a9cbf0ea..c61e42e0c 100644 --- a/src/net/download.cpp +++ b/src/net/download.cpp @@ -202,7 +202,7 @@ bool Download::start() logger->log1(DOWNLOAD_ERROR_MESSAGE_THREAD); if (mError) strcpy(mError, DOWNLOAD_ERROR_MESSAGE_THREAD); - mUpdateFunction(mPtr, DOWNLOAD_STATUS_THREAD_ERROR, 0, 0); + mUpdateFunction(mPtr, DownloadStatus::THREAD_ERROR, 0, 0); if (!mIgnoreError) return false; } @@ -239,12 +239,12 @@ int Download::downloadProgress(void *clientp, double dltotal, double dlnow, if (d->mOptions.cancel) { - return d->mUpdateFunction(d->mPtr, DOWNLOAD_STATUS_CANCELLED, + return d->mUpdateFunction(d->mPtr, DownloadStatus::CANCELLED, static_cast(dltotal), static_cast(dlnow)); } - return d->mUpdateFunction(d->mPtr, DOWNLOAD_STATUS_IDLE, + return d->mUpdateFunction(d->mPtr, DownloadStatus::IDLE, static_cast(dltotal), static_cast(dlnow)); } @@ -283,7 +283,7 @@ int Download::downloadThread(void *ptr) logger->log_r("selected url: %s", d->mUrl.c_str()); while (attempts < 3 && !complete && !d->mOptions.cancel) { - d->mUpdateFunction(d->mPtr, DOWNLOAD_STATUS_STARTING, 0, 0); + d->mUpdateFunction(d->mPtr, DownloadStatus::STARTING, 0, 0); if (d->mOptions.cancel) { @@ -372,7 +372,7 @@ int Download::downloadThread(void *ptr) if (d->mOptions.cancel) break; -// d->mUpdateFunction(d->mPtr, DOWNLOAD_STATUS_ERROR, 0, 0); +// d->mUpdateFunction(d->mPtr, DownloadStatus::ERROR, 0, 0); if (file) { @@ -495,11 +495,11 @@ int Download::downloadThread(void *ptr) } else if (!complete || attempts >= 3) { - d->mUpdateFunction(d->mPtr, DOWNLOAD_STATUS_ERROR, 0, 0); + d->mUpdateFunction(d->mPtr, DownloadStatus::ERROR, 0, 0); } else { - d->mUpdateFunction(d->mPtr, DOWNLOAD_STATUS_COMPLETE, 0, 0); + d->mUpdateFunction(d->mPtr, DownloadStatus::COMPLETE, 0, 0); } return 0; diff --git a/src/net/download.h b/src/net/download.h index bc12a8f7c..0d2997b22 100644 --- a/src/net/download.h +++ b/src/net/download.h @@ -19,26 +19,17 @@ * along with this program. If not, see . */ - #ifndef NET_DOWNLOAD_H #define NET_DOWNLOAD_H +#include "net/downloadstatus.h" + #include #include #include "localconsts.h" -enum DownloadStatus -{ - DOWNLOAD_STATUS_CANCELLED = -3, - DOWNLOAD_STATUS_THREAD_ERROR = -2, - DOWNLOAD_STATUS_ERROR = -1, - DOWNLOAD_STATUS_STARTING = 0, - DOWNLOAD_STATUS_IDLE, - DOWNLOAD_STATUS_COMPLETE -}; - -typedef int (*DownloadUpdate)(void *ptr, DownloadStatus status, +typedef int (*DownloadUpdate)(void *ptr, DownloadStatus::Type status, size_t total, size_t remaining); // Matches what CURL expects diff --git a/src/net/downloadstatus.h b/src/net/downloadstatus.h new file mode 100644 index 000000000..8c5066915 --- /dev/null +++ b/src/net/downloadstatus.h @@ -0,0 +1,38 @@ +/* + * The ManaPlus Client + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2014 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * 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 2 of the License, or + * 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 + * along with this program. If not, see . + */ + +#ifndef NET_DOWNLOADSTATUS_H +#define NET_DOWNLOADSTATUS_H + +namespace DownloadStatus +{ + enum Type + { + CANCELLED = -3, + THREAD_ERROR = -2, + ERROR = -1, + STARTING = 0, + IDLE, + COMPLETE + }; +} // namespace Net + +#endif // NET_DOWNLOADSTATUS_H -- cgit v1.2.3-70-g09d2