File indexing completed on 2024-05-19 04:50:22
0001 /**************************************************************************************** 0002 * Copyright (c) 2008 Casey Link <unnamedrambler@gmail.com> * 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 "Mp3tunesServiceCollectionLocation.h" 0018 0019 #include "Mp3tunesWorkers.h" 0020 #include "core/logger/Logger.h" 0021 #include "core/support/Components.h" 0022 0023 #include <ThreadWeaver/Job> 0024 #include <ThreadWeaver/ThreadWeaver> 0025 #include <ThreadWeaver/Queue> 0026 0027 #include "core/support/Debug.h" 0028 0029 using namespace Collections; 0030 0031 Mp3tunesServiceCollectionLocation::Mp3tunesServiceCollectionLocation( Mp3tunesServiceCollection *parentCollection ) 0032 : ServiceCollectionLocation( parentCollection ) 0033 , m_collection( parentCollection ) 0034 { 0035 DEBUG_BLOCK 0036 } 0037 0038 Mp3tunesServiceCollectionLocation::~Mp3tunesServiceCollectionLocation() 0039 { 0040 } 0041 0042 QString Mp3tunesServiceCollectionLocation::prettyLocation() const 0043 { 0044 return i18n( "MP3tunes Locker" ); 0045 } 0046 0047 bool Mp3tunesServiceCollectionLocation::isWritable() const 0048 { 0049 return true; 0050 } 0051 0052 void Mp3tunesServiceCollectionLocation::copyUrlsToCollection ( 0053 const QMap<Meta::TrackPtr, QUrl> &sources, 0054 const Transcoding::Configuration &configuration ) 0055 { 0056 DEBUG_BLOCK 0057 Q_UNUSED( configuration ); // TODO: we might support transcoding here 0058 0059 QStringList urls; 0060 QString error; 0061 debug() << "sources has " << sources.count(); 0062 foreach( const Meta::TrackPtr &track, sources.keys() ) 0063 { 0064 debug() << "copying " << sources[ track ] << " to mp3tunes locker"; 0065 debug() << "file is at " << sources[ track ].toDisplayString(); 0066 0067 QString supported_types = "mp3 mp4 m4a m4b m4p aac wma ogg"; 0068 0069 if( supported_types.contains( track->type() ) ) 0070 { 0071 0072 debug() << "Added " << sources[ track ].toDisplayString() << " to queue."; 0073 urls.push_back( sources[ track ].toDisplayString() ); 0074 0075 } 0076 else 0077 { 0078 error = i18n( "Only the following types of tracks can be uploaded to MP3tunes: mp3, mp4, m4a, m4p, aac, wma, and ogg. " ); 0079 debug() << "File type not supported " << track->type(); 0080 } 0081 } 0082 if( !error.isEmpty() ) 0083 Amarok::Logger::longMessage( error ); 0084 Mp3tunesSimpleUploader * uploadWorker = new Mp3tunesSimpleUploader( m_collection->locker(), urls ); 0085 connect( uploadWorker, &Mp3tunesSimpleUploader::uploadComplete, this, &Mp3tunesServiceCollectionLocation::slotCopyOperationFinished ); 0086 ThreadWeaver::Queue::instance()->enqueue( QSharedPointer<ThreadWeaver::Job>(uploadWorker) ); 0087 }