File indexing completed on 2025-01-19 04:24:23
0001 /**************************************************************************************** 0002 * Copyright (c) 2007 Maximilian Kossick <maximilian.kossick@googlemail.com> * 0003 * Copyright (c) 2008 Jason A. Donenfeld <Jason@zx2c4.com> * 0004 * Copyright (c) 2010 Casey Link <unnamedrambler@gmail.com> * 0005 * Copyright (c) 2010 Teo Mrnjavac <teo@kde.org> * 0006 * * 0007 * This program is free software; you can redistribute it and/or modify it under * 0008 * the terms of the GNU General Public License as published by the Free Software * 0009 * Foundation; either version 2 of the License, or (at your option) any later * 0010 * version. * 0011 * * 0012 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0013 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0014 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0015 * * 0016 * You should have received a copy of the GNU General Public License along with * 0017 * this program. If not, see <http://www.gnu.org/licenses/>. * 0018 ****************************************************************************************/ 0019 0020 #ifndef AMAROK_SQLCOLLECTIONLOCATION_H 0021 #define AMAROK_SQLCOLLECTIONLOCATION_H 0022 0023 #include "amarok_sqlcollection_export.h" 0024 #include "core/collections/CollectionLocation.h" 0025 0026 #include <KJob> 0027 #include <KCompositeJob> 0028 #include <QSet> 0029 #include <QMap> 0030 #include <QString> 0031 0032 class OrganizeCollectionDelegateFactory; 0033 0034 namespace Collections { 0035 0036 class SqlCollection; 0037 0038 class SqlCollectionLocation; 0039 0040 /** 0041 * @class TransferJob 0042 * A simple class that provides KJob functionality (progress reporting, aborting, etc) for sqlcollectionlocation. 0043 * It calls SqlCollectionLocation::startNextJob() 0044 */ 0045 class TransferJob : public KCompositeJob 0046 { 0047 Q_OBJECT 0048 public: 0049 TransferJob( SqlCollectionLocation * location, const Transcoding::Configuration & configuration ); 0050 0051 void start() override; 0052 bool addSubjob( KJob* job ) override; 0053 0054 void emitInfo( const QString &message ); 0055 public Q_SLOTS: 0056 /** 0057 * A move or copy job finished 0058 */ 0059 void slotJobFinished( KJob *job ); 0060 protected Q_SLOTS: 0061 void slotResult( KJob *job ) override; 0062 void doWork(); 0063 void propagateProcessedAmount( KJob *job, KJob::Unit unit, qulonglong amount); 0064 protected: 0065 bool doKill() override; 0066 private: 0067 SqlCollectionLocation* m_location; 0068 bool m_killed; 0069 Transcoding::Configuration m_transcodeFormat; 0070 }; 0071 0072 class AMAROK_SQLCOLLECTION_EXPORT SqlCollectionLocation : public CollectionLocation 0073 { 0074 Q_OBJECT 0075 0076 public: 0077 explicit SqlCollectionLocation( SqlCollection *collection ); 0078 ~SqlCollectionLocation() override; 0079 0080 QString prettyLocation() const override; 0081 QStringList actualLocation() const override; 0082 bool isWritable() const override; 0083 bool isOrganizable() const override; 0084 0085 bool remove( const Meta::TrackPtr &track ); 0086 bool insert( const Meta::TrackPtr &track, const QString &path ) override; 0087 0088 //dependency injectors 0089 void setOrganizeCollectionDelegateFactory( OrganizeCollectionDelegateFactory *fac ); 0090 0091 protected: 0092 void showDestinationDialog( const Meta::TrackList &tracks, 0093 bool removeSources, 0094 const Transcoding::Configuration &configuration ) override; 0095 void copyUrlsToCollection( const QMap<Meta::TrackPtr, QUrl> &sources, 0096 const Transcoding::Configuration & configuration ) override; 0097 void removeUrlsFromCollection( const Meta::TrackList &sources ) override; 0098 0099 private Q_SLOTS: 0100 void slotDialogAccepted(); 0101 void slotDialogRejected(); 0102 void slotJobFinished( KJob *job ); 0103 void slotRemoveJobFinished( KJob *job ); 0104 void slotTransferJobFinished( KJob *job ); 0105 void slotTransferJobAborted(); 0106 0107 private: 0108 QUrl moodFile( const QUrl &track ) const; 0109 void migrateLabels( const QMap<Meta::TrackPtr, QString> &trackMap ); 0110 bool startNextJob(const Transcoding::Configuration &configuration ); 0111 bool startNextRemoveJob(); 0112 0113 Collections::SqlCollection *m_collection; 0114 OrganizeCollectionDelegateFactory *m_delegateFactory; 0115 QMap<Meta::TrackPtr, QString> m_destinations; 0116 QMap<Meta::TrackPtr, QUrl> m_sources; 0117 Meta::TrackList m_removetracks; 0118 QHash<Meta::TrackPtr, QUrl> m_originalUrls; 0119 bool m_overwriteFiles; 0120 QMap<KJob*, Meta::TrackPtr> m_jobs; 0121 QMap<KJob*, Meta::TrackPtr> m_removejobs; 0122 TransferJob* m_transferjob; 0123 friend class TransferJob; // so the transfer job can run the jobs 0124 }; 0125 0126 class SqlCollectionLocationFactory 0127 { 0128 public: 0129 virtual SqlCollectionLocation* createSqlCollectionLocation() const = 0; 0130 virtual ~SqlCollectionLocationFactory() {} 0131 }; 0132 0133 } //namespace Collections 0134 0135 class AMAROK_SQLCOLLECTION_EXPORT OrganizeCollectionDelegate : public QObject 0136 { 0137 Q_OBJECT 0138 public: 0139 OrganizeCollectionDelegate() : QObject() {} 0140 ~ OrganizeCollectionDelegate() override {} 0141 0142 virtual void setTracks( const Meta::TrackList &tracks ) = 0; 0143 virtual void setFolders( const QStringList &folders ) = 0; 0144 virtual void setIsOrganizing( bool organizing ) = 0; 0145 virtual void setTranscodingConfiguration( const Transcoding::Configuration &configuration ) = 0; 0146 virtual void setCaption( const QString &caption ) = 0; 0147 0148 virtual void show() = 0; 0149 0150 virtual bool overwriteDestinations() const = 0; 0151 virtual QMap<Meta::TrackPtr, QString> destinations() const = 0; 0152 0153 Q_SIGNALS: 0154 void accepted(); 0155 void rejected(); 0156 }; 0157 0158 class OrganizeCollectionDelegateFactory 0159 { 0160 public: 0161 virtual OrganizeCollectionDelegate* createDelegate() = 0; 0162 virtual ~OrganizeCollectionDelegateFactory() {} 0163 }; 0164 0165 #endif