Comments from revision 9a739a3346a7
This commit is contained in:
parent
b3bf374b6e
commit
1b6ce64532
@ -18,6 +18,7 @@
|
|||||||
#include "clementinerunner.h"
|
#include "clementinerunner.h"
|
||||||
#include "globalsearchinterface.h"
|
#include "globalsearchinterface.h"
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
#include <QDBusConnection>
|
#include <QDBusConnection>
|
||||||
#include <QMutexLocker>
|
#include <QMutexLocker>
|
||||||
#include <QtDebug>
|
#include <QtDebug>
|
||||||
@ -77,11 +78,12 @@ void ClementineRunner::match(Plasma::RunnerContext& context) {
|
|||||||
|
|
||||||
int id = 0;
|
int id = 0;
|
||||||
PendingQuery query;
|
PendingQuery query;
|
||||||
query.results_mutex_.lock();
|
|
||||||
|
|
||||||
// Start the search
|
// Start the search
|
||||||
{
|
{
|
||||||
QMutexLocker l(&pending_mutex_);
|
QMutexLocker l(&query.results_mutex_);
|
||||||
|
QMutexLocker l2(&pending_mutex_);
|
||||||
|
|
||||||
QDBusPendingReply<int> reply = interface_->StartSearch(context.query(), true);
|
QDBusPendingReply<int> reply = interface_->StartSearch(context.query(), true);
|
||||||
reply.waitForFinished();
|
reply.waitForFinished();
|
||||||
|
|
||||||
@ -94,8 +96,6 @@ void ClementineRunner::match(Plasma::RunnerContext& context) {
|
|||||||
pending_queries_[id] = &query;
|
pending_queries_[id] = &query;
|
||||||
}
|
}
|
||||||
|
|
||||||
query.results_mutex_.unlock();
|
|
||||||
|
|
||||||
// Wait for results to arrive
|
// Wait for results to arrive
|
||||||
forever {
|
forever {
|
||||||
query.results_semaphore_.acquire();
|
query.results_semaphore_.acquire();
|
||||||
@ -131,25 +131,26 @@ void ClementineRunner::match(Plasma::RunnerContext& context) {
|
|||||||
|
|
||||||
void ClementineRunner::FillMatch(const GlobalSearchServiceResult& result,
|
void ClementineRunner::FillMatch(const GlobalSearchServiceResult& result,
|
||||||
Plasma::QueryMatch* match) const {
|
Plasma::QueryMatch* match) const {
|
||||||
QString line[2];
|
QString text;
|
||||||
|
QString subtext;
|
||||||
|
|
||||||
switch (result.type_) {
|
switch (result.type_) {
|
||||||
case globalsearch::Type_Track:
|
case globalsearch::Type_Track:
|
||||||
case globalsearch::Type_Stream: {
|
case globalsearch::Type_Stream: {
|
||||||
line[0] = result.title_;
|
text = result.title_;
|
||||||
|
|
||||||
if (!result.artist_.isEmpty()) {
|
if (!result.artist_.isEmpty()) {
|
||||||
line[1] += result.artist_;
|
subtext += result.artist_;
|
||||||
} else if (!result.album_artist_.isEmpty()) {
|
} else if (!result.album_artist_.isEmpty()) {
|
||||||
line[1] += result.album_artist_;
|
subtext += result.album_artist_;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!result.album_.isEmpty()) {
|
if (!result.album_.isEmpty()) {
|
||||||
line[1] += " - " + result.album_;
|
subtext += " - " + result.album_;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.track_ > 0) {
|
if (result.track_ > 0) {
|
||||||
line[1] += " - " + tr("track %1").arg(result.track_);
|
subtext += " - " + tr("track %1").arg(result.track_);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -157,33 +158,33 @@ void ClementineRunner::FillMatch(const GlobalSearchServiceResult& result,
|
|||||||
|
|
||||||
case globalsearch::Type_Album: {
|
case globalsearch::Type_Album: {
|
||||||
if (!result.album_artist_.isEmpty())
|
if (!result.album_artist_.isEmpty())
|
||||||
line[0] += result.album_artist_;
|
text += result.album_artist_;
|
||||||
else if (result.is_compilation_)
|
else if (result.is_compilation_)
|
||||||
line[0] += tr("Various Artists");
|
text += tr("Various Artists");
|
||||||
else if (!result.artist_.isEmpty())
|
else if (!result.artist_.isEmpty())
|
||||||
line[0] += result.artist_;
|
text += result.artist_;
|
||||||
else
|
else
|
||||||
line[0] += tr("Unknown");
|
text += tr("Unknown");
|
||||||
|
|
||||||
// Dash
|
// Dash
|
||||||
line[0] += " - ";
|
text += " - ";
|
||||||
|
|
||||||
// Album
|
// Album
|
||||||
if (result.album_.isEmpty())
|
if (result.album_.isEmpty())
|
||||||
line[0] += tr("Unknown");
|
text += tr("Unknown");
|
||||||
else
|
else
|
||||||
line[0] += result.album_;
|
text += result.album_;
|
||||||
|
|
||||||
if (result.album_size_ > 1)
|
if (result.album_size_ > 1)
|
||||||
line[1] = tr("Album with %1 tracks").arg(result.album_size_);
|
subtext = tr("Album with %1 tracks").arg(result.album_size_);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
match->setType(Plasma::QueryMatch::CompletionMatch);
|
match->setType(Plasma::QueryMatch::CompletionMatch);
|
||||||
match->setText(line[0]);
|
match->setText(text);
|
||||||
match->setSubtext(line[1]);
|
match->setSubtext(subtext);
|
||||||
match->setRelevance(ResultRelevance(result));
|
match->setRelevance(ResultRelevance(result));
|
||||||
|
|
||||||
if (!result.image_.isNull()) {
|
if (!result.image_.isNull()) {
|
||||||
@ -219,6 +220,8 @@ qreal ClementineRunner::ResultRelevance(const GlobalSearchServiceResult& result)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ClementineRunner::ResultsAvailable(int id, GlobalSearchServiceResultList results) {
|
void ClementineRunner::ResultsAvailable(int id, GlobalSearchServiceResultList results) {
|
||||||
|
Q_ASSERT(QThread::currentThread() == qApp->thread());
|
||||||
|
|
||||||
// Lock the mutex and add the results to the list.
|
// Lock the mutex and add the results to the list.
|
||||||
QMutexLocker l(&pending_mutex_);
|
QMutexLocker l(&pending_mutex_);
|
||||||
PendingMap::iterator it = pending_queries_.find(id);
|
PendingMap::iterator it = pending_queries_.find(id);
|
||||||
@ -242,6 +245,8 @@ void ClementineRunner::ResultsAvailable(int id, GlobalSearchServiceResultList re
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ClementineRunner::SearchFinished(int id) {
|
void ClementineRunner::SearchFinished(int id) {
|
||||||
|
Q_ASSERT(QThread::currentThread() == qApp->thread());
|
||||||
|
|
||||||
QMutexLocker l(&pending_mutex_);
|
QMutexLocker l(&pending_mutex_);
|
||||||
PendingMap::iterator it = pending_queries_.find(id);
|
PendingMap::iterator it = pending_queries_.find(id);
|
||||||
if (it == pending_queries_.end())
|
if (it == pending_queries_.end())
|
||||||
@ -257,6 +262,8 @@ void ClementineRunner::SearchFinished(int id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ClementineRunner::ArtLoaded(int result_id, const QByteArray& image_data) {
|
void ClementineRunner::ArtLoaded(int result_id, const QByteArray& image_data) {
|
||||||
|
Q_ASSERT(QThread::currentThread() == qApp->thread());
|
||||||
|
|
||||||
QMutexLocker l(&pending_mutex_);
|
QMutexLocker l(&pending_mutex_);
|
||||||
|
|
||||||
// Find a query that has a result with this ID waiting for art
|
// Find a query that has a result with this ID waiting for art
|
||||||
@ -280,7 +287,7 @@ void ClementineRunner::ArtLoaded(int result_id, const QByteArray& image_data) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the art to this result and remote it from the waiting list
|
// Add the art to this result and remove it from the waiting list
|
||||||
QMutexLocker result_l(&query->results_mutex_);
|
QMutexLocker result_l(&query->results_mutex_);
|
||||||
query->results_ << *it;
|
query->results_ << *it;
|
||||||
query->results_waiting_for_art_.erase(it);
|
query->results_waiting_for_art_.erase(it);
|
||||||
|
@ -70,32 +70,32 @@ void GlobalSearchService::ResultsAvailableSlot(int id, const SearchProvider::Res
|
|||||||
foreach (const SearchProvider::Result& result, results) {
|
foreach (const SearchProvider::Result& result, results) {
|
||||||
const int result_id = next_result_id_ ++;
|
const int result_id = next_result_id_ ++;
|
||||||
|
|
||||||
RecentResult& recent = recent_results_[result_id];
|
RecentResult* recent = &recent_results_[result_id];
|
||||||
recent.result_.art_on_the_way_ = false;
|
recent->result_.art_on_the_way_ = false;
|
||||||
|
|
||||||
// Prefetch art if it was requested
|
// Prefetch art if it was requested
|
||||||
if (pending.prefetch_art_ && !result.provider_->art_is_probably_remote()) {
|
if (pending.prefetch_art_ && !result.provider_->art_is_probably_remote()) {
|
||||||
const int art_id = engine_->LoadArtAsync(result);
|
const int art_id = engine_->LoadArtAsync(result);
|
||||||
prefetching_art_[art_id] = result_id;
|
prefetching_art_[art_id] = result_id;
|
||||||
recent.result_.art_on_the_way_ = true;
|
recent->result_.art_on_the_way_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build the result to send back
|
// Build the result to send back
|
||||||
recent.result_.result_id_ = result_id;
|
recent->result_.result_id_ = result_id;
|
||||||
recent.result_.provider_name_ = result.provider_->name();
|
recent->result_.provider_name_ = result.provider_->name();
|
||||||
recent.result_.type_ = result.type_;
|
recent->result_.type_ = result.type_;
|
||||||
recent.result_.match_quality_ = result.match_quality_;
|
recent->result_.match_quality_ = result.match_quality_;
|
||||||
|
|
||||||
recent.result_.album_size_ = result.album_size_;
|
recent->result_.album_size_ = result.album_size_;
|
||||||
|
|
||||||
recent.result_.title_ = result.metadata_.title();
|
recent->result_.title_ = result.metadata_.title();
|
||||||
recent.result_.artist_ = result.metadata_.artist();
|
recent->result_.artist_ = result.metadata_.artist();
|
||||||
recent.result_.album_ = result.metadata_.album();
|
recent->result_.album_ = result.metadata_.album();
|
||||||
recent.result_.album_artist_ = result.metadata_.albumartist();
|
recent->result_.album_artist_ = result.metadata_.albumartist();
|
||||||
recent.result_.is_compilation_ = result.metadata_.is_compilation();
|
recent->result_.is_compilation_ = result.metadata_.is_compilation();
|
||||||
recent.result_.track_ = result.metadata_.track();
|
recent->result_.track_ = result.metadata_.track();
|
||||||
|
|
||||||
ret << recent.result_;
|
ret << recent->result_;
|
||||||
}
|
}
|
||||||
|
|
||||||
emit ResultsAvailable(id, ret);
|
emit ResultsAvailable(id, ret);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user