24 #include <gui_utils/throbber.h>
26 #include <core/exception.h>
34 #define SPINNER_ICON_NAME "process-working"
35 #define SPINNER_FALLBACK_ICON_NAME "gnome-spinner"
36 #define SPINNER_DEFAULT_TIMEOUT 100
52 Throbber::Throbber(BaseObjectType* cobject,
53 const Glib::RefPtr<Gtk::Builder> &builder)
56 Gtk::Container *parent = get_parent();
57 Gtk::ToolItem *toolitem =
dynamic_cast<Gtk::ToolItem *
>(parent);
59 ctor(toolitem->get_icon_size());
62 ctor(Gtk::IconSize(Gtk::ICON_SIZE_BUTTON));
78 Throbber::ctor(Gtk::IconSize icon_size)
80 __timeout = SPINNER_DEFAULT_TIMEOUT;
81 __icon_size = icon_size;
84 #if GTKMM_MAJOR_VERSION > 2 || ( GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 14 )
85 Glib::RefPtr<Gtk::Settings> settings = Gtk::Settings::get_for_screen(get_screen());
86 if ( ! Gtk::IconSize::lookup(icon_size, isw, ish, settings) ) {
87 throw Exception(
"Could not get icon sizes");
90 if ( ! Gtk::IconSize::lookup(icon_size, isw, ish) ) {
91 throw Exception(
"Could not get icon sizes");
94 int requested_size = std::max(isw, ish);
96 Glib::RefPtr<Gtk::IconTheme> icon_theme = Gtk::IconTheme::get_for_screen(get_screen());
97 Gtk::IconInfo icon_info = icon_theme->lookup_icon(SPINNER_ICON_NAME,
99 Gtk::IconLookupFlags());
101 icon_info = icon_theme->lookup_icon(SPINNER_FALLBACK_ICON_NAME,
102 requested_size, Gtk::IconLookupFlags());
104 throw Exception(
"Could not find neither default nor fallback throbber icon");
108 int size = icon_info.get_base_size();
110 #ifdef GLIBMM_EXCEPTIONS_ENABLED
111 Glib::RefPtr<Gdk::Pixbuf> icon = icon_info.load_icon();
113 std::auto_ptr<Glib::Error> error;
114 Glib::RefPtr<Gdk::Pixbuf> icon = icon_info.load_icon(error);
117 int pixwidth = icon->get_width();
118 int pixheight = icon->get_height();
120 for (
int y = 0; y < pixheight; y += size) {
121 for (
int x = 0; x < pixwidth ; x += size) {
122 if ( (x + size <= icon->get_width()) &&
123 (y + size <= icon->get_height()) ) {
124 Glib::RefPtr<Gdk::Pixbuf> p = Gdk::Pixbuf::create_subpixbuf(icon, x, y, size, size);
125 __pixbufs.push_back(p);
130 if ( __pixbufs.empty() ) {
131 throw Exception(
"Could not extract any throbber images from pixbuf");
135 set(__pixbufs.front());
143 Throbber::draw_next()
145 __current = (__current + 1) % __pixbufs.size();
146 if ( (__current == 0) && (__pixbufs.size() > 1) ) {
149 set(__pixbufs[__current]);
172 return (__timeout_connection && __timeout_connection.connected());
179 if ( ! __timeout_connection || ! __timeout_connection.connected()) {
180 __timeout_connection = Glib::signal_timeout().connect(
181 sigc::mem_fun(*
this, &Throbber::draw_next), __timeout);
189 if (__timeout_connection && __timeout_connection.connected()) {
190 __timeout_connection.disconnect();
194 set(__pixbufs.front());
207 set(stock_id, __icon_size);
Fawkes library namespace.
void start_anim()
Start animation.
void stop_anim()
Stop animation.
void set_timeout(unsigned int timeout)
Set the animation timeout.
Base class for exceptions in Fawkes.
void set_stock(const Gtk::StockID &stock_id)
Set image from stock ID.
Throbber(Gtk::IconSize &icon_size)
Constructor.
bool anim_running()
Check if animation is running.