X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Fsession_metadata_dialog.cc;h=a4cfee2b1047ff33aa78eca0955fb3419553cdfa;hb=a2c0b10d8a6cf4ab5a0fdcdfe157c35c0ed9a709;hp=f4e708f62ae359cb890c0e5f367f392fea3a9ffd;hpb=9d35a105bd3cfa14bd139028490ce880ce4d7fb5;p=ardour.git diff --git a/gtk2_ardour/session_metadata_dialog.cc b/gtk2_ardour/session_metadata_dialog.cc index f4e708f62a..a4cfee2b10 100644 --- a/gtk2_ardour/session_metadata_dialog.cc +++ b/gtk2_ardour/session_metadata_dialog.cc @@ -30,7 +30,7 @@ #include "ardour/session.h" #include "ardour/session_utils.h" -#include "i18n.h" +#include "pbd/i18n.h" using namespace std; using namespace Glib; @@ -228,6 +228,7 @@ EAN13MetadataField::EAN13MetadataField (Getter getter, Setter setter, string con entry = 0; label = 0; value_label = 0; + status_label = Gtk::manage (new Gtk::Label ("")); } MetadataPtr @@ -249,6 +250,7 @@ EAN13MetadataField::load_data (ARDOUR::SessionMetadata const & data) if (entry) { entry->set_text (_value); } + update_status (); } void @@ -257,6 +259,45 @@ EAN13MetadataField::update_value () // Accept only numeric characters _value = numeric_string (entry->get_text()); entry->set_text (_value); + update_status (); +} + +void +EAN13MetadataField::update_status () +{ + int len = _value.length (); + if (len == 13) { + // calculate EAN-13 modulo 10 check digit + int sum = 0; + const char *p = _value.c_str(); + for (int i = 0; i < 12; i++) { + char c = p[i] - '0'; + if (i % 2) { + sum += c * 3; + } else { + sum += c; + } + } + sum %= 10; + if (sum) + sum = 10 - sum; + + if (sum == p[12] - '0') { + status_label->set_markup (string_compose( + "%1: %2", + _("EAN Check digit OK"), sum)); + } else { + status_label->set_markup (string_compose( + "%1: %2 (%3 %4)", + _("EAN Check digit error"), p[12] - '0', _("expected"), sum)); + } + } else if (len > 0) { + status_label->set_markup (string_compose( + "%1: %2 (<13)", + _("EAN Length error"), len)); + } else { + status_label->set_text(""); + } } Gtk::Widget & @@ -694,6 +735,11 @@ SessionMetadataDialog::init_album_data () ptr = MetadataPtr (new EAN13MetadataField (&ARDOUR::SessionMetadata::barcode, &ARDOUR::SessionMetadata::set_barcode, _("EAN barcode"))); data_set->add_data_field (ptr); + + // EAN13MetadataField is the only kind of MetadataField which has a status label. + EAN13MetadataField &emf = (EAN13MetadataField &) *ptr; + ((Gtk::VBox &) data_set->get_widget()).pack_end (*emf.status_label); + emf.update_status (); } template @@ -857,7 +903,7 @@ SessionMetadataImporter::run () return; } - //create a temporary + //create a temporary ARDOUR::SessionMetadata data; data.set_state (*node, version); init_data ( true ); //skip user data here