File indexing completed on 2024-05-05 04:49:22
0001 /**************************************************************************************** 0002 * Copyright (c) 2009 Maximilian Kossick <maximilian.kossick@googlemail.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 "MasterSlaveSynchronizationJob.h" 0018 0019 #include "core/collections/Collection.h" 0020 #include "core/collections/CollectionLocation.h" 0021 #include "core/support/Debug.h" 0022 0023 MasterSlaveSynchronizationJob::MasterSlaveSynchronizationJob() 0024 : SynchronizationBaseJob() 0025 , m_master( nullptr ) 0026 , m_slave( nullptr ) 0027 { 0028 0029 } 0030 0031 MasterSlaveSynchronizationJob::~MasterSlaveSynchronizationJob() 0032 { 0033 } 0034 0035 void 0036 MasterSlaveSynchronizationJob::setMaster( Collections::Collection *master ) 0037 { 0038 m_master = master; 0039 setCollectionA( master ); 0040 } 0041 0042 void 0043 MasterSlaveSynchronizationJob::setSlave( Collections::Collection *slave ) 0044 { 0045 m_slave = slave; 0046 setCollectionB( slave ); 0047 } 0048 0049 void 0050 MasterSlaveSynchronizationJob::doSynchronization( const Meta::TrackList &tracks, InSet syncDirection, Collections::Collection *collA, Collections::Collection *collB ) 0051 { 0052 DEBUG_BLOCK 0053 if( !( syncDirection == OnlyInA || syncDirection == OnlyInB ) ) 0054 { 0055 debug() << "warning, received an unexpected syncDirection"; 0056 return; 0057 } 0058 if( !( m_master == collA || m_master == collB ) || !( m_slave == collA || m_slave == collB ) ) 0059 { 0060 debug() << "warning, received an unknown collection"; 0061 return; 0062 } 0063 if( !m_slave->isWritable() ) 0064 { 0065 debug() << "Error: slave collection " << m_slave->collectionId() << " is not writable"; 0066 return; 0067 } 0068 if( ( syncDirection == OnlyInA && collA == m_master ) || ( syncDirection == OnlyInB && collB == m_master ) ) 0069 { 0070 debug() << "Master " << m_master->collectionId() << " has to sync " << tracks.count() << " track(s) to " << m_slave->collectionId(); 0071 Collections::CollectionLocation *masterLoc = m_master->location(); 0072 Collections::CollectionLocation *slaveLoc = m_slave->location(); 0073 masterLoc->prepareCopy( tracks, slaveLoc ); 0074 } 0075 else 0076 { 0077 //we have tested for the correct synDirections and the correct collections above, 0078 //so these are definitely the tracks that have to be removed from the slave 0079 debug() << "Delete " << tracks.count() << " track(s) from slave " << m_slave->collectionId(); 0080 //do some more stuff, and *really* show a confirmation dialog 0081 Collections::CollectionLocation *slaveLoc = m_slave->location(); 0082 slaveLoc->prepareRemove( tracks ); 0083 } 0084 }