initial commit
[goodguy/history.git] / cinelerra-5.0 / cinelerra / loadfile.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2009 Adam Williams <broadcast at earthling dot net>
5  * 
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * 
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  * 
20  */
21
22 #include "assets.h"
23 #include "bcsignals.h"
24 #include "bchash.h"
25 #include "edl.h"
26 #include "errorbox.h"
27 #include "file.h"
28 #include "filesystem.h"
29 #include "indexfile.h"
30 #include "language.h"
31 #include "loadfile.h"
32 #include "loadmode.h"
33 #include "localsession.h"
34 #include "mainmenu.h"
35 #include "mainundo.h"
36 #include "mwindow.h"
37 #include "mwindowgui.h"
38 #include "theme.h"
39
40
41
42 #include <string.h>
43
44 Load::Load(MWindow *mwindow, MainMenu *mainmenu)
45  : BC_MenuItem(_("Load files..."), "o", 'o')
46
47         this->mwindow = mwindow;
48         this->mainmenu = mainmenu;
49 }
50
51 Load::~Load()
52 {
53         delete thread;
54 }
55
56 void Load::create_objects()
57 {
58         thread = new LoadFileThread(mwindow, this);
59 }
60
61 int Load::handle_event() 
62 {
63         mwindow->gui->unlock_window();
64         thread->start();
65         mwindow->gui->lock_window("Load::handle_event");
66         return 1;
67 }
68
69
70
71
72
73
74 LoadFileThread::LoadFileThread(MWindow *mwindow, Load *load)
75  : BC_DialogThread()
76 {
77         this->mwindow = mwindow;
78         this->load = load;
79 }
80
81 LoadFileThread::~LoadFileThread()
82 {
83 }
84
85 BC_Window* LoadFileThread::new_gui()
86 {
87         char default_path[BCTEXTLEN];
88
89         sprintf(default_path, "~");
90         mwindow->defaults->get("DEFAULT_LOADPATH", default_path);
91         load_mode = mwindow->defaults->get("LOAD_MODE", LOADMODE_REPLACE);
92
93         mwindow->gui->lock_window("LoadFileThread::new_gui");
94         window = new LoadFileWindow(mwindow, this, default_path);
95         mwindow->gui->unlock_window();
96         
97         window->create_objects();
98         return window;
99 }
100
101 void LoadFileThread::handle_done_event(int result)
102 {
103         ArrayList<char*> path_list;
104         path_list.set_array_delete();
105 // Collect all selected files
106         if(!result)
107         {
108                 char *in_path, *out_path;
109                 int i = 0;
110                 window->lock_window("LoadFileThread::handle_done_event");
111                 window->hide_window();
112                 window->unlock_window();
113
114                 while((in_path = window->get_path(i)))
115                 {
116                         int j;
117                         for(j = 0; j < path_list.total; j++)
118                         {
119                                 if(!strcmp(in_path, path_list.values[j])) break;
120                         }
121
122                         if(j == path_list.total)
123                         {
124                                 path_list.append(out_path = new char[strlen(in_path) + 1]);
125                                 strcpy(out_path, in_path);
126                         }
127                         i++;
128                 }
129         }
130
131         mwindow->defaults->update("DEFAULT_LOADPATH", 
132                 window->get_submitted_path());
133         mwindow->defaults->update("LOAD_MODE", 
134                 load_mode);
135
136 // No file selected
137         if(path_list.total == 0 || result == 1)
138         {
139                 return;
140         }
141
142         mwindow->interrupt_indexes();
143         mwindow->gui->lock_window("LoadFileThread::run");
144         result = mwindow->load_filenames(&path_list, load_mode);
145         mwindow->gui->mainmenu->add_load(path_list.values[0]);
146         mwindow->gui->unlock_window();
147         path_list.remove_all_objects();
148
149
150         mwindow->save_backup();
151
152         mwindow->restart_brender();
153 }
154
155
156
157
158
159
160
161
162
163
164
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) - 
170                         BC_WindowBase::get_resources()->filebox_h / 2,
171                 init_directory, 
172                 PROGRAM_NAME ": Load",
173                 _("Select files to load:"), 
174                 0,
175                 0,
176                 1,
177                 mwindow->theme->loadfile_pad)
178 {
179         this->thread = thread;
180         this->mwindow = mwindow; 
181 }
182
183 LoadFileWindow::~LoadFileWindow() 
184 {
185         lock_window("LoadFileWindow::~LoadFileWindow");
186         delete loadmode;
187         unlock_window();
188 }
189
190 void LoadFileWindow::create_objects()
191 {
192         lock_window("LoadFileWindow::create_objects");
193         BC_FileBox::create_objects();
194
195         int x = get_w() / 2 - 
196                 LoadMode::calculate_w(this, mwindow->theme, 0, 1) / 2;
197         int y = get_cancel_button()->get_y() - 
198                 LoadMode::calculate_h(this, mwindow->theme);
199         loadmode = new LoadMode(mwindow, this, x, y, &thread->load_mode, 0, 1);
200         loadmode->create_objects();
201         show_window(1);
202         unlock_window();
203
204 }
205
206 int LoadFileWindow::resize_event(int w, int h)
207 {
208         int x = w / 2 - 200;
209         int y = get_cancel_button()->get_y() - 
210                 LoadMode::calculate_h(this, mwindow->theme);
211         draw_background(0, 0, w, h);
212
213         loadmode->reposition_window(x, y);
214
215         return BC_FileBox::resize_event(w, h);
216 }
217
218
219
220
221
222
223
224
225
226
227
228
229
230 LocateFileWindow::LocateFileWindow(MWindow *mwindow, 
231         char *init_directory, 
232         char *old_filename)
233  : BC_FileBox(mwindow->gui->get_abs_cursor_x(1),
234                 mwindow->gui->get_abs_cursor_y(1), 
235                 init_directory, 
236                 PROGRAM_NAME ": Locate file", 
237                 old_filename)
238
239         this->mwindow = mwindow; 
240 }
241
242 LocateFileWindow::~LocateFileWindow()
243 {
244 }
245
246
247
248
249
250
251
252 LoadPrevious::LoadPrevious(MWindow *mwindow, Load *loadfile)
253  : BC_MenuItem(""), Thread()
254
255         this->mwindow = mwindow;
256         this->loadfile = loadfile; 
257 }
258
259 int LoadPrevious::handle_event()
260 {
261         ArrayList<char*> path_list;
262         path_list.set_array_delete();
263         char *out_path;
264         int load_mode = mwindow->defaults->get("LOAD_MODE", LOADMODE_REPLACE);
265
266
267         path_list.append(out_path = new char[strlen(path) + 1]);
268         strcpy(out_path, path);
269
270         mwindow->load_filenames(&path_list, LOADMODE_REPLACE);
271         mwindow->gui->mainmenu->add_load(path_list.values[0]);
272         path_list.remove_all_objects();
273
274
275         mwindow->defaults->update("LOAD_MODE", load_mode);
276         mwindow->save_backup();
277         return 1;
278 }
279
280
281
282 void LoadPrevious::run()
283 {
284 //      loadfile->mwindow->load(path, loadfile->append);
285 }
286
287 int LoadPrevious::set_path(char *path)
288 {
289         strcpy(this->path, path);
290         return 0;
291 }
292
293
294
295 LoadBackup::LoadBackup(MWindow *mwindow)
296  : BC_MenuItem(_("Load backup"))
297 {
298         this->mwindow = mwindow;
299 }
300
301 int LoadBackup::handle_event()
302 {
303         mwindow->load_backup();
304         return 1;
305 }
306
307
308
309
310