1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
|
/* pps-search-result.c
* this file is part of papers, a gnome document viewer
*
* Copyright (C) 2024 Markus Göllnitz <camelcasenick@bewares.it>
*
* Papers 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 of the License, or
* (at your option) any later version.
*
* Papers 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "pps-search-result.h"
#include <string.h>
typedef struct
{
gchar *markup;
gchar *label;
guint page;
guint index;
guint global_index;
GList *find_rectangles;
} PpsSearchResultPrivate;
G_DEFINE_TYPE_WITH_PRIVATE (PpsSearchResult, pps_search_result, G_TYPE_OBJECT)
#define GET_PRIVATE(o) pps_search_result_get_instance_private (o)
static void
pps_search_result_init (PpsSearchResult *self)
{
}
static void
pps_search_result_dispose (GObject *object)
{
PpsSearchResult *self = PPS_SEARCH_RESULT (object);
PpsSearchResultPrivate *priv = GET_PRIVATE (self);
g_clear_pointer (&priv->markup, g_free);
g_clear_pointer (&priv->label, g_free);
g_clear_list (&priv->find_rectangles, (GDestroyNotify) pps_find_rectangle_free);
G_OBJECT_CLASS (pps_search_result_parent_class)->dispose (object);
}
static void
pps_search_result_class_init (PpsSearchResultClass *result_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (result_class);
object_class->dispose = pps_search_result_dispose;
}
PpsSearchResult *
pps_search_result_new (gchar *markup,
gchar *label,
guint page,
guint index,
guint global_index,
PpsFindRectangle *rect)
{
PpsSearchResult *result = g_object_new (PPS_TYPE_SEARCH_RESULT, NULL);
PpsSearchResultPrivate *priv = GET_PRIVATE (result);
priv->markup = g_strdup (markup);
priv->label = g_strdup (label);
priv->page = page;
priv->index = index;
priv->global_index = global_index;
priv->find_rectangles = g_list_append (priv->find_rectangles,
pps_find_rectangle_copy (rect));
return result;
}
const gchar *
pps_search_result_get_markup (PpsSearchResult *self)
{
PpsSearchResultPrivate *priv = GET_PRIVATE (self);
return priv->markup;
}
const gchar *
pps_search_result_get_label (PpsSearchResult *self)
{
PpsSearchResultPrivate *priv = GET_PRIVATE (self);
return priv->label;
}
guint
pps_search_result_get_page (PpsSearchResult *self)
{
PpsSearchResultPrivate *priv = GET_PRIVATE (self);
return priv->page;
}
guint
pps_search_result_get_index (PpsSearchResult *self)
{
PpsSearchResultPrivate *priv = GET_PRIVATE (self);
return priv->index;
}
/**
* pps_search_result_get_global_index:
* @self: the PpsSearchResult
*
* Returns: the index of this result relative the complete result model.
*
* Since: 48.0
*/
guint
pps_search_result_get_global_index (PpsSearchResult *self)
{
PpsSearchResultPrivate *priv = GET_PRIVATE (self);
return priv->global_index;
}
/**
* pps_search_result_get_rectangle_list:
* @self: the PpsSearchResult
*
* Returns: (nullable) (transfer none) (element-type PpsFindRectangle): the
* list of rectangles for this result.
*/
GList *
pps_search_result_get_rectangle_list (PpsSearchResult *self)
{
PpsSearchResultPrivate *priv = GET_PRIVATE (self);
return priv->find_rectangles;
}
/**
* pps_search_result_append_rectangle:
* @self: the PpsSearchResult
* @rect: the #PpsFindRectangle to append
*
* Appends a rectangle to the search result. This should not be used outside the
* creation of the search result.
*/
void
pps_search_result_append_rectangle (PpsSearchResult *self, PpsFindRectangle *rect)
{
PpsSearchResultPrivate *priv = GET_PRIVATE (self);
priv->find_rectangles = g_list_append (priv->find_rectangles,
pps_find_rectangle_copy (rect));
}
|