Scrapper : Show error message when request failed.

GuiMsgBox : Support for icons
This commit is contained in:
Fabrice CARUSO
2019-09-12 10:55:04 +02:00
parent 69cc33d4d0
commit 07a4362e77
10 changed files with 306 additions and 16 deletions
@@ -283,10 +283,10 @@ void ScraperSearchComponent::onSearchDone(const std::vector<ScraperSearchResult>
void ScraperSearchComponent::onSearchError(const std::string& error)
{
LOG(LogInfo) << "ScraperSearchComponent search error: " << error;
mWindow->pushGui(new GuiMsgBox(mWindow, Utils::String::toUpper(error),
mWindow->pushGui(new GuiMsgBox(mWindow, _("AN ERROR HAS OCCURED") + " :\n" + Utils::String::toUpper(error),
_("RETRY"), std::bind(&ScraperSearchComponent::search, this, mLastSearch), // batocera
_("SKIP"), mSkipCallback, // batocera
_("CANCEL"), mCancelCallback)); // batocera
_("CANCEL"), mCancelCallback, ICON_ERROR)); // batocera
}
int ScraperSearchComponent::getSelectedIndex()
+1 -1
View File
@@ -92,7 +92,7 @@ void ScraperSearchHandle::update()
}
// we finished without any errors!
if(mRequestQueue.empty())
if(mRequestQueue.empty() && mStatus != ASYNC_ERROR)
{
setStatus(ASYNC_DONE);
return;
+7
View File
@@ -341,6 +341,13 @@ void Window::render()
bottom->render(transform);
if(bottom != top)
{
if (top->getValue() == "GuiMsgBox" && mGuiStack.size() > 2)
{
auto& middle = mGuiStack.at(mGuiStack.size()-2);
if (middle != bottom)
middle->render(transform);
}
mBackgroundOverlay->render(transform);
top->render(transform);
}
+1
View File
@@ -47,6 +47,7 @@ public:
void setGlowColor(unsigned int color) { mGlowColor = color; };
void setGlowSize(unsigned int size) { mGlowSize = size; };
void setPadding(const Vector4f padding) { mPadding = padding; }
protected:
virtual void onTextChanged();
+70 -9
View File
@@ -2,15 +2,28 @@
#include "components/ButtonComponent.h"
#include "components/MenuComponent.h"
#include "components/ImageComponent.h"
#include "resources/ResourceManager.h"
#include "LocaleES.h"
#define HORIZONTAL_PADDING_PX 20
#define HORIZONTAL_PADDING_PX (Renderer::getScreenWidth()*0.01)
GuiMsgBox::GuiMsgBox(Window* window, const std::string& text, const std::string& name1, const std::function<void()>& func1, GuiMsgBoxIcon icon)
: GuiMsgBox(window, text, name1, func1, "", nullptr, "", nullptr, icon) { }
GuiMsgBox::GuiMsgBox(Window* window, const std::string& text,
const std::string& name1, const std::function<void()>& func1,
const std::string& name2, const std::function<void()>& func2,
GuiMsgBoxIcon icon)
: GuiMsgBox(window, text, name1, func1, name2, func2, "", nullptr, icon) { }
GuiMsgBox::GuiMsgBox(Window* window, const std::string& text,
const std::string& name1, const std::function<void()>& func1,
const std::string& name2, const std::function<void()>& func2,
const std::string& name3, const std::function<void()>& func3) : GuiComponent(window),
mBackground(window, ":/frame.png"), mGrid(window, Vector2i(1, 2))
const std::string& name3, const std::function<void()>& func3,
GuiMsgBoxIcon icon) : GuiComponent(window),
mBackground(window, ":/frame.png"), mGrid(window, Vector2i(2, 2))
{
auto theme = ThemeData::getMenuTheme();
mBackground.setImagePath(theme->Background.path);
@@ -19,9 +32,54 @@ GuiMsgBox::GuiMsgBox(Window* window, const std::string& text,
float width = Renderer::getScreenWidth() * 0.6f; // max width
float minWidth = Renderer::getScreenWidth() * 0.3f; // minimum width
mImage = nullptr;
mMsg = std::make_shared<TextComponent>(mWindow, text, ThemeData::getMenuTheme()->Text.font, ThemeData::getMenuTheme()->Text.color, ALIGN_CENTER);
mGrid.setEntry(mMsg, Vector2i(0, 0), false, false);
std::string imageFile;
switch (icon)
{
case ICON_INFORMATION:
imageFile = ":/info.svg";
break;
case ICON_QUESTION:
imageFile = ":/question.svg";
break;
case ICON_WARNING:
imageFile = ":/warning.svg";
break;
case ICON_ERROR:
imageFile = ":/alert.svg";
break;
case ICON_AUTOMATIC:
if (text.rfind("?") != std::string::npos || name1 == _("YES"))
imageFile = ":/question.svg";
else if (name1 == _("OK"))
{
if (name2.empty())
imageFile = ":/info.svg";
else
imageFile = ":/question.svg";
}
break;
}
if (!imageFile.empty() && ResourceManager::getInstance()->fileExists(imageFile))
{
mImage = std::make_shared<ImageComponent>(window);
mImage->setImage(imageFile);
mImage->setColorShift(theme->Text.color);
mImage->setMaxSize(theme->Text.font->getLetterHeight() * 2.0f, theme->Text.font->getLetterHeight() * 2.0f);
mGrid.setEntry(mImage, Vector2i(0, 0), false, false);
}
mMsg = std::make_shared<TextComponent>(mWindow, text, ThemeData::getMenuTheme()->Text.font, ThemeData::getMenuTheme()->Text.color, mImage == nullptr ? ALIGN_CENTER : ALIGN_LEFT); // CENTER
mMsg->setPadding(Vector4f(Renderer::getScreenWidth()*0.015f, 0, Renderer::getScreenWidth()*0.015f, 0));
mGrid.setEntry(mMsg, Vector2i(mImage == nullptr ? 0 : 1, 0), false, false, Vector2i(mImage == nullptr ? 2 : 1, 1));
// create the buttons
mButtons.push_back(std::make_shared<ButtonComponent>(mWindow, name1, name1, std::bind(&GuiMsgBox::deleteMeAndCall, this, func1)));
@@ -47,7 +105,7 @@ GuiMsgBox::GuiMsgBox(Window* window, const std::string& text,
// put the buttons into a ComponentGrid
mButtonGrid = makeButtonGrid(mWindow, mButtons);
mGrid.setEntry(mButtonGrid, Vector2i(0, 1), true, false, Vector2i(1, 1), GridFlags::BORDER_TOP);
mGrid.setEntry(mButtonGrid, Vector2i(0, 1), true, false, Vector2i(2, 1), GridFlags::BORDER_TOP);
// decide final width
if(mMsg->getSize().x() < width && mButtonGrid->getSize().x() < width)
@@ -56,7 +114,7 @@ GuiMsgBox::GuiMsgBox(Window* window, const std::string& text,
width = Math::max(mButtonGrid->getSize().x(), mMsg->getSize().x());
width = Math::max(width, minWidth);
}
// now that we know width, we can find height
mMsg->setSize(width, 0); // mMsg->getSize.y() now returns the proper length
const float msgHeight = Math::max(Font::get(FONT_SIZE_LARGE)->getHeight(), mMsg->getSize().y()*1.225f);
@@ -92,9 +150,12 @@ bool GuiMsgBox::input(InputConfig* config, Input input)
void GuiMsgBox::onSizeChanged()
{
mGrid.setSize(mSize);
if (mImage != nullptr)
mGrid.setColWidthPerc(0, (ThemeData::getMenuTheme()->Text.font->getLetterHeight() * 4.5f) / mSize.x());
mGrid.setRowHeightPerc(1, mButtonGrid->getSize().y() / mSize.y());
// update messagebox size
mMsg->setSize(mSize.x() - HORIZONTAL_PADDING_PX*2, mGrid.getRowHeight(0));
mGrid.onSizeChanged();
+28 -4
View File
@@ -8,26 +8,50 @@
class ButtonComponent;
class TextComponent;
class ImageComponent;
enum GuiMsgBoxIcon
{
ICON_AUTOMATIC,
ICON_INFORMATION,
ICON_QUESTION,
ICON_WARNING,
ICON_ERROR
};
class GuiMsgBox : public GuiComponent
{
public:
GuiMsgBox(Window* window, const std::string& text,
const std::string& name1, const std::function<void()>& func1,
const std::string& name2, const std::function<void()>& func2,
const std::string& name3, const std::function<void()>& func3,
GuiMsgBoxIcon icon = ICON_AUTOMATIC);
GuiMsgBox(Window* window, const std::string& text,
const std::string& name1, const std::function<void()>& func1,
const std::string& name2, const std::function<void()>& func2,
GuiMsgBoxIcon icon = ICON_AUTOMATIC);
GuiMsgBox(Window* window, const std::string& text,
const std::string& name1 = "OK", const std::function<void()>& func1 = nullptr,
const std::string& name2 = "", const std::function<void()>& func2 = nullptr,
const std::string& name3 = "", const std::function<void()>& func3 = nullptr);
GuiMsgBoxIcon icon = ICON_AUTOMATIC);
bool input(InputConfig* config, Input input) override;
void onSizeChanged() override;
std::vector<HelpPrompt> getHelpPrompts() override;
std::string getValue() const override { return "GuiMsgBox"; }
private:
void deleteMeAndCall(const std::function<void()>& func);
NinePatchComponent mBackground;
ComponentGrid mGrid;
ComponentGrid mGrid;
std::shared_ptr<ImageComponent> mImage;
std::shared_ptr<TextComponent> mMsg;
std::vector< std::shared_ptr<ButtonComponent> > mButtons;
std::shared_ptr<ComponentGrid> mButtonGrid;
+47
View File
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- Generator: Adobe Illustrator 18.1.1, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 27.963 27.963" style="enable-background:new 0 0 27.963 27.963;" xml:space="preserve">
<g>
<g id="c129_exclamation">
<path fill="#fff" d="M13.983,0C6.261,0,0.001,6.259,0.001,13.979c0,7.724,6.26,13.984,13.982,13.984s13.98-6.261,13.98-13.984
C27.963,6.259,21.705,0,13.983,0z M13.983,26.531c-6.933,0-12.55-5.62-12.55-12.553c0-6.93,5.617-12.548,12.55-12.548
c6.931,0,12.549,5.618,12.549,12.548C26.531,20.911,20.913,26.531,13.983,26.531z"/>
<polygon fill="#fff" points="15.579,17.158 16.191,4.579 11.804,4.579 12.414,17.158 "/>
<path fill="#fff" d="M13.998,18.546c-1.471,0-2.5,1.029-2.5,2.526c0,1.443,0.999,2.528,2.444,2.528h0.056c1.499,0,2.469-1.085,2.469-2.528
C16.441,19.575,15.468,18.546,13.998,18.546z"/>
</g>
<g id="Capa_1_207_">
</g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.2 KiB

+51
View File
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- Generator: Adobe Illustrator 19.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 202.978 202.978" style="enable-background:new 0 0 202.978 202.978;" xml:space="preserve">
<g>
<g>
<g>
<g>
<path style="fill:#fff;" d="M100.942,0.001C44.9,0.304-0.297,45.98,0.006,102.031
c0.293,56.051,45.998,101.238,102.02,100.945c56.081-0.303,101.248-45.978,100.945-102.02
C202.659,44.886,157.013-0.292,100.942,0.001z M101.948,186.436c-46.916,0.234-85.108-37.576-85.372-84.492
c-0.244-46.907,37.537-85.157,84.453-85.411c46.926-0.254,85.167,37.596,85.421,84.483
C186.695,147.951,148.855,186.182,101.948,186.436z M116.984,145.899l-0.42-75.865l-39.149,0.254l0.078,16.6l10.63-0.059
l0.313,59.237l-11.275,0.039l0.088,15.857l49.134-0.264l-0.098-15.847L116.984,145.899z M102.065,58.837
c9.575-0.039,15.349-6.448,15.3-14.323c-0.254-8.07-5.882-14.225-15.095-14.186c-9.184,0.059-15.173,6.292-15.134,14.362
C87.185,52.555,93.028,58.906,102.065,58.837z"/>
</g>
</g>
</g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.3 KiB

+50
View File
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- Generator: Adobe Illustrator 18.1.1, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 473.733 473.733" style="enable-background:new 0 0 473.733 473.733;" xml:space="preserve">
<g>
<g>
<path fill="#fff" d="M231.2,336.033c-9.35,0-17,7.65-17,17v11.333c0,9.35,7.65,17,17,17s17-7.65,17-17v-11.333
C248.2,343.683,240.55,336.033,231.2,336.033z"/>
<path fill="#fff" d="M236.867,473.733c130.617,0,236.867-106.25,236.867-236.867S367.483,0,236.867,0S0,106.25,0,236.867
S106.25,473.733,236.867,473.733z M236.867,34c111.917,0,202.867,90.95,202.867,202.867s-90.95,202.867-202.867,202.867
S34,348.783,34,236.867S124.95,34,236.867,34z"/>
<path fill="#fff" d="M163.2,194.367C163.483,194.367,163.483,194.367,163.2,194.367c9.35,0,17-7.083,17-16.433c0,0,0.283-13.6,7.083-26.917
c8.5-17,23.517-25.5,45.617-25.5c20.683,0,35.983,5.667,44.483,16.717c7.083,9.067,9.067,21.533,5.667,35.133
c-4.25,16.717-18.7,31.167-32.583,45.333c-17,17.567-34.85,35.417-34.85,59.5c0,9.35,7.65,17,17,17s17-7.65,17-17
c0-10.2,12.183-22.667,25.217-35.7c16.15-16.433,34.567-35.133,41.083-60.633c6.233-23.517,1.983-47.033-11.617-64.317
c-10.483-13.6-31.45-30.033-71.117-30.033c-44.483,0-65.733,23.8-75.933,44.2c-10.2,20.4-10.767,39.95-10.767,42.217
C146.483,187,153.85,194.367,163.2,194.367z"/>
</g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.6 KiB

+49
View File
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- Generator: Adobe Illustrator 19.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 486.463 486.463" style="enable-background:new 0 0 486.463 486.463;" xml:space="preserve">
<g>
<g>
<path fill="#fff" d="M243.225,333.382c-13.6,0-25,11.4-25,25s11.4,25,25,25c13.1,0,25-11.4,24.4-24.4
C268.225,344.682,256.925,333.382,243.225,333.382z"/>
<path fill="#fff" d="M474.625,421.982c15.7-27.1,15.8-59.4,0.2-86.4l-156.6-271.2c-15.5-27.3-43.5-43.5-74.9-43.5s-59.4,16.3-74.9,43.4
l-156.8,271.5c-15.6,27.3-15.5,59.8,0.3,86.9c15.6,26.8,43.5,42.9,74.7,42.9h312.8
C430.725,465.582,458.825,449.282,474.625,421.982z M440.625,402.382c-8.7,15-24.1,23.9-41.3,23.9h-312.8
c-17,0-32.3-8.7-40.8-23.4c-8.6-14.9-8.7-32.7-0.1-47.7l156.8-271.4c8.5-14.9,23.7-23.7,40.9-23.7c17.1,0,32.4,8.9,40.9,23.8
l156.7,271.4C449.325,369.882,449.225,387.482,440.625,402.382z"/>
<path fill="#fff" d="M237.025,157.882c-11.9,3.4-19.3,14.2-19.3,27.3c0.6,7.9,1.1,15.9,1.7,23.8c1.7,30.1,3.4,59.6,5.1,89.7
c0.6,10.2,8.5,17.6,18.7,17.6c10.2,0,18.2-7.9,18.7-18.2c0-6.2,0-11.9,0.6-18.2c1.1-19.3,2.3-38.6,3.4-57.9
c0.6-12.5,1.7-25,2.3-37.5c0-4.5-0.6-8.5-2.3-12.5C260.825,160.782,248.925,155.082,237.025,157.882z"/>
</g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.5 KiB