@@ -203,6 +203,57 @@ 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, dbusMethod, 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
+ } else if (watcher->isError ()) {
233
+ QDBusError error = watcher->error ();
234
+ QByteArray errorData = error.name ().toLocal8Bit ();
235
+ const char *errorCStr = errorData.constData ();
236
+
237
+ qCWarning (lcMemoryCardLog) << " Unmount error:" << errorCStr << dbusMethod;
238
+
239
+ for (uint i = 0 ; i < sizeof (dbus_error_entries) / sizeof (ErrorEntry); i++) {
240
+ if (strcmp (dbus_error_entries[i].dbusErrorName , errorCStr) == 0 ) {
241
+ emit unmountError (dbus_error_entries[i].errorCode );
242
+ break ;
243
+ }
244
+ }
245
+
246
+ emit status (devicePath, Partition::Mounted);
247
+ }
248
+ watcher->deleteLater ();
249
+ });
250
+
251
+ }
252
+ else {
253
+ qCWarning (lcMemoryCardLog) << " Block device" << devicePath << " not found" ;
254
+ }
255
+ }
256
+
206
257
void UDisks2::Monitor::format (const QString &devicePath, const QString &filesystemType, const QVariantMap &arguments)
207
258
{
208
259
if (devicePath.isEmpty ()) {
@@ -651,6 +702,45 @@ void UDisks2::Monitor::doFormat(const QString &devicePath, const QString &dbusOb
651
702
});
652
703
}
653
704
705
+ void UDisks2::Monitor::doSetLabel (const QString &devicePath, const QString &dbusObjectPath, const QVariantList &arguments)
706
+ {
707
+ const QString dbusMethod = UDISKS2_BLOCK_SETLABEL;
708
+ if (devicePath.isEmpty ()) {
709
+ qCCritical (lcMemoryCardLog) << " Cannot" << dbusMethod.toLower () << " without device name" ;
710
+ return ;
711
+ }
712
+
713
+ QDBusMessage method = QDBusMessage::createMethodCall (
714
+ UDISKS2_SERVICE,
715
+ dbusObjectPath,
716
+ UDISKS2_FILESYSTEM_INTERFACE,
717
+ dbusMethod);
718
+ method.setArguments (arguments);
719
+ QDBusPendingCall pendingCall = QDBusConnection::systemBus ().asyncCall (method);
720
+ QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher (pendingCall, this );
721
+ connect (watcher, &QDBusPendingCallWatcher::finished,
722
+ this , [this , devicePath, dbusMethod](QDBusPendingCallWatcher *watcher) {
723
+ if (watcher->isValid () && watcher->isFinished ()) {
724
+ emit status (devicePath, Partition::Renamed);
725
+ mount (devicePath);
726
+ } else if (watcher->isError ()) {
727
+ QDBusError error = watcher->error ();
728
+ QByteArray errorData = error.name ().toLocal8Bit ();
729
+ const char *errorCStr = errorData.constData ();
730
+ qCWarning (lcMemoryCardLog) << dbusMethod << " error:" << errorCStr;
731
+
732
+ for (uint i = 0 ; i < sizeof (dbus_error_entries) / sizeof (ErrorEntry); i++) {
733
+ if (strcmp (dbus_error_entries[i].dbusErrorName , errorCStr) == 0 ) {
734
+ emit setLabelError (dbus_error_entries[i].errorCode );
735
+ break ;
736
+ }
737
+ }
738
+ }
739
+
740
+ watcher->deleteLater ();
741
+ });
742
+ }
743
+
654
744
void UDisks2::Monitor::getBlockDevices ()
655
745
{
656
746
QDBusInterface managerInterface (UDISKS2_SERVICE,
0 commit comments