fix stuff
[dcpomatic.git] / src / tools / dcpomatic.cc
index 979672fb4274e4ce110b08aad0189e993f168549..8e7c2e4539c65838313665d81a7413f34e41cc1c 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2022 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
 
 #include "wx/about_dialog.h"
 #include "wx/content_panel.h"
+#ifdef DCPOMATIC_CUCUMBER
+#include "wx/cucumber_bridge.h"
+#include "wx/cucumber_registry.h"
+#endif
 #include "wx/dkdm_dialog.h"
 #include "wx/export_subtitles_dialog.h"
 #include "wx/export_video_file_dialog.h"
@@ -104,6 +108,9 @@ LIBDCP_DISABLE_WARNINGS
 LIBDCP_ENABLE_WARNINGS
 #ifdef __WXGTK__
 #include <X11/Xlib.h>
+extern "C" {
+#include <xdo.h>
+}
 #endif
 #ifdef __WXMSW__
 #include <shellapi.h>
@@ -515,6 +522,19 @@ public:
                return _film;
        }
 
+#ifdef DCPOMATIC_CUCUMBER
+       void cucumber_add_content_file (string filename) {
+               std::cout << ".cucumber_add_content_file\n";
+               _film_editor->cucumber_add_content_file (filename);
+       }
+
+       /* Could be called from any thread */
+       std::string cucumber_get_content_list () {
+               std::cout << ".cucumber_get_content_list\n";
+               return _film_editor->cucumber_get_content_list();
+       }
+#endif
+
 private:
 
        void show (wxShowEvent& ev)
@@ -1567,6 +1587,9 @@ static const wxCmdLineEntryDesc command_line_description[] = {
        { wxCMD_LINE_OPTION, "c", "content", "add content file / directory", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
        { wxCMD_LINE_OPTION, "d", "dcp", "add content DCP", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
        { wxCMD_LINE_SWITCH, "v", "version", "show DCP-o-matic version", wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL },
+#ifdef DCPOMATIC_CUCUMBER
+       { wxCMD_LINE_SWITCH, "t", "cucumber", "enable cucumber tests", wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL },
+#endif
        { wxCMD_LINE_OPTION, "", "config", "directory containing config.xml and cinemas.xml", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
        { wxCMD_LINE_PARAM, 0, 0, "film to load or create", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
        { wxCMD_LINE_NONE, "", "", "", wxCmdLineParamType (0), 0 }
@@ -1711,6 +1734,12 @@ private:
                                notes.Centre();
                                notes.ShowModal();
                        }
+
+#ifdef DCPOMATIC_CUCUMBER
+                       if (_cucumber_bridge) {
+                               _cucumber_bridge->start();
+                       }
+#endif
                }
                catch (exception& e)
                {
@@ -1721,7 +1750,20 @@ private:
                return true;
        }
 
-       void OnInitCmdLine (wxCmdLineParser& parser) override
+       int FilterEvent(wxEvent& event) override
+       {
+               auto key = dynamic_cast<wxKeyEvent*>(&event);
+               if (key && key->GetEventType() == wxEVT_CHAR) {
+                       std::cout << "CHAR: " << key->m_keyCode << " " << key->m_uniChar << " " << key->m_rawCode << " " << key->m_rawFlags << "\n";
+               } else if (key && key->GetEventType() == wxEVT_KEY_UP) {
+                       std::cout << "KEY_UP: " << key->m_keyCode << " " << key->m_uniChar << " " << key->m_rawCode << " " << key->m_rawFlags << "\n";
+               } else if (key && key->GetEventType() == wxEVT_KEY_DOWN) {
+                       std::cout << "KEY_DOWN: " << key->m_keyCode << " " << key->m_uniChar << " " << key->m_rawCode << " " << key->m_rawFlags << "\n";
+               }
+               return -1;
+       }
+
+       void OnInitCmdLine(wxCmdLineParser& parser) override
        {
                parser.SetDesc (command_line_description);
                parser.SetSwitchChars (wxT ("-"));
@@ -1757,9 +1799,86 @@ private:
                        State::override_path = wx_to_std (config);
                }
 
+#ifdef DCPOMATIC_CUCUMBER
+               if (parser.Found(wxT("cucumber"))) {
+                       _cucumber_bridge = new CucumberBridge ();
+                       _cucumber_bridge->ClickButton.connect (bind(&App::cucumber_click_button, this, _1));
+                       _cucumber_bridge->SelectMenu.connect (bind(&App::cucumber_select_menu, this, _1));
+                       _cucumber_bridge->Type.connect (bind(&App::cucumber_type, this, _1));
+                       _cucumber_bridge->AddContentFile.connect (bind(&App::cucumber_add_content_file, this, _1));
+                       _cucumber_bridge->GetContentList.connect (bind(&App::cucumber_get_content_list, this));
+               }
+#endif
+
                return true;
        }
 
+
+#ifdef DCPOMATIC_CUCUMBER
+       void cucumber_add_content_file (string filename)
+       {
+               _frame->cucumber_add_content_file (filename);
+       }
+
+
+       std::string cucumber_get_content_list ()
+       {
+               return _frame->cucumber_get_content_list ();
+       }
+
+
+       void cucumber_click_button (string id)
+       {
+               CucumberRegistry::instance()->click_button (id);
+       }
+
+
+       void cucumber_select_menu (string id)
+       {
+               if (id == CUCUMBER_MENU_FILE_NEW) {
+                       wxPostEvent (_frame, wxMenuEvent(wxEVT_MENU, ID_file_new));
+               }
+       }
+
+
+       void cucumber_type (string text)
+       {
+#ifdef DCPOMATIC_LINUX
+               // xdo_t* xdo = xdo_new (NULL);
+               // xdo_enter_text_window (xdo, CURRENTWINDOW, text.c_str(), 200000);
+               // xdo_send_keysequence_window (xdo, CURRENTWINDOW, "Return", 200000);
+               // xdo_free (xdo);
+               auto send = [this](int code, int rawcode) {
+                       auto event = wxKeyEvent(wxEVT_KEY_DOWN);
+                       event.SetEventObject(this);
+                       event.m_keyCode = event.m_uniChar = code;
+                       event.m_rawCode = rawcode;
+                       std::cout << "process " << code << " " << rawcode << "\n";
+                       ProcessEvent (event);
+
+                       event = wxKeyEvent(wxEVT_CHAR);
+                       event.SetEventObject(this);
+                       event.m_keyCode = event.m_uniChar = code;
+                       event.m_rawCode = rawcode;
+                       std::cout << "process " << code << " " << rawcode << "\n";
+                       ProcessEvent (event);
+
+                       event = wxKeyEvent(wxEVT_KEY_UP);
+                       event.SetEventObject(this);
+                       event.m_keyCode = event.m_uniChar = code;
+                       event.m_rawCode = rawcode;
+                       std::cout << "process " << code << " " << rawcode << "\n";
+                       ProcessEvent (event);
+               };
+
+               for (auto i = 0U; i < text.length(); ++i) {
+                       send (text[i], text[i]);
+               }
+               send (WXK_RETURN, 65293);
+#endif
+       }
+#endif
+
        void report_exception ()
        {
                try {
@@ -1922,6 +2041,9 @@ private:
        string _film_to_create;
        string _content_to_add;
        string _dcp_to_add;
+#ifdef DCPOMATIC_CUCUMBER
+       CucumberBridge* _cucumber_bridge = nullptr;
+#endif
 };