X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Fwx%2Fkdm_dialog.cc;h=02b91a1e2aa3e30b4fa479230b7b74d8b0cd02de;hb=a1b0ed4ac0753b420ce8ab8467165e220bdb4b05;hp=34004902b79d905950b295782b236b519ed814a0;hpb=914849f57d4979d537fe4215576bc6e05d2f8795;p=dcpomatic.git diff --git a/src/wx/kdm_dialog.cc b/src/wx/kdm_dialog.cc index 34004902b..02b91a1e2 100644 --- a/src/wx/kdm_dialog.cc +++ b/src/wx/kdm_dialog.cc @@ -20,13 +20,14 @@ #include #include #include +#include #include "lib/cinema.h" #include "lib/config.h" #include "kdm_dialog.h" #include "cinema_dialog.h" #include "screen_dialog.h" #include "wx_util.h" -#ifdef __WXMSW__ +#ifdef DCPOMATIC_USE_OWN_DIR_PICKER #include "dir_picker_ctrl.h" #else #include @@ -43,9 +44,6 @@ KDMDialog::KDMDialog (wxWindow* parent) : wxDialog (parent, wxID_ANY, _("Make KDMs")) { wxBoxSizer* vertical = new wxBoxSizer (wxVERTICAL); - - add_label_to_sizer (vertical, this, "Make KDMs for"); - wxBoxSizer* targets = new wxBoxSizer (wxHORIZONTAL); _targets = new wxTreeCtrl (this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTR_HIDE_ROOT | wxTR_MULTIPLE | wxTR_HAS_BUTTONS); @@ -63,62 +61,73 @@ KDMDialog::KDMDialog (wxWindow* parent) wxBoxSizer* target_buttons = new wxBoxSizer (wxVERTICAL); _add_cinema = new wxButton (this, wxID_ANY, _("Add Cinema...")); - target_buttons->Add (_add_cinema, 1, 0, 6); + target_buttons->Add (_add_cinema, 1, wxEXPAND, 6); _edit_cinema = new wxButton (this, wxID_ANY, _("Edit Cinema...")); - target_buttons->Add (_edit_cinema, 1, 0, 6); + target_buttons->Add (_edit_cinema, 1, wxEXPAND, 6); _remove_cinema = new wxButton (this, wxID_ANY, _("Remove Cinema")); - target_buttons->Add (_remove_cinema, 1, 0, 6); + target_buttons->Add (_remove_cinema, 1, wxEXPAND, 6); _add_screen = new wxButton (this, wxID_ANY, _("Add Screen...")); - target_buttons->Add (_add_screen, 1, 0, 6); + target_buttons->Add (_add_screen, 1, wxEXPAND, 6); _edit_screen = new wxButton (this, wxID_ANY, _("Edit Screen...")); - target_buttons->Add (_edit_screen, 1, 0, 6); + target_buttons->Add (_edit_screen, 1, wxEXPAND, 6); _remove_screen = new wxButton (this, wxID_ANY, _("Remove Screen")); - target_buttons->Add (_remove_screen, 1, 0, 6); + target_buttons->Add (_remove_screen, 1, wxEXPAND, 6); targets->Add (target_buttons, 0, 0, 6); vertical->Add (targets, 1, wxEXPAND | wxALL, 6); wxFlexGridSizer* table = new wxFlexGridSizer (3, 2, 6); - add_label_to_sizer (table, this, "From"); + add_label_to_sizer (table, this, _("From"), true); _from_date = new wxDatePickerCtrl (this, wxID_ANY); table->Add (_from_date, 1, wxEXPAND); _from_time = new wxTimePickerCtrl (this, wxID_ANY); table->Add (_from_time, 1, wxEXPAND); - add_label_to_sizer (table, this, "Until"); + add_label_to_sizer (table, this, _("Until"), true); _until_date = new wxDatePickerCtrl (this, wxID_ANY); table->Add (_until_date, 1, wxEXPAND); _until_time = new wxTimePickerCtrl (this, wxID_ANY); table->Add (_until_time, 1, wxEXPAND); - add_label_to_sizer (table, this, "Write to"); + _write_to = new wxRadioButton (this, wxID_ANY, _("Write to")); + table->Add (_write_to, 1, wxEXPAND); -#ifdef __WXMSW__ - _folder = new DirPickerCtrl (this); +#ifdef DCPOMATIC_USE_OWN_DIR_PICKER + _folder = new DirPickerCtrl (this); #else - _folder = new wxDirPickerCtrl (this, wxDD_DIR_MUST_EXIST); + _folder = new wxDirPickerCtrl (this, wxID_ANY); #endif + _folder->SetPath (wxStandardPaths::Get().GetDocumentsDir()); + table->Add (_folder, 1, wxEXPAND); + table->AddSpacer (0); + + _email = new wxRadioButton (this, wxID_ANY, _("Send by email")); + table->Add (_email, 1, wxEXPAND); + table->AddSpacer (0); vertical->Add (table, 0, wxEXPAND | wxALL, 6); - wxSizer* buttons = CreateSeparatedButtonSizer (wxOK); + wxSizer* buttons = CreateSeparatedButtonSizer (wxOK | wxCANCEL); if (buttons) { vertical->Add (buttons, wxSizerFlags().Expand().DoubleBorder()); } - _targets->Connect (wxID_ANY, wxEVT_COMMAND_TREE_SEL_CHANGED, wxCommandEventHandler (KDMDialog::targets_selection_changed), 0, this); + _targets->Bind (wxEVT_COMMAND_TREE_SEL_CHANGED, boost::bind (&KDMDialog::setup_sensitivity, this)); + + _add_cinema->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&KDMDialog::add_cinema_clicked, this)); + _edit_cinema->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&KDMDialog::edit_cinema_clicked, this)); + _remove_cinema->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&KDMDialog::remove_cinema_clicked, this)); - _add_cinema->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (KDMDialog::add_cinema_clicked), 0, this); - _edit_cinema->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (KDMDialog::edit_cinema_clicked), 0, this); - _remove_cinema->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (KDMDialog::remove_cinema_clicked), 0, this); + _add_screen->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&KDMDialog::add_screen_clicked, this)); + _edit_screen->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&KDMDialog::edit_screen_clicked, this)); + _remove_screen->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&KDMDialog::remove_screen_clicked, this)); - _add_screen->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (KDMDialog::add_screen_clicked), 0, this); - _edit_screen->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (KDMDialog::edit_screen_clicked), 0, this); - _remove_screen->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (KDMDialog::remove_screen_clicked), 0, this); + _write_to->Bind (wxEVT_COMMAND_RADIOBUTTON_SELECTED, boost::bind (&KDMDialog::setup_sensitivity, this)); + _email->Bind (wxEVT_COMMAND_RADIOBUTTON_SELECTED, boost::bind (&KDMDialog::setup_sensitivity, this)); setup_sensitivity (); @@ -161,12 +170,6 @@ KDMDialog::selected_screens () const return c; } -void -KDMDialog::targets_selection_changed (wxCommandEvent &) -{ - setup_sensitivity (); -} - void KDMDialog::setup_sensitivity () { @@ -179,6 +182,11 @@ KDMDialog::setup_sensitivity () _add_screen->Enable (sc); _edit_screen->Enable (ss); _remove_screen->Enable (ss); + + wxButton* ok = dynamic_cast (FindWindowById (wxID_OK)); + ok->Enable (sc || ss); + + _folder->Enable (_write_to->GetValue ()); } void @@ -186,7 +194,8 @@ KDMDialog::add_cinema (shared_ptr c) { _cinemas[_targets->AppendItem (_root, std_to_wx (c->name))] = c; - for (list >::iterator i = c->screens.begin(); i != c->screens.end(); ++i) { + list > sc = c->screens (); + for (list >::iterator i = sc.begin(); i != sc.end(); ++i) { add_screen (c, *i); } } @@ -207,7 +216,7 @@ KDMDialog::add_screen (shared_ptr c, shared_ptr s) } void -KDMDialog::add_cinema_clicked (wxCommandEvent &) +KDMDialog::add_cinema_clicked () { CinemaDialog* d = new CinemaDialog (this, "Add Cinema"); d->ShowModal (); @@ -222,7 +231,7 @@ KDMDialog::add_cinema_clicked (wxCommandEvent &) } void -KDMDialog::edit_cinema_clicked (wxCommandEvent &) +KDMDialog::edit_cinema_clicked () { if (selected_cinemas().size() != 1) { return; @@ -243,7 +252,7 @@ KDMDialog::edit_cinema_clicked (wxCommandEvent &) } void -KDMDialog::remove_cinema_clicked (wxCommandEvent &) +KDMDialog::remove_cinema_clicked () { if (selected_cinemas().size() != 1) { return; @@ -258,7 +267,7 @@ KDMDialog::remove_cinema_clicked (wxCommandEvent &) } void -KDMDialog::add_screen_clicked (wxCommandEvent &) +KDMDialog::add_screen_clicked () { if (selected_cinemas().size() != 1) { return; @@ -267,10 +276,12 @@ KDMDialog::add_screen_clicked (wxCommandEvent &) shared_ptr c = selected_cinemas().front().second; ScreenDialog* d = new ScreenDialog (this, "Add Screen"); - d->ShowModal (); + if (d->ShowModal () != wxID_OK) { + return; + } - shared_ptr s (new Screen (d->name())); - c->screens.push_back (s); + shared_ptr s (new Screen (d->name(), d->certificate())); + c->add_screen (s); add_screen (c, s); Config::instance()->write (); @@ -279,7 +290,7 @@ KDMDialog::add_screen_clicked (wxCommandEvent &) } void -KDMDialog::edit_screen_clicked (wxCommandEvent &) +KDMDialog::edit_screen_clicked () { if (selected_screens().size() != 1) { return; @@ -287,10 +298,11 @@ KDMDialog::edit_screen_clicked (wxCommandEvent &) pair > s = selected_screens().front(); - ScreenDialog* d = new ScreenDialog (this, "Edit screen", s.second->name); + ScreenDialog* d = new ScreenDialog (this, "Edit screen", s.second->name, s.second->certificate); d->ShowModal (); s.second->name = d->name (); + s.second->certificate = d->certificate (); _targets->SetItemText (s.first, std_to_wx (d->name())); Config::instance()->write (); @@ -299,7 +311,7 @@ KDMDialog::edit_screen_clicked (wxCommandEvent &) } void -KDMDialog::remove_screen_clicked (wxCommandEvent &) +KDMDialog::remove_screen_clicked () { if (selected_screens().size() != 1) { return; @@ -308,7 +320,8 @@ KDMDialog::remove_screen_clicked (wxCommandEvent &) pair > s = selected_screens().front(); map >::iterator i = _cinemas.begin (); - while (i != _cinemas.end() && find (i->second->screens.begin(), i->second->screens.end(), s.second) == i->second->screens.end()) { + list > sc = i->second->screens (); + while (i != _cinemas.end() && find (sc.begin(), sc.end(), s.second) == sc.end()) { ++i; } @@ -316,8 +329,67 @@ KDMDialog::remove_screen_clicked (wxCommandEvent &) return; } - i->second->screens.remove (s.second); + i->second->remove_screen (s.second); _targets->Delete (s.first); Config::instance()->write (); } + +list > +KDMDialog::screens () const +{ + list > s; + + list > > cinemas = selected_cinemas (); + for (list > >::iterator i = cinemas.begin(); i != cinemas.end(); ++i) { + list > sc = i->second->screens (); + for (list >::const_iterator j = sc.begin(); j != sc.end(); ++j) { + s.push_back (*j); + } + } + + list > > screens = selected_screens (); + for (list > >::iterator i = screens.begin(); i != screens.end(); ++i) { + s.push_back (i->second); + } + + s.sort (); + s.unique (); + + return s; +} + +boost::posix_time::ptime +KDMDialog::from () const +{ + return posix_time (_from_date, _from_time); +} + +boost::posix_time::ptime +KDMDialog::posix_time (wxDatePickerCtrl* date_picker, wxTimePickerCtrl* time_picker) +{ + wxDateTime const date = date_picker->GetValue (); + wxDateTime const time = time_picker->GetValue (); + return boost::posix_time::ptime ( + boost::gregorian::date (date.GetYear(), date.GetMonth() + 1, date.GetDay()), + boost::posix_time::time_duration (time.GetHour(), time.GetMinute(), time.GetSecond()) + ); +} + +boost::posix_time::ptime +KDMDialog::until () const +{ + return posix_time (_until_date, _until_time); +} + +string +KDMDialog::directory () const +{ + return wx_to_std (_folder->GetPath ()); +} + +bool +KDMDialog::write_to () const +{ + return _write_to->GetValue (); +}