#include #include #include #include #include #include #include #include #define T(String) gettext(String) using namespace std; using namespace net::lliurex::mrpdi; /** * Application class */ class Application { public: Gtk::Window * window; Gtk::Window * dlgClose; Gtk::TreeView * treeview; Core * core; input::InputHandler * handler; Glib::RefPtr pix_tablet,pix_whiteboard; Glib::RefPtr store; Glib::RefPtr statusIcon; /** * Constructor */ Application() { cout<<"[Constructor]"< glade; glade=Gtk::Builder::create_from_file("/usr/share/mrpdi/gui/interface.glade"); glade->get_widget("winManager",window); Gtk::Button * button; glade->get_widget("btnRefresh",button); button->signal_clicked().connect(sigc::mem_fun(*this,&Application::on_btnrefresh_clicked)); glade->get_widget("btnRun",button); button->signal_clicked().connect(sigc::mem_fun(*this,&Application::on_btnrun_clicked)); glade->get_widget("btnStop",button); button->signal_clicked().connect(sigc::mem_fun(*this,&Application::on_btnstop_clicked)); glade->get_widget("btnDebug",button); button->signal_clicked().connect(sigc::mem_fun(*this,&Application::on_btndebug_clicked)); glade->get_widget("btnCalibrate",button); button->signal_clicked().connect(sigc::mem_fun(*this,&Application::on_btncalibrate_clicked)); glade->get_widget("btnClose",button); button->signal_clicked().connect(sigc::mem_fun(*this,&Application::on_btnclose_clicked)); glade->get_widget("dlgClose",dlgClose); glade->get_widget("dlgbtnCancel",button); button->signal_clicked().connect(sigc::mem_fun(*this,&Application::on_dlg_cancel)); glade->get_widget("dlgbtnAccept",button); button->signal_clicked().connect(sigc::mem_fun(*this,&Application::on_dlg_accept)); window->signal_window_state_event().connect(sigc::mem_fun(*this,&Application::on_window_state_changed)); window->signal_delete_event().connect(sigc::mem_fun(*this,&Application::on_window_destroy)); glade->get_widget("treeDevices",treeview); pix_tablet = Gdk::Pixbuf::create_from_file("/usr/share/mrpdi/gui/tablet.svg"); pix_whiteboard = Gdk::Pixbuf::create_from_file("/usr/share/mrpdi/gui/whiteboard.svg"); Gtk::TreeModelColumn >pixbuf_col; Gtk::TreeModelColumn id_col; Gtk::TreeModelColumn address_col; Gtk::TreeModelColumn name_col; Gtk::TreeModelColumn status_col; Gtk::TreeModel::ColumnRecord cr; cr.add(pixbuf_col); cr.add(address_col); cr.add(id_col); cr.add(name_col); cr.add(status_col); store=Gtk::ListStore::create(cr); treeview->set_model(store); treeview->append_column(T("Type"),pixbuf_col); treeview->append_column_numeric(T("Id"),id_col,"%08x"); treeview->append_column_numeric(T("Address"),address_col,"%08x"); treeview->append_column(T("Name"),name_col); treeview->append_column(T("Status"),status_col); window->show_all(); //status icon statusIcon =Gtk::StatusIcon::create("input-tablet"); statusIcon->set_tooltip_text("MrPDI GUI"); statusIcon->signal_button_press_event().connect(sigc::mem_fun(*this,&Application::on_statusicon_button_press)); core = new Core(); handler = new input::InputHandler(); core->init(); core->set_input_handler(handler); refresh(); Glib::signal_timeout().connect(sigc::mem_fun(*this,&Application::on_timer), 1000); } /** * Destructor * things should be closed here */ ~Application() { cout<<"[Destructor]"<shutdown(); delete handler; delete core; } /** * Refresh device table */ void refresh() { vector selection; vector list; core->update_devices(&list); selection=treeview->get_selection()->get_selected_rows(); store->clear(); for(int n=0;nappend()); if(list[n].type==0)row.set_value >(0,pix_tablet); else row.set_value >(0,pix_whiteboard); row.set_value(1,list[n].address); row.set_value(2,list[n].id); row.set_value(3,list[n].name); if(list[n].status==1)row.set_value(4,T("Running")); else row.set_value(4,T("Stop")); vector parameters; core->get_parameter_list(list[n].id,¶meters); /* for(int m=0;m> "<0) treeview->get_selection()->select(selection[0]); } /** * Window state hook */ bool on_window_state_changed(GdkEventWindowState* event) { cout<<"State:"<new_window_state<new_window_state & GDK_WINDOW_STATE_ICONIFIED) == GDK_WINDOW_STATE_ICONIFIED) { cout<<"Minimize!"<hide(); } return false; } /** * Notify Area Icon hook */ bool on_statusicon_button_press(GdkEventButton* event) { if(event->button==1) { cout<<"Maximize!"<maximize(); window->deiconify(); window->show_all(); } return false; } /** * Timer handler */ int on_timer() { //cout<<"tic tac!!!"<hide(); } /** * Dialog accept */ void on_dlg_accept() { core->shutdown(); Gtk::Main::quit(); } /** * Close button */ void on_btnclose_clicked() { dlgClose->show_all(); } /** * Calibrate */ void on_btncalibrate_clicked() { Glib::RefPtr selection; Gtk::TreeModel::iterator iter; unsigned int id,address,value; cout<<"[Calibrate]"<get_selection(); iter=selection->get_selected(); if(iter) { Gtk::TreeModel::Row row = *iter; row.get_value(2,id); row.get_value(1,address); cout<<"Debugging "<calibrate(address); } } /** * Debug mode */ void on_btndebug_clicked() { Glib::RefPtr selection; Gtk::TreeModel::iterator iter; unsigned int id,address,value; cout<<"[Debug]"<get_selection(); iter=selection->get_selected(); if(iter) { Gtk::TreeModel::Row row = *iter; row.get_value(2,id); row.get_value(1,address); cout<<"Debugging "<get_parameter(id,"common.debug",&value); core->set_parameter(id,"common.debug",(~value) & 1); } } /** * Refresh button click signal */ void on_btnrefresh_clicked() { cout<<"[Refresh]"< selection; Gtk::TreeModel::iterator iter; unsigned int id,address; cout<<"[Run]"<get_selection(); iter=selection->get_selected(); if(iter) { Gtk::TreeModel::Row row = *iter; row.get_value(2,id); row.get_value(1,address); cout<<"Turning on "<start(id,address); } } /** * Stop button clicked */ void on_btnstop_clicked() { Glib::RefPtr selection; Gtk::TreeModel::iterator iter; unsigned int id,address; cout<<"[Stop]"<get_selection(); iter=selection->get_selected(); if(iter) { Gtk::TreeModel::Row row = *iter; row.get_value(2,id); row.get_value(1,address); cout<<"Shutting down"<stop(id,address); } } /** * Destroy window event */ bool on_window_destroy(GdkEventAny* event) { Gtk::Main::quit(); return false; } }; /** * Main */ int main(int argc,char * argv[]) { textdomain("mrpdi-gui"); Gtk::Main kit(argc, argv); Application app; Gtk::Main::run(); return 0; }