1
0
mirror of https://github.com/clangen/musikcube.git synced 2025-02-19 15:40:50 +00:00

Extracted IValue, IValueList wrapper functionality from

CategoryListQuery and into new SdkWrappers helper that is available to
all queries.

Implemented "AllCategoriesQuery" for retrieving a sorted list of all
normal and extended categories that can be queried.
This commit is contained in:
casey langen 2018-01-04 21:19:15 -08:00
parent 3705c278d3
commit 654f26f9b6
12 changed files with 347 additions and 106 deletions

@ -21,6 +21,7 @@ set(CORE_SOURCES
./library/LocalLibrary.cpp
./library/LocalSimpleDataProvider.cpp
./library/query/local/AlbumListQuery.cpp
./library/query/local/AllCategoriesQuery.cpp
./library/query/local/AppendPlaylistQuery.cpp
./library/query/local/GetPlaylistQuery.cpp
./library/query/local/CategoryListQuery.cpp

@ -107,6 +107,7 @@
<ClCompile Include="library\metadata\MetadataMap.cpp" />
<ClCompile Include="library\metadata\MetadataMapList.cpp" />
<ClCompile Include="library\query\local\AlbumListQuery.cpp" />
<ClCompile Include="library\query\local\AllCategoriesQuery.cpp" />
<ClCompile Include="library\query\local\AppendPlaylistQuery.cpp" />
<ClCompile Include="library\query\local\CategoryListQuery.cpp" />
<ClCompile Include="library\query\local\CategoryTrackListQuery.cpp" />
@ -165,6 +166,7 @@
<ClInclude Include="library\metadata\MetadataMap.h" />
<ClInclude Include="library\metadata\MetadataMapList.h" />
<ClInclude Include="library\query\local\AlbumListQuery.h" />
<ClInclude Include="library\query\local\AllCategoriesQuery.h" />
<ClInclude Include="library\query\local\AppendPlaylistQuery.h" />
<ClInclude Include="library\query\local\CategoryListQuery.h" />
<ClInclude Include="library\query\local\CategoryTrackListQuery.h" />
@ -178,6 +180,7 @@
<ClInclude Include="Library\query\local\LocalQueryBase.h" />
<ClInclude Include="library\query\local\TrackMetadataQuery.h" />
<ClInclude Include="library\query\local\util\CategoryQueryUtil.h" />
<ClInclude Include="library\query\local\util\SdkWrappers.h" />
<ClInclude Include="library\track\IndexerTrack.h" />
<ClInclude Include="library\track\LibraryTrack.h" />
<ClInclude Include="library\track\Track.h" />

@ -205,6 +205,9 @@
<ClCompile Include="library\query\local\util\CategoryQueryUtil.cpp">
<Filter>src\library\query\local\util</Filter>
</ClCompile>
<ClCompile Include="library\query\local\AllCategoriesQuery.cpp">
<Filter>src\library\query\local</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="pch.hpp">
@ -495,5 +498,11 @@
<ClInclude Include="library\query\local\util\CategoryQueryUtil.h">
<Filter>src\library\query\local\util</Filter>
</ClInclude>
<ClInclude Include="library\query\local\util\SdkWrappers.h">
<Filter>src\library\query\local\util</Filter>
</ClInclude>
<ClInclude Include="library\query\local\AllCategoriesQuery.h">
<Filter>src\library\query\local</Filter>
</ClInclude>
</ItemGroup>
</Project>

@ -0,0 +1,81 @@
//////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2007-2017 musikcube team
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#include "pch.hpp"
#include "AllCategoriesQuery.h"
#include <core/db/Statement.h>
using musik::core::db::Statement;
using musik::core::db::Row;
using namespace musik::core::db;
using namespace musik::core::db::local;
AllCategoriesQuery::AllCategoriesQuery() {
this->result.reset(new SdkValueList());
}
AllCategoriesQuery::~AllCategoriesQuery() {
}
AllCategoriesQuery::Result AllCategoriesQuery::GetResult() {
return this->result;
}
musik::core::sdk::IValueList* AllCategoriesQuery::GetSdkResult() {
return new SdkValueList(this->result);
}
bool AllCategoriesQuery::OnRun(Connection& db) {
this->result.reset(new SdkValueList());
Statement stmt("SELECT DISTINCT name FROM meta_keys ORDER BY name", db);
this->result->Add(std::make_shared<SdkValue>("albums", 0, "category"));
this->result->Add(std::make_shared<SdkValue>("artists", 0, "category"));
this->result->Add(std::make_shared<SdkValue>("album_artists", 0, "category"));
this->result->Add(std::make_shared<SdkValue>("genres", 0, "category"));
while (stmt.Step() == db::Row) {
this->result->Add(std::make_shared<SdkValue>(
stmt.ColumnText(0), 0, "category"
));
}
using Value = const SdkValue::Shared;
this->result->Sort([](Value& a, Value& b) -> bool {
return a->ToString() < b->ToString();
});
return true;
}

@ -0,0 +1,62 @@
//////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2007-2017 musikcube team
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
#include <core/library/query/local/LocalQueryBase.h>
#include <core/library/query/local/util/SdkWrappers.h>
#include <core/sdk/IValueList.h>
namespace musik { namespace core { namespace db { namespace local {
class AllCategoriesQuery : public musik::core::db::LocalQueryBase {
public:
using Result = SdkValueList::Shared;
AllCategoriesQuery();
virtual ~AllCategoriesQuery();
std::string Name() { return "AllCategoriesQuery"; }
virtual Result GetResult();
musik::core::sdk::IValueList* GetSdkResult();
protected:
virtual bool OnRun(musik::core::db::Connection &db);
private:
Result result;
};
} } } }

@ -44,8 +44,6 @@ using namespace musik::core::db;
using namespace musik::core::library::constants;
using namespace musik::core::db::local;
#define RESET_RESULT(x) x.reset(new std::vector<std::shared_ptr<Result>>);
static const std::string UNFILTERED_PLAYLISTS_QUERY =
"SELECT DISTINCT id, name "
"FROM playlists "
@ -57,29 +55,6 @@ static const std::string FILTERED_PLAYLISTS_QUERY =
"WHERE LOWER(name) LIKE LOWER(?) "
"ORDER BY name;";
/* data structure that we can return to plugins who need metadata info */
class ValueList : public musik::core::sdk::IValueList {
public:
ValueList(CategoryListQuery::ResultList results) {
this->results = results;
}
virtual void Release() {
delete this;
}
virtual size_t Count() {
return this->results->size();
}
virtual musik::core::sdk::IValue* GetAt(size_t index) {
return this->results->at(index).get();
}
private:
CategoryListQuery::ResultList results;
};
CategoryListQuery::CategoryListQuery(
const std::string& trackField, const std::string& filter)
: CategoryListQuery(trackField, category::PredicateList(), filter) {
@ -98,7 +73,7 @@ CategoryListQuery::CategoryListQuery(
const std::string& filter)
: trackField(trackField)
, filter(filter) {
RESET_RESULT(result);
result.reset(new SdkValueList());
if (this->filter.size()) {
/* transform "FilteR" => "%filter%" */
@ -125,18 +100,18 @@ CategoryListQuery::CategoryListQuery(
CategoryListQuery::~CategoryListQuery() {
}
CategoryListQuery::ResultList CategoryListQuery::GetResult() {
CategoryListQuery::Result CategoryListQuery::GetResult() {
return this->result;
}
musik::core::sdk::IValueList* CategoryListQuery::GetSdkResult() {
return new ValueList(this->result);
return new SdkValueList(this->result);
}
int CategoryListQuery::GetIndexOf(int64_t id) {
auto result = this->GetResult();
for (size_t i = 0; i < result->size(); i++) {
if (id == (*result)[i]->id) {
for (size_t i = 0; i < result->Count(); i++) {
if (id == result->GetAt(i)->GetId()) {
return i;
}
}
@ -215,16 +190,17 @@ void CategoryListQuery::QueryExtended(musik::core::db::Connection &db) {
void CategoryListQuery::ProcessResult(musik::core::db::Statement &stmt) {
while (stmt.Step() == Row) {
std::shared_ptr<Result> row(new Result());
row->id = stmt.ColumnInt64(0);
row->displayValue = stmt.ColumnText(1);
row->type = this->trackField;
result->push_back(row);
auto row = std::make_shared<SdkValue>(
stmt.ColumnText(1),
stmt.ColumnInt64(0),
this->trackField);
result->Add(row);
}
}
bool CategoryListQuery::OnRun(Connection& db) {
RESET_RESULT(result);
result.reset(new SdkValueList());
switch (this->outputType) {
case Playlist: QueryPlaylist(db); break;

@ -36,6 +36,7 @@
#include <core/library/query/local/LocalQueryBase.h>
#include <core/library/query/local/util/CategoryQueryUtil.h>
#include <core/library/query/local/util/SdkWrappers.h>
#include <core/db/Statement.h>
#include <core/db/Connection.h>
#include <core/sdk/IValueList.h>
@ -46,35 +47,7 @@ namespace musik { namespace core { namespace db { namespace local {
class CategoryListQuery : public musik::core::db::LocalQueryBase {
public:
/* note we implement the SDK's IMetadataValue interface so
we can return data to plugins! */
struct Result : public musik::core::sdk::IValue {
virtual int64_t GetId() {
return this->id;
}
virtual musik::core::sdk::IResource::Class GetClass() {
return musik::core::sdk::IResource::Class::Value;
}
virtual const char* GetType() {
return this->type.c_str();
}
virtual size_t GetValue(char* dst, size_t size) {
return musik::core::CopyString(this->displayValue, dst, size);
}
virtual void Release() {
}
std::string displayValue;
std::string type;
int64_t id;
};
typedef std::shared_ptr<std::vector<
std::shared_ptr<Result> > > ResultList;
using Result = SdkValueList::Shared;
CategoryListQuery(
const std::string& trackField,
@ -94,7 +67,7 @@ namespace musik { namespace core { namespace db { namespace local {
std::string Name() { return "CategoryListQuery"; }
virtual ResultList GetResult();
virtual Result GetResult();
virtual int GetIndexOf(int64_t id);
musik::core::sdk::IValueList* GetSdkResult();
@ -114,7 +87,7 @@ namespace musik { namespace core { namespace db { namespace local {
std::string filter;
OutputType outputType;
category::PredicateList regular, extended;
ResultList result;
Result result;
};
} } } }

@ -0,0 +1,140 @@
//////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2007-2017 musikcube team
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
#include <core/sdk/IValueList.h>
#include <core/support/Common.h>
#include <vector>
#include <memory>
namespace musik { namespace core { namespace db { namespace local {
class SdkValue: public musik::core::sdk::IValue {
public:
using Shared = std::shared_ptr<SdkValue>;
SdkValue(
const std::string& displayValue,
int64_t id,
const std::string& type)
{
this->displayValue = displayValue;
this->id = id;
this->type = type;
}
virtual int64_t GetId() {
return this->id;
}
virtual musik::core::sdk::IResource::Class GetClass() {
return musik::core::sdk::IResource::Class::Value;
}
virtual const char* GetType() {
return this->type.c_str();
}
virtual size_t GetValue(char* dst, size_t size) {
return musik::core::CopyString(this->displayValue, dst, size);
}
std::string ToString() {
return this->displayValue;
}
virtual void Release() {
}
private:
std::string displayValue;
std::string type;
int64_t id;
};
class SdkValueList : public musik::core::sdk::IValueList {
public:
using SharedValueList = std::shared_ptr<std::vector<SdkValue::Shared>>;
using Shared = std::shared_ptr<SdkValueList>;
SdkValueList() {
values.reset(new std::vector<SdkValue::Shared>());
}
SdkValueList(const SdkValueList& other) {
this->values = other.values;
}
SdkValueList(std::shared_ptr<SdkValueList>& other) {
this->values = other->values;
}
SdkValueList(SharedValueList values) {
this->values = values;
}
virtual void Release() {
delete this;
}
virtual size_t Count() {
return this->values->size();
}
virtual musik::core::sdk::IValue* GetAt(size_t index) {
return this->values->at(index).get();
}
SdkValue::Shared At(size_t index) {
return this->values->at(index);
}
SdkValue::Shared operator[](size_t index) {
return this->values->at(index);
}
void Add(std::shared_ptr<SdkValue> value) {
this->values->push_back(value);
}
void Sort(std::function<bool(const SdkValue::Shared&, const SdkValue::Shared&)> compare) {
std::sort(values->begin(), values->end(), compare);
}
private:
SharedValueList values;
};
} } } }

@ -86,7 +86,7 @@ static inline std::string getModifiedText() {
static inline std::string getTitleForCategory(const std::string& fieldName) {
return FIELD_TO_TITLE.find(fieldName) == FIELD_TO_TITLE.end()
? _TSTR("browse_title_category") : _TSTR(FIELD_TO_TITLE[fieldName]);
? _TSTR(fieldName) : _TSTR(FIELD_TO_TITLE[fieldName]);
}
BrowseLayout::BrowseLayout(

@ -91,13 +91,11 @@ static inline void touchOperationExpiry() {
lastOperationExpiry = now() + duration_cast<milliseconds>(Seconds(60));
}
static inline int findPlaylistIndex(CategoryListQuery::ResultList result, int64_t playlistId) {
int i = 0;
for (auto it : *(result.get())) {
if (it->id == playlistId) {
return i;
static inline int findPlaylistIndex(CategoryListQuery::Result result, int64_t playlistId) {
for (size_t i = 0; i < result->Count(); i++) {
if (result->At(i)->GetId() == playlistId) {
return (int)i;
}
++i;
}
return -1;
}
@ -141,12 +139,10 @@ static std::shared_ptr<CategoryListQuery> queryPlaylists(ILibraryPtr library) {
}
static void addPlaylistsToAdapter(
std::shared_ptr<Adapter> adapter, CategoryListQuery::ResultList result)
std::shared_ptr<Adapter> adapter, CategoryListQuery::Result result)
{
auto it = result->begin();
while (it != result->end()) {
adapter->AddEntry((*it)->displayValue);
++it;
for (size_t i = 0; i < result->Count(); i++) {
adapter->AddEntry(result->At(i)->ToString());
}
}
@ -390,7 +386,7 @@ static void showAddCategorySelectionToPlaylistOverlay(
createNewPlaylist(queue, library, categoryType, categoryId);
}
else { /* add to existing */
int64_t playlistId = (*result)[index - 1]->id;
int64_t playlistId = (*result)[index - 1]->GetId();
setLastPlaylistId(playlistId);
auto query = SavePlaylistQuery::Append(
@ -435,7 +431,7 @@ static void showAddTrackToPlaylistOverlay(
createNewPlaylist(queue, list, library);
}
else { /* add to existing */
int64_t playlistId = (*result)[index - 1]->id;
int64_t playlistId = (*result)[index - 1]->GetId();
setLastPlaylistId(playlistId);
library->Enqueue(SavePlaylistQuery::Append(library, playlistId, list), 0);
}
@ -623,7 +619,7 @@ void PlayQueueOverlays::ShowLoadPlaylistOverlay(
std::shared_ptr<CategoryListQuery> query = queryPlaylists(library);
auto result = query->GetResult();
if (!result->size()) {
if (!result->Count()) {
showNoPlaylistsDialog();
return;
}
@ -638,7 +634,7 @@ void PlayQueueOverlays::ShowLoadPlaylistOverlay(
[library, result, callback]
(ListOverlay* overlay, IScrollAdapterPtr adapter, size_t index) {
if (index != ListWindow::NO_SELECTION && callback) {
int64_t playlistId = (*result)[index]->id;
int64_t playlistId = (*result)[index]->GetId();
callback(playlistId);
}
});
@ -662,8 +658,8 @@ void PlayQueueOverlays::ShowSavePlaylistOverlay(
select by default. if they did, try to find it */
size_t selectedIndex = 0;
if (selectedPlaylistId != -1) {
for (size_t i = 0; i < result->size(); i++) {
if (result->at(i)->id == selectedPlaylistId) {
for (size_t i = 0; i < result->Count(); i++) {
if (result->At(i)->GetId() == selectedPlaylistId) {
selectedIndex = i + 1; /* offset "new..." */
break;
}
@ -683,8 +679,8 @@ void PlayQueueOverlays::ShowSavePlaylistOverlay(
}
else { /* replace existing */
--index;
int64_t playlistId = (*result)[index]->id;
std::string playlistName = (*result)[index]->displayValue;
int64_t playlistId = (*result)[index]->GetId();
std::string playlistName = (*result)[index]->ToString();
confirmOverwritePlaylist(library, playlistName, playlistId, tracks);
}
},
@ -695,7 +691,7 @@ void PlayQueueOverlays::ShowRenamePlaylistOverlay(ILibraryPtr library) {
std::shared_ptr<CategoryListQuery> query = queryPlaylists(library);
auto result = query->GetResult();
if (!result->size()) {
if (!result->Count()) {
showNoPlaylistsDialog();
return;
}
@ -709,8 +705,8 @@ void PlayQueueOverlays::ShowRenamePlaylistOverlay(ILibraryPtr library) {
adapter,
[library, result](ListOverlay* overlay, IScrollAdapterPtr adapter, size_t index) {
if (index != ListWindow::NO_SELECTION) {
int64_t playlistId = (*result)[index]->id;
std::string playlistName = (*result)[index]->displayValue;
int64_t playlistId = (*result)[index]->GetId();
std::string playlistName = (*result)[index]->ToString();
ShowRenamePlaylistOverlay(library, playlistId, playlistName);
}
});
@ -720,7 +716,7 @@ void PlayQueueOverlays::ShowDeletePlaylistOverlay(ILibraryPtr library) {
std::shared_ptr<CategoryListQuery> query = queryPlaylists(library);
auto result = query->GetResult();
if (!result->size()) {
if (!result->Count()) {
showNoPlaylistsDialog();
return;
}
@ -735,8 +731,8 @@ void PlayQueueOverlays::ShowDeletePlaylistOverlay(ILibraryPtr library) {
[library, result]
(ListOverlay* overlay, IScrollAdapterPtr adapter, size_t index) {
if (index != ListWindow::NO_SELECTION) {
int64_t playlistId = (*result)[index]->id;
std::string playlistName = (*result)[index]->displayValue;
int64_t playlistId = (*result)[index]->GetId();
std::string playlistName = (*result)[index]->ToString();
ShowConfirmDeletePlaylistOverlay(library, playlistName, playlistId);
}
});

@ -114,22 +114,22 @@ void CategoryListView::Requery(const std::string& filter, const int64_t selectAf
}
void CategoryListView::Reset() {
this->metadata.reset(new std::vector<std::shared_ptr<CategoryListQuery::Result> >()); /* ugh */
this->metadata.reset(new SdkValueList()); /* ugh */
this->OnAdapterChanged();
}
int64_t CategoryListView::GetSelectedId() {
size_t index = this->GetSelectedIndex();
if (index != NO_SELECTION && this->metadata && index < this->metadata->size()) {
return this->metadata->at(index)->id;
if (index != NO_SELECTION && this->metadata && index < this->metadata->Count()) {
return this->metadata->At(index)->GetId();
}
return -1;
}
std::string CategoryListView::GetSelectedValue() {
size_t index = this->GetSelectedIndex();
if (index != NO_SELECTION && this->metadata && index < this->metadata->size()) {
return this->metadata->at(index)->displayValue;
if (index != NO_SELECTION && this->metadata && index < this->metadata->Count()) {
return this->metadata->At(index)->ToString();
}
return "";
}
@ -169,8 +169,8 @@ void CategoryListView::ScrollToPlaying() {
/* by ID: preferred. */
if (fieldIdColumn.size()) {
int64_t id = this->playing->GetInt64(fieldIdColumn.c_str(), 0);
for (size_t i = 0; i < this->metadata->size(); i++) {
if (this->metadata->at(i)->id == id) {
for (size_t i = 0; i < this->metadata->Count(); i++) {
if (this->metadata->At(i)->GetId() == id) {
selected = i;
break;
}
@ -183,8 +183,8 @@ void CategoryListView::ScrollToPlaying() {
if (value.size()) {
/* binary search would be better, but need to research if sqlite
properly sorts utf8 strings. */
for (size_t i = 0; i < this->metadata->size(); i++) {
if (this->metadata->at(i)->displayValue == value) {
for (size_t i = 0; i < this->metadata->Count(); i++) {
if (this->metadata->At(i)->ToString() == value) {
selected = i;
break;
}
@ -259,11 +259,11 @@ CategoryListView::Adapter::Adapter(CategoryListView &parent)
}
size_t CategoryListView::Adapter::GetEntryCount() {
return parent.metadata ? parent.metadata->size() : 0;
return parent.metadata ? parent.metadata->Count() : 0;
}
IScrollAdapter::EntryPtr CategoryListView::Adapter::GetEntry(cursespp::ScrollableWindow* window, size_t index) {
std::string value = parent.metadata->at(index)->displayValue;
std::string value = parent.metadata->At(index)->ToString();
bool playing = false;
@ -271,7 +271,7 @@ IScrollAdapter::EntryPtr CategoryListView::Adapter::GetEntry(cursespp::Scrollabl
/* we should generally be able to match by ID; if not, fall back to by name */
if (parent.fieldIdColumn.size()) {
auto playingId = parent.playing->GetInt64(parent.fieldIdColumn.c_str(), 0);
playing = (playingId == parent.metadata->at(index)->id);
playing = (playingId == parent.metadata->At(index)->GetId());
}
else {
playing = parent.playing->GetString(parent.fieldName.c_str()) == value;

@ -117,7 +117,7 @@ namespace musik {
std::string fieldName, fieldIdColumn;
std::string filter;
int64_t selectAfterQuery;
musik::core::db::local::CategoryListQuery::ResultList metadata;
musik::core::db::local::CategoryListQuery::Result metadata;
};
}
}