1 // Copyright (C) 2008 Ben Asselstine
3 // This program is free software; you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation; either version 3 of the License, or
6 // (at your option) any later version.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU Library General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 #include "timed-message-dialog.h"
25 #include "ucompose.hpp"
26 #include "decorated.h"
29 #include "decorated.h"
31 TimedMessageDialog::TimedMessageDialog(Gtk::Window &parent, std::string message, int timeout, int grace)
37 window = new Gtk::MessageDialog(parent, message);
38 //Gtk::MessageDialog dialog(parent, message);
39 //window.reset(&dialog);
40 window->set_message(message);
41 window->signal_response().connect
42 (sigc::mem_fun(*this, &TimedMessageDialog::on_response));
44 decorator.decorate(window);
45 decorator.window_closed.connect(sigc::mem_fun(window, &Gtk::Dialog::hide));
46 window->set_transient_for(parent);
49 void TimedMessageDialog::on_response(int id)
55 TimedMessageDialog::~TimedMessageDialog()
60 void TimedMessageDialog::show_all()
65 void TimedMessageDialog::hide()
70 void TimedMessageDialog::run()
74 Timing::instance().register_timer
75 (sigc::mem_fun(this, &TimedMessageDialog::tick), 1000);
79 main_loop = Glib::MainLoop::create();
83 bool TimedMessageDialog::tick()
88 if (d_timer_count >= d_grace)
92 return Timing::CONTINUE;
97 int secs = d_timeout - d_timer_count;
99 s = String::ucompose(ngettext("This message will disappear in %1 second.",
100 "This message will disappear in %1 seconds.",
102 window->set_secondary_text(s);
105 if (d_timer_count <= d_timeout)
106 return Timing::CONTINUE;
114 void TimedMessageDialog::set_title(std::string title)
116 window->set_title(title);
119 void TimedMessageDialog::set_image(Glib::RefPtr<Gdk::Pixbuf> picture)
121 Gtk::Image *image = new Gtk::Image(picture);
122 window->property_image() = image;