Beispiel #1
0
gboolean	
_http_package_write_to_stream_real(HttpPackage * package,
				GOutputStream * stream,
				gsize * length,
				GCancellable * cancellable,
				GError ** error)
{
	HttpPackagePrivate
	* priv = http_package_get_instance_private(package);
	gsize 
	count = 0,total_count = 0;
	GList
	* iter;
	gboolean
	done = TRUE;
	for(iter = g_list_first(priv->attributes);((iter)&&(done));iter = iter->next)
	{
		HttpPackageAttribute
		* attr = (HttpPackageAttribute*)iter->data;
		done = g_output_stream_printf(stream,&count,cancellable,error,"%s: %s\r\n",attr->name,attr->value);
		total_count += count;
	}
	if(done)
	{
		done = g_output_stream_printf(stream,&count,cancellable,error,"\r\n");
		if(length) *length = total_count + count;
	}
	if(done)
		g_output_stream_flush(stream,cancellable,error);
	return done;
}
Beispiel #2
0
static inline bool
write_line(GOutputStream *out,
           const char    *line,
           GError       **error)
{
    return g_output_stream_printf(out, nullptr, nullptr, error, "%s\n", line);
}
Beispiel #3
0
gboolean	
_http_response_write_to_stream_real(HttpPackage * package,
				GOutputStream * stream,
				gsize * length,
				GCancellable * cancellable,
				GError ** error)
{
	g_return_val_if_fail(HTTP_IS_RESPONSE(package),FALSE);
	HttpResponsePrivate
	* priv = http_response_get_instance_private(HTTP_RESPONSE(package));
	g_return_val_if_fail(priv->code != HTTP_RESPONSE_INVALID,FALSE);
	g_return_val_if_fail(priv->version > 0,FALSE);
	gsize
	count = 0,total_count = 0;
	gboolean
	done = TRUE;
	if(g_output_stream_printf(stream,&count,cancellable,error,"HTTP/%0.1f %d %s\r\n",priv->version,_http_response_codes[priv->code],_http_response_strings[priv->code]))
	{
		done = HTTP_PACKAGE_CLASS(http_response_parent_class)->write_to_stream(package,stream,&total_count,cancellable,error);
		if(length)
			*length = total_count + count;		
	}
	else
		done = FALSE;	
	return done;
}
Beispiel #4
0
static bool
write_source_file_header(GOutputStream *stream,
                         GFile         *source_file,
                         GError       **error)
{
    GjsAutoChar path = get_file_identifier(source_file);
    return g_output_stream_printf(stream, NULL, NULL, error, "SF:%s\n", path.get());
}
Beispiel #5
0
static void
dump_with_linebreaks (GOutputStream *output,
                      const gchar   *text)
{
  gint len = strlen (text);

  while (len > 0)
    {
      const gchar *t;
      gint         i, space;

      /*  groff doesn't like lines to start with a single quote  */
      if (*text == '\'')
        g_output_stream_printf (output, NULL, NULL, NULL,
                                "\\&");  /*  a zero width space  */

      for (t = text, i = 0, space = 0;
           *t != '\n' && (i <= LINE_LENGTH || space == 0) && i < len;
           t++, i++)
        {
          if (g_ascii_isspace (*t))
            space = i;
        }

      if (i > LINE_LENGTH && space && *t != '\n')
        i = space;

      g_output_stream_write_all (output, text, i, NULL, NULL, NULL);
      g_output_stream_printf (output, NULL, NULL, NULL,
                              "\n");

      if (*t == '\n')
        g_output_stream_printf (output, NULL, NULL, NULL,
                                ".br\n");

      i++;

      text += i;
      len  -= i;
    }
}
Beispiel #6
0
static void
dump_gimprc_manpage (GimpConfig       *rc,
                     GimpConfigWriter *writer,
                     GOutputStream    *output)
{
  GObjectClass  *klass;
  GParamSpec   **property_specs;
  guint          n_property_specs;
  guint          i;

  g_output_stream_printf (output, NULL, NULL, NULL,
                          "%s", man_page_header);

  klass = G_OBJECT_GET_CLASS (rc);
  property_specs = g_object_class_list_properties (klass, &n_property_specs);

  for (i = 0; i < n_property_specs; i++)
    {
      GParamSpec *prop_spec = property_specs[i];
      gchar      *desc;

      if (! (prop_spec->flags & GIMP_CONFIG_PARAM_SERIALIZE))
        continue;

      if (prop_spec->flags & GIMP_CONFIG_PARAM_IGNORE)
        continue;

      g_output_stream_printf (output, NULL, NULL, NULL,
                              ".TP\n");

      if (gimp_config_serialize_property (rc, prop_spec, writer))
        {
          g_output_stream_printf (output, NULL, NULL, NULL,
                                  "\n");

          desc = dump_describe_param (prop_spec);

          dump_with_linebreaks (output, desc);

          g_output_stream_printf (output, NULL, NULL, NULL,
                                  "\n");

          g_free (desc);
        }
    }

  g_free (property_specs);

  g_output_stream_printf (output, NULL, NULL, NULL,
                          "%s", man_page_path);
  g_output_stream_printf (output, NULL, NULL, NULL,
                          "%s", man_page_footer);
}
Beispiel #7
0
void playlist_save_handler(	GSimpleAction *action,
				GVariant *param,
				gpointer data )
{
	gmpv_handle *ctx = data;
	PlaylistWidget *playlist;
	GFile *dest_file;
	GOutputStream *dest_stream;
	GtkFileChooser *file_chooser;
	GtkWidget *save_dialog;
	GError *error;
	GtkTreeIter iter;
	gboolean rc;

	playlist = PLAYLIST_WIDGET(ctx->gui->playlist);
	dest_file = NULL;
	dest_stream = NULL;
	error = NULL;
	rc = FALSE;

	save_dialog
		= gtk_file_chooser_dialog_new(	_("Save Playlist"),
						GTK_WINDOW(ctx->gui),
						GTK_FILE_CHOOSER_ACTION_SAVE,
						_("_Cancel"),
						GTK_RESPONSE_CANCEL,
						_("_Save"),
						GTK_RESPONSE_ACCEPT,
						NULL );

	file_chooser = GTK_FILE_CHOOSER(save_dialog);

	gtk_file_chooser_set_do_overwrite_confirmation(file_chooser, TRUE);
	gtk_file_chooser_set_current_name(file_chooser, "playlist.m3u");

	if(gtk_dialog_run(GTK_DIALOG(save_dialog)) == GTK_RESPONSE_ACCEPT)
	{
		/* There should be only one file selected. */
		dest_file = gtk_file_chooser_get_file(file_chooser);
	}

	gtk_widget_destroy(save_dialog);

	if(dest_file)
	{
		GFileOutputStream *dest_file_stream;

		dest_file_stream = g_file_replace(	dest_file,
							NULL,
							FALSE,
							G_FILE_CREATE_NONE,
							NULL,
							&error );

		dest_stream = G_OUTPUT_STREAM(dest_file_stream);

		rc = gtk_tree_model_get_iter_first
			(GTK_TREE_MODEL(playlist->list_store), &iter);

		rc &= !!dest_stream;
	}

	while(rc)
	{
		gchar *uri;
		gsize written;

		gtk_tree_model_get(	GTK_TREE_MODEL(playlist->list_store),
					&iter,
					PLAYLIST_URI_COLUMN,
					&uri,
					-1 );

		rc &= g_output_stream_printf(	dest_stream,
						&written,
						NULL,
						&error,
						"%s\n",
						uri );

		rc &= gtk_tree_model_iter_next
			(GTK_TREE_MODEL(playlist->list_store), &iter);
	}

	if(dest_stream)
	{
		g_output_stream_close(dest_stream, NULL, &error);
	}

	if(dest_file)
	{
		g_object_unref(dest_file);
	}

	if(error)
	{
		show_error_dialog(ctx, NULL, error->message);

		g_error_free(error);
	}
}