Commit 0598677d authored by Michael Pyne's avatar Michael Pyne

Decouple StatusLabel from PlayerManager, cleanup StatusLabel.

parent 230b5b8f
......@@ -14,8 +14,8 @@
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef FILEHANDLE_H
#define FILEHANDLE_H
#ifndef JUK_FILEHANDLE_H
#define JUK_FILEHANDLE_H
#include <QString>
......
......@@ -165,22 +165,19 @@ void JuK::setupLayout()
{
new TagTransactionManager(this);
qCDebug(JUK_LOG) << "Creating GUI";
QTime stopwatch;
stopwatch.start();
m_splitter = new PlaylistSplitter(m_player, this);
setCentralWidget(m_splitter);
m_statusLabel = new StatusLabel(m_splitter->playlist(), statusBar());
connect(CollectionList::instance(), &CollectionList::signalCollectionChanged,
m_statusLabel, &StatusLabel::playlistItemDataHasChanged);
m_statusLabel = new StatusLabel(*m_splitter->playlist(), statusBar());
statusBar()->addWidget(m_statusLabel, 1);
m_player->setStatusLabel(m_statusLabel);
connect(m_player, &PlayerManager::tick, m_statusLabel,
&StatusLabel::setItemCurrentTime);
connect(m_player, &PlayerManager::totalTimeChanged,
m_statusLabel, &StatusLabel::setItemTotalTime);
connect(m_splitter, &PlaylistSplitter::currentPlaylistChanged,
m_statusLabel, &StatusLabel::slotCurrentPlaylistHasChanged);
m_splitter->setFocus();
qCDebug(JUK_LOG) << "GUI created in" << stopwatch.elapsed() << "ms";
}
void JuK::setupActions()
......
......@@ -45,14 +45,14 @@ MediaPlayer2Player::MediaPlayer2Player(QObject* parent)
: QDBusAbstractAdaptor(parent)
, m_player(JuK::JuKInstance()->playerManager())
{
connect(m_player, SIGNAL(signalItemChanged(FileHandle)), this, SLOT(currentSourceChanged()));
connect(m_player, SIGNAL(signalPlay()), this, SLOT(stateUpdated()));
connect(m_player, SIGNAL(signalPause()), this, SLOT(stateUpdated()));
connect(m_player, SIGNAL(signalStop()), this, SLOT(stateUpdated()));
connect(m_player, SIGNAL(totalTimeChanged(int)), this, SLOT(totalTimeChanged()));
connect(m_player, SIGNAL(seekableChanged(bool)), this, SLOT(seekableChanged(bool)));
connect(m_player, SIGNAL(volumeChanged(float)), this, SLOT(volumeChanged(float)));
connect(m_player, SIGNAL(seeked(int)), this, SLOT(seeked(int)));
connect(m_player, &PlayerManager::signalItemChanged, this, &MediaPlayer2Player::currentSourceChanged);
connect(m_player, &PlayerManager::signalPlay, this, &MediaPlayer2Player::stateUpdated);
connect(m_player, &PlayerManager::signalPause, this, &MediaPlayer2Player::stateUpdated);
connect(m_player, &PlayerManager::signalStop, this, &MediaPlayer2Player::stateUpdated);
connect(m_player, &PlayerManager::totalTimeChanged, this, &MediaPlayer2Player::totalTimeChanged);
connect(m_player, &PlayerManager::seekableChanged, this, &MediaPlayer2Player::seekableChanged);
connect(m_player, &PlayerManager::volumeChanged, this, &MediaPlayer2Player::volumeChanged);
connect(m_player, &PlayerManager::seeked, this, &MediaPlayer2Player::seeked);
}
MediaPlayer2Player::~MediaPlayer2Player()
......
......@@ -56,7 +56,6 @@ enum PlayerManagerStatus { StatusStopped = -1, StatusPaused = 1, StatusPlaying =
PlayerManager::PlayerManager() :
QObject(),
m_playlistInterface(nullptr),
m_statusLabel(nullptr),
m_setup(false)
{
// This class is the first thing constructed during program startup, and
......@@ -196,11 +195,6 @@ void PlayerManager::setPlaylistInterface(PlaylistInterface *interface)
m_playlistInterface = interface;
}
void PlayerManager::setStatusLabel(StatusLabel *label)
{
m_statusLabel = label;
}
////////////////////////////////////////////////////////////////////////////////
// public slots
////////////////////////////////////////////////////////////////////////////////
......@@ -409,18 +403,11 @@ void PlayerManager::slotFinished()
void PlayerManager::slotLength(qint64 msec)
{
m_statusLabel->setItemTotalTime(msec / 1000);
emit totalTimeChanged(msec);
}
void PlayerManager::slotTick(qint64 msec)
{
if(!m_setup || !m_playlistInterface)
return;
if(m_statusLabel)
m_statusLabel->setItemCurrentTime(msec / 1000);
emit tick(msec);
}
......
......@@ -26,7 +26,6 @@
#include <Phonon/Global>
#include <Phonon/Path>
class StatusLabel;
class PlaylistInterface;
class QPixmap;
......@@ -74,7 +73,6 @@ public:
QString playingString() const;
void setPlaylistInterface(PlaylistInterface *interface);
void setStatusLabel(StatusLabel *label);
QString randomPlayMode() const;
......@@ -100,8 +98,8 @@ public slots:
void setRandomPlayMode(const QString &randomMode);
signals:
void tick(int time);
void totalTimeChanged(int time);
void tick(qint64 /* time_msec */);
void totalTimeChanged(qint64 /* time_msec */);
void mutedChanged(bool muted);
void volumeChanged(float volume);
void seeked(int newPos);
......@@ -127,7 +125,6 @@ private slots:
private:
FileHandle m_file;
PlaylistInterface *m_playlistInterface;
StatusLabel *m_statusLabel;
bool m_muted;
bool m_setup;
......
......@@ -141,6 +141,7 @@ private:
class PlaylistBox::Item : public QObject, public QTreeWidgetItem, public PlaylistObserver
{
friend class PlaylistBox;
friend class PlaylistSplitter;
friend class ViewMode;
friend class CompactViewMode;
friend class TreeViewMode;
......
......@@ -180,7 +180,7 @@ void PlaylistSplitter::setupLayout()
// Create a splitter to go between the playlists and the editor.
m_editorSplitter = new QSplitter(Qt::Vertical, this);
m_editorSplitter->setObjectName( QLatin1String("editorSplitter" ));
m_editorSplitter->setObjectName(QLatin1String("editorSplitter"));
// Make sure none of the optional widgets are collapsible, this causes the
// widget to be essentially invisible but logically shown.
......@@ -196,13 +196,13 @@ void PlaylistSplitter::setupLayout()
topLayout->setSpacing(0);
m_playlistStack = new QStackedWidget(top);
m_playlistStack->setObjectName( QLatin1String("playlistStack" ));
m_playlistStack->setObjectName(QLatin1String("playlistStack"));
m_playlistStack->installEventFilter(this);
m_playlistStack->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
m_playlistStack->hide(); // Will be shown after CollectionList filled.
m_editor = new TagEditor(m_editorSplitter);
m_editor->setObjectName( QLatin1String("TagEditor" ));
m_editor->setObjectName(QLatin1String("TagEditor"));
// Create the lyrics widget
m_lyricsWidget = new LyricsWidget(this);
......@@ -210,13 +210,15 @@ void PlaylistSplitter::setupLayout()
// Create the PlaylistBox
m_playlistBox = new PlaylistBox(m_player, this, m_playlistStack);
m_playlistBox->setObjectName( QLatin1String( "playlistBox" ) );
m_playlistBox->setObjectName(QLatin1String("playlistBox"));
connect(m_playlistBox->object(), SIGNAL(signalSelectedItemsChanged()),
this, SLOT(slotPlaylistSelectionChanged()));
connect(m_playlistBox, SIGNAL(signalPlaylistDestroyed(Playlist*)),
m_editor, SLOT(slotPlaylistDestroyed(Playlist*)));
connect(m_playlistBox, SIGNAL(startupComplete()), SLOT(slotEnable()));
connect(m_playlistBox, &QTreeWidget::currentItemChanged,
this, &PlaylistSplitter::slotCurrentPlaylistChanged);
connect(m_playlistBox, SIGNAL(startFilePlayback(FileHandle)),
m_player, SLOT(play(FileHandle)));
......@@ -325,13 +327,16 @@ void PlaylistSplitter::slotPlaylistChanged(int i)
m_newVisible = 0;
}
void PlaylistSplitter::slotCurrentPlaylistChanged(QTreeWidgetItem *item)
{
auto pItem = static_cast<PlaylistBox::Item*>(item);
emit currentPlaylistChanged(*(pItem->playlist()));
}
void PlaylistSplitter::slotEnable()
{
qCDebug(JUK_LOG) << "Enabling GUI";
QTime stopwatch; stopwatch.start();
setEnabled(true); // Ready to go.
m_playlistStack->show();
qCDebug(JUK_LOG) << "Finished enabling GUI, took" << stopwatch.elapsed() << "ms";
(void) new Mpris2(this);
}
......
......@@ -20,6 +20,7 @@
#include <QSplitter>
class QStackedWidget;
class QTreeWidgetItem;
class Playlist;
class SearchWidget;
......@@ -59,6 +60,7 @@ signals:
* again at least this works.
*/
void guiReady();
void currentPlaylistChanged(const PlaylistInterface &currentPlaylist);
public slots:
virtual void setFocus();
......@@ -87,6 +89,7 @@ private slots:
void slotShowSearchResults();
void slotPlaylistSelectionChanged();
void slotPlaylistChanged(int i);
void slotCurrentPlaylistChanged(QTreeWidgetItem *item);
private:
Playlist *m_newVisible;
......
......@@ -32,6 +32,7 @@
#include "filehandle.h"
#include "playlistinterface.h"
#include "actioncollection.h"
#include "playermanager.h"
#include "tag.h"
#include "juk_debug.h"
......@@ -41,19 +42,18 @@ using namespace ActionCollection;
// static helpers
////////////////////////////////////////////////////////////////////////////////
static QString formatTime(int seconds)
static QString formatTime(qint64 milliseconds)
{
static const KFormat fmt;
return fmt.formatDuration(seconds * 1000);
return fmt.formatDuration(milliseconds);
}
////////////////////////////////////////////////////////////////////////////////
// public methods
////////////////////////////////////////////////////////////////////////////////
StatusLabel::StatusLabel(PlaylistInterface *playlist, QWidget *parent) :
QWidget(parent),
PlaylistObserver(playlist)
StatusLabel::StatusLabel(const PlaylistInterface &currentPlaylist, QWidget *parent) :
QWidget(parent)
{
auto hboxLayout = new QHBoxLayout(this);
......@@ -113,43 +113,33 @@ StatusLabel::StatusLabel(PlaylistInterface *playlist, QWidget *parent) :
installEventFilter(this);
playlistItemDataHasChanged();
slotCurrentPlaylistHasChanged(currentPlaylist);
}
void StatusLabel::playingItemHasChanged()
void StatusLabel::slotPlayingItemHasChanged(const FileHandle &file)
{
if(!playlist()->playing()) {
return;
}
const FileHandle file = playlist()->currentFile();
const Tag *tag = file.tag();
const QString mid = (tag->artist().isEmpty() || tag->title().isEmpty())
? QString()
: QStringLiteral(" - ");
setItemTotalTime(tag->seconds());
setItemCurrentTime(0);
m_trackLabel->setText(tag->artist() + mid + tag->title());
m_playlistLabel->setText(playlist()->name().simplified());
}
void StatusLabel::playlistItemDataHasChanged()
void StatusLabel::slotCurrentPlaylistHasChanged(const PlaylistInterface &currentPlaylist)
{
playingItemHasChanged();
const auto plist = playlist();
if(!plist->playing()) {
if(!currentPlaylist.playing()) {
return;
}
setItemTotalTime(0);
setItemCurrentTime(0);
m_playlistLabel->setText(plist->name());
m_playlistLabel->setText(currentPlaylist.name());
m_trackLabel->setText(
i18np("1 item", "%1 items", plist->count()) +
i18np("1 item", "%1 items", currentPlaylist.count()) +
QStringLiteral(" - ") +
formatTime(plist->time())
formatTime(qint64(1000) * currentPlaylist.time())
);
}
......@@ -159,10 +149,10 @@ void StatusLabel::playlistItemDataHasChanged()
void StatusLabel::updateTime()
{
const int seconds = m_showTimeRemaining
const qint64 milliseconds = m_showTimeRemaining
? m_itemTotalTime - m_itemCurrentTime
: m_itemCurrentTime;
const QString timeString = formatTime(seconds) + QStringLiteral(" / ") +
const QString timeString = formatTime(milliseconds) + QStringLiteral(" / ") +
formatTime(m_itemTotalTime);
m_itemTimeLabel->setText(timeString);
......
......@@ -17,30 +17,33 @@
#ifndef JUK_STATUSLABEL_H
#define JUK_STATUSLABEL_H
#include "playlistinterface.h"
#include <QWidget>
class KSqueezedTextLabel;
class QEvent;
class QLabel;
class KSqueezedTextLabel;
class StatusLabel : public QWidget, public PlaylistObserver
class FileHandle;
class PlaylistInterface;
class StatusLabel : public QWidget
{
Q_OBJECT
public:
explicit StatusLabel(PlaylistInterface *playlist, QWidget *parent = nullptr);
virtual void playingItemHasChanged() Q_DECL_FINAL;
explicit StatusLabel(const PlaylistInterface &currentPlaylist, QWidget *parent = nullptr);
public slots:
void slotPlayingItemHasChanged(const FileHandle &file);
void slotCurrentPlaylistHasChanged(const PlaylistInterface &currentPlaylist);
/**
* This just sets internal variables that are used by setItemCurrentTime().
* This just sets internal variables that are used by updateTime().
* Please call that method to display the time.
*/
void setItemTotalTime(int time) { m_itemTotalTime = time; }
void setItemCurrentTime(int time) { m_itemCurrentTime = time; updateTime(); }
virtual void playlistItemDataHasChanged() Q_DECL_FINAL;
void setItemTotalTime(qint64 time_msec) { m_itemTotalTime = time_msec; }
void setItemCurrentTime(qint64 time_msec) { m_itemCurrentTime = time_msec; updateTime(); }
private:
void updateTime();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment