prevent popup deactivation while button_down
[goodguy/history.git] / cinelerra-5.0 / 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 "mwindow.h"
37 #include "mwindowgui.h"
38 #include "theme.h"
39
40
41
42 #include <string.h>
43
44 Load::Load(MWindow *mwindow, MainMenu *mainmenu)
45  : BC_MenuItem(_("Load files..."), "o", 'o')
46
47         this->mwindow = mwindow;
48         this->mainmenu = mainmenu;
49 }
50
51 Load::~Load()
52 {
53         delete thread;
54 }
55
56 void Load::create_objects()
57 {
58         thread = new LoadFileThread(mwindow, this);
59 }
60
61 int Load::handle_event() 
62 {
63         mwindow->gui->unlock_window();
64         thread->start();
65         mwindow->gui->lock_window("Load::handle_event");
66         return 1;
67 }
68
69
70
71
72
73
74 LoadFileThread::LoadFileThread(MWindow *mwindow, Load *load)
75  : BC_DialogThread()
76 {
77         this->mwindow = mwindow;
78         this->load = load;
79 }
80
81 LoadFileThread::~LoadFileThread()
82 {
83         close_window();
84 }
85
86 BC_Window* LoadFileThread::new_gui()
87 {
88         char default_path[BCTEXTLEN];
89
90         sprintf(default_path, "~");
91         mwindow->defaults->get("DEFAULT_LOADPATH", default_path);
92         load_mode = mwindow->defaults->get("LOAD_MODE", LOADMODE_REPLACE);
93
94         mwindow->gui->lock_window("LoadFileThread::new_gui");
95         window = new LoadFileWindow(mwindow, this, default_path);
96         mwindow->gui->unlock_window();
97         
98         window->create_objects();
99         return window;
100 }
101
102 void LoadFileThread::handle_done_event(int result)
103 {
104         ArrayList<char*> path_list;
105         path_list.set_array_delete();
106 // Collect all selected files
107         if(!result)
108         {
109                 char *in_path, *out_path;
110                 int i = 0;
111                 window->lock_window("LoadFileThread::handle_done_event");
112                 window->hide_window();
113                 window->unlock_window();
114
115                 while((in_path = window->get_path(i)))
116                 {
117                         int j;
118                         for(j = 0; j < path_list.total; j++)
119                         {
120                                 if(!strcmp(in_path, path_list.values[j])) break;
121                         }
122
123                         if(j == path_list.total)
124                         {
125                                 path_list.append(out_path = new char[strlen(in_path) + 1]);
126                                 strcpy(out_path, in_path);
127                         }
128                         i++;
129                 }
130         }
131
132         mwindow->defaults->update("DEFAULT_LOADPATH", 
133                 window->get_submitted_path());
134         mwindow->defaults->update("LOAD_MODE", 
135                 load_mode);
136
137 // No file selected
138         if(path_list.total == 0 || result == 1)
139         {
140                 return;
141         }
142
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();
149
150
151         mwindow->save_backup();
152
153         mwindow->restart_brender();
154 }
155
156
157
158
159
160
161
162
163
164
165
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,
172                 init_directory, 
173                 _(PROGRAM_NAME ": Load"),
174                 _("Select files to load:"), 
175                 0,
176                 0,
177                 1,
178                 mwindow->theme->loadfile_pad)
179 {
180         this->thread = thread;
181         this->mwindow = mwindow; 
182 }
183
184 LoadFileWindow::~LoadFileWindow() 
185 {
186         lock_window("LoadFileWindow::~LoadFileWindow");
187         delete loadmode;
188         unlock_window();
189 }
190
191 void LoadFileWindow::create_objects()
192 {
193         lock_window("LoadFileWindow::create_objects");
194         BC_FileBox::create_objects();
195
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();
202         show_window(1);
203         unlock_window();
204
205 }
206
207 int LoadFileWindow::resize_event(int w, int h)
208 {
209         int x = w / 2 - 200;
210         int y = get_cancel_button()->get_y() - 
211                 LoadMode::calculate_h(this, mwindow->theme);
212         draw_background(0, 0, w, h);
213
214         loadmode->reposition_window(x, y);
215
216         return BC_FileBox::resize_event(w, h);
217 }
218
219
220
221
222
223
224
225
226
227
228
229
230
231 LocateFileWindow::LocateFileWindow(MWindow *mwindow, 
232         char *init_directory, 
233         char *old_filename)
234  : BC_FileBox(mwindow->gui->get_abs_cursor_x(1),
235                 mwindow->gui->get_abs_cursor_y(1), 
236                 init_directory, 
237                 _(PROGRAM_NAME ": Locate file"), 
238                 old_filename)
239
240         this->mwindow = mwindow; 
241 }
242
243 LocateFileWindow::~LocateFileWindow()
244 {
245 }
246
247
248
249
250
251
252
253 LoadPrevious::LoadPrevious(MWindow *mwindow, Load *loadfile)
254  : BC_MenuItem(""), Thread()
255
256         this->mwindow = mwindow;
257         this->loadfile = loadfile; 
258 }
259
260 int LoadPrevious::handle_event()
261 {
262         ArrayList<char*> path_list;
263         path_list.set_array_delete();
264         char *out_path;
265         int load_mode = mwindow->defaults->get("LOAD_MODE", LOADMODE_REPLACE);
266
267
268         path_list.append(out_path = new char[strlen(path) + 1]);
269         strcpy(out_path, path);
270
271         mwindow->load_filenames(&path_list, LOADMODE_REPLACE);
272         mwindow->gui->mainmenu->add_load(path_list.values[0]);
273         path_list.remove_all_objects();
274
275
276         mwindow->defaults->update("LOAD_MODE", load_mode);
277         mwindow->save_backup();
278         return 1;
279 }
280
281
282
283 void LoadPrevious::run()
284 {
285 //      loadfile->mwindow->load(path, loadfile->append);
286 }
287
288 int LoadPrevious::set_path(char *path)
289 {
290         strcpy(this->path, path);
291         return 0;
292 }
293
294
295
296 LoadBackup::LoadBackup(MWindow *mwindow)
297  : BC_MenuItem(_("Load backup"))
298 {
299         this->mwindow = mwindow;
300 }
301
302 int LoadBackup::handle_event()
303 {
304         mwindow->load_backup();
305         return 1;
306 }
307
308
309
310
311