A handful of additional small bugfixes for directory browsing:

1. Update the tracklist on indexer progress
2. Optimized DirectoryAdapter::HasSubdirectories()
3. Added directory name to tracklist title
4. Hide direcotry chooser for root paths without any subdirs
This commit is contained in:
casey langen 2018-02-12 09:44:16 -08:00
parent e5d82dc868
commit 5dbb2c6abc
5 changed files with 74 additions and 14 deletions

View File

@ -64,8 +64,11 @@ DirectoryLayout::DirectoryLayout(
: LayoutBase()
, playback(playback)
, library(library)
, queryHash(0) {
, queryHash(0)
, hasSubdirectories(true) {
this->InitializeWindows();
this->library->Indexer()->Progress.connect(this, &DirectoryLayout::OnIndexerProgress);
this->library->Indexer()->Finished.connect(this, &DirectoryLayout::OnIndexerProgress);
}
DirectoryLayout::~DirectoryLayout() {
@ -74,11 +77,20 @@ DirectoryLayout::~DirectoryLayout() {
void DirectoryLayout::OnLayout() {
size_t cx = this->GetWidth(), cy = this->GetHeight();
size_t x = 0, y = 0;
size_t directoryWidth = std::min(MAX_CATEGORY_WIDTH, cx / 4);
this->directoryList->MoveAndResize(x, y, directoryWidth, cy);
this->trackList->MoveAndResize(x + directoryWidth, y, cx - directoryWidth, cy);
this->directoryList->SetFocusOrder(0);
this->trackList->SetFocusOrder(1);
if (this->hasSubdirectories) {
size_t directoryWidth = std::min(MAX_CATEGORY_WIDTH, cx / 4);
this->directoryList->Show();
this->directoryList->MoveAndResize(x, y, directoryWidth, cy);
this->trackList->MoveAndResize(x + directoryWidth, y, cx - directoryWidth, cy);
this->directoryList->SetFocusOrder(0);
this->trackList->SetFocusOrder(1);
}
else {
this->directoryList->Hide();
this->trackList->MoveAndResize(x, y, cx, cy);
this->trackList->SetFocusOrder(0);
}
}
void DirectoryLayout::InitializeWindows() {
@ -114,6 +126,7 @@ void DirectoryLayout::SetDirectory(const std::string& directory) {
this->rootDirectory = directory;
this->adapter->SetRootDirectory(directory);
this->directoryList->SetSelectedIndex(0);
this->UpdateTitle();
this->Refresh(true);
}
@ -124,6 +137,10 @@ void DirectoryLayout::OnVisibilityChanged(bool visible) {
}
}
void DirectoryLayout::OnIndexerProgress(int count) {
this->Requery(true);
}
void DirectoryLayout::RequeryTrackList(ListWindow *view) {
size_t selected = this->directoryList->GetSelectedIndex();
std::string fullPath = "";
@ -156,15 +173,28 @@ void DirectoryLayout::RequeryTrackList(ListWindow *view) {
void DirectoryLayout::OnDirectoryChanged(
ListWindow *view, size_t newIndex, size_t oldIndex)
{
this->UpdateTitle();
this->RequeryTrackList(view);
}
void DirectoryLayout::UpdateTitle() {
std::string title =
_TSTR("browse_title_directory_tracks") +
this->adapter->GetCurrentPath();
this->trackList->SetFrameTitle(title);
}
void DirectoryLayout::Refresh(bool requery) {
this->adapter->Refresh();
this->hasSubdirectories = this->adapter->HasSubDirectories();
if (requery) { this->Requery(); }
}
void DirectoryLayout::Requery() {
void DirectoryLayout::Requery(bool invalidate) {
if (invalidate) {
this->queryHash = 0;
}
this->RequeryTrackList(this->directoryList.get());
}

View File

@ -73,8 +73,9 @@ namespace musik {
private:
void InitializeWindows();
void Refresh(bool requery = false);
void Requery();
void Requery(bool invalidate = false);
void RequeryTrackList(cursespp::ListWindow *view);
void UpdateTitle();
bool IsParentSelected();
bool IsParentRoot();
@ -89,6 +90,8 @@ namespace musik {
size_t newIndex,
size_t oldIndex);
void OnIndexerProgress(int count);
musik::core::audio::PlaybackService& playback;
musik::core::ILibraryPtr library;
std::string rootDirectory;
@ -96,6 +99,7 @@ namespace musik {
std::shared_ptr<cursespp::ListWindow> directoryList;
std::shared_ptr<TrackListView> trackList;
size_t queryHash;
bool hasSubdirectories;
};
}
}

View File

@ -46,7 +46,7 @@ using namespace cursespp;
using namespace boost::filesystem;
#ifdef WIN32
void buildDriveList(std::vector<std::string>& target) {
static void buildDriveList(std::vector<std::string>& target) {
target.clear();
static char buffer[4096];
DWORD result = ::GetLogicalDriveStringsA(4096, buffer);
@ -60,7 +60,30 @@ void buildDriveList(std::vector<std::string>& target) {
}
#endif
void buildDirectoryList(
static bool hasSubdirectories(
boost::filesystem::path p, bool showDotfiles)
{
try {
directory_iterator end;
directory_iterator file(p);
while (file != end) {
if (is_directory(file->status())) {
if (showDotfiles || file->path().leaf().string()[0] != '.') {
return true;
}
}
++file;
}
}
catch (...) {
}
return false;
}
static void buildDirectoryList(
const path& p,
std::vector<std::string>& target,
bool showDotfiles)
@ -82,7 +105,6 @@ void buildDirectoryList(
}
}
catch (...) {
/* todo: log maybe? */
}
std::sort(target.begin(), target.end(), std::locale(""));
@ -228,9 +250,11 @@ bool DirectoryAdapter::HasSubDirectories(size_t index) {
}
index = hasParent ? index - 1 : index;
std::vector<std::string> subdirs;
buildDirectoryList(this->dir / this->subdirs[index], subdirs, this->showDotfiles);
return subdirs.size() > 0;
return hasSubdirectories(this->dir / this->subdirs[index], this->showDotfiles);
}
bool DirectoryAdapter::HasSubDirectories() {
return hasSubdirectories(this->dir, this->showDotfiles);
}
IScrollAdapter::EntryPtr DirectoryAdapter::GetEntry(cursespp::ScrollableWindow* window, size_t index) {

View File

@ -58,6 +58,7 @@ namespace musik {
std::string GetFullPathAt(size_t index);
std::string GetLeafAt(size_t index);
bool HasSubDirectories(size_t index);
bool HasSubDirectories();
void SetRootDirectory(const std::string& fullPath);
void SetAllowEscapeRoot(bool allowEscape);
size_t IndexOf(const std::string& leaf);

View File

@ -22,6 +22,7 @@
"browse_title_directory": "directory",
"browse_playlist_modified": "playlist modified. press '%s' to save.",
"browse_categories_title": "select category",
"browse_title_directory_tracks": "tracks in ",
"browse_pick_path_overlay_title": "select root directory",
"browse_pick_path_last_directory": "last directory",