fullscreen segv fix, popup for 4opts preview, renderfarm print fix, pan widget upgrad...
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / awindowgui.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 1997-2012 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 "arender.h"
23 #include "asset.h"
24 #include "assetedit.h"
25 #include "assetpopup.h"
26 #include "assetremove.h"
27 #include "assets.h"
28 #include "audiodevice.h"
29 #include "awindow.h"
30 #include "awindowgui.h"
31 #include "bccmodels.h"
32 #include "bcsignals.h"
33 #include "bchash.h"
34 #include "binfolder.h"
35 #include "cache.h"
36 #include "cstrdup.h"
37 #include "clip.h"
38 #include "clipedls.h"
39 #include "clippopup.h"
40 #include "cursors.h"
41 #include "cwindowgui.h"
42 #include "cwindow.h"
43 #include "edits.h"
44 #include "edit.h"
45 #include "edl.h"
46 #include "edlsession.h"
47 #include "effectlist.h"
48 #include "file.h"
49 #include "filesystem.h"
50 #include "folderlistmenu.h"
51 #include "indexable.h"
52 #include "keys.h"
53 #include "language.h"
54 #include "labels.h"
55 #include "labelpopup.h"
56 #include "localsession.h"
57 #include "mainerror.h"
58 #include "mainmenu.h"
59 #include "mainsession.h"
60 #include "mwindowgui.h"
61 #include "mwindow.h"
62 #include "preferences.h"
63 #include "proxy.h"
64 #include "proxypopup.h"
65 #include "renderengine.h"
66 #include "samples.h"
67 #include "theme.h"
68 #include "tracks.h"
69 #include "track.h"
70 #include "transportque.h"
71 #include "vframe.h"
72 #include "vicon.h"
73 #include "vrender.h"
74 #include "vwindowgui.h"
75 #include "vwindow.h"
76
77 #include "data/lad_picon_png.h"
78 #include "data/ff_audio_png.h"
79 #include "data/ff_video_png.h"
80
81 #include<stdio.h>
82 #include<unistd.h>
83 #include<fcntl.h>
84
85
86 const char *AWindowGUI::folder_names[] =
87 {
88         N_("Audio Effects"),
89         N_("Video Effects"),
90         N_("Audio Transitions"),
91         N_("Video Transitions"),
92         N_("Labels"),
93         N_("Clips"),
94         N_("Media"),
95         N_("Proxy"),
96 };
97
98 const char *AVIconDrawing::avicon_names[] =
99 {
100         N_("Full Play"),
101         N_("Mouse Over"),
102         N_("Src Target"),
103         N_("No Play"),
104 };
105
106 AssetVIcon::AssetVIcon(AssetPicon *picon, int w, int h, double framerate, int64_t length)
107  : VIcon(w, h, framerate), Garbage("AssetVIcon")
108 {
109         this->picon = picon;
110         this->length = length;
111         temp = 0;
112 }
113
114 AssetVIcon::~AssetVIcon()
115 {
116         picon->gui->vicon_thread->del_vicon(this);
117         delete temp;
118 }
119
120 VFrame *AssetVIcon::frame()
121 {
122         AssetVIconThread *avt = picon->gui->vicon_thread;
123         Asset *asset = (Asset *)picon->indexable;
124         if( !asset )
125                 return *images[0];
126         if( !asset->video_data && audio_data && audio_size && length > 0 ) {
127                 if( !temp ) temp = new VFrame(0, -1, w, h, BC_RGB888, -1);
128                 temp->clear_frame();
129                 int sample_rate = asset->get_sample_rate();
130                 int64_t audio_samples = asset->get_audio_samples();
131                 double duration = (double)audio_samples / sample_rate;
132                 picon->draw_hue_bar(temp, duration);
133                 int secs = length / frame_rate + 0.5;
134                 if( !secs ) secs = 1;
135                 int bfrsz = VICON_SAMPLE_RATE;
136                 int samples = audio_size/sizeof(vicon_audio_t);
137                 double line_pos = (double)seq_no/(length-1);
138                 int audio_pos = samples * line_pos * (secs-1)/secs;
139                 vicon_audio_t *audio_data = ((vicon_audio_t *)this->audio_data) + audio_pos;
140                 static const int mx = (1<<(8*sizeof(*audio_data)-1)) - 1;
141                 double data[bfrsz], sample_scale = 1./mx;
142                 int len = samples - audio_pos;
143                 if( len > bfrsz ) len = bfrsz;
144                 int i = 0;
145                 while( i < len ) data[i++] = *audio_data++ * sample_scale;
146                 while( i < bfrsz ) data[i++] = 0;
147                 picon->draw_wave(temp, data, bfrsz, RED, GREEN);
148                 int x = (w-1) * line_pos;
149                 temp->pixel_rgb = RED;
150                 temp->draw_line(x,0, x,h);
151                 return temp;
152         }
153         int vw = avt->vw, vh = avt->vh, vicon_cmodel = avt->vicon_cmodel;
154         if( !asset->video_data ) {
155                 if( !temp ) {
156                         temp = new VFrame(0, -1, vw, vh, BC_RGB888, -1);
157                         temp->clear_frame();
158                 }
159                 return temp;
160         }
161         if( seq_no >= images.size() ) {
162                 MWindow *mwindow = picon->mwindow;
163                 File *file = mwindow->video_cache->check_out(asset, mwindow->edl, 1);
164                 if( !file ) return 0;
165                 if( temp && (temp->get_w() != asset->width || temp->get_h() != asset->height) ) {
166                         delete temp;  temp = 0;
167                 }
168                 if( !temp )
169                         temp = new VFrame(0, -1, asset->width, asset->height, BC_RGB888, -1);
170                 while( seq_no >= images.size() ) {
171                         mwindow->video_cache->check_in(asset);
172                         Thread::yield();
173                         file = mwindow->video_cache->check_out(asset, mwindow->edl, 0);
174                         if( !file ) { usleep(1000);  continue; }
175                         file->set_layer(0);
176                         int64_t pos = images.size() / picon->gui->vicon_thread->refresh_rate * frame_rate;
177                         file->set_video_position(pos,0);
178                         if( file->read_frame(temp) ) temp->clear_frame();
179                         add_image(temp, vw, vh, vicon_cmodel);
180                 }
181                 mwindow->video_cache->check_in(asset);
182         }
183         return *images[seq_no];
184 }
185
186 int64_t AssetVIcon::set_seq_no(int64_t no)
187 {
188         if( no >= length ) no = 0;
189         return seq_no = no;
190 }
191
192 int AssetVIcon::get_vx()
193 {
194         BC_ListBox *lbox = picon->gui->asset_list;
195         return lbox->get_icon_x(picon);
196 }
197 int AssetVIcon::get_vy()
198 {
199         BC_ListBox *lbox = picon->gui->asset_list;
200         return lbox->get_icon_y(picon);
201 }
202
203 void AssetVIcon::load_audio()
204 {
205         MWindow *mwindow = picon->mwindow;
206         Asset *asset = (Asset *)picon->indexable;
207         File *file = mwindow->audio_cache->check_out(asset, mwindow->edl, 1);
208         int channels = asset->get_audio_channels();
209         if( channels > 2 ) channels = 2;
210         int sample_rate = asset->get_sample_rate();
211         int bfrsz = sample_rate;
212         Samples samples(bfrsz);
213         double time_scale = (double)sample_rate / VICON_SAMPLE_RATE;
214         vicon_audio_t *audio_data = (vicon_audio_t *)this->audio_data;
215         static const int mx = (1<<(8*sizeof(*audio_data)-1)) - 1;
216         double sample_scale = (double)mx / channels;
217         int audio_pos = 0, audio_len = audio_size/sizeof(vicon_audio_t);
218         while( audio_pos < audio_len ) {
219                 int64_t pos = audio_pos * time_scale;
220                 for( int ch=0; ch<channels; ++ch ) {
221                         file->set_channel(ch);
222                         file->set_audio_position(pos);
223                         file->read_samples(&samples, bfrsz);
224                         double *data = samples.get_data();
225                         for( int64_t k=audio_pos; k<audio_len; ++k ) {
226                                 int i = k * time_scale - pos;
227                                 if( i >= bfrsz ) break;
228                                 int v = audio_data[k] + data[i] * sample_scale;
229                                 audio_data[k] = CLIP(v, -mx,mx);
230                         }
231                 }
232                 audio_pos = (pos + bfrsz) / time_scale;
233         }
234         mwindow->audio_cache->check_in(asset);
235 }
236
237
238 AssetVIconAudio::AssetVIconAudio(AWindowGUI *gui)
239  : Thread(1, 0, 0)
240 {
241         this->gui = gui;
242         audio = new AudioDevice(gui->mwindow);
243         interrupted = 0;
244         vicon = 0;
245 }
246 AssetVIconAudio::~AssetVIconAudio()
247 {
248         delete audio;
249 }
250
251 void AssetVIconAudio::run()
252 {
253         int channels = 2;
254         int64_t bfrsz = VICON_SAMPLE_RATE;
255         MWindow *mwindow = gui->mwindow;
256         EDL *edl = mwindow->edl;
257         EDLSession *session = edl->session;
258         AudioOutConfig *aconfig = session->playback_config->aconfig;
259         audio->open_output(aconfig, VICON_SAMPLE_RATE, bfrsz, channels, 0);
260         audio->start_playback();
261         double out0[bfrsz], out1[bfrsz], *out[2] = { out0, out1 };
262         vicon_audio_t *audio_data = (vicon_audio_t *)vicon->audio_data;
263         static const int mx = (1<<(8*sizeof(*audio_data)-1)) - 1;
264
265         int audio_len = vicon->audio_size/sizeof(vicon_audio_t);
266         while( !interrupted ) {
267                 int len = audio_len - audio_pos;
268                 if( len <= 0 ) break;
269                 if( len > bfrsz ) len = bfrsz;
270                 int k = audio_pos;
271                 for( int i=0; i<len; ++i,++k )
272                         out0[i] = out1[i] = (double)audio_data[k] / mx;
273                 audio_pos = k;
274                 audio->write_buffer(out, channels, len);
275         }
276
277         if( !interrupted )
278                 audio->set_last_buffer();
279         audio->stop_audio(interrupted ? 0 : 1);
280         audio->close_all();
281 }
282
283 void AssetVIconAudio::start(AssetVIcon *vicon)
284 {
285         if( running() ) return;
286         interrupted = 0;
287         double pos = vicon->length > 0 ? (double)vicon->seq_no/vicon->length : 0;
288         int audio_len = vicon->audio_size/sizeof(vicon_audio_t);
289         audio_pos = pos * audio_len;
290         this->vicon = vicon;
291         Thread::start();
292 }
293
294 void AssetVIconAudio::stop(int wait)
295 {
296         if( running() && !interrupted ) {
297                 interrupted = 1;
298                 audio->stop_audio(wait);
299         }
300         Thread::join();
301         if( vicon ) {
302                 vicon->playing_audio = 0;
303                 vicon = 0;
304         }
305 }
306
307 void AssetVIcon::start_audio()
308 {
309         if( playing_audio < 0 ) return;
310         picon->gui->vicon_audio->stop(0);
311         playing_audio = 1;
312         picon->gui->vicon_audio->start(this);
313 }
314
315 void AssetVIcon::stop_audio()
316 {
317         if( playing_audio > 0 ) {
318                 picon->gui->vicon_audio->stop(0);
319                 playing_audio = 0;
320         }
321 }
322
323 AssetViewPopup::AssetViewPopup(VIconThread *vt, int draw_mode,
324                 int x, int y, int w, int h)
325  : ViewPopup(vt, x, y, w, h)
326 {
327         this->draw_mode = draw_mode;
328         this->bar_h = (VIEW_POPUP_BAR_H * h) / 200;
329 }
330
331 AssetViewPopup::~AssetViewPopup()
332 {
333 }
334
335 int AssetViewPopup::button_press_event()
336 {
337         if( !is_event_win() ) return 0;
338         AssetVIconThread *avt = (AssetVIconThread *)vt;
339         if( !avt->vicon ) return 0;
340
341         int dir = 1;
342         switch( get_buttonpress() ) {
343         case LEFT_BUTTON:
344                 break;
345         case WHEEL_DOWN:
346                 dir = -1; // fall thru
347         case WHEEL_UP:
348                 switch( draw_mode ) {
349                 case ASSET_VIEW_MEDIA:
350                 case ASSET_VIEW_MEDIA_MAP:
351                         avt->zoom_scale(dir);
352                         return 1;
353                 } // fall thru
354         default:
355                 return 0;
356         }
357
358         int x = get_cursor_x(), y = get_cursor_y();
359         AssetVIcon *vicon = (AssetVIcon *)avt->vicon;
360         AssetPicon *picon = vicon->picon;
361         MWindow *mwindow = picon->mwindow;
362         EDL *edl = mwindow->edl;
363         dragging = 0;
364         if( y < get_h()/2 ) {
365                 Indexable *idxbl =
366                         picon->indexable ? picon->indexable :
367                         picon->edl ? picon->edl : 0;
368                 if( !idxbl ) return 0;
369                 double sample_rate = idxbl->get_sample_rate();
370                 double audio_length = sample_rate > 0 && idxbl->have_audio() ?
371                         idxbl->get_audio_samples() / sample_rate : 0;
372                 double frame_rate = idxbl->get_frame_rate();
373                 double video_length = frame_rate > 0 && idxbl->have_video() ?
374                         idxbl->get_video_frames() / frame_rate : 0;
375                 double idxbl_length = bmax(audio_length, video_length);
376                 double pos = x * idxbl_length / get_w();
377                 double start = 0, end = idxbl_length;
378                 double lt = DBL_MAX, rt = DBL_MAX;
379                 for( Track *track=edl->tracks->first; track!=0; track=track->next ) {
380                         for( Edit *edit=track->edits->first; edit!=0; edit=edit->next ) {
381                                 Indexable *indexable = (Indexable *)edit->asset;
382                                 if( !indexable ) indexable = (Indexable *)edit->nested_edl;
383                                 if( !indexable ) continue;
384                                 if( indexable->id == idxbl->id ||
385                                     (!indexable->is_asset == !idxbl->is_asset &&
386                                      !strcmp(indexable->path, idxbl->path)) ) {
387                                         double start_pos = track->from_units(edit->startsource);
388                                         double end_pos = track->from_units(edit->startsource + edit->length);
389                                         double dlt = pos - start_pos, drt = end_pos - pos;
390                                         if( dlt >= 0 &&  dlt < lt ) { lt = dlt;  start = start_pos; }
391                                         else if( dlt < 0 && -dlt < rt ) { rt = -dlt;  end = start_pos; }
392                                         if( drt >= 0 &&  drt < rt ) { rt = drt;  end = end_pos; }
393                                         else if( drt < 0 && -drt < lt ) { lt = -drt; start = end_pos; }
394                                 }
395                         }
396                 }
397                 mwindow->gui->lock_window("AssetVIcon::popup_button_press");
398                 VWindow *vwindow = mwindow->get_viewer(1, 0);
399                 vwindow->change_source(idxbl);
400                 mwindow->gui->unlock_window();
401                 EDL *vedl = vwindow->get_edl();
402                 vedl->set_inpoint(start);
403                 vedl->set_outpoint(end);
404                 vedl->local_session->set_selectionstart(start);
405                 vedl->local_session->set_selectionend(start);
406                 vwindow->gui->lock_window("AssetViewPopup::button_press_event");
407                 vwindow->update_position();
408                 vwindow->gui->unlock_window();
409                 return 1;
410         }
411         else {
412                 dragging = 1;
413                 if( !ctrl_down() && !shift_down() )
414                         return cursor_motion_event();
415                 Indexable *idxbl =
416                         picon->indexable ? picon->indexable :
417                         picon->edl ? picon->edl : 0;
418                 if( !idxbl ) return 0;
419                 double total_length = mwindow->edl->tracks->total_length();
420                 double pos = x * total_length / get_w();
421                 double start = 0, end = total_length;
422                 double lt = DBL_MAX, rt = DBL_MAX;
423                 for( Track *track=edl->tracks->first; track!=0; track=track->next ) {
424                         for( Edit *edit=track->edits->first; edit!=0; edit=edit->next ) {
425                                 Indexable *indexable = (Indexable *)edit->asset;
426                                 if( !indexable ) indexable = (Indexable *)edit->nested_edl;
427                                 if( !indexable ) continue;
428                                 if( indexable->id == idxbl->id ||
429                                     (!indexable->is_asset == !idxbl->is_asset &&
430                                      !strcmp(indexable->path, idxbl->path)) ) {
431                                         double start_pos = track->from_units(edit->startproject);
432                                         double end_pos = track->from_units(edit->startproject + edit->length);
433                                         double dlt = pos - start_pos, drt = end_pos - pos;
434                                         if( dlt >= 0 &&  dlt < lt ) { lt = dlt;  start = start_pos; }
435                                         else if( dlt < 0 && -dlt < rt ) { rt = -dlt;  end = start_pos; }
436                                         if( drt >= 0 &&  drt < rt ) { rt = drt;  end = end_pos; }
437                                         else if( drt < 0 && -drt < lt ) { lt = -drt; start = end_pos; }
438                                 }
439                         }
440                 }
441                 mwindow->gui->lock_window("AssetVIcon::popup_button_press");
442                 mwindow->select_point(start);
443                 edl->local_session->set_selectionstart(start);
444                 edl->local_session->set_selectionend(!shift_down() ? start : end);
445                 mwindow->zoom_sample(edl->local_session->zoom_sample);
446                 mwindow->gui->unlock_window();
447                 return 1;
448         }
449         return 0;
450 }
451
452 int AssetViewPopup::button_release_event()
453 {
454         if( !is_event_win() ) return 0;
455         dragging = 0;
456         return 1;
457 }
458
459 int AssetViewPopup::cursor_motion_event()
460 {
461         AssetVIconThread *avt = (AssetVIconThread *)vt;
462         AssetVIcon *vicon = (AssetVIcon *)avt->vicon;
463         if( vicon && dragging && is_event_win() &&
464             get_button_down() && get_buttonpress() == LEFT_BUTTON &&
465             !ctrl_down() && !alt_down() && !shift_down() ) {
466                 switch( draw_mode ) {
467                 case ASSET_VIEW_MEDIA_MAP:
468                 case ASSET_VIEW_FULL:
469                         MWindow *mwindow = vicon->picon->mwindow;
470                         EDL *edl = mwindow->edl;
471                         int x = get_cursor_x();
472                         double total_length = edl->tracks->total_length();
473                         double pos = x * total_length / get_w();
474                         mwindow->gui->lock_window("AssetVIcon::popup_cursor_motion");
475                         mwindow->select_point(pos);
476                         mwindow->zoom_sample(edl->local_session->zoom_sample);
477                         mwindow->gui->unlock_window();
478                         return 1;
479                 }
480         }
481         return 0;
482 }
483
484 void AssetViewPopup::draw_vframe(VFrame *vframe) 
485 {
486         switch( draw_mode ) {
487         case ASSET_VIEW_MEDIA:
488         case ASSET_VIEW_ICON:
489                 ViewPopup::draw_vframe(vframe);
490         case ASSET_VIEW_NONE:
491         default:
492                 return;
493         case ASSET_VIEW_MEDIA_MAP:
494         case ASSET_VIEW_FULL:
495                 break;
496         }
497         set_color(BLACK);
498         draw_box(0,0,get_w(),get_h());
499         int y1 = bar_h;
500         int y2 = get_h()-bar_h;
501         BC_WindowBase::draw_vframe(vframe, 0,y1, get_w(),y2-y1);
502         AssetVIconThread *avt = (AssetVIconThread *)vt;
503         AssetVIcon *vicon = (AssetVIcon *)avt->vicon;
504         AssetPicon *picon = (AssetPicon *)vicon->picon;
505         Indexable *idxbl =
506                 picon->indexable ? picon->indexable :
507                 picon->edl ? picon->edl : 0;
508         if( !idxbl ) return;
509         double sample_rate = idxbl->get_sample_rate();
510         double audio_length = sample_rate > 0 && idxbl->have_audio() ?
511                 idxbl->get_audio_samples() / sample_rate : 0;
512         double frame_rate = idxbl->get_frame_rate();
513         double video_length = frame_rate > 0 && idxbl->have_video() ?
514                 idxbl->get_video_frames() / frame_rate : 0;
515         double idxbl_length = bmax(audio_length, video_length);
516         if( !idxbl_length ) idxbl_length = 1;
517
518         EDL *edl = picon->mwindow->edl;
519         double total_length = edl->tracks->total_length();
520         if( !total_length ) total_length = 1;
521         for( Track *track=edl->tracks->first; track!=0; track=track->next ) {
522                 if( !track->record ) continue;
523                 for( Edit *edit=track->edits->first; edit!=0; edit=edit->next ) {
524                         Indexable *indexable = (Indexable *)edit->asset;
525                         if( !indexable ) indexable = (Indexable *)edit->nested_edl;
526                         if( !indexable ) continue;
527                         if( indexable->id == idxbl->id ||
528                             (!indexable->is_asset == !idxbl->is_asset &&
529                              !strcmp(indexable->path, idxbl->path)) ) {
530                                 double pos1 = track->from_units(edit->startsource);
531                                 double pos2 = track->from_units(edit->startsource + edit->length);
532                                 double xscale = get_w() / idxbl_length;
533                                 int ex1 = pos1 * xscale, ex2 = pos2 * xscale;
534                                 set_color(WHITE);
535                                 draw_box(ex1,0, ex2-ex1,y1);
536                                 set_color(BLACK);
537                                 draw_line(ex1,0, ex1,y1);
538                                 draw_line(ex2,0, ex2,y1);
539                                 pos1 = track->from_units(edit->startproject);
540                                 pos2 = track->from_units(edit->startproject + edit->length);
541                                 xscale = get_w() / total_length;
542                                 int px1 = pos1 * xscale, px2 = pos2 * xscale;
543                                 set_color(RED);
544                                 draw_box(px1,y2, px2-px1,get_h()-y2);
545                                 set_color(BLACK);
546                                 draw_line(px1,y2, px1,get_h()-1);
547                                 draw_line(px2,y2, px2,get_h()-1);
548
549                                 set_color(YELLOW);
550                                 draw_line(ex1,y1, px1,y2);
551                                 draw_line(ex2,y1, px2,y2);
552                         }
553                 }
554         }
555 }
556
557 int AssetViewPopup::keypress_event()
558 {
559         AssetVIconThread *avt = (AssetVIconThread *)vt;
560         switch( avt->draw_mode ) {
561         case ASSET_VIEW_MEDIA_MAP:
562                 switch( get_keypress() ) {
563                 case 'f':
564                 case 'F':
565                         avt->draw_mode = ASSET_VIEW_FULL;
566                         avt->viewing = 0;
567                         return 1;
568                 }
569                 break;
570         case ASSET_VIEW_FULL:
571                 avt->draw_mode = ASSET_VIEW_MEDIA_MAP;
572                 avt->viewing = 0;
573                 return 1;
574         }
575         return ViewPopup::keypress_event();
576 }
577
578
579 AssetVIconThread::AssetVIconThread(AWindowGUI *gui, Preferences *preferences)
580  : VIconThread(gui->asset_list, preferences->vicon_size * 16/9, preferences->vicon_size,
581         4*preferences->awindow_picon_h * 16/9, 4*preferences->awindow_picon_h)
582 {
583         this->gui = gui;
584         draw_mode = ASSET_VIEW_NONE;
585         int vicon_cmodel = BC_RGB8;
586         switch( preferences->vicon_color_mode ) {
587         case VICON_COLOR_MODE_LOW:   vicon_cmodel = BC_RGB8;    break;
588         case VICON_COLOR_MODE_MED:   vicon_cmodel = BC_RGB565;  break;
589         case VICON_COLOR_MODE_HIGH:  vicon_cmodel = BC_RGB888;  break;
590         }
591         this->vicon_cmodel = vicon_cmodel;
592         this->draw_lock = new Mutex("AssetVIconThread::draw_lock");
593 }
594
595 AssetVIconThread::~AssetVIconThread()
596 {
597         delete draw_lock;
598 }
599
600 void AssetVIconThread::drawing_started()
601 {
602         draw_lock->lock("AssetVIconThread::drawing_started");
603 }
604
605 void AssetVIconThread::drawing_stopped()
606 {
607         draw_lock->unlock();
608 }
609
610 void AssetVIconThread::set_view_popup(AssetVIcon *v, int draw_mode)
611 {
612         gui->stop_vicon_drawing();
613         this->draw_mode = draw_mode;
614         VIconThread::set_view_popup(v);
615         gui->start_vicon_drawing();
616 }
617
618 void AssetVIconThread::set_view_popup(AssetVIcon *v)
619 {
620         if( !v ) draw_mode = ASSET_VIEW_NONE;
621         VIconThread::set_view_popup(v);
622 }
623
624 ViewPopup *AssetVIconThread::new_view_window()
625 {
626         BC_WindowBase *parent = wdw->get_parent();
627         int rx = 0, ry = 0, rw = 0, rh = 0;
628         if( draw_mode != ASSET_VIEW_FULL ) {
629                 XineramaScreenInfo *info = parent->get_xinerama_info(-1);
630                 int cx = info ? info->x_org + info->width/2 : parent->get_root_w(0)/2;
631                 int cy = info ? info->y_org + info->height/2 : parent->get_root_h(0)/2;
632                 int vx = viewing->get_vx(), vy = viewing->get_vy();
633                 wdw->get_root_coordinates(vx, vy, &rx, &ry);
634                 rx += (rx >= cx ? -view_w+viewing->w/4 : viewing->w-viewing->w/4);
635                 ry += (ry >= cy ? -view_h+viewing->h/4 : viewing->h-viewing->h/4);
636                 rw = view_w;  rh = view_h;
637         }
638         else
639                 parent->get_fullscreen_geometry(rx, ry, rw, rh);
640         AssetViewPopup *popup = new AssetViewPopup(this, draw_mode, rx, ry, rw, rh);
641         switch( draw_mode ) {
642         case ASSET_VIEW_NONE:
643         case ASSET_VIEW_ICON:
644         case ASSET_VIEW_MEDIA_MAP:
645         case ASSET_VIEW_FULL:
646                 vicon->stop_audio();
647                 vicon->playing_audio = -1;
648                 break;
649         case ASSET_VIEW_MEDIA:
650                 vicon->playing_audio = 1;
651                 vicon->start_audio();
652                 break;
653         }
654         wdw->set_active_subwindow(popup);
655         return popup;
656 }
657
658 void AssetVIconThread::close_view_popup()
659 {
660         stop_drawing();
661         drawing_started(); // waits for draw lock
662         drawing_stopped();
663 }
664
665
666 AWindowFolderItem::AWindowFolderItem()
667  : BC_ListBoxItem()
668 {
669         parent = 0;
670 }
671
672 AWindowFolderItem::AWindowFolderItem(const char *text, int color)
673  : BC_ListBoxItem(text, color)
674 {
675         parent = 0;
676 }
677
678 AWindowFolderItem::AWindowFolderItem(const char *text, BC_Pixmap *icon, int color)
679  : BC_ListBoxItem(text, icon, color)
680 {
681         parent = 0;
682 }
683
684 AssetPicon *AWindowFolderItem::get_picon()
685 {
686         AWindowFolderItem *item = this;
687         while( item->parent ) { item = (AWindowFolderItem*)item->parent; }
688         return (AssetPicon*)item;
689 }
690
691 int AWindowFolderSubItems::matches(const char *text)
692 {
693         int i = names.size();
694         while( --i >= 0 && strcmp(names[i], text) );
695         if( i < 0 ) {
696                 ArrayList<BC_ListBoxItem *> *sublist = get_sublist();
697                 i = sublist ? sublist->size() : 0;
698                 while( --i >= 0 ) {
699                         AWindowFolderSubItems *item = (AWindowFolderSubItems *)sublist->get(i);
700                         if( item->matches(text) ) break;
701                 }
702         }
703         return i >= 0 ? 1 : 0;
704 }
705
706
707 AssetPicon::AssetPicon(MWindow *mwindow,
708         AWindowGUI *gui, Indexable *indexable)
709  : AWindowFolderItem()
710 {
711         reset();
712         this->mwindow = mwindow;
713         this->gui = gui;
714         this->indexable = indexable;
715         indexable->add_user();
716         this->id = indexable->id;
717 }
718
719 AssetPicon::AssetPicon(MWindow *mwindow,
720         AWindowGUI *gui, EDL *edl)
721  : AWindowFolderItem()
722 {
723         reset();
724         this->mwindow = mwindow;
725         this->gui = gui;
726         this->edl = edl;
727         edl->add_user();
728         this->id = edl->id;
729 }
730
731 AssetPicon::AssetPicon(MWindow *mwindow,
732         AWindowGUI *gui, int folder, int persist)
733  : AWindowFolderItem(_(AWindowGUI::folder_names[folder]),
734         folder>=0 && folder<AWINDOW_FOLDERS ?
735                 gui->folder_icons[folder] : gui->folder_icon)
736 {
737         reset();
738         foldernum = folder;
739         this->mwindow = mwindow;
740         this->gui = gui;
741         persistent = persist;
742 }
743
744 AssetPicon::AssetPicon(MWindow *mwindow,
745         AWindowGUI *gui, int folder, const char *title)
746  : AWindowFolderItem(title, gui->folder_icon)
747 {
748         reset();
749         foldernum = folder;
750         this->mwindow = mwindow;
751         this->gui = gui;
752         persistent = 0;
753 }
754
755 AssetPicon::AssetPicon(MWindow *mwindow,
756         AWindowGUI *gui, PluginServer *plugin)
757  : AWindowFolderItem()
758 {
759         reset();
760         this->mwindow = mwindow;
761         this->gui = gui;
762         this->plugin = plugin;
763 }
764
765 AssetPicon::AssetPicon(MWindow *mwindow,
766         AWindowGUI *gui, Label *label)
767  : AWindowFolderItem()
768 {
769         reset();
770         this->mwindow = mwindow;
771         this->gui = gui;
772         this->label = label;
773         indexable = 0;
774         icon = 0;
775         id = 0;
776 }
777
778 AssetPicon::~AssetPicon()
779 {
780         if( vicon ) vicon->remove_user();
781         delete vicon_frame;
782         if( indexable ) indexable->remove_user();
783         if( edl ) edl->remove_user();
784         if( icon && !gui->protected_pixmap(icon) ) {
785                 delete icon;
786                 if( !plugin ) delete icon_vframe;
787         }
788 }
789
790 void AssetPicon::draw_hue_bar(VFrame *frame, double duration)
791 {
792         float t = duration > 1 ? (log(duration) / log(3600.f)) : 0;
793         if( t > 1 ) t = 1;
794         float h = 300 * t, s = 1., v = 1.;
795         float r, g, b; // duration, 0..1hr == hue red..magenta
796         HSV::hsv_to_rgb(r,g,b, h,s,v);
797         int ih = frame->get_h()/8, iw = frame->get_w();
798         int ir = r * 256;  CLAMP(ir, 0,255);
799         int ig = g * 256;  CLAMP(ig, 0,255);
800         int ib = b * 256;  CLAMP(ib, 0,255);
801         unsigned char **rows = frame->get_rows();
802         for( int y=0; y<ih; ++y ) {
803                 unsigned char *rp = rows[y];
804                 for( int x=0; x<iw; rp+=3,++x ) {
805                         rp[0] = ir;  rp[1] = ig;  rp[2] = ib;
806                 }
807         }
808 }
809
810 void AssetPicon::draw_wave(VFrame *frame, double *dp, int len,
811                 int base_color, int line_color, int x, int y, int w, int h)
812 {
813         int h1 = h-1, h2 = h/2, iy = h2;
814         int rgb_color = frame->pixel_rgb;
815         for( int ix=0,x1=0,x2=0; ix<w; ++ix,x1=x2 ) {
816                 double min = *dp, max = min;
817                 x2 = (len * (ix+1))/w;
818                 for( int i=x1; i<x2; ++i ) {
819                         double value = *dp++;
820                         if( value < min ) min = value;
821                         if( value > max ) max = value;
822                 }
823                 int ctr = (min + max) / 2;
824                 int y0 = (int)(h2 - ctr*h2);  CLAMP(y0, 0,h1);
825                 int y1 = (int)(h2 - min*h2);  CLAMP(y1, 0,h1);
826                 int y2 = (int)(h2 - max*h2);  CLAMP(y2, 0,h1);
827                 frame->pixel_rgb = line_color;
828                 frame->draw_line(ix+x,y1+y, ix+x,y2+y);
829                 frame->pixel_rgb = base_color;
830                 frame->draw_line(ix+x,iy+y, ix+x,y0+y);
831                 iy = y0;
832         }
833         frame->pixel_rgb = rgb_color;
834 }
835
836 void AssetPicon::reset()
837 {
838         plugin = 0;
839         label = 0;
840         indexable = 0;
841         edl = 0;
842         parent = 0;
843         sub_items = 0;
844         foldernum = AW_NO_FOLDER;
845         sort_key = -1;
846         icon = 0;
847         icon_vframe = 0;
848         vicon = 0;
849         vicon_frame = 0;
850         in_use = 1;
851         comments_time = 0;
852         id = 0;
853         persistent = 0;
854 }
855
856 void AssetPicon::open_render_engine(EDL *edl, int is_audio)
857 {
858         TransportCommand command;
859         command.command = is_audio ? NORMAL_FWD : CURRENT_FRAME;
860         command.get_edl()->copy_all(edl);
861         command.change_type = CHANGE_ALL;
862         command.realtime = 0;
863         render_engine = new RenderEngine(0, mwindow->preferences, 0, 0);
864         render_engine->set_vcache(mwindow->video_cache);
865         render_engine->set_acache(mwindow->audio_cache);
866         render_engine->arm_command(&command);
867 }
868 void AssetPicon::close_render_engine()
869 {
870         delete render_engine;  render_engine = 0;
871 }
872 void AssetPicon::render_video(int64_t pos, VFrame *vfrm)
873 {
874         if( !render_engine || !render_engine->vrender ) return;
875         render_engine->vrender->process_buffer(vfrm, pos, 0);
876 }
877 void AssetPicon::render_audio(int64_t pos, Samples **samples, int len)
878 {
879         if( !render_engine || !render_engine->arender ) return;
880         render_engine->arender->process_buffer(samples, len, pos);
881 }
882
883 void AssetPicon::create_objects()
884 {
885         FileSystem fs;
886         char name[BCTEXTLEN];
887         int pixmap_w, pixmap_h;
888
889         int picon_h = mwindow->preferences->awindow_picon_h;
890         pixmap_h = picon_h * BC_WindowBase::get_resources()->icon_scale;
891
892         if( indexable ) {
893                 fs.extract_name(name, indexable->path);
894                 set_text(name);
895         }
896         else if( edl ) {
897                 set_text(strcpy(name, edl->local_session->clip_title));
898                 set_text(name);
899         }
900
901         if( indexable && indexable->is_asset ) {
902                 Asset *asset = (Asset*)indexable;
903                 if( asset->video_data ) {
904                         if( mwindow->preferences->use_thumbnails ) {
905                                 gui->unlock_window();
906                                 File *file = mwindow->video_cache->check_out(asset,
907                                         mwindow->edl,
908                                         1);
909
910                                 if( file ) {
911                                         int height = asset->height > 0 ? asset->height : 1;
912                                         pixmap_w = pixmap_h * asset->width / height;
913
914                                         file->set_layer(0);
915                                         file->set_video_position(0, 0);
916
917                                         if( gui->temp_picon &&
918                                                 (gui->temp_picon->get_w() != asset->width ||
919                                                 gui->temp_picon->get_h() != asset->height) ) {
920                                                 delete gui->temp_picon;
921                                                 gui->temp_picon = 0;
922                                         }
923
924                                         if( !gui->temp_picon ) {
925                                                 gui->temp_picon = new VFrame(0, -1,
926                                                         asset->width, asset->height,
927                                                         BC_RGB888, -1);
928                                         }
929                                         { char string[BCTEXTLEN];
930                                         sprintf(string, _("Reading %s"), name);
931                                         mwindow->gui->lock_window("AssetPicon::create_objects");
932                                         mwindow->gui->show_message(string);
933                                         mwindow->gui->unlock_window(); }
934                                         file->read_frame(gui->temp_picon);
935                                         mwindow->video_cache->check_in(asset);
936
937                                         gui->lock_window("AssetPicon::create_objects 0");
938                                         icon = new BC_Pixmap(gui, pixmap_w, pixmap_h);
939                                         icon->draw_vframe(gui->temp_picon,
940                                                 0, 0, pixmap_w, pixmap_h, 0, 0);
941                                         icon_vframe = new VFrame(0,
942                                                 -1, pixmap_w, pixmap_h, BC_RGB888, -1);
943                                         icon_vframe->transfer_from(gui->temp_picon);
944                                         if( asset->folder_no == AW_MEDIA_FOLDER ||
945                                             asset->folder_no == AW_PROXY_FOLDER ) {
946 // vicon images
947                                                 double framerate = asset->get_frame_rate();
948                                                 if( !framerate ) framerate = VICON_RATE;
949                                                 int64_t frames = asset->get_video_frames();
950                                                 double secs = frames / framerate;
951                                                 if( secs > 5 ) secs = 5;
952                                                 int64_t length = secs * gui->vicon_thread->refresh_rate;
953                                                 vicon = new AssetVIcon(this, pixmap_w, pixmap_h, framerate, length);
954                                                 if( asset->audio_data && secs > 0 ) {
955                                                         gui->unlock_window();
956                                                         int audio_len = VICON_SAMPLE_RATE*secs+0.5;
957                                                         vicon->init_audio(audio_len*sizeof(vicon_audio_t));
958                                                         vicon->load_audio();
959                                                         gui->lock_window("AssetPicon::create_objects 1");
960                                                 }
961                                                 gui->vicon_thread->add_vicon(vicon);
962                                         }
963                                 }
964                                 else {
965                                         eprintf("Unable to open %s\nin asset: %s",asset->path, get_text());
966                                         gui->lock_window("AssetPicon::create_objects 2");
967                                         icon = gui->video_icon;
968                                         icon_vframe = gui->video_vframe;
969                                 }
970                         }
971                         else {
972                                 icon = gui->video_icon;
973                                 icon_vframe = gui->video_vframe;
974                         }
975                 }
976                 else
977                 if( asset->audio_data ) {
978                         if( mwindow->preferences->use_thumbnails ) {
979                                 gui->unlock_window();
980                                 File *file = mwindow->audio_cache->check_out(asset,
981                                         mwindow->edl,
982                                         1);
983                                 if( file ) {
984                                         pixmap_w = pixmap_h * 16/9;
985                                         icon_vframe = new VFrame(0,
986                                                 -1, pixmap_w, pixmap_h, BC_RGB888, -1);
987                                         icon_vframe->clear_frame();
988                                         { char string[BCTEXTLEN];
989                                         sprintf(string, _("Reading %s"), name);
990                                         mwindow->gui->lock_window("AssetPicon::create_objects 3");
991                                         mwindow->gui->show_message(string);
992                                         mwindow->gui->unlock_window(); }
993                                         int sample_rate = asset->get_sample_rate();
994                                         int channels = asset->get_audio_channels();
995                                         if( channels > 2 ) channels = 2;
996                                         int64_t audio_samples = asset->get_audio_samples();
997                                         double duration = (double)audio_samples / sample_rate;
998                                         draw_hue_bar(icon_vframe, duration);
999                                         int bfrsz = sample_rate;
1000                                         Samples samples(bfrsz);
1001                                         static int line_colors[2] = { GREEN, YELLOW };
1002                                         static int base_colors[2] = { RED, PINK };
1003                                         for( int i=channels; --i>=0; ) {
1004                                                 file->set_channel(i);
1005                                                 file->set_audio_position(0);
1006                                                 file->read_samples(&samples, bfrsz);
1007                                                 draw_wave(icon_vframe, samples.get_data(), bfrsz,
1008                                                         base_colors[i], line_colors[i]);
1009                                         }
1010                                         mwindow->audio_cache->check_in(asset);
1011                                         if( asset->folder_no == AW_MEDIA_FOLDER ) {
1012                                                 double secs = duration;
1013                                                 if( secs > 5 ) secs = 5;
1014                                                 double refresh_rate = gui->vicon_thread->refresh_rate;
1015                                                 int64_t length = secs * refresh_rate;
1016                                                 vicon = new AssetVIcon(this, pixmap_w, pixmap_h, refresh_rate, length);
1017                                                 int audio_len = VICON_SAMPLE_RATE*secs+0.5;
1018                                                 vicon->init_audio(audio_len*sizeof(vicon_audio_t));
1019                                                 vicon->load_audio();
1020                                                 gui->vicon_thread->add_vicon(vicon);
1021                                         }
1022                                         gui->lock_window("AssetPicon::create_objects 4");
1023                                         icon = new BC_Pixmap(gui, pixmap_w, pixmap_h);
1024                                         icon->draw_vframe(icon_vframe,
1025                                                 0, 0, pixmap_w, pixmap_h, 0, 0);
1026                                 }
1027                                 else {
1028                                         eprintf("Unable to open %s\nin asset: %s",asset->path, get_text());
1029                                         gui->lock_window("AssetPicon::create_objects 5");
1030                                         icon = gui->audio_icon;
1031                                         icon_vframe = gui->audio_vframe;
1032                                 }
1033                         }
1034                         else {
1035                                 icon = gui->audio_icon;
1036                                 icon_vframe = gui->audio_vframe;
1037                         }
1038
1039                 }
1040                 struct stat st;
1041                 comments_time = !stat(asset->path, &st) ? st.st_mtime : 0;
1042         }
1043         else
1044         if( indexable && !indexable->is_asset ) {
1045                 icon = gui->video_icon;
1046                 icon_vframe = gui->video_vframe;
1047         }
1048         else
1049         if( edl ) {
1050                 if( edl->tracks->playable_video_tracks() ) {
1051                         if( mwindow->preferences->use_thumbnails ) {
1052                                 gui->unlock_window();
1053                                 AssetVIconThread *avt = gui->vicon_thread;
1054                                 char clip_icon_path[BCTEXTLEN];
1055                                 char *clip_icon = edl->local_session->clip_icon;
1056                                 VFrame *vframe = 0;
1057                                 if( clip_icon[0] ) {
1058                                         snprintf(clip_icon_path, sizeof(clip_icon_path),
1059                                                 "%s/%s", File::get_config_path(), clip_icon);
1060                                         vframe = VFramePng::vframe_png(clip_icon_path);
1061                                 }
1062                                 if( vframe &&
1063                                     ( vframe->get_w() != avt->vw || vframe->get_h() != avt->vh ) ) {
1064                                         delete vframe;  vframe = 0;
1065                                 }
1066                                 int edl_h = edl->get_h(), edl_w = edl->get_w();
1067                                 int height = edl_h > 0 ? edl_h : 1;
1068                                 int width = edl_w > 0 ? edl_w : 1;
1069                                 int color_model = edl->session->color_model;
1070                                 if( !vframe ) {
1071 //printf("render clip: %s\n", name);
1072                                         VFrame::get_temp(gui->temp_picon, width, height, color_model);
1073                                         char string[BCTEXTLEN];
1074                                         sprintf(string, _("Rendering %s"), name);
1075                                         mwindow->gui->lock_window("AssetPicon::create_objects");
1076                                         mwindow->gui->show_message(string);
1077                                         mwindow->gui->unlock_window();
1078                                         open_render_engine(edl, 0);
1079                                         render_video(0, gui->temp_picon);
1080                                         close_render_engine();
1081                                         vframe = new VFrame(avt->vw, avt->vh, BC_RGB888);
1082                                         vframe->transfer_from(gui->temp_picon);
1083                                         if( clip_icon[0] )
1084                                                 vframe->write_png(clip_icon_path);
1085                                 }
1086                                 pixmap_w = pixmap_h * width / height;
1087                                 vicon = new AssetVIcon(this, pixmap_w, pixmap_h, VICON_RATE, 1);
1088                                 vicon->add_image(vframe, avt->vw, avt->vh, avt->vicon_cmodel);
1089                                 icon_vframe = new VFrame(pixmap_w, pixmap_h, BC_RGB888);
1090                                 icon_vframe->transfer_from(vframe);
1091                                 delete vframe;
1092                                 gui->lock_window("AssetPicon::create_objects 0");
1093                                 icon = new BC_Pixmap(gui, pixmap_w, pixmap_h);
1094                                 icon->draw_vframe(icon_vframe,
1095                                         0, 0, pixmap_w, pixmap_h, 0, 0);
1096                         }
1097                         else {
1098                                 icon = gui->clip_icon;
1099                                 icon_vframe = gui->clip_vframe;
1100                         }
1101                 }
1102                 else
1103                 if( edl->tracks->playable_audio_tracks() ) {
1104                         if( mwindow->preferences->use_thumbnails ) {
1105                                 gui->unlock_window();
1106                                 char clip_icon_path[BCTEXTLEN];
1107                                 char *clip_icon = edl->local_session->clip_icon;
1108                                 if( clip_icon[0] ) {
1109                                         snprintf(clip_icon_path, sizeof(clip_icon_path),
1110                                                 "%s/%s", File::get_config_path(), clip_icon);
1111                                         icon_vframe = VFramePng::vframe_png(clip_icon_path);
1112                                 }
1113                                 if( !icon_vframe ) {
1114                                         pixmap_w = pixmap_h * 16/9;
1115                                         icon_vframe = new VFrame(0,
1116                                                 -1, pixmap_w, pixmap_h, BC_RGB888, -1);
1117                                         icon_vframe->clear_frame();
1118                                         char string[BCTEXTLEN];
1119                                         sprintf(string, _("Rendering %s"), name);
1120                                         mwindow->gui->lock_window("AssetPicon::create_objects 3");
1121                                         mwindow->gui->show_message(string);
1122                                         mwindow->gui->unlock_window();
1123                                         int sample_rate = edl->get_sample_rate();
1124                                         int channels = edl->get_audio_channels();
1125                                         if( channels > 2 ) channels = 2;
1126                                         int64_t audio_samples = edl->get_audio_samples();
1127                                         double duration = (double)audio_samples / sample_rate;
1128                                         draw_hue_bar(icon_vframe, duration);
1129                                         Samples *samples[MAX_CHANNELS];
1130                                         int bfrsz = sample_rate;
1131                                         for( int i=0; i<MAX_CHANNELS; ++i )
1132                                                 samples[i] = i<channels ? new Samples(bfrsz) : 0;
1133                                         open_render_engine(edl, 1);
1134                                         render_audio(0, samples, bfrsz);
1135                                         close_render_engine();
1136                                         gui->lock_window("AssetPicon::create_objects 4");
1137                                         static int line_colors[2] = { GREEN, YELLOW };
1138                                         static int base_colors[2] = { RED, PINK };
1139                                         for( int i=channels; --i>=0; ) {
1140                                                 draw_wave(icon_vframe, samples[i]->get_data(), bfrsz,
1141                                                         base_colors[i], line_colors[i]);
1142                                         }
1143                                         for( int i=0; i<channels; ++i ) delete samples[i];
1144                                         if( clip_icon[0] ) icon_vframe->write_png(clip_icon_path);
1145                                 }
1146                                 else {
1147                                         pixmap_w = icon_vframe->get_w();
1148                                         pixmap_h = icon_vframe->get_h();
1149                                 }
1150                                 icon = new BC_Pixmap(gui, pixmap_w, pixmap_h);
1151                                 icon->draw_vframe(icon_vframe,
1152                                         0, 0, pixmap_w, pixmap_h, 0, 0);
1153                         }
1154                         else {
1155                                 icon = gui->clip_icon;
1156                                 icon_vframe = gui->clip_vframe;
1157                         }
1158                 }
1159         }
1160         else
1161         if( plugin ) {
1162                 strcpy(name, _(plugin->title));
1163                 set_text(name);
1164                 icon_vframe = plugin->get_picon();
1165                 if( icon_vframe )
1166                         icon = gui->create_pixmap(icon_vframe);
1167                 else if( plugin->audio ) {
1168                         if( plugin->transition ) {
1169                                 icon = gui->atransition_icon;
1170                                 icon_vframe = gui->atransition_vframe;
1171                         }
1172                         else if( plugin->is_ffmpeg() ) {
1173                                 icon = gui->ff_aud_icon;
1174                                 icon_vframe = gui->ff_aud_vframe;
1175                         }
1176                         else if( plugin->is_ladspa() ) {
1177                                 icon = gui->ladspa_icon;
1178                                 icon_vframe = gui->ladspa_vframe;
1179                         }
1180                         else {
1181                                 icon = gui->aeffect_icon;
1182                                 icon_vframe = gui->aeffect_vframe;
1183                         }
1184                 }
1185                 else if( plugin->video ) {
1186                         if( plugin->transition ) {
1187                                 icon = gui->vtransition_icon;
1188                                 icon_vframe = gui->vtransition_vframe;
1189                         }
1190                         else if( plugin->is_ffmpeg() ) {
1191                                 icon = gui->ff_vid_icon;
1192                                 icon_vframe = gui->ff_vid_vframe;
1193                         }
1194                         else {
1195                                 icon = gui->veffect_icon;
1196                                 icon_vframe = gui->veffect_vframe;
1197                         }
1198                 }
1199         }
1200         else
1201         if( label ) {
1202                 Units::totext(name,
1203                               label->position,
1204                               mwindow->edl->session->time_format,
1205                               mwindow->edl->session->sample_rate,
1206                               mwindow->edl->session->frame_rate,
1207                               mwindow->edl->session->frames_per_foot);
1208                 set_text(name);
1209                 icon = gui->label_icon;
1210                 icon_vframe = gui->label_vframe;
1211         }
1212         if( !icon ) {
1213                 icon = gui->file_icon;
1214                 icon_vframe = BC_WindowBase::get_resources()->type_to_icon[ICON_UNKNOWN];
1215         }
1216         set_icon(icon);
1217         set_icon_vframe(icon_vframe);
1218 }
1219
1220 AWindowGUI::AWindowGUI(MWindow *mwindow, AWindow *awindow)
1221  : BC_Window(_(PROGRAM_NAME ": Resources"),
1222         mwindow->session->awindow_x, mwindow->session->awindow_y,
1223         mwindow->session->awindow_w, mwindow->session->awindow_h,
1224         100, 100, 1, 1, 1)
1225 {
1226         this->mwindow = mwindow;
1227         this->awindow = awindow;
1228
1229         file_vframe = 0;                file_icon = 0;
1230         folder_vframe = 0;              folder_icon = 0;
1231         audio_vframe = 0;               audio_icon = 0;
1232         video_vframe = 0;               video_icon = 0;
1233         label_vframe = 0;               label_icon = 0;
1234
1235         aeffect_folder_vframe = 0;      aeffect_folder_icon = 0;
1236         atransition_folder_vframe = 0;  atransition_folder_icon = 0;
1237         clip_folder_vframe = 0;         clip_folder_icon = 0;
1238         label_folder_vframe = 0;        label_folder_icon = 0;
1239         media_folder_vframe = 0;        media_folder_icon = 0;
1240         proxy_folder_vframe = 0;        proxy_folder_icon = 0;
1241         veffect_folder_vframe = 0;      veffect_folder_icon = 0;
1242         vtransition_folder_vframe = 0;  vtransition_folder_icon = 0;
1243
1244         ladspa_vframe = 0;              ladspa_icon = 0;
1245         ff_aud_vframe = 0;              ff_aud_icon = 0;
1246         ff_vid_vframe = 0;              ff_vid_icon = 0;
1247
1248         clip_vframe = 0;                clip_icon = 0;
1249         atransition_vframe = 0;         atransition_icon = 0;
1250         vtransition_vframe = 0;         vtransition_icon = 0;
1251         aeffect_vframe = 0;             aeffect_icon = 0;
1252         veffect_vframe = 0;             veffect_icon = 0;
1253
1254         plugin_visibility = ((uint64_t)1<<(8*sizeof(uint64_t)-1))-1;
1255         asset_menu = 0;
1256         effectlist_menu = 0;
1257         assetlist_menu = 0;
1258         cliplist_menu = 0;
1259         proxylist_menu = 0;
1260         labellist_menu = 0;
1261         folderlist_menu = 0;
1262         temp_picon = 0;
1263         search_text = 0;
1264         allow_iconlisting = 1;
1265         remove_plugin = 0;
1266         vicon_thread = 0;
1267         vicon_audio = 0;
1268         vicon_drawing = AVICON_FULL_PLAY;
1269         displayed_folder = AW_NO_FOLDER;
1270         new_folder_thread = 0;
1271         modify_folder_thread = 0;
1272         folder_lock = new Mutex("AWindowGUI::folder_lock");
1273 }
1274
1275 AWindowGUI::~AWindowGUI()
1276 {
1277         assets.remove_all_objects();
1278         folders.remove_all_objects();
1279         aeffects.remove_all_objects();
1280         veffects.remove_all_objects();
1281         atransitions.remove_all_objects();
1282         vtransitions.remove_all_objects();
1283         labellist.remove_all_objects();
1284         displayed_assets[1].remove_all_objects();
1285
1286         delete new_folder_thread;
1287         delete modify_folder_thread;
1288         delete vicon_thread;
1289         delete vicon_audio;
1290
1291         delete search_text;
1292         delete temp_picon;
1293         delete remove_plugin;
1294
1295         delete file_vframe;             delete file_icon;
1296         delete folder_vframe;           delete folder_icon;
1297         delete audio_vframe;            delete audio_icon;
1298         delete video_vframe;            delete video_icon;
1299         delete label_vframe;            delete label_icon;
1300         delete clip_vframe;             delete clip_icon;
1301         delete aeffect_folder_vframe;   delete aeffect_folder_icon;
1302         delete atransition_folder_vframe; delete atransition_folder_icon;
1303         delete veffect_folder_vframe;   delete veffect_folder_icon;
1304         delete vtransition_folder_vframe; delete vtransition_folder_icon;
1305         delete clip_folder_vframe;      delete clip_folder_icon;
1306         delete label_folder_vframe;     delete label_folder_icon;
1307         delete media_folder_vframe;     delete media_folder_icon;
1308         delete proxy_folder_vframe;     delete proxy_folder_icon;
1309         delete ladspa_vframe;           delete ladspa_icon;
1310         delete ff_aud_vframe;           delete ff_aud_icon;
1311         delete ff_vid_vframe;           delete ff_vid_icon;
1312         delete atransition_vframe;      delete atransition_icon;
1313         delete vtransition_vframe;      delete vtransition_icon;
1314         delete aeffect_vframe;          delete aeffect_icon;
1315         delete veffect_vframe;          delete veffect_icon;
1316         delete folder_lock;
1317 }
1318
1319 bool AWindowGUI::protected_pixmap(BC_Pixmap *icon)
1320 {
1321         return  icon == file_icon ||
1322                 icon == folder_icon ||
1323                 icon == audio_icon ||
1324                 icon == video_icon ||
1325                 icon == clip_icon ||
1326                 icon == label_icon ||
1327                 icon == vtransition_icon ||
1328                 icon == atransition_icon ||
1329                 icon == veffect_icon ||
1330                 icon == aeffect_icon ||
1331                 icon == ladspa_icon ||
1332                 icon == ff_aud_icon ||
1333                 icon == ff_vid_icon ||
1334                 icon == aeffect_folder_icon ||
1335                 icon == veffect_folder_icon ||
1336                 icon == atransition_folder_icon ||
1337                 icon == vtransition_folder_icon ||
1338                 icon == label_folder_icon ||
1339                 icon == clip_folder_icon ||
1340                 icon == media_folder_icon ||
1341                 icon == proxy_folder_icon;
1342 }
1343
1344 VFrame *AWindowGUI::get_picon(const char *name, const char *plugin_icons)
1345 {
1346         char png_path[BCTEXTLEN];
1347         char *pp = png_path, *ep = pp + sizeof(png_path)-1;
1348         snprintf(pp, ep-pp, "%s/picon/%s/%s.png",
1349                 File::get_plugin_path(), plugin_icons, name);
1350         if( access(png_path, R_OK) ) return 0;
1351         return VFramePng::vframe_png(png_path,0,0);
1352 }
1353
1354 VFrame *AWindowGUI::get_picon(const char *name)
1355 {
1356         VFrame *vframe = get_picon(name, mwindow->preferences->plugin_icons);
1357         if( !vframe ) {
1358                 char png_name[BCSTRLEN], *pp = png_name, *ep = pp + sizeof(png_name)-1;
1359                 snprintf(pp, ep-pp, "%s.png", name);
1360                 unsigned char *data = mwindow->theme->get_image_data(png_name);
1361                 if( data ) vframe = new VFramePng(data, 0.);
1362         }
1363         return vframe;
1364 }
1365
1366 void AWindowGUI::resource_icon(VFrame *&vfrm, BC_Pixmap *&icon, const char *fn, int idx)
1367 {
1368         vfrm = get_picon(fn);
1369         if( !vfrm ) vfrm = BC_WindowBase::get_resources()->type_to_icon[idx];
1370         icon = new BC_Pixmap(this, vfrm, PIXMAP_ALPHA);
1371 }
1372 void AWindowGUI::theme_icon(VFrame *&vfrm, BC_Pixmap *&icon, const char *fn)
1373 {
1374         vfrm = get_picon(fn);
1375         if( !vfrm ) vfrm = mwindow->theme->get_image(fn);
1376         icon = new BC_Pixmap(this, vfrm, PIXMAP_ALPHA);
1377 }
1378 void AWindowGUI::plugin_icon(VFrame *&vfrm, BC_Pixmap *&icon, const char *fn, unsigned char *png)
1379 {
1380         vfrm = get_picon(fn);
1381         if( !vfrm ) vfrm = new VFramePng(png);
1382         icon = new BC_Pixmap(this, vfrm, PIXMAP_ALPHA);
1383 }
1384
1385 void AWindowGUI::create_objects()
1386 {
1387         lock_window("AWindowGUI::create_objects");
1388         asset_titles[0] = C_("Title");
1389         asset_titles[1] = _("Comments");
1390
1391         set_icon(mwindow->theme->get_image("awindow_icon"));
1392
1393         resource_icon(file_vframe,   file_icon,   "film_icon",   ICON_UNKNOWN);
1394         resource_icon(folder_vframe, folder_icon, "folder_icon", ICON_FOLDER);
1395         resource_icon(audio_vframe,  audio_icon,  "audio_icon",  ICON_SOUND);
1396         resource_icon(video_vframe,  video_icon,  "video_icon",  ICON_FILM);
1397         resource_icon(label_vframe,  label_icon,  "label_icon",  ICON_LABEL);
1398
1399         theme_icon(aeffect_folder_vframe,      aeffect_folder_icon,     "aeffect_folder");
1400         theme_icon(atransition_folder_vframe,  atransition_folder_icon, "atransition_folder");
1401         theme_icon(clip_folder_vframe,         clip_folder_icon,        "clip_folder");
1402         theme_icon(label_folder_vframe,        label_folder_icon,       "label_folder");
1403         theme_icon(media_folder_vframe,        media_folder_icon,       "media_folder");
1404         theme_icon(proxy_folder_vframe,        proxy_folder_icon,       "proxy_folder");
1405         theme_icon(veffect_folder_vframe,      veffect_folder_icon,     "veffect_folder");
1406         theme_icon(vtransition_folder_vframe,  vtransition_folder_icon, "vtransition_folder");
1407
1408         folder_icons[AW_AEFFECT_FOLDER] = aeffect_folder_icon;
1409         folder_icons[AW_VEFFECT_FOLDER] = veffect_folder_icon;
1410         folder_icons[AW_ATRANSITION_FOLDER] = atransition_folder_icon;
1411         folder_icons[AW_VTRANSITION_FOLDER] = vtransition_folder_icon;
1412         folder_icons[AW_LABEL_FOLDER] = label_folder_icon;
1413         folder_icons[AW_CLIP_FOLDER] = clip_folder_icon;
1414         folder_icons[AW_MEDIA_FOLDER] = media_folder_icon;
1415         folder_icons[AW_PROXY_FOLDER] = proxy_folder_icon;
1416
1417         theme_icon(clip_vframe,        clip_icon,        "clip_icon");
1418         theme_icon(atransition_vframe, atransition_icon, "atransition_icon");
1419         theme_icon(vtransition_vframe, vtransition_icon, "vtransition_icon");
1420         theme_icon(aeffect_vframe,     aeffect_icon,     "aeffect_icon");
1421         theme_icon(veffect_vframe,     veffect_icon,     "veffect_icon");
1422
1423         plugin_icon(ladspa_vframe, ladspa_icon, "lad_picon", lad_picon_png);
1424         plugin_icon(ff_aud_vframe, ff_aud_icon, "ff_audio",  ff_audio_png);
1425         plugin_icon(ff_vid_vframe, ff_vid_icon, "ff_video",  ff_video_png);
1426         folder_lock->lock("AWindowGUI::create_objects");
1427 // Mandatory folders
1428         folders.append(new AssetPicon(mwindow, this, AW_AEFFECT_FOLDER, 1));
1429         folders.append(new AssetPicon(mwindow, this, AW_VEFFECT_FOLDER, 1));
1430         folders.append(new AssetPicon(mwindow, this, AW_ATRANSITION_FOLDER, 1));
1431         folders.append(new AssetPicon(mwindow, this, AW_VTRANSITION_FOLDER, 1));
1432         folders.append(new AssetPicon(mwindow, this, AW_LABEL_FOLDER, 1));
1433         folders.append(new AssetPicon(mwindow, this, AW_CLIP_FOLDER, 1));
1434         folders.append(new AssetPicon(mwindow, this, AW_PROXY_FOLDER, 1));
1435         folders.append(new AssetPicon(mwindow, this, AW_MEDIA_FOLDER, 1));
1436
1437         create_label_folder();
1438         folder_lock->unlock();
1439
1440         mwindow->theme->get_awindow_sizes(this);
1441         load_defaults(mwindow->defaults);
1442         new_folder_thread = new NewFolderThread(this);
1443         modify_folder_thread = new ModifyFolderThread(this);
1444
1445         int x1 = mwindow->theme->alist_x, y1 = mwindow->theme->alist_y;
1446         int w1 = mwindow->theme->alist_w, h1 = mwindow->theme->alist_h;
1447         search_text = new AWindowSearchText(mwindow, this, x1, y1+5);
1448         search_text->create_objects();
1449         int dy = search_text->get_h() + 10;
1450         y1 += dy;  h1 -= dy;
1451         add_subwindow(asset_list = new AWindowAssets(mwindow, this, x1, y1, w1, h1));
1452
1453         vicon_thread = new AssetVIconThread(this, mwindow->preferences);
1454         asset_list->update_vicon_area();
1455         vicon_thread->start();
1456         vicon_audio = new AssetVIconAudio(this);
1457
1458         add_subwindow(divider = new AWindowDivider(mwindow, this,
1459                 mwindow->theme->adivider_x, mwindow->theme->adivider_y,
1460                 mwindow->theme->adivider_w, mwindow->theme->adivider_h));
1461
1462         divider->set_cursor(HSEPARATE_CURSOR, 0, 0);
1463
1464         int fx = mwindow->theme->afolders_x, fy = mwindow->theme->afolders_y;
1465         int fw = mwindow->theme->afolders_w, fh = mwindow->theme->afolders_h;
1466         const char *text = _("Preview");
1467         int tw = get_text_width(MEDIUMFONT, text);
1468         int pw = BC_PopupMenu::calculate_w(4, tw, -1);
1469         add_subwindow(avicon_drawing = new AVIconDrawing(this, fw, fy, pw, text));
1470         avicon_drawing->create_objects();
1471         add_subwindow(add_tools = new AddTools(mwindow, this, fx, fy, _("Visibility")));
1472         add_tools->create_objects();
1473         fy += add_tools->get_h();  fh -= add_tools->get_h();
1474         add_subwindow(folder_list = new AWindowFolders(mwindow,
1475                 this, fx, fy, fw, fh));
1476         update_effects();
1477         folder_list->load_expanders();
1478
1479         //int x = mwindow->theme->abuttons_x;
1480         //int y = mwindow->theme->abuttons_y;
1481
1482         add_subwindow(asset_menu = new AssetPopup(mwindow, this));
1483         asset_menu->create_objects();
1484         add_subwindow(clip_menu = new ClipPopup(mwindow, this));
1485         clip_menu->create_objects();
1486         add_subwindow(label_menu = new LabelPopup(mwindow, this));
1487         label_menu->create_objects();
1488         add_subwindow(proxy_menu = new ProxyPopup(mwindow, this));
1489         proxy_menu->create_objects();
1490
1491         add_subwindow(effectlist_menu = new EffectListMenu(mwindow, this));
1492         effectlist_menu->create_objects();
1493         add_subwindow(assetlist_menu = new AssetListMenu(mwindow, this));
1494         assetlist_menu->create_objects();
1495         add_subwindow(cliplist_menu = new ClipListMenu(mwindow, this));
1496         cliplist_menu->create_objects();
1497         add_subwindow(labellist_menu = new LabelListMenu(mwindow, this));
1498         labellist_menu->create_objects();
1499         add_subwindow(proxylist_menu = new ProxyListMenu(mwindow, this));
1500         proxylist_menu->create_objects();
1501
1502         add_subwindow(folderlist_menu = new FolderListMenu(mwindow, this));
1503         folderlist_menu->create_objects();
1504
1505         create_custom_xatoms();
1506         unlock_window();
1507 }
1508
1509 int AWindowGUI::resize_event(int w, int h)
1510 {
1511         mwindow->session->awindow_x = get_x();
1512         mwindow->session->awindow_y = get_y();
1513         mwindow->session->awindow_w = w;
1514         mwindow->session->awindow_h = h;
1515
1516         mwindow->theme->get_awindow_sizes(this);
1517         mwindow->theme->draw_awindow_bg(this);
1518         reposition_objects();
1519
1520 //      int x = mwindow->theme->abuttons_x;
1521 //      int y = mwindow->theme->abuttons_y;
1522 //      new_bin->reposition_window(x, y);
1523 //      x += new_bin->get_w();
1524 //      delete_bin->reposition_window(x, y);
1525 //      x += delete_bin->get_w();
1526 //      rename_bin->reposition_window(x, y);
1527 //      x += rename_bin->get_w();
1528 //      delete_disk->reposition_window(x, y);
1529 //      x += delete_disk->get_w();
1530 //      delete_project->reposition_window(x, y);
1531 //      x += delete_project->get_w();
1532 //      info->reposition_window(x, y);
1533 //      x += info->get_w();
1534 //      redraw_index->reposition_window(x, y);
1535 //      x += redraw_index->get_w();
1536 //      paste->reposition_window(x, y);
1537 //      x += paste->get_w();
1538 //      append->reposition_window(x, y);
1539 //      x += append->get_w();
1540 //      view->reposition_window(x, y);
1541
1542         BC_WindowBase::resize_event(w, h);
1543         asset_list->update_vicon_area();
1544         return 1;
1545 }
1546
1547 int AWindowGUI::translation_event()
1548 {
1549         mwindow->session->awindow_x = get_x();
1550         mwindow->session->awindow_y = get_y();
1551         return 0;
1552 }
1553
1554 void AWindowGUI::reposition_objects()
1555 {
1556         int x1 = mwindow->theme->alist_x, y1 = mwindow->theme->alist_y;
1557         int w1 = mwindow->theme->alist_w, h1 = mwindow->theme->alist_h;
1558         search_text->reposition_window(x1, y1+5, w1);
1559         int dy = search_text->get_h() + 10;
1560         y1 += dy;  h1 -= dy;
1561         asset_list->reposition_window(x1, y1, w1, h1);
1562         divider->reposition_window(
1563                 mwindow->theme->adivider_x, mwindow->theme->adivider_y,
1564                 mwindow->theme->adivider_w, mwindow->theme->adivider_h);
1565         int fx = mwindow->theme->afolders_x, fy = mwindow->theme->afolders_y;
1566         int fw = mwindow->theme->afolders_w, fh = mwindow->theme->afolders_h;
1567         add_tools->resize_event(fw-avicon_w, add_tools->get_h());
1568         avicon_drawing->reposition_window(fw-avicon_drawing->get_w(), fy);
1569         fy += add_tools->get_h();  fh -= add_tools->get_h();
1570         folder_list->reposition_window(fx, fy, fw, fh);
1571 }
1572
1573 int AWindowGUI::save_defaults(BC_Hash *defaults)
1574 {
1575         defaults->update("PLUGIN_VISIBILTY", plugin_visibility);
1576         defaults->update("VICON_DRAWING", vicon_drawing);
1577         return 0;
1578 }
1579
1580 int AWindowGUI::load_defaults(BC_Hash *defaults)
1581 {
1582         plugin_visibility = defaults->get("PLUGIN_VISIBILTY", plugin_visibility);
1583         vicon_drawing = defaults->get("VICON_DRAWING", vicon_drawing);
1584         return 0;
1585 }
1586
1587 int AWindowGUI::close_event()
1588 {
1589         hide_window();
1590         mwindow->session->show_awindow = 0;
1591         unlock_window();
1592
1593         mwindow->gui->lock_window("AWindowGUI::close_event");
1594         mwindow->gui->mainmenu->show_awindow->set_checked(0);
1595         mwindow->gui->unlock_window();
1596
1597         lock_window("AWindowGUI::close_event");
1598         save_defaults(mwindow->defaults);
1599         mwindow->save_defaults();
1600         return 1;
1601 }
1602
1603 void AWindowGUI::start_vicon_drawing()
1604 {
1605         if( !vicon_thread->interrupted ) return;
1606         switch( vicon_drawing ) {
1607         case AVICON_FULL_PLAY:  // all vicons, viewing, target
1608         case AVICON_MOUSE_OVER: // one vicon, viewing, target
1609                 break;
1610         case AVICON_SRC_TARGET: // no vicons, no view, target
1611         case AVICON_NO_PLAY:    // no vicons, no view, no target
1612                 return;
1613         }
1614         if( mwindow->edl->session->awindow_folder == AW_MEDIA_FOLDER ||
1615             mwindow->edl->session->awindow_folder == AW_PROXY_FOLDER ||
1616             mwindow->edl->session->awindow_folder == AW_CLIP_FOLDER ||
1617             mwindow->edl->session->awindow_folder >= AWINDOW_USER_FOLDERS ) {
1618                 switch( mwindow->edl->session->assetlist_format ) {
1619                 case ASSETS_ICONS:
1620                 case ASSETS_ICONS_PACKED:
1621                 case ASSETS_ICON_LIST:
1622                         asset_list->update_vicon_area();
1623                         vicon_thread->start_drawing();
1624                         break;
1625                 default:
1626                         break;
1627                 }
1628         }
1629 }
1630
1631 int AWindowGUI::stop_vicon_drawing()
1632 {
1633         if( vicon_thread->interrupted ) return 0;
1634         vicon_thread->stop_drawing();
1635         return 1;
1636 }
1637
1638 void AWindowGUI::close_view_popup()
1639 {
1640         vicon_thread->close_view_popup();
1641 }
1642
1643 VFrame *AssetPicon::get_vicon_frame()
1644 {
1645         if( !vicon ) return 0;
1646         if( gui->vicon_thread->interrupted ) return 0;
1647         VFrame *frame = vicon->frame();
1648         if( !frame ) return 0;
1649         if( !vicon_frame )
1650                 vicon_frame = new VFrame(vicon->w, vicon->h, frame->get_color_model());
1651         vicon_frame->transfer_from(frame);
1652         return vicon_frame;
1653 }
1654
1655 int AWindowGUI::cycle_assetlist_format()
1656 {
1657         EDLSession *session = mwindow->edl->session;
1658         int format = ASSETS_TEXT;
1659         if( allow_iconlisting ) {
1660                 switch( session->assetlist_format ) {
1661                 case ASSETS_TEXT:
1662                         format = ASSETS_ICONS;
1663                         break;
1664                 case ASSETS_ICONS:
1665                         format = ASSETS_ICONS_PACKED;
1666                         break;
1667                 case ASSETS_ICONS_PACKED:
1668                         format = ASSETS_ICON_LIST;
1669                         break;
1670                 case ASSETS_ICON_LIST:
1671                         format = ASSETS_TEXT;
1672                         break;
1673                 }
1674         }
1675         stop_vicon_drawing();
1676         session->assetlist_format = format;
1677         asset_list->update_format(session->assetlist_format, 0);
1678         async_update_assets();
1679         start_vicon_drawing();
1680         return 1;
1681 }
1682
1683 AWindowRemovePluginGUI::
1684 AWindowRemovePluginGUI(AWindow *awindow, AWindowRemovePlugin *thread,
1685         int x, int y, PluginServer *plugin)
1686  : BC_Window(_(PROGRAM_NAME ": Remove plugin"), x,y, 500,200, 50, 50, 1, 0, 1, -1, "", 1)
1687 {
1688         this->awindow = awindow;
1689         this->thread = thread;
1690         this->plugin = plugin;
1691         VFrame *vframe = plugin->get_picon();
1692         icon = vframe ? create_pixmap(vframe) : 0;
1693         plugin_list.append(new BC_ListBoxItem(plugin->title, icon));
1694 }
1695
1696 AWindowRemovePluginGUI::
1697 ~AWindowRemovePluginGUI()
1698 {
1699         if( !awindow->gui->protected_pixmap(icon) )
1700                 delete icon;
1701         plugin_list.remove_all();
1702 }
1703
1704 void AWindowRemovePluginGUI::create_objects()
1705 {
1706         lock_window("AWindowRemovePluginGUI::create_objects");
1707         BC_Button *ok_button = new BC_OKButton(this);
1708         add_subwindow(ok_button);
1709         BC_Button *cancel_button = new BC_CancelButton(this);
1710         add_subwindow(cancel_button);
1711         int x = 10, y = 10;
1712         BC_Title *title = new BC_Title(x, y, _("remove plugin?"));
1713         add_subwindow(title);
1714         y += title->get_h() + 5;
1715         list = new BC_ListBox(x, y,
1716                 get_w() - 20, ok_button->get_y() - y - 5, LISTBOX_TEXT, &plugin_list,
1717                 0, 0, 1, 0, 0, LISTBOX_SINGLE, ICON_LEFT, 0);
1718         add_subwindow(list);
1719         show_window();
1720         unlock_window();
1721 }
1722
1723 int AWindowRemovePlugin::remove_plugin(PluginServer *plugin, ArrayList<BC_ListBoxItem*> &folder)
1724 {
1725         int ret = 0;
1726         for( int i=0; i<folder.size(); ) {
1727                 AssetPicon *picon = (AssetPicon *)folder[i];
1728                 if( picon->plugin == plugin ) {
1729                         folder.remove_object_number(i);
1730                         ++ret;
1731                         continue;
1732                 }
1733                 ++i;
1734         }
1735         return ret;
1736 }
1737
1738 void AWindowRemovePlugin::handle_close_event(int result)
1739 {
1740         if( !result ) {
1741                 printf(_("remove %s\n"), plugin->path);
1742                 awindow->gui->lock_window("AWindowRemovePlugin::handle_close_event");
1743                 ArrayList<BC_ListBoxItem*> *folder =
1744                         plugin->audio ? plugin->transition ?
1745                                 &awindow->gui->atransitions :
1746                                 &awindow->gui->aeffects :
1747                         plugin->video ?  plugin->transition ?
1748                                 &awindow->gui->vtransitions :
1749                                 &awindow->gui->veffects :
1750                         0;
1751                 if( folder ) remove_plugin(plugin, *folder);
1752                 MWindow *mwindow = awindow->mwindow;
1753                 awindow->gui->unlock_window();
1754                 char plugin_path[BCTEXTLEN];
1755                 strcpy(plugin_path, plugin->path);
1756                 mwindow->plugindb->remove(plugin);
1757                 remove(plugin_path);
1758                 char index_path[BCTEXTLEN];
1759                 mwindow->create_defaults_path(index_path, PLUGIN_FILE);
1760                 remove(index_path);
1761                 char picon_path[BCTEXTLEN];
1762                 FileSystem fs;
1763                 snprintf(picon_path, sizeof(picon_path), "%s/picon",
1764                         File::get_plugin_path());
1765                 char png_name[BCSTRLEN], png_path[BCTEXTLEN];
1766                 plugin->get_plugin_png_name(png_name);
1767                 fs.update(picon_path);
1768                 for( int i=0; i<fs.dir_list.total; ++i ) {
1769                         char *fs_path = fs.dir_list[i]->path;
1770                         if( !fs.is_dir(fs_path) ) continue;
1771                         snprintf(png_path, sizeof(picon_path), "%s/%s",
1772                                 fs_path, png_name);
1773                         remove(png_path);
1774                 }
1775                 delete plugin;  plugin = 0;
1776                 awindow->gui->async_update_assets();
1777         }
1778 }
1779
1780 AWindowRemovePlugin::
1781 AWindowRemovePlugin(AWindow *awindow, PluginServer *plugin)
1782  : BC_DialogThread()
1783 {
1784         this->awindow = awindow;
1785         this->plugin = plugin;
1786 }
1787
1788 AWindowRemovePlugin::
1789 ~AWindowRemovePlugin()
1790 {
1791         close_window();
1792 }
1793
1794 BC_Window* AWindowRemovePlugin::new_gui()
1795 {
1796         int x = awindow->gui->get_abs_cursor_x(0);
1797         int y = awindow->gui->get_abs_cursor_y(0);
1798         AWindowRemovePluginGUI *gui = new AWindowRemovePluginGUI(awindow, this, x, y, plugin);
1799         gui->create_objects();
1800         return gui;
1801 }
1802
1803 int AWindowGUI::keypress_event()
1804 {
1805         switch( get_keypress() ) {
1806         case 'w': case 'W':
1807                 if( ctrl_down() ) {
1808                         close_event();
1809                         return 1;
1810                 }
1811                 break;
1812         case 'o':
1813                 if( !ctrl_down() && !shift_down() ) {
1814                         assetlist_menu->load_file->handle_event();
1815                         return 1;
1816                 }
1817                 break;
1818         case 'v':
1819                 return cycle_assetlist_format();
1820         case DELETE:
1821                 if( shift_down() && ctrl_down() ) {
1822                         PluginServer* plugin = selected_plugin();
1823                         if( !plugin ) break;
1824                         remove_plugin = new AWindowRemovePlugin(awindow, plugin);
1825                         unlock_window();
1826                         remove_plugin->start();
1827                         lock_window("AWindowGUI::keypress_event 1");
1828                         return 1;
1829                 }
1830                 collect_assets();
1831                 if( shift_down() ) {
1832                         mwindow->awindow->asset_remove->start();
1833                         return 1;
1834                 }
1835                 unlock_window();
1836                 mwindow->remove_assets_from_project(1, 1,
1837                         mwindow->session->drag_assets,
1838                         mwindow->session->drag_clips);
1839                 lock_window("AWindowGUI::keypress_event 2");
1840                 return 1;
1841         case KEY_F1:
1842         case KEY_F2:
1843         case KEY_F3:
1844         case KEY_F4:
1845                 if( shift_down() && ctrl_down() ) {
1846                         resend_event(mwindow->gui);
1847                         return 1;
1848                 }
1849                 break;
1850         }
1851         return 0;
1852 }
1853
1854
1855
1856 int AWindowGUI::create_custom_xatoms()
1857 {
1858         UpdateAssetsXAtom = create_xatom("CWINDOWGUI_UPDATE_ASSETS");
1859         return 0;
1860 }
1861 int AWindowGUI::receive_custom_xatoms(xatom_event *event)
1862 {
1863         if( event->message_type == UpdateAssetsXAtom ) {
1864                 update_assets();
1865                 return 1;
1866         }
1867         return 0;
1868 }
1869
1870 void AWindowGUI::async_update_assets()
1871 {
1872         xatom_event event;
1873         event.message_type = UpdateAssetsXAtom;
1874         send_custom_xatom(&event);
1875 }
1876
1877
1878 void AWindowGUI::update_folder_list()
1879 {
1880         for( int i = 0; i < folders.total; i++ ) {
1881                 AssetPicon *picon = (AssetPicon*)folders.values[i];
1882                 picon->in_use = 0;
1883         }
1884
1885 // Search assets for folders
1886         for( int i = 0; i < mwindow->edl->folders.total; i++ ) {
1887                 BinFolder *bin_folder = mwindow->edl->folders[i];
1888                 int exists = 0;
1889
1890                 for( int j = 0; j < folders.total; j++ ) {
1891                         AssetPicon *picon = (AssetPicon*)folders[j];
1892                         if( !strcasecmp(picon->get_text(), bin_folder->title) ) {
1893                                 exists = 1;
1894                                 picon->in_use = 1;
1895                                 break;
1896                         }
1897                 }
1898
1899                 if( !exists ) {
1900                         const char *title = bin_folder->title;
1901                         int folder = bin_folder->awindow_folder;
1902                         AssetPicon *picon = new AssetPicon(mwindow, this, folder, title);
1903                         picon->create_objects();
1904                         folders.append(picon);
1905                 }
1906         }
1907
1908 // Delete unused non-persistent folders
1909         int do_autoplace = 0;
1910         for( int i=folders.total; --i>=0; ) {
1911                 AssetPicon *picon = (AssetPicon*)folders.values[i];
1912                 if( !picon->in_use && !picon->persistent ) {
1913                         delete picon;
1914                         folders.remove_number(i);
1915                         do_autoplace = 1;
1916                 }
1917         }
1918         if( do_autoplace )
1919                 folder_list->set_autoplacement(&folders, 0, 1);
1920 }
1921
1922 void AWindowGUI::create_persistent_folder(ArrayList<BC_ListBoxItem*> *output,
1923         int do_audio, int do_video, int is_realtime, int is_transition)
1924 {
1925         ArrayList<PluginServer*> plugin_list;
1926 // Get pointers to plugindb entries
1927         mwindow->search_plugindb(do_audio, do_video, is_realtime, is_transition,
1928                         0, plugin_list);
1929
1930         for( int i = 0; i < plugin_list.total; i++ ) {
1931                 PluginServer *server = plugin_list.values[i];
1932                 int visible = plugin_visibility & (1<<server->dir_idx);
1933                 if( !visible ) continue;
1934 // Create new listitem
1935                 AssetPicon *picon = new AssetPicon(mwindow, this, server);
1936                 picon->create_objects();
1937                 output->append(picon);
1938         }
1939 }
1940
1941 void AWindowGUI::create_label_folder()
1942 {
1943         Label *current;
1944         for( current = mwindow->edl->labels->first; current; current = NEXT ) {
1945                 AssetPicon *picon = new AssetPicon(mwindow, this, current);
1946                 picon->create_objects();
1947                 labellist.append(picon);
1948         }
1949 }
1950
1951
1952 void AWindowGUI::update_asset_list()
1953 {
1954         ArrayList<AssetPicon *> new_assets;
1955         for( int i = 0; i < assets.total; i++ ) {
1956                 AssetPicon *picon = (AssetPicon*)assets.values[i];
1957                 picon->in_use = 0;
1958         }
1959
1960         mwindow->gui->lock_window("AWindowGUI::update_asset_list");
1961 // Synchronize EDL clips
1962         for( int i=0; i<mwindow->edl->clips.size(); ++i ) {
1963                 int exists = 0;
1964
1965 // Look for clip in existing listitems
1966                 for( int j = 0; j < assets.total && !exists; j++ ) {
1967                         AssetPicon *picon = (AssetPicon*)assets.values[j];
1968
1969                         if( picon->id == mwindow->edl->clips[i]->id ) {
1970                                 picon->edl = mwindow->edl->clips[i];
1971                                 picon->set_text(mwindow->edl->clips[i]->local_session->clip_title);
1972                                 exists = 1;
1973                                 picon->in_use = 1;
1974                         }
1975                 }
1976
1977 // Create new listitem
1978                 if( !exists ) {
1979                         AssetPicon *picon = new AssetPicon(mwindow,
1980                                 this, mwindow->edl->clips[i]);
1981                         new_assets.append(picon);
1982                 }
1983         }
1984
1985 // Synchronize EDL assets
1986         for( Asset *current=mwindow->edl->assets->first; current; current=NEXT ) {
1987                 int exists = 0;
1988
1989 // Look for asset in existing listitems
1990                 for( int j = 0; j < assets.total && !exists; j++ ) {
1991                         AssetPicon *picon = (AssetPicon*)assets.values[j];
1992
1993                         if( picon->id == current->id ) {
1994                                 picon->indexable = current;
1995                                 picon->in_use = 1;
1996                                 exists = 1;
1997                         }
1998                 }
1999
2000 // Create new listitem
2001                 if( !exists ) {
2002                         AssetPicon *picon = new AssetPicon(mwindow,
2003                                 this, current);
2004                         new_assets.append(picon);
2005                 }
2006         }
2007
2008 // Synchronize nested EDLs
2009         for( int i=0; i<mwindow->edl->nested_edls.size(); ++i ) {
2010                 int exists = 0;
2011                 EDL *nested_edl = mwindow->edl->nested_edls[i];
2012
2013 // Look for asset in existing listitems
2014                 for( int j=0; j<assets.total && !exists; ++j ) {
2015                         AssetPicon *picon = (AssetPicon*)assets.values[j];
2016
2017                         if( picon->id == nested_edl->id ) {
2018                                 picon->indexable = nested_edl;
2019                                 picon->in_use = 1;
2020                                 exists = 1;
2021                         }
2022                 }
2023
2024 // Create new listitem
2025                 if( !exists ) {
2026                         AssetPicon *picon = new AssetPicon(mwindow,
2027                                 this, (Indexable*)nested_edl);
2028                         new_assets.append(picon);
2029                 }
2030         }
2031         mwindow->gui->unlock_window();
2032
2033         for( int i=0; i<new_assets.size(); ++i ) {
2034                 AssetPicon *picon = new_assets[i];
2035                 picon->create_objects();
2036                 if( picon->indexable )
2037                         picon->foldernum = AW_MEDIA_FOLDER;
2038                 else if( picon->edl )
2039                         picon->foldernum = AW_CLIP_FOLDER;
2040                 assets.append(picon);
2041         }
2042
2043         mwindow->gui->lock_window();
2044         mwindow->gui->default_message();
2045         mwindow->gui->unlock_window();
2046
2047         for( int i = assets.size() - 1; i >= 0; i-- ) {
2048                 AssetPicon *picon = (AssetPicon*)assets.get(i);
2049                 if( !picon->in_use ) {
2050                         delete picon;
2051                         assets.remove_number(i);
2052                         continue;
2053                 }
2054                 if( picon->indexable && picon->indexable->is_asset ) {
2055                         struct stat st;
2056                         picon->comments_time = !stat(picon->indexable->path, &st) ?
2057                                 st.st_mtime : 0;
2058                 }
2059         }
2060 }
2061
2062 void AWindowGUI::update_picon(Indexable *indexable)
2063 {
2064         VIcon *vicon = 0;
2065         for( int i = 0; i < assets.total; i++ ) {
2066                 AssetPicon *picon = (AssetPicon*)assets.values[i];
2067                 if( picon->indexable == indexable ||
2068                     picon->edl == (EDL *)indexable ) {
2069                         char name[BCTEXTLEN];
2070                         FileSystem fs;
2071                         fs.extract_name(name, indexable->path);
2072                         picon->set_text(name);
2073                         vicon = picon->vicon;
2074                         break;
2075                 }
2076         }
2077         if( vicon ) {
2078                 stop_vicon_drawing();
2079                 vicon->clear_images();
2080                 vicon->reset(indexable->get_frame_rate());
2081                 start_vicon_drawing();
2082         }
2083 }
2084
2085 void AWindowGUI::sort_assets()
2086 {
2087         folder_lock->lock("AWindowGUI::sort_assets");
2088         switch( mwindow->edl->session->awindow_folder ) {
2089         case AW_AEFFECT_FOLDER:
2090                 sort_picons(&aeffects);
2091                 break;
2092         case AW_VEFFECT_FOLDER:
2093                 sort_picons(&veffects);
2094                 break;
2095         case AW_ATRANSITION_FOLDER:
2096                 sort_picons(&atransitions);
2097                 break;
2098         case AW_VTRANSITION_FOLDER:
2099                 sort_picons(&vtransitions);
2100                 break;
2101         case AW_LABEL_FOLDER:
2102                 sort_picons(&labellist);
2103                 break;
2104         default:
2105                 sort_picons(&assets);
2106                 break;
2107         }
2108 // reset xyposition
2109         asset_list->update_format(asset_list->get_format(), 0);
2110         folder_lock->unlock();
2111         update_assets();
2112 }
2113
2114 void AWindowGUI::sort_folders()
2115 {
2116         folder_lock->lock("AWindowGUI::update_assets");
2117 //      folder_list->collapse_recursive(&folders, 0);
2118         folder_list->set_autoplacement(&folders, 0, 1);
2119         sort_picons(&folders);
2120         folder_list->update_format(folder_list->get_format(), 0);
2121         folder_lock->unlock();
2122         update_assets();
2123 }
2124
2125 EDL *AWindowGUI::collect_proxy(Indexable *indexable)
2126 {
2127         Asset *proxy_asset = (Asset *)indexable;
2128         char path[BCTEXTLEN];
2129         int proxy_scale = mwindow->edl->session->proxy_scale;
2130         ProxyRender::from_proxy_path(path, proxy_asset, proxy_scale);
2131         Asset *unproxy_asset = mwindow->edl->assets->get_asset(path);
2132         if( !unproxy_asset || !unproxy_asset->layers ) return 0;
2133 // make a clip from proxy video tracks and unproxy audio tracks
2134         EDL *proxy_edl = new EDL(mwindow->edl);
2135         proxy_edl->create_objects();
2136         proxy_edl->set_path(proxy_asset->path);
2137         FileSystem fs;  fs.extract_name(path, proxy_asset->path);
2138         strcpy(proxy_edl->local_session->clip_title, path);
2139         strcpy(proxy_edl->local_session->clip_notes, _("Proxy clip"));
2140         proxy_edl->session->video_tracks = proxy_asset->layers;
2141         proxy_edl->session->audio_tracks = unproxy_asset->channels;
2142         proxy_edl->create_default_tracks();
2143         double length = proxy_asset->frame_rate > 0 ?
2144                 ( proxy_asset->video_length >= 0 ?
2145                         ( proxy_asset->video_length / proxy_asset->frame_rate ) :
2146                         ( proxy_edl->session->si_useduration ?
2147                                 proxy_edl->session->si_duration :
2148                                 1.0 / proxy_asset->frame_rate ) ) :
2149                 1.0 / proxy_edl->session->frame_rate;
2150         Track *current = proxy_edl->tracks->first;
2151         for( int vtrack=0; current; current=NEXT ) {
2152                 if( current->data_type != TRACK_VIDEO ) continue;
2153                 current->insert_asset(proxy_asset, 0, length, 0, vtrack++);
2154         }
2155         length = (double)unproxy_asset->audio_length / unproxy_asset->sample_rate;
2156         current = proxy_edl->tracks->first;
2157         for( int atrack=0; current; current=NEXT ) {
2158                 if( current->data_type != TRACK_AUDIO ) continue;
2159                 current->insert_asset(unproxy_asset, 0, length, 0, atrack++);
2160         }
2161         proxy_edl->folder_no = AW_PROXY_FOLDER;
2162         return proxy_edl;
2163 }
2164
2165
2166 void AWindowGUI::collect_assets(int proxy)
2167 {
2168         mwindow->session->drag_assets->remove_all();
2169         mwindow->session->drag_clips->remove_all();
2170         int i = 0;  AssetPicon *result;
2171         while( (result = (AssetPicon*)asset_list->get_selection(0, i++)) != 0 ) {
2172                 Indexable *indexable = result->indexable;
2173                 if( proxy && indexable && indexable->is_asset &&
2174                     indexable->folder_no == AW_PROXY_FOLDER ) {
2175                         EDL *drag_edl = collect_proxy(indexable);
2176                         if( drag_edl ) mwindow->session->drag_clips->append(drag_edl);
2177                         continue;
2178                 }
2179                 if( indexable ) {
2180                         mwindow->session->drag_assets->append(indexable);
2181                         continue;
2182                 }
2183                 if( result->edl ) {
2184                         mwindow->session->drag_clips->append(result->edl);
2185                         continue;
2186                 }
2187         }
2188 }
2189
2190 void AWindowGUI::copy_picons(AssetPicon *picon, ArrayList<BC_ListBoxItem*> *src)
2191 {
2192 // Remove current pointers
2193         ArrayList<BC_ListBoxItem*> *dst = displayed_assets;
2194         dst[0].remove_all();
2195         dst[1].remove_all_objects();
2196
2197         AWindowFolderSubItems *sub_items = picon ? picon->sub_items : 0;
2198         int folder = mwindow->edl->session->awindow_folder;
2199         BinFolder *bin_folder = folder < AWINDOW_USER_FOLDERS ? 0 :
2200                 mwindow->edl->get_folder(folder);
2201
2202 // Create new pointers
2203         for( int i = 0; i < src->total; i++ ) {
2204                 int visible = folder >= AW_CLIP_FOLDER ? 0 : 1;
2205                 picon = (AssetPicon*)src->values[i];
2206                 picon->sort_key = -1;
2207                 if( !visible && bin_folder ) {
2208                         Indexable *idxbl = bin_folder->is_clips ? (Indexable *)picon->edl :
2209                             picon->indexable ? picon->indexable :
2210                             picon->edl ? picon->edl->get_proxy_asset() : 0;
2211                         if( idxbl ) {
2212                                 picon->sort_key = mwindow->edl->folders.matches_indexable(folder, idxbl);
2213                                 if( picon->sort_key < 0 ) continue;
2214                                 visible = 1;
2215                         }
2216                 }
2217                 if( !visible && picon->indexable && picon->indexable->folder_no == folder )
2218                         visible = 1;
2219                 if( !visible && picon->edl && picon->edl->folder_no == folder )
2220                         visible = 1;
2221                 if( visible && sub_items ) {
2222                         if( !sub_items->matches(picon->get_text()) )
2223                                 visible = 0;
2224                 }
2225                 if( visible ) {
2226                         const char *text = search_text->get_text();
2227                         if( text && text[0] )
2228                                 visible = bstrcasestr(picon->get_text(), text) ? 1 : 0;
2229                 }
2230                 if( visible && picon->vicon && picon->vicon->hidden )
2231                         picon->vicon->hidden = 0;
2232                 if( visible ) {
2233                         BC_ListBoxItem *item2, *item1;
2234                         dst[0].append(item1 = picon);
2235                         if( picon->edl )
2236                                 dst[1].append(item2 = new BC_ListBoxItem(picon->edl->local_session->clip_notes));
2237                         else
2238                         if( picon->label )
2239                                 dst[1].append(item2 = new BC_ListBoxItem(picon->label->textstr));
2240                         else if( picon->comments_time ) {
2241                                 char date_time[BCSTRLEN];
2242                                 struct tm stm;  localtime_r(&picon->comments_time, &stm);
2243                                 sprintf(date_time,"%04d.%02d.%02d %02d:%02d:%02d",
2244                                          stm.tm_year+1900, stm.tm_mon+1, stm.tm_mday,
2245                                          stm.tm_hour, stm.tm_min, stm.tm_sec);
2246                                 dst[1].append(item2 = new BC_ListBoxItem(date_time));
2247                         }
2248                         else
2249                                 dst[1].append(item2 = new BC_ListBoxItem(""));
2250                         item1->set_autoplace_text(1);  item1->set_autoplace_icon(1);
2251                         item2->set_autoplace_text(1);  item2->set_autoplace_icon(1);
2252                 }
2253         }
2254 }
2255
2256 void AWindowGUI::sort_picons(ArrayList<BC_ListBoxItem*> *src)
2257 {
2258         int done = 0, changed = 0;
2259         while( !done ) {
2260                 done = 1;
2261                 for( int i=0; i<src->total-1; ++i ) {
2262                         AssetPicon *item1 = (AssetPicon *)src->values[i];
2263                         AssetPicon *item2 = (AssetPicon *)src->values[i + 1];
2264                         double v = item2->sort_key - item1->sort_key;
2265                         if( v > 0 ) continue;
2266                         if( v == 0 ) {
2267                                 const char *cp1 = item1->get_text();
2268                                 const char *bp1 = strrchr(cp1, '/');
2269                                 if( bp1 ) cp1 = bp1 + 1;
2270                                 const char *cp2 = item2->get_text();
2271                                 const char *bp2 = strrchr(cp2, '/');
2272                                 if( bp2 ) cp2 = bp2 + 1;
2273                                 if( strcmp(cp2, cp1) >= 0 ) continue;
2274                         }
2275                         src->values[i + 1] = item1;
2276                         src->values[i] = item2;
2277                         done = 0;  changed = 1;
2278                 }
2279         }
2280         if( changed ) {
2281                 for( int i=0; i<src->total; ++i ) {
2282                         AssetPicon *item = (AssetPicon *)src->values[i];
2283                         item->set_autoplace_icon(1);
2284                         item->set_autoplace_text(1);
2285                 }
2286         }
2287 }
2288
2289 void AWindowGUI::filter_displayed_assets()
2290 {
2291         //allow_iconlisting = 1;
2292         asset_titles[0] = C_("Title");
2293         asset_titles[1] = _("Comments");
2294         AssetPicon *picon = 0;
2295         int selected_folder = mwindow->edl->session->awindow_folder;
2296         // Ensure the current folder icon is highlighted
2297         for( int i = 0; i < folders.total; i++ ) {
2298                 AssetPicon *folder_item = (AssetPicon *)folders.values[i];
2299                 int selected = folder_item->foldernum == selected_folder ? 1 : 0;
2300                 folder_item->set_selected(selected);
2301                 if( selected ) picon = folder_item;
2302         }
2303
2304         ArrayList<BC_ListBoxItem*> *src = &assets;
2305         switch( selected_folder ) {
2306         case AW_AEFFECT_FOLDER:  src = &aeffects;  break;
2307         case AW_VEFFECT_FOLDER:  src = &veffects;  break;
2308         case AW_ATRANSITION_FOLDER:  src = &atransitions;  break;
2309         case AW_VTRANSITION_FOLDER:  src = &vtransitions;  break;
2310         case AW_LABEL_FOLDER:  src = &labellist;
2311                 asset_titles[0] = _("Time Stamps");
2312                 asset_titles[1] = C_("Title");
2313                 //allow_iconlisting = 0;
2314                 break;
2315         }
2316         copy_picons(picon, src);
2317 }
2318
2319
2320 void AWindowGUI::update_assets()
2321 {
2322         stop_vicon_drawing();
2323         folder_lock->lock("AWindowGUI::update_assets");
2324         update_folder_list();
2325         update_asset_list();
2326         labellist.remove_all_objects();
2327         create_label_folder();
2328
2329         if( displayed_folder != mwindow->edl->session->awindow_folder )
2330                 search_text->clear();
2331         vicon_thread->hide_vicons();
2332         filter_displayed_assets();
2333         folder_lock->unlock();
2334
2335         if( mwindow->edl->session->folderlist_format != folder_list->get_format() ) {
2336                 folder_list->update_format(mwindow->edl->session->folderlist_format, 0);
2337         }
2338         int folder_xposition = folder_list->get_xposition();
2339         int folder_yposition = folder_list->get_yposition();
2340         folder_list->update(&folders, 0, 0, 1, folder_xposition, folder_yposition, -1);
2341
2342         if( mwindow->edl->session->assetlist_format != asset_list->get_format() ) {
2343                 asset_list->update_format(mwindow->edl->session->assetlist_format, 0);
2344         }
2345         int asset_xposition = asset_list->get_xposition();
2346         int asset_yposition = asset_list->get_yposition();
2347         if( displayed_folder != mwindow->edl->session->awindow_folder ) {
2348                 displayed_folder = mwindow->edl->session->awindow_folder;
2349                 asset_xposition = asset_yposition = 0;
2350         }
2351         asset_list->update(displayed_assets, asset_titles,
2352                 mwindow->edl->session->asset_columns, ASSET_COLUMNS,
2353                 asset_xposition, asset_yposition, -1, 0);
2354         asset_list->center_selection();
2355
2356         flush();
2357         start_vicon_drawing();
2358         return;
2359 }
2360
2361 void AWindowGUI::update_effects()
2362 {
2363         aeffects.remove_all_objects();
2364         create_persistent_folder(&aeffects, 1, 0, 1, 0);
2365         veffects.remove_all_objects();
2366         create_persistent_folder(&veffects, 0, 1, 1, 0);
2367         atransitions.remove_all_objects();
2368         create_persistent_folder(&atransitions, 1, 0, 0, 1);
2369         vtransitions.remove_all_objects();
2370         create_persistent_folder(&vtransitions, 0, 1, 0, 1);
2371 }
2372
2373 int AWindowGUI::drag_motion()
2374 {
2375         if( get_hidden() ) return 0;
2376
2377         int result = 0;
2378         return result;
2379 }
2380
2381 int AWindowGUI::drag_stop()
2382 {
2383         if( get_hidden() ) return 0;
2384         return 0;
2385 }
2386
2387 Indexable* AWindowGUI::selected_asset()
2388 {
2389         AssetPicon *picon = (AssetPicon*)asset_list->get_selection(0, 0);
2390         return picon ? picon->indexable : 0;
2391 }
2392
2393 PluginServer* AWindowGUI::selected_plugin()
2394 {
2395         AssetPicon *picon = (AssetPicon*)asset_list->get_selection(0, 0);
2396         return picon ? picon->plugin : 0;
2397 }
2398
2399 AssetPicon* AWindowGUI::selected_folder()
2400 {
2401         AssetPicon *picon = (AssetPicon*)folder_list->get_selection(0, 0);
2402         return picon;
2403 }
2404
2405
2406
2407
2408
2409
2410
2411
2412 AWindowDivider::AWindowDivider(MWindow *mwindow, AWindowGUI *gui, int x, int y, int w, int h)
2413  : BC_SubWindow(x, y, w, h)
2414 {
2415         this->mwindow = mwindow;
2416         this->gui = gui;
2417 }
2418 AWindowDivider::~AWindowDivider()
2419 {
2420 }
2421
2422 int AWindowDivider::button_press_event()
2423 {
2424         if( is_event_win() && cursor_inside() ) {
2425                 mwindow->session->current_operation = DRAG_PARTITION;
2426                 return 1;
2427         }
2428         return 0;
2429 }
2430
2431 int AWindowDivider::cursor_motion_event()
2432 {
2433         if( mwindow->session->current_operation == DRAG_PARTITION ) {
2434                 int wmin = 25;
2435                 int wmax = mwindow->session->awindow_w - mwindow->theme->adivider_w - wmin;
2436                 int fw = gui->get_relative_cursor_x();
2437                 if( fw > wmax ) fw = wmax;
2438                 if( fw < wmin ) fw = wmin;
2439                 mwindow->session->afolders_w = fw;
2440                 mwindow->theme->get_awindow_sizes(gui);
2441                 gui->reposition_objects();
2442                 gui->flush();
2443         }
2444         return 0;
2445 }
2446
2447 int AWindowDivider::button_release_event()
2448 {
2449         if( mwindow->session->current_operation == DRAG_PARTITION ) {
2450                 mwindow->session->current_operation = NO_OPERATION;
2451                 return 1;
2452         }
2453         return 0;
2454 }
2455
2456
2457
2458
2459
2460
2461 AWindowFolders::AWindowFolders(MWindow *mwindow, AWindowGUI *gui, int x, int y, int w, int h)
2462  : BC_ListBox(x, y, w, h,
2463                 mwindow->edl->session->folderlist_format == FOLDERS_ICONS ?
2464                         LISTBOX_ICONS : LISTBOX_TEXT,
2465                 &gui->folders,    // Each column has an ArrayList of BC_ListBoxItems.
2466                 0,                // Titles for columns.  Set to 0 for no titles
2467                 0,                // width of each column
2468                 1,                // Total columns.
2469                 0,                // Pixel of top of window.
2470                 0,                // If this listbox is a popup window
2471                 LISTBOX_SINGLE,   // Select one item or multiple items
2472                 ICON_TOP,         // Position of icon relative to text of each item
2473                 1)                // Allow drags
2474 {
2475         this->mwindow = mwindow;
2476         this->gui = gui;
2477         set_drag_scroll(0);
2478         last_item0 = 0;
2479         last_item1 = 0;
2480 }
2481
2482 AWindowFolders::~AWindowFolders()
2483 {
2484 }
2485
2486 int AWindowFolders::selection_changed()
2487 {
2488         AWindowFolderItem *item0 = (AWindowFolderItem*)get_selection(0, 0);
2489         AWindowFolderItem *item1 = (AWindowFolderItem*)get_selection(0, 1);
2490 // prefer expanded entry
2491         AWindowFolderItem *item = item1 ? item1 : item0;
2492         if( item0 && item1 && last_item0 == item0 && last_item1 == item1 ) {
2493                 item1->set_selected(0);
2494                 item1 = 0;
2495                 item = item0;
2496         }
2497         last_item0 = item0;
2498         last_item1 = item1;
2499         if( item ) {
2500                 AssetPicon *picon = item->get_picon();
2501                 picon->sub_items = (AWindowFolderSubItems*)(!item->parent ? 0 : item);
2502
2503                 gui->stop_vicon_drawing();
2504
2505                 if( get_button_down() && get_buttonpress() == RIGHT_BUTTON ) {
2506                         gui->folderlist_menu->update_titles();
2507                         gui->folderlist_menu->activate_menu();
2508                 }
2509
2510                 mwindow->edl->session->awindow_folder = picon->foldernum;
2511                 gui->asset_list->draw_background();
2512                 gui->async_update_assets();
2513
2514                 gui->start_vicon_drawing();
2515         }
2516         return 1;
2517 }
2518
2519 int AWindowFolders::button_press_event()
2520 {
2521         int result = BC_ListBox::button_press_event();
2522
2523         if( !result ) {
2524                 if( get_buttonpress() == RIGHT_BUTTON &&
2525                     is_event_win() && cursor_inside() ) {
2526                         gui->folderlist_menu->update_titles();
2527                         gui->folderlist_menu->activate_menu();
2528                         result = 1;
2529                 }
2530         }
2531
2532         return result;
2533 }
2534
2535 int AWindowFolders::drag_stop()
2536 {
2537         int result = 0;
2538         if( get_hidden() ) return 0;
2539         if( mwindow->session->current_operation == DRAG_ASSET &&
2540             gui->folder_list->cursor_above() ) { // check user folder
2541                 int item_no = gui->folder_list->get_cursor_data_item_no();
2542                 AssetPicon *picon = (AssetPicon *)(item_no < 0 ? 0 : gui->folders[item_no]);
2543                 if( picon && picon->foldernum >= AWINDOW_USER_FOLDERS ) {
2544                         BinFolder *folder = mwindow->edl->get_folder(picon->foldernum);
2545                         ArrayList<Indexable *> *drags = folder->is_clips ?
2546                                 ((ArrayList<Indexable *> *)mwindow->session->drag_clips) :
2547                                 ((ArrayList<Indexable *> *)mwindow->session->drag_assets);
2548                         if( folder && drags && !folder->add_patterns(drags, shift_down()) )
2549                                 flicker(1,30);
2550                         mwindow->session->current_operation = ::NO_OPERATION;
2551                         result = 1;
2552                 }
2553         }
2554         return result;
2555 }
2556
2557 AWindowFolderSubItems::AWindowFolderSubItems(AWindowFolderItem *parent, const char *text)
2558  : AWindowFolderItem(text)
2559 {
2560         this->parent = parent;
2561 }
2562
2563 int AWindowFolders::load_expanders()
2564 {
2565         char expanders_path[BCTEXTLEN];
2566         mwindow->create_defaults_path(expanders_path, EXPANDERS_FILE);
2567         FILE *fp = fopen(expanders_path, "r");
2568         if( !fp ) {
2569                 snprintf(expanders_path, sizeof(expanders_path), "%s/%s",
2570                         File::get_cindat_path(), EXPANDERS_FILE);
2571                 fp = fopen(expanders_path, "r");
2572         }
2573
2574         if( !fp ) return 1;
2575         const char tab = '\t';
2576         char line[BCTEXTLEN];   line[0] = 0;
2577         AWindowFolderItem *item = 0, *parent;
2578         AWindowFolderSubItems *sub_items = 0;
2579         int k = 0;
2580         while( fgets(line,sizeof(line),fp) ) {
2581                 if( line[0] == '#' ) continue;
2582                 int i = strlen(line);
2583                 if( i > 0 && line[i-1] == '\n' ) line[--i] = 0;
2584                 if( i == 0 ) continue;
2585                 i = 0;
2586                 for( char *cp=line; *cp==tab; ++cp ) ++i;
2587                 if( i == 0 ) {
2588                         int i = gui->folders.size();
2589                         while( --i >= 0 ) {
2590                                 AssetPicon *folder = (AssetPicon *)gui->folders[i];
2591                                 if( !strcmp(folder->get_text(),_(line)) ) break;
2592                         }
2593                         item = (AWindowFolderItem*)(i >= 0 ? gui->folders[i] : 0);
2594                         sub_items = 0;
2595                         k = 0;
2596                         continue;
2597                 }
2598                 if( i > k+1 ) continue;
2599                 if( i == k+1 ) {
2600                         if( line[i] != '-' && sub_items ) {
2601                                 sub_items->names.append(cstrdup(_(&line[i])));
2602                                 continue;
2603                         }
2604                         parent = item;
2605                         k = i;
2606                 }
2607                 else {
2608                         while( i < k ) {
2609                                 item = item->parent;
2610                                 --k;
2611                         }
2612                         parent = item->parent;
2613                 }
2614                 ArrayList<BC_ListBoxItem*> *sublist = parent->get_sublist();
2615                 if( !sublist ) sublist = parent->new_sublist(1);
2616                 sub_items = new AWindowFolderSubItems(parent, &line[i]);
2617                 sublist->append(item = sub_items);
2618         }
2619         fclose(fp);
2620         return 0;
2621 }
2622
2623
2624 AWindowAssets::AWindowAssets(MWindow *mwindow, AWindowGUI *gui, int x, int y, int w, int h)
2625  : BC_ListBox(x, y, w, h, !gui->allow_iconlisting ? LISTBOX_TEXT :
2626                 mwindow->edl->session->assetlist_format == ASSETS_ICONS ? LISTBOX_ICONS :
2627                 mwindow->edl->session->assetlist_format == ASSETS_ICONS_PACKED ? LISTBOX_ICONS_PACKED :
2628                 mwindow->edl->session->assetlist_format == ASSETS_ICON_LIST ? LISTBOX_ICON_LIST :
2629                         LISTBOX_TEXT,
2630                 &gui->assets,     // Each column has an ArrayList of BC_ListBoxItems.
2631                 gui->asset_titles,// Titles for columns.  Set to 0 for no titles
2632                 mwindow->edl->session->asset_columns, // width of each column
2633                 1,                // Total columns.
2634                 0,                // Pixel of top of window.
2635                 0,                // If this listbox is a popup window
2636                 LISTBOX_MULTIPLE, // Select one item or multiple items
2637                 ICON_TOP,         // Position of icon relative to text of each item
2638                 -1)               // Allow drags, require shift for scrolling
2639 {
2640         this->mwindow = mwindow;
2641         this->gui = gui;
2642         set_drag_scroll(0);
2643         set_scroll_stretch(1, 1);
2644 }
2645
2646 AWindowAssets::~AWindowAssets()
2647 {
2648 }
2649
2650 int AWindowAssets::button_press_event()
2651 {
2652         AssetVIconThread *avt = gui->vicon_thread;
2653         if( avt->draw_mode != ASSET_VIEW_NONE && is_event_win() ) {
2654                 int dir = 1, button = get_buttonpress();
2655                 switch( button ) {
2656                 case WHEEL_DOWN: dir = -1;  // fall thru
2657                 case WHEEL_UP: {
2658                         int x = get_cursor_x(), y = get_cursor_y();
2659                         if( avt->cursor_inside(x, y) && avt->view_win )
2660                                 avt->zoom_scale(dir);
2661                         return 1; }
2662                 }
2663         }
2664
2665         int result = BC_ListBox::button_press_event();
2666
2667         if( !result && get_buttonpress() == RIGHT_BUTTON &&
2668             is_event_win() && cursor_inside() ) {
2669                 BC_ListBox::deactivate_selection();
2670                 int folder = mwindow->edl->session->awindow_folder;
2671                 switch( folder ) {
2672                 case AW_AEFFECT_FOLDER:
2673                 case AW_VEFFECT_FOLDER:
2674                 case AW_ATRANSITION_FOLDER:
2675                 case AW_VTRANSITION_FOLDER:
2676                         gui->effectlist_menu->update();
2677                         gui->effectlist_menu->activate_menu();
2678                         break;
2679                 case AW_LABEL_FOLDER:
2680                         gui->labellist_menu->update();
2681                         gui->labellist_menu->activate_menu();
2682                         break;
2683                 case AW_CLIP_FOLDER:
2684                         gui->cliplist_menu->update();
2685                         gui->cliplist_menu->activate_menu();
2686                         break;
2687                 case AW_PROXY_FOLDER:
2688                         gui->proxylist_menu->update();
2689                         gui->proxylist_menu->activate_menu();
2690                         break;
2691                 default:
2692                 case AW_MEDIA_FOLDER: {
2693                         int shots =  folder==AW_MEDIA_FOLDER || folder>=AWINDOW_USER_FOLDERS;
2694                         gui->assetlist_menu->update_titles(shots);
2695                         gui->assetlist_menu->activate_menu();
2696                         break; }
2697                 }
2698                 result = 1;
2699         }
2700
2701         return result;
2702 }
2703
2704
2705 int AWindowAssets::handle_event()
2706 {
2707         AssetPicon *asset_picon = (AssetPicon *)get_selection(0, 0);
2708         if( !asset_picon ) return 0;
2709         Indexable *picon_idxbl = asset_picon->indexable;
2710         EDL *picon_edl = asset_picon->edl;
2711         int proxy = 0;
2712         VWindow *vwindow = 0;
2713         switch( mwindow->edl->session->awindow_folder ) {
2714         case AW_AEFFECT_FOLDER:
2715         case AW_VEFFECT_FOLDER:
2716         case AW_ATRANSITION_FOLDER:
2717         case AW_VTRANSITION_FOLDER: return 1;
2718         case AW_PROXY_FOLDER:
2719                 proxy = 1; // fall thru
2720         default:
2721                 if( mwindow->vwindows.size() > DEFAULT_VWINDOW )
2722                         vwindow = mwindow->vwindows.get(DEFAULT_VWINDOW);
2723                 break;
2724         }
2725         if( !vwindow || !vwindow->is_running() ) return 1;
2726         if( proxy && picon_idxbl ) {
2727                 picon_edl = gui->collect_proxy(picon_idxbl);
2728                 picon_idxbl = 0;
2729         }
2730
2731         if( picon_idxbl ) vwindow->change_source(picon_idxbl);
2732         else if( picon_edl ) vwindow->change_source(picon_edl);
2733         return 1;
2734 }
2735
2736 int AWindowAssets::selection_changed()
2737 {
2738 // Show popup window
2739         AssetPicon *item;
2740         int folder = mwindow->edl->session->awindow_folder;
2741         if( get_button_down() && get_buttonpress() == RIGHT_BUTTON &&
2742             (item = (AssetPicon*)get_selection(0, 0)) ) {
2743                 switch( folder ) {
2744                 case AW_AEFFECT_FOLDER:
2745                 case AW_VEFFECT_FOLDER:
2746                 case AW_ATRANSITION_FOLDER:
2747                 case AW_VTRANSITION_FOLDER:
2748                         gui->effectlist_menu->update();
2749                         gui->effectlist_menu->activate_menu();
2750                         break;
2751                 case AW_LABEL_FOLDER:
2752                         if( !item->label ) break;
2753                         gui->label_menu->activate_menu();
2754                         break;
2755                 case AW_CLIP_FOLDER:
2756                         if( !item->indexable && !item->edl ) break;
2757                         gui->clip_menu->update();
2758                         gui->clip_menu->activate_menu();
2759                         break;
2760                 case AW_PROXY_FOLDER:
2761                         if( !item->indexable && !item->edl ) break;
2762                         gui->proxy_menu->update();
2763                         gui->proxy_menu->activate_menu();
2764                         break;
2765                 default:
2766                         if( !item->indexable && !item->edl ) break;
2767                         gui->asset_menu->update();
2768                         gui->asset_menu->activate_menu();
2769                         break;
2770                 }
2771
2772                 deactivate_selection();
2773         }
2774         else if( get_button_down() ) {
2775                 if( (item = (AssetPicon*)get_selection(0, 0)) != 0 ) {
2776                         switch( folder ) {
2777                         case AW_MEDIA_FOLDER:
2778                         case AW_PROXY_FOLDER:
2779                         case AWINDOW_USER_FOLDERS:
2780                                 if( get_buttonpress() == LEFT_BUTTON ||
2781                                     get_buttonpress() == MIDDLE_BUTTON ) {
2782                                         AssetVIcon *vicon = 0;
2783                                         AssetVIconThread *avt = gui->vicon_thread;
2784                                         if( !avt->vicon && gui->vicon_drawing != AVICON_NO_PLAY )
2785                                                 vicon = item->vicon;
2786                                         int draw_mode = !vicon ?
2787                                                         ASSET_VIEW_NONE :
2788                                                 get_buttonpress() == MIDDLE_BUTTON ?
2789                                                         ASSET_VIEW_MEDIA_MAP : ASSET_VIEW_MEDIA;
2790                                         avt->set_view_popup(vicon, draw_mode);
2791                                 }
2792                                 break;
2793                         case AW_CLIP_FOLDER:
2794                                 if( get_buttonpress() == LEFT_BUTTON ) {
2795                                         AssetVIcon *vicon = 0;
2796                                         if( !gui->vicon_thread->vicon )
2797                                                 vicon = item->vicon;
2798                                         gui->vicon_thread->set_view_popup(vicon, ASSET_VIEW_ICON);
2799                                 }
2800                                 break;
2801                         }
2802                 }
2803                 else {
2804                         gui->vicon_thread->set_view_popup(0);
2805                         if( gui->vicon_drawing != AVICON_FULL_PLAY )
2806                                 gui->stop_vicon_drawing();
2807                 }
2808         }
2809         return 1;
2810 }
2811
2812 void AWindowAssets::draw_background()
2813 {
2814         clear_box(0,0,get_w(),get_h(),get_bg_surface());
2815         set_color(BC_WindowBase::get_resources()->audiovideo_color);
2816         set_font(LARGEFONT);
2817         int folder = mwindow->edl->session->awindow_folder;
2818         const char *title = mwindow->edl->get_folder_name(folder);
2819         draw_text(get_w() - get_text_width(LARGEFONT, title) - 4, 30,
2820                 title, -1, get_bg_surface());
2821 }
2822
2823 int AWindowAssets::drag_start_event()
2824 {
2825         int collect_pluginservers = 0;
2826         int collect_assets = 0, proxy = 0;
2827
2828         if( BC_ListBox::drag_start_event() ) {
2829                 switch( mwindow->edl->session->awindow_folder ) {
2830                 case AW_AEFFECT_FOLDER:
2831                         mwindow->session->current_operation = DRAG_AEFFECT;
2832                         collect_pluginservers = 1;
2833                         break;
2834                 case AW_VEFFECT_FOLDER:
2835                         mwindow->session->current_operation = DRAG_VEFFECT;
2836                         collect_pluginservers = 1;
2837                         break;
2838                 case AW_ATRANSITION_FOLDER:
2839                         mwindow->session->current_operation = DRAG_ATRANSITION;
2840                         collect_pluginservers = 1;
2841                         break;
2842                 case AW_VTRANSITION_FOLDER:
2843                         mwindow->session->current_operation = DRAG_VTRANSITION;
2844                         collect_pluginservers = 1;
2845                         break;
2846                 case AW_LABEL_FOLDER:
2847                         // do nothing!
2848                         break;
2849                 case AW_PROXY_FOLDER:
2850                         proxy = 1; // fall thru
2851                 case AW_MEDIA_FOLDER:
2852                 default:
2853                         mwindow->session->current_operation = DRAG_ASSET;
2854                         collect_assets = 1;
2855                         break;
2856                 }
2857
2858                 if( collect_pluginservers ) {
2859                         int i = 0;
2860                         mwindow->session->drag_pluginservers->remove_all();
2861                         while(1)
2862                         {
2863                                 AssetPicon *result = (AssetPicon*)get_selection(0, i++);
2864                                 if( !result ) break;
2865
2866                                 mwindow->session->drag_pluginservers->append(result->plugin);
2867                         }
2868                 }
2869
2870                 if( collect_assets ) {
2871                         gui->collect_assets(proxy);
2872                 }
2873
2874                 return 1;
2875         }
2876         return 0;
2877 }
2878
2879 int AWindowAssets::drag_motion_event()
2880 {
2881         BC_ListBox::drag_motion_event();
2882         unlock_window();
2883
2884         mwindow->gui->lock_window("AWindowAssets::drag_motion_event");
2885         mwindow->gui->drag_motion();
2886         mwindow->gui->unlock_window();
2887
2888         for( int i = 0; i < mwindow->vwindows.size(); i++ ) {
2889                 VWindow *vwindow = mwindow->vwindows.get(i);
2890                 if( !vwindow->is_running() ) continue;
2891                 vwindow->gui->lock_window("AWindowAssets::drag_motion_event");
2892                 vwindow->gui->drag_motion();
2893                 vwindow->gui->unlock_window();
2894         }
2895
2896         mwindow->cwindow->gui->lock_window("AWindowAssets::drag_motion_event");
2897         mwindow->cwindow->gui->drag_motion();
2898         mwindow->cwindow->gui->unlock_window();
2899
2900         lock_window("AWindowAssets::drag_motion_event");
2901         if( mwindow->session->current_operation == DRAG_ASSET &&
2902             gui->folder_list->cursor_above() ) { // highlight user folder
2903                 BC_ListBoxItem *item = 0;
2904                 int item_no = gui->folder_list->get_cursor_data_item_no(&item);
2905                 if( item_no >= 0 ) {
2906                         AssetPicon *folder = (AssetPicon *)gui->folders[item_no];
2907                         if( folder->foldernum < AWINDOW_USER_FOLDERS ) item_no = -1;
2908                 }
2909                 if( item_no >= 0 )
2910                         item_no = gui->folder_list->item_to_index(&gui->folders, item);
2911                 int folder_xposition = gui->folder_list->get_xposition();
2912                 int folder_yposition = gui->folder_list->get_yposition();
2913                 gui->folder_list->update(&gui->folders, 0, 0, 1,
2914                         folder_xposition, folder_yposition, item_no, 0, 1);
2915         }
2916         return 0;
2917 }
2918
2919 int AWindowAssets::drag_stop_event()
2920 {
2921         int result = 0;
2922
2923         result = gui->drag_stop();
2924
2925         unlock_window();
2926
2927         if( !result ) {
2928                 mwindow->gui->lock_window("AWindowAssets::drag_stop_event");
2929                 result = mwindow->gui->drag_stop();
2930                 mwindow->gui->unlock_window();
2931         }
2932
2933         if( !result ) {
2934                 for( int i = 0; !result && i < mwindow->vwindows.size(); i++ ) {
2935                         VWindow *vwindow = mwindow->vwindows.get(i);
2936                         if( !vwindow ) continue;
2937                 &