[gnome-shell] Add shell_write_string_to_stream()



commit e4e92a2b3869046bfa9f1b5a2648ee982ff3193c
Author: Owen W. Taylor <otaylor fishsoup net>
Date:   Wed May 12 17:19:20 2010 -0400

    Add shell_write_string_to_stream()
    
    Add a helper function to write a string as UTF-8 to a GOutputStream.
    The signature of GOutputStream:
    
     gboolean g_output_stream_write_all (GOutputStream *stream,
                                         const void *buffer,
                                         gsize count,
                                         gsize *bytes_written,
                                         GCancellable *cancellable,
                                         GError **error);
    
    Can't currently be handled by GJS.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=618189

 src/shell-global.c |   20 ++++++++++++++++++++
 src/shell-global.h |    4 ++++
 2 files changed, 24 insertions(+), 0 deletions(-)
---
diff --git a/src/shell-global.c b/src/shell-global.c
index bc99b43..531ef2c 100644
--- a/src/shell-global.c
+++ b/src/shell-global.c
@@ -1304,6 +1304,26 @@ shell_popup_menu (GtkMenu *menu, int button, guint32 time,
 }
 
 /**
+ * shell_write_string_to_stream:
+ * @stream: a #GOutputStream
+ * @str: a UTF-8 string to write to @stream
+ * @error: location to store GError
+ *
+ * Write a string to a GOutputStream as UTF-8. This is a workaround
+ * for not having binary buffers in GJS.
+ *
+ * Return value: %TRUE if write succeeded
+ */
+gboolean
+shell_write_string_to_stream (GOutputStream *stream,
+                              const char    *str,
+                              GError       **error)
+{
+  return g_output_stream_write_all (stream, str, strlen (str),
+                                    NULL, NULL, error);
+}
+
+/**
  * shell_global_get_current_time:
  * @global: A #ShellGlobal
  *
diff --git a/src/shell-global.h b/src/shell-global.h
index 696b439..480d47b 100644
--- a/src/shell-global.h
+++ b/src/shell-global.h
@@ -92,6 +92,10 @@ ClutterModifierType shell_get_event_state (ClutterEvent *event);
 void shell_popup_menu (GtkMenu *menu, int button, guint32 time,
                        int menu_x, int menu_y);
 
+gboolean shell_write_string_to_stream (GOutputStream *stream,
+                                       const char    *str,
+                                       GError       **error);
+
 guint32 shell_global_get_current_time (ShellGlobal *global);
 
 GAppLaunchContext *shell_global_create_app_launch_context (ShellGlobal *global);



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