remove all of Gtk::Window::set_position (WIN_POS_MOUSE) for anything deriving from...
[ardour.git] / gtk2_ardour / add_video_dialog.cc
1 /*
2     Copyright (C) 2010-2013 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 #include <curl/curl.h>
25
26 #include "pbd/error.h"
27 #include "pbd/convert.h"
28 #include "gtkmm2ext/utils.h"
29 #include "gtkmm2ext/rgb_macros.h"
30 #include "ardour/session_directory.h"
31 #include "ardour/profile.h"
32 #include "ardour/template_utils.h"
33 #include "ardour/session.h"
34 #include "ardour_ui.h"
35
36 #include "utils.h"
37 #include "add_video_dialog.h"
38 #include "utils_videotl.h"
39 #include "i18n.h"
40
41 using namespace Gtk;
42 using namespace std;
43 using namespace PBD;
44 using namespace ARDOUR;
45
46 #define PREVIEW_WIDTH (240)
47 #define PREVIEW_HEIGHT (180)
48
49 #ifndef MIN
50 #define MIN(a,b) ( (a) < (b) ? (a) : (b) )
51 #endif
52
53 AddVideoDialog::AddVideoDialog (Session* s)
54         : ArdourDialog (_("Set Video Track"))
55         , seek_slider (0,1000,1)
56         , preview_path ("")
57         , pi_tcin ("-", Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false)
58         , pi_tcout ("-", Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false)
59         , pi_aspect ("-", Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false)
60         , pi_fps ("-", Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false)
61         , chooser (FILE_CHOOSER_ACTION_OPEN)
62         , xjadeo_checkbox (_("Launch External Video Monitor"))
63         , set_session_fps_checkbox (_("Adjust Session Framerate to Match Video Framerate"))
64         , harvid_path ("")
65         , harvid_reset (_("Reload docroot"))
66         , harvid_list (ListStore::create(harvid_list_columns))
67         , harvid_list_view (harvid_list)
68 {
69         set_session (s);
70         set_name ("AddVideoDialog");
71         set_modal (true);
72         set_skip_taskbar_hint (true);
73         set_resizable (true);
74         set_size_request (800, -1);
75
76         harvid_initialized = false;
77         std::string dstdir = video_dest_dir(_session->session_directory().video_path(), video_get_docroot(Config));
78
79         if (Config->get_video_advanced_setup()) {
80
81                 /* Harvid Browser */
82                 harvid_list_view.append_column("", pixBufRenderer);
83                 harvid_list_view.append_column(_("Filename"), harvid_list_columns.filename);
84
85                 harvid_list_view.get_column(0)->set_alignment(0.5);
86                 harvid_list_view.get_column(0)->add_attribute(pixBufRenderer, "stock-id", harvid_list_columns.id);
87                 harvid_list_view.get_column(1)->set_expand(true);
88                 harvid_list_view.get_column(1)->set_sort_column(harvid_list_columns.filename);
89                 harvid_list_view.set_enable_search(true);
90                 harvid_list_view.set_search_column(1);
91
92                 harvid_list_view.get_selection()->set_mode (SELECTION_SINGLE);
93
94                 harvid_list_view.get_selection()->signal_changed().connect(sigc::mem_fun(*this, &AddVideoDialog::harvid_list_view_selected));
95                 harvid_list_view.signal_row_activated().connect (sigc::mem_fun (*this, &AddVideoDialog::harvid_list_view_activated));
96
97                 VBox* vbox = manage (new VBox);
98                 Gtk::ScrolledWindow *scroll = manage(new ScrolledWindow);
99                 scroll->add(harvid_list_view);
100                 scroll->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
101
102                 HBox* hbox = manage (new HBox);
103                 harvid_path.set_alignment (0, 0.5);
104                 hbox->pack_start (harvid_path, true, true);
105                 hbox->pack_start (harvid_reset, false, false);
106
107                 vbox->pack_start (*hbox, false, false);
108                 vbox->pack_start (*scroll, true, true);
109
110                 notebook.append_page (*vbox, _("VideoServerIndex"));
111         } else {
112                 /* dummy entry */
113                 VBox* vbox = manage (new VBox);
114                 notebook.append_page (*vbox, _("VideoServerIndex"));
115         }
116
117         /* file chooser */
118         chooser.set_border_width (4);
119 #ifdef GTKOSX
120         /* some broken redraw behaviour - this is a bandaid */
121         chooser.signal_selection_changed().connect (mem_fun (chooser, &Widget::queue_draw));
122 #endif
123         chooser.set_current_folder (dstdir);
124
125         Gtk::FileFilter video_filter;
126         Gtk::FileFilter matchall_filter;
127         video_filter.add_custom (FILE_FILTER_FILENAME, mem_fun(*this, &AddVideoDialog::on_video_filter));
128         video_filter.set_name (_("Video files"));
129
130         matchall_filter.add_pattern ("*.*");
131         matchall_filter.set_name (_("All files"));
132
133         chooser.add_filter (video_filter);
134         chooser.add_filter (matchall_filter);
135         chooser.set_select_multiple (false);
136
137         VBox* vboxfb = manage (new VBox);
138         vboxfb->pack_start (chooser, true, true, 0);
139
140         if (video_get_docroot(Config).size() > 0 &&
141                         Config->get_video_advanced_setup()) {
142                 notebook.append_page (*vboxfb, _("Browse Files"));
143         }
144
145         /* Global Options*/
146         Gtk::Label* l;
147         VBox* options_box = manage (new VBox);
148
149         l = manage (new Label (_("<b>Options</b>"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
150         l->set_use_markup ();
151
152         options_box->pack_start (*l, false, true, 4);
153         options_box->pack_start (xjadeo_checkbox, false, true, 2);
154         options_box->pack_start (set_session_fps_checkbox, false, true, 2);
155
156         /* preview pane */
157         VBox* previewpane = manage (new VBox);
158         Gtk::Table *table = manage(new Table(5,2));
159
160         table->set_row_spacings(2);
161         table->set_col_spacings(4);
162
163         l = manage (new Label (_("<b>Video Information</b>"), Gtk::ALIGN_CENTER, Gtk::ALIGN_CENTER, false));
164         l->set_use_markup ();
165         table->attach (*l, 0, 2, 0, 1, FILL, FILL);
166         l = manage (new Label (_("Start:"), Gtk::ALIGN_RIGHT, Gtk::ALIGN_CENTER, false));
167         table->attach (*l, 0, 1, 1, 2, FILL, FILL);
168         table->attach (pi_tcin, 1, 2, 1, 2, FILL, FILL);
169         l = manage (new Label (_("End:"), Gtk::ALIGN_RIGHT, Gtk::ALIGN_CENTER, false));
170         table->attach (*l, 0, 1, 2, 3, FILL, FILL);
171         table->attach (pi_tcout, 1, 2, 2, 3, FILL, FILL);
172         l = manage (new Label (_("Frame rate:"), Gtk::ALIGN_RIGHT, Gtk::ALIGN_CENTER, false));
173         table->attach (*l, 0, 1, 3, 4, FILL, FILL);
174         table->attach (pi_fps, 1, 2, 3, 4, FILL, FILL);
175         l = manage (new Label (_("Aspect Ratio:"), Gtk::ALIGN_RIGHT, Gtk::ALIGN_CENTER, false));
176         table->attach (*l, 0, 1, 4, 5, FILL, FILL);
177         table->attach (pi_aspect, 1, 2, 4, 5, FILL, FILL);
178
179         preview_image = manage(new Gtk::Image);
180
181         imgbuf = Gdk::Pixbuf::create(Gdk::COLORSPACE_RGB, true, 8, PREVIEW_WIDTH, PREVIEW_HEIGHT);
182         imgbuf->fill(RGBA_TO_UINT(127,0,0,255));
183         preview_image->set(imgbuf);
184         seek_slider.set_draw_value(false);
185
186         HBox* hbox = manage (new HBox);
187         hbox->pack_start (*table, true, false);
188
189         Gtk::Alignment *al = manage(new Gtk::Alignment());
190         al->set_size_request(-1, 20);
191
192         previewpane->pack_start (*preview_image, false, false);
193         previewpane->pack_start (seek_slider, false, false);
194         previewpane->pack_start (*al, false, false);
195         previewpane->pack_start (*hbox, true, true, 6);
196
197         /* Overall layout */
198         hbox = manage (new HBox);
199         if (Config->get_video_advanced_setup()) {
200                 hbox->pack_start (notebook, true, true);
201         } else {
202                 hbox->pack_start (*vboxfb, true, true);
203         }
204         hbox->pack_start (*previewpane, false, false);
205
206         get_vbox()->set_spacing (4);
207         get_vbox()->pack_start (*hbox, true, true);
208         get_vbox()->pack_start (*options_box, false, false);
209
210
211         /* xjadeo checkbox */
212         if (ARDOUR_UI::instance()->video_timeline->found_xjadeo()
213                         /* TODO xjadeo setup w/ xjremote */
214                         && video_get_docroot(Config).size() > 0) {
215                 xjadeo_checkbox.set_active(true);  /* set in ardour_ui.cpp ?! */
216         } else {
217                 printf("xjadeo was not found or video-server docroot is unset (remote video-server)\n");
218                 xjadeo_checkbox.set_active(false);
219                 xjadeo_checkbox.set_sensitive(false);
220         }
221
222         /* FPS checkbox */
223         set_session_fps_checkbox.set_active(true);
224
225         /* Buttons */
226         add_button (Stock::CANCEL, RESPONSE_CANCEL);
227         ok_button = add_button (Stock::OK, RESPONSE_ACCEPT);
228         //ok_button->set_sensitive(false);
229         set_action_ok(false);
230
231         /* connect signals after eveything has been initialized */
232         chooser.signal_selection_changed().connect (mem_fun (*this, &AddVideoDialog::file_selection_changed));
233         chooser.signal_file_activated().connect (mem_fun (*this, &AddVideoDialog::file_activated));
234         //chooser.signal_update_preview().connect(sigc::mem_fun(*this, &AddVideoDialog::update_preview));
235         notebook.signal_switch_page().connect (sigc::hide_return (sigc::hide (sigc::hide (sigc::mem_fun (*this, &AddVideoDialog::page_switch)))));
236         seek_slider.signal_value_changed().connect(sigc::mem_fun(*this, &AddVideoDialog::seek_preview));
237         harvid_reset.signal_clicked().connect (sigc::mem_fun (*this, &AddVideoDialog::harvid_load_docroot));
238
239         show_all_children ();
240 }
241
242 AddVideoDialog::~AddVideoDialog ()
243 {
244 }
245
246 void
247 AddVideoDialog::on_show ()
248 {
249         Dialog::on_show ();
250 }
251
252 static bool check_video_file_extension(std::string file)
253 {
254         const char* suffixes[] = {
255                 ".avi"     , ".AVI"     ,
256                 ".mov"     , ".MOV"     ,
257                 ".ogg"     , ".OGG"     ,
258                 ".ogv"     , ".OGV"     ,
259                 ".mpg"     , ".MPG"     ,
260                 ".mov"     , ".MOV"     ,
261                 ".mp4"     , ".MP4"     ,
262                 ".mkv"     , ".MKV"     ,
263                 ".vob"     , ".VOB"     ,
264                 ".asf"     , ".ASF"     ,
265                 ".avs"     , ".AVS"     ,
266                 ".dts"     , ".DTS"     ,
267                 ".flv"     , ".FLV"     ,
268                 ".m4v"     , ".M4V"     ,
269                 ".matroska", ".MATROSKA",
270                 ".h264"    , ".H264"    ,
271                 ".dv"      , ".DV"      ,
272                 ".dirac"   , ".DIRAC"   ,
273                 ".webm"    , ".WEBM"    ,
274         };
275
276         for (size_t n = 0; n < sizeof(suffixes)/sizeof(suffixes[0]); ++n) {
277                 if (file.rfind (suffixes[n]) == file.length() - strlen (suffixes[n])) {
278                         return true;
279                 }
280         }
281
282         return false;
283 }
284
285 bool
286 AddVideoDialog::on_video_filter (const FileFilter::Info& filter_info)
287 {
288         return check_video_file_extension(filter_info.filename);
289 }
290
291 std::string
292 AddVideoDialog::file_name (bool &local_file)
293 {
294         int n = notebook.get_current_page ();
295         if (n == 1 || ! Config->get_video_advanced_setup()) {
296                 local_file = true;
297                 return chooser.get_filename();
298         } else {
299                 local_file = false;
300                 Gtk::TreeModel::iterator iter = harvid_list_view.get_selection()->get_selected();
301                 if(!iter) return "";
302
303                 std::string uri = (*iter)[harvid_list_columns.uri];
304                 std::string video_server_url = video_get_server_url(Config);
305
306                 /* check if video server is running locally */
307                 if (video_get_docroot(Config).size() > 0
308                                 && !video_server_url.compare(0, 16, "http://localhost"))
309                 {
310                         /* check if the file can be accessed */
311                         int plen;
312                         CURL *curl;
313                         curl = curl_easy_init();
314                         char *ue = curl_easy_unescape(curl, uri.c_str(), uri.length(), &plen);
315                         std::string path = video_get_docroot(Config) + ue;
316                         if (!::access(path.c_str(), R_OK)) {
317                                 uri = path;
318                                 local_file = true;
319                         }
320                         curl_easy_cleanup(curl);
321                         curl_free(ue);
322                 }
323                 return uri;
324         }
325 }
326
327 enum VtlImportOption
328 AddVideoDialog::import_option ()
329 {
330         int n = notebook.get_current_page ();
331         if (n == 0 && Config->get_video_advanced_setup()) { return VTL_IMPORT_NONE; }
332         return VTL_IMPORT_TRANSCODE;
333 }
334
335 bool
336 AddVideoDialog::launch_xjadeo ()
337 {
338         return xjadeo_checkbox.get_active();
339 }
340
341 bool
342 AddVideoDialog::auto_set_session_fps ()
343 {
344         return set_session_fps_checkbox.get_active();
345 }
346
347 void
348 AddVideoDialog::clear_preview_image ()
349 {
350         imgbuf->fill(RGBA_TO_UINT(0,0,0,255));
351         video_draw_cross(imgbuf);
352         preview_image->set(imgbuf);
353         preview_image->show();
354 }
355
356 void
357 AddVideoDialog::set_action_ok (bool yn)
358 {
359         if (yn) {
360                 ok_button->set_sensitive(true);
361         } else {
362                 preview_path = "";
363                 pi_tcin.set_text("-");
364                 pi_tcout.set_text("-");
365                 pi_aspect.set_text("-");
366                 pi_fps.set_text("-");
367                 ok_button->set_sensitive(false);
368                 clear_preview_image();
369         }
370 }
371
372 void
373 AddVideoDialog::file_selection_changed ()
374 {
375         if (chooser.get_filename().size() > 0) {
376                 std::string path = chooser.get_filename();
377                 bool ok =
378                                 check_video_file_extension(path)
379                                 &&  Glib::file_test(path.c_str(), Glib::FILE_TEST_IS_REGULAR | Glib::FILE_TEST_IS_SYMLINK)
380                                 && !Glib::file_test(path.c_str(), Glib::FILE_TEST_IS_DIR);
381                 set_action_ok(ok);
382                 if (ok) {
383                         seek_slider.set_value(0);
384                         request_preview(video_map_path(video_get_docroot(Config), path));
385                 }
386         } else {
387                 set_action_ok(false);
388         }
389 }
390
391 void
392 AddVideoDialog::file_activated ()
393 {
394         if (chooser.get_filename().size() > 0) {
395                 std::string path = chooser.get_filename();
396                 // TODO check docroot -> set import options
397                 bool ok =
398                                 check_video_file_extension(path)
399                                 &&  Glib::file_test(path.c_str(), Glib::FILE_TEST_IS_REGULAR | Glib::FILE_TEST_IS_SYMLINK)
400                                 && !Glib::file_test(path.c_str(), Glib::FILE_TEST_IS_DIR);
401                 if (ok) {
402                         Gtk::Dialog::response(RESPONSE_ACCEPT);
403                 }
404         }
405 }
406
407 /**** Tree List Interaction ***/
408
409 void
410 AddVideoDialog::harvid_list_view_selected () {
411         Gtk::TreeModel::iterator iter = harvid_list_view.get_selection()->get_selected();
412         // TODO check docroot -> set import options, xjadeo
413         if(!iter) {
414                 set_action_ok(false);
415                 return;
416         }
417         if ((std::string)((*iter)[harvid_list_columns.id]) == Stock::DIRECTORY.id) {
418                 set_action_ok(false);
419         } else {
420                 set_action_ok(true);
421                 seek_slider.set_value(0);
422                 request_preview((*iter)[harvid_list_columns.uri]);
423         }
424 }
425
426 void
427 AddVideoDialog::harvid_list_view_activated (const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn*) {
428         Gtk::TreeModel::iterator iter = harvid_list->get_iter(path);
429         if (!iter) return;
430         std::string type = (*iter)[harvid_list_columns.id];
431         std::string url = (*iter)[harvid_list_columns.uri];
432
433 #if 0
434         printf ("A: %s %s %s\n",
435                         ((std::string)((*iter)[harvid_list_columns.id])).c_str(),
436                         ((std::string)((*iter)[harvid_list_columns.uri])).c_str(),
437                         ((std::string)((*iter)[harvid_list_columns.filename])).c_str());
438 #endif
439
440         if (type == Gtk::Stock::DIRECTORY.id) {
441                 harvid_request(url.c_str());
442         } else {
443                 Gtk::Dialog::response(RESPONSE_ACCEPT);
444         }
445 }
446
447 void
448 AddVideoDialog::harvid_load_docroot() {
449         set_action_ok(false);
450
451         std::string video_server_url = video_get_server_url(Config);
452         char url[2048];
453         snprintf(url, sizeof(url), "%s%sindex/"
454                 , video_server_url.c_str()
455                 , (video_server_url.length()>0 && video_server_url.at(video_server_url.length()-1) == '/')?"":"/");
456         harvid_request(url);
457         harvid_initialized = true;
458 }
459
460 bool
461 AddVideoDialog::page_switch() {
462         if (notebook.get_current_page () == 1 || Config->get_video_advanced_setup()) {
463                 file_selection_changed();
464                 return true;
465         }
466
467         if (harvid_initialized) {
468                 harvid_list_view_selected();
469         } else {
470                 harvid_load_docroot();
471         }
472         return true;
473 }
474
475 /**** Harvid HTTP interface ***/
476 void
477 AddVideoDialog::harvid_request(std::string u)
478 {
479         char url[2048];
480         int status;
481         snprintf(url, sizeof(url), "%s?format=csv", u.c_str());
482
483         harvid_list->clear();
484
485         char *res = curl_http_get(url, &status);
486         if (status != 200) {
487                 printf("request failed\n"); // XXX
488                 harvid_path.set_text(" - request failed -");
489                 free(res);
490                 return;
491         }
492
493         /* add up-to-parent */
494         size_t se = u.find_last_of("/", u.size()-2);
495         size_t ss = u.find("/index/");
496         if (se != string::npos && ss != string::npos && se > ss) {
497                 TreeModel::iterator new_row = harvid_list->append();
498                 TreeModel::Row row = *new_row;
499                 row[harvid_list_columns.id      ] = Gtk::Stock::DIRECTORY.id;
500                 row[harvid_list_columns.uri     ] = u.substr(0, se + 1);
501                 row[harvid_list_columns.filename] = X_("..");
502         }
503         if (se != string::npos) {
504                 int plen;
505                 std::string path = u.substr(ss + 6);
506                 CURL *curl;
507                 curl = curl_easy_init();
508                 char *ue = curl_easy_unescape(curl, path.c_str(), path.length(), &plen);
509                 harvid_path.set_text(std::string(ue));
510                 curl_easy_cleanup(curl);
511                 curl_free(ue);
512         } else {
513                 harvid_path.set_text(" ??? ");
514         }
515
516         if (!res) return;
517
518         std::vector<std::vector<std::string> > lines;
519         ParseCSV(std::string(res), lines);
520         for (std::vector<std::vector<std::string> >::iterator i = lines.begin(); i != lines.end(); ++i) {
521                 TreeModel::iterator new_row = harvid_list->append();
522                 TreeModel::Row row = *new_row;
523
524                 if (i->at(0) == X_("D")) {
525                         row[harvid_list_columns.id      ] = Gtk::Stock::DIRECTORY.id;
526                         row[harvid_list_columns.uri     ] = i->at(1).c_str();
527                         row[harvid_list_columns.filename] = i->at(2).c_str();
528                 } else {
529                         row[harvid_list_columns.id      ] = Gtk::Stock::MEDIA_PLAY.id;
530                         row[harvid_list_columns.uri     ] = i->at(2).c_str();
531                         row[harvid_list_columns.filename] = i->at(3).c_str();
532                 }
533         }
534
535         free(res);
536 }
537
538 void
539 AddVideoDialog::seek_preview()
540 {
541         if (preview_path.size() > 0)
542                 request_preview(preview_path);
543 }
544
545 void
546 AddVideoDialog::request_preview(std::string u)
547 {
548         std::string video_server_url = video_get_server_url(Config);
549
550         double video_file_fps;
551         long long int video_duration;
552         double video_start_offset;
553         double video_aspect_ratio;
554
555         int clip_width = PREVIEW_WIDTH;
556         int clip_height = PREVIEW_HEIGHT;
557         int clip_xoff, clip_yoff;
558
559         if (!video_query_info(video_server_url, u,
560                         video_file_fps, video_duration, video_start_offset, video_aspect_ratio))
561         {
562                 printf("image preview info request failed\n");
563                 // set_action_ok(false); // XXX only if docroot mismatch
564                 preview_path = "";
565                 pi_tcin.set_text("-");
566                 pi_tcout.set_text("-");
567                 pi_aspect.set_text("-");
568                 pi_fps.set_text("-");
569
570                 clear_preview_image();
571                 return;
572         }
573
574         if ((PREVIEW_WIDTH / (double)PREVIEW_HEIGHT) > video_aspect_ratio ) {
575                 clip_width = MIN(PREVIEW_WIDTH, rint(clip_height * video_aspect_ratio));
576         } else {
577                 clip_height = MIN(PREVIEW_HEIGHT, rint(clip_width / video_aspect_ratio));
578         }
579
580         pi_tcin.set_text(Timecode::timecode_format_sampletime(
581                                 video_start_offset, video_file_fps, video_file_fps, rint(video_file_fps*100.0)==2997));
582         pi_tcout.set_text(Timecode::timecode_format_sampletime(
583                                 video_start_offset + video_duration, video_file_fps, video_file_fps, rint(video_file_fps*100.0)==2997));
584
585         /* todo break out this code -> re-usability */
586         const int arc = rint(video_aspect_ratio*100);
587
588         switch (arc) {
589                 case 100:
590                         pi_aspect.set_text(X_(" 1:1"));  // square (large format stills)
591                         break;
592                 case 125:
593                         pi_aspect.set_text(X_(" 5:4"));
594                         break;
595                 case 133:
596                         pi_aspect.set_text(X_(" 4:3"));
597                         break;
598                 case 134:
599                         pi_aspect.set_text(X_(" 47:35")); // 752x560, Super8-scans
600                         break;
601                 case 137:
602                 case 138:
603                         pi_aspect.set_text(X_(" 1.37:1")); // 'Academy ratio' <= 1953
604                         break;
605                 case 141:
606                         pi_aspect.set_text(X_(" 1.41:1")); //  Lichtenberg ratio
607                         break;
608                 case 150:
609                         pi_aspect.set_text(X_(" 3:2"));  // classic 35mm
610                         break;
611                 case 160:
612                         pi_aspect.set_text(X_(" 8:5"));  // credit-card size
613                         break;
614                 case 162:
615                         pi_aspect.set_text(X_(" 16:10")); // golden ratio 1.61803..
616                         break;
617                 case 166:
618                 case 167:
619                         pi_aspect.set_text(X_(" 5:3")); // Super16, EU-widescreen
620                         break;
621                 case 177:
622                 case 178:
623                         pi_aspect.set_text(X_(" 16:9")); // HD video
624                         break;
625                 case 180:
626                         pi_aspect.set_text(X_(" 9:5"));
627                         break;
628                 case 185:
629                         pi_aspect.set_text(X_(" 1.85:1")); // US widescreen cinema
630                         break;
631                 case 200:
632                         pi_aspect.set_text(X_(" 2:1"));
633                         break;
634                 case 239:
635                 case 240:
636                         pi_aspect.set_text(X_(" 2.40:1")); // Anamorphic
637                         break;
638                 case 266:
639                 case 267:
640                         pi_aspect.set_text(X_(" 2.66:1")); // CinemaScope
641                         break;
642                 case 275:
643                         pi_aspect.set_text(X_(" 2.75:1")); // Ultra Panavision
644                         break;
645                 case 400:
646                         pi_aspect.set_text(X_(" 4.00:1")); // three 35mm 1.33:1 polyvision
647                         break;
648                 default:
649                         pi_aspect.set_text(string_compose(X_(" %1:1"), video_aspect_ratio));
650                 break;
651         }
652
653         pi_fps.set_text(string_compose(_(" %1 fps"), video_file_fps));
654
655         clip_xoff = (PREVIEW_WIDTH - clip_width)/2;
656         clip_yoff = (PREVIEW_HEIGHT - clip_height)/2;
657
658         char url[2048];
659         snprintf(url, sizeof(url), "%s%s?frame=%lli&w=%d&h=%di&file=%s&format=rgb"
660                 , video_server_url.c_str()
661                 , (video_server_url.length()>0 && video_server_url.at(video_server_url.length()-1) == '/')?"":"/"
662                 , (long long) (video_duration * seek_slider.get_value() / 1000.0)
663                 , clip_width, clip_height, u.c_str());
664
665         char *data = curl_http_get(url, NULL);
666         if (!data) {
667                 printf("image preview request failed %s\n", url);
668                 imgbuf->fill(RGBA_TO_UINT(0,0,0,255));
669                 video_draw_cross(imgbuf);
670                 preview_path = "";
671         } else {
672                 Glib::RefPtr<Gdk::Pixbuf> tmp;
673                 tmp = Gdk::Pixbuf::create_from_data ((guint8*) data, Gdk::COLORSPACE_RGB, false, 8, clip_width, clip_height, clip_width*3);
674                 if (clip_width != PREVIEW_WIDTH || clip_height != PREVIEW_HEIGHT) {
675                         imgbuf->fill(RGBA_TO_UINT(0,0,0,255));
676                 }
677                 tmp->copy_area (0, 0, clip_width, clip_height, imgbuf, clip_xoff, clip_yoff);
678                 preview_path = u;
679                 free(data);
680         }
681         preview_image->set(imgbuf);
682         preview_image->show();
683 }