no longer need ffmpeg patch0 which was for Termux
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / savefile.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 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 "confirmsave.h"
23 #include "bchash.h"
24 #include "bcrecentlist.h"
25 #include "edl.h"
26 #include "file.h"
27 #include "filexml.h"
28 #include "fileformat.h"
29 #include "indexfile.h"
30 #include "language.h"
31 #include "mainerror.h"
32 #include "mainmenu.h"
33 #include "mwindow.h"
34 #include "mwindowgui.h"
35 #include "playback3d.h"
36 #include "savefile.h"
37 #include "mainsession.h"
38
39 #include <string.h>
40
41
42 SaveBackup::SaveBackup(MWindow *mwindow)
43  : BC_MenuItem(_("Save backup"), "b", 'b')
44 {
45         this->mwindow = mwindow;
46 }
47 int SaveBackup::handle_event()
48 {
49         mwindow->save_backup();
50         mwindow->gui->show_message(_("Saved backup."));
51         return 1;
52 }
53
54
55 Save::Save(MWindow *mwindow) : BC_MenuItem(_("Save"), "s", 's')
56 {
57         this->mwindow = mwindow;
58         quit_now = 0;
59 }
60
61 void Save::create_objects(SaveAs *saveas)
62 {
63         this->saveas = saveas;
64 }
65
66 int Save::handle_event()
67 {
68         mwindow->gui->unlock_window();
69         int ret = mwindow->save(0);
70         mwindow->gui->lock_window("Save::handle_event");
71         if( !ret ) {
72                 mwindow->session->changes_made = 0;
73 // Last command in program
74                 if( saveas->quit_now )
75                         mwindow->quit();
76         }
77         return 1;
78 }
79
80 int Save::save_before_quit()
81 {
82         mwindow->gui->lock_window("Save::save_before_quit");
83         saveas->quit_now = 1;
84         handle_event();
85         mwindow->gui->unlock_window();
86         return 0;
87 }
88
89 SaveAs::SaveAs(MWindow *mwindow)
90  : BC_MenuItem(_("Save as..."), "Shift-S", 'S'), Thread()
91 {
92         set_shift(1);
93         this->mwindow = mwindow;
94         quit_now = 0;
95 }
96
97 int SaveAs::set_mainmenu(MainMenu *mmenu)
98 {
99         this->mmenu = mmenu;
100         return 0;
101 }
102
103 int SaveAs::handle_event()
104 {
105         quit_now = 0;
106         start();
107         return 1;
108 }
109
110 void SaveAs::run()
111 {
112         if( mwindow->save(1) )
113                 return;
114         mwindow->session->changes_made = 0;
115         if( quit_now )
116                 mwindow->quit();
117         return;
118 }
119
120
121 int SaveProjectModeItem::handle_event()
122 {
123         ((SaveProjectMode *)get_popup_menu())->update(id);
124         return 1;
125 }
126
127 SaveProjectMode::SaveProjectMode(SaveProjectWindow *gui, int x, int y)
128  : BC_PopupMenu(x, y, xS(100), "")
129 {
130         this->gui = gui;
131         save_modes[SAVE_PROJECT_COPY]     = _("Copy");
132         save_modes[SAVE_PROJECT_SYMLINK]  = _("SymLink");
133         save_modes[SAVE_PROJECT_RELLINK]  = _("RelLink");
134 }
135
136 SaveProjectMode::~SaveProjectMode()
137 {
138 }
139
140 void SaveProjectMode::create_objects()
141 {
142         add_item(new SaveProjectModeItem(save_modes[SAVE_PROJECT_COPY],    SAVE_PROJECT_COPY));
143         add_item(new SaveProjectModeItem(save_modes[SAVE_PROJECT_SYMLINK], SAVE_PROJECT_SYMLINK));
144         add_item(new SaveProjectModeItem(save_modes[SAVE_PROJECT_RELLINK], SAVE_PROJECT_RELLINK));
145         set_text(save_modes[gui->save_mode]);
146 }
147
148 void SaveProjectMode::update(int mode)
149 {
150         if( gui->save_mode == mode ) return;
151         set_text(save_modes[gui->save_mode = mode]);
152 }
153
154 SaveProjectTextBox::SaveProjectTextBox(SaveProjectWindow *gui, int x, int y, int w)
155  : BC_TextBox(x, y, w, 1, gui->dir_path)
156 {
157         this->gui = gui;
158 }
159 SaveProjectTextBox::~SaveProjectTextBox()
160 {
161 }
162
163 int SaveProjectTextBox::handle_event()
164 {
165         return 1;
166 }
167
168 SaveProjectWindow::SaveProjectWindow(MWindow *mwindow, const char *dir_path,
169                         int save_mode, int overwrite, int reload)
170  : BC_Window(_(PROGRAM_NAME ": Export Project"),
171                 mwindow->gui->get_abs_cursor_x(1),
172                 mwindow->gui->get_abs_cursor_y(1) -
173                         BC_WindowBase::get_resources()->filebox_h / 2,
174                 xS(540), yS(220), xS(540), yS(220), 0)
175 {
176         this->mwindow = mwindow;
177         strcpy(this->dir_path, dir_path);
178         this->overwrite = overwrite;
179         this->save_mode = save_mode;
180         this->reload = reload;
181 }
182 SaveProjectWindow::~SaveProjectWindow()
183 {
184 }
185
186 void SaveProjectWindow::create_objects()
187 {
188         int xs10 = xS(10), xs20 = xS(20);
189         int ys10 = yS(10), ys20 = yS(20);
190         int x = xs20, y = ys20, x1 = get_w()-xS(80);
191         BC_Title *title;
192         add_subwindow(title = new BC_Title(x, y, _("Project Directory:")));
193         y += title->get_h() + ys10;
194         add_subwindow(textbox = new SaveProjectTextBox(this, x, y, x1-x));
195         x1 += xs10;
196         add_subwindow(recent_project = new BC_RecentList("RECENT_PROJECT",
197                 mwindow->defaults, textbox, 10, x1, y, xS(300), yS(100)));
198         recent_project->load_items("RECENT_PROJECT");
199         x1 += recent_project->get_w() + xs10;
200         add_subwindow(browse_button = new BrowseButton(mwindow->theme, this,
201                 textbox, x1, y-yS(5), "", "", "", 1));
202         y += textbox->get_h() + ys20;
203         add_subwindow(mode_popup = new SaveProjectMode(this, x, y));
204         mode_popup->create_objects();
205         y += mode_popup->get_h() + ys10;
206         x1 = x;
207         BC_CheckBox *overwrite_files, *reload_project;
208         add_subwindow(overwrite_files = new BC_CheckBox(x1, y, &overwrite, _("Overwrite files")));
209         x1 += overwrite_files->get_w() + xs20;
210         add_subwindow(reload_project = new BC_CheckBox(x1, y, &reload, _("Reload project")));
211         add_subwindow(new BC_OKButton(this));
212         add_subwindow(new BC_CancelButton(this));
213         show_window(1);
214 }
215
216 SaveProject::SaveProject(MWindow *mwindow)
217  : BC_MenuItem(_("Export Project..."), "Alt-s", 's'), Thread()
218 {
219         set_alt(1);
220         this->mwindow = mwindow;
221 }
222
223 int SaveProject::handle_event()
224 {
225         start();
226         return 1;
227 }
228
229 void SaveProject::run()
230 {
231         char dir_path[1024];  sprintf(dir_path, "~");
232         mwindow->defaults->get("PROJECT_DIRECTORY", dir_path);
233         int reload = mwindow->defaults->get("PROJECT_RELOAD", 0);
234         int overwrite = mwindow->defaults->get("PROJECT_OVERWRITE", 0);
235         int save_mode = mwindow->defaults->get("PROJECT_SAVE_MODE", 0);
236
237         SaveProjectWindow window(mwindow, dir_path, save_mode, overwrite, reload);
238         window.lock_window("SaveProject::run");
239         window.create_objects();
240         window.unlock_window();
241         int result = window.run_window();
242         if( result ) return;
243
244         strcpy(dir_path, window.textbox->get_text());
245         window.recent_project->add_item("RECENT_PROJECT", dir_path);
246         reload = window.get_reload();
247         overwrite = window.get_overwrite();
248         save_mode = window.get_save_mode();
249         mwindow->defaults->update("PROJECT_DIRECTORY", dir_path);
250         mwindow->defaults->update("PROJECT_RELOAD", reload);
251         mwindow->defaults->update("PROJECT_OVERWRITE", overwrite);
252         mwindow->defaults->update("PROJECT_SAVE_MODE", save_mode);
253         mwindow->save_project(dir_path, save_mode, overwrite, reload);
254 }
255