File indexing completed on 2024-05-05 04:48:44

0001 /****************************************************************************************
0002  * Copyright (c) 2009 Téo Mrnjavac <teo@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 "PlaylistViewUrlGenerator.h"
0018 
0019 #include "core/support/Debug.h"
0020 #include "layouts/LayoutManager.h"
0021 #include "MainWindow.h"
0022 #include "PlaylistDock.h"
0023 #include "PlaylistSortWidget.h"
0024 #include "ProgressiveSearchWidget.h"
0025 
0026 #include <KLocalizedString>
0027 #include <QStandardPaths>
0028 
0029 namespace Playlist
0030 {
0031 
0032 ViewUrlGenerator * ViewUrlGenerator::s_instance = nullptr;
0033 
0034 ViewUrlGenerator * ViewUrlGenerator::instance()
0035 {
0036     if( s_instance == nullptr)
0037         s_instance = new ViewUrlGenerator();
0038 
0039     return s_instance;
0040 }
0041 
0042 
0043 ViewUrlGenerator::ViewUrlGenerator()
0044 {}
0045 
0046 ViewUrlGenerator::~ViewUrlGenerator()
0047 {}
0048 
0049 AmarokUrl
0050 ViewUrlGenerator::createUrl()
0051 {
0052     DEBUG_BLOCK
0053     AmarokUrl url;
0054     url.setCommand( QStringLiteral("playlist") );
0055     url.setPath( QStringLiteral("view") );
0056     Dock * playlistDock = The::mainWindow()->playlistDock();
0057 
0058     QString filterExpr = playlistDock->searchWidget()->currentFilter();
0059     QString onlyMatches = playlistDock->searchWidget()->onlyMatches() ? "true" : "false";
0060     QString sortPath = playlistDock->sortWidget()->sortPath();
0061     QString prettySortPath = playlistDock->sortWidget()->prettySortPath();
0062     QString layout = LayoutManager::instance()->activeLayoutName();
0063     debug()<< "The filter is "<< filterExpr;
0064     debug()<< "OnlyMatches is "<< onlyMatches;
0065     debug()<< "The sortPath is "<< sortPath;
0066     debug()<< "The layout is "<< layout;
0067 
0068     QString prettyUrlName;
0069 
0070     if( !sortPath.isEmpty() )
0071     {
0072         url.setArg( QStringLiteral("sort"), sortPath );
0073         prettyUrlName.append( prettySortPath );
0074     }
0075     if( !filterExpr.isEmpty() )
0076     {
0077         url.setArg( QStringLiteral("filter"), filterExpr );
0078         url.setArg( QStringLiteral("matches"), onlyMatches );
0079         if( !prettyUrlName.isEmpty() )
0080             prettyUrlName.append( "  |  " );
0081         QString prettyFilterExpr = "\"" + filterExpr + "\"";
0082         prettyUrlName.append( ( onlyMatches == QStringLiteral( "true" ) )
0083                               ? i18n( "Filter %1", prettyFilterExpr )
0084                               : i18n( "Search %1", prettyFilterExpr ) );
0085     }
0086     if( !layout.isEmpty() )
0087     {
0088         url.setArg( QStringLiteral("layout"), layout );
0089         if( !prettyUrlName.isEmpty() )
0090             prettyUrlName.append( "  |  " );
0091         prettyUrlName.append( i18n( "%1 layout", layout ) );
0092     }
0093 
0094     url.setName( prettyUrlName );
0095     debug()<< "Url is "<<url.url();
0096     return url;
0097 }
0098 
0099 QString
0100 ViewUrlGenerator::description()
0101 {
0102     return i18n( "Bookmark Playlist Setup" );
0103 }
0104 
0105 QIcon ViewUrlGenerator::icon()
0106 {
0107     return QIcon( QPixmap( QStandardPaths::locate( QStandardPaths::GenericDataLocation, "amarok/images/playlist-bookmark-16.png" ) ) );
0108 }
0109 
0110 } //namespace Playlist