[gnome-commander] GnomeCmdCon: add create_keyring_attributes() method



commit 8b679306461546ff637f643372d424e0bfa95e5a
Author: Piotr Eljasiak <epiotr src gnome org>
Date:   Mon Dec 12 19:40:53 2011 +0100

    GnomeCmdCon: add create_keyring_attributes() method

 src/gnome-cmd-con.cc |   67 ++++++++++++++++++++++++++++++++++++++++++++++++++
 src/gnome-cmd-con.h  |   11 ++++++++
 2 files changed, 78 insertions(+), 0 deletions(-)
---
diff --git a/src/gnome-cmd-con.cc b/src/gnome-cmd-con.cc
index 3802bef..75abee5 100644
--- a/src/gnome-cmd-con.cc
+++ b/src/gnome-cmd-con.cc
@@ -543,3 +543,70 @@ XML::xstream &operator << (XML::xstream &xml, GnomeCmdCon &con)
 
     return xml << XML::endtag();
 }
+
+
+GnomeKeyringAttributeList *gnome_cmd_con_create_keyring_attributes (const gchar *uri_str, const gchar *alias, ConnectionMethodID method)
+{
+    GnomeVFSURI *uri = gnome_vfs_uri_new (uri_str);
+
+    const gchar *user = gnome_vfs_uri_get_user_name (uri);
+    const gchar *domain = NULL;
+    const gchar *server = gnome_vfs_uri_get_host_name (uri);
+    const gchar *path = gnome_vfs_uri_get_path (uri);
+    const gchar *protocol = gnome_vfs_uri_get_scheme (uri);
+    guint port = gnome_vfs_uri_get_host_port (uri);
+
+    gchar **a = NULL;
+
+    if (method==CON_SMB)
+    {
+        a = g_strsplit (user, ";", 2);
+
+        if (g_strv_length (a) > 1)
+        {
+            domain = a[0];
+            user = a[1];
+        }
+    }
+
+    GnomeKeyringAttributeList *attributes = gnome_keyring_attribute_list_new ();
+
+    gnome_keyring_attribute_list_append_string (attributes, "alias", alias);
+
+    if (protocol)
+        gnome_keyring_attribute_list_append_string (attributes, "protocol", protocol);
+
+    if (user)
+        gnome_keyring_attribute_list_append_string (attributes, "user", user);
+
+    if (server)
+        gnome_keyring_attribute_list_append_string (attributes, "server", server);
+
+    if (port)
+        gnome_keyring_attribute_list_append_uint32 (attributes, "port", port);
+
+    if (domain)
+        gnome_keyring_attribute_list_append_string (attributes, "domain", domain);
+
+    if (path)
+        gnome_keyring_attribute_list_append_string (attributes, "object", path);
+
+    gnome_keyring_attribute_list_append_string (attributes, "application", "GNOME Commander");
+
+    {
+        gchar date[11];
+        GDate *now = g_date_new ();
+
+        g_date_set_time_t (now, time (NULL));
+        g_date_strftime (date, sizeof(date), "%Y-%m-%d", now);
+
+        gnome_keyring_attribute_list_append_string (attributes, "date-modified", date);
+
+        g_date_free (now);
+    }
+
+    gnome_vfs_uri_unref (uri);
+    g_strfreev (a);
+
+    return attributes;
+}
diff --git a/src/gnome-cmd-con.h b/src/gnome-cmd-con.h
index 8c9fd33..bb19586 100644
--- a/src/gnome-cmd-con.h
+++ b/src/gnome-cmd-con.h
@@ -30,6 +30,8 @@
 
 struct GnomeCmdConPrivate;
 
+#include <gnome-keyring.h>
+
 #include <string>
 
 #include "gnome-cmd-path.h"
@@ -113,6 +115,8 @@ struct GnomeCmdCon
 
     GnomeCmdConPrivate  *priv;
 
+    GnomeKeyringAttributeList *create_keyring_attributes();
+
     friend XML::xstream &operator << (XML::xstream &xml, GnomeCmdCon &con);
 };
 
@@ -485,4 +489,11 @@ inline std::string &gnome_cmd_con_make_uri (std::string &s, ConnectionMethodID m
     }
 }
 
+GnomeKeyringAttributeList *gnome_cmd_con_create_keyring_attributes (const gchar *uri_str, const gchar *alias, ConnectionMethodID method);
+
+inline GnomeKeyringAttributeList *GnomeCmdCon::create_keyring_attributes()
+{
+    return gnome_cmd_con_create_keyring_attributes (uri, alias, method);
+}
+
 #endif // __GNOME_CMD_CON_H__



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