Merge branch 'master' of git://repo.or.cz/tele
[tele.git] / src / plugins / beagle.c
blobb8f43adc3b106e36879f7557f68091d51cb4eee0
1 /**
3 * beagle plugin
5 * beagle.c
7 * Copyright : (C) 2007 by Diogo Ferreira <diogo@underdev.org>
8 * (C) 2007 by João Oliveirinha <joliveirinha@floodbit.org>
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 3
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 **/
23 #include <beagle/beagle.h>
24 #include <teleport.h>
26 #define PLUGIN_NAME "beagleplugin"
28 static BeagleClient *client;
29 static const TeleportPlugin *myself;
30 static BeagleQuery *beagle_query;
32 static void
33 hits_finished (BeagleQuery *q, BeagleFinishedResponse *response, gpointer p)
35 g_object_unref(q);
38 static void
39 beagle_cancel_query(void)
41 if (beagle_query) {
42 g_object_unref(beagle_query);
43 g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "%s: Last Query Canceled\n", PLUGIN_NAME);
47 static void
48 hits_added (BeagleQuery *query, BeagleHitsAddedResponse *response)
50 GSList *hits, *l;
51 GSList *actionGroup = NULL;
52 TeleportAction *act;
54 hits = beagle_hits_added_response_get_hits (response);
56 g_print("------------------------\n");
57 for (l = hits; l; l = l->next)
59 BeagleHit *h = BEAGLE_HIT (l->data);
60 g_print("[%s] %s\n", beagle_hit_get_mime_type(h), beagle_hit_get_uri(h));
62 act = g_new (TeleportAction, 1);
63 act->text = g_strdup (beagle_hit_get_uri(h));
64 act->mime_type = g_strdup (beagle_hit_get_mime_type(h));
65 act->backend = myself;
66 act->data = NULL;
68 actionGroup = g_slist_append (actionGroup, act);
70 g_print("-------------------------\n");
72 if (actionGroup)
73 teleport_trigger_query_update (actionGroup);
76 static
77 GSList * beagleSearch (const TeleportPlugin *p, const gchar *q)
79 BeagleQuery *query = beagle_query_new ();
81 beagle_query_add_text(query, q);
83 g_signal_connect (query, "hits-added", G_CALLBACK(hits_added), client);
84 g_signal_connect (query, "finished", G_CALLBACK(hits_finished), NULL);
86 beagle_client_send_request_async (client, BEAGLE_REQUEST(query), NULL);
88 return NULL;
91 static
92 gboolean beagleDoAction (TeleportAction *act)
94 return TRUE;
97 static
98 gboolean beagleInitPlugin (const TeleportPlugin *p)
101 g_type_init ();
103 myself = p;
105 client = beagle_client_new (NULL);
107 if (!client)
109 g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Failed to load %s plugin", PLUGIN_NAME);
111 return FALSE;
114 return TRUE;
117 static
118 void beagleFiniPlugin (const TeleportPlugin *p)
120 g_object_unref (client);
123 TeleportPluginVTable beagleVTable = {
124 (gchar *)PLUGIN_NAME,
125 beagleInitPlugin,
126 beagleFiniPlugin,
127 beagleSearch,
128 beagleDoAction,
129 beagle_cancel_query
132 int teleport_get_abi ()
134 return TELEPORT_ABI;
137 TeleportPluginVTable* teleport_get_vtable ()
139 return &beagleVTable;