diff options
| author | Michal Hruby <michal.mhr@gmail.com> | 2012-10-11 13:04:13 +0200 |
|---|---|---|
| committer | Michal Hruby <michal.mhr@gmail.com> | 2012-10-11 13:04:13 +0200 |
| commit | ea9780c33cb4e926b43b7f11e603db2468e9f3bc (patch) | |
| tree | aa5600c3e2b8b4e90b985f4beb7a930a544b76e7 /UnityCore | |
| parent | 8262f4286d4c36befdd7611b76c6f25fdfcd3682 (diff) | |
| parent | a32dbba4ac890d5430335264f8da3db16568d707 (diff) | |
Merge trunk
(bzr r2769.4.3)
Diffstat (limited to 'UnityCore')
| -rw-r--r-- | UnityCore/DBusIndicators.cpp | 33 | ||||
| -rw-r--r-- | UnityCore/DBusIndicators.h | 4 | ||||
| -rw-r--r-- | UnityCore/DesktopUtilities.cpp | 24 | ||||
| -rw-r--r-- | UnityCore/GLibDBusProxy.cpp | 28 | ||||
| -rw-r--r-- | UnityCore/HomeLens.cpp | 2 | ||||
| -rw-r--r-- | UnityCore/Indicator.cpp | 15 | ||||
| -rw-r--r-- | UnityCore/Indicator.h | 1 |
7 files changed, 90 insertions, 17 deletions
diff --git a/UnityCore/DBusIndicators.cpp b/UnityCore/DBusIndicators.cpp index 2e3df31ce..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(DBusIndicators* owner); + Impl(std::string const& dbus_name, DBusIndicators* owner); void CheckLocalService(); void RequestSyncAll(); @@ -84,9 +84,9 @@ public: // Public Methods -DBusIndicators::Impl::Impl(DBusIndicators* owner) +DBusIndicators::Impl::Impl(std::string const& 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)); @@ -276,6 +276,8 @@ void DBusIndicators::Impl::Sync(GVariant* args) return; std::map<Indicator::Ptr, Indicator::Entries> indicators; + int wantedIndex = 0; + bool anyIndexDifferent = false; g_variant_get(args, "(a(ssssbbusbbi))", &iter); while (g_variant_iter_loop(iter, "(ssssbbusbbi)", @@ -305,7 +307,18 @@ 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 + int existingEntryIndex = indicator->EntryIndex(entry_id); + if (wantedIndex == existingEntryIndex) + e = indicator->GetEntry(entry_id); + else + anyIndexDifferent = true; + } if (!e) { @@ -321,6 +334,7 @@ void DBusIndicators::Impl::Sync(GVariant* args) } entries.push_back(e); + wantedIndex++; } } g_variant_iter_free(iter); @@ -393,12 +407,21 @@ void DBusIndicators::Impl::SyncGeometries(std::string const& name, } DBusIndicators::DBusIndicators() - : pimpl(new Impl(this)) + : pimpl(new Impl(SERVICE_NAME, this)) +{} + +DBusIndicators::DBusIndicators(std::string const& dbus_name) + : pimpl(new Impl(dbus_name, this)) {} DBusIndicators::~DBusIndicators() {} +bool DBusIndicators::IsConnected() const +{ + return pimpl->gproxy_.IsConnected(); +} + void DBusIndicators::SyncGeometries(std::string const& name, EntryLocationMap const& locations) { diff --git a/UnityCore/DBusIndicators.h b/UnityCore/DBusIndicators.h index 13bf445eb..5ac1111c8 100644 --- a/UnityCore/DBusIndicators.h +++ b/UnityCore/DBusIndicators.h @@ -50,6 +50,10 @@ public: virtual void OnShowAppMenu(unsigned int xid, int x, int y, unsigned int timestamp); +protected: + DBusIndicators(std::string const& dbus_name); + bool IsConnected() const; + private: class Impl; std::unique_ptr<Impl> pimpl; diff --git a/UnityCore/DesktopUtilities.cpp b/UnityCore/DesktopUtilities.cpp index a627c191b..7ef0be903 100644 --- a/UnityCore/DesktopUtilities.cpp +++ b/UnityCore/DesktopUtilities.cpp @@ -87,6 +87,12 @@ std::string DesktopUtilities::GetDesktopID(std::vector<std::string> const& defau if (desktop_path.empty()) return ""; + 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 dir : default_paths) { if (!dir.empty()) @@ -100,11 +106,11 @@ std::string DesktopUtilities::GetDesktopID(std::vector<std::string> 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<std::string> 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<GDesktopAppInfo> 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) { diff --git a/UnityCore/GLibDBusProxy.cpp b/UnityCore/GLibDBusProxy.cpp index bd086574b..273bb42a3 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<GDBusProxy> proxy_; glib::Object<GCancellable> cancellable_; bool connected_; + unsigned reconnection_attempts_; glib::Signal<void, GDBusProxy*, char*, char*, GVariant*> g_signal_connection_; glib::Signal<void, GDBusProxy*, GParamSpec*> 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_ERROR(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)); 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) diff --git a/UnityCore/Indicator.cpp b/UnityCore/Indicator.cpp index c5eb9f127..8fe03252c 100644 --- a/UnityCore/Indicator.cpp +++ b/UnityCore/Indicator.cpp @@ -115,6 +115,21 @@ Entry::Ptr Indicator::GetEntry(std::string const& entry_id) const return Entry::Ptr(); } +int Indicator::EntryIndex(std::string const& entry_id) const +{ + int i = 0; + for (auto entry : entries_) + { + if (entry->id() == entry_id) + { + return i; + } + ++i; + } + + return -1; +} + void Indicator::OnEntryShowMenu(std::string const& entry_id, unsigned int xid, int x, int y, unsigned int button, unsigned int timestamp) { diff --git a/UnityCore/Indicator.h b/UnityCore/Indicator.h index 1fe8f1c27..23b4bd575 100644 --- a/UnityCore/Indicator.h +++ b/UnityCore/Indicator.h @@ -48,6 +48,7 @@ public: void Sync(Entries const& new_entries); Entry::Ptr GetEntry(std::string const& entry_id) const; + int EntryIndex(std::string const& entry_id) const; Entries GetEntries() const; // Signals |
