[gnote] Add shell search provider



commit 7aea1e511b577130a5eee6fe3bd95fa6a6962fca
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Sun May 5 17:02:55 2013 +0300

    Add shell search provider
    
    Make notes apear in result of GNOME Shell search.
    Bug 694014.

 src/Makefile.am                                    |    3 +-
 src/dbus/Makefile.am                               |   11 +-
 src/dbus/gnote-search-provider.ini                 |    5 +
 src/dbus/searchprovider.cpp                        |  240 ++++++++++++++++++++
 src/dbus/searchprovider.hpp                        |   75 ++++++
 src/dbus/shell-search-provider-dbus-interfaces.xml |   87 +++++++
 src/remotecontrolproxy.cpp                         |   59 +++--
 src/remotecontrolproxy.hpp                         |   14 +-
 8 files changed, 468 insertions(+), 26 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 2408b6e..d9750cf 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -62,6 +62,7 @@ DBUS_SOURCES=remotecontrolproxy.hpp remotecontrolproxy.cpp \
        dbus/iremotecontrol.hpp \
        dbus/remotecontrol-client-glue.cpp \
        dbus/remotecontrol-glue.cpp \
+       dbus/searchprovider.hpp dbus/searchprovider.cpp \
        $(NULL)
 
 libgnote_la_LDFLAGS = -release @LIBGNOTE_RELEASE@ -version-info @LIBGNOTE_VERSION_INFO@
@@ -159,7 +160,7 @@ gnote_SOURCES = \
        synchronization/silentui.hpp synchronization/silentui.cpp \
        synchronization/syncdialog.hpp synchronization/syncdialog.cpp \
        synchronization/syncmanager.hpp synchronization/syncmanager.cpp \
-       $(DBUS_SOURCES)   \
+       $(DBUS_SOURCES) \
        main.cpp \
        $(NULL)
 
diff --git a/src/dbus/Makefile.am b/src/dbus/Makefile.am
index b8a8e61..7e60e55 100644
--- a/src/dbus/Makefile.am
+++ b/src/dbus/Makefile.am
@@ -1,8 +1,13 @@
 introspectdir = $(datadir)/gnote
 
-introspect_DATA = gnote-introspect.xml
+introspect_DATA = \
+       gnote-introspect.xml \
+       shell-search-provider-dbus-interfaces.xml
+
+searchproviderdir = $(datadir)/gnome-shell/search-providers
+searchprovider_DATA = gnote-search-provider.ini
 
 EXTRA_DIST = \
        gnote-introspect.xml \
-       remotecontrol-glue.hpp \
-       remotecontrol-client-glue.hpp
+       src/dbus/shell-search-provider-dbus-interfaces.xml \
+       $(searchprovider_DATA)
diff --git a/src/dbus/gnote-search-provider.ini b/src/dbus/gnote-search-provider.ini
new file mode 100644
index 0000000..073f7ab
--- /dev/null
+++ b/src/dbus/gnote-search-provider.ini
@@ -0,0 +1,5 @@
+[Shell Search Provider]
+DesktopId=gnote.desktop
+BusName=org.gnome.Gnote
+ObjectPath=/org/gnome/Gnote/SearchProvider
+Version=2
diff --git a/src/dbus/searchprovider.cpp b/src/dbus/searchprovider.cpp
new file mode 100644
index 0000000..4646e82
--- /dev/null
+++ b/src/dbus/searchprovider.cpp
@@ -0,0 +1,240 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 2013 Aurimas Cernius
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include <giomm/dbusconnection.h>
+#include <giomm/dbuserror.h>
+
+#include "debug.hpp"
+#include "iconmanager.hpp"
+#include "ignote.hpp"
+#include "search.hpp"
+#include "searchprovider.hpp"
+
+
+namespace org {
+namespace gnome {
+namespace Gnote {
+
+
+SearchProvider::SearchProvider(const Glib::RefPtr<Gio::DBus::Connection> & conn,
+                               const char *object_path,
+                               const Glib::RefPtr<Gio::DBus::InterfaceInfo> & search_interface,
+                               gnote::NoteManager & manager)
+  : Gio::DBus::InterfaceVTable(sigc::mem_fun(*this, &SearchProvider::on_method_call))
+  , m_manager(manager)
+{
+  conn->register_object(object_path, search_interface, *this);
+
+  m_stubs["GetInitialResultSet"] = &SearchProvider::GetInitialResultSet_stub;
+  m_stubs["GetSubsearchResultSet"] = &SearchProvider::GetSubsearchResultSet_stub;
+  m_stubs["GetResultMetas"] = &SearchProvider::GetResultMetas_stub;
+  m_stubs["ActivateResult"] = &SearchProvider::ActivateResult_stub;
+  m_stubs["LaunchSearch"] = &SearchProvider::LaunchSearch_stub;
+}
+
+void SearchProvider::on_method_call(const Glib::RefPtr<Gio::DBus::Connection> &,
+                                    const Glib::ustring &,
+                                    const Glib::ustring &,
+                                    const Glib::ustring &,
+                                    const Glib::ustring & method_name,
+                                    const Glib::VariantContainerBase & parameters,
+                                    const Glib::RefPtr<Gio::DBus::MethodInvocation> & invocation)
+{
+  DBG_OUT("Search method %s called", method_name.c_str());
+  std::map<Glib::ustring, stub_func>::iterator iter = m_stubs.find(method_name);
+  if(iter == m_stubs.end()) {
+    invocation->return_error(Gio::DBus::Error(Gio::DBus::Error::UNKNOWN_METHOD,
+                             "Unknown method: " + method_name));
+  }
+  else {
+    try {
+      stub_func func = iter->second;
+      invocation->return_value((this->*func)(parameters));
+    }
+    catch(Glib::Exception & e) {
+      invocation->return_error(Gio::DBus::Error(Gio::DBus::Error::UNKNOWN_METHOD,
+                               "Exception in method " + method_name + ": " + e.what()));
+    }
+    catch(std::exception & e) {
+      invocation->return_error(Gio::DBus::Error(Gio::DBus::Error::UNKNOWN_METHOD,
+                               "Exception in method " + method_name + ": " + e.what()));
+    }
+    catch(...) {
+      invocation->return_error(Gio::DBus::Error(Gio::DBus::Error::UNKNOWN_METHOD,
+                               "Exception in method " + method_name));
+    }
+  }
+}
+
+std::vector<Glib::ustring> SearchProvider::GetInitialResultSet(const std::vector<Glib::ustring> & terms)
+{
+  std::set<gnote::Note::Ptr> final_result;
+  gnote::Search search(m_manager);
+  gnote::notebooks::Notebook::Ptr notebook;
+  for(std::vector<Glib::ustring>::const_iterator query = terms.begin(); query != terms.end(); ++query) {
+    gnote::Search::ResultsPtr results = search.search_notes(*query, false, notebook);
+    for(gnote::Search::Results::iterator iter = results->begin(); iter != results->end(); ++iter) {
+      final_result.insert(iter->second);
+    }
+  }
+
+  std::vector<Glib::ustring> ret;
+  for(std::set<gnote::Note::Ptr>::iterator iter = final_result.begin(); iter != final_result.end(); ++iter) {
+    ret.push_back((*iter)->uri());
+  }
+
+  return ret;
+}
+
+Glib::VariantContainerBase SearchProvider::GetInitialResultSet_stub(const Glib::VariantContainerBase & 
params)
+{
+  if(params.get_n_children() != 1) {
+    throw std::invalid_argument("One argument expected");
+  }
+
+  Glib::Variant<std::vector<Glib::ustring> > terms;
+  params.get_child(terms, 0);
+  return Glib::VariantContainerBase::create_tuple(
+    Glib::Variant<std::vector<Glib::ustring> >::create(GetInitialResultSet(terms.get())));
+}
+
+std::vector<Glib::ustring> SearchProvider::GetSubsearchResultSet(
+    const std::vector<Glib::ustring> & previous_results, const std::vector<Glib::ustring> & terms)
+{
+  std::set<Glib::ustring> previous(previous_results.begin(), previous_results.end());
+  if(previous.size() == 0) {
+    return std::vector<Glib::ustring>();
+  }
+
+  std::vector<Glib::ustring> final_result;
+  std::vector<Glib::ustring> new_result = GetInitialResultSet(terms);
+  for(std::vector<Glib::ustring>::iterator iter = new_result.begin(); iter != new_result.end(); ++iter) {
+    if(previous.find(*iter) != previous.end()) {
+      final_result.push_back(*iter);
+    }
+  }
+
+  return final_result;
+}
+
+Glib::VariantContainerBase SearchProvider::GetSubsearchResultSet_stub(const Glib::VariantContainerBase & 
params)
+{
+  if(params.get_n_children() != 2) {
+    throw std::invalid_argument("Two arguments expected");
+  }
+
+  Glib::Variant<std::vector<Glib::ustring> > previous_results, terms;
+  params.get_child(previous_results, 0);
+  params.get_child(terms, 1);
+  return Glib::VariantContainerBase::create_tuple(
+    Glib::Variant<std::vector<Glib::ustring> >::create(GetSubsearchResultSet(previous_results.get(), 
terms.get())));
+}
+
+std::vector<std::map<Glib::ustring, Glib::ustring> > SearchProvider::GetResultMetas(
+    const std::vector<Glib::ustring> & identifiers)
+{
+  std::vector<std::map<Glib::ustring, Glib::ustring> > ret;
+  for(std::vector<Glib::ustring>::const_iterator iter = identifiers.begin(); iter != identifiers.end(); 
++iter) {
+    gnote::Note::Ptr note = m_manager.find_by_uri(*iter);
+    if(note == 0) {
+      continue;
+    }
+
+    std::map<Glib::ustring, Glib::ustring> meta;
+    meta["id"] = note->uri();
+    meta["name"] = note->get_title();
+    ret.push_back(meta);
+  }
+
+  return ret;
+}
+
+Glib::VariantContainerBase SearchProvider::GetResultMetas_stub(const Glib::VariantContainerBase & params)
+{
+  if(params.get_n_children() != 1) {
+    throw std::invalid_argument("One argument expected");
+  }
+
+  Glib::Variant<std::vector<Glib::ustring> > identifiers;
+  params.get_child(identifiers, 0);
+  std::vector<std::map<Glib::ustring, Glib::ustring> > metas = GetResultMetas(identifiers.get());
+
+  GVariantBuilder result;
+  g_variant_builder_init(&result, G_VARIANT_TYPE("aa{sv}"));
+
+  for(std::vector<std::map<Glib::ustring, Glib::ustring> >::iterator iter = metas.begin();
+      iter != metas.end(); ++iter) {
+    g_variant_builder_open(&result, G_VARIANT_TYPE("a{sv}"));
+    for(std::map<Glib::ustring, Glib::ustring>::iterator entry = iter->begin(); entry != iter->end(); 
++entry) {
+      g_variant_builder_add(&result, "{sv}", entry->first.c_str(), 
g_variant_new_string(entry->second.c_str()));
+    }
+    g_variant_builder_add(&result, "{sv}", "gicon", g_variant_new_string(get_icon()));
+    g_variant_builder_close(&result);
+  }
+
+  return Glib::VariantContainerBase(g_variant_new("(aa{sv})", &result));
+}
+
+void SearchProvider::ActivateResult(const Glib::ustring & identifier,
+                                    const std::vector<Glib::ustring> & /*terms*/,
+                                    guint32 /*timestamp*/)
+{
+  gnote::Note::Ptr note = m_manager.find_by_uri(identifier);
+  if(note != 0) {
+    gnote::IGnote::obj().open_note(note);
+  }
+}
+
+Glib::VariantContainerBase SearchProvider::ActivateResult_stub(const Glib::VariantContainerBase & params)
+{
+  if(params.get_n_children() != 3) {
+    throw std::invalid_argument("Expected three arguments");
+  }
+
+  Glib::Variant<Glib::ustring> identifier;
+  Glib::Variant<std::vector<Glib::ustring> > terms;
+  Glib::Variant<guint32> timestamp;
+  params.get_child(identifier, 0);
+  params.get_child(terms, 1);
+  params.get_child(timestamp, 2);
+  ActivateResult(identifier.get(), terms.get(), timestamp.get());
+  return Glib::VariantContainerBase();
+}
+
+Glib::VariantContainerBase SearchProvider::LaunchSearch_stub(const Glib::VariantContainerBase &)
+{
+  // this method does nothing
+  return Glib::VariantContainerBase();
+}
+
+gchar *SearchProvider::get_icon()
+{
+  if(m_note_icon == 0) {
+    Gtk::IconInfo info = gnote::IconManager::obj().lookup_icon(gnote::IconManager::NOTE, 48);
+    m_note_icon = Gio::Icon::create(info.get_filename());
+  }
+
+  return g_icon_to_string(m_note_icon->gobj());
+}
+
+
+}
+}
+}
diff --git a/src/dbus/searchprovider.hpp b/src/dbus/searchprovider.hpp
new file mode 100644
index 0000000..0fe61cc
--- /dev/null
+++ b/src/dbus/searchprovider.hpp
@@ -0,0 +1,75 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 2013 Aurimas Cernius
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _DBUS_SEARCHPROVIDER_HPP_
+#define _DBUS_SEARCHPROVIDER_HPP_
+
+
+#include <giomm/dbusinterfacevtable.h>
+
+#include "notemanager.hpp"
+
+
+namespace org {
+namespace gnome {
+namespace Gnote {
+
+class SearchProvider
+  : Gio::DBus::InterfaceVTable
+{
+public:
+  SearchProvider(const Glib::RefPtr<Gio::DBus::Connection> & conn, const char *object_path,
+                 const Glib::RefPtr<Gio::DBus::InterfaceInfo> & search_interface,
+                 gnote::NoteManager & manager);
+
+  std::vector<Glib::ustring> GetInitialResultSet(const std::vector<Glib::ustring> & terms);
+  std::vector<Glib::ustring> GetSubsearchResultSet(const std::vector<Glib::ustring> & previous_results,
+                                                   const std::vector<Glib::ustring> & terms);
+  std::vector<std::map<Glib::ustring, Glib::ustring> > GetResultMetas(
+        const std::vector<Glib::ustring> & identifiers);
+  void ActivateResult(const Glib::ustring & identifier, const std::vector<Glib::ustring> & terms, guint32 
timestamp);
+private:
+  void on_method_call(const Glib::RefPtr<Gio::DBus::Connection> & connection,
+                      const Glib::ustring & sender,
+                      const Glib::ustring & object_path,
+                      const Glib::ustring & interface_name,
+                      const Glib::ustring & method_name,
+                      const Glib::VariantContainerBase & parameters,
+                      const Glib::RefPtr<Gio::DBus::MethodInvocation> & invocation);
+
+  Glib::VariantContainerBase GetInitialResultSet_stub(const Glib::VariantContainerBase &);
+  Glib::VariantContainerBase GetSubsearchResultSet_stub(const Glib::VariantContainerBase &);
+  Glib::VariantContainerBase GetResultMetas_stub(const Glib::VariantContainerBase &);
+  Glib::VariantContainerBase ActivateResult_stub(const Glib::VariantContainerBase &);
+  Glib::VariantContainerBase LaunchSearch_stub(const Glib::VariantContainerBase &);
+  gchar *get_icon();
+
+  typedef Glib::VariantContainerBase (SearchProvider::*stub_func)(const Glib::VariantContainerBase &);
+  std::map<Glib::ustring, stub_func> m_stubs;
+
+  gnote::NoteManager & m_manager;
+  Glib::RefPtr<Gio::Icon> m_note_icon;
+};
+
+}
+}
+}
+
+#endif
diff --git a/src/dbus/shell-search-provider-dbus-interfaces.xml 
b/src/dbus/shell-search-provider-dbus-interfaces.xml
new file mode 100644
index 0000000..26b213d
--- /dev/null
+++ b/src/dbus/shell-search-provider-dbus-interfaces.xml
@@ -0,0 +1,87 @@
+<!DOCTYPE node PUBLIC
+'-//freedesktop//DTD D-BUS Object Introspection 1.0//EN'
+'http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd'>
+<node>
+
+  <!--
+      org.gnome.Shell.SearchProvider2:
+      @short_description: Search provider interface
+
+      The interface used for integrating into GNOME Shell's search
+      interface (version 2).
+  -->
+  <interface name="org.gnome.Shell.SearchProvider2">
+
+    <!--
+        GetInitialResultSet:
+        @terms: Array of search terms, which the provider should treat as logical AND.
+        @results: An array of result identifier strings representing items which match the given search 
terms. Identifiers must be unique within the provider's domain, but other than that may be chosen freely by 
the provider.
+
+        Called when the user first begins a search.
+    -->
+    <method name="GetInitialResultSet">
+      <arg type="as" name="terms" direction="in" />
+      <arg type="as" name="results" direction="out" />
+    </method>
+
+    <!--
+        GetSubsearchResultSet:
+        @previous_results: Array of results previously returned by GetInitialResultSet().
+        @terms: Array of updated search terms, which the provider should treat as logical AND.
+        @results: An array of result identifier strings representing items which match the given search 
terms. Identifiers must be unique within the provider's domain, but other than that may be chosen freely by 
the provider.
+
+        Called when a search is performed which is a "subsearch" of
+        the previous search, e.g. the method may return less results, but
+        not more or different results.
+
+        This allows search providers to only search through the previous
+        result set, rather than possibly performing a full re-query.
+    -->
+    <method name="GetSubsearchResultSet">
+      <arg type="as" name="previous_results" direction="in" />
+      <arg type="as" name="terms" direction="in" />
+      <arg type="as" name="results" direction="out" />
+    </method>
+
+    <!--
+        GetResultMetas:
+        @identifiers: An array of result identifiers as returned by GetInitialResultSet() or 
GetSubsearchResultSet()
+        @metas: A dictionary describing the given search result, containing 'id' and 'name' (both strings). 
Optionally, either 'gicon' (a serialized GIcon) or 'icon-data' (raw image data as (iiibiiay) - width, height, 
rowstride, has-alpha, bits per sample, channels, data) can be specified if the result can be better served 
with a thumbnail of the content (such as with images). A 'description' field (string) may also be specified 
if more context would help the user find the desired result.
+
+        Return an array of meta data used to display each given result
+    -->
+    <method name="GetResultMetas">
+      <arg type="as" name="identifiers" direction="in" />
+      <arg type="aa{sv}" name="metas" direction="out" />
+    </method>
+
+    <!--
+        ActivateResult:
+        @identifier: A result identifier as returned by GetInitialResultSet() or GetSubsearchResultSet()
+        @terms: Array of search terms, which the provider should treat as logical AND.
+        @timestamp: A timestamp of the user interaction that triggered this call
+
+        Called when the users chooses a given result. The result should
+        be displayed in the application associated with the corresponding
+        provider. The provided search terms can be used to allow launching a full search in
+        the application.
+    -->
+    <method name="ActivateResult">
+      <arg type="s" name="identifier" direction="in" />
+      <arg type="as" name="terms" direction="in" />
+      <arg type="u" name="timestamp" direction="in" />
+    </method>
+
+    <!--
+        LaunchSearch:
+        @terms: Array of search terms, which the provider should treat as logical AND.
+        @timestamp: A timestamp of the user interaction that triggered this call
+
+        Asks the search provider to launch a full search in the application for the provided terms.
+    -->
+    <method name="LaunchSearch">
+      <arg type="as" name="terms" direction="in" />
+      <arg type="u" name="timestamp" direction="in" />
+    </method>
+  </interface>
+</node>
diff --git a/src/remotecontrolproxy.cpp b/src/remotecontrolproxy.cpp
index eb6fb31..aab810f 100644
--- a/src/remotecontrolproxy.cpp
+++ b/src/remotecontrolproxy.cpp
@@ -27,21 +27,54 @@
 #include "debug.hpp"
 #include "dbus/remotecontrol.hpp"
 #include "dbus/remotecontrolclient.hpp"
+#include "dbus/searchprovider.hpp"
 #include "remotecontrolproxy.hpp"
 
 
+namespace {
+  void load_interface_from_file(const char *filename, const char *interface_name,
+                                Glib::RefPtr<Gio::DBus::InterfaceInfo> & interface)
+  {
+    if(interface != 0) {
+      return;
+    }
+    std::ifstream fin(filename);
+    if(!fin) {
+      return;
+    }
+    Glib::ustring introspect_xml;
+    while(!fin.eof()) {
+      std::string line;
+      std::getline(fin, line);
+      introspect_xml += line;
+    }
+    fin.close();
+    try {
+      Glib::RefPtr<Gio::DBus::NodeInfo> node = Gio::DBus::NodeInfo::create_for_xml(introspect_xml);
+      interface = node->lookup_interface(interface_name);
+    }
+    catch(Glib::Error & e) {
+      ERR_OUT(_("Failed to load D-Bus interface %s: %s"), interface_name, e.what().c_str());
+    }
+  }
+}
+
 namespace gnote {
 
 const char *RemoteControlProxy::GNOTE_SERVER_NAME = "org.gnome.Gnote";
 const char *RemoteControlProxy::GNOTE_INTERFACE_NAME = "org.gnome.Gnote.RemoteControl";
 const char *RemoteControlProxy::GNOTE_SERVER_PATH = "/org/gnome/Gnote/RemoteControl";
+const char *RemoteControlProxy::GNOTE_SEARCH_PROVIDER_PATH = "/org/gnome/Gnote/SearchProvider";
+const char *RemoteControlProxy::GNOTE_SEARCH_PROVIDER_INTERFACE_NAME = "org.gnome.Shell.SearchProvider2";
 
 NoteManager *RemoteControlProxy::s_manager;
 RemoteControl *RemoteControlProxy::s_remote_control;
+org::gnome::Gnote::SearchProvider *RemoteControlProxy::s_search_provider;
 bool RemoteControlProxy::s_bus_acquired;
 Glib::RefPtr<Gio::DBus::Connection> RemoteControlProxy::s_connection;
 Glib::RefPtr<RemoteControlClient> RemoteControlProxy::s_remote_control_proxy;
 Glib::RefPtr<Gio::DBus::InterfaceInfo> RemoteControlProxy::s_gnote_interface;
+Glib::RefPtr<Gio::DBus::InterfaceInfo> RemoteControlProxy::s_search_provider_interface;
 RemoteControlProxy::slot_name_acquire_finish RemoteControlProxy::s_on_name_acquire_finish;
 
 
@@ -103,6 +136,8 @@ void RemoteControlProxy::register_object(const Glib::RefPtr<Gio::DBus::Connectio
 {
   load_introspection_xml();
   s_remote_control = new RemoteControl(conn, manager, GNOTE_SERVER_PATH, GNOTE_INTERFACE_NAME, 
s_gnote_interface);
+  s_search_provider = new org::gnome::Gnote::SearchProvider(conn, GNOTE_SEARCH_PROVIDER_PATH,
+                                                            s_search_provider_interface, manager);
   on_finish(true, true);
 }
 
@@ -115,27 +150,9 @@ void RemoteControlProxy::on_name_lost(const Glib::RefPtr<Gio::DBus::Connection>
 
 void RemoteControlProxy::load_introspection_xml()
 {
-  if(s_gnote_interface != 0) {
-    return;
-  }
-  std::ifstream fin(DATADIR"/gnote/gnote-introspect.xml");
-  if(!fin) {
-    return;
-  }
-  Glib::ustring introspect_xml;
-  while(!fin.eof()) {
-    std::string line;
-    std::getline(fin, line);
-    introspect_xml += line;
-  }
-  fin.close();
-  try {
-    Glib::RefPtr<Gio::DBus::NodeInfo> node = Gio::DBus::NodeInfo::create_for_xml(introspect_xml);
-    s_gnote_interface = node->lookup_interface(GNOTE_INTERFACE_NAME);
-  }
-  catch(Glib::Error & e) {
-    ERR_OUT(_("Failed to load D-Bus interface: %s"), e.what().c_str());
-  }
+  load_interface_from_file(DATADIR"/gnote/gnote-introspect.xml", GNOTE_INTERFACE_NAME, s_gnote_interface);
+  load_interface_from_file(DATADIR"/gnote/shell-search-provider-dbus-interfaces.xml",
+                           GNOTE_SEARCH_PROVIDER_INTERFACE_NAME, s_search_provider_interface);
 }
 
 }
diff --git a/src/remotecontrolproxy.hpp b/src/remotecontrolproxy.hpp
index 176ce83..f48fb63 100644
--- a/src/remotecontrolproxy.hpp
+++ b/src/remotecontrolproxy.hpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2011 Aurimas Cernius
+ * Copyright (C) 2011,2013 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
@@ -25,6 +25,14 @@
 #include <giomm/dbusconnection.h>
 #include <giomm/dbusintrospection.h>
 
+namespace org {
+namespace gnome {
+namespace Gnote {
+  class SearchProvider;
+}
+}
+}
+
 namespace gnote {
 
 class RemoteControl;
@@ -37,6 +45,8 @@ public:
   static const char *GNOTE_SERVER_PATH;
   static const char *GNOTE_INTERFACE_NAME;
   static const char *GNOTE_SERVER_NAME;
+  static const char *GNOTE_SEARCH_PROVIDER_PATH;
+  static const char *GNOTE_SEARCH_PROVIDER_INTERFACE_NAME;
 
   typedef sigc::slot<void, bool, bool> slot_name_acquire_finish;
   typedef sigc::slot<void> slot_connected;
@@ -55,9 +65,11 @@ private:
 
   static NoteManager * s_manager;
   static RemoteControl * s_remote_control;
+  static org::gnome::Gnote::SearchProvider * s_search_provider;
   static bool s_bus_acquired;
   static Glib::RefPtr<Gio::DBus::Connection> s_connection;
   static Glib::RefPtr<Gio::DBus::InterfaceInfo> s_gnote_interface;
+  static Glib::RefPtr<Gio::DBus::InterfaceInfo> s_search_provider_interface;
   static Glib::RefPtr<RemoteControlClient> s_remote_control_proxy;
   static slot_name_acquire_finish s_on_name_acquire_finish;
 };


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]