Started to add a 'reload' button to refresh the addons.
This is WIP, so best not to press this button. Maybe I should rename the button to read "Don't press" ;) git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@8702 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
13cc69246f
commit
cbd83c24f6
@ -1,6 +1,7 @@
|
||||
<stkgui>
|
||||
|
||||
<icon-button id="back" x="0" y="0" height="8%" icon="gui/back.png"/>
|
||||
<button id="reload" x="-1" y="0" height="5%" text="Reload" />
|
||||
|
||||
<div x="2%" y="2%" width="96%" height="96%" layout="vertical-row" >
|
||||
|
||||
|
@ -62,6 +62,8 @@ AddonsManager::AddonsManager() : m_addons_list(std::vector<Addon>() ),
|
||||
void AddonsManager::initOnline(const XMLNode *xml)
|
||||
{
|
||||
m_addons_list.lock();
|
||||
// Clear the list in case that a reinit is being done.
|
||||
m_addons_list.getData().clear();
|
||||
loadInstalledAddons();
|
||||
m_addons_list.unlock();
|
||||
|
||||
@ -133,11 +135,23 @@ void AddonsManager::initOnline(const XMLNode *xml)
|
||||
downloadIcons();
|
||||
} // initOnline
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Reinitialises the addon manager, which happens when the user selects
|
||||
* 'reload' in the addon manager.
|
||||
*/
|
||||
void AddonsManager::reInit()
|
||||
{
|
||||
m_addons_list.lock();
|
||||
m_addons_list.getData().clear();
|
||||
m_addons_list.unlock();
|
||||
m_state.setAtomic(STATE_INIT);
|
||||
} // reInit
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Download all necessary icons (i.e. icons that are either missing or have
|
||||
* been updated since they were downloaded).
|
||||
*/
|
||||
void *AddonsManager::downloadIcons()
|
||||
void AddonsManager::downloadIcons()
|
||||
{
|
||||
for(unsigned int i=0; i<m_addons_list.getData().size(); i++)
|
||||
{
|
||||
@ -168,7 +182,7 @@ void *AddonsManager::downloadIcons()
|
||||
m_addons_list.getData()[i].setIconReady();
|
||||
} // for i<m_addons_list.size()
|
||||
|
||||
return NULL;
|
||||
return;
|
||||
} // downloadIcons
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@ -52,7 +52,7 @@ private:
|
||||
|
||||
void saveInstalled(const std::string &type="");
|
||||
void loadInstalledAddons();
|
||||
void *downloadIcons();
|
||||
void downloadIcons();
|
||||
|
||||
public:
|
||||
AddonsManager();
|
||||
@ -64,7 +64,7 @@ public:
|
||||
int getAddonIndex(const std::string &id) const;
|
||||
bool install(const Addon &addon);
|
||||
bool uninstall(const Addon &addon);
|
||||
|
||||
void reInit();
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the list of addons (installed and uninstalled). */
|
||||
unsigned int getNumAddons() const { return m_addons_list.getData().size();}
|
||||
|
@ -175,6 +175,8 @@ void *NetworkHttp::mainLoop(void *obj)
|
||||
case Request::HC_QUIT: assert(false); break; // quit is checked already
|
||||
case Request::HC_INIT:
|
||||
status = me->init(); break;
|
||||
case Request::HC_REINIT:
|
||||
status = me->reInit();
|
||||
case Request::HC_DOWNLOAD_FILE:
|
||||
status = me->downloadFileInternal(me->m_current_request);
|
||||
break;
|
||||
@ -310,6 +312,44 @@ CURLcode NetworkHttp::init()
|
||||
#endif
|
||||
} // init
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
/** Reinitialises the network manager. This is triggered when the users
|
||||
* selects 'reload' in the addon manager screen. This function inserts
|
||||
* a high priority reinit request into the request queue.
|
||||
*/
|
||||
void NetworkHttp::insertReInit()
|
||||
{
|
||||
Request *request = new Request(Request::HC_REINIT, 9999,
|
||||
/*manage_memory*/true);
|
||||
|
||||
if(UserConfigParams::logAddons())
|
||||
printf("[addons] Inserting reInit request.\n");
|
||||
insertRequest(request);
|
||||
} // insertReInit
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Reinitialises the addons manager. This function is triggered when a
|
||||
* reInit request is handled. It removes all queued requests, deletes
|
||||
* the news.xml and addons.xml files, and trigges a reload of those files.
|
||||
*/
|
||||
CURLcode NetworkHttp::reInit()
|
||||
{
|
||||
m_all_requests.lock();
|
||||
m_all_requests.getData().clear();
|
||||
m_all_requests.unlock();
|
||||
|
||||
addons_manager->setErrorState(); FIXME
|
||||
std::string news_file = file_manager->getAddonsFile("news.xml");
|
||||
file_manager->removeFile(news_file);
|
||||
std::string addons_file = file_manager->getAddonsFile("addons.xml");
|
||||
file_manager->removeFile(addons_file);
|
||||
if(UserConfigParams::logAddons())
|
||||
printf("[addons] Xml files deleted, re-initialising addon manager.\n");
|
||||
|
||||
return init();
|
||||
|
||||
} // reInit
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Checks the last modified date and if necessary updates the
|
||||
* list of addons.
|
||||
|
@ -73,11 +73,13 @@ private:
|
||||
static int progressDownload(void *clientp, double dltotal, double dlnow,
|
||||
double ultotal, double ulnow);
|
||||
void insertRequest(Request *request);
|
||||
CURLcode reInit();
|
||||
public:
|
||||
NetworkHttp();
|
||||
~NetworkHttp();
|
||||
void startNetworkThread();
|
||||
void stopNetworkThread();
|
||||
void insertReInit();
|
||||
Request *downloadFileAsynchron(const std::string &url,
|
||||
const std::string &save = "",
|
||||
int priority = 1,
|
||||
|
@ -87,6 +87,11 @@ void NewsManager::checkRedirect(const XMLNode *xml)
|
||||
*/
|
||||
void NewsManager::updateNews(const XMLNode *xml, const std::string &filename)
|
||||
{
|
||||
// This function is also called in case of a reinit, so
|
||||
// we have to delete existing news messages here first.
|
||||
m_news.lock();
|
||||
m_news.getData().clear();
|
||||
m_news.unlock();
|
||||
bool error = true;
|
||||
int frequency=0;
|
||||
if(xml->get("frequency", &frequency))
|
||||
|
@ -36,8 +36,8 @@ public:
|
||||
*/
|
||||
enum HttpCommands {HC_QUIT,
|
||||
HC_INIT,
|
||||
HC_DOWNLOAD_FILE,
|
||||
HC_NEWS };
|
||||
HC_REINIT,
|
||||
HC_DOWNLOAD_FILE };
|
||||
|
||||
private:
|
||||
/** The progress indicator. 0 till it is started and the first
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include <sstream>
|
||||
|
||||
#include "addons/addons_manager.hpp"
|
||||
#include "addons/network_http.hpp"
|
||||
#include "guiengine/widget.hpp"
|
||||
#include "guiengine/widgets/ribbon_widget.hpp"
|
||||
#include "guiengine/CGUISpriteBank.h"
|
||||
@ -167,6 +168,12 @@ void AddonsScreen::eventCallback(GUIEngine::Widget* widget,
|
||||
StateManager::get()->escapePressed();
|
||||
}
|
||||
|
||||
else if (name == "reload")
|
||||
{
|
||||
network_http->insertReInit();
|
||||
StateManager::get()->escapePressed();
|
||||
}
|
||||
|
||||
else if (name == "list_addons")
|
||||
{
|
||||
GUIEngine::ListWidget* list =
|
||||
|
Loading…
Reference in New Issue
Block a user