Commit 31b5aac2 authored by Scott Wheeler's avatar Scott Wheeler

Ok, finally getting to something like a sane API for the JuK class and have

moved most of the playing related stuff into the PlayerManager class.  There
are a few things yet to go, but they'll come in the upcoming days.

svn path=/trunk/kdemultimedia/juk/; revision=292734
parent 3a1e1c86
This diff is collapsed.
......@@ -46,13 +46,6 @@ public:
public slots:
void back(int howMany = 0);
void slotPopulateBackMenu();
void forward();
void seekBack();
void seekForward();
void volumeUp();
void volumeDown();
void volumeMute();
signals:
void signalEdit();
......@@ -89,19 +82,6 @@ private:
QString playingString() const;
int currentTime() const { return m_player->currentTime(); }
int totalTime() const { return m_player->totalTime(); }
/**
* Set the volume. 100 is the maximum.
*/
void setVolume(float volume);
/**
* Set the position in the currently playing track (in seconds).
*/
void setTime(int time);
void updatePlaylistInfo();
/**
......@@ -154,31 +134,25 @@ private:
QValueList<SplitterConnection> m_splitterConnections;
// actions
SliderAction *m_sliderAction;
KToggleAction *m_showSearchAction;
KToggleAction *m_showEditorAction;
KToggleAction *m_showHistoryAction;
SliderAction *m_sliderAction;
KToggleAction *m_randomPlayAction;
KToggleAction *m_toggleSystemTrayAction;
KToggleAction *m_toggleDockOnCloseAction;
KToggleAction *m_togglePopupsAction;
KToggleAction *m_toggleSplashAction;
KToggleAction *m_loopPlaylistAction;
KSelectAction *m_outputSelectAction;
KActionMenu *m_guessMenu;
KToolBarPopupAction *m_backAction;
KToggleAction *m_loopPlaylistAction;
PlayerManager *m_player;
KGlobalAccel *m_accel;
bool m_noSeek;
bool m_startDocked;
bool m_showSplash;
bool m_shuttingDown;
bool m_muted;
static const int m_pollInterval = 800;
};
#endif
......@@ -51,7 +51,7 @@ public:
* This is a member function, provided to create a global accelerator with
* standard keys. It behaves like the function in KGlobalAccel.
*/
static void insert(KGlobalAccel *keys, const QString& action, const QString& label,
static void insert(KGlobalAccel *keys, const QString &action, const QString &label,
const QObject *objSlot, const char *methodSlot);
private:
......
......@@ -42,7 +42,8 @@ PlayerManager::PlayerManager() :
m_statusLabel(0),
m_player(0),
m_timer(0),
m_noSeek(false)
m_noSeek(false),
m_muted(false)
{
setup();
}
......@@ -133,8 +134,10 @@ void PlayerManager::play(const QString &fileName)
if(fileName.isNull()) {
if(player()->paused())
player()->play();
else if(player()->playing())
else if(player()->playing()) {
m_sliderAction->trackPositionSlider()->setValue(0);
player()->seekPosition(0);
}
else {
QString file = m_playlistInterface->currentFile();
if(!file.isNull())
......@@ -156,7 +159,6 @@ void PlayerManager::play(const QString &fileName)
action("forward")->setEnabled(true);
action("back")->setEnabled(true);
m_sliderAction->trackPositionSlider()->setValue(0);
m_sliderAction->trackPositionSlider()->setEnabled(true);
m_timer->start(m_pollInterval);
......@@ -224,6 +226,19 @@ void PlayerManager::seekPosition(int position)
slotUpdateTime(position);
player()->seekPosition(position);
m_sliderAction->trackPositionSlider()->setValue(position);
}
void PlayerManager::seekForward()
{
int position = m_sliderAction->trackPositionSlider()->value();
seekPosition(kMin(m_sliderAction->trackPositionSlider()->maxValue(), position + 10));
}
void PlayerManager::seekBack()
{
int position = m_sliderAction->trackPositionSlider()->value();
seekPosition(kMax(m_sliderAction->trackPositionSlider()->minValue(), position - 10));
}
void PlayerManager::playPause()
......@@ -249,6 +264,39 @@ void PlayerManager::back()
stop();
}
void PlayerManager::volumeUp()
{
if(!m_player || !m_sliderAction)
return;
int volume = m_sliderAction->volumeSlider()->value() +
m_sliderAction->volumeSlider()->maxValue() / 25; // 4% up
slotSetVolume(volume);
m_sliderAction->volumeSlider()->setValue(volume);
}
void PlayerManager::volumeDown()
{
if(!m_player || !m_sliderAction)
return;
int volume = m_sliderAction->volumeSlider()->value() -
m_sliderAction->volumeSlider()->maxValue() / 25; // 4% down
slotSetVolume(volume);
m_sliderAction->volumeSlider()->setValue(volume);
}
void PlayerManager::mute()
{
if(!m_player || !m_sliderAction)
return;
slotSetVolume(m_muted ? m_sliderAction->volumeSlider()->value() : 0);
m_muted = !m_muted;
}
////////////////////////////////////////////////////////////////////////////////
// private slots
////////////////////////////////////////////////////////////////////////////////
......@@ -373,7 +421,7 @@ void PlayerManager::setup()
float volume =
float(m_sliderAction->volumeSlider()->value()) /
float(m_sliderAction->volumeSlider()->maxValue());
float(m_sliderAction->volumeSlider()->maxValue());
m_player->setVolume(volume);
......
......@@ -53,6 +53,9 @@ public:
void setStatusLabel(StatusLabel *label);
public slots:
// implementations of the player interface
virtual void play(const QString &fileName = QString::null);
virtual void pause();
virtual void stop();
......@@ -60,12 +63,16 @@ public slots:
virtual void seek(long seekTime);
virtual void seekPosition(int position);
void playPause();
// additional slots
void seekForward();
void seekBack();
void playPause();
void forward();
void back();
void slotSetVolume(int volume); // TODO: make private
void volumeUp();
void volumeDown();
void mute();
private:
Player *player() const;
......@@ -75,6 +82,7 @@ private slots:
void slotPollPlay();
void slotUpdateTime(int position);
void slotSetOutput(int system);
void slotSetVolume(int volume); // TODO: make private
private:
static PlayerManager *m_instance;
......@@ -85,6 +93,7 @@ private:
Player *m_player;
QTimer *m_timer;
bool m_noSeek;
bool m_muted;
static const int m_pollInterval = 800;
};
......
......@@ -177,16 +177,12 @@ void SystemTray::wheelEvent(QWheelEvent *e)
// that a reinterpret_cast isn't portable when combined with multiple
// inheritance. (This is why I don't check the result.)
JuK *juk = dynamic_cast<JuK *>(parent());
switch(e->state()) {
case ShiftButton:
if(juk) {
if(e->delta() > 0)
juk->volumeUp();
else
juk->volumeDown();
}
if(e->delta() > 0)
action("volumeUp")->activate();
else
action("volumeDown")->activate();
break;
default:
if(e->delta() > 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