From ea9b5b90766b4c8da618ee7e04f5410fa6661393 Mon Sep 17 00:00:00 2001 From: Nick Dedekind Date: Mon, 1 Oct 2012 14:30:18 +0100 Subject: Fixed re-ordering of shopping lens category in home lens. Fixes LP: #1054219 (bzr r2769.3.1) --- UnityCore/HomeLens.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'UnityCore') diff --git a/UnityCore/HomeLens.cpp b/UnityCore/HomeLens.cpp index da995637f..7157bc57d 100644 --- a/UnityCore/HomeLens.cpp +++ b/UnityCore/HomeLens.cpp @@ -986,7 +986,7 @@ void HomeLens::Impl::LensSearchFinished(Lens::Ptr const& lens) { unsigned shopping_cat_num = order_vector.at(shopping_index); order_vector.erase(order_vector.begin() + shopping_index); - order_vector.insert(order_vector.begin() + 2, shopping_cat_num); + order_vector.insert(order_vector.size() > 2 ? order_vector.begin() + 2 : order_vector.end(), shopping_cat_num); } if (cached_categories_order_ != order_vector) -- cgit v1.2.3 From 287cc6b5d5f277b61a818927b232849d48bbeb3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Tue, 2 Oct 2012 21:21:23 +0200 Subject: DesktopUtilities: unescape the desktop paths and ids before processing them (bzr r2787.2.1) --- UnityCore/DesktopUtilities.cpp | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'UnityCore') diff --git a/UnityCore/DesktopUtilities.cpp b/UnityCore/DesktopUtilities.cpp index a627c191b..10af68556 100644 --- a/UnityCore/DesktopUtilities.cpp +++ b/UnityCore/DesktopUtilities.cpp @@ -87,7 +87,13 @@ std::string DesktopUtilities::GetDesktopID(std::vector const& defau if (desktop_path.empty()) return ""; - for (auto dir : default_paths) + glib::String unescaped(g_uri_unescape_string(desktop_path.c_str(), NULL)); + std::string const& desktop_file = unescaped.Str(); + + if (desktop_file.empty()) + return ""; + + for (auto const& dir : default_paths) { if (!dir.empty()) { @@ -100,11 +106,11 @@ std::string DesktopUtilities::GetDesktopID(std::vector const& defau dir.append(G_DIR_SEPARATOR_S "applications" G_DIR_SEPARATOR_S); } - if (desktop_path.find(dir) == 0) + if (desktop_file.find(dir) == 0) { // if we are in a subdirectory of system path, the store name should // be subdir-filename.desktop - std::string desktop_suffix = desktop_path.substr(dir.size()); + std::string desktop_suffix = desktop_file.substr(dir.size()); std::replace(desktop_suffix.begin(), desktop_suffix.end(), G_DIR_SEPARATOR, '-'); return desktop_suffix; @@ -112,7 +118,7 @@ std::string DesktopUtilities::GetDesktopID(std::vector const& defau } } - return desktop_path; + return desktop_file; } std::string DesktopUtilities::GetDesktopID(std::string const& desktop_path) @@ -126,12 +132,18 @@ std::string DesktopUtilities::GetDesktopPathById(std::string const& desktop_id) if (desktop_id.empty()) return ""; + glib::String unescaped_id(g_uri_unescape_string(desktop_id.c_str(), NULL)); + std::string const& id = unescaped_id.Str(); + + if (id.empty()) + return ""; + glib::Object info; - if (desktop_id.find(G_DIR_SEPARATOR_S) != std::string::npos) - info = g_desktop_app_info_new_from_filename(desktop_id.c_str()); + if (id.find(G_DIR_SEPARATOR_S) != std::string::npos) + info = g_desktop_app_info_new_from_filename(id.c_str()); else - info = g_desktop_app_info_new(desktop_id.c_str()); + info = g_desktop_app_info_new(id.c_str()); if (info) { -- cgit v1.2.3 From a77ca6df0bc3c2971a2ba34d72edfae9c6637bde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Tue, 2 Oct 2012 22:55:11 +0200 Subject: TestDesktopUtilitiesDesktopID: add test for escaped values (bzr r2787.2.2) --- UnityCore/DesktopUtilities.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'UnityCore') diff --git a/UnityCore/DesktopUtilities.cpp b/UnityCore/DesktopUtilities.cpp index 10af68556..7ef0be903 100644 --- a/UnityCore/DesktopUtilities.cpp +++ b/UnityCore/DesktopUtilities.cpp @@ -93,7 +93,7 @@ std::string DesktopUtilities::GetDesktopID(std::vector const& defau if (desktop_file.empty()) return ""; - for (auto const& dir : default_paths) + for (auto dir : default_paths) { if (!dir.empty()) { -- cgit v1.2.3 From 6166c20dda854c60eb3b32ce809dd01935ef9b43 Mon Sep 17 00:00:00 2001 From: Michal Hruby Date: Thu, 4 Oct 2012 10:16:35 +0200 Subject: Try to reconnect to DBus proxy if we fail the first time Fixes LP: #1058619 (bzr r2791.3.1) --- UnityCore/GLibDBusProxy.cpp | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'UnityCore') diff --git a/UnityCore/GLibDBusProxy.cpp b/UnityCore/GLibDBusProxy.cpp index bd086574b..bdb01bbd7 100644 --- a/UnityCore/GLibDBusProxy.cpp +++ b/UnityCore/GLibDBusProxy.cpp @@ -36,6 +36,7 @@ namespace glib namespace { +const unsigned MAX_RECONNECTION_ATTEMPTS = 5; nux::logging::Logger logger("unity.glib.dbusproxy"); } @@ -55,7 +56,7 @@ public: GDBusProxyFlags flags); ~Impl(); - void StartReconnectionTimeout(); + void StartReconnectionTimeout(unsigned timeout); void Connect(); void Call(string const& method_name, @@ -91,6 +92,7 @@ public: glib::Object proxy_; glib::Object cancellable_; bool connected_; + unsigned reconnection_attempts_; glib::Signal g_signal_connection_; glib::Signal name_owner_signal_; @@ -113,8 +115,9 @@ DBusProxy::Impl::Impl(DBusProxy* owner, , flags_(flags) , cancellable_(g_cancellable_new()) , connected_(false) + , reconnection_attempts_(0) { - StartReconnectionTimeout(); + StartReconnectionTimeout(1); } DBusProxy::Impl::~Impl() @@ -122,7 +125,7 @@ DBusProxy::Impl::~Impl() g_cancellable_cancel(cancellable_); } -void DBusProxy::Impl::StartReconnectionTimeout() +void DBusProxy::Impl::StartReconnectionTimeout(unsigned timeout) { LOG_DEBUG(logger) << "Starting reconnection timeout for " << name_; @@ -134,7 +137,7 @@ void DBusProxy::Impl::StartReconnectionTimeout() return false; }; - reconnect_timeout_.reset(new glib::TimeoutSeconds(1, callback)); + reconnect_timeout_.reset(new glib::TimeoutSeconds(timeout, callback)); } void DBusProxy::Impl::Connect() @@ -169,12 +172,27 @@ void DBusProxy::Impl::OnProxyConnectCallback(GObject* source, // therefore we should deal with the error before touching the impl pointer if (!proxy || error) { - LOG_WARNING(logger) << "Unable to connect to proxy: " << error; + // if the cancellable was cancelled, "self" points to destroyed object + if (error && !g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) + { + if (self->reconnection_attempts_++ < MAX_RECONNECTION_ATTEMPTS) + { + LOG_WARNING(logger) << "Unable to connect to proxy: \"" << error + << "\"... Trying to reconnect (attempt " + << self->reconnection_attempts_ << ")"; + self->StartReconnectionTimeout(3); + } + else + { + LOG_WARNING(logger) << "Unable to connect to proxy: " << error; + } + } return; } LOG_DEBUG(logger) << "Sucessfully created proxy: " << self->object_path_; + self->reconnection_attempts_ = 0; self->proxy_ = proxy; self->g_signal_connection_.Connect(self->proxy_, "g-signal", sigc::mem_fun(self, &Impl::OnProxySignal)); -- cgit v1.2.3 From 2f12de28487f6e5f12425fbcc3993823f05875fa Mon Sep 17 00:00:00 2001 From: Michal Hruby Date: Thu, 4 Oct 2012 10:39:01 +0200 Subject: Use error instead of warning the last time (bzr r2791.3.2) --- UnityCore/GLibDBusProxy.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'UnityCore') diff --git a/UnityCore/GLibDBusProxy.cpp b/UnityCore/GLibDBusProxy.cpp index bdb01bbd7..273bb42a3 100644 --- a/UnityCore/GLibDBusProxy.cpp +++ b/UnityCore/GLibDBusProxy.cpp @@ -184,7 +184,7 @@ void DBusProxy::Impl::OnProxyConnectCallback(GObject* source, } else { - LOG_WARNING(logger) << "Unable to connect to proxy: " << error; + LOG_ERROR(logger) << "Unable to connect to proxy: " << error; } } return; -- cgit v1.2.3 From 778638eabedcfac34d9740658b12d0c4b7333a68 Mon Sep 17 00:00:00 2001 From: Albert Astals Date: Fri, 5 Oct 2012 15:15:52 +0200 Subject: Do not reuse the menu entries if their order changes (bzr r2807.2.1) --- UnityCore/DBusIndicators.cpp | 14 +++++++++++++- UnityCore/Indicator.cpp | 12 +++++++++++- UnityCore/Indicator.h | 2 +- 3 files changed, 25 insertions(+), 3 deletions(-) (limited to 'UnityCore') diff --git a/UnityCore/DBusIndicators.cpp b/UnityCore/DBusIndicators.cpp index 2e3df31ce..defaaa02e 100644 --- a/UnityCore/DBusIndicators.cpp +++ b/UnityCore/DBusIndicators.cpp @@ -276,6 +276,9 @@ void DBusIndicators::Impl::Sync(GVariant* args) return; std::map indicators; + int wantedIndex = 0; + int existingEntryIndex = -1; + bool anyIndexDifferent = false; g_variant_get(args, "(a(ssssbbusbbi))", &iter); while (g_variant_iter_loop(iter, "(ssssbbusbbi)", @@ -305,7 +308,15 @@ void DBusIndicators::Impl::Sync(GVariant* args) // Null entries (entry_id == "") are empty indicators. if (entry != "") { - Entry::Ptr e = indicator->GetEntry(entry_id); + Entry::Ptr e; + if (!anyIndexDifferent) + { + // Indicators can only add or remove entries, so if + // there is a index change we can't reuse the existing ones + // after that index + e = indicator->GetEntry(entry_id, &existingEntryIndex); + anyIndexDifferent = wantedIndex != existingEntryIndex; + } if (!e) { @@ -321,6 +332,7 @@ void DBusIndicators::Impl::Sync(GVariant* args) } entries.push_back(e); + wantedIndex++; } } g_variant_iter_free(iter); diff --git a/UnityCore/Indicator.cpp b/UnityCore/Indicator.cpp index c5eb9f127..91c90dc7f 100644 --- a/UnityCore/Indicator.cpp +++ b/UnityCore/Indicator.cpp @@ -106,12 +106,22 @@ void Indicator::Sync(Indicator::Entries const& new_entries) } } -Entry::Ptr Indicator::GetEntry(std::string const& entry_id) const +Entry::Ptr Indicator::GetEntry(std::string const& entry_id, int *index) const { + int i = 0; for (auto entry : entries_) + { if (entry->id() == entry_id) + { + if (index != nullptr) + *index = i; return entry; + } + ++i; + } + if (index != nullptr) + *index = -1; return Entry::Ptr(); } diff --git a/UnityCore/Indicator.h b/UnityCore/Indicator.h index 1fe8f1c27..200c322d7 100644 --- a/UnityCore/Indicator.h +++ b/UnityCore/Indicator.h @@ -47,7 +47,7 @@ public: virtual bool IsAppmenu() const { return false; } void Sync(Entries const& new_entries); - Entry::Ptr GetEntry(std::string const& entry_id) const; + Entry::Ptr GetEntry(std::string const& entry_id, int *index = nullptr) const; Entries GetEntries() const; // Signals -- cgit v1.2.3 From d33e2c536e38ea99c5852027f22270d2c07da0db Mon Sep 17 00:00:00 2001 From: Albert Astals Date: Fri, 5 Oct 2012 15:33:28 +0200 Subject: Marco prefers a new method over extending GetEntry (bzr r2807.2.2) --- UnityCore/DBusIndicators.cpp | 8 +++++--- UnityCore/Indicator.cpp | 19 ++++++++++++------- UnityCore/Indicator.h | 3 ++- 3 files changed, 19 insertions(+), 11 deletions(-) (limited to 'UnityCore') diff --git a/UnityCore/DBusIndicators.cpp b/UnityCore/DBusIndicators.cpp index defaaa02e..005397b5f 100644 --- a/UnityCore/DBusIndicators.cpp +++ b/UnityCore/DBusIndicators.cpp @@ -277,7 +277,6 @@ void DBusIndicators::Impl::Sync(GVariant* args) std::map indicators; int wantedIndex = 0; - int existingEntryIndex = -1; bool anyIndexDifferent = false; g_variant_get(args, "(a(ssssbbusbbi))", &iter); @@ -314,8 +313,11 @@ void DBusIndicators::Impl::Sync(GVariant* args) // Indicators can only add or remove entries, so if // there is a index change we can't reuse the existing ones // after that index - e = indicator->GetEntry(entry_id, &existingEntryIndex); - anyIndexDifferent = wantedIndex != existingEntryIndex; + int existingEntryIndex = indicator->EntryIndex(entry_id); + if (wantedIndex == existingEntryIndex) + e = indicator->GetEntry(entry_id); + else + anyIndexDifferent = true; } if (!e) diff --git a/UnityCore/Indicator.cpp b/UnityCore/Indicator.cpp index 91c90dc7f..8fe03252c 100644 --- a/UnityCore/Indicator.cpp +++ b/UnityCore/Indicator.cpp @@ -106,23 +106,28 @@ void Indicator::Sync(Indicator::Entries const& new_entries) } } -Entry::Ptr Indicator::GetEntry(std::string const& entry_id, int *index) const +Entry::Ptr Indicator::GetEntry(std::string const& entry_id) const +{ + for (auto entry : entries_) + if (entry->id() == entry_id) + return entry; + + return Entry::Ptr(); +} + +int Indicator::EntryIndex(std::string const& entry_id) const { int i = 0; for (auto entry : entries_) { if (entry->id() == entry_id) { - if (index != nullptr) - *index = i; - return entry; + return i; } ++i; } - if (index != nullptr) - *index = -1; - return Entry::Ptr(); + return -1; } void Indicator::OnEntryShowMenu(std::string const& entry_id, unsigned int xid, diff --git a/UnityCore/Indicator.h b/UnityCore/Indicator.h index 200c322d7..23b4bd575 100644 --- a/UnityCore/Indicator.h +++ b/UnityCore/Indicator.h @@ -47,7 +47,8 @@ public: virtual bool IsAppmenu() const { return false; } void Sync(Entries const& new_entries); - Entry::Ptr GetEntry(std::string const& entry_id, int *index = nullptr) const; + Entry::Ptr GetEntry(std::string const& entry_id) const; + int EntryIndex(std::string const& entry_id) const; Entries GetEntries() const; // Signals -- cgit v1.2.3 From 7142d86d9dbba735894cd2a6269f9af3a086ef25 Mon Sep 17 00:00:00 2001 From: Albert Astals Date: Fri, 5 Oct 2012 17:51:37 +0200 Subject: Add a unit test for the dbus indicators that check the entries are in the correct order (bzr r2807.2.4) --- UnityCore/DBusIndicators.cpp | 13 +++++++------ UnityCore/DBusIndicators.h | 5 ++++- 2 files changed, 11 insertions(+), 7 deletions(-) (limited to 'UnityCore') diff --git a/UnityCore/DBusIndicators.cpp b/UnityCore/DBusIndicators.cpp index 005397b5f..586c6cd95 100644 --- a/UnityCore/DBusIndicators.cpp +++ b/UnityCore/DBusIndicators.cpp @@ -37,7 +37,6 @@ namespace { nux::logging::Logger logger("unity.indicator.DBusIndicators"); -const std::string SERVICE_NAME("com.canonical.Unity.Panel.Service"); const std::string SERVICE_PATH("/com/canonical/Unity/Panel/Service"); const std::string SERVICE_IFACE("com.canonical.Unity.Panel.Service"); } // anonymous namespace @@ -48,7 +47,7 @@ const std::string SERVICE_IFACE("com.canonical.Unity.Panel.Service"); class DBusIndicators::Impl { public: - Impl(DBusIndicators* owner); + Impl(const std::string &dbus_name, DBusIndicators* owner); void CheckLocalService(); void RequestSyncAll(); @@ -84,9 +83,9 @@ public: // Public Methods -DBusIndicators::Impl::Impl(DBusIndicators* owner) +DBusIndicators::Impl::Impl(const std::string &dbus_name, DBusIndicators* owner) : owner_(owner) - , gproxy_(SERVICE_NAME, SERVICE_PATH, SERVICE_IFACE, + , gproxy_(dbus_name, SERVICE_PATH, SERVICE_IFACE, G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES) { gproxy_.Connect("ReSync", sigc::mem_fun(this, &DBusIndicators::Impl::OnReSync)); @@ -127,11 +126,13 @@ void DBusIndicators::Impl::CheckLocalService() void DBusIndicators::Impl::OnConnected() { + owner_->connected = true; RequestSyncAll(); } void DBusIndicators::Impl::OnDisconnected() { + owner_->connected = false; for (auto indicator : owner_->GetIndicators()) { owner_->RemoveIndicator(indicator->name()); @@ -406,8 +407,8 @@ void DBusIndicators::Impl::SyncGeometries(std::string const& name, cached_loc = locations; } -DBusIndicators::DBusIndicators() - : pimpl(new Impl(this)) +DBusIndicators::DBusIndicators(const std::string &dbus_name) + : connected(false), pimpl(new Impl(dbus_name, this)) {} DBusIndicators::~DBusIndicators() diff --git a/UnityCore/DBusIndicators.h b/UnityCore/DBusIndicators.h index 13bf445eb..07edd2a33 100644 --- a/UnityCore/DBusIndicators.h +++ b/UnityCore/DBusIndicators.h @@ -22,6 +22,7 @@ #include "Indicators.h" +#include namespace unity { @@ -35,9 +36,11 @@ class DBusIndicators : public Indicators public: typedef std::shared_ptr Ptr; - DBusIndicators(); + DBusIndicators(const std::string &dbus_name = "com.canonical.Unity.Panel.Service"); ~DBusIndicators(); + nux::Property connected; + void SyncGeometries(std::string const& name, EntryLocationMap const& locations); -- cgit v1.2.3 From 1898507932cbc2e1e2f92c523f214edb38a4c9cf Mon Sep 17 00:00:00 2001 From: Albert Astals Date: Mon, 8 Oct 2012 09:50:23 +0200 Subject: Do not use a nux::Property but a pimpl var for the connected state (bzr r2807.2.5) --- UnityCore/DBusIndicators.cpp | 13 ++++++++++--- UnityCore/DBusIndicators.h | 4 +--- 2 files changed, 11 insertions(+), 6 deletions(-) (limited to 'UnityCore') diff --git a/UnityCore/DBusIndicators.cpp b/UnityCore/DBusIndicators.cpp index 586c6cd95..f61a18533 100644 --- a/UnityCore/DBusIndicators.cpp +++ b/UnityCore/DBusIndicators.cpp @@ -74,6 +74,7 @@ public: DBusIndicators* owner_; + bool connected_; glib::DBusProxy gproxy_; glib::Source::UniquePtr reconnect_timeout_; glib::Source::UniquePtr show_entry_idle_; @@ -85,6 +86,7 @@ public: // Public Methods DBusIndicators::Impl::Impl(const std::string &dbus_name, DBusIndicators* owner) : owner_(owner) + , connected_(false) , gproxy_(dbus_name, SERVICE_PATH, SERVICE_IFACE, G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES) { @@ -126,13 +128,13 @@ void DBusIndicators::Impl::CheckLocalService() void DBusIndicators::Impl::OnConnected() { - owner_->connected = true; + connected_ = true; RequestSyncAll(); } void DBusIndicators::Impl::OnDisconnected() { - owner_->connected = false; + connected_ = false; for (auto indicator : owner_->GetIndicators()) { owner_->RemoveIndicator(indicator->name()); @@ -408,12 +410,17 @@ void DBusIndicators::Impl::SyncGeometries(std::string const& name, } DBusIndicators::DBusIndicators(const std::string &dbus_name) - : connected(false), pimpl(new Impl(dbus_name, this)) + : pimpl(new Impl(dbus_name, this)) {} DBusIndicators::~DBusIndicators() {} +bool DBusIndicators::IsConnected() const +{ + return pimpl->connected_; +} + void DBusIndicators::SyncGeometries(std::string const& name, EntryLocationMap const& locations) { diff --git a/UnityCore/DBusIndicators.h b/UnityCore/DBusIndicators.h index 07edd2a33..67cec7b42 100644 --- a/UnityCore/DBusIndicators.h +++ b/UnityCore/DBusIndicators.h @@ -22,8 +22,6 @@ #include "Indicators.h" -#include - namespace unity { namespace indicator @@ -39,7 +37,7 @@ public: DBusIndicators(const std::string &dbus_name = "com.canonical.Unity.Panel.Service"); ~DBusIndicators(); - nux::Property connected; + bool IsConnected() const; void SyncGeometries(std::string const& name, EntryLocationMap const& locations); -- cgit v1.2.3 From d11e43736bd61f8a9964f34ed509e4538f0c3023 Mon Sep 17 00:00:00 2001 From: Albert Astals Date: Mon, 8 Oct 2012 09:56:38 +0200 Subject: Make the constructor that takes a dbus_name protected as suggested by Marco (bzr r2807.2.6) --- UnityCore/DBusIndicators.cpp | 4 ++++ UnityCore/DBusIndicators.h | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'UnityCore') diff --git a/UnityCore/DBusIndicators.cpp b/UnityCore/DBusIndicators.cpp index f61a18533..8c62b75bf 100644 --- a/UnityCore/DBusIndicators.cpp +++ b/UnityCore/DBusIndicators.cpp @@ -409,6 +409,10 @@ void DBusIndicators::Impl::SyncGeometries(std::string const& name, cached_loc = locations; } +DBusIndicators::DBusIndicators() + : pimpl(new Impl("com.canonical.Unity.Panel.Service", this)) +{} + DBusIndicators::DBusIndicators(const std::string &dbus_name) : pimpl(new Impl(dbus_name, this)) {} diff --git a/UnityCore/DBusIndicators.h b/UnityCore/DBusIndicators.h index 67cec7b42..b0d441f89 100644 --- a/UnityCore/DBusIndicators.h +++ b/UnityCore/DBusIndicators.h @@ -34,7 +34,7 @@ class DBusIndicators : public Indicators public: typedef std::shared_ptr Ptr; - DBusIndicators(const std::string &dbus_name = "com.canonical.Unity.Panel.Service"); + DBusIndicators(); ~DBusIndicators(); bool IsConnected() const; @@ -51,6 +51,9 @@ public: virtual void OnShowAppMenu(unsigned int xid, int x, int y, unsigned int timestamp); +protected: + DBusIndicators(std::string const& dbus_name); + private: class Impl; std::unique_ptr pimpl; -- cgit v1.2.3 From 1e61481c3ad502850682211399ac237786ece9d7 Mon Sep 17 00:00:00 2001 From: Albert Astals Date: Mon, 8 Oct 2012 09:59:01 +0200 Subject: Make IsConnected also protected as suggested by Marco (bzr r2807.2.7) --- UnityCore/DBusIndicators.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'UnityCore') diff --git a/UnityCore/DBusIndicators.h b/UnityCore/DBusIndicators.h index b0d441f89..221c2b521 100644 --- a/UnityCore/DBusIndicators.h +++ b/UnityCore/DBusIndicators.h @@ -37,8 +37,6 @@ public: DBusIndicators(); ~DBusIndicators(); - bool IsConnected() const; - void SyncGeometries(std::string const& name, EntryLocationMap const& locations); @@ -53,6 +51,7 @@ public: protected: DBusIndicators(std::string const& dbus_name); + bool IsConnected() const; private: class Impl; -- cgit v1.2.3 From 63a899219b3788bda993c1a34855f2e2b92355ae Mon Sep 17 00:00:00 2001 From: Albert Astals Date: Mon, 8 Oct 2012 11:18:35 +0200 Subject: just use the proxy connected function (bzr r2807.2.11) --- UnityCore/DBusIndicators.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'UnityCore') diff --git a/UnityCore/DBusIndicators.cpp b/UnityCore/DBusIndicators.cpp index 8c62b75bf..30a935c62 100644 --- a/UnityCore/DBusIndicators.cpp +++ b/UnityCore/DBusIndicators.cpp @@ -74,7 +74,6 @@ public: DBusIndicators* owner_; - bool connected_; glib::DBusProxy gproxy_; glib::Source::UniquePtr reconnect_timeout_; glib::Source::UniquePtr show_entry_idle_; @@ -86,7 +85,6 @@ public: // Public Methods DBusIndicators::Impl::Impl(const std::string &dbus_name, DBusIndicators* owner) : owner_(owner) - , connected_(false) , gproxy_(dbus_name, SERVICE_PATH, SERVICE_IFACE, G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES) { @@ -128,13 +126,11 @@ void DBusIndicators::Impl::CheckLocalService() void DBusIndicators::Impl::OnConnected() { - connected_ = true; RequestSyncAll(); } void DBusIndicators::Impl::OnDisconnected() { - connected_ = false; for (auto indicator : owner_->GetIndicators()) { owner_->RemoveIndicator(indicator->name()); @@ -422,7 +418,7 @@ DBusIndicators::~DBusIndicators() bool DBusIndicators::IsConnected() const { - return pimpl->connected_; + return pimpl->gproxy_.IsConnected(); } void DBusIndicators::SyncGeometries(std::string const& name, -- cgit v1.2.3 From b0db9e765c43ad8bcb31cdb8f043c33d876ca052 Mon Sep 17 00:00:00 2001 From: Albert Astals Date: Mon, 8 Oct 2012 11:59:53 +0200 Subject: Move test to dbus proxy (adding CallSync in it) (bzr r2807.2.12) --- UnityCore/GLibDBusProxy.cpp | 74 +++++++++++++++++++++++++++++++++++++++++++++ UnityCore/GLibDBusProxy.h | 6 ++++ 2 files changed, 80 insertions(+) (limited to 'UnityCore') diff --git a/UnityCore/GLibDBusProxy.cpp b/UnityCore/GLibDBusProxy.cpp index 273bb42a3..c23de09e8 100644 --- a/UnityCore/GLibDBusProxy.cpp +++ b/UnityCore/GLibDBusProxy.cpp @@ -66,6 +66,12 @@ public: GDBusCallFlags flags, int timeout_msec); + GVariant *CallSync(string const& method_name, + GVariant* parameters, + GCancellable* cancellable, + GDBusCallFlags flags, + int timeout_msec); + void Connect(string const& signal_name, ReplyCallback callback); bool IsConnected(); @@ -274,6 +280,65 @@ void DBusProxy::Impl::Call(string const& method_name, } } +GVariant *DBusProxy::Impl::CallSync(std::string const& method_name, + GVariant* parameters, + GCancellable *cancellable, + GDBusCallFlags flags, + int timeout_msec) +{ + if (!proxy_) + { + bool timedout = false; + auto timeout_check = [&] () -> bool + { + timedout = true; + return false; + }; + glib::Timeout timeout(timeout_msec < 0 ? 10000 : timeout_msec, timeout_check); + + while (!proxy_ && !timedout) + { + g_main_context_iteration(g_main_context_get_thread_default(), TRUE); + } + } + + if (proxy_) + { + glib::Error error; + GVariant *ret = g_dbus_proxy_call_sync(proxy_, + method_name.c_str(), + parameters, + flags, + timeout_msec, + cancellable != NULL ? cancellable : cancellable_, + &error); + if (error) + { + if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) + { + // silently ignore + } + else + { + LOG_WARNING(logger) << "Calling method \"" << method_name + << "\" on object path: \"" + << object_path_ + << "\" failed: " << error; + } + + return nullptr; + } + return ret; + } + else + { + LOG_WARNING(logger) << "Cannot call method " << method_name + << " proxy " << object_path_ << " does not exist"; + } + return nullptr; +} + + void DBusProxy::Impl::OnCallCallback(GObject* source, GAsyncResult* res, gpointer call_data) { glib::Error error; @@ -329,6 +394,15 @@ void DBusProxy::Call(string const& method_name, timeout_msec); } +GVariant *DBusProxy::CallSync(std::string const& method_name, + GVariant* parameters, + GCancellable *cancellable, + GDBusCallFlags flags, + int timeout_msec) +{ + return pimpl->CallSync(method_name, parameters, cancellable, flags, timeout_msec); +} + void DBusProxy::Connect(std::string const& signal_name, ReplyCallback callback) { pimpl->Connect(signal_name, callback); diff --git a/UnityCore/GLibDBusProxy.h b/UnityCore/GLibDBusProxy.h index 06cce6cc6..b1f62f1bd 100644 --- a/UnityCore/GLibDBusProxy.h +++ b/UnityCore/GLibDBusProxy.h @@ -53,6 +53,12 @@ public: GDBusCallFlags flags = G_DBUS_CALL_FLAGS_NONE, int timeout_msec = -1); + GVariant *CallSync(std::string const& method_name, + GVariant* parameters = nullptr, + GCancellable *cancellable = nullptr, + GDBusCallFlags flags = G_DBUS_CALL_FLAGS_NONE, + int timeout_msec = -1); + void Connect(std::string const& signal_name, ReplyCallback callback); bool IsConnected(); -- cgit v1.2.3 From bcda3348765f11e9a9e48ca6413deb63f901cae5 Mon Sep 17 00:00:00 2001 From: Albert Astals Date: Mon, 8 Oct 2012 12:03:05 +0200 Subject: closer to the original (bzr r2807.2.13) --- UnityCore/DBusIndicators.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'UnityCore') diff --git a/UnityCore/DBusIndicators.cpp b/UnityCore/DBusIndicators.cpp index 30a935c62..2fabdff1a 100644 --- a/UnityCore/DBusIndicators.cpp +++ b/UnityCore/DBusIndicators.cpp @@ -37,6 +37,7 @@ namespace { nux::logging::Logger logger("unity.indicator.DBusIndicators"); +const std::string SERVICE_NAME("com.canonical.Unity.Panel.Service"); const std::string SERVICE_PATH("/com/canonical/Unity/Panel/Service"); const std::string SERVICE_IFACE("com.canonical.Unity.Panel.Service"); } // anonymous namespace @@ -406,7 +407,7 @@ void DBusIndicators::Impl::SyncGeometries(std::string const& name, } DBusIndicators::DBusIndicators() - : pimpl(new Impl("com.canonical.Unity.Panel.Service", this)) + : pimpl(new Impl(SERVICE_NAME, this)) {} DBusIndicators::DBusIndicators(const std::string &dbus_name) -- cgit v1.2.3 From ae36ba373dfd7f811e91c3efaaf990ca1aa308d7 Mon Sep 17 00:00:00 2001 From: Albert Astals Date: Mon, 8 Oct 2012 12:09:18 +0200 Subject: style (bzr r2807.2.14) --- UnityCore/DBusIndicators.cpp | 6 +++--- UnityCore/DBusIndicators.h | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'UnityCore') diff --git a/UnityCore/DBusIndicators.cpp b/UnityCore/DBusIndicators.cpp index 2fabdff1a..49250973f 100644 --- a/UnityCore/DBusIndicators.cpp +++ b/UnityCore/DBusIndicators.cpp @@ -48,7 +48,7 @@ const std::string SERVICE_IFACE("com.canonical.Unity.Panel.Service"); class DBusIndicators::Impl { public: - Impl(const std::string &dbus_name, DBusIndicators* owner); + Impl(std::string const& dbus_name, DBusIndicators* owner); void CheckLocalService(); void RequestSyncAll(); @@ -84,7 +84,7 @@ public: // Public Methods -DBusIndicators::Impl::Impl(const std::string &dbus_name, DBusIndicators* owner) +DBusIndicators::Impl::Impl(std::string const& dbus_name, DBusIndicators* owner) : owner_(owner) , gproxy_(dbus_name, SERVICE_PATH, SERVICE_IFACE, G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES) @@ -410,7 +410,7 @@ DBusIndicators::DBusIndicators() : pimpl(new Impl(SERVICE_NAME, this)) {} -DBusIndicators::DBusIndicators(const std::string &dbus_name) +DBusIndicators::DBusIndicators(std::string const& dbus_name) : pimpl(new Impl(dbus_name, this)) {} diff --git a/UnityCore/DBusIndicators.h b/UnityCore/DBusIndicators.h index 221c2b521..5ac1111c8 100644 --- a/UnityCore/DBusIndicators.h +++ b/UnityCore/DBusIndicators.h @@ -22,6 +22,7 @@ #include "Indicators.h" + namespace unity { namespace indicator -- cgit v1.2.3 From f15c28e6c67054ae33c584f95f6ac78902071950 Mon Sep 17 00:00:00 2001 From: Albert Astals Date: Mon, 8 Oct 2012 12:11:09 +0200 Subject: no need for double space (bzr r2807.2.15) --- UnityCore/GLibDBusProxy.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'UnityCore') diff --git a/UnityCore/GLibDBusProxy.cpp b/UnityCore/GLibDBusProxy.cpp index c23de09e8..51a7a002e 100644 --- a/UnityCore/GLibDBusProxy.cpp +++ b/UnityCore/GLibDBusProxy.cpp @@ -338,7 +338,6 @@ GVariant *DBusProxy::Impl::CallSync(std::string const& method_name, return nullptr; } - void DBusProxy::Impl::OnCallCallback(GObject* source, GAsyncResult* res, gpointer call_data) { glib::Error error; -- cgit v1.2.3 From f0031ebab64be5725a3e6b1dcb5e664a70c2a952 Mon Sep 17 00:00:00 2001 From: Albert Astals Date: Mon, 8 Oct 2012 12:12:58 +0200 Subject: i read the code easier like this (bzr r2807.2.16) --- UnityCore/GLibDBusProxy.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'UnityCore') diff --git a/UnityCore/GLibDBusProxy.cpp b/UnityCore/GLibDBusProxy.cpp index 51a7a002e..89b261239 100644 --- a/UnityCore/GLibDBusProxy.cpp +++ b/UnityCore/GLibDBusProxy.cpp @@ -312,7 +312,11 @@ GVariant *DBusProxy::Impl::CallSync(std::string const& method_name, timeout_msec, cancellable != NULL ? cancellable : cancellable_, &error); - if (error) + if (!error) + { + return ret; + } + else { if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { @@ -325,10 +329,7 @@ GVariant *DBusProxy::Impl::CallSync(std::string const& method_name, << object_path_ << "\" failed: " << error; } - - return nullptr; } - return ret; } else { -- cgit v1.2.3 From 7ded34bce7178cfb145c5d8f28576899ba045aa3 Mon Sep 17 00:00:00 2001 From: Albert Astals Date: Mon, 8 Oct 2012 12:19:33 +0200 Subject: timeout_check is a bad name, move to timeout_cb (bzr r2807.2.19) --- UnityCore/GLibDBusProxy.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'UnityCore') diff --git a/UnityCore/GLibDBusProxy.cpp b/UnityCore/GLibDBusProxy.cpp index 89b261239..93a9e6a46 100644 --- a/UnityCore/GLibDBusProxy.cpp +++ b/UnityCore/GLibDBusProxy.cpp @@ -289,12 +289,12 @@ GVariant *DBusProxy::Impl::CallSync(std::string const& method_name, if (!proxy_) { bool timedout = false; - auto timeout_check = [&] () -> bool + auto timeout_cb = [&] () -> bool { timedout = true; return false; }; - glib::Timeout timeout(timeout_msec < 0 ? 10000 : timeout_msec, timeout_check); + glib::Timeout timeout(timeout_msec < 0 ? 10000 : timeout_msec, timeout_cb); while (!proxy_ && !timedout) { -- cgit v1.2.3 From fe74cc7d058c7944795feb3dce2b4949a2c60e9a Mon Sep 17 00:00:00 2001 From: Albert Astals Date: Mon, 8 Oct 2012 13:04:54 +0200 Subject: move the star (bzr r2807.2.21) --- UnityCore/GLibDBusProxy.cpp | 2 +- UnityCore/GLibDBusProxy.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'UnityCore') diff --git a/UnityCore/GLibDBusProxy.cpp b/UnityCore/GLibDBusProxy.cpp index 93a9e6a46..afe632b74 100644 --- a/UnityCore/GLibDBusProxy.cpp +++ b/UnityCore/GLibDBusProxy.cpp @@ -280,7 +280,7 @@ void DBusProxy::Impl::Call(string const& method_name, } } -GVariant *DBusProxy::Impl::CallSync(std::string const& method_name, +GVariant* DBusProxy::Impl::CallSync(std::string const& method_name, GVariant* parameters, GCancellable *cancellable, GDBusCallFlags flags, diff --git a/UnityCore/GLibDBusProxy.h b/UnityCore/GLibDBusProxy.h index b1f62f1bd..fbc794c72 100644 --- a/UnityCore/GLibDBusProxy.h +++ b/UnityCore/GLibDBusProxy.h @@ -53,7 +53,7 @@ public: GDBusCallFlags flags = G_DBUS_CALL_FLAGS_NONE, int timeout_msec = -1); - GVariant *CallSync(std::string const& method_name, + GVariant* CallSync(std::string const& method_name, GVariant* parameters = nullptr, GCancellable *cancellable = nullptr, GDBusCallFlags flags = G_DBUS_CALL_FLAGS_NONE, -- cgit v1.2.3 From b69884c8754f609919bde2466feb71f636c64681 Mon Sep 17 00:00:00 2001 From: Albert Astals Date: Mon, 8 Oct 2012 13:10:20 +0200 Subject: more style fixes (bzr r2807.2.22) --- UnityCore/GLibDBusProxy.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'UnityCore') diff --git a/UnityCore/GLibDBusProxy.cpp b/UnityCore/GLibDBusProxy.cpp index afe632b74..8f71a4ffc 100644 --- a/UnityCore/GLibDBusProxy.cpp +++ b/UnityCore/GLibDBusProxy.cpp @@ -66,11 +66,11 @@ public: GDBusCallFlags flags, int timeout_msec); - GVariant *CallSync(string const& method_name, - GVariant* parameters, - GCancellable* cancellable, - GDBusCallFlags flags, - int timeout_msec); + GVariant* CallSync(string const& method_name, + GVariant* parameters, + GCancellable* cancellable, + GDBusCallFlags flags, + int timeout_msec); void Connect(string const& signal_name, ReplyCallback callback); bool IsConnected(); @@ -394,7 +394,7 @@ void DBusProxy::Call(string const& method_name, timeout_msec); } -GVariant *DBusProxy::CallSync(std::string const& method_name, +GVariant* DBusProxy::CallSync(std::string const& method_name, GVariant* parameters, GCancellable *cancellable, GDBusCallFlags flags, -- cgit v1.2.3 From ba1bb560066ce77b3f88e1e99657724a31c78613 Mon Sep 17 00:00:00 2001 From: Albert Astals Date: Mon, 8 Oct 2012 13:28:35 +0200 Subject: Remove CallSync from dbus proxy, go back to old dbus indicators test code (bzr r2807.2.23) --- UnityCore/GLibDBusProxy.cpp | 74 --------------------------------------------- UnityCore/GLibDBusProxy.h | 6 ---- 2 files changed, 80 deletions(-) (limited to 'UnityCore') diff --git a/UnityCore/GLibDBusProxy.cpp b/UnityCore/GLibDBusProxy.cpp index 8f71a4ffc..273bb42a3 100644 --- a/UnityCore/GLibDBusProxy.cpp +++ b/UnityCore/GLibDBusProxy.cpp @@ -66,12 +66,6 @@ public: GDBusCallFlags flags, int timeout_msec); - GVariant* CallSync(string const& method_name, - GVariant* parameters, - GCancellable* cancellable, - GDBusCallFlags flags, - int timeout_msec); - void Connect(string const& signal_name, ReplyCallback callback); bool IsConnected(); @@ -280,65 +274,6 @@ void DBusProxy::Impl::Call(string const& method_name, } } -GVariant* DBusProxy::Impl::CallSync(std::string const& method_name, - GVariant* parameters, - GCancellable *cancellable, - GDBusCallFlags flags, - int timeout_msec) -{ - if (!proxy_) - { - bool timedout = false; - auto timeout_cb = [&] () -> bool - { - timedout = true; - return false; - }; - glib::Timeout timeout(timeout_msec < 0 ? 10000 : timeout_msec, timeout_cb); - - while (!proxy_ && !timedout) - { - g_main_context_iteration(g_main_context_get_thread_default(), TRUE); - } - } - - if (proxy_) - { - glib::Error error; - GVariant *ret = g_dbus_proxy_call_sync(proxy_, - method_name.c_str(), - parameters, - flags, - timeout_msec, - cancellable != NULL ? cancellable : cancellable_, - &error); - if (!error) - { - return ret; - } - else - { - if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) - { - // silently ignore - } - else - { - LOG_WARNING(logger) << "Calling method \"" << method_name - << "\" on object path: \"" - << object_path_ - << "\" failed: " << error; - } - } - } - else - { - LOG_WARNING(logger) << "Cannot call method " << method_name - << " proxy " << object_path_ << " does not exist"; - } - return nullptr; -} - void DBusProxy::Impl::OnCallCallback(GObject* source, GAsyncResult* res, gpointer call_data) { glib::Error error; @@ -394,15 +329,6 @@ void DBusProxy::Call(string const& method_name, timeout_msec); } -GVariant* DBusProxy::CallSync(std::string const& method_name, - GVariant* parameters, - GCancellable *cancellable, - GDBusCallFlags flags, - int timeout_msec) -{ - return pimpl->CallSync(method_name, parameters, cancellable, flags, timeout_msec); -} - void DBusProxy::Connect(std::string const& signal_name, ReplyCallback callback) { pimpl->Connect(signal_name, callback); diff --git a/UnityCore/GLibDBusProxy.h b/UnityCore/GLibDBusProxy.h index fbc794c72..06cce6cc6 100644 --- a/UnityCore/GLibDBusProxy.h +++ b/UnityCore/GLibDBusProxy.h @@ -53,12 +53,6 @@ public: GDBusCallFlags flags = G_DBUS_CALL_FLAGS_NONE, int timeout_msec = -1); - GVariant* CallSync(std::string const& method_name, - GVariant* parameters = nullptr, - GCancellable *cancellable = nullptr, - GDBusCallFlags flags = G_DBUS_CALL_FLAGS_NONE, - int timeout_msec = -1); - void Connect(std::string const& signal_name, ReplyCallback callback); bool IsConnected(); -- cgit v1.2.3