File indexing completed on 2024-05-05 04:47:21

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 Pulic 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 "ContextUrlRunner.h"
0018 
0019 #include "MainWindow.h"
0020 #include "AmarokUrlHandler.h"
0021 #include "context/ContextView.h"
0022 #include "context/AppletModel.h"
0023 
0024 #include <KLocalizedString>
0025 
0026 ContextUrlRunner::ContextUrlRunner()
0027 {}
0028 
0029 ContextUrlRunner::~ContextUrlRunner()
0030 {
0031     The::amarokUrlHandler()->unRegisterRunner ( this );
0032 }
0033 
0034 QIcon ContextUrlRunner::icon() const
0035 {
0036     return QIcon::fromTheme( QStringLiteral("x-media-podcast-amarok") );
0037 }
0038 
0039 bool ContextUrlRunner::run( const AmarokUrl &url )
0040 {
0041     DEBUG_BLOCK
0042     
0043     if( url.isNull() )
0044         return false;
0045 
0046     if( url.command() != command() )
0047         return false;
0048 
0049 
0050     QString appletsString = url.args().value( QStringLiteral("applets") );
0051     debug() << "applet string: " << appletsString;
0052     QStringList appletList = appletsString.split( QLatin1Char(',') );
0053     auto model = Context::ContextView::self()->appletModel();
0054     if( model )
0055     {
0056         model->clear();
0057         foreach( const QString &appletPluginName, appletList )
0058         {
0059             model->setAppletEnabled( appletPluginName, true );
0060         }
0061     }
0062     The::mainWindow()->showDock( MainWindow::AmarokDockContext );
0063 
0064     return true;
0065 }
0066 
0067 QString ContextUrlRunner::command() const
0068 {
0069     return QStringLiteral("context");
0070 }
0071 
0072 QString ContextUrlRunner::prettyCommand() const
0073 {
0074     return i18nc( "A type of command that affects the context view", "Context" );
0075 }
0076