diff --git a/CMakeLists.txt b/CMakeLists.txt index 7d030f0b..b2637dc9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,72 +1,77 @@ project(plasma-mobile) cmake_minimum_required (VERSION 2.8) set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules") find_package(KDE4 REQUIRED) find_package(KActivities 6.0.0 REQUIRED) include(KDE4Defaults) add_definitions (${QT_DEFINITIONS} ${KDE4_DEFINITIONS}) add_definitions(-DDISABLE_NEPOMUK_LEGACY=1) find_package(Nepomuk REQUIRED) find_package(Soprano) +find_package(QtMobility) macro_log_feature( Soprano_FOUND "Soprano" "Semantic Desktop Storing" "http://soprano.sourceforge.net" TRUE "${SOPRANO_MIN_VERSION}" "Soprano is needed for Nepomuk" ) find_package(KDeclarative REQUIRED) macro_log_feature( KDeclarative_FOUND "libkdeclarative" "KDE Declarative (QML) support from kdelibs" "http://www.kde.org" TRUE "" "" ) +if(NOT X11_Xinput_FOUND) + macro_log_feature(X11_Xinput_FOUND "libXi" "X11 input management library" "http://xorg.freedesktop.org" FALSE "" "Needed for orientation dataengine.") +endif(NOT X11_Xinput_FOUND) + include(SopranoAddOntology) add_definitions(-DDISABLE_NEPOMUK_LEGACY=1) include_directories( ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}/inputmethod ${KDE4_INCLUDES} ${KDECLARATIVE_INCLUDE_DIR} ${KACTIVITIES_INCLUDE_DIRS} ${SOPRANO_INCLUDE_DIR} ) MACRO(installPackage dir component) SET(root ${ARGN}) IF(NOT root) SET(root plasma/plasmoids) ENDIF(NOT root) install(DIRECTORY ${dir}/ DESTINATION ${DATA_INSTALL_DIR}/${root}/${component} PATTERN Messages.sh EXCLUDE) install(FILES ${dir}/metadata.desktop DESTINATION ${SERVICES_INSTALL_DIR} RENAME plasma-applet-${component}.desktop) ENDMACRO(installPackage) MACRO(add_kao_ontology var) soprano_add_ontology( ${var} ${KACTIVITIES_ONTOLOGIES_DIR}/kao.trig "KAO" "Nepomuk2::Vocabulary" "trig" ) ENDMACRO(add_kao_ontology) add_subdirectory(applets) add_subdirectory(applications) add_subdirectory(artwork) add_subdirectory(components) add_subdirectory(containments) add_subdirectory(dataengines) add_subdirectory(qmlpackages) add_subdirectory(runners) add_subdirectory(shell) add_subdirectory(wallpapers) if (BUILD_HANDSET) add_subdirectory(handset) endif (BUILD_HANDSET) diff --git a/applets/CMakeLists.txt b/applets/CMakeLists.txt index f33ba406..8b8e3575 100644 --- a/applets/CMakeLists.txt +++ b/applets/CMakeLists.txt @@ -1,8 +1,9 @@ installPackage(active-welcome org.kde.active.welcome) installPackage(notifications org.kde.active.notifications) +installPackage(orientation org.kde.active.orientation) installPackage(powerbutton org.kde.active.powerbutton) installPackage(resourcelist org.kde.resourcelist) installPackage(digital-clock org.kde.digital-clock) add_subdirectory(alarms) add_subdirectory(locationchooser) diff --git a/applets/orientation/Messages.sh b/applets/orientation/Messages.sh new file mode 100644 index 00000000..87d9c334 --- /dev/null +++ b/applets/orientation/Messages.sh @@ -0,0 +1,4 @@ +#! /usr/bin/env bash +$EXTRACTRC `find . -name \*.rc -o -name \*.ui -o -name \*.kcfg` >> rc.cpp +$XGETTEXT `find . -name \*.qml` -L Java -o $podir/plasma_applet_org.kde.active.orientation.pot +rm -f rc.cpp diff --git a/applets/orientation/contents/code/Orientation.qml b/applets/orientation/contents/code/Orientation.qml new file mode 100644 index 00000000..dffdead0 --- /dev/null +++ b/applets/orientation/contents/code/Orientation.qml @@ -0,0 +1,70 @@ +// -*- coding: iso-8859-1 -*- +/* + * Copyright 2012 Jeremy Whiting + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2 or + * (at your option) any later version. + * + * This program 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 Library General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +import Qt 4.7 +import org.kde.plasma.core 0.1 as PlasmaCore +import org.kde.plasma.mobilecomponents 0.1 + +Item { + id: orientation + width: buttonColumn.width + height: buttonColumn.height + property int minimumWidth: buttonColumn.width + property int minimumHeight: buttonColumn.height + + PlasmaCore.DataSource { + id: orientationSource + engine: "orientation" + interval: 0 + } + + Component.onCompleted: { + plasmoid.setPopupIconByName("transform-rotate") + } + + Column { + id: buttonColumn + spacing: 5 + IconButton { + width: 32 + height: 32 + icon: QIcon("object-rotate-left") + + onClicked: { + var sources = orientationSource.sources + var service = orientationSource.serviceForSource(sources[0]) + var operation = service.operationDescription("rotateLeft") + service.startOperationCall(operation) + } + } + + IconButton { + icon: QIcon("object-rotate-right") + width: 32 + height: 32 + onClicked: { + var sources = orientationSource.sources + var service = orientationSource.serviceForSource(sources[0]) + var operation = service.operationDescription("rotateRight") + service.startOperationCall(operation) + } + } + } +} diff --git a/applets/orientation/metadata.desktop b/applets/orientation/metadata.desktop new file mode 100644 index 00000000..02b245fb --- /dev/null +++ b/applets/orientation/metadata.desktop @@ -0,0 +1,20 @@ +[Desktop Entry] +Name=Orientation +Comment=Lock/Unlock and configure screen orientation +Encoding=UTF-8 +Keywords=Screen, Orientation +Type=Service +Icon=transform-rotate +X-KDE-ParentApp= +X-KDE-PluginInfo-Author=Jeremy Whiting +X-KDE-PluginInfo-Category=System Information +X-KDE-PluginInfo-Email=jpwhiting@kde.org +X-KDE-PluginInfo-License=GPL +X-KDE-PluginInfo-Name=org.kde.active.orientation +X-KDE-PluginInfo-Version= +X-KDE-PluginInfo-Website=http://plasma.kde.org +X-KDE-ServiceTypes=Plasma/Applet,Plasma/PopupApplet +X-Plasma-API=declarativeappletscript +X-Plasma-DefaultSize=32,64 +X-Plasma-MainScript=code/Orientation.qml +X-Plasma-RemoteLocation= diff --git a/cmake/modules/FindQtMobility.cmake b/cmake/modules/FindQtMobility.cmake new file mode 100644 index 00000000..b47fad21 --- /dev/null +++ b/cmake/modules/FindQtMobility.cmake @@ -0,0 +1,102 @@ +# - Try to find the QtMobility libraries +# +# This module will search for the QtMobility libraries. +# +# It supports both a minimum version and searching for individual +# components. For the minimum version, use +# find_package(QtMobility 1.2.0). For specific components, use +# find_package(QtMobility COMPONENTS ...). See below for a list of known +# components. +# +# Once done this will define +# QTMOBILITY_FOUND - QtMobility and all specified components were found. +# QTMOBILITY_INCLUDE_DIR - Include directory for global QtMobility files. +# QTMOBILITY_INCLUDE_DIRS - All found QtMobility components' include dirs. +# QTMOBILITY_LIBRARIES - All found QtMobility components' libraries. +# QTMOBILITY_VERSION - The version of QtMobility that was found. +# +# For each found component the following will be defined: +# QTMOBILITY_{COMPONENT}_INCLUDE_DIR - The include directory for the component. +# QTMOBILITY_{COMPONENT}_LIBRARY - The location of the library for the component. +# +# Note that searching for components will be limited to the specified components +# if the components option is used. +# +# Copyright (c) 2011 Arjen Hiemstra +# Redistribution and use is allowed according to the terms of the BSD license. + +set(QTMOBILITY_COMPONENTS + Bearer + Connectivity + Contacts + Feedback + Gallery + Location + Messaging + MultimediaKit + Organizer + PublishSubscribe + Sensors + ServiceFramework + SystemInfo + Versit +) + +if (QtMobility_FIND_COMPONENTS) + foreach (component ${QtMobility_FIND_COMPONENTS}) + string(TOUPPER ${component} _COMPONENT) + set(QTMOBILITY_USE_${_COMPONENT} 1) + endforeach (component) +endif (QtMobility_FIND_COMPONENTS) + +find_path(QTMOBILITY_INCLUDE_DIR qmobilityglobal.h PATH_SUFFIXES QtMobility) + +#Find the mobility version +if(QTMOBILITY_INCLUDE_DIR) + file(READ "${QTMOBILITY_INCLUDE_DIR}/qmobilityglobal.h" _qtmobility_global_header LIMIT 2000) + string(REGEX MATCH "#define QTM_VERSION_STR \"([0-9.]*)\"" _qtmobility_version_match "${_qtmobility_global_header}") + set(QTMOBILITY_VERSION "${CMAKE_MATCH_1}") + message(STATUS "QtMobility Version ${QTMOBILITY_VERSION} detected") +endif(QTMOBILITY_INCLUDE_DIR) + +set(QTMOBILITY_VARIABLES "QTMOBILITY_INCLUDE_DIR") +set(QTMOBILITY_INCLUDE_DIRS ${QTMOBILITY_INCLUDE_DIR}) + +#A list of files to find for specific components +set(QTMOBILITY_FIND_FILES + QNetworkConfiguration #Bearer + QBluetoothSocket #Connectivity + QContact #Contacts + QFeedbackInterface #Feedback + QAbstractGallery #Gallery + QLandmark #Location + QMessage #Messaging + QMediaPlayer #MultimediaKit + QOrganizerItem #Organizer + QValueSpace #PublishSubscribe + QSensor #Sensors + QService #ServiceFramework + QSystemInfo #SystemInfo + QVersitDocument #Versit +) + +list(LENGTH QTMOBILITY_COMPONENTS _component_count) +math(EXPR _component_count "${_component_count} - 1") +foreach (index RANGE ${_component_count}) + list(GET QTMOBILITY_COMPONENTS ${index} component) + list(GET QTMOBILITY_FIND_FILES ${index} file) + string(TOUPPER ${component} _COMPONENT) + if (NOT QtMobility_FIND_COMPONENTS OR QTMOBILITY_USE_${_COMPONENT}) + message(STATUS "Looking for QtMobility Component \"${component}\"") + find_path(QTMOBILITY_${_COMPONENT}_INCLUDE_DIR ${file} PATH_SUFFIXES Qt${component}) + find_library(QTMOBILITY_${_COMPONENT}_LIBRARY NAMES Qt${component}) + list(APPEND QTMOBILITY_VARIABLES "QTMOBILITY_${_COMPONENT}_INCLUDE_DIR" "QTMOBILITY_${_COMPONENT}_LIBRARY") + list(APPEND QTMOBILITY_INCLUDE_DIRS ${QTMOBILITY_${_COMPONENT}_INCLUDE_DIR}) + list(APPEND QTMOBILITY_LIBRARIES ${QTMOBILITY_${_COMPONENT}_LIBRARY}) + endif (NOT QtMobility_FIND_COMPONENTS OR QTMOBILITY_USE_${_COMPONENT}) +endforeach (index) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(QtMobility REQUIRED_VARS ${QTMOBILITY_VARIABLES} VERSION_VAR QTMOBILITY_VERSION) + +mark_as_advanced(${QTMOBILITY_VARIABLES}) diff --git a/dataengines/CMakeLists.txt b/dataengines/CMakeLists.txt index c9bfa935..effba3c5 100644 --- a/dataengines/CMakeLists.txt +++ b/dataengines/CMakeLists.txt @@ -1,5 +1,8 @@ add_subdirectory(alarms) add_subdirectory(apps) add_subdirectory(devicecapabilities) add_subdirectory(metadata) +if (X11_Xinput_FOUND) + add_subdirectory(orientation) +endif (X11_Xinput_FOUND) add_subdirectory(preview) diff --git a/dataengines/orientation/CMakeLists.txt b/dataengines/orientation/CMakeLists.txt new file mode 100644 index 00000000..b37bc7b4 --- /dev/null +++ b/dataengines/orientation/CMakeLists.txt @@ -0,0 +1,31 @@ +project(orientationengine) + +find_package(LibKScreen) + +include_directories(${CMAKE_CURRENT_BINARY_DIR} + ${QTMOBILITY_INCLUDE_DIR} + ${LibKScreen_INCLUDE_DIR} + ${QTMOBILITY_SENSORS_INCLUDE_DIR}) + +set(orientationengine_srcs + orientationengine.cpp + orientationservice.cpp + orientationjob.cpp +) + +kde4_add_plugin(plasma_engine_orientation ${orientationengine_srcs}) + +target_link_libraries(plasma_engine_orientation + ${KDE4_PLASMA_LIBS} + ${KDE4_KIO_LIBS} + ${LibKScreen_LIBRARY} + ${X11_LIBRARIES} + ${X11_Xinput_LIB} + ${QTMOBILITY_SENSORS_LIBRARY} +) + +install(TARGETS plasma_engine_orientation DESTINATION ${PLUGIN_INSTALL_DIR}) +install(FILES plasma-engine-orientation.desktop DESTINATION ${SERVICES_INSTALL_DIR}) +install(FILES orientation.operations + DESTINATION ${DATA_INSTALL_DIR}/plasma/services) + diff --git a/dataengines/orientation/orientation.operations b/dataengines/orientation/orientation.operations new file mode 100644 index 00000000..aeb8a776 --- /dev/null +++ b/dataengines/orientation/orientation.operations @@ -0,0 +1,14 @@ + + + + + + + + + + + + + diff --git a/dataengines/orientation/orientationengine.cpp b/dataengines/orientation/orientationengine.cpp new file mode 100644 index 00000000..32eee78d --- /dev/null +++ b/dataengines/orientation/orientationengine.cpp @@ -0,0 +1,119 @@ +/* + Copyright 2012 Jeremy Whiting + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published by + the Free Software Foundation; either version 2 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 Library General Public + License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ + + +#include "orientationengine.h" +#include "orientationservice.h" + +#include + +#include +#include +#include + +#include + +K_EXPORT_PLASMA_DATAENGINE(orientationengine, OrientationEngine) + +using namespace QtMobility; + +OrientationEngine::OrientationEngine(QObject* parent, const QVariantList& args) + : Plasma::DataEngine(parent) +{ + Q_UNUSED(args); + setMaxSourceCount(64); // Guard against loading too many connections + + // This prevents applets from setting an unnecessarily high + // update interval and using too much CPU. + // In the case of a clock that only has second precision, + // a third of a second should be more than enough. + setMinimumPollingInterval(333); +} + +Plasma::Service *OrientationEngine::serviceForSource(const QString &source) +{ + if (m_touchscreens.contains(source)) + { + OrientationService *service = + new OrientationService(m_touchscreens.value(source), + containerForSource(source)); + service->setParent(this); + return service; + } + return NULL; +} + +void OrientationEngine::init() +{ + m_sensor = new QOrientationSensor(this); + connect(m_sensor, SIGNAL(readingChanged()), this, SLOT(onReadingChange())); + m_sensor->start(); + + Display * display = XOpenDisplay(0); + int ndevices_return; + XDeviceInfo *devices = XListInputDevices( display, &ndevices_return); + + kDebug() << "Got " << ndevices_return << " X input devices"; + int foundScreen = 0; + for (int i = 0; i < ndevices_return; ++i) + { + if (devices[i].type == XInternAtom(display, XI_TOUCHSCREEN, False) + || devices[i].type == XInternAtom(display, XI_TOUCHPAD, FALSE)) + { + QString name = QString("Screen%1").arg(foundScreen); + kDebug() << "Got a touchscreen device " << devices[i].name; + m_touchscreens.insert(name, devices[i].id); + setData(name, "Orientation", 0); + ++foundScreen; + } + } + + XFreeDeviceList(devices); +} + +OrientationEngine::~OrientationEngine() +{ +} + +void OrientationEngine::onReadingChange() +{ + QOrientationReading* reading = m_sensor->reading(); + if (reading != 0) + { + kDebug() << "Orientation reading changed to " << reading->orientation(); + switch (reading->orientation()) + { + case QOrientationReading::TopDown: + //set_matrix(k_inverted_matrix); + break; + case QOrientationReading::LeftUp: + //set_matrix(k_left_matrix); + break; + case QOrientationReading::RightUp: + //set_matrix(k_right_matrix); + break; + case QOrientationReading::TopUp: + default: + //set_matrix(k_normal_matrix); + break; + } + } +} + +#include "orientationengine.moc" diff --git a/dataengines/orientation/orientationengine.h b/dataengines/orientation/orientationengine.h new file mode 100644 index 00000000..56aefbab --- /dev/null +++ b/dataengines/orientation/orientationengine.h @@ -0,0 +1,53 @@ +/* + Copyright 2012 Jeremy Whiting + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published by + the Free Software Foundation; either version 2 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 Library General Public + License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ + + +#ifndef ORIENTATION_ENGINE_H +#define ORIENTATION_ENGINE_H + +#include +#include + +#include +#include + +namespace QtMobility +{ + class QOrientationSensor; +} + +class OrientationEngine : public Plasma::DataEngine +{ + Q_OBJECT + +public: + OrientationEngine(QObject* parent, const QVariantList& args); + ~OrientationEngine(); + Plasma::Service *serviceForSource(const QString &source); + virtual void init(); + +private slots: + void onReadingChange(); + +private: + QtMobility::QOrientationSensor* m_sensor; + QMap m_touchscreens; +}; + +#endif diff --git a/dataengines/orientation/orientationjob.cpp b/dataengines/orientation/orientationjob.cpp new file mode 100644 index 00000000..82a1d0dd --- /dev/null +++ b/dataengines/orientation/orientationjob.cpp @@ -0,0 +1,192 @@ +/* + * Copyright 2012 Jeremy Whiting + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * This program 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 General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "orientationjob.h" + +#include + +#include + +#include + +#include +#include +#include + +using namespace QtMobility; + +static const float k_normal_matrix[9] = {1, 0, 0, 0, 1, 0, 0, 0, 1}; +static const float k_left_matrix[9] = {0, -1, 1, 1, 0, 0, 0, 0, 1}; +static const float k_right_matrix[9] = {0, 1, 0, -1, 0, 1, 0, 0, 1}; +static const float k_inverted_matrix[9] = {-1, 0, 1, 0, -1, 1, 0, 0, 1}; +static const int k_matrix_length = 9; + +OrientationJob::OrientationJob(XID id, + int reading, + const QString &operation, + QMap ¶meters, + QObject *parent) : + ServiceJob(parent->objectName(), operation, parameters, parent), + m_id(id), + m_prevReading((QOrientationReading::Orientation)reading) +{ + kDebug() << "Orientation job created with xid " << id << " and operation " << operation + << " previous reading is " << m_prevReading; + +} + +OrientationJob::~OrientationJob() +{ +} + +void OrientationJob::start() +{ + const QString operation = operationName(); + kDebug() << "OrientationJob started with operation name " << operation + << " and previous orientation " << m_prevReading; + + // Default to top up for all operations. + QOrientationReading::Orientation direction = QOrientationReading::TopUp; + if (operation == "setOrientation") { + direction = (QOrientationReading::Orientation) + parameters()["orientation"].value(); + } + else if (operation == "rotateLeft") { + // Set direction to whatever is left of the previous reading. + switch (m_prevReading) + { + case QOrientationReading::TopDown: + direction = QOrientationReading::RightUp; + break; + case QOrientationReading::LeftUp: + direction = QOrientationReading::TopDown; + break; + case QOrientationReading::RightUp: + direction = QOrientationReading::TopUp; + break; + case QOrientationReading::TopUp: + default: + direction = QOrientationReading::LeftUp; + } + } + else if (operation == "rotateRight") { + // Set direction to whatever is right of the previous reading. + switch (m_prevReading) + { + case QOrientationReading::TopDown: + direction = QOrientationReading::LeftUp; + break; + case QOrientationReading::LeftUp: + direction = QOrientationReading::TopUp; + break; + case QOrientationReading::RightUp: + direction = QOrientationReading::TopDown; + break; + case QOrientationReading::TopUp: + default: + direction = QOrientationReading::RightUp; + } + } + KScreen::Config* config = KScreen::Config::current(); + if (config == 0) + { + setenv("KSCREEN_BACKEND", "XRandR", 0); + config = KScreen::Config::current(); + Q_ASSERT(config != 0); + } + KScreen::Output* output = config->primaryOutput(); + if (output == 0) + { + // There's not a primary output, so just take the first connected output. + QHash connected = config->connectedOutputs(); + if (connected.size() < 1) + return; + output = (*connected.begin()); + } + kDebug() << "direction is " << direction; + switch (direction) + { + case QOrientationReading::TopDown: + set_matrix(k_inverted_matrix); + kDebug() << "rotating upside down"; + output->setRotation(KScreen::Output::Inverted); + break; + case QOrientationReading::LeftUp: + set_matrix(k_left_matrix); + kDebug() << "rotating left"; + output->setRotation(KScreen::Output::Left); + break; + case QOrientationReading::RightUp: + set_matrix(k_right_matrix); + kDebug() << "rotating right"; + output->setRotation(KScreen::Output::Right); + break; + default: + case QOrientationReading::TopUp: + set_matrix(k_normal_matrix); + kDebug() << "rotating normal"; + output->setRotation(KScreen::Output::None); + break; + } + KScreen::Config::setConfig(config); + emit dataChanged(direction); + setResult(true); +} + +void OrientationJob::set_matrix (const float * values) +{ + Display * display = XOpenDisplay(0); + Atom property = XInternAtom(display, "Coordinate Transformation Matrix", False); + Atom old_type; + int old_format; + unsigned long nitems, bytes_after; + + union { + unsigned char *c; + long *l; + } data; + + XDevice *device = XOpenDevice(display, m_id); + if (XGetDeviceProperty(display, device, property, 0, 0, False, + AnyPropertyType, &old_type, &old_format, &nitems, + &bytes_after, &data.c) == Success) + { + XFree(data.c); + data.c = (unsigned char*)calloc(k_matrix_length, sizeof(long)); + + for (int i = 0; i < k_matrix_length; ++i) + { + kDebug() << "value " << values[i] << " for " << i; + *(float*)(data.l + i) = values[i]; + } + + XChangeDeviceProperty (display, device, property, old_type, + old_format, PropModeReplace, data.c, + k_matrix_length); + XFlush(display); + free(data.c); + } + else + { + kDebug() << "Failed to get device property"; + } + XCloseDevice(display, device); +} + + +#include "orientationjob.moc" diff --git a/dataengines/orientation/orientationjob.h b/dataengines/orientation/orientationjob.h new file mode 100644 index 00000000..98e16ba3 --- /dev/null +++ b/dataengines/orientation/orientationjob.h @@ -0,0 +1,49 @@ +/* + * Copyright 2012 Jeremy Whiting + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * This program 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 General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef ORIENTATION_JOB_H +#define ORIENTATION_JOB_H + +// plasma +#include +#include +#include +#include + +class OrientationJob : public Plasma::ServiceJob +{ + + Q_OBJECT + + public: + OrientationJob(XID id, int reading, const QString &operation, QMap ¶meters, QObject *parent = 0); + ~OrientationJob(); + + Q_SIGNALS: + void dataChanged(int); + + protected: + void start(); + + private: + void set_matrix(const float *value); + XID m_id; + QtMobility::QOrientationReading::Orientation m_prevReading; +}; + +#endif // TASKJOB_H diff --git a/dataengines/orientation/orientationservice.cpp b/dataengines/orientation/orientationservice.cpp new file mode 100644 index 00000000..bc83b59a --- /dev/null +++ b/dataengines/orientation/orientationservice.cpp @@ -0,0 +1,47 @@ +/* + * Copyright 2012 Jeremy Whiting + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2 or + * (at your option) any later version. + * + * This program 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 General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "orientationservice.h" +#include "orientationjob.h" + +OrientationService::OrientationService(XID id, Plasma::DataContainer *source) + : m_id(id), + m_source(source) +{ + setName("orientation"); +} + +Plasma::ServiceJob *OrientationService::createJob(const QString &operation, QMap ¶meters) +{ + Plasma::ServiceJob *sjob = new OrientationJob(m_id, + m_source->data().value("orientation").toInt(), + operation, + parameters, + this); + connect(sjob, SIGNAL(dataChanged(int)), + this, SLOT(onDataChanged(int))); + return sjob; +} + +void OrientationService::onDataChanged(int value) +{ + m_source->setData("orientation", value); +} + +#include "orientationservice.moc" diff --git a/dataengines/orientation/orientationservice.h b/dataengines/orientation/orientationservice.h new file mode 100644 index 00000000..f8fff494 --- /dev/null +++ b/dataengines/orientation/orientationservice.h @@ -0,0 +1,47 @@ +/* + * Copyright 2012 Jeremy Whiting + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2 or + * (at your option) any later version. + * + * This program 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 General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef ORIENTATION_SERVICE_H +#define ORIENTATION_SERVICE_H + +#include "orientationengine.h" + +#include +#include +#include +#include + +class OrientationService : public Plasma::Service +{ + Q_OBJECT + +public: + OrientationService(XID id, Plasma::DataContainer *source); + Plasma::ServiceJob *createJob(const QString &operation, + QMap ¶meters); + +private Q_SLOTS: + void onDataChanged(int value); + +private: + XID m_id; + Plasma::DataContainer *m_source; +}; + +#endif // SEARCHLAUNCH_SERVICE_H diff --git a/dataengines/orientation/plasma-engine-orientation.desktop b/dataengines/orientation/plasma-engine-orientation.desktop new file mode 100644 index 00000000..9c31d6cc --- /dev/null +++ b/dataengines/orientation/plasma-engine-orientation.desktop @@ -0,0 +1,16 @@ +[Desktop Entry] +Name=Orientation +Comment=Adjusts screen orientation +X-KDE-ServiceTypes=Plasma/DataEngine +Type=Service +Icon=transform-rotate +X-KDE-Library=plasma_engine_orientation + +X-KDE-PluginInfo-Author=Jeremy Whiting +X-KDE-PluginInfo-Email=jpwhiting@kde.org +X-KDE-PluginInfo-Name=orientation +X-KDE-PluginInfo-Version=0.1 +X-KDE-PluginInfo-Website=http://kde.org +X-KDE-PluginInfo-Category=Utilities +X-KDE-PluginInfo-Depends= + diff --git a/qmlpackages/contour-tablet-homescreen/contents/config/plasma-default-layoutrc b/qmlpackages/contour-tablet-homescreen/contents/config/plasma-default-layoutrc index 98d9b731..8422a85a 100644 --- a/qmlpackages/contour-tablet-homescreen/contents/config/plasma-default-layoutrc +++ b/qmlpackages/contour-tablet-homescreen/contents/config/plasma-default-layoutrc @@ -1,160 +1,165 @@ [ContainmentDefaults] defaultContainment=org.kde.active.activityscreen [Containments][9] ActionPluginsSource=Global activity= activityId= excludeFromActivities=true desktop=-1 formfactor=2 geometry=0,0,800,32 immutability=1 location=3 plugin=org.kde.active.systemtray screen=-1 [Containments][9][Applets][10] geometry=2,4,28.2857142857143,24 immutability=1 plugin=notifier [Containments][9][Applets][11] geometry=16,4,24,24 immutability=1 plugin=battery [Containments][9][Applets][12] geometry=49,4,24,24 immutability=1 plugin=org.kde.networkmanagement [Containments][9][Applets][13] geometry=60,0,64,48 immutability=1 plugin=org.kde.active.notifications [Containments][9][Applets][14] geometry=90,4,120,24 immutability=1 plugin=org.kde.sharelikeconnect [Containments][9][Applets][15] geometry=120,4,24,24 immutability=1 plugin=digital-clock [Containments][9][Applets][15][Configuration] ShowCalendarPopup=false +[Containments][9][Applets][16] +geometry=70,4,24,24 +immutability=1 +plugin=org.kde.active.orientation + [Containments][9][Applets][17] geometry=145,4,24,24 immutability=1 plugin=org.kde.locationchooser [Containments][9][General] SkipItems=klipper [Containments][20] activity=Introduction FirstStartup=false desktop=-1 formfactor=0 geometry=0,0,800,480 immutability=1 location=1 plugin=org.kde.active.activityscreen screen=0 wallpaperplugin=image wallpaperpluginmode=SingleImage [Containments][20][Applets][25] geometry=0,0,684,572 immutability=1 plugin=org.kde.active.welcome zvalue=0 [Containments][20][General] FirstStartup=false ItemsGeometries=Applet-25:0,0,712,632; [Containments][20][Wallpaper][image] wallpaper=/usr/share/wallpapers/default_wallpaper.png wallpaperposition=2 [Containments][21] activity=Vacation Planning FirstStartup=false desktop=-1 formfactor=0 geometry=0,0,800,480 immutability=1 location=1 plugin=org.kde.active.activityscreen screen=-1 wallpaperplugin=image wallpaperpluginmode=SingleImage [Containments][21][Applets][90] geometry=0,0,506,256 immutability=1 plugin=weather zvalue=0 [Containments][21][Applets][90][Configuration] Share=false pressureUnit=5008 source=wettercom|weather|Berlin, Berlin, DE|DE0001020;Berlin speedUnit=9001 temperatureUnit=6001 updateInterval=30 visibilityUnit=2007 [Containments][21][Applets][91] geometry=0,0,506,414 immutability=1 plugin=plasma_applet_notes zvalue=0 [Containments][21][Applets][91][Configuration] autoSaveHtml=\n\n

Checklist

\n

- pack suitcase

\n

- book tickets

scrollValue=0 [Containments][21][General] ItemsGeometries=Bookmark:7,345,712,158;Applet-90:0,0,553,387;Application:1,474,534,158;Applet-91:714,0,534,474; FirstStartup=false [Containments][21][Wallpaper][image] slideTimer=10 slidepaths=/usr/share/wallpapers/ userswallpapers=/usr/share/wallpapers/CarribeanSunset.jpg wallpaper=/usr/share/wallpapers/CarribeanSunset.jpg wallpapercolor=0,0,0 wallpaperposition=0 [Containments][21][Wallpaper][image] wallpaper=/usr/share/wallpapers/CarribeanSunset.jpg wallpaperposition=2 [Containments][22] activity=My First Activity desktop=-1 formfactor=0 geometry=0,0,800,480 immutability=1 location=1 plugin=org.kde.active.activityscreen screen=-1 wallpaperplugin=image wallpaperpluginmode=SingleImage [Containments][22][General] FirstStartup=false [Containments][22][Wallpaper][image] wallpaper=/usr/share/wallpapers/Orchid.jpg wallpaperposition=2