2017-07-03 06:27:25 -04:00
|
|
|
/*
|
2019-08-02 17:26:43 -04:00
|
|
|
* Copyright (C) 2017-2018 Johannes Mueller <github@johannes-mueller.org>
|
|
|
|
* Copyright (C) 2017-2019 Robin Gareus <robin@gareus.org>
|
|
|
|
* Copyright (C) 2017 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2017-07-03 06:27:25 -04:00
|
|
|
|
2017-07-07 13:53:45 -04:00
|
|
|
#include <map>
|
2017-08-19 18:54:19 -04:00
|
|
|
#include <vector>
|
2017-07-15 13:43:39 -04:00
|
|
|
#include <cerrno>
|
2017-07-07 13:53:45 -04:00
|
|
|
|
2017-07-03 06:27:25 -04:00
|
|
|
#include <glib/gstdio.h>
|
|
|
|
|
2017-07-07 13:53:45 -04:00
|
|
|
#include <gtkmm/filechooserdialog.h>
|
2017-08-17 15:42:32 -04:00
|
|
|
#include <gtkmm/frame.h>
|
2017-08-19 18:54:19 -04:00
|
|
|
#include <gtkmm/liststore.h>
|
2017-07-03 08:30:05 -04:00
|
|
|
#include <gtkmm/notebook.h>
|
2017-08-19 18:54:19 -04:00
|
|
|
#include <gtkmm/progressbar.h>
|
2017-07-07 13:53:45 -04:00
|
|
|
#include <gtkmm/separator.h>
|
2017-07-03 06:27:25 -04:00
|
|
|
#include <gtkmm/scrolledwindow.h>
|
2017-07-07 13:53:45 -04:00
|
|
|
#include <gtkmm/stock.h>
|
2017-08-19 18:54:19 -04:00
|
|
|
#include <gtkmm/textview.h>
|
2017-07-03 06:27:25 -04:00
|
|
|
#include <gtkmm/treeiter.h>
|
2017-08-19 18:54:19 -04:00
|
|
|
#include <gtkmm/treeview.h>
|
2017-07-03 06:27:25 -04:00
|
|
|
|
2017-07-07 13:53:45 -04:00
|
|
|
#include "pbd/basename.h"
|
2017-07-03 06:27:25 -04:00
|
|
|
#include "pbd/error.h"
|
2017-07-07 13:53:45 -04:00
|
|
|
#include "pbd/file_archive.h"
|
2017-07-06 02:07:55 -04:00
|
|
|
#include "pbd/file_utils.h"
|
2017-07-03 06:27:25 -04:00
|
|
|
#include "pbd/i18n.h"
|
2017-07-06 01:31:12 -04:00
|
|
|
#include "pbd/xml++.h"
|
2017-07-03 06:27:25 -04:00
|
|
|
|
2017-07-12 11:34:22 -04:00
|
|
|
#include "gtkmm2ext/gui_thread.h"
|
2019-01-02 11:37:03 -05:00
|
|
|
#include "gtkmm2ext/utils.h"
|
2017-07-12 11:34:22 -04:00
|
|
|
|
2020-04-05 09:41:37 -04:00
|
|
|
#include "ardour/directory_names.h"
|
2017-10-18 13:24:54 -04:00
|
|
|
#include "ardour/filename_extensions.h"
|
2017-07-12 11:34:22 -04:00
|
|
|
#include "ardour/filesystem_paths.h"
|
2017-07-03 06:27:25 -04:00
|
|
|
#include "ardour/template_utils.h"
|
|
|
|
|
2017-08-19 18:54:19 -04:00
|
|
|
#include "progress_reporter.h"
|
|
|
|
|
2017-07-03 06:27:25 -04:00
|
|
|
#include "template_dialog.h"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace Gtk;
|
|
|
|
using namespace PBD;
|
|
|
|
using namespace ARDOUR;
|
|
|
|
|
2017-08-19 18:54:19 -04:00
|
|
|
class TemplateManager : public Gtk::HBox,
|
|
|
|
public ProgressReporter
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~TemplateManager () {}
|
|
|
|
|
2017-08-26 08:07:45 -04:00
|
|
|
virtual void init () = 0;
|
2017-08-19 18:54:19 -04:00
|
|
|
void handle_dirty_description ();
|
|
|
|
|
|
|
|
PBD::Signal0<void> TemplatesImported;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
TemplateManager ();
|
|
|
|
|
2017-08-26 08:07:45 -04:00
|
|
|
Gtk::TextView _description_editor;
|
|
|
|
Gtk::Button _save_desc;
|
|
|
|
|
2017-08-19 18:54:19 -04:00
|
|
|
void setup_model (const std::vector<ARDOUR::TemplateInfo>& templates);
|
|
|
|
|
|
|
|
void row_selection_changed ();
|
|
|
|
|
|
|
|
virtual void delete_selected_template () = 0;
|
|
|
|
bool adjust_plugin_paths (XMLNode* node, const std::string& name, const std::string& new_name) const;
|
|
|
|
|
|
|
|
struct SessionTemplateColumns : public Gtk::TreeModel::ColumnRecord {
|
|
|
|
SessionTemplateColumns () {
|
|
|
|
add (name);
|
|
|
|
add (path);
|
|
|
|
add (description);
|
|
|
|
}
|
|
|
|
|
|
|
|
Gtk::TreeModelColumn<std::string> name;
|
|
|
|
Gtk::TreeModelColumn<std::string> path;
|
|
|
|
Gtk::TreeModelColumn<std::string> description;
|
|
|
|
};
|
|
|
|
|
|
|
|
Glib::RefPtr<Gtk::ListStore> _template_model;
|
|
|
|
SessionTemplateColumns _template_columns;
|
|
|
|
|
|
|
|
Gtk::TreeModel::const_iterator _current_selection;
|
|
|
|
|
|
|
|
Gtk::ProgressBar _progress_bar;
|
|
|
|
std::string _current_action;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void render_template_names (Gtk::CellRenderer* rnd, const Gtk::TreeModel::iterator& it);
|
|
|
|
void validate_edit (const Glib::ustring& path_string, const Glib::ustring& new_name);
|
|
|
|
void start_edit ();
|
|
|
|
|
|
|
|
void set_desc_dirty ();
|
|
|
|
|
|
|
|
bool key_event (GdkEventKey* ev);
|
|
|
|
|
2017-08-19 19:36:11 -04:00
|
|
|
virtual void get_templates (vector<TemplateInfo>& templates) const = 0;
|
|
|
|
|
2017-08-19 18:54:19 -04:00
|
|
|
virtual void rename_template (Gtk::TreeModel::iterator& item, const Glib::ustring& new_name) = 0;
|
|
|
|
|
|
|
|
virtual void save_template_desc ();
|
|
|
|
|
|
|
|
void export_all_templates ();
|
|
|
|
void import_template_set ();
|
|
|
|
|
|
|
|
virtual std::string templates_dir () const = 0;
|
2020-04-05 09:41:37 -04:00
|
|
|
virtual std::string templates_dir_basename () const = 0;
|
2017-08-19 18:54:19 -04:00
|
|
|
virtual std::string template_file (const Gtk::TreeModel::const_iterator& item) const = 0;
|
|
|
|
|
|
|
|
virtual bool adjust_xml_tree (XMLTree& tree, const std::string& old_name, const std::string& new_name) const = 0;
|
|
|
|
|
|
|
|
Gtk::TreeView _template_treeview;
|
|
|
|
Gtk::CellRendererText _validating_cellrenderer;
|
|
|
|
Gtk::TreeView::Column _validated_column;
|
|
|
|
|
|
|
|
bool _desc_dirty;
|
|
|
|
|
|
|
|
Gtk::Button _remove_button;
|
|
|
|
Gtk::Button _rename_button;
|
|
|
|
|
|
|
|
Gtk::Button _export_all_templates_button;
|
|
|
|
Gtk::Button _import_template_set_button;
|
|
|
|
|
2017-08-20 08:35:29 -04:00
|
|
|
sigc::connection _cursor_changed_connection;
|
|
|
|
|
2017-08-19 18:54:19 -04:00
|
|
|
void update_progress_gui (float p);
|
|
|
|
};
|
|
|
|
|
|
|
|
class SessionTemplateManager : public TemplateManager
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SessionTemplateManager () : TemplateManager () {}
|
|
|
|
~SessionTemplateManager () {}
|
|
|
|
|
2017-08-26 08:07:45 -04:00
|
|
|
void init ();
|
|
|
|
|
2017-08-19 19:36:11 -04:00
|
|
|
void get_templates (vector<TemplateInfo>& templates) const;
|
2017-08-19 18:54:19 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
void rename_template (Gtk::TreeModel::iterator& item, const Glib::ustring& new_name);
|
|
|
|
void delete_selected_template ();
|
|
|
|
|
|
|
|
std::string templates_dir () const;
|
2020-04-05 09:41:37 -04:00
|
|
|
virtual std::string templates_dir_basename () const;
|
2017-08-19 18:54:19 -04:00
|
|
|
std::string template_file (const Gtk::TreeModel::const_iterator& item) const;
|
|
|
|
|
|
|
|
bool adjust_xml_tree (XMLTree& tree, const std::string& old_name, const std::string& new_name) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class RouteTemplateManager : public TemplateManager
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RouteTemplateManager () : TemplateManager () {}
|
|
|
|
~RouteTemplateManager () {}
|
|
|
|
|
2017-08-26 08:07:45 -04:00
|
|
|
void init ();
|
|
|
|
|
2017-08-19 19:36:11 -04:00
|
|
|
void get_templates (vector<TemplateInfo>& templates) const;
|
2017-08-19 18:54:19 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
void rename_template (Gtk::TreeModel::iterator& item, const Glib::ustring& new_name);
|
|
|
|
void delete_selected_template ();
|
|
|
|
|
|
|
|
std::string templates_dir () const;
|
2020-04-05 09:41:37 -04:00
|
|
|
virtual std::string templates_dir_basename () const;
|
2017-08-19 18:54:19 -04:00
|
|
|
std::string template_file (const Gtk::TreeModel::const_iterator& item) const;
|
|
|
|
|
|
|
|
bool adjust_xml_tree (XMLTree& tree, const std::string& old_name, const std::string& new_name) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-07-03 06:27:25 -04:00
|
|
|
TemplateDialog::TemplateDialog ()
|
2017-07-03 08:30:05 -04:00
|
|
|
: ArdourDialog ("Manage Templates")
|
|
|
|
{
|
|
|
|
Notebook* nb = manage (new Notebook);
|
|
|
|
|
|
|
|
SessionTemplateManager* session_tm = manage (new SessionTemplateManager);
|
|
|
|
nb->append_page (*session_tm, _("Session Templates"));
|
|
|
|
|
|
|
|
RouteTemplateManager* route_tm = manage (new RouteTemplateManager);
|
|
|
|
nb->append_page (*route_tm, _("Track Templates"));
|
|
|
|
|
|
|
|
get_vbox()->pack_start (*nb);
|
2017-08-20 13:10:50 -04:00
|
|
|
add_button (_("Done"), Gtk::RESPONSE_OK);
|
2017-07-03 08:30:05 -04:00
|
|
|
|
2017-07-07 13:53:45 -04:00
|
|
|
get_vbox()->show_all();
|
|
|
|
|
|
|
|
session_tm->init ();
|
|
|
|
route_tm->init ();
|
2017-07-12 11:34:22 -04:00
|
|
|
|
|
|
|
session_tm->TemplatesImported.connect (*this, invalidator (*this), boost::bind (&RouteTemplateManager::init, route_tm), gui_context ());
|
|
|
|
route_tm->TemplatesImported.connect (*this, invalidator (*this), boost::bind (&SessionTemplateManager::init, session_tm), gui_context ());
|
2017-08-19 18:29:46 -04:00
|
|
|
|
|
|
|
signal_hide().connect (sigc::mem_fun (session_tm, &TemplateManager::handle_dirty_description));
|
|
|
|
signal_hide().connect (sigc::mem_fun (route_tm, &TemplateManager::handle_dirty_description));
|
2017-08-24 09:31:45 -04:00
|
|
|
nb->signal_switch_page().connect (sigc::hide (sigc::hide (sigc::mem_fun (session_tm, &TemplateManager::handle_dirty_description))));
|
|
|
|
nb->signal_switch_page().connect (sigc::hide (sigc::hide (sigc::mem_fun (route_tm, &TemplateManager::handle_dirty_description))));
|
2017-07-03 08:30:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
TemplateManager::TemplateManager ()
|
|
|
|
: HBox ()
|
2017-07-07 13:53:45 -04:00
|
|
|
, ProgressReporter ()
|
2017-08-17 15:42:32 -04:00
|
|
|
, _save_desc (_("Save Description"))
|
|
|
|
, _desc_dirty (false)
|
2017-07-03 06:27:25 -04:00
|
|
|
, _remove_button (_("Remove"))
|
|
|
|
, _rename_button (_("Rename"))
|
2017-07-07 13:53:45 -04:00
|
|
|
, _export_all_templates_button (_("Export all"))
|
|
|
|
, _import_template_set_button (_("Import"))
|
2017-07-03 06:27:25 -04:00
|
|
|
{
|
2017-07-03 08:30:05 -04:00
|
|
|
_template_model = ListStore::create (_template_columns);
|
|
|
|
_template_treeview.set_model (_template_model);
|
2017-07-03 06:27:25 -04:00
|
|
|
|
|
|
|
_validated_column.set_title (_("Template Name"));
|
|
|
|
_validated_column.pack_start (_validating_cellrenderer);
|
2017-07-03 08:30:05 -04:00
|
|
|
_template_treeview.append_column (_validated_column);
|
2017-07-03 06:27:25 -04:00
|
|
|
_validating_cellrenderer.property_editable() = true;
|
|
|
|
|
2017-07-03 08:30:05 -04:00
|
|
|
_validated_column.set_cell_data_func (_validating_cellrenderer, sigc::mem_fun (*this, &TemplateManager::render_template_names));
|
|
|
|
_validating_cellrenderer.signal_edited().connect (sigc::mem_fun (*this, &TemplateManager::validate_edit));
|
2017-08-20 08:35:29 -04:00
|
|
|
_cursor_changed_connection = _template_treeview.signal_cursor_changed().connect (sigc::mem_fun (*this, &TemplateManager::row_selection_changed));
|
2017-07-03 08:30:05 -04:00
|
|
|
_template_treeview.signal_key_press_event().connect (sigc::mem_fun (*this, &TemplateManager::key_event));
|
2017-07-03 06:27:25 -04:00
|
|
|
|
|
|
|
ScrolledWindow* sw = manage (new ScrolledWindow);
|
2017-07-03 07:05:21 -04:00
|
|
|
sw->property_hscrollbar_policy() = POLICY_AUTOMATIC;
|
2017-07-03 08:30:05 -04:00
|
|
|
sw->add (_template_treeview);
|
2017-07-03 06:27:25 -04:00
|
|
|
sw->set_size_request (300, 200);
|
|
|
|
|
2017-07-07 13:53:45 -04:00
|
|
|
VBox* vb_btns = manage (new VBox);
|
|
|
|
vb_btns->set_spacing (4);
|
|
|
|
vb_btns->pack_start (_rename_button, false, false);
|
|
|
|
vb_btns->pack_start (_remove_button, false, false);
|
2017-08-17 15:42:32 -04:00
|
|
|
vb_btns->pack_start (_save_desc, false, false);
|
2017-07-03 06:27:25 -04:00
|
|
|
|
|
|
|
_rename_button.set_sensitive (false);
|
2017-07-03 08:30:05 -04:00
|
|
|
_rename_button.signal_clicked().connect (sigc::mem_fun (*this, &TemplateManager::start_edit));
|
2017-07-03 06:27:25 -04:00
|
|
|
_remove_button.set_sensitive (false);
|
2017-07-03 08:30:05 -04:00
|
|
|
_remove_button.signal_clicked().connect (sigc::mem_fun (*this, &TemplateManager::delete_selected_template));
|
2017-07-03 06:27:25 -04:00
|
|
|
|
2017-07-07 13:53:45 -04:00
|
|
|
vb_btns->pack_start (*(manage (new VSeparator ())));
|
|
|
|
|
|
|
|
vb_btns->pack_start (_export_all_templates_button, false, false);
|
|
|
|
vb_btns->pack_start (_import_template_set_button, false, false);
|
|
|
|
|
2017-07-12 11:44:35 -04:00
|
|
|
_export_all_templates_button.set_sensitive (false);
|
2017-07-07 13:53:45 -04:00
|
|
|
_export_all_templates_button.signal_clicked().connect (sigc::mem_fun (*this, &TemplateManager::export_all_templates));
|
|
|
|
|
|
|
|
_import_template_set_button.set_sensitive (true);
|
|
|
|
_import_template_set_button.signal_clicked().connect (sigc::mem_fun (*this, &TemplateManager::import_template_set));
|
|
|
|
|
2017-07-03 08:30:05 -04:00
|
|
|
set_spacing (6);
|
2017-07-07 13:53:45 -04:00
|
|
|
|
|
|
|
VBox* vb = manage (new VBox);
|
|
|
|
vb->pack_start (*sw);
|
|
|
|
vb->pack_start (_progress_bar);
|
|
|
|
|
2018-06-09 13:08:15 -04:00
|
|
|
Frame* desc_frame = manage (new Frame (_("Description")));
|
2017-08-17 15:42:32 -04:00
|
|
|
|
|
|
|
_description_editor.set_wrap_mode (Gtk::WRAP_WORD);
|
|
|
|
_description_editor.set_size_request (300,400);
|
|
|
|
_description_editor.set_border_width (6);
|
|
|
|
|
|
|
|
_save_desc.set_sensitive (false);
|
|
|
|
_save_desc.signal_clicked().connect (sigc::mem_fun (*this, &TemplateManager::save_template_desc));
|
|
|
|
|
|
|
|
_description_editor.get_buffer()->signal_changed().connect (sigc::mem_fun (*this, &TemplateManager::set_desc_dirty));
|
|
|
|
|
2018-06-09 13:08:15 -04:00
|
|
|
desc_frame->add (_description_editor);
|
2017-08-17 15:42:32 -04:00
|
|
|
|
2017-07-03 08:30:05 -04:00
|
|
|
pack_start (*vb);
|
2018-06-09 13:08:15 -04:00
|
|
|
pack_start (*desc_frame);
|
2017-07-07 13:53:45 -04:00
|
|
|
pack_start (*vb_btns);
|
2017-07-03 06:27:25 -04:00
|
|
|
|
|
|
|
show_all_children ();
|
2017-07-07 13:53:45 -04:00
|
|
|
_progress_bar.hide ();
|
2017-07-03 06:27:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-07-03 08:30:05 -04:00
|
|
|
TemplateManager::setup_model (const vector<TemplateInfo>& templates)
|
2017-07-03 06:27:25 -04:00
|
|
|
{
|
2017-07-03 08:30:05 -04:00
|
|
|
_template_model->clear ();
|
2017-07-03 06:27:25 -04:00
|
|
|
|
2017-07-03 08:30:05 -04:00
|
|
|
for (vector<TemplateInfo>::const_iterator it = templates.begin(); it != templates.end(); ++it) {
|
2017-07-03 06:27:25 -04:00
|
|
|
TreeModel::Row row;
|
2017-07-03 08:30:05 -04:00
|
|
|
row = *(_template_model->append ());
|
2017-07-03 06:27:25 -04:00
|
|
|
|
2017-07-03 08:30:05 -04:00
|
|
|
row[_template_columns.name] = it->name;
|
|
|
|
row[_template_columns.path] = it->path;
|
2017-08-17 15:42:32 -04:00
|
|
|
row[_template_columns.description] = it->description;
|
2017-07-03 06:27:25 -04:00
|
|
|
}
|
2017-07-12 11:44:35 -04:00
|
|
|
|
|
|
|
_export_all_templates_button.set_sensitive (!templates.empty ());
|
2017-07-03 06:27:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-08-19 18:29:46 -04:00
|
|
|
TemplateManager::handle_dirty_description ()
|
2017-07-03 06:27:25 -04:00
|
|
|
{
|
2017-08-19 18:29:46 -04:00
|
|
|
if (_desc_dirty && _current_selection) {
|
|
|
|
ArdourDialog dlg (_("Description not saved"), true);
|
|
|
|
const string name = _current_selection->get_value (_template_columns.name);
|
2018-02-28 14:01:11 -05:00
|
|
|
Label msg (string_compose (_("The description of template \"%1\" has been modified but has not been saved yet.\n"
|
2017-08-19 18:29:46 -04:00
|
|
|
"Do you want to save it?"), name));
|
|
|
|
dlg.get_vbox()->pack_start (msg);
|
|
|
|
msg.show ();
|
|
|
|
dlg.add_button (_("Save"), RESPONSE_ACCEPT);
|
|
|
|
dlg.add_button (_("Discard"), RESPONSE_REJECT);
|
|
|
|
dlg.set_default_response (RESPONSE_REJECT);
|
|
|
|
|
|
|
|
int response = dlg.run ();
|
|
|
|
|
|
|
|
if (response == RESPONSE_ACCEPT) {
|
|
|
|
save_template_desc ();
|
|
|
|
} else {
|
|
|
|
_description_editor.get_buffer()->set_text (_current_selection->get_value (_template_columns.description));
|
2017-07-03 06:27:25 -04:00
|
|
|
}
|
2020-04-02 05:56:47 -04:00
|
|
|
_desc_dirty = false;
|
2017-07-03 06:27:25 -04:00
|
|
|
}
|
2017-08-19 18:29:46 -04:00
|
|
|
}
|
2017-07-03 06:27:25 -04:00
|
|
|
|
2017-08-19 18:29:46 -04:00
|
|
|
void
|
|
|
|
TemplateManager::row_selection_changed ()
|
|
|
|
{
|
2017-08-19 19:36:11 -04:00
|
|
|
if (_current_selection) {
|
|
|
|
handle_dirty_description ();
|
|
|
|
} else {
|
|
|
|
_description_editor.get_buffer()->set_text ("");
|
|
|
|
}
|
2017-08-19 18:29:46 -04:00
|
|
|
|
|
|
|
_current_selection = _template_treeview.get_selection()->get_selected ();
|
|
|
|
if (_current_selection) {
|
|
|
|
const string desc = _current_selection->get_value (_template_columns.description);
|
|
|
|
_description_editor.get_buffer()->set_text (desc);
|
|
|
|
}
|
|
|
|
|
2017-08-20 08:35:29 -04:00
|
|
|
_desc_dirty = false;
|
|
|
|
_save_desc.set_sensitive (false);
|
|
|
|
|
2017-08-19 19:36:11 -04:00
|
|
|
_description_editor.set_sensitive (_current_selection);
|
2017-08-19 18:29:46 -04:00
|
|
|
_rename_button.set_sensitive (_current_selection);
|
|
|
|
_remove_button.set_sensitive (_current_selection);
|
2017-07-03 06:27:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-07-03 08:30:05 -04:00
|
|
|
TemplateManager::render_template_names (Gtk::CellRenderer*, const Gtk::TreeModel::iterator& it)
|
2017-07-03 06:27:25 -04:00
|
|
|
{
|
|
|
|
if (it) {
|
2017-07-03 08:30:05 -04:00
|
|
|
_validating_cellrenderer.property_text () = it->get_value (_template_columns.name);
|
2017-07-03 06:27:25 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-07-03 08:30:05 -04:00
|
|
|
TemplateManager::validate_edit (const Glib::ustring& path_string, const Glib::ustring& new_name)
|
2017-07-03 06:27:25 -04:00
|
|
|
{
|
|
|
|
const TreePath path (path_string);
|
2017-07-03 08:30:05 -04:00
|
|
|
TreeModel::iterator current = _template_model->get_iter (path);
|
2017-07-03 06:27:25 -04:00
|
|
|
|
2017-07-03 08:30:05 -04:00
|
|
|
if (current->get_value (_template_columns.name) == new_name) {
|
2017-07-03 06:27:25 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-07-03 08:30:05 -04:00
|
|
|
TreeModel::Children rows = _template_model->children ();
|
2017-07-03 06:27:25 -04:00
|
|
|
|
|
|
|
bool found = false;
|
|
|
|
for (TreeModel::Children::const_iterator it = rows.begin(); it != rows.end(); ++it) {
|
2017-07-03 08:30:05 -04:00
|
|
|
if (it->get_value (_template_columns.name) == new_name) {
|
2017-07-03 06:27:25 -04:00
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found) {
|
|
|
|
error << string_compose (_("Template of name \"%1\" already exists"), new_name) << endmsg;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
rename_template (current, new_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-07-03 08:30:05 -04:00
|
|
|
TemplateManager::start_edit ()
|
2017-07-03 06:27:25 -04:00
|
|
|
{
|
|
|
|
TreeModel::Path path;
|
|
|
|
TreeViewColumn* col;
|
2017-07-03 08:30:05 -04:00
|
|
|
_template_treeview.get_cursor (path, col);
|
2017-08-20 08:35:29 -04:00
|
|
|
_cursor_changed_connection.block ();
|
2017-07-03 08:30:05 -04:00
|
|
|
_template_treeview.set_cursor (path, *col, /*set_editing =*/ true);
|
2017-08-20 08:35:29 -04:00
|
|
|
_cursor_changed_connection.unblock ();
|
2017-07-03 08:30:05 -04:00
|
|
|
}
|
|
|
|
|
2017-08-17 15:42:32 -04:00
|
|
|
void
|
|
|
|
TemplateManager::set_desc_dirty ()
|
|
|
|
{
|
|
|
|
_desc_dirty = true;
|
|
|
|
_save_desc.set_sensitive (true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TemplateManager::save_template_desc ()
|
|
|
|
{
|
2017-08-19 18:29:46 -04:00
|
|
|
const string file_path = template_file (_current_selection);
|
2017-08-17 15:42:32 -04:00
|
|
|
|
2017-08-20 13:53:42 -04:00
|
|
|
string desc_txt = _description_editor.get_buffer()->get_text ();
|
|
|
|
string::reverse_iterator wss = desc_txt.rbegin();
|
|
|
|
while (wss != desc_txt.rend() && isspace (*wss)) {
|
|
|
|
desc_txt.erase (--(wss++).base());
|
|
|
|
}
|
|
|
|
|
2017-08-19 18:29:46 -04:00
|
|
|
_current_selection->set_value (_template_columns.description, desc_txt);
|
2017-08-17 15:42:32 -04:00
|
|
|
|
|
|
|
XMLTree tree;
|
|
|
|
|
|
|
|
if (!tree.read(file_path)) {
|
|
|
|
error << string_compose (_("Could not parse template file \"%1\"."), file_path) << endmsg;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-08-20 16:26:54 -04:00
|
|
|
tree.root()->remove_nodes_and_delete (X_("description"));
|
2017-08-19 13:45:08 -04:00
|
|
|
|
2017-08-30 11:45:14 -04:00
|
|
|
if (!desc_txt.empty ()) {
|
|
|
|
XMLNode* desc = new XMLNode (X_("description"));
|
|
|
|
XMLNode* dn = new XMLNode (X_("content"), desc_txt);
|
|
|
|
desc->add_child_nocopy (*dn);
|
2017-08-30 12:01:17 -04:00
|
|
|
tree.root()->add_child_nocopy (*desc);
|
2017-08-30 11:45:14 -04:00
|
|
|
}
|
2017-08-17 15:42:32 -04:00
|
|
|
|
|
|
|
if (!tree.write ()) {
|
|
|
|
error << string_compose(X_("Could not write to template file \"%1\"."), file_path) << endmsg;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_save_desc.set_sensitive (false);
|
|
|
|
_desc_dirty = false;
|
|
|
|
}
|
|
|
|
|
2017-07-03 08:30:05 -04:00
|
|
|
bool
|
|
|
|
TemplateManager::key_event (GdkEventKey* ev)
|
|
|
|
{
|
|
|
|
if (ev->keyval == GDK_KEY_F2) {
|
|
|
|
start_edit ();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (ev->keyval == GDK_KEY_Delete) {
|
|
|
|
delete_selected_template ();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-08-26 08:07:45 -04:00
|
|
|
static bool
|
|
|
|
accept_all_files (string const &, void *)
|
2017-07-07 13:53:45 -04:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-08-26 08:07:45 -04:00
|
|
|
static void
|
|
|
|
_set_progress (Progress* p, size_t n, size_t t)
|
2017-07-07 13:53:45 -04:00
|
|
|
{
|
|
|
|
p->set_progress (float (n) / float(t));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
TemplateManager::export_all_templates ()
|
|
|
|
{
|
2017-07-07 16:01:01 -04:00
|
|
|
GError* err = NULL;
|
|
|
|
char* td = g_dir_make_tmp ("ardour-templates-XXXXXX", &err);
|
|
|
|
|
|
|
|
if (!td) {
|
|
|
|
error << string_compose(_("Could not make tmpdir: %1"), err->message) << endmsg;
|
|
|
|
return;
|
|
|
|
}
|
2020-04-04 18:07:54 -04:00
|
|
|
const string tmpdir = PBD::canonical_path (td);
|
2017-07-07 16:01:01 -04:00
|
|
|
g_free (td);
|
|
|
|
g_clear_error (&err);
|
|
|
|
|
2017-07-07 13:53:45 -04:00
|
|
|
FileChooserDialog dialog(_("Save Exported Template Archive"), FILE_CHOOSER_ACTION_SAVE);
|
2019-01-02 11:37:03 -05:00
|
|
|
Gtkmm2ext::add_volume_shortcuts (dialog);
|
2017-10-18 13:24:54 -04:00
|
|
|
dialog.set_filename (X_("templates"));
|
2017-07-07 13:53:45 -04:00
|
|
|
|
|
|
|
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
|
|
|
|
dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
|
|
|
|
|
|
|
|
FileFilter archive_filter;
|
2017-10-18 13:24:54 -04:00
|
|
|
archive_filter.add_pattern (string_compose(X_("*%1"), ARDOUR::template_archive_suffix));
|
2017-07-07 13:53:45 -04:00
|
|
|
archive_filter.set_name (_("Template archives"));
|
|
|
|
dialog.add_filter (archive_filter);
|
|
|
|
|
|
|
|
int result = dialog.run ();
|
|
|
|
|
|
|
|
if (result != RESPONSE_OK || !dialog.get_filename().length()) {
|
2017-07-12 13:57:53 -04:00
|
|
|
PBD::remove_directory (tmpdir);
|
2017-07-07 13:53:45 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-07-12 13:57:53 -04:00
|
|
|
string filename = dialog.get_filename ();
|
2017-10-18 13:24:54 -04:00
|
|
|
filename += ARDOUR::template_archive_suffix;
|
2017-07-12 13:57:53 -04:00
|
|
|
|
|
|
|
if (g_file_test (filename.c_str(), G_FILE_TEST_EXISTS)) {
|
|
|
|
ArdourDialog dlg (_("File exists"), true);
|
|
|
|
Label msg (string_compose (_("The file %1 already exists."), filename));
|
|
|
|
dlg.get_vbox()->pack_start (msg);
|
|
|
|
msg.show ();
|
|
|
|
dlg.add_button (_("Overwrite"), RESPONSE_ACCEPT);
|
|
|
|
dlg.add_button (_("Cancel"), RESPONSE_REJECT);
|
|
|
|
dlg.set_default_response (RESPONSE_REJECT);
|
|
|
|
|
|
|
|
result = dlg.run ();
|
|
|
|
|
|
|
|
if (result == RESPONSE_REJECT) {
|
|
|
|
PBD::remove_directory (tmpdir);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-12 11:34:22 -04:00
|
|
|
PBD::copy_recurse (templates_dir (), Glib::build_filename (tmpdir, Glib::path_get_basename (templates_dir ())));
|
2017-07-07 13:53:45 -04:00
|
|
|
|
|
|
|
vector<string> files;
|
|
|
|
PBD::find_files_matching_regex (files, tmpdir, string ("\\.template$"), /* recurse = */ true);
|
|
|
|
|
|
|
|
vector<string>::const_iterator it;
|
|
|
|
for (it = files.begin(); it != files.end(); ++it) {
|
|
|
|
const string bn = PBD::basename_nosuffix (*it);
|
|
|
|
const string old_path = Glib::build_filename (templates_dir (), bn);
|
|
|
|
const string new_path = Glib::build_filename ("$TEMPLATEDIR", bn);
|
|
|
|
|
|
|
|
XMLTree tree;
|
|
|
|
if (!tree.read (*it)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (adjust_xml_tree (tree, old_path, new_path)) {
|
|
|
|
tree.write (*it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
find_files_matching_filter (files, tmpdir, accept_all_files, 0, false, true, true);
|
|
|
|
|
|
|
|
std::map<std::string, std::string> filemap;
|
|
|
|
for (it = files.begin(); it != files.end(); ++it) {
|
|
|
|
filemap[*it] = it->substr (tmpdir.size()+1, it->size() - tmpdir.size() - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
_current_action = _("Exporting templates");
|
|
|
|
|
2017-07-12 13:57:53 -04:00
|
|
|
PBD::FileArchive ar (filename);
|
2017-07-07 13:53:45 -04:00
|
|
|
PBD::ScopedConnectionList progress_connection;
|
|
|
|
ar.progress.connect_same_thread (progress_connection, boost::bind (&_set_progress, this, _1, _2));
|
|
|
|
ar.create (filemap);
|
|
|
|
|
|
|
|
PBD::remove_directory (tmpdir);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TemplateManager::import_template_set ()
|
|
|
|
{
|
|
|
|
FileChooserDialog dialog (_("Import template archives"));
|
|
|
|
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
|
|
|
|
dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
|
|
|
|
|
|
|
|
FileFilter archive_filter;
|
2017-10-18 13:24:54 -04:00
|
|
|
archive_filter.add_pattern (string_compose(X_("*%1"), ARDOUR::template_archive_suffix));
|
2020-04-01 16:41:52 -04:00
|
|
|
archive_filter.add_pattern (X_("*.tar.xz")); // template archives from 5.x
|
2017-07-07 13:53:45 -04:00
|
|
|
archive_filter.set_name (_("Template archives"));
|
|
|
|
dialog.add_filter (archive_filter);
|
|
|
|
|
|
|
|
int result = dialog.run ();
|
|
|
|
|
|
|
|
if (result != RESPONSE_OK || !dialog.get_filename().length()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_current_action = _("Importing templates");
|
|
|
|
|
|
|
|
FileArchive ar (dialog.get_filename ());
|
|
|
|
PBD::ScopedConnectionList progress_connection;
|
|
|
|
ar.progress.connect_same_thread (progress_connection, boost::bind (&_set_progress, this, _1, _2));
|
|
|
|
|
2020-04-05 09:41:37 -04:00
|
|
|
for (std::string fn = ar.next_file_name(); !fn.empty(); fn = ar.next_file_name()) {
|
|
|
|
const size_t pos = fn.find (templates_dir_basename ());
|
|
|
|
if (pos == string::npos) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
const std::string dest = Glib::build_filename (user_config_directory(), fn.substr (pos));
|
|
|
|
ar.extract_current_file (dest);
|
|
|
|
}
|
2017-07-07 13:53:45 -04:00
|
|
|
vector<string> files;
|
|
|
|
PBD::find_files_matching_regex (files, templates_dir (), string ("\\.template$"), /* recurse = */ true);
|
|
|
|
|
|
|
|
vector<string>::const_iterator it;
|
|
|
|
for (it = files.begin(); it != files.end(); ++it) {
|
|
|
|
const string bn = PBD::basename_nosuffix (*it);
|
|
|
|
const string old_path = Glib::build_filename ("$TEMPLATEDIR", bn);
|
|
|
|
const string new_path = Glib::build_filename (templates_dir (), bn);
|
|
|
|
|
|
|
|
XMLTree tree;
|
|
|
|
if (!tree.read (*it)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (adjust_xml_tree (tree, old_path, new_path)) {
|
|
|
|
tree.write (*it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
init ();
|
2017-07-12 11:34:22 -04:00
|
|
|
TemplatesImported (); /* emit signal */
|
2017-07-07 13:53:45 -04:00
|
|
|
}
|
|
|
|
|
2017-07-06 01:31:12 -04:00
|
|
|
bool
|
|
|
|
TemplateManager::adjust_plugin_paths (XMLNode* node, const string& name, const string& new_name) const
|
|
|
|
{
|
|
|
|
bool adjusted = false;
|
|
|
|
|
|
|
|
const XMLNodeList& procs = node->children (X_("Processor"));
|
|
|
|
XMLNodeConstIterator pit;
|
|
|
|
for (pit = procs.begin(); pit != procs.end(); ++pit) {
|
|
|
|
XMLNode* lv2_node = (*pit)->child (X_("lv2"));
|
|
|
|
if (!lv2_node) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
string template_dir;
|
|
|
|
|
|
|
|
if (!lv2_node->get_property (X_("template-dir"), template_dir)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const int suffix_pos = template_dir.size() - name.size();
|
|
|
|
if (suffix_pos < 0) {
|
|
|
|
cerr << "Template name\"" << name << "\" longer than template-dir \"" << template_dir << "\", WTH?" << endl;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (template_dir.compare (suffix_pos, template_dir.size(), name)) {
|
|
|
|
cerr << "Template name \"" << name << "\" no suffix of template-dir \"" << template_dir << "\"" << endl;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const string new_template_dir = template_dir.substr (0, suffix_pos) + new_name;
|
|
|
|
lv2_node->set_property (X_("template-dir"), new_template_dir);
|
|
|
|
|
|
|
|
adjusted = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return adjusted;
|
|
|
|
}
|
2017-07-03 08:30:05 -04:00
|
|
|
|
2017-07-07 13:53:45 -04:00
|
|
|
void
|
|
|
|
TemplateManager::update_progress_gui (float p)
|
|
|
|
{
|
|
|
|
if (p >= 1.0) {
|
|
|
|
_progress_bar.hide ();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_progress_bar.show ();
|
|
|
|
_progress_bar.set_text (_current_action);
|
|
|
|
_progress_bar.set_fraction (p);
|
|
|
|
}
|
|
|
|
|
2017-08-26 08:07:45 -04:00
|
|
|
void
|
|
|
|
SessionTemplateManager::init ()
|
|
|
|
{
|
|
|
|
vector<TemplateInfo> templates;
|
|
|
|
get_templates (templates);
|
|
|
|
setup_model (templates);
|
|
|
|
|
|
|
|
_progress_bar.hide ();
|
|
|
|
_description_editor.set_sensitive (false);
|
|
|
|
_save_desc.set_sensitive (false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
RouteTemplateManager::init ()
|
|
|
|
{
|
|
|
|
vector<TemplateInfo> templates;
|
|
|
|
get_templates (templates);
|
|
|
|
setup_model (templates);
|
|
|
|
|
|
|
|
_progress_bar.hide ();
|
|
|
|
_description_editor.set_sensitive (false);
|
|
|
|
_save_desc.set_sensitive (false);
|
|
|
|
}
|
|
|
|
|
2017-08-19 19:36:11 -04:00
|
|
|
void
|
|
|
|
SessionTemplateManager::get_templates (vector<TemplateInfo>& templates) const
|
2017-07-03 08:30:05 -04:00
|
|
|
{
|
2017-08-17 15:42:32 -04:00
|
|
|
find_session_templates (templates, /* read_xml = */ true);
|
2017-07-03 08:30:05 -04:00
|
|
|
}
|
|
|
|
|
2017-08-26 08:07:45 -04:00
|
|
|
void
|
|
|
|
RouteTemplateManager::get_templates (vector<TemplateInfo>& templates) const
|
2017-07-03 08:30:05 -04:00
|
|
|
{
|
|
|
|
find_route_templates (templates);
|
2017-07-03 06:27:25 -04:00
|
|
|
}
|
|
|
|
|
2017-07-14 14:58:41 -04:00
|
|
|
#include <cerrno>
|
2017-07-07 13:53:45 -04:00
|
|
|
|
2017-07-03 06:27:25 -04:00
|
|
|
void
|
2017-07-06 01:31:12 -04:00
|
|
|
SessionTemplateManager::rename_template (TreeModel::iterator& item, const Glib::ustring& new_name_)
|
2017-07-03 06:27:25 -04:00
|
|
|
{
|
2017-07-06 01:31:12 -04:00
|
|
|
const string old_path = item->get_value (_template_columns.path);
|
|
|
|
const string old_name = item->get_value (_template_columns.name);
|
|
|
|
const string new_name = string (new_name_);
|
2017-07-03 08:30:05 -04:00
|
|
|
|
2017-09-22 11:16:04 -04:00
|
|
|
if (old_name == new_name) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-07-06 01:31:12 -04:00
|
|
|
const string old_file_old_path = Glib::build_filename (old_path, old_name+".template");
|
2017-07-03 08:30:05 -04:00
|
|
|
|
2017-07-06 01:31:12 -04:00
|
|
|
XMLTree tree;
|
|
|
|
|
|
|
|
if (!tree.read(old_file_old_path)) {
|
|
|
|
error << string_compose (_("Could not parse template file \"%1\"."), old_file_old_path) << endmsg;
|
2017-07-03 06:27:25 -04:00
|
|
|
return;
|
|
|
|
}
|
2017-07-06 01:31:12 -04:00
|
|
|
XMLNode* root = tree.root();
|
|
|
|
|
|
|
|
const XMLNode* const routes_node = root->child (X_("Routes"));
|
|
|
|
if (routes_node) {
|
|
|
|
const XMLNodeList& routes = routes_node->children (X_("Route"));
|
|
|
|
XMLNodeConstIterator rit;
|
|
|
|
for (rit = routes.begin(); rit != routes.end(); ++rit) {
|
|
|
|
adjust_plugin_paths (*rit, old_name, new_name);
|
2017-07-03 08:30:05 -04:00
|
|
|
}
|
2017-07-06 01:31:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
const string new_file_old_path = Glib::build_filename (old_path, new_name+".template");
|
|
|
|
|
|
|
|
tree.set_filename (new_file_old_path);
|
|
|
|
|
|
|
|
if (!tree.write ()) {
|
|
|
|
error << string_compose(_("Could not write to new template file \"%1\"."), new_file_old_path);
|
2017-07-03 08:30:05 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-07-06 01:31:12 -04:00
|
|
|
const string new_path = Glib::build_filename (user_template_directory (), new_name);
|
|
|
|
|
|
|
|
if (g_rename (old_path.c_str(), new_path.c_str()) != 0) {
|
|
|
|
error << string_compose (_("Could not rename template directory from \"%1\" to \"%2\": %3"),
|
|
|
|
old_path, new_path, strerror (errno)) << endmsg;
|
|
|
|
g_unlink (new_file_old_path.c_str());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const string old_file_new_path = Glib::build_filename (new_path, old_name+".template");
|
|
|
|
if (g_unlink (old_file_new_path.c_str())) {
|
|
|
|
error << string_compose (X_("Could not delete old template file \"%1\": %2"),
|
|
|
|
old_file_new_path, strerror (errno)) << endmsg;
|
|
|
|
}
|
|
|
|
|
|
|
|
item->set_value (_template_columns.name, new_name);
|
2017-07-03 08:30:05 -04:00
|
|
|
item->set_value (_template_columns.path, new_path);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SessionTemplateManager::delete_selected_template ()
|
|
|
|
{
|
2017-08-19 18:29:46 -04:00
|
|
|
if (!_current_selection) {
|
2017-07-03 08:30:05 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-08-19 18:29:46 -04:00
|
|
|
PBD::remove_directory (_current_selection->get_value (_template_columns.path));
|
2017-07-03 06:27:25 -04:00
|
|
|
|
2017-08-19 18:29:46 -04:00
|
|
|
_template_model->erase (_current_selection);
|
2017-08-19 19:36:11 -04:00
|
|
|
_current_selection = TreeIter ();
|
2017-07-03 06:27:25 -04:00
|
|
|
row_selection_changed ();
|
|
|
|
}
|
|
|
|
|
2017-07-07 13:53:45 -04:00
|
|
|
string
|
|
|
|
SessionTemplateManager::templates_dir () const
|
|
|
|
{
|
|
|
|
return user_template_directory ();
|
|
|
|
}
|
|
|
|
|
2020-04-05 09:41:37 -04:00
|
|
|
string
|
|
|
|
SessionTemplateManager::templates_dir_basename () const
|
|
|
|
{
|
|
|
|
return string (templates_dir_name);
|
|
|
|
}
|
|
|
|
|
2017-08-17 15:42:32 -04:00
|
|
|
|
|
|
|
string
|
|
|
|
SessionTemplateManager::template_file (const TreeModel::const_iterator& item) const
|
|
|
|
{
|
|
|
|
const string path = item->get_value (_template_columns.path);
|
|
|
|
const string name = item->get_value (_template_columns.name);
|
|
|
|
return Glib::build_filename (path, name+".template");
|
|
|
|
}
|
|
|
|
|
2017-07-07 13:53:45 -04:00
|
|
|
bool
|
|
|
|
SessionTemplateManager::adjust_xml_tree (XMLTree& tree, const std::string& old_name, const std::string& new_name) const
|
|
|
|
{
|
|
|
|
bool adjusted = false;
|
|
|
|
XMLNode* root = tree.root();
|
|
|
|
|
|
|
|
const XMLNode* const routes_node = root->child (X_("Routes"));
|
|
|
|
if (routes_node) {
|
|
|
|
const XMLNodeList& routes = routes_node->children (X_("Route"));
|
|
|
|
XMLNodeConstIterator rit;
|
|
|
|
for (rit = routes.begin(); rit != routes.end(); ++rit) {
|
|
|
|
if (adjust_plugin_paths (*rit, old_name, new_name)) {
|
|
|
|
adjusted = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return adjusted;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-03 08:30:05 -04:00
|
|
|
void
|
|
|
|
RouteTemplateManager::rename_template (TreeModel::iterator& item, const Glib::ustring& new_name)
|
2017-07-03 06:27:25 -04:00
|
|
|
{
|
2017-07-06 04:04:07 -04:00
|
|
|
const string old_name = item->get_value (_template_columns.name);
|
2017-07-03 08:30:05 -04:00
|
|
|
const string old_filepath = item->get_value (_template_columns.path);
|
|
|
|
const string new_filepath = Glib::build_filename (user_route_template_directory(), new_name+".template");
|
|
|
|
|
2017-09-22 11:16:04 -04:00
|
|
|
if (old_name == new_name) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-07-06 01:31:12 -04:00
|
|
|
XMLTree tree;
|
|
|
|
if (!tree.read (old_filepath)) {
|
|
|
|
error << string_compose (_("Could not parse template file \"%1\"."), old_filepath) << endmsg;
|
2017-07-03 08:30:05 -04:00
|
|
|
return;
|
2017-07-03 06:27:25 -04:00
|
|
|
}
|
2017-07-20 14:10:23 -04:00
|
|
|
tree.root()->set_property (X_("name"), new_name);
|
2017-07-06 01:31:12 -04:00
|
|
|
tree.root()->children().front()->set_property (X_("name"), new_name);
|
|
|
|
|
2017-07-06 04:04:07 -04:00
|
|
|
const bool adjusted = adjust_plugin_paths (tree.root(), old_name, string (new_name));
|
|
|
|
|
|
|
|
const string old_state_dir = Glib::build_filename (user_route_template_directory(), old_name);
|
|
|
|
const string new_state_dir = Glib::build_filename (user_route_template_directory(), new_name);
|
2017-07-06 01:31:12 -04:00
|
|
|
|
|
|
|
if (adjusted) {
|
2017-07-20 14:08:09 -04:00
|
|
|
if (g_file_test (old_state_dir.c_str(), G_FILE_TEST_EXISTS)) {
|
|
|
|
if (g_rename (old_state_dir.c_str(), new_state_dir.c_str()) != 0) {
|
2020-04-13 10:09:40 -04:00
|
|
|
error << string_compose (_("Could not rename state dir \"%1\" to \"%2\": %3"), old_state_dir, new_state_dir, strerror (errno)) << endmsg;
|
2017-07-20 14:08:09 -04:00
|
|
|
return;
|
|
|
|
}
|
2017-07-06 01:31:12 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tree.set_filename (new_filepath);
|
|
|
|
|
|
|
|
if (!tree.write ()) {
|
|
|
|
error << string_compose(_("Could not write new template file \"%1\"."), new_filepath) << endmsg;
|
2017-07-06 04:04:07 -04:00
|
|
|
if (adjusted) {
|
|
|
|
g_rename (new_state_dir.c_str(), old_state_dir.c_str());
|
|
|
|
}
|
2017-07-06 01:31:12 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_unlink (old_filepath.c_str()) != 0) {
|
|
|
|
error << string_compose (_("Could not remove old template file \"%1\": %2"), old_filepath, strerror (errno)) << endmsg;
|
|
|
|
}
|
2017-07-03 06:27:25 -04:00
|
|
|
|
2017-07-03 08:30:05 -04:00
|
|
|
item->set_value (_template_columns.name, string (new_name));
|
|
|
|
item->set_value (_template_columns.path, new_filepath);
|
2017-07-03 06:27:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-07-03 08:30:05 -04:00
|
|
|
RouteTemplateManager::delete_selected_template ()
|
2017-07-03 06:27:25 -04:00
|
|
|
{
|
2017-08-19 18:29:46 -04:00
|
|
|
if (!_current_selection) {
|
2017-07-03 06:27:25 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-08-19 18:29:46 -04:00
|
|
|
const string file_path = _current_selection->get_value (_template_columns.path);
|
2017-07-03 08:30:05 -04:00
|
|
|
|
|
|
|
if (g_unlink (file_path.c_str()) != 0) {
|
|
|
|
error << string_compose(_("Could not delete template file \"%1\": %2"), file_path, strerror (errno)) << endmsg;
|
2017-07-03 06:27:25 -04:00
|
|
|
return;
|
|
|
|
}
|
2017-08-19 18:29:46 -04:00
|
|
|
PBD::remove_directory (Glib::build_filename (user_route_template_directory (),
|
|
|
|
_current_selection->get_value (_template_columns.name)));
|
2017-07-03 06:27:25 -04:00
|
|
|
|
2017-08-19 18:29:46 -04:00
|
|
|
_template_model->erase (_current_selection);
|
2017-07-03 08:30:05 -04:00
|
|
|
row_selection_changed ();
|
2017-07-03 06:27:25 -04:00
|
|
|
}
|
2017-07-07 13:53:45 -04:00
|
|
|
|
|
|
|
string
|
|
|
|
RouteTemplateManager::templates_dir () const
|
|
|
|
{
|
|
|
|
return user_route_template_directory ();
|
|
|
|
}
|
|
|
|
|
2020-04-05 09:41:37 -04:00
|
|
|
string
|
|
|
|
RouteTemplateManager::templates_dir_basename () const
|
|
|
|
{
|
|
|
|
return string (route_templates_dir_name);
|
|
|
|
}
|
|
|
|
|
2017-08-17 15:42:32 -04:00
|
|
|
|
|
|
|
string
|
|
|
|
RouteTemplateManager::template_file (const TreeModel::const_iterator& item) const
|
|
|
|
{
|
|
|
|
return item->get_value (_template_columns.path);
|
|
|
|
}
|
|
|
|
|
2017-07-07 13:53:45 -04:00
|
|
|
bool
|
|
|
|
RouteTemplateManager::adjust_xml_tree (XMLTree& tree, const std::string& old_name, const std::string& new_name) const
|
|
|
|
{
|
|
|
|
return adjust_plugin_paths (tree.root(), old_name, string (new_name));
|
|
|
|
}
|