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) mwindow->gui->set_done(0);
120 if(saveas->quit_now) mwindow->playback_3d->quit();
125 int Save::save_before_quit()
127 saveas->quit_now = 1;
132 SaveAs::SaveAs(MWindow *mwindow)
133 : BC_MenuItem(_("Save as..."), ""), Thread()
135 this->mwindow = mwindow;
139 int SaveAs::set_mainmenu(MainMenu *mmenu)
145 int SaveAs::handle_event()
154 // ======================================= get path from user
156 //printf("SaveAs::run 1\n");
157 char directory[1024], filename[1024];
158 sprintf(directory, "~");
159 mwindow->defaults->get("DIRECTORY", directory);
161 // Loop if file exists
163 SaveFileWindow *window;
165 window = new SaveFileWindow(mwindow, directory);
166 window->lock_window("SaveAs::run");
167 window->create_objects();
168 window->unlock_window();
169 result = window->run_window();
170 mwindow->defaults->update("DIRECTORY", window->get_submitted_path());
171 strcpy(filename, window->get_submitted_path());
174 // Extend the filename with .xml
175 if(strlen(filename) < 4 ||
176 strcasecmp(&filename[strlen(filename) - 4], ".xml"))
178 strcat(filename, ".xml");
181 // ======================================= try to save it
182 if(filename[0] == 0) return; // no filename given
183 if(result == 1) return; // user cancelled
184 result = ConfirmSave::test_file(mwindow, filename);
185 }while(result); // file exists so repeat
187 //printf("SaveAs::run 6 %s\n", filename);
194 mwindow->gui->lock_window("SaveAs::run 1");
195 // update the project name
196 mwindow->set_filename(filename);
197 mwindow->edl->save_xml(&file,
201 mwindow->gui->unlock_window();
202 file.terminate_string();
204 if(file.write_to_file(filename))
207 mwindow->set_filename(""); // update the project name
208 sprintf(string2, _("Couldn't open %s."), filename);
209 ErrorBox error(_(PROGRAM_NAME ": Error"),
210 mwindow->gui->get_abs_cursor_x(1),
211 mwindow->gui->get_abs_cursor_y(1));
212 error.create_objects(string2);
213 error.raise_window();
219 char string[BCTEXTLEN];
220 sprintf(string, _("\"%s\" %dC written"), filename, (int)strlen(file.string()));
221 mwindow->gui->lock_window("SaveAs::run 2");
222 mwindow->gui->show_message(string);
223 mwindow->gui->unlock_window();
227 mwindow->session->changes_made = 0;
228 mmenu->add_load(filename);
229 // Last command in program
230 // if(quit_now) mwindow->gui->set_done(0);
231 if(quit_now) mwindow->playback_3d->quit();
242 SaveFileWindow::SaveFileWindow(MWindow *mwindow, char *init_directory)
243 : BC_FileBox(mwindow->gui->get_abs_cursor_x(1),
244 mwindow->gui->get_abs_cursor_y(1) - BC_WindowBase::get_resources()->filebox_h / 2,
246 _(PROGRAM_NAME ": Save"),
247 _("Enter a filename to save as"))
249 this->mwindow = mwindow;
252 SaveFileWindow::~SaveFileWindow() {}