void
Ut_AboutBusinessLogic::testBluetooth ()
{
    QSignalSpy spy (
        m_Api,
        SIGNAL (requestFinished (AboutBusinessLogic::requestType, QVariant)));

    QMap <QString, QVariant> properties;
    properties["Address"] = QString ("fake-bluetooth-address");

    /*
     * Let's initiate the Bluetooth query that will call the
     * QDBusAbstractInterface::callWithCallback() that is stubbed.
     */
    m_Api->initiateBluetoothQueries ();
    QCOMPARE (lastCalledMethod, QString ("DefaultAdapter"));

    /*
     * Let's answer the previous step by calling the DBus callback manually.
     * This will initiate an other DBus call also stubbed.
     */
    m_Api->defaultBluetoothAdapterReceived (
            QDBusObjectPath("/fakeObjectPath"));
    QCOMPARE (lastCalledMethod, QString ("GetProperties"));

    /*
     * Answering the second DBus call and checking if the businesslogic
     * processed the data as it should.
     */
    m_Api->defaultBluetoothAdapterAddressReceived (properties);

    QTest::qWait (100);
    QCOMPARE (spy.count (), 1);

    QList<QVariant> args = spy.first ();

    QCOMPARE (args.at (0).value<AboutBusinessLogic::requestType>(),
              AboutBusinessLogic::reqBtAddr);
#if 0
    /* for some strange reason it is not working :-S */
    QCOMPARE (args.at (1).toString (), QString ("fake-bluetooth-address"));
#endif

    /*
     * Let's test the failure socket. This does not do nothing...
     */
    m_Api->DBusMessagingFailure (QDBusError());

    delete m_Api;
    /*
     * Let's see what happens if we initate the data collection and instead of
     * producing answers to queries we just destroy the object.
     */
    m_Api = new AboutBusinessLogic;
    m_Api->initiateBluetoothQueries ();
    //XXX: delete m_Api; (done in cleanup ())
}
Exemplo n.º 2
0
    void Mpris2DBusHandler::updateTrackProperties()
    {
        DEBUG_BLOCK

        Meta::TrackPtr currentTrack = The::engineController()->currentTrack();
        if ( !currentTrack )
        {
            int rowCount = The::playlist()->qaim()->rowCount();
            setPropertyInternal( "Metadata", QVariantMap() );
            setPropertyInternal( "CanPlay", rowCount > 0 );
            setPropertyInternal( "CanPause", false );
            //setPropertyInternal( "CanSeek", false );
        }
        else
        {
            QVariantMap metaData = Meta::Field::mpris20MapFromTrack( currentTrack );
            if ( currentTrack == The::playlist()->activeTrack() )
                metaData["mpris:trackid"] = QVariant::fromValue<QDBusObjectPath>(activeMprisTrackId());
            else {
                // we should be updated shortly
                QString path = QString( "%1/PendingTrack" ).arg( MPRIS2_OBJECT_PATH );
                metaData["mpris:trackid"] = QVariant::fromValue<QDBusObjectPath>( QDBusObjectPath( path ) );
            }

            setPropertyInternal( "CanPlay", true );
            // Phonon doesn't actually tell us whether the media is pausable,
            // so we always claim it is
            setPropertyInternal( "CanPause", true );
            //setPropertyInternal( "CanSeek", The::engineController()->phononMediaObject()->isSeekable() );
            setPropertyInternal( "Metadata", metaData );
        }
    }
Exemplo n.º 3
0
inline QDBusObjectPath QDBusDemarshaller::toObjectPath()
{
    if (isCurrentTypeStringLike())
        return toObjectPathUnchecked();
    else
        return QDBusObjectPath();
}
Exemplo n.º 4
0
void ObexAgentManager::UnregisterAgent(const QDBusObjectPath &path, const QDBusMessage &msg)
{
    if (m_agent == path && m_service == msg.service()) {
        m_agent = QDBusObjectPath();
        m_service.clear();
    }
}
Exemplo n.º 5
0
// TODO - These can be refactored quite easily
const QDBusObjectPath PBTreeNode::job(void)
{
    for(int j=0; j < interfaces.count(); j++) {
        PBObjectInterface* iface = interfaces.at(j);

        if (iface == NULL) {
            qDebug("Null interface");
        } else {
            if(iface->interface.compare(JobStateInterface) == 0) {
                QVariant variant;
                variant = *iface->properties.find("job");
                if (variant.isValid() ) {

                    QDBusObjectPath job = variant.value<QDBusObjectPath>();

                    return job;
                }
            }
        }
    }

    // No job - should this be flagged as an error in the tests themselves?
    qDebug("There is no job property");

    return QDBusObjectPath("");
}
Exemplo n.º 6
0
void BearerPropertiesTest::initTestCase()
{
    fakeModem = new FakeModem();

    modem = new Modem();
    modem->setAccessTechnologies(16);
    modem->SetCurrentBands({0});
    modem->SetCurrentCapabilities(4);
    modem->SetCurrentModes({MM_MODEM_MODE_ANY, MM_MODEM_MODE_NONE});
    modem->setDevice(QLatin1String("/sys/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2"));
    modem->setDeviceIdentifier(QLatin1String("1c435eb6d74494b5f78d7221e2c5ae9ec526a981"));
    modem->setDrivers({QLatin1String("option1")});
    modem->setEquipmentIdentifier(QLatin1String("353475021085110"));
    modem->setManufacturer(QLatin1String("huawei"));
    modem->setMaxActiveBearers(1);
    modem->setMaxBearers(1);
    modem->setModel(QLatin1String("K2540"));
    //modem->setOwnNumbers();
    modem->setPlugin(QLatin1String("Huawei"));
    modem->setPorts({{QLatin1String("ttyUSB0"), MM_MODEM_PORT_TYPE_AT}, {QLatin1String("ttyUSB1"), MM_MODEM_PORT_TYPE_QCDM}, {QLatin1String("ttyUSB2"), MM_MODEM_PORT_TYPE_AT}});
    modem->SetPowerState(3);
    modem->setPrimaryPort(QLatin1String("ttyUSB2"));
    modem->setRevision(QLatin1String("11.001.05.00.11"));
    modem->setSignalQuality({93, true});
    modem->setSim(QDBusObjectPath("/org/kde/fakemodem/SIM/1"));
    modem->setState(8);
    modem->setStateFailedReason(0);
    modem->setSupportedBands({0});
    modem->setSupportedCapabilities({4});
    modem->setSupportedIpFamilies(3);
    ModemManager::SupportedModesType supportedModes;
    ModemManager::CurrentModesType supportedMode1 = {MM_MODEM_MODE_4G & MM_MODEM_MODE_3G & MM_MODEM_MODE_2G, MM_MODEM_MODE_NONE};
    ModemManager::CurrentModesType supportedMode2 = {MM_MODEM_MODE_4G & MM_MODEM_MODE_3G & MM_MODEM_MODE_2G, MM_MODEM_MODE_2G};
    ModemManager::CurrentModesType supportedMode3 = {MM_MODEM_MODE_4G & MM_MODEM_MODE_3G & MM_MODEM_MODE_2G, MM_MODEM_MODE_3G};
    supportedModes << supportedMode1 << supportedMode2 << supportedMode3;
    modem->setSupportedModes(supportedModes);
    modem->setUnlockRequired(1);
    modem->setUnlockRetries({{MM_MODEM_LOCK_SIM_PIN, 3}, {MM_MODEM_LOCK_SIM_PIN2, 3}, {MM_MODEM_LOCK_SIM_PUK, 10}, {MM_MODEM_LOCK_SIM_PUK2, 10}});

    QSignalSpy addModemSpy(ModemManager::notifier(), SIGNAL(modemAdded(QString)));
    fakeModem->addModem(modem);
    QVERIFY(addModemSpy.wait());

    bearer = new Bearer();
    // We need to set some default values
    bearer->setConnected(false);
    bearer->setInterface(QLatin1String("ttyUSB0"));
    bearer->setIp4Config({{QLatin1String("method"), MM_BEARER_IP_METHOD_PPP}});
    bearer->setIp6Config({{QLatin1String("method"), MM_BEARER_IP_METHOD_UNKNOWN}});
    bearer->setIpTimeout(20);
    bearer->setProperties({{QLatin1String("apn"),QLatin1String("internet")},{QLatin1Literal("ip-type"), 1}, {QLatin1String("number"), QLatin1String("*99#")}});
    bearer->setSuspended(false);
#if MM_CHECK_VERSION(1, 2, 0)
    ModemManager::Modem::Ptr modemInterface = ModemManager::modemDevices().first()->modemInterface();
    QCOMPARE(modemInterface->listBearers().count(), 0);
    QSignalSpy bearerAddedSpy(modemInterface.data(), SIGNAL(bearerAdded(QString)));
    fakeModem->addBearer(bearer);
    QVERIFY(bearerAddedSpy.wait());
#endif
}
Exemplo n.º 7
0
QDBusObjectPath QTerminalApp::getActiveWindow()
{
    QWidget *aw = activeWindow();
    if (aw == nullptr)
        return QDBusObjectPath("/");
    return qobject_cast<MainWindow*>(aw)->getDbusPath();
}
QDBusArgument &operator<<(QDBusArgument &arg, const Struct2 &)
{
    arg.beginStructure();
    arg << QString() << QDBusObjectPath() << QString();
    arg.endStructure();
    return arg;
}
Exemplo n.º 9
0
QVariantMap MprisPlayer::typeMetadata(const QVariantMap &aMetadata)
{
    QVariantMap metadata;
    QVariantMap::const_iterator i = aMetadata.constBegin();
    while (i != aMetadata.constEnd()) {
        switch (Mpris::enumerationFromString<Mpris::Metadata>(i.key())) {
        case Mpris::TrackId:
            metadata.insert(i.key(), QVariant::fromValue(QDBusObjectPath(i.value().toString())));
            break;
        case Mpris::Length:
            metadata.insert(i.key(), QVariant::fromValue(i.value().toLongLong()));
            break;
        case Mpris::ArtUrl:
        case Mpris::Url:
            metadata.insert(i.key(), QVariant::fromValue(i.value().toUrl().toString()));
            break;
        case Mpris::Album:
        case Mpris::AsText:
        case Mpris::Title:
            metadata.insert(i.key(), QVariant::fromValue(i.value().toString()));
            break;
        case Mpris::AlbumArtist:
        case Mpris::Artist:
        case Mpris::Comment:
        case Mpris::Composer:
        case Mpris::Genre:
        case Mpris::Lyricist:
            metadata.insert(i.key(), QVariant::fromValue(i.value().toStringList()));
            break;
        case Mpris::AudioBPM:
        case Mpris::DiscNumber:
        case Mpris::TrackNumber:
        case Mpris::UseCount:
            metadata.insert(i.key(), QVariant::fromValue(i.value().toInt()));
            break;
        case Mpris::AutoRating:
        case Mpris::UserRating:
            metadata.insert(i.key(), QVariant::fromValue(i.value().toFloat()));
            break;
        case Mpris::ContentCreated:
        case Mpris::FirstUsed:
        case Mpris::LastUsed:
            metadata.insert(i.key(), QVariant::fromValue(i.value().toDate().toString(Qt::ISODate)));
            break;
        case Mpris::InvalidMetadata:
            // Passing with the original type and hoping the user used
            // a type supported by DBus
            metadata.insert(i.key(), i.value());
            break;
        default:
            // Nothing to do
            break;
        }

        ++i;
    }

    return metadata;
}
Exemplo n.º 10
0
void Log::removeMonitor(QZeitgeist::Monitor *monitor)
{
    Q_ASSERT(monitor != 0);

    d->logInterface->RemoveMonitor(QDBusObjectPath(monitor->objectPath()));

    monitor->deleteLater();
}
Exemplo n.º 11
0
void PendingClear::clearAccount(const Tp::AccountPtr &account)
{
    QDBusObjectPath path = QDBusObjectPath(account->objectPath());
    QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(
                mInterface->ClearAccount(path));

    connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
            this,
            SLOT(onLogCleared(QDBusPendingCallWatcher*)));
}
Exemplo n.º 12
0
void PendingClear::clearRoom(const Tp::AccountPtr &account, const QString &objectId)
{
    QDBusObjectPath path = QDBusObjectPath(account->objectPath());
    QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(
                mInterface->ClearEntity(path, objectId, EntityTypeRoom));

    connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
            this,
            SLOT(onLogCleared(QDBusPendingCallWatcher*)));
}
Exemplo n.º 13
0
QDBusObjectPath JobManager::startJob(const QString &command)
{
	if (command.isEmpty()) {
		qWarning("%s: 'command' must be specified", Q_FUNC_INFO);
		return QDBusObjectPath();
	}

	const int jobId = m_nextJobId++;

	m_jobs[jobId] = new Job(jobId, command, this);
	connect(m_jobs[jobId], SIGNAL(finished(Job*)),
			this, SLOT(onJobFinished(Job*)));
	new JobViewAdaptor(m_jobs[jobId]);
	const QString path = QString("/com/tieto/sysjt/JobView%1").arg(jobId);
	QDBusConnection::sessionBus().registerObject(path, m_jobs[jobId]);

	emit jobStarted(m_jobs[jobId]);

	return QDBusObjectPath(path);
}
Exemplo n.º 14
0
static QDBusObjectPath mprisTrackId(quint64 playlistTrackId)
{
    QString path;
    if( playlistTrackId > 0 ) {
        path = QString( "%1/Track/%2" ).arg( MPRIS2_OBJECT_PATH ).arg( playlistTrackId );
    } else {
        // dropped out of the playlist
        path = QString( "%1/OrphanTrack" ).arg( MPRIS2_OBJECT_PATH );
    }
    return QDBusObjectPath( path );
}
Exemplo n.º 15
0
Tp::ChannelDetails BaseChannel::details() const
{
    Tp::ChannelDetails details;
    details.channel = QDBusObjectPath(objectPath());
    details.properties.unite(immutableProperties());

    foreach(const AbstractChannelInterfacePtr & iface, mPriv->interfaces) {
        details.properties.unite(iface->immutableProperties());
    }

    return details;
}
Exemplo n.º 16
0
QDBusObjectPath QDBusData::toObjectPath(bool* ok) const
{
    if (d->type != QDBusData::ObjectPath)
    {
        if (ok != 0) *ok = false;
        return QDBusObjectPath();
    }

    if (ok != 0) *ok = true;

    return *((QDBusObjectPath*)d->value.pointer);
}
Exemplo n.º 17
0
void QBluetoothTransferReplyBluez::cleanupSession()
{
    if (!m_objectPushBluez)
        return;

    QDBusPendingReply<> reply = m_clientBluez->RemoveSession(QDBusObjectPath(m_objectPushBluez->path()));
    reply.waitForFinished();
    if (reply.isError())
        qCWarning(QT_BT_BLUEZ) << "Abort: Cannot remove obex session";

    delete m_objectPushBluez;
    m_objectPushBluez = 0;
}
Exemplo n.º 18
0
void ObexAgentManager::runAuthorizePushAction(const QVariantMap &properties)
{
    Q_UNUSED(properties)

    QDBusMessage call = QDBusMessage::createMethodCall(m_service,
                        m_agent.path(),
                        QStringLiteral("org.bluez.obex.Agent1"),
                        QStringLiteral("AuthorizePush"));

    call << QVariant::fromValue(QDBusObjectPath(QStringLiteral("/org/bluez/session1/transfer1")));
    const QString &fileName = QDBusConnection::sessionBus().call(call).arguments().first().toString();
    Q_UNUSED(fileName)
}
Exemplo n.º 19
0
 QVariantMap toDBus(const MetaData &md) const {
     QVariantMap map;
     map["mpris:trackid"] = QVariant::fromValue(QDBusObjectPath(dbusTrackId(md.mrl())));
     map["mpris:length"] = 1000LL*(qint64)md.duration();
     map["xesam:url"] = md.mrl().toString();
     map["xesam:title"] = md.title().isEmpty() ? engine->mediaInfo()->name() : md.title();
     if (!md.album().isEmpty())
         map["xesam:album"] = md.album();
     if (!md.artist().isEmpty())
         map["xesam:artist"] = QStringList(md.artist());
     if (!md.genre().isEmpty())
         map["xesam:genre"] = QStringList(md.genre());
     return map;
 }
Exemplo n.º 20
0
void NDBusDevice::setupNetworks(const QStringList &networks)
{
	qDebug() << "d->networks = " << networks;

	d->networks.clear();

	NDBusNetwork *net;
	QStringList::const_iterator iterator;
	for (iterator=networks.constBegin(); iterator!=networks.constEnd(); iterator++) {
		net = new NDBusNetwork(QDBusObjectPath(*iterator), this);
		net->update();
		d->networks << net;
	}
}
Exemplo n.º 21
0
QVariantMap Mpris::Metadata() const {
    QVariantMap metadataMap;
    if (!currentSong.title.isEmpty() && !currentSong.artist.isEmpty() &&
            (!currentSong.album.isEmpty() || (currentSong.isStream() && !currentSong.name().isEmpty()))) {
        metadataMap.insert("mpris:trackid", QVariant::fromValue<QDBusObjectPath>(QDBusObjectPath(mprisPath.arg(currentSong.id))));
        if (currentSong.time>0) {
            metadataMap.insert("mpris:length", convertTime(currentSong.time));
        }
        if (!currentSong.album.isEmpty()) {
            metadataMap.insert("xesam:album", currentSong.album);
        } else {
            QString name=currentSong.name();
            if (!name.isEmpty()) {
                metadataMap.insert("xesam:album", name);
            }
        }
        if (!currentSong.albumartist.isEmpty() && currentSong.albumartist!=currentSong.artist) {
            metadataMap.insert("xesam:albumArtist", QStringList() << currentSong.albumartist);
        }
        metadataMap.insert("xesam:artist", QStringList() << currentSong.artist);
        metadataMap.insert("xesam:title", currentSong.title);
        if (!currentSong.genre.isEmpty()) {
            metadataMap.insert("xesam:genre", QStringList() << currentSong.genre);
        }
        if (currentSong.track>0) {
            metadataMap.insert("xesam:trackNumber", currentSong.track);
        }
        if (currentSong.disc>0) {
            metadataMap.insert("xesam:discNumber", currentSong.disc);
        }
        if (currentSong.year>0) {
            metadataMap.insert("xesam:contentCreated", QString("%04d").arg(currentSong.year));
        }
        if (!currentSong.file.isEmpty()) {
            if (currentSong.isNonMPD()) {
                metadataMap.insert("xesam:url", currentSong.file);
            } else if (MPDConnection::self()->getDetails().dirReadable) {
                QString mpdDir=MPDConnection::self()->getDetails().dir;
                if (!mpdDir.isEmpty()) {
                    metadataMap.insert("xesam:url", "file://"+mpdDir+currentSong.file);
                }
            }
        }
        if (!currentCover.isEmpty()) {
             metadataMap.insert("mpris:artUrl", "file://"+currentCover);
        }
    }

    return metadataMap;
}
Exemplo n.º 22
0
QDBusObjectPath JobViewServer::requestView(const QString &appName, const QString &appIconName, int capabilities) {
  QString objectPath = QString("/JobViewServer/JobView_%1").arg(++lastID);
  JobView* jobview = new JobView(objectPath, appName, appIconName, capabilities);
  Plasma::Meter* meter = new Plasma::Meter();
  meter->setMeterType(Plasma::Meter::BarMeterHorizontal);
  meter->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
  activeMeters.insert(jobview->objectPath(), meter);
  activeJobViews.insert(jobview->objectPath(), jobview);
  meterLayout->addItem(meter);
  jobViewLayout->addItem(jobview);
  connect(jobview, SIGNAL(progressChanged(uint)), this, SLOT(updateMeter(uint)));
  connect(jobview, SIGNAL(terminated()), this, SLOT(jobViewTerminated()));
  updateStatusIndicators();
  return QDBusObjectPath(objectPath);
}
Exemplo n.º 23
0
FakeUser::FakeUser(const QString &path, qlonglong uid, const QString &name,
                   const QString &fullName, int accountType, QObject *parent)
    : QObject(parent)
    , cached(false)
    , m_uid(uid)
    , m_name(name)
    , m_fullName(fullName)
    , m_accountType(accountType)
    , m_path(QDBusObjectPath(path))
{
    QDBusConnection bus = QDBusConnection::sessionBus();

    if (!bus.registerObject(path, this))
        qFatal("Unable to register object: %s", qPrintable(bus.lastError().message()));
}
Exemplo n.º 24
0
void ClientImpl::removeAction(ActionImpl *actionImpl)
{
    QString path = actionImpl->path();
    if (!mActions.contains(path))
    {
        return;
    }

    QDBusPendingReply<bool> reply = mProxy->deactivateClientAction(QDBusObjectPath(path));
    reply.waitForFinished();

    QDBusConnection::sessionBus().unregisterObject(QString("/global_key_shortcuts") + path);

    mActions[path]->disconnect();
    mActions.remove(path);
}
Exemplo n.º 25
0
bool ClientImpl::modifyClientAction(const QString &path, const QString &description)
{
    if (!mActions.contains(path))
    {
        return false;
    }

    QDBusPendingReply<bool> reply = mProxy->modifyClientAction(QDBusObjectPath(path), description);
    reply.waitForFinished();
    if (reply.isError())
    {
        return false;
    }

    return reply.argumentAt<0>();
}
Exemplo n.º 26
0
QString ClientImpl::changeClientActionShortcut(const QString &path, const QString &shortcut)
{
    if (!mActions.contains(path))
    {
        return QString();
    }

    QDBusPendingReply<QString> reply = mProxy->changeClientActionShortcut(QDBusObjectPath(path), shortcut);
    reply.waitForFinished();
    if (reply.isError())
    {
        return QString();
    }

    return reply.argumentAt<0>();
}
Exemplo n.º 27
0
void BluetoothDevice::unpair()
{
    OrgBluezManagerInterface manager(
	    "org.bluez",
	    "/", QDBusConnection::systemBus());

    QDBusObjectPath adapterpath = manager.DefaultAdapter();

    if(adapterpath.path().isEmpty()) return;

    OrgBluezAdapterInterface adapter(
	    "org.bluez",
	    adapterpath.path(),
	    QDBusConnection::systemBus());

    adapter.RemoveDevice(QDBusObjectPath(m_device->path()));
}
Exemplo n.º 28
0
QZeitgeist::Monitor *Log::installMonitor(
        QZeitgeist::DataModel::TimeRange timeRange,
        QZeitgeist::DataModel::EventList eventTemplateList)
{
    Q_ASSERT(eventTemplateList.size() > 0);

    LogPrivate::monitorIdIndex++;

    QZeitgeist::Monitor *monitor = new QZeitgeist::Monitor(
            LogPrivate::monitorIdIndex,
            timeRange, eventTemplateList, this);

    d->logInterface->InstallMonitor(QDBusObjectPath(monitor->objectPath()),
            timeRange, eventTemplateList);

    return monitor;
}
DockManagerNotificationBackend::DockManagerNotificationBackend(QObject* parent)
    : AbstractNotificationBackend(parent)
    , _bus(QDBusConnection::sessionBus())
{
    NotificationSettings notificationSettings;
    _enabled = notificationSettings.value("DockManager/Enabled", false).toBool();

    notificationSettings.notify("DockManager/Enabled", this, &DockManagerNotificationBackend::enabledChanged);

    _dock = new QDBusInterface("net.launchpad.DockManager", "/net/launchpad/DockManager", "net.launchpad.DockManager", _bus, this);
    if (_dock->isValid()) {
        _bus.connect("net.launchpad.DockManager",
                     "/net/launchpad/DockManager",
                     "net.launchpad.DockManager",
                     "ItemAdded",
                     this,
                     SLOT(itemAdded(QDBusObjectPath)));
    }
    else {
        // evil implementations (awn) use fd.o
        _dock = new QDBusInterface("org.freedesktop.DockManager", "/org/freedesktop/DockManager", "org.freedesktop.DockManager", _bus, this);
        if (_dock->isValid()) {
            _bus.connect("org.freedesktop.DockManager",
                         "/org/freedesktop/DockManager",
                         "org.freedesktop.DockManager",
                         "ItemAdded",
                         this,
                         SLOT(itemAdded(QDBusObjectPath)));
        }
        else {
            _available = _enabled = false;
            return;
        }
    }
    _available = true;

    itemAdded(QDBusObjectPath());

    connect(Client::coreConnection(),
            &CoreConnection::progressValueChanged,
            this,
            selectOverload<int>(&DockManagerNotificationBackend::updateProgress));
    connect(Client::coreConnection(), &CoreConnection::synchronized, this, &DockManagerNotificationBackend::synchronized);
}
Exemplo n.º 30
0
QVariantMap MediaPlayer2Player::Metadata() const
{
    QVariantMap metaData;

    // The track ID is annoying since it must result in a valid DBus object
    // path, and the regex for that is, and I quote: [a-zA-Z0-9_]*, along with
    // the normal / delimiters for paths.
    PlaylistItem *item = Playlist::playingItem();
    if (!item)
        return metaData;

    FileHandle playingFile = item->file();
    QByteArray playingTrackFileId = idFromPlaylistItem(item);

    metaData["mpris:trackid"] =
        QVariant::fromValue<QDBusObjectPath>(
                QDBusObjectPath(playingTrackFileId.constData()));

    metaData["xesam:album"] = playingFile.tag()->album();
    metaData["xesam:title"] = playingFile.tag()->title();
    metaData["xesam:artist"] = QStringList(playingFile.tag()->artist());
    metaData["xesam:genre"]  = QStringList(playingFile.tag()->genre());

    metaData["mpris:length"] = qint64(playingFile.tag()->seconds() * 1000000);
    metaData["xesam:url"] = QString::fromLatin1(
            KUrl::fromLocalFile(playingFile.absFilePath()).toEncoded());

    if(playingFile.coverInfo()->hasCover()) {
        QString fallbackFileName = KStandardDirs::locateLocal("tmp",
                QString("juk-cover-%1.png").arg(item->trackId()));

        QString path = fallbackFileName;
        if(!QFile::exists(path)) {
            path = playingFile.coverInfo()->localPathToCover(fallbackFileName);
        }

        metaData["mpris:artUrl"] = QString::fromLatin1(QUrl::fromLocalFile(
                path).toEncoded());
    }

    return metaData;
}