forked from mixxxdj/mixxx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
importfilestask.cpp
59 lines (53 loc) · 2.28 KB
/
importfilestask.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "library/scanner/importfilestask.h"
#include "library/scanner/libraryscanner.h"
#include "moc_importfilestask.cpp"
#include "util/timer.h"
ImportFilesTask::ImportFilesTask(LibraryScanner* pScanner,
const ScannerGlobalPointer scannerGlobal,
const QString& dirPath,
const bool prevHashExists,
const mixxx::cache_key_t newHash,
const std::list<QFileInfo>& filesToImport,
const std::list<QFileInfo>& possibleCovers,
SecurityTokenPointer pToken)
: ScannerTask(pScanner, scannerGlobal),
m_dirPath(dirPath),
m_prevHashExists(prevHashExists),
m_newHash(newHash),
m_filesToImport(filesToImport),
m_possibleCovers(possibleCovers),
m_pToken(pToken) {
}
void ImportFilesTask::run() {
ScopedTimer timer(u"ImportFilesTask::run");
for (const QFileInfo& fileInfo: m_filesToImport) {
// If a flag was raised telling us to cancel the library scan then stop.
if (m_scannerGlobal->shouldCancel()) {
setSuccess(false);
return;
}
const QString trackLocation(mixxx::FileInfo(fileInfo).location());
//qDebug() << "ImportFilesTask::run" << trackLocation;
// If the file does not exist in the database then add it. If it
// does then it is either in the user's library OR the user has
// "removed" the track via "Right-Click -> Remove". These tracks
// stay in the library, but their mixxx_deleted column is 1.
if (m_scannerGlobal->trackExistsInDatabase(trackLocation)) {
// If the track is in the database, mark it as existing. This code gets
// executed when other files in the same directory have changed (the
// directory hash has changed).
emit trackExists(trackLocation);
} else {
if (!fileInfo.exists()) {
qWarning() << "ImportFilesTask: Skipping inaccessible file"
<< trackLocation;
continue;
}
qDebug() << "Importing track" << trackLocation;
emit addNewTrack(trackLocation);
}
}
// Insert or update the hash in the database.
emit directoryHashedAndScanned(m_dirPath, !m_prevHashExists, m_newHash);
setSuccess(true);
}