Allow .docbook files as file path, #699995
[yelp.git] / libyelp / yelp-storage.c
blobbdac183c4c266dacbfb498fae7a3114c2144e4fa
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * Copyright (C) 2011 Shaun McCance <shaunm@gnome.org>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public
16 * License along with this program; if not, see <http://www.gnu.org/licenses/>.
18 * Author: Shaun McCance <shaunm@gnome.org>
21 #include "yelp-storage.h"
22 #include "yelp-sqlite-storage.h"
24 G_DEFINE_INTERFACE (YelpStorage, yelp_storage, G_TYPE_OBJECT)
26 static YelpStorage *default_storage;
28 static void
29 yelp_storage_default_init (YelpStorageInterface *iface)
31 default_storage = NULL;
34 void
35 yelp_storage_set_default (YelpStorage *storage)
37 default_storage = g_object_ref (storage);
40 YelpStorage *
41 yelp_storage_get_default (void)
43 static GMutex mutex;
44 g_mutex_lock (&mutex);
45 if (default_storage == NULL)
46 default_storage = yelp_sqlite_storage_new (":memory:");
47 g_mutex_unlock (&mutex);
48 return default_storage;
51 void
52 yelp_storage_update (YelpStorage *storage,
53 const gchar *doc_uri,
54 const gchar *full_uri,
55 const gchar *title,
56 const gchar *desc,
57 const gchar *icon,
58 const gchar *text)
60 YelpStorageInterface *iface;
62 g_return_if_fail (YELP_IS_STORAGE (storage));
64 iface = YELP_STORAGE_GET_INTERFACE (storage);
66 if (iface->update)
67 (*iface->update) (storage,
68 doc_uri, full_uri,
69 title, desc, icon,
70 text);
73 GVariant *
74 yelp_storage_search (YelpStorage *storage,
75 const gchar *doc_uri,
76 const gchar *text)
78 YelpStorageInterface *iface;
80 g_return_val_if_fail (YELP_IS_STORAGE (storage), NULL);
82 iface = YELP_STORAGE_GET_INTERFACE (storage);
84 if (iface->search)
85 return (*iface->search) (storage, doc_uri, text);
86 else
87 return NULL;
90 gchar *
91 yelp_storage_get_root_title (YelpStorage *storage,
92 const gchar *doc_uri)
94 YelpStorageInterface *iface;
96 g_return_val_if_fail (YELP_IS_STORAGE (storage), NULL);
98 iface = YELP_STORAGE_GET_INTERFACE (storage);
100 if (iface->search)
101 return (*iface->get_root_title) (storage, doc_uri);
102 else
103 return NULL;
106 void
107 yelp_storage_set_root_title (YelpStorage *storage,
108 const gchar *doc_uri,
109 const gchar *title)
111 YelpStorageInterface *iface;
113 g_return_if_fail (YELP_IS_STORAGE (storage));
115 iface = YELP_STORAGE_GET_INTERFACE (storage);
117 if (iface->search)
118 (*iface->set_root_title) (storage, doc_uri, title);