00001 /* 00002 * Copyright (C) 2008 Nokia Corporation. 00003 * 00004 * Contact: Marius Vollmer <marius.vollmer@nokia.com> 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public License 00008 * version 2.1 as published by the Free Software Foundation. 00009 * 00010 * This library is distributed in the hope that it will be useful, but 00011 * WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Lesser General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Lesser General Public 00016 * License along with this library; if not, write to the Free Software 00017 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 00018 * 02110-1301 USA 00019 * 00020 */ 00021 00022 #ifndef DBUSNAMELISTENER_H 00023 #define DBUSNAMELISTENER_H 00024 00025 #include <QObject> 00026 #include <QString> 00027 #include <QDBusConnection> 00028 #include <QDBusServiceWatcher> 00029 00030 class QDBusPendingCallWatcher; 00031 00032 namespace ContextSubscriber { 00033 00034 class DBusNameListener : public QDBusServiceWatcher 00035 { 00036 Q_OBJECT 00037 public: 00038 enum ServicePresence {NotPresent = 0, Present, Unknown}; 00039 00040 explicit DBusNameListener(QDBusConnection::BusType busType, const QString &busName, QObject *parent = 0); 00041 explicit DBusNameListener(const QDBusConnection bus, const QString &busName, QObject *parent = 0); 00042 virtual ~DBusNameListener(); 00043 00044 void startListening(bool nameHasOwnerCheck); 00045 00046 ServicePresence isServicePresent() const; 00047 00048 private Q_SLOTS: 00049 void onNameHasOwnerFinished(QDBusPendingCallWatcher* watcher); 00050 void setServicePresent(); 00051 void setServiceGone(); 00052 00053 private: 00054 void init(); 00055 ServicePresence servicePresent; 00056 QDBusConnection::BusType busType; 00057 QString busName; 00058 bool listeningStarted; 00059 QDBusConnection* connection; 00060 00061 Q_SIGNALS: 00062 void nameAppeared(); 00063 void nameDisappeared(); 00064 }; 00065 00066 } // end namespace 00067 00068 #endif