58bb4d5ea0d4cb601c5fd249d4e95b43214ccdab
[dcpomatic.git] / src / wx / wx_util.cc
1 /*
2     Copyright (C) 2012-2021 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 /** @file src/wx/wx_util.cc
23  *  @brief Some utility functions and classes.
24  */
25
26
27 #include "file_picker_ctrl.h"
28 #include "language_tag_widget.h"
29 #include "password_entry.h"
30 #include "region_subtag_widget.h"
31 #include "static_text.h"
32 #include "wx_ptr.h"
33 #include "wx_util.h"
34 #include "lib/config.h"
35 #include "lib/cross.h"
36 #include "lib/job.h"
37 #include "lib/job_manager.h"
38 #include "lib/util.h"
39 #include "lib/version.h"
40 #include <dcp/locale_convert.h>
41 #include <dcp/warnings.h>
42 LIBDCP_DISABLE_WARNINGS
43 #include <wx/filepicker.h>
44 #include <wx/progdlg.h>
45 #include <wx/sizer.h>
46 #include <wx/spinctrl.h>
47 #include <wx/splash.h>
48 LIBDCP_ENABLE_WARNINGS
49 #include <boost/thread.hpp>
50
51
52 using std::string;
53 using std::vector;
54 using std::pair;
55 using std::shared_ptr;
56 using boost::optional;
57 using dcp::locale_convert;
58 using namespace dcpomatic;
59
60
61 wxStaticText *
62 #ifdef __WXOSX__
63 create_label (wxWindow* p, wxString t, bool left)
64 #else
65 create_label (wxWindow* p, wxString t, bool)
66 #endif
67 {
68 #ifdef __WXOSX__
69         if (left) {
70                 t += wxT (":");
71         }
72 #endif
73         return new StaticText (p, t);
74 }
75
76
77 #ifdef __WXOSX__
78 static
79 void
80 setup_osx_flags (wxSizer* s, bool left, int& flags)
81 {
82         if (left) {
83                 auto box = dynamic_cast<wxBoxSizer*>(s);
84                 if (!box || box->GetOrientation() != wxHORIZONTAL) {
85                         flags |= wxALIGN_RIGHT;
86                 }
87         }
88 }
89 #endif
90
91
92 /** Add a wxStaticText to a wxSizer.
93  *  @param s Sizer to add to.
94  *  @param p Parent window for the wxStaticText.
95  *  @param t Text for the wxStaticText.
96  *  @param left true if this label is a `left label'; ie the sort
97  *  of label which should be right-aligned on OS X.
98  *  @param prop Proportion to pass when calling Add() on the wxSizer.
99  */
100 wxStaticText *
101 add_label_to_sizer (wxSizer* s, wxWindow* p, wxString t, bool left, int prop, int flags)
102 {
103 #ifdef __WXOSX__
104         setup_osx_flags (s, left, flags);
105 #endif
106         auto m = create_label (p, t, left);
107         s->Add (m, prop, flags, DCPOMATIC_SIZER_GAP);
108         return m;
109 }
110
111
112 wxStaticText *
113 #ifdef __WXOSX__
114 add_label_to_sizer (wxSizer* s, wxStaticText* t, bool left, int prop, int flags)
115 #else
116 add_label_to_sizer (wxSizer* s, wxStaticText* t, bool, int prop, int flags)
117 #endif
118 {
119 #ifdef __WXOSX__
120         setup_osx_flags (s, left, flags);
121 #endif
122         s->Add (t, prop, flags, DCPOMATIC_SIZER_GAP);
123         return t;
124 }
125
126
127 wxStaticText *
128 add_label_to_sizer(wxGridBagSizer* s, wxWindow* p, wxString t, bool left, wxGBPosition pos, wxGBSpan span, bool indent)
129 {
130         int flags = wxALIGN_CENTER_VERTICAL | wxLEFT;
131 #ifdef __WXOSX__
132         setup_osx_flags (s, left, flags);
133 #endif
134         auto m = create_label (p, t, left);
135         s->Add(m, pos, span, flags, indent ? DCPOMATIC_SIZER_X_GAP : 0);
136         return m;
137 }
138
139
140 wxStaticText *
141 #ifdef __WXOSX__
142 add_label_to_sizer (wxGridBagSizer* s, wxStaticText* t, bool left, wxGBPosition pos, wxGBSpan span)
143 #else
144 add_label_to_sizer (wxGridBagSizer* s, wxStaticText* t, bool, wxGBPosition pos, wxGBSpan span)
145 #endif
146 {
147         int flags = wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT;
148 #ifdef __WXOSX__
149         setup_osx_flags (s, left, flags);
150 #endif
151         s->Add (t, pos, span, flags);
152         return t;
153 }
154
155
156 /** Pop up an error dialogue box.
157  *  @param parent Parent.
158  *  @param m Message.
159  *  @param e Extended message.
160  */
161 void
162 error_dialog (wxWindow* parent, wxString m, optional<wxString> e)
163 {
164         auto d = make_wx<wxMessageDialog>(parent, m, _("DCP-o-matic"), wxOK | wxICON_ERROR);
165         if (e) {
166                 wxString em = *e;
167                 em[0] = wxToupper (em[0]);
168                 d->SetExtendedMessage (em);
169         }
170         d->ShowModal ();
171 }
172
173
174 /** Pop up an error dialogue box.
175  *  @param parent Parent.
176  *  @param m Message.
177  */
178 void
179 message_dialog (wxWindow* parent, wxString m)
180 {
181         auto d = make_wx<wxMessageDialog>(parent, m, _("DCP-o-matic"), wxOK | wxICON_INFORMATION);
182         d->ShowModal ();
183 }
184
185
186 /** @return true if the user answered "yes" */
187 bool
188 confirm_dialog (wxWindow* parent, wxString m)
189 {
190         auto d = make_wx<wxMessageDialog>(parent, m, _("DCP-o-matic"), wxYES_NO | wxICON_QUESTION);
191         return d->ShowModal() == wxID_YES;
192 }
193
194
195 /** @param s wxWidgets string.
196  *  @return Corresponding STL string.
197  */
198 string
199 wx_to_std (wxString s)
200 {
201         return string (s.ToUTF8());
202 }
203
204
205 /** @param s STL string.
206  *  @return Corresponding wxWidgets string.
207  */
208 wxString
209 std_to_wx (string s)
210 {
211         return wxString (s.c_str(), wxConvUTF8);
212 }
213
214
215 string
216 string_client_data (wxClientData* o)
217 {
218         return wx_to_std (dynamic_cast<wxStringClientData*>(o)->GetData());
219 }
220
221
222 void
223 checked_set (FilePickerCtrl* widget, boost::filesystem::path value)
224 {
225         if (widget->path() != value) {
226                 if (value.empty()) {
227                         /* Hack to make wxWidgets clear the control when we are passed
228                            an empty value.
229                         */
230                         value = " ";
231                 }
232                 widget->set_path(value);
233         }
234 }
235
236
237 void
238 checked_set (wxDirPickerCtrl* widget, boost::filesystem::path value)
239 {
240         if (widget->GetPath() != std_to_wx (value.string())) {
241                 if (value.empty()) {
242                         /* Hack to make wxWidgets clear the control when we are passed
243                            an empty value.
244                         */
245                         value = " ";
246                 }
247                 widget->SetPath (std_to_wx (value.string()));
248         }
249 }
250
251
252 void
253 checked_set (wxSpinCtrl* widget, int value)
254 {
255         if (widget->GetValue() != value) {
256                 widget->SetValue (value);
257         }
258 }
259
260
261 void
262 checked_set (wxSpinCtrlDouble* widget, double value)
263 {
264         /* XXX: completely arbitrary epsilon */
265         if (fabs (widget->GetValue() - value) > 1e-16) {
266                 widget->SetValue (value);
267         }
268 }
269
270
271 void
272 checked_set (wxChoice* widget, int value)
273 {
274         if (widget->GetSelection() != value) {
275                 widget->SetSelection (value);
276         }
277 }
278
279
280 void
281 checked_set (wxChoice* widget, string value)
282 {
283         wxClientData* o = nullptr;
284         if (widget->GetSelection() != -1) {
285                 o = widget->GetClientObject (widget->GetSelection ());
286         }
287
288         if (!o || string_client_data(o) != value) {
289                 for (unsigned int i = 0; i < widget->GetCount(); ++i) {
290                         if (string_client_data (widget->GetClientObject (i)) == value) {
291                                 widget->SetSelection (i);
292                         }
293                 }
294         }
295 }
296
297
298 void
299 checked_set (wxChoice* widget, vector<pair<string, string>> items)
300 {
301        vector<pair<string, string>> current;
302        for (unsigned int i = 0; i < widget->GetCount(); ++i) {
303                current.push_back (
304                        make_pair(
305                                wx_to_std(widget->GetString(i)),
306                                widget->GetClientData() ? string_client_data(widget->GetClientObject(i)) : ""
307                                )
308                        );
309        }
310
311        if (current == items) {
312                return;
313        }
314
315        widget->Clear ();
316        for (auto i: items) {
317                widget->Append (std_to_wx(i.first), new wxStringClientData(std_to_wx(i.second)));
318        }
319 }
320
321
322 void
323 checked_set (wxTextCtrl* widget, string value)
324 {
325         if (widget->GetValue() != std_to_wx (value)) {
326                 widget->ChangeValue (std_to_wx (value));
327         }
328 }
329
330
331 void
332 checked_set (PasswordEntry* entry, string value)
333 {
334         if (entry->get() != value) {
335                 entry->set(value);
336         }
337 }
338
339
340 void
341 checked_set (wxTextCtrl* widget, wxString value)
342 {
343         if (widget->GetValue() != value) {
344                 widget->ChangeValue (value);
345         }
346 }
347
348
349 void
350 checked_set (wxStaticText* widget, string value)
351 {
352         if (widget->GetLabel() != std_to_wx (value)) {
353                 widget->SetLabel (std_to_wx (value));
354         }
355 }
356
357
358 void
359 checked_set (wxStaticText* widget, wxString value)
360 {
361         if (widget->GetLabel() != value) {
362                 widget->SetLabel (value);
363         }
364 }
365
366
367 void
368 checked_set (wxCheckBox* widget, bool value)
369 {
370         if (widget->GetValue() != value) {
371                 widget->SetValue (value);
372         }
373 }
374
375
376 void
377 checked_set (wxRadioButton* widget, bool value)
378 {
379         if (widget->GetValue() != value) {
380                 widget->SetValue (value);
381         }
382 }
383
384
385 void
386 checked_set(LanguageTagWidget* widget, dcp::LanguageTag value)
387 {
388         if (widget->get() != value) {
389                 widget->set(value);
390         }
391 }
392
393
394 void
395 checked_set(LanguageTagWidget* widget, optional<dcp::LanguageTag> value)
396 {
397         if (widget->get() != value) {
398                 widget->set(value);
399         }
400 }
401
402
403 void
404 checked_set(RegionSubtagWidget* widget, optional<dcp::LanguageTag::RegionSubtag> value)
405 {
406         if (widget->get() != value) {
407                 widget->set(value);
408         }
409 }
410
411
412 #ifdef DCPOMATIC_OSX
413
414 void
415 dcpomatic_setup_i18n()
416 {
417         wxLog::EnableLogging();
418
419         auto get_locale_value = [](CFLocaleKey key) {
420                 CFLocaleRef cflocale = CFLocaleCopyCurrent();
421                 auto value = (CFStringRef) CFLocaleGetValue(cflocale, key);
422                 char buffer[64];
423                 CFStringGetCString(value, buffer, sizeof(buffer), kCFStringEncodingUTF8);
424                 CFRelease(cflocale);
425                 return string(buffer);
426         };
427
428         auto translations = new wxTranslations();
429
430         auto config_lang = Config::instance()->language();
431         if (config_lang && !config_lang->empty()) {
432                 translations->SetLanguage(std_to_wx(*config_lang));
433         } else {
434                 /* We want to use the user's preferred language.  It seems that if we use the wxWidgets default we will get the
435                  * language for the locale, which may not be what we want (e.g. for a machine in Germany, configured for DE locale,
436                  * but with the preferred language set to English).
437                  *
438                  * Instead, the the language code from macOS then get the corresponding canonical language string with region,
439                  * which wxTranslations::SetLanguage will accept.
440                  */
441                 auto const language_code = get_locale_value(kCFLocaleLanguageCode);
442                 /* Ideally this would be wxUILocale (as wxLocale is deprecated) but we want to keep this building
443                  * with the old wxWidgets we use for the older macOS builds.
444                  */
445                 auto const info = wxLocale::FindLanguageInfo(std_to_wx(language_code));
446                 if (info) {
447 #if wxCHECK_VERSION(3, 1, 6)
448                         translations->SetLanguage(info->GetCanonicalWithRegion());
449 #else
450                         translations->SetLanguage(info->CanonicalName);
451 #endif
452                 }
453         }
454
455 #ifdef DCPOMATIC_DEBUG
456         wxFileTranslationsLoader::AddCatalogLookupPathPrefix(wxT("build/src/wx/mo"));
457         wxFileTranslationsLoader::AddCatalogLookupPathPrefix(wxT("build/src/tools/mo"));
458 #endif
459
460         translations->AddStdCatalog();
461         translations->AddCatalog(wxT("libdcpomatic2-wx"));
462         translations->AddCatalog(wxT("dcpomatic2"));
463
464         wxTranslations::Set(translations);
465
466         dcpomatic_setup_gettext_i18n(config_lang.get_value_or(""));
467 }
468
469 #else
470
471 void
472 dcpomatic_setup_i18n ()
473 {
474         int language = wxLANGUAGE_DEFAULT;
475
476         auto config_lang = Config::instance()->language ();
477         if (config_lang && !config_lang->empty ()) {
478                 auto const li = wxLocale::FindLanguageInfo (std_to_wx (config_lang.get ()));
479                 if (li) {
480                         language = li->Language;
481                 }
482         }
483
484         wxLocale* locale = nullptr;
485         if (wxLocale::IsAvailable (language)) {
486                 locale = new wxLocale (language, wxLOCALE_LOAD_DEFAULT);
487
488 #ifdef DCPOMATIC_WINDOWS
489                 locale->AddCatalogLookupPathPrefix (std_to_wx (mo_path().string()));
490 #endif
491
492 #ifdef DCPOMATIC_LINUX
493                 locale->AddCatalogLookupPathPrefix (LINUX_LOCALE_PREFIX);
494
495                 /* We have to include the wxWidgets .mo in our distribution,
496                    so we rename it to avoid clashes with any other installation
497                    of wxWidgets.
498                 */
499                 locale->AddCatalog (wxT ("dcpomatic2-wxstd"));
500
501                 /* Fedora 29 (at least) installs wxstd3.mo instead of wxstd.mo */
502                 locale->AddCatalog (wxT ("wxstd3"));
503 #endif
504
505                 locale->AddCatalog(wxT("wxstd"));
506                 locale->AddCatalog(wxT("libdcpomatic2-wx"));
507                 locale->AddCatalog(wxT("dcpomatic2"));
508
509                 if (!locale->IsOk()) {
510                         delete locale;
511                         locale = new wxLocale (wxLANGUAGE_ENGLISH);
512                 }
513         }
514
515         if (locale) {
516                 dcpomatic_setup_gettext_i18n (wx_to_std (locale->GetCanonicalName ()));
517         }
518 }
519
520 #endif
521
522
523 int
524 wx_get (wxSpinCtrl* w)
525 {
526         return w->GetValue ();
527 }
528
529
530 int
531 wx_get (wxChoice* w)
532 {
533         return w->GetSelection ();
534 }
535
536
537 double
538 wx_get (wxSpinCtrlDouble* w)
539 {
540         return w->GetValue ();
541 }
542
543
544 /** @param s String of the form Context|String
545  *  @return translation, or String if no translation is available.
546  */
547 wxString
548 context_translation (wxString s)
549 {
550         auto t = wxGetTranslation (s);
551         if (t == s) {
552                 /* No translation; strip the context */
553                 int c = t.Find (wxT ("|"));
554                 if (c != wxNOT_FOUND) {
555                         t = t.Mid (c + 1);
556                 }
557         }
558
559         return t;
560 }
561
562
563 wxString
564 time_to_timecode (DCPTime t, double fps)
565 {
566         auto w = t.seconds ();
567         int const h = (w / 3600);
568         w -= h * 3600;
569         int const m = (w / 60);
570         w -= m * 60;
571         int const s = floor (w);
572         w -= s;
573         int const f = lrint (w * fps);
574         return wxString::Format (wxT("%02d:%02d:%02d.%02d"), h, m, s, f);
575 }
576
577
578 void
579 setup_audio_channels_choice (wxChoice* choice, int minimum)
580 {
581         vector<pair<string, string>> items;
582         for (int i = minimum; i <= 16; i += 2) {
583                 if (i == 2) {
584                         items.push_back (make_pair(wx_to_std(_("2 - stereo")), locale_convert<string>(i)));
585                 } else if (i == 4) {
586                         items.push_back (make_pair(wx_to_std(_("4 - L/C/R/Lfe")), locale_convert<string>(i)));
587                 } else if (i == 6) {
588                         items.push_back (make_pair(wx_to_std(_("6 - 5.1")), locale_convert<string>(i)));
589                 } else if (i == 8) {
590                         items.push_back (make_pair(wx_to_std(_("8 - 5.1/HI/VI")), locale_convert<string>(i)));
591                 } else if (i == 12) {
592                         items.push_back (make_pair(wx_to_std(_("12 - 7.1/HI/VI")), locale_convert<string>(i)));
593                 } else {
594                         items.push_back (make_pair(locale_convert<string> (i), locale_convert<string>(i)));
595                 }
596         }
597
598         checked_set (choice, items);
599 }
600
601
602 wxSplashScreen*
603 maybe_show_splash ()
604 {
605         wxSplashScreen* splash = nullptr;
606
607         try {
608                 wxBitmap bitmap;
609                 if (bitmap.LoadFile(bitmap_path("splash.png"), wxBITMAP_TYPE_PNG)) {
610                         {
611                                 /* This wxMemoryDC must be destroyed before bitmap can be used elsewhere */
612                                 wxMemoryDC dc(bitmap);
613                                 auto const version = wxString::Format("%s (%s)", dcpomatic_version, dcpomatic_git_commit);
614                                 auto screen_size = dc.GetSize();
615                                 auto text_size = dc.GetTextExtent(version);
616                                 dc.DrawText(version, (screen_size.GetWidth() - text_size.GetWidth()) / 2, 236);
617                         }
618 #ifdef DCPOMATIC_WINDOWS
619                         /* Having wxSTAY_ON_TOP means error dialogues hide behind the splash screen on Windows, no matter what I try */
620                         splash = new wxSplashScreen(bitmap, wxSPLASH_CENTRE_ON_SCREEN | wxSPLASH_NO_TIMEOUT, 0, nullptr, -1, wxDefaultPosition, wxDefaultSize, wxBORDER_SIMPLE | wxFRAME_NO_TASKBAR);
621 #else
622                         splash = new wxSplashScreen(bitmap, wxSPLASH_CENTRE_ON_SCREEN | wxSPLASH_NO_TIMEOUT, 0, nullptr, -1);
623 #endif
624                         wxYield ();
625                 }
626         } catch (boost::filesystem::filesystem_error& e) {
627                 /* Maybe we couldn't find the splash image; never mind */
628         }
629
630         return splash;
631 }
632
633
634 double
635 calculate_mark_interval (double mark_interval)
636 {
637         if (mark_interval > 5) {
638                 mark_interval -= lrint (mark_interval) % 5;
639         }
640         if (mark_interval > 10) {
641                 mark_interval -= lrint (mark_interval) % 10;
642         }
643         if (mark_interval > 60) {
644                 mark_interval -= lrint (mark_interval) % 60;
645         }
646         if (mark_interval > 3600) {
647                 mark_interval -= lrint (mark_interval) % 3600;
648         }
649
650         if (mark_interval < 1) {
651                 mark_interval = 1;
652         }
653
654         return mark_interval;
655 }
656
657
658 /** @return false if the task was cancelled */
659 bool
660 display_progress (wxString title, wxString task)
661 {
662         auto jm = JobManager::instance ();
663
664         wxProgressDialog progress (title, task, 100, 0, wxPD_CAN_ABORT);
665
666         bool ok = true;
667
668         while (jm->work_to_do()) {
669                 dcpomatic_sleep_seconds (1);
670                 if (!progress.Pulse()) {
671                         /* user pressed cancel */
672                         for (auto i: jm->get()) {
673                                 i->cancel();
674                         }
675                         ok = false;
676                         break;
677                 }
678         }
679
680         return ok;
681 }
682
683
684 int
685 get_offsets (vector<Offset>& offsets)
686 {
687         offsets.push_back (Offset(_("UTC-11"),  -11,  0));
688         offsets.push_back (Offset(_("UTC-10"),  -10,  0));
689         offsets.push_back (Offset(_("UTC-9"),    -9,  0));
690         offsets.push_back (Offset(_("UTC-8"),    -8,  0));
691         offsets.push_back (Offset(_("UTC-7"),    -7,  0));
692         offsets.push_back (Offset(_("UTC-6"),    -6,  0));
693         offsets.push_back (Offset(_("UTC-5"),    -5,  0));
694         offsets.push_back (Offset(_("UTC-4:30"), -4, 30));
695         offsets.push_back (Offset(_("UTC-4"),    -4,  0));
696         offsets.push_back (Offset(_("UTC-3:30"), -3, 30));
697         offsets.push_back (Offset(_("UTC-3"),    -3,  0));
698         offsets.push_back (Offset(_("UTC-2"),    -2,  0));
699         offsets.push_back (Offset(_("UTC-1"),    -1,  0));
700         int utc = offsets.size();
701         offsets.push_back (Offset(_("UTC")  ,     0,  0));
702         offsets.push_back (Offset(_("UTC+1"),     1,  0));
703         offsets.push_back (Offset(_("UTC+2"),     2,  0));
704         offsets.push_back (Offset(_("UTC+3"),     3,  0));
705         offsets.push_back (Offset(_("UTC+4"),     4,  0));
706         offsets.push_back (Offset(_("UTC+5"),     5,  0));
707         offsets.push_back (Offset(_("UTC+5:30"),  5, 30));
708         offsets.push_back (Offset(_("UTC+6"),     6,  0));
709         offsets.push_back (Offset(_("UTC+7"),     7,  0));
710         offsets.push_back (Offset(_("UTC+8"),     8,  0));
711         offsets.push_back (Offset(_("UTC+9"),     9,  0));
712         offsets.push_back (Offset(_("UTC+9:30"),  9, 30));
713         offsets.push_back (Offset(_("UTC+10"),   10,  0));
714         offsets.push_back (Offset(_("UTC+11"),   11,  0));
715         offsets.push_back (Offset(_("UTC+12"),   12,  0));
716
717         return utc;
718 }
719
720
721 wxString
722 bitmap_path (string name)
723 {
724         boost::filesystem::path base;
725
726 #ifdef DCPOMATIC_DEBUG
727         /* Hack to allow Linux and OS X to find icons when running from the source tree */
728         char* path = getenv ("DCPOMATIC_GRAPHICS");
729         if (path) {
730                 base = path;
731         } else {
732                 base = resources_path();
733         }
734
735         if (!boost::filesystem::exists(base / name)) {
736                 base = path / boost::filesystem::path("osx/preferences");
737         }
738 #else
739         base = resources_path();
740 #endif
741
742         auto p = base / name;
743         return std_to_wx (p.string());
744 }
745
746
747 wxString
748 icon_path(string name)
749 {
750         return gui_is_dark() ? bitmap_path(String::compose("%1_white.png", name)) : bitmap_path(String::compose("%1_black.png", name));
751 }
752
753
754 wxSize
755 small_button_size (wxWindow* parent, wxString text)
756 {
757         wxClientDC dc (parent);
758         auto size = dc.GetTextExtent (text);
759         size.SetHeight (-1);
760         size.IncBy (32, 0);
761         return size;
762 }
763
764
765 bool
766 gui_is_dark ()
767 {
768 #if defined(DCPOMATIC_OSX) && wxCHECK_VERSION(3, 1, 0)
769         auto appearance = wxSystemSettings::GetAppearance();
770         return appearance.IsDark();
771 #else
772         return false;
773 #endif
774 }
775
776
777 #if wxCHECK_VERSION(3,1,0)
778 double
779 dpi_scale_factor (wxWindow* window)
780 {
781         return window->GetDPIScaleFactor();
782 }
783 #else
784 double
785 dpi_scale_factor (wxWindow*)
786 {
787         return 1;
788 }
789 #endif
790
791
792
793 int
794 search_ctrl_height ()
795 {
796 #ifdef __WXGTK3__
797         return 30;
798 #else
799         return -1;
800 #endif
801 }
802
803
804 void
805 report_config_load_failure(wxWindow* parent, Config::LoadFailure what)
806 {
807         switch (what) {
808         case Config::LoadFailure::CONFIG:
809                 message_dialog(parent, _("The existing configuration failed to load.  Default values will be used instead.  These may take a short time to create."));
810                 break;
811         case Config::LoadFailure::CINEMAS:
812                 message_dialog(
813                         parent,
814                         _(wxString::Format("The cinemas list for creating KDMs (cinemas.xml) failed to load.  Please check the numbered backup files in %s",
815                                            std_to_wx(Config::instance()->cinemas_file().parent_path().string())))
816                         );
817                 break;
818         case Config::LoadFailure::DKDM_RECIPIENTS:
819                 message_dialog(
820                         parent,
821                         _(wxString::Format("The recipients list for creating DKDMs (dkdm_recipients.xml) failed to load.  Please check the numbered backup files in %s",
822                                            std_to_wx(Config::instance()->dkdm_recipients_file().parent_path().string())))
823                         );
824                 break;
825         }
826 }
827