2 * Copyright (C) 2017 Konsulko Group
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "lightmediascanner.h"
19 LightMediaScanner::LightMediaScanner(const QString& path)
21 lms = QSqlDatabase::addDatabase("QSQLITE");
22 lms.setDatabaseName(path);
25 qDebug() << "Cannot open database: " << path;
27 query = QSqlQuery(lms);
28 query.prepare("SELECT files.path FROM files LEFT JOIN audios WHERE audios.id = files.id ORDER BY audios.artist_id, audios.album_id, audios.trackno");
30 qDebug() << "Cannot run SQL query";
34 bool LightMediaScanner::next(QString& item)
39 item = query.value(0).toString();
44 QVariantList LightMediaScanner::processLightMediaScanner()
46 QVariantList mediaFiles;
48 LightMediaScanner scanner(QDir::homePath() + "/.config/lightmediascannerd/db.sqlite3");
49 while (scanner.next(music)) {
50 QFileInfo fileInfo(music);
51 // Possible for stale entries due to removable media
52 if (!fileInfo.exists())
54 mediaFiles.append(QUrl::fromLocalFile(music));