summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJavier S. Pedro <maemo@javispedro.com>2011-09-11 03:31:14 +0200
committerJavier <javier@pcjavier.(none)>2011-09-11 03:31:14 +0200
commit0d8b5446e880298d89511dd0bc0dbe328ccfce97 (patch)
tree3146a1ee224cbd0c75975d842b0fca17c5474f08
parent94ab9634b2306016a8bc50fb3c67aa853481a5c7 (diff)
downloadglol-master.tar.gz
glol-master.zip
Try to revert to previous state on SIGINT/SIGTERM.HEADmaster
-rw-r--r--fakeproperty.cpp33
-rw-r--r--fakeproperty.h14
-rw-r--r--fakepropertyadaptor.cpp15
-rw-r--r--fakepropertyadaptor.h5
-rw-r--r--faker.cpp25
-rw-r--r--faker.h27
-rw-r--r--glol.pro16
-rw-r--r--main.cpp57
8 files changed, 165 insertions, 27 deletions
diff --git a/fakeproperty.cpp b/fakeproperty.cpp
index 38d9040..8eea148 100644
--- a/fakeproperty.cpp
+++ b/fakeproperty.cpp
@@ -1,16 +1,41 @@
#include "fakeproperty.h"
-FakeProperty::FakeProperty(const QString& key, const QVariant& value, QObject *parent) :
- QObject(parent), _key(key), _value(value)
+FakeProperty::FakeProperty(const QString& key, QObject* parent) :
+ QObject(parent), _key(key), _value(), _timestamp(0)
{
}
-const QString& FakeProperty::key() const
+QString FakeProperty::key() const
{
return _key;
}
-const QVariant& FakeProperty::value() const
+QVariant FakeProperty::value() const
{
return _value;
}
+
+quint64 FakeProperty::timestamp() const
+{
+ return _timestamp;
+}
+
+void FakeProperty::setValue(const QVariant &value)
+{
+ _value = value;
+ if (_timestamp) {
+ emit valueChanged();
+ }
+}
+
+void FakeProperty::startFaking()
+{
+ _timestamp = Q_INT64_C(-1); /* To have priority over other providers */
+ emit valueChanged();
+}
+
+void FakeProperty::stopFaking()
+{
+ _timestamp = 0; /* To stop having priority over other providers */
+ emit valueChanged();
+}
diff --git a/fakeproperty.h b/fakeproperty.h
index 4509b83..3f920ad 100644
--- a/fakeproperty.h
+++ b/fakeproperty.h
@@ -7,17 +7,23 @@ class FakeProperty : public QObject
{
Q_OBJECT
public:
- explicit FakeProperty(const QString& key, const QVariant& value, QObject *parent = 0);
- const QString& key() const;
- const QVariant& value() const;
+ explicit FakeProperty(const QString& key, QObject *parent = 0);
+ QString key() const;
+ QVariant value() const;
+ quint64 timestamp() const;
signals:
+ void valueChanged();
public slots:
+ void setValue(const QVariant& value);
+ void startFaking();
+ void stopFaking();
-private:
+protected:
QString _key;
QVariant _value;
+ quint64 _timestamp;
};
diff --git a/fakepropertyadaptor.cpp b/fakepropertyadaptor.cpp
index 0a65c31..369c1c1 100644
--- a/fakepropertyadaptor.cpp
+++ b/fakepropertyadaptor.cpp
@@ -7,6 +7,7 @@
FakePropertyAdaptor::FakePropertyAdaptor(FakeProperty* property) :
QDBusAbstractAdaptor(property), _property(property)
{
+ connect(_property, SIGNAL(valueChanged()), SLOT(propertyChanged()));
}
QString FakePropertyAdaptor::objectPath() const
@@ -20,17 +21,25 @@ QString FakePropertyAdaptor::objectPath() const
void FakePropertyAdaptor::Subscribe(const QDBusMessage& msg, QVariantList& values, quint64& timestamp)
{
- qDebug() << "subscribe from " << msg.service();
+ Q_UNUSED(msg);
Get(values, timestamp);
}
void FakePropertyAdaptor::Unsubscribe(const QDBusMessage& msg)
{
- qDebug() << "unsubscribe from " << msg.service();
+ Q_UNUSED(msg);
}
void FakePropertyAdaptor::Get(QVariantList& values, quint64& timestamp)
{
values << _property->value();
- timestamp = -1LL;
+ timestamp = _property->timestamp();
+}
+
+void FakePropertyAdaptor::propertyChanged()
+{
+ QVariantList values;
+ quint64 timestamp;
+ Get(values, timestamp);
+ emit ValueChanged(values, timestamp);
}
diff --git a/fakepropertyadaptor.h b/fakepropertyadaptor.h
index 8293042..6c70d46 100644
--- a/fakepropertyadaptor.h
+++ b/fakepropertyadaptor.h
@@ -23,8 +23,11 @@ public slots:
void Unsubscribe(const QDBusMessage& msg);
void Get(QVariantList& values, quint64& timestamp);
-private:
+protected:
FakeProperty* _property;
+
+protected slots:
+ void propertyChanged();
};
#endif // FAKEPROPERTYADAPTOR_H
diff --git a/faker.cpp b/faker.cpp
new file mode 100644
index 0000000..b512439
--- /dev/null
+++ b/faker.cpp
@@ -0,0 +1,25 @@
+#include "faker.h"
+
+#define SERVICE_NAME "com.javispedro.glol"
+
+Faker::Faker(const QString& val, QObject *parent) :
+ QObject(parent), _bus(QDBusConnection::sessionBus()),
+ _property(new FakeProperty("Screen.TopEdge")),
+ _adaptor(new FakePropertyAdaptor(_property))
+{
+ _property->setValue(val);
+}
+
+void Faker::start()
+{
+ _bus.registerObject(_adaptor->objectPath(), _property);
+ _bus.registerService(SERVICE_NAME);
+ _property->startFaking();
+}
+
+void Faker::stop()
+{
+ _property->stopFaking();
+ _bus.unregisterService(SERVICE_NAME);
+ _bus.unregisterObject(_adaptor->objectPath());
+}
diff --git a/faker.h b/faker.h
new file mode 100644
index 0000000..7c2c149
--- /dev/null
+++ b/faker.h
@@ -0,0 +1,27 @@
+#ifndef FAKER_H
+#define FAKER_H
+
+#include <QtDBus/QDBusConnection>
+
+#include "fakeproperty.h"
+#include "fakepropertyadaptor.h"
+
+class Faker : public QObject
+{
+ Q_OBJECT
+public:
+ explicit Faker(const QString& val, QObject *parent = 0);
+
+signals:
+
+public slots:
+ void start();
+ void stop();
+
+protected:
+ QDBusConnection _bus;
+ FakeProperty *_property;
+ FakePropertyAdaptor *_adaptor;
+};
+
+#endif // FAKER_H
diff --git a/glol.pro b/glol.pro
index 0f1033c..2cb225d 100644
--- a/glol.pro
+++ b/glol.pro
@@ -14,11 +14,13 @@ TEMPLATE = app
SOURCES += main.cpp \
fakepropertyadaptor.cpp \
- fakeproperty.cpp
+ fakeproperty.cpp \
+ faker.cpp
HEADERS += \
fakepropertyadaptor.h \
- fakeproperty.h
+ fakeproperty.h \
+ faker.h
OTHER_FILES += \
com.javispedro.glol.context \
@@ -30,9 +32,11 @@ OTHER_FILES += \
qtc_packaging/debian_harmattan/changelog
unix:!symbian:!maemo5 {
- target.path = /usr/bin
+ target.path = /usr/bin
INSTALLS += target
- contextfiles.path += /usr/share/contextkit/providers
- contextfiles.files = com.javispedro.glol.context
- INSTALLS += contextfiles
+ contextfiles.path += /usr/share/contextkit/providers
+ contextfiles.files = com.javispedro.glol.context
+ INSTALLS += contextfiles
}
+
+
diff --git a/main.cpp b/main.cpp
index d112d28..26a1171 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1,19 +1,58 @@
+#include <stdio.h>
+#include <signal.h>
+
#include <QtCore/QCoreApplication>
-#include <QtCore/QDebug>
-#include <QtDBus/QDBusConnection>
+#include <QtCore/QStringList>
+
+#include "faker.h"
-#include "fakeproperty.h"
-#include "fakepropertyadaptor.h"
+static Faker* faker;
+
+static void printHelp()
+{
+ printf("glol -- temporarily lock orientation in all applications\n");
+ printf("Use: glol <p|portrait|l|landscape|ip|il>\n");
+}
+
+static void handleSignal(int signal)
+{
+ Q_UNUSED(signal);
+ // Potentially unsafe. But...
+ faker->stop();
+ QCoreApplication::instance()->quit();
+}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
- QDBusConnection bus = QDBusConnection::sessionBus();
- FakeProperty *property = new FakeProperty("Screen.TopEdge", QString("top"));
- FakePropertyAdaptor *adaptor = new FakePropertyAdaptor(property);
- bus.registerObject(adaptor->objectPath(), property);
- bus.registerService("com.javispedro.glol");
+ QMap<QString, QString> map;
+ QString val;
+
+ if (a.arguments().count() != 2) {
+ printHelp();
+ return 1;
+ }
+
+ map["p"] = "left";
+ map["portrait"] = "left";
+ map["l"] = "top";
+ map["landscape"] = "top";
+ map["ip"] = "right";
+ map["il"] = "bottom";
+
+ val = map[a.arguments().at(1).toLower()];
+ if (val.isEmpty()) {
+ printHelp();
+ return 1;
+ }
+
+ signal(SIGINT, handleSignal);
+ signal(SIGTERM, handleSignal);
+ signal(SIGHUP, handleSignal);
+
+ faker = new Faker(val);
+ faker->start();
return a.exec();
}