@@ -203,6 +203,26 @@ void UDisks2::Monitor::unmount(const QString &devicePath)
203203 startMountOperation (devicePath, UDISKS2_FILESYSTEM_UNMOUNT, m_blockDevices->objectPath (devicePath), arguments);
204204}
205205
206+ void UDisks2::Monitor::setLabel (const QString &devicePath, const QString &label)
207+ {
208+ if (devicePath.isEmpty ()) {
209+ qCCritical (lcMemoryCardLog) << " Cannot set label without device name" ;
210+ return ;
211+ }
212+
213+ if (m_blockDevices->find (devicePath)) {
214+ QVariantList arguments;
215+ arguments << label;
216+ QVariantMap options;
217+ arguments << options;
218+
219+ doSetLabel (devicePath, m_blockDevices->objectPath (devicePath), arguments);
220+ }
221+ else {
222+ qCWarning (lcMemoryCardLog) << " Block device" << devicePath << " not found" ;
223+ }
224+ }
225+
206226void UDisks2::Monitor::format (const QString &devicePath, const QString &filesystemType, const QVariantMap &arguments)
207227{
208228 if (devicePath.isEmpty ()) {
@@ -651,6 +671,45 @@ void UDisks2::Monitor::doFormat(const QString &devicePath, const QString &dbusOb
651671 });
652672}
653673
674+ void UDisks2::Monitor::doSetLabel (const QString &devicePath, const QString &dbusObjectPath, const QVariantList &arguments)
675+ {
676+ const QString dbusMethod = UDISKS2_BLOCK_SETLABEL;
677+ if (devicePath.isEmpty ()) {
678+ qCCritical (lcMemoryCardLog) << " Cannot" << dbusMethod.toLower () << " without device name" ;
679+ return ;
680+ }
681+
682+ QDBusMessage method = QDBusMessage::createMethodCall (
683+ UDISKS2_SERVICE,
684+ dbusObjectPath,
685+ UDISKS2_FILESYSTEM_INTERFACE,
686+ dbusMethod);
687+ method.setArguments (arguments);
688+ QDBusPendingCall pendingCall = QDBusConnection::systemBus ().asyncCall (method);
689+ QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher (pendingCall, this );
690+ connect (watcher, &QDBusPendingCallWatcher::finished,
691+ this , [this , devicePath, dbusMethod](QDBusPendingCallWatcher *watcher) {
692+ if (watcher->isError ()) {
693+ QDBusError error = watcher->error ();
694+ QByteArray errorData = error.name ().toLocal8Bit ();
695+ const char *errorCStr = errorData.constData ();
696+ qCWarning (lcMemoryCardLog) << dbusMethod << " error:" << errorCStr;
697+
698+ for (uint i = 0 ; i < sizeof (dbus_error_entries) / sizeof (ErrorEntry); i++) {
699+ if (strcmp (dbus_error_entries[i].dbusErrorName , errorCStr) == 0 ) {
700+ emit setLabelError (dbus_error_entries[i].errorCode );
701+ break ;
702+ }
703+ }
704+ }
705+
706+ emit status (devicePath, Partition::Unmounted);
707+ watcher->deleteLater ();
708+ });
709+
710+ emit status (devicePath, Partition::Renaming);
711+ }
712+
654713void UDisks2::Monitor::getBlockDevices ()
655714{
656715 QDBusInterface managerInterface (UDISKS2_SERVICE,
0 commit comments