1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * Copyright (C) 2011 Shaun McCance <shaunm@gnome.org>
4 *
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.
9 *
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.
14 *
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/>.
17 *
18 * Author: Shaun McCance <shaunm@gnome.org>
19 */
20
21 #include "yelp-storage.h"
22 #include "yelp-sqlite-storage.h"
23
G_DEFINE_INTERFACE(YelpStorage,yelp_storage,G_TYPE_OBJECT)24 G_DEFINE_INTERFACE (YelpStorage, yelp_storage, G_TYPE_OBJECT)
25
26 static YelpStorage *default_storage;
27
28 static void
29 yelp_storage_default_init (YelpStorageInterface *iface)
30 {
31 default_storage = NULL;
32 }
33
34 void
yelp_storage_set_default(YelpStorage * storage)35 yelp_storage_set_default (YelpStorage *storage)
36 {
37 default_storage = g_object_ref (storage);
38 }
39
40 YelpStorage *
yelp_storage_get_default(void)41 yelp_storage_get_default (void)
42 {
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;
49 }
50
51 void
yelp_storage_update(YelpStorage * storage,const gchar * doc_uri,const gchar * full_uri,const gchar * title,const gchar * desc,const gchar * icon,const gchar * text)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)
59 {
60 YelpStorageInterface *iface;
61
62 g_return_if_fail (YELP_IS_STORAGE (storage));
63
64 iface = YELP_STORAGE_GET_INTERFACE (storage);
65
66 if (iface->update)
67 (*iface->update) (storage,
68 doc_uri, full_uri,
69 title, desc, icon,
70 text);
71 }
72
73 GVariant *
yelp_storage_search(YelpStorage * storage,const gchar * doc_uri,const gchar * text)74 yelp_storage_search (YelpStorage *storage,
75 const gchar *doc_uri,
76 const gchar *text)
77 {
78 YelpStorageInterface *iface;
79
80 g_return_val_if_fail (YELP_IS_STORAGE (storage), NULL);
81
82 iface = YELP_STORAGE_GET_INTERFACE (storage);
83
84 if (iface->search)
85 return (*iface->search) (storage, doc_uri, text);
86 else
87 return NULL;
88 }
89
90 gchar *
yelp_storage_get_root_title(YelpStorage * storage,const gchar * doc_uri)91 yelp_storage_get_root_title (YelpStorage *storage,
92 const gchar *doc_uri)
93 {
94 YelpStorageInterface *iface;
95
96 g_return_val_if_fail (YELP_IS_STORAGE (storage), NULL);
97
98 iface = YELP_STORAGE_GET_INTERFACE (storage);
99
100 if (iface->search)
101 return (*iface->get_root_title) (storage, doc_uri);
102 else
103 return NULL;
104 }
105
106 void
yelp_storage_set_root_title(YelpStorage * storage,const gchar * doc_uri,const gchar * title)107 yelp_storage_set_root_title (YelpStorage *storage,
108 const gchar *doc_uri,
109 const gchar *title)
110 {
111 YelpStorageInterface *iface;
112
113 g_return_if_fail (YELP_IS_STORAGE (storage));
114
115 iface = YELP_STORAGE_GET_INTERFACE (storage);
116
117 if (iface->search)
118 (*iface->set_root_title) (storage, doc_uri, title);
119 }
120