# HG changeset patch
# User Tobias Westergaard Kjeldsen <tobias@wkjeldsen.dk>
# Date 1420993042 -3600
#      Sun Jan 11 17:17:22 2015 +0100
# Branch work
# Node ID 9a4c9607a216c890da7099bf66d68bf2842b5847
# Parent  12de1e5dd57da7e1fc50207f530f74a07a6ed320
Add file size "Size" in the file properties window.

diff -r 12de1e5dd57d -r 9a4c9607a216 properties/ev-properties-view.h
--- a/properties/ev-properties-view.h	Sun Jan 11 17:11:04 2015 +0100
+++ b/properties/ev-properties-view.h	Sun Jan 11 17:17:22 2015 +0100
@@ -41,7 +41,7 @@
 GType		ev_properties_view_get_type		(void);
 void		ev_properties_view_register_type	(GTypeModule *module);
 
-GtkWidget      *ev_properties_view_new			(EvDocument     *document);
+GtkWidget      *ev_properties_view_new			(EvDocument           *document);
 void		ev_properties_view_set_info		(EvPropertiesView     *properties,
 							 const EvDocumentInfo *info);
 
# HG changeset patch
# User Tobias Westergaard Kjeldsen <tobias@wkjeldsen.dk>
# Date 1420992664 -3600
#      Sun Jan 11 17:11:04 2015 +0100
# Branch work
# Node ID 12de1e5dd57da7e1fc50207f530f74a07a6ed320
# Parent  eb6fc4ff15a87a32075593d935d9669d3805ba25
Add file size "Size" in the file properties window.

diff -r eb6fc4ff15a8 -r 12de1e5dd57d libdocument/ev-document.c
--- a/libdocument/ev-document.c	Sun Jan 11 15:56:41 2015 +0100
+++ b/libdocument/ev-document.c	Sun Jan 11 17:11:04 2015 +0100
@@ -593,25 +593,30 @@
 static gchar *
 _ev_document_get_file_size_gfile (GFile *file, GError **error)
 {
+	goffset size = 0;
+
 	if (g_file_query_exists (file, NULL)) {
 		GFileInfo *info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_SIZE,
                                                      G_FILE_QUERY_INFO_NONE, NULL, error);
 
-		goffset size = g_file_info_get_size (info);
+		size = g_file_info_get_size (info);
 
-		g_object_unref (file);
 		g_object_unref (info);
+	}
 
-		return g_format_size (size);
-	}
-	return NULL;
+	return g_format_size (size);
 }
 
 static gchar *
 _ev_document_get_file_size (const char  *uri, GError **error)
 {
 	GFile *file = g_file_new_for_uri (uri);
-	return _ev_document_get_file_size_gfile (file, error);
+
+	gchar *size = _ev_document_get_file_size_gfile (file, error);
+
+	g_object_unref (file);
+
+	return size;
 }
 
 static gint
# HG changeset patch
# User Tobias Westergaard Kjeldsen <tobias@wkjeldsen.dk>
# Date 1420988201 -3600
#      Sun Jan 11 15:56:41 2015 +0100
# Branch work
# Node ID eb6fc4ff15a87a32075593d935d9669d3805ba25
# Parent  9a6b47f2f6bc600f744f0a25f9c6620f9db69a24
Add file size "Size" in the file properties window.

diff -r 9a6b47f2f6bc -r eb6fc4ff15a8 libdocument/ev-document-info.h
--- a/libdocument/ev-document-info.h	Sat Jan 10 23:56:15 2015 +0100
+++ b/libdocument/ev-document-info.h	Sun Jan 11 15:56:41 2015 +0100
@@ -125,7 +125,6 @@
 	double paper_height;
 	double paper_width;
 	EvDocumentLicense *license;
-	char *file_size; /* eg, 200KB */
 
 	/* Mask of all the valid fields */
 	guint fields_mask;
diff -r 9a6b47f2f6bc -r eb6fc4ff15a8 libdocument/ev-document.c
--- a/libdocument/ev-document.c	Sat Jan 10 23:56:15 2015 +0100
+++ b/libdocument/ev-document.c	Sun Jan 11 15:56:41 2015 +0100
@@ -56,11 +56,18 @@
 
 	gchar         **page_labels;
 	EvPageSize     *page_sizes;
+	gchar          *file_size; /* eg, 200kB */
 	EvDocumentInfo *info;
 
 	synctex_scanner_t synctex_scanner;
 };
 
+static gchar          *_ev_document_get_file_size_gfile 
+                                                    (GFile *file,
+                                                     GError **error);
+static gchar          *_ev_document_get_file_size
+                                                    (const char  *uri,
+                                                     GError **error);
 static gint            _ev_document_get_n_pages     (EvDocument *document);
 static void            _ev_document_get_page_size   (EvDocument *document,
 						     EvPage     *page,
@@ -124,6 +131,11 @@
 		document->priv->page_labels = NULL;
 	}
 
+	if (document->priv->file_size) {
+		g_free (document->priv->file_size);
+		document->priv->file_size = NULL;
+	}
+
 	if (document->priv->info) {
 		ev_document_info_free (document->priv->info);
 		document->priv->info = NULL;
@@ -331,7 +343,7 @@
 	} else {
                 ev_document_setup_cache (document);
 		document->priv->uri = g_strdup (uri);
-		document->priv->info->file_size = ev_document_file_size (document);
+		document->priv->file_size = _ev_document_get_file_size (uri, error);
 		ev_document_initialize_synctex (document, uri);
         }
 
@@ -423,7 +435,7 @@
 
         ev_document_setup_cache (document);
 	document->priv->uri = g_file_get_uri (file);
-	document->priv->info->file_size = ev_document_file_size (document);
+	document->priv->file_size = _ev_document_get_file_size_gfile (file, error);
 	ev_document_initialize_synctex (document, document->priv->uri);
 
         return TRUE;
@@ -578,6 +590,30 @@
         return result;
 }
 
+static gchar *
+_ev_document_get_file_size_gfile (GFile *file, GError **error)
+{
+	if (g_file_query_exists (file, NULL)) {
+		GFileInfo *info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_SIZE,
+                                                     G_FILE_QUERY_INFO_NONE, NULL, error);
+
+		goffset size = g_file_info_get_size (info);
+
+		g_object_unref (file);
+		g_object_unref (info);
+
+		return g_format_size (size);
+	}
+	return NULL;
+}
+
+static gchar *
+_ev_document_get_file_size (const char  *uri, GError **error)
+{
+	GFile *file = g_file_new_for_uri (uri);
+	return _ev_document_get_file_size_gfile (file, error);
+}
+
 static gint
 _ev_document_get_n_pages (EvDocument  *document)
 {
@@ -746,20 +782,6 @@
 	return ev_document_render (document, rc);
 }
 
-gchar *
-ev_document_file_size (EvDocument *document)
-{
-	FILE *fp = g_fopen (g_filename_from_uri (document->priv->uri, NULL, NULL), "r");
-	if (fp) {
-		fseek (fp, 0L, SEEK_END);
-		unsigned long size = (unsigned long)ftell (fp);
-		fclose (fp);
-
-		return g_format_size (size);
-	}
-	return NULL;
-}
-
 const gchar *
 ev_document_get_uri (EvDocument *document)
 {
@@ -819,6 +841,14 @@
 	return (document->priv->max_width > 0 && document->priv->max_height > 0);
 }
 
+const gchar *
+ev_document_get_file_size (EvDocument *document)
+{
+	g_return_val_if_fail (EV_IS_DOCUMENT (document), -1);
+
+	return document->priv->file_size;
+}
+
 gint
 ev_document_get_max_label_len (EvDocument *document)
 {
@@ -955,7 +985,6 @@
 	copy->permissions = info->permissions;
 	copy->n_pages = info->n_pages;
 	copy->license = ev_document_license_copy (info->license);
-	copy->file_size = g_strdup (info->file_size);
 
 	copy->fields_mask = info->fields_mask;
 
@@ -977,7 +1006,6 @@
 	g_free (info->producer);
 	g_free (info->linearized);
 	g_free (info->security);
-	g_free (info->file_size);
 	ev_document_license_free (info->license);
 
 	g_free (info);
diff -r 9a6b47f2f6bc -r eb6fc4ff15a8 libdocument/ev-document.h
--- a/libdocument/ev-document.h	Sat Jan 10 23:56:15 2015 +0100
+++ b/libdocument/ev-document.h	Sun Jan 11 15:56:41 2015 +0100
@@ -181,7 +181,7 @@
 						   EvRenderContext *rc);
 cairo_surface_t *ev_document_get_thumbnail_surface (EvDocument      *document,
 						    EvRenderContext *rc);
-gchar           *ev_document_file_size            (EvDocument *document);
+const gchar     *ev_document_get_file_size        (EvDocument      *document);
 const gchar     *ev_document_get_uri              (EvDocument      *document);
 const gchar     *ev_document_get_title            (EvDocument      *document);
 gboolean         ev_document_is_page_size_uniform (EvDocument      *document);
diff -r 9a6b47f2f6bc -r eb6fc4ff15a8 properties/ev-properties-main.c
--- a/properties/ev-properties-main.c	Sat Jan 10 23:56:15 2015 +0100
+++ b/properties/ev-properties-main.c	Sun Jan 11 15:56:41 2015 +0100
@@ -114,7 +114,7 @@
 	}
 	
 	label = gtk_label_new (_("Document"));
-	page = ev_properties_view_new (uri);
+	page = ev_properties_view_new (document);
 	ev_properties_view_set_info (EV_PROPERTIES_VIEW (page),
 				     ev_document_get_info (document));
 	gtk_widget_show (page);
diff -r 9a6b47f2f6bc -r eb6fc4ff15a8 properties/ev-properties-view.c
--- a/properties/ev-properties-view.c	Sat Jan 10 23:56:15 2015 +0100
+++ b/properties/ev-properties-view.c	Sun Jan 11 15:56:41 2015 +0100
@@ -81,6 +81,7 @@
 	GtkWidget *grid;
 	GtkWidget *labels[N_PROPERTIES];
 	gchar     *uri;
+	gchar     *file_size;
 };
 
 struct _EvPropertiesViewClass {
@@ -99,6 +100,11 @@
 		properties->uri = NULL;
 	}
 
+	if (properties->file_size) {
+		g_free (properties->file_size);
+		properties->file_size = NULL;
+	}
+
 	G_OBJECT_CLASS (ev_properties_view_parent_class)->dispose (object);
 }
 
@@ -372,7 +378,7 @@
 		set_property (properties, GTK_GRID (grid), PAPER_SIZE_PROPERTY, text, &row);
 		g_free (text);
 	}
-	set_property (properties, GTK_GRID (grid), FILE_SIZE_PROPERTY, info->file_size, &row);
+	set_property (properties, GTK_GRID (grid), FILE_SIZE_PROPERTY, properties->file_size, &row);
 }
 
 static void
@@ -393,14 +399,15 @@
 }
 
 GtkWidget *
-ev_properties_view_new (const gchar *uri)
+ev_properties_view_new (EvDocument *document)
 {
 	EvPropertiesView *properties;
 
 	properties = g_object_new (EV_TYPE_PROPERTIES,
 				   "orientation", GTK_ORIENTATION_VERTICAL,
 				   NULL);
-	properties->uri = g_uri_unescape_string (uri, NULL);
+	properties->uri = ev_document_get_uri (document);
+	properties->file_size = ev_document_get_file_size (document);
 
 	return GTK_WIDGET (properties);
 }
diff -r 9a6b47f2f6bc -r eb6fc4ff15a8 properties/ev-properties-view.h
--- a/properties/ev-properties-view.h	Sat Jan 10 23:56:15 2015 +0100
+++ b/properties/ev-properties-view.h	Sun Jan 11 15:56:41 2015 +0100
@@ -41,7 +41,7 @@
 GType		ev_properties_view_get_type		(void);
 void		ev_properties_view_register_type	(GTypeModule *module);
 
-GtkWidget      *ev_properties_view_new			(const gchar          *uri);
+GtkWidget      *ev_properties_view_new			(EvDocument     *document);
 void		ev_properties_view_set_info		(EvPropertiesView     *properties,
 							 const EvDocumentInfo *info);
 
diff -r 9a6b47f2f6bc -r eb6fc4ff15a8 shell/ev-properties-dialog.c
--- a/shell/ev-properties-dialog.c	Sat Jan 10 23:56:15 2015 +0100
+++ b/shell/ev-properties-dialog.c	Sun Jan 11 15:56:41 2015 +0100
@@ -83,7 +83,7 @@
 
 	if (properties->general_page == NULL) {
 		label = gtk_label_new (_("General"));
-		properties->general_page = ev_properties_view_new (uri);
+		properties->general_page = ev_properties_view_new (document);
 		gtk_notebook_append_page (GTK_NOTEBOOK (properties->notebook),
 					  properties->general_page, label);
 		gtk_widget_show (properties->general_page);
