Example #1
0
struct mwServicePlace *
mwServicePlace_new(struct mwSession *session,
		   struct mwPlaceHandler *handler) {

  struct mwServicePlace *srvc_place;
  struct mwService *srvc;

  g_return_val_if_fail(session != NULL, NULL);
  g_return_val_if_fail(handler != NULL, NULL);

  srvc_place = g_new0(struct mwServicePlace, 1);
  srvc_place->handler = handler;

  srvc = MW_SERVICE(srvc_place);
  mwService_init(srvc, session, mwService_PLACE);
  srvc->start = NULL;
  srvc->stop = (mwService_funcStop) stop;
  srvc->recv_create = NULL;
  srvc->recv_accept = recv_channelAccept;
  srvc->recv_destroy = recv_channelDestroy;
  srvc->recv = recv;
  srvc->clear = (mwService_funcClear) clear;
  srvc->get_name = get_name;
  srvc->get_desc = get_desc;

  return srvc_place;
}
Example #2
0
/**
 * cr_input_consume_chars:
 *@a_this: the this pointer of the current instance of #CRInput.
 *@a_char: the character to consume.
 *@a_nb_char: in/out parameter. The number of characters to consume.
 *If set to a negative value, the function will consume all the occurences
 *of a_char found.
 *After return, if the return value equals CR_OK, this variable contains 
 *the number of characters actually consumed.
 *
 *Consumes up to a_nb_char occurences of the next contiguous characters 
 *which equal a_char. Note that the next character of the input stream
 **MUST* equal a_char to trigger the consumption, or else, the error
 *code CR_PARSING_ERROR is returned.
 *If the number of contiguous characters that equals a_char is less than
 *a_nb_char, then this function consumes all the characters it can consume.
 * 
 *Returns CR_OK if at least one character has been consumed, an error code
 *otherwise.
 */
enum CRStatus
cr_input_consume_chars (CRInput * a_this, guint32 a_char, gulong * a_nb_char)
{
        enum CRStatus status = CR_OK;
        gulong nb_consumed = 0;

        g_return_val_if_fail (a_this && PRIVATE (a_this) && a_nb_char,
                              CR_BAD_PARAM_ERROR);

        g_return_val_if_fail (a_char != 0 || a_nb_char != NULL,
                              CR_BAD_PARAM_ERROR);

        for (nb_consumed = 0; ((status == CR_OK)
                               && (*a_nb_char > 0
                                   && nb_consumed < *a_nb_char));
             nb_consumed++) {
                status = cr_input_consume_char (a_this, a_char);
        }

        *a_nb_char = nb_consumed;

        if ((nb_consumed > 0)
            && ((status == CR_PARSING_ERROR)
                || (status == CR_END_OF_INPUT_ERROR))) {
                status = CR_OK;
        }

        return status;
}
Example #3
0
GObject *
peas_extension_gjs_new (GType      exten_type,
                        GType     *interfaces,
                        JSContext *js_context,
                        JSObject  *js_object)
{
  PeasExtensionGjs *gexten;
  GType real_type;

  g_return_val_if_fail (js_context != NULL, NULL);
  g_return_val_if_fail (js_object != NULL, NULL);

  real_type = peas_extension_register_subclass (PEAS_TYPE_EXTENSION_GJS,
                                                interfaces);

  /* Already Warned */
  if (real_type == G_TYPE_INVALID)
    {
      g_free (interfaces);
      return NULL;
    }

  gexten = PEAS_EXTENSION_GJS (g_object_new (real_type, NULL));

  gexten->js_context = js_context;
  gexten->js_object = js_object;
  PEAS_EXTENSION_WRAPPER (gexten)->exten_type = exten_type;
  PEAS_EXTENSION_WRAPPER (gexten)->interfaces = interfaces;
  JS_AddObjectRoot (gexten->js_context, &gexten->js_object);

  return G_OBJECT (gexten);
}
Example #4
0
static gboolean
test_text_attr (void)
{
    AtkTextAttribute attr1, attr2;
    G_CONST_RETURN gchar *name;

    name = atk_text_attribute_get_name (ATK_TEXT_ATTR_PIXELS_INSIDE_WRAP);
    g_return_val_if_fail (name, FALSE);
    if (strcmp (name, "pixels-inside-wrap") != 0)
    {
        g_print ("Unexpected name for ATK_TEXT_ATTR_PIXELS_INSIDE_WRAP %s\n", name);
        return FALSE;
    }

    name = atk_text_attribute_get_name (ATK_TEXT_ATTR_BG_STIPPLE);
    g_return_val_if_fail (name, FALSE);
    if (strcmp (name, "bg-stipple") != 0)
    {
        g_print ("Unexpected name for ATK_TEXT_ATTR_BG_STIPPLE %s\n", name);
        return FALSE;
    }

    attr1 = atk_text_attribute_for_name ("left-margin");
    if (attr1 != ATK_TEXT_ATTR_LEFT_MARGIN)
    {
        g_print ("Unexpected attribute for left-margin\n");
        return FALSE;
    }

    attr1 = atk_text_attribute_register ("test-attribute");
    name = atk_text_attribute_get_name (attr1);
    g_return_val_if_fail (name, FALSE);
    if (strcmp (name, "test-attribute") != 0)
    {
        g_print ("Unexpected name for test-attribute %s\n", name);
        return FALSE;
    }
    attr2 = atk_text_attribute_for_name ("test-attribute");
    if (attr1 != attr2)
    {
        g_print ("Unexpected attribute for test-attribute\n");
        return FALSE;
    }
    attr2 = atk_text_attribute_for_name ("TEST_ATTR");
    if (attr2 != 0)
    {
        g_print ("Unexpected attribute for TEST_ATTR\n");
        return FALSE;
    }
    /*
     * Check that a non-existent attribute returns NULL
     */
    name = atk_text_attribute_get_name (ATK_TEXT_ATTR_LAST_DEFINED + 2);
    if (name)
    {
        g_print ("Unexpected name for undefined attribute %s\n", name);
        return FALSE;
    }
    return TRUE;
}
Example #5
0
GFile *
file_remote_upload_image_prepare (Gimp          *gimp,
                                  GFile         *file,
                                  gboolean      *mounted,
                                  GimpProgress  *progress,
                                  GError       **error)
{
  GFile *local_file;

  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
  g_return_val_if_fail (G_IS_FILE (file), NULL);
  g_return_val_if_fail (mounted != NULL, NULL);
  g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), NULL);
  g_return_val_if_fail (error == NULL || *error == NULL, NULL);

  local_file = file_remote_mount_file (gimp, file, progress);

  if (local_file)
    {
      *mounted = TRUE;
    }
  else
    {
      *mounted = FALSE;

      local_file = file_remote_get_temp_file (gimp, file);
    }

  return local_file;
}
Example #6
0
/**
 * ggit_reflog_append:
 * @reflog: a #GgitReflog.
 * @oid: a #GgitOId.
 * @committer: a #GgitSignature.
 * @message: the message.
 * @error: a #GError for error reporting, or %NULL.
 *
 * Creates a reflog entry.
 *
 * Returns: %TRUE if the reflog was successfully created, or %FALSE if error is set.
 */
gboolean
ggit_reflog_append (GgitReflog     *reflog,
                    GgitOId        *oid,
                    GgitSignature  *committer,
                    const gchar    *message,
                    GError        **error)
{
	gint ret;

	g_return_val_if_fail (reflog != NULL, FALSE);
	g_return_val_if_fail (oid != NULL, FALSE);
	g_return_val_if_fail (GGIT_IS_SIGNATURE (committer), FALSE);
	g_return_val_if_fail (message != NULL && *message != '\0', FALSE);
	g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

	ret = git_reflog_append (reflog->reflog,
	                         _ggit_oid_get_oid (oid),
	                         _ggit_native_get (committer),
	                         message);

	if (ret != GIT_OK)
	{
		_ggit_error_set (error, ret);
		return FALSE;
	}

	return TRUE;
}
Example #7
0
GnomeCanvasItem*
bst_canvas_source_new (GnomeCanvasGroup *group,
		       SfiProxy		 source)
{
  BstCanvasSource *csource;
  GnomeCanvasItem *item;

  g_return_val_if_fail (GNOME_IS_CANVAS_GROUP (group), NULL);
  g_return_val_if_fail (BSE_IS_SOURCE (source), NULL);

  item = gnome_canvas_item_new (group,
				BST_TYPE_CANVAS_SOURCE,
				NULL);
  csource = BST_CANVAS_SOURCE (item);
  csource->source = bse_item_use (source);
  bse_proxy_connect (csource->source,
		     "swapped_signal::release", gtk_object_destroy, csource,
		     "swapped_signal::io_changed", source_channels_changed, csource,
		     "swapped_signal::property-notify::uname", source_name_changed, csource,
		     "swapped_signal::property-notify::pos-x", source_pos_changed, csource,
		     "swapped_signal::property-notify::pos-y", source_pos_changed, csource,
		     "swapped_signal::icon-changed", source_icon_changed, csource,
		     NULL);

  canvas_source_set_position (csource);
  bst_canvas_source_build (csource);
  
  GNOME_CANVAS_NOTIFY (item);
  
  return item;
}
Example #8
0
/**
 * g_value_transform:
 * @src_value: Source value.
 * @dest_value: Target value.
 *
 * Tries to cast the contents of @src_value into a type appropriate
 * to store in @dest_value, e.g. to transform a %G_TYPE_INT value
 * into a %G_TYPE_FLOAT value. Performing transformations between
 * value types might incur precision lossage. Especially
 * transformations into strings might reveal seemingly arbitrary
 * results and shouldn't be relied upon for production code (such
 * as rcfile value or object property serialization).
 *
 * Returns: Whether a transformation rule was found and could be applied.
 *  Upon failing transformations, @dest_value is left untouched.
 */
gboolean
g_value_transform (const GValue *src_value,
                   GValue       *dest_value)
{
    GType dest_type;

    g_return_val_if_fail (G_IS_VALUE (src_value), FALSE);
    g_return_val_if_fail (G_IS_VALUE (dest_value), FALSE);

    dest_type = G_VALUE_TYPE (dest_value);
    if (g_value_type_compatible (G_VALUE_TYPE (src_value), dest_type))
    {
        g_value_copy (src_value, dest_value);

        return TRUE;
    }
    else
    {
        GValueTransform transform = transform_func_lookup (G_VALUE_TYPE (src_value), dest_type);

        if (transform)
        {
            g_value_unset (dest_value);

            /* setup and transform */
            value_meminit (dest_value, dest_type);
            transform (src_value, dest_value);

            return TRUE;
        }
    }
    return FALSE;
}
Example #9
0
/**
 * ggit_branch_move:
 * @branch: a #GgitBranch.
 * @new_branch_name: target name of the branch once the move is performed; this name is validated for consistency.
 * @flags: a #GgitCreateFlags.
 * @error: a #GError for error reporting, or %NULL.
 *
 * Moves/renames an existing branch reference.
 *
 * Returns: (transfer full): the new branch.
 **/
GgitBranch *
ggit_branch_move (GgitBranch       *branch,
                  const gchar      *new_branch_name,
                  GgitCreateFlags   flags,
                  GError          **error)
{
	git_reference *out;
	gboolean force;
	gint ret;

	g_return_val_if_fail (GGIT_IS_BRANCH (branch), NULL);
	g_return_val_if_fail (new_branch_name != NULL, NULL);
	g_return_val_if_fail (error == NULL || *error == NULL, NULL);

	force = flags & GGIT_CREATE_FORCE;

	ret = git_branch_move (&out,
	                       _ggit_native_get (branch),
	                       new_branch_name,
	                       force ? 1 : 0);

	if (ret != GIT_OK)
	{
		_ggit_error_set (error, ret);
		return NULL;
	}

	return _ggit_branch_wrap (out);
}
Example #10
0
/**
 * gst_adapter_take_list:
 * @adapter: a #GstAdapter
 * @nbytes: the number of bytes to take
 *
 * Returns a #GSList of buffers containing the first @nbytes bytes of the
 * @adapter. The returned bytes will be flushed from the adapter.
 * When the caller can deal with individual buffers, this function is more
 * performant because no memory should be coppied.
 *
 * Caller owns returned list and contained buffers. gst_buffer_unref() each
 * buffer in the list before freeng the list after usage.
 *
 * Returns: a #GSList of buffers containing the first @nbytes of the adapter,
 * or #NULL if @nbytes bytes are not available
 *
 * Since: 0.10.31
 */
GList *
gst_adapter_take_list (GstAdapter * adapter, guint nbytes)
{
    GList *result = NULL, *tail = NULL;
    GstBuffer *cur;
    guint hsize, skip;

    g_return_val_if_fail (GST_IS_ADAPTER (adapter), NULL);
    g_return_val_if_fail (nbytes <= adapter->size, NULL);

    GST_LOG_OBJECT (adapter, "taking %u bytes", nbytes);

    while (nbytes > 0) {
        cur = adapter->buflist->data;
        skip = adapter->skip;
        hsize = MIN (nbytes, GST_BUFFER_SIZE (cur) - skip);

        cur = gst_adapter_take_buffer (adapter, hsize);

        if (result == NULL) {
            result = tail = g_list_append (result, cur);
        } else {
            tail = g_list_append (tail, cur);
            tail = g_list_next (tail);
        }
        nbytes -= hsize;
    }
    return result;
}
gboolean
nm_vpn_manager_deactivate_connection (NMVPNManager *self,
                                      const char *path,
                                      NMVPNConnectionStateReason reason)
{
	NMVPNManagerPrivate *priv;
	GHashTableIter iter;
	gpointer data;
	GSList *active, *elt;

	g_return_val_if_fail (self, FALSE);
	g_return_val_if_fail (NM_IS_VPN_MANAGER (self), FALSE);
	g_return_val_if_fail (path != NULL, FALSE);

	priv = NM_VPN_MANAGER_GET_PRIVATE (self);
	g_hash_table_iter_init (&iter, priv->services);
	while (g_hash_table_iter_next (&iter, NULL, &data)) {
		active = nm_vpn_service_get_active_connections (NM_VPN_SERVICE (data));
		for (elt = active; elt; elt = g_slist_next (elt)) {
			NMVPNConnection *vpn = NM_VPN_CONNECTION (elt->data);
			const char *vpn_path;

			vpn_path = nm_vpn_connection_get_active_connection_path (vpn);
			if (!strcmp (path, vpn_path)) {
				nm_vpn_connection_disconnect (vpn, reason);
				return TRUE;
			}
		}
	}

	return FALSE;
}
Example #12
0
/**
 * gjs_cairo_path_from_path:
 * @context: the context
 * @path: cairo_path_t to attach to the object
 *
 * Constructs a pattern wrapper given cairo pattern.
 * NOTE: This function takes ownership of the path.
 */
JSObject *
gjs_cairo_path_from_path(JSContext    *context,
                         cairo_path_t *path)
{
    JSObject *object;
    GjsCairoPath *priv;

    g_return_val_if_fail(context != NULL, NULL);
    g_return_val_if_fail(path != NULL, NULL);

    object = JS_NewObject(context, &gjs_cairo_path_class, NULL, NULL);
    if (!object) {
        gjs_throw(context, "failed to create path");
        return NULL;
    }

    priv = g_slice_new0(GjsCairoPath);

    g_assert(priv_from_js(context, object) == NULL);
    JS_SetPrivate(context, object, priv);

    priv->context = context;
    priv->object = object;
    priv->path = path;

    return object;
}
Example #13
0
/**
 * gdata_freebase_service_get_image:
 * @self: a #GDataFreebaseService
 * @value: a #GDataFreebaseTopicValue from a topic result
 * @cancellable: (allow-none): optional #GCancellable object, or %NULL
 * @max_width: maximum width of the image returned, or 0
 * @max_height: maximum height of the image returned, or 0
 * @error: (allow-none): a #GError, or %NULL
 *
 * Creates an input stream to an image object returned in a topic query. If @max_width and @max_height
 * are unspecified (i.e. set to 0), the image returned will be the smallest available.
 *
 * Return value: (transfer full): a #GInputStream opened to the image; unref with g_object_unref()
 *
 * Since: 0.15.1
 * Deprecated: 0.17.7: Google Freebase has been permanently shut down.
 */
GInputStream *
gdata_freebase_service_get_image (GDataFreebaseService *self, GDataFreebaseTopicValue *value,
				  GCancellable *cancellable, guint max_width, guint max_height, GError **error)
{
	GInputStream *stream;
	gchar *uri;

	g_return_val_if_fail (GDATA_IS_FREEBASE_SERVICE (self), NULL);
	g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
	g_return_val_if_fail (value != NULL, NULL);
	g_return_val_if_fail (!error || !*error, NULL);
	g_return_val_if_fail (max_width < 4096 && max_height < 4096, NULL);

	if (!gdata_freebase_topic_value_is_image (value)) {
		g_set_error (error,
			     GDATA_SERVICE_ERROR,
			     GDATA_SERVICE_ERROR_BAD_QUERY_PARAMETER,
			     _("Property ‘%s’ does not hold an image"),
			     gdata_freebase_topic_value_get_property (value));
		return NULL;
	}

	uri = compose_image_uri (value, max_width, max_height);
	stream = gdata_download_stream_new (GDATA_SERVICE (self), get_freebase_authorization_domain (), uri, cancellable);
	g_free (uri);

	return stream;
}
Example #14
0
EmpathyChat *
empathy_chat_window_find_chat (McAccount   *account,
			       const gchar *id)
{
	GList *l;

	g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL);
	g_return_val_if_fail (!G_STR_EMPTY (id), NULL);

	for (l = chat_windows; l; l = l->next) {
		EmpathyChatWindowPriv *priv;
		EmpathyChatWindow     *window;
		GList                *ll;

		window = l->data;
		priv = GET_PRIV (window);

		for (ll = priv->chats; ll; ll = ll->next) {
			EmpathyChat *chat;

			chat = ll->data;

			if (empathy_account_equal (account, empathy_chat_get_account (chat)) &&
			    !tp_strdiff (id, empathy_chat_get_id (chat))) {
				return chat;
			}
		}
	}

	return NULL;
}
Example #15
0
/**
 * wbl_string_set_equal:
 * @a: a #WblStringSet
 * @b: another #WblStringSet
 *
 * Check whether two string sets are equal — whether they contain exactly the
 * same members. Formally:
 *    @a = @b ≡ @a ⊆ @b ∧ @b ⊆ @a
 *
 * Returns: %TRUE if @a and @b are equal, %FALSE otherwise
 *
 * Since: 0.2.0
 */
gboolean
wbl_string_set_equal (WblStringSet  *a,
                      WblStringSet  *b)
{
	GHashTableIter iter;
	const gchar *key;

	g_return_val_if_fail (_wbl_string_set_is_valid (a), FALSE);
	g_return_val_if_fail (_wbl_string_set_is_valid (b), FALSE);

	/* Quick checks. */
	if (a == b)
		return TRUE;
	if (a->hash != b->hash)
		return FALSE;
	if (wbl_string_set_get_size (a) != wbl_string_set_get_size (b))
		return FALSE;

	/* Compare elements. */
	g_hash_table_iter_init (&iter, a->set);

	while (g_hash_table_iter_next (&iter, (gpointer *) &key, NULL)) {
		if (!g_hash_table_contains (b->set, key)) {
			return FALSE;
		}
	}

	return TRUE;
}
/**
 * gst_codec_utils_h265_caps_set_level_tier_and_profile:
 * @caps: the #GstCaps to which the level, tier and profile are to be added
 * @profile_tier_level: Pointer to the profile_tier_level struct
 * @len: Length of the data available in @profile_tier_level.
 *
 * Sets the level, tier and profile in @caps if it can be determined from
 * @profile_tier_level. See gst_codec_utils_h265_get_level(),
 * gst_codec_utils_h265_get_tier() and gst_codec_utils_h265_get_profile()
 * for more details on the parameters.
 *
 * Returns: %TRUE if the level, tier, profile could be set, %FALSE otherwise.
 *
 * Since 1.4
 */
gboolean
gst_codec_utils_h265_caps_set_level_tier_and_profile (GstCaps * caps,
    const guint8 * profile_tier_level, guint len)
{
  const gchar *level, *tier, *profile;

  g_return_val_if_fail (GST_IS_CAPS (caps), FALSE);
  g_return_val_if_fail (GST_CAPS_IS_SIMPLE (caps), FALSE);
  g_return_val_if_fail (GST_SIMPLE_CAPS_HAS_NAME (caps, "video/x-h265"), FALSE);
  g_return_val_if_fail (profile_tier_level != NULL, FALSE);

  level = gst_codec_utils_h265_get_level (profile_tier_level, len);
  if (level != NULL)
    gst_caps_set_simple (caps, "level", G_TYPE_STRING, level, NULL);

  tier = gst_codec_utils_h265_get_tier (profile_tier_level, len);
  if (tier != NULL)
    gst_caps_set_simple (caps, "tier", G_TYPE_STRING, tier, NULL);

  profile = gst_codec_utils_h265_get_profile (profile_tier_level, len);
  if (profile != NULL)
    gst_caps_set_simple (caps, "profile", G_TYPE_STRING, profile, NULL);

  GST_LOG ("profile : %s", (profile) ? profile : "---");
  GST_LOG ("tier    : %s", (tier) ? tier : "---");
  GST_LOG ("level   : %s", (level) ? level : "---");

  return (level != NULL && tier != NULL && profile != NULL);
}
Example #17
0
/**
 * ggit_reflog_rename:
 * @reflog: a #GgitReflog.
 * @new_name: the new name of the reference.
 * @error: a #GError for error reporting, or %NULL.
 *
 * Renames the reflog for to @new_name, on error @error is set.
 */
gboolean
ggit_reflog_rename (GgitReflog  *reflog,
                    const gchar *new_name,
                    GError      **error)
{
	git_reference *nref;
	gint ret;

	g_return_val_if_fail (reflog != NULL, FALSE);
	g_return_val_if_fail (new_name != NULL && *new_name != '\0', FALSE);
	g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

	nref = _ggit_native_get (reflog->ref);

	ret = git_reflog_rename (git_reference_owner (nref),
	                         git_reference_name (nref),
	                         new_name);

	if (ret != GIT_OK)
	{
		_ggit_error_set (error, ret);
		return FALSE;
	}

	return TRUE;
}
GtkWidget *
gimp_dynamics_factory_view_new (GimpViewType      view_type,
                                GimpDataFactory  *factory,
                                GimpContext      *context,
                                gint              view_size,
                                gint              view_border_width,
                                GimpMenuFactory  *menu_factory)
{
  g_return_val_if_fail (GIMP_IS_DATA_FACTORY (factory), NULL);
  g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
  g_return_val_if_fail (view_size > 0 &&
                        view_size <= GIMP_VIEWABLE_MAX_PREVIEW_SIZE, NULL);
  g_return_val_if_fail (view_border_width >= 0 &&
                        view_border_width <= GIMP_VIEW_MAX_BORDER_WIDTH,
                        NULL);
  g_return_val_if_fail (menu_factory == NULL ||
                        GIMP_IS_MENU_FACTORY (menu_factory), NULL);

  return g_object_new (GIMP_TYPE_DYNAMICS_FACTORY_VIEW,
                       "view-type",         view_type,
                       "data-factory",      factory,
                       "context",           context,
                       "view-size",         view_size,
                       "view-border-width", view_border_width,
                       "menu-factory",      menu_factory,
                       "menu-identifier",   "<Dynamics>",
                       "ui-path",           "/dynamics-popup",
                       "action-group",      "dynamics",
                       NULL);
}
Example #19
0
/**
 * gda_report_engine_find_declared_object
 * @engine: a #GdaReportEngine object
 * @obj_type: the type of requested object
 * @obj_name: the name (in @engine) of the object to find
 *
 * Finds an object which has previously been declared using gda_report_engine_declare_object().
 *
 * Returns: a pointer to the requested object, or %NULL if not found
 */
GObject *
gda_report_engine_find_declared_object (GdaReportEngine *engine, GType obj_type, const gchar *obj_name)
{
	gchar prefix, *real_name;
	GObject *current_obj;
	g_return_val_if_fail (GDA_IS_REPORT_ENGINE (engine), NULL);
	g_return_val_if_fail (engine->priv, NULL);
	g_return_val_if_fail (obj_name, NULL);

	if (obj_type == GDA_TYPE_STATEMENT)
		prefix = 'S';
	else if (obj_type == GDA_TYPE_CONNECTION)
		prefix = 'C';
	else if (obj_type == GDA_TYPE_HOLDER)
		prefix = 'H';
	else {
		g_warning (_("Object type '%s' cannot be requested in this context"), g_type_name (obj_type));
		return NULL;
	}
	real_name = g_strdup_printf ("%c%s", prefix, obj_name);
	current_obj = g_hash_table_lookup (engine->priv->objects, real_name);
	/*g_print ("%s(): requested %s => %p\n", __FUNCTION__, real_name, current_obj);*/
	g_free (real_name);
	return current_obj;
}
Example #20
0
/* Create new view. */
TEXT_BUFFER_VIEW_REC *textbuffer_view_create(TEXT_BUFFER_REC *buffer,
					     int width, int height,
					     int scroll, int utf8)
{
	TEXT_BUFFER_VIEW_REC *view;

        g_return_val_if_fail(buffer != NULL, NULL);
        g_return_val_if_fail(width > 0, NULL);

	view = g_new0(TEXT_BUFFER_VIEW_REC, 1);
	view->buffer = buffer;
        view->siblings = textbuffer_get_views(buffer);

	view->width = width;
        view->height = height;
	view->scroll = scroll;
        view->utf8 = utf8;

	view->cache = textbuffer_cache_get(view->siblings, width);
	textbuffer_view_init_bottom(view);

	view->startline = view->bottom_startline;
        view->subline = view->bottom_subline;
	view->bottom = TRUE;

	textbuffer_view_init_ypos(view);

	view->bookmarks = g_hash_table_new((GHashFunc) g_str_hash,
					   (GCompareFunc) g_str_equal);

	views = g_slist_append(views, view);
        return view;
}
Example #21
0
static gboolean
test_role (void)
{
    AtkRole role1, role2;
    G_CONST_RETURN gchar *name;

    name = atk_role_get_name (ATK_ROLE_PAGE_TAB);
    g_return_val_if_fail (name, FALSE);
    if (strcmp (name, "page-tab") != 0)
    {
        g_print ("Unexpected name for ATK_ROLE_PAGE_TAB %s\n", name);
        return FALSE;
    }

    name = atk_role_get_name (ATK_ROLE_LAYERED_PANE);
    g_return_val_if_fail (name, FALSE);
    if (strcmp (name, "layered-pane") != 0)
    {
        g_print ("Unexpected name for ATK_ROLE_LAYERED_PANE %s\n", name);
        return FALSE;
    }

    role1 = atk_role_for_name ("list-item");
    if (role1 != ATK_ROLE_LIST_ITEM)
    {
        g_print ("Unexpected role for list-item\n");
        return FALSE;
    }

    role1 = atk_role_register ("test-role");
    name = atk_role_get_name (role1);
    g_return_val_if_fail (name, FALSE);
    if (strcmp (name, "test-role") != 0)
    {
        g_print ("Unexpected name for test-role %s\n", name);
        return FALSE;
    }
    role2 = atk_role_for_name ("test-role");
    if (role1 != role2)
    {
        g_print ("Unexpected role for test-role\n");
        return FALSE;
    }
    role2 = atk_role_for_name ("TEST_ROLE");
    if (role2 != 0)
    {
        g_print ("Unexpected role for TEST_ROLE\n");
        return FALSE;
    }
    /*
     * Check that a non-existent role returns NULL
     */
    name = atk_role_get_name (ATK_ROLE_LAST_DEFINED + 2);
    if (name)
    {
        g_print ("Unexpected name for undefined role %s\n", name);
        return FALSE;
    }
    return TRUE;
}
Example #22
0
/**
 * clutter_container_class_find_child_property:
 * @klass: a #GObjectClass implementing the #ClutterContainer interface.
 * @property_name: a property name.
 *
 * Looks up the #GParamSpec for a child property of @klass.
 *
 * Return value: (transfer none): The #GParamSpec for the property or %NULL
 *   if no such property exist.
 *
 * Since: 0.8
 */
GParamSpec *
clutter_container_class_find_child_property (GObjectClass *klass,
                                             const gchar  *property_name)
{
  ClutterContainerIface *iface;
  GObjectClass          *child_class;
  GParamSpec            *pspec;

  g_return_val_if_fail (G_IS_OBJECT_CLASS (klass), NULL);
  g_return_val_if_fail (property_name != NULL, NULL);
  g_return_val_if_fail (g_type_is_a (G_TYPE_FROM_CLASS (klass),
                                     CLUTTER_TYPE_CONTAINER),
                        NULL);

  iface = g_type_interface_peek (klass, CLUTTER_TYPE_CONTAINER);
  g_return_val_if_fail (iface != NULL, NULL);

  if (iface->child_meta_type == G_TYPE_INVALID)
    return NULL;

  child_class = g_type_class_ref (iface->child_meta_type);
  pspec = g_object_class_find_property (child_class, property_name);
  g_type_class_unref (child_class);

  return pspec;
}
Example #23
0
/**
 * gst_vaapi_object_new:
 * @klass: The object class
 * @display: The #GstVaapiDisplay
 *
 * Creates a new #GstVaapiObject. The @klass argument shall not be
 * %NULL, and it must reference a statically allocated descriptor.
 *
 * This function zero-initializes the derived object data. Also note
 * that this is an internal function that shall not be used outside of
 * libgstvaapi libraries.
 *
 * Returns: The newly allocated #GstVaapiObject
 */
gpointer
gst_vaapi_object_new (const GstVaapiObjectClass * klass,
    GstVaapiDisplay * display)
{
  const GstVaapiMiniObjectClass *const object_class =
      GST_VAAPI_MINI_OBJECT_CLASS (klass);
  GstVaapiObject *object;
  guint sub_size;

  g_return_val_if_fail (klass != NULL, NULL);
  g_return_val_if_fail (display != NULL, NULL);

  object = (GstVaapiObject *) gst_vaapi_mini_object_new (object_class);
  if (!object)
    return NULL;

  object->display = gst_object_ref (display);
  object->object_id = VA_INVALID_ID;

  sub_size = object_class->size - sizeof (*object);
  if (sub_size > 0)
    memset (((guchar *) object) + sizeof (*object), 0, sub_size);

  if (klass->init)
    klass->init (object);
  return object;
}
Example #24
0
PurplePounce *
purple_pounce_new(const char *ui_type, PurpleAccount *pouncer,
				const char *pouncee, PurplePounceEvent event,
				PurplePounceOption option)
{
	PurplePounce *pounce;
	PurplePounceHandler *handler;

	g_return_val_if_fail(ui_type != NULL, NULL);
	g_return_val_if_fail(pouncer != NULL, NULL);
	g_return_val_if_fail(pouncee != NULL, NULL);
	g_return_val_if_fail(event   != 0,    NULL);

	pounce = g_new0(PurplePounce, 1);

	pounce->ui_type  = g_strdup(ui_type);
	pounce->pouncer  = pouncer;
	pounce->pouncee  = g_strdup(pouncee);
	pounce->events   = event;
	pounce->options  = option;

	pounce->actions  = g_hash_table_new_full(g_str_hash, g_str_equal,
											 g_free, free_action_data);

	handler = g_hash_table_lookup(pounce_handlers, pounce->ui_type);

	if (handler != NULL && handler->new_pounce != NULL)
		handler->new_pounce(pounce);

	pounces = g_list_append(pounces, pounce);

	schedule_pounces_save();

	return pounce;
}
Example #25
0
gboolean
file_remote_upload_image_finish (Gimp          *gimp,
                                 GFile         *file,
                                 GFile         *local_file,
                                 gboolean       mounted,
                                 GimpProgress  *progress,
                                 GError       **error)
{
  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
  g_return_val_if_fail (G_IS_FILE (file), NULL);
  g_return_val_if_fail (G_IS_FILE (local_file), NULL);
  g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), NULL);
  g_return_val_if_fail (error == NULL || *error == NULL, NULL);

  if (! mounted)
    {
      if (! file_remote_copy_file (gimp, local_file, file, UPLOAD,
                                   progress, error))
        {
          return FALSE;
        }
    }

  return TRUE;
}
Example #26
0
PurplePounce *
purple_find_pounce(const PurpleAccount *pouncer, const char *pouncee,
				 PurplePounceEvent events)
{
	PurplePounce *pounce = NULL;
	GList *l;
	char *norm_pouncee;

	g_return_val_if_fail(pouncer != NULL, NULL);
	g_return_val_if_fail(pouncee != NULL, NULL);
	g_return_val_if_fail(events  != PURPLE_POUNCE_NONE, NULL);

	norm_pouncee = g_strdup(purple_normalize(pouncer, pouncee));

	for (l = purple_pounces_get_all(); l != NULL; l = l->next)
	{
		pounce = (PurplePounce *)l->data;

		if ((purple_pounce_get_events(pounce) & events) &&
			(purple_pounce_get_pouncer(pounce) == pouncer) &&
			!purple_utf8_strcasecmp(purple_normalize(pouncer, purple_pounce_get_pouncee(pounce)),
								  norm_pouncee))
		{
			break;
		}

		pounce = NULL;
	}

	g_free(norm_pouncee);

	return pounce;
}
Example #27
0
/**
 * accept a connection
 *
 * event handler for listening connections
 *
 * @param srv    a listening socket 
 * 
 */
network_socket *network_socket_accept(network_socket *srv) {
	network_socket *client;

	g_return_val_if_fail(srv, NULL);
	g_return_val_if_fail(srv->socket_type == SOCK_STREAM, NULL); /* accept() only works on stream sockets */

	client = network_socket_new();
    if (-1 == (client->fd = accept4(srv->fd, &client->src->addr.common, &(client->src->len), SOCK_NONBLOCK))) {
        network_socket_free(client);

        return NULL;
    }

	if (network_address_refresh_name(client->src)) {
		network_socket_free(client);
		return NULL;
	}

	/* the listening side may be INADDR_ANY, let's get which address the client really connected to */
	if (-1 == getsockname(client->fd, &client->dst->addr.common, &(client->dst->len))) {
		network_address_reset(client->dst);
	} else if (network_address_refresh_name(client->dst)) {
		network_address_reset(client->dst);
	}

	return client;
}
Example #28
0
gboolean
wing_get_version_number (gint *major,
                         gint *minor)
{
  typedef NTSTATUS (WINAPI fRtlGetVersion) (PRTL_OSVERSIONINFOEXW);
  OSVERSIONINFOEXW osverinfo;
  fRtlGetVersion *RtlGetVersion;
  HMODULE hmodule;

  hmodule = LoadLibraryW (L"ntdll.dll");
  g_return_val_if_fail (hmodule != NULL, FALSE);

  RtlGetVersion = (fRtlGetVersion *)GetProcAddress (hmodule, "RtlGetVersion");
  g_return_val_if_fail (RtlGetVersion != NULL, FALSE);

  memset (&osverinfo, 0, sizeof (OSVERSIONINFOEXW));
  osverinfo.dwOSVersionInfoSize = sizeof (OSVERSIONINFOEXW);
  RtlGetVersion (&osverinfo);

  FreeLibrary (hmodule);

  *major = osverinfo.dwMajorVersion;
  *minor = osverinfo.dwMinorVersion;

  return TRUE;
}
gint er_dtls_connection_send(ErDtlsConnection *self, gpointer data, gint len)
{
    g_return_val_if_fail(ER_IS_DTLS_CONNECTION(self), 0);
    int ret = 0;

    g_return_val_if_fail(self->priv->ssl, 0);
    g_return_val_if_fail(self->priv->bio, 0);

    LOG_TRACE(self, "locking @ send");
    g_mutex_lock(&self->priv->mutex);
    LOG_TRACE(self, "locked @ send");

    if (SSL_is_init_finished(self->priv->ssl)) {
        ret = SSL_write(self->priv->ssl, data, len);
        LOG_DEBUG(self, "data sent: input was %d B, output is %d B", len, ret);
    } else {
        LOG_WARNING(self, "tried to send data before handshake was complete");
        ret = 0;
    }

    LOG_TRACE(self, "unlocking @ send");
    g_mutex_unlock(&self->priv->mutex);

    return ret;
}
/**
 * gdk_pixbuf_new_from_data:
 * @data: (array) (element-type char): Image data in 8-bit/sample packed format
 * @colorspace: Colorspace for the image data
 * @has_alpha: Whether the data has an opacity channel
 * @bits_per_sample: Number of bits per sample
 * @width: Width of the image in pixels, must be > 0
 * @height: Height of the image in pixels, must be > 0
 * @rowstride: Distance in bytes between row starts
 * @destroy_fn: (scope async): Function used to free the data when the pixbuf's reference count
 * drops to zero, or %NULL if the data should not be freed
 * @destroy_fn_data: (closure): Closure data to pass to the destroy notification function
 * 
 * Creates a new #GdkPixbuf out of in-memory image data.  Currently only RGB
 * images with 8 bits per sample are supported.
 * 
 * Return value: (transfer full): A newly-created #GdkPixbuf structure with a reference count of 1.
 **/
GdkPixbuf *
gdk_pixbuf_new_from_data (const guchar *data, GdkColorspace colorspace, gboolean has_alpha,
			  int bits_per_sample, int width, int height, int rowstride,
	  GdkPixbufDestroyNotify destroy_fn, gpointer destroy_fn_data)
{
	GdkPixbuf *pixbuf;

	/* Only 8-bit/sample RGB buffers are supported for now */

	g_return_val_if_fail (data != NULL, NULL);
	g_return_val_if_fail (colorspace == GDK_COLORSPACE_RGB, NULL);
	g_return_val_if_fail (bits_per_sample == 8, NULL);
	g_return_val_if_fail (width > 0, NULL);
	g_return_val_if_fail (height > 0, NULL);

	pixbuf = g_object_new (GDK_TYPE_PIXBUF, 
			       "colorspace", colorspace,
			       "n-channels", has_alpha ? 4 : 3,
			       "bits-per-sample", bits_per_sample,
			       "has-alpha", has_alpha ? TRUE : FALSE,
			       "width", width,
			       "height", height,
			       "rowstride", rowstride,
			       "pixels", data,
			       NULL);
        
	pixbuf->destroy_fn = destroy_fn;
	pixbuf->destroy_fn_data = destroy_fn_data;

	return pixbuf;
}