summaryrefslogtreecommitdiff
path: root/src/dbus/server/pim/edsf-view.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/dbus/server/pim/edsf-view.cpp')
-rw-r--r--src/dbus/server/pim/edsf-view.cpp118
1 files changed, 118 insertions, 0 deletions
diff --git a/src/dbus/server/pim/edsf-view.cpp b/src/dbus/server/pim/edsf-view.cpp
new file mode 100644
index 00000000..f573df9f
--- /dev/null
+++ b/src/dbus/server/pim/edsf-view.cpp
@@ -0,0 +1,118 @@
+/*
+ * Copyright (C) 2012 Intel Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) version 3.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#include "edsf-view.h"
+#include <syncevo/BoostHelper.h>
+
+SE_GOBJECT_TYPE(EdsfPersona);
+
+SE_BEGIN_CXX
+
+EDSFView::EDSFView(const ESourceRegistryCXX &registry,
+ const std::string &uuid,
+ const std::string &query) :
+ m_registry(registry),
+ m_uuid(uuid),
+ m_query(query)
+{
+}
+
+void EDSFView::init(const boost::shared_ptr<EDSFView> &self)
+{
+ m_self = self;
+}
+
+boost::shared_ptr<EDSFView> EDSFView::create(const ESourceRegistryCXX &registry,
+ const std::string &uuid,
+ const std::string &query)
+{
+ boost::shared_ptr<EDSFView> view(new EDSFView(registry, uuid, query));
+ view->init(view);
+ return view;
+}
+
+void EDSFView::doStart()
+{
+ ESourceCXX source(e_source_registry_ref_source(m_registry, m_uuid.c_str()), false);
+ if (!source) {
+ SE_LOG_DEBUG(NULL, NULL, "edsf %s: address book not found", m_uuid.c_str());
+ return;
+ }
+ m_store = EdsfPersonaStoreCXX::steal(edsf_persona_store_new_with_source_registry(m_registry, source));
+ GErrorCXX gerror;
+ m_ebook = EBookClientCXX::steal(e_book_client_new(source.get(), gerror));
+ if (!m_ebook) {
+ SE_LOG_DEBUG(NULL, NULL, "edfs %s: no client for address book: %s", m_uuid.c_str(), gerror->message);
+ return;
+ }
+ SYNCEVO_GLIB_CALL_ASYNC(e_client_open,
+ boost::bind(&EDSFView::opened,
+ m_self,
+ _1,
+ _2),
+ E_CLIENT(m_ebook.get()),
+ false,
+ NULL);
+}
+
+void EDSFView::opened(gboolean success, const GError *gerror) throw()
+{
+ try {
+ if (!success) {
+ SE_LOG_DEBUG(NULL, NULL, "edfs %s: opening failed: %s", m_uuid.c_str(), gerror->message);
+ return;
+ }
+ SYNCEVO_GLIB_CALL_ASYNC(e_book_client_get_contacts,
+ boost::bind(&EDSFView::read,
+ m_self,
+ _1,
+ _2,
+ _3),
+ m_ebook.get(),
+ m_query.c_str(),
+ NULL);
+ } catch (...) {
+ Exception::handle(HANDLE_EXCEPTION_NO_ERROR);
+ }
+}
+
+void EDSFView::read(gboolean success, GSList *contactslist, const GError *gerror) throw()
+{
+ try {
+ GListCXX<EContact, GSList, GObjectDestructor> contacts(contactslist);
+ if (!success) {
+ SE_LOG_DEBUG(NULL, NULL, "edfs %s: reading failed: %s", m_uuid.c_str(), gerror->message);
+ return;
+ }
+
+ BOOST_FOREACH (EContact *contact, contacts) {
+ EdsfPersonaCXX persona(edsf_persona_new(m_store, contact), false);
+ GeeHashSetCXX personas(gee_hash_set_new(G_TYPE_OBJECT, g_object_ref, g_object_unref, NULL, NULL), false);
+ gee_collection_add(GEE_COLLECTION(personas.get()), persona.get());
+ FolksIndividualCXX individual(folks_individual_new(GEE_SET(personas.get())), false);
+ m_addedSignal(individual);
+ }
+ m_isQuiescent = true;
+ m_quiescenceSignal();
+ } catch (...) {
+ Exception::handle(HANDLE_EXCEPTION_NO_ERROR);
+ }
+}
+
+SE_END_CXX