|
Packit |
8fb625 |
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
/*
|
|
Packit |
8fb625 |
* Copyright (C) 2004-2008 Red Hat, Inc.
|
|
Packit |
8fb625 |
* Copyright (C) 2013 Intel Corporation.
|
|
Packit |
8fb625 |
*
|
|
Packit |
8fb625 |
* Nautilus is free software; you can redistribute it and/or
|
|
Packit |
8fb625 |
* modify it under the terms of the GNU General Public License as
|
|
Packit |
8fb625 |
* published by the Free Software Foundation; either version 2 of the
|
|
Packit |
8fb625 |
* License, or (at your option) any later version.
|
|
Packit |
8fb625 |
*
|
|
Packit |
8fb625 |
* Nautilus is distributed in the hope that it will be useful,
|
|
Packit |
8fb625 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
8fb625 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
8fb625 |
* General Public License for more details.
|
|
Packit |
8fb625 |
*
|
|
Packit |
8fb625 |
* You should have received a copy of the GNU General Public License
|
|
Packit |
8fb625 |
* along with this program; if not, write to the Free Software
|
|
Packit |
8fb625 |
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
Packit |
8fb625 |
*
|
|
Packit |
8fb625 |
* Authors: Bastien Nocera <hadess@hadess.net>
|
|
Packit |
8fb625 |
* Authors: Emilio Pozuelo Monfort <emilio.pozuelo@collabora.co.uk>
|
|
Packit |
8fb625 |
*
|
|
Packit |
8fb625 |
*/
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
#include "config.h"
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
#include <glib.h>
|
|
Packit |
8fb625 |
#include <glib/gstdio.h>
|
|
Packit |
8fb625 |
#include <glib/gi18n-lib.h>
|
|
Packit |
8fb625 |
#include <gio/gio.h>
|
|
Packit |
8fb625 |
#include <gtk/gtk.h>
|
|
Packit |
8fb625 |
#include <bluetooth-client.h>
|
|
Packit |
8fb625 |
#include <libnotify/notify.h>
|
|
Packit |
8fb625 |
#include <canberra-gtk.h>
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
#include "bluetooth-settings-obexpush.h"
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
#define MANAGER_SERVICE "org.bluez.obex"
|
|
Packit |
8fb625 |
#define MANAGER_IFACE "org.bluez.obex.AgentManager1"
|
|
Packit |
8fb625 |
#define MANAGER_PATH "/org/bluez/obex"
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
#define AGENT_PATH "/org/gnome/share/agent"
|
|
Packit |
8fb625 |
#define AGENT_IFACE "org.bluez.obex.Agent1"
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
#define TRANSFER_IFACE "org.bluez.obex.Transfer1"
|
|
Packit |
8fb625 |
#define SESSION_IFACE "org.bluez.obex.Session1"
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
static GDBusNodeInfo *introspection_data = NULL;
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
static const gchar introspection_xml[] =
|
|
Packit |
8fb625 |
"<node name='"AGENT_PATH"'>"
|
|
Packit |
8fb625 |
" <interface name='"AGENT_IFACE"'>"
|
|
Packit |
8fb625 |
" <method name='Release'>"
|
|
Packit |
8fb625 |
" </method>"
|
|
Packit |
8fb625 |
" <method name='Cancel'>"
|
|
Packit |
8fb625 |
" </method>"
|
|
Packit |
8fb625 |
" <method name='AuthorizePush'>"
|
|
Packit |
8fb625 |
" <arg name='transfer' type='o' />"
|
|
Packit |
8fb625 |
" <arg name='path' type='s' direction='out' />"
|
|
Packit |
8fb625 |
" </method>"
|
|
Packit |
8fb625 |
" </interface>"
|
|
Packit |
8fb625 |
"</node>";
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
G_DEFINE_TYPE(ObexAgent, obex_agent, G_TYPE_OBJECT)
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
static ObexAgent *agent;
|
|
Packit |
8fb625 |
static BluetoothClient *client;
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
static void
|
|
Packit |
8fb625 |
on_close_notification (NotifyNotification *notification)
|
|
Packit |
8fb625 |
{
|
|
Packit |
8fb625 |
g_object_unref (notification);
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
static void
|
|
Packit |
8fb625 |
notification_launch_action_on_file_cb (NotifyNotification *notification,
|
|
Packit |
8fb625 |
const char *action,
|
|
Packit |
8fb625 |
const char *file_uri)
|
|
Packit |
8fb625 |
{
|
|
Packit |
8fb625 |
g_assert (action != NULL);
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
/* We launch the file viewer for the file */
|
|
Packit |
8fb625 |
if (g_str_equal (action, "display") != FALSE) {
|
|
Packit |
8fb625 |
GdkDisplay *display;
|
|
Packit |
8fb625 |
GAppLaunchContext *ctx;
|
|
Packit |
8fb625 |
GTimeVal val;
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
g_get_current_time (&val;;
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
display = gdk_display_get_default ();
|
|
Packit |
8fb625 |
ctx = G_APP_LAUNCH_CONTEXT (gdk_display_get_app_launch_context (display));
|
|
Packit |
8fb625 |
gdk_app_launch_context_set_timestamp (GDK_APP_LAUNCH_CONTEXT (ctx), val.tv_sec);
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
if (g_app_info_launch_default_for_uri (file_uri, ctx, NULL) == FALSE) {
|
|
Packit |
8fb625 |
g_warning ("Failed to launch the file viewer\n");
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
g_object_unref (ctx);
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
/* we open the Downloads folder */
|
|
Packit |
8fb625 |
if (g_str_equal (action, "reveal") != FALSE) {
|
|
Packit |
8fb625 |
GDBusConnection *connection = agent->connection;
|
|
Packit |
8fb625 |
GVariantBuilder builder;
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
g_variant_builder_init (&builder, G_VARIANT_TYPE ("as"));
|
|
Packit |
8fb625 |
g_variant_builder_add (&builder, "s", file_uri);
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
g_dbus_connection_call (connection,
|
|
Packit |
8fb625 |
"org.freedesktop.FileManager1",
|
|
Packit |
8fb625 |
"/org/freedesktop/FileManager1",
|
|
Packit |
8fb625 |
"org.freedesktop.FileManager1",
|
|
Packit |
8fb625 |
"ShowItems",
|
|
Packit |
8fb625 |
g_variant_new ("(ass)", &builder, ""),
|
|
Packit |
8fb625 |
NULL,
|
|
Packit |
8fb625 |
G_DBUS_CALL_FLAGS_NONE,
|
|
Packit |
8fb625 |
-1,
|
|
Packit |
8fb625 |
NULL,
|
|
Packit |
8fb625 |
NULL,
|
|
Packit |
8fb625 |
NULL);
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
g_variant_builder_clear (&builder);
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
notify_notification_close (notification, NULL);
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
static void
|
|
Packit |
8fb625 |
show_notification (const char *filename)
|
|
Packit |
8fb625 |
{
|
|
Packit |
8fb625 |
char *file_uri, *notification_text, *display, *mime_type;
|
|
Packit |
8fb625 |
NotifyNotification *notification;
|
|
Packit |
8fb625 |
ca_context *ctx;
|
|
Packit |
8fb625 |
GAppInfo *app;
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
file_uri = g_filename_to_uri (filename, NULL, NULL);
|
|
Packit |
8fb625 |
if (file_uri == NULL) {
|
|
Packit |
8fb625 |
g_warning ("Could not make a filename from '%s'", filename);
|
|
Packit |
8fb625 |
return;
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
display = g_filename_display_basename (filename);
|
|
Packit |
8fb625 |
/* Translators: %s is the name of the filename received */
|
|
Packit |
8fb625 |
notification_text = g_strdup_printf(_("You received ā%sā via Bluetooth"), display);
|
|
Packit |
8fb625 |
g_free (display);
|
|
Packit |
8fb625 |
notification = notify_notification_new (_("You received a file"),
|
|
Packit |
8fb625 |
notification_text,
|
|
Packit |
8fb625 |
"bluetooth");
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
notify_notification_set_timeout (notification, NOTIFY_EXPIRES_DEFAULT);
|
|
Packit |
8fb625 |
notify_notification_set_hint_string (notification, "desktop-entry", "gnome-bluetooth-panel");
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
mime_type = g_content_type_guess (filename, NULL, 0, NULL);
|
|
Packit |
8fb625 |
app = g_app_info_get_default_for_type (mime_type, FALSE);
|
|
Packit |
8fb625 |
if (app != NULL) {
|
|
Packit |
8fb625 |
g_object_unref (app);
|
|
Packit |
8fb625 |
notify_notification_add_action (notification, "display", _("Open File"),
|
|
Packit |
8fb625 |
(NotifyActionCallback) notification_launch_action_on_file_cb,
|
|
Packit |
8fb625 |
g_strdup (file_uri), (GFreeFunc) g_free);
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
notify_notification_add_action (notification, "reveal", _("Reveal File"),
|
|
Packit |
8fb625 |
(NotifyActionCallback) notification_launch_action_on_file_cb,
|
|
Packit |
8fb625 |
g_strdup (file_uri), (GFreeFunc) g_free);
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
g_free (file_uri);
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
g_signal_connect (G_OBJECT (notification), "closed", G_CALLBACK (on_close_notification), notification);
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
if (!notify_notification_show (notification, NULL)) {
|
|
Packit |
8fb625 |
g_warning ("failed to send notification\n");
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
g_free (notification_text);
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
/* Now we do the audio notification */
|
|
Packit |
8fb625 |
ctx = ca_gtk_context_get ();
|
|
Packit |
8fb625 |
ca_context_play (ctx, 0,
|
|
Packit |
8fb625 |
CA_PROP_EVENT_ID, "complete-download",
|
|
Packit |
8fb625 |
CA_PROP_EVENT_DESCRIPTION, _("File reception complete"),
|
|
Packit |
8fb625 |
NULL);
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
static void
|
|
Packit |
8fb625 |
reject_transfer (GDBusMethodInvocation *invocation)
|
|
Packit |
8fb625 |
{
|
|
Packit |
8fb625 |
const char *filename;
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
filename = g_object_get_data (G_OBJECT (invocation), "temp-filename");
|
|
Packit |
8fb625 |
g_remove (filename);
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
g_dbus_method_invocation_return_dbus_error (invocation,
|
|
Packit |
8fb625 |
"org.bluez.obex.Error.Rejected", "Not Authorized");
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
static void
|
|
Packit |
8fb625 |
ask_user_transfer_accepted (NotifyNotification *notification,
|
|
Packit |
8fb625 |
char *action,
|
|
Packit |
8fb625 |
GDBusMethodInvocation *invocation)
|
|
Packit |
8fb625 |
{
|
|
Packit |
8fb625 |
gchar *file = g_object_get_data (G_OBJECT (invocation), "temp-filename");
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
g_debug ("Notification: transfer accepted! accepting transfer");
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
g_dbus_method_invocation_return_value (invocation,
|
|
Packit |
8fb625 |
g_variant_new ("(s)", file));
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
static void
|
|
Packit |
8fb625 |
ask_user_transfer_rejected (NotifyNotification *notification,
|
|
Packit |
8fb625 |
char *action,
|
|
Packit |
8fb625 |
GDBusMethodInvocation *invocation)
|
|
Packit |
8fb625 |
{
|
|
Packit |
8fb625 |
g_debug ("Notification: transfer rejected! rejecting transfer");
|
|
Packit |
8fb625 |
reject_transfer (invocation);
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
static void
|
|
Packit |
8fb625 |
ask_user_on_close (NotifyNotification *notification,
|
|
Packit |
8fb625 |
GDBusMethodInvocation *invocation)
|
|
Packit |
8fb625 |
{
|
|
Packit |
8fb625 |
g_debug ("Notification closed! rejecting transfer");
|
|
Packit |
8fb625 |
reject_transfer (invocation);
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
static void
|
|
Packit |
8fb625 |
ask_user (GDBusMethodInvocation *invocation,
|
|
Packit |
8fb625 |
const char *filename,
|
|
Packit |
8fb625 |
const char *name)
|
|
Packit |
8fb625 |
{
|
|
Packit |
8fb625 |
NotifyNotification *notification;
|
|
Packit |
8fb625 |
char *summary, *body;
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
summary = g_strdup_printf(_("Bluetooth file transfer from %s"), name);
|
|
Packit |
8fb625 |
body = g_filename_display_basename (filename);
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
notification = notify_notification_new (summary, body, "bluetooth");
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
notify_notification_set_urgency (notification, NOTIFY_URGENCY_CRITICAL);
|
|
Packit |
8fb625 |
notify_notification_set_timeout (notification, NOTIFY_EXPIRES_NEVER);
|
|
Packit |
8fb625 |
notify_notification_set_hint_string (notification, "desktop-entry",
|
|
Packit |
8fb625 |
"gnome-bluetooth-panel");
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
notify_notification_add_action (notification, "cancel", _("Decline"),
|
|
Packit |
8fb625 |
(NotifyActionCallback) ask_user_transfer_rejected,
|
|
Packit |
8fb625 |
invocation, NULL);
|
|
Packit |
8fb625 |
notify_notification_add_action (notification, "receive", _("Accept"),
|
|
Packit |
8fb625 |
(NotifyActionCallback) ask_user_transfer_accepted,
|
|
Packit |
8fb625 |
invocation, NULL);
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
/* We want to reject the transfer if the user closes the notification
|
|
Packit |
8fb625 |
* without accepting or rejecting it, so we connect to it. However
|
|
Packit |
8fb625 |
* if the user clicks on one of the actions, the callback for the
|
|
Packit |
8fb625 |
* action will be invoked, and then the notification will be closed
|
|
Packit |
8fb625 |
* and the callback for :closed will be called. So we disconnect
|
|
Packit |
8fb625 |
* from :closed if the invocation object goes away (which will happen
|
|
Packit |
8fb625 |
* after the handler of either action accepts or rejects the transfer).
|
|
Packit |
8fb625 |
*/
|
|
Packit |
8fb625 |
g_signal_connect_object (G_OBJECT (notification), "closed",
|
|
Packit |
8fb625 |
G_CALLBACK (ask_user_on_close), invocation, 0);
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
if (!notify_notification_show (notification, NULL))
|
|
Packit |
8fb625 |
g_warning ("failed to send notification\n");
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
g_free (summary);
|
|
Packit |
8fb625 |
g_free (body);
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
static gboolean
|
|
Packit |
8fb625 |
get_paired_for_address (const char *adapter,
|
|
Packit |
8fb625 |
const char *device,
|
|
Packit |
8fb625 |
char **name)
|
|
Packit |
8fb625 |
{
|
|
Packit |
8fb625 |
GtkTreeModel *model;
|
|
Packit |
8fb625 |
GtkTreeIter parent;
|
|
Packit |
8fb625 |
gboolean next;
|
|
Packit |
8fb625 |
gboolean ret = FALSE;
|
|
Packit |
8fb625 |
char *addr;
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
model = bluetooth_client_get_model (client);
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
for (next = gtk_tree_model_get_iter_first (model, &parent);
|
|
Packit |
8fb625 |
next;
|
|
Packit |
8fb625 |
next = gtk_tree_model_iter_next (model, &parent)) {
|
|
Packit |
8fb625 |
gtk_tree_model_get (model, &parent,
|
|
Packit |
8fb625 |
BLUETOOTH_COLUMN_ADDRESS, &addr,
|
|
Packit |
8fb625 |
-1);
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
if (g_strcmp0 (addr, adapter) == 0) {
|
|
Packit |
8fb625 |
GtkTreeIter child;
|
|
Packit |
8fb625 |
char *dev_addr;
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
for (next = gtk_tree_model_iter_children (model, &child, &parent);
|
|
Packit |
8fb625 |
next;
|
|
Packit |
8fb625 |
next = gtk_tree_model_iter_next (model, &child)) {
|
|
Packit |
8fb625 |
gboolean paired;
|
|
Packit |
8fb625 |
char *alias;
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
gtk_tree_model_get (model, &child,
|
|
Packit |
8fb625 |
BLUETOOTH_COLUMN_ADDRESS, &dev_addr,
|
|
Packit |
8fb625 |
BLUETOOTH_COLUMN_PAIRED, &paired,
|
|
Packit |
8fb625 |
BLUETOOTH_COLUMN_ALIAS, &alias,
|
|
Packit |
8fb625 |
-1);
|
|
Packit |
8fb625 |
if (g_strcmp0 (dev_addr, device) == 0) {
|
|
Packit |
8fb625 |
ret = paired;
|
|
Packit |
8fb625 |
*name = alias;
|
|
Packit |
8fb625 |
next = FALSE;
|
|
Packit |
8fb625 |
} else {
|
|
Packit |
8fb625 |
g_free (alias);
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
g_free (dev_addr);
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
g_free (addr);
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
g_object_unref (model);
|
|
Packit |
8fb625 |
return ret;
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
static void
|
|
Packit |
8fb625 |
on_check_bonded_or_ask_session_acquired (GObject *object,
|
|
Packit |
8fb625 |
GAsyncResult *res,
|
|
Packit |
8fb625 |
gpointer user_data)
|
|
Packit |
8fb625 |
{
|
|
Packit |
8fb625 |
GDBusMethodInvocation *invocation = user_data;
|
|
Packit |
8fb625 |
GDBusProxy *session;
|
|
Packit |
8fb625 |
GError *error = NULL;
|
|
Packit |
8fb625 |
GVariant *v;
|
|
Packit |
8fb625 |
char *device, *adapter, *name;
|
|
Packit |
8fb625 |
gboolean paired;
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
session = g_dbus_proxy_new_for_bus_finish (res, &error);
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
if (!session) {
|
|
Packit |
8fb625 |
g_debug ("Failed to create a proxy for the session: %s", error->message);
|
|
Packit |
8fb625 |
g_clear_error (&error);
|
|
Packit |
8fb625 |
goto out;
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
device = NULL;
|
|
Packit |
8fb625 |
adapter = NULL;
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
/* obexd puts the remote device in Destination and our adapter
|
|
Packit |
8fb625 |
* in Source */
|
|
Packit |
8fb625 |
v = g_dbus_proxy_get_cached_property (session, "Destination");
|
|
Packit |
8fb625 |
if (v) {
|
|
Packit |
8fb625 |
device = g_variant_dup_string (v, NULL);
|
|
Packit |
8fb625 |
g_variant_unref (v);
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
v = g_dbus_proxy_get_cached_property (session, "Source");
|
|
Packit |
8fb625 |
if (v) {
|
|
Packit |
8fb625 |
adapter = g_variant_dup_string (v, NULL);
|
|
Packit |
8fb625 |
g_variant_unref (v);
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
g_object_unref (session);
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
if (!device || !adapter) {
|
|
Packit |
8fb625 |
g_debug ("Could not get remote device for the transfer");
|
|
Packit |
8fb625 |
g_free (device);
|
|
Packit |
8fb625 |
g_free (adapter);
|
|
Packit |
8fb625 |
goto out;
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
name = NULL;
|
|
Packit |
8fb625 |
paired = get_paired_for_address (adapter, device, &name);
|
|
Packit |
8fb625 |
g_free (device);
|
|
Packit |
8fb625 |
g_free (adapter);
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
if (paired) {
|
|
Packit |
8fb625 |
g_debug ("Remote device '%s' is paired, auto-accepting the transfer", name);
|
|
Packit |
8fb625 |
g_dbus_method_invocation_return_value (invocation,
|
|
Packit |
8fb625 |
g_variant_new ("(s)", g_object_get_data (G_OBJECT (invocation), "temp-filename")));
|
|
Packit |
8fb625 |
g_free (name);
|
|
Packit |
8fb625 |
return;
|
|
Packit |
8fb625 |
} else {
|
|
Packit |
8fb625 |
ask_user (invocation,
|
|
Packit |
8fb625 |
g_object_get_data (G_OBJECT (invocation), "filename"),
|
|
Packit |
8fb625 |
name ? name : device);
|
|
Packit |
8fb625 |
g_free (name);
|
|
Packit |
8fb625 |
return;
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
out:
|
|
Packit |
8fb625 |
g_debug ("Rejecting transfer");
|
|
Packit |
8fb625 |
reject_transfer (invocation);
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
static void
|
|
Packit |
8fb625 |
check_if_bonded_or_ask (GDBusProxy *transfer,
|
|
Packit |
8fb625 |
GDBusMethodInvocation *invocation)
|
|
Packit |
8fb625 |
{
|
|
Packit |
8fb625 |
GVariant *v;
|
|
Packit |
8fb625 |
const gchar *session = NULL;
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
v = g_dbus_proxy_get_cached_property (transfer, "Session");
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
if (v) {
|
|
Packit |
8fb625 |
session = g_variant_get_string (v, NULL);
|
|
Packit |
8fb625 |
g_dbus_proxy_new_for_bus (G_BUS_TYPE_SESSION,
|
|
Packit |
8fb625 |
G_DBUS_PROXY_FLAGS_NONE,
|
|
Packit |
8fb625 |
NULL,
|
|
Packit |
8fb625 |
MANAGER_SERVICE,
|
|
Packit |
8fb625 |
session,
|
|
Packit |
8fb625 |
SESSION_IFACE,
|
|
Packit |
8fb625 |
NULL,
|
|
Packit |
8fb625 |
on_check_bonded_or_ask_session_acquired,
|
|
Packit |
8fb625 |
invocation);
|
|
Packit |
8fb625 |
g_variant_unref (v);
|
|
Packit |
8fb625 |
} else {
|
|
Packit |
8fb625 |
g_debug ("Could not get session path for the transfer, "
|
|
Packit |
8fb625 |
"rejecting the transfer");
|
|
Packit |
8fb625 |
reject_transfer (invocation);
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
static void
|
|
Packit |
8fb625 |
obex_agent_release (GError **error)
|
|
Packit |
8fb625 |
{
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
static void
|
|
Packit |
8fb625 |
obex_agent_cancel (GError **error)
|
|
Packit |
8fb625 |
{
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
/* From the old embed/mozilla/MozDownload.cpp */
|
|
Packit |
8fb625 |
static const char*
|
|
Packit |
8fb625 |
file_is_compressed (const char *filename)
|
|
Packit |
8fb625 |
{
|
|
Packit |
8fb625 |
int i;
|
|
Packit |
8fb625 |
static const char * const compression[] = {".gz", ".bz2", ".Z", ".lz", ".xz", NULL};
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
for (i = 0; compression[i] != NULL; i++) {
|
|
Packit |
8fb625 |
if (g_str_has_suffix (filename, compression[i]))
|
|
Packit |
8fb625 |
return compression[i];
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
return NULL;
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
static const char*
|
|
Packit |
8fb625 |
parse_extension (const char *filename)
|
|
Packit |
8fb625 |
{
|
|
Packit |
8fb625 |
const char *compression;
|
|
Packit |
8fb625 |
const char *last_separator;
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
compression = file_is_compressed (filename);
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
/* if the file is compressed we might have a double extension */
|
|
Packit |
8fb625 |
if (compression != NULL) {
|
|
Packit |
8fb625 |
int i;
|
|
Packit |
8fb625 |
static const char * const extensions[] = {"tar", "ps", "xcf", "dvi", "txt", "text", NULL};
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
for (i = 0; extensions[i] != NULL; i++) {
|
|
Packit |
8fb625 |
char *suffix;
|
|
Packit |
8fb625 |
suffix = g_strdup_printf (".%s%s", extensions[i], compression);
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
if (g_str_has_suffix (filename, suffix)) {
|
|
Packit |
8fb625 |
char *p;
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
p = g_strrstr (filename, suffix);
|
|
Packit |
8fb625 |
g_free (suffix);
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
return p;
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
g_free (suffix);
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
/* no compression, just look for the last dot in the filename */
|
|
Packit |
8fb625 |
last_separator = strrchr (filename, G_DIR_SEPARATOR);
|
|
Packit |
8fb625 |
return strrchr ((last_separator) ? last_separator : filename, '.');
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
char *
|
|
Packit |
8fb625 |
lookup_download_dir (void)
|
|
Packit |
8fb625 |
{
|
|
Packit |
8fb625 |
const char *special_dir;
|
|
Packit |
8fb625 |
char *dir;
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
special_dir = g_get_user_special_dir (G_USER_DIRECTORY_DOWNLOAD);
|
|
Packit |
8fb625 |
if (special_dir != NULL && strcmp (special_dir, g_get_home_dir ()) != 0) {
|
|
Packit |
8fb625 |
g_mkdir_with_parents (special_dir, 0755);
|
|
Packit |
8fb625 |
return g_strdup (special_dir);
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
dir = g_build_filename (g_get_home_dir (), "Downloads", NULL);
|
|
Packit |
8fb625 |
g_mkdir_with_parents (dir, 0755);
|
|
Packit |
8fb625 |
return dir;
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
static char *
|
|
Packit |
8fb625 |
move_temp_filename (GObject *object)
|
|
Packit |
8fb625 |
{
|
|
Packit |
8fb625 |
const char *orig_filename;
|
|
Packit |
8fb625 |
char *dest_filename, *dest_dir;
|
|
Packit |
8fb625 |
GFile *src, *dest;
|
|
Packit |
8fb625 |
GError *error = NULL;
|
|
Packit |
8fb625 |
gboolean res;
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
orig_filename = g_object_get_data (object, "temp-filename");
|
|
Packit |
8fb625 |
src = g_file_new_for_path (orig_filename);
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
dest_dir = lookup_download_dir ();
|
|
Packit |
8fb625 |
dest_filename = g_build_filename (dest_dir, g_object_get_data (object, "filename"), NULL);
|
|
Packit |
8fb625 |
g_free (dest_dir);
|
|
Packit |
8fb625 |
dest = g_file_new_for_path (dest_filename);
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
res = g_file_move (src, dest,
|
|
Packit |
8fb625 |
G_FILE_COPY_NONE, NULL,
|
|
Packit |
8fb625 |
NULL, NULL, &error);
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
/* This is sync, but the files will be on the same partition already
|
|
Packit |
8fb625 |
* (~/.cache/obexd to ~/Downloads) */
|
|
Packit |
8fb625 |
if (!res && g_error_matches (error, G_IO_ERROR, G_IO_ERROR_EXISTS)) {
|
|
Packit |
8fb625 |
guint i = 1;
|
|
Packit |
8fb625 |
const char *dot_pos;
|
|
Packit |
8fb625 |
gssize position;
|
|
Packit |
8fb625 |
char *serial = NULL;
|
|
Packit |
8fb625 |
GString *tmp_filename;
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
dot_pos = parse_extension (dest_filename);
|
|
Packit |
8fb625 |
if (dot_pos)
|
|
Packit |
8fb625 |
position = dot_pos - dest_filename;
|
|
Packit |
8fb625 |
else
|
|
Packit |
8fb625 |
position = strlen (dest_filename);
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
tmp_filename = g_string_new (NULL);
|
|
Packit |
8fb625 |
g_string_assign (tmp_filename, dest_filename);
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
while (!res && g_error_matches (error, G_IO_ERROR, G_IO_ERROR_EXISTS)) {
|
|
Packit |
8fb625 |
g_debug ("Couldn't move file to %s", tmp_filename->str);
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
g_clear_error (&error);
|
|
Packit |
8fb625 |
g_object_unref (dest);
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
serial = g_strdup_printf ("(%d)", i++);
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
g_string_assign (tmp_filename, dest_filename);
|
|
Packit |
8fb625 |
g_string_insert (tmp_filename, position, serial);
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
g_free (serial);
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
dest = g_file_new_for_path (tmp_filename->str);
|
|
Packit |
8fb625 |
res = g_file_move (src, dest,
|
|
Packit |
8fb625 |
G_FILE_COPY_NONE, NULL,
|
|
Packit |
8fb625 |
NULL, NULL, &error);
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
g_free (dest_filename);
|
|
Packit |
8fb625 |
dest_filename = g_strdup (tmp_filename->str);
|
|
Packit |
8fb625 |
g_string_free (tmp_filename, TRUE);
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
if (!res) {
|
|
Packit |
8fb625 |
g_warning ("Failed to move %s to %s: '%s'",
|
|
Packit |
8fb625 |
orig_filename, dest_filename, error->message);
|
|
Packit |
8fb625 |
g_error_free (error);
|
|
Packit |
8fb625 |
} else {
|
|
Packit |
8fb625 |
g_debug ("Moved %s (orig name %s) to %s",
|
|
Packit |
8fb625 |
orig_filename, (char *) g_object_get_data (object, "filename"), dest_filename);
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
g_object_unref (src);
|
|
Packit |
8fb625 |
g_object_unref (dest);
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
return dest_filename;
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
static void
|
|
Packit |
8fb625 |
transfer_property_changed (GDBusProxy *transfer,
|
|
Packit |
8fb625 |
GVariant *changed_properties,
|
|
Packit |
8fb625 |
GStrv invalidated_properties,
|
|
Packit |
8fb625 |
gpointer user_data)
|
|
Packit |
8fb625 |
{
|
|
Packit |
8fb625 |
GVariantIter iter;
|
|
Packit |
8fb625 |
const gchar *key;
|
|
Packit |
8fb625 |
GVariant *value;
|
|
Packit |
8fb625 |
const char *filename;
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
g_debug ("Calling transfer_property_changed()");
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
filename = g_object_get_data (G_OBJECT (transfer), "filename");
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
g_variant_iter_init (&iter, changed_properties);
|
|
Packit |
8fb625 |
while (g_variant_iter_next (&iter, "{&sv}", &key, &value)) {
|
|
Packit |
8fb625 |
char *str = g_variant_print (value, TRUE);
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
if (g_str_equal (key, "Status")) {
|
|
Packit |
8fb625 |
const gchar *status;
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
status = g_variant_get_string (value, NULL);
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
g_debug ("Got status %s = %s for filename %s", status, str, filename);
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
if (g_str_equal (status, "complete")) {
|
|
Packit |
8fb625 |
char *path;
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
path = move_temp_filename (G_OBJECT (transfer));
|
|
Packit |
8fb625 |
g_debug ("transfer completed, showing a notification");
|
|
Packit |
8fb625 |
show_notification (path);
|
|
Packit |
8fb625 |
g_free (path);
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
/* Done with this transfer */
|
|
Packit |
8fb625 |
if (g_str_equal (status, "complete") ||
|
|
Packit |
8fb625 |
g_str_equal (status, "error")) {
|
|
Packit |
8fb625 |
g_object_unref (transfer);
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
} else {
|
|
Packit |
8fb625 |
g_debug ("Unhandled property changed %s = %s for filename %s", key, str, filename);
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
g_free (str);
|
|
Packit |
8fb625 |
g_variant_unref (value);
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
static void
|
|
Packit |
8fb625 |
obex_agent_authorize_push (GObject *source_object,
|
|
Packit |
8fb625 |
GAsyncResult *res,
|
|
Packit |
8fb625 |
gpointer user_data)
|
|
Packit |
8fb625 |
{
|
|
Packit |
8fb625 |
GDBusProxy *transfer = g_dbus_proxy_new_for_bus_finish (res, NULL);
|
|
Packit |
8fb625 |
GDBusMethodInvocation *invocation = user_data;
|
|
Packit |
8fb625 |
GVariant *variant = g_dbus_proxy_get_cached_property (transfer, "Name");
|
|
Packit |
8fb625 |
const gchar *filename = g_variant_get_string (variant, NULL);
|
|
Packit |
8fb625 |
char *template;
|
|
Packit |
8fb625 |
int fd;
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
g_debug ("AuthorizePush received");
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
template = g_build_filename (g_get_user_cache_dir (), "obexd", "XXXXXX", NULL);
|
|
Packit |
8fb625 |
fd = g_mkstemp (template);
|
|
Packit |
8fb625 |
close (fd);
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
g_object_set_data_full (G_OBJECT (transfer), "filename", g_strdup (filename), g_free);
|
|
Packit |
8fb625 |
g_object_set_data_full (G_OBJECT (transfer), "temp-filename", g_strdup (template), g_free);
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
g_object_set_data_full (G_OBJECT (invocation), "filename", g_strdup (filename), g_free);
|
|
Packit |
8fb625 |
g_object_set_data_full (G_OBJECT (invocation), "temp-filename", g_strdup (template), g_free);
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
g_signal_connect (transfer, "g-properties-changed",
|
|
Packit |
8fb625 |
G_CALLBACK (transfer_property_changed), NULL);
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
/* check_if_bonded_or_ask() will accept or reject the transfer */
|
|
Packit |
8fb625 |
check_if_bonded_or_ask (transfer, invocation);
|
|
Packit |
8fb625 |
g_variant_unref (variant);
|
|
Packit |
8fb625 |
g_free (template);
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
static void
|
|
Packit |
8fb625 |
handle_method_call (GDBusConnection *connection,
|
|
Packit |
8fb625 |
const gchar *sender,
|
|
Packit |
8fb625 |
const gchar *object_path,
|
|
Packit |
8fb625 |
const gchar *interface_name,
|
|
Packit |
8fb625 |
const gchar *method_name,
|
|
Packit |
8fb625 |
GVariant *parameters,
|
|
Packit |
8fb625 |
GDBusMethodInvocation *invocation,
|
|
Packit |
8fb625 |
gpointer user_data)
|
|
Packit |
8fb625 |
{
|
|
Packit |
8fb625 |
if (g_str_equal (method_name, "Cancel")) {
|
|
Packit |
8fb625 |
obex_agent_cancel (NULL);
|
|
Packit |
8fb625 |
g_dbus_method_invocation_return_value (invocation, NULL);
|
|
Packit |
8fb625 |
} else if (g_str_equal (method_name, "Release")) {
|
|
Packit |
8fb625 |
obex_agent_release (NULL);
|
|
Packit |
8fb625 |
g_dbus_method_invocation_return_value (invocation, NULL);
|
|
Packit |
8fb625 |
} else if (g_str_equal (method_name, "AuthorizePush")) {
|
|
Packit |
8fb625 |
const gchar *transfer;
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
g_variant_get (parameters, "(&o)", &transfer);
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
g_dbus_proxy_new_for_bus (G_BUS_TYPE_SESSION,
|
|
Packit |
8fb625 |
G_DBUS_PROXY_FLAGS_NONE,
|
|
Packit |
8fb625 |
NULL,
|
|
Packit |
8fb625 |
MANAGER_SERVICE,
|
|
Packit |
8fb625 |
transfer,
|
|
Packit |
8fb625 |
TRANSFER_IFACE,
|
|
Packit |
8fb625 |
NULL,
|
|
Packit |
8fb625 |
obex_agent_authorize_push,
|
|
Packit |
8fb625 |
invocation);
|
|
Packit |
8fb625 |
} else {
|
|
Packit |
8fb625 |
g_warning ("Unknown method name or unknown parameters: %s",
|
|
Packit |
8fb625 |
method_name);
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
static const GDBusInterfaceVTable interface_vtable =
|
|
Packit |
8fb625 |
{
|
|
Packit |
8fb625 |
handle_method_call,
|
|
Packit |
8fb625 |
NULL,
|
|
Packit |
8fb625 |
NULL
|
|
Packit |
8fb625 |
};
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
static void
|
|
Packit |
8fb625 |
obexd_appeared_cb (GDBusConnection *connection,
|
|
Packit |
8fb625 |
const gchar *name,
|
|
Packit |
8fb625 |
const gchar *name_owner,
|
|
Packit |
8fb625 |
gpointer user_data)
|
|
Packit |
8fb625 |
{
|
|
Packit |
8fb625 |
ObexAgent *self = user_data;
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
g_debug ("obexd appeared, registering agent");
|
|
Packit |
8fb625 |
g_dbus_connection_call (self->connection,
|
|
Packit |
8fb625 |
MANAGER_SERVICE,
|
|
Packit |
8fb625 |
MANAGER_PATH,
|
|
Packit |
8fb625 |
MANAGER_IFACE,
|
|
Packit |
8fb625 |
"RegisterAgent",
|
|
Packit |
8fb625 |
g_variant_new ("(o)", AGENT_PATH),
|
|
Packit |
8fb625 |
NULL,
|
|
Packit |
8fb625 |
G_DBUS_CALL_FLAGS_NONE,
|
|
Packit |
8fb625 |
-1,
|
|
Packit |
8fb625 |
NULL,
|
|
Packit |
8fb625 |
NULL,
|
|
Packit |
8fb625 |
NULL);
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
static void
|
|
Packit |
8fb625 |
on_bus_acquired (GDBusConnection *connection,
|
|
Packit |
8fb625 |
const gchar *name,
|
|
Packit |
8fb625 |
gpointer user_data)
|
|
Packit |
8fb625 |
{
|
|
Packit |
8fb625 |
ObexAgent *self = user_data;
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
/* parse introspection data */
|
|
Packit |
8fb625 |
introspection_data = g_dbus_node_info_new_for_xml (introspection_xml,
|
|
Packit |
8fb625 |
NULL);
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
self->connection = connection;
|
|
Packit |
8fb625 |
self->object_reg_id = g_dbus_connection_register_object (connection,
|
|
Packit |
8fb625 |
AGENT_PATH,
|
|
Packit |
8fb625 |
introspection_data->interfaces[0],
|
|
Packit |
8fb625 |
&interface_vtable,
|
|
Packit |
8fb625 |
NULL, /* user_data */
|
|
Packit |
8fb625 |
NULL, /* user_data_free_func */
|
|
Packit |
8fb625 |
NULL); /* GError** */
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
g_dbus_node_info_unref (introspection_data);
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
g_assert (self->object_reg_id > 0);
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
self->obexd_watch_id = g_bus_watch_name_on_connection (self->connection,
|
|
Packit |
8fb625 |
MANAGER_SERVICE,
|
|
Packit |
8fb625 |
G_BUS_NAME_WATCHER_FLAGS_AUTO_START,
|
|
Packit |
8fb625 |
obexd_appeared_cb,
|
|
Packit |
8fb625 |
NULL,
|
|
Packit |
8fb625 |
self,
|
|
Packit |
8fb625 |
NULL);
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
static void
|
|
Packit |
8fb625 |
obex_agent_init (ObexAgent *self)
|
|
Packit |
8fb625 |
{
|
|
Packit |
8fb625 |
self->owner_id = g_bus_own_name (G_BUS_TYPE_SESSION,
|
|
Packit |
8fb625 |
AGENT_IFACE,
|
|
Packit |
8fb625 |
G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT,
|
|
Packit |
8fb625 |
on_bus_acquired,
|
|
Packit |
8fb625 |
NULL,
|
|
Packit |
8fb625 |
NULL,
|
|
Packit |
8fb625 |
self,
|
|
Packit |
8fb625 |
NULL);
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
client = bluetooth_client_new ();
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
static void
|
|
Packit |
8fb625 |
obex_agent_dispose (GObject *obj)
|
|
Packit |
8fb625 |
{
|
|
Packit |
8fb625 |
ObexAgent *self = OBEX_AGENT (obj);
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
g_dbus_connection_unregister_object (self->connection, self->object_reg_id);
|
|
Packit |
8fb625 |
self->object_reg_id = 0;
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
g_bus_unown_name (self->owner_id);
|
|
Packit |
8fb625 |
self->owner_id = 0;
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
g_bus_unwatch_name (self->obexd_watch_id);
|
|
Packit |
8fb625 |
self->obexd_watch_id = 0;
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
g_clear_object (&client);
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
G_OBJECT_CLASS (obex_agent_parent_class)->dispose (obj);
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
static void
|
|
Packit |
8fb625 |
obex_agent_class_init (ObexAgentClass *klass)
|
|
Packit |
8fb625 |
{
|
|
Packit |
8fb625 |
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
gobject_class->dispose = obex_agent_dispose;
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
static ObexAgent *
|
|
Packit |
8fb625 |
obex_agent_new (void)
|
|
Packit |
8fb625 |
{
|
|
Packit |
8fb625 |
return (ObexAgent *) g_object_new (OBEX_AGENT_TYPE, NULL);
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
void
|
|
Packit |
8fb625 |
obex_agent_down (void)
|
|
Packit |
8fb625 |
{
|
|
Packit |
8fb625 |
if (agent != NULL) {
|
|
Packit |
8fb625 |
g_dbus_connection_call (agent->connection,
|
|
Packit |
8fb625 |
MANAGER_SERVICE,
|
|
Packit |
8fb625 |
MANAGER_PATH,
|
|
Packit |
8fb625 |
MANAGER_IFACE,
|
|
Packit |
8fb625 |
"UnregisterAgent",
|
|
Packit |
8fb625 |
g_variant_new ("(o)", AGENT_PATH),
|
|
Packit |
8fb625 |
NULL,
|
|
Packit |
8fb625 |
G_DBUS_CALL_FLAGS_NONE,
|
|
Packit |
8fb625 |
-1,
|
|
Packit |
8fb625 |
NULL,
|
|
Packit |
8fb625 |
NULL,
|
|
Packit |
8fb625 |
NULL);
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
g_clear_object (&agent);
|
|
Packit |
8fb625 |
g_clear_object (&client);
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
void
|
|
Packit |
8fb625 |
obex_agent_up (void)
|
|
Packit |
8fb625 |
{
|
|
Packit |
8fb625 |
if (agent == NULL)
|
|
Packit |
8fb625 |
agent = obex_agent_new ();
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
if (!notify_init ("gnome-bluetooth")) {
|
|
Packit |
8fb625 |
g_warning("Unable to initialize the notification system");
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
}
|