Commit 5093e9f3 authored by Scott Wheeler's avatar Scott Wheeler

Add a global action collection to avoid some of the nasty hacks of trying

to get the one from the main window.

svn path=/trunk/kdemultimedia/juk/; revision=292027
parent 3f3cd4ab
......@@ -3,6 +3,7 @@ check_PROGRAMS = tagguessertest mbtest
juk_SOURCES = \
advancedsearchdialog.cpp \
actioncollection.cpp \
artsplayer.cpp \
cache.cpp \
collectionlist.cpp \
......
/***************************************************************************
actioncollection.cpp
-------------------
begin : Fri Feb 27 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 "actioncollection.h"
namespace ActionCollection
{
KActionCollection *actions()
{
static KActionCollection *a =
new KActionCollection(static_cast<QWidget *>(0), "JuK Action Collection");
return a;
}
KAction *action(const char *key)
{
return actions()->action(key);
}
}
/***************************************************************************
actioncollection.h
-------------------
begin : Fri Feb 27 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 JUK_ACTIONCOLLECTION_H
#define JUK_ACTIONCOLLECTION_H
class KActionCollection;
class KAction;
namespace ActionCollection
{
/**
* The global action collection for JuK.
*/
KActionCollection *actions();
/**
* Returns the action for the associated key from the global action
* collection.
*/
KAction *action(const char *key);
/**
* Returns the action for the associated key but includes a cast to the
* type \a T. i.e. KSelectAction *a = action<KSelectAction>("chooser");
*/
template <class T> T *action(const char *key)
{
return dynamic_cast<T *>(action(key));
}
}
#endif
......@@ -34,6 +34,7 @@
#include "tagguesserconfigdlg.h"
#include "filerenamerconfigdlg.h"
#include "playermanager.h"
#include "actioncollection.h"
////////////////////////////////////////////////////////////////////////////////
// public members
......@@ -72,6 +73,11 @@ JuK::~JuK()
}
KActionCollection *JuK::actionCollection() const
{
return ActionCollection::actions();
}
////////////////////////////////////////////////////////////////////////////////
// public slots
////////////////////////////////////////////////////////////////////////////////
......@@ -87,6 +93,11 @@ void JuK::setVolume(float volume)
}
}
void JuK::setTime(int time)
{
m_player->seek(time);
}
void JuK::startPlayingPlaylist()
{
if(m_randomPlayAction->isChecked())
......@@ -724,6 +735,11 @@ void JuK::slotPlaylistChanged()
updatePlaylistInfo();
}
void JuK::slotQuit()
{
kapp->quit();
}
////////////////////////////////////////////////////////////////////////////////
// settings menu
////////////////////////////////////////////////////////////////////////////////
......
......@@ -45,6 +45,7 @@ class JuK : public KMainWindow, virtual public JuKIface
public:
JuK(QWidget* parent = 0, const char *name = 0);
virtual ~JuK();
virtual KActionCollection *actionCollection() const;
public slots:
void play();
......@@ -110,7 +111,7 @@ private:
/**
* Set the position in the currently playing track (in seconds).
*/
void setTime(int time) { m_player->seek(time); }
void setTime(int time);
void updatePlaylistInfo();
......@@ -141,7 +142,7 @@ private slots:
void slotPlaylistChanged();
// file menu
void slotQuit() { m_shuttingDown = true; kapp->quit(); }
void slotQuit();
// settings menu
void slotToggleSystemTray(bool enabled);
......
......@@ -15,9 +15,6 @@
* *
***************************************************************************/
#include <kactioncollection.h>
#include <kmainwindow.h>
#include <kapplication.h>
#include <kdebug.h>
#include <qslider.h>
......@@ -27,6 +24,9 @@
#include "playlistinterface.h"
#include "slideraction.h"
#include "statuslabel.h"
#include "actioncollection.h"
using namespace ActionCollection;
PlayerManager *PlayerManager::m_instance = 0;
......@@ -37,7 +37,6 @@ PlayerManager *PlayerManager::m_instance = 0;
PlayerManager::PlayerManager() :
QObject(0, "PlayerManager"),
Player(),
m_actionCollection(0),
m_sliderAction(0),
m_playlistInterface(0),
m_statusLabel(0),
......@@ -152,10 +151,10 @@ void PlayerManager::play(const QString &fileName)
return;
}
m_actionCollection->action("pause")->setEnabled(true);
m_actionCollection->action("stop")->setEnabled(true);
m_actionCollection->action("forward")->setEnabled(true);
m_actionCollection->action("back")->setEnabled(true);
action("pause")->setEnabled(true);
action("stop")->setEnabled(true);
action("forward")->setEnabled(true);
action("back")->setEnabled(true);
m_sliderAction->trackPositionSlider()->setValue(0);
m_sliderAction->trackPositionSlider()->setEnabled(true);
......@@ -174,7 +173,7 @@ void PlayerManager::pause()
}
m_timer->stop();
m_actionCollection->action("pause")->setEnabled(false);
action("pause")->setEnabled(false);
player()->pause();
}
......@@ -186,10 +185,10 @@ void PlayerManager::stop()
m_timer->stop();
m_actionCollection->action("pause")->setEnabled(false);
m_actionCollection->action("stop")->setEnabled(false);
m_actionCollection->action("back")->setEnabled(false);
m_actionCollection->action("forward")->setEnabled(false);
action("pause")->setEnabled(false);
action("stop")->setEnabled(false);
action("back")->setEnabled(false);
action("forward")->setEnabled(false);
m_sliderAction->trackPositionSlider()->setValue(0);
m_sliderAction->trackPositionSlider()->setEnabled(false);
......@@ -326,31 +325,13 @@ Player *PlayerManager::player() const
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"))
if(!action("pause") ||
!action("stop") ||
!action("back") ||
!action("forward") ||
!action("trackPositionAction"))
{
kdWarning(65432) << k_funcinfo << "Could not find all of the required actions." << endl;
......@@ -359,14 +340,14 @@ void PlayerManager::setup()
// initialize action states
m_actionCollection->action("pause")->setEnabled(false);
m_actionCollection->action("stop")->setEnabled(false);
m_actionCollection->action("back")->setEnabled(false);
m_actionCollection->action("forward")->setEnabled(false);
action("pause")->setEnabled(false);
action("stop")->setEnabled(false);
action("back")->setEnabled(false);
action("forward")->setEnabled(false);
// setup sliders
m_sliderAction = static_cast<SliderAction *>(m_actionCollection->action("trackPositionAction"));
m_sliderAction = action<SliderAction>("trackPositionAction");
connect(m_sliderAction, SIGNAL(signalPositionChanged(int)),
this, SLOT(seekPosition(int)));
......@@ -375,7 +356,7 @@ void PlayerManager::setup()
connect(m_sliderAction->volumeSlider(), SIGNAL(valueChanged(int)),
this, SLOT(slotSetVolume(int)));
KAction *outputAction = m_actionCollection->action("outputSelect");
KAction *outputAction = action("outputSelect");
if(outputAction) {
int mediaSystem = static_cast<KSelectAction *>(outputAction)->currentItem();
......
......@@ -79,7 +79,6 @@ private slots:
private:
static PlayerManager *m_instance;
KActionCollection *m_actionCollection;
SliderAction *m_sliderAction;
PlaylistInterface *m_playlistInterface;
StatusLabel *m_statusLabel;
......
......@@ -18,10 +18,11 @@
#ifndef SLIDERACTION_H
#define SLIDERACTION_H
#include "customaction.h"
class QSlider;
class QBoxLayout;
#include "customaction.h"
class QDockWindow;
class SliderAction : public CustomAction
{
......
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