File indexing completed on 2025-01-05 04:26:01
0001 /**************************************************************************************** 0002 * Copyright (c) 2012 Matěj Laitl <matej@laitl.cz> * 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 #ifndef IPODPLAYLISTPROVIDER_H 0018 #define IPODPLAYLISTPROVIDER_H 0019 0020 #include "IpodPlaylist.h" 0021 0022 #include "core-impl/playlists/providers/user/UserPlaylistProvider.h" 0023 0024 0025 class IpodCollection; 0026 struct _Itdb_iTunesDB; 0027 typedef _Itdb_iTunesDB Itdb_iTunesDB; 0028 0029 class IpodPlaylistProvider : public Playlists::UserPlaylistProvider, private Playlists::PlaylistObserver 0030 { 0031 Q_OBJECT 0032 0033 public: 0034 explicit IpodPlaylistProvider( IpodCollection *collection ); 0035 virtual ~IpodPlaylistProvider(); 0036 0037 // PlaylistProvider methods: 0038 QString prettyName() const override; 0039 QIcon icon() const override; 0040 0041 int playlistCount() const override; 0042 Playlists::PlaylistList playlists() override; 0043 0044 Playlists::PlaylistPtr addPlaylist(Playlists::PlaylistPtr playlist ) override; 0045 Meta::TrackPtr addTrack( const Meta::TrackPtr &track ) override; 0046 0047 // UserPlaylistProvider methods: 0048 Playlists::PlaylistPtr save( const Meta::TrackList &tracks, 0049 const QString& name = QString() ) override; 0050 0051 QActionList providerActions() override; 0052 QActionList playlistActions( const Playlists::PlaylistList &playlists ) override; 0053 QActionList trackActions( const QMultiHash<Playlists::PlaylistPtr, int> &playlistTracks ) override; 0054 0055 bool isWritable() override; 0056 void renamePlaylist( Playlists::PlaylistPtr playlist, const QString &newName ) override; 0057 bool deletePlaylists( const Playlists::PlaylistList &playlistlist ) override; 0058 0059 // PlaylistObserver methods: 0060 void metadataChanged( const Playlists::PlaylistPtr &playlist ) override; 0061 void trackAdded( const Playlists::PlaylistPtr &playlist, const Meta::TrackPtr &track, int position ) override; 0062 void trackRemoved( const Playlists::PlaylistPtr &playlist, int position ) override; 0063 0064 // IpodPlaylistProvider specific methods: 0065 /** 0066 * Copy tracks stored in playlists tracksToCopy() to iPod and them add them to the 0067 * playlist. The actual call to start copying tracks is deferred to next eventloop 0068 * iteration to pickup multiple successive addTrack() calls. 0069 */ 0070 void scheduleCopyAndInsertToPlaylist( AmarokSharedPointer<IpodPlaylist> playlist ); 0071 0072 /** 0073 * Remove this track from all playlists it belongs to, it was removed from the 0074 * database. The @param track is the MemoryMeta proxy track. 0075 */ 0076 void removeTrackFromPlaylists( Meta::TrackPtr track ); 0077 0078 /** 0079 * Return true whether there are some stale & orphaned files/entries in iTunes db 0080 */ 0081 bool hasStaleOrOrphaned() const; 0082 0083 public Q_SLOTS: 0084 /** 0085 * Re-add orphaned files to db and remove stale iTunes database entries. Meant to 0086 * be connected to the respective QAction. 0087 */ 0088 void slotConsolidateStaleOrphaned(); 0089 0090 Q_SIGNALS: 0091 /** 0092 * Signals to IpodCollection that the database has been dirtied and it has to 0093 * write the database in some point in time. 0094 */ 0095 void startWriteDatabaseTimer(); 0096 0097 private Q_SLOTS: 0098 void slotCopyAndInsertToPlaylists(); 0099 0100 private: 0101 friend class IpodParseTracksJob; 0102 0103 void copyAndInsertToPlaylist( const TrackPositionList &tracks, Playlists::PlaylistPtr destPlaylist ); 0104 bool orphanedAndStaleTracksMatch( const Meta::TrackPtr &orphaned, const Meta::TrackPtr &stale ); 0105 template <class T> bool entitiesDiffer( T first, T second ); 0106 0107 IpodCollection *m_coll; 0108 Playlists::PlaylistList m_playlists; 0109 QSet< AmarokSharedPointer<IpodPlaylist> > m_copyTracksTo; 0110 Playlists::PlaylistPtr m_stalePlaylist; 0111 Playlists::PlaylistPtr m_orphanedPlaylist; 0112 }; 0113 0114 #endif // IPODPLAYLISTPROVIDER_H