Commit a8a4ea02 authored by Scott Wheeler's avatar Scott Wheeler

Start to add a "PlaylistManager" class that will implement the Playlist

interface but also manage the top level KActions.

The goal is to move as much of this stuff out of the JuK and PlaylistSplitter
classes and instead have some small APIs that are used more specialized.

svn path=/trunk/kdemultimedia/juk/; revision=287893
parent d3e4e9cd
bin_PROGRAMS = juk
check_PROGRAMS = tagguessertest mbtest
juk_SOURCES = directorylistbase.ui \
gstreamerplayer.cpp artsplayer.cpp directorylist.cpp stringhash.cpp \
sortedstringlist.cpp systemtray.cpp splashscreen.cpp \
statuslabel.cpp collectionlist.cpp \
playlistitem.cpp playlist.cpp playlistsplitter.cpp \
playlistbox.cpp tageditor.cpp cache.cpp \
player.cpp tag.cpp customaction.cpp \
slideraction.cpp keydialog.cpp juk.cpp main.cpp tagguesser.cpp \
tagguesserconfigdlgwidget.ui tagguesserconfigdlg.cpp jukIface.skel \
playlistsearch.cpp searchwidget.cpp filerenamer.cpp dynamicplaylist.cpp \
searchplaylist.cpp musicbrainzquery.cpp mediafiles.cpp viewmode.cpp \
advancedsearchdialog.cpp historyplaylist.cpp trackpickerdialogbase.ui \
musicbrainzitem.cpp trackpickerdialog.cpp filerenamerconfigdlgwidget.ui \
filerenamerconfigdlg.cpp stringshare.cpp
juk_SOURCES = \
advancedsearchdialog.cpp \
artsplayer.cpp \
cache.cpp \
collectionlist.cpp \
customaction.cpp \
directorylist.cpp \
directorylistbase.ui \
dynamicplaylist.cpp \
filerenamer.cpp \
filerenamerconfigdlg.cpp \
filerenamerconfigdlgwidget.ui \
gstreamerplayer.cpp \
historyplaylist.cpp \
juk.cpp \
jukIface.skel \
keydialog.cpp \
main.cpp \
mediafiles.cpp \
musicbrainzitem.cpp \
musicbrainzquery.cpp \
player.cpp \
playermanager.cpp \
playlist.cpp \
playlistbox.cpp \
playlistitem.cpp \
playlistsearch.cpp \
playlistsplitter.cpp \
searchplaylist.cpp \
searchwidget.cpp \
slideraction.cpp \
sortedstringlist.cpp \
splashscreen.cpp \
statuslabel.cpp \
stringhash.cpp \
stringshare.cpp \
systemtray.cpp \
tag.cpp \
tageditor.cpp \
tagguesser.cpp \
tagguesserconfigdlg.cpp \
tagguesserconfigdlgwidget.ui \
trackpickerdialog.cpp \
trackpickerdialogbase.ui \
viewmode.cpp
tagguessertest_SOURCES = tagguessertest.cpp tagguesser.cpp
mbtest_SOURCES = mbtest.cpp musicbrainzquery.cpp
......
......@@ -106,9 +106,6 @@ void JuK::slotGuessTagInfoFromInternet()
void JuK::play()
{
if(!m_player)
return;
if(m_player->paused()) {
m_player->play();
m_statusLabel->setPlayingItemInfo(playingString(), m_splitter->playingList());
......
......@@ -22,11 +22,7 @@
#include "artsplayer.h"
#include "gstreamerplayer.h"
/*
* The goal here is to contain all of the #if'ed ugliness in this file.
*/
// The goal here is to contain all of the #if'ed ugliness in this file.
Player *Player::createPlayer(int system)
{
......@@ -34,15 +30,15 @@ Player *Player::createPlayer(int system)
#if HAVE_GSTREAMER
switch(system) {
case Arts:
p = new ArtsPlayer();
break;
p = new ArtsPlayer;
break;
case GStreamer:
p = new GStreamerPlayer();
break;
p = new GStreamerPlayer;
break;
}
#else
Q_UNUSED(system);
p = new ArtsPlayer();
p = new ArtsPlayer;
#endif
return p;
......@@ -61,3 +57,4 @@ KSelectAction *Player::playerSelectAction(QObject *parent)
#endif
return action;
}
......@@ -29,7 +29,6 @@ class KSelectAction;
class Player
{
public:
enum SoundSystem { Arts = 0, GStreamer = 1 };
virtual ~Player() {}
......
/***************************************************************************
playermanager.cpp
-------------------
begin : Sat Feb 14 2004
copyright : (C) 2004 by Scott Wheeler
email : wheeler@kde.org
***************************************************************************/
/***************************************************************************
* *
* This program 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 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include <kactioncollection.h>
#include <kmainwindow.h>
#include <kapplication.h>
#include <kdebug.h>
#include <qslider.h>
#include "playermanager.h"
#include "slideraction.h"
PlayerManager *PlayerManager::m_instance = 0;
////////////////////////////////////////////////////////////////////////////////
// protected members
////////////////////////////////////////////////////////////////////////////////
PlayerManager::PlayerManager() :
QObject(0, "PlayerManager"),
Player(),
m_actionCollection(0),
m_sliderAction(0),
m_player(0)
{
setup();
}
PlayerManager::~PlayerManager()
{
}
////////////////////////////////////////////////////////////////////////////////
// public members
////////////////////////////////////////////////////////////////////////////////
PlayerManager *PlayerManager::instance() // static
{
if(!m_instance)
m_instance = new PlayerManager;
return m_instance;
}
void PlayerManager::play(const QString &fileName)
{
if(!m_player)
return;
if(m_player->paused())
m_player->stop();
m_player->play(fileName);
// Make sure that the m_player actually starts before doing anything.
if(m_player->playing()) {
m_actionCollection->action("pause")->setEnabled(true);
m_actionCollection->action("stop")->setEnabled(true);
m_actionCollection->action("forward")->setEnabled(true);
m_actionCollection->action("back")->setEnabled(true);
m_sliderAction->trackPositionSlider()->setValue(0);
m_sliderAction->trackPositionSlider()->setEnabled(true);
// m_playTimer->start(m_pollInterval);
}
else
stop();
}
void PlayerManager::pause()
{
if(!m_player)
return;
m_player->pause();
}
void PlayerManager::stop()
{
if(!m_player)
return;
m_player->stop();
}
void PlayerManager::setVolume(float volume = 1.0)
{
if(!m_player)
return;
m_player->setVolume(volume);
}
float PlayerManager::volume() const
{
if(!m_player)
return 0;
return m_player->volume();
}
bool PlayerManager::playing() const
{
if(!m_player)
return false;
return m_player->playing();
}
bool PlayerManager::paused() const
{
if(!m_player)
return false;
return m_player->paused();
}
long PlayerManager::totalTime() const
{
if(!m_player)
return 0;
return m_player->totalTime();
}
long PlayerManager::currentTime() const
{
if(!m_player)
return 0;
return m_player->currentTime();
}
int PlayerManager::position() const
{
if(!m_player)
return 0;
return m_player->position();
}
void PlayerManager::seek(long seekTime)
{
if(!m_player)
return;
m_player->seek(seekTime);
}
void PlayerManager::seekPosition(int position)
{
if(!m_player)
return;
m_player->seekPosition(position);
}
////////////////////////////////////////////////////////////////////////////////
// private members
////////////////////////////////////////////////////////////////////////////////
void PlayerManager::setup()
{
// Since we're doing a little wizardry to keep the interaction and API
// requirements as light as possible we want to check everything we're
// going to need to make sure that everything's in order.
KMainWindow *mainWindow = dynamic_cast<KMainWindow *>(kapp->mainWidget());
if(!mainWindow) {
kdWarning(65432) << k_funcinfo << "Could not find main window." << endl;
return;
}
m_actionCollection = mainWindow->actionCollection();
if(!m_actionCollection) {
kdWarning(65432) << k_funcinfo << "Action collection is null." << endl;
return;
}
// All of the actions required by this class should be listed here.
if(!m_actionCollection->action("pause") ||
!m_actionCollection->action("stop") ||
!m_actionCollection->action("back") ||
!m_actionCollection->action("forward") ||
!m_actionCollection->action("trackPositionAction"))
{
kdWarning(65432) << k_funcinfo << "Could not find all of the required actions." << endl;
return;
}
m_actionCollection->action("pause")->setEnabled(false);
m_actionCollection->action("stop")->setEnabled(false);
m_actionCollection->action("back")->setEnabled(false);
m_actionCollection->action("forward")->setEnabled(false);
m_sliderAction = static_cast<SliderAction *>(m_actionCollection->action("trackPositionAction"));
}
#include "playermanager.moc"
/***************************************************************************
playermanager.h
-------------------
begin : Sat Feb 14 2004
copyright : (C) 2004 by Scott Wheeler
email : wheeler@kde.org
***************************************************************************/
/***************************************************************************
* *
* This program 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 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef PLAYERMANAGER_H
#define PLAYERMANAGER_H
#include <qobject.h>
#include "player.h"
class SliderAction;
/**
* This class serves as a proxy to the Player interface and handles managing
* the actions from the top-level mainwindow.
*/
class PlayerManager : public QObject, public Player
{
Q_OBJECT
protected:
PlayerManager();
virtual ~PlayerManager();
public:
static PlayerManager *instance();
public slots:
// Implementation of the Player interface
virtual void play(const QString &fileName = QString::null);
virtual void pause();
virtual void stop();
virtual void setVolume(float volume = 1.0);
virtual float volume() const;
virtual bool playing() const;
virtual bool paused() const;
virtual long totalTime() const;
virtual long currentTime() const;
virtual int position() const;
virtual void seek(long seekTime);
virtual void seekPosition(int position);
private:
void setup();
static PlayerManager *m_instance;
KActionCollection *m_actionCollection;
SliderAction *m_sliderAction;
Player *m_player;
};
#endif
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