diff options
author | Patrick Ohly <patrick.ohly@intel.com> | 2013-02-25 21:35:46 +0100 |
---|---|---|
committer | Patrick Ohly <patrick.ohly@intel.com> | 2013-02-26 12:03:46 +0100 |
commit | fde7bc7974b1020afef98b5cbd49fc1689bcefd8 (patch) | |
tree | 7b5136742e1b25dc2a0d7709b7ef74892a9e1d9a /src/dbus/server/pim/manager.cpp | |
parent | 3c21df32e013440c5d69f58cb4e871fadb305c9f (diff) |
PIM: add ReplaceSearch, always allow it
The new ReplaceSearch is more flexible than RefineSearch. It can
handle both tightening the search and relaxing it. The downside of it
is the more expensive implementation (must check all contacts again,
then find minimal set of change signals to update view).
Previously, a search which had no filter set at all at the begining
could not be refined. This limitation of the implementation gets
removed by always using a FilteredView, even if the initial filter is
empty.
When the parent of a FilteredView emits signals, it is not necessarily
always in a consistent state and the FilteredView must not invoke
methods in the parent. Stressing the FilteredView by using it in tests
originally written for the FullView showed that the filling up a view
violated that rule and led to contacts being present multiple
times. Fixed by delaying the reading from the parent into either an
idle callback or the parent's quiescence signal processing, whichever
comes first.
Diffstat (limited to 'src/dbus/server/pim/manager.cpp')
-rw-r--r-- | src/dbus/server/pim/manager.cpp | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/src/dbus/server/pim/manager.cpp b/src/dbus/server/pim/manager.cpp index b77b4c18..8399ac5c 100644 --- a/src/dbus/server/pim/manager.cpp +++ b/src/dbus/server/pim/manager.cpp @@ -654,6 +654,7 @@ class ViewResource : public Resource, public GDBusCXX::DBusObjectHelper add(this, &ViewResource::readContacts, "ReadContacts"); add(this, &ViewResource::close, "Close"); add(this, &ViewResource::refineSearch, "RefineSearch"); + add(this, &ViewResource::replaceSearch, "ReplaceSearch"); activate(); // The view might have been started already, for example when @@ -761,11 +762,13 @@ public: /** ViewControl.RefineSearch() */ void refineSearch(const LocaleFactory::Filter_t &filter) { - if (filter.empty()) { - SE_THROW("New filter is empty. It must be more restrictive than the old filter."); - } + replaceSearch(filter, true); + } + + void replaceSearch(const LocaleFactory::Filter_t &filter, bool refine) + { boost::shared_ptr<IndividualFilter> individualFilter = m_locale->createFilter(filter); - m_view->refineFilter(individualFilter); + m_view->replaceFilter(individualFilter, refine); } }; unsigned int ViewResource::m_counter; @@ -833,17 +836,17 @@ void Manager::doSearch(const ESourceRegistryCXX ®istry, view = m_folks->getMainView(); bool quiescent = view->isQuiescent(); std::string ebookFilter; - if (!filter.empty()) { - boost::shared_ptr<IndividualFilter> individualFilter = m_locale->createFilter(filter); - ebookFilter = individualFilter->getEBookFilter(); - if (quiescent) { - // Don't search via EDS directly because the unified - // address book is ready. - ebookFilter.clear(); - } - view = FilteredView::create(view, individualFilter); - view->setName(StringPrintf("filtered view%u", ViewResource::getNextViewNumber())); + // Always use a filtered view. That way we can implement ReplaceView or RefineView + // without having to switch from a FullView to a FilteredView. + boost::shared_ptr<IndividualFilter> individualFilter = m_locale->createFilter(filter); + ebookFilter = individualFilter->getEBookFilter(); + if (quiescent) { + // Don't search via EDS directly because the unified + // address book is ready. + ebookFilter.clear(); } + view = FilteredView::create(view, individualFilter); + view->setName(StringPrintf("filtered view%u", ViewResource::getNextViewNumber())); SE_LOG_DEBUG(NULL, NULL, "preparing %s: EDS search term is '%s', active address books %s", view->getName(), |