summaryrefslogtreecommitdiffstats
path: root/app/plug-in/gimppluginmanager-help-domain.c
blob: 96ea41b62cda9f503796ec6001b694ef6bac8732 (plain)
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
/* GIMP - The GNU Image Manipulation Program
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 *
 * gimppluginmanager-help-domain.c
 *
 * This program 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 3 of the License, or
 * (at your option) any later version.
 *
 * This program 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, see <https://www.gnu.org/licenses/>.
 */

#include "config.h"

#include <string.h>

#include <gio/gio.h>

#include "plug-in-types.h"

#include "gimppluginmanager.h"
#include "gimppluginmanager-help-domain.h"


typedef struct _GimpPlugInHelpDomain GimpPlugInHelpDomain;

struct _GimpPlugInHelpDomain
{
  GFile *file;
  gchar *domain_name;
  gchar *domain_uri;
};


void
gimp_plug_in_manager_help_domain_exit (GimpPlugInManager *manager)
{
  GSList *list;

  g_return_if_fail (GIMP_IS_PLUG_IN_MANAGER (manager));

  for (list = manager->help_domains; list; list = list->next)
    {
      GimpPlugInHelpDomain *domain = list->data;

      g_object_unref (domain->file);
      g_free (domain->domain_name);
      g_free (domain->domain_uri);
      g_slice_free (GimpPlugInHelpDomain, domain);
    }

  g_slist_free (manager->help_domains);
  manager->help_domains = NULL;
}

void
gimp_plug_in_manager_add_help_domain (GimpPlugInManager *manager,
                                      GFile             *file,
                                      const gchar       *domain_name,
                                      const gchar       *domain_uri)
{
  GimpPlugInHelpDomain *domain;

  g_return_if_fail (GIMP_IS_PLUG_IN_MANAGER (manager));
  g_return_if_fail (G_IS_FILE (file));
  g_return_if_fail (domain_name != NULL);

  domain = g_slice_new (GimpPlugInHelpDomain);

  domain->file        = g_object_ref (file);
  domain->domain_name = g_strdup (domain_name);
  domain->domain_uri  = g_strdup (domain_uri);

  manager->help_domains = g_slist_prepend (manager->help_domains, domain);

#ifdef VERBOSE
  g_print ("added help domain \"%s\" for base uri \"%s\"\n",
           domain->domain_name ? domain->domain_name : "(null)",
           domain->domain_uri  ? domain->domain_uri  : "(null)");
#endif
}

const gchar *
gimp_plug_in_manager_get_help_domain (GimpPlugInManager  *manager,
                                      GFile              *file,
                                      const gchar       **domain_uri)
{
  GSList *list;

  g_return_val_if_fail (GIMP_IS_PLUG_IN_MANAGER (manager), NULL);
  g_return_val_if_fail (file == NULL || G_IS_FILE (file), NULL);

  if (domain_uri)
    *domain_uri = NULL;

  /*  A NULL prog_name is GIMP itself, return the default domain  */
  if (! file)
    return NULL;

  for (list = manager->help_domains; list; list = list->next)
    {
      GimpPlugInHelpDomain *domain = list->data;

      if (domain && domain->file &&
          g_file_equal (domain->file, file))
        {
          if (domain_uri && domain->domain_uri)
            *domain_uri = domain->domain_uri;

          return domain->domain_name;
        }
    }

  return NULL;
}

gint
gimp_plug_in_manager_get_help_domains (GimpPlugInManager   *manager,
                                       gchar             ***help_domains,
                                       gchar             ***help_uris)
{
  gint n_domains;

  g_return_val_if_fail (GIMP_IS_PLUG_IN_MANAGER (manager), 0);
  g_return_val_if_fail (help_domains != NULL, 0);
  g_return_val_if_fail (help_uris != NULL, 0);

  n_domains = g_slist_length (manager->help_domains);

  if (n_domains > 0)
    {
      GSList *list;
      gint    i;

      *help_domains = g_new0 (gchar *, n_domains + 1);
      *help_uris    = g_new0 (gchar *, n_domains + 1);

      for (list = manager->help_domains, i = 0; list; list = list->next, i++)
        {
          GimpPlugInHelpDomain *domain = list->data;

          (*help_domains)[i] = g_strdup (domain->domain_name);
          (*help_uris)[i]    = g_strdup (domain->domain_uri);
        }
    }
  else
    {
      *help_domains = NULL;
      *help_uris    = NULL;
    }

  return n_domains;
}