r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / loadfile.C
blobf336bcfee4c8a8ac481bf8c034015edadb049c78
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", window.get_path());
114                 mwindow->defaults->update("LOAD_MODE", load_mode);
115         }
117 // No file selected
118         if(path_list.total == 0 || result == 1)
119         {
120                 return;
121         }
123         mwindow->undo->update_undo_before(_("load"), LOAD_ALL);
124         mwindow->interrupt_indexes();
125         mwindow->gui->lock_window();
126         result = mwindow->load_filenames(&path_list, load_mode);
127         mwindow->gui->mainmenu->add_load(path_list.values[0]);
128         mwindow->gui->unlock_window();
129         path_list.remove_all_objects();
132         mwindow->save_backup();
133         mwindow->restart_brender();
134         mwindow->undo->update_undo_after();
135         return;
145 LoadFileWindow::LoadFileWindow(MWindow *mwindow, 
146         LoadFileThread *thread,
147         char *init_directory)
148  : BC_FileBox(mwindow->gui->get_abs_cursor_x(),
149                 mwindow->gui->get_abs_cursor_y() - BC_WindowBase::get_resources()->filebox_h / 2,
150                 init_directory, 
151                 PROGRAM_NAME ": Load",
152                 _("Select files to load:"), 
153                 0,
154                 0,
155                 1,
156                 mwindow->theme->loadfile_pad)
158         this->thread = thread;
159         this->mwindow = mwindow; 
162 LoadFileWindow::~LoadFileWindow() 
164         delete loadmode;
167 int LoadFileWindow::create_objects()
169         BC_FileBox::create_objects();
171         int x = get_w() / 2 - 200;
172         int y = get_h() - 90;
173         loadmode = new LoadMode(mwindow, this, x, y, &thread->load_mode, 0);
174         loadmode->create_objects();
176         return 0;
179 int LoadFileWindow::resize_event(int w, int h)
181         int x = w / 2 - 200;
182         int y = h - 90;
183         draw_background(0, 0, w, h);
185         loadmode->reposition_window(x, y);
187         return BC_FileBox::resize_event(w, h);
191 NewTimeline::NewTimeline(int x, int y, LoadFileWindow *window)
192  : BC_Radial(x, 
193         y, 
194         window->thread->load_mode == LOAD_REPLACE,
195         _("Replace current project."))
197         this->window = window;
199 int NewTimeline::handle_event()
201         window->newtracks->set_value(0);
202         window->newconcatenate->set_value(0);
203         window->concatenate->set_value(0);
204         window->resourcesonly->set_value(0);
205         return 1;
208 NewConcatenate::NewConcatenate(int x, int y, LoadFileWindow *window)
209  : BC_Radial(x, 
210         y, 
211         window->thread->load_mode == LOAD_REPLACE_CONCATENATE,
212         _("Replace current project and concatenate tracks."))
214         this->window = window;
216 int NewConcatenate::handle_event()
218         window->newtimeline->set_value(0);
219         window->newtracks->set_value(0);
220         window->concatenate->set_value(0);
221         window->resourcesonly->set_value(0);
222         return 1;
225 AppendNewTracks::AppendNewTracks(int x, int y, LoadFileWindow *window)
226  : BC_Radial(x, 
227         y, 
228         window->thread->load_mode == LOAD_NEW_TRACKS,
229         _("Append in new tracks."))
231         this->window = window;
233 int AppendNewTracks::handle_event()
235         window->newtimeline->set_value(0);
236         window->newconcatenate->set_value(0);
237         window->concatenate->set_value(0);
238         window->resourcesonly->set_value(0);
239         return 1;
242 EndofTracks::EndofTracks(int x, int y, LoadFileWindow *window)
243  : BC_Radial(x, 
244         y, 
245         window->thread->load_mode == LOAD_CONCATENATE,
246         _("Concatenate to existing tracks."))
248         this->window = window;
250 int EndofTracks::handle_event()
252         window->newtimeline->set_value(0);
253         window->newconcatenate->set_value(0);
254         window->newtracks->set_value(0);
255         window->resourcesonly->set_value(0);
256         return 1;
259 ResourcesOnly::ResourcesOnly(int x, int y, LoadFileWindow *window)
260  : BC_Radial(x, 
261         y, 
262         window->thread->load_mode == LOAD_RESOURCESONLY,
263         _("Create new resources only."))
265         this->window = window;
267 int ResourcesOnly::handle_event()
269         set_value(1);
270         window->newtimeline->set_value(0);
271         window->newconcatenate->set_value(0);
272         window->newtracks->set_value(0);
273         window->concatenate->set_value(0);
274         return 1;
283 LocateFileWindow::LocateFileWindow(MWindow *mwindow, 
284         char *init_directory, 
285         char *old_filename)
286  : BC_FileBox(mwindow->gui->get_abs_cursor_x(),
287                 mwindow->gui->get_abs_cursor_y(), 
288                 init_directory, 
289                 PROGRAM_NAME ": Locate file", 
290                 old_filename)
292         this->mwindow = mwindow; 
295 LocateFileWindow::~LocateFileWindow() {}
303 LoadPrevious::LoadPrevious(MWindow *mwindow, Load *loadfile)
304  : BC_MenuItem(""), Thread()
306         this->mwindow = mwindow;
307         this->loadfile = loadfile; 
310 int LoadPrevious::handle_event()
312         ArrayList<char*> path_list;
313         path_list.set_array_delete();
314         char *out_path;
315         int load_mode = mwindow->defaults->get("LOAD_MODE", LOAD_REPLACE);
317         mwindow->undo->update_undo_before(_("load previous"), LOAD_ALL);
319         path_list.append(out_path = new char[strlen(path) + 1]);
320         strcpy(out_path, path);
321 //printf("LoadPrevious::LoadPrevious 1\n");
322         mwindow->load_filenames(&path_list, LOAD_REPLACE);
323 //printf("LoadPrevious::LoadPrevious 2\n");
324         mwindow->gui->mainmenu->add_load(path_list.values[0]);
325 //printf("LoadPrevious::LoadPrevious 3\n");
326         path_list.remove_all_objects();
327 //printf("LoadPrevious::LoadPrevious 4\n");
330         mwindow->defaults->update("LOAD_MODE", load_mode);
331         mwindow->undo->update_undo_after();
332         mwindow->save_backup();
333         return 1;
342 void LoadPrevious::run()
344 //      loadfile->mwindow->load(path, loadfile->append);
347 int LoadPrevious::set_path(char *path)
349         strcpy(this->path, path);
359 LoadBackup::LoadBackup(MWindow *mwindow)
360  : BC_MenuItem(_("Load backup"))
362         this->mwindow = mwindow;
365 int LoadBackup::handle_event()
367         ArrayList<char*> path_list;
368         path_list.set_array_delete();
369         char *out_path;
370         char string[BCTEXTLEN];
371         strcpy(string, BACKUP_PATH);
372         FileSystem fs;
373         fs.complete_path(string);
374         
375         path_list.append(out_path = new char[strlen(string) + 1]);
376         strcpy(out_path, string);
377         
378         mwindow->undo->update_undo_before(_("load backup"), LOAD_ALL);
379         mwindow->load_filenames(&path_list, LOAD_REPLACE);
380         mwindow->edl->local_session->clip_title[0] = 0;
381         mwindow->set_filename("");
382         path_list.remove_all_objects();
383         mwindow->undo->update_undo_after();
384         mwindow->save_backup();
386         return 1;
388