您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ G_INPUT_STREAM函数代码示例

51自学网 2021-06-01 21:01:19
  C++
这篇教程C++ G_INPUT_STREAM函数代码示例写得很实用,希望能帮到您。

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

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

示例1: checksum_file_list_parse_checksum_file

gintchecksum_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,


示例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 */nsresultnsGIOInputStream::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,


示例3: scrollback_load

voidscrollback_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,


示例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,


示例5: xmms_gvfs_init

static gbooleanxmms_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,


示例6: render_card_init

static voidrender_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,


示例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,


示例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*/gbooleaninfo_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,


示例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,


示例10: web_handler

static voidweb_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,


示例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,


示例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,


示例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,


示例14: ensure_thumbnail_job

static gbooleanensure_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,


示例15: gst_gio_base_src_create

static GstFlowReturngst_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,


示例16: avatar_chooser_drag_data_received_cb

static voidavatar_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,


示例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_prefixed_error(				error,				ierror,				"failed to read signature from bundle: ");		goto out;	}	if (verify) {		g_message("Verifying bundle... ");		/* the squashfs image size is in offset */		res = cms_verify_file(bundlename, sig, offset, &ierror);		if (!res) {			g_propagate_error(error, ierror);			goto out;		}	}	res = TRUE;out:	g_clear_object(&bundlestream);	g_clear_object(&bundlefile);	g_clear_pointer(&sig, g_bytes_unref);	r_context_end_step("check_bundle", res);	return res;}
开发者ID:gavinschenk,项目名称:rauc,代码行数:93,


示例18: file_read_callback

static voidfile_read_callback (GObject      *object,		    GAsyncResult *res,		    gpointer      data){	NemoImagePropertiesPage *page;	GInputStream *stream;	gssize count_read;	GError *error;	int exif_still_loading;	gboolean done_reading;	page = NEMO_IMAGE_PROPERTIES_PAGE (data);	stream = G_INPUT_STREAM (object);	error = NULL;	done_reading = FALSE;	count_read = g_input_stream_read_finish (stream, res, &error);	if (count_read > 0) {		g_assert (count_read <= sizeof(page->details->buffer));#ifdef HAVE_EXIF		exif_still_loading = exif_loader_write (page->details->exifldr,				  		        page->details->buffer,				  			count_read);#else		exif_still_loading = 0;#endif		if (page->details->pixbuf_still_loading) {			if (!gdk_pixbuf_loader_write (page->details->loader,					      	      page->details->buffer,					      	      count_read,					      	      NULL)) {				page->details->pixbuf_still_loading = FALSE;			}		}		if (page->details->pixbuf_still_loading ||		    (exif_still_loading == 1)) {			g_input_stream_read_async (G_INPUT_STREAM (stream),						   page->details->buffer,						   sizeof (page->details->buffer),						   0,						   page->details->cancellable,						   file_read_callback,						   page);		}		else {			done_reading = TRUE;		}	}	else {		/* either EOF, cancelled or an error occurred */		done_reading = TRUE;	}	if (done_reading) {		load_finished (page);		g_input_stream_close_async (stream,					    0,					    page->details->cancellable,					    file_close_callback,					    page);	}}
开发者ID:ebbes,项目名称:nemo,代码行数:68,


示例19: ipset_node_cache_load

ipset_node_id_tipset_node_cache_load(GInputStream *stream,                      ipset_node_cache_t *cache,                      GError **err){    g_return_val_if_fail(err == NULL || *err == NULL, FALSE);    ipset_node_id_t  result;    gsize bytes_read;    /*     * Create a GDataInputStream to read in the binary data.     */    GDataInputStream  *dstream = g_data_input_stream_new(stream);    g_data_input_stream_set_byte_order        (dstream, G_DATA_STREAM_BYTE_ORDER_BIG_ENDIAN);    /*     * First, read in the magic number from the stream to ensure that     * this is an IP set.     */    guint8  magic[MAGIC_NUMBER_LENGTH];    g_debug("Reading IP set magic number");    TRY_OR_RETURN(0,                  g_input_stream_read_all,                  G_INPUT_STREAM(dstream),                  magic, MAGIC_NUMBER_LENGTH,                  &bytes_read, NULL);    if (bytes_read != MAGIC_NUMBER_LENGTH)    {        /*         * We reached EOF before reading the entire magic number.         */        g_set_error(err,                    IPSET_ERROR,                    IPSET_ERROR_PARSE_ERROR,                    "Unexpected end of file");        return 0;    }    if (memcmp(magic, MAGIC_NUMBER, MAGIC_NUMBER_LENGTH) != 0)    {        /*         * The magic number doesn't match, so this isn't a BDD.         */        g_set_error(err,                    IPSET_ERROR,                    IPSET_ERROR_PARSE_ERROR,                    "Magic number doesn't match; "                    "this isn't an IP set.");        return 0;    }    /*     * Read in the version number and dispatch to the right reading     * function.     */    guint16  version;    g_debug("Reading IP set version");    TRY_OR_RETURN(0,                  version = g_data_input_stream_read_uint16,                  dstream, NULL);    switch (version)    {      case 0x0001:        TRY_OR_RETURN(0,                      result = load_v1,                      dstream, cache);        return result;      default:        /*         * We don't know how to read this version number.         */        g_set_error(err,                    IPSET_ERROR,                    IPSET_ERROR_PARSE_ERROR,                    "Unknown version number %" G_GUINT16_FORMAT,                    version);        return 0;    }  error:    /*     * If there's an error, clean up the objects that we've created     * before returning.     */    if (dstream != NULL)        g_object_unref(dstream);//.........这里部分代码省略.........
开发者ID:janies,项目名称:ipset,代码行数:101,


示例20: tmp_picasaweb_upload_async

/** * tmp_picasaweb_upload_async: * * Temporary solution to provide asynchronous uploading and stop * blocking the UI until gdata_picasaweb_service_upload_file_async() * becomes available (bgo #600262).  This method does the synchronous * file upload, but is run asynchronously via * g_simple_async_result_run_in_thread(). * * This sets up a minimal #GDataPicasaWebFile entry, using the * basename of the filepath for the file's title (which is not the * caption, but might be something we would consider doing).  The * image file and the minimal entry are then uploaded to PicasaWeb's * default album of "Drop Box".  In the future, we might consider * adding an Album Chooser to the Preferences/login window, but only * if there's demand. **/static voidtmp_picasaweb_upload_async (GSimpleAsyncResult *result, GObject *source_object, GCancellable *cancellable){	GDataPicasaWebFile *new_file = NULL;	XviewerPostasaPlugin *plugin = XVIEWER_POSTASA_PLUGIN (source_object);	GDataPicasaWebService *service = plugin->priv->service;	GDataPicasaWebFile *file_entry;	PicasaWebUploadFileAsyncData *data;#ifdef HAVE_LIBGDATA_0_8	GDataUploadStream *upload_stream;	GFileInputStream *in_stream;	GFileInfo *file_info;#endif	gchar *filename;	GError *error = NULL;	data = (PicasaWebUploadFileAsyncData*)g_async_result_get_user_data (G_ASYNC_RESULT (result));	/* get filename to set image title */	file_entry = gdata_picasaweb_file_new (NULL);	filename = g_file_get_basename (data->imgfile);	gdata_entry_set_title (GDATA_ENTRY (file_entry), filename);	g_free (filename);#ifdef HAVE_LIBGDATA_0_8	file_info = g_file_query_info (data->imgfile,				      G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME ","				      G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,				      G_FILE_QUERY_INFO_NONE, cancellable,				      &error);	if (file_info == NULL)		goto got_err;	upload_stream = gdata_picasaweb_service_upload_file (service,				      NULL /* Upload to Dropbox */, file_entry,				      g_file_info_get_display_name (file_info),				      g_file_info_get_content_type (file_info),				      cancellable, &error);	g_object_unref (file_info);	if (upload_stream == NULL)		goto got_err;	in_stream = g_file_read (data->imgfile, cancellable, &error);	if (in_stream == NULL) {		g_object_unref (upload_stream);		goto got_err;	}	if (g_output_stream_splice (G_OUTPUT_STREAM (upload_stream),				    G_INPUT_STREAM (in_stream),				    G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE |				    G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET,				    cancellable, &error) == -1)	{		g_object_unref (upload_stream);		g_object_unref (in_stream);		goto got_err;	}	new_file = gdata_picasaweb_service_finish_file_upload (service,							       upload_stream,							       &error);	g_object_unref (upload_stream);	g_object_unref (in_stream);got_err:	/* Jump here if any GIO/GData call doesn't return successfully.	 * Error handling happens below. */#else	/* libgdata-0.6 */	new_file = gdata_picasaweb_service_upload_file (service,					       NULL /* Uploading to Drop Box */,					       file_entry, data->imgfile,					       cancellable, &error);#endif	g_object_unref (file_entry);	if (new_file == NULL || error) {//.........这里部分代码省略.........
开发者ID:linuxmint,项目名称:xviewer-plugins,代码行数:101,


示例21: www_closeStream_cb

inline static voidwww_closeStream_cb (GObject *source_object, GAsyncResult *res, gpointer user_data){    g_input_stream_close_finish (G_INPUT_STREAM (source_object), res, NULL);    g_object_unref (G_INPUT_STREAM (source_object));}
开发者ID:gallochri,项目名称:gnome-arcade,代码行数:6,


示例22: image_drag_data_received_cb

static voidimage_drag_data_received_cb (GtkWidget *widget,			     GdkDragContext *context,			     gint x, gint y,			     GtkSelectionData *selection_data,			     guint info, guint time, EImageChooser *chooser){	char *target_type;	gboolean handled = FALSE;	target_type = gdk_atom_name (gtk_selection_data_get_target (selection_data));	if (!strcmp (target_type, URI_LIST_TYPE)) {		const char *data = gtk_selection_data_get_data (selection_data);		char *uri;		GFile *file;		GInputStream *istream;		char *nl = strstr (data, "/r/n");		if (nl)			uri = g_strndup (data, nl - (char *) data);		else			uri = g_strdup (data);		file = g_file_new_for_uri (uri);		istream = G_INPUT_STREAM (g_file_read (file, NULL, NULL));		if (istream != NULL) {			GFileInfo *info;			info = g_file_query_info (file,						  G_FILE_ATTRIBUTE_STANDARD_SIZE,						  G_FILE_QUERY_INFO_NONE,						  NULL, NULL);			if (info != NULL) {				gsize size;				gboolean success;				gchar *buf;				size = g_file_info_get_size (info);				g_object_unref (info);				buf = g_malloc (size);				success = g_input_stream_read_all (istream,								   buf,								   size,								   &size,								   NULL,								   NULL);				g_input_stream_close (istream, NULL, NULL);				if (success &&						set_image_from_data (chooser, buf, size))					handled = TRUE;				else					g_free (buf);			}			g_object_unref (istream);		}		g_object_unref (file);		g_free (uri);	}	gtk_drag_finish (context, handled, FALSE, time);}
开发者ID:TheCoffeMaker,项目名称:Mate-Desktop-Environment,代码行数:69,


示例23: pk_backend_config_parse

static gbooleanpk_backend_config_parse (PkBackendConfig *config, const gchar *filename,			 PkBackendConfigSection *section, GError **error){	GFile *file;	GFileInputStream *is;	GDataInputStream *input;	gchar *key, *str, *line = NULL;	guint num = 1;	GError *e = NULL;	g_return_val_if_fail (config != NULL, FALSE);	g_return_val_if_fail (filename != NULL, FALSE);	file = g_file_new_for_path (filename);	is = g_file_read (file, NULL, &e);	if (is == NULL) {		g_propagate_error (error, e);		g_object_unref (file);		return FALSE;	}	input = g_data_input_stream_new (G_INPUT_STREAM (is));	for (;; g_free (line), ++num) {		line = g_data_input_stream_read_line (input, NULL, NULL, &e);		if (line != NULL) {			g_strstrip (line);		} else {			break;		}		/* skip empty lines */		if (*line == '/0' || *line == '#') {			continue;		}		/* remove trailing comments */		for (str = line; *str != '/0' && *str != '#'; ++str);		*str-- = '/0';		/* change sections */		if (*line == '[' && *str == ']') {			*str = '/0';			str = line + 1;			if (*str == '/0') {				g_set_error (&e, ALPM_ERROR,					     ALPM_ERR_CONFIG_INVALID,					     "empty section name");				break;			}			section = pk_backend_config_enter_section (config, str);			continue;		}		/* parse a directive */		if (section == NULL) {			g_set_error (&e, ALPM_ERROR, ALPM_ERR_CONFIG_INVALID,				     "directive must belong to a section");			break;		}		str = line;		key = strsep (&str, "=");		g_strchomp (key);		if (str != NULL) {			g_strchug (str);		}		if (str == NULL) {			/* set a boolean directive */			if (pk_backend_config_section_match (section,							     "options") == 0 &&			    pk_backend_config_set_boolean (config, key)) {				continue;			}			/* report error below */		} else if (g_strcmp0 (key, "Include") == 0) {			gsize i;			glob_t match = { 0 };			/* ignore globbing errors */			if (glob (str, GLOB_NOCHECK, NULL, &match) != 0) {				continue;			}			/* parse the files that matched */			for (i = 0; i < match.gl_pathc; ++i) {				if (!pk_backend_config_parse (config,							      match.gl_pathv[i],							      section, &e)) {					break;				}			}//.........这里部分代码省略.........
开发者ID:AOSC-Dev,项目名称:PackageKit,代码行数:101,


示例24: gimp_help_locale_parse

gbooleangimp_help_locale_parse (GimpHelpLocale    *locale,                        const gchar       *uri,                        const gchar       *help_domain,                        GimpHelpProgress  *progress,                        GError           **error){  GMarkupParseContext *context;  GFile               *file;  GFileInputStream    *stream;  GCancellable        *cancellable = NULL;  LocaleParser         parser      = { NULL, };  goffset              size        = 0;  gboolean             success;  g_return_val_if_fail (locale != NULL, FALSE);  g_return_val_if_fail (uri != NULL, FALSE);  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);  if (locale->help_id_mapping)    {      g_hash_table_destroy (locale->help_id_mapping);      locale->help_id_mapping = NULL;    }  if (locale->help_missing)    {      g_free (locale->help_missing);      locale->help_missing = NULL;    }#ifdef GIMP_HELP_DEBUG  g_printerr ("help (%s): parsing '%s' for /"%s/"/n",              locale->locale_id, uri, help_domain);#endif  file = g_file_new_for_uri (uri);  if (progress)    {      gchar *name = g_file_get_parse_name (file);      cancellable = g_cancellable_new ();      _gimp_help_progress_start (progress, cancellable,                                 _("Loading index from '%s'"), name);      g_object_unref (cancellable);      g_free (name);    }  if (progress)    {      GFileInfo *info = g_file_query_info (file,                                           G_FILE_ATTRIBUTE_STANDARD_SIZE, 0,                                           cancellable, error);      if (! info)        {          locale_set_error (error,                            _("Could not open '%s' for reading: %s"), file);          g_object_unref (file);          return FALSE;        }      size = g_file_info_get_size (info);      g_object_unref (info);    }  stream = g_file_read (file, cancellable, error);  if (! stream)    {      locale_set_error (error,                        _("Could not open '%s' for reading: %s"), file);      g_object_unref (file);      return FALSE;    }  parser.file         = file;  parser.value        = g_string_new (NULL);  parser.locale       = locale;  parser.help_domain  = help_domain;  parser.id_attr_name = g_strdup ("id");  context = g_markup_parse_context_new (&markup_parser, 0, &parser, NULL);  success = locale_parser_parse (context, progress,                                 G_INPUT_STREAM (stream), size,                                 cancellable, error);  if (progress)    _gimp_help_progress_finish (progress);  g_markup_parse_context_free (context);  g_object_unref (stream);  g_string_free (parser.value, TRUE);  g_free (parser.id_attr_name);//.........这里部分代码省略.........
开发者ID:jiapei100,项目名称:gimp,代码行数:101,


示例25: main

intmain (int argc, char **argv){  GOptionContext* context;  GError *error = NULL;  GFile *infile;  GFile *outfile;  GInputStream *instream;  GOutputStream *outstream;  GMainLoop *loop;  ByzanzEncoder *encoder;    g_set_prgname (argv[0]);#ifdef GETTEXT_PACKAGE  bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");  textdomain (GETTEXT_PACKAGE);#endif  context = g_option_context_new (_("process a Byzanz debug recording"));#ifdef GETTEXT_PACKAGE  g_option_context_set_translation_domain(context, GETTEXT_PACKAGE);#endif  g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);  if (!g_option_context_parse (context, &argc, &argv, &error)) {    g_print (_("Wrong option: %s/n"), error->message);    usage ();    g_error_free (error);    return 1;  }  if (argc != 3) {    usage ();    return 0;  }  infile = g_file_new_for_commandline_arg (argv[1]);  outfile = g_file_new_for_commandline_arg (argv[2]);  loop = g_main_loop_new (NULL, FALSE);  instream = G_INPUT_STREAM (g_file_read (infile, NULL, &error));  if (instream == NULL) {    g_print ("%s/n", error->message);    g_error_free (error);    return 1;  }  outstream = G_OUTPUT_STREAM (g_file_replace (outfile, NULL,         FALSE, G_FILE_CREATE_REPLACE_DESTINATION, NULL, &error));  if (outstream == NULL) {    g_print ("%s/n", error->message);    g_error_free (error);    return 1;  }  encoder = byzanz_encoder_new (byzanz_encoder_get_type_from_file (outfile),      instream, outstream, FALSE, NULL);    g_signal_connect (encoder, "notify", G_CALLBACK (encoder_notify), loop);    g_main_loop_run (loop);  g_main_loop_unref (loop);  g_object_unref (encoder);  g_object_unref (instream);  g_object_unref (outstream);  g_object_unref (infile);  g_object_unref (outfile);  return 0;}
开发者ID:npnth,项目名称:bysans,代码行数:69,


示例26: decrypt_file

voiddecrypt_file (const gchar *input_file_path, const gchar *pwd){    GError *err = NULL;    goffset file_size = get_file_size (input_file_path);    if (file_size == -1) {        return;    }    if (file_size < (goffset) (sizeof (Metadata) + SHA512_DIGEST_SIZE)) {        g_printerr ("The selected file is not encrypted./n");        return;    }    GFile *in_file = g_file_new_for_path (input_file_path);    GFileInputStream *in_stream = g_file_read (in_file, NULL, &err);    if (err != NULL) {        g_printerr ("%s/n", err->message);        // TODO        return;    }    gchar *output_file_path;    if (!g_str_has_suffix (input_file_path, ".enc")) {        g_printerr ("The selected file may not be encrypted/n");        output_file_path = g_strconcat (input_file_path, ".decrypted", NULL);    }    else {        output_file_path = g_strndup (input_file_path, (gsize) g_utf8_strlen (input_file_path, -1) - 4); // remove .enc    }    GFile *out_file = g_file_new_for_path (output_file_path);    GFileOutputStream *out_stream = g_file_append_to (out_file, G_FILE_CREATE_REPLACE_DESTINATION, NULL, &err);    if (err != NULL) {        g_printerr ("%s/n", err->message);        // TODO        return;    }    Metadata *header_metadata = g_new0 (Metadata, 1);    CryptoKeys *decryption_keys = g_new0 (CryptoKeys, 1);    gssize rw_len = g_input_stream_read (G_INPUT_STREAM (in_stream), header_metadata, sizeof (Metadata), NULL, &err);    if (rw_len == -1) {        g_printerr ("%s/n", err->message);        // TODO        return;    }    guchar *original_hmac = g_malloc (SHA512_DIGEST_SIZE);    if (!g_seekable_seek (G_SEEKABLE (in_stream), file_size - SHA512_DIGEST_SIZE, G_SEEK_SET, NULL, &err)) {        g_printerr ("Couldn't set the position, exiting.../n");        //TODO        return;    }    rw_len = g_input_stream_read (G_INPUT_STREAM (in_stream), original_hmac, SHA512_DIGEST_SIZE, NULL, &err);    if (rw_len == -1) {        g_printerr ("%s/n", err->message);        // TODO        return;    }    if (!g_seekable_seek (G_SEEKABLE (in_stream), 0, G_SEEK_SET, NULL, &err)) {        g_printerr ("Couldn't set the position, exiting.../n");        //TODO        return;    }    GFile *file_encrypted_data = get_g_file_with_encrypted_data (in_stream, file_size);    if (file_encrypted_data == NULL) {        // TODO        return;    }    if (!setup_keys (pwd, gcry_cipher_get_algo_keylen (header_metadata->algo), header_metadata, decryption_keys)) {        g_printerr ("Error during key derivation or during memory allocation/n");        //TODO        return;    }    if (!compare_hmac (decryption_keys->hmac_key, original_hmac, file_encrypted_data)) {        g_printerr ("HMAC differs from the one stored inside the file./nEither the password is wrong or the file has been corrupted./n");        // TODO        return;    }    decrypt (header_metadata, decryption_keys, file_encrypted_data, file_size - sizeof (Metadata) - SHA512_DIGEST_SIZE, out_stream);    g_unlink (g_file_get_path (file_encrypted_data));    // TODO remove encrypted file? Give option to the user    multiple_unref (5, (gpointer) &file_encrypted_data,                    (gpointer) &in_stream,                    (gpointer) &out_stream,                    (gpointer) &in_file,                    (gpointer) &out_file);    multiple_gcry_free (3, (gpointer) &decryption_keys->crypto_key,                        (gpointer) &decryption_keys->derived_key,                        (gpointer) &decryption_keys->hmac_key);    multiple_free (4, (gpointer) &header_metadata,//.........这里部分代码省略.........
开发者ID:paolostivanin,项目名称:GTKCrypto,代码行数:101,


示例27: Ogg_Header_Read_File_Info

gbooleanOgg_Header_Read_File_Info (const gchar *filename, ET_File_Info *ETFileInfo){    OggVorbis_File vf;    vorbis_info *vi;    gint encoder_version = 0;    gint channels = 0;    glong rate = 0;    glong bitrate_nominal = 0;    gdouble duration = 0;    gulong filesize;    gint res;    ov_callbacks callbacks = { et_ogg_read_func, et_ogg_seek_func,                               et_ogg_close_func, et_ogg_tell_func };    EtOggState state;    gchar *filename_utf8;    g_return_val_if_fail (filename != NULL && ETFileInfo != NULL, FALSE);    state.file = g_file_new_for_path (filename);    state.error = NULL;    state.istream = G_INPUT_STREAM (g_file_read (state.file, NULL,                                                 &state.error));    filename_utf8 = filename_to_display (filename);    if (!state.istream)    {        /* FIXME: Pass error back to calling function. */        Log_Print (LOG_ERROR, _("Error while opening file: '%s' (%s)"),                   filename_utf8, state.error->message);        g_free (filename_utf8);        return FALSE;    }    if ((res = ov_open_callbacks (&state, &vf, NULL, 0, callbacks)) == 0)    {        if ( (vi=ov_info(&vf,0)) != NULL )        {            encoder_version = vi->version;         // Vorbis encoder version used to create this bitstream.            channels        = vi->channels;        // Number of channels in bitstream.            rate            = vi->rate;            // (Hz) Sampling rate of the bitstream.            bitrate_nominal = vi->bitrate_nominal; // (b/s) Specifies the average bitrate for a VBR bitstream.        }else        {            Log_Print(LOG_ERROR,_("Ogg Vorbis: The specified bitstream does not exist or the "                        "file has been initialized improperly (file: '%s')."),filename_utf8);        }        duration        = ov_time_total(&vf,-1); // (s) Total time.        //g_print("play time: %ld s/n",(long)ov_time_total(&vf,-1));        //g_print("serialnumber: %ld/n",(long)ov_serialnumber(&vf,-1));        //g_print("compressed length: %ld bytes/n",(long)(ov_raw_total(&vf,-1)));        /***{            // Test for displaying comments            vorbis_comment *vc = ov_comment(&vf,-1);            Log_Print(LOG_OK,">>> %s",filename_utf8);            Log_Print(LOG_OK,"Nbr comments : %d",vc->comments);            Log_Print(LOG_OK,"Vendor : %s",vc->vendor);            char **ptr = vc->user_comments;            while(*ptr){              Log_Print(LOG_OK,"> %s",*ptr);              ++ptr;            }        }***/        ov_clear(&vf); // This close also the file    }else    {        /* On error. */        if (state.error)        {            g_debug ("Ogg Vorbis: error reading header information (%s)",                     state.error->message);        }        et_ogg_close_func (&state);        switch (res)        {            case OV_EREAD:                Log_Print(LOG_ERROR,_("Ogg Vorbis: Read from media returned an error (file: '%s')."),filename_utf8);                break;            case OV_ENOTVORBIS:                Log_Print(LOG_ERROR,_("Ogg Vorbis: Bitstream is not Vorbis data (file: '%s')."),filename_utf8);                break;            case OV_EVERSION:                Log_Print(LOG_ERROR,_("Ogg Vorbis: Vorbis version mismatch (file: '%s')."),filename_utf8);                break;            case OV_EBADHEADER:                Log_Print(LOG_ERROR,_("Ogg Vorbis: Invalid Vorbis bitstream header (file: '%s')."),filename_utf8);                break;            case OV_EFAULT:                Log_Print(LOG_ERROR,_("Ogg Vorbis: Internal logic fault, indicates a bug or heap/stack corruption (file: '%s')."),filename_utf8);                break;            default:                break;        }    }//.........这里部分代码省略.........
开发者ID:imclab,项目名称:easytag-mac,代码行数:101,



注:本文中的G_INPUT_STREAM函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


C++ G_IO_STREAM函数代码示例
C++ G_INITIALIZE函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。