r602: Fix baver's code... don't insert timecode when show_tc is not set
[cinelerra_cv/mob.git] / cinelerra / loadfile.C
blob7102d3a34117a3c9f18837ef1437bde7f02d8f77
1 #include "assets.h"
2 #include "defaults.h"
3 #include "edl.h"
4 #include "errorbox.h"
5 #include "file.h"
6 #include "filesystem.h"
7 #include "indexfile.h"
8 #include "loadfile.h"
9 #include "loadmode.h"
10 #include "localsession.h"
11 #include "mainmenu.h"
12 #include "mainundo.h"
13 #include "mwindow.h"
14 #include "mwindowgui.h"
15 #include "theme.h"
18 #include <libintl.h>
19 #define _(String) gettext(String)
20 #define gettext_noop(String) String
21 #define N_(String) gettext_noop (String)
25 #include <string.h>
27 Load::Load(MWindow *mwindow, MainMenu *mainmenu)
28  : BC_MenuItem(_("Load files..."), "o", 'o')
29
30         this->mwindow = mwindow;
31         this->mainmenu = mainmenu;
34 Load::~Load()
36         delete thread;
39 int Load::create_objects()
41         thread = new LoadFileThread(mwindow, this);
42         return 0;
45 int Load::handle_event() 
47 //printf("Load::handle_event 1\n");
48         if(!thread->running())
49         {
50 //printf("Load::handle_event 2\n");
51                 thread->start();
52         }
53         return 1;
61 LoadFileThread::LoadFileThread(MWindow *mwindow, Load *load)
62  : Thread()
64         this->mwindow = mwindow;
65         this->load = load;
68 LoadFileThread::~LoadFileThread()
72 void LoadFileThread::run()
74         int result;
75         ArrayList<BC_ListBoxItem*> *dirlist;
76         FileSystem fs;
77         ArrayList<char*> path_list;
78         path_list.set_array_delete();
79         char default_path[BCTEXTLEN];
80         char *reel_name = 0;
81         int reel_number = 0;
82         int overwrite_reel = 0;
83         
84         sprintf(default_path, "~");
85         mwindow->defaults->get("DEFAULT_LOADPATH", default_path);
86         load_mode = mwindow->defaults->get("LOAD_MODE", LOAD_REPLACE);
88         {
89                 LoadFileWindow window(mwindow, this, default_path);
90                 window.create_objects();
91                 result = window.run_window();
93                 if ((!result) && (load_mode == LOAD_REPLACE)) {
94                         mwindow->set_filename(window.get_path(0));
95                 }
97 // Collect all selected files
98                 if(!result)
99                 {
100                         char *in_path, *out_path;
101                         int i = 0;
103                         while(in_path = window.get_path(i))
104                         {
105                                 int j;
106                                 for(j = 0; j < path_list.total; j++)
107                                 {
108                                         if(!strcmp(in_path, path_list.values[j])) break;
109                                 }
110                                 
111                                 if(j == path_list.total)
112                                 {
113                                         path_list.append(out_path = new char[strlen(in_path) + 1]);
114                                         strcpy(out_path, in_path);
115                                 }
116                                 i++;
117                         }
118                 }
120                 mwindow->defaults->update("DEFAULT_LOADPATH", 
121                         window.get_submitted_path());
122                 mwindow->defaults->update("LOAD_MODE", 
123                         load_mode);
124         }
126 // No file selected
127         if(path_list.total == 0 || result == 1)
128         {
129                 return;
130         }
132 //      {
133 //              ReelWindow rwindow(mwindow);
134 //              rwindow.create_objects();
135 //              result = rwindow.run_window();
137 //              if(result)
138 //              {
139 //                      return;
140 //              }
141                 
142 //              reel_name = rwindow.reel_name->get_text();
143 //              reel_number = atol(rwindow.reel_number->get_text());
144 //              overwrite_reel = rwindow.overwrite_reel;
145 //      }
147         reel_name = "none";
148         reel_number = 0;
149         overwrite_reel = 0;
150         
151         mwindow->undo->update_undo_before(_("load"), LOAD_ALL);
152         mwindow->interrupt_indexes();
153         mwindow->gui->lock_window();
154         result = mwindow->load_filenames(&path_list, load_mode, 0, reel_name, reel_number, overwrite_reel);
155         mwindow->gui->mainmenu->add_load(path_list.values[0]);
156         mwindow->gui->unlock_window();
157         path_list.remove_all_objects();
160         mwindow->save_backup();
161         mwindow->restart_brender();
162         mwindow->undo->update_undo_after();
163         return;
173 LoadFileWindow::LoadFileWindow(MWindow *mwindow, 
174         LoadFileThread *thread,
175         char *init_directory)
176  : BC_FileBox(mwindow->gui->get_abs_cursor_x(1),
177                 mwindow->gui->get_abs_cursor_y(1) - BC_WindowBase::get_resources()->filebox_h / 2,
178                 init_directory, 
179                 PROGRAM_NAME ": Load",
180                 _("Select files to load:"), 
181                 mwindow->defaults, NULL, 
182                 0,
183                 0,
184                 1,
185                 mwindow->theme->loadfile_pad)
187         this->thread = thread;
188         this->mwindow = mwindow; 
191 LoadFileWindow::~LoadFileWindow() 
193         delete loadmode;
196 int LoadFileWindow::create_objects()
198         BC_FileBox::create_objects();
200         int x = get_w() / 2 - 200;
201         int y = get_h() - 90;
203         loadmode = new LoadMode(mwindow, this, x, y, &thread->load_mode, 0);
204         loadmode->create_objects();
206         return 0;
209 int LoadFileWindow::resize_event(int w, int h)
211         int x = w / 2 - 200;
212         int y = h - 90;
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)
227  : BC_Radial(x, 
228         y, 
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);
240         return 1;
243 NewConcatenate::NewConcatenate(int x, int y, LoadFileWindow *window)
244  : BC_Radial(x, 
245         y, 
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);
257         return 1;
260 AppendNewTracks::AppendNewTracks(int x, int y, LoadFileWindow *window)
261  : BC_Radial(x, 
262         y, 
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);
274         return 1;
277 EndofTracks::EndofTracks(int x, int y, LoadFileWindow *window)
278  : BC_Radial(x, 
279         y, 
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);
291         return 1;
294 ResourcesOnly::ResourcesOnly(int x, int y, LoadFileWindow *window)
295  : BC_Radial(x, 
296         y, 
297         window->thread->load_mode == LOAD_RESOURCESONLY,
298         _("Create new resources only."))
300         this->window = window;
302 int ResourcesOnly::handle_event()
304         set_value(1);
305         window->newtimeline->set_value(0);
306         window->newconcatenate->set_value(0);
307         window->newtracks->set_value(0);
308         window->concatenate->set_value(0);
309         return 1;
318 LocateFileWindow::LocateFileWindow(MWindow *mwindow, 
319         char *init_directory, 
320         char *old_filename)
321  : BC_FileBox(mwindow->gui->get_abs_cursor_x(1),
322                 mwindow->gui->get_abs_cursor_y(1), 
323                 init_directory, 
324                 PROGRAM_NAME ": Locate file", 
325                 old_filename)
327         this->mwindow = mwindow; 
330 LocateFileWindow::~LocateFileWindow() {}
338 LoadPrevious::LoadPrevious(MWindow *mwindow)
339  : BC_MenuItem(""), Thread()
341         this->mwindow = mwindow;
342         this->loadfile = loadfile; 
345 int LoadPrevious::handle_event()
347         ArrayList<char*> path_list;
348         path_list.set_array_delete();
349         char *out_path;
350         int load_mode = mwindow->defaults->get("LOAD_MODE", LOAD_REPLACE);
352         mwindow->undo->update_undo_before(_("load previous"), LOAD_ALL);
354         path_list.append(out_path = new char[strlen(path) + 1]);
355         strcpy(out_path, path);
356         mwindow->load_filenames(&path_list, LOAD_REPLACE);
357         mwindow->gui->mainmenu->add_load(path_list.values[0]);
358         path_list.remove_all_objects();
361         mwindow->defaults->update("LOAD_MODE", load_mode);
362         mwindow->undo->update_undo_after();
363         mwindow->save_backup();
364         return 1;
368 void LoadPrevious::run()
370 //      loadfile->mwindow->load(path, loadfile->append);
373 int LoadPrevious::set_path(char *path)
375         strcpy(this->path, path);
385 LoadBackup::LoadBackup(MWindow *mwindow)
386  : BC_MenuItem(_("Load backup"))
388         this->mwindow = mwindow;
391 int LoadBackup::handle_event()
393         ArrayList<char*> path_list;
394         path_list.set_array_delete();
395         char *out_path;
396         char string[BCTEXTLEN];
397         strcpy(string, BACKUP_PATH);
398         FileSystem fs;
399         fs.complete_path(string);
400         
401         path_list.append(out_path = new char[strlen(string) + 1]);
402         strcpy(out_path, string);
403         
404         mwindow->undo->update_undo_before(_("load backup"), LOAD_ALL);
405         mwindow->load_filenames(&path_list, LOAD_REPLACE, 0);
406         mwindow->edl->local_session->clip_title[0] = 0;
407 // This is unique to backups since the path of the backup is different than the
408 // path of the project.
409         mwindow->set_filename(mwindow->edl->project_path);
410         path_list.remove_all_objects();
411         mwindow->undo->update_undo_after();
412         mwindow->save_backup();
414         return 1;
416         
419 // Dialog to set reel number/name
421 ReelWindow::ReelWindow(MWindow *mwindow)
422  : BC_Window(_("Please enter the reel name and number"),
423         mwindow->gui->get_abs_cursor_x(1) - 375 / 2,
424         mwindow->gui->get_abs_cursor_y(1) - 150 / 2,
425         375,
426         150,
427         100,
428         100,
429         0,
430         0,
431         1)
433         this->mwindow = mwindow;
434         overwrite_reel = 0; // TODO: this should be loaded from previous time
437 ReelWindow::~ReelWindow()
439         delete reel_name_title;
440         delete reel_name;
441         delete reel_number_title;
442         delete reel_number;
443         delete checkbox;
446 int ReelWindow::create_objects()
448         int y = 10;
449         int x = 0;
451         add_subwindow(checkbox = new OverwriteReel(this, x, y, !overwrite_reel));       
452         y += 40;
453         
454         x = 10;
455         add_subwindow(reel_name_title = new BC_Title(x, y, _("Reel Name:")));
456         x += reel_name_title->get_w() + 20;
458         add_subwindow(reel_name = new BC_TextBox(x,
459                 y,
460                 250,
461                 1,
462                 "cin0000"));
463         
464         y += 30;
465         
466         x = 10;
467         
468         add_subwindow(reel_number_title = new BC_Title(x, y,
469                                                                                                                                         _("Reel Number:")));
470         // line up the text boxes
471         x += reel_name_title->get_w() + 20;
473         add_subwindow(reel_number = new BC_TextBox(x,
474                 y,
475                 50,
476                 1,
477                 "00"));
479         add_subwindow(ok_button = new BC_OKButton(this));
480         
481         add_subwindow(cancel_button = new BC_CancelButton(this));
483 // Disable reel_name and reel_number if the user doesn't want to overwrite
484 // (overwrite == accept default as well)
485         if(!overwrite_reel)
486         {
487                 reel_name->disable();
488                 reel_number->disable();
489         }
490         show_window();
492         return 0;       
495 int ReelWindow::resize_event(int w, int h)
497 // Doesn't resize
498         return 0;
501 OverwriteReel::OverwriteReel(ReelWindow *rwindow,
502         int x, int y, int value)
503  : BC_CheckBox(x, y, value, _("Use default or previous name and number"))
505         this->rwindow = rwindow;
508 int OverwriteReel::handle_event()
510         rwindow->overwrite_reel = !get_value();
511 // If the checkbox is not enabled, we want to enable the reel_name and
512 // reel_number text boxes
513         if(!get_value())
514         {
515                 rwindow->reel_name->enable();
516                 rwindow->reel_number->enable();
517         }
518         else
519         {
520                 rwindow->reel_name->disable();
521                 rwindow->reel_number->disable();
522         }