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