3
* Copyright (C) 2015 Christian Hergert <christian@hergert.me>
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation, either version 3 of the License, or
8
* (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
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19
#include <glib/gi18n.h>
21
#include "ide-internal.h"
22
#include "ide-search-context.h"
23
#include "ide-search-engine.h"
24
#include "ide-search-provider.h"
25
#include "ide-search-result.h"
27
struct _IdeSearchEngine
29
IdeObject parent_instance;
33
G_DEFINE_TYPE (IdeSearchEngine, ide_search_engine, IDE_TYPE_OBJECT)
40
static guint gSignals [LAST_SIGNAL];
43
* ide_search_engine_search:
44
* @providers: (allow-none) (element-type IdeSearchProvider*): Optional list
45
* of specific providers to use when searching.
46
* @search_terms: The search terms.
48
* Begins a query against the requested search providers.
50
* If @providers is %NULL, all registered providers will be used.
52
* Returns: (transfer full) (nullable): An #IdeSearchContext or %NULL if no
53
* providers could be loaded.
56
ide_search_engine_search (IdeSearchEngine *self,
57
const GList *providers,
58
const gchar *search_terms)
60
IdeSearchContext *search_context;
64
g_return_val_if_fail (IDE_IS_SEARCH_ENGINE (self), NULL);
65
g_return_val_if_fail (search_terms, NULL);
68
providers = self->providers;
70
context = ide_object_get_context (IDE_OBJECT (self));
71
search_context = g_object_new (IDE_TYPE_SEARCH_CONTEXT,
75
for (iter = providers; iter; iter = iter->next)
76
_ide_search_context_add_provider (search_context, iter->data, 0);
78
return search_context;
82
* ide_search_engine_get_providers:
84
* Returns the list of registered search providers.
86
* Returns: (transfer none) (element-type IdeSearchProvider*): A #GList of
90
ide_search_engine_get_providers (IdeSearchEngine *self)
92
g_return_val_if_fail (IDE_IS_SEARCH_ENGINE (self), NULL);
94
return self->providers;
98
ide_search_engine_add_provider (IdeSearchEngine *self,
99
IdeSearchProvider *provider)
101
g_return_if_fail (IDE_IS_SEARCH_ENGINE (self));
102
g_return_if_fail (IDE_IS_SEARCH_PROVIDER (provider));
104
self->providers = g_list_append (self->providers, g_object_ref (provider));
105
g_signal_emit (self, gSignals [PROVIDER_ADDED], 0, provider);
109
ide_search_engine_dispose (GObject *object)
111
IdeSearchEngine *self = (IdeSearchEngine *)object;
114
copy = self->providers;
115
self->providers = NULL;
116
g_list_foreach (copy, (GFunc)g_object_unref, NULL);
119
G_OBJECT_CLASS (ide_search_engine_parent_class)->dispose (object);
123
ide_search_engine_class_init (IdeSearchEngineClass *klass)
125
GObjectClass *object_class = G_OBJECT_CLASS (klass);
127
object_class->dispose = ide_search_engine_dispose;
129
gSignals [PROVIDER_ADDED] =
130
g_signal_new ("provider-added",
131
G_TYPE_FROM_CLASS (klass),
137
IDE_TYPE_SEARCH_PROVIDER);
141
ide_search_engine_init (IdeSearchEngine *self)