prevent popup deactivation while button_down
[goodguy/history.git] / cinelerra-5.0 / cinelerra / assetedit.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2010 Adam Williams <broadcast at earthling dot net>
5  * 
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * 
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  * 
20  */
21
22 #include "asset.h"
23 #include "assetedit.h"
24 #include "awindow.h"
25 #include "awindowgui.h"
26 #include "bcprogressbox.h"
27 #include "bcsignals.h"
28 #include "bitspopup.h"
29 #include "cache.h"
30 #include "clip.h"
31 #include "cplayback.h"
32 #include "cwindow.h"
33 #include "edl.h"
34 #include "edlsession.h"
35 #include "file.h"
36 #include "filempeg.h"
37 #include "fileffmpeg.h"
38 #include "filesystem.h"
39 #include "format.inc"
40 #include "indexable.h"
41 #include "indexfile.h"
42 #include "indexstate.h"
43 #include "language.h"
44 #include "mainindexes.h"
45 #include "mwindow.h"
46 #include "mwindowgui.h"
47 #include "new.h"
48 #include "preferences.h"
49 #include "resizetrackthread.h"
50 #include "removefile.h"
51 #include "theme.h"
52 #include "transportque.h"
53
54 #include <string.h>
55
56
57
58 AssetEdit::AssetEdit(MWindow *mwindow)
59  : BC_DialogThread()
60 {
61         this->mwindow = mwindow;
62         indexable = 0;
63         window = 0;
64         changed_params = new Asset;
65         //set_synchronous(0);
66 }
67
68
69 AssetEdit::~AssetEdit()
70 {
71         close_window();
72         changed_params->remove_user();
73 }
74
75
76 void AssetEdit::edit_asset(Indexable *indexable)
77 {
78         if(this->indexable)
79         {
80                 close_window();
81         }
82
83         this->indexable = indexable;
84         this->indexable->add_user();
85
86 // Copy asset parameters into temporary storage for editing.
87         if(indexable->is_asset)
88         {
89                 changed_params->copy_from((Asset*)indexable, 0);
90         }
91         else
92         {
93                 EDL *nested_edl = (EDL*)indexable;
94
95         strcpy(changed_params->path, nested_edl->path);
96                 changed_params->sample_rate = nested_edl->session->sample_rate;
97         changed_params->channels = nested_edl->session->audio_channels;
98
99 //printf("AssetEdit::edit_asset %d %f\n", __LINE__, nested_edl->session->frame_rate);
100                 changed_params->frame_rate = nested_edl->session->frame_rate;
101         changed_params->width = nested_edl->session->output_w;
102         changed_params->height = nested_edl->session->output_h;
103         }
104
105         BC_DialogThread::start();
106 }
107
108 void AssetEdit::handle_close_event(int result)
109 {
110         if(!result)
111         {
112                 int changed = 0;
113                 Asset *asset = 0;
114                 EDL *nested_edl = 0;
115
116                 if(indexable->is_asset)
117                 {
118                         asset = (Asset*)indexable;
119                         if(!changed_params->equivalent(*asset, 1, 1))
120                                 changed = 1;
121                 }
122                 else
123                 {
124                         nested_edl = (EDL*)indexable;
125                         if(strcmp(changed_params->path, nested_edl->path) 
126 //                ||
127 //                changed_params->sample_rate != nested_edl->session->sample_rate ||
128 //                              !EQUIV(changed_params->frame_rate, nested_edl->session->frame_rate)
129                 )
130                                 changed = 1;
131                 }
132 //printf("AssetEdit::handle_close_event %d\n", __LINE__);
133
134                 if(changed)
135                 {
136                         mwindow->gui->lock_window();
137 //printf("AssetEdit::handle_close_event %d\n", __LINE__);
138
139 // Omit index status from copy since an index rebuild may have been
140 // happening when new_asset was created but not be happening anymore.
141                         if(asset)
142                         {
143                         mwindow->remove_asset_from_caches(asset);
144 //printf("AssetEdit::handle_close_event %d %f\n", __LINE__, asset->get_frame_rate());
145                                 asset->copy_from(changed_params, 0);
146 //printf("AssetEdit::handle_close_event %d %d %d\n", __LINE__, changed_params->bits, asset->bits);
147                         }
148                         else
149                         {
150                                 strcpy(nested_edl->path, changed_params->path);
151 // Other parameters can't be changed because they're defined in the other EDL
152 //                nested_edl->session->frame_rate = changed_params->frame_rate;
153 //                nested_edl->session->sample_rate = changed_params->sample_rate;
154                         }
155 //printf("AssetEdit::handle_close_event %d\n", __LINE__);
156
157                         mwindow->gui->update(0,
158                                 2,
159                                 0,
160                                 0,
161                                 0, 
162                                 0,
163                                 0);
164 //printf("AssetEdit::handle_close_event %d\n", __LINE__);
165
166 // Start index rebuilding
167                         if( (asset && asset->audio_data) || nested_edl)
168                         {
169                                 char source_filename[BCTEXTLEN];
170                                 char index_filename[BCTEXTLEN];
171                                 IndexFile::get_index_filename(source_filename, 
172                                         mwindow->preferences->index_directory,
173                                         index_filename, 
174                                         indexable->path);
175                                 remove_file(index_filename);
176                                 indexable->index_state->index_status = INDEX_NOTTESTED;
177                                 mwindow->mainindexes->add_next_asset(0, indexable);
178                                 mwindow->mainindexes->start_build();
179                         }
180                         mwindow->gui->unlock_window();
181 //printf("AssetEdit::handle_close_event %d\n", __LINE__);
182
183
184                         mwindow->awindow->gui->lock_window();
185                         mwindow->awindow->gui->update_assets();
186                         mwindow->awindow->gui->unlock_window();
187 //printf("AssetEdit::handle_close_event %d\n", __LINE__);
188
189                         mwindow->restart_brender();
190                         mwindow->sync_parameters(CHANGE_ALL);
191 //printf("AssetEdit::handle_close_event %d\n", __LINE__);
192                 }
193         }
194
195         this->indexable->remove_user();
196         this->indexable = 0;
197 //printf("AssetEdit::handle_close_event %d\n", __LINE__);
198 }
199
200 BC_Window* AssetEdit::new_gui()
201 {
202         window = new AssetEditWindow(mwindow, this);
203         window->create_objects();
204         return window;
205 }
206
207
208
209
210
211
212
213
214
215 AssetEditWindow::AssetEditWindow(MWindow *mwindow, AssetEdit *asset_edit)
216  : BC_Window(_(PROGRAM_NAME ": Asset Info"), 
217         mwindow->gui->get_abs_cursor_x(1) - 400 / 2, 
218         mwindow->gui->get_abs_cursor_y(1) - 500 / 2, 
219         400, 
220         530,
221         400,
222         530,
223         0,
224         0,
225         1)
226 {
227         this->mwindow = mwindow;
228         this->asset_edit = asset_edit;
229         bitspopup = 0;
230         path_text = 0;
231         path_button = 0;
232         hilo = 0;
233         lohi = 0;
234         allow_edits = 0;
235         detail_thread = 0;
236 }
237
238
239
240
241
242 AssetEditWindow::~AssetEditWindow()
243 {
244         lock_window("AssetEditWindow::~AssetEditWindow");
245         if(bitspopup) delete bitspopup;
246         if(detail_thread) delete detail_thread;
247         unlock_window();
248 }
249
250
251
252
253 void AssetEditWindow::create_objects()
254 {
255         int y = 10, x = 10, x1 = 10, x2 = 150;
256         char string[BCTEXTLEN];
257         int vmargin;
258         FileSystem fs;
259         BC_Title *title;
260         Asset *asset = 0;
261         EDL *nested_edl = 0;
262
263         if(asset_edit->indexable->is_asset)
264                 asset = (Asset*)asset_edit->indexable;
265         else
266                 nested_edl = (EDL*)asset_edit->indexable;
267
268         if(asset && asset->format == FILE_PCM)
269                 allow_edits = 1;
270         else
271                 allow_edits = 0;
272
273         lock_window("AssetEditWindow::create_objects");
274         if(allow_edits) 
275                 vmargin = 30;
276         else
277                 vmargin = 20;
278
279         add_subwindow(path_text = new AssetEditPathText(this, y));
280         add_subwindow(path_button = new AssetEditPath(mwindow, 
281                 this, 
282                 path_text, 
283                 y, 
284                 asset_edit->indexable->path, 
285                 _(PROGRAM_NAME ": Asset path"), _("Select a file for this asset:")));
286         y += 30;
287
288         if(asset)
289         {
290                 add_subwindow(new BC_Title(x, y, _("File format:")));
291                 x = x2;
292                 add_subwindow(new BC_Title(x, y, File::formattostr(mwindow->plugindb, 
293                                 asset->format), 
294                         MEDIUMFONT, 
295                         mwindow->theme->assetedit_color));
296                 x = x1;
297                 y += 20;
298
299                 int64_t bytes = fs.get_size(asset->path);
300                 add_subwindow(new BC_Title(x, y, _("Bytes:")));
301                 sprintf(string, "" _LD "", bytes);
302                 Units::punctuate(string);
303         
304
305                 add_subwindow(new BC_Title(x2, y, string, MEDIUMFONT, mwindow->theme->assetedit_color));
306                 if(asset->format == FILE_MPEG || asset->format == FILE_FFMPEG)
307                 {
308                         detail_thread = new DetailAssetThread(mwindow);
309                         BC_GenericButton *detail = new DetailAssetButton(this, x2+120, y);
310                         add_subwindow(detail);
311                 }
312
313                 y += 20;
314                 x = x1;
315
316                 double length = 0.;
317                 y += 20;
318                 x = x1;
319
320                 if(asset->audio_length > 0)
321                         length = (double)asset->audio_length / asset->sample_rate;
322                 if(asset->video_length > 0)
323                         length = MAX(length, (double)asset->video_length / asset->frame_rate);
324                 int64_t bitrate;
325                 if(!EQUIV(length, 0))
326                         bitrate = (int64_t)(bytes * 8 / length);
327                 else
328                         bitrate = bytes;
329                 add_subwindow(new BC_Title(x, y, _("Bitrate (bits/sec):")));
330                 sprintf(string, "" _LD "", bitrate);
331
332                 Units::punctuate(string);
333                 add_subwindow(new BC_Title(x2, y, string, MEDIUMFONT, mwindow->theme->assetedit_color));
334
335                 y += 30;
336                 x = x1;
337         }
338
339         if((asset && asset->audio_data) || nested_edl)
340         {
341                 add_subwindow(new BC_Bar(x, y, get_w() - x * 2));
342                 y += 5;
343
344                 add_subwindow(new BC_Title(x, y, _("Audio:"), LARGEFONT, RED));
345
346                 y += 30;
347
348                 if(asset)
349                 {
350                         if(asset->get_compression_text(1, 0))
351                         {
352                                 add_subwindow(new BC_Title(x, y, _("Compression:")));
353                                 x = x2;
354                                 add_subwindow(new BC_Title(x, 
355                                         y, 
356                                         asset->get_compression_text(1, 0), 
357                                         MEDIUMFONT, 
358                                         mwindow->theme->assetedit_color));
359                                 y += vmargin;
360                                 x = x1;
361                         }
362                 }
363
364                 add_subwindow(new BC_Title(x, y, _("Channels:")));
365                 sprintf(string, "%d", asset_edit->changed_params->channels);
366
367                 x = x2;
368                 if(allow_edits)
369                 {
370                         BC_TumbleTextBox *textbox = new AssetEditChannels(this, 
371                                 string, 
372                                 x, 
373                                 y);
374                         textbox->create_objects();
375                         y += vmargin;
376                 }
377                 else
378                 {
379                         add_subwindow(new BC_Title(x, y, string, MEDIUMFONT, mwindow->theme->assetedit_color));
380                         y += 20;
381                 }
382
383                 x = x1;
384                 add_subwindow(new BC_Title(x, y, _("Sample rate:")));
385                 sprintf(string, "%d", asset_edit->changed_params->sample_rate);
386
387                 x = x2;
388                 if(asset)
389                 {
390                         BC_TextBox *textbox;
391                         add_subwindow(textbox = new AssetEditRate(this, string, x, y));
392                         x += textbox->get_w();
393                         add_subwindow(new SampleRatePulldown(mwindow, textbox, x, y));
394                 }
395                 else
396                 {
397                         add_subwindow(new BC_Title(x, y, string, MEDIUMFONT, mwindow->theme->assetedit_color));
398                 }
399
400                 y += 30;
401                 x = x1;
402
403                 if(asset)
404                 {
405                         add_subwindow(new BC_Title(x, y, _("Bits:")));
406                         x = x2;
407                         if(allow_edits)
408                         {
409                                 bitspopup = new BitsPopup(this, 
410                                         x, 
411                                         y, 
412                                         &asset_edit->changed_params->bits, 
413                                         1, 
414                                         1, 
415                                         1,
416                                         0,
417                                         1);
418                                 bitspopup->create_objects();
419                         }
420                         else
421                                 add_subwindow(new BC_Title(x, y, File::bitstostr(asset->bits), MEDIUMFONT, mwindow->theme->assetedit_color));
422
423
424                         x = x1;
425                         y += vmargin;
426                         add_subwindow(new BC_Title(x, y, _("Header length:")));
427                         sprintf(string, "%d", asset->header);
428
429                         x = x2;
430                         if(allow_edits)
431                                 add_subwindow(new AssetEditHeader(this, string, x, y));
432                         else
433                                 add_subwindow(new BC_Title(x, y, string, MEDIUMFONT, mwindow->theme->assetedit_color));
434
435                         y += vmargin;
436                         x = x1;
437
438                         add_subwindow(new BC_Title(x, y, _("Byte order:")));
439
440                         if(allow_edits)
441                         {
442                                 x = x2;
443
444                                 add_subwindow(lohi = new AssetEditByteOrderLOHI(this, 
445                                         asset->byte_order, 
446                                         x, 
447                                         y));
448                                 x += 70;
449                                 add_subwindow(hilo = new AssetEditByteOrderHILO(this, 
450                                         !asset->byte_order, 
451                                         x, 
452                                         y));
453                                 y += vmargin;
454                         }
455                         else
456                         {
457                                 x = x2;
458                                 if(asset->byte_order)
459                                         add_subwindow(new BC_Title(x, y, _("Lo-Hi"), MEDIUMFONT, mwindow->theme->assetedit_color));
460                                 else
461                                         add_subwindow(new BC_Title(x, y, _("Hi-Lo"), MEDIUMFONT, mwindow->theme->assetedit_color));
462                                 y += vmargin;
463                         }
464
465
466                         x = x1;
467                         if(allow_edits)
468                         {
469         //                      add_subwindow(new BC_Title(x, y, _("Values are signed:")));
470                                 add_subwindow(new AssetEditSigned(this, asset->signed_, x, y));
471                         }
472                         else
473                         {
474                                 if(!asset->signed_ && asset->bits == 8)
475                                         add_subwindow(new BC_Title(x, y, _("Values are unsigned")));
476                                 else
477                                         add_subwindow(new BC_Title(x, y, _("Values are signed")));
478                         }
479
480                         y += 30;
481                 }
482         }
483
484         x = x1;
485         if((asset && asset->video_data) || nested_edl)
486         {
487                 add_subwindow(new BC_Bar(x, y, get_w() - x * 2));
488                 y += 5;
489
490                 add_subwindow(new BC_Title(x, y, _("Video:"), LARGEFONT, RED));
491                 y += 30;
492                 x = x1;
493
494
495                 if(asset && asset->get_compression_text(0,1))
496                 {
497                         add_subwindow(new BC_Title(x, y, _("Compression:")));
498                         x = x2;
499                         add_subwindow(new BC_Title(x, 
500                                 y, 
501                                 asset->get_compression_text(0,1), 
502                                 MEDIUMFONT, 
503                                 mwindow->theme->assetedit_color));
504                         y += vmargin;
505                         x = x1;
506                 }
507
508                 add_subwindow(new BC_Title(x, y, _("Frame rate:")));
509                 x = x2;
510                 sprintf(string, "%.2f", asset_edit->changed_params->frame_rate);
511
512 //printf("AssetEditWindow::create_objects %d %f\n", __LINE__, asset_edit->changed_params->frame_rate);
513                 if(asset)
514                 {
515                         BC_TextBox *framerate;
516                         add_subwindow(framerate = new AssetEditFRate(this, string, x, y));
517                         x += 105;
518                         add_subwindow(new FrameRatePulldown(mwindow, framerate, x, y));
519                 }
520                 else
521                 {
522                         add_subwindow(new BC_Title(x, y, string, MEDIUMFONT, mwindow->theme->assetedit_color));
523                 }
524
525                 y += 30;
526                 x = x1;
527                 add_subwindow(new BC_Title(x, y, _("Width:")));
528                 x = x2;
529                 sprintf(string, "%d", asset_edit->changed_params->width);
530                 win_width = new BC_Title(x, y, string, MEDIUMFONT, mwindow->theme->assetedit_color);
531                 add_subwindow(win_width);
532
533                 y += vmargin;
534                 x = x1;
535                 add_subwindow(new BC_Title(x, y, _("Height:")));
536                 x = x2;
537                 sprintf(string, "%d", asset_edit->changed_params->height);
538                 win_height = new BC_Title(x, y, string, MEDIUMFONT, mwindow->theme->assetedit_color);
539                 add_subwindow(win_height);
540                 y += win_height->get_h() + 5;
541
542                 if(asset && (asset->format == FILE_MPEG || asset->format == FILE_FFMPEG ) )
543                 {
544                         y += 5;
545                         x = x1;
546                         add_subwindow(new BC_Title(x, y, _("Actual width:")));
547                         x = x2;
548                         sprintf(string, "%d", asset->actual_width);
549                         add_subwindow(new BC_Title(x, y, string, MEDIUMFONT, mwindow->theme->assetedit_color));
550
551                         BC_GenericButton *resize = new ResizeAssetButton(this, x+64, y);
552                         add_subwindow(resize);
553
554                         y += vmargin;
555                         x = x1;
556                         add_subwindow(new BC_Title(x, y, _("Actual height:")));
557                         x = x2;
558                         sprintf(string, "%d", asset->actual_height);
559                         title = new BC_Title(x, y, string, MEDIUMFONT, mwindow->theme->assetedit_color);
560                         add_subwindow(title);
561                         y += title->get_h() + 5;
562                 }
563         }
564
565         add_subwindow(new BC_OKButton(this));
566         add_subwindow(new BC_CancelButton(this));
567         show_window();
568         unlock_window();
569 }
570
571 void AssetEditWindow::show_info_detail()
572 {
573         detail_thread->start((Asset*)asset_edit->indexable);
574 }
575
576
577 AssetEditChannels::AssetEditChannels(AssetEditWindow *fwindow, 
578         char *text, 
579         int x,
580         int y)
581  : BC_TumbleTextBox(fwindow, 
582                 (int)atol(text),
583                 (int)1,
584                 (int)MAXCHANNELS,
585                 x, 
586                 y, 
587                 50)
588 {
589         this->fwindow = fwindow;
590 }
591
592 int AssetEditChannels::handle_event()
593 {
594         Asset *asset = (Asset*)fwindow->asset_edit->changed_params;
595         asset->channels = atol(get_text());
596         return 1;
597 }
598
599 AssetEditRate::AssetEditRate(AssetEditWindow *fwindow, char *text, int x, int y)
600  : BC_TextBox(x, y, 100, 1, text)
601 {
602         this->fwindow = fwindow;
603 }
604
605 int AssetEditRate::handle_event()
606 {
607         Asset *asset = (Asset*)fwindow->asset_edit->changed_params;
608         asset->sample_rate = atol(get_text());
609         return 1;
610 }
611
612 AssetEditFRate::AssetEditFRate(AssetEditWindow *fwindow, char *text, int x, int y)
613  : BC_TextBox(x, y, 100, 1, text)
614 {
615         this->fwindow = fwindow;
616 }
617
618 int AssetEditFRate::handle_event()
619 {
620         Asset *asset = (Asset*)fwindow->asset_edit->changed_params;
621         asset->frame_rate = atof(get_text());
622         return 1;
623 }
624
625 AssetEditHeader::AssetEditHeader(AssetEditWindow *fwindow, char *text, int x, int y)
626  : BC_TextBox(x, y, 100, 1, text)
627 {
628         this->fwindow = fwindow;
629 }
630
631 int AssetEditHeader::handle_event()
632 {
633         Asset *asset = (Asset*)fwindow->asset_edit->changed_params;
634         asset->header = atol(get_text());
635         return 1;
636 }
637
638 AssetEditByteOrderLOHI::AssetEditByteOrderLOHI(AssetEditWindow *fwindow, 
639         int value, 
640         int x,
641         int y)
642  : BC_Radial(x, y, value, _("Lo-Hi"))
643 {
644         this->fwindow = fwindow;
645 }
646
647 int AssetEditByteOrderLOHI::handle_event()
648 {
649         Asset *asset = (Asset*)fwindow->asset_edit->changed_params;
650         asset->byte_order = 1;
651         fwindow->hilo->update(0);
652         update(1);
653         return 1;
654 }
655
656 AssetEditByteOrderHILO::AssetEditByteOrderHILO(AssetEditWindow *fwindow, 
657         int value, 
658         int x, 
659         int y)
660  : BC_Radial(x, y, value, _("Hi-Lo"))
661 {
662         this->fwindow = fwindow;
663 }
664
665 int AssetEditByteOrderHILO::handle_event()
666 {
667         Asset *asset = (Asset*)fwindow->asset_edit->changed_params;
668         asset->byte_order = 0;
669         fwindow->lohi->update(0);
670         update(1);
671         return 1;
672 }
673
674 AssetEditSigned::AssetEditSigned(AssetEditWindow *fwindow, 
675         int value, 
676         int x, 
677         int y)
678  : BC_CheckBox(x, y, value, _("Values are signed"))
679 {
680         this->fwindow = fwindow;
681 }
682
683 int AssetEditSigned::handle_event()
684 {
685         Asset *asset = (Asset*)fwindow->asset_edit->changed_params;
686         asset->signed_ = get_value();
687         return 1;
688 }
689
690
691
692
693
694
695
696 AssetEditPathText::AssetEditPathText(AssetEditWindow *fwindow, int y)
697  : BC_TextBox(5, y, 300, 1, fwindow->asset_edit->changed_params->path) 
698 {
699         this->fwindow = fwindow; 
700 }
701 AssetEditPathText::~AssetEditPathText() 
702 {
703 }
704 int AssetEditPathText::handle_event() 
705 {
706         strcpy(fwindow->asset_edit->changed_params->path, get_text());
707         return 1;
708 }
709
710 AssetEditPath::AssetEditPath(MWindow *mwindow, 
711         AssetEditWindow *fwindow, 
712         BC_TextBox *textbox, 
713         int y, 
714         const char *text, 
715         const char *window_title, 
716         const char *window_caption)
717  : BrowseButton(mwindow, 
718         fwindow, 
719         textbox, 
720         310, 
721         y, 
722         text, 
723         window_title, 
724         window_caption, 
725         0) 
726
727         this->fwindow = fwindow; 
728 }
729 AssetEditPath::~AssetEditPath() {}
730
731
732
733
734
735
736 AssetEditFormat::AssetEditFormat(AssetEditWindow *fwindow, char* default_, int y)
737  : FormatPopup(fwindow->mwindow->plugindb, 90, y)
738
739         this->fwindow = fwindow; 
740 }
741 AssetEditFormat::~AssetEditFormat() 
742 {
743 }
744 int AssetEditFormat::handle_event()
745 {
746         Asset *asset = (Asset*)fwindow->asset_edit->changed_params;
747         asset->format = File::strtoformat(fwindow->mwindow->plugindb, 
748                 get_selection(0, 0)->get_text());
749         return 1;
750 }
751
752
753
754
755 DetailAssetButton::DetailAssetButton(AssetEditWindow *fwindow, int x, int y)
756  : BC_GenericButton(x, y, _("Detail"))
757 {
758         this->fwindow = fwindow;
759         set_underline(0);
760 }
761
762 DetailAssetButton::~DetailAssetButton()
763 {
764 }
765
766 int DetailAssetButton::handle_event()
767 {
768         fwindow->show_info_detail();
769         return 1;
770 }
771
772 DetailAssetWindow::DetailAssetWindow(MWindow *mwindow, Asset *asset)
773  : BC_Window(_("Asset Detail"),
774         mwindow->gui->get_abs_cursor_x(1) - 600/2,
775         mwindow->gui->get_abs_cursor_y(1) - 500/2,
776         600, 500)
777 {
778         this->mwindow = mwindow;
779         this->asset = asset;
780         asset->add_user();
781         info[0] = 0;
782         text = 0;
783 }
784
785 DetailAssetWindow::~DetailAssetWindow()
786 {
787         asset->remove_user();
788         delete text;
789 }
790
791 DetailAssetThread::DetailAssetThread(MWindow *mwindow)
792  : Thread(1, 0, 0)
793 {
794         this->mwindow = mwindow;
795         dwindow = 0;
796 }
797
798 DetailAssetThread::~DetailAssetThread()
799 {
800         stop();
801 }
802
803 void DetailAssetThread::stop()
804 {
805         if( Thread::running() ) {
806                 dwindow->lock_window("DetailAssetThread::stop");
807                 dwindow->set_done(1);
808                 dwindow->unlock_window();
809                 Thread::join();
810         }
811 }
812
813 void DetailAssetWindow::create_objects()
814 {
815         int y = 10, x = 10;
816         char file_name[BCTEXTLEN];
817         int len = sizeof(info);
818         strncpy(info,_("no info available"),len);
819         if( !mwindow->preferences->get_asset_file_path(asset, file_name) ) {
820                 switch( asset->format ) {
821                 case FILE_MPEG:
822                         FileMPEG::get_info(asset->path, file_name, &info[0],len);
823                         break;
824                 case FILE_FFMPEG:
825                         FileFFMPEG::get_info(asset->path, &info[0],len);
826                         break;
827                 }
828         }
829         lock_window("DetailAssetThread::create_objects");
830         text = new BC_ScrollTextBox(this, x, y, get_w()-32, 23, info, -len);
831         text->create_objects();  text->set_text_row(0);
832         add_subwindow(new BC_OKButton(this));
833         show_window();
834         unlock_window();
835 }
836
837 void DetailAssetThread::start(Asset *asset)
838 {
839         stop();
840         delete dwindow;
841         dwindow = new DetailAssetWindow(mwindow, asset);
842         Thread::start();
843 }
844
845 void DetailAssetThread::run()
846 {
847 // Get length from TOC
848         dwindow->create_objects();
849         dwindow->run_window();
850         delete dwindow;
851         dwindow = 0;
852 }
853
854