I have made the following changes intended for : CE:MW:Shared / contextkit-plugins-nemo
Please review and accept or decline. BOSS has already run some checks on this request. See the "Messages from BOSS" section below. https://build.pub.meego.com//request/show/6815 Thank You, zalevski [This message was auto-generated] --- Request # 6815: Messages from BOSS: State: review at 2012-09-29T10:26:26 by bossbot Reviews: accepted by bossbot : Prechecks succeeded. new for CE-maintainers : Please replace this text with a review and approve/reject the review (not the SR). BOSS will take care of the rest Changes: submit: home:zalevski:branches:CE:MW:Shared / contextkit-plugins-nemo -> CE:MW:Shared / contextkit-plugins-nemo changes files: -------------- --- contextkit-plugins-nemo.changes +++ contextkit-plugins-nemo.changes @@ -0,0 +1,3 @@ +* Sat Sep 29 2012 Denis Zalevskiy <[email protected]> - 0.7.38 +- Generic keyboard plugin + old: ---- contextkit-plugins-nemo-0.7.37.tar.bz2 new: ---- contextkit-plugins-nemo-0.7.38.tar.bz2 spec files: ----------- --- contextkit-plugins-nemo.spec +++ contextkit-plugins-nemo.spec @@ -1,7 +1,7 @@ Name: contextkit-plugins-nemo Summary: ContextKit providers for Nemo Mobile -Version: 0.7.37 -Release: 7 +Version: 0.7.38 +Release: 1 Group: Applications/System License: LGPLv2 URL: https://github.com/nemomobile/contextkit-nemo @@ -41,6 +41,8 @@ %define p_gypsy -n contextkit-plugin-location-gypsy %define p_skyhook -n contextkit-plugin-location-skyhook %define g_location contextkit-plugin-location +%define p_keyboard -n contextkit-plugin-keyboard-generic +%define g_keyboard contextkit-plugin-keyboard %define g_all %{g_bluetooth}, %{g_power}, %{g_session}, %{g_profile}, %{g_internet}, %{g_cellular}, %{g_cellular}, %{g_phone}, %{g_media}, %{g_mce}, %{g_location} @@ -170,6 +172,14 @@ %description %{p_skyhook} %{summary} +%package %{p_keyboard} +Summary: Generic keyboard ContextKit plugin +Group: Applications/System +BuildRequires: pkgconfig(udev) +Provides: %{g_keyboard} +%description %{p_keyboard} +%{summary} + %package tests Summary: Tests for ContextKit plugins License: GPLv2 @@ -278,6 +288,14 @@ %post %{p_skyhook} update-contextkit-providers +%files %{p_keyboard} +%defattr(-,root,root,-) +%{plugins_dir}/keyboard-generic.so +%{context_dir}/keyboard-generic.context + +%post %{p_keyboard} +update-contextkit-providers + %files tests %defattr(-,root,root,-) %{tests_dir}/contextkit-test-bluez @@ -291,3 +309,4 @@ %{tests_dir}/contextkit-test-mce %{tests_dir}/contextkit-test-location-gypsy %{tests_dir}/contextkit-test-location-skyhook +%{tests_dir}/contextkit-test-keyboard-generic other changes: -------------- ++++++ contextkit-plugins-nemo-0.7.37.tar.bz2 -> contextkit-plugins-nemo-0.7.38.tar.bz2 --- CMakeLists.txt +++ CMakeLists.txt @@ -47,6 +47,7 @@ elseif(${PLATFORM} STREQUAL "NEMO_SHARED") add_subdirectory(maemo) add_subdirectory("meego/upower") + add_subdirectory("meego/keyboard-generic") add_subdirectory("meego/cellular") add_subdirectory("meego/connman") add_subdirectory("meego/phone") --- include/cor +++ include/cor +(directory) --- include/cor/udev.hpp +++ include/cor/udev.hpp @@ -0,0 +1,150 @@ +#ifndef _COR_UDEV_HPP_ +#define _COR_UDEV_HPP_ +/* + * Tiny libudev wrapper + * + * Copyright (C) 2012 Jolla Ltd. + * Contact: Denis Zalevskiy <[email protected]> + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + */ + +#include <libudev.h> +#include <stddef.h> + +namespace cor { + +namespace udev { + +class Root +{ +public: + Root() : p(udev_new()) {} + ~Root() + { + if (p) + udev_unref(p); + } + + operator bool() const { return (p != 0); } + + udev_device *mk_device(char const *path) + { + return udev_device_new_from_syspath(p, path); + } + + struct udev_enumerate *mk_enumerate() + { + return udev_enumerate_new(p); + } + +private: + struct udev *p; +}; + + +class Enumerate +{ +public: + Enumerate(Root &root) + : p(root.mk_enumerate()) + {} + + ~Enumerate() + { + if (p) + udev_enumerate_unref(p); + } + + operator bool() const { return (p != 0); } + + void subsystem_add(char const *name) + { + udev_enumerate_add_match_subsystem(p, name); + } + + struct udev_list_entry *devices() + { + udev_enumerate_scan_devices(p); + return udev_enumerate_get_list_entry(p); + } + +private: + struct udev_enumerate *p; +}; + +class ListEntry +{ +public: + ListEntry(Enumerate &e) + : p(e.devices()) {} + + ListEntry(struct udev_list_entry *p) + : p(p) {} + + template <typename T> + void for_each(T const &fn) + { + struct udev_list_entry *entry; + udev_list_entry_foreach(entry, p) { + if (!fn(ListEntry(entry))) + break; + } + } + + char const *path() const + { + return udev_list_entry_get_name(p); + } +private: + struct udev_list_entry *p; +}; + + +class Device +{ +public: + Device(Root &root, char const *path) + : p(root.mk_device(path)) + { } + + operator bool() const { return (p != 0); } + + ~Device() + { + if (!p) + udev_device_unref(p); + } + + char const *attr(char const *name) const + { + return udev_device_get_sysattr_value(p, name); + } + +private: + struct udev_device *p; +}; + +} // namespace udev + +} // namespace cor + +#endif // _COR_UDEV_HPP_ --- maemo/kbslider/CMakeLists.txt +++ maemo/kbslider/CMakeLists.txt @@ -24,6 +24,6 @@ qt4_wrap_cpp(MOC_SRC ${HDRS}) add_ckit_plugin(${PROVIDER} MODULE ${SRC} ${MOC_SRC}) -TARGET_LINK_LIBRARIES(${PROVIDER} common) +TARGET_LINK_LIBRARIES(${PROVIDER} ${UDEV_LIBRARIES} common) install(TARGETS ${PROVIDER} DESTINATION lib/contextkit/subscriber-plugins) --- meego/keyboard-generic +++ meego/keyboard-generic +(directory) --- meego/keyboard-generic/CMakeLists.txt +++ meego/keyboard-generic/CMakeLists.txt @@ -0,0 +1,31 @@ +pkg_check_modules(UDEV libudev) +set(PROVIDER keyboard-generic) +set(INTERFACE internal_keyboard) + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") + +CKIT_GENERATE_CONTEXT(${INTERFACE} ${PROVIDER}) +CKIT_GENERATE_TEST_MAIN(${INTERFACE} ${PROVIDER}) + +include_directories( + ${UDEV_INCLUDE_DIRS} +) + +link_directories( + ${UDEV_LIBRARY_DIRS} +) + +set(SRC + plugin.cpp + ) + +set(HDRS + plugin.hpp + ) + +qt4_wrap_cpp(MOC_SRC ${HDRS}) + +add_ckit_plugin(${PROVIDER} MODULE ${SRC} ${MOC_SRC}) +TARGET_LINK_LIBRARIES(${PROVIDER} ${UDEV_LIBRARIES}) + +install(TARGETS ${PROVIDER} DESTINATION lib/contextkit/subscriber-plugins) --- meego/keyboard-generic/plugin.cpp +++ meego/keyboard-generic/plugin.cpp @@ -0,0 +1,142 @@ +/* + * Generic keyboard properties provider + * + * Copyright (C) 2012 Jolla Ltd. + * Contact: Denis Zalevskiy <[email protected]> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 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 + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html + */ + +#include <contextkit_props/internal_keyboard.hpp> +#include <cor/udev.hpp> +#include "plugin.hpp" + +#include <linux/input.h> + +#include <QString> +#include <QStringList> +#include <QVector> + + +IProviderPlugin* pluginFactory(const QString&) +{ + return new ContextKitNemo::KeyboardGeneric(); +} + +namespace ContextKitNemo +{ + +static bool isKeyboardDevice(cor::udev::Device const &dev) +{ + QString key(dev.attr("capabilities/key")); + QStringList caps_strs(key.split(' ', QString::SkipEmptyParts)); + if (caps_strs.isEmpty()) + return false; + QVector<unsigned long> caps; + foreach(QString const &s, caps_strs) { + unsigned long v; + bool is_ok = false; + v = s.toULong(&is_ok, 16); + if (!is_ok) + return false; + caps.push_back(v); + } + size_t count = 0; + for (unsigned i = KEY_Q; i <= KEY_P; ++i) { + int pos = caps.size() - (i / sizeof(unsigned long)); + if (pos < 0) + break; + size_t bit = i % sizeof(unsigned long); + if ((caps[pos] >> bit) & 1) + ++count; + } + return (count == KEY_P - KEY_Q); +} + +static bool isKeyboardAvailable() +{ + using namespace cor::udev; + Root udev; + if (!udev) + return false; + + Enumerate input(udev); + if (!input) + return false; + + input.subsystem_add("input"); + ListEntry devs(input); + + bool is_kbd_found = false; + auto find_kbd = [&is_kbd_found, &udev](ListEntry const &e) -> bool { + Device d(udev, e.path()); + is_kbd_found = isKeyboardDevice(d); + return !is_kbd_found; + }; + devs.for_each(find_kbd); + return is_kbd_found; +} + +KeyboardGeneric::KeyboardGeneric() +{ + props[keyboard_is_present] = [&]() { + emitChanged(keyboard_is_present, is_kbd_available); + }; + props[keyboard_is_open] = [&]() { + emitChanged(keyboard_is_open, is_kbd_available); + }; + QMetaObject::invokeMethod(this, "ready", Qt::QueuedConnection); +} + +void KeyboardGeneric::setup() +{ + if (!is_setup) { + is_kbd_available = isKeyboardAvailable(); + is_setup = true; + } +} + +void KeyboardGeneric::emitChanged(QString const &name, QVariant const &value) +{ + emit valueChanged(name, value); +} + +/// Implementation of the IPropertyProvider::subscribe. +void KeyboardGeneric::subscribe(QSet<QString> keys) +{ + setup(); + foreach(QString const &k, keys) { + if (props.contains(k)) + props[k](); + } +} + +/// Implementation of the IPropertyProvider::unsubscribe. +void KeyboardGeneric::unsubscribe(QSet<QString>) +{ +} + +void KeyboardGeneric::blockUntilReady() +{ + emit ready(); +} + +void KeyboardGeneric::blockUntilSubscribed(const QString &) +{ +} + +} // namespace --- meego/keyboard-generic/plugin.hpp +++ meego/keyboard-generic/plugin.hpp @@ -0,0 +1,67 @@ +#ifndef _CONTEXTKIT_PLUGIN_KEYBOARD_GENERIC_HPP_ +#define _CONTEXTKIT_PLUGIN_KEYBOARD_GENERIC_HPP_ +/* + * Generic keyboard properties provider + * + * Copyright (C) 2012 Jolla Ltd. + * Contact: Denis Zalevskiy <[email protected]> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 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 + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html + */ + +#include <iproviderplugin.h> + +#include <functional> + +#include <QObject> +#include <QMap> +#include <QSet> + +using ContextSubscriber::IProviderPlugin; + +extern "C" { + IProviderPlugin* pluginFactory(const QString&); +} + +namespace ContextKitNemo +{ + +class KeyboardGeneric : public IProviderPlugin +{ + Q_OBJECT; +public: + KeyboardGeneric(); + virtual ~KeyboardGeneric() {} + + virtual void subscribe(QSet<QString>); + virtual void unsubscribe(QSet<QString>); + virtual void blockUntilReady(); + virtual void blockUntilSubscribed(const QString&); + +private: + void setup(); + void emitChanged(QString const &, QVariant const &); + + QMap<QString, std::function<void ()> > props; + + bool is_setup; + bool is_kbd_available; +}; + +} + +#endif //_CONTEXTKIT_PLUGIN_KEYBOARD_GENERIC_HPP_
