diff options
| author | Pawel Stolowski <pawel.stolowski@canonical.com> | 2012-09-06 17:30:59 +0200 | 
|---|---|---|
| committer | Pawel Stolowski <pawel.stolowski@canonical.com> | 2012-09-06 17:30:59 +0200 | 
| commit | e95ee42a73e7d896b99884b5308b59c649c12abf (patch) | |
| tree | c53bfeae5edd1c0edd7d4f5e162936daf00dd689 | |
| parent | 310bc79b9bdec2b87f0f74d3cfee9ba4d8d00c96 (diff) | |
| parent | 5eb7dd1938afa9574cf5996b89792506a02430a5 (diff) | |
Merged trunk.
(bzr r2655.7.2)
| -rw-r--r-- | UnityCore/GLibSource.cpp | 27 | ||||
| -rw-r--r-- | UnityCore/GLibSource.h | 19 | ||||
| -rw-r--r-- | dash/DashView.cpp | 6 | ||||
| -rw-r--r-- | tests/test_glib_source.cpp | 34 | ||||
| -rw-r--r-- | unity-shared/CoverArt.cpp | 1 | 
5 files changed, 60 insertions, 27 deletions
| diff --git a/UnityCore/GLibSource.cpp b/UnityCore/GLibSource.cpp index dbce7cf5b..29de4ed63 100644 --- a/UnityCore/GLibSource.cpp +++ b/UnityCore/GLibSource.cpp @@ -69,13 +69,12 @@ Source::Priority Source::GetPriority() const  return static_cast<Priority>(prio);  } -bool Source::Run(Callback callback) +bool Source::Run(Callback const& callback)  {  if (!source_ || source_id_ || IsRunning())  return false; - callback_ = callback; - callback_data_ = new CallBackData(this); + callback_data_ = new CallBackData(this, callback);  g_source_set_callback(source_, SourceCallback, callback_data_, DestroyCallback);  source_id_ = g_source_attach(source_, nullptr); @@ -101,16 +100,14 @@ gboolean Source::SourceCallback(gpointer data)  if (!data)  return G_SOURCE_REMOVE; - auto self = static_cast<CallBackData*>(data)->self; + auto cb_data = static_cast<CallBackData*>(data); - if (self && self->callback_ && self->callback_()) + if (cb_data && cb_data->callback_fn_ && cb_data->callback_fn_())  {  return G_SOURCE_CONTINUE;  } - else - { - return G_SOURCE_REMOVE; - } + + return G_SOURCE_REMOVE;  }  void Source::DestroyCallback(gpointer data) @@ -133,7 +130,7 @@ void Source::DestroyCallback(gpointer data)  } -Timeout::Timeout(unsigned int milliseconds, Callback cb, Priority prio) +Timeout::Timeout(unsigned int milliseconds, Callback const& cb, Priority prio)  {  Init(milliseconds, prio);  Run(cb); @@ -151,7 +148,7 @@ void Timeout::Init(unsigned int milliseconds, Priority prio)  } -TimeoutSeconds::TimeoutSeconds(unsigned int seconds, Callback cb, Priority prio) +TimeoutSeconds::TimeoutSeconds(unsigned int seconds, Callback const& cb, Priority prio)  {  Init(seconds, prio);  Run(cb); @@ -169,7 +166,7 @@ void TimeoutSeconds::Init(unsigned int seconds, Priority prio)  } -Idle::Idle(Callback cb, Priority prio) +Idle::Idle(Callback const& cb, Priority prio)  {  Init(prio);  Run(cb); @@ -255,7 +252,7 @@ Source::Ptr SourceManager::AddTimeout(unsigned int milliseconds, std::string con  return nullptr;  } -Source::Ptr SourceManager::AddTimeout(unsigned int milliseconds, Source::Callback cb, std::string const& nick) +Source::Ptr SourceManager::AddTimeout(unsigned int milliseconds, Source::Callback const& cb, std::string const& nick)  {  auto timeout = std::make_shared<Timeout>(milliseconds); @@ -280,7 +277,7 @@ Source::Ptr SourceManager::AddTimeoutSeconds(unsigned int seconds, std::string c  return nullptr;  } -Source::Ptr SourceManager::AddTimeoutSeconds(unsigned int seconds, Source::Callback cb, std::string const& nick) +Source::Ptr SourceManager::AddTimeoutSeconds(unsigned int seconds, Source::Callback const& cb, std::string const& nick)  {  auto timeout = std::make_shared<TimeoutSeconds>(seconds); @@ -305,7 +302,7 @@ Source::Ptr SourceManager::AddIdle(std::string const& nick)  return nullptr;  } -Source::Ptr SourceManager::AddIdle(Source::Callback cb, std::string const& nick) +Source::Ptr SourceManager::AddIdle(Source::Callback const& cb, std::string const& nick)  {  auto idle = std::make_shared<Idle>(); diff --git a/UnityCore/GLibSource.h b/UnityCore/GLibSource.h index 468e6b8af..3a09c088c 100644 --- a/UnityCore/GLibSource.h +++ b/UnityCore/GLibSource.h @@ -77,7 +77,7 @@ public:  * This Run a source using the @callback function as Source's callback.  * The method will return false if the source is already running, true otherwise.  */ - bool Run(Callback callback); + bool Run(Callback const& callback);  bool IsRunning() const;  /** @@ -104,11 +104,13 @@ protected:  private:  struct CallBackData  { - CallBackData(Source* src) + CallBackData(Source* src, Callback const& callback)  : self(src) + , callback_fn_(callback)  {}  Source* self; + Callback callback_fn_;  };  static gboolean SourceCallback(gpointer data); @@ -116,7 +118,6 @@ private:  unsigned int source_id_;  CallBackData* callback_data_; - Callback callback_;  }; @@ -133,7 +134,7 @@ class Timeout : public Source  {  public:  Timeout(unsigned int milliseconds, Priority prio = Priority::DEFAULT); - Timeout(unsigned int milliseconds, Callback cb, Priority prio = Priority::DEFAULT); + Timeout(unsigned int milliseconds, Callback const& cb, Priority prio = Priority::DEFAULT);  private:  void Init(unsigned int milliseconds, Priority prio); @@ -153,7 +154,7 @@ class TimeoutSeconds : public Source  {  public:  TimeoutSeconds(unsigned int seconds, Priority prio = Priority::DEFAULT); - TimeoutSeconds(unsigned int seconds, Callback cb, Priority prio = Priority::DEFAULT); + TimeoutSeconds(unsigned int seconds, Callback const& cb, Priority prio = Priority::DEFAULT);  private:  void Init(unsigned int seconds, Priority prio); @@ -173,7 +174,7 @@ class Idle : public Source  {  public:  Idle(Priority prio = Priority::DEFAULT_IDLE); - Idle(Callback cb, Priority prio = Priority::DEFAULT_IDLE); + Idle(Callback const& cb, Priority prio = Priority::DEFAULT_IDLE);  private:  void Init(Priority prio); @@ -206,13 +207,13 @@ public:  bool Add(Source::Ptr const& source, std::string const& nick = "");  Source::Ptr AddTimeout(unsigned int milliseconds, std::string const& nick = ""); - Source::Ptr AddTimeout(unsigned int milliseconds, Source::Callback cb, std::string const& nick = ""); + Source::Ptr AddTimeout(unsigned int milliseconds, Source::Callback const& cb, std::string const& nick = "");  Source::Ptr AddTimeoutSeconds(unsigned int seconds, std::string const& nick = ""); - Source::Ptr AddTimeoutSeconds(unsigned int seconds, Source::Callback cb, std::string const& nick = ""); + Source::Ptr AddTimeoutSeconds(unsigned int seconds, Source::Callback const& cb, std::string const& nick = "");  Source::Ptr AddIdle(std::string const& nick = ""); - Source::Ptr AddIdle(Source::Callback cb, std::string const& nick = ""); + Source::Ptr AddIdle(Source::Callback const& cb, std::string const& nick = "");  bool Remove(std::string const& nick);  bool Remove(unsigned int id); diff --git a/dash/DashView.cpp b/dash/DashView.cpp index fb6bde6dd..65bd73e50 100644 --- a/dash/DashView.cpp +++ b/dash/DashView.cpp @@ -247,6 +247,12 @@ void DashView::AboutToHide()  home_lens_->view_type = ViewType::HIDDEN;  LOG_DEBUG(logger) << "Setting ViewType " << ViewType::HIDDEN  << " on '" << home_lens_->id() << "'"; + + // if a preview is open, close it + if (preview_displaying_)  + { + ClosePreview(); + }  }  void DashView::SetupViews() diff --git a/tests/test_glib_source.cpp b/tests/test_glib_source.cpp index a654fa8fa..54718c91e 100644 --- a/tests/test_glib_source.cpp +++ b/tests/test_glib_source.cpp @@ -247,11 +247,14 @@ TEST(TestGLibTimeout, RemovePtrOnCallback)  unsigned int local_callback_call_count = 0;  Source::UniquePtr timeout(new Timeout(10, [&] { + unsigned int id = timeout->Id();  local_callback_called = true; - ++local_callback_call_count; - timeout.reset(); + local_callback_call_count++; - // this function would be called more than once if we had not removed the source. + timeout.reset(); + // resetting the ptr should destroy the source. + EXPECT_TRUE(g_main_context_find_source_by_id(NULL, id) == nullptr); + // this function would be called more than once (local_callback_call_count > 1) if we had not removed the source.  return true;  })); @@ -262,6 +265,31 @@ TEST(TestGLibTimeout, RemovePtrOnCallback)  EXPECT_EQ(local_callback_call_count, 1);  } +TEST(TestGLibTimeout, AutoRemoveSourceOnCallback) +{ + bool local_callback_called = false; + unsigned int local_callback_call_count = 0; + + Source::UniquePtr timeout(new Timeout(10, [&] { + local_callback_called = true; + ++local_callback_call_count; + + // return false to remove source. + return false; + })); + unsigned int id = timeout->Id(); + + Utils::WaitForTimeoutMSec(100); + + timeout.reset(); + EXPECT_EQ(local_callback_called, true); + EXPECT_EQ(local_callback_call_count, 1); + + // source should be removed by now. + EXPECT_TRUE(g_main_context_find_source_by_id(NULL, id) == nullptr); +} + +  // GLib TimeoutSeconds tests  TEST(TestGLibTimeoutSeconds, Construction) diff --git a/unity-shared/CoverArt.cpp b/unity-shared/CoverArt.cpp index 000be4dd2..ac8044e5a 100644 --- a/unity-shared/CoverArt.cpp +++ b/unity-shared/CoverArt.cpp @@ -286,6 +286,7 @@ void CoverArt::TextureLoaded(std::string const& texid, unsigned size, glib::Obje  return;  }  texture_screenshot_.Adopt(nux::CreateTexture2DFromPixbuf(pixbuf, true)); + QueueDraw();  }  void CoverArt::Draw(nux::GraphicsEngine& gfx_engine, bool force_draw) | 
