commit f78163870d0168de2f28b388543e13573c3fa8a6
parent db756818fd4c09e2813cf8ba062378ba304de736
Author: cfillion <cfillion@users.noreply.github.com>
Date: Sun, 15 Oct 2017 10:55:17 -0400
about: split File column into File and Path in the Concents path
(+ some code cleanup)
Diffstat:
7 files changed, 74 insertions(+), 67 deletions(-)
diff --git a/src/about.cpp b/src/about.cpp
@@ -523,7 +523,8 @@ void AboutPackageDelegate::init(About *dialog)
dialog->menu()->addColumn({"Version", 142, 0, ListView::VersionType});
- dialog->list()->addColumn({"File", 474});
+ dialog->list()->addColumn({"File", 267});
+ dialog->list()->addColumn({"Path", 207});
dialog->list()->addColumn({"Action List", 84});
dialog->menu()->reserveRows(m_package->versions().size());
@@ -588,7 +589,8 @@ void AboutPackageDelegate::updateList(const int index)
int c = 0;
auto row = m_dialog->list()->createRow((void *)src);
- row->setCell(c++, src->targetPath().join());
+ row->setCell(c++, src->targetPath().basename());
+ row->setCell(c++, src->targetPath().dirname().join());
row->setCell(c++, actionList);
}
}
diff --git a/src/path.cpp b/src/path.cpp
@@ -143,6 +143,22 @@ void Path::removeLast()
m_parts.pop_back();
}
+string Path::front() const
+{
+ if(empty())
+ return {};
+
+ return m_parts.front();
+}
+
+string Path::basename() const
+{
+ if(empty())
+ return {};
+
+ return m_parts.back();
+}
+
Path Path::dirname() const
{
if(empty())
@@ -180,22 +196,6 @@ string Path::join(const bool nativeSeparator) const
return path;
}
-string Path::first() const
-{
- if(empty())
- return {};
-
- return m_parts.front();
-}
-
-string Path::last() const
-{
- if(empty())
- return {};
-
- return m_parts.back();
-}
-
bool Path::startsWith(const Path &o) const
{
if(size() < o.size() || absolute() != o.absolute())
diff --git a/src/path.hpp b/src/path.hpp
@@ -45,9 +45,9 @@ public:
bool absolute() const { return m_absolute; }
Path dirname() const;
+ std::string front() const;
+ std::string basename() const;
std::string join(bool nativeSeparator = true) const;
- std::string first() const;
- std::string last() const;
bool startsWith(const Path &) const;
Path prependRoot() const;
diff --git a/src/source.cpp b/src/source.cpp
@@ -42,11 +42,11 @@ auto Source::getSection(const char *name) -> Section
return UnknownSection;
}
-auto Source::detectSection(const string &category) -> Section
+auto Source::detectSection(const Path &category) -> Section
{
// this is for compatibility with indexes made for v1.0
- string topcategory = Path(category).first();
+ string topcategory = category.front();
boost::algorithm::to_lower(topcategory);
if(topcategory == "midi editor")
diff --git a/src/source.hpp b/src/source.hpp
@@ -39,7 +39,7 @@ public:
};
static Section getSection(const char *);
- static Section detectSection(const std::string &category);
+ static Section detectSection(const Path &category);
Source(const std::string &file, const std::string &url, const Version *);
const Version *version() const { return m_version; }
diff --git a/test/path.cpp b/test/path.cpp
@@ -19,36 +19,57 @@ TEST_CASE("compare paths", M) {
REQUIRE_FALSE(a != a);
}
-TEST_CASE("append path components", M) {
+TEST_CASE("append path segments", M) {
Path path;
REQUIRE(path.empty());
REQUIRE(path.size() == 0);
- REQUIRE(path.join() == string());
- REQUIRE(path.dirname().empty());
- path.append("hello");
+ path.append(string());
+ REQUIRE(path.empty());
+ REQUIRE(path.size() == 0);
+
+ path.append("foo");
REQUIRE_FALSE(path.empty());
REQUIRE(path.size() == 1);
- REQUIRE(path.join() == "hello");
- REQUIRE(path.dirname().empty());
- path.append("world");
+ path.append("bar");
REQUIRE(path.size() == 2);
-#ifndef _WIN32
- REQUIRE(path.join() == "hello/world");
-#else
- REQUIRE(path.join() == "hello\\world");
-#endif
- REQUIRE(path.dirname().join() == "hello");
- path.append("test");
+ path.append("baz");
REQUIRE(path.size() == 3);
-#ifndef _WIN32
- REQUIRE(path.join() == "hello/world/test");
-#else
- REQUIRE(path.join() == "hello\\world\\test");
-#endif
- REQUIRE(path.dirname() == Path("hello/world"));
+}
+
+TEST_CASE("path dirname", M) {
+ Path path;
+ REQUIRE(path.dirname().empty());
+
+ path.append("foo");
+ REQUIRE(path.dirname().empty());
+
+ path.append("bar");
+ REQUIRE(path.dirname() == Path("foo"));
+
+ path.append("baz");
+ REQUIRE(path.dirname() == Path("foo/bar"));
+}
+
+TEST_CASE("path basename", M) {
+ Path path;
+ REQUIRE(path.basename().empty());
+
+ path.append("foo");
+ REQUIRE(path.basename() == "foo");
+
+ path.append("bar");
+ REQUIRE(path.basename() == "bar");
+}
+
+TEST_CASE("path first segment", M) {
+ Path path;
+ REQUIRE(path.front().empty());
+
+ path.append("foo");
+ REQUIRE(path.front() == "foo");
}
TEST_CASE("concatenate paths", M) {
@@ -63,13 +84,6 @@ TEST_CASE("concatenate paths", M) {
REQUIRE(a + "world" == c);
}
-TEST_CASE("empty components", M) {
- Path a;
- a.append(string());
-
- REQUIRE(a.size() == 0);
-}
-
TEST_CASE("strip trailing/leading slashes", M) {
Path a;
a.append("a/b/");
@@ -87,8 +101,8 @@ TEST_CASE("strip trailing/leading slashes", M) {
TEST_CASE("clear path", M) {
Path a;
a.append("test");
-
CHECK(a.size() == 1);
+
a.clear();
REQUIRE(a.size() == 0);
}
@@ -203,7 +217,7 @@ TEST_CASE("compare absolute to relative path (unix)", M) {
}
#endif
-TEST_CASE("remove last component of path", M) {
+TEST_CASE("remove last segment of path", M) {
Path a;
a.append("a");
a.append("b");
@@ -251,15 +265,6 @@ TEST_CASE("remove root path", M) {
REQUIRE(path.removeRoot() == Path("hello/world"));
}
-TEST_CASE("first and last path component", M) {
- REQUIRE(Path().first().empty());
- REQUIRE(Path().last().empty());
-
- const Path path("hello/world/chunky/bacon");
- REQUIRE(path.first() == "hello");
- REQUIRE(path.last() == "bacon");
-}
-
TEST_CASE("directory traversal", M) {
SECTION("append (enabled)") {
REQUIRE(Path("a/./b") == Path("a/b"));
@@ -278,7 +283,7 @@ TEST_CASE("directory traversal", M) {
const Path a = Path("a/b/c") + "../../../d/e/f";
REQUIRE(a == Path("d/e/f"));
- // here, the directory traversal components are lost before concatenating
+ // here, the directory traversal segments are lost before concatenating
const Path b = Path("a/b/c") + Path("../../../d/e/f");
REQUIRE(b == Path("a/b/c/d/e/f"));
}
diff --git a/test/source.cpp b/test/source.cpp
@@ -86,12 +86,12 @@ TEST_CASE("explicit source section", M) {
}
TEST_CASE("implicit section detection (v1.0 compatibility)", M) {
- REQUIRE(Source::MainSection == Source::detectSection("Hello World"));
- REQUIRE(Source::MainSection == Source::detectSection("Hello/World"));
- REQUIRE(Source::MainSection == Source::detectSection("Hello/midi editor"));
+ REQUIRE(Source::MainSection == Source::detectSection(Path{"Hello World"}));
+ REQUIRE(Source::MainSection == Source::detectSection(Path{"Hello/World"}));
+ REQUIRE(Source::MainSection == Source::detectSection(Path{"Hello/midi editor"}));
- REQUIRE(Source::MIDIEditorSection == Source::detectSection("midi editor"));
- REQUIRE(Source::MIDIEditorSection == Source::detectSection("midi editor/Hello"));
+ REQUIRE(Source::MIDIEditorSection == Source::detectSection(Path{"midi editor"}));
+ REQUIRE(Source::MIDIEditorSection == Source::detectSection(Path{"midi editor/Hello"}));
}
TEST_CASE("implicit section detection from source (v1.0 compatibility)") {