Basic global searching in Grooveshark.
This commit is contained in:
parent
30803b6743
commit
dd017e99ee
|
@ -122,6 +122,7 @@ set(SOURCES
|
|||
globalsearch/globalsearchsortmodel.cpp
|
||||
globalsearch/globalsearchtooltip.cpp
|
||||
globalsearch/globalsearchwidget.cpp
|
||||
globalsearch/groovesharksearchprovider.cpp
|
||||
globalsearch/librarysearchprovider.cpp
|
||||
globalsearch/searchprovider.cpp
|
||||
globalsearch/simplesearchprovider.cpp
|
||||
|
@ -370,6 +371,7 @@ set(HEADERS
|
|||
globalsearch/globalsearchpopup.h
|
||||
globalsearch/globalsearchtooltip.h
|
||||
globalsearch/globalsearchwidget.h
|
||||
globalsearch/groovesharksearchprovider.h
|
||||
globalsearch/searchprovider.h
|
||||
globalsearch/tooltipactionwidget.h
|
||||
globalsearch/tooltipresultwidget.h
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
#include "groovesharksearchprovider.h"
|
||||
|
||||
#include "core/logging.h"
|
||||
#include "internet/groovesharkservice.h"
|
||||
|
||||
GroovesharkSearchProvider::GroovesharkSearchProvider(QObject* parent)
|
||||
: service_(NULL) {
|
||||
}
|
||||
|
||||
void GroovesharkSearchProvider::Init(GrooveSharkService* service) {
|
||||
service_ = service;
|
||||
SearchProvider::Init("GrooveShark", "grooveshark", QIcon(), true, true);
|
||||
connect(service_, SIGNAL(SimpleSearchResults(int, SongList)),
|
||||
SLOT(SearchDone(int, SongList)));
|
||||
}
|
||||
|
||||
void GroovesharkSearchProvider::SearchAsync(int id, const QString& query) {
|
||||
const int service_id = service_->SimpleSearch(query);
|
||||
pending_searches_[service_id] = id;
|
||||
|
||||
qLog(Debug) << "Searching grooveshark for:" << query;
|
||||
}
|
||||
|
||||
void GroovesharkSearchProvider::SearchDone(int id, SongList songs) {
|
||||
qLog(Debug) << Q_FUNC_INFO;
|
||||
|
||||
// Map back to the original id.
|
||||
const int global_search_id = pending_searches_.take(id);
|
||||
|
||||
ResultList ret;
|
||||
foreach (const Song& song, songs) {
|
||||
Result result(this);
|
||||
result.type_ = Result::Type_Track;
|
||||
result.metadata_ = song;
|
||||
result.match_quality_ = Result::Quality_AtStart;
|
||||
|
||||
ret << result;
|
||||
}
|
||||
|
||||
qLog(Debug) << "Found:" << ret.size() << "songs from grooveshark";
|
||||
|
||||
emit ResultsAvailable(global_search_id, ret);
|
||||
emit SearchFinished(global_search_id);
|
||||
}
|
||||
|
||||
void GroovesharkSearchProvider::LoadArtAsync(int id, const Result& result) {
|
||||
|
||||
}
|
||||
|
||||
void GroovesharkSearchProvider::LoadTracksAsync(int id, const Result& result) {
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
#ifndef GROOVESHARKSEARCHPROVIDER_H
|
||||
#define GROOVESHARKSEARCHPROVIDER_H
|
||||
|
||||
#include "searchprovider.h"
|
||||
|
||||
class GrooveSharkService;
|
||||
|
||||
class GroovesharkSearchProvider : public SearchProvider {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit GroovesharkSearchProvider(QObject* parent = 0);
|
||||
void Init(GrooveSharkService* service);
|
||||
|
||||
// SearchProvider
|
||||
void SearchAsync(int id, const QString& query);
|
||||
void LoadArtAsync(int id, const Result& result);
|
||||
void LoadTracksAsync(int id, const Result& result);
|
||||
|
||||
private slots:
|
||||
void SearchDone(int id, SongList songs);
|
||||
|
||||
private:
|
||||
GrooveSharkService* service_;
|
||||
QMap<int, int> pending_searches_;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
|
@ -15,6 +15,7 @@
|
|||
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "groovesharkservice.h"
|
||||
|
||||
#include <QMenu>
|
||||
#include <QMessageBox>
|
||||
|
@ -40,13 +41,13 @@
|
|||
#include "core/song.h"
|
||||
#include "core/taskmanager.h"
|
||||
#include "core/utilities.h"
|
||||
#include "globalsearch/globalsearch.h"
|
||||
#include "globalsearch/groovesharksearchprovider.h"
|
||||
#include "playlist/playlist.h"
|
||||
#include "playlist/playlistcontainer.h"
|
||||
#include "playlist/playlistmanager.h"
|
||||
#include "ui/iconloader.h"
|
||||
|
||||
#include "groovesharkservice.h"
|
||||
|
||||
// The GrooveShark terms of service require that application keys are not
|
||||
// accessible to third parties. Therefore this application key is obfuscated to
|
||||
// prevent third parties from viewing it.
|
||||
|
@ -67,6 +68,7 @@ GrooveSharkService::GrooveSharkService(InternetModel *parent)
|
|||
: InternetService(kServiceName, parent, parent),
|
||||
url_handler_(new GrooveSharkUrlHandler(this, this)),
|
||||
pending_search_playlist_(NULL),
|
||||
next_pending_search_id_(0),
|
||||
root_(NULL),
|
||||
search_(NULL),
|
||||
network_(new NetworkAccessManager(this)),
|
||||
|
@ -89,6 +91,9 @@ GrooveSharkService::GrooveSharkService(InternetModel *parent)
|
|||
session_id_ = s.value("sessionid").toString();
|
||||
username_ = s.value("username").toString();
|
||||
|
||||
GroovesharkSearchProvider* search_provider = new GroovesharkSearchProvider(this);
|
||||
search_provider->Init(this);
|
||||
model()->global_search()->AddProvider(search_provider);
|
||||
}
|
||||
|
||||
|
||||
|
@ -128,6 +133,33 @@ void GrooveSharkService::Search(const QString& text, Playlist* playlist, bool no
|
|||
}
|
||||
}
|
||||
|
||||
int GrooveSharkService::SimpleSearch(const QString& query) {
|
||||
QList<Param> parameters;
|
||||
parameters << Param("query", query)
|
||||
<< Param("country", "")
|
||||
<< Param("limit", QString::number(kSongSearchLimit))
|
||||
<< Param("offset", "");
|
||||
|
||||
QNetworkReply* reply = CreateRequest("getSongSearchResults", parameters, false);
|
||||
connect(reply, SIGNAL(finished()), SLOT(SimpleSearchFinished()));
|
||||
|
||||
int id = next_pending_search_id_++;
|
||||
pending_searches_[reply] = id;
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
void GrooveSharkService::SimpleSearchFinished() {
|
||||
QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
|
||||
Q_ASSERT(reply);
|
||||
reply->deleteLater();
|
||||
|
||||
const int id = pending_searches_.take(reply);
|
||||
QVariantMap result = ExtractResult(reply);
|
||||
SongList songs = ExtractSongs(result);
|
||||
emit SimpleSearchResults(id, songs);
|
||||
}
|
||||
|
||||
void GrooveSharkService::DoSearch() {
|
||||
QList<Param> parameters;
|
||||
|
||||
|
|
|
@ -67,6 +67,8 @@ class GrooveSharkService : public InternetService {
|
|||
LoginState login_state() const { return login_state_; }
|
||||
const QString& session_id() { return session_id_; }
|
||||
|
||||
int SimpleSearch(const QString& query);
|
||||
|
||||
|
||||
static const char* kServiceName;
|
||||
static const char* kSettingsGroup;
|
||||
|
@ -81,6 +83,7 @@ class GrooveSharkService : public InternetService {
|
|||
|
||||
signals:
|
||||
void LoginFinished(bool success);
|
||||
void SimpleSearchResults(int id, SongList songs);
|
||||
|
||||
protected:
|
||||
QModelIndex GetCurrentIndex();
|
||||
|
@ -102,10 +105,12 @@ class GrooveSharkService : public InternetService {
|
|||
void OpenSearchTab();
|
||||
void DoSearch();
|
||||
void SearchSongsFinished();
|
||||
void SimpleSearchFinished();
|
||||
void Authenticated();
|
||||
void UserPlaylistsRetrieved();
|
||||
void PlaylistSongsRetrieved();
|
||||
|
||||
|
||||
private:
|
||||
void EnsureMenuCreated();
|
||||
void EnsureItemsCreated();
|
||||
|
@ -132,6 +137,9 @@ class GrooveSharkService : public InternetService {
|
|||
QString pending_search_;
|
||||
Playlist* pending_search_playlist_;
|
||||
|
||||
int next_pending_search_id_;
|
||||
QMap<QNetworkReply*, int> pending_searches_;
|
||||
|
||||
QMap<QNetworkReply*, PlaylistInfo> pending_retrieve_playlists_;
|
||||
|
||||
QStandardItem* root_;
|
||||
|
|
Loading…
Reference in New Issue