if ( this->current_folder.compare("") == 0 ) {
this->enter_folder("/");
} else {
- this->enter_folder(this->current_folder);
+ this->enter_folder(this->current_folder.c_str());
}
}
}
// Enter a new folder
-void FileScreen::enter_folder(std::string folder)
+void FileScreen::enter_folder(const char *folder)
{
-
// Remember where we are
this->current_folder = folder;
// We need the number of lines to setup the menu
- uint16_t number_of_files_in_folder = this->count_folder_content(this->current_folder);
+ uint16_t number_of_files_in_folder = this->count_folder_content(this->current_folder.c_str());
// Setup menu
THEPANEL->setup_menu(number_of_files_in_folder + 1); // same number of files as menu items
if ( this->current_folder[this->current_folder.length() - 1] == '/' && this->current_folder.length() != 1 ) {
this->current_folder.erase(this->current_folder.length() - 1, 1);
}
- this->enter_folder(this->current_folder);
+ this->enter_folder(this->current_folder.c_str());
}
} else {
//printf("enter file\r\n");
// Enter file
string path = this->current_folder;
- if ( path.compare("/") == 0 ) {
+ if(path.compare("/") == 0) {
path = "";
}
path = path + "/" + this->file_at( line - 1 );
- if ( this->is_a_folder( path ) ) {
- this->enter_folder(path);
+ if(this->is_a_folder(path.c_str())) {
+ this->enter_folder(path.c_str());
return;
}
}
// Check wether a line is a folder or a file
-bool FileScreen::is_a_folder( string path )
+bool FileScreen::is_a_folder(const char *path)
{
- // In the special case of /local/ ( the mbed flash chip ) we don't have sub-folders, everything is a file
- if ( path.substr(0, 7).compare("/local/") == 0 ) {
- return false;
- }
// Else, check if it's a folder or not
DIR *d;
- d = opendir(path.c_str());
+ d = opendir(path);
if (d == NULL) {
return false;
} else {
}
}
+bool FileScreen::filter_file(const char *f)
+{
+ string fn= lc(f);
+ string path = this->current_folder;
+ if(path == "/") path= "";
+ path= path + "/" + fn;
+ // only filter files that have a .g in them and directories
+ return (is_a_folder(path.c_str()) || fn.find(".g") != string::npos);
+}
+
// Find the "line"th file in the current folder
string FileScreen::file_at(uint16_t line)
{
d = opendir(this->current_folder.c_str());
if (d != NULL) {
while ((p = readdir(d)) != NULL) {
- string fn= lc(string(p->d_name));
- // only filter files that have a .g in them
- if(fn.find(".g") != string::npos && count++ == line ) {
+ // only filter files that have a .g in them and directories
+ if(filter_file(p->d_name) && count++ == line ) {
closedir(d);
- return fn;
+ return p->d_name;
}
}
}
}
// Count how many files there are in the current folder that have a .g in them
-uint16_t FileScreen::count_folder_content(std::string folder)
+uint16_t FileScreen::count_folder_content(const char *folder)
{
DIR *d;
struct dirent *p;
uint16_t count = 0;
- d = opendir(folder.c_str());
+ d = opendir(folder);
if (d != NULL) {
while ((p = readdir(d)) != NULL) {
- string fn= lc(string(p->d_name));
- if(fn.find(".g") != string::npos)
- count++;
+ if(filter_file(p->d_name)) count++;
}
closedir(d);
return count;
- } else {
- return 0;
}
+ return 0;
}
+
void FileScreen::on_main_loop()
{
if (this->start_play) {
void on_enter();
void on_refresh();
void on_main_loop();
- void enter_folder(std::string folder);
- uint16_t count_folder_content(std::string folder);
void clicked_line(uint16_t line);
void display_menu_line(uint16_t line);
- bool is_a_folder( string path );
- string file_at(uint16_t line);
-
- std::string current_folder;
private:
+ void enter_folder(const char *folder);
+ bool is_a_folder(const char *path );
+ uint16_t count_folder_content(const char *folder);
+ string file_at(uint16_t line);
+ bool filter_file(const char *f);
void play(string path);
- bool start_play;
+
+ std::string current_folder;
string play_path;
+ bool start_play;
};