mirror of
https://github.com/clementine-player/Clementine
synced 2025-02-01 11:56:45 +01:00
Tidy up closure implementation.
This commit is contained in:
parent
20a967a19f
commit
fc34a244c6
@ -1,3 +1,20 @@
|
|||||||
|
/* This file is part of Clementine.
|
||||||
|
Copyright 2011, David Sansome <me@davidsansome.com>
|
||||||
|
|
||||||
|
Clementine is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
Clementine is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
#include "closure.h"
|
#include "closure.h"
|
||||||
|
|
||||||
#include "core/logging.h"
|
#include "core/logging.h"
|
||||||
@ -6,24 +23,30 @@ Closure::Closure(QObject* sender,
|
|||||||
const char* signal,
|
const char* signal,
|
||||||
QObject* receiver,
|
QObject* receiver,
|
||||||
const char* slot,
|
const char* slot,
|
||||||
const ClosureArgumentWrapper* val1,
|
const ClosureArgumentWrapper* val0,
|
||||||
const ClosureArgumentWrapper* val2)
|
const ClosureArgumentWrapper* val1)
|
||||||
: QObject(receiver),
|
: QObject(receiver),
|
||||||
val1_(val1),
|
val0_(val0),
|
||||||
val2_(val2) {
|
val1_(val1) {
|
||||||
const QMetaObject* meta_receiver = receiver->metaObject();
|
const QMetaObject* meta_receiver = receiver->metaObject();
|
||||||
|
|
||||||
QByteArray normalised_slot = QMetaObject::normalizedSignature(slot + 1);
|
QByteArray normalised_slot = QMetaObject::normalizedSignature(slot + 1);
|
||||||
slot_ = meta_receiver->method(
|
slot_ = meta_receiver->method(
|
||||||
meta_receiver->indexOfSlot(normalised_slot.constData()));
|
meta_receiver->indexOfSlot(normalised_slot.constData()));
|
||||||
|
|
||||||
connect(sender, signal, this, SLOT(Invoked()), Qt::AutoConnection);
|
connect(sender, signal, SLOT(Invoked()));
|
||||||
|
connect(sender, SIGNAL(destroyed()), SLOT(Cleanup()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Closure::Invoked() {
|
void Closure::Invoked() {
|
||||||
qLog(Debug) << "Invoking:" << slot_.signature() << val1_->arg().name();
|
slot_.invoke(
|
||||||
slot_.invoke(parent(), val1_->arg(), val2_->arg());
|
parent(),
|
||||||
|
val0_ ? val0_->arg() : QGenericArgument(),
|
||||||
delete val1_;
|
val1_ ? val1_->arg() : QGenericArgument());
|
||||||
delete val2_;
|
deleteLater();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Closure::Cleanup() {
|
||||||
|
disconnect();
|
||||||
|
deleteLater();
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,35 @@
|
|||||||
|
/* This file is part of Clementine.
|
||||||
|
Copyright 2011, David Sansome <me@davidsansome.com>
|
||||||
|
|
||||||
|
Clementine is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
Clementine is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef CLOSURE_H
|
#ifndef CLOSURE_H
|
||||||
#define CLOSURE_H
|
#define CLOSURE_H
|
||||||
|
|
||||||
#include <QMetaMethod>
|
#include <QMetaMethod>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
|
#include <boost/scoped_ptr.hpp>
|
||||||
|
|
||||||
#include "core/logging.h"
|
#include "core/logging.h"
|
||||||
|
|
||||||
class ClosureArgumentWrapper {
|
class ClosureArgumentWrapper {
|
||||||
public:
|
public:
|
||||||
virtual ~ClosureArgumentWrapper() {}
|
virtual ~ClosureArgumentWrapper() {}
|
||||||
|
|
||||||
virtual QGenericArgument arg() const {
|
virtual QGenericArgument arg() const = 0;
|
||||||
qLog(Debug) << Q_FUNC_INFO;
|
|
||||||
return QGenericArgument();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
@ -22,7 +38,6 @@ class ClosureArgument : public ClosureArgumentWrapper {
|
|||||||
ClosureArgument(const T& data) : data_(data) {}
|
ClosureArgument(const T& data) : data_(data) {}
|
||||||
|
|
||||||
virtual QGenericArgument arg() const {
|
virtual QGenericArgument arg() const {
|
||||||
qLog(Debug) << Q_FUNC_INFO;
|
|
||||||
return Q_ARG(T, data_);
|
return Q_ARG(T, data_);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,17 +51,18 @@ class Closure : public QObject {
|
|||||||
public:
|
public:
|
||||||
Closure(QObject* sender, const char* signal,
|
Closure(QObject* sender, const char* signal,
|
||||||
QObject* receiver, const char* slot,
|
QObject* receiver, const char* slot,
|
||||||
const ClosureArgumentWrapper* val1,
|
const ClosureArgumentWrapper* val0 = 0,
|
||||||
const ClosureArgumentWrapper* val2);
|
const ClosureArgumentWrapper* val1 = 0);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void Invoked();
|
void Invoked();
|
||||||
|
void Cleanup();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QMetaMethod slot_;
|
QMetaMethod slot_;
|
||||||
|
|
||||||
const ClosureArgumentWrapper* val1_;
|
boost::scoped_ptr<const ClosureArgumentWrapper> val0_;
|
||||||
const ClosureArgumentWrapper* val2_;
|
boost::scoped_ptr<const ClosureArgumentWrapper> val1_;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define C_ARG(type, data) new ClosureArgument<type>(data)
|
#define C_ARG(type, data) new ClosureArgument<type>(data)
|
||||||
|
@ -171,7 +171,7 @@ int GrooveSharkService::SearchAlbums(const QString& query) {
|
|||||||
|
|
||||||
QNetworkReply* reply = CreateRequest("getAlbumSearchResults", parameters, false);
|
QNetworkReply* reply = CreateRequest("getAlbumSearchResults", parameters, false);
|
||||||
|
|
||||||
int id = next_pending_search_id_++;
|
const int id = next_pending_search_id_++;
|
||||||
|
|
||||||
new Closure(reply, SIGNAL(finished()),
|
new Closure(reply, SIGNAL(finished()),
|
||||||
this, SLOT(SearchAlbumsFinished(QNetworkReply*,int)),
|
this, SLOT(SearchAlbumsFinished(QNetworkReply*,int)),
|
||||||
@ -182,7 +182,19 @@ int GrooveSharkService::SearchAlbums(const QString& query) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GrooveSharkService::SearchAlbumsFinished(QNetworkReply* reply, int id) {
|
void GrooveSharkService::SearchAlbumsFinished(QNetworkReply* reply, int id) {
|
||||||
qLog(Debug) << reply << id;
|
reply->deleteLater();
|
||||||
|
|
||||||
|
QVariantMap result = ExtractResult(reply);
|
||||||
|
QVariantList albums = result["albums"].toList();
|
||||||
|
foreach (const QVariant& v, albums) {
|
||||||
|
QVariantMap album = v.toMap();
|
||||||
|
//quint64 album_id = album["AlbumID"].toULongLong();
|
||||||
|
QString album_name = album["AlbumName"].toString();
|
||||||
|
QString artist_name = album["ArtistName"].toString();
|
||||||
|
//QString cover_art = album["CoverArtFilename"].toString();
|
||||||
|
|
||||||
|
qLog(Debug) << "Found:" << album_name << artist_name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GrooveSharkService::DoSearch() {
|
void GrooveSharkService::DoSearch() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user