]> 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 1203157211c0a13a347dbcd6cf93ba0ff14b640f..dba2bb0c3d410e2b0b0e6cd32260e99e80672834 100644 (file)
@@ -15,7 +15,7 @@
  *
  * 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.
  */
 
 #include "config.h"
@@ -28,7 +28,7 @@
 #include <langinfo.h>
 #endif
 
-#include <glib/gi18n.h>
+#include <glib/gi18n-lib.h>
 #include <gtk/gtk.h>
 
 #include "ev-properties-view.h"
@@ -47,7 +47,8 @@ typedef enum {
        LINEARIZED_PROPERTY,
        FORMAT_PROPERTY,
        SECURITY_PROPERTY,
-       PAPER_SIZE_PROPERTY
+       PAPER_SIZE_PROPERTY,
+       N_PROPERTIES
 } Property;
 
 typedef struct {
@@ -56,26 +57,27 @@ typedef struct {
 } PropertyInfo;
 
 static const PropertyInfo properties_info[] = {
-       { 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") }
+       { 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;
 
        GtkWidget *table;
+       GtkWidget *labels[N_PROPERTIES];
        gchar     *uri;
 };
 
@@ -106,29 +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;
-       char s[256];
-       const char *fmt_hack = "%c";
-       size_t len;
-#ifdef HAVE_LOCALTIME_R
-       struct tm t;
-       if (time == 0 || !localtime_r (&time, &t)) return NULL;
-       len = strftime (s, sizeof (s), fmt_hack, &t);
-#else
-       struct tm *t;
-       if (time == 0 || !(t = localtime (&time)) ) return NULL;
-       len = strftime (s, sizeof (s), fmt_hack, t);
-#endif
-
-       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.
  */
@@ -170,33 +149,40 @@ make_valid_utf8 (const gchar *name)
 }
 
 static void
-set_property (GtkTable    *table,
-             Property     property,
-             const gchar *text,
-             gint        *row)
+set_property (EvPropertiesView *properties,
+             GtkTable         *table,
+             Property          property,
+             const gchar      *text,
+             gint             *row)
 {
        GtkWidget *label;
        gchar     *markup;
        gchar     *valid_text;
 
-       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);
+       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);
 
-       label = gtk_label_new (NULL);
-       g_object_set (G_OBJECT (label),
-                     "xalign", 0.0,
-                     "width_chars", 25,
-                     "selectable", TRUE,
-                     "ellipsize", PANGO_ELLIPSIZE_END,
-                     NULL);
-       
+               gtk_table_attach (table, label, 0, 1, *row, *row + 1,
+                                 GTK_FILL, GTK_FILL, 0, 0);
+               gtk_widget_show (label);
+       }
+
+       if (!properties->labels[property]) {
+               label = gtk_label_new (NULL);
+
+               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"));
@@ -208,8 +194,12 @@ set_property (GtkTable    *table,
                g_free (valid_text);
        }
 
-       gtk_table_attach (table, label, 1, 2, *row, *row + 1,
-                         GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);
+       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_widget_show (label);
 
        *row += 1;
@@ -268,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);
        }
@@ -330,51 +320,51 @@ ev_properties_view_set_info (EvPropertiesView *properties, const EvDocumentInfo
        table = properties->table;
 
        if (info->fields_mask & EV_DOCUMENT_INFO_TITLE) {
-               set_property (GTK_TABLE (table), TITLE_PROPERTY, info->title, &row);
+               set_property (properties, GTK_TABLE (table), TITLE_PROPERTY, info->title, &row);
        }
-       set_property (GTK_TABLE (table), URI_PROPERTY, properties->uri, &row);
+       set_property (properties, GTK_TABLE (table), URI_PROPERTY, properties->uri, &row);
        if (info->fields_mask & EV_DOCUMENT_INFO_SUBJECT) {
-               set_property (GTK_TABLE (table), SUBJECT_PROPERTY, info->subject, &row);
+               set_property (properties, GTK_TABLE (table), SUBJECT_PROPERTY, info->subject, &row);
        }
        if (info->fields_mask & EV_DOCUMENT_INFO_AUTHOR) {
-               set_property (GTK_TABLE (table), AUTHOR_PROPERTY, info->author, &row);
+               set_property (properties, GTK_TABLE (table), AUTHOR_PROPERTY, info->author, &row);
        }
        if (info->fields_mask & EV_DOCUMENT_INFO_KEYWORDS) {
-               set_property (GTK_TABLE (table), KEYWORDS_PROPERTY, info->keywords, &row);
+               set_property (properties, GTK_TABLE (table), KEYWORDS_PROPERTY, info->keywords, &row);
        }
        if (info->fields_mask & EV_DOCUMENT_INFO_PRODUCER) {
-               set_property (GTK_TABLE (table), PRODUCER_PROPERTY, info->producer, &row);
+               set_property (properties, GTK_TABLE (table), PRODUCER_PROPERTY, info->producer, &row);
        }
        if (info->fields_mask & EV_DOCUMENT_INFO_CREATOR) {
-               set_property (GTK_TABLE (table), CREATOR_PROPERTY, info->creator, &row);
+               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 (GTK_TABLE (table), CREATION_DATE_PROPERTY, text, &row);
+               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 (GTK_TABLE (table), MOD_DATE_PROPERTY, text, &row);
+               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) {
-               set_property (GTK_TABLE (table), FORMAT_PROPERTY, info->format, &row);
+               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 (GTK_TABLE (table), N_PAGES_PROPERTY, text, &row);
+               set_property (properties, GTK_TABLE (table), N_PAGES_PROPERTY, text, &row);
                g_free (text);
        }
        if (info->fields_mask & EV_DOCUMENT_INFO_LINEARIZED) {
-               set_property (GTK_TABLE (table), LINEARIZED_PROPERTY, info->linearized, &row);
+               set_property (properties, GTK_TABLE (table), LINEARIZED_PROPERTY, info->linearized, &row);
        }
        if (info->fields_mask & EV_DOCUMENT_INFO_SECURITY) {
-               set_property (GTK_TABLE (table), SECURITY_PROPERTY, info->security, &row);
+               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 (GTK_TABLE (table), PAPER_SIZE_PROPERTY, text, &row);
+               set_property (properties, GTK_TABLE (table), PAPER_SIZE_PROPERTY, text, &row);
                g_free (text);
        }
 }