Fixed crash: OMG QDbusAdaptors can not be removed!
Added a fixme for future reference reloadPlugins() now recycles plugins already present Lots of debug messages and minor changes added trying to fix the bug
This commit is contained in:
parent
2a1996cbf7
commit
0f38eb34a4
9 changed files with 64 additions and 35 deletions
|
@ -68,36 +68,46 @@ bool Device::hasPlugin(const QString& name)
|
||||||
|
|
||||||
void Device::reloadPlugins()
|
void Device::reloadPlugins()
|
||||||
{
|
{
|
||||||
|
QMap< QString, KdeConnectPlugin* > newPluginMap;
|
||||||
|
|
||||||
|
if (paired()) { //Do not load any plugin for unpaired devices
|
||||||
|
|
||||||
|
QString path = KStandardDirs().resourceDirs("config").first()+"kdeconnect/";
|
||||||
|
QMap<QString,QString> pluginStates = KSharedConfig::openConfig(path + id())->group("Plugins").entryMap();
|
||||||
|
|
||||||
|
PluginLoader* loader = PluginLoader::instance();
|
||||||
|
|
||||||
|
//Code borrowed from KWin
|
||||||
|
foreach (const QString& pluginName, loader->getPluginList()) {
|
||||||
|
|
||||||
|
const QString value = pluginStates.value(pluginName + QString::fromLatin1("Enabled"), QString());
|
||||||
|
KPluginInfo info = loader->getPluginInfo(pluginName);
|
||||||
|
bool enabled = (value.isNull() ? info.isPluginEnabledByDefault() : QVariant(value).toBool());
|
||||||
|
|
||||||
|
if (enabled) {
|
||||||
|
|
||||||
|
if (m_plugins.contains(pluginName)) {
|
||||||
|
//Already loaded, reuse it
|
||||||
|
newPluginMap[pluginName] = m_plugins[pluginName];
|
||||||
|
m_plugins.remove(pluginName);
|
||||||
|
} else {
|
||||||
|
KdeConnectPlugin* plugin = loader->instantiatePluginForDevice(pluginName, this);
|
||||||
|
|
||||||
|
connect(this, SIGNAL(receivedPackage(const NetworkPackage&)),
|
||||||
|
plugin, SLOT(receivePackage(const NetworkPackage&)));
|
||||||
|
|
||||||
|
newPluginMap[pluginName] = plugin;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Erase all the plugins left in the original map (it means that we don't want
|
||||||
|
//them anymore, otherways they would have been moved to the newPluginMap)
|
||||||
qDeleteAll(m_plugins);
|
qDeleteAll(m_plugins);
|
||||||
m_plugins.clear();
|
m_plugins.clear();
|
||||||
|
|
||||||
QString path = KStandardDirs().resourceDirs("config").first()+"kdeconnect/";
|
m_plugins = newPluginMap;
|
||||||
QMap<QString,QString> pluginStates = KSharedConfig::openConfig(path + id())->group("Plugins").entryMap();
|
|
||||||
|
|
||||||
PluginLoader* loader = PluginLoader::instance();
|
|
||||||
|
|
||||||
//Code borrowed from KWin
|
|
||||||
foreach (const QString& pluginName, loader->getPluginList()) {
|
|
||||||
|
|
||||||
const QString value = pluginStates.value(pluginName + QString::fromLatin1("Enabled"), QString());
|
|
||||||
KPluginInfo info = loader->getPluginInfo(pluginName);
|
|
||||||
bool enabled = (value.isNull() ? info.isPluginEnabledByDefault() : QVariant(value).toBool());
|
|
||||||
|
|
||||||
qDebug() << pluginName << "enabled:" << enabled;
|
|
||||||
|
|
||||||
if (enabled) {
|
|
||||||
KdeConnectPlugin* plugin = loader->instantiatePluginForDevice(pluginName, this);
|
|
||||||
|
|
||||||
connect(this, SIGNAL(receivedPackage(const NetworkPackage&)),
|
|
||||||
plugin, SLOT(receivePackage(const NetworkPackage&)));
|
|
||||||
// connect(plugin, SIGNAL(sendPackage(const NetworkPackage&)),
|
|
||||||
// device, SLOT(sendPackage(const NetworkPackage&)));
|
|
||||||
|
|
||||||
|
|
||||||
m_plugins[pluginName] = plugin;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_EMIT pluginsChanged();
|
Q_EMIT pluginsChanged();
|
||||||
|
|
||||||
|
@ -106,7 +116,6 @@ void Device::reloadPlugins()
|
||||||
|
|
||||||
void Device::setPair(bool b)
|
void Device::setPair(bool b)
|
||||||
{
|
{
|
||||||
qDebug() << "setPair" << b;
|
|
||||||
m_paired = b;
|
m_paired = b;
|
||||||
KSharedConfigPtr config = KSharedConfig::openConfig("kdeconnectrc");
|
KSharedConfigPtr config = KSharedConfig::openConfig("kdeconnectrc");
|
||||||
if (b) {
|
if (b) {
|
||||||
|
@ -116,6 +125,7 @@ void Device::setPair(bool b)
|
||||||
qDebug() << name() << "unpaired";
|
qDebug() << name() << "unpaired";
|
||||||
config->group("devices").group("paired").deleteGroup(id());
|
config->group("devices").group("paired").deleteGroup(id());
|
||||||
}
|
}
|
||||||
|
reloadPlugins();
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool lessThan(DeviceLink* p1, DeviceLink* p2)
|
static bool lessThan(DeviceLink* p1, DeviceLink* p2)
|
||||||
|
|
|
@ -25,7 +25,11 @@
|
||||||
BatteryDbusInterface::BatteryDbusInterface(QObject *parent)
|
BatteryDbusInterface::BatteryDbusInterface(QObject *parent)
|
||||||
: QDBusAbstractAdaptor(parent)
|
: QDBusAbstractAdaptor(parent)
|
||||||
{
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
BatteryDbusInterface::~BatteryDbusInterface()
|
||||||
|
{
|
||||||
|
qDebug() << "Destroying BatteryDbusInterface";
|
||||||
}
|
}
|
||||||
|
|
||||||
void BatteryDbusInterface::updateValues(bool isCharging, int currentCharge)
|
void BatteryDbusInterface::updateValues(bool isCharging, int currentCharge)
|
||||||
|
|
|
@ -33,7 +33,8 @@ class BatteryDbusInterface
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit BatteryDbusInterface(QObject *parent);
|
explicit BatteryDbusInterface(QObject *parent);
|
||||||
|
virtual ~BatteryDbusInterface();
|
||||||
|
|
||||||
int charge() { return mCharge; }
|
int charge() { return mCharge; }
|
||||||
bool isCharging() { return mIsCharging; }
|
bool isCharging() { return mIsCharging; }
|
||||||
|
|
||||||
|
|
|
@ -32,8 +32,9 @@ K_EXPORT_PLUGIN( KdeConnectPluginFactory("kdeconnect_battery", "kdeconnect_batte
|
||||||
BatteryPlugin::BatteryPlugin(QObject *parent, const QVariantList &args)
|
BatteryPlugin::BatteryPlugin(QObject *parent, const QVariantList &args)
|
||||||
: KdeConnectPlugin(parent, args)
|
: KdeConnectPlugin(parent, args)
|
||||||
{
|
{
|
||||||
batteryDbusInterface = new BatteryDbusInterface(parent);
|
|
||||||
|
|
||||||
|
batteryDbusInterface = new BatteryDbusInterface(parent);
|
||||||
|
|
||||||
NetworkPackage np(PACKAGE_TYPE_BATTERY);
|
NetworkPackage np(PACKAGE_TYPE_BATTERY);
|
||||||
np.set("request",true);
|
np.set("request",true);
|
||||||
device()->sendPackage(np);
|
device()->sendPackage(np);
|
||||||
|
@ -42,7 +43,14 @@ BatteryPlugin::BatteryPlugin(QObject *parent, const QVariantList &args)
|
||||||
|
|
||||||
BatteryPlugin::~BatteryPlugin()
|
BatteryPlugin::~BatteryPlugin()
|
||||||
{
|
{
|
||||||
batteryDbusInterface->deleteLater();
|
//FIXME: Qt dbus does not allow to remove an adaptor! (it causes a crash in
|
||||||
|
// the next access to device via dbus). The implication of not deleting this
|
||||||
|
// is that disabling the plugin does not remove the interface (that will
|
||||||
|
// return outdated values) and that enabling it again instantiates a second
|
||||||
|
// adaptor. This is a partial memory leak (the memory will be freed when the
|
||||||
|
// device is destroyed anyway)
|
||||||
|
|
||||||
|
//batteryDbusInterface->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BatteryPlugin::receivePackage(const NetworkPackage& np)
|
bool BatteryPlugin::receivePackage(const NetworkPackage& np)
|
||||||
|
|
|
@ -12,4 +12,4 @@ X-KDE-PluginInfo-License=GPL
|
||||||
X-KDE-PluginInfo-EnabledByDefault=true
|
X-KDE-PluginInfo-EnabledByDefault=true
|
||||||
Icon=preferences-desktop-notification
|
Icon=preferences-desktop-notification
|
||||||
Name=Notification sync
|
Name=Notification sync
|
||||||
Comment=Show every notification in KDE and keep them in sync
|
Comment=Show phone notifications in KDE and keep them in sync
|
||||||
|
|
|
@ -11,5 +11,5 @@ X-KDE-PluginInfo-Website=http://albertvaka.wordpress.com
|
||||||
X-KDE-PluginInfo-License=GPL
|
X-KDE-PluginInfo-License=GPL
|
||||||
X-KDE-PluginInfo-EnabledByDefault=true
|
X-KDE-PluginInfo-EnabledByDefault=true
|
||||||
Icon=speaker
|
Icon=speaker
|
||||||
Name=Pause music on call
|
Name=Pause media during calls
|
||||||
Comment=Pause music during a phone call
|
Comment=Pause music/videos during a phone call
|
||||||
|
|
|
@ -33,6 +33,11 @@ PingPlugin::PingPlugin(QObject* parent, const QVariantList& args)
|
||||||
qDebug() << "Ping plugin constructor for device" << device()->name();
|
qDebug() << "Ping plugin constructor for device" << device()->name();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PingPlugin::~PingPlugin()
|
||||||
|
{
|
||||||
|
qDebug() << "Ping plugin destructor for device" << device()->name();
|
||||||
|
}
|
||||||
|
|
||||||
bool PingPlugin::receivePackage(const NetworkPackage& np)
|
bool PingPlugin::receivePackage(const NetworkPackage& np)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,8 @@ class KDE_EXPORT PingPlugin
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit PingPlugin(QObject *parent, const QVariantList &args);
|
explicit PingPlugin(QObject *parent, const QVariantList &args);
|
||||||
|
virtual ~PingPlugin();
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
virtual bool receivePackage(const NetworkPackage& np);
|
virtual bool receivePackage(const NetworkPackage& np);
|
||||||
|
|
||||||
|
|
|
@ -12,4 +12,4 @@ X-KDE-PluginInfo-License=GPL
|
||||||
X-KDE-PluginInfo-EnabledByDefault=true
|
X-KDE-PluginInfo-EnabledByDefault=true
|
||||||
Icon=call-start
|
Icon=call-start
|
||||||
Name=Telephony integration
|
Name=Telephony integration
|
||||||
Comment=Currently it only shows notifications for calls and SMS
|
Comment=Show notifications for calls and SMS (answering coming soon)
|
||||||
|
|
Loading…
Reference in a new issue