# include <iostream>
# include <gtkmm.h>
# include <gtkmm/widget.h>
# include <gtkmm/notebook.h>
# include <pangomm/fontdescription.h>
# include <pango/pango.h>
# ifndef DISABLE_VTE
# include <vte/vte.h>
# endif
# include <boost/filesystem.hpp>
# include "astroid.hh"
# include "poll.hh"
# include "main_window.hh"
# include "modes/mode.hh"
# include "modes/thread_index/thread_index.hh"
# include "modes/saved_searches.hh"
# include "modes/help_mode.hh"
# include "modes/edit_message.hh"
# include "modes/log_view.hh"
# include "command_bar.hh"
# include "actions/action.hh"
# include "actions/action_manager.hh"
# include "utils/resource.hh"
using namespace std;
namespace bfs = boost::filesystem;
# ifndef DISABLE_VTE
extern "C" {
void mw_on_terminal_child_exit (VteTerminal * t, gint a, gpointer mw) {
((Astroid::MainWindow *) mw)->on_terminal_child_exit (t, a);
}
void mw_on_terminal_commit (VteTerminal * t, gchar ** tx, guint sz, gpointer mw) {
((Astroid::MainWindow *) mw)->on_terminal_commit (t, tx, sz);
}
# if VTE_CHECK_VERSION(0,48,0)
void mw_on_terminal_spawn_callback (VteTerminal * t, GPid pid, GError * err, gpointer mw)
{
((Astroid::MainWindow *) mw)->on_terminal_spawn_callback (t, pid, err);
}
# endif
}
# endif
namespace Astroid {
atomic<uint> MainWindow::nextid (0);
int Notebook::icon_size = 42;
Notebook::Notebook () {
set_scrollable (true);
set_action_widget (&icons, Gtk::PACK_END);
icons.show_all ();
astroid->poll->signal_poll_state ().connect (
sigc::mem_fun (this, &Notebook::poll_state_changed));
signal_size_allocate ().connect (
sigc::mem_fun (this, &Notebook::on_my_size_allocate));
poll_state_changed (astroid->poll->get_poll_state());
}
void Notebook::on_my_size_allocate (Gtk::Allocation &) {
icon_size = icons.get_height ();
}
void Notebook::poll_state_changed (bool state) {
if (state && !spinner_on) {
/* set up spinner for poll */
spinner_on = true;
icons.pack_end (poll_spinner, true, true, 5);
icons.show_all ();
poll_spinner.start ();
} else if (!state && spinner_on) {
poll_spinner.stop ();
icons.remove (poll_spinner);
spinner_on = false;
}
}
void Notebook::add_widget (Gtk::Widget * w) {
icons.pack_start (*w, true, true, 5);
w->show ();
icons.show_all ();
}
void Notebook::remove_widget (Gtk::Widget * w) {
icons.remove (*w);
}
MainWindow::MainWindow () {
id = ++nextid;
actions = astroid->actions;
LOG (debug) << "mw: init, id: " << id;
set_title ("");
set_default_size (1200, 800);
path icon = Resource (false, "ui/icons/icon_color.png").get_path ();
try {
refptr<Gdk::Pixbuf> pixbuf = Gdk::Pixbuf::create_from_file (icon.c_str (), 42, 42, true);
set_icon (pixbuf);
} catch (Gdk::PixbufError &e) {
LOG (error) << "mw: could not set icon: " << e.what ();
}
vbox.set_orientation (Gtk::ORIENTATION_VERTICAL);
command.set_main_window (this);
command.property_search_mode_enabled().signal_changed().connect(
sigc::mem_fun (*this, &MainWindow::on_command_mode_changed)
);
vbox.pack_start (command, false, true, 0);
vbox.pack_start (notebook, Gtk::PACK_EXPAND_WIDGET, 0);
/* set up yes-no asker */
rev_yes_no = Gtk::manage (new Gtk::Revealer ());
rev_yes_no->set_transition_type (Gtk::REVEALER_TRANSITION_TYPE_SLIDE_UP);
Gtk::Box * rh = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL));
label_yes_no = Gtk::manage (new Gtk::Label ());
rh->pack_start (*label_yes_no, true, true, 5);
label_yes_no->set_halign (Gtk::ALIGN_START);
/* buttons */
Gtk::Button * yes = Gtk::manage (new Gtk::Button("_Yes"));