From 7b8f40e117072bba2c6a0e016c420e4ed14344c8 Mon Sep 17 00:00:00 2001 From: jeffser Date: Thu, 30 May 2024 09:33:06 -0600 Subject: [PATCH] Initial support for Gnome Search (doesn't work yet) --- data/com.jeffser.Alpaca.SearchProvider.ini.in | 6 ++ ...m.jeffser.Alpaca.SearchProvider.service.in | 3 + src/alpaca_search_provider.in | 90 +++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 data/com.jeffser.Alpaca.SearchProvider.ini.in create mode 100644 data/com.jeffser.Alpaca.SearchProvider.service.in create mode 100644 src/alpaca_search_provider.in diff --git a/data/com.jeffser.Alpaca.SearchProvider.ini.in b/data/com.jeffser.Alpaca.SearchProvider.ini.in new file mode 100644 index 00000000..842784d4 --- /dev/null +++ b/data/com.jeffser.Alpaca.SearchProvider.ini.in @@ -0,0 +1,6 @@ +[Shell Search Provider] +DesktopId=@appid@.desktop +BusName=@appid@.SearchProvider +ObjectPath=/com/jeffser/Alpaca/SearchProvider +Version=2 + diff --git a/data/com.jeffser.Alpaca.SearchProvider.service.in b/data/com.jeffser.Alpaca.SearchProvider.service.in new file mode 100644 index 00000000..5994b0aa --- /dev/null +++ b/data/com.jeffser.Alpaca.SearchProvider.service.in @@ -0,0 +1,3 @@ +[D-BUS Service] +Name=@appid@.SearchProvider +Exec=@libexecdir@/alpaca_search_provider \ No newline at end of file diff --git a/src/alpaca_search_provider.in b/src/alpaca_search_provider.in new file mode 100644 index 00000000..b29d9902 --- /dev/null +++ b/src/alpaca_search_provider.in @@ -0,0 +1,90 @@ +#!@PYTHON@ + +import sys +from gi.repository import Gio, GLib + +DBUS_NAME = "com.jeffser.Alpaca.SearchProvider" +DBUS_OBJECT_PATH = "/com/jeffser/Alpaca/SearchProvider" +DBUS_INTERFACE = "org.gnome.Shell.SearchProvider2" + +class SearchProvider: + def __init__(self): + print("ALPACA __init__") + self.connection = Gio.bus_get_sync(Gio.BusType.SESSION, None) + self.connection.register_object(DBUS_OBJECT_PATH, self.get_interface_info(), None, self.handle_method_call, None) + + def get_interface_info(self): + print("ALPACA get_interface_info") + xml = """ + + + + + + + + + + + + + + + + + + + + + + + """ + return Gio.DBusNodeInfo.new_for_xml(xml).interfaces[0] + + def handle_method_call(self, connection, sender, object_path, interface_name, method_name, parameters, invocation): + print("ALPACA handle_method_call") + if method_name == "GetInitialResultSet": + self.handle_get_initial_result_set(invocation, parameters) + elif method_name == "GetSubsearchResultSet": + self.handle_get_subsearch_result_set(invocation, parameters) + elif method_name == "GetResultMetas": + self.handle_get_result_metas(invocation, parameters) + elif method_name == "ActivateResult": + self.handle_activate_result(invocation, parameters) + + def handle_get_initial_result_set(self, invocation, parameters): + print("ALPACA handle_get_initial_result_set") + terms = parameters.unpack()[0] + print(f"Initial search terms: {terms}") + results = ["result1", "result2"] + invocation.return_value(GLib.Variant("(as)", [results])) + + def handle_get_subsearch_result_set(self, invocation, parameters): + print("ALPACA handle_get_subsearch_result_set") + previous_results, terms = parameters.unpack() + print(f"Subsearch terms: {terms}, previous results: {previous_results}") + results = ["result3", "result4"] + invocation.return_value(GLib.Variant("(as)", [results])) + + def handle_get_result_metas(self, invocation, parameters): + print("ALPACA handle_get_result_metas") + identifiers = parameters.unpack()[0] #LINE 66 + print(f"Result metas for identifiers: {identifiers}") + metas = [] + for identifier in identifiers: + meta = {"name": GLib.Variant("s", identifier)} + metas.append(GLib.Variant("a{sv}", meta)) + invocation.return_value(GLib.Variant("(a{sv})", [metas])) + + + def handle_activate_result(self, invocation, parameters): + print("ALPACA handle_activate_result") + identifier, terms, timestamp = parameters.unpack() + print(f"Activated result: {identifier}, terms: {terms}, timestamp: {timestamp}") + invocation.return_value(None) + +if __name__ == "__main__": + provider = SearchProvider() + loop = GLib.MainLoop() + loop.run() +