1 #include <msp/gltk/button.h>
2 #include <msp/io/print.h>
3 #include <msp/strings/utils.h>
4 #include "timetabledialog.h"
10 TimetableDialog::TimetableDialog(Timetable &tt):
17 add_button(*(btn = new GLtk::Button("Cncl")), 0);
18 btn->set_geometry(GLtk::Geometry(geom.w-80, 10, 30, 25));
19 btn->set_style("red");
21 add_button(*(btn = new GLtk::Button("OK")), 1);
22 btn->set_geometry(GLtk::Geometry(geom.w-40, 10, 30, 25));
23 btn->set_style("green");
25 add(*(tgl_enabled = new GLtk::Toggle("On")));
26 tgl_enabled->set_geometry(GLtk::Geometry(10, 10, 40, 27));
27 tgl_enabled->set_value(timetable.is_enabled());
28 tgl_enabled->signal_toggled.connect(sigc::mem_fun(this, &TimetableDialog::enabled_toggled));
30 add(*(ent_timetable = new GLtk::Entry));
31 ent_timetable->set_geometry(GLtk::Geometry(10, 45, geom.w-20, geom.h-55));
32 ent_timetable->set_style("multiline");
33 ent_timetable->set_multiline(true);
36 for(unsigned i=0; i<timetable.get_n_rows(); ++i)
40 text += timetable.get_row(i).str();
42 ent_timetable->set_text(text);
45 void TimetableDialog::enabled_toggled(bool value)
47 timetable.set_enabled(value);
51 void TimetableDialog::on_response(int code)
55 vector<string> lines = split(ent_timetable->get_text(), '\n');
56 vector<Timetable::Row> rows;
57 rows.reserve(lines.size());
60 for(vector<string>::const_iterator i=lines.begin(); i!=lines.end(); ++i)
61 rows.push_back(Timetable::Row::parse(*i));
63 for(vector<Timetable::Row>::const_iterator i=rows.begin(); i!=rows.end(); ++i)
66 catch(const exception &e)
68 // XXX Need a better way to report errors. Also, should not let the dialog close.
69 IO::print("%s\n", e.what());