add grabshot, move snapshot, asset update mtime, plugins.txt for ffmpeg 3.4.1
[goodguy/history.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 "asset.h"
23 #include "assetedit.h"
24 #include "assetpopup.h"
25 #include "assets.h"
26 #include "awindowgui.h"
27 #include "awindow.h"
28 #include "bccmodels.h"
29 #include "bcsignals.h"
30 #include "bchash.h"
31 #include "cache.h"
32 #include "cstrdup.h"
33 #include "clip.h"
34 #include "clippopup.h"
35 #include "cursors.h"
36 #include "cwindowgui.h"
37 #include "cwindow.h"
38 #include "edl.h"
39 #include "edlsession.h"
40 #include "effectlist.h"
41 #include "file.h"
42 #include "filesystem.h"
43 #include "folderlistmenu.h"
44 #include "indexable.h"
45 #include "keys.h"
46 #include "language.h"
47 #include "labels.h"
48 #include "labelpopup.h"
49 #include "localsession.h"
50 #include "mainmenu.h"
51 #include "mainsession.h"
52 #include "mwindowgui.h"
53 #include "mwindow.h"
54 #include "nestededls.h"
55 #include "newfolder.h"
56 #include "preferences.h"
57 #include "theme.h"
58 #include "vframe.h"
59 #include "vicon.h"
60 #include "vwindowgui.h"
61 #include "vwindow.h"
62
63 #include "data/lad_picon_png.h"
64 #include "data/ff_audio_png.h"
65 #include "data/ff_video_png.h"
66
67 #include<stdio.h>
68 #include<unistd.h>
69 #include<fcntl.h>
70
71
72 const char *AWindowGUI::folder_names[] =
73 {
74         N_("Audio Effects"),
75         N_("Video Effects"),
76         N_("Audio Transitions"),
77         N_("Video Transitions"),
78         N_("Labels"),
79         N_("Clips"),
80         N_("Media"),
81         N_("Proxy"),
82 };
83
84
85 AssetVIcon::AssetVIcon(AssetPicon *picon, int w, int h, double framerate, int64_t length)
86  : VIcon(w, h, framerate)
87 {
88         this->picon = picon;
89         this->length = length;
90         temp = 0;
91 }
92
93 AssetVIcon::~AssetVIcon()
94 {
95         delete temp;
96 }
97
98 VFrame *AssetVIcon::frame()
99 {
100         if( seq_no >= images.size() ) {
101                 MWindow *mwindow = picon->mwindow;
102                 Asset *asset = (Asset *)picon->indexable;
103                 File *file = mwindow->video_cache->check_out(asset, mwindow->edl, 1);
104                 if( !file ) return 0;
105                 if( temp && (temp->get_w() != asset->width || temp->get_h() != asset->height) ) {
106                         delete temp;  temp = 0;
107                 }
108                 if( !temp )
109                         temp = new VFrame(0, -1, asset->width, asset->height, BC_RGB888, -1);
110                 int ww = picon->gui->vicon_thread->view_w;
111                 int hh = picon->gui->vicon_thread->view_h;
112                 while( seq_no >= images.size() ) {
113                         file->set_layer(0);
114                         int64_t pos = images.size() / picon->gui->vicon_thread->refresh_rate * frame_rate;
115                         file->set_video_position(pos,0);
116                         if( file->read_frame(temp) ) temp->clear_frame();
117                         add_image(temp, ww, hh, BC_RGB8);
118                 }
119                 mwindow->video_cache->check_in(asset);
120         }
121         return *images[seq_no];
122 }
123
124 int64_t AssetVIcon::set_seq_no(int64_t no)
125 {
126         if( no >= length ) no = 0;
127         return seq_no = no;
128 }
129
130 int AssetVIcon::get_vx()
131 {
132         BC_ListBox *lbox = picon->gui->asset_list;
133         return lbox->get_item_x(picon);
134 }
135 int AssetVIcon::get_vy()
136 {
137         BC_ListBox *lbox = picon->gui->asset_list;
138         return lbox->get_item_y(picon) + lbox->get_title_h();
139 }
140
141
142 AssetPicon::AssetPicon(MWindow *mwindow,
143         AWindowGUI *gui, Indexable *indexable)
144  : BC_ListBoxItem()
145 {
146         reset();
147         this->mwindow = mwindow;
148         this->gui = gui;
149         this->indexable = indexable;
150         indexable->add_user();
151         this->id = indexable->id;
152 }
153
154 AssetPicon::AssetPicon(MWindow *mwindow,
155         AWindowGUI *gui, EDL *edl)
156  : BC_ListBoxItem()
157 {
158         reset();
159         this->mwindow = mwindow;
160         this->gui = gui;
161         this->edl = edl;
162         edl->add_user();
163         this->id = edl->id;
164 }
165
166 AssetPicon::AssetPicon(MWindow *mwindow,
167         AWindowGUI *gui, int folder, int persist)
168  : BC_ListBoxItem(_(AWindowGUI::folder_names[folder]),
169         folder>=0 && folder<AWINDOW_FOLDERS ?
170                 gui->folder_icons[folder]: gui->folder_icon)
171 {
172         reset();
173         foldernum = folder;
174         this->mwindow = mwindow;
175         this->gui = gui;
176         persistent = persist;
177 }
178
179 AssetPicon::AssetPicon(MWindow *mwindow,
180         AWindowGUI *gui, PluginServer *plugin)
181  : BC_ListBoxItem()
182 {
183         reset();
184         this->mwindow = mwindow;
185         this->gui = gui;
186         this->plugin = plugin;
187 }
188
189 AssetPicon::AssetPicon(MWindow *mwindow,
190         AWindowGUI *gui, Label *label)
191  : BC_ListBoxItem()
192 {
193         reset();
194         this->mwindow = mwindow;
195         this->gui = gui;
196         this->label = label;
197         indexable = 0;
198         icon = 0;
199         id = 0;
200 }
201
202 AssetPicon::~AssetPicon()
203 {
204         if( vicon )
205                 gui->vicon_thread->del_vicon(vicon);
206         if( indexable ) indexable->remove_user();
207         if( edl ) edl->remove_user();
208         if( icon && !gui->protected_pixmap(icon) ) {
209                 delete icon;
210                 if( !plugin ) delete icon_vframe;
211         }
212 }
213
214 void AssetPicon::reset()
215 {
216         plugin = 0;
217         label = 0;
218         indexable = 0;
219         edl = 0;
220         foldernum = AW_NO_FOLDER;
221         icon = 0;
222         icon_vframe = 0;
223         vicon = 0;
224         in_use = 1;
225         mtime = 0;
226         id = 0;
227         persistent = 0;
228 }
229
230 void AssetPicon::create_objects()
231 {
232         FileSystem fs;
233         char name[BCTEXTLEN];
234         int pixmap_w, pixmap_h;
235
236         pixmap_h = 50 * BC_WindowBase::get_resources()->icon_scale;
237
238         if( indexable ) {
239                 fs.extract_name(name, indexable->path);
240                 set_text(name);
241         }
242
243         if( indexable && indexable->is_asset ) {
244                 Asset *asset = (Asset*)indexable;
245                 if( asset->video_data ) {
246                         if( mwindow->preferences->use_thumbnails ) {
247                                 gui->unlock_window();
248                                 File *file = mwindow->video_cache->check_out(asset,
249                                         mwindow->edl,
250                                         1);
251
252                                 if( file ) {
253                                         int height = asset->height > 0 ? asset->height : 1;
254                                         pixmap_w = pixmap_h * asset->width / height;
255
256                                         file->set_layer(0);
257                                         file->set_video_position(0, 0);
258
259                                         if( gui->temp_picon &&
260                                                 (gui->temp_picon->get_w() != asset->width ||
261                                                 gui->temp_picon->get_h() != asset->height) ) {
262                                                 delete gui->temp_picon;
263                                                 gui->temp_picon = 0;
264                                         }
265
266                                         if( !gui->temp_picon ) {
267                                                 gui->temp_picon = new VFrame(0, -1,
268                                                         asset->width, asset->height,
269                                                         BC_RGB888, -1);
270                                         }
271                                         { char string[BCTEXTLEN];
272                                         sprintf(string, _("Reading %s"), name);
273                                         mwindow->gui->lock_window("AssetPicon::create_objects");
274                                         mwindow->gui->show_message(string);
275                                         mwindow->gui->unlock_window(); }
276                                         file->read_frame(gui->temp_picon);
277                                         mwindow->video_cache->check_in(asset);
278
279                                         gui->lock_window("AssetPicon::create_objects 1");
280                                         icon = new BC_Pixmap(gui, pixmap_w, pixmap_h);
281                                         icon->draw_vframe(gui->temp_picon,
282                                                 0, 0, pixmap_w, pixmap_h, 0, 0);
283                                         icon_vframe = new VFrame(0,
284                                                 -1, pixmap_w, pixmap_h, BC_RGB888, -1);
285                                         icon_vframe->transfer_from(gui->temp_picon);
286                                         if( asset->awindow_folder == AW_MEDIA_FOLDER ) {
287 // vicon images
288                                                 double framerate = asset->get_frame_rate();
289                                                 if( !framerate ) framerate = VICON_RATE;
290                                                 int64_t frames = asset->get_video_frames();
291                                                 double secs = frames / framerate;
292                                                 if( secs > 5 ) secs = 5;
293                                                 int64_t length = secs * gui->vicon_thread->refresh_rate;
294                                                 vicon = new AssetVIcon(this, pixmap_w, pixmap_h, framerate, length);
295                                                 gui->vicon_thread->add_vicon(vicon);
296                                         }
297
298                                 }
299                                 else {
300                                         gui->lock_window("AssetPicon::create_objects 2");
301                                         icon = gui->video_icon;
302                                         icon_vframe = gui->video_vframe;
303                                 }
304                         }
305                         else {
306                                 icon = gui->video_icon;
307                                 icon_vframe = gui->video_vframe;
308                         }
309                 }
310                 else
311                 if( asset->audio_data ) {
312                         icon = gui->audio_icon;
313                         icon_vframe = gui->audio_vframe;
314                 }
315                 struct stat st;
316                 mtime = !stat(asset->path, &st) ? st.st_mtime : 0;
317         }
318         else
319         if( indexable && !indexable->is_asset ) {
320                 icon = gui->video_icon;
321                 icon_vframe = gui->video_vframe;
322         }
323         else
324         if( edl ) {
325                 set_text(strcpy(name, edl->local_session->clip_title));
326                 icon = gui->clip_icon;
327                 icon_vframe = gui->clip_vframe;
328         }
329         else
330         if( plugin ) {
331                 strcpy(name,  plugin->title);
332                 set_text(name);
333                 icon_vframe = plugin->get_picon();
334                 if( icon_vframe )
335                         icon = gui->create_pixmap(icon_vframe);
336                 else if( plugin->audio ) {
337                         if( plugin->transition ) {
338                                 icon = gui->atransition_icon;
339                                 icon_vframe = gui->atransition_vframe;
340                         }
341                         else if( plugin->is_ffmpeg() ) {
342                                 icon = gui->ff_aud_icon;
343                                 icon_vframe = gui->ff_aud_vframe;
344                         }
345                         else if( plugin->is_ladspa() ) {
346                                 icon = gui->ladspa_icon;
347                                 icon_vframe = gui->ladspa_vframe;
348                         }
349                         else {
350                                 icon = gui->aeffect_icon;
351                                 icon_vframe = gui->aeffect_vframe;
352                         }
353                 }
354                 else if( plugin->video ) {
355                         if( plugin->transition ) {
356                                 icon = gui->vtransition_icon;
357                                 icon_vframe = gui->vtransition_vframe;
358                         }
359                         else if( plugin->is_ffmpeg() ) {
360                                 icon = gui->ff_vid_icon;
361                                 icon_vframe = gui->ff_vid_vframe;
362                         }
363                         else {
364                                 icon = gui->veffect_icon;
365                                 icon_vframe = gui->veffect_vframe;
366                         }
367                 }
368         }
369         else
370         if( label ) {
371                 Units::totext(name,
372                               label->position,
373                               mwindow->edl->session->time_format,
374                               mwindow->edl->session->sample_rate,
375                               mwindow->edl->session->frame_rate,
376                               mwindow->edl->session->frames_per_foot);
377                 set_text(name);
378                 icon = gui->label_icon;
379                 icon_vframe = gui->label_vframe;
380         }
381         if( !icon ) {
382                 icon = gui->file_icon;
383                 icon_vframe = BC_WindowBase::get_resources()->type_to_icon[ICON_UNKNOWN];
384         }
385         set_icon(icon);
386         set_icon_vframe(icon_vframe);
387 }
388
389 AWindowGUI::AWindowGUI(MWindow *mwindow, AWindow *awindow)
390  : BC_Window(_(PROGRAM_NAME ": Resources"),
391         mwindow->session->awindow_x, mwindow->session->awindow_y,
392         mwindow->session->awindow_w, mwindow->session->awindow_h,
393         100, 100, 1, 1, 1)
394 {
395         this->mwindow = mwindow;
396         this->awindow = awindow;
397
398         file_vframe = 0;                file_icon = 0;
399         folder_vframe = 0;              folder_icon = 0;
400         audio_vframe = 0;               audio_icon = 0;
401         video_vframe = 0;               video_icon = 0;
402         label_vframe = 0;               label_icon = 0;
403
404         atransition_vframe = 0;         atransition_icon = 0;
405         vtransition_vframe = 0;         vtransition_icon = 0;
406         aeffect_vframe = 0;             aeffect_icon = 0;
407         ladspa_vframe = 0;              ladspa_icon = 0;
408         veffect_vframe = 0;             veffect_icon = 0;
409         ff_aud_vframe = 0;              ff_aud_icon = 0;
410         ff_vid_vframe = 0;              ff_vid_icon = 0;
411
412         aeffect_folder_vframe = 0;      aeffect_folder_icon = 0;
413         atransition_folder_vframe = 0;  atransition_folder_icon = 0;
414         clip_folder_vframe = 0;         clip_folder_icon = 0;
415         label_folder_vframe = 0;        label_folder_icon = 0;
416         media_folder_vframe = 0;        media_folder_icon = 0;
417         proxy_folder_vframe = 0;        proxy_folder_icon = 0;
418         veffect_folder_vframe = 0;      veffect_folder_icon = 0;
419         vtransition_folder_vframe = 0;  vtransition_folder_icon = 0;
420
421         ladspa_vframe = 0;              ladspa_icon = 0;
422         ff_aud_vframe = 0;              ff_aud_icon = 0;
423         ff_vid_vframe = 0;              ff_vid_icon = 0;
424
425         clip_vframe = 0;                clip_icon = 0;
426         atransition_vframe = 0;         atransition_icon = 0;
427         vtransition_vframe = 0;         vtransition_icon = 0;
428         aeffect_vframe = 0;             aeffect_icon = 0;
429         veffect_vframe = 0;             veffect_icon = 0;
430
431         plugin_visibility = ((uint64_t)1<<(8*sizeof(uint64_t)-1))-1;
432         newfolder_thread = 0;
433         asset_menu = 0;
434         effectlist_menu = 0;
435         assetlist_menu = 0;
436         cliplist_menu = 0;
437         labellist_menu = 0;
438         folderlist_menu = 0;
439         temp_picon = 0;
440         search_text = 0;
441         allow_iconlisting = 1;
442         remove_plugin = 0;
443         vicon_thread = 0;
444         vicon_drawing = 1;
445         displayed_folder = AW_NO_FOLDER;
446 }
447
448 AWindowGUI::~AWindowGUI()
449 {
450         assets.remove_all_objects();
451         folders.remove_all_objects();
452         aeffects.remove_all_objects();
453         veffects.remove_all_objects();
454         atransitions.remove_all_objects();
455         vtransitions.remove_all_objects();
456         labellist.remove_all_objects();
457         displayed_assets[1].remove_all_objects();
458
459         delete vicon_thread;
460         delete newfolder_thread;
461
462         delete asset_menu;
463         delete clip_menu;
464         delete label_menu;
465         delete effectlist_menu;
466         delete assetlist_menu;
467         delete cliplist_menu;
468         delete labellist_menu;
469         delete folderlist_menu;
470         delete search_text;
471         delete temp_picon;
472         delete remove_plugin;
473
474         delete file_vframe;             delete file_icon;
475         delete folder_vframe;           delete folder_icon;
476         delete audio_vframe;            delete audio_icon;
477         delete video_vframe;            delete video_icon;
478         delete label_vframe;            delete label_icon;
479         delete clip_vframe;             delete clip_icon;
480         delete aeffect_folder_vframe;   delete aeffect_folder_icon;
481         delete atransition_folder_vframe; delete atransition_folder_icon;
482         delete veffect_folder_vframe;   delete veffect_folder_icon;
483         delete vtransition_folder_vframe; delete vtransition_folder_icon;
484         delete clip_folder_vframe;      delete clip_folder_icon;
485         delete label_folder_vframe;     delete label_folder_icon;
486         delete media_folder_vframe;     delete media_folder_icon;
487         delete proxy_folder_vframe;     delete proxy_folder_icon;
488         delete ladspa_vframe;           delete ladspa_icon;
489         delete ff_aud_vframe;           delete ff_aud_icon;
490         delete ff_vid_vframe;           delete ff_vid_icon;
491         delete atransition_vframe;      delete atransition_icon;
492         delete vtransition_vframe;      delete vtransition_icon;
493         delete aeffect_vframe;          delete aeffect_icon;
494         delete veffect_vframe;          delete veffect_icon;
495 }
496
497 bool AWindowGUI::protected_pixmap(BC_Pixmap *icon)
498 {
499         return  icon == file_icon ||
500                 icon == folder_icon ||
501                 icon == audio_icon ||
502                 icon == video_icon ||
503                 icon == clip_icon ||
504                 icon == label_icon ||
505                 icon == vtransition_icon ||
506                 icon == atransition_icon ||
507                 icon == veffect_icon ||
508                 icon == aeffect_icon ||
509                 icon == ladspa_icon ||
510                 icon == ff_aud_icon ||
511                 icon == ff_vid_icon ||
512                 icon == aeffect_folder_icon ||
513                 icon == veffect_folder_icon ||
514                 icon == atransition_folder_icon ||
515                 icon == vtransition_folder_icon ||
516                 icon == label_folder_icon ||
517                 icon == clip_folder_icon ||
518                 icon == media_folder_icon ||
519                 icon == proxy_folder_icon;
520 }
521
522 VFrame *AWindowGUI::get_picon(const char *name, const char *plugin_icons)
523 {
524         char png_path[BCTEXTLEN];
525         char *pp = png_path, *ep = pp + sizeof(png_path)-1;
526         snprintf(pp, ep-pp, "%s/picon/%s/%s.png",
527                 File::get_plugin_path(), plugin_icons, name);
528         if( access(png_path, R_OK) ) return 0;
529         return VFramePng::vframe_png(png_path,0,0);
530 }
531
532 VFrame *AWindowGUI::get_picon(const char *name)
533 {
534         VFrame *vframe = get_picon(name, mwindow->preferences->plugin_icons);
535         if( !vframe ) {
536                 char png_name[BCSTRLEN], *pp = png_name, *ep = pp + sizeof(png_name)-1;
537                 snprintf(pp, ep-pp, "%s.png", name);
538                 unsigned char *data = mwindow->theme->get_image_data(png_name);
539                 if( data ) vframe = new VFramePng(data, 0.);
540         }
541         return vframe;
542 }
543
544 void AWindowGUI::resource_icon(VFrame *&vfrm, BC_Pixmap *&icon, const char *fn, int idx)
545 {
546         vfrm = get_picon(fn);
547         if( !vfrm ) vfrm = BC_WindowBase::get_resources()->type_to_icon[idx];
548         icon = new BC_Pixmap(this, vfrm, PIXMAP_ALPHA);
549 }
550 void AWindowGUI::theme_icon(VFrame *&vfrm, BC_Pixmap *&icon, const char *fn)
551 {
552         vfrm = get_picon(fn);
553         if( !vfrm ) vfrm = mwindow->theme->get_image(fn);
554         icon = new BC_Pixmap(this, vfrm, PIXMAP_ALPHA);
555 }
556 void AWindowGUI::plugin_icon(VFrame *&vfrm, BC_Pixmap *&icon, const char *fn, unsigned char *png)
557 {
558         vfrm = get_picon(fn);
559         if( !vfrm ) vfrm = new VFramePng(png);
560         icon = new BC_Pixmap(this, vfrm, PIXMAP_ALPHA);
561 }
562
563 void AWindowGUI::create_objects()
564 {
565         lock_window("AWindowGUI::create_objects");
566         asset_titles[0] = C_("Title");
567         asset_titles[1] = _("Comments");
568
569         set_icon(mwindow->theme->get_image("awindow_icon"));
570
571         resource_icon(file_vframe,   file_icon,   "film_icon",   ICON_UNKNOWN);
572         resource_icon(folder_vframe, folder_icon, "folder_icon", ICON_FOLDER);
573         resource_icon(audio_vframe,  audio_icon,  "audio_icon",  ICON_SOUND);
574         resource_icon(video_vframe,  video_icon,  "video_icon",  ICON_FILM);
575         resource_icon(label_vframe,  label_icon,  "label_icon",  ICON_LABEL);
576
577         theme_icon(aeffect_folder_vframe,      aeffect_folder_icon,     "aeffect_folder");
578         theme_icon(atransition_folder_vframe,  atransition_folder_icon, "atransition_folder");
579         theme_icon(clip_folder_vframe,         clip_folder_icon,        "clip_folder");
580         theme_icon(label_folder_vframe,        label_folder_icon,       "label_folder");
581         theme_icon(media_folder_vframe,        media_folder_icon,       "media_folder");
582         theme_icon(proxy_folder_vframe,        proxy_folder_icon,       "proxy_folder");
583         theme_icon(veffect_folder_vframe,      veffect_folder_icon,     "veffect_folder");
584         theme_icon(vtransition_folder_vframe,  vtransition_folder_icon, "vtransition_folder");
585
586         folder_icons[AW_AEFFECT_FOLDER] = aeffect_folder_icon;
587         folder_icons[AW_VEFFECT_FOLDER] = veffect_folder_icon;
588         folder_icons[AW_ATRANSITION_FOLDER] = atransition_folder_icon;
589         folder_icons[AW_VTRANSITION_FOLDER] = vtransition_folder_icon;
590         folder_icons[AW_LABEL_FOLDER] = label_folder_icon;
591         folder_icons[AW_CLIP_FOLDER] = clip_folder_icon;
592         folder_icons[AW_MEDIA_FOLDER] = media_folder_icon;
593         folder_icons[AW_PROXY_FOLDER] = proxy_folder_icon;
594
595         theme_icon(clip_vframe,        clip_icon,        "clip_icon");
596         theme_icon(atransition_vframe, atransition_icon, "atransition_icon");
597         theme_icon(vtransition_vframe, vtransition_icon, "vtransition_icon");
598         theme_icon(aeffect_vframe,     aeffect_icon,     "aeffect_icon");
599         theme_icon(veffect_vframe,     veffect_icon,     "veffect_icon");
600
601         plugin_icon(ladspa_vframe, ladspa_icon, "lad_picon", lad_picon_png);
602         plugin_icon(ff_aud_vframe, ff_aud_icon, "ff_audio",  ff_audio_png);
603         plugin_icon(ff_vid_vframe, ff_vid_icon, "ff_video",  ff_video_png);
604
605 // Mandatory folders
606         folders.append(new AssetPicon(mwindow, this, AW_AEFFECT_FOLDER, 1));
607         folders.append(new AssetPicon(mwindow, this, AW_VEFFECT_FOLDER, 1));
608         folders.append(new AssetPicon(mwindow, this, AW_ATRANSITION_FOLDER, 1));
609         folders.append(new AssetPicon(mwindow, this, AW_VTRANSITION_FOLDER, 1));
610         folders.append(new AssetPicon(mwindow, this, AW_LABEL_FOLDER, 1));
611         folders.append(new AssetPicon(mwindow, this, AW_CLIP_FOLDER, 1));
612         folders.append(new AssetPicon(mwindow, this, AW_PROXY_FOLDER, 1));
613         folders.append(new AssetPicon(mwindow, this, AW_MEDIA_FOLDER, 1));
614
615         create_label_folder();
616
617         mwindow->theme->get_awindow_sizes(this);
618         load_defaults(mwindow->defaults);
619
620         int x1 = mwindow->theme->alist_x, y1 = mwindow->theme->alist_y;
621         int w1 = mwindow->theme->alist_w, h1 = mwindow->theme->alist_h;
622         search_text = new AWindowSearchText(mwindow, this, x1, y1+5);
623         search_text->create_objects();
624         int dy = search_text->get_h() + 10;
625         y1 += dy;  h1 -= dy;
626         add_subwindow(asset_list = new AWindowAssets(mwindow, this, x1, y1, w1, h1));
627
628         vicon_thread = new VIconThread(asset_list);
629         vicon_thread->start();
630
631         add_subwindow(divider = new AWindowDivider(mwindow, this,
632                 mwindow->theme->adivider_x, mwindow->theme->adivider_y,
633                 mwindow->theme->adivider_w, mwindow->theme->adivider_h));
634
635         divider->set_cursor(HSEPARATE_CURSOR, 0, 0);
636
637         int fx = mwindow->theme->afolders_x, fy = mwindow->theme->afolders_y;
638         int fw = mwindow->theme->afolders_w, fh = mwindow->theme->afolders_h;
639         VFrame **images = mwindow->theme->get_image_set("playpatch_data");
640         AVIconDrawing::calculate_geometry(this, images, &avicon_w, &avicon_h);
641         add_subwindow(avicon_drawing = new AVIconDrawing(this, fw-avicon_w, fy, images));
642         add_subwindow(add_tools = new AddTools(mwindow, this, fx, fy, _("Visibility")));
643         add_tools->create_objects();
644         fy += add_tools->get_h();  fh -= add_tools->get_h();
645         add_subwindow(folder_list = new AWindowFolders(mwindow,
646                 this, fx, fy, fw, fh));
647         update_effects();
648
649         //int x = mwindow->theme->abuttons_x;
650         //int y = mwindow->theme->abuttons_y;
651
652
653         newfolder_thread = new NewFolderThread(mwindow, this);
654
655         add_subwindow(asset_menu = new AssetPopup(mwindow, this));
656         asset_menu->create_objects();
657         add_subwindow(clip_menu = new ClipPopup(mwindow, this));
658         clip_menu->create_objects();
659         add_subwindow(label_menu = new LabelPopup(mwindow, this));
660         label_menu->create_objects();
661
662         add_subwindow(effectlist_menu = new EffectListMenu(mwindow, this));
663         effectlist_menu->create_objects();
664         add_subwindow(assetlist_menu = new AssetListMenu(mwindow, this));
665         assetlist_menu->create_objects();
666         add_subwindow(cliplist_menu = new ClipListMenu(mwindow, this));
667         cliplist_menu->create_objects();
668         add_subwindow(labellist_menu = new LabelListMenu(mwindow, this));
669         labellist_menu->create_objects();
670
671         add_subwindow(folderlist_menu = new FolderListMenu(mwindow, this));
672         folderlist_menu->create_objects();
673
674         create_custom_xatoms();
675         unlock_window();
676 }
677
678 int AWindowGUI::resize_event(int w, int h)
679 {
680         mwindow->session->awindow_x = get_x();
681         mwindow->session->awindow_y = get_y();
682         mwindow->session->awindow_w = w;
683         mwindow->session->awindow_h = h;
684
685         mwindow->theme->get_awindow_sizes(this);
686         mwindow->theme->draw_awindow_bg(this);
687         reposition_objects();
688
689 //      int x = mwindow->theme->abuttons_x;
690 //      int y = mwindow->theme->abuttons_y;
691 //      new_bin->reposition_window(x, y);
692 //      x += new_bin->get_w();
693 //      delete_bin->reposition_window(x, y);
694 //      x += delete_bin->get_w();
695 //      rename_bin->reposition_window(x, y);
696 //      x += rename_bin->get_w();
697 //      delete_disk->reposition_window(x, y);
698 //      x += delete_disk->get_w();
699 //      delete_project->reposition_window(x, y);
700 //      x += delete_project->get_w();
701 //      info->reposition_window(x, y);
702 //      x += info->get_w();
703 //      redraw_index->reposition_window(x, y);
704 //      x += redraw_index->get_w();
705 //      paste->reposition_window(x, y);
706 //      x += paste->get_w();
707 //      append->reposition_window(x, y);
708 //      x += append->get_w();
709 //      view->reposition_window(x, y);
710
711         BC_WindowBase::resize_event(w, h);
712         return 1;
713 }
714
715 int AWindowGUI::translation_event()
716 {
717         mwindow->session->awindow_x = get_x();
718         mwindow->session->awindow_y = get_y();
719         return 0;
720 }
721
722 void AWindowGUI::reposition_objects()
723 {
724         int x1 = mwindow->theme->alist_x, y1 = mwindow->theme->alist_y;
725         int w1 = mwindow->theme->alist_w, h1 = mwindow->theme->alist_h;
726         search_text->reposition_window(x1, y1+5, w1);
727         int dy = search_text->get_h() + 10;
728         y1 += dy;  h1 -= dy;
729         asset_list->reposition_window(x1, y1, w1, h1);
730         divider->reposition_window(
731                 mwindow->theme->adivider_x, mwindow->theme->adivider_y,
732                 mwindow->theme->adivider_w, mwindow->theme->adivider_h);
733         int fx = mwindow->theme->afolders_x, fy = mwindow->theme->afolders_y;
734         int fw = mwindow->theme->afolders_w, fh = mwindow->theme->afolders_h;
735         add_tools->resize_event(fw-avicon_w, add_tools->get_h());
736         avicon_drawing->reposition_window(fw-avicon_w, fy);
737         fy += add_tools->get_h();  fh -= add_tools->get_h();
738         folder_list->reposition_window(fx, fy, fw, fh);
739 }
740
741 int AWindowGUI::save_defaults(BC_Hash *defaults)
742 {
743         defaults->update("PLUGIN_VISIBILTY", plugin_visibility);
744         defaults->update("VICON_DRAWING", vicon_drawing);
745         return 0;
746 }
747
748 int AWindowGUI::load_defaults(BC_Hash *defaults)
749 {
750         plugin_visibility = defaults->get("PLUGIN_VISIBILTY", plugin_visibility);
751         vicon_drawing = defaults->get("VICON_DRAWING", vicon_drawing);
752         return 0;
753 }
754
755 int AWindowGUI::close_event()
756 {
757         hide_window();
758         mwindow->session->show_awindow = 0;
759         unlock_window();
760
761         mwindow->gui->lock_window("AWindowGUI::close_event");
762         mwindow->gui->mainmenu->show_awindow->set_checked(0);
763         mwindow->gui->unlock_window();
764
765         lock_window("AWindowGUI::close_event");
766         save_defaults(mwindow->defaults);
767         mwindow->save_defaults();
768         return 1;
769 }
770
771 void AWindowGUI::start_vicon_drawing()
772 {
773         if( !vicon_drawing ) return;
774         if( mwindow->edl->session->awindow_folder != AW_MEDIA_FOLDER ) return;
775         if( mwindow->edl->session->assetlist_format != ASSETS_ICONS ) return;
776         vicon_thread->start_drawing();
777 }
778
779 void AWindowGUI::stop_vicon_drawing()
780 {
781         vicon_thread->stop_drawing();
782 }
783
784 AWindowRemovePluginGUI::
785 AWindowRemovePluginGUI(AWindow *awindow, AWindowRemovePlugin *thread,
786         int x, int y, PluginServer *plugin)
787  : BC_Window(_(PROGRAM_NAME ": Remove plugin"), x,y, 500,200, 50, 50, 1, 0, 1, -1, "", 1)
788 {
789         this->awindow = awindow;
790         this->thread = thread;
791         this->plugin = plugin;
792         VFrame *vframe = plugin->get_picon();
793         icon = vframe ? create_pixmap(vframe) : 0;
794         plugin_list.append(new BC_ListBoxItem(plugin->title, icon));
795 }
796
797 AWindowRemovePluginGUI::
798 ~AWindowRemovePluginGUI()
799 {
800         if( !awindow->gui->protected_pixmap(icon) )
801                 delete icon;
802         plugin_list.remove_all();
803 }
804
805 void AWindowRemovePluginGUI::create_objects()
806 {
807         BC_Button *ok_button = new BC_OKButton(this);
808         add_subwindow(ok_button);
809         BC_Button *cancel_button = new BC_CancelButton(this);
810         add_subwindow(cancel_button);
811         int x = 10, y = 10;
812         BC_Title *title = new BC_Title(x, y, _("remove plugin?"));
813         add_subwindow(title);
814         y += title->get_h() + 5;
815         list = new BC_ListBox(x, y,
816                 get_w() - 20, ok_button->get_y() - y - 5, LISTBOX_TEXT, &plugin_list,
817                 0, 0, 1, 0, 0, LISTBOX_SINGLE, ICON_LEFT, 0);
818         add_subwindow(list);
819         show_window();
820 }
821
822 int AWindowRemovePlugin::remove_plugin(PluginServer *plugin, ArrayList<BC_ListBoxItem*> &folder)
823 {
824         int ret = 0;
825         for( int i=0; i<folder.size(); ) {
826                 AssetPicon *picon = (AssetPicon *)folder[i];
827                 if( picon->plugin == plugin ) {
828                         folder.remove_object_number(i);
829                         ++ret;
830                         continue;
831                 }
832                 ++i;
833         }
834         return ret;
835 }
836
837 void AWindowRemovePlugin::handle_close_event(int result)
838 {
839         if( !result ) {
840                 printf(_("remove %s\n"), plugin->path);
841                 awindow->gui->lock_window("AWindowRemovePlugin::handle_close_event");
842                 ArrayList<BC_ListBoxItem*> *folder =
843                         plugin->audio ? plugin->transition ?
844                                 &awindow->gui->atransitions :
845                                 &awindow->gui->aeffects :
846                         plugin->video ?  plugin->transition ?
847                                 &awindow->gui->vtransitions :
848                                 &awindow->gui->veffects :
849                         0;
850                 if( folder ) remove_plugin(plugin, *folder);
851                 MWindow *mwindow = awindow->mwindow;
852                 awindow->gui->unlock_window();
853                 char plugin_path[BCTEXTLEN];
854                 strcpy(plugin_path, plugin->path);
855                 mwindow->plugindb->remove(plugin);
856                 remove(plugin_path);
857                 char index_path[BCTEXTLEN];
858                 mwindow->create_defaults_path(index_path, PLUGIN_FILE);
859                 remove(index_path);
860                 char picon_path[BCTEXTLEN];
861                 FileSystem fs;
862                 snprintf(picon_path, sizeof(picon_path), "%s/picon",
863                         File::get_plugin_path());
864                 char png_name[BCSTRLEN], png_path[BCTEXTLEN];
865                 plugin->get_plugin_png_name(png_name);
866                 fs.update(picon_path);
867                 for( int i=0; i<fs.dir_list.total; ++i ) {
868                         char *fs_path = fs.dir_list[i]->path;
869                         if( !fs.is_dir(fs_path) ) continue;
870                         snprintf(png_path, sizeof(picon_path), "%s/%s",
871                                 fs_path, png_name);
872                         remove(png_path);
873                 }
874                 delete plugin;  plugin = 0;
875                 awindow->gui->async_update_assets();
876         }
877 }
878
879 AWindowRemovePlugin::
880 AWindowRemovePlugin(AWindow *awindow, PluginServer *plugin)
881  : BC_DialogThread()
882 {
883         this->awindow = awindow;
884         this->plugin = plugin;
885 }
886
887 AWindowRemovePlugin::
888 ~AWindowRemovePlugin()
889 {
890         close_window();
891 }
892
893 BC_Window* AWindowRemovePlugin::new_gui()
894 {
895         int x = awindow->gui->get_abs_cursor_x(0);
896         int y = awindow->gui->get_abs_cursor_y(0);
897         AWindowRemovePluginGUI *gui = new AWindowRemovePluginGUI(awindow, this, x, y, plugin);
898         gui->create_objects();
899         return gui;
900 }
901
902 int AWindowGUI::keypress_event()
903 {
904         switch( get_keypress() ) {
905         case 'w': case 'W':
906                 if( ctrl_down() ) {
907                         close_event();
908                         return 1;
909                 }
910                 break;
911         case DELETE:
912                 if( shift_down() ) {
913                         PluginServer* plugin = selected_plugin();
914                         if( !plugin ) break;
915                         remove_plugin = new AWindowRemovePlugin(awindow, plugin);
916                         unlock_window();
917                         remove_plugin->start();
918                         lock_window();
919                 }
920         }
921         return 0;
922 }
923
924
925
926 int AWindowGUI::create_custom_xatoms()
927 {
928         UpdateAssetsXAtom = create_xatom("CWINDOWGUI_UPDATE_ASSETS");
929         return 0;
930 }
931 int AWindowGUI::recieve_custom_xatoms(xatom_event *event)
932 {
933         if( event->message_type == UpdateAssetsXAtom ) {
934                 update_assets();
935                 return 1;
936         }
937         return 0;
938 }
939
940 void AWindowGUI::async_update_assets()
941 {
942         xatom_event event;
943         event.message_type = UpdateAssetsXAtom;
944         send_custom_xatom(&event);
945 }
946
947
948 void AWindowGUI::update_folder_list()
949 {
950         for( int i = 0; i < folders.total; i++ ) {
951                 AssetPicon *picon = (AssetPicon*)folders.values[i];
952                 picon->in_use = 0;
953         }
954
955 // Search assets for folders
956         for( int i = 0; i < mwindow->edl->folders.total; i++ ) {
957                 const char *folder = mwindow->edl->folders.values[i];
958                 int exists = 0;
959
960                 for( int j = 0; j < folders.total; j++ ) {
961                         AssetPicon *picon = (AssetPicon*)folders.values[j];
962                         if( !strcasecmp(picon->get_text(), folder) ) {
963                                 exists = 1;
964                                 picon->in_use = 1;
965                                 break;
966                         }
967                 }
968
969                 if( !exists ) {
970                         int aw_folder = folder_number(folder);
971                         if( aw_folder >= 0 ) {
972                                 AssetPicon *picon = new AssetPicon(mwindow, this, aw_folder, 1);
973                                 picon->create_objects();
974                                 folders.append(picon);
975                         }
976                 }
977         }
978
979 // Delete unused non-persistent folders
980         for( int i=folders.total; --i>=0; ) {
981                 AssetPicon *picon = (AssetPicon*)folders.values[i];
982                 if( !picon->in_use && !picon->persistent ) {
983                         delete picon;
984                         folders.remove_number(i);
985                 }
986         }
987 }
988
989 void AWindowGUI::create_persistent_folder(ArrayList<BC_ListBoxItem*> *output,
990         int do_audio, int do_video, int is_realtime, int is_transition)
991 {
992         ArrayList<PluginServer*> plugin_list;
993 // Get pointers to plugindb entries
994         mwindow->search_plugindb(do_audio, do_video, is_realtime, is_transition,
995                         0, plugin_list);
996
997         for( int i = 0; i < plugin_list.total; i++ ) {
998                 PluginServer *server = plugin_list.values[i];
999                 int visible = plugin_visibility & (1<<server->dir_idx);
1000                 if( !visible ) continue;
1001 // Create new listitem
1002                 AssetPicon *picon = new AssetPicon(mwindow, this, server);
1003                 picon->create_objects();
1004                 output->append(picon);
1005         }
1006 }
1007
1008 void AWindowGUI::create_label_folder()
1009 {
1010         Label *current;
1011         for( current = mwindow->edl->labels->first; current; current = NEXT ) {
1012                 AssetPicon *picon = new AssetPicon(mwindow, this, current);
1013                 picon->create_objects();
1014                 labellist.append(picon);
1015         }
1016 }
1017
1018
1019 void AWindowGUI::update_asset_list()
1020 {
1021         for( int i = 0; i < assets.total; i++ ) {
1022                 AssetPicon *picon = (AssetPicon*)assets.values[i];
1023                 picon->in_use = 0;
1024         }
1025
1026 // Synchronize EDL clips
1027         for( int i = 0; i < mwindow->edl->clips.total; i++ ) {
1028                 int exists = 0;
1029
1030 // Look for clip in existing listitems
1031                 for( int j = 0; j < assets.total && !exists; j++ ) {
1032                         AssetPicon *picon = (AssetPicon*)assets.values[j];
1033
1034                         if( picon->id == mwindow->edl->clips.values[i]->id ) {
1035                                 picon->edl = mwindow->edl->clips.values[i];
1036                                 picon->set_text(mwindow->edl->clips.values[i]->local_session->clip_title);
1037                                 exists = 1;
1038                                 picon->in_use = 1;
1039                         }
1040                 }
1041
1042 // Create new listitem
1043                 if( !exists ) {
1044                         AssetPicon *picon = new AssetPicon(mwindow,
1045                                 this, mwindow->edl->clips.values[i]);
1046                         picon->create_objects();
1047                         assets.append(picon);
1048                 }
1049         }
1050
1051 // Synchronize EDL assets
1052         for( Asset *current = mwindow->edl->assets->first;
1053                 current;
1054                 current = NEXT ) {
1055                 int exists = 0;
1056
1057 // Look for asset in existing listitems
1058                 for( int j = 0; j < assets.total && !exists; j++ ) {
1059                         AssetPicon *picon = (AssetPicon*)assets.values[j];
1060
1061                         if( picon->id == current->id ) {
1062                                 picon->indexable = current;
1063                                 exists = 1;
1064                                 picon->in_use = 1;
1065                                 break;
1066                         }
1067                 }
1068
1069 // Create new listitem
1070                 if( !exists ) {
1071                         AssetPicon *picon = new AssetPicon(mwindow,
1072                                 this, current);
1073                         picon->create_objects();
1074                         assets.append(picon);
1075                 }
1076         }
1077
1078         mwindow->gui->lock_window("AWindowGUI::update_asset_list");
1079         mwindow->gui->default_message();
1080         mwindow->gui->unlock_window();
1081
1082 // Synchronize nested EDLs
1083         for( int i = 0; i < mwindow->edl->nested_edls->size(); i++ ) {
1084                 int exists = 0;
1085                 Indexable *indexable = mwindow->edl->nested_edls->get(i);
1086
1087 // Look for asset in existing listitems
1088                 for( int j = 0; j < assets.total && !exists; j++ ) {
1089                         AssetPicon *picon = (AssetPicon*)assets.values[j];
1090
1091                         if( picon->id == indexable->id ) {
1092                                 picon->indexable = indexable;
1093                                 exists = 1;
1094                                 picon->in_use = 1;
1095                                 break;
1096                         }
1097                 }
1098
1099 // Create new listitem
1100                 if( !exists ) {
1101                         AssetPicon *picon = new AssetPicon(mwindow,
1102                                 this, indexable);
1103                         picon->create_objects();
1104                         assets.append(picon);
1105                 }
1106         }
1107
1108         for( int i = assets.size() - 1; i >= 0; i-- ) {
1109                 AssetPicon *picon = (AssetPicon*)assets.get(i);
1110                 if( !picon->in_use ) {
1111                         delete picon;
1112                         assets.remove_number(i);
1113                         continue;
1114                 }
1115                 if( !picon->indexable->is_asset ) continue;
1116                 struct stat st;
1117                 picon->mtime = !stat(picon->indexable->path, &st) ? st.st_mtime : 0;
1118         }
1119 }
1120
1121 void AWindowGUI::update_picon(Indexable *indexable)
1122 {
1123         VIcon *vicon = 0;
1124         for( int i = 0; i < assets.total; i++ ) {
1125                 AssetPicon *picon = (AssetPicon*)assets.values[i];
1126                 if( picon->indexable == indexable ||
1127                     picon->edl == (EDL *)indexable ) {
1128                         char name[BCTEXTLEN];
1129                         FileSystem fs;
1130                         fs.extract_name(name, indexable->path);
1131                         picon->set_text(name);
1132                         vicon = picon->vicon;
1133                         break;
1134                 }
1135         }
1136         if( vicon ) {
1137                 stop_vicon_drawing();
1138                 vicon->clear_images();
1139                 vicon->reset(indexable->get_frame_rate());
1140                 start_vicon_drawing();
1141         }
1142 }
1143
1144 void AWindowGUI::sort_assets(int use_mtime)
1145 {
1146         switch( mwindow->edl->session->awindow_folder ) {
1147         case AW_AEFFECT_FOLDER:
1148                 sort_picons(&aeffects);
1149                 break;
1150         case AW_VEFFECT_FOLDER:
1151                 sort_picons(&veffects);
1152                 break;
1153         case AW_ATRANSITION_FOLDER:
1154                 sort_picons(&atransitions);
1155                 break;
1156         case AW_VTRANSITION_FOLDER:
1157                 sort_picons(&vtransitions);
1158                 break;
1159         case AW_LABEL_FOLDER:
1160                 sort_picons(&labellist);
1161                 break;
1162         default:
1163                 sort_picons(&assets, use_mtime);
1164         }
1165 // reset xyposition
1166         asset_list->update_format(asset_list->get_format(), 0);
1167         update_assets();
1168 }
1169
1170 void AWindowGUI::sort_folders()
1171 {
1172         sort_picons(&folders);
1173         folder_list->update_format(folder_list->get_format(), 0);
1174         update_assets();
1175 }
1176
1177 void AWindowGUI::collect_assets()
1178 {
1179         int i = 0;
1180         mwindow->session->drag_assets->remove_all();
1181         mwindow->session->drag_clips->remove_all();
1182         while(1)
1183         {
1184                 AssetPicon *result = (AssetPicon*)asset_list->get_selection(0, i++);
1185                 if( !result ) break;
1186
1187                 if( result->indexable ) mwindow->session->drag_assets->append(result->indexable);
1188                 if( result->edl ) mwindow->session->drag_clips->append(result->edl);
1189         }
1190 }
1191
1192 void AWindowGUI::copy_picons(ArrayList<BC_ListBoxItem*> *dst,
1193         ArrayList<BC_ListBoxItem*> *src, int folder)
1194 {
1195 // Remove current pointers
1196         dst[0].remove_all();
1197         dst[1].remove_all_objects();
1198
1199 // Create new pointers
1200         for( int i = 0; i < src->total; i++ ) {
1201                 AssetPicon *picon = (AssetPicon*)src->values[i];
1202                 if( folder < 0 ||
1203                     (picon->indexable && picon->indexable->awindow_folder == folder) ||
1204                     (picon->edl && picon->edl->local_session->awindow_folder == folder) ) {
1205                         const char *text = search_text->get_text();
1206                         int hidden = text && text[0] && !bstrcasestr(picon->get_text(), text);
1207                         if( picon->vicon ) picon->vicon->hidden = hidden;
1208                         if( hidden ) continue;
1209                         BC_ListBoxItem *item2, *item1;
1210                         dst[0].append(item1 = picon);
1211                         if( picon->edl )
1212                                 dst[1].append(item2 = new BC_ListBoxItem(picon->edl->local_session->clip_notes));
1213                         else
1214                         if( picon->label && picon->label->textstr )
1215                                 dst[1].append(item2 = new BC_ListBoxItem(picon->label->textstr));
1216                         else if( picon->mtime ) {
1217                                 char date_time[BCSTRLEN];
1218                                 struct tm stm;  localtime_r(&picon->mtime, &stm);
1219                                 sprintf(date_time,"%04d.%02d.%02d %02d:%02d:%02d",
1220                                          stm.tm_year+1900, stm.tm_mon+1, stm.tm_mday,
1221                                          stm.tm_hour, stm.tm_min, stm.tm_sec);
1222                                 dst[1].append(item2 = new BC_ListBoxItem(date_time));
1223                         }
1224                         else
1225                                 dst[1].append(item2 = new BC_ListBoxItem(""));
1226                         item1->set_autoplace_text(1);  item1->set_autoplace_icon(1);
1227                         item2->set_autoplace_text(1);  item2->set_autoplace_icon(1);
1228                 }
1229         }
1230 }
1231
1232 void AWindowGUI::sort_picons(ArrayList<BC_ListBoxItem*> *src, int use_mtime)
1233 {
1234         int done = 0, changed = 0;
1235         while( !done ) {
1236                 done = 1;
1237                 for( int i=0; i<src->total-1; ++i ) {
1238                         AssetPicon *item1 = (AssetPicon *)src->values[i];
1239                         AssetPicon *item2 = (AssetPicon *)src->values[i + 1];
1240                         if( use_mtime ? item1->mtime > item2->mtime :
1241                             strcmp(item1->get_text(), item2->get_text()) > 0 ) {
1242                                 src->values[i + 1] = item1;
1243                                 src->values[i] = item2;
1244                                 done = 0;  changed = 1;
1245                         }
1246                 }
1247         }
1248         if( changed ) {
1249                 for( int i=0; i<src->total; ++i ) {
1250                         AssetPicon *item = (AssetPicon *)src->values[i];
1251                         item->set_autoplace_icon(1);
1252                         item->set_autoplace_text(1);
1253                 }
1254         }
1255 }
1256
1257
1258 void AWindowGUI::filter_displayed_assets()
1259 {
1260         //allow_iconlisting = 1;
1261         asset_titles[0] = C_("Title");
1262         asset_titles[1] = _("Comments");
1263
1264         switch( mwindow->edl->session->awindow_folder ) {
1265         case AW_AEFFECT_FOLDER:
1266                 copy_picons(displayed_assets, &aeffects, AW_NO_FOLDER);
1267                 break;
1268         case AW_VEFFECT_FOLDER:
1269                 copy_picons(displayed_assets, &veffects, AW_NO_FOLDER);
1270                 break;
1271         case AW_ATRANSITION_FOLDER:
1272                 copy_picons(displayed_assets, &atransitions, AW_NO_FOLDER);
1273                 break;
1274         case AW_VTRANSITION_FOLDER:
1275                 copy_picons(displayed_assets, &vtransitions, AW_NO_FOLDER);
1276                 break;
1277         case AW_LABEL_FOLDER:
1278                 copy_picons(displayed_assets, &labellist, AW_NO_FOLDER);
1279                 asset_titles[0] = _("Time Stamps");
1280                 asset_titles[1] = C_("Title");
1281                 //allow_iconlisting = 0;
1282                 break;
1283         default:
1284                 copy_picons(displayed_assets, &assets, mwindow->edl->session->awindow_folder);
1285                 break;
1286         }
1287
1288         // Ensure the current folder icon is highlighted
1289         int selected_folder = mwindow->edl->session->awindow_folder;
1290         for( int i = 0; i < folders.total; i++ ) {
1291                 AssetPicon *folder_item = (AssetPicon *)folders.values[i];
1292                 int selected = folder_item->foldernum == selected_folder ? 1 : 0;
1293                 folder_item->set_selected(selected);
1294         }
1295 }
1296
1297
1298 void AWindowGUI::update_assets()
1299 {
1300         stop_vicon_drawing();
1301         update_folder_list();
1302         update_asset_list();
1303         labellist.remove_all_objects();
1304         create_label_folder();
1305
1306         if( displayed_folder != mwindow->edl->session->awindow_folder )
1307                 search_text->clear();
1308         filter_displayed_assets();
1309
1310         if( mwindow->edl->session->folderlist_format != folder_list->get_format() ) {
1311                 folder_list->update_format(mwindow->edl->session->folderlist_format, 0);
1312         }
1313         int folder_xposition = folder_list->get_xposition();
1314         int folder_yposition = folder_list->get_yposition();
1315         folder_list->update(&folders, 0, 0, 1, folder_xposition, folder_yposition, -1);
1316
1317         if( mwindow->edl->session->assetlist_format != asset_list->get_format() ) {
1318                 asset_list->update_format(mwindow->edl->session->assetlist_format, 0);
1319         }
1320         int asset_xposition = asset_list->get_xposition();
1321         int asset_yposition = asset_list->get_yposition();
1322         if( displayed_folder != mwindow->edl->session->awindow_folder ) {
1323                 displayed_folder = mwindow->edl->session->awindow_folder;
1324                 asset_xposition = asset_yposition = 0;
1325         }
1326         asset_list->update(displayed_assets, asset_titles,
1327                 mwindow->edl->session->asset_columns, ASSET_COLUMNS,
1328                 asset_xposition, asset_yposition, -1, 0);
1329         asset_list->center_selection();
1330
1331         flush();
1332         start_vicon_drawing();
1333         return;
1334 }
1335
1336 void AWindowGUI::update_effects()
1337 {
1338         aeffects.remove_all_objects();
1339         create_persistent_folder(&aeffects, 1, 0, 1, 0);
1340         veffects.remove_all_objects();
1341         create_persistent_folder(&veffects, 0, 1, 1, 0);
1342         atransitions.remove_all_objects();
1343         create_persistent_folder(&atransitions, 1, 0, 0, 1);
1344         vtransitions.remove_all_objects();
1345         create_persistent_folder(&vtransitions, 0, 1, 0, 1);
1346 }
1347
1348 int AWindowGUI::folder_number(const char *name)
1349 {
1350         for( int i = 0; i < AWINDOW_FOLDERS; i++ ) {
1351                 if( !strcasecmp(name, folder_names[i]) ) return i;
1352         }
1353         return AW_NO_FOLDER;
1354 }
1355
1356 int AWindowGUI::drag_motion()
1357 {
1358         if( get_hidden() ) return 0;
1359
1360         int result = 0;
1361         return result;
1362 }
1363
1364 int AWindowGUI::drag_stop()
1365 {
1366         if( get_hidden() ) return 0;
1367
1368         return 0;
1369 }
1370
1371 Indexable* AWindowGUI::selected_asset()
1372 {
1373         AssetPicon *picon = (AssetPicon*)asset_list->get_selection(0, 0);
1374         return picon ? picon->indexable : 0;
1375 }
1376
1377 PluginServer* AWindowGUI::selected_plugin()
1378 {
1379         AssetPicon *picon = (AssetPicon*)asset_list->get_selection(0, 0);
1380         return picon ? picon->plugin : 0;
1381 }
1382
1383 AssetPicon* AWindowGUI::selected_folder()
1384 {
1385         AssetPicon *picon = (AssetPicon*)folder_list->get_selection(0, 0);
1386         return picon;
1387 }
1388
1389
1390
1391
1392
1393
1394
1395
1396 AWindowDivider::AWindowDivider(MWindow *mwindow, AWindowGUI *gui, int x, int y, int w, int h)
1397  : BC_SubWindow(x, y, w, h)
1398 {
1399         this->mwindow = mwindow;
1400         this->gui = gui;
1401 }
1402 AWindowDivider::~AWindowDivider()
1403 {
1404 }
1405
1406 int AWindowDivider::button_press_event()
1407 {
1408         if( is_event_win() && cursor_inside() ) {
1409                 mwindow->session->current_operation = DRAG_PARTITION;
1410                 return 1;
1411         }
1412         return 0;
1413 }
1414
1415 int AWindowDivider::cursor_motion_event()
1416 {
1417         if( mwindow->session->current_operation == DRAG_PARTITION ) {
1418                 int wmin = 25;
1419                 int wmax = mwindow->session->awindow_w - mwindow->theme->adivider_w - wmin;
1420                 int fw = gui->get_relative_cursor_x();
1421                 if( fw > wmax ) fw = wmax;
1422                 if( fw < wmin ) fw = wmin;
1423                 mwindow->session->afolders_w = fw;
1424                 mwindow->theme->get_awindow_sizes(gui);
1425                 gui->reposition_objects();
1426                 gui->flush();
1427         }
1428         return 0;
1429 }
1430
1431 int AWindowDivider::button_release_event()
1432 {
1433         if( mwindow->session->current_operation == DRAG_PARTITION ) {
1434                 mwindow->session->current_operation = NO_OPERATION;
1435                 return 1;
1436         }
1437         return 0;
1438 }
1439
1440
1441
1442
1443
1444
1445 AWindowFolders::AWindowFolders(MWindow *mwindow, AWindowGUI *gui, int x, int y, int w, int h)
1446  : BC_ListBox(x, y, w, h,
1447                 mwindow->edl->session->folderlist_format == ASSETS_ICONS ?
1448                         LISTBOX_ICONS : LISTBOX_TEXT,
1449                 &gui->folders,    // Each column has an ArrayList of BC_ListBoxItems.
1450                 0,                // Titles for columns.  Set to 0 for no titles
1451                 0,                // width of each column
1452                 1,                // Total columns.
1453                 0,                // Pixel of top of window.
1454                 0,                // If this listbox is a popup window
1455                 LISTBOX_SINGLE,   // Select one item or multiple items
1456                 ICON_TOP,         // Position of icon relative to text of each item
1457                 1)                // Allow drags
1458 {
1459         this->mwindow = mwindow;
1460         this->gui = gui;
1461         set_drag_scroll(0);
1462 }
1463
1464 AWindowFolders::~AWindowFolders()
1465 {
1466 }
1467
1468 int AWindowFolders::selection_changed()
1469 {
1470         AssetPicon *picon = (AssetPicon*)get_selection(0, 0);
1471         if( picon ) {
1472                 gui->stop_vicon_drawing();
1473
1474                 if( get_button_down() && get_buttonpress() == 3 ) {
1475                         gui->folderlist_menu->update_titles();
1476                         gui->folderlist_menu->activate_menu();
1477                 }
1478
1479                 mwindow->edl->session->awindow_folder = picon->foldernum;
1480                 gui->asset_list->draw_background();
1481                 gui->async_update_assets();
1482
1483                 gui->start_vicon_drawing();
1484         }
1485         return 1;
1486 }
1487
1488 int AWindowFolders::button_press_event()
1489 {
1490         int result = 0;
1491
1492         result = BC_ListBox::button_press_event();
1493
1494         if( !result ) {
1495                 if( get_buttonpress() == 3 && is_event_win() && cursor_inside() ) {
1496                         gui->folderlist_menu->update_titles();
1497                         gui->folderlist_menu->activate_menu();
1498                         result = 1;
1499                 }
1500         }
1501
1502
1503         return result;
1504 }
1505
1506
1507
1508
1509
1510
1511
1512 AWindowAssets::AWindowAssets(MWindow *mwindow, AWindowGUI *gui, int x, int y, int w, int h)
1513  : BC_ListBox(x, y, w, h,
1514                 (mwindow->edl->session->assetlist_format == ASSETS_ICONS && gui->allow_iconlisting ) ?
1515                         LISTBOX_ICONS : LISTBOX_TEXT,
1516                 &gui->assets,     // Each column has an ArrayList of BC_ListBoxItems.
1517                 gui->asset_titles,// Titles for columns.  Set to 0 for no titles
1518                 mwindow->edl->session->asset_columns, // width of each column
1519                 1,                // Total columns.
1520                 0,                // Pixel of top of window.
1521                 0,                // If this listbox is a popup window
1522                 LISTBOX_MULTIPLE, // Select one item or multiple items
1523                 ICON_TOP,         // Position of icon relative to text of each item
1524                 -1)               // Allow drags, require shift for scrolling
1525 {
1526         this->mwindow = mwindow;
1527         this->gui = gui;
1528         set_drag_scroll(0);
1529         set_scroll_stretch(1, 1);
1530 }
1531
1532 AWindowAssets::~AWindowAssets()
1533 {
1534 }
1535
1536 int AWindowAssets::button_press_event()
1537 {
1538         int result = 0;
1539
1540         result = BC_ListBox::button_press_event();
1541
1542         if( !result && get_buttonpress() == 3 && is_event_win() && cursor_inside() ) {
1543                 BC_ListBox::deactivate_selection();
1544                 int folder = mwindow->edl->session->awindow_folder;
1545                 switch( folder ) {
1546                 case AW_AEFFECT_FOLDER:
1547                 case AW_VEFFECT_FOLDER:
1548                 case AW_ATRANSITION_FOLDER:
1549                 case AW_VTRANSITION_FOLDER:
1550                         gui->effectlist_menu->update();
1551                         gui->effectlist_menu->activate_menu();
1552                         break;
1553                 case AW_LABEL_FOLDER:
1554                         gui->labellist_menu->update();
1555                         gui->labellist_menu->activate_menu();
1556                         break;
1557                 case AW_CLIP_FOLDER:
1558                         gui->cliplist_menu->update();
1559                         gui->cliplist_menu->activate_menu();
1560                         break;
1561                 case AW_MEDIA_FOLDER:
1562                 case AW_PROXY_FOLDER:
1563                         gui->assetlist_menu->update_titles(folder==AW_MEDIA_FOLDER);
1564                         gui->assetlist_menu->activate_menu();
1565                         break;
1566                 }
1567                 result = 1;
1568         }
1569
1570         return result;
1571 }
1572
1573
1574 int AWindowAssets::handle_event()
1575 {
1576         AssetPicon *asset_picon = (AssetPicon *)get_selection(0, 0);
1577         if( !asset_picon ) return 0;
1578         switch( mwindow->edl->session->awindow_folder ) {
1579         case AW_AEFFECT_FOLDER:
1580         case AW_VEFFECT_FOLDER:
1581         case AW_ATRANSITION_FOLDER:
1582         case AW_VTRANSITION_FOLDER: return 1;
1583         }
1584         VWindow *vwindow = mwindow->vwindows.size() > DEFAULT_VWINDOW ?
1585                 mwindow->vwindows.get(DEFAULT_VWINDOW) : 0;
1586         if( !vwindow || !vwindow->is_running() ) return 1;
1587
1588         vwindow->gui->lock_window("AWindowAssets::handle_event");
1589         if( asset_picon->indexable )
1590                 vwindow->change_source(asset_picon->indexable);
1591         else if( asset_picon->edl )
1592                 vwindow->change_source(asset_picon->edl);
1593         vwindow->gui->unlock_window();
1594         return 1;
1595 }
1596
1597 int AWindowAssets::selection_changed()
1598 {
1599 // Show popup window
1600         AssetPicon *item;
1601         if( get_button_down() && get_buttonpress() == 3 &&
1602             (item = (AssetPicon*)get_selection(0, 0)) ) {
1603                 int folder = mwindow->edl->session->awindow_folder;
1604                 switch( folder ) {
1605                 case AW_AEFFECT_FOLDER:
1606                 case AW_VEFFECT_FOLDER:
1607                 case AW_ATRANSITION_FOLDER:
1608                 case AW_VTRANSITION_FOLDER:
1609                         gui->effectlist_menu->update();
1610                         gui->effectlist_menu->activate_menu();
1611                         break;
1612                 case AW_LABEL_FOLDER:
1613                         if( !item->label ) break;
1614                         gui->label_menu->activate_menu();
1615                         break;
1616                 case AW_CLIP_FOLDER:
1617                         if( !item->indexable && !item->edl ) break;
1618                         gui->clip_menu->update();
1619                         gui->clip_menu->activate_menu();
1620                         break;
1621                 default:
1622                         if( !item->indexable && !item->edl ) break;
1623                         gui->asset_menu->update();
1624                         gui->asset_menu->activate_menu();
1625                         break;
1626                 }
1627
1628                 BC_ListBox::deactivate_selection();
1629                 return 1;
1630         }
1631         else if( get_button_down() && get_buttonpress() == 1 &&
1632                  (item = (AssetPicon*)get_selection(0, 0)) ) {
1633                 VIcon *vicon = 0;
1634                 if( !gui->vicon_thread->viewing ) {
1635                         vicon = item->vicon;
1636                 }
1637                 gui->vicon_thread->set_view_popup(vicon);
1638
1639         }
1640         return 0;
1641 }
1642
1643 void AWindowAssets::draw_background()
1644 {
1645         clear_box(0,0,get_w(),get_h(),get_bg_surface());
1646         set_color(BC_WindowBase::get_resources()->audiovideo_color);
1647         set_font(LARGEFONT);
1648         int aw_folder = mwindow->edl->session->awindow_folder;
1649         if( aw_folder < 0 ) return;
1650         const char *aw_name = _(AWindowGUI::folder_names[aw_folder]);
1651         draw_text(get_w() - get_text_width(LARGEFONT, aw_name) - 4, 30,
1652                 aw_name, -1, get_bg_surface());
1653 }
1654
1655 int AWindowAssets::drag_start_event()
1656 {
1657         int collect_pluginservers = 0;
1658         int collect_assets = 0;
1659
1660         if( BC_ListBox::drag_start_event() ) {
1661                 switch( mwindow->edl->session->awindow_folder ) {
1662                 case AW_AEFFECT_FOLDER:
1663                         mwindow->session->current_operation = DRAG_AEFFECT;
1664                         collect_pluginservers = 1;
1665                         break;
1666                 case AW_VEFFECT_FOLDER:
1667                         mwindow->session->current_operation = DRAG_VEFFECT;
1668                         collect_pluginservers = 1;
1669                         break;
1670                 case AW_ATRANSITION_FOLDER:
1671                         mwindow->session->current_operation = DRAG_ATRANSITION;
1672                         collect_pluginservers = 1;
1673                         break;
1674                 case AW_VTRANSITION_FOLDER:
1675                         mwindow->session->current_operation = DRAG_VTRANSITION;
1676                         collect_pluginservers = 1;
1677                         break;
1678                 case AW_LABEL_FOLDER:
1679                         // do nothing!
1680                         break;
1681                 default:
1682                         mwindow->session->current_operation = DRAG_ASSET;
1683                         collect_assets = 1;
1684                         break;
1685                 }
1686
1687                 if( collect_pluginservers ) {
1688                         int i = 0;
1689                         mwindow->session->drag_pluginservers->remove_all();
1690                         while(1)
1691                         {
1692                                 AssetPicon *result = (AssetPicon*)get_selection(0, i++);
1693                                 if( !result ) break;
1694
1695                                 mwindow->session->drag_pluginservers->append(result->plugin);
1696                         }
1697                 }
1698
1699                 if( collect_assets ) {
1700                         gui->collect_assets();
1701                 }
1702
1703                 return 1;
1704         }
1705         return 0;
1706 }
1707
1708 int AWindowAssets::drag_motion_event()
1709 {
1710         BC_ListBox::drag_motion_event();
1711         unlock_window();
1712
1713         mwindow->gui->lock_window("AWindowAssets::drag_motion_event");
1714         mwindow->gui->drag_motion();
1715         mwindow->gui->unlock_window();
1716
1717         for( int i = 0; i < mwindow->vwindows.size(); i++ ) {
1718                 VWindow *vwindow = mwindow->vwindows.get(i);
1719                 if( !vwindow->is_running() ) continue;
1720                 vwindow->gui->lock_window("AWindowAssets::drag_motion_event");
1721                 vwindow->gui->drag_motion();
1722                 vwindow->gui->unlock_window();
1723         }
1724
1725         mwindow->cwindow->gui->lock_window("AWindowAssets::drag_motion_event");
1726         mwindow->cwindow->gui->drag_motion();
1727         mwindow->cwindow->gui->unlock_window();
1728
1729         lock_window("AWindowAssets::drag_motion_event");
1730         return 0;
1731 }
1732
1733 int AWindowAssets::drag_stop_event()
1734 {
1735         int result = 0;
1736
1737         result = gui->drag_stop();
1738
1739         unlock_window();
1740
1741         if( !result ) {
1742                 mwindow->gui->lock_window("AWindowAssets::drag_stop_event");
1743                 result = mwindow->gui->drag_stop();
1744                 mwindow->gui->unlock_window();
1745         }
1746
1747         if( !result ) {
1748                 for( int i = 0; !result && i < mwindow->vwindows.size(); i++ ) {
1749                         VWindow *vwindow = mwindow->vwindows.get(i);
1750                         if( !vwindow ) continue;
1751                         if( !vwindow->is_running() ) continue;
1752                         if( vwindow->gui->is_hidden() ) continue;
1753                         vwindow->gui->lock_window("AWindowAssets::drag_stop_event");
1754                         if( vwindow->gui->cursor_above() &&
1755                             vwindow->gui->get_cursor_over_window() ) {
1756                                 result = vwindow->gui->drag_stop();
1757                         }
1758                         vwindow->gui->unlock_window();
1759                 }
1760         }
1761
1762         if( !result ) {
1763                 mwindow->cwindow->gui->lock_window("AWindowAssets::drag_stop_event");
1764                 result = mwindow->cwindow->gui->drag_stop();
1765                 mwindow->cwindow->gui->unlock_window();
1766         }
1767
1768         lock_window("AWindowAssets::drag_stop_event");
1769
1770         if( result )
1771                 get_drag_popup()->set_animation(0);
1772
1773         BC_ListBox::drag_stop_event();
1774 // since NO_OPERATION is also defined in listbox, we have to reach for global scope...
1775         mwindow->session->current_operation = ::NO_OPERATION;
1776         return 1;
1777 }
1778
1779 int AWindowAssets::column_resize_event()
1780 {
1781         mwindow->edl->session->asset_columns[0] = get_column_width(0);
1782         mwindow->edl->session->asset_columns[1] = get_column_width(1);
1783         return 1;
1784 }
1785
1786 int AWindowAssets::focus_in_event()
1787 {
1788         gui->start_vicon_drawing();
1789         return 0;
1790 }
1791
1792 int AWindowAssets::focus_out_event()
1793 {
1794         gui->stop_vicon_drawing();
1795         return BC_ListBox::focus_out_event();
1796 }
1797
1798 AWindowSearchTextBox::AWindowSearchTextBox(AWindowSearchText *search_text, int x, int y, int w)
1799  : BC_TextBox(x, y, w, 1, "")
1800 {
1801         this->search_text = search_text;
1802 }
1803
1804 int AWindowSearchTextBox::handle_event()
1805 {
1806         return search_text->handle_event();
1807 }
1808
1809 AWindowSearchText::AWindowSearchText(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1810 {
1811         this->mwindow = mwindow;
1812         this->gui = gui;
1813         this->x = x;
1814         this->y = y;
1815 }
1816
1817 void AWindowSearchText::create_objects()
1818 {
1819         int x1 = x, y1 = y, margin = 10;
1820         gui->add_subwindow(text_title = new BC_Title(x1, y1, _("Search:")));
1821         x1 += text_title->get_w() + margin;
1822         int w1 = gui->get_w() - x1 - 2*margin;
1823         gui->add_subwindow(text_box = new AWindowSearchTextBox(this, x1, y1, w1));
1824 }
1825
1826 int AWindowSearchText::handle_event()
1827 {
1828         gui->async_update_assets();
1829         return 1;
1830 }
1831
1832 int AWindowSearchText::get_w()
1833 {
1834         return text_box->get_w() + text_title->get_w() + 10;
1835 }
1836
1837 int AWindowSearchText::get_h()
1838 {
1839         return bmax(text_box->get_h(),text_title->get_h());
1840 }
1841
1842 void AWindowSearchText::reposition_window(int x, int y, int w)
1843 {
1844         int x1 = x, y1 = y, margin = 10;
1845         text_title->reposition_window(x1, y1);
1846         x1 += text_title->get_w() + margin;
1847         int w1 = gui->get_w() - x1 - 2*margin;
1848         text_box->reposition_window(x1, y1, w1);
1849 }
1850
1851 const char *AWindowSearchText::get_text()
1852 {
1853         return text_box->get_text();
1854 }
1855
1856 void AWindowSearchText::clear()
1857 {
1858         text_box->update("");
1859 }
1860
1861 AWindowNewFolder::AWindowNewFolder(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1862  : BC_Button(x, y, mwindow->theme->newbin_data)
1863 {
1864         this->mwindow = mwindow;
1865         this->gui = gui;
1866         set_tooltip(_("New bin"));
1867 }
1868
1869 int AWindowNewFolder::handle_event()
1870 {
1871         gui->newfolder_thread->start_new_folder();
1872         return 1;
1873 }
1874
1875 AWindowDeleteFolder::AWindowDeleteFolder(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1876  : BC_Button(x, y, mwindow->theme->deletebin_data)
1877 {
1878         this->mwindow = mwindow;
1879         this->gui = gui;
1880         set_tooltip(_("Delete bin"));
1881 }
1882
1883 int AWindowDeleteFolder::handle_event()
1884 {
1885         if( gui->folder_list->get_selection(0, 0) ) {
1886                 BC_ListBoxItem *folder = gui->folder_list->get_selection(0, 0);
1887                 mwindow->delete_folder(folder->get_text());
1888         }
1889         return 1;
1890 }
1891
1892 AWindowRenameFolder::AWindowRenameFolder(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1893  : BC_Button(x, y, mwindow->theme->renamebin_data)
1894 {
1895         this->mwindow = mwindow;
1896         this->gui = gui;
1897         set_tooltip(_("Rename bin"));
1898 }
1899
1900 int AWindowRenameFolder::handle_event()
1901 {
1902         return 1;
1903 }
1904
1905 AWindowDeleteDisk::AWindowDeleteDisk(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1906  : BC_Button(x, y, mwindow->theme->deletedisk_data)
1907 {
1908         this->mwindow = mwindow;
1909         this->gui = gui;
1910         set_tooltip(_("Delete asset from disk"));
1911 }
1912
1913 int AWindowDeleteDisk::handle_event()
1914 {
1915         return 1;
1916 }
1917
1918 AWindowDeleteProject::AWindowDeleteProject(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1919  : BC_Button(x, y, mwindow->theme->deleteproject_data)
1920 {
1921         this->mwindow = mwindow;
1922         this->gui = gui;
1923         set_tooltip(_("Delete asset from project"));
1924 }
1925
1926 int AWindowDeleteProject::handle_event()
1927 {
1928         return 1;
1929 }
1930
1931 // AWindowInfo::AWindowInfo(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1932 //  : BC_Button(x, y, mwindow->theme->infoasset_data)
1933 // {
1934 //      this->mwindow = mwindow;
1935 //      this->gui = gui;
1936 //      set_tooltip(_("Edit information on asset"));
1937 // }
1938 // 
1939 // int AWindowInfo::handle_event()
1940 // {
1941 //      int cur_x, cur_y;
1942 //      gui->get_abs_cursor(cur_x, cur_y, 0);
1943 //      gui->awindow->asset_edit->edit_asset(gui->selected_asset(), cur_x, cur_y);
1944 //      return 1;
1945 // }
1946
1947 AWindowRedrawIndex::AWindowRedrawIndex(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1948  : BC_Button(x, y, mwindow->theme->redrawindex_data)
1949 {
1950         this->mwindow = mwindow;
1951         this->gui = gui;
1952         set_tooltip(_("Redraw index"));
1953 }
1954
1955 int AWindowRedrawIndex::handle_event()
1956 {
1957         return 1;
1958 }
1959
1960 AWindowPaste::AWindowPaste(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1961  : BC_Button(x, y, mwindow->theme->pasteasset_data)
1962 {
1963         this->mwindow = mwindow;
1964         this->gui = gui;
1965         set_tooltip(_("Paste asset on recordable tracks"));
1966 }
1967
1968 int AWindowPaste::handle_event()
1969 {
1970         return 1;
1971 }
1972
1973 AWindowAppend::AWindowAppend(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1974  : BC_Button(x, y, mwindow->theme->appendasset_data)
1975 {
1976         this->mwindow = mwindow;
1977         this->gui = gui;
1978         set_tooltip(_("Append asset in new tracks"));
1979 }
1980
1981 int AWindowAppend::handle_event()
1982 {
1983         return 1;
1984 }
1985
1986 AWindowView::AWindowView(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1987  : BC_Button(x, y, mwindow->theme->viewasset_data)
1988 {
1989         this->mwindow = mwindow;
1990         this->gui = gui;
1991         set_tooltip(_("View asset"));
1992 }
1993
1994 int AWindowView::handle_event()
1995 {
1996         return 1;
1997 }
1998
1999 AddTools::AddTools(MWindow *mwindow, AWindowGUI *gui, int x, int y, const char *title)
2000  : BC_PopupMenu(x, y, BC_Title::calculate_w(gui, title, MEDIUMFONT)+8, title, -1, 0, 4)
2001 {
2002         this->mwindow = mwindow;
2003         this->gui = gui;
2004 }
2005
2006 void AddTools::create_objects()
2007 {
2008         uint64_t vis = 0;
2009         add_item(new AddPluginItem(this, "ladspa", PLUGIN_LADSPA_ID));
2010         vis |= 1 << PLUGIN_LADSPA_ID;
2011         add_item(new AddPluginItem(this, "ffmpeg", PLUGIN_FFMPEG_ID));
2012         vis |= 1 << PLUGIN_FFMPEG_ID;
2013         for( int i=0; i<MWindow::plugindb->size(); ++i ) {
2014                 PluginServer *plugin = MWindow::plugindb->get(i);
2015                 if( !plugin->audio && !plugin->video ) continue;
2016                 int idx = plugin->dir_idx;
2017                 uint32_t msk = 1 << idx;
2018                 if( (msk & vis) != 0 ) continue;
2019                 vis |= msk;
2020                 char parent[BCTEXTLEN];
2021                 strcpy(parent, plugin->path);
2022                 char *bp = strrchr(parent, '/');
2023                 if( bp ) { *bp = 0;  bp = strrchr(parent, '/'); }
2024                 if( !bp ) bp = parent; else ++bp;
2025                 add_item(new AddPluginItem(this, bp, idx));
2026         }
2027 }
2028
2029 #if 0
2030 // plugin_dirs list from toplevel makefile include plugin_defs
2031 N_("ladspa")
2032 N_("ffmpeg")
2033 N_("audio_tools")
2034 N_("audio_transitions")
2035 N_("blending")
2036 N_("colors")
2037 N_("exotic")
2038 N_("transforms")
2039 N_("tv_effects")
2040 N_("video_tools")
2041 N_("video_transitions")
2042 #endif
2043
2044 AddPluginItem::AddPluginItem(AddTools *menu, char const *text, int idx)
2045  : BC_MenuItem(_(text))
2046 {
2047         this->menu = menu;
2048         this->idx = idx;
2049         uint64_t msk = (uint64_t)1 << idx, vis = menu->gui->plugin_visibility;
2050         int chk = (msk & vis) ? 1 : 0;
2051         set_checked(chk);
2052 }
2053
2054 int AddPluginItem::handle_event()
2055 {
2056         int chk = get_checked() ^ 1;
2057         set_checked(chk);
2058         uint64_t msk = (uint64_t)1 << idx, vis = menu->gui->plugin_visibility;
2059         menu->gui->plugin_visibility = chk ? vis | msk : vis & ~msk;
2060         menu->gui->update_effects();
2061         menu->gui->save_defaults(menu->mwindow->defaults);
2062         menu->gui->async_update_assets();
2063         return 1;
2064 }
2065
2066 AVIconDrawing::AVIconDrawing(AWindowGUI *agui, int x, int y, VFrame **images)
2067  : BC_Toggle(x, y, images, agui->vicon_drawing)
2068 {
2069         this->agui = agui;
2070         set_tooltip(_("draw vicons"));
2071 }
2072
2073 void AVIconDrawing::calculate_geometry(AWindowGUI *agui, VFrame **images, int *ww, int *hh)
2074 {
2075         int text_line = -1, toggle_x = -1, toggle_y = -1;
2076         int text_x = -1, text_y = -1, text_w = -1, text_h = -1;
2077         BC_Toggle::calculate_extents(agui, images, 1,
2078                 &text_line, ww, hh, &toggle_x, &toggle_y,
2079                 &text_x, &text_y, &text_w, &text_h, "", MEDIUMFONT);
2080 }
2081
2082 AVIconDrawing::~AVIconDrawing()
2083 {
2084 }
2085
2086 int AVIconDrawing::handle_event()
2087 {
2088         agui->vicon_drawing = get_value();
2089         if( agui->vicon_drawing )
2090                 agui->start_vicon_drawing();
2091         else
2092                 agui->stop_vicon_drawing();
2093         return 1;
2094 }
2095
2096
2097 AWindowListFormat::AWindowListFormat(MWindow *mwindow, AWindowGUI *gui)
2098  : BC_MenuItem("")
2099 {
2100         this->mwindow = mwindow;
2101         this->gui = gui;
2102 }
2103
2104 int AWindowListFormat::handle_event()
2105 {
2106         gui->stop_vicon_drawing();
2107
2108         EDLSession *session = mwindow->edl->session;
2109         switch( session->assetlist_format ) {
2110         case ASSETS_TEXT:
2111                 session->assetlist_format = ASSETS_ICONS;
2112                 break;
2113         case ASSETS_ICONS:
2114                 session->assetlist_format = ASSETS_TEXT;
2115                 break;
2116         }
2117
2118         gui->asset_list->update_format(session->assetlist_format, 1);
2119         if( !mwindow->awindow->gui->allow_iconlisting ) {
2120                 mwindow->edl->session->assetlist_format = ASSETS_TEXT;
2121         }
2122
2123         gui->start_vicon_drawing();
2124         return 1;
2125 }
2126
2127 void AWindowListFormat::update()
2128 {
2129         set_text(mwindow->edl->session->assetlist_format == ASSETS_TEXT ?
2130                 (char*)_("Display icons") : (char*)_("Display text"));
2131 }
2132
2133 AWindowListSort::AWindowListSort(MWindow *mwindow, AWindowGUI *gui)
2134  : BC_MenuItem(_("Sort items"))
2135 {
2136         this->mwindow = mwindow;
2137         this->gui = gui;
2138 }
2139
2140 int AWindowListSort::handle_event()
2141 {
2142         gui->sort_assets(0);
2143         return 1;
2144 }
2145