From 2eaa5d3600878f36b13e399ea4cb7c7b56649e9c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Oliver=20Gro=C3=9F?= Date: Fri, 14 Mar 2008 12:44:23 +0100 Subject: [PATCH] [medialib] added support for medialib updates --- common.h | 4 +++ medialib.cpp | 83 +++++++++++++++++++++++++++++++++++++++++++++++------------- medialib.h | 2 ++ 3 files changed, 72 insertions(+), 17 deletions(-) diff --git a/common.h b/common.h index 9799ed1..8a2a490 100644 --- a/common.h +++ b/common.h @@ -20,5 +20,9 @@ namespace XmmsQt { xmmsc_result_disconnect(result); xmmsc_result_unref(result); } + + inline bool resultHasKey(xmmsc_result_t * result, const char * key) { + return xmmsc_result_get_dict_entry_type(result, key) != XMMSC_RESULT_VALUE_TYPE_NONE; + } } #endif diff --git a/medialib.cpp b/medialib.cpp index 19c4a44..3a2042f 100644 --- a/medialib.cpp +++ b/medialib.cpp @@ -147,6 +147,24 @@ namespace XmmsQt { } } + void QMedialib::updatedMediaInfoCallback(xmmsc_result_t * result, void * instance) { + if (xmmsc_result_iserror(result)) { + qDebug() << "Error: (QMedialib::updatedMediaInfoCallback)" << xmmsc_result_get_error(result); + return; + } + + if (instance) { + QMedialib * medialib = static_cast(instance); + quint32 id; + xmmsc_result_get_uint(result, &id); + qDebug() << "Media info updated for: #" << id; + if (medialib->checkMediaInfo(id)) { + medialib->removeMediaInfo(id); + medialib->requestMediaInfo(id); + } + } + } + void QMedialib::recievedMediaInfoCallback(xmmsc_result_t * result, void * instance) { if (xmmsc_result_iserror(result)) { qDebug() << "Error: (QMedialib::recievedMediaInfoCallback)" << xmmsc_result_get_error(result); @@ -159,31 +177,60 @@ namespace XmmsQt { const char * strBuffer; xmmsc_result_get_dict_entry_int(result, "id", &id); + if (medialib->m_CachedMedia.contains(id)) { + xmmsc_result_unref(result); + return; + } + MediaInfo * newMediaInfo = new MediaInfo(); - xmmsc_result_get_dict_entry_string(result, "genre", &strBuffer); - newMediaInfo->genre = strBuffer; - xmmsc_result_get_dict_entry_string(result, "album", &strBuffer); - newMediaInfo->album = strBuffer; - xmmsc_result_get_dict_entry_string(result, "artist", &strBuffer); - newMediaInfo->artist = strBuffer; - xmmsc_result_get_dict_entry_string(result, "title", &strBuffer); - newMediaInfo->title = strBuffer; - - xmmsc_result_get_dict_entry_int(result, "duration", &intBuffer); - newMediaInfo->duration = intBuffer; - xmmsc_result_get_dict_entry_int(result, "channels", &intBuffer); - newMediaInfo->channels = intBuffer; - xmmsc_result_get_dict_entry_int(result, "samplerate", &intBuffer); - newMediaInfo->sampleRate = intBuffer; - xmmsc_result_get_dict_entry_int(result, "sample_format", &intBuffer); - newMediaInfo->sampleFormat = intBuffer; + if (resultHasKey(result, "genre")) { + xmmsc_result_get_dict_entry_string(result, "genre", &strBuffer); + newMediaInfo->genre = strBuffer; + } + if (resultHasKey(result, "album")) { + xmmsc_result_get_dict_entry_string(result, "album", &strBuffer); + newMediaInfo->album = strBuffer; + } + if (resultHasKey(result, "artist")) { + xmmsc_result_get_dict_entry_string(result, "artist", &strBuffer); + newMediaInfo->artist = strBuffer; + } + if (resultHasKey(result, "title")) { + xmmsc_result_get_dict_entry_string(result, "title", &strBuffer); + newMediaInfo->title = strBuffer; + } + if (resultHasKey(result, "url")) { + xmmsc_result_get_dict_entry_string(result, "url", &strBuffer); + newMediaInfo->url = strBuffer; + } + + if (resultHasKey(result, "duration")) { + if (xmmsc_result_get_dict_entry_int(result, "duration", &intBuffer)) + newMediaInfo->duration = intBuffer; + else + newMediaInfo->duration = 0; + } + + if (resultHasKey(result, "channels")) { + xmmsc_result_get_dict_entry_int(result, "channels", &intBuffer); + newMediaInfo->channels = intBuffer; + } + if (resultHasKey(result, "samplerate")) { + xmmsc_result_get_dict_entry_int(result, "samplerate", &intBuffer); + newMediaInfo->sampleRate = intBuffer; + } + if (resultHasKey(result, "sample_format")) { + xmmsc_result_get_dict_entry_int(result, "sample_format", &intBuffer); + newMediaInfo->sampleFormat = intBuffer; + } qDebug() << "Inserting media info #" << id << " with " << newMediaInfo->artist << ", " << newMediaInfo->title << ", " << newMediaInfo->album << ", " << newMediaInfo->duration; + qDebug() << "-> url: " << newMediaInfo->url; medialib->m_CachedMedia.insert(id, newMediaInfo); emit medialib->mediaInfoReady(id); } @@ -200,6 +247,7 @@ namespace XmmsQt { disconnectNotifierUnref(xmmsc_broadcast_playlist_changed(m_Connection)); disconnectNotifierUnref(xmmsc_broadcast_playlist_current_pos(m_Connection)); disconnectNotifierUnref(xmmsc_broadcast_collection_changed(m_Connection)); + disconnectNotifierUnref(xmmsc_broadcast_medialib_entry_changed(m_Connection)); } m_Connection = connection; @@ -210,6 +258,7 @@ namespace XmmsQt { connectNotifierUnref(xmmsc_broadcast_playlist_changed(m_Connection), playlistChangedCallback, this); connectNotifierUnref(xmmsc_broadcast_playlist_current_pos(m_Connection), currentPosCallback, this); connectNotifierUnref(xmmsc_broadcast_collection_changed(m_Connection), collectionChangedCallback, this); + connectNotifierUnref(xmmsc_broadcast_medialib_entry_changed(m_Connection), updatedMediaInfoCallback, this); connectNotifierUnref(xmmsc_playlist_list(m_Connection), fillPlaylists, this); connectNotifierUnref(xmmsc_playlist_current_active(m_Connection), activePlaylistCallback, this); diff --git a/medialib.h b/medialib.h index 04ec87a..2014775 100644 --- a/medialib.h +++ b/medialib.h @@ -23,6 +23,7 @@ namespace XmmsQt { QString album; QString genre; //QString comment; + QString url; quint32 channels; quint32 sampleRate; quint32 sampleFormat; @@ -41,6 +42,7 @@ namespace XmmsQt { QPlaylist * m_ActivePlaylist; static void recievedMediaInfoCallback(xmmsc_result_t * result, void * instance); + static void updatedMediaInfoCallback(xmmsc_result_t * result, void * instance); static void playlistChangedCallback(xmmsc_result_t * result, void * instance); static void activePlaylistCallback(xmmsc_result_t * result, void * instance); -- 2.11.4.GIT