Commit 7d77cc46 authored by Scott Wheeler's avatar Scott Wheeler

Ah, this feels good. I was using the "find the mainwindow" hack several

places -- now they're moved over to the global action collection.

svn path=/trunk/kdemultimedia/juk/; revision=292038
parent 5093e9f3
......@@ -36,6 +36,8 @@
#include "playermanager.h"
#include "actioncollection.h"
using namespace ActionCollection;
////////////////////////////////////////////////////////////////////////////////
// public members
////////////////////////////////////////////////////////////////////////////////
......@@ -710,27 +712,27 @@ void JuK::slotPlaylistChanged()
!m_splitter->hasListSelected() ||
m_splitter->readOnlyListSelected())
{
actionCollection()->action("file_save")->setEnabled(false);
actionCollection()->action("file_save_as")->setEnabled(false);
actionCollection()->action("renamePlaylist")->setEnabled(false);
actionCollection()->action("reloadPlaylist")->setEnabled(false);
actionCollection()->action("deleteItemPlaylist")->setEnabled(false);
action("file_save")->setEnabled(false);
action("file_save_as")->setEnabled(false);
action("renamePlaylist")->setEnabled(false);
action("reloadPlaylist")->setEnabled(false);
action("deleteItemPlaylist")->setEnabled(false);
}
else {
actionCollection()->action("file_save")->setEnabled(true);
actionCollection()->action("file_save_as")->setEnabled(true);
actionCollection()->action("renamePlaylist")->setEnabled(true);
actionCollection()->action("deleteItemPlaylist")->setEnabled(true);
action("file_save")->setEnabled(true);
action("file_save_as")->setEnabled(true);
action("renamePlaylist")->setEnabled(true);
action("deleteItemPlaylist")->setEnabled(true);
if(m_splitter->fileBasedListSelected() || m_splitter->dynamicListSelected())
actionCollection()->action("reloadPlaylist")->setEnabled(true);
action("reloadPlaylist")->setEnabled(true);
else
actionCollection()->action("reloadPlaylist")->setEnabled(false);
action("reloadPlaylist")->setEnabled(false);
}
if(m_splitter->hasListSelected())
actionCollection()->action("duplicatePlaylist")->setEnabled(true);
action("duplicatePlaylist")->setEnabled(true);
else
actionCollection()->action("duplicatePlaylist")->setEnabled(false);
action("duplicatePlaylist")->setEnabled(false);
updatePlaylistInfo();
}
......
......@@ -21,7 +21,6 @@
#include <kiconloader.h>
#include <klineedit.h>
#include <kaction.h>
#include <kmainwindow.h>
#include <kpopupmenu.h>
#include <klocale.h>
#include <kdebug.h>
......@@ -44,6 +43,7 @@
#include "mediafiles.h"
#include "collectionlist.h"
#include "filerenamer.h"
#include "actioncollection.h"
////////////////////////////////////////////////////////////////////////////////
// Playlist::SharedSettings definition
......@@ -1238,9 +1238,6 @@ void Playlist::slotShowRMBMenu(QListViewItem *item, const QPoint &point, int col
// A bit of a hack to get a pointer to the action collection.
// Probably more of these actions should be ported over to using KActions.
KActionCollection *actionCollection =
static_cast<KMainWindow *>(kapp->mainWidget())->actionCollection();
m_rmbMenu = new KPopupMenu(this);
m_rmbMenu->insertItem(SmallIconSet("player_play"), i18n("Play Next"), this, SLOT(slotSetNext()));
......@@ -1266,9 +1263,10 @@ void Playlist::slotShowRMBMenu(QListViewItem *item, const QPoint &point, int col
}
m_rmbMenu->insertSeparator();
actionCollection->action("guessTag")->plug(m_rmbMenu);
ActionCollection::action("guessTag")->plug(m_rmbMenu);
if(!readOnly())
actionCollection->action("renameFile")->plug(m_rmbMenu);
ActionCollection::action("renameFile")->plug(m_rmbMenu);
m_rmbMenu->insertSeparator();
m_rmbMenu->insertItem(SmallIcon("new"), i18n("Create Playlist From Selected Items"), this, SLOT(slotCreateGroup()));
......
......@@ -21,7 +21,6 @@
#include <kinputdialog.h>
#include <kpopupmenu.h>
#include <kaction.h>
#include <kmainwindow.h>
#include <kdebug.h>
#include <qheader.h>
......@@ -33,6 +32,9 @@
#include "playlistsplitter.h"
#include "viewmode.h"
#include "searchplaylist.h"
#include "actioncollection.h"
using namespace ActionCollection;
////////////////////////////////////////////////////////////////////////////////
// PlaylistBox public methods
......@@ -58,29 +60,17 @@ PlaylistBox::PlaylistBox(PlaylistSplitter *parent, const QString &name) :
m_contextMenu = new KPopupMenu(this);
// Find the main window and then get the associated KActionCollection.
QObject *w = parent;
while(w && !dynamic_cast<KMainWindow *>(w))
w = w->parent();
if(!w)
return;
KActionCollection *actions = static_cast<KMainWindow *>(w)->actionCollection();
actions->action("file_new")->plug(m_contextMenu);
actions->action("renamePlaylist")->plug(m_contextMenu);
actions->action("duplicatePlaylist")->plug(m_contextMenu);
actions->action("reloadPlaylist")->plug(m_contextMenu);
actions->action("deleteItemPlaylist")->plug(m_contextMenu);
actions->action("file_save")->plug(m_contextMenu);
actions->action("file_save_as")->plug(m_contextMenu);
action("file_new")->plug(m_contextMenu);
action("renamePlaylist")->plug(m_contextMenu);
action("duplicatePlaylist")->plug(m_contextMenu);
action("reloadPlaylist")->plug(m_contextMenu);
action("deleteItemPlaylist")->plug(m_contextMenu);
action("file_save")->plug(m_contextMenu);
action("file_save_as")->plug(m_contextMenu);
// add the view modes stuff
m_viewModeAction = new KSelectAction(actions, "viewModeMenu");
m_viewModeAction = new KSelectAction(actions(), "viewModeMenu");
m_viewModeAction->setText(i18n("View Modes"));
m_viewModes.append(new ViewMode(this));
......
......@@ -19,8 +19,7 @@
#include <kmessagebox.h>
#include <kinputdialog.h>
#include <kcmdlineargs.h>
#include <kmainwindow.h>
#include <kactioncollection.h>
#include <kaction.h>
#include <kdebug.h>
#include <qpopupmenu.h>
......@@ -35,6 +34,9 @@
#include "historyplaylist.h"
#include "mediafiles.h"
#include "advancedsearchdialog.h"
#include "actioncollection.h"
using namespace ActionCollection;
////////////////////////////////////////////////////////////////////////////////
// helper functions
......@@ -173,11 +175,8 @@ QString PlaylistSplitter::nextFile()
}
else if(m_playingItem) {
KMainWindow *w = dynamic_cast<KMainWindow *>(kapp->mainWidget());
KAction *randomAction = w ? w->actionCollection()->action("randomPlay") : 0;
KAction *loopAction = w ? w->actionCollection()->action("loopPlaylist") : 0;
bool random = w && randomAction && static_cast<KToggleAction *>(randomAction)->isChecked();
bool loop = w && loopAction && static_cast<KToggleAction *>(loopAction)->isChecked();
bool random = action("randomPlay") && action<KToggleAction>("randomePlay")->isChecked();
bool loop = action("loopPlaylist") && action<KToggleAction>("loopPlaylist")->isChecked();
i = m_playingItem->playlist()->nextItem(m_playingItem, random);
......
......@@ -18,7 +18,6 @@
#include <kpopupmenu.h>
#include <kpassivepopup.h>
#include <kaction.h>
#include <kmainwindow.h>
#include <kiconeffect.h>
#include <kdebug.h>
......@@ -29,15 +28,18 @@
#include "systemtray.h"
#include "playermanager.h"
#include "actioncollection.h"
#include "jukIface.h"
using namespace ActionCollection;
static bool copyImage(QImage &dest, QImage &src, int x, int y);
////////////////////////////////////////////////////////////////////////////////
// public methods
////////////////////////////////////////////////////////////////////////////////
SystemTray::SystemTray(KMainWindow *parent, const char *name) : KSystemTray(parent, name),
SystemTray::SystemTray(QWidget *parent, const char *name) : KSystemTray(parent, name),
m_popup(0)
{
......@@ -55,29 +57,19 @@ SystemTray::SystemTray(KMainWindow *parent, const char *name) : KSystemTray(pare
KPopupMenu *cm = contextMenu();
m_actionCollection = parent->actionCollection();
m_playAction = m_actionCollection->action("play");
m_pauseAction = m_actionCollection->action("pause");
m_stopAction = m_actionCollection->action("stop");
m_backAction = m_actionCollection->action("back");
m_forwardAction = m_actionCollection->action("forward");
connect(m_playAction, SIGNAL(activated()), this, SLOT(slotPlay()));
connect(m_pauseAction, SIGNAL(activated()), this, SLOT(slotPause()));
connect(m_stopAction, SIGNAL(activated()), this, SLOT(slotStop()));
m_togglePopupsAction = static_cast<KToggleAction *>(m_actionCollection->action("togglePopups"));
connect(action("play"), SIGNAL(activated()), this, SLOT(slotPlay()));
connect(action("pause"), SIGNAL(activated()), this, SLOT(slotPause()));
connect(action("stop"), SIGNAL(activated()), this, SLOT(slotStop()));
m_playAction->plug(cm);
m_pauseAction->plug(cm);
m_stopAction->plug(cm);
m_backAction->plug(cm);
m_forwardAction->plug(cm);
action("play")->plug(cm);
action("pause")->plug(cm);
action("stop")->plug(cm);
action("back")->plug(cm);
action("forward")->plug(cm);
cm->insertSeparator();
m_togglePopupsAction->plug(cm);
action("togglePopups")->plug(cm);
if(PlayerManager::instance()->playing())
slotPlay();
......@@ -116,7 +108,7 @@ void SystemTray::slotStop()
void SystemTray::createPopup(const QString &songName, bool addButtons)
{
// If the action exists and it's checked, do our stuff
if(m_togglePopupsAction && m_togglePopupsAction->isChecked()) {
if(action<KToggleAction>("togglePopups")->isChecked()) {
delete m_popup;
m_popup = new KPassivePopup(this);
......@@ -127,7 +119,7 @@ void SystemTray::createPopup(const QString &songName, bool addButtons)
if(addButtons) {
QPushButton *backButton = new QPushButton(m_backPix, 0, box, "popup_back");
backButton->setFlat(true);
connect(backButton, SIGNAL(clicked()), m_backAction, SLOT(activate()));
connect(backButton, SIGNAL(clicked()), action("back"), SLOT(activate()));
}
QLabel *l = new QLabel(songName, box);
......@@ -136,7 +128,7 @@ void SystemTray::createPopup(const QString &songName, bool addButtons)
if(addButtons) {
QPushButton *forwardButton = new QPushButton (m_forwardPix, 0, box, "popup_forward");
forwardButton->setFlat(true);
connect(forwardButton, SIGNAL(clicked()), m_forwardAction, SLOT(activate()));
connect(forwardButton, SIGNAL(clicked()), action("forward"), SLOT(activate()));
}
m_popup->setView(box);
......@@ -202,9 +194,9 @@ void SystemTray::wheelEvent(QWheelEvent *e)
break;
default:
if(e->delta() > 0)
m_forwardAction->activate();
action("forward")->activate();
else
m_backAction->activate();
action("back")->activate();
break;
}
e->accept();
......@@ -218,18 +210,16 @@ void SystemTray::mousePressEvent(QMouseEvent *e)
switch(e->button()) {
case LeftButton:
case RightButton:
default:
KSystemTray::mousePressEvent(e);
break;
case MidButton:
if(!rect().contains(e->pos()))
return;
if(m_pauseAction->isEnabled())
m_pauseAction->activate();
if(action("pause")->isEnabled())
action("pause")->activate();
else
m_playAction->activate();
break;
default:
// nothing
action("play")->activate();
break;
}
}
......
......@@ -22,16 +22,13 @@
class QTimer;
class KPassivePopup;
class KMainWindow;
class KAction;
class KToggleAction;
class SystemTray : public KSystemTray
{
Q_OBJECT
public:
SystemTray(KMainWindow *parent = 0, const char *name = 0);
SystemTray(QWidget *parent = 0, const char *name = 0);
virtual ~SystemTray();
public slots:
......@@ -60,14 +57,6 @@ private:
KPassivePopup *m_popup;
QLabel *m_currentLabel;
KActionCollection *m_actionCollection;
KAction *m_playAction;
KAction *m_pauseAction;
KAction *m_stopAction;
KAction *m_backAction;
KAction *m_forwardAction;
KToggleAction *m_togglePopupsAction;
};
#endif // SYSTEMTRAY_H
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