Ejemplo n.º 1
0
Archivo: shared.c Proyecto: vifino/dwb
JSObjectRef 
make_object_for_class(JSContextRef ctx, int iclass, GObject *o, gboolean protect)
{
    ScriptContext *sctx = scripts_get_context();
    if (sctx == NULL) 
        return JSValueToObject(ctx, NIL, NULL);

    JSObjectRef retobj = g_object_get_qdata(o, sctx->ref_quark);
    if (retobj != NULL) {
        goto finish;
    }

    retobj = JSObjectMake(ctx, sctx->classes[iclass], o);
    if (protect) 
    {
        g_object_set_qdata_full(o, sctx->ref_quark, retobj, (GDestroyNotify)object_destroy_cb);
        JSValueProtect(ctx, retobj);
    }
    else 
        g_object_set_qdata_full(o, sctx->ref_quark, retobj, NULL);

finish:
    scripts_release_context();
    return retobj;
}
Ejemplo n.º 2
0
/**
 * fm_dnd_set_dest_auto_scroll
 * @drag_dest_widget: a drag destination widget
 * @hadj: horizontal GtkAdjustment
 * @vadj: vertical GtkAdjustment
 *
 * This function installs a "drag-motion" handler to the dest widget
 * to support auto-scroll when the dragged item is near the margin
 * of the destination widget. For example, when a user drags an item
 * over the bottom of a GtkTreeView, the desired behavior should be
 * to scroll up the content of the tree view and to expose the items
 * below currently visible region. So the user can drop on them.
 */
void fm_dnd_set_dest_auto_scroll(GtkWidget* drag_dest_widget,
                                 GtkAdjustment* hadj, GtkAdjustment* vadj)
{
    FmDndAutoScroll* as;
    if(G_UNLIKELY(data_id == 0))
        data_id = g_quark_from_static_string("FmDndAutoScroll");

    if(G_UNLIKELY(!hadj && !vadj))
    {
        g_object_set_qdata_full(G_OBJECT(drag_dest_widget), data_id, NULL, NULL);
        return;
    }

    as = g_slice_new(FmDndAutoScroll);
    as->widget = drag_dest_widget; /* no g_object_ref is needed here */
    as->timeout = 0;
    as->hadj = hadj ? GTK_ADJUSTMENT(g_object_ref(hadj)) : NULL;
    as->vadj = vadj ? GTK_ADJUSTMENT(g_object_ref(vadj)) : NULL;

    g_object_set_qdata_full(G_OBJECT(drag_dest_widget), data_id,
                            as, fm_dnd_auto_scroll_free);

    g_signal_connect(drag_dest_widget, "drag-motion",
                     G_CALLBACK(on_drag_motion), as);
    g_signal_connect(drag_dest_widget, "drag-leave",
                     G_CALLBACK(on_drag_leave), as);
}
Ejemplo n.º 3
0
GtkWidget *sphinx_gui_list_new() {
	GtkCellRenderer *renderer;
	GtkTreeViewColumn *column;
	GtkTreeIter iter;
	GtkListStore *store = gtk_list_store_new(2, G_TYPE_STRING,
						G_TYPE_STRING);
	GtkTreeView *list = GTK_TREE_VIEW(gtk_tree_view_new_with_model(
			GTK_TREE_MODEL(store)));
	GtkTreeSelection *sel = gtk_tree_view_get_selection(list);
	gtk_tree_selection_set_mode(sel, GTK_SELECTION_SINGLE);

	list_load(store);

	column = gtk_tree_view_column_new();
	renderer = gtk_cell_renderer_text_new();
	g_object_set_qdata_full(G_OBJECT(renderer),
		g_quark_from_static_string("column"), (gpointer)0, NULL);
	g_object_set(G_OBJECT(renderer), "editable", TRUE, NULL);
	g_signal_connect(renderer, "edited", G_CALLBACK(list_edit), list);
	gtk_tree_view_insert_column_with_attributes(list, -1, "Phrase",
						renderer, "text", 0, NULL);

	column = gtk_tree_view_column_new();
	renderer = gtk_cell_renderer_text_new();
	g_object_set_qdata_full(G_OBJECT(renderer),
		g_quark_from_static_string("column"), (gpointer)1, NULL);
	g_object_set(G_OBJECT(renderer), "editable", TRUE, NULL);
	g_signal_connect(renderer, "edited", G_CALLBACK(list_edit), list),
	gtk_tree_view_insert_column_with_attributes(list, -1, "Command",
						renderer, "text", 1, NULL);

	return GTK_WIDGET(list);
}
Ejemplo n.º 4
0
/**
 * gdk_pixbuf_remove_option:
 * @pixbuf: a #GdkPixbuf
 * @key: a nul-terminated string representing the key to remove.
 *
 * Remove the key/value pair option attached to a #GdkPixbuf.
 *
 * Return value: %TRUE if an option was removed, %FALSE if not.
 *
 * Since: 2.36
 **/
gboolean
gdk_pixbuf_remove_option (GdkPixbuf   *pixbuf,
                          const gchar *key)
{
        GQuark  quark;
        gchar **options;
        guint n;
        GPtrArray *array;
        gboolean found;

        g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), FALSE);
        g_return_val_if_fail (key != NULL, FALSE);

        quark = g_quark_from_static_string ("gdk_pixbuf_options");

        options = g_object_get_qdata (G_OBJECT (pixbuf), quark);
        if (!options)
                return FALSE;

        g_object_steal_qdata (G_OBJECT (pixbuf), quark);

        /* There's at least a nul-terminator */
        array = g_ptr_array_new_full (1, g_free);

        found = FALSE;
        for (n = 0; options[2*n]; n++) {
                if (strcmp (options[2*n], key) != 0) {
                        g_ptr_array_add (array, g_strdup (options[2*n]));   /* key */
                        g_ptr_array_add (array, g_strdup (options[2*n+1])); /* value */
                } else {
                        found = TRUE;
                }
        }

        if (array->len == 0) {
                g_ptr_array_unref (array);
                g_strfreev (options);
                return found;
        }

        if (!found) {
                g_ptr_array_free (array, TRUE);
                g_object_set_qdata_full (G_OBJECT (pixbuf), quark,
                                         options, (GDestroyNotify) g_strfreev);
                return FALSE;
        }

        g_ptr_array_add (array, NULL);
        g_object_set_qdata_full (G_OBJECT (pixbuf), quark,
                                 g_ptr_array_free (array, FALSE), (GDestroyNotify) g_strfreev);
        g_strfreev (options);

        return TRUE;
}
Ejemplo n.º 5
0
static gboolean
pango_module_load (GTypeModule *module)
{
  PangoModule *pango_module = PANGO_MODULE (module);

  if (pango_module->path)
    {
      pango_module->library = g_module_open (pango_module->path, G_MODULE_BIND_LOCAL);
      if (!pango_module->library)
	{
	  GQuark warned_quark = get_warned_quark ();
	  if (!g_object_get_qdata (G_OBJECT (pango_module), warned_quark))
	    {
	      g_warning ("%s", g_module_error());
	      g_object_set_qdata_full (G_OBJECT (pango_module), warned_quark,
				       GINT_TO_POINTER (1), NULL);
	    }
	  return FALSE;
	}

      /* extract symbols from the lib */
      if (!g_module_symbol (pango_module->library, "script_engine_init",
			    (gpointer *)(void *)&pango_module->init) ||
	  !g_module_symbol (pango_module->library, "script_engine_exit",
			    (gpointer *)(void *)&pango_module->exit) ||
	  !g_module_symbol (pango_module->library, "script_engine_list",
			    (gpointer *)(void *)&pango_module->list) ||
	  !g_module_symbol (pango_module->library, "script_engine_create",
			    (gpointer *)(void *)&pango_module->create))
	{
	  GQuark warned_quark = get_warned_quark ();
	  if (!g_object_get_qdata (G_OBJECT (pango_module), warned_quark))
	    {
	      g_warning ("%s", g_module_error());
	      g_object_set_qdata_full (G_OBJECT (pango_module), warned_quark,
				       GINT_TO_POINTER (1), NULL);
	    }

	  g_module_close (pango_module->library);

	  return FALSE;
	}
    }

  /* call the module's init function to let it */
  /* setup anything it needs to set up. */
  pango_module->init (module);

  return TRUE;
}
Ejemplo n.º 6
0
/**
 * gs_file_enumerator_iterate:
 * @direnum: an open #GFileEnumerator
 * @out_info: (out) (transfer none) (allow-none): Output location for the next #GFileInfo
 * @out_child: (out) (transfer none) (allow-none): Output location for the next #GFile, or %NULL
 * @cancellable: a #GCancellable
 * @error: a #GError
 *
 * This is a version of g_file_enumerator_next_file() that's easier to
 * use correctly from C programs.  With g_file_enumerator_next_file(),
 * the gboolean return value signifies "end of iteration or error", which
 * requires allocation of a temporary #GError.
 *
 * In contrast, with this function, a %FALSE return from
 * gs_file_enumerator_iterate() <emphasis>always</emphasis> means
 * "error".  End of iteration is signaled by @out_info being %NULL.
 *
 * Another crucial difference is that the references for @out_info and
 * @out_child are owned by @direnum (they are cached as hidden
 * properties).  You must not unref them in your own code.  This makes
 * memory management significantly easier for C code in combination
 * with loops.
 *
 * Finally, this function optionally allows retrieving a #GFile as
 * well.
 *
 * The code pattern for correctly using gs_file_enumerator_iterate() from C
 * is:
 *
 * |[
 * direnum = g_file_enumerate_children (file, ...);
 * while (TRUE)
 *   {
 *     GFileInfo *info;
 *     if (!gs_file_enumerator_iterate (direnum, &info, NULL, cancellable, error))
 *       goto out;
 *     if (!info)
 *       break;
 *     ... do stuff with "info"; do not unref it! ...
 *   }
 *
 * out:
 *   g_object_unref (direnum); // Note: frees the last @info
 * ]|
 */
gboolean
gs_file_enumerator_iterate (GFileEnumerator  *direnum,
                            GFileInfo       **out_info,
                            GFile           **out_child,
                            GCancellable     *cancellable,
                            GError          **error)
{
    gboolean ret = FALSE;
    GError *temp_error = NULL;

    static GQuark cached_info_quark;
    static GQuark cached_child_quark;
    static gsize quarks_initialized;

    g_return_val_if_fail (direnum != NULL, FALSE);
    g_return_val_if_fail (out_info != NULL, FALSE);

    if (g_once_init_enter (&quarks_initialized))
    {
        cached_info_quark = g_quark_from_static_string ("gsystem-cached-info");
        cached_child_quark = g_quark_from_static_string ("gsystem-cached-child");
        g_once_init_leave (&quarks_initialized, 1);
    }


    *out_info = g_file_enumerator_next_file (direnum, cancellable, &temp_error);
    if (out_child)
        *out_child = NULL;
    if (temp_error != NULL)
    {
        g_propagate_error (error, temp_error);
        goto out;
    }
    else if (*out_info != NULL)
    {
        g_object_set_qdata_full ((GObject*)direnum, cached_info_quark, *out_info, (GDestroyNotify)g_object_unref);
        if (out_child != NULL)
        {
            const char *name = g_file_info_get_name (*out_info);
            *out_child = g_file_get_child (g_file_enumerator_get_container (direnum), name);
            g_object_set_qdata_full ((GObject*)direnum, cached_child_quark, *out_child, (GDestroyNotify)g_object_unref);
        }
    }

    ret = TRUE;
out:
    return ret;
}
Ejemplo n.º 7
0
static void
kms_recorder_endpoint_stopped (KmsUriEndpoint * obj)
{
  KmsRecorderEndpoint *self = KMS_RECORDER_ENDPOINT (obj);

  if (self->priv->stopping) {
    return;
  }

  kms_recorder_endpoint_change_state (self, KMS_URI_ENDPOINT_STATE_STOP);

  if (kms_base_media_muxer_get_state (self->priv->mux) >= GST_STATE_PAUSED) {
    self->priv->stopping = TRUE;
    kms_recorder_endpoint_send_eos_to_appsrcs (self);
  }

  kms_recorder_endpoint_remove_pads (self);

  // Reset base time data
  BASE_TIME_LOCK (self);

  g_object_set_qdata_full (G_OBJECT (self), base_time_key_quark (), NULL, NULL);

  self->priv->paused_time = G_GUINT64_CONSTANT (0);
  self->priv->paused_start = GST_CLOCK_TIME_NONE;

  BASE_TIME_UNLOCK (self);

  if (kms_base_media_muxer_get_state (self->priv->mux) < GST_STATE_PAUSED &&
      !self->priv->stopping) {
    KMS_ELEMENT_UNLOCK (self);
    kms_base_media_muxer_set_state (self->priv->mux, GST_STATE_NULL);
    KMS_ELEMENT_LOCK (self);
  }
}
Ejemplo n.º 8
0
static GcrCertificateInfo*
certificate_info_load (GcrCertificate *cert)
{
	GcrCertificateInfo *info;
	GNode *asn1;
	gconstpointer der;
	gsize n_der;

	g_assert (GCR_IS_CERTIFICATE (cert));

	der = gcr_certificate_get_der_data (cert, &n_der);
	g_return_val_if_fail (der, NULL);

	info = g_object_get_qdata (G_OBJECT (cert), CERTIFICATE_INFO);
	if (info != NULL) {
		if (n_der == info->n_der && der == info->der)
			return info;
	}
	
	/* Cache is invalid or non existent */
	asn1 = egg_asn1x_create_and_decode (pkix_asn1_tab, "Certificate", der, n_der);
	if (asn1 == NULL) {
		g_warning ("a derived class provided an invalid or unparseable X.509 DER certificate data.");
		return NULL;
	}
	
	info = g_new0 (GcrCertificateInfo, 1);
	info->der = der;
	info->n_der = n_der;
	info->asn1 = asn1;

	g_object_set_qdata_full (G_OBJECT (cert), CERTIFICATE_INFO, info, certificate_info_free);
	return info;
}
Ejemplo n.º 9
0
void
fvkbd_gtk_ui_set_qdata(FvkbdGtkUI *ui, GQuark quark, gpointer data,
				GDestroyNotify destroy)
{
	g_return_if_fail(FVKBD_IS_GTK_UI(ui));
	g_object_set_qdata_full(G_OBJECT(ui), quark, data, destroy);
}
Ejemplo n.º 10
0
static void on_show_history_menu(GtkMenuToolButton* btn, FmMainWin* win)
{
    GtkMenuShell* menu = (GtkMenuShell*)gtk_menu_tool_button_get_menu(btn);
    GList* l;
    GList* cur = fm_nav_history_get_cur_link(win->nav_history);

    /* delete old items */
    gtk_container_foreach(GTK_CONTAINER(menu), (GtkCallback)gtk_widget_destroy, NULL);

    for(l = fm_nav_history_list(win->nav_history); l; l=l->next)
    {
        const FmNavHistoryItem* item = (FmNavHistoryItem*)l->data;
        FmPath* path = item->path;
        char* str = fm_path_display_name(path, TRUE);
        GtkMenuItem* mi;
        if( l == cur )
        {
            mi = gtk_check_menu_item_new_with_label(str);
            gtk_check_menu_item_set_draw_as_radio(GTK_CHECK_MENU_ITEM(mi), TRUE);
            gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(mi), TRUE);
        }
        else
            mi = gtk_menu_item_new_with_label(str);
        g_free(str);

        g_object_set_qdata_full(G_OBJECT(mi), fm_qdata_id, l, NULL);
        g_signal_connect(mi, "activate", G_CALLBACK(on_history_item), win);
        gtk_menu_shell_append(menu, mi);
    }
    gtk_widget_show_all( GTK_WIDGET(menu) );
}
Ejemplo n.º 11
0
GtkWidget *
terminal_search_dialog_new (GtkWindow   *parent)
{
  GtkWidget *dialog;
  TerminalSearchDialogPrivate *priv;
  GtkListStore *store;
  GtkEntryCompletion *completion;

  priv = g_new0 (TerminalSearchDialogPrivate, 1);

  if (!terminal_util_load_builder_file ("find-dialog.ui",
					"find-dialog", &dialog,
					"search-label", &priv->search_label,
					"search-entry", &priv->search_entry,
					"match-case-checkbutton", &priv->match_case_checkbutton,
					"entire-word-checkbutton", &priv->entire_word_checkbutton,
					"regex-checkbutton", &priv->regex_checkbutton,
					"search-backwards-checkbutton", &priv->backwards_checkbutton,
					"wrap-around-checkbutton", &priv->wrap_around_checkbutton,
					NULL))
  {
    g_free (priv);
    return NULL;
  }

  g_object_set_qdata_full (G_OBJECT (dialog), get_quark (), priv,
			   (GDestroyNotify) terminal_search_dialog_private_destroy);


  priv->search_text_entry = gtk_bin_get_child (GTK_BIN (priv->search_entry));
  gtk_widget_set_size_request (priv->search_entry, 300, -1);

  priv->store = store = gtk_list_store_new (1, G_TYPE_STRING);
  g_object_set (G_OBJECT (priv->search_entry),
		"model", store,
		"text-column", 0,
		NULL);

  priv->completion = completion = gtk_entry_completion_new ();
  gtk_entry_completion_set_model (completion, GTK_TREE_MODEL (store));
  gtk_entry_completion_set_text_column (completion, 0);
  gtk_entry_completion_set_minimum_key_length (completion, HISTORY_MIN_ITEM_LEN);
  gtk_entry_completion_set_popup_completion (completion, FALSE);
  gtk_entry_completion_set_inline_completion (completion, TRUE);
  gtk_entry_set_completion (GTK_ENTRY (priv->search_text_entry), completion);

  gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
  gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT, FALSE);

  gtk_entry_set_activates_default (GTK_ENTRY (priv->search_text_entry), TRUE);
  g_signal_connect (priv->search_text_entry, "changed", G_CALLBACK (update_sensitivity), dialog);
  g_signal_connect (priv->regex_checkbutton, "toggled", G_CALLBACK (update_sensitivity), dialog);

  g_signal_connect (dialog, "response", G_CALLBACK (response_handler), NULL);

  if (parent)
    gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);

  return GTK_WIDGET (dialog);
}
Ejemplo n.º 12
0
static GstPadStats *
get_pad_stats (GstStatsTracer * self, GstPad * pad)
{
  GstPadStats *stats;
  gboolean is_new = FALSE;

  if (!pad) {
    no_pad_stats.index = G_MAXUINT;
    return &no_pad_stats;
  }

  G_LOCK (_pad_stats);
  if (!(stats = g_object_get_qdata ((GObject *) pad, data_quark))) {
    stats = fill_pad_stats (self, pad);
    g_object_set_qdata_full ((GObject *) pad, data_quark, stats,
        free_pad_stats);
    is_new = TRUE;
  }
  G_UNLOCK (_pad_stats);
  if (G_UNLIKELY (stats->parent_ix == G_MAXUINT)) {
    GstElement *elem = get_real_pad_parent (pad);
    if (elem) {
      GstElementStats *elem_stats = get_element_stats (self, elem);

      stats->parent_ix = elem_stats->index;
    }
  }
  if (G_UNLIKELY (is_new)) {
    log_new_pad_stats (stats, pad);
  }
  return stats;
}
Ejemplo n.º 13
0
static inline ClutterLayoutMeta *
get_child_meta (ClutterLayoutManager *manager,
                ClutterContainer     *container,
                ClutterActor         *actor)
{
    ClutterLayoutMeta *layout = NULL;

    layout = g_object_get_qdata (G_OBJECT (actor), quark_layout_meta);
    if (layout != NULL)
    {
        ClutterChildMeta *child = CLUTTER_CHILD_META (layout);

        if (layout->manager == manager &&
                child->container == container &&
                child->actor == actor)
            return layout;

        /* if the LayoutMeta referenced is not attached to the
         * layout manager then we simply ask the layout manager
         * to replace it with the right one
         */
    }

    layout = create_child_meta (manager, container, actor);
    if (layout != NULL)
    {
        g_assert (CLUTTER_IS_LAYOUT_META (layout));
        g_object_set_qdata_full (G_OBJECT (actor), quark_layout_meta,
                                 layout,
                                 (GDestroyNotify) g_object_unref);
        return layout;
    }

    return NULL;
}
Ejemplo n.º 14
0
/* Returns a structure with information we will use to rendering given the
 * #PangoFont. This is computed once per font and cached for later retrieval.
 */
static ThaiFontInfo *
thai_get_font_info (PangoFont            *font,
		    const PangoOTRuleset *ruleset)
{
  ThaiFontInfo *font_info;
  static GQuark info_id = 0;
  
  if (G_UNLIKELY (!info_id))
    info_id = g_quark_from_string ("thai-font-info");

  font_info = g_object_get_qdata (G_OBJECT (font), info_id);

  if (G_UNLIKELY (!font_info))
    {
      /* No cached information not found, so we need to compute it
       * from scratch
       */
      font_info = g_new (ThaiFontInfo, 1);
      font_info->font = font;

      /* detect font set by determining availibility of OT ruleset & glyphs */
      if (pango_ot_ruleset_get_feature_count (ruleset, NULL, NULL))
	font_info->font_set = THAI_FONT_TIS;
      else if (contain_glyphs(font, tis620_2))
	font_info->font_set = THAI_FONT_TIS_WIN;
      else if (contain_glyphs(font, tis620_1))
	font_info->font_set = THAI_FONT_TIS_MAC;
      else
	font_info->font_set = THAI_FONT_TIS;

      g_object_set_qdata_full (G_OBJECT (font), info_id, font_info, (GDestroyNotify)g_free);
    }

  return font_info;
}
Ejemplo n.º 15
0
static void
kms_hub_port_start_media_type (KmsElement * self, KmsElementPadType type,
    GstPadTemplate * templ, const gchar * pad_name)
{
  GstElement *capsfilter = gst_element_factory_make ("capsfilter", NULL);
  GstPad *src = gst_element_get_static_pad (capsfilter, "src");
  GstPad *internal_src;

  gst_bin_add (GST_BIN (self), capsfilter);
  gst_element_sync_state_with_parent (capsfilter);

  internal_src = gst_ghost_pad_new_from_template (pad_name, src, templ);

  g_object_set_qdata_full (G_OBJECT (internal_src), key_elem_data_quark (),
      g_object_ref (capsfilter), g_object_unref);
  g_object_set_qdata (G_OBJECT (internal_src), key_type_data_quark (),
      GINT_TO_POINTER (type));

  g_signal_connect (internal_src, "linked",
      G_CALLBACK (kms_hub_port_internal_src_pad_linked), NULL);

  if (GST_STATE (self) >= GST_STATE_PAUSED
      || GST_STATE_PENDING (self) >= GST_STATE_PAUSED
      || GST_STATE_TARGET (self) >= GST_STATE_PAUSED) {
    gst_pad_set_active (internal_src, TRUE);
  }

  gst_element_add_pad (GST_ELEMENT (self), internal_src);
  g_object_unref (src);
}
Ejemplo n.º 16
0
static void
kms_hub_port_internal_src_pad_linked (GstPad * pad, GstPad * peer,
    gpointer data)
{
  GstPad *target, *new_pad;
  GstElement *capsfilter;
  KmsElement *self;
  KmsElementPadType type;

  capsfilter = g_object_get_qdata (G_OBJECT (pad), key_elem_data_quark ());
  g_return_if_fail (capsfilter);
  self = KMS_ELEMENT (gst_object_get_parent (GST_OBJECT (capsfilter)));
  g_return_if_fail (self);

  target = gst_element_get_static_pad (capsfilter, "sink");
  if (!target) {
    GST_WARNING_OBJECT (pad, "No sink in capsfilter");
    goto end;
  }

  type =
      GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (pad),
          key_type_data_quark ()));
  new_pad = kms_element_connect_sink_target (self, target, type);
  g_object_unref (target);
  g_object_set_qdata_full (G_OBJECT (pad), key_pad_data_quark (),
      g_object_ref (new_pad), g_object_unref);

end:
  g_object_unref (self);
}
Ejemplo n.º 17
0
/**
 * gtk_text_buffer_register_serialize_format:
 * @buffer: a #GtkTextBuffer
 * @mime_type: the format's mime-type
 * @function: the serialize function to register
 * @user_data: %function's user_data
 * @user_data_destroy: a function to call when @user_data is no longer needed
 *
 * This function registers a rich text serialization @function along with
 * its @mime_type with the passed @buffer.
 *
 * Return value: (transfer none): the #GdkAtom that corresponds to the
 *               newly registered format's mime-type.
 *
 * Since: 2.10
 **/
GdkAtom
gtk_text_buffer_register_serialize_format (GtkTextBuffer              *buffer,
                                           const gchar                *mime_type,
                                           GtkTextBufferSerializeFunc  function,
                                           gpointer                    user_data,
                                           GDestroyNotify              user_data_destroy)
{
  GList   *formats;
  GdkAtom  atom;

  g_return_val_if_fail (GTK_IS_TEXT_BUFFER (buffer), GDK_NONE);
  g_return_val_if_fail (mime_type != NULL && *mime_type != '\0', GDK_NONE);
  g_return_val_if_fail (function != NULL, GDK_NONE);

  formats = g_object_steal_qdata (G_OBJECT (buffer), serialize_quark ());

  formats = register_format (formats, mime_type,
                             (gpointer) function,
                             user_data, user_data_destroy,
                             &atom);

  g_object_set_qdata_full (G_OBJECT (buffer), serialize_quark (),
                           formats, (GDestroyNotify) free_format_list);

  g_object_notify (G_OBJECT (buffer), "copy-target-list");

  return atom;
}
Ejemplo n.º 18
0
static gboolean
accept_ready (GSocket      *accept_socket,
	      GIOCondition  condition,
	      gpointer      user_data)
{
  GTask *task = user_data;
  GError *error = NULL;
  GSocket *socket;
  GObject *source_object;

  socket = g_socket_accept (accept_socket, g_task_get_cancellable (task), &error);
  if (socket)
    {
      source_object = g_object_get_qdata (G_OBJECT (accept_socket), source_quark);
      if (source_object)
	g_object_set_qdata_full (G_OBJECT (task),
				 source_quark,
				 g_object_ref (source_object), g_object_unref);
      g_task_return_pointer (task, socket, g_object_unref);
    }
  else
    {
      g_task_return_error (task, error);
    }

  g_object_unref (task);
  return FALSE;
}
Ejemplo n.º 19
0
/**
 * g_socket_listener_add_socket:
 * @listener: a #GSocketListener
 * @socket: a listening #GSocket
 * @source_object: (allow-none): Optional #GObject identifying this source
 * @error: #GError for error reporting, or %NULL to ignore.
 *
 * Adds @socket to the set of sockets that we try to accept
 * new clients from. The socket must be bound to a local
 * address and listened to.
 *
 * @source_object will be passed out in the various calls
 * to accept to identify this particular source, which is
 * useful if you're listening on multiple addresses and do
 * different things depending on what address is connected to.
 *
 * Returns: %TRUE on success, %FALSE on error.
 *
 * Since: 2.22
 */
gboolean
g_socket_listener_add_socket (GSocketListener  *listener,
			      GSocket          *socket,
			      GObject          *source_object,
			      GError          **error)
{
  if (!check_listener (listener, error))
    return FALSE;

  /* TODO: Check that socket it is bound & not closed? */

  if (g_socket_is_closed (socket))
    {
      g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
			   _("Added socket is closed"));
      return FALSE;
    }

  g_object_ref (socket);
  g_ptr_array_add (listener->priv->sockets, socket);

  if (source_object)
    g_object_set_qdata_full (G_OBJECT (socket), source_quark,
			     g_object_ref (source_object), g_object_unref);


  if (G_SOCKET_LISTENER_GET_CLASS (listener)->changed)
    G_SOCKET_LISTENER_GET_CLASS (listener)->changed (listener);

  return TRUE;
}
Ejemplo n.º 20
0
/**
 * cogl_pango_font_map_get_renderer:
 * @fm: a #CoglPangoFontMap
 *
 * Retrieves the #CoglPangoRenderer for the passed font map.
 *
 * Return value: a #PangoRenderer
 *
 * Since: 1.0
 */
PangoRenderer *
cogl_pango_font_map_get_renderer (CoglPangoFontMap *fm)
{
  PangoRenderer *renderer;

  g_return_val_if_fail (COGL_PANGO_IS_FONT_MAP (fm), NULL);

  /* We want to keep a cached pointer to the renderer from the font
     map instance but as we don't have a proper subclass we have to
     store it in the object data instead */

  renderer = g_object_get_qdata (G_OBJECT (fm),
				 cogl_pango_font_map_get_renderer_key ());

  if (G_UNLIKELY (renderer == NULL))
    {
      renderer = g_object_new (COGL_PANGO_TYPE_RENDERER, NULL);
      g_object_set_qdata_full (G_OBJECT (fm),
			       cogl_pango_font_map_get_renderer_key (),
			       renderer,
			       g_object_unref);
    }

  return renderer;
}
static void clone_set_info(MetaDeepinClonedWidget* w, gpointer data)
{
    if (!_cloned_widget_key_quark) {
        _cloned_widget_key_quark = g_quark_from_static_string("cloned-widget-key");
    }
    g_object_set_qdata_full(G_OBJECT(w), _cloned_widget_key_quark, data, g_free);
}
Ejemplo n.º 22
0
/**
 * tidy_stylable_set_style:
 * @stylable: a #TidyStylable
 * @style: a #TidyStyle
 *
 * Sets @style as the new #TidyStyle to be used by @stylable.
 *
 * The #TidyStylable will take ownership of the passed #TidyStyle.
 *
 * After the #TidyStle has been set, the TidyStylable::style-set signal
 * will be emitted.
 */
void
tidy_stylable_set_style (TidyStylable *stylable,
                         TidyStyle    *style)
{
  TidyStylableIface *iface;
  TidyStyle *old_style;

  g_return_if_fail (TIDY_IS_STYLABLE (stylable));
  g_return_if_fail (TIDY_IS_STYLE (style));

  iface = TIDY_STYLABLE_GET_IFACE (stylable);

  old_style = tidy_stylable_get_style (stylable);
  g_object_ref (old_style);

  if (iface->set_style)
    iface->set_style (stylable, style);
  else
    {
      g_object_set_qdata_full (G_OBJECT (stylable),
                               quark_style,
                               g_object_ref_sink (style),
                               g_object_unref);
    }

  g_signal_emit (stylable, stylable_signals[STYLE_SET], 0, old_style);
  g_object_unref (old_style);

  g_object_notify (G_OBJECT (stylable), "style");
}
Ejemplo n.º 23
0
static CarbonMenuItem *
carbon_menu_item_connect (GtkWidget     *menu_item,
			  GtkWidget     *label,
			  MenuRef        menu,
			  MenuItemIndex  index)
{
  CarbonMenuItem *carbon_item = carbon_menu_item_get (menu_item);

  if (!carbon_item)
    {
      carbon_item = carbon_menu_item_new ();

      g_object_set_qdata_full (G_OBJECT (menu_item), carbon_menu_item_quark,
			       carbon_item,
			       (GDestroyNotify) carbon_menu_item_free);

      g_signal_connect (menu_item, "notify",
                        G_CALLBACK (carbon_menu_item_notify),
                        carbon_item);

      if (label)
	g_signal_connect_swapped (label, "notify::label",
				  G_CALLBACK (carbon_menu_item_notify_label),
				  menu_item);
    }

  carbon_item->menu  = menu;
  carbon_item->index = index;

  return carbon_item;
}
Ejemplo n.º 24
0
/**
 * gs_file_get_path_cached:
 *
 * Like g_file_get_path(), but returns a constant copy so callers
 * don't need to free the result.
 */
const char *
gs_file_get_path_cached (GFile *file)
{
    const char *path;
    static GQuark _file_path_quark = 0;

    if (G_UNLIKELY (_file_path_quark) == 0)
        _file_path_quark = g_quark_from_static_string ("gsystem-file-path");

    G_LOCK (pathname_cache);

    path = g_object_get_qdata ((GObject*)file, _file_path_quark);
    if (!path)
    {
        if (g_file_has_uri_scheme (file, "trash") ||
                g_file_has_uri_scheme (file, "recent"))
            path = gs_file_get_target_path (file);
        else
            path = g_file_get_path (file);
        if (path == NULL)
        {
            G_UNLOCK (pathname_cache);
            return NULL;
        }
        g_object_set_qdata_full ((GObject*)file, _file_path_quark, (char*)path, (GDestroyNotify)g_free);
    }

    G_UNLOCK (pathname_cache);

    return path;
}
Ejemplo n.º 25
0
static PangoOTRuleset *
get_gpos_ruleset (FT_Face face, const PangoIndicInfo *indic_info)
{
  PangoOTInfo    *info = pango_ot_info_get (face);
  GQuark          ruleset_quark = g_quark_from_string (indic_info->gposQuarkName);
  PangoOTRuleset *ruleset;

  if (!info)
    return NULL;

  ruleset = g_object_get_qdata (G_OBJECT (info), ruleset_quark);

  if (!ruleset)
    {
      guint    script_index;

      ruleset = pango_ot_ruleset_new (info);

      if (pango_ot_info_find_script (info, PANGO_OT_TABLE_GPOS,
				     indic_info->scriptTag, &script_index))
	{
	  maybe_add_GPOS_feature (ruleset, info, script_index, FT_MAKE_TAG ('b','l','w','m'), blwm);
	  maybe_add_GPOS_feature (ruleset, info, script_index, FT_MAKE_TAG ('a','b','v','m'), abvm);
	  maybe_add_GPOS_feature (ruleset, info, script_index, FT_MAKE_TAG ('d','i','s','t'), dist);
	}

      g_object_set_qdata_full (G_OBJECT (info), ruleset_quark, ruleset,
			       (GDestroyNotify)g_object_unref);
    }

  return ruleset;
}
static GstTagData *
gst_tag_setter_get_data (GstTagSetter * setter)
{
    GstTagData *data;

    data = g_object_get_qdata (G_OBJECT (setter), gst_tag_key);
    if (!data) {
        static GStaticMutex create_mutex = G_STATIC_MUTEX_INIT;

        /* make sure no other thread is creating a GstTagData at the same time */
        g_static_mutex_lock (&create_mutex);
        data = g_object_get_qdata (G_OBJECT (setter), gst_tag_key);
        if (!data) {
            data = g_slice_new (GstTagData);
            g_static_mutex_init (&data->lock);
            data->list = NULL;
            data->mode = GST_TAG_MERGE_KEEP;
            g_object_set_qdata_full (G_OBJECT (setter), gst_tag_key, data,
                                     gst_tag_data_free);
        }
        g_static_mutex_unlock (&create_mutex);
    }

    return data;
}
Ejemplo n.º 27
0
GdkMirWindowReference *
_gdk_mir_event_source_get_window_reference (GdkWindow *window)
{
  static GQuark win_ref_quark;
  GdkMirWindowReference *ref;

  if G_UNLIKELY (!win_ref_quark)
    win_ref_quark = g_quark_from_string ("GdkMirEventSource window reference");

  ref = g_object_get_qdata (G_OBJECT (window), win_ref_quark);

  if (!ref)
    {
      GdkMirEventSource *source;

      source = _gdk_mir_display_get_event_source (gdk_window_get_display (window));
      g_source_ref ((GSource *) source);

      ref = g_slice_new (GdkMirWindowReference);
      ref->window = window;
      ref->source = source;
      ref->ref_count = 0;
      g_object_add_weak_pointer (G_OBJECT (window), (gpointer *) &ref->window);

      g_object_set_qdata_full (G_OBJECT (window), win_ref_quark,
                               ref, (GDestroyNotify) _gdk_mir_window_reference_unref);
    }

  g_atomic_int_inc (&ref->ref_count);

  return ref;
}
/**
 * ges_extractable_set_asset:
 * @self: Target object
 * @asset: (transfer none): The #GESAsset to set
 *
 * Method to set the asset which instantiated the specified object
 *
 * Return: %TRUE if @asset could be set %FALSE otherwize
 */
gboolean
ges_extractable_set_asset (GESExtractable * self, GESAsset * asset)
{
  GESExtractableInterface *iface;

  g_return_val_if_fail (GES_IS_EXTRACTABLE (self), FALSE);

  iface = GES_EXTRACTABLE_GET_INTERFACE (self);
  GST_DEBUG_OBJECT (self, "Setting asset to %" GST_PTR_FORMAT, asset);

  if (iface->can_update_asset == FALSE &&
      g_object_get_qdata (G_OBJECT (self), ges_asset_key)) {
    GST_WARNING_OBJECT (self, "Can not reset asset on object");

    return FALSE;
  }

  g_object_set_qdata_full (G_OBJECT (self), ges_asset_key,
      gst_object_ref (asset), gst_object_unref);

  /* Let classes that implement the interface know that a asset has been set */
  if (iface->set_asset_full)
    return iface->set_asset_full (self, asset);

  if (iface->set_asset)
    iface->set_asset (self, asset);

  return TRUE;
}
Ejemplo n.º 29
0
static void
create_child_meta (ClutterContainer *container,
                   ClutterActor     *actor)
{
  ClutterContainerIface *iface = CLUTTER_CONTAINER_GET_IFACE (container);
  ClutterChildMeta *child_meta = NULL;

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

  if (!g_type_is_a (iface->child_meta_type, CLUTTER_TYPE_CHILD_META))
    {
      g_warning ("%s: Child data of type '%s' is not a ClutterChildMeta",
                 G_STRLOC, g_type_name (iface->child_meta_type));
      return;
    }

  child_meta = g_object_new (iface->child_meta_type,
                             "container", container,
                             "actor", actor,
                             NULL);

  g_object_set_qdata_full (G_OBJECT (actor), quark_child_meta,
                           child_meta,
                           (GDestroyNotify) g_object_unref);
}
Ejemplo n.º 30
0
void
_signon_object_ready (gpointer object, GQuark quark, const GError *error)
{
    SignonReadyData *rd;

    g_object_set_qdata((GObject *)object, _signon_object_ready_quark(), GINT_TO_POINTER(TRUE));

    if(error)
        g_object_set_qdata_full ((GObject *)object, _signon_object_error_quark(),
                                  g_error_copy(error),
                                 (GDestroyNotify)g_error_free);

    /* steal the qdata so the callbacks won't be invoked again, even if the
     * object becomes ready or is finalized while still invoking them */

    rd = g_object_steal_qdata ((GObject *)object, quark);
    if (!rd) return;

    g_object_ref (object);

    signon_object_invoke_ready_callbacks (rd, error);
    rd->self = NULL; /* so the callbacks won't be invoked again */
    signon_ready_data_free (rd);

    g_object_unref (object);

    //TODO: set some sort of ready information
}