# HG changeset patch
# User Tobias Westergaard Kjeldsen <tobias@wkjeldsen.dk>
# Date 1421508747 -3600
#      Sat Jan 17 16:32:27 2015 +0100
# Node ID 658c5973c52148ddb6a12ede3a584278790c1577
# Parent  003be63e6c804532059b35509aaab92b7c88aace
Add file size "Size" in the file properties window.

diff --git a/libdocument/ev-document.c b/libdocument/ev-document.c
--- a/libdocument/ev-document.c
+++ b/libdocument/ev-document.c
@@ -39,6 +39,7 @@
 struct _EvDocumentPrivate
 {
 	gchar          *uri;
+	guint64         file_size; /* eg, 200kB */
 
 	gint            n_pages;
 
@@ -59,6 +60,8 @@
 	synctex_scanner_t synctex_scanner;
 };
 
+static guint64         _ev_document_get_size_gfile  (GFile      *file);
+static guint64         _ev_document_get_size        (const char *uri);
 static gint            _ev_document_get_n_pages     (EvDocument *document);
 static void            _ev_document_get_page_size   (EvDocument *document,
 						     EvPage     *page,
@@ -329,6 +332,7 @@
 	} else {
                 ev_document_setup_cache (document);
 		document->priv->uri = g_strdup (uri);
+		document->priv->file_size = _ev_document_get_size (uri);
 		ev_document_initialize_synctex (document, uri);
         }
 
@@ -420,6 +424,7 @@
 
         ev_document_setup_cache (document);
 	document->priv->uri = g_file_get_uri (file);
+	document->priv->file_size = _ev_document_get_size_gfile (file);
 	ev_document_initialize_synctex (document, document->priv->uri);
 
         return TRUE;
@@ -574,6 +579,32 @@
         return result;
 }
 
+static guint64
+_ev_document_get_size_gfile (GFile *file)
+{
+	goffset    size = 0;
+	GFileInfo *info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_SIZE,
+                                             G_FILE_QUERY_INFO_NONE, NULL, NULL);
+	if(info) {
+		size = g_file_info_get_size (info);
+
+		g_object_unref (info);
+	}
+
+	return size;
+}
+
+static guint64
+_ev_document_get_size (const char  *uri)
+{
+	GFile  *file = g_file_new_for_uri (uri);
+	guint64 size = _ev_document_get_size_gfile (file);
+
+	g_object_unref (file);
+
+	return size;
+}
+
 static gint
 _ev_document_get_n_pages (EvDocument  *document)
 {
@@ -802,6 +833,14 @@
 	return (document->priv->max_width > 0 && document->priv->max_height > 0);
 }
 
+guint64
+ev_document_get_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)
 {
diff --git a/libdocument/ev-document.h b/libdocument/ev-document.h
--- a/libdocument/ev-document.h
+++ b/libdocument/ev-document.h
@@ -181,6 +181,7 @@
 						   EvRenderContext *rc);
 cairo_surface_t *ev_document_get_thumbnail_surface (EvDocument      *document,
 						    EvRenderContext *rc);
+guint64          ev_document_get_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 --git a/properties/ev-properties-main.c b/properties/ev-properties-main.c
--- a/properties/ev-properties-main.c
+++ b/properties/ev-properties-main.c
@@ -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 --git a/properties/ev-properties-view.c b/properties/ev-properties-view.c
--- a/properties/ev-properties-view.c
+++ b/properties/ev-properties-view.c
@@ -48,7 +48,8 @@
 	FORMAT_PROPERTY,
 	SECURITY_PROPERTY,
 	PAPER_SIZE_PROPERTY,
-	N_PROPERTIES
+	FILE_SIZE_PROPERTY,
+	N_PROPERTIES,
 } Property;
 
 typedef struct {
@@ -70,7 +71,8 @@
 	{ LINEARIZED_PROPERTY,    N_("Optimized:") },
 	{ FORMAT_PROPERTY,        N_("Format:") },
 	{ SECURITY_PROPERTY,      N_("Security:") },
-	{ PAPER_SIZE_PROPERTY,    N_("Paper Size:") }
+	{ PAPER_SIZE_PROPERTY,    N_("Paper Size:") },
+	{ FILE_SIZE_PROPERTY,     N_("Size:") }
 };
 
 struct _EvPropertiesView {
@@ -79,6 +81,7 @@
 	GtkWidget *grid;
 	GtkWidget *labels[N_PROPERTIES];
 	gchar     *uri;
+	guint64    file_size;
 };
 
 struct _EvPropertiesViewClass {
@@ -370,6 +373,11 @@
 		set_property (properties, GTK_GRID (grid), PAPER_SIZE_PROPERTY, text, &row);
 		g_free (text);
 	}
+	if(properties->file_size) {
+		text = g_format_size (properties->file_size);
+		set_property (properties, GTK_GRID (grid), FILE_SIZE_PROPERTY, text, &row);
+		g_free (text);
+	}
 }
 
 static void
@@ -390,14 +398,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 = g_uri_unescape_string (ev_document_get_uri (document), NULL);
+	properties->file_size = ev_document_get_size (document);
 
 	return GTK_WIDGET (properties);
 }
diff --git a/properties/ev-properties-view.h b/properties/ev-properties-view.h
--- a/properties/ev-properties-view.h
+++ b/properties/ev-properties-view.h
@@ -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 --git a/shell/ev-properties-dialog.c b/shell/ev-properties-dialog.c
--- a/shell/ev-properties-dialog.c
+++ b/shell/ev-properties-dialog.c
@@ -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);
