]> www.fi.muni.cz Git - evince.git/blobdiff - properties/ev-properties-view.c
Updated German translation.
[evince.git] / properties / ev-properties-view.c
index 70c337e2dfbeb001359ba7673867a148590ac986..e4bdd3f25252da824d74863b97ed1dcc46d13c0b 100644 (file)
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
  */
 
-#ifdef HAVE_CONFIG_H
 #include "config.h"
-#endif
 
-#include "ev-properties-view.h"
-#include "ev-document-fonts.h"
+#include <string.h>
+#include <sys/time.h>
+#include <time.h>
+
+#ifdef HAVE__NL_MEASUREMENT_MEASUREMENT
+#include <langinfo.h>
+#endif
 
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
 #include <glade/glade.h>
-#include <time.h>
-#include <sys/time.h>
-#include <string.h>
+
+#include "ev-properties-view.h"
+#include "ev-document-fonts.h"
 
 typedef enum
 {
@@ -45,7 +48,8 @@ typedef enum
        N_PAGES_PROPERTY,
        LINEARIZED_PROPERTY,
        FORMAT_PROPERTY,
-       SECURITY_PROPERTY
+       SECURITY_PROPERTY,
+       PAPER_SIZE_PROPERTY
 } Property;
 
 typedef struct
@@ -66,7 +70,8 @@ static const PropertyInfo properties_info[] = {
        { N_PAGES_PROPERTY, "pages" },
        { LINEARIZED_PROPERTY, "optimized" },
        { FORMAT_PROPERTY, "version" },
-       { SECURITY_PROPERTY, "security" }
+       { SECURITY_PROPERTY, "security" },
+       { PAPER_SIZE_PROPERTY, "papersize" }
 };
 
 struct _EvPropertiesView {
@@ -90,6 +95,8 @@ ev_properties_view_dispose (GObject *object)
                g_object_unref (properties->xml);
                properties->xml = NULL;
        }
+
+       G_OBJECT_CLASS (ev_properties_view_parent_class)->dispose (object);
 }
 
 static void
@@ -110,7 +117,7 @@ ev_properties_view_format_date (GTime utime)
        const char *fmt_hack = "%c";
        size_t len;
 
-       if (!localtime_r (&time, &t)) return NULL;
+       if (time == 0 || !localtime_r (&time, &t)) return NULL;
 
        len = strftime (s, sizeof (s), fmt_hack, &t);
        if (len == 0 || s[0] == '\0') return NULL;
@@ -185,6 +192,111 @@ set_property (GladeXML *xml, Property property, const char *text)
        g_free (valid_text);
 }
 
+static GtkUnit
+get_default_user_units (void)
+{
+       /* Translate to the default units to use for presenting
+        * lengths to the user. Translate to default:inch if you
+        * want inches, otherwise translate to default:mm.
+        * Do *not* translate it to "predefinito:mm", if it
+        * it isn't default:mm or default:inch it will not work
+        */
+       gchar *e = _("default:mm");
+
+#ifdef HAVE__NL_MEASUREMENT_MEASUREMENT
+       gchar *imperial = NULL;
+       
+       imperial = nl_langinfo (_NL_MEASUREMENT_MEASUREMENT);
+       if (imperial && imperial[0] == 2)
+               return GTK_UNIT_INCH;  /* imperial */
+       if (imperial && imperial[0] == 1)
+               return GTK_UNIT_MM;  /* metric */
+#endif
+
+       if (strcmp (e, "default:mm") == 0)
+               return GTK_UNIT_MM;
+       if (strcmp (e, "default:inch") == 0)
+               return GTK_UNIT_INCH;
+       
+       g_warning ("Whoever translated default:mm did so wrongly.\n");
+                               
+       return GTK_UNIT_MM;
+}
+
+static gdouble
+get_tolerance (gdouble size)
+{
+       if (size < 150.0f)
+               return 1.5f;
+       else if (size >= 150.0f && size <= 600.0f)
+               return 2.0f;
+       else
+               return 3.0f;
+}
+
+static char *
+ev_regular_paper_size (const EvDocumentInfo *info)
+{
+       GList *paper_sizes, *l;
+       gchar *exact_size;
+       gchar *str = NULL;
+       GtkUnit units;
+
+       units = get_default_user_units ();
+
+       if (units == GTK_UNIT_MM) {
+               exact_size = g_strdup_printf(_("%.0f x %.0f mm"),
+                                            info->paper_width,
+                                            info->paper_height);
+       } else {
+               exact_size = g_strdup_printf (_("%.2f x %.2f inch"),
+                                             info->paper_width  / 25.4f,
+                                             info->paper_height / 25.4f);
+       }
+
+       paper_sizes = gtk_paper_size_get_paper_sizes (FALSE);
+       
+       for (l = paper_sizes; l && l->data; l = g_list_next (l)) {
+               GtkPaperSize *size = (GtkPaperSize *) l->data;
+               gdouble paper_width;
+               gdouble paper_height;
+               gdouble width_tolerance;
+               gdouble height_tolerance;
+
+               paper_width = gtk_paper_size_get_width (size, GTK_UNIT_MM);
+               paper_height = gtk_paper_size_get_height (size, GTK_UNIT_MM);
+
+               width_tolerance = get_tolerance (paper_width);
+               height_tolerance = get_tolerance (paper_height);
+
+               if (ABS (info->paper_height - paper_height) <= height_tolerance &&
+                   ABS (info->paper_width  - paper_width) <= width_tolerance) {
+                       /* Note to translators: first placeholder is the paper name (eg.
+                        * A4), second placeholder is the paper size (eg. 297x210 mm) */
+                       str = g_strdup_printf (_("%s, Portrait (%s)"),
+                                              gtk_paper_size_get_display_name (size),
+                                              exact_size);
+               } else if (ABS (info->paper_width  - paper_height) <= height_tolerance &&
+                          ABS (info->paper_height - paper_width) <= width_tolerance) {
+                       /* Note to translators: first placeholder is the paper name (eg.
+                        * A4), second placeholder is the paper size (eg. 297x210 mm) */
+                       str = g_strdup_printf ( _("%s, Landscape (%s)"),
+                                               gtk_paper_size_get_display_name (size),
+                                               exact_size);
+               }
+       }
+
+       g_list_foreach (paper_sizes, (GFunc) gtk_paper_size_free, NULL);
+       g_list_free (paper_sizes);
+
+       if (str != NULL) {
+               g_free (exact_size);
+               return str;
+       }
+       
+       return exact_size;
+}
+
 void
 ev_properties_view_set_info (EvPropertiesView *properties, const EvDocumentInfo *info)
 {
@@ -222,6 +334,7 @@ ev_properties_view_set_info (EvPropertiesView *properties, const EvDocumentInfo
        if (info->fields_mask & EV_DOCUMENT_INFO_FORMAT) {
                text = g_strdup_printf ("%s", info->format);
                set_property (xml, FORMAT_PROPERTY, text);
+               g_free (text);
        }
        if (info->fields_mask & EV_DOCUMENT_INFO_N_PAGES) {
                text = g_strdup_printf ("%d", info->n_pages);
@@ -234,6 +347,11 @@ ev_properties_view_set_info (EvPropertiesView *properties, const EvDocumentInfo
        if (info->fields_mask & EV_DOCUMENT_INFO_SECURITY) {
                set_property (xml, SECURITY_PROPERTY, info->security);
        }
+       if (info->fields_mask & EV_DOCUMENT_INFO_PAPER_SIZE) {
+               text = ev_regular_paper_size (info);
+               set_property (xml, PAPER_SIZE_PROPERTY, text);
+               g_free (text);
+       }
 }
 
 static void
@@ -242,7 +360,7 @@ ev_properties_view_init (EvPropertiesView *properties)
        GladeXML *xml;
 
        /* Create a new GladeXML object from XML file glade_file */
-       xml = glade_xml_new (DATADIR "/evince-properties.glade", "general_page_root", NULL);
+       xml = glade_xml_new (DATADIR "/evince-properties.glade", "general_page_root", GETTEXT_PACKAGE);
        properties->xml = xml;
        g_assert (xml != NULL);