r499: This commit was manufactured by cvs2svn to create tag 'r1_2_1-last'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / loadfile.C
blobda48fbe7f2eda2fd64e34caa4f9a581fb1680067
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 // Collect all selected files
94                 if(!result)
95                 {
96                         char *in_path, *out_path;
97                         int i = 0;
99                         while(in_path = window.get_path(i))
100                         {
101                                 int j;
102                                 for(j = 0; j < path_list.total; j++)
103                                 {
104                                         if(!strcmp(in_path, path_list.values[j])) break;
105                                 }
106                                 
107                                 if(j == path_list.total)
108                                 {
109                                         path_list.append(out_path = new char[strlen(in_path) + 1]);
110                                         strcpy(out_path, in_path);
111                                 }
112                                 i++;
113                         }
114                 }
116                 mwindow->defaults->update("DEFAULT_LOADPATH", 
117                         window.get_submitted_path());
118                 mwindow->defaults->update("LOAD_MODE", 
119                         load_mode);
120         }
122 // No file selected
123         if(path_list.total == 0 || result == 1)
124         {
125                 return;
126         }
128         {
129                 ReelWindow rwindow(mwindow);
130                 rwindow.create_objects();
131                 result = rwindow.run_window();
133                 if(result)
134                 {
135                         return;
136                 }
137                 
138                 reel_name = rwindow.reel_name->get_text();
139                 reel_number = atol(rwindow.reel_number->get_text());
140                 overwrite_reel = rwindow.overwrite_reel;
141         }
143         mwindow->undo->update_undo_before(_("load"), LOAD_ALL);
144         mwindow->interrupt_indexes();
145         mwindow->gui->lock_window();
146         result = mwindow->load_filenames(&path_list, load_mode, 0, reel_name, reel_number, overwrite_reel);
147         mwindow->gui->mainmenu->add_load(path_list.values[0]);
148         mwindow->gui->unlock_window();
149         path_list.remove_all_objects();
152         mwindow->save_backup();
153         mwindow->restart_brender();
154         mwindow->undo->update_undo_after();
155         return;
165 LoadFileWindow::LoadFileWindow(MWindow *mwindow, 
166         LoadFileThread *thread,
167         char *init_directory)
168  : BC_FileBox(mwindow->gui->get_abs_cursor_x(1),
169                 mwindow->gui->get_abs_cursor_y(1) - BC_WindowBase::get_resources()->filebox_h / 2,
170                 init_directory, 
171                 PROGRAM_NAME ": Load",
172                 _("Select files to load:"), 
173                 mwindow->defaults, NULL, 
174                 0,
175                 0,
176                 1,
177                 mwindow->theme->loadfile_pad)
179         this->thread = thread;
180         this->mwindow = mwindow; 
183 LoadFileWindow::~LoadFileWindow() 
185         delete loadmode;
188 int LoadFileWindow::create_objects()
190         BC_FileBox::create_objects();
192         int x = get_w() / 2 - 200;
193         int y = get_h() - 90;
195         loadmode = new LoadMode(mwindow, this, x, y, &thread->load_mode, 0);
196         loadmode->create_objects();
198         return 0;
201 int LoadFileWindow::resize_event(int w, int h)
203         int x = w / 2 - 200;
204         int y = h - 90;
205         draw_background(0, 0, w, h);
207         loadmode->reposition_window(x, y);
209         return BC_FileBox::resize_event(w, h);
218 NewTimeline::NewTimeline(int x, int y, LoadFileWindow *window)
219  : BC_Radial(x, 
220         y, 
221         window->thread->load_mode == LOAD_REPLACE,
222         _("Replace current project."))
224         this->window = window;
226 int NewTimeline::handle_event()
228         window->newtracks->set_value(0);
229         window->newconcatenate->set_value(0);
230         window->concatenate->set_value(0);
231         window->resourcesonly->set_value(0);
232         return 1;
235 NewConcatenate::NewConcatenate(int x, int y, LoadFileWindow *window)
236  : BC_Radial(x, 
237         y, 
238         window->thread->load_mode == LOAD_REPLACE_CONCATENATE,
239         _("Replace current project and concatenate tracks."))
241         this->window = window;
243 int NewConcatenate::handle_event()
245         window->newtimeline->set_value(0);
246         window->newtracks->set_value(0);
247         window->concatenate->set_value(0);
248         window->resourcesonly->set_value(0);
249         return 1;
252 AppendNewTracks::AppendNewTracks(int x, int y, LoadFileWindow *window)
253  : BC_Radial(x, 
254         y, 
255         window->thread->load_mode == LOAD_NEW_TRACKS,
256         _("Append in new tracks."))
258         this->window = window;
260 int AppendNewTracks::handle_event()
262         window->newtimeline->set_value(0);
263         window->newconcatenate->set_value(0);
264         window->concatenate->set_value(0);
265         window->resourcesonly->set_value(0);
266         return 1;
269 EndofTracks::EndofTracks(int x, int y, LoadFileWindow *window)
270  : BC_Radial(x, 
271         y, 
272         window->thread->load_mode == LOAD_CONCATENATE,
273         _("Concatenate to existing tracks."))
275         this->window = window;
277 int EndofTracks::handle_event()
279         window->newtimeline->set_value(0);
280         window->newconcatenate->set_value(0);
281         window->newtracks->set_value(0);
282         window->resourcesonly->set_value(0);
283         return 1;
286 ResourcesOnly::ResourcesOnly(int x, int y, LoadFileWindow *window)
287  : BC_Radial(x, 
288         y, 
289         window->thread->load_mode == LOAD_RESOURCESONLY,
290         _("Create new resources only."))
292         this->window = window;
294 int ResourcesOnly::handle_event()
296         set_value(1);
297         window->newtimeline->set_value(0);
298         window->newconcatenate->set_value(0);
299         window->newtracks->set_value(0);
300         window->concatenate->set_value(0);
301         return 1;
310 LocateFileWindow::LocateFileWindow(MWindow *mwindow, 
311         char *init_directory, 
312         char *old_filename)
313  : BC_FileBox(mwindow->gui->get_abs_cursor_x(1),
314                 mwindow->gui->get_abs_cursor_y(1), 
315                 init_directory, 
316                 PROGRAM_NAME ": Locate file", 
317                 old_filename)
319         this->mwindow = mwindow; 
322 LocateFileWindow::~LocateFileWindow() {}
330 LoadPrevious::LoadPrevious(MWindow *mwindow)
331  : BC_MenuItem(""), Thread()
333         this->mwindow = mwindow;
334         this->loadfile = loadfile; 
337 int LoadPrevious::handle_event()
339         ArrayList<char*> path_list;
340         path_list.set_array_delete();
341         char *out_path;
342         int load_mode = mwindow->defaults->get("LOAD_MODE", LOAD_REPLACE);
344         mwindow->undo->update_undo_before(_("load previous"), LOAD_ALL);
346         path_list.append(out_path = new char[strlen(path) + 1]);
347         strcpy(out_path, path);
348         mwindow->load_filenames(&path_list, LOAD_REPLACE);
349         mwindow->gui->mainmenu->add_load(path_list.values[0]);
350         path_list.remove_all_objects();
353         mwindow->defaults->update("LOAD_MODE", load_mode);
354         mwindow->undo->update_undo_after();
355         mwindow->save_backup();
356         return 1;
360 void LoadPrevious::run()
362 //      loadfile->mwindow->load(path, loadfile->append);
365 int LoadPrevious::set_path(char *path)
367         strcpy(this->path, path);
377 LoadBackup::LoadBackup(MWindow *mwindow)
378  : BC_MenuItem(_("Load backup"))
380         this->mwindow = mwindow;
383 int LoadBackup::handle_event()
385         ArrayList<char*> path_list;
386         path_list.set_array_delete();
387         char *out_path;
388         char string[BCTEXTLEN];
389         strcpy(string, BACKUP_PATH);
390         FileSystem fs;
391         fs.complete_path(string);
392         
393         path_list.append(out_path = new char[strlen(string) + 1]);
394         strcpy(out_path, string);
395         
396         mwindow->undo->update_undo_before(_("load backup"), LOAD_ALL);
397         mwindow->load_filenames(&path_list, LOAD_REPLACE, 0);
398         mwindow->edl->local_session->clip_title[0] = 0;
399 // This is unique to backups since the path of the backup is different than the
400 // path of the project.
401         mwindow->set_filename(mwindow->edl->project_path);
402         path_list.remove_all_objects();
403         mwindow->undo->update_undo_after();
404         mwindow->save_backup();
406         return 1;
408         
411 // Dialog to set reel number/name
413 ReelWindow::ReelWindow(MWindow *mwindow)
414  : BC_Window(_("Please enter the reel name and number"),
415         mwindow->gui->get_abs_cursor_x(1) - 375 / 2,
416         mwindow->gui->get_abs_cursor_y(1) - 150 / 2,
417         375,
418         150,
419         100,
420         100,
421         0,
422         0,
423         1)
425         this->mwindow = mwindow;
426         overwrite_reel = 0; // TODO: this should be loaded from previous time
429 ReelWindow::~ReelWindow()
431         delete reel_name_title;
432         delete reel_name;
433         delete reel_number_title;
434         delete reel_number;
435         delete checkbox;
438 int ReelWindow::create_objects()
440         int y = 10;
441         int x = 0;
443         add_subwindow(checkbox = new OverwriteReel(this, x, y, !overwrite_reel));       
444         y += 40;
445         
446         x = 10;
447         add_subwindow(reel_name_title = new BC_Title(x, y, _("Reel Name:")));
448         x += reel_name_title->get_w() + 20;
450         add_subwindow(reel_name = new BC_TextBox(x,
451                 y,
452                 250,
453                 1,
454                 "cin0000"));
455         
456         y += 30;
457         
458         x = 10;
459         
460         add_subwindow(reel_number_title = new BC_Title(x, y,
461                                                                                                                                         _("Reel Number:")));
462         // line up the text boxes
463         x += reel_name_title->get_w() + 20;
465         add_subwindow(reel_number = new BC_TextBox(x,
466                 y,
467                 50,
468                 1,
469                 "00"));
471         add_subwindow(ok_button = new BC_OKButton(this));
472         
473         add_subwindow(cancel_button = new BC_CancelButton(this));
475 // Disable reel_name and reel_number if the user doesn't want to overwrite
476 // (overwrite == accept default as well)
477         if(!overwrite_reel)
478         {
479                 reel_name->disable();
480                 reel_number->disable();
481         }
482         show_window();
484         return 0;       
487 int ReelWindow::resize_event(int w, int h)
489 // Doesn't resize
490         return 0;
493 OverwriteReel::OverwriteReel(ReelWindow *rwindow,
494         int x, int y, int value)
495  : BC_CheckBox(x, y, value, _("Use default or previous name and number"))
497         this->rwindow = rwindow;
500 int OverwriteReel::handle_event()
502         rwindow->overwrite_reel = !get_value();
503 // If the checkbox is not enabled, we want to enable the reel_name and
504 // reel_number text boxes
505         if(!get_value())
506         {
507                 rwindow->reel_name->enable();
508                 rwindow->reel_number->enable();
509         }
510         else
511         {
512                 rwindow->reel_name->disable();
513                 rwindow->reel_number->disable();
514         }