gui/hdd_menu.cpp: convert to singleton;

add basic notify about device hotplug/remove
This commit is contained in:
[CST] Focus
2014-04-23 17:25:08 +04:00
parent bc5b5dd7f3
commit 6be2b32cd3
4 changed files with 66 additions and 8 deletions

View File

@@ -95,10 +95,7 @@ devtool_s CHDDMenuHandler::devtools[] = {
static int my_filter(const struct dirent * dent)
{
if ((dent->d_name[0] == 's' && (dent->d_name[1] == 'd' || dent->d_name[1] == 'r')) ||
!strncmp(dent->d_name, "mmcblk", 6))
return 1;
return 0;
return CHDDMenuHandler::getInstance()->filterDevName(dent->d_name);
}
CHDDMenuHandler::CHDDMenuHandler()
@@ -111,6 +108,62 @@ CHDDMenuHandler::~CHDDMenuHandler()
{
}
CHDDMenuHandler* CHDDMenuHandler::getInstance()
{
static CHDDMenuHandler* me = NULL;
if(!me)
me = new CHDDMenuHandler();
return me;
}
int CHDDMenuHandler::filterDevName(const char * name)
{
if ((name[0] == 's' && (name[1] == 'd' || name[1] == 'r')) ||
!strncmp(name, "mmcblk", 6))
return 1;
return 0;
}
int CHDDMenuHandler::handleMsg(const neutrino_msg_t msg, neutrino_msg_data_t data)
{
if(msg != NeutrinoMessages::EVT_HOTPLUG)
return messages_return::unhandled;
std::string str((char *) data);
std::map<std::string,std::string> smap;
if (!split_config_string(str, smap))
return messages_return::handled;
std::map<std::string,std::string>::iterator it = smap.find("MDEV");
if (it == smap.end())
return messages_return::handled;
std::string dev = it->second;
it = smap.find("ACTION");
if (it == smap.end())
return messages_return::handled;
bool added = it->second == "add";
printf("CHDDMenuHandler::handleMsg: %s MDEV=%s\n", it->second.c_str(), dev.c_str());
if (!filterDevName(dev.c_str()))
return messages_return::handled;
bool mounted = is_mounted(dev.c_str());
std::string message = dev + ": " + (added ?
g_Locale->getText(mounted ? LOCALE_HDD_MOUNT_OK : LOCALE_HDD_MOUNT_FAILED)
: g_Locale->getText(LOCALE_HDD_UMOUNTED));
ShowHint(LOCALE_MESSAGEBOX_INFO, message.c_str());
return messages_return::handled;
}
bool CHDDMenuHandler::is_mounted(const char *dev)
{
bool res = false;

View File

@@ -88,12 +88,16 @@ class CHDDMenuHandler : public CMenuTarget
int checkDevice(std::string dev);
int formatDevice(std::string dev);
void showError(neutrino_locale_t err);
CHDDMenuHandler();
public:
CHDDMenuHandler();
~CHDDMenuHandler();
static CHDDMenuHandler* getInstance();
int exec( CMenuTarget* parent, const std::string &actionkey);
int doMenu();
int filterDevName(const char * name);
int handleMsg(const neutrino_msg_t _msg, neutrino_msg_data_t data);
};
#endif

View File

@@ -2562,6 +2562,7 @@ int CNeutrinoApp::handleMsg(const neutrino_msg_t _msg, neutrino_msg_data_t data)
res = res | channelList->handleMsg(msg, data);
res = res | CRecordManager::getInstance()->handleMsg(msg, data);
res = res | CEpgScan::getInstance()->handleMsg(msg, data);
res = res | CHDDMenuHandler::getInstance()->handleMsg(msg, data);
if( res != messages_return::unhandled ) {
if( ( msg>= CRCInput::RC_WithData ) && ( msg< CRCInput::RC_WithData+ 0x10000000 ) ) {

View File

@@ -421,7 +421,7 @@ void CNeutrinoApp::InitMenuSettings()
// drive settings
if (g_settings.recording_type != CNeutrinoApp::RECORDING_OFF) {
mf = new CMenuForwarder(LOCALE_HDD_SETTINGS, true, NULL, new CHDDMenuHandler());
mf = new CMenuForwarder(LOCALE_HDD_SETTINGS, true, NULL, CHDDMenuHandler::getInstance());
mf->setHint(NEUTRINO_ICON_HINT_HDD, LOCALE_MENU_HINT_HDD);
personalize.addItem(MENU_SETTINGS, mf, &g_settings.personalize[SNeutrinoSettings::P_MSET_DRIVES]);
}