[gnote] * Show addins in preferences.



commit 7d52fb042b94bf8c74be4cb8a47e43d37cb2d19b
Author: Hubert Figuiere <hub figuiere net>
Date:   Tue Apr 21 04:13:35 2009 -0400

      * Show addins in preferences.
---
 .gitignore                        |    1 +
 NEWS                              |    1 +
 configure.ac                      |    1 +
 src/Makefile.am                   |    2 +
 src/addinmanager.hpp              |    5 +
 src/addinpreferencefactory.cpp    |   31 ++++++
 src/addinpreferencefactory.hpp    |   45 ++++++++
 src/addins/addins.mk.in           |   12 ++
 src/addins/fixedwidth/Makefile.am |   11 +--
 src/preferencesdialog.cpp         |  208 ++++++++++++++++++++++++++++++++-----
 src/preferencesdialog.hpp         |   16 ++--
 src/sharp/addinstreemodel.cpp     |   80 ++++++++++++++
 src/sharp/addinstreemodel.hpp     |   75 +++++++++++++
 src/sharp/dynamicmodule.cpp       |   13 +++
 src/sharp/dynamicmodule.hpp       |    6 +
 15 files changed, 463 insertions(+), 44 deletions(-)

diff --git a/.gitignore b/.gitignore
index 9118a77..8b06d74 100644
--- a/.gitignore
+++ b/.gitignore
@@ -35,6 +35,7 @@ src/stringtest
 src/notetest
 src/dttest
 src/libgnote.a
+src/addins/addins.mk
 src/addins/fixedwidth/fixedwidth.so
 m4/intltool.m4
 m4/libtool.m4
diff --git a/NEWS b/NEWS
index d1dafe0..03ea873 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,7 @@ New features
 
   * Now support addins:
     - Fixed Width (Bug #578980)
+  * Show addins in preferences.
 
 Fixes:
 
diff --git a/configure.ac b/configure.ac
index b22bb48..1614703 100644
--- a/configure.ac
+++ b/configure.ac
@@ -185,6 +185,7 @@ data/icons/Makefile
 libtomboy/Makefile
 src/Makefile
 src/addins/Makefile
+src/addins/addins.mk
 src/addins/fixedwidth/Makefile
 po/Makefile.in
 po/Makefile
diff --git a/src/Makefile.am b/src/Makefile.am
index a94442e..6309493 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -42,6 +42,7 @@ gnote_SOURCES = main.cpp
 
 libgnote_a_SOURCES = \
 	base/singleton.hpp \
+	sharp/addinstreemodel.hpp sharp/addinstreemodel.cpp \
 	sharp/datetime.hpp sharp/datetime.cpp \
 	sharp/dynamicmodule.hpp sharp/dynamicmodule.cpp \
 	sharp/directory.hpp sharp/directory.cpp \
@@ -60,6 +61,7 @@ libgnote_a_SOURCES = \
 	abstractaddin.hpp abstractaddin.cpp \
 	actionmanager.hpp actionmanager.cpp \
 	addinmanager.hpp addinmanager.cpp \
+	addinpreferencefactory.hpp addinpreferencefactory.cpp \
 	applicationaddin.hpp \
 	contrast.hpp contrast.cpp \
 	debug.hpp debug.cpp \
diff --git a/src/addinmanager.hpp b/src/addinmanager.hpp
index 2312dc9..d05061a 100644
--- a/src/addinmanager.hpp
+++ b/src/addinmanager.hpp
@@ -49,6 +49,11 @@ public:
   void get_application_addins(std::list<ApplicationAddin*> &) const;
   void get_preference_tab_addins(std::list<PreferenceTabAddin *> &) const;
 
+  const sharp::ModuleList & get_modules() const
+    { 
+      return m_module_manager.get_modules(); 
+    }
+
   sigc::signal<void> & signal_application_addin_list_changed();
 private:
 
diff --git a/src/addinpreferencefactory.cpp b/src/addinpreferencefactory.cpp
new file mode 100644
index 0000000..771b639
--- /dev/null
+++ b/src/addinpreferencefactory.cpp
@@ -0,0 +1,31 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 2009 Hubert Figuiere
+ *
+ * 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 "addinpreferencefactory.hpp"
+
+namespace gnote {
+  
+const char * AddinPreferenceFactory::IFACE_NAME = "gnote::AddinPreferenceFactory";
+
+
+}
diff --git a/src/addinpreferencefactory.hpp b/src/addinpreferencefactory.hpp
new file mode 100644
index 0000000..8fac0ac
--- /dev/null
+++ b/src/addinpreferencefactory.hpp
@@ -0,0 +1,45 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 2009 Hubert Figuiere
+ *
+ * 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 __ADDIN_PREFERENCE_FACTORY_HPP_
+#define __ADDIN_PREFERENCE_FACTORY_HPP_
+
+#include <gtkmm/widget.h>
+
+#include "sharp/modulefactory.hpp"
+
+
+namespace gnote {
+
+class AddinPreferenceFactory
+  : public sharp::IInterface
+{
+public:
+  static const char * IFACE_NAME;
+  virtual Gtk::Widget * create_preference_widget() = 0;
+};
+
+};
+
+
+#endif
+
diff --git a/src/addins/addins.mk.in b/src/addins/addins.mk.in
new file mode 100644
index 0000000..c74d120
--- /dev/null
+++ b/src/addins/addins.mk.in
@@ -0,0 +1,12 @@
+
+
+
+INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/src
+
+AM_CPPFLAGS= LIBGTKMM_CFLAGS@ @LIBGLIBMM_CFLAGS@ \
+	@GCONF_CFLAGS@ \
+	-DDATADIR=\"$(datadir)\" -DLIBDIR=\"$(libdir)\"
+
+AM_LDFLAGS = -avoid-version -module -Wl,--export-dynamic
+
+ADDINSDIR = @libdir@/@PACKAGE_NAME@/addins/@VERSION@
diff --git a/src/addins/fixedwidth/Makefile.am b/src/addins/fixedwidth/Makefile.am
index b40e258..248f192 100644
--- a/src/addins/fixedwidth/Makefile.am
+++ b/src/addins/fixedwidth/Makefile.am
@@ -1,14 +1,7 @@
 
+include $(builddir)/../addins.mk
 
-
-INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/src
-AM_CPPFLAGS= LIBGTKMM_CFLAGS@ @LIBGLIBMM_CFLAGS@ \
-	@GCONF_CFLAGS@ \
-	-DDATADIR=\"$(datadir)\" -DLIBDIR=\"$(libdir)\"
-
-AM_LDFLAGS = -avoid-version -module -Wl,--export-dynamic
-
-addinsdir = @libdir@/@PACKAGE_NAME@/addins/@VERSION@
+addinsdir = $(ADDINSDIR)
 addins_LTLIBRARIES = fixedwidth.la
 
 
diff --git a/src/preferencesdialog.cpp b/src/preferencesdialog.cpp
index 51a9a94..6793e7b 100644
--- a/src/preferencesdialog.cpp
+++ b/src/preferencesdialog.cpp
@@ -37,8 +37,11 @@
 #include <gtkmm/stock.h>
 #include <gtkmm/table.h>
 
+#include "sharp/addinstreemodel.hpp"
+#include "sharp/modulemanager.hpp"
 #include "sharp/propertyeditor.hpp"
 #include "addinmanager.hpp"
+#include "addinpreferencefactory.hpp"
 #include "debug.hpp"
 #include "gnote.hpp"
 #include "notemanager.hpp"
@@ -51,6 +54,22 @@
 
 namespace gnote {
 
+  class AddinInfoDialog
+    : public Gtk::Dialog
+  {
+  public:
+    AddinInfoDialog(const sharp::DynamicModule * module, Gtk::Dialog &parent);
+    void set_addin_id(const std::string & id)
+      { m_id = id; }
+    const std::string & get_addin_id() const
+      { return m_id; }
+  private:
+    void fill(Gtk::Label &);
+    const sharp::DynamicModule *m_module;
+    std::string m_id;
+  };
+
+
   PreferencesDialog::PreferencesDialog(AddinManager & addinmanager)
     : Gtk::Dialog()
     , syncAddinCombo(NULL)
@@ -520,16 +539,16 @@ namespace gnote {
     Gtk::HBox *hbox = manage(new Gtk::HBox (false, 6));
 
     // TreeView of Add-ins
-    Gtk::TreeView *tree = manage(new Gtk::TreeView ());
-//    addin_tree = new Mono.Addins.Gui.AddinTreeWidget (tree);
+    m_addin_tree = manage(new Gtk::TreeView ());
+    m_addin_tree_model = sharp::AddinsTreeModel::create(m_addin_tree);
 
-    tree->show ();
+    m_addin_tree->show ();
 
     Gtk::ScrolledWindow *sw = manage(new Gtk::ScrolledWindow ());
     sw->property_hscrollbar_policy() = Gtk::POLICY_AUTOMATIC;
     sw->property_vscrollbar_policy() = Gtk::POLICY_AUTOMATIC;
     sw->set_shadow_type(Gtk::SHADOW_IN);
-    sw->add (*tree);
+    sw->add (*m_addin_tree);
     sw->show ();
     hbox->pack_start(*sw, true, true, 0);
 
@@ -578,7 +597,7 @@ namespace gnote {
     vbox->pack_start(*hbox, true, true, 0);
     vbox->show ();
 
-    tree->get_selection()->signal_changed().connect(
+    m_addin_tree->get_selection()->signal_changed().connect(
       sigc::mem_fun(*this, &PreferencesDialog::on_addin_tree_selection_changed));
     load_addins ();
 
@@ -586,6 +605,19 @@ namespace gnote {
   }
 
 
+  const sharp::DynamicModule * PreferencesDialog::get_selected_addin()
+  {
+    /// TODO really set
+    Glib::RefPtr<Gtk::TreeSelection> select = m_addin_tree->get_selection();
+    Gtk::TreeIter iter = select->get_selected();
+    const sharp::DynamicModule * module = NULL;
+    if(iter) {
+      module = m_addin_tree_model->get_module(iter);
+    }
+    return module;
+  }
+
+
   void PreferencesDialog::on_addin_tree_selection_changed()
   {
     update_addin_buttons();
@@ -595,17 +627,32 @@ namespace gnote {
   /// Set the sensitivity of the buttons based on what is selected
   void PreferencesDialog::update_addin_buttons()
   {
-    /// TODO really set
-    enable_addin_button->set_sensitive(false);
-    disable_addin_button->set_sensitive(false);
-    addin_prefs_button->set_sensitive(false);
-    addin_info_button->set_sensitive(false);
+    const sharp::DynamicModule * module = get_selected_addin();
+    if(module) {
+      enable_addin_button->set_sensitive(!module->enabled());
+      disable_addin_button->set_sensitive(module->enabled());
+      addin_prefs_button->set_sensitive(
+        module->has_interface(AddinPreferenceFactory::IFACE_NAME));
+      addin_info_button->set_sensitive(true);
+    }
+    else {
+      enable_addin_button->set_sensitive(false);
+      disable_addin_button->set_sensitive(false);
+      addin_prefs_button->set_sensitive(false);
+      addin_info_button->set_sensitive(false);
+    }
   }
 
 
   void PreferencesDialog::load_addins()
   {
     ///// TODO populate
+    const sharp::ModuleList & list(m_addin_manager.get_modules());
+    for(sharp::ModuleList::const_iterator iter = list.begin();
+        iter != list.end(); ++iter) {
+
+      Gtk::TreeIter treeiter = m_addin_tree_model->append(*iter);
+    }
 
     update_addin_buttons();
   }
@@ -624,6 +671,7 @@ namespace gnote {
 
   void PreferencesDialog::on_addin_prefs_button()
   {
+    const sharp::DynamicModule * module = get_selected_addin();
 #if 0
     Gtk::Dialog dialog = null;
 //    Mono.Addins.Addin addin =
@@ -652,7 +700,6 @@ namespace gnote {
       Gtk::HBox hbox = new Gtk::HBox (false, 6);
       Gtk::VBox vbox = new Gtk::VBox (false, 6);
       vbox.BorderWidth = 6;
-
       hbox.PackStart (icon, false, false, 0);
       hbox.PackStart (caption, true, true, 0);
       vbox.PackStart (hbox, false, false, 0);
@@ -688,35 +735,60 @@ namespace gnote {
 
   void PreferencesDialog::on_addin_info_button()
   {
-#if 0
-    Mono.Addins.Addin addin =
-      addin_tree.ActiveAddinData as Mono.Addins.Addin;
+    const sharp::DynamicModule * addin = get_selected_addin();
 
-    if (addin == null)
+    if (addin == NULL) {
       return;
+    }
 
-    Gtk.Dialog dialog = null;
-    if (addin_info_dialogs.ContainsKey (addin.Id) == false) {
-      dialog = new AddinInfoDialog (
-        Mono.Addins.Setup.SetupService.GetAddinHeader (addin),
-        this);
-      dialog.DeleteEvent += AddinInfoDialogDeleted;
-      dialog.Response += AddinInfoDialogResponse;
+    Gtk::Dialog* dialog;
+    std::map<std::string, Gtk::Dialog* >::iterator iter;
+    iter = addin_info_dialogs.find(addin->id());
+    if (iter == addin_info_dialogs.end()) {
+      dialog = manage(new AddinInfoDialog (addin, *this));
+      dialog->signal_delete_event().connect(
+        sigc::bind(
+          sigc::mem_fun(*this, &PreferencesDialog::addin_info_dialog_deleted), 
+          dialog), false);
+      dialog->signal_response().connect(
+        sigc::bind(
+          sigc::mem_fun(*this, &PreferencesDialog::addin_info_dialog_response),
+          dialog));
 
       // Store this dialog off in a dictionary so it can be presented
       // again if the user clicks on the Info button before closing
       // the original dialog.
-      dialog.Data ["AddinId"] = addin.Id;
-      addin_info_dialogs [addin.Id] = dialog;
-    } else {
+      static_cast<AddinInfoDialog*>(dialog)->set_addin_id(addin->id());
+      addin_info_dialogs [addin->id()] = dialog;
+    } 
+    else {
       // It's already opened so just present it again
-      dialog = addin_info_dialogs [addin.Id];
+      dialog = iter->second;
     }
 
-    dialog.Present ();
-#endif
+    dialog->present ();
   }
 
+  bool PreferencesDialog::addin_info_dialog_deleted(GdkEventAny*, 
+                                                    Gtk::Dialog* dialog)
+  {
+    // Remove the addin from the addin_prefs_dialogs Dictionary
+    dialog->hide ();
+
+    AddinInfoDialog *addin_dialog = static_cast<AddinInfoDialog*>(dialog);
+    addin_prefs_dialogs.erase(addin_dialog->get_addin_id());
+
+    return false;
+  }
+
+
+  void PreferencesDialog::addin_info_dialog_response(int, Gtk::Dialog* dlg)
+  {
+    addin_info_dialog_deleted(NULL, dlg);
+  }
+
+
+
   Gtk::Label *PreferencesDialog::make_label (const std::string & label_text/*, params object[] args*/)
   {
 //    if (args.Length > 0)
@@ -800,5 +872,85 @@ namespace gnote {
     template_note->get_window()->show ();
   }
 
+
+
+  AddinInfoDialog::AddinInfoDialog(const sharp::DynamicModule * module,
+                                   Gtk::Dialog &parent)
+    : Gtk::Dialog(module->name(), parent, false, true)
+    , m_module(module)
+  {
+    property_destroy_with_parent() = true;
+    add_button(Gtk::Stock::CLOSE, Gtk::RESPONSE_CLOSE);
+    
+    // TODO: Change this icon to be an addin/package icon
+    Gtk::Image *icon = manage(new Gtk::Image(Gtk::Stock::INFO, 
+                                             Gtk::ICON_SIZE_DIALOG));
+    icon->property_yalign() = 0;
+
+    Gtk::Label *info_label = manage(new Gtk::Label ());
+    info_label->property_xalign() = 0;
+    info_label->property_yalign() = 0;
+    info_label->set_use_markup(true);
+    info_label->set_use_underline(false);
+    info_label->property_wrap() = true;
+
+    Gtk::HBox *hbox = manage(new Gtk::HBox (false, 6));
+    Gtk::VBox *vbox = manage(new Gtk::VBox (false, 12));
+    hbox->set_border_width(12);
+    vbox->set_border_width(6);
+
+    hbox->pack_start (*icon, false, false, 0);
+    hbox->pack_start (*vbox, true, true, 0);
+
+    vbox->pack_start (*info_label, true, true, 0);
+
+    hbox->show_all ();
+
+    get_vbox()->pack_start(*hbox, true, true, 0);
+
+    fill (*info_label);
+  }
+
+	void AddinInfoDialog::fill(Gtk::Label & info_label)
+  {
+    std::string sb("<b><big>");
+    sb += std::string(m_module->name()) + "</big></b>\n\n";
+
+    const char * s = m_module->description();
+    if (s && *s) {
+      sb += std::string(s) + "\n\n";
+    }
+
+    sb += str(boost::format("<small><b>%1%</b>\n%2%\n\n")
+              % _("Version:") % m_module->version());
+
+    s = m_module->authors();
+    if (s && *s) {
+      sb += str(boost::format("<b>%1%</b>\n%2%\n\n")
+                % _("Author:") % s);
+    }
+    
+    s = m_module->copyright();
+    if (s && *s) {
+      sb += str(boost::format("<b>%1%</b>\n%2%\n\n") 
+                % _("Copyright:") % s);
+    }
+
+#if 0 // TODO handle module dependencies
+    if (info.Dependencies.Count > 0) {
+      sb.Append (string.Format (
+                   "<b>{0}</b>\n",
+                   Catalog.GetString ("Add-in Dependencies:")));
+      foreach (Mono.Addins.Description.Dependency dep in info.Dependencies) {
+        sb.Append (dep.Name + "\n");
+      }
+    }
+#endif
+
+    sb += "</small>";
+
+    info_label.set_markup(sb);
+  }
+
 }
 
diff --git a/src/preferencesdialog.hpp b/src/preferencesdialog.hpp
index 0aad3eb..d509178 100644
--- a/src/preferencesdialog.hpp
+++ b/src/preferencesdialog.hpp
@@ -31,6 +31,8 @@
 #include <gtkmm/liststore.h>
 #include <gtkmm/combobox.h>
 
+#include "sharp/addinstreemodel.hpp"
+
 namespace gnote {
 
 class SyncServiceAddin;
@@ -62,6 +64,7 @@ private:
   void on_reset_sync_addin_button();
   void on_save_sync_addin_button();
 
+  const sharp::DynamicModule * get_selected_addin();
   void on_addin_tree_selection_changed();
   void update_addin_buttons();
   void load_addins();
@@ -69,6 +72,8 @@ private:
   void on_disable_addin_button();
   void on_addin_prefs_button();
   void on_addin_info_button();
+  bool addin_info_dialog_deleted(GdkEventAny*, Gtk::Dialog*);
+  void addin_info_dialog_response(int, Gtk::Dialog*);
 ////
 
   class SyncStoreModel
@@ -98,7 +103,8 @@ private:
   Gtk::Label  *font_face;
   Gtk::Label  *font_size;
 
-  //Mono.Addins.Gui.AddinTreeWidget addin_tree;
+  Gtk::TreeView              *m_addin_tree;
+  sharp::AddinsTreeModel::Ptr m_addin_tree_model;
   
   Gtk::Button *enable_addin_button;
   Gtk::Button *disable_addin_button;
@@ -110,20 +116,16 @@ private:
   Gtk::RadioButton overwriteOnConflictRadio;
 
 
-  /// <summary>
   /// Keep track of the opened addin prefs dialogs so other windows
   /// can be interacted with (as opposed to opening these as modal
   /// dialogs).
   ///
   /// Key = Mono.Addins.Addin.Id
-  /// </summary>
-  std::map<std::string, Gtk::Dialog> addin_prefs_dialogs;
+  std::map<std::string, Gtk::Dialog* > addin_prefs_dialogs;
 
-  /// <summary>
   /// Used to keep track of open AddinInfoDialogs.
   /// Key = Mono.Addins.Addin.Id
-  /// </summary>
-  std::map<std::string, Gtk::Dialog> addin_info_dialogs;
+  std::map<std::string, Gtk::Dialog* > addin_info_dialogs;
 
 };
 
diff --git a/src/sharp/addinstreemodel.cpp b/src/sharp/addinstreemodel.cpp
new file mode 100644
index 0000000..c69c014
--- /dev/null
+++ b/src/sharp/addinstreemodel.cpp
@@ -0,0 +1,80 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 2009 Hubert Figuiere
+ * 
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+
+
+#include <glibmm/i18n.h>
+
+#include "sharp/addinstreemodel.hpp"
+
+
+
+namespace sharp {
+
+
+  AddinsTreeModel::Ptr AddinsTreeModel::create(Gtk::TreeView * treeview)
+  {
+    AddinsTreeModel::Ptr p(new AddinsTreeModel());
+    if(treeview) {
+      treeview->set_model(p);
+      p->set_columns(treeview);
+    }
+    return p;
+  }
+
+  AddinsTreeModel::AddinsTreeModel()
+    : Gtk::TreeStore()
+  {
+    set_column_types(m_columns);
+  }
+
+  const sharp::DynamicModule * AddinsTreeModel::get_module(const Gtk::TreeIter & iter)
+  {
+    const sharp::DynamicModule * module = NULL;
+    if(iter) {
+      iter->get_value(2, module);
+    }
+    return module;
+  }
+
+
+  void AddinsTreeModel::set_columns(Gtk::TreeView *treeview)
+  {
+      treeview->append_column(_("Name"), m_columns.name);
+      treeview->append_column(_("Description"), m_columns.description);
+  }
+
+
+  Gtk::TreeIter AddinsTreeModel::append(const sharp::DynamicModule *module)
+  {
+    Gtk::TreeIter iter = Gtk::TreeStore::append();
+    iter->set_value(0, std::string(module->name()));
+    iter->set_value(1, std::string(module->description()));
+    iter->set_value(2, module);
+    return iter;
+  }
+
+
+
+}
diff --git a/src/sharp/addinstreemodel.hpp b/src/sharp/addinstreemodel.hpp
new file mode 100644
index 0000000..03a0a6c
--- /dev/null
+++ b/src/sharp/addinstreemodel.hpp
@@ -0,0 +1,75 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 2009 Hubert Figuiere
+ * 
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+
+
+
+#ifndef __SHARP_ADDINSTREEMODEL_HPP_
+#define __SHARP_ADDINSTREEMODEL_HPP_
+
+#include <gtkmm/treestore.h>
+#include <gtkmm/treeview.h>
+
+#include "sharp/dynamicmodule.hpp"
+
+namespace sharp {
+
+class AddinsTreeModel
+  : public Gtk::TreeStore
+{
+public:
+  typedef Glib::RefPtr<AddinsTreeModel> Ptr;
+  static Ptr create(Gtk::TreeView * treeview);
+
+  const sharp::DynamicModule * get_module(const Gtk::TreeIter &);
+
+  Gtk::TreeIter append(const sharp::DynamicModule *);
+  class AddinsColumns
+    : public Gtk::TreeModelColumnRecord
+  {
+  public:
+    AddinsColumns()
+      {
+        add(name); 
+        add(description); 
+        add(addin);
+      }
+
+    Gtk::TreeModelColumn<std::string>          name;
+    Gtk::TreeModelColumn<std::string>          description;
+    Gtk::TreeModelColumn<const sharp::DynamicModule *> addin;
+  };
+  AddinsColumns m_columns;
+
+protected:
+  AddinsTreeModel();
+  void set_columns(Gtk::TreeView *v);
+private:
+  
+};
+
+}
+
+
+#endif
diff --git a/src/sharp/dynamicmodule.cpp b/src/sharp/dynamicmodule.cpp
index a77da2f..d44f921 100644
--- a/src/sharp/dynamicmodule.cpp
+++ b/src/sharp/dynamicmodule.cpp
@@ -32,6 +32,7 @@
 namespace sharp {
 
   DynamicModule::DynamicModule()
+    : m_enabled(true)
   {
   }
 
@@ -41,6 +42,11 @@ namespace sharp {
     sharp::map_delete_all_second(m_interfaces);
   }
 
+  const char * DynamicModule::copyright() const
+  {
+    return "";
+  }
+
   
   IfaceFactoryBase * DynamicModule::query_interface(const char * intf) const
   {
@@ -53,6 +59,13 @@ namespace sharp {
     return iter->second;
   }
 
+  bool DynamicModule::has_interface(const char * intf) const
+  {
+    std::map<std::string, IfaceFactoryBase *>::const_iterator iter;
+    iter = m_interfaces.find(intf);
+    return (iter != m_interfaces.end());
+  }
+
 
   void DynamicModule::add(const char * iface, IfaceFactoryBase* mod)
   {
diff --git a/src/sharp/dynamicmodule.hpp b/src/sharp/dynamicmodule.hpp
index c542e1a..a215bfd 100644
--- a/src/sharp/dynamicmodule.hpp
+++ b/src/sharp/dynamicmodule.hpp
@@ -55,6 +55,11 @@ public:
   virtual const char * authors() const = 0;
   virtual const char * category() const = 0;
   virtual const char * version() const = 0;
+  virtual const char * copyright() const;
+  bool enabled() const
+    {
+      return m_enabled;
+    }
   /** Query an "interface" 
    * may return NULL
    */
@@ -71,6 +76,7 @@ protected:
   void add(const char * iface, IfaceFactoryBase*);
   
 private:
+  bool m_enabled;
   std::map<std::string, IfaceFactoryBase *> m_interfaces;
 };
 



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