[gnote] Add support for custom plugin attributes



commit cf053204af76b9af59f13f9984a5b114984e2005
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Sat Mar 1 18:54:33 2014 +0200

    Add support for custom plugin attributes

 src/addininfo.cpp |   20 +++++++++++++++++++-
 src/addininfo.hpp |   13 ++++++++++++-
 2 files changed, 31 insertions(+), 2 deletions(-)
---
diff --git a/src/addininfo.cpp b/src/addininfo.cpp
index 715f86b..bc4da94 100644
--- a/src/addininfo.cpp
+++ b/src/addininfo.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2013 Aurimas Cernius
+ * Copyright (C) 2013-2014 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
@@ -22,6 +22,7 @@
 #include <glibmm/i18n.h>
 #include <glibmm/keyfile.h>
 
+#include "base/macros.hpp"
 #include "addininfo.hpp"
 #include "debug.hpp"
 
@@ -31,6 +32,7 @@ namespace gnote {
   namespace {
 
     const char * ADDIN_INFO = "AddinInfo";
+    const char * ADDIN_ATTS = "AddinAttributes";
 
     AddinCategory resolve_addin_category(const std::string & cat)
     {
@@ -87,10 +89,26 @@ void AddinInfo::load_from_file(const std::string & info_file)
       DBG_OUT("Can't read default enabled status, assuming default: %s", e.what().c_str());
     }
     m_addin_module = addin_info.get_string(ADDIN_INFO, "Module");
+
+    if(addin_info.has_group(ADDIN_ATTS)) {
+      FOREACH(const Glib::ustring & key, addin_info.get_keys(ADDIN_ATTS)) {
+        m_attributes[key] = addin_info.get_string(ADDIN_ATTS, key);
+      }
+    }
   }
   catch(Glib::Error & e) {
     throw std::runtime_error(e.what());
   }
 }
 
+Glib::ustring AddinInfo::get_attribute(const Glib::ustring & att)
+{
+  std::map<Glib::ustring, Glib::ustring>::iterator iter = m_attributes.find(att);
+  if(iter != m_attributes.end()) {
+    return iter->second;
+  }
+  return Glib::ustring();
+}
+
+
 }
diff --git a/src/addininfo.hpp b/src/addininfo.hpp
index 4dc9c88..096aed4 100644
--- a/src/addininfo.hpp
+++ b/src/addininfo.hpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2013 Aurimas Cernius
+ * Copyright (C) 2013-2014 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
@@ -21,6 +21,10 @@
 #define _ADDININFO_HPP_
 
 #include <string>
+#include <map>
+
+#include <glibmm/ustring.h>
+
 
 namespace gnote {
 
@@ -80,6 +84,11 @@ public:
     {
       m_addin_module = module;
     }
+  const std::map<Glib::ustring, Glib::ustring> & attributes()
+    {
+      return m_attributes;
+    }
+  Glib::ustring get_attribute(const Glib::ustring & att);
 private:
   std::string m_id;
   std::string m_name;
@@ -90,6 +99,8 @@ private:
   std::string m_copyright;
   bool m_default_enabled;
   std::string m_addin_module;
+
+  std::map<Glib::ustring, Glib::ustring> m_attributes;
 };
 
 }


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