Commit 4b6adc4c authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer
Browse files

changed warnings to include the invalid menu path. Added check that makes

2004-05-15  Michael Natterer  <mitch@gimp.org>

	* app/plug-in/plug-in-params.c (plug_in_proc_args_check): changed
	warnings to include the invalid menu path. Added check that makes
	sure menu paths are either "<Prefix>" or "<Prefix>/foo" but *not*
	"<Prefix>foo".

	* app/actions/plug-in-actions.c: added function
	plug_in_actions_check_translation() which validates both the
	original and translated menu paths and spits detailed error
	messages if any of them is broken. Made action creation simpler
	(?) and more robust.

	* app/menus/plug-in-menus.c: argh, the translated menu path must
	be a sorting criteria *only*. Fixed the whole stuff to always use
	the original menu path because translation is done entirely by
	plug-in-actions.c. Fixes bad crashes for all locales. Added
	boolean return value to plug_in_menus_build_path() and don't try
	to create the menu item in an invalid location if creating the
	submenus failed.
parent 727f8a43
2004-05-15 Michael Natterer <mitch@gimp.org>
* app/plug-in/plug-in-params.c (plug_in_proc_args_check): changed
warnings to include the invalid menu path. Added check that makes
sure menu paths are either "<Prefix>" or "<Prefix>/foo" but *not*
"<Prefix>foo".
* app/actions/plug-in-actions.c: added function
plug_in_actions_check_translation() which validates both the
original and translated menu paths and spits detailed error
messages if any of them is broken. Made action creation simpler
(?) and more robust.
* app/menus/plug-in-menus.c: argh, the translated menu path must
be a sorting criteria *only*. Fixed the whole stuff to always use
the original menu path because translation is done entirely by
plug-in-actions.c. Fixes bad crashes for all locales. Added
boolean return value to plug_in_menus_build_path() and don't try
to create the menu item in an invalid location if creating the
submenus failed.
2004-05-14 Sven Neumann <sven@gimp.org>
* app/menus/file-dialog-menu.c: check if the file procedure
......
......@@ -48,9 +48,11 @@
/* local function prototypes */
static void plug_in_actions_build_path (GimpActionGroup *group,
const gchar *path_original,
const gchar *path_translated);
static gboolean plug_in_actions_check_translation (const gchar *original,
const gchar *translated);
static void plug_in_actions_build_path (GimpActionGroup *group,
const gchar *original,
const gchar *translated);
/* private variables */
......@@ -251,13 +253,13 @@ void
plug_in_actions_add_proc (GimpActionGroup *group,
PlugInProcDef *proc_def)
{
const gchar *progname;
const gchar *locale_domain;
const gchar *help_domain;
gchar *path_original;
gchar *path_translated;
gchar *help_id;
gchar *p1, *p2;
GimpPlugInActionEntry entry;
const gchar *progname;
const gchar *locale_domain;
const gchar *help_domain;
const gchar *label_translated;
gchar *path_original = NULL;
gchar *path_translated = NULL;
g_return_if_fail (GIMP_IS_ACTION_GROUP (group));
g_return_if_fail (proc_def != NULL);
......@@ -267,73 +269,70 @@ plug_in_actions_add_proc (GimpActionGroup *group,
locale_domain = plug_ins_locale_domain (group->gimp, progname, NULL);
help_domain = plug_ins_help_domain (group->gimp, progname, NULL);
help_id = plug_in_proc_def_get_help_id (proc_def, help_domain);
if (proc_def->menu_label)
{
path_original = g_strdup (proc_def->menu_label);
path_translated = g_strdup (dgettext (locale_domain, path_original));
p1 = path_original;
p2 = path_translated;
label_translated = dgettext (locale_domain, proc_def->menu_label);
}
else
{
path_original = g_strdup (proc_def->menu_paths->data);
path_translated = g_strdup (dgettext (locale_domain, path_original));
gchar *p1, *p2;
path_original = proc_def->menu_paths->data;
path_translated = dgettext (locale_domain, path_original);
if (! plug_in_actions_check_translation (path_original, path_translated))
return;
path_original = g_strdup (path_original);
path_translated = g_strdup (path_translated);
p1 = strrchr (path_original, '/');
p2 = strrchr (path_translated, '/');
*p1 = '\0';
*p2 = '\0';
label_translated = p2 + 1;
}
if (p1 && p2)
{
GimpPlugInActionEntry entry;
gchar *label;
if (proc_def->menu_label)
label = proc_def->menu_label;
else
label = p2 + 1;
entry.name = proc_def->db_info.name;
entry.stock_id = NULL;
entry.label = label;
entry.accelerator = NULL;
entry.tooltip = NULL;
entry.proc_def = proc_def;
entry.help_id = help_id;
entry.name = proc_def->db_info.name;
entry.stock_id = NULL;
entry.label = label_translated;
entry.accelerator = NULL;
entry.tooltip = NULL;
entry.proc_def = proc_def;
entry.help_id = plug_in_proc_def_get_help_id (proc_def, help_domain);
#if 0
g_print ("adding plug-in action '%s' (%s)\n",
proc_def->db_info.name, label);
g_print ("adding plug-in action '%s' (%s)\n",
proc_def->db_info.name, label_translated);
#endif
gimp_action_group_add_plug_in_actions (group, &entry, 1,
G_CALLBACK (plug_in_run_cmd_callback));
gimp_action_group_add_plug_in_actions (group, &entry, 1,
G_CALLBACK (plug_in_run_cmd_callback));
if (proc_def->menu_label)
{
GList *list;
g_free ((gchar *) entry.help_id);
for (list = proc_def->menu_paths; list; list = g_list_next (list))
plug_in_actions_build_path (group,
list->data,
dgettext (locale_domain, list->data));
}
else
if (proc_def->menu_label)
{
GList *list;
for (list = proc_def->menu_paths; list; list = g_list_next (list))
{
*p1 = '\0';
*p2 = '\0';
const gchar *original = list->data;
const gchar *translated = dgettext (locale_domain, original);
plug_in_actions_build_path (group, path_original, path_translated);
if (plug_in_actions_check_translation (original, translated))
plug_in_actions_build_path (group, original, translated);
}
}
else
{
plug_in_actions_build_path (group, path_original, path_translated);
g_free (path_original);
g_free (path_translated);
g_free (help_id);
g_free (path_original);
g_free (path_translated);
}
}
void
......@@ -362,6 +361,64 @@ plug_in_actions_remove_proc (GimpActionGroup *group,
/* private functions */
static gboolean
plug_in_actions_check_translation (const gchar *original,
const gchar *translated)
{
const gchar *p1;
const gchar *p2;
/* first check if <Prefix> is present and identical in both strings */
p1 = strchr (original, '>');
p2 = strchr (translated, '>');
if (!p1 || !p2 ||
(p1 - original) != (p2 - translated) ||
strncmp (original, translated, p1 - original))
{
g_printerr ("bad translation \"%s\"\n"
"for menu path \"%s\"\n"
"(<Prefix> must not be translated)\n\n",
translated, original);
return FALSE;
}
p1++;
p2++;
/* then check if either a '/' or nothing follows in *both* strings */
if (! ((*p1 == '/' && *p2 == '/') ||
(*p1 == '\0' && *p2 == '\0')))
{
g_printerr ("bad translation \"%s\"\n"
"for menu path \"%s\"\n"
"(<Prefix> must be followed by either nothing or '/')\n\n",
translated, original);
return FALSE;
}
/* then check the number of slashes in the remaining string */
while (p1 && p2)
{
p1 = strchr (p1, '/');
p2 = strchr (p2, '/');
if (p1) p1++;
if (p2) p2++;
}
if (p1 || p2)
{
g_printerr ("bad translation \"%s\"\n"
"for menu path \"%s\"\n"
"(number of '/' must be the same)\n\n",
translated, original);
return FALSE;
}
return TRUE;
}
static void
plug_in_actions_build_path (GimpActionGroup *group,
const gchar *path_original,
......
......@@ -39,15 +39,24 @@
#include "gimp-intl.h"
typedef struct _PlugInMenuEntry PlugInMenuEntry;
struct _PlugInMenuEntry
{
PlugInProcDef *proc_def;
const gchar *menu_path;
};
/* local function prototypes */
static gboolean plug_in_menus_tree_traverse (gchar *menu_path,
PlugInProcDef *proc_def,
GimpUIManager *manager);
static void plug_in_menus_build_path (GimpUIManager *manager,
const gchar *ui_path,
guint merge_id,
const gchar *path);
static gboolean plug_in_menus_tree_traverse (gpointer key,
PlugInMenuEntry *entry,
GimpUIManager *manager);
static gboolean plug_in_menus_build_path (GimpUIManager *manager,
const gchar *ui_path,
guint merge_id,
const gchar *menu_path);
/* public functions */
......@@ -114,7 +123,7 @@ plug_in_menus_setup (GimpUIManager *manager,
g_return_if_fail (ui_path != NULL);
menu_entries = g_tree_new_full ((GCompareDataFunc) g_utf8_collate, NULL,
g_free, NULL);
g_free, g_free);
for (list = manager->gimp->plug_in_proc_defs;
list;
......@@ -138,10 +147,14 @@ plug_in_menus_setup (GimpUIManager *manager,
(! strcmp (ui_path, "/image-menubar") ||
! strcmp (ui_path, "/image-popup"))))
{
const gchar *progname;
const gchar *locale_domain;
gchar *stripped;
gchar *key;
PlugInMenuEntry *entry = g_new0 (PlugInMenuEntry, 1);
const gchar *progname;
const gchar *locale_domain;
gchar *stripped;
gchar *key;
entry->proc_def = proc_def;
entry->menu_path = path->data;
progname = plug_in_proc_def_get_progname (proc_def);
......@@ -159,7 +172,7 @@ plug_in_menus_setup (GimpUIManager *manager,
g_free (stripped);
g_tree_insert (menu_entries, key, proc_def);
g_tree_insert (menu_entries, key, entry);
}
}
}
......@@ -183,8 +196,8 @@ plug_in_menus_add_proc (GimpUIManager *manager,
const gchar *menu_path)
{
gchar *path;
gchar *action_path;
gchar *merge_key;
gchar *action_path;
guint merge_id;
g_return_if_fail (GIMP_IS_UI_MANAGER (manager));
......@@ -196,6 +209,13 @@ plug_in_menus_add_proc (GimpUIManager *manager,
if (! proc_def->menu_label)
{
gchar *p = strrchr (path, '/');
if (! p)
{
g_free (path);
return;
}
*p = '\0';
}
......@@ -213,12 +233,23 @@ plug_in_menus_add_proc (GimpUIManager *manager,
g_free (merge_key);
plug_in_menus_build_path (manager, ui_path, merge_id, path);
if (strchr (path, '/'))
{
if (! plug_in_menus_build_path (manager, ui_path, merge_id, path))
{
g_free (path);
return;
}
action_path = g_strdup_printf ("%s%s", ui_path, strchr (path, '/'));
action_path = g_strdup_printf ("%s%s", ui_path, strchr (path, '/'));
}
else
{
action_path = g_strdup (ui_path);
}
#if 0
g_print ("adding UI for '%s' (@ %s)\n",
g_print ("adding menu item for '%s' (@ %s)\n",
proc_def->db_info.name, action_path);
#endif
......@@ -256,66 +287,69 @@ plug_in_menus_remove_proc (GimpUIManager *manager,
/* private functions */
static gboolean
plug_in_menus_tree_traverse (gchar *menu_path,
PlugInProcDef *proc_def,
GimpUIManager *manager)
plug_in_menus_tree_traverse (gpointer key,
PlugInMenuEntry *entry,
GimpUIManager *manager)
{
const gchar *ui_path = g_object_get_data (G_OBJECT (manager), "ui-path");
if (proc_def->menu_label)
{
gchar *p = strrchr (menu_path, '/');
*p = '\0';
}
plug_in_menus_add_proc (manager, ui_path, proc_def, menu_path);
plug_in_menus_add_proc (manager, ui_path, entry->proc_def, entry->menu_path);
return FALSE;
}
static void
static gboolean
plug_in_menus_build_path (GimpUIManager *manager,
const gchar *ui_path,
guint merge_id,
const gchar *path)
const gchar *menu_path)
{
gchar *action_path;
gchar *action_path;
gboolean retval = TRUE;
if (! strchr (menu_path, '/'))
return TRUE;
action_path = g_strdup_printf ("%s%s", ui_path, strchr (path, '/'));
action_path = g_strdup_printf ("%s%s", ui_path, strchr (menu_path, '/'));
if (! gtk_ui_manager_get_widget (GTK_UI_MANAGER (manager), action_path))
{
gchar *base_path = g_strdup (path);
gchar *parent_menu_path = g_strdup (menu_path);
gchar *p;
p = strrchr (base_path, '/');
p = strrchr (parent_menu_path, '/');
*p = '\0';
if (p)
if (plug_in_menus_build_path (manager, ui_path, merge_id,
parent_menu_path))
{
gchar *name;
gchar *parent_action_path = action_path; /* no strdup() needed */
gchar *menu_item_name;
p = strrchr (parent_action_path, '/');
*p = '\0';
plug_in_menus_build_path (manager, ui_path, merge_id, base_path);
p = strrchr (action_path, '/');
*p = '\0';
menu_item_name = strrchr (menu_path, '/') + 1;
#if 0
g_print ("adding UI for '%s' (@ %s)\n",
path, action_path);
g_print ("adding menu '%s' at path '%s' for action '%s'\n",
menu_item_name, action_path, menu_path);
#endif
name = strrchr (path, '/') + 1;
gtk_ui_manager_add_ui (GTK_UI_MANAGER (manager), merge_id,
action_path, name, path,
parent_action_path, menu_item_name, menu_path,
GTK_UI_MANAGER_MENU,
FALSE);
}
else
{
retval = FALSE;
}
g_free (base_path);
g_free (parent_menu_path);
}
g_free (action_path);
return retval;
}
......@@ -77,7 +77,7 @@ plug_in_params_to_args (GPParam *params,
{
count = args[i-1].value.pdb_int;
args[i].value.pdb_pointer = g_new (gint32, count);
memcpy (args[i].value.pdb_pointer,
memcpy (args[i].value.pdb_pointer,
params[i].data.d_int32array, count * 4);
}
else
......@@ -90,7 +90,7 @@ plug_in_params_to_args (GPParam *params,
{
count = args[i-1].value.pdb_int;
args[i].value.pdb_pointer = g_new (gint16, count);
memcpy (args[i].value.pdb_pointer,
memcpy (args[i].value.pdb_pointer,
params[i].data.d_int16array, count * 2);
}
else
......@@ -103,7 +103,7 @@ plug_in_params_to_args (GPParam *params,
{
count = args[i-1].value.pdb_int;
args[i].value.pdb_pointer = g_new (gint8, count);
memcpy (args[i].value.pdb_pointer,
memcpy (args[i].value.pdb_pointer,
params[i].data.d_int8array, count);
}
else
......@@ -116,7 +116,7 @@ plug_in_params_to_args (GPParam *params,
{
count = args[i-1].value.pdb_int;
args[i].value.pdb_pointer = g_new (gdouble, count);
memcpy (args[i].value.pdb_pointer,
memcpy (args[i].value.pdb_pointer,
params[i].data.d_floatarray, count * 8);
}
else
......@@ -127,7 +127,7 @@ plug_in_params_to_args (GPParam *params,
case GIMP_PDB_STRINGARRAY:
if (full_copy)
{
args[i].value.pdb_pointer = g_new (gchar *,
args[i].value.pdb_pointer = g_new (gchar *,
args[i-1].value.pdb_int);
stringarray = args[i].value.pdb_pointer;
......@@ -484,6 +484,8 @@ plug_in_proc_args_check (const gchar *plug_in_name,
guint32 n_return_vals,
GError **error)
{
gchar *p;
g_return_val_if_fail (plug_in_name != NULL, FALSE);
g_return_val_if_fail (plug_in_prog != NULL, FALSE);
g_return_val_if_fail (procedure_name != NULL, FALSE);
......@@ -571,14 +573,32 @@ plug_in_proc_args_check (const gchar *plug_in_name,
else
{
g_set_error (error, 0, 0,
"Plug-In \"%s\"\n(%s)\n\n"
"Plug-In \"%s\"\n(%s)\n"
"attempted to install procedure \"%s\" "
"in an invalid menu location.\n"
"in the invalid menu location \"%s\".\n"
"Use either \"<Toolbox>\", \"<Image>\", "
"\"<Load>\", or \"<Save>\".",
gimp_filename_to_utf8 (plug_in_name),
gimp_filename_to_utf8 (plug_in_prog),
procedure_name);
procedure_name,
menu_path);
return FALSE;
}
p = strchr (menu_path, '>') + 1;
if (*p != '/' && *p != '\0')
{
g_set_error (error, 0, 0,
"Plug-In \"%s\"\n(%s)\n"
"attempted to install procedure \"%s\"\n"
"in the invalid menu location \"%s\".\n"
"The menu path must look like either \"<Prefix>\" "
"or \"<Prefix>/path/to/item\".",
gimp_filename_to_utf8 (plug_in_name),
gimp_filename_to_utf8 (plug_in_prog),
procedure_name,
menu_path);
return FALSE;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment