summaryrefslogtreecommitdiffstats
path: root/examples/widgets/maemovibration
diff options
context:
space:
mode:
Diffstat (limited to 'examples/widgets/maemovibration')
-rw-r--r--examples/widgets/maemovibration/buttonwidget.cpp26
-rw-r--r--examples/widgets/maemovibration/buttonwidget.h24
-rw-r--r--examples/widgets/maemovibration/data/48x48/maemovibration.pngbin0 -> 2406 bytes
-rw-r--r--examples/widgets/maemovibration/data/64x64/maemovibration.pngbin0 -> 2989 bytes
-rw-r--r--examples/widgets/maemovibration/data/maemovibration.desktop12
-rw-r--r--examples/widgets/maemovibration/data/maemovibration.service3
-rw-r--r--examples/widgets/maemovibration/maemovibration.pro52
-rw-r--r--examples/widgets/maemovibration/main.cpp44
-rw-r--r--examples/widgets/maemovibration/mcevibrator.cpp79
-rw-r--r--examples/widgets/maemovibration/mcevibrator.h31
10 files changed, 271 insertions, 0 deletions
diff --git a/examples/widgets/maemovibration/buttonwidget.cpp b/examples/widgets/maemovibration/buttonwidget.cpp
new file mode 100644
index 0000000000..a723c31492
--- /dev/null
+++ b/examples/widgets/maemovibration/buttonwidget.cpp
@@ -0,0 +1,26 @@
+#include "buttonwidget.h"
+#include <QSignalMapper>
+#include <QGridLayout>
+#include <QPushButton>
+
+//! [0]
+ButtonWidget::ButtonWidget(QStringList texts, QWidget *parent)
+ : QWidget(parent)
+{
+ signalMapper = new QSignalMapper(this);
+
+ QGridLayout *gridLayout = new QGridLayout;
+ for (int i = 0; i < texts.size(); ++i) {
+ QPushButton *button = new QPushButton(texts[i]);
+ connect(button, SIGNAL(clicked()), signalMapper, SLOT(map()));
+ signalMapper->setMapping(button, texts[i]);
+ gridLayout->addWidget(button, i / 2, i % 2);
+ }
+
+ connect(signalMapper, SIGNAL(mapped(const QString &)),
+ this, SIGNAL(clicked(const QString &)));
+
+ setLayout(gridLayout);
+}
+//! [0]
+
diff --git a/examples/widgets/maemovibration/buttonwidget.h b/examples/widgets/maemovibration/buttonwidget.h
new file mode 100644
index 0000000000..6635c67782
--- /dev/null
+++ b/examples/widgets/maemovibration/buttonwidget.h
@@ -0,0 +1,24 @@
+#ifndef BUTTONWIDGET_H
+#define BUTTONWIDGET_H
+
+#include <QWidget>
+#include <QSignalMapper>
+
+//! [0]
+class ButtonWidget : public QWidget
+{
+ Q_OBJECT
+
+public:
+ ButtonWidget(QStringList texts, QWidget *parent = 0);
+
+signals:
+ void clicked(const QString &text);
+
+private:
+ QSignalMapper *signalMapper;
+};
+//! [0]
+
+#endif // BUTTONWIDGET_H
+
diff --git a/examples/widgets/maemovibration/data/48x48/maemovibration.png b/examples/widgets/maemovibration/data/48x48/maemovibration.png
new file mode 100644
index 0000000000..f32e9ced99
--- /dev/null
+++ b/examples/widgets/maemovibration/data/48x48/maemovibration.png
Binary files differ
diff --git a/examples/widgets/maemovibration/data/64x64/maemovibration.png b/examples/widgets/maemovibration/data/64x64/maemovibration.png
new file mode 100644
index 0000000000..f09cf7c3c6
--- /dev/null
+++ b/examples/widgets/maemovibration/data/64x64/maemovibration.png
Binary files differ
diff --git a/examples/widgets/maemovibration/data/maemovibration.desktop b/examples/widgets/maemovibration/data/maemovibration.desktop
new file mode 100644
index 0000000000..a88ed4e0aa
--- /dev/null
+++ b/examples/widgets/maemovibration/data/maemovibration.desktop
@@ -0,0 +1,12 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Name=Maemo Vibration
+Exec=/usr/bin/maemovibration
+Icon=maemovibration
+X-HildonDesk-ShowInToolbar=true
+X-Window-Icon=maemovibration
+X-Window-Icon-Dimmed=maemovibration
+X-Osso-Type=application/x-executable
+X-Osso-Service=com.nokia.maemovibration
diff --git a/examples/widgets/maemovibration/data/maemovibration.service b/examples/widgets/maemovibration/data/maemovibration.service
new file mode 100644
index 0000000000..1fab19f35c
--- /dev/null
+++ b/examples/widgets/maemovibration/data/maemovibration.service
@@ -0,0 +1,3 @@
+[D-BUS Service]
+Name=com.nokia.maemovibration
+Exec=/usr/bin/maemovibration
diff --git a/examples/widgets/maemovibration/maemovibration.pro b/examples/widgets/maemovibration/maemovibration.pro
new file mode 100644
index 0000000000..5c645dd369
--- /dev/null
+++ b/examples/widgets/maemovibration/maemovibration.pro
@@ -0,0 +1,52 @@
+TARGET = maemovibration
+HEADERS += buttonwidget.h mcevibrator.h
+SOURCES += main.cpp buttonwidget.cpp mcevibrator.cpp
+
+# All generated files goes same directory
+OBJECTS_DIR = build
+MOC_DIR = build
+UI_DIR = build
+DESTDIR = build
+
+TEMPLATE = app
+CONFIG += debug
+QT=core gui
+
+maemo5 {
+ QT += dbus
+ CONFIG += link_pkgconfig
+ PKG_CONFIG += mce
+ INSTALLS += target
+ target.path = /usr/bin/
+
+ INSTALLS += desktop
+ desktop.path = /usr/share/applications/hildon
+ desktop.files = data/maemovibration.desktop
+
+ INSTALLS += service
+ service.path = /usr/share/dbus-1/services
+ service.files = data/maemovibration.service
+
+ INSTALLS += icon64
+ icon64.path = /usr/share/icons/hicolor/64x64/apps
+ icon64.files = data/64x64/maemovibration.png
+
+ #
+ # Targets for debian source and binary package creation
+ #
+ debian-src.commands = dpkg-buildpackage -S -r -us -uc -d
+ debian-bin.commands = dpkg-buildpackage -b -r -uc -d
+ debian-all.depends = debian-src debian-bin
+
+ #
+ # Clean all but Makefile
+ #
+ compiler_clean.commands = -$(DEL_FILE) $(TARGET)
+
+ QMAKE_EXTRA_TARGETS += debian-all debian-src debian-bin compiler_clean
+}
+
+!maemo5 {
+ error(The Maemo Vibration Example only works for the maemo target!)
+}
+
diff --git a/examples/widgets/maemovibration/main.cpp b/examples/widgets/maemovibration/main.cpp
new file mode 100644
index 0000000000..f81529b185
--- /dev/null
+++ b/examples/widgets/maemovibration/main.cpp
@@ -0,0 +1,44 @@
+
+#include "buttonwidget.h"
+#include "mcevibrator.h"
+
+#include <QtDebug>
+#include <QApplication>
+#include <QFile>
+#include <QTextStream>
+#include <QMessageBox>
+#include <QTextStream>
+
+#include <cstdlib>
+
+//! [0]
+int main(int argc, char *argv[])
+{
+ QApplication a(argc, argv);
+ QString path = MceVibrator::defaultMceFilePath;
+
+ QFile file(path);
+ QStringList names;
+ if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
+ QTextStream stream(&file);
+ names = MceVibrator::parsePatternNames(stream);
+ file.close();
+ }
+
+ if (names.isEmpty()){
+ qDebug() << "Could not read vibration pattern names from " << path;
+ a.exit(-1);
+ }
+//! [0]
+
+//! [1]
+ ButtonWidget buttonWidget(names);
+ MceVibrator vibrator;
+ QObject::connect(&buttonWidget, SIGNAL(clicked(const QString &)),
+ &vibrator, SLOT(vibrate(const QString &)));
+ buttonWidget.show();
+
+ return a.exec();
+}
+//! [1]
+
diff --git a/examples/widgets/maemovibration/mcevibrator.cpp b/examples/widgets/maemovibration/mcevibrator.cpp
new file mode 100644
index 0000000000..be6415fa16
--- /dev/null
+++ b/examples/widgets/maemovibration/mcevibrator.cpp
@@ -0,0 +1,79 @@
+
+#include "mcevibrator.h"
+
+#include <QStringList>
+#include <QDebug>
+#include <QDBusConnection>
+#include <QDBusMessage>
+
+#include <mce/dbus-names.h>
+
+const char MceVibrator::defaultMceFilePath[] = "/etc/mce/mce.ini";
+
+//! [5]
+static void checkError(QDBusMessage &msg)
+{
+ if (msg.type() == QDBusMessage::ErrorMessage)
+ qDebug() << msg.errorName() << msg.errorMessage();
+}
+//! [5]
+
+//! [0]
+MceVibrator::MceVibrator(QObject *parent) :
+ QObject(parent),
+ mceInterface(MCE_SERVICE, MCE_REQUEST_PATH, MCE_REQUEST_IF,
+ QDBusConnection::systemBus())
+{
+ QDBusMessage reply = mceInterface.call(MCE_ENABLE_VIBRATOR);
+ checkError(reply);
+}
+//! [0]
+
+//! [3]
+MceVibrator::~MceVibrator()
+{
+ deactivate(lastPatternName);
+ QDBusMessage reply = mceInterface.call(MCE_DISABLE_VIBRATOR);
+ checkError(reply);
+}
+//! [3]
+
+//! [1]
+void MceVibrator::vibrate(const QString &patternName)
+{
+ deactivate(lastPatternName);
+ lastPatternName = patternName;
+ QDBusMessage reply = mceInterface.call(MCE_ACTIVATE_VIBRATOR_PATTERN, patternName);
+ checkError(reply);
+}
+//! [1]
+
+//! [2]
+void MceVibrator::deactivate(const QString &patternName)
+{
+ if (!patternName.isNull()) {
+ QDBusMessage reply = mceInterface.call(MCE_DEACTIVATE_VIBRATOR_PATTERN, patternName);
+ checkError(reply);
+ }
+}
+//! [2]
+
+//! [4]
+QStringList MceVibrator::parsePatternNames(QTextStream &stream)
+{
+ QStringList result;
+ QString line;
+
+ do {
+ line = stream.readLine();
+ if (line.startsWith(QLatin1String("VibratorPatterns="))) {
+ QString values = line.section('=', 1);
+ result = values.split(';');
+ break;
+ }
+ } while (!line.isNull());
+
+ return result;
+}
+//! [4]
+
diff --git a/examples/widgets/maemovibration/mcevibrator.h b/examples/widgets/maemovibration/mcevibrator.h
new file mode 100644
index 0000000000..5aac87d9c6
--- /dev/null
+++ b/examples/widgets/maemovibration/mcevibrator.h
@@ -0,0 +1,31 @@
+#ifndef MCEVIBRATOR_H
+#define MCEVIBRATOR_H
+
+#include <QObject>
+#include <QTextStream>
+#include <QDBusInterface>
+
+//! [0]
+class MceVibrator : public QObject
+{
+ Q_OBJECT
+public:
+ explicit MceVibrator(QObject *parent = 0);
+ ~MceVibrator();
+
+ static const char defaultMceFilePath[];
+ static QStringList parsePatternNames(QTextStream &stream);
+
+public slots:
+ void vibrate(const QString &patternName);
+
+private:
+ void deactivate(const QString &patternName);
+
+ QDBusInterface mceInterface;
+ QString lastPatternName;
+};
+//! [0]
+
+#endif // MCEVIBRATOR_H
+