1
0
mirror of https://github.com/clementine-player/Clementine synced 2024-12-18 20:34:39 +01:00

Add some syntactic sugar to closures.

This commit is contained in:
John Maguire 2011-10-06 13:11:18 +02:00
parent bac6095491
commit a6e8797b9d
3 changed files with 43 additions and 8 deletions

View File

@ -63,3 +63,9 @@ void Closure::Cleanup() {
disconnect();
deleteLater();
}
Closure* NewClosure(
QObject* sender, const char* signal,
QObject* receiver, const char* slot) {
return new Closure(sender, signal, receiver, slot);
}

View File

@ -73,4 +73,35 @@ class Closure : public QObject {
#define C_ARG(type, data) new ClosureArgument<type>(data)
Closure* NewClosure(
QObject* sender,
const char* signal,
QObject* receiver,
const char* slot);
template <typename T>
Closure* NewClosure(
QObject* sender,
const char* signal,
QObject* receiver,
const char* slot,
const T& val0) {
return new Closure(
sender, signal, receiver, slot,
C_ARG(T, val0));
}
template <typename T0, typename T1>
Closure* NewClosure(
QObject* sender,
const char* signal,
QObject* receiver,
const char* slot,
const T0& val0,
const T1& val1) {
return new Closure(
sender, signal, receiver, slot,
C_ARG(T0, val0), C_ARG(T1, val1));
}
#endif // CLOSURE_H

View File

@ -173,10 +173,9 @@ int GroovesharkService::SearchAlbums(const QString& query) {
const int id = next_pending_search_id_++;
new Closure(reply, SIGNAL(finished()),
this, SLOT(SearchAlbumsFinished(QNetworkReply*,int)),
C_ARG(QNetworkReply*, reply),
C_ARG(int, id));
NewClosure(reply, SIGNAL(finished()),
this, SLOT(SearchAlbumsFinished(QNetworkReply*,int)),
reply, id);
return id;
}
@ -222,10 +221,9 @@ void GroovesharkService::FetchSongsForAlbum(int id, quint64 album_id) {
<< Param("country", "");
QNetworkReply* reply = CreateRequest("getAlbumSongs", parameters, false);
new Closure(reply, SIGNAL(finished()),
this, SLOT(GetAlbumSongsFinished(QNetworkReply*,int)),
C_ARG(QNetworkReply*, reply),
C_ARG(int, id));
NewClosure(reply, SIGNAL(finished()),
this, SLOT(GetAlbumSongsFinished(QNetworkReply*,int)),
reply, id);
}
void GroovesharkService::GetAlbumSongsFinished(