Skip to content

Commit

Permalink
Get metadata from main window instead
Browse files Browse the repository at this point in the history
  • Loading branch information
kraxarn committed Apr 12, 2020
1 parent 5c63d71 commit 2326ec9
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 16 deletions.
7 changes: 6 additions & 1 deletion src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -791,4 +791,9 @@ QStringList MainWindow::currentTracks()
for (int i = 0; i < songs->topLevelItemCount(); i++)
tracks.append(songs->topLevelItem(i)->data(0, RoleTrackId).toString());
return tracks;
}
}

spt::Playback MainWindow::currentPlayback()
{
return current;
}
1 change: 1 addition & 0 deletions src/mainwindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class MainWindow : public QMainWindow
QPixmap getImage(const QString &type, const QString &url);
void refreshPlaylist(spt::Playlist &playlist, bool force = false);
bool loadPlaylist(spt::Playlist &playlist);
spt::Playback currentPlayback();
// I know these should be methods, I'm just lazy
QString cacheLocation;
QVector<spt::Playlist> *sptPlaylists;
Expand Down
31 changes: 17 additions & 14 deletions src/mediaplayer/mediaplayerplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ using namespace mp;
MediaPlayerPlayer::MediaPlayerPlayer(spt::Spotify *spotify, QObject *parent)
: spotify(spotify), dBus(QDBusConnection::sessionBus()), QDBusAbstractAdaptor(parent)
{
currentPlayback = spotify->currentPlayback();
}

void MediaPlayerPlayer::Next() const
Expand All @@ -25,7 +24,7 @@ void MediaPlayerPlayer::Play() const

void MediaPlayerPlayer::PlayPause() const
{
if (spotify->currentPlayback().isPlaying)
if (currentPlayback().isPlaying)
spotify->pause();
else
spotify->resume();
Expand Down Expand Up @@ -57,12 +56,12 @@ bool MediaPlayerPlayer::canControl() const
}
QMap<QString, QVariant> MediaPlayerPlayer::metadata() const
{
return spotify->currentPlayback().metadata();
return currentPlayback().metadata();
}

double MediaPlayerPlayer::getVolume() const
{
return spotify->currentPlayback().volume / 100.0;
return currentPlayback().volume / 100.0;
}

void MediaPlayerPlayer::setVolume(double value) const
Expand All @@ -72,12 +71,12 @@ void MediaPlayerPlayer::setVolume(double value) const

qint64 MediaPlayerPlayer::position() const
{
return spotify->currentPlayback().progressMs * 1000;
return currentPlayback().progressMs * 1000;
}

QString MediaPlayerPlayer::playbackStatus() const
{
return spotify->currentPlayback().isPlaying ? "Playing" : "Paused";
return currentPlayback().isPlaying ? "Playing" : "Paused";
}

void MediaPlayerPlayer::OpenUri(QString uri) const
Expand All @@ -98,7 +97,7 @@ void MediaPlayerPlayer::setPlaybackRate(double value) const

bool MediaPlayerPlayer::shuffle() const
{
return spotify->currentPlayback().shuffle;
return currentPlayback().shuffle;
}

void MediaPlayerPlayer::setShuffle(bool value) const
Expand All @@ -109,31 +108,31 @@ void MediaPlayerPlayer::setShuffle(bool value) const
void MediaPlayerPlayer::emitMetadataChange() const
{
QVariantMap properties;
properties["Metadata"] = spotify->currentPlayback().metadata();
properties["Metadata"] = currentPlayback().metadata();
Service::signalPropertiesChange(this, properties);
}

void MediaPlayerPlayer::currentSourceChanged() const
{
QVariantMap properties;
properties["Metadata"] = currentPlayback.metadata();
properties["PlaybackStatus"] = currentPlayback.isPlaying ? "Playing" : "Paused";
properties["Metadata"] = currentPlayback().metadata();
properties["PlaybackStatus"] = currentPlayback().isPlaying ? "Playing" : "Paused";
//properties["CanSeek"] = true;
Service::signalPropertiesChange(this, properties);
}

void MediaPlayerPlayer::stateUpdated() const
{
QVariantMap properties;
properties["PlaybackStatus"] = spotify->currentPlayback().isPlaying ? "Playing" : "Paused";
properties["PlaybackStatus"] = currentPlayback().isPlaying ? "Playing" : "Paused";
//properties["CanPause"] = true;
Service::signalPropertiesChange(this, properties);
}

void MediaPlayerPlayer::totalTimeChanged() const
{
QVariantMap properties;
properties["Metadata"] = currentPlayback.metadata();
properties["Metadata"] = currentPlayback().metadata();
Service::signalPropertiesChange(this, properties);
}

Expand All @@ -147,7 +146,7 @@ void MediaPlayerPlayer::seekableChanged(bool seekable) const
void MediaPlayerPlayer::volumeChanged() const
{
QVariantMap properties;
properties["Volume"] = spotify->currentPlayback().volume / 100.0;
properties["Volume"] = currentPlayback().volume / 100.0;
Service::signalPropertiesChange(this, properties);
}

Expand All @@ -158,5 +157,9 @@ void MediaPlayerPlayer::tick(qint64 newPos)

void MediaPlayerPlayer::setCurrentPlayback(const spt::Playback &playback)
{
currentPlayback = playback;
}

spt::Playback MediaPlayerPlayer::currentPlayback() const
{
return ((Service*) parent())->currentPlayback();
}
4 changes: 3 additions & 1 deletion src/mediaplayer/mediaplayerplayer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace mp { class MediaPlayerPlayer; }

#include "../spotify/spotify.hpp"
#include "../mainwindow.hpp"
#include "service.hpp"

#include <QDBusConnection>
#include <QDebug>
Expand Down Expand Up @@ -81,6 +82,7 @@ namespace mp
private:
QDBusConnection dBus;
spt::Spotify *spotify;
spt::Playback currentPlayback;

spt::Playback currentPlayback() const;
};
}
5 changes: 5 additions & 0 deletions src/mediaplayer/service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ void Service::tick(qint64 newPos)
emit playerPlayer->tick(newPos);
}

spt::Playback Service::currentPlayback()
{
return ((MainWindow*) parent())->currentPlayback();
}

/*void Service::updateMetadata(const QVariantMap &metadata)
{
//properties->updateMetadata(metadata);
Expand Down
2 changes: 2 additions & 0 deletions src/mediaplayer/service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ namespace mp
Service(spt::Spotify *spotify, QObject *parent);
virtual ~Service();

spt::Playback currentPlayback();

static void signalPropertiesChange(const QObject* adaptor, const QVariantMap& properties);

void metadataChanged();
Expand Down

0 comments on commit 2326ec9

Please sign in to comment.