Cleanup: white space.
[dcpomatic.git] / src / wx / screens_panel.cc
1 /*
2     Copyright (C) 2015-2022 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21
22 #include "cinema_dialog.h"
23 #include "dcpomatic_button.h"
24 #include "screen_dialog.h"
25 #include "screens_panel.h"
26 #include "wx_util.h"
27 #include "lib/cinema.h"
28 #include "lib/config.h"
29 #include "lib/scope_guard.h"
30 #include "lib/screen.h"
31 #include "lib/timer.h"
32 #include <unicode/putil.h>
33 #include <unicode/ucol.h>
34 #include <unicode/uiter.h>
35 #include <unicode/utypes.h>
36 #include <unicode/ustring.h>
37
38
39 using std::cout;
40 using std::make_pair;
41 using std::make_shared;
42 using std::map;
43 using std::pair;
44 using std::shared_ptr;
45 using std::string;
46 using std::vector;
47 using boost::optional;
48 using namespace dcpomatic;
49
50
51 ScreensPanel::ScreensPanel (wxWindow* parent)
52         : wxPanel (parent, wxID_ANY)
53 {
54         auto sizer = new wxBoxSizer (wxVERTICAL);
55
56         _search = new wxSearchCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(200, search_ctrl_height()));
57 #ifndef __WXGTK3__
58         /* The cancel button seems to be strangely broken in GTK3; clicking on it twice sometimes works */
59         _search->ShowCancelButton (true);
60 #endif
61         sizer->Add (_search, 0, wxBOTTOM, DCPOMATIC_SIZER_GAP);
62
63         auto targets = new wxBoxSizer (wxHORIZONTAL);
64         _targets = new wxTreeListCtrl (this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTL_MULTIPLE | wxTL_3STATE | wxTL_NO_HEADER);
65         _targets->AppendColumn (wxT("foo"));
66
67         targets->Add (_targets, 1, wxEXPAND | wxRIGHT, DCPOMATIC_SIZER_GAP);
68
69         add_cinemas ();
70
71         auto side_buttons = new wxBoxSizer (wxVERTICAL);
72
73         auto target_buttons = new wxBoxSizer (wxVERTICAL);
74
75         _add_cinema = new Button (this, _("Add Cinema..."));
76         target_buttons->Add (_add_cinema, 1, wxEXPAND | wxBOTTOM, DCPOMATIC_BUTTON_STACK_GAP);
77         _edit_cinema = new Button (this, _("Edit Cinema..."));
78         target_buttons->Add (_edit_cinema, 1, wxEXPAND | wxBOTTOM, DCPOMATIC_BUTTON_STACK_GAP);
79         _remove_cinema = new Button (this, _("Remove Cinema"));
80         target_buttons->Add (_remove_cinema, 1, wxEXPAND | wxBOTTOM, DCPOMATIC_BUTTON_STACK_GAP);
81         _add_screen = new Button (this, _("Add Screen..."));
82         target_buttons->Add (_add_screen, 1, wxEXPAND | wxBOTTOM, DCPOMATIC_BUTTON_STACK_GAP);
83         _edit_screen = new Button (this, _("Edit Screen..."));
84         target_buttons->Add (_edit_screen, 1, wxEXPAND | wxBOTTOM, DCPOMATIC_BUTTON_STACK_GAP);
85         _remove_screen = new Button (this, _("Remove Screen"));
86         target_buttons->Add (_remove_screen, 1, wxEXPAND | wxBOTTOM, DCPOMATIC_BUTTON_STACK_GAP);
87
88         side_buttons->Add (target_buttons, 0, 0);
89
90         auto check_buttons = new wxBoxSizer (wxVERTICAL);
91
92         _check_all = new Button (this, _("Check all"));
93         check_buttons->Add (_check_all, 1, wxEXPAND | wxBOTTOM, DCPOMATIC_BUTTON_STACK_GAP);
94         _uncheck_all = new Button (this, _("Uncheck all"));
95         check_buttons->Add (_uncheck_all, 1, wxEXPAND | wxBOTTOM, DCPOMATIC_BUTTON_STACK_GAP);
96
97         side_buttons->Add (check_buttons, 1, wxEXPAND | wxTOP, DCPOMATIC_BUTTON_STACK_GAP * 8);
98
99         targets->Add (side_buttons, 0, 0);
100
101         sizer->Add (targets, 1, wxEXPAND);
102
103         _search->Bind        (wxEVT_TEXT, boost::bind (&ScreensPanel::search_changed, this));
104         _targets->Bind       (wxEVT_TREELIST_SELECTION_CHANGED, &ScreensPanel::selection_changed_shim, this);
105         _targets->Bind       (wxEVT_TREELIST_ITEM_CHECKED, &ScreensPanel::checkbox_changed, this);
106
107         _add_cinema->Bind    (wxEVT_BUTTON, boost::bind (&ScreensPanel::add_cinema_clicked, this));
108         _edit_cinema->Bind   (wxEVT_BUTTON, boost::bind (&ScreensPanel::edit_cinema_clicked, this));
109         _remove_cinema->Bind (wxEVT_BUTTON, boost::bind (&ScreensPanel::remove_cinema_clicked, this));
110
111         _add_screen->Bind    (wxEVT_BUTTON, boost::bind (&ScreensPanel::add_screen_clicked, this));
112         _edit_screen->Bind   (wxEVT_BUTTON, boost::bind (&ScreensPanel::edit_screen_clicked, this));
113         _remove_screen->Bind (wxEVT_BUTTON, boost::bind (&ScreensPanel::remove_screen_clicked, this));
114
115         _check_all->Bind     (wxEVT_BUTTON, boost::bind(&ScreensPanel::check_all, this));
116         _uncheck_all->Bind   (wxEVT_BUTTON, boost::bind(&ScreensPanel::uncheck_all, this));
117
118         SetSizer (sizer);
119
120         UErrorCode status = U_ZERO_ERROR;
121         _collator = ucol_open(nullptr, &status);
122         if (_collator) {
123                 ucol_setAttribute(_collator, UCOL_NORMALIZATION_MODE, UCOL_ON, &status);
124                 ucol_setAttribute(_collator, UCOL_STRENGTH, UCOL_PRIMARY, &status);
125                 ucol_setAttribute(_collator, UCOL_ALTERNATE_HANDLING, UCOL_SHIFTED, &status);
126         }
127 }
128
129
130 ScreensPanel::~ScreensPanel ()
131 {
132         _targets->Unbind (wxEVT_TREELIST_SELECTION_CHANGED, &ScreensPanel::selection_changed_shim, this);
133         _targets->Unbind (wxEVT_TREELIST_ITEM_CHECKED, &ScreensPanel::checkbox_changed, this);
134
135         if (_collator) {
136                 ucol_close (_collator);
137         }
138 }
139
140
141 void
142 ScreensPanel::check_all ()
143 {
144         for (auto cinema = _targets->GetFirstChild(_targets->GetRootItem()); cinema.IsOk();  cinema = _targets->GetNextSibling(cinema)) {
145                 _targets->CheckItem(cinema, wxCHK_CHECKED);
146                 for (auto screen = _targets->GetFirstChild(cinema); screen.IsOk(); screen = _targets->GetNextSibling(screen)) {
147                         _targets->CheckItem(screen, wxCHK_CHECKED);
148                         set_screen_checked(screen, true);
149                 }
150         }
151 }
152
153
154 void
155 ScreensPanel::uncheck_all ()
156 {
157         for (auto cinema = _targets->GetFirstChild(_targets->GetRootItem()); cinema.IsOk();  cinema = _targets->GetNextSibling(cinema)) {
158                 _targets->CheckItem(cinema, wxCHK_UNCHECKED);
159                 for (auto screen = _targets->GetFirstChild(cinema); screen.IsOk(); screen = _targets->GetNextSibling(screen)) {
160                         _targets->CheckItem(screen, wxCHK_UNCHECKED);
161                         set_screen_checked(screen, false);
162                 }
163         }
164 }
165
166
167 void
168 ScreensPanel::setup_sensitivity ()
169 {
170         bool const sc = _selected_cinemas.size() == 1;
171         bool const ss = _selected_screens.size() == 1;
172
173         _edit_cinema->Enable (sc || ss);
174         _remove_cinema->Enable (_selected_cinemas.size() >= 1);
175
176         _add_screen->Enable (sc || ss);
177         _edit_screen->Enable (ss);
178         _remove_screen->Enable (_selected_screens.size() >= 1);
179 }
180
181
182 optional<wxTreeListItem>
183 ScreensPanel::add_cinema (shared_ptr<Cinema> cinema, wxTreeListItem previous)
184 {
185         auto search = wx_to_std (_search->GetValue ());
186         transform (search.begin(), search.end(), search.begin(), ::tolower);
187
188         if (!search.empty ()) {
189                 auto name = cinema->name;
190                 transform (name.begin(), name.end(), name.begin(), ::tolower);
191                 if (name.find (search) == string::npos) {
192                         return {};
193                 }
194         }
195
196         auto id = _targets->InsertItem(_targets->GetRootItem(), previous, std_to_wx(cinema->name));
197
198         _item_to_cinema[id] = cinema;
199         _cinema_to_item[cinema] = id;
200
201         for (auto screen: cinema->screens()) {
202                 add_screen (cinema, screen);
203         }
204
205         return id;
206 }
207
208
209 optional<wxTreeListItem>
210 ScreensPanel::add_screen (shared_ptr<Cinema> cinema, shared_ptr<Screen> screen)
211 {
212         auto item = cinema_to_item(cinema);
213         if (!item) {
214                 return {};
215         }
216
217         auto id = _targets->AppendItem(*item, std_to_wx(screen->name));
218
219         _item_to_screen[id] = screen;
220         _screen_to_item[screen] = id;
221
222         return item;
223 }
224
225
226 void
227 ScreensPanel::add_cinema_clicked ()
228 {
229         auto dialog = new CinemaDialog (GetParent(), _("Add Cinema"));
230         ScopeGuard sg = [dialog]() { dialog->Destroy(); };
231
232         if (dialog->ShowModal() == wxID_OK) {
233                 auto cinema = make_shared<Cinema>(dialog->name(), dialog->emails(), dialog->notes(), dialog->utc_offset_hour(), dialog->utc_offset_minute());
234
235                 auto cinemas = Config::instance()->cinemas();
236                 cinemas.sort(
237                         [this](shared_ptr<Cinema> a, shared_ptr<Cinema> b) { return compare(a->name, b->name) < 0; }
238                         );
239
240                 try {
241                         Config::instance()->add_cinema(cinema);
242                 } catch (FileError& e) {
243                         error_dialog(GetParent(), _("Could not write cinema details to the cinemas.xml file.  Check that the location of cinemas.xml is valid in DCP-o-matic's preferences."), std_to_wx(e.what()));
244                         return;
245                 }
246
247                 optional<wxTreeListItem> item;
248                 for (auto existing_cinema: cinemas) {
249                         if (!item && compare(dialog->name(), existing_cinema->name) < 0) {
250                                 if (auto existing_item = cinema_to_item(existing_cinema)) {
251                                         item = add_cinema (cinema, *existing_item);
252                                 }
253                         }
254                 }
255
256                 if (!item) {
257                         item = add_cinema (cinema, wxTLI_LAST);
258                 }
259
260                 if (item) {
261                         _targets->UnselectAll ();
262                         _targets->Select (*item);
263                 }
264         }
265
266         selection_changed ();
267 }
268
269
270 shared_ptr<Cinema>
271 ScreensPanel::cinema_for_operation () const
272 {
273         if (_selected_cinemas.size() == 1) {
274                 return _selected_cinemas[0];
275         } else if (_selected_screens.size() == 1) {
276                 return _selected_screens[0]->cinema;
277         }
278
279         return {};
280 }
281
282
283 void
284 ScreensPanel::edit_cinema_clicked ()
285 {
286         auto cinema = cinema_for_operation ();
287         if (!cinema) {
288                 return;
289         }
290
291         auto dialog = new CinemaDialog(
292                 GetParent(), _("Edit cinema"), cinema->name, cinema->emails, cinema->notes, cinema->utc_offset_hour(), cinema->utc_offset_minute()
293                 );
294         ScopeGuard sg = [dialog]() { dialog->Destroy(); };
295
296         if (dialog->ShowModal() == wxID_OK) {
297                 cinema->name = dialog->name();
298                 cinema->emails = dialog->emails();
299                 cinema->notes = dialog->notes();
300                 cinema->set_utc_offset_hour(dialog->utc_offset_hour());
301                 cinema->set_utc_offset_minute(dialog->utc_offset_minute());
302                 notify_cinemas_changed();
303                 auto item = cinema_to_item(cinema);
304                 DCPOMATIC_ASSERT(item);
305                 _targets->SetItemText (*item, std_to_wx(dialog->name()));
306         }
307 }
308
309
310 void
311 ScreensPanel::remove_cinema_clicked ()
312 {
313         if (_selected_cinemas.size() == 1) {
314                 if (!confirm_dialog(this, wxString::Format(_("Are you sure you want to remove the cinema '%s'?"), std_to_wx(_selected_cinemas[0]->name)))) {
315                         return;
316                 }
317         } else {
318                 if (!confirm_dialog(this, wxString::Format(_("Are you sure you want to remove %d cinemas?"), int(_selected_cinemas.size())))) {
319                         return;
320                 }
321         }
322
323         for (auto const& cinema: _selected_cinemas) {
324                 Config::instance()->remove_cinema(cinema);
325                 auto item = cinema_to_item(cinema);
326                 DCPOMATIC_ASSERT(item);
327                 _targets->DeleteItem(*item);
328         }
329
330         selection_changed ();
331 }
332
333
334 void
335 ScreensPanel::add_screen_clicked ()
336 {
337         auto cinema = cinema_for_operation ();
338         if (!cinema) {
339                 return;
340         }
341
342         auto dialog = new ScreenDialog(GetParent(), _("Add Screen"));
343         ScopeGuard sg = [dialog]() { dialog->Destroy(); };
344
345         if (dialog->ShowModal () != wxID_OK) {
346                 return;
347         }
348
349         for (auto screen: cinema->screens()) {
350                 if (screen->name == dialog->name()) {
351                         error_dialog (
352                                 GetParent(),
353                                 wxString::Format (
354                                         _("You cannot add a screen called '%s' as the cinema already has a screen with this name."),
355                                         std_to_wx(dialog->name()).data()
356                                         )
357                                 );
358                         return;
359                 }
360         }
361
362         auto screen = std::make_shared<Screen>(dialog->name(), dialog->notes(), dialog->recipient(), dialog->recipient_file(), dialog->trusted_devices());
363         cinema->add_screen (screen);
364         notify_cinemas_changed();
365
366         auto id = add_screen (cinema, screen);
367         if (id) {
368                 _targets->Expand (id.get ());
369         }
370 }
371
372
373 void
374 ScreensPanel::edit_screen_clicked ()
375 {
376         if (_selected_screens.size() != 1) {
377                 return;
378         }
379
380         auto edit_screen = _selected_screens[0];
381
382         auto dialog = new ScreenDialog(
383                 GetParent(), _("Edit screen"),
384                 edit_screen->name,
385                 edit_screen->notes,
386                 edit_screen->recipient,
387                 edit_screen->recipient_file,
388                 edit_screen->trusted_devices
389                 );
390         ScopeGuard sg = [dialog]() { dialog->Destroy(); };
391
392         if (dialog->ShowModal() != wxID_OK) {
393                 return;
394         }
395
396         auto cinema = edit_screen->cinema;
397         for (auto screen: cinema->screens()) {
398                 if (screen != edit_screen && screen->name == dialog->name()) {
399                         error_dialog (
400                                 GetParent(),
401                                 wxString::Format (
402                                         _("You cannot change this screen's name to '%s' as the cinema already has a screen with this name."),
403                                         std_to_wx(dialog->name()).data()
404                                         )
405                                 );
406                         return;
407                 }
408         }
409
410         edit_screen->name = dialog->name();
411         edit_screen->notes = dialog->notes();
412         edit_screen->recipient = dialog->recipient();
413         edit_screen->recipient_file = dialog->recipient_file();
414         edit_screen->trusted_devices = dialog->trusted_devices();
415         notify_cinemas_changed();
416
417         auto item = screen_to_item(edit_screen);
418         DCPOMATIC_ASSERT (item);
419         _targets->SetItemText (*item, std_to_wx(dialog->name()));
420 }
421
422
423 void
424 ScreensPanel::remove_screen_clicked ()
425 {
426         if (_selected_screens.size() == 1) {
427                 if (!confirm_dialog(this, wxString::Format(_("Are you sure you want to remove the screen '%s'?"), std_to_wx(_selected_screens[0]->name)))) {
428                         return;
429                 }
430         } else {
431                 if (!confirm_dialog(this, wxString::Format(_("Are you sure you want to remove %d screens?"), int(_selected_screens.size())))) {
432                         return;
433                 }
434         }
435
436         for (auto const& screen: _selected_screens) {
437                 screen->cinema->remove_screen(screen);
438                 auto item = screen_to_item(screen);
439                 DCPOMATIC_ASSERT(item);
440                 _targets->DeleteItem(*item);
441         }
442
443         notify_cinemas_changed();
444 }
445
446
447 vector<shared_ptr<Screen>>
448 ScreensPanel::screens () const
449 {
450         vector<shared_ptr<Screen>> output;
451         std::copy (_checked_screens.begin(), _checked_screens.end(), std::back_inserter(output));
452         return output;
453 }
454
455
456 void
457 ScreensPanel::selection_changed_shim (wxTreeListEvent &)
458 {
459         selection_changed ();
460 }
461
462
463 void
464 ScreensPanel::selection_changed ()
465 {
466         if (_ignore_selection_change) {
467                 return;
468         }
469
470         wxTreeListItems selection;
471         _targets->GetSelections (selection);
472
473         _selected_cinemas.clear ();
474         _selected_screens.clear ();
475
476         for (size_t i = 0; i < selection.size(); ++i) {
477                 if (auto cinema = item_to_cinema(selection[i])) {
478                         _selected_cinemas.push_back(cinema);
479                 }
480                 if (auto screen = item_to_screen(selection[i])) {
481                         _selected_screens.push_back(screen);
482                 }
483         }
484
485         setup_sensitivity ();
486 }
487
488
489 void
490 ScreensPanel::add_cinemas ()
491 {
492         auto cinemas = Config::instance()->cinemas();
493         cinemas.sort(
494                 [this](shared_ptr<Cinema> a, shared_ptr<Cinema> b) { return compare(a->name, b->name) < 0; }
495                 );
496
497         for (auto cinema: cinemas) {
498                 add_cinema (cinema, wxTLI_LAST);
499         }
500 }
501
502
503 void
504 ScreensPanel::search_changed ()
505 {
506         _targets->DeleteAllItems ();
507
508         _item_to_cinema.clear ();
509         _cinema_to_item.clear ();
510         _item_to_screen.clear ();
511         _screen_to_item.clear ();
512
513         add_cinemas ();
514
515         _ignore_selection_change = true;
516
517         for (auto const& selection: _selected_cinemas) {
518                 if (auto item = cinema_to_item(selection)) {
519                         _targets->Select (*item);
520                 }
521         }
522
523         for (auto const& selection: _selected_screens) {
524                 if (auto item = screen_to_item(selection)) {
525                         _targets->Select (*item);
526                 }
527         }
528
529         _ignore_selection_change = false;
530
531         _ignore_check_change = true;
532
533         for (auto const& checked: _checked_screens) {
534                 if (auto item = screen_to_item(checked)) {
535                         _targets->CheckItem(*item, wxCHK_CHECKED);
536                         setup_cinema_checked_state(*item);
537                 }
538         }
539
540         _ignore_check_change = false;
541 }
542
543
544 void
545 ScreensPanel::set_screen_checked (wxTreeListItem item, bool checked)
546 {
547         auto screen = item_to_screen(item);
548         DCPOMATIC_ASSERT(screen);
549         if (checked) {
550                 _checked_screens.insert(screen);
551         } else {
552                 _checked_screens.erase(screen);
553         }
554 }
555
556
557 void
558 ScreensPanel::setup_cinema_checked_state (wxTreeListItem screen)
559 {
560         auto cinema = _targets->GetItemParent(screen);
561         DCPOMATIC_ASSERT (cinema.IsOk());
562         int checked = 0;
563         int unchecked = 0;
564         for (auto child = _targets->GetFirstChild(cinema); child.IsOk(); child = _targets->GetNextSibling(child)) {
565                 if (_targets->GetCheckedState(child) == wxCHK_CHECKED) {
566                     ++checked;
567                 } else {
568                     ++unchecked;
569                 }
570         }
571         if (checked == 0) {
572                 _targets->CheckItem(cinema, wxCHK_UNCHECKED);
573         } else if (unchecked == 0) {
574                 _targets->CheckItem(cinema, wxCHK_CHECKED);
575         } else {
576                 _targets->CheckItem(cinema, wxCHK_UNDETERMINED);
577         }
578 }
579
580
581 void
582 ScreensPanel::checkbox_changed (wxTreeListEvent& ev)
583 {
584         if (_ignore_check_change) {
585                 return;
586         }
587
588         if (item_to_cinema(ev.GetItem())) {
589                 /* Cinema: check/uncheck all children */
590                 auto const checked = _targets->GetCheckedState(ev.GetItem());
591                 for (auto child = _targets->GetFirstChild(ev.GetItem()); child.IsOk(); child = _targets->GetNextSibling(child)) {
592                         _targets->CheckItem(child, checked);
593                         set_screen_checked(child, checked);
594                 }
595         } else {
596                 set_screen_checked(ev.GetItem(), _targets->GetCheckedState(ev.GetItem()));
597                 setup_cinema_checked_state(ev.GetItem());
598         }
599
600         ScreensChanged ();
601 }
602
603
604 shared_ptr<Cinema>
605 ScreensPanel::item_to_cinema (wxTreeListItem item) const
606 {
607         auto iter = _item_to_cinema.find (item);
608         if (iter == _item_to_cinema.end()) {
609                 return {};
610         }
611
612         return iter->second;
613 }
614
615
616 shared_ptr<Screen>
617 ScreensPanel::item_to_screen (wxTreeListItem item) const
618 {
619         auto iter = _item_to_screen.find (item);
620         if (iter == _item_to_screen.end()) {
621                 return {};
622         }
623
624         return iter->second;
625 }
626
627
628 optional<wxTreeListItem>
629 ScreensPanel::cinema_to_item (shared_ptr<Cinema> cinema) const
630 {
631         auto iter = _cinema_to_item.find (cinema);
632         if (iter == _cinema_to_item.end()) {
633                 return {};
634         }
635
636         return iter->second;
637 }
638
639
640 optional<wxTreeListItem>
641 ScreensPanel::screen_to_item (shared_ptr<Screen> screen) const
642 {
643         auto iter = _screen_to_item.find (screen);
644         if (iter == _screen_to_item.end()) {
645                 return {};
646         }
647
648         return iter->second;
649 }
650
651
652 int
653 ScreensPanel::compare (string const& utf8_a, string const& utf8_b)
654 {
655         if (_collator) {
656                 UErrorCode error = U_ZERO_ERROR;
657                 boost::scoped_array<uint16_t> utf16_a(new uint16_t[utf8_a.size() + 1]);
658                 u_strFromUTF8(reinterpret_cast<UChar*>(utf16_a.get()), utf8_a.size() + 1, nullptr, utf8_a.c_str(), -1, &error);
659                 boost::scoped_array<uint16_t> utf16_b(new uint16_t[utf8_b.size() + 1]);
660                 u_strFromUTF8(reinterpret_cast<UChar*>(utf16_b.get()), utf8_b.size() + 1, nullptr, utf8_b.c_str(), -1, &error);
661                 return ucol_strcoll(_collator, reinterpret_cast<UChar*>(utf16_a.get()), -1, reinterpret_cast<UChar*>(utf16_b.get()), -1);
662         } else {
663                 return strcoll(utf8_a.c_str(), utf8_b.c_str());
664         }
665 }
666
667
668 bool
669 ScreensPanel::notify_cinemas_changed()
670 {
671         try {
672                 Config::instance()->changed(Config::CINEMAS);
673         } catch (FileError& e) {
674                 error_dialog(GetParent(), _("Could not write cinema details to the cinemas.xml file.  Check that the location of cinemas.xml is valid in DCP-o-matic's preferences."), std_to_wx(e.what()));
675                 return false;
676         }
677
678         return true;
679 }
680
681