ardour
video_server_dialog.cc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 Paul Davis
3  Author: Robin Gareus <robin@gareus.org>
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 
19 */
20 #include <cstdio>
21 #include <cmath>
22 
23 #include <sigc++/bind.h>
24 
25 #include "pbd/error.h"
26 #include "pbd/file_utils.h"
28 #include "gtkmm2ext/utils.h"
29 #include "ardour/template_utils.h"
30 #include "ardour/session.h"
31 
32 #ifdef interface
33 #undef interface
34 #endif
35 
36 #include "video_server_dialog.h"
37 #include "utils_videotl.h"
38 #include "video_tool_paths.h"
39 #include "i18n.h"
40 
41 #ifdef PLATFORM_WINDOWS
42 #include <windows.h>
43 #endif
44 
45 using namespace Gtk;
46 using namespace std;
47 using namespace PBD;
48 using namespace ARDOUR;
49 using namespace VideoUtils;
50 
52  : ArdourDialog (_("Launch Video Server"))
53  , path_label (_("Server Executable:"), Gtk::ALIGN_LEFT)
54  , path_browse_button (_("Browse"))
55  , docroot_label (_("Server Docroot:"), Gtk::ALIGN_LEFT)
56  , docroot_browse_button (_("Browse"))
57  , listenport_adjustment (1554, 1025, 65536, 1, 10, 0)
58  , listenport_spinner (listenport_adjustment)
59  , cachesize_adjustment (256, 32, 32768, 1, 32, 0)
60  , cachesize_spinner (cachesize_adjustment)
61  , showagain_checkbox (_("Don't show this dialog again. (Reset in Edit->Preferences)."))
62 {
63  set_session (s);
64 
65  set_name ("VideoServerDialog");
66  set_modal (true);
67  set_skip_taskbar_hint (true);
68  set_resizable (false);
69 
70  Gtk::Label* l;
71  VBox* vbox = manage (new VBox);
72  VBox* options_box = manage (new VBox);
73  HBox* path_hbox = manage (new HBox);
74  HBox* docroot_hbox = manage (new HBox);
75 
76  path_entry.set_width_chars(38);
77  path_browse_button.set_name ("PaddedButton");
78  path_entry.set_text("/usr/bin/harvid");
79  docroot_entry.set_width_chars(38);
80  docroot_entry.set_text(Config->get_video_server_docroot());
81  docroot_browse_button.set_name ("PaddedButton");
82 
83  listenaddr_combo.set_name ("PaddedButton");
84 #ifndef __APPLE__
85  /* Note: on OSX icsd is not able to bind to IPv4 localhost */
86  listenaddr_combo.append_text("127.0.0.1");
87 #endif
88  listenaddr_combo.append_text("0.0.0.0");
89  listenaddr_combo.set_active(0);
90 
91  std::string harvid_exe;
92  if (ArdourVideoToolPaths::harvid_exe(harvid_exe)) {
93  path_entry.set_text(harvid_exe);
94  } else {
95  PBD::warning <<
97  _("The external video server 'harvid' can not be found.\n"
98  "The tool is included with the %1 releases from ardour.org, "
99  "alternatively you can download it from http://x42.github.com/harvid/ "
100  "or acquire it from your distribution.\n"
101  "\n"
102  "see also http://manual.ardour.org/video-timeline/setup/"
103  ), PROGRAM_NAME)
104  << endmsg;
105  }
106 
107  if (docroot_entry.get_text().empty()) {
108  std::string docroot = Glib::path_get_dirname(_session->session_directory().root_path());
109  if ((docroot.empty() || docroot.at(docroot.length()-1) != '/')) { docroot += "/"; }
110  docroot_entry.set_text(docroot);
111  }
112 
113  path_hbox->pack_start (path_label, false, false, 3);
114  path_hbox->pack_start (path_entry, true, true, 3);
115  path_hbox->pack_start (path_browse_button, false, false, 3);
116 
117  docroot_hbox->pack_start (docroot_label, false, false, 3);
118  docroot_hbox->pack_start (docroot_entry, true, true, 3);
119  docroot_hbox->pack_start (docroot_browse_button, false, false, 3);
120 
121  l = manage (new Label (_("<b>Options</b>"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
122  l->set_use_markup ();
123  options_box->pack_start (*l, false, true, 4);
124 
125  Table* t = manage (new Table (2, 3));
126  t->set_spacings (4);
127  options_box->pack_start (*t, true, true, 4);
128 
129  l = manage (new Label (_("Listen Address:")));
130  l->set_alignment (0, 0.5);
131  t->attach (*l, 0, 1, 0, 1, FILL);
132  t->attach (listenaddr_combo, 1, 2, 0, 1);
133 
134  l = manage (new Label (_("Listen Port:")));
135  l->set_alignment (0, 0.5);
136  t->attach (*l, 0, 1, 1, 2, FILL);
137  t->attach (listenport_spinner, 1, 2, 1, 2);
138 
139  l = manage (new Label (_("Cache Size:")));
140  l->set_alignment (0, 0.5);
141  t->attach (*l, 0, 1, 2, 3, FILL);
142  t->attach (cachesize_spinner, 1, 2, 2, 3);
143 
144  l = manage (new Label (string_compose(
145  _("%1 relies on an external video server for the videotimeline.\nThe server configured in Edit -> Preferences -> Video is not reachable.\nDo you want %1 to launch 'harvid' on this machine?"), PROGRAM_NAME)
146  , Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
147  l->set_max_width_chars(80);
148  l->set_line_wrap();
149  vbox->pack_start (*l, true, true, 4);
150  vbox->pack_start (*path_hbox, false, false);
151  if (Config->get_video_advanced_setup()){
152  vbox->pack_start (*docroot_hbox, false, false);
153  } else {
154 #ifndef PLATFORM_WINDOWS
155  docroot_entry.set_text(X_("/"));
156 #else
157  docroot_entry.set_text(X_("C:\\"));
158 #endif
159  listenport_spinner.set_sensitive(false);
160  }
161  vbox->pack_start (*options_box, false, true);
162 
163  get_vbox()->set_spacing (4);
164  get_vbox()->pack_start (*vbox, false, false);
165  get_vbox()->pack_start (showagain_checkbox, false, false);
166  showagain_checkbox.set_active(!Config->get_show_video_server_dialog());
167 
168  path_browse_button.signal_clicked().connect (sigc::mem_fun (*this, &VideoServerDialog::open_path_dialog));
169  docroot_browse_button.signal_clicked().connect (sigc::mem_fun (*this, &VideoServerDialog::open_docroot_dialog));
170 
171  show_all_children ();
172  add_button (Stock::CANCEL, RESPONSE_CANCEL);
173  add_button (Stock::EXECUTE, RESPONSE_ACCEPT);
174 }
175 
177 {
178 }
179 
180 void
182 {
183  Dialog::on_show ();
184 }
185 
186 void
188 {
189  Gtk::FileChooserDialog dialog(_("Set Video Server Executable"), Gtk::FILE_CHOOSER_ACTION_OPEN);
190  dialog.set_filename (path_entry.get_text());
191 
192  dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
193  dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
194 
195  int result = dialog.run();
196 
197  if (result == Gtk::RESPONSE_OK) {
198  std::string filename = dialog.get_filename();
199 
200  if (filename.length()) {
201  path_entry.set_text (filename);
202  }
203  }
204 }
205 
206 void
208 {
209  Gtk::FileChooserDialog dialog(_("Server docroot"), Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
210  dialog.set_filename (docroot_entry.get_text());
211 
212  dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
213  dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
214 
215  int result = dialog.run();
216 
217  if (result == Gtk::RESPONSE_OK) {
218  std::string dirname = dialog.get_filename();
219 
220  if (dirname.empty() || dirname.at(dirname.length()-1) != G_DIR_SEPARATOR) {
221  dirname += "/";
222  }
223 
224  if (dirname.length()) {
225  docroot_entry.set_text (dirname);
226  }
227  }
228 }
229 
230 std::string
232  return docroot_entry.get_text();
233 }
const std::string root_path() const
bool harvid_exe(std::string &harvid_exe)
Gtk::Button path_browse_button
Definition: ardour_ui.h:130
Gtk::SpinButton cachesize_spinner
Definition: Beats.hpp:239
LIBPBD_API Transmitter warning
std::ostream & endmsg(std::ostream &ostr)
Definition: transmitter.h:71
#define _(Text)
Definition: i18n.h:11
#define X_(Text)
Definition: i18n.h:13
LIBARDOUR_API RCConfiguration * Config
Definition: globals.cc:119
Gtk::SpinButton listenport_spinner
Definition: amp.h:29
Gtk::CheckButton showagain_checkbox
common functions used for video-file im/export
VideoServerDialog(ARDOUR::Session *)
Gtk::ComboBoxText listenaddr_combo
Definition: debug.h:30
virtual void set_session(ARDOUR::Session *)
const SessionDirectory & session_directory() const
Definition: session.h:182
ARDOUR::Session * _session
std::string string_compose(const std::string &fmt, const T1 &o1)
Definition: compose.h:208
Gtk::Button docroot_browse_button