take a guint64 parameter and handle values beyond a gigabyte.

2003-11-14  Sven Neumann  <sven@gimp.org>

	* libgimpbase/gimputils.[ch] (gimp_memsize_to_string): take a
	guint64 parameter and handle values beyond a gigabyte.

	* app/core/gimptemplate.[ch]: use a guint64 for the initial memory
	size and removed the gboolean that used to indicate a gulong
	overflow.

	* app/widgets/gimptemplateeditor.[ch]: changed accordingly.

	* app/gui/file-new-dialog.c: don't set the OK button insensitive
	when the initial memory size exceeds GULONG_MAX.

	* app/widgets/gimpsessioninfo.c (gimp_session_info_deserialize):
	replaced a misleading comment.
This commit is contained in:
Sven Neumann
2003-11-14 12:05:13 +00:00
committed by Sven Neumann
parent 31a72d1bd3
commit 5ea47f728f
10 changed files with 64 additions and 98 deletions

View File

@ -1,3 +1,20 @@
2003-11-14 Sven Neumann <sven@gimp.org>
* libgimpbase/gimputils.[ch] (gimp_memsize_to_string): take a
guint64 parameter and handle values beyond a gigabyte.
* app/core/gimptemplate.[ch]: use a guint64 for the initial memory
size and removed the gboolean that used to indicate a gulong
overflow.
* app/widgets/gimptemplateeditor.[ch]: changed accordingly.
* app/gui/file-new-dialog.c: don't set the OK button insensitive
when the initial memory size exceeds GULONG_MAX.
* app/widgets/gimpsessioninfo.c (gimp_session_info_deserialize):
replaced a misleading comment.
2003-11-14 Simon Budig <simon@gimp.org>
* app/tools/gimpvectoroptions.c: Add two buttons to the

View File

@ -319,20 +319,9 @@ gimp_template_notify (GObject *object,
1 /* selection */ +
(template->image_type == GIMP_RGB ? 4 : 2) /* projection */);
size = ((guint64) channels *
(guint64) template->width *
(guint64) template->height);
if (size > G_MAXULONG)
{
template->initial_size = G_MAXULONG;
template->initial_size_too_large = TRUE;
}
else
{
template->initial_size = (gulong) size;
template->initial_size_too_large = FALSE;
}
template->initial_size = ((guint64) channels *
(guint64) template->width *
(guint64) template->height);
if (! strcmp (pspec->name, "stock-id"))
gimp_viewable_invalidate_preview (GIMP_VIEWABLE (object));

View File

@ -54,8 +54,7 @@ struct _GimpTemplate
gchar *comment;
gchar *filename;
gulong initial_size;
gboolean initial_size_too_large;
guint64 initial_size;
};
struct _GimpTemplateClass

View File

@ -58,7 +58,6 @@ typedef struct
Gimp *gimp;
GimpTemplate *template;
gulong memsize;
} FileNewDialog;
@ -67,9 +66,6 @@ typedef struct
static void file_new_response (GtkWidget *widget,
gint response_id,
FileNewDialog *dialog);
static void file_new_template_notify (GimpTemplate *template,
GParamSpec *param_spec,
FileNewDialog *dialog);
static void file_new_template_select (GimpContainerMenu *menu,
GimpTemplate *template,
gpointer insert_data,
@ -94,7 +90,6 @@ file_new_dialog_new (Gimp *gimp)
dialog->gimp = gimp;
dialog->template = g_object_new (GIMP_TYPE_TEMPLATE, NULL);
dialog->memsize = 0;
dialog->dialog =
gimp_viewable_dialog_new (NULL,
@ -155,10 +150,6 @@ file_new_dialog_new (Gimp *gimp)
gtk_box_pack_start (GTK_BOX (main_vbox), dialog->editor, FALSE, FALSE, 0);
gtk_widget_show (dialog->editor);
g_signal_connect (dialog->template, "notify",
G_CALLBACK (file_new_template_notify),
dialog);
return dialog->dialog;
}
@ -209,7 +200,7 @@ file_new_response (GtkWidget *widget,
break;
case GTK_RESPONSE_OK:
if (dialog->memsize >
if (dialog->template->initial_size >
GIMP_GUI_CONFIG (dialog->gimp->config)->max_new_image_size)
file_new_confirm_dialog (dialog);
else
@ -222,21 +213,6 @@ file_new_response (GtkWidget *widget,
}
}
static void
file_new_template_notify (GimpTemplate *template,
GParamSpec *param_spec,
FileNewDialog *dialog)
{
if (dialog->memsize != template->initial_size)
{
dialog->memsize = template->initial_size;
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog->dialog),
GTK_RESPONSE_OK,
! template->initial_size_too_large);
}
}
static void
file_new_template_select (GimpContainerMenu *menu,
GimpTemplate *template,
@ -288,7 +264,7 @@ file_new_confirm_dialog (FileNewDialog *dialog)
gchar *max_size_str;
gchar *text;
size_str = gimp_memsize_to_string (dialog->memsize);
size_str = gimp_memsize_to_string (dialog->template->initial_size);
max_size_str = gimp_memsize_to_string (GIMP_GUI_CONFIG (dialog->gimp->config)->max_new_image_size);
text = g_strdup_printf (_("You are trying to create an image with\n"

View File

@ -58,7 +58,6 @@ typedef struct
Gimp *gimp;
GimpTemplate *template;
gulong memsize;
} FileNewDialog;
@ -67,9 +66,6 @@ typedef struct
static void file_new_response (GtkWidget *widget,
gint response_id,
FileNewDialog *dialog);
static void file_new_template_notify (GimpTemplate *template,
GParamSpec *param_spec,
FileNewDialog *dialog);
static void file_new_template_select (GimpContainerMenu *menu,
GimpTemplate *template,
gpointer insert_data,
@ -94,7 +90,6 @@ file_new_dialog_new (Gimp *gimp)
dialog->gimp = gimp;
dialog->template = g_object_new (GIMP_TYPE_TEMPLATE, NULL);
dialog->memsize = 0;
dialog->dialog =
gimp_viewable_dialog_new (NULL,
@ -155,10 +150,6 @@ file_new_dialog_new (Gimp *gimp)
gtk_box_pack_start (GTK_BOX (main_vbox), dialog->editor, FALSE, FALSE, 0);
gtk_widget_show (dialog->editor);
g_signal_connect (dialog->template, "notify",
G_CALLBACK (file_new_template_notify),
dialog);
return dialog->dialog;
}
@ -209,7 +200,7 @@ file_new_response (GtkWidget *widget,
break;
case GTK_RESPONSE_OK:
if (dialog->memsize >
if (dialog->template->initial_size >
GIMP_GUI_CONFIG (dialog->gimp->config)->max_new_image_size)
file_new_confirm_dialog (dialog);
else
@ -222,21 +213,6 @@ file_new_response (GtkWidget *widget,
}
}
static void
file_new_template_notify (GimpTemplate *template,
GParamSpec *param_spec,
FileNewDialog *dialog)
{
if (dialog->memsize != template->initial_size)
{
dialog->memsize = template->initial_size;
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog->dialog),
GTK_RESPONSE_OK,
! template->initial_size_too_large);
}
}
static void
file_new_template_select (GimpContainerMenu *menu,
GimpTemplate *template,
@ -288,7 +264,7 @@ file_new_confirm_dialog (FileNewDialog *dialog)
gchar *max_size_str;
gchar *text;
size_str = gimp_memsize_to_string (dialog->memsize);
size_str = gimp_memsize_to_string (dialog->template->initial_size);
max_size_str = gimp_memsize_to_string (GIMP_GUI_CONFIG (dialog->gimp->config)->max_new_image_size);
text = g_strdup_printf (_("You are trying to create an image with\n"

View File

@ -466,7 +466,7 @@ gimp_session_info_deserialize (GScanner *scanner,
case SESSION_INFO_OPEN:
info->open = TRUE;
/* for backward compatibility */
/* the screen number is optional */
if (g_scanner_peek_next_token (scanner) == G_TOKEN_RIGHT_PAREN)
break;

View File

@ -136,7 +136,6 @@ static void
gimp_template_editor_init (GimpTemplateEditor *editor)
{
editor->template = NULL;
editor->memsize = 0;
}
static void
@ -668,7 +667,8 @@ gimp_template_editor_template_notify (GimpTemplate *template,
GParamSpec *param_spec,
GimpTemplateEditor *editor)
{
GimpAspectType aspect;
GimpAspectType aspect;
gchar *text;
if (param_spec)
{
@ -684,20 +684,9 @@ gimp_template_editor_template_notify (GimpTemplate *template,
}
}
if (editor->memsize != template->initial_size)
{
gchar *text;
editor->memsize = template->initial_size;
if (template->initial_size_too_large)
text = g_strdup (_("Too large!"));
else
text = gimp_memsize_to_string (editor->memsize);
gtk_label_set_text (GTK_LABEL (editor->memsize_label), text);
g_free (text);
}
text = gimp_memsize_to_string (template->initial_size);
gtk_label_set_text (GTK_LABEL (editor->memsize_label), text);
g_free (text);
if (editor->template->width > editor->template->height)
aspect = GIMP_ASPECT_LANDSCAPE;

View File

@ -41,7 +41,6 @@ struct _GimpTemplateEditor
GtkVBox parent_instance;
GimpTemplate *template;
gulong memsize;
GimpContainer *stock_id_container;
GimpContext *stock_id_context;

View File

@ -175,20 +175,21 @@ gimp_any_to_utf8 (const gchar *str,
* @memsize: A memory size in bytes.
*
* This function returns a human readable, translated representation
* of the passed @memsize. Large values are rounded to the closest
* reasonable memsize unit, e.g.: "3456" becomes "3456 Bytes", "4100"
* becomes "4 KB" and so on.
* of the passed @memsize. Large values are displayed using a
* reasonable memsize unit, e.g.: "345" becomes "345 Bytes", "4500"
* becomes "4.4 KB" and so on.
*
* Return value: A human-readable, translated string.
* Return value: A newly allocated human-readable, translated string.
**/
gchar *
gimp_memsize_to_string (gulong memsize)
gimp_memsize_to_string (guint64 memsize)
{
if (memsize < 4096)
if (memsize < 1024)
{
return g_strdup_printf (_("%d Bytes"), (gint) memsize);
}
else if (memsize < 1024 * 10)
if (memsize < 1024 * 10)
{
return g_strdup_printf (_("%.2f KB"), (gdouble) memsize / 1024.0);
}
@ -200,15 +201,35 @@ gimp_memsize_to_string (gulong memsize)
{
return g_strdup_printf (_("%d KB"), (gint) memsize / 1024);
}
else if (memsize < 1024 * 1024 * 10)
memsize /= 1024;
if (memsize < 1024 * 10)
{
memsize /= 1024;
return g_strdup_printf (_("%.2f MB"), (gdouble) memsize / 1024.0);
}
else if (memsize < 1024 * 100)
{
return g_strdup_printf (_("%.1f MB"), (gdouble) memsize / 1024.0);
}
else if (memsize < 1024 * 1024)
{
return g_strdup_printf (_("%d MB"), (gint) memsize / 1024);
}
memsize /= 1024;
if (memsize < 1024 * 10)
{
return g_strdup_printf (_("%.2f GB"), (gdouble) memsize / 1024.0);
}
else if (memsize < 1024 * 100)
{
return g_strdup_printf (_("%.1f GB"), (gdouble) memsize / 1024.0);
}
else
{
memsize /= 1024;
return g_strdup_printf (_("%.1f MB"), (gdouble) memsize / 1024.0);
return g_strdup_printf (_("%d GB"), (gint) memsize / 1024);
}
}

View File

@ -28,7 +28,7 @@ gchar * gimp_any_to_utf8 (const gchar *str,
const gchar *warning_format,
...) G_GNUC_PRINTF (3, 4);
gchar * gimp_memsize_to_string (gulong memsize);
gchar * gimp_memsize_to_string (guint64 memsize);
gchar * gimp_strip_uline (const gchar *str);