diff options
author | Siegfried-Angel Gevatter Pujals <siegfried@gevatter.com> | 2012-11-12 10:54:41 +0100 |
---|---|---|
committer | Siegfried-Angel Gevatter Pujals <siegfried@gevatter.com> | 2012-11-12 10:54:41 +0100 |
commit | aba2ed423fc611343bbdccf5d85a23c669ebc94d (patch) | |
tree | 1fb158fc245abcfef93311127c6d7c7579841b55 | |
parent | d719fb76f9e6b02cf425445216ca2d236d6615be (diff) | |
parent | c3ef7df033faf2b591339561dcb2216b5cace3d8 (diff) | |
download | zeitgeist-aba2ed423fc611343bbdccf5d85a23c669ebc94d.tar.gz |
Merge branch 'master' of ssh://git.freedesktop.org/git/zeitgeist/zeitgeist
Conflicts:
libzeitgeist/enumerations.vala
25 files changed, 386 insertions, 58 deletions
diff --git a/configure.ac b/configure.ac index fa6e4376..f69fa5c1 100644 --- a/configure.ac +++ b/configure.ac @@ -59,6 +59,8 @@ AC_CONFIG_FILES([ test/c/Makefile test/data/Makefile examples/Makefile + examples/c/Makefile + examples/vala/Makefile doc/Makefile doc/libzeitgeist/Makefile po/Makefile.in diff --git a/examples/Makefile.am b/examples/Makefile.am index 5a6d7138..28dd4add 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -1,45 +1,6 @@ -NULL = +NULL = -AM_CPPFLAGS = \ - $(ZEITGEIST_CFLAGS) \ - -include $(CONFIG_HEADER) \ - -I $(top_srcdir)/libzeitgeist/ \ - -w \ +SUBDIRS = \ + vala \ + c \ $(NULL) - -AM_VALAFLAGS = \ - --target-glib=2.26 \ - --pkg gio-2.0 \ - $(top_srcdir)/libzeitgeist/zeitgeist-2.0.vapi \ - $(top_srcdir)/config.vapi \ - $(NULL) - -zeitgeist_libs = \ - $(top_builddir)/libzeitgeist/libzeitgeist-2.0.la \ - $(ZEITGEIST_LIBS) - -noinst_PROGRAMS = \ - data-source-stuff \ - get-events-with-id \ - monitor-events \ - most-recent-events \ - insert-events \ - $(NULL) - -data_source_stuff_SOURCES = data-source-stuff.vala -data_source_stuff_LDADD = $(zeitgeist_libs) - -get_events_with_id_SOURCES = get-events-with-id.vala -get_events_with_id_LDADD = $(zeitgeist_libs) - -monitor_events_SOURCES = monitor-events.vala -monitor_events_LDADD = $(zeitgeist_libs) - -most_recent_events_SOURCES = most-recent-events.vala -most_recent_events_LDADD = $(zeitgeist_libs) - -insert_events_SOURCES = insert-events.vala -insert_events_LDADD = $(zeitgeist_libs) - -distclean-local: - rm -f *.c *.o *.~[0-9]~ diff --git a/examples/c/Makefile.am b/examples/c/Makefile.am new file mode 100644 index 00000000..0d165cb6 --- /dev/null +++ b/examples/c/Makefile.am @@ -0,0 +1,35 @@ +include $(top_srcdir)/libzeitgeist/Makefile.decl + +INCLUDES = \ + -I$(top_srcdir)/libzeitgeist -I$(top_builddir)/libzeitgeist \ + $(GIO_UNIX_CFLAGS) \ + $(ZEITGEIST_CFLAGS) + +AM_CFLAGS = \ + -Wall \ + -g \ + -DZEITGEIST_COMPILATION \ + -DTEST_DIR=\"$(top_srcdir)/tests\" + +zeitgeist_libs = $(top_builddir)/libzeitgeist/libzeitgeist-2.0.la $(ZEITGEIST_LIBS) + +EXTRA_DIST += \ + test.desktop + +helper_sources = \ + $(top_srcdir)/libzeitgeist/zeitgeist.h \ + test.desktop + +noinst_PROGRAMS = \ + find-events \ + monitor-events \ + search-events + +find_events_SOURCES = find-events.c +find_events_LDADD = $(zeitgeist_libs) + +monitor_events_SOURCES = monitor-events.c +monitor_events_LDADD = $(zeitgeist_libs) + +search_events_SOURCES = search-events.c +search_events_LDADD = $(zeitgeist_libs) diff --git a/examples/c/find-events.c b/examples/c/find-events.c new file mode 100644 index 00000000..7c80c2e8 --- /dev/null +++ b/examples/c/find-events.c @@ -0,0 +1,91 @@ +/* + * Copyright (C) 2010 Canonical Ltd + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * 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/>. + * + * Authored by Mikkel Kamstrup Erlandsen <mikkel.kamstrup@canonical.com> + * + */ + +#include <glib.h> +#include <glib/gprintf.h> +#include <glib-object.h> +#include <zeitgeist.h> + +static void +on_events_received (ZeitgeistLog *log, + GAsyncResult *res, + gpointer user_data) +{ + ZeitgeistResultSet *events; + ZeitgeistEvent *event; + ZeitgeistSubject *subject; + GError *error; + GMainLoop *mainloop = (GMainLoop*) user_data; + gint i; + + error = NULL; + events = zeitgeist_log_find_events_finish (log, res, &error); + + if (error) + { + g_warning ("Error reading results: %s", error->message); + g_error_free (error); + return; + } + + g_message ("Got %i events:", zeitgeist_result_set_size (events)); + + while (zeitgeist_result_set_has_next (events)) + { + event = zeitgeist_result_set_next_value (events); + for (i = 0; i < zeitgeist_event_num_subjects (event); i++) + { + subject = zeitgeist_event_get_subject (event, i); + g_printf ("%s\n", zeitgeist_subject_get_uri (subject)); + } + } + + g_object_unref (events); + + g_main_loop_quit (mainloop); +} + +gint +main (gint argc, + gchar *argv[]) +{ + GMainLoop *mainloop; + ZeitgeistLog *log; + GPtrArray *templates; + + mainloop = g_main_loop_new (NULL, FALSE); + log = g_object_new (ZEITGEIST_TYPE_LOG, NULL); + + templates = g_ptr_array_new (); + g_ptr_array_add (templates, zeitgeist_event_new ()); + + zeitgeist_log_find_events (log, + zeitgeist_time_range_new_to_now (), + templates, + ZEITGEIST_STORAGE_STATE_ANY, + 10, + ZEITGEIST_RESULT_TYPE_MOST_RECENT_EVENTS, + NULL, + (GAsyncReadyCallback)on_events_received, + mainloop); + + g_main_loop_run (mainloop); + + return 0; +} diff --git a/examples/c/monitor-events.c b/examples/c/monitor-events.c new file mode 100644 index 00000000..e6d8c114 --- /dev/null +++ b/examples/c/monitor-events.c @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2010 Canonical Ltd + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * 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/>. + * + * Authored by Mikkel Kamstrup Erlandsen <mikkel.kamstrup@canonical.com> + * + */ + +#include <glib.h> +#include <glib/gprintf.h> +#include <glib-object.h> +#include <zeitgeist.h> + +static void +on_events_inserted (ZeitgeistMonitor *mon, + ZeitgeistTimeRange *time_range, + ZeitgeistResultSet *events, + gpointer user_data) +{ + ZeitgeistEvent *event; + ZeitgeistSubject *subject; + gint j; + + g_message ("%i events inserted", zeitgeist_result_set_size (events)); + + while (zeitgeist_result_set_has_next (events)) + { + event = zeitgeist_result_set_next_value (events); + for (j = 0; j < zeitgeist_event_num_subjects (event); j++) + { + subject = zeitgeist_event_get_subject (event, j); + g_message (" * %s", zeitgeist_subject_get_uri (subject)); + } + } +} + +static void +on_events_deleted (ZeitgeistMonitor *mon, + ZeitgeistTimeRange *time_range, + GArray *event_ids, + gpointer user_data) +{ + g_message ("%i events deleted", event_ids->len); +} + +gint +main (gint argc, + gchar *argv[]) +{ + GMainLoop *mainloop; + ZeitgeistLog *log; + ZeitgeistMonitor *monitor; + GPtrArray *templates; + GError** error; + + error = NULL; + mainloop = g_main_loop_new (NULL, FALSE); + log = g_object_new (ZEITGEIST_TYPE_LOG, NULL); + + /* Templates matching anything */ + templates = g_ptr_array_new (); + g_ptr_array_add (templates, zeitgeist_event_new ()); + + monitor = zeitgeist_monitor_new (zeitgeist_time_range_new_anytime (), + templates); + + g_signal_connect (monitor, "events-inserted", + G_CALLBACK (on_events_inserted), NULL); + g_signal_connect (monitor, "events-deleted", + G_CALLBACK (on_events_deleted), NULL); + + zeitgeist_log_install_monitor (log, monitor, error); + + g_main_loop_run (mainloop); + + return 0; +} diff --git a/examples/c/search-events.c b/examples/c/search-events.c new file mode 100644 index 00000000..c022b437 --- /dev/null +++ b/examples/c/search-events.c @@ -0,0 +1,107 @@ +/* + * Copyright (C) 2010 Canonical Ltd + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * 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/>. + * + * Authored by Mikkel Kamstrup Erlandsen <mikkel.kamstrup@canonical.com> + * + */ + +#include <glib.h> +#include <glib/gprintf.h> +#include <glib-object.h> +#include <zeitgeist.h> + +static void +on_events_received (ZeitgeistIndex *index, + GAsyncResult *res, + gpointer user_data) +{ + ZeitgeistResultSet *events; + ZeitgeistEvent *event; + ZeitgeistSubject *subject; + GError *error; + GMainLoop *mainloop = (GMainLoop*) user_data; + gint i; + + error = NULL; + events = zeitgeist_index_search_finish (index, res, &error); + + if (error) + { + g_warning ("Error reading results: %s", error->message); + g_error_free (error); + return; + } + + g_message ("Got %u/%u events:", + zeitgeist_result_set_size (events), + zeitgeist_result_set_estimated_matches (events)); + + while (zeitgeist_result_set_has_next (events)) + { + event = zeitgeist_result_set_next_value (events); + for (i = 0; i < zeitgeist_event_num_subjects (event); i++) + { + subject = zeitgeist_event_get_subject (event, i); + g_printf ("%s\n", zeitgeist_subject_get_uri (subject)); + } + } + + g_object_unref (events); + + g_main_loop_quit (mainloop); +} + +gint +main (gint argc, + gchar *argv[]) +{ + GMainLoop *mainloop; + ZeitgeistIndex *index; + gchar **queryv; + gchar *query; + + + if (argc <= 1) + { + g_printf ("Please specify a string to search for.\n"); + return 1; + } + + /* Construct query string by concatenating the command line args + * except the first one */ + queryv = argv; + queryv++; + query = g_strjoinv (" ", queryv); + + mainloop = g_main_loop_new (NULL, FALSE); + index = zeitgeist_index_new (); + + g_printf ("Searching for '%s':\n", query); + + zeitgeist_index_search (index, + query, + zeitgeist_time_range_new_anytime (), + g_ptr_array_new (), + 0, + 10, + ZEITGEIST_RESULT_TYPE_RELEVANCY, + NULL, + (GAsyncReadyCallback)on_events_received, + mainloop); + + g_main_loop_run (mainloop); + + return 0; +} diff --git a/examples/vala/Makefile.am b/examples/vala/Makefile.am new file mode 100644 index 00000000..5a6d7138 --- /dev/null +++ b/examples/vala/Makefile.am @@ -0,0 +1,45 @@ +NULL = + +AM_CPPFLAGS = \ + $(ZEITGEIST_CFLAGS) \ + -include $(CONFIG_HEADER) \ + -I $(top_srcdir)/libzeitgeist/ \ + -w \ + $(NULL) + +AM_VALAFLAGS = \ + --target-glib=2.26 \ + --pkg gio-2.0 \ + $(top_srcdir)/libzeitgeist/zeitgeist-2.0.vapi \ + $(top_srcdir)/config.vapi \ + $(NULL) + +zeitgeist_libs = \ + $(top_builddir)/libzeitgeist/libzeitgeist-2.0.la \ + $(ZEITGEIST_LIBS) + +noinst_PROGRAMS = \ + data-source-stuff \ + get-events-with-id \ + monitor-events \ + most-recent-events \ + insert-events \ + $(NULL) + +data_source_stuff_SOURCES = data-source-stuff.vala +data_source_stuff_LDADD = $(zeitgeist_libs) + +get_events_with_id_SOURCES = get-events-with-id.vala +get_events_with_id_LDADD = $(zeitgeist_libs) + +monitor_events_SOURCES = monitor-events.vala +monitor_events_LDADD = $(zeitgeist_libs) + +most_recent_events_SOURCES = most-recent-events.vala +most_recent_events_LDADD = $(zeitgeist_libs) + +insert_events_SOURCES = insert-events.vala +insert_events_LDADD = $(zeitgeist_libs) + +distclean-local: + rm -f *.c *.o *.~[0-9]~ diff --git a/examples/data-source-stuff.vala b/examples/vala/data-source-stuff.vala index 6e744287..6e744287 100644 --- a/examples/data-source-stuff.vala +++ b/examples/vala/data-source-stuff.vala diff --git a/examples/get-events-with-id.vala b/examples/vala/get-events-with-id.vala index 32682372..32682372 100644 --- a/examples/get-events-with-id.vala +++ b/examples/vala/get-events-with-id.vala diff --git a/examples/insert-events.vala b/examples/vala/insert-events.vala index aad9393d..aad9393d 100644 --- a/examples/insert-events.vala +++ b/examples/vala/insert-events.vala diff --git a/examples/monitor-events.vala b/examples/vala/monitor-events.vala index ed6feab4..ed6feab4 100644 --- a/examples/monitor-events.vala +++ b/examples/vala/monitor-events.vala diff --git a/examples/most-recent-events.vala b/examples/vala/most-recent-events.vala index 316e9f43..316e9f43 100644 --- a/examples/most-recent-events.vala +++ b/examples/vala/most-recent-events.vala diff --git a/libzeitgeist/enumerations.vala b/libzeitgeist/enumerations.vala index 044de3ab..54c20178 100644 --- a/libzeitgeist/enumerations.vala +++ b/libzeitgeist/enumerations.vala @@ -167,7 +167,7 @@ public enum ResultType // Events are sorted by query // relevancy - /* + /* * Returns true if the results for the given result_type will be sorted * ascendantly by date, false if they'll be sorted descendingly. **/ diff --git a/libzeitgeist/log.vala b/libzeitgeist/log.vala index 693b941c..781fc582 100644 --- a/libzeitgeist/log.vala +++ b/libzeitgeist/log.vala @@ -212,7 +212,7 @@ public class Log : QueuedProxyWrapper yield proxy.quit (cancellable); } - public async void install_monitor (Monitor monitor) throws Error + public void install_monitor (Monitor monitor) throws Error { // FIXME //monitor.destroy.connect (() => {}); diff --git a/src/engine.vala b/src/engine.vala index 094c676b..8d7e1517 100644 --- a/src/engine.vala +++ b/src/engine.vala @@ -260,7 +260,7 @@ public class Engine : DbReader } private void bind_cached_reference (Sqlite.Statement stmt, - int position, TableLookup table, string? value_) + int position, TableLookup table, string? value_) throws EngineError { if (value_ != null) stmt.bind_int64 (position, table.id_for_string (value_)); diff --git a/src/table-lookup.vala b/src/table-lookup.vala index 039e3414..b582b143 100644 --- a/src/table-lookup.vala +++ b/src/table-lookup.vala @@ -105,7 +105,7 @@ namespace Zeitgeist.SQLite return id; } - public unowned string get_value (int id) throws EngineError + public unowned string? get_value (int id) throws EngineError { // When we fetch an event, it either was already in the database // at the time Zeitgeist started or it was inserted later -using diff --git a/test/c/test-datasource.c b/test/c/test-datasource.c index 485c228d..14bac27e 100644 --- a/test/c/test-datasource.c +++ b/test/c/test-datasource.c @@ -108,6 +108,7 @@ test_to_from_variant (Fixture *fix, gconstpointer data) gint64 now; GError** error; + error = NULL; /* Build the data source to serialize */ orig = zeitgeist_data_source_new_full ("my-id", "my-name", "my description", NULL); @@ -142,7 +143,6 @@ int main (int argc, char *argv[]) { - g_type_init (); g_test_init (&argc, &argv, NULL); g_test_add ("/Zeitgeist/DataSource/CreateEmpty", Fixture, NULL, diff --git a/test/c/test-event.c b/test/c/test-event.c index d2396799..3a09600d 100644 --- a/test/c/test-event.c +++ b/test/c/test-event.c @@ -144,8 +144,9 @@ test_from_variant (Fixture *fix, gconstpointer data) ZeitgeistEvent *ev; ZeitgeistSubject *su; GByteArray *payload; - GError *error; + GError **error; + error = NULL; g_variant_builder_init (&b, G_VARIANT_TYPE ("(" ZEITGEIST_EVENT_SIGNATURE ")")); /* Build event data */ @@ -424,7 +425,6 @@ int main (int argc, char *argv[]) { - g_type_init (); g_test_init (&argc, &argv, NULL); g_test_add ("/Zeitgeist/Event/CreateEmpty", Fixture, NULL, diff --git a/test/c/test-log.c b/test/c/test-log.c index 98e12594..b392ea90 100644 --- a/test/c/test-log.c +++ b/test/c/test-log.c @@ -202,7 +202,6 @@ int main (int argc, char *argv[]) { - g_type_init (); g_test_init (&argc, &argv, NULL); g_test_add ("/Zeitgeist/Log/InsertGetDelete", Fixture, NULL, diff --git a/test/c/test-mimetypes.c b/test/c/test-mimetypes.c index 370c84cd..799656f8 100644 --- a/test/c/test-mimetypes.c +++ b/test/c/test-mimetypes.c @@ -79,7 +79,6 @@ int main (int argc, char *argv[]) { - g_type_init (); g_test_init (&argc, &argv, NULL); g_test_add ("/Zeitgeist/Mime/TextPlain", Fixture, NULL, diff --git a/test/c/test-monitor.c b/test/c/test-monitor.c index 6a28fc14..5ee76402 100644 --- a/test/c/test-monitor.c +++ b/test/c/test-monitor.c @@ -67,7 +67,6 @@ int main (int argc, char *argv[]) { - g_type_init (); g_test_init (&argc, &argv, NULL); g_test_add ("/Zeitgeist/Monitor/Create", Fixture, NULL, diff --git a/test/c/test-symbols.c b/test/c/test-symbols.c index 3a63ebe3..636db6fd 100644 --- a/test/c/test-symbols.c +++ b/test/c/test-symbols.c @@ -181,7 +181,6 @@ int main (int argc, char *argv[]) { - g_type_init (); g_test_init (&argc, &argv, NULL); g_test_add ("/Zeitgeist/Symbols/NullNull", Fixture, NULL, diff --git a/test/c/test-timerange.c b/test/c/test-timerange.c index 4fad4183..e52c0b00 100644 --- a/test/c/test-timerange.c +++ b/test/c/test-timerange.c @@ -104,6 +104,7 @@ test_from_variant (Fixture *fix, gconstpointer data) gint64 i,j; GError **error; + error = NULL; v = g_variant_new ("(xx)", G_GINT64_CONSTANT(0), G_MAXINT64); g_variant_get (v, "(xx)", &i, &j); @@ -137,7 +138,6 @@ int main (int argc, char *argv[]) { - g_type_init (); g_test_init (&argc, &argv, NULL); g_test_add ("/Zeitgeist/TimeRange/Create", Fixture, NULL, diff --git a/test/c/test-timestamp.c b/test/c/test-timestamp.c index 83aaee3e..7f4307e3 100644 --- a/test/c/test-timestamp.c +++ b/test/c/test-timestamp.c @@ -159,7 +159,6 @@ int main (int argc, char *argv[]) { - g_type_init (); g_test_init (&argc, &argv, NULL); g_test_add ("/Zeitgeist/Timestamp/FromISO8601", Fixture, NULL, diff --git a/test/direct/Makefile.am b/test/direct/Makefile.am index 63e72e77..4026627f 100644 --- a/test/direct/Makefile.am +++ b/test/direct/Makefile.am @@ -32,8 +32,12 @@ SRC_FILES = \ $(top_srcdir)/src/extension-store.vala \ $(top_srcdir)/src/notify.vala \ $(top_srcdir)/src/table-lookup.vala \ - $(top_srcdir)/libzeitgeist/datamodel.vala \ - $(top_srcdir)/libzeitgeist/data-source.vala \ + $(top_srcdir)/libzeitgeist/data-source.vala \ + $(top_srcdir)/libzeitgeist/enumerations.vala \ + $(top_srcdir)/libzeitgeist/event.vala \ + $(top_srcdir)/libzeitgeist/subject.vala \ + $(top_srcdir)/libzeitgeist/timerange.vala \ + $(top_srcdir)/libzeitgeist/timestamp.vala \ $(top_srcdir)/src/where-clause.vala \ $(top_srcdir)/libzeitgeist/remote.vala \ $(top_srcdir)/libzeitgeist/timestamp.vala \ |