[gnome-disk-utility] Add experimental --address option to connect to a remote udisks daemon
- From: David Zeuthen <davidz src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-disk-utility] Add experimental --address option to connect to a remote udisks daemon
- Date: Thu, 3 Dec 2009 00:21:52 +0000 (UTC)
commit d29468486b0165a9519671e8c9a8341b9dd54d94
Author: David Zeuthen <davidz redhat com>
Date: Wed Dec 2 19:15:58 2009 -0500
Add experimental --address option to connect to a remote udisks daemon
As already mentioned in the udisks commit
http://cgit.freedesktop.org/DeviceKit/DeviceKit-disks/commit/?id=b1582dab2c4fdcf7dcb8f74717bf476615876d5d
this feature is experimental. Some notes
- We really need to pipeline and make dbus calls async - it is quite
visible how slow our sync-fest is
- We should have a File->Connect... menu item and a connection
dialog. This will also handle authentication. Should also use
things like Avahi to discover udisks servers. Also want a "recently
used servers" feature. And use of the keyring to store the password.
- Should be able to show several udisks servers - each server should
probably be in the tree view with it's (display-) hostname.
- There's a few couple of places where the UI needs to be adjusted -
for example the hyperlink for a mounted volume. Should probably
just not show for remote udisks servers.
- With this feature it is now feasible (and probably desirable)
to port Palimpsest to Windows.
Anyway, lots of UX work needed - for now it's just a hidden
experimental command-line option.
src/gdu/gdu-adapter.c | 24 ++++++--------------
src/gdu/gdu-device.c | 17 +++-----------
src/gdu/gdu-expander.c | 22 +++++-------------
src/gdu/gdu-pool.c | 51 ++++++++++++++++++++++++++++++++-----------
src/gdu/gdu-pool.h | 1 +
src/gdu/gdu-port.c | 22 +++++-------------
src/gdu/gdu-private.h | 2 +
src/palimpsest/gdu-main.c | 4 ++-
src/palimpsest/gdu-shell.c | 14 ++++++++---
src/palimpsest/gdu-shell.h | 2 +-
10 files changed, 78 insertions(+), 81 deletions(-)
---
diff --git a/src/gdu/gdu-adapter.c b/src/gdu/gdu-adapter.c
index 3f2df48..b23f74f 100644
--- a/src/gdu/gdu-adapter.c
+++ b/src/gdu/gdu-adapter.c
@@ -91,7 +91,7 @@ adapter_properties_free (AdapterProperties *props)
static AdapterProperties *
adapter_properties_get (DBusGConnection *bus,
- const char *object_path)
+ const char *object_path)
{
AdapterProperties *props;
GError *error;
@@ -146,7 +146,6 @@ out:
struct _GduAdapterPrivate
{
- DBusGConnection *bus;
DBusGProxy *proxy;
GduPool *pool;
@@ -178,7 +177,6 @@ gdu_adapter_finalize (GduAdapter *adapter)
g_debug ("##### finalized adapter %s",
adapter->priv->props != NULL ? adapter->priv->props->native_path : adapter->priv->object_path);
- dbus_g_connection_unref (adapter->priv->bus);
g_free (adapter->priv->object_path);
if (adapter->priv->proxy != NULL)
g_object_unref (adapter->priv->proxy);
@@ -231,7 +229,8 @@ update_info (GduAdapter *adapter)
{
AdapterProperties *new_properties;
- new_properties = adapter_properties_get (adapter->priv->bus, adapter->priv->object_path);
+ new_properties = adapter_properties_get (_gdu_pool_get_connection (adapter->priv->pool),
+ adapter->priv->object_path);
if (new_properties != NULL) {
if (adapter->priv->props != NULL)
adapter_properties_free (adapter->priv->props);
@@ -246,25 +245,16 @@ update_info (GduAdapter *adapter)
GduAdapter *
_gdu_adapter_new_from_object_path (GduPool *pool, const char *object_path)
{
- GError *error;
GduAdapter *adapter;
adapter = GDU_ADAPTER (g_object_new (GDU_TYPE_ADAPTER, NULL));
adapter->priv->object_path = g_strdup (object_path);
adapter->priv->pool = g_object_ref (pool);
- error = NULL;
- adapter->priv->bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
- if (adapter->priv->bus == NULL) {
- g_warning ("Couldn't connect to system bus: %s", error->message);
- g_error_free (error);
- goto error;
- }
-
- adapter->priv->proxy = dbus_g_proxy_new_for_name (adapter->priv->bus,
- "org.freedesktop.UDisks",
- adapter->priv->object_path,
- "org.freedesktop.UDisks.Adapter");
+ adapter->priv->proxy = dbus_g_proxy_new_for_name (_gdu_pool_get_connection (adapter->priv->pool),
+ "org.freedesktop.UDisks",
+ adapter->priv->object_path,
+ "org.freedesktop.UDisks.Adapter");
dbus_g_proxy_set_default_timeout (adapter->priv->proxy, INT_MAX);
dbus_g_proxy_add_signal (adapter->priv->proxy, "Changed", G_TYPE_INVALID);
diff --git a/src/gdu/gdu-device.c b/src/gdu/gdu-device.c
index 2a27ab7..970c63d 100644
--- a/src/gdu/gdu-device.c
+++ b/src/gdu/gdu-device.c
@@ -512,6 +512,7 @@ device_properties_get (DBusGConnection *bus,
props = NULL;
goto out;
}
+ g_debug ("yay, got props for %s", object_path);
g_hash_table_foreach (hash_table, (GHFunc) collect_props, props);
@@ -526,7 +527,6 @@ out:
struct _GduDevicePrivate
{
- DBusGConnection *bus;
DBusGProxy *proxy;
GduPool *pool;
@@ -559,7 +559,6 @@ gdu_device_finalize (GduDevice *device)
g_debug ("##### finalized device %s",
device->priv->props != NULL ? device->priv->props->device_file : device->priv->object_path);
- dbus_g_connection_unref (device->priv->bus);
g_free (device->priv->object_path);
if (device->priv->proxy != NULL)
g_object_unref (device->priv->proxy);
@@ -620,7 +619,8 @@ update_info (GduDevice *device)
{
DeviceProperties *new_properties;
- new_properties = device_properties_get (device->priv->bus, device->priv->object_path);
+ new_properties = device_properties_get (_gdu_pool_get_connection (device->priv->pool),
+ device->priv->object_path);
if (new_properties != NULL) {
if (device->priv->props != NULL)
device_properties_free (device->priv->props);
@@ -635,22 +635,13 @@ update_info (GduDevice *device)
GduDevice *
_gdu_device_new_from_object_path (GduPool *pool, const char *object_path)
{
- GError *error;
GduDevice *device;
device = GDU_DEVICE (g_object_new (GDU_TYPE_DEVICE, NULL));
device->priv->object_path = g_strdup (object_path);
device->priv->pool = g_object_ref (pool);
- error = NULL;
- device->priv->bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
- if (device->priv->bus == NULL) {
- g_warning ("Couldn't connect to system bus: %s", error->message);
- g_error_free (error);
- goto error;
- }
-
- device->priv->proxy = dbus_g_proxy_new_for_name (device->priv->bus,
+ device->priv->proxy = dbus_g_proxy_new_for_name (_gdu_pool_get_connection (device->priv->pool),
"org.freedesktop.UDisks",
device->priv->object_path,
"org.freedesktop.UDisks.Device");
diff --git a/src/gdu/gdu-expander.c b/src/gdu/gdu-expander.c
index 121b811..5be5908 100644
--- a/src/gdu/gdu-expander.c
+++ b/src/gdu/gdu-expander.c
@@ -167,7 +167,6 @@ out:
struct _GduExpanderPrivate
{
- DBusGConnection *bus;
DBusGProxy *proxy;
GduPool *pool;
@@ -199,7 +198,6 @@ gdu_expander_finalize (GduExpander *expander)
g_debug ("##### finalized expander %s",
expander->priv->props != NULL ? expander->priv->props->native_path : expander->priv->object_path);
- dbus_g_connection_unref (expander->priv->bus);
g_free (expander->priv->object_path);
if (expander->priv->proxy != NULL)
g_object_unref (expander->priv->proxy);
@@ -252,7 +250,8 @@ update_info (GduExpander *expander)
{
ExpanderProperties *new_properties;
- new_properties = expander_properties_get (expander->priv->bus, expander->priv->object_path);
+ new_properties = expander_properties_get (_gdu_pool_get_connection (expander->priv->pool),
+ expander->priv->object_path);
if (new_properties != NULL) {
if (expander->priv->props != NULL)
expander_properties_free (expander->priv->props);
@@ -267,25 +266,16 @@ update_info (GduExpander *expander)
GduExpander *
_gdu_expander_new_from_object_path (GduPool *pool, const char *object_path)
{
- GError *error;
GduExpander *expander;
expander = GDU_EXPANDER (g_object_new (GDU_TYPE_EXPANDER, NULL));
expander->priv->object_path = g_strdup (object_path);
expander->priv->pool = g_object_ref (pool);
- error = NULL;
- expander->priv->bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
- if (expander->priv->bus == NULL) {
- g_warning ("Couldn't connect to system bus: %s", error->message);
- g_error_free (error);
- goto error;
- }
-
- expander->priv->proxy = dbus_g_proxy_new_for_name (expander->priv->bus,
- "org.freedesktop.UDisks",
- expander->priv->object_path,
- "org.freedesktop.UDisks.Expander");
+ expander->priv->proxy = dbus_g_proxy_new_for_name (_gdu_pool_get_connection (expander->priv->pool),
+ "org.freedesktop.UDisks",
+ expander->priv->object_path,
+ "org.freedesktop.UDisks.Expander");
dbus_g_proxy_set_default_timeout (expander->priv->proxy, INT_MAX);
dbus_g_proxy_add_signal (expander->priv->proxy, "Changed", G_TYPE_INVALID);
diff --git a/src/gdu/gdu-pool.c b/src/gdu/gdu-pool.c
index 2552c21..79ffbfe 100644
--- a/src/gdu/gdu-pool.c
+++ b/src/gdu/gdu-pool.c
@@ -1608,7 +1608,8 @@ get_properties (GduPool *pool)
dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE),
&hash_table,
G_TYPE_INVALID)) {
- g_debug ("Error calling GetAll() when retrieving properties for /: %s", error->message);
+ g_debug ("Error calling GetAll() retrieving properties for /org/freedesktop/UDisks: %s",
+ error->message);
g_error_free (error);
goto out;
}
@@ -1649,16 +1650,29 @@ out:
return ret;
}
+
/**
* gdu_pool_new:
*
* Create a new #GduPool object.
*
* Returns: A #GduPool object. Caller must free this object using g_object_unref().
- **/
+ */
GduPool *
gdu_pool_new (void)
{
+ return gdu_pool_new_for_address (NULL);
+}
+
+DBusGConnection *
+_gdu_pool_get_connection (GduPool *pool)
+{
+ return pool->priv->bus;
+}
+
+GduPool *
+gdu_pool_new_for_address (const gchar *dbus_address)
+{
int n;
GPtrArray *devices;
GPtrArray *adapters;
@@ -1670,11 +1684,22 @@ gdu_pool_new (void)
pool = GDU_POOL (g_object_new (GDU_TYPE_POOL, NULL));
error = NULL;
- pool->priv->bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
- if (pool->priv->bus == NULL) {
- g_warning ("Couldn't connect to system bus: %s", error->message);
- g_error_free (error);
- goto error;
+ if (dbus_address == NULL) {
+ pool->priv->bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
+ if (pool->priv->bus == NULL) {
+ g_warning ("Couldn't connect to system bus: %s", error->message);
+ g_error_free (error);
+ goto error;
+ }
+ } else {
+ pool->priv->bus = dbus_g_connection_open (dbus_address, &error);
+ if (pool->priv->bus == NULL) {
+ g_warning ("Couldn't connect to address `%s': %s",
+ dbus_address,
+ error->message);
+ g_error_free (error);
+ goto error;
+ }
}
dbus_g_object_register_marshaller (
@@ -1705,6 +1730,12 @@ gdu_pool_new (void)
G_TYPE_DOUBLE,
G_TYPE_INVALID);
+ /* get the properties on the daemon object */
+ if (!get_properties (pool)) {
+ g_warning ("Couldn't get daemon properties");
+ goto error;
+ }
+
dbus_g_proxy_connect_signal (pool->priv->proxy, "DeviceAdded",
G_CALLBACK (device_added_signal_handler), pool, NULL);
dbus_g_proxy_connect_signal (pool->priv->proxy, "DeviceRemoved",
@@ -1744,12 +1775,6 @@ gdu_pool_new (void)
dbus_g_proxy_connect_signal (pool->priv->proxy, "PortChanged",
G_CALLBACK (port_changed_signal_handler), pool, NULL);
- /* get the properties on the daemon object at / */
- if (!get_properties (pool)) {
- g_warning ("Couldn't get daemon properties");
- goto error;
- }
-
/* prime the list of devices */
error = NULL;
if (!org_freedesktop_UDisks_enumerate_devices (pool->priv->proxy, &devices, &error)) {
diff --git a/src/gdu/gdu-pool.h b/src/gdu/gdu-pool.h
index c94e879..5c78542 100644
--- a/src/gdu/gdu-pool.h
+++ b/src/gdu/gdu-pool.h
@@ -79,6 +79,7 @@ struct _GduPoolClass
GType gdu_pool_get_type (void);
GduPool *gdu_pool_new (void);
+GduPool *gdu_pool_new_for_address (const gchar *dbus_address);
char *gdu_pool_get_daemon_version (GduPool *pool);
gboolean gdu_pool_is_daemon_inhibited (GduPool *pool);
diff --git a/src/gdu/gdu-port.c b/src/gdu/gdu-port.c
index fd62b59..24d0dec 100644
--- a/src/gdu/gdu-port.c
+++ b/src/gdu/gdu-port.c
@@ -137,7 +137,6 @@ out:
struct _GduPortPrivate
{
- DBusGConnection *bus;
DBusGProxy *proxy;
GduPool *pool;
@@ -169,7 +168,6 @@ gdu_port_finalize (GduPort *port)
g_debug ("##### finalized port %s",
port->priv->props != NULL ? port->priv->props->native_path : port->priv->object_path);
- dbus_g_connection_unref (port->priv->bus);
g_free (port->priv->object_path);
if (port->priv->proxy != NULL)
g_object_unref (port->priv->proxy);
@@ -222,7 +220,8 @@ update_info (GduPort *port)
{
PortProperties *new_properties;
- new_properties = port_properties_get (port->priv->bus, port->priv->object_path);
+ new_properties = port_properties_get (_gdu_pool_get_connection (port->priv->pool),
+ port->priv->object_path);
if (new_properties != NULL) {
if (port->priv->props != NULL)
port_properties_free (port->priv->props);
@@ -237,25 +236,16 @@ update_info (GduPort *port)
GduPort *
_gdu_port_new_from_object_path (GduPool *pool, const char *object_path)
{
- GError *error;
GduPort *port;
port = GDU_PORT (g_object_new (GDU_TYPE_PORT, NULL));
port->priv->object_path = g_strdup (object_path);
port->priv->pool = g_object_ref (pool);
- error = NULL;
- port->priv->bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
- if (port->priv->bus == NULL) {
- g_warning ("Couldn't connect to system bus: %s", error->message);
- g_error_free (error);
- goto error;
- }
-
- port->priv->proxy = dbus_g_proxy_new_for_name (port->priv->bus,
- "org.freedesktop.UDisks",
- port->priv->object_path,
- "org.freedesktop.UDisks.Port");
+ port->priv->proxy = dbus_g_proxy_new_for_name (_gdu_pool_get_connection (port->priv->pool),
+ "org.freedesktop.UDisks",
+ port->priv->object_path,
+ "org.freedesktop.UDisks.Port");
dbus_g_proxy_set_default_timeout (port->priv->proxy, INT_MAX);
dbus_g_proxy_add_signal (port->priv->proxy, "Changed", G_TYPE_INVALID);
diff --git a/src/gdu/gdu-private.h b/src/gdu/gdu-private.h
index 2127450..e2fe806 100644
--- a/src/gdu/gdu-private.h
+++ b/src/gdu/gdu-private.h
@@ -75,6 +75,8 @@
G_TYPE_STRING, \
G_TYPE_INVALID))
+DBusGConnection *_gdu_pool_get_connection (GduPool *pool);
+
GduKnownFilesystem *_gdu_known_filesystem_new (gpointer data);
GduProcess * _gdu_process_new (gpointer data);
diff --git a/src/palimpsest/gdu-main.c b/src/palimpsest/gdu-main.c
index 76f8bdc..9a33e5a 100644
--- a/src/palimpsest/gdu-main.c
+++ b/src/palimpsest/gdu-main.c
@@ -117,10 +117,12 @@ message_received (UniqueApp *app,
const char *volume_to_show = NULL;
const char *drive_to_show = NULL;
+const char *dbus_address = NULL;
static GOptionEntry entries[] = {
{ "show-volume", 0, 0, G_OPTION_ARG_FILENAME, &volume_to_show, N_("Volume to show"), N_("DEVICE") },
{ "show-drive", 0, 0, G_OPTION_ARG_FILENAME, &drive_to_show, N_("Drive to show"), N_("DEVICE") },
+ { "address", 'a', 0, G_OPTION_ARG_STRING, &dbus_address, "D-Bus address to connect to", NULL },
{ NULL }
};
@@ -177,7 +179,7 @@ main (int argc, char **argv)
return 1;
}
- shell = gdu_shell_new ();
+ shell = gdu_shell_new (dbus_address);
g_signal_connect (unique_app, "message-received",
G_CALLBACK (message_received), shell);
diff --git a/src/palimpsest/gdu-shell.c b/src/palimpsest/gdu-shell.c
index bdbc6a3..e46ebbd 100644
--- a/src/palimpsest/gdu-shell.c
+++ b/src/palimpsest/gdu-shell.c
@@ -42,6 +42,8 @@
struct _GduShellPrivate
{
+ gchar *dbus_address;
+
GtkWidget *app_window;
GduPool *pool;
@@ -68,6 +70,7 @@ G_DEFINE_TYPE (GduShell, gdu_shell, G_TYPE_OBJECT);
static void
gdu_shell_finalize (GduShell *shell)
{
+ g_free (shell->priv->dbus_address);
if (G_OBJECT_CLASS (parent_class)->finalize)
(* G_OBJECT_CLASS (parent_class)->finalize) (G_OBJECT (shell));
}
@@ -90,13 +93,16 @@ static void
gdu_shell_init (GduShell *shell)
{
shell->priv = G_TYPE_INSTANCE_GET_PRIVATE (shell, GDU_TYPE_SHELL, GduShellPrivate);
- create_window (shell);
}
GduShell *
-gdu_shell_new (void)
+gdu_shell_new (const gchar *dbus_address)
{
- return GDU_SHELL (g_object_new (GDU_TYPE_SHELL, NULL));;
+ GduShell *shell;
+ shell = GDU_SHELL (g_object_new (GDU_TYPE_SHELL, NULL));
+ shell->priv->dbus_address = g_strdup (dbus_address);
+ create_window (shell);
+ return shell;
}
GtkWidget *
@@ -1665,7 +1671,7 @@ create_window (GduShell *shell)
GduPoolTreeModel *model;
GtkTreeViewColumn *column;
- shell->priv->pool = gdu_pool_new ();
+ shell->priv->pool = gdu_pool_new_for_address (shell->priv->dbus_address);
shell->priv->app_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_resizable (GTK_WINDOW (shell->priv->app_window), TRUE);
diff --git a/src/palimpsest/gdu-shell.h b/src/palimpsest/gdu-shell.h
index 5c85568..f5b8e0b 100644
--- a/src/palimpsest/gdu-shell.h
+++ b/src/palimpsest/gdu-shell.h
@@ -54,7 +54,7 @@ struct _GduShellClass
};
GType gdu_shell_get_type (void);
-GduShell *gdu_shell_new (void);
+GduShell *gdu_shell_new (const char *dbus_address);
GtkWidget *gdu_shell_get_toplevel (GduShell *shell);
GduPool *gdu_shell_get_pool (GduShell *shell);
void gdu_shell_update (GduShell *shell);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]