Evince
Evince is a document viewer capable of displaying multiple and single page document formats like PDF and Postscript.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ev-properties-view.c File Reference
#include "config.h"
#include <string.h>
#include <sys/time.h>
#include <time.h>
#include <glib/gi18n-lib.h>
#include <gtk/gtk.h>
#include "ev-properties-view.h"
+ Include dependency graph for ev-properties-view.c:

Go to the source code of this file.

Data Structures

struct  PropertyInfo
 
struct  _EvPropertiesView
 
struct  _EvPropertiesViewClass
 

Enumerations

enum  Property {
  TITLE_PROPERTY, URI_PROPERTY, SUBJECT_PROPERTY, AUTHOR_PROPERTY,
  KEYWORDS_PROPERTY, PRODUCER_PROPERTY, CREATOR_PROPERTY, CREATION_DATE_PROPERTY,
  MOD_DATE_PROPERTY, N_PAGES_PROPERTY, LINEARIZED_PROPERTY, FORMAT_PROPERTY,
  SECURITY_PROPERTY, PAPER_SIZE_PROPERTY, FILE_SIZE_PROPERTY, N_PROPERTIES
}
 

Functions

static void ev_properties_view_dispose (GObject *object)
 
static void ev_properties_view_class_init (EvPropertiesViewClass *properties_class)
 
static gchar * make_valid_utf8 (const gchar *name)
 
static void set_property (EvPropertiesView *properties, GtkGrid *grid, Property property, const gchar *text, gint *row)
 
static GtkUnit get_default_user_units (void)
 
static gdouble get_tolerance (gdouble size)
 
static char * ev_regular_paper_size (const EvDocumentInfo *info)
 
void ev_properties_view_set_info (EvPropertiesView *properties, const EvDocumentInfo *info)
 
static void ev_properties_view_init (EvPropertiesView *properties)
 
void ev_properties_view_register_type (GTypeModule *module)
 
GtkWidget * ev_properties_view_new (EvDocument *document)
 

Variables

static const PropertyInfo properties_info []
 

Enumeration Type Documentation

enum Property
Enumerator
TITLE_PROPERTY 
URI_PROPERTY 
SUBJECT_PROPERTY 
AUTHOR_PROPERTY 
KEYWORDS_PROPERTY 
PRODUCER_PROPERTY 
CREATOR_PROPERTY 
CREATION_DATE_PROPERTY 
MOD_DATE_PROPERTY 
N_PAGES_PROPERTY 
LINEARIZED_PROPERTY 
FORMAT_PROPERTY 
SECURITY_PROPERTY 
PAPER_SIZE_PROPERTY 
FILE_SIZE_PROPERTY 
N_PROPERTIES 

Definition at line 36 of file ev-properties-view.c.

Function Documentation

static void ev_properties_view_class_init ( EvPropertiesViewClass properties_class)
static

Definition at line 107 of file ev-properties-view.c.

108 {
109  GObjectClass *g_object_class = G_OBJECT_CLASS (properties_class);
110 
111  g_object_class->dispose = ev_properties_view_dispose;
112 }
static void ev_properties_view_dispose ( GObject *  object)
static

Definition at line 94 of file ev-properties-view.c.

95 {
97 
98  if (properties->uri) {
99  g_free (properties->uri);
100  properties->uri = NULL;
101  }
102 
103  G_OBJECT_CLASS (ev_properties_view_parent_class)->dispose (object);
104 }

+ Here is the caller graph for this function:

static void ev_properties_view_init ( EvPropertiesView properties)
static

Definition at line 394 of file ev-properties-view.c.

395 {
396  properties->grid = gtk_grid_new ();
397  gtk_grid_set_column_spacing (GTK_GRID (properties->grid), 12);
398  gtk_grid_set_row_spacing (GTK_GRID (properties->grid), 6);
399  gtk_container_set_border_width (GTK_CONTAINER (properties->grid), 12);
400  gtk_box_pack_start (GTK_BOX (properties), properties->grid, TRUE, TRUE, 0);
401  gtk_widget_show (properties->grid);
402 }
GtkWidget* ev_properties_view_new ( EvDocument document)

Definition at line 411 of file ev-properties-view.c.

412 {
414 
415  properties = g_object_new (EV_TYPE_PROPERTIES,
416  "orientation", GTK_ORIENTATION_VERTICAL,
417  NULL);
418  properties->uri = g_uri_unescape_string (ev_document_get_uri (document), NULL);
419  properties->file_size = ev_document_get_size (document);
420 
421  return GTK_WIDGET (properties);
422 }

+ Here is the caller graph for this function:

void ev_properties_view_register_type ( GTypeModule *  module)

Definition at line 405 of file ev-properties-view.c.

406 {
408 }

+ Here is the caller graph for this function:

void ev_properties_view_set_info ( EvPropertiesView properties,
const EvDocumentInfo info 
)

Definition at line 330 of file ev-properties-view.c.

331 {
332  GtkWidget *grid;
333  gchar *text;
334  gint row = 0;
335 
336  grid = properties->grid;
337 
338  if (info->fields_mask & EV_DOCUMENT_INFO_TITLE) {
339  set_property (properties, GTK_GRID (grid), TITLE_PROPERTY, info->title, &row);
340  }
341  set_property (properties, GTK_GRID (grid), URI_PROPERTY, properties->uri, &row);
342  if (info->fields_mask & EV_DOCUMENT_INFO_SUBJECT) {
343  set_property (properties, GTK_GRID (grid), SUBJECT_PROPERTY, info->subject, &row);
344  }
345  if (info->fields_mask & EV_DOCUMENT_INFO_AUTHOR) {
346  set_property (properties, GTK_GRID (grid), AUTHOR_PROPERTY, info->author, &row);
347  }
348  if (info->fields_mask & EV_DOCUMENT_INFO_KEYWORDS) {
349  set_property (properties, GTK_GRID (grid), KEYWORDS_PROPERTY, info->keywords, &row);
350  }
351  if (info->fields_mask & EV_DOCUMENT_INFO_PRODUCER) {
352  set_property (properties, GTK_GRID (grid), PRODUCER_PROPERTY, info->producer, &row);
353  }
354  if (info->fields_mask & EV_DOCUMENT_INFO_CREATOR) {
355  set_property (properties, GTK_GRID (grid), CREATOR_PROPERTY, info->creator, &row);
356  }
357  if (info->fields_mask & EV_DOCUMENT_INFO_CREATION_DATE) {
358  text = ev_document_misc_format_date (info->creation_date);
359  set_property (properties, GTK_GRID (grid), CREATION_DATE_PROPERTY, text, &row);
360  g_free (text);
361  }
362  if (info->fields_mask & EV_DOCUMENT_INFO_MOD_DATE) {
363  text = ev_document_misc_format_date (info->modified_date);
364  set_property (properties, GTK_GRID (grid), MOD_DATE_PROPERTY, text, &row);
365  g_free (text);
366  }
367  if (info->fields_mask & EV_DOCUMENT_INFO_FORMAT) {
368  set_property (properties, GTK_GRID (grid), FORMAT_PROPERTY, info->format, &row);
369  }
370  if (info->fields_mask & EV_DOCUMENT_INFO_N_PAGES) {
371  text = g_strdup_printf ("%d", info->n_pages);
372  set_property (properties, GTK_GRID (grid), N_PAGES_PROPERTY, text, &row);
373  g_free (text);
374  }
375  if (info->fields_mask & EV_DOCUMENT_INFO_LINEARIZED) {
376  set_property (properties, GTK_GRID (grid), LINEARIZED_PROPERTY, info->linearized, &row);
377  }
378  if (info->fields_mask & EV_DOCUMENT_INFO_SECURITY) {
379  set_property (properties, GTK_GRID (grid), SECURITY_PROPERTY, info->security, &row);
380  }
381  if (info->fields_mask & EV_DOCUMENT_INFO_PAPER_SIZE) {
382  text = ev_regular_paper_size (info);
383  set_property (properties, GTK_GRID (grid), PAPER_SIZE_PROPERTY, text, &row);
384  g_free (text);
385  }
386  if (properties->file_size) {
387  text = g_format_size (properties->file_size);
388  set_property (properties, GTK_GRID (grid), FILE_SIZE_PROPERTY, text, &row);
389  g_free (text);
390  }
391 }

+ Here is the caller graph for this function:

static char* ev_regular_paper_size ( const EvDocumentInfo info)
static

Definition at line 267 of file ev-properties-view.c.

268 {
269  GList *paper_sizes, *l;
270  gchar *exact_size;
271  gchar *str = NULL;
272  GtkUnit units;
273 
274  units = get_default_user_units ();
275 
276  if (units == GTK_UNIT_MM) {
277  exact_size = g_strdup_printf(_("%.0f × %.0f mm"),
278  info->paper_width,
279  info->paper_height);
280  } else {
281  exact_size = g_strdup_printf (_("%.2f × %.2f inch"),
282  info->paper_width / 25.4f,
283  info->paper_height / 25.4f);
284  }
285 
286  paper_sizes = gtk_paper_size_get_paper_sizes (FALSE);
287 
288  for (l = paper_sizes; l && l->data; l = g_list_next (l)) {
289  GtkPaperSize *size = (GtkPaperSize *) l->data;
290  gdouble paper_width;
291  gdouble paper_height;
292  gdouble width_tolerance;
293  gdouble height_tolerance;
294 
295  paper_width = gtk_paper_size_get_width (size, GTK_UNIT_MM);
296  paper_height = gtk_paper_size_get_height (size, GTK_UNIT_MM);
297 
298  width_tolerance = get_tolerance (paper_width);
299  height_tolerance = get_tolerance (paper_height);
300 
301  if (ABS (info->paper_height - paper_height) <= height_tolerance &&
302  ABS (info->paper_width - paper_width) <= width_tolerance) {
303  /* Note to translators: first placeholder is the paper name (eg.
304  * A4), second placeholder is the paper size (eg. 297x210 mm) */
305  str = g_strdup_printf (_("%s, Portrait (%s)"),
306  gtk_paper_size_get_display_name (size),
307  exact_size);
308  } else if (ABS (info->paper_width - paper_height) <= height_tolerance &&
309  ABS (info->paper_height - paper_width) <= width_tolerance) {
310  /* Note to translators: first placeholder is the paper name (eg.
311  * A4), second placeholder is the paper size (eg. 297x210 mm) */
312  str = g_strdup_printf ( _("%s, Landscape (%s)"),
313  gtk_paper_size_get_display_name (size),
314  exact_size);
315  }
316  }
317 
318  g_list_foreach (paper_sizes, (GFunc) gtk_paper_size_free, NULL);
319  g_list_free (paper_sizes);
320 
321  if (str != NULL) {
322  g_free (exact_size);
323  return str;
324  }
325 
326  return exact_size;
327 }

+ Here is the caller graph for this function:

static GtkUnit get_default_user_units ( void  )
static

Definition at line 225 of file ev-properties-view.c.

226 {
227  /* Translate to the default units to use for presenting
228  * lengths to the user. Translate to default:inch if you
229  * want inches, otherwise translate to default:mm.
230  * Do *not* translate it to "predefinito:mm", if it
231  * it isn't default:mm or default:inch it will not work
232  */
233  gchar *e = _("default:mm");
234 
235 #ifdef HAVE__NL_MEASUREMENT_MEASUREMENT
236  gchar *imperial = NULL;
237 
238  imperial = nl_langinfo (_NL_MEASUREMENT_MEASUREMENT);
239  if (imperial && imperial[0] == 2)
240  return GTK_UNIT_INCH; /* imperial */
241  if (imperial && imperial[0] == 1)
242  return GTK_UNIT_MM; /* metric */
243 #endif
244 
245  if (strcmp (e, "default:mm") == 0)
246  return GTK_UNIT_MM;
247  if (strcmp (e, "default:inch") == 0)
248  return GTK_UNIT_INCH;
249 
250  g_warning ("Whoever translated default:mm did so wrongly.\n");
251 
252  return GTK_UNIT_MM;
253 }

+ Here is the caller graph for this function:

static gdouble get_tolerance ( gdouble  size)
static

Definition at line 256 of file ev-properties-view.c.

257 {
258  if (size < 150.0f)
259  return 1.5f;
260  else if (size >= 150.0f && size <= 600.0f)
261  return 2.0f;
262  else
263  return 3.0f;
264 }

+ Here is the caller graph for this function:

static gchar* make_valid_utf8 ( const gchar *  name)
static

Definition at line 118 of file ev-properties-view.c.

119 {
120  GString *string;
121  const gchar *remainder, *invalid;
122  gint remaining_bytes, valid_bytes;
123 
124  string = NULL;
125  remainder = name;
126  remaining_bytes = strlen (name);
127 
128  while (remaining_bytes != 0)
129  {
130  if (g_utf8_validate (remainder, remaining_bytes, &invalid))
131  break;
132  valid_bytes = invalid - remainder;
133 
134  if (string == NULL)
135  string = g_string_sized_new (remaining_bytes);
136 
137  g_string_append_len (string, remainder, valid_bytes);
138  g_string_append_c (string, '?');
139 
140  remaining_bytes -= valid_bytes + 1;
141  remainder = invalid + 1;
142  }
143 
144  if (string == NULL)
145  return g_strdup (name);
146 
147  g_string_append (string, remainder);
148 
149  g_assert (g_utf8_validate (string->str, -1, NULL));
150 
151  return g_string_free (string, FALSE);
152 }

+ Here is the caller graph for this function:

static void set_property ( EvPropertiesView properties,
GtkGrid *  grid,
Property  property,
const gchar *  text,
gint *  row 
)
static

Definition at line 155 of file ev-properties-view.c.

160 {
161  GtkWidget *property_label = NULL;
162  GtkWidget *value_label = NULL;
163  gchar *markup;
164  gchar *valid_text;
165 
166  if (!properties->labels[property]) {
167  property_label = gtk_label_new (NULL);
168  g_object_set (G_OBJECT (property_label), "xalign", 0.0, NULL);
169  markup = g_strdup_printf ("<b>%s</b>", _(properties_info[property].label));
170  gtk_label_set_markup (GTK_LABEL (property_label), markup);
171  g_free (markup);
172 
173  gtk_grid_attach (grid, property_label, 0, *row, 1, 1);
174  gtk_widget_show (property_label);
175  }
176 
177  if (!properties->labels[property]) {
178  value_label = gtk_label_new (NULL);
179 
180  g_object_set (G_OBJECT (value_label),
181  "xalign", 0.0,
182  "width_chars", 25,
183  "selectable", TRUE,
184  "ellipsize", PANGO_ELLIPSIZE_END,
185  NULL);
186  } else {
187  value_label = properties->labels[property];
188  }
189 
190  if (text == NULL || text[0] == '\000') {
191  /* translators: This is used when a document property does
192  not have a value. Examples:
193  Author: None
194  Keywords: None
195  */
196  markup = g_markup_printf_escaped ("<i>%s</i>", _("None"));
197  gtk_label_set_markup (GTK_LABEL (value_label), markup);
198  g_free (markup);
199  } else {
200  valid_text = make_valid_utf8 (text ? text : "");
201  gtk_label_set_text (GTK_LABEL (value_label), valid_text);
202  g_free (valid_text);
203  }
204 
205  if (!properties->labels[property]) {
206  gtk_grid_attach (grid, value_label, 1, *row, 1, 1);
207  properties->labels[property] = value_label;
208  }
209 
210  if (property_label && value_label) {
211  atk_object_add_relationship (gtk_widget_get_accessible (property_label),
212  ATK_RELATION_LABEL_FOR,
213  gtk_widget_get_accessible (value_label));
214  atk_object_add_relationship (gtk_widget_get_accessible (value_label),
215  ATK_RELATION_LABELLED_BY,
216  gtk_widget_get_accessible (property_label));
217  }
218 
219  gtk_widget_show (value_label);
220 
221  *row += 1;
222 }

+ Here is the caller graph for this function:

Variable Documentation

const PropertyInfo properties_info[]
static
Initial value:
= {
{ 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:") },
{ FILE_SIZE_PROPERTY, N_("Size:") }
}

Definition at line 60 of file ev-properties-view.c.