1 /***************************************************************************
2 begin : Fre Nov 15 2002
3 copyright : (C) Mark Kretschmann <markey@web.de>
4 : (C) Max Howell <max.howell@methylblue.com>
5 : (C) G??bor Lehel <illissius@gmail.com>
6 ***************************************************************************/
8 /***************************************************************************
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
15 ***************************************************************************/
17 #include "config-amarok.h" //HAVE_LIBVISUAL definition
19 #include "actionclasses.h" //see toolbar construction
20 #include "amarokconfig.h"
22 #include "analyzerwidget.h"
23 #include "collection/CollectionManager.h"
24 #include "collectionbrowser/CollectionWidget.h"
25 #include "context/CoverBling.h"
26 #include "context/ContextView.h"
27 #include "context/DataEngineManager.h"
28 #include "CoverManager.h" // for actions
30 #include "editfilterdialog.h"
31 #include "enginecontroller.h" //for actions in ctor
32 #include "filebrowser.h"
33 #include "filebrowserwidget.h"
34 #include "k3bexporter.h"
35 #include "lastfm.h" //check credentials when adding lastfm streams
36 #include "MainWindow.h"
37 #include "mediabrowser.h"
38 #include "playlist/PlaylistModel.h"
39 #include "playlist/PlaylistWidget.h"
40 #include "progressslider.h"
41 #include "scriptmanager.h"
42 #include "searchwidget.h"
43 #include "servicebrowser/ServicePluginManager.h"
44 #include "servicebrowser/scriptableservice/scriptableservice.h"
45 #include "servicebrowser/servicebrowser.h"
46 #include "servicebrowser/shoutcast/ShoutcastService.h"
47 #include "servicebrowser/mp3tunes/mp3tunesservice.h"
49 #include "Sidebar.moc"
50 #include "socketserver.h"
51 #include "Statistics.h"
52 #include "ContextStatusBar.h"
53 #include "TheInstances.h"
54 #include "threadmanager.h"
55 #include "volumewidget.h"
56 #include "PodcastCollection.h"
57 #include "playlistmanager/PlaylistManager.h"
59 #include "playlistbrowser/PlaylistBrowser.h"
61 #include "queuemanager/QueueManager.h"
64 #include <QHeaderView>
65 #include <QLabel> //search filter label
67 #include <QPaintEngine>
68 #include <QPainter> //dynamic title
70 #include <QTimer> //search filter timer
71 #include <QToolTip> //QToolTip::add()
72 #include <QVBoxLayout>
74 #include <KAction> //m_actionCollection
75 #include <KActionCollection>
76 #include <KActionMenu>
77 #include <kapplication.h> //kapp
78 #include <kfiledialog.h> //savePlaylist(), openPlaylist()
80 #include <kinputdialog.h> //slotAddStream()
83 #include <kmessagebox.h> //savePlaylist()
85 #include <kpushbutton.h>
89 class ContextWidget
: public KVBox
91 // Set a useful size default of the center tab.
93 ContextWidget( QWidget
*parent
) : KVBox( parent
) {}
94 QSize
sizeHint() const { return QSize( 400, 300 ); }
97 MainWindow
*MainWindow::s_instance
= 0;
99 MainWindow::MainWindow()
100 :KXmlGuiWindow( 0, Qt::WGroupLeader
)
103 setObjectName("MainWindow");
106 new Playlist::Model( this );
108 // Sets caption and icon correctly (needed e.g. for GNOME)
109 kapp
->setTopWidget( this );
115 if( AmarokConfig::mainWindowSize().isValid() )
117 // if first ever run, use sizeHint(), and let
118 // KWindowSystem place us otherwise use the stored values
119 resize( AmarokConfig::mainWindowSize() );
120 move( AmarokConfig::mainWindowPos() );
122 m_browsers
= new SideBar( this, new KVBox
);
125 MainWindow::~MainWindow()
128 AmarokConfig::setMainWindowPos( pos() ); //TODO de XT?
129 AmarokConfig::setMainWindowSize( size() ); //TODO de XT?
133 ///////// public interface
136 * This function will initialize the playlist window.
138 void MainWindow::init()
140 layout()->setContentsMargins( 0, 0, 0, 0 );
143 //this function is necessary because Amarok::actionCollection() returns our actionCollection
144 //via the App::m_pMainWindow pointer since App::m_pMainWindow is not defined until
145 //the above ctor returns it causes a crash unless we do the initialisation in 2 stages.
146 Playlist::Widget
*playlistWidget
= new Playlist::Widget( this );
149 m_controlBar
= new MainToolbar( this );
150 m_controlBar
->setMaximumSize( 20000, 62 );
151 m_controlBar
->setSizePolicy( QSizePolicy::Expanding
, QSizePolicy::Preferred
);
153 AnalyzerWidget
*aw
= new AnalyzerWidget( m_controlBar
);
154 aw
->setMinimumSize( 200, 30 );
156 m_controlBar
->layout()->setAlignment( aw
, Qt::AlignLeft
);
158 KVBox
*aVBox
= new KVBox( m_controlBar
);
159 aVBox
->setMaximumSize( 50000, 60 );
161 KHBox
*insideBox
= new KHBox( aVBox
);
162 insideBox
->setMaximumSize( 600000, 45 );
164 KToolBar
*playerControlsToolbar
= new Amarok::ToolBar( insideBox
);
166 playerControlsToolbar
->setMinimumSize( 180, 45 );
167 insideBox
->layout()->setAlignment( playerControlsToolbar
, Qt::AlignCenter
);
169 QWidget
* spacer
= new QWidget( m_controlBar
);
170 spacer
->setMinimumSize( 50, 30 );
171 m_controlBar
->layout()->setAlignment( spacer
, Qt::AlignRight
);
173 VolumeWidget
*vw
= new VolumeWidget( m_controlBar
);
174 vw
->setMinimumSize( 150, 30 );
175 m_controlBar
->layout()->setAlignment( vw
, Qt::AlignRight
| Qt::AlignVCenter
);
177 ProgressWidget
*pWidget
= new ProgressWidget( aVBox
);
178 pWidget
->setMinimumSize( 400, 17 );
179 pWidget
->setMaximumSize( 600000, 17 );
181 playerControlsToolbar
->setToolButtonStyle( Qt::ToolButtonIconOnly
);
182 playerControlsToolbar
->setSizePolicy( QSizePolicy::Preferred
, QSizePolicy::Preferred
);
183 playerControlsToolbar
->setIconDimensions( 32 );
184 playerControlsToolbar
->setMovable( false );
185 playerControlsToolbar
->addAction( actionCollection()->action( "prev" ) );
186 playerControlsToolbar
->addAction( actionCollection()->action( "play_pause" ) );
187 playerControlsToolbar
->addAction( actionCollection()->action( "stop" ) );
188 playerControlsToolbar
->addAction( actionCollection()->action( "next" ) );
193 QColor topColor
= bottomColor
= palette().highlight().color().dark( 150 );
194 bottomColor
= bottomColor
.dark( 100 );
195 topColor
.setAlpha( 75 );
196 bottomColor
.setAlpha( 130 );
200 ContextWidget
*contextWidget
= new ContextWidget( this );
201 contextWidget
->setSizePolicy( QSizePolicy::Maximum
, QSizePolicy::Maximum
);
202 new Context::ContextView( contextWidget
);
204 new Amarok::ContextStatusBar( contextWidget
);
206 if( AmarokConfig::useCoverBling() && QGLFormat::hasOpenGL() )
207 new CoverBling( contextWidget
);
210 connect( m_browsers
, SIGNAL( widgetActivated( int ) ), SLOT( slotShrinkBrowsers( int ) ) );
212 QVBoxLayout
*mainLayout
= new QVBoxLayout
;
213 mainLayout
->setContentsMargins( 1, 1, 1, 1 );
215 QWidget
*centralWidget
= new QWidget( this );
216 centralWidget
->setLayout( mainLayout
);
218 m_splitter
= new QSplitter( Qt::Horizontal
, centralWidget
);
219 m_splitter
->setHandleWidth( 0 );
220 m_splitter
->addWidget( m_browsers
);
221 m_splitter
->addWidget( contextWidget
);
222 m_splitter
->addWidget( playlistWidget
);
224 mainLayout
->addWidget( m_controlBar
);
225 mainLayout
->addWidget( m_splitter
);
226 setCentralWidget( centralWidget
);
230 Debug::Block
block( "Creating browsers. Please report long start times!" );
232 #define addBrowserMacro( Type, name, text, icon ) { \
233 Debug::Block block( name ); \
234 m_browsers->addWidget( KIcon( icon ), text, new Type( name ) ); \
235 m_browserNames.append( name ); }
237 #define addInstBrowserMacro( Type, name, text, icon ) { \
238 m_browsers->addWidget( KIcon( icon ), text, Type::instance() ); \
239 m_browserNames.append( name ); }
241 addBrowserMacro( CollectionWidget
, "CollectionBrowser", i18n("Collection"), Amarok::icon( "collection" ) )
243 addBrowserMacro( PlaylistBrowserNS::PlaylistBrowser
, "NeoPlaylistBrowser", i18n("Playlists"), Amarok::icon( "playlist" ) )
245 PodcastCollection
*podcastCollection
= new PodcastCollection();
246 The::playlistManager()->addProvider( podcastCollection
->channelProvider(), PlaylistManager::PodcastChannel
);
248 addBrowserMacro( FileBrowserWidget
, "FileBrowserWidget", i18n("Files"), Amarok::icon( "files" ) );
250 //DEBUG: Comment out the addBrowserMacro line and uncomment the m_browsers line (passing in a vfat device name) to see the "virtual root" functionality
254 //uncomment to enable the old file browser
255 // addBrowserMacro( FileBrowser, "FileBrowser", i18n("Files"), Amarok::icon( "files" ) )
257 //cant use macros here since we need access to the browsers directly
259 ServiceBrowser
* internetContentServiceBrowser
= new ServiceBrowser(this, "Internet Content" );;
260 m_browsers
->addWidget( KIcon( Amarok::icon( "magnatune" ) ), i18n("Internet"), internetContentServiceBrowser
);
261 m_browserNames
.append( "Internet" );
264 //get the plugin manager
265 ServicePluginManager::instance()->setBrowser( internetContentServiceBrowser
);
266 ServicePluginManager::instance()->init();
268 debug() << "Add me dammit!!!!!";
269 internetContentServiceBrowser
->setScriptableServiceManager( new ScriptableServiceManager( 0 ) );
272 new MediaBrowser( "MediaBrowser" );
273 if( MediaBrowser::isAvailable() )
275 addInstBrowserMacro( MediaBrowser
, "MediaBrowser", i18n("Devices"), Amarok::icon( "device" ) )
277 #undef addBrowserMacro
278 #undef addInstBrowserMacro
283 kapp
->installEventFilter( this ); // keyboards shortcuts for the browsers
285 Amarok::MessageQueue::instance()->sendMessages();
288 void MainWindow::deleteBrowsers()
290 m_browsers
->deleteBrowsers();
293 void MainWindow::slotSetFilter( const QString
&filter
) //SLOT
296 // m_lineEdit->setText( filter );
299 void MainWindow::slotShrinkBrowsers( int index
) const
301 // Because QSplitter sucks and will not recompute sizes if a pane is shrunk and not hidden.
305 sizes
<< m_browsers
->sideBarWidget()->width()
306 << m_splitter
->sizes()[1] + m_splitter
->sizes()[0] - m_browsers
->sideBarWidget()->width()
307 << m_splitter
->sizes()[2];
308 m_splitter
->setSizes( sizes
);
312 // void MainWindow::slotEditFilter() //SLOT
314 // EditFilterDialog *fd = new EditFilterDialog( this, true, "" );
315 // connect( fd, SIGNAL(filterChanged(const QString &)), SLOT(slotSetFilter(const QString &)) );
317 // m_searchWidget->lineEdit()->setText( fd->filter() );
321 void MainWindow::addBrowser( const QString
&name
, QWidget
*browser
, const QString
&text
, const QString
&icon
)
323 if( !m_browserNames
.contains( name
) )
325 m_browsers
->addWidget( KIcon(Amarok::icon( icon
)), text
, browser
);
326 m_browserNames
.append( name
);
330 void MainWindow::showBrowser( const QString
&name
)
332 const int index
= m_browserNames
.indexOf( name
);
334 m_browsers
->showWidget( index
);
339 * @param o The object
342 * Here we filter some events for the Playlist Search LineEdit and the Playlist. @n
343 * this makes life easier since we have more useful functions available from this class
345 bool MainWindow::eventFilter( QObject
*o
, QEvent
*e
)
347 typedef Q3ListViewItemIterator It
;
351 case 6/*QEvent::KeyPress*/:
353 //there are a few keypresses that we intercept
355 #define e static_cast<QKeyEvent*>(e)
358 // if( e->key() == Qt::Key_F2 )
360 // // currentItem is ALWAYS visible.
361 // Q3ListViewItem *item = pl->currentItem();
363 // // intercept F2 for inline tag renaming
364 // // NOTE: tab will move to the next tag
365 // // NOTE: if item is still null don't select first item in playlist, user wouldn't want that. It's silly.
366 // // TODO: berkus has solved the "inability to cancel" issue with K3ListView, but it's not in kdelibs yet..
368 // // item may still be null, but this is safe
369 // // NOTE: column 0 cannot be edited currently, hence we pick column 1
370 // pl->rename( item, 1 ); //TODO what if this column is hidden?
376 // if( o == m_searchWidget->lineEdit() ) //the search lineedit
378 // Q3ListViewItem *item;
379 // switch( e->key() )
382 // case Qt::Key_Down:
383 // case Qt::Key_PageDown:
384 // case Qt::Key_PageUp:
386 // QApplication::sendEvent( pl, e );
389 // case Qt::Key_Return:
390 // case Qt::Key_Enter:
391 // item = *It( pl, It::Visible );
392 // //m_lineEdit->clear();
393 // pl->m_filtertimer->stop(); //HACK HACK HACK
395 // if( e->modifiers() & Qt::ControlModifier )
397 // QList<PlaylistItem*> in, out;
398 // if( e->modifiers() & Qt::ShiftModifier )
399 // for( It it( pl, It::Visible ); PlaylistItem *x = static_cast<PlaylistItem*>( *it ); ++it )
401 // pl->queue( x, true );
402 // ( pl->m_nextTracks.contains( x ) ? in : out ).append( x );
406 // It it( pl, It::Visible );
407 // pl->activate( *it );
409 // for( int i = 0; PlaylistItem *x = static_cast<PlaylistItem*>( *it ); ++i, ++it )
412 // pl->m_nextTracks.insert( i, x );
415 // if( !in.isEmpty() || !out.isEmpty() )
416 // emit pl->queueChanged( in, out );
417 // pl->setFilter( "" );
418 // pl->ensureItemCentered( ( e->modifiers() & Qt::ShiftModifier ) ? item : pl->currentTrack() );
422 // pl->setFilter( "" );
423 // if( ( e->modifiers() & Qt::ShiftModifier ) && item )
425 // pl->queue( item );
426 // pl->ensureItemCentered( item );
430 // pl->activate( item );
431 // pl->showCurrentTrack();
436 // case Qt::Key_Escape:
437 // m_searchWidget->lineEdit()->clear();
445 //following are for Playlist::instance() only
446 //we don't handle these in the playlist because often we manipulate the lineEdit too
455 return QWidget::eventFilter( o
, e
);
459 void MainWindow::closeEvent( QCloseEvent
*e
)
466 //KDE policy states we should hide to tray and not quit() when the
467 //close window button is pushed for the main widget
469 e
->accept(); //if we don't do this the info box appears on quit()!
471 if( AmarokConfig::showTrayIcon() && e
->spontaneous() && !kapp
->sessionSaving() )
473 KMessageBox::information( this,
474 i18n( "<qt>Closing the main-window will keep Amarok running in the System Tray. "
475 "Use <B>Quit</B> from the menu, or the Amarok tray-icon to exit the application.</qt>" ),
476 i18n( "Docking in System Tray" ), "hideOnCloseInfo" );
484 void MainWindow::showEvent( QShowEvent
* )
487 // static bool firstTime = true;
489 // Playlist::instance()->setFocus();
490 // firstTime = false;
493 #include <qdesktopwidget.h>
494 QSize
MainWindow::sizeHint() const
496 return QApplication::desktop()->screenGeometry( (QWidget
*)this ).size() / 1.5;
500 void MainWindow::savePlaylist() const //SLOT
502 QString playlistName
= KFileDialog::getSaveFileName();
503 The::playlistModel()->saveM3U( playlistName
);
507 void MainWindow::slotBurnPlaylist() const //SLOT
509 K3bExporter::instance()->exportCurrentPlaylist();
512 void MainWindow::slotShowCoverManager() const //SLOT
514 CoverManager::showOnce();
517 void MainWindow::slotPlayMedia() //SLOT
519 // Request location and immediately start playback
520 slotAddLocation( true );
524 void MainWindow::slotAddLocation( bool directPlay
) //SLOT
526 // open a file selector to add media to the playlist
528 KFileDialog
dlg( KUrl(QString()), QString("*.*|"), this );
529 dlg
.setCaption( directPlay
? i18n("Play Media (Files or URLs)") : i18n("Add Media (Files or URLs)") );
530 dlg
.setMode( KFile::Files
| KFile::Directory
);
532 files
= dlg
.selectedUrls();
533 if( files
.isEmpty() ) return;
534 const int options
= directPlay
? Playlist::Append
| Playlist::DirectPlay
: Playlist::Append
;
536 Meta::TrackList tracks
= CollectionManager::instance()->tracksForUrls( files
);
538 The::playlistModel()->insertOptioned( tracks
.takeFirst(), options
);
540 foreach( Meta::TrackPtr track
, tracks
)
542 The::playlistModel()->insertOptioned( track
, Playlist::Append
);
546 void MainWindow::slotAddStream() //SLOT
549 QString url
= KInputDialog::getText( i18n("Add Stream"), i18n("URL"), QString(), &ok
, this );
553 Meta::TrackPtr track
= CollectionManager::instance()->trackForUrl( KUrl( url
) );
555 The::playlistModel()->insertOptioned( track
, Playlist::Append
|Playlist::DirectPlay
);
559 void MainWindow::playLastfmPersonal() //SLOT
561 if( !LastFm::Controller::checkCredentials() ) return;
563 const KUrl
url( QString( "lastfm://user/%1/personal" )
564 .arg( AmarokConfig::scrobblerUsername() ) );
566 Meta::TrackPtr track
= CollectionManager::instance()->trackForUrl( url
);
568 The::playlistModel()->insertOptioned( track
, Playlist::Append
|Playlist::DirectPlay
);
572 void MainWindow::addLastfmPersonal() //SLOT
574 if( !LastFm::Controller::checkCredentials() ) return;
576 const KUrl
url( QString( "lastfm://user/%1/personal" )
577 .arg( AmarokConfig::scrobblerUsername() ) );
579 Meta::TrackPtr track
= CollectionManager::instance()->trackForUrl( url
);
581 The::playlistModel()->insertOptioned( track
, Playlist::Append
);
585 void MainWindow::playLastfmNeighbor() //SLOT
587 if( !LastFm::Controller::checkCredentials() ) return;
589 const KUrl
url( QString( "lastfm://user/%1/neighbours" )
590 .arg( AmarokConfig::scrobblerUsername() ) );
592 Meta::TrackPtr track
= CollectionManager::instance()->trackForUrl( url
);
594 The::playlistModel()->insertOptioned( track
, Playlist::Append
);
598 void MainWindow::addLastfmNeighbor() //SLOT
600 if( !LastFm::Controller::checkCredentials() ) return;
602 const KUrl
url( QString( "lastfm://user/%1/neighbours" )
603 .arg( AmarokConfig::scrobblerUsername() ) );
605 Meta::TrackPtr track
= CollectionManager::instance()->trackForUrl( url
);
607 The::playlistModel()->insertOptioned( track
, Playlist::Append
);
611 void MainWindow::playLastfmCustom() //SLOT
613 const QString token
= LastFm::Controller::createCustomStation();
614 if( token
.isEmpty() ) return;
616 const KUrl
url( "lastfm://artist/" + token
+ "/similarartists" );
617 Meta::TrackPtr track
= CollectionManager::instance()->trackForUrl( url
);
619 The::playlistModel()->insertOptioned( track
, Playlist::Append
|Playlist::DirectPlay
);
623 void MainWindow::addLastfmCustom() //SLOT
625 const QString token
= LastFm::Controller::createCustomStation();
626 if( token
.isEmpty() ) return;
628 const KUrl
url( "lastfm://artist/" + token
+ "/similarartists" );
629 Meta::TrackPtr track
= CollectionManager::instance()->trackForUrl( url
);
631 The::playlistModel()->insertOptioned( track
, Playlist::Append
);
635 void MainWindow::playLastfmGlobaltag() //SLOT
637 if( !LastFm::Controller::checkCredentials() ) return;
639 KAction
*action
= dynamic_cast<KAction
*>( sender() );
640 if( !action
) return;
642 const QString tag
= action
->text();
643 const KUrl
url( "lastfm://globaltags/" + tag
);
644 Meta::TrackPtr track
= CollectionManager::instance()->trackForUrl( url
);
646 The::playlistModel()->insertOptioned( track
, Playlist::Append
|Playlist::DirectPlay
);
650 void MainWindow::addLastfmGlobaltag() //SLOT
652 if( !LastFm::Controller::checkCredentials() ) return;
654 KAction
*action
= dynamic_cast<KAction
*>( sender() );
655 if( !action
) return;
657 const QString tag
= action
->text();
658 const KUrl
url( "lastfm://globaltags/" + tag
);
659 Meta::TrackPtr track
= CollectionManager::instance()->trackForUrl( url
);
661 The::playlistModel()->insertOptioned( track
, Playlist::Append
);
665 void MainWindow::playAudioCD() //SLOT
668 if( EngineController::engine()->getAudioCDContents(QString(), urls
) )
670 Meta::TrackList tracks
= CollectionManager::instance()->tracksForUrls( urls
);
671 if( !tracks
.isEmpty() )
672 The::playlistModel()->insertOptioned( tracks
, Playlist::Replace
);
675 { // Default behaviour
676 showBrowser( "FileBrowser" );
680 void MainWindow::showScriptSelector() //SLOT
682 ScriptManager::instance()->show();
683 ScriptManager::instance()->raise();
686 void MainWindow::showQueueManager() //SLOT
688 if( QueueManagerNS::QueueManager::instance() )
690 QueueManagerNS::QueueManager::instance()->raise();
694 QueueManagerNS::QueueManager dialog
;
695 if( dialog
.exec() == QDialog::Accepted
)
701 void MainWindow::showStatistics() //SLOT
703 if( Statistics::instance() ) {
704 Statistics::instance()->raise();
711 void MainWindow::slotToggleFocus() //SLOT
714 // if( m_browsers->currentWidget() && ( Playlist::instance()->hasFocus() /*|| m_searchWidget->lineEdit()->hasFocus()*/ ) )
715 // m_browsers->currentWidget()->setFocus();
718 void MainWindow::slotToggleToolbar() //SLOT
720 m_controlBar
->setVisible( !m_controlBar
->isHidden() );
721 AmarokConfig::setShowToolbar( !AmarokConfig::showToolbar() );
722 Amarok::actionCollection()->action( "toggle_toolbar" )->setText( !m_controlBar
->isHidden() ? i18n("Hide Toolbar") : i18n("Show Toolbar") );
725 void MainWindow::toolsMenuAboutToShow() //SLOT
727 Amarok::actionCollection()->action( "equalizer" )->setEnabled( !EngineController::hasEngineProperty( "HasEqualizer" ) );
728 Amarok::actionCollection()->action( "rescan_collection" )->setEnabled( !ThreadManager::instance()->isJobPending( "CollectionScanner" ) );
732 #include <kwindowsystem.h>
734 * Show/hide playlist global shortcut and PlayerWindow PlaylistButton connect to this slot
736 * 1. hidden & iconified -> deiconify & show @n
737 * 2. hidden & deiconified -> show @n
738 * 3. shown & iconified -> deiconify @n
739 * 4. shown & deiconified -> hide @n
740 * 5. don't hide if there is no tray icon or playerWindow. todo (I can't be arsed) @n
742 * @note isMinimized() can only be true if the window isVisible()
743 * this has taken me hours to get right, change at your peril!
744 * there are more contingencies than you can believe
746 void MainWindow::showHide() //SLOT
749 const KWindowInfo info
= KWindowSystem::windowInfo( winId(), 0, 0 );
750 const uint desktop
= KWindowSystem::currentDesktop();
751 const bool isOnThisDesktop
= info
.isOnDesktop( desktop
);
752 const bool isShaded
= false;
756 KWindowSystem::clearState( winId(), NET::Shaded
);
760 if( !isOnThisDesktop
)
762 KWindowSystem::setOnDesktop( winId(), desktop
);
765 else if( !info
.isMinimized() && !isShaded
) setVisible( !isVisible() );
767 if( isVisible() ) KWindowSystem::unminimizeWindow( winId() );
769 setVisible( !isVisible() );
773 void MainWindow::activate()
776 const KWindowInfo info
= KWindowSystem::windowInfo( winId(), 0, 0 );
778 if( KWindowSystem::activeWindow() != winId())
780 else if( !info
.isMinimized() )
783 KWindowSystem::activateWindow( winId() );
789 bool MainWindow::isReallyShown() const
792 const KWindowInfo info
= KWindowSystem::windowInfo( winId(), 0, 0 );
793 return !isHidden() && !info
.isMinimized() && info
.isOnDesktop( KWindowSystem::currentDesktop() );
799 void MainWindow::createActions()
801 KActionCollection
* const ac
= actionCollection();
802 const EngineController
* const ec
= EngineController::instance();
804 KStandardAction::keyBindings( kapp
, SLOT( slotConfigShortcuts() ), ac
);
805 KStandardAction::preferences( kapp
, SLOT( slotConfigAmarok() ), ac
);
806 ac
->action(KStandardAction::name(KStandardAction::KeyBindings
))->setIcon( KIcon( Amarok::icon( "configure" ) ) );
807 ac
->action(KStandardAction::name(KStandardAction::Preferences
))->setIcon( KIcon( Amarok::icon( "configure" ) ) );
809 KStandardAction::quit( kapp
, SLOT( quit() ), ac
);
811 KAction
*action
= new KAction( KIcon( Amarok::icon( "files" ) ), i18n("&Add Media..."), this );
812 connect( action
, SIGNAL( triggered(bool) ), this, SLOT( slotAddLocation() ) );
813 ac
->addAction( "playlist_add", action
);
815 action
= new KAction( KIcon( Amarok::icon( "playlist_clear" ) ), i18nc( "clear playlist", "&Clear" ), this );
816 connect( action
, SIGNAL( triggered( bool ) ), The::playlistModel(), SLOT( clear() ) );
817 ac
->addAction( "playlist_clear", action
);
819 action
= new KAction( KIcon( Amarok::icon( "files" ) ), i18n("&Add Stream..."), this );
820 connect( action
, SIGNAL( triggered(bool) ), this, SLOT( slotAddStream() ) );
821 ac
->addAction( "stream_add", action
);
823 action
= new KAction( KIcon( Amarok::icon( "save" ) ), i18n("&Save Playlist As..."), this );
824 connect( action
, SIGNAL( triggered(bool) ), this, SLOT( savePlaylist() ) );
825 ac
->addAction( "playlist_save", action
);
827 KAction
*burn
= new KAction( KIcon(Amarok::icon( "burn" )), i18n( "Burn Current Playlist" ), this );
828 connect( burn
, SIGNAL( triggered(bool) ), SLOT( slotBurnPlaylist() ) );
829 burn
->setEnabled( K3bExporter::isAvailable() );
830 ac
->addAction( "playlist_burn", burn
);
832 KAction
*covermanager
= new KAction( KIcon(Amarok::icon( "covermanager" )), i18n( "Cover Manager" ), this );
833 connect( covermanager
, SIGNAL( triggered(bool) ), SLOT( slotShowCoverManager() ) );
834 ac
->addAction( "cover_manager", covermanager
);
836 KAction
*visuals
= new KAction( KIcon( Amarok::icon("visualizations") ), i18n("&Visualizations"), this );
837 // connect( visuals, SIGNAL( triggered(bool) ), Vis::Selector::instance(), SLOT( show() ) );
838 ac
->addAction( "visualizations", visuals
);
840 KAction
*equalizer
= new KAction( KIcon( Amarok::icon( "equalizer" ) ), i18n( "E&qualizer"), this );
841 connect( equalizer
, SIGNAL( triggered(bool) ), kapp
, SLOT( slotConfigEqualizer() ) );
842 ac
->addAction( "equalizer", equalizer
);
844 KAction
*toggleToolbar
= new KAction( this );
845 toggleToolbar
->setText( i18n("Hide Toolbar") );
847 //FIXME m_controlBar is initialised after the actions are created so we need to change the text of this action
848 //when the menu is shown
849 //toggleToolbar->setText( !m_controlBar->isHidden() ? i18n("Hide Toolbar") : i18n("Show Toolbar") );
850 connect( toggleToolbar
, SIGNAL( triggered(bool) ), SLOT( slotToggleToolbar() ) );
851 ac
->addAction( "toggle_toolbar", toggleToolbar
);
853 // KAction *update_podcasts = new KAction( this );
854 // update_podcasts->setText( i18n( "Update Podcasts" ) );
855 // //update_podcasts->setIcon( KIcon(Amarok::icon( "refresh" )) );
856 // ac->addAction( "podcasts_update", update_podcasts );
857 // connect(update_podcasts, SIGNAL(triggered(bool)),
858 // The::podcastCollection(), SLOT(slotUpdateAll()));
860 KAction
*playact
= new KAction( KIcon(Amarok::icon( "files" )), i18n("Play Media..."), this );
861 connect(playact
, SIGNAL(triggered(bool)), SLOT(slotPlayMedia()));
862 ac
->addAction( "playlist_playmedia", playact
);
864 KAction
*acd
= new KAction( KIcon( Amarok::icon( "album" ) ), i18n("Play Audio CD"), this );
865 connect(acd
, SIGNAL(triggered(bool)), SLOT(playAudioCD()));
866 ac
->addAction( "play_audiocd", acd
);
868 KAction
*script
= new KAction( KIcon(Amarok::icon( "scripts" )), i18n("Script Manager"), this );
869 connect(script
, SIGNAL(triggered(bool)), SLOT(showScriptSelector()));
870 ac
->addAction( "script_manager", script
);
872 KAction
*queue
= new KAction( KIcon( Amarok::icon( "queue" )), i18n( "Queue Manager" ), this );
873 connect(queue
, SIGNAL(triggered(bool)), SLOT(showQueueManager()));
874 ac
->addAction( "queue_manager", queue
);
876 KAction
*seekForward
= new KAction( KIcon( Amarok::icon( "fastforward" ) ), i18n("&Seek Forward"), this );
877 seekForward
->setShortcut( Qt::Key_Right
);
878 connect(seekForward
, SIGNAL(triggered(bool)), ec
, SLOT(seekForward()));
879 ac
->addAction( "seek_forward", seekForward
);
881 KAction
*seekBackward
= new KAction( KIcon( Amarok::icon( "rewind" ) ), i18n("&Seek Backward"), this );
882 seekForward
->setShortcut( Qt::Key_Left
);
883 connect(seekForward
, SIGNAL(triggered(bool)), ec
, SLOT(seekBackward()));
884 ac
->addAction( "seek_backward", seekBackward
);
886 KAction
*statistics
= new KAction( KIcon(Amarok::icon( "info" )), i18n( "Statistics" ), this );
887 connect(statistics
, SIGNAL(triggered(bool)), SLOT(showStatistics()));
888 ac
->addAction( "statistics", statistics
);
890 KAction
*update
= new KAction( KIcon(Amarok::icon( "refresh")), i18n( "Update Collection" ), this );
891 connect(update
, SIGNAL(triggered(bool)), CollectionManager::instance(), SLOT(checkCollectionChanges()));
892 ac
->addAction( "update_collection", update
);
894 KAction
*rescan
= new KAction( KIcon(Amarok::icon( "rescan")), i18n( "Rescan Collection" ), this );
895 connect(rescan
, SIGNAL(triggered(bool)), CollectionManager::instance(), SLOT(startFullScan()));
896 rescan
->setEnabled( !ThreadManager::instance()->isJobPending( "CollectionScanner" ) );
897 ac
->addAction( "rescan_collection", rescan
);
899 m_lastfmTags
<< "Alternative" << "Ambient" << "Chill Out" << "Classical" << "Dance"
900 << "Electronica" << "Favorites" << "Heavy Metal" << "Hip Hop" << "Indie Rock"
901 << "Industrial" << "Japanese" << "Pop" << "Psytrance" << "Rap" << "Rock"
902 << "Soundtrack" << "Techno" << "Trance";
904 KMenu
* playTagRadioMenu
= new KMenu( this );
905 playTagRadioMenu
->setTitle( i18n( "Global Tag Radio" ) );
906 foreach( const QString
&lastfmTag
, m_lastfmTags
)
908 KAction
*lastfmAction
= new KAction( lastfmTag
, this );
909 connect( lastfmAction
, SIGNAL( triggered(bool) ), SLOT( playLastfmGlobaltag() ) );
910 playTagRadioMenu
->addAction( lastfmAction
);
913 KMenu
* addTagRadioMenu
= new KMenu( this );
914 addTagRadioMenu
->setTitle( i18n( "Global Tag Radio" ) );
915 foreach( const QString
&lastfmTag
, m_lastfmTags
)
917 KAction
*lastfmAction
= new KAction( lastfmTag
, this );
918 connect( lastfmAction
, SIGNAL( triggered(bool) ), SLOT( addLastfmGlobaltag() ) );
919 addTagRadioMenu
->addAction( lastfmAction
);
922 KActionMenu
* playLastfm
= new KActionMenu( KIcon(Amarok::icon("audioscrobbler")), i18n( "Play las&t.fm Stream" ), ac
);
923 KMenu
* playLastfmMenu
= playLastfm
->menu();
924 playLastfmMenu
->addAction( i18n( "Personal Radio" ), this, SLOT( playLastfmPersonal() ) );
925 playLastfmMenu
->addAction( i18n( "Neighbor Radio" ), this, SLOT( playLastfmNeighbor() ) );
926 playLastfmMenu
->addAction( i18n( "Custom Station" ), this, SLOT( playLastfmCustom() ) );
927 playLastfmMenu
->addMenu( playTagRadioMenu
);
928 ac
->addAction( "lastfm_play", playLastfm
);
930 KActionMenu
* addLastfm
= new KActionMenu( KIcon(Amarok::icon("audioscrobbler")), i18n( "Add las&t.fm Stream" ), ac
);
931 KMenu
* addLastfmMenu
= addLastfm
->menu();
932 addLastfmMenu
->addAction( i18n( "Personal Radio" ), this, SLOT( addLastfmPersonal() ) );
933 addLastfmMenu
->addAction( i18n( "Neighbor Radio" ), this, SLOT( addLastfmNeighbor() ) );
934 addLastfmMenu
->addAction( i18n( "Custom Station" ), this, SLOT( addLastfmCustom() ) );
935 addLastfmMenu
->addMenu( addTagRadioMenu
);
936 ac
->addAction( "lastfm_add", addLastfm
);
938 KAction
*previous
= new KAction( this );
939 previous
->setIcon( KIcon(Amarok::icon( "back" )) );
940 previous
->setText( i18n( "Previous Track" ) );
941 ac
->addAction( "prev", previous
);
942 connect( previous
, SIGNAL(triggered(bool)), The::playlistModel(), SLOT( back() ) );
944 KAction
*play
= new KAction( this );
945 play
->setIcon( KIcon(Amarok::icon( "play" )) );
946 play
->setText( i18n( "Play" ) );
947 ac
->addAction( "play", play
);
948 connect( play
, SIGNAL(triggered(bool)), ec
, SLOT( play() ));
950 KAction
*pause
= new KAction( this );
951 pause
->setIcon( KIcon(Amarok::icon( "pause" )) );
952 pause
->setText( i18n( "Pause" ));
953 ac
->addAction( "pause", pause
);
954 connect( pause
, SIGNAL(triggered(bool)), ec
, SLOT( pause() ) );
956 KAction
*next
= new KAction( this );
957 next
->setIcon( KIcon(Amarok::icon( "next" )) );
958 next
->setText( i18n( "Next Track" ) );
959 ac
->addAction( "next", next
);
960 connect( next
, SIGNAL(triggered(bool)), The::playlistModel(), SLOT( next() ) );
962 KAction
*toggleFocus
= new KAction(i18n( "Toggle Focus" ), ac
);
963 toggleFocus
->setShortcut( Qt::ControlModifier
+ Qt::Key_Tab
);
964 connect( toggleFocus
, SIGNAL(triggered(bool)), SLOT( slotToggleFocus() ));
966 new Amarok::MenuAction( ac
);
967 new Amarok::StopAction( ac
);
968 new Amarok::PlayPauseAction( ac
);
969 new Amarok::RepeatAction( ac
);
970 new Amarok::RandomAction( ac
);
971 new Amarok::FavorAction( ac
);
973 if( K3bExporter::isAvailable() )
974 new Amarok::BurnMenuAction( ac
);
976 ac
->associateWidget( this );
979 void MainWindow::createMenus()
981 m_menubar
= menuBar();//new MenuBar( this );
984 KMenu
*actionsMenu
= new KMenu( m_menubar
);
985 actionsMenu
->setTitle( i18n("&Amarok") );
986 actionsMenu
->addAction( actionCollection()->action("playlist_playmedia") );
987 actionsMenu
->addAction( actionCollection()->action("lastfm_play") );
988 actionsMenu
->addAction( actionCollection()->action("play_audiocd") );
989 actionsMenu
->addSeparator();
990 actionsMenu
->addAction( actionCollection()->action("prev") );
991 actionsMenu
->addAction( actionCollection()->action("play_pause") );
992 actionsMenu
->addAction( actionCollection()->action("stop") );
993 actionsMenu
->addAction( actionCollection()->action("next") );
994 actionsMenu
->addSeparator();
995 actionsMenu
->addAction( actionCollection()->action(KStandardAction::name(KStandardAction::Quit
)) );
998 //BEGIN Playlist menu
999 KMenu
*playlistMenu
= new KMenu( m_menubar
);
1000 playlistMenu
->setTitle( i18n("&Playlist") );
1001 playlistMenu
->addAction( actionCollection()->action("playlist_add") );
1002 playlistMenu
->addAction( actionCollection()->action("stream_add") );
1003 playlistMenu
->addAction( actionCollection()->action("lastfm_add") );
1004 playlistMenu
->addAction( actionCollection()->action("playlist_save") );
1005 playlistMenu
->addAction( actionCollection()->action("playlist_burn") );
1006 playlistMenu
->addAction( actionCollection()->action("podcasts_update") );
1007 playlistMenu
->addSeparator();
1008 playlistMenu
->addAction( actionCollection()->action("playlist_undo") );
1009 playlistMenu
->addAction( actionCollection()->action("playlist_redo") );
1010 playlistMenu
->addSeparator();
1011 playlistMenu
->addAction( actionCollection()->action("playlist_clear") );
1012 playlistMenu
->addAction( actionCollection()->action("playlist_shuffle") );
1014 playlistMenu
->addSeparator();
1015 playlistMenu
->addAction( actionCollection()->action("queue_selected") );
1016 playlistMenu
->addAction( actionCollection()->action("playlist_remove_duplicates") );
1017 playlistMenu
->addAction( actionCollection()->action("playlist_select_all") );
1022 KMenu
*modeMenu
= new KMenu( m_menubar
);
1023 modeMenu
->setTitle( i18n("&Mode") );
1024 QAction
*repeat
= actionCollection()->action("repeat");
1025 connect( repeat
, SIGNAL(triggered( int ) ), The::playlistModel(), SLOT(playlistRepeatMode(int) ) );
1026 modeMenu
->addAction( repeat
);
1027 KSelectAction
*random
= static_cast<KSelectAction
*>( actionCollection()->action("random_mode") );
1028 modeMenu
->addAction( random
);
1029 random
->menu()->addSeparator();
1030 random
->menu()->addAction( actionCollection()->action("favor_tracks") );
1034 m_toolsMenu
= new KMenu( m_menubar
);
1035 m_toolsMenu
->setTitle( i18n("&Tools") );
1036 m_toolsMenu
->addAction( actionCollection()->action("cover_manager") );
1037 m_toolsMenu
->addAction( actionCollection()->action("queue_manager") );
1038 m_toolsMenu
->addAction( actionCollection()->action("visualizations") );
1039 m_toolsMenu
->addAction( actionCollection()->action("equalizer") );
1040 m_toolsMenu
->addAction( actionCollection()->action("script_manager") );
1041 m_toolsMenu
->addAction( actionCollection()->action("statistics") );
1042 m_toolsMenu
->addSeparator();
1043 m_toolsMenu
->addAction( actionCollection()->action("update_collection") );
1044 m_toolsMenu
->addAction( actionCollection()->action("rescan_collection") );
1046 #ifndef HAVE_LIBVISUAL
1047 actionCollection()->action( "visualizations" )->setEnabled( false );
1050 connect( m_toolsMenu
, SIGNAL( aboutToShow() ), SLOT( toolsMenuAboutToShow() ) );
1051 connect( m_toolsMenu
, SIGNAL( activated(int) ), SLOT( slotMenuActivated(int) ) );
1054 //BEGIN Settings menu
1055 m_settingsMenu
= new KMenu( m_menubar
);
1056 m_settingsMenu
->setTitle( i18n("&Settings") );
1057 //TODO use KStandardAction or KXmlGuiWindow
1059 m_settingsMenu
->addAction( actionCollection()->action( "toggle_toolbar" ) );
1060 m_settingsMenu
->addSeparator();
1064 // plug it first, as this item will be moved to the applications first menu
1065 m_settingsMenu
->addAction( actionCollection()->action(KStandardAction::name(KStandardAction::Preferences
)) );
1067 // m_settingsMenu->addAction( actionCollection()->action("options_configure_globals") );
1068 m_settingsMenu
->addAction( actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings
)) );
1069 m_settingsMenu
->addAction( actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)) );
1070 m_settingsMenu
->addAction( actionCollection()->action(KStandardAction::name(KStandardAction::Preferences
)) );
1072 connect( m_settingsMenu
, SIGNAL( activated(int) ), SLOT( slotMenuActivated(int) ) );
1075 m_menubar
->addMenu( actionsMenu
);
1076 m_menubar
->addMenu( playlistMenu
);
1077 m_menubar
->addMenu( modeMenu
);
1078 m_menubar
->addMenu( m_toolsMenu
);
1079 m_menubar
->addMenu( m_settingsMenu
);
1080 m_menubar
->addMenu( Amarok::Menu::helpMenu() );
1085 #include "MainWindow.moc"