Warning, file /multimedia/amarok/src/amarokurls/NavigationUrlRunner.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /**************************************************************************************** 0002 * Copyright (c) 2008 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 "NavigationUrlRunner.h" 0018 0019 #include "MainWindow.h" 0020 #include "amarokconfig.h" 0021 #include "amarokurls/AmarokUrlHandler.h" 0022 #include "browsers/BrowserDock.h" 0023 #include "browsers/CollectionTreeItemModelBase.h" 0024 #include "browsers/collectionbrowser/CollectionWidget.h" 0025 #include "browsers/filebrowser/FileBrowser.h" 0026 #include "browsers/playlistbrowser/PlaylistBrowser.h" 0027 #include "browsers/servicebrowser/ServiceBrowser.h" 0028 #include "core/support/Debug.h" 0029 #include "playlistmanager/PlaylistManager.h" 0030 #include "services/ServiceBase.h" 0031 0032 NavigationUrlRunner::NavigationUrlRunner() 0033 : AmarokUrlRunnerBase() 0034 {} 0035 0036 0037 NavigationUrlRunner::~NavigationUrlRunner() 0038 { 0039 The::amarokUrlHandler()->unRegisterRunner( this ); 0040 } 0041 0042 bool 0043 NavigationUrlRunner::run(const AmarokUrl &url ) 0044 { 0045 DEBUG_BLOCK; 0046 0047 //get to the correct category 0048 debug() << "Navigate to path: " << url.path(); 0049 The::mainWindow()->browserDock()->list()->navigate( url.path() ); 0050 0051 BrowserCategory * active = The::mainWindow()->browserDock()->list()->activeCategoryRecursive(); 0052 0053 QMap<QString, QString> args = url.args(); 0054 0055 if ( args.keys().contains( QStringLiteral("levels") ) ) 0056 { 0057 QString levelsString = args.value( QStringLiteral("levels") ); 0058 QList<CategoryId::CatMenuId> levels; 0059 0060 QStringList levelsStringList = levelsString.split( QLatin1Char('-') ); 0061 0062 foreach( const QString &levelString, levelsStringList ) { 0063 if( levelString == QLatin1String("genre") ) 0064 levels.append( CategoryId::Genre ); 0065 else if( levelString == QLatin1String("artist") ) 0066 levels.append( CategoryId::Artist ); 0067 else if( levelString == QLatin1String("album") ) 0068 levels.append( CategoryId::Album ); 0069 else if( levelString == QLatin1String("albumartist") ) 0070 levels.append( CategoryId::AlbumArtist ); 0071 else if( levelString == QLatin1String("composer") ) 0072 levels.append( CategoryId::Composer ); 0073 else if( levelString == QLatin1String("year") ) 0074 levels.append( CategoryId::Year ); 0075 } 0076 0077 active->setLevels( levels ); 0078 0079 } 0080 0081 0082 //if we are activating the local collection, check if we need to restore "show cover" and "show year" 0083 //if in the local collection view, also store "show covers" and "show years" 0084 if( url.path().endsWith( QLatin1String("collections"), Qt::CaseInsensitive ) ) 0085 { 0086 if ( args.keys().contains( QStringLiteral("show_cover") ) ) 0087 { 0088 if( args.value( QStringLiteral("show_cover") ).compare( QLatin1String("true"), Qt::CaseInsensitive ) == 0 ) 0089 AmarokConfig::setShowAlbumArt( true ); 0090 else if( args.value( QStringLiteral("show_cover") ).compare( QLatin1String("false"), Qt::CaseInsensitive ) == 0 ) 0091 AmarokConfig::setShowAlbumArt( false ); 0092 } 0093 0094 if ( args.keys().contains( QStringLiteral("show_years") ) ) 0095 { 0096 if( args.value( QStringLiteral("show_years") ).compare( QLatin1String("true"), Qt::CaseInsensitive ) == 0 ) 0097 AmarokConfig::setShowYears( true ); 0098 else if( args.value( QStringLiteral("show_years") ).compare( QLatin1String("false"), Qt::CaseInsensitive ) == 0 ) 0099 AmarokConfig::setShowYears( false ); 0100 } 0101 } 0102 0103 //also set the correct path if we are navigating to the file browser 0104 if( url.path().endsWith( QLatin1String("files"), Qt::CaseInsensitive ) ) 0105 { 0106 FileBrowser * fileBrowser = dynamic_cast<FileBrowser *>( The::mainWindow()->browserDock()->list()->activeCategory() ); 0107 if( fileBrowser ) 0108 { 0109 if( args.keys().contains( QStringLiteral("path") ) ) 0110 { 0111 fileBrowser->setDir( QUrl::fromUserInput(args.value( QStringLiteral("path") )) ); 0112 } 0113 } 0114 } 0115 0116 if ( args.keys().contains( QStringLiteral("filter") ) ) 0117 active->setFilter( QUrl::fromPercentEncoding(args.value( QStringLiteral("filter") ).toUtf8()) ); 0118 0119 The::mainWindow()->showDock( MainWindow::AmarokDockNavigation ); 0120 0121 return true; 0122 } 0123 0124 QString NavigationUrlRunner::command() const 0125 { 0126 return QStringLiteral("navigate"); 0127 } 0128 0129 QString NavigationUrlRunner::prettyCommand() const 0130 { 0131 return i18nc( "A type of command that affects the view in the browser category", "Navigate" ); 0132 } 0133 0134 QIcon NavigationUrlRunner::icon() const 0135 { 0136 return QIcon::fromTheme( QStringLiteral("flag-amarok") ); 0137 } 0138 0139