[gnote] Add IconManager
- From: Aurimas Äernius <aurimasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnote] Add IconManager
- Date: Sun, 18 Nov 2012 16:03:17 +0000 (UTC)
commit e0e9a4733b30d2d7716398c8e3acf77ccfa85b87
Author: Aurimas Äernius <aurisc4 gmail com>
Date: Sun Nov 11 23:06:19 2012 +0200
Add IconManager
Manage icons loaded by Gnote.
Remove utils::get_icon, replacing by IconManager.
src/Makefile.am | 1 +
src/actionmanager.cpp | 6 +--
src/actionmanager.hpp | 5 --
src/addins/backlinks/backlinkmenuitem.cpp | 11 +----
src/addins/backlinks/backlinkmenuitem.hpp | 4 +-
src/addins/bugzilla/bugzillalink.cpp | 13 +----
src/addins/bugzilla/bugzillalink.hpp | 3 +-
src/gnote.cpp | 3 +-
src/iconmanager.cpp | 64 ++++++++++++++++++++++++++++
src/iconmanager.hpp | 57 +++++++++++++++++++++++++
src/notebooks/createnotebookdialog.cpp | 8 +--
src/notebooks/notebookapplicationaddin.cpp | 12 +++--
src/notebooks/notebookapplicationaddin.hpp | 2 -
src/notebooks/notebooknewnotemenuitem.cpp | 3 +-
src/notebooks/notebooknoteaddin.cpp | 21 ++-------
src/notebooks/notebooknoteaddin.hpp | 6 +--
src/notewindow.cpp | 27 +++++-------
src/notewindow.hpp | 6 +--
src/recentchanges.cpp | 3 +-
src/searchnoteswidget.cpp | 35 +++++----------
src/searchnoteswidget.hpp | 8 +---
src/sharp/addinstreemodel.cpp | 4 +-
src/synchronization/syncdialog.cpp | 3 +-
src/tray.cpp | 46 ++++++++++----------
src/tray.hpp | 11 +----
src/utils.cpp | 14 +------
src/utils.hpp | 3 -
27 files changed, 210 insertions(+), 169 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 52ca978..7e80ea1 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -106,6 +106,7 @@ libgnote_la_SOURCES = \
applicationaddin.cpp \
contrast.hpp contrast.cpp \
debug.hpp debug.cpp \
+ iconmanager.hpp iconmanager.cpp \
importaddin.hpp importaddin.cpp \
keybinder.hpp \
noteaddin.hpp noteaddin.cpp \
diff --git a/src/actionmanager.cpp b/src/actionmanager.cpp
index 4e5fd46..d6ea701 100644
--- a/src/actionmanager.cpp
+++ b/src/actionmanager.cpp
@@ -65,7 +65,7 @@
#include "sharp/xml.hpp"
#include "debug.hpp"
#include "actionmanager.hpp"
-#include "utils.hpp"
+#include "iconmanager.hpp"
namespace gnote {
@@ -82,8 +82,6 @@ namespace gnote {
populate_action_groups();
make_app_actions();
make_app_menu_items();
- m_newNote = utils::get_icon("note-new", 16);
- DBG_ASSERT(m_newNote, "note-new icon not found");
}
@@ -97,7 +95,7 @@ namespace gnote {
"/TrayIconMenu/TrayNewNotePlaceholder/TrayNewNote");
DBG_ASSERT(imageitem, "Item not found");
if (imageitem) {
- imageitem->set_image(*manage(new Gtk::Image(m_newNote)));
+ imageitem->set_image(*manage(new Gtk::Image(IconManager::obj().get_icon(IconManager::NOTE_NEW, 16))));
}
}
diff --git a/src/actionmanager.hpp b/src/actionmanager.hpp
index 306e329..e2be923 100644
--- a/src/actionmanager.hpp
+++ b/src/actionmanager.hpp
@@ -63,10 +63,6 @@ public:
{
return m_ui;
}
- Glib::RefPtr<Gdk::Pixbuf> get_new_note() const
- {
- return m_newNote;
- }
Glib::RefPtr<Gio::SimpleAction> get_app_action(const std::string & name) const;
const std::vector<Glib::RefPtr<Gio::SimpleAction> > & get_app_actions() const
{
@@ -83,7 +79,6 @@ private:
Glib::RefPtr<Gtk::UIManager> m_ui;
Glib::RefPtr<Gtk::ActionGroup> m_main_window_actions;
- Glib::RefPtr<Gdk::Pixbuf> m_newNote;
std::vector<Glib::RefPtr<Gio::SimpleAction> > m_app_actions;
diff --git a/src/addins/backlinks/backlinkmenuitem.cpp b/src/addins/backlinks/backlinkmenuitem.cpp
index 0087044..b830c2f 100644
--- a/src/addins/backlinks/backlinkmenuitem.cpp
+++ b/src/addins/backlinks/backlinkmenuitem.cpp
@@ -20,21 +20,16 @@
#include "gnote.hpp"
+#include "iconmanager.hpp"
#include "notewindow.hpp"
#include "backlinkmenuitem.hpp"
namespace backlinks {
-Glib::RefPtr<Gdk::Pixbuf> BacklinkMenuItem::s_note_icon;
-
-
-const Glib::RefPtr<Gdk::Pixbuf> & BacklinkMenuItem::get_note_icon()
+Glib::RefPtr<Gdk::Pixbuf> BacklinkMenuItem::get_note_icon()
{
- if(!s_note_icon) {
- s_note_icon = gnote::utils::get_icon("note", 16);
- }
- return s_note_icon;
+ return gnote::IconManager::obj().get_icon(gnote::IconManager::NOTE, 16);
}
diff --git a/src/addins/backlinks/backlinkmenuitem.hpp b/src/addins/backlinks/backlinkmenuitem.hpp
index c1cb7ba..984d1c0 100644
--- a/src/addins/backlinks/backlinkmenuitem.hpp
+++ b/src/addins/backlinks/backlinkmenuitem.hpp
@@ -1,6 +1,7 @@
/*
* gnote
*
+ * Copyright (C) 2012 Aurimas Cernius
* Copyright (C) 2009 Hubert Figuiere
*
* This program is free software: you can redistribute it and/or modify
@@ -42,8 +43,7 @@ private:
gnote::Note::Ptr m_note;
std::string m_title_search;
- static const Glib::RefPtr<Gdk::Pixbuf> & get_note_icon();
- static Glib::RefPtr<Gdk::Pixbuf> s_note_icon;
+ static Glib::RefPtr<Gdk::Pixbuf> get_note_icon();
};
}
diff --git a/src/addins/bugzilla/bugzillalink.cpp b/src/addins/bugzilla/bugzillalink.cpp
index 844a06b..399cc10 100644
--- a/src/addins/bugzilla/bugzillalink.cpp
+++ b/src/addins/bugzilla/bugzillalink.cpp
@@ -1,6 +1,7 @@
/*
* gnote
*
+ * Copyright (C) 2012 Aurimas Cernius
* Copyright (C) 2009 Hubert Figuiere
*
* This program is free software: you can redistribute it and/or modify
@@ -20,6 +21,7 @@
#include "sharp/uri.hpp"
#include "debug.hpp"
+#include "iconmanager.hpp"
#include "utils.hpp"
#include "bugzillalink.hpp"
#include "bugzillanoteaddin.hpp"
@@ -28,17 +30,8 @@ namespace bugzilla {
#define URI_ATTRIBUTE_NAME "uri"
- Glib::RefPtr<Gdk::Pixbuf> BugzillaLink::s_bug_icon;
-
- void BugzillaLink::_static_init()
- {
- s_bug_icon = gnote::utils::get_icon("bug", 16);
- }
-
-
BugzillaLink::BugzillaLink()
{
- _static_init();
}
@@ -86,7 +79,7 @@ namespace bugzilla {
image = Gdk::Pixbuf::create_from_file(imagePath);
}
catch(...) {
- image = s_bug_icon;
+ image = gnote::IconManager::obj().get_icon(gnote::IconManager::BUG, 16);
}
set_image(image);
}
diff --git a/src/addins/bugzilla/bugzillalink.hpp b/src/addins/bugzilla/bugzillalink.hpp
index 90c9b60..e8c7518 100644
--- a/src/addins/bugzilla/bugzillalink.hpp
+++ b/src/addins/bugzilla/bugzillalink.hpp
@@ -1,6 +1,7 @@
/*
* gnote
*
+ * Copyright (C) 2012 Aurimas Cernius
* Copyright (C) 2009 Hubert Figuiere
*
* This program is free software: you can redistribute it and/or modify
@@ -47,8 +48,6 @@ protected:
virtual void on_attribute_read(const std::string &);
private:
void make_image();
- static void _static_init();
- static Glib::RefPtr<Gdk::Pixbuf> s_bug_icon;
};
}
diff --git a/src/gnote.cpp b/src/gnote.cpp
index 36e2685..1f55f76 100644
--- a/src/gnote.cpp
+++ b/src/gnote.cpp
@@ -41,6 +41,7 @@
#include "addinmanager.hpp"
#include "applicationaddin.hpp"
#include "debug.hpp"
+#include "iconmanager.hpp"
#include "notemanager.hpp"
#include "notewindow.hpp"
#include "preferencesdialog.hpp"
@@ -346,7 +347,7 @@ namespace gnote {
about.set_name("Gnote");
about.set_program_name("Gnote");
about.set_version(VERSION);
- about.set_logo(utils::get_icon("gnote", 48));
+ about.set_logo(IconManager::obj().get_icon(IconManager::GNOTE, 48));
about.set_copyright(_("Copyright \xc2\xa9 2010-2012 Aurimas Cernius\n"
"Copyright \xc2\xa9 2009-2011 Debarshi Ray\n"
"Copyright \xc2\xa9 2009 Hubert Figuiere\n"
diff --git a/src/iconmanager.cpp b/src/iconmanager.cpp
new file mode 100644
index 0000000..d6292e7
--- /dev/null
+++ b/src/iconmanager.cpp
@@ -0,0 +1,64 @@
+/*
+ * 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 <gtkmm/icontheme.h>
+
+#include "debug.hpp"
+#include "iconmanager.hpp"
+
+
+
+namespace gnote {
+
+const char *IconManager::BUG = "bug";
+const char *IconManager::EMBLEM_PACKAGE = "emblem-package";
+const char *IconManager::FILTER_NOTE_ALL = "filter-note-all";
+const char *IconManager::FILTER_NOTE_UNFILED = "filter-note-unfiled";
+const char *IconManager::GNOTE = "gnote";
+const char *IconManager::NOTE = "note";
+const char *IconManager::NOTE_NEW = "note-new";
+const char *IconManager::NOTEBOOK = "notebook";
+const char *IconManager::NOTEBOOK_NEW = "notebook-new";
+const char *IconManager::PIN_ACTIVE = "pin-active";
+const char *IconManager::PIN_DOWN = "pin-down";
+const char *IconManager::PIN_UP = "pin-up";
+
+Glib::RefPtr<Gdk::Pixbuf> IconManager::get_icon(const std::string & name, int size)
+{
+ try {
+ IconDef icon = std::make_pair(name, size);
+ IconMap::iterator iter = m_icons.find(icon);
+ if(iter != m_icons.end()) {
+ return iter->second;
+ }
+
+ Glib::RefPtr<Gdk::Pixbuf> pixbuf = Gtk::IconTheme::get_default()->load_icon(
+ name, size, (Gtk::IconLookupFlags) 0);
+ m_icons[icon] = pixbuf;
+ return pixbuf;
+ }
+ catch(const Glib::Exception & e) {
+ ERR_OUT("Failed to load icon (%s, %d): %s", name.c_str(), size, e.what().c_str());
+ }
+ return Glib::RefPtr<Gdk::Pixbuf>();
+}
+
+}
+
diff --git a/src/iconmanager.hpp b/src/iconmanager.hpp
new file mode 100644
index 0000000..3ad9e54
--- /dev/null
+++ b/src/iconmanager.hpp
@@ -0,0 +1,57 @@
+/*
+ * 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 <map>
+#include <string>
+
+#include <gdkmm/pixbuf.h>
+#include <glibmm/refptr.h>
+
+#include "base/singleton.hpp"
+
+
+namespace gnote {
+
+class IconManager
+ : public base::Singleton<IconManager>
+{
+public:
+ static const char *BUG;
+ static const char *EMBLEM_PACKAGE;
+ static const char *FILTER_NOTE_ALL;
+ static const char *FILTER_NOTE_UNFILED;
+ static const char *GNOTE;
+ static const char *NOTE;
+ static const char *NOTE_NEW;
+ static const char *NOTEBOOK;
+ static const char *NOTEBOOK_NEW;
+ static const char *PIN_ACTIVE;
+ static const char *PIN_DOWN;
+ static const char *PIN_UP;
+
+ Glib::RefPtr<Gdk::Pixbuf> get_icon(const std::string &, int);
+private:
+ typedef std::pair<std::string, int> IconDef;
+ typedef std::map<IconDef, Glib::RefPtr<Gdk::Pixbuf> > IconMap;
+
+ IconMap m_icons;
+};
+
+}
+
diff --git a/src/notebooks/createnotebookdialog.cpp b/src/notebooks/createnotebookdialog.cpp
index ca0c399..9eeb625 100644
--- a/src/notebooks/createnotebookdialog.cpp
+++ b/src/notebooks/createnotebookdialog.cpp
@@ -1,6 +1,7 @@
/*
* gnote
*
+ * Copyright (C) 2012 Aurimas Cernius
* Copyright (C) 2009 Hubert Figuiere
*
* This program is free software: you can redistribute it and/or modify
@@ -28,6 +29,7 @@
#include "sharp/string.hpp"
#include "notebooks/createnotebookdialog.hpp"
#include "notebooks/notebookmanager.hpp"
+#include "iconmanager.hpp"
#include "utils.hpp"
namespace gnote {
@@ -38,10 +40,6 @@ namespace gnote {
_("Create a new notebook"),
_("Type the name of the notebook you'd like to create."))
{
- m_newNotebookIcon = utils::get_icon ("notebook-new", 16);
- m_newNotebookIconDialog = utils::get_icon ("notebook-new", 48);
-// set_icon_list(m_newNotebookIconDialog);
-
Gtk::Table *table = manage(new Gtk::Table (2, 2, false));
Gtk::Label *label = manage(new Gtk::Label (_("N_otebook name:"), true));
@@ -67,7 +65,7 @@ namespace gnote {
set_extra_widget(table);
add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL, false);
- add_button (m_newNotebookIcon,
+ add_button (IconManager::obj().get_icon(IconManager::NOTEBOOK_NEW, 16),
// Translation note: This is the Create button in the Create
// New Note Dialog.
_("C_reate"), Gtk::RESPONSE_OK, true);
diff --git a/src/notebooks/notebookapplicationaddin.cpp b/src/notebooks/notebookapplicationaddin.cpp
index 50054c4..226e02c 100644
--- a/src/notebooks/notebookapplicationaddin.cpp
+++ b/src/notebooks/notebookapplicationaddin.cpp
@@ -39,6 +39,7 @@
#include "actionmanager.hpp"
#include "debug.hpp"
#include "gnote.hpp"
+#include "iconmanager.hpp"
#include "notemanager.hpp"
namespace gnote {
@@ -55,8 +56,6 @@ namespace gnote {
, m_notebookUi(0)
, m_trayNotebookMenu(NULL)
{
- m_notebookIcon = utils::get_icon ("notebook", 16);
- m_newNotebookIcon = utils::get_icon ("notebook-new", 16);
}
@@ -87,7 +86,8 @@ namespace gnote {
if (item) {
Gtk::ImageMenuItem *image_item = dynamic_cast<Gtk::ImageMenuItem*>(item);
if (image_item) {
- image_item->set_image(*manage(new Gtk::Image(m_notebookIcon)));
+ image_item->set_image(*manage(new Gtk::Image(
+ IconManager::obj().get_icon(IconManager::NOTEBOOK, 16))));
}
m_trayNotebookMenu = manage(new Gtk::Menu());
item->set_submenu(*m_trayNotebookMenu);
@@ -103,7 +103,8 @@ namespace gnote {
Gtk::ImageMenuItem *imageitem = dynamic_cast<Gtk::ImageMenuItem*>(
am.get_widget ("/NotebooksTreeContextMenu/NewNotebookNote"));
if (imageitem) {
- imageitem->set_image(*manage(new Gtk::Image(am.get_new_note())));
+ imageitem->set_image(*manage(new Gtk::Image(
+ IconManager::obj().get_icon(IconManager::NOTE_NEW, 16))));
}
NoteManager & nm(Gnote::obj().default_note_manager());
@@ -184,7 +185,8 @@ namespace gnote {
// Add in the "New Notebook..." menu item
Gtk::ImageMenuItem *newNotebookMenuItem =
manage(new Gtk::ImageMenuItem (_("New Note_book..."), true));
- newNotebookMenuItem->set_image(*manage(new Gtk::Image (m_newNotebookIcon)));
+ newNotebookMenuItem->set_image(*manage(new Gtk::Image(
+ IconManager::obj().get_icon(IconManager::NOTEBOOK_NEW, 16))));
newNotebookMenuItem->signal_activate()
.connect(sigc::mem_fun(*this, &NotebookApplicationAddin::on_new_notebook_menu_item));
newNotebookMenuItem->show_all ();
diff --git a/src/notebooks/notebookapplicationaddin.hpp b/src/notebooks/notebookapplicationaddin.hpp
index 4a5f2c9..7c27e5a 100644
--- a/src/notebooks/notebookapplicationaddin.hpp
+++ b/src/notebooks/notebookapplicationaddin.hpp
@@ -61,8 +61,6 @@ namespace gnote {
bool m_initialized;
guint m_notebookUi;
Glib::RefPtr<Gtk::ActionGroup> m_actionGroup;
- Glib::RefPtr<Gdk::Pixbuf> m_notebookIcon;
- Glib::RefPtr<Gdk::Pixbuf> m_newNotebookIcon;
Gtk::Menu *m_trayNotebookMenu;
std::list<Gtk::MenuItem*> m_trayNotebookMenuItems;
};
diff --git a/src/notebooks/notebooknewnotemenuitem.cpp b/src/notebooks/notebooknewnotemenuitem.cpp
index cdd40c2..b33564b 100644
--- a/src/notebooks/notebooknewnotemenuitem.cpp
+++ b/src/notebooks/notebooknewnotemenuitem.cpp
@@ -26,6 +26,7 @@
#include "sharp/string.hpp"
#include "gnote.hpp"
+#include "iconmanager.hpp"
#include "note.hpp"
#include "notemanager.hpp"
#include "notewindow.hpp"
@@ -39,7 +40,7 @@ namespace gnote {
: Gtk::ImageMenuItem(str(boost::format(_("New \"%1%\" Note")) % notebook->get_name()))
, m_notebook(notebook)
{
- set_image(*manage(new Gtk::Image(utils::get_icon("note-new", 16))));
+ set_image(*manage(new Gtk::Image(IconManager::obj().get_icon(IconManager::NOTE_NEW, 16))));
signal_activate().connect(sigc::mem_fun(*this, &NotebookNewNoteMenuItem::on_activated));
}
diff --git a/src/notebooks/notebooknoteaddin.cpp b/src/notebooks/notebooknoteaddin.cpp
index 0b22307..7a1765d 100644
--- a/src/notebooks/notebooknoteaddin.cpp
+++ b/src/notebooks/notebooknoteaddin.cpp
@@ -27,6 +27,7 @@
#include "notebooks/notebooknoteaddin.hpp"
#include "notebooks/notebookmanager.hpp"
#include "debug.hpp"
+#include "iconmanager.hpp"
#include "tag.hpp"
#include "tagmanager.hpp"
#include "notewindow.hpp"
@@ -35,21 +36,8 @@
namespace gnote {
namespace notebooks {
- bool NotebookNoteAddin::s_static_inited = false;
- Glib::RefPtr<Gdk::Pixbuf> NotebookNoteAddin::s_notebookIcon;
- Glib::RefPtr<Gdk::Pixbuf> NotebookNoteAddin::s_newNotebookIcon;
Tag::Ptr NotebookNoteAddin::s_templateTag;
- void NotebookNoteAddin::_init_static()
- {
- if(!s_static_inited) {
- s_notebookIcon = utils::get_icon("notebook", 22);
- s_newNotebookIcon = utils::get_icon("notebook-new", 16);
- s_static_inited = true;
- }
- }
-
-
Tag::Ptr NotebookNoteAddin::get_template_tag()
{
if(!s_templateTag) {
@@ -63,7 +51,6 @@ namespace notebooks {
: m_toolButton(NULL)
, m_menu(NULL)
{
- _init_static();
}
@@ -80,7 +67,8 @@ namespace notebooks {
void NotebookNoteAddin::initialize_tool_button()
{
m_toolButton = Gtk::manage(
- new gnote::utils::ToolMenuButton(*manage(new Gtk::Image(s_notebookIcon)), "",
+ new gnote::utils::ToolMenuButton(*manage(new Gtk::Image(
+ IconManager::obj().get_icon(IconManager::NOTEBOOK, 22))), "",
m_menu));
m_toolButton->set_is_important(true);
m_toolButton->set_tooltip_text(_("Place this note into a notebook"));
@@ -220,7 +208,8 @@ namespace notebooks {
// Add the "New Notebook..."
Gtk::ImageMenuItem *newNotebookMenuItem =
manage(new Gtk::ImageMenuItem (_("_New notebook..."), true));
- newNotebookMenuItem->set_image(*manage(new Gtk::Image (s_newNotebookIcon)));
+ newNotebookMenuItem->set_image(*manage(new Gtk::Image(
+ IconManager::obj().get_icon(IconManager::NOTEBOOK_NEW, 16))));
newNotebookMenuItem->signal_activate()
.connect(sigc::mem_fun(*this,&NotebookNoteAddin::on_new_notebook_menu_item));
newNotebookMenuItem->show ();
diff --git a/src/notebooks/notebooknoteaddin.hpp b/src/notebooks/notebooknoteaddin.hpp
index a75b808..9422724 100644
--- a/src/notebooks/notebooknoteaddin.hpp
+++ b/src/notebooks/notebooknoteaddin.hpp
@@ -1,7 +1,7 @@
/*
* gnote
*
- * Copyright (C) 2011 Aurimas Cernius
+ * Copyright (C) 2011-2012 Aurimas Cernius
* Copyright (C) 2009 Hubert Figuiere
*
* This program is free software: you can redistribute it and/or modify
@@ -70,10 +70,6 @@ namespace notebooks {
sigc::connection m_note_added_cid;
sigc::connection m_note_removed_cid;
- static void _init_static();
- static bool s_static_inited;
- static Glib::RefPtr<Gdk::Pixbuf> s_notebookIcon;
- static Glib::RefPtr<Gdk::Pixbuf> s_newNotebookIcon;
static Tag::Ptr s_templateTag;
};
diff --git a/src/notewindow.cpp b/src/notewindow.cpp
index 166e7b9..2ae49cb 100644
--- a/src/notewindow.cpp
+++ b/src/notewindow.cpp
@@ -34,6 +34,7 @@
#include "libtomboy/tomboyutil.h"
#include "debug.hpp"
+#include "iconmanager.hpp"
#include "note.hpp"
#include "notewindow.hpp"
#include "notemanager.hpp"
@@ -52,18 +53,14 @@
namespace gnote {
- bool NoteWindow::s_static_inited = false;
- Glib::RefPtr<Gio::Icon> NoteWindow::s_icon_pin_active;
- Glib::RefPtr<Gio::Icon> NoteWindow::s_icon_pin_down;
-
- void NoteWindow::_init_static()
+ Glib::RefPtr<Gio::Icon> NoteWindow::get_icon_pin_active()
{
- if(!s_static_inited) {
- s_static_inited = true;
+ return IconManager::obj().get_icon(IconManager::PIN_ACTIVE, 22);
+ }
- s_icon_pin_active = utils::get_icon("pin-active", 22);
- s_icon_pin_down = utils::get_icon("pin-down", 22);
- }
+ Glib::RefPtr<Gio::Icon> NoteWindow::get_icon_pin_down()
+ {
+ return IconManager::obj().get_icon(IconManager::PIN_DOWN, 22);
}
@@ -78,8 +75,6 @@ namespace gnote {
, m_y(-1)
, m_global_keys(NULL)
{
- _init_static();
-
m_template_tag = TagManager::obj().get_or_create_system_tag(TagManager::TEMPLATE_NOTE_SYSTEM_TAG);
m_template_save_size_tag = TagManager::obj().get_or_create_system_tag(TagManager::TEMPLATE_NOTE_SAVE_SIZE_SYSTEM_TAG);
m_template_save_selection_tag = TagManager::obj().get_or_create_system_tag(TagManager::TEMPLATE_NOTE_SAVE_SELECTION_SYSTEM_TAG);
@@ -372,10 +367,10 @@ namespace gnote {
m_pin_image = manage(new Gtk::Image);
if(m_note.is_pinned()) {
- m_pin_image->property_gicon() = s_icon_pin_down;
+ m_pin_image->property_gicon() = get_icon_pin_down();
}
else {
- m_pin_image->property_gicon() = s_icon_pin_active;
+ m_pin_image->property_gicon() = get_icon_pin_active();
}
m_pin_button = manage(new Gtk::ToolButton(*m_pin_image, _("Pin")));
@@ -680,10 +675,10 @@ namespace gnote {
return;
}
if(pinned) {
- m_pin_image->property_gicon() = s_icon_pin_down;
+ m_pin_image->property_gicon() = get_icon_pin_down();
}
else {
- m_pin_image->property_gicon() = s_icon_pin_active;
+ m_pin_image->property_gicon() = get_icon_pin_active();
}
}
diff --git a/src/notewindow.hpp b/src/notewindow.hpp
index d452dda..66be7fb 100644
--- a/src/notewindow.hpp
+++ b/src/notewindow.hpp
@@ -154,10 +154,8 @@ public:
return *m_find_bar;
}
private:
- static void _init_static();
- static bool s_static_inited;
- static Glib::RefPtr<Gio::Icon> s_icon_pin_active;
- static Glib::RefPtr<Gio::Icon> s_icon_pin_down;
+ static Glib::RefPtr<Gio::Icon> get_icon_pin_active();
+ static Glib::RefPtr<Gio::Icon> get_icon_pin_down();
bool on_key_pressed(GdkEventKey*);
void on_delete_button_clicked();
diff --git a/src/recentchanges.cpp b/src/recentchanges.cpp
index 7bd05dd..b742ac3 100644
--- a/src/recentchanges.cpp
+++ b/src/recentchanges.cpp
@@ -30,6 +30,7 @@
#include "actionmanager.hpp"
#include "debug.hpp"
#include "gnote.hpp"
+#include "iconmanager.hpp"
#include "note.hpp"
#include "notemanager.hpp"
#include "notewindow.hpp"
@@ -65,7 +66,7 @@ namespace gnote {
m_menu = manage(new Gtk::Menu);
m_menu->signal_show().connect(sigc::mem_fun(*this, &NoteRecentChanges::on_menu_show));
utils::ToolMenuButton *tool_button = manage(new utils::ToolMenuButton(
- *manage(new Gtk::Image(utils::get_icon("note", 24))), _("_Show"), m_menu));
+ *manage(new Gtk::Image(IconManager::obj().get_icon(IconManager::NOTE, 24))), _("_Show"), m_menu));
tool_button->set_use_underline(true);
tool_button->set_is_important(true);
tool_button->show_all();
diff --git a/src/searchnoteswidget.cpp b/src/searchnoteswidget.cpp
index c30aab9..6f34e9f 100644
--- a/src/searchnoteswidget.cpp
+++ b/src/searchnoteswidget.cpp
@@ -29,6 +29,7 @@
#include <gtkmm/table.h>
#include "debug.hpp"
+#include "iconmanager.hpp"
#include "notemanager.hpp"
#include "notewindow.hpp"
#include "recenttreeview.hpp"
@@ -42,24 +43,11 @@
namespace gnote {
std::list<std::string> SearchNotesWidget::s_previous_searches;
-bool SearchNotesWidget::s_static_inited = false;
-Glib::RefPtr<Gdk::Pixbuf> SearchNotesWidget::s_note_icon;
-Glib::RefPtr<Gdk::Pixbuf> SearchNotesWidget::s_all_notes_icon;
-Glib::RefPtr<Gdk::Pixbuf> SearchNotesWidget::s_unfiled_notes_icon;
-Glib::RefPtr<Gdk::Pixbuf> SearchNotesWidget::s_pinned_notes_icon;
-Glib::RefPtr<Gdk::Pixbuf> SearchNotesWidget::s_notebook_icon;
-void SearchNotesWidget::_init_static()
+
+Glib::RefPtr<Gdk::Pixbuf> SearchNotesWidget::get_note_icon()
{
- if(s_static_inited) {
- return;
- }
- s_note_icon = utils::get_icon ("note", 22);
- s_all_notes_icon = utils::get_icon ("filter-note-all", 22);
- s_unfiled_notes_icon = utils::get_icon ("filter-note-unfiled", 22);
- s_pinned_notes_icon = utils::get_icon ("pin-down", 22);
- s_notebook_icon = utils::get_icon ("notebook", 22);
- s_static_inited = true;
+ return IconManager::obj().get_icon(IconManager::NOTE, 22);
}
@@ -77,7 +65,6 @@ SearchNotesWidget::SearchNotesWidget(NoteManager & m)
, m_notebook_list_context_menu(NULL)
, m_initial_position_restored(false)
{
- _init_static();
make_actions();
Gtk::Label *label = manage(new Gtk::Label (_("_Search:"), true));
@@ -486,16 +473,16 @@ void SearchNotesWidget::notebook_pixbuf_cell_data_func(Gtk::CellRenderer * rende
Gtk::CellRendererPixbuf *crp = dynamic_cast<Gtk::CellRendererPixbuf*>(renderer);
if(std::tr1::dynamic_pointer_cast<notebooks::AllNotesNotebook>(notebook)) {
- crp->property_pixbuf() = s_all_notes_icon;
+ crp->property_pixbuf() = IconManager::obj().get_icon(IconManager::FILTER_NOTE_ALL, 22);
}
else if(std::tr1::dynamic_pointer_cast<notebooks::UnfiledNotesNotebook>(notebook)) {
- crp->property_pixbuf() = s_unfiled_notes_icon;
+ crp->property_pixbuf() = IconManager::obj().get_icon(IconManager::FILTER_NOTE_UNFILED, 22);
}
else if(std::tr1::dynamic_pointer_cast<notebooks::PinnedNotesNotebook>(notebook)) {
- crp->property_pixbuf() = s_pinned_notes_icon;
+ crp->property_pixbuf() = IconManager::obj().get_icon(IconManager::PIN_DOWN, 22);
}
else {
- crp->property_pixbuf() = s_notebook_icon;
+ crp->property_pixbuf() = IconManager::obj().get_icon(IconManager::NOTEBOOK, 22);
}
}
@@ -697,7 +684,7 @@ void SearchNotesWidget::update_results()
std::string nice_date = utils::get_pretty_print_date(note->change_date(), true);
Gtk::TreeIter iter = m_store->append();
- iter->set_value(0, s_note_icon); /* icon */
+ iter->set_value(0, get_note_icon()); /* icon */
iter->set_value(1, note->get_title()); /* title */
iter->set_value(2, nice_date); /* change date */
iter->set_value(3, note); /* note */
@@ -1379,7 +1366,7 @@ void SearchNotesWidget::add_note(const Note::Ptr & note)
std::string nice_date =
utils::get_pretty_print_date(note->change_date(), true);
Gtk::TreeIter iter = m_store->append();
- iter->set_value(m_column_types.icon, s_note_icon);
+ iter->set_value(m_column_types.icon, get_note_icon());
iter->set_value(m_column_types.title, note->get_title());
iter->set_value(m_column_types.change_date, nice_date);
iter->set_value(m_column_types.note, note);
diff --git a/src/searchnoteswidget.hpp b/src/searchnoteswidget.hpp
index 3ffba32..cfde14c 100644
--- a/src/searchnoteswidget.hpp
+++ b/src/searchnoteswidget.hpp
@@ -178,15 +178,9 @@ private:
Gtk::Menu *m_notebook_list_context_menu;
bool m_initial_position_restored;
- static void _init_static();
+ static Glib::RefPtr<Gdk::Pixbuf> get_note_icon();
static std::list<std::string> s_previous_searches;
- static bool s_static_inited;
- static Glib::RefPtr<Gdk::Pixbuf> s_note_icon;
- static Glib::RefPtr<Gdk::Pixbuf> s_all_notes_icon;
- static Glib::RefPtr<Gdk::Pixbuf> s_unfiled_notes_icon;
- static Glib::RefPtr<Gdk::Pixbuf> s_pinned_notes_icon;
- static Glib::RefPtr<Gdk::Pixbuf> s_notebook_icon;
};
}
diff --git a/src/sharp/addinstreemodel.cpp b/src/sharp/addinstreemodel.cpp
index f27f7da..b0cf79b 100644
--- a/src/sharp/addinstreemodel.cpp
+++ b/src/sharp/addinstreemodel.cpp
@@ -28,8 +28,8 @@
#include <glibmm/i18n.h>
#include "sharp/addinstreemodel.hpp"
-#include "utils.hpp"
#include "abstractaddin.hpp"
+#include "iconmanager.hpp"
namespace sharp {
@@ -82,7 +82,7 @@ namespace sharp {
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 = gnote::IconManager::obj().get_icon(gnote::IconManager::EMBLEM_PACKAGE, 22);
}
icon_renderer->property_pixbuf() = icon;
}
diff --git a/src/synchronization/syncdialog.cpp b/src/synchronization/syncdialog.cpp
index ea13e5b..5d71093 100644
--- a/src/synchronization/syncdialog.cpp
+++ b/src/synchronization/syncdialog.cpp
@@ -28,6 +28,7 @@
#include <gtkmm/treeview.h>
#include "gnote.hpp"
+#include "iconmanager.hpp"
#include "notemanager.hpp"
#include "notewindow.hpp"
#include "preferences.hpp"
@@ -288,7 +289,7 @@ SyncDialog::SyncDialog()
hbox->show();
outerVBox->pack_start(*hbox, false, false, 0);
- m_image = manage(new Gtk::Image(utils::get_icon("gnote", 48)));
+ m_image = manage(new Gtk::Image(IconManager::obj().get_icon(IconManager::GNOTE, 48)));
m_image->set_alignment(0, 0);
m_image->show();
hbox->pack_start(*m_image, false, false, 0);
diff --git a/src/tray.cpp b/src/tray.cpp
index 633bb91..a63765c 100644
--- a/src/tray.cpp
+++ b/src/tray.cpp
@@ -35,6 +35,7 @@
#include "tray.hpp"
#include "debug.hpp"
#include "actionmanager.hpp"
+#include "iconmanager.hpp"
#include "utils.hpp"
#include "gnote.hpp"
#include "note.hpp"
@@ -65,12 +66,6 @@ namespace gnote {
- bool NoteMenuItem::s_static_inited = false;
- Glib::RefPtr<Gdk::Pixbuf> NoteMenuItem::s_note_icon;
- Glib::RefPtr<Gdk::Pixbuf> NoteMenuItem::s_pinup;
- Glib::RefPtr<Gdk::Pixbuf> NoteMenuItem::s_pinup_active;
- Glib::RefPtr<Gdk::Pixbuf> NoteMenuItem::s_pindown;
-
NoteMenuItem::NoteMenuItem(const Note::Ptr & note, bool show_pin)
: Gtk::ImageMenuItem(get_display_name(note))
, m_note(note)
@@ -78,8 +73,7 @@ namespace gnote {
, m_pinned(false)
, m_inhibit_activate(false)
{
- _init_static();
- set_image(*manage(new Gtk::Image(s_note_icon)));
+ set_image(*manage(new Gtk::Image(IconManager::obj().get_icon(IconManager::NOTE, 16))));
if(show_pin) {
Gtk::HBox *box = manage(new Gtk::HBox(false, 0));
Gtk::Widget *child = get_child();
@@ -89,7 +83,7 @@ namespace gnote {
box->show();
m_pinned = note->is_pinned();
- m_pin_img = manage(new Gtk::Image(m_pinned ? s_pindown : s_pinup));
+ m_pin_img = manage(new Gtk::Image(m_pinned ? get_pindown_icon() : get_pinup_icon()));
m_pin_img->show();
box->pack_start(*m_pin_img, false, false, 0);
}
@@ -113,7 +107,7 @@ namespace gnote {
+ m_pin_img->get_allocation().get_width())) {
m_pinned = !m_pinned;
m_note->set_pinned(m_pinned);
- m_pin_img->set(m_pinned ? s_pindown : s_pinup);
+ m_pin_img->set(m_pinned ? get_pindown_icon() : get_pinup_icon());
m_inhibit_activate = true;
return true;
}
@@ -137,11 +131,16 @@ namespace gnote {
if (!m_pinned && m_pin_img) {
if (ev->x >= m_pin_img->get_allocation().get_x() &&
ev->x < m_pin_img->get_allocation().get_x() + m_pin_img->get_allocation().get_width()) {
- if (m_pin_img->get_pixbuf() != s_pinup_active) {
- m_pin_img->set(s_pinup_active);
+ Glib::RefPtr<Gdk::Pixbuf> pin_active = IconManager::obj().get_icon(IconManager::PIN_ACTIVE, 16);
+ if (m_pin_img->get_pixbuf() != pin_active) {
+ m_pin_img->set(pin_active);
+ }
+ }
+ else {
+ Glib::RefPtr<Gdk::Pixbuf> pinup = get_pinup_icon();
+ if (m_pin_img->get_pixbuf() != pinup) {
+ m_pin_img->set(pinup);
}
- } else if (m_pin_img->get_pixbuf() != s_pinup) {
- m_pin_img->set(s_pinup);
}
}
@@ -152,7 +151,7 @@ namespace gnote {
bool NoteMenuItem::on_leave_notify_event(GdkEventCrossing *ev)
{
if (!m_pinned && m_pin_img) {
- m_pin_img->set(s_pinup);
+ m_pin_img->set(get_pinup_icon());
}
return Gtk::ImageMenuItem::on_leave_notify_event(ev);
}
@@ -186,15 +185,14 @@ namespace gnote {
- void NoteMenuItem::_init_static()
+ Glib::RefPtr<Gdk::Pixbuf> NoteMenuItem::get_pinup_icon()
+ {
+ return IconManager::obj().get_icon(IconManager::PIN_UP, 16);
+ }
+
+ Glib::RefPtr<Gdk::Pixbuf> NoteMenuItem::get_pindown_icon()
{
- if(s_static_inited)
- return;
- s_note_icon = utils::get_icon("note", 16);
- s_pinup = utils::get_icon("pin-up", 16);
- s_pinup_active = utils::get_icon("pin-active", 16);
- s_pindown = utils::get_icon("pin-down", 16);
- s_static_inited = true;
+ return IconManager::obj().get_icon(IconManager::PIN_DOWN, 16);
}
Tray::Tray(NoteManager & manager, IGnoteTray & trayicon)
@@ -541,7 +539,7 @@ namespace gnote {
size = 32;
}
else size = 48;
- Glib::RefPtr<Gdk::Pixbuf> pixbuf = utils::get_icon("gnote", size);
+ Glib::RefPtr<Gdk::Pixbuf> pixbuf = IconManager::obj().get_icon(IconManager::GNOTE, size);
set(pixbuf);
return Gtk::StatusIcon::on_size_changed(size);
}
diff --git a/src/tray.hpp b/src/tray.hpp
index 1eb15e1..57d7a1a 100644
--- a/src/tray.hpp
+++ b/src/tray.hpp
@@ -1,7 +1,7 @@
/*
* gnote
*
- * Copyright (C) 2010-2011 Aurimas Cernius
+ * Copyright (C) 2010-2012 Aurimas Cernius
* Copyright (C) 2009 Hubert Figuiere
*
* This program is free software: you can redistribute it and/or modify
@@ -55,13 +55,8 @@ private:
static std::string get_display_name(const Note::Ptr & n);
static std::string ellipsify (const std::string & str, size_t max);
- static void _init_static();
-
- static bool s_static_inited;
- static Glib::RefPtr<Gdk::Pixbuf> s_note_icon;
- static Glib::RefPtr<Gdk::Pixbuf> s_pinup;
- static Glib::RefPtr<Gdk::Pixbuf> s_pinup_active;
- static Glib::RefPtr<Gdk::Pixbuf> s_pindown;
+ static Glib::RefPtr<Gdk::Pixbuf> get_pinup_icon();
+ static Glib::RefPtr<Gdk::Pixbuf> get_pindown_icon();
};
diff --git a/src/utils.cpp b/src/utils.cpp
index dfc04df..662b14f 100644
--- a/src/utils.cpp
+++ b/src/utils.cpp
@@ -1,7 +1,7 @@
/*
* gnote
*
- * Copyright (C) 2010-2011 Aurimas Cernius
+ * Copyright (C) 2010-2012 Aurimas Cernius
* Copyright (C) 2010 Debarshi Ray
* Copyright (C) 2009 Hubert Figuiere
*
@@ -104,18 +104,6 @@ namespace gnote {
}
- Glib::RefPtr<Gdk::Pixbuf> get_icon(const std::string & name, int size)
- {
- try {
- return Gtk::IconTheme::get_default()->load_icon(name, size, (Gtk::IconLookupFlags) 0);
- }
- catch(const Glib::Exception & e)
- {
- std::cout << e.what().c_str() << std::endl;
- }
- return Glib::RefPtr<Gdk::Pixbuf>();
- }
-
void show_help(const std::string & filename, const std::string & link_id,
GdkScreen *screen, Gtk::Window *parent)
{
diff --git a/src/utils.hpp b/src/utils.hpp
index 0ef8567..af53db3 100644
--- a/src/utils.hpp
+++ b/src/utils.hpp
@@ -48,9 +48,6 @@ namespace sharp {
namespace gnote {
namespace utils {
- Glib::RefPtr<Gdk::Pixbuf> get_icon(const std::string & , int );
-
-
void popup_menu(Gtk::Menu &menu, const GdkEventButton *);
void show_help(const std::string & filename, const std::string & link_id,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]