1 /*
2 * gnote
3 *
4 * Copyright (C) 2012-2013,2017,2019,2021 Aurimas Cernius
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20
21 #include <glibmm/i18n.h>
22 #include <gtkmm/icontheme.h>
23
24 #include "debug.hpp"
25 #include "iconmanager.hpp"
26
27
28
29 namespace gnote {
30
31 const char *IconManager::BUG = "bug";
32 const char *IconManager::EMBLEM_PACKAGE = "emblem-package";
33 const char *IconManager::FILTER_NOTE_ALL = "filter-note-all";
34 const char *IconManager::FILTER_NOTE_UNFILED = "filter-note-unfiled";
35 const char *IconManager::GNOTE = "org.gnome.Gnote";
36 const char *IconManager::NOTE = "note";
37 const char *IconManager::NOTE_NEW = "note-new";
38 const char *IconManager::NOTEBOOK = "notebook";
39 const char *IconManager::NOTEBOOK_NEW = "notebook-new";
40 const char *IconManager::PIN_ACTIVE = "pin-active";
41 const char *IconManager::PIN_DOWN = "pin-down";
42 const char *IconManager::PIN_UP = "pin-up";
43 const char *IconManager::ACTIVE_NOTES = "active-notes";
44 const char *IconManager::SPECIAL_NOTES = "special-notes";
45
46
get_icon(const Glib::ustring & name,int size)47 Glib::RefPtr<Gdk::Pixbuf> IconManager::get_icon(const Glib::ustring & name, int size)
48 {
49 try {
50 IconDef icon = std::make_pair(name, size);
51 IconMap::iterator iter = m_icons.find(icon);
52 if(iter != m_icons.end()) {
53 return iter->second;
54 }
55
56 Glib::RefPtr<Gdk::Pixbuf> pixbuf = Gtk::IconTheme::get_default()->load_icon(
57 name, size, (Gtk::IconLookupFlags) 0);
58 m_icons[icon] = pixbuf;
59 return pixbuf;
60 }
61 catch(const Glib::Exception & e) {
62 /* TRANSLATORS: the first %s is icon name, %d is for size, last %s is error description */
63 ERR_OUT(_("Failed to load icon (%s, %d): %s"), name.c_str(), size, e.what().c_str());
64 }
65 return Glib::RefPtr<Gdk::Pixbuf>();
66 }
67
lookup_icon(const Glib::ustring & name,int size)68 Gtk::IconInfo IconManager::lookup_icon(const Glib::ustring & name, int size)
69 {
70 return Gtk::IconTheme::get_default()->lookup_icon(name, size, (Gtk::IconLookupFlags) 0);
71 }
72
73 }
74
75