gui/hdd_menu.cpp: add question to set record directory to formatted drive;

mark partition used for recording with icon, disable umount
This commit is contained in:
[CST] Focus
2014-05-01 19:03:09 +04:00
parent bbf0a95542
commit bbcd7330a8
5 changed files with 133 additions and 74 deletions

View File

@@ -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

View File

@@ -55,6 +55,7 @@
#include <mymenu.h>
#include <driver/screen_max.h>
#include <driver/record.h>
#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<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;
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<std::string, std::string>::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<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;
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<std::string, std::string>::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<hdd_s>::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);
}
}

View File

@@ -25,8 +25,8 @@
#ifndef __hdd_menu__
#define __hdd_menu__
#include "widget/menue.h"
#include <gui/widget/hintbox.h>
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:

View File

@@ -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,

View File

@@ -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",