Skip to content

Try to stop or eject drive before ejecting volume from side-pane #1049

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/mountoperation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,24 @@ void MountOperation::onEjectVolumeFinished(GVolume* volume, GAsyncResult* res, Q
delete pThis;
}

void MountOperation::onStopDriveFinished(GDrive* drive, GAsyncResult* res, QPointer<MountOperation>* pThis) {
if(*pThis) {
GError* error = nullptr;
g_drive_stop_finish(drive, res, &error);
(*pThis)->handleFinish(error);
}
delete pThis;
}

void MountOperation::onEjectDriveFinished(GDrive* drive, GAsyncResult* res, QPointer<MountOperation>* pThis) {
if(*pThis) {
GError* error = nullptr;
g_drive_eject_with_operation_finish(drive, res, &error);
(*pThis)->handleFinish(error);
}
delete pThis;
}

void MountOperation::onEjectFileFinished(GFile* file, GAsyncResult* res, QPointer<MountOperation>* pThis) {
if(*pThis) {
GError* error = nullptr;
Expand Down
17 changes: 17 additions & 0 deletions src/mountoperation.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,21 @@ class LIBFM_QT_API MountOperation: public QObject {
prepareUnmount(mnt);
g_object_unref(mnt);
}
// The current function is called when the volume can be ejected,
// but we first check if the drive can be stopped or ejected.
if(GDrive* drv = g_volume_get_drive(volume)) {
if(g_drive_can_stop(drv)) {
g_drive_stop(drv, G_MOUNT_UNMOUNT_NONE, op, cancellable_, (GAsyncReadyCallback)onStopDriveFinished, new QPointer<MountOperation>(this));
g_object_unref(drv);
return;
}
else if(g_drive_can_eject(drv)) {
g_drive_eject_with_operation(drv, G_MOUNT_UNMOUNT_NONE, op, cancellable_, (GAsyncReadyCallback)onEjectDriveFinished, new QPointer<MountOperation>(this));
g_object_unref(drv);
return;
}
g_object_unref(drv);
}
g_volume_eject_with_operation(volume, G_MOUNT_UNMOUNT_NONE, op, cancellable_, (GAsyncReadyCallback)onEjectVolumeFinished, new QPointer<MountOperation>(this));
}

Expand Down Expand Up @@ -163,6 +178,8 @@ class LIBFM_QT_API MountOperation: public QObject {
static void onEjectMountFinished(GMount* mount, GAsyncResult* res, QPointer<MountOperation>* pThis);
static void onEjectVolumeFinished(GVolume* volume, GAsyncResult* res, QPointer<MountOperation>* pThis);
static void onEjectFileFinished(GFile* file, GAsyncResult* res, QPointer<MountOperation>* pThis);
static void onStopDriveFinished(GDrive* drive, GAsyncResult* res, QPointer<MountOperation>* pThis);
static void onEjectDriveFinished(GDrive* drive, GAsyncResult* res, QPointer<MountOperation>* pThis);

void handleFinish(GError* error);

Expand Down