created a base function for two functions with duplicate code.
* plug-ins/gimpressionist/presets.c: created a base function for two functions with duplicate code.
This commit is contained in:
@ -1,3 +1,8 @@
|
|||||||
|
2004-07-28 Shlomi Fish <shlomif@iglu.org.il>
|
||||||
|
|
||||||
|
* plug-ins/gimpressionist/presets.c: created a base function for
|
||||||
|
two functions with duplicate code.
|
||||||
|
|
||||||
2004-07-28 Sven Neumann <sven@gimp.org>
|
2004-07-28 Sven Neumann <sven@gimp.org>
|
||||||
|
|
||||||
* plug-ins/imagemap/imap_default_dialog.c: no need to include
|
* plug-ins/imagemap/imap_default_dialog.c: no need to include
|
||||||
|
@ -80,19 +80,13 @@ static char presetdesc[4096] = "";
|
|||||||
static char *factory_defaults = "<Factory defaults>";
|
static char *factory_defaults = "<Factory defaults>";
|
||||||
|
|
||||||
static gchar *
|
static gchar *
|
||||||
get_object_name(gchar *dir, gchar *filename, void *context)
|
get_early_line_from_preset (gchar *full_path, const gchar *prefix)
|
||||||
{
|
{
|
||||||
gchar *ret = NULL;
|
|
||||||
gchar *full_path = NULL;
|
|
||||||
FILE *f;
|
FILE *f;
|
||||||
char line[1024] = "";
|
gchar line[4096];
|
||||||
int line_idx;
|
gint prefix_len, line_idx;
|
||||||
|
|
||||||
/* First try to extract the object's name (= user-friendly description)
|
prefix_len = strlen (prefix);
|
||||||
* from the preset file
|
|
||||||
* */
|
|
||||||
|
|
||||||
full_path = g_build_filename (dir, filename, NULL);
|
|
||||||
f = fopen (full_path, "rt");
|
f = fopen (full_path, "rt");
|
||||||
if (f)
|
if (f)
|
||||||
{
|
{
|
||||||
@ -105,27 +99,45 @@ get_object_name(gchar *dir, gchar *filename, void *context)
|
|||||||
if (!fgets (line, sizeof(line), f))
|
if (!fgets (line, sizeof(line), f))
|
||||||
break;
|
break;
|
||||||
g_strchomp (line);
|
g_strchomp (line);
|
||||||
if (!strncmp (line, "name=", 5))
|
if (!strncmp (line, prefix, prefix_len))
|
||||||
{
|
{
|
||||||
ret = g_strcompress (line+5);
|
fclose(f);
|
||||||
break;
|
return g_strdup (line+prefix_len);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fclose (f);
|
fclose (f);
|
||||||
}
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* The object name defaults to a filename-derived description */
|
static gchar *
|
||||||
if (! ret)
|
get_object_name (gchar *dir, gchar *filename, void *context)
|
||||||
{
|
{
|
||||||
|
gchar *ret = NULL, *unprocessed_line = NULL;
|
||||||
|
gchar *full_path = NULL;
|
||||||
|
|
||||||
|
/* First try to extract the object's name (= user-friendly description)
|
||||||
|
* from the preset file
|
||||||
|
* */
|
||||||
|
|
||||||
|
full_path = g_build_filename (dir, filename, NULL);
|
||||||
|
unprocessed_line = get_early_line_from_preset (full_path, "name=");
|
||||||
|
g_free (full_path);
|
||||||
|
if (unprocessed_line)
|
||||||
|
{
|
||||||
|
ret = g_strcompress (unprocessed_line);
|
||||||
|
g_free(unprocessed_line);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* The object name defaults to a filename-derived description */
|
||||||
ret = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
|
ret = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free (full_path);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
preset_read_dir_into_list (void)
|
preset_read_dir_into_list (void)
|
||||||
{
|
{
|
||||||
@ -794,7 +806,7 @@ static void read_description(const char *fn)
|
|||||||
{
|
{
|
||||||
char *rel_fname;
|
char *rel_fname;
|
||||||
char *fname;
|
char *fname;
|
||||||
FILE *f;
|
gchar *unprocessed_line;
|
||||||
|
|
||||||
rel_fname = g_build_filename ("Presets", fn, NULL);
|
rel_fname = g_build_filename ("Presets", fn, NULL);
|
||||||
fname = findfile (rel_fname);
|
fname = findfile (rel_fname);
|
||||||
@ -817,28 +829,21 @@ static void read_description(const char *fn)
|
|||||||
/* Don't delete global presets - bug # 147483 */
|
/* Don't delete global presets - bug # 147483 */
|
||||||
gtk_widget_set_sensitive (delete_button, can_delete_preset (fname));
|
gtk_widget_set_sensitive (delete_button, can_delete_preset (fname));
|
||||||
|
|
||||||
f = fopen(fname, "rt");
|
unprocessed_line = get_early_line_from_preset (fname, "desc=");
|
||||||
g_free(fname);
|
g_free(fname);
|
||||||
if (f)
|
|
||||||
{
|
|
||||||
char line[4096];
|
|
||||||
char tmplabel[4096];
|
|
||||||
while(!feof(f))
|
|
||||||
{
|
|
||||||
fgets(line, 4095, f);
|
|
||||||
if (!strncmp (line, "desc=", 5))
|
|
||||||
{
|
|
||||||
parse_desc (line + 5, tmplabel, sizeof (tmplabel));
|
|
||||||
set_preset_description_text (tmplabel);
|
|
||||||
fclose (f);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fclose (f);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (unprocessed_line)
|
||||||
|
{
|
||||||
|
char tmplabel[4096];
|
||||||
|
parse_desc (unprocessed_line, tmplabel, sizeof (tmplabel));
|
||||||
|
g_free (unprocessed_line);
|
||||||
|
set_preset_description_text (tmplabel);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
set_preset_description_text ("");
|
set_preset_description_text ("");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void presets_list_select_preset (GtkTreeSelection *selection,
|
static void presets_list_select_preset (GtkTreeSelection *selection,
|
||||||
gpointer data)
|
gpointer data)
|
||||||
|
Reference in New Issue
Block a user