Пример #1
0
static WatchNameData *
watch_name_data_new (GClosure *name_appeared_closure,
                     GClosure *name_vanished_closure)
{
  WatchNameData *data;

  data = g_new0 (WatchNameData, 1);

  if (name_appeared_closure != NULL)
    {
      data->name_appeared_closure = g_closure_ref (name_appeared_closure);
      g_closure_sink (name_appeared_closure);
      if (G_CLOSURE_NEEDS_MARSHAL (name_appeared_closure))
        g_closure_set_marshal (name_appeared_closure, g_cclosure_marshal_generic);
    }

  if (name_vanished_closure != NULL)
    {
      data->name_vanished_closure = g_closure_ref (name_vanished_closure);
      g_closure_sink (name_vanished_closure);
      if (G_CLOSURE_NEEDS_MARSHAL (name_vanished_closure))
        g_closure_set_marshal (name_vanished_closure, g_cclosure_marshal_generic);
    }

  return data;
}
Пример #2
0
static OwnNameData *
own_name_data_new (GClosure *bus_acquired_closure,
                   GClosure *name_acquired_closure,
                   GClosure *name_lost_closure)
{
  OwnNameData *data;

  data = g_new0 (OwnNameData, 1);

  if (bus_acquired_closure != NULL)
    {
      data->bus_acquired_closure = g_closure_ref (bus_acquired_closure);
      g_closure_sink (bus_acquired_closure);
      if (G_CLOSURE_NEEDS_MARSHAL (bus_acquired_closure))
        g_closure_set_marshal (bus_acquired_closure, g_cclosure_marshal_generic);
    }

  if (name_acquired_closure != NULL)
    {
      data->name_acquired_closure = g_closure_ref (name_acquired_closure);
      g_closure_sink (name_acquired_closure);
      if (G_CLOSURE_NEEDS_MARSHAL (name_acquired_closure))
        g_closure_set_marshal (name_acquired_closure, g_cclosure_marshal_generic);
    }

  if (name_lost_closure != NULL)
    {
      data->name_lost_closure = g_closure_ref (name_lost_closure);
      g_closure_sink (name_lost_closure);
      if (G_CLOSURE_NEEDS_MARSHAL (name_lost_closure))
        g_closure_set_marshal (name_lost_closure, g_cclosure_marshal_generic);
    }

  return data;
}
Пример #3
0
void dt_lua_async_call_alien_internal(const char * call_function, int line,lua_CFunction pusher,int nresults,dt_lua_finish_callback cb, void*cb_data, dt_lua_async_call_arg_type arg_type,...)
{
#ifdef _DEBUG
  dt_print(DT_DEBUG_LUA,"LUA DEBUG : %s called from %s %d\n",__FUNCTION__,call_function,line);
#endif
  async_call_data*data = malloc(sizeof(async_call_data));
  data->pusher = pusher;
  data->extra=NULL;
  data->cb = cb;
  data->cb_data = cb_data;
  data->nresults = nresults;
  va_list ap;
  va_start(ap,arg_type);
  dt_lua_async_call_arg_type cur_type = arg_type;
  while(cur_type != LUA_ASYNC_DONE){
    data->extra=g_list_append(data->extra,GINT_TO_POINTER(cur_type));
    switch(cur_type) {
      case LUA_ASYNC_TYPEID:
        data->extra=g_list_append(data->extra,GINT_TO_POINTER(va_arg(ap,luaA_Type)));
        data->extra=g_list_append(data->extra,va_arg(ap,gpointer));
        break;
      case LUA_ASYNC_TYPEID_WITH_FREE:
        {
          data->extra=g_list_append(data->extra,GINT_TO_POINTER(va_arg(ap,luaA_Type)));
          data->extra=g_list_append(data->extra,va_arg(ap,gpointer));
          GClosure* closure = va_arg(ap,GClosure*);
          g_closure_ref (closure);
          g_closure_sink (closure);
          g_closure_set_marshal(closure, g_cclosure_marshal_generic);
          data->extra=g_list_append(data->extra,closure);
        }
        break;
      case LUA_ASYNC_TYPENAME:
        data->extra=g_list_append(data->extra,va_arg(ap,char *));
        data->extra=g_list_append(data->extra,va_arg(ap,gpointer));
        break;
      case LUA_ASYNC_TYPENAME_WITH_FREE:
        {
          data->extra=g_list_append(data->extra,va_arg(ap,char *));
          data->extra=g_list_append(data->extra,va_arg(ap,gpointer));
          GClosure* closure = va_arg(ap,GClosure*);
          g_closure_ref (closure);
          g_closure_sink (closure);
          g_closure_set_marshal(closure, g_cclosure_marshal_generic);
          data->extra=g_list_append(data->extra,closure);
        }
        break;
      default:
        // should never happen
        g_assert(false);
        break;
    }
    cur_type = va_arg(ap,dt_lua_async_call_arg_type);
  }

  va_end(ap);

  g_async_queue_push(darktable.lua_state.alien_job_queue,(gpointer)data);
  g_main_context_wakeup(darktable.lua_state.context);
}
Пример #4
0
void
moo_plugin_method_new (const char     *name,
                       GType           ptype,
                       GCallback       method,
                       GClosureMarshal c_marshaller,
                       GType           return_type,
                       guint           n_params,
                       ...)
{
    va_list args;
    GClosure *closure;

    g_return_if_fail (g_type_is_a (ptype, MOO_TYPE_PLUGIN));
    g_return_if_fail (name != NULL);
    g_return_if_fail (method != NULL);
    g_return_if_fail (c_marshaller != NULL);

    closure = g_cclosure_new (method, NULL, NULL);
    g_closure_sink (g_closure_ref (closure));

    va_start (args, n_params);
    moo_plugin_method_new_valist (name, ptype, closure, c_marshaller,
                                  return_type, n_params, args);
    va_end (args);

    g_closure_unref (closure);
}
/**
 * thunar_clipboard_manager_paste_files:
 * @manager           : a #XfdesktopClipboardManager.
 * @target_file       : the #GFile of the folder to which the contents on the clipboard
 *                      should be pasted.
 * @widget            : a #GtkWidget, on which to perform the paste or %NULL if no widget is
 *                      known.
 * @new_files_closure : a #GClosure to connect to the job's "new-files" signal,
 *                      which will be emitted when the job finishes with the
 *                      list of #GFile<!---->s created by the job, or
 *                      %NULL if you're not interested in the signal.
 *
 * Pastes the contents from the clipboard associated with @manager to the directory
 * referenced by @target_file.
 * Code copied and adapted from thunar-clipboard-manager.c
 * Copyright (c) 2005-2006 Benedikt Meurer <*****@*****.**>
 * Copyright (c) 2009-2011 Jannis Pohlmann <*****@*****.**>
 **/
void
xfdesktop_clipboard_manager_paste_files (XfdesktopClipboardManager *manager,
                                      GFile                  *target_file,
                                      GtkWidget              *widget,
                                      GClosure               *new_files_closure)
{
  XfdesktopClipboardPasteRequest *request;

  g_return_if_fail (XFDESKTOP_IS_CLIPBOARD_MANAGER (manager));
  g_return_if_fail (widget == NULL || GTK_IS_WIDGET (widget));

  /* prepare the paste request */
  request = g_slice_new0 (XfdesktopClipboardPasteRequest);
  request->manager = g_object_ref (G_OBJECT (manager));
  request->target_file = g_object_ref (target_file);
  request->widget = widget;

  /* take a reference on the closure (if any) */
  if (G_LIKELY (new_files_closure != NULL))
    {
      request->new_files_closure = new_files_closure;
      g_closure_ref (new_files_closure);
      g_closure_sink (new_files_closure);
    }

  /* get notified when the widget is destroyed prior to
   * completing the clipboard contents retrieval
   */
  if (G_LIKELY (request->widget != NULL))
    g_object_add_weak_pointer (G_OBJECT (request->widget), (gpointer) &request->widget);

  /* schedule the request */
  gtk_clipboard_request_contents (manager->clipboard, manager->x_special_gnome_copied_files,
                                  xfdesktop_clipboard_manager_contents_received, request);
}
Пример #6
0
/*
 * clutter_alpha_set_closure_internal:
 * @alpha: a #ClutterAlpha
 * @closure: a #GClosure
 *
 * Sets the @closure for @alpha. This function does not
 * set the #ClutterAlpha:mode property and does not emit
 * the #GObject::notify signal for it.
 */
static inline void
clutter_alpha_set_closure_internal (ClutterAlpha *alpha,
                                    GClosure     *closure)
{
  ClutterAlphaPrivate *priv = alpha->priv;

  if (priv->notify != NULL)
    priv->notify (priv->user_data);
  else if (priv->closure != NULL)
    g_closure_unref (priv->closure);

  priv->func = NULL;
  priv->user_data = NULL;
  priv->notify = NULL;

  if (closure == NULL)
    return;

  /* need to take ownership of the closure before sinking it */
  priv->closure = g_closure_ref (closure);
  g_closure_sink (closure);

  /* set the marshaller */
  if (G_CLOSURE_NEEDS_MARSHAL (closure))
    {
      GClosureMarshal marshal = _clutter_marshal_DOUBLE__VOID;

      g_closure_set_marshal (priv->closure, marshal);
    }
}
/**
 * g_source_set_closure:
 * @source: the source
 * @closure: a #GClosure
 *
 * Set the callback for a source as a #GClosure.
 *
 * If the source is not one of the standard GLib types, the @closure_callback
 * and @closure_marshal fields of the #GSourceFuncs structure must have been
 * filled in with pointers to appropriate functions.
 */
void
g_source_set_closure (GSource  *source,
		      GClosure *closure)
{
  g_return_if_fail (source != NULL);
  g_return_if_fail (closure != NULL);

  if (!source->source_funcs->closure_callback &&
      source->source_funcs != &g_io_watch_funcs &&
      source->source_funcs != &g_timeout_funcs &&
      source->source_funcs != &g_idle_funcs)
    {
      g_critical (G_STRLOC ": closure can not be set on closure without GSourceFuncs::closure_callback\n");
      return;
    }

  g_closure_ref (closure);
  g_closure_sink (closure);
  g_source_set_callback_indirect (source, closure, &closure_callback_funcs);

  if (G_CLOSURE_NEEDS_MARSHAL (closure))
    {
      GClosureMarshal marshal = (GClosureMarshal)source->source_funcs->closure_marshal;
      if (!marshal)
	{
	  if (source->source_funcs == &g_idle_funcs ||
	      source->source_funcs == &g_timeout_funcs)
	    marshal = source_closure_marshal_BOOLEAN__VOID;
	  else if (source->source_funcs == &g_io_watch_funcs)
	    marshal = g_cclosure_marshal_BOOLEAN__FLAGS;
	}
      if (marshal)
	g_closure_set_marshal (closure, marshal);
    }
}
Пример #8
0
static VALUE
rg_initialize(VALUE self)
{
    GClosure* closure = g_rclosure_new(rb_block_proc(), Qnil, NULL);
    G_INITIALIZE(self, closure);
    g_closure_sink(closure);
    return self;
}
Пример #9
0
void owl_variable_dict_newvar_other(owl_vardict *vd, const char *name, const char *summary, const char *description, const char *validsettings, bool takes_on_off, GClosure *get_tostring_fn, GClosure *set_fromstring_fn)
{
  owl_variable *var = owl_variable_newvar(OWL_VARIABLE_OTHER, name, summary,
                                          description, validsettings);
  var->takes_on_off = takes_on_off;

  var->get_tostring_fn = g_closure_ref(get_tostring_fn);
  g_closure_sink(get_tostring_fn);

  var->set_fromstring_fn = g_closure_ref(set_fromstring_fn);
  g_closure_sink(set_fromstring_fn);

  var->default_str = owl_variable_get_tostring(var);

  /* Note: this'll overwrite any existing variable of that name, even a C one,
     but it's consistent with previous behavior and commands. */
  owl_variable_dict_add_variable(vd, var);
}
Пример #10
0
/* Hack. We iterate over the accel map instead of the actions,
 * in order to pull the parameters out of accel map entries
 */
static void
add_accel_closure (gpointer         data,
                   const gchar     *accel_path,
                   guint            accel_key,
                   GdkModifierType  accel_mods,
                   gboolean         changed)
{
    GtkApplicationWindow *window = data;
    GActionGroup *actions;
    const gchar *path;
    const gchar *p;
    gchar *action_name;
    GVariant *parameter;
    AccelClosure *closure;

    if (accel_key == 0)
        return;

    if (!g_str_has_prefix (accel_path, "<GAction>/"))
        return;

    path = accel_path + strlen ("<GAction>/");
    p = strchr (path, '/');
    if (p)
    {
        action_name = g_strndup (path, p - path);
        parameter = g_variant_parse (NULL, p + 1, NULL, NULL, NULL);
        if (!parameter)
            g_warning ("Failed to parse parameter from '%s'\n", accel_path);
    }
    else
    {
        action_name = g_strdup (path);
        parameter = NULL;
    }

    actions = G_ACTION_GROUP (_gtk_widget_get_action_muxer (GTK_WIDGET (window)));
    if (g_action_group_has_action (actions, action_name))
    {
        closure = (AccelClosure*) g_closure_new_object (sizeof (AccelClosure), g_object_ref (actions));
        g_closure_set_marshal (&closure->closure, accel_activate);

        closure->action_name = g_strdup (action_name);
        closure->parameter = parameter ? g_variant_ref_sink (parameter) : NULL;

        window->priv->accel_closures = g_slist_prepend (window->priv->accel_closures, g_closure_ref (&closure->closure));
        g_closure_sink (&closure->closure);

        gtk_accel_group_connect_by_path (window->priv->accels, accel_path, &closure->closure);
    }
    else if (parameter)
    {
        g_variant_unref (parameter);
    }

    g_free (action_name);
}
Пример #11
0
static inline GClosure *createCppClosure(ClosureDataBase *closureData)
{
    GClosure *closure = g_closure_new_simple(sizeof(GClosure), closureData);
    g_closure_set_marshal(closure, &c_marshaller);
    g_closure_add_finalize_notifier(closure, NULL, &closureDestroyNotify);
    g_closure_ref(closure);
    g_closure_sink(closure);
    return closure;
}
Пример #12
0
CALLER_OWN GClosure *owl_variable_make_closure(owl_variable *v,
                                               GCallback fn,
                                               GClosureMarshal marshal) {
  GClosure *closure = g_cclosure_new_swap(fn, v, NULL);
  g_closure_set_marshal(closure,marshal);
  g_closure_ref(closure);
  g_closure_sink(closure);
  return closure;
}
Пример #13
0
static void
test_closure (GClosure *closure)
{
  /* try to produce high contention in closure->ref_count */
  guint i = 0, n = quick_rand32() % 199;
  for (i = 0; i < n; i++)
    g_closure_ref (closure);
  g_closure_sink (closure); /* NOP */
  for (i = 0; i < n; i++)
    g_closure_unref (closure);
}
Пример #14
0
/**
 * g_object_bind_property_with_closures:
 * @source: (type GObject.Object): the source #GObject
 * @source_property: the property on @source to bind
 * @target: (type GObject.Object): the target #GObject
 * @target_property: the property on @target to bind
 * @flags: flags to pass to #GBinding
 * @transform_to: a #GClosure wrapping the transformation function
 *   from the @source to the @target, or %NULL to use the default
 * @transform_from: a #GClosure wrapping the transformation function
 *   from the @target to the @source, or %NULL to use the default
 *
 * Creates a binding between @source_property on @source and @target_property
 * on @target, allowing you to set the transformation functions to be used by
 * the binding.
 *
 * This function is the language bindings friendly version of
 * g_object_bind_property_full(), using #GClosure<!-- -->s instead of
 * function pointers.
 *
 * Rename to: g_object_bind_property_full
 *
 * Return value: (transfer none): the #GBinding instance representing the
 *   binding between the two #GObject instances. The binding is released
 *   whenever the #GBinding reference count reaches zero.
 *
 * Since: 2.26
 */
GBinding *
g_object_bind_property_with_closures (gpointer       source,
                                      const gchar   *source_property,
                                      gpointer       target,
                                      const gchar   *target_property,
                                      GBindingFlags  flags,
                                      GClosure      *transform_to,
                                      GClosure      *transform_from)
{
  TransformData *data;

  data = g_slice_new0 (TransformData);

  if (transform_to != NULL)
    {
      if (G_CLOSURE_NEEDS_MARSHAL (transform_to))
        g_closure_set_marshal (transform_to, g_cclosure_marshal_BOOLEAN__BOXED_BOXED);

      data->transform_to_closure = g_closure_ref (transform_to);
      g_closure_sink (data->transform_to_closure);
    }

  if (transform_from != NULL)
    {
      if (G_CLOSURE_NEEDS_MARSHAL (transform_from))
        g_closure_set_marshal (transform_from, g_cclosure_marshal_BOOLEAN__BOXED_BOXED);

      data->transform_from_closure = g_closure_ref (transform_from);
      g_closure_sink (data->transform_from_closure);
    }

  return g_object_bind_property_full (source, source_property,
                                      target, target_property,
                                      flags,
                                      transform_to != NULL ? bind_with_closures_transform_to : NULL,
                                      transform_from != NULL ? bind_with_closures_transform_from : NULL,
                                      data,
                                      bind_with_closures_free_func);
}
Пример #15
0
/**
 * pyg_signal_class_closure_get:
 *
 * Returns the GClosure used for the class closure of signals.  When
 * called, it will invoke the method do_signalname (for the signal
 * "signalname").
 *
 * Returns: the closure.
 */
GClosure *
pyg_signal_class_closure_get(void)
{
    static GClosure *closure;

    if (closure == NULL) {
	closure = g_closure_new_simple(sizeof(GClosure), NULL);
	g_closure_set_marshal(closure, pyg_signal_class_closure_marshal);

	g_closure_ref(closure);
	g_closure_sink(closure);
    }
    return closure;
}
Пример #16
0
void
moo_plugin_method_newv (const char     *name,
                        GType           ptype,
                        GClosure       *closure,
                        GClosureMarshal c_marshaller,
                        GType           return_type,
                        guint           n_params,
                        const GType    *param_types)
{
    MooPluginMeth *m;
    GHashTable *meths;
    char *norm_name;

    g_return_if_fail (g_type_is_a (ptype, MOO_TYPE_PLUGIN));
    g_return_if_fail (name != NULL);
    g_return_if_fail (closure != NULL);
    g_return_if_fail (c_marshaller != NULL);
    g_return_if_fail (!n_params || param_types);

    norm_name = g_strdelimit (g_strdup (name), "_", '-');
    meths = g_type_get_qdata (ptype, MOO_PLUGIN_METHS_QUARK);

    if (meths)
    {
        if (g_hash_table_lookup (meths, norm_name) != NULL)
        {
            g_warning ("method '%s' is already registered for type '%s'",
                       name, g_type_name (ptype));
            g_free (norm_name);
            return;
        }
    }
    else
    {
        meths = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
                                       (GDestroyNotify) meth_free);
        g_type_set_qdata (ptype, MOO_PLUGIN_METHS_QUARK, meths);
    }

    m = g_new0 (MooPluginMeth, 1);
    m->ptype = ptype;
    m->return_type = return_type;
    m->n_params = n_params;
    m->param_types = n_params ? g_memdup (param_types, n_params * sizeof (GType)) : NULL;
    m->closure = g_closure_ref (closure);
    g_closure_sink (closure);
    g_closure_set_marshal (closure, c_marshaller);

    g_hash_table_insert (meths, norm_name, m);
}
Пример #17
0
/**
 * playerctl_player_on:
 * @self: an #PlayerctlPlayer
 * @event: the event to subscribe to
 * @callback: the callback to run on the event
 *
 * A convenience function for bindings to subscribe an event with a callback
 *
 * Returns: (transfer none): the #PlayerctlPlayer for chaining
 */
PlayerctlPlayer *playerctl_player_on(PlayerctlPlayer *self, const gchar *event, GClosure *callback, GError **err)
{
  GError *tmp_error = NULL;

  if (self->priv->init_error != NULL) {
    g_propagate_error(err, g_error_copy(self->priv->init_error));
    return self;
  }

  g_closure_ref(callback);
  g_closure_sink(callback);

  g_signal_connect_closure(self, event, callback, TRUE);

  return self;
}
Пример #18
0
static void
infobar_response_cb (GtkInfoBar *infobar, gint response, RBImportErrorsSource *source)
{
	char **details = NULL;
	GtkTreeIter iter;
	GClosure *closure;
	int i;

	/* gather plugin installer detail strings */
	if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (source->priv->missing_plugin_model), &iter) == FALSE) {
		return;
	}

	i = 0;
	do {
		RhythmDBEntry *entry;
		char **bits;
		int j;

		entry = rhythmdb_query_model_iter_to_entry (source->priv->missing_plugin_model, &iter);
		bits = g_strsplit (rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_COMMENT), "\n", 0);

		for (j = 0; bits[j] != NULL; j++) {
			if (rb_str_in_strv (bits[j], (const char **)details) == FALSE) {
				details = g_realloc (details, sizeof (char *) * i+2);
				details[i++] = g_strdup (bits[j]);
				details[i] = NULL;
			}
		}

		g_strfreev (bits);
	} while (gtk_tree_model_iter_next (GTK_TREE_MODEL (source->priv->missing_plugin_model), &iter));

	/* run the installer */
	closure = g_cclosure_new ((GCallback) missing_plugins_retry_cb,
				  g_object_ref (source),
				  (GClosureNotify) missing_plugins_retry_cleanup);
	g_closure_set_marshal (closure, g_cclosure_marshal_VOID__BOOLEAN);
	if (rb_missing_plugins_install ((const char **)details, TRUE, closure) == TRUE) {
		/* disable the button while the installer is running */
		gtk_info_bar_set_response_sensitive (infobar, response, FALSE);
	}
	g_closure_sink (closure);

	g_strfreev (details);
}
Пример #19
0
/**
 * clutter_binding_pool_install_action:
 * @pool: a #ClutterBindingPool
 * @action_name: the name of the action
 * @key_val: key symbol
 * @modifiers: bitmask of modifiers
 * @callback: (type Clutter.BindingActionFunc): function to be called
 *   when the action is activated
 * @data: data to be passed to @callback
 * @notify: function to be called when the action is removed
 *   from the pool
 *
 * Installs a new action inside a #ClutterBindingPool. The action
 * is bound to @key_val and @modifiers.
 *
 * The same action name can be used for multiple @key_val, @modifiers
 * pairs.
 *
 * When an action has been activated using clutter_binding_pool_activate()
 * the passed @callback will be invoked (with @data).
 *
 * Actions can be blocked with clutter_binding_pool_block_action()
 * and then unblocked using clutter_binding_pool_unblock_action().
 *
 * Since: 1.0
 */
void
clutter_binding_pool_install_action (ClutterBindingPool  *pool,
                                     const gchar         *action_name,
                                     guint                key_val,
                                     ClutterModifierType  modifiers,
                                     GCallback            callback,
                                     gpointer             data,
                                     GDestroyNotify       notify)
{
  ClutterBindingEntry *entry;
  GClosure *closure;

  g_return_if_fail (pool != NULL);
  g_return_if_fail (action_name != NULL);
  g_return_if_fail (key_val != 0);
  g_return_if_fail (callback != NULL);

  entry = binding_pool_lookup_entry (pool, key_val, modifiers);
  if (G_UNLIKELY (entry))
    {
      g_warning ("There already is an action '%s' for the given "
                 "key symbol of %d (modifiers: %d) installed inside "
                 "the binding pool.",
                 entry->name,
                 entry->key_val, entry->modifiers);
      return;
    }
  else
    entry = binding_entry_new (action_name, key_val, modifiers);

  closure = g_cclosure_new (callback, data, (GClosureNotify) notify);
  entry->closure = g_closure_ref (closure);
  g_closure_sink (closure);

  if (G_CLOSURE_NEEDS_MARSHAL (closure))
    {
      GClosureMarshal marshal;

      marshal = _clutter_marshal_BOOLEAN__STRING_UINT_FLAGS;
      g_closure_set_marshal (closure, marshal);
    }

  pool->entries = g_slist_prepend (pool->entries, entry);
  g_hash_table_insert (pool->entries_hash, entry, entry);
}
Пример #20
0
static JSBool
gjs_timeout_add(JSContext *context,
                   JSObject  *obj,
                   uintN      argc,
                   jsval     *argv,
                   jsval     *retval)
{
    GClosure *closure;
    JSObject *callback;
    guint32 interval;
    guint id;

    /* Best I can tell, there is no way to know if argv[1] is really
     * callable other than to just try it. Checking whether it's a
     * function will not detect native objects that provide
     * JSClass::call, for example.
     */
    if (!gjs_parse_args(context, "timeout_add", "uo", argc, argv,
                        "interval", &interval, "callback", &callback))
      return JS_FALSE;

    closure = gjs_closure_new(context, callback, "timeout");
    if (closure == NULL)
        return JS_FALSE;

    g_closure_ref(closure);
    g_closure_sink(closure);

    id = g_timeout_add_full(G_PRIORITY_DEFAULT,
                            interval,
                            closure_source_func,
                            closure,
                            closure_destroy_notify);

    /* this is needed to remove the timeout if the JSContext is
     * destroyed.
     */
    g_closure_add_invalidate_notifier(closure, GUINT_TO_POINTER(id),
                                      closure_invalidated);

    if (!JS_NewNumberValue(context, id, retval))
        return JS_FALSE;

    return JS_TRUE;
}
Пример #21
0
/**
 * clutter_binding_pool_override_action:
 * @pool: a #ClutterBindingPool
 * @key_val: key symbol
 * @modifiers: bitmask of modifiers
 * @callback: (type Clutter.BindingActionFunc): function to be called when the action is activated
 * @data: data to be passed to @callback
 * @notify: function to be called when the action is removed
 *   from the pool
 *
 * Allows overriding the action for @key_val and @modifiers inside a
 * #ClutterBindingPool. See clutter_binding_pool_install_action().
 *
 * When an action has been activated using clutter_binding_pool_activate()
 * the passed @callback will be invoked (with @data).
 *
 * Actions can be blocked with clutter_binding_pool_block_action()
 * and then unblocked using clutter_binding_pool_unblock_action().
 *
 * Since: 1.0
 */
void
clutter_binding_pool_override_action (ClutterBindingPool  *pool,
                                      guint                key_val,
                                      ClutterModifierType  modifiers,
                                      GCallback            callback,
                                      gpointer             data,
                                      GDestroyNotify       notify)
{
  ClutterBindingEntry *entry;
  GClosure *closure;

  g_return_if_fail (pool != NULL);
  g_return_if_fail (key_val != 0);
  g_return_if_fail (callback != NULL);

  entry = binding_pool_lookup_entry (pool, key_val, modifiers);
  if (G_UNLIKELY (entry == NULL))
    {
      g_warning ("There is no action for the given key symbol "
                 "of %d (modifiers: %d) installed inside the "
                 "binding pool.",
                 key_val, modifiers);
      return;
    }

  if (entry->closure)
    {
      g_closure_unref (entry->closure);
      entry->closure = NULL;
    }

  closure = g_cclosure_new (callback, data, (GClosureNotify) notify);
  entry->closure = g_closure_ref (closure);
  g_closure_sink (closure);

  if (G_CLOSURE_NEEDS_MARSHAL (closure))
    {
      GClosureMarshal marshal;

      marshal = _clutter_marshal_BOOLEAN__STRING_UINT_FLAGS;
      g_closure_set_marshal (closure, marshal);
    }
}
Пример #22
0
void
terminal_accels_init (void)
{
	guint i, j;

	settings_keybindings = g_settings_new (CONF_KEYS_SCHEMA);

	g_signal_connect (settings_keybindings,
			  "changed",
			  G_CALLBACK(keys_change_notify),
			  NULL);

	gsettings_key_to_entry = g_hash_table_new (g_str_hash, g_str_equal);

	notification_group = gtk_accel_group_new ();

	for (i = 0; i < G_N_ELEMENTS (all_entries); ++i)
	{
		for (j = 0; j < all_entries[i].n_elements; ++j)
		{
			KeyEntry *key_entry;

			key_entry = &(all_entries[i].key_entry[j]);

			g_hash_table_insert (gsettings_key_to_entry,
			                     (gpointer) key_entry->gsettings_key,
			                     key_entry);

			key_entry->closure = g_closure_new_simple (sizeof (GClosure), key_entry);

			g_closure_ref (key_entry->closure);
			g_closure_sink (key_entry->closure);

			gtk_accel_group_connect_by_path (notification_group,
			                                 I_(key_entry->accel_path),
			                                 key_entry->closure);
			keys_change_notify (settings_keybindings, key_entry->gsettings_key, NULL);
		}
	}

	g_signal_connect (notification_group, "accel-changed",
	                  G_CALLBACK (accel_changed_callback), NULL);
}
Пример #23
0
/**
 * g_source_set_closure:
 * @source: the source
 * @closure: a #GClosure
 *
 * Set the callback for a source as a #GClosure.
 *
 * If the source is not one of the standard GLib types, the @closure_callback
 * and @closure_marshal fields of the #GSourceFuncs structure must have been
 * filled in with pointers to appropriate functions.
 */
void
g_source_set_closure (GSource  *source,
		      GClosure *closure)
{
  g_return_if_fail (source != NULL);
  g_return_if_fail (closure != NULL);

  if (!source->source_funcs->closure_callback &&
#ifdef G_OS_UNIX
      source->source_funcs != &g_unix_fd_source_funcs &&
      source->source_funcs != &g_unix_signal_funcs &&
#endif
      source->source_funcs != &g_child_watch_funcs &&
      source->source_funcs != &g_io_watch_funcs &&
      source->source_funcs != &g_timeout_funcs &&
      source->source_funcs != &g_idle_funcs)
    {
      g_critical (G_STRLOC ": closure cannot be set on GSource without GSourceFuncs::closure_callback\n");
      return;
    }

  g_closure_ref (closure);
  g_closure_sink (closure);
  g_source_set_callback_indirect (source, closure, &closure_callback_funcs);

  g_closure_add_invalidate_notifier (closure, source, closure_invalidated);

  if (G_CLOSURE_NEEDS_MARSHAL (closure))
    {
      GClosureMarshal marshal = (GClosureMarshal)source->source_funcs->closure_marshal;
      if (marshal)
	g_closure_set_marshal (closure, marshal);
      else if (source->source_funcs == &g_idle_funcs ||
#ifdef G_OS_UNIX
               source->source_funcs == &g_unix_signal_funcs ||
#endif
               source->source_funcs == &g_timeout_funcs)
	g_closure_set_marshal (closure, source_closure_marshal_BOOLEAN__VOID);
      else
        g_closure_set_marshal (closure, g_cclosure_marshal_generic);
    }
}
Пример #24
0
static void
gtk_action_init (GtkAction *action)
{
  action->private_data = G_TYPE_INSTANCE_GET_PRIVATE (action,
                                                      GTK_TYPE_ACTION,
                                                      GtkActionPrivate);

  action->private_data->name = NULL;
  action->private_data->label = NULL;
  action->private_data->short_label = NULL;
  action->private_data->tooltip = NULL;
  action->private_data->stock_id = NULL;
  action->private_data->icon_name = NULL;
  action->private_data->visible_horizontal = TRUE;
  action->private_data->visible_vertical   = TRUE;
  action->private_data->visible_overflown  = TRUE;
  action->private_data->is_important = FALSE;
  action->private_data->hide_if_empty = TRUE;
  action->private_data->always_show_image = FALSE;
  action->private_data->activate_blocked = FALSE;

  action->private_data->sensitive = TRUE;
  action->private_data->visible = TRUE;

  action->private_data->label_set = FALSE;
  action->private_data->short_label_set = FALSE;

  action->private_data->accel_count = 0;
  action->private_data->accel_group = NULL;
  action->private_data->accel_quark = 0;
  action->private_data->accel_closure = 
    g_closure_new_object (sizeof (GClosure), G_OBJECT (action));
  g_closure_set_marshal (action->private_data->accel_closure, 
			 closure_accel_activate);
  g_closure_ref (action->private_data->accel_closure);
  g_closure_sink (action->private_data->accel_closure);

  action->private_data->action_group = NULL;

  action->private_data->proxies = NULL;
  action->private_data->gicon = NULL;  
}
Пример #25
0
static JSBool
gjs_timeout_add_seconds(JSContext *context,
                           JSObject  *obj,
                           uintN      argc,
                           jsval     *argv,
                           jsval     *retval)
{
    GClosure *closure;
    JSObject *callback;
    guint32 interval;
    guint id;

    /* See comment for timeout_add above */
    if (!gjs_parse_args(context, "timeout_add_seconds", "uo", argc, argv,
                        "interval", &interval, "callback", &callback))
      return JS_FALSE;

    closure = gjs_closure_new(context, callback, "timeout_seconds");
    if (closure == NULL)
        return JS_FALSE;

    g_closure_ref(closure);
    g_closure_sink(closure);

    id = g_timeout_add_seconds_full(G_PRIORITY_DEFAULT,
                                    interval,
                                    closure_source_func,
                                    closure,
                                    closure_destroy_notify);

    /* this is needed to remove the timeout if the JSContext is
     * destroyed.
     */
    g_closure_add_invalidate_notifier(closure, GUINT_TO_POINTER(id),
                                      closure_invalidated);

    if (!JS_NewNumberValue(context, id, retval))
        return JS_FALSE;

    return JS_TRUE;
}
Пример #26
0
/**
 * e_soup_ssl_trust_connect:
 * @soup_message: a #SoupMessage about to be sent to the source
 * @source: an #ESource that uses WebDAV
 *
 * Sets up automatic SSL certificate trust handling for @soup_message using the trust
 * data stored in @source's WebDAV extension. If @soup_message is about to be sent on
 * an SSL connection with an invalid certificate, the code checks if the WebDAV
 * extension already has a trust response for that certificate and verifies it
 * with e_source_webdav_verify_ssl_trust(). If the verification fails, then
 * the @soup_message send also fails.
 *
 * This works by connecting to the "network-event" signal on @soup_message and
 * connecting to the "accept-certificate" signal on each #GTlsConnection for
 * which @soup_message reports a #G_SOCKET_CLIENT_TLS_HANDSHAKING event. These
 * handlers are torn down automatically when @soup_message is disposed. This process
 * is not thread-safe; it is sufficient for safety if all use of @soup_message's
 * session and the disposal of @soup_message occur in the same thread.
 *
 * Since: 3.16
 **/
void
e_soup_ssl_trust_connect (SoupMessage *soup_message,
                          ESource *source)
{
	ESoupSslTrustData *handler;

	g_return_if_fail (SOUP_IS_MESSAGE (soup_message));
	g_return_if_fail (E_IS_SOURCE (source));

	handler = g_malloc (sizeof (ESoupSslTrustData));
	handler->soup_message = soup_message;
	g_object_weak_ref (G_OBJECT (soup_message), e_soup_ssl_trust_message_finalized_cb, handler);
	handler->source = g_object_ref (source);
	handler->accept_certificate_closure = g_cclosure_new (G_CALLBACK (e_soup_ssl_trust_accept_certificate_cb), handler, NULL);

	g_closure_ref (handler->accept_certificate_closure);
	g_closure_sink (handler->accept_certificate_closure);

	g_signal_connect (
		soup_message, "network-event",
		G_CALLBACK (e_soup_ssl_trust_network_event_cb), handler);
}
static gboolean
emit_status_changed (RhythmDBImportJob *job)
{
	g_mutex_lock (&job->priv->lock);
	job->priv->status_changed_id = 0;

	rb_debug ("emitting status changed: %d/%d", job->priv->imported, job->priv->total);
	g_signal_emit (job, signals[STATUS_CHANGED], 0, job->priv->total, job->priv->imported);

	/* temporary ref while emitting this signal as we're expecting the caller
	 * to release the final reference there.
	 */
	g_object_ref (job);
	if (job->priv->scan_complete && job->priv->imported >= job->priv->total) {

		if (job->priv->retry_entries != NULL && job->priv->retried == FALSE) {
			gboolean processing = FALSE;
			char **details = NULL;
			GClosure *retry;
			GSList *l;
			int i;

			/* gather missing plugin details etc. */
			i = 0;
			for (l = job->priv->retry_entries; l != NULL; l = l->next) {
				RhythmDBEntry *entry;
				char **bits;
				int j;

				entry = (RhythmDBEntry *)l->data;
				bits = g_strsplit (rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_COMMENT), "\n", 0);
				for (j = 0; bits[j] != NULL; j++) {
					if (rb_str_in_strv (bits[j], (const char **)details) == FALSE) {
						details = g_realloc (details, sizeof (char *) * (i+2));
						details[i++] = g_strdup (bits[j]);
						details[i] = NULL;
					}
				}
				g_strfreev (bits);
			}

			retry = g_cclosure_new ((GCallback) missing_plugins_retry_cb,
						g_object_ref (job),
						(GClosureNotify)g_object_unref);
			g_closure_set_marshal (retry, g_cclosure_marshal_VOID__BOOLEAN);

			processing = rb_missing_plugins_install ((const char **)details, FALSE, retry);
			g_strfreev (details);
			if (processing) {
				rb_debug ("plugin installation is in progress");
			} else {
				rb_debug ("no plugin installation attempted; job complete");
				g_signal_emit (job, signals[COMPLETE], 0, job->priv->total);
			}
			g_closure_sink (retry);
		} else {
			rb_debug ("emitting job complete");
			g_signal_emit (job, signals[COMPLETE], 0, job->priv->total);
		}
	}
	g_mutex_unlock (&job->priv->lock);
	g_object_unref (job);

	return FALSE;
}
Пример #28
0
void dt_lua_do_chunk_async_internal(const char * call_function, int line, lua_CFunction pusher,dt_lua_async_call_arg_type arg_type,...)
{
#ifdef _DEBUG
  dt_print(DT_DEBUG_LUA,"LUA DEBUG : %s called from %s %d\n",__FUNCTION__,call_function,line);
#endif
  dt_job_t *job = dt_control_job_create(&async_callback_job, "lua: async call");
  if(job)
  {
    async_call_data*data = malloc(sizeof(async_call_data));
    data->pusher = pusher;
    data->extra=NULL;
    va_list ap;
    va_start(ap,arg_type);
    dt_lua_async_call_arg_type cur_type = arg_type;
    while(cur_type != LUA_ASYNC_DONE){
      data->extra=g_list_append(data->extra,GINT_TO_POINTER(cur_type));
      switch(cur_type) {
        case LUA_ASYNC_TYPEID:
          data->extra=g_list_append(data->extra,GINT_TO_POINTER(va_arg(ap,luaA_Type)));
          data->extra=g_list_append(data->extra,va_arg(ap,gpointer));
          break;
        case LUA_ASYNC_TYPEID_WITH_FREE:
          {
            data->extra=g_list_append(data->extra,GINT_TO_POINTER(va_arg(ap,luaA_Type)));
            data->extra=g_list_append(data->extra,va_arg(ap,gpointer));
            GClosure* closure = va_arg(ap,GClosure*);
            g_closure_ref (closure);
            g_closure_sink (closure);
            g_closure_set_marshal(closure, g_cclosure_marshal_generic);
            data->extra=g_list_append(data->extra,closure);
          }
          break;
        case LUA_ASYNC_TYPENAME:
          data->extra=g_list_append(data->extra,va_arg(ap,char *));
          data->extra=g_list_append(data->extra,va_arg(ap,gpointer));
          break;
        case LUA_ASYNC_TYPENAME_WITH_FREE:
          {
            data->extra=g_list_append(data->extra,va_arg(ap,char *));
            data->extra=g_list_append(data->extra,va_arg(ap,gpointer));
            GClosure* closure = va_arg(ap,GClosure*);
            g_closure_ref (closure);
            g_closure_sink (closure);
            g_closure_set_marshal(closure, g_cclosure_marshal_generic);
            data->extra=g_list_append(data->extra,closure);
          }
          break;
        default:
          // should never happen
          g_assert(false);
          break;
      }
      cur_type = va_arg(ap,dt_lua_async_call_arg_type);

    }
    va_end(ap);
    
    dt_control_job_set_params(job, data, async_callback_job_destructor);
    dt_control_add_job(darktable.control, DT_JOB_QUEUE_USER_FG, job);
  }
}
static void
missing_encoder_response_cb (GtkDialog *dialog, gint response, RBTrackTransferQueue *queue)
{
	GClosure *retry;
	GstEncodingTarget *target;
	GPtrArray *details;
	GList *profiles;
	const GList *l;
	RBEncoder *encoder;

	switch (response) {
	case GTK_RESPONSE_YES:
		/* 'continue' -> start the batch */
		rb_debug ("starting batch regardless of missing plugins");
		actually_start_batch (queue);
		break;

	case GTK_RESPONSE_CANCEL:
	case GTK_RESPONSE_DELETE_EVENT:
		/* 'cancel' -> cancel the batch and start the next one */
		rb_debug ("cancelling batch");
		_rb_track_transfer_batch_cancel (queue->priv->current);
		g_object_unref (queue->priv->current);
		queue->priv->current = NULL;

		start_next_batch (queue);
		break;

	case GTK_RESPONSE_ACCEPT:
		/* 'install plugins' -> try to install encoder/muxer */

		/* get profiles that need plugins installed */
		profiles = NULL;
		encoder = rb_encoder_new ();
		g_object_get (queue->priv->current, "encoding-target", &target, NULL);
		for (l = gst_encoding_target_get_profiles (target); l != NULL; l = l->next) {
			GstEncodingProfile *profile = GST_ENCODING_PROFILE (l->data);
			char *profile_media_type;
			profile_media_type = rb_gst_encoding_profile_get_media_type (profile);
			if (profile_media_type != NULL &&
			    (rb_gst_media_type_is_lossless (profile_media_type) == FALSE) &&
			    rb_encoder_get_missing_plugins (encoder, profile, NULL, NULL)) {
				profiles = g_list_append (profiles, profile);
			}
			g_free (profile_media_type);
		}
		g_object_unref (encoder);
		g_object_unref (target);

		if (profiles == NULL) {
			rb_debug ("apparently we don't need any plugins any more");
			actually_start_batch (queue);
			break;
		}

		rb_debug ("attempting plugin installation");
		details = get_missing_plugin_strings (profiles, FALSE);
		retry = g_cclosure_new ((GCallback) missing_plugins_retry_cb,
					g_object_ref (queue),
					(GClosureNotify) g_object_unref);
		g_closure_set_marshal (retry, g_cclosure_marshal_VOID__BOOLEAN);
		if (rb_missing_plugins_install ((const char **)details->pdata, FALSE, retry)) {
			rb_debug ("attempting to install missing plugins for transcoding");
		} else {
			rb_debug ("proceeding without the missing plugins for transcoding");
			actually_start_batch (queue);
		}

		g_closure_sink (retry);
		g_ptr_array_free (details, TRUE);
		g_list_free (profiles);
		break;

	default:
		g_assert_not_reached ();
	}

	gtk_widget_destroy (GTK_WIDGET (dialog));
}
Пример #30
0
static void
thunar_uca_provider_activated (ThunarUcaProvider *uca_provider,
                               GtkAction         *action)
{
  GtkTreeRowReference *row;
  ThunarUcaContext    *uca_context;
  GtkTreePath         *path;
  GtkTreeIter          iter;
  GtkWidget           *dialog;
  GtkWidget           *window;
  gboolean             succeed;
  GError              *error = NULL;
  GList               *files;
  gchar              **argv;
  gchar               *working_directory = NULL;
  gchar               *filename;
  gchar               *label;
  gchar               *uri;
  gint                 argc;
  gchar               *icon_name = NULL;
  gboolean             startup_notify;
  GClosure            *child_watch;

  g_return_if_fail (THUNAR_UCA_IS_PROVIDER (uca_provider));
  g_return_if_fail (GTK_IS_ACTION (action));

  /* check if the row reference is still valid */
  row = g_object_get_qdata (G_OBJECT (action), thunar_uca_row_quark);
  if (G_UNLIKELY (!gtk_tree_row_reference_valid (row)))
    return;

  /* determine the iterator for the item */
  path = gtk_tree_row_reference_get_path (row);
  gtk_tree_model_get_iter (GTK_TREE_MODEL (uca_provider->model), &iter, path);
  gtk_tree_path_free (path);

  /* determine the files and the window for the action */
  uca_context = g_object_get_qdata (G_OBJECT (action), thunar_uca_context_quark);
  window = thunar_uca_context_get_window (uca_context);
  files = thunar_uca_context_get_files (uca_context);

  /* determine the argc/argv for the item */
  succeed = thunar_uca_model_parse_argv (uca_provider->model, &iter, files, &argc, &argv, &error);
  if (G_LIKELY (succeed))
    {
      /* get the icon name and whether startup notification is active */
      gtk_tree_model_get (GTK_TREE_MODEL (uca_provider->model), &iter,
                          THUNAR_UCA_MODEL_COLUMN_ICON, &icon_name,
                          THUNAR_UCA_MODEL_COLUMN_STARTUP_NOTIFY, &startup_notify,
                          -1);

      /* determine the working from the first file */
      if (G_LIKELY (files != NULL))
        {
          /* determine the filename of the first selected file */
          uri = thunarx_file_info_get_uri (files->data);
          filename = g_filename_from_uri (uri, NULL, NULL);
          if (G_LIKELY (filename != NULL))
            {
              /* if this is a folder action, we just use the filename as working directory */
              if (g_object_get_qdata (G_OBJECT (action), thunar_uca_folder_quark) != NULL)
                {
                  working_directory = filename;
                  filename = NULL;
                }
              else
                {
                  working_directory = g_path_get_dirname (filename);
                }
            }
          g_free (filename);
          g_free (uri);
        }

      /* build closre for child watch */
      child_watch = g_cclosure_new_swap (G_CALLBACK (thunar_uca_provider_child_watch),
                                         uca_provider, thunar_uca_provider_child_watch_destroy);
      g_closure_ref (child_watch);
      g_closure_sink (child_watch);

      /* spawn the command on the window's screen */
      succeed = xfce_spawn_on_screen_with_child_watch (gtk_widget_get_screen (GTK_WIDGET (window)),
                                                       working_directory, argv, NULL,
                                                       G_SPAWN_SEARCH_PATH,
                                                       startup_notify,
                                                       gtk_get_current_event_time (),
                                                       icon_name,
                                                       child_watch,
                                                       &error);

      /* check if we succeed */
      if (G_LIKELY (succeed))
        {
          /* release existing child watch */
          thunar_uca_provider_child_watch_destroy (uca_provider, NULL);

          /* set new closure */
          uca_provider->child_watch = child_watch;

          /* take over ownership of the working directory as child watch path */
          uca_provider->child_watch_path = working_directory;
          working_directory = NULL;
        }
      else
        {
          /* spawn failed, release watch */
          g_closure_unref (child_watch);
        }

      /* cleanup */
      g_free (working_directory);
      g_strfreev (argv);
      g_free (icon_name);
    }

  /* present error message to the user */
  if (G_UNLIKELY (!succeed))
    {
      g_object_get (G_OBJECT (action), "label", &label, NULL);
      dialog = gtk_message_dialog_new ((GtkWindow *) window,
                                       GTK_DIALOG_DESTROY_WITH_PARENT
                                       | GTK_DIALOG_MODAL,
                                       GTK_MESSAGE_ERROR,
                                       GTK_BUTTONS_CLOSE,
                                       _("Failed to launch action \"%s\"."), label);
      gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s.", error->message);
      gtk_dialog_run (GTK_DIALOG (dialog));
      gtk_widget_destroy (dialog);
      g_error_free (error);
      g_free (label);
    }
}