aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2016-03-21 18:15:05 -0500
committerCharles Kerr <charles.kerr@canonical.com>2016-03-21 18:15:05 -0500
commitecf802d7c939fcc73838d19de546294bc1c89e33 (patch)
tree7dd63f36d28630767464858ed2dd17c836930e8f /src
parent1c4f005f0765f460b28808a624fbec7737324b1a (diff)
downloadayatana-indicator-display-ecf802d7c939fcc73838d19de546294bc1c89e33.tar.gz
ayatana-indicator-display-ecf802d7c939fcc73838d19de546294bc1c89e33.tar.bz2
ayatana-indicator-display-ecf802d7c939fcc73838d19de546294bc1c89e33.zip
add Greeter skeleton
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/dbus-names.h7
-rw-r--r--src/greeter.cpp123
-rw-r--r--src/greeter.h47
4 files changed, 178 insertions, 0 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index cdd2384..060071d 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -10,6 +10,7 @@ add_library(
STATIC
adbd-client.cpp
exporter.cpp
+ greeter.cpp
indicator.cpp
rotation-lock.cpp
usb-manager.cpp
diff --git a/src/dbus-names.h b/src/dbus-names.h
index 753b8c8..3127b9f 100644
--- a/src/dbus-names.h
+++ b/src/dbus-names.h
@@ -38,5 +38,12 @@ namespace DBusNames
enum Reason { EXPIRED=1, DISMISSED=2, API=3, UNDEFINED=4 };
}
}
+
+ namespace UnityGreeter
+ {
+ static constexpr char const * NAME = "com.canonical.UnityGreeter";
+ static constexpr char const * PATH = "/";
+ static constexpr char const * INTERFACE = "com.canonical.UnityGreeter";
+ }
}
diff --git a/src/greeter.cpp b/src/greeter.cpp
new file mode 100644
index 0000000..351b870
--- /dev/null
+++ b/src/greeter.cpp
@@ -0,0 +1,123 @@
+/*
+ * Copyright 2016 Canonical Ltd.
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 3, 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 warranties of
+ * MERCHANTABILITY, SATISFACTORY QUALITY, 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, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Charles Kerr <charles.kerr@canonical.com>
+ */
+
+#include <src/dbus-names.h>
+#include <src/greeter.h>
+
+#include <gio/gio.h>
+
+class UnityGreeter::Impl
+{
+public:
+
+ Impl():
+ m_cancellable{g_cancellable_new()}
+ {
+ g_bus_get(G_BUS_TYPE_SESSION, m_cancellable, on_bus_ready_static, this);
+ }
+
+ ~Impl()
+ {
+ g_cancellable_cancel(m_cancellable);
+ g_clear_object(&m_cancellable);
+
+ if (m_subscription_id != 0)
+ g_dbus_connection_signal_unsubscribe (m_bus, m_subscription_id);
+
+ g_clear_object(&m_bus);
+ }
+
+ core::Property<bool>& is_active()
+ {
+ return m_is_active;
+ }
+
+private:
+
+ static void on_bus_ready_static(GObject* /*source*/, GAsyncResult* res, gpointer gself)
+ {
+ GError* error {};
+ auto bus = g_bus_get_finish (res, &error);
+ if (error != nullptr) {
+ if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+ g_warning("UsbSnap: Error getting session bus: %s", error->message);
+ g_clear_error(&error);
+ } else {
+ static_cast<Impl*>(gself)->on_bus_ready(bus);
+ }
+ g_clear_object(&bus);
+ }
+
+ void on_bus_ready(GDBusConnection* bus)
+ {
+ m_bus = G_DBUS_CONNECTION(g_object_ref(G_OBJECT(bus)));
+
+ m_subscription_id = g_dbus_connection_signal_subscribe(m_bus,
+ DBusNames::UnityGreeter::NAME,
+ "org.freedesktop.DBus.Properties",
+ "PropertiesChanged",
+ DBusNames::UnityGreeter::PATH,
+ nullptr,
+ G_DBUS_SIGNAL_FLAGS_NONE,
+ on_properties_changed_signal_static,
+ this,
+ nullptr);
+ }
+
+ static void on_properties_changed_signal_static(GDBusConnection* /*connection*/,
+ const gchar* sender_name,
+ const gchar* object_path,
+ const gchar* interface_name,
+ const gchar* signal_name,
+ GVariant* parameters,
+ gpointer gself)
+ {
+ g_return_if_fail(!g_strcmp0(sender_name, DBusNames::UnityGreeter::NAME));
+ g_return_if_fail(!g_strcmp0(object_path, DBusNames::UnityGreeter::PATH));
+ g_return_if_fail(!g_strcmp0(interface_name, "org.freedesktop.DBus.Properties"));
+ g_return_if_fail(!g_strcmp0(signal_name, "PropertiesChanged"));
+
+ static_cast<Impl*>(gself)->on_properties_changed_signal(parameters);
+ }
+
+ void on_properties_changed_signal(GVariant* parameters)
+ {
+ g_message("%s %s", G_STRLOC, g_variant_print(parameters, true));
+ }
+
+ core::Property<bool> m_is_active;
+ GCancellable* m_cancellable {};
+ GDBusConnection* m_bus {};
+ unsigned int m_subscription_id {};
+};
+
+/***
+****
+***/
+
+Greeter::Greeter() =default;
+
+Greeter::~Greeter() =default;
+
+UnityGreeter::~UnityGreeter() =default;
+
+UnityGreeter::UnityGreeter():
+ impl{new Impl{}}
+{
+}
diff --git a/src/greeter.h b/src/greeter.h
new file mode 100644
index 0000000..e084d25
--- /dev/null
+++ b/src/greeter.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2016 Canonical Ltd.
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 3, 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 warranties of
+ * MERCHANTABILITY, SATISFACTORY QUALITY, 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, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Charles Kerr <charles.kerr@canonical.com>
+ */
+
+#pragma once
+
+#include <core/property.h>
+
+#include <memory>
+#include <string>
+
+class Greeter
+{
+public:
+ Greeter();
+ virtual ~Greeter();
+ virtual core::Property<bool>& is_active() =0;
+};
+
+
+class UnityGreeter: public Greeter
+{
+public:
+ UnityGreeter();
+ virtual ~UnityGreeter();
+ core::Property<bool>& is_active() override;
+
+protected:
+ class Impl;
+ std::unique_ptr<Impl> impl;
+};
+