#include <addon_menu.hpp>
Inherits Menu.
Public Member Functions | |
AddonMenu () | |
void | refresh () |
void | check_menu () |
Private Member Functions | |
AddonMenu (const AddonMenu &) | |
AddonMenu & | operator= (const AddonMenu &) |
Private Attributes | |
std::vector< Addon * > | m_addons |
Definition at line 28 of file addon_menu.hpp.
AddonMenu::AddonMenu | ( | ) |
AddonMenu::AddonMenu | ( | const AddonMenu & | ) | [private] |
void AddonMenu::refresh | ( | ) |
Definition at line 42 of file addon_menu.cpp.
References _(), Menu::add_back(), Menu::add_entry(), Menu::add_hl(), Menu::add_inactive(), Menu::add_label(), Menu::add_toggle(), ADDON_LIST_START_ID, Menu::clear(), generate_addons_menu_sorter(), AddonManager::get_addons(), AddonManager::get_instance(), and m_addons.
Referenced by AddonMenu(), and check_menu().
00043 { 00044 clear(); 00045 00046 AddonManager& adm = AddonManager::get_instance(); 00047 00048 // refresh list of addons 00049 m_addons = adm.get_addons(); 00050 00051 // sort list 00052 std::sort(m_addons.begin(), m_addons.end(), generate_addons_menu_sorter); 00053 00054 00055 add_label(_("Add-ons")); 00056 add_hl(); 00057 00058 // FIXME: don't use macro, use AddonManager::online_available() or so 00059 #ifdef HAVE_LIBCURL 00060 add_entry(0, std::string(_("Check Online"))); 00061 #else 00062 add_inactive(0, std::string(_("Check Online (disabled)"))); 00063 #endif 00064 00065 //add_hl(); 00066 00067 for (unsigned int i = 0; i < m_addons.size(); i++) 00068 { 00069 const Addon& addon = *m_addons[i]; 00070 std::string text = ""; 00071 00072 if (!addon.kind.empty()) 00073 { 00074 text += addon.kind + " "; 00075 } 00076 text += std::string("\"") + addon.title + "\""; 00077 00078 if (!addon.author.empty()) 00079 { 00080 text += " by \"" + addon.author + "\""; 00081 } 00082 add_toggle(ADDON_LIST_START_ID + i, text, addon.loaded); 00083 } 00084 00085 add_hl(); 00086 add_back(_("Back")); 00087 }
void AddonMenu::check_menu | ( | ) | [virtual] |
Implements Menu.
Definition at line 90 of file addon_menu.cpp.
References ADDON_LIST_START_ID, Menu::check(), AddonManager::check_online(), AddonManager::disable(), AddonManager::enable(), AddonManager::get_instance(), AddonManager::install(), log_warning, m_addons, refresh(), Menu::set_active_item(), and Menu::set_toggled().
00091 { 00092 int index = check(); 00093 00094 if (index == -1) 00095 { 00096 // do nothing 00097 } 00098 else if (index == 0) // check if "Check Online" was chosen 00099 { 00100 try 00101 { 00102 AddonManager::get_instance().check_online(); 00103 refresh(); 00104 set_active_item(index); 00105 } 00106 catch (std::exception& e) 00107 { 00108 log_warning << "Check for available Add-ons failed: " << e.what() << std::endl; 00109 } 00110 } 00111 else 00112 { 00113 // if one of the Addons listed was chosen, take appropriate action 00114 if ((index >= ADDON_LIST_START_ID) && (index < ADDON_LIST_START_ID) + m_addons.size()) 00115 { 00116 Addon& addon = *m_addons[index - ADDON_LIST_START_ID]; 00117 if (!addon.installed) 00118 { 00119 try 00120 { 00121 AddonManager::get_instance().install(&addon); 00122 } 00123 catch (std::exception& e) 00124 { 00125 log_warning << "Installing Add-on failed: " << e.what() << std::endl; 00126 } 00127 set_toggled(index, addon.loaded); 00128 } 00129 else if (!addon.loaded) 00130 { 00131 try 00132 { 00133 AddonManager::get_instance().enable(&addon); 00134 } 00135 catch (std::exception& e) 00136 { 00137 log_warning << "Enabling Add-on failed: " << e.what() << std::endl; 00138 } 00139 set_toggled(index, addon.loaded); 00140 } 00141 else 00142 { 00143 try 00144 { 00145 AddonManager::get_instance().disable(&addon); 00146 } 00147 catch (std::exception& e) 00148 { 00149 log_warning << "Disabling Add-on failed: " << e.what() << std::endl; 00150 } 00151 set_toggled(index, addon.loaded); 00152 } 00153 } 00154 } 00155 }
std::vector<Addon*> AddonMenu::m_addons [private] |