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 = \
mediafiles.cpp \
musicbrainzitem.cpp \
musicbrainzquery.cpp \
player.cpp \
playermanager.cpp \
playlist.cpp \
playlistbox.cpp \
......
......@@ -61,14 +61,14 @@ ArtsPlayer::~ArtsPlayer()
delete m_dispatcher;
}
void ArtsPlayer::play(const QString &fileName)
void ArtsPlayer::play(const FileHandle &file)
{
// kdDebug(65432) << k_funcinfo << endl;
// 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.
if(!fileName.isNull())
m_currentURL.setPath(fileName);
if(!file.isNull())
m_currentURL.setPath(file.absFilePath());
if(m_server->server().isNull()) {
KMessageBox::error(0, i18n("Cannot find the aRts soundserver."));
......
......@@ -47,7 +47,7 @@ public:
ArtsPlayer();
virtual ~ArtsPlayer();
virtual void play(const QString &fileName = QString::null);
virtual void play(const FileHandle &file = FileHandle::null());
virtual void pause();
virtual void stop();
......
......@@ -43,14 +43,14 @@ GStreamerPlayer::~GStreamerPlayer()
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_durationNs = 0;
if(!fileName.isEmpty())
m_player->setLocation(fileName);
if(!file.isNull())
m_player->setLocation(file.absFilePath());
if(m_player->getState() != Element::STATE_PLAYING)
m_player->setState(Element::STATE_PLAYING);
......
......@@ -38,7 +38,7 @@ public:
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 float volume() const;
......
......@@ -94,20 +94,6 @@ void JuK::slotGuessTagInfoFromInternet()
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)
{
m_splitter->open(file);
......@@ -230,15 +216,14 @@ void JuK::setupActions()
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");
m_backAction = new KToolBarPopupAction(i18n("Previous &Track"), "player_start", 0,
this, SLOT(back()), actions(), "back");
// m_backAction = new KToolBarPopupAction(i18n("Previous &Track"), "player_start", 0,
// this, SLOT(back()), actions(), "back");
// TODO: switch this back to being a popup action
connect(m_backAction->popupMenu(), SIGNAL(aboutToShow()),
this, SLOT(slotPopulateBackMenu()));
connect(m_backAction->popupMenu(), SIGNAL(activated(int)),
this, SLOT(back(int)));
new KAction(i18n("Previous& Track"), "player_start", 0, m_player, SLOT(back()), actions(), "back");
new KAction(i18n("&Next Track"), "player_end", 0, m_player, SLOT(forward()), actions(), "forward");
new KAction(i18n("&Next Track"), "player_end", 0, m_player, SLOT(forward()), actions(), "forward");
new KToggleAction(i18n("&Loop Playlist"), 0, 0, actions(), "loopPlaylist");
// the following are not visible by default
......@@ -295,7 +280,7 @@ void JuK::setupActions()
this, SLOT(slotToggleSystemTray(bool)));
m_outputSelectAction = Player::playerSelectAction(actions());
m_outputSelectAction = PlayerManager::playerSelectAction(actions());
if(m_outputSelectAction)
m_outputSelectAction->setCurrentItem(0);
......@@ -550,12 +535,6 @@ void JuK::updatePlaylistInfo()
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,
const char *name, const QString &pix,
const KShortcut &shortcut)
......
......@@ -43,10 +43,6 @@ public:
virtual ~JuK();
virtual KActionCollection *actionCollection() const;
public slots:
void back(int howMany = 0);
void slotPopulateBackMenu();
signals:
void signalEdit();
void signalNewSong(const QString& songTitle);
......@@ -84,12 +80,6 @@ private:
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 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 @@
#include <qstring.h>
#include "filehandle.h"
class QObject;
class KSelectAction;
class Player
{
public:
enum SoundSystem { Arts = 0, GStreamer = 1 };
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 stop() = 0;
......@@ -51,13 +51,6 @@ public:
virtual void seek(long seekTime) = 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:
Player() {}
......
......@@ -16,20 +16,54 @@
***************************************************************************/
#include <kdebug.h>
#include <klocale.h>
#include <qslider.h>
#include <qtimer.h>
#include "artsplayer.h"
#include "gstreamerplayer.h"
#include "playermanager.h"
#include "playlistinterface.h"
#include "slideraction.h"
#include "statuslabel.h"
#include "actioncollection.h"
#include "config.h"
using namespace ActionCollection;
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
////////////////////////////////////////////////////////////////////////////////
......@@ -121,30 +155,48 @@ void PlayerManager::setStatusLabel(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
////////////////////////////////////////////////////////////////////////////////
void PlayerManager::play(const QString &fileName)
void PlayerManager::play(const FileHandle &file)
{
if(!player() || !m_playlistInterface)
return;
if(fileName.isNull()) {
if(player()->paused())
if(file.isNull()) {
if(player()->paused())
player()->play();
else if(player()->playing()) {
m_sliderAction->trackPositionSlider()->setValue(0);
m_sliderAction->trackPositionSlider()->setValue(0);
player()->seekPosition(0);
}
}
else {
QString file = m_playlistInterface->currentFile();
if(!file.isNull())
player()->play(file);
}
// TODO: currentFile() really should return a FileHanlde as such
// making the cast below not needed.
FileHandle currentFile = FileHandle(m_playlistInterface->currentFile());
if(!currentFile.isNull())
player()->play(currentFile);
}
}
else
player()->play(fileName);
player()->play(file);
// Make sure that the player() actually starts before doing anything.
......@@ -247,7 +299,10 @@ void PlayerManager::playPause()
void PlayerManager::forward()
{
QString file = m_playlistInterface->nextFile();
// TODO: nextFile() should return a FileHandle
FileHandle file = FileHandle(m_playlistInterface->nextFile());
if(!file.isNull())
play(file);
else
......@@ -256,7 +311,10 @@ void PlayerManager::forward()
void PlayerManager::back()
{
QString file = m_playlistInterface->previousFile();
// TODO: previousFile() should return a FileHandle
FileHandle file = FileHandle(m_playlistInterface->previousFile());
if(!file.isNull())
play(file);
else
......@@ -266,10 +324,10 @@ void PlayerManager::back()
void PlayerManager::volumeUp()
{
if(!player() || !m_sliderAction)
return;
return;
int volume = m_sliderAction->volumeSlider()->volume() +
m_sliderAction->volumeSlider()->maxValue() / 25; // 4% up
m_sliderAction->volumeSlider()->maxValue() / 25; // 4% up
slotSetVolume(volume);
m_sliderAction->volumeSlider()->setVolume(volume);
......@@ -278,10 +336,10 @@ void PlayerManager::volumeUp()
void PlayerManager::volumeDown()
{
if(!player() || !m_sliderAction)
return;
return;
int volume = m_sliderAction->volumeSlider()->value() -
m_sliderAction->volumeSlider()->maxValue() / 25; // 4% down
m_sliderAction->volumeSlider()->maxValue() / 25; // 4% down
slotSetVolume(volume);
m_sliderAction->volumeSlider()->setVolume(volume);
......@@ -309,7 +367,10 @@ void PlayerManager::slotPollPlay()
if(!player()->playing()) {
m_timer->stop();
QString nextFile = m_playlistInterface->nextFile();
// TODO: nextFile() should use FileHandle
FileHandle nextFile = FileHandle(m_playlistInterface->nextFile());
if(!nextFile.isNull())
play(nextFile);
else
......@@ -343,7 +404,7 @@ void PlayerManager::slotSetOutput(int system)
{
stop();
delete m_player;
m_player = Player::createPlayer(system);
m_player = createPlayer(system);
}
void PlayerManager::slotSetVolume(int volume)
......@@ -412,11 +473,11 @@ void PlayerManager::setup()
if(outputAction) {
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)));
}
else
m_player = Player::createPlayer();
m_player = createPlayer();
float volume =
float(m_sliderAction->volumeSlider()->volume()) /
......
......@@ -18,13 +18,14 @@
#ifndef PLAYERMANAGER_H
#define PLAYERMANAGER_H
#include "player.h"
#include "filehandle.h"
class QTimer;
class KSelectAction;
class SliderAction;
class StatusLabel;
class PlaylistInterface;
class Player;
/**
* This class serves as a proxy to the Player interface and handles managing
......@@ -52,9 +53,11 @@ public:
void setPlaylistInterface(PlaylistInterface *interface);
void setStatusLabel(StatusLabel *label);
static KSelectAction *playerSelectAction(QObject *parent);
public slots:
void play(const QString &fileName = QString::null);
void play(const FileHandle &file = FileHandle::null());
void pause();
void stop();
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