enough with umpteen "i18n.h" files. Consolidate on pbd/i18n.h
[ardour.git] / gtk2_ardour / startup.cc
index 7bb9b2e29524a2daa40910698f18e8c15ee95275..58c1cfc7ad403bdf713771b12a09538ffb588ea1 100644 (file)
 
 #ifdef WAF_BUILD
 #include "gtk2ardour-config.h"
+#include "gtk2ardour-version.h"
 #endif
 
-#include <fstream>
 #include <algorithm>
+#include <fcntl.h>
+
+#include "pbd/gstdio_compat.h"
 
 #include <gtkmm/main.h>
 #include <gtkmm/filechooser.h>
 
 #include "pbd/failed_constructor.h"
+#include "pbd/scoped_file_descriptor.h"
 #include "pbd/file_utils.h"
 #include "pbd/replace_all.h"
 #include "pbd/whitespace.h"
 
 #include "ardour/audioengine.h"
 #include "ardour/filesystem_paths.h"
+#include "ardour/filename_extensions.h"
+#include "ardour/plugin_manager.h"
 #include "ardour/recent_sessions.h"
 #include "ardour/session.h"
 #include "ardour/session_state_utils.h"
 #include "ardour/template_utils.h"
-#include "ardour/filename_extensions.h"
+#include "ardour/profile.h"
 
-#include "ardour_ui.h"
 #include "startup.h"
 #include "opts.h"
 #include "engine_dialog.h"
-#include "i18n.h"
+#include "pbd/i18n.h"
 #include "utils.h"
 
 using namespace std;
@@ -55,16 +60,10 @@ using namespace Gdk;
 using namespace Glib;
 using namespace PBD;
 using namespace ARDOUR;
+using namespace ARDOUR_UI_UTILS;
 
 ArdourStartup* ArdourStartup::the_startup = 0;
 
-static string poor_mans_glob (string path)
-{
-       string copy = path;
-       replace_all (copy, "~", Glib::get_home_dir());
-       return copy;
-}
-
 ArdourStartup::ArdourStartup ()
        : _response (RESPONSE_OK)
        , config_modified (false)
@@ -78,37 +77,32 @@ ArdourStartup::ArdourStartup ()
        , monitoring_page_index (-1)
        , final_page_index (-1)
 {
-       set_keep_above (true);
        set_position (WIN_POS_CENTER);
        set_border_width (12);
-       
-       if ((icon_pixbuf = ::get_icon ("ardour_icon_48px")) == 0) {
+
+       if ((icon_pixbuf = ::get_icon (PROGRAM_NAME "-icon_48px")) == 0) {
                throw failed_constructor();
        }
-       
+
        list<Glib::RefPtr<Gdk::Pixbuf> > window_icons;
        Glib::RefPtr<Gdk::Pixbuf> icon;
-       
-       if ((icon = ::get_icon ("ardour_icon_16px")) != 0) {
+
+       if ((icon = ::get_icon (PROGRAM_NAME "-icon_16px")) != 0) {
                window_icons.push_back (icon);
        }
-       if ((icon = ::get_icon ("ardour_icon_22px")) != 0) {
+       if ((icon = ::get_icon (PROGRAM_NAME "-icon_22px")) != 0) {
                window_icons.push_back (icon);
        }
-       if ((icon = ::get_icon ("ardour_icon_32px")) != 0) {
+       if ((icon = ::get_icon (PROGRAM_NAME "-icon_32px")) != 0) {
                window_icons.push_back (icon);
        }
-       if ((icon = ::get_icon ("ardour_icon_48px")) != 0) {
+       if ((icon = ::get_icon (PROGRAM_NAME "-icon_48px")) != 0) {
                window_icons.push_back (icon);
        }
        if (!window_icons.empty ()) {
                set_default_icon_list (window_icons);
        }
-       
-#ifdef __APPLE__
-       setup_prerelease_page ();
-#endif
-       
+
        setup_new_user_page ();
        setup_first_time_config_page ();
        setup_monitoring_choice_page ();
@@ -125,47 +119,23 @@ ArdourStartup::~ArdourStartup ()
 bool
 ArdourStartup::required ()
 {
-       return !Glib::file_test (been_here_before_path(), Glib::FILE_TEST_EXISTS);
-}
+       /* look for a "been here before" file for this version or earlier
+        * versions
+        */
 
-std::string
-ArdourStartup::been_here_before_path ()
-{
-       // XXXX use more specific version so we can catch upgrades
-       return Glib::build_filename (user_config_directory (), ".a3");
-}
+       const int current_version = atoi (PROGRAM_VERSION);
 
-void
-ArdourStartup::setup_prerelease_page ()
-{
-       VBox* vbox = manage (new VBox);
-       Label* label = manage (new Label);
-       label->set_markup (string_compose (_("<b>Welcome to this BETA release of Ardour %1</b>\n\n\
-Ardour %1 has been released for Linux but because of the lack of testers,\n\
-it is still at the beta stage on OS X. So, a few guidelines:\n\
-\n\
-1) Please do <b>NOT</b> use this software with the expectation that it is stable or reliable\n\
-   though it may be so, depending on your workflow.\n\
-2) <b>Please do NOT use the forums at ardour.org to report issues</b>.\n\
-3) Please <b>DO</b> use the bugtracker at http://tracker.ardour.org/ to report issues\n\
-   making sure to note the product version number as %1-beta.\n\
-4) Please <b>DO</b> use the ardour-users mailing list to discuss ideas and pass on comments.\n\
-5) Please <b>DO</b> join us on IRC for real time discussions about ardour3. You\n\
-   can get there directly from Ardour via the Help->Chat menu option.\n\
-\n\
-Full information on all the above can be found on the support page at\n\
-\n\
-                http://ardour.org/support\n\
-"), VERSIONSTRING));
+       for (int v = current_version; v != 0; --v) {
+               if (Glib::file_test (ARDOUR::been_here_before_path (v), Glib::FILE_TEST_EXISTS)) {
+                       if (v != current_version) {
+                               /* older version exists, create the current one */
+                               PBD::ScopedFileDescriptor fout (g_open (been_here_before_path (current_version).c_str(), O_CREAT|O_TRUNC|O_RDWR, 0666));
+                       }
+                       return false;
+               }
+       }
 
-       vbox->set_border_width (12);
-       vbox->pack_start (*label, false, false, 12);
-       vbox->show_all ();
-       
-       append_page (*vbox);
-       set_page_type (*vbox, ASSISTANT_PAGE_CONTENT);
-       set_page_title (*vbox, _("This is a BETA RELEASE"));
-       set_page_complete (*vbox, true);
+       return true;
 }
 
 void
@@ -209,7 +179,7 @@ ArdourStartup::default_dir_changed ()
 {
        Config->set_default_session_parent_dir (default_dir_chooser->get_filename());
        // make new session folder chooser point to the new default
-       new_folder_chooser.set_current_folder (Config->get_default_session_parent_dir());       
+       new_folder_chooser.set_current_folder (Config->get_default_session_parent_dir());
        config_changed ();
 }
 
@@ -243,6 +213,7 @@ Where would you like new %1 sessions to be stored by default?\n\n\
        vbox->pack_start (*txt, false, false);
        vbox->pack_start (*hbox, false, true);
 
+       cerr << "set default folder to " << poor_mans_glob (Config->get_default_session_parent_dir()) << endl;
        default_dir_chooser->set_current_folder (poor_mans_glob (Config->get_default_session_parent_dir()));
        default_dir_chooser->signal_current_folder_changed().connect (sigc::mem_fun (*this, &ArdourStartup::default_dir_changed));
        default_dir_chooser->show ();
@@ -376,13 +347,32 @@ void
 ArdourStartup::setup_final_page ()
 {
        string msg = string_compose (_("%1 is ready for use"), PROGRAM_NAME);
-       
-       final_page.set_markup (string_compose ("<span weight=\"bold\" size=\"large\">%1</span>", msg));
-       final_page.show ();
-       final_page_index = append_page (final_page);
-       set_page_complete (final_page, true);
-       set_page_header_image (final_page, icon_pixbuf);
-       set_page_type (final_page, ASSISTANT_PAGE_CONFIRM);
+
+       plugin_disco_button.signal_clicked().connect (sigc::mem_fun(*this, &ArdourStartup::discover_plugins));
+       plugin_disco_button.set_label (_("Scan for Plugins"));
+       plugin_disco_button.show ();
+
+       Gtk::Label* final_label = manage (new Label);
+       final_label->set_markup (string_compose ("<span weight=\"bold\" size=\"large\">%1</span>", msg));
+       final_label->show ();
+
+       VBox* vbox = manage (new VBox);
+       vbox->pack_start (*final_label, true, true);
+       if (!Profile->get_mixbus()) {
+               vbox->pack_start (plugin_disco_button, true, false);
+       }
+       vbox->show ();
+
+       final_page_index = append_page (*vbox);
+       set_page_complete (*vbox, true);
+       set_page_header_image (*vbox, icon_pixbuf);
+       set_page_type (*vbox, ASSISTANT_PAGE_CONFIRM);
+}
+
+void
+ArdourStartup::discover_plugins () {
+       plugin_disco_button.set_sensitive (false);
+       PluginManager::instance().refresh();
 }
 
 void
@@ -403,6 +393,14 @@ ArdourStartup::on_delete_event (GdkEventAny*)
 void
 ArdourStartup::on_apply ()
 {
+       /* file-chooser button does not emit 'current_folder_changed' signal
+        * when a folder from the dropdown or the sidebar is chosen.
+        * -> explicitly poll for the dir as suggested by the gtk documentation.
+        */
+       if (default_dir_chooser && default_dir_chooser->get_filename() != Config->get_default_session_parent_dir ()) {
+               config_modified = true;
+       }
+
        if (config_modified) {
 
                if (default_dir_chooser) {
@@ -425,10 +423,10 @@ ArdourStartup::on_apply ()
                /* "touch" the been-here-before path now we've successfully
                   made it through the first time setup (at least)
                */
-               ofstream fout (been_here_before_path().c_str());
+               PBD::ScopedFileDescriptor fout (g_open (been_here_before_path ().c_str(), O_CREAT|O_TRUNC|O_RDWR, 0666));
 
        }
-               
+
        _response = RESPONSE_OK;
        gtk_main_quit ();
 }
@@ -439,6 +437,3 @@ ArdourStartup::move_along_now ()
 {
        on_apply ();
 }
-
-
-