4 * Copyright (C) 2008 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
22 #include "confirmsave.h"
28 #include "fileformat.h"
29 #include "indexfile.h"
33 #include "mwindowgui.h"
34 #include "playback3d.h"
36 #include "mainsession.h"
48 SaveBackup::SaveBackup(MWindow *mwindow)
49 : BC_MenuItem(_("Save backup"))
51 this->mwindow = mwindow;
53 int SaveBackup::handle_event()
55 mwindow->save_backup();
56 mwindow->gui->show_message(_("Saved backup."));
70 Save::Save(MWindow *mwindow) : BC_MenuItem(_("Save"), "s", 's')
72 this->mwindow = mwindow;
76 void Save::create_objects(SaveAs *saveas)
78 this->saveas = saveas;
81 int Save::handle_event()
83 if(mwindow->session->filename[0] == 0)
90 // TODO: Move this into mwindow.
92 mwindow->edl->save_xml(&file,
93 mwindow->session->filename,
96 file.terminate_string();
98 if(file.write_to_file(mwindow->session->filename))
101 sprintf(string2, _("Couldn't open %s"), mwindow->session->filename);
102 ErrorBox error(_(PROGRAM_NAME ": Error"),
103 mwindow->gui->get_abs_cursor_x(1),
104 mwindow->gui->get_abs_cursor_y(1));
105 error.create_objects(string2);
106 error.raise_window();
112 char string[BCTEXTLEN];
113 sprintf(string, _("\"%s\" %dC written"),
114 mwindow->session->filename, (int)strlen(file.string()));
115 mwindow->gui->show_message(string);
117 mwindow->session->changes_made = 0;
118 // Last command in program
119 if( saveas->quit_now )
125 int Save::save_before_quit()
127 saveas->quit_now = 1;
132 SaveAs::SaveAs(MWindow *mwindow)
133 : BC_MenuItem(_("Save as..."), "Shift-S", 'S'), Thread()
136 this->mwindow = mwindow;
140 int SaveAs::set_mainmenu(MainMenu *mmenu)
146 int SaveAs::handle_event()
155 // ======================================= get path from user
157 //printf("SaveAs::run 1\n");
158 char directory[1024], filename[1024];
159 sprintf(directory, "~");
160 mwindow->defaults->get("DIRECTORY", directory);
162 // Loop if file exists
164 SaveFileWindow *window;
166 window = new SaveFileWindow(mwindow, directory);
167 window->lock_window("SaveAs::run");
168 window->create_objects();
169 window->unlock_window();
170 result = window->run_window();
171 mwindow->defaults->update("DIRECTORY", window->get_submitted_path());
172 strcpy(filename, window->get_submitted_path());
175 // Extend the filename with .xml
176 if(strlen(filename) < 4 ||
177 strcasecmp(&filename[strlen(filename) - 4], ".xml"))
179 strcat(filename, ".xml");
182 // ======================================= try to save it
183 if(filename[0] == 0) return; // no filename given
184 if(result == 1) return; // user cancelled
185 result = ConfirmSave::test_file(mwindow, filename);
186 }while(result); // file exists so repeat
188 //printf("SaveAs::run 6 %s\n", filename);
195 mwindow->gui->lock_window("SaveAs::run 1");
196 // update the project name
197 mwindow->set_filename(filename);
198 mwindow->edl->save_xml(&file,
202 mwindow->gui->unlock_window();
203 file.terminate_string();
205 if(file.write_to_file(filename))
208 mwindow->set_filename(""); // update the project name
209 sprintf(string2, _("Couldn't open %s."), filename);
210 ErrorBox error(_(PROGRAM_NAME ": Error"),
211 mwindow->gui->get_abs_cursor_x(1),
212 mwindow->gui->get_abs_cursor_y(1));
213 error.create_objects(string2);
214 error.raise_window();
220 char string[BCTEXTLEN];
221 sprintf(string, _("\"%s\" %dC written"), filename, (int)strlen(file.string()));
222 mwindow->gui->lock_window("SaveAs::run 2");
223 mwindow->gui->show_message(string);
224 mwindow->gui->unlock_window();
228 mwindow->session->changes_made = 0;
229 mmenu->add_load(filename);
230 // Last command in program
243 SaveFileWindow::SaveFileWindow(MWindow *mwindow, char *init_directory)
244 : BC_FileBox(mwindow->gui->get_abs_cursor_x(1),
245 mwindow->gui->get_abs_cursor_y(1) - BC_WindowBase::get_resources()->filebox_h / 2,
247 _(PROGRAM_NAME ": Save"),
248 _("Enter a filename to save as"))
250 this->mwindow = mwindow;
253 SaveFileWindow::~SaveFileWindow() {}