Exciting new Alt/h help key provided by sge (Georgy) with many thanks!
[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 // *** CONTEXT_HELP ***
182         context_help_set_keyword("Export Project");
183 }
184 SaveProjectWindow::~SaveProjectWindow()
185 {
186 }
187
188 void SaveProjectWindow::create_objects()
189 {
190         int xs10 = xS(10), xs20 = xS(20);
191         int ys10 = yS(10), ys20 = yS(20);
192         int x = xs20, y = ys20, x1 = get_w()-xS(80);
193         BC_Title *title;
194         add_subwindow(title = new BC_Title(x, y, _("Project Directory:")));
195         y += title->get_h() + ys10;
196         add_subwindow(textbox = new SaveProjectTextBox(this, x, y, x1-x));
197         x1 += xs10;
198         add_subwindow(recent_project = new BC_RecentList("RECENT_PROJECT",
199                 mwindow->defaults, textbox, 10, x1, y, xS(300), yS(100)));
200         recent_project->load_items("RECENT_PROJECT");
201         x1 += recent_project->get_w() + xs10;
202         add_subwindow(browse_button = new BrowseButton(mwindow->theme, this,
203                 textbox, x1, y-yS(5), "", "", "", 1));
204         y += textbox->get_h() + ys20;
205         add_subwindow(mode_popup = new SaveProjectMode(this, x, y));
206         mode_popup->create_objects();
207         y += mode_popup->get_h() + ys10;
208         x1 = x;
209         BC_CheckBox *overwrite_files, *reload_project;
210         add_subwindow(overwrite_files = new BC_CheckBox(x1, y, &overwrite, _("Overwrite files")));
211         x1 += overwrite_files->get_w() + xs20;
212         add_subwindow(reload_project = new BC_CheckBox(x1, y, &reload, _("Reload project")));
213         add_subwindow(new BC_OKButton(this));
214         add_subwindow(new BC_CancelButton(this));
215         show_window(1);
216 }
217
218 SaveProject::SaveProject(MWindow *mwindow)
219  : BC_MenuItem(_("Export Project..."), "Alt-s", 's'), Thread()
220 {
221         set_alt(1);
222         this->mwindow = mwindow;
223 }
224
225 int SaveProject::handle_event()
226 {
227         start();
228         return 1;
229 }
230
231 void SaveProject::run()
232 {
233         char dir_path[1024];  sprintf(dir_path, "~");
234         mwindow->defaults->get("PROJECT_DIRECTORY", dir_path);
235         int reload = mwindow->defaults->get("PROJECT_RELOAD", 0);
236         int overwrite = mwindow->defaults->get("PROJECT_OVERWRITE", 0);
237         int save_mode = mwindow->defaults->get("PROJECT_SAVE_MODE", 0);
238
239         SaveProjectWindow window(mwindow, dir_path, save_mode, overwrite, reload);
240         window.lock_window("SaveProject::run");
241         window.create_objects();
242         window.unlock_window();
243         int result = window.run_window();
244         if( result ) return;
245
246         strcpy(dir_path, window.textbox->get_text());
247         window.recent_project->add_item("RECENT_PROJECT", dir_path);
248         reload = window.get_reload();
249         overwrite = window.get_overwrite();
250         save_mode = window.get_save_mode();
251         mwindow->defaults->update("PROJECT_DIRECTORY", dir_path);
252         mwindow->defaults->update("PROJECT_RELOAD", reload);
253         mwindow->defaults->update("PROJECT_OVERWRITE", overwrite);
254         mwindow->defaults->update("PROJECT_SAVE_MODE", save_mode);
255         mwindow->save_project(dir_path, save_mode, overwrite, reload);
256 }
257
258   
259 SaveSession::SaveSession(MWindow *mwindow)
260  : BC_MenuItem(_("Save Session"),_("Ctrl-s"),'s')
261 {
262         this->mwindow = mwindow;
263         set_ctrl(1);
264 }
265
266 int SaveSession::handle_event()
267 {
268         mwindow->save_defaults();
269         mwindow->save_backup();
270         mwindow->save(0);
271         mwindow->gui->show_message(_("Saved session."));
272         return 1;
273 }
274
275