Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

savefile.C

Go to the documentation of this file.
00001 #include "confirmsave.h"
00002 #include "defaults.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 "mainmenu.h"
00010 #include "mwindow.h"
00011 #include "mwindowgui.h"
00012 #include "savefile.h"
00013 #include "mainsession.h"
00014 
00015 #include <string.h>
00016 
00017 #include <libintl.h>
00018 #define _(String) gettext(String)
00019 #define gettext_noop(String) String
00020 #define N_(String) gettext_noop (String)
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 SaveBackup::SaveBackup(MWindow *mwindow)
00031  : BC_MenuItem(_("Save backup"))
00032 {
00033         this->mwindow = mwindow;
00034 }
00035 int SaveBackup::handle_event()
00036 {
00037         mwindow->save_backup();
00038         mwindow->gui->show_message(_("Saved backup."));
00039         return 1;
00040 }
00041 
00042 
00043 
00044 
00045 
00046 
00047 
00048 
00049 
00050 
00051 
00052 Save::Save(MWindow *mwindow) : BC_MenuItem(_("Save"), "s", 's')
00053 { 
00054         this->mwindow = mwindow; 
00055         quit_now = 0; 
00056 }
00057 
00058 int Save::create_objects(SaveAs *saveas)
00059 {
00060         this->saveas = saveas;
00061         return 0;
00062 }
00063 
00064 int Save::handle_event()
00065 {
00066         if(mwindow->session->filename[0] == 0) 
00067         {
00068                 saveas->start();
00069         }
00070         else
00071         {
00072 // save it
00073 // TODO: Move this into mwindow.
00074                 FileXML file;
00075                 mwindow->edl->save_xml(mwindow->plugindb, 
00076                         &file, 
00077                         mwindow->session->filename,
00078                         0,
00079                         0);
00080                 file.terminate_string();
00081 
00082                 if(file.write_to_file(mwindow->session->filename))
00083                 {
00084                         char string2[256];
00085                         sprintf(string2, _("Couldn't open %s"), mwindow->session->filename);
00086                         ErrorBox error(PROGRAM_NAME ": Error",
00087                                 mwindow->gui->get_abs_cursor_x(1),
00088                                 mwindow->gui->get_abs_cursor_y(1));
00089                         error.create_objects(string2);
00090                         error.run_window();
00091                         return 1;               
00092                 }
00093                 else
00094                 {
00095                         char string[BCTEXTLEN];
00096                         sprintf(string, _("\"%s\" %dC written"), mwindow->session->filename, strlen(file.string));
00097                         mwindow->gui->show_message(string);
00098                 }
00099                 mwindow->session->changes_made = 0;
00100                 if(saveas->quit_now) mwindow->gui->set_done(0);
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 // ======================================= get path from user
00135         int result;
00136 //printf("SaveAs::run 1\n");
00137         char directory[1024], filename[1024];
00138         sprintf(directory, "~");
00139         mwindow->defaults->get("DIRECTORY", directory);
00140 
00141 // Loop if file exists
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 // Extend the filename with .xml
00153                 if(strlen(filename) < 4 || 
00154                         strcasecmp(&filename[strlen(filename) - 4], ".xml"))
00155                 {
00156                         strcat(filename, ".xml");
00157                 }
00158 
00159 // ======================================= try to save it
00160                 if(filename[0] == 0) return;              // no filename given
00161                 if(result == 1) return;          // user cancelled
00162                 result = ConfirmSave::test_file(mwindow, filename);
00163         }while(result);        // file exists so repeat
00164 
00165 //printf("SaveAs::run 6 %s\n", filename);
00166 
00167 
00168 
00169 
00170 // save it
00171         FileXML file;
00172         mwindow->set_filename(filename);      // update the project name
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("");      // update the project name
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.run_window();
00190                 return;         
00191         }
00192         else
00193         {
00194                 char string[BCTEXTLEN];
00195                 sprintf(string, _("\"%s\" %dC written"), filename, strlen(file.string));
00196                 mwindow->gui->lock_window();
00197                 mwindow->gui->show_message(string);
00198                 mwindow->gui->unlock_window();
00199         }
00200 
00201 
00202         mwindow->session->changes_made = 0;
00203         mmenu->add_load(filename);
00204         if(quit_now) mwindow->gui->set_done(0);
00205         return;
00206 }
00207 
00208 
00209 
00210 
00211 
00212 
00213 
00214 
00215 SaveFileWindow::SaveFileWindow(MWindow *mwindow, char *init_directory)
00216  : BC_FileBox(mwindow->gui->get_abs_cursor_x(1),
00217         mwindow->gui->get_abs_cursor_y(1) - BC_WindowBase::get_resources()->filebox_h / 2,
00218         init_directory, 
00219         PROGRAM_NAME ": Save", 
00220         _("Enter a filename to save as"))
00221 { 
00222         this->mwindow = mwindow; 
00223 }
00224 
00225 SaveFileWindow::~SaveFileWindow() {}
00226 

Generated on Sun Jan 8 13:39:00 2006 for Cinelerra-svn by  doxygen 1.4.4