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()
86 BC_Window* LoadFileThread::new_gui()
88 char default_path[BCTEXTLEN];
90 sprintf(default_path, "~");
91 mwindow->defaults->get("DEFAULT_LOADPATH", default_path);
92 load_mode = mwindow->defaults->get("LOAD_MODE", LOADMODE_REPLACE);
94 mwindow->gui->lock_window("LoadFileThread::new_gui");
95 window = new LoadFileWindow(mwindow, this, default_path);
96 mwindow->gui->unlock_window();
98 window->create_objects();
102 void LoadFileThread::handle_done_event(int result)
104 ArrayList<char*> path_list;
105 path_list.set_array_delete();
106 // Collect all selected files
109 char *in_path, *out_path;
111 window->lock_window("LoadFileThread::handle_done_event");
112 window->hide_window();
113 window->unlock_window();
115 while((in_path = window->get_path(i)))
118 for(j = 0; j < path_list.total; j++)
120 if(!strcmp(in_path, path_list.values[j])) break;
123 if(j == path_list.total)
125 path_list.append(out_path = new char[strlen(in_path) + 1]);
126 strcpy(out_path, in_path);
132 mwindow->defaults->update("DEFAULT_LOADPATH",
133 window->get_submitted_path());
134 mwindow->defaults->update("LOAD_MODE",
138 if(path_list.total == 0 || result == 1)
143 mwindow->interrupt_indexes();
144 mwindow->gui->lock_window("LoadFileThread::run");
145 result = mwindow->load_filenames(&path_list, load_mode);
146 mwindow->gui->mainmenu->add_load(path_list.values[0]);
147 mwindow->gui->unlock_window();
148 path_list.remove_all_objects();
151 mwindow->save_backup();
153 mwindow->restart_brender();
166 LoadFileWindow::LoadFileWindow(MWindow *mwindow,
167 LoadFileThread *thread,
168 char *init_directory)
169 : BC_FileBox(mwindow->gui->get_abs_cursor_x(1),
170 mwindow->gui->get_abs_cursor_y(1) -
171 BC_WindowBase::get_resources()->filebox_h / 2,
173 _(PROGRAM_NAME ": Load"),
174 _("Select files to load:"),
178 mwindow->theme->loadfile_pad)
180 this->thread = thread;
181 this->mwindow = mwindow;
184 LoadFileWindow::~LoadFileWindow()
186 lock_window("LoadFileWindow::~LoadFileWindow");
191 void LoadFileWindow::create_objects()
193 lock_window("LoadFileWindow::create_objects");
194 BC_FileBox::create_objects();
196 int x = get_w() / 2 -
197 LoadMode::calculate_w(this, mwindow->theme, 0, 1) / 2;
198 int y = get_cancel_button()->get_y() -
199 LoadMode::calculate_h(this, mwindow->theme);
200 loadmode = new LoadMode(mwindow, this, x, y, &thread->load_mode, 0, 1);
201 loadmode->create_objects();
207 int LoadFileWindow::resize_event(int w, int h)
210 int y = get_cancel_button()->get_y() -
211 LoadMode::calculate_h(this, mwindow->theme);
212 draw_background(0, 0, w, h);
214 loadmode->reposition_window(x, y);
216 return BC_FileBox::resize_event(w, h);
231 LocateFileWindow::LocateFileWindow(MWindow *mwindow,
232 char *init_directory,
234 : BC_FileBox(mwindow->gui->get_abs_cursor_x(1),
235 mwindow->gui->get_abs_cursor_y(1),
237 _(PROGRAM_NAME ": Locate file"),
240 this->mwindow = mwindow;
243 LocateFileWindow::~LocateFileWindow()
253 LoadPrevious::LoadPrevious(MWindow *mwindow, Load *loadfile)
254 : BC_MenuItem(""), Thread()
256 this->mwindow = mwindow;
257 this->loadfile = loadfile;
260 int LoadPrevious::handle_event()
262 ArrayList<char*> path_list;
263 path_list.set_array_delete();
265 int load_mode = mwindow->defaults->get("LOAD_MODE", LOADMODE_REPLACE);
268 path_list.append(out_path = new char[strlen(path) + 1]);
269 strcpy(out_path, path);
271 mwindow->load_filenames(&path_list, LOADMODE_REPLACE);
272 mwindow->gui->mainmenu->add_load(path_list.values[0]);
273 path_list.remove_all_objects();
276 mwindow->defaults->update("LOAD_MODE", load_mode);
277 mwindow->save_backup();
283 void LoadPrevious::run()
285 // loadfile->mwindow->load(path, loadfile->append);
288 int LoadPrevious::set_path(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();