void Camera::startCamera() { QDBusConnection bus = QDBusConnection::sessionBus(); bus.connect("com.nokia.maemo.CameraService", "/", "com.nokia.maemo.meegotouch.CameraInterface", "captureCanceled", this, SLOT(captureCanceled(QString))); bus.connect("com.nokia.maemo.CameraService", "/", "com.nokia.maemo.meegotouch.CameraInterface", "captureCompleted", this, SLOT(captureCompleted(QString,QString))); QDBusMessage message = QDBusMessage::createMethodCall( "com.nokia.maemo.CameraService", "/", "com.nokia.maemo.meegotouch.CameraInterface", "showCamera"); QList<QVariant> args; args << (uint)0 << "" << "still-capture" << true; message.setArguments(args); QDBusMessage reply = bus.call(message); if (reply.type() == QDBusMessage::ErrorMessage) { qDebug() << Q_FUNC_INFO << "reply.type == errormessage; name=" << reply.errorName() << "; message=" << reply.errorMessage(); bus.disconnect("com.nokia.maemo.CameraService", "/", "com.nokia.maemo.meegotouch.CameraInterface", "captureCanceled", this, SLOT(captureCanceled(QString))); bus.disconnect("com.nokia.maemo.CameraService", "/", "com.nokia.maemo.meegotouch.CameraInterface", "captureCompleted", this, SLOT(captureCompleted(QString,QString))); if (m_lastEcId) this->callback(m_lastEcId, ""); } }
void Mp3tunesAmarokClient::harmonyDownloadReady( const Mp3tunesHarmonyDownload &download ) { qDebug() << "Got message about ready: " << download.trackTitle() << " by " << download.artistName() << " on " << download. albumTitle(); QString name = "org.kde.amarok"; QDBusMessage m = QDBusMessage::createMethodCall( name, "/Mp3tunesHarmonyHandler", "", "emitDownloadReady" ); QList<QVariant> args; args.append( download.serialize() ); m.setArguments(args); QDBusMessage response = QDBusConnection::sessionBus().call( m ); if( response.type() == QDBusMessage::ErrorMessage ) { qDebug() << "Got ERROR response harmonyDownloadReady"; qDebug() << response.errorName() << ": " << response.errorMessage(); } }
void SeafileTrayIcon::showMessage(const QString &title, const QString &message, const QString &repo_id, const QString &commit_id, const QString &previous_commit_id, MessageIcon icon, int millisecondsTimeoutHint) { #ifdef Q_OS_MAC repo_id_ = repo_id; commit_id_ = commit_id; previous_commit_id_ = previous_commit_id; if (!utils::mac::isOSXMountainLionOrGreater()) { QIcon info_icon(":/images/info.png"); TrayNotificationWidget* trayNotification = new TrayNotificationWidget(info_icon.pixmap(32, 32), title, message); tnm->append(trayNotification); return; } QSystemTrayIcon::showMessage(title, message, icon, millisecondsTimeoutHint); #elif defined(Q_OS_LINUX) repo_id_ = repo_id; Q_UNUSED(icon); QVariantMap hints; QString brand = getBrand(); hints["resident"] = QVariant(true); hints["desktop-entry"] = QVariant(brand); QList<QVariant> args = QList<QVariant>() << brand << quint32(0) << brand << title << message << QStringList () << hints << qint32(-1); QDBusMessage method = QDBusMessage::createMethodCall("org.freedesktop.Notifications","/org/freedesktop/Notifications", "org.freedesktop.Notifications", "Notify"); method.setArguments(args); QDBusConnection::sessionBus().asyncCall(method); #else TrayMessage msg; msg.title = title; msg.message = message; msg.icon = icon; msg.repo_id = repo_id; msg.commit_id = commit_id; msg.previous_commit_id = previous_commit_id; pending_messages_.enqueue(msg); #endif }
void PowerManagerNux::setState(uint dobusy, const QString &/* reason*/) { qDebug() << " [M/Nux] System/PowerManager: set new state"; if(m_busy == dobusy){ return; } m_intended_state = dobusy ? busy : idle; if (m_state == error || m_state == m_intended_state || m_state == request_busy || m_state == request_idle) return; QDBusMessage call; if (!m_use_gsm) call = QDBusMessage::createMethodCall( "org.freedesktop.PowerManager", "/org/freedesktop/PowerManager/Inhibit", "org.freedesktop.PowerManager.Inhibit", dobusy ? "Inhibit" : "UnInhibit"); else call = QDBusMessage::createMethodCall( "org.gnome.SessionManager", "/org/gnome/SessionManager", "org.gnome.SessionManager", dobusy ? "Inhibit" : "UnInhibit"); m_state = dobusy ? request_busy : request_idle; QList<QVariant> args; if(dobusy){ // XXX reason args << "Hello there"; if (m_use_gsm) args << (uint)0; args << "User is busy doing something"; if (m_use_gsm) args << (uint)8; }else{ args << m_cookie; } call.setArguments(args); QDBusPendingCall pcall = QDBusConnection::sessionBus().asyncCall(call, 1000); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pcall, this); connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), this, SLOT(OnAsyncReply(QDBusPendingCallWatcher*))); // XXX untested m_busy = dobusy; }
void FdoNotifyPlugin::notifyUser( const QString &messageText ) { QDBusMessage message = QDBusMessage::createMethodCall( "org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications", "Notify" ); QList<QVariant> arguments; arguments << QString( "Tomahawk" ); //app_name arguments << quint32( 0 ); //notification_id arguments << QString(); //app_icon arguments << QString( "Tomahawk" ); //summary arguments << messageText.replace("&", "&"); //body arguments << QStringList(); //actions QVariantMap dict; dict["desktop-entry"] = QString( "tomahawk" ); dict[ "image_data" ] = ImageConverter::variantForImage( QImage( RESPATH "icons/tomahawk-icon-128x128.png" ) ); arguments << dict; //hints arguments << qint32( -1 ); //expire_timeout message.setArguments( arguments ); QDBusConnection::sessionBus().send( message ); }
void KopeteRunner::run(const Plasma::RunnerContext& context, const Plasma::QueryMatch& match) { Q_UNUSED(context) // HACK: Strip off the "kopete_" prefix const QString id = match.data().toString(); QString method; QVariantList args; if (id == "connect") method = "connectAll"; else if (id == "disconnect") method = "disconnectAll"; else if (id == "status") { method = "setOnlineStatus"; QStringList status = match.text().split(": "); status.takeFirst(); QStringList message = match.subtext().split(": "); message.takeFirst(); args << status.join(": ") << message.join(": "); } else if (id == "message") { method = "setStatusMessage"; QStringList message = match.text().split(": "); message.takeFirst(); args << message.join(": "); } else if (!QUuid(id).isNull()) { method = "openChat"; args << id; } else qDebug("Unknown ID: %s", id.toUtf8().constData()); if (!method.isNull()) { QDBusMessage message = generateMethodCall(method); message.setArguments(args); QDBusConnection::sessionBus().send(message); } }
int PlatformUdisks2::open(DeviceItem* item) { int ret = -1; QDBusConnection connection = QDBusConnection::systemBus(); QList<QVariant> args; QVariantMap map; args << map; QString udi = QString("/org/freedesktop/UDisks2/block_devices/%1").arg(item->getUDI()); QDBusMessage message = QDBusMessage::createMethodCall("org.freedesktop.UDisks2", udi, "org.freedesktop.UDisks2.Block", "OpenForRestore"); message.setArguments(args); QDBusMessage reply = connection.call(message); if (reply.type() == QDBusMessage::ErrorMessage) { QMessageBox msgBox; msgBox.setText(QString("DBUS error (%1): %2").arg(item->getUDI()).arg(reply.errorMessage())); msgBox.exec(); ret = -1; } else if (reply.arguments().empty() || reply.arguments()[0].userType() != qMetaTypeId<QDBusUnixFileDescriptor>()) { QMessageBox msgBox; msgBox.setText(QString("got empty or invalid reply!?")); msgBox.exec(); errno = EINVAL; } else { QDBusUnixFileDescriptor fd(qvariant_cast<QDBusUnixFileDescriptor>(reply.arguments()[0])); if (fd.isValid()) { ret = ::dup(fd.fileDescriptor()); } } qDebug() << "ret" << ret; return ret; }
long long PlatformUdisks::getSize(const QString &devicePath) { long long ret; QDBusConnection connection = QDBusConnection::systemBus(); QDBusMessage message; QList<QVariant> args; args << "org.freedesktop.UDisks"; args << "DeviceSize"; message = QDBusMessage::createMethodCall("org.freedesktop.UDisks", devicePath, "org.freedesktop.DBus.Properties", "Get"); message.setArguments(args); QDBusReply<QDBusVariant> reply = connection.call(message); if (!reply.isValid()) return(0); ret = reply.value().variant().toLongLong(); return(ret); }
void Mp3tunesAmarokClient::dbusEmitMessage( const QString &message, const QString ¶m = QString() ) { QString name = "org.kde.amarok"; QDBusMessage m = QDBusMessage::createMethodCall( name, "/Mp3tunesHarmonyHandler", "", message ); if( !param.isEmpty() ) { QList<QVariant> args; args.append( param ); m.setArguments(args); } QDBusMessage response = QDBusConnection::sessionBus().call( m ); if( response.type() == QDBusMessage::ErrorMessage ) { qDebug() << "Got ERROR response " << message; qDebug() << response.errorName() << ": " << response.errorMessage(); } }
bool PlatformUdisks::getIsDrive(const QString &path) { bool ret; QDBusConnection connection = QDBusConnection::systemBus(); QDBusMessage message; QList<QVariant> args; args << "org.freedesktop.UDisks"; args << "DeviceIsDrive"; message = QDBusMessage::createMethodCall("org.freedesktop.UDisks", path, "org.freedesktop.DBus.Properties", "Get"); message.setArguments(args); QDBusReply<QDBusVariant> reply = connection.call(message); if (!reply.isValid()) return(false); ret = reply.value().variant().toBool(); return(ret); }
/*! Places a call to the remote method specified by \a method on this interface, using \a args as arguments. This function returns immediately after queueing the call. The reply from the remote function is delivered to the \a returnMethod on object \a receiver. If an error occurs, the \a errorMethod on object \a receiver is called instead. This function returns true if the queueing succeeds. It does not indicate that the executed call succeeded. If it fails, the \a errorMethod is called. The \a returnMethod must have as its parameters the types returned by the function call. Optionally, it may have a QDBusMessage parameter as its last or only parameter. The \a errorMethod must have a QDBusError as its only parameter. \since 4.3 \sa QDBusError, QDBusMessage */ bool QDBusAbstractInterface::callWithCallback(const QString &method, const QList<QVariant> &args, QObject *receiver, const char *returnMethod, const char *errorMethod) { Q_D(QDBusAbstractInterface); QDBusMessage msg = QDBusMessage::createMethodCall(service(), path(), interface(), method); msg.setArguments(args); d->lastError = 0; return d->connection.callWithCallback(msg, receiver, returnMethod, errorMethod); }
int main() { QDBusMessage myDBusMessage; //! [0] QList<QVariant> arguments; arguments << QVariant(42) << QVariant::fromValue(QDBusVariant(43)) << QVariant("hello"); myDBusMessage.setArguments(arguments); //! [0] //! [1] // call a D-Bus function that returns a D-Bus variant QVariant v = callMyDBusFunction(); // retrieve the D-Bus variant QDBusVariant dbusVariant = qvariant_cast<QDBusVariant>(v); // retrieve the actual value stored in the D-Bus variant QVariant result = dbusVariant.variant(); //! [1] return 0; }
bool PlatformUdisks::isUSB(const QString &udiskPath) { QDBusConnection connection = QDBusConnection::systemBus(); QDBusMessage message; QList<QVariant> args; args << "org.freedesktop.UDisks"; args << "DriveConnectionInterface"; message = QDBusMessage::createMethodCall("org.freedesktop.UDisks", udiskPath, "org.freedesktop.DBus.Properties", "Get"); message.setArguments(args); QDBusReply<QDBusVariant> reply = connection.call(message); if (!reply.isValid()) return false; if (reply.value().variant().toString() == "usb") return true; else return false; }
KIO::DropJob* DragAndDropHelper::dropUrls(const QUrl& destUrl, QDropEvent* event, QWidget* window) { const QMimeData* mimeData = event->mimeData(); if (mimeData->hasFormat("application/x-kde-ark-dndextract-service") && mimeData->hasFormat("application/x-kde-ark-dndextract-path")) { const QString remoteDBusClient = mimeData->data("application/x-kde-ark-dndextract-service"); const QString remoteDBusPath = mimeData->data("application/x-kde-ark-dndextract-path"); QDBusMessage message = QDBusMessage::createMethodCall(remoteDBusClient, remoteDBusPath, "org.kde.ark.DndExtract", "extractSelectedFilesTo"); message.setArguments({destUrl.toDisplayString(QUrl::PreferLocalFile)}); QDBusConnection::sessionBus().call(message); } else { // Drop into a directory or a desktop-file KIO::DropJob *job = KIO::drop(event, destUrl); KJobWidgets::setWindow(job, window); return job; } return 0; }
void FdoNotifyPlugin::pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant pushData ) { Q_UNUSED( caller ); qDebug() << Q_FUNC_INFO; if ( type != Tomahawk::InfoSystem::InfoNotifyUser || !pushData.canConvert< QVariantMap >() ) { qDebug() << Q_FUNC_INFO << " not the right type or could not convert the hash"; return; } QVariantMap hash = pushData.value< QVariantMap >(); if ( !hash.contains( "message" ) ) { qDebug() << Q_FUNC_INFO << " hash did not contain a message"; return; } QDBusMessage message = QDBusMessage::createMethodCall( "org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications", "Notify" ); QList<QVariant> arguments; arguments << QString( "Tomahawk" ); //app_name arguments << quint32( 0 ); //notification_id arguments << QString(); //app_icon arguments << QString( "Tomahawk" ); //summary arguments << hash["message"].toString(); //body arguments << QStringList(); //actions QVariantMap dict; dict["desktop-entry"] = QString( "tomahawk" ); if ( hash.contains( "image" ) ) { QVariant tempVariant = hash["image"]; QImage tempImage = tempVariant.value< QImage >(); dict["image_data"] = ImageConverter::variantForImage( tempImage ); } else dict["image_data"] = ImageConverter::variantForImage( QImage( RESPATH "icons/tomahawk-icon-128x128.png" ) ); arguments << dict; //hints arguments << qint32( -1 ); //expire_timeout message.setArguments( arguments ); QDBusConnection::sessionBus().send( message ); }
bool PlatformUdisks2::doUnmount(const QString &partitionPath) { bool ret = true; QDBusConnection connection = QDBusConnection::systemBus(); QList<QVariant> args; QVariantMap map; args << map; QDBusMessage message = QDBusMessage::createMethodCall("org.freedesktop.UDisks2", partitionPath, "org.freedesktop.UDisks2.Filesystem", "Unmount"); message.setArguments(args); QDBusMessage reply = connection.call(message); if (reply.type() == QDBusMessage::ErrorMessage) { QMessageBox msgBox; msgBox.setText(QString("DBUS error (%1): %2").arg(partitionPath).arg(reply.errorMessage())); msgBox.exec(); ret = false; } return(ret); }
/** ***************************************************************************/ bool MPRIS::Command::isApplicable(Player &p) const { // Check the applicable-option if given if (!applicableCheck_) return true; // split DBus interface and property into seperate strings int splitAt = property_.lastIndexOf('.'); QString ifaceName = property_.left(splitAt); QString propertyName = property_.right(property_.length() - splitAt -1); // Compose Get-Property-Message QDBusMessage mesg = QDBusMessage::createMethodCall( p.getBusId(), //"org.mpris.MediaPlayer2.rhythmbox", path_, //"/org/mpris/MediaPlayer2", "org.freedesktop.DBus.Properties", "Get"); QList<QVariant> args; // Specify DBus interface to get the property from and the property-name args.append(ifaceName); //"org.mpris.MediaPlayer2.Player"); args.append(propertyName); //"CanGoNext"); mesg.setArguments(args); // Query the property QDBusMessage reply = QDBusConnection::sessionBus().call(mesg); // Check if the result is as expected if ( reply.type() != QDBusMessage::ReplyMessage ){ qWarning() << "Error while querying the property 'PlaybackStatus'"; return true; } if ( reply.arguments().empty() ) { qWarning() << "Reply query 'PlaybackStatus' is empty"; return true; } return (reply.arguments().at(0).value<QDBusVariant>().variant() == expectedValue_) == positivity_; }
void TohoSettings::writeScreenCapture() { QDBusMessage m = QDBusMessage::createMethodCall("com.kimmoli.toholed", "/", "com.kimmoli.toholed", "setSettings" ); QVariantMap map; map.insert("ssp", m_ssp); map.insert("sspPath", QStandardPaths::writableLocation(QStandardPaths::PicturesLocation)); QList<QVariant> args; args.append(map); m.setArguments(args); if (QDBusConnection::systemBus().send(m)) qDebug() << "success" << args; else qDebug() << "failed" << QDBusConnection::systemBus().lastError().message(); }
void Sms::sendSMS(QString number, QString message) { /* dbus-send --system --print-reply --dest= org.ofono /ril_0 org.ofono.MessageManager.SendMessage string:"+358500000000" string:"test sms" */ QDBusMessage m = QDBusMessage::createMethodCall("org.ofono", "/ril_0", "org.ofono.MessageManager", "SendMessage" ); QList<QVariant> args; args.append(number); args.append(message); m.setArguments(args); if (QDBusConnection::systemBus().send(m)) qDebug() << "success"; else qDebug() << "fail" << QDBusConnection::systemBus().lastError().message(); }
Authorization::Code DBusCodeAuthProvider::generateCode(Session *session, const QString &identifier) { Authorization::Code code = DefaultProvider::generateCode(session, identifier); QDBusMessage message = QDBusMessage::createMethodCall(QStringLiteral("org.freedesktop.Notifications"), QStringLiteral("/org/freedesktop/Notifications"), QStringLiteral("org.freedesktop.Notifications"), QStringLiteral("Notify")); message.setArguments({ QCoreApplication::applicationName(), QVariant::fromValue(0u), QString(), QStringLiteral("New auth code request"), QStringLiteral("Auth code for account %1 is %2. Peer IP: %3").arg(identifier, code.code, session->ip), QStringList(), QVariantMap(), 3000 }); // QString app_name, uint replaces_id, QString app_icon, QString summary, // QString body, QStringList actions, QVariantMap hints, int timeout QDBusConnection::sessionBus().send(message); return code; }
uint AsemanLinuxNativeNotification::sendNotify(const QString &title, const QString &body, const QString &icon, uint replace_id, int timeOut, const QStringList &actions) { QVariantList args; args << QCoreApplication::applicationName(); args << replace_id; args << icon; args << title; args << body; args << QVariant::fromValue<QStringList>(actions) ; args << QVariant::fromValue<QVariantMap>(QVariantMap()); args << timeOut; QDBusMessage omsg = QDBusMessage::createMethodCall( DBUS_SERVICE , DBUS_PATH , DBUS_OBJECT , DBUS_NOTIFY ); omsg.setArguments( args ); const QDBusMessage & imsg = p->connection->call( omsg , QDBus::BlockWithGui ); const QVariantList & res = imsg.arguments(); if( res.isEmpty() ) return 0; uint id_res = res.first().toUInt(); p->notifies.insert( id_res ); return id_res; }
void SeafileTrayIcon::showMessage(const QString & title, const QString & message, MessageIcon icon, int millisecondsTimeoutHint, bool is_repo_message) { if (!is_repo_message) repo_id_ = QString(); #ifdef Q_OS_MAC Q_UNUSED(icon); Q_UNUSED(millisecondsTimeoutHint); QIcon info_icon(":/images/info.png"); TrayNotificationWidget* trayNotification = new TrayNotificationWidget(info_icon.pixmap(32, 32), title, message); tnm->append(trayNotification); #elif defined(Q_OS_LINUX) Q_UNUSED(icon); QVariantMap hints; hints["resident"] = QVariant(true); hints["desktop-entry"] = QVariant("seafile"); QList<QVariant> args = QList<QVariant>() << "seafile" << quint32(0) << "seafile" << title << message << QStringList () << hints << qint32(-1); QDBusMessage method = QDBusMessage::createMethodCall("org.freedesktop.Notifications","/org/freedesktop/Notifications", "org.freedesktop.Notifications", "Notify"); method.setArguments(args); QDBusConnection::sessionBus().asyncCall(method); #else QSystemTrayIcon::showMessage(title, message, icon, millisecondsTimeoutHint); #endif }
void TohoSettings::writeSettings(QString key, bool value) { /**/ qDebug() << "write settings" << key << value; QDBusMessage m = QDBusMessage::createMethodCall("com.kimmoli.toholed", "/", "com.kimmoli.toholed", "setSettings" ); QVariantMap map; map.insert(key, value); QList<QVariant> args; args.append(map); m.setArguments(args); if (QDBusConnection::systemBus().send(m)) qDebug() << "success" << map; else qDebug() << "failed" << QDBusConnection::systemBus().lastError().message(); }
void PulseAudioControl::openConnection() { //! If the connection already exists, do nothing if ((dbusConnection != NULL) && (dbus_connection_get_is_connected(dbusConnection))) { return; } // Establish a connection to the server char *pa_bus_address = getenv("PULSE_DBUS_SERVER"); QByteArray addressArray; if (pa_bus_address == NULL) { QDBusMessage message = QDBusMessage::createMethodCall("org.pulseaudio.Server", "/org/pulseaudio/server_lookup1", "org.freedesktop.DBus.Properties", "Get"); message.setArguments(QVariantList() << "org.PulseAudio.ServerLookup1" << "Address"); QDBusMessage reply = QDBusConnection::sessionBus().call(message); if (reply.type() == QDBusMessage::ReplyMessage && reply.arguments().count() > 0) { addressArray = reply.arguments().first().value<QDBusVariant>().variant().toString().toAscii(); pa_bus_address = addressArray.data(); } } if (pa_bus_address != NULL) { DBusError dbus_err; dbus_error_init(&dbus_err); dbusConnection = dbus_connection_open(pa_bus_address, &dbus_err); DBUS_ERR_CHECK(dbus_err); } if (dbusConnection != NULL) { dbus_connection_setup_with_g_main(dbusConnection, NULL); dbus_connection_add_filter(dbusConnection, PulseAudioControl::stepsUpdatedSignalHandler, (void *)this, NULL); addSignalMatch(); } }
/// Returns the name of the current implementor of an interface. If an error /// occurs (e.g., we cannot connect to the Meego service mapper), returns an /// empty string. QString ServiceResolver::implementorName(const QString& interface) { if (resolved.contains(interface)) return resolved[interface]; // A blocking call QDBusMessage message = QDBusMessage::createMethodCall(MAPPER_SERVICENAME, MAPPER_PATH, MAPPER_INTERFACE, "serviceName"); message.setArguments(QVariantList() << interface); QDBusMessage reply = QDBusConnection::sessionBus().call(message); if (reply.type() != QDBusMessage::ReplyMessage || reply.arguments().size() == 0) { LCA_WARNING << "invalid reply from service mapper" << reply.errorName(); return ""; } QString service = reply.arguments()[0].toString(); if (service.size() == 0) { // don't insert to the "resolved" map return ""; } resolved.insert(interface, service); return service; }
/*! Places a call to the remote method specified by \a method on this interface, using \a args as arguments. This function returns immediately after queueing the call. The reply from the remote function is delivered to the \a returnMethod on object \a receiver. If an error occurs, the \a errorMethod on object \a receiver is called instead. This function returns true if the queueing succeeds. It does not indicate that the executed call succeeded. If it fails, the \a errorMethod is called. If the queueing failed, this function returns false and no slot will be called. The \a returnMethod must have as its parameters the types returned by the function call. Optionally, it may have a QDBusMessage parameter as its last or only parameter. The \a errorMethod must have a QDBusError as its only parameter. \since 4.3 \sa QDBusError, QDBusMessage */ bool QDBusAbstractInterface::callWithCallback(const QString &method, const QList<QVariant> &args, QObject *receiver, const char *returnMethod, const char *errorMethod) { Q_D(QDBusAbstractInterface); if (!d->isValid || !d->canMakeCalls()) return false; QDBusMessage msg = QDBusMessage::createMethodCall(service(), path(), interface(), method); QDBusMessagePrivate::setParametersValidated(msg, true); msg.setArguments(args); d->lastError = 0; return d->connection.callWithCallback(msg, receiver, returnMethod, errorMethod); }
void PowerManagementInhibitor::RequestBusy() { m_intended_state = busy; if (m_state == error || m_state == busy || m_state == request_busy || m_state == request_idle) return; qDebug("D-Bus: PowerManagementInhibitor: Requesting busy"); QDBusMessage call; if (!m_use_gsm) call = QDBusMessage::createMethodCall( "org.freedesktop.PowerManagement", "/org/freedesktop/PowerManagement/Inhibit", "org.freedesktop.PowerManagement.Inhibit", "Inhibit"); else call = QDBusMessage::createMethodCall( "org.gnome.SessionManager", "/org/gnome/SessionManager", "org.gnome.SessionManager", "Inhibit"); m_state = request_busy; QList<QVariant> args; args << "qMule"; if (m_use_gsm) args << (uint)0; args << "Active torrents are presented"; if (m_use_gsm) args << (uint)8; call.setArguments(args); QDBusPendingCall pcall = QDBusConnection::sessionBus().asyncCall(call, 1000); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pcall, this); connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), this, SLOT(OnAsyncReply(QDBusPendingCallWatcher*))); }
void FdoNotifyPlugin::nowPlaying( const QVariant& input ) { tDebug( LOGVERBOSE ) << Q_FUNC_INFO; if ( !input.canConvert< QVariantMap >() ) return; QVariantMap map = input.toMap(); if ( !map.contains( "trackinfo" ) || !map[ "trackinfo" ].canConvert< Tomahawk::InfoSystem::InfoStringHash >() ) return; InfoStringHash hash = map[ "trackinfo" ].value< Tomahawk::InfoSystem::InfoStringHash >(); if ( !hash.contains( "title" ) || !hash.contains( "artist" ) || !hash.contains( "album" ) ) return; QString messageText; // If the window manager supports notification styling then use it. if ( m_wmSupportsBodyMarkup ) { // Remark: If using xml-based markup in notifications, the supplied strings need to be escaped. QString album; if ( !hash[ "album" ].isEmpty() ) album = tr( "<br /><i>on</i> %1", "%1 is an album name" ).arg( Qt::escape( hash[ "album" ] ) ); messageText = tr( "%1<br /><i>by</i> %2%3.", "%1 is a title, %2 is an artist and %3 is replaced by either the previous message or nothing" ) .arg( Qt::escape( hash[ "title" ] ) ) .arg( Qt::escape( hash[ "artist" ] ) ) .arg( album ); } else { QString album; if ( !hash[ "album" ].isEmpty() ) album = QString( " %1" ).arg( tr( "on \"%1\"", "%1 is an album name" ).arg( hash[ "album" ] ) ); messageText = tr( "\"%1\" by %2%3.", "%1 is a title, %2 is an artist and %3 is replaced by either the previous message or nothing" ) .arg( hash[ "title" ] ) .arg( hash[ "artist" ] ) .arg( album ); } tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "sending message" << messageText; QDBusMessage message = QDBusMessage::createMethodCall( "org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications", "Notify" ); QList<QVariant> arguments; arguments << QString( "Tomahawk" ); //app_name arguments << m_nowPlayingId; //notification_id arguments << QString(); //app_icon arguments << QString( "Tomahawk - Now Playing" ); //summary arguments << messageText; //body arguments << QStringList(); //actions QVariantMap dict; dict["desktop-entry"] = QString( "tomahawk" ); // If there is a cover availble use it, else use Tomahawk logo as default. QImage image; if ( map.contains( "coveruri" ) && map[ "coveruri" ].canConvert< QString >() ) image = QImage( map[ "coveruri" ].toString(), "PNG" ); else image = QImage( RESPATH "icons/tomahawk-icon-512x512.png" ); // Convert image to QVariant and scale to a consistent size. dict[ "image_data" ] = ImageConverter::variantForImage( image.scaledToHeight( getNotificationIconHeight() ) ); arguments << dict; //hints arguments << qint32( -1 ); //expire_timeout message.setArguments( arguments ); // Handle reply in a callback, so that this a non-blocking call QDBusConnection::sessionBus().callWithCallback( message, this, SLOT( dbusPlayingReplyReceived( QDBusMessage ) ) ); }
void MailManagerImpl::Register( const QDBusObjectPath ®istrarPath, uint lastModseq ) { Q_UNUSED( lastModseq ); registrars.append( registrarPath ); QDBusMessage m = QDBusMessage::createMethodCall( message().service(), registrarPath.path(), "org.freedesktop.email.metadata.Registrar", "Cleanup" ); QList<QVariant> args; args.append ( static_cast<uint> ( time( 0 ) ) ); m.setArguments( args ); QDBusConnection::sessionBus().send( m ); QList< QPointer< KMFolder > > folders = kmkernel->allFolders(); QList< QPointer< KMFolder > >::Iterator it = folders.begin(); while ( it != folders.end() ) { uint i = 0; KMFolder *folder = (*it); ++it; folder->open("DBus"); uint fcount = folder->count(); while ( i < fcount ) { QVector<QStringList> predicatesArray; QVector<QStringList> valuesArray; QStringList subjects; uint processed = 0; for ( ; i < fcount; ++i ) { const KMMsgBase *msg = folder->getMsgBase( i ); processMsgBase( msg, subjects, predicatesArray, valuesArray ); processed++; if ( processed >= max_per_dbus_call ) break; } if (!subjects.isEmpty()) { QDBusMessage m = QDBusMessage::createMethodCall( message().service(), registrarPath.path(), "org.freedesktop.email.metadata.Registrar", "SetMany" ); QList<QVariant> args; args.append( subjects ); args.append( qVariantFromValue( predicatesArray ) ); args.append( qVariantFromValue( valuesArray ) ); args.append( static_cast<uint> ( time( 0 ) ) ); m.setArguments( args ); QDBusConnection::sessionBus().send( m ); } } folder->close( "DBus", false ); } }
/////////////////////// Private Functions ////////////////////////////// // // Function to emit the org.freedesktop.Dbus.Properties.PropertiesChanged() // DBus signal. Called from the local inline setxxx functions void MediaPlayer2Player::sendPropertyChanged() { // changed properties if (changeditems.size() <= 0) return; // create a map of all changed items. Use for loop because it is possible // (but highly unlikely) that this slot could be called with more than // one property needing to be changed QMap<QString, QVariant> vmap; for (int i = 0; i < changeditems.size(); ++i) { switch (changeditems.at(i) ) { case MBMP_MPRIS::PlaybackStatus: vmap["PlaybackSatus"] = QVariant(playbackstatus); break; case MBMP_MPRIS::LoopStatus: vmap["LoopSatus"] = QVariant(loopstatus); break; case MBMP_MPRIS::PlaybackRate: vmap["Rate"] = QVariant(playbackrate); break; case MBMP_MPRIS::Shuffle: vmap["Shuffle"] = QVariant(shuffle); break; case MBMP_MPRIS::Metadata: vmap["Metadata"] = QVariant(metadata); break; case MBMP_MPRIS::Volume: vmap["Volume"] = QVariant(volume); break; case MBMP_MPRIS::MinRate: vmap["MinimumRate"] = QVariant(minimumrate); break; case MBMP_MPRIS::MaxRate: vmap["MaximumRate"] = QVariant(maximumrate); break; case MBMP_MPRIS::CanGoNext: vmap["CanGoNext"] = QVariant(cangonext); break; case MBMP_MPRIS::CanGoPrevious: vmap["CanGoPrevious"] = QVariant(cangoprevious); break; case MBMP_MPRIS::CanPlay: vmap["CanPlay"] = QVariant(canplay); break; case MBMP_MPRIS::CanPause: vmap["CanPause"] = QVariant(canpause); break; case MBMP_MPRIS::CanSeek: vmap["CanSeek"] = QVariant(canseek); break; default: break; } // switch } // for changeditems.clear(); // create the message. We never remove a property so we don't need // to deal with that - send an empty qstringlist QList<QVariant> vlist; vlist << QVariant(IPC_INTERFACE_MEDIAPLAYER2PLAYER) << vmap << QStringList(); QDBusMessage msg = QDBusMessage::createSignal(IPC_OBJECT, "org.freedesktop.Dbus.Properties", "PropertiesChanged"); msg.setArguments(vlist); QDBusConnection::sessionBus().send(msg); return; }