#include "lib/cinema.h"
#include "lib/config.h"
#include "lib/screen.h"
+#include "lib/timer.h"
#include <unicode/putil.h>
#include <unicode/ucol.h>
#include <unicode/uiter.h>
auto targets = new wxBoxSizer (wxHORIZONTAL);
_targets = new wxTreeListCtrl (this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTL_MULTIPLE | wxTL_3STATE | wxTL_NO_HEADER);
_targets->AppendColumn (wxT("foo"));
- _targets->SetSortColumn (0);
- _targets->SetItemComparator (&_comparator);
targets->Add (_targets, 1, wxEXPAND | wxRIGHT, DCPOMATIC_SIZER_GAP);
add_cinemas ();
+ auto side_buttons = new wxBoxSizer (wxVERTICAL);
+
auto target_buttons = new wxBoxSizer (wxVERTICAL);
_add_cinema = new Button (this, _("Add Cinema..."));
_remove_screen = new Button (this, _("Remove Screen"));
target_buttons->Add (_remove_screen, 1, wxEXPAND | wxBOTTOM, DCPOMATIC_BUTTON_STACK_GAP);
- targets->Add (target_buttons, 0, 0);
+ side_buttons->Add (target_buttons, 0, 0);
+
+ auto check_buttons = new wxBoxSizer (wxVERTICAL);
+
+ _check_all = new Button (this, _("Check all"));
+ check_buttons->Add (_check_all, 1, wxEXPAND | wxBOTTOM, DCPOMATIC_BUTTON_STACK_GAP);
+ _uncheck_all = new Button (this, _("Uncheck all"));
+ check_buttons->Add (_uncheck_all, 1, wxEXPAND | wxBOTTOM, DCPOMATIC_BUTTON_STACK_GAP);
+
+ side_buttons->Add (check_buttons, 1, wxEXPAND | wxTOP, DCPOMATIC_BUTTON_STACK_GAP * 8);
+
+ targets->Add (side_buttons, 0, 0);
sizer->Add (targets, 1, wxEXPAND);
_edit_screen->Bind (wxEVT_BUTTON, boost::bind (&ScreensPanel::edit_screen_clicked, this));
_remove_screen->Bind (wxEVT_BUTTON, boost::bind (&ScreensPanel::remove_screen_clicked, this));
+ _check_all->Bind (wxEVT_BUTTON, boost::bind(&ScreensPanel::check_all, this));
+ _uncheck_all->Bind (wxEVT_BUTTON, boost::bind(&ScreensPanel::uncheck_all, this));
+
SetSizer (sizer);
+
+ UErrorCode status = U_ZERO_ERROR;
+ _collator = ucol_open(nullptr, &status);
+ if (_collator) {
+ ucol_setAttribute(_collator, UCOL_NORMALIZATION_MODE, UCOL_ON, &status);
+ ucol_setAttribute(_collator, UCOL_STRENGTH, UCOL_PRIMARY, &status);
+ ucol_setAttribute(_collator, UCOL_ALTERNATE_HANDLING, UCOL_SHIFTED, &status);
+ }
}
{
_targets->Unbind (wxEVT_TREELIST_SELECTION_CHANGED, &ScreensPanel::selection_changed_shim, this);
_targets->Unbind (wxEVT_TREELIST_ITEM_CHECKED, &ScreensPanel::checkbox_changed, this);
+
+ if (_collator) {
+ ucol_close (_collator);
+ }
+}
+
+
+void
+ScreensPanel::check_all ()
+{
+ for (auto cinema = _targets->GetFirstChild(_targets->GetRootItem()); cinema.IsOk(); cinema = _targets->GetNextSibling(cinema)) {
+ _targets->CheckItem(cinema, wxCHK_CHECKED);
+ for (auto screen = _targets->GetFirstChild(cinema); screen.IsOk(); screen = _targets->GetNextSibling(screen)) {
+ _targets->CheckItem(screen, wxCHK_CHECKED);
+ set_screen_checked(screen, true);
+ }
+ }
+}
+
+
+void
+ScreensPanel::uncheck_all ()
+{
+ for (auto cinema = _targets->GetFirstChild(_targets->GetRootItem()); cinema.IsOk(); cinema = _targets->GetNextSibling(cinema)) {
+ _targets->CheckItem(cinema, wxCHK_UNCHECKED);
+ for (auto screen = _targets->GetFirstChild(cinema); screen.IsOk(); screen = _targets->GetNextSibling(screen)) {
+ _targets->CheckItem(screen, wxCHK_UNCHECKED);
+ set_screen_checked(screen, false);
+ }
+ }
}
optional<wxTreeListItem>
-ScreensPanel::add_cinema (shared_ptr<Cinema> cinema)
+ScreensPanel::add_cinema (shared_ptr<Cinema> cinema, wxTreeListItem previous)
{
auto search = wx_to_std (_search->GetValue ());
transform (search.begin(), search.end(), search.begin(), ::tolower);
}
}
- auto id = _targets->AppendItem(_targets->GetRootItem(), std_to_wx(cinema->name));
+ auto id = _targets->InsertItem(_targets->GetRootItem(), previous, std_to_wx(cinema->name));
- _cinemas.push_back(make_pair(id, cinema));
_item_to_cinema[id] = cinema;
_cinema_to_item[cinema] = id;
auto id = _targets->AppendItem(*item, std_to_wx(screen->name));
- _screens.push_back(make_pair(id, screen));
_item_to_screen[id] = screen;
_screen_to_item[screen] = id;
auto d = new CinemaDialog (GetParent(), _("Add Cinema"));
if (d->ShowModal () == wxID_OK) {
auto cinema = make_shared<Cinema>(d->name(), d->emails(), d->notes(), d->utc_offset_hour(), d->utc_offset_minute());
- Config::instance()->add_cinema (cinema);
- auto id = add_cinema (cinema);
- if (id) {
+
+ auto cinemas = Config::instance()->cinemas();
+ cinemas.sort(
+ [this](shared_ptr<Cinema> a, shared_ptr<Cinema> b) { return compare(a->name, b->name) < 0; }
+ );
+
+ optional<wxTreeListItem> item;
+ for (auto existing_cinema: cinemas) {
+ if (!item && compare(d->name(), existing_cinema->name) < 0) {
+ if (auto existing_item = cinema_to_item(existing_cinema)) {
+ item = add_cinema (cinema, *existing_item);
+ }
+ }
+ }
+
+ if (!item) {
+ item = add_cinema (cinema, wxTLI_LAST);
+ }
+
+ if (item) {
_targets->UnselectAll ();
- _targets->Select (*id);
+ _targets->Select (*item);
}
+
+ Config::instance()->add_cinema (cinema);
}
d->Destroy ();
+
+ selection_changed ();
}
-optional<pair<wxTreeListItem, shared_ptr<Cinema>>>
+shared_ptr<Cinema>
ScreensPanel::cinema_for_operation () const
{
if (_selected_cinemas.size() == 1) {
- return make_pair(_selected_cinemas.begin()->first, _selected_cinemas.begin()->second);
+ return _selected_cinemas[0];
} else if (_selected_screens.size() == 1) {
- return make_pair(_targets->GetItemParent(_selected_screens.begin()->first), _selected_screens.begin()->second->cinema);
+ return _selected_screens[0]->cinema;
}
return {};
}
auto d = new CinemaDialog (
- GetParent(), _("Edit cinema"), cinema->second->name, cinema->second->emails, cinema->second->notes, cinema->second->utc_offset_hour(), cinema->second->utc_offset_minute()
+ GetParent(), _("Edit cinema"), cinema->name, cinema->emails, cinema->notes, cinema->utc_offset_hour(), cinema->utc_offset_minute()
);
if (d->ShowModal() == wxID_OK) {
- cinema->second->name = d->name ();
- cinema->second->emails = d->emails ();
- cinema->second->notes = d->notes ();
- cinema->second->set_utc_offset_hour (d->utc_offset_hour ());
- cinema->second->set_utc_offset_minute (d->utc_offset_minute ());
- _targets->SetItemText (cinema->first, std_to_wx(d->name()));
+ cinema->name = d->name();
+ cinema->emails = d->emails();
+ cinema->notes = d->notes();
+ cinema->set_utc_offset_hour(d->utc_offset_hour());
+ cinema->set_utc_offset_minute(d->utc_offset_minute());
+ auto item = cinema_to_item(cinema);
+ DCPOMATIC_ASSERT(item);
+ _targets->SetItemText (*item, std_to_wx(d->name()));
Config::instance()->changed (Config::CINEMAS);
}
ScreensPanel::remove_cinema_clicked ()
{
if (_selected_cinemas.size() == 1) {
- if (!confirm_dialog(this, wxString::Format(_("Are you sure you want to remove the cinema '%s'?"), std_to_wx(_selected_cinemas.begin()->second->name)))) {
+ if (!confirm_dialog(this, wxString::Format(_("Are you sure you want to remove the cinema '%s'?"), std_to_wx(_selected_cinemas[0]->name)))) {
return;
}
} else {
}
}
- for (auto const& i: _selected_cinemas) {
- Config::instance()->remove_cinema (i.second);
- _targets->DeleteItem (i.first);
+ for (auto const& cinema: _selected_cinemas) {
+ Config::instance()->remove_cinema(cinema);
+ auto item = cinema_to_item(cinema);
+ DCPOMATIC_ASSERT(item);
+ _targets->DeleteItem(*item);
}
selection_changed ();
return;
}
- for (auto screen: cinema->second->screens()) {
+ for (auto screen: cinema->screens()) {
if (screen->name == d->name()) {
error_dialog (
GetParent(),
}
auto screen = std::make_shared<Screen>(d->name(), d->notes(), d->recipient(), d->recipient_file(), d->trusted_devices());
- cinema->second->add_screen (screen);
- auto id = add_screen (cinema->second, screen);
+ cinema->add_screen (screen);
+ auto id = add_screen (cinema, screen);
if (id) {
_targets->Expand (id.get ());
}
return;
}
- auto edit_screen = *_selected_screens.begin();
+ auto edit_screen = _selected_screens[0];
auto d = new ScreenDialog (
GetParent(), _("Edit screen"),
- edit_screen.second->name,
- edit_screen.second->notes,
- edit_screen.second->recipient,
- edit_screen.second->recipient_file,
- edit_screen.second->trusted_devices
+ edit_screen->name,
+ edit_screen->notes,
+ edit_screen->recipient,
+ edit_screen->recipient_file,
+ edit_screen->trusted_devices
);
if (d->ShowModal() != wxID_OK) {
return;
}
- auto cinema = edit_screen.second->cinema;
+ auto cinema = edit_screen->cinema;
for (auto screen: cinema->screens()) {
- if (screen != edit_screen.second && screen->name == d->name()) {
+ if (screen != edit_screen && screen->name == d->name()) {
error_dialog (
GetParent(),
wxString::Format (
}
}
- edit_screen.second->name = d->name ();
- edit_screen.second->notes = d->notes ();
- edit_screen.second->recipient = d->recipient ();
- edit_screen.second->recipient_file = d->recipient_file ();
- edit_screen.second->trusted_devices = d->trusted_devices ();
- _targets->SetItemText (edit_screen.first, std_to_wx(d->name()));
+ edit_screen->name = d->name();
+ edit_screen->notes = d->notes();
+ edit_screen->recipient = d->recipient();
+ edit_screen->recipient_file = d->recipient_file();
+ edit_screen->trusted_devices = d->trusted_devices();
+ auto item = screen_to_item(edit_screen);
+ DCPOMATIC_ASSERT (item);
+ _targets->SetItemText (*item, std_to_wx(d->name()));
Config::instance()->changed (Config::CINEMAS);
d->Destroy ();
ScreensPanel::remove_screen_clicked ()
{
if (_selected_screens.size() == 1) {
- if (!confirm_dialog(this, wxString::Format(_("Are you sure you want to remove the screen '%s'?"), std_to_wx(_selected_screens.begin()->second->name)))) {
+ if (!confirm_dialog(this, wxString::Format(_("Are you sure you want to remove the screen '%s'?"), std_to_wx(_selected_screens[0]->name)))) {
return;
}
} else {
}
}
- for (auto const& i: _selected_screens) {
- auto j = _cinemas.begin ();
- while (j != _cinemas.end ()) {
- auto sc = j->second->screens ();
- if (find (sc.begin(), sc.end(), i.second) != sc.end ()) {
- break;
- }
-
- ++j;
- }
-
- if (j == _cinemas.end()) {
- continue;
- }
-
- j->second->remove_screen (i.second);
- _targets->DeleteItem (i.first);
+ for (auto const& screen: _selected_screens) {
+ screen->cinema->remove_screen(screen);
+ auto item = screen_to_item(screen);
+ DCPOMATIC_ASSERT(item);
+ _targets->DeleteItem(*item);
}
Config::instance()->changed (Config::CINEMAS);
ScreensPanel::screens () const
{
vector<shared_ptr<Screen>> output;
-
- for (auto item = _targets->GetFirstItem(); item.IsOk(); item = _targets->GetNextItem(item)) {
- if (_targets->GetCheckedState(item) == wxCHK_CHECKED) {
- if (auto screen = item_to_screen(item)) {
- output.push_back (screen);
- }
- }
- }
-
+ std::copy (_checked_screens.begin(), _checked_screens.end(), std::back_inserter(output));
return output;
}
for (size_t i = 0; i < selection.size(); ++i) {
if (auto cinema = item_to_cinema(selection[i])) {
- _selected_cinemas.push_back(make_pair(selection[i], cinema));
+ _selected_cinemas.push_back(cinema);
}
if (auto screen = item_to_screen(selection[i])) {
- _selected_screens.push_back(make_pair(selection[i], screen));
+ _selected_screens.push_back(screen);
}
}
void
ScreensPanel::add_cinemas ()
{
- for (auto cinema: Config::instance()->cinemas()) {
- add_cinema (cinema);
+ auto cinemas = Config::instance()->cinemas();
+ cinemas.sort(
+ [this](shared_ptr<Cinema> a, shared_ptr<Cinema> b) { return compare(a->name, b->name) < 0; }
+ );
+
+ for (auto cinema: cinemas) {
+ add_cinema (cinema, wxTLI_LAST);
}
}
ScreensPanel::search_changed ()
{
_targets->DeleteAllItems ();
- _cinemas.clear ();
- _screens.clear ();
_item_to_cinema.clear ();
_cinema_to_item.clear ();
_ignore_selection_change = true;
for (auto const& selection: _selected_cinemas) {
- /* The wxTreeListItems will now be different, so we must search by cinema */
- if (auto item = cinema_to_item(selection.second)) {
+ if (auto item = cinema_to_item(selection)) {
_targets->Select (*item);
}
}
for (auto const& selection: _selected_screens) {
- /* Likewise by screen */
- if (auto item = screen_to_item(selection.second)) {
+ if (auto item = screen_to_item(selection)) {
_targets->Select (*item);
}
}
_ignore_check_change = true;
for (auto const& checked: _checked_screens) {
- if (auto item = screen_to_item(checked.second)) {
+ if (auto item = screen_to_item(checked)) {
_targets->CheckItem(*item, wxCHK_CHECKED);
setup_cinema_checked_state(*item);
}
void
ScreensPanel::set_screen_checked (wxTreeListItem item, bool checked)
{
- auto current = std::find_if(
- _checked_screens.begin(), _checked_screens.end(),
- [item](pair<wxTreeListItem, shared_ptr<Screen>> const& screen) { return screen.first == item; }
- );
-
- if (current == _checked_screens.end() && checked) {
- _checked_screens.push_back({item, item_to_screen(item)});
- } else if (current != _checked_screens.end() && !checked) {
- _checked_screens.erase(current);
+ auto screen = item_to_screen(item);
+ DCPOMATIC_ASSERT(screen);
+ if (checked) {
+ _checked_screens.insert(screen);
+ } else {
+ _checked_screens.erase(screen);
}
}
}
-ScreensPanel::Comparator::Comparator ()
-{
- UErrorCode status = U_ZERO_ERROR;
- _collator = ucol_open(nullptr, &status);
- if (_collator) {
- ucol_setAttribute(_collator, UCOL_NORMALIZATION_MODE, UCOL_ON, &status);
- ucol_setAttribute(_collator, UCOL_STRENGTH, UCOL_PRIMARY, &status);
- ucol_setAttribute(_collator, UCOL_ALTERNATE_HANDLING, UCOL_SHIFTED, &status);
- }
-}
-
-ScreensPanel::Comparator::~Comparator ()
-{
- if (_collator) {
- ucol_close (_collator);
- }
-}
-
int
-ScreensPanel::Comparator::Compare (wxTreeListCtrl* tree_list, unsigned, wxTreeListItem a, wxTreeListItem b)
+ScreensPanel::compare (string const& utf8_a, string const& utf8_b)
{
- auto utf8_a = wx_to_std(tree_list->GetItemText(a));
- auto utf8_b = wx_to_std(tree_list->GetItemText(b));
if (_collator) {
UErrorCode error = U_ZERO_ERROR;
boost::scoped_array<uint16_t> utf16_a(new uint16_t[utf8_a.size() + 1]);