1 /****************************************************************************************
2  * Copyright (c) 2009  Nikolaj Hald Nielsen <nhn@kde.org>                               *
3  *                                                                                      *
4  * This program is free software; you can redistribute it and/or modify it under        *
5  * the terms of the GNU General Public License as published by the Free Software        *
6  * Foundation; either version 2 of the License, or (at your option) any later           *
7  * version.                                                                             *
8  *                                                                                      *
9  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
10  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
11  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
12  *                                                                                      *
13  * You should have received a copy of the GNU General Public License along with         *
14  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
15  ****************************************************************************************/
16 
17 #include "CurrentTrackToolbar.h"
18 
19 #include "EngineController.h"
20 #include "GlobalCurrentTrackActions.h"
21 #include "core/capabilities/ActionsCapability.h"
22 #include "core/capabilities/BookmarkThisCapability.h"
23 #include "core/meta/Meta.h"
24 
25 
CurrentTrackToolbar(QWidget * parent)26 CurrentTrackToolbar::CurrentTrackToolbar( QWidget * parent )
27     : QToolBar( parent )
28 {
29     setToolButtonStyle( Qt::ToolButtonIconOnly );
30     setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Preferred );
31     //setIconDimensions( 16 );
32     setContentsMargins( 0, 0, 0, 0 );
33 
34     EngineController *engine = The::engineController();
35 
36     connect( engine, &EngineController::trackChanged,
37              this, &CurrentTrackToolbar::handleAddActions );
38 }
39 
~CurrentTrackToolbar()40 CurrentTrackToolbar::~CurrentTrackToolbar()
41 {}
42 
handleAddActions()43 void CurrentTrackToolbar::handleAddActions()
44 {
45     clear();
46 
47     Meta::TrackPtr track = The::engineController()->currentTrack();
48 
49     foreach( QAction* action, The::globalCurrentTrackActions()->actions() )
50         addAction( action );
51 
52     if( track )
53     {
54         QScopedPointer< Capabilities::ActionsCapability > ac( track->create<Capabilities::ActionsCapability>() );
55         if( ac )
56         {
57             QList<QAction *> currentTrackActions = ac->actions();
58             foreach( QAction *action, currentTrackActions )
59             {
60                 if( !action->parent() )
61                     action->setParent( this );
62                 addAction( action );
63             }
64         }
65 
66         QScopedPointer< Capabilities::BookmarkThisCapability > btc( track->create<Capabilities::BookmarkThisCapability>() );
67         if( btc && btc->bookmarkAction() )
68             addAction( btc->bookmarkAction() );
69     }
70 }
71