add ffmpeg indexing
[goodguy/history.git] / cinelerra-5.0 / 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 "awindowgui.inc"
28 #include "awindow.h"
29 #include "awindowmenu.h"
30 #include "bcsignals.h"
31 #include "cache.h"
32 #include "bccmodels.h"
33 #include "cursors.h"
34 #include "cwindowgui.h"
35 #include "cwindow.h"
36 #include "edl.h"
37 #include "edlsession.h"
38 #include "file.h"
39 #include "filesystem.h"
40 #include "indexable.h"
41 #include "keys.h"
42 #include "language.h"
43 #include "localsession.h"
44 #include "mainmenu.h"
45 #include "mainsession.h"
46 #include "mwindowgui.h"
47 #include "mwindow.h"
48 #include "nestededls.h"
49 #include "newfolder.h"
50 #include "preferences.h"
51 #include "theme.h"
52 #include "vframe.h"
53 #include "vwindowgui.h"
54 #include "vwindow.h"
55
56 #include "data/lad_picon_png.h"
57
58 #include<stdio.h>
59 #include<unistd.h>
60 #include<fcntl.h>
61
62 AssetPicon::AssetPicon(MWindow *mwindow, 
63         AWindowGUI *gui, 
64         Indexable *indexable)
65  : BC_ListBoxItem()
66 {
67         reset();
68         this->mwindow = mwindow;
69         this->gui = gui;
70         this->indexable = indexable;
71         indexable->add_user();
72         this->id = indexable->id;
73 }
74
75 AssetPicon::AssetPicon(MWindow *mwindow, 
76         AWindowGUI *gui, 
77         EDL *edl)
78  : BC_ListBoxItem()
79 {
80         reset();
81         this->mwindow = mwindow;
82         this->gui = gui;
83         this->edl = edl;
84         edl->add_user();
85         this->id = edl->id;
86 }
87
88 AssetPicon::AssetPicon(MWindow *mwindow, 
89         AWindowGUI *gui, 
90         const char *folder)
91  : BC_ListBoxItem(folder, gui->folder_icon)
92 {
93         reset();
94         this->mwindow = mwindow;
95         this->gui = gui;
96 }
97
98 AssetPicon::AssetPicon(MWindow *mwindow, 
99         AWindowGUI *gui, 
100         PluginServer *plugin)
101  : BC_ListBoxItem()
102 {
103         reset();
104         this->mwindow = mwindow;
105         this->gui = gui;
106         this->plugin = plugin;
107 }
108
109
110 AssetPicon::~AssetPicon()
111 {
112         if(indexable) indexable->remove_user();
113         if(edl) edl->remove_user();
114         if( icon && !gui->protected_pixmap(icon) ) {
115                 delete icon;
116                 if( !plugin ) delete icon_vframe;
117         }
118 }
119
120 void AssetPicon::reset()
121 {
122         plugin = 0;
123         indexable = 0;
124         edl = 0;
125         icon = 0;
126         icon_vframe = 0;
127         in_use = 1;
128         id = 0;
129         persistent = 0;
130 }
131
132 void AssetPicon::create_objects()
133 {
134         FileSystem fs;
135         char name[BCTEXTLEN];
136         int pixmap_w, pixmap_h;
137         const int debug = 0;
138
139         pixmap_h = 50;
140
141         if(debug) printf("AssetPicon::create_objects %d\n", __LINE__);
142         if(indexable)
143         {
144                 fs.extract_name(name, indexable->path);
145                 set_text(name);
146         }
147         
148         if(indexable && indexable->is_asset)
149         {
150                 if(debug) printf("AssetPicon::create_objects %d\n", __LINE__);
151                 Asset *asset = (Asset*)indexable;
152                 if(asset->video_data)
153                 {
154                         if(mwindow->preferences->use_thumbnails)
155                         {
156                                 gui->unlock_window();
157                                 if(debug) printf("AssetPicon::create_objects %d\n", __LINE__);
158                                 File *file = mwindow->video_cache->check_out(asset, 
159                                         mwindow->edl,
160                                         1);
161                                 if(debug) printf("AssetPicon::create_objects %d\n", __LINE__);
162
163                                 if(file)
164                                 {
165                                         int height = asset->height > 0 ? asset->height : 1;
166                                         pixmap_w = pixmap_h * asset->width / height;
167
168                                         file->set_layer(0);
169                                         file->set_video_position(0, 0);
170
171                                         if(gui->temp_picon && 
172                                                 (gui->temp_picon->get_w() != asset->width ||
173                                                 gui->temp_picon->get_h() != asset->height))
174                                         {
175                                                 delete gui->temp_picon;
176                                                 gui->temp_picon = 0;
177                                         }
178
179                                         if(!gui->temp_picon)
180                                         {
181                                                 gui->temp_picon = new VFrame(0, -1,
182                                                         asset->width, asset->height, 
183                                                         BC_RGB888, -1);
184                                         }
185
186                                         file->read_frame(gui->temp_picon);
187                                         if(debug) printf("AssetPicon::create_objects %d\n", __LINE__);
188                                         mwindow->video_cache->check_in(asset);
189
190                                         gui->lock_window("AssetPicon::create_objects 1");
191                                         icon = new BC_Pixmap(gui, pixmap_w, pixmap_h);
192                                         icon->draw_vframe(gui->temp_picon,
193                                                 0, 0, pixmap_w, pixmap_h, 0, 0);
194 //printf("%d %d\n", gui->temp_picon->get_w(), gui->temp_picon->get_h());
195                                         icon_vframe = new VFrame(0,
196                                                 -1, pixmap_w, pixmap_h, BC_RGB888, -1);
197                                         BC_CModels::transfer(
198                                                 icon_vframe->get_rows(),
199                                                 gui->temp_picon->get_rows(),
200                                                 0, 0, 0, 0, 0, 0, 0, 0, 
201                                                 gui->temp_picon->get_w(), 
202                                                 gui->temp_picon->get_h(),
203                                                 0, 0, pixmap_w, pixmap_h,
204                                                 BC_RGB888, BC_RGB888,
205                                                 0, 0, 0);
206
207                                         if(debug) printf("AssetPicon::create_objects %d\n", __LINE__);
208
209                                 }
210                                 else
211                                 {
212                                         gui->lock_window("AssetPicon::create_objects 2");
213                                         icon = gui->video_icon;
214                                         icon_vframe = BC_WindowBase::get_resources()->type_to_icon[ICON_FILM];
215                                 }
216                         }
217                         else
218                         {
219                                 icon = gui->video_icon;
220                                 icon_vframe = BC_WindowBase::get_resources()->type_to_icon[ICON_FILM];                  
221                         }
222                 }
223                 else
224                 if(asset->audio_data)
225                 {
226                         icon = gui->audio_icon;
227                         icon_vframe = BC_WindowBase::get_resources()->type_to_icon[ICON_SOUND];
228                 }
229 //printf("AssetPicon::create_objects 2\n");
230
231                 if(debug) printf("AssetPicon::create_objects %d\n", __LINE__);
232         }
233         else
234         if(indexable && !indexable->is_asset)
235         {
236                 icon = gui->video_icon;
237                 icon_vframe = BC_WindowBase::get_resources()->type_to_icon[ICON_FILM];
238         }
239         else
240         if(edl)
241         {
242 //printf("AssetPicon::create_objects 4 %s\n", edl->local_session->clip_title);
243                 set_text(strcpy(name, edl->local_session->clip_title));
244                 icon = gui->clip_icon;
245                 icon_vframe = mwindow->theme->get_image("clip_icon");
246         }
247         else
248         if(plugin)
249         {
250                 strcpy(name, _(plugin->title));
251                 set_text(name);
252                 icon_vframe = plugin->get_picon();
253                 if( icon_vframe )
254                         icon = gui->create_pixmap(icon_vframe);
255                 else if( plugin->audio ) {
256                         if( plugin->transition ) {
257                                 icon = gui->atransition_icon;
258                                 icon_vframe = gui->atransition_vframe;
259                         }
260                         else if( !plugin->is_ladspa() ) {
261                                 icon = gui->aeffect_icon;
262                                 icon_vframe = gui->aeffect_vframe;
263                         }
264                         else {
265                                 icon = gui->ladspa_icon;
266                                 icon_vframe = gui->ladspa_vframe;
267                         }
268                 }
269                 else if( plugin->video ) {
270                         if( plugin->transition ) {
271                                 icon = gui->vtransition_icon;
272                                 icon_vframe = gui->vtransition_vframe;
273                         }
274                         else {
275                                 icon = gui->veffect_icon;
276                                 icon_vframe = gui->veffect_vframe;
277                         }
278                 }
279         }
280         if( !icon ) {
281                 icon = gui->file_icon;
282                 icon_vframe = BC_WindowBase::get_resources()->type_to_icon[ICON_UNKNOWN];
283         }
284         set_icon(icon);
285         set_icon_vframe(icon_vframe);
286
287         if(debug) printf("AssetPicon::create_objects %d\n", __LINE__);
288 }
289
290
291
292
293
294
295 AWindowGUI::AWindowGUI(MWindow *mwindow, AWindow *awindow)
296  : BC_Window(PROGRAM_NAME ": Resources",
297         mwindow->session->awindow_x, 
298     mwindow->session->awindow_y, 
299     mwindow->session->awindow_w, 
300     mwindow->session->awindow_h,
301     100,
302     100,
303     1,
304     1,
305     1)
306 {
307 // printf("AWindowGUI::AWindowGUI %d %d %d %d\n",
308 // mwindow->session->awindow_x, 
309 // mwindow->session->awindow_y, 
310 // mwindow->session->awindow_w, 
311 // mwindow->session->awindow_h);
312         this->mwindow = mwindow;
313         this->awindow = awindow;
314         file_icon = 0;
315         audio_icon = 0;
316         video_icon = 0;
317         folder_icon = 0;
318         clip_icon = 0;
319         atransition_icon = 0;  atransition_vframe = 0;
320         vtransition_icon = 0;  vtransition_vframe = 0;
321         aeffect_icon = 0;      aeffect_vframe = 0;
322         ladspa_icon = 0;       ladspa_vframe = 0;
323         veffect_icon = 0;      veffect_vframe = 0;
324         newfolder_thread = 0;
325         asset_menu = 0;
326         assetlist_menu = 0;
327         folderlist_menu = 0;
328         temp_picon = 0;
329         remove_plugin = 0;
330         plugin_visibility = ~0;
331 }
332
333 AWindowGUI::~AWindowGUI()
334 {
335         assets.remove_all_objects();
336         folders.remove_all_objects();
337         aeffects.remove_all_objects();
338         veffects.remove_all_objects();
339         atransitions.remove_all_objects();
340         vtransitions.remove_all_objects();
341         displayed_assets[1].remove_all_objects();
342         delete file_icon;
343         delete audio_icon;
344         delete video_icon;
345         delete folder_icon;
346         delete clip_icon;
347         delete atransition_icon;
348         delete vtransition_icon;
349         delete aeffect_icon;
350         delete ladspa_icon;
351         delete ladspa_vframe;
352         delete veffect_icon;
353         delete newfolder_thread;
354         delete asset_menu;
355         delete assetlist_menu;
356         delete folderlist_menu;
357         if(temp_picon) delete temp_picon;
358         delete remove_plugin;
359 }
360
361 bool AWindowGUI::protected_pixmap(BC_Pixmap *icon)
362 {
363         return  icon == file_icon ||
364                 icon == audio_icon ||
365                 icon == folder_icon ||
366                 icon == clip_icon ||
367                 icon == video_icon ||
368                 icon == veffect_icon ||
369                 icon == vtransition_icon ||
370                 icon == aeffect_icon ||
371                 icon == ladspa_icon ||
372                 icon == atransition_icon; 
373 }
374
375 void AWindowGUI::create_objects()
376 {
377         AssetPicon *picon;
378
379         lock_window("AWindowGUI::create_objects");
380 SET_TRACE
381 //printf("AWindowGUI::create_objects 1\n");
382         asset_titles[0] = _("Title");
383         asset_titles[1] = _("Comments");
384
385 SET_TRACE
386
387         set_icon(mwindow->theme->get_image("awindow_icon"));
388         file_icon = new BC_Pixmap(this, 
389                 BC_WindowBase::get_resources()->type_to_icon[ICON_UNKNOWN],
390                 PIXMAP_ALPHA);
391
392         folder_icon = new BC_Pixmap(this, 
393                 BC_WindowBase::get_resources()->type_to_icon[ICON_FOLDER],
394                 PIXMAP_ALPHA);
395
396         audio_icon = new BC_Pixmap(this, 
397                 BC_WindowBase::get_resources()->type_to_icon[ICON_SOUND],
398                 PIXMAP_ALPHA);
399
400         video_icon = new BC_Pixmap(this, 
401                 BC_WindowBase::get_resources()->type_to_icon[ICON_FILM],
402                 PIXMAP_ALPHA);
403
404 SET_TRACE
405
406         clip_vframe = mwindow->theme->get_image("clip_icon");
407         clip_icon = new BC_Pixmap(this, clip_vframe, PIXMAP_ALPHA);
408         atransition_vframe = mwindow->theme->get_image("atransition_icon");
409         atransition_icon = new BC_Pixmap(this, atransition_vframe, PIXMAP_ALPHA);
410         vtransition_vframe = mwindow->theme->get_image("vtransition_icon");
411         vtransition_icon = new BC_Pixmap(this, vtransition_vframe, PIXMAP_ALPHA);
412         aeffect_vframe = mwindow->theme->get_image("aeffect_icon");
413         aeffect_icon = new BC_Pixmap(this, aeffect_vframe, PIXMAP_ALPHA);
414         ladspa_vframe = new VFrame(lad_picon_png);
415         ladspa_icon = new BC_Pixmap(this, ladspa_vframe, PIXMAP_ALPHA);
416         veffect_vframe = mwindow->theme->get_image("veffect_icon");
417         veffect_icon = new BC_Pixmap(this, veffect_vframe, PIXMAP_ALPHA);
418
419 SET_TRACE
420
421 // Mandatory folders
422         folders.append(picon = new AssetPicon(mwindow,
423                 this,
424                 AEFFECT_FOLDER));
425         picon->persistent = 1;
426         folders.append(picon = new AssetPicon(mwindow,
427                 this,
428                 VEFFECT_FOLDER));
429         picon->persistent = 1;
430         folders.append(picon = new AssetPicon(mwindow,
431                 this,
432                 ATRANSITION_FOLDER));
433         picon->persistent = 1;
434         folders.append(picon = new AssetPicon(mwindow,
435                 this,
436                 VTRANSITION_FOLDER));
437         picon->persistent = 1;
438 SET_TRACE
439
440         mwindow->theme->get_awindow_sizes(this);
441
442 SET_TRACE
443         add_subwindow(asset_list = new AWindowAssets(mwindow,
444                 this,
445                 mwindow->theme->alist_x, 
446                 mwindow->theme->alist_y, 
447                 mwindow->theme->alist_w, 
448                 mwindow->theme->alist_h));
449
450 SET_TRACE
451         add_subwindow(divider = new AWindowDivider(mwindow,
452                 this,
453                 mwindow->theme->adivider_x,
454                 mwindow->theme->adivider_y,
455                 mwindow->theme->adivider_w,
456                 mwindow->theme->adivider_h));
457
458 SET_TRACE
459         divider->set_cursor(HSEPARATE_CURSOR, 0, 0);
460
461 SET_TRACE
462         int fx = mwindow->theme->afolders_x, fy = mwindow->theme->afolders_y; 
463         int fw = mwindow->theme->afolders_w, fh = mwindow->theme->afolders_h; 
464         add_subwindow(add_tools = new AddTools(mwindow, this, fx, fy, fw));
465         add_tools->create_objects();
466         fy += add_tools->get_h();  fh -= add_tools->get_h();
467 SET_TRACE
468         add_subwindow(folder_list = new AWindowFolders(mwindow,
469                 this, fx, fy, fw, fh));
470 SET_TRACE
471         update_effects();
472 SET_TRACE
473
474         //int x = mwindow->theme->abuttons_x;
475         //int y = mwindow->theme->abuttons_y;
476
477 SET_TRACE
478
479         newfolder_thread = new NewFolderThread(mwindow, this);
480
481         add_subwindow(asset_menu = new AssetPopup(mwindow, this));
482         asset_menu->create_objects();
483
484 SET_TRACE
485
486         add_subwindow(assetlist_menu = new AssetListMenu(mwindow, this));
487
488 SET_TRACE
489         assetlist_menu->create_objects();
490
491 SET_TRACE
492
493         add_subwindow(folderlist_menu = new FolderListMenu(mwindow, this));
494         folderlist_menu->create_objects();
495 //printf("AWindowGUI::create_objects 2\n");
496
497 SET_TRACE
498         unlock_window();
499 }
500
501 int AWindowGUI::resize_event(int w, int h)
502 {
503         mwindow->session->awindow_x = get_x();
504         mwindow->session->awindow_y = get_y();
505         mwindow->session->awindow_w = w;
506         mwindow->session->awindow_h = h;
507
508         mwindow->theme->get_awindow_sizes(this);
509         mwindow->theme->draw_awindow_bg(this);
510
511         asset_list->reposition_window(mwindow->theme->alist_x, 
512         mwindow->theme->alist_y, 
513         mwindow->theme->alist_w, 
514         mwindow->theme->alist_h);
515         divider->reposition_window(mwindow->theme->adivider_x,
516                 mwindow->theme->adivider_y,
517                 mwindow->theme->adivider_w,
518                 mwindow->theme->adivider_h);
519
520         int fx = mwindow->theme->afolders_x, fy = mwindow->theme->afolders_y; 
521         int fw = mwindow->theme->afolders_w, fh = mwindow->theme->afolders_h; 
522         add_tools->reposition_window(fx, fy, fw, add_tools->get_h());
523         fy += add_tools->get_h();  fh -= add_tools->get_h();
524         folder_list->reposition_window(fx, fy, fw, fh);
525         
526 //      int x = mwindow->theme->abuttons_x;
527 //      int y = mwindow->theme->abuttons_y;
528 //      new_bin->reposition_window(x, y);
529 //      x += new_bin->get_w();
530 //      delete_bin->reposition_window(x, y);
531 //      x += delete_bin->get_w();
532 //      rename_bin->reposition_window(x, y);
533 //      x += rename_bin->get_w();
534 //      delete_disk->reposition_window(x, y);
535 //      x += delete_disk->get_w();
536 //      delete_project->reposition_window(x, y);
537 //      x += delete_project->get_w();
538 //      info->reposition_window(x, y);
539 //      x += info->get_w();
540 //      redraw_index->reposition_window(x, y);
541 //      x += redraw_index->get_w();
542 //      paste->reposition_window(x, y);
543 //      x += paste->get_w();
544 //      append->reposition_window(x, y);
545 //      x += append->get_w();
546 //      view->reposition_window(x, y);
547
548         BC_WindowBase::resize_event(w, h);
549         return 1;
550 }
551
552 int AWindowGUI::translation_event()
553 {
554         mwindow->session->awindow_x = get_x();
555         mwindow->session->awindow_y = get_y();
556         return 0;
557 }
558
559 void AWindowGUI::reposition_objects()
560 {
561         mwindow->theme->get_awindow_sizes(this);
562         asset_list->reposition_window(mwindow->theme->alist_x, 
563         mwindow->theme->alist_y, 
564         mwindow->theme->alist_w, 
565         mwindow->theme->alist_h);
566         divider->reposition_window(mwindow->theme->adivider_x,
567                 mwindow->theme->adivider_y,
568                 mwindow->theme->adivider_w,
569                 mwindow->theme->adivider_h);
570         folder_list->reposition_window(mwindow->theme->afolders_x, 
571         mwindow->theme->afolders_y, 
572         mwindow->theme->afolders_w, 
573         mwindow->theme->afolders_h);
574         flush();
575 }
576
577 int AWindowGUI::close_event()
578 {
579         hide_window();
580         mwindow->session->show_awindow = 0;
581         unlock_window();
582
583         mwindow->gui->lock_window("AWindowGUI::close_event");
584         mwindow->gui->mainmenu->show_awindow->set_checked(0);
585         mwindow->gui->unlock_window();
586
587         lock_window("AWindowGUI::close_event");
588         mwindow->save_defaults();
589         return 1;
590 }
591
592 AWindowRemovePluginGUI::
593 AWindowRemovePluginGUI(AWindow *awindow, AWindowRemovePlugin *thread,
594         int x, int y, PluginServer *plugin)
595  : BC_Window(PROGRAM_NAME ": Remove plugin", x,y, 500,200, 50, 50, 1, 0, 1, -1, "", 1)
596 {
597         this->awindow = awindow;
598         this->thread = thread;
599         this->plugin = plugin;
600         VFrame *vframe = plugin->get_picon();
601         icon = vframe ? create_pixmap(vframe) : 0;
602         plugin_list.append(new BC_ListBoxItem(plugin->title, icon));
603 }
604
605 AWindowRemovePluginGUI::
606 ~AWindowRemovePluginGUI()
607 {
608         if( !awindow->gui->protected_pixmap(icon) )
609                 delete icon;
610         plugin_list.remove_all();
611 }
612
613 void AWindowRemovePluginGUI::create_objects()
614 {
615         BC_Button *ok_button = new BC_OKButton(this);
616         add_subwindow(ok_button);
617         BC_Button *cancel_button = new BC_CancelButton(this);
618         add_subwindow(cancel_button);
619         int x = 10, y = 10;
620         BC_Title *title = new BC_Title(x, y, _("remove plugin?"));
621         add_subwindow(title);
622         y += title->get_h() + 5;
623         list = new BC_ListBox(x, y,
624                 get_w() - 20, ok_button->get_y() - y - 5, LISTBOX_TEXT, &plugin_list,
625                 0, 0, 1, 0, 0, LISTBOX_SINGLE, ICON_LEFT, 0);
626         add_subwindow(list);
627         show_window();
628 }
629
630 int AWindowRemovePlugin::remove_plugin(PluginServer *plugin, ArrayList<BC_ListBoxItem*> &folder)
631 {
632         int ret = 0;
633         for( int i=0; i<folder.size(); ) {
634                 AssetPicon *picon = (AssetPicon *)folder[i];
635                 if( picon->plugin == plugin ) {
636                         folder.remove_object_number(i);
637                         ++ret;
638                         continue;
639                 }
640                 ++i;
641         }
642         return ret;
643 }
644
645 void AWindowRemovePlugin::handle_close_event(int result)
646 {
647         if( !result ) {
648                 printf("remove %s\n", plugin->path);
649                 ArrayList<BC_ListBoxItem*> *folder = 
650                         plugin->audio ? plugin->transition ?
651                                 &awindow->gui->atransitions :
652                                 &awindow->gui->aeffects :
653                         plugin->video ?  plugin->transition ?
654                                 &awindow->gui->vtransitions :
655                                 &awindow->gui->veffects :
656                         0;
657                 if( folder ) remove_plugin(plugin, *folder);
658                 awindow->gui->update_assets();
659                 char png_path[BCTEXTLEN], plugin_path[BCTEXTLEN], index_path[BCTEXTLEN];
660                 strcpy(plugin_path, plugin->path);
661                 if( !plugin->get_plugin_png_path(png_path) ) png_path[0] = 0;
662                 MWindow *mwindow = awindow->mwindow;
663                 sprintf(index_path, "%s/%s", mwindow->preferences->plugin_dir, PLUGIN_FILE);
664                 mwindow->plugindb->remove(plugin);
665                 plugin->delete_this();
666                 remove(plugin_path);
667                 if( png_path[0] ) remove(png_path);
668                 remove(index_path);
669         }
670 }
671
672 AWindowRemovePlugin::
673 AWindowRemovePlugin(AWindow *awindow, PluginServer *plugin)
674  : BC_DialogThread()
675 {
676         this->awindow = awindow;
677         this->plugin = plugin;
678 }
679
680 AWindowRemovePlugin::
681 ~AWindowRemovePlugin()
682 {
683         close_window();
684 }
685
686 BC_Window* AWindowRemovePlugin::new_gui()
687 {
688         int x = awindow->gui->get_abs_cursor_x(0);
689         int y = awindow->gui->get_abs_cursor_y(0);
690         AWindowRemovePluginGUI *gui = new AWindowRemovePluginGUI(awindow, this, x, y, plugin);
691         gui->create_objects();
692         return gui;
693 }
694
695 int AWindowGUI::keypress_event()
696 {
697         switch(get_keypress()) {
698         case 'w': case 'W':
699                 if(ctrl_down()) {
700                         close_event();
701                         return 1;
702                 }
703                 break;
704         case DELETE:
705                 if(shift_down()) {
706                         PluginServer* plugin = selected_plugin();
707                         if( !plugin ) break;
708                         remove_plugin = new AWindowRemovePlugin(awindow, plugin);
709                         unlock_window();
710                         remove_plugin->start();
711                         lock_window();
712                 }
713         }
714         return 0;
715 }
716
717 void AWindowGUI::update_folder_list()
718 {
719 //printf("AWindowGUI::update_folder_list 1\n");
720         for(int i = 0; i < folders.total; i++)
721         {
722                 AssetPicon *picon = (AssetPicon*)folders.values[i];
723                 picon->in_use--;
724         }
725 //printf("AWindowGUI::update_folder_list 1\n");
726
727 // Search assets for folders
728         for(int i = 0; i < mwindow->edl->folders.total; i++)
729         {
730                 char *folder = mwindow->edl->folders.values[i];
731                 int exists = 0;
732 //printf("AWindowGUI::update_folder_list 1.1\n");
733
734                 for(int j = 0; j < folders.total; j++)
735                 {
736                         AssetPicon *picon = (AssetPicon*)folders.values[j];
737                         if(!strcasecmp(picon->get_text(), folder))
738                         {
739                                 exists = 1;
740                                 picon->in_use = 1;
741                                 break;
742                         }
743                 }
744
745                 if(!exists)
746                 {
747                         AssetPicon *picon = new AssetPicon(mwindow, this, folder);
748                         picon->create_objects();
749                         folders.append(picon);
750                 }
751 //printf("AWindowGUI::update_folder_list 1.3\n");
752         }
753 //printf("AWindowGUI::update_folder_list 1\n");
754 //for(int i = 0; i < folders.total; i++)
755 //      printf("AWindowGUI::update_folder_list %s\n", folders.values[i]->get_text());
756
757 // Delete excess
758         for(int i = folders.total - 1; i >= 0; i--)
759         {
760                 AssetPicon *picon = (AssetPicon*)folders.values[i];
761                 if(!picon->in_use && !picon->persistent)
762                 {
763                         delete picon;
764                         folders.remove_number(i);
765                 }
766         }
767 //for(int i = 0; i < folders.total; i++)
768 //      printf("AWindowGUI::update_folder_list %s\n", folders.values[i]->get_text());
769 //printf("AWindowGUI::update_folder_list 2\n");
770 }
771
772 void AWindowGUI::create_persistent_folder(ArrayList<BC_ListBoxItem*> *output, 
773         int do_audio, int do_video, int is_realtime, int is_transition)
774 {
775         ArrayList<PluginServer*> plugin_list;
776 // Get pointers to plugindb entries
777         mwindow->search_plugindb(do_audio, do_video, is_realtime, is_transition,
778                         0, plugin_list);
779
780         for(int i = 0; i < plugin_list.total; i++) {
781                 PluginServer *server = plugin_list.values[i];
782                 int visible = plugin_visibility & (1<<server->dir_idx);
783                 if(!visible) continue;
784 // Create new listitem
785                 AssetPicon *picon = new AssetPicon(mwindow, this, server);
786                 picon->create_objects();
787                 output->append(picon);
788         }
789 }
790
791 void AWindowGUI::update_asset_list()
792 {
793 //printf("AWindowGUI::update_asset_list 1\n");
794         for(int i = 0; i < assets.total; i++)
795         {
796                 AssetPicon *picon = (AssetPicon*)assets.values[i];
797                 picon->in_use--;
798         }
799
800
801
802
803
804 //printf("AWindowGUI::update_asset_list 2\n");
805
806
807 // Synchronize EDL clips
808         for(int i = 0; i < mwindow->edl->clips.total; i++)
809         {
810                 int exists = 0;
811                 
812 // Look for clip in existing listitems
813                 for(int j = 0; j < assets.total && !exists; j++)
814                 {
815                         AssetPicon *picon = (AssetPicon*)assets.values[j];
816                         
817                         if(picon->id == mwindow->edl->clips.values[i]->id)
818                         {
819                                 picon->edl = mwindow->edl->clips.values[i];
820                                 picon->set_text(mwindow->edl->clips.values[i]->local_session->clip_title);
821                                 exists = 1;
822                                 picon->in_use = 1;
823                         }
824                 }
825
826 // Create new listitem
827                 if(!exists)
828                 {
829                         AssetPicon *picon = new AssetPicon(mwindow, 
830                                 this, 
831                                 mwindow->edl->clips.values[i]);
832                         picon->create_objects();
833                         assets.append(picon);
834                 }
835         }
836
837
838
839
840
841 //printf("AWindowGUI::update_asset_list %d\n", __LINE__);
842
843
844 // Synchronize EDL assets
845         for(Asset *current = mwindow->edl->assets->first; 
846                 current; 
847                 current = NEXT)
848         {
849                 int exists = 0;
850
851 // Look for asset in existing listitems
852                 for(int j = 0; j < assets.total && !exists; j++)
853                 {
854                         AssetPicon *picon = (AssetPicon*)assets.values[j];
855
856                         if(picon->id == current->id)
857                         {
858                                 picon->indexable = current;
859                                 exists = 1;
860                                 picon->in_use = 1;
861                                 break;
862                         }
863                 }
864
865 // Create new listitem
866                 if(!exists)
867                 {
868 //printf("AWindowGUI::update_asset_list %d\n", __LINE__);
869                         AssetPicon *picon = new AssetPicon(mwindow, this, current);
870 //printf("AWindowGUI::update_asset_list %d\n", __LINE__);
871                         picon->create_objects();
872 //printf("AWindowGUI::update_asset_list %d\n", __LINE__);
873                         assets.append(picon);
874                 }
875         }
876
877
878
879 //printf("AWindowGUI::update_asset_list %d\n", __LINE__);
880
881
882 // Synchronize nested EDLs
883         for(int i = 0; i < mwindow->edl->nested_edls->size(); i++)
884         {
885                 int exists = 0;
886                 Indexable *indexable = mwindow->edl->nested_edls->get(i);
887
888 // Look for asset in existing listitems
889                 for(int j = 0; j < assets.total && !exists; j++)
890                 {
891                         AssetPicon *picon = (AssetPicon*)assets.values[j];
892
893                         if(picon->id == indexable->id)
894                         {
895                                 picon->indexable = indexable;
896                                 exists = 1;
897                                 picon->in_use = 1;
898                                 break;
899                         }
900                 }
901
902 // Create new listitem
903                 if(!exists)
904                 {
905                         AssetPicon *picon = new AssetPicon(mwindow, 
906                                 this, 
907                                 indexable);
908                         picon->create_objects();
909                         assets.append(picon);
910                 }
911         }
912
913
914
915
916
917
918
919
920
921 //printf("AWindowGUI::update_asset_list %d\n", __LINE__);
922         for(int i = assets.size() - 1; i >= 0; i--)
923         {
924                 AssetPicon *picon = (AssetPicon*)assets.get(i);
925 //printf("AWindowGUI::update_asset_list %s %d\n", picon->asset->path, picon->in_use);
926                 if(!picon->in_use)
927                 {
928                         delete picon;
929                         assets.remove_number(i);
930                 }
931         }
932 //printf("AWindowGUI::update_asset_list 7 %d\n", assets.total);
933 }
934
935
936
937
938
939 void AWindowGUI::sort_assets()
940 {
941 //printf("AWindowGUI::sort_assets 1 %s\n", mwindow->edl->session->current_folder);
942         if(!strcasecmp(mwindow->edl->session->current_folder, AEFFECT_FOLDER))
943                 sort_picons(&aeffects, 
944                         0);
945         else
946         if(!strcasecmp(mwindow->edl->session->current_folder, VEFFECT_FOLDER))
947                 sort_picons(&veffects, 
948                         0);
949         else
950         if(!strcasecmp(mwindow->edl->session->current_folder, ATRANSITION_FOLDER))
951                 sort_picons(&atransitions, 
952                         0);
953         else
954         if(!strcasecmp(mwindow->edl->session->current_folder, VTRANSITION_FOLDER))
955                 sort_picons(&vtransitions, 
956                         0);
957         else
958                 sort_picons(&assets, 
959                         mwindow->edl->session->current_folder);
960
961         update_assets();
962 }
963
964
965
966
967
968
969
970
971
972
973
974 void AWindowGUI::collect_assets()
975 {
976         int i = 0;
977         mwindow->session->drag_assets->remove_all();
978         mwindow->session->drag_clips->remove_all();
979         while(1)
980         {
981                 AssetPicon *result = (AssetPicon*)asset_list->get_selection(0, i++);
982                 if(!result) break;
983
984                 if(result->indexable) mwindow->session->drag_assets->append(result->indexable);
985                 if(result->edl) mwindow->session->drag_clips->append(result->edl);
986         }
987 }
988
989 void AWindowGUI::copy_picons(ArrayList<BC_ListBoxItem*> *dst, 
990         ArrayList<BC_ListBoxItem*> *src, 
991         char *folder)
992 {
993 // Remove current pointers
994         dst[0].remove_all();
995         dst[1].remove_all_objects();
996
997 // Create new pointers
998 //if(folder) printf("AWindowGUI::copy_picons 1 %s\n", folder);
999         for(int i = 0; i < src->total; i++)
1000         {
1001                 AssetPicon *picon = (AssetPicon*)src->values[i];
1002 //printf("AWindowGUI::copy_picons 2 %s\n", picon->asset->folder);
1003                 if(!folder ||
1004                         (folder && picon->indexable && !strcasecmp(picon->indexable->folder, folder)) ||
1005                         (folder && picon->edl && !strcasecmp(picon->edl->local_session->folder, folder)))
1006                 {
1007                         BC_ListBoxItem *item2, *item1;
1008                         dst[0].append(item1 = picon);
1009                         if(picon->edl)
1010                                 dst[1].append(item2 = new BC_ListBoxItem(picon->edl->local_session->clip_notes));
1011                         else
1012                                 dst[1].append(item2 = new BC_ListBoxItem(""));
1013                         item1->set_autoplace_text(1);
1014                         item2->set_autoplace_text(1);
1015 //printf("AWindowGUI::copy_picons 3 %s\n", picon->get_text());
1016                 }
1017         }
1018 }
1019
1020 void AWindowGUI::sort_picons(ArrayList<BC_ListBoxItem*> *src, 
1021                 char *folder)
1022 {
1023 //printf("AWindowGUI::sort_picons 1\n")
1024         int done = 0;
1025         while(!done)
1026         {
1027                 done = 1;
1028                 for(int i = 0; i < src->total - 1; i++)
1029                 {
1030                         BC_ListBoxItem *item1 = src->values[i];
1031                         BC_ListBoxItem *item2 = src->values[i + 1];
1032                         item1->set_autoplace_icon(1);
1033                         item2->set_autoplace_icon(1);
1034                         item1->set_autoplace_text(1);
1035                         item2->set_autoplace_text(1);
1036                         if(strcmp(item1->get_text(), item2->get_text()) > 0)
1037                         {
1038                                 src->values[i + 1] = item1;
1039                                 src->values[i] = item2;
1040                                 done = 0;
1041                         }
1042                 }
1043         }
1044 }
1045
1046
1047 void AWindowGUI::filter_displayed_assets()
1048 {
1049         if(!strcasecmp(mwindow->edl->session->current_folder, AEFFECT_FOLDER))
1050                 copy_picons(displayed_assets, 
1051                         &aeffects, 
1052                         0);
1053         else
1054         if(!strcasecmp(mwindow->edl->session->current_folder, VEFFECT_FOLDER))
1055                 copy_picons(displayed_assets, 
1056                         &veffects, 
1057                         0);
1058         else
1059         if(!strcasecmp(mwindow->edl->session->current_folder, ATRANSITION_FOLDER))
1060                 copy_picons(displayed_assets, 
1061                         &atransitions, 
1062                         0);
1063         else
1064         if(!strcasecmp(mwindow->edl->session->current_folder, VTRANSITION_FOLDER))
1065                 copy_picons(displayed_assets, 
1066                         &vtransitions, 
1067                         0);
1068         else
1069                 copy_picons(displayed_assets, 
1070                         &assets, 
1071                         mwindow->edl->session->current_folder);
1072 }
1073
1074
1075 void AWindowGUI::update_assets()
1076 {
1077 //printf("AWindowGUI::update_assets 1\n");
1078         update_folder_list();
1079 //printf("AWindowGUI::update_assets 2\n");
1080         update_asset_list();
1081 //printf("AWindowGUI::update_assets 3\n");
1082         filter_displayed_assets();
1083
1084 //for(int i = 0; i < folders.total; i++)
1085 //printf("AWindowGUI::update_assets 4\n");
1086 //      printf("AWindowGUI::update_assets %s\n", folders.values[i]->get_text());
1087         if(mwindow->edl->session->folderlist_format != folder_list->get_format())
1088                 folder_list->update_format(mwindow->edl->session->folderlist_format, 0);
1089         folder_list->update(&folders,
1090                 0,
1091                 0,
1092                 1,
1093                 folder_list->get_xposition(),
1094                 folder_list->get_yposition(),
1095                 -1);
1096 //printf("AWindowGUI::update_assets 5\n");
1097
1098         if(mwindow->edl->session->assetlist_format != asset_list->get_format())
1099                 asset_list->update_format(mwindow->edl->session->assetlist_format, 0);
1100
1101
1102 //printf("AWindowGUI::update_assets 6 %d\n", displayed_assets[0].total);
1103         asset_list->update(displayed_assets,
1104                 asset_titles,
1105                 mwindow->edl->session->asset_columns,
1106                 ASSET_COLUMNS, 
1107                 asset_list->get_xposition(),
1108                 asset_list->get_yposition(),
1109                 -1,
1110                 0);
1111 //printf("AWindowGUI::update_assets 7\n");
1112
1113         flush();
1114 //printf("AWindowGUI::update_assets 8\n");
1115         return;
1116 }
1117
1118 void AWindowGUI::update_effects()
1119 {
1120         aeffects.remove_all_objects();
1121         create_persistent_folder(&aeffects, 1, 0, 1, 0);
1122         veffects.remove_all_objects();
1123         create_persistent_folder(&veffects, 0, 1, 1, 0);
1124         atransitions.remove_all_objects();
1125         create_persistent_folder(&atransitions, 1, 0, 0, 1);
1126         vtransitions.remove_all_objects();
1127         create_persistent_folder(&vtransitions, 0, 1, 0, 1);
1128 }
1129
1130 int AWindowGUI::current_folder_number()
1131 {
1132         int result = -1;
1133         for(int i = 0; i < folders.total; i++)
1134         {
1135                 if(!strcasecmp(folders.values[i]->get_text(), mwindow->edl->session->current_folder))
1136                 {
1137                         result = i;
1138                         break;
1139                 }
1140         }
1141         return result;
1142 }
1143
1144 int AWindowGUI::drag_motion()
1145 {
1146         if(get_hidden()) return 0;
1147
1148         int result = 0;
1149         return result;
1150 }
1151
1152 int AWindowGUI::drag_stop()
1153 {
1154         if(get_hidden()) return 0;
1155
1156         return 0;
1157 }
1158
1159 Indexable* AWindowGUI::selected_asset()
1160 {
1161         AssetPicon *picon = (AssetPicon*)asset_list->get_selection(0, 0);
1162         return picon ? picon->indexable : 0;
1163 }
1164
1165 PluginServer* AWindowGUI::selected_plugin()
1166 {
1167         AssetPicon *picon = (AssetPicon*)asset_list->get_selection(0, 0);
1168         return picon ? picon->plugin : 0;
1169 }
1170
1171 AssetPicon* AWindowGUI::selected_folder()
1172 {
1173         AssetPicon *picon = (AssetPicon*)folder_list->get_selection(0, 0);
1174         return picon;
1175 }
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186 AWindowDivider::AWindowDivider(MWindow *mwindow, AWindowGUI *gui, int x, int y, int w, int h)
1187  : BC_SubWindow(x, y, w, h)
1188 {
1189         this->mwindow = mwindow;
1190         this->gui = gui;
1191 }
1192 AWindowDivider::~AWindowDivider()
1193 {
1194 }
1195
1196 int AWindowDivider::button_press_event()
1197 {
1198         if(is_event_win() && cursor_inside())
1199         {
1200                 mwindow->session->current_operation = DRAG_PARTITION;
1201                 return 1;
1202         }
1203         return 0;
1204 }
1205
1206 int AWindowDivider::cursor_motion_event()
1207 {
1208         if(mwindow->session->current_operation == DRAG_PARTITION)
1209         {
1210                 mwindow->session->afolders_w = gui->get_relative_cursor_x();
1211                 gui->reposition_objects();
1212         }
1213         return 0;
1214 }
1215
1216 int AWindowDivider::button_release_event()
1217 {
1218         if(mwindow->session->current_operation == DRAG_PARTITION)
1219         {
1220                 mwindow->session->current_operation = NO_OPERATION;
1221                 return 1;
1222         }
1223         return 0;
1224 }
1225
1226
1227
1228
1229
1230
1231 AWindowFolders::AWindowFolders(MWindow *mwindow, AWindowGUI *gui, int x, int y, int w, int h)
1232  : BC_ListBox(x, 
1233                 y, 
1234                 w, 
1235                 h,
1236                 mwindow->edl->session->folderlist_format == FOLDERS_ICONS ? 
1237                         LISTBOX_ICONS : LISTBOX_TEXT, 
1238                 &gui->folders, // Each column has an ArrayList of BC_ListBoxItems.
1239                 0,             // Titles for columns.  Set to 0 for no titles
1240                 0,                // width of each column
1241                 1,                      // Total columns.
1242                 0,                    // Pixel of top of window.
1243                 0,                        // If this listbox is a popup window
1244                 LISTBOX_SINGLE,  // Select one item or multiple items
1245                 ICON_TOP,        // Position of icon relative to text of each item
1246                 1)               // Allow drags
1247 {
1248         this->mwindow = mwindow;
1249         this->gui = gui;
1250         set_drag_scroll(0);
1251 }
1252
1253 AWindowFolders::~AWindowFolders()
1254 {
1255 }
1256         
1257 int AWindowFolders::selection_changed()
1258 {
1259         AssetPicon *picon = (AssetPicon*)get_selection(0, 0);
1260         if(picon)
1261         {
1262                 if(get_button_down() && get_buttonpress() == 3)
1263                 {
1264                         gui->folderlist_menu->update_titles();
1265                         gui->folderlist_menu->activate_menu();
1266                 }
1267
1268                 strcpy(mwindow->edl->session->current_folder, picon->get_text());
1269 //printf("AWindowFolders::selection_changed 1\n");
1270                 gui->asset_list->draw_background();
1271                 gui->update_assets();
1272         }
1273         return 1;
1274 }
1275
1276 int AWindowFolders::button_press_event()
1277 {
1278         int result = 0;
1279
1280         result = BC_ListBox::button_press_event();
1281
1282         if(!result)
1283         {
1284                 if(get_buttonpress() == 3 && is_event_win() && cursor_inside())
1285                 {
1286                         gui->folderlist_menu->update_titles();
1287                         gui->folderlist_menu->activate_menu();
1288                         result = 1;
1289                 }
1290         }
1291
1292
1293         return result;
1294 }
1295
1296
1297
1298
1299
1300
1301
1302 AWindowAssets::AWindowAssets(MWindow *mwindow, AWindowGUI *gui, int x, int y, int w, int h)
1303  : BC_ListBox(x, 
1304                 y, 
1305                 w, 
1306                 h,
1307                 mwindow->edl->session->assetlist_format == ASSETS_ICONS ? 
1308                         LISTBOX_ICONS : LISTBOX_TEXT,
1309                 &gui->assets,     // Each column has an ArrayList of BC_ListBoxItems.
1310                 gui->asset_titles,             // Titles for columns.  Set to 0 for no titles
1311                 mwindow->edl->session->asset_columns,                // width of each column
1312                 1,                      // Total columns.
1313                 0,                    // Pixel of top of window.
1314                 0,                        // If this listbox is a popup window
1315                 LISTBOX_MULTIPLE,  // Select one item or multiple items
1316                 ICON_TOP,        // Position of icon relative to text of each item
1317                 1)               // Allow drag
1318 {
1319         this->mwindow = mwindow;
1320         this->gui = gui;
1321         set_drag_scroll(0);
1322 }
1323
1324 AWindowAssets::~AWindowAssets()
1325 {
1326 }
1327
1328 int AWindowAssets::button_press_event()
1329 {
1330         int result = 0;
1331
1332         result = BC_ListBox::button_press_event();
1333
1334         if(!result && get_buttonpress() == 3 && is_event_win() && cursor_inside())
1335         {
1336                 BC_ListBox::deactivate_selection();
1337                 gui->assetlist_menu->update_titles();
1338                 gui->assetlist_menu->activate_menu();
1339                 result = 1;
1340         }
1341
1342
1343         return result;
1344 }
1345
1346
1347 int AWindowAssets::handle_event()
1348 {
1349 //printf("AWindowAssets::handle_event 1 %d %d\n", get_buttonpress(), get_selection(0, 0));
1350         if(get_selection(0, 0))
1351         {
1352                 if(!strcasecmp(mwindow->edl->session->current_folder, AEFFECT_FOLDER))
1353                 {
1354                 }
1355                 else
1356                 if(!strcasecmp(mwindow->edl->session->current_folder, VEFFECT_FOLDER))
1357                 {
1358                 }
1359                 else
1360                 if(!strcasecmp(mwindow->edl->session->current_folder, ATRANSITION_FOLDER))
1361                 {
1362                 }
1363                 else
1364                 if(!strcasecmp(mwindow->edl->session->current_folder, VTRANSITION_FOLDER))
1365                 {
1366                 }
1367                 else
1368                 if(mwindow->vwindows.size())
1369                 {
1370 //printf("AWindowAssets::handle_event 2 %d %d\n", get_buttonpress(), get_selection(0, 0));
1371                         mwindow->vwindows.get(DEFAULT_VWINDOW)->gui->lock_window("AWindowAssets::handle_event");
1372                         
1373                         if(((AssetPicon*)get_selection(0, 0))->indexable)
1374                                 mwindow->vwindows.get(DEFAULT_VWINDOW)->change_source(((AssetPicon*)get_selection(0, 0))->indexable);
1375                         else
1376                         if(((AssetPicon*)get_selection(0, 0))->edl)
1377                                 mwindow->vwindows.get(DEFAULT_VWINDOW)->change_source(((AssetPicon*)get_selection(0, 0))->edl);
1378
1379                         mwindow->vwindows.get(DEFAULT_VWINDOW)->gui->unlock_window();
1380                 }
1381                 return 1;
1382         }
1383
1384         return 0;
1385 }
1386
1387 int AWindowAssets::selection_changed()
1388 {
1389 // Show popup window
1390         if(get_button_down() && get_buttonpress() == 3 && get_selection(0, 0))
1391         {
1392                 if(!strcasecmp(mwindow->edl->session->current_folder, AEFFECT_FOLDER) || 
1393                         !strcasecmp(mwindow->edl->session->current_folder, VEFFECT_FOLDER) ||
1394                         !strcasecmp(mwindow->edl->session->current_folder, ATRANSITION_FOLDER) ||
1395                         !strcasecmp(mwindow->edl->session->current_folder, VTRANSITION_FOLDER))
1396                 {
1397                         gui->assetlist_menu->update_titles();
1398                         gui->assetlist_menu->activate_menu();
1399                 }
1400                 else
1401                 {
1402                         if(((AssetPicon*)get_selection(0, 0))->indexable)
1403                                 gui->asset_menu->update();
1404                         else
1405                         if(((AssetPicon*)get_selection(0, 0))->edl)
1406                                 gui->asset_menu->update();
1407
1408
1409
1410                         gui->asset_menu->activate_menu();
1411                 }
1412
1413                 BC_ListBox::deactivate_selection();
1414                 return 1;
1415         }
1416         return 0;
1417 }
1418
1419 void AWindowAssets::draw_background()
1420 {
1421         clear_box(0,0,get_w(),get_h(),get_bg_surface());
1422         set_color(RED);
1423         set_font(LARGEFONT);
1424         draw_text(get_w() - 
1425                         get_text_width(LARGEFONT, mwindow->edl->session->current_folder) - 4, 
1426                 30, 
1427                 mwindow->edl->session->current_folder, 
1428                 -1, 
1429                 get_bg_surface());
1430 }
1431
1432 int AWindowAssets::drag_start_event()
1433 {
1434         int collect_pluginservers = 0;
1435         int collect_assets = 0;
1436
1437         if(BC_ListBox::drag_start_event())
1438         {
1439                 if(!strcasecmp(mwindow->edl->session->current_folder, AEFFECT_FOLDER))
1440                 {
1441                         mwindow->session->current_operation = DRAG_AEFFECT;
1442                         collect_pluginservers = 1;
1443                 }
1444                 else
1445                 if(!strcasecmp(mwindow->edl->session->current_folder, VEFFECT_FOLDER))
1446                 {
1447                         mwindow->session->current_operation = DRAG_VEFFECT;
1448                         collect_pluginservers = 1;
1449                 }
1450                 else
1451                 if(!strcasecmp(mwindow->edl->session->current_folder, ATRANSITION_FOLDER))
1452                 {
1453                         mwindow->session->current_operation = DRAG_ATRANSITION;
1454                         collect_pluginservers = 1;
1455                 }
1456                 else
1457                 if(!strcasecmp(mwindow->edl->session->current_folder, VTRANSITION_FOLDER))
1458                 {
1459                         mwindow->session->current_operation = DRAG_VTRANSITION;
1460                         collect_pluginservers = 1;
1461                 }
1462                 else
1463                 {
1464                         mwindow->session->current_operation = DRAG_ASSET;
1465                         collect_assets = 1;
1466                 }
1467                 
1468                 
1469                 if(collect_pluginservers)
1470                 {
1471                         int i = 0;
1472                         mwindow->session->drag_pluginservers->remove_all();
1473                         while(1)
1474                         {
1475                                 AssetPicon *result = (AssetPicon*)get_selection(0, i++);
1476                                 if(!result) break;
1477                                 
1478                                 mwindow->session->drag_pluginservers->append(result->plugin);
1479                         }
1480                 }
1481                 
1482                 if(collect_assets)
1483                 {
1484                         gui->collect_assets();
1485                 }
1486
1487                 return 1;
1488         }
1489         return 0;
1490 }
1491
1492 int AWindowAssets::drag_motion_event()
1493 {
1494         BC_ListBox::drag_motion_event();
1495         unlock_window();
1496
1497         mwindow->gui->lock_window("AWindowAssets::drag_motion_event");
1498         mwindow->gui->drag_motion();
1499         mwindow->gui->unlock_window();
1500
1501         for(int i = 0; i < mwindow->vwindows.size(); i++)
1502         {
1503                 VWindow *vwindow = mwindow->vwindows.get(i);
1504                 vwindow->gui->lock_window("AWindowAssets::drag_motion_event");
1505                 vwindow->gui->drag_motion();
1506                 vwindow->gui->unlock_window();
1507         }
1508
1509         mwindow->cwindow->gui->lock_window("AWindowAssets::drag_motion_event");
1510         mwindow->cwindow->gui->drag_motion();
1511         mwindow->cwindow->gui->unlock_window();
1512
1513         lock_window("AWindowAssets::drag_motion_event");
1514         return 0;
1515 }
1516
1517 int AWindowAssets::drag_stop_event()
1518 {
1519         int result = 0;
1520
1521         result = gui->drag_stop();
1522
1523         unlock_window();
1524
1525         if(!result)
1526         {
1527                 mwindow->gui->lock_window("AWindowAssets::drag_stop_event");
1528                 result = mwindow->gui->drag_stop();
1529                 mwindow->gui->unlock_window();
1530         }
1531
1532         if(!result) 
1533         {
1534                 for(int i = 0; i < mwindow->vwindows.size(); i++)
1535                 {
1536                         VWindow *vwindow = mwindow->vwindows.get(i);
1537                         vwindow->gui->lock_window("AWindowAssets::drag_stop_event");
1538                         result = vwindow->gui->drag_stop();
1539                         vwindow->gui->unlock_window();
1540                 }
1541         }
1542
1543         if(!result) 
1544         {
1545                 mwindow->cwindow->gui->lock_window("AWindowAssets::drag_stop_event");
1546                 result = mwindow->cwindow->gui->drag_stop();
1547                 mwindow->cwindow->gui->unlock_window();
1548         }
1549
1550         lock_window("AWindowAssets::drag_stop_event");
1551
1552         if(result) get_drag_popup()->set_animation(0);
1553
1554         BC_ListBox::drag_stop_event();
1555         mwindow->session->current_operation = ::NO_OPERATION; // since NO_OPERATION is also defined in listbox, we have to reach for global scope...
1556         return 0;
1557 }
1558
1559 int AWindowAssets::column_resize_event()
1560 {
1561         mwindow->edl->session->asset_columns[0] = get_column_width(0);
1562         mwindow->edl->session->asset_columns[1] = get_column_width(1);
1563         return 1;
1564 }
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577 AWindowNewFolder::AWindowNewFolder(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1578  : BC_Button(x, y, mwindow->theme->newbin_data)
1579 {
1580         this->mwindow = mwindow;
1581         this->gui = gui;
1582         set_tooltip(_("New bin"));
1583 }
1584
1585 int AWindowNewFolder::handle_event()
1586 {
1587         gui->newfolder_thread->start_new_folder();
1588         return 1;
1589 }
1590
1591 AWindowDeleteFolder::AWindowDeleteFolder(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1592  : BC_Button(x, y, mwindow->theme->deletebin_data)
1593 {
1594         this->mwindow = mwindow;
1595         this->gui = gui;
1596         set_tooltip(_("Delete bin"));
1597 }
1598
1599 int AWindowDeleteFolder::handle_event()
1600 {
1601         if(gui->folder_list->get_selection(0, 0))
1602         {
1603                 BC_ListBoxItem *folder = gui->folder_list->get_selection(0, 0);
1604                 mwindow->delete_folder(folder->get_text());
1605         }
1606         return 1;
1607 }
1608
1609 AWindowRenameFolder::AWindowRenameFolder(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1610  : BC_Button(x, y, mwindow->theme->renamebin_data)
1611 {
1612         this->mwindow = mwindow;
1613         this->gui = gui;
1614         set_tooltip(_("Rename bin"));
1615 }
1616
1617 int AWindowRenameFolder::handle_event()
1618 {
1619         return 1;
1620 }
1621
1622 AWindowDeleteDisk::AWindowDeleteDisk(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1623  : BC_Button(x, y, mwindow->theme->deletedisk_data)
1624 {
1625         this->mwindow = mwindow;
1626         this->gui = gui;
1627         set_tooltip(_("Delete asset from disk"));
1628 }
1629
1630 int AWindowDeleteDisk::handle_event()
1631 {
1632         return 1;
1633 }
1634
1635 AWindowDeleteProject::AWindowDeleteProject(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1636  : BC_Button(x, y, mwindow->theme->deleteproject_data)
1637 {
1638         this->mwindow = mwindow;
1639         this->gui = gui;
1640         set_tooltip(_("Delete asset from project"));
1641 }
1642
1643 int AWindowDeleteProject::handle_event()
1644 {
1645         return 1;
1646 }
1647
1648 AWindowInfo::AWindowInfo(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1649  : BC_Button(x, y, mwindow->theme->infoasset_data)
1650 {
1651         this->mwindow = mwindow;
1652         this->gui = gui;
1653         set_tooltip(_("Edit information on asset"));
1654 }
1655
1656 int AWindowInfo::handle_event()
1657 {
1658         gui->awindow->asset_edit->edit_asset(gui->selected_asset());
1659         return 1;
1660 }
1661
1662 AWindowRedrawIndex::AWindowRedrawIndex(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1663  : BC_Button(x, y, mwindow->theme->redrawindex_data)
1664 {
1665         this->mwindow = mwindow;
1666         this->gui = gui;
1667         set_tooltip(_("Redraw index"));
1668 }
1669
1670 int AWindowRedrawIndex::handle_event()
1671 {
1672         return 1;
1673 }
1674
1675 AWindowPaste::AWindowPaste(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1676  : BC_Button(x, y, mwindow->theme->pasteasset_data)
1677 {
1678         this->mwindow = mwindow;
1679         this->gui = gui;
1680         set_tooltip(_("Paste asset on recordable tracks"));
1681 }
1682
1683 int AWindowPaste::handle_event()
1684 {
1685         return 1;
1686 }
1687
1688 AWindowAppend::AWindowAppend(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1689  : BC_Button(x, y, mwindow->theme->appendasset_data)
1690 {
1691         this->mwindow = mwindow;
1692         this->gui = gui;
1693         set_tooltip(_("Append asset in new tracks"));
1694 }
1695
1696 int AWindowAppend::handle_event()
1697 {
1698         return 1;
1699 }
1700
1701 AWindowView::AWindowView(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1702  : BC_Button(x, y, mwindow->theme->viewasset_data)
1703 {
1704         this->mwindow = mwindow;
1705         this->gui = gui;
1706         set_tooltip(_("View asset"));
1707 }
1708
1709 int AWindowView::handle_event()
1710 {
1711         return 1;
1712 }
1713
1714 AddTools::AddTools(MWindow *mwindow, AWindowGUI *gui, int x, int y, int w)
1715  : BC_MenuBar(x, y, w)
1716 {
1717         this->mwindow = mwindow;
1718         this->gui = gui;
1719 }
1720
1721 void AddTools::create_objects()
1722 {
1723         add_menu(add_plugins = new AddPluginsMenu(mwindow, gui));
1724         add_plugins->create_objects();
1725 }
1726
1727 AddPluginsMenu::AddPluginsMenu(MWindow *mwindow, AWindowGUI *gui)
1728  : BC_Menu("Add Tools")
1729 {
1730         this->mwindow = mwindow;
1731         this->gui = gui;
1732 }
1733
1734 void AddPluginsMenu::create_objects()
1735 {
1736         uint32_t vis = 0;
1737         for( int i=0; i<MWindow::plugindb->size(); ++i ) {
1738                 PluginServer *plugin = MWindow::plugindb->get(i);
1739                 if( !plugin->audio && !plugin->video ) continue;
1740                 int idx = plugin->dir_idx;
1741                 uint32_t msk = 1 << idx;
1742                 if( (msk & vis) != 0 ) continue;
1743                 vis |= msk;
1744                 char parent[BCTEXTLEN];
1745                 strcpy(parent, plugin->path);
1746                 char *cp = strrchr(parent, '/');
1747                 if( !cp ) continue;
1748                 *cp = 0;
1749                 char *bp = strrchr(parent, '/');
1750                 if( !bp ) bp = parent; else ++bp;
1751                 if( !strcmp(bp, "ladspa") )
1752                         gui->plugin_visibility &= ~(1 << idx);
1753                 add_item(new AddPluginItem(this, bp, idx));
1754         }
1755                 
1756 }
1757
1758 AddPluginItem::AddPluginItem(AddPluginsMenu *menu, char const *text, int idx)
1759  : BC_MenuItem(text)
1760 {
1761         this->menu = menu;
1762         this->idx = idx;
1763         uint32_t msk = 1 << idx, vis = menu->gui->plugin_visibility;
1764         int chk = (msk & vis) ? 1 : 0;
1765         set_checked(chk);
1766 }
1767
1768 int AddPluginItem::handle_event()
1769 {
1770         int chk = get_checked() ^ 1;
1771         set_checked(chk);
1772         uint32_t msk = 1 << idx, vis = menu->gui->plugin_visibility;
1773         menu->gui->plugin_visibility = chk ? vis | msk : vis & ~msk;
1774         menu->gui->update_effects();
1775         menu->gui->update_assets();
1776         return 1;
1777 }
1778