mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-31 01:11:12 +02:00
gui/hdd_menu.cpp: convert to singleton;
add basic notify about device hotplug/remove
This commit is contained in:
@@ -95,10 +95,7 @@ devtool_s CHDDMenuHandler::devtools[] = {
|
|||||||
|
|
||||||
static int my_filter(const struct dirent * dent)
|
static int my_filter(const struct dirent * dent)
|
||||||
{
|
{
|
||||||
if ((dent->d_name[0] == 's' && (dent->d_name[1] == 'd' || dent->d_name[1] == 'r')) ||
|
return CHDDMenuHandler::getInstance()->filterDevName(dent->d_name);
|
||||||
!strncmp(dent->d_name, "mmcblk", 6))
|
|
||||||
return 1;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CHDDMenuHandler::CHDDMenuHandler()
|
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 CHDDMenuHandler::is_mounted(const char *dev)
|
||||||
{
|
{
|
||||||
bool res = false;
|
bool res = false;
|
||||||
|
@@ -88,12 +88,16 @@ class CHDDMenuHandler : public CMenuTarget
|
|||||||
int checkDevice(std::string dev);
|
int checkDevice(std::string dev);
|
||||||
int formatDevice(std::string dev);
|
int formatDevice(std::string dev);
|
||||||
void showError(neutrino_locale_t err);
|
void showError(neutrino_locale_t err);
|
||||||
|
CHDDMenuHandler();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CHDDMenuHandler();
|
|
||||||
~CHDDMenuHandler();
|
~CHDDMenuHandler();
|
||||||
int exec( CMenuTarget* parent, const std::string &actionkey);
|
|
||||||
int doMenu();
|
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
|
#endif
|
||||||
|
@@ -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 | channelList->handleMsg(msg, data);
|
||||||
res = res | CRecordManager::getInstance()->handleMsg(msg, data);
|
res = res | CRecordManager::getInstance()->handleMsg(msg, data);
|
||||||
res = res | CEpgScan::getInstance()->handleMsg(msg, data);
|
res = res | CEpgScan::getInstance()->handleMsg(msg, data);
|
||||||
|
res = res | CHDDMenuHandler::getInstance()->handleMsg(msg, data);
|
||||||
|
|
||||||
if( res != messages_return::unhandled ) {
|
if( res != messages_return::unhandled ) {
|
||||||
if( ( msg>= CRCInput::RC_WithData ) && ( msg< CRCInput::RC_WithData+ 0x10000000 ) ) {
|
if( ( msg>= CRCInput::RC_WithData ) && ( msg< CRCInput::RC_WithData+ 0x10000000 ) ) {
|
||||||
|
@@ -421,7 +421,7 @@ void CNeutrinoApp::InitMenuSettings()
|
|||||||
|
|
||||||
// drive settings
|
// drive settings
|
||||||
if (g_settings.recording_type != CNeutrinoApp::RECORDING_OFF) {
|
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);
|
mf->setHint(NEUTRINO_ICON_HINT_HDD, LOCALE_MENU_HINT_HDD);
|
||||||
personalize.addItem(MENU_SETTINGS, mf, &g_settings.personalize[SNeutrinoSettings::P_MSET_DRIVES]);
|
personalize.addItem(MENU_SETTINGS, mf, &g_settings.personalize[SNeutrinoSettings::P_MSET_DRIVES]);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user