Credit Andrew - fix vorbis audio which was scratchy and ensure aging plugin does...
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / savefile.C
index ffd9aef688638b0ed41acee22492dfaf66bbbf31..c227a56029e0df191f0a4b839f801a8a66fb2e9a 100644 (file)
 #include <string.h>
 
 
-
-
-
-
-
-
-
 SaveBackup::SaveBackup(MWindow *mwindow)
  : BC_MenuItem(_("Save backup"), "b", 'b')
 {
@@ -59,15 +52,6 @@ int SaveBackup::handle_event()
 }
 
 
-
-
-
-
-
-
-
-
-
 Save::Save(MWindow *mwindow) : BC_MenuItem(_("Save"), "s", 's')
 {
        this->mwindow = mwindow;
@@ -81,37 +65,10 @@ void Save::create_objects(SaveAs *saveas)
 
 int Save::handle_event()
 {
-       if(mwindow->session->filename[0] == 0)
-       {
-               saveas->start();
-       }
-       else
-       {
-// save it
-// TODO: Move this into mwindow.
-               FileXML file;
-               mwindow->edl->save_xml(&file, mwindow->session->filename);
-               file.terminate_string();
-
-               if(file.write_to_file(mwindow->session->filename))
-               {
-                       char string2[256];
-                       sprintf(string2, _("Couldn't open %s"), mwindow->session->filename);
-                       ErrorBox error(_(PROGRAM_NAME ": Error"),
-                               mwindow->gui->get_abs_cursor_x(1),
-                               mwindow->gui->get_abs_cursor_y(1));
-                       error.create_objects(string2);
-                       error.raise_window();
-                       error.run_window();
-                       return 1;
-               }
-               else
-               {
-                       char string[BCTEXTLEN];
-                       sprintf(string, _("\"%s\" %dC written"),
-                                mwindow->session->filename, (int)strlen(file.string()));
-                       mwindow->gui->show_message(string);
-               }
+       mwindow->gui->unlock_window();
+       int ret = mwindow->save(0);
+       mwindow->gui->lock_window("Save::handle_event");
+       if( !ret ) {
                mwindow->session->changes_made = 0;
 // Last command in program
                if( saveas->quit_now )
@@ -152,99 +109,15 @@ int SaveAs::handle_event()
 
 void SaveAs::run()
 {
-// ======================================= get path from user
-       int result;
-//printf("SaveAs::run 1\n");
-       char directory[1024], filename[1024];
-       sprintf(directory, "~");
-       mwindow->defaults->get("DIRECTORY", directory);
-
-// Loop if file exists
-       do{
-               SaveFileWindow *window;
-
-               window = new SaveFileWindow(mwindow, directory);
-               window->lock_window("SaveAs::run");
-               window->create_objects();
-               window->unlock_window();
-               result = window->run_window();
-               mwindow->defaults->update("DIRECTORY", window->get_submitted_path());
-               strcpy(filename, window->get_submitted_path());
-               delete window;
-
-// Extend the filename with .xml
-               if(strlen(filename) < 4 ||
-                       strcasecmp(&filename[strlen(filename) - 4], ".xml"))
-               {
-                       strcat(filename, ".xml");
-               }
-
-// ======================================= try to save it
-               if(filename[0] == 0) return;              // no filename given
-               if(result == 1) return;          // user cancelled
-               result = ConfirmSave::test_file(mwindow, filename);
-       }while(result);        // file exists so repeat
-
-//printf("SaveAs::run 6 %s\n", filename);
-
-
-
-
-// save it
-       FileXML file;
-       mwindow->gui->lock_window("SaveAs::run 1");
-// update the project name
-       mwindow->set_filename(filename);
-       mwindow->edl->save_xml(&file, filename);
-       mwindow->gui->unlock_window();
-       file.terminate_string();
-
-       if(file.write_to_file(filename))
-       {
-               char string2[256];
-               mwindow->set_filename("");      // update the project name
-               sprintf(string2, _("Couldn't open %s."), filename);
-               ErrorBox error(_(PROGRAM_NAME ": Error"),
-                       mwindow->gui->get_abs_cursor_x(1),
-                       mwindow->gui->get_abs_cursor_y(1));
-               error.create_objects(string2);
-               error.raise_window();
-               error.run_window();
+       if( mwindow->save(1) )
                return;
-       }
-       else
-       {
-               char string[BCTEXTLEN];
-               sprintf(string, _("\"%s\" %dC written"), filename, (int)strlen(file.string()));
-               mwindow->gui->lock_window("SaveAs::run 2");
-               mwindow->gui->show_message(string);
-               mwindow->gui->unlock_window();
-       }
-
-
        mwindow->session->changes_made = 0;
-       mmenu->add_load(filename);
-// Last command in program
        if( quit_now )
                mwindow->quit();
        return;
 }
 
 
-SaveFileWindow::SaveFileWindow(MWindow *mwindow, char *init_directory)
- : BC_FileBox(mwindow->gui->get_abs_cursor_x(1),
-       mwindow->gui->get_abs_cursor_y(1) - BC_WindowBase::get_resources()->filebox_h / 2,
-       init_directory,
-       _(PROGRAM_NAME ": Save"),
-       _("Enter a filename to save as"))
-{
-       this->mwindow = mwindow;
-}
-
-SaveFileWindow::~SaveFileWindow() {}
-
-
-
 int SaveProjectModeItem::handle_event()
 {
        ((SaveProjectMode *)get_popup_menu())->update(id);
@@ -252,7 +125,7 @@ int SaveProjectModeItem::handle_event()
 }
 
 SaveProjectMode::SaveProjectMode(SaveProjectWindow *gui, int x, int y)
- : BC_PopupMenu(x, y, 100, "")
+ : BC_PopupMenu(x, y, xS(100), "")
 {
        this->gui = gui;
        save_modes[SAVE_PROJECT_COPY]     = _("Copy");
@@ -298,13 +171,15 @@ SaveProjectWindow::SaveProjectWindow(MWindow *mwindow, const char *dir_path,
                mwindow->gui->get_abs_cursor_x(1),
                mwindow->gui->get_abs_cursor_y(1) -
                        BC_WindowBase::get_resources()->filebox_h / 2,
-               540, 220, 540, 220, 0)
+               xS(540), yS(220), xS(540), yS(220), 0)
 {
        this->mwindow = mwindow;
        strcpy(this->dir_path, dir_path);
        this->overwrite = overwrite;
        this->save_mode = save_mode;
        this->reload = reload;
+// *** CONTEXT_HELP ***
+       context_help_set_keyword("Export Project");
 }
 SaveProjectWindow::~SaveProjectWindow()
 {
@@ -312,26 +187,28 @@ SaveProjectWindow::~SaveProjectWindow()
 
 void SaveProjectWindow::create_objects()
 {
-       int x = 20, y = 20, x1 = get_w()-80;
+       int xs10 = xS(10), xs20 = xS(20);
+       int ys10 = yS(10), ys20 = yS(20);
+       int x = xs20, y = ys20, x1 = get_w()-xS(80);
        BC_Title *title;
        add_subwindow(title = new BC_Title(x, y, _("Project Directory:")));
-       y += title->get_h() + 10;
+       y += title->get_h() + ys10;
        add_subwindow(textbox = new SaveProjectTextBox(this, x, y, x1-x));
-       x1 += 10;
+       x1 += xs10;
        add_subwindow(recent_project = new BC_RecentList("RECENT_PROJECT",
-               mwindow->defaults, textbox, 10, x1, y, 300, 100));
+               mwindow->defaults, textbox, 10, x1, y, xS(300), yS(100)));
        recent_project->load_items("RECENT_PROJECT");
-       x1 += recent_project->get_w() + 10;
+       x1 += recent_project->get_w() + xs10;
        add_subwindow(browse_button = new BrowseButton(mwindow->theme, this,
-               textbox, x1, y-5, "", "", "", 1));
-       y += textbox->get_h() + 20;
+               textbox, x1, y-yS(5), "", "", "", 1));
+       y += textbox->get_h() + ys20;
        add_subwindow(mode_popup = new SaveProjectMode(this, x, y));
        mode_popup->create_objects();
-       y += mode_popup->get_h() + 10;
+       y += mode_popup->get_h() + ys10;
        x1 = x;
        BC_CheckBox *overwrite_files, *reload_project;
        add_subwindow(overwrite_files = new BC_CheckBox(x1, y, &overwrite, _("Overwrite files")));
-       x1 += overwrite_files->get_w() + 20;
+       x1 += overwrite_files->get_w() + xs20;
        add_subwindow(reload_project = new BC_CheckBox(x1, y, &reload, _("Reload project")));
        add_subwindow(new BC_OKButton(this));
        add_subwindow(new BC_CancelButton(this));
@@ -378,3 +255,21 @@ void SaveProject::run()
        mwindow->save_project(dir_path, save_mode, overwrite, reload);
 }
 
+  
+SaveSession::SaveSession(MWindow *mwindow)
+ : BC_MenuItem(_("Save Session"),_("Ctrl-s"),'s')
+{
+       this->mwindow = mwindow;
+       set_ctrl(1);
+}
+
+int SaveSession::handle_event()
+{
+       mwindow->save_defaults();
+       mwindow->save_backup();
+       mwindow->save(0);
+       mwindow->gui->show_message(_("Saved session."));
+       return 1;
+}
+
+