4 * Copyright (C) 2009 Adam Williams <broadcast at earthling dot net>
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.
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.
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
23 #include "bcsignals.h"
28 #include "filesystem.h"
29 #include "indexfile.h"
33 #include "localsession.h"
36 #include "mainsession.h"
38 #include "mwindowgui.h"
39 #include "preferences.h"
46 Load::Load(MWindow *mwindow, MainMenu *mainmenu)
47 : BC_MenuItem(_("Load files..."), "o", 'o')
49 this->mwindow = mwindow;
50 this->mainmenu = mainmenu;
59 void Load::create_objects()
61 thread = new LoadFileThread(mwindow, this);
64 int Load::handle_event()
66 mwindow->gui->unlock_window();
68 mwindow->gui->lock_window("Load::handle_event");
77 LoadFileThread::LoadFileThread(MWindow *mwindow, Load *load)
80 this->mwindow = mwindow;
83 load_mode = LOADMODE_REPLACE;
84 edl_mode = LOADMODE_EDL_CLIP;
87 LoadFileThread::~LoadFileThread()
92 BC_Window* LoadFileThread::new_gui()
94 char default_path[BCTEXTLEN];
96 sprintf(default_path, "~");
97 mwindow->defaults->get("DEFAULT_LOADPATH", default_path);
98 load_mode = mwindow->defaults->get("LOAD_MODE", load_mode);
100 mwindow->gui->lock_window("LoadFileThread::new_gui");
101 window = new LoadFileWindow(mwindow, this, default_path);
102 mwindow->gui->unlock_window();
104 window->create_objects();
108 void LoadFileThread::handle_done_event(int result)
110 window->lock_window("LoadFileThread::handle_done_event");
111 window->hide_window();
112 window->unlock_window();
114 if( !result ) load_apply();
117 void LoadFileThread::load_apply()
119 mwindow->defaults->update("DEFAULT_LOADPATH", window->get_submitted_path());
120 mwindow->defaults->update("LOAD_MODE", load_mode);
121 if( edl_mode == LOADMODE_EDL_FILEREF )
122 mwindow->show_warning(
123 &mwindow->preferences->warn_fileref,
124 _("Other projects can change this project"));
125 ArrayList<char*> path_list;
126 path_list.set_array_delete();
128 // Collect all selected files
130 for( int i=0; (in_path = window->get_path(i))!=0; ++i ) {
131 int k = path_list.size();
132 while( --k >= 0 && strcmp(in_path, path_list.values[k]) );
133 if( k < 0 ) path_list.append(cstrdup(in_path));
137 if( !path_list.size() ) return;
139 if( load_mode == LOADMODE_REPLACE )
140 mwindow->set_filename(path_list[0]);
142 mwindow->interrupt_indexes();
143 mwindow->gui->lock_window("LoadFileThread::run");
144 mwindow->load_filenames(&path_list, load_mode, edl_mode, 0);
145 mwindow->gui->mainmenu->add_load(path_list.values[0]);
146 mwindow->gui->unlock_window();
147 path_list.remove_all_objects();
149 mwindow->save_backup();
151 mwindow->restart_brender();
153 if( load_mode == LOADMODE_REPLACE ||
154 load_mode == LOADMODE_REPLACE_CONCATENATE )
155 mwindow->session->changes_made = 0;
157 mwindow->session->changes_made = 1;
161 LoadFileWindow::LoadFileWindow(MWindow *mwindow,
162 LoadFileThread *thread,
163 char *init_directory)
164 : BC_FileBox(mwindow->gui->get_abs_cursor_x(1),
165 mwindow->gui->get_abs_cursor_y(1) -
166 BC_WindowBase::get_resources()->filebox_h / 2,
168 _(PROGRAM_NAME ": Load"),
169 _("Select files to load:"),
173 mwindow->theme->loadfile_pad)
175 this->thread = thread;
176 this->mwindow = mwindow;
179 LoadFileWindow::~LoadFileWindow()
181 lock_window("LoadFileWindow::~LoadFileWindow");
186 void LoadFileWindow::create_objects()
188 lock_window("LoadFileWindow::create_objects");
189 BC_FileBox::create_objects();
191 int x = get_w() / 2 - LoadMode::calculate_w(this, mwindow->theme) / 2;
192 int y = get_y_margin();
193 // always start as clip to match historical behavior
194 thread->edl_mode = LOADMODE_EDL_CLIP;
195 loadmode = new LoadMode(mwindow, this, x, y,
196 &thread->load_mode, &thread->edl_mode, 0, 1);
197 loadmode->create_objects();
198 const char *apply = _("Apply");
199 x = 3*get_w()/4 - BC_GenericButton::calculate_w(this, apply)/2;
200 y = get_h() - BC_CancelButton::calculate_h() - yS(16);
201 add_subwindow(load_file_apply = new LoadFileApply(this, x, y, apply));
208 int LoadFileWindow::resize_event(int w, int h)
210 draw_background(0, 0, w, h);
211 BC_FileBox::resize_event(w, h);
212 int x = w / 2 - LoadMode::calculate_w(this, mwindow->theme) / 2;
213 int y = get_y_margin();
214 loadmode->reposition_window(x, y);
215 const char *apply = load_file_apply->get_text();
216 x = 3*get_w()/4 - BC_GenericButton::calculate_w(this, apply)/2;
217 y = get_h() - BC_CancelButton::calculate_h() - yS(16);
218 load_file_apply->reposition_window(x, y);
224 LoadFileApply::LoadFileApply(LoadFileWindow *load_file_window,
225 int x, int y, const char *text)
226 : BC_GenericButton(x, y, text)
228 this->load_file_window = load_file_window;
231 int LoadFileApply::handle_event()
233 load_file_window->thread->load_apply();
238 LocateFileWindow::LocateFileWindow(MWindow *mwindow,
239 char *init_directory,
241 : BC_FileBox(mwindow->gui->get_abs_cursor_x(1),
242 mwindow->gui->get_abs_cursor_y(1),
244 _(PROGRAM_NAME ": Locate file"),
247 this->mwindow = mwindow;
250 LocateFileWindow::~LocateFileWindow()
260 LoadPrevious::LoadPrevious(MWindow *mwindow, Load *loadfile)
263 this->mwindow = mwindow;
264 this->loadfile = loadfile;
267 int LoadPrevious::handle_event()
269 if( !path[0] ) return 1;
270 ArrayList<char*> path_list;
271 path_list.set_array_delete();
273 int load_mode = mwindow->defaults->get("LOAD_MODE", LOADMODE_REPLACE);
275 path_list.append(out_path = new char[strlen(path) + 1]);
276 strcpy(out_path, path);
278 mwindow->load_filenames(&path_list, LOADMODE_REPLACE);
279 mwindow->gui->mainmenu->add_load(path_list.values[0]);
280 path_list.remove_all_objects();
282 mwindow->defaults->update("LOAD_MODE", load_mode);
283 mwindow->save_backup();
284 mwindow->session->changes_made = 0;
288 int LoadPrevious::set_path(const char *path)
290 strcpy(this->path, path);
296 LoadBackup::LoadBackup(MWindow *mwindow)
297 : BC_MenuItem(_("Load backup"))
299 this->mwindow = mwindow;
302 int LoadBackup::handle_event()
304 mwindow->load_backup();
305 mwindow->session->changes_made = 1;