File indexing completed on 2025-01-05 04:25:54

0001 /****************************************************************************************
0002  * Copyright (c) 2009 Maximilian Kossick <maximilian.kossick@googlemail.com>            *
0003  * Copyright (c) 2013 Ralf Engels <ralf-engels@gmx.de>                                  *
0004  *                                                                                      *
0005  * This program is free software; you can redistribute it and/or modify it under        *
0006  * the terms of the GNU General Public License as published by the Free Software        *
0007  * Foundation; either version 2 of the License, or (at your option) any later           *
0008  * version.                                                                             *
0009  *                                                                                      *
0010  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0011  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0012  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0013  *                                                                                      *
0014  * You should have received a copy of the GNU General Public License along with         *
0015  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0016  ****************************************************************************************/
0017 
0018 #define DEBUG_PREFIX "SqlCapabilities"
0019 
0020 #include "SqlCapabilities.h"
0021 
0022 #include "MetaValues.h"
0023 #include "SqlMeta.h"
0024 #include "core/support/Debug.h"
0025 
0026 #include <QFile>
0027 #include <QList>
0028 
0029 namespace Capabilities {
0030 
0031 OrganiseCapabilityImpl::OrganiseCapabilityImpl( Meta::SqlTrack *track )
0032     : Capabilities::OrganiseCapability()
0033     , m_track( track )
0034 {}
0035 
0036 OrganiseCapabilityImpl::~OrganiseCapabilityImpl()
0037 {}
0038 
0039 
0040 void
0041 OrganiseCapabilityImpl::deleteTrack()
0042 {
0043     if( QFile::remove( m_track->playableUrl().path() ) )
0044         m_track->remove();
0045 }
0046 
0047 
0048 TimecodeWriteCapabilityImpl::TimecodeWriteCapabilityImpl( Meta::SqlTrack *track )
0049     : Capabilities::TimecodeWriteCapability()
0050     , m_track( track )
0051 {}
0052 
0053 TimecodeWriteCapabilityImpl::~TimecodeWriteCapabilityImpl()
0054 {}
0055 
0056 
0057 TimecodeLoadCapabilityImpl::TimecodeLoadCapabilityImpl( Meta::SqlTrack *track )
0058     : Capabilities::TimecodeLoadCapability()
0059     , m_track( track )
0060 {}
0061 
0062 TimecodeLoadCapabilityImpl::~TimecodeLoadCapabilityImpl()
0063 {}
0064 
0065 bool
0066 TimecodeLoadCapabilityImpl::hasTimecodes()
0067 {
0068     return ( loadTimecodes().size() > 0 );
0069 }
0070 
0071 QList<AmarokSharedPointer<AmarokUrl> >
0072 TimecodeLoadCapabilityImpl::loadTimecodes()
0073 {
0074     QList<AmarokSharedPointer<AmarokUrl> > list = PlayUrlRunner::bookmarksFromUrl( m_track->playableUrl() );
0075     return list;
0076 }
0077 
0078 
0079 FindInSourceCapabilityImpl::FindInSourceCapabilityImpl( Meta::SqlTrack *track )
0080     : Capabilities::FindInSourceCapability()
0081     , m_track( track )
0082 {}
0083 
0084 FindInSourceCapabilityImpl::~FindInSourceCapabilityImpl()
0085 {}
0086 
0087 void
0088 FindInSourceCapabilityImpl::findInSource( QFlags<TargetTag> tag )
0089 {
0090     DEBUG_BLOCK
0091 
0092     QStringList filters;
0093     Meta::AlbumPtr album       = m_track->album();
0094     Meta::ArtistPtr artist     = m_track->artist();
0095     Meta::ComposerPtr composer = m_track->composer();
0096     Meta::GenrePtr genre       = m_track->genre();
0097     Meta::YearPtr year         = m_track->year();
0098     QString name;
0099 
0100     if( tag.testFlag(Artist) && !(name = artist ? artist->prettyName() : QString()).isEmpty() )
0101         filters << QString( "%1:\"%2\"" ).arg( Meta::shortI18nForField( Meta::valArtist ), name );
0102     if( tag.testFlag(Album) && !(name = album ? album->prettyName() : QString()).isEmpty() )
0103         filters << QString( "%1:\"%2\"" ).arg( Meta::shortI18nForField( Meta::valAlbum ), name );
0104     if( tag.testFlag(Composer) && !(name = composer ? composer->prettyName() : QString()).isEmpty() )
0105         filters << QString( "%1:\"%2\"" ).arg( Meta::shortI18nForField( Meta::valComposer ), name );
0106     if( tag.testFlag(Genre) && !(name = genre ? genre->prettyName() : QString()).isEmpty() )
0107         filters << QString( "%1:\"%2\"" ).arg( Meta::shortI18nForField( Meta::valGenre ), name );
0108     if( tag.testFlag(Track) && !(name = m_track ? m_track->prettyName() : QString()).isEmpty() )
0109         filters << QString( "%1:\"%2\"" ).arg( Meta::shortI18nForField( Meta::valTitle ), name );
0110     if( tag.testFlag(Year) && !(name = year ? year->name() : QString()).isEmpty() )
0111         filters << QString( "%1:%2" ).arg( Meta::shortI18nForField( Meta::valYear ), name );
0112 
0113     if( !filters.isEmpty() )
0114     {
0115         AmarokUrl url;
0116         url.setCommand( "navigate" );
0117         url.setPath( "collections" );
0118         url.setArg( "filter", filters.join( QLatin1String(" AND ") ) );
0119 
0120         debug() << "running url: " << url.url();
0121         url.run();
0122     }
0123 }
0124 
0125 } //namespace Capabilities
0126 
0127