Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

globalkeyshortucts: fix segfault and other bugs in daemon

Segmentation fault happened if a deleted shortcut was triggered. Also
shortcuts were never unregistered and objects were never freed...
  • Loading branch information...
commit 697e6e494e8cbd9547e50e797153b778ee47a128 1 parent 50b9ffc
@amoskvin amoskvin authored
View
5 razorqt-globalkeyshortcuts/src/CMakeLists.txt
@@ -60,11 +60,6 @@ set(APP_SHARE_DIR ${RAZOR_SHARE_DIR}/${PROJECT})
#************************************************
-if (RUNNER_MATH)
- add_definitions(-DMATH_ENABLED)
-endif (RUNNER_MATH)
-
-
qt4_wrap_cpp(MOC_SOURCES ${MOC_FILES})
qt4_wrap_ui(UI_HEADERS ${UI_FILES})
qt4_add_resources(QRC_SOURCES ${QRC_FILES})
View
181 razorqt-globalkeyshortcuts/src/globalaccel.cpp
@@ -1,33 +1,43 @@
/* BEGIN_COMMON_COPYRIGHT_HEADER
- * (c)LGPL2+
- *
- * Razor - a lightweight, Qt based, desktop toolset
- * http://razor-qt.org
- *
- * Copyright: 2012 Razor team
- * Authors:
- *   Aaron Lewis <the.warl0ck.1989@gmail.com>
- *
- * This program or library is free software; you can redistribute it
- * and/or modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
-
- * You should have received a copy of the GNU Lesser General
- * Public License along with this library; if not, write to the
- * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301 USA
- *
- * END_COMMON_COPYRIGHT_HEADER */
+ * (c)LGPL2+
+ *
+ * Razor - a lightweight, Qt based, desktop toolset
+ * http://razor-qt.org
+ *
+ * Copyright: 2012 Razor team
+ * Authors:
+ * Aaron Lewis <the.warl0ck.1989@gmail.com>
+ *
+ * This program or library is free software; you can redistribute it
+ * and/or modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * END_COMMON_COPYRIGHT_HEADER */
+
+#include <QtDBus/QDBusConnection>
+#include <QtCore/QProcess>
+#include <QtCore/QDebug>
#include "globalaccel.h"
-CommandShortcut::CommandShortcut (const QString & cmd, QObject *parent):
- AbstractShortcut (parent),
+AbstractShortcut::AbstractShortcut(const QKeySequence& sequence, QObject* parent) :
+ mShortcut(sequence, this)
+{
+ connect(&mShortcut, SIGNAL(activated()), SLOT(exec()));
+}
+
+CommandShortcut::CommandShortcut(const QKeySequence& sequence, const QString& cmd, QObject* parent):
+ AbstractShortcut(sequence, parent),
m_cmd (cmd)
{
}
@@ -38,33 +48,22 @@ bool CommandShortcut::exec()
}
////
-DBusShortcut::DBusShortcut (const QString & dest,
+DBusShortcut::DBusShortcut( const QKeySequence& sequence,
+ const QString & dest,
const QString & path,
const QString & interface,
const QString & method,
const QList<QVariant> & parameters,
QObject *parent) :
- AbstractShortcut (parent),
- m_dest (dest),
- m_path (path),
- m_interface (interface),
- m_method (method),
- m_params (parameters)
-
+ AbstractShortcut(sequence, parent),
+ mMessage(QDBusMessage::createMethodCall(dest, path, interface, method))
{
+ mMessage.setArguments(parameters);
}
bool DBusShortcut::exec()
{
- QDBusMessage message = QDBusMessage::createMethodCall(
- m_dest,
- m_path,
- m_interface,
- m_method
- );
- message.setArguments (m_params);
-
- return QDBusConnection::sessionBus().send (message);
+ return QDBusConnection::sessionBus().send(mMessage);
}
////////////////////
@@ -74,7 +73,7 @@ GlobalAccel::GlobalAccel(QObject *parent):
m_shortcutSettings (new RazorSettings("globalkeyshortcuts", this))
{
// read settings
- bindDefault ();
+ rebindAll();
// monitor changes
connect(m_shortcutSettings , SIGNAL(settingsChanged()) , SLOT(rebindAll()));
@@ -82,73 +81,51 @@ GlobalAccel::GlobalAccel(QObject *parent):
GlobalAccel::~GlobalAccel()
{
-
+ qDeleteAll(mMapping);
+ delete m_shortcutSettings;
}
-void GlobalAccel::bindDefault()
+void GlobalAccel::rebindAll()
{
+ qDebug() << "Loading settings...";
// clear existing
- mapping.clear();
-
-#define GET_VALUE_BOOL(a) m_shortcutSettings->value(a).toBool()
-#define GET_VALUE_STRING(a) m_shortcutSettings->value(a).toString()
-#define GET_VALUE_LIST(a) m_shortcutSettings->value(a).toList()
+ qDeleteAll(mMapping);
+ mMapping.clear();
foreach(const QString & group , m_shortcutSettings->childGroups())
{
m_shortcutSettings->beginGroup(group);
- // shortcut is not enabled
- if ( ! GET_VALUE_BOOL("Enabled") )
- {
- continue;
- }
-
- const QString & type = GET_VALUE_STRING("Type");
- // if shortcut is dbus call
- if ( type.toLower() == "dbus" )
- {
- mapping.insert(QKeySequence(group), new DBusShortcut (
- GET_VALUE_STRING("Destination"),
- GET_VALUE_STRING("Path"),
- GET_VALUE_STRING("Interface"),
- GET_VALUE_STRING("Method"),
- GET_VALUE_LIST("Parameter")
- ));
-
- QxtGlobalShortcut *sc = new QxtGlobalShortcut(this);
- sc->setShortcut(QKeySequence (group));
- connect(sc , SIGNAL(activated()) , SLOT(launchApp()));
- }
- // otherwise it "should" be a command execution for now
- else
- {
- const QString & cmd = GET_VALUE_STRING("Exec");
- // command is not empty
- if ( ! cmd.isEmpty() )
- {
- mapping.insert(QKeySequence(group), new CommandShortcut (cmd));
-
- // create shortcut binding
- QxtGlobalShortcut *sc = new QxtGlobalShortcut(this);
- sc->setShortcut(QKeySequence (group));
- connect(sc , SIGNAL(activated()) , SLOT(launchApp()));
- }
- }
+ // shortcut is not enabled
+ if (!m_shortcutSettings->value("Enabled").toBool())
+ {
+ continue;
+ }
+
+ QKeySequence sequence(group);
+ const QString& type = m_shortcutSettings->value("Type").toString();
+ // if shortcut is dbus call
+ if (type.toLower() == "dbus")
+ {
+ mMapping.append(new DBusShortcut(sequence,
+ m_shortcutSettings->value("Destination").toString(),
+ m_shortcutSettings->value("Path").toString(),
+ m_shortcutSettings->value("Interface").toString(),
+ m_shortcutSettings->value("Method").toString(),
+ m_shortcutSettings->value("Parameter").toList()
+ ));
+ }
+ // otherwise it "should" be a command execution for now
+ else
+ {
+ const QString& cmd = m_shortcutSettings->value("Exec").toString();
+ // command is not empty
+ if (!cmd.isEmpty())
+ {
+ mMapping.append(new CommandShortcut(sequence, cmd));
+ }
+ }
m_shortcutSettings->endGroup();
}
-
-}
-
-void GlobalAccel::rebindAll()
-{
- qDebug() << "Reloading settings..";
- bindDefault();
-}
-
-void GlobalAccel::launchApp()
-{
- QxtGlobalShortcut *sc = qobject_cast<QxtGlobalShortcut *>(sender());
- mapping.value ( sc->shortcut() )->exec();
}
View
93 razorqt-globalkeyshortcuts/src/globalaccel.h
@@ -1,37 +1,32 @@
/* BEGIN_COMMON_COPYRIGHT_HEADER
- * (c)LGPL2+
- *
- * Razor - a lightweight, Qt based, desktop toolset
- * http://razor-qt.org
- *
- * Copyright: 2012 Razor team
- * Authors:
- *   Aaron Lewis <the.warl0ck.1989@gmail.com>
- *
- * This program or library is free software; you can redistribute it
- * and/or modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
-
- * You should have received a copy of the GNU Lesser General
- * Public License along with this library; if not, write to the
- * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301 USA
- *
- * END_COMMON_COPYRIGHT_HEADER */
-#include <QProcess>
-#include <QSettings>
-#include <QMap>
-#include <QKeySequence>
-#include <QObject>
-#include <QDebug>
-#include <QDBusMessage>
-#include <QDBusConnection>
+ * (c)LGPL2+
+ *
+ * Razor - a lightweight, Qt based, desktop toolset
+ * http://razor-qt.org
+ *
+ * Copyright: 2012 Razor team
+ * Authors:
+ * Aaron Lewis <the.warl0ck.1989@gmail.com>
+ *
+ * This program or library is free software; you can redistribute it
+ * and/or modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * END_COMMON_COPYRIGHT_HEADER */
+
+#include <QtGui/QKeySequence>
+#include <QtDBus/QDBusMessage>
#include <razorqt/razorsettings.h>
#include <razorqxt/qxtglobalshortcut.h>
@@ -40,17 +35,24 @@ class AbstractShortcut : public QObject
{
Q_OBJECT
public:
- AbstractShortcut (QObject *parent = 0) {}
+ AbstractShortcut(const QKeySequence& sequence, QObject* parent = 0);
+ ~AbstractShortcut() {}
- /* Execute the command */
- virtual bool exec() = 0;
+ private slots:
+ /* Execute the command */
+ virtual bool exec() = 0;
+
+ private:
+ QxtGlobalShortcut mShortcut;
};
class CommandShortcut : public AbstractShortcut
{
Q_OBJECT
public:
- CommandShortcut(const QString & cmd, QObject *parent = 0);
+ CommandShortcut(const QKeySequence& sequence, const QString& cmd, QObject* parent = 0);
+
+ private slots:
bool exec();
private:
@@ -62,23 +64,19 @@ class DBusShortcut : public AbstractShortcut
{
Q_OBJECT
public:
- DBusShortcut( const QString & dest,
+ DBusShortcut(const QKeySequence& sequence,
+ const QString & dest,
const QString & path,
const QString & interface,
const QString & method,
const QList<QVariant> & parameters = QList<QVariant>(),
QObject *parent = 0);
+ private slots:
bool exec();
private:
- QString m_dest, /* DBUS destination */
- m_path, /* DBUS path */
- m_interface, /* Call interface */
- m_method; /* Call method */
-
- QList<QVariant> m_params; /* Call parameters */
-
+ QDBusMessage mMessage;
};
class GlobalAccel: public QObject
@@ -89,13 +87,10 @@ class GlobalAccel: public QObject
~GlobalAccel();
GlobalAccel(QObject *parent = 0);
- void bindDefault();
-
private:
RazorSettings *m_shortcutSettings;
- QMap<QKeySequence, AbstractShortcut*> mapping;
+ QList<AbstractShortcut*> mMapping;
private slots:
- void launchApp();
void rebindAll();
};
View
1  razorqt-globalkeyshortcuts/src/main.cpp
@@ -35,7 +35,6 @@ int main(int argc, char *argv[])
QApplication a(argc, argv);
GlobalAccel ga;
- ga.bindDefault();
return a.exec();
}
Please sign in to comment.
Something went wrong with that request. Please try again.