disconnect GVolumeMonitor signals from GioLister before destroying it
fixes #5369
This commit is contained in:
parent
e31278c056
commit
948140fab5
|
@ -21,7 +21,7 @@
|
|||
|
||||
#include "core/logging.h"
|
||||
|
||||
bool CheckedGConnect(gpointer source, const char* signal, GCallback callback,
|
||||
gulong CheckedGConnect(gpointer source, const char* signal, GCallback callback,
|
||||
gpointer data, const int callback_param_count) {
|
||||
guint signal_id = 0;
|
||||
GQuark detail = 0;
|
||||
|
@ -29,7 +29,7 @@ bool CheckedGConnect(gpointer source, const char* signal, GCallback callback,
|
|||
if (!g_signal_parse_name(signal, G_OBJECT_TYPE(source), &signal_id, &detail,
|
||||
false)) {
|
||||
qFatal("Connecting to invalid signal: %s", signal);
|
||||
return false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
GSignalQuery query;
|
||||
|
@ -39,9 +39,8 @@ bool CheckedGConnect(gpointer source, const char* signal, GCallback callback,
|
|||
int signal_params = query.n_params + 2;
|
||||
if (signal_params != callback_param_count) {
|
||||
qFatal("Connecting callback to signal with different parameters counts");
|
||||
return false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
g_signal_connect(source, signal, G_CALLBACK(callback), data);
|
||||
return true;
|
||||
return g_signal_connect(source, signal, G_CALLBACK(callback), data);
|
||||
}
|
||||
|
|
|
@ -25,14 +25,14 @@
|
|||
#include <boost/typeof/typeof.hpp>
|
||||
|
||||
// Do not call this directly, use CHECKED_GCONNECT instead.
|
||||
bool CheckedGConnect(gpointer source, const char* signal, GCallback callback,
|
||||
gpointer data, const int callback_param_count);
|
||||
gulong CheckedGConnect(gpointer source, const char* signal, GCallback callback,
|
||||
gpointer data, const int callback_param_count);
|
||||
|
||||
#define FUNCTION_ARITY(callback) \
|
||||
boost::function_types::function_arity<BOOST_TYPEOF(callback)>::value
|
||||
|
||||
#define CHECKED_GCONNECT(source, signal, callback, data) \
|
||||
CheckedGConnect(source, signal, G_CALLBACK(callback), data, \
|
||||
FUNCTION_ARITY(callback));
|
||||
FUNCTION_ARITY(callback))
|
||||
|
||||
#endif // CORE_SIGNALCHECKER_H_
|
||||
|
|
|
@ -94,11 +94,19 @@ void GioLister::Init() {
|
|||
g_list_free(mounts);
|
||||
|
||||
// Connect signals from the monitor
|
||||
CHECKED_GCONNECT(monitor_, "volume-added", &VolumeAddedCallback, this);
|
||||
CHECKED_GCONNECT(monitor_, "volume-removed", &VolumeRemovedCallback, this);
|
||||
CHECKED_GCONNECT(monitor_, "mount-added", &MountAddedCallback, this);
|
||||
CHECKED_GCONNECT(monitor_, "mount-changed", &MountChangedCallback, this);
|
||||
CHECKED_GCONNECT(monitor_, "mount-removed", &MountRemovedCallback, this);
|
||||
signals_.append(CHECKED_GCONNECT(monitor_, "volume-added", &VolumeAddedCallback, this));
|
||||
signals_.append(CHECKED_GCONNECT(monitor_, "volume-removed", &VolumeRemovedCallback, this));
|
||||
signals_.append(CHECKED_GCONNECT(monitor_, "mount-added", &MountAddedCallback, this));
|
||||
signals_.append(CHECKED_GCONNECT(monitor_, "mount-changed", &MountChangedCallback, this));
|
||||
signals_.append(CHECKED_GCONNECT(monitor_, "mount-removed", &MountRemovedCallback, this));
|
||||
}
|
||||
|
||||
GioLister::~GioLister()
|
||||
{
|
||||
foreach(gulong signal, signals_)
|
||||
{
|
||||
g_signal_handler_disconnect(monitor_, signal);
|
||||
}
|
||||
}
|
||||
|
||||
QStringList GioLister::DeviceUniqueIDs() {
|
||||
|
|
|
@ -36,6 +36,7 @@ class GioLister : public DeviceLister {
|
|||
|
||||
public:
|
||||
GioLister() {}
|
||||
~GioLister();
|
||||
|
||||
int priority() const { return 50; }
|
||||
|
||||
|
@ -137,6 +138,7 @@ class GioLister : public DeviceLister {
|
|||
|
||||
private:
|
||||
ScopedGObject<GVolumeMonitor> monitor_;
|
||||
QList<gulong> signals_;
|
||||
|
||||
QMutex mutex_;
|
||||
QMap<QString, DeviceInfo> devices_;
|
||||
|
|
Loading…
Reference in New Issue