]> www.fi.muni.cz Git - evince.git/blobdiff - properties/ev-properties-view.c
[dualscreen] fix crash on ctrl+w and fix control window closing
[evince.git] / properties / ev-properties-view.c
index 4162fddd3dc8bbe8049c6d3f92e6ba1cbfbfba3d..dba2bb0c3d410e2b0b0e6cd32260e99e80672834 100644 (file)
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
-#ifdef HAVE_CONFIG_H
 #include "config.h"
-#endif
-
-#include "ev-properties-view.h"
-#include "ev-document-fonts.h"
 
-#include <glib/gi18n.h>
-#include <gtk/gtk.h>
-#include <gtk/gtkversion.h>
-#include <glade/glade.h>
-#include <time.h>
-#include <sys/time.h>
 #include <string.h>
+#include <sys/time.h>
+#include <time.h>
 
 #ifdef HAVE__NL_MEASUREMENT_MEASUREMENT
 #include <langinfo.h>
 #endif
 
-typedef enum
-{
+#include <glib/gi18n-lib.h>
+#include <gtk/gtk.h>
+
+#include "ev-properties-view.h"
+
+typedef enum {
        TITLE_PROPERTY,
+       URI_PROPERTY,
        SUBJECT_PROPERTY,
        AUTHOR_PROPERTY,
        KEYWORDS_PROPERTY,
@@ -51,35 +47,38 @@ typedef enum
        LINEARIZED_PROPERTY,
        FORMAT_PROPERTY,
        SECURITY_PROPERTY,
-       PAPER_SIZE_PROPERTY
+       PAPER_SIZE_PROPERTY,
+       N_PROPERTIES
 } Property;
 
-typedef struct
-{
+typedef struct {
        Property property;
-       const char *label_id;
+       const char *label;
 } PropertyInfo;
 
 static const PropertyInfo properties_info[] = {
-       { TITLE_PROPERTY, "title" },
-       { SUBJECT_PROPERTY, "subject" },
-       { AUTHOR_PROPERTY, "author" },
-       { KEYWORDS_PROPERTY, "keywords" },
-       { PRODUCER_PROPERTY, "producer" },
-       { CREATOR_PROPERTY, "creator" },
-       { CREATION_DATE_PROPERTY, "created" },
-       { MOD_DATE_PROPERTY, "modified" },
-       { N_PAGES_PROPERTY, "pages" },
-       { LINEARIZED_PROPERTY, "optimized" },
-       { FORMAT_PROPERTY, "version" },
-       { SECURITY_PROPERTY, "security" },
-       { PAPER_SIZE_PROPERTY, "papersize" }
+       { TITLE_PROPERTY,         N_("Title:") },
+       { URI_PROPERTY,           N_("Location:") },
+       { SUBJECT_PROPERTY,       N_("Subject:") },
+       { AUTHOR_PROPERTY,        N_("Author:") },
+       { KEYWORDS_PROPERTY,      N_("Keywords:") },
+       { PRODUCER_PROPERTY,      N_("Producer:") },
+       { CREATOR_PROPERTY,       N_("Creator:") },
+       { CREATION_DATE_PROPERTY, N_("Created:") },
+       { MOD_DATE_PROPERTY,      N_("Modified:") },
+       { N_PAGES_PROPERTY,       N_("Number of Pages:") },
+       { LINEARIZED_PROPERTY,    N_("Optimized:") },
+       { FORMAT_PROPERTY,        N_("Format:") },
+       { SECURITY_PROPERTY,      N_("Security:") },
+       { PAPER_SIZE_PROPERTY,    N_("Paper Size:") }
 };
 
 struct _EvPropertiesView {
        GtkVBox base_instance;
 
-       GladeXML *xml;
+       GtkWidget *table;
+       GtkWidget *labels[N_PROPERTIES];
+       gchar     *uri;
 };
 
 struct _EvPropertiesViewClass {
@@ -92,12 +91,12 @@ static void
 ev_properties_view_dispose (GObject *object)
 {
        EvPropertiesView *properties = EV_PROPERTIES_VIEW (object);
-
-       if (properties->xml) {
-               g_object_unref (properties->xml);
-               properties->xml = NULL;
+       
+       if (properties->uri) {
+               g_free (properties->uri);
+               properties->uri = NULL;
        }
-
+       
        G_OBJECT_CLASS (ev_properties_view_parent_class)->dispose (object);
 }
 
@@ -109,24 +108,6 @@ ev_properties_view_class_init (EvPropertiesViewClass *properties_class)
        g_object_class->dispose = ev_properties_view_dispose;
 }
 
-/* Returns a locale specific date and time representation */
-static char *
-ev_properties_view_format_date (GTime utime)
-{
-       time_t time = (time_t) utime;
-       struct tm t;
-       char s[256];
-       const char *fmt_hack = "%c";
-       size_t len;
-
-       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;
-
-       return g_locale_to_utf8 (s, -1, NULL, NULL, NULL);
-}
-
 /* This is cut out of gconvert.c from glib (and mildly modified).  Not all
    backends give valid UTF-8 for properties, so we make sure that is.
  */
@@ -168,33 +149,62 @@ make_valid_utf8 (const gchar *name)
 }
 
 static void
-set_property (GladeXML *xml, Property property, const char *text)
+set_property (EvPropertiesView *properties,
+             GtkTable         *table,
+             Property          property,
+             const gchar      *text,
+             gint             *row)
 {
-       GtkWidget *widget;
-       char *valid_text;
+       GtkWidget *label;
+       gchar     *markup;
+       gchar     *valid_text;
+
+       if (!properties->labels[property]) {
+               label = gtk_label_new (NULL);
+               g_object_set (G_OBJECT (label), "xalign", 0.0, NULL);
+               markup = g_strdup_printf ("<b>%s</b>", _(properties_info[property].label));
+               gtk_label_set_markup (GTK_LABEL (label), markup);
+               g_free (markup);
+
+               gtk_table_attach (table, label, 0, 1, *row, *row + 1,
+                                 GTK_FILL, GTK_FILL, 0, 0);
+               gtk_widget_show (label);
+       }
 
-       widget = glade_xml_get_widget (xml, properties_info[property].label_id);
-       g_return_if_fail (GTK_IS_LABEL (widget));
+       if (!properties->labels[property]) {
+               label = gtk_label_new (NULL);
 
-       if (text == NULL || text[0] == '\000') {
-               gchar *markup;
+               g_object_set (G_OBJECT (label),
+                             "xalign", 0.0,
+                             "width_chars", 25,
+                             "selectable", TRUE,
+                             "ellipsize", PANGO_ELLIPSIZE_END,
+                             NULL);
+       } else {
+               label = properties->labels[property];
+       }
 
+       if (text == NULL || text[0] == '\000') {
                markup = g_markup_printf_escaped ("<i>%s</i>", _("None"));
-               gtk_label_set_markup (GTK_LABEL (widget), markup);
+               gtk_label_set_markup (GTK_LABEL (label), markup);
                g_free (markup);
-
-               return;
+       } else {
+               valid_text = make_valid_utf8 (text ? text : "");
+               gtk_label_set_text (GTK_LABEL (label), valid_text);
+               g_free (valid_text);
        }
-       text = text ? text : "";
 
-       valid_text = make_valid_utf8 (text);
+       if (!properties->labels[property]) {
+               gtk_table_attach (table, label, 1, 2, *row, *row + 1,
+                                 GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);
+               properties->labels[property] = label;
+       }
 
-       gtk_label_set_text (GTK_LABEL (widget), valid_text);
+       gtk_widget_show (label);
 
-       g_free (valid_text);
+       *row += 1;
 }
 
-#if GTK_CHECK_VERSION (2, 11, 0)
 static GtkUnit
 get_default_user_units (void)
 {
@@ -248,11 +258,11 @@ ev_regular_paper_size (const EvDocumentInfo *info)
        units = get_default_user_units ();
 
        if (units == GTK_UNIT_MM) {
-               exact_size = g_strdup_printf(_("%.0f x %.0f mm"),
+               exact_size = g_strdup_printf(_("%.0f × %.0f mm"),
                                             info->paper_width,
                                             info->paper_height);
        } else {
-               exact_size = g_strdup_printf (_("%.2f x %.2f inch"),
+               exact_size = g_strdup_printf (_("%.2f × %.2f inch"),
                                              info->paper_width  / 25.4f,
                                              info->paper_height / 25.4f);
        }
@@ -299,195 +309,62 @@ ev_regular_paper_size (const EvDocumentInfo *info)
        
        return exact_size;
 }
-#else /* ! GTK 2.11.0 */
-/*
- * All values are in mm. 
- * Source: http://en.wikipedia.org/wiki/Paper_size
- */
-struct regular_paper_size {
-       double width;
-       double height;
-       double width_tolerance;
-       double height_tolerance;
-       const char *description;
-} const regular_paper_sizes[] = {
-       // ISO 216 paper sizes
-       {  841.0f, 1189.0f, 3.0f, 3.0f, "A0"  },
-       {  594.0f,  841.0f, 2.0f, 3.0f, "A1"  },
-       {  420.0f,  594.0f, 2.0f, 2.0f, "A2"  },
-       {  297.0f,  420.0f, 2.0f, 2.0f, "A3"  },
-       {  210.0f,  297.0f, 2.0f, 2.0f, "A4"  },
-       {  148.0f,  210.0f, 1.5f, 2.0f, "A5"  },
-       {  105.0f,  148.0f, 1.5f, 1.5f, "A6"  },
-       {   74.0f,  105.0f, 1.5f, 1.5f, "A7"  },
-       {   52.0f,   74.0f, 1.5f, 1.5f, "A8"  },
-       {   37.0f,   52.0f, 1.5f, 1.5f, "A9"  },
-       {   26.0f,   37.0f, 1.5f, 1.5f, "A10" },
-       { 1000.0f, 1414.0f, 3.0f, 3.0f, "B0"  },
-       {  707.0f, 1000.0f, 3.0f, 3.0f, "B1"  },
-       {  500.0f,  707.0f, 2.0f, 3.0f, "B2"  },
-       {  353.0f,  500.0f, 2.0f, 2.0f, "B3"  },
-       {  250.0f,  353.0f, 2.0f, 2.0f, "B4"  },
-       {  176.0f,  250.0f, 2.0f, 2.0f, "B5"  },
-       {  125.0f,  176.0f, 1.5f, 2.0f, "B6"  },
-       {   88.0f,  125.0f, 1.5f, 1.5f, "B7"  },
-       {   62.0f,   88.0f, 1.5f, 1.5f, "B8"  },
-       {   44.0f,   62.0f, 1.5f, 1.5f, "B9"  },
-       {   31.0f,   44.0f, 1.5f, 1.5f, "B10" },
-       {  917.0f, 1297.0f, 3.0f, 3.0f, "C0"  },
-       {  648.0f,  917.0f, 3.0f, 3.0f, "C1"  },
-       {  458.0f,  648.0f, 2.0f, 3.0f, "C2"  },
-       {  324.0f,  458.0f, 2.0f, 2.0f, "C3"  },
-       {  229.0f,  324.0f, 2.0f, 2.0f, "C4"  },
-       {  162.0f,  229.0f, 2.0f, 2.0f, "C5"  },
-       {  114.0f,  162.0f, 1.5f, 2.0f, "C6"  },
-       {   81.0f,  114.0f, 1.5f, 1.5f, "C7"  },
-       {   57.0f,   81.0f, 1.5f, 1.5f, "C8"  },
-       {   40.0f,   57.0f, 1.5f, 1.5f, "C9"  },
-       {   28.0f,   40.0f, 1.5f, 1.5f, "C10" },
-
-       // US paper sizes
-       {  279.0f,  216.0f, 3.0f, 3.0f, "Letter" },
-       {  356.0f,  216.0f, 3.0f, 3.0f, "Legal"  },
-       {  432.0f,  279.0f, 3.0f, 3.0f, "Ledger" }
-};
-
-typedef enum {
-  EV_UNIT_INCH,
-  EV_UNIT_MM
-} EvUnit; 
-
-static EvUnit
-ev_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 EV_UNIT_INCH;  /* imperial */
-  if (imperial && imperial[0] == 1 )
-    return EV_UNIT_MM;  /* metric */
-#endif
-
-  if (strcmp (e, "default:inch")==0)
-    return EV_UNIT_INCH;
-  else if (strcmp (e, "default:mm"))
-    g_warning ("Whoever translated default:mm did so wrongly.\n");
-  return EV_UNIT_MM;
-}
-
-static char *
-ev_regular_paper_size (const EvDocumentInfo *info)
-{
-       const struct regular_paper_size *size;   
-       EvUnit unit;
-       char *exact_size = NULL;
-       char *str = NULL;
-       int i;
-
-       unit = ev_get_default_user_units ();    
-
-       if (unit == EV_UNIT_INCH)
-               /* Imperial measurement (inches) */
-               exact_size = g_strdup_printf( _("%.2f x %.2f in"),
-                                             info->paper_width  / 25.4f,
-                                             info->paper_height / 25.4f );
-       else
-               /* Metric measurement (millimeters) */
-               exact_size = g_strdup_printf( _("%.0f x %.0f mm"),
-                                             info->paper_width,
-                                             info->paper_height );
-       
-       for (i = G_N_ELEMENTS ( regular_paper_sizes ) - 1; i >= 0; i--) {
-               size = &regular_paper_sizes[i];
-
-               if ( ABS( info->paper_height - size->height ) <= size->height_tolerance &&
-                    ABS( info->paper_width  - size->width  ) <= size->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)"),
-                                               size->description,
-                                               exact_size );
-               } else if ( ABS( info->paper_width  - size->height ) <= size->height_tolerance &&
-                           ABS( info->paper_height - size->width  ) <= size->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)"),
-                                               size->description,
-                                               exact_size );
-               }
-       }
-
-       if (str != NULL) {
-               g_free (exact_size);
-               return str;
-       } else
-               return exact_size;
-}
-#endif /* GTK 2.11.0 */
 
 void
 ev_properties_view_set_info (EvPropertiesView *properties, const EvDocumentInfo *info)
 {
-       GladeXML *xml = properties->xml;
-       char *text;
+       GtkWidget *table;
+       gchar     *text;
+       gint       row = 0;
+
+       table = properties->table;
 
        if (info->fields_mask & EV_DOCUMENT_INFO_TITLE) {
-               set_property (xml, TITLE_PROPERTY, info->title);
+               set_property (properties, GTK_TABLE (table), TITLE_PROPERTY, info->title, &row);
        }
+       set_property (properties, GTK_TABLE (table), URI_PROPERTY, properties->uri, &row);
        if (info->fields_mask & EV_DOCUMENT_INFO_SUBJECT) {
-               set_property (xml, SUBJECT_PROPERTY, info->subject);
+               set_property (properties, GTK_TABLE (table), SUBJECT_PROPERTY, info->subject, &row);
        }
        if (info->fields_mask & EV_DOCUMENT_INFO_AUTHOR) {
-               set_property (xml, AUTHOR_PROPERTY, info->author);
+               set_property (properties, GTK_TABLE (table), AUTHOR_PROPERTY, info->author, &row);
        }
        if (info->fields_mask & EV_DOCUMENT_INFO_KEYWORDS) {
-               set_property (xml, KEYWORDS_PROPERTY, info->keywords);
+               set_property (properties, GTK_TABLE (table), KEYWORDS_PROPERTY, info->keywords, &row);
        }
        if (info->fields_mask & EV_DOCUMENT_INFO_PRODUCER) {
-               set_property (xml, PRODUCER_PROPERTY, info->producer);
+               set_property (properties, GTK_TABLE (table), PRODUCER_PROPERTY, info->producer, &row);
        }
        if (info->fields_mask & EV_DOCUMENT_INFO_CREATOR) {
-               set_property (xml, CREATOR_PROPERTY, info->creator);
+               set_property (properties, GTK_TABLE (table), CREATOR_PROPERTY, info->creator, &row);
        }
        if (info->fields_mask & EV_DOCUMENT_INFO_CREATION_DATE) {
-               text = ev_properties_view_format_date (info->creation_date);
-               set_property (xml, CREATION_DATE_PROPERTY, text);
+               text = ev_document_misc_format_date (info->creation_date);
+               set_property (properties, GTK_TABLE (table), CREATION_DATE_PROPERTY, text, &row);
                g_free (text);
        }
        if (info->fields_mask & EV_DOCUMENT_INFO_MOD_DATE) {
-               text = ev_properties_view_format_date (info->modified_date);
-               set_property (xml, MOD_DATE_PROPERTY, text);
+               text = ev_document_misc_format_date (info->modified_date);
+               set_property (properties, GTK_TABLE (table), MOD_DATE_PROPERTY, text, &row);
                g_free (text);
        }
        if (info->fields_mask & EV_DOCUMENT_INFO_FORMAT) {
-               text = g_strdup_printf ("%s", info->format);
-               set_property (xml, FORMAT_PROPERTY, text);
-               g_free (text);
+               set_property (properties, GTK_TABLE (table), FORMAT_PROPERTY, info->format, &row);
        }
        if (info->fields_mask & EV_DOCUMENT_INFO_N_PAGES) {
                text = g_strdup_printf ("%d", info->n_pages);
-               set_property (xml, N_PAGES_PROPERTY, text);
+               set_property (properties, GTK_TABLE (table), N_PAGES_PROPERTY, text, &row);
                g_free (text);
        }
        if (info->fields_mask & EV_DOCUMENT_INFO_LINEARIZED) {
-               set_property (xml, LINEARIZED_PROPERTY, info->linearized);
+               set_property (properties, GTK_TABLE (table), LINEARIZED_PROPERTY, info->linearized, &row);
        }
        if (info->fields_mask & EV_DOCUMENT_INFO_SECURITY) {
-               set_property (xml, SECURITY_PROPERTY, info->security);
+               set_property (properties, GTK_TABLE (table), SECURITY_PROPERTY, info->security, &row);
        }
        if (info->fields_mask & EV_DOCUMENT_INFO_PAPER_SIZE) {
                text = ev_regular_paper_size (info);
-               set_property (xml, PAPER_SIZE_PROPERTY, text);
+               set_property (properties, GTK_TABLE (table), PAPER_SIZE_PROPERTY, text, &row);
                g_free (text);
        }
 }
@@ -495,16 +372,13 @@ ev_properties_view_set_info (EvPropertiesView *properties, const EvDocumentInfo
 static void
 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", GETTEXT_PACKAGE);
-       properties->xml = xml;
-       g_assert (xml != NULL);
-
-       gtk_box_pack_start (GTK_BOX (properties),
-                           glade_xml_get_widget (xml, "general_page_root"),
+       properties->table = gtk_table_new (13, 2, FALSE);
+       gtk_table_set_col_spacings (GTK_TABLE (properties->table), 12);
+       gtk_table_set_row_spacings (GTK_TABLE (properties->table), 6);
+       gtk_container_set_border_width (GTK_CONTAINER (properties->table), 12);
+       gtk_box_pack_start (GTK_BOX (properties), properties->table, 
                            TRUE, TRUE, 0);
+       gtk_widget_show (properties->table);
 }
 
 void
@@ -514,11 +388,12 @@ ev_properties_view_register_type (GTypeModule *module)
 }
 
 GtkWidget *
-ev_properties_view_new (void)
+ev_properties_view_new (const gchar *uri)
 {
        EvPropertiesView *properties;
 
        properties = g_object_new (EV_TYPE_PROPERTIES, NULL);
+       properties->uri = g_strdup (uri);
 
        return GTK_WIDGET (properties);
 }