From 584a6c334b49ba509c310c34f534b14efa2cc0ea Mon Sep 17 00:00:00 2001 From: Nikolaus Gullotta Date: Thu, 4 Apr 2019 13:41:51 -0500 Subject: [PATCH] move ugly glib mkdir stuff to ensure_directory function and make methods smarter about when they should use it --- gtk2_ardour/mixer_snapshot_dialog.cc | 41 ++++++++++++++-------------- gtk2_ardour/mixer_snapshot_dialog.h | 1 + 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/gtk2_ardour/mixer_snapshot_dialog.cc b/gtk2_ardour/mixer_snapshot_dialog.cc index 3f3d910e28..8d82b904f6 100644 --- a/gtk2_ardour/mixer_snapshot_dialog.cc +++ b/gtk2_ardour/mixer_snapshot_dialog.cc @@ -94,6 +94,20 @@ void MixerSnapshotDialog::set_session(Session* s) refill(); } +void MixerSnapshotDialog::ensure_directory(bool global) +{ + string path; + if(global) { + path = Glib::build_filename(user_config_directory(-1), "mixer_snapshots"); + } else { + path = Glib::build_filename(_session->session_directory().root_path(), "mixer_snapshots"); + } + + if(!Glib::file_test(path.c_str(), Glib::FILE_TEST_EXISTS & Glib::FILE_TEST_IS_DIR)) { + ::g_mkdir(path.c_str(), 0775); + } +} + void MixerSnapshotDialog::display_drag_data_received(const Glib::RefPtr& context, int x, int y, const Gtk::SelectionData& data, guint info, guint time, bool global) { if (data.get_target() != "string") { @@ -110,6 +124,10 @@ void MixerSnapshotDialog::display_drag_data_received(const Glib::RefPtrget_object_drag_data(paths, &source); + if(!paths.empty()) { + ensure_directory(global); + } + for (list::const_iterator i = paths.begin(); i != paths.end(); i++) { string new_path; if(global) { @@ -323,16 +341,6 @@ void MixerSnapshotDialog::new_snapshot(bool global) return; } - string path = Glib::build_filename(user_config_directory(-1), "mixer_snapshots"); - if(!Glib::file_test(path.c_str(), Glib::FILE_TEST_EXISTS & Glib::FILE_TEST_IS_DIR)) { - ::g_mkdir(path.c_str(), 0775); - } - - path = Glib::build_filename(_session->session_directory().root_path(), "mixer_snapshots"); - if(!Glib::file_test(path.c_str(), Glib::FILE_TEST_EXISTS & Glib::FILE_TEST_IS_DIR)) { - ::g_mkdir(path.c_str(), 0775); - } - MixerSnapshot* snap = new MixerSnapshot(_session); Prompter prompt(true); @@ -350,6 +358,7 @@ void MixerSnapshotDialog::new_snapshot(bool global) prompt.get_vbox()->pack_start(*sel); if(prompt.run() == RESPONSE_ACCEPT) { + ensure_directory(global); string new_label; prompt.get_result(new_label); if (new_label.length() > 0) { @@ -376,16 +385,6 @@ void MixerSnapshotDialog::new_snapshot(bool global) void MixerSnapshotDialog::new_snap_from_session(bool global) { - string testpath = Glib::build_filename(user_config_directory(-1), "mixer_snapshots"); - if(!Glib::file_test(testpath.c_str(), Glib::FILE_TEST_EXISTS & Glib::FILE_TEST_IS_DIR)) { - ::g_mkdir(testpath.c_str(), 0775); - } - - testpath = Glib::build_filename(_session->session_directory().root_path(), "mixer_snapshots"); - if(!Glib::file_test(testpath.c_str(), Glib::FILE_TEST_EXISTS & Glib::FILE_TEST_IS_DIR)) { - ::g_mkdir(testpath.c_str(), 0775); - } - Gtk::FileChooserDialog session_selector(_("Open Session"), FILE_CHOOSER_ACTION_OPEN); string session_parent_dir = Glib::path_get_dirname(_session->path()); session_selector.add_button(Stock::CANCEL, RESPONSE_CANCEL); @@ -399,6 +398,8 @@ void MixerSnapshotDialog::new_snap_from_session(bool global) return; } + ensure_directory(global); + string session_path = session_selector.get_filename(); MixerSnapshot* snapshot = new MixerSnapshot(_session, session_path); diff --git a/gtk2_ardour/mixer_snapshot_dialog.h b/gtk2_ardour/mixer_snapshot_dialog.h index 2f18e3d1dc..a67ca55e33 100644 --- a/gtk2_ardour/mixer_snapshot_dialog.h +++ b/gtk2_ardour/mixer_snapshot_dialog.h @@ -50,6 +50,7 @@ class MixerSnapshotDialog : public ArdourWindow private: void display_drag_data_received(const Glib::RefPtr& context, int x, int y, const Gtk::SelectionData& data, guint info, guint time, bool); + void ensure_directory(bool); void new_snapshot(bool); void new_snap_from_session(bool);