File indexing completed on 2024-05-19 04:49:16
0001 /**************************************************************************************** 0002 * Copyright (c) 2008 Casey Link <unnamedrambler@gmail.com> * 0003 * Copyright (c) 2008 Jason A. Donenfeld <Jason@zx2c4.com> * 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 #include "FileCollectionLocation.h" 0019 0020 #include "core/collections/CollectionLocationDelegate.h" 0021 #include "core/logger/Logger.h" 0022 #include "core/support/Components.h" 0023 #include "core/support/Debug.h" 0024 0025 0026 #include <kio/job.h> 0027 #include <kio/jobclasses.h> 0028 #include <kio/deletejob.h> 0029 0030 #include <KLocalizedString> 0031 0032 #include <QDir> 0033 #include <QFile> 0034 #include <QFileInfo> 0035 0036 using namespace Collections; 0037 0038 FileCollectionLocation::FileCollectionLocation() 0039 : CollectionLocation() 0040 { 0041 // nothing to do 0042 } 0043 0044 FileCollectionLocation::~FileCollectionLocation() 0045 { 0046 // nothing to do 0047 } 0048 0049 QString 0050 FileCollectionLocation::prettyLocation() const 0051 { 0052 return QStringLiteral("File Browser Location"); 0053 } 0054 0055 0056 bool 0057 FileCollectionLocation::isWritable() const 0058 { 0059 return true; 0060 } 0061 0062 bool 0063 FileCollectionLocation::isOrganizable() const 0064 { 0065 return false; 0066 } 0067 0068 void FileCollectionLocation::startRemoveJobs() 0069 { 0070 DEBUG_BLOCK 0071 while ( !m_removetracks.isEmpty() ) 0072 { 0073 Meta::TrackPtr track = m_removetracks.takeFirst(); 0074 QUrl src = track->playableUrl(); 0075 0076 KIO::DeleteJob *job = nullptr; 0077 0078 src.setPath( QDir::cleanPath(src.path()) ); 0079 debug() << "deleting " << src; 0080 KIO::JobFlags flags = KIO::HideProgressInfo; 0081 job = KIO::del( src, flags ); 0082 connect( job, &KIO::Job::result, this, &FileCollectionLocation::slotRemoveJobFinished ); 0083 QString name = track->prettyName(); 0084 if( track->artist() ) 0085 name = QStringLiteral( "%1 - %2" ).arg( track->artist()->name(), track->prettyName() ); 0086 0087 Amarok::Logger::newProgressOperation( job, i18n( "Removing: %1", name ) ); 0088 m_removejobs.insert( job, track ); 0089 } 0090 } 0091 0092 void FileCollectionLocation::slotRemoveJobFinished( KJob *job ) 0093 { 0094 // ignore and error that the file did not exist in the first place. Perhaps destination 0095 // collection too eager? :-) 0096 if( job->error() && job->error() != KIO::ERR_DOES_NOT_EXIST ) 0097 transferError( m_removejobs.value( job ), KIO::buildErrorString( job->error(), job->errorString() ) ); 0098 else 0099 transferSuccessful( m_removejobs.value( job ) ); 0100 0101 m_removejobs.remove( job ); 0102 job->deleteLater(); 0103 0104 if(m_removejobs.isEmpty()) { 0105 slotRemoveOperationFinished(); 0106 } 0107 } 0108 0109 0110 void FileCollectionLocation::removeUrlsFromCollection(const Meta::TrackList& sources) 0111 { 0112 DEBUG_BLOCK 0113 m_removetracks = sources; 0114 0115 debug() << "removing " << m_removetracks.size() << "tracks"; 0116 startRemoveJobs(); 0117 } 0118 0119 void FileCollectionLocation::showRemoveDialog( const Meta::TrackList &tracks ) 0120 { 0121 DEBUG_BLOCK 0122 if( !isHidingRemoveConfirm() ) 0123 { 0124 Collections::CollectionLocationDelegate *delegate = Amarok::Components::collectionLocationDelegate(); 0125 const bool del = delegate->reallyDelete( this, tracks ); 0126 0127 if( !del ) 0128 abort(); 0129 else 0130 slotShowRemoveDialogDone(); 0131 } else 0132 slotShowRemoveDialogDone(); 0133 } 0134