From 6af49fb89facc67f369ede8cce6c315fd705d3cc Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 26 Jul 2007 16:19:58 +0000 Subject: Fix various Table bugs (and put some way too slow code in there, but hey, it works). Use PathTable for models on the client side. Implement renaming on client side. git-svn-id: http://svn.drobilla.net/lad/ingen@636 a436a847-0d15-0410-975c-d299462d15a1 --- src/libs/client/ObjectModel.hpp | 2 +- src/libs/client/PatchModel.cpp | 2 +- src/libs/client/Serializer.hpp | 4 +- src/libs/client/Store.cpp | 55 ++++++++++++++++++++------- src/libs/client/Store.hpp | 8 ++-- src/libs/engine/events/ConnectionEvent.cpp | 1 + src/libs/engine/events/DisconnectionEvent.cpp | 1 + src/libs/gui/NodeModule.cpp | 8 ++++ src/libs/gui/NodeModule.hpp | 2 + src/libs/gui/PatchPortModule.cpp | 1 + src/libs/gui/RenameWindow.cpp | 4 +- 11 files changed, 66 insertions(+), 22 deletions(-) diff --git a/src/libs/client/ObjectModel.hpp b/src/libs/client/ObjectModel.hpp index fe0f223c..429f5359 100644 --- a/src/libs/client/ObjectModel.hpp +++ b/src/libs/client/ObjectModel.hpp @@ -81,7 +81,7 @@ protected: ObjectModel(const Path& path); - virtual void set_path(const Path& p) { _path = p; } + virtual void set_path(const Path& p) { _path = p; renamed_sig.emit(); } virtual void set_parent(SharedPtr p) { assert(p); _parent = p; } virtual void add_child(SharedPtr c); virtual bool remove_child(SharedPtr c); diff --git a/src/libs/client/PatchModel.cpp b/src/libs/client/PatchModel.cpp index 615ae562..f67c7706 100644 --- a/src/libs/client/PatchModel.cpp +++ b/src/libs/client/PatchModel.cpp @@ -30,7 +30,7 @@ namespace Client { void PatchModel::set_path(const Path& new_path) { - throw; + ObjectModel::set_path(new_path); #if 0 // FIXME: haack if (new_path == "") { diff --git a/src/libs/client/Serializer.hpp b/src/libs/client/Serializer.hpp index 837d7333..23f93df6 100644 --- a/src/libs/client/Serializer.hpp +++ b/src/libs/client/Serializer.hpp @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include "ObjectModel.hpp" namespace Ingen { @@ -72,7 +72,7 @@ private: Raul::RDF::Node path_to_node_id(const Path& path); - typedef Raul::Table NodeMap; + typedef Raul::PathTable NodeMap; Mode _mode; NodeMap _node_map; diff --git a/src/libs/client/Store.cpp b/src/libs/client/Store.cpp index a2c9bf6f..674fc24e 100644 --- a/src/libs/client/Store.cpp +++ b/src/libs/client/Store.cpp @@ -24,11 +24,13 @@ #include "PatchModel.hpp" #include "SigClientInterface.hpp" +using namespace std; +using Raul::Path; + namespace Ingen { namespace Client { - Store::Store(SharedPtr engine, SharedPtr emitter) : _engine(engine) , _emitter(emitter) @@ -146,7 +148,7 @@ Store::add_orphan(SharedPtr child) { cerr << "WARNING: Orphan object " << child->path() << " received." << endl; - Raul::Table > >::iterator children + Raul::PathTable > >::iterator children = _orphans.find(child->path().parent()); _engine->request_object(child->path().parent()); @@ -164,7 +166,7 @@ Store::add_orphan(SharedPtr child) void Store::add_metadata_orphan(const Path& subject_path, const string& predicate, const Atom& value) { - Raul::Table > >::iterator orphans + Raul::PathTable > >::iterator orphans = _metadata_orphans.find(subject_path); _engine->request_object(subject_path); @@ -182,7 +184,7 @@ Store::add_metadata_orphan(const Path& subject_path, const string& predicate, co void Store::resolve_metadata_orphans(SharedPtr subject) { - Raul::Table > >::iterator v + Raul::PathTable > >::iterator v = _metadata_orphans.find(subject->path()); if (v != _metadata_orphans.end()) { @@ -202,7 +204,7 @@ Store::resolve_metadata_orphans(SharedPtr subject) void Store::resolve_orphans(SharedPtr parent) { - Raul::Table > >::iterator c + Raul::PathTable > >::iterator c = _orphans.find(parent->path()); if (c != _orphans.end()) { @@ -257,7 +259,7 @@ Store::add_object(SharedPtr object) } - //cout << "[Store] Added " << object->path() << endl; + cout << "[Store] Added " << object->path() << endl; } @@ -348,14 +350,41 @@ Store::destruction_event(const Path& path) void Store::rename_event(const Path& old_path, const Path& new_path) { - SharedPtr object = remove_object(old_path); - if (object) { - object->set_path(new_path); - add_object(object); - object->renamed_sig.emit(); - cerr << "[Store] Renamed " << old_path << " -> " << new_path << endl; - } else { + Objects::iterator parent = _objects.find(old_path); + if (parent == _objects.end()) { cerr << "[Store] Failed to find object " << old_path << " to rename." << endl; + return; + } + + Objects::iterator descendants_end = _objects.find_descendants_end(parent); + + vector > > objs = _objects.yank(parent, descendants_end); + + assert(objs.size() > 0); + + for (vector > >::iterator i = objs.begin(); i != objs.end(); ++i) { + const Path& child_old_path = i->first; + assert(Path::descendant_comparator(old_path, child_old_path)); + + Path child_new_path; + if (child_old_path == old_path) + child_new_path = new_path; + else + child_new_path = new_path.base() + child_old_path.substr(old_path.length()+1); + + cerr << "[Store] Renamed " << child_old_path << " -> " << child_new_path << endl; + i->second->set_path(child_new_path); + i->first = child_new_path; + } + + _objects.cram(objs); + + cerr << "[Store] Table:" << endl; + //for (size_t i=0; i < objs.size(); ++i) { + // cerr << objs[i].first << "\t\t: " << objs[i].second << endl; + //} + for (Objects::iterator i = _objects.begin(); i != _objects.end(); ++i) { + cerr << i->first << "\t\t: " << i->second << endl; } } diff --git a/src/libs/client/Store.hpp b/src/libs/client/Store.hpp index 627d6f8a..25398eaa 100644 --- a/src/libs/client/Store.hpp +++ b/src/libs/client/Store.hpp @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include #include "interface/EngineInterface.hpp" using std::string; using std::list; @@ -63,7 +63,7 @@ public: typedef Raul::Table > Plugins; const Plugins& plugins() const { return _plugins; } - typedef Raul::Table > Objects; + typedef Raul::PathTable > Objects; const Objects& objects() const { return _objects; } sigc::signal > new_object_sig; @@ -113,14 +113,14 @@ private: /** Objects we've received, but depend on the existance of another unknown object. * Keyed by the path of the depended-on object (for tolerance of orderless comms) */ - Raul::Table > > _orphans; + Raul::PathTable > > _orphans; /** Same idea, except with plugins instead of parents. * It's unfortunate everything doesn't just have a URI and this was the same.. ahem.. */ Raul::Table > > _plugin_orphans; /** Not orphans OF metadata like the above, but orphans which are metadata */ - Raul::Table > > _metadata_orphans; + Raul::PathTable > > _metadata_orphans; /** Ditto */ list > _connection_orphans; diff --git a/src/libs/engine/events/ConnectionEvent.cpp b/src/libs/engine/events/ConnectionEvent.cpp index c1fd3180..554a974f 100644 --- a/src/libs/engine/events/ConnectionEvent.cpp +++ b/src/libs/engine/events/ConnectionEvent.cpp @@ -170,6 +170,7 @@ ConnectionEvent::post_process() // FIXME: better error messages string msg = "Unable to make connection "; msg.append(_src_port_path + " -> " + _dst_port_path); + cerr << "CONNECTION ERROR " << (unsigned)_error << endl; _responder->respond_error(msg); } } diff --git a/src/libs/engine/events/DisconnectionEvent.cpp b/src/libs/engine/events/DisconnectionEvent.cpp index ba35f84e..dc78a118 100644 --- a/src/libs/engine/events/DisconnectionEvent.cpp +++ b/src/libs/engine/events/DisconnectionEvent.cpp @@ -192,6 +192,7 @@ DisconnectionEvent::post_process() // FIXME: better error messages string msg = "Unable to disconnect "; msg.append(_src_port_path + " -> " + _dst_port_path); + cerr << "DISCONNECTION ERROR " << (unsigned)_error << endl; _responder->respond_error(msg); } } diff --git a/src/libs/gui/NodeModule.cpp b/src/libs/gui/NodeModule.cpp index 3c319344..cf4f1409 100644 --- a/src/libs/gui/NodeModule.cpp +++ b/src/libs/gui/NodeModule.cpp @@ -51,6 +51,7 @@ NodeModule::NodeModule(boost::shared_ptr canvas, SharedPtrmetadata_update_sig.connect(sigc::mem_fun(this, &NodeModule::metadata_update)); signal_clicked.connect(sigc::mem_fun(this, &NodeModule::on_click)); + node->renamed_sig.connect(sigc::mem_fun(this, &NodeModule::renamed)); } @@ -88,6 +89,13 @@ NodeModule::create(boost::shared_ptr canvas, SharedPtr n } +void +NodeModule::renamed() +{ + set_name(_node->path().name()); +} + + void NodeModule::add_port(SharedPtr port, bool resize_to_fit) { diff --git a/src/libs/gui/NodeModule.hpp b/src/libs/gui/NodeModule.hpp index b68d1143..b554a64c 100644 --- a/src/libs/gui/NodeModule.hpp +++ b/src/libs/gui/NodeModule.hpp @@ -79,6 +79,8 @@ protected: void add_port(SharedPtr port, bool resize=true); void remove_port(SharedPtr port); + void renamed(); + SharedPtr _node; NodeMenu _menu; }; diff --git a/src/libs/gui/PatchPortModule.cpp b/src/libs/gui/PatchPortModule.cpp index bf63e9b6..15ce9ac4 100644 --- a/src/libs/gui/PatchPortModule.cpp +++ b/src/libs/gui/PatchPortModule.cpp @@ -76,6 +76,7 @@ PatchPortModule::create(boost::shared_ptr canvas, SharedPtradd_port(ret->_patch_port); for (MetadataMap::const_iterator m = port->metadata().begin(); m != port->metadata().end(); ++m) diff --git a/src/libs/gui/RenameWindow.cpp b/src/libs/gui/RenameWindow.cpp index 04ffdd9f..6567799e 100644 --- a/src/libs/gui/RenameWindow.cpp +++ b/src/libs/gui/RenameWindow.cpp @@ -71,7 +71,9 @@ RenameWindow::name_changed() if (name.find("/") != string::npos) { _message_label->set_text("Name may not contain '/'"); _ok_button->property_sensitive() = false; - //} else if (_object->parent()->patch_model()->get_node(name) != NULL) { + } else if (!Path::is_valid_name(name)) { + _message_label->set_text("Name contains invalid characters"); + _ok_button->property_sensitive() = false; } else if (App::instance().store()->object(_object->parent()->path().base() + name)) { _message_label->set_text("An object already exists with that name."); _ok_button->property_sensitive() = false; -- cgit v1.2.1