File indexing completed on 2024-05-19 04:49:12
0001 /**************************************************************************************** 0002 * Copyright (c) 2009 Alejandro Wainzinger <aikawarazuni@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 "MediaDeviceCollectionLocation.h" 0018 0019 #include "MediaDeviceCache.h" // for collection refresh hack 0020 #include "core/meta/Meta.h" 0021 #include "core/support/Debug.h" 0022 #include "core-impl/collections/mediadevicecollection/MediaDeviceCollection.h" 0023 0024 #include <KJob> 0025 #include <KLocalizedString> 0026 #include <kio/job.h> 0027 #include <kio/jobclasses.h> 0028 0029 using namespace Collections; 0030 0031 MediaDeviceCollectionLocation::MediaDeviceCollectionLocation( MediaDeviceCollection *collection ) 0032 : CollectionLocation( collection ) 0033 , m_collection( collection ) 0034 , m_handler( m_collection->handler() ) 0035 { 0036 //nothing to do 0037 } 0038 0039 MediaDeviceCollectionLocation::~MediaDeviceCollectionLocation() 0040 { 0041 //nothing to do 0042 } 0043 0044 QString 0045 MediaDeviceCollectionLocation::prettyLocation() const 0046 { 0047 return collection()->prettyName(); 0048 } 0049 0050 bool 0051 MediaDeviceCollectionLocation::isWritable() const 0052 { 0053 return m_handler->isWritable(); 0054 } 0055 0056 void 0057 MediaDeviceCollectionLocation::getKIOCopyableUrls( const Meta::TrackList &tracks ) 0058 { 0059 connect( m_handler, &Meta::MediaDeviceHandler::gotCopyableUrls, this, &MediaDeviceCollectionLocation::slotGetKIOCopyableUrlsDone ); 0060 m_handler->getCopyableUrls( tracks ); 0061 } 0062 0063 0064 void 0065 MediaDeviceCollectionLocation::copyUrlsToCollection( const QMap<Meta::TrackPtr, QUrl> &sources, 0066 const Transcoding::Configuration &configuration ) 0067 { 0068 DEBUG_BLOCK 0069 Q_UNUSED( configuration ) 0070 0071 connect( m_handler, &Meta::MediaDeviceHandler::copyTracksDone, 0072 this, &MediaDeviceCollectionLocation::copyOperationFinished, 0073 Qt::QueuedConnection ); 0074 m_handler->copyTrackListToDevice( sources.keys() ); 0075 0076 /* 0077 connect( m_collection, SIGNAL(copyTracksCompleted(bool)), 0078 SLOT(copyOperationFinished(bool)) ); 0079 0080 // Copy list of tracks 0081 m_collection->copyTrackListToDevice( sources.keys() ); 0082 */ 0083 0084 // TODO: call handler's method for copying a list of 0085 // tracks to the device. At the end, if successful, 0086 // write to database, and any unsuccessful track 0087 // copies will generate warning/error messages 0088 } 0089 0090 void 0091 MediaDeviceCollectionLocation::copyOperationFinished( bool success ) 0092 { 0093 // TODO: should connect database written signal to 0094 // to this slot 0095 0096 if( success ) 0097 { 0098 m_handler->writeDatabase(); 0099 } 0100 // TODO: will be replaced with a more powerful method 0101 // which deals with particular reasons for failed copies 0102 /* 0103 DEBUG_BLOCK 0104 if( !success ) 0105 { 0106 QMap<Meta::TrackPtr, QString> failedTracks = m_collection->handler()->tracksFailed(); 0107 debug() << "The following tracks failed to copy"; 0108 foreach( Meta::TrackPtr track, failedTracks.keys() ) 0109 { 0110 // TODO: better error handling 0111 debug() << track->artist()->name() << " - " << track->name() << " with error: " << failedTracks[ track ]; 0112 source()->transferError( track, failedTracks[ track ] ); 0113 } 0114 } 0115 */ 0116 slotCopyOperationFinished(); 0117 } 0118 0119 void 0120 MediaDeviceCollectionLocation::removeUrlsFromCollection( const Meta::TrackList &sources ) 0121 { 0122 DEBUG_BLOCK 0123 connect( m_handler, &Meta::MediaDeviceHandler::removeTracksDone, 0124 this, &MediaDeviceCollectionLocation::removeOperationFinished ); 0125 0126 m_handler->removeTrackListFromDevice( sources ); 0127 } 0128 0129 void 0130 MediaDeviceCollectionLocation::removeOperationFinished() 0131 { 0132 DEBUG_BLOCK 0133 0134 m_handler->writeDatabase(); 0135 0136 slotRemoveOperationFinished(); 0137 } 0138 0139