Some more property work
authorMatthias Clasen <matthiasc@src.gnome.org>
Sat, 1 Dec 2007 06:12:45 +0000 (06:12 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Sat, 1 Dec 2007 06:12:45 +0000 (06:12 +0000)
svn path=/trunk/; revision=6008

gio/ChangeLog
gio/gbufferedinputstream.c
gio/gbufferedoutputstream.c
gio/gdataoutputstream.c
gio/gdirectorymonitor.c
gio/gfilemonitor.c
gio/gmountoperation.c

index b89899367c00a950791c546d4f05036176ac46f1..aaf5d7d1cdd656387c005be5a2b330cdd31d5406 100644 (file)
@@ -1,5 +1,8 @@
 2007-12-01  Matthias Clasen <mclasen@redhat.com>
 
+       * gdirectorymonitor.c:
+       * gfilemonitor.c: Add properties
+
        * gbufferedoutputstream.c: Don't mark buffer-size property 
        as construct-only.
 
index 62c96f986a35fabe254f223402471ffc9ee3cd3f..13c2464604149c9525bb3b662fa15ae08d398d9b 100644 (file)
  * 
  * By default, #GBufferedInputStream's buffer size is set at 4 kilobytes.
  * 
- * To create a buffered input stream, use g_buffered_input_stream_new(), or 
- * g_buffered_input_stream_new_sized() to specify the buffer's size at construction.
+ * To create a buffered input stream, use g_buffered_input_stream_new(), 
+ * or g_buffered_input_stream_new_sized() to specify the buffer's size at 
+ * construction.
  * 
  * To get the size of a buffer within a buffered input stream, use 
  * g_buffered_input_stream_get_buffer_size(). To change the size of a 
- * buffered input stream's buffer, use g_buffered_input_stream_set_buffer_size(). 
- * Note: the buffer's size cannot be reduced below the size of the data within the
- * buffer.
+ * buffered input stream's buffer, use
+ * g_buffered_input_stream_set_buffer_size(). Note that the buffer's size 
+ * cannot be reduced below the size of the data within the buffer.
  *
  **/
 
@@ -207,6 +208,9 @@ g_buffered_input_stream_set_buffer_size (GBufferedInputStream  *stream,
 
   priv = stream->priv;
 
+  if (priv->len == size)
+    return;
+
   if (priv->buffer)
     {
       in_buffer = priv->end - priv->pos;
@@ -229,6 +233,8 @@ g_buffered_input_stream_set_buffer_size (GBufferedInputStream  *stream,
       priv->end = 0;
       priv->buffer = g_malloc (size);
     }
+
+  g_object_notify (G_OBJECT (stream), "buffer-size");
 }
 
 static void
index 020d753495138467fb5b43b02b9a036535e699ff..15ca514d81b9475854b3f723948743fe478e0498 100644 (file)
@@ -153,7 +153,7 @@ g_buffered_output_stream_class_init (GBufferedOutputStreamClass *klass)
                                                       1,
                                                       G_MAXUINT,
                                                       DEFAULT_BUFFER_SIZE,
-                                                      G_PARAM_READWRITE|
+                                                      G_PARAM_READWRITE|G_PARAM_CONSTRUCT|
                                                       G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
 
   g_object_class_install_property (object_class,
index bfcf38ba0faebb66f6b97d1b5d1b1d29157dfbac..b7ab2caf43b473b11e9e069a9718f41e9e249f56 100644 (file)
@@ -23,6 +23,7 @@
 #include <config.h>
 #include <string.h>
 #include "gdataoutputstream.h"
+#include "gioenumtypes.h"
 #include "glibintl.h"
 
 #include "gioalias.h"
@@ -44,7 +45,8 @@ struct _GDataOutputStreamPrivate {
 };
 
 enum {
-  PROP_0
+  PROP_0,
+  PROP_BYTE_ORDER
 };
 
 static void g_data_output_stream_set_property (GObject      *object,
@@ -71,6 +73,22 @@ g_data_output_stream_class_init (GDataOutputStreamClass *klass)
   object_class = G_OBJECT_CLASS (klass);
   object_class->get_property = g_data_output_stream_get_property;
   object_class->set_property = g_data_output_stream_set_property;
+
+  /**
+   * GDataOutputStream:byte-order:
+   *
+   * Determines the byte ordering that is used when writing 
+   * multi-byte entities (such as integers) to the stream.
+   */
+  g_object_class_install_property (object_class,
+                                   PROP_BYTE_ORDER,
+                                   g_param_spec_enum ("byte-order",
+                                                      P_("Byte order"),
+                                                      P_("The byte order"),
+                                                      G_TYPE_DATA_STREAM_BYTE_ORDER,
+                                                      G_DATA_STREAM_BYTE_ORDER_BIG_ENDIAN,
+                                                      G_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_BLURB));
+
 }
 
 static void
@@ -79,14 +97,16 @@ g_data_output_stream_set_property (GObject     *object,
                                  const GValue *value,
                                  GParamSpec   *pspec)
 {
-  GDataOutputStreamPrivate *priv;
-  GDataOutputStream        *dstream;
+  GDataOutputStream *dstream;
 
   dstream = G_DATA_OUTPUT_STREAM (object);
-  priv = dstream->priv;
 
   switch (prop_id) 
     {
+    case PROP_BYTE_ORDER:
+      g_data_output_stream_set_byte_order (dstream, g_value_get_enum (value));
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -106,7 +126,11 @@ g_data_output_stream_get_property (GObject    *object,
   priv = dstream->priv;
 
   switch (prop_id)
-    { 
+    {
+    case PROP_BYTE_ORDER:
+      g_value_set_enum (value, priv->byte_order);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -156,9 +180,14 @@ void
 g_data_output_stream_set_byte_order (GDataOutputStream    *stream,
                                      GDataStreamByteOrder  order)
 {
+  GDataOutputStreamPrivate *priv;
   g_return_if_fail (G_IS_DATA_OUTPUT_STREAM (stream));
-
-  stream->priv->byte_order = order;
+  priv = stream->priv;
+  if (priv->byte_order != order)
+    {
+      priv->byte_order = order;
+      g_object_notify (G_OBJECT (stream), "byte-order");
+    }
 }
 
 /**
index 6c4d290474f6c68ec9af8ec9866c61fe0c8a2a31..00c5bdf1243b68def0c517a47040b9579b9db170 100644 (file)
@@ -64,6 +64,12 @@ struct _GDirectoryMonitorPrivate {
   guint32 timeout_fires_at;
 };
 
+enum {
+  PROP_0,
+  PROP_RATE_LIMIT,
+  PROP_CANCELLED
+};
+
 #define DEFAULT_RATE_LIMIT_MSECS 800
 #define DEFAULT_VIRTUAL_CHANGES_DONE_DELAY_SECS 2
 
@@ -76,6 +82,56 @@ rate_limiter_free (RateLimiter *limiter)
   g_free (limiter);
 }
 
+static void
+g_directory_monitor_set_property (GObject      *object,
+                                  guint         prop_id,
+                                  const GValue *value,
+                                  GParamSpec   *pspec)
+{
+  GDirectoryMonitor *monitor;
+
+  monitor = G_DIRECTORY_MONITOR (object);
+
+  switch (prop_id)
+    {
+    case PROP_RATE_LIMIT:
+      g_directory_monitor_set_rate_limit (monitor, g_value_get_int (value));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+static void
+g_directory_monitor_get_property (GObject    *object,
+                                  guint       prop_id,
+                                  GValue     *value,
+                                  GParamSpec *pspec)
+{
+  GDirectoryMonitor *monitor;
+  GDirectoryMonitorPrivate *priv;
+
+  monitor = G_DIRECTORY_MONITOR (object);
+  priv = monitor->priv;
+
+  switch (prop_id)
+    {
+    case PROP_RATE_LIMIT:
+      g_value_set_int (value, priv->rate_limit_msec);
+      break;
+
+    case PROP_CANCELLED:
+      g_value_set_boolean (value, priv->cancelled);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
 static void
 g_directory_monitor_finalize (GObject *object)
 {
@@ -113,12 +169,15 @@ g_directory_monitor_dispose (GObject *object)
 static void
 g_directory_monitor_class_init (GDirectoryMonitorClass *klass)
 {
-  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+  GObjectClass *object_class;
   
   g_type_class_add_private (klass, sizeof (GDirectoryMonitorPrivate));
   
-  gobject_class->finalize = g_directory_monitor_finalize;
-  gobject_class->dispose = g_directory_monitor_dispose;
+  object_class = G_OBJECT_CLASS (klass);
+  object_class->finalize = g_directory_monitor_finalize;
+  object_class->dispose = g_directory_monitor_dispose;
+  object_class->get_property = g_directory_monitor_get_property;
+  object_class->set_property = g_directory_monitor_set_property;
 
   /**
    * GDirectoryMonitor::changed:
@@ -136,10 +195,28 @@ g_directory_monitor_class_init (GDirectoryMonitorClass *klass)
                  G_STRUCT_OFFSET (GDirectoryMonitorClass, changed),
                  NULL, NULL,
                  _gio_marshal_VOID__OBJECT_OBJECT_INT,
-                 G_TYPE_NONE,3,
-                 G_TYPE_FILE,
-                 G_TYPE_FILE,
-                 G_TYPE_INT);
+                 G_TYPE_NONE, 3,
+                 G_TYPE_FILE, G_TYPE_FILE, G_TYPE_INT);
+
+  g_object_class_install_property (object_class,
+                                   PROP_RATE_LIMIT,
+                                   g_param_spec_int ("rate-limit",
+                                                     P_("Rate limit"),
+                                                     P_("The limit of the monitor to watch for changes, in milliseconds"),
+                                                     0, G_MAXINT,
+                                                     DEFAULT_RATE_LIMIT_MSECS,
+                                                     G_PARAM_READWRITE|
+                                                     G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
+
+  g_object_class_install_property (object_class,
+                                   PROP_CANCELLED,
+                                   g_param_spec_boolean ("cancelled",
+                                                         P_("Cancelled"),
+                                                         P_("Whether the monitor has been cancelled"),
+                                                         FALSE,
+                                                         G_PARAM_READABLE|
+                                                         G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
+
 }
 
 static void
@@ -174,6 +251,7 @@ g_directory_monitor_cancel (GDirectoryMonitor *monitor)
     return TRUE;
   
   monitor->priv->cancelled = TRUE;
+  g_object_notify (G_OBJECT (monitor), "cancelled");
   
   class = G_DIRECTORY_MONITOR_GET_CLASS (monitor);
   return (* class->cancel) (monitor);
@@ -192,9 +270,14 @@ void
 g_directory_monitor_set_rate_limit (GDirectoryMonitor *monitor,
                                    int                limit_msecs)
 {
+  GDirectoryMonitorPrivate *priv;
   g_return_if_fail (G_IS_DIRECTORY_MONITOR (monitor));
-
-  monitor->priv->rate_limit_msec = limit_msecs;
+  priv = monitor->priv;
+  if (priv->rate_limit_msec != limit_msecs)
+    {
+      monitor->priv->rate_limit_msec = limit_msecs;
+      g_object_notify (G_OBJECT (monitor), "rate-limit");
+    }
 }
 
 /**
index 1e1b5a213d095c1339d3a7de7b912b5eb6d194c9..730aa66418c69f64330f9ec53fa44e93ff5f99b0 100644 (file)
@@ -51,7 +51,7 @@ struct _GFileMonitorPrivate {
   int rate_limit_msec;
 
   /* Rate limiting change events */
-  guint32 last_sent_change_time; /* Some monitonic clock in msecs */
+  guint32 last_sent_change_time; /* Some monotonic clock in msecs */
   GFile *last_sent_change_file;
   
   guint send_delayed_change_timeout;
@@ -61,11 +61,68 @@ struct _GFileMonitorPrivate {
   GFile *virtual_changes_done_file;
 };
 
+enum {
+  PROP_0,
+  PROP_RATE_LIMIT,
+  PROP_CANCELLED
+};
+
+static void
+g_file_monitor_set_property (GObject      *object,
+                             guint         prop_id,
+                             const GValue *value,
+                             GParamSpec   *pspec)
+{
+  GFileMonitor *monitor;
+
+  monitor = G_FILE_MONITOR (object);
+
+  switch (prop_id)
+    {
+    case PROP_RATE_LIMIT:
+      g_file_monitor_set_rate_limit (monitor, g_value_get_int (value));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+static void
+g_file_monitor_get_property (GObject    *object,
+                             guint       prop_id,
+                             GValue     *value,
+                             GParamSpec *pspec)
+{
+  GFileMonitor *monitor;
+  GFileMonitorPrivate *priv;
+
+  monitor = G_FILE_MONITOR (object);
+  priv = monitor->priv;
+
+  switch (prop_id)
+    {
+    case PROP_RATE_LIMIT:
+      g_value_set_int (value, priv->rate_limit_msec);
+      break;
+
+    case PROP_CANCELLED:
+      g_value_set_boolean (value, priv->cancelled);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
 #define DEFAULT_RATE_LIMIT_MSECS 800
 #define DEFAULT_VIRTUAL_CHANGES_DONE_DELAY_SECS 2
 
 static guint signals[LAST_SIGNAL] = { 0 };
 
+
 static void
 g_file_monitor_finalize (GObject *object)
 {
@@ -107,12 +164,15 @@ g_file_monitor_dispose (GObject *object)
 static void
 g_file_monitor_class_init (GFileMonitorClass *klass)
 {
-  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+  GObjectClass *object_class;
   
   g_type_class_add_private (klass, sizeof (GFileMonitorPrivate));
   
-  gobject_class->finalize = g_file_monitor_finalize;
-  gobject_class->dispose = g_file_monitor_dispose;
+  object_class = G_OBJECT_CLASS (klass);
+  object_class->finalize = g_file_monitor_finalize;
+  object_class->dispose = g_file_monitor_dispose;
+  object_class->get_property = g_file_monitor_get_property;
+  object_class->set_property = g_file_monitor_set_property;
 
   /**
    * GFileMonitor::changed:
@@ -130,10 +190,27 @@ g_file_monitor_class_init (GFileMonitorClass *klass)
                  G_STRUCT_OFFSET (GFileMonitorClass, changed),
                  NULL, NULL,
                  _gio_marshal_VOID__OBJECT_OBJECT_INT,
-                 G_TYPE_NONE,3,
-                 G_TYPE_FILE,
-                 G_TYPE_FILE,
-                 G_TYPE_INT);
+                 G_TYPE_NONE, 3,
+                 G_TYPE_FILE, G_TYPE_FILE, G_TYPE_INT); 
+
+  g_object_class_install_property (object_class,
+                                   PROP_RATE_LIMIT,
+                                   g_param_spec_int ("rate-limit",
+                                                     P_("Rate limit"),
+                                                     P_("The limit of the monitor to watch for changes, in milliseconds"),
+                                                     0, G_MAXINT,
+                                                     DEFAULT_RATE_LIMIT_MSECS,
+                                                     G_PARAM_READWRITE|
+                                                     G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
+
+  g_object_class_install_property (object_class,
+                                   PROP_CANCELLED,
+                                   g_param_spec_boolean ("cancelled",
+                                                         P_("Cancelled"),
+                                                         P_("Whether the monitor has been cancelled"),
+                                                         FALSE,
+                                                         G_PARAM_READABLE|
+                                                         G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
 }
 
 static void
@@ -180,7 +257,8 @@ g_file_monitor_cancel (GFileMonitor* monitor)
     return TRUE;
   
   monitor->priv->cancelled = TRUE;
-  
+  g_object_notify (G_OBJECT (monitor), "cancelled");
+
   klass = G_FILE_MONITOR_GET_CLASS (monitor);
   return (* klass->cancel) (monitor);
 }
@@ -199,9 +277,14 @@ void
 g_file_monitor_set_rate_limit (GFileMonitor *monitor,
                               int           limit_msecs)
 {
+  GFileMonitorPrivate *priv;
   g_return_if_fail (G_IS_FILE_MONITOR (monitor));
-
-  monitor->priv->rate_limit_msec = limit_msecs;
+  priv = monitor->priv;
+  if (priv->rate_limit_msec != limit_msecs)
+    {
+      monitor->priv->rate_limit_msec = limit_msecs;
+      g_object_notify (G_OBJECT (monitor), "rate-limit");
+    }
 }
 
 static guint32
index e99ab473e47e4b0dc7dfad92b185d812a7507d80..6679c2ecb27410f9466e7ffb1f31a48a5d0443d3 100644 (file)
@@ -305,7 +305,8 @@ g_mount_operation_class_init (GMountOperationClass *klass)
                                                         P_("Username"),
                                                         P_("The user name"),
                                                         NULL,
-                                                        G_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_BLURB));
+                                                        G_PARAM_READWRITE|
+                                                        G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
 
   /**
    * GMountOperation:password:
@@ -319,7 +320,8 @@ g_mount_operation_class_init (GMountOperationClass *klass)
                                                         P_("Password"),
                                                         P_("The password"),
                                                         NULL,
-                                                        G_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_BLURB));
+                                                        G_PARAM_READWRITE|
+                                                        G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
 
   /**
    * GMountOperation:anonymous:
@@ -332,7 +334,8 @@ g_mount_operation_class_init (GMountOperationClass *klass)
                                                          P_("Anonymous"),
                                                          P_("Whether to use an anonymous user"),
                                                          FALSE,
-                                                         G_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_BLURB));
+                                                         G_PARAM_READWRITE|
+                                                         G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
 
   /**
    * GMountOperation:domain:
@@ -345,7 +348,8 @@ g_mount_operation_class_init (GMountOperationClass *klass)
                                                         P_("Domain"),
                                                         P_("The domain of the mount operation"),
                                                         NULL,
-                                                        G_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_BLURB));
+                                                        G_PARAM_READWRITE|
+                                                        G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
 
   /**
    * GMountOperation:password-save:
@@ -359,7 +363,8 @@ g_mount_operation_class_init (GMountOperationClass *klass)
                                                       P_("How passwords should be saved"),
                                                       G_TYPE_PASSWORD_SAVE,
                                                       G_PASSWORD_SAVE_NEVER,
-                                                      G_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_BLURB));
+                                                      G_PARAM_READWRITE|
+                                                      G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
 
   /**
    * GMountOperation:choice:
@@ -373,7 +378,8 @@ g_mount_operation_class_init (GMountOperationClass *klass)
                                                      P_("Choice"),
                                                      P_("The users choice"),
                                                      0, G_MAXINT, 0,
-                                                     G_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_BLURB));
+                                                     G_PARAM_READWRITE|
+                                                     G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
 }
 
 static void