Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 87ee0948 authored by Scott Wheeler's avatar Scott Wheeler

Moved a couple of the classes over to FileHandle rather than just passing

around string based file names.  Moved the static methods for creating
a Player instance from Player to PlayerManager.  Removed play() and back()
from the JuK class since they belong in PlayerManager.  For the moment
this means the "back history" doesn't work.

svn path=/trunk/kdemultimedia/juk/; revision=301959
parent 270a717d
...@@ -24,7 +24,6 @@ juk_SOURCES = \ ...@@ -24,7 +24,6 @@ juk_SOURCES = \
mediafiles.cpp \ mediafiles.cpp \
musicbrainzitem.cpp \ musicbrainzitem.cpp \
musicbrainzquery.cpp \ musicbrainzquery.cpp \
player.cpp \
playermanager.cpp \ playermanager.cpp \
playlist.cpp \ playlist.cpp \
playlistbox.cpp \ playlistbox.cpp \
......
...@@ -61,14 +61,14 @@ ArtsPlayer::~ArtsPlayer() ...@@ -61,14 +61,14 @@ ArtsPlayer::~ArtsPlayer()
delete m_dispatcher; delete m_dispatcher;
} }
void ArtsPlayer::play(const QString &fileName) void ArtsPlayer::play(const FileHandle &file)
{ {
// kdDebug(65432) << k_funcinfo << endl; // kdDebug(65432) << k_funcinfo << endl;
// Make sure that the server still exists, if it doesn't a new one should // Make sure that the server still exists, if it doesn't a new one should
// be started automatically and the factory and amanPlay are created again. // be started automatically and the factory and amanPlay are created again.
if(!fileName.isNull()) if(!file.isNull())
m_currentURL.setPath(fileName); m_currentURL.setPath(file.absFilePath());
if(m_server->server().isNull()) { if(m_server->server().isNull()) {
KMessageBox::error(0, i18n("Cannot find the aRts soundserver.")); KMessageBox::error(0, i18n("Cannot find the aRts soundserver."));
......
...@@ -47,7 +47,7 @@ public: ...@@ -47,7 +47,7 @@ public:
ArtsPlayer(); ArtsPlayer();
virtual ~ArtsPlayer(); virtual ~ArtsPlayer();
virtual void play(const QString &fileName = QString::null); virtual void play(const FileHandle &file = FileHandle::null());
virtual void pause(); virtual void pause();
virtual void stop(); virtual void stop();
......
...@@ -43,14 +43,14 @@ GStreamerPlayer::~GStreamerPlayer() ...@@ -43,14 +43,14 @@ GStreamerPlayer::~GStreamerPlayer()
delete m_player; delete m_player;
} }
void GStreamerPlayer::play(const QString &fileName) void GStreamerPlayer::play(const FileHandle &file)
{ {
m_currentFile = fileName; m_currentFile = file.absFilePath();
m_positionNs = 0; m_positionNs = 0;
m_durationNs = 0; m_durationNs = 0;
if(!fileName.isEmpty()) if(!file.isNull())
m_player->setLocation(fileName); m_player->setLocation(file.absFilePath());
if(m_player->getState() != Element::STATE_PLAYING) if(m_player->getState() != Element::STATE_PLAYING)
m_player->setState(Element::STATE_PLAYING); m_player->setState(Element::STATE_PLAYING);
......
...@@ -38,7 +38,7 @@ public: ...@@ -38,7 +38,7 @@ public:
GStreamerPlayer(); GStreamerPlayer();
virtual ~GStreamerPlayer(); virtual ~GStreamerPlayer();
virtual void play(const QString &fileName = QString::null); virtual void play(const FileHandle &file = FileHandle::null());
virtual void setVolume(float volume = 1.0); virtual void setVolume(float volume = 1.0);
virtual float volume() const; virtual float volume() const;
......
...@@ -94,20 +94,6 @@ void JuK::slotGuessTagInfoFromInternet() ...@@ -94,20 +94,6 @@ void JuK::slotGuessTagInfoFromInternet()
m_splitter->slotGuessTagInfo(TagGuesser::MusicBrainz); m_splitter->slotGuessTagInfo(TagGuesser::MusicBrainz);
} }
void JuK::back(int howMany)
{
for(--howMany; howMany > 0; --howMany)
m_splitter->playPreviousFile(m_randomPlayAction->isChecked());
play(m_splitter->playPreviousFile(m_randomPlayAction->isChecked()));
}
void JuK::slotPopulateBackMenu()
{
m_splitter->populatePlayHistoryMenu(m_backAction->popupMenu(),
m_randomPlayAction->isChecked());
}
void JuK::openFile(const QString &file) void JuK::openFile(const QString &file)
{ {
m_splitter->open(file); m_splitter->open(file);
...@@ -230,15 +216,14 @@ void JuK::setupActions() ...@@ -230,15 +216,14 @@ void JuK::setupActions()
new KAction(i18n("P&ause"), "player_pause", 0, m_player, SLOT(pause()), actions(), "pause"); new KAction(i18n("P&ause"), "player_pause", 0, m_player, SLOT(pause()), actions(), "pause");
new KAction(i18n("&Stop"), "player_stop", 0, m_player, SLOT(stop()), actions(), "stop"); new KAction(i18n("&Stop"), "player_stop", 0, m_player, SLOT(stop()), actions(), "stop");
m_backAction = new KToolBarPopupAction(i18n("Previous &Track"), "player_start", 0, // m_backAction = new KToolBarPopupAction(i18n("Previous &Track"), "player_start", 0,
this, SLOT(back()), actions(), "back"); // this, SLOT(back()), actions(), "back");
// TODO: switch this back to being a popup action
connect(m_backAction->popupMenu(), SIGNAL(aboutToShow()), new KAction(i18n("Previous& Track"), "player_start", 0, m_player, SLOT(back()), actions(), "back");
this, SLOT(slotPopulateBackMenu())); new KAction(i18n("&Next Track"), "player_end", 0, m_player, SLOT(forward()), actions(), "forward");
connect(m_backAction->popupMenu(), SIGNAL(activated(int)),
this, SLOT(back(int)));
new KAction(i18n("&Next Track"), "player_end", 0, m_player, SLOT(forward()), actions(), "forward");
new KToggleAction(i18n("&Loop Playlist"), 0, 0, actions(), "loopPlaylist"); new KToggleAction(i18n("&Loop Playlist"), 0, 0, actions(), "loopPlaylist");
// the following are not visible by default // the following are not visible by default
...@@ -295,7 +280,7 @@ void JuK::setupActions() ...@@ -295,7 +280,7 @@ void JuK::setupActions()
this, SLOT(slotToggleSystemTray(bool))); this, SLOT(slotToggleSystemTray(bool)));
m_outputSelectAction = Player::playerSelectAction(actions()); m_outputSelectAction = PlayerManager::playerSelectAction(actions());
if(m_outputSelectAction) if(m_outputSelectAction)
m_outputSelectAction->setCurrentItem(0); m_outputSelectAction->setCurrentItem(0);
...@@ -550,12 +535,6 @@ void JuK::updatePlaylistInfo() ...@@ -550,12 +535,6 @@ void JuK::updatePlaylistInfo()
m_splitter->selectedPlaylistTotalTime()); m_splitter->selectedPlaylistTotalTime());
} }
void JuK::play(const QString &file)
{
m_player->play(file);
emit signalNewSong(playingString());
}
KAction *JuK::createSplitterAction(const QString &text, const char *slot, KAction *JuK::createSplitterAction(const QString &text, const char *slot,
const char *name, const QString &pix, const char *name, const QString &pix,
const KShortcut &shortcut) const KShortcut &shortcut)
......
...@@ -43,10 +43,6 @@ public: ...@@ -43,10 +43,6 @@ public:
virtual ~JuK(); virtual ~JuK();
virtual KActionCollection *actionCollection() const; virtual KActionCollection *actionCollection() const;
public slots:
void back(int howMany = 0);
void slotPopulateBackMenu();
signals: signals:
void signalEdit(); void signalEdit();
void signalNewSong(const QString& songTitle); void signalNewSong(const QString& songTitle);
...@@ -84,12 +80,6 @@ private: ...@@ -84,12 +80,6 @@ private:
void updatePlaylistInfo(); void updatePlaylistInfo();
/**
* This is the main method to play stuff. Everything else is just a wrapper
* around this.
*/
void play(const QString &file);
void openFile(const QString &file); void openFile(const QString &file);
void openFile(const QStringList &files); void openFile(const QStringList &files);
......
/***************************************************************************
player.cpp - description
-------------------
begin : Sun Feb 17 2002
copyright : (C) 2002, 2003 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 <kaction.h>
#include <klocale.h>
#include "player.h"
#include "artsplayer.h"
#include "gstreamerplayer.h"
// The goal here is to contain all of the #if'ed ugliness in this file.
Player *Player::createPlayer(int system)
{
Player *p = 0;
#if HAVE_GSTREAMER
switch(system) {
case Arts:
p = new ArtsPlayer;
break;
case GStreamer:
p = new GStreamerPlayer;
break;
}
#else
Q_UNUSED(system);
#ifdef USE_ARTS
p = new ArtsPlayer;
#endif
#endif
return p;
}
KSelectAction *Player::playerSelectAction(QObject *parent)
{
KSelectAction *action = 0;
#if HAVE_GSTREAMER
action = new KSelectAction(i18n("&Output To"), 0, parent, "outputSelect");
QStringList l;
l << "aRts" << "GStreamer";
action->setItems(l);
#else
Q_UNUSED(parent);
#endif
return action;
}
...@@ -24,17 +24,17 @@ ...@@ -24,17 +24,17 @@
#include <qstring.h> #include <qstring.h>
#include "filehandle.h"
class QObject; class QObject;
class KSelectAction; class KSelectAction;
class Player class Player
{ {
public: public:
enum SoundSystem { Arts = 0, GStreamer = 1 };
virtual ~Player() {} virtual ~Player() {}
virtual void play(const QString &fileName = QString::null) = 0; virtual void play(const FileHandle &file = FileHandle::null()) = 0;
virtual void pause() = 0; virtual void pause() = 0;
virtual void stop() = 0; virtual void stop() = 0;
...@@ -51,13 +51,6 @@ public: ...@@ -51,13 +51,6 @@ public:
virtual void seek(long seekTime) = 0; virtual void seek(long seekTime) = 0;
virtual void seekPosition(int position) = 0; virtual void seekPosition(int position) = 0;
/**
* Returns a pointer to a Player object.
* Ownership of the returned player is transferred to the caller.
*/
static Player *createPlayer(int system = Arts);
static KSelectAction *playerSelectAction(QObject *parent);
protected: protected:
Player() {} Player() {}
......
...@@ -16,20 +16,54 @@ ...@@ -16,20 +16,54 @@
***************************************************************************/ ***************************************************************************/
#include <kdebug.h> #include <kdebug.h>
#include <klocale.h>
#include <qslider.h> #include <qslider.h>
#include <qtimer.h> #include <qtimer.h>
#include "artsplayer.h"
#include "gstreamerplayer.h"
#include "playermanager.h" #include "playermanager.h"
#include "playlistinterface.h" #include "playlistinterface.h"
#include "slideraction.h" #include "slideraction.h"
#include "statuslabel.h" #include "statuslabel.h"
#include "actioncollection.h" #include "actioncollection.h"
#include "config.h"
using namespace ActionCollection; using namespace ActionCollection;
PlayerManager *PlayerManager::m_instance = 0; PlayerManager *PlayerManager::m_instance = 0;
////////////////////////////////////////////////////////////////////////////////
// helper functions
////////////////////////////////////////////////////////////////////////////////
enum SoundSystem { ArtsBackend = 0, GStreamerBackend = 1 };
static Player *createPlayer(int system = ArtsBackend)
{
Player *p = 0;
#if HAVE_GSTREAMER
switch(system) {
case ArtsBackend:
p = new ArtsPlayer;
break;
case GStreamerBackend:
p = new GStreamerPlayer;
break;
}
#else
Q_UNUSED(system);
#ifdef USE_ARTS
p = new ArtsPlayer;
#endif
#endif
return p;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// protected members // protected members
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
...@@ -121,30 +155,48 @@ void PlayerManager::setStatusLabel(StatusLabel *label) ...@@ -121,30 +155,48 @@ void PlayerManager::setStatusLabel(StatusLabel *label)
m_statusLabel = label; m_statusLabel = label;
} }
KSelectAction *PlayerManager::playerSelectAction(QObject *parent) // static
{
KSelectAction *action = 0;
#if HAVE_GSTREAMER
action = new KSelectAction(i18n("&Output To"), 0, parent, "outputSelect");
QStringList l;
l << "aRts" << "GStreamer";
action->setItems(l);
#else
Q_UNUSED(parent);
#endif
return action;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// public slots // public slots
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void PlayerManager::play(const QString &fileName) void PlayerManager::play(const FileHandle &file)
{ {
if(!player() || !m_playlistInterface) if(!player() || !m_playlistInterface)
return; return;
if(fileName.isNull()) { if(file.isNull()) {
if(player()->paused()) if(player()->paused())
player()->play(); player()->play();
else if(player()->playing()) { else if(player()->playing()) {
m_sliderAction->trackPositionSlider()->setValue(0); m_sliderAction->trackPositionSlider()->setValue(0);
player()->seekPosition(0); player()->seekPosition(0);
} }
else { else {
QString file = m_playlistInterface->currentFile(); // TODO: currentFile() really should return a FileHanlde as such
if(!file.isNull()) // making the cast below not needed.
player()->play(file);
} FileHandle currentFile = FileHandle(m_playlistInterface->currentFile());
if(!currentFile.isNull())
player()->play(currentFile);
}
} }
else else
player()->play(fileName); player()->play(file);
// Make sure that the player() actually starts before doing anything. // Make sure that the player() actually starts before doing anything.
...@@ -247,7 +299,10 @@ void PlayerManager::playPause() ...@@ -247,7 +299,10 @@ void PlayerManager::playPause()
void PlayerManager::forward() void PlayerManager::forward()
{ {
QString file = m_playlistInterface->nextFile(); // TODO: nextFile() should return a FileHandle
FileHandle file = FileHandle(m_playlistInterface->nextFile());
if(!file.isNull()) if(!file.isNull())
play(file); play(file);
else else
...@@ -256,7 +311,10 @@ void PlayerManager::forward() ...@@ -256,7 +311,10 @@ void PlayerManager::forward()
void PlayerManager::back() void PlayerManager::back()
{ {
QString file = m_playlistInterface->previousFile(); // TODO: previousFile() should return a FileHandle
FileHandle file = FileHandle(m_playlistInterface->previousFile());
if(!file.isNull()) if(!file.isNull())
play(file); play(file);
else else
...@@ -266,10 +324,10 @@ void PlayerManager::back() ...@@ -266,10 +324,10 @@ void PlayerManager::back()
void PlayerManager::volumeUp() void PlayerManager::volumeUp()
{ {
if(!player() || !m_sliderAction) if(!player() || !m_sliderAction)
return; return;
int volume = m_sliderAction->volumeSlider()->volume() + int volume = m_sliderAction->volumeSlider()->volume() +
m_sliderAction->volumeSlider()->maxValue() / 25; // 4% up m_sliderAction->volumeSlider()->maxValue() / 25; // 4% up
slotSetVolume(volume); slotSetVolume(volume);
m_sliderAction->volumeSlider()->setVolume(volume); m_sliderAction->volumeSlider()->setVolume(volume);
...@@ -278,10 +336,10 @@ void PlayerManager::volumeUp() ...@@ -278,10 +336,10 @@ void PlayerManager::volumeUp()
void PlayerManager::volumeDown() void PlayerManager::volumeDown()
{ {
if(!player() || !m_sliderAction) if(!player() || !m_sliderAction)
return; return;
int volume = m_sliderAction->volumeSlider()->value() - int volume = m_sliderAction->volumeSlider()->value() -
m_sliderAction->volumeSlider()->maxValue() / 25; // 4% down m_sliderAction->volumeSlider()->maxValue() / 25; // 4% down
slotSetVolume(volume); slotSetVolume(volume);
m_sliderAction->volumeSlider()->setVolume(volume); m_sliderAction->volumeSlider()->setVolume(volume);
...@@ -309,7 +367,10 @@ void PlayerManager::slotPollPlay() ...@@ -309,7 +367,10 @@ void PlayerManager::slotPollPlay()
if(!player()->playing()) { if(!player()->playing()) {
m_timer->stop(); m_timer->stop();
QString nextFile = m_playlistInterface->nextFile();
// TODO: nextFile() should use FileHandle
FileHandle nextFile = FileHandle(m_playlistInterface->nextFile());
if(!nextFile.isNull()) if(!nextFile.isNull())
play(nextFile); play(nextFile);
else else
...@@ -343,7 +404,7 @@ void PlayerManager::slotSetOutput(int system) ...@@ -343,7 +404,7 @@ void PlayerManager::slotSetOutput(int system)
{ {
stop(); stop();
delete m_player; delete m_player;
m_player = Player::createPlayer(system); m_player = createPlayer(system);
} }
void PlayerManager::slotSetVolume(int volume) void PlayerManager::slotSetVolume(int volume)
...@@ -412,11 +473,11 @@ void PlayerManager::setup() ...@@ -412,11 +473,11 @@ void PlayerManager::setup()
if(outputAction) { if(outputAction) {
int mediaSystem = static_cast<KSelectAction *>(outputAction)->currentItem(); int mediaSystem = static_cast<KSelectAction *>(outputAction)->currentItem();
m_player = Player::createPlayer(mediaSystem); m_player = createPlayer(mediaSystem);
connect(outputAction, SIGNAL(activated(int)), this, SLOT(slotSetOutput(int))); connect(outputAction, SIGNAL(activated(int)), this, SLOT(slotSetOutput(int)));
} }
else else
m_player = Player::createPlayer(); m_player = createPlayer();
float volume = float volume =
float(m_sliderAction->volumeSlider()->volume()) / float(m_sliderAction->volumeSlider()->volume()) /
......
...@@ -18,13 +18,14 @@ ...@@ -18,13 +18,14 @@
#ifndef PLAYERMANAGER_H #ifndef PLAYERMANAGER_H
#define PLAYERMANAGER_H #define PLAYERMANAGER_H
#include "filehandle.h"
#include "player.h"
class QTimer; class QTimer;
class KSelectAction;
class SliderAction; class SliderAction;
class StatusLabel; class StatusLabel;
class PlaylistInterface; class PlaylistInterface;
class Player;
/** /**
* This class serves as a proxy to the Player interface and handles managing * This class serves as a proxy to the Player interface and handles managing
...@@ -52,9 +53,11 @@ public: ...@@ -52,9 +53,11 @@ public:
void setPlaylistInterface(PlaylistInterface *interface); void setPlaylistInterface(PlaylistInterface *interface);
void setStatusLabel(StatusLabel *label); void setStatusLabel(StatusLabel *label);
static KSelectAction *playerSelectAction(QObject *parent);
public slots: public slots:
void play(const QString &fileName = QString::null); void play(const FileHandle &file = FileHandle::null());
void pause(); void pause();
void stop(); void stop();
void setVolume(float volume = 1.0); void setVolume(float volume = 1.0);
......
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