QList<QVariantMap> TrackListInterfaceTest::testGetTracksMetadata(const QList<QDBusObjectPath>& trackIds) { QDBusReply<QList<QVariantMap> > reply = iface->call("GetTracksMetadata"); if (!reply.isValid()) { emit interfaceError(Method, "GetTracksMetadata", "Call to GetTracksMetadata failed with error " + reply.error().message()); } else { QList<QVariantMap> metadataList = reply.value(); QMap<QDBusObjectPath,QVariantMap> metadataMap; int i = 0; Q_FOREACH (const QVariantMap& metadata, metadataList) { if (metadata.isEmpty()) { emit interfaceWarning(Method, "GetTracksMetadata", "Got an empty entry at position " + QString::number(i)); } else if (!metadata.contains("mpris:trackid")) { emit interfaceError(Method, "GetTracksMetadata", "No mpris:trackid entry at position " + QString::number(i)); } else if (metadata.value("mpris:trackid").userType() != qMetaTypeId<QDBusObjectPath>()) { emit interfaceError(Method, "GetTracksMetadata", "mpris:trackid entry was not sent as a D-Bus object path (D-Bus type 'o') at position " + QString::number(i)); } else { QDBusObjectPath trackid = metadata.value("mpris:trackid").value<QDBusObjectPath>(); if (trackid.path().isEmpty()) { emit interfaceError(Method, "GetTracksMetadata", "mpris:trackid entry is an empty path at position " + QString::number(i)); } else if (!trackIds.contains(trackid)) { emit interfaceWarning(Method, "GetTracksMetadata", "Entry " + trackid.path() + " was not requested at position " + QString::number(i)); } else { metadataMap.put(trackid, metadata); } } ++i; } } }
void QLlcpSocketPrivate::initializeRequestor() { if (m_socketRequestor) return; if (m_requestorPath.isEmpty()) { m_requestorPath = QLatin1String(requestorBasePath) + QString::number(requestorId.fetchAndAddOrdered(1)); } Manager manager(QLatin1String("com.nokia.nfc"), QLatin1String("/"), m_connection); QDBusObjectPath defaultAdapterPath = manager.DefaultAdapter(); if (!m_socketRequestor) { m_socketRequestor = new SocketRequestor(defaultAdapterPath.path(), this); connect(m_socketRequestor, SIGNAL(accessFailed(QDBusObjectPath,QString,QString)), this, SLOT(AccessFailed(QDBusObjectPath,QString,QString))); connect(m_socketRequestor, SIGNAL(accessGranted(QDBusObjectPath,QString)), this, SLOT(AccessGranted(QDBusObjectPath,QString))); connect(m_socketRequestor, SIGNAL(accept(QDBusVariant,QDBusVariant,int,QVariantMap)), this, SLOT(Accept(QDBusVariant,QDBusVariant,int,QVariantMap))); connect(m_socketRequestor, SIGNAL(connect(QDBusVariant,QDBusVariant,int,QVariantMap)), this, SLOT(Connect(QDBusVariant,QDBusVariant,int,QVariantMap))); connect(m_socketRequestor, SIGNAL(socket(QDBusVariant,int,QVariantMap)), this, SLOT(Socket(QDBusVariant,int,QVariantMap))); }
/*! Finds a user by \a userName. Sync blocking API. \param userName The user name to look up. \return the corresponding UserAccount object. */ UserAccount *AccountsManager::findUserByName(const QString &userName) { Q_D(AccountsManager); QDBusPendingReply<QDBusObjectPath> reply = d->interface->FindUserByName(userName); reply.waitForFinished(); if (reply.isError()) { QDBusError error = reply.error(); qWarning("Couldn't find user by user name %s: %s", userName.toUtf8().constData(), error.errorString(error.type()).toUtf8().constData()); return 0; } QDBusObjectPath path = reply.argumentAt<0>(); if (path.path().isEmpty()) return Q_NULLPTR; UserAccount *account = d->usersCache.value(path.path(), Q_NULLPTR); if (!account) { account = new UserAccount(path.path(), d->interface->connection()); d->usersCache[path.path()] = account; } return account; }
/*! Caches a user account, so that it shows up in listCachedUsers() output. The user name may be a remote user, but the system must be able to lookup the user name and resolve the user information. A userCached() signal with a UserAccount pointer will be emitted as soon as the user account has been cached by AccountsService. \param userName The user name for the user. */ void AccountsManager::cacheUser(const QString &userName) { Q_D(AccountsManager); QDBusPendingCall call = d->interface->CacheUser(userName); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, this); connect(watcher, &QDBusPendingCallWatcher::finished, this, [=](QDBusPendingCallWatcher *w) { QDBusPendingReply<QDBusObjectPath> reply = *w; w->deleteLater(); if (reply.isError()) { QDBusError error = reply.error(); qWarning("Couldn't cache user %s: %s", userName.toUtf8().constData(), error.errorString(error.type()).toUtf8().constData()); } else { QDBusObjectPath path = reply.argumentAt<0>(); if (path.path().isEmpty()) return; UserAccount *account = d->usersCache.value(path.path(), Q_NULLPTR); if (!account) { account = new UserAccount(path.path(), d->interface->connection()); d->usersCache[path.path()] = account; } Q_EMIT userCached(account); } }); }
void MainWindow::deviceRemoved(QDBusMessage message) { int index; QString devicePath; #ifdef USEHAL devicePath = message.arguments().at(0).toString(); if (devicePath.startsWith("/org/freedesktop/Hal/devices/storage_serial")) #else QDBusObjectPath path = message.arguments().at(0).value<QDBusObjectPath>(); devicePath = path.path(); if (devicePath.startsWith("/org/freedesktop/UDisks/devices/")) #endif { QLinkedList<DeviceItem *> list = pPlatform->getDeviceList(); QLinkedList<DeviceItem *>::iterator i; for (i = list.begin(); i != list.end(); ++i) { if ((*i)->getUDI() == devicePath) { if (removeMenuItem((*i)->getDisplayString()) != -1) { pPlatform->removeDeviceFromList(devicePath); break; } } } } }
void QBluetoothTransferReplyBluez::sessionStarted(QDBusPendingCallWatcher *watcher) { QDBusPendingReply<QDBusObjectPath, QVariantMap> reply = *watcher; if (reply.isError()) { qCWarning(QT_BT_BLUEZ) << "Failed to start obex session:" << reply.error().name() << reply.reply().errorMessage(); m_errorStr = QBluetoothTransferReply::tr("Push session cannot be started"); m_error = QBluetoothTransferReply::SessionError; m_finished = true; m_running = false; cleanupSession(); emit QBluetoothTransferReply::error(m_error); emit finished(this); watcher->deleteLater(); return; } const QDBusObjectPath path = reply.argumentAt<0>(); const QVariantMap map = reply.argumentAt<1>(); m_transfer_path = path.path(); //watch the transfer OrgFreedesktopDBusPropertiesInterface *properties = new OrgFreedesktopDBusPropertiesInterface( QStringLiteral("org.bluez.obex"), path.path(), QDBusConnection::sessionBus(), this); connect(properties, SIGNAL(PropertiesChanged(QString,QVariantMap,QStringList)), SLOT(sessionChanged(QString,QVariantMap,QStringList))); watcher->deleteLater(); }
void MediaPlayer2Player::SetPosition( const QDBusObjectPath& TrackId, qlonglong position ) const { QDBusObjectPath activeTrackId = activeMprisTrackId(); if( TrackId == activeTrackId ) The::engineController()->seek( position / 1000 ); else debug() << "SetPosition() called with a trackId (" << TrackId.path() << ") which is not for the active track (" << activeTrackId.path() << ")"; }
void Mpris2DBusHandler::SetPosition( const QDBusObjectPath &trackId, qlonglong position ) { QDBusObjectPath activeTrackId = activeMprisTrackId(); if( trackId == activeTrackId ) The::engineController()->seek( position / 1000 ); else warning() << "SetPosition() called with a trackId (" << trackId.path() << ") which is not for the active track (" << activeTrackId.path() << ")"; }
CreationResult *AccountsWorker::createAccountInternal(const User *user) { CreationResult *result = new CreationResult; // validate username QDBusPendingReply<bool, QString, int> reply = m_accountsInter->IsUsernameValid(user->name()); reply.waitForFinished(); if (reply.isError()) { result->setType(CreationResult::UserNameError); result->setMessage(reply.error().message()); return result; } bool validation = reply.argumentAt(0).toBool(); if (!validation) { result->setType(CreationResult::UserNameError); result->setMessage(dgettext("dde-daemon", reply.argumentAt(1).toString().toUtf8().data())); return result; } // validate password if (user->password() != user->repeatPassword()) { result->setType(CreationResult::PasswordMatchError); result->setMessage(tr("Password not match")); return result; } // default FullName is empty string QDBusObjectPath path = m_accountsInter->CreateUser(user->name(), QString(), 1); const QString userPath = path.path(); if (userPath.isEmpty() || userPath.isNull()) { result->setType(CreationResult::UnknownError); result->setMessage("no method call result on CreateUser"); return result; } AccountsUser *userDBus = new AccountsUser("com.deepin.daemon.Accounts", userPath, QDBusConnection::systemBus(), this); if (!userDBus->isValid()) { result->setType(CreationResult::UnknownError); result->setMessage("user dbus is still not valid."); return result; } //TODO(hualet): better to check all the call results. bool sifResult = !userDBus->SetIconFile(user->currentAvatar()).isError(); bool spResult = !userDBus->SetPassword(cryptUserPassword(user->password())).isError(); if (!sifResult || !spResult) { result->setType(CreationResult::UnknownError); if (!sifResult) result->setMessage("set icon file for new created user failed."); if (!spResult) result->setMessage("set password for new created user failed"); return result; } return result; }
void QtBluezDiscoveryManager::InterfacesRemoved(const QDBusObjectPath &object_path, const QStringList &interfaces) { if (!d->references.contains(object_path.path()) || !interfaces.contains(QStringLiteral("org.bluez.Adapter1"))) return; removeAdapterFromMonitoring(object_path.path()); }
void AccountsManagerPrivate::_q_userDeleted(const QDBusObjectPath &path) { Q_Q(AccountsManager); UserAccount *account = usersCache.value(path.path(), Q_NULLPTR); usersCache.remove(path.path()); Q_EMIT q->userDeleted(account->userId()); account->deleteLater(); }
void NeardHelper::interfacesRemoved(const QDBusObjectPath &path, const QStringList &list) { if (list.contains(QStringLiteral("org.neard.Record"))) { qCDebug(QT_NFC_NEARD) << "record removed" << path.path(); emit recordRemoved(path); } else if (list.contains(QStringLiteral("org.neard.Tag"))) { qCDebug(QT_NFC_NEARD) << "tag removed" << path.path(); emit tagRemoved(path); } }
UDiskMountDevice::UDiskMountDevice(const QDBusObjectPath &path): RazorMountDevice(), mUdiskPath(path.path()) { mDbus = new QDBusInterface("org.freedesktop.UDisks", path.path(), "org.freedesktop.UDisks.Device", QDBusConnection::systemBus(), this); update(); }
void SoundApplet::defaultSinkChanged() { delete m_defSinkInter; const QDBusObjectPath defSinkPath = m_audioInter->GetDefaultSink(); m_defSinkInter = new DBusSink(defSinkPath.path(), this); connect(m_defSinkInter, &DBusSink::VolumeChanged, this, &SoundApplet::onVolumeChanged); connect(m_defSinkInter, &DBusSink::MuteChanged, this, &SoundApplet::onVolumeChanged); emit defaultSinkChanged(m_defSinkInter); }
void AccountsManagerPrivate::_q_userAdded(const QDBusObjectPath &path) { Q_Q(AccountsManager); if (usersCache.contains(path.path())) { Q_EMIT q->userAdded(usersCache[path.path()]); return; } UserAccount *account = new UserAccount(path.path(), interface->connection()); usersCache[path.path()] = account; Q_EMIT q->userAdded(account); }
static inline OrgBluezDeviceInterface *getDevice(const QBluetoothAddress &address, QBluetoothLocalDevicePrivate *d_ptr){ QDBusPendingReply<QDBusObjectPath> reply = d_ptr->adapter->FindDevice(address.toString()); reply.waitForFinished(); if(reply.isError()){ qDebug() << Q_FUNC_INFO << "reply failed" << reply.error(); return 0; } QDBusObjectPath path = reply.value(); return new OrgBluezDeviceInterface(QLatin1String("org.bluez"), path.path(), QDBusConnection::systemBus()); }
/* * DBus UDisk RemoveDevice handler */ void MediaMonitorUnix::deviceRemoved( QDBusObjectPath o) { LOG(VB_MEDIA, LOG_INFO, LOC + "deviceRemoved " + o.path()); #if 0 // This fails because the DeviceFile has just been deleted QString dev = DeviceProperty(o, "DeviceFile"); if (!dev.isEmpty()) RemoveDevice(dev); #else QString dev = QFileInfo(o.path()).baseName(); dev.prepend("/dev/"); RemoveDevice(dev); #endif }
void MainItem::dropEvent(QDropEvent *event) { updateIcon(false); if (event->source()) return; if (event->mimeData()->formats().indexOf("RequestDock") != -1){ //from desktop or launcher QJsonObject dataObj = QJsonDocument::fromJson(event->mimeData()->data("RequestDock")).object(); if (!dataObj.isEmpty()){ QString appKey = dataObj.value("appKey").toString(); QString appName = dataObj.value("appName").toString(); if (appKey.isEmpty()) return; event->ignore(); ConfirmUninstallDialog *dialog = new ConfirmUninstallDialog; //TODO: need real icon name dialog->setIcon(getThemeIconPath(appKey)); QString message = tr("Are you sure to uninstall %1?").arg(appName); dialog->setMessage(message); connect(dialog, &ConfirmUninstallDialog::buttonClicked, [=](int key){ dialog->deleteLater(); if (key == 1){ qWarning() << "Uninstall application:" << appKey << appName; m_launcher->RequestUninstall(appKey, true); } }); dialog->exec(); } } else//File or Dirctory { QStringList files; foreach (QUrl fileUrl, event->mimeData()->urls()) files << fileUrl.path(); QDBusPendingReply<QString, QDBusObjectPath, QString> tmpReply = m_dfo->NewTrashJob(files, false, "", "", ""); QDBusObjectPath op = tmpReply.argumentAt(1).value<QDBusObjectPath>(); DBusTrashJob * dtj = new DBusTrashJob(op.path(), this); connect(dtj, &DBusTrashJob::Done, dtj, &DBusTrashJob::deleteLater); connect(dtj, &DBusTrashJob::Done, [=](){ updateIcon(false); }); if (dtj->isValid()) dtj->Execute(); qWarning()<< op.path() << "Move files to trash: "<< files; } }
void AgentAdaptor::RequestBrowser(const QDBusObjectPath &service_path, const QString &url) { if (lastBrowserRequestService != service_path.path()) browserRequestTimer.invalidate(); if (!browserRequestTimer.isValid()) { lastBrowserRequestService = service_path.path(); browserRequestTimer.start(); m_userAgent->requestBrowser(service_path.path(), url); } if (browserRequestTimer.hasExpired(5 * 60 * 1000)) { browserRequestTimer.invalidate(); } }
void UPower::probeDevices() { if (!m_interface) return; QDBusArgument argument = m_interface->call( "EnumerateDevices" ).arguments().at(0).value<QDBusArgument>(); if( m_interface->lastError().type() == QDBusError::NoError ) { argument.beginArray(); while( !argument.atEnd() ) { QDBusObjectPath dbusPath; argument >> dbusPath; deviceAdded(dbusPath.path()); } }
static QScriptValue do_dbus_call(QScriptContext *context, QScriptEngine *engine) { int firstArgument = 0; QString functionName = context->callee().property(QLatin1String("functionName")).toString(); if (functionName.isEmpty()) { functionName = context->argument(0).toString(); ++firstArgument; } QScriptValue thisObject = context->thisObject(); QDBusAbstractInterface *iface = qobject_cast<QDBusAbstractInterface *>(thisObject.toQObject()); if (!iface) return QScriptValue(); QDBusMessage msg = QDBusMessage::createMethodCall(iface->service(), iface->path(), iface->interface(), functionName); QList<QVariant> args; for (int i = firstArgument; i < context->argumentCount(); ++i) { args.append(context->argument(i).toVariant()); } msg.setArguments(args); msg = iface->connection().call(msg); QScriptValue returnValue = engine->nullValue(); args = msg.arguments(); if (args.count() != 1) return returnValue; QVariant variant = args.first(); if (variant.type() == QVariant::UserType && variant.userType() == qMetaTypeId<QDBusObjectPath>()) { QDBusObjectPath path = qvariant_cast<QDBusObjectPath>(variant); QDBusInterface *returnedIface = new QDBusInterface(iface->service(), path.path(), /*interface*/QString(), iface->connection(), engine); returnValue = setupDBusInterface(engine, returnedIface); } else { returnValue = engine->newVariant(variant); } return returnValue; }
QModelIndex QDBusModel::findObject(const QDBusObjectPath &objectPath) { QStringList path = objectPath.path().split(QLatin1Char('/'), QString::SkipEmptyParts); QDBusItem *item = root; int childIdx = -1; while (item && !path.isEmpty()) { const QString branch = path.takeFirst() + QLatin1Char('/'); childIdx = -1; // do a linear search over all the children for (int i = 0; i < item->children.count(); ++i) { QDBusItem *child = item->children.at(i); if (child->type == PathItem && child->name == branch) { item = child; childIdx = i; // prefetch the found branch if (!item->isPrefetched) addPath(item); break; } } // branch not found - bail out if (childIdx == -1) return QModelIndex(); } // found the right item if (childIdx != -1 && item && path.isEmpty()) return createIndex(childIdx, 0, item); return QModelIndex(); }
QStringList QNetworkManagerInterfaceDeviceWired::availableConnections() { QStringList list; if (propertyMap.contains("AvailableConnections")) { const QDBusArgument &dbusArgs = propertyMap.value("Carrier").value<QDBusArgument>(); QDBusObjectPath path; dbusArgs.beginArray(); while (!dbusArgs.atEnd()) { dbusArgs >> path; list << path.path(); } dbusArgs.endArray(); } return list; }
bool Partition::isPartition(const QDBusObjectPath &path, int replyTimeout) { QXmlStreamReader xml(introspect(path.path(), replyTimeout)); bool hasBlockInterface = false; bool hasPartitionInterface = false; bool hasFileSystemInterface = false; while (!xml.atEnd()) { xml.readNext(); if (xml.isStartElement() && xml.name() == "interface") { QStringRef interface = xml.attributes().value("name"); if (!hasBlockInterface && interface == Interface::UDisks2("Block")) hasBlockInterface = true; else if (!hasPartitionInterface && interface == Interface::UDisks2( "Partition")) hasPartitionInterface = true; else if (!hasFileSystemInterface && interface == Interface::UDisks2( "Filesystem")) hasFileSystemInterface = true; if (hasBlockInterface && hasPartitionInterface && hasFileSystemInterface) return true; } } return false; }
const QString PBTreeNode::GetIntrospectXml(const QDBusObjectPath &object_path) { // Connect to the introspectable interface QDBusInterface iface(PBBusName, \ object_path.path(), \ ofDIntrospectableName, \ QDBusConnection::sessionBus()); // Lets see what we have - introspect this first QDBusMessage reply = iface.call("Introspect"); if (reply.type() != QDBusMessage::ReplyMessage) { qDebug("Could not introspect this object"); return NULL; } QList<QVariant> args = reply.arguments(); QList<QVariant>::iterator iter = args.begin(); QVariant variant = *iter; // The introspected string describing this object const QString intro_xml = variant.value<QString>(); return intro_xml; }
void QNmDBusHelper::slotAccessPointRemoved(QDBusObjectPath path) { if(path.path().length() > 2) { QDBusMessage msg = this->message(); emit pathForAccessPointRemoved(msg.path(), path); } }
QVariantMap PlatformUdisks2::getBlockDeviceProperties(const QString &blockDevice) { QVariantMap properties; QDBusInterface remoteApp("org.freedesktop.UDisks2", blockDevice, "org.freedesktop.UDisks2.Block", QDBusConnection::systemBus()); QDBusObjectPath objectPath = qvariant_cast<QDBusObjectPath>(remoteApp.property("Drive")); QString path = objectPath.path(); properties.insert("drivePath", path); properties.insert("path", QString(remoteApp.property("Device").toByteArray())); properties.insert("size", remoteApp.property("Size")); return properties; }
QString DeviceKitLister::FindUniqueIdByPath(const QDBusObjectPath &path) const { foreach (const DeviceData& data, device_data_) { if (data.dbus_path == path.path()) return data.unique_id(); } return QString(); }
QStringList QNetworkManagerConnectionActive::devices() const { QStringList list; if (propertyMap.contains("Devices")) { const QDBusArgument &dbusArgs = propertyMap.value("Devices").value<QDBusArgument>(); QDBusObjectPath path; dbusArgs.beginArray(); while (!dbusArgs.atEnd()) { dbusArgs >> path; list.append(path.path()); } dbusArgs.endArray(); } return list; }
void Udisks2Lister::RemoveDevice(const QDBusObjectPath& device_path) { QWriteLocker locker(&device_data_lock_); QString id; for (const auto& data : device_data_) { if (data.dbus_path == device_path.path()) { id = data.unique_id(); break; } } if (id.isEmpty()) return; qLog(Debug) << "UDisks2 device removed: " << device_path.path(); device_data_.remove(id); DeviceRemoved(id); }