Drop references held by any GUI Lua script after execution
[ardour.git] / gtk2_ardour / add_video_dialog.cc
index 5c58b7abcd4b71da8f98b4c44620c4e77cbe3414..8e1747d5964b3a55d17d956a4c2f98bafdf59865 100644 (file)
@@ -1,28 +1,32 @@
 /*
-    Copyright (C) 2010-2013 Paul Davis
-    Author: Robin Gareus <robin@gareus.org>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
-*/
+ * Copyright (C) 2013-2018 Paul Davis <paul@linuxaudiosystems.com>
+ * Copyright (C) 2013-2019 Robin Gareus <robin@gareus.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
 #include <cstdio>
 #include <cmath>
 
 #include <sigc++/bind.h>
 #include <curl/curl.h>
 
+#include <gtkmm/box.h>
+#include <gtkmm/filechooserdialog.h>
+#include <gtkmm/scrolledwindow.h>
+#include <gtkmm/stock.h>
+
 #include "pbd/error.h"
 #include "pbd/convert.h"
 #include "gtkmm2ext/utils.h"
 #include "ardour/session.h"
 #include "ardour_ui.h"
 
-#include "utils.h"
 #include "add_video_dialog.h"
+#include "ardour_http.h"
 #include "utils_videotl.h"
-#include "i18n.h"
+#include "pbd/i18n.h"
 
 using namespace Gtk;
 using namespace std;
@@ -60,7 +64,7 @@ AddVideoDialog::AddVideoDialog (Session* s)
        , pi_aspect ("-", Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false)
        , pi_fps ("-", Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false)
        , chooser (FILE_CHOOSER_ACTION_OPEN)
-       , xjadeo_checkbox (_("Launch External Video Monitor"))
+       , xjadeo_checkbox (_("Open Video Monitor Window"))
        , set_session_fps_checkbox (_("Adjust Session Framerate to Match Video Framerate"))
        , harvid_path ("")
        , harvid_reset (_("Reload docroot"))
@@ -109,7 +113,8 @@ AddVideoDialog::AddVideoDialog (Session* s)
 
        /* file chooser */
        chooser.set_border_width (4);
-#ifdef GTKOSX
+       Gtkmm2ext::add_volume_shortcuts (chooser);
+#ifdef __APPLE__
        /* some broken redraw behaviour - this is a bandaid */
        chooser.signal_selection_changed().connect (mem_fun (chooser, &Widget::queue_draw));
 #endif
@@ -193,8 +198,11 @@ AddVideoDialog::AddVideoDialog (Session* s)
 
        /* xjadeo checkbox */
        if (ARDOUR_UI::instance()->video_timeline->found_xjadeo()
+#ifndef PLATFORM_WINDOWS
                        /* TODO xjadeo setup w/ xjremote */
-                       && video_get_docroot(Config).size() > 0) {
+                       && video_get_docroot(Config).size() > 0
+#endif
+                ) {
                xjadeo_checkbox.set_active(true);  /* set in ardour_ui.cpp ?! */
        } else {
                printf("xjadeo was not found or video-server docroot is unset (remote video-server)\n");
@@ -270,6 +278,9 @@ static bool check_video_file_extension(std::string file)
                ".ogg"     , ".OGG"     ,
                ".ogv"     , ".OGV"     ,
                ".mpg"     , ".MPG"     ,
+               ".mpeg"    , ".MPEG"    ,
+               ".mts"     , ".MTS"     ,
+               ".m2t"     , ".M2T"     ,
                ".mov"     , ".MOV"     ,
                ".mp4"     , ".MP4"     ,
                ".mkv"     , ".MKV"     ,
@@ -284,6 +295,9 @@ static bool check_video_file_extension(std::string file)
                ".dv"      , ".DV"      ,
                ".dirac"   , ".DIRAC"   ,
                ".webm"    , ".WEBM"    ,
+               ".wmv"     , ".WMV"     ,
+               ".ts"      , ".TS"      ,
+               ".mxf"     , ".MXF"     ,
        };
 
        for (size_t n = 0; n < sizeof(suffixes)/sizeof(suffixes[0]); ++n) {
@@ -317,8 +331,15 @@ AddVideoDialog::file_name (bool &local_file)
                std::string video_server_url = video_get_server_url(Config);
 
                /* check if video server is running locally */
-               if (video_get_docroot(Config).size() > 0
-                               && !video_server_url.compare(0, 16, "http://localhost"))
+               if (
+#ifdef PLATFORM_WINDOWS
+                               (video_get_docroot(Config).size() > 0 || !show_advanced)
+#else
+                               video_get_docroot(Config).size() > 0
+#endif
+                               &&
+                               (0 == video_server_url.compare (0, 16, "http://127.0.0.1") || 0 == video_server_url.compare (0, 16, "http://localhost"))
+                  )
                {
                        /* check if the file can be accessed */
                        int plen;
@@ -327,7 +348,7 @@ AddVideoDialog::file_name (bool &local_file)
                        char *ue = curl_easy_unescape(curl, uri.c_str(), uri.length(), &plen);
 #ifdef PLATFORM_WINDOWS
                        char *tmp;
-                       while (tmp = strchr(ue, '/')) *tmp = '\\';
+                       while ((tmp = strchr(ue, '/'))) *tmp = '\\';
 #endif
                        std::string path = video_get_docroot(Config) + ue;
                        if (!::access(path.c_str(), R_OK)) {
@@ -392,8 +413,7 @@ AddVideoDialog::file_selection_changed ()
        if (chooser.get_filename().size() > 0) {
                std::string path = chooser.get_filename();
                bool ok =
-                               check_video_file_extension(path)
-                               &&  Glib::file_test(path.c_str(), Glib::FILE_TEST_IS_REGULAR | Glib::FILE_TEST_IS_SYMLINK)
+                               Glib::file_test(path.c_str(), Glib::FILE_TEST_IS_REGULAR | Glib::FILE_TEST_IS_SYMLINK)
                                && !Glib::file_test(path.c_str(), Glib::FILE_TEST_IS_DIR);
                set_action_ok(ok);
                if (ok) {
@@ -412,8 +432,7 @@ AddVideoDialog::file_activated ()
                std::string path = chooser.get_filename();
                // TODO check docroot -> set import options
                bool ok =
-                               check_video_file_extension(path)
-                               &&  Glib::file_test(path.c_str(), Glib::FILE_TEST_IS_REGULAR | Glib::FILE_TEST_IS_SYMLINK)
+                               Glib::file_test(path.c_str(), Glib::FILE_TEST_IS_REGULAR | Glib::FILE_TEST_IS_SYMLINK)
                                && !Glib::file_test(path.c_str(), Glib::FILE_TEST_IS_DIR);
                if (ok) {
                        Gtk::Dialog::response(RESPONSE_ACCEPT);
@@ -500,7 +519,7 @@ AddVideoDialog::harvid_request(std::string u)
 
        harvid_list->clear();
 
-       char *res = a3_curl_http_get(url, &status);
+       char* res = ArdourCurl::http_get (url, &status, false);
        if (status != 200) {
                printf("request failed\n"); // XXX
                harvid_path.set_text(" - request failed -");
@@ -680,7 +699,7 @@ AddVideoDialog::request_preview(std::string u)
                , (long long) (video_duration * seek_slider.get_value() / 1000.0)
                , clip_width, clip_height, u.c_str());
 
-       char *data = a3_curl_http_get(url, NULL);
+       char* data = ArdourCurl::http_get (url, NULL, false);
        if (!data) {
                printf("image preview request failed %s\n", url);
                imgbuf->fill(RGBA_TO_UINT(0,0,0,255));