vtl: open video dialog - aspect ratios
[ardour.git] / gtk2_ardour / video_server_dialog.cc
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 #ifdef WITH_VIDEOTIMELINE
21
22 #include <cstdio>
23 #include <cmath>
24
25 #include <sigc++/bind.h>
26
27 #include "pbd/error.h"
28 #include "pbd/file_utils.h"
29 #include "ardour/session_directory.h"
30 #include "gtkmm2ext/utils.h"
31 #include "ardour/template_utils.h"
32 #include "ardour/session.h"
33
34 #include "video_server_dialog.h"
35 #include "utils_videotl.h"
36 #include "i18n.h"
37
38 using namespace Gtk;
39 using namespace std;
40 using namespace PBD;
41 using namespace ARDOUR;
42
43 VideoServerDialog::VideoServerDialog (Session* s)
44         : ArdourDialog (_("Launch Video Server"))
45         , path_label (_("Server Executable:"), Gtk::ALIGN_LEFT)
46         , path_browse_button (_("Browse"))
47         , docroot_label (_("Server Docroot:"), Gtk::ALIGN_LEFT)
48         , docroot_browse_button (_("Browse"))
49         , listenport_adjustment (1554, 1025, 65536, 1, 10, 0)
50         , listenport_spinner (listenport_adjustment)
51         , cachesize_adjustment (256, 32, 32768, 1, 32, 0)
52         , cachesize_spinner (cachesize_adjustment)
53         , showagain_checkbox (_("Don't show this dialog again. (Reset in Edit->Preferences)."))
54 {
55         set_session (s);
56
57         set_name ("VideoServerDialog");
58         set_position (Gtk::WIN_POS_MOUSE);
59         set_modal (true);
60         set_skip_taskbar_hint (true);
61         set_resizable (false);
62
63         Gtk::Label* l;
64         VBox* vbox = manage (new VBox);
65         VBox* options_box = manage (new VBox);
66         HBox* path_hbox = manage (new HBox);
67         HBox* docroot_hbox = manage (new HBox);
68
69         path_entry.set_width_chars(38);
70         path_browse_button.set_name ("PaddedButton");
71         path_entry.set_text("/usr/bin/harvid");
72         docroot_entry.set_width_chars(38);
73         docroot_entry.set_text(Config->get_video_server_docroot());
74         docroot_browse_button.set_name ("PaddedButton");
75
76         listenaddr_combo.set_name ("PaddedButton");
77 #ifndef __APPLE__
78         /* Note: on OSX icsd is not able to bind to IPv4 localhost */
79         listenaddr_combo.append_text("127.0.0.1");
80 #endif
81         listenaddr_combo.append_text("0.0.0.0");
82         listenaddr_combo.set_active(0);
83
84         std::string icsd_file_path;
85         if (find_file_in_search_path (PBD::SearchPath(Glib::getenv("PATH")), X_("harvid"), icsd_file_path)) {
86                 path_entry.set_text(icsd_file_path);
87         }
88         else if (Glib::file_test(X_("C:\\Program Files\\harvid\\harvid.exe"), Glib::FILE_TEST_EXISTS)) {
89                 path_entry.set_text(X_("C:\\Program Files\\harvid\\harvid.exe"));
90         }
91         else {
92                 PBD::warning <<
93                         _("The external video server 'harvid' can not be found. The tool is included with the Ardour releases from ardour.org, "
94                           "alternatively you can download it from http://x42.github.com/harvid/ or acquire it from your distribution.") << endmsg;
95         }
96
97
98         if (docroot_entry.get_text().empty()) {
99           std::string docroot =  Glib::path_get_dirname(_session->session_directory().root_path());
100           if ((docroot.empty() || docroot.at(docroot.length()-1) != '/')) { docroot += "/"; }
101                 docroot_entry.set_text(docroot);
102         }
103
104         path_hbox->pack_start (path_label, false, false, 3);
105         path_hbox->pack_start (path_entry, true, true, 3);
106         path_hbox->pack_start (path_browse_button, false, false, 3);
107
108         docroot_hbox->pack_start (docroot_label, false, false, 3);
109         docroot_hbox->pack_start (docroot_entry, true, true, 3);
110         docroot_hbox->pack_start (docroot_browse_button, false, false, 3);
111
112         l = manage (new Label (_("<b>Options</b>"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
113         l->set_use_markup ();
114         options_box->pack_start (*l, false, true, 4);
115
116         Table* t = manage (new Table (2, 3));
117         t->set_spacings (4);
118         options_box->pack_start (*t, true, true, 4);
119
120         l = manage (new Label (_("Listen Address:")));
121         l->set_alignment (0, 0.5);
122         t->attach (*l, 0, 1, 0, 1, FILL);
123         t->attach (listenaddr_combo, 1, 2, 0, 1);
124
125         l = manage (new Label (_("Listen Port:")));
126         l->set_alignment (0, 0.5);
127         t->attach (*l, 0, 1, 1, 2, FILL);
128         t->attach (listenport_spinner, 1, 2, 1, 2);
129
130         l = manage (new Label (_("Cache Size:")));
131         l->set_alignment (0, 0.5);
132         t->attach (*l, 0, 1, 2, 3, FILL);
133         t->attach (cachesize_spinner, 1, 2, 2, 3);
134
135         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));
136         l->set_max_width_chars(80);
137         l->set_line_wrap();
138         vbox->pack_start (*l, true, true, 4);
139         vbox->pack_start (*path_hbox, false, false);
140         if (Config->get_video_advanced_setup()){
141                 vbox->pack_start (*docroot_hbox, false, false);
142         } else {
143                 docroot_entry.set_text(X_("/"));
144                 listenport_spinner.set_sensitive(false);
145         }
146         vbox->pack_start (*options_box, false, true);
147
148         get_vbox()->set_spacing (4);
149         get_vbox()->pack_start (*vbox, false, false);
150         get_vbox()->pack_start (showagain_checkbox, false, false);
151         showagain_checkbox.set_active(!Config->get_show_video_server_dialog());
152
153         path_browse_button.signal_clicked().connect (sigc::mem_fun (*this, &VideoServerDialog::open_path_dialog));
154         docroot_browse_button.signal_clicked().connect (sigc::mem_fun (*this, &VideoServerDialog::open_docroot_dialog));
155
156         show_all_children ();
157         add_button (Stock::CANCEL, RESPONSE_CANCEL);
158         add_button (Stock::EXECUTE, RESPONSE_ACCEPT);
159 }
160
161 VideoServerDialog::~VideoServerDialog ()
162 {
163 }
164
165 void
166 VideoServerDialog::on_show ()
167 {
168         Dialog::on_show ();
169 }
170
171 void
172 VideoServerDialog::open_path_dialog ()
173 {
174         Gtk::FileChooserDialog dialog(_("Set Video Server Executable"), Gtk::FILE_CHOOSER_ACTION_OPEN);
175         dialog.set_filename (path_entry.get_text());
176
177         dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
178         dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
179
180         int result = dialog.run();
181
182         if (result == Gtk::RESPONSE_OK) {
183                 std::string filename = dialog.get_filename();
184
185                 if (filename.length()) {
186                         path_entry.set_text (filename);
187                 }
188         }
189 }
190
191 void
192 VideoServerDialog::open_docroot_dialog ()
193 {
194         Gtk::FileChooserDialog dialog(_("Server docroot"), Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
195         dialog.set_filename (docroot_entry.get_text());
196
197         dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
198         dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
199
200         int result = dialog.run();
201
202         if (result == Gtk::RESPONSE_OK) {
203                 std::string dirname = dialog.get_filename();
204
205                 if (dirname.empty() || dirname.at(dirname.length()-1) != G_DIR_SEPARATOR) {
206                         dirname += "/";
207                 }
208
209                 if (dirname.length()) {
210                         docroot_entry.set_text (dirname);
211                 }
212         }
213 }
214
215 std::string
216 VideoServerDialog::get_docroot () {
217         return docroot_entry.get_text();
218 }
219
220 #endif /* WITH_VIDEOTIMELINE */