Move 'show in file manager' code to cross_*
authorCarl Hetherington <cth@carlh.net>
Thu, 17 Jun 2021 21:21:54 +0000 (23:21 +0200)
committerCarl Hetherington <cth@carlh.net>
Tue, 21 Sep 2021 07:46:32 +0000 (09:46 +0200)
src/lib/cross.h
src/lib/cross_linux.cc
src/lib/cross_osx.cc
src/lib/cross_windows.cc
src/tools/dcpomatic.cc

index 25b3b38200c601b12f1ebd1f5b842c0e83b14482..91911330577d3a1991b6bcc4e1699f0095ab3927 100644 (file)
@@ -67,6 +67,7 @@ extern void unprivileged ();
 extern boost::filesystem::path config_path ();
 extern boost::filesystem::path directory_containing_executable ();
 extern boost::filesystem::path fix_long_path (boost::filesystem::path path);
+extern bool show_in_file_manager (boost::filesystem::path dir, boost::filesystem::path select);
 namespace dcpomatic {
        std::string get_process_id ();
 }
index 65151791cc820dc4f83ab1317e9418a59ac39aa0..d142c416f7cbb296fd3facdfca37b0700fff3176 100644 (file)
@@ -411,3 +411,22 @@ fix_long_path (boost::filesystem::path path)
        return path;
 }
 
+
+bool
+show_in_file_manager (boost::filesystem::path dir, boost::filesystem::path)
+{
+       int r = system ("which nautilus");
+       if (WEXITSTATUS(r) == 0) {
+               r = system (String::compose("nautilus \"%1\"", dir.string()).c_str());
+               return static_cast<bool>(WEXITSTATUS(r));
+       } else {
+               int r = system ("which konqueror");
+               if (WEXITSTATUS(r) == 0) {
+                       r = system (String::compose("konqueror \"%1\"", dir.string()).c_str());
+                       return static_cast<bool>(WEXITSTATUS(r));
+               }
+       }
+
+       return true;
+}
+
index b9b7796a21a73c71e2fb59ac972134fd4ed3439f..d0cb9f216980846307f70c84745e98a38f5a18be 100644 (file)
@@ -638,3 +638,12 @@ fix_long_path (boost::filesystem::path path)
 {
        return path;
 }
+
+
+bool
+show_in_file_manager (boost::filesystem::path, boost::filesystem::path select)
+{
+       int r = system (String::compose("open -R \"%1\"", select.string()).c_str());
+       return static_cast<bool>(WEXITSTATUS(r));
+}
+
index ac92aa7eb730b8364673b8b8725b862453b7975f..f778a60e15088d932d85cb33a2ed9620c09d91f0 100644 (file)
@@ -694,3 +694,13 @@ dcpomatic::get_process_id ()
        return dcp::raw_convert<string>(GetCurrentProcessId());
 }
 
+
+bool
+show_in_file_manager (boost::filesystem::path, boost::filesystem::path select)
+{
+       std::wstringstream args;
+       args << "/select," << select;
+       auto const r = ShellExecute (0, L"open", L"explorer.exe", args.str().c_str(), 0, SW_SHOWDEFAULT);
+       return (reinterpret_cast<int64_t>(r) <= 32);
+}
+
index ea3dc9a41a81c2c287313aaf722b2280dc8882a3..ca45963f440a90b52cf0dd4b4c330501436a2b99 100644 (file)
@@ -58,6 +58,7 @@
 #include "lib/analytics.h"
 #include "lib/emailer.h"
 #include "lib/config.h"
+#include "lib/cross.h"
 #include "lib/util.h"
 #include "lib/video_content.h"
 #include "lib/content.h"
@@ -127,8 +128,6 @@ using std::shared_ptr;
 using std::string;
 using std::vector;
 using std::wcout;
-using std::wstring;
-using std::wstringstream;
 using boost::optional;
 using boost::is_any_of;
 using boost::algorithm::find;
@@ -1027,36 +1026,9 @@ private:
        void jobs_show_dcp ()
        {
                DCPOMATIC_ASSERT (_film->directory ());
-#ifdef DCPOMATIC_WINDOWS
-               wstringstream args;
-               args << "/select," << _film->dir (_film->dcp_name(false));
-               ShellExecute (0, L"open", L"explorer.exe", args.str().c_str(), 0, SW_SHOWDEFAULT);
-#endif
-
-#ifdef DCPOMATIC_LINUX
-               int r = system ("which nautilus");
-               if (WEXITSTATUS (r) == 0) {
-                       r = system (String::compose("nautilus \"%1\"", _film->directory()->string()).c_str());
-                       if (WEXITSTATUS (r)) {
-                               error_dialog (this, _("Could not show DCP."), _("Could not run nautilus"));
-                       }
-               } else {
-                       int r = system ("which konqueror");
-                       if (WEXITSTATUS (r) == 0) {
-                               r = system (String::compose ("konqueror \"%1\"", _film->directory()->string()).c_str());
-                               if (WEXITSTATUS (r)) {
-                                       error_dialog (this, _("Could not show DCP"), _("Could not run konqueror"));
-                               }
-                       }
+               if (show_in_file_manager(_film->directory().get(), _film->dir(_film->dcp_name(false)))) {
+                       error_dialog (this, _("Could not show DCP."));
                }
-#endif
-
-#ifdef DCPOMATIC_OSX
-               int r = system (String::compose ("open -R \"%1\"", _film->dir (_film->dcp_name(false)).string()).c_str());
-               if (WEXITSTATUS (r)) {
-                       error_dialog (this, _("Could not show DCP"));
-               }
-#endif
        }
 
        void view_closed_captions ()