Esempio n. 1
0
bool Systemd::SystemdPrivate::enableUnitFiles(const QStringList &files, bool runtime, bool force)
{
    qDBusRegisterMetaType<DBusUnitFileChange>();
    qDBusRegisterMetaType<DBusUnitFileChangeList>();
    QDBusPendingReply<bool, DBusUnitFileChangeList> reply = isdface.EnableUnitFiles(files, runtime, force);
    reply.waitForFinished();

    if (reply.isError()) {
        qDebug() << reply.error().message();
        return false;
    }

    return true;
}
void QOfonoConnectionContext::setContextPath(const QString &idPath)
{

    if (idPath != contextPath()) {
        if(d_ptr->context) {
            delete d_ptr->context;
            d_ptr->context = 0;
            d_ptr->properties.clear();
        }

qDebug() << Q_FUNC_INFO;
        d_ptr->context = new OfonoConnectionContext("org.ofono", idPath, QDBusConnection::systemBus(),this);
        if (d_ptr->context->isValid()) {
            d_ptr->contextPath = idPath;
            connect(d_ptr->context,SIGNAL(PropertyChanged(QString,QDBusVariant)),
                    this,SLOT(propertyChanged(QString,QDBusVariant)));
            QDBusPendingReply<QVariantMap> reply;
            reply = d_ptr->context->GetProperties();
            reply.waitForFinished();
            if (reply.isError())
                Q_EMIT reportError(reply.error().message());

            d_ptr->properties = reply.value();
           Q_EMIT contextPathChanged(idPath);

        } else {
            Q_EMIT reportError("Context is not valid");
            qDebug() << Q_FUNC_INFO << "error Context is not valid";
        }
        QOfonoManager manager;
        if (manager.modems().count() > 0) {
            QOfonoConnectionManager connManager;
            Q_FOREACH (const QString &path, manager.modems()) {
                connManager.setModemPath(path);
                if (connManager.contexts().contains(idPath)) {
                    d_ptr->modemPath = path;
                    Q_EMIT modemPathChanged(path);
                    break;
                }
            }
        }
/*        if (!validateProvisioning()) {
            provisionForCurrentNetwork(this->type());
        } else {
            Q_EMIT reportError("Context provision is not valid");
            qDebug() << Q_FUNC_INFO << "error Context provision is not valid";
        }
*/
    }
QString QBluetoothSocketPrivate::peerName() const
{
    quint64 bdaddr;

    if (socketType == QBluetoothServiceInfo::RfcommProtocol) {
        sockaddr_rc addr;
        socklen_t addrLength = sizeof(addr);

        if (::getpeername(socket, reinterpret_cast<sockaddr *>(&addr), &addrLength) < 0)
            return QString();

        convertAddress(addr.rc_bdaddr.b, bdaddr);
    } else if (socketType == QBluetoothServiceInfo::L2capProtocol) {
        sockaddr_l2 addr;
        socklen_t addrLength = sizeof(addr);

        if (::getpeername(socket, reinterpret_cast<sockaddr *>(&addr), &addrLength) < 0)
            return QString();

        convertAddress(addr.l2_bdaddr.b, bdaddr);
    } else {
        qCWarning(QT_BT_BLUEZ) << "peerName() called on socket of unknown type";
        return QString();
    }

    const QString peerAddress = QBluetoothAddress(bdaddr).toString();
    const QString localAdapter = localAddress().toString();

    if (isBluez5()) {
        OrgFreedesktopDBusObjectManagerInterface manager(QStringLiteral("org.bluez"),
                                                         QStringLiteral("/"),
                                                         QDBusConnection::systemBus());
        QDBusPendingReply<ManagedObjectList> reply = manager.GetManagedObjects();
        reply.waitForFinished();
        if (reply.isError())
            return QString();

        foreach (const QDBusObjectPath &path, reply.value().keys()) {
            const InterfaceList ifaceList = reply.value().value(path);
            foreach (const QString &iface, ifaceList.keys()) {
                if (iface == QStringLiteral("org.bluez.Device1")) {
                    if (ifaceList.value(iface).value(QStringLiteral("Address")).toString()
                            == peerAddress)
                        return ifaceList.value(iface).value(QStringLiteral("Alias")).toString();
                }
            }
        }
        return QString();
    } else {
void QMirClientClipboard::onDBusClipboardGetContentsFinished(QDBusPendingCallWatcher* call)
{
    Q_ASSERT(call == mPendingGetContentsCall.data());

    QDBusPendingReply<QByteArray> reply = *call;
    if (reply.isError()) {
        qCritical("QMirClientClipboard - Failed to get system clipboard contents via D-Bus. %s, %s",
                qPrintable(reply.error().name()), qPrintable(reply.error().message()));
        // TODO: Might try again later a number of times...
    } else {
        QByteArray serializedMimeData = reply.argumentAt<0>();
        updateMimeData(serializedMimeData);
    }
    call->deleteLater();
}
Esempio n. 5
0
void ItemRetrievalJob::callFinished(QDBusPendingCallWatcher *watcher)
{
    watcher->deleteLater();
    QDBusPendingReply<QString> reply = *watcher;
    if (m_active) {
        m_active = false;
        const QString errorMsg = reply.isError() ? reply.error().message() : reply;
        if (!errorMsg.isEmpty()) {
            Q_EMIT requestCompleted(m_request, QStringLiteral("Unable to retrieve item from resource: %1").arg(errorMsg));
        } else {
            Q_EMIT requestCompleted(m_request, QString());
        }
    }
    deleteLater();
}
void PlayerActionJob::callFinished(QDBusPendingCallWatcher* watcher)
{
    QDBusPendingReply<void> result = *watcher;
    watcher->deleteLater();

    if (result.isError()) {
        // FIXME: try to be a bit cleverer with the error message?
        setError(Failed);
        setErrorText(result.error().message());
    } else {
        setError(NoError);
    }

    emitResult();
}
Esempio n. 7
0
void A2DPTest::connectResult(QDBusPendingCallWatcher *watcher)
{
    watcher->deleteLater();
    QDBusPendingReply<> reply = *watcher;
    if (!reply.isValid()) {
        if (reply.isError() && reply.error().name() == A2DP_CONNECTED) {
            emit deviceReady(true);
            return;
        }

        delete audioSink;
        audioSink = NULL;
        emit deviceReady(false);
    } else
        emit deviceReady(true);
}
/*!
    Creates a new \a accountType type user account whose name is \a userName,
    real name is \a fullName.

    \param userName The name of the new user to be created.
    \param fullName First name and last name.
    \param accountType The account type.
    \return whether the user was created successfully.
*/
bool AccountsManager::createUser(const QString &userName,
                                 const QString &fullName,
                                 UserAccount::AccountType accountType)
{
    Q_D(AccountsManager);

    QDBusPendingReply<QDBusObjectPath> reply = d->interface->CreateUser(userName, fullName, accountType);
    if (reply.isError()) {
        QDBusError error = reply.error();
        qWarning("Couldn't create user %s: %s", userName.toUtf8().constData(),
                 error.errorString(error.type()).toUtf8().constData());
        return false;
    }

    return true;
}
Esempio n. 9
0
Unit::Ptr SystemdPrivate::getUnit(const QString &name)
{
    Unit::Ptr unit;

    QDBusPendingReply<QDBusObjectPath> reply = isdface.GetUnit(name);
    reply.waitForFinished();

    if (reply.isError()) {
        qDebug() << reply.error().message();
    } else if (! reply.reply().arguments().isEmpty()) {
        QString unitPath = qdbus_cast<QDBusObjectPath>(reply.reply().arguments().first()).path();
        unit = Unit::Ptr(new Unit(unitPath), &QObject::deleteLater);
    }

    return unit;
}
Esempio n. 10
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>();
}
Esempio n. 11
0
void QBluetoothLocalDevice::powerOn()
{
    if (!d_ptr)
        return;

    // Ensure that mode change is confirmed by first requesting a session
    QDBusPendingReply<void> reply = d_ptr->adapter->RequestSession();
    reply.waitForFinished();
    if (reply.isError())
        return;

    d_ptr->adapter->SetProperty(QLatin1String("Powered"), QDBusVariant(QVariant::fromValue(true)));

    // Release requested session in order to keep Bluez happy
    d_ptr->adapter->ReleaseSession();
}
Esempio n. 12
0
Job::Ptr SystemdPrivate::getJob(const uint id)
{
    Job::Ptr job;

    QDBusPendingReply<QDBusObjectPath> reply = isdface.GetJob(id);
    reply.waitForFinished();

    if (reply.isError()) {
        qDebug() << reply.error().message();
    } else if (! reply.reply().arguments().isEmpty()) {
        QString jobPath = qdbus_cast<QDBusObjectPath>(reply.reply().arguments().first()).path();
        job = Job::Ptr(new Job(jobPath), &QObject::deleteLater);
    }

    return job;
}
static inline OrgBluezDeviceInterface *getDevice(const QBluetoothAddress &address, QBluetoothLocalDevicePrivate *d_ptr)
{
    if (!d_ptr || !d_ptr->adapter)
        return 0;
    QDBusPendingReply<QDBusObjectPath> reply = d_ptr->adapter->FindDevice(address.toString());
    reply.waitForFinished();
    if(reply.isError()) {
        qWarning() << Q_FUNC_INFO << "reply failed" << reply.error();
        return 0;
    }

    QDBusObjectPath path = reply.value();

    return new OrgBluezDeviceInterface(QLatin1String("org.bluez"), path.path(),
                                       QDBusConnection::systemBus());
}
Esempio n. 14
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>();
}
Esempio n. 15
0
AccountModel::AccountModel(QObject* parent)
 : QAbstractListModel(parent)
 , m_sessions(new UserSession(this))
{
    m_dbus = new AccountsManager("org.freedesktop.Accounts", "/org/freedesktop/Accounts", QDBusConnection::systemBus(), this);
    QDBusPendingReply <QList <QDBusObjectPath > > reply = m_dbus->ListCachedUsers();
    reply.waitForFinished();

    if (reply.isError()) {
        qCDebug(USER_MANAGER_LOG) << reply.error().message();
        return;
    }

    QList<QDBusObjectPath> users = reply.value();
    Q_FOREACH(const QDBusObjectPath& path, users) {
        addAccount(path.path());
    }
void AudioPlayerControlRunner::songsInPlaylist(QDBusPendingCallWatcher *call)
{
    QDBusPendingReply<int> reply = *call;
    m_running = !reply.isError();

    if (m_running) {
        m_songsInPlaylist = reply.value();
        if (m_currentTrack > -1) {
            // calculate if the next song is available given the new count
            m_nextSongAvailable = m_songsInPlaylist > m_currentTrack;
        }
    } else {
        m_songsInPlaylist = 0;
    }

    call->deleteLater();
}
Esempio n. 17
0
void QOfonoCallForwarding::getPropertiesComplete(QDBusPendingCallWatcher *call)
{
    QDBusPendingReply<QVariantMap> reply = *call;
    if (!reply.isError()) {
        d_ptr->properties = reply.value();
        Q_EMIT voiceUnconditionalChanged(voiceUnconditional());
        Q_EMIT voiceBusyChanged(voiceBusy());
        Q_EMIT voiceNoReplyChanged(voiceNoReply());
        Q_EMIT voiceNoReplyTimeoutChanged(voiceNoReplyTimeout());
        Q_EMIT voiceNotReachableChanged(voiceNotReachable());
        Q_EMIT forwardingFlagOnSimChanged(forwardingFlagOnSim());
        Q_EMIT readyChanged();
    } else {
        Q_EMIT getPropertiesFailed();
    }
    call->deleteLater();
}
Esempio n. 18
0
void ConferenceAuthOp::passwordFlagOperationFinished(QDBusPendingCallWatcher *watcher)
{
    QDBusPendingReply<uint> reply = *watcher;
    if (reply.isError()) {
        qWarning() << "Reply is a error. ABORT!";
        return;
    }


    if (reply.argumentAt<0>() == Tp::ChannelPasswordFlagProvide) {
        if (m_walletInterface->hasEntry(m_account, m_channel->targetId())) {
            providePassword(m_walletInterface->entry(m_account, m_channel->targetId()));
        } else {
            passwordDialog();
        }
    }
}
Esempio n. 19
0
QNetworkManagerSettingsConnection::QNetworkManagerSettingsConnection(const QString &settingsService, const QString &connectionObjectPath, QObject *parent)
    : QDBusAbstractInterface(settingsService,
                             connectionObjectPath,
                             NM_DBUS_IFACE_SETTINGS_CONNECTION,
                             QDBusConnection::systemBus(), parent)
{
    qDBusRegisterMetaType<QNmSettingsMap>();
    if (!isValid()) {
        return;
    }
    interfacepath = connectionObjectPath;
    QDBusPendingReply<QNmSettingsMap> nmReply
            = call(QLatin1String("GetSettings"));
    if (!nmReply.isError()) {
        settingsMap = nmReply.value();
    }
}
Esempio n. 20
0
QNetworkManagerSettings::QNetworkManagerSettings(const QString &settingsService, QObject *parent)
        : QDBusAbstractInterface(settingsService,
                                 NM_DBUS_PATH_SETTINGS,
                                 NM_DBUS_IFACE_SETTINGS,
                                 QDBusConnection::systemBus(), parent)
{
    if (!isValid()) {
        return;
    }
    interfacePath = settingsService;
    QDBusPendingReply<QList <QDBusObjectPath> > nmReply
            = call(QLatin1String("ListConnections"));

    if (!nmReply.isError()) {
        connectionsList = nmReply.value();
    }
}
Esempio n. 21
0
void OperatorProxy::operatorDBusGetPropDone(QDBusPendingCallWatcher *call)
{
    QDBusPendingReply<QVariantMap> reply = *call;

    if (reply.isError()) {
        // TODO: Handle this properly
        qCritical() << org::ofono::NetworkOperator::staticInterfaceName() <<
                       ".GetProperties() failed: " << reply.error().message();
    } else {
        QVariantMap properties = reply.value();
        m_countryCode  = qdbus_cast<QString>(properties["MobileCountryCode"]);
        m_networkCode  = qdbus_cast<QString>(properties["MobileNetworkCode"]);
        m_name         = qdbus_cast<QString>(properties["Name"]);
        m_status       = qdbus_cast<QString>(properties["Status"]);
        m_technologies = qdbus_cast<QStringList>(properties["Technologies"]);
    }
}
void AudioPlayerControlRunner::prevNextSongAvailable(QDBusPendingCallWatcher *call)
{
    QDBusPendingReply<int> reply = *call;
    m_running = !reply.isError();

    if (m_running) {
        m_currentTrack = reply.value();
        if (m_songsInPlaylist > 0) {
            m_nextSongAvailable = m_songsInPlaylist > m_currentTrack;
            m_prevSongAvailable = m_currentTrack > 0;
        }
    } else {
        m_currentTrack = 0;
    }

    call->deleteLater();
}
void PendingContactInfo::onCallFinished(QDBusPendingCallWatcher *watcher)
{
    QDBusPendingReply<Tp::ContactInfoFieldList> reply = *watcher;

    if (!reply.isError()) {
        mPriv->info = Contact::InfoFields(reply.value());
        debug() << "Got reply to ContactInfo.RequestContactInfo";
        setFinished();
    } else {
        debug().nospace() <<
            "ContactInfo.RequestContactInfo failed: " <<
            reply.error().name() << ": " << reply.error().message();
        setFinishedWithError(reply.error());
    }

    watcher->deleteLater();
}
Esempio n. 24
0
void Device::isLaptopFetched(QDBusPendingCallWatcher* watcher)
{
    const QDBusPendingReply<QVariant> reply = *watcher;
    if (reply.isError()) {
        qCDebug(KSCREEN_KDED) << "Couldn't get if the device is a laptop: " << reply.error().message();
        return;
    }

    m_isLaptop = reply.value().toBool();
    watcher->deleteLater();

    if (!m_isLaptop) {
        setReady();
        return;
    }

    fetchLidIsClosed();
}
Esempio n. 25
0
void Device::isLidClosedFetched(QDBusPendingCallWatcher* watcher)
{
    const QDBusPendingReply<QVariant> reply = *watcher;
    if (reply.isError()) {
        qCDebug(KSCREEN_KDED) << "Couldn't get if the laptop has the lid closed: " << reply.error().message();
        return;
    }

    if (reply.argumentAt<0>() != m_isLidClosed) {
        m_isLidClosed = reply.value().toBool();
        if (m_isReady) {
            Q_EMIT lidClosedChanged(m_isLidClosed);;
        }
    }
    watcher->deleteLater();

    fetchIsDocked();
}
Esempio n. 26
0
File: ssu.cpp Progetto: jvihrial/ssu
void Ssu::updateStoreCredentials(){
  QDBusMessage message = QDBusMessage::createMethodCall("com.jolla.jollastore",
                                                        "/StoreClient",
                                                        "com.jolla.jollastore",
                                                        "storeCredentials");
  QDBusPendingReply<QString, QString> reply = SsuCoreConfig::userSessionBus().asyncCall(message);
  reply.waitForFinished();
  if (reply.isError()) {
    setError(QString("Store credentials not received. %1").arg(reply.error().message()));
  } else {
    SsuCoreConfig *settings = SsuCoreConfig::instance();
    settings->beginGroup("credentials-store");
    settings->setValue("username", reply.argumentAt<0>());
    settings->setValue("password", reply.argumentAt<1>());
    settings->endGroup();
    settings->sync();
  }
}
Esempio n. 27
0
void NetworkManager::getTechnologiesReply(QDBusPendingCallWatcher *call)
{
    Q_ASSERT(call);

    pr_dbg() << "Got reply with technolgies";

    QDBusPendingReply<ConnmanObjectList> reply = *call;
    if (reply.isError()) {

        pr_dbg() << "Error getTechnologiesReply:" << reply.error().message();

        disconnectFromConnman();

        // TODO: set up timer to reconnect in a bit
        //QTimer::singleShot(10000,this,SLOT(connectToConnman()));
    } else {

        ConnmanObjectList lst = reply.value();
        ConnmanObject obj;
        foreach (obj, lst) { // TODO: consider optimizations

            NetworkTechnology *tech = new NetworkTechnology(obj.objpath.path(),
                    obj.properties, this);

            m_technologiesCache.insert(tech->type(), tech);

            pr_dbg() << "Technology: " << tech->type();
            pr_dbg() << "\tConnected:" << tech->connected();
            pr_dbg() << "\tPowered:" << tech->powered();
        }

        connect(m_manager,
                SIGNAL(TechnologyAdded(const QDBusObjectPath &, const QVariantMap &)),
                this,
                SLOT(technologyAdded(const QDBusObjectPath &, const QVariantMap &)));

        connect(m_manager,
                SIGNAL(TechnologyRemoved(const QDBusObjectPath &)),
                this,
                SLOT(technologyRemoved(const QDBusObjectPath &)));

        emit technologiesChanged();
    }
Esempio n. 28
0
void NetworkManager::getPropertiesReply(QDBusPendingCallWatcher *call)
{
    Q_ASSERT(call);
    QDBusPendingReply<QVariantMap> reply = *call;
    if (reply.isError()) {
        qDebug() << "Error getPropertiesReply: " << reply.error().message();
        disconnectFromConnman();
        // TODO: set up timer to reconnect in a bit
        QTimer::singleShot(10000,this,SLOT(connectToConnman()));
    } else {
        m_propertiesCache = reply.value();
        emit stateChanged(m_propertiesCache[State].toString());
        qDebug() << "State: " << m_propertiesCache["State"].toString();
        connect(m_manager,
                SIGNAL(PropertyChanged(const QString&, const QDBusVariant&)),
                this,
                SLOT(propertyChanged(const QString&, const QDBusVariant&)));
    }
}
Esempio n. 29
0
QBluetoothLocalDevice::HostMode QBluetoothLocalDevice::hostMode() const
{
    if (!d_ptr)
        return HostPoweredOff;

    QDBusPendingReply<QVariantMap> reply = d_ptr->adapter->GetProperties();
    reply.waitForFinished();
    if (reply.isError())
        return HostPoweredOff;

    if (!reply.value().value(QLatin1String("Powered")).toBool())
        return HostPoweredOff;
    else if (reply.value().value(QLatin1String("Discoverable")).toBool())
        return HostDiscoverable;
    else if (reply.value().value(QLatin1String("Powered")).toBool())
        return HostConnectable;

    return HostPoweredOff;
}
Esempio n. 30
0
Action *ClientImpl::addClientAction(const QString &shortcut, const QString &path, const QString &description, QObject *parent)
{
    if (!QRegExp("(/[A-Za-z0-9_]+){2,}").exactMatch(path))
    {
        return 0;
    }

    if (mActions.contains(path))
    {
        return 0;
    }

    Action *globalAction = new Action(parent);

    ActionImpl *globalActionImpl = new ActionImpl(this, globalAction, path, description, globalAction);
    globalAction->impl = globalActionImpl;

    if (!QDBusConnection::sessionBus().registerObject(QString("/global_key_shortcuts") + path, globalActionImpl))
    {
        return 0;
    }

    if (mDaemonPresent)
    {
        QDBusPendingReply<QString, qulonglong> reply = mProxy->addClientAction(shortcut, QDBusObjectPath(path), description);
        reply.waitForFinished();
        globalActionImpl->setValid(!reply.isError() && reply.argumentAt<1>());
        if (globalActionImpl->isValid())
        {
            globalActionImpl->setShortcut(reply.argumentAt<0>());
        }
    }
    else
    {
        globalActionImpl->setValid(false);
    }

    mActions[path] = globalAction;


    return globalAction;
}