summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/http.c11
-rw-r--r--src/share-extension.c13
-rw-r--r--src/user_share.c178
3 files changed, 66 insertions, 136 deletions
diff --git a/src/http.c b/src/http.c
index c07a202..71161cd 100644
--- a/src/http.c
+++ b/src/http.c
@@ -26,10 +26,7 @@
#include <glib.h>
#include <glib/gi18n.h>
#include <X11/Xlib.h>
-
-#ifdef HAVE_DBUS_1_1
#include <dbus/dbus.h>
-#endif
#include <gio/gio.h>
@@ -57,9 +54,7 @@
#define GSETTINGS_SCHEMA "org.mate.FileSharing"
-#ifdef HAVE_DBUS_1_1
static char *dbus_session_id;
-#endif
static pid_t httpd_pid = 0;
@@ -94,7 +89,7 @@ get_port (void)
return -1;
}
-#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__APPLE__)
+#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__APPLE__) || defined(__OpenBSD__)
/* XXX This exposes a potential race condition, but without this,
* httpd will not start on the above listed platforms due to the fact
* that SO_REUSEADDR is also needed when Apache binds to the listening
@@ -155,7 +150,6 @@ get_share_name (void)
return name;
}
-#ifdef HAVE_DBUS_1_1
static void
init_dbus() {
/* The only use we make of D-BUS is to fetch the session BUS ID so we can export
@@ -190,7 +184,6 @@ init_dbus() {
dbus_connection_close(connection);
dbus_connection_unref(connection);
}
-#endif
static void
ensure_conf_dir (void)
@@ -470,9 +463,7 @@ http_down (void)
gboolean
http_init (void)
{
-#ifdef HAVE_DBUS_1_1
init_dbus();
-#endif
return TRUE;
}
diff --git a/src/share-extension.c b/src/share-extension.c
index 188c559..b3b2952 100644
--- a/src/share-extension.c
+++ b/src/share-extension.c
@@ -27,10 +27,13 @@
#include <string.h>
#include <glib/gi18n-lib.h>
#include <gtk/gtk.h>
-#include <bluetooth-client.h>
#include <libcaja-extension/caja-menu-provider.h>
#include <libcaja-extension/caja-location-widget-provider.h>
+#ifdef HAVE_BLUETOOTH
+#include <bluetooth-client.h>
+#endif
+
#include "caja-share-bar.h"
#include "user_share-common.h"
@@ -101,6 +104,7 @@ bar_response_cb (CajaShareBar *bar,
}
}
++#ifdef HAVE_BLUETOOTH
static void
downloads_bar_set_from_bluetooth_status (GtkWidget *bar)
{
@@ -121,6 +125,7 @@ default_adapter_powered_cb (GObject *gobject,
{
downloads_bar_set_from_bluetooth_status (bar);
}
+#endif /* HAVE_BLUETOOTH */
static GtkWidget *
caja_user_share_get_location_widget (CajaLocationWidgetProvider *iface,
@@ -163,8 +168,13 @@ caja_user_share_get_location_widget (CajaLocationWidgetProvider *iface,
if (is_dir[0] != FALSE && is_dir[1] != FALSE) {
bar = caja_share_bar_new (_("May be used to share or receive files"));
} else if (is_dir[0] != FALSE) {
+#ifndef HAVE_BLUETOOTH
bar = caja_share_bar_new (_("May be shared over the network or Bluetooth"));
+#else
+ bar = caja_share_bar_new (_("May be shared over the network"));
+#endif /* !HAVE_BLUETOOTH */
} else {
+#ifdef HAVE_BLUETOOTH
BluetoothClient *client;
bar = caja_share_bar_new (_("May be used to receive files over Bluetooth"));
@@ -175,6 +185,7 @@ caja_user_share_get_location_widget (CajaLocationWidgetProvider *iface,
g_signal_connect (G_OBJECT (client), "notify::default-adapter-powered",
G_CALLBACK (default_adapter_powered_cb), bar);
downloads_bar_set_from_bluetooth_status (bar);
+#endif /* HAVE_BLUETOOTH */
}
g_signal_connect (bar, "response",
diff --git a/src/user_share.c b/src/user_share.c
index 53ceec1..d33cd67 100644
--- a/src/user_share.c
+++ b/src/user_share.c
@@ -27,6 +27,7 @@
#include <gtk/gtk.h>
#include <glib/gi18n.h>
#include <glib/gstdio.h>
+#include <gio/gio.h>
#include <X11/Xlib.h>
#include "user_share.h"
@@ -61,14 +62,12 @@ static GSettings* settings;
#define GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD "require-password"
#ifdef HAVE_BLUETOOTH
-/* ConsoleKit */
-#define CK_NAME "org.freedesktop.ConsoleKit"
-#define CK_INTERFACE "org.freedesktop.ConsoleKit"
-#define CK_MANAGER_PATH "/org/freedesktop/ConsoleKit/Manager"
-#define CK_MANAGER_INTERFACE "org.freedesktop.ConsoleKit.Manager"
-#define CK_SEAT_INTERFACE "org.freedesktop.ConsoleKit.Seat"
-#define CK_SESSION_INTERFACE "org.freedesktop.ConsoleKit.Session"
+/* MATE Session */
+#define MATE_SESSION_DBUS_NAME "org.mate.SessionManager"
+#define MATE_SESSION_DBUS_OBJECT "/org/mate/SessionManager"
+#define MATE_SESSION_DBUS_INTERFACE "org.mate.SessionManager"
+static GDBusProxy *session_proxy = NULL;
static gboolean has_console = TRUE;
static BluetoothClient *client = NULL;
@@ -113,136 +112,65 @@ obex_services_shutdown (void)
}
static void
-sessionchanged_cb (void)
+session_properties_changed_cb (GDBusProxy *session,
+ GVariant *changed,
+ char **invalidated,
+ gpointer user_data)
{
- DBusGConnection *dbus_connection;
- DBusGProxy *proxy_ck_manager;
- DBusGProxy *proxy_ck_session;
+ GVariant *v;
- gchar *ck_session_path;
- gboolean is_active = FALSE;
- GError *error = NULL;
+ v = g_variant_lookup_value (changed, "SessionIsActive", G_VARIANT_TYPE_BOOLEAN);
+ if (v) {
+ has_console = g_variant_get_boolean (v);
+ g_debug ("Received session is active change: now %s", has_console ? "active" : "inactive");
- g_message ("Active session changed");
+ if (has_console)
+ obex_services_start ();
+ else
+ obex_services_shutdown ();
- dbus_connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
- if (!dbus_connection) {
- g_warning ("Unable to connect to dbus");
- dbus_g_connection_unref (dbus_connection);
- return;
- }
-
- proxy_ck_manager = dbus_g_proxy_new_for_name (dbus_connection,
- CK_NAME,
- CK_MANAGER_PATH,
- CK_MANAGER_INTERFACE);
- if (dbus_g_proxy_call (proxy_ck_manager, "GetCurrentSession",
- &error, G_TYPE_INVALID,
- DBUS_TYPE_G_OBJECT_PATH, &ck_session_path,
- G_TYPE_INVALID) == FALSE) {
- g_warning ("Couldn't request the name: %s", error->message);
- dbus_g_connection_unref (dbus_connection);
- g_object_unref (proxy_ck_manager);
- g_error_free (error);
- return;
- }
-
- proxy_ck_session = dbus_g_proxy_new_for_name (dbus_connection,
- CK_NAME,
- ck_session_path,
- CK_SESSION_INTERFACE);
-
- if (dbus_g_proxy_call (proxy_ck_session, "IsActive",
- &error, G_TYPE_INVALID,
- G_TYPE_BOOLEAN, &is_active,
- G_TYPE_INVALID) == FALSE) {
-
- g_warning ("Couldn't request the name: %s", error->message);
- dbus_g_connection_unref (dbus_connection);
- g_object_unref (proxy_ck_manager);
- g_object_unref (proxy_ck_session);
- g_error_free (error);
- return;
- }
-
- has_console = is_active;
- if (is_active) {
- obex_services_start ();
- } else {
- obex_services_shutdown ();
+ g_variant_unref (v);
}
+}
- dbus_g_connection_unref (dbus_connection);
- g_free (ck_session_path);
- g_object_unref (proxy_ck_manager);
- g_object_unref (proxy_ck_session);
- if (error != NULL) {
- g_error_free (error);
- }
+static gboolean
+is_session_active (void)
+{
+ GVariant *variant;
+ gboolean is_session_active = FALSE;
+
+ variant = g_dbus_proxy_get_cached_property (session_proxy,
+ "SessionIsActive");
+ if (variant) {
+ is_session_active = g_variant_get_boolean (variant);
+ g_variant_unref (variant);
+ }
+
+ return is_session_active;
}
static void
-consolekit_init (void)
+session_init (void)
{
- DBusGConnection *dbus_connection;
- DBusGProxy *proxy_ck_manager;
- DBusGProxy *proxy_ck_session;
- DBusGProxy *proxy_ck_seat;
- gchar *ck_session_path;
- gchar *ck_seat_path;
GError *error = NULL;
- dbus_connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, NULL);
-
- if (!dbus_connection) {
- g_warning ("Unable to connect to dbus");
- dbus_g_connection_unref (dbus_connection);
- return;
- }
-
- proxy_ck_manager = dbus_g_proxy_new_for_name (dbus_connection,
- CK_NAME,
- CK_MANAGER_PATH,
- CK_MANAGER_INTERFACE);
- if (dbus_g_proxy_call (proxy_ck_manager, "GetCurrentSession",
- &error, G_TYPE_INVALID,
- DBUS_TYPE_G_OBJECT_PATH, &ck_session_path,
- G_TYPE_INVALID) == FALSE) {
-
- g_warning ("Couldn't request the name: %s", error->message);
- g_object_unref (proxy_ck_manager);
- return;
- }
-
- proxy_ck_session = dbus_g_proxy_new_for_name (dbus_connection,
- CK_NAME,
- ck_session_path,
- CK_SESSION_INTERFACE);
- if (dbus_g_proxy_call (proxy_ck_session, "GetSeatId",
- &error, G_TYPE_INVALID,
- DBUS_TYPE_G_OBJECT_PATH, &ck_seat_path,
- G_TYPE_INVALID) == FALSE) {
-
- g_warning ("Couldn't request the name: %s", error->message);
- g_object_unref (proxy_ck_session);
- return;
- }
-
- proxy_ck_seat = dbus_g_proxy_new_for_name (dbus_connection,
- CK_NAME,
- ck_seat_path,
- CK_SEAT_INTERFACE);
- dbus_g_proxy_add_signal (proxy_ck_seat, "ActiveSessionChanged",
- G_TYPE_STRING, G_TYPE_INVALID);
- dbus_g_proxy_connect_signal (proxy_ck_seat, "ActiveSessionChanged",
- G_CALLBACK (sessionchanged_cb), NULL, NULL);
- if (error != NULL) {
- g_error_free (error);
+ session_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
+ G_DBUS_PROXY_FLAGS_NONE,
+ NULL,
+ MATE_SESSION_DBUS_NAME,
+ MATE_SESSION_DBUS_OBJECT,
+ MATE_SESSION_DBUS_INTERFACE,
+ NULL,
+ &error);
+ if (session_proxy == NULL) {
+ g_warning ("Failed to get session proxy: %s", error->message);
+ g_error_free (error);
+ return;
}
- g_object_unref (proxy_ck_manager);
- g_object_unref (proxy_ck_session);
- g_free (ck_seat_path);
- dbus_g_connection_unref (dbus_connection);
+ g_signal_connect (session_proxy, "g-properties-changed",
+ G_CALLBACK (session_properties_changed_cb),
+ NULL);
+ has_console = is_session_active ();
}
static void
@@ -549,7 +477,7 @@ main (int argc, char **argv)
G_CALLBACK (file_sharing_bluetooth_obexpush_notify_changed), NULL);
bluez_init ();
- consolekit_init ();
+ session_init ();
#endif /* HAVE_BLUETOOTH */
/* Initial setting */