Moved AddonProp into a separate class Addon with proper

getter; started to remove usage of m_index in addon_manager.


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@7185 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk
2010-12-29 21:52:33 +00:00
parent ad44673071
commit 141ae9f5da
11 changed files with 304 additions and 280 deletions

View File

@@ -12,10 +12,12 @@ supertuxkart_SOURCES = \
main.cpp \
main_loop.cpp \
main_loop.hpp \
addons/network_http.cpp \
addons/network_http.hpp \
addons/addon.cpp \
addons/addon.hpp \
addons/addons_manager.cpp \
addons/addons_manager.hpp \
addons/network_http.cpp \
addons/network_http.hpp \
addons/zip.cpp \
addons/zip.hpp \
animations/animation_base.hpp \

45
src/addons/addon.cpp Normal file
View File

@@ -0,0 +1,45 @@
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2010 Lucas Baudin, Joerg Henrichs
//
// 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
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
/**
\page addons Addons
*/
#ifdef ADDONS_MANAGER
#include "addons/addon.hpp"
#include "io/file_manager.hpp"
#include "io/xml_node.hpp"
Addon::Addon(const XMLNode &xml, bool installed)
{
m_installed = installed;
m_installed_version = 0;
m_name = "";
m_version = 0 ;
m_file = "";
m_description = "";
m_icon = "";
m_id = "";
m_type = xml.getName();
xml.get("name", &m_name );
xml.get("version", &m_version );
xml.get("file", &m_file );
xml.get("description", &m_description);
xml.get("icon", &m_icon );
xml.get("id", &m_id );
}; // Addon(const XML&)
#endif

89
src/addons/addon.hpp Executable file
View File

@@ -0,0 +1,89 @@
// $Id$
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2010 Lucas Baudin, Joerg Henrichs
//
// 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
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifdef ADDONS_MANAGER
#ifndef HEADER_ADDON_HPP
#define HEADER_ADDON_HPP
#include <sstream>
class XMLNode;
class Addon
{
public:
std::string m_name;
int m_version;
int m_installed_version;
std::string m_description;
std::string m_icon;
std::string m_file;
std::string m_id;
bool m_installed;
std::string m_type;
Addon() {};
/** Initialises the object from an XML node. */
Addon(const XMLNode &xml, bool installed=false);
// --------------------------------------------------------------------
/** Returns the name of the addon. */
const std::string& getName() const {return m_name; }
// --------------------------------------------------------------------
/** Returns the type of the addon. */
const std::string& getType() const {return m_type; }
// --------------------------------------------------------------------
/** Returns the name of the icon of this addon. */
const std::string& getIcon() const {return m_icon; }
// --------------------------------------------------------------------
/** Returns the name of the addon. */
const std::string& getDescription() const {return m_description; }
// --------------------------------------------------------------------
/** Returns if the addon is installed. */
bool isInstalled() const {return m_installed; }
// --------------------------------------------------------------------
/** Returns the installed version of an addon. */
int getInstalledVersion() const {return m_installed_version; }
// --------------------------------------------------------------------
/** Returns the latest version of this addon.
* m_version>m_installed_version if a newer version is available
* online. */
int getVersion() const {return m_version; }
// --------------------------------------------------------------------
/** Returns the version as string. */
std::string getVersionAsStr() const
{
std::ostringstream os;
os << m_version;
return os.str();
} // getVersionAsStr
// --------------------------------------------------------------------
/** Returns the ID of this addon. */
const std::string& getId() const {return m_id; }
// --------------------------------------------------------------------
/** True if this addon needs to be updated. */
bool needsUpdate() const
{
return getInstalledVersion() < getVersion();
}
// --------------------------------------------------------------------
}; // Addon
#endif
#endif

View File

@@ -87,13 +87,13 @@ void AddonsManager::initOnline()
const XMLNode *node = xml->getNode(i);
if(node->getName()=="track")
{
AddonsProp addons(*node);
m_addons_list.push_back(addons);
Addon addon(*node);
m_addons_list.push_back(addon);
}
else if(node->getName()=="kart")
{
AddonsProp addons(*node);
m_addons_list.push_back(addons);
Addon addon(*node);
m_addons_list.push_back(addon);
}
else
{
@@ -118,11 +118,6 @@ bool AddonsManager::onlineReady()
return m_state.get()==STATE_READY;
} // onlineReady
// ----------------------------------------------------------------------------
void AddonsManager::resetIndex()
{
m_index = -1;
}
// ----------------------------------------------------------------------------
void AddonsManager::loadInstalledAddons()
{
@@ -147,7 +142,8 @@ void AddonsManager::loadInstalledAddons()
node->get("id", &id );
node->get("name", &name );
node->get("version", &version);
if(selectId(id))
if(getAddon(id))
{
m_addons_list[m_index].m_installed = true;
m_addons_list[m_index].m_installed_version = version;
@@ -156,8 +152,8 @@ void AddonsManager::loadInstalledAddons()
}
else
{
AddonsProp addons(*xml, /* installed= */ true);
m_addons_list.push_back(addons);
Addon addon(*xml, /* installed= */ true);
m_addons_list.push_back(addon);
}
}
} // for i <= xml->getNumNodes()
@@ -166,63 +162,6 @@ void AddonsManager::loadInstalledAddons()
m_index = old_index;
} // loadInstalledAddons
// ----------------------------------------------------------------------------
bool AddonsManager::next()
{
if(m_index + 1 < (int)m_addons_list.size())
{
m_index ++;
return true;
}
m_index = -1;
return false;
} // next
// ----------------------------------------------------------------------------
bool AddonsManager::nextType(std::string type)
{
while(next())
{
if(m_addons_list[m_index].m_type == type)
return true;
}
while(next())
{
if(m_addons_list[m_index].m_type == type)
return false;
}
return false;
} // nextType
// ----------------------------------------------------------------------------
bool AddonsManager::previous()
{
if(m_index - 1 > 0)
{
m_index --;
return true;
}
m_index = m_addons_list.size() - 1;
return false;
} // previous
// ----------------------------------------------------------------------------
bool AddonsManager::previousType(std::string type)
{
while(previous())
{
if(m_addons_list[m_index].m_type == type)
return true;
}
while(previous())
{
if(m_addons_list[m_index].m_type == type)
return false;
}
return false;
} // previousType
// ----------------------------------------------------------------------------
bool AddonsManager::select(std::string name)
{
@@ -253,19 +192,28 @@ bool AddonsManager::selectId(std::string id)
} // selectId
// ----------------------------------------------------------------------------
/* FIXME : remove this function */
const AddonsManager::AddonsProp& AddonsManager::getAddons() const
/** Returns an addon with a given id. Raises an assertion if the id is not
* found!
* \param id The id to search for.
*/
const Addon* AddonsManager::getAddon(const std::string &id) const
{
return m_addons_list[m_index];
} // getAddons
int i = getAddonIndex(id);
return (i<0) ? NULL : &(m_addons_list[i]);
} // getAddon
// ----------------------------------------------------------------------------
std::string AddonsManager::getVersionAsStr() const
int AddonsManager::getAddonIndex(const std::string &id) const
{
std::ostringstream os;
os << m_addons_list[m_index].m_version;
return os.str();
} // getVersionAsStr
for(unsigned int i = 0; i < m_addons_list.size(); i++)
{
if(m_addons_list[i].getId()== id)
{
return i;
}
}
return -1;
} // getAddonIndex
// ----------------------------------------------------------------------------
std::string AddonsManager::getIdAsStr() const
@@ -406,10 +354,4 @@ const std::string& AddonsManager::getDownloadStateAsStr() const
return m_str_state;
} // getDownloadStateAsStr
// ----------------------------------------------------------------------------
bool AddonsManager::needUpdate() const
{
return getInstalledVersion() < getVersion();
} // needUpdate
#endif

View File

@@ -24,153 +24,87 @@
#include <map>
#include <vector>
#include "addons/addon.hpp"
#include "io/xml_node.hpp"
#include "utils/synchronised.hpp"
class AddonsManager
{
private:
std::vector<Addon> m_addons_list;
int m_index;
std::string m_file_installed;
void saveInstalled();
void loadInstalledAddons();
std::string m_type;
int m_download_state;
std::string m_str_state;
/** Which state the addons manager is:
* INIT: Waiting to download the list of addons.
* READY: List is downloaded, manager is ready.
* ERROR: Error downloading the list, no addons available. */
enum STATE_TYPE {STATE_INIT, STATE_READY, STATE_ERROR};
// Synchronise the state between threads (e.g. GUI and update thread)
Synchronised<STATE_TYPE> m_state;
public:
class AddonsProp
{
public:
std::string m_name;
int m_version;
int m_installed_version;
std::string m_description;
std::string m_icon;
std::string m_file;
std::string m_id;
bool m_installed;
std::string m_type;
AddonsProp() {};
/** Initialises the object from an XML node. */
AddonsProp(const XMLNode &xml, bool installed=false)
{
m_installed = installed;
m_installed_version = 0;
m_type = xml.getName();
m_name = ""; xml.get("name", &m_name );
m_version = 0 ; xml.get("version", &m_version );
m_file = ""; xml.get("file", &m_file );
m_description = ""; xml.get("description", &m_description);
m_icon = ""; xml.get("icon", &m_icon );
m_id = ""; xml.get("id", &m_id );
}; // AddonsProp(const XML&)
// --------------------------------------------------------------------
/** Returns the name of the addon. */
const std::string& getName() const {return m_name; }
// --------------------------------------------------------------------
/** Returns if the addon is installed. */
bool isInstalled() const {return m_installed; }
// --------------------------------------------------------------------
/** Returns the installed version of an addon. */
int getInstalledVersion() const {return m_installed_version; }
// --------------------------------------------------------------------
/** Returns the latest version of this addon.
* m_version>m_installed_version if a newer version is available
* online. */
int getVersion() const {return m_version; }
// --------------------------------------------------------------------
/** Returns the ID of this addon. */
const std::string& getId() const {return m_id; }
// --------------------------------------------------------------------
};
AddonsManager();
private:
std::vector<AddonsProp> m_addons_list;
int m_index;
std::string m_file_installed;
void saveInstalled();
void loadInstalledAddons();
std::string m_type;
int m_download_state;
std::string m_str_state;
void initOnline();
bool onlineReady();
/** Which state the addons manager is:
* INIT: Waiting to download the list of addons.
* READY: List is downloaded, manager is ready.
* ERROR: Error downloading the list, no addons available. */
enum STATE_TYPE {STATE_INIT, STATE_READY, STATE_ERROR};
// Synchronise the state between threads (e.g. GUI and update thread)
Synchronised<STATE_TYPE> m_state;
/** Returns the list of addons (installed and uninstalled). */
unsigned int getNumAddons() const { return m_addons_list.size(); }
public:
AddonsManager();
/** Returns the i-th addons. */
const Addon& getAddon(unsigned int i) { return m_addons_list[i];}
const Addon* getAddon(const std::string &id) const;
int getAddonIndex(const std::string &id) const;
void initOnline();
bool onlineReady();
/** Get all the selected addon parameters. */
const Addon &getAddons() const;
/** Returns the list of addons (installed and uninstalled). */
unsigned int getNumAddons() const { return m_addons_list.size(); }
/** Select an addon with it name. */
bool select(std::string);
/** Returns the i-th addons. */
const AddonsProp& getAddons(unsigned int i) { return m_addons_list[i];}
/** Select an addon with it id. */
bool selectId(std::string);
/** Select the next addons in the addons list. */
bool next();
/** Select the next addons in the addons list. */
bool previous();
/** Get the version of the selected addon as a string. */
std::string getVersionAsStr() const;
/** Get all the selected addon parameters. */
const AddonsProp &getAddons() const;
/** Get the installed version of the selected addon. */
int getInstalledVersion() const;
std::string getInstalledVersionAsStr() const;
/** Select an addon with it name. */
bool select(std::string);
/** Get the installed version of the selected addon. */
std::string getIdAsStr() const;
/** Select an addon with it id. */
bool selectId(std::string);
/** Get the description of the selected addons. */
const std::string &getDescription() const
{ return m_addons_list[m_index].m_description; };
/** Get the name of the selected addon. */
const std::string &getName() const
{ return m_addons_list[m_index].m_name; };
const std::string &getType() const
{ return m_addons_list[m_index].m_type; };
/** Install or upgrade the selected addon. */
void install();
/** Get the version of the selected addon. */
int getVersion() const { return m_addons_list[m_index].m_version; };
/** Uninstall the selected addon. This method will remove all the
* directory of the addon.*/
void uninstall();
/** Get the path of the addon icon. */
const std::string &getIcon() const
{ return m_addons_list[m_index].m_icon; };
/** Get the state of the addon: if it is installed or not.*/
bool isInstalled() const
{ return m_addons_list[m_index].m_installed; };
/** Get the version of the selected addon as a string. */
std::string getVersionAsStr() const;
int getDownloadState();
/** Get the installed version of the selected addon. */
int getInstalledVersion() const;
std::string getInstalledVersionAsStr() const;
/** Return a simple bool to know if the addon needs to be updated */
bool needUpdate() const;
/** Get the installed version of the selected addon. */
std::string getIdAsStr() const;
/** Get the description of the selected addons. */
const std::string &getDescription() const
{ return m_addons_list[m_index].m_description; };
const std::string &getType() const
{ return m_addons_list[m_index].m_type; };
/** Install or upgrade the selected addon. */
void install();
/** Uninstall the selected addon. This method will remove all the
* directory of the addon.*/
void uninstall();
void resetIndex();
/** Get the state of the addon: if it is installed or not.*/
bool isInstalled() const
{ return m_addons_list[m_index].m_installed; };
bool nextType(std::string type);
bool previousType(std::string type);
int getDownloadState();
/** Get the install state (if it is the download, unzip...)*/
const std::string& getDownloadStateAsStr() const;
/** Get the install state (if it is the download, unzip...)*/
const std::string& getDownloadStateAsStr() const;
};
extern AddonsManager *addons_manager;
#endif
#endif

View File

@@ -1106,6 +1106,10 @@
<Filter
Name="addons"
>
<File
RelativePath="..\..\addons\addon.cpp"
>
</File>
<File
RelativePath="..\..\addons\addons_manager.cpp"
>
@@ -2028,6 +2032,10 @@
<Filter
Name="addons"
>
<File
RelativePath="..\..\addons\addon.hpp"
>
</File>
<File
RelativePath="..\..\addons\addons_manager.hpp"
>

View File

@@ -61,7 +61,30 @@ void AddonsScreen::loadedFromFile()
m_icon_bank->addTextureAsSprite(icon3);
}
// ----------------------------------------------------------------------------
void AddonsScreen::loadList()
void AddonsScreen::init()
{
Screen::init();
getWidget<GUIEngine::RibbonWidget>("category")->setDeactivated();
m_type = "kart";
pthread_mutex_init(&m_mutex, NULL);
std::cout << "[Addons] Using directory <" + file_manager->getAddonsDir()
<< ">\n";
GUIEngine::ListWidget* w_list =
getWidget<GUIEngine::ListWidget>("list_addons");
w_list->setIcons(m_icon_bank);
//w_list->clear();
std::cout << "icon bank" << std::endl;
m_can_load_list = false;
getWidget<GUIEngine::LabelWidget>("update_status")
->setText(_("Updating the list..."));
pthread_t thread;
pthread_create(&thread, NULL, &AddonsScreen::downloadList, this);
}
// ----------------------------------------------------------------------------
void AddonsScreen::loadList(const std::string &type)
{
std::cout << "load list" << std::endl;
GUIEngine::ListWidget* w_list =
@@ -69,23 +92,22 @@ void AddonsScreen::loadList()
w_list->clear();
for(unsigned int i=0; i<addons_manager->getNumAddons(); i++)
{
const AddonsManager::AddonsProp &addons = addons_manager->getAddons(i);
std::cout << addons.getName()<< std::endl;
if(addons.isInstalled() &&
addons.getInstalledVersion() < addons.getVersion())
const Addon &addon = addons_manager->getAddon(i);
if(addon.getType()!=type) continue;
std::cout << addon.getName()<< std::endl;
if(addon.isInstalled() && addon.needsUpdate())
{
w_list->addItem(addons.getId(), addons.getName().c_str(),
w_list->addItem(addon.getId(), addon.getName().c_str(),
2 /* icon installed */);
}
else if(addons.isInstalled())
else if(addon.isInstalled())
{
w_list->addItem(addons.getId(),
addons_manager->getName().c_str(), 0 /* icon installed */);
w_list->addItem(addon.getId(), addon.getName().c_str(),
0 /* icon installed */);
}
else
{
w_list->addItem(addons.getId(), addons.getName().c_str(),
w_list->addItem(addon.getId(), addon.getName().c_str(),
1 /* icon unsinstalled*/);
}
}
@@ -116,8 +138,7 @@ void AddonsScreen::eventCallback(GUIEngine::Widget* widget,
getWidget<GUIEngine::ListWidget>("list_addons");
std::string addons = list->getSelectionInternalName();
addons_manager->selectId(addons);
m_load = new AddonsLoading(0.8f, 0.8f);
m_load = new AddonsLoading(0.8f, 0.8f, addons);
}
if (name == "category")
{
@@ -129,12 +150,12 @@ void AddonsScreen::eventCallback(GUIEngine::Widget* widget,
else if (selection == "tab_track")
{
m_type = "track";
loadList();
loadList("track");
}
else if (selection == "tab_kart")
{
m_type = "kart";
loadList();
loadList("kart");
}
}
}
@@ -146,34 +167,11 @@ void AddonsScreen::onUpdate(float delta, irr::video::IVideoDriver* driver)
pthread_mutex_lock(&m_mutex);
if(m_can_load_list)
{
loadList();
loadList(m_type);
}
pthread_mutex_unlock(&m_mutex);
}
// ----------------------------------------------------------------------------
void AddonsScreen::init()
{
Screen::init();
getWidget<GUIEngine::RibbonWidget>("category")->setDeactivated();
m_type = "kart";
pthread_mutex_init(&m_mutex, NULL);
std::cout << "[Addons] Using directory <" + file_manager->getAddonsDir()
<< ">\n";
GUIEngine::ListWidget* w_list =
getWidget<GUIEngine::ListWidget>("list_addons");
w_list->setIcons(m_icon_bank);
//w_list->clear();
std::cout << "icon bank" << std::endl;
m_can_load_list = false;
getWidget<GUIEngine::LabelWidget>("update_status")
->setText(_("Updating the list..."));
pthread_t thread;
pthread_create(&thread, NULL, &AddonsScreen::downloadList, this);
}
// ----------------------------------------------------------------------------

View File

@@ -59,7 +59,7 @@ public:
std::string m_type;
/** Load the addons into the main list.*/
void loadList();
void loadList(const std::string &type);
/** \brief implement callback from parent class GUIEngine::Screen */
virtual void loadedFromFile();

View File

@@ -61,8 +61,7 @@ void AddonsUpdateScreen::eventCallback(GUIEngine::Widget* widget,
GUIEngine::ListWidget* list = getWidget<GUIEngine::ListWidget>("list_addons");
std::string addons = list->getSelectionInternalName();
addons_manager->selectId(addons);
m_load = new AddonsLoading(0.8f, 0.8f);
m_load = new AddonsLoading(0.8f, 0.8f, addons);
}
else if (name == "category")
{
@@ -73,13 +72,13 @@ void AddonsUpdateScreen::eventCallback(GUIEngine::Widget* widget,
{
StateManager::get()->replaceTopMostScreen(AddonsScreen::getInstance());
AddonsScreen::getInstance()->m_type = "track";
AddonsScreen::getInstance()->loadList();
AddonsScreen::getInstance()->loadList("track");
}
else if (selection == "tab_kart")
{
StateManager::get()->replaceTopMostScreen(AddonsScreen::getInstance());
AddonsScreen::getInstance()->m_type = "kart";
AddonsScreen::getInstance()->loadList();
AddonsScreen::getInstance()->loadList("kart");
}
}
}
@@ -93,18 +92,16 @@ void AddonsUpdateScreen::init()
GUIEngine::ListWidget* w_list = this->getWidget<GUIEngine::ListWidget>("list_addons");
w_list->clear();
addons_manager->resetIndex();
//w_list->addItem("kart", _("Karts:"), -1 /* no icon */);
while(addons_manager->next())
for(unsigned int i=0; i<addons_manager->getNumAddons(); i++)
{
if(addons_manager->isInstalled() &&
addons_manager->getInstalledVersion() < addons_manager->getVersion())
const Addon &addon = addons_manager->getAddon(i);
if(addon.isInstalled() && addon.needsUpdate())
{
std::cout << addons_manager->getName() << std::endl;
w_list->addItem(addons_manager->getIdAsStr(),
addons_manager->getName().c_str(), 0);
std::cout << addon.getName() << std::endl;
w_list->addItem(addon.getId(), addon.getName().c_str(), 0);
}
}
} // for i<getNumAddons
}
#endif

View File

@@ -35,11 +35,13 @@
using namespace GUIEngine;
using namespace irr::gui;
// ------------------------------------------------------------------------------------------------------
AddonsLoading::AddonsLoading(const float w, const float h)
// ----------------------------------------------------------------------------
AddonsLoading::AddonsLoading(const float w, const float h,
const std::string &addon_name)
: ModalDialog(w, h)
{
m_addon = *(addons_manager->getAddon(addon_name));
loadFromFile("addons_view_dialog.stkgui");
m_can_install = false;
m_can_load_icon = false;
@@ -52,9 +54,9 @@ AddonsLoading::AddonsLoading(const float w, const float h)
m_description = getWidget<LabelWidget>("description");
m_version = getWidget<LabelWidget>("version");
if(addons_manager->isInstalled())
if(m_addon.isInstalled())
{
if(addons_manager->getInstalledVersion() < addons_manager->getVersion())
if(m_addon.needsUpdate())
getWidget<ButtonWidget>("install")->setLabel(_("Update"));
else
getWidget<ButtonWidget>("install")->setLabel(_("Uninstall"));
@@ -62,14 +64,16 @@ AddonsLoading::AddonsLoading(const float w, const float h)
loadInfo();
}
// ----------------------------------------------------------------------------
void AddonsLoading::loadInfo()
{
m_name->setText(StringUtils::insertValues(_("Name: %i"),
addons_manager->getName().c_str()));
m_addon.getName().c_str()));
m_description->setText(StringUtils::insertValues(_("Description: %i"),
addons_manager->getDescription().c_str()));
m_addon.getDescription().c_str()));
m_version->setText(StringUtils::insertValues(_("Version: %i"),
addons_manager->getVersionAsStr().c_str()));
m_addon.getVersionAsStr().c_str()));
pthread_t thread;
pthread_create(&thread, NULL, &AddonsLoading::downloadIcon, this);
}
@@ -79,8 +83,8 @@ void * AddonsLoading::downloadIcon( void * pthis)
{
AddonsLoading * pt = (AddonsLoading*)pthis;
std::string iconPath = "icon/" + addons_manager->getIcon();
network_http->downloadFileAsynchron(iconPath, addons_manager->getName() + ".png");
std::string iconPath = "icon/" + pt->m_addon.getIcon();
network_http->downloadFileAsynchron(iconPath, pt->m_addon.getName() + ".png");
// FIXME if (network_http->downloadFile(iconPath, addons_manager->getName() + ".png"))
{
pthread_mutex_lock(&(pt->m_mutex_can_install));
@@ -106,12 +110,14 @@ GUIEngine::EventPropagation AddonsLoading::processEvent(const std::string& event
}
else if(eventSource == "next")
{
addons_manager->nextType(addons_manager->getType());
// addons_manager->nextType(addons_manager->getType());
assert(false);
loadInfo();
}
else if(eventSource == "previous")
{
addons_manager->previousType(addons_manager->getType());
// FIXME: addons_manager->previousType(addons_manager->getType());
assert(false);
loadInfo();
}
if(eventSource == "install")
@@ -169,7 +175,7 @@ void AddonsLoading::onUpdate(float delta)
if(m_can_load_icon)
{
m_icon->setImage( (file_manager->getConfigDir() + "/"
+ addons_manager->getName() + ".png").c_str(),
+ m_addon.getName() + ".png").c_str(),
IconButtonWidget::ICON_PATH_TYPE_ABSOLUTE);
}
pthread_mutex_unlock(&(m_mutex_can_install));
@@ -190,7 +196,7 @@ void AddonsLoading::close()
void * AddonsLoading::startInstall(void* pthis)
{
AddonsLoading * obj = (AddonsLoading*)pthis;
if(!addons_manager->isInstalled() || addons_manager->needUpdate())
if(!obj->m_addon.isInstalled() || obj->m_addon.needsUpdate())
{
addons_manager->install();
}

View File

@@ -21,7 +21,7 @@
#ifndef HEADER_ADDONS_LOADING_HPP
#define HEADER_ADDONS_LOADING_HPP
#include "addons/addon.hpp"
#include "addons/addons_manager.hpp"
#include "guiengine/widgets.hpp"
#include "guiengine/modaldialog.hpp"
@@ -43,6 +43,8 @@ private:
GUIEngine::IconButtonWidget *m_next;
GUIEngine::IconButtonWidget *m_previous;
/** The addon to load. */
Addon m_addon;
/**
* This function is called when the user click on 'Install', 'Uninstall', or
* 'Update'. It is started using a thread.
@@ -70,8 +72,9 @@ public:
* Creates a modal dialog with given percentage of screen width and height
*/
pthread_mutex_t m_mutex_can_install;
AddonsLoading(const float percentWidth, const float percentHeight);
GUIEngine::EventPropagation processEvent(const std::string& eventSource);
AddonsLoading(const float percent_width, const float percent_height,
const std::string &addon_name);
GUIEngine::EventPropagation processEvent(const std::string& event_source);
/** This function is called by the GUI, all the frame (or somthing like
* that). It checks the flags (m_can_install, m_can_load_icon and