[gnote] Add gnome-keyring support files



commit af2289fbea689941e0a8df77860c8490b04e7cef
Author: Aurimas Äernius <aurisc4 gmail com>
Date:   Sun Jun 17 20:19:53 2012 +0300

    Add gnome-keyring support files

 src/Makefile.am                        |    6 +
 src/gnome_keyring/genericitemdata.cpp  |   38 ++++++++
 src/gnome_keyring/genericitemdata.hpp  |   52 +++++++++++
 src/gnome_keyring/itemdata.cpp         |   66 +++++++++++++
 src/gnome_keyring/itemdata.hpp         |   61 ++++++++++++
 src/gnome_keyring/keyringexception.cpp |   61 ++++++++++++
 src/gnome_keyring/keyringexception.hpp |   56 +++++++++++
 src/gnome_keyring/netitemdata.cpp      |   55 +++++++++++
 src/gnome_keyring/netitemdata.hpp      |   60 ++++++++++++
 src/gnome_keyring/noteitemdata.hpp     |   48 ++++++++++
 src/gnome_keyring/ring.cpp             |  158 ++++++++++++++++++++++++++++++++
 src/gnome_keyring/ring.hpp             |   55 +++++++++++
 12 files changed, 716 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 1237c5e..7db47b8 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -88,6 +88,12 @@ libgnote_la_SOURCES = \
 	base/singleton.hpp \
 	base/macros.hpp \
 	base/inifile.hpp base/inifile.cpp \
+	gnome_keyring/genericitemdata.hpp gnome_keyring/genericitemdata.cpp \
+	gnome_keyring/itemdata.hpp gnome_keyring/itemdata.cpp \
+	gnome_keyring/netitemdata.hpp gnome_keyring/netitemdata.cpp \
+	gnome_keyring/noteitemdata.hpp \
+	gnome_keyring/keyringexception.hpp gnome_keyring/keyringexception.cpp \
+	gnome_keyring/ring.hpp gnome_keyring/ring.cpp \
 	sharp/addinstreemodel.hpp sharp/addinstreemodel.cpp \
 	sharp/datetime.hpp sharp/datetime.cpp \
 	sharp/dynamicmodule.hpp sharp/dynamicmodule.cpp \
diff --git a/src/gnome_keyring/genericitemdata.cpp b/src/gnome_keyring/genericitemdata.cpp
new file mode 100644
index 0000000..22b1e1e
--- /dev/null
+++ b/src/gnome_keyring/genericitemdata.cpp
@@ -0,0 +1,38 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 2012 Aurimas Cernius
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "genericitemdata.hpp"
+
+
+namespace gnome {
+namespace keyring {
+
+void GenericItemData::set_values_from_attributes()
+{
+  std::map<std::string, std::string>::iterator name_attr = attributes.find("name");
+  if(name_attr == attributes.end()) {
+    return;
+  }
+
+  name = name_attr->second;
+}
+
+}
+}
diff --git a/src/gnome_keyring/genericitemdata.hpp b/src/gnome_keyring/genericitemdata.hpp
new file mode 100644
index 0000000..43e3720
--- /dev/null
+++ b/src/gnome_keyring/genericitemdata.hpp
@@ -0,0 +1,52 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 2012 Aurimas Cernius
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _GNOME_KEYRING_GENERICITEMDATA_HPP_
+#define _GNOME_KEYRING_GENERICITEMDATA_HPP_
+
+#include "itemdata.hpp"
+
+
+namespace gnome {
+namespace keyring {
+
+class GenericItemData
+  : public ItemData
+{
+public:
+  static ItemData::Ptr create()
+    {
+      return ItemData::Ptr(new GenericItemData);
+    }
+
+  std::string name;
+
+  virtual ItemType type() const
+    {
+      return GENERIC_SECRET;
+    }
+protected:
+  virtual void set_values_from_attributes();
+};
+
+}
+}
+
+#endif
diff --git a/src/gnome_keyring/itemdata.cpp b/src/gnome_keyring/itemdata.cpp
new file mode 100644
index 0000000..a27a972
--- /dev/null
+++ b/src/gnome_keyring/itemdata.cpp
@@ -0,0 +1,66 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 2012 Aurimas Cernius
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include <stdexcept>
+
+#include <boost/format.hpp>
+#include <boost/lexical_cast.hpp>
+
+#include "itemdata.hpp"
+#include "genericitemdata.hpp"
+#include "netitemdata.hpp"
+#include "noteitemdata.hpp"
+
+
+namespace gnome {
+namespace keyring {
+
+
+std::string ItemData::str()
+{
+  std::string sb;
+  for(std::map<std::string, std::string>::iterator iter = attributes.begin();
+      iter != attributes.end(); ++iter) {
+    sb += boost::str(boost::format("%1%: %2%\n") % iter->first % iter->second);
+  }
+  return boost::str(boost::format("Keyring: %1% ItemID: %2% Secret: %3%\n%4%")
+                    % keyring % item_id % secret % sb);
+}
+
+void ItemData::set_values_from_attributes()
+{
+}
+
+ItemData::Ptr ItemData::get_instance_from_item_type(ItemType type)
+{
+  switch(type) {
+  case GENERIC_SECRET:
+    return GenericItemData::create();
+  case NETWORK_PASSWORD:
+    return NetItemData::create();
+  case NOTE:
+    return NoteItemData::create();
+  default:
+    throw std::invalid_argument("Unknown type: " + boost::lexical_cast<std::string>(type));
+  }
+}
+
+}
+}
diff --git a/src/gnome_keyring/itemdata.hpp b/src/gnome_keyring/itemdata.hpp
new file mode 100644
index 0000000..2dca8c8
--- /dev/null
+++ b/src/gnome_keyring/itemdata.hpp
@@ -0,0 +1,61 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 2012 Aurimas Cernius
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _GNOME_KEYRING_ITEMDATA_HPP_
+#define _GNOME_KEYRING_ITEMDATA_HPP_
+
+#include <map>
+#include <string>
+#include <tr1/memory>
+
+
+namespace gnome {
+namespace keyring {
+
+enum ItemType {
+  GENERIC_SECRET,
+  NETWORK_PASSWORD,
+  NOTE
+};
+
+class ItemData
+{
+public:
+  friend class Ring;
+  typedef std::tr1::shared_ptr<ItemData> Ptr;
+
+  std::string keyring;
+  int item_id;
+  std::string secret;
+  std::map<std::string, std::string> attributes;
+
+  virtual ItemType type() const = 0;
+
+  virtual std::string str();
+protected:
+  virtual void set_values_from_attributes();
+
+  static Ptr get_instance_from_item_type(ItemType type);
+};
+
+}
+}
+
+#endif
diff --git a/src/gnome_keyring/keyringexception.cpp b/src/gnome_keyring/keyringexception.cpp
new file mode 100644
index 0000000..fb23648
--- /dev/null
+++ b/src/gnome_keyring/keyringexception.cpp
@@ -0,0 +1,61 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 2012 Aurimas Cernius
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "keyringexception.hpp"
+
+namespace gnome {
+namespace keyring {
+
+KeyringException::KeyringException(GnomeKeyringResult code)
+  : m_result(code)
+  , m_what(get_msg(code))
+{
+}
+
+const char * KeyringException::get_msg(GnomeKeyringResult code)
+{
+  switch(code) {
+  case GNOME_KEYRING_RESULT_OK:
+    return "Success";
+  case GNOME_KEYRING_RESULT_DENIED:
+    return "Access denied";
+  case GNOME_KEYRING_RESULT_NO_KEYRING_DAEMON:
+    return "The keyring daemon is not available";
+  case GNOME_KEYRING_RESULT_ALREADY_UNLOCKED:
+    return "Keyring was already unlocked";
+  case GNOME_KEYRING_RESULT_NO_SUCH_KEYRING:
+    return "No such keyring";
+  case GNOME_KEYRING_RESULT_BAD_ARGUMENTS:
+    return "Bad arguments";
+  case GNOME_KEYRING_RESULT_IO_ERROR:
+    return "I/O error";
+  case GNOME_KEYRING_RESULT_CANCELLED:
+    return "Operation canceled";
+  case GNOME_KEYRING_RESULT_KEYRING_ALREADY_EXISTS:
+    return "Item already exists";
+  case GNOME_KEYRING_RESULT_NO_MATCH:
+    return "No match";
+  default:
+    return "Unknown error";
+  }
+}
+
+}
+}
diff --git a/src/gnome_keyring/keyringexception.hpp b/src/gnome_keyring/keyringexception.hpp
new file mode 100644
index 0000000..eade27a
--- /dev/null
+++ b/src/gnome_keyring/keyringexception.hpp
@@ -0,0 +1,56 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 2012 Aurimas Cernius
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _GNOME_KEYRING_KEYRINGEXCEPTION_HPP_
+#define _GNOME_KEYRING_KEYRINGEXCEPTION_HPP_
+
+#include <stdexcept>
+
+#include <gnome-keyring.h>
+
+
+
+namespace gnome {
+namespace keyring {
+
+class KeyringException
+  : public std::exception
+{
+public:
+  KeyringException(GnomeKeyringResult);
+  GnomeKeyringResult result() const
+    {
+      return m_result;
+    }
+  virtual const char * what() const throw()
+    {
+      return m_what;
+    }
+private:
+  static const char * get_msg(GnomeKeyringResult);
+
+  GnomeKeyringResult m_result;
+  const char * m_what;
+};
+
+}
+}
+
+#endif
diff --git a/src/gnome_keyring/netitemdata.cpp b/src/gnome_keyring/netitemdata.cpp
new file mode 100644
index 0000000..2032229
--- /dev/null
+++ b/src/gnome_keyring/netitemdata.cpp
@@ -0,0 +1,55 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 2012 Aurimas Cernius
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include <boost/lexical_cast.hpp>
+#include "netitemdata.hpp"
+
+namespace gnome {
+namespace keyring {
+
+void NetItemData::set_values_from_attributes()
+{
+  user = get_attribute_value("user");
+  domain = get_attribute_value("domain");
+  server = get_attribute_value("server");
+  obj = get_attribute_value("object");
+  protocol = get_attribute_value("protocol");
+  auth_type = get_attribute_value("authtype");
+  std::string port_num = get_attribute_value("port");
+  if(port_num != "") {
+    port = boost::lexical_cast<int>(port_num);
+  }
+
+  ItemData::set_values_from_attributes();
+}
+
+
+std::string NetItemData::get_attribute_value(const std::string & att_name) const
+{
+  std::map<std::string, std::string>::const_iterator iter = attributes.find(att_name);
+  if(iter == attributes.end()) {
+    return "";
+  }
+
+  return iter->second;
+}
+
+}
+}
diff --git a/src/gnome_keyring/netitemdata.hpp b/src/gnome_keyring/netitemdata.hpp
new file mode 100644
index 0000000..07d0a6e
--- /dev/null
+++ b/src/gnome_keyring/netitemdata.hpp
@@ -0,0 +1,60 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 2012 Aurimas Cernius
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _GNOME_KEYRING_NETITEMDATA_HPP_
+#define _GNOME_KEYRING_NETITEMDATA_HPP_
+
+#include "itemdata.hpp"
+
+
+namespace gnome {
+namespace keyring {
+
+class NetItemData
+  : public ItemData
+{
+public:
+  static ItemData::Ptr create()
+    {
+      return ItemData::Ptr(new NetItemData);
+    }
+
+  std::string user;
+  std::string domain;
+  std::string server;
+  std::string obj;
+  std::string protocol;
+  std::string auth_type;
+  int port;
+
+  virtual ItemType type() const
+    {
+      return NETWORK_PASSWORD;
+    }
+protected:
+  virtual void set_values_from_attributes();
+private:
+  std::string get_attribute_value(const std::string & att_name) const;
+};
+
+}
+}
+
+#endif
diff --git a/src/gnome_keyring/noteitemdata.hpp b/src/gnome_keyring/noteitemdata.hpp
new file mode 100644
index 0000000..9886470
--- /dev/null
+++ b/src/gnome_keyring/noteitemdata.hpp
@@ -0,0 +1,48 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 2012 Aurimas Cernius
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _GNOME_KEYRING_NOTEITEMDATA_HPP_
+#define _GNOME_KEYRING_NOTEITEMDATA_HPP_
+
+#include "itemdata.hpp"
+
+
+namespace gnome {
+namespace keyring {
+
+class NoteItemData
+  : public ItemData
+{
+public:
+  static ItemData::Ptr create()
+    {
+      return ItemData::Ptr(new NoteItemData);
+    }
+
+  virtual ItemType type() const
+    {
+      return NOTE;
+    }
+};
+
+}
+}
+
+#endif
diff --git a/src/gnome_keyring/ring.cpp b/src/gnome_keyring/ring.cpp
new file mode 100644
index 0000000..d44e9e5
--- /dev/null
+++ b/src/gnome_keyring/ring.cpp
@@ -0,0 +1,158 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 2012 Aurimas Cernius
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+
+#include <boost/lexical_cast.hpp>
+
+#include "keyringexception.hpp"
+#include "ring.hpp"
+
+
+namespace gnome {
+namespace keyring {
+
+std::vector<ItemData::Ptr> Ring::find(ItemType type, const std::map<std::string, std::string> & atts)
+{
+  std::vector<ItemData::Ptr> res;
+  GList *list = NULL;
+  GnomeKeyringAttributeList *attributes = keyring_attributes(atts);
+  GnomeKeyringResult result = gnome_keyring_find_items_sync(keyring_item_type(type), attributes, &list);
+  gnome_keyring_attribute_list_free(attributes);
+  if(result == GNOME_KEYRING_RESULT_OK) {
+    for(GList *item = g_list_first(list); item; item = g_list_next(item)) {
+      GnomeKeyringFound *found_item = static_cast<GnomeKeyringFound*>(item->data);
+      ItemData::Ptr item_data = ItemData::get_instance_from_item_type(type);
+      item_data->keyring = found_item->keyring;
+      item_data->item_id = found_item->item_id;
+      item_data->secret = found_item->secret;
+      transfer_attributes(item_data, found_item);
+      res.push_back(item_data);
+    }
+    gnome_keyring_found_list_free(list);
+  }
+  else if(result != GNOME_KEYRING_RESULT_NO_MATCH) {
+    throw KeyringException(result);
+  }
+
+  return res;
+}
+
+GnomeKeyringItemType Ring::keyring_item_type(ItemType type)
+{
+  switch(type) {
+  case GENERIC_SECRET:
+    return GNOME_KEYRING_ITEM_GENERIC_SECRET;
+  case NETWORK_PASSWORD:
+    return GNOME_KEYRING_ITEM_NETWORK_PASSWORD;
+  case NOTE:
+  default:
+    return GNOME_KEYRING_ITEM_NOTE;
+  }
+}
+
+GnomeKeyringAttributeList *Ring::keyring_attributes(const std::map<std::string, std::string> & atts)
+{
+  GnomeKeyringAttributeList *list = gnome_keyring_attribute_list_new();
+  for(std::map<std::string, std::string>::const_iterator iter = atts.begin(); iter != atts.end(); ++iter) {
+    gnome_keyring_attribute_list_append_string(list, iter->first.c_str(), iter->second.c_str());
+  }
+  return list;
+}
+
+void Ring::transfer_attributes(ItemData::Ptr item_data, GnomeKeyringFound *found_item)
+{
+  if(!found_item->attributes) {
+    return;
+  }
+  for(unsigned i = 0; i < found_item->attributes->len; ++i) {
+    GnomeKeyringAttribute att = g_array_index(found_item->attributes, GnomeKeyringAttribute, i);
+    std::string value = att.type == GNOME_KEYRING_ATTRIBUTE_TYPE_STRING
+                          ? att.value.string
+                          : boost::lexical_cast<std::string>(att.value.integer);
+    item_data->attributes[att.name] = value;
+  }
+}
+
+std::string Ring::default_keyring()
+{
+  char *keyring = NULL;
+  GnomeKeyringResult result = gnome_keyring_get_default_keyring_sync(&keyring);
+  if(result == GNOME_KEYRING_RESULT_OK) {
+    std::string res;
+    if(keyring) {
+      res = keyring;
+      g_free(keyring);
+    }
+    return res;
+  }
+  throw KeyringException(result);
+}
+
+int Ring::create_item(const std::string & keyring, ItemType type, const std::string & displayName,
+                      const std::map<std::string, std::string> & attributes,
+                      const std::string & secret, bool updateIfExists)
+{
+  GnomeKeyringAttributeList *atts = keyring_attributes(attributes);
+  guint32 item_id = 0;
+  GnomeKeyringResult result = gnome_keyring_item_create_sync(keyring_c_str(keyring), keyring_item_type(type),
+                                                             displayName.c_str(), atts, secret.c_str(),
+                                                             updateIfExists ? TRUE : FALSE, &item_id);
+  gnome_keyring_attribute_list_free(atts);
+  if(result == GNOME_KEYRING_RESULT_OK) {
+    return item_id;
+  }
+  throw KeyringException(result);
+}
+
+void Ring::set_item_info(const std::string & keyring, int id, ItemType type,
+                         const std::string & displayName, const std::string & secret)
+{
+  GnomeKeyringItemInfo *info = gnome_keyring_item_info_new();
+  gnome_keyring_item_info_set_type(info, keyring_item_type(type));
+  gnome_keyring_item_info_set_display_name(info, displayName.c_str());
+  gnome_keyring_item_info_set_secret(info, secret.c_str());
+  GnomeKeyringResult result = gnome_keyring_item_set_info_sync(keyring_c_str(keyring), id, info);
+  gnome_keyring_item_info_free(info);
+  if(result != GNOME_KEYRING_RESULT_OK) {
+    throw KeyringException(result);
+  }
+}
+
+void Ring::set_item_attributes(const std::string & keyring, int id, const std::map<std::string, std::string> & atts)
+{
+  GnomeKeyringAttributeList *attributes = keyring_attributes(atts);
+  GnomeKeyringResult result = gnome_keyring_item_set_attributes_sync(keyring_c_str(keyring), id, attributes);
+  gnome_keyring_attribute_list_free(attributes);
+  if(result != GNOME_KEYRING_RESULT_OK) {
+    throw KeyringException(result);
+  }
+}
+
+const char * Ring::keyring_c_str(const std::string & keyring)
+{
+  const char *key_ring = NULL;
+  if(keyring != "") {
+    key_ring = keyring.c_str();
+  }
+  return key_ring;
+}
+
+}
+}
diff --git a/src/gnome_keyring/ring.hpp b/src/gnome_keyring/ring.hpp
new file mode 100644
index 0000000..e42f8a0
--- /dev/null
+++ b/src/gnome_keyring/ring.hpp
@@ -0,0 +1,55 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 2012 Aurimas Cernius
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _GNOME_KEYRING_RING_HPP_
+#define _GNOME_KEYRING_RING_HPP_
+
+#include <vector>
+
+#include <gnome-keyring.h>
+
+#include "itemdata.hpp"
+
+
+namespace gnome {
+namespace keyring {
+
+class Ring
+{
+public:
+  static std::vector<ItemData::Ptr> find(ItemType type, const std::map<std::string, std::string> & atts);
+  static std::string default_keyring();
+  static int create_item(const std::string & keyring, ItemType type, const std::string & displayName,
+                         const std::map<std::string, std::string> & attributes,
+                         const std::string & secret, bool updateIfExists);
+  static void set_item_info(const std::string & keyring, int id, ItemType type,
+                            const std::string & displayName, const std::string & secret);
+  static void set_item_attributes(const std::string & keyring, int id, const std::map<std::string, std::string> & atts);
+private:
+  static GnomeKeyringItemType keyring_item_type(ItemType type);
+  static GnomeKeyringAttributeList *keyring_attributes(const std::map<std::string, std::string> & atts);
+  static void transfer_attributes(ItemData::Ptr, GnomeKeyringFound*);
+  static const char * keyring_c_str(const std::string &);
+};
+
+}
+}
+
+#endif



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