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"), "b", 'b')
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, mwindow->session->filename);
93 file.terminate_string();
95 if(file.write_to_file(mwindow->session->filename))
98 sprintf(string2, _("Couldn't open %s"), mwindow->session->filename);
99 ErrorBox error(_(PROGRAM_NAME ": Error"),
100 mwindow->gui->get_abs_cursor_x(1),
101 mwindow->gui->get_abs_cursor_y(1));
102 error.create_objects(string2);
103 error.raise_window();
109 char string[BCTEXTLEN];
110 sprintf(string, _("\"%s\" %dC written"),
111 mwindow->session->filename, (int)strlen(file.string()));
112 mwindow->gui->show_message(string);
114 mwindow->session->changes_made = 0;
115 // Last command in program
116 if( saveas->quit_now )
122 int Save::save_before_quit()
124 saveas->quit_now = 1;
129 SaveAs::SaveAs(MWindow *mwindow)
130 : BC_MenuItem(_("Save as..."), "Shift-S", 'S'), Thread()
133 this->mwindow = mwindow;
137 int SaveAs::set_mainmenu(MainMenu *mmenu)
143 int SaveAs::handle_event()
152 // ======================================= get path from user
154 //printf("SaveAs::run 1\n");
155 char directory[1024], filename[1024];
156 sprintf(directory, "~");
157 mwindow->defaults->get("DIRECTORY", directory);
159 // Loop if file exists
161 SaveFileWindow *window;
163 window = new SaveFileWindow(mwindow, directory);
164 window->lock_window("SaveAs::run");
165 window->create_objects();
166 window->unlock_window();
167 result = window->run_window();
168 mwindow->defaults->update("DIRECTORY", window->get_submitted_path());
169 strcpy(filename, window->get_submitted_path());
172 // Extend the filename with .xml
173 if(strlen(filename) < 4 ||
174 strcasecmp(&filename[strlen(filename) - 4], ".xml"))
176 strcat(filename, ".xml");
179 // ======================================= try to save it
180 if(filename[0] == 0) return; // no filename given
181 if(result == 1) return; // user cancelled
182 result = ConfirmSave::test_file(mwindow, filename);
183 }while(result); // file exists so repeat
185 //printf("SaveAs::run 6 %s\n", filename);
192 mwindow->gui->lock_window("SaveAs::run 1");
193 // update the project name
194 mwindow->set_filename(filename);
195 mwindow->edl->save_xml(&file, filename);
196 mwindow->gui->unlock_window();
197 file.terminate_string();
199 if(file.write_to_file(filename))
202 mwindow->set_filename(""); // update the project name
203 sprintf(string2, _("Couldn't open %s."), filename);
204 ErrorBox error(_(PROGRAM_NAME ": Error"),
205 mwindow->gui->get_abs_cursor_x(1),
206 mwindow->gui->get_abs_cursor_y(1));
207 error.create_objects(string2);
208 error.raise_window();
214 char string[BCTEXTLEN];
215 sprintf(string, _("\"%s\" %dC written"), filename, (int)strlen(file.string()));
216 mwindow->gui->lock_window("SaveAs::run 2");
217 mwindow->gui->show_message(string);
218 mwindow->gui->unlock_window();
222 mwindow->session->changes_made = 0;
223 mmenu->add_load(filename);
224 // Last command in program
237 SaveFileWindow::SaveFileWindow(MWindow *mwindow, char *init_directory)
238 : BC_FileBox(mwindow->gui->get_abs_cursor_x(1),
239 mwindow->gui->get_abs_cursor_y(1) - BC_WindowBase::get_resources()->filebox_h / 2,
241 _(PROGRAM_NAME ": Save"),
242 _("Enter a filename to save as"))
244 this->mwindow = mwindow;
247 SaveFileWindow::~SaveFileWindow() {}