@@ -203,6 +203,42 @@ 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 (m_blockDevices->find (devicePath)) {
209
+ QVariantList args;
210
+ QVariantMap opts;
211
+ args << opts;
212
+
213
+ const QString dbusMethod = UDISKS2_FILESYSTEM_UNMOUNT;
214
+
215
+ QDBusMessage method = QDBusMessage::createMethodCall (
216
+ UDISKS2_SERVICE,
217
+ m_blockDevices->objectPath (devicePath),
218
+ UDISKS2_FILESYSTEM_INTERFACE,
219
+ dbusMethod);
220
+ method.setArguments (args);
221
+ QDBusPendingCall pendingCall = QDBusConnection::systemBus ().asyncCall (method);
222
+ QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher (pendingCall, this );
223
+ connect (watcher, &QDBusPendingCallWatcher::finished,
224
+ this , [this , devicePath, label](QDBusPendingCallWatcher *watcher) {
225
+ if (watcher->isValid () && watcher->isFinished ()) {
226
+ QVariantList arguments;
227
+ arguments << label;
228
+ QVariantMap options;
229
+ arguments << options;
230
+
231
+ doSetLabel (devicePath, m_blockDevices->objectPath (devicePath), arguments);
232
+ }
233
+ watcher->deleteLater ();
234
+ });
235
+
236
+ }
237
+ else {
238
+ qCWarning (lcMemoryCardLog) << " Block device" << devicePath << " not found" ;
239
+ }
240
+ }
241
+
206
242
void UDisks2::Monitor::format (const QString &devicePath, const QString &filesystemType, const QVariantMap &arguments)
207
243
{
208
244
if (devicePath.isEmpty ()) {
@@ -651,6 +687,44 @@ void UDisks2::Monitor::doFormat(const QString &devicePath, const QString &dbusOb
651
687
});
652
688
}
653
689
690
+ void UDisks2::Monitor::doSetLabel (const QString &devicePath, const QString &dbusObjectPath, const QVariantList &arguments)
691
+ {
692
+ const QString dbusMethod = UDISKS2_BLOCK_SETLABEL;
693
+ if (devicePath.isEmpty ()) {
694
+ qCCritical (lcMemoryCardLog) << " Cannot" << dbusMethod.toLower () << " without device name" ;
695
+ return ;
696
+ }
697
+
698
+ QDBusInterface udisks2Interface (UDISKS2_SERVICE,
699
+ dbusObjectPath,
700
+ UDISKS2_FILESYSTEM_INTERFACE,
701
+ QDBusConnection::systemBus ());
702
+
703
+ QDBusPendingCall pendingCall = udisks2Interface.asyncCallWithArgumentList (dbusMethod, arguments);
704
+ QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher (pendingCall, this );
705
+ connect (watcher, &QDBusPendingCallWatcher::finished,
706
+ this , [this , devicePath, dbusMethod](QDBusPendingCallWatcher *watcher) {
707
+ if (watcher->isValid () && watcher->isFinished ()) {
708
+ emit status (devicePath, Partition::Renamed);
709
+ mount (devicePath);
710
+ } else if (watcher->isError ()) {
711
+ QDBusError error = watcher->error ();
712
+ QByteArray errorData = error.name ().toLocal8Bit ();
713
+ const char *errorCStr = errorData.constData ();
714
+ qCWarning (lcMemoryCardLog) << dbusMethod << " error:" << errorCStr;
715
+
716
+ for (uint i = 0 ; i < sizeof (dbus_error_entries) / sizeof (ErrorEntry); i++) {
717
+ if (strcmp (dbus_error_entries[i].dbusErrorName , errorCStr) == 0 ) {
718
+ emit setLabelError (dbus_error_entries[i].errorCode );
719
+ break ;
720
+ }
721
+ }
722
+ }
723
+
724
+ watcher->deleteLater ();
725
+ });
726
+ }
727
+
654
728
void UDisks2::Monitor::getBlockDevices ()
655
729
{
656
730
QDBusInterface managerInterface (UDISKS2_SERVICE,
0 commit comments