[libgepub] Added file property to support GFile initialization



commit 14cc7348bb7cbd5c10e483b04fa9fc6f468943c2
Author: Daniel GarcĂ­a Moreno <danigm wadobo com>
Date:   Mon Mar 13 17:48:24 2017 +0100

    Added file property to support GFile initialization

 libgepub/gepub-doc.c |   34 ++++++++++++++++++++++++++++------
 tests/test-gepub.c   |   10 ++++++++--
 2 files changed, 36 insertions(+), 8 deletions(-)
---
diff --git a/libgepub/gepub-doc.c b/libgepub/gepub-doc.c
index 6630805..63450c3 100644
--- a/libgepub/gepub-doc.c
+++ b/libgepub/gepub-doc.c
@@ -64,6 +64,7 @@ enum {
     PROP_0,
     PROP_PATH,
     PROP_PAGE,
+    PROP_FILE,
     NUM_PROPS
 };
 
@@ -94,9 +95,16 @@ gepub_doc_set_property (GObject      *object,
     case PROP_PATH:
         doc->path = g_value_dup_string (value);
         break;
-    //case PROP_PAGE:
-    //    gepub_doc_set_page (doc, g_value_get_int (value));
-    //    break;
+    case PROP_PAGE:
+        gepub_doc_set_page (doc, g_value_get_int (value));
+        break;
+    case PROP_FILE: {
+        GFile *f = G_FILE (g_value_get_object (value));
+        if (f) {
+            doc->path = g_file_get_path (G_FILE (g_value_get_object (value)));
+        }
+        break;
+    }
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
         break;
@@ -115,9 +123,14 @@ gepub_doc_get_property (GObject    *object,
     case PROP_PATH:
         g_value_set_string (value, doc->path);
         break;
-    //case PROP_PAGE:
-    //    g_value_set_int (value, gepub_doc_get_page (doc));
-    //    break;
+    case PROP_PAGE:
+        g_value_set_int (value, gepub_doc_get_page (doc));
+        break;
+    case PROP_FILE: {
+        GFile *f = g_file_new_for_path (doc->path);
+        g_value_set_object (value, f);
+        break;
+    }
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
         break;
@@ -154,6 +167,15 @@ gepub_doc_class_init (GepubDocClass *klass)
                           G_PARAM_READWRITE |
                           G_PARAM_STATIC_STRINGS);
 
+    properties[PROP_FILE] =
+        g_param_spec_object ("file",
+                             "File",
+                             "GFile to the EPUB document",
+                             G_TYPE_FILE,
+                             G_PARAM_READWRITE |
+                             G_PARAM_CONSTRUCT_ONLY |
+                             G_PARAM_STATIC_STRINGS);
+
     g_object_class_install_properties (object_class, NUM_PROPS, properties);
 }
 
diff --git a/tests/test-gepub.c b/tests/test-gepub.c
index 028a5f8..f237964 100644
--- a/tests/test-gepub.c
+++ b/tests/test-gepub.c
@@ -43,7 +43,7 @@ button_pressed (GtkButton *button, GepubDoc *doc)
     printf ("CURRENT: %d\n", gepub_doc_get_page (doc));
     printf ("CURRENT: %s\n", gepub_doc_get_current_id (doc));
     printf ("CURRENT: %s\n", gepub_doc_get_current_path (doc));
-    print_replaced_text (doc);
+    //print_replaced_text (doc);
 }
 
 void
@@ -93,6 +93,8 @@ main (int argc, char **argv)
 
     GtkTextBuffer *buffer;
 
+    GError *error = NULL;
+
     GepubDoc *doc;
     GtkWidget *widget = gepub_widget_new ();
 
@@ -108,7 +110,11 @@ main (int argc, char **argv)
     gtk_container_add (GTK_CONTAINER (window), vpaned);
 
     // gepub widget
-    doc = gepub_doc_new (argv[1]);
+    GFile *file = g_file_new_for_path (argv[1]);
+    doc = g_initable_new (gepub_doc_get_type (), NULL, &error,
+                          "file", file,
+                          NULL);
+    g_object_unref (file);
     if (!doc) {
         perror ("BAD epub FILE");
         return -1;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]