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"
37 #include "mwindowgui.h"
44 Load::Load(MWindow *mwindow, MainMenu *mainmenu)
45 : BC_MenuItem(_("Load files..."), "o", 'o')
47 this->mwindow = mwindow;
48 this->mainmenu = mainmenu;
56 void Load::create_objects()
58 thread = new LoadFileThread(mwindow, this);
61 int Load::handle_event()
63 mwindow->gui->unlock_window();
65 mwindow->gui->lock_window("Load::handle_event");
74 LoadFileThread::LoadFileThread(MWindow *mwindow, Load *load)
77 this->mwindow = mwindow;
81 LoadFileThread::~LoadFileThread()
85 BC_Window* LoadFileThread::new_gui()
87 char default_path[BCTEXTLEN];
89 sprintf(default_path, "~");
90 mwindow->defaults->get("DEFAULT_LOADPATH", default_path);
91 load_mode = mwindow->defaults->get("LOAD_MODE", LOADMODE_REPLACE);
93 mwindow->gui->lock_window("LoadFileThread::new_gui");
94 window = new LoadFileWindow(mwindow, this, default_path);
95 mwindow->gui->unlock_window();
97 window->create_objects();
101 void LoadFileThread::handle_done_event(int result)
103 ArrayList<char*> path_list;
104 path_list.set_array_delete();
105 // Collect all selected files
108 char *in_path, *out_path;
110 window->lock_window("LoadFileThread::handle_done_event");
111 window->hide_window();
112 window->unlock_window();
114 while((in_path = window->get_path(i)))
117 for(j = 0; j < path_list.total; j++)
119 if(!strcmp(in_path, path_list.values[j])) break;
122 if(j == path_list.total)
124 path_list.append(out_path = new char[strlen(in_path) + 1]);
125 strcpy(out_path, in_path);
131 mwindow->defaults->update("DEFAULT_LOADPATH",
132 window->get_submitted_path());
133 mwindow->defaults->update("LOAD_MODE",
137 if(path_list.total == 0 || result == 1)
142 mwindow->interrupt_indexes();
143 mwindow->gui->lock_window("LoadFileThread::run");
144 result = mwindow->load_filenames(&path_list, load_mode);
145 mwindow->gui->mainmenu->add_load(path_list.values[0]);
146 mwindow->gui->unlock_window();
147 path_list.remove_all_objects();
150 mwindow->save_backup();
152 mwindow->restart_brender();
165 LoadFileWindow::LoadFileWindow(MWindow *mwindow,
166 LoadFileThread *thread,
167 char *init_directory)
168 : BC_FileBox(mwindow->gui->get_abs_cursor_x(1),
169 mwindow->gui->get_abs_cursor_y(1) -
170 BC_WindowBase::get_resources()->filebox_h / 2,
172 PROGRAM_NAME ": Load",
173 _("Select files to load:"),
177 mwindow->theme->loadfile_pad)
179 this->thread = thread;
180 this->mwindow = mwindow;
183 LoadFileWindow::~LoadFileWindow()
185 lock_window("LoadFileWindow::~LoadFileWindow");
190 void LoadFileWindow::create_objects()
192 lock_window("LoadFileWindow::create_objects");
193 BC_FileBox::create_objects();
195 int x = get_w() / 2 -
196 LoadMode::calculate_w(this, mwindow->theme, 0, 1) / 2;
197 int y = get_cancel_button()->get_y() -
198 LoadMode::calculate_h(this, mwindow->theme);
199 loadmode = new LoadMode(mwindow, this, x, y, &thread->load_mode, 0, 1);
200 loadmode->create_objects();
206 int LoadFileWindow::resize_event(int w, int h)
209 int y = get_cancel_button()->get_y() -
210 LoadMode::calculate_h(this, mwindow->theme);
211 draw_background(0, 0, w, h);
213 loadmode->reposition_window(x, y);
215 return BC_FileBox::resize_event(w, h);
230 LocateFileWindow::LocateFileWindow(MWindow *mwindow,
231 char *init_directory,
233 : BC_FileBox(mwindow->gui->get_abs_cursor_x(1),
234 mwindow->gui->get_abs_cursor_y(1),
236 PROGRAM_NAME ": Locate file",
239 this->mwindow = mwindow;
242 LocateFileWindow::~LocateFileWindow()
252 LoadPrevious::LoadPrevious(MWindow *mwindow, Load *loadfile)
253 : BC_MenuItem(""), Thread()
255 this->mwindow = mwindow;
256 this->loadfile = loadfile;
259 int LoadPrevious::handle_event()
261 ArrayList<char*> path_list;
262 path_list.set_array_delete();
264 int load_mode = mwindow->defaults->get("LOAD_MODE", LOADMODE_REPLACE);
267 path_list.append(out_path = new char[strlen(path) + 1]);
268 strcpy(out_path, path);
270 mwindow->load_filenames(&path_list, LOADMODE_REPLACE);
271 mwindow->gui->mainmenu->add_load(path_list.values[0]);
272 path_list.remove_all_objects();
275 mwindow->defaults->update("LOAD_MODE", load_mode);
276 mwindow->save_backup();
282 void LoadPrevious::run()
284 // loadfile->mwindow->load(path, loadfile->append);
287 int LoadPrevious::set_path(char *path)
289 strcpy(this->path, path);
295 LoadBackup::LoadBackup(MWindow *mwindow)
296 : BC_MenuItem(_("Load backup"))
298 this->mwindow = mwindow;
301 int LoadBackup::handle_event()
303 mwindow->load_backup();