|
2011-05-30
, 19:36
|
Posts: 435 |
Thanked: 769 times |
Joined on Apr 2010
|
#2
|
The Following User Says Thank You to gionni88 For This Useful Post: | ||
|
2011-05-30
, 20:01
|
|
Posts: 738 |
Thanked: 983 times |
Joined on Apr 2010
@ London
|
#3
|
|
2011-05-30
, 21:07
|
Posts: 435 |
Thanked: 769 times |
Joined on Apr 2010
|
#4
|
#include "backlighthandler.h" #include <QtCore/QCoreApplication> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); new BacklightHandler; return a.exec(); }
#ifndef BACKLIGHTHANDLER_H #define BACKLIGHTHANDLER_H #include <QObject> #include <QCoreApplication> #include <QDebug> #include <QFile> #include <QFileSystemWatcher> #include <QStringList> class BacklightHandler : public QObject { Q_OBJECT public: explicit BacklightHandler(QObject *parent = 0); signals: public slots: private: int backlightValue; int defaultBacklightValue; QFileSystemWatcher *backlightFileWatcher; void setBacklight(int); int readBacklightValue(); private slots: void backlightValueChanged(); }; #endif // BACKLIGHTHANDLER_H
#include "backlighthandler.h" BacklightHandler::BacklightHandler(QObject *parent) : QObject(parent) { defaultBacklightValue = readBacklightValue(); backlightValue = qApp->arguments().at(1).toInt(); backlightFileWatcher = new QFileSystemWatcher; backlightFileWatcher->addPath("/sys/class/backlight/acx565akm/brightness"); connect(backlightFileWatcher, SIGNAL(fileChanged(QString)), this, SLOT(backlightValueChanged())); setBacklight(backlightValue); } void BacklightHandler::setBacklight(int value) { QString program = QString("echo 'echo %1 > /sys/class/backlight/acx565akm/brightness' | root").arg(QString::number(value)); system(program.toStdString().c_str()); } int BacklightHandler::readBacklightValue() { qDebug()<<"Reading backlight value."; QFile file("/sys/class/backlight/acx565akm/brightness"); file.open(QIODevice::ReadOnly | QIODevice::Text); QTextStream t( &file ); QString value; value = t.readLine(); qDebug()<<"Backlight value: "<<value<<endl; file.close(); return value.toInt(); } void BacklightHandler::backlightValueChanged() { qDebug()<<"Backlight value changed."; int tempValue; tempValue = readBacklightValue(); if (tempValue == backlightValue) { qDebug()<<"Value is the same, returning."; return; } qDebug()<<"Value is different, editing file."<<endl; setBacklight(backlightValue); }
The Following 2 Users Say Thank You to gionni88 For This Useful Post: | ||
|
2011-05-30
, 21:14
|
|
Posts: 738 |
Thanked: 983 times |
Joined on Apr 2010
@ London
|
#5
|
I am fairly familiar with c++, but I am completely lost in the "setting framework and pieces" phase that sadly comes first. There are a lot of documentation out there, but their not consistent between one another
I'm using the Qt SDK as I thought it would be useful to get familiar with it, and as Qt provides dbus abstraction. I've chosen "Qt Console Application" template, does that make sense?
I tried to inherit from a QtService class, but it does not seem to find the includes. How do I add include paths in a Qt SDK project?
Or is there a more straightforward way to create a service? (ie what do I need to implement?)
Targets would be maemo 5, meego, and linux desktop.
Any advice appreciated.. after that I should be good on my own.
thanks!