r136: This commit was manufactured by cvs2svn to create tag 'hv_1_1_8'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / loadfile.C
blobafb9a8e0a2849e543742432d44937765ccde1439
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];
81         sprintf(default_path, "~");
82         mwindow->defaults->get("DEFAULT_LOADPATH", default_path);
83         load_mode = mwindow->defaults->get("LOAD_MODE", LOAD_REPLACE);
85         {
86                 LoadFileWindow window(mwindow, this, default_path);
87                 window.create_objects();
88                 result = window.run_window();
90 // Collect all selected files
91                 if(!result)
92                 {
93                         char *in_path, *out_path;
94                         int i = 0;
96                         while(in_path = window.get_path(i))
97                         {
98                                 int j;
99                                 for(j = 0; j < path_list.total; j++)
100                                 {
101                                         if(!strcmp(in_path, path_list.values[j])) break;
102                                 }
103                                 
104                                 if(j == path_list.total)
105                                 {
106                                         path_list.append(out_path = new char[strlen(in_path) + 1]);
107                                         strcpy(out_path, in_path);
108                                 }
109                                 i++;
110                         }
111                 }
113                 mwindow->defaults->update("DEFAULT_LOADPATH", 
114                         window.get_submitted_path());
115                 mwindow->defaults->update("LOAD_MODE", 
116                         load_mode);
117         }
119 // No file selected
120         if(path_list.total == 0 || result == 1)
121         {
122                 return;
123         }
125         mwindow->undo->update_undo_before(_("load"), LOAD_ALL);
126         mwindow->interrupt_indexes();
127         mwindow->gui->lock_window();
128         result = mwindow->load_filenames(&path_list, load_mode);
129         mwindow->gui->mainmenu->add_load(path_list.values[0]);
130         mwindow->gui->unlock_window();
131         path_list.remove_all_objects();
134         mwindow->save_backup();
135         mwindow->restart_brender();
136         mwindow->undo->update_undo_after();
137         return;
147 LoadFileWindow::LoadFileWindow(MWindow *mwindow, 
148         LoadFileThread *thread,
149         char *init_directory)
150  : BC_FileBox(mwindow->gui->get_abs_cursor_x(),
151                 mwindow->gui->get_abs_cursor_y() - BC_WindowBase::get_resources()->filebox_h / 2,
152                 init_directory, 
153                 PROGRAM_NAME ": Load",
154                 _("Select files to load:"), 
155                 0,
156                 0,
157                 1,
158                 mwindow->theme->loadfile_pad)
160         this->thread = thread;
161         this->mwindow = mwindow; 
164 LoadFileWindow::~LoadFileWindow() 
166         delete loadmode;
169 int LoadFileWindow::create_objects()
171         BC_FileBox::create_objects();
173         int x = get_w() / 2 - 200;
174         int y = get_h() - 90;
175         loadmode = new LoadMode(mwindow, this, x, y, &thread->load_mode, 0);
176         loadmode->create_objects();
178         return 0;
181 int LoadFileWindow::resize_event(int w, int h)
183         int x = w / 2 - 200;
184         int y = h - 90;
185         draw_background(0, 0, w, h);
187         loadmode->reposition_window(x, y);
189         return BC_FileBox::resize_event(w, h);
198 NewTimeline::NewTimeline(int x, int y, LoadFileWindow *window)
199  : BC_Radial(x, 
200         y, 
201         window->thread->load_mode == LOAD_REPLACE,
202         _("Replace current project."))
204         this->window = window;
206 int NewTimeline::handle_event()
208         window->newtracks->set_value(0);
209         window->newconcatenate->set_value(0);
210         window->concatenate->set_value(0);
211         window->resourcesonly->set_value(0);
212         return 1;
215 NewConcatenate::NewConcatenate(int x, int y, LoadFileWindow *window)
216  : BC_Radial(x, 
217         y, 
218         window->thread->load_mode == LOAD_REPLACE_CONCATENATE,
219         _("Replace current project and concatenate tracks."))
221         this->window = window;
223 int NewConcatenate::handle_event()
225         window->newtimeline->set_value(0);
226         window->newtracks->set_value(0);
227         window->concatenate->set_value(0);
228         window->resourcesonly->set_value(0);
229         return 1;
232 AppendNewTracks::AppendNewTracks(int x, int y, LoadFileWindow *window)
233  : BC_Radial(x, 
234         y, 
235         window->thread->load_mode == LOAD_NEW_TRACKS,
236         _("Append in new tracks."))
238         this->window = window;
240 int AppendNewTracks::handle_event()
242         window->newtimeline->set_value(0);
243         window->newconcatenate->set_value(0);
244         window->concatenate->set_value(0);
245         window->resourcesonly->set_value(0);
246         return 1;
249 EndofTracks::EndofTracks(int x, int y, LoadFileWindow *window)
250  : BC_Radial(x, 
251         y, 
252         window->thread->load_mode == LOAD_CONCATENATE,
253         _("Concatenate to existing tracks."))
255         this->window = window;
257 int EndofTracks::handle_event()
259         window->newtimeline->set_value(0);
260         window->newconcatenate->set_value(0);
261         window->newtracks->set_value(0);
262         window->resourcesonly->set_value(0);
263         return 1;
266 ResourcesOnly::ResourcesOnly(int x, int y, LoadFileWindow *window)
267  : BC_Radial(x, 
268         y, 
269         window->thread->load_mode == LOAD_RESOURCESONLY,
270         _("Create new resources only."))
272         this->window = window;
274 int ResourcesOnly::handle_event()
276         set_value(1);
277         window->newtimeline->set_value(0);
278         window->newconcatenate->set_value(0);
279         window->newtracks->set_value(0);
280         window->concatenate->set_value(0);
281         return 1;
290 LocateFileWindow::LocateFileWindow(MWindow *mwindow, 
291         char *init_directory, 
292         char *old_filename)
293  : BC_FileBox(mwindow->gui->get_abs_cursor_x(),
294                 mwindow->gui->get_abs_cursor_y(), 
295                 init_directory, 
296                 PROGRAM_NAME ": Locate file", 
297                 old_filename)
299         this->mwindow = mwindow; 
302 LocateFileWindow::~LocateFileWindow() {}
310 LoadPrevious::LoadPrevious(MWindow *mwindow, Load *loadfile)
311  : BC_MenuItem(""), Thread()
313         this->mwindow = mwindow;
314         this->loadfile = loadfile; 
317 int LoadPrevious::handle_event()
319         ArrayList<char*> path_list;
320         path_list.set_array_delete();
321         char *out_path;
322         int load_mode = mwindow->defaults->get("LOAD_MODE", LOAD_REPLACE);
324         mwindow->undo->update_undo_before(_("load previous"), LOAD_ALL);
326         path_list.append(out_path = new char[strlen(path) + 1]);
327         strcpy(out_path, path);
328         mwindow->load_filenames(&path_list, LOAD_REPLACE);
329         mwindow->gui->mainmenu->add_load(path_list.values[0]);
330         path_list.remove_all_objects();
333         mwindow->defaults->update("LOAD_MODE", load_mode);
334         mwindow->undo->update_undo_after();
335         mwindow->save_backup();
336         return 1;
345 void LoadPrevious::run()
347 //      loadfile->mwindow->load(path, loadfile->append);
350 int LoadPrevious::set_path(char *path)
352         strcpy(this->path, path);
362 LoadBackup::LoadBackup(MWindow *mwindow)
363  : BC_MenuItem(_("Load backup"))
365         this->mwindow = mwindow;
368 int LoadBackup::handle_event()
370         ArrayList<char*> path_list;
371         path_list.set_array_delete();
372         char *out_path;
373         char string[BCTEXTLEN];
374         strcpy(string, BACKUP_PATH);
375         FileSystem fs;
376         fs.complete_path(string);
377         
378         path_list.append(out_path = new char[strlen(string) + 1]);
379         strcpy(out_path, string);
380         
381         mwindow->undo->update_undo_before(_("load backup"), LOAD_ALL);
382         mwindow->load_filenames(&path_list, LOAD_REPLACE);
383         mwindow->edl->local_session->clip_title[0] = 0;
384         mwindow->set_filename("");
385         path_list.remove_all_objects();
386         mwindow->undo->update_undo_after();
387         mwindow->save_backup();
389         return 1;
391