3 This file is part of R²C²
4 Copyright © 2010 Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
8 #include <msp/gltk/button.h>
9 #include <msp/io/print.h>
10 #include <msp/strings/utils.h>
11 #include "timetabledialog.h"
17 TimetableDialog::TimetableDialog(Timetable &tt):
24 add_button(*(btn = new GLtk::Button("Cncl")), 0);
25 btn->set_geometry(GLtk::Geometry(geom.w-80, 10, 30, 25));
26 btn->set_style("red");
28 add_button(*(btn = new GLtk::Button("OK")), 1);
29 btn->set_geometry(GLtk::Geometry(geom.w-40, 10, 30, 25));
30 btn->set_style("green");
32 add(*(tgl_enabled = new GLtk::Toggle("On")));
33 tgl_enabled->set_geometry(GLtk::Geometry(10, 10, 40, 27));
34 tgl_enabled->set_value(timetable.is_enabled());
35 tgl_enabled->signal_toggled.connect(sigc::mem_fun(this, &TimetableDialog::enabled_toggled));
37 add(*(ent_timetable = new GLtk::Entry));
38 ent_timetable->set_geometry(GLtk::Geometry(10, 45, geom.w-20, geom.h-55));
39 ent_timetable->set_style("multiline");
40 ent_timetable->set_multiline(true);
43 for(unsigned i=0; i<timetable.get_n_rows(); ++i)
47 text += timetable.get_row(i).str();
49 ent_timetable->set_text(text);
52 void TimetableDialog::enabled_toggled(bool value)
54 timetable.set_enabled(value);
58 void TimetableDialog::on_response(int code)
62 vector<string> lines = split(ent_timetable->get_text(), '\n');
63 vector<Timetable::Row> rows;
64 rows.reserve(lines.size());
67 for(vector<string>::const_iterator i=lines.begin(); i!=lines.end(); ++i)
68 rows.push_back(Timetable::Row::parse(*i));
70 for(vector<Timetable::Row>::const_iterator i=rows.begin(); i!=rows.end(); ++i)
73 catch(const Exception &e)
75 // XXX Need a better way to report errors. Also, should not let the dialog close.
76 IO::print("%s\n", e.what());