4 * Copyright (C) 2009 Adam Williams <broadcast at earthling dot net>
5 * Copyright (C) 2003-2016 Cinelerra CV contributors
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "bcsignals.h"
29 #include "filesystem.h"
30 #include "indexfile.h"
34 #include "localsession.h"
37 #include "mainsession.h"
39 #include "mwindowgui.h"
40 #include "preferences.h"
47 Load::Load(MWindow *mwindow, MainMenu *mainmenu)
48 : BC_MenuItem(_("Load files..."), "o", 'o')
50 this->mwindow = mwindow;
51 this->mainmenu = mainmenu;
60 void Load::create_objects()
62 thread = new LoadFileThread(mwindow, this);
65 int Load::handle_event()
67 mwindow->gui->unlock_window();
69 mwindow->gui->lock_window("Load::handle_event");
78 LoadFileThread::LoadFileThread(MWindow *mwindow, Load *load)
81 this->mwindow = mwindow;
84 load_mode = LOADMODE_RESOURCESONLY;
85 edl_mode = LOADMODE_EDL_CLIP;
88 LoadFileThread::~LoadFileThread()
93 BC_Window* LoadFileThread::new_gui()
95 char default_path[BCTEXTLEN];
97 sprintf(default_path, "~");
98 mwindow->defaults->get("DEFAULT_LOADPATH", default_path);
99 load_mode = mwindow->defaults->get("LOAD_MODE", load_mode);
101 mwindow->gui->lock_window("LoadFileThread::new_gui");
102 window = new LoadFileWindow(mwindow, this, default_path);
103 mwindow->gui->unlock_window();
105 window->create_objects();
109 void LoadFileThread::handle_done_event(int result)
111 window->lock_window("LoadFileThread::handle_done_event");
112 window->hide_window();
113 window->unlock_window();
115 if( !result ) load_apply();
118 void LoadFileThread::load_apply()
120 mwindow->defaults->update("DEFAULT_LOADPATH", window->get_submitted_path());
121 mwindow->defaults->update("LOAD_MODE", load_mode);
122 if( edl_mode == LOADMODE_EDL_FILEREF )
123 mwindow->show_warning(
124 &mwindow->preferences->warn_fileref,
125 _("Other projects can change this project\n"
126 "and this can become a broken link"));
127 ArrayList<char*> path_list;
128 path_list.set_array_delete();
130 // Collect all selected files
132 for( int i=0; (in_path = window->get_path(i))!=0; ++i ) {
133 int k = path_list.size();
134 while( --k >= 0 && strcmp(in_path, path_list.values[k]) );
135 if( k < 0 ) path_list.append(cstrdup(in_path));
139 if( !path_list.size() ) return;
140 int replaced = load_mode == LOADMODE_REPLACE ||
141 load_mode == LOADMODE_REPLACE_CONCATENATE ? 1 : 0;
143 mwindow->interrupt_indexes();
144 mwindow->gui->lock_window("LoadFileThread::run");
145 mwindow->load_filenames(&path_list, load_mode, edl_mode, replaced);
146 mwindow->gui->mainmenu->add_load(path_list.values[0]);
147 mwindow->gui->unlock_window();
148 path_list.remove_all_objects();
150 mwindow->save_backup();
151 mwindow->restart_brender();
152 mwindow->session->changes_made = !replaced ? 1 : 0;
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,
163 _(PROGRAM_NAME ": Load"),
164 _("Select files to load:"),
168 mwindow->theme->loadfile_pad)
170 this->thread = thread;
171 this->mwindow = mwindow;
172 // *** CONTEXT_HELP ***
173 context_help_set_keyword("Loading Files");
176 LoadFileWindow::~LoadFileWindow()
178 lock_window("LoadFileWindow::~LoadFileWindow");
183 void LoadFileWindow::create_objects()
185 lock_window("LoadFileWindow::create_objects");
186 BC_FileBox::create_objects();
188 int x = get_w() / 2 - LoadMode::calculate_w(this, mwindow->theme) / 2;
189 int y = get_y_margin();
190 // always start as clip to match historical behavior
191 thread->edl_mode = LOADMODE_EDL_CLIP;
192 loadmode = new LoadMode(mwindow, this, x, y,
193 &thread->load_mode, &thread->edl_mode, 0, 1);
194 loadmode->create_objects();
195 const char *apply = _("Apply");
196 x = 3*get_w()/4 - BC_GenericButton::calculate_w(this, apply)/2;
197 y = get_h() - BC_CancelButton::calculate_h() - yS(16);
198 add_subwindow(load_file_apply = new LoadFileApply(this, x, y, apply));
205 int LoadFileWindow::resize_event(int w, int h)
207 draw_background(0, 0, w, h);
208 BC_FileBox::resize_event(w, h);
209 int x = w / 2 - LoadMode::calculate_w(this, mwindow->theme) / 2;
210 int y = get_y_margin();
211 loadmode->reposition_window(x, y);
212 const char *apply = load_file_apply->get_text();
213 x = 3*get_w()/4 - BC_GenericButton::calculate_w(this, apply)/2;
214 y = get_h() - BC_CancelButton::calculate_h() - yS(16);
215 load_file_apply->reposition_window(x, y);
221 LoadFileApply::LoadFileApply(LoadFileWindow *load_file_window,
222 int x, int y, const char *text)
223 : BC_GenericButton(x, y, text)
225 this->load_file_window = load_file_window;
228 int LoadFileApply::handle_event()
230 load_file_window->thread->load_apply();
235 LocateFileWindow::LocateFileWindow(MWindow *mwindow,
236 char *init_directory,
238 : BC_FileBox(mwindow->gui->get_abs_cursor_x(1),
239 mwindow->gui->get_abs_cursor_y(1),
241 _(PROGRAM_NAME ": Locate file"),
244 this->mwindow = mwindow;
247 LocateFileWindow::~LocateFileWindow()
257 LoadPrevious::LoadPrevious(MWindow *mwindow, Load *loadfile)
260 this->mwindow = mwindow;
261 this->loadfile = loadfile;
264 int LoadPrevious::handle_event()
266 if( !path[0] ) return 1;
267 ArrayList<char*> path_list;
268 path_list.set_array_delete();
270 int load_mode = mwindow->defaults->get("LOAD_MODE", LOADMODE_REPLACE);
272 path_list.append(out_path = new char[strlen(path) + 1]);
273 strcpy(out_path, path);
275 mwindow->load_filenames(&path_list, LOADMODE_REPLACE);
276 mwindow->gui->mainmenu->add_load(path_list.values[0]);
277 path_list.remove_all_objects();
279 mwindow->defaults->update("LOAD_MODE", load_mode);
280 mwindow->save_backup();
281 mwindow->session->changes_made = 0;
285 int LoadPrevious::set_path(const char *path)
287 strcpy(this->path, path);
293 LoadBackup::LoadBackup(MWindow *mwindow)
294 : BC_MenuItem(_("Load backup"))
296 this->mwindow = mwindow;
299 int LoadBackup::handle_event()
301 mwindow->load_backup();
302 mwindow->session->changes_made = 1;