File indexing completed on 2024-05-05 04:49:23

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 "UnionJob.h"
0018 
0019 #include "core/collections/Collection.h"
0020 #include "core/collections/CollectionLocation.h"
0021 #include "core/support/Debug.h"
0022 
0023 UnionJob::UnionJob( Collections::Collection *collA, Collections::Collection *collB )
0024         : SynchronizationBaseJob()
0025 {
0026     DEBUG_BLOCK
0027     setCollectionA( collA );
0028     setCollectionB( collB );
0029 }
0030 
0031 UnionJob::~UnionJob()
0032 {
0033     //nothing to do
0034 }
0035 
0036 void
0037 UnionJob::doSynchronization( const Meta::TrackList &tracks, InSet syncDirection, Collections::Collection *collA, Collections::Collection *collB )
0038 {
0039     DEBUG_BLOCK
0040     if( !( syncDirection == OnlyInA || syncDirection == OnlyInB ) )
0041     {
0042         debug() << "warning, received an unexpected syncDirection";
0043         return;
0044     }
0045     Collections::Collection *from = ( syncDirection == OnlyInA ? collA : collB );
0046     Collections::Collection *to = ( syncDirection == OnlyInA ? collB : collA );
0047 
0048     debug() << "Collection " << from->collectionId() << " has to sync " << tracks.count() << " track(s) to " << to->collectionId();
0049     //show confirmation dialog, actually do stuff
0050     Collections::CollectionLocation *fromLoc = from->location();
0051     Collections::CollectionLocation *toLoc = to->location();
0052 
0053     if( !toLoc->isWritable() )
0054     {
0055         debug() << "Collection " << to->collectionId() << " is not writable";
0056         fromLoc->deleteLater();
0057         toLoc->deleteLater();
0058     }
0059     else
0060     {
0061         fromLoc->prepareCopy( tracks, toLoc );
0062     }
0063 }