From cfcf86f38f3d952b1f21dda85e19cc2c29c18474 Mon Sep 17 00:00:00 2001 From: "[CST] Focus" Date: Thu, 1 May 2014 19:03:09 +0400 Subject: [PATCH] gui/hdd_menu.cpp: add question to set record directory to formatted drive; mark partition used for recording with icon, disable umount Origin commit data ------------------ Commit: https://github.com/neutrino-images/ni-neutrino/commit/bbcd7330a8cb577900a1fe66e5f6a321aab4f1d6 Author: [CST] Focus Date: 2014-05-01 (Thu, 01 May 2014) --- data/locale/english.locale | 1 + src/gui/hdd_menu.cpp | 201 +++++++++++++++++++++++-------------- src/gui/hdd_menu.h | 3 +- src/system/locals.h | 1 + src/system/locals_intern.h | 1 + 5 files changed, 133 insertions(+), 74 deletions(-) diff --git a/data/locale/english.locale b/data/locale/english.locale index 74d0ecbdd..fc3ba48e2 100644 --- a/data/locale/english.locale +++ b/data/locale/english.locale @@ -638,6 +638,7 @@ hdd_noise Acoustic-control (AAM) hdd_not_found No HDD found hdd_removable_device Removable device hdd_settings Hard Disk Drive/USB +hdd_set_recdir Use device for recording ? hdd_sleep Switch off after... hdd_slow Slow hdd_umount Unmount diff --git a/src/gui/hdd_menu.cpp b/src/gui/hdd_menu.cpp index 4d1615324..bee9c69bd 100644 --- a/src/gui/hdd_menu.cpp +++ b/src/gui/hdd_menu.cpp @@ -55,6 +55,7 @@ #include #include +#include #define BLKID_BIN "/sbin/blkid" #define EJECT_BIN "/bin/eject" @@ -128,76 +129,6 @@ int CHDDMenuHandler::filterDevName(const char * name) return 0; } -int CHDDMenuHandler::handleMsg(const neutrino_msg_t msg, neutrino_msg_data_t data) -{ - if (msg == NeutrinoMessages::EVT_HOTPLUG) { - 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; - printf("CHDDMenuHandler::handleMsg: MDEV=%s\n", dev.c_str()); - if (!filterDevName(dev.c_str())) - return messages_return::handled; - - it = smap.find("ACTION"); - if (it == smap.end()) - return messages_return::handled; - - bool added = it->second == "add"; - bool mounted = is_mounted(dev.c_str()); - std::string tmp = dev.substr(0, 2); - - if (added && !mounted && tmp != "sr") { - std::string message = dev + ": " + g_Locale->getText(LOCALE_HDD_MOUNT_FAILED); - message += std::string(" ") + g_Locale->getText(LOCALE_HDD_FORMAT) + std::string(" ?"); - int res = ShowMsg(LOCALE_MESSAGEBOX_INFO, message, CMessageBox::mbrNo, CMessageBox::mbYes | CMessageBox::mbNo); - if(res == CMessageBox::mbrYes) { - unsigned char * p = new unsigned char[dev.size() + 1]; - if (p) { - sprintf((char *)p, "%s", dev.c_str()); - g_RCInput->postMsg(NeutrinoMessages::EVT_FORMAT_DRIVE , (neutrino_msg_data_t)p); - return messages_return::handled | messages_return::cancel_all; - } - } - } else { - 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()); - } - if (in_menu && !lock_refresh) { - show_menu = true; - return messages_return::handled | messages_return::cancel_all; - } - lock_refresh = false; - return messages_return::handled; - } - else if (msg == NeutrinoMessages::EVT_FORMAT_DRIVE) { - std::string dev((char *) data); - printf("NeutrinoMessages::EVT_FORMAT_DRIVE: [%s]\n", dev.c_str()); - check_dev_tools(); - getBlkIds(); - scanDevices(); - for (std::map::iterator it = devtitle.begin(); it != devtitle.end(); ++it) { - if (dev.substr(0, it->first.size()) == it->first) { - showDeviceMenu(it->first); - break; - } - } - hdd_list.clear(); - devtitle.clear(); - return messages_return::handled; - } - return messages_return::unhandled; -} - bool CHDDMenuHandler::is_mounted(const char *dev) { bool res = false; @@ -401,6 +332,100 @@ bool CHDDMenuHandler::waitfordev(std::string dev, int maxwait) } #endif +void CHDDMenuHandler::showHint(std::string &message) +{ + CHintBox * hintBox = new CHintBox(LOCALE_MESSAGEBOX_INFO, message.c_str()); + hintBox->paint(); + + uint64_t timeoutEnd = CRCInput::calcTimeoutEnd(3); + neutrino_msg_t msg; + neutrino_msg_data_t data; + + while(true) { + g_RCInput->getMsgAbsoluteTimeout(&msg, &data, &timeoutEnd); + + if ((msg == CRCInput::RC_timeout) || (msg < CRCInput::RC_MaxRC)) + break; + else if (msg == NeutrinoMessages::EVT_HOTPLUG) { + g_RCInput->postMsg(msg, data); + break; + } + else if (CNeutrinoApp::getInstance()->handleMsg(msg, data) & messages_return::cancel_all) + break; + } + delete hintBox; +} + +int CHDDMenuHandler::handleMsg(const neutrino_msg_t msg, neutrino_msg_data_t data) +{ + if (msg == NeutrinoMessages::EVT_HOTPLUG) { + 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; + printf("CHDDMenuHandler::handleMsg: MDEV=%s\n", dev.c_str()); + if (!filterDevName(dev.c_str())) + return messages_return::handled; + + it = smap.find("ACTION"); + if (it == smap.end()) + return messages_return::handled; + + bool added = it->second == "add"; + bool mounted = is_mounted(dev.c_str()); + std::string tmp = dev.substr(0, 2); + + if (added && !mounted && tmp != "sr") { + std::string message = dev + ": " + g_Locale->getText(LOCALE_HDD_MOUNT_FAILED); + message += std::string(" ") + g_Locale->getText(LOCALE_HDD_FORMAT) + std::string(" ?"); + int res = ShowMsg(LOCALE_MESSAGEBOX_INFO, message, CMessageBox::mbrNo, CMessageBox::mbYes | CMessageBox::mbNo); + if(res == CMessageBox::mbrYes) { + unsigned char * p = new unsigned char[dev.size() + 1]; + if (p) { + sprintf((char *)p, "%s", dev.c_str()); + g_RCInput->postMsg(NeutrinoMessages::EVT_FORMAT_DRIVE , (neutrino_msg_data_t)p); + return messages_return::handled | messages_return::cancel_all; + } + } + } else { + std::string message = dev + ": " + (added ? + g_Locale->getText(mounted ? LOCALE_HDD_MOUNT_OK : LOCALE_HDD_MOUNT_FAILED) + : g_Locale->getText(LOCALE_HDD_UMOUNTED)); + showHint(message); + } + if (in_menu && !lock_refresh) { + show_menu = true; + return messages_return::handled | messages_return::cancel_all; + } + lock_refresh = false; + return messages_return::handled; + } + else if (msg == NeutrinoMessages::EVT_FORMAT_DRIVE) { + std::string dev((char *) data); + printf("NeutrinoMessages::EVT_FORMAT_DRIVE: [%s]\n", dev.c_str()); + check_dev_tools(); + getBlkIds(); + scanDevices(); + for (std::map::iterator it = devtitle.begin(); it != devtitle.end(); ++it) { + if (dev.substr(0, it->first.size()) == it->first) { + showDeviceMenu(it->first); + break; + } + } + hdd_list.clear(); + devtitle.clear(); + return messages_return::handled; + } + return messages_return::unhandled; +} + int CHDDMenuHandler::exec(CMenuTarget* parent, const std::string &actionkey) { if (parent) @@ -435,7 +460,26 @@ int CHDDMenuHandler::exec(CMenuTarget* parent, const std::string &actionkey) return checkDevice(dev); } else if (actionkey[0] == 'f') { - return formatDevice(dev); + int ret = formatDevice(dev); + std::string devname = "/dev/" + dev + getDefaultPart(dev); + if (show_menu && is_mounted(devname.c_str())) { + bool old_menu = in_menu; + in_menu = false; + int res = ShowMsg(LOCALE_RECORDINGMENU_DEFDIR, LOCALE_HDD_SET_RECDIR, CMessageBox::mbrNo, CMessageBox::mbYes | CMessageBox::mbNo); + if(res == CMessageBox::mbrYes) { + g_settings.network_nfs_recordingdir = std::string(MOUNT_BASE) + "/" + dev + getDefaultPart(dev) + "/movies"; + CRecordManager::getInstance()->SetDirectory(g_settings.network_nfs_recordingdir); + if(g_settings.timeshiftdir.empty()) + { + std::string timeshiftDir = g_settings.network_nfs_recordingdir + "/.timeshift"; + safe_mkdir(timeshiftDir.c_str()); + printf("New timeshift dir: %s\n", timeshiftDir.c_str()); + CRecordManager::getInstance()->SetTimeshiftDirectory(timeshiftDir); + } + } + in_menu = old_menu; + } + return ret; } return menu_return::RETURN_REPAINT; } @@ -663,15 +707,26 @@ _show_menu: } if (!hdd_list.empty()) { + struct stat rec_st; + memset(&rec_st, 0, sizeof(rec_st)); + stat(g_settings.network_nfs_recordingdir.c_str(), &rec_st); + sort(hdd_list.begin(), hdd_list.end(), cmp_hdd_by_name()); mount = g_Locale->getText(LOCALE_HDD_MOUNT); umount = g_Locale->getText(LOCALE_HDD_UMOUNT); int shortcut = 1; hddmenu->addItem(new CMenuSeparator(CMenuSeparator::LINE | CMenuSeparator::STRING, LOCALE_HDD_MOUNT_UMOUNT)); for (std::vector::iterator it = hdd_list.begin(); it != hdd_list.end(); ++it) { + const char * rec_icon = NULL; + if (it->mounted) { + std::string dst = MOUNT_BASE + it->devname; + if (!stat(dst.c_str(), &stat_buf) && rec_st.st_dev == stat_buf.st_dev) + rec_icon = CNeutrinoApp::getInstance()->recordingstatus ? NEUTRINO_ICON_REC : NEUTRINO_ICON_REC_GRAY; + } std::string key = "m" + it->devname; - it->cmf = new CMenuForwarder(it->desc, true, it->mounted ? umount : mount , this, - key.c_str(), CRCInput::convertDigitToKey(shortcut++)); + bool enabled = !rec_icon || !CNeutrinoApp::getInstance()->recordingstatus; + it->cmf = new CMenuForwarder(it->desc, enabled, it->mounted ? umount : mount , this, + key.c_str(), CRCInput::convertDigitToKey(shortcut++), NULL, rec_icon); hddmenu->addItem(it->cmf); } } diff --git a/src/gui/hdd_menu.h b/src/gui/hdd_menu.h index 9a244394a..d073da013 100644 --- a/src/gui/hdd_menu.h +++ b/src/gui/hdd_menu.h @@ -25,8 +25,8 @@ #ifndef __hdd_menu__ #define __hdd_menu__ - #include "widget/menue.h" +#include using namespace std; @@ -91,6 +91,7 @@ class CHDDMenuHandler : public CMenuTarget int formatDevice(std::string dev); void showError(neutrino_locale_t err); bool scanDevices(); + void showHint(std::string &messsage); CHDDMenuHandler(); public: diff --git a/src/system/locals.h b/src/system/locals.h index aeca005f0..7e9e0bcd9 100644 --- a/src/system/locals.h +++ b/src/system/locals.h @@ -665,6 +665,7 @@ typedef enum LOCALE_HDD_NOT_FOUND, LOCALE_HDD_REMOVABLE_DEVICE, LOCALE_HDD_SETTINGS, + LOCALE_HDD_SET_RECDIR, LOCALE_HDD_SLEEP, LOCALE_HDD_SLOW, LOCALE_HDD_UMOUNT, diff --git a/src/system/locals_intern.h b/src/system/locals_intern.h index 8402a72fe..e85613acc 100644 --- a/src/system/locals_intern.h +++ b/src/system/locals_intern.h @@ -665,6 +665,7 @@ const char * locale_real_names[] = "hdd_not_found", "hdd_removable_device", "hdd_settings", + "hdd_set_recdir", "hdd_sleep", "hdd_slow", "hdd_umount",