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