mirror of
https://github.com/clangen/musikcube.git
synced 2025-03-29 19:20:28 +00:00
- Fixed a bug that could let partial results get displayed in
CategoryListView - Allow queries to be marked as cancelable so they won't be processed.
This commit is contained in:
parent
306103c0e8
commit
dd9b0818f1
@ -22,6 +22,7 @@ namespace musik { namespace core {
|
||||
Running = 2,
|
||||
Failed = 3,
|
||||
Finished = 4,
|
||||
Canceled = 5
|
||||
} Status;
|
||||
|
||||
virtual ~IQuery() { }
|
||||
|
@ -48,7 +48,8 @@ static boost::atomic<int> nextId(0);
|
||||
QueryBase::QueryBase()
|
||||
: status(0)
|
||||
, options(0)
|
||||
, queryId(0) {
|
||||
, queryId(0)
|
||||
, cancel(false) {
|
||||
this->queryId = nextId++;
|
||||
}
|
||||
|
||||
@ -62,7 +63,11 @@ std::string QueryBase::Name() {
|
||||
bool QueryBase::Run(db::Connection &db) {
|
||||
this->SetStatus(Running);
|
||||
try {
|
||||
if (OnRun(db)) {
|
||||
if (this->IsCanceled()) {
|
||||
this->SetStatus(Canceled);
|
||||
return true;
|
||||
}
|
||||
else if (OnRun(db)) {
|
||||
this->SetStatus(Finished);
|
||||
return true;
|
||||
}
|
||||
|
@ -57,6 +57,8 @@ namespace musik { namespace core { namespace query {
|
||||
virtual int GetStatus();
|
||||
virtual int GetId();
|
||||
virtual int GetOptions();
|
||||
virtual void Cancel() { this->cancel = true; }
|
||||
virtual bool IsCanceled() { return cancel; }
|
||||
|
||||
protected:
|
||||
void SetStatus(int status);
|
||||
@ -69,6 +71,7 @@ namespace musik { namespace core { namespace query {
|
||||
unsigned int status;
|
||||
unsigned int queryId;
|
||||
unsigned int options;
|
||||
volatile bool cancel;
|
||||
boost::mutex stateMutex;
|
||||
};
|
||||
|
||||
|
@ -10,7 +10,13 @@
|
||||
using namespace musik::core::library::constants;
|
||||
|
||||
#define CATEGORY_WIDTH 25
|
||||
#define TRANSPORT_HEIGHT 2
|
||||
|
||||
#ifdef WIN32
|
||||
#define TRANSPORT_HEIGHT 3
|
||||
#else
|
||||
#define TRANSPORT_HEIGHT 2
|
||||
#endif
|
||||
|
||||
#define DEFAULT_CATEGORY constants::Track::ALBUM_ID
|
||||
|
||||
using namespace musik::core;
|
||||
@ -120,7 +126,7 @@ bool LibraryLayout::KeyPress(const std::string& key) {
|
||||
return true;
|
||||
}
|
||||
else if (key == "KEY_F(5)") {
|
||||
this->categoryList->Requery();
|
||||
this->categoryList->Requery();
|
||||
return true;
|
||||
}
|
||||
else if (key == "CTL_DOWN") {
|
||||
|
@ -15,7 +15,7 @@ using namespace musik::core::db;
|
||||
using namespace musik::core::library::constants;
|
||||
using namespace musik::box;
|
||||
|
||||
#define reset(x) x.reset(new std::vector<std::shared_ptr<Result> >);
|
||||
#define RESET_RESULT(x) x.reset(new std::vector<std::shared_ptr<Result> >);
|
||||
|
||||
static const std::string ALBUM_QUERY =
|
||||
"SELECT DISTINCT albums.id, albums.name "
|
||||
@ -47,7 +47,7 @@ static void initFieldToQueryMap() {
|
||||
CategoryListViewQuery::CategoryListViewQuery(const std::string& trackField) {
|
||||
this->trackField = trackField;
|
||||
|
||||
reset(result);
|
||||
RESET_RESULT(result);
|
||||
|
||||
{
|
||||
boost::mutex::scoped_lock lock(QUERY_MAP_MUTEX);
|
||||
@ -71,7 +71,7 @@ CategoryListViewQuery::ResultList CategoryListViewQuery::GetResult() {
|
||||
}
|
||||
|
||||
bool CategoryListViewQuery::OnRun(Connection& db) {
|
||||
reset(result);
|
||||
RESET_RESULT(result);
|
||||
|
||||
std::string query = FIELD_TO_QUERY_MAP[this->trackField];
|
||||
Statement stmt(query.c_str(), db);
|
||||
|
@ -34,6 +34,10 @@ CategoryListView::~CategoryListView() {
|
||||
}
|
||||
|
||||
void CategoryListView::Requery() {
|
||||
if (this->activeQuery) {
|
||||
this->activeQuery->Cancel();
|
||||
}
|
||||
|
||||
this->activeQuery.reset(new CategoryListViewQuery(this->fieldName));
|
||||
this->library->Enqueue(activeQuery);
|
||||
}
|
||||
@ -56,7 +60,6 @@ void CategoryListView::SetFieldName(const std::string& fieldName) {
|
||||
|
||||
if (this->metadata) {
|
||||
this->metadata.reset();
|
||||
//this->OnAdapterChanged();
|
||||
}
|
||||
|
||||
this->Requery();
|
||||
@ -71,10 +74,12 @@ void CategoryListView::OnQueryCompleted(QueryPtr query) {
|
||||
|
||||
void CategoryListView::ProcessMessage(IMessage &message) {
|
||||
if (message.Type() == WINDOW_MESSAGE_QUERY_COMPLETED) {
|
||||
this->metadata = activeQuery->GetResult();
|
||||
activeQuery.reset();
|
||||
this->OnAdapterChanged();
|
||||
this->OnInvalidated();
|
||||
if (this->activeQuery && this->activeQuery->GetStatus() == IQuery::Finished) {
|
||||
this->metadata = activeQuery->GetResult();
|
||||
activeQuery.reset();
|
||||
this->OnAdapterChanged();
|
||||
this->OnInvalidated();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user