change copy packed clip to unpacked in move_edits
[goodguy/cinelerra.git] / cinelerra-5.1 / 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 "mainsession.h"
37 #include "mwindow.h"
38 #include "mwindowgui.h"
39 #include "theme.h"
40
41
42
43 #include <string.h>
44
45 Load::Load(MWindow *mwindow, MainMenu *mainmenu)
46  : BC_MenuItem(_("Load files..."), "o", 'o')
47 {
48         this->mwindow = mwindow;
49         this->mainmenu = mainmenu;
50 }
51
52 Load::~Load()
53 {
54         delete thread;
55 }
56
57 void Load::create_objects()
58 {
59         thread = new LoadFileThread(mwindow, this);
60 }
61
62 int Load::handle_event()
63 {
64         mwindow->gui->unlock_window();
65         thread->start();
66         mwindow->gui->lock_window("Load::handle_event");
67         return 1;
68 }
69
70
71
72
73
74
75 LoadFileThread::LoadFileThread(MWindow *mwindow, Load *load)
76  : BC_DialogThread()
77 {
78         this->mwindow = mwindow;
79         this->load = load;
80 }
81
82 LoadFileThread::~LoadFileThread()
83 {
84         close_window();
85 }
86
87 BC_Window* LoadFileThread::new_gui()
88 {
89         char default_path[BCTEXTLEN];
90
91         sprintf(default_path, "~");
92         mwindow->defaults->get("DEFAULT_LOADPATH", default_path);
93         load_mode = mwindow->defaults->get("LOAD_MODE", LOADMODE_REPLACE);
94
95         mwindow->gui->lock_window("LoadFileThread::new_gui");
96         window = new LoadFileWindow(mwindow, this, default_path);
97         mwindow->gui->unlock_window();
98
99         window->create_objects();
100         return window;
101 }
102
103 void LoadFileThread::handle_done_event(int result)
104 {
105         window->lock_window("LoadFileThread::handle_done_event");
106         window->hide_window();
107         window->unlock_window();
108
109         if( !result ) load_apply();
110 }
111
112 void LoadFileThread::load_apply()
113 {
114         mwindow->defaults->update("DEFAULT_LOADPATH",
115                 window->get_submitted_path());
116         mwindow->defaults->update("LOAD_MODE",
117                 load_mode);
118
119         ArrayList<char*> path_list;
120         path_list.set_array_delete();
121
122 // Collect all selected files
123         char *in_path;
124         for( int i=0; (in_path = window->get_path(i))!=0; ++i ) {
125                 int k = path_list.size();
126                 while( --k >= 0 && strcmp(in_path, path_list.values[k]) );
127                 if( k < 0 ) path_list.append(cstrdup(in_path));
128         }
129
130 // No file selected
131         if( !path_list.size() ) return;
132
133         if( load_mode == LOADMODE_REPLACE )
134                 mwindow->set_filename(path_list[0]);
135
136         mwindow->interrupt_indexes();
137         mwindow->gui->lock_window("LoadFileThread::run");
138         mwindow->load_filenames(&path_list, load_mode, 0);
139         mwindow->gui->mainmenu->add_load(path_list.values[0]);
140         mwindow->gui->unlock_window();
141         path_list.remove_all_objects();
142
143         mwindow->save_backup();
144
145         mwindow->restart_brender();
146
147         if(load_mode == LOADMODE_REPLACE || load_mode == LOADMODE_REPLACE_CONCATENATE)
148                 mwindow->session->changes_made = 0;
149         else
150                 mwindow->session->changes_made = 1;
151 }
152
153
154 LoadFileWindow::LoadFileWindow(MWindow *mwindow,
155         LoadFileThread *thread,
156         char *init_directory)
157  : BC_FileBox(mwindow->gui->get_abs_cursor_x(1),
158                 mwindow->gui->get_abs_cursor_y(1) -
159                         BC_WindowBase::get_resources()->filebox_h / 2,
160                 init_directory,
161                 _(PROGRAM_NAME ": Load"),
162                 _("Select files to load:"),
163                 0,
164                 0,
165                 1,
166                 mwindow->theme->loadfile_pad)
167 {
168         this->thread = thread;
169         this->mwindow = mwindow;
170 }
171
172 LoadFileWindow::~LoadFileWindow()
173 {
174         lock_window("LoadFileWindow::~LoadFileWindow");
175         delete loadmode;
176         unlock_window();
177 }
178
179 void LoadFileWindow::create_objects()
180 {
181         lock_window("LoadFileWindow::create_objects");
182         BC_FileBox::create_objects();
183
184         int x = get_w() / 2 -
185                 LoadMode::calculate_w(this, mwindow->theme) / 2;
186         int y = get_cancel_button()->get_y() -
187                 LoadMode::calculate_h(this, mwindow->theme);
188         loadmode = new LoadMode(mwindow, this, x, y, &thread->load_mode, 0);
189         loadmode->create_objects();
190         add_subwindow(load_file_apply = new LoadFileApply(this));
191
192         show_window(1);
193         unlock_window();
194
195 }
196
197 int LoadFileWindow::resize_event(int w, int h)
198 {
199         draw_background(0, 0, w, h);
200         int x = w / 2 - 200;
201         int y = get_cancel_button()->get_y() -
202                 LoadMode::calculate_h(this, mwindow->theme);
203         loadmode->reposition_window(x, y);
204
205         x = (w - BC_GenericButton::calculate_w(this, _("Apply")))/2;
206         y = h - BC_GenericButton::calculate_h() - 15;
207         load_file_apply->reposition_window(x, y);
208
209         return BC_FileBox::resize_event(w, h);
210 }
211
212
213 LoadFileApply::LoadFileApply(LoadFileWindow *load_file_window)
214  : BC_GenericButton( (load_file_window->get_w() -
215                 BC_GenericButton::calculate_w(load_file_window, _("Apply")))/2,
216         load_file_window->get_h() - BC_GenericButton::calculate_h() - 15,
217         _("Apply"))
218 {
219         this->load_file_window = load_file_window;
220 }
221
222 int LoadFileApply::handle_event()
223 {
224         load_file_window->thread->load_apply();
225         return 1;
226 }
227
228
229 LocateFileWindow::LocateFileWindow(MWindow *mwindow,
230         char *init_directory,
231         char *old_filename)
232  : BC_FileBox(mwindow->gui->get_abs_cursor_x(1),
233                 mwindow->gui->get_abs_cursor_y(1),
234                 init_directory,
235                 _(PROGRAM_NAME ": Locate file"),
236                 old_filename)
237 {
238         this->mwindow = mwindow;
239 }
240
241 LocateFileWindow::~LocateFileWindow()
242 {
243 }
244
245
246
247
248
249
250
251 LoadPrevious::LoadPrevious(MWindow *mwindow, Load *loadfile)
252  : BC_MenuItem(""), Thread()
253 {
254         this->mwindow = mwindow;
255         this->loadfile = loadfile;
256 }
257
258 int LoadPrevious::handle_event()
259 {
260         ArrayList<char*> path_list;
261         path_list.set_array_delete();
262         char *out_path;
263         int load_mode = mwindow->defaults->get("LOAD_MODE", LOADMODE_REPLACE);
264
265         path_list.append(out_path = new char[strlen(path) + 1]);
266         strcpy(out_path, path);
267
268         mwindow->load_filenames(&path_list, LOADMODE_REPLACE);
269         mwindow->gui->mainmenu->add_load(path_list.values[0]);
270         path_list.remove_all_objects();
271
272         mwindow->defaults->update("LOAD_MODE", load_mode);
273         mwindow->save_backup();
274         mwindow->session->changes_made = 0;
275         return 1;
276 }
277
278
279
280 void LoadPrevious::run()
281 {
282 //      loadfile->mwindow->load(path, loadfile->append);
283 }
284
285 int LoadPrevious::set_path(char *path)
286 {
287         strcpy(this->path, path);
288         return 0;
289 }
290
291
292
293 LoadBackup::LoadBackup(MWindow *mwindow)
294  : BC_MenuItem(_("Load backup"))
295 {
296         this->mwindow = mwindow;
297 }
298
299 int LoadBackup::handle_event()
300 {
301         mwindow->load_backup();
302         mwindow->session->changes_made = 1;
303         return 1;
304 }
305
306