3 This file is part of the MSP Märklin suite
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"
15 using namespace Marklin;
17 TimetableDialog::TimetableDialog(const GLtk::Resources &r, Timetable &tt):
26 add_button(*(btn = new GLtk::Button(res, "Cncl")), 0);
27 btn->set_geometry(GLtk::Geometry(geom.w-80, 10, 30, 25));
28 btn->set_style("red");
30 add_button(*(btn = new GLtk::Button(res, "OK")), 1);
31 btn->set_geometry(GLtk::Geometry(geom.w-40, 10, 30, 25));
32 btn->set_style("green");
34 add(*(tgl_enabled = new GLtk::Toggle(res, "On")));
35 tgl_enabled->set_geometry(GLtk::Geometry(10, 10, 40, 27));
36 tgl_enabled->set_value(timetable.is_enabled());
37 tgl_enabled->signal_toggled.connect(sigc::mem_fun(this, &TimetableDialog::enabled_toggled));
39 add(*(ent_timetable = new GLtk::Entry(res)));
40 ent_timetable->set_geometry(GLtk::Geometry(10, 45, geom.w-20, geom.h-55));
41 ent_timetable->set_style("multiline");
42 ent_timetable->set_multiline(true);
45 for(unsigned i=0; i<timetable.get_n_rows(); ++i)
49 text += timetable.get_row(i).str();
51 ent_timetable->set_text(text);
54 void TimetableDialog::enabled_toggled(bool value)
56 timetable.set_enabled(value);
60 void TimetableDialog::on_response(int code)
64 vector<string> lines = split(ent_timetable->get_text(), '\n');
65 vector<Timetable::Row> rows;
66 rows.reserve(lines.size());
69 for(vector<string>::const_iterator i=lines.begin(); i!=lines.end(); ++i)
70 rows.push_back(Timetable::Row::parse(*i));
72 for(vector<Timetable::Row>::const_iterator i=rows.begin(); i!=rows.end(); ++i)
75 catch(const Exception &e)
77 // XXX Need a better way to report errors. Also, should not let the dialog close.
78 IO::print("%s\n", e.what());