Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/edge' into update/gcc4.8
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfmanjm committed Sep 14, 2014
2 parents ce6ee09 + 378e2ef commit 2f2c215
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 38 deletions.
6 changes: 2 additions & 4 deletions src/libs/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,13 @@ string absolute_from_relative( string path )
return path;
}

string match = "../" ;
while ( path.substr(0, 3) == match ) {
while ( path.substr(0, 3) == "../" ) {
path = path.substr(3);
unsigned found = cwd.find_last_of("/");
cwd = cwd.substr(0, found);
}

match = ".." ;
if ( path.substr(0, 2) == match ) {
if ( path.substr(0, 2) == ".." ) {
path = path.substr(2);
unsigned found = cwd.find_last_of("/");
cwd = cwd.substr(0, found);
Expand Down
45 changes: 17 additions & 28 deletions src/modules/utils/panel/screens/FileScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@
#include "DirHandle.h"
#include "mri.h"

using namespace std;
using std::string;

FileScreen::FileScreen()
{
this->current_folder = "";
this->start_play = false;
}

Expand All @@ -33,11 +32,7 @@ void FileScreen::on_enter()
THEPANEL->lcd->clear();

// Default folder to enter
if ( this->current_folder.compare("") == 0 ) {
this->enter_folder("/");
} else {
this->enter_folder(this->current_folder.c_str());
}
this->enter_folder(THEKERNEL->current_path.c_str());
}

// For every ( potential ) refresh of the screen
Expand All @@ -55,10 +50,10 @@ void FileScreen::on_refresh()
void FileScreen::enter_folder(const char *folder)
{
// Remember where we are
this->current_folder = folder;
THEKERNEL->current_path= 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.c_str());
uint16_t number_of_files_in_folder = this->count_folder_content();

// Setup menu
THEPANEL->setup_menu(number_of_files_in_folder + 1); // same number of files as menu items
Expand All @@ -82,25 +77,21 @@ void FileScreen::display_menu_line(uint16_t line)
void FileScreen::clicked_line(uint16_t line)
{
if ( line == 0 ) {
if ( this->current_folder.compare("/") == 0 ) {
string path= THEKERNEL->current_path;
if(path == "/") {
// Exit file navigation
THEPANEL->enter_screen(this->parent);
} else {
// Go up one folder
this->current_folder = this->current_folder.substr(0, this->current_folder.find_last_of('/') + 1);
if ( this->current_folder[this->current_folder.length() - 1] == '/' && this->current_folder.length() != 1 ) {
this->current_folder.erase(this->current_folder.length() - 1, 1);
path = path.substr(0, path.find_last_of('/'));
if (path.empty()) {
path= "/";
}
this->enter_folder(this->current_folder.c_str());
this->enter_folder(path.c_str());
}
} else {
//printf("enter file\r\n");
// Enter file
string path = this->current_folder;
if(path.compare("/") == 0) {
path = "";
}
path = path + "/" + this->file_at( line - 1 );
string path= absolute_from_relative(this->file_at(line - 1));
if(this->is_a_folder(path.c_str())) {
this->enter_folder(path.c_str());
return;
Expand Down Expand Up @@ -130,9 +121,7 @@ bool FileScreen::is_a_folder(const char *path)
bool FileScreen::filter_file(const char *f)
{
string fn= lc(f);
string path = this->current_folder;
if(path == "/") path= "";
path= path + "/" + fn;
string path= absolute_from_relative(fn);
// only filter files that have a .g in them and directories
return (is_a_folder(path.c_str()) || fn.find(".g") != string::npos);
}
Expand All @@ -143,7 +132,7 @@ string FileScreen::file_at(uint16_t line)
DIR *d;
struct dirent *p;
uint16_t count = 0;
d = opendir(this->current_folder.c_str());
d = opendir(THEKERNEL->current_path.c_str());
if (d != NULL) {
while ((p = readdir(d)) != NULL) {
// only filter files that have a .g in them and directories
Expand All @@ -159,12 +148,12 @@ string FileScreen::file_at(uint16_t line)
}

// Count how many files there are in the current folder that have a .g in them
uint16_t FileScreen::count_folder_content(const char *folder)
uint16_t FileScreen::count_folder_content()
{
DIR *d;
struct dirent *p;
uint16_t count = 0;
d = opendir(folder);
d = opendir(THEKERNEL->current_path.c_str());
if (d != NULL) {
while ((p = readdir(d)) != NULL) {
if(filter_file(p->d_name)) count++;
Expand All @@ -180,13 +169,13 @@ void FileScreen::on_main_loop()
if (this->start_play) {
this->start_play = false;
THEPANEL->set_playing_file(this->play_path);
this->play(this->play_path);
this->play(this->play_path.c_str());
THEPANEL->enter_screen(this->parent);
return;
}
}

void FileScreen::play(string path)
void FileScreen::play(const char *path)
{
struct SerialMessage message;
message.message = string("play ") + path;
Expand Down
10 changes: 4 additions & 6 deletions src/modules/utils/panel/screens/FileScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "PanelScreen.h"

#include <string>
using namespace std;

class FileScreen : public PanelScreen {
public:
Expand All @@ -25,13 +24,12 @@ class FileScreen : public PanelScreen {
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);
uint16_t count_folder_content();
std::string file_at(uint16_t line);
bool filter_file(const char *f);
void play(string path);
void play(const char *path);

std::string current_folder;
string play_path;
std::string play_path;
bool start_play;
};

Expand Down

0 comments on commit 2f2c215

Please sign in to comment.