00001 #include "confirmsave.h"
00002 #include "bchash.h"
00003 #include "edl.h"
00004 #include "errorbox.h"
00005 #include "file.h"
00006 #include "filexml.h"
00007 #include "fileformat.h"
00008 #include "indexfile.h"
00009 #include "language.h"
00010 #include "mainmenu.h"
00011 #include "mwindow.h"
00012 #include "mwindowgui.h"
00013 #include "playback3d.h"
00014 #include "savefile.h"
00015 #include "mainsession.h"
00016
00017 #include <string.h>
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 SaveBackup::SaveBackup(MWindow *mwindow)
00028 : BC_MenuItem(_("Save backup"))
00029 {
00030 this->mwindow = mwindow;
00031 }
00032 int SaveBackup::handle_event()
00033 {
00034 mwindow->save_backup();
00035 mwindow->gui->show_message(_("Saved backup."));
00036 return 1;
00037 }
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 Save::Save(MWindow *mwindow) : BC_MenuItem(_("Save"), "s", 's')
00050 {
00051 this->mwindow = mwindow;
00052 quit_now = 0;
00053 }
00054
00055 int Save::create_objects(SaveAs *saveas)
00056 {
00057 this->saveas = saveas;
00058 return 0;
00059 }
00060
00061 int Save::handle_event()
00062 {
00063 if(mwindow->session->filename[0] == 0)
00064 {
00065 saveas->start();
00066 }
00067 else
00068 {
00069
00070
00071 FileXML file;
00072 mwindow->edl->save_xml(mwindow->plugindb,
00073 &file,
00074 mwindow->session->filename,
00075 0,
00076 0);
00077 file.terminate_string();
00078
00079 if(file.write_to_file(mwindow->session->filename))
00080 {
00081 char string2[256];
00082 sprintf(string2, _("Couldn't open %s"), mwindow->session->filename);
00083 ErrorBox error(PROGRAM_NAME ": Error",
00084 mwindow->gui->get_abs_cursor_x(1),
00085 mwindow->gui->get_abs_cursor_y(1));
00086 error.create_objects(string2);
00087 error.raise_window();
00088 error.run_window();
00089 return 1;
00090 }
00091 else
00092 {
00093 char string[BCTEXTLEN];
00094 sprintf(string, _("\"%s\" %dC written"), mwindow->session->filename, strlen(file.string));
00095 mwindow->gui->show_message(string);
00096 }
00097 mwindow->session->changes_made = 0;
00098
00099
00100 if(saveas->quit_now) mwindow->playback_3d->quit();
00101 }
00102 return 1;
00103 }
00104
00105 int Save::save_before_quit()
00106 {
00107 saveas->quit_now = 1;
00108 handle_event();
00109 return 0;
00110 }
00111
00112 SaveAs::SaveAs(MWindow *mwindow)
00113 : BC_MenuItem(_("Save as..."), ""), Thread()
00114 {
00115 this->mwindow = mwindow;
00116 quit_now = 0;
00117 }
00118
00119 int SaveAs::set_mainmenu(MainMenu *mmenu)
00120 {
00121 this->mmenu = mmenu;
00122 return 0;
00123 }
00124
00125 int SaveAs::handle_event()
00126 {
00127 quit_now = 0;
00128 start();
00129 return 1;
00130 }
00131
00132 void SaveAs::run()
00133 {
00134
00135 int result;
00136
00137 char directory[1024], filename[1024];
00138 sprintf(directory, "~");
00139 mwindow->defaults->get("DIRECTORY", directory);
00140
00141
00142 do{
00143 SaveFileWindow *window;
00144
00145 window = new SaveFileWindow(mwindow, directory);
00146 window->create_objects();
00147 result = window->run_window();
00148 mwindow->defaults->update("DIRECTORY", window->get_submitted_path());
00149 strcpy(filename, window->get_submitted_path());
00150 delete window;
00151
00152
00153 if(strlen(filename) < 4 ||
00154 strcasecmp(&filename[strlen(filename) - 4], ".xml"))
00155 {
00156 strcat(filename, ".xml");
00157 }
00158
00159
00160 if(filename[0] == 0) return;
00161 if(result == 1) return;
00162 result = ConfirmSave::test_file(mwindow, filename);
00163 }while(result);
00164
00165
00166
00167
00168
00169
00170
00171 FileXML file;
00172 mwindow->set_filename(filename);
00173 mwindow->edl->save_xml(mwindow->plugindb,
00174 &file,
00175 filename,
00176 0,
00177 0);
00178 file.terminate_string();
00179
00180 if(file.write_to_file(filename))
00181 {
00182 char string2[256];
00183 mwindow->set_filename("");
00184 sprintf(string2, _("Couldn't open %s."), filename);
00185 ErrorBox error(PROGRAM_NAME ": Error",
00186 mwindow->gui->get_abs_cursor_x(1),
00187 mwindow->gui->get_abs_cursor_y(1));
00188 error.create_objects(string2);
00189 error.raise_window();
00190 error.run_window();
00191 return;
00192 }
00193 else
00194 {
00195 char string[BCTEXTLEN];
00196 sprintf(string, _("\"%s\" %dC written"), filename, strlen(file.string));
00197 mwindow->gui->lock_window();
00198 mwindow->gui->show_message(string);
00199 mwindow->gui->unlock_window();
00200 }
00201
00202
00203 mwindow->session->changes_made = 0;
00204 mmenu->add_load(filename);
00205
00206
00207 if(quit_now) mwindow->playback_3d->quit();
00208 return;
00209 }
00210
00211
00212
00213
00214
00215
00216
00217
00218 SaveFileWindow::SaveFileWindow(MWindow *mwindow, char *init_directory)
00219 : BC_FileBox(mwindow->gui->get_abs_cursor_x(1),
00220 mwindow->gui->get_abs_cursor_y(1) - BC_WindowBase::get_resources()->filebox_h / 2,
00221 init_directory,
00222 PROGRAM_NAME ": Save",
00223 _("Enter a filename to save as"))
00224 {
00225 this->mwindow = mwindow;
00226 }
00227
00228 SaveFileWindow::~SaveFileWindow() {}
00229