1
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4
* Copyright (C) 2004-2008 Red Hat, Inc.
6
* Nautilus is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License as
8
* published by the Free Software Foundation; either version 2 of the
9
* License, or (at your option) any later version.
11
* Nautilus is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
* Authors: Bastien Nocera <hadess@hadess.net>
26
#include <dbus/dbus-glib.h>
27
#include <dbus/dbus-glib-lowlevel.h>
28
#include <gconf/gconf-client.h>
33
#include "user_share.h"
34
#include "user_share-private.h"
36
static DBusGConnection *connection = NULL;
37
static DBusGProxy *manager_proxy = NULL;
38
static DBusGProxy *server_proxy = NULL;
45
char *public_dir, *server;
46
gboolean allow_write, require_pairing;
48
client = gconf_client_get_default ();
49
require_pairing = gconf_client_get_bool (client, FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING, NULL);
52
if (manager_proxy == NULL) {
53
manager_proxy = dbus_g_proxy_new_for_name (connection,
56
"org.openobex.Manager");
57
if (dbus_g_proxy_call (manager_proxy, "CreateBluetoothServer",
58
&err, G_TYPE_STRING, "00:00:00:00:00:00", G_TYPE_STRING, "ftp", G_TYPE_BOOLEAN, require_pairing, G_TYPE_INVALID,
59
DBUS_TYPE_G_OBJECT_PATH, &server, G_TYPE_INVALID) == FALSE) {
60
g_printerr ("Creating Bluetooth ObexFTP server failed: %s\n",
63
g_object_unref (manager_proxy);
69
public_dir = lookup_public_dir ();
70
allow_write = gconf_client_get_bool (client, FILE_SHARING_BLUETOOTH_ALLOW_WRITE, NULL);
71
g_object_unref (client);
73
if (server_proxy == NULL) {
74
server_proxy = dbus_g_proxy_new_for_name (connection,
77
"org.openobex.Server");
80
if (dbus_g_proxy_call (server_proxy, "Start", &err,
81
G_TYPE_STRING, public_dir, G_TYPE_BOOLEAN, allow_write, G_TYPE_BOOLEAN, TRUE, G_TYPE_INVALID,
82
G_TYPE_INVALID) == FALSE) {
83
g_printerr ("Starting Bluetooth ObexFTP server failed: %s\n",
87
g_object_unref (server_proxy);
89
g_object_unref (manager_proxy);
98
obexftp_stop (gboolean stop_manager)
102
if (server_proxy == NULL)
105
if (dbus_g_proxy_call (server_proxy, "Close", &err, G_TYPE_INVALID, G_TYPE_INVALID) == FALSE) {
106
const gchar *error_name = NULL;
108
if (err != NULL && err->code == DBUS_GERROR_REMOTE_EXCEPTION)
109
error_name = dbus_g_error_get_name (err);
110
if (error_name == NULL ||
111
(error_name != NULL && strcmp (error_name, "org.openobex.Error.NotStarted") != 0)) {
112
g_printerr ("Stopping Bluetooth ObexFTP server failed: %s\n",
120
if (stop_manager != FALSE) {
121
g_object_unref (server_proxy);
123
g_object_unref (manager_proxy);
124
manager_proxy = NULL;
135
obexftp_restart (void)
137
obexftp_stop (FALSE);
146
connection = dbus_g_bus_get (DBUS_BUS_SESSION, &err);
147
if (connection == NULL) {
148
g_printerr ("Connecting to session bus failed: %s\n",
154
dbus_connection_set_exit_on_disconnect (dbus_g_connection_get_connection (connection), FALSE);