@@ -203,6 +203,26 @@ void UDisks2::Monitor::unmount(const QString &devicePath)
203
203
startMountOperation (devicePath, UDISKS2_FILESYSTEM_UNMOUNT, m_blockDevices->objectPath (devicePath), arguments);
204
204
}
205
205
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
+
206
226
void UDisks2::Monitor::format (const QString &devicePath, const QString &filesystemType, const QVariantMap &arguments)
207
227
{
208
228
if (devicePath.isEmpty ()) {
@@ -651,6 +671,48 @@ void UDisks2::Monitor::doFormat(const QString &devicePath, const QString &dbusOb
651
671
});
652
672
}
653
673
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->isValid () && watcher->isFinished ()) {
693
+ emit status (devicePath, Partition::Unmounted);
694
+ } else if (watcher->isError ()) {
695
+ QDBusError error = watcher->error ();
696
+ QByteArray errorData = error.name ().toLocal8Bit ();
697
+ const char *errorCStr = errorData.constData ();
698
+ qCWarning (lcMemoryCardLog) << dbusMethod << " error:" << errorCStr;
699
+
700
+ for (uint i = 0 ; i < sizeof (dbus_error_entries) / sizeof (ErrorEntry); i++) {
701
+ if (strcmp (dbus_error_entries[i].dbusErrorName , errorCStr) == 0 ) {
702
+ emit setLabelError (dbus_error_entries[i].errorCode );
703
+ break ;
704
+ }
705
+ }
706
+
707
+ emit status (devicePath, Partition::Unmounted);
708
+ }
709
+
710
+ watcher->deleteLater ();
711
+ });
712
+
713
+ emit status (devicePath, Partition::Renaming);
714
+ }
715
+
654
716
void UDisks2::Monitor::getBlockDevices ()
655
717
{
656
718
QDBusInterface managerInterface (UDISKS2_SERVICE,
0 commit comments