[gtksourceview/wip/loader-saver] GtkSourceFile API with stubs



commit 9f016375553396b434a34b42a9c253cb26a7e9f0
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Wed Dec 11 14:30:49 2013 +0100

    GtkSourceFile API with stubs
    
    And move the GtkSourceNewlineType enum from gtksourcebuffer.h to
    gtksourcefile.h.

 gtksourceview/gtksourcebuffer.h            |    7 -
 gtksourceview/gtksourcebufferinputstream.h |    2 +-
 gtksourceview/gtksourcefile.c              |  330 +++++++++++++++++++++++++++-
 gtksourceview/gtksourcefile.h              |  105 +++++++++-
 4 files changed, 433 insertions(+), 11 deletions(-)
---
diff --git a/gtksourceview/gtksourcebuffer.h b/gtksourceview/gtksourcebuffer.h
index 17c7a63..f04facb 100644
--- a/gtksourceview/gtksourcebuffer.h
+++ b/gtksourceview/gtksourcebuffer.h
@@ -73,13 +73,6 @@ typedef enum
        GTK_SOURCE_CHANGE_CASE_TITLE
 } GtkSourceChangeCaseType;
 
-typedef enum
-{
-       GTK_SOURCE_NEWLINE_TYPE_LF,
-       GTK_SOURCE_NEWLINE_TYPE_CR,
-       GTK_SOURCE_NEWLINE_TYPE_CR_LF
-} GtkSourceNewlineType;
-
 struct _GtkSourceBuffer
 {
        GtkTextBuffer parent_instance;
diff --git a/gtksourceview/gtksourcebufferinputstream.h b/gtksourceview/gtksourcebufferinputstream.h
index 1134f10..f67e831 100644
--- a/gtksourceview/gtksourcebufferinputstream.h
+++ b/gtksourceview/gtksourcebufferinputstream.h
@@ -26,7 +26,7 @@
 #include <gio/gio.h>
 #include <gtk/gtk.h>
 #include "gtksourcetypes-private.h"
-#include "gtksourcebuffer.h"
+#include "gtksourcefile.h"
 
 G_BEGIN_DECLS
 
diff --git a/gtksourceview/gtksourcefile.c b/gtksourceview/gtksourcefile.c
index 33624e2..19c74ff 100644
--- a/gtksourceview/gtksourcefile.c
+++ b/gtksourceview/gtksourcefile.c
@@ -20,15 +20,127 @@
  */
 
 #include "gtksourcefile.h"
+#include "gtksourcebuffer.h"
+#include "gtksourceencoding.h"
+#include "gtksourceview-typebuiltins.h"
+
+enum
+{
+       PROP_0,
+       PROP_LOCATION,
+       PROP_BUFFER,
+       PROP_ENCODING,
+       PROP_NEWLINE_TYPE,
+       PROP_COMPRESSION_TYPE
+};
 
 struct _GtkSourceFilePrivate
 {
-       gint something;
+       GFile *location;
+       GtkSourceBuffer *buffer;
+       const GtkSourceEncoding *encoding;
+       GtkSourceNewlineType newline_type;
+       GtkSourceCompressionType compression_type;
 };
 
 G_DEFINE_TYPE_WITH_PRIVATE (GtkSourceFile, gtk_source_file, G_TYPE_OBJECT)
 
 static void
+gtk_source_file_get_property (GObject    *object,
+                             guint       prop_id,
+                             GValue     *value,
+                             GParamSpec *pspec)
+{
+       GtkSourceFile *file;
+
+       g_return_if_fail (GTK_SOURCE_IS_FILE (object));
+
+       file = GTK_SOURCE_FILE (object);
+
+       switch (prop_id)
+       {
+               case PROP_LOCATION:
+                       g_value_set_object (value, file->priv->location);
+                       break;
+
+               case PROP_BUFFER:
+                       g_value_set_object (value, file->priv->buffer);
+                       break;
+
+               case PROP_ENCODING:
+                       g_value_set_boxed (value, file->priv->encoding);
+                       break;
+
+               case PROP_NEWLINE_TYPE:
+                       g_value_set_enum (value, file->priv->newline_type);
+                       break;
+
+               case PROP_COMPRESSION_TYPE:
+                       g_value_set_enum (value, file->priv->compression_type);
+                       break;
+
+               default:
+                       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+                       break;
+       }
+}
+
+static void
+gtk_source_file_set_property (GObject      *object,
+                             guint         prop_id,
+                             const GValue *value,
+                             GParamSpec   *pspec)
+{
+       GtkSourceFile *file;
+
+       g_return_if_fail (GTK_SOURCE_IS_FILE (object));
+
+       file = GTK_SOURCE_FILE (object);
+
+       switch (prop_id)
+       {
+               case PROP_LOCATION:
+                       g_assert (file->priv->location == NULL);
+                       file->priv->location = g_value_get_object (value);
+                       g_object_ref (file->priv->location);
+                       break;
+
+               case PROP_BUFFER:
+                       g_assert (file->priv->buffer == NULL);
+                       file->priv->buffer = g_value_get_object (value);
+                       g_object_ref (file->priv->buffer);
+                       break;
+
+               case PROP_ENCODING:
+                       gtk_source_file_set_encoding (file, g_value_get_boxed (value));
+                       break;
+
+               case PROP_NEWLINE_TYPE:
+                       gtk_source_file_set_newline_type (file, g_value_get_enum (value));
+                       break;
+
+               case PROP_COMPRESSION_TYPE:
+                       gtk_source_file_set_compression_type (file, g_value_get_enum (value));
+                       break;
+
+               default:
+                       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+                       break;
+       }
+}
+
+static void
+gtk_source_file_dispose (GObject *object)
+{
+       GtkSourceFile *file = GTK_SOURCE_FILE (object);
+
+       g_clear_object (&file->priv->location);
+       g_clear_object (&file->priv->buffer);
+
+       G_OBJECT_CLASS (gtk_source_file_parent_class)->dispose (object);
+}
+
+static void
 gtk_source_file_finalize (GObject *object)
 {
 
@@ -40,7 +152,56 @@ gtk_source_file_class_init (GtkSourceFileClass *klass)
 {
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
+       object_class->get_property = gtk_source_file_get_property;
+       object_class->set_property = gtk_source_file_set_property;
+       object_class->dispose = gtk_source_file_dispose;
        object_class->finalize = gtk_source_file_finalize;
+
+       g_object_class_install_property (object_class, PROP_LOCATION,
+                                        g_param_spec_object ("location",
+                                                             "Location",
+                                                             "The file's location",
+                                                             G_TYPE_FILE,
+                                                             G_PARAM_READWRITE |
+                                                             G_PARAM_CONSTRUCT_ONLY |
+                                                             G_PARAM_STATIC_STRINGS));
+
+       g_object_class_install_property (object_class, PROP_BUFFER,
+                                        g_param_spec_object ("buffer",
+                                                             "Buffer",
+                                                             "The associated GtkSourceBuffer",
+                                                             GTK_SOURCE_TYPE_BUFFER,
+                                                             G_PARAM_READWRITE |
+                                                             G_PARAM_CONSTRUCT_ONLY |
+                                                             G_PARAM_STATIC_STRINGS));
+
+       g_object_class_install_property (object_class, PROP_ENCODING,
+                                        g_param_spec_boxed ("encoding",
+                                                            "Encoding",
+                                                            "The GtkSourceEncoding used",
+                                                            GTK_SOURCE_TYPE_ENCODING,
+                                                            G_PARAM_READWRITE |
+                                                            G_PARAM_STATIC_STRINGS));
+
+       g_object_class_install_property (object_class, PROP_NEWLINE_TYPE,
+                                        g_param_spec_enum ("newline-type",
+                                                           "Newline type",
+                                                           "The type of line ending",
+                                                           GTK_SOURCE_TYPE_NEWLINE_TYPE,
+                                                           GTK_SOURCE_NEWLINE_TYPE_LF,
+                                                           G_PARAM_READWRITE |
+                                                           G_PARAM_CONSTRUCT |
+                                                           G_PARAM_STATIC_STRINGS));
+
+       g_object_class_install_property (object_class, PROP_COMPRESSION_TYPE,
+                                        g_param_spec_enum ("compression-type",
+                                                           "Compression type",
+                                                           "The compression type",
+                                                           GTK_SOURCE_TYPE_COMPRESSION_TYPE,
+                                                           GTK_SOURCE_COMPRESSION_TYPE_NONE,
+                                                           G_PARAM_READWRITE |
+                                                           G_PARAM_CONSTRUCT |
+                                                           G_PARAM_STATIC_STRINGS));
 }
 
 static void
@@ -48,3 +209,170 @@ gtk_source_file_init (GtkSourceFile *self)
 {
        self->priv = gtk_source_file_get_instance_private (self);
 }
+
+GtkSourceFile *
+gtk_source_file_new (GFile           *location,
+                    GtkSourceBuffer *buffer)
+{
+       g_return_val_if_fail (G_IS_FILE (location), NULL);
+       g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), NULL);
+
+       return g_object_new (GTK_SOURCE_TYPE_FILE,
+                            "location", location,
+                            "buffer", buffer,
+                            NULL);
+}
+
+GFile *
+gtk_source_file_get_location (GtkSourceFile *file)
+{
+       g_return_val_if_fail (GTK_SOURCE_IS_FILE (file), NULL);
+
+       return file->priv->location;
+}
+
+GtkSourceBuffer *
+gtk_source_file_get_buffer (GtkSourceFile *file)
+{
+       g_return_val_if_fail (GTK_SOURCE_IS_FILE (file), NULL);
+
+       return file->priv->buffer;
+}
+
+const GtkSourceEncoding *
+gtk_source_file_get_encoding (GtkSourceFile *file)
+{
+       g_return_val_if_fail (GTK_SOURCE_IS_FILE (file), NULL);
+
+       return file->priv->encoding;
+}
+
+void
+gtk_source_file_set_encoding (GtkSourceFile           *file,
+                             const GtkSourceEncoding *encoding)
+{
+       g_return_if_fail (GTK_SOURCE_IS_FILE (file));
+
+       if (file->priv->encoding != encoding)
+       {
+               file->priv->encoding = encoding;
+               g_object_notify (G_OBJECT (file), "encoding");
+       }
+}
+
+GtkSourceNewlineType
+gtk_source_file_get_newline_type (GtkSourceFile *file)
+{
+       g_return_val_if_fail (GTK_SOURCE_IS_FILE (file), GTK_SOURCE_NEWLINE_TYPE_LF);
+
+       return file->priv->newline_type;
+}
+
+void
+gtk_source_file_set_newline_type (GtkSourceFile *file,
+                                 GtkSourceNewlineType newline_type)
+{
+       g_return_if_fail (GTK_SOURCE_IS_FILE (file));
+
+       if (file->priv->newline_type != newline_type)
+       {
+               file->priv->newline_type = newline_type;
+               g_object_notify (G_OBJECT (file), "newline-type");
+       }
+}
+
+GtkSourceCompressionType
+gtk_source_file_get_compression_type (GtkSourceFile *file)
+{
+       g_return_val_if_fail (GTK_SOURCE_IS_FILE (file), GTK_SOURCE_COMPRESSION_TYPE_NONE);
+
+       return file->priv->compression_type;
+}
+
+void
+gtk_source_file_set_compression_type (GtkSourceFile            *file,
+                                     GtkSourceCompressionType  compression_type)
+{
+       g_return_if_fail (GTK_SOURCE_IS_FILE (file));
+
+       if (file->priv->compression_type != compression_type)
+       {
+               file->priv->compression_type = compression_type;
+               g_object_notify (G_OBJECT (file), "compression-type");
+       }
+}
+
+/* FIXME add load flags parameter for future expension? */
+gboolean
+gtk_source_file_load (GtkSourceFile          *file,
+                     GCancellable           *cancellable,
+                     GFileProgressCallback   progress_callback,
+                     gpointer                progress_callback_data,
+                     GError                **error)
+{
+       g_return_val_if_fail (GTK_SOURCE_IS_FILE (file), FALSE);
+       g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+       return TRUE;
+}
+
+void
+gtk_source_file_load_async (GtkSourceFile         *file,
+                           gint                   io_priority,
+                           GCancellable          *cancellable,
+                           GFileProgressCallback  progress_callback,
+                           gpointer               progress_callback_data,
+                           GAsyncReadyCallback    callback,
+                           gpointer               user_data)
+{
+       g_return_if_fail (GTK_SOURCE_IS_FILE (file));
+}
+
+gboolean
+gtk_source_file_load_finish (GtkSourceFile  *file,
+                            GAsyncResult   *result,
+                            GError        **error)
+{
+       g_return_val_if_fail (GTK_SOURCE_IS_FILE (file), FALSE);
+       g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+       return TRUE;
+}
+
+gboolean
+gtk_source_file_save (GtkSourceFile           *file,
+                     GtkSourceFileSaveFlags   flags,
+                     GCancellable            *cancellable,
+                     GFileProgressCallback    progress_callback,
+                     gpointer                 progress_callback_data,
+                     GError                 **error)
+{
+       g_return_val_if_fail (GTK_SOURCE_IS_FILE (file), FALSE);
+       g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+       return TRUE;
+}
+
+void
+gtk_source_file_save_async (GtkSourceFile          *file,
+                           GtkSourceFileSaveFlags  flags,
+                           gint                    io_priority,
+                           GCancellable           *cancellable,
+                           GFileProgressCallback   progress_callback,
+                           gpointer                progress_callback_data,
+                           GAsyncReadyCallback     callback,
+                           gpointer                user_data)
+{
+       g_return_if_fail (GTK_SOURCE_IS_FILE (file));
+}
+
+gboolean
+gtk_source_file_save_finish (GtkSourceFile  *file,
+                            GAsyncResult   *result,
+                            GError        **error)
+{
+       g_return_val_if_fail (GTK_SOURCE_IS_FILE (file), FALSE);
+       g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+       return TRUE;
+}
diff --git a/gtksourceview/gtksourcefile.h b/gtksourceview/gtksourcefile.h
index c1f0b39..ddeee02 100644
--- a/gtksourceview/gtksourcefile.h
+++ b/gtksourceview/gtksourcefile.h
@@ -22,7 +22,7 @@
 #ifndef __GTK_SOURCE_FILE_H__
 #define __GTK_SOURCE_FILE_H__
 
-#include <glib-object.h>
+#include <gio/gio.h>
 #include <gtksourceview/gtksourcetypes.h>
 
 G_BEGIN_DECLS
@@ -37,6 +37,47 @@ G_BEGIN_DECLS
 typedef struct _GtkSourceFileClass    GtkSourceFileClass;
 typedef struct _GtkSourceFilePrivate  GtkSourceFilePrivate;
 
+typedef enum
+{
+       GTK_SOURCE_NEWLINE_TYPE_LF,
+       GTK_SOURCE_NEWLINE_TYPE_CR,
+       GTK_SOURCE_NEWLINE_TYPE_CR_LF
+} GtkSourceNewlineType;
+
+/* NOTE: when adding a new compression type, make sure to update:
+ *   1) The buffer loader to support it
+ *   2) gedit_document_compression_type_for_display
+ */
+
+/**
+ * GtkSourceCompressionType:
+ * @GTK_SOURCE_COMPRESSION_TYPE_NONE: save file in plain text.
+ * @GTK_SOURCE_COMPRESSION_TYPE_GZIP: save file using gzip compression.
+ *
+ * Since: 3.12
+ */
+typedef enum
+{
+       GTK_SOURCE_COMPRESSION_TYPE_NONE,
+       GTK_SOURCE_COMPRESSION_TYPE_GZIP
+} GtkSourceCompressionType;
+
+/**
+ * GtkSourceFileSaveFlags:
+ * @GTK_SOURCE_FILE_SAVE_IGNORE_MTIME: save file despite external modifications.
+ * @GTK_SOURCE_FILE_SAVE_IGNORE_BACKUP: write the file directly without attempting to backup.
+ * @GTK_SOURCE_FILE_SAVE_PRESERVE_BACKUP: preserve previous backup file, needed to support autosaving.
+ * @GTK_SOURCE_FILE_SAVE_IGNORE_INVALID_CHARS: do not save invalid characters.
+ */
+/* FIXME: merge IGNORE_BACKUP and PRESERVE_BACKUP? */
+typedef enum
+{
+       GTK_SOURCE_FILE_SAVE_IGNORE_MTIME               = 1 << 0,
+       GTK_SOURCE_FILE_SAVE_IGNORE_BACKUP              = 1 << 1,
+       GTK_SOURCE_FILE_SAVE_PRESERVE_BACKUP            = 1 << 2,
+       GTK_SOURCE_FILE_SAVE_IGNORE_INVALID_CHARS       = 1 << 3
+} GtkSourceFileSaveFlags;
+
 struct _GtkSourceFile
 {
        GObject parent;
@@ -49,7 +90,67 @@ struct _GtkSourceFileClass
        GObjectClass parent_class;
 };
 
-GType gtk_source_file_get_type (void) G_GNUC_CONST;
+GType                   gtk_source_file_get_type               (void) G_GNUC_CONST;
+
+GtkSourceFile          *gtk_source_file_new                    (GFile                   *location,
+                                                                GtkSourceBuffer         *buffer);
+
+GFile                  *gtk_source_file_get_location           (GtkSourceFile           *file);
+
+GtkSourceBuffer                *gtk_source_file_get_buffer             (GtkSourceFile           *file);
+
+const GtkSourceEncoding        *gtk_source_file_get_encoding           (GtkSourceFile           *file);
+
+void                    gtk_source_file_set_encoding           (GtkSourceFile           *file,
+                                                                const GtkSourceEncoding *encoding);
+
+GtkSourceNewlineType    gtk_source_file_get_newline_type       (GtkSourceFile           *file);
+
+void                    gtk_source_file_set_newline_type       (GtkSourceFile           *file,
+                                                                GtkSourceNewlineType     newline_type);
+
+GtkSourceCompressionType gtk_source_file_get_compression_type  (GtkSourceFile           *file);
+
+void                    gtk_source_file_set_compression_type   (GtkSourceFile            *file,
+                                                                GtkSourceCompressionType  compression_type);
+
+gboolean                gtk_source_file_load                   (GtkSourceFile            *file,
+                                                                GCancellable             *cancellable,
+                                                                GFileProgressCallback     progress_callback,
+                                                                gpointer                  
progress_callback_data,
+                                                                GError                  **error);
+
+void                    gtk_source_file_load_async             (GtkSourceFile            *file,
+                                                                gint                      io_priority,
+                                                                GCancellable             *cancellable,
+                                                                GFileProgressCallback     progress_callback,
+                                                                gpointer                  
progress_callback_data,
+                                                                GAsyncReadyCallback       callback,
+                                                                gpointer                  user_data);
+
+gboolean                gtk_source_file_load_finish            (GtkSourceFile            *file,
+                                                                GAsyncResult             *result,
+                                                                GError                  **error);
+
+gboolean                gtk_source_file_save                   (GtkSourceFile            *file,
+                                                                GtkSourceFileSaveFlags    flags,
+                                                                GCancellable             *cancellable,
+                                                                GFileProgressCallback     progress_callback,
+                                                                gpointer                  
progress_callback_data,
+                                                                GError                  **error);
+
+void                    gtk_source_file_save_async             (GtkSourceFile            *file,
+                                                                GtkSourceFileSaveFlags    flags,
+                                                                gint                      io_priority,
+                                                                GCancellable             *cancellable,
+                                                                GFileProgressCallback     progress_callback,
+                                                                gpointer                  
progress_callback_data,
+                                                                GAsyncReadyCallback       callback,
+                                                                gpointer                  user_data);
+
+gboolean                gtk_source_file_save_finish            (GtkSourceFile            *file,
+                                                                GAsyncResult             *result,
+                                                                GError                  **error);
 
 G_END_DECLS
 


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