mirror of
https://github.com/tuxbox-fork-migrations/recycled-ni-neutrino.git
synced 2025-08-28 16:01:10 +02:00
gui/filebrowser.cpp: cleanup, simplify footer
Origin commit data
------------------
Branch: ni/coolstream
Commit: 713820a1c0
Author: [CST] Focus <focus.cst@gmail.com>
Date: 2014-10-01 (Wed, 01 Oct 2014)
------------------
No further description and justification available within origin commit message!
------------------
This commit was generated by Migit
This commit is contained in:
@@ -58,25 +58,12 @@
|
||||
#include <system/helpers.h>
|
||||
#include <xmltree/xmlinterface.h>
|
||||
|
||||
#ifdef __USE_FILE_OFFSET64
|
||||
typedef struct dirent64 dirent_struct;
|
||||
#define my_alphasort alphasort64
|
||||
#define my_scandir scandir64
|
||||
typedef struct stat64 stat_struct;
|
||||
#define my_stat stat64
|
||||
#define my_lstat lstat64
|
||||
#else
|
||||
typedef struct dirent dirent_struct;
|
||||
#define my_alphasort alphasort
|
||||
#define my_scandir scandir
|
||||
typedef struct stat stat_struct;
|
||||
#define my_stat stat
|
||||
#define my_lstat lstat
|
||||
#ifndef __USE_FILE_OFFSET64
|
||||
#error not using 64 bit file offsets
|
||||
#endif
|
||||
|
||||
#define SMSKEY_TIMEOUT 2000
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
size_t CurlWriteToString(void *ptr, size_t size, size_t nmemb, void *data)
|
||||
{
|
||||
std::string* pStr = (std::string*) data;
|
||||
@@ -84,15 +71,11 @@ size_t CurlWriteToString(void *ptr, size_t size, size_t nmemb, void *data)
|
||||
return size*nmemb;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
SMSKeyInput::SMSKeyInput()
|
||||
{
|
||||
resetOldKey();
|
||||
m_timeout = SMSKEY_TIMEOUT;
|
||||
}
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
unsigned char SMSKeyInput::handleMsg(const neutrino_msg_t msg)
|
||||
{
|
||||
@@ -126,7 +109,6 @@ unsigned char SMSKeyInput::handleMsg(const neutrino_msg_t msg)
|
||||
m_oldKey=*key;
|
||||
return *key;
|
||||
}
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
void SMSKeyInput::resetOldKey()
|
||||
{
|
||||
@@ -161,9 +143,6 @@ void SMSKeyInput::setTimeout(int timeout)
|
||||
m_timeout = timeout;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
bool comparetolower(const char a, const char b)
|
||||
{
|
||||
return tolower(a) < tolower(b);
|
||||
@@ -179,18 +158,10 @@ bool sortByName (const CFile& a, const CFile& b)
|
||||
return false;
|
||||
|
||||
return a.Mode < b.Mode;
|
||||
/*
|
||||
int result = __gnu_cxx::lexicographical_compare_3way(a.Name.begin(), a.Name.end(), b.Name.begin(), b.Name.end(), comparetolower);
|
||||
|
||||
if (result == 0)
|
||||
return a.Mode < b.Mode;
|
||||
else
|
||||
return result < 0;
|
||||
*/
|
||||
}
|
||||
|
||||
bool sortByNameDirsFirst(const CFile& a, const CFile& b)
|
||||
// Sorts alphabetically with Directories first
|
||||
bool sortByNameDirsFirst(const CFile& a, const CFile& b)
|
||||
{
|
||||
int typea, typeb;
|
||||
typea = a.getType();
|
||||
@@ -255,8 +226,6 @@ const neutrino_locale_t sortByNames[FILEBROWSER_NUMBER_OF_SORT_VARIANTS] =
|
||||
LOCALE_FILEBROWSER_SORT_SIZE
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
CFileBrowser::CFileBrowser()
|
||||
{
|
||||
commonInit();
|
||||
@@ -284,9 +253,8 @@ void CFileBrowser::commonInit()
|
||||
Dir_Mode = false;
|
||||
Hide_records = false;
|
||||
selected = 0;
|
||||
selections.clear();
|
||||
m_SMSKeyInput.setTimeout(SMSKEY_TIMEOUT);
|
||||
fontInit();
|
||||
//fontInit();
|
||||
}
|
||||
|
||||
void CFileBrowser::fontInit()
|
||||
@@ -302,28 +270,22 @@ void CFileBrowser::fontInit()
|
||||
fheight = fnt_item->getHeight();
|
||||
if (fheight == 0)
|
||||
fheight = 1; /* avoid div by zero on invalid font */
|
||||
foheight = fnt_small->getHeight()+6; //initial height value for buttonbar; TODO get value from buttonbar
|
||||
//foheight = fnt_small->getHeight()+6; //initial height value for buttonbar; TODO get value from buttonbar
|
||||
foheight = paintFoot(false);
|
||||
skwidth = 26;
|
||||
|
||||
liststart = 0;
|
||||
listmaxshow = std::max(1,(int)(height - theight - 2 * foheight)/fheight);
|
||||
listmaxshow = std::max(1,(int)(height - theight - foheight)/fheight);
|
||||
|
||||
//recalc height
|
||||
height = theight + listmaxshow * fheight + 2 * foheight;
|
||||
height = theight + listmaxshow * fheight + foheight;
|
||||
y = getScreenStartY(height);
|
||||
|
||||
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
|
||||
CFileBrowser::~CFileBrowser()
|
||||
{
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
CFile *CFileBrowser::getSelectedFile()
|
||||
{
|
||||
if ((!(filelist.empty())) && (!(filelist[selected].Name.empty())))
|
||||
@@ -332,8 +294,6 @@ CFile *CFileBrowser::getSelectedFile()
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
void CFileBrowser::ChangeDir(const std::string & filename, int selection)
|
||||
{
|
||||
std::string newpath;
|
||||
@@ -341,36 +301,19 @@ void CFileBrowser::ChangeDir(const std::string & filename, int selection)
|
||||
{
|
||||
std::string::size_type pos = Path.substr(0,Path.length()-1).rfind('/');
|
||||
|
||||
#ifdef ENABLE_MOVIEPLAYER_VLC
|
||||
bool is_vlc = (strncmp(Path.c_str(), VLC_URI, strlen(VLC_URI)) == 0);
|
||||
#endif
|
||||
if (pos == std::string::npos)
|
||||
{
|
||||
newpath = Path;
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef ENABLE_MOVIEPLAYER_VLC
|
||||
if (is_vlc && (pos < strlen(VLC_URI) - 1))
|
||||
newpath = VLC_URI;
|
||||
else
|
||||
#endif
|
||||
newpath = Path.substr(0, pos + 1);
|
||||
}
|
||||
|
||||
#ifdef ENABLE_MOVIEPLAYER_VLC
|
||||
if (strncmp(is_vlc ? &(newpath.c_str()[strlen(VLC_URI)]) : newpath.c_str(), base.c_str(), base.length()) != 0)
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
newpath=filename;
|
||||
}
|
||||
|
||||
if (m_Mode != ModeSC && (newpath.rfind('/') != newpath.length()-1 || newpath.length() == 0))
|
||||
{
|
||||
newpath += '/';
|
||||
}
|
||||
|
||||
filelist.clear();
|
||||
Path = newpath;
|
||||
name = newpath;
|
||||
@@ -383,9 +326,8 @@ void CFileBrowser::ChangeDir(const std::string & filename, int selection)
|
||||
if (Filter != NULL && !file->isDir() && use_filter)
|
||||
{
|
||||
if (!Filter->matchFilter(file->Name))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (Hide_records) {
|
||||
int ext_pos = file->Name.rfind('.');
|
||||
if (ext_pos > 0) {
|
||||
@@ -415,122 +357,15 @@ void CFileBrowser::ChangeDir(const std::string & filename, int selection)
|
||||
paintFoot();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
bool CFileBrowser::readDir(const std::string & dirname, CFileList* flist)
|
||||
{
|
||||
bool ret;
|
||||
|
||||
#ifdef ENABLE_INTERNETRADIO
|
||||
if (m_Mode == ModeSC) {
|
||||
ret = readDir_sc(dirname, flist);
|
||||
}
|
||||
if (m_Mode == ModeSC)
|
||||
return readDir_sc(dirname, flist);
|
||||
else
|
||||
#endif
|
||||
#ifdef ENABLE_MOVIEPLAYER_VLC
|
||||
if (strncmp(dirname.c_str(), VLC_URI, strlen(VLC_URI)) == 0)
|
||||
{
|
||||
ret = readDir_vlc(dirname, flist);
|
||||
return readDir_std(dirname, flist);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
ret = readDir_std(dirname, flist);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_MOVIEPLAYER_VLC
|
||||
bool CFileBrowser::readDir_vlc(const std::string & dirname, CFileList* flist)
|
||||
{
|
||||
// printf("readDir_vlc %s\n",dirname.c_str());
|
||||
std::string answer="";
|
||||
char *dir_escaped = curl_escape(dirname.substr(strlen(VLC_URI)).c_str(), 0);
|
||||
std::string url = m_baseurl;
|
||||
url += dir_escaped;
|
||||
curl_free(dir_escaped);
|
||||
std::cout << "[FileBrowser] vlc URL: " << url << std::endl;
|
||||
CURL *curl_handle;
|
||||
CURLcode httpres;
|
||||
/* init the curl session */
|
||||
curl_handle = curl_easy_init();
|
||||
/* timeout. 15 seconds should be enough */
|
||||
curl_easy_setopt(curl_handle, CURLOPT_CONNECTTIMEOUT, 15);
|
||||
/* specify URL to get */
|
||||
curl_easy_setopt(curl_handle, CURLOPT_URL, url.c_str());
|
||||
/* send all data to this function */
|
||||
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, CurlWriteToString);
|
||||
/* we pass our 'chunk' struct to the callback function */
|
||||
curl_easy_setopt(curl_handle, CURLOPT_FILE, (void *)&answer);
|
||||
/* Generate error if http error >= 400 occurs */
|
||||
curl_easy_setopt(curl_handle, CURLOPT_FAILONERROR, 1);
|
||||
/* error handling */
|
||||
char error[CURL_ERROR_SIZE];
|
||||
curl_easy_setopt(curl_handle, CURLOPT_ERRORBUFFER, error);
|
||||
/* get it! */
|
||||
httpres = curl_easy_perform(curl_handle);
|
||||
/* cleanup curl stuff */
|
||||
curl_easy_cleanup(curl_handle);
|
||||
|
||||
// std::cout << "Answer:" << std::endl << "----------------" << std::endl << answer << std::endl;
|
||||
|
||||
if (!answer.empty() && httpres == 0)
|
||||
{
|
||||
xmlDocPtr answer_parser = parseXml(answer.c_str());
|
||||
|
||||
if (answer_parser != NULL) {
|
||||
xmlNodePtr element = xmlDocGetRootElement(answer_parser);
|
||||
element = element->xmlChildrenNode;
|
||||
char *ptr;
|
||||
if (element == NULL) {
|
||||
printf("[FileBrowser] vlc: Drive is not readable. Possibly no disc inserted\n");
|
||||
CFile file;
|
||||
file.Mode = S_IFDIR + 0777 ;
|
||||
file.Name = dirname + "..";
|
||||
file.Size = 0;
|
||||
file.Time = 0;
|
||||
flist->push_back(file);
|
||||
} else {
|
||||
while (element) {
|
||||
CFile file;
|
||||
ptr = xmlGetAttribute(element, "type");
|
||||
if (strcmp(ptr, "directory")==0)
|
||||
file.Mode = S_IFDIR + 0777 ;
|
||||
else
|
||||
file.Mode = S_IFREG + 0777 ;
|
||||
|
||||
file.Name = dirname + xmlGetAttribute(element, "name");
|
||||
ptr = xmlGetAttribute(element, "size");
|
||||
if (ptr)
|
||||
file.Size = atoi(ptr);
|
||||
else
|
||||
file.Size = 0;
|
||||
file.Time = 0;
|
||||
|
||||
element = element->xmlNextNode;
|
||||
flist->push_back(file);
|
||||
}
|
||||
}
|
||||
xmlFreeDoc(answer_parser);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/* since all CURL error messages use only US-ASCII characters, when can safely print them as if they were UTF-8 encoded */
|
||||
if (httpres == 22) {
|
||||
strcat(error, "\nProbably wrong vlc version\nPlease use vlc 0.8.5 or higher");
|
||||
}
|
||||
DisplayErrorMessage(error); // UTF-8
|
||||
CFile file;
|
||||
|
||||
file.Name = dirname + "..";
|
||||
file.Mode = S_IFDIR + 0777;
|
||||
file.Size = 0;
|
||||
file.Time = 0;
|
||||
flist->push_back(file);
|
||||
|
||||
return false;
|
||||
}
|
||||
#endif /* ENABLE_MOVIEPLAYER_VLC */
|
||||
|
||||
#ifdef ENABLE_INTERNETRADIO
|
||||
bool CFileBrowser::readDir_sc(const std::string & dirname, CFileList* flist)
|
||||
@@ -708,11 +543,11 @@ printf("CFileBrowser::readDir_sc: httpres %d error, %s\n", httpres, error);
|
||||
bool CFileBrowser::readDir_std(const std::string & dirname, CFileList* flist)
|
||||
{
|
||||
// printf("readDir_std %s\n",dirname.c_str());
|
||||
stat_struct statbuf;
|
||||
dirent_struct **namelist;
|
||||
struct stat64 statbuf;
|
||||
dirent64 **namelist;
|
||||
int n;
|
||||
|
||||
n = my_scandir(dirname.c_str(), &namelist, 0, my_alphasort);
|
||||
n = scandir64(dirname.c_str(), &namelist, 0, alphasort64);
|
||||
if (n < 0)
|
||||
{
|
||||
perror(("Filebrowser scandir: "+dirname).c_str());
|
||||
@@ -726,7 +561,7 @@ bool CFileBrowser::readDir_std(const std::string & dirname, CFileList* flist)
|
||||
file.Name = dirname + namelist[i]->d_name;
|
||||
|
||||
// printf("file.Name: '%s', getFileName: '%s' getPath: '%s'\n",file.Name.c_str(),file.getFileName().c_str(),file.getPath().c_str());
|
||||
if(my_stat((file.Name).c_str(),&statbuf) != 0)
|
||||
if(stat64((file.Name).c_str(),&statbuf) != 0)
|
||||
perror("stat error");
|
||||
else
|
||||
{
|
||||
@@ -754,8 +589,6 @@ bool CFileBrowser::checkBD(CFile &file)
|
||||
return false;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
bool CFileBrowser::exec(const char * const dirname)
|
||||
{
|
||||
neutrino_msg_t msg;
|
||||
@@ -774,7 +607,7 @@ bool CFileBrowser::exec(const char * const dirname)
|
||||
std::replace(name.begin(), name.end(), '\\', '/');
|
||||
|
||||
fontInit();
|
||||
paintHead();
|
||||
//paintHead();
|
||||
int selection = -1;
|
||||
if (name == Path)
|
||||
selection = selected;
|
||||
@@ -799,87 +632,18 @@ bool CFileBrowser::exec(const char * const dirname)
|
||||
m_SMSKeyInput.resetOldKey();
|
||||
paintSMSKey();
|
||||
}
|
||||
|
||||
if (msg == CRCInput::RC_yellow || msg == CRCInput::RC_play)
|
||||
if (msg == CRCInput::RC_blue)
|
||||
{
|
||||
if ((Multi_Select) && (selected < filelist.size()))
|
||||
if(Filter != NULL)
|
||||
{
|
||||
if(filelist[selected].getFileName() != "..")
|
||||
{
|
||||
if(!filelist[selected].isDir() || Dirs_Selectable)
|
||||
{
|
||||
filelist[selected].Marked = !filelist[selected].Marked;
|
||||
msg_repeatok = CRCInput::RC_down; // jump to next item
|
||||
use_filter = !use_filter;
|
||||
ChangeDir(Path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (msg_repeatok == CRCInput::RC_up)
|
||||
else if (msg == CRCInput::RC_home)
|
||||
{
|
||||
if (!(filelist.empty()))
|
||||
{
|
||||
unsigned int prevselected=selected;
|
||||
unsigned int prevliststart = liststart;
|
||||
if (selected)
|
||||
selected --;
|
||||
else
|
||||
selected = filelist.size() - 1;
|
||||
liststart = (selected/listmaxshow)*listmaxshow;
|
||||
if(prevliststart!=liststart)
|
||||
{
|
||||
paint();
|
||||
}
|
||||
else
|
||||
{
|
||||
paintItem(prevselected - prevliststart);
|
||||
paintItem(selected - liststart);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (msg_repeatok == CRCInput::RC_down)
|
||||
{
|
||||
if (!(filelist.empty()))
|
||||
{
|
||||
unsigned int prevselected=selected;
|
||||
unsigned int prevliststart = liststart;
|
||||
selected = (selected + 1) % filelist.size();
|
||||
liststart = (selected/listmaxshow)*listmaxshow;
|
||||
if(prevliststart!=liststart)
|
||||
{
|
||||
paint();
|
||||
}
|
||||
else
|
||||
{
|
||||
paintItem(prevselected - prevliststart);
|
||||
paintItem(selected - liststart);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ( ( msg == CRCInput::RC_timeout ) )
|
||||
{
|
||||
selected = oldselected;
|
||||
loop = false;
|
||||
}
|
||||
else if ( msg == CRCInput::RC_right )
|
||||
{
|
||||
if (!(filelist.empty()))
|
||||
{
|
||||
if (filelist[selected].isDir())
|
||||
{
|
||||
#ifdef ENABLE_INTERNETRADIO
|
||||
if (m_Mode == ModeSC) {
|
||||
ChangeDir(filelist[selected].Url);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
if (filelist[selected].getFileName() != "..") {
|
||||
selections.push_back(selected);
|
||||
ChangeDir(filelist[selected].Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (msg == CRCInput::RC_left)
|
||||
{
|
||||
#ifdef ENABLE_INTERNETRADIO
|
||||
@@ -903,57 +667,124 @@ bool CFileBrowser::exec(const char * const dirname)
|
||||
ChangeDir("..");
|
||||
}
|
||||
}
|
||||
else if ((msg == CRCInput::RC_red) || msg == (neutrino_msg_t) g_settings.key_pagedown)
|
||||
else if (msg == NeutrinoMessages::STANDBY_ON ||
|
||||
msg == NeutrinoMessages::SHUTDOWN ||
|
||||
msg == NeutrinoMessages::SLEEPTIMER)
|
||||
{
|
||||
if (!(filelist.empty())) {
|
||||
unsigned int last = filelist.size() - 1;
|
||||
if (selected != last && selected + listmaxshow >= filelist.size()) {
|
||||
selected = last;
|
||||
menu_ret = menu_return::RETURN_EXIT_ALL;
|
||||
loop = false;
|
||||
g_RCInput->postMsg(msg, data);
|
||||
}
|
||||
else if (msg == CRCInput::RC_timeout)
|
||||
{
|
||||
selected = oldselected;
|
||||
loop = false;
|
||||
}
|
||||
else if (msg > CRCInput::RC_MaxRC)
|
||||
{
|
||||
if (CNeutrinoApp::getInstance()->handleMsg( msg, data ) & messages_return::cancel_all) {
|
||||
menu_ret = menu_return::RETURN_EXIT_ALL;
|
||||
loop = false;
|
||||
}
|
||||
}
|
||||
if ((filelist.empty()))
|
||||
continue;
|
||||
|
||||
if (msg == CRCInput::RC_yellow || msg == CRCInput::RC_play)
|
||||
{
|
||||
if ((Multi_Select) && (selected < filelist.size()))
|
||||
{
|
||||
if(filelist[selected].getFileName() != "..")
|
||||
{
|
||||
if(!filelist[selected].isDir() || Dirs_Selectable)
|
||||
{
|
||||
filelist[selected].Marked = !filelist[selected].Marked;
|
||||
msg_repeatok = CRCInput::RC_down; // jump to next item
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (msg_repeatok == CRCInput::RC_up)
|
||||
{
|
||||
unsigned int prevselected=selected;
|
||||
unsigned int prevliststart = liststart;
|
||||
if (selected)
|
||||
selected --;
|
||||
else
|
||||
selected = filelist.size() - 1;
|
||||
liststart = (selected/listmaxshow)*listmaxshow;
|
||||
if(prevliststart != liststart)
|
||||
{
|
||||
paint();
|
||||
}
|
||||
else
|
||||
{
|
||||
paintItem(prevselected - prevliststart);
|
||||
paintItem(selected - liststart);
|
||||
}
|
||||
}
|
||||
else if (msg_repeatok == CRCInput::RC_down)
|
||||
{
|
||||
unsigned int prevselected=selected;
|
||||
unsigned int prevliststart = liststart;
|
||||
selected = (selected + 1) % filelist.size();
|
||||
liststart = (selected/listmaxshow)*listmaxshow;
|
||||
if(prevliststart != liststart)
|
||||
{
|
||||
paint();
|
||||
}
|
||||
else
|
||||
{
|
||||
paintItem(prevselected - prevliststart);
|
||||
paintItem(selected - liststart);
|
||||
}
|
||||
}
|
||||
else if (msg == CRCInput::RC_right)
|
||||
{
|
||||
if (filelist[selected].isDir())
|
||||
{
|
||||
#ifdef ENABLE_INTERNETRADIO
|
||||
if (m_Mode == ModeSC) {
|
||||
ChangeDir(filelist[selected].Url);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
if (filelist[selected].getFileName() != "..") {
|
||||
selections.push_back(selected);
|
||||
ChangeDir(filelist[selected].Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (msg == (neutrino_msg_t) g_settings.key_pagedown)
|
||||
{
|
||||
unsigned int last = filelist.size() - 1;
|
||||
if (selected != last && selected + listmaxshow >= filelist.size()) {
|
||||
selected = last;
|
||||
} else {
|
||||
selected = (selected == last) ? 0 : selected + listmaxshow;
|
||||
liststart = (selected / listmaxshow) * listmaxshow;
|
||||
}
|
||||
paint();
|
||||
}
|
||||
}
|
||||
else if (msg == CRCInput::RC_green || msg == (neutrino_msg_t) g_settings.key_pageup)
|
||||
else if (msg == (neutrino_msg_t) g_settings.key_pageup)
|
||||
{
|
||||
if (!(filelist.empty())) {
|
||||
if (selected && selected < listmaxshow) {
|
||||
selected = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
selected = selected ? selected - listmaxshow : filelist.size() - 1;
|
||||
liststart = (selected/listmaxshow)*listmaxshow;
|
||||
}
|
||||
paint();
|
||||
}
|
||||
}
|
||||
else if ( msg == CRCInput::RC_blue )
|
||||
{
|
||||
if(Filter != NULL)
|
||||
{
|
||||
use_filter = !use_filter;
|
||||
ChangeDir(Path);
|
||||
}
|
||||
}
|
||||
else if ( msg == CRCInput::RC_home )
|
||||
{
|
||||
loop = false;
|
||||
}
|
||||
else if ( msg == CRCInput::RC_spkr && strncmp(Path.c_str(), VLC_URI, strlen(VLC_URI)) != 0) //Not in vlc mode
|
||||
else if (msg == CRCInput::RC_spkr)
|
||||
{
|
||||
if(".." != (filelist[selected].getFileName().substr(0,2))) // do not delete that
|
||||
{
|
||||
std::stringstream _msg;
|
||||
_msg << g_Locale->getText(LOCALE_FILEBROWSER_DODELETE1) << " ";
|
||||
if (filelist[selected].getFileName().length() > 25)
|
||||
{
|
||||
_msg << filelist[selected].getFileName().substr(0, 25) << "...";
|
||||
}
|
||||
else
|
||||
_msg << filelist[selected].getFileName();
|
||||
|
||||
@@ -970,8 +801,6 @@ bool CFileBrowser::exec(const char * const dirname)
|
||||
}
|
||||
}
|
||||
else if (msg == CRCInput::RC_ok)
|
||||
{
|
||||
if (!(filelist.empty()))
|
||||
{
|
||||
bool has_selected = false;
|
||||
if (Multi_Select) {
|
||||
@@ -994,19 +823,16 @@ bool CFileBrowser::exec(const char * const dirname)
|
||||
else
|
||||
#endif
|
||||
{
|
||||
if ( !selections.empty() )
|
||||
{
|
||||
if (!selections.empty() ) {
|
||||
ChangeDir("..",selections.back());
|
||||
selections.pop_back();
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
std::string::size_type pos = Path.substr(0,Path.length()-1).rfind('/');
|
||||
if (pos != std::string::npos) {
|
||||
if (pos != std::string::npos)
|
||||
ChangeDir("..");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
bool return_dir = Hide_records && checkBD(filelist[selected]);
|
||||
@@ -1021,17 +847,14 @@ bool CFileBrowser::exec(const char * const dirname)
|
||||
selections.push_back(selected);
|
||||
ChangeDir(filelist[selected].Name);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
filelist[selected].Marked = true;
|
||||
loop = false;
|
||||
res = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (msg==CRCInput::RC_help)
|
||||
else if (msg == CRCInput::RC_help || msg == CRCInput::RC_red)
|
||||
{
|
||||
if (++g_settings.filebrowser_sortmethod >= FILEBROWSER_NUMBER_OF_SORT_VARIANTS)
|
||||
g_settings.filebrowser_sortmethod = 0;
|
||||
@@ -1043,29 +866,8 @@ bool CFileBrowser::exec(const char * const dirname)
|
||||
}
|
||||
else if (CRCInput::isNumeric(msg_repeatok))
|
||||
{
|
||||
if (!(filelist.empty()))
|
||||
SMSInput(msg_repeatok);
|
||||
}
|
||||
else if (msg == CRCInput::RC_sat || msg == CRCInput::RC_favorites) {
|
||||
//FIXME do nothing ?
|
||||
}
|
||||
else if (msg == NeutrinoMessages::STANDBY_ON ||
|
||||
msg == NeutrinoMessages::SHUTDOWN ||
|
||||
msg == NeutrinoMessages::SLEEPTIMER)
|
||||
{
|
||||
menu_ret = menu_return::RETURN_EXIT_ALL;
|
||||
loop = false;
|
||||
g_RCInput->postMsg(msg, data);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
if ( CNeutrinoApp::getInstance()->handleMsg( msg, data ) & messages_return::cancel_all )
|
||||
{
|
||||
menu_ret = menu_return::RETURN_EXIT_ALL;
|
||||
loop = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
hide();
|
||||
@@ -1103,8 +905,6 @@ bool CFileBrowser::exec(const char * const dirname)
|
||||
return res;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
void CFileBrowser::addRecursiveDir(CFileList * re_filelist, std::string rpath, bool bRootCall, CProgressWindow * progress)
|
||||
{
|
||||
neutrino_msg_t msg;
|
||||
@@ -1122,7 +922,7 @@ void CFileBrowser::addRecursiveDir(CFileList * re_filelist, std::string rpath, b
|
||||
// home key cancel scan
|
||||
bCancel=true;
|
||||
}
|
||||
else if (msg!=CRCInput::RC_timeout)
|
||||
else if (msg > CRCInput::RC_MaxRC && msg != CRCInput::RC_timeout)
|
||||
{
|
||||
// other event, save to low priority queue
|
||||
g_RCInput->postMsg( msg, data, false );
|
||||
@@ -1131,9 +931,7 @@ void CFileBrowser::addRecursiveDir(CFileList * re_filelist, std::string rpath, b
|
||||
return;
|
||||
|
||||
if ((m_Mode != ModeSC) && ((rpath.empty()) || ((*rpath.rbegin()) != '/')))
|
||||
{
|
||||
rpath += '/';
|
||||
}
|
||||
|
||||
CFileList tmplist;
|
||||
if(!readDir(rpath, &tmplist))
|
||||
@@ -1144,25 +942,21 @@ void CFileBrowser::addRecursiveDir(CFileList * re_filelist, std::string rpath, b
|
||||
{
|
||||
n = tmplist.size();
|
||||
if(progress)
|
||||
{
|
||||
progress->showStatusMessageUTF(FILESYSTEM_ENCODING_TO_UTF8_STRING(rpath));
|
||||
}
|
||||
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
if(progress)
|
||||
{
|
||||
progress->showGlobalStatus(100/n*i);
|
||||
}
|
||||
|
||||
std::string basename = tmplist[i].Name.substr(tmplist[i].Name.rfind('/')+1);
|
||||
if( basename != ".." )
|
||||
{
|
||||
if(Filter != NULL && (!tmplist[i].isDir()) && use_filter)
|
||||
{
|
||||
if(!Filter->matchFilter(tmplist[i].Name))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if(!tmplist[i].isDir())
|
||||
re_filelist->push_back(tmplist[i]);
|
||||
else
|
||||
@@ -1172,16 +966,11 @@ void CFileBrowser::addRecursiveDir(CFileList * re_filelist, std::string rpath, b
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
void CFileBrowser::hide()
|
||||
{
|
||||
frameBuffer->paintBackgroundBoxRel(x,y, width,height);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
void CFileBrowser::paintItem(unsigned int pos)
|
||||
{
|
||||
int colwidth1, colwidth2, colwidth3;
|
||||
@@ -1261,9 +1050,8 @@ void CFileBrowser::paintItem(unsigned int pos)
|
||||
const char * attribute = "xwr";
|
||||
char modestring[9 + 1];
|
||||
for (int m = 8; m >= 0; m--)
|
||||
{
|
||||
modestring[8 - m] = (actual_file->Mode & (1 << m)) ? attribute[m % 3] : '-';
|
||||
}
|
||||
|
||||
modestring[9] = 0;
|
||||
|
||||
fnt_item->RenderString(x + width - 25 - colwidth3 - colwidth2 , ypos+ fheight, colwidth2, modestring, color);
|
||||
@@ -1317,8 +1105,6 @@ void CFileBrowser::paintItem(unsigned int pos)
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
void CFileBrowser::paintHead()
|
||||
{
|
||||
char *l_name;
|
||||
@@ -1363,6 +1149,7 @@ bool chooserDir(char *setting_dir, bool test_dir, const char *action_str, size_t
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool chooserDir(std::string &setting_dir, bool test_dir, const char *action_str, bool allow_tmp)
|
||||
{
|
||||
const char *wrong_str = "Wrong/unsupported";
|
||||
@@ -1381,70 +1168,48 @@ bool chooserDir(std::string &setting_dir, bool test_dir, const char *action_str,
|
||||
return false;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
const struct button_label FileBrowserFilterButton[2] =
|
||||
{
|
||||
{ NEUTRINO_ICON_BUTTON_BLUE , LOCALE_FILEBROWSER_FILTER_INACTIVE },
|
||||
{ NEUTRINO_ICON_BUTTON_BLUE , LOCALE_FILEBROWSER_FILTER_ACTIVE },
|
||||
};
|
||||
|
||||
void CFileBrowser::paintFoot()
|
||||
int CFileBrowser::paintFoot(bool show)
|
||||
{
|
||||
struct button_label FileBrowserButtons[4] =
|
||||
{
|
||||
{ NEUTRINO_ICON_BUTTON_RED , LOCALE_FILEBROWSER_NEXTPAGE },
|
||||
{ NEUTRINO_ICON_BUTTON_GREEN , LOCALE_FILEBROWSER_PREVPAGE },
|
||||
{ NEUTRINO_ICON_BUTTON_YELLOW, LOCALE_FILEBROWSER_MARK },
|
||||
};
|
||||
std::string sort_text = g_Locale->getText(LOCALE_MOVIEBROWSER_FOOT_SORT);
|
||||
sort_text += g_Locale->getText(sortByNames[g_settings.filebrowser_sortmethod]);
|
||||
|
||||
const struct button_label FileBrowserButtons2[3] =
|
||||
{
|
||||
{ NEUTRINO_ICON_BUTTON_OKAY , LOCALE_FILEBROWSER_SELECT },
|
||||
{ NEUTRINO_ICON_BUTTON_HELP , sortByNames[g_settings.filebrowser_sortmethod] },
|
||||
{ NEUTRINO_ICON_BUTTON_MUTE_SMALL , LOCALE_FILEBROWSER_DELETE },
|
||||
};
|
||||
int sort_text_len = g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_SMALL]->getRenderWidth(g_Locale->getText(LOCALE_MOVIEBROWSER_FOOT_SORT));
|
||||
int len = 0;
|
||||
for (int i = 0; i < FILEBROWSER_NUMBER_OF_SORT_VARIANTS; i++)
|
||||
len = std::max(len, g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_SMALL]->getRenderWidth(g_Locale->getText(sortByNames[i])));
|
||||
|
||||
//y first line
|
||||
int by1 = y + height - (2 * foheight );
|
||||
//y second line
|
||||
int by2 = by1 + foheight;
|
||||
//width
|
||||
sort_text_len += len;
|
||||
|
||||
neutrino_locale_t f_loc = LOCALE_FILEBROWSER_FILTER_INACTIVE;
|
||||
if (Filter != NULL && use_filter)
|
||||
f_loc = LOCALE_FILEBROWSER_FILTER_ACTIVE;
|
||||
|
||||
button_label_ext footerButtons[] = {
|
||||
{ NEUTRINO_ICON_BUTTON_RED, NONEXISTANT_LOCALE, sort_text.c_str(), sort_text_len, false },
|
||||
{ NEUTRINO_ICON_BUTTON_OKAY, LOCALE_FILEBROWSER_SELECT, NULL, 0, false },
|
||||
{ NEUTRINO_ICON_BUTTON_MUTE_SMALL, LOCALE_FILEBROWSER_DELETE, NULL, 0, false },
|
||||
{ NEUTRINO_ICON_BUTTON_PLAY, LOCALE_FILEBROWSER_MARK, NULL, 0, false },
|
||||
{ NEUTRINO_ICON_BUTTON_BLUE, f_loc, NULL, 0, false },
|
||||
};
|
||||
int cnt = sizeof(footerButtons) / sizeof(button_label_ext);
|
||||
int fowidth = width - skwidth;
|
||||
|
||||
//background
|
||||
frameBuffer->paintBoxRel(x, by1, width, (2 * foheight ), COL_INFOBAR_SHADOW_PLUS_1, RADIUS_MID, CORNER_BOTTOM);
|
||||
if (!show)
|
||||
return paintButtons(footerButtons, cnt, 0, 0, 0, 0, 0, false, NULL, NULL);
|
||||
|
||||
|
||||
if (!(filelist.empty()))
|
||||
{
|
||||
int idx = 1;
|
||||
int num_buttons = Multi_Select ? 3 : 2;
|
||||
if (Filter != NULL)
|
||||
{
|
||||
FileBrowserButtons[num_buttons].button = FileBrowserFilterButton[!use_filter].button;
|
||||
FileBrowserButtons[num_buttons].locale = FileBrowserFilterButton[!use_filter].locale;
|
||||
num_buttons++;
|
||||
if (filelist.empty()) {
|
||||
frameBuffer->paintBoxRel(x, y + height - foheight, width, foheight, COL_INFOBAR_SHADOW_PLUS_1, RADIUS_MID, CORNER_BOTTOM);
|
||||
return foheight;
|
||||
}
|
||||
//red, green, yellow button
|
||||
::paintButtons(x, by1, 0, num_buttons, FileBrowserButtons, fowidth, foheight);
|
||||
|
||||
/* TODO: the changing existence of the OK button makes the sort button
|
||||
* shift its place :-( */
|
||||
num_buttons = 1;
|
||||
//OK-Button
|
||||
if ((filelist[selected].getType() != CFile::FILE_UNKNOWN) || filelist[selected].isDir())
|
||||
{
|
||||
idx = 0;
|
||||
num_buttons++;
|
||||
}
|
||||
if (strncmp(Path.c_str(), VLC_URI, strlen(VLC_URI)) != 0) // No delete in vlc mode
|
||||
num_buttons++;
|
||||
|
||||
::paintButtons(x, by2, 0, num_buttons, &(FileBrowserButtons2[idx]), fowidth, foheight);
|
||||
|
||||
int res = paintButtons(footerButtons, Filter ? cnt : cnt - 1, x, y + height - foheight, width, foheight, fowidth);
|
||||
paintSMSKey();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void CFileBrowser::paintSMSKey()
|
||||
@@ -1452,25 +1217,21 @@ void CFileBrowser::paintSMSKey()
|
||||
int skheight = fnt_small->getHeight();
|
||||
|
||||
//background
|
||||
frameBuffer->paintBoxRel(x + width - skwidth, y + height - foheight - (skheight/2), skwidth, skheight, COL_INFOBAR_SHADOW_PLUS_1);
|
||||
frameBuffer->paintBoxRel(x + width - skwidth, y + height - foheight, skwidth, foheight, COL_INFOBAR_SHADOW_PLUS_1, RADIUS_MID, CORNER_BOTTOM_RIGHT);
|
||||
|
||||
if(m_SMSKeyInput.getOldKey()!=0)
|
||||
{
|
||||
char cKey[2] = {m_SMSKeyInput.getOldKey(), 0};
|
||||
cKey[0] = toupper(cKey[0]);
|
||||
int len = fnt_small->getRenderWidth(cKey);
|
||||
fnt_small->RenderString(x + width - skwidth, y + height - foheight + (skheight/2), len, cKey, COL_MENUHEAD_TEXT);
|
||||
fnt_small->RenderString(x + width - skwidth, y + height - foheight + foheight/2 + skheight/2, len, cKey, COL_MENUHEAD_TEXT);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
void CFileBrowser::paint()
|
||||
{
|
||||
liststart = (selected/listmaxshow)*listmaxshow;
|
||||
|
||||
// if (filelist[0].Name.length() != 0)
|
||||
// frameBuffer->paintIcon(NEUTRINO_ICON_BUTTON_HELP, x+ width- 30, y+ 5 );
|
||||
CVFD::getInstance()->setMode(CVFD::MODE_MENU_UTF8, g_Locale->getText(LOCALE_FILEBROWSER_HEAD));
|
||||
|
||||
for(unsigned int count=0;count<listmaxshow;count++)
|
||||
@@ -1489,8 +1250,6 @@ void CFileBrowser::paint()
|
||||
frameBuffer->paintBoxRel(x+ width- 13, ypos+ 2+ sbs*(sb-4)/sbc, 11, (sb-4)/sbc, COL_MENUCONTENT_PLUS_3, RADIUS_SMALL);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
void CFileBrowser::SMSInput(const neutrino_msg_t msg)
|
||||
{
|
||||
unsigned char key = m_SMSKeyInput.handleMsg(msg);
|
||||
@@ -1499,39 +1258,32 @@ void CFileBrowser::SMSInput(const neutrino_msg_t msg)
|
||||
for(i=(selected+1) % filelist.size(); i != selected ; i= (i+1) % filelist.size())
|
||||
{
|
||||
if(tolower(filelist[i].getFileName()[0]) == key)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
int prevselected=selected;
|
||||
selected=i;
|
||||
paintItem(prevselected - liststart);
|
||||
unsigned int oldliststart = liststart;
|
||||
liststart = (selected/listmaxshow)*listmaxshow;
|
||||
|
||||
if(oldliststart!=liststart)
|
||||
{
|
||||
paint();
|
||||
}
|
||||
else
|
||||
{
|
||||
paintItem(selected - liststart);
|
||||
}
|
||||
paintSMSKey();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
void CFileBrowser::recursiveDelete(const char* file)
|
||||
{
|
||||
stat_struct statbuf;
|
||||
dirent_struct **namelist;
|
||||
struct stat64 statbuf;
|
||||
dirent64 **namelist;
|
||||
int n;
|
||||
printf("Delete %s\n", file);
|
||||
if(my_lstat(file,&statbuf) == 0)
|
||||
if(lstat64(file,&statbuf) == 0)
|
||||
{
|
||||
if(S_ISDIR(statbuf.st_mode))
|
||||
{
|
||||
n = my_scandir(file, &namelist, 0, my_alphasort);
|
||||
n = scandir64(file, &namelist, 0, alphasort64);
|
||||
while(n--)
|
||||
{
|
||||
if(strcmp(namelist[n]->d_name, ".")!=0 && strcmp(namelist[n]->d_name, "..")!=0)
|
||||
|
@@ -54,7 +54,6 @@
|
||||
#include <vector>
|
||||
|
||||
#define ENABLE_INTERNETRADIO
|
||||
#define VLC_URI "vlc://"
|
||||
|
||||
bool chooserDir(std::string &setting_dir, bool test_dir, const char *action_str, bool allow_tmp = false);
|
||||
bool chooserDir(char *setting_dir, bool test_dir, const char *action_str, size_t str_leng, bool allow_tmp = false);
|
||||
@@ -152,9 +151,6 @@ class CFileBrowser
|
||||
|
||||
CFileList selected_filelist;
|
||||
bool readDir(const std::string & dirname, CFileList* flist);
|
||||
#ifdef ENABLE_MOVIEPLAYER_VLC
|
||||
bool readDir_vlc(const std::string & dirname, CFileList* flist);
|
||||
#endif
|
||||
bool readDir_std(const std::string & dirname, CFileList* flist);
|
||||
#ifdef ENABLE_INTERNETRADIO
|
||||
bool readDir_sc(const std::string & dirname, CFileList* flist);
|
||||
@@ -188,7 +184,7 @@ class CFileBrowser
|
||||
void paintItem(unsigned pos);
|
||||
void paint();
|
||||
void paintHead();
|
||||
void paintFoot();
|
||||
int paintFoot(bool show = true);
|
||||
void paintSMSKey();
|
||||
void recursiveDelete(const char* file);
|
||||
|
||||
@@ -201,7 +197,6 @@ class CFileBrowser
|
||||
|
||||
typedef enum {
|
||||
ModeFile,
|
||||
ModeVLC,
|
||||
ModeSC
|
||||
} tFileBrowserMode;
|
||||
|
||||
|
Reference in New Issue
Block a user