#include #include #include #include #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; AppIndicator *indicator; map settings_map; bool corrupted_settings; /** * Constructor */ Application() { cout<<"* Starting MrPDI gui"< 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(); indicator = app_indicator_new ("mrpdi","input-tablet", APP_INDICATOR_CATEGORY_APPLICATION_STATUS); app_indicator_set_status (indicator, APP_INDICATOR_STATUS_ACTIVE); app_indicator_set_attention_icon (indicator, "input-tablet"); Gtk::Menu * menu = new Gtk::Menu(); Gtk::MenuItem * itm_show=new Gtk::MenuItem(T("Show")); menu->append(*itm_show); itm_show->signal_activate().connect(sigc::mem_fun(*this,&Application::on_indicator_show_click)); menu->show_all(); app_indicator_set_menu(indicator,menu->gobj()); core = new Core(); handler = new input::InputHandler(); core->init(); core->set_input_handler(handler); handler->set_settings(settings_map); refresh(); Glib::signal_timeout().connect(sigc::mem_fun(*this,&Application::on_timer), 1000); } /** * Destructor * things should be closed here */ ~Application() { cout<<"* Shutting down MrPDI gui"<shutdown(); settings_map = handler->get_settings(); if(!corrupted_settings) save_setup(); delete handler; delete core; } void on_indicator_show_click() { window->deiconify(); window->show_all(); } /** * loads calibration setup * */ void load_setup() { struct passwd * pwd; cout<<"* Loading settings"<::iterator it; for(it=settings_map.begin();it!=settings_map.end();it++) { libconfig::Setting & device = devices.add(libconfig::Setting::TypeGroup); //id libconfig::Setting & id = device.add("id",libconfig::Setting::TypeInt); id.setFormat(libconfig::Setting::FormatHex); id=(int)it->first; //name libconfig::Setting & name = device.add("name",libconfig::Setting::TypeString); name=it->second.name; //calibration libconfig::Setting & calibration = device.add("calibration",libconfig::Setting::TypeArray); for(int n=0;n<8;n++) { libconfig::Setting & f = calibration.add(libconfig::Setting::TypeFloat); f=it->second.calibration[n]; } //params libconfig::Setting & params = device.add("params",libconfig::Setting::TypeList); std::map::iterator pit; for(pit=it->second.params.begin();pit!=it->second.params.end();pit++) { cout<<"* name:"<first<<" value:"<second<first; libconfig::Setting & pvalue = param.add("value",libconfig::Setting::TypeInt); pvalue=(int)pit->second; } } cfg.writeFile(path.c_str()); } /** * 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); } if(selection.size()>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; } /** * 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<<"* Turning off "<stop(id,address); } } /** * Destroy window event */ bool on_window_destroy(GdkEventAny* event) { dlgClose->show_all(); return true; } }; /** * Main */ int main(int argc,char * argv[]) { textdomain("mrpdi-gui"); Gtk::Main kit(argc, argv); Application app; Gtk::Main::run(); return 0; }