Skip to content

Commit

Permalink
Added "Nothing New" indicator after check for new packages with no ne…
Browse files Browse the repository at this point in the history
…w results
  • Loading branch information
Grumbel committed Aug 25, 2014
1 parent 9c5748c commit 7124036
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 12 deletions.
10 changes: 9 additions & 1 deletion src/addon/addon_manager.cpp
Expand Up @@ -79,7 +79,8 @@ AddonManager::AddonManager(const std::string& addon_directory,
m_repository_url("http://localhost:8000/index-0_4_0.nfo"),
m_ignored_addon_ids(ignored_addon_ids),
m_installed_addons(),
m_repository_addons()
m_repository_addons(),
m_has_been_updated(false)
{
PHYSFS_mkdir(m_addon_directory.c_str());

Expand Down Expand Up @@ -171,11 +172,18 @@ AddonManager::has_online_support() const
return true;
}

bool
AddonManager::has_been_updated() const
{
return m_has_been_updated;
}

void
AddonManager::check_online()
{
std::string addoninfos = m_downloader.download(m_repository_url);
m_repository_addons = parse_addon_infos(addoninfos);
m_has_been_updated = true;
}

void
Expand Down
3 changes: 3 additions & 0 deletions src/addon/addon_manager.hpp
Expand Up @@ -46,12 +46,15 @@ class AddonManager : public Currenton<AddonManager>
AddonList m_installed_addons;
AddonList m_repository_addons;

bool m_has_been_updated;

public:
AddonManager(const std::string& addon_directory,
std::vector<std::string>& enabled_addons_);
~AddonManager();

bool has_online_support() const;
bool has_been_updated() const;
void check_online();

std::vector<AddonId> get_repository_addons() const;
Expand Down
34 changes: 23 additions & 11 deletions src/supertux/menu/addon_menu.cpp
Expand Up @@ -110,7 +110,11 @@ AddonMenu::rebuild_menu()
add_hl();


if (!m_installed_addons.empty())
if (m_installed_addons.empty())
{
add_inactive(MNID_NOTHING_NEW, _("No Addons installed"));
}
else
{
int idx = 0;
for (const auto& addon_id : m_installed_addons)
Expand All @@ -120,20 +124,12 @@ AddonMenu::rebuild_menu()
add_toggle(MAKE_INSTALLED_MENU_ID(idx), text, addon.is_enabled());
idx += 1;
}

add_hl();
}

if (!m_addon_manager.has_online_support())
{
add_inactive(MNID_CHECK_ONLINE, std::string(_("Check Online (disabled)")));
}
else
{
add_entry(MNID_CHECK_ONLINE, std::string(_("Check Online")));
}
add_hl();

{
bool have_new_stuff = false;
int idx = 0;
for (const auto& addon_id : m_repository_addons)
{
Expand All @@ -155,16 +151,32 @@ AddonMenu::rebuild_menu()
<< std::endl;
std::string text = generate_menu_item_text(addon);
add_entry(MAKE_REPOSITORY_MENU_ID(idx), "Install " + text + " *NEW*");
have_new_stuff = true;
}
}
catch(const std::exception& err)
{
// addon is not installed
std::string text = generate_menu_item_text(addon);
add_entry(MAKE_REPOSITORY_MENU_ID(idx), "Install " + text);
have_new_stuff = true;
}
idx += 1;
}

if (!have_new_stuff && m_addon_manager.has_been_updated())
{
add_inactive(MNID_NOTHING_NEW, _("No new Addons found"));
}
}

if (!m_addon_manager.has_online_support())
{
add_inactive(MNID_CHECK_ONLINE, std::string(_("Check Online (disabled)")));
}
else
{
add_entry(MNID_CHECK_ONLINE, std::string(_("Check Online")));
}

add_hl();
Expand Down
1 change: 1 addition & 0 deletions src/supertux/menu/addon_menu.hpp
Expand Up @@ -27,6 +27,7 @@ class AddonMenu : public Menu
private:
enum {
MNID_CHECK_ONLINE,
MNID_NOTHING_NEW,
MNID_ADDON_LIST_START = 10
};

Expand Down

0 comments on commit 7124036

Please sign in to comment.