fix bug in batchrender job load from xml
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / batchrender.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2011 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 "batchrender.h"
24 #include "bcdisplayinfo.h"
25 #include "bcsignals.h"
26 #include "confirmsave.h"
27 #include "cstrdup.h"
28 #include "bchash.h"
29 #include "edits.h"
30 #include "edit.h"
31 #include "edl.h"
32 #include "edlsession.h"
33 #include "errorbox.h"
34 #include "file.h"
35 #include "filesystem.h"
36 #include "filexml.h"
37 #include "indexable.h"
38 #include "keyframe.h"
39 #include "keys.h"
40 #include "labels.h"
41 #include "language.h"
42 #include "localsession.h"
43 #include "mainerror.h"
44 #include "mainundo.h"
45 #include "mainsession.h"
46 #include "mutex.h"
47 #include "mwindow.h"
48 #include "mwindowgui.h"
49 #include "packagedispatcher.h"
50 #include "packagerenderer.h"
51 #include "plugin.h"
52 #include "pluginset.h"
53 #include "preferences.h"
54 #include "render.h"
55 #include "theme.h"
56 #include "tracks.h"
57 #include "transportque.h"
58 #include "vframe.h"
59
60 #include "dvdcreate.h"
61 #include "bdcreate.h"
62
63 int BatchRenderThread::column_widths[] = { 42, 42, 42, 222, 222, 150 };
64 const char *BatchRenderThread::column_titles[] = {
65         N_("Enabled"), N_("Labeled"), N_("Farmed"), N_("Output"), N_("EDL"), N_("Elapsed")
66 };
67
68 BatchRenderMenuItem::BatchRenderMenuItem(MWindow *mwindow)
69  : BC_MenuItem(_("Batch Render..."), _("Shift-B"), 'B')
70 {
71         set_shift(1);
72         this->mwindow = mwindow;
73 }
74
75 int BatchRenderMenuItem::handle_event()
76 {
77         mwindow->batch_render->start(1, 1);
78         return 1;
79 }
80
81 BatchRenderJob::BatchRenderJob(const char *tag,
82                 Preferences *preferences, int labeled, int farmed)
83 {
84         this->tag = tag;
85         this->preferences = preferences;
86         this->labeled = labeled;
87         this->farmed = farmed >= 0 ? farmed : preferences->use_renderfarm;
88         asset = new Asset;
89         edl_path[0] = 0;
90         enabled = 1;
91         elapsed = 0;
92 }
93
94 BatchRenderJob::BatchRenderJob(Preferences *preferences, int labeled, int farmed)
95  : BatchRenderJob("JOB", preferences, labeled, farmed)
96 {
97 }
98
99 BatchRenderJob::~BatchRenderJob()
100 {
101         asset->Garbage::remove_user();
102 }
103
104 void BatchRenderJob::copy_from(BatchRenderJob *src)
105 {
106         enabled = src->enabled;
107         farmed = src->farmed;
108         labeled = src->labeled;
109         asset->copy_from(src->asset, 0);
110         strcpy(edl_path, src->edl_path);
111         elapsed = 0;
112 }
113
114 BatchRenderJob *BatchRenderJob::copy()
115 {
116         BatchRenderJob *t = new BatchRenderJob(tag, preferences, labeled, farmed);
117         t->copy_from(this);
118         return t;
119 }
120
121 void BatchRenderJob::load(FileXML *file)
122 {
123         int result = 0;
124         char job_title[BCSTRLEN];
125         strcpy(job_title, file->tag.title);
126
127         enabled = file->tag.get_property("ENABLED", enabled);
128         farmed = file->tag.get_property("FARMED", farmed);
129         labeled = file->tag.get_property("LABELED", labeled);
130         edl_path[0] = 0;
131         file->tag.get_property("EDL_PATH", edl_path);
132         elapsed = file->tag.get_property("ELAPSED", elapsed);
133
134         result = file->read_tag();
135         if( !result ) {
136                 if( file->tag.title_is("ASSET") ) {
137                         file->tag.get_property("SRC", asset->path);
138                         asset->read(file, 0);
139 // The compression parameters are stored in the defaults to reduce
140 // coding maintenance.  The defaults must now be stuffed into the XML for
141 // unique storage.
142                         BC_Hash defaults;
143                         defaults.load_string(file->read_text(job_title));
144                         asset->load_defaults(&defaults,
145                                 "", 0, 1, 0, 0, 0);
146                 }
147         }
148 }
149
150 void BatchRenderJob::save(FileXML *file)
151 {
152         char end_tag[BCSTRLEN];  end_tag[0] = '/';
153         strcpy(&end_tag[1], file->tag.get_title());
154         file->tag.set_property("ENABLED", enabled);
155         file->tag.set_property("FARMED", farmed);
156         file->tag.set_property("LABELED", labeled);
157         file->tag.set_property("EDL_PATH", edl_path);
158         file->tag.set_property("ELAPSED", elapsed);
159         file->append_tag();
160         file->append_newline();
161         asset->write(file, 0, "");
162
163 // The compression parameters are stored in the defaults to reduce
164 // coding maintenance.  The defaults must now be stuffed into the XML for
165 // unique storage.
166         BC_Hash defaults;
167         asset->save_defaults(&defaults, "", 0, 1, 0, 0, 0);
168         char *string;
169         defaults.save_string(string);
170         file->append_text(string);
171         free(string);
172         file->tag.set_title(end_tag);
173         file->append_tag();
174         file->append_newline();
175 }
176
177 char *BatchRenderJob::create_script(EDL *edl, ArrayList<Indexable *> *idxbls)
178 {
179         return 0;
180 }
181
182 int BatchRenderJob::get_strategy()
183 {
184         return Render::get_strategy(farmed, labeled);
185 }
186
187
188 BatchRenderThread::BatchRenderThread(MWindow *mwindow)
189  : BC_DialogThread()
190 {
191         this->mwindow = mwindow;
192         current_job = 0;
193         rendering_job = -1;
194         is_rendering = 0;
195         default_job = 0;
196         boot_defaults = 0;
197         preferences = 0;
198         warn = 1;
199         render = 0;
200         batch_path[0] = 0;
201         do_farmed = 0;
202         do_labeled = 0;
203 }
204
205 BatchRenderThread::~BatchRenderThread()
206 {
207         close_window();
208         delete boot_defaults;
209         delete preferences;
210         delete default_job;
211         delete render;
212 }
213
214 void BatchRenderThread::reset(const char *path)
215 {
216         if( path ) {
217                 strcpy(batch_path, path);
218                 warn = 1;
219         }
220         current_job = 0;
221         rendering_job = -1;
222         delete default_job;  default_job = 0;
223         jobs.remove_all_objects();
224 }
225
226 void BatchRenderThread::start(int do_farmed, int do_labeled)
227 {
228         this->do_farmed = do_farmed;
229         this->do_labeled = do_labeled;
230         BC_DialogThread::start();
231 }
232
233 void BatchRenderThread::handle_close_event(int result)
234 {
235 // Save settings
236         save_jobs(batch_path);
237         save_defaults(mwindow->defaults);
238         reset();
239 }
240
241 BC_Window* BatchRenderThread::new_gui()
242 {
243         current_start = 0.0;
244         current_end = 0.0;
245         default_job = new BatchRenderJob(mwindow->preferences, 0, -1);
246         load_jobs(batch_path, mwindow->preferences);
247         load_defaults(mwindow->defaults);
248         this->gui = new BatchRenderGUI(mwindow, this,
249                 mwindow->session->batchrender_x, mwindow->session->batchrender_y,
250                 mwindow->session->batchrender_w, mwindow->session->batchrender_h);
251         this->gui->create_objects();
252         return this->gui;
253 }
254
255
256 void BatchRenderThread::load_jobs(char *path, Preferences *preferences)
257 {
258         FileXML file;
259         int result = 0;
260
261         jobs.remove_all_objects();
262         if( !path ) path = batch_path;
263         if( !path[0] ) create_path(path);
264         file.read_from_file(path);
265
266         while( !result ) {
267                 if( !(result = file.read_tag()) ) {
268                         if( file.tag.title_is("JOBS") ) {
269                                 warn = file.tag.get_property("WARN", 1);
270                         }
271                         else if( file.tag.title_is("JOB") ) {
272                                 BatchRenderJob *job =  new BatchRenderJob(preferences, 0,0);
273                                 jobs.append(job);
274                                 job->load(&file);
275                         }
276                         else if( file.tag.title_is("DVD_JOB") ) {
277                                 DVD_BatchRenderJob *job =  new DVD_BatchRenderJob(preferences, 0,0,0,0);
278                                 jobs.append(job);
279                                 job->load(&file);
280                         }
281                         else if( file.tag.title_is("BD_JOB") ) {
282                                 BD_BatchRenderJob *job =  new BD_BatchRenderJob(preferences, 0,0);
283                                 jobs.append(job);
284                                 job->load(&file);
285                         }
286                 }
287         }
288 }
289
290 void BatchRenderThread::save_jobs(char *path)
291 {
292         FileXML file;
293         file.tag.set_title("JOBS");
294         file.tag.set_property("WARN", warn);
295         file.append_tag();
296         file.append_newline();
297
298         for( int i = 0; i < jobs.total; i++ ) {
299                 file.tag.set_title(jobs[i]->tag);
300                 jobs[i]->save(&file);
301         }
302         file.tag.set_title("/JOBS");
303         file.append_tag();
304         file.append_newline();
305
306         if( !path ) path = batch_path;
307         if( !path[0] ) create_path(path);
308         file.write_to_file(path);
309 }
310
311 void BatchRenderThread::load_defaults(BC_Hash *defaults)
312 {
313         if( default_job ) {
314                 default_job->asset->load_defaults(defaults,
315                         "BATCHRENDER_", 1, 1, 1, 1, 1);
316         }
317
318         for( int i = 0; i < BATCHRENDER_COLUMNS; i++ ) {
319                 char string[BCTEXTLEN];
320                 sprintf(string, "BATCHRENDER_COLUMN%d", i);
321                 list_width[i] = defaults->get(string, xS(column_widths[i]));
322         }
323 }
324
325 void BatchRenderThread::save_defaults(BC_Hash *defaults)
326 {
327         if( default_job ) {
328                 default_job->asset->save_defaults(defaults,
329                         "BATCHRENDER_", 1, 1, 1, 1, 1);
330         }
331         for( int i=0; i<BATCHRENDER_COLUMNS; ++i ) {
332                 char string[BCTEXTLEN];
333                 sprintf(string, "BATCHRENDER_COLUMN%d", i);
334                 defaults->update(string, list_width[i]);
335         }
336 //      defaults->update("BATCHRENDER_JOB", current_job);
337         if( mwindow )
338                 mwindow->save_defaults();
339         else
340                 defaults->save();
341 }
342
343 char* BatchRenderThread::create_path(char *string)
344 {
345         FileSystem fs;
346         sprintf(string, "%s/", File::get_config_path());
347         fs.complete_path(string);
348         strcat(string, BATCH_PATH);
349         return string;
350 }
351
352 void BatchRenderThread::new_job()
353 {
354         BatchRenderJob *result = get_current_job()->copy();
355         jobs.append(result);
356         current_job = jobs.total - 1;
357         gui->create_list(1);
358         gui->change_job();
359 }
360
361 void BatchRenderThread::delete_job()
362 {
363         if( current_job < jobs.total && current_job >= 0 ) {
364                 jobs.remove_object_number(current_job);
365                 if( current_job > 0 ) current_job--;
366                 gui->create_list(1);
367                 gui->change_job();
368         }
369 }
370
371 void BatchRenderThread::use_current_edl()
372 {
373 // printf("BatchRenderThread::use_current_edl %d %p %s\n",
374 // __LINE__,
375 // mwindow->edl->path,
376 // mwindow->edl->path);
377
378         strcpy(get_current_edl(), mwindow->edl->path);
379         gui->create_list(1);
380         gui->edl_path_text->update(get_current_edl());
381 }
382
383 void BatchRenderThread::update_selected_edl()
384 {
385         FileXML xml_file;
386         char *path = get_current_edl();
387         EDL *edl = mwindow->edl;
388         edl->save_xml(&xml_file, path);
389         xml_file.terminate_string();
390         if( xml_file.write_to_file(path) ) {
391                 char msg[BCTEXTLEN];
392                 sprintf(msg, _("Unable to save: %s"), path);
393                 MainError::show_error(msg);
394         }
395 }
396
397 BatchRenderJob* BatchRenderThread::get_current_job()
398 {
399         return current_job >= 0 && current_job < jobs.total ?
400                 jobs.values[current_job] : default_job;
401 }
402
403
404 Asset* BatchRenderThread::get_current_asset()
405 {
406         return get_current_job()->asset;
407 }
408
409 char* BatchRenderThread::get_current_edl()
410 {
411         return get_current_job()->edl_path;
412 }
413
414 int BatchRenderThread::test_errmsg(BatchRenderWarnJobs &err_jobs, const char *msg, int *warn)
415 {
416         int count = err_jobs.size();
417         if( !count ) return 0;
418         fprintf(stderr, msg, count);
419         char string[BCTEXTLEN], *sp = string, *ep = sp+sizeof(string)-1;
420         sp += snprintf(sp,ep-sp, msg,count);
421         for( int i=0; i<count; ++i ) {
422                 int no = err_jobs[i].no;
423                 const char *path = err_jobs[i].path;
424                 fprintf(stderr, "%d: %s\n", no, path);
425                 sp += snprintf(sp,ep-sp, "%d: %s\n", no, path);
426         }
427         sp += snprintf(sp,ep-sp, _("press cancel to abandon batch render"));
428         mwindow->show_warning(warn, string);
429         if( mwindow->wait_warning() ) {
430                 gui->button_enable();
431         }
432         return 1;
433 }
434
435 // Test EDL files for existence
436 int BatchRenderThread::test_edl_files()
437 {
438         int ret = 0;
439         const char *path = 0;
440         BatchRenderWarnJobs not_equiv;
441         BatchRenderWarnJobs empty_jobs;
442         BatchRenderWarnJobs no_labels;
443         BatchRenderWarnJobs no_rendering;
444
445         for( int i=0; !ret && i<jobs.size(); ++i ) {
446                 if( !jobs.values[i]->enabled ) continue;
447                 path = jobs[i]->edl_path;
448                 int is_script = *path == '@' ? 1 : 0;
449                 if( is_script ) ++path;
450                 FILE *fp = fopen(path, "r");
451                 if( fp ) {
452                         if( mwindow && !is_script ) {
453                                 char *bfr = 0;  size_t sz = 0;
454                                 struct stat st;
455                                 if( !fstat(fileno(fp), &st) ) {
456                                         sz = st.st_size;
457                                         bfr = new char[sz+1];
458                                         if( fread(bfr, 1, sz+1, fp) != sz )
459                                                 ret = 1;
460                                         else
461                                                 bfr[sz] = 0;
462                                 }
463                                 if( !ret ) {
464                                         EDL *edl = new EDL; edl->create_objects();
465                                         XMLBuffer data(bfr, sz, 0);
466                                         { FileXML file;
467                                         file.set_shared_input(&data);
468                                         edl->load_xml(&file, LOAD_ALL); }
469                                         double pos = edl->equivalent_output(mwindow->edl);
470                                         if( pos >= 0 )
471                                                 not_equiv.add(i+1, path);
472                                         double length = edl->tracks->total_playable_length();
473                                         double start = edl->local_session->get_selectionstart(1);
474                                         if( start >= length )
475                                                 empty_jobs.add(i+1, path);
476                                         if( jobs[i]->labeled && !edl->labels->first)
477                                                 no_labels.add(i+1,path);
478                                         Asset *asset = jobs[i]->asset;
479                                         if( !asset->audio_data && !asset->video_data )
480                                                 no_rendering.add(i+1,path);
481                                         edl->remove_user();
482                                 }
483                                 delete [] bfr;
484                         }
485                         fclose(fp);
486                 }
487                 else
488                         ret = 1;
489         }
490
491         if( ret ) {
492                 char string[BCTEXTLEN];
493                 sprintf(string, _("EDL %s not found.\n"), path);
494                 if( mwindow ) {
495                         ErrorBox error_box(_(PROGRAM_NAME ": Error"),
496                                 mwindow->gui->get_abs_cursor_x(1),
497                                 mwindow->gui->get_abs_cursor_y(1));
498                         error_box.create_objects(string);
499                         error_box.run_window();
500                         gui->button_enable();
501                 }
502                 else {
503                         fprintf(stderr, "%s", string);
504                 }
505                 is_rendering = 0;
506                 ret = 1;
507         }
508
509         if( !ret && warn && mwindow ) {
510                 ret = test_errmsg(not_equiv, _("%d job EDLs do not match session edl\n"), &warn);
511                 if( !warn ) gui->warning->update(0);
512         }
513         if( !ret && mwindow )
514                 ret = test_errmsg(empty_jobs, _("%d job EDLs begin position beyond end of media\n"), 0);
515         if( !ret && mwindow )
516                 ret = test_errmsg(no_rendering, _("%d job EDLs no audio or video in render asset format\n"), 0);
517         if( !ret && mwindow )
518                 ret = test_errmsg(no_labels, _("%d job EDLs Create new file at labels checked, but no labels\n"), 0);
519         if( ret )
520                 is_rendering = 0;
521         return ret;
522 }
523
524 void BatchRenderThread::calculate_dest_paths(ArrayList<char*> *paths,
525         Preferences *preferences)
526 {
527         for( int i = 0; i < jobs.total; i++ ) {
528                 BatchRenderJob *job = jobs.values[i];
529                 if( job->enabled && *job->edl_path != '@' ) {
530                         PackageDispatcher *packages = new PackageDispatcher;
531
532 // Load EDL
533                         TransportCommand *command = new TransportCommand;
534                         FileXML *file = new FileXML;
535                         file->read_from_file(job->edl_path);
536
537 // Use command to calculate range.
538                         command->command = NORMAL_FWD;
539                         command->get_edl()->load_xml(file,
540                                 LOAD_ALL);
541                         command->change_type = CHANGE_ALL;
542                         command->set_playback_range();
543                         command->playback_range_adjust_inout();
544
545 // Create test packages
546                         int result = packages->create_packages(mwindow, command->get_edl(),
547                                 preferences, job->get_strategy(), job->asset,
548                                 command->start_position, command->end_position, 0);
549                         if( !result )
550                                 packages->get_package_paths(paths);
551
552 // Append output paths allocated to total
553
554 // Delete package harness
555                         delete packages;
556                         delete command;
557                         delete file;
558                 }
559         }
560 }
561
562
563 void BatchRenderThread::start_rendering(char *config_path,
564         char *batch_path)
565 {
566         BC_Hash *boot_defaults;
567         Preferences *preferences;
568         Render *render;
569         BC_Signals *signals = new BC_Signals;
570         // XXX the above stuff is leaked,
571 //PRINT_TRACE
572 // Initialize stuff which MWindow does.
573         signals->initialize("/tmp/cinelerra_batch%d.dmp");
574         boot_defaults = 0;
575         MWindow::init_defaults(boot_defaults, config_path);
576         load_defaults(boot_defaults);
577         preferences = new Preferences;
578         preferences->load_defaults(boot_defaults);
579         BC_Signals::set_trap_hook(trap_hook, this);
580         BC_Signals::set_catch_segv(preferences->trap_sigsegv);
581         BC_Signals::set_catch_intr(0);
582         if( preferences->trap_sigsegv ) {
583                 BC_Trace::enable_locks();
584         }
585         else {
586                 BC_Trace::disable_locks();
587         }
588
589         MWindow::init_plugins(0, preferences);
590         char font_path[BCTEXTLEN];
591         strcpy(font_path, preferences->plugin_dir);
592         strcat(font_path, "/" FONT_SEARCHPATH);
593         BC_Resources::init_fontconfig(font_path);
594         BC_WindowBase::get_resources()->vframe_shm = 1;
595
596 //PRINT_TRACE
597         strcpy(this->batch_path, batch_path);
598         load_jobs(batch_path, preferences);
599         save_jobs(batch_path);
600         save_defaults(boot_defaults);
601
602 //PRINT_TRACE
603 // Test EDL files for existence
604         if( test_edl_files() ) return;
605
606 //PRINT_TRACE
607
608 // Predict all destination paths
609         ArrayList<char*> paths;
610         paths.set_array_delete();
611         calculate_dest_paths(&paths, preferences);
612
613 //PRINT_TRACE
614         int result = ConfirmSave::test_files(0, &paths);
615         paths.remove_all_objects();
616 // Abort on any existing file because it's so hard to set this up.
617         if( result ) return;
618
619 //PRINT_TRACE
620         render = new Render(0);
621 //PRINT_TRACE
622         render->start_batches(&jobs, boot_defaults, preferences);
623 //PRINT_TRACE
624 }
625
626 void BatchRenderThread::start_rendering()
627 {
628         if( is_rendering ) return;
629         is_rendering = 1;
630
631         save_jobs(batch_path);
632         save_defaults(mwindow->defaults);
633         gui->button_disable();
634
635 // Test EDL files for existence
636         if( test_edl_files() ) return;
637
638 // Predict all destination paths
639         ArrayList<char*> paths;
640         calculate_dest_paths(&paths,
641                 mwindow->preferences);
642
643 // Test destination files for overwrite
644         int result = ConfirmSave::test_files(mwindow, &paths);
645         paths.remove_all_objects();
646
647 // User cancelled
648         if( result ) {
649                 is_rendering = 0;
650                 gui->button_enable();
651                 return;
652         }
653
654         mwindow->render->start_batches(&jobs);
655 }
656
657 void BatchRenderThread::stop_rendering()
658 {
659         if( !is_rendering ) return;
660         mwindow->render->stop_operation();
661         is_rendering = 0;
662 }
663
664 void BatchRenderThread::update_active(int number)
665 {
666         gui->lock_window("BatchRenderThread::update_active");
667         if( number >= 0 ) {
668                 current_job = number;
669                 rendering_job = number;
670         }
671         else {
672                 rendering_job = -1;
673                 is_rendering = 0;
674         }
675         gui->create_list(1);
676         gui->unlock_window();
677 }
678
679 void BatchRenderThread::update_done(int number,
680         int create_list,
681         double elapsed_time)
682 {
683         gui->lock_window("BatchRenderThread::update_done");
684         if( number < 0 ) {
685                 gui->button_enable();
686         }
687         else {
688                 jobs.values[number]->enabled = 0;
689                 jobs.values[number]->elapsed = elapsed_time;
690                 if( create_list ) gui->create_list(1);
691         }
692         gui->unlock_window();
693 }
694
695 void BatchRenderThread::move_batch(int src, int dst)
696 {
697         BatchRenderJob *src_job = jobs.values[src];
698         if( dst < 0 ) dst = jobs.total - 1;
699
700         if( dst != src ) {
701                 for( int i = src; i < jobs.total - 1; i++ )
702                         jobs.values[i] = jobs.values[i + 1];
703 //              if( dst > src ) dst--;
704                 for( int i = jobs.total - 1; i > dst; i-- )
705                         jobs.values[i] = jobs.values[i - 1];
706                 jobs.values[dst] = src_job;
707                 gui->create_list(1);
708         }
709 }
710
711 void BatchRenderThread::trap_hook(FILE *fp, void *vp)
712 {
713         MWindow *mwindow = ((BatchRenderThread *)vp)->mwindow;
714         fprintf(fp, "\nEDL:\n");
715         mwindow->dump_edl(fp);
716         fprintf(fp, "\nUNDO:\n");
717         mwindow->dump_undo(fp);
718         fprintf(fp, "\nEXE:\n");
719         mwindow->dump_exe(fp);
720 }
721
722
723
724
725
726 BatchRenderGUI::BatchRenderGUI(MWindow *mwindow,
727         BatchRenderThread *thread, int x, int y, int w, int h)
728  : BC_Window(_(PROGRAM_NAME ": Batch Render"),
729         x, y, w, h, xS(730), yS(400), 1, 0, 1)
730 {
731         this->mwindow = mwindow;
732         this->thread = thread;
733         use_renderfarm = 0;
734 }
735
736 BatchRenderGUI::~BatchRenderGUI()
737 {
738         lock_window("BatchRenderGUI::~BatchRenderGUI");
739         loadlist_batch->stop();
740         savelist_batch->stop();
741         delete format_tools;
742         unlock_window();
743 }
744
745
746 void BatchRenderGUI::create_objects()
747 {
748         int xs10 = xS(10), xs30 = xS(30), xs40 = xS(40);
749         int ys5 = yS(5), ys10 = yS(10), ys15 = yS(15);
750         lock_window("BatchRenderGUI::create_objects");
751         mwindow->theme->get_batchrender_sizes(this, get_w(), get_h());
752         create_list(0);
753
754         int x = mwindow->theme->batchrender_x1;
755         int y = ys5;
756         int x1 = x, x2 = get_w()/2 + xs30; // mwindow->theme->batchrender_x2;
757         int y1 = ys5, y2 = ys5;
758
759 // output file
760         add_subwindow(output_path_title = new BC_Title(x1, y1, _("Output path:")));
761         y1 += output_path_title->get_h() + mwindow->theme->widget_border;
762
763         format_tools = new BatchFormat(mwindow, this, thread->get_current_asset());
764         format_tools->set_w(x2 - xs40);
765         BatchRenderJob *current_job = thread->get_current_job();
766         format_tools->create_objects(x1, y1, 1, 1, 1, 1, 0, 1, 0, 0,
767                         thread->do_labeled ? &current_job->labeled : 0, 0);
768         if( thread->do_labeled < 0 )
769                 format_tools->labeled_files->disable();
770         if( thread->do_farmed ) {
771                 use_renderfarm = new BatchRenderUseFarm(thread, x1, y1,
772                         &current_job->farmed);
773                 add_subwindow(use_renderfarm);
774                 y1 += use_renderfarm->get_h() + ys10;
775                 if( thread->do_farmed < 0 )
776                         use_renderfarm->disable();
777         }
778
779 // input EDL
780         add_subwindow(edl_path_title = new BC_Title(x2, y2, _("EDL Path:")));
781         y2 += edl_path_title->get_h() + mwindow->theme->widget_border;
782
783         x = x2;  y = y2;
784         add_subwindow(edl_path_text = new BatchRenderEDLPath( thread,
785                 x, y, get_w()-x - xs40, thread->get_current_edl()));
786         x =  x2 + edl_path_text->get_w();
787         add_subwindow(edl_path_browse = new BrowseButton(
788                 mwindow->theme, this, edl_path_text, x, y, thread->get_current_edl(),
789                 _("Input EDL"), _("Select an EDL to load:"), 0));
790         y2 = y + edl_path_browse->get_h() + mwindow->theme->widget_border;
791
792         x = x2;  y = y2;
793         add_subwindow(update_selected_edl = new BatchRenderUpdateEDL(thread, x, y));
794         y += update_selected_edl->get_h() + mwindow->theme->widget_border;
795         add_subwindow(use_current_edl = new BatchRenderCurrentEDL(thread, x, y));
796         y += use_current_edl->get_h() + mwindow->theme->widget_border;
797         if( !mwindow->edl || !mwindow->edl->path[0] ) use_current_edl->disable();
798         add_subwindow(new_batch = new BatchRenderNew(thread, x, y));
799         x += new_batch->get_w() + mwindow->theme->widget_border;
800         add_subwindow(delete_batch = new BatchRenderDelete(thread, x, y));
801         x = x2;  y += delete_batch->get_h() + mwindow->theme->widget_border;
802         add_subwindow(savelist_batch = new BatchRenderSaveList(thread, x, y));
803         x += savelist_batch->get_w() + mwindow->theme->widget_border;
804         add_subwindow(loadlist_batch = new BatchRenderLoadList(thread, x, y));
805         y += loadlist_batch->get_h() + mwindow->theme->widget_border;
806         add_subwindow(warning = new BatchRenderWarning(thread, x2, y));
807         y2 = y + warning->get_h() + mwindow->theme->widget_border;
808         if( y2 > y1 ) y1 = y2;
809         x = mwindow->theme->batchrender_x1, y = y1;
810
811         add_subwindow(list_title = new BC_Title(x, y, _("Batches to render:")));
812         x1 = x + list_title->get_w() + mwindow->theme->widget_border;;
813         add_subwindow(batch_path = new BC_Title(x1, y, thread->batch_path, MEDIUMFONT));
814         y += list_title->get_h() + mwindow->theme->widget_border;
815         y1 = get_h();
816         y1 -= ys15 + BC_GenericButton::calculate_h() + mwindow->theme->widget_border;
817         add_subwindow(batch_list = new BatchRenderList(thread, x, y,
818                 get_w() - x - xs10, y1 - y));
819         y += batch_list->get_h() + mwindow->theme->widget_border;
820
821         add_subwindow(start_button = new BatchRenderStart(thread, x, y));
822         x = get_w() / 2 - BC_GenericButton::calculate_w(this, _("Stop")) / 2;
823         add_subwindow(stop_button = new BatchRenderStop(thread, x, y));
824         x = get_w() - BC_GenericButton::calculate_w(this, _("Close")) - xs10;
825         add_subwindow(cancel_button = new BatchRenderCancel(thread, x, y));
826
827         show_window(1);
828         unlock_window();
829 }
830
831 void BatchRenderGUI::button_disable()
832 {
833         new_batch->disable();
834         delete_batch->disable();
835         use_current_edl->disable();
836         update_selected_edl->disable();
837 }
838
839 void BatchRenderGUI::button_enable()
840 {
841         new_batch->enable();
842         delete_batch->enable();
843         if( mwindow->edl && mwindow->edl->path[0] )
844                 use_current_edl->enable();
845         update_selected_edl->enable();
846 }
847
848 int BatchRenderGUI::resize_event(int w, int h)
849 {
850         int xs10 = xS(10), xs40 = xS(40);
851         int ys5 = yS(5), ys15 = yS(15);
852         mwindow->session->batchrender_w = w;
853         mwindow->session->batchrender_h = h;
854         mwindow->theme->get_batchrender_sizes(this, w, h);
855
856         int x = mwindow->theme->batchrender_x1;
857         int y = ys5;
858         int x1 = x, x2 = get_w()/2 + xs10; // mwindow->theme->batchrender_x2;
859         int y1 = ys5, y2 = ys5;
860
861 // output file
862         output_path_title->reposition_window(x1, y1);
863         y1 += output_path_title->get_h() + mwindow->theme->widget_border;
864         format_tools->reposition_window(x1, y1);
865         if( thread->do_farmed )
866                 use_renderfarm->reposition_window(x1, y1);
867 // input EDL
868         x = x2, y = y2;
869         edl_path_title->reposition_window(x, y);
870         y += edl_path_title->get_h() + mwindow->theme->widget_border;
871         edl_path_text->reposition_window(x, y, w - x - xs40);
872         x += edl_path_text->get_w();
873         edl_path_browse->reposition_window(x, y);
874         y2 = y + edl_path_browse->get_h() + mwindow->theme->widget_border;
875
876         x = x2;  y = y2;
877         update_selected_edl->reposition_window(x, y);
878         y += update_selected_edl->get_h() + mwindow->theme->widget_border;
879         use_current_edl->reposition_window(x, y);
880         y += use_current_edl->get_h() + mwindow->theme->widget_border;
881         new_batch->reposition_window(x, y);
882         x += new_batch->get_w() + mwindow->theme->widget_border;
883         delete_batch->reposition_window(x, y);
884
885         x = x2;  y += delete_batch->get_h() + mwindow->theme->widget_border;
886         savelist_batch->reposition_window(x, y);
887         x += savelist_batch->get_w() + mwindow->theme->widget_border;
888         loadlist_batch->reposition_window(x, y);
889         y += loadlist_batch->get_h() + mwindow->theme->widget_border;
890         warning->reposition_window(x2, y);
891
892         y1 = ys15 + BC_GenericButton::calculate_h() + mwindow->theme->widget_border;
893         y2 = get_h() - y1 - batch_list->get_h();
894         y2 -= list_title->get_h() + mwindow->theme->widget_border;
895
896         x = mwindow->theme->batchrender_x1;  y = y2;
897         list_title->reposition_window(x, y);
898         y += list_title->get_h() + mwindow->theme->widget_border;
899         batch_list->reposition_window(x, y, w - x - xs10, h - y - y1);
900         y += batch_list->get_h() + mwindow->theme->widget_border;
901
902         start_button->reposition_window(x, y);
903         x = w / 2 - stop_button->get_w() / 2;
904         stop_button->reposition_window(x, y);
905         x = w - cancel_button->get_w() - xs10;
906         cancel_button->reposition_window(x, y);
907         return 1;
908 }
909
910 int BatchRenderGUI::translation_event()
911 {
912         mwindow->session->batchrender_x = get_x();
913         mwindow->session->batchrender_y = get_y();
914         return 1;
915 }
916
917 int BatchRenderGUI::close_event()
918 {
919 // Stop batch rendering
920         unlock_window();
921         thread->stop_rendering();
922         lock_window("BatchRenderGUI::close_event");
923         set_done(1);
924         return 1;
925 }
926
927 void BatchRenderGUI::create_list(int update_widget)
928 {
929         for( int i = 0; i < BATCHRENDER_COLUMNS; i++ ) {
930                 list_items[i].remove_all_objects();
931         }
932
933         const char **column_titles = BatchRenderThread::column_titles;
934         list_columns = 0;
935         list_titles[list_columns] = _(column_titles[ENABLED_COL]);
936         list_width[list_columns++] = thread->list_width[ENABLED_COL];
937         if( thread->do_labeled > 0 ) {
938                 list_titles[list_columns] = _(column_titles[LABELED_COL]);
939                 list_width[list_columns++] = thread->list_width[LABELED_COL];
940         }
941         if( thread->do_farmed > 0 ) {
942                 list_titles[list_columns] = _(column_titles[FARMED_COL]);
943                 list_width[list_columns++] = thread->list_width[FARMED_COL];
944         }
945         list_titles[list_columns] = _(column_titles[OUTPUT_COL]);
946         list_width[list_columns++] = thread->list_width[OUTPUT_COL];
947         list_titles[list_columns] = _(column_titles[EDL_COL]);
948         list_width[list_columns++] = thread->list_width[EDL_COL];
949         list_titles[list_columns] = _(column_titles[ELAPSED_COL]);
950         list_width[list_columns++] = thread->list_width[ELAPSED_COL];
951
952         for( int i = 0; i < thread->jobs.total; i++ ) {
953                 BatchRenderJob *job = thread->jobs.values[i];
954                 char string[BCTEXTLEN];
955                 BC_ListBoxItem *enabled = new BC_ListBoxItem(job->enabled ? "X" : " ");
956                 BC_ListBoxItem *labeled = thread->do_labeled > 0 ?
957                         new BC_ListBoxItem(job->labeled ? "X" : " ") : 0;
958                 BC_ListBoxItem *farmed  = thread->do_farmed > 0 ?
959                         new BC_ListBoxItem(job->farmed  ? "X" : " ") : 0;
960                 BC_ListBoxItem *out_path = new BC_ListBoxItem(job->asset->path);
961                 BC_ListBoxItem *edl_path = new BC_ListBoxItem(job->edl_path);
962                 BC_ListBoxItem *elapsed = new BC_ListBoxItem(!job->elapsed ? _("Unknown") :
963                         Units::totext(string, job->elapsed, TIME_HMS2));
964                 int col = 0;
965                 list_items[col++].append(enabled);
966                 if( labeled ) list_items[col++].append(labeled);
967                 if( farmed ) list_items[col++].append(farmed);
968                 list_items[col++].append(out_path);
969                 list_items[col++].append(edl_path);
970                 list_items[col].append(elapsed);
971                 if( i == thread->current_job ) {
972                         enabled->set_selected(1);
973                         if( labeled ) labeled->set_selected(1);
974                         if( farmed ) farmed->set_selected(1);
975                         out_path->set_selected(1);
976                         edl_path->set_selected(1);
977                         elapsed->set_selected(1);
978                 }
979                 if( i == thread->rendering_job ) {
980                         enabled->set_color(RED);
981                         if( labeled ) labeled->set_color(RED);
982                         if( farmed ) farmed->set_color(RED);
983                         out_path->set_color(RED);
984                         edl_path->set_color(RED);
985                         elapsed->set_color(RED);
986                 }
987         }
988
989         if( update_widget ) {
990                 batch_list->update(list_items, list_titles, list_width, list_columns,
991                         batch_list->get_xposition(), batch_list->get_yposition(),
992                         batch_list->get_highlighted_item(), 1, 1);
993         }
994 }
995
996 void BatchRenderGUI::change_job()
997 {
998         BatchRenderJob *job = thread->get_current_job();
999         format_tools->update(job->asset, thread->do_labeled ? &job->labeled : 0);
1000         if( thread->do_farmed ) use_renderfarm->update(&job->farmed);
1001         edl_path_text->update(job->edl_path);
1002 }
1003
1004
1005 BatchFormat::BatchFormat(MWindow *mwindow, BatchRenderGUI *gui, Asset *asset)
1006  : FormatTools(mwindow, gui, asset)
1007 {
1008         this->gui = gui;
1009         this->mwindow = mwindow;
1010 }
1011
1012 BatchFormat::~BatchFormat()
1013 {
1014 }
1015
1016
1017 int BatchFormat::handle_event()
1018 {
1019         gui->create_list(1);
1020         return 1;
1021 }
1022
1023 BatchRenderEDLPath::BatchRenderEDLPath(BatchRenderThread *thread,
1024         int x, int y, int w, char *text)
1025  : BC_TextBox(x, y, w, 1, text)
1026 {
1027         this->thread = thread;
1028 }
1029
1030
1031 int BatchRenderEDLPath::handle_event()
1032 {
1033         calculate_suggestions();
1034         strcpy(thread->get_current_edl(), get_text());
1035         thread->gui->create_list(1);
1036         return 1;
1037 }
1038
1039 BatchRenderNew::BatchRenderNew(BatchRenderThread *thread,
1040         int x,
1041         int y)
1042  : BC_GenericButton(x, y, _("New"))
1043 {
1044         this->thread = thread;
1045 }
1046
1047 int BatchRenderNew::handle_event()
1048 {
1049         thread->new_job();
1050         return 1;
1051 }
1052
1053 BatchRenderDelete::BatchRenderDelete(BatchRenderThread *thread, int x, int y)
1054  : BC_GenericButton(x, y, _("Delete"))
1055 {
1056         this->thread = thread;
1057 }
1058
1059 int BatchRenderDelete::handle_event()
1060 {
1061         thread->delete_job();
1062         return 1;
1063 }
1064
1065
1066
1067 BatchRenderSaveList::BatchRenderSaveList(BatchRenderThread *thread, int x, int y)
1068  : BC_GenericButton(x, y, _("Save Jobs"))
1069 {
1070         this->thread = thread;
1071         set_tooltip(_("Save a Batch Render List"));
1072         gui = 0;
1073         startup_lock = new Mutex("BatchRenderSaveList::startup_lock");
1074 }
1075
1076 BatchRenderSaveList::~BatchRenderSaveList()
1077 {
1078         stop();
1079         delete startup_lock;
1080 }
1081
1082 void BatchRenderSaveList::stop()
1083 {
1084         startup_lock->lock("BatchRenderSaveList::~BrowseButton");
1085         if( gui ) gui->set_done(1);
1086         startup_lock->unlock();
1087         Thread::join();
1088 }
1089
1090 int BatchRenderSaveList::handle_event()
1091 {
1092         if( Thread::running() ) {
1093                 if( gui ) {
1094                         gui->lock_window();
1095                         gui->raise_window();
1096                         gui->unlock_window();
1097                 }
1098                 return 1;
1099         }
1100         startup_lock->lock("BatchRenderSaveList::handle_event 1");
1101         Thread::start();
1102         startup_lock->lock("BatchRenderSaveList::handle_event 2");
1103         startup_lock->unlock();
1104         return 1;
1105 }
1106
1107 void BatchRenderSaveList::run()
1108 {
1109         char default_path[BCTEXTLEN];
1110         sprintf(default_path, "~");
1111         thread->mwindow->defaults->get("DEFAULT_BATCHLOADPATH", default_path);
1112         BC_FileBox filewindow(xS(100), yS(100), default_path,
1113                         _("Save Batch Render List"),
1114                         _("Enter a Batch Render filename to save as:"),
1115                         0, 0, 0, 0);
1116         gui = &filewindow;
1117
1118         startup_lock->unlock();
1119         filewindow.create_objects();
1120
1121         int result2 = filewindow.run_window();
1122         if( !result2 ) {
1123                 strcpy(thread->batch_path, filewindow.get_submitted_path());
1124                 thread->gui->lock_window("BatchRenderSaveList::run");
1125                 thread->gui->batch_path->update(thread->batch_path);
1126                 thread->gui->unlock_window();
1127                 thread->mwindow->defaults->update("DEFAULT_BATCHLOADPATH", thread->batch_path);
1128                 thread->save_jobs(thread->batch_path);
1129         }
1130
1131         startup_lock->lock("BatchRenderLoadList::run");
1132         gui = 0;
1133         startup_lock->unlock();
1134 }
1135
1136 int BatchRenderSaveList::keypress_event() {
1137         if( get_keypress() == 's' ||
1138             get_keypress() == 'S' ) return handle_event();
1139         return 0;
1140 }
1141
1142
1143 BatchRenderLoadList::BatchRenderLoadList(BatchRenderThread *thread,
1144         int x,
1145         int y)
1146   : BC_GenericButton(x, y, _("Load Jobs")),
1147     Thread()
1148 {
1149         this->thread = thread;
1150         set_tooltip(_("Load a previously saved Batch Render List"));
1151         gui = 0;
1152         startup_lock = new Mutex("BatchRenderLoadList::startup_lock");
1153 }
1154
1155 BatchRenderLoadList::~BatchRenderLoadList()
1156 {
1157         stop();
1158         delete startup_lock;
1159 }
1160
1161 void BatchRenderLoadList::stop()
1162 {
1163         startup_lock->lock("BatchRenderLoadList::~BrowseButton");
1164         if( gui ) gui->set_done(1);
1165         startup_lock->unlock();
1166         Thread::join();
1167 }
1168
1169 int BatchRenderLoadList::handle_event()
1170 {
1171         if( Thread::running() ) {
1172                 if( gui ) {
1173                         gui->lock_window();
1174                         gui->raise_window();
1175                         gui->unlock_window();
1176                 }
1177                 return 1;
1178         }
1179         startup_lock->lock("BatchRenderLoadList::handle_event 1");
1180         Thread::start();
1181         startup_lock->lock("BatchRenderLoadList::handle_event 2");
1182         startup_lock->unlock();
1183         return 1;
1184 }
1185
1186 void BatchRenderLoadList::run()
1187 {
1188         char default_path[BCTEXTLEN];
1189         sprintf(default_path, "~");
1190         thread->mwindow->defaults->get("DEFAULT_BATCHLOADPATH", default_path);
1191         BC_FileBox filewindow(xS(100), yS(100), default_path, _("Load Batch Render List"),
1192                         _("Enter a Batch Render filename to load from:"),
1193                         0, 0, 0, 0);
1194         gui = &filewindow;
1195
1196         startup_lock->unlock();
1197         filewindow.create_objects();
1198
1199         int result2 = filewindow.run_window();
1200         if( !result2 ) {
1201                 thread->gui->lock_window("BatchRenderLoadList::run");
1202                 strcpy(thread->batch_path, filewindow.get_submitted_path());
1203                 thread->gui->batch_path->update(thread->batch_path);
1204                 thread->mwindow->defaults->update("DEFAULT_BATCHLOADPATH", thread->batch_path);
1205                 thread->load_jobs(thread->batch_path, thread->mwindow->preferences);
1206                 thread->gui->create_list(1);
1207                 thread->current_job = 0;
1208                 thread->gui->change_job();
1209                 thread->gui->unlock_window();
1210         }
1211
1212         startup_lock->lock("BatchRenderLoadList::run");
1213         gui = 0;
1214         startup_lock->unlock();
1215 }
1216
1217 int BatchRenderLoadList::keypress_event() {
1218         if( get_keypress() == 'o' ||
1219             get_keypress() == 'O' ) return handle_event();
1220         return 0;
1221 }
1222
1223 BatchRenderCurrentEDL::BatchRenderCurrentEDL(BatchRenderThread *thread,
1224         int x,
1225         int y)
1226  : BC_GenericButton(x, y, _("Use Current EDL"))
1227 {
1228         this->thread = thread;
1229 }
1230
1231 int BatchRenderCurrentEDL::handle_event()
1232 {
1233         thread->use_current_edl();
1234         return 1;
1235 }
1236
1237 BatchRenderUpdateEDL::BatchRenderUpdateEDL(BatchRenderThread *thread,
1238         int x,
1239         int y)
1240  : BC_GenericButton(x, y, _("Save to EDL Path"))
1241 {
1242         this->thread = thread;
1243 }
1244
1245 int BatchRenderUpdateEDL::handle_event()
1246 {
1247         thread->update_selected_edl();
1248         return 1;
1249 }
1250
1251
1252 BatchRenderList::BatchRenderList(BatchRenderThread *thread,
1253         int x, int y, int w, int h)
1254  : BC_ListBox(x, y, w, h, LISTBOX_TEXT, thread->gui->list_items,
1255         thread->gui->list_titles, thread->gui->list_width, thread->gui->list_columns,
1256         0, 0, LISTBOX_SINGLE, ICON_LEFT, 1)
1257 {
1258         this->thread = thread;
1259         dragging_item = 0;
1260         set_process_drag(0);
1261 }
1262
1263 int BatchRenderList::handle_event()
1264 {
1265         return 1;
1266 }
1267
1268 int BatchRenderList::selection_changed()
1269 {
1270         thread->current_job = get_selection_number(0, 0);
1271         thread->gui->change_job();
1272         int cursor_x = get_cursor_x();
1273         BatchRenderJob *job = thread->get_current_job();
1274         int col_x = 0, changed = 1;
1275         if( cursor_x < (col_x += thread->list_width[ENABLED_COL]) )
1276                 job->enabled = !job->enabled;
1277         else if( thread->do_labeled > 0 &&
1278                  cursor_x < (col_x += thread->list_width[LABELED_COL]) )
1279                 job->labeled = job->edl_path[0] != '@' ? !job->labeled : 0;
1280         else if( thread->do_farmed > 0 &&
1281                  cursor_x < (col_x += thread->list_width[FARMED_COL]) )
1282                 job->farmed = job->edl_path[0] != '@' ? !job->farmed : 0;
1283         else
1284                 changed = 0;
1285         if( changed ) {
1286                 thread->gui->create_list(1);
1287                 thread->gui->change_job();
1288         }
1289         return 1;
1290 }
1291
1292 int BatchRenderList::column_resize_event()
1293 {
1294         int col = 0;
1295         thread->list_width[ENABLED_COL] = get_column_width(col++);
1296         if( thread->do_labeled > 0 )
1297                 thread->list_width[LABELED_COL] = get_column_width(col++);
1298         if( thread->do_farmed > 0 )
1299                 thread->list_width[FARMED_COL] = get_column_width(col++);
1300         thread->list_width[OUTPUT_COL] = get_column_width(col++);
1301         thread->list_width[EDL_COL] = get_column_width(col++);
1302         thread->list_width[ELAPSED_COL] = get_column_width(col);
1303         return 1;
1304 }
1305
1306 int BatchRenderList::drag_start_event()
1307 {
1308         if( BC_ListBox::drag_start_event() ) {
1309                 dragging_item = 1;
1310                 return 1;
1311         }
1312
1313         return 0;
1314 }
1315
1316 int BatchRenderList::drag_motion_event()
1317 {
1318         if( BC_ListBox::drag_motion_event() ) {
1319                 return 1;
1320         }
1321         return 0;
1322 }
1323
1324 int BatchRenderList::drag_stop_event()
1325 {
1326         if( dragging_item ) {
1327                 int src = get_selection_number(0, 0);
1328                 int dst = get_highlighted_item();
1329                 if( src != dst ) {
1330                         thread->move_batch(src, dst);
1331                 }
1332                 BC_ListBox::drag_stop_event();
1333                 dragging_item = 0;
1334         }
1335         return 0;
1336 }
1337
1338
1339
1340 BatchRenderStart::BatchRenderStart(BatchRenderThread *thread, int x, int y)
1341  : BC_GenericButton(x, y, _("Start"))
1342 {
1343         this->thread = thread;
1344 }
1345
1346 int BatchRenderStart::handle_event()
1347 {
1348         thread->start_rendering();
1349         return 1;
1350 }
1351
1352 BatchRenderStop::BatchRenderStop(BatchRenderThread *thread, int x, int y)
1353  : BC_GenericButton(x, y, _("Stop"))
1354 {
1355         this->thread = thread;
1356 }
1357
1358 int BatchRenderStop::handle_event()
1359 {
1360         unlock_window();
1361         thread->stop_rendering();
1362         lock_window("BatchRenderStop::handle_event");
1363         return 1;
1364 }
1365
1366
1367 BatchRenderWarning::BatchRenderWarning(BatchRenderThread *thread, int x, int y)
1368  : BC_CheckBox(x, y, thread->warn, _("warn if jobs/session mismatched"))
1369 {
1370         this->thread = thread;
1371 }
1372
1373 int BatchRenderWarning::handle_event()
1374 {
1375         thread->warn = get_value();
1376         return 1;
1377 }
1378
1379 BatchRenderCancel::BatchRenderCancel(BatchRenderThread *thread, int x, int y)
1380  : BC_GenericButton(x, y, _("Close"))
1381 {
1382         this->thread = thread;
1383 }
1384
1385 int BatchRenderCancel::handle_event()
1386 {
1387         unlock_window();
1388         thread->stop_rendering();
1389         lock_window("BatchRenderCancel::handle_event");
1390         thread->gui->set_done(1);
1391         return 1;
1392 }
1393
1394 int BatchRenderCancel::keypress_event()
1395 {
1396         if( get_keypress() == ESC ) {
1397                 unlock_window();
1398                 thread->stop_rendering();
1399                 lock_window("BatchRenderCancel::keypress_event");
1400                 thread->gui->set_done(1);
1401                 return 1;
1402         }
1403         return 0;
1404 }
1405
1406 BatchRenderUseFarm::BatchRenderUseFarm(BatchRenderThread *thread, int x, int y, int *output)
1407  : BC_CheckBox(x, y, *output, _("Use render farm"))
1408 {
1409         this->thread = thread;
1410         this->output = output;
1411 }
1412
1413 int BatchRenderUseFarm::handle_event()
1414 {
1415         *output = get_value();
1416         thread->gui->create_list(1);
1417         return 1;
1418 }
1419
1420 void BatchRenderUseFarm::update(int *output)
1421 {
1422         this->output = output;
1423         BC_CheckBox::update(*output);
1424 }
1425