Merge branch 'master' into windows
[ardour.git] / gtk2_ardour / export_dialog.cc
index 5ba3b6de0acd1b03a92e478a5e1ce0c7382cdb16..6351c512c19cc1d0dee757e3fd72e50a0cfa9396 100644 (file)
@@ -21,7 +21,7 @@
 
 #include <sigc++/signal.h>
 
-#include "pbd/filesystem.h"
+#include <gtkmm/messagedialog.h>
 
 #include "ardour/audioregion.h"
 #include "ardour/export_status.h"
@@ -29,6 +29,7 @@
 
 #include "export_dialog.h"
 #include "gui_thread.h"
+#include "nag.h"
 
 #include "i18n.h"
 
@@ -36,9 +37,9 @@ using namespace ARDOUR;
 using namespace PBD;
 using std::string;
 
-ExportDialog::ExportDialog (PublicEditor & editor, std::string title, std::string xml_node_name)
+ExportDialog::ExportDialog (PublicEditor & editor, std::string title, ARDOUR::ExportProfileManager::ExportType type)
   : ArdourDialog (title)
-  , xml_node_name (xml_node_name)
+  , type (type)
   , editor (editor)
 
   , warn_label ("", Gtk::ALIGN_LEFT)
@@ -63,7 +64,7 @@ ExportDialog::set_session (ARDOUR::Session* s)
        handler = _session->get_export_handler ();
        status = _session->get_export_status ();
 
-       profile_manager.reset (new ExportProfileManager (*_session, xml_node_name));
+       profile_manager.reset (new ExportProfileManager (*_session, type));
 
        /* Possibly init stuff in derived classes */
 
@@ -95,8 +96,6 @@ ExportDialog::set_session (ARDOUR::Session* s)
        channel_selector->CriticalSelectionChanged.connect (sigc::mem_fun (*this, &ExportDialog::update_warnings_and_example_filename));
        file_notebook->CriticalSelectionChanged.connect (sigc::mem_fun (*this, &ExportDialog::update_warnings_and_example_filename));
 
-       status->Aborting.connect (abort_connection, invalidator (*this), boost::bind (&ExportDialog::notify_errors, this), gui_context());
-
        update_warnings_and_example_filename ();
 }
 
@@ -216,9 +215,9 @@ ExportDialog::init_components ()
 }
 
 void
-ExportDialog::notify_errors ()
+ExportDialog::notify_errors (bool force)
 {
-       if (status->errors()) {
+       if (force || status->errors()) {
                std::string txt = _("Export has been aborted due to an error!\nSee the Log for details.");
                Gtk::MessageDialog msg (txt, false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
                msg.run();
@@ -304,9 +303,14 @@ ExportDialog::show_conflicting_files ()
 void
 ExportDialog::do_export ()
 {
-       profile_manager->prepare_for_export ();
-       handler->do_export ();
-       show_progress ();
+       try {
+               profile_manager->prepare_for_export ();
+               handler->do_export ();
+               show_progress ();
+       } catch(std::exception & e) {
+               error << string_compose (_("Export initialization failed: %1"), e.what()) << endmsg;
+               notify_errors(true);
+       }
 }
 
 void
@@ -324,17 +328,28 @@ ExportDialog::show_progress ()
        progress_connection = Glib::signal_timeout().connect (sigc::mem_fun(*this, &ExportDialog::progress_timeout), 100);
 
        gtk_main_iteration ();
+
        while (status->running) {
                if (gtk_events_pending()) {
                        gtk_main_iteration ();
                } else {
-                       usleep (10000);
+                       Glib::usleep (10000);
                }
        }
 
        if (!status->aborted()) {
-               status->finish ();
+
+               NagScreen* ns = NagScreen::maybe_nag (_("export"));
+               
+               if (ns) {
+                       ns->nag ();
+                       delete ns;
+               }
+       } else {
+               notify_errors ();
        }
+
+       status->finish ();
 }
 
 gint
@@ -393,7 +408,7 @@ ExportDialog::add_warning (string const & text)
 /*** Dialog specializations ***/
 
 ExportRangeDialog::ExportRangeDialog (PublicEditor & editor, string range_id) :
-  ExportDialog (editor, _("Export Range"), X_("RangeExportProfile")),
+  ExportDialog (editor, _("Export Range"), ExportProfileManager::RangeExport),
   range_id (range_id)
 {}
 
@@ -407,7 +422,7 @@ ExportRangeDialog::init_components ()
 }
 
 ExportSelectionDialog::ExportSelectionDialog (PublicEditor & editor) :
-  ExportDialog (editor, _("Export Selection"), X_("SelectionExportProfile"))
+  ExportDialog (editor, _("Export Selection"), ExportProfileManager::SelectionExport)
 {}
 
 void
@@ -420,7 +435,7 @@ ExportSelectionDialog::init_components ()
 }
 
 ExportRegionDialog::ExportRegionDialog (PublicEditor & editor, ARDOUR::AudioRegion const & region, ARDOUR::AudioTrack & track) :
-  ExportDialog (editor, _("Export Region"), X_("RegionExportProfile")),
+  ExportDialog (editor, _("Export Region"), ExportProfileManager::RegionExport),
   region (region),
   track (track)
 {}
@@ -445,7 +460,7 @@ ExportRegionDialog::init_components ()
 }
 
 StemExportDialog::StemExportDialog (PublicEditor & editor)
-  : ExportDialog(editor, _("Stem Export"), X_("StemExportProfile"))
+  : ExportDialog(editor, _("Stem Export"), ExportProfileManager::StemExport)
 {
 
 }