summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-04-16 15:56:08 +0300
committerAndrei Karas <akaras@inbox.ru>2016-04-16 15:57:43 +0300
commite811e48760c7f9a22615f40a0b025d34b9f12eb0 (patch)
tree2d9d75f3d29a19a99b8529f5fc8cc4106b972507
parentfdbf478bdce6cdbad0a532621b2ef559a51b3daa (diff)
downloadmanaverse-e811e48760c7f9a22615f40a0b025d34b9f12eb0.tar.gz
manaverse-e811e48760c7f9a22615f40a0b025d34b9f12eb0.tar.bz2
manaverse-e811e48760c7f9a22615f40a0b025d34b9f12eb0.tar.xz
manaverse-e811e48760c7f9a22615f40a0b025d34b9f12eb0.zip
Move downloadstatus enum into separate file.
Also convert it to strong typed enum.
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/Makefile.am1
-rw-r--r--src/enums/gui/updatedownloadstatus.h42
-rw-r--r--src/gui/windows/updaterwindow.cpp70
-rw-r--r--src/gui/windows/updaterwindow.h17
5 files changed, 82 insertions, 49 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index a6c964f07..27adf202c 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1256,6 +1256,7 @@ SET(SRCS
enums/gui/progresscolorid.h
enums/gui/serverdialogdonwloadstatus.h
enums/gui/themecolorid.h
+ enums/gui/updatedownloadstatus.h
enums/gui/usercolorid.h
listeners/errorlistener.cpp
listeners/errorlistener.h
diff --git a/src/Makefile.am b/src/Makefile.am
index a8b7c604a..0d15388a6 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -110,6 +110,7 @@ SRC += events/actionevent.h \
enums/gui/progresscolorid.h \
enums/gui/serverdialogdonwloadstatus.h \
enums/gui/themecolorid.h \
+ enums/gui/updatedownloadstatus.h \
enums/gui/usercolorid.h \
listeners/errorlistener.cpp \
listeners/errorlistener.h \
diff --git a/src/enums/gui/updatedownloadstatus.h b/src/enums/gui/updatedownloadstatus.h
new file mode 100644
index 000000000..b45aec590
--- /dev/null
+++ b/src/enums/gui/updatedownloadstatus.h
@@ -0,0 +1,42 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2004-2009 The Mana World Development Team
+ * Copyright (C) 2009-2010 The Mana Developers
+ * Copyright (C) 2012-2016 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 <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef ENUMS_GUI_UPDATEDOWNLOADSTATUS_H
+#define ENUMS_GUI_UPDATEDOWNLOADSTATUS_H
+
+#include "enums/simpletypes/enumdefines.h"
+
+enumStart(UpdateDownloadStatus)
+{
+ UPDATE_ERROR = 0,
+ UPDATE_IDLE,
+ UPDATE_LIST,
+ UPDATE_COMPLETE,
+ UPDATE_NEWS,
+ UPDATE_RESOURCES,
+ UPDATE_PATCH,
+ UPDATE_LIST2,
+ UPDATE_RESOURCES2
+}
+enumEnd(UpdateDownloadStatus);
+
+#endif // ENUMS_GUI_UPDATEDOWNLOADSTATUS_H
diff --git a/src/gui/windows/updaterwindow.cpp b/src/gui/windows/updaterwindow.cpp
index 7d2e0c4f8..1a4359849 100644
--- a/src/gui/windows/updaterwindow.cpp
+++ b/src/gui/windows/updaterwindow.cpp
@@ -196,7 +196,7 @@ UpdaterWindow::UpdaterWindow(const std::string &restrict updateHost,
"browserbox.xml")),
mScrollArea(new ScrollArea(this, mBrowserBox,
true, "update_background.xml")),
- mDownloadStatus(UPDATE_NEWS),
+ mDownloadStatus(UpdateDownloadStatus::UPDATE_NEWS),
mDownloadedBytes(0),
mUpdateIndex(0),
mUpdateIndexOffset(0),
@@ -310,11 +310,11 @@ void UpdaterWindow::action(const ActionEvent &event)
// Register the user cancel
mUserCancel = true;
// Skip the updating process
- if (mDownloadStatus != UPDATE_COMPLETE)
+ if (mDownloadStatus != UpdateDownloadStatus::UPDATE_COMPLETE)
{
if (mDownload)
mDownload->cancel();
- mDownloadStatus = UPDATE_ERROR;
+ mDownloadStatus = UpdateDownloadStatus::UPDATE_ERROR;
}
}
else if (eventId == "play")
@@ -340,8 +340,8 @@ void UpdaterWindow::keyPressed(KeyEvent &event)
else if (actionId == InputAction::GUI_SELECT ||
actionId == InputAction::GUI_SELECT2)
{
- if (mDownloadStatus == UPDATE_COMPLETE ||
- mDownloadStatus == UPDATE_ERROR)
+ if (mDownloadStatus == UpdateDownloadStatus::UPDATE_COMPLETE ||
+ mDownloadStatus == UpdateDownloadStatus::UPDATE_ERROR)
{
action(ActionEvent(nullptr, mPlayButton->getActionEventId()));
}
@@ -503,17 +503,17 @@ int UpdaterWindow::updateProgress(void *ptr,
else if (status == DownloadStatus::Error ||
status == DownloadStatus::Cancelled)
{
- if (uw->mDownloadStatus == UPDATE_COMPLETE
- || uw->mDownloadStatus == UPDATE_NEWS)
+ if (uw->mDownloadStatus == UpdateDownloadStatus::UPDATE_COMPLETE ||
+ uw->mDownloadStatus == UpdateDownloadStatus::UPDATE_NEWS)
{ // ignoring error in last state (was UPDATE_PATCH)
- uw->mDownloadStatus = UPDATE_COMPLETE;
+ uw->mDownloadStatus = UpdateDownloadStatus::UPDATE_COMPLETE;
uw->mDownloadComplete = true;
free(uw->mMemoryBuffer);
uw->mMemoryBuffer = nullptr;
}
else
{
- uw->mDownloadStatus = UPDATE_ERROR;
+ uw->mDownloadStatus = UpdateDownloadStatus::UPDATE_ERROR;
}
}
@@ -536,9 +536,9 @@ int UpdaterWindow::updateProgress(void *ptr,
uw->setProgress(progress);
- if ((client->getState() != State::UPDATE
- && client->getState() != State::GAME)
- || uw->mDownloadStatus == UPDATE_ERROR)
+ if ((client->getState() != State::UPDATE &&
+ client->getState() != State::GAME) ||
+ uw->mDownloadStatus == UpdateDownloadStatus::UPDATE_ERROR)
{
// If the action was canceled return an error code to stop the mThread
return -1;
@@ -572,7 +572,7 @@ void UpdaterWindow::download()
mDownload->cancel();
delete mDownload;
}
- if (mDownloadStatus == UPDATE_PATCH)
+ if (mDownloadStatus == UpdateDownloadStatus::UPDATE_PATCH)
{
mDownload = new Net::Download(this,
branding.getStringValue("updateMirror1") + mCurrentFile,
@@ -593,8 +593,8 @@ void UpdaterWindow::download()
&updateProgress,
false, false, mValidateXml);
- if (mDownloadStatus == UPDATE_LIST2
- || mDownloadStatus == UPDATE_RESOURCES2)
+ if (mDownloadStatus == UpdateDownloadStatus::UPDATE_LIST2 ||
+ mDownloadStatus == UpdateDownloadStatus::UPDATE_RESOURCES2)
{
const std::string str = mUpdateServerPath + "/" + mCurrentFile;
mDownload->addMirror(updateServer3 + str);
@@ -618,7 +618,7 @@ void UpdaterWindow::download()
}
else
{
- if (mDownloadStatus == UPDATE_RESOURCES)
+ if (mDownloadStatus == UpdateDownloadStatus::UPDATE_RESOURCES)
{
mDownload->setFile(std::string(mUpdatesDir).append("/").append(
mCurrentFile), mCurrentChecksum);
@@ -630,7 +630,7 @@ void UpdaterWindow::download()
}
}
- if (mDownloadStatus != UPDATE_RESOURCES)
+ if (mDownloadStatus != UpdateDownloadStatus::UPDATE_RESOURCES)
mDownload->noCache();
setLabel(mCurrentFile + " (0%)");
@@ -839,7 +839,7 @@ void UpdaterWindow::logic()
switch (mDownloadStatus)
{
- case UPDATE_ERROR:
+ case UpdateDownloadStatus::UPDATE_ERROR:
mBrowserBox->addRow("");
// TRANSLATORS: update message
mBrowserBox->addRow(_("##1 The update process is incomplete."));
@@ -851,9 +851,9 @@ void UpdaterWindow::logic()
mBrowserBox->addRow(mDownload->getError());
mScrollArea->setVerticalScrollAmount(
mScrollArea->getVerticalMaxScroll());
- mDownloadStatus = UPDATE_COMPLETE;
+ mDownloadStatus = UpdateDownloadStatus::UPDATE_COMPLETE;
break;
- case UPDATE_NEWS:
+ case UpdateDownloadStatus::UPDATE_NEWS:
if (mDownloadComplete)
{
// Parse current memory buffer as news and dispose of the data
@@ -862,11 +862,11 @@ void UpdaterWindow::logic()
mValidateXml = true;
mCurrentFile = xmlUpdateFile;
mStoreInMemory = false;
- mDownloadStatus = UPDATE_LIST;
+ mDownloadStatus = UpdateDownloadStatus::UPDATE_LIST;
download(); // download() changes mDownloadComplete to false
}
break;
- case UPDATE_PATCH:
+ case UpdateDownloadStatus::UPDATE_PATCH:
if (mDownloadComplete)
{
// Parse current memory buffer as news and dispose of the data
@@ -877,12 +877,12 @@ void UpdaterWindow::logic()
mCurrentFile = xmlUpdateFile;
mValidateXml = true;
mStoreInMemory = false;
- mDownloadStatus = UPDATE_LIST2;
+ mDownloadStatus = UpdateDownloadStatus::UPDATE_LIST2;
download();
}
break;
- case UPDATE_LIST:
+ case UpdateDownloadStatus::UPDATE_LIST:
if (mDownloadComplete)
{
if (mCurrentFile == xmlUpdateFile)
@@ -902,7 +902,7 @@ void UpdaterWindow::logic()
mCurrentFile = txtUpdateFile;
mValidateXml = false;
mStoreInMemory = false;
- mDownloadStatus = UPDATE_LIST;
+ mDownloadStatus = UpdateDownloadStatus::UPDATE_LIST;
download();
break;
}
@@ -914,10 +914,10 @@ void UpdaterWindow::logic()
"/").append(txtUpdateFile));
}
mStoreInMemory = false;
- mDownloadStatus = UPDATE_RESOURCES;
+ mDownloadStatus = UpdateDownloadStatus::UPDATE_RESOURCES;
}
break;
- case UPDATE_RESOURCES:
+ case UpdateDownloadStatus::UPDATE_RESOURCES:
if (mDownloadComplete)
{
if (CAST_SIZE(mUpdateIndex) < mUpdateFiles.size())
@@ -960,19 +960,19 @@ void UpdaterWindow::logic()
// Download of updates completed
mCurrentFile = "latest.txt";
mStoreInMemory = true;
- mDownloadStatus = UPDATE_PATCH;
+ mDownloadStatus = UpdateDownloadStatus::UPDATE_PATCH;
mValidateXml = false;
download(); // download() changes
// mDownloadComplete to false
}
else
{
- mDownloadStatus = UPDATE_COMPLETE;
+ mDownloadStatus = UpdateDownloadStatus::UPDATE_COMPLETE;
}
}
}
break;
- case UPDATE_LIST2:
+ case UpdateDownloadStatus::UPDATE_LIST2:
if (mDownloadComplete)
{
if (mCurrentFile == xmlUpdateFile)
@@ -984,11 +984,11 @@ void UpdaterWindow::logic()
mUpdateIndex = 0;
mValidateXml = true;
mStoreInMemory = false;
- mDownloadStatus = UPDATE_RESOURCES2;
+ mDownloadStatus = UpdateDownloadStatus::UPDATE_RESOURCES2;
download();
}
break;
- case UPDATE_RESOURCES2:
+ case UpdateDownloadStatus::UPDATE_RESOURCES2:
if (mDownloadComplete)
{
mValidateXml = false;
@@ -1022,17 +1022,17 @@ void UpdaterWindow::logic()
else
{
mUpdatesDir = mUpdatesDirReal;
- mDownloadStatus = UPDATE_COMPLETE;
+ mDownloadStatus = UpdateDownloadStatus::UPDATE_COMPLETE;
}
}
break;
- case UPDATE_COMPLETE:
+ case UpdateDownloadStatus::UPDATE_COMPLETE:
mUpdatesDir = mUpdatesDirReal;
enable();
// TRANSLATORS: updater window label
setLabel(_("Completed"));
break;
- case UPDATE_IDLE:
+ case UpdateDownloadStatus::UPDATE_IDLE:
break;
default:
logger->log("UpdaterWindow::logic unknown status: "
diff --git a/src/gui/windows/updaterwindow.h b/src/gui/windows/updaterwindow.h
index 3bd8a5a6f..0d322dccf 100644
--- a/src/gui/windows/updaterwindow.h
+++ b/src/gui/windows/updaterwindow.h
@@ -23,6 +23,8 @@
#ifndef GUI_WINDOWS_UPDATERWINDOW_H
#define GUI_WINDOWS_UPDATERWINDOW_H
+#include "enums/gui/updatedownloadstatus.h"
+
#include "enums/net/downloadstatus.h"
#include "enums/net/updatetype.h"
@@ -170,19 +172,6 @@ class UpdaterWindow final : public Window,
static bool validateFile(const std::string &filePath,
const unsigned long hash) A_WARN_UNUSED;
- enum UpdateDownloadStatus
- {
- UPDATE_ERROR = 0,
- UPDATE_IDLE,
- UPDATE_LIST,
- UPDATE_COMPLETE,
- UPDATE_NEWS,
- UPDATE_RESOURCES,
- UPDATE_PATCH,
- UPDATE_LIST2,
- UPDATE_RESOURCES2
- };
-
/** The new progress value to be set in the logic method. */
float mDownloadProgress;
@@ -229,7 +218,7 @@ class UpdaterWindow final : public Window,
ScrollArea *mScrollArea A_NONNULLPOINTER;
/** Status of the current download. */
- UpdateDownloadStatus mDownloadStatus;
+ UpdateDownloadStatusT mDownloadStatus;
/** Byte count currently downloaded in mMemoryBuffer. */
int mDownloadedBytes;