diff options
| author | Eleni Maria Stea <elenimaria.stea@canonical.com> | 2013-11-08 17:04:14 +0200 |
|---|---|---|
| committer | Eleni Maria Stea <elenimaria.stea@canonical.com> | 2013-11-08 17:04:14 +0200 |
| commit | 517280af9f6fd5bb7b71d7fbab01d130a8666723 (patch) | |
| tree | f187b9e45d499f22d6469400e60a0d2584b81f56 /unity-shared | |
| parent | 2d911d11d30790592924a77b55fcaa52fb5794b6 (diff) | |
| parent | 6a2e5491e487dbbeed835b3c962fbba812fb617d (diff) | |
merged to trunk
(bzr r3587.4.3)
Diffstat (limited to 'unity-shared')
| -rw-r--r-- | unity-shared/BackgroundEffectHelper.cpp | 2 | ||||
| -rw-r--r-- | unity-shared/DebugDBusInterface.cpp | 242 | ||||
| -rw-r--r-- | unity-shared/Introspectable.cpp | 72 | ||||
| -rw-r--r-- | unity-shared/Introspectable.h | 12 | ||||
| -rw-r--r-- | unity-shared/PlacesOverlayVScrollBar.cpp | 3 | ||||
| -rw-r--r-- | unity-shared/PluginAdapter.cpp | 2 | ||||
| -rw-r--r-- | unity-shared/SearchBar.cpp | 1 |
7 files changed, 154 insertions, 180 deletions
diff --git a/unity-shared/BackgroundEffectHelper.cpp b/unity-shared/BackgroundEffectHelper.cpp index d48aad978..0d86d3aba 100644 --- a/unity-shared/BackgroundEffectHelper.cpp +++ b/unity-shared/BackgroundEffectHelper.cpp @@ -74,7 +74,7 @@ void BackgroundEffectHelper::ProcessDamage(nux::Geometry const& geo) if (bg_effect_helper->cache_dirty || !bg_effect_helper->owner || !bg_effect_helper->enabled) continue; - if (!geo.Intersect(bg_effect_helper->blur_geometry_).IsNull()) + if (geo.IsIntersecting(bg_effect_helper->blur_geometry_)) { bg_effect_helper->DirtyCache(); } diff --git a/unity-shared/DebugDBusInterface.cpp b/unity-shared/DebugDBusInterface.cpp index 16dfa6795..b92a3bd36 100644 --- a/unity-shared/DebugDBusInterface.cpp +++ b/unity-shared/DebugDBusInterface.cpp @@ -1,6 +1,6 @@ // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- /* - * Copyright (C) 2010 Canonical Ltd + * Copyright (C) 2010-2013 Canonical Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 as @@ -15,20 +15,16 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * * Authored by: Alex Launi <alex.launi@canonical.com> + * Thomi Richards <thomi.richards@canonical.com> + * Marco Trevisan <marco.trevisan@canonical.com> */ -#include <queue> -#include <iostream> #include <fstream> #include <sstream> -#include <iostream> #include <boost/algorithm/string.hpp> -#include <boost/algorithm/string/split.hpp> -#include <boost/algorithm/string/classification.hpp> -#include <boost/bind.hpp> #include <NuxCore/Logger.h> #include <NuxCore/LoggingWriter.h> -#include <xpathselect/node.h> +#include <UnityCore/Variant.h> #include <xpathselect/xpathselect.h> #include <dlfcn.h> @@ -45,17 +41,25 @@ namespace { namespace local { + const std::string PROTOCOL_VERSION = "1.4"; + const std::string XPATH_SELECT_LIB = "libxpathselect.so.1.4"; + std::ofstream output_file; - void* xpathselect_driver_ = NULL; + void* xpathselect_driver_ = nullptr; - class IntrospectableAdapter: public xpathselect::Node + class IntrospectableAdapter : public std::enable_shared_from_this<IntrospectableAdapter>, public xpathselect::Node { public: - typedef std::shared_ptr<IntrospectableAdapter> Ptr; - IntrospectableAdapter(Introspectable* node, std::string const& parent_path) - : node_(node) + typedef std::shared_ptr<IntrospectableAdapter const> Ptr; + IntrospectableAdapter(Introspectable* node, IntrospectableAdapter::Ptr const& parent = nullptr) + : node_(node) + , parent_(parent) + , full_path_((parent_ ? parent_->GetPath() : "") + "/" + GetName()) + {} + + int32_t GetId() const { - full_path_ = parent_path + "/" + GetName(); + return node_->GetIntrospectionId(); } std::string GetName() const @@ -68,145 +72,124 @@ namespace local return full_path_; } - bool MatchProperty(const std::string& name, const std::string& value) const + Node::Ptr GetParent() const { - bool matches = false; + return parent_; + } + + bool MatchStringProperty(std::string const& name, std::string const& value) const + { + auto const& prop_value = GetPropertyValue(name); + + if (prop_value) + { + if (!g_variant_is_of_type(prop_value, G_VARIANT_TYPE_STRING)) + { + LOG_WARNING(logger) << "Unable to match '"<< name << "', it's not a string property."; + return false; + } + + return (prop_value.GetString() == value); + } - GVariantBuilder child_builder; - g_variant_builder_init(&child_builder, G_VARIANT_TYPE("a{sv}")); - g_variant_builder_add(&child_builder, "{sv}", "id", g_variant_new_uint64(node_->GetIntrospectionId())); - node_->AddProperties(&child_builder); - GVariant* prop_dict = g_variant_builder_end(&child_builder); - GVariant *prop_value = g_variant_lookup_value(prop_dict, name.c_str(), NULL); + return false; + } + + bool MatchBooleanProperty(std::string const& name, bool value) const + { + auto const& prop_value = GetPropertyValue(name); - if (prop_value != NULL) + if (prop_value) + { + if (!g_variant_is_of_type(prop_value, G_VARIANT_TYPE_BOOLEAN)) + { + LOG_WARNING(logger) << "Unable to match '"<< name << "', it's not a boolean property."; + return false; + } + + return (prop_value.GetBool() == value); + } + + return false; + } + + bool MatchIntegerProperty(std::string const& name, int32_t value) const + { + auto const& prop_value = GetPropertyValue(name); + + if (prop_value) { GVariantClass prop_val_type = g_variant_classify(prop_value); - // it'd be nice to be able to do all this with one method. However, the booleans need - // special treatment, and I can't figure out how to group all the integer types together - // without resorting to template functions.... and we all know what happens when you - // start doing that... + // it'd be nice to be able to do all this with one method. + // I can't figure out how to group all the integer types together switch (prop_val_type) { - case G_VARIANT_CLASS_STRING: - { - const gchar* prop_val = g_variant_get_string(prop_value, NULL); - if (g_strcmp0(prop_val, value.c_str()) == 0) - { - matches = true; - } - } - break; - case G_VARIANT_CLASS_BOOLEAN: - { - std::string value = boost::to_upper_copy(value); - bool p = value == "TRUE" || - value == "ON" || - value == "YES" || - value == "1"; - matches = (g_variant_get_boolean(prop_value) == p); - } - break; case G_VARIANT_CLASS_BYTE: - { - // It would be nice if I could do all the integer types together, but I couldn't see how... - std::stringstream stream(value); - int val; // changing this to guchar causes problems. - stream >> val; - matches = (stream.rdstate() & (stream.badbit|stream.failbit)) == 0 && - val == g_variant_get_byte(prop_value); - } - break; + return static_cast<unsigned char>(value) == prop_value.GetByte(); case G_VARIANT_CLASS_INT16: - { - std::stringstream stream(value); - gint16 val; - stream >> val; - matches = (stream.rdstate() & (stream.badbit|stream.failbit)) == 0 && - val == g_variant_get_int16(prop_value); - } - break; + return value == prop_value.GetInt16(); case G_VARIANT_CLASS_UINT16: - { - std::stringstream stream(value); - guint16 val; - stream >> val; - matches = (stream.rdstate() & (stream.badbit|stream.failbit)) == 0 && - val == g_variant_get_uint16(prop_value); - } - break; + return static_cast<uint16_t>(value) == prop_value.GetUInt16(); case G_VARIANT_CLASS_INT32: - { - std::stringstream stream(value); - gint32 val; - stream >> val; - matches = (stream.rdstate() & (stream.badbit|stream.failbit)) == 0 && - val == g_variant_get_int32(prop_value); - } - break; + return value == prop_value.GetInt32(); case G_VARIANT_CLASS_UINT32: - { - std::stringstream stream(value); - guint32 val; - stream >> val; - matches = (stream.rdstate() & (stream.badbit|stream.failbit)) == 0 && - val == g_variant_get_uint32(prop_value); - } - break; + return static_cast<uint32_t>(value) == prop_value.GetUInt32(); case G_VARIANT_CLASS_INT64: - { - std::stringstream stream(value); - gint64 val; - stream >> val; - matches = (stream.rdstate() & (stream.badbit|stream.failbit)) == 0 && - val == g_variant_get_int64(prop_value); - } - break; + return value == prop_value.GetInt64(); case G_VARIANT_CLASS_UINT64: - { - std::stringstream stream(value); - guint64 val; - stream >> val; - matches = (stream.rdstate() & (stream.badbit|stream.failbit)) == 0 && - val == g_variant_get_uint64(prop_value); - } - break; + return static_cast<uint64_t>(value) == prop_value.GetUInt64(); default: - LOG_WARNING(logger) << "Unable to match against property of unknown type."; + LOG_WARNING(logger) << "Unable to match '"<< name << "' against property of unknown integer type."; }; } - g_variant_unref(prop_value); - g_variant_unref(prop_dict); - return matches; + + return false; + } + + glib::Variant GetPropertyValue(std::string const& name) const + { + if (name == "id") + return glib::Variant(GetId()); + + GVariantBuilder properties_builder; + g_variant_builder_init(&properties_builder, G_VARIANT_TYPE("a{sv}")); + node_->AddProperties(&properties_builder); + glib::Variant props_dict(g_variant_builder_end(&properties_builder)); + return g_variant_lookup_value(props_dict, name.c_str(), nullptr); } std::vector<xpathselect::Node::Ptr> Children() const { std::vector<xpathselect::Node::Ptr> children; - for(auto child: node_->GetIntrospectableChildren()) - { - children.push_back(std::make_shared<IntrospectableAdapter>(child, GetPath() )); - } + auto const& this_ptr = shared_from_this(); + + for(auto const& child: node_->GetIntrospectableChildren()) + children.push_back(std::make_shared<IntrospectableAdapter>(child, this_ptr)); + return children; + } + Introspectable* Node() const + { + return node_; } - Introspectable* node_; private: + Introspectable* node_; + IntrospectableAdapter::Ptr parent_; std::string full_path_; }; - xpathselect::NodeList select_nodes(local::IntrospectableAdapter::Ptr root, - std::string const& query) + xpathselect::NodeVector select_nodes(IntrospectableAdapter::Ptr const& root, std::string const& query) { - if (xpathselect_driver_ == NULL) - xpathselect_driver_ = dlopen("libxpathselect.so.1.3", RTLD_LAZY); + if (!xpathselect_driver_) + xpathselect_driver_ = dlopen(XPATH_SELECT_LIB.c_str(), RTLD_LAZY); if (xpathselect_driver_) { - typedef decltype(&xpathselect::SelectNodes) entry_t; + typedef decltype(&xpathselect::SelectNodes) select_nodes_t; dlerror(); - entry_t entry_point = (entry_t) dlsym(xpathselect_driver_, "SelectNodes"); + auto SelectNodes = reinterpret_cast<select_nodes_t>(dlsym(xpathselect_driver_, "SelectNodes")); const char* err = dlerror(); if (err) { @@ -214,7 +197,7 @@ namespace local } else { - return entry_point(root, query); + return SelectNodes(root, query); } } else @@ -223,7 +206,7 @@ namespace local } // Fallen through here as we've hit an error - return xpathselect::NodeList(); + return xpathselect::NodeVector(); } // This needs to be called at destruction to cleanup the dlopen @@ -240,10 +223,8 @@ bool TryLoadXPathImplementation(); GVariant* GetState(std::string const& query); void StartLogToFile(std::string const& file_path); void ResetLogging(); -void SetLogSeverity(std::string const& log_component, - std::string const& severity); -void LogMessage(std::string const& severity, - std::string const& message); +void SetLogSeverity(std::string const& log_component, std::string const& severity); +void LogMessage(std::string const& severity, std::string const& message); namespace dbus { @@ -317,7 +298,7 @@ GVariant* DebugDBusInterface::HandleDBusMethodCall(std::string const& method, GV } else if (method == "GetVersion") { - return g_variant_new("(s)", "1.3"); + return g_variant_new("(s)", local::PROTOCOL_VERSION.c_str()); } else if (method == "StartLogToFile") { @@ -352,16 +333,15 @@ GVariant* DebugDBusInterface::HandleDBusMethodCall(std::string const& method, GV GVariant* GetState(std::string const& query) { - GVariantBuilder builder; + GVariantBuilder builder; g_variant_builder_init(&builder, G_VARIANT_TYPE("a(sv)")); - local::IntrospectableAdapter::Ptr root_node = std::make_shared<local::IntrospectableAdapter>(_parent_introspectable, std::string()); - auto nodes = local::select_nodes(root_node, query); - for (auto n : nodes) + auto root_node = std::make_shared<local::IntrospectableAdapter>(_parent_introspectable); + for (auto const& n : local::select_nodes(root_node, query)) { - auto p = std::static_pointer_cast<local::IntrospectableAdapter>(n); + auto p = std::static_pointer_cast<local::IntrospectableAdapter const>(n); if (p) - g_variant_builder_add(&builder, "(sv)", p->GetPath().c_str(), p->node_->Introspect()); + g_variant_builder_add(&builder, "(sv)", p->GetPath().c_str(), p->Node()->Introspect()); } return g_variant_new("(a(sv))", &builder); diff --git a/unity-shared/Introspectable.cpp b/unity-shared/Introspectable.cpp index 9e3d8b920..ed932587f 100644 --- a/unity-shared/Introspectable.cpp +++ b/unity-shared/Introspectable.cpp @@ -17,6 +17,7 @@ * Authored by: Alex Launi <alex.launi@canonical.com> */ +#include <UnityCore/Variant.h> #include "Introspectable.h" namespace unity @@ -24,88 +25,85 @@ namespace unity namespace debug { +const std::string CHILDREN_NAME = "Children"; + Introspectable::Introspectable() { - static guint64 unique_id=0; - _id = unique_id++; + static int32_t unique_id_ = 0; + id_ = unique_id_++; } Introspectable::~Introspectable() { - for (auto parent : _parents) - parent->_children.remove(this); - for (auto child : _children) - child->_parents.remove(this); + for (auto parent : parents_) + parent->children_.remove(this); + for (auto child : children_) + child->parents_.remove(this); } Introspectable::IntrospectableList Introspectable::GetIntrospectableChildren() { - return _children; + return children_; } GVariant* Introspectable::Introspect() { - GVariantBuilder builder; - GVariantBuilder child_builder; - gint n_children = 0; + GVariantBuilder builder; + GVariantBuilder child_builder; + bool has_valid_children = false; g_variant_builder_init(&builder, G_VARIANT_TYPE("a{sv}")); - g_variant_builder_add(&builder, "{sv}", "id", g_variant_new_uint64(_id)); - + variant::BuilderWrapper build_wrapper(&builder); + build_wrapper.add("id", id_); AddProperties(&builder); g_variant_builder_init(&child_builder, G_VARIANT_TYPE("as")); - auto children = GetIntrospectableChildren(); - for (auto it = children.begin(); it != children.end(); it++) + for (auto const& child : GetIntrospectableChildren()) { - if ((*it)->GetName() != "") + auto const& child_name = child->GetName(); + + if (!child_name.empty()) { - g_variant_builder_add(&child_builder, "s", (*it)->GetName().c_str()); - n_children++; + g_variant_builder_add(&child_builder, "s", child_name.c_str()); + has_valid_children = true; } } - GVariant* child_results = g_variant_builder_end(&child_builder); + glib::Variant child_results(g_variant_builder_end(&child_builder)); + + if (has_valid_children) + build_wrapper.add(CHILDREN_NAME, child_results); - if (n_children > 0) - g_variant_builder_add(&builder, "{sv}", GetChildsName().c_str(), child_results); return g_variant_builder_end(&builder); } void Introspectable::AddChild(Introspectable* child) { - _children.push_back(child); - child->_parents.push_back(this); + children_.push_back(child); + child->parents_.push_back(this); } void Introspectable::RemoveChild(Introspectable* child) { - _children.remove(child); - child->_parents.remove(this); -} - -std::string -Introspectable::GetChildsName() const -{ - return "Children"; + children_.remove(child); + child->parents_.remove(this); } -guint64 Introspectable::GetIntrospectionId() const +int32_t Introspectable::GetIntrospectionId() const { - return _id; + return id_; } void Introspectable::RemoveAllChildren() { - for (auto child : _children) - { - child->_parents.remove(this); - } - _children.clear(); + for (auto child : children_) + child->parents_.remove(this); + + children_.clear(); } } diff --git a/unity-shared/Introspectable.h b/unity-shared/Introspectable.h index 245ec7b84..af7c0dd84 100644 --- a/unity-shared/Introspectable.h +++ b/unity-shared/Introspectable.h @@ -41,13 +41,9 @@ public: void RemoveChild(Introspectable* child); virtual void AddProperties(GVariantBuilder* builder) = 0; virtual IntrospectableList GetIntrospectableChildren(); - guint64 GetIntrospectionId() const; + int32_t GetIntrospectionId() const; protected: - /// Please don't override this unless you really need to. The only valid reason - /// is if you have a property that simply *must* be called 'Children'. - virtual std::string GetChildsName() const; - void RemoveAllChildren(); /* @@ -61,9 +57,9 @@ protected: */ private: - std::list<Introspectable*> _children; - std::list<Introspectable*> _parents; - guint64 _id; + std::list<Introspectable*> children_; + std::list<Introspectable*> parents_; + int32_t id_; }; } } diff --git a/unity-shared/PlacesOverlayVScrollBar.cpp b/unity-shared/PlacesOverlayVScrollBar.cpp index fc5d2daac..e16f4b848 100644 --- a/unity-shared/PlacesOverlayVScrollBar.cpp +++ b/unity-shared/PlacesOverlayVScrollBar.cpp @@ -209,9 +209,8 @@ void PlacesOverlayVScrollBar::CheckIfThumbIsInsideSlider() { nux::Geometry const& slider_geo = _slider->GetAbsoluteGeometry(); nux::Geometry const& thumb_geo = overlay_window_->GetThumbGeometry(); - nux::Geometry const& intersection = (thumb_geo.Intersect(slider_geo)); - if (!intersection.IsNull()) + if (thumb_geo.IsIntersecting(slider_geo)) { ResetConnector(); overlay_window_->ThumbInsideSlider(); diff --git a/unity-shared/PluginAdapter.cpp b/unity-shared/PluginAdapter.cpp index b233f3067..34bead63d 100644 --- a/unity-shared/PluginAdapter.cpp +++ b/unity-shared/PluginAdapter.cpp @@ -573,7 +573,7 @@ bool PluginAdapter::IsWindowObscured(Window window_id) const && sibling->isMapped() && sibling->isViewable() && (sibling->state() & MAXIMIZE_STATE) == MAXIMIZE_STATE - && !GetWindowGeometry(sibling->id()).Intersect(win_geo).IsNull()) + && GetWindowGeometry(sibling->id()).IsIntersecting(win_geo)) { return true; } diff --git a/unity-shared/SearchBar.cpp b/unity-shared/SearchBar.cpp index 11974736b..3f300e91c 100644 --- a/unity-shared/SearchBar.cpp +++ b/unity-shared/SearchBar.cpp @@ -617,6 +617,7 @@ void SearchBar::AddProperties(GVariantBuilder* builder) .add("filter-label-y", show_filters_->GetAbsoluteY()) .add("filter-label-width", show_filters_->GetAbsoluteWidth()) .add("filter-label-height", show_filters_->GetAbsoluteHeight()) + .add("filter-label-geo", show_filters_->GetAbsoluteGeometry()) .add("im_active", pango_entry_->im_active()); } |
