X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fengineer%2Ftrainlistdialog.cpp;h=e84fc883df04252fd8dfd9d7378531bbb68a64b3;hb=9afe42fc94eed6754da8401082e76121f8c66783;hp=f4fbb102fe580b2f114ae0810f2852eb519aa07e;hpb=190829464f446f211e4aff058bb555519a65c6ee;p=r2c2.git diff --git a/source/engineer/trainlistdialog.cpp b/source/engineer/trainlistdialog.cpp index f4fbb10..e84fc88 100644 --- a/source/engineer/trainlistdialog.cpp +++ b/source/engineer/trainlistdialog.cpp @@ -20,6 +20,15 @@ public: }; +class DetectedLocoItem: public GLtk::List::MultiColumnItem +{ +public: + typedef const Driver::DetectedLocomotive *ValueType; + + DetectedLocoItem(ValueType); +}; + + TrainListDialog::TrainListDialog(Engineer &e): engineer(e), layout(engineer.get_layout()) @@ -31,6 +40,13 @@ TrainListDialog::TrainListDialog(Engineer &e): lst_trains->set_data(trains); lst_trains->set_item_type(); + lst_imported = dynamic_cast(get_item(widgets, "lst_imported")); + lst_imported->set_data(detected_locos); + lst_imported->set_item_type(); + + dynamic_cast(get_item(widgets, "tgl_trains"))->signal_toggled.connect(sigc::bind(sigc::mem_fun(this, &TrainListDialog::tab_toggled), lst_trains)); + dynamic_cast(get_item(widgets, "tgl_import"))->signal_toggled.connect(sigc::bind(sigc::mem_fun(this, &TrainListDialog::tab_toggled), lst_imported)); + dynamic_cast(get_item(widgets, "btn_new"))->signal_clicked.connect(sigc::mem_fun(this, &TrainListDialog::new_clicked)); dynamic_cast(get_item(widgets, "btn_show"))->signal_clicked.connect(sigc::mem_fun(this, &TrainListDialog::show_clicked)); @@ -41,6 +57,12 @@ TrainListDialog::TrainListDialog(Engineer &e): i->second->signal_name_changed.connect(sigc::hide(sigc::bind(sigc::mem_fun(this, &TrainListDialog::train_name_changed), sigc::ref(*i->second)))); } + if(layout.has_driver()) + { + Driver &driver = layout.get_driver(); + driver.signal_locomotive_detected.connect(sigc::mem_fun(this, &TrainListDialog::locomotive_detected)); + driver.signal_locomotive_gone.connect(sigc::mem_fun(this, &TrainListDialog::locomotive_gone)); + } layout.signal_train_added.connect(sigc::mem_fun(this, &TrainListDialog::train_added)); layout.signal_train_removed.connect(sigc::mem_fun(this, &TrainListDialog::train_removed)); } @@ -48,6 +70,12 @@ TrainListDialog::TrainListDialog(Engineer &e): void TrainListDialog::new_clicked() { NewTrainDialog *dlg = new NewTrainDialog(engineer); + if(lst_imported->is_visible()) + { + int selected = lst_imported->get_selected_index(); + if(selected>=0) + dlg->prefill(*detected_locos.get(selected)); + } find_ancestor()->add(*dlg); dlg->autosize(); } @@ -62,6 +90,23 @@ void TrainListDialog::show_clicked() } } +void TrainListDialog::tab_toggled(bool value, GLtk::Widget *wdg) +{ + wdg->set_visible(value); +} + +void TrainListDialog::locomotive_detected(const Driver::DetectedLocomotive &loco) +{ + detected_locos.append(&loco); +} + +void TrainListDialog::locomotive_gone(const Driver::DetectedLocomotive &loco) +{ + int index = detected_locos.find(&loco); + if(index>=0) + detected_locos.remove(index); +} + void TrainListDialog::train_added(Train &train) { unsigned n_items = trains.size(); @@ -94,3 +139,10 @@ TrainItem::TrainItem(ValueType train) add(*new GLtk::Label(train->get_name())); } + +DetectedLocoItem::DetectedLocoItem(ValueType loco) +{ + add(*new GLtk::Label(loco->protocol)); + add(*new GLtk::Label(lexical_cast(loco->address))); + add(*new GLtk::Label(loco->name)); +}