Allow uninstalling addons that have upgrades available
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@10477 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
d0c303c064
commit
2786dbe353
@ -18,15 +18,21 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<bubble word_wrap="true" id="description" height="100%" width="90%" proportion="6" align="center" />
|
||||
<bubble word_wrap="true" id="description" height="100%" width="90%" proportion="5" align="center" />
|
||||
|
||||
<div width="90%" proportion="2" align="center">
|
||||
<button id="install" x="0" y="0" width="100%" height="100%" I18N="Addons" text="Install"/>
|
||||
<progressbar id="progress" x="0" y="20%" width="100%" height="60%" />
|
||||
<div width="80%" proportion="5" align="center">
|
||||
<buttonbar id="actions" x="0" y="0" height="100%" width="100%" align="center">
|
||||
<icon-button id="install" width="128" height="128"
|
||||
icon="gui/package-update.png"
|
||||
I18N="Add-on screen action" text="Install"/>
|
||||
<icon-button id="uninstall" width="128" height="128"
|
||||
icon="gui/package-uninstall.png"
|
||||
I18N="Add-on screen action" text="Uninstall"/>
|
||||
<icon-button id="back" width="128" height="128"
|
||||
icon="gui/back.png"
|
||||
I18N="Add-ons screen action" text="Back"/>
|
||||
</buttonbar>
|
||||
<progressbar id="progress" x="0" y="20%" width="100%" height="30%" />
|
||||
</div>
|
||||
|
||||
<spacer height="10" />
|
||||
|
||||
<button id="cancel" proportion="2" width="90%" I18N="Addons" text="Back" align="center"/>
|
||||
</div>
|
||||
</stkgui>
|
||||
|
BIN
data/gui/package-uninstall.png
Normal file
BIN
data/gui/package-uninstall.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
@ -419,6 +419,24 @@ void RibbonWidget::clearAllChildren()
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void RibbonWidget::removeChildNamed(const char* name)
|
||||
{
|
||||
// This method should only be called BEFORE a widget is added
|
||||
assert(m_element == NULL);
|
||||
|
||||
Widget* child;
|
||||
for_in (child, m_children)
|
||||
{
|
||||
if (child->m_properties[PROP_ID] == name)
|
||||
{
|
||||
m_children.erase(child);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void RibbonWidget::select(std::string item, const int mousePlayerID)
|
||||
{
|
||||
const int subbuttons_amount = m_children.size();
|
||||
|
@ -180,6 +180,12 @@ namespace GUIEngine
|
||||
*/
|
||||
void clearAllChildren();
|
||||
|
||||
/**
|
||||
* \brief clear one child from this ribbon
|
||||
* \pre this must be called before RibbonWidget::add, while the widget is not yet displayed
|
||||
*/
|
||||
void removeChildNamed(const char* name);
|
||||
|
||||
PtrVector<Widget>& getRibbonChildren() { return m_children; }
|
||||
};
|
||||
|
||||
|
@ -52,19 +52,12 @@ AddonsLoading::AddonsLoading(const float w, const float h,
|
||||
|
||||
m_icon = getWidget<IconButtonWidget> ("icon" );
|
||||
m_progress = getWidget<ProgressBarWidget>("progress");
|
||||
m_install_button = getWidget<ButtonWidget> ("install" );
|
||||
m_back_button = getWidget<ButtonWidget> ("cancel" );
|
||||
m_install_button = getWidget<IconButtonWidget> ("install" );
|
||||
m_back_button = getWidget<IconButtonWidget> ("back" );
|
||||
|
||||
if(m_progress)
|
||||
m_progress->setVisible(false);
|
||||
|
||||
if(m_addon.isInstalled())
|
||||
{
|
||||
if(m_addon.needsUpdate())
|
||||
getWidget<ButtonWidget>("install")->setLabel(_("Update"));
|
||||
else
|
||||
getWidget<ButtonWidget>("install")->setLabel(_("Uninstall"));
|
||||
} // if isInstalled
|
||||
} // AddonsLoading
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -84,8 +77,23 @@ void AddonsLoading::beforeAddingWidgets()
|
||||
/* Init the icon here to be able to load a single image*/
|
||||
m_icon = getWidget<IconButtonWidget> ("icon" );
|
||||
m_progress = getWidget<ProgressBarWidget>("progress");
|
||||
m_back_button = getWidget<ButtonWidget> ("cancel" );
|
||||
m_back_button = getWidget<IconButtonWidget> ("back" );
|
||||
|
||||
|
||||
RibbonWidget* r = getWidget<RibbonWidget>("actions");
|
||||
|
||||
if (m_addon.isInstalled())
|
||||
{
|
||||
if (m_addon.needsUpdate())
|
||||
getWidget<IconButtonWidget> ("install")->setText( _("Update") );
|
||||
else
|
||||
r->removeChildNamed("install");
|
||||
}
|
||||
else
|
||||
{
|
||||
r->removeChildNamed("uninstall");
|
||||
}
|
||||
|
||||
getWidget<LabelWidget>("name")->setText(m_addon.getName().c_str(), false);
|
||||
getWidget<BubbleWidget>("description")
|
||||
->setText(m_addon.getDescription().c_str());
|
||||
@ -159,6 +167,8 @@ void AddonsLoading::beforeAddingWidgets()
|
||||
getWidget<LabelWidget>("size")->setText(size, false);
|
||||
} // AddonsLoading
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void AddonsLoading::init()
|
||||
{
|
||||
GUIEngine::LabelWidget* flags = getWidget<LabelWidget>("flags");
|
||||
@ -180,7 +190,7 @@ void AddonsLoading::escapePressed()
|
||||
GUIEngine::EventPropagation
|
||||
AddonsLoading::processEvent(const std::string& event_source)
|
||||
{
|
||||
if(event_source == "cancel")
|
||||
if(event_source == "back")
|
||||
{
|
||||
// Cancel a download only if we are installing/upgrading one
|
||||
// (and not uninstalling an installed one):
|
||||
@ -207,13 +217,17 @@ GUIEngine::EventPropagation
|
||||
m_progress->setVisible(true);
|
||||
// Change the 'back' button into a 'cancel' button.
|
||||
m_back_button->setText(_("Cancel"));
|
||||
m_install_button->setVisible(false);
|
||||
|
||||
RibbonWidget* r = getWidget<RibbonWidget>("actions");
|
||||
r->setVisible(false);
|
||||
|
||||
startDownload();
|
||||
}
|
||||
else // uninstall
|
||||
{
|
||||
doInstall();
|
||||
}
|
||||
return GUIEngine::EVENT_BLOCK;
|
||||
}
|
||||
else if (event_source == "uninstall")
|
||||
{
|
||||
doUninstall();
|
||||
return GUIEngine::EVENT_BLOCK;
|
||||
}
|
||||
return GUIEngine::EVENT_LET;
|
||||
@ -275,36 +289,62 @@ void AddonsLoading::doInstall()
|
||||
delete m_download_request;
|
||||
m_download_request = NULL;
|
||||
bool error=false;
|
||||
if(!m_addon.isInstalled() || m_addon.needsUpdate())
|
||||
|
||||
assert(!m_addon.isInstalled() || m_addon.needsUpdate());
|
||||
error = !addons_manager->install(m_addon);
|
||||
if(error)
|
||||
{
|
||||
error = !addons_manager->install(m_addon);
|
||||
if(error)
|
||||
{
|
||||
core::stringw msg = StringUtils::insertValues(
|
||||
_("Problems installing the addon '%s'."),
|
||||
core::stringw(m_addon.getName().c_str()));
|
||||
m_back_button->setText(msg.c_str());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
error = !addons_manager->uninstall(m_addon);
|
||||
if(error)
|
||||
{
|
||||
printf("[addons]Directory '%s' can not be removed.\n",
|
||||
m_addon.getDataDir().c_str());
|
||||
printf("[addons]Please remove this directory manually.\n");
|
||||
core::stringw msg = StringUtils::insertValues(
|
||||
_("Problems removing the addon '%s'."),
|
||||
core::stringw(m_addon.getName().c_str()));
|
||||
m_back_button->setText(msg.c_str());
|
||||
}
|
||||
core::stringw msg = StringUtils::insertValues(
|
||||
_("Problems installing the addon '%s'."),
|
||||
core::stringw(m_addon.getName().c_str()));
|
||||
m_back_button->setText(msg.c_str());
|
||||
}
|
||||
|
||||
if(error)
|
||||
{
|
||||
m_progress->setVisible(false);
|
||||
m_install_button->setVisible(true);
|
||||
|
||||
RibbonWidget* r = getWidget<RibbonWidget>("actions");
|
||||
r->setVisible(true);
|
||||
|
||||
m_install_button->setText(_("Try again"));
|
||||
}
|
||||
else
|
||||
{
|
||||
// The list of the addon screen needs to be updated to correctly
|
||||
// display the newly (un)installed addon.
|
||||
AddonsScreen::getInstance()->loadList();
|
||||
dismiss();
|
||||
}
|
||||
} // doInstall
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void AddonsLoading::doUninstall()
|
||||
{
|
||||
delete m_download_request;
|
||||
m_download_request = NULL;
|
||||
bool error=false;
|
||||
|
||||
error = !addons_manager->uninstall(m_addon);
|
||||
if(error)
|
||||
{
|
||||
printf("[addons]Directory '%s' can not be removed.\n",
|
||||
m_addon.getDataDir().c_str());
|
||||
printf("[addons]Please remove this directory manually.\n");
|
||||
core::stringw msg = StringUtils::insertValues(
|
||||
_("Problems removing the addon '%s'."),
|
||||
core::stringw(m_addon.getName().c_str()));
|
||||
m_back_button->setText(msg.c_str());
|
||||
}
|
||||
|
||||
if(error)
|
||||
{
|
||||
m_progress->setVisible(false);
|
||||
|
||||
RibbonWidget* r = getWidget<RibbonWidget>("actions");
|
||||
r->setVisible(true);
|
||||
|
||||
m_install_button->setText(_("Try again"));
|
||||
}
|
||||
else
|
||||
|
@ -36,8 +36,8 @@ class AddonsLoading : public GUIEngine::ModalDialog
|
||||
private:
|
||||
GUIEngine::LabelWidget *m_state;
|
||||
GUIEngine::ProgressBarWidget *m_progress;
|
||||
GUIEngine::ButtonWidget *m_back_button;
|
||||
GUIEngine::ButtonWidget *m_install_button;
|
||||
GUIEngine::IconButtonWidget *m_back_button;
|
||||
GUIEngine::IconButtonWidget *m_install_button;
|
||||
|
||||
GUIEngine::IconButtonWidget *m_icon;
|
||||
|
||||
@ -45,7 +45,8 @@ private:
|
||||
Addon m_addon;
|
||||
void startDownload();
|
||||
void doInstall();
|
||||
|
||||
void doUninstall();
|
||||
|
||||
/** True if the icon is being displayed. */
|
||||
bool m_icon_shown;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user