CLOUD: Fix CloudIcon
It's not a Request again, but still it controls ConnMan's timer.
This commit is contained in:
parent
cec93e2c03
commit
45e83d06c2
4 changed files with 12 additions and 30 deletions
|
@ -34,13 +34,13 @@ const float CloudIcon::ALPHA_STEP = 0.03;
|
||||||
const float CloudIcon::ALPHA_MAX = 1;
|
const float CloudIcon::ALPHA_MAX = 1;
|
||||||
const float CloudIcon::ALPHA_MIN = 0.5;
|
const float CloudIcon::ALPHA_MIN = 0.5;
|
||||||
|
|
||||||
CloudIcon::CloudIcon(): Request(nullptr, nullptr), _wasVisible(false), _iconsInited(false), _currentAlpha(0), _alphaRising(true) {
|
CloudIcon::CloudIcon(): _wasVisible(false), _iconsInited(false), _currentAlpha(0), _alphaRising(true) {
|
||||||
initIcons();
|
initIcons();
|
||||||
}
|
}
|
||||||
|
|
||||||
CloudIcon::~CloudIcon() {}
|
CloudIcon::~CloudIcon() {}
|
||||||
|
|
||||||
void CloudIcon::draw() {
|
bool CloudIcon::draw() {
|
||||||
initIcons();
|
initIcons();
|
||||||
|
|
||||||
Cloud::Storage *storage = CloudMan.getCurrentStorage();
|
Cloud::Storage *storage = CloudMan.getCurrentStorage();
|
||||||
|
@ -71,7 +71,7 @@ void CloudIcon::draw() {
|
||||||
_currentAlpha -= 3 * ALPHA_STEP;
|
_currentAlpha -= 3 * ALPHA_STEP;
|
||||||
if (_currentAlpha <= 0) {
|
if (_currentAlpha <= 0) {
|
||||||
_currentAlpha = 0;
|
_currentAlpha = 0;
|
||||||
finish();
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,13 +84,8 @@ void CloudIcon::draw() {
|
||||||
g_system->copyRectToOSD(surface->getPixels(), surface->pitch, x, y, surface->w, surface->h);
|
g_system->copyRectToOSD(surface->getPixels(), surface->pitch, x, y, surface->w, surface->h);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void CloudIcon::handle() {}
|
return false;
|
||||||
|
|
||||||
void CloudIcon::restart() {
|
|
||||||
_currentAlpha = 0;
|
|
||||||
_alphaRising = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CloudIcon::initIcons() {
|
void CloudIcon::initIcons() {
|
||||||
|
|
|
@ -23,12 +23,11 @@
|
||||||
#ifndef BACKENDS_NETWORKING_CURL_CLOUDICON_H
|
#ifndef BACKENDS_NETWORKING_CURL_CLOUDICON_H
|
||||||
#define BACKENDS_NETWORKING_CURL_CLOUDICON_H
|
#define BACKENDS_NETWORKING_CURL_CLOUDICON_H
|
||||||
|
|
||||||
#include "backends/networking/curl/request.h"
|
|
||||||
#include "graphics/transparent_surface.h"
|
#include "graphics/transparent_surface.h"
|
||||||
|
|
||||||
namespace Networking {
|
namespace Networking {
|
||||||
|
|
||||||
class CloudIcon: public Request {
|
class CloudIcon {
|
||||||
static const float ALPHA_STEP, ALPHA_MAX, ALPHA_MIN;
|
static const float ALPHA_STEP, ALPHA_MAX, ALPHA_MIN;
|
||||||
|
|
||||||
bool _wasVisible, _iconsInited;
|
bool _wasVisible, _iconsInited;
|
||||||
|
@ -43,9 +42,8 @@ public:
|
||||||
CloudIcon();
|
CloudIcon();
|
||||||
~CloudIcon();
|
~CloudIcon();
|
||||||
|
|
||||||
void draw();
|
/** Returns true if ConnMan's timer could be stopped. */
|
||||||
virtual void handle();
|
bool draw();
|
||||||
virtual void restart();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // End of namespace Networking
|
} // End of namespace Networking
|
||||||
|
|
|
@ -37,7 +37,7 @@ DECLARE_SINGLETON(Networking::ConnectionManager);
|
||||||
|
|
||||||
namespace Networking {
|
namespace Networking {
|
||||||
|
|
||||||
ConnectionManager::ConnectionManager(): _multi(0), _timerStarted(false), _frame(0), _icon(nullptr) {
|
ConnectionManager::ConnectionManager(): _multi(0), _timerStarted(false), _frame(0) {
|
||||||
curl_global_init(CURL_GLOBAL_ALL);
|
curl_global_init(CURL_GLOBAL_ALL);
|
||||||
_multi = curl_multi_init();
|
_multi = curl_multi_init();
|
||||||
}
|
}
|
||||||
|
@ -84,10 +84,6 @@ void ConnectionManager::startTimer(int interval) {
|
||||||
} else {
|
} else {
|
||||||
warning("Failed to install Networking::ConnectionManager's timer");
|
warning("Failed to install Networking::ConnectionManager's timer");
|
||||||
}
|
}
|
||||||
if (_timerStarted && !_icon) {
|
|
||||||
_icon = new CloudIcon();
|
|
||||||
addRequest(_icon, new Common::Callback<ConnectionManager, Request *>(this, &ConnectionManager::cloudIconDeleted));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConnectionManager::stopTimer() {
|
void ConnectionManager::stopTimer() {
|
||||||
|
@ -95,7 +91,6 @@ void ConnectionManager::stopTimer() {
|
||||||
Common::TimerManager *manager = g_system->getTimerManager();
|
Common::TimerManager *manager = g_system->getTimerManager();
|
||||||
manager->removeTimerProc(connectionsThread);
|
manager->removeTimerProc(connectionsThread);
|
||||||
_timerStarted = false;
|
_timerStarted = false;
|
||||||
if (_icon) _icon->finish();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConnectionManager::handle() {
|
void ConnectionManager::handle() {
|
||||||
|
@ -104,10 +99,10 @@ void ConnectionManager::handle() {
|
||||||
++_frame;
|
++_frame;
|
||||||
if (_frame % CLOUD_PERIOD == 0) interateRequests();
|
if (_frame % CLOUD_PERIOD == 0) interateRequests();
|
||||||
if (_frame % CURL_PERIOD == 0) processTransfers();
|
if (_frame % CURL_PERIOD == 0) processTransfers();
|
||||||
_handleMutex.unlock();
|
|
||||||
|
|
||||||
//icon redrawing is doesn't require any mutex, but must be done after requests are iterated
|
if (_icon.draw() && _requests.empty())
|
||||||
if (_icon) _icon->draw();
|
stopTimer();
|
||||||
|
_handleMutex.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConnectionManager::interateRequests() {
|
void ConnectionManager::interateRequests() {
|
||||||
|
@ -129,7 +124,6 @@ void ConnectionManager::interateRequests() {
|
||||||
|
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
if (_requests.empty()) stopTimer();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConnectionManager::processTransfers() {
|
void ConnectionManager::processTransfers() {
|
||||||
|
@ -158,8 +152,4 @@ void ConnectionManager::processTransfers() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConnectionManager::cloudIconDeleted(Request *icon) {
|
|
||||||
if (_icon == icon) _icon = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // End of namespace Cloud
|
} // End of namespace Cloud
|
||||||
|
|
|
@ -79,7 +79,7 @@ class ConnectionManager : public Common::Singleton<ConnectionManager> {
|
||||||
bool _timerStarted;
|
bool _timerStarted;
|
||||||
Common::Array<RequestWithCallback> _requests;
|
Common::Array<RequestWithCallback> _requests;
|
||||||
Common::Mutex _handleMutex;
|
Common::Mutex _handleMutex;
|
||||||
CloudIcon *_icon;
|
CloudIcon _icon;
|
||||||
uint32 _frame;
|
uint32 _frame;
|
||||||
|
|
||||||
void startTimer(int interval = TIMER_INTERVAL);
|
void startTimer(int interval = TIMER_INTERVAL);
|
||||||
|
@ -87,7 +87,6 @@ class ConnectionManager : public Common::Singleton<ConnectionManager> {
|
||||||
void handle();
|
void handle();
|
||||||
void interateRequests();
|
void interateRequests();
|
||||||
void processTransfers();
|
void processTransfers();
|
||||||
void cloudIconDeleted(Request *icon);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ConnectionManager();
|
ConnectionManager();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue