File indexing completed on 2024-05-05 04:48:50

0001 /****************************************************************************************
0002  * Copyright (c) 2007 Maximilian Kossick <maximilian.kossick@googlemail.com>            *
0003  * Copyright (c) 2008 Seb Ruiz <ruiz@kde.org>                                           *
0004  * Copyright (c) 2009-2010 Jeff Mitchell <mitchell@kde.org>                             *
0005  * Copyright (c) 2013 Ralf Engels <ralf-engels@gmx.de>                                  *
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 ABSTRACT_SCAN_RESULTPROCESSOR_H
0021 #define ABSTRACT_SCAN_RESULTPROCESSOR_H
0022 
0023 #include "amarok_export.h"
0024 #include "GenericScanManager.h"
0025 
0026 #include <QList>
0027 #include <QHash>
0028 #include <QMultiHash>
0029 #include <QPair>
0030 #include <QSet>
0031 #include <QString>
0032 #include <QStringList>
0033 
0034 namespace CollectionScanner
0035 {
0036     class Track;
0037     class Directory;
0038     class Album;
0039     class Playlist;
0040 }
0041 class GenericScanManager;
0042 template<class T >
0043 class QSharedPointer;
0044 
0045 /** The ScanResulProcessor class connects to a GenericScanManager and
0046  *  adds further processing to the directoryScanned signal.
0047  *
0048  *  The AbstractScanResultProcessor can determine if tracks need to be removed
0049  *  and better sort Tracks into albums.
0050  */
0051 class AMAROK_EXPORT AbstractScanResultProcessor : public QObject
0052 {
0053     Q_OBJECT
0054 
0055     public:
0056         explicit AbstractScanResultProcessor( GenericScanManager* manager, QObject* parent = nullptr );
0057         ~AbstractScanResultProcessor() override;
0058 
0059     Q_SIGNALS:
0060         /** Those signals can be connected to a progress bar to get progress information
0061          *  from the scanner.
0062          */
0063         void endProgressOperation( QObject * );
0064         void incrementProgress();
0065         void totalSteps( int totalSteps );
0066 
0067     protected Q_SLOTS:
0068         // Signals received from the ScanManager.
0069         // They must be send in the correct order:
0070         // first scanStarted
0071         // then scandirectoryCount, scanDirectoryScanned in no particular order number
0072         // then scanSucceeded or scanFailed.
0073 
0074         virtual void scanStarted( GenericScanManager::ScanType type );
0075 
0076         virtual void scanDirectoryCount( int count );
0077 
0078         /** Submits a new directory for processing. */
0079         virtual void scanDirectoryScanned( QSharedPointer<CollectionScanner::Directory> dir );
0080 
0081         virtual void scanSucceeded();
0082         virtual void scanFailed( const QString& message );
0083 
0084         virtual void abort();
0085 
0086     protected:
0087         /** This are status messages that the scanner emits frequently.
0088          *  You can collect them and display later.
0089          */
0090         virtual void message( const QString& message ) = 0;
0091 
0092         virtual void commitDirectory( QSharedPointer<CollectionScanner::Directory> dir );
0093         virtual void commitPlaylist( const CollectionScanner::Playlist &playlist );
0094         virtual void commitAlbum( CollectionScanner::Album *album ) = 0;
0095         virtual void commitTrack( CollectionScanner::Track *track, CollectionScanner::Album *srcAlbum ) = 0;
0096 
0097         /**
0098          * Delete directories (and their tracks) that have been deleted.
0099          *
0100          * In FullScan nad UpdateScan mode, it should delete all database directories on
0101          * mounted filesystems not encountered in the scan.
0102          *
0103          * In PartialUpdateScan mode, things are more complicated. It should only delete
0104          * not-encountered (direct) subdirectories of directories passed to
0105          * deleteDeletedTracksAndSubdirs(). However, if such directory is deleted, all its
0106          * subdirectories should be removed too.
0107          */
0108         virtual void deleteDeletedDirectories() = 0;
0109 
0110         virtual void deleteDeletedTracksAndSubdirs( QSharedPointer<CollectionScanner::Directory> directory ) = 0;
0111 
0112         CollectionScanner::Album* sortTrack( CollectionScanner::Track *track,
0113                                              const QString &dirName = QString() );
0114 
0115         /** Cleans up all the stuff that the processor picked up through
0116          *  the commit methods.
0117          *  This function is called by scanSucceeded and scanFailed.
0118          */
0119         virtual void cleanupMembers();
0120 
0121         GenericScanManager* m_manager;
0122 
0123         QList<QSharedPointer<CollectionScanner::Directory> > m_directories;
0124 
0125         // The keys for this hashtable are album name, artist (artist is empty for compilations)
0126         typedef QPair<QString, QString> AlbumKey;
0127 
0128         QHash<AlbumKey, CollectionScanner::Album*> m_albums;
0129         // all the albums sorted by album name
0130         QMultiHash<QString, CollectionScanner::Album*> m_albumNames;
0131 
0132         GenericScanManager::ScanType m_type;
0133 };
0134 
0135 #endif