Exemple #1
0
bool SensorManager::registerService()
{
    clearError();

    bool ok = bus().isConnected();
    if ( !ok )
    {
        QDBusError error = bus().lastError();
        setError(SmNotConnected, error.message());
        return false;
    }

    ok = bus().registerObject( OBJECT_PATH, this );
    if ( !ok )
    {
        QDBusError error = bus().lastError();
        setError(SmCanNotRegisterObject, error.message());
        return false;
    }

    ok = bus().registerService ( SERVICE_NAME );
    if ( !ok )
    {
        QDBusError error = bus().lastError();
        setError(SmCanNotRegisterService, error.message());
        return false;
    }
    return true;
}
QString KWinWaylandTouchpad::valueWriter(const Prop<T> &prop)
{
    if (!prop.changed()) {
        return QString();
    }
    m_iface->setProperty(prop.dbus, prop.val);
    QDBusError error = m_iface->lastError();
    if (error.isValid()) {
        qCCritical(KCM_TOUCHPAD) << error.message();
        return error.message();
    }
    return QString();
}
bool DBusLauncherImpl::launch(const QUrl& url, const QString& mimeType, QWidget* window)
{
    if (!url.isValid()) return false;

    if (url.isLocalFile()) return launch(url.path(), mimeType, window); 

    if (mimeType.isEmpty()) return launch(url, window);

    QDBusError error;
    QValueList<QVariant> params;
    params.append(url.toString());
    params.append(mimeType);

    QDBusMessage reply = m_proxy->sendWithReply("LaunchURL", params, &error);

    if (error.isValid())
    {
        qWarning("Error while launching through D-Bus:\nerror '%s'\nmessage '%s'",
                    error.name().local8Bit().data(), error.message().local8Bit().data());
        return false;
    }

    if (reply.count() != 1 || reply[0].type() != QVariant::Bool)
    {
        qWarning("Unexpected launcher reply");
        return false;
    }

    return reply[0].toBool();
}
bool DBusLauncherImpl::launch(const QString& fileName, const QString& mimeType,
                                 QWidget* window)
{
    QFileInfo fileInfo(fileName);
    if (!fileInfo.exists() || !fileInfo.isReadable()) return false;

    if (mimeType.isEmpty()) return launch(fileName, window);

    QDBusError error;
    QValueList<QVariant> params;
    params.append(fileInfo.absFilePath());
    params.append(mimeType);

    QDBusMessage reply = m_proxy->sendWithReply("LaunchFile", params, &error);

    if (error.isValid())
    {
        qWarning("Error while launching through D-Bus:\nerror '%s'\nmessage '%s'",
                    error.name().local8Bit().data(), error.message().local8Bit().data());
        return false;
    }

    if (reply.count() != 1 || reply[0].type() != QVariant::Bool)
    {
        qWarning("Unexpected launcher reply");
        return false;
    }

    return reply[0].toBool();
}
Exemple #5
0
bool KHotKeys::init()
{
    khotkeys_inited = true;

    // Check if khotkeys is running
    QDBusConnection bus = QDBusConnection::sessionBus();
    khotkeysInterface = new OrgKdeKhotkeysInterface(
        "org.kde.kded",
        "/modules/khotkeys",
        bus,
        NULL);

    QDBusError err;
    if(!khotkeysInterface->isValid())
        {
        err = khotkeysInterface->lastError();
        if (err.isValid())
            {
            kError() << err.name() << ":" << err.message();
            }
        KMessageBox::error(
            NULL,
            "<qt>" + i18n("Unable to contact khotkeys. Your changes are saved, but they could not be activated.") + "</qt>" );
        }

    khotkeys_present = khotkeysInterface->isValid();
    return true;
}
void CReporterNotificationPrivate::retrieveNotificationId()
{
    if (callWatcher == 0)
        return;

    callWatcher->waitForFinished();

    QDBusPendingReply<quint32> reply = *callWatcher;
    callWatcher->deleteLater();
    callWatcher = 0;

    if (reply.isValid()) {
        id = reply.argumentAt<0>();
        if (id == 0) {
            // Notification didn't exist, create a new one.
            sendDBusNotify();
            retrieveNotificationId();
            return;
        }
        qDebug() << __PRETTY_FUNCTION__
                 << "Create notification with id: " << id;
    } else if (reply.isError()) {
        QDBusError error = reply.error();
        qDebug() << __PRETTY_FUNCTION__ << "Failed to create notification: "
                 << error.name() << " - " << error.message();
    }
}
Exemple #7
0
void QSpiApplicationAdaptor::notifyKeyboardListenerError(const QDBusError& error, const QDBusMessage& /*message*/)
{
    qWarning() << "QSpiApplication::keyEventError " << error.name() << error.message();
    while (!keyEvents.isEmpty()) {
        QPair<QObject*, QKeyEvent*> event = keyEvents.dequeue();
        QApplication::postEvent(event.first, event.second);
    }
}
Exemple #8
0
QScriptValue qDBusErrorToScriptValue(QScriptEngine *engine, const QDBusError &error)
{
    QScriptValue v = engine->newObject();
    v.setProperty(QLatin1String("type"), QScriptValue(engine, error.type()), QScriptValue::ReadOnly);
    v.setProperty(QLatin1String("name"), QScriptValue(engine, error.name()), QScriptValue::ReadOnly);
    v.setProperty(QLatin1String("message"), QScriptValue(engine, error.message()), QScriptValue::ReadOnly);
    v.setProperty(QLatin1String("isValid"), QScriptValue(engine, error.isValid()), QScriptValue::ReadOnly);
    return v;
}
Exemple #9
0
bool TimeDateCtl::setTimeZone(QString timeZone, QString& errorMessage)
{
    mIface->call("SetTimezone", timeZone, true);
    QDBusError err = mIface->lastError();
    if(err.isValid())
    {
        errorMessage = err.message();
        return false;
    }
    return true;
}
Exemple #10
0
void KNotification::slotReceivedIdError(const QDBusError& error)
{
	if(d->id == -2) //we are already closed
	{
		deleteLater();
		return;
	}
	kWarning(299) << "Error while contacting notify daemon" << error.message();
	d->id = -3;
	QTimer::singleShot(0, this, SLOT(deref()));
}
Exemple #11
0
bool TimeDateCtl::setUseNtp(bool value, QString& errorMessage)
{
    mIface->call("SetNTP", value, true);
    QDBusError err = mIface->lastError();
    if(err.isValid())
    {
        errorMessage = err.message();
        return false;
    }
    return true;
}
bool ServiceControl::stopService()
{
    QDBusError reply;
    systemd->call("StopUnit", ROCKPOOLD_SYSTEMD_UNIT, "replace");
    systemd->call("DisableUnitFiles", QStringList() << ROCKPOOLD_SYSTEMD_UNIT, false);
    if (reply.isValid()) {
        qWarning() << reply.message();
        return false;
    } else {
        systemd->call("Reload");
        return true;
    }
}
Exemple #13
0
bool TimeDateCtl::setDateTime(QDateTime dateTime, QString& errorMessage)
{
    // the timedatectl dbus service accepts "usec" input.
    // Qt can only get "msec"  => convert to usec here.
    mIface->call("SetTime", dateTime.toMSecsSinceEpoch() * 1000, false, true);
    QDBusError err = mIface->lastError();
    if(err.isValid())
    {
        errorMessage = err.message();
        return false;
    }
    return true;
}
void KCMHotkeysPrivate::save()
    {
    if (current)
        applyCurrentItem();

    // Write the settings
    model->save();

    if (!KHotKeys::Daemon::isRunning())
        {
        if (!KHotKeys::Daemon::start())
            {
            // On startup the demon does the updating stuff, therefore reload
            // the actions.
            model->load();
            }
        else
            {
            KMessageBox::error(
                q,
                "<qt>" + i18n("Unable to contact khotkeys. Your changes are saved, but they could not be activated.") + "</qt>" );
            }

        return;
        }

    // Inform kdedkhotkeys demon to reload settings
    QDBusConnection bus = QDBusConnection::sessionBus();
    QPointer<OrgKdeKhotkeysInterface> iface = new OrgKdeKhotkeysInterface(
        "org.kde.kded",
        "/modules/khotkeys",
        bus,
        q);

    QDBusError err;
    if(!iface->isValid())
        {
        err = iface->lastError();
        if (err.isValid())
            {
            kError() << err.name() << ":" << err.message();
            }
        KMessageBox::error(
            q,
            "<qt>" + i18n("Unable to contact khotkeys. Your changes are saved, but they could not be activated.") + "</qt>" );
        return;
        }

    // Reread the configuration. We have no possibility to check if it worked.
    iface->reread_configuration();
    }
void getProperty(const QString &service, const QString &path, const QString &interfaceAndName)
{
    QString property;
    QString interface;
    if (!splitInterfaceAndName(interfaceAndName, "Property", interface, property))
        exit(1);
    
    QDBusInterfacePtr iface(*connection, service, path, interface);
    QVariant reply = iface->property(property.toLatin1());
    if (reply.isNull()) {
        QDBusError error = iface->lastError();
        fprintf(stderr, "Could not get property '%s' on interface '%s': %s (%s)\n",
                qPrintable(property), qPrintable(interface), qPrintable(error.name()),
                qPrintable(error.message()));
        exit(1);
    }

    printf("%s\n", qPrintable(reply.toString()));
}
Exemple #16
0
AbstractSensorChannel* SensorManager::addSensor(const QString& id)
{
    sensordLogD() << "Adding sensor: " << id;

    clearError();

    QString cleanId = getCleanId(id);
    QMap<QString, SensorInstanceEntry>::const_iterator entryIt = sensorInstanceMap_.find(cleanId);

    if (entryIt == sensorInstanceMap_.end()) {
        sensordLogC() << QString("%1 not present").arg(cleanId);
        setError( SmIdNotRegistered, QString(tr("instance for sensor type '%1' not registered").arg(cleanId)) );
        return NULL;
    }

    const QString& typeName = entryIt.value().type_;

    if ( !sensorFactoryMap_.contains(typeName) )
    {
        setError( SmFactoryNotRegistered, QString(tr("factory for sensor type '%1' not registered").arg(typeName)) );
        return NULL;
    }

    AbstractSensorChannel* sensorChannel = sensorFactoryMap_[typeName](id);
    if ( !sensorChannel->isValid() )
    {
        sensordLogC() << QString("%1 instantiation failed").arg(cleanId);
        delete sensorChannel;
        return NULL;
    }

    bool ok = bus().registerObject(OBJECT_PATH + "/" + sensorChannel->id(), sensorChannel);
    if ( !ok )
    {
        QDBusError error = bus().lastError();
        setError(SmCanNotRegisterObject, error.message());
        sensordLogC() << "Failed to register sensor '" << OBJECT_PATH + "/" + sensorChannel->id() << "'";
        delete sensorChannel;
        return NULL;
    }
    return sensorChannel;
}
Exemple #17
0
bool Notifications::notifyDBus(const QString &text) {
	Q_ASSERT(m_interface);

	if (!m_interface->isValid()) return false;

	QString member = "Notify";
	QVariantList params;
	params << qApp->applicationName() << static_cast<unsigned int>(0);
	params << "/home/h/Projects/qmpdclient/qmpdclient/icons/qmpdclient22.png";
	params << qApp->applicationName() << text;
	params << QStringList() << QMap<QString, QVariant>() << Config::instance()->notificationsTimeout()*1000;
	QDBusMessage reply = m_interface->callWithArgumentList(QDBus::Block, member, params);

	if (reply.type() == QDBusMessage::ErrorMessage) {
		QDBusError err = reply;
		qWarning("Error: %s\n%s", qPrintable(err.name()), qPrintable(err.message()));
		return false;
	} else if (reply.type() != QDBusMessage::ReplyMessage) {
		qWarning("Invalid reply type %d", int(reply.type()));
		return false;
	}

	return true;
}
void DesktopNotificationsFactory::error(const QDBusError &error)
{
    qWarning() << "QDBusError:" << error.message();
}
void QOfonoMessageManager::messagesError(const QDBusError &error)
{
    qDebug() << Q_FUNC_INFO << error.message();
}
Exemple #20
0
void WatchCommands::musicControl(WatchConnector::MusicControl operation)
{
    logger()->debug() << "Operation:" << operation;

    QString mpris = parent()->property("mpris").toString();
    if (mpris.isEmpty()) {
        logger()->debug() << "No mpris interface active";
        return;
    }

    QString method;

    switch(operation) {
    case WatchConnector::musicPLAY_PAUSE:
        method = "PlayPause";
        break;
    case WatchConnector::musicPAUSE:
        method = "Pause";
        break;
    case WatchConnector::musicPLAY:
        method = "Play";
        break;
    case WatchConnector::musicNEXT:
        method = "Next";
        break;
    case WatchConnector::musicPREVIOUS:
        method = "Previous";
        break;
    case WatchConnector::musicVOLUME_UP:
    case WatchConnector::musicVOLUME_DOWN: {
            QDBusReply<QDBusVariant> VolumeReply = QDBusConnection::sessionBus().call(
                        QDBusMessage::createMethodCall(mpris, "/org/mpris/MediaPlayer2", "org.freedesktop.DBus.Properties", "Get")
                        << "org.mpris.MediaPlayer2.Player" << "Volume");
            if (VolumeReply.isValid()) {
                double volume = VolumeReply.value().variant().toDouble();
                if (operation == WatchConnector::musicVOLUME_UP) {
                    volume += 0.1;
                }
                else {
                    volume -= 0.1;
                }
                logger()->debug() << "Setting volume" << volume;
                QDBusError err = QDBusConnection::sessionBus().call(
                            QDBusMessage::createMethodCall(mpris, "/org/mpris/MediaPlayer2", "org.freedesktop.DBus.Properties", "Set")
                            << "org.mpris.MediaPlayer2.Player" << "Volume" << QVariant::fromValue(QDBusVariant(volume)));
                if (err.isValid()) {
                    logger()->error() << err.message();
                }
            }
            else {
                logger()->error() << VolumeReply.error().message();
            }
        }
        return;
    case WatchConnector::musicGET_NOW_PLAYING:
        onMprisMetadataChanged(parent()->property("mprisMetadata").toMap());
        return;

    case WatchConnector::musicSEND_NOW_PLAYING:
        logger()->warn() << "Operation" << operation << "not supported";
        return;
    }

    if (method.isEmpty()) {
        logger()->error() << "Requested unsupported operation" << operation;
        return;
    }

    logger()->debug() << operation << "->" << method;

    QDBusError err = QDBusConnection::sessionBus().call(
                QDBusMessage::createMethodCall(mpris, "/org/mpris/MediaPlayer2", "org.mpris.MediaPlayer2.Player", method));
    if (err.isValid()) {
        logger()->error() << err.message();
    }
}
Exemple #21
0
void ReadPasswordJobPrivate::kwalletReadFinished( QDBusPendingCallWatcher* watcher ) {
    watcher->deleteLater();
    if ( watcher->isError() ) {
        const QDBusError err = watcher->error();
        q->emitFinishedWithError( OtherError, tr("Could not read password: %1; %2").arg( QDBusError::errorString( err.type() ), err.message() ) );
        return;
    }

    if ( dataType == Binary ) {
        QDBusPendingReply<QByteArray> reply = *watcher;
        data = reply.value();
    } else {
        QDBusPendingReply<QString> reply = *watcher;
        data = reply.value().toUtf8();
    }
    q->emitFinished();
}
void DBusProxy::invalidate(const QDBusError &error)
{
    invalidate(error.name(), error.message());
}
void DynamicAddress::errorCallback(const QDBusError &error)
{
    Q_EMIT addressFetchError(error.message());
}
void UDiskMountDevice::dbusError(const QDBusError &err, const QDBusMessage &msg)
{
    qWarning() << "UdisksInfo::mDbus_error" << err.message();
    emit error(err.message());
}
Exemple #25
0
void ReadPasswordJobPrivate::kwalletEntryTypeFinished( QDBusPendingCallWatcher* watcher ) {
    watcher->deleteLater();
    if ( watcher->isError() ) {
        const QDBusError err = watcher->error();
        q->emitFinishedWithError( OtherError, tr("Could not determine data type: %1; %2").arg( QDBusError::errorString( err.type() ), err.message() ) );
        return;
    }

    const QDBusPendingReply<int> reply = *watcher;

    dataType = reply.value() == 1/*Password*/ ? Text : Binary;

    const QDBusPendingCall nextReply = dataType == Text
                                       ? QDBusPendingCall( iface->readPassword( walletHandle, q->service(), key, q->service() ) )
                                       : QDBusPendingCall( iface->readEntry( walletHandle, q->service(), key, q->service() ) );
    QDBusPendingCallWatcher* nextWatcher = new QDBusPendingCallWatcher( nextReply, this );
    connect( nextWatcher, SIGNAL(finished(QDBusPendingCallWatcher*)), this, SLOT(kwalletReadFinished(QDBusPendingCallWatcher*)) );
}
Exemple #26
0
QDebug operator<<(QDebug dbg, const QDBusError &msg)
{
    dbg.nospace() << "QDBusError(" << msg.name() << ", " << msg.message() << ')';
    return dbg.space();
}
Exemple #27
0
void WritePasswordJobPrivate::kwalletWriteFinished( QDBusPendingCallWatcher* watcher ) {
    watcher->deleteLater();
    QDBusPendingReply<int> reply = *watcher;
    if ( reply.isError() ) {
        const QDBusError err = reply.error();
        q->emitFinishedWithError( OtherError, tr("Could not open wallet: %1; %2").arg( QDBusError::errorString( err.type() ), err.message() ) );
        return;
    }

    q->emitFinished();
}
Exemple #28
0
void WritePasswordJobPrivate::kwalletOpenFinished( QDBusPendingCallWatcher* watcher ) {
    watcher->deleteLater();
    QDBusPendingReply<int> reply = *watcher;

    std::auto_ptr<QSettings> local( !q->settings() ? new QSettings(  q->service() ) : 0 );
    QSettings* actual = q->settings() ? q->settings() : local.get();

    if ( reply.isError() ) {
        if ( q->insecureFallback() ) {
            if ( mode == Delete ) {
                actual->remove( key );
                actual->sync();

                q->emitFinished();
                return;
            }

            actual->setValue( QString( "%1/type" ).arg( key ), (int)mode );
            if ( mode == Text )
                actual->setValue( QString( "%1/data" ).arg( key ), textData.toUtf8() );
            else if ( mode == Binary )
                actual->setValue( QString( "%1/data" ).arg( key ), binaryData );
            actual->sync();

            q->emitFinished();
        } else {
            const QDBusError err = reply.error();
            q->emitFinishedWithError( OtherError, tr("Could not open wallet: %1; %2").arg( QDBusError::errorString( err.type() ), err.message() ) );
        }
        return;
    }

    if ( actual->contains( key ) )
    {
        // If we had previously written to QSettings, but we now have a kwallet available, migrate and delete old insecure data
        actual->remove( key );
        actual->sync();
    }

    const int handle = reply.value();

    if ( handle < 0 ) {
        q->emitFinishedWithError( AccessDenied, tr("Access to keychain denied") );
        return;
    }

    QDBusPendingReply<int> nextReply;

    if ( !textData.isEmpty() )
        nextReply = iface->writePassword( handle, q->service(), key, textData, q->service() );
    else if ( !binaryData.isEmpty() )
        nextReply = iface->writeEntry( handle, q->service(), key, binaryData, q->service() );
    else
        nextReply = iface->removeEntry( handle, q->service(), key, q->service() );

    QDBusPendingCallWatcher* nextWatcher = new QDBusPendingCallWatcher( nextReply, this );
    connect( nextWatcher, SIGNAL(finished(QDBusPendingCallWatcher*)), this, SLOT(kwalletWriteFinished(QDBusPendingCallWatcher*)) );
}
Exemple #29
0
void FdInhibition::slotDBusError(const QDBusError& error)
{
    qDebug() << error.message();
}
Exemple #30
0
void ReadPasswordJobPrivate::kwalletOpenFinished( QDBusPendingCallWatcher* watcher ) {
    watcher->deleteLater();
    const QDBusPendingReply<int> reply = *watcher;

    std::auto_ptr<QSettings> local( !q->settings() ? new QSettings( q->service() ) : 0 );
    QSettings* actual = q->settings() ? q->settings() : local.get();
    WritePasswordJobPrivate::Mode mode;

    const QString typeKey = QString( "%1/type" ).arg( key );
    const QString dataKey = QString( "%1/data" ).arg( key );
    if ( reply.isError() ) {
        const QDBusError err = reply.error();

        if ( q->insecureFallback() && actual->contains( dataKey ) ) {

            mode = (WritePasswordJobPrivate::Mode)actual->value( typeKey ).toInt();
            data = actual->value( dataKey ).toByteArray();

            q->emitFinished();

            return;
        } else {
            if ( err.type() == QDBusError::ServiceUnknown ) //KWalletd not running
                q->emitFinishedWithError( NoBackendAvailable, tr("No keychain service available") );
            else
                q->emitFinishedWithError( OtherError, tr("Could not open wallet: %1; %2").arg( QDBusError::errorString( err.type() ), err.message() ) );

            return;
        }
    }

    if ( actual->contains( dataKey ) ) {
        // We previously stored data in the insecure QSettings, but now have KWallet available.
        // Do the migration

        data = actual->value( dataKey ).toByteArray();
        mode = (WritePasswordJobPrivate::Mode)actual->value( typeKey ).toInt();
        actual->remove( key );

        q->emitFinished();


        WritePasswordJob* j = new WritePasswordJob( q->service(), 0 );
        j->setSettings( q->settings() );
        j->setKey( key );
        j->setAutoDelete( true );
        if ( mode == WritePasswordJobPrivate::Binary )
            j->setBinaryData( data );
        else if ( mode == WritePasswordJobPrivate::Text )
            j->setTextData( QString::fromUtf8( data ) );
        else
            Q_ASSERT( false );

        j->start();

        return;
    }

    walletHandle = reply.value();

    if ( walletHandle < 0 ) {
        q->emitFinishedWithError( AccessDenied, tr("Access to keychain denied") );
        return;
    }

    const QDBusPendingReply<int> nextReply = iface->entryType( walletHandle, q->service(), key, q->service() );
    QDBusPendingCallWatcher* nextWatcher = new QDBusPendingCallWatcher( nextReply, this );
    connect( nextWatcher, SIGNAL(finished(QDBusPendingCallWatcher*)), this, SLOT(kwalletEntryTypeFinished(QDBusPendingCallWatcher*)) );
}