Dont add null mimetypes. Fixes bgo# 337431. The patch hasnt been officially accepted...
[beagle.git] / libbeagle / beagle / test-client.c
blobb3a89e914fe669458d365df76bbf7b3ca899459e
1 #include <beagle/beagle.h>
3 #if 0
4 static void
5 test_daemon_information (BeagleClient *client)
7 BeagleDaemonInformationRequest *request;
8 BeagleResponse *response;
10 request = beagle_daemon_information_request_new ();
11 response = beagle_client_send_request (client, BEAGLE_REQUEST (request), NULL);
13 g_object_unref (request);
14 g_object_unref (response);
16 g_print ("Beagle version: %s\n", beagle_daemon_information_response_get_version (BEAGLE_DAEMON_INFORMATION_RESPONSE (response)));
18 g_print ("%s\n", beagle_daemon_information_response_get_human_readable_status (BEAGLE_DAEMON_INFORMATION_RESPONSE (response)));
22 static void
23 test_shutdown (BeagleClient *client)
25 BeagleShutdownRequest *request;
26 BeagleResponse *response;
28 request = beagle_shutdown_request_new ();
29 response = beagle_client_send_request (client, BEAGLE_REQUEST (request), NULL);
32 #endif
34 static void
35 hits_added_cb (BeagleQuery *query, BeagleHitsAddedResponse *response, BeagleClient *client)
37 GSList *hits;
38 BeagleSnippetRequest *snippet;
40 hits = beagle_hits_added_response_get_hits (response);
41 snippet = beagle_snippet_request_new ();
43 g_print ("%d\n", g_slist_length (beagle_query_get_stemmed_text (query)));
45 beagle_snippet_request_set_query (snippet, query);
47 while (hits != NULL) {
48 BeagleHit *hit = hits->data;
49 BeagleResponse *resp;
50 GError *err = NULL;
52 g_print ("added %s\n", beagle_hit_get_uri (hit));
54 beagle_snippet_request_set_hit (snippet, hit);
56 resp = beagle_client_send_request (client, BEAGLE_REQUEST (snippet), &err);
57 if (err) {
58 g_print ("got error: %s\n",
59 err->message);
60 g_error_free (err);
63 if (resp) {
64 g_print ("getting a snippet: %s\n",
65 beagle_snippet_response_get_snippet (BEAGLE_SNIPPET_RESPONSE (resp)));
66 g_object_unref (resp);
69 hits = hits->next;
72 g_object_unref (snippet);
76 static void
77 hits_subtracted_cb (BeagleQuery *query, BeagleHitsSubtractedResponse *response)
79 GSList *uris;
81 uris = beagle_hits_subtracted_response_get_uris (response);
82 while (uris != NULL) {
83 char *uri = uris->data;
85 g_print ("removed: %s\n", uri);
87 uris = uris->next;
91 static void
92 finished_cb (BeagleQuery *query, BeagleFinishedResponse *response, GMainLoop *loop)
94 g_print ("finished!\n");
95 g_main_loop_quit (loop);
98 static void
99 test_live_query (BeagleClient *client)
101 BeagleQuery *query;
102 GMainLoop *loop;
104 loop = g_main_loop_new (NULL, FALSE);
106 query = beagle_query_new ();
107 g_signal_connect (query, "hits-added",
108 G_CALLBACK (hits_added_cb), client);
109 g_signal_connect (query, "hits-subtracted",
110 G_CALLBACK (hits_subtracted_cb), NULL);
111 g_signal_connect (query, "finished",
112 G_CALLBACK (finished_cb), loop);
114 beagle_query_add_text (query, "gnome");
116 beagle_client_send_request_async (client, BEAGLE_REQUEST (query), NULL);
118 g_main_loop_run (loop);
119 g_print ("back from main loop!\n");
120 g_object_unref (query);
123 #if 0
124 static void
125 test_indexer (BeagleClient *client)
127 BeagleIndexable *indexable;
128 BeagleProperty *prop;
129 BeagleIndexingServiceRequest *request;
131 indexable = beagle_indexable_new ("uid:richard");
133 prop = beagle_property_new ("sliff", "sloff");
134 beagle_indexable_add_property (indexable, prop);
136 request = beagle_indexing_service_request_new ();
137 beagle_indexing_service_request_add (request, indexable);
138 beagle_client_send_request (client, BEAGLE_REQUEST (request), NULL);
140 #endif
144 main ()
146 BeagleClient *client;
148 g_type_init ();
150 client = beagle_client_new (NULL);
151 #if 0
152 g_print ("testing indexer\n");
153 test_indexer (client);
155 g_print ("testing daemon information\n");
156 test_daemon_information (client);
157 #endif
158 g_print ("testing live query\n");
159 test_live_query (client);
161 g_print ("good bye!\n");
162 g_object_unref (client);
164 /* test_shutdown (client);*/
166 return 0;