Exemple #1
0
    PurpleAccount* createPurpleAccount(MojString username, MojString prpl, MojObject prefs)
    {
        PurplePluginProtocolInfo* info = getProtocolInfo(prpl.data());

        // TODO: Strip off possible junk here!
        //       The Username Split API might be useful, as soon as I have
        //       understood it ...
        PurpleAccount* account = purple_account_new(username.data(), prpl.data());

        for(GList* l = info->protocol_options; l != NULL; l = l->next)
        {
            PurpleAccountOption* option = (PurpleAccountOption*)l->data;

            const char* name = purple_account_option_get_setting(option);

            if (!prefs.contains(name))
                continue;

            switch(purple_account_option_get_type(option))
            {
            case PURPLE_PREF_BOOLEAN:
                {
                    bool value;
                    prefs.get(name, value);
                    purple_account_set_bool(account, name, value);
                }
                break;

            case PURPLE_PREF_INT:
                {
                    bool found;
                    int value;
                    prefs.get(name, value, found);
                    purple_account_set_int(account, name, value);
                }
                break;

            case PURPLE_PREF_STRING:
            case PURPLE_PREF_STRING_LIST:
                {
                    bool found;
                    MojString value;
                    prefs.get(name, value, found);
                    purple_account_set_string(account, name, value.data());
                }
                break;

            default:
                continue;
            }
        }

        return account;
    }
/*
* Returns XML (DIDL) representation of the DLNA node. It gives a
* complete representation of the item, with as many tags as available.
*
* Reference: http://www.upnp.org/specs/av/UPnP-av-ContentDirectory-v1-Service.pdf
*/
QDomElement DlnaVideoItem::getXmlContentDirectory(QDomDocument *xml, QStringList properties) const {
    if (!xml)
        return QDomElement();

    QDomElement xml_obj = xml->createElement("item");

    updateXmlContentDirectory(xml, &xml_obj, properties);

    // properties optional of videoItem

    if (properties.contains("*") or properties.contains("upnp:genre")) {
        QDomElement upnpGenre = xml->createElement("upnp:genre");
        upnpGenre.appendChild(xml->createTextNode(metaDataGenre()));
        xml_obj.appendChild(upnpGenre);
    }

    if (properties.contains("*") or properties.contains("upnp:longDescription")) {

    }

    if (properties.contains("*") or properties.contains("upnp:producer")) {

    }

    if (properties.contains("*") or properties.contains("upnp:rating")) {

    }

    if (properties.contains("*") or properties.contains("upnp:actor")) {

    }

    if (properties.contains("*") or properties.contains("upnp:director")) {

    }

    if (properties.contains("*") or properties.contains("dc:description")) {

    }

    if (properties.contains("*") or properties.contains("dc:publisher")) {

    }

    if (properties.contains("*") or properties.contains("dc:language")) {

    }

    if (properties.contains("*") or properties.contains("dc:relation")) {

    }

    // add <res> element

    QTime duration(0, 0, 0);
    QDomElement res = xml->createElement("res");
    res.setAttribute("xmlns:dlna", "urn:schemas-dlna-org:metadata-1-0/");

    // mandatory properties: protocolInfo
    res.setAttribute("protocolInfo", getProtocolInfo());

    // optional properties
    if ((properties.contains("*") or properties.contains("res@bitrate")) and bitrate() != -1) {
        // bitrate in bytes/sec
        res.setAttribute("bitrate", QString("%1").arg(qRound(double(bitrate())/8.0)));
    }

    if (properties.contains("*") or properties.contains("res@resolution")) {
        res.setAttribute("resolution", resolution());
    }

    if (properties.contains("*") or properties.contains("res@duration")) {
        res.setAttribute("duration", QString("%1").arg(duration.addSecs(getLengthInSeconds()).toString("hh:mm:ss")));
    }

    if (properties.contains("*") or properties.contains("res@sampleFrequency")) {
        res.setAttribute("sampleFrequency", QString("%1").arg(samplerate()));
    }

    if (properties.contains("*") or properties.contains("res@nrAudioChannels")) {
        res.setAttribute("nrAudioChannels", QString("%1").arg(channelCount()));
    }

    if ((properties.contains("*") or properties.contains("res@size")) and size() != -1) {
        // size in bytes
        res.setAttribute("size", QString("%1").arg(size()));
    }

    res.appendChild(xml->createTextNode(QString("http://%2:%3/get/%1/%4").arg(getResourceId()).arg(host).arg(port).arg(getName().toUtf8().toPercentEncoding().constData())));

    xml_obj.appendChild(res);

    return xml_obj;
}
Exemple #3
0
    MojObject getProtocolOptions(MojString prpl)
    {
        MojObject result;

        PurplePluginProtocolInfo* info = getProtocolInfo(prpl.data());

        for(GList* l = info->protocol_options; l != NULL; l = l->next)
        {
            PurpleAccountOption* option = (PurpleAccountOption*)l->data;

            MojObject node;
            MojObject choices;

            node.putString("text", purple_account_option_get_text(option));

            switch(purple_account_option_get_type(option))
            {
            case PURPLE_PREF_BOOLEAN:
                node.putString("type", "bool");
                node.putBool("default_value",
                    purple_account_option_get_default_bool(option)
                    );
                break;

            case PURPLE_PREF_INT:
                node.putString("type", "int");
                node.putInt("default_value",
                    purple_account_option_get_default_int(option)
                    );
                break;

            case PURPLE_PREF_STRING:
                node.putString("type", "string");
                {
                    const char* def
                        = purple_account_option_get_default_string(option);
                    node.putString("default_value", def ? def : "");
                }
                break;

            case PURPLE_PREF_STRING_LIST:
                node.putString("type", "list");
                {
                    MojObject choices;

                    for (GList* list = purple_account_option_get_list(option);
                         list != NULL; list = list->next)
                    {
                        PurpleKeyValuePair* kvp = (PurpleKeyValuePair*)list->data;
                        // XXX: Dangerous!
                        if (kvp->key && kvp->value)
                            choices.putString((const char*)kvp->value,
                                              (const char*)kvp->key);
                    }
                    node.put("choices", choices);

                    const char* def
                        = purple_account_option_get_default_list_value(option);
                    node.putString("default_value", def ? def : "");
                }
                break;

            default:
                continue;
            };

            result.put(purple_account_option_get_setting(option), node);
        }

        return result;
    }