From edcd71e1de45196ec8f14ffa6cf7659ea2c0221f Mon Sep 17 00:00:00 2001 From: "jsc@umbraculum.org" Date: Fri, 26 Apr 2013 11:43:03 +0200 Subject: Fixed lot of stuff. --- plugingui/directory.cc | 20 ++++++++++++++++---- plugingui/directory.h | 3 ++- plugingui/filebrowser.cc | 11 +++++++---- 3 files changed, 25 insertions(+), 9 deletions(-) (limited to 'plugingui') diff --git a/plugingui/directory.cc b/plugingui/directory.cc index 5f80508..7e7d7e1 100644 --- a/plugingui/directory.cc +++ b/plugingui/directory.cc @@ -53,8 +53,7 @@ void Directory::refresh() { bool Directory::cd(std::string dir) { DEBUG(directory, "Changing to '%s'\n", dir.c_str()); - int r = chdir( (path() + "/" + dir).c_str() ); - if(!r) { + if(exists(path() + "/" + dir)) { _path += "/" + dir; refresh(); return true; @@ -114,9 +113,12 @@ std::string Directory::cleanPath(std::string path) { } Directory::EntryList Directory::listFiles(std::string path) { + DEBUG(directory, "Listing files in '%s'\n", path.c_str()); + Directory::EntryList entries; - DIR *dir = opendir("."); + DIR *dir = opendir(path.c_str()); if(!dir) { + DEBUG(directory, "Couldn't open directory '%s\n", path.c_str()); return entries; } @@ -129,6 +131,8 @@ Directory::EntryList Directory::listFiles(std::string path) { } bool Directory::isRoot(std::string path) { + //TODO: Handle WIN32 + if(path == "/") return true; else return false; } @@ -160,10 +164,18 @@ bool Directory::isDir() return isDir(path()); } -bool Directory::exists(std::string filename) { +bool Directory::fileExists(std::string filename) { return !isDir(path() + "/" + filename); } +bool Directory::exists(std::string path) { + struct stat st; + if(stat(path.c_str(), &st) == 0) { + return true; + } + else return false; +} + bool Directory::isDir(std::string path) { DEBUG(directory, "Is '%s' dir?\n", path.c_str()); struct stat st; diff --git a/plugingui/directory.h b/plugingui/directory.h index 53213ee..48b0dd4 100644 --- a/plugingui/directory.h +++ b/plugingui/directory.h @@ -57,7 +57,7 @@ class Directory { bool cd(std::string dir); bool isDir(); void setPath(std::string path); - bool exists(std::string file); + bool fileExists(std::string file); // Add filter, ie. directories or files only EntryList entryList(); @@ -70,6 +70,7 @@ class Directory { static bool isRoot(std::string path); static Directory::DriveList drives(); static bool isDir(std::string path); + static bool exists(std::string file); private: std::string _path; diff --git a/plugingui/filebrowser.cc b/plugingui/filebrowser.cc index d64a0ab..d9b3250 100644 --- a/plugingui/filebrowser.cc +++ b/plugingui/filebrowser.cc @@ -75,7 +75,7 @@ static void changeDir(void *ptr) { INFO(filebrowser, "Changing dir to '%s'\n", (dir->path() + "/" + value).c_str()); - if(!value.empty() && dir->exists(value)) { + if(!value.empty() && dir->fileExists(value)) { std::string file = dir->path() + "/" + value; DEBUG(filebrowser, "Selecting file '%s'\n", file.c_str()); if(prv->filesel_handler) prv->filesel_handler(prv->ptr, file); @@ -271,10 +271,13 @@ static bool isDir(std::string d) void GUI::FileBrowser::setPath(std::string path) { - // TODO: Remove this check to directoy.cc - if(path.empty()) return; + WARN(filebrowser, "Not implemented yet!"); + // TODO: Remove this check to directoy.cc +// INFO(filebrowser, "Setting path to '%s'\n", path.c_str()); +// if(path.empty()) return; - prv->dir->setPath(path); + // TODO: Strip path to set path to a directory +// prv->dir->setPath(path); /* std::string dir; if(prv->dir->isDir()) { -- cgit v1.2.3