svnno****@sourc*****
svnno****@sourc*****
Fri Mar 23 15:06:50 JST 2007
Revision: 2980 http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi?root=kazehakase&view=rev&rev=2980 Author: kous Date: 2007-03-23 15:06:50 +0900 (Fri, 23 Mar 2007) Log Message: ----------- * src/kz-search.[ch]: - class -> interface. - used KzModule. * module/search/kz-hyper-estraier-search.c: followed the above change. * module/search/kz-search-hyper-estraier.c: renamed to the above file. * module/search/kz-search-hyper-estraier.h: removed. * module/search/Makefile.am: removed lib prefix. * src/kz-app.c: followed the above change. Modified Paths: -------------- kazehakase/trunk/ChangeLog kazehakase/trunk/module/search/Makefile.am kazehakase/trunk/src/kz-app.c kazehakase/trunk/src/kz-search.c kazehakase/trunk/src/kz-search.h Added Paths: ----------- kazehakase/trunk/module/search/kz-hyper-estraier-search.c Removed Paths: ------------- kazehakase/trunk/module/search/kz-search-hyper-estraier.c kazehakase/trunk/module/search/kz-search-hyper-estraier.h Modified: kazehakase/trunk/ChangeLog =================================================================== --- kazehakase/trunk/ChangeLog 2007-03-23 06:06:19 UTC (rev 2979) +++ kazehakase/trunk/ChangeLog 2007-03-23 06:06:50 UTC (rev 2980) @@ -1,3 +1,18 @@ +2007-03-23 Kouhei Sutou <kou****@cozmi*****> + + * src/kz-search.[ch]: + - class -> interface. + - used KzModule. + + * module/search/kz-hyper-estraier-search.c: followed the above + change. + * module/search/kz-search-hyper-estraier.c: renamed to the above + file. + * module/search/kz-search-hyper-estraier.h: removed. + * module/search/Makefile.am: removed lib prefix. + + * src/kz-app.c: followed the above change. + 2007-03-23 Hiroyuki Ikezoe <poinc****@ikezo*****> * src/prefs_ui/prefs_font.c, module/embed/gecko/kz-gecko-single.cpp: Modified: kazehakase/trunk/module/search/Makefile.am =================================================================== --- kazehakase/trunk/module/search/Makefile.am 2007-03-23 06:06:19 UTC (rev 2979) +++ kazehakase/trunk/module/search/Makefile.am 2007-03-23 06:06:50 UTC (rev 2980) @@ -29,8 +29,11 @@ LIBADD = $(GLIB_LIBS) LDFLAGS = \ - -version-info $(LT_VERSION_INFO) \ - -export-dynamic $(no_undefined) $(LIBTOOL_EXPORT_OPTIONS) + -rpath $(searchdir) \ + -avoid-version \ + -module \ + -export-dynamic $(no_undefined) \ + $(LIBTOOL_EXPORT_OPTIONS) search_LTLIBRARIES = @@ -39,22 +42,22 @@ kz-search-common.h if WITH_EST -search_LTLIBRARIES += libhyperestraier.la +search_LTLIBRARIES += hyper-estraier.la -libhyperestraier_la_SOURCES = \ +hyper_estraier_la_SOURCES = \ $(search_common_sources) \ - kz-search-hyper-estraier.h kz-search-hyper-estraier.c -libhyperestraier_la_LIBADD = $(EST_LIBS) -libhyperestraier_la_CPPFLAGS = $(EST_CFLAGS) + kz-hyper-estraier-search.c +hyper_estraier_la_LIBADD = $(EST_LIBS) +hyper_estraier_la_CPPFLAGS = $(EST_CFLAGS) endif if WITH_ANTHY_TRAINER -search_LTLIBRARIES += libanthy-trainer.la +search_LTLIBRARIES += anthy-trainer.la -libanthy_trainer_la_SOURCES = \ +anthy_trainer_la_SOURCES = \ kz-anthy-trainer.h kz-anthy-trainer.c -libanthy_trainer_la_LIBADD = $(ANTHY_LIBS) $(MECAB_LIBS) -libanthy_trainer_la_CPPFLAGS = $(ANTHY_CFLAGS) $(MECAB_CFLAGS) +anthy_trainer_la_LIBADD = $(ANTHY_LIBS) $(MECAB_LIBS) +anthy_trainer_la_CPPFLAGS = $(ANTHY_CFLAGS) $(MECAB_CFLAGS) endif Copied: kazehakase/trunk/module/search/kz-hyper-estraier-search.c (from rev 2973, kazehakase/trunk/module/search/kz-search-hyper-estraier.c) =================================================================== --- kazehakase/trunk/module/search/kz-search-hyper-estraier.c 2007-03-23 03:04:48 UTC (rev 2973) +++ kazehakase/trunk/module/search/kz-hyper-estraier-search.c 2007-03-23 06:06:50 UTC (rev 2980) @@ -0,0 +1,578 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ + +/* + * Copyright (C) 2007 Kouhei Sutou <kou****@cozmi*****> + * copyright (c) 2004 hiroyuki ikezoe + * + * 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 2, 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, write to the free software + * foundation, inc., 59 temple place - suite 330, boston, ma 02111-1307, usa. + */ + +#include <ctype.h> +#include <glib/gi18n.h> +#include <glib.h> +#include <glib/gstdio.h> +#include <estraier.h> +#include <estmtdb.h> + +#include "kazehakase.h" +#include "utils/utils.h" +#include "glib-utils.h" +#include "kz-search.h" +#include "kz-search-common.h" +#include "kz-module-impl.h" +#include "egg-pixbuf-thumbnail.h" + +#define HISTORY_INDEX "history_index.hest" + +#define KZ_TYPE_HYPER_ESTRAIER_SEARCH (kz_type_hyper_estraier_search) +#define KZ_HYPER_ESTRAIER_SEARCH(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), KZ_TYPE_HYPER_ESTRAIER_SEARCH, KzHyperEstraierSearch)) +#define KZ_IS_HYPER_ESTRAIER_SEARCH(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), KZ_TYPE_HYPER_ESTRAIER_SEARCH)) +#define KZ_HYPER_ESTRAIER_SEARCH_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), KZ_TYPE_HYPER_ESTRAISER_SEARCH, KzHyperEstraierSearchClass)) +#define KZ_IS_HYPER_ESTRAISER_SEARCH_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), KZ_TYPE_HYPER_ESTRAISER_SEARCH)) +#define KZ_HYPER_ESTRAIER_SEARCH_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), KZ_TYPE_HYPER_ESTRAISER_SEARCH, KzHyperEstraierSearchClass)) + +typedef struct _KzHyperEstraierSearch KzHyperEstraierSearch; + +struct _KzHyperEstraierSearch +{ + GObject parent; + + ESTMTDB *db; + gchar *dbname; + gchar *cache_path; + size_t cache_path_len; +}; + +typedef struct _KzHyperEstraierSearchClass KzHyperEstraierSearchClass; +struct _KzHyperEstraierSearchClass +{ + GObjectClass parent_class; +}; + + +/* KzHyperEstraierSearch Class */ +static void kz_hyper_estraier_search_class_init (KzHyperEstraierSearchClass *klass); +static void kz_hyper_estraier_search_init (KzHyperEstraierSearch *search); + +/* GObject Class */ +static void dispose (GObject *object); + +/* KzSearchIFace */ +static void kz_hyper_estraier_search_iface_init (KzSearchIFace *iface); + + +static gchar *get_search_result_html (KzSearch *search, const gchar *text); +static KzBookmark *get_search_result_bookmark (KzSearch *search, const gchar *text); +static gboolean register_document (KzSearch *search, + const gchar *uri, + const gchar *title, + const gchar *contents, + GTime mtime); +static gboolean unregister_document (KzSearch *search, const gchar *uri); +static GPid optimize_index (KzSearch *search); +static void make_index (KzSearch *search); +static gboolean exist_index_dir (KzSearch *search); + + +static GObjectClass *parent_class; +static GType kz_type_hyper_estraier_search = 0; + +static void +kz_hyper_estraier_search_register_type (GTypeModule *module) +{ + static const GTypeInfo kz_hyper_estraier_search_info = + { + sizeof (KzHyperEstraierSearchClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc) kz_hyper_estraier_search_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (KzHyperEstraierSearch), + 0, /* n_preallocs */ + (GInstanceInitFunc) kz_hyper_estraier_search_init, + }; + + const GInterfaceInfo kz_search_info = + { + (GInterfaceInitFunc) kz_hyper_estraier_search_iface_init, + NULL, + NULL + }; + + kz_type_hyper_estraier_search = + g_type_module_register_type (module, + G_TYPE_OBJECT, + "KzHyperEstraierSearch", + &kz_hyper_estraier_search_info, 0); + + g_type_module_add_interface(module, + KZ_TYPE_HYPER_ESTRAIER_SEARCH, + KZ_TYPE_SEARCH, + &kz_search_info); +} + +G_MODULE_EXPORT void +KZ_MODULE_IMPL_INIT (GTypeModule *module) +{ + kz_hyper_estraier_search_register_type(module); +} + +G_MODULE_EXPORT void +KZ_MODULE_IMPL_EXIT (void) +{ +} + +G_MODULE_EXPORT GObject * +KZ_MODULE_IMPL_INSTANTIATE (const gchar *first_property, + va_list var_args) +{ + return g_object_new_valist(KZ_TYPE_HYPER_ESTRAIER_SEARCH, + first_property, var_args); +} + + +static void +kz_hyper_estraier_search_class_init (KzHyperEstraierSearchClass *klass) +{ + GObjectClass *object_class; + + parent_class = g_type_class_peek_parent (klass); + object_class = (GObjectClass *) klass; + + object_class->dispose = dispose; +} + +static void +kz_hyper_estraier_search_iface_init (KzSearchIFace *iface) +{ + iface->get_search_result_html = get_search_result_html; + iface->get_search_result_bookmark = get_search_result_bookmark; + iface->register_document = register_document; + iface->unregister_document = unregister_document; + iface->optimize_index = optimize_index; + iface->make_index = make_index; + iface->exist_index_dir = exist_index_dir; +} + +static void +kz_hyper_estraier_search_init (KzHyperEstraierSearch *search) +{ + search->db = NULL; + search->cache_path = g_build_filename(g_get_home_dir(), HISTORY_DIR, + NULL); + search->dbname = g_build_filename(g_get_home_dir(), + "."PACKAGE, HISTORY_INDEX, NULL); + + search->cache_path_len = strlen(search->cache_path); +} + +static void +dispose (GObject *object) +{ + KzHyperEstraierSearch *search; + + search = KZ_HYPER_ESTRAIER_SEARCH(object); + if (search->db) + { + int ecode, ret; + ret = est_mtdb_close(search->db, &ecode); + if (!ret) + g_warning("db close error: %s", est_err_msg(ecode)); + } + if (search->dbname) + g_free(search->dbname); + if (search->cache_path) + g_free(search->cache_path); + + search->db = NULL; + search->dbname = NULL; + search->cache_path = NULL; + + if (G_OBJECT_CLASS(parent_class)->dispose) + G_OBJECT_CLASS(parent_class)->dispose(object); +} + + +static gchar * +create_search_result_html (KzSearch *search, const gchar *text) +{ + ESTMTDB *db; + ESTCOND *cond; + CBLIST *highlights; + int ecode, *results, n_results, i, ret; + gchar *except_word, *tmp; + gchar **texts; + GString *html, *phrase; + gint num_summary = 128, max_results = 20, half_of_summary; + KzHyperEstraierSearch *he_search; + + he_search = KZ_HYPER_ESTRAIER_SEARCH(search); + db = est_mtdb_open(he_search->dbname, ESTDBREADER, &ecode); + if (!db) + { + g_warning("db open error: %s", est_err_msg(ecode)); + return NULL; + } + + cond = est_cond_new(); + texts = g_strsplit(text, " ", -1); + tmp = g_strjoinv(" " ESTOPISECT " ", texts); + + highlights = cblistopen(); + for (i = 0; texts[i]; i++) + { + cblistpush(highlights, texts[i], -1); + } + + g_strfreev(texts); + phrase = g_string_new(tmp); + + except_word = KZ_CONF_GET_STR("History", "except_keyword"); + if (except_word && *except_word) + { + texts = g_strsplit(except_word, ",", -1); + g_free(except_word); + i = 0; + while (texts[i]) + { + phrase = g_string_append(phrase, " " ESTOPDIFF " "); + phrase = g_string_append(phrase, texts[i]); + i++; + } + g_strfreev(texts); + } + est_cond_set_phrase(cond, phrase->str); + g_string_free(phrase, TRUE); + + KZ_CONF_GET("History", "num_summary", num_summary, INT); + KZ_CONF_GET("History", "max_results", max_results, INT); + half_of_summary = num_summary / 2; + + results = est_mtdb_search(db, cond, &n_results, NULL); + + html = g_string_sized_new(0); + + g_string_append(html, DTD"\n"); + g_string_append(html, "<html>\n"); + g_string_append(html, HEAD); + g_string_append(html, "<body>\n"); + + g_string_append_printf(html, "<h1>Search results for %s</h1>", + text); + + for (i = 0; i < MIN(n_results, max_results); i++) + { + ESTDOC *doc; + const gchar *title, *uri, *date; + gchar *desc, *cache_str = NULL; + const gchar *cache_link, *thumb_uri, *thumb_filename; + + doc = est_mtdb_get_doc(db, results[i], 0); + if (!doc) + continue; + + cache_link = est_doc_attr(doc, ESTDATTRURI); + uri = create_uri_from_filename(cache_link + + strlen("file://") + + he_search->cache_path_len); + thumb_filename = egg_pixbuf_get_thumb_filename(uri, + EGG_PIXBUF_THUMB_LARGE); + thumb_uri = g_strdup_printf("history-search:?image=%s", + thumb_filename); + title = est_doc_attr(doc, ESTDATTRTITLE); + date = est_doc_attr(doc, ESTDATTRMDATE); + + desc = est_doc_make_snippet(doc, highlights, num_summary, half_of_summary, half_of_summary); + + if (g_file_test(cache_link+strlen("file://"), G_FILE_TEST_EXISTS)) + cache_str = g_strdup_printf("<span class=\"cache\"><a href=\"%s\">cache</a></span>\n", cache_link); + else + cache_str = g_strdup(""); + + g_string_append_printf(html, + CONTENT, + uri, + title, + thumb_uri, /* thumbnail */ + desc, + uri, + cache_str, + date); + g_free(cache_str); + g_free(desc); + est_doc_delete(doc); + } + free(results); + + cblistclose(highlights); + est_cond_delete(cond); + + ret = est_mtdb_close(db, &ecode); + if (!ret) + g_warning("db close error: %s", est_err_msg(ecode)); + + g_string_append_printf(html, FOOTER, _EST_PROJURL, "Hyper Estraier", _EST_VERSION); + g_string_append(html, "</body></html>"); + + return g_string_free(html, FALSE); +} + + +gchar * +get_search_result_html (KzSearch *search, const gchar *text) +{ + if (!text) return NULL; + + return create_search_result_html(search, text); +} + +static gchar * +get_document_encoding (const gchar *contents) +{ + gchar *encoding = NULL; + gchar *p; + + if (!contents) return NULL; + + p = (gchar*)contents; + while ((p = strstr(p, "<meta "))) + { + gchar *end; + p = strstr(p, "http-equiv=\""); + if (!p) break; + + p+=12; + end = strchr(p, '"'); + if (!end) break; + + if (g_ascii_strncasecmp(p, "content-type", end - p)) + continue; + + p = end; + /* negligent */ + p = strstr(p, "charset="); + if (!p) break; + p+=8; + end = strchr(p, ';'); + if (!end) + end = strchr(p, '"'); + if (!end) break; + + encoding = g_strndup(p, end - p); + break; + } + + return encoding; +} + +gboolean +register_document (KzSearch *search, const gchar *uri, const gchar *title, const gchar *contents, GTime mtime) +{ + ESTMTDB *db; + ESTDOC *doc; + int ret, ecode, success; + gchar *time_str, *filename, *text = NULL; + gchar *tmp_filename, *tmp_path; + KzHyperEstraierSearch *he_search; + + he_search = KZ_HYPER_ESTRAIER_SEARCH(search); + db = est_mtdb_open(he_search->dbname, ESTDBWRITER | ESTDBCREAT, &ecode); + if (!db) + { + g_warning("db open error: %s", est_err_msg(ecode)); + return FALSE; + } + + doc = est_doc_new(); + + tmp_filename = create_filename_with_path_from_uri(uri); + tmp_path = g_build_filename(he_search->cache_path, tmp_filename, NULL); + filename = g_strdup_printf("file://%s", tmp_path); + g_free(tmp_path); + g_free(tmp_filename); + est_doc_add_attr(doc, ESTDATTRURI, filename); + g_free(filename); + + if (title) + est_doc_add_attr(doc, ESTDATTRTITLE, title); + + time_str = cbdatestrwww(mtime, 0); + est_doc_add_attr(doc, ESTDATTRMDATE, time_str); + g_free(time_str); + + text = html_to_text(contents); + if (text) + { + est_doc_add_text(doc, text); + g_free(text); + } + + success = est_mtdb_put_doc(db, doc, ESTPDCLEAN); + if (!success) + g_warning("register error: %s", est_err_msg(ecode)); + + est_doc_delete(doc); + + ret = est_mtdb_close(db, &ecode); + if (!ret) + g_warning("db close error: %s", est_err_msg(ecode)); + + return (success != 0) ? TRUE : FALSE; +} + +gboolean +unregister_document (KzSearch *search, const gchar *uri) +{ + ESTMTDB *db; + int id, ret, ecode, success; + KzHyperEstraierSearch *he_search; + + he_search = KZ_HYPER_ESTRAIER_SEARCH(search); + db = est_mtdb_open(he_search->dbname, ESTDBREADER, &ecode); + if (!db) + { + g_warning("db open error: %s", est_err_msg(ecode)); + return FALSE; + } + + id = est_mtdb_uri_to_id(db, uri); + if (id == -1) + return FALSE; + success = est_mtdb_out_doc(db, id, ESTODCLEAN); + + ret = est_mtdb_close(db, &ecode); + if (!ret) + g_warning("db close error: %s", est_err_msg(ecode)); + + return (success != 0) ? TRUE : FALSE; +} + +static GPid +optimize_index (KzSearch *search) +{ + ESTMTDB *db; + int ret, ecode; + KzHyperEstraierSearch *he_search; + + he_search = KZ_HYPER_ESTRAIER_SEARCH(search); + db = est_mtdb_open(he_search->dbname, ESTDBREADER, &ecode); + if (!db) + { + g_warning("db open error: %s", est_err_msg(ecode)); + return FALSE; + } + + est_mtdb_optimize(db, 0); + + ret = est_mtdb_close(db, &ecode); + if (!ret) + g_warning("db close error: %s", est_err_msg(ecode)); +#warning FIXME! return GSource or something. + return 0; +} + +static KzBookmark * +get_search_result_bookmark (KzSearch *search, const gchar *text) +{ + /* not implemented yet */ + return NULL; +} + +static void +register_documents_in_path (KzSearch *search, const gchar *path) +{ + GDir *gd; + const gchar *file; + KzHyperEstraierSearch *he_search; + + gd = g_dir_open(path, 0, NULL); + if (!gd) + return; + + he_search = KZ_HYPER_ESTRAIER_SEARCH(search); + while ((file = g_dir_read_name (gd))) + { + gchar *new_path = g_build_filename (path, file, NULL); + if (g_file_test(new_path, G_FILE_TEST_IS_DIR)) + { + register_documents_in_path(search, new_path); + } + else + { + gchar *uri, *contents; + gchar *encoding = NULL; + GTime mtime; + struct stat st; + + g_file_get_contents(new_path, &contents, NULL, NULL); + g_stat(new_path, &st); + mtime = st.st_mtime; + uri = create_uri_from_filename(new_path + + strlen("file://") + + he_search->cache_path_len); + + encoding = get_document_encoding(contents); + if (!encoding) + encoding = g_strdup(est_enc_name(contents, + strlen(contents), + ESTLANGJA)); + + if (encoding && strcmp(encoding, "UTF-8")) + { + gchar *utf8_contents; + utf8_contents = g_convert(contents, -1, + "UTF-8", encoding, + NULL, NULL, + NULL); + if (utf8_contents) + { + kz_search_register_document(search, uri, + NULL, + utf8_contents, + mtime); + g_free(utf8_contents); + } + } + else + kz_search_register_document(search, uri, NULL, contents, mtime); + + if (encoding) + g_free(encoding); + g_free(uri); + g_free(contents); + } + g_free(new_path); + } + g_dir_close (gd); +} + +static void +make_index (KzSearch *search) +{ + KzHyperEstraierSearch *he_search; + he_search = KZ_HYPER_ESTRAIER_SEARCH(search); + + register_documents_in_path(search, he_search->cache_path); +} + +static gboolean +exist_index_dir(KzSearch *search) +{ + KzHyperEstraierSearch *he_search; + he_search = KZ_HYPER_ESTRAIER_SEARCH(search); + + return g_file_test(he_search->dbname, G_FILE_TEST_IS_DIR); +} Deleted: kazehakase/trunk/module/search/kz-search-hyper-estraier.c =================================================================== --- kazehakase/trunk/module/search/kz-search-hyper-estraier.c 2007-03-23 06:06:19 UTC (rev 2979) +++ kazehakase/trunk/module/search/kz-search-hyper-estraier.c 2007-03-23 06:06:50 UTC (rev 2980) @@ -1,580 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Copyright (C) 2004 Hiroyuki Ikezoe - * - * 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 2, 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, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#include <ctype.h> -#include <glib/gi18n.h> -#include <glib.h> -#include <glib/gstdio.h> -#include <estraier.h> -#include <estmtdb.h> - -#include "kazehakase.h" -#include "utils/utils.h" -#include "glib-utils.h" -#include "kz-search-common.h" -#include "kz-search-hyper-estraier.h" -#include "egg-pixbuf-thumbnail.h" - -#define HISTORY_INDEX "history_index.hest" - - -typedef struct _KzSearchHyperEstraierPrivate KzSearchHyperEstraierPrivate; -struct _KzSearchHyperEstraierPrivate -{ - ESTMTDB *db; - gchar *dbname; - gchar *cache_path; - size_t cache_path_len; -}; - -typedef struct _KzSearchHyperEstraierClass KzSearchHyperEstraierClass; -struct _KzSearchHyperEstraierClass -{ - KzSearchClass parent_class; -}; - -#define KZ_SEARCH_HYPER_ESTRAIER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), KZ_TYPE_SEARCH_HYPER_ESTRAIER, KzSearchHyperEstraierPrivate)) - -#define KZ_SEARCH_HYPER_ESTRAIER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), KZ_TYPE_SEARCH_HYPER_ESTRAIER, KzSearchHyperEstraierClass)) -#define KZ_IS_SEARCH_HYPER_ESTRAIER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), KZ_TYPE_SEARCH_HYPER_ESTRAIER)) -#define KZ_SEARCH_HYPER_ESTRAIER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), KZ_TYPE_SEARCH_HYPER_ESTRAIER, KzSearchHyperEstraierClass)) - -/* for module */ -void kz_search_module_init (GTypeModule *module); -void kz_search_module_exit (void); -KzSearch *kz_search_module_create (void); - -/* KzSearchHyperEstraier Class */ -static void kz_search_hyper_estraier_class_init (KzSearchHyperEstraierClass *klass); -static void kz_search_hyper_estraier_init (KzSearchHyperEstraier *search); - -/* GObject Class */ -static GObject *constructor (GType type, - guint n_props, - GObjectConstructParam *props); -static void dispose (GObject *object); - -/* KzSearch Class */ -static gchar *get_search_result_html (KzSearch *search, const gchar *text); -static KzBookmark *get_search_result_bookmark (KzSearch *search, const gchar *text); -static gboolean register_document (KzSearch *search, - const gchar *uri, - const gchar *title, - const gchar *contents, - GTime mtime); -static gboolean unregister_document (KzSearch *search, const gchar *uri); -static GPid optimize_index (KzSearch *search); -static void make_index (KzSearch *search); -static gboolean exist_index_dir (KzSearch *search); - -static KzSearchHyperEstraier *the_kz_search_hyper_estraier = NULL; - -static GObjectClass *parent_class; -static GType kz_search_hyper_estraier_type = 0; - -static void -kz_search_hyper_estraier_register_type (GTypeModule *module) -{ - static const GTypeInfo kz_search_hyper_estraier_info = - { - sizeof (KzSearchHyperEstraierClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) kz_search_hyper_estraier_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (KzSearchHyperEstraier), - 0, /* n_preallocs */ - (GInstanceInitFunc) kz_search_hyper_estraier_init, - }; - - kz_search_hyper_estraier_type = g_type_module_register_type (module, - KZ_TYPE_SEARCH, - "KzSearchHyperEstraier", - &kz_search_hyper_estraier_info, 0); -} - -G_MODULE_EXPORT void -kz_search_module_init (GTypeModule *module) -{ - kz_search_hyper_estraier_register_type(module); -} - -G_MODULE_EXPORT void -kz_search_module_exit (void) -{ -} - -G_MODULE_EXPORT KzSearch * -kz_search_module_create (void) -{ - return kz_search_hyper_estraier_new(); -} - -GType -kz_search_hyper_estraier_get_type (void) -{ - return kz_search_hyper_estraier_type; -} - -static void -kz_search_hyper_estraier_class_init (KzSearchHyperEstraierClass *klass) -{ - GObjectClass *object_class; - KzSearchClass *search_class; - - parent_class = g_type_class_peek_parent (klass); - object_class = (GObjectClass *) klass; - search_class = (KzSearchClass *) klass; - - object_class->constructor = constructor; - object_class->dispose = dispose; - - search_class->get_search_result_html = get_search_result_html; - search_class->get_search_result_bookmark = get_search_result_bookmark; - search_class->register_document = register_document; - search_class->unregister_document = unregister_document; - search_class->optimize_index = optimize_index; - search_class->make_index = make_index; - search_class->exist_index_dir = exist_index_dir; - - g_type_class_add_private (object_class, sizeof(KzSearchHyperEstraierPrivate)); -} - - -static void -kz_search_hyper_estraier_init (KzSearchHyperEstraier *search) -{ - KzSearchHyperEstraierPrivate *priv = KZ_SEARCH_HYPER_ESTRAIER_GET_PRIVATE(search); - - priv->db = NULL; - priv->cache_path = g_build_filename(g_get_home_dir(), HISTORY_DIR, NULL); - priv->dbname = g_build_filename(g_get_home_dir(), "."PACKAGE, HISTORY_INDEX, NULL); - - priv->cache_path_len = strlen(priv->cache_path); -} - -static GObject * -constructor (GType type, - guint n_props, - GObjectConstructParam *props) -{ - GObject *object; - - if (!the_kz_search_hyper_estraier) - { - GObjectClass *klass = G_OBJECT_CLASS(parent_class); - object = klass->constructor(type, n_props, props); - the_kz_search_hyper_estraier = KZ_SEARCH_HYPER_ESTRAIER(object); - } - else - { - object = g_object_ref(G_OBJECT(the_kz_search_hyper_estraier)); - } - return object; -} - -static void -dispose (GObject *object) -{ - KzSearchHyperEstraierPrivate *priv = KZ_SEARCH_HYPER_ESTRAIER_GET_PRIVATE(object); - - if (priv->db) - { - int ecode, ret; - ret = est_mtdb_close(priv->db, &ecode); - if (!ret) - g_warning("db close error: %s", est_err_msg(ecode)); - } - if (priv->dbname) - g_free(priv->dbname); - if (priv->cache_path) - g_free(priv->cache_path); - - priv->db = NULL; - priv->dbname = NULL; - priv->cache_path = NULL; - - if (G_OBJECT_CLASS(parent_class)->dispose) - G_OBJECT_CLASS(parent_class)->dispose(object); -} - - -KzSearch * -kz_search_hyper_estraier_new (void) -{ - return KZ_SEARCH(g_object_new(KZ_TYPE_SEARCH_HYPER_ESTRAIER, NULL)); -} - -static gchar * -create_search_result_html (KzSearch *search, const gchar *text) -{ - ESTMTDB *db; - ESTCOND *cond; - CBLIST *highlights; - int ecode, *results, n_results, i, ret; - gchar *except_word, *tmp; - gchar **texts; - GString *html, *phrase; - gint num_summary = 128, max_results = 20, half_of_summary; - KzSearchHyperEstraierPrivate *priv = KZ_SEARCH_HYPER_ESTRAIER_GET_PRIVATE(search); - - db = est_mtdb_open(priv->dbname, ESTDBREADER, &ecode); - if (!db) - { - g_warning("db open error: %s", est_err_msg(ecode)); - return NULL; - } - - cond = est_cond_new(); - texts = g_strsplit(text, " ", -1); - tmp = g_strjoinv(" " ESTOPISECT " ", texts); - - highlights = cblistopen(); - for (i = 0; texts[i]; i++) - { - cblistpush(highlights, texts[i], -1); - } - - g_strfreev(texts); - phrase = g_string_new(tmp); - - except_word = KZ_CONF_GET_STR("History", "except_keyword"); - if (except_word && *except_word) - { - texts = g_strsplit(except_word, ",", -1); - g_free(except_word); - i = 0; - while (texts[i]) - { - phrase = g_string_append(phrase, " " ESTOPDIFF " "); - phrase = g_string_append(phrase, texts[i]); - i++; - } - g_strfreev(texts); - } - est_cond_set_phrase(cond, phrase->str); - g_string_free(phrase, TRUE); - - KZ_CONF_GET("History", "num_summary", num_summary, INT); - KZ_CONF_GET("History", "max_results", max_results, INT); - half_of_summary = num_summary / 2; - - results = est_mtdb_search(db, cond, &n_results, NULL); - - html = g_string_sized_new(0); - - g_string_append(html, DTD"\n"); - g_string_append(html, "<html>\n"); - g_string_append(html, HEAD); - g_string_append(html, "<body>\n"); - - g_string_append_printf(html, "<h1>Search results for %s</h1>", - text); - - for (i = 0; i < MIN(n_results, max_results); i++) - { - ESTDOC *doc; - const gchar *title, *uri, *date; - gchar *desc, *cache_str = NULL; - const gchar *cache_link, *thumb_uri, *thumb_filename; - - doc = est_mtdb_get_doc(db, results[i], 0); - if (!doc) - continue; - - cache_link = est_doc_attr(doc, ESTDATTRURI); - uri = create_uri_from_filename(cache_link + - strlen("file://") + priv->cache_path_len); - thumb_filename = egg_pixbuf_get_thumb_filename(uri, - EGG_PIXBUF_THUMB_LARGE); - thumb_uri = g_strdup_printf("history-search:?image=%s", - thumb_filename); - title = est_doc_attr(doc, ESTDATTRTITLE); - date = est_doc_attr(doc, ESTDATTRMDATE); - - desc = est_doc_make_snippet(doc, highlights, num_summary, half_of_summary, half_of_summary); - - if (g_file_test(cache_link+strlen("file://"), G_FILE_TEST_EXISTS)) - cache_str = g_strdup_printf("<span class=\"cache\"><a href=\"%s\">cache</a></span>\n", cache_link); - else - cache_str = g_strdup(""); - - g_string_append_printf(html, - CONTENT, - uri, - title, - thumb_uri, /* thumbnail */ - desc, - uri, - cache_str, - date); - g_free(cache_str); - g_free(desc); - est_doc_delete(doc); - } - free(results); - - cblistclose(highlights); - est_cond_delete(cond); - - ret = est_mtdb_close(db, &ecode); - if (!ret) - g_warning("db close error: %s", est_err_msg(ecode)); - - g_string_append_printf(html, FOOTER, _EST_PROJURL, "Hyper Estraier", _EST_VERSION); - g_string_append(html, "</body></html>"); - - return g_string_free(html, FALSE); -} - - -gchar * -get_search_result_html (KzSearch *search, const gchar *text) -{ - if (!text) return NULL; - - return create_search_result_html(search, text); -} - -static gchar * -get_document_encoding (const gchar *contents) -{ - gchar *encoding = NULL; - gchar *p; - - if (!contents) return NULL; - - p = (gchar*)contents; - while ((p = strstr(p, "<meta "))) - { - gchar *end; - p = strstr(p, "http-equiv=\""); - if (!p) break; - - p+=12; - end = strchr(p, '"'); - if (!end) break; - - if (g_ascii_strncasecmp(p, "content-type", end - p)) - continue; - - p = end; - /* negligent */ - p = strstr(p, "charset="); - if (!p) break; - p+=8; - end = strchr(p, ';'); - if (!end) - end = strchr(p, '"'); - if (!end) break; - - encoding = g_strndup(p, end - p); - break; - } - - return encoding; -} - -gboolean -register_document (KzSearch *search, const gchar *uri, const gchar *title, const gchar *contents, GTime mtime) -{ - ESTMTDB *db; - ESTDOC *doc; - int ret, ecode, success; - gchar *time_str, *filename, *text = NULL; - gchar *tmp_filename, *tmp_path; - KzSearchHyperEstraierPrivate *priv = KZ_SEARCH_HYPER_ESTRAIER_GET_PRIVATE(search); - - db = est_mtdb_open(priv->dbname, ESTDBWRITER | ESTDBCREAT, &ecode); - if (!db) - { - g_warning("db open error: %s", est_err_msg(ecode)); - return FALSE; - } - - doc = est_doc_new(); - - tmp_filename = create_filename_with_path_from_uri(uri); - tmp_path = g_build_filename(priv->cache_path, tmp_filename, NULL); - filename = g_strdup_printf("file://%s", tmp_path); - g_free(tmp_path); - g_free(tmp_filename); - est_doc_add_attr(doc, ESTDATTRURI, filename); - g_free(filename); - - if (title) - est_doc_add_attr(doc, ESTDATTRTITLE, title); - - time_str = cbdatestrwww(mtime, 0); - est_doc_add_attr(doc, ESTDATTRMDATE, time_str); - g_free(time_str); - - text = html_to_text(contents); - if (text) - { - est_doc_add_text(doc, text); - g_free(text); - } - - success = est_mtdb_put_doc(db, doc, ESTPDCLEAN); - if (!success) - g_warning("register error: %s", est_err_msg(ecode)); - - est_doc_delete(doc); - - ret = est_mtdb_close(db, &ecode); - if (!ret) - g_warning("db close error: %s", est_err_msg(ecode)); - - return (success != 0) ? TRUE : FALSE; -} - -gboolean -unregister_document (KzSearch *search, const gchar *uri) -{ - ESTMTDB *db; - int id, ret, ecode, success; - KzSearchHyperEstraierPrivate *priv = KZ_SEARCH_HYPER_ESTRAIER_GET_PRIVATE(search); - - db = est_mtdb_open(priv->dbname, ESTDBREADER, &ecode); - if (!db) - { - g_warning("db open error: %s", est_err_msg(ecode)); - return FALSE; - } - - id = est_mtdb_uri_to_id(db, uri); - if (id == -1) - return FALSE; - success = est_mtdb_out_doc(db, id, ESTODCLEAN); - - ret = est_mtdb_close(db, &ecode); - if (!ret) - g_warning("db close error: %s", est_err_msg(ecode)); - - return (success != 0) ? TRUE : FALSE; -} - -static GPid -optimize_index (KzSearch *search) -{ - ESTMTDB *db; - int ret, ecode; - KzSearchHyperEstraierPrivate *priv = KZ_SEARCH_HYPER_ESTRAIER_GET_PRIVATE(search); - - db = est_mtdb_open(priv->dbname, ESTDBREADER, &ecode); - if (!db) - { - g_warning("db open error: %s", est_err_msg(ecode)); - return FALSE; - } - - est_mtdb_optimize(db, 0); - - ret = est_mtdb_close(db, &ecode); - if (!ret) - g_warning("db close error: %s", est_err_msg(ecode)); -#warning FIXME! return GSource or something. - return 0; -} - -static KzBookmark * -get_search_result_bookmark (KzSearch *search, const gchar *text) -{ - /* not implemented yet */ - return NULL; -} - -static void -register_documents_in_path (KzSearch *search, const gchar *path) -{ - GDir *gd; - const gchar *file; - KzSearchHyperEstraierPrivate *priv = KZ_SEARCH_HYPER_ESTRAIER_GET_PRIVATE(search); - - gd = g_dir_open(path, 0, NULL); - if (!gd) - return; - - while ((file = g_dir_read_name (gd))) - { - gchar *new_path = g_build_filename (path, file, NULL); - if (g_file_test(new_path, G_FILE_TEST_IS_DIR)) - { - register_documents_in_path(search, new_path); - } - else - { - gchar *uri, *contents; - gchar *encoding = NULL; - GTime mtime; - struct stat st; - - g_file_get_contents(new_path, &contents, NULL, NULL); - g_stat(new_path, &st); - mtime = st.st_mtime; - uri = create_uri_from_filename(new_path + strlen("file://") + priv->cache_path_len); - - encoding = get_document_encoding(contents); - if (!encoding) - encoding = g_strdup(est_enc_name(contents, strlen(contents), ESTLANGJA)); - - if (encoding && strcmp(encoding, "UTF-8")) - { - gchar *utf8_contents; - utf8_contents = g_convert(contents, -1, - "UTF-8", encoding, - NULL, NULL, - NULL); - kz_search_register_document(search, uri, NULL, utf8_contents, mtime); - g_free(utf8_contents); - } - else - kz_search_register_document(search, uri, NULL, contents, mtime); - - if (encoding) - g_free(encoding); - g_free(uri); - g_free(contents); - } - g_free(new_path); - } - g_dir_close (gd); -} - -static void -make_index (KzSearch *search) -{ - KzSearchHyperEstraierPrivate *priv = KZ_SEARCH_HYPER_ESTRAIER_GET_PRIVATE(search); - - register_documents_in_path(search, priv->cache_path); -} - -static gboolean -exist_index_dir(KzSearch *search) -{ - gboolean exist = FALSE; - KzSearchHyperEstraierPrivate *priv = KZ_SEARCH_HYPER_ESTRAIER_GET_PRIVATE(search); - - exist = g_file_test(priv->dbname, G_FILE_TEST_IS_DIR); - - return exist; -} Deleted: kazehakase/trunk/module/search/kz-search-hyper-estraier.h =================================================================== --- kazehakase/trunk/module/search/kz-search-hyper-estraier.h 2007-03-23 06:06:19 UTC (rev 2979) +++ kazehakase/trunk/module/search/kz-search-hyper-estraier.h 2007-03-23 06:06:50 UTC (rev 2980) @@ -1,46 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Copyright (C) 2004 Hiroyuki Ikezoe - * - * 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 2, 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, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifndef __KZ_SEARCH_HYPER_ESTRAIER_H__ -#define __KZ_SEARCH_HYPER_ESTRAIER_H__ - -#include <glib-object.h> -#include "kz-search.h" - -G_BEGIN_DECLS - -#define KZ_TYPE_SEARCH_HYPER_ESTRAIER (kz_search_hyper_estraier_get_type ()) -#define KZ_SEARCH_HYPER_ESTRAIER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), KZ_TYPE_SEARCH_HYPER_ESTRAIER, KzSearchHyperEstraier)) -#define KZ_IS_SEARCH_HYPER_ESTRAIER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), KZ_TYPE_SEARCH_HYPER_ESTRAIER)) - -typedef struct _KzSearchHyperEstraier KzSearchHyperEstraier; - -struct _KzSearchHyperEstraier -{ - KzSearch parent; -}; - -GType kz_search_hyper_estraier_get_type (void) G_GNUC_CONST; - -KzSearch *kz_search_hyper_estraier_new (void); - -G_END_DECLS - -#endif /* __HYPER_ESTRAIERSEARCH_H__ */ Modified: kazehakase/trunk/src/kz-app.c =================================================================== --- kazehakase/trunk/src/kz-app.c 2007-03-23 06:06:19 UTC (rev 2979) +++ kazehakase/trunk/src/kz-app.c 2007-03-23 06:06:50 UTC (rev 2980) @@ -257,7 +257,7 @@ search_engine = kz_profile_get_string(priv->profile, "History" , "search_engine"); if (search_engine) { - if (!strcmp(search_engine, "hyperestraier") || + if (!strcmp(search_engine, "hyper-estraier") || !strcmp(search_engine, "rast")) priv->search = kz_search_new(search_engine); Modified: kazehakase/trunk/src/kz-search.c =================================================================== --- kazehakase/trunk/src/kz-search.c 2007-03-23 06:06:19 UTC (rev 2979) +++ kazehakase/trunk/src/kz-search.c 2007-03-23 06:06:50 UTC (rev 2980) @@ -1,6 +1,7 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* + * Copyright (C) 2007 Kouhei Sutou <kou****@cozmi*****> * Copyright (C) 2004 Hiroyuki Ikezoe * * This program is free software; you can redistribute it and/or modify @@ -24,279 +25,206 @@ #include "kazehakase.h" #include "glib-utils.h" #include "kz-search.h" +#include "kz-module.h" -typedef struct _KzSearchModule KzSearchModule; -typedef struct _KzSearchModuleClass KzSearchModuleClass; -struct _KzSearchModule -{ - GTypeModule object; - GModule *library; +static GList *searches = NULL; - void (*init) (GTypeModule *module); - void (*exit) (void); - KzSearch *(*create) (void); - gchar *path; -}; - -struct _KzSearchModuleClass +static const gchar * +_kz_search_module_dir (void) { - GTypeModuleClass parent_class; -}; + const gchar *base_dir; + base_dir = g_getenv("KZ_SEARCH_MODULE_DIR"); + if (base_dir) + return base_dir; + return KZ_SEARCH_MODULEDIR; +} -GType kz_search_module_get_type (void) G_GNUC_CONST; - -G_DEFINE_TYPE (KzSearchModule, kz_search_module, G_TYPE_TYPE_MODULE) - -#define KZ_TYPE_SEARCH_MODULE (kz_search_module_get_type ()) -#define KZ_SEARCH_MODULE(module) (G_TYPE_CHECK_INSTANCE_CAST ((module), KZ_TYPE_SEARCH_MODULE, KzSearchModule)) - -static GSList *loaded_search; - -static gboolean -kz_search_module_load (GTypeModule *module) +void +kz_search_load (const gchar *base_dir) { - KzSearchModule *s_module = KZ_SEARCH_MODULE(module); - gpointer initp, exitp, createp; + if (!base_dir) + base_dir = _kz_search_module_dir(); - s_module->library = g_module_open(s_module->path, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL); - if (!s_module->library) - { - g_warning(g_module_error()); - return FALSE; - } - - /* exact symbols from the lib */ - if (!g_module_symbol(s_module->library, "kz_search_module_init", &initp) || - !g_module_symbol(s_module->library, "kz_search_module_exit", &exitp) || - !g_module_symbol(s_module->library, "kz_search_module_create", &createp)) - { - g_warning(g_module_error()); - g_module_close(s_module->library); - - return FALSE; - } - - s_module->init = initp; - s_module->exit = exitp; - s_module->create = createp; - - s_module->init(module); - - return TRUE; + searches = g_list_concat(kz_module_load_modules(base_dir), searches); } - -static void -kz_search_module_unload (GTypeModule *module) -{ - KzSearchModule *s_module = KZ_SEARCH_MODULE(module); - s_module->exit(); - - g_module_close(s_module->library); - s_module->library = NULL; - - s_module->init = NULL; - s_module->exit = NULL; - s_module->create = NULL; +void +kz_search_unload (void) +{ + g_list_foreach(searches, (GFunc)kz_module_unload, NULL); + g_list_free(searches); + searches = NULL; } -static void -kz_search_module_finalize (GObject *object) +void +kz_search_exit (void) { - KzSearchModule *module = KZ_SEARCH_MODULE(object); - - g_free(module->path); - - G_OBJECT_CLASS(kz_search_module_parent_class)->finalize(object); + g_list_foreach(searches, (GFunc)kz_module_exit, NULL); } -static void -kz_search_module_class_init (KzSearchModuleClass *klass) + +GList * +kz_search_engine_names (void) { - GTypeModuleClass *module_class = G_TYPE_MODULE_CLASS(klass); - GObjectClass *gobject_class = G_OBJECT_CLASS(klass); + GList *node; + GList *result = NULL; - module_class->load = kz_search_module_load; - module_class->unload = kz_search_module_unload; + for (node = searches; node; node = g_list_next(node)) + { + KzModule *module = node->data; + result = g_list_append(result, + g_strdup(G_TYPE_MODULE(module)->name)); + } - gobject_class->finalize = kz_search_module_finalize; -} - -static void -kz_search_module_init (KzSearchModule *module) -{ + return result; } static KzSearch * -kz_search_module_create (KzSearchModule *module) +_kz_search_new (KzModule *module, const gchar *name, + const gchar *first_property, ...) { - KzSearch *search = NULL; - if (g_type_module_use(G_TYPE_MODULE(module))) - { - search = module->create(); - g_type_module_unuse(G_TYPE_MODULE(module)); - return search; - } - return NULL; + GObject *search; + va_list var_args; + + va_start(var_args, first_property); + search = kz_module_instantiate(module, first_property, var_args); + va_end(var_args); + + return KZ_SEARCH(search); } - + KzSearch * kz_search_new (const gchar *name) { - GSList *l; - gchar *module_path; - KzSearchModule *module; - KzSearch *search = NULL; + KzModule *module; - for (l = loaded_search; l; l = l->next) + module = kz_module_find(searches, name); + if (!module) { - module = l->data; - - if (strcmp(G_TYPE_MODULE (module)->name, name) == 0) - return kz_search_module_create(module); + module = kz_module_load_module(_kz_search_module_dir(), name); + if (!module) + return NULL; + searches = g_list_prepend(searches, module); } - if (g_module_supported()) - { - module_path = g_module_build_path(KZ_SEARCH_MODULEDIR, name); - - if (module_path) - { - module = g_object_new(KZ_TYPE_SEARCH_MODULE, NULL); - - g_type_module_set_name(G_TYPE_MODULE(module), name); - module->path = g_strdup(module_path); - - loaded_search = g_slist_prepend(loaded_search, - module); - - search = kz_search_module_create(module); - g_free(module_path); - } - } - - return search; + return _kz_search_new(module, name, NULL); } -#define KZ_SEARCH_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), KZ_TYPE_SEARCH, KzSearchPrivate)) - -G_DEFINE_ABSTRACT_TYPE(KzSearch, kz_search, G_TYPE_OBJECT) - -static void -kz_search_class_init (KzSearchClass *klass) +GType +kz_search_get_type (void) { - GObjectClass *object_class; - - kz_search_parent_class = g_type_class_peek_parent (klass); - object_class = (GObjectClass *) klass; - - klass->get_search_result_html = NULL; - klass->get_search_result_bookmark = NULL; - klass->optimize_index = NULL; - klass->make_index = NULL; - klass->exist_index_dir = NULL; + static GType type = 0; + if (!type) + { + static const GTypeInfo info = { + sizeof (KzSearchIFace), + NULL, /* base_init */ + NULL, /* base_finalize */ + NULL, /* class_init */ + NULL, /* class_finalize */ + NULL, /* class_data */ + 0, + 0, /* n_preallocs */ + NULL, /* instance_init */ + }; + type = g_type_register_static(G_TYPE_INTERFACE, "KzSearch", + &info, 0); + g_type_interface_add_prerequisite(type, G_TYPE_OBJECT); + } + return type; } - -static void -kz_search_init (KzSearch *search) -{ -} - gchar * kz_search_get_search_result_html (KzSearch *search, const gchar *text) { - KzSearchClass *klass; + KzSearchIFace *iface; - g_return_val_if_fail (KZ_IS_SEARCH (search), NULL); + g_return_val_if_fail(KZ_IS_SEARCH(search), NULL); - klass = KZ_SEARCH_GET_CLASS (search); - if (klass->get_search_result_html) - return klass->get_search_result_html (search, text); - else - return NULL; + iface = KZ_SEARCH_GET_IFACE(search); + g_return_val_if_fail(iface->get_search_result_html, NULL); + + return iface->get_search_result_html(search, text); } KzBookmark * kz_search_get_search_result_bookmark (KzSearch *search, const gchar *text) { - KzSearchClass *klass; + KzSearchIFace *iface; - g_return_val_if_fail (KZ_IS_SEARCH(search), NULL); + g_return_val_if_fail(KZ_IS_SEARCH(search), NULL); - klass = KZ_SEARCH_GET_CLASS(search); - if (klass->get_search_result_bookmark) - return klass->get_search_result_bookmark(search, text); - else - return NULL; + iface = KZ_SEARCH_GET_IFACE(search); + g_return_val_if_fail(iface->get_search_result_bookmark, NULL); + + return iface->get_search_result_bookmark(search, text); } gboolean -kz_search_register_document (KzSearch *search, const gchar *uri, const gchar *title, const gchar *contents, GTime mtime) +kz_search_register_document (KzSearch *search, const gchar *uri, + const gchar *title, const gchar *contents, + GTime mtime) { - KzSearchClass *klass; + KzSearchIFace *iface; - g_return_val_if_fail (KZ_IS_SEARCH (search), FALSE); + g_return_val_if_fail(KZ_IS_SEARCH(search), FALSE); - klass = KZ_SEARCH_GET_CLASS (search); - if (klass->register_document) - return klass->register_document (search, uri, title, contents, mtime); - else - return FALSE; + iface = KZ_SEARCH_GET_IFACE(search); + g_return_val_if_fail(iface->register_document, FALSE); + + return iface->register_document(search, uri, title, contents, mtime); } gboolean kz_search_unregister_document (KzSearch *search, const gchar *uri) { - KzSearchClass *klass; + KzSearchIFace *iface; - g_return_val_if_fail (KZ_IS_SEARCH (search), FALSE); + g_return_val_if_fail(KZ_IS_SEARCH(search), FALSE); - klass = KZ_SEARCH_GET_CLASS (search); - if (klass->unregister_document) - return klass->unregister_document (search, uri); - else - return FALSE; + iface = KZ_SEARCH_GET_IFACE(search); + g_return_val_if_fail(iface->unregister_document, FALSE); + + return iface->unregister_document(search, uri); } GPid kz_search_optimize_index (KzSearch *search) { - KzSearchClass *klass; + KzSearchIFace *iface; g_return_val_if_fail(KZ_IS_SEARCH(search), 0); - klass = KZ_SEARCH_GET_CLASS(search); - if (klass->optimize_index) - return klass->optimize_index(search); - else - return 0; + iface = KZ_SEARCH_GET_IFACE(search); + g_return_val_if_fail(iface->optimize_index, 0); + + return iface->optimize_index(search); } void kz_search_make_index (KzSearch *search) { - KzSearchClass *klass; + KzSearchIFace *iface; g_return_if_fail(KZ_IS_SEARCH(search)); - klass = KZ_SEARCH_GET_CLASS(search); - if (klass->make_index) - klass->make_index(search); + iface = KZ_SEARCH_GET_IFACE(search); + g_return_if_fail(iface->make_index); + + return iface->make_index(search); } gboolean kz_search_exist_index_dir (KzSearch *search) { - KzSearchClass *klass; + KzSearchIFace *iface; g_return_val_if_fail(KZ_IS_SEARCH(search), FALSE); - klass = KZ_SEARCH_GET_CLASS(search); - if (klass->exist_index_dir) - return klass->exist_index_dir(search); - else - return FALSE; + iface = KZ_SEARCH_GET_IFACE(search); + g_return_val_if_fail(iface->make_index, FALSE); + + return iface->exist_index_dir(search); } Modified: kazehakase/trunk/src/kz-search.h =================================================================== --- kazehakase/trunk/src/kz-search.h 2007-03-23 06:06:19 UTC (rev 2979) +++ kazehakase/trunk/src/kz-search.h 2007-03-23 06:06:50 UTC (rev 2980) @@ -1,6 +1,7 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* + * Copyright (C) 2007 Kouhei Sutou <kou****@cozmi*****> * Copyright (C) 2004 Hiroyuki Ikezoe * * This program is free software; you can redistribute it and/or modify @@ -26,25 +27,18 @@ G_BEGIN_DECLS -#define KZ_TYPE_SEARCH (kz_search_get_type ()) -#define KZ_SEARCH(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), KZ_TYPE_SEARCH, KzSearch)) -#define KZ_SEARCH_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), KZ_TYPE_SEARCH, KzSearchClass)) -#define KZ_IS_SEARCH(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), KZ_TYPE_SEARCH)) -#define KZ_IS_SEARCH_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), KZ_TYPE_SEARCH)) -#define KZ_SEARCH_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), KZ_TYPE_SEARCH, KzSearchClass)) +#define KZ_TYPE_SEARCH (kz_search_get_type()) +#define KZ_SEARCH(o) (G_TYPE_CHECK_INSTANCE_CAST((o), KZ_TYPE_SEARCH, KzSearch)) +#define KZ_IS_SEARCH(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), KZ_TYPE_SEARCH)) +#define KZ_SEARCH_GET_IFACE(o) (G_TYPE_INSTANCE_GET_INTERFACE((o), KZ_TYPE_SEARCH, KzSearchIFace)) typedef struct _KzSearch KzSearch; -typedef struct _KzSearchClass KzSearchClass; +typedef struct _KzSearchIFace KzSearchIFace; -struct _KzSearch +struct _KzSearchIFace { - GObject parent; -}; + GTypeInterface g_iface; -struct _KzSearchClass -{ - GObjectClass parent_class; - gchar *(*get_search_result_html) (KzSearch *search, const gchar *text); KzBookmark *(*get_search_result_bookmark) (KzSearch *search, const gchar *text); gboolean (*register_document) (KzSearch *search, @@ -58,22 +52,27 @@ gboolean (*exist_index_dir) (KzSearch *search); }; -GType kz_search_get_type (void) G_GNUC_CONST; +GType kz_search_get_type (void) G_GNUC_CONST; -KzSearch *kz_search_new (const gchar *name); +void kz_search_load (const gchar *base_dir); +void kz_search_unload (void); +void kz_search_exit (void); +GList *kz_search_engine_names (void); -gchar *kz_search_get_search_result_html (KzSearch *search, const gchar *text); -KzBookmark *kz_search_get_search_result_bookmark (KzSearch *search, const gchar *text); +KzSearch *kz_search_new (const gchar *name); -gboolean kz_search_register_document (KzSearch *search, +gchar *kz_search_get_search_result_html (KzSearch *search, const gchar *text); +KzBookmark *kz_search_get_search_result_bookmark (KzSearch *search, const gchar *text); + +gboolean kz_search_register_document (KzSearch *search, const gchar *uri, const gchar *title, const gchar *contents, GTime mtime); -gboolean kz_search_unregister_document (KzSearch *search, const gchar *uri); -GPid kz_search_optimize_index (KzSearch *search); -void kz_search_make_index (KzSearch *search); -gboolean kz_search_exist_index_dir (KzSearch *search); +gboolean kz_search_unregister_document (KzSearch *search, const gchar *uri); +GPid kz_search_optimize_index (KzSearch *search); +void kz_search_make_index (KzSearch *search); +gboolean kz_search_exist_index_dir (KzSearch *search); G_END_DECLS