1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- #include "song.h"
-
- Song::Song(QObject *parent) : QObject(parent), cover(0, 0)
- {
- tries = 0;
- }
-
- QString Song::getArtist() const
- {
- return artist;
- }
-
- QString Song::getTitle() const
- {
- return title;
- }
-
- QUrl Song::getCoverUrl() const
- {
- return coverUrl;
- }
-
- int Song::getDuration() const
- {
- return duration;
- }
-
- void Song::setArtist(QString a)
- {
- artist = a;
- }
-
- void Song::setTitle(QString t)
- {
- title = t;
- }
-
- void Song::setCoverUrl(QUrl u)
- {
- coverUrl = u;
- }
-
- void Song::setDuration(int d)
- {
- duration = d;
- }
-
- void Song::downloadCover()
- {
- if(cover.isNull())
- {
- if(mgr != 0)
- {
- tries = 0;
- QNetworkReply* reply = mgr->get(QNetworkRequest(coverUrl));
- connect(reply, SIGNAL(finished()), this, SLOT(onCoverFinished()));
- connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(onCoverError(QNetworkReply::NetworkError)));
- }
- }
- else
- emit coverDownloaded(cover);
- }
-
- void Song::setNetworkManager(QNetworkAccessManager *m)
- {
- mgr = m;
- }
-
- void Song::onCoverFinished()
- {
- QNetworkReply* reply = (QNetworkReply*)sender();
- if(cover.loadFromData(reply->readAll()) && !cover.isNull())
- emit coverDownloaded(cover);
- }
-
- void Song::onCoverError(QNetworkReply::NetworkError)
- {
- if(tries < 3)
- {
- ++tries;
- downloadCover();
- }
- }
|