MythTV
master
|
Image Scanner thread requires a database/filesystem adapter. More...
#include <libmythmetadata/imagescanner.h>
Public Member Functions | |
ImageScanThread (DBFS *dbfs, ImageThumb< DBFS > *thumbGen) | |
Constructor. More... | |
~ImageScanThread () override | |
void | cancel () |
Clears queued items so that the thread can exit. More... | |
bool | IsScanning () |
Return current scanner status. More... | |
bool | ClearsPending () |
Get status of 'clear device' queue. More... | |
void | ChangeState (bool scan) |
Run or interrupt scanner. More... | |
void | EnqueueClear (int devId, const QString &action) |
Queues a 'Clear Device' request, which will be actioned immediately. More... | |
QStringList | GetProgress () |
Returns number of images scanned & total number to scan. More... | |
Public Member Functions inherited from MThread | |
MThread (const QString &objectName) | |
Standard constructor. More... | |
MThread (const QString &objectName, QRunnable *runnable) | |
Use this constructor if you want the default run() method to run the QRunnable's run() method instead of entering the Qt event loop. More... | |
virtual | ~MThread () |
MThread (const MThread &)=delete | |
MThread & | operator= (const MThread &)=delete |
void | RunProlog (void) |
Sets up a thread, call this if you reimplement run(). More... | |
void | RunEpilog (void) |
Cleans up a thread's resources, call this if you reimplement run(). More... | |
QThread * | qthread (void) |
Returns the thread, this will always return the same pointer no matter how often you restart the thread. More... | |
void | setObjectName (const QString &name) |
QString | objectName (void) const |
void | setPriority (QThread::Priority priority) |
QThread::Priority | priority (void) const |
bool | isFinished (void) const |
bool | isRunning (void) const |
void | setStackSize (uint stackSize) |
uint | stackSize (void) const |
void | exit (int retcode=0) |
Use this to exit from the thread if you are using a Qt event loop. More... | |
void | start (QThread::Priority p=QThread::InheritPriority) |
Tell MThread to start running the thread in the near future. More... | |
void | terminate (void) |
Kill a thread unsafely. More... | |
void | quit (void) |
calls exit(0) More... | |
bool | wait (std::chrono::milliseconds time=std::chrono::milliseconds::max()) |
Wait for the MThread to exit, with a maximum timeout. More... | |
Protected Member Functions | |
void | run () override |
Synchronises database to the storage group. More... | |
Protected Member Functions inherited from MThread | |
int | exec (void) |
Enters the qt event loop. call exit or quit to exit thread. More... | |
Private Types | |
using | ClearTask = QPair< int, QString > |
Private Member Functions | |
void | SyncSubTree (const QFileInfo &dirInfo, int parentId, int devId, const QString &base) |
Scans a dir subtree. More... | |
int | SyncDirectory (const QFileInfo &dirInfo, int devId, const QString &base, int parentId) |
Updates/populates db for a dir. More... | |
void | PopulateMetadata (const QString &path, int type, QString &comment, std::chrono::seconds &time, int &orientation) |
Read image date, orientation, comment from metadata. More... | |
void | SyncFile (const QFileInfo &fileInfo, int devId, const QString &base, int parentId) |
Updates/populates db for an image/video file. More... | |
void | CountTree (QDir &dir) |
Counts images in a dir subtree. More... | |
void | CountFiles (const QStringList &paths) |
Counts images in a list of subtrees. More... | |
void | Broadcast (int progress) |
Notify listeners of scan progress. More... | |
Private Attributes | |
bool | m_scanning {false} |
The requested scan state. More... | |
QMutex | m_mutexState |
Mutex protecting scan state. More... | |
QList< ClearTask > | m_clearQueue |
Queue of pending Clear requests. More... | |
QMutex | m_mutexQueue |
Mutex protecting Clear requests. More... | |
DBFS & | m_dbfs |
Database/filesystem adapter. More... | |
ImageThumb< DBFS > & | m_thumb |
Companion thumbnail generator. More... | |
ImageHash | m_dbDirMap |
Dirs in the Db from last scan, Map<Db filepath, Db Image> More... | |
ImageHash | m_dbFileMap |
Files in the Db from last scan, Map<Db filepath, Db Image> More... | |
ImageHash | m_seenDir |
Dirs seen by current scan, Map<Db filepath, Earlier Image> More... | |
NameHash | m_seenFile |
Files seen by current scan Map <Db filepath, Earlier abs filepath> More... | |
QStringList | m_changedImages |
Ids of dirs/files that have been updates/modified. More... | |
QElapsedTimer | m_bcastTimer |
Elapsed time since last progress event generated. More... | |
int | m_progressCount {0} |
Number of images scanned. More... | |
int | m_progressTotalCount {0} |
Total number of images to scan. More... | |
QMutex | m_mutexProgress |
Progress counts mutex. More... | |
QDir | m_dir |
Global working dir for file detection. More... | |
QRegularExpression | m_exclusions |
Pattern of dir names to ignore whilst scanning. More... | |
Additional Inherited Members | |
Static Public Member Functions inherited from MThread | |
static void | ThreadSetup (const QString &name) |
This is to be called on startup in those few threads that haven't been ported to MThread. More... | |
static void | ThreadCleanup (void) |
This is to be called on exit in those few threads that haven't been ported to MThread. More... | |
static void | Cleanup (void) |
This will print out all the running threads, call exit(1) on each and then wait up to 5 seconds total for all the threads to exit. More... | |
static void | GetAllThreadNames (QStringList &list) |
static void | GetAllRunningThreadNames (QStringList &list) |
Static Protected Member Functions inherited from MThread | |
static void | setTerminationEnabled (bool enabled=true) |
static void | usleep (std::chrono::microseconds time) |
template<typename R , typename P > | |
static std::enable_if_t< std::chrono::treat_as_floating_point< R >::value, void > | usleep (std::chrono::duration< R, P > time) |
Protected Attributes inherited from MThread | |
MThreadInternal * | m_thread {nullptr} |
QRunnable * | m_runnable {nullptr} |
bool | m_prologExecuted {true} |
bool | m_epilogExecuted {true} |
Image Scanner thread requires a database/filesystem adapter.
Definition at line 25 of file imagescanner.h.
|
private |
Definition at line 57 of file imagescanner.h.
ImageScanThread< DBFS >::ImageScanThread | ( | DBFS * | dbfs, |
ImageThumb< DBFS > * | thumbGen | ||
) |
Constructor.
dbfs | Database/filesystem adapter |
thumbGen | Companion thumbnail generator |
Definition at line 14 of file imagescanner.cpp.
|
override |
Definition at line 23 of file imagescanner.cpp.
void ImageScanThread< DBFS >::cancel |
Clears queued items so that the thread can exit.
Definition at line 34 of file imagescanner.cpp.
bool ImageScanThread< DBFS >::IsScanning |
Return current scanner status.
Definition at line 50 of file imagescanner.cpp.
bool ImageScanThread< DBFS >::ClearsPending |
Get status of 'clear device' queue.
Definition at line 62 of file imagescanner.cpp.
void ImageScanThread< DBFS >::ChangeState | ( | bool | scan | ) |
Run or interrupt scanner.
Clear requests are actioned before and after every scan
scan | If true, scan will start after pending clears are actioned If false, a running scan is interrupted. Pending clear requests will be actioned. |
Definition at line 77 of file imagescanner.cpp.
void ImageScanThread< DBFS >::EnqueueClear | ( | int | devId, |
const QString & | action | ||
) |
Queues a 'Clear Device' request, which will be actioned immediately.
If scanner is already running, any scan will be aborted to process the clear.
devId | Device id |
action | [DEVICE] (CLOSE | CLEAR) |
Definition at line 96 of file imagescanner.cpp.
QStringList ImageScanThread< DBFS >::GetProgress |
Returns number of images scanned & total number to scan.
Definition at line 111 of file imagescanner.cpp.
|
overrideprotectedvirtual |
Synchronises database to the storage group.
Scans all dirs and files and populates database with metadata for each. Broadcasts progress events whilst scanning, initiates thumbnail generation and notifies clients when finished.
Reimplemented from MThread.
Definition at line 126 of file imagescanner.cpp.
|
private |
Scans a dir subtree.
Uses a recursive depth-first scan to detect all files matching image/video filters. Dirs that match exclusions regexp are ignored.
dirInfo | Dir info at root of this subtree |
parentId | Id of parent dir |
devId | Device id being scanned |
base | Root device path |
Definition at line 240 of file imagescanner.cpp.
|
private |
Updates/populates db for a dir.
Db is updated if dir modified time has changed since last scan. Contents are scanned even if dir is unchanged. Clones are dirs within the Storage Group with the same path (relative to SG). They resolve to a single Db dir - their contents are amalgamated. ie. <SG dir 1>/somePath/dirName and <SG dir 2>/somePath/dirName result in a single Gallery dir of "somePath/dirName"
dirInfo | Dir info |
devId | Id of device containing dir |
base | Device path |
parentId | Db id of the dir's parent |
Definition at line 315 of file imagescanner.cpp.
|
private |
Read image date, orientation, comment from metadata.
[in] | path | Image filepath |
[in] | type | Picture or Video |
[out] | comment | Image comment |
[out] | time | Time/date of image capture |
[out] | orientation | Exif orientation code |
Definition at line 411 of file imagescanner.cpp.
|
private |
Updates/populates db for an image/video file.
Db is updated if file modified time has changed since last scan. Extracts orientation, date and 2 comments from exif/video metadata. Duplicates are files within the Storage Group with the same path (relative to SG). They are invalid (user error?) - only the first is accepted; others are ignored. ie. <SG dir 1>/somePath/fileName and <SG dir 2>/somePath/fileName result in a single image from <SG dir 1>. This is consistent with StorageGroup::FindFile(), which will never find the second file.
fileInfo | File info |
devId | Id of device containing dir |
base | Device path |
parentId | Db id of the dir's parent |
Definition at line 445 of file imagescanner.cpp.
|
private |
Counts images in a dir subtree.
Ignores dirs that match exclusions regexp
dir | Root of subtree |
Definition at line 541 of file imagescanner.cpp.
|
private |
Counts images in a list of subtrees.
paths | List of dir trees to scan |
Definition at line 569 of file imagescanner.cpp.
|
private |
Notify listeners of scan progress.
progress | Number of images processed |
Definition at line 610 of file imagescanner.cpp.
|
private |
The requested scan state.
Definition at line 59 of file imagescanner.h.
|
private |
Mutex protecting scan state.
Definition at line 60 of file imagescanner.h.
|
private |
Queue of pending Clear requests.
Definition at line 61 of file imagescanner.h.
|
private |
Mutex protecting Clear requests.
Definition at line 62 of file imagescanner.h.
|
private |
Database/filesystem adapter.
Definition at line 63 of file imagescanner.h.
|
private |
Companion thumbnail generator.
Definition at line 64 of file imagescanner.h.
|
private |
Dirs in the Db from last scan, Map<Db filepath, Db Image>
Definition at line 67 of file imagescanner.h.
|
private |
Files in the Db from last scan, Map<Db filepath, Db Image>
Definition at line 69 of file imagescanner.h.
|
private |
Dirs seen by current scan, Map<Db filepath, Earlier Image>
Definition at line 71 of file imagescanner.h.
|
private |
Files seen by current scan Map <Db filepath, Earlier abs filepath>
Definition at line 73 of file imagescanner.h.
|
private |
Ids of dirs/files that have been updates/modified.
Definition at line 75 of file imagescanner.h.
|
private |
Elapsed time since last progress event generated.
Definition at line 78 of file imagescanner.h.
|
private |
Number of images scanned.
Definition at line 79 of file imagescanner.h.
|
private |
Total number of images to scan.
Definition at line 80 of file imagescanner.h.
|
private |
Progress counts mutex.
Definition at line 81 of file imagescanner.h.
|
private |
Global working dir for file detection.
Definition at line 84 of file imagescanner.h.
|
private |
Pattern of dir names to ignore whilst scanning.
Definition at line 86 of file imagescanner.h.