diff --git a/contourd/CMakeLists.txt b/contourd/CMakeLists.txt index df62768c..bfd0eaca 100644 --- a/contourd/CMakeLists.txt +++ b/contourd/CMakeLists.txt @@ -1,135 +1,160 @@ project(contourd) # This should be REQUIRED once we get rid of the hack below find_package(QtMobility) # build stuff # =============================================================================================== include_directories( ${contour_SOURCE_DIR}/contourd/location ${contour_SOURCE_DIR}/contourd/recommendation ${contour_BINARY_DIR} ${QT_INCLUDES} ${KDE4_INCLUDES} ${NEPOMUK_INCLUDE_DIR} ${SOPRANO_INCLUDE_DIR} #hack to find qt-mobility includes. TODO: get cmake macro ${INCLUDE_INSTALL_DIR}/QtMobility ${INCLUDE_INSTALL_DIR}/QtMobility/QtMobility ${QT_INCLUDE_DIR}/QtMobility ${QT_INCLUDE_DIR}/QtMobility/QtMobility #this uses the cmake macro ${QTMOBILITY_INCLUDE_DIR} ) +configure_file( + config-features.h.cmake + ${CMAKE_CURRENT_BINARY_DIR}/config-features.h +) + add_subdirectory(recommendation/plugins) set(recommendationmanager_SRC recommendation/RecommendationManager.cpp recommendation/RecommendationEngine.cpp recommendation/RecommendationItem.cpp recommendation/RecommendationScriptEngine.cpp recommendation/sensors/dbus/DBusSensor.cpp location/LocationManager.cpp location/network-engines/NetworkNotifier.cpp location/network-engines/dummy/DummyNetworkNotifier.cpp + location/network-engines/connman/ConnmanNetworkNotifier.cpp main.cpp ) qt4_add_dbus_adaptor( recommendationmanager_SRC recommendation/org.kde.contour.RecommendationManager.xml recommendation/RecommendationManager.h Contour::RecommendationManager ) qt4_add_dbus_adaptor( recommendationmanager_SRC location/org.kde.contour.LocationManager.xml location/LocationManager.h Contour::LocationManager ) qt4_add_dbus_adaptor( - recommendationmanager_SRC location/network-engines/dummy/org.kde.contour.LocationManager.DummyNetworkNotifier.xml + recommendationmanager_SRC location/network-engines/dummy/org.kde.LocationManager.DummyNetworkNotifier.xml location/network-engines/dummy/DummyNetworkNotifier.h DummyNetworkNotifier ) +qt4_add_dbus_adaptor( + recommendationmanager_SRC location/network-engines/connman/org.kde.LocationManager.ConnmanNetworkNotifier.xml + location/network-engines/connman/ConnmanNetworkNotifier.h ConnmanNetworkNotifier +) + find_file(kext_onto_src kext.trig PATH_SUFFIXES "ontology/kde" PATHS ${CMAKE_INSTALL_PREFIX}/share ENV XDG_DATA_DIRS) soprano_add_ontology(recommendationmanager_SRC ${kext_onto_src} "KExt" "Nepomuk::Vocabulary" "trig" ) soprano_add_ontology(recommendationmanager_SRC ${SHAREDDESKTOPONTOLOGIES_ROOT_DIR}/nepomuk/nao.trig "NAO" "Nepomuk::Vocabulary" "trig" ) soprano_add_ontology(recommendationmanager_SRC ${SHAREDDESKTOPONTOLOGIES_ROOT_DIR}/nie/nie.trig "NIE" "Nepomuk::Vocabulary" "trig" ) soprano_add_ontology(recommendationmanager_SRC ${SHAREDDESKTOPONTOLOGIES_ROOT_DIR}/nie/nco.trig "NCO" "Nepomuk::Vocabulary" "trig" ) ######################################################################## set(ADDITIONAL_LINK_LIBRARIES) set(recommendationmanager_SRC ${recommendationmanager_SRC} location/network-engines/solid/SolidNetworkNotifier.cpp ) set(ADDITIONAL_LINK_LIBRARIES ${ADDITIONAL_LINK_LIBRARIES} ${KDE4_SOLID_LIBS} ) ######################################################################## kde4_add_executable(contour ${recommendationmanager_SRC} ) target_link_libraries( contour ${QT_QTCORE_LIBRARY} ${QT_QTSCRIPT_LIBRARY} ${KDE4_KDECORE_LIBS} ${KDE4_KIO_LIBS} ${SOPRANO_LIBRARIES} ${NEPOMUK_LIBRARIES} ${NEPOMUK_QUERY_LIBRARIES} ${ADDITIONAL_LINK_LIBRARIES} kworkspace solidcontrol solidcontrolifaces QtLocation QtContacts QtSensors ) install(FILES contour-recommendationengine.desktop DESTINATION ${SERVICETYPES_INSTALL_DIR} ) install(FILES contour-recommendationengine-qtscript.desktop DESTINATION ${SERVICETYPES_INSTALL_DIR} ) install(FILES contour.desktop DESTINATION ${AUTOSTART_INSTALL_DIR} ) -install( - TARGETS contour ${INSTALL_TARGETS_DEFAULT_ARGS} +install(TARGETS + contour + ${INSTALL_TARGETS_DEFAULT_ARGS} ) +message("AAAAAAAA ${DATA_INSTALL_DIR}") + +install(FILES + location/network-engines/connman/org.kde.LocationManager.ConnmanWatcher.py + + DESTINATION + ${DATA_INSTALL_DIR}/locationmanager/ + + PERMISSIONS + OWNER_READ OWNER_WRITE OWNER_EXECUTE + GROUP_READ GROUP_EXECUTE + WORLD_READ WORLD_EXECUTE + ) diff --git a/contourd/config-features.h.cmake b/contourd/config-features.h.cmake new file mode 100644 index 00000000..5db54715 --- /dev/null +++ b/contourd/config-features.h.cmake @@ -0,0 +1,2 @@ +#cmakedefine DATA_INSTALL_DIR "@DATA_INSTALL_DIR@" + diff --git a/contourd/location/network-engines/connman/ConnmanNetworkNotifier.cpp b/contourd/location/network-engines/connman/ConnmanNetworkNotifier.cpp new file mode 100644 index 00000000..b753920c --- /dev/null +++ b/contourd/location/network-engines/connman/ConnmanNetworkNotifier.cpp @@ -0,0 +1,102 @@ +/* + * Copyright (C) 2011 Ivan Cukic + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * or (at your option) any later version, 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 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 "ConnmanNetworkNotifier.h" +#include "connmannetworknotifieradaptor.h" +#include + +#include +#include +#include + +#include + +#define CONNMAN_WATCHER_EXEC DATA_INSTALL_DIR"/locationmanager/org.kde.LocationManager.ConnmanWatcher.py" +// #define CONNMAN_DBUS_ADDRESS "org.moblin.connman" +#define CONNMAN_DBUS_ADDRESS "net.connman" + +REGISTER_NETWORK_NOTIFIER(ConnmanNetworkNotifier) + +class ConnmanNetworkNotifier::Private { +public: + Private() + : watcher(NULL), process(NULL) + {} + + QDBusServiceWatcher * watcher; + QProcess * process; +}; + + +ConnmanNetworkNotifier::ConnmanNetworkNotifier(QObject * parent) + : NetworkNotifier(parent), d(new Private()) +{ +} + +void ConnmanNetworkNotifier::init() +{ + kDebug() << "EXECUTABLE:" << CONNMAN_WATCHER_EXEC; + + // Hmh, connman doesn't show up when registered. Lets hope it will be online + // before the location manager is started + + if (!QDBusConnection::systemBus().interface()->isServiceRegistered(CONNMAN_DBUS_ADDRESS)) { + kDebug() << "Watching for" << CONNMAN_DBUS_ADDRESS << "to arrive"; + + d->watcher = new QDBusServiceWatcher( + CONNMAN_DBUS_ADDRESS, + QDBusConnection::systemBus(), + QDBusServiceWatcher::WatchForRegistration | + QDBusServiceWatcher::WatchForUnregistration | + QDBusServiceWatcher::WatchForOwnerChange, + this + ); + + kDebug() << "Connecting" << + connect(d->watcher, SIGNAL(serviceRegistered(QString)), + this, SLOT(enable())); + } else { + enable(); + + } +} + +void ConnmanNetworkNotifier::enable() +{ + kDebug() << "Starting connman listener"; + + (void) new ConnmanNetworkNotifierAdaptor(this); + QDBusConnection::sessionBus().registerObject( + QLatin1String("/ConnmanInterface"), this); + + d->process = new QProcess(this); + d->process->setProcessChannelMode(QProcess::ForwardedChannels); + d->process->start(CONNMAN_WATCHER_EXEC); +} + +ConnmanNetworkNotifier::~ConnmanNetworkNotifier() +{ + delete d; +} + +void ConnmanNetworkNotifier::setWifiName(const QString & accessPoint) +{ + setActiveAccessPoint(accessPoint); +} + diff --git a/contourd/location/network-engines/dummy/DummyNetworkNotifier.h b/contourd/location/network-engines/connman/ConnmanNetworkNotifier.h similarity index 78% copy from contourd/location/network-engines/dummy/DummyNetworkNotifier.h copy to contourd/location/network-engines/connman/ConnmanNetworkNotifier.h index 7b9c8e76..c46c96c0 100644 --- a/contourd/location/network-engines/dummy/DummyNetworkNotifier.h +++ b/contourd/location/network-engines/connman/ConnmanNetworkNotifier.h @@ -1,48 +1,51 @@ /* * Copyright (C) 2011 Ivan Cukic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, * or (at your option) any later version, 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 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 DUMMY_NETWORK_NOTIFIER_H_ #define DUMMY_NETWORK_NOTIFIER_H_ #include "../NetworkNotifier.h" /** - * DummyNetworkNotifier + * ConnmanNetworkNotifier */ -class DummyNetworkNotifier: public NetworkNotifier { +class ConnmanNetworkNotifier: public NetworkNotifier { Q_OBJECT - Q_CLASSINFO("D-Bus Interface", "org.kde.contour.LocationManager.DummyNetworkNotifier") + Q_CLASSINFO("D-Bus Interface", "org.kde.LocationManager.ConnmanNetworkNotifier") public: - DummyNetworkNotifier(QObject * parent = NULL); - virtual ~DummyNetworkNotifier(); + ConnmanNetworkNotifier(QObject * parent = NULL); + virtual ~ConnmanNetworkNotifier(); public Q_SLOTS: void setWifiName(const QString & accessPoint); +protected Q_SLOTS: + void enable(); + protected: void init(); private: class Private; Private * const d; }; #endif // DUMMYNETWORK_NOTIFIER_H_ diff --git a/contourd/location/network-engines/dummy/org.kde.contour.LocationManager.DummyNetworkNotifier.xml b/contourd/location/network-engines/connman/org.kde.LocationManager.ConnmanNetworkNotifier.xml similarity index 78% copy from contourd/location/network-engines/dummy/org.kde.contour.LocationManager.DummyNetworkNotifier.xml copy to contourd/location/network-engines/connman/org.kde.LocationManager.ConnmanNetworkNotifier.xml index 20de75a5..b3fa23cf 100644 --- a/contourd/location/network-engines/dummy/org.kde.contour.LocationManager.DummyNetworkNotifier.xml +++ b/contourd/location/network-engines/connman/org.kde.LocationManager.ConnmanNetworkNotifier.xml @@ -1,8 +1,8 @@ - + diff --git a/contourd/location/network-engines/connman/watch-connman.py b/contourd/location/network-engines/connman/org.kde.LocationManager.ConnmanWatcher.py similarity index 80% rename from contourd/location/network-engines/connman/watch-connman.py rename to contourd/location/network-engines/connman/org.kde.LocationManager.ConnmanWatcher.py index 401d3b64..8d27e01c 100644 --- a/contourd/location/network-engines/connman/watch-connman.py +++ b/contourd/location/network-engines/connman/org.kde.LocationManager.ConnmanWatcher.py @@ -1,51 +1,51 @@ #!/usr/bin/python # This is a quick and dirty script to monitor when connman # connects to a network, or disconnects from it. -# On those events, it passes the info to the contour daemon +# On those events, it passes the info to the locationmanager daemon # via the dummy network notifier import gobject import dbus import dbus.mainloop.glib dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) bus = dbus.SystemBus() # Getting the main connman object main_obj = bus.get_object('net.connman', '/') props = main_obj.GetProperties(dbus_interface='net.connman.Manager') -def notify_contour(networkName): +def notify_locationmanager(networkName): global bus - contour_obj = bus.get_object('org.kde.LocationManager', '/dummynn') + locationmanager_obj = bus.get_object('org.kde.LocationManager', '/ConnmanInterface') props = main_obj.setWifiName(networkName) def main_obj_propchg(key, value): global bus global main_obj if key == "State": if value == "online" : # searching for active wifi info services = main_obj.GetServices(dbus_interface='net.connman.Manager') for service in services: for part in service: if isinstance(part, dbus.Dictionary): if (part["State"] == "ready"): print("CONNECTED TO:", part["Name"]) - notify_contour(part["Name"]) + notify_locationmanager(part["Name"]) return # we are offline print("OFFLINE") - notify_contour("") + notify_locationmanager("") bus.add_signal_receiver(main_obj_propchg, dbus_interface = "net.connman.Manager", signal_name = "PropertyChanged") loop = gobject.MainLoop() loop.run() diff --git a/contourd/location/network-engines/dummy/DummyNetworkNotifier.h b/contourd/location/network-engines/dummy/DummyNetworkNotifier.h index 7b9c8e76..72d89c6c 100644 --- a/contourd/location/network-engines/dummy/DummyNetworkNotifier.h +++ b/contourd/location/network-engines/dummy/DummyNetworkNotifier.h @@ -1,48 +1,48 @@ /* * Copyright (C) 2011 Ivan Cukic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, * or (at your option) any later version, 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 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 DUMMY_NETWORK_NOTIFIER_H_ -#define DUMMY_NETWORK_NOTIFIER_H_ +#ifndef CONNMAN_NETWORK_NOTIFIER_H_ +#define CONNMAN_NETWORK_NOTIFIER_H_ #include "../NetworkNotifier.h" /** * DummyNetworkNotifier */ class DummyNetworkNotifier: public NetworkNotifier { Q_OBJECT - Q_CLASSINFO("D-Bus Interface", "org.kde.contour.LocationManager.DummyNetworkNotifier") + Q_CLASSINFO("D-Bus Interface", "org.kde.LocationManager.DummyNetworkNotifier") public: DummyNetworkNotifier(QObject * parent = NULL); virtual ~DummyNetworkNotifier(); public Q_SLOTS: void setWifiName(const QString & accessPoint); protected: void init(); private: class Private; Private * const d; }; -#endif // DUMMYNETWORK_NOTIFIER_H_ +#endif // CONNMANNETWORK_NOTIFIER_H_ diff --git a/contourd/location/network-engines/dummy/org.kde.contour.LocationManager.DummyNetworkNotifier.xml b/contourd/location/network-engines/dummy/org.kde.LocationManager.DummyNetworkNotifier.xml similarity index 100% rename from contourd/location/network-engines/dummy/org.kde.contour.LocationManager.DummyNetworkNotifier.xml rename to contourd/location/network-engines/dummy/org.kde.LocationManager.DummyNetworkNotifier.xml