From 6be2b32cd34ccad5eb40510904d7fcef366e189a Mon Sep 17 00:00:00 2001 From: "[CST] Focus" Date: Wed, 23 Apr 2014 17:25:08 +0400 Subject: [PATCH] gui/hdd_menu.cpp: convert to singleton; add basic notify about device hotplug/remove --- src/gui/hdd_menu.cpp | 61 +++++++++++++++++++++++++++++++++++++++--- src/gui/hdd_menu.h | 10 ++++--- src/neutrino.cpp | 1 + src/neutrino_menue.cpp | 2 +- 4 files changed, 66 insertions(+), 8 deletions(-) diff --git a/src/gui/hdd_menu.cpp b/src/gui/hdd_menu.cpp index 47f306ae6..a91545eeb 100644 --- a/src/gui/hdd_menu.cpp +++ b/src/gui/hdd_menu.cpp @@ -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 smap; + + if (!split_config_string(str, smap)) + return messages_return::handled; + + std::map::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; diff --git a/src/gui/hdd_menu.h b/src/gui/hdd_menu.h index 2e17cea31..97cc6b447 100644 --- a/src/gui/hdd_menu.h +++ b/src/gui/hdd_menu.h @@ -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(); - 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 diff --git a/src/neutrino.cpp b/src/neutrino.cpp index fd332e3f5..53e5cc40b 100644 --- a/src/neutrino.cpp +++ b/src/neutrino.cpp @@ -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 ) ) { diff --git a/src/neutrino_menue.cpp b/src/neutrino_menue.cpp index 86e2ba133..44474f338 100644 --- a/src/neutrino_menue.cpp +++ b/src/neutrino_menue.cpp @@ -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]); }