diff --git a/src/TomahawkWindow.cpp b/src/TomahawkWindow.cpp index 8ad0974d9..dbd0179f7 100644 --- a/src/TomahawkWindow.cpp +++ b/src/TomahawkWindow.cpp @@ -109,14 +109,12 @@ TomahawkWindow::TomahawkWindow( QWidget* parent ) #endif ui->setupUi( this ); - ui->menuApp->insertAction( ui->actionCreatePlaylist, ActionCollection::instance()->getAction( "togglePrivacy" ) ); - ui->menuApp->insertSeparator( ui->actionCreatePlaylist ); - applyPlatformTweaks(); ui->centralWidget->setContentsMargins( 0, 0, 0, 0 ); TomahawkUtils::unmarginLayout( ui->centralWidget->layout() ); + setMenuBar( ActionCollection::instance()->createMenuBar( this ) ); setupAccountsMenu(); setupToolBar(); setupSideBar(); @@ -128,8 +126,8 @@ TomahawkWindow::TomahawkWindow( QWidget* parent ) if ( qApp->arguments().contains( "--debug" ) ) { - ui->menu_Help->addSeparator(); - ui->menu_Help->addAction( "Crash now...", this, SLOT( crashNow() ) ); + connect( ActionCollection::instance()->getAction( "crashNow" ), SIGNAL( triggered() ), + this, SLOT( crashNow() ) ); } // set initial state @@ -311,21 +309,17 @@ TomahawkWindow::setupSideBar() ui->splitter->addWidget( ViewManager::instance()->widget() ); ui->splitter->setCollapsible( 1, false ); - ui->actionShowOfflineSources->setChecked( TomahawkSettings::instance()->showOfflineSources() ); + ActionCollection::instance()->getAction( "showOfflineSources" ) + ->setChecked( TomahawkSettings::instance()->showOfflineSources() ); } void TomahawkWindow::setupUpdateCheck() { -#ifndef Q_OS_MAC - ui->menu_Help->insertSeparator( ui->actionAboutTomahawk ); -#endif - #if defined( Q_OS_MAC ) && defined( HAVE_SPARKLE ) - QAction* checkForUpdates = ui->menu_Help->addAction( tr( "Check For Updates..." ) ); - checkForUpdates->setMenuRole( QAction::ApplicationSpecificRole ); - connect( checkForUpdates, SIGNAL( triggered( bool ) ), SLOT( checkForUpdates() ) ); + connect( ActionCollection::instance()->getAction( "checkForUpdates" ), SIGNAL( triggered( bool ) ), + SLOT( checkForUpdates() ) ); #elif defined( Q_WS_WIN ) QUrl updaterUrl; @@ -339,9 +333,8 @@ TomahawkWindow::setupUpdateCheck() updater->SetNetworkAccessManager( TomahawkUtils::nam() ); updater->SetVersion( TomahawkUtils::appFriendlyVersion() ); - ui->menu_Help->addSeparator(); - QAction* checkForUpdates = ui->menu_Help->addAction( tr( "Check For Updates..." ) ); - connect( checkForUpdates, SIGNAL( triggered() ), updater, SLOT( CheckNow() ) ); + connect( ActionCollection::instance()->getAction( "checkForUpdates" ), SIGNAL( triggered() ), + updater, SLOT( CheckNow() ) ); #endif } @@ -430,30 +423,22 @@ TomahawkWindow::setupSignals() connect( AudioEngine::instance(), SIGNAL( stopped() ), SLOT( audioStopped() ) ); // + ActionCollection *ac = ActionCollection::instance(); // connect( ui->actionAddPeerManually, SIGNAL( triggered() ), SLOT( addPeerManually() ) ); - connect( ui->actionPreferences, SIGNAL( triggered() ), SLOT( showSettingsDialog() ) ); - connect( ui->actionDiagnostics, SIGNAL( triggered() ), SLOT( showDiagnosticsDialog() ) ); - connect( ui->actionLegalInfo, SIGNAL( triggered() ), SLOT( legalInfo() ) ); + connect( ac->getAction( "preferences" ), SIGNAL( triggered() ), SLOT( showSettingsDialog() ) ); + connect( ac->getAction( "diagnostics" ), SIGNAL( triggered() ), SLOT( showDiagnosticsDialog() ) ); + connect( ac->getAction( "legalInfo" ), SIGNAL( triggered() ), SLOT( legalInfo() ) ); connect( m_actionToggleConnect, SIGNAL( triggered() ), AccountManager::instance(), SLOT( toggleAccountsConnected() ) ); - connect( ui->actionUpdateCollection, SIGNAL( triggered() ), SLOT( updateCollectionManually() ) ); - connect( ui->actionRescanCollection, SIGNAL( triggered() ), SLOT( rescanCollectionManually() ) ); - connect( ui->actionLoadXSPF, SIGNAL( triggered() ), SLOT( loadSpiff() )); - connect( ui->actionCreatePlaylist, SIGNAL( triggered() ), SLOT( createPlaylist() )); - connect( ui->actionCreate_New_Station, SIGNAL( triggered() ), SLOT( createStation() )); - connect( ui->actionAboutTomahawk, SIGNAL( triggered() ), SLOT( showAboutTomahawk() ) ); - connect( ui->actionExit, SIGNAL( triggered() ), qApp, SLOT( quit() ) ); - connect( ui->actionShowOfflineSources, SIGNAL( triggered() ), SLOT( showOfflineSources() ) ); - - connect( ui->actionPlay, SIGNAL( triggered() ), AudioEngine::instance(), SLOT( playPause() ) ); - connect( ui->actionNext, SIGNAL( triggered() ), AudioEngine::instance(), SLOT( next() ) ); - connect( ui->actionPrevious, SIGNAL( triggered() ), AudioEngine::instance(), SLOT( previous() ) ); + connect( ac->getAction( "updateCollection" ), SIGNAL( triggered() ), SLOT( updateCollectionManually() ) ); + connect( ac->getAction( "rescanCollection" ), SIGNAL( triggered() ), SLOT( rescanCollectionManually() ) ); + connect( ac->getAction( "loadXSPF" ), SIGNAL( triggered() ), SLOT( loadSpiff() )); + connect( ac->getAction( "aboutTomahawk" ), SIGNAL( triggered() ), SLOT( showAboutTomahawk() ) ); + connect( ac->getAction( "quit" ), SIGNAL( triggered() ), qApp, SLOT( quit() ) ); + connect( ac->getAction( "showOfflineSources" ), SIGNAL( triggered() ), SLOT( showOfflineSources() ) ); #if defined( Q_OS_MAC ) - connect( ui->actionMinimize, SIGNAL( triggered() ), SLOT( minimize() ) ); - connect( ui->actionZoom, SIGNAL( triggered() ), SLOT( maximize() ) ); -#else - ui->menuWindow->clear(); - ui->menuWindow->menuAction()->setVisible( false ); + connect( ac->getAction( "minimize" ), SIGNAL( triggered() ), SLOT( minimize() ) ); + connect( ac->getAction( "zoom" ), SIGNAL( triggered() ), SLOT( maximize() ) ); #endif // @@ -528,8 +513,8 @@ TomahawkWindow::showEvent( QShowEvent* e ) QMainWindow::showEvent( e ); #if defined( Q_OS_MAC ) - ui->actionMinimize->setDisabled( false ); - ui->actionZoom->setDisabled( false ); + ActionCollection::instance()->getAction( "minimize" )->setDisabled( false ); + ActionCollection::instance()->getAction( "zoom" )->setDisabled( false ); #endif } @@ -540,8 +525,8 @@ TomahawkWindow::hideEvent( QHideEvent* e ) QMainWindow::hideEvent( e ); #if defined( Q_OS_MAC ) - ui->actionMinimize->setDisabled( true ); - ui->actionZoom->setDisabled( true ); + ActionCollection::instance()->getAction( "minimize" )->setDisabled( true ); + ActionCollection::instance()->getAction( "zoom" )->setDisabled( true ); #endif } @@ -818,8 +803,10 @@ TomahawkWindow::pluginMenuRemoved( QMenu* menu ) void TomahawkWindow::showOfflineSources() { - m_sourcetree->showOfflineSources( ui->actionShowOfflineSources->isChecked() ); - TomahawkSettings::instance()->setShowOfflineSources( ui->actionShowOfflineSources->isChecked() ); + m_sourcetree->showOfflineSources( ActionCollection::instance() + ->getAction( "showOfflineSources" )->isChecked() ); + TomahawkSettings::instance()->setShowOfflineSources( ActionCollection::instance() + ->getAction( "showOfflineSources" )->isChecked() ); } @@ -1054,7 +1041,7 @@ TomahawkWindow::audioStarted() { m_audioRetryCounter = 0; - ui->actionPlay->setText( tr( "Pause" ) ); + ActionCollection::instance()->getAction( "playPause" )->setText( tr( "Pause" ) ); ActionCollection::instance()->getAction( "stop" )->setEnabled( true ); #ifdef Q_OS_WIN @@ -1074,7 +1061,7 @@ TomahawkWindow::audioFinished() void TomahawkWindow::audioPaused() { - ui->actionPlay->setText( tr( "Play" ) ); + ActionCollection::instance()->getAction( "playPause" )->setText( tr( "&Play" ) ); } diff --git a/src/TomahawkWindow.ui b/src/TomahawkWindow.ui index 786516cba..665100efb 100644 --- a/src/TomahawkWindow.ui +++ b/src/TomahawkWindow.ui @@ -61,60 +61,6 @@ - - - - 0 - 0 - 1000 - 20 - - - - - &Settings - - - - - - &Controls - - - - - - - - - - - - - - - - - - - &Window - - - - - - - &Help - - - - - - - - - - diff --git a/src/libtomahawk/ActionCollection.cpp b/src/libtomahawk/ActionCollection.cpp index bc6908e30..7bb74bb5b 100644 --- a/src/libtomahawk/ActionCollection.cpp +++ b/src/libtomahawk/ActionCollection.cpp @@ -3,6 +3,7 @@ * Copyright 2010-2011, Christian Muehlhaeuser * Copyright 2010-2012, Jeff Mitchell * Copyright 2012, Leo Franchi + * Copyright 2012, Teo Mrnjavac * * Tomahawk is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -69,14 +70,17 @@ ActionCollection::initActions() m_actionCollection[ "togglePrivacy" ] = privacyToggle; connect( m_actionCollection[ "togglePrivacy" ], SIGNAL( triggered() ), SLOT( togglePrivateListeningMode() ), Qt::UniqueConnection ); - m_actionCollection[ "loadPlaylist" ] = new QAction( tr( "&Load Playlist" ), this ); + m_actionCollection[ "loadPlaylist" ] = new QAction( tr( "&Load Playlist" ), this ); + m_actionCollection[ "loadPlaylist" ]->setShortcut( Qt::Key_Space ); m_actionCollection[ "renamePlaylist" ] = new QAction( tr( "&Rename Playlist" ), this ); - m_actionCollection[ "copyPlaylist" ] = new QAction( tr( "&Copy Playlist Link" ), this ); - m_actionCollection[ "playPause" ] = new QAction( tr( "&Play" ), this ); - m_actionCollection[ "stop" ] = new QAction( tr( "&Stop" ), this ); - m_actionCollection[ "previousTrack" ] = new QAction( tr( "&Previous Track" ), this ); - m_actionCollection[ "nextTrack" ] = new QAction( tr( "&Next Track" ), this ); - m_actionCollection[ "quit" ] = new QAction( tr( "&Quit" ), this ); + m_actionCollection[ "copyPlaylist" ] = new QAction( tr( "&Copy Playlist Link" ), this ); + m_actionCollection[ "playPause" ] = new QAction( tr( "&Play" ), this ); + m_actionCollection[ "stop" ] = new QAction( tr( "&Stop" ), this ); + m_actionCollection[ "previousTrack" ] = new QAction( tr( "&Previous Track" ), this ); + m_actionCollection[ "nextTrack" ] = new QAction( tr( "&Next Track" ), this ); + m_actionCollection[ "quit" ] = new QAction( tr( "&Quit" ), this ); + m_actionCollection[ "quit" ]->setShortcut( QKeySequence::Quit ); + m_actionCollection[ "quit" ]->setMenuRole( QAction::QuitRole ); // connect actions to AudioEngine AudioEngine *ae = AudioEngine::instance(); @@ -84,6 +88,91 @@ ActionCollection::initActions() connect( m_actionCollection[ "stop" ], SIGNAL( triggered() ), ae, SLOT( stop() ), Qt::UniqueConnection ); connect( m_actionCollection[ "previousTrack" ], SIGNAL( triggered() ), ae, SLOT( previous() ), Qt::UniqueConnection ); connect( m_actionCollection[ "nextTrack" ], SIGNAL( triggered() ), ae, SLOT( next() ), Qt::UniqueConnection ); + + // main menu actions + m_actionCollection[ "loadXSPF" ] = new QAction( tr( "Load &XSPF..." ), this ); + m_actionCollection[ "updateCollection" ] = new QAction( tr( "U&pdate Collection" ), this ); + m_actionCollection[ "rescanCollection" ] = new QAction( tr( "Fully &Rescan Collection" ), this ); + m_actionCollection[ "showOfflineSources" ] = new QAction( tr( "Show Offline Sources" ), this ); + m_actionCollection[ "showOfflineSources" ]->setCheckable( true ); + m_actionCollection[ "preferences" ] = new QAction( tr( "&Configure Tomahawk..." ), this ); + m_actionCollection[ "preferences" ]->setMenuRole( QAction::PreferencesRole ); + m_actionCollection[ "minimize" ] = new QAction( tr( "Minimize" ), this ); + m_actionCollection[ "minimize" ]->setShortcut( QKeySequence( "Ctrl+M" ) ); + m_actionCollection[ "zoom" ] = new QAction( tr( "Zoom" ), this ); + m_actionCollection[ "zoom" ]->setShortcut( QKeySequence( "Meta+Ctrl+Z" ) ); + m_actionCollection[ "diagnostics" ] = new QAction( tr( "Diagnostics..." ), this ); + m_actionCollection[ "aboutTomahawk" ] = new QAction( tr( "About &Tomahawk..." ), this ); + m_actionCollection[ "aboutTomahawk" ]->setMenuRole( QAction::AboutRole ); + m_actionCollection[ "legalInfo" ] = new QAction( tr( "&Legal Information..." ), this ); +#if defined( Q_OS_MAC ) && defined( HAVE_SPARKLE ) || defined( Q_WS_WIN ) + m_actionCollection[ "checkForUpdates" ] = new QAction( tr( "Check For Updates..." ), this ); + m_actionCollection[ "checkForUpdates" ]->setMenuRole( QAction::ApplicationSpecificRole ); +#endif + m_actionCollection[ "crashNow" ] = new QAction( "Crash now...", this ); +} + +QMenuBar * +ActionCollection::createMenuBar( QWidget *parent ) +{ + QMenuBar *menuBar = new QMenuBar( parent ); + + QMenu *controlsMenu = new QMenu( tr( "&Controls" ), menuBar ); + controlsMenu->addAction( m_actionCollection[ "playPause" ] ); + controlsMenu->addAction( m_actionCollection[ "previousTrack" ] ); + controlsMenu->addAction( m_actionCollection[ "nextTrack" ] ); + controlsMenu->addSeparator(); + controlsMenu->addAction( m_actionCollection[ "togglePrivacy" ] ); + controlsMenu->addAction( m_actionCollection[ "showOfflineSources" ] ); + controlsMenu->addSeparator(); + controlsMenu->addAction( m_actionCollection[ "loadXSPF" ] ); + controlsMenu->addAction( m_actionCollection[ "updateCollection" ] ); + controlsMenu->addAction( m_actionCollection[ "rescanCollection" ] ); + controlsMenu->addSeparator(); + controlsMenu->addAction( m_actionCollection[ "quit" ] ); + + QMenu *settingsMenu = new QMenu( tr( "&Settings" ), menuBar ); + settingsMenu->addAction( m_actionCollection[ "preferences" ] ); + + QMenu *windowMenu = new QMenu( tr( "&Window" ), menuBar ); + windowMenu->addAction( m_actionCollection[ "minimize" ] ); + windowMenu->addAction( m_actionCollection[ "zoom" ] ); + + QMenu *helpMenu = new QMenu( tr( "&Help" ), menuBar ); + helpMenu->addAction( m_actionCollection[ "diagnostics" ] ); + helpMenu->addAction( m_actionCollection[ "aboutTomahawk" ] ); + helpMenu->addAction( m_actionCollection[ "legalInfo" ] ); + + // Setup update check +#ifndef Q_OS_MAC + helpMenu->insertSeparator( m_actionCollection[ "aboutTomahawk" ] ); +#endif + +#if defined( Q_OS_MAC ) && defined( HAVE_SPARKLE ) + helpMenu->addAction( m_actionCollection[ "checkForUpdates" ] ); +#elif defined( Q_WS_WIN ) + helpMenu->addSeparator(); + helpMenu->addAction( m_actionCollection[ "checkForUpdates" ] ); +#endif + if ( qApp->arguments().contains( "--debug" ) ) + { + helpMenu->addSeparator(); + helpMenu->addAction( m_actionCollection[ "crashNow" ] ); + } + + menuBar->addMenu( controlsMenu ); + menuBar->addMenu( settingsMenu ); +#if defined( Q_OS_MAC ) + menuBar->addMenu( windowMenu ); +#endif + menuBar->addMenu( helpMenu ); + return menuBar; +} + +QMenu * +ActionCollection::createCompressedMenu( QWidget *parent ) +{ + } diff --git a/src/libtomahawk/ActionCollection.h b/src/libtomahawk/ActionCollection.h index 378b13cba..aa24ba58f 100644 --- a/src/libtomahawk/ActionCollection.h +++ b/src/libtomahawk/ActionCollection.h @@ -24,6 +24,7 @@ #include "DllMacro.h" #include +#include class DLLEXPORT ActionCollection : public QObject { @@ -43,6 +44,9 @@ public: void initActions(); + QMenuBar *createMenuBar( QWidget *parent ); + QMenu *createCompressedMenu( QWidget *parent ); + QAction* getAction( const QString& name ); QList< QAction* > getAction( ActionDestination category ); QObject* actionNotifier( QAction* );