diff options
-rw-r--r-- | app/main.cpp | 28 | ||||
-rw-r--r-- | binding/mediaplayer-api.c | 5 | ||||
-rw-r--r-- | binding/mediaplayer-manager.c | 24 | ||||
-rw-r--r-- | binding/mediaplayer-manager.h | 1 |
4 files changed, 26 insertions, 32 deletions
diff --git a/app/main.cpp b/app/main.cpp index 5ad9577..63e408a 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -31,23 +31,6 @@ #include "playlistwithmetadata.h" -#ifndef HAVE_LIGHTMEDIASCANNER -QVariantList readMusicFile(const QString &path) -{ - QVariantList ret; - QDir dir(path); - for (const auto &entry : dir.entryList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot, QDir::Name)) { - QFileInfo fileInfo(dir.absoluteFilePath(entry)); - if (fileInfo.isDir()) { - ret.append(readMusicFile(fileInfo.absoluteFilePath())); - } else if (fileInfo.isFile()) { - ret.append(QUrl::fromLocalFile(fileInfo.absoluteFilePath())); - } - } - return ret; -} -#endif - int main(int argc, char *argv[]) { #ifdef HAVE_LIBHOMESCREEN @@ -68,17 +51,6 @@ int main(int argc, char *argv[]) QQmlApplicationEngine engine; QQmlContext *context = engine.rootContext(); -#ifndef HAVE_LIGHTMEDIASCANNER - QVariantList mediaFiles; - QString music; - - for (const auto &music : QStandardPaths::standardLocations(QStandardPaths::MusicLocation)) { - mediaFiles.append(readMusicFile(music)); - } - - context->setContextProperty("mediaFiles", mediaFiles); -#endif - QCommandLineParser parser; parser.addPositionalArgument("port", app.translate("main", "port for binding")); parser.addPositionalArgument("secret", app.translate("main", "secret for binding")); diff --git a/binding/mediaplayer-api.c b/binding/mediaplayer-api.c index 44944df..08372ad 100644 --- a/binding/mediaplayer-api.c +++ b/binding/mediaplayer-api.c @@ -91,10 +91,6 @@ static json_object *new_json_object_from_device(GList *list) json_object_object_add(jresp, "Media", jarray); - // TODO: Add media path - jstring = json_object_new_string(""); - json_object_object_add(jresp, "Path", jstring); - return jresp; } @@ -105,6 +101,7 @@ static void media_results_get (struct afb_req request) ListLock(); list = media_lightmediascanner_scan(); + list = media_local_scan(list); if (list == NULL) { afb_req_fail(request, "failed", "media scan error"); ListUnlock(); diff --git a/binding/mediaplayer-manager.c b/binding/mediaplayer-manager.c index 6265312..38e5cab 100644 --- a/binding/mediaplayer-manager.c +++ b/binding/mediaplayer-manager.c @@ -83,6 +83,30 @@ void DebugTraceSendMsg(int level, gchar* message) } +GList* media_local_scan(GList *list) +{ + gchar *path = g_strconcat(g_get_home_dir(), "/", "Music", NULL); + gchar *tmp = NULL; + GDir *dir; + + dir = g_dir_open(path, 0, NULL); + if (dir == NULL) + { + LOGE("Cannot open media path %s\n", path); + return list; + } + + while ((tmp = (gchar *) g_dir_read_name(dir)) != NULL) + { + list = g_list_append(list, g_strdup_printf("file://%s/%s", path, tmp)); + } + + g_free(path); + g_dir_close(dir); + + return list; +} + GList* media_lightmediascanner_scan(void) { sqlite3 *conn; diff --git a/binding/mediaplayer-manager.h b/binding/mediaplayer-manager.h index ae4fc8a..5864867 100644 --- a/binding/mediaplayer-manager.h +++ b/binding/mediaplayer-manager.h @@ -98,5 +98,6 @@ void ListLock(); void ListUnlock(); GList* media_lightmediascanner_scan(void); +GList* media_local_scan(GList *list); #endif |