• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ G_INPUT_STREAM函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中G_INPUT_STREAM函数的典型用法代码示例。如果您正苦于以下问题:C++ G_INPUT_STREAM函数的具体用法?C++ G_INPUT_STREAM怎么用?C++ G_INPUT_STREAM使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了G_INPUT_STREAM函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: checksum_file_list_parse_checksum_file

gint
checksum_file_list_parse_checksum_file (CheckcopyFileList * list, GFile *root, GFile *file)
{
  CheckcopyFileListPrivate *priv = GET_PRIVATE (list);
  GDataInputStream * in;
  gchar * line;
  gsize length;
  GCancellable *cancel;
  GError * error = NULL;
  GFile * parent;
  gchar * prefix;
  gint n = 0;

  cancel = checkcopy_get_cancellable ();

  parent = g_file_get_parent (file);
  prefix = g_file_get_relative_path (root, parent);

  in = g_data_input_stream_new (G_INPUT_STREAM (g_file_read (file, cancel, &error)));

  while ((line = g_data_input_stream_read_line (in,
                                                &length,
                                                cancel,
                                                &error)) != NULL)
  {
    gchar *c;

    if (*line == ';' || *line == '#') {
      /* skip comment lines */
      continue;
    }

    /* find the end of the first column */
    for (c = line; *c != ' ' && *c != '\0'; c++);

    /* make sure we found some chars and we don't just have one column */
    if (c != line && *c != '\0') {
      gchar * checksum = NULL;
      gchar * filename = NULL;
      CheckcopyFileInfo * info;
      CheckcopyChecksumType checksum_type;

      /* found a checksum, parse the line into
       * checksum and filename */

      n++;

      *c = '\0';
      c++;

      checksum = g_strdup (line);

      checksum_type = checkcopy_file_info_get_checksum_type (line);

      /* skip spaces */
      while (*c == ' ' && *c != '\0') c++;

      /* some programs mark filenames with a star */
      if (*c == '*')
        c++;

      /* rest of the line is the file name */

      if (prefix != NULL && *prefix != '\0')
        filename = g_strconcat (prefix, G_DIR_SEPARATOR_S, c, NULL);
      else
        filename = g_strdup (c);


      info = checkcopy_file_list_grab_info (list, filename);

      if (info->status == CHECKCOPY_STATUS_NONE) {
        info->checksum = checksum;
        info->checksum_type = checksum_type;
        checkcopy_file_list_transition (list, info, CHECKCOPY_STATUS_VERIFIABLE);

        DBG ("Parsed checksum for %s", info->relname);

        if (priv->verify_only) {
          checkcopy_worker_add_file (g_file_resolve_relative_path (root, filename));
        }
      } else {
        /* We saw the file before the checksum.
         *
         * Verify it now.
         */

        DBG ("%s was copied already, verifying it immediately", filename);

        if (!g_str_equal (info->checksum, checksum)) {
          /* Verification failed. We want to display the checksum
           * the file is supposed to have in the gui, so switch
           * the two variables.
           */
          gchar * ts;

          ts = info->checksum;
          info->checksum = checksum;
          checksum = ts;

//.........这里部分代码省略.........
开发者ID:squisher,项目名称:checkcopy,代码行数:101,代码来源:checkcopy-file-list.c


示例2: g_input_stream_read

/**
 * Read content of file or create file list from directory
 * @param aBuf read destination buffer
 * @param aCount length of destination buffer
 * @param aCountRead number of read characters
 * @return NS_OK when read successfully, NS_BASE_STREAM_CLOSED when end of file,
 *         error code otherwise
 */
nsresult
nsGIOInputStream::DoRead(char *aBuf, uint32_t aCount, uint32_t *aCountRead)
{
  nsresult rv = NS_ERROR_NOT_AVAILABLE;
  if (mStream) {
    // file read
    GError *error = nullptr;    
    uint32_t bytes_read = g_input_stream_read(G_INPUT_STREAM(mStream),
                                              aBuf,
                                              aCount,
                                              nullptr,
                                              &error);
    if (error) {
      rv = MapGIOResult(error);
      *aCountRead = 0;
      g_warning("Cannot read from file: %s", error->message);
      g_error_free(error);
      return rv;
    }
    *aCountRead = bytes_read;
    mBytesRemaining -= *aCountRead;
    return NS_OK;
  }
  else if (mDirOpen) {
    // directory read
    while (aCount && rv != NS_BASE_STREAM_CLOSED)
    {
      // Copy data out of our buffer
      uint32_t bufLen = mDirBuf.Length() - mDirBufCursor;
      if (bufLen)
      {
        uint32_t n = std::min(bufLen, aCount);
        memcpy(aBuf, mDirBuf.get() + mDirBufCursor, n);
        *aCountRead += n;
        aBuf += n;
        aCount -= n;
        mDirBufCursor += n;
      }

      if (!mDirListPtr)    // Are we at the end of the directory list?
      {
        rv = NS_BASE_STREAM_CLOSED;
      }
      else if (aCount)     // Do we need more data?
      {
        GFileInfo *info = (GFileInfo *) mDirListPtr->data;

        // Prune '.' and '..' from directory listing.
        const char * fname = g_file_info_get_name(info);
        if (fname && fname[0] == '.' && 
            (fname[1] == '\0' || (fname[1] == '.' && fname[2] == '\0')))
        {
          mDirListPtr = mDirListPtr->next;
          continue;
        }

        mDirBuf.AssignLiteral("201: ");

        // The "filename" field
        nsCString escName;
        nsCOMPtr<nsINetUtil> nu = do_GetService(NS_NETUTIL_CONTRACTID);
        if (nu && fname) {
          nu->EscapeString(nsDependentCString(fname),
                           nsINetUtil::ESCAPE_URL_PATH, escName);

          mDirBuf.Append(escName);
          mDirBuf.Append(' ');
        }

        // The "content-length" field
        // XXX truncates size from 64-bit to 32-bit
        mDirBuf.AppendInt(int32_t(g_file_info_get_size(info)));
        mDirBuf.Append(' ');

        // The "last-modified" field
        //
        // NSPR promises: PRTime is compatible with time_t
        // we just need to convert from seconds to microseconds
        GTimeVal gtime;
        g_file_info_get_modification_time(info, &gtime);

        PRExplodedTime tm;
        PRTime pt = ((PRTime) gtime.tv_sec) * 1000000;
        PR_ExplodeTime(pt, PR_GMTParameters, &tm);
        {
          char buf[64];
          PR_FormatTimeUSEnglish(buf, sizeof(buf),
              "%a,%%20%d%%20%b%%20%Y%%20%H:%M:%S%%20GMT ", &tm);
          mDirBuf.Append(buf);
        }

        // The "file-type" field
//.........这里部分代码省略.........
开发者ID:AOSC-Dev,项目名称:Pale-Moon,代码行数:101,代码来源:nsGIOProtocolHandler.cpp


示例3: scrollback_load

void
scrollback_load (session *sess)
{
	GInputStream *stream;
	GDataInputStream *istream;
	gchar *buf, *text;
	gint lines = 0;
	time_t stamp = 0;

	if (sess->text_scrollback == SET_DEFAULT)
	{
		if (!prefs.hex_text_replay)
			return;
	}
	else
	{
		if (sess->text_scrollback != SET_ON)
			return;
	}

	if (!sess->scrollfile)
	{
		if ((buf = scrollback_get_filename (sess)) == NULL)
			return;

		sess->scrollfile = g_file_new_for_path (buf);
		g_free (buf);
	}

	stream = G_INPUT_STREAM(g_file_read (sess->scrollfile, NULL, NULL));
	if (!stream)
		return;

	istream = g_data_input_stream_new (stream);
	/*
	 * This is to avoid any issues moving between windows/unix
	 * but the docs mention an invalid \r without a following \n
	 * can lock up the program... (Our write() always adds \n)
	 */
	g_data_input_stream_set_newline_type (istream, G_DATA_STREAM_NEWLINE_TYPE_ANY);
	g_object_unref (stream);

	while (1)
	{
		GError *err = NULL;
		gsize n_bytes;

		buf = g_data_input_stream_read_line_utf8 (istream, &n_bytes, NULL, &err);

		if (!err && buf)
		{
			/*
			 * Some scrollback lines have three blanks after the timestamp and a newline
			 * Some have only one blank and a newline
			 * Some don't even have a timestamp
			 * Some don't have any text at all
			 */
			if (buf[0] == 'T' && buf[1] == ' ')
			{
				if (sizeof (time_t) == 4)
					stamp = strtoul (buf + 2, NULL, 10);
				else
					stamp = g_ascii_strtoull (buf + 2, NULL, 10); /* in case time_t is 64 bits */

				if (G_UNLIKELY(stamp == 0))
				{
					g_warning ("Invalid timestamp in scrollback file");
					continue;
				}

				text = strchr (buf + 3, ' ');
				if (text && text[1])
				{
					if (prefs.hex_text_stripcolor_replay)
					{
						text = strip_color (text + 1, -1, STRIP_COLOR);
					}

					fe_print_text (sess, text, stamp, TRUE);

					if (prefs.hex_text_stripcolor_replay)
					{
						g_free (text);
					}
				}
				else
				{
					fe_print_text (sess, "  ", stamp, TRUE);
				}
			}
			else
			{
				if (strlen (buf))
					fe_print_text (sess, buf, 0, TRUE);
				else
					fe_print_text (sess, "  ", 0, TRUE);
			}
			lines++;

			g_free (buf);
//.........这里部分代码省略.........
开发者ID:Cynede,项目名称:hexchat,代码行数:101,代码来源:text.c


示例4: gimp_scanner_new_gfile

/**
 * gimp_scanner_new_gfile:
 * @file: a #GFile
 * @error: return location for #GError, or %NULL
 *
 * Return value: The new #GScanner.
 *
 * Since: 2.10
 **/
GScanner *
gimp_scanner_new_gfile (GFile   *file,
                        GError **error)
{
  GScanner *scanner;
  gchar    *path;

  g_return_val_if_fail (G_IS_FILE (file), NULL);
  g_return_val_if_fail (error == NULL || *error == NULL, NULL);

  path = g_file_get_path (file);

  if (path)
    {
      GMappedFile *mapped;

      mapped = g_mapped_file_new (path, FALSE, error);
      g_free (path);

      if (! mapped)
        {
          if (error)
            {
              (*error)->domain = GIMP_CONFIG_ERROR;
              (*error)->code   = ((*error)->code == G_FILE_ERROR_NOENT ?
                                  GIMP_CONFIG_ERROR_OPEN_ENOENT :
                                  GIMP_CONFIG_ERROR_OPEN);
            }

          return NULL;
        }

      /*  gimp_scanner_new() takes a "name" for the scanner, not a filename  */
      scanner = gimp_scanner_new (gimp_file_get_utf8_name (file),
                                  mapped, NULL, error);

      g_scanner_input_text (scanner,
                            g_mapped_file_get_contents (mapped),
                            g_mapped_file_get_length (mapped));
    }
  else
    {
      GInputStream *input;

      input = G_INPUT_STREAM (g_file_read (file, NULL, error));

      if (! input)
        {
          if (error)
            {
              (*error)->domain = GIMP_CONFIG_ERROR;
              (*error)->code   = ((*error)->code == G_IO_ERROR_NOT_FOUND ?
                                  GIMP_CONFIG_ERROR_OPEN_ENOENT :
                                  GIMP_CONFIG_ERROR_OPEN);
            }

          return NULL;
        }

      g_object_set_data (G_OBJECT (input), "gimp-data", file);

      scanner = gimp_scanner_new_stream (input, error);

      g_object_unref (input);
    }

  return scanner;
}
开发者ID:LebedevRI,项目名称:gimp,代码行数:77,代码来源:gimpscanner.c


示例5: xmms_gvfs_init

static gboolean
xmms_gvfs_init (xmms_xform_t *xform)
{
	xmms_gvfs_data_t *data;
	GFile *file;
	GFileInfo *info;
	GFileInputStream *handle;
	GError *error = NULL;
	const gchar *url;

	url = xmms_xform_indata_get_str (xform, XMMS_STREAM_TYPE_URL);
	g_return_val_if_fail (url, FALSE);

	/* This is an ugly hack to handle files with
	   chars needing url encoding */
	if (!g_ascii_strncasecmp (url, "file://", 7)) {
		file = g_file_new_for_path (url+7);
	} else {
		file = g_file_new_for_uri (url);
	}
	handle = g_file_read (file, NULL, &error);
	g_object_unref (file);

	if (!handle) {
		xmms_log_error ("Failed to upen url %s for reading: %s",
		                url, error->message);
		return FALSE;
	}

	data = g_new (xmms_gvfs_data_t, 1);
	data->handle = G_INPUT_STREAM (handle);
	xmms_xform_private_data_set (xform, data);

	info = g_file_input_stream_query_info (handle, (char *)query_attributes,
	                                       NULL, &error);

	if (!info) {
		xmms_log_info ("failed to query information for %s", url);
	} else {
		int i;

		for (i = 0; i < G_N_ELEMENTS (attr_map); i++) {
			if (!g_file_info_has_attribute (info, attr_map[i].gvfs)) {
				continue;
			}

			switch (attr_map[i].type) {
				case XMMSV_TYPE_STRING: {
					gchar *attr = g_file_info_get_attribute_as_string (info,
					                                                   attr_map[i].gvfs);
					xmms_xform_metadata_set_str (xform, attr_map[i].mlib, attr);
					g_free (attr);
					break;
				}
				case XMMSV_TYPE_INT32: {
					/* right now the xform metadata api only handles strings
					 * and 32 bit ints. however the gvfs api returns uint64 for
					 * the numeric attributes we're interested in and we just
					 * pass that to the xform and pray that it doesn't overflow
					 * as we know it's unsafe.
					 */

					gint64 attr = g_file_info_get_attribute_uint64 (info,
					                                                attr_map[i].gvfs);
					xmms_xform_metadata_set_int (xform, attr_map[i].mlib, attr);
					break;
				}
				default:
					g_assert_not_reached ();
			}
		}

		g_object_unref (info);
	}

	xmms_xform_outdata_type_add (xform,
	                             XMMS_STREAM_TYPE_MIMETYPE,
	                             "application/octet-stream",
	                             XMMS_STREAM_TYPE_END);

	return TRUE;
}
开发者ID:randalboyle,项目名称:xmms2-devel,代码行数:82,代码来源:gvfs.c


示例6: render_card_init

static void
render_card_init (char *card_fname)
{
	int i;
	if (render_init) {
		for (i = 0; i < 52; i++)
			g_object_unref (card_pixbuf[i]);
		cairo_surface_destroy (grey_surface);
		render_init = 0;
	}

	/* gdk_pixbuf_new_from_file doesn't seem to support .svgz (while
	 * librsvg does), so decompress it here. Code from aisleriot
	 * src/lib/ar-svg.c */
	GFile *cf = g_file_new_for_path (card_fname);
	GFileInfo *info;
	GError *error = NULL;
	if (!(info = g_file_query_info (cf,
					G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE,
					G_FILE_QUERY_INFO_NONE,
					NULL,
					&error))) {
		printf ("%s: %s\n", card_fname, error->message);
		g_object_unref (cf);
		g_error_free (error);
		return;
	}

	const char *type = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE);
	char *gz_type = g_content_type_from_mime_type ("application/x-gzip");
	gboolean is_gzip = (type != NULL && g_content_type_is_a (type, gz_type));
	g_free (gz_type);
	g_object_unref (info);

	GInputStream *stream;
	if (!(stream = G_INPUT_STREAM (g_file_read (cf, NULL, &error)))) {
		printf ("%s: %s\n", card_fname, error->message);
		g_object_unref (cf);
		g_error_free (error);
		return;
	}
	g_object_unref (cf);

	if (is_gzip) {
		GZlibDecompressor *decompressor;
		GInputStream *converter_stream;

		decompressor = g_zlib_decompressor_new (G_ZLIB_COMPRESSOR_FORMAT_GZIP);
		converter_stream = g_converter_input_stream_new (stream,
				G_CONVERTER (decompressor));
		g_object_unref (stream);
		stream = converter_stream;
	}

	/* file contains cards in 13 columns (A/2..10/J/Q/K) and 5 rows (C/D/H/S/Jokers) */
	/* actual card height is computed from resulting actual size */
	GdkPixbuf *pb = gdk_pixbuf_new_from_stream_at_scale (stream,
			card_width * 13, -1, TRUE, NULL, &error);
	g_object_unref (stream);
	if (!pb) {
		printf ("%s: %s.\n", card_fname, error->message);
		g_error_free (error);
		return;
	}
	int buf_width = gdk_pixbuf_get_width (pb);
	int buf_height = gdk_pixbuf_get_height (pb);
	card_width = ceil (gdk_pixbuf_get_width (pb) / 13.0);
	card_height = ceil (gdk_pixbuf_get_height (pb) / 5.0);
	for (i = 0; i < 52; i++) {
		card_pixbuf[i] = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, card_width, card_height);
		if (!card_pixbuf[i]) {
			printf ("%s: rendering card_pixbuf failed\n", card_fname);
			return;
		}
		int col = (i + 1) % 13;
		int row = i / 13;
		gdk_pixbuf_copy_area (pb, buf_width * col / 13.0, buf_height * row / 5.0,
		//gdk_pixbuf_copy_area (pb, card_width * col, card_height * row,
			card_width, card_height, card_pixbuf[i], 0, 0);
	}
	g_object_unref (pb);

	/* construct a alpha channel in card shape for greying out cards */
	grey_surface = cairo_image_surface_create (CAIRO_FORMAT_A8, card_width, card_height);
	cairo_t *ct = cairo_create (grey_surface);
	gdk_cairo_set_source_pixbuf (ct, card_pixbuf[0], 0, 0);
	cairo_paint_with_alpha (ct, 0.3);
	cairo_destroy (ct);

	render_init = 1;
}
开发者ID:ChristophBerg,项目名称:tenace,代码行数:91,代码来源:hand_display.c


示例7: xcf_load_invoker

static GimpValueArray *
xcf_load_invoker (GimpProcedure         *procedure,
                  Gimp                  *gimp,
                  GimpContext           *context,
                  GimpProgress          *progress,
                  const GimpValueArray  *args,
                  GError               **error)
{
  XcfInfo         info = { 0, };
  GimpValueArray *return_vals;
  GimpImage      *image   = NULL;
  const gchar    *uri;
  gchar          *filename;
  GFile          *file;
  gboolean        success = FALSE;
  gchar           id[14];
  GError         *my_error = NULL;

  gimp_set_busy (gimp);

  uri      = g_value_get_string (gimp_value_array_index (args, 1));
#ifdef GIO_IS_FIXED
  file     = g_file_new_for_uri (uri);
#else
  file     = g_file_new_for_path (uri);
#endif
  filename = g_file_get_parse_name (file);

  info.input = G_INPUT_STREAM (g_file_read (file, NULL, &my_error));

  if (info.input)
    {
      info.gimp        = gimp;
      info.seekable    = G_SEEKABLE (info.input);
      info.progress    = progress;
      info.filename    = filename;
      info.compression = COMPRESS_NONE;

      if (progress)
        {
          gchar *name = g_filename_display_name (filename);
          gchar *msg  = g_strdup_printf (_("Opening '%s'"), name);

          gimp_progress_start (progress, msg, FALSE);

          g_free (msg);
          g_free (name);
        }

      success = TRUE;

      info.cp += xcf_read_int8 (info.input, (guint8 *) id, 14);

      if (! g_str_has_prefix (id, "gimp xcf "))
        {
          success = FALSE;
        }
      else if (strcmp (id + 9, "file") == 0)
        {
          info.file_version = 0;
        }
      else if (id[9] == 'v')
        {
          info.file_version = atoi (id + 10);
        }
      else
        {
          success = FALSE;
        }

      if (success)
        {
          if (info.file_version >= 0 &&
              info.file_version < G_N_ELEMENTS (xcf_loaders))
            {
              image = (*(xcf_loaders[info.file_version])) (gimp, &info, error);

              if (! image)
                success = FALSE;
            }
          else
            {
              g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                           _("XCF error: unsupported XCF file version %d "
                             "encountered"), info.file_version);
              success = FALSE;
            }
        }

      g_object_unref (info.input);

      if (progress)
        gimp_progress_end (progress);
    }
  else
    {
      g_propagate_prefixed_error (error, my_error,
                                  _("Could not open '%s' for reading: "),
                                  filename);
    }
//.........这里部分代码省略.........
开发者ID:alfanak,项目名称:gimp,代码行数:101,代码来源:xcf.c


示例8: info_mpc_read

/*
* info_mpc_read:
* @file: file from which to read a header
* @stream_info: stream information to fill
* @error: a #Gerror, or %NULL
*
* Read header from the given MusePack @file.
*
* Returns: %TRUE on success, %FALSE and with @error set on failure
*/
gboolean
info_mpc_read (GFile *file,
               StreamInfoMpc *stream_info,
               GError **error)
{
    GFileInfo *info;
    GFileInputStream *istream;
    guint32 header_buffer[MPC_HEADER_LENGTH];
    gsize bytes_read;
    gsize id3_size;
    
    info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_SIZE,
                              G_FILE_QUERY_INFO_NONE, NULL, error);

    if (!info)
    {
        return FALSE;
    }

    stream_info->FileSize = g_file_info_get_size (info);
    g_object_unref (info);

    {
        gchar *path;
        FILE *fp;

        path = g_file_get_path (file);
        fp = g_fopen (path, "rb");
        g_free (path);

        if (!fp)
        {
            /* TODO: Add specific error domain and message. */
            g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_INVAL, "%s",
                         g_strerror (EINVAL));
            return FALSE;
        }

        /* Skip id3v2. */
        /* FIXME: is_id3v2 (and is_id3v1 and is_ape) should accept an istream
         * or GFile. */
        id3_size = is_id3v2 (fp);

        fseek (fp, 0, SEEK_END);
        stream_info->FileSize = ftell (fp);

        /* Stream size. */
        stream_info->ByteLength = stream_info->FileSize - is_id3v1 (fp)
                                  - is_ape (fp) - id3_size;

        fclose (fp);
    }
        
    istream = g_file_read (file, NULL, error);

    if (!istream)
    {
        return FALSE;
    }

    if (!g_seekable_seek (G_SEEKABLE (istream), id3_size, G_SEEK_SET, NULL,
                          error))
    {
        return FALSE;
    }

    /* Read 16 guint32. */
    if (!g_input_stream_read_all (G_INPUT_STREAM (istream), header_buffer,
                                  MPC_HEADER_LENGTH * 4, &bytes_read, NULL,
                                  error))
    {
        g_debug ("Only %" G_GSIZE_FORMAT "bytes out of 16 bytes of data were "
                 "read", bytes_read);
        return FALSE;
    }

    /* FIXME: Read 4 bytes, take as a uint32, then byteswap if necessary. (The
     * official Musepack decoder expects the user(!) to request the
     * byteswap.) */
    if (memcmp (header_buffer, "MP+", 3) != 0)
    {
        /* TODO: Add specific error domain and message. */
        g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_INVAL, "%s",
                     g_strerror (EINVAL));
        return FALSE;
    }
    
    stream_info->StreamVersion = header_buffer[0] >> 24;

    if (stream_info->StreamVersion >= 7)
//.........这里部分代码省略.........
开发者ID:GNOME,项目名称:easytag,代码行数:101,代码来源:info_mpc.c


示例9: gimp_color_profile_new_from_file

/**
 * gimp_color_profile_new_from_file:
 * @file:  a #GFile
 * @error: return location for #GError
 *
 * This function opens an ICC color profile from @file.
 *
 * Return value: the #GimpColorProfile, or %NULL. On error, %NULL is
 *               returned and @error is set.
 *
 * Since: 2.10
 **/
GimpColorProfile *
gimp_color_profile_new_from_file (GFile   *file,
                                  GError **error)
{
  GimpColorProfile *profile      = NULL;
  cmsHPROFILE       lcms_profile = NULL;
  guint8           *data         = NULL;
  gsize             length       = 0;
  gchar            *path;

  g_return_val_if_fail (G_IS_FILE (file), NULL);
  g_return_val_if_fail (error == NULL || *error == NULL, NULL);

  path = g_file_get_path (file);

  if (path)
    {
      GMappedFile  *mapped;

      mapped = g_mapped_file_new (path, FALSE, error);

      if (! mapped)
        return NULL;

      length = g_mapped_file_get_length (mapped);
      data   = g_memdup (g_mapped_file_get_contents (mapped), length);

      lcms_profile = cmsOpenProfileFromMem (data, length);

      g_mapped_file_unref (mapped);
    }
  else
    {
      GFileInfo *info;

      info = g_file_query_info (file,
                                G_FILE_ATTRIBUTE_STANDARD_SIZE,
                                G_FILE_QUERY_INFO_NONE,
                                NULL, error);
      if (info)
        {
          GInputStream *input;

          length = g_file_info_get_size (info);
          data   = g_malloc (length);

          g_object_unref (info);

          input = G_INPUT_STREAM (g_file_read (file, NULL, error));

          if (input)
            {
              gsize bytes_read;

              if (g_input_stream_read_all (input, data, length,
                                           &bytes_read, NULL, error) &&
                  bytes_read == length)
                {
                  lcms_profile = cmsOpenProfileFromMem (data, length);
                }

              g_object_unref (input);
            }
        }
    }

  if (lcms_profile)
    {
      profile = g_object_new (GIMP_TYPE_COLOR_PROFILE, NULL);

      profile->priv->lcms_profile = lcms_profile;
      profile->priv->data         = data;
      profile->priv->length       = length;
    }
  else
    {
      if (data)
        g_free (data);

      if (error && *error == NULL)
        {
          g_set_error (error, gimp_color_profile_error_quark (), 0,
                       _("'%s' does not appear to be an ICC color profile"),
                       gimp_file_get_utf8_name (file));
        }
    }

  return profile;
//.........这里部分代码省略.........
开发者ID:jones263,项目名称:gimp,代码行数:101,代码来源:gimpcolorprofile.c


示例10: web_handler

static void
web_handler (ShpHttpRequest request, const gchar * path, const gchar * query,
    GSocketConnection * connection, gpointer user_data)
{
  ShpRest *self = SHP_REST (user_data);
  GFile *file;
  GFileInputStream *input_stream;
  GDataInputStream *data;
  GError *error = NULL;
  GOutputStream *out;
  gchar *line;
  ShpJsonNode *node;

  out = g_io_stream_get_output_stream (G_IO_STREAM (connection));

  if (request != SHP_HTTP_GET) {
    g_debug ("rest: unsupported request type");
    send_error (out, 400, "Invalid request");
    return;
  }

  if (self->config_file == NULL) {
    g_warning ("rest: config file not specified");
    send_error (out, 500, "Internal server error");
    return;
  }

  /* FIXME: load file at start */
  file = g_file_new_for_path (self->config_file);
  input_stream = g_file_read (file, NULL, &error);
  if (!input_stream) {
    g_warning ("rest: error reading config file: %s", error->message);
    g_clear_error (&error);
    send_error (out, 500, "Internal server error");
    return;
  }

  data = g_data_input_stream_new (G_INPUT_STREAM (input_stream));

  node = shp_json_node_new_object (NULL);

  while (TRUE) {
    guint i;
    gchar **options_list;
    ShpJsonNode *obj = NULL;
    ShpJsonNode *arr = NULL;

    //plugin:device-type:type1,option1:type2,option2

    line = g_data_input_stream_read_line (data, NULL, NULL, NULL);
    if (!line)
      break;

    g_debug ("rest: config file line: %s", line);

    options_list = g_strsplit (line, ":", 0);
    for (i = 0; options_list[i] != NULL; i++) {
      ShpJsonNode *child;
      ShpJsonNode *grand_child;
      gchar **params;

      switch (i) {
        case 0:
          obj = shp_json_node_new_object (options_list[i]);
          break;
        case 1:
          child = shp_json_node_new_string ("device-type", options_list[i]);
          shp_json_node_append_element (obj, child);
          break;
        case 2:
          arr = shp_json_node_new_array ("display-options");
          /* fall trhough */
        default:
          params = g_strsplit (options_list[i], " ", 0);
          if (params && params[0] && params[1] && !params[2]) {
            child = shp_json_node_new_object (NULL);
            grand_child = shp_json_node_new_string ("option", params[0]);
            shp_json_node_append_element (child, grand_child);
            grand_child = shp_json_node_new_string ("type", params[1]);
            shp_json_node_append_element (child, grand_child);
            shp_json_node_append_element (arr, child);
          }
          g_strfreev (params);
          break;
      }
    }
    g_strfreev (options_list);

    if (obj != NULL) {
      if (arr != NULL)
        shp_json_node_append_element (obj, arr);
      shp_json_node_append_element (node, obj);
    }

    g_free (line);
  }

  g_object_unref (input_stream);
  g_object_unref (file);

//.........这里部分代码省略.........
开发者ID:otonchev,项目名称:homefrog,代码行数:101,代码来源:shp-rest.c


示例11: g_file_input_stream_query_info

 *
 * Returns: a #GFileInfo, or %NULL on error.
 **/
GFileInfo *
g_file_input_stream_query_info (GFileInputStream  *stream,
                                const char        *attributes,
                                GCancellable      *cancellable,
                                GError           **error)
{
  GFileInputStreamClass *class;
  GInputStream *input_stream;
  GFileInfo *info;
  
  g_return_val_if_fail (G_IS_FILE_INPUT_STREAM (stream), NULL);
  
  input_stream = G_INPUT_STREAM (stream);
  
  if (!g_input_stream_set_pending (input_stream, error))
    return NULL;
      
  info = NULL;
  
  if (cancellable)
    g_cancellable_push_current (cancellable);
  
  class = G_FILE_INPUT_STREAM_GET_CLASS (stream);
  if (class->query_info)
    info = class->query_info (stream, attributes, cancellable, error);
  else
    g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
                         _("Stream doesn't support query_info"));
开发者ID:MacIrssi,项目名称:MILibs,代码行数:31,代码来源:gfileinputstream.c


示例12: gtk_drag_get_source_widget

void MainWindow::dragDataRecived(GtkWidget * widget, GdkDragContext * dragContext, gint x, gint y,
		GtkSelectionData * data, guint info, guint time, MainWindow * win) {

	GtkWidget * source = gtk_drag_get_source_widget(dragContext);
	if (source && widget == gtk_widget_get_toplevel(source)) {
		gtk_drag_finish(dragContext, false, false, time);
		return;
	}

	guchar * text = gtk_selection_data_get_text(data);
	if (text) {
		win->control->clipboardPasteText((const char *) text);

		g_free(text);
		gtk_drag_finish(dragContext, true, false, time);
		return;
	}

	GdkPixbuf * image = gtk_selection_data_get_pixbuf(data);
	if (image) {
		win->control->clipboardPasteImage(image);

		gdk_pixbuf_unref(image);
		gtk_drag_finish(dragContext, true, false, time);
		return;
	}

	// TODO LOW PRIO: use x and y for insert location!

	gchar ** uris = gtk_selection_data_get_uris(data);
	if (uris) {
		for (int i = 0; uris[i] != NULL && i < 3; i++) {
			const char * uri = uris[i];

			// TODO LOW PRIO: check first if its an image
			//			GSList * imageFormats = gdk_pixbuf_get_formats();
			//			for(GSList * l = imageFormats; l != NULL; l = l->next) {
			//				GdkPixbufFormat * f = (GdkPixbufFormat *)l->data;
			//				printf("", f);
			//			}
			//
			//			g_slist_free(imageFormats);

			GFile * file = g_file_new_for_uri(uri);
			GError * err = NULL;
			GCancellable * cancel = g_cancellable_new();

			int cancelTimeout = g_timeout_add(3000, (GSourceFunc) cancellable_cancel, cancel);

			GFileInputStream * in = g_file_read(file, cancel, &err);

			if (g_cancellable_is_cancelled(cancel)) {
				continue;
			}

			g_object_unref(file);
			if (err == NULL) {
				GdkPixbuf * pixbuf = gdk_pixbuf_new_from_stream(G_INPUT_STREAM(in), cancel, NULL);
				if (g_cancellable_is_cancelled(cancel)) {
					continue;
				}
				g_input_stream_close(G_INPUT_STREAM(in), cancel, NULL);
				if (g_cancellable_is_cancelled(cancel)) {
					continue;
				}

				if (pixbuf) {
					win->control->clipboardPasteImage(pixbuf);

					gdk_pixbuf_unref(pixbuf);
				}
			} else {
				g_error_free(err);
			}

			if (!g_cancellable_is_cancelled(cancel)) {
				g_source_remove(cancelTimeout);
			}
			g_object_unref(cancel);

			//TODO LOW PRIO: handle .xoj, .pdf and Images
			printf("open uri: %s\n", uris[i]);
		}

		gtk_drag_finish(dragContext, true, false, time);

		g_strfreev(uris);
	}

	gtk_drag_finish(dragContext, false, false, time);
}
开发者ID:wbrenna,项目名称:xournalpp,代码行数:91,代码来源:MainWindow.cpp


示例13: on_input_stream_close_ready

static void on_input_stream_close_ready (GObject * object, GAsyncResult * res, gpointer data)
{
	GError * error = NULL;
	g_input_stream_close_finish (G_INPUT_STREAM(object), res, &error);
	handle_critical_error (error);
}
开发者ID:trhura,项目名称:rookie,代码行数:6,代码来源:gio-download.c


示例14: ensure_thumbnail_job

static gboolean
ensure_thumbnail_job (GIOSchedulerJob *job,
                      GCancellable *cancellable,
                      gpointer user_data)
{
    LoadThumbnailData *data = user_data;
    gboolean thumb_failed;
    const gchar *thumb_path;

    GError *error = NULL;
    GFile *thumb_file = NULL;
    GFileInputStream *is = NULL;
    GFileInfo *info = NULL;

    info = g_file_query_info (data->font_file,
                              ATTRIBUTES_FOR_EXISTING_THUMBNAIL,
                              G_FILE_QUERY_INFO_NONE,
                              NULL, &error);

    if (error != NULL) {
        g_debug ("Can't query info for file %s: %s\n", data->font_path, error->message);
        goto out;
    }

    thumb_failed = g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_THUMBNAILING_FAILED);
    if (thumb_failed)
        goto out;

    thumb_path = g_file_info_get_attribute_byte_string (info, G_FILE_ATTRIBUTE_THUMBNAIL_PATH);

    if (thumb_path != NULL) {
        thumb_file = g_file_new_for_path (thumb_path);
        is = g_file_read (thumb_file, NULL, &error);

        if (error != NULL) {
            g_debug ("Can't read file %s: %s\n", thumb_path, error->message);
            goto out;
        }

        data->pixbuf = gdk_pixbuf_new_from_stream_at_scale (G_INPUT_STREAM (is),
                                                            128, 128, TRUE,
                                                            NULL, &error);

        if (error != NULL) {
            g_debug ("Can't read thumbnail pixbuf %s: %s\n", thumb_path, error->message);
            goto out;
        }
    } else {
        data->pixbuf = create_thumbnail (data);
    }

 out:
    g_clear_error (&error);
    g_clear_object (&is);
    g_clear_object (&thumb_file);
    g_clear_object (&info);

    g_io_scheduler_job_send_to_mainloop_async (job, ensure_thumbnail_job_done,
                                               data, NULL);

    return FALSE;
}
开发者ID:rkmax,项目名称:gnome-font-viewer,代码行数:62,代码来源:font-model.c


示例15: gst_gio_base_src_create

static GstFlowReturn
gst_gio_base_src_create (GstBaseSrc * base_src, guint64 offset, guint size,
    GstBuffer ** buf_return)
{
  GstGioBaseSrc *src = GST_GIO_BASE_SRC (base_src);
  GstBuffer *buf;
  GstFlowReturn ret = GST_FLOW_OK;

  g_return_val_if_fail (G_IS_INPUT_STREAM (src->stream), GST_FLOW_ERROR);

  /* If we have the requested part in our cache take a subbuffer of that,
   * otherwise fill the cache again with at least 4096 bytes from the
   * requested offset and return a subbuffer of that.
   *
   * We need caching because every read/seek operation will need to go
   * over DBus if our backend is GVfs and this is painfully slow. */
  if (src->cache && offset >= GST_BUFFER_OFFSET (src->cache) &&
      offset + size <= GST_BUFFER_OFFSET_END (src->cache)) {
    GST_DEBUG_OBJECT (src, "Creating subbuffer from cached buffer: offset %"
        G_GUINT64_FORMAT " length %u", offset, size);

    buf = gst_buffer_copy_region (src->cache, GST_BUFFER_COPY_ALL,
        offset - GST_BUFFER_OFFSET (src->cache), size);

    GST_BUFFER_OFFSET (buf) = offset;
    GST_BUFFER_OFFSET_END (buf) = offset + size;
  } else {
    guint cachesize = MAX (4096, size);
    GstMapInfo map;
    gssize read, res;
    gboolean success, eos;
    GError *err = NULL;

    if (src->cache) {
      gst_buffer_unref (src->cache);
      src->cache = NULL;
    }

    if (G_UNLIKELY (offset != src->position)) {
      if (!GST_GIO_STREAM_IS_SEEKABLE (src->stream))
        return GST_FLOW_NOT_SUPPORTED;

      GST_DEBUG_OBJECT (src, "Seeking to position %" G_GUINT64_FORMAT, offset);
      ret = gst_gio_seek (src, G_SEEKABLE (src->stream), offset, src->cancel);

      if (ret == GST_FLOW_OK)
        src->position = offset;
      else
        return ret;
    }

    src->cache = gst_buffer_new_and_alloc (cachesize);
    if (G_UNLIKELY (src->cache == NULL)) {
      GST_ERROR_OBJECT (src, "Failed to allocate %u bytes", cachesize);
      return GST_FLOW_ERROR;
    }

    GST_LOG_OBJECT (src, "Reading %u bytes from offset %" G_GUINT64_FORMAT,
        cachesize, offset);

    /* GIO sometimes gives less bytes than requested although
     * it's not at the end of file. SMB for example only
     * supports reads up to 64k. So we loop here until we get at
     * at least the requested amount of bytes or a read returns
     * nothing. */
    gst_buffer_map (src->cache, &map, GST_MAP_WRITE);
    read = 0;
    while (size - read > 0 && (res =
            g_input_stream_read (G_INPUT_STREAM (src->stream),
                map.data + read, cachesize - read, src->cancel, &err)) > 0) {
      read += res;
    }
    gst_buffer_unmap (src->cache, &map);

    success = (read >= 0);
    eos = (cachesize > 0 && read == 0);

    if (!success && !gst_gio_error (src, "g_input_stream_read", &err, &ret)) {
      GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL),
          ("Could not read from stream: %s", err->message));
      g_clear_error (&err);
    }

    if (success && !eos) {
      src->position += read;

      GST_BUFFER_OFFSET (src->cache) = offset;
      GST_BUFFER_OFFSET_END (src->cache) = offset + read;

      GST_DEBUG_OBJECT (src, "Read successful");
      GST_DEBUG_OBJECT (src, "Creating subbuffer from new "
          "cached buffer: offset %" G_GUINT64_FORMAT " length %u", offset,
          size);

      buf =
          gst_buffer_copy_region (src->cache, GST_BUFFER_COPY_ALL, 0, MIN (size,
              read));

      GST_BUFFER_OFFSET (buf) = offset;
      GST_BUFFER_OFFSET_END (buf) = offset + MIN (size, read);
//.........这里部分代码省略.........
开发者ID:collects,项目名称:gst-plugins-base,代码行数:101,代码来源:gstgiobasesrc.c


示例16: avatar_chooser_drag_data_received_cb

static void
avatar_chooser_drag_data_received_cb (GtkWidget          *widget,
				     GdkDragContext     *context,
				     gint                x,
				     gint                y,
				     GtkSelectionData   *selection_data,
				     guint               info,
				     guint               time,
				     EmpathyAvatarChooser *chooser)
{
	gchar    *target_type;
	gboolean  handled = FALSE;

	target_type = gdk_atom_name (selection_data->target);
	if (!strcmp (target_type, URI_LIST_TYPE)) {
		GFile            *file;
		GFileInputStream *input_stream;
		gchar            *nl;
		gchar            *data = NULL;

		nl = strstr (selection_data->data, "\r\n");
		if (nl) {
			gchar *uri;

			uri = g_strndup (selection_data->data,
					 nl - (gchar *) selection_data->data);

			file = g_file_new_for_uri (uri);
			g_free (uri);
		} else {
			file = g_file_new_for_uri (selection_data->data);
		}

		input_stream = g_file_read (file, NULL, NULL);

		if (input_stream != NULL) {
			GFileInfo *info;

			info = g_file_query_info (file,
						  G_FILE_ATTRIBUTE_STANDARD_SIZE,
						  0, NULL, NULL);
			if (info != NULL) {
				goffset size;
				gssize bytes_read;

				size = g_file_info_get_size (info);
				data = g_malloc (size);

				bytes_read = g_input_stream_read (G_INPUT_STREAM (input_stream),
								  data, size,
								  NULL, NULL);
				if (bytes_read != -1) {
					avatar_chooser_set_image_from_data (
						chooser, data,
						(gsize) bytes_read,
						TRUE);
					handled = TRUE;
				}

				g_free (data);
				g_object_unref (info);
			}

			g_object_unref (input_stream);
		}

		g_object_unref (file);
	}

	gtk_drag_finish (context, handled, FALSE, time);
}
开发者ID:kenvandine,项目名称:empathy,代码行数:71,代码来源:empathy-avatar-chooser.c


示例17: check_bundle

gboolean check_bundle(const gchar *bundlename, gsize *size, gboolean verify, GError **error) {
	GError *ierror = NULL;
	GBytes *sig = NULL;
	GFile *bundlefile = NULL;
	GFileInputStream *bundlestream = NULL;
	guint64 sigsize;
	goffset offset;
	gboolean res = FALSE;

	r_context_begin_step("check_bundle", "Checking bundle", verify);

	if (!r_context()->config->keyring_path) {
		g_set_error(error, G_FILE_ERROR, G_FILE_ERROR_EXIST, "No keyring file provided");
		goto out;
	}

	g_message("Reading bundle: %s", bundlename);

	bundlefile = g_file_new_for_path(bundlename);
	bundlestream = g_file_read(bundlefile, NULL, &ierror);
	if (bundlestream == NULL) {
		g_propagate_prefixed_error(
				error,
				ierror,
				"failed to open bundle for reading: ");
		goto out;
	}

	offset = sizeof(sigsize);
	res = g_seekable_seek(G_SEEKABLE(bundlestream),
			      -offset, G_SEEK_END, NULL, &ierror);
	if (!res) {
		g_propagate_prefixed_error(
				error,
				ierror,
				"failed to seek to end of bundle: ");
		goto out;
	}
	offset = g_seekable_tell((GSeekable *)bundlestream);

	res = input_stream_read_uint64_all(G_INPUT_STREAM(bundlestream),
			                   &sigsize, NULL, &ierror);
	if (!res) {
		g_propagate_prefixed_error(
				error,
				ierror,
				"failed to read signature size from bundle: ");
		goto out;
	}

	offset -= sigsize;

	if (size)
		*size = offset;

	res = g_seekable_seek(G_SEEKABLE(bundlestream),
			      offset, G_SEEK_SET, NULL, &ierror);
	if (!res) {
		g_propagate_prefixed_error(
				error,
				ierror,
				"failed to seek to start of bundle signature: ");
		goto out;
	}

	res = input_stream_read_bytes_all(G_INPUT_STREAM(bundlestream),
			                  &sig, sigsize, NULL, &ierror);
	if (!res) {
		g_propagate 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ G_IO_STREAM函数代码示例发布时间:2022-05-30
下一篇:
C++ G_INITIALIZE函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap