2013-03-12 17:00:09 -04:00
/*
2019-08-02 17:26:43 -04:00
* Copyright ( C ) 2013 - 2014 Tim Mayberry < mojofunk @ gmail . com >
* Copyright ( C ) 2013 - 2016 Paul Davis < paul @ linuxaudiosystems . com >
* Copyright ( C ) 2013 - 2018 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 .
*/
2013-03-12 17:00:09 -04:00
# include <cstdio>
# include <cmath>
# include <sigc++/bind.h>
2017-07-16 21:48:18 -04:00
# include <gtkmm/box.h>
# include <gtkmm/filechooserdialog.h>
# include <gtkmm/stock.h>
# include <gtkmm/table.h>
2013-03-12 17:00:09 -04:00
# include "pbd/error.h"
# include "pbd/file_utils.h"
2018-11-18 21:20:11 -05:00
# include "ardour/filesystem_paths.h"
2013-03-12 17:00:09 -04:00
# include "ardour/session_directory.h"
# include "gtkmm2ext/utils.h"
# include "ardour/template_utils.h"
# include "ardour/session.h"
2013-07-21 04:49:29 -04:00
# ifdef interface
# undef interface
# endif
2013-03-12 17:00:09 -04:00
# include "video_server_dialog.h"
2013-03-28 08:41:36 -04:00
# include "utils_videotl.h"
2016-07-14 14:44:52 -04:00
# include "pbd/i18n.h"
2013-03-12 17:00:09 -04:00
2014-05-02 06:07:06 -04:00
# ifdef PLATFORM_WINDOWS
# include <windows.h>
# endif
2021-05-06 19:45:00 -04:00
# ifdef __APPLE__
extern int query_darwin_version ( ) ; // cocoacarbon.mm
# endif
2013-03-12 17:00:09 -04:00
using namespace Gtk ;
using namespace std ;
using namespace PBD ;
using namespace ARDOUR ;
2013-08-03 10:54:57 -04:00
using namespace VideoUtils ;
2013-03-12 17:00:09 -04:00
VideoServerDialog : : VideoServerDialog ( Session * s )
: ArdourDialog ( _ ( " Launch Video Server " ) )
2022-01-26 16:19:32 -05:00
, path_label ( _ ( " Server Executable: " ) , Gtk : : ALIGN_START )
2013-03-12 17:00:09 -04:00
, path_browse_button ( _ ( " Browse " ) )
2022-01-26 16:19:32 -05:00
, docroot_label ( _ ( " Server Docroot: " ) , Gtk : : ALIGN_START )
2013-03-12 17:00:09 -04:00
, docroot_browse_button ( _ ( " Browse " ) )
, listenport_adjustment ( 1554 , 1025 , 65536 , 1 , 10 , 0 )
, listenport_spinner ( listenport_adjustment )
, cachesize_adjustment ( 256 , 32 , 32768 , 1 , 32 , 0 )
, cachesize_spinner ( cachesize_adjustment )
2023-12-17 14:58:11 -05:00
, showagain_checkbox ( _ ( " Do not show this dialog again (reset in Preferences > Video). " ) )
2013-03-12 17:00:09 -04:00
{
set_session ( s ) ;
set_name ( " VideoServerDialog " ) ;
set_modal ( true ) ;
set_skip_taskbar_hint ( true ) ;
set_resizable ( false ) ;
Gtk : : Label * l ;
VBox * vbox = manage ( new VBox ) ;
VBox * options_box = manage ( new VBox ) ;
HBox * path_hbox = manage ( new HBox ) ;
HBox * docroot_hbox = manage ( new HBox ) ;
path_entry . set_width_chars ( 38 ) ;
path_entry . set_text ( " /usr/bin/harvid " ) ;
docroot_entry . set_width_chars ( 38 ) ;
2017-01-10 21:55:04 -05:00
docroot_entry . set_text ( video_get_docroot ( Config ) ) ;
2013-03-12 17:00:09 -04:00
2022-01-26 15:11:15 -05:00
listenaddr_combo . append ( " 127.0.0.1 " ) ;
listenaddr_combo . append ( " 0.0.0.0 " ) ;
2021-05-06 19:45:00 -04:00
# ifdef __APPLE__
/* Note: on OSX icsd is not able to bind to IPv4 localhost,
* except on bigsur where 0.0 .0 .0 works
*/
if ( query_darwin_version ( ) > = 20 ) {
listenaddr_combo . set_active ( 1 ) ;
} else {
listenaddr_combo . set_active ( 0 ) ;
}
# else
2013-03-12 17:00:09 -04:00
listenaddr_combo . set_active ( 0 ) ;
2021-05-06 19:45:00 -04:00
# endif
2013-03-12 17:00:09 -04:00
2014-12-23 12:28:45 -05:00
std : : string harvid_exe ;
if ( ArdourVideoToolPaths : : harvid_exe ( harvid_exe ) ) {
path_entry . set_text ( harvid_exe ) ;
} else {
2013-03-27 11:04:56 -04:00
PBD : : warning < <
2013-07-23 14:24:23 -04:00
string_compose (
2014-04-11 11:01:26 -04:00
_ ( " The external video server 'harvid' can not be found. \n "
" The tool is included with the %1 releases from ardour.org, "
" alternatively you can download it from http://x42.github.com/harvid/ "
" or acquire it from your distribution. \n "
" \n "
" see also http://manual.ardour.org/video-timeline/setup/ "
) , PROGRAM_NAME )
2013-07-23 14:24:23 -04:00
< < endmsg ;
2013-03-12 17:00:09 -04:00
}
2017-01-10 16:38:43 -05:00
# ifdef PLATFORM_WINDOWS
if ( VideoUtils : : harvid_version > = 0x000802 ) {
/* empty docroot -> all drive letters */
} else
# endif
2013-03-12 17:00:09 -04:00
if ( docroot_entry . get_text ( ) . empty ( ) ) {
std : : string docroot = Glib : : path_get_dirname ( _session - > session_directory ( ) . root_path ( ) ) ;
if ( ( docroot . empty ( ) | | docroot . at ( docroot . length ( ) - 1 ) ! = ' / ' ) ) { docroot + = " / " ; }
docroot_entry . set_text ( docroot ) ;
}
path_hbox - > pack_start ( path_label , false , false , 3 ) ;
path_hbox - > pack_start ( path_entry , true , true , 3 ) ;
path_hbox - > pack_start ( path_browse_button , false , false , 3 ) ;
docroot_hbox - > pack_start ( docroot_label , false , false , 3 ) ;
docroot_hbox - > pack_start ( docroot_entry , true , true , 3 ) ;
docroot_hbox - > pack_start ( docroot_browse_button , false , false , 3 ) ;
2022-01-26 16:19:32 -05:00
l = manage ( new Label ( _ ( " <b>Options</b> " ) , Gtk : : ALIGN_START , Gtk : : ALIGN_CENTER , false ) ) ;
2013-03-12 17:00:09 -04:00
l - > set_use_markup ( ) ;
options_box - > pack_start ( * l , false , true , 4 ) ;
Table * t = manage ( new Table ( 2 , 3 ) ) ;
t - > set_spacings ( 4 ) ;
options_box - > pack_start ( * t , true , true , 4 ) ;
l = manage ( new Label ( _ ( " Listen Address: " ) ) ) ;
l - > set_alignment ( 0 , 0.5 ) ;
t - > attach ( * l , 0 , 1 , 0 , 1 , FILL ) ;
t - > attach ( listenaddr_combo , 1 , 2 , 0 , 1 ) ;
l = manage ( new Label ( _ ( " Listen Port: " ) ) ) ;
l - > set_alignment ( 0 , 0.5 ) ;
t - > attach ( * l , 0 , 1 , 1 , 2 , FILL ) ;
t - > attach ( listenport_spinner , 1 , 2 , 1 , 2 ) ;
l = manage ( new Label ( _ ( " Cache Size: " ) ) ) ;
l - > set_alignment ( 0 , 0.5 ) ;
t - > attach ( * l , 0 , 1 , 2 , 3 , FILL ) ;
t - > attach ( cachesize_spinner , 1 , 2 , 2 , 3 ) ;
2013-07-23 14:24:23 -04:00
l = manage ( new Label ( string_compose (
2023-12-17 14:58:11 -05:00
_ ( " %1 relies on an external video server for the videotimeline. \n The server configured in Preferences -> Video is not reachable. \n Do you want %1 to launch 'harvid' on this machine? " ) , PROGRAM_NAME )
2022-01-26 16:19:32 -05:00
, Gtk : : ALIGN_START , Gtk : : ALIGN_CENTER , false ) ) ;
2013-03-28 08:41:36 -04:00
l - > set_max_width_chars ( 80 ) ;
2013-03-12 17:00:09 -04:00
l - > set_line_wrap ( ) ;
2013-03-28 08:41:36 -04:00
vbox - > pack_start ( * l , true , true , 4 ) ;
2013-03-12 17:00:09 -04:00
vbox - > pack_start ( * path_hbox , false , false ) ;
2013-03-28 08:41:36 -04:00
if ( Config - > get_video_advanced_setup ( ) ) {
vbox - > pack_start ( * docroot_hbox , false , false ) ;
} else {
listenport_spinner . set_sensitive ( false ) ;
}
2013-03-12 17:00:09 -04:00
vbox - > pack_start ( * options_box , false , true ) ;
get_vbox ( ) - > set_spacing ( 4 ) ;
get_vbox ( ) - > pack_start ( * vbox , false , false ) ;
get_vbox ( ) - > pack_start ( showagain_checkbox , false , false ) ;
2013-03-28 08:41:36 -04:00
showagain_checkbox . set_active ( ! Config - > get_show_video_server_dialog ( ) ) ;
2013-03-12 17:00:09 -04:00
path_browse_button . signal_clicked ( ) . connect ( sigc : : mem_fun ( * this , & VideoServerDialog : : open_path_dialog ) ) ;
docroot_browse_button . signal_clicked ( ) . connect ( sigc : : mem_fun ( * this , & VideoServerDialog : : open_docroot_dialog ) ) ;
show_all_children ( ) ;
add_button ( Stock : : CANCEL , RESPONSE_CANCEL ) ;
add_button ( Stock : : EXECUTE , RESPONSE_ACCEPT ) ;
}
VideoServerDialog : : ~ VideoServerDialog ( )
{
}
void
VideoServerDialog : : on_show ( )
{
Dialog : : on_show ( ) ;
}
void
VideoServerDialog : : open_path_dialog ( )
{
Gtk : : FileChooserDialog dialog ( _ ( " Set Video Server Executable " ) , Gtk : : FILE_CHOOSER_ACTION_OPEN ) ;
dialog . set_filename ( path_entry . get_text ( ) ) ;
dialog . add_button ( Gtk : : Stock : : CANCEL , Gtk : : RESPONSE_CANCEL ) ;
dialog . add_button ( Gtk : : Stock : : OK , Gtk : : RESPONSE_OK ) ;
int result = dialog . run ( ) ;
if ( result = = Gtk : : RESPONSE_OK ) {
std : : string filename = dialog . get_filename ( ) ;
if ( filename . length ( ) ) {
path_entry . set_text ( filename ) ;
}
}
}
void
VideoServerDialog : : open_docroot_dialog ( )
{
Gtk : : FileChooserDialog dialog ( _ ( " Server docroot " ) , Gtk : : FILE_CHOOSER_ACTION_SELECT_FOLDER ) ;
dialog . set_filename ( docroot_entry . get_text ( ) ) ;
dialog . add_button ( Gtk : : Stock : : CANCEL , Gtk : : RESPONSE_CANCEL ) ;
dialog . add_button ( Gtk : : Stock : : OK , Gtk : : RESPONSE_OK ) ;
int result = dialog . run ( ) ;
if ( result = = Gtk : : RESPONSE_OK ) {
std : : string dirname = dialog . get_filename ( ) ;
2013-03-28 08:41:36 -04:00
if ( dirname . empty ( ) | | dirname . at ( dirname . length ( ) - 1 ) ! = G_DIR_SEPARATOR ) {
dirname + = " / " ;
}
2013-03-12 17:00:09 -04:00
if ( dirname . length ( ) ) {
docroot_entry . set_text ( dirname ) ;
}
}
}
2013-03-28 08:41:36 -04:00
std : : string
VideoServerDialog : : get_docroot ( ) {
return docroot_entry . get_text ( ) ;
}