예제 #1
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));
}
예제 #2
0
QVariant BrowseModelPrivate::data(const QModelIndex &index, int role) const
{
    if (!index.isValid()) {
        return QVariant();
    }

    DIDLLiteObject object = m_data.at(index.row());
    if (object.isEmpty()) {
        return QVariant();
    }

    switch (role) {
    case BrowseRoleTitle:
        return QString::fromUtf8(gupnp_didl_lite_object_get_title(object));
    case BrowseRoleId:
        return QString::fromUtf8(gupnp_didl_lite_object_get_id(object));
    case BrowseRoleUPnPClass:
        return QString::fromUtf8(gupnp_didl_lite_object_get_upnp_class(object));
    case BrowseRoleIcon:
        return findIconForObject(object);
    case BrowseRoleURI:
        return getCompatibleUri(index.row(), m_protocolInfo);
    case BrowseRoleType:
        if (GUPNP_IS_DIDL_LITE_CONTAINER(object)) {
            return QLatin1String("container");
        } else {
            return QLatin1String("object");
        }
    case BrowseRoleDetail:
        return createDetailsForObject(object);
    case BrowseRoleMetaData:
        return generateMetaData(object);
    case BrowseRoleFilter:
        return QString::fromUtf8(gupnp_didl_lite_object_get_title(object)) + createDetailsForObject(object);
    default:
        return QVariant();
    }
}
예제 #3
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;
}
static gboolean
parse_elements (GUPnPDIDLLiteParser *parser,
                xmlNode             *node,
                GUPnPAVXMLDoc       *xml_doc,
                xmlNs               *upnp_ns,
                xmlNs               *dc_ns,
                xmlNs               *dlna_ns,
                xmlNs               *pv_ns,
                gboolean             recursive,
                GError             **error)
{
        xmlNode *element;

        for (element = node->children; element; element = element->next) {
                GUPnPDIDLLiteObject *object;

                object = gupnp_didl_lite_object_new_from_xml (element, xml_doc,
                                                              upnp_ns, dc_ns,
                                                              dlna_ns, pv_ns);

                if (object == NULL)
                        continue;

                if (GUPNP_IS_DIDL_LITE_CONTAINER (object)) {
                        g_signal_emit (parser,
                                       signals[CONTAINER_AVAILABLE],
                                       0,
                                       object);
                        if (recursive &&
                            !parse_elements (parser,
                                             element,
                                             xml_doc,
                                             upnp_ns,
                                             dc_ns,
                                             dlna_ns,
                                             pv_ns,
                                             recursive,
                                             error)) {
                                g_object_unref (object);

                                return FALSE;
                        }
                } else if (GUPNP_IS_DIDL_LITE_ITEM (object)) {
                        node = gupnp_didl_lite_object_get_xml_node (object);
                        if (!verify_didl_attributes (node)) {
                                g_object_unref (object);
                                g_set_error (error,
                                             G_MARKUP_ERROR,
                                             G_MARKUP_ERROR_PARSE,
                                             "Could not parse DIDL-Lite XML");

                                return FALSE;
                        }

                        g_signal_emit (parser,
                                       signals[ITEM_AVAILABLE],
                                       0,
                                       object);
                }

                g_signal_emit (parser,
                               signals[OBJECT_AVAILABLE],
                               0,
                               object);

                g_object_unref (object);
        }

        return TRUE;
}