Adding a mutex to avoid gui problem in the addons_loading dialog and desactive the next and previous button (and some code cleanup)

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@5618 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
xapantu 2010-07-02 16:54:08 +00:00
parent 088efbb96a
commit 079a25cbd8
4 changed files with 47 additions and 28 deletions

View File

@ -31,7 +31,7 @@ void download(std::string file, std::string save)
{
CURL *session = curl_easy_init();
std::cout << "Downloading: " << std::string(UserConfigParams::m_server_addons.toString() + "/" + file) << std::endl;
curl_easy_setopt(session, CURLOPT_URL, std::string(UserConfigParams::m_server_addons.toString() + "/" + file).c_str());
/*curl_easy_setopt(session, CURLOPT_URL, std::string(UserConfigParams::m_server_addons.toString() + "/" + file).c_str());
FILE * fp;
if(save != "")
fp = fopen(std::string(file_manager->getConfigDir() + std::string("/") + save).c_str(), "w");
@ -41,7 +41,7 @@ void download(std::string file, std::string save)
curl_easy_setopt(session, CURLOPT_WRITEFUNCTION, fwrite);
curl_easy_perform(session);
fclose(fp);
curl_easy_cleanup(session);
curl_easy_cleanup(session);*/
std::cout << UserConfigParams::m_server_addons.toString() << std::endl;
}

View File

@ -92,7 +92,7 @@ void AddonsScreen::loadList()
this->addons->GetName().c_str(), 1 /* icon */);
}
//remove the text from the widget : "Updating list..." (see l164)
//remove the text from the widget : "Updating list..."
m_update_status->setText("");
this->can_load_list = false;
}

View File

@ -41,8 +41,8 @@ AddonsLoading::AddonsLoading(Addons * id, const float w, const float h) :
ModalDialog(w, h)
{
this->addons = id;
m_can_install = false;
pthread_mutex_init(&mutex_can_install, NULL);
core::rect< s32 > area_right(10, 0, m_area.getWidth()/2, m_area.getHeight());
core::rect< s32 > area_left(m_area.getWidth()/2 + 20, 0, m_area.getWidth(), m_area.getHeight());
@ -50,27 +50,27 @@ AddonsLoading::AddonsLoading(Addons * id, const float w, const float h) :
icon = new IconButtonWidget(IconButtonWidget::SCALE_MODE_KEEP_CUSTOM_ASPECT_RATIO, false, /*focusbale*/ false);
/* Next and previous button*/
IconButtonWidget * next_previous = new IconButtonWidget();
next_previous->setImage("gui/next_addons.png");
next_previous->x = area_right.UpperLeftCorner.X + 100;
next_previous->y = area_right.UpperLeftCorner.Y +20 ;
next_previous->w = 75;
next_previous->m_properties[PROP_ID] = "next";
next_previous->h = 40;
next_previous->setParent(m_irrlicht_window);
m_children.push_back(next_previous);
next_previous->add();
m_next = new IconButtonWidget();
m_next->setImage("gui/next_addons.png");
m_next->x = area_right.UpperLeftCorner.X + 100;
m_next->y = area_right.UpperLeftCorner.Y +20 ;
m_next->w = 75;
m_next->m_properties[PROP_ID] = "next";
m_next->h = 40;
m_next->setParent(m_irrlicht_window);
m_children.push_back(m_next);
m_next->add();
next_previous = new IconButtonWidget();
next_previous->setImage("gui/back_addons.png");
next_previous->x = area_right.UpperLeftCorner.X + 20;
next_previous->y = area_right.UpperLeftCorner.Y +20 ;
next_previous->w = 75;
next_previous->m_properties[PROP_ID] = "previous";
next_previous->h = 40;
next_previous->setParent(m_irrlicht_window);
m_children.push_back(next_previous);
next_previous->add();
m_previous = new IconButtonWidget();
m_previous->setImage("gui/back_addons.png");
m_previous->x = area_right.UpperLeftCorner.X + 20;
m_previous->y = area_right.UpperLeftCorner.Y +20 ;
m_previous->w = 75;
m_previous->m_properties[PROP_ID] = "previous";
m_previous->h = 40;
m_previous->setParent(m_irrlicht_window);
m_children.push_back(m_previous);
m_previous->add();
name = new LabelWidget();
name->m_text = StringUtils::insertValues(_("Name: %i"), this->addons->GetName().c_str());
@ -184,12 +184,26 @@ GUIEngine::EventPropagation AddonsLoading::processEvent(const std::string& event
if(eventSource == "install")
{
m_back_button->setDeactivated();
m_next->setDeactivated();
m_previous->setDeactivated();
this->install_button->setDeactivated();
pthread_t thread;
pthread_create(&thread, NULL, &AddonsLoading::startInstall, this);
}
return GUIEngine::EVENT_LET;
}
// ------------------------------------------------------------------------------------------------------
void AddonsLoading::onUpdate(float delta)
{
pthread_mutex_lock(&(this->mutex_can_install));
if(m_can_install)
{
this->close();
}
pthread_mutex_unlock(&(mutex_can_install));
}
// ------------------------------------------------------------------------------------------------------
void AddonsLoading::close()
{
@ -199,7 +213,6 @@ void AddonsLoading::close()
((AddonsScreen*)curr_screen)->can_load_list = true;
pthread_mutex_unlock(&(((AddonsScreen*)curr_screen)->mutex));
dismiss();
std::cout << "unlock the mutex" << std::endl;
}
// ------------------------------------------------------------------------------------------------------
@ -215,7 +228,9 @@ void * AddonsLoading::startInstall(void* pthis)
{
obj->addons->Install();
}
obj->close();
pthread_mutex_lock(&(obj->mutex_can_install));
obj->m_can_install = true;
pthread_mutex_unlock(&(obj->mutex_can_install));
return NULL;
}
// ------------------------------------------------------------------------------------------------------

View File

@ -37,17 +37,21 @@ private:
GUIEngine::ButtonWidget * m_back_button;
GUIEngine::ButtonWidget * install_button;
GUIEngine::IconButtonWidget * icon;
GUIEngine::IconButtonWidget * m_next;
GUIEngine::IconButtonWidget * m_previous;
static void * startInstall(void*);
static void * downloadIcon(void*);
pthread_mutex_t mutex;
void loadInfo();
bool m_can_install;
public:
/**
* Creates a modal dialog with given percentage of screen width and height
*/
pthread_mutex_t mutex_can_install;
Addons * addons;
AddonsLoading(Addons * id, const float percentWidth, const float percentHeight);
GUIEngine::EventPropagation processEvent(const std::string& eventSource);
void onUpdate(float delta);
void close();
};