@@ -203,6 +203,64 @@ 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 objectPath = m_blockDevices->objectPath (devicePath);
214
+ PartitionManagerPrivate::Partitions affectedPartitions;
215
+ lookupPartitions (affectedPartitions, QStringList () << objectPath);
216
+
217
+ for (auto partition : affectedPartitions) {
218
+ // partition is already unmounted
219
+ if (partition->status == Partition::Unmounted) {
220
+ QVariantList arguments;
221
+ arguments << label;
222
+ QVariantMap options;
223
+ arguments << options;
224
+ doSetLabel (devicePath, m_blockDevices->objectPath (devicePath), arguments, false );
225
+ return ;
226
+ }
227
+ }
228
+
229
+ const QString dbusMethod = UDISKS2_FILESYSTEM_UNMOUNT;
230
+
231
+ QDBusMessage method = QDBusMessage::createMethodCall (
232
+ UDISKS2_SERVICE,
233
+ m_blockDevices->objectPath (devicePath),
234
+ UDISKS2_FILESYSTEM_INTERFACE,
235
+ dbusMethod);
236
+ method.setArguments (args);
237
+ QDBusPendingCall pendingCall = QDBusConnection::systemBus ().asyncCall (method);
238
+ QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher (pendingCall, this );
239
+ connect (watcher, &QDBusPendingCallWatcher::finished,
240
+ this , [this , devicePath, dbusMethod, label](QDBusPendingCallWatcher *watcher) {
241
+ if (watcher->isValid () && watcher->isFinished ()) {
242
+ QVariantList arguments;
243
+ arguments << label;
244
+ QVariantMap options;
245
+ arguments << options;
246
+
247
+ doSetLabel (devicePath, m_blockDevices->objectPath (devicePath), arguments);
248
+ } else if (watcher->isError ()) {
249
+ QDBusError error = watcher->error ();
250
+ QByteArray errorData = error.name ().toLocal8Bit ();
251
+ const char *errorCStr = errorData.constData ();
252
+
253
+ qCWarning (lcMemoryCardLog) << " Unmount error:" << errorCStr << dbusMethod;
254
+ }
255
+ watcher->deleteLater ();
256
+ });
257
+
258
+ }
259
+ else {
260
+ qCWarning (lcMemoryCardLog) << " Block device" << devicePath << " not found" ;
261
+ }
262
+ }
263
+
206
264
void UDisks2::Monitor::format (const QString &devicePath, const QString &filesystemType, const QVariantMap &arguments)
207
265
{
208
266
if (devicePath.isEmpty ()) {
@@ -651,6 +709,47 @@ void UDisks2::Monitor::doFormat(const QString &devicePath, const QString &dbusOb
651
709
});
652
710
}
653
711
712
+ void UDisks2::Monitor::doSetLabel (const QString &devicePath, const QString &dbusObjectPath, const QVariantList &arguments, bool needMount)
713
+ {
714
+ const QString dbusMethod = UDISKS2_BLOCK_SETLABEL;
715
+ if (devicePath.isEmpty ()) {
716
+ qCCritical (lcMemoryCardLog) << " Cannot" << dbusMethod.toLower () << " without device name" ;
717
+ return ;
718
+ }
719
+
720
+ QDBusMessage method = QDBusMessage::createMethodCall (
721
+ UDISKS2_SERVICE,
722
+ dbusObjectPath,
723
+ UDISKS2_FILESYSTEM_INTERFACE,
724
+ dbusMethod);
725
+ method.setArguments (arguments);
726
+ QDBusPendingCall pendingCall = QDBusConnection::systemBus ().asyncCall (method);
727
+ QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher (pendingCall, this );
728
+ connect (watcher, &QDBusPendingCallWatcher::finished,
729
+ this , [this , devicePath, dbusMethod, needMount](QDBusPendingCallWatcher *watcher) {
730
+ if (watcher->isValid () && watcher->isFinished ()) {
731
+ emit status (devicePath, Partition::Renamed);
732
+ if (needMount) {
733
+ mount (devicePath);
734
+ }
735
+ } else if (watcher->isError ()) {
736
+ QDBusError error = watcher->error ();
737
+ QByteArray errorData = error.name ().toLocal8Bit ();
738
+ const char *errorCStr = errorData.constData ();
739
+ qCWarning (lcMemoryCardLog) << dbusMethod << " error:" << errorCStr;
740
+
741
+ for (uint i = 0 ; i < sizeof (dbus_error_entries) / sizeof (ErrorEntry); i++) {
742
+ if (strcmp (dbus_error_entries[i].dbusErrorName , errorCStr) == 0 ) {
743
+ emit setLabelError (dbus_error_entries[i].errorCode );
744
+ break ;
745
+ }
746
+ }
747
+ }
748
+
749
+ watcher->deleteLater ();
750
+ });
751
+ }
752
+
654
753
void UDisks2::Monitor::getBlockDevices ()
655
754
{
656
755
QDBusInterface managerInterface (UDISKS2_SERVICE,
0 commit comments