Revert "Move TaskManager::Task and UrlHandler::LoadResult structs out of their parent classes - PythonQt doesn't understand nested structs."

This reverts commit 5234798a7f.
This commit is contained in:
David Sansome 2011-07-21 00:22:20 +01:00
parent dd3eee63e5
commit 9fadf57acc
18 changed files with 97 additions and 107 deletions

View File

@ -81,9 +81,9 @@ void Player::ReloadSettings() {
engine_->ReloadSettings();
}
void Player::HandleLoadResult(const UrlHandler_LoadResult& result) {
void Player::HandleLoadResult(const UrlHandler::LoadResult& result) {
switch (result.type_) {
case UrlHandler_LoadResult::NoMoreTracks:
case UrlHandler::LoadResult::NoMoreTracks:
qLog(Debug) << "URL handler for" << result.original_url_
<< "said no more tracks";
@ -91,7 +91,7 @@ void Player::HandleLoadResult(const UrlHandler_LoadResult& result) {
NextItem(Engine::Auto);
break;
case UrlHandler_LoadResult::TrackAvailable: {
case UrlHandler::LoadResult::TrackAvailable: {
// Might've been an async load, so check we're still on the same item
int current_index = playlists_->active()->current_row();
if (current_index == -1)
@ -114,7 +114,7 @@ void Player::HandleLoadResult(const UrlHandler_LoadResult& result) {
break;
}
case UrlHandler_LoadResult::WillLoadAsynchronously:
case UrlHandler::LoadResult::WillLoadAsynchronously:
qLog(Debug) << "URL handler for" << result.original_url_
<< "is loading asynchronously";
@ -446,16 +446,16 @@ void Player::TrackAboutToEnd() {
// Get the actual track URL rather than the stream URL.
if (url_handlers_.contains(url.scheme())) {
UrlHandler_LoadResult result = url_handlers_[url.scheme()]->LoadNext(url);
UrlHandler::LoadResult result = url_handlers_[url.scheme()]->LoadNext(url);
switch (result.type_) {
case UrlHandler_LoadResult::NoMoreTracks:
case UrlHandler::LoadResult::NoMoreTracks:
return;
case UrlHandler_LoadResult::WillLoadAsynchronously:
case UrlHandler::LoadResult::WillLoadAsynchronously:
loading_async_ = url;
return;
case UrlHandler_LoadResult::TrackAvailable:
case UrlHandler::LoadResult::TrackAvailable:
url = result.media_url_;
break;
}
@ -489,8 +489,8 @@ void Player::RegisterUrlHandler(UrlHandler* handler) {
qLog(Info) << "Registered URL handler for" << scheme;
url_handlers_.insert(scheme, handler);
connect(handler, SIGNAL(destroyed(QObject*)), SLOT(UrlHandlerDestroyed(QObject*)));
connect(handler, SIGNAL(AsyncLoadComplete(UrlHandler_LoadResult)),
SLOT(HandleLoadResult(UrlHandler_LoadResult)));
connect(handler, SIGNAL(AsyncLoadComplete(UrlHandler::LoadResult)),
SLOT(HandleLoadResult(UrlHandler::LoadResult)));
}
void Player::UnregisterUrlHandler(UrlHandler* handler) {
@ -504,8 +504,8 @@ void Player::UnregisterUrlHandler(UrlHandler* handler) {
qLog(Info) << "Unregistered URL handler for" << scheme;
url_handlers_.remove(scheme);
disconnect(handler, SIGNAL(destroyed(QObject*)), this, SLOT(UrlHandlerDestroyed(QObject*)));
disconnect(handler, SIGNAL(AsyncLoadComplete(UrlHandler_LoadResult)),
this, SLOT(HandleLoadResult(UrlHandler_LoadResult)));
disconnect(handler, SIGNAL(AsyncLoadComplete(UrlHandler::LoadResult)),
this, SLOT(HandleLoadResult(UrlHandler::LoadResult)));
}
void Player::UrlHandlerDestroyed(QObject* object) {

View File

@ -161,7 +161,7 @@ public slots:
void InvalidSongRequested(const QUrl&);
void UrlHandlerDestroyed(QObject* object);
void HandleLoadResult(const UrlHandler_LoadResult& result);
void HandleLoadResult(const UrlHandler::LoadResult& result);
private:
PlaylistManagerInterface* playlists_;

View File

@ -24,7 +24,7 @@ TaskManager::TaskManager(QObject *parent)
}
int TaskManager::StartTask(const QString& name) {
TaskManager_Task t;
Task t;
t.name = name;
t.progress = 0;
t.progress_max = 0;
@ -40,8 +40,8 @@ int TaskManager::StartTask(const QString& name) {
return t.id;
}
QList<TaskManager_Task> TaskManager::GetTasks() {
QList<TaskManager_Task> ret;
QList<TaskManager::Task> TaskManager::GetTasks() {
QList<TaskManager::Task> ret;
{
QMutexLocker l(&mutex_);
@ -57,7 +57,7 @@ void TaskManager::SetTaskBlocksLibraryScans(int id) {
if (!tasks_.contains(id))
return;
TaskManager_Task& t = tasks_[id];
Task& t = tasks_[id];
t.blocks_library_scans = true;
}
@ -71,7 +71,7 @@ void TaskManager::SetTaskProgress(int id, int progress, int max) {
if (!tasks_.contains(id))
return;
TaskManager_Task& t = tasks_[id];
Task& t = tasks_[id];
t.progress = progress;
if (max)
t.progress_max = max;
@ -90,7 +90,7 @@ void TaskManager::SetTaskFinished(int id) {
if (tasks_[id].blocks_library_scans) {
resume_library_watchers = true;
foreach (const TaskManager_Task& task, tasks_.values()) {
foreach (const Task& task, tasks_.values()) {
if (task.id != id && task.blocks_library_scans) {
resume_library_watchers = false;
break;

View File

@ -22,22 +22,22 @@
#include <QMutex>
#include <QObject>
struct TaskManager_Task {
int id;
QString name;
int progress;
int progress_max;
bool blocks_library_scans;
};
class TaskManager : public QObject {
Q_OBJECT
public:
TaskManager(QObject* parent = 0);
struct Task {
int id;
QString name;
int progress;
int progress_max;
bool blocks_library_scans;
};
// Everything here is thread safe
QList<TaskManager_Task> GetTasks();
QList<Task> GetTasks();
int StartTask(const QString& name);
void SetTaskBlocksLibraryScans(int id);
@ -52,7 +52,7 @@ signals:
private:
QMutex mutex_;
QMap<int, TaskManager_Task> tasks_;
QMap<int, Task> tasks_;
int next_task_id_;
};

View File

@ -17,7 +17,7 @@
#include "urlhandler.h"
UrlHandler_LoadResult::UrlHandler_LoadResult(
UrlHandler::LoadResult::LoadResult(
const QUrl& original_url, Type type, const QUrl& media_url)
: original_url_(original_url), type_(type), media_url_(media_url)
{

View File

@ -21,37 +21,6 @@
#include <QObject>
#include <QUrl>
// Returned by StartLoading() and LoadNext(), indicates what the player
// should do when it wants to load a URL.
struct UrlHandler_LoadResult {
enum Type {
// There wasn't a track available, and the player should move on to the
// next playlist item.
NoMoreTracks,
// There might be another track available but the handler needs to do some
// work (eg. fetching a remote playlist) to find out. AsyncLoadComplete
// will be emitted later with the same original_url.
WillLoadAsynchronously,
// There was a track available. Its url is in media_url.
TrackAvailable,
};
UrlHandler_LoadResult(const QUrl& original_url = QUrl(),
Type type = NoMoreTracks,
const QUrl& media_url = QUrl());
// The url that the playlist item has in Url().
// Might be something unplayable like lastfm://...
QUrl original_url_;
Type type_;
// The actual url to something that gstreamer can play.
QUrl media_url_;
};
class UrlHandler : public QObject {
Q_OBJECT
@ -61,20 +30,47 @@ public:
// The URL scheme that this handler handles.
virtual QString scheme() const = 0;
// Returned by StartLoading() and LoadNext(), indicates what the player
// should do when it wants to load a URL.
struct LoadResult {
enum Type {
// There wasn't a track available, and the player should move on to the
// next playlist item.
NoMoreTracks,
// There might be another track available but the handler needs to do some
// work (eg. fetching a remote playlist) to find out. AsyncLoadComplete
// will be emitted later with the same original_url.
WillLoadAsynchronously,
// There was a track available. Its url is in media_url.
TrackAvailable,
};
LoadResult(const QUrl& original_url = QUrl(),
Type type = NoMoreTracks,
const QUrl& media_url = QUrl());
// The url that the playlist item has in Url().
// Might be something unplayable like lastfm://...
QUrl original_url_;
Type type_;
// The actual url to something that gstreamer can play.
QUrl media_url_;
};
// Called by the Player when a song starts loading - gives the handler
// a chance to do something clever to get a playable track.
virtual UrlHandler_LoadResult StartLoading(const QUrl& url) {
return UrlHandler_LoadResult(url);
}
virtual LoadResult StartLoading(const QUrl& url) { return LoadResult(url); }
// Called by the player when a song finishes - gives the handler a chance to
// get another track to play.
virtual UrlHandler_LoadResult LoadNext(const QUrl& url) {
return UrlHandler_LoadResult(url);
}
virtual LoadResult LoadNext(const QUrl& url) { return LoadResult(url); }
signals:
void AsyncLoadComplete(const UrlHandler_LoadResult& result);
void AsyncLoadComplete(const UrlHandler::LoadResult& result);
};
#endif // URLHANDLER_H

View File

@ -686,10 +686,10 @@ void DeviceManager::DeviceTaskStarted(int id) {
}
void DeviceManager::TasksChanged() {
QList<TaskManager_Task> tasks = task_manager_->GetTasks();
QList<TaskManager::Task> tasks = task_manager_->GetTasks();
QList<QPersistentModelIndex> finished_tasks = active_tasks_.values();
foreach (const TaskManager_Task& task, tasks) {
foreach (const TaskManager::Task& task, tasks) {
if (!active_tasks_.contains(task.id))
continue;

View File

@ -33,8 +33,8 @@ QString DigitallyImportedUrlHandler::scheme() const {
return service_->url_scheme_;
}
UrlHandler_LoadResult DigitallyImportedUrlHandler::StartLoading(const QUrl& url) {
UrlHandler_LoadResult ret(url);
UrlHandler::LoadResult DigitallyImportedUrlHandler::StartLoading(const QUrl& url) {
LoadResult ret(url);
if (task_id_ != -1) {
return ret;
}
@ -60,7 +60,7 @@ UrlHandler_LoadResult DigitallyImportedUrlHandler::StartLoading(const QUrl& url)
// Tell the user what's happening
task_id_ = service_->model()->task_manager()->StartTask(tr("Loading stream"));
ret.type_ = UrlHandler_LoadResult::WillLoadAsynchronously;
ret.type_ = LoadResult::WillLoadAsynchronously;
return ret;
}
@ -84,10 +84,8 @@ void DigitallyImportedUrlHandler::LoadPlaylistFinished(QIODevice* device) {
return;
}
emit AsyncLoadComplete(UrlHandler_LoadResult(
last_original_url_,
UrlHandler_LoadResult::TrackAvailable,
songs[0].url()));
emit AsyncLoadComplete(LoadResult(
last_original_url_, LoadResult::TrackAvailable, songs[0].url()));
}
void DigitallyImportedUrlHandler::CancelTask() {

View File

@ -28,7 +28,7 @@ public:
DigitallyImportedUrlHandler(DigitallyImportedServiceBase* service);
QString scheme() const;
UrlHandler_LoadResult StartLoading(const QUrl& url);
LoadResult StartLoading(const QUrl& url);
void CancelTask();
void LoadPlaylistFinished(QIODevice* device);

View File

@ -23,12 +23,12 @@ LastFMUrlHandler::LastFMUrlHandler(LastFMService* service, QObject* parent)
service_(service) {
}
UrlHandler_LoadResult LastFMUrlHandler::StartLoading(const QUrl& url) {
UrlHandler::LoadResult LastFMUrlHandler::StartLoading(const QUrl& url) {
if (!service_->IsAuthenticated())
return UrlHandler_LoadResult();
return LoadResult();
service_->Tune(url);
return UrlHandler_LoadResult(url, UrlHandler_LoadResult::WillLoadAsynchronously);
return LoadResult(url, LoadResult::WillLoadAsynchronously);
}
void LastFMUrlHandler::TunerTrackAvailable() {
@ -36,14 +36,13 @@ void LastFMUrlHandler::TunerTrackAvailable() {
}
void LastFMUrlHandler::TunerError() {
emit AsyncLoadComplete(UrlHandler_LoadResult(
service_->last_url_, UrlHandler_LoadResult::NoMoreTracks));
emit AsyncLoadComplete(LoadResult(service_->last_url_, LoadResult::NoMoreTracks));
}
UrlHandler_LoadResult LastFMUrlHandler::LoadNext(const QUrl& url) {
UrlHandler::LoadResult LastFMUrlHandler::LoadNext(const QUrl& url) {
const QUrl media_url = service_->DeququeNextMediaUrl();
if (media_url.isEmpty()) {
return UrlHandler_LoadResult();
return LoadResult();
}
return UrlHandler_LoadResult(url, UrlHandler_LoadResult::TrackAvailable, media_url);
return LoadResult(url, LoadResult::TrackAvailable, media_url);
}

View File

@ -30,8 +30,8 @@ public:
LastFMUrlHandler(LastFMService* service, QObject* parent);
QString scheme() const { return "lastfm"; }
UrlHandler_LoadResult StartLoading(const QUrl& url);
UrlHandler_LoadResult LoadNext(const QUrl& url);
LoadResult StartLoading(const QUrl& url);
LoadResult LoadNext(const QUrl& url);
void TunerTrackAvailable();
void TunerError();

View File

@ -23,7 +23,6 @@ MagnatuneUrlHandler::MagnatuneUrlHandler(MagnatuneService* service, QObject* par
service_(service) {
}
UrlHandler_LoadResult MagnatuneUrlHandler::StartLoading(const QUrl& url) {
return UrlHandler_LoadResult(url, UrlHandler_LoadResult::TrackAvailable,
service_->ModifyUrl(url));
UrlHandler::LoadResult MagnatuneUrlHandler::StartLoading(const QUrl& url) {
return LoadResult(url, LoadResult::TrackAvailable, service_->ModifyUrl(url));
}

View File

@ -28,7 +28,7 @@ public:
MagnatuneUrlHandler(MagnatuneService* service, QObject* parent);
QString scheme() const { return "magnatune"; }
UrlHandler_LoadResult StartLoading(const QUrl& url);
LoadResult StartLoading(const QUrl& url);
private:
MagnatuneService* service_;

View File

@ -33,7 +33,7 @@ SomaFMUrlHandler::SomaFMUrlHandler(SomaFMService* service, QObject* parent)
{
}
UrlHandler_LoadResult SomaFMUrlHandler::StartLoading(const QUrl& url) {
UrlHandler::LoadResult SomaFMUrlHandler::StartLoading(const QUrl& url) {
QUrl playlist_url = url;
playlist_url.setScheme("http");
@ -44,7 +44,7 @@ UrlHandler_LoadResult SomaFMUrlHandler::StartLoading(const QUrl& url) {
if (!task_id_)
task_id_ = service_->model()->task_manager()->StartTask(tr("Loading stream"));
return UrlHandler_LoadResult(url, UrlHandler_LoadResult::WillLoadAsynchronously);
return LoadResult(url, LoadResult::WillLoadAsynchronously);
}
void SomaFMUrlHandler::LoadPlaylistFinished() {
@ -58,8 +58,7 @@ void SomaFMUrlHandler::LoadPlaylistFinished() {
if (reply->error() != QNetworkReply::NoError) {
// TODO: Error handling
qLog(Error) << reply->errorString();
emit AsyncLoadComplete(UrlHandler_LoadResult(
original_url, UrlHandler_LoadResult::NoMoreTracks));
emit AsyncLoadComplete(LoadResult(original_url, LoadResult::NoMoreTracks));
return;
}
@ -72,7 +71,6 @@ void SomaFMUrlHandler::LoadPlaylistFinished() {
QSettings s(temp_file.fileName(), QSettings::IniFormat);
s.beginGroup("playlist");
emit AsyncLoadComplete(UrlHandler_LoadResult(
original_url, UrlHandler_LoadResult::TrackAvailable,
s.value("File1").toString()));
emit AsyncLoadComplete(LoadResult(original_url, LoadResult::TrackAvailable,
s.value("File1").toString()));
}

View File

@ -30,7 +30,7 @@ public:
SomaFMUrlHandler(SomaFMService* service, QObject* parent);
QString scheme() const { return "somafm"; }
UrlHandler_LoadResult StartLoading(const QUrl& url);
LoadResult StartLoading(const QUrl& url);
private slots:
void LoadPlaylistFinished();

View File

@ -27,7 +27,7 @@ SpotifyUrlHandler::SpotifyUrlHandler(SpotifyService* service, QObject* parent)
service_(service) {
}
UrlHandler_LoadResult SpotifyUrlHandler::StartLoading(const QUrl& url) {
UrlHandler::LoadResult SpotifyUrlHandler::StartLoading(const QUrl& url) {
// Pick an unused local port. There's a possible race condition here -
// something else might grab the port before gstreamer does.
quint16 port = 0;
@ -40,13 +40,13 @@ UrlHandler_LoadResult SpotifyUrlHandler::StartLoading(const QUrl& url) {
if (port == 0) {
qLog(Warning) << "Couldn't pick an unused port";
return UrlHandler_LoadResult();
return LoadResult();
}
// Tell Spotify to start sending to this port
service_->server()->StartPlayback(url.toString(), port);
// Tell gstreamer to listen on this port
return UrlHandler_LoadResult(url, UrlHandler_LoadResult::TrackAvailable,
QUrl("tcp://localhost:" + QString::number(port)));
return LoadResult(url, LoadResult::TrackAvailable,
QUrl("tcp://localhost:" + QString::number(port)));
}

View File

@ -28,7 +28,7 @@ public:
SpotifyUrlHandler(SpotifyService* service, QObject* parent);
QString scheme() const { return "spotify"; }
UrlHandler_LoadResult StartLoading(const QUrl& url);
LoadResult StartLoading(const QUrl& url);
private:
SpotifyService* service_;

View File

@ -47,10 +47,10 @@ void MultiLoadingIndicator::SetTaskManager(TaskManager* task_manager) {
}
void MultiLoadingIndicator::UpdateText() {
QList<TaskManager_Task> tasks = task_manager_->GetTasks();
QList<TaskManager::Task> tasks = task_manager_->GetTasks();
QStringList strings;
foreach (const TaskManager_Task& task, tasks) {
foreach (const TaskManager::Task& task, tasks) {
QString task_text(task.name);
task_text[0] = task_text[0].toLower();