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/ControlBox.h"
28 #include "context/DataEngineManager.h"
29 #include "covermanager.h" // for actions
31 #include "editfilterdialog.h"
32 #include "enginecontroller.h" //for actions in ctor
33 #include "filebrowser.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"
41 #include "progressslider.h"
42 #include "scriptmanager.h"
43 #include "searchwidget.h"
44 #include "selectLabel.h"
45 #include "servicebrowser/magnatunestore/MagnatuneStore.h"
46 #include "servicebrowser/scriptableservice/scriptableservice.h"
47 #include "servicebrowser/servicebrowser.h"
48 #include "servicebrowser/jamendo/jamendoservice.h"
49 #include "servicebrowser/shoutcast/ShoutcastService.h"
50 //#include "servicebrowser/mp3tunes/mp3tunesservice.h"
52 #include "Sidebar.moc"
53 #include "socketserver.h"
54 #include "Statistics.h"
55 #include "statusbar.h"
56 #include "TheInstances.h"
57 #include "threadmanager.h"
59 #include "volumewidget.h"
60 #include "PodcastCollection.h"
61 #include "playlistmanager/PlaylistManager.h"
63 #include "playlistbrowser/PlaylistBrowser.h"
65 #include "queuemanager/QueueManager.h"
68 #include <QHeaderView>
69 #include <QLabel> //search filter label
71 #include <QPainter> //dynamic title
73 #include <QTimer> //search filter timer
74 #include <QToolTip> //QToolTip::add()
75 #include <QVBoxLayout>
77 #include <KAction> //m_actionCollection
78 #include <KActionCollection>
79 #include <KActionMenu>
80 #include <kapplication.h> //kapp
81 #include <kfiledialog.h> //savePlaylist(), openPlaylist()
83 #include <kinputdialog.h> //slotAddStream()
86 #include <kmessagebox.h> //savePlaylist()
88 #include <kpushbutton.h>
89 #include <kstandarddirs.h> //Welcome Tab, locate welcome.html
90 #include <kstatusbar.h>
92 #include <ktoolbarspaceraction.h>
94 #include <kxmlguibuilder.h> //XMLGUI
95 #include <kxmlguifactory.h> //XMLGUI
98 MainWindow
*MainWindow::s_instance
= 0;
100 MainWindow::MainWindow()
101 :KXmlGuiWindow( 0, Qt::WGroupLeader
)
104 setObjectName("MainWindow");
107 new Playlist::Model( this );
109 // Sets caption and icon correctly (needed e.g. for GNOME)
110 kapp
->setTopWidget( this );
116 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()
127 AmarokConfig::setMainWindowPos( pos() ); //TODO de XT?
128 AmarokConfig::setMainWindowSize( size() ); //TODO de XT?
132 ///////// public interface
135 * This function will initialize the playlist window.
137 void MainWindow::init()
139 layout()->setContentsMargins( 0, 0, 0, 0 );
142 //this function is necessary because Amarok::actionCollection() returns our actionCollection
143 //via the App::m_pMainWindow pointer since App::m_pMainWindow is not defined until
144 //the above ctor returns it causes a crash unless we do the initialisation in 2 stages.
145 KVBox
*playlistwindow
= new KVBox
;
146 playlistwindow
->setMaximumSize( QSize( 300, 7000 ) );
147 playlistwindow
->setMinimumSize( QSize( 250, 100 ) );
148 playlistwindow
->setSizePolicy( QSizePolicy::Fixed
, QSizePolicy::Expanding
);
150 new Playlist::Widget( playlistwindow
);
152 KToolBar
*plBar
= new Amarok::ToolBar( playlistwindow
);
153 plBar
->setObjectName( "PlaylistToolBar" );
156 { //START Playlist toolbar
157 plBar
->setToolButtonStyle( Qt::ToolButtonIconOnly
);
158 plBar
->setSizePolicy( QSizePolicy::Preferred
, QSizePolicy::Preferred
);
159 plBar
->setIconDimensions( 22 );
160 plBar
->setMovable( false );
161 plBar
->addAction( new KToolBarSpacerAction( this ) );
162 plBar
->addAction( actionCollection()->action( "playlist_clear") );
163 plBar
->addAction( actionCollection()->action( "playlist_save") );
164 plBar
->addSeparator();
165 plBar
->addAction( actionCollection()->action( "playlist_undo") );
166 plBar
->addAction( actionCollection()->action( "playlist_redo") );
167 plBar
->addSeparator();
168 plBar
->addWidget( new SelectLabel( static_cast<Amarok::SelectAction
*>( actionCollection()->action("repeat") ), plBar
) );
169 plBar
->addWidget( new SelectLabel( static_cast<Amarok::SelectAction
*>( actionCollection()->action("random_mode") ), plBar
) );
170 plBar
->addAction( new KToolBarSpacerAction( this ) );
171 } //END Playlist Toolbar
174 m_controlBar
= new KHBox( this );
175 m_controlBar
->setMaximumSize( 20000, 62 );
176 m_controlBar
->setSizePolicy( QSizePolicy::Expanding
, QSizePolicy::Preferred
);
178 AnalyzerWidget
*aw
= new AnalyzerWidget( m_controlBar
);
179 aw
->setMinimumSize( 200, 30 );
181 m_controlBar
->layout()->setAlignment( aw
, Qt::AlignLeft
);
183 KVBox
*aVBox
= new KVBox( m_controlBar
);
184 aVBox
->setMaximumSize( 50000, 60 );
186 KHBox
*insideBox
= new KHBox( aVBox
);
187 insideBox
->setMaximumSize( 600000, 45 );
189 KToolBar
*playerControlsToolbar
= new Amarok::ToolBar( insideBox
);
191 playerControlsToolbar
->setMinimumSize( 200, 45 );
192 insideBox
->layout()->setAlignment( playerControlsToolbar
, Qt::AlignRight
);
194 VolumeWidget
*vw
= new VolumeWidget( insideBox
);
195 vw
->setMinimumSize( 200, 25 );
196 insideBox
->layout()->setAlignment( vw
, Qt::AlignRight
);
198 ProgressWidget
*pWidget
= new ProgressWidget( aVBox
);
199 pWidget
->setMinimumSize( 400, 17 );
200 pWidget
->setMaximumSize( 600000, 17 );
202 playerControlsToolbar
->setToolButtonStyle( Qt::ToolButtonIconOnly
);
203 playerControlsToolbar
->setSizePolicy( QSizePolicy::Preferred
, QSizePolicy::Preferred
);
204 playerControlsToolbar
->setIconDimensions( 32 );
205 playerControlsToolbar
->setMovable( false );
206 playerControlsToolbar
->addAction( actionCollection()->action( "prev" ) );
207 playerControlsToolbar
->addAction( actionCollection()->action( "play_pause" ) );
208 playerControlsToolbar
->addAction( actionCollection()->action( "stop" ) );
209 playerControlsToolbar
->addAction( actionCollection()->action( "next" ) );
214 QColor topColor
= bottomColor
= palette().highlight().color().dark( 150 );
215 bottomColor
= bottomColor
.dark( 100 );
216 topColor
.setAlpha( 75 );
217 bottomColor
.setAlpha( 130 );
219 QLinearGradient
toolbarGradiant( m_controlBar
->contentsRect().topLeft(),
220 m_controlBar
->contentsRect().bottomLeft() );
221 toolbarGradiant
.setColorAt( .8, topColor
);
222 toolbarGradiant
.setColorAt( 1, bottomColor
);
223 QBrush
b( toolbarGradiant
);
224 p
.setBrush( QPalette::Window
, b
);
226 m_controlBar
->setAutoFillBackground( true );
227 m_controlBar
->setPalette( p
);
229 this->toolBars().clear();
234 QWidget
*contextWidget
= new QWidget( this );
235 contextWidget
->setMinimumSize( QSize(500,100) );
236 contextWidget
->setSizePolicy( QSizePolicy::Expanding
, QSizePolicy::Expanding
);
237 new Context::ContextView( contextWidget
);
239 QVBoxLayout
* layout
= new QVBoxLayout( contextWidget
);
240 layout
->setContentsMargins( 0, 0, 0, 0 );
241 layout
->addWidget( Context::ContextView::self() );
242 Amarok::StatusBar
*statusbar
= new Amarok::StatusBar( contextWidget
);
243 layout
->addWidget( statusbar
);
245 if( AmarokConfig::useCoverBling() && QGLFormat::hasOpenGL() )
246 layout
->addWidget( new CoverBling( this ) );
248 ControlBox
* controlBox
= new ControlBox( contextWidget
);
250 // TODO fix the location of the controlbox so its not a few pixels out of the
252 connect( controlBox
, SIGNAL(zoomIn()), Context::ContextView::self(), SLOT(zoomIn()) );
253 connect( controlBox
, SIGNAL(zoomOut()), Context::ContextView::self(), SLOT(zoomOut()) );
254 connect( controlBox
, SIGNAL(addApplet(const QString
&)), Context::ContextView::self(), SLOT(addApplet(const QString
&)) );
255 connect( controlBox
, SIGNAL(lockInterface(bool)), Context::ContextView::self()->contextScene(), SLOT(setImmutable(bool)) );
258 m_browsers
->setMaximumSize( QSize(300,7000) );
259 connect( m_browsers
, SIGNAL( widgetActivated( int ) ), SLOT( slotShrinkBrowsers( int ) ) );
261 QVBoxLayout
*mainLayout
= new QVBoxLayout
;
262 mainLayout
->setContentsMargins( 0, 0, 0, 0 );
264 QWidget
*centralWidget
= new QWidget( this );
265 centralWidget
->setLayout( mainLayout
);
267 m_splitter
= new QSplitter( Qt::Horizontal
, centralWidget
);
268 m_splitter
->setHandleWidth( 0 );
269 m_splitter
->addWidget( m_browsers
);
270 m_splitter
->addWidget( contextWidget
);
271 m_splitter
->addWidget( playlistwindow
);
273 mainLayout
->addWidget( m_controlBar
);
274 mainLayout
->addWidget( m_splitter
);
275 setCentralWidget( centralWidget
);
279 Debug::Block
block( "Creating browsers. Please report long start times!" );
281 #define addBrowserMacro( Type, name, text, icon ) { \
282 Debug::Block block( name ); \
283 m_browsers->addWidget( KIcon( icon ), text, new Type( name ) ); \
284 m_browserNames.append( name ); }
286 #define addInstBrowserMacro( Type, name, text, icon ) { \
287 m_browsers->addWidget( KIcon( icon ), text, Type::instance() ); \
288 m_browserNames.append( name ); }
290 addBrowserMacro( CollectionWidget
, "CollectionBrowser", i18n("Collection"), Amarok::icon( "collection" ) )
291 //FIXME: figure this out
292 //m_browsers->makeDropProxy( "CollectionBrowser", CollectionView::instance() );
294 addBrowserMacro( PlaylistBrowserNS::PlaylistBrowser
, "NeoPlaylistBrowser", i18n("Playlists"), Amarok::icon( "playlist" ) )
296 PodcastCollection
*podcastCollection
= new PodcastCollection();
297 The::playlistManager()->addProvider( podcastCollection
->channelProvider(), PlaylistManager::PodcastChannel
);
299 //DEBUG: Comment out the addBrowserMacro line and uncomment the m_browsers line (passing in a vfat device name) to see the "virtual root" functionality
304 //addBrowserMacro( FileBrowser, "FileBrowser", i18n("Files"), Amarok::icon( "files" ) )
305 //Add Magnatune browser
306 //addInstBrowserMacro( MagnatuneStore, "MagnatuneStore", i18n("Magnatune"), Amarok::icon( "magnatune" ) )
309 //cant use macros here since we need access to the browsers directly
310 // ServiceBrowser * storeServiceBrowser = new ServiceBrowser(this, "Stores" );;
311 //m_browsers->addWidget( KIcon( Amarok::icon( "magnatune" ) ), i18n("Stores"), storeServiceBrowser );
312 //m_browserNames.append( "Stores" );
315 ServiceBrowser
* internetContentServiceBrowser
= new ServiceBrowser(this, "Internet Content" );;
316 m_browsers
->addWidget( KIcon( Amarok::icon( "magnatune" ) ), i18n("Internet"), internetContentServiceBrowser
);
317 m_browserNames
.append( "Internet" );
319 debug() << "Add me dammit!!!!!";
320 internetContentServiceBrowser
->setScriptableServiceManager( new ScriptableServiceManager( 0 ) );
322 internetContentServiceBrowser
->addService( new MagnatuneStore( "Dummy service 1" ) );
324 internetContentServiceBrowser
->addService( new JamendoService( "Jamendo.com" ) );
326 internetContentServiceBrowser
->addService( new ShoutcastService( "Shoutcasst Directory" ) );
329 //internetContentServiceBrowser->addService( new Mp3tunesService( "Mp3tunes.com" ) );
331 //addInstBrowserMacro( ServiceBrowser, "Stores", i18n("Stores"), Amarok::icon( "magnatune" ) ) //FIXME: icon
332 //addInstBrowserMacro( ServiceBrowser, "Internet Content", i18n("Internet Content"), Amarok::icon( "magnatune" ) ) //FIXME: icon
334 new MediaBrowser( "MediaBrowser" );
335 if( MediaBrowser::isAvailable() )
337 addInstBrowserMacro( MediaBrowser
, "MediaBrowser", i18n("Devices"), Amarok::icon( "device" ) )
338 //to re-enable mediabrowser hiding, uncomment this:
339 //connect( MediaBrowser::instance(), SIGNAL( availabilityChanged( bool ) ),
340 // this, SLOT( mbAvailabilityChanged( bool ) ) );
341 //FIXME: figure this out
342 //m_browsers->makeDropProxy( "MediaBrowser", MediaBrowser::queue() );
345 #undef addBrowserMacro
346 #undef addInstBrowserMacro
351 kapp
->installEventFilter( this ); // keyboards shortcuts for the browsers
353 Amarok::MessageQueue::instance()->sendMessages();
356 void MainWindow::slotSetFilter( const QString
&filter
) //SLOT
359 // m_lineEdit->setText( filter );
362 void MainWindow::slotShrinkBrowsers( int index
) const
364 // Because QSplitter sucks and will not recompute sizes if a pane is shrunk and not hidden.
368 sizes
<< m_browsers
->sideBarWidget()->width()
369 << m_splitter
->sizes()[1] + m_splitter
->sizes()[0] - m_browsers
->sideBarWidget()->width()
370 << m_splitter
->sizes()[2];
371 m_splitter
->setSizes( sizes
);
375 // void MainWindow::slotEditFilter() //SLOT
377 // EditFilterDialog *fd = new EditFilterDialog( this, true, "" );
378 // connect( fd, SIGNAL(filterChanged(const QString &)), SLOT(slotSetFilter(const QString &)) );
380 // m_searchWidget->lineEdit()->setText( fd->filter() );
384 void MainWindow::addBrowser( const QString
&name
, QWidget
*browser
, const QString
&text
, const QString
&icon
)
386 if( !m_browserNames
.contains( name
) )
388 m_browsers
->addWidget( KIcon(Amarok::icon( icon
)), text
, browser
);
389 m_browserNames
.append( name
);
393 void MainWindow::showBrowser( const QString
&name
)
395 const int index
= m_browserNames
.indexOf( name
);
397 m_browsers
->showWidget( index
);
402 * @param o The object
405 * Here we filter some events for the Playlist Search LineEdit and the Playlist. @n
406 * this makes life easier since we have more useful functions available from this class
408 bool MainWindow::eventFilter( QObject
*o
, QEvent
*e
)
410 typedef Q3ListViewItemIterator It
;
414 case 6/*QEvent::KeyPress*/:
416 //there are a few keypresses that we intercept
418 #define e static_cast<QKeyEvent*>(e)
421 // if( e->key() == Qt::Key_F2 )
423 // // currentItem is ALWAYS visible.
424 // Q3ListViewItem *item = pl->currentItem();
426 // // intercept F2 for inline tag renaming
427 // // NOTE: tab will move to the next tag
428 // // NOTE: if item is still null don't select first item in playlist, user wouldn't want that. It's silly.
429 // // TODO: berkus has solved the "inability to cancel" issue with K3ListView, but it's not in kdelibs yet..
431 // // item may still be null, but this is safe
432 // // NOTE: column 0 cannot be edited currently, hence we pick column 1
433 // pl->rename( item, 1 ); //TODO what if this column is hidden?
439 // if( o == m_searchWidget->lineEdit() ) //the search lineedit
441 // Q3ListViewItem *item;
442 // switch( e->key() )
445 // case Qt::Key_Down:
446 // case Qt::Key_PageDown:
447 // case Qt::Key_PageUp:
449 // QApplication::sendEvent( pl, e );
452 // case Qt::Key_Return:
453 // case Qt::Key_Enter:
454 // item = *It( pl, It::Visible );
455 // //m_lineEdit->clear();
456 // pl->m_filtertimer->stop(); //HACK HACK HACK
458 // if( e->modifiers() & Qt::ControlModifier )
460 // QList<PlaylistItem*> in, out;
461 // if( e->modifiers() & Qt::ShiftModifier )
462 // for( It it( pl, It::Visible ); PlaylistItem *x = static_cast<PlaylistItem*>( *it ); ++it )
464 // pl->queue( x, true );
465 // ( pl->m_nextTracks.contains( x ) ? in : out ).append( x );
469 // It it( pl, It::Visible );
470 // pl->activate( *it );
472 // for( int i = 0; PlaylistItem *x = static_cast<PlaylistItem*>( *it ); ++i, ++it )
475 // pl->m_nextTracks.insert( i, x );
478 // if( !in.isEmpty() || !out.isEmpty() )
479 // emit pl->queueChanged( in, out );
480 // pl->setFilter( "" );
481 // pl->ensureItemCentered( ( e->modifiers() & Qt::ShiftModifier ) ? item : pl->currentTrack() );
485 // pl->setFilter( "" );
486 // if( ( e->modifiers() & Qt::ShiftModifier ) && item )
488 // pl->queue( item );
489 // pl->ensureItemCentered( item );
493 // pl->activate( item );
494 // pl->showCurrentTrack();
499 // case Qt::Key_Escape:
500 // m_searchWidget->lineEdit()->clear();
508 //following are for Playlist::instance() only
509 //we don't handle these in the playlist because often we manipulate the lineEdit too
518 return QWidget::eventFilter( o
, e
);
522 void MainWindow::closeEvent( QCloseEvent
*e
)
528 Amarok::genericEventHandler( this, e
);
533 void MainWindow::showEvent( QShowEvent
* )
536 // static bool firstTime = true;
538 // Playlist::instance()->setFocus();
539 // firstTime = false;
542 #include <qdesktopwidget.h>
543 QSize
MainWindow::sizeHint() const
545 return QApplication::desktop()->screenGeometry( (QWidget
*)this ).size() / 1.5;
549 void MainWindow::savePlaylist() const //SLOT
552 // Playlist *pl = Playlist::instance();
554 // PlaylistItem *item = pl->firstChild();
555 // if( item && !item->isVisible() )
556 // item = static_cast<PlaylistItem*>( item->itemBelow() );
558 // QString title = pl->playlistName();
560 // if( item && title == i18n( "Untitled" ) )
562 // QString artist = item->artist();
563 // QString album = item->album();
565 // bool useArtist = true, useAlbum = true;
567 // item = static_cast<PlaylistItem*>( item->itemBelow() );
569 // for( ; item; item = static_cast<PlaylistItem*>( item->itemBelow() ) )
571 // if( artist != item->artist() )
572 // useArtist = false;
573 // if( album != item->album() )
576 // if( !useArtist && !useAlbum )
580 // if( useArtist && useAlbum )
581 // title = i18n("%1 - %2", artist, album );
582 // else if( useArtist )
584 // else if( useAlbum )
588 // QString path = PlaylistDialog::getSaveFileName( title, pl->proposeOverwriteOnSave() );
590 // if( !path.isEmpty() && Playlist::instance()->saveM3U( path ) )
591 // MainWindow::self()->showBrowser( "PlaylistBrowser" );
595 void MainWindow::slotBurnPlaylist() const //SLOT
597 K3bExporter::instance()->exportCurrentPlaylist();
600 void MainWindow::slotShowCoverManager() const //SLOT
602 CoverManager::showOnce();
605 void MainWindow::slotPlayMedia() //SLOT
607 // Request location and immediately start playback
608 slotAddLocation( true );
612 void MainWindow::slotAddLocation( bool directPlay
) //SLOT
614 // open a file selector to add media to the playlist
616 //files = KFileDialog::getOpenUrls( QString::null, "*.*|" + i18n("All Files"), this, i18n("Add Media") );
617 KFileDialog
dlg( KUrl(QString()), QString("*.*|"), this );
618 dlg
.setCaption( directPlay
? i18n("Play Media (Files or URLs)") : i18n("Add Media (Files or URLs)") );
619 dlg
.setMode( KFile::Files
| KFile::Directory
);
621 files
= dlg
.selectedUrls();
622 if( files
.isEmpty() ) return;
623 const int options
= directPlay
? Playlist::Append
| Playlist::DirectPlay
: Playlist::Append
;
625 Meta::TrackList tracks
= CollectionManager::instance()->tracksForUrls( files
);
627 The::playlistModel()->insertOptioned( tracks
.takeFirst(), options
);
629 foreach( Meta::TrackPtr track
, tracks
)
631 The::playlistModel()->insertOptioned( track
, Playlist::Append
);
635 void MainWindow::slotAddStream() //SLOT
638 QString url
= KInputDialog::getText( i18n("Add Stream"), i18n("URL"), QString(), &ok
, this );
642 Meta::TrackPtr track
= CollectionManager::instance()->trackForUrl( KUrl( url
) );
644 The::playlistModel()->insertOptioned( track
, Playlist::Append
|Playlist::DirectPlay
);
648 void MainWindow::playLastfmPersonal() //SLOT
650 if( !LastFm::Controller::checkCredentials() ) return;
652 const KUrl
url( QString( "lastfm://user/%1/personal" )
653 .arg( AmarokConfig::scrobblerUsername() ) );
655 Meta::TrackPtr track
= CollectionManager::instance()->trackForUrl( url
);
657 The::playlistModel()->insertOptioned( track
, Playlist::Append
|Playlist::DirectPlay
);
661 void MainWindow::addLastfmPersonal() //SLOT
663 if( !LastFm::Controller::checkCredentials() ) return;
665 const KUrl
url( QString( "lastfm://user/%1/personal" )
666 .arg( AmarokConfig::scrobblerUsername() ) );
668 Meta::TrackPtr track
= CollectionManager::instance()->trackForUrl( url
);
670 The::playlistModel()->insertOptioned( track
, Playlist::Append
);
674 void MainWindow::playLastfmNeighbor() //SLOT
676 if( !LastFm::Controller::checkCredentials() ) return;
678 const KUrl
url( QString( "lastfm://user/%1/neighbours" )
679 .arg( AmarokConfig::scrobblerUsername() ) );
681 Meta::TrackPtr track
= CollectionManager::instance()->trackForUrl( url
);
683 The::playlistModel()->insertOptioned( track
, Playlist::Append
);
687 void MainWindow::addLastfmNeighbor() //SLOT
689 if( !LastFm::Controller::checkCredentials() ) return;
691 const KUrl
url( QString( "lastfm://user/%1/neighbours" )
692 .arg( AmarokConfig::scrobblerUsername() ) );
694 Meta::TrackPtr track
= CollectionManager::instance()->trackForUrl( url
);
696 The::playlistModel()->insertOptioned( track
, Playlist::Append
);
700 void MainWindow::playLastfmCustom() //SLOT
702 const QString token
= LastFm::Controller::createCustomStation();
703 if( token
.isEmpty() ) return;
705 const KUrl
url( "lastfm://artist/" + token
+ "/similarartists" );
706 Meta::TrackPtr track
= CollectionManager::instance()->trackForUrl( url
);
708 The::playlistModel()->insertOptioned( track
, Playlist::Append
|Playlist::DirectPlay
);
712 void MainWindow::addLastfmCustom() //SLOT
714 const QString token
= LastFm::Controller::createCustomStation();
715 if( token
.isEmpty() ) return;
717 const KUrl
url( "lastfm://artist/" + token
+ "/similarartists" );
718 Meta::TrackPtr track
= CollectionManager::instance()->trackForUrl( url
);
720 The::playlistModel()->insertOptioned( track
, Playlist::Append
);
724 void MainWindow::playLastfmGlobaltag() //SLOT
726 if( !LastFm::Controller::checkCredentials() ) return;
728 KAction
*action
= dynamic_cast<KAction
*>( sender() );
729 if( !action
) return;
731 const QString tag
= action
->text();
732 const KUrl
url( "lastfm://globaltags/" + tag
);
733 Meta::TrackPtr track
= CollectionManager::instance()->trackForUrl( url
);
735 The::playlistModel()->insertOptioned( track
, Playlist::Append
|Playlist::DirectPlay
);
739 void MainWindow::addLastfmGlobaltag() //SLOT
741 if( !LastFm::Controller::checkCredentials() ) return;
743 KAction
*action
= dynamic_cast<KAction
*>( sender() );
744 if( !action
) return;
746 const QString tag
= action
->text();
747 const KUrl
url( "lastfm://globaltags/" + tag
);
748 Meta::TrackPtr track
= CollectionManager::instance()->trackForUrl( url
);
750 The::playlistModel()->insertOptioned( track
, Playlist::Append
);
754 void MainWindow::playAudioCD() //SLOT
757 if( EngineController::engine()->getAudioCDContents(QString(), urls
) )
759 Meta::TrackList tracks
= CollectionManager::instance()->tracksForUrls( urls
);
760 if( !tracks
.isEmpty() )
761 The::playlistModel()->insertOptioned( tracks
, Playlist::Replace
);
764 { // Default behaviour
765 showBrowser( "FileBrowser" );
766 //FileBrowser *fb = static_cast<FileBrowser *>( m_browsers->at( m_browserNames.indexOf( "FileBrowser" ) ) );
767 //fb->setUrl( KUrl("audiocd:/Wav/") );
771 void MainWindow::showScriptSelector() //SLOT
773 ScriptManager::instance()->show();
774 ScriptManager::instance()->raise();
777 void MainWindow::showQueueManager() //SLOT
779 if( QueueManagerNS::QueueManager::instance() )
781 QueueManagerNS::QueueManager::instance()->raise();
785 QueueManagerNS::QueueManager dialog
;
786 if( dialog
.exec() == QDialog::Accepted
)
792 void MainWindow::showStatistics() //SLOT
794 if( Statistics::instance() ) {
795 Statistics::instance()->raise();
802 void MainWindow::slotToggleFocus() //SLOT
805 // if( m_browsers->currentWidget() && ( Playlist::instance()->hasFocus() /*|| m_searchWidget->lineEdit()->hasFocus()*/ ) )
806 // m_browsers->currentWidget()->setFocus();
809 void MainWindow::slotToggleToolbar() //SLOT
811 m_controlBar
->setVisible( !m_controlBar
->isHidden() );
812 AmarokConfig::setShowToolbar( !AmarokConfig::showToolbar() );
813 Amarok::actionCollection()->action( "toggle_toolbar" )->setText( !m_controlBar
->isHidden() ? i18n("Hide Toolbar") : i18n("Show Toolbar") );
816 void MainWindow::toolsMenuAboutToShow() //SLOT
818 Amarok::actionCollection()->action( "equalizer" )->setEnabled( !EngineController::hasEngineProperty( "HasEqualizer" ) );
819 Amarok::actionCollection()->action( "rescan_collection" )->setEnabled( !ThreadManager::instance()->isJobPending( "CollectionScanner" ) );
823 #include <kwindowsystem.h>
825 * Show/hide playlist global shortcut and PlayerWindow PlaylistButton connect to this slot
827 * 1. hidden & iconified -> deiconify & show @n
828 * 2. hidden & deiconified -> show @n
829 * 3. shown & iconified -> deiconify @n
830 * 4. shown & deiconified -> hide @n
831 * 5. don't hide if there is no tray icon or playerWindow. todo (I can't be arsed) @n
833 * @note isMinimized() can only be true if the window isVisible()
834 * this has taken me hours to get right, change at your peril!
835 * there are more contingencies than you can believe
837 void MainWindow::showHide() //SLOT
840 const KWindowInfo info
= KWindowSystem::windowInfo( winId(), 0, 0 );
841 const uint desktop
= KWindowSystem::currentDesktop();
842 const bool isOnThisDesktop
= info
.isOnDesktop( desktop
);
843 const bool isShaded
= false;
847 KWindowSystem::clearState( winId(), NET::Shaded
);
851 if( !isOnThisDesktop
)
853 KWindowSystem::setOnDesktop( winId(), desktop
);
856 else if( !info
.isMinimized() && !isShaded
) setVisible( !isVisible() );
858 if( isVisible() ) KWindowSystem::unminimizeWindow( winId() );
860 setVisible( !isVisible() );
864 void MainWindow::activate()
867 const KWindowInfo info
= KWindowSystem::windowInfo( winId(), 0, 0 );
869 if( KWindowSystem::activeWindow() != winId())
871 else if( !info
.isMinimized() )
874 KWindowSystem::activateWindow( winId() );
880 bool MainWindow::isReallyShown() const
883 const KWindowInfo info
= KWindowSystem::windowInfo( winId(), 0, 0 );
884 return !isHidden() && !info
.isMinimized() && info
.isOnDesktop( KWindowSystem::currentDesktop() );
891 MainWindow::mbAvailabilityChanged( bool isAvailable
) //SLOT
895 if( m_browserNames
.indexOf( "MediaBrowser" ) == -1 )
896 addBrowser( "MediaBrowser", MediaBrowser::instance(), i18n( "Media Device" ), Amarok::icon( "device" ) );
900 if( m_browserNames
.indexOf( "MediaBrowser" ) != -1 )
902 showBrowser( "CollectionBrowser" );
903 //removeMediaBrowser( MediaBrowser::instance() );
904 m_browsers
->removeWidget( MediaBrowser::instance() );
909 void MainWindow::createActions()
911 KActionCollection
* const ac
= actionCollection();
912 const EngineController
* const ec
= EngineController::instance();
914 KStandardAction::keyBindings( kapp
, SLOT( slotConfigShortcuts() ), ac
);
915 KStandardAction::preferences( kapp
, SLOT( slotConfigAmarok() ), ac
);
916 ac
->action(KStandardAction::name(KStandardAction::KeyBindings
))->setIcon( KIcon( Amarok::icon( "configure" ) ) );
917 ac
->action(KStandardAction::name(KStandardAction::Preferences
))->setIcon( KIcon( Amarok::icon( "configure" ) ) );
919 KStandardAction::quit( kapp
, SLOT( quit() ), ac
);
921 KAction
*action
= new KAction( KIcon( Amarok::icon( "files" ) ), i18n("&Add Media..."), this );
922 connect( action
, SIGNAL( triggered(bool) ), this, SLOT( slotAddLocation() ) );
923 ac
->addAction( "playlist_add", action
);
925 action
= new KAction( KIcon( Amarok::icon( "playlist_clear" ) ), i18nc( "clear playlist", "&Clear" ), this );
926 connect( action
, SIGNAL( triggered( bool ) ), The::playlistModel(), SLOT( clear() ) );
927 ac
->addAction( "playlist_clear", action
);
929 action
= new KAction( KIcon( Amarok::icon( "files" ) ), i18n("&Add Stream..."), this );
930 connect( action
, SIGNAL( triggered(bool) ), this, SLOT( slotAddStream() ) );
931 ac
->addAction( "stream_add", action
);
933 action
= new KAction( KIcon( Amarok::icon( "save" ) ), i18n("&Save Playlist As..."), this );
934 connect( action
, SIGNAL( triggered(bool) ), this, SLOT( savePlaylist() ) );
935 ac
->addAction( "playlist_save", action
);
937 KAction
*burn
= new KAction( KIcon(Amarok::icon( "burn" )), i18n( "Burn Current Playlist" ), this );
938 connect( burn
, SIGNAL( triggered(bool) ), SLOT( slotBurnPlaylist() ) );
939 burn
->setEnabled( K3bExporter::isAvailable() );
940 ac
->addAction( "playlist_burn", burn
);
942 KAction
*covermanager
= new KAction( KIcon(Amarok::icon( "covermanager" )), i18n( "Cover Manager" ), this );
943 connect( covermanager
, SIGNAL( triggered(bool) ), SLOT( slotShowCoverManager() ) );
944 ac
->addAction( "cover_manager", covermanager
);
946 KAction
*visuals
= new KAction( KIcon( Amarok::icon("visualizations") ), i18n("&Visualizations"), this );
947 // connect( visuals, SIGNAL( triggered(bool) ), Vis::Selector::instance(), SLOT( show() ) );
948 ac
->addAction( "visualizations", visuals
);
950 KAction
*equalizer
= new KAction( KIcon( Amarok::icon( "equalizer" ) ), i18n( "E&qualizer"), this );
951 connect( equalizer
, SIGNAL( triggered(bool) ), kapp
, SLOT( slotConfigEqualizer() ) );
952 ac
->addAction( "equalizer", equalizer
);
954 KAction
*toggleToolbar
= new KAction( this );
955 toggleToolbar
->setText( i18n("Hide Toolbar") );
957 //FIXME m_controlBar is initialised after the actions are created so we need to change the text of this action
958 //when the menu is shown
959 //toggleToolbar->setText( !m_controlBar->isHidden() ? i18n("Hide Toolbar") : i18n("Show Toolbar") );
960 connect( toggleToolbar
, SIGNAL( triggered(bool) ), SLOT( slotToggleToolbar() ) );
961 ac
->addAction( "toggle_toolbar", toggleToolbar
);
963 // KAction *update_podcasts = new KAction( this );
964 // update_podcasts->setText( i18n( "Update Podcasts" ) );
965 // //update_podcasts->setIcon( KIcon(Amarok::icon( "refresh" )) );
966 // ac->addAction( "podcasts_update", update_podcasts );
967 // connect(update_podcasts, SIGNAL(triggered(bool)),
968 // The::podcastCollection(), SLOT(slotUpdateAll()));
970 KAction
*playact
= new KAction( KIcon(Amarok::icon( "files" )), i18n("Play Media..."), this );
971 connect(playact
, SIGNAL(triggered(bool)), SLOT(slotPlayMedia()));
972 ac
->addAction( "playlist_playmedia", playact
);
974 KAction
*acd
= new KAction( KIcon( Amarok::icon( "album" ) ), i18n("Play Audio CD"), this );
975 connect(acd
, SIGNAL(triggered(bool)), SLOT(playAudioCD()));
976 ac
->addAction( "play_audiocd", acd
);
978 KAction
*script
= new KAction( KIcon(Amarok::icon( "scripts" )), i18n("Script Manager"), this );
979 connect(script
, SIGNAL(triggered(bool)), SLOT(showScriptSelector()));
980 ac
->addAction( "script_manager", script
);
982 KAction
*queue
= new KAction( KIcon( Amarok::icon( "queue" )), i18n( "Queue Manager" ), this );
983 connect(queue
, SIGNAL(triggered(bool)), SLOT(showQueueManager()));
984 ac
->addAction( "queue_manager", queue
);
986 KAction
*seekForward
= new KAction( KIcon( Amarok::icon( "fastforward" ) ), i18n("&Seek Forward"), this );
987 seekForward
->setShortcut( Qt::Key_Right
);
988 connect(seekForward
, SIGNAL(triggered(bool)), ec
, SLOT(seekForward()));
989 ac
->addAction( "seek_forward", seekForward
);
991 KAction
*seekBackward
= new KAction( KIcon( Amarok::icon( "rewind" ) ), i18n("&Seek Backward"), this );
992 seekForward
->setShortcut( Qt::Key_Left
);
993 connect(seekForward
, SIGNAL(triggered(bool)), ec
, SLOT(seekBackward()));
994 ac
->addAction( "seek_backward", seekBackward
);
996 KAction
*statistics
= new KAction( KIcon(Amarok::icon( "info" )), i18n( "Statistics" ), this );
997 connect(statistics
, SIGNAL(triggered(bool)), SLOT(showStatistics()));
998 ac
->addAction( "statistics", statistics
);
1000 KAction
*update
= new KAction( KIcon(Amarok::icon( "refresh")), i18n( "Update Collection" ), this );
1001 connect(update
, SIGNAL(triggered(bool)), CollectionDB::instance(), SLOT(scanModifiedDirs()));
1002 ac
->addAction( "update_collection", update
);
1004 KAction
*rescan
= new KAction( KIcon(Amarok::icon( "rescan")), i18n( "Rescan Collection" ), this );
1005 connect(update
, SIGNAL(triggered(bool)), CollectionDB::instance(), SLOT(startScan()));
1006 rescan
->setEnabled( !ThreadManager::instance()->isJobPending( "CollectionScanner" ) );
1007 ac
->addAction( "rescan_collection", rescan
);
1009 m_lastfmTags
<< "Alternative" << "Ambient" << "Chill Out" << "Classical" << "Dance"
1010 << "Electronica" << "Favorites" << "Heavy Metal" << "Hip Hop" << "Indie Rock"
1011 << "Industrial" << "Japanese" << "Pop" << "Psytrance" << "Rap" << "Rock"
1012 << "Soundtrack" << "Techno" << "Trance";
1014 KMenu
* playTagRadioMenu
= new KMenu( this );
1015 playTagRadioMenu
->setTitle( i18n( "Global Tag Radio" ) );
1016 foreach( QString lastfmTag
, m_lastfmTags
)
1018 KAction
*lastfmAction
= new KAction( lastfmTag
, this );
1019 connect( lastfmAction
, SIGNAL( triggered(bool) ), SLOT( playLastfmGlobaltag() ) );
1020 playTagRadioMenu
->addAction( lastfmAction
);
1023 KMenu
* addTagRadioMenu
= new KMenu( this );
1024 addTagRadioMenu
->setTitle( i18n( "Global Tag Radio" ) );
1025 foreach( QString lastfmTag
, m_lastfmTags
)
1027 KAction
*lastfmAction
= new KAction( lastfmTag
, this );
1028 connect( lastfmAction
, SIGNAL( triggered(bool) ), SLOT( addLastfmGlobaltag() ) );
1029 addTagRadioMenu
->addAction( lastfmAction
);
1032 KActionMenu
* playLastfm
= new KActionMenu( KIcon(Amarok::icon("audioscrobbler")), i18n( "Play las&t.fm Stream" ), ac
);
1033 KMenu
* playLastfmMenu
= playLastfm
->menu();
1034 playLastfmMenu
->addAction( i18n( "Personal Radio" ), this, SLOT( playLastfmPersonal() ) );
1035 playLastfmMenu
->addAction( i18n( "Neighbor Radio" ), this, SLOT( playLastfmNeighbor() ) );
1036 playLastfmMenu
->addAction( i18n( "Custom Station" ), this, SLOT( playLastfmCustom() ) );
1037 playLastfmMenu
->addMenu( playTagRadioMenu
);
1038 ac
->addAction( "lastfm_play", playLastfm
);
1040 KActionMenu
* addLastfm
= new KActionMenu( KIcon(Amarok::icon("audioscrobbler")), i18n( "Add las&t.fm Stream" ), ac
);
1041 KMenu
* addLastfmMenu
= addLastfm
->menu();
1042 addLastfmMenu
->addAction( i18n( "Personal Radio" ), this, SLOT( addLastfmPersonal() ) );
1043 addLastfmMenu
->addAction( i18n( "Neighbor Radio" ), this, SLOT( addLastfmNeighbor() ) );
1044 addLastfmMenu
->addAction( i18n( "Custom Station" ), this, SLOT( addLastfmCustom() ) );
1045 addLastfmMenu
->addMenu( addTagRadioMenu
);
1046 ac
->addAction( "lastfm_add", addLastfm
);
1048 KAction
*previous
= new KAction( this );
1049 previous
->setIcon( KIcon(Amarok::icon( "back" )) );
1050 previous
->setText( i18n( "Previous Track" ) );
1051 ac
->addAction( "prev", previous
);
1052 connect( previous
, SIGNAL(triggered(bool)), The::playlistModel(), SLOT( back() ) );
1054 KAction
*play
= new KAction( this );
1055 play
->setIcon( KIcon(Amarok::icon( "play" )) );
1056 play
->setText( i18n( "Play" ) );
1057 ac
->addAction( "play", play
);
1058 connect( play
, SIGNAL(triggered(bool)), ec
, SLOT( play() ));
1060 KAction
*pause
= new KAction( this );
1061 pause
->setIcon( KIcon(Amarok::icon( "pause" )) );
1062 pause
->setText( i18n( "Pause" ));
1063 ac
->addAction( "pause", pause
);
1064 connect( pause
, SIGNAL(triggered(bool)), ec
, SLOT( pause() ) );
1066 KAction
*next
= new KAction( this );
1067 next
->setIcon( KIcon(Amarok::icon( "next" )) );
1068 next
->setText( i18n( "Next Track" ) );
1069 ac
->addAction( "next", next
);
1070 connect( next
, SIGNAL(triggered(bool)), The::playlistModel(), SLOT( next() ) );
1072 KAction
*toggleFocus
= new KAction(i18n( "Toggle Focus" ), ac
);
1073 toggleFocus
->setShortcut( Qt::ControlModifier
+ Qt::Key_Tab
);
1074 connect( toggleFocus
, SIGNAL(triggered(bool)), SLOT( slotToggleFocus() ));
1076 new Amarok::MenuAction( ac
);
1077 new Amarok::StopAction( ac
);
1078 new Amarok::PlayPauseAction( ac
);
1079 new Amarok::RepeatAction( ac
);
1080 new Amarok::RandomAction( ac
);
1081 new Amarok::FavorAction( ac
);
1083 if( K3bExporter::isAvailable() )
1084 new Amarok::BurnMenuAction( ac
);
1086 ac
->setAssociatedWidget( this );
1089 void MainWindow::createMenus()
1091 m_menubar
= menuBar();//new MenuBar( this );
1093 //BEGIN Actions menu
1094 KMenu
*actionsMenu
= new KMenu( m_menubar
);
1095 actionsMenu
->setTitle( i18n("&Amarok") );
1096 actionsMenu
->addAction( actionCollection()->action("playlist_playmedia") );
1097 actionsMenu
->addAction( actionCollection()->action("lastfm_play") );
1098 actionsMenu
->addAction( actionCollection()->action("play_audiocd") );
1099 actionsMenu
->addSeparator();
1100 actionsMenu
->addAction( actionCollection()->action("prev") );
1101 actionsMenu
->addAction( actionCollection()->action("play_pause") );
1102 actionsMenu
->addAction( actionCollection()->action("stop") );
1103 actionsMenu
->addAction( actionCollection()->action("next") );
1104 actionsMenu
->addSeparator();
1105 actionsMenu
->addAction( actionCollection()->action(KStandardAction::name(KStandardAction::Quit
)) );
1108 //BEGIN Playlist menu
1109 KMenu
*playlistMenu
= new KMenu( m_menubar
);
1110 playlistMenu
->setTitle( i18n("&Playlist") );
1111 playlistMenu
->addAction( actionCollection()->action("playlist_add") );
1112 playlistMenu
->addAction( actionCollection()->action("stream_add") );
1113 playlistMenu
->addAction( actionCollection()->action("lastfm_add") );
1114 playlistMenu
->addAction( actionCollection()->action("playlist_save") );
1115 playlistMenu
->addAction( actionCollection()->action("playlist_burn") );
1116 playlistMenu
->addAction( actionCollection()->action("podcasts_update") );
1117 playlistMenu
->addSeparator();
1118 playlistMenu
->addAction( actionCollection()->action("playlist_undo") );
1119 playlistMenu
->addAction( actionCollection()->action("playlist_redo") );
1120 playlistMenu
->addSeparator();
1121 playlistMenu
->addAction( actionCollection()->action("playlist_clear") );
1122 playlistMenu
->addAction( actionCollection()->action("playlist_shuffle") );
1124 playlistMenu
->addSeparator();
1125 playlistMenu
->addAction( actionCollection()->action("queue_selected") );
1126 playlistMenu
->addAction( actionCollection()->action("playlist_remove_duplicates") );
1127 playlistMenu
->addAction( actionCollection()->action("playlist_select_all") );
1132 KMenu
*modeMenu
= new KMenu( m_menubar
);
1133 modeMenu
->setTitle( i18n("&Mode") );
1134 modeMenu
->addAction( actionCollection()->action("repeat") );
1135 KSelectAction
*random
= static_cast<KSelectAction
*>( actionCollection()->action("random_mode") );
1136 modeMenu
->addAction( random
);
1137 random
->menu()->addSeparator();
1138 random
->menu()->addAction( actionCollection()->action("favor_tracks") );
1142 m_toolsMenu
= new KMenu( m_menubar
);
1143 m_toolsMenu
->setTitle( i18n("&Tools") );
1144 m_toolsMenu
->addAction( actionCollection()->action("cover_manager") );
1145 m_toolsMenu
->addAction( actionCollection()->action("queue_manager") );
1146 m_toolsMenu
->addAction( actionCollection()->action("visualizations") );
1147 m_toolsMenu
->addAction( actionCollection()->action("equalizer") );
1148 m_toolsMenu
->addAction( actionCollection()->action("script_manager") );
1149 m_toolsMenu
->addAction( actionCollection()->action("statistics") );
1150 m_toolsMenu
->addSeparator();
1151 m_toolsMenu
->addAction( actionCollection()->action("update_collection") );
1152 m_toolsMenu
->addAction( actionCollection()->action("rescan_collection") );
1154 #ifndef HAVE_LIBVISUAL
1155 actionCollection()->action( "visualizations" )->setEnabled( false );
1158 connect( m_toolsMenu
, SIGNAL( aboutToShow() ), SLOT( toolsMenuAboutToShow() ) );
1159 connect( m_toolsMenu
, SIGNAL( activated(int) ), SLOT( slotMenuActivated(int) ) );
1162 //BEGIN Settings menu
1163 m_settingsMenu
= new KMenu( m_menubar
);
1164 m_settingsMenu
->setTitle( i18n("&Settings") );
1165 //TODO use KStandardAction or KXmlGuiWindow
1167 m_settingsMenu
->addAction( actionCollection()->action( "toggle_toolbar" ) );
1168 m_settingsMenu
->addSeparator();
1172 // plug it first, as this item will be moved to the applications first menu
1173 m_settingsMenu
->addAction( actionCollection()->action(KStandardAction::name(KStandardAction::Preferences
)) );
1175 // m_settingsMenu->addAction( actionCollection()->action("options_configure_globals") );
1176 m_settingsMenu
->addAction( actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings
)) );
1177 m_settingsMenu
->addAction( actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)) );
1178 m_settingsMenu
->addAction( actionCollection()->action(KStandardAction::name(KStandardAction::Preferences
)) );
1180 connect( m_settingsMenu
, SIGNAL( activated(int) ), SLOT( slotMenuActivated(int) ) );
1183 m_menubar
->addMenu( actionsMenu
);
1184 m_menubar
->addMenu( playlistMenu
);
1185 m_menubar
->addMenu( modeMenu
);
1186 m_menubar
->addMenu( m_toolsMenu
);
1187 m_menubar
->addMenu( m_settingsMenu
);
1188 m_menubar
->addMenu( Amarok::Menu::helpMenu() );
1192 #include "MainWindow.moc"