00001 #include "assets.h"
00002 #include "defaults.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 mwindow->restart_brender();
00157
00158
00159 if(load_mode == LOAD_REPLACE || load_mode == LOAD_REPLACE_CONCATENATE)
00160 mwindow->session->changes_made = 0;
00161 else
00162 mwindow->session->changes_made = 1;
00163
00164 return;
00165 }
00166
00167
00168
00169
00170
00171
00172
00173
00174 LoadFileWindow::LoadFileWindow(MWindow *mwindow,
00175 LoadFileThread *thread,
00176 char *init_directory)
00177 : BC_FileBox(mwindow->gui->get_abs_cursor_x(1),
00178 mwindow->gui->get_abs_cursor_y(1) - BC_WindowBase::get_resources()->filebox_h / 2,
00179 init_directory,
00180 PROGRAM_NAME ": Load",
00181 _("Select files to load:"),
00182 0,
00183 0,
00184 1,
00185 mwindow->theme->loadfile_pad)
00186 {
00187 this->thread = thread;
00188 this->mwindow = mwindow;
00189 }
00190
00191 LoadFileWindow::~LoadFileWindow()
00192 {
00193 delete loadmode;
00194 }
00195
00196 int LoadFileWindow::create_objects()
00197 {
00198 BC_FileBox::create_objects();
00199
00200 int x = get_w() / 2 - 200;
00201 int y = get_cancel_button()->get_y() - 50;
00202 loadmode = new LoadMode(mwindow, this, x, y, &thread->load_mode, 0);
00203 loadmode->create_objects();
00204
00205 return 0;
00206 }
00207
00208 int LoadFileWindow::resize_event(int w, int h)
00209 {
00210 int x = w / 2 - 200;
00211 int y = get_cancel_button()->get_y() - 50;
00212 draw_background(0, 0, w, h);
00213
00214 loadmode->reposition_window(x, y);
00215
00216 return BC_FileBox::resize_event(w, h);
00217 }
00218
00219
00220
00221
00222
00223
00224
00225 NewTimeline::NewTimeline(int x, int y, LoadFileWindow *window)
00226 : BC_Radial(x,
00227 y,
00228 window->thread->load_mode == LOAD_REPLACE,
00229 _("Replace current project."))
00230 {
00231 this->window = window;
00232 }
00233 int NewTimeline::handle_event()
00234 {
00235 window->newtracks->set_value(0);
00236 window->newconcatenate->set_value(0);
00237 window->concatenate->set_value(0);
00238 window->resourcesonly->set_value(0);
00239 return 1;
00240 }
00241
00242 NewConcatenate::NewConcatenate(int x, int y, LoadFileWindow *window)
00243 : BC_Radial(x,
00244 y,
00245 window->thread->load_mode == LOAD_REPLACE_CONCATENATE,
00246 _("Replace current project and concatenate tracks."))
00247 {
00248 this->window = window;
00249 }
00250 int NewConcatenate::handle_event()
00251 {
00252 window->newtimeline->set_value(0);
00253 window->newtracks->set_value(0);
00254 window->concatenate->set_value(0);
00255 window->resourcesonly->set_value(0);
00256 return 1;
00257 }
00258
00259 AppendNewTracks::AppendNewTracks(int x, int y, LoadFileWindow *window)
00260 : BC_Radial(x,
00261 y,
00262 window->thread->load_mode == LOAD_NEW_TRACKS,
00263 _("Append in new tracks."))
00264 {
00265 this->window = window;
00266 }
00267 int AppendNewTracks::handle_event()
00268 {
00269 window->newtimeline->set_value(0);
00270 window->newconcatenate->set_value(0);
00271 window->concatenate->set_value(0);
00272 window->resourcesonly->set_value(0);
00273 return 1;
00274 }
00275
00276 EndofTracks::EndofTracks(int x, int y, LoadFileWindow *window)
00277 : BC_Radial(x,
00278 y,
00279 window->thread->load_mode == LOAD_CONCATENATE,
00280 _("Concatenate to existing tracks."))
00281 {
00282 this->window = window;
00283 }
00284 int EndofTracks::handle_event()
00285 {
00286 window->newtimeline->set_value(0);
00287 window->newconcatenate->set_value(0);
00288 window->newtracks->set_value(0);
00289 window->resourcesonly->set_value(0);
00290 return 1;
00291 }
00292
00293 ResourcesOnly::ResourcesOnly(int x, int y, LoadFileWindow *window)
00294 : BC_Radial(x,
00295 y,
00296 window->thread->load_mode == LOAD_RESOURCESONLY,
00297 _("Create new resources only."))
00298 {
00299 this->window = window;
00300 }
00301 int ResourcesOnly::handle_event()
00302 {
00303 set_value(1);
00304 window->newtimeline->set_value(0);
00305 window->newconcatenate->set_value(0);
00306 window->newtracks->set_value(0);
00307 window->concatenate->set_value(0);
00308 return 1;
00309 }
00310
00311
00312
00313
00314
00315
00316
00317 LocateFileWindow::LocateFileWindow(MWindow *mwindow,
00318 char *init_directory,
00319 char *old_filename)
00320 : BC_FileBox(mwindow->gui->get_abs_cursor_x(1),
00321 mwindow->gui->get_abs_cursor_y(1),
00322 init_directory,
00323 PROGRAM_NAME ": Locate file",
00324 old_filename)
00325 {
00326 this->mwindow = mwindow;
00327 }
00328
00329 LocateFileWindow::~LocateFileWindow()
00330 {
00331 }
00332
00333
00334
00335
00336
00337
00338
00339 LoadPrevious::LoadPrevious(MWindow *mwindow)
00340 : BC_MenuItem(""), Thread()
00341 {
00342 this->mwindow = mwindow;
00343 this->loadfile = loadfile;
00344 }
00345
00346 int LoadPrevious::handle_event()
00347 {
00348 ArrayList<char*> path_list;
00349 path_list.set_array_delete();
00350 char *out_path;
00351 int load_mode = mwindow->defaults->get("LOAD_MODE", LOAD_REPLACE);
00352
00353
00354 path_list.append(out_path = new char[strlen(path) + 1]);
00355 strcpy(out_path, path);
00356 mwindow->load_filenames(&path_list, LOAD_REPLACE);
00357 mwindow->gui->mainmenu->add_load(path_list.values[0]);
00358 path_list.remove_all_objects();
00359
00360
00361 mwindow->defaults->update("LOAD_MODE", load_mode);
00362 mwindow->undo->update_undo(_("load previous"), LOAD_ALL);
00363 mwindow->save_backup();
00364 mwindow->session->changes_made = 0;
00365
00366 return 1;
00367 }
00368
00369
00370 void LoadPrevious::run()
00371 {
00372
00373 }
00374
00375 int LoadPrevious::set_path(char *path)
00376 {
00377 strcpy(this->path, path);
00378 }
00379
00380
00381
00382
00383
00384
00385
00386
00387 LoadBackup::LoadBackup(MWindow *mwindow)
00388 : BC_MenuItem(_("Load backup"))
00389 {
00390 this->mwindow = mwindow;
00391 }
00392
00393 int LoadBackup::handle_event()
00394 {
00395 ArrayList<char*> path_list;
00396 path_list.set_array_delete();
00397 char *out_path;
00398 char string[BCTEXTLEN];
00399 strcpy(string, BACKUP_PATH);
00400 FileSystem fs;
00401 fs.complete_path(string);
00402
00403 path_list.append(out_path = new char[strlen(string) + 1]);
00404 strcpy(out_path, string);
00405
00406 mwindow->load_filenames(&path_list, LOAD_REPLACE, 0);
00407 mwindow->edl->local_session->clip_title[0] = 0;
00408
00409
00410 mwindow->set_filename(mwindow->edl->project_path);
00411 path_list.remove_all_objects();
00412 mwindow->undo->update_undo(_("load backup"), LOAD_ALL, 0, 0);
00413 mwindow->save_backup();
00414
00415
00416 mwindow->session->changes_made = 1;
00417
00418 return 1;
00419 }
00420
00421
00422
00423
00424
00425 ReelWindow::ReelWindow(MWindow *mwindow)
00426 : BC_Window(_("Please enter the reel name and number"),
00427 mwindow->gui->get_abs_cursor_x(1) - 375 / 2,
00428 mwindow->gui->get_abs_cursor_y(1) - 150 / 2,
00429 375,
00430 150,
00431 100,
00432 100,
00433 0,
00434 0,
00435 1)
00436 {
00437 this->mwindow = mwindow;
00438 overwrite_reel = 0;
00439 }
00440
00441 ReelWindow::~ReelWindow()
00442 {
00443 delete reel_name_title;
00444 delete reel_name;
00445 delete reel_number_title;
00446 delete reel_number;
00447 delete checkbox;
00448 }
00449
00450 int ReelWindow::create_objects()
00451 {
00452 int y = 10;
00453 int x = 0;
00454
00455 add_subwindow(checkbox = new OverwriteReel(this, x, y, !overwrite_reel));
00456 y += 40;
00457
00458 x = 10;
00459 add_subwindow(reel_name_title = new BC_Title(x, y, _("Reel Name:")));
00460 x += reel_name_title->get_w() + 20;
00461
00462 add_subwindow(reel_name = new BC_TextBox(x,
00463 y,
00464 250,
00465 1,
00466 "cin0000"));
00467
00468 y += 30;
00469
00470 x = 10;
00471
00472 add_subwindow(reel_number_title = new BC_Title(x, y,
00473 _("Reel Number:")));
00474
00475 x += reel_name_title->get_w() + 20;
00476
00477 add_subwindow(reel_number = new BC_TextBox(x,
00478 y,
00479 50,
00480 1,
00481 "00"));
00482
00483 add_subwindow(ok_button = new BC_OKButton(this));
00484
00485 add_subwindow(cancel_button = new BC_CancelButton(this));
00486
00487
00488
00489 if(!overwrite_reel)
00490 {
00491 reel_name->disable();
00492 reel_number->disable();
00493 }
00494 show_window();
00495
00496 return 0;
00497 }
00498
00499 int ReelWindow::resize_event(int w, int h)
00500 {
00501
00502 return 0;
00503 }
00504
00505 OverwriteReel::OverwriteReel(ReelWindow *rwindow,
00506 int x, int y, int value)
00507 : BC_CheckBox(x, y, value, _("Use default or previous name and number"))
00508 {
00509 this->rwindow = rwindow;
00510 }
00511
00512 int OverwriteReel::handle_event()
00513 {
00514 rwindow->overwrite_reel = !get_value();
00515
00516
00517 if(!get_value())
00518 {
00519 rwindow->reel_name->enable();
00520 rwindow->reel_number->enable();
00521 }
00522 else
00523 {
00524 rwindow->reel_name->disable();
00525 rwindow->reel_number->disable();
00526 }
00527 }