File indexing completed on 2024-05-05 04:49:23

0001 /****************************************************************************************
0002  * Copyright (c) 2009  Nikolaj Hald Nielsen <nhn@kde.org>                               *
0003  *                                                                                      *
0004  * This program is free software; you can redistribute it and/or modify it under        *
0005  * the terms of the GNU General Public License as published by the Free Software        *
0006  * Foundation; either version 2 of the License, or (at your option) any later           *
0007  * version.                                                                             *
0008  *                                                                                      *
0009  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0010  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0011  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0012  *                                                                                      *
0013  * You should have received a copy of the GNU General Public License along with         *
0014  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0015  ****************************************************************************************/
0016  
0017 #include "CurrentTrackToolbar.h"
0018 
0019 #include "EngineController.h"
0020 #include "GlobalCurrentTrackActions.h"
0021 #include "core/capabilities/ActionsCapability.h"
0022 #include "core/capabilities/BookmarkThisCapability.h"
0023 #include "core/meta/Meta.h"
0024 
0025 
0026 CurrentTrackToolbar::CurrentTrackToolbar( QWidget * parent )
0027     : QToolBar( parent )
0028 {
0029     setToolButtonStyle( Qt::ToolButtonIconOnly );
0030     setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Preferred );
0031     //setIconDimensions( 16 );
0032     setContentsMargins( 0, 0, 0, 0 );
0033 
0034     EngineController *engine = The::engineController();
0035 
0036     connect( engine, &EngineController::trackChanged,
0037              this, &CurrentTrackToolbar::handleAddActions );
0038 }
0039 
0040 CurrentTrackToolbar::~CurrentTrackToolbar()
0041 {}
0042 
0043 void CurrentTrackToolbar::handleAddActions()
0044 {
0045     clear();
0046 
0047     Meta::TrackPtr track = The::engineController()->currentTrack();
0048 
0049     foreach( QAction* action, The::globalCurrentTrackActions()->actions() )
0050         addAction( action );
0051 
0052     if( track )
0053     {
0054         QScopedPointer< Capabilities::ActionsCapability > ac( track->create<Capabilities::ActionsCapability>() );
0055         if( ac )
0056         {
0057             QList<QAction *> currentTrackActions = ac->actions();
0058             foreach( QAction *action, currentTrackActions )
0059             {
0060                 if( !action->parent() )
0061                     action->setParent( this );
0062                 addAction( action );
0063             }
0064         }
0065 
0066         QScopedPointer< Capabilities::BookmarkThisCapability > btc( track->create<Capabilities::BookmarkThisCapability>() );
0067         if( btc && btc->bookmarkAction() )
0068             addAction( btc->bookmarkAction() );
0069     }
0070 }