From 0d8b5446e880298d89511dd0bc0dbe328ccfce97 Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Sun, 11 Sep 2011 03:31:14 +0200 Subject: Try to revert to previous state on SIGINT/SIGTERM. --- main.cpp | 57 ++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 48 insertions(+), 9 deletions(-) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index d112d28..26a1171 100644 --- a/main.cpp +++ b/main.cpp @@ -1,19 +1,58 @@ +#include +#include + #include -#include -#include +#include + +#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 \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 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(); } -- cgit v1.2.3