Initial checkin of Pika from heckimp
This commit is contained in:
379
plug-ins/help/help.c
Normal file
379
plug-ins/help/help.c
Normal file
@ -0,0 +1,379 @@
|
||||
/* PIKA - Photo and Image Kooker Application
|
||||
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
|
||||
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
|
||||
*
|
||||
* Original copyright, applying to most contents (license remains unchanged):
|
||||
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
||||
*
|
||||
* The PIKA Help plug-in
|
||||
* Copyright (C) 1999-2008 Sven Neumann <sven@gimp.org>
|
||||
* Michael Natterer <mitch@gimp.org>
|
||||
* Henrik Brix Andersen <brix@gimp.org>
|
||||
*
|
||||
* 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> /* strlen */
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "libpika/pika.h"
|
||||
|
||||
#include "pikahelp.h"
|
||||
|
||||
#include "libpika/stdplugins-intl.h"
|
||||
|
||||
|
||||
/* defines */
|
||||
|
||||
#define PIKA_HELP_EXT_PROC "extension-pika-help"
|
||||
#define PIKA_HELP_TEMP_EXT_PROC "extension-pika-help-temp"
|
||||
|
||||
|
||||
typedef struct _Help Help;
|
||||
typedef struct _HelpClass HelpClass;
|
||||
|
||||
struct _Help
|
||||
{
|
||||
PikaPlugIn parent_instance;
|
||||
};
|
||||
|
||||
struct _HelpClass
|
||||
{
|
||||
PikaPlugInClass parent_class;
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
gchar *procedure;
|
||||
gchar *help_domain;
|
||||
gchar *help_locales;
|
||||
gchar *help_id;
|
||||
} IdleHelp;
|
||||
|
||||
|
||||
/* forward declarations */
|
||||
|
||||
#define HELP_TYPE (help_get_type ())
|
||||
#define HELP (obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), HELP_TYPE, Help))
|
||||
|
||||
GType help_get_type (void) G_GNUC_CONST;
|
||||
|
||||
static GList * help_query_procedures (PikaPlugIn *plug_in);
|
||||
static PikaProcedure * help_create_procedure (PikaPlugIn *plug_in,
|
||||
const gchar *name);
|
||||
|
||||
static PikaValueArray * help_run (PikaProcedure *procedure,
|
||||
const PikaValueArray *args,
|
||||
gpointer run_data);
|
||||
static PikaValueArray * help_temp_run (PikaProcedure *procedure,
|
||||
const PikaValueArray *args,
|
||||
gpointer run_data);
|
||||
|
||||
static void help_temp_proc_install (PikaPlugIn *plug_in);
|
||||
static void help_load (const gchar *procedure,
|
||||
const gchar *help_domain,
|
||||
const gchar *help_locales,
|
||||
const gchar *help_id);
|
||||
static gboolean help_load_idle (gpointer data);
|
||||
|
||||
static PikaHelpProgress * help_load_progress_new (void);
|
||||
|
||||
|
||||
static GMainLoop *main_loop = NULL;
|
||||
|
||||
G_DEFINE_TYPE (Help, help, PIKA_TYPE_PLUG_IN)
|
||||
|
||||
PIKA_MAIN (HELP_TYPE)
|
||||
DEFINE_STD_SET_I18N
|
||||
|
||||
|
||||
static void
|
||||
help_class_init (HelpClass *klass)
|
||||
{
|
||||
PikaPlugInClass *plug_in_class = PIKA_PLUG_IN_CLASS (klass);
|
||||
|
||||
plug_in_class->query_procedures = help_query_procedures;
|
||||
plug_in_class->create_procedure = help_create_procedure;
|
||||
plug_in_class->set_i18n = STD_SET_I18N;
|
||||
}
|
||||
|
||||
static void
|
||||
help_init (Help *help)
|
||||
{
|
||||
}
|
||||
|
||||
static GList *
|
||||
help_query_procedures (PikaPlugIn *plug_in)
|
||||
{
|
||||
return g_list_append (NULL, g_strdup (PIKA_HELP_EXT_PROC));
|
||||
}
|
||||
|
||||
static PikaProcedure *
|
||||
help_create_procedure (PikaPlugIn *plug_in,
|
||||
const gchar *name)
|
||||
{
|
||||
PikaProcedure *procedure = NULL;
|
||||
|
||||
if (! strcmp (name, PIKA_HELP_EXT_PROC))
|
||||
{
|
||||
procedure = pika_procedure_new (plug_in, name,
|
||||
PIKA_PDB_PROC_TYPE_EXTENSION,
|
||||
help_run, NULL, NULL);
|
||||
|
||||
pika_procedure_set_attribution (procedure,
|
||||
"Sven Neumann <sven@gimp.org>, "
|
||||
"Michael Natterer <mitch@gimp.org>, "
|
||||
"Henrik Brix Andersen <brix@gimp.org>",
|
||||
"Sven Neumann, Michael Natterer & Henrik Brix Andersen",
|
||||
"1999-2008");
|
||||
|
||||
PIKA_PROC_ARG_STRV (procedure, "domain-names",
|
||||
"Domain Names",
|
||||
"Domain names",
|
||||
G_PARAM_READWRITE);
|
||||
|
||||
PIKA_PROC_ARG_STRV (procedure, "domain-uris",
|
||||
"Domain URIs",
|
||||
"Domain URIs",
|
||||
G_PARAM_READWRITE);
|
||||
}
|
||||
|
||||
return procedure;
|
||||
}
|
||||
|
||||
static PikaValueArray *
|
||||
help_run (PikaProcedure *procedure,
|
||||
const PikaValueArray *args,
|
||||
gpointer run_data)
|
||||
{
|
||||
PikaPDBStatusType status = PIKA_PDB_SUCCESS;
|
||||
|
||||
if (! pika_help_init (PIKA_VALUES_GET_STRV (args, 0),
|
||||
PIKA_VALUES_GET_STRV (args, 1)))
|
||||
{
|
||||
status = PIKA_PDB_CALLING_ERROR;
|
||||
}
|
||||
|
||||
if (status == PIKA_PDB_SUCCESS)
|
||||
{
|
||||
PikaPlugIn *plug_in = pika_procedure_get_plug_in (procedure);
|
||||
|
||||
main_loop = g_main_loop_new (NULL, FALSE);
|
||||
|
||||
help_temp_proc_install (plug_in);
|
||||
|
||||
pika_procedure_extension_ready (procedure);
|
||||
pika_plug_in_extension_enable (plug_in);
|
||||
|
||||
g_main_loop_run (main_loop);
|
||||
|
||||
g_main_loop_unref (main_loop);
|
||||
main_loop = NULL;
|
||||
|
||||
pika_plug_in_remove_temp_procedure (plug_in, PIKA_HELP_TEMP_EXT_PROC);
|
||||
}
|
||||
|
||||
return pika_procedure_new_return_values (procedure, status, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
help_temp_proc_install (PikaPlugIn *plug_in)
|
||||
{
|
||||
PikaProcedure *procedure;
|
||||
|
||||
procedure = pika_procedure_new (plug_in, PIKA_HELP_TEMP_EXT_PROC,
|
||||
PIKA_PDB_PROC_TYPE_TEMPORARY,
|
||||
help_temp_run, NULL, NULL);
|
||||
|
||||
pika_procedure_set_attribution (procedure,
|
||||
"Sven Neumann <sven@gimp.org>, "
|
||||
"Michael Natterer <mitch@gimp.org>"
|
||||
"Henrik Brix Andersen <brix@gimp.org",
|
||||
"Sven Neumann, Michael Natterer & "
|
||||
"Henrik Brix Andersen",
|
||||
"1999-2008");
|
||||
|
||||
PIKA_PROC_ARG_STRING (procedure, "help-proc",
|
||||
"The procedure of the browser to use",
|
||||
"The procedure of the browser to use",
|
||||
NULL,
|
||||
G_PARAM_READWRITE);
|
||||
|
||||
PIKA_PROC_ARG_STRING (procedure, "help-domain",
|
||||
"Help domain to use",
|
||||
"Help domain to use",
|
||||
NULL,
|
||||
G_PARAM_READWRITE);
|
||||
|
||||
PIKA_PROC_ARG_STRING (procedure, "help-locales",
|
||||
"Language to use",
|
||||
"Language to use",
|
||||
NULL,
|
||||
G_PARAM_READWRITE);
|
||||
|
||||
PIKA_PROC_ARG_STRING (procedure, "help-id",
|
||||
"Help ID to open",
|
||||
"Help ID to open",
|
||||
NULL,
|
||||
G_PARAM_READWRITE);
|
||||
|
||||
pika_plug_in_add_temp_procedure (plug_in, procedure);
|
||||
g_object_unref (procedure);
|
||||
}
|
||||
|
||||
static PikaValueArray *
|
||||
help_temp_run (PikaProcedure *procedure,
|
||||
const PikaValueArray *args,
|
||||
gpointer run_data)
|
||||
{
|
||||
PikaPDBStatusType status = PIKA_PDB_SUCCESS;
|
||||
const gchar *help_proc = NULL;
|
||||
const gchar *help_domain = PIKA_HELP_DEFAULT_DOMAIN;
|
||||
const gchar *help_locales = NULL;
|
||||
const gchar *help_id = PIKA_HELP_DEFAULT_ID;
|
||||
|
||||
if (PIKA_VALUES_GET_STRING (args, 0))
|
||||
help_proc = PIKA_VALUES_GET_STRING (args, 0);
|
||||
|
||||
if (PIKA_VALUES_GET_STRING (args, 1))
|
||||
help_domain = PIKA_VALUES_GET_STRING (args, 1);
|
||||
|
||||
if (PIKA_VALUES_GET_STRING (args, 2))
|
||||
help_locales = PIKA_VALUES_GET_STRING (args, 2);
|
||||
|
||||
if (PIKA_VALUES_GET_STRING (args, 3))
|
||||
help_id = PIKA_VALUES_GET_STRING (args, 3);
|
||||
|
||||
if (! help_proc)
|
||||
status = PIKA_PDB_CALLING_ERROR;
|
||||
|
||||
if (status == PIKA_PDB_SUCCESS)
|
||||
help_load (help_proc, help_domain, help_locales, help_id);
|
||||
|
||||
return pika_procedure_new_return_values (procedure, status, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
help_load (const gchar *procedure,
|
||||
const gchar *help_domain,
|
||||
const gchar *help_locales,
|
||||
const gchar *help_id)
|
||||
{
|
||||
IdleHelp *idle_help = g_slice_new (IdleHelp);
|
||||
|
||||
idle_help->procedure = g_strdup (procedure);
|
||||
idle_help->help_domain = g_strdup (help_domain);
|
||||
idle_help->help_locales = g_strdup (help_locales);
|
||||
idle_help->help_id = g_strdup (help_id);
|
||||
|
||||
g_idle_add (help_load_idle, idle_help);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
help_load_idle (gpointer data)
|
||||
{
|
||||
IdleHelp *idle_help = data;
|
||||
PikaHelpDomain *domain;
|
||||
|
||||
domain = pika_help_lookup_domain (idle_help->help_domain);
|
||||
|
||||
if (domain)
|
||||
{
|
||||
PikaHelpProgress *progress = NULL;
|
||||
GList *locales;
|
||||
gchar *uri;
|
||||
gboolean fatal_error;
|
||||
|
||||
locales = pika_help_parse_locales (idle_help->help_locales);
|
||||
|
||||
if (! g_str_has_prefix (domain->help_uri, "file:"))
|
||||
progress = help_load_progress_new ();
|
||||
|
||||
uri = pika_help_domain_map (domain, locales, idle_help->help_id,
|
||||
progress, NULL, &fatal_error);
|
||||
|
||||
if (progress)
|
||||
pika_help_progress_free (progress);
|
||||
|
||||
g_list_free_full (locales, (GDestroyNotify) g_free);
|
||||
|
||||
if (uri)
|
||||
{
|
||||
PikaValueArray *return_vals;
|
||||
|
||||
#ifdef PIKA_HELP_DEBUG
|
||||
g_printerr ("help: calling '%s' for '%s'\n",
|
||||
idle_help->procedure, uri);
|
||||
#endif
|
||||
|
||||
return_vals = pika_pdb_run_procedure (pika_get_pdb (),
|
||||
idle_help->procedure,
|
||||
G_TYPE_STRING, uri,
|
||||
G_TYPE_NONE);
|
||||
pika_value_array_unref (return_vals);
|
||||
|
||||
g_free (uri);
|
||||
}
|
||||
else if (fatal_error)
|
||||
{
|
||||
g_main_loop_quit (main_loop);
|
||||
}
|
||||
}
|
||||
|
||||
g_free (idle_help->procedure);
|
||||
g_free (idle_help->help_domain);
|
||||
g_free (idle_help->help_locales);
|
||||
g_free (idle_help->help_id);
|
||||
|
||||
g_slice_free (IdleHelp, idle_help);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
help_load_progress_start (const gchar *message,
|
||||
gboolean cancelable,
|
||||
gpointer user_data)
|
||||
{
|
||||
pika_progress_init (message);
|
||||
}
|
||||
|
||||
static void
|
||||
help_load_progress_update (gdouble value,
|
||||
gpointer user_data)
|
||||
{
|
||||
pika_progress_update (value);
|
||||
}
|
||||
|
||||
static void
|
||||
help_load_progress_end (gpointer user_data)
|
||||
{
|
||||
pika_progress_end ();
|
||||
}
|
||||
|
||||
static PikaHelpProgress *
|
||||
help_load_progress_new (void)
|
||||
{
|
||||
static const PikaHelpProgressVTable vtable =
|
||||
{
|
||||
help_load_progress_start,
|
||||
help_load_progress_end,
|
||||
help_load_progress_update
|
||||
};
|
||||
|
||||
return pika_help_progress_new (&vtable, NULL);
|
||||
}
|
76
plug-ins/help/locales.c
Normal file
76
plug-ins/help/locales.c
Normal file
@ -0,0 +1,76 @@
|
||||
/* PIKA - Photo and Image Kooker Application
|
||||
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
|
||||
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
|
||||
*
|
||||
* Original copyright, applying to most contents (license remains unchanged):
|
||||
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
||||
*
|
||||
* The PIKA Help plug-in
|
||||
* Copyright (C) 1999-2008 Sven Neumann <sven@gimp.org>
|
||||
* Michael Natterer <mitch@gimp.org>
|
||||
* Henrik Brix Andersen <brix@gimp.org>
|
||||
*
|
||||
* 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 <glib.h>
|
||||
|
||||
#include "help.h"
|
||||
#include "locales.h"
|
||||
|
||||
|
||||
GList *
|
||||
locales_parse (const gchar *help_locales)
|
||||
{
|
||||
GList *locales = NULL;
|
||||
GList *list;
|
||||
const gchar *s;
|
||||
const gchar *p;
|
||||
|
||||
g_return_val_if_fail (help_locales != NULL, NULL);
|
||||
|
||||
/* split the string at colons, building a list */
|
||||
s = help_locales;
|
||||
for (p = strchr (s, ':'); p; p = strchr (s, ':'))
|
||||
{
|
||||
gchar *new = g_strndup (s, p - s);
|
||||
|
||||
locales = g_list_append (locales, new);
|
||||
s = p + 1;
|
||||
}
|
||||
|
||||
if (*s)
|
||||
locales = g_list_append (locales, g_strdup (s));
|
||||
|
||||
/* if the list doesn't contain the default domain yet, append it */
|
||||
for (list = locales; list; list = list->next)
|
||||
if (strcmp ((const gchar *) list->data, PIKA_HELP_DEFAULT_LOCALE) == 0)
|
||||
break;
|
||||
|
||||
if (! list)
|
||||
locales = g_list_append (locales, g_strdup (PIKA_HELP_DEFAULT_LOCALE));
|
||||
|
||||
#ifdef PIKA_HELP_DEBUG
|
||||
g_printerr ("help: locales: ");
|
||||
for (list = locales; list; list = list->next)
|
||||
g_printerr ("%s ", (const gchar *) list->data);
|
||||
g_printerr ("\n");
|
||||
#endif
|
||||
|
||||
return locales;
|
||||
}
|
35
plug-ins/help/locales.h
Normal file
35
plug-ins/help/locales.h
Normal file
@ -0,0 +1,35 @@
|
||||
/* PIKA - Photo and Image Kooker Application
|
||||
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
|
||||
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
|
||||
*
|
||||
* Original copyright, applying to most contents (license remains unchanged):
|
||||
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
||||
*
|
||||
* The PIKA Help plug-in
|
||||
* Copyright (C) 1999-2008 Sven Neumann <sven@gimp.org>
|
||||
* Michael Natterer <mitch@gimp.org>
|
||||
* Henrik Brix Andersen <brix@gimp.org>
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef __LOCALES_H__
|
||||
#define __LOCALES_H__
|
||||
|
||||
|
||||
GList * locales_parse (const gchar *help_locales);
|
||||
|
||||
|
||||
#endif /* ! __LOCALES_H__ */
|
||||
|
47
plug-ins/help/meson.build
Normal file
47
plug-ins/help/meson.build
Normal file
@ -0,0 +1,47 @@
|
||||
plugin_name = 'help'
|
||||
|
||||
plugin_sources = [
|
||||
# 'pika-help-lookup.c',
|
||||
'pikahelp.c',
|
||||
'pikahelpdomain.c',
|
||||
'pikahelpitem.c',
|
||||
'pikahelplocale.c',
|
||||
'pikahelpprogress.c',
|
||||
]
|
||||
|
||||
if platform_windows
|
||||
plugin_sources += windows.compile_resources(
|
||||
pika_plugins_rc,
|
||||
args: [
|
||||
'--define', 'ORIGINALFILENAME_STR="@0@"'.format(plugin_name+'.exe'),
|
||||
'--define', 'INTERNALNAME_STR="@0@"' .format(plugin_name),
|
||||
'--define', 'TOP_SRCDIR="@0@"' .format(meson.project_source_root()),
|
||||
],
|
||||
include_directories: [
|
||||
rootInclude, appInclude,
|
||||
],
|
||||
)
|
||||
endif
|
||||
|
||||
help_plugin_lib = static_library('help_plugin',
|
||||
plugin_sources,
|
||||
include_directories: [ rootInclude, ],
|
||||
dependencies: [
|
||||
gtk3, gegl, cairo, gio, gdk_pixbuf,
|
||||
],
|
||||
install: false,
|
||||
)
|
||||
|
||||
executable(plugin_name,
|
||||
'help.c',
|
||||
dependencies: [
|
||||
libpikaui_dep,
|
||||
gio,
|
||||
gdk_pixbuf,
|
||||
],
|
||||
link_with: [
|
||||
help_plugin_lib,
|
||||
],
|
||||
install: true,
|
||||
install_dir: pikaplugindir / 'plug-ins' / plugin_name,
|
||||
)
|
199
plug-ins/help/pika-help-lookup.c
Normal file
199
plug-ins/help/pika-help-lookup.c
Normal file
@ -0,0 +1,199 @@
|
||||
/* PIKA - Photo and Image Kooker Application
|
||||
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
|
||||
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
|
||||
*
|
||||
* Original copyright, applying to most contents (license remains unchanged):
|
||||
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
||||
*
|
||||
* pika-help-lookup - a standalone pika-help ID to filename mapper
|
||||
* Copyright (C) 2004-2008 Sven Neumann <sven@gimp.org>
|
||||
*
|
||||
* 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 <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "libpika/pika.h"
|
||||
|
||||
#include "pikahelp.h"
|
||||
|
||||
|
||||
static void show_version (void) G_GNUC_NORETURN;
|
||||
|
||||
static gchar * lookup (const gchar *help_domain,
|
||||
const gchar *help_locales,
|
||||
const gchar *help_id);
|
||||
|
||||
static PikaHelpProgress * progress_new (void);
|
||||
|
||||
|
||||
static const gchar *help_base = NULL;
|
||||
static gchar *help_root = NULL;
|
||||
static const gchar *help_locales = NULL;
|
||||
static const gchar **help_ids = NULL;
|
||||
|
||||
static gboolean be_verbose = FALSE;
|
||||
|
||||
|
||||
static const GOptionEntry entries[] =
|
||||
{
|
||||
{ "version", 'v', 0,
|
||||
G_OPTION_ARG_CALLBACK, (GOptionArgFunc) show_version,
|
||||
"Show version information and exit", NULL
|
||||
},
|
||||
{ "base", 'b', 0,
|
||||
G_OPTION_ARG_STRING, &help_base,
|
||||
"Specifies base URI", "URI"
|
||||
},
|
||||
{ "root", 'r', 0,
|
||||
G_OPTION_ARG_FILENAME, &help_root,
|
||||
"Specifies root directory for index files", "DIR"
|
||||
},
|
||||
{ "lang", 'l', 0,
|
||||
G_OPTION_ARG_STRING, &help_locales,
|
||||
"Specifies help language", "LANG"
|
||||
},
|
||||
{
|
||||
"verbose", 0, 0,
|
||||
G_OPTION_ARG_NONE, &be_verbose,
|
||||
"Be more verbose", NULL
|
||||
},
|
||||
{
|
||||
G_OPTION_REMAINING, 0, 0,
|
||||
G_OPTION_ARG_STRING_ARRAY, &help_ids,
|
||||
NULL, NULL
|
||||
},
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
|
||||
gint
|
||||
main (gint argc,
|
||||
gchar *argv[])
|
||||
{
|
||||
GOptionContext *context;
|
||||
gchar *uri;
|
||||
GError *error = NULL;
|
||||
|
||||
help_base = g_getenv (PIKA_HELP_ENV_URI);
|
||||
help_root = g_build_filename (pika_data_directory (), PIKA_HELP_PREFIX, NULL);
|
||||
|
||||
context = g_option_context_new ("HELP-ID");
|
||||
g_option_context_add_main_entries (context, entries, NULL);
|
||||
|
||||
if (! g_option_context_parse (context, &argc, &argv, &error))
|
||||
{
|
||||
g_print ("%s\n", error->message);
|
||||
g_error_free (error);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (help_base)
|
||||
uri = g_strdup (help_base);
|
||||
else
|
||||
uri = g_filename_to_uri (help_root, NULL, NULL);
|
||||
|
||||
pika_help_register_domain (PIKA_HELP_DEFAULT_DOMAIN, uri);
|
||||
g_free (uri);
|
||||
|
||||
uri = lookup (PIKA_HELP_DEFAULT_DOMAIN,
|
||||
help_locales ? help_locales : PIKA_HELP_DEFAULT_LOCALE,
|
||||
help_ids ? help_ids[0] : PIKA_HELP_DEFAULT_ID);
|
||||
|
||||
if (uri)
|
||||
{
|
||||
g_print ("%s\n", uri);
|
||||
g_free (uri);
|
||||
}
|
||||
|
||||
g_option_context_free (context);
|
||||
g_free (help_root);
|
||||
|
||||
return uri ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
}
|
||||
|
||||
static gchar *
|
||||
lookup (const gchar *help_domain,
|
||||
const gchar *help_locales,
|
||||
const gchar *help_id)
|
||||
{
|
||||
PikaHelpDomain *domain = pika_help_lookup_domain (help_domain);
|
||||
|
||||
if (domain)
|
||||
{
|
||||
PikaHelpProgress *progress = progress_new ();
|
||||
GList *locales;
|
||||
gchar *full_uri;
|
||||
|
||||
locales = pika_help_parse_locales (help_locales);
|
||||
full_uri = pika_help_domain_map (domain, locales, help_id, progress,
|
||||
NULL, NULL);
|
||||
|
||||
pika_help_progress_free (progress);
|
||||
|
||||
g_list_free_full (locales, (GDestroyNotify) g_free);
|
||||
|
||||
return full_uri;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
show_version (void)
|
||||
{
|
||||
g_print ("pika-help-lookup version %s\n", PIKA_VERSION);
|
||||
exit (EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
progress_start (const gchar *message,
|
||||
gboolean cancelable,
|
||||
gpointer user_data)
|
||||
{
|
||||
if (be_verbose)
|
||||
g_printerr ("\n%s\n", message);
|
||||
}
|
||||
|
||||
static void
|
||||
progress_end (gpointer user_data)
|
||||
{
|
||||
if (be_verbose)
|
||||
g_printerr ("done\n");
|
||||
}
|
||||
|
||||
static void
|
||||
progress_set_value (gdouble percentage,
|
||||
gpointer user_data)
|
||||
{
|
||||
if (be_verbose)
|
||||
g_printerr (".");
|
||||
}
|
||||
|
||||
static PikaHelpProgress *
|
||||
progress_new (void)
|
||||
{
|
||||
const PikaHelpProgressVTable vtable =
|
||||
{
|
||||
progress_start,
|
||||
progress_end,
|
||||
progress_set_value
|
||||
};
|
||||
|
||||
return pika_help_progress_new (&vtable, NULL);
|
||||
}
|
156
plug-ins/help/pikahelp.c
Normal file
156
plug-ins/help/pikahelp.c
Normal file
@ -0,0 +1,156 @@
|
||||
/* PIKA - Photo and Image Kooker Application
|
||||
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
|
||||
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
|
||||
*
|
||||
* Original copyright, applying to most contents (license remains unchanged):
|
||||
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
||||
*
|
||||
* The PIKA Help plug-in
|
||||
* Copyright (C) 1999-2008 Sven Neumann <sven@gimp.org>
|
||||
* Michael Natterer <mitch@gimp.org>
|
||||
* Henrik Brix Andersen <brix@gimp.org>
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/* This code is written so that it can also be compiled standalone.
|
||||
* It shouldn't depend on libpika.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "libpika/pika.h"
|
||||
|
||||
#include "pikahelp.h"
|
||||
|
||||
#ifdef DISABLE_NLS
|
||||
#define _(String) (String)
|
||||
#else
|
||||
#include "libpika/stdplugins-intl.h"
|
||||
#endif
|
||||
|
||||
|
||||
/* private variables */
|
||||
|
||||
static GHashTable *domain_hash = NULL;
|
||||
|
||||
|
||||
/* public functions */
|
||||
|
||||
gboolean
|
||||
pika_help_init (const gchar **domain_names,
|
||||
const gchar **domain_uris)
|
||||
{
|
||||
gint i;
|
||||
guint num_domain_names, num_domain_uris;
|
||||
|
||||
num_domain_names = domain_names? g_strv_length ((gchar **) domain_names) : 0;
|
||||
num_domain_uris = domain_uris? g_strv_length ((gchar **) domain_uris) : 0;
|
||||
if (num_domain_names != num_domain_uris)
|
||||
{
|
||||
g_printerr ("help: number of names doesn't match number of URIs.\n");
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
for (i = 0; i < num_domain_names; i++)
|
||||
pika_help_register_domain (domain_names[i], domain_uris[i]);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
pika_help_exit (void)
|
||||
{
|
||||
if (domain_hash)
|
||||
{
|
||||
g_hash_table_destroy (domain_hash);
|
||||
domain_hash = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
pika_help_register_domain (const gchar *domain_name,
|
||||
const gchar *domain_uri)
|
||||
{
|
||||
g_return_if_fail (domain_name != NULL);
|
||||
g_return_if_fail (domain_uri != NULL);
|
||||
|
||||
#ifdef PIKA_HELP_DEBUG
|
||||
g_printerr ("help: registering help domain \"%s\" with base uri \"%s\"\n",
|
||||
domain_name, domain_uri);
|
||||
#endif
|
||||
|
||||
if (! domain_hash)
|
||||
domain_hash = g_hash_table_new_full (g_str_hash, g_str_equal,
|
||||
g_free,
|
||||
(GDestroyNotify) pika_help_domain_free);
|
||||
|
||||
g_hash_table_insert (domain_hash,
|
||||
g_strdup (domain_name),
|
||||
pika_help_domain_new (domain_name, domain_uri));
|
||||
}
|
||||
|
||||
PikaHelpDomain *
|
||||
pika_help_lookup_domain (const gchar *domain_name)
|
||||
{
|
||||
g_return_val_if_fail (domain_name, NULL);
|
||||
|
||||
if (domain_hash)
|
||||
return g_hash_table_lookup (domain_hash, domain_name);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GList *
|
||||
pika_help_parse_locales (const gchar *help_locales)
|
||||
{
|
||||
GList *locales = NULL;
|
||||
GList *list;
|
||||
const gchar *s;
|
||||
const gchar *p;
|
||||
|
||||
g_return_val_if_fail (help_locales != NULL, NULL);
|
||||
|
||||
/* split the string at colons, building a list */
|
||||
s = help_locales;
|
||||
for (p = strchr (s, ':'); p; p = strchr (s, ':'))
|
||||
{
|
||||
gchar *new = g_strndup (s, p - s);
|
||||
locales = g_list_append (locales, new);
|
||||
s = p + 1;
|
||||
}
|
||||
|
||||
if (*s)
|
||||
locales = g_list_append (locales, g_strdup (s));
|
||||
|
||||
/* if the list doesn't contain the default locale yet, append it */
|
||||
for (list = locales; list; list = list->next)
|
||||
if (strcmp ((const gchar *) list->data, PIKA_HELP_DEFAULT_LOCALE) == 0)
|
||||
break;
|
||||
|
||||
if (! list)
|
||||
locales = g_list_append (locales, g_strdup (PIKA_HELP_DEFAULT_LOCALE));
|
||||
|
||||
#ifdef PIKA_HELP_DEBUG
|
||||
g_printerr ("help: locales: ");
|
||||
for (list = locales; list; list = list->next)
|
||||
g_printerr ("%s ", (const gchar *) list->data);
|
||||
g_printerr ("\n");
|
||||
#endif
|
||||
|
||||
return locales;
|
||||
}
|
60
plug-ins/help/pikahelp.h
Normal file
60
plug-ins/help/pikahelp.h
Normal file
@ -0,0 +1,60 @@
|
||||
/* PIKA - Photo and Image Kooker Application
|
||||
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
|
||||
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
|
||||
*
|
||||
* Original copyright, applying to most contents (license remains unchanged):
|
||||
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
||||
*
|
||||
* The PIKA Help plug-in
|
||||
* Copyright (C) 1999-2008 Sven Neumann <sven@gimp.org>
|
||||
* Michael Natterer <mitch@gimp.org>
|
||||
* Henrik Brix Andersen <brix@gimp.org>
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef __PIKA_HELP_H__
|
||||
#define __PIKA_HELP_H__
|
||||
|
||||
|
||||
#include "pikahelptypes.h"
|
||||
|
||||
#include "pikahelpdomain.h"
|
||||
#include "pikahelpitem.h"
|
||||
#include "pikahelplocale.h"
|
||||
#include "pikahelpprogress.h"
|
||||
|
||||
|
||||
#define PIKA_HELP_DEFAULT_DOMAIN "https://heckin.technology/AlderconeStudio/PIKApp/help"
|
||||
#define PIKA_HELP_DEFAULT_ID "pika-main"
|
||||
#define PIKA_HELP_DEFAULT_LOCALE "en"
|
||||
|
||||
#define PIKA_HELP_PREFIX "help"
|
||||
#define PIKA_HELP_ENV_URI "PIKA2_HELP_URI"
|
||||
|
||||
/* #define PIKA_HELP_DEBUG */
|
||||
|
||||
|
||||
gboolean pika_help_init (const gchar **domain_names,
|
||||
const gchar **domain_uris);
|
||||
void pika_help_exit (void);
|
||||
|
||||
void pika_help_register_domain (const gchar *domain_name,
|
||||
const gchar *domain_uri);
|
||||
PikaHelpDomain * pika_help_lookup_domain (const gchar *domain_name);
|
||||
|
||||
GList * pika_help_parse_locales (const gchar *help_locales);
|
||||
|
||||
|
||||
#endif /* ! __PIKA_HELP_H__ */
|
257
plug-ins/help/pikahelpdomain.c
Normal file
257
plug-ins/help/pikahelpdomain.c
Normal file
@ -0,0 +1,257 @@
|
||||
/* PIKA - Photo and Image Kooker Application
|
||||
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
|
||||
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
|
||||
*
|
||||
* Original copyright, applying to most contents (license remains unchanged):
|
||||
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
||||
*
|
||||
* The PIKA Help plug-in
|
||||
* Copyright (C) 1999-2008 Sven Neumann <sven@gimp.org>
|
||||
* Michael Natterer <mitch@gimp.org>
|
||||
* Henrik Brix Andersen <brix@gimp.org>
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/* This code is written so that it can also be compiled standalone.
|
||||
* It shouldn't depend on libpika.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <glib-object.h>
|
||||
#include <gio/gio.h>
|
||||
|
||||
#include "libpikabase/pikabase.h"
|
||||
|
||||
#include "pikahelp.h"
|
||||
|
||||
#ifdef DISABLE_NLS
|
||||
#define _(String) (String)
|
||||
#else
|
||||
#include "libpika/stdplugins-intl.h"
|
||||
#endif
|
||||
|
||||
|
||||
/* local function prototypes */
|
||||
|
||||
static gboolean domain_locale_parse (PikaHelpDomain *domain,
|
||||
PikaHelpLocale *locale,
|
||||
PikaHelpProgress *progress,
|
||||
GError **error);
|
||||
|
||||
|
||||
/* public functions */
|
||||
|
||||
PikaHelpDomain *
|
||||
pika_help_domain_new (const gchar *domain_name,
|
||||
const gchar *domain_uri)
|
||||
{
|
||||
PikaHelpDomain *domain = g_slice_new0 (PikaHelpDomain);
|
||||
|
||||
domain->help_domain = g_strdup (domain_name);
|
||||
domain->help_uri = g_strdup (domain_uri);
|
||||
|
||||
if (domain_uri)
|
||||
{
|
||||
/* strip trailing slash */
|
||||
if (g_str_has_suffix (domain->help_uri, "/"))
|
||||
domain->help_uri[strlen (domain->help_uri) - 1] = '\0';
|
||||
}
|
||||
|
||||
return domain;
|
||||
}
|
||||
|
||||
void
|
||||
pika_help_domain_free (PikaHelpDomain *domain)
|
||||
{
|
||||
g_return_if_fail (domain != NULL);
|
||||
|
||||
if (domain->help_locales)
|
||||
g_hash_table_destroy (domain->help_locales);
|
||||
|
||||
g_free (domain->help_domain);
|
||||
g_free (domain->help_uri);
|
||||
|
||||
g_slice_free (PikaHelpDomain, domain);
|
||||
}
|
||||
|
||||
PikaHelpLocale *
|
||||
pika_help_domain_lookup_locale (PikaHelpDomain *domain,
|
||||
const gchar *locale_id,
|
||||
PikaHelpProgress *progress)
|
||||
{
|
||||
PikaHelpLocale *locale = NULL;
|
||||
|
||||
if (domain->help_locales)
|
||||
locale = g_hash_table_lookup (domain->help_locales, locale_id);
|
||||
else
|
||||
domain->help_locales =
|
||||
g_hash_table_new_full (g_str_hash, g_str_equal,
|
||||
g_free,
|
||||
(GDestroyNotify) pika_help_locale_free);
|
||||
|
||||
if (locale)
|
||||
return locale;
|
||||
|
||||
locale = pika_help_locale_new (locale_id);
|
||||
g_hash_table_insert (domain->help_locales, g_strdup (locale_id), locale);
|
||||
|
||||
domain_locale_parse (domain, locale, progress, NULL);
|
||||
|
||||
return locale;
|
||||
}
|
||||
|
||||
gchar *
|
||||
pika_help_domain_map (PikaHelpDomain *domain,
|
||||
GList *help_locales,
|
||||
const gchar *help_id,
|
||||
PikaHelpProgress *progress,
|
||||
PikaHelpLocale **ret_locale,
|
||||
gboolean *fatal_error)
|
||||
{
|
||||
PikaHelpLocale *locale = NULL;
|
||||
const gchar *ref = NULL;
|
||||
GList *list;
|
||||
|
||||
g_return_val_if_fail (domain != NULL, NULL);
|
||||
g_return_val_if_fail (help_locales != NULL, NULL);
|
||||
g_return_val_if_fail (help_id != NULL, NULL);
|
||||
|
||||
if (fatal_error)
|
||||
*fatal_error = FALSE;
|
||||
|
||||
/* first pass: look for a reference matching the help_id */
|
||||
for (list = help_locales; list && !ref; list = list->next)
|
||||
{
|
||||
locale = pika_help_domain_lookup_locale (domain,
|
||||
(const gchar *) list->data,
|
||||
progress);
|
||||
ref = pika_help_locale_map (locale, help_id);
|
||||
}
|
||||
|
||||
/* second pass: look for a fallback */
|
||||
for (list = help_locales; list && !ref; list = list->next)
|
||||
{
|
||||
locale = pika_help_domain_lookup_locale (domain,
|
||||
(const gchar *) list->data,
|
||||
progress);
|
||||
ref = locale->help_missing;
|
||||
}
|
||||
|
||||
if (ret_locale)
|
||||
*ret_locale = locale;
|
||||
|
||||
if (ref)
|
||||
{
|
||||
return g_strconcat (domain->help_uri, "/",
|
||||
locale->locale_id, "/",
|
||||
ref,
|
||||
NULL);
|
||||
}
|
||||
else /* try to assemble a useful error message */
|
||||
{
|
||||
GError *error = NULL;
|
||||
|
||||
#ifdef PIKA_HELP_DEBUG
|
||||
g_printerr ("help: help_id lookup and all fallbacks failed for '%s'\n",
|
||||
help_id);
|
||||
#endif
|
||||
|
||||
locale = pika_help_domain_lookup_locale (domain,
|
||||
PIKA_HELP_DEFAULT_LOCALE, NULL);
|
||||
|
||||
if (! domain_locale_parse (domain, locale, NULL, &error))
|
||||
{
|
||||
switch (error->code)
|
||||
{
|
||||
case G_IO_ERROR_NOT_FOUND:
|
||||
if (domain->help_domain)
|
||||
{
|
||||
g_message (_("The help pages for '%s' are not available."),
|
||||
domain->help_domain);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_message ("%s\n\n%s",
|
||||
_("The PIKA user manual is not available."),
|
||||
/* TRANSLATORS: do not end the URL with a dot,
|
||||
* it would be in the link. Because of
|
||||
* technical limitations, make sure the URL
|
||||
* ends with a space, a newline or is end of text.
|
||||
* Cf. bug 762282.
|
||||
*/
|
||||
_("Please install the additional help package "
|
||||
"or use the online user manual at: "
|
||||
"https://docs.pika.org/"));
|
||||
}
|
||||
break;
|
||||
|
||||
case G_IO_ERROR_NOT_SUPPORTED:
|
||||
g_message ("%s\n\n%s",
|
||||
error->message,
|
||||
_("Perhaps you are missing GIO backends and need "
|
||||
"to install GVFS?"));
|
||||
break;
|
||||
|
||||
case G_IO_ERROR_CANCELLED:
|
||||
break;
|
||||
|
||||
default:
|
||||
g_message ("%s", error->message);
|
||||
break;
|
||||
}
|
||||
|
||||
g_error_free (error);
|
||||
|
||||
if (fatal_error)
|
||||
*fatal_error = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_message (_("Help ID '%s' unknown"), help_id);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* private functions */
|
||||
|
||||
static gboolean
|
||||
domain_locale_parse (PikaHelpDomain *domain,
|
||||
PikaHelpLocale *locale,
|
||||
PikaHelpProgress *progress,
|
||||
GError **error)
|
||||
{
|
||||
gchar *uri;
|
||||
gboolean success;
|
||||
|
||||
g_return_val_if_fail (domain != NULL, FALSE);
|
||||
g_return_val_if_fail (locale != NULL, FALSE);
|
||||
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
||||
|
||||
uri = g_strdup_printf ("%s/%s/pika-help.xml",
|
||||
domain->help_uri, locale->locale_id);
|
||||
|
||||
success = pika_help_locale_parse (locale, uri, domain->help_domain,
|
||||
progress, error);
|
||||
|
||||
g_free (uri);
|
||||
|
||||
return success;
|
||||
}
|
55
plug-ins/help/pikahelpdomain.h
Normal file
55
plug-ins/help/pikahelpdomain.h
Normal file
@ -0,0 +1,55 @@
|
||||
/* PIKA - Photo and Image Kooker Application
|
||||
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
|
||||
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
|
||||
*
|
||||
* Original copyright, applying to most contents (license remains unchanged):
|
||||
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
||||
*
|
||||
* The PIKA Help plug-in
|
||||
* Copyright (C) 1999-2008 Sven Neumann <sven@gimp.org>
|
||||
* Michael Natterer <mitch@gimp.org>
|
||||
* Henrik Brix Andersen <brix@gimp.org>
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef __PIKA_HELP_DOMAIN_H__
|
||||
#define __PIKA_HELP_DOMAIN_H__
|
||||
|
||||
|
||||
struct _PikaHelpDomain
|
||||
{
|
||||
gchar *help_domain;
|
||||
gchar *help_uri;
|
||||
GHashTable *help_locales;
|
||||
};
|
||||
|
||||
|
||||
PikaHelpDomain * pika_help_domain_new (const gchar *domain_name,
|
||||
const gchar *domain_uri);
|
||||
void pika_help_domain_free (PikaHelpDomain *domain);
|
||||
|
||||
PikaHelpLocale * pika_help_domain_lookup_locale (PikaHelpDomain *domain,
|
||||
const gchar *locale_id,
|
||||
PikaHelpProgress *progress);
|
||||
gchar * pika_help_domain_map (PikaHelpDomain *domain,
|
||||
GList *help_locales,
|
||||
const gchar *help_id,
|
||||
PikaHelpProgress *progress,
|
||||
PikaHelpLocale **locale,
|
||||
gboolean *fatal_error);
|
||||
void pika_help_domain_exit (void);
|
||||
|
||||
|
||||
#endif /* ! __PIKA_HELP_DOMAIN_H__ */
|
77
plug-ins/help/pikahelpitem.c
Normal file
77
plug-ins/help/pikahelpitem.c
Normal file
@ -0,0 +1,77 @@
|
||||
/* PIKA - Photo and Image Kooker Application
|
||||
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
|
||||
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
|
||||
*
|
||||
* Original copyright, applying to most contents (license remains unchanged):
|
||||
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
||||
*
|
||||
* The PIKA Help plug-in
|
||||
* Copyright (C) 1999-2008 Sven Neumann <sven@gimp.org>
|
||||
* Michael Natterer <mitch@gimp.org>
|
||||
* Henrik Brix Andersen <brix@gimp.org>
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/* This code is written so that it can also be compiled standalone.
|
||||
* It shouldn't depend on libpika.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "pikahelptypes.h"
|
||||
|
||||
#include "pikahelpitem.h"
|
||||
|
||||
#ifdef DISABLE_NLS
|
||||
#define _(String) (String)
|
||||
#else
|
||||
#include "libpika/stdplugins-intl.h"
|
||||
#endif
|
||||
|
||||
|
||||
/* public functions */
|
||||
|
||||
PikaHelpItem *
|
||||
pika_help_item_new (const gchar *ref,
|
||||
const gchar *title,
|
||||
const gchar *sort,
|
||||
const gchar *parent)
|
||||
{
|
||||
PikaHelpItem *item = g_slice_new0 (PikaHelpItem);
|
||||
|
||||
item->ref = g_strdup (ref);
|
||||
item->title = g_strdup (title);
|
||||
item->sort = g_strdup (sort);
|
||||
item->parent = g_strdup (parent);
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
void
|
||||
pika_help_item_free (PikaHelpItem *item)
|
||||
{
|
||||
g_free (item->ref);
|
||||
g_free (item->title);
|
||||
g_free (item->sort);
|
||||
g_free (item->parent);
|
||||
|
||||
g_list_free (item->children);
|
||||
|
||||
g_slice_free (PikaHelpItem, item);
|
||||
}
|
51
plug-ins/help/pikahelpitem.h
Normal file
51
plug-ins/help/pikahelpitem.h
Normal file
@ -0,0 +1,51 @@
|
||||
/* PIKA - Photo and Image Kooker Application
|
||||
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
|
||||
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
|
||||
*
|
||||
* Original copyright, applying to most contents (license remains unchanged):
|
||||
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
||||
*
|
||||
* The PIKA Help plug-in
|
||||
* Copyright (C) 1999-2008 Sven Neumann <sven@gimp.org>
|
||||
* Michael Natterer <mitch@gimp.org>
|
||||
* Henrik Brix Andersen <brix@gimp.org>
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef __PIKA_HELP_ITEM_H__
|
||||
#define __PIKA_HELP_ITEM_H__
|
||||
|
||||
|
||||
struct _PikaHelpItem
|
||||
{
|
||||
gchar *ref;
|
||||
gchar *title;
|
||||
gchar *sort; /* optional sort key provided by doc team */
|
||||
gchar *parent;
|
||||
|
||||
/* extra fields used by the help-browser */
|
||||
GList *children;
|
||||
gulong index;
|
||||
};
|
||||
|
||||
|
||||
PikaHelpItem * pika_help_item_new (const gchar *ref,
|
||||
const gchar *title,
|
||||
const gchar *sort,
|
||||
const gchar *parent);
|
||||
void pika_help_item_free (PikaHelpItem *item);
|
||||
|
||||
|
||||
#endif /* __PIKA_HELP_ITEM_H__ */
|
585
plug-ins/help/pikahelplocale.c
Normal file
585
plug-ins/help/pikahelplocale.c
Normal file
@ -0,0 +1,585 @@
|
||||
/* PIKA - Photo and Image Kooker Application
|
||||
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
|
||||
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
|
||||
*
|
||||
* Original copyright, applying to most contents (license remains unchanged):
|
||||
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
||||
*
|
||||
* The PIKA Help plug-in
|
||||
* Copyright (C) 1999-2008 Sven Neumann <sven@gimp.org>
|
||||
* Michael Natterer <mitch@gimp.org>
|
||||
* Henrik Brix Andersen <brix@gimp.org>
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/* This code is written so that it can also be compiled standalone.
|
||||
* It shouldn't depend on libpika.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <glib-object.h>
|
||||
#include <gio/gio.h>
|
||||
|
||||
#include "pikahelp.h"
|
||||
#include "pikahelpprogress-private.h"
|
||||
|
||||
#ifdef DISABLE_NLS
|
||||
#define _(String) (String)
|
||||
#else
|
||||
#include "libpika/stdplugins-intl.h"
|
||||
#endif
|
||||
|
||||
#ifdef PLATFORM_OSX
|
||||
#include <Foundation/Foundation.h>
|
||||
#endif
|
||||
|
||||
/* local function prototypes */
|
||||
|
||||
static void locale_set_error (GError **error,
|
||||
const gchar *format,
|
||||
GFile *file);
|
||||
|
||||
|
||||
/* public functions */
|
||||
|
||||
PikaHelpLocale *
|
||||
pika_help_locale_new (const gchar *locale_id)
|
||||
{
|
||||
PikaHelpLocale *locale = g_slice_new0 (PikaHelpLocale);
|
||||
|
||||
locale->locale_id = g_strdup (locale_id);
|
||||
|
||||
return locale;
|
||||
}
|
||||
|
||||
void
|
||||
pika_help_locale_free (PikaHelpLocale *locale)
|
||||
{
|
||||
g_return_if_fail (locale != NULL);
|
||||
|
||||
if (locale->help_id_mapping)
|
||||
g_hash_table_destroy (locale->help_id_mapping);
|
||||
|
||||
g_free (locale->locale_id);
|
||||
g_free (locale->help_missing);
|
||||
|
||||
g_list_free (locale->toplevel_items);
|
||||
|
||||
g_slice_free (PikaHelpLocale, locale);
|
||||
}
|
||||
|
||||
const gchar *
|
||||
pika_help_locale_map (PikaHelpLocale *locale,
|
||||
const gchar *help_id)
|
||||
{
|
||||
g_return_val_if_fail (locale != NULL, NULL);
|
||||
g_return_val_if_fail (help_id != NULL, NULL);
|
||||
|
||||
if (locale->help_id_mapping)
|
||||
{
|
||||
PikaHelpItem *item = g_hash_table_lookup (locale->help_id_mapping,
|
||||
help_id);
|
||||
|
||||
if (item)
|
||||
return item->ref;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/* the locale mapping parser */
|
||||
|
||||
typedef enum
|
||||
{
|
||||
LOCALE_START,
|
||||
LOCALE_IN_HELP,
|
||||
LOCALE_IN_ITEM,
|
||||
LOCALE_IN_MISSING,
|
||||
LOCALE_IN_UNKNOWN
|
||||
} LocaleParserState;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GFile *file;
|
||||
LocaleParserState state;
|
||||
LocaleParserState last_known_state;
|
||||
gint markup_depth;
|
||||
gint unknown_depth;
|
||||
GString *value;
|
||||
|
||||
PikaHelpLocale *locale;
|
||||
const gchar *help_domain;
|
||||
gchar *id_attr_name;
|
||||
} LocaleParser;
|
||||
|
||||
static gboolean locale_parser_parse (GMarkupParseContext *context,
|
||||
PikaHelpProgress *progress,
|
||||
GInputStream *stream,
|
||||
goffset size,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
static void locale_parser_start_element (GMarkupParseContext *context,
|
||||
const gchar *element_name,
|
||||
const gchar **attribute_names,
|
||||
const gchar **attribute_values,
|
||||
gpointer user_data,
|
||||
GError **error);
|
||||
static void locale_parser_end_element (GMarkupParseContext *context,
|
||||
const gchar *element_name,
|
||||
gpointer user_data,
|
||||
GError **error);
|
||||
static void locale_parser_error (GMarkupParseContext *context,
|
||||
GError *error,
|
||||
gpointer user_data);
|
||||
static void locale_parser_start_unknown (LocaleParser *parser);
|
||||
static void locale_parser_end_unknown (LocaleParser *parser);
|
||||
static void locale_parser_parse_namespace (LocaleParser *parser,
|
||||
const gchar **names,
|
||||
const gchar **values);
|
||||
static void locale_parser_parse_item (LocaleParser *parser,
|
||||
const gchar **names,
|
||||
const gchar **values);
|
||||
static void locale_parser_parse_missing (LocaleParser *parser,
|
||||
const gchar **names,
|
||||
const gchar **values);
|
||||
|
||||
static const GMarkupParser markup_parser =
|
||||
{
|
||||
locale_parser_start_element,
|
||||
locale_parser_end_element,
|
||||
NULL, /* characters */
|
||||
NULL, /* passthrough */
|
||||
locale_parser_error
|
||||
};
|
||||
|
||||
gboolean
|
||||
pika_help_locale_parse (PikaHelpLocale *locale,
|
||||
const gchar *uri,
|
||||
const gchar *help_domain,
|
||||
PikaHelpProgress *progress,
|
||||
GError **error)
|
||||
{
|
||||
GMarkupParseContext *context;
|
||||
GFile *file = NULL;
|
||||
GCancellable *cancellable = NULL;
|
||||
LocaleParser parser = { NULL, };
|
||||
#ifdef PLATFORM_OSX
|
||||
NSURL *fileURL;
|
||||
NSString *nsUri;
|
||||
NSData *data;
|
||||
const gchar *str;
|
||||
#else
|
||||
GFileInputStream *stream;
|
||||
goffset size = 0;
|
||||
#endif
|
||||
gboolean success;
|
||||
|
||||
g_return_val_if_fail (locale != NULL, FALSE);
|
||||
g_return_val_if_fail (uri != NULL, FALSE);
|
||||
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
||||
|
||||
if (locale->help_id_mapping)
|
||||
{
|
||||
g_hash_table_destroy (locale->help_id_mapping);
|
||||
locale->help_id_mapping = NULL;
|
||||
}
|
||||
|
||||
if (locale->help_missing)
|
||||
{
|
||||
g_free (locale->help_missing);
|
||||
locale->help_missing = NULL;
|
||||
}
|
||||
|
||||
#ifdef PIKA_HELP_DEBUG
|
||||
g_printerr ("help (%s): parsing '%s' for \"%s\"\n",
|
||||
locale->locale_id, uri, help_domain);
|
||||
#endif
|
||||
|
||||
file = g_file_new_for_uri (uri);
|
||||
|
||||
if (progress)
|
||||
{
|
||||
gchar *name = g_file_get_parse_name (file);
|
||||
|
||||
cancellable = g_cancellable_new ();
|
||||
_pika_help_progress_start (progress, cancellable,
|
||||
_("Loading index from '%s'"), name);
|
||||
|
||||
g_clear_object (&cancellable);
|
||||
g_free (name);
|
||||
}
|
||||
|
||||
#ifdef PLATFORM_OSX
|
||||
nsUri = [NSString stringWithUTF8String: uri];
|
||||
fileURL = [NSURL URLWithString: nsUri];
|
||||
[nsUri release];
|
||||
|
||||
if (progress)
|
||||
_pika_help_progress_pulse (progress);
|
||||
|
||||
/* Load the data from the remote URL into the NSData object */
|
||||
data = [NSData dataWithContentsOfURL:fileURL];
|
||||
[fileURL release];
|
||||
|
||||
if (! data)
|
||||
{
|
||||
locale_set_error (error,
|
||||
_("Could not load data from '%s': %s"), file);
|
||||
g_object_unref (file);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (progress)
|
||||
_pika_help_progress_pulse (progress);
|
||||
#else /* PLATFORM_OSX */
|
||||
if (progress)
|
||||
{
|
||||
GFileInfo *info = g_file_query_info (file,
|
||||
G_FILE_ATTRIBUTE_STANDARD_SIZE, 0,
|
||||
cancellable, error);
|
||||
if (! info)
|
||||
{
|
||||
locale_set_error (error,
|
||||
_("Could not open '%s' for reading: %s"), file);
|
||||
g_object_unref (file);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
size = g_file_info_get_size (info);
|
||||
|
||||
g_object_unref (info);
|
||||
}
|
||||
|
||||
stream = g_file_read (file, cancellable, error);
|
||||
|
||||
if (! stream)
|
||||
{
|
||||
locale_set_error (error,
|
||||
_("Could not open '%s' for reading: %s"), file);
|
||||
g_object_unref (file);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
#endif /* ! PLATFORM_OSX */
|
||||
|
||||
parser.file = file;
|
||||
parser.value = g_string_new (NULL);
|
||||
parser.locale = locale;
|
||||
parser.help_domain = help_domain;
|
||||
parser.id_attr_name = g_strdup ("id");
|
||||
|
||||
context = g_markup_parse_context_new (&markup_parser, 0, &parser, NULL);
|
||||
|
||||
#ifdef PLATFORM_OSX
|
||||
str = (const char *)[data bytes];
|
||||
|
||||
if (! g_markup_parse_context_parse (context, str, [data length], error))
|
||||
success = FALSE;
|
||||
else
|
||||
success = g_markup_parse_context_end_parse (context, error);
|
||||
|
||||
[data release];
|
||||
#else /* PLATFORM_OSX */
|
||||
success = locale_parser_parse (context, progress,
|
||||
G_INPUT_STREAM (stream), size,
|
||||
cancellable, error);
|
||||
|
||||
g_object_unref (stream);
|
||||
#endif /* ! PLATFORM_OSX */
|
||||
if (progress)
|
||||
_pika_help_progress_finish (progress);
|
||||
|
||||
g_markup_parse_context_free (context);
|
||||
|
||||
g_string_free (parser.value, TRUE);
|
||||
g_free (parser.id_attr_name);
|
||||
|
||||
if (! success)
|
||||
locale_set_error (error, _("Parse error in '%s':\n%s"), file);
|
||||
|
||||
g_object_unref (file);
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
locale_parser_parse (GMarkupParseContext *context,
|
||||
PikaHelpProgress *progress,
|
||||
GInputStream *stream,
|
||||
goffset size,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
gssize len;
|
||||
goffset done = 0;
|
||||
gchar buffer[4096];
|
||||
|
||||
while ((len = g_input_stream_read (stream, buffer, sizeof (buffer),
|
||||
cancellable, error)) != -1)
|
||||
{
|
||||
switch (len)
|
||||
{
|
||||
case 0:
|
||||
return g_markup_parse_context_end_parse (context, error);
|
||||
|
||||
default:
|
||||
done += len;
|
||||
|
||||
if (progress)
|
||||
{
|
||||
if (size > 0)
|
||||
_pika_help_progress_update (progress, (gdouble) done / size);
|
||||
else
|
||||
_pika_help_progress_pulse (progress);
|
||||
}
|
||||
|
||||
if (! g_markup_parse_context_parse (context, buffer, len, error))
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
locale_parser_start_element (GMarkupParseContext *context,
|
||||
const gchar *element_name,
|
||||
const gchar **attribute_names,
|
||||
const gchar **attribute_values,
|
||||
gpointer user_data,
|
||||
GError **error)
|
||||
{
|
||||
LocaleParser *parser = (LocaleParser *) user_data;
|
||||
|
||||
switch (parser->state)
|
||||
{
|
||||
case LOCALE_START:
|
||||
if (strcmp (element_name, "pika-help") == 0)
|
||||
{
|
||||
parser->state = LOCALE_IN_HELP;
|
||||
locale_parser_parse_namespace (parser,
|
||||
attribute_names, attribute_values);
|
||||
}
|
||||
else
|
||||
locale_parser_start_unknown (parser);
|
||||
break;
|
||||
|
||||
case LOCALE_IN_HELP:
|
||||
if (strcmp (element_name, "help-item") == 0)
|
||||
{
|
||||
parser->state = LOCALE_IN_ITEM;
|
||||
locale_parser_parse_item (parser,
|
||||
attribute_names, attribute_values);
|
||||
}
|
||||
else if (strcmp (element_name, "help-missing") == 0)
|
||||
{
|
||||
parser->state = LOCALE_IN_MISSING;
|
||||
locale_parser_parse_missing (parser,
|
||||
attribute_names, attribute_values);
|
||||
}
|
||||
else
|
||||
locale_parser_start_unknown (parser);
|
||||
break;
|
||||
|
||||
case LOCALE_IN_ITEM:
|
||||
case LOCALE_IN_MISSING:
|
||||
case LOCALE_IN_UNKNOWN:
|
||||
locale_parser_start_unknown (parser);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
locale_parser_end_element (GMarkupParseContext *context,
|
||||
const gchar *element_name,
|
||||
gpointer user_data,
|
||||
GError **error)
|
||||
{
|
||||
LocaleParser *parser = (LocaleParser *) user_data;
|
||||
|
||||
switch (parser->state)
|
||||
{
|
||||
case LOCALE_START:
|
||||
g_warning ("locale_parser: This shouldn't happen.");
|
||||
break;
|
||||
|
||||
case LOCALE_IN_HELP:
|
||||
parser->state = LOCALE_START;
|
||||
break;
|
||||
|
||||
case LOCALE_IN_ITEM:
|
||||
case LOCALE_IN_MISSING:
|
||||
parser->state = LOCALE_IN_HELP;
|
||||
break;
|
||||
|
||||
case LOCALE_IN_UNKNOWN:
|
||||
locale_parser_end_unknown (parser);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
locale_parser_error (GMarkupParseContext *context,
|
||||
GError *error,
|
||||
gpointer user_data)
|
||||
{
|
||||
LocaleParser *parser = (LocaleParser *) user_data;
|
||||
gchar *name = g_file_get_parse_name (parser->file);
|
||||
|
||||
g_printerr ("help (parsing %s): %s", name, error->message);
|
||||
|
||||
g_free (name);
|
||||
}
|
||||
|
||||
static void
|
||||
locale_parser_start_unknown (LocaleParser *parser)
|
||||
{
|
||||
if (parser->unknown_depth == 0)
|
||||
parser->last_known_state = parser->state;
|
||||
|
||||
parser->state = LOCALE_IN_UNKNOWN;
|
||||
parser->unknown_depth++;
|
||||
}
|
||||
|
||||
static void
|
||||
locale_parser_end_unknown (LocaleParser *parser)
|
||||
{
|
||||
g_assert (parser->unknown_depth > 0 && parser->state == LOCALE_IN_UNKNOWN);
|
||||
|
||||
parser->unknown_depth--;
|
||||
|
||||
if (parser->unknown_depth == 0)
|
||||
parser->state = parser->last_known_state;
|
||||
}
|
||||
|
||||
static void
|
||||
locale_parser_parse_namespace (LocaleParser *parser,
|
||||
const gchar **names,
|
||||
const gchar **values)
|
||||
{
|
||||
for (; *names && *values; names++, values++)
|
||||
{
|
||||
if (! strncmp (*names, "xmlns:", 6) &&
|
||||
! strcmp (*values, parser->help_domain))
|
||||
{
|
||||
g_free (parser->id_attr_name);
|
||||
parser->id_attr_name = g_strdup_printf ("%s:id", *names + 6);
|
||||
|
||||
#ifdef PIKA_HELP_DEBUG
|
||||
g_printerr ("help (%s): id attribute name for \"%s\" is \"%s\"\n",
|
||||
parser->locale->locale_id,
|
||||
parser->help_domain,
|
||||
parser->id_attr_name);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
locale_parser_parse_item (LocaleParser *parser,
|
||||
const gchar **names,
|
||||
const gchar **values)
|
||||
{
|
||||
const gchar *id = NULL;
|
||||
const gchar *ref = NULL;
|
||||
const gchar *title = NULL;
|
||||
const gchar *sort = NULL; /* optional sort key provided by doc team */
|
||||
const gchar *parent = NULL;
|
||||
|
||||
for (; *names && *values; names++, values++)
|
||||
{
|
||||
if (! strcmp (*names, parser->id_attr_name))
|
||||
id = *values;
|
||||
|
||||
if (! strcmp (*names, "ref"))
|
||||
ref = *values;
|
||||
|
||||
if (! strcmp (*names, "title"))
|
||||
title = *values;
|
||||
|
||||
if (! strcmp (*names, "sort"))
|
||||
sort = *values;
|
||||
|
||||
if (! strcmp (*names, "parent"))
|
||||
parent = *values;
|
||||
}
|
||||
|
||||
if (id && ref)
|
||||
{
|
||||
if (! parser->locale->help_id_mapping)
|
||||
parser->locale->help_id_mapping =
|
||||
g_hash_table_new_full (g_str_hash,
|
||||
g_str_equal,
|
||||
g_free,
|
||||
(GDestroyNotify) pika_help_item_free);
|
||||
|
||||
g_hash_table_insert (parser->locale->help_id_mapping,
|
||||
g_strdup (id),
|
||||
pika_help_item_new (ref, title, sort, parent));
|
||||
|
||||
#ifdef PIKA_HELP_DEBUG
|
||||
g_printerr ("help (%s): added mapping \"%s\" -> \"%s\"\n",
|
||||
parser->locale->locale_id, id, ref);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
locale_parser_parse_missing (LocaleParser *parser,
|
||||
const gchar **names,
|
||||
const gchar **values)
|
||||
{
|
||||
const gchar *ref = NULL;
|
||||
|
||||
for (; *names && *values; names++, values++)
|
||||
{
|
||||
if (! strcmp (*names, "ref"))
|
||||
ref = *values;
|
||||
}
|
||||
|
||||
if (ref &&
|
||||
parser->locale->help_missing == NULL)
|
||||
{
|
||||
parser->locale->help_missing = g_strdup (ref);
|
||||
|
||||
#ifdef PIKA_HELP_DEBUG
|
||||
g_printerr ("help (%s): added fallback for missing help -> \"%s\"\n",
|
||||
parser->locale->locale_id, ref);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
locale_set_error (GError **error,
|
||||
const gchar *format,
|
||||
GFile *file)
|
||||
{
|
||||
if (error && *error)
|
||||
{
|
||||
gchar *name = g_file_get_parse_name (file);
|
||||
gchar *msg;
|
||||
|
||||
msg = g_strdup_printf (format, name, (*error)->message);
|
||||
g_free (name);
|
||||
|
||||
g_free ((*error)->message);
|
||||
(*error)->message = msg;
|
||||
}
|
||||
}
|
55
plug-ins/help/pikahelplocale.h
Normal file
55
plug-ins/help/pikahelplocale.h
Normal file
@ -0,0 +1,55 @@
|
||||
/* PIKA - Photo and Image Kooker Application
|
||||
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
|
||||
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
|
||||
*
|
||||
* Original copyright, applying to most contents (license remains unchanged):
|
||||
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
||||
*
|
||||
* The PIKA Help plug-in
|
||||
* Copyright (C) 1999-2008 Sven Neumann <sven@gimp.org>
|
||||
* Michael Natterer <mitch@gimp.org>
|
||||
* Henrik Brix Andersen <brix@gimp.org>
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef __PIKA_HELP_LOCALE_H__
|
||||
#define __PIKA_HELP_LOCALE_H__
|
||||
|
||||
|
||||
struct _PikaHelpLocale
|
||||
{
|
||||
gchar *locale_id;
|
||||
GHashTable *help_id_mapping;
|
||||
gchar *help_missing;
|
||||
|
||||
/* eek */
|
||||
GList *toplevel_items;
|
||||
};
|
||||
|
||||
|
||||
PikaHelpLocale * pika_help_locale_new (const gchar *locale_id);
|
||||
void pika_help_locale_free (PikaHelpLocale *locale);
|
||||
|
||||
const gchar * pika_help_locale_map (PikaHelpLocale *locale,
|
||||
const gchar *help_id);
|
||||
|
||||
gboolean pika_help_locale_parse (PikaHelpLocale *locale,
|
||||
const gchar *uri,
|
||||
const gchar *help_domain,
|
||||
PikaHelpProgress *progress,
|
||||
GError **error);
|
||||
|
||||
|
||||
#endif /* __PIKA_HELP_LOCALE_H__ */
|
43
plug-ins/help/pikahelpprogress-private.h
Normal file
43
plug-ins/help/pikahelpprogress-private.h
Normal file
@ -0,0 +1,43 @@
|
||||
/* PIKA - Photo and Image Kooker Application
|
||||
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
|
||||
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
|
||||
*
|
||||
* Original copyright, applying to most contents (license remains unchanged):
|
||||
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
||||
*
|
||||
* The PIKA Help plug-in
|
||||
* Copyright (C) 1999-2008 Sven Neumann <sven@gimp.org>
|
||||
* Michael Natterer <mitch@gimp.org>
|
||||
* Henrik Brix Andersen <brix@gimp.org>
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef __PIKA_HELP_PROGRESS_PRIVATE_H__
|
||||
#define __PIKA_HELP_PROGRESS_PRIVATE_H__
|
||||
|
||||
|
||||
/* internal API */
|
||||
|
||||
void _pika_help_progress_start (PikaHelpProgress *progress,
|
||||
GCancellable *cancellable,
|
||||
const gchar *format,
|
||||
...) G_GNUC_PRINTF (3, 4) G_GNUC_INTERNAL;
|
||||
void _pika_help_progress_update (PikaHelpProgress *progress,
|
||||
gdouble percentage) G_GNUC_INTERNAL;
|
||||
void _pika_help_progress_pulse (PikaHelpProgress *progress) G_GNUC_INTERNAL;
|
||||
void _pika_help_progress_finish (PikaHelpProgress *progress) G_GNUC_INTERNAL;
|
||||
|
||||
|
||||
#endif /* ! __PIKA_HELP_PROGRESS_PRIVATE_H__ */
|
154
plug-ins/help/pikahelpprogress.c
Normal file
154
plug-ins/help/pikahelpprogress.c
Normal file
@ -0,0 +1,154 @@
|
||||
/* PIKA - Photo and Image Kooker Application
|
||||
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
|
||||
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
|
||||
*
|
||||
* Original copyright, applying to most contents (license remains unchanged):
|
||||
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
||||
*
|
||||
* The PIKA Help plug-in
|
||||
* Copyright (C) 1999-2008 Sven Neumann <sven@gimp.org>
|
||||
* Michael Natterer <mitch@gimp.org>
|
||||
* Henrik Brix Andersen <brix@gimp.org>
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/* This code is written so that it can also be compiled standalone.
|
||||
* It shouldn't depend on libpika.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <gio/gio.h>
|
||||
|
||||
#include "pikahelptypes.h"
|
||||
#include "pikahelpprogress.h"
|
||||
#include "pikahelpprogress-private.h"
|
||||
|
||||
|
||||
struct _PikaHelpProgress
|
||||
{
|
||||
PikaHelpProgressVTable vtable;
|
||||
gpointer user_data;
|
||||
|
||||
GCancellable *cancellable;
|
||||
};
|
||||
|
||||
|
||||
PikaHelpProgress *
|
||||
pika_help_progress_new (const PikaHelpProgressVTable *vtable,
|
||||
gpointer user_data)
|
||||
{
|
||||
PikaHelpProgress *progress;
|
||||
|
||||
g_return_val_if_fail (vtable != NULL, NULL);
|
||||
|
||||
progress = g_slice_new0 (PikaHelpProgress);
|
||||
|
||||
progress->vtable.start = vtable->start;
|
||||
progress->vtable.end = vtable->end;
|
||||
progress->vtable.set_value = vtable->set_value;
|
||||
|
||||
progress->user_data = user_data;
|
||||
|
||||
return progress;
|
||||
}
|
||||
|
||||
void
|
||||
pika_help_progress_free (PikaHelpProgress *progress)
|
||||
{
|
||||
g_return_if_fail (progress != NULL);
|
||||
|
||||
if (progress->cancellable)
|
||||
{
|
||||
g_object_unref (progress->cancellable);
|
||||
progress->cancellable = NULL;
|
||||
}
|
||||
|
||||
g_slice_free (PikaHelpProgress, progress);
|
||||
}
|
||||
|
||||
void
|
||||
pika_help_progress_cancel (PikaHelpProgress *progress)
|
||||
{
|
||||
g_return_if_fail (progress != NULL);
|
||||
|
||||
if (progress->cancellable)
|
||||
g_cancellable_cancel (progress->cancellable);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
_pika_help_progress_start (PikaHelpProgress *progress,
|
||||
GCancellable *cancellable,
|
||||
const gchar *format,
|
||||
...)
|
||||
{
|
||||
gchar *message;
|
||||
va_list args;
|
||||
|
||||
g_return_if_fail (progress != NULL);
|
||||
|
||||
if (cancellable)
|
||||
g_object_ref (cancellable);
|
||||
|
||||
if (progress->cancellable)
|
||||
g_object_unref (progress->cancellable);
|
||||
|
||||
progress->cancellable = cancellable;
|
||||
|
||||
va_start (args, format);
|
||||
message = g_strdup_vprintf (format, args);
|
||||
va_end (args);
|
||||
|
||||
if (progress->vtable.start)
|
||||
progress->vtable.start (message, cancellable != NULL, progress->user_data);
|
||||
|
||||
g_free (message);
|
||||
}
|
||||
|
||||
void
|
||||
_pika_help_progress_update (PikaHelpProgress *progress,
|
||||
gdouble percentage)
|
||||
{
|
||||
g_return_if_fail (progress != NULL);
|
||||
|
||||
if (progress->vtable.set_value)
|
||||
progress->vtable.set_value (percentage, progress->user_data);
|
||||
}
|
||||
|
||||
void
|
||||
_pika_help_progress_pulse (PikaHelpProgress *progress)
|
||||
{
|
||||
g_return_if_fail (progress != NULL);
|
||||
|
||||
_pika_help_progress_update (progress, -1.0);
|
||||
}
|
||||
|
||||
void
|
||||
_pika_help_progress_finish (PikaHelpProgress *progress)
|
||||
{
|
||||
g_return_if_fail (progress != NULL);
|
||||
|
||||
if (progress->vtable.end)
|
||||
progress->vtable.end (progress->user_data);
|
||||
|
||||
if (progress->cancellable)
|
||||
{
|
||||
g_object_unref (progress->cancellable);
|
||||
progress->cancellable = NULL;
|
||||
}
|
||||
}
|
55
plug-ins/help/pikahelpprogress.h
Normal file
55
plug-ins/help/pikahelpprogress.h
Normal file
@ -0,0 +1,55 @@
|
||||
/* PIKA - Photo and Image Kooker Application
|
||||
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
|
||||
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
|
||||
*
|
||||
* Original copyright, applying to most contents (license remains unchanged):
|
||||
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
||||
*
|
||||
* The PIKA Help plug-in
|
||||
* Copyright (C) 1999-2008 Sven Neumann <sven@gimp.org>
|
||||
* Michael Natterer <mitch@gimp.org>
|
||||
* Henrik Brix Andersen <brix@gimp.org>
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef __PIKA_HELP_PROGRESS_H__
|
||||
#define __PIKA_HELP_PROGRESS_H__
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
void (* start) (const gchar *message,
|
||||
gboolean cancelable,
|
||||
gpointer user_data);
|
||||
void (* end) (gpointer user_data);
|
||||
void (* set_value) (gdouble percentage,
|
||||
gpointer user_data);
|
||||
|
||||
/* Padding for future expansion. Must be initialized with NULL! */
|
||||
void (* _pika_reserved1) (void);
|
||||
void (* _pika_reserved2) (void);
|
||||
void (* _pika_reserved3) (void);
|
||||
void (* _pika_reserved4) (void);
|
||||
} PikaHelpProgressVTable;
|
||||
|
||||
|
||||
PikaHelpProgress * pika_help_progress_new (const PikaHelpProgressVTable *vtable,
|
||||
gpointer user_data);
|
||||
void pika_help_progress_free (PikaHelpProgress *progress);
|
||||
|
||||
void pika_help_progress_cancel (PikaHelpProgress *progress);
|
||||
|
||||
|
||||
#endif /* ! __PIKA_HELP_PROGRESS_H__ */
|
37
plug-ins/help/pikahelptypes.h
Normal file
37
plug-ins/help/pikahelptypes.h
Normal file
@ -0,0 +1,37 @@
|
||||
/* PIKA - Photo and Image Kooker Application
|
||||
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
|
||||
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
|
||||
*
|
||||
* Original copyright, applying to most contents (license remains unchanged):
|
||||
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
||||
*
|
||||
* The PIKA Help plug-in
|
||||
* Copyright (C) 1999-2008 Sven Neumann <sven@gimp.org>
|
||||
* Michael Natterer <mitch@gimp.org>
|
||||
* Henrik Brix Andersen <brix@gimp.org>
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef __PIKA_HELP_TYPES_H__
|
||||
#define __PIKA_HELP_TYPES_H__
|
||||
|
||||
|
||||
typedef struct _PikaHelpDomain PikaHelpDomain;
|
||||
typedef struct _PikaHelpItem PikaHelpItem;
|
||||
typedef struct _PikaHelpLocale PikaHelpLocale;
|
||||
typedef struct _PikaHelpProgress PikaHelpProgress;
|
||||
|
||||
|
||||
#endif /* ! __PIKA_HELP_TYPES_H__ */
|
Reference in New Issue
Block a user