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