Adding API for editing GnomeVFSVolume's



Hi,

I was talking on #nautilus about adding support to be able to edit
connected servers after they have been created.  Currently your only
option is the umount the connection and then recreate it.  I was told
that we needed to add support to gnome-vfs so that we can edit
GnomeVFSVolume's first.  This is what i have created so far to add
this.  One missing item is the ability to  change what gnome-vfs
method the connection uses.   From what I could see gnome-vfs doesn't
have a function to do this on normal uri's so I wasn't sure if it is
wanted or not.  I think it would be useful.  Below is what I have
created thus far.  Comments please.

Trevor Davenport
trevor davenport gmail com


/* return true if the volume is a GNOME_VFS_VOLUME_TYPE_CONNECTED_SERVER
   we don't want to edit other types */
gboolean  gnome_vfs_volume_is_editable        (GnomeVFSVolume *volume);

/* set's hostname in the volume */
void      gnome_vfs_volume_set_host_name      (GnomeVFSVolume *volume,
                                                                      
 char* host_name);
                                               
/* set's port to connect to*/
void      gnome_vfs_volume_set_host_port      (GnomeVFSVolume *volume,
                                                                    
guint host_port);
                                               
/* set's display name */
void      gnome_vfs_volume_set_display_name   (GnomeVFSVolume *volume,
                                                                      
   char* display_name);
                                               
/* set's username used to connect */
void      gnome_vfs_volume_set_user_name      (GnomeVFSVolume *volume,
                                                                      
  char* user_name);
                                               
/* set's replaces everything after hostname with supplied folder */
void      gnome_vfs_volume_set_host_folder    (GnomeVFSVolume *volume,
                                                                     
char* host_folder);
                                               
/* set gconf key for server with supplied id */
void      gnome_vfs_connect_to_server_id      (gint id,
                                                                     char *uri,
                                                                    
char *display_name,
                                                                    
char *icon);

gboolean gnome_vfs_volume_is_editable (GnomeVFSVolume *volume) {
        if (volume->priv->volume_type ==
GNOME_VFS_VOLUME_TYPE_CONNECTED_SERVER)  {
                return TRUE;
        } else {
                return FALSE;
        }        
}

void gnome_vfs_volume_set_host_name      (GnomeVFSVolume *volume,
                                                                  
char* host_name)
{
        g_return_if_fail( gnome_vfs_volume_is_editable (volume) );
        
        GnomeVFSURI* uri;
        gchar* str_uri;
        
        uri = gnome_vfs_uri_new ( volume->priv->activation_uri );
        
        gnome_vfs_uri_set_host_name (uri, host_name);
        
        str_uri = gnome_vfs_uri_to_string (uri,  GNOME_VFS_URI_HIDE_PASSWORD);
        
        volume->priv->activation_uri   = str_uri;
        
        gnome_vfs_connect_to_server_id ( *volume->priv->gconf_id,
                                                            str_uri,
                                                           
volume->priv->display_name,
                                                            volume->priv->icon);
        gnome_vfs_uri_unref (uri);
        g_free (str_uri);
}

void gnome_vfs_volume_set_host_port (GnomeVFSVolume *volume,
                                                            guint host_port) 
{
        g_return_if_fail( gnome_vfs_volume_is_editable (volume) );
        
        GnomeVFSURI* uri;
        gchar* str_uri;
        
        uri = gnome_vfs_uri_new ( volume->priv->activation_uri );
        
        gnome_vfs_uri_set_host_port (uri, host_port);
        
        str_uri = gnome_vfs_uri_to_string (uri,  GNOME_VFS_URI_HIDE_PASSWORD);
        
        volume->priv->activation_uri   = str_uri;
        
        gnome_vfs_connect_to_server_id ( *volume->priv->gconf_id,
                                                             str_uri,
                                                            
volume->priv->display_name,
                                                            
volume->priv->icon);
        gnome_vfs_uri_unref (uri);
        g_free (str_uri);
}

void gnome_vfs_volume_set_display_name (GnomeVFSVolume *volume,
                                                                  
char* display_name)
{
        g_return_if_fail( gnome_vfs_volume_is_editable (volume) );
               
        g_free (volume->priv->display_name);

        volume->priv->display_name = g_strdup (display_name);
        
        gnome_vfs_connect_to_server_id ( *volume->priv->gconf_id,
                                                            
volume->priv->activation_uri,
                                                            
volume->priv->display_name,
                                                            
volume->priv->icon);
}

void gnome_vfs_volume_set_user_name (GnomeVFSVolume *volume,
                                                               char* user_name) 
{
        g_return_if_fail( gnome_vfs_volume_is_editable (volume) );
        
        GnomeVFSURI* uri;
        gchar* str_uri;
        
        uri = gnome_vfs_uri_new ( volume->priv->activation_uri );
        
        gnome_vfs_uri_set_user_name (uri, user_name);
        
        str_uri = gnome_vfs_uri_to_string (uri, GNOME_VFS_URI_HIDE_PASSWORD);
        
        volume->priv->activation_uri = str_uri;
        
        gnome_vfs_connect_to_server_id ( *volume->priv->gconf_id,
                                                             str_uri,
                                                            
volume->priv->display_name,
                                                            
volume->priv->icon);
        gnome_vfs_uri_unref (uri);
        g_free (str_uri);
}

void gnome_vfs_volume_set_host_folder (GnomeVFSVolume *volume,
                                                              char*
host_folder)
{
        g_return_if_fail( gnome_vfs_volume_is_editable (volume) );
        
        GnomeVFSURI* old_uri;
        GnomeVFSURI* new_uri;
        GnomeVFSToplevelURI* top;
        gchar* str_uri;
        
        old_uri = gnome_vfs_uri_new ( volume->priv->activation_uri );
        
        top = gnome_vfs_uri_get_toplevel (old_uri);

        gnome_vfs_uri_unref (old_uri);

        new_uri = gnome_vfs_uri_append_path (&top->uri, host_folder);

        g_free (top);
                        
        str_uri = gnome_vfs_uri_to_string (old_uri, 
GNOME_VFS_URI_HIDE_PASSWORD);
        
        volume->priv->activation_uri = str_uri;
        
        gnome_vfs_connect_to_server_id ( *volume->priv->gconf_id,
                                                             str_uri,
                                                            
volume->priv->display_name,
                                                            
volume->priv->icon);
        gnome_vfs_uri_unref (new_uri);
        g_free (str_uri);
}

void gnome_vfs_connect_to_server_id    (int id,
                                                              char *uri,
                                                              char
*display_name,
                                                              char *icon) 
{
        GConfClient *client;
        char *key;

        client = gconf_client_get_default ();

        key = g_strconcat (CONNECTED_SERVERS_DIR "/",
                                     id,
                                     "/icon", NULL);
        gconf_client_set_string (client, key, icon, NULL);
        g_free (key);
        
        key = g_strconcat (CONNECTED_SERVERS_DIR "/",
                                     id,
                                     "/display_name", NULL);
        gconf_client_set_string (client, key, display_name, NULL);
        g_free (key);

        /* Uri key creation triggers creation, do this last */
        key = g_strconcat (CONNECTED_SERVERS_DIR "/",
                                     id,
                                     "/uri", NULL);
        gconf_client_set_string (client, key, uri, NULL);
        g_free (key);
        
        g_object_unref (client);

}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]