summaryrefslogtreecommitdiff
path: root/plugingui
diff options
context:
space:
mode:
authorJonas Suhr Christensen <jsc@umbraculum.org>2013-05-04 19:27:32 +0200
committerJonas Suhr Christensen <jsc@umbraculum.org>2013-05-04 19:27:32 +0200
commita93d2e811f26d291d2c1983318f585906c9b6d46 (patch)
treea41665a9124f3539d8b14ac37da9fdaf3d95f428 /plugingui
parent6704a42a9b6e253ceb02a89523deb405f5d85300 (diff)
Attempt to handle windows path in filebrowser
Diffstat (limited to 'plugingui')
-rw-r--r--plugingui/directory.cc66
-rw-r--r--plugingui/directory.h2
-rw-r--r--plugingui/filebrowser.cc35
3 files changed, 84 insertions, 19 deletions
diff --git a/plugingui/directory.cc b/plugingui/directory.cc
index 44f24a4..c124cb1 100644
--- a/plugingui/directory.cc
+++ b/plugingui/directory.cc
@@ -36,6 +36,15 @@
#include <hugin.hpp>
+// http://en.wikipedia.org/wiki/Path_(computing)
+#ifdef WIN32
+ #define SEP "\\"
+#else
+ #define SEP "/"
+#endif
+
+
+
Directory::Directory(std::string path) {
setPath(path);
}
@@ -62,8 +71,8 @@ bool Directory::cd(std::string dir) {
if(dir.empty() || dir == ".") return true;
DEBUG(directory, "Changing to '%s'\n", dir.c_str());
- if(exists(_path + "/" + dir)) {
- std::string path = _path + "/" + dir;
+ if(exists(_path + SEP + dir)) {
+ std::string path = _path + SEP + dir;
setPath(path);
refresh();
return true;
@@ -95,7 +104,7 @@ std::string Directory::cwd() {
std::string Directory::cleanPath(std::string path) {
- WARN(directory, "Cleaning path '%s'\n", path.c_str());
+ DEBUG(directory, "Cleaning path '%s'\n", path.c_str());
Directory::Path pathlst = parsePath(path);
return Directory::pathToStr(pathlst);
@@ -115,7 +124,9 @@ Directory::EntryList Directory::listFiles(std::string path) {
while((entry = readdir(dir)) != NULL) {
std::string name = entry->d_name;
if(name == ".") continue;
+
if(Directory::isRoot(path) && name == "..") continue;
+
entries.push_back(entry->d_name);
}
@@ -123,10 +134,41 @@ Directory::EntryList Directory::listFiles(std::string path) {
}
bool Directory::isRoot(std::string path) {
- //TODO: Handle WIN32
-
+#ifdef WIN32
+ // TODO: This is not a correct root calculation, but works with partitions
+ if(path.size() == 2) {
+ if(path == root()) return true;
+ else return false;
+ }
+ else if (path.size() == 3) {
+ if(path == root() + SEP) return true;
+ return false;
+ }
+ else {
+ return false;
+ }
+#else
if(path == "/") return true;
else return false;
+#endif
+}
+
+std::string Directory::root() {
+ return root(cwd());
+}
+
+// TODO: Handle windows root
+std::string Directory::root(std::string path) {
+#ifdef WIN32
+ if(path.size() < 3) {
+ return "c:"; // just something default when input is bad
+ }
+ else {
+ return path.substr(0, 2);
+ }
+#else
+ return "/";
+#endif
}
Directory::DriveList Directory::drives() {
@@ -154,7 +196,7 @@ bool Directory::isDir()
}
bool Directory::fileExists(std::string filename) {
- return !isDir(_path + "/" + filename);
+ return !isDir(_path + SEP + filename);
}
bool Directory::exists(std::string path) {
@@ -190,8 +232,8 @@ Directory::Path Directory::parsePath(std::string path_str) {
for(size_t c = 0; c < path_str.size(); c++) {
current_char = path_str.at(c);
- if(current_char == "/") {
- if(prev_char == "/") {
+ if(current_char == SEP) {
+ if(prev_char == SEP) {
dir.clear();
prev_char = current_char;
continue;
@@ -224,18 +266,20 @@ Directory::Path Directory::parsePath(std::string path_str) {
std::string Directory::pathToStr(Directory::Path& path) {
std::string cleaned_path;
- DEBUG(directory, "Number of directories in path %d\n", path.size());
+ DEBUG(directory, "Number of directories in path is %d\n", path.size());
for(Directory::Path::iterator it = path.begin();
it != path.end(); it++) {
std::string dir = *it;
DEBUG(directory, "\tDir '%s'\n", dir.c_str());
- cleaned_path += "/" + dir;
+ cleaned_path += SEP + dir;
}
DEBUG(directory, "Cleaned path '%s'\n", cleaned_path.c_str());
- if(cleaned_path.empty()) cleaned_path = "/";
+ if(cleaned_path.empty()) {
+ cleaned_path = Directory::root();
+ }
return cleaned_path;
}
diff --git a/plugingui/directory.h b/plugingui/directory.h
index 391bf45..9e184d4 100644
--- a/plugingui/directory.h
+++ b/plugingui/directory.h
@@ -65,6 +65,8 @@ class Directory {
//void setSorting();
static std::string cwd();
+ static std::string root();
+ static std::string root(std::string path);
static std::string cleanPath(std::string path);
static Directory::EntryList listFiles(std::string path);
static bool isRoot(std::string path);
diff --git a/plugingui/filebrowser.cc b/plugingui/filebrowser.cc
index 21e3cc8..bb6f5de 100644
--- a/plugingui/filebrowser.cc
+++ b/plugingui/filebrowser.cc
@@ -97,15 +97,34 @@ static void changeDir(void *ptr) {
lb->clear();
std::vector<GUI::ListBoxBasic::Item> items;
- Directory::EntryList entries = dir->entryList();
- for(Directory::EntryList::iterator it = entries.begin();
- it != entries.end(); it++) {
- GUI::ListBoxBasic::Item item;
- std::string name = *it;
- item.name = name;
- item.value = name;
- items.push_back(item);
+
+#ifdef WIN32
+ if(Directory::isRoot(dir->path()) && value == "..") {
+ DEBUG(filebrowser, "Showing partitions...\n");
+ Directory::DriveList entries = dir->drives();
+ for(Directory::DriveList::iterator it = entries.begin();
+ it != entries.end(); it++) {
+ GUI::ListBoxBasic::Item item;
+ std::string name = (*it).name;
+ item.name = name;
+ item.value = name;
+ items.push_back(item);
+ }
}
+ else {
+#endif
+ Directory::EntryList entries = dir->entryList();
+ for(Directory::EntryList::iterator it = entries.begin();
+ it != entries.end(); it++) {
+ GUI::ListBoxBasic::Item item;
+ std::string name = *it;
+ item.name = name;
+ item.value = name;
+ items.push_back(item);
+ }
+#ifdef WIN32
+ }
+#endif
lb->addItems(items);
}