/*! 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; }
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; } } }
/*! 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 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 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 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 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(); }
/* * 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 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); }
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(); } }
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(); }
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(); }
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 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))); }
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); }
void devicemodel::removeDevice(QDBusObjectPath objectPath) { QList<device*>::iterator anIterator; for ( anIterator = m_devicesList.begin(); anIterator != m_devicesList.end(); anIterator++ ) { if ( (*anIterator)->path() == objectPath.path() ) { int index =anIterator - m_devicesList.begin(); device* devicetoRemove= (*anIterator); beginRemoveRows(QModelIndex(), index ,index ); m_devicesList.erase(anIterator); emit modelChanged(); endRemoveRows(); delete devicetoRemove; break; } } }
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 PBTreeNode::GetObjectProperties(const QDBusObjectPath &object_path, \ const QString interface) { QVariantMap properties; // Connect to the freedesktop Properties interface QDBusInterface iface(PBBusName, \ object_path.path(), \ ofDPropertiesName, \ QDBusConnection::sessionBus()); // GetAll properties QDBusMessage reply = iface.call("GetAll",interface); if (reply.type() != QDBusMessage::ReplyMessage) { // not worth complaining if they dont have properties, just return the empty return properties; } QList<QVariant> args = reply.arguments(); if (args.empty()) { return properties; } QList<QVariant>::iterator p = args.begin(); QVariant variant = *p; const QDBusArgument qda = variant.value<QDBusArgument>(); qda >> properties; return properties; }
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 BluetoothDevice::unpair() { OrgBluezManagerInterface manager( "org.bluez", "/", QDBusConnection::systemBus()); QDBusObjectPath adapterpath = manager.DefaultAdapter(); if(adapterpath.path().isEmpty()) return; OrgBluezAdapterInterface adapter( "org.bluez", adapterpath.path(), QDBusConnection::systemBus()); adapter.RemoveDevice(QDBusObjectPath(m_device->path())); }
inline void QDBusMarshaller::append(const QDBusObjectPath &arg) { QByteArray data = arg.path().toUtf8(); if (!ba && data.isEmpty()) error(); const char *cdata = data.constData(); qIterAppend(&iterator, ba, DBUS_TYPE_OBJECT_PATH, &cdata); }
inline void QDBusMarshaller::append(const QDBusObjectPath &arg) { QByteArray data = arg.path().toUtf8(); if (!ba && data.isEmpty()) error(QLatin1String("Invalid object path passed in arguments")); const char *cdata = data.constData(); qIterAppend(&iterator, ba, DBUS_TYPE_OBJECT_PATH, &cdata); }
UDisksJob::UDisksJob(const QDBusObjectPath &objectPath, const QVariantMap &properties, UDisksObject *parent) : UDisksInterface(parent), d_ptr(new UDisksJobPrivate(objectPath.path())) { Q_D(UDisksJob); d->properties = properties; }
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() << ")"; }
void ManagerProxy::modemRemoved(const QDBusObjectPath &in0) { TRACE // TODO: Handle modem removals, currently active for sure, others, maybe... qWarning() << QString("Unhandled ModemRemoved event: \"%1\"") .arg(in0.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; }