2 Copyright (C) 2010 Paul Davis
3 Author: Robin Gareus <robin@gareus.org>
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.
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.
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.
23 #include <sigc++/bind.h>
25 #include "pbd/error.h"
26 #include "pbd/file_utils.h"
27 #include "ardour/session_directory.h"
28 #include "gtkmm2ext/utils.h"
29 #include "ardour/template_utils.h"
30 #include "ardour/session.h"
32 #include "video_server_dialog.h"
33 #include "utils_videotl.h"
39 using namespace ARDOUR;
41 VideoServerDialog::VideoServerDialog (Session* s)
42 : ArdourDialog (_("Launch Video Server"))
43 , path_label (_("Server Executable:"), Gtk::ALIGN_LEFT)
44 , path_browse_button (_("Browse"))
45 , docroot_label (_("Server Docroot:"), Gtk::ALIGN_LEFT)
46 , docroot_browse_button (_("Browse"))
47 , listenport_adjustment (1554, 1025, 65536, 1, 10, 0)
48 , listenport_spinner (listenport_adjustment)
49 , cachesize_adjustment (256, 32, 32768, 1, 32, 0)
50 , cachesize_spinner (cachesize_adjustment)
51 , showagain_checkbox (_("Don't show this dialog again. (Reset in Edit->Preferences)."))
55 set_name ("VideoServerDialog");
57 set_skip_taskbar_hint (true);
58 set_resizable (false);
61 VBox* vbox = manage (new VBox);
62 VBox* options_box = manage (new VBox);
63 HBox* path_hbox = manage (new HBox);
64 HBox* docroot_hbox = manage (new HBox);
66 path_entry.set_width_chars(38);
67 path_browse_button.set_name ("PaddedButton");
68 path_entry.set_text("/usr/bin/harvid");
69 docroot_entry.set_width_chars(38);
70 docroot_entry.set_text(Config->get_video_server_docroot());
71 docroot_browse_button.set_name ("PaddedButton");
73 listenaddr_combo.set_name ("PaddedButton");
75 /* Note: on OSX icsd is not able to bind to IPv4 localhost */
76 listenaddr_combo.append_text("127.0.0.1");
78 listenaddr_combo.append_text("0.0.0.0");
79 listenaddr_combo.set_active(0);
81 std::string icsd_file_path;
82 if (find_file_in_search_path (PBD::SearchPath(Glib::getenv("PATH")), X_("harvid"), icsd_file_path)) {
83 path_entry.set_text(icsd_file_path);
85 else if (Glib::file_test(X_("C:\\Program Files\\harvid\\harvid.exe"), Glib::FILE_TEST_EXISTS)) {
86 path_entry.set_text(X_("C:\\Program Files\\harvid\\harvid.exe"));
90 _("The external video server 'harvid' can not be found. The tool is included with the Ardour releases from ardour.org, "
91 "alternatively you can download it from http://x42.github.com/harvid/ or acquire it from your distribution.") << endmsg;
95 if (docroot_entry.get_text().empty()) {
96 std::string docroot = Glib::path_get_dirname(_session->session_directory().root_path());
97 if ((docroot.empty() || docroot.at(docroot.length()-1) != '/')) { docroot += "/"; }
98 docroot_entry.set_text(docroot);
101 path_hbox->pack_start (path_label, false, false, 3);
102 path_hbox->pack_start (path_entry, true, true, 3);
103 path_hbox->pack_start (path_browse_button, false, false, 3);
105 docroot_hbox->pack_start (docroot_label, false, false, 3);
106 docroot_hbox->pack_start (docroot_entry, true, true, 3);
107 docroot_hbox->pack_start (docroot_browse_button, false, false, 3);
109 l = manage (new Label (_("<b>Options</b>"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
110 l->set_use_markup ();
111 options_box->pack_start (*l, false, true, 4);
113 Table* t = manage (new Table (2, 3));
115 options_box->pack_start (*t, true, true, 4);
117 l = manage (new Label (_("Listen Address:")));
118 l->set_alignment (0, 0.5);
119 t->attach (*l, 0, 1, 0, 1, FILL);
120 t->attach (listenaddr_combo, 1, 2, 0, 1);
122 l = manage (new Label (_("Listen Port:")));
123 l->set_alignment (0, 0.5);
124 t->attach (*l, 0, 1, 1, 2, FILL);
125 t->attach (listenport_spinner, 1, 2, 1, 2);
127 l = manage (new Label (_("Cache Size:")));
128 l->set_alignment (0, 0.5);
129 t->attach (*l, 0, 1, 2, 3, FILL);
130 t->attach (cachesize_spinner, 1, 2, 2, 3);
132 l = manage (new Label (_("Ardour relies on an external Video Server for the videotimeline.\nThe server configured in Edit -> Prefereces -> Video is not reachable.\nDo you want ardour to launch 'harvid' on this machine?"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
133 l->set_max_width_chars(80);
135 vbox->pack_start (*l, true, true, 4);
136 vbox->pack_start (*path_hbox, false, false);
137 if (Config->get_video_advanced_setup()){
138 vbox->pack_start (*docroot_hbox, false, false);
140 docroot_entry.set_text(X_("/"));
141 listenport_spinner.set_sensitive(false);
143 vbox->pack_start (*options_box, false, true);
145 get_vbox()->set_spacing (4);
146 get_vbox()->pack_start (*vbox, false, false);
147 get_vbox()->pack_start (showagain_checkbox, false, false);
148 showagain_checkbox.set_active(!Config->get_show_video_server_dialog());
150 path_browse_button.signal_clicked().connect (sigc::mem_fun (*this, &VideoServerDialog::open_path_dialog));
151 docroot_browse_button.signal_clicked().connect (sigc::mem_fun (*this, &VideoServerDialog::open_docroot_dialog));
153 show_all_children ();
154 add_button (Stock::CANCEL, RESPONSE_CANCEL);
155 add_button (Stock::EXECUTE, RESPONSE_ACCEPT);
158 VideoServerDialog::~VideoServerDialog ()
163 VideoServerDialog::on_show ()
169 VideoServerDialog::open_path_dialog ()
171 Gtk::FileChooserDialog dialog(_("Set Video Server Executable"), Gtk::FILE_CHOOSER_ACTION_OPEN);
172 dialog.set_filename (path_entry.get_text());
174 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
175 dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
177 int result = dialog.run();
179 if (result == Gtk::RESPONSE_OK) {
180 std::string filename = dialog.get_filename();
182 if (filename.length()) {
183 path_entry.set_text (filename);
189 VideoServerDialog::open_docroot_dialog ()
191 Gtk::FileChooserDialog dialog(_("Server docroot"), Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
192 dialog.set_filename (docroot_entry.get_text());
194 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
195 dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
197 int result = dialog.run();
199 if (result == Gtk::RESPONSE_OK) {
200 std::string dirname = dialog.get_filename();
202 if (dirname.empty() || dirname.at(dirname.length()-1) != G_DIR_SEPARATOR) {
206 if (dirname.length()) {
207 docroot_entry.set_text (dirname);
213 VideoServerDialog::get_docroot () {
214 return docroot_entry.get_text();