/** * gdk_pixbuf_set_option: * @pixbuf: a #GdkPixbuf * @key: a nul-terminated string. * @value: a nul-terminated string. * * Attaches a key/value pair as an option to a #GdkPixbuf. If @key already * exists in the list of options attached to @pixbuf, the new value is * ignored and %FALSE is returned. * * Return value: %TRUE on success. * * Since: 2.2 **/ gboolean gdk_pixbuf_set_option (GdkPixbuf *pixbuf, const gchar *key, const gchar *value) { GQuark quark; gchar **options; gint n = 0; g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), FALSE); g_return_val_if_fail (key != NULL, FALSE); g_return_val_if_fail (value != NULL, FALSE); quark = g_quark_from_static_string ("gdk_pixbuf_options"); options = g_object_get_qdata (G_OBJECT (pixbuf), quark); if (options) { for (n = 0; options[2*n]; n++) { if (strcmp (options[2*n], key) == 0) return FALSE; } g_object_steal_qdata (G_OBJECT (pixbuf), quark); options = g_renew (gchar *, options, 2*(n+1) + 1); } else {
/** * 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; }
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 }
/** * fm_icon_set_user_data_destroy * @func: function for user data * * Sets @func to be used by fm_icon_unload_user_data_cache() to destroy * user data that was set by fm_icon_set_user_data(). * * Since: 0.1.0 * * Deprecated: 1.2.0: */ static gboolean reload_user_data_cache(GIcon* key, FmIcon* icon, gpointer unused) { /* reset destroy_func for data -- compatibility */ gpointer user_data = g_object_steal_qdata(G_OBJECT(icon), fm_qdata_id); if (user_data) g_object_set_qdata_full(G_OBJECT(icon), fm_qdata_id, user_data, destroy_func); return TRUE; }
/** * fm_pixbuf_from_icon_with_fallback * @icon: icon descriptor * @size: size in pixels * @fallback: (allow-none): name of fallback icon * * Creates a #GdkPixbuf and draws icon there. If icon cannot be found then * icon with name @fallback will be loaded instead. * * Returns: (transfer full): an image. * * Since: 1.2.0 */ GdkPixbuf* fm_pixbuf_from_icon_with_fallback(FmIcon* icon, int size, const char *fallback) { GtkIconInfo* ii; GdkPixbuf* pix = NULL; GSList *pixs, *l; PixEntry* ent; pixs = (GSList*)g_object_steal_qdata(G_OBJECT(icon), fm_qdata_id); for( l = pixs; l; l=l->next ) { ent = (PixEntry*)l->data; if(ent->size == size) /* cached pixbuf is found! */ { return ent->pix ? GDK_PIXBUF(g_object_ref(ent->pix)) : NULL; } } /* not found! load the icon from disk */ ii = gtk_icon_theme_lookup_by_gicon(gtk_icon_theme_get_default(), G_ICON(icon), size, GTK_ICON_LOOKUP_FORCE_SIZE); if(ii) { pix = gtk_icon_info_load_icon(ii, NULL); gtk_icon_info_free(ii); /* increase ref_count to keep this pixbuf in memory even when no one is using it. */ if(pix) g_object_ref(pix); } if (pix == NULL) { char* str = g_icon_to_string(G_ICON(icon)); g_debug("unable to load icon %s", str); if(fallback) pix = gtk_icon_theme_load_icon(gtk_icon_theme_get_default(), fallback, size, GTK_ICON_LOOKUP_USE_BUILTIN|GTK_ICON_LOOKUP_FORCE_SIZE, NULL); if(pix == NULL) /* still unloadable */ pix = gtk_icon_theme_load_icon(gtk_icon_theme_get_default(), "unknown", size, GTK_ICON_LOOKUP_USE_BUILTIN|GTK_ICON_LOOKUP_FORCE_SIZE, NULL); if(G_LIKELY(pix)) g_object_ref(pix); g_free(str); } /* cache this! */ ent = g_slice_new(PixEntry); ent->size = size; ent->pix = pix; /* FIXME: maybe we should unload icons that nobody is using to reduce memory usage. */ /* g_object_weak_ref(); */ pixs = g_slist_prepend(pixs, ent); g_object_set_qdata_full(G_OBJECT(icon), fm_qdata_id, pixs, destroy_pixbufs); return pix; }
/** * 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; }
/** * gtk_text_buffer_unregister_deserialize_format: * @buffer: a #GtkTextBuffer * @format: a #GdkAtom representing a registered rich text format. * * This function unregisters a rich text format that was previously * registered using gtk_text_buffer_register_deserialize_format() or * gtk_text_buffer_register_deserialize_tagset(). * * Since: 2.10 **/ void gtk_text_buffer_unregister_deserialize_format (GtkTextBuffer *buffer, GdkAtom format) { GList *formats; g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer)); g_return_if_fail (format != GDK_NONE); formats = g_object_steal_qdata (G_OBJECT (buffer), deserialize_quark ()); formats = unregister_format (formats, format); g_object_set_qdata_full (G_OBJECT (buffer), deserialize_quark (), formats, (GDestroyNotify) free_format_list); g_object_notify (G_OBJECT (buffer), "paste-target-list"); }
static void post_decodebin_pad_removed_handler (GstElement * decodebin, GstPad * pad, KmsHttpEndpoint * self) { GstElement *appsink, *appsrc; GstPad *sinkpad; if (GST_PAD_IS_SINK (pad)) return; GST_DEBUG ("pad %" GST_PTR_FORMAT " removed", pad); appsink = g_object_steal_qdata (G_OBJECT (pad), appsink_data_quark ()); if (appsink == NULL) { GST_ERROR ("No appsink was found associated with %" GST_PTR_FORMAT, pad); return; } sinkpad = gst_element_get_static_pad (appsink, "sink"); appsrc = g_object_get_qdata (G_OBJECT (sinkpad), appsrc_data_quark ()); g_object_unref (sinkpad); if (!gst_element_set_locked_state (appsink, TRUE)) GST_ERROR ("Could not block element %s", GST_ELEMENT_NAME (appsink)); GST_DEBUG ("Removing appsink %s from %s", GST_ELEMENT_NAME (appsink), GST_ELEMENT_NAME (self->pipeline)); gst_element_set_state (appsink, GST_STATE_NULL); gst_bin_remove (GST_BIN (self->pipeline), appsink); if (appsrc == NULL) { GST_ERROR ("No appsink was found associated with %" GST_PTR_FORMAT, pad); return; } if (GST_OBJECT_PARENT (appsrc) != NULL) { g_object_ref (appsrc); gst_bin_remove (GST_BIN (GST_OBJECT_PARENT (appsrc)), appsrc); gst_element_set_state (appsrc, GST_STATE_NULL); g_object_unref (appsrc); } }
static gboolean category_filter_model_update( GtkTreeStore * store ) { int i, n; int low = 0; int all = 0; int high = 0; int public = 0; int normal = 0; int private = 0; int store_pos; GtkTreeIter top; GtkTreeIter iter; GtkTreeModel * model = GTK_TREE_MODEL( store ); GPtrArray * hosts = g_ptr_array_new( ); GStringChunk * strings = g_string_chunk_new( 4096 ); GHashTable * hosts_hash = g_hash_table_new_full( g_str_hash, g_str_equal, NULL, g_free ); GObject * o = G_OBJECT( store ); GtkTreeModel * tmodel = GTK_TREE_MODEL( g_object_get_qdata( o, TORRENT_MODEL_KEY ) ); g_object_steal_qdata( o, DIRTY_KEY ); /* Walk through all the torrents, tallying how many matches there are * for the various categories. Also make a sorted list of all tracker * hosts s.t. we can merge it with the existing list */ if( gtk_tree_model_iter_nth_child( tmodel, &iter, NULL, 0 ) ) do { tr_torrent * tor; const tr_info * inf; int keyCount; char ** keys; gtk_tree_model_get( tmodel, &iter, MC_TORRENT, &tor, -1 ); inf = tr_torrentInfo( tor ); keyCount = 0; keys = g_new( char*, inf->trackerCount ); for( i=0, n=inf->trackerCount; i<n; ++i ) { int k; int * count; char buf[1024]; char * key; gtr_get_host_from_url( buf, sizeof( buf ), inf->trackers[i].announce ); key = g_string_chunk_insert_const( strings, buf ); count = g_hash_table_lookup( hosts_hash, key ); if( count == NULL ) { count = tr_new0( int, 1 ); g_hash_table_insert( hosts_hash, key, count ); g_ptr_array_add( hosts, key ); } for( k=0; k<keyCount; ++k ) if( !strcmp( keys[k], key ) ) break; if( k==keyCount ) keys[keyCount++] = key; } for( i=0; i<keyCount; ++i ) { int * incrementme = g_hash_table_lookup( hosts_hash, keys[i] ); ++*incrementme; } g_free( keys ); ++all; if( inf->isPrivate ) ++private; else ++public;
/** * fm_icon_set_user_data * @icon: a #FmIcon object * @user_data: data pointer to set * * Sets @user_data to be associated with @icon. * * See also: fm_icon_get_user_data(), fm_icon_unload_user_data_cache(). * * Since: 0.1.0 * * Deprecated: 1.2.0: Use g_object_set_qdata_full() instead. */ void fm_icon_set_user_data(FmIcon* icon, gpointer user_data) { /* this old API meant to replace data not freeing it */ g_object_steal_qdata(G_OBJECT(icon), fm_qdata_id); g_object_set_qdata_full(G_OBJECT(icon), fm_qdata_id, user_data, destroy_func); }