6 #include "filesystem.h"
11 #include "localsession.h"
14 #include "mainsession.h"
16 #include "mwindowgui.h"
23 Load::Load(MWindow *mwindow, MainMenu *mainmenu)
24 : BC_MenuItem(_("Load files..."), "o", 'o')
26 this->mwindow = mwindow;
27 this->mainmenu = mainmenu;
35 int Load::create_objects()
37 thread = new LoadFileThread(mwindow, this);
41 int Load::handle_event()
43 //printf("Load::handle_event 1\n");
44 if(!thread->running())
46 //printf("Load::handle_event 2\n");
57 LoadFileThread::LoadFileThread(MWindow *mwindow, Load *load)
60 this->mwindow = mwindow;
64 LoadFileThread::~LoadFileThread()
68 void LoadFileThread::run()
71 ArrayList<BC_ListBoxItem*> *dirlist;
73 ArrayList<char*> path_list;
74 path_list.set_array_delete();
75 char default_path[BCTEXTLEN];
78 int overwrite_reel = 0;
80 sprintf(default_path, "~");
81 mwindow->defaults->get("DEFAULT_LOADPATH", default_path);
82 load_mode = mwindow->defaults->get("LOAD_MODE", LOAD_REPLACE);
85 LoadFileWindow window(mwindow, this, default_path);
86 window.create_objects();
87 result = window.run_window();
89 if ((!result) && (load_mode == LOAD_REPLACE)) {
90 mwindow->set_filename(window.get_path(0));
93 // Collect all selected files
96 char *in_path, *out_path;
99 while((in_path = window.get_path(i)))
102 for(j = 0; j < path_list.total; j++)
104 if(!strcmp(in_path, path_list.values[j])) break;
107 if(j == path_list.total)
109 path_list.append(out_path = new char[strlen(in_path) + 1]);
110 strcpy(out_path, in_path);
116 mwindow->defaults->update("DEFAULT_LOADPATH",
117 window.get_submitted_path());
118 mwindow->defaults->update("LOAD_MODE",
123 if(path_list.total == 0 || result == 1)
129 // ReelWindow rwindow(mwindow);
130 // rwindow.create_objects();
131 // result = rwindow.run_window();
138 // reel_name = rwindow.reel_name->get_text();
139 // reel_number = atol(rwindow.reel_number->get_text());
140 // overwrite_reel = rwindow.overwrite_reel;
147 mwindow->interrupt_indexes();
148 mwindow->gui->lock_window("LoadFileThread::run");
149 result = mwindow->load_filenames(&path_list, load_mode, 0, reel_name, reel_number, overwrite_reel);
150 mwindow->gui->mainmenu->add_load(path_list.values[0]);
151 mwindow->gui->unlock_window();
152 path_list.remove_all_objects();
155 mwindow->save_backup();
157 mwindow->restart_brender();
158 // mwindow->undo->update_undo(_("load"), LOAD_ALL);
160 if(load_mode == LOAD_REPLACE || load_mode == LOAD_REPLACE_CONCATENATE)
161 mwindow->session->changes_made = 0;
163 mwindow->session->changes_made = 1;
175 LoadFileWindow::LoadFileWindow(MWindow *mwindow,
176 LoadFileThread *thread,
177 char *init_directory)
178 : BC_FileBox(mwindow->gui->get_abs_cursor_x(1),
179 mwindow->gui->get_abs_cursor_y(1) - BC_WindowBase::get_resources()->filebox_h / 2,
181 PROGRAM_NAME ": Load",
182 _("Select files to load:"),
186 mwindow->theme->loadfile_pad)
188 this->thread = thread;
189 this->mwindow = mwindow;
192 LoadFileWindow::~LoadFileWindow()
197 int LoadFileWindow::create_objects()
199 BC_FileBox::create_objects();
201 int x = get_w() / 2 - 200;
202 int y = get_cancel_button()->get_y() - 50;
203 loadmode = new LoadMode(mwindow, this, x, y, &thread->load_mode, 0);
204 loadmode->create_objects();
209 int LoadFileWindow::resize_event(int w, int h)
212 int y = get_cancel_button()->get_y() - 50;
213 draw_background(0, 0, w, h);
215 loadmode->reposition_window(x, y);
217 return BC_FileBox::resize_event(w, h);
226 NewTimeline::NewTimeline(int x, int y, LoadFileWindow *window)
229 window->thread->load_mode == LOAD_REPLACE,
230 _("Replace current project."))
232 this->window = window;
234 int NewTimeline::handle_event()
236 window->newtracks->set_value(0);
237 window->newconcatenate->set_value(0);
238 window->concatenate->set_value(0);
239 window->resourcesonly->set_value(0);
243 NewConcatenate::NewConcatenate(int x, int y, LoadFileWindow *window)
246 window->thread->load_mode == LOAD_REPLACE_CONCATENATE,
247 _("Replace current project and concatenate tracks."))
249 this->window = window;
251 int NewConcatenate::handle_event()
253 window->newtimeline->set_value(0);
254 window->newtracks->set_value(0);
255 window->concatenate->set_value(0);
256 window->resourcesonly->set_value(0);
260 AppendNewTracks::AppendNewTracks(int x, int y, LoadFileWindow *window)
263 window->thread->load_mode == LOAD_NEW_TRACKS,
264 _("Append in new tracks."))
266 this->window = window;
268 int AppendNewTracks::handle_event()
270 window->newtimeline->set_value(0);
271 window->newconcatenate->set_value(0);
272 window->concatenate->set_value(0);
273 window->resourcesonly->set_value(0);
277 EndofTracks::EndofTracks(int x, int y, LoadFileWindow *window)
280 window->thread->load_mode == LOAD_CONCATENATE,
281 _("Concatenate to existing tracks."))
283 this->window = window;
285 int EndofTracks::handle_event()
287 window->newtimeline->set_value(0);
288 window->newconcatenate->set_value(0);
289 window->newtracks->set_value(0);
290 window->resourcesonly->set_value(0);
294 ResourcesOnly::ResourcesOnly(int x, int y, LoadFileWindow *window)
297 window->thread->load_mode == LOAD_RESOURCESONLY,
298 _("Create new resources only."))
300 this->window = window;
302 int ResourcesOnly::handle_event()
305 window->newtimeline->set_value(0);
306 window->newconcatenate->set_value(0);
307 window->newtracks->set_value(0);
308 window->concatenate->set_value(0);
318 LocateFileWindow::LocateFileWindow(MWindow *mwindow,
319 char *init_directory,
321 : BC_FileBox(mwindow->gui->get_abs_cursor_x(1),
322 mwindow->gui->get_abs_cursor_y(1),
324 PROGRAM_NAME ": Locate file",
327 this->mwindow = mwindow;
330 LocateFileWindow::~LocateFileWindow()
340 LoadPrevious::LoadPrevious(MWindow *mwindow)
341 : BC_MenuItem(""), Thread()
343 this->mwindow = mwindow;
344 this->loadfile = loadfile;
347 int LoadPrevious::handle_event()
349 ArrayList<char*> path_list;
350 path_list.set_array_delete();
352 int load_mode = mwindow->defaults->get("LOAD_MODE", LOAD_REPLACE);
355 path_list.append(out_path = new char[strlen(path) + 1]);
356 strcpy(out_path, path);
357 mwindow->load_filenames(&path_list, LOAD_REPLACE);
358 mwindow->gui->mainmenu->add_load(path_list.values[0]);
359 path_list.remove_all_objects();
362 mwindow->defaults->update("LOAD_MODE", load_mode);
363 mwindow->undo->update_undo(_("load previous"), LOAD_ALL);
364 mwindow->save_backup();
365 mwindow->session->changes_made = 0;
375 void LoadPrevious::run()
377 // loadfile->mwindow->load(path, loadfile->append);
380 int LoadPrevious::set_path(char *path)
382 strcpy(this->path, path);
392 LoadBackup::LoadBackup(MWindow *mwindow)
393 : BC_MenuItem(_("Load backup"))
395 this->mwindow = mwindow;
398 int LoadBackup::handle_event()
400 ArrayList<char*> path_list;
401 path_list.set_array_delete();
403 char string[BCTEXTLEN];
404 strcpy(string, BACKUP_PATH);
406 fs.complete_path(string);
408 path_list.append(out_path = new char[strlen(string) + 1]);
409 strcpy(out_path, string);
411 mwindow->load_filenames(&path_list, LOAD_REPLACE, 0);
412 mwindow->edl->local_session->clip_title[0] = 0;
413 // This is unique to backups since the path of the backup is different than the
414 // path of the project.
415 mwindow->set_filename(mwindow->edl->project_path);
416 path_list.remove_all_objects();
417 mwindow->undo->update_undo(_("load backup"), LOAD_ALL, 0, 0);
418 mwindow->save_backup();
419 // We deliberately mark the project changed, because the backup is most likely
420 // not identical to the project file that it refers to.
421 mwindow->session->changes_made = 1;
428 // Dialog to set reel number/name
430 ReelWindow::ReelWindow(MWindow *mwindow)
431 : BC_Window(_("Please enter the reel name and number"),
432 mwindow->gui->get_abs_cursor_x(1) - 375 / 2,
433 mwindow->gui->get_abs_cursor_y(1) - 150 / 2,
442 this->mwindow = mwindow;
443 overwrite_reel = 0; // TODO: this should be loaded from previous time
446 ReelWindow::~ReelWindow()
448 delete reel_name_title;
450 delete reel_number_title;
455 int ReelWindow::create_objects()
460 add_subwindow(checkbox = new OverwriteReel(this, x, y, !overwrite_reel));
464 add_subwindow(reel_name_title = new BC_Title(x, y, _("Reel Name:")));
465 x += reel_name_title->get_w() + 20;
467 add_subwindow(reel_name = new BC_TextBox(x,
477 add_subwindow(reel_number_title = new BC_Title(x, y,
479 // line up the text boxes
480 x += reel_name_title->get_w() + 20;
482 add_subwindow(reel_number = new BC_TextBox(x,
488 add_subwindow(ok_button = new BC_OKButton(this));
490 add_subwindow(cancel_button = new BC_CancelButton(this));
492 // Disable reel_name and reel_number if the user doesn't want to overwrite
493 // (overwrite == accept default as well)
496 reel_name->disable();
497 reel_number->disable();
504 int ReelWindow::resize_event(int w, int h)
510 OverwriteReel::OverwriteReel(ReelWindow *rwindow,
511 int x, int y, int value)
512 : BC_CheckBox(x, y, value, _("Use default or previous name and number"))
514 this->rwindow = rwindow;
517 int OverwriteReel::handle_event()
519 rwindow->overwrite_reel = !get_value();
520 // If the checkbox is not enabled, we want to enable the reel_name and
521 // reel_number text boxes
524 rwindow->reel_name->enable();
525 rwindow->reel_number->enable();
529 rwindow->reel_name->disable();
530 rwindow->reel_number->disable();