3 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "awindowgui.h"
23 #include "binfolder.h"
28 #include "indexable.h"
30 #include "localsession.h"
31 #include "mainerror.h"
32 #include "mainsession.h"
38 const char *BinFolderEnabled::types[] = {
46 const char *BinFolderTarget::types[] = {
59 const char *BinFolderOp::types[] = {
71 const char *sfx, *sfxs;
74 { N_("min"), N_("mins"), 60, },
75 { N_("hour"), N_("hours"), 60*60, },
76 { N_("day"), N_("days"), 24*60*60, },
77 { N_("week"), N_("weeks"), 24*60*60*7, },
78 { N_("month"), N_("months"), 24*60*60*31, },
79 { N_("year"), N_("years"), 24*60*60*365.25, },
81 #define SCAN_RANGE_DAYS 2
82 #define DBL_INF 9007199254740991.
84 static int scan_inf(const char *cp, char *&bp)
87 const char *inf = _("inf");
88 const int linf = strlen(inf);
89 if( strncasecmp(cp,inf,linf) ) return 0;
90 bp = (char *)(cp + linf);
94 static double scan_no(const char *cp, char *&bp)
96 while( *cp == ' ' ) ++cp;
97 if( scan_inf(cp, bp) ) return DBL_INF;
98 if( *cp == '+' ) return 0;
99 double v = strtod(cp, &bp);
101 case 'T': v *= 1099511627776.; break;
102 case 't': v *= 1e12; break;
103 case 'G': v *= 1073741824.; break;
104 case 'g': v *= 1e9; break;
105 case 'M': v *= 1048576.; break;
106 case 'm': v *= 1e6; break;
107 case 'K': v *= 1024.; break;
108 case 'k': v *= 1e3; break;
115 static void scan_around(const char *cp, char *&bp, double &v, double &a)
118 double sv = scan_no(cp, bp);
119 if( bp > cp ) v = sv;
121 double sa = scan_no(cp=bp+1, bp);
122 if( bp > cp ) a = sa;
126 static void show_no(double v, char *&cp, char *ep, const char *fmt="%0.0f")
129 cp += snprintf(cp, ep-cp, "%s", _("inf"));
133 static const struct { double radix; const char *sfx; } sfxs[] = {
134 { 1024., "K" }, { 1e3, "k" },
135 { 1048576., "M" }, { 1e6, "m" },
136 { 1073741824., "G" }, { 1e9, "g" },
137 { 1099511627776., "T" }, { 1e12, "t" },
139 for( int i=sizeof(sfxs)/sizeof(sfxs[0]); --i>=0; ) {
140 if( v < sfxs[i].radix ) continue;
141 if( fmod(v, sfxs[i].radix) == 0 ) {
147 cp += snprintf(cp, ep-cp, fmt, v);
148 if( sfx ) cp += snprintf(cp, ep-cp, "%s", sfx);
151 static double scan_duration(const char *cp, char *&bp)
153 if( scan_inf(cp, bp) ) return DBL_INF;
156 double v = strtod(cp, &bp);
157 if( cp >= bp ) break;
158 int k = sizeof(scan_ranges)/sizeof(scan_ranges[0]);
160 const char *tsfx = _(scan_ranges[k].sfx);
161 int lsfx = strlen(tsfx), msfx = strncasecmp(bp, tsfx, lsfx);
162 const char *tsfxs = _(scan_ranges[k].sfxs);
163 int lsfxs = strlen(tsfxs), msfxs = strncasecmp(bp, tsfxs, lsfxs);
164 int len = !msfx && !msfxs ? (lsfx > lsfxs ? lsfx : lsfxs) :
165 !msfx ? lsfx : !msfxs ? lsfxs : -1;
167 secs += v * scan_ranges[k].radix;
173 int hour = 0, mins = 0;
174 if( *bp == ':' && v == (int)v ) {
176 v = strtod(cp=bp+1, &bp);
177 if( *bp == ':' && v == (int)v ) {
178 hour = mins; mins = v;
179 v = strtod(cp=bp+1, &bp);
182 secs += hour*3600 + mins*60 + v;
184 while( *bp && (*bp<'0' || *bp>'9') ) ++bp;
190 static void show_duration(double v, char *&cp, char *ep)
193 cp += snprintf(cp, ep-cp, "%s", _("inf"));
196 double secs = v; char *bp = cp;
197 int k = sizeof(scan_ranges)/sizeof(scan_ranges[0]);
198 while( --k >= SCAN_RANGE_DAYS ) {
199 if( secs >= scan_ranges[k].radix ) {
200 int v = secs/scan_ranges[k].radix;
201 secs -= v * scan_ranges[k].radix;
202 cp += snprintf(cp, ep-cp,"%d%s", v,
203 v > 1 ? _(scan_ranges[k].sfxs) : _(scan_ranges[k].sfx));
207 if( cp > bp && cp < ep ) *cp++ = ' ';
208 int64_t n = secs; int hour = n/3600, min = (n/60)%60, sec = n%60;
209 if( hour > 0 ) cp += snprintf(cp, ep-cp, "%d:", hour);
210 if( hour > 0 || min > 0 ) cp += snprintf(cp, ep-cp, "%02d:", min);
211 cp += snprintf(cp, ep-cp, n>=10 ? "%02d" : "%d", sec);
215 static int64_t scan_date(const char *cp, char *&bp)
217 double year=0, mon=1, day=1;
218 double hour=0, min=0;
220 while( *bp == ' ' ) ++bp;
221 if( *bp == '+' ) return 0;
222 double secs = strtod(cp=bp, &bp);
223 if( *bp == '/' && secs == (int)secs ) {
224 year = secs; secs = 0;
225 mon = strtod(cp=bp+1, &bp);
226 if( *bp == '/' && mon == (int)mon ) {
227 day = strtod(cp=bp+1, &bp);
228 while( *bp == ' ' ) ++bp;
229 secs = *bp != '+' ? strtod(cp=bp, &bp) : 0;
232 if( *bp == ':' && secs == (int)secs ) {
233 hour = secs; secs = 0;
234 min = strtod(cp=bp+1, &bp);
235 if( *bp == ':' && min == (int)min ) {
236 secs = strtod(cp=bp+1, &bp);
239 struct tm ttm; memset(&ttm, 0, sizeof(ttm));
240 ttm.tm_year = year-1900; ttm.tm_mon = mon-1; ttm.tm_mday = day;
241 ttm.tm_hour = hour; ttm.tm_min = min; ttm.tm_sec = secs;
242 time_t t = mktime(&ttm);
246 static void show_date(time_t t, char *&cp, char *ep)
248 struct tm tm; localtime_r(&t, &tm);
249 cp += snprintf(cp, ep-cp, "%04d/%02d/%02d %02d:%02d:%02d",
250 tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday,
251 tm.tm_hour, tm.tm_min, tm.tm_sec);
254 double BinFolder::matches_indexable(Indexable *idxbl)
257 for( int i=0; i<filters.size(); ++i ) {
258 BinFolderFilter *filter = filters[i];
259 double ret = filter->op->test(filter->target, idxbl);
260 switch( filter->enabled->type ) {
261 case FOLDER_ENABLED_OR: {
262 if( result < 0 ) result = ret;
264 case FOLDER_ENABLED_AND: {
265 if( ret < 0 ) result = -1;
267 case FOLDER_ENABLED_OR_NOT: {
268 if( ret < 0 ) result = 1;
270 case FOLDER_ENABLED_AND_NOT: {
271 if( ret >= 0 ) result = -1;
279 BinFolder::BinFolder(int awindow_folder, int is_clips, const char *title)
281 this->awindow_folder = awindow_folder;
282 this->is_clips = is_clips;
283 char *bp = this->title;
284 int len = sizeof(this->title);
285 while( --len>0 && *title ) *bp++ = *title++;
289 BinFolder::BinFolder(BinFolder &that)
294 void BinFolder::copy_from(BinFolder *that)
296 strcpy(title, that->title);
297 awindow_folder = that->awindow_folder;
298 is_clips = that->is_clips;
299 filters.copy_from(&that->filters);
302 BinFolder::~BinFolder()
306 void BinFolder::save_xml(FileXML *file)
308 file->tag.set_title("FOLDER");
309 file->tag.set_property("TITLE", title);
310 file->tag.set_property("AWINDOW_FOLDER", awindow_folder);
311 file->tag.set_property("IS_CLIPS", is_clips);
313 file->append_newline();
314 for( int i=0; i<filters.size(); ++i )
315 filters[i]->save_xml(file);
316 file->tag.set_title("/FOLDER");
318 file->append_newline();
321 int BinFolder::load_xml(FileXML *file)
324 file->tag.get_property("TITLE", title);
325 awindow_folder = file->tag.get_property("AWINDOW_FOLDER", -1);
326 is_clips = file->tag.get_property("IS_CLIPS", 0);
327 filters.remove_all_objects();
330 while( !(ret=file->read_tag()) ) {
331 if( file->tag.title_is("/FOLDER") ) break;
332 if( file->tag.title_is("FILTER") ) {
333 BinFolderFilter *filter = new BinFolderFilter();
334 filter->load_xml(file);
335 filters.append(filter);
341 int BinFolder::add_patterns(ArrayList<Indexable*> *drag_idxbls)
343 int n = drag_idxbls->size();
347 for( int i=0; i<n; ++i ) {
348 idxbl = drag_idxbls->get(i);
349 if( !idxbl->is_asset &&
350 idxbl->awindow_folder == AW_PROXY_FOLDER )
352 len += strlen(idxbl->get_title()) + 1;
355 char *pats = new char[len+1], *bp = pats;
356 for( int i=0; i<n; ++i ) {
357 idxbl = drag_idxbls->get(i);
358 if( !idxbl->is_asset &&
359 idxbl->awindow_folder == AW_PROXY_FOLDER )
361 if( i > 0 ) *bp++ = '\n';
362 const char *cp = idxbl->get_title();
363 while( *cp ) *bp++ = *cp++;
366 // new pattern filter
367 BinFolderFilter *filter = new BinFolderFilter();
368 filter->update_enabled(FOLDER_ENABLED_OR);
369 filter->update_target(FOLDER_TARGET_PATTERNS);
370 filter->update_op(FOLDER_OP_MATCHES);
371 BinFolderTargetPatterns *patterns = (BinFolderTargetPatterns *)(filter->target);
372 patterns->update(pats);
373 filters.append(filter);
378 double BinFolders::matches_indexable(int folder, Indexable *idxbl)
381 BinFolder *bin_folder = 0;
382 while( --k>=0 && (bin_folder=get(k)) && bin_folder->awindow_folder!=folder );
383 if( k < 0 ) return -1;
384 if( bin_folder->is_clips && idxbl->is_asset ) return -1;
385 if( !bin_folder->is_clips && !idxbl->is_asset ) return -1;
386 return bin_folder->matches_indexable(idxbl);
389 void BinFolders::save_xml(FileXML *file)
391 file->tag.set_title("FOLDERS");
393 file->append_newline();
394 for( int i=0; i<size(); ++i )
395 get(i)->save_xml(file);
396 file->tag.set_title("/FOLDERS");
398 file->append_newline();
401 int BinFolders::load_xml(FileXML *file)
405 while( !(ret=file->read_tag()) ) {
406 if( file->tag.title_is("/FOLDERS") ) break;
407 if( file->tag.title_is("FOLDER") ) {
408 BinFolder *folder = new BinFolder(-1, -1, "folder");
409 folder->load_xml(file);
416 void BinFolders::copy_from(BinFolders *that)
419 for( int i=0; i<that->size(); ++i )
420 append(new BinFolder(*that->get(i)));
424 BinFolderFilter::BinFolderFilter()
431 BinFolderFilter::~BinFolderFilter()
439 void BinFolderFilter::update_enabled(int type)
442 enabled = new BinFolderEnabled(this, type);
444 enabled->update(type);
447 void BinFolderFilter::update_target(int type)
450 if( target->type == type ) return;
451 delete target; target = 0;
454 case FOLDER_TARGET_PATTERNS: target = new BinFolderTargetPatterns(this); break;
455 case FOLDER_TARGET_FILE_SIZE: target = new BinFolderTargetFileSize(this); break;
456 case FOLDER_TARGET_MOD_TIME: target = new BinFolderTargetTime(this); break;
457 case FOLDER_TARGET_TRACK_TYPE: target = new BinFolderTargetTrackType(this); break;
458 case FOLDER_TARGET_WIDTH: target = new BinFolderTargetWidth(this); break;
459 case FOLDER_TARGET_HEIGHT: target = new BinFolderTargetHeight(this); break;
460 case FOLDER_TARGET_FRAMERATE: target = new BinFolderTargetFramerate(this); break;
461 case FOLDER_TARGET_SAMPLERATE: target = new BinFolderTargetSamplerate(this); break;
462 case FOLDER_TARGET_CHANNELS: target = new BinFolderTargetChannels(this); break;
463 case FOLDER_TARGET_DURATION: target = new BinFolderTargetDuration(this); break;
467 void BinFolderFilter::update_op(int type)
470 if( op->type == type ) return;
474 case FOLDER_OP_AROUND: op = new BinFolderOpAround(this); break;
475 case FOLDER_OP_EQ: op = new BinFolderOpEQ(this); break;
476 case FOLDER_OP_GE: op = new BinFolderOpGE(this); break;
477 case FOLDER_OP_GT: op = new BinFolderOpGT(this); break;
478 case FOLDER_OP_NE: op = new BinFolderOpNE(this); break;
479 case FOLDER_OP_LE: op = new BinFolderOpLE(this); break;
480 case FOLDER_OP_LT: op = new BinFolderOpLT(this); break;
481 case FOLDER_OP_MATCHES: op = new BinFolderOpMatches(this); break;
485 void BinFolderFilter::update_value(const char *text)
488 value = new BinFolderValue(this, text);
493 void BinFolderFilter::save_xml(FileXML *file)
495 file->tag.set_title("FILTER");
496 file->tag.set_property("ENABLED", enabled->type);
497 file->tag.set_property("OP", op->type);
498 file->tag.set_property("TARGET", target->type);
499 target->save_xml(file);
501 if( target->type == FOLDER_TARGET_PATTERNS )
502 file->append_text(((BinFolderTargetPatterns *)target)->text);
503 file->tag.set_title("/FILTER");
505 file->append_newline();
508 int BinFolderFilter::load_xml(FileXML *file)
510 int enabled_type = file->tag.get_property("ENABLED", FOLDER_ENABLED_AND);
511 int op_type = file->tag.get_property("OP", FOLDER_OP_MATCHES);
512 int target_type = file->tag.get_property("TARGET", FOLDER_TARGET_PATTERNS);
514 file->read_text_until("/FILTER", data, sizeof(data), 0);
515 update_enabled(enabled_type);
516 update_target(target_type);
518 target->load_xml(file);
519 if( target->type == FOLDER_TARGET_PATTERNS )
520 ((BinFolderTargetPatterns *)target)->update(data);
524 void BinFolderFilters::copy_from(BinFolderFilters *that)
527 for( int i=0; i<that->size(); ++i ) {
528 BinFolderFilter *filter = new BinFolderFilter();
529 BinFolderFilter *tp = that->get(i);
530 filter->update_enabled(tp->enabled->type);
531 filter->update_target(tp->target->type);
532 filter->update_op(tp->op->type);
533 filter->target->copy_from(tp->target);
534 filter->op->copy_from(tp->op);
539 double BinFolderOp::around(double v, double a)
541 if( type != FOLDER_OP_AROUND ) return v;
543 return a>0 ? v/a : v;
546 // string theory: Feynman, Einstein and Schrodinger string compare
547 // Feynman: try all possible matches, weight the outcomes
548 // Schrodinger: it may be there several ways at the same time
549 // Einstein: the more matches there are, the heavier it is
550 double BinFolderOp::around(const char *ap, const char *bp)
552 int64_t v = 0, vmx = 0;
553 int alen = strlen(ap), blen = strlen(bp);
555 const char *cp = ap; ap = bp; bp = cp;
556 int clen = alen; alen = blen; blen = clen;
558 // 4 level loop (with strncmp), don't try long strings
559 for( int n=0; ++n<=alen; ) {
561 int an = alen-n+1, bn = blen-n+1;
562 for( int i=an; --i>=0; ) {
563 for( int j=bn; --j>=0; ) {
564 if( !strncmp(ap+i, bp+j, n) ) v += nn;
569 return !vmx ? -1 : 1 - v / (double)vmx;
573 double BinFolderOp::compare(BinFolderTarget *target, Indexable *idxbl)
576 switch( target->type ) {
577 case FOLDER_TARGET_PATTERNS: {
578 BinFolderTargetPatterns *tgt = (BinFolderTargetPatterns *)target;
580 case FOLDER_OP_AROUND: {
581 const char *cp = idxbl->path;
582 const char *bp = strrchr(cp, '/');
583 if( bp ) cp = bp + 1;
584 v = around(cp, tgt->text);
586 case FOLDER_OP_EQ: case FOLDER_OP_GT: case FOLDER_OP_GE:
587 case FOLDER_OP_NE: case FOLDER_OP_LT: case FOLDER_OP_LE: {
588 const char *cp = idxbl->path;
589 const char *bp = strrchr(cp, '/');
590 if( bp ) cp = bp + 1;
591 v = strcmp(cp, tgt->text);
593 case FOLDER_OP_MATCHES: {
595 char *cp = tgt->text;
596 while( v < 0 && *cp ) {
597 char pattern[BCTEXTLEN], *bp = pattern, ch;
598 while( *cp && (ch=*cp++)!='\n' ) *bp++ = ch;
600 if( !pattern[0] ) continue;
601 const char *title = idxbl->get_title();
602 if( !FileSystem::test_filter(title, pattern) )
608 case FOLDER_TARGET_FILE_SIZE: {
609 BinFolderTargetFileSize *tgt = (BinFolderTargetFileSize *)target;
610 int64_t file_size = !idxbl->is_asset ? -1 :
611 FileSystem::get_size(idxbl->path);
612 v = around(file_size - tgt->file_size, tgt->around);
614 case FOLDER_TARGET_MOD_TIME: {
615 BinFolderTargetTime *tgt = (BinFolderTargetTime *)target;
617 if( stat(idxbl->path, &st) ) break;
618 v = around(st.st_mtime - tgt->mtime, tgt->around);
620 case FOLDER_TARGET_TRACK_TYPE: {
621 BinFolderTargetTrackType *tgt = (BinFolderTargetTrackType *)target;
622 int want_audio = (tgt->data_types&(1<<TRACK_AUDIO)) ? 1 : 0;
623 int has_audio = idxbl->have_audio();
624 if( want_audio != has_audio ) break;
625 int want_video = (tgt->data_types&(1<<TRACK_VIDEO)) ? 1 : 0;
626 int has_video = idxbl->have_video();
627 if( want_video != has_video ) break;
630 case FOLDER_TARGET_WIDTH: {
631 BinFolderTargetWidth *tgt = (BinFolderTargetWidth *)target;
632 int w = idxbl->get_w();
633 v = around(w - tgt->width, tgt->around);
635 case FOLDER_TARGET_HEIGHT: {
636 BinFolderTargetHeight *tgt = (BinFolderTargetHeight *)target;
637 int h = idxbl->get_h();
638 v = around(h - tgt->height, tgt->around);
640 case FOLDER_TARGET_FRAMERATE: {
641 BinFolderTargetFramerate *tgt = (BinFolderTargetFramerate *)target;
642 double rate = idxbl->get_frame_rate();
643 v = around(rate - tgt->framerate, tgt->around);
645 case FOLDER_TARGET_SAMPLERATE: {
646 BinFolderTargetSamplerate *tgt = (BinFolderTargetSamplerate *)target;
647 double rate = idxbl->get_sample_rate();
648 v = around(rate - tgt->samplerate, tgt->around);
650 case FOLDER_TARGET_CHANNELS: {
651 BinFolderTargetChannels *tgt = (BinFolderTargetChannels *)target;
652 double chs = idxbl->get_audio_channels();
653 v = around(chs - tgt->channels, tgt->around);
655 case FOLDER_TARGET_DURATION: {
656 BinFolderTargetDuration *tgt = (BinFolderTargetDuration *)target;
658 double video_rate = !idxbl->have_video() ? 0 : idxbl->get_frame_rate();
659 if( video_rate > 0 ) {
660 double video_length = idxbl->get_video_frames() / video_rate;
661 if( video_length > len ) len = video_length;
663 double audio_rate = !idxbl->have_audio() ? 0 : idxbl->get_sample_rate();
664 if( audio_rate > 0 ) {
665 double audio_length = idxbl->get_audio_samples() / audio_rate;
666 if( audio_length > len ) len = audio_length;
668 v = around(len - tgt->duration, tgt->around);
675 BinFolderEnabled::BinFolderEnabled(BinFolderFilter *filter, int type)
676 : BC_ListBoxItem(_(types[type]))
678 this->filter = filter;
682 BinFolderEnabled::~BinFolderEnabled()
686 void BinFolderEnabled::update(int type)
689 set_text(_(types[type]));
692 BinFolderEnabledType::BinFolderEnabledType(int no)
693 : BC_MenuItem(_(BinFolderEnabled::types[no]))
697 BinFolderEnabledType::~BinFolderEnabledType()
701 int BinFolderEnabledType::handle_event()
703 BinFolderEnabledPopup *enabled_popup = (BinFolderEnabledPopup *)get_popup_menu();
704 BinFolderList *folder_list = enabled_popup->folder_list;
705 int i = folder_list->get_selection_number(FOLDER_COLUMN_ENABLE, 0);
707 BinFolder *folder = folder_list->folder;
708 BinFolderFilter *filter = folder->filters[i];
709 filter->update_enabled(no);
710 folder_list->create_list();
715 BinFolderEnabledPopup::BinFolderEnabledPopup(BinFolderList *folder_list)
716 : BC_PopupMenu(0, 0, 0, "", 0)
718 this->folder_list = folder_list;
722 void BinFolderEnabledPopup::create_objects()
724 add_item(new BinFolderEnabledType(FOLDER_ENABLED_OFF));
725 add_item(new BinFolderEnabledType(FOLDER_ENABLED_AND));
726 add_item(new BinFolderEnabledType(FOLDER_ENABLED_OR));
727 add_item(new BinFolderEnabledType(FOLDER_ENABLED_AND_NOT));
728 add_item(new BinFolderEnabledType(FOLDER_ENABLED_OR_NOT));
731 void BinFolderEnabledPopup::activate_menu(BC_ListBoxItem *item)
733 this->enabled = (BinFolderEnabled *)item;
734 BC_PopupMenu::activate_menu();
737 BinFolderTarget::BinFolderTarget(BinFolderFilter *filter, int type)
738 : BC_ListBoxItem(_(types[type]))
740 this->filter = filter;
745 BinFolderTarget::~BinFolderTarget()
749 BC_Window *BinFolderTarget::new_gui(ModifyTargetThread *thread)
751 ModifyTargetGUI *window = new ModifyTargetGUI(thread);
752 window->create_objects();
756 BinFolderTargetType::BinFolderTargetType(int no)
757 : BC_MenuItem(_(BinFolderTarget::types[no]))
761 BinFolderTargetType::~BinFolderTargetType()
765 int BinFolderTargetType::handle_event()
767 BinFolderTargetPopup *target_popup = (BinFolderTargetPopup *)get_popup_menu();
768 BinFolderList *folder_list = target_popup->folder_list;
769 int i = folder_list->get_selection_number(FOLDER_COLUMN_TARGET, 0);
771 BinFolder *folder = folder_list->folder;
772 BinFolderFilter *filter = folder->filters[i];
773 filter->update_target(no);
774 folder_list->create_list();
779 BinFolderTargetPopup::BinFolderTargetPopup(BinFolderList *folder_list)
780 : BC_PopupMenu(0, 0, 0, "", 0)
782 this->folder_list = folder_list;
786 void BinFolderTargetPopup::create_objects()
788 add_item(new BinFolderTargetType(FOLDER_TARGET_PATTERNS));
789 add_item(new BinFolderTargetType(FOLDER_TARGET_FILE_SIZE));
790 add_item(new BinFolderTargetType(FOLDER_TARGET_MOD_TIME));
791 add_item(new BinFolderTargetType(FOLDER_TARGET_TRACK_TYPE));
792 add_item(new BinFolderTargetType(FOLDER_TARGET_WIDTH));
793 add_item(new BinFolderTargetType(FOLDER_TARGET_HEIGHT));
794 add_item(new BinFolderTargetType(FOLDER_TARGET_FRAMERATE));
795 add_item(new BinFolderTargetType(FOLDER_TARGET_SAMPLERATE));
796 add_item(new BinFolderTargetType(FOLDER_TARGET_CHANNELS));
797 add_item(new BinFolderTargetType(FOLDER_TARGET_DURATION));
800 void BinFolderTargetPopup::activate_menu(BC_ListBoxItem *item)
802 this->target = (BinFolderTarget *)item;
803 BC_PopupMenu::activate_menu();
807 BinFolderTargetPatterns::BinFolderTargetPatterns(BinFolderFilter *filter)
808 : BinFolderTarget(filter, FOLDER_TARGET_PATTERNS)
813 BinFolderTargetPatterns::~BinFolderTargetPatterns()
818 void BinFolderTargetPatterns::save_xml(FileXML *file) {}
819 void BinFolderTargetPatterns::load_xml(FileXML *file) {}
821 void BinFolderTargetPatterns::copy_from(BinFolderTarget *that)
823 BinFolderTargetPatterns *tp = (BinFolderTargetPatterns*)that;
827 void BinFolderTargetPatterns::update(const char *text)
829 delete [] this->text;
830 this->text = cstrdup(text);
831 filter->update_value(text);
834 BC_Window *BinFolderTargetPatterns::new_gui(ModifyTargetThread *thread)
836 return new ModifyTargetPatternsGUI(thread);
840 BinFolderTargetFileSize::BinFolderTargetFileSize(BinFolderFilter *filter)
841 : BinFolderTarget(filter, FOLDER_TARGET_FILE_SIZE)
844 update(file_size, -1);
846 BinFolderTargetFileSize::~BinFolderTargetFileSize()
850 void BinFolderTargetFileSize::save_xml(FileXML *file)
852 file->tag.set_property("FILE_SIZE", file_size);
853 file->tag.set_property("AROUND", around);
856 void BinFolderTargetFileSize::load_xml(FileXML *file)
858 int64_t file_size = file->tag.get_property("FILE_SIZE", this->file_size);
859 double around = file->tag.get_property("AROUND", this->around);
860 update(file_size, around);
863 void BinFolderTargetFileSize::copy_from(BinFolderTarget *that)
865 BinFolderTargetFileSize *tp = (BinFolderTargetFileSize *)that;
866 update(tp->file_size, tp->around);
869 void BinFolderTargetFileSize::update(int64_t file_size, double around)
871 this->file_size = file_size;
872 this->around = around;
873 char txt[BCSTRLEN], *cp = txt, *ep = cp + sizeof(txt)-1;
874 show_no(file_size, cp, ep);
875 if( around >= 0 && filter->op->type == FOLDER_OP_AROUND ) {
876 if( cp < ep ) *cp++ = '+';
877 show_no(around, cp, ep);
880 filter->update_value(txt);
883 BC_Window *BinFolderTargetFileSize::new_gui(ModifyTargetThread *thread)
885 return new ModifyTargetFileSizeGUI(thread);
889 BinFolderTargetTime::BinFolderTargetTime(BinFolderFilter *filter)
890 : BinFolderTarget(filter, FOLDER_TARGET_MOD_TIME)
896 BinFolderTargetTime::~BinFolderTargetTime()
900 void BinFolderTargetTime::save_xml(FileXML *file)
902 file->tag.set_property("MTIME", mtime);
903 file->tag.set_property("AROUND", around);
906 void BinFolderTargetTime::load_xml(FileXML *file)
908 int64_t mtime = file->tag.get_property("MTIME", this->mtime);
909 double around = file->tag.get_property("AROUND", this->around);
910 update(mtime, around);
913 void BinFolderTargetTime::copy_from(BinFolderTarget *that)
915 BinFolderTargetTime *tp = (BinFolderTargetTime *)that;
916 update(tp->mtime, tp->around);
919 void BinFolderTargetTime::update(int64_t mtime, double around)
922 this->around = around;
923 char txt[BCSTRLEN], *cp = txt, *ep = cp + sizeof(txt)-1;
924 show_date(mtime, cp, ep);
925 if( around >= 0 && filter->op->type == FOLDER_OP_AROUND ) {
926 if( cp < ep ) *cp++ = '+';
927 show_duration(around, cp, ep);
930 filter->update_value(txt);
933 BC_Window *BinFolderTargetTime::new_gui(ModifyTargetThread *thread)
935 return new ModifyTargetTimeGUI(thread);
939 BinFolderTargetTrackType::BinFolderTargetTrackType(BinFolderFilter *filter)
940 : BinFolderTarget(filter, FOLDER_TARGET_TRACK_TYPE)
942 data_types = (1<<TRACK_AUDIO);
945 BinFolderTargetTrackType::~BinFolderTargetTrackType()
949 void BinFolderTargetTrackType::save_xml(FileXML *file)
951 file->tag.set_property("DATA_TYPES", data_types);
954 void BinFolderTargetTrackType::load_xml(FileXML *file)
956 int data_types = file->tag.get_property("DATA_TYPES", this->data_types);
960 void BinFolderTargetTrackType::copy_from(BinFolderTarget *that)
962 BinFolderTargetTrackType *tp = (BinFolderTargetTrackType *)that;
963 update(tp->data_types);
966 void BinFolderTargetTrackType::update(int data_types)
968 this->data_types = data_types;
970 char txt[BCSTRLEN], *cp = txt, *ep = cp + sizeof(txt)-1;
971 if( data_types & (1<<TRACK_AUDIO) ) {
972 if( cp > txt && cp < ep ) *cp++ = ' ';
973 cp += snprintf(cp, ep-cp, "%s",_("audio"));
975 if( data_types & (1<<TRACK_VIDEO) ) {
976 if( cp > txt && cp < ep ) *cp++ = ' ';
977 cp += snprintf(cp, ep-cp, "%s",_("video"));
980 filter->update_value(txt);
983 BC_Window *BinFolderTargetTrackType::new_gui(ModifyTargetThread *thread)
985 return new ModifyTargetTrackTypeGUI(thread);
989 BinFolderTargetWidth::BinFolderTargetWidth(BinFolderFilter *filter)
990 : BinFolderTarget(filter, FOLDER_TARGET_WIDTH)
995 BinFolderTargetWidth::~BinFolderTargetWidth()
999 void BinFolderTargetWidth::save_xml(FileXML *file)
1001 file->tag.set_property("WIDTH", width);
1002 file->tag.set_property("AROUND", around);
1004 void BinFolderTargetWidth::load_xml(FileXML *file)
1006 int width = file->tag.get_property("WIDTH", this->width);
1007 double around = file->tag.get_property("AROUND", this->around);
1008 update(width, around);
1011 void BinFolderTargetWidth::copy_from(BinFolderTarget *that)
1013 BinFolderTargetWidth *tp = (BinFolderTargetWidth *)that;
1014 update(tp->width, tp->around);
1017 void BinFolderTargetWidth::update(int width, double around)
1019 this->width = width;
1020 this->around = around;
1021 char txt[BCSTRLEN], *cp = txt, *ep = cp + sizeof(txt)-1;
1022 show_no(width, cp, ep);
1023 if( around >= 0 && filter->op->type == FOLDER_OP_AROUND ) {
1024 if( cp < ep ) *cp++ = '+';
1025 show_no(around, cp, ep);
1028 filter->update_value(txt);
1031 BC_Window *BinFolderTargetWidth::new_gui(ModifyTargetThread *thread)
1033 return new ModifyTargetWidthGUI(thread);
1037 BinFolderTargetHeight::BinFolderTargetHeight(BinFolderFilter *filter)
1038 : BinFolderTarget(filter, FOLDER_TARGET_HEIGHT)
1043 BinFolderTargetHeight::~BinFolderTargetHeight()
1047 void BinFolderTargetHeight::save_xml(FileXML *file)
1049 file->tag.set_property("HEIGHT", height);
1050 file->tag.set_property("AROUND", around);
1052 void BinFolderTargetHeight::load_xml(FileXML *file)
1054 int height = file->tag.get_property("HEIGHT", this->height);
1055 double around = file->tag.get_property("AROUND", this->around);
1056 update(height, around);
1059 void BinFolderTargetHeight::copy_from(BinFolderTarget *that)
1061 BinFolderTargetHeight *tp = (BinFolderTargetHeight *)that;
1062 update(tp->height, tp->around);
1065 void BinFolderTargetHeight::update(int height, double around)
1067 this->height = height;
1068 this->around = around;
1069 char txt[BCSTRLEN], *cp = txt, *ep = cp + sizeof(txt)-1;
1070 show_no(height, cp, ep);
1071 if( around >= 0 && filter->op->type == FOLDER_OP_AROUND ) {
1072 if( cp < ep ) *cp++ = '+';
1073 show_no(around, cp, ep);
1076 filter->update_value(txt);
1079 BC_Window *BinFolderTargetHeight::new_gui(ModifyTargetThread *thread)
1081 return new ModifyTargetHeightGUI(thread);
1085 BinFolderTargetFramerate::BinFolderTargetFramerate(BinFolderFilter *filter)
1086 : BinFolderTarget(filter, FOLDER_TARGET_FRAMERATE)
1089 update(framerate, -1);
1091 BinFolderTargetFramerate::~BinFolderTargetFramerate()
1095 void BinFolderTargetFramerate::save_xml(FileXML *file)
1097 file->tag.set_property("FRAMERATE", framerate);
1098 file->tag.set_property("AROUND", around);
1101 void BinFolderTargetFramerate::load_xml(FileXML *file)
1103 double framerate = file->tag.get_property("FRAMERATE", this->framerate);
1104 double around = file->tag.get_property("AROUND", this->around);
1105 update(framerate, around);
1108 void BinFolderTargetFramerate::copy_from(BinFolderTarget *that)
1110 BinFolderTargetFramerate *tp = (BinFolderTargetFramerate *)that;
1111 update(tp->framerate, tp->around);
1114 void BinFolderTargetFramerate::update(double framerate, double around)
1116 this->framerate = framerate;
1117 this->around = around;
1118 char txt[BCSTRLEN], *cp = txt, *ep = cp + sizeof(txt)-1;
1119 show_no(framerate, cp, ep, "%0.3f");
1120 if( around >= 0 && filter->op->type == FOLDER_OP_AROUND ) {
1121 if( cp < ep ) *cp++ = '+';
1122 show_no(around, cp, ep, "%0.3f");
1125 filter->update_value(txt);
1128 BC_Window *BinFolderTargetFramerate::new_gui(ModifyTargetThread *thread)
1130 return new ModifyTargetFramerateGUI(thread);
1134 BinFolderTargetSamplerate::BinFolderTargetSamplerate(BinFolderFilter *filter)
1135 : BinFolderTarget(filter, FOLDER_TARGET_SAMPLERATE)
1138 update(samplerate, -1);
1141 BinFolderTargetSamplerate::~BinFolderTargetSamplerate()
1145 void BinFolderTargetSamplerate::save_xml(FileXML *file)
1147 file->tag.set_property("SAMPLERATE", samplerate);
1148 file->tag.set_property("AROUND", around);
1151 void BinFolderTargetSamplerate::load_xml(FileXML *file)
1153 double samplerate = file->tag.get_property("SAMPLERATE", this->samplerate);
1154 double around = file->tag.get_property("AROUND", this->around);
1155 update(samplerate, around);
1158 void BinFolderTargetSamplerate::copy_from(BinFolderTarget *that)
1160 BinFolderTargetSamplerate *tp = (BinFolderTargetSamplerate *)that;
1161 update(tp->samplerate, tp->around);
1164 void BinFolderTargetSamplerate::update(int samplerate, double around)
1166 this->samplerate = samplerate;
1167 this->around = around;
1168 char txt[BCSTRLEN], *cp = txt, *ep = cp + sizeof(txt)-1;
1169 show_no(samplerate, cp, ep);
1170 if( around >= 0 && filter->op->type == FOLDER_OP_AROUND ) {
1171 if( cp < ep ) *cp++ = '+';
1172 show_no(around, cp, ep);
1175 filter->update_value(txt);
1178 BC_Window *BinFolderTargetSamplerate::new_gui(ModifyTargetThread *thread)
1180 return new ModifyTargetSamplerateGUI(thread);
1184 BinFolderTargetChannels::BinFolderTargetChannels(BinFolderFilter *filter)
1185 : BinFolderTarget(filter, FOLDER_TARGET_CHANNELS)
1188 update(channels, -1);
1190 BinFolderTargetChannels::~BinFolderTargetChannels()
1194 void BinFolderTargetChannels::save_xml(FileXML *file)
1196 file->tag.set_property("CHANNELS", channels);
1197 file->tag.set_property("AROUND", around);
1200 void BinFolderTargetChannels::load_xml(FileXML *file)
1202 int channels = file->tag.get_property("CHANNELS", this->channels);
1203 double around = file->tag.get_property("AROUND", this->around);
1204 update(channels, around);
1207 void BinFolderTargetChannels::copy_from(BinFolderTarget *that)
1209 BinFolderTargetChannels *tp = (BinFolderTargetChannels *)that;
1210 update(tp->channels, tp->around);
1213 void BinFolderTargetChannels::update(int channels, double around)
1215 this->channels = channels;
1216 this->around = around;
1217 char txt[BCSTRLEN], *cp = txt, *ep = cp + sizeof(txt)-1;
1218 show_no(channels, cp, ep);
1219 if( around >= 0 && filter->op->type == FOLDER_OP_AROUND ) {
1220 if( cp < ep ) *cp++ = '+';
1221 show_no(around, cp, ep);
1224 filter->update_value(txt);
1227 BC_Window *BinFolderTargetChannels::new_gui(ModifyTargetThread *thread)
1229 return new ModifyTargetChannelsGUI(thread);
1233 BinFolderTargetDuration::BinFolderTargetDuration(BinFolderFilter *filter)
1234 : BinFolderTarget(filter, FOLDER_TARGET_DURATION)
1237 update(duration, -1);
1239 BinFolderTargetDuration::~BinFolderTargetDuration()
1243 void BinFolderTargetDuration::save_xml(FileXML *file)
1245 file->tag.set_property("DURATION", duration);
1246 file->tag.set_property("AROUND", around);
1249 void BinFolderTargetDuration::load_xml(FileXML *file)
1251 int64_t duration = file->tag.get_property("DURATION", this->duration);
1252 double around = file->tag.get_property("AROUND", this->around);
1253 update(duration, around);
1256 void BinFolderTargetDuration::copy_from(BinFolderTarget *that)
1258 BinFolderTargetDuration *tp = (BinFolderTargetDuration *)that;
1259 update(tp->duration, tp->around);
1262 void BinFolderTargetDuration::update(int64_t duration, double around)
1264 this->duration = duration;
1265 this->around = around;
1266 char txt[BCSTRLEN], *cp = txt, *ep = cp + sizeof(txt)-1;
1267 show_duration(duration, cp, ep);
1268 if( around >= 0 && filter->op->type == FOLDER_OP_AROUND ) {
1269 if( cp < ep ) *cp++ = '+';
1270 show_duration(around, cp, ep);
1273 filter->update_value(txt);
1276 BC_Window *BinFolderTargetDuration::new_gui(ModifyTargetThread *thread)
1278 return new ModifyTargetDurationGUI(thread);
1282 BinFolderOp::BinFolderOp(BinFolderFilter *filter, int type)
1283 : BC_ListBoxItem(_(types[type]))
1285 this->filter = filter;
1289 BinFolderOp::~BinFolderOp()
1293 void BinFolderOp::copy_from(BinFolderOp *that)
1298 BinFolderOpType::BinFolderOpType(int no)
1299 : BC_MenuItem(_(BinFolderOp::types[no]))
1303 BinFolderOpType::~BinFolderOpType()
1307 int BinFolderOpType::handle_event()
1309 BinFolderOpPopup *op_popup = (BinFolderOpPopup *)get_popup_menu();
1310 BinFolderList *folder_list = op_popup->folder_list;
1311 int i = folder_list->get_selection_number(FOLDER_COLUMN_OP, 0);
1313 BinFolder *folder = folder_list->folder;
1314 BinFolderFilter *filter = folder->filters[i];
1315 filter->update_op(no);
1316 folder_list->create_list();
1321 BinFolderOpPopup::BinFolderOpPopup(BinFolderList *folder_list)
1322 : BC_PopupMenu(0, 0, 0, "", 0)
1324 this->folder_list = folder_list;
1328 void BinFolderOpPopup::create_objects()
1330 add_item(new BinFolderOpType(FOLDER_OP_AROUND));
1331 add_item(new BinFolderOpType(FOLDER_OP_EQ));
1332 add_item(new BinFolderOpType(FOLDER_OP_GE));
1333 add_item(new BinFolderOpType(FOLDER_OP_GT));
1334 add_item(new BinFolderOpType(FOLDER_OP_NE));
1335 add_item(new BinFolderOpType(FOLDER_OP_LE));
1336 add_item(new BinFolderOpType(FOLDER_OP_LT));
1337 add_item(new BinFolderOpType(FOLDER_OP_MATCHES));
1340 void BinFolderOpPopup::activate_menu(BC_ListBoxItem *item)
1342 this->op = (BinFolderOp *)item;
1343 BC_PopupMenu::activate_menu();
1346 double BinFolderOp::test(BinFolderTarget *target, Indexable *idxbl)
1351 double BinFolderOpEQ::test(BinFolderTarget *target, Indexable *idxbl)
1353 double v = compare(target, idxbl);
1354 return v == 0 ? 1 : -1;
1357 double BinFolderOpGT::test(BinFolderTarget *target, Indexable *idxbl)
1359 double v = compare(target, idxbl);
1360 return v > 0 ? 1 : -1;
1363 double BinFolderOpGE::test(BinFolderTarget *target, Indexable *idxbl)
1365 double v = compare(target, idxbl);
1366 return v >= 0 ? 1 : -1;
1369 double BinFolderOpNE::test(BinFolderTarget *target, Indexable *idxbl)
1371 double v = compare(target, idxbl);
1372 return v != 0 ? 1 : -1;
1375 double BinFolderOpLT::test(BinFolderTarget *target, Indexable *idxbl)
1377 double v = compare(target, idxbl);
1378 return v < 0 ? 1 : -1;
1381 double BinFolderOpLE::test(BinFolderTarget *target, Indexable *idxbl)
1383 double v = compare(target, idxbl);
1384 return v <= 0 ? 1 : -1;
1387 double BinFolderOpMatches::test(BinFolderTarget *target, Indexable *idxbl)
1389 double v = compare(target, idxbl);
1393 double BinFolderOpAround::test(BinFolderTarget *target, Indexable *idxbl)
1395 double v = compare(target, idxbl);
1399 BinFolderValue::BinFolderValue(BinFolderFilter *filter, const char *text)
1402 this->filter = filter;
1406 BinFolderValue::~BinFolderValue()
1411 void BinFolderValue::update(const char *text)
1413 const char *cp = text;
1414 char txt[BCSTRLEN], *tp = txt;
1415 for( int i=sizeof(txt); --i>0 && *cp!=0 && *cp!='\n'; ++tp,++cp ) *tp = *cp;
1421 BinFolderList::BinFolderList(BinFolder *folder, MWindow *mwindow,
1422 ModifyFolderGUI *window, int x, int y, int w, int h)
1423 : BC_ListBox(x, y, w, h, LISTBOX_TEXT, 0,
1424 0, 0, 1, 0, 0, LISTBOX_SINGLE, ICON_LEFT, 1)
1426 this->folder = folder;
1427 this->mwindow = mwindow;
1428 this->window = window;
1430 set_process_drag(1);
1437 BinFolderList::~BinFolderList()
1439 save_defaults(mwindow->defaults);
1440 delete modify_target;
1443 void BinFolderList::create_objects()
1445 list_titles[FOLDER_COLUMN_ENABLE] = _("Enable");
1446 list_titles[FOLDER_COLUMN_TARGET] = _("Target");
1447 list_titles[FOLDER_COLUMN_OP] = _("Op");
1448 list_titles[FOLDER_COLUMN_VALUE] = _("Value");
1449 list_width[FOLDER_COLUMN_ENABLE] = 80;
1450 list_width[FOLDER_COLUMN_TARGET] = 80;
1451 list_width[FOLDER_COLUMN_OP] = 50;
1452 list_width[FOLDER_COLUMN_VALUE] = 180;
1453 load_defaults(mwindow->defaults);
1455 add_subwindow(enabled_popup = new BinFolderEnabledPopup(this));
1456 enabled_popup->create_objects();
1457 add_subwindow(op_popup = new BinFolderOpPopup(this));
1458 op_popup->create_objects();
1459 add_subwindow(target_popup = new BinFolderTargetPopup(this));
1460 target_popup->create_objects();
1462 modify_target = new ModifyTargetThread(this);
1465 void BinFolderList::create_list()
1467 for( int i=0; i<FOLDER_COLUMNS; ++i )
1468 list_items[i].remove_all();
1469 for( int i=0; i<folder->filters.size(); ++i ) {
1470 BinFolderFilter *filter = folder->filters[i];
1471 list_items[FOLDER_COLUMN_ENABLE].append(filter->enabled);
1472 list_items[FOLDER_COLUMN_TARGET].append(filter->target);
1473 list_items[FOLDER_COLUMN_OP].append(filter->op);
1474 list_items[FOLDER_COLUMN_VALUE].append(filter->value);
1476 update(list_items, list_titles, list_width, FOLDER_COLUMNS,
1477 get_xposition(), get_yposition(), get_highlighted_item(),
1481 int BinFolderList::handle_event()
1486 int BinFolderList::selection_changed()
1488 if( !cursor_above() ) return 0;
1489 int no = get_selection_number(0, 0);
1490 if( no < 0 ) return 0;
1491 BinFolderFilter *filter = folder->filters[no];
1492 if( get_button_down() && get_buttonpress() == 3 ) {
1493 int cx = get_cursor_x(), col = -1;
1494 for( int i=0; col<0 && i<FOLDER_COLUMNS; ++i ) {
1495 int ofs = get_column_offset(i);
1496 if( cx >= ofs && cx < ofs+get_column_width(i) ) {
1500 BC_ListBoxItem *item = col >= 0 ? get_selection(col, 0) : 0;
1502 deactivate_selection();
1504 case FOLDER_COLUMN_ENABLE:
1505 enabled_popup->activate_menu(item);
1507 case FOLDER_COLUMN_TARGET:
1508 target_popup->activate_menu(item);
1510 case FOLDER_COLUMN_OP:
1511 op_popup->activate_menu(item);
1513 case FOLDER_COLUMN_VALUE: {
1514 modify_target->close_window();
1515 int cw = filter->target->type == FOLDER_TARGET_PATTERNS ? 400 : 320;
1516 int ch = filter->target->type == FOLDER_TARGET_PATTERNS ? 300 : 120;
1517 int cx, cy; get_abs_cursor(cx, cy);
1518 if( (cx-=cw/2) < 50 ) cx = 50;
1519 if( (cy-=ch/2) < 50 ) cy = 50;
1520 modify_target->start(filter->target, cx, cy, cw, ch);
1528 int BinFolderList::column_resize_event()
1530 for( int i = 0; i < FOLDER_COLUMNS; i++ ) {
1531 list_width[i] = get_column_width(i);
1536 int BinFolderList::drag_start_event()
1538 if( BC_ListBox::drag_start_event() ) {
1546 int BinFolderList::drag_motion_event()
1548 if( BC_ListBox::drag_motion_event() ) {
1554 int BinFolderList::drag_stop_event()
1556 if( dragging_item ) {
1557 int src = get_selection_number(0, 0);
1558 int dst = get_highlighted_item();
1560 move_filter(src, dst);
1562 BC_ListBox::drag_stop_event();
1568 void BinFolderList::move_filter(int src, int dst)
1570 BinFolderFilters &filters = folder->filters;
1571 BinFolderFilter *src_filter = filters[src];
1572 if( dst < 0 ) dst = filters.size()-1;
1575 for( int i=src; i<filters.size()-1; ++i )
1576 filters[i] = filters[i+1];
1577 for( int i=filters.size(); --i>dst; )
1578 filters[i] = filters[i-1];
1579 filters[dst] = src_filter;
1583 void BinFolderList::save_defaults(BC_Hash *defaults)
1585 defaults->update("BIN_FOLDER_ENA", list_width[FOLDER_COLUMN_ENABLE]);
1586 defaults->update("BIN_FOLDER_TGT", list_width[FOLDER_COLUMN_TARGET]);
1587 defaults->update("BIN_FOLDER_OPR", list_width[FOLDER_COLUMN_OP]);
1588 defaults->update("BIN_FOLDER_VAL", list_width[FOLDER_COLUMN_VALUE]);
1590 void BinFolderList::load_defaults(BC_Hash *defaults)
1592 list_width[FOLDER_COLUMN_ENABLE] = defaults->get("BIN_FOLDER_ENA", list_width[FOLDER_COLUMN_ENABLE]);
1593 list_width[FOLDER_COLUMN_TARGET] = defaults->get("BIN_FOLDER_TGT", list_width[FOLDER_COLUMN_TARGET]);
1594 list_width[FOLDER_COLUMN_OP] = defaults->get("BIN_FOLDER_OPR", list_width[FOLDER_COLUMN_OP]);
1595 list_width[FOLDER_COLUMN_VALUE] = defaults->get("BIN_FOLDER_VAL", list_width[FOLDER_COLUMN_VALUE]);
1598 BinFolderAddFilter::BinFolderAddFilter(BinFolderList *folder_list, int x, int y)
1599 : BC_GenericButton(x, y, _("Add"))
1601 this->folder_list = folder_list;
1603 BinFolderAddFilter::~BinFolderAddFilter()
1607 int BinFolderAddFilter::handle_event()
1609 folder_list->modify_target->close_window();
1610 // default new filter
1611 BinFolderFilter *filter = new BinFolderFilter();
1612 filter->update_enabled(FOLDER_ENABLED_OR);
1613 filter->update_target(FOLDER_TARGET_PATTERNS);
1614 filter->update_op(FOLDER_OP_MATCHES);
1615 BinFolderTargetPatterns *patterns = (BinFolderTargetPatterns *)(filter->target);
1616 filter->update_value(patterns->text);
1617 folder_list->folder->filters.append(filter);
1618 folder_list->create_list();
1622 BinFolderDelFilter::BinFolderDelFilter(BinFolderList *folder_list, int x, int y)
1623 : BC_GenericButton(x, y, _("Del"))
1625 this->folder_list = folder_list;
1627 BinFolderDelFilter::~BinFolderDelFilter()
1631 int BinFolderDelFilter::handle_event()
1633 folder_list->modify_target->close_window();
1634 int no = folder_list->get_selection_number(0, 0);
1636 folder_list->folder->filters.remove_object_number(no);
1637 folder_list->create_list();
1642 BinFolderApplyFilter::BinFolderApplyFilter(BinFolderList *folder_list, int x, int y)
1643 : BC_GenericButton(x, y, _("Apply"))
1645 this->folder_list = folder_list;
1647 BinFolderApplyFilter::~BinFolderApplyFilter()
1651 int BinFolderApplyFilter::handle_event()
1653 ModifyFolderThread *thread = folder_list->window->thread;
1654 thread->original->copy_from(thread->folder);
1655 thread->agui->async_update_assets();
1660 NewFolderGUI::NewFolderGUI(NewFolderThread *thread, int x, int y, int w, int h)
1661 : BC_Window(_(PROGRAM_NAME ": New folder"),
1662 x, y, w, h, -1, -1, 0, 0, 1)
1664 this->thread = thread;
1667 NewFolderGUI::~NewFolderGUI()
1671 void NewFolderGUI::create_objects()
1673 lock_window("NewFolderGUI::create_objects");
1676 add_subwindow(title = new BC_Title(x, y, _("Folder name:")));
1677 y += title->get_h() + 5;
1678 const char *text = !thread->is_clips ? _("media bin") : _("clip bin");
1679 add_subwindow(text_box = new BC_TextBox(x, y, 300, 1, text));
1680 add_subwindow(new BC_OKButton(this));
1681 add_subwindow(new BC_CancelButton(this));
1686 const char* NewFolderGUI::get_text()
1688 return text_box->get_text();
1692 NewFolderThread::NewFolderThread(AWindowGUI *agui)
1699 NewFolderThread::~NewFolderThread()
1704 void NewFolderThread::start(int x, int y, int w, int h, int is_clips)
1707 this->is_clips = is_clips;
1708 this->wx = x; this->wy = y;
1709 this->ww = w; this->wh = h;
1713 BC_Window *NewFolderThread::new_gui()
1715 window = new NewFolderGUI(this, wx, wy, ww, wh);
1716 window->create_objects();
1720 void NewFolderThread::handle_done_event(int result)
1723 const char *text = window->get_text();
1724 agui->mwindow->new_folder(text, is_clips);
1728 void NewFolderThread::handle_close_event(int result)
1733 ModifyFolderGUI::ModifyFolderGUI(ModifyFolderThread *thread, int x, int y, int w, int h)
1734 : BC_Window(_(PROGRAM_NAME ": Modify folder"), x, y, w, h, 320, 200, 1, 0, 1)
1736 this->thread = thread;
1739 ModifyFolderGUI::~ModifyFolderGUI()
1743 int ModifyFolderGUI::receive_custom_xatoms(xatom_event *event)
1745 if( event->message_type == modify_folder_xatom ) {
1752 void ModifyFolderGUI::async_update_filters()
1755 event.message_type = modify_folder_xatom;
1756 send_custom_xatom(&event);
1760 void ModifyFolderGUI::create_objects()
1762 lock_window("ModifyFolderGUI::create_objects");
1763 modify_folder_xatom = create_xatom("CWINDOWGUI_UPDATE_FILTERS");
1766 add_subwindow(title = new BC_Title(x, y, _("Enter the name of the folder:")));
1767 const char *text = !thread->folder->is_clips ? _("Media") : _("Clips");
1768 int tw = BC_Title::calculate_w(this, text, LARGEFONT);
1769 int x0 = get_w() - 50 - tw;
1770 add_subwindow(text_title = new BC_Title(x0, y, text, LARGEFONT, YELLOW));
1771 y += title->get_h() + 10;
1772 add_subwindow(text_box = new BC_TextBox(x, y, 300, 1, thread->folder->title));
1773 y += text_box->get_h() + 10;
1774 int lh = get_h() - y - BC_OKButton::calculate_h() - 30;
1775 int lw = get_w() - x - 160;
1776 add_subwindow(folder_list =
1777 new BinFolderList(thread->folder, thread->agui->mwindow, this, x, y, lw, lh));
1778 folder_list->create_objects();
1779 int x1 = x + folder_list->get_w() + 15, y1 = y;
1780 add_subwindow(add_filter = new BinFolderAddFilter(folder_list, x1, y1));
1781 y1 += add_filter->get_h() + 10;
1782 add_subwindow(del_filter = new BinFolderDelFilter(folder_list, x1, y1));
1783 y1 += del_filter->get_h() + 10;
1784 add_subwindow(apply_filter = new BinFolderApplyFilter(folder_list, x1, y1));
1785 add_subwindow(ok_button = new BC_OKButton(this));
1786 add_subwindow(cancel_button = new BC_CancelButton(this));
1791 int ModifyFolderGUI::resize_event(int w, int h)
1793 MWindow *mwindow = thread->agui->mwindow;
1794 mwindow->session->bwindow_w = w;
1795 mwindow->session->bwindow_h = h;
1796 int tx = text_title->get_x() + w - get_w();
1797 int ty = text_title->get_y();
1798 text_title->reposition_window(tx, ty);
1799 int lx = folder_list->get_x();
1800 int ly = folder_list->get_y();
1801 int lh = h - ly - BC_OKButton::calculate_h() - 30;
1802 int lw = w - lx - 160;
1803 folder_list->reposition_window(lx, ly, lw, lh);
1804 int x1 = lx + lw + 15;
1805 add_filter->reposition_window(x1, add_filter->get_y());
1806 del_filter->reposition_window(x1, del_filter->get_y());
1807 apply_filter->reposition_window(x1,apply_filter->get_y());
1808 ok_button->resize_event(w, h);
1809 cancel_button->resize_event(w, h);
1813 const char* ModifyFolderGUI::get_text()
1815 return text_box->get_text();
1818 void ModifyFolderGUI::update_filters()
1820 folder_list->create_list();
1824 ModifyFolderThread::ModifyFolderThread(AWindowGUI *agui)
1833 ModifyFolderThread::~ModifyFolderThread()
1839 void ModifyFolderThread::start(BinFolder *folder, int x, int y, int w, int h)
1842 this->original = folder;
1843 this->modify_edl = agui->mwindow->edl;
1844 this->modify_edl->add_user();
1845 this->folder = new BinFolder(*folder);
1846 this->wx = x; this->wy = y;
1847 this->ww = w; this->wh = h;
1851 BC_Window *ModifyFolderThread::new_gui()
1853 window = new ModifyFolderGUI(this, wx, wy, ww, wh);
1854 window->create_objects();
1858 void ModifyFolderThread::handle_done_event(int result)
1861 const char *title = window->get_text();
1862 if( strcmp(folder->title, title) ) {
1863 if( agui->mwindow->edl->get_folder_number(title) >= 0 ) {
1864 eprintf("folder already exists: %s", title);
1868 strncpy(folder->title, title,sizeof(folder->title));
1872 original->copy_from(folder);
1873 agui->async_update_assets();
1875 delete folder; folder = 0;
1877 modify_edl->remove_user();
1880 void ModifyFolderThread::handle_close_event(int result)
1885 ModifyTargetThread::ModifyTargetThread(BinFolderList *folder_list)
1888 this->folder_list = folder_list;
1892 ModifyTargetThread::~ModifyTargetThread()
1897 void ModifyTargetThread::start(BinFolderTarget *target, int x, int y, int w, int h)
1899 this->target = target;
1905 BC_Window *ModifyTargetThread::new_gui()
1907 window = (ModifyTargetGUI *)target->new_gui(this);
1908 window->create_objects();
1912 void ModifyTargetThread::handle_done_event(int result)
1916 folder_list->window->async_update_filters();
1920 void ModifyTargetThread::handle_close_event(int result)
1925 ModifyTargetGUI::ModifyTargetGUI(ModifyTargetThread *thread, int allow_resize)
1926 : BC_Window(_(PROGRAM_NAME ": Modify target"),
1927 thread->wx, thread->wy, thread->ww, thread->wh,
1928 -1, -1, allow_resize, 0, 1)
1930 this->thread = thread;
1933 ModifyTargetGUI::~ModifyTargetGUI()
1937 void ModifyTargetGUI::create_objects(BC_TextBox *&text_box)
1939 lock_window("ModifyTargetGUI::create_objects");
1941 const char *text = thread->target->filter->value->get_text();
1942 add_subwindow(text_box = new BC_TextBox(x, y, get_w()-20, 1, text));
1943 add_subwindow(new BC_OKButton(this));
1944 add_subwindow(new BC_CancelButton(this));
1949 int ModifyTargetGUI::resize_event(int w, int h)
1951 return BC_WindowBase::resize_event(w, h);
1954 ModifyTargetPatternsGUI::ModifyTargetPatternsGUI(ModifyTargetThread *thread)
1955 : ModifyTargetGUI(thread, 1)
1957 this->thread = thread;
1958 scroll_text_box = 0;
1962 ModifyTargetPatternsGUI::~ModifyTargetPatternsGUI()
1964 delete scroll_text_box;
1967 void ModifyTargetPatternsGUI::create_objects()
1969 lock_window("ModifyTargetPatternsGUI::create_objects");
1970 BinFolderTargetPatterns *target = (BinFolderTargetPatterns *)thread->target;
1972 int text_font = MEDIUMFONT;
1973 text_rowsz = get_text_ascent(text_font)+1 + get_text_descent(text_font)+1;
1974 int th = get_h() - y - BC_OKButton::calculate_h() - 20;
1975 int rows = th / text_rowsz;
1976 int text_len = strlen(target->text);
1977 if( text_len < BCTEXTLEN ) text_len = BCTEXTLEN;
1978 scroll_text_box = new BC_ScrollTextBox(this, x, y, get_w()-20, rows,
1979 target->text, 2*text_len);
1980 scroll_text_box->create_objects();
1981 add_subwindow(ok_button = new BC_OKButton(this));
1982 add_subwindow(cancel_button = new BC_CancelButton(this));
1987 int ModifyTargetPatternsGUI::resize_event(int w, int h)
1989 int tx = scroll_text_box->get_x();
1990 int ty = scroll_text_box->get_y();
1991 int th = h - ty - BC_OKButton::calculate_h() - 20;
1993 int rows = th / text_rowsz;
1994 scroll_text_box->reposition_window(tx, ty, tw, rows);
1995 ok_button->resize_event(w, h);
1996 cancel_button->resize_event(w, h);
2000 void ModifyTargetPatternsGUI::update()
2002 BinFolderTargetPatterns *target = (BinFolderTargetPatterns *)thread->target;
2003 const char *cp = scroll_text_box->get_text();
2008 ModifyTargetFileSizeGUI::ModifyTargetFileSizeGUI(ModifyTargetThread *thread)
2009 : ModifyTargetGUI(thread)
2013 ModifyTargetFileSizeGUI::~ModifyTargetFileSizeGUI()
2017 void ModifyTargetFileSizeGUI::create_objects()
2019 ModifyTargetGUI::create_objects(text_box);
2022 void ModifyTargetFileSizeGUI::update()
2024 BinFolderTargetFileSize *target = (BinFolderTargetFileSize *)thread->target;
2025 double file_size = target->file_size, around = target->around;
2026 const char *cp = text_box->get_text(); char *bp = 0;
2027 scan_around(cp, bp, file_size, around);
2028 target->update(file_size, around);
2032 ModifyTargetTimeGUI::ModifyTargetTimeGUI(ModifyTargetThread *thread)
2033 : ModifyTargetGUI(thread)
2037 ModifyTargetTimeGUI::~ModifyTargetTimeGUI()
2041 void ModifyTargetTimeGUI::create_objects()
2043 ModifyTargetGUI::create_objects(text_box);
2046 void ModifyTargetTimeGUI::update()
2048 BinFolderTargetTime *target = (BinFolderTargetTime *)thread->target;
2049 int64_t mtime = target->mtime; double around = target->around;
2050 const char *cp = text_box->get_text(); char *bp = 0;
2051 int64_t v = scan_date(cp, bp);
2055 v = scan_duration(cp=bp+1, bp);
2056 if( bp > cp ) around = v;
2059 target->update(mtime, around);
2063 ModifyTargetTrackTypeGUI::ModifyTargetTrackTypeGUI(ModifyTargetThread *thread)
2064 : ModifyTargetGUI(thread)
2068 ModifyTargetTrackTypeGUI::~ModifyTargetTrackTypeGUI()
2072 void ModifyTargetTrackTypeGUI::create_objects()
2074 ModifyTargetGUI::create_objects(text_box);
2077 void ModifyTargetTrackTypeGUI::update()
2079 BinFolderTargetTrackType *target = (BinFolderTargetTrackType *)thread->target;
2080 const char *cp = text_box->get_text();
2082 if( bstrcasestr(cp, _("audio")) ) data_types |= (1<<TRACK_AUDIO);
2083 if( bstrcasestr(cp, _("video")) ) data_types |= (1<<TRACK_VIDEO);
2084 target->update(data_types);
2088 ModifyTargetWidthGUI::ModifyTargetWidthGUI(ModifyTargetThread *thread)
2089 : ModifyTargetGUI(thread)
2093 ModifyTargetWidthGUI::~ModifyTargetWidthGUI()
2097 void ModifyTargetWidthGUI::create_objects()
2099 ModifyTargetGUI::create_objects(text_box);
2102 void ModifyTargetWidthGUI::update()
2104 BinFolderTargetWidth *target = (BinFolderTargetWidth *)thread->target;
2105 double width = target->width, around = target->around;
2106 const char *cp = text_box->get_text(); char *bp = 0;
2107 scan_around(cp, bp, width, around);
2108 target->update(width, around);
2112 ModifyTargetHeightGUI::ModifyTargetHeightGUI(ModifyTargetThread *thread)
2113 : ModifyTargetGUI(thread)
2117 ModifyTargetHeightGUI::~ModifyTargetHeightGUI()
2121 void ModifyTargetHeightGUI::create_objects()
2123 ModifyTargetGUI::create_objects(text_box);
2126 void ModifyTargetHeightGUI::update()
2128 BinFolderTargetHeight *target = (BinFolderTargetHeight *)thread->target;
2129 double height = target->height, around = target->around;
2130 const char *cp = text_box->get_text(); char *bp = 0;
2131 scan_around(cp, bp, height, around);
2132 target->update(height, around);
2136 ModifyTargetFramerateGUI::ModifyTargetFramerateGUI(ModifyTargetThread *thread)
2137 : ModifyTargetGUI(thread)
2141 ModifyTargetFramerateGUI::~ModifyTargetFramerateGUI()
2145 void ModifyTargetFramerateGUI::create_objects()
2147 ModifyTargetGUI::create_objects(text_box);
2150 void ModifyTargetFramerateGUI::update()
2152 BinFolderTargetFramerate *target = (BinFolderTargetFramerate *)thread->target;
2153 double framerate = target->framerate, around = target->around;
2154 const char *cp = text_box->get_text(); char *bp = 0;
2155 scan_around(cp, bp, framerate, around);
2156 target->update(framerate, around);
2160 ModifyTargetSamplerateGUI::ModifyTargetSamplerateGUI(ModifyTargetThread *thread)
2161 : ModifyTargetGUI(thread)
2165 ModifyTargetSamplerateGUI::~ModifyTargetSamplerateGUI()
2169 void ModifyTargetSamplerateGUI::create_objects()
2171 ModifyTargetGUI::create_objects(text_box);
2174 void ModifyTargetSamplerateGUI::update()
2176 BinFolderTargetSamplerate *target = (BinFolderTargetSamplerate *)thread->target;
2177 double samplerate = target->samplerate, around = target->around;
2178 const char *cp = text_box->get_text(); char *bp = 0;
2179 scan_around(cp, bp, samplerate, around);
2180 target->update(samplerate, around);
2184 ModifyTargetChannelsGUI::ModifyTargetChannelsGUI(ModifyTargetThread *thread)
2185 : ModifyTargetGUI(thread)
2189 ModifyTargetChannelsGUI::~ModifyTargetChannelsGUI()
2193 void ModifyTargetChannelsGUI::create_objects()
2195 ModifyTargetGUI::create_objects(text_box);
2198 void ModifyTargetChannelsGUI::update()
2200 BinFolderTargetChannels *target = (BinFolderTargetChannels *)thread->target;
2201 double channels = target->channels, around = target->around;
2202 const char *cp = text_box->get_text(); char *bp = 0;
2203 scan_around(cp, bp, channels, around);
2204 target->update(channels, around);
2208 ModifyTargetDurationGUI::ModifyTargetDurationGUI(ModifyTargetThread *thread)
2209 : ModifyTargetGUI(thread)
2213 ModifyTargetDurationGUI::~ModifyTargetDurationGUI()
2217 void ModifyTargetDurationGUI::create_objects()
2219 ModifyTargetGUI::create_objects(text_box);
2222 void ModifyTargetDurationGUI::update()
2224 BinFolderTargetDuration *target = (BinFolderTargetDuration *)thread->target;
2225 int64_t duration = target->duration, around = target->around;
2226 const char *cp = text_box->get_text(); char *bp = 0;
2227 int64_t v = scan_duration(cp, bp);
2231 v = scan_duration(cp=bp+1, bp);
2232 if( bp > cp ) around = v;
2235 target->update(duration, around);