fix: should disconnect when obj get destoryed

This commit is contained in:
Gary Wang 2019-11-27 19:07:55 +08:00
parent 4fb8986d11
commit 8e0557c8c2

View File

@ -26,8 +26,11 @@ using namespace Gio;
class DGioMountOperationPrivate class DGioMountOperationPrivate
{ {
public:
DGioMountOperationPrivate(DGioMountOperation *qq); DGioMountOperationPrivate(DGioMountOperation *qq);
~DGioMountOperationPrivate();
private:
Glib::RefPtr<MountOperation> getGmmMountOperationInstance() const; Glib::RefPtr<MountOperation> getGmmMountOperationInstance() const;
QString username() const; QString username() const;
@ -36,6 +39,8 @@ class DGioMountOperationPrivate
void slot_askQuestion(const Glib::ustring& message, const Glib::StringArrayHandle& choices); void slot_askQuestion(const Glib::ustring& message, const Glib::StringArrayHandle& choices);
void slot_showUnmountProgress(const Glib::ustring &message, gint64 time_left, gint64 bytes_left); void slot_showUnmountProgress(const Glib::ustring &message, gint64 time_left, gint64 bytes_left);
QList<sigc::connection> m_connections;
private: private:
Glib::RefPtr<MountOperation> m_gmmMountOperationPtr; Glib::RefPtr<MountOperation> m_gmmMountOperationPtr;
@ -49,9 +54,16 @@ DGioMountOperationPrivate::DGioMountOperationPrivate(DGioMountOperation *qq)
{ {
m_gmmMountOperationPtr = Gio::MountOperation::create(); m_gmmMountOperationPtr = Gio::MountOperation::create();
m_gmmMountOperationPtr->signal_ask_password().connect(sigc::mem_fun(*this, &DGioMountOperationPrivate::slot_askPassword)); m_connections.append(m_gmmMountOperationPtr->signal_ask_password().connect(sigc::mem_fun(*this, &DGioMountOperationPrivate::slot_askPassword)));
m_gmmMountOperationPtr->signal_ask_question().connect(sigc::mem_fun(*this, &DGioMountOperationPrivate::slot_askQuestion)); m_connections.append(m_gmmMountOperationPtr->signal_ask_question().connect(sigc::mem_fun(*this, &DGioMountOperationPrivate::slot_askQuestion)));
m_gmmMountOperationPtr->signal_show_unmount_progress().connect(sigc::mem_fun(*this, &DGioMountOperationPrivate::slot_showUnmountProgress)); m_connections.append(m_gmmMountOperationPtr->signal_show_unmount_progress().connect(sigc::mem_fun(*this, &DGioMountOperationPrivate::slot_showUnmountProgress)));
}
DGioMountOperationPrivate::~DGioMountOperationPrivate()
{
for (auto & c : m_connections) {
c.disconnect();
}
} }
Glib::RefPtr<MountOperation> DGioMountOperationPrivate::getGmmMountOperationInstance() const Glib::RefPtr<MountOperation> DGioMountOperationPrivate::getGmmMountOperationInstance() const