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