00001 #include "assets.h"
00002 #include "bchash.h"
00003 #include "edl.h"
00004 #include "errorbox.h"
00005 #include "file.h"
00006 #include "filesystem.h"
00007 #include "indexfile.h"
00008 #include "language.h"
00009 #include "loadfile.h"
00010 #include "loadmode.h"
00011 #include "localsession.h"
00012 #include "mainmenu.h"
00013 #include "mainundo.h"
00014 #include "mainsession.h"
00015 #include "mwindow.h"
00016 #include "mwindowgui.h"
00017 #include "theme.h"
00018
00019
00020
00021 #include <string.h>
00022
00023 Load::Load(MWindow *mwindow, MainMenu *mainmenu)
00024 : BC_MenuItem(_("Load files..."), "o", 'o')
00025 {
00026 this->mwindow = mwindow;
00027 this->mainmenu = mainmenu;
00028 }
00029
00030 Load::~Load()
00031 {
00032 delete thread;
00033 }
00034
00035 int Load::create_objects()
00036 {
00037 thread = new LoadFileThread(mwindow, this);
00038 return 0;
00039 }
00040
00041 int Load::handle_event()
00042 {
00043
00044 if(!thread->running())
00045 {
00046
00047 thread->start();
00048 }
00049 return 1;
00050 }
00051
00052
00053
00054
00055
00056
00057 LoadFileThread::LoadFileThread(MWindow *mwindow, Load *load)
00058 : Thread()
00059 {
00060 this->mwindow = mwindow;
00061 this->load = load;
00062 }
00063
00064 LoadFileThread::~LoadFileThread()
00065 {
00066 }
00067
00068 void LoadFileThread::run()
00069 {
00070 int result;
00071 ArrayList<BC_ListBoxItem*> *dirlist;
00072 FileSystem fs;
00073 ArrayList<char*> path_list;
00074 path_list.set_array_delete();
00075 char default_path[BCTEXTLEN];
00076 char *reel_name = 0;
00077 int reel_number = 0;
00078 int overwrite_reel = 0;
00079
00080 sprintf(default_path, "~");
00081 mwindow->defaults->get("DEFAULT_LOADPATH", default_path);
00082 load_mode = mwindow->defaults->get("LOAD_MODE", LOAD_REPLACE);
00083
00084 {
00085 LoadFileWindow window(mwindow, this, default_path);
00086 window.create_objects();
00087 result = window.run_window();
00088
00089 if ((!result) && (load_mode == LOAD_REPLACE)) {
00090 mwindow->set_filename(window.get_path(0));
00091 }
00092
00093
00094 if(!result)
00095 {
00096 char *in_path, *out_path;
00097 int i = 0;
00098
00099 while((in_path = window.get_path(i)))
00100 {
00101 int j;
00102 for(j = 0; j < path_list.total; j++)
00103 {
00104 if(!strcmp(in_path, path_list.values[j])) break;
00105 }
00106
00107 if(j == path_list.total)
00108 {
00109 path_list.append(out_path = new char[strlen(in_path) + 1]);
00110 strcpy(out_path, in_path);
00111 }
00112 i++;
00113 }
00114 }
00115
00116 mwindow->defaults->update("DEFAULT_LOADPATH",
00117 window.get_submitted_path());
00118 mwindow->defaults->update("LOAD_MODE",
00119 load_mode);
00120 }
00121
00122
00123 if(path_list.total == 0 || result == 1)
00124 {
00125 return;
00126 }
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143 reel_name = "none";
00144 reel_number = 0;
00145 overwrite_reel = 0;
00146
00147 mwindow->interrupt_indexes();
00148 mwindow->gui->lock_window("LoadFileThread::run");
00149 result = mwindow->load_filenames(&path_list, load_mode, 0, reel_name, reel_number, overwrite_reel);
00150 mwindow->gui->mainmenu->add_load(path_list.values[0]);
00151 mwindow->gui->unlock_window();
00152 path_list.remove_all_objects();
00153
00154
00155 mwindow->save_backup();
00156
00157 mwindow->restart_brender();
00158
00159
00160 if(load_mode == LOAD_REPLACE || load_mode == LOAD_REPLACE_CONCATENATE)
00161 mwindow->session->changes_made = 0;
00162 else
00163 mwindow->session->changes_made = 1;
00164
00165 return;
00166 }
00167
00168
00169
00170
00171
00172
00173
00174
00175 LoadFileWindow::LoadFileWindow(MWindow *mwindow,
00176 LoadFileThread *thread,
00177 char *init_directory)
00178 : BC_FileBox(mwindow->gui->get_abs_cursor_x(1),
00179 mwindow->gui->get_abs_cursor_y(1) - BC_WindowBase::get_resources()->filebox_h / 2,
00180 init_directory,
00181 PROGRAM_NAME ": Load",
00182 _("Select files to load:"),
00183 0,
00184 0,
00185 1,
00186 mwindow->theme->loadfile_pad)
00187 {
00188 this->thread = thread;
00189 this->mwindow = mwindow;
00190 }
00191
00192 LoadFileWindow::~LoadFileWindow()
00193 {
00194 delete loadmode;
00195 }
00196
00197 int LoadFileWindow::create_objects()
00198 {
00199 BC_FileBox::create_objects();
00200
00201 int x = get_w() / 2 - 200;
00202 int y = get_cancel_button()->get_y() - 50;
00203 loadmode = new LoadMode(mwindow, this, x, y, &thread->load_mode, 0);
00204 loadmode->create_objects();
00205
00206 return 0;
00207 }
00208
00209 int LoadFileWindow::resize_event(int w, int h)
00210 {
00211 int x = w / 2 - 200;
00212 int y = get_cancel_button()->get_y() - 50;
00213 draw_background(0, 0, w, h);
00214
00215 loadmode->reposition_window(x, y);
00216
00217 return BC_FileBox::resize_event(w, h);
00218 }
00219
00220
00221
00222
00223
00224
00225
00226 NewTimeline::NewTimeline(int x, int y, LoadFileWindow *window)
00227 : BC_Radial(x,
00228 y,
00229 window->thread->load_mode == LOAD_REPLACE,
00230 _("Replace current project."))
00231 {
00232 this->window = window;
00233 }
00234 int NewTimeline::handle_event()
00235 {
00236 window->newtracks->set_value(0);
00237 window->newconcatenate->set_value(0);
00238 window->concatenate->set_value(0);
00239 window->resourcesonly->set_value(0);
00240 return 1;
00241 }
00242
00243 NewConcatenate::NewConcatenate(int x, int y, LoadFileWindow *window)
00244 : BC_Radial(x,
00245 y,
00246 window->thread->load_mode == LOAD_REPLACE_CONCATENATE,
00247 _("Replace current project and concatenate tracks."))
00248 {
00249 this->window = window;
00250 }
00251 int NewConcatenate::handle_event()
00252 {
00253 window->newtimeline->set_value(0);
00254 window->newtracks->set_value(0);
00255 window->concatenate->set_value(0);
00256 window->resourcesonly->set_value(0);
00257 return 1;
00258 }
00259
00260 AppendNewTracks::AppendNewTracks(int x, int y, LoadFileWindow *window)
00261 : BC_Radial(x,
00262 y,
00263 window->thread->load_mode == LOAD_NEW_TRACKS,
00264 _("Append in new tracks."))
00265 {
00266 this->window = window;
00267 }
00268 int AppendNewTracks::handle_event()
00269 {
00270 window->newtimeline->set_value(0);
00271 window->newconcatenate->set_value(0);
00272 window->concatenate->set_value(0);
00273 window->resourcesonly->set_value(0);
00274 return 1;
00275 }
00276
00277 EndofTracks::EndofTracks(int x, int y, LoadFileWindow *window)
00278 : BC_Radial(x,
00279 y,
00280 window->thread->load_mode == LOAD_CONCATENATE,
00281 _("Concatenate to existing tracks."))
00282 {
00283 this->window = window;
00284 }
00285 int EndofTracks::handle_event()
00286 {
00287 window->newtimeline->set_value(0);
00288 window->newconcatenate->set_value(0);
00289 window->newtracks->set_value(0);
00290 window->resourcesonly->set_value(0);
00291 return 1;
00292 }
00293
00294 ResourcesOnly::ResourcesOnly(int x, int y, LoadFileWindow *window)
00295 : BC_Radial(x,
00296 y,
00297 window->thread->load_mode == LOAD_RESOURCESONLY,
00298 _("Create new resources only."))
00299 {
00300 this->window = window;
00301 }
00302 int ResourcesOnly::handle_event()
00303 {
00304 set_value(1);
00305 window->newtimeline->set_value(0);
00306 window->newconcatenate->set_value(0);
00307 window->newtracks->set_value(0);
00308 window->concatenate->set_value(0);
00309 return 1;
00310 }
00311
00312
00313
00314
00315
00316
00317
00318 LocateFileWindow::LocateFileWindow(MWindow *mwindow,
00319 char *init_directory,
00320 char *old_filename)
00321 : BC_FileBox(mwindow->gui->get_abs_cursor_x(1),
00322 mwindow->gui->get_abs_cursor_y(1),
00323 init_directory,
00324 PROGRAM_NAME ": Locate file",
00325 old_filename)
00326 {
00327 this->mwindow = mwindow;
00328 }
00329
00330 LocateFileWindow::~LocateFileWindow()
00331 {
00332 }
00333
00334
00335
00336
00337
00338
00339
00340 LoadPrevious::LoadPrevious(MWindow *mwindow)
00341 : BC_MenuItem(""), Thread()
00342 {
00343 this->mwindow = mwindow;
00344 this->loadfile = loadfile;
00345 }
00346
00347 int LoadPrevious::handle_event()
00348 {
00349 ArrayList<char*> path_list;
00350 path_list.set_array_delete();
00351 char *out_path;
00352 int load_mode = mwindow->defaults->get("LOAD_MODE", LOAD_REPLACE);
00353
00354
00355 path_list.append(out_path = new char[strlen(path) + 1]);
00356 strcpy(out_path, path);
00357 mwindow->load_filenames(&path_list, LOAD_REPLACE);
00358 mwindow->gui->mainmenu->add_load(path_list.values[0]);
00359 path_list.remove_all_objects();
00360
00361
00362 mwindow->defaults->update("LOAD_MODE", load_mode);
00363 mwindow->undo->update_undo(_("load previous"), LOAD_ALL);
00364 mwindow->save_backup();
00365 mwindow->session->changes_made = 0;
00366 return 1;
00367 }
00368
00369
00370
00371
00372
00373
00374
00375 void LoadPrevious::run()
00376 {
00377
00378 }
00379
00380 int LoadPrevious::set_path(char *path)
00381 {
00382 strcpy(this->path, path);
00383 }
00384
00385
00386
00387
00388
00389
00390
00391
00392 LoadBackup::LoadBackup(MWindow *mwindow)
00393 : BC_MenuItem(_("Load backup"))
00394 {
00395 this->mwindow = mwindow;
00396 }
00397
00398 int LoadBackup::handle_event()
00399 {
00400 ArrayList<char*> path_list;
00401 path_list.set_array_delete();
00402 char *out_path;
00403 char string[BCTEXTLEN];
00404 strcpy(string, BACKUP_PATH);
00405 FileSystem fs;
00406 fs.complete_path(string);
00407
00408 path_list.append(out_path = new char[strlen(string) + 1]);
00409 strcpy(out_path, string);
00410
00411 mwindow->load_filenames(&path_list, LOAD_REPLACE, 0);
00412 mwindow->edl->local_session->clip_title[0] = 0;
00413
00414
00415 mwindow->set_filename(mwindow->edl->project_path);
00416 path_list.remove_all_objects();
00417 mwindow->undo->update_undo(_("load backup"), LOAD_ALL, 0, 0);
00418 mwindow->save_backup();
00419
00420
00421 mwindow->session->changes_made = 1;
00422
00423 return 1;
00424 }
00425
00426
00427
00428
00429
00430 ReelWindow::ReelWindow(MWindow *mwindow)
00431 : BC_Window(_("Please enter the reel name and number"),
00432 mwindow->gui->get_abs_cursor_x(1) - 375 / 2,
00433 mwindow->gui->get_abs_cursor_y(1) - 150 / 2,
00434 375,
00435 150,
00436 100,
00437 100,
00438 0,
00439 0,
00440 1)
00441 {
00442 this->mwindow = mwindow;
00443 overwrite_reel = 0;
00444 }
00445
00446 ReelWindow::~ReelWindow()
00447 {
00448 delete reel_name_title;
00449 delete reel_name;
00450 delete reel_number_title;
00451 delete reel_number;
00452 delete checkbox;
00453 }
00454
00455 int ReelWindow::create_objects()
00456 {
00457 int y = 10;
00458 int x = 0;
00459
00460 add_subwindow(checkbox = new OverwriteReel(this, x, y, !overwrite_reel));
00461 y += 40;
00462
00463 x = 10;
00464 add_subwindow(reel_name_title = new BC_Title(x, y, _("Reel Name:")));
00465 x += reel_name_title->get_w() + 20;
00466
00467 add_subwindow(reel_name = new BC_TextBox(x,
00468 y,
00469 250,
00470 1,
00471 "cin0000"));
00472
00473 y += 30;
00474
00475 x = 10;
00476
00477 add_subwindow(reel_number_title = new BC_Title(x, y,
00478 _("Reel Number:")));
00479
00480 x += reel_name_title->get_w() + 20;
00481
00482 add_subwindow(reel_number = new BC_TextBox(x,
00483 y,
00484 50,
00485 1,
00486 "00"));
00487
00488 add_subwindow(ok_button = new BC_OKButton(this));
00489
00490 add_subwindow(cancel_button = new BC_CancelButton(this));
00491
00492
00493
00494 if(!overwrite_reel)
00495 {
00496 reel_name->disable();
00497 reel_number->disable();
00498 }
00499 show_window();
00500
00501 return 0;
00502 }
00503
00504 int ReelWindow::resize_event(int w, int h)
00505 {
00506
00507 return 0;
00508 }
00509
00510 OverwriteReel::OverwriteReel(ReelWindow *rwindow,
00511 int x, int y, int value)
00512 : BC_CheckBox(x, y, value, _("Use default or previous name and number"))
00513 {
00514 this->rwindow = rwindow;
00515 }
00516
00517 int OverwriteReel::handle_event()
00518 {
00519 rwindow->overwrite_reel = !get_value();
00520
00521
00522 if(!get_value())
00523 {
00524 rwindow->reel_name->enable();
00525 rwindow->reel_number->enable();
00526 }
00527 else
00528 {
00529 rwindow->reel_name->disable();
00530 rwindow->reel_number->disable();
00531 }
00532 }