static void
didl_item_available_cb (GUPnPDIDLLiteParser *parser,
                        GUPnPDIDLLiteObject *object,
                        gpointer             user_data)
{
        GList *resources;
        GUPnPDIDLLiteResource *resource;
        const char **import_uri = (const char **) user_data;

        if (*import_uri != NULL) {
                /* This means we've already found importURI. */
                /* No need to search further. */
                return;
        }

        resources = gupnp_didl_lite_object_get_resources (object);
        if (resources == NULL) {
                return;
        }

        resource = (GUPnPDIDLLiteResource *) resources->data;

        *import_uri = gupnp_didl_lite_resource_get_import_uri(resource);
        if (*import_uri != NULL) {
                *import_uri = g_strdup (*import_uri);
        }

        while (resources) {
                g_object_unref ((GUPnPDIDLLiteResource *) resources->data);
                resources = g_list_delete_link (resources, resources);
        }
}
Beispiel #2
0
static QUrl findIconForObject(GUPnPDIDLLiteObject *object)
{
    QUrl thumbnail;
    GList* resources = gupnp_didl_lite_object_get_resources(object);
    GList* it = resources;

    const char *upnp_class = gupnp_didl_lite_object_get_upnp_class (object);

    if (upnp_class == 0) {
        thumbnail.setUrl(QLatin1String("image://theme/icon-m-content-file-unknown-inverse"));

        return thumbnail;
    }

    if (strncmp(upnp_class, AUDIO_PREFIX, sizeof(AUDIO_PREFIX) - 1) == 0 ||
        strncmp(upnp_class, MUSIC_ALBUM_CLASS, sizeof(MUSIC_ALBUM_CLASS) - 1) == 0) {
        const char *album_art_uri = gupnp_didl_lite_object_get_album_art(object);
        thumbnail.setUrl(QString::fromUtf8(album_art_uri));
    } else {
        while (it) {
            GUPnPDIDLLiteResource *res = (GUPnPDIDLLiteResource*) it->data;
            GUPnPProtocolInfo *info = gupnp_didl_lite_resource_get_protocol_info(res);
            const char *profile = gupnp_protocol_info_get_dlna_profile(info);
            if (profile != 0 &&
                (strncmp(profile, "JPEG_TN", 7) == 0 ||
                 strncmp(profile, "PNG_TN", 6) == 0)) {
                thumbnail.setUrl(QString::fromUtf8(gupnp_didl_lite_resource_get_uri(res)));
                break;
            }
            it = it->next;
        }
    }

    if (thumbnail.isEmpty()) {
        if (strncmp(upnp_class, IMAGE_PREFIX, sizeof(IMAGE_PREFIX) - 1) == 0) {
            thumbnail.setUrl(QLatin1String("image://theme/icon-m-content-image-inverse"));
        } else if (strncmp(upnp_class, VIDEO_PREFIX, sizeof(VIDEO_PREFIX) - 1) == 0) {
            thumbnail.setUrl(QLatin1String("image://theme/icon-m-content-videos-inverse"));
        } else if (strncmp(upnp_class, AUDIO_PREFIX, sizeof(AUDIO_PREFIX) - 1) == 0) {
            thumbnail.setUrl(QLatin1String("image://theme/icon-m-content-audio-inverse"));
        } else if (strncmp(upnp_class, MUSIC_ALBUM_CLASS, sizeof(MUSIC_ALBUM_CLASS) - 1) == 0) {
            thumbnail.setUrl(QLatin1String("image://theme/icon-m-content-album-inverse"));
        } else if (strncmp(upnp_class, ARTIST_CLASS, sizeof(ARTIST_CLASS) - 1) == 0) {
            thumbnail.setUrl(QLatin1String("image://theme/icon-m-content-artist-inverse"));
        } else if (strncmp(upnp_class, GENRE_CLASS, sizeof(GENRE_CLASS) - 1) == 0) {
            thumbnail.setUrl(QLatin1String("image://theme/icon-m-content-genre-inverse"));
        } else if (strncmp(upnp_class, CONTAINER_PREFIX, sizeof(CONTAINER_PREFIX) - 1) == 0) {
            thumbnail.setUrl(QLatin1String("image://theme/icon-m-toolbar-directory-white"));
        }
    }

    g_list_free_full(resources, g_object_unref);

    if (thumbnail.isEmpty()) {
        thumbnail.setUrl(QLatin1String("image://theme/icon-m-content-file-unknown-inverse"));
    }

    return thumbnail;
}
Beispiel #3
0
static QString generateMetaData(GUPnPDIDLLiteObject *object)
{
    GList *resources, *it;

    if (GUPNP_IS_DIDL_LITE_CONTAINER(object)) {
        return QString();
    }

    // produce minimal DIDL
    auto writer = wrap(gupnp_didl_lite_writer_new (NULL));
    GUPnPDIDLLiteObject *item = GUPNP_DIDL_LITE_OBJECT(gupnp_didl_lite_writer_add_item(writer));
    const char *title = gupnp_didl_lite_object_get_title(object);

    // maximum title length is 256 bytes
    if (strlen(title) > 256) {
        char *tmp = 0;
        const char *end_ptr = 0;

        g_utf8_validate(title, 256, &end_ptr);
        tmp = g_strndup(title, end_ptr - title);
        gupnp_didl_lite_object_set_title(item, tmp);
        g_free(tmp);
    } else {
        gupnp_didl_lite_object_set_title(item, title);
    }

    gupnp_didl_lite_object_set_upnp_class(item, gupnp_didl_lite_object_get_upnp_class(object));
    gupnp_didl_lite_object_set_parent_id(item, gupnp_didl_lite_object_get_parent_id(object));
    gupnp_didl_lite_object_set_id(item, gupnp_didl_lite_object_get_id(object));
    gupnp_didl_lite_object_set_restricted(item, gupnp_didl_lite_object_get_restricted(object));
    it = resources = gupnp_didl_lite_object_get_resources(object);
    while (it != 0) {
        GUPnPDIDLLiteResource *orig_resource = GUPNP_DIDL_LITE_RESOURCE(it->data);
        GUPnPDIDLLiteResource *resource = gupnp_didl_lite_object_add_resource(item);
        gupnp_didl_lite_resource_set_uri(resource,
                                         gupnp_didl_lite_resource_get_uri (orig_resource));
        gupnp_didl_lite_resource_set_protocol_info(resource,
                                                   gupnp_didl_lite_resource_get_protocol_info(orig_resource));

        it = it->next;
    }
    g_list_free_full(resources, (GDestroyNotify)g_object_unref);

    return QString::fromUtf8(gupnp_didl_lite_writer_get_string(writer));
}
Beispiel #4
0
static QString createDetailsForObject(GUPnPDIDLLiteObject *object)
{
    QString result;

    if (GUPNP_IS_DIDL_LITE_CONTAINER(object)) {
        return result;
    }

    GList* resources = gupnp_didl_lite_object_get_resources(object);
    GList* it = resources;

    const char *author = gupnp_didl_lite_object_get_artist(object);
    const char *album = gupnp_didl_lite_object_get_album(object);

    if (author != 0) {
        result += QString::fromLatin1("%1").arg(QString::fromUtf8(author));
    }

    if (album != 0) {
        if (not result.isEmpty()) {
            result += QLatin1String(" | ");
        }
        result += QString::fromLatin1("%1").arg(QString::fromUtf8(album));
    }

    const QLatin1String empty = QLatin1String(" ");
    while (it) {
        GUPnPDIDLLiteResource *res = (GUPnPDIDLLiteResource*) it->data;
        GUPnPProtocolInfo *info = gupnp_didl_lite_resource_get_protocol_info(res);
        // use first non-transcoded uri; might be problematic
        if (gupnp_protocol_info_get_dlna_conversion (info) == GUPNP_DLNA_CONVERSION_NONE) {
            long duration = gupnp_didl_lite_resource_get_duration(res);
            if (duration > 0) {
                if (not result.isEmpty()) {
                    result += empty;
                }
                result += formatTime(duration);

            }

            int width = gupnp_didl_lite_resource_get_width(res);
            int height = gupnp_didl_lite_resource_get_height(res);
            if (width > 0 && height > 0) {
                if (not result.isEmpty()) {
                    result += empty;
                }
                result += QString::fromLatin1("%1x%2").arg(QString::number(width), QString::number(height));
            }

            gint64 size = gupnp_didl_lite_resource_get_size64(res);
            if (size > 0) {
                if (not result.isEmpty()) {
                    result += empty;
                }

                result += formatSize(size);
            }

            break;
        }
        it = it->next;
    }

    g_list_free_full(resources, g_object_unref);

    return result;
}