Make plasma libs build.
[amarok.git] / src / collection / CollectionLocation.cpp
blobfdcb37cd90826564618c2b2bc661861df7025227
1 /*
2 * Copyright (c) 2007 Maximilian Kossick <maximilian.kossick@googlemail.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #include "CollectionLocation.h"
20 #include "Collection.h"
22 CollectionLocation::CollectionLocation()
23 :QObject()
25 //nothing to do
28 CollectionLocation::CollectionLocation( const Collection* parentCollection)
29 :QObject()
31 m_parentCollection = parentCollection;
34 CollectionLocation::~CollectionLocation()
36 //nothing to do
39 const Collection*
40 CollectionLocation::collection() const
42 return m_parentCollection;
45 QString
46 CollectionLocation::prettyLocation() const
48 return QString();
51 bool
52 CollectionLocation::isWriteable() const
54 return false;
57 void
58 CollectionLocation::prepareCopy( Meta::TrackPtr track, CollectionLocation *destination )
60 Meta::TrackList list;
61 list.append( track );
62 prepareCopy( list, destination );
66 void
67 CollectionLocation::prepareCopy( const Meta::TrackList &tracks, CollectionLocation *destination )
69 if( !destination->isWriteable() )
70 return;
71 m_destination = destination;
72 setupConnections();
73 KUrl::List urls = getKIOCopyableUrls( tracks );
74 emit startCopy( urls, false );
77 void
78 CollectionLocation::prepareMove( Meta::TrackPtr track, CollectionLocation *destination )
80 Meta::TrackList list;
81 list.append( track );
82 prepareMove( list, destination );
85 void
86 CollectionLocation::prepareMove( const Meta::TrackList &tracks, CollectionLocation *destination )
88 if( !destination->isWriteable() )
89 return;
90 m_destination = destination;
91 setupConnections();
92 KUrl::List urls = getKIOCopyableUrls( tracks );
93 emit startCopy( urls, true );
96 bool
97 CollectionLocation::remove( Meta::TrackPtr track )
99 Q_UNUSED( track )
100 return false;
103 KUrl::List
104 CollectionLocation::getKIOCopyableUrls( const Meta::TrackList &tracks )
106 KUrl::List urls;
107 foreach( Meta::TrackPtr track, tracks )
108 if( track->isPlayable() )
109 urls.append( track->playableUrl() );
111 return urls;
114 void
115 CollectionLocation::copyUrlsToCollection( const KUrl::List &sources )
117 //reimplement in implementations which are writeable
118 Q_UNUSED( sources )
119 slotCopyOperationFinished();
122 void
123 CollectionLocation::slotCopyOperationFinished()
125 emit finishCopy( m_removeSources );
128 void
129 CollectionLocation::slotStartCopy( const KUrl::List &sources, bool removeSources )
131 m_removeSources = removeSources;
132 copyUrlsToCollection( sources );
135 void
136 CollectionLocation::slotFinishCopy( bool removeSources )
138 if( removeSources )
139 removeSourceTracks( m_sourceTracks );
140 m_sourceTracks.clear();
141 m_destination->deleteLater();
142 this->deleteLater();
145 void
146 CollectionLocation::setupConnections()
148 connect( this, SIGNAL( startCopy( KUrl::List, bool ) ),
149 m_destination, SLOT( slotStartCopy( KUrl::List, bool ) ) );
150 connect( m_destination, SIGNAL( finishCopy( bool ) ),
151 this, SLOT( slotFinishCopy( bool ) ) );
154 void
155 CollectionLocation::removeSourceTracks( const Meta::TrackList &tracks )
157 Meta::TrackList notDeletableTracks;
158 foreach( Meta::TrackPtr track, tracks )
160 if( !remove( track ) )
161 notDeletableTracks.append( track );
163 //TODO inform user about tracks which were not deleted
166 #include "CollectionLocation.moc"