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