~ubuntu-branches/debian/stretch/gnome-builder/stretch

« back to all changes in this revision

Viewing changes to libide/ide-search-engine.c

  • Committer: Package Import Robot
  • Author(s): Andreas Henriksson
  • Date: 2015-10-11 12:38:45 UTC
  • Revision ID: package-import@ubuntu.com-20151011123845-a0hvkz01se0p1p5a
Tags: upstream-3.16.3
ImportĀ upstreamĀ versionĀ 3.16.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ide-search-engine.c
 
2
 *
 
3
 * Copyright (C) 2015 Christian Hergert <christian@hergert.me>
 
4
 *
 
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.
 
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
 
13
 * GNU General Public License for more details.
 
14
 *
 
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/>.
 
17
 */
 
18
 
 
19
#include <glib/gi18n.h>
 
20
 
 
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"
 
26
 
 
27
struct _IdeSearchEngine
 
28
{
 
29
  IdeObject  parent_instance;
 
30
  GList     *providers;
 
31
};
 
32
 
 
33
G_DEFINE_TYPE (IdeSearchEngine, ide_search_engine, IDE_TYPE_OBJECT)
 
34
 
 
35
enum {
 
36
  PROVIDER_ADDED,
 
37
  LAST_SIGNAL
 
38
};
 
39
 
 
40
static guint gSignals [LAST_SIGNAL];
 
41
 
 
42
/**
 
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.
 
47
 *
 
48
 * Begins a query against the requested search providers.
 
49
 *
 
50
 * If @providers is %NULL, all registered providers will be used.
 
51
 *
 
52
 * Returns: (transfer full) (nullable): An #IdeSearchContext or %NULL if no
 
53
 *   providers could be loaded.
 
54
 */
 
55
IdeSearchContext *
 
56
ide_search_engine_search (IdeSearchEngine *self,
 
57
                          const GList     *providers,
 
58
                          const gchar     *search_terms)
 
59
{
 
60
  IdeSearchContext *search_context;
 
61
  IdeContext *context;
 
62
  const GList *iter;
 
63
 
 
64
  g_return_val_if_fail (IDE_IS_SEARCH_ENGINE (self), NULL);
 
65
  g_return_val_if_fail (search_terms, NULL);
 
66
 
 
67
  if (!providers)
 
68
    providers = self->providers;
 
69
 
 
70
  context = ide_object_get_context (IDE_OBJECT (self));
 
71
  search_context = g_object_new (IDE_TYPE_SEARCH_CONTEXT,
 
72
                                 "context", context,
 
73
                                 NULL);
 
74
 
 
75
  for (iter = providers; iter; iter = iter->next)
 
76
    _ide_search_context_add_provider (search_context, iter->data, 0);
 
77
 
 
78
  return search_context;
 
79
}
 
80
 
 
81
/**
 
82
 * ide_search_engine_get_providers:
 
83
 *
 
84
 * Returns the list of registered search providers.
 
85
 *
 
86
 * Returns: (transfer none) (element-type IdeSearchProvider*): A #GList of
 
87
 *   #IdeSearchProvider.
 
88
 */
 
89
GList *
 
90
ide_search_engine_get_providers (IdeSearchEngine *self)
 
91
{
 
92
  g_return_val_if_fail (IDE_IS_SEARCH_ENGINE (self), NULL);
 
93
 
 
94
  return self->providers;
 
95
}
 
96
 
 
97
void
 
98
ide_search_engine_add_provider (IdeSearchEngine   *self,
 
99
                                IdeSearchProvider *provider)
 
100
{
 
101
  g_return_if_fail (IDE_IS_SEARCH_ENGINE (self));
 
102
  g_return_if_fail (IDE_IS_SEARCH_PROVIDER (provider));
 
103
 
 
104
  self->providers = g_list_append (self->providers, g_object_ref (provider));
 
105
  g_signal_emit (self, gSignals [PROVIDER_ADDED], 0, provider);
 
106
}
 
107
 
 
108
static void
 
109
ide_search_engine_dispose (GObject *object)
 
110
{
 
111
  IdeSearchEngine *self = (IdeSearchEngine *)object;
 
112
  GList *copy;
 
113
 
 
114
  copy = self->providers;
 
115
  self->providers = NULL;
 
116
  g_list_foreach (copy, (GFunc)g_object_unref, NULL);
 
117
  g_list_free (copy);
 
118
 
 
119
  G_OBJECT_CLASS (ide_search_engine_parent_class)->dispose (object);
 
120
}
 
121
 
 
122
static void
 
123
ide_search_engine_class_init (IdeSearchEngineClass *klass)
 
124
{
 
125
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
126
 
 
127
  object_class->dispose = ide_search_engine_dispose;
 
128
 
 
129
  gSignals [PROVIDER_ADDED] =
 
130
    g_signal_new ("provider-added",
 
131
                  G_TYPE_FROM_CLASS (klass),
 
132
                  G_SIGNAL_RUN_LAST,
 
133
                  0,
 
134
                  NULL, NULL, NULL,
 
135
                  G_TYPE_NONE,
 
136
                  1,
 
137
                  IDE_TYPE_SEARCH_PROVIDER);
 
138
}
 
139
 
 
140
static void
 
141
ide_search_engine_init (IdeSearchEngine *self)
 
142
{
 
143
}