[gnote] Show addin categories and versions
- From: Aurimas Černius <aurimasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnote] Show addin categories and versions
- Date: Thu, 30 Dec 2010 20:44:47 +0000 (UTC)
commit aa2411a5418e0b97cf3f098acc50f6573c90f534
Author: Aurimas Ä?ernius <aurisc4 gmail com>
Date: Wed Dec 29 23:15:15 2010 +0200
Show addin categories and versions
Replace description column with version and make tree of categories
in preferences dialog addins tab.
Display addin categories as localizable strings.
Add `Unknown' category and use it as default fallback.
Fixes Bug 620402.
src/abstractaddin.hpp | 2 +
src/sharp/addinstreemodel.cpp | 95 ++++++++++++++++++++++++++++++++++++++--
src/sharp/addinstreemodel.hpp | 14 ++++--
3 files changed, 102 insertions(+), 9 deletions(-)
---
diff --git a/src/abstractaddin.hpp b/src/abstractaddin.hpp
index 9007581..69dbb01 100644
--- a/src/abstractaddin.hpp
+++ b/src/abstractaddin.hpp
@@ -1,6 +1,7 @@
/*
* gnote
*
+ * Copyright (C) 2010 Aurimas Cernius
* Copyright (C) 2009 Hubert Figuiere
*
* This program is free software: you can redistribute it and/or modify
@@ -30,6 +31,7 @@
namespace gnote {
enum {
+ ADDIN_CATEGORY_UNKNOWN,
ADDIN_CATEGORY_TOOLS,
ADDIN_CATEGORY_FORMATTING,
ADDIN_CATEGORY_DESKTOP_INTEGRATION
diff --git a/src/sharp/addinstreemodel.cpp b/src/sharp/addinstreemodel.cpp
index 3d6c0bc..cb180fa 100644
--- a/src/sharp/addinstreemodel.cpp
+++ b/src/sharp/addinstreemodel.cpp
@@ -1,6 +1,7 @@
/*
* gnote
*
+ * Copyright (C) 2010 Aurimas Cernius
* Copyright (C) 2009 Hubert Figuiere
*
* Permission is hereby granted, free of charge, to any person obtaining a
@@ -27,7 +28,8 @@
#include <glibmm/i18n.h>
#include "sharp/addinstreemodel.hpp"
-
+#include "utils.hpp"
+#include "abstractaddin.hpp"
namespace sharp {
@@ -58,23 +60,106 @@ namespace sharp {
return module;
}
+ void AddinsTreeModel::name_cell_data_func(Gtk::CellRenderer * renderer,
+ const Gtk::TreeIter & iter)
+ {
+ Gtk::CellRendererText *text_renderer = dynamic_cast<Gtk::CellRendererText*>(renderer);
+ std::string value;
+ iter->get_value(0, value);
+ text_renderer->property_text() = value;
+ const sharp::DynamicModule *module = get_module(iter);
+ if(!module || module->is_enabled()) {
+ text_renderer->property_foreground() = "black";
+ }
+ else {
+ text_renderer->property_foreground() = "grey";
+ }
+ }
+
+ void AddinsTreeModel::name_pixbuf_cell_data_func(Gtk::CellRenderer * renderer,
+ const Gtk::TreeIter & iter)
+ {
+ Gtk::CellRendererPixbuf *icon_renderer = dynamic_cast<Gtk::CellRendererPixbuf*>(renderer);
+ Glib::RefPtr<Gdk::Pixbuf> icon;
+ if(get_module(iter)) {
+ icon = gnote::utils::get_icon("emblem-package", 22);
+ }
+ icon_renderer->property_pixbuf() = icon;
+ }
void AddinsTreeModel::set_columns(Gtk::TreeView *treeview)
{
- treeview->append_column(_("Name"), m_columns.name);
- treeview->append_column(_("Description"), m_columns.description);
+ Gtk::TreeViewColumn *column = manage(new Gtk::TreeViewColumn);
+ column->set_title(_("Name"));
+ column->set_sizing(Gtk::TREE_VIEW_COLUMN_AUTOSIZE);
+ column->set_resizable(false);
+ Gtk::CellRendererPixbuf *icon_renderer = manage(new Gtk::CellRendererPixbuf);
+ column->pack_start(*icon_renderer, false);
+ column->set_cell_data_func(*icon_renderer,
+ sigc::mem_fun(*this, &AddinsTreeModel::name_pixbuf_cell_data_func));
+ Gtk::CellRenderer *renderer = manage(new Gtk::CellRendererText);
+ column->pack_start(*renderer, true);
+ column->set_cell_data_func(*renderer,
+ sigc::mem_fun(*this, &AddinsTreeModel::name_cell_data_func));
+ treeview->append_column(*column);
+ treeview->append_column(_("Version"), m_columns.version);
}
Gtk::TreeIter AddinsTreeModel::append(const sharp::DynamicModule *module)
{
- Gtk::TreeIter iter = Gtk::TreeStore::append();
+ int category = module->category();
+ Gtk::TreeIter iter = children().begin();
+ while(iter != children().end()) {
+ int row_value;
+ iter->get_value(3, row_value);
+ if(row_value == category)
+ break;
+ else ++iter;
+ }
+ if(iter == children().end()) {
+ iter = Gtk::TreeStore::append();
+ category = ensure_valid_addin_category(category);
+ iter->set_value(0, get_addin_category_name(category));
+ iter->set_value(3, category);
+ }
+ iter = Gtk::TreeStore::append(iter->children());
iter->set_value(0, std::string(module->name()));
- iter->set_value(1, std::string(module->description()));
+ iter->set_value(1, std::string(module->version()));
iter->set_value(2, module);
return iter;
}
+ std::string AddinsTreeModel::get_addin_category_name(int category)
+ {
+ switch(category) {
+ case gnote::ADDIN_CATEGORY_FORMATTING:
+ /* TRANSLATORS: Addin category. */
+ return _("Formatting");
+ case gnote::ADDIN_CATEGORY_DESKTOP_INTEGRATION:
+ /* TRANSLATORS: Addin category. */
+ return _("Desktop integration");
+ case gnote::ADDIN_CATEGORY_TOOLS:
+ /* TRANSLATORS: Addin category. */
+ return _("Tools");
+ case gnote::ADDIN_CATEGORY_UNKNOWN:
+ default:
+ /* TRANSLATORS: Addin category is unknown. */
+ return _("Unknown");
+ }
+ }
+ int AddinsTreeModel::ensure_valid_addin_category(int category)
+ {
+ switch(category) {
+ case gnote::ADDIN_CATEGORY_FORMATTING:
+ case gnote::ADDIN_CATEGORY_DESKTOP_INTEGRATION:
+ case gnote::ADDIN_CATEGORY_TOOLS:
+ return category;
+ case gnote::ADDIN_CATEGORY_UNKNOWN:
+ default:
+ return gnote::ADDIN_CATEGORY_UNKNOWN;
+ }
+ }
}
diff --git a/src/sharp/addinstreemodel.hpp b/src/sharp/addinstreemodel.hpp
index 625d266..bd108fe 100644
--- a/src/sharp/addinstreemodel.hpp
+++ b/src/sharp/addinstreemodel.hpp
@@ -1,6 +1,7 @@
/*
* gnote
*
+ * Copyright (C) 2010 Aurimas Cernius
* Copyright (C) 2009 Hubert Figuiere
*
* Permission is hereby granted, free of charge, to any person obtaining a
@@ -51,22 +52,27 @@ public:
public:
AddinsColumns()
{
- add(name);
- add(description);
+ add(name);
+ add(version);
add(addin);
+ add(category);
}
Gtk::TreeModelColumn<std::string> name;
- Gtk::TreeModelColumn<std::string> description;
+ Gtk::TreeModelColumn<std::string> version;
Gtk::TreeModelColumn<const sharp::DynamicModule *> addin;
+ Gtk::TreeModelColumn<int> category;
};
AddinsColumns m_columns;
+ static std::string get_addin_category_name(int category);
+ static int ensure_valid_addin_category(int category);
protected:
AddinsTreeModel();
void set_columns(Gtk::TreeView *v);
private:
-
+ void name_cell_data_func(Gtk::CellRenderer * renderer, const Gtk::TreeIter & iter);
+ void name_pixbuf_cell_data_func(Gtk::CellRenderer * renderer, const Gtk::TreeIter & iter);
};
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]