static void downgrade_to_pixels (const GdkPixbuf *pixbuf) { switch (pixbuf->storage) { case STORAGE_PIXELS: return; case STORAGE_BYTES: { GdkPixbuf *mut_pixbuf = (GdkPixbuf *) pixbuf; gsize len; Pixels pixels; pixels.pixels = g_bytes_unref_to_data (pixbuf->s.bytes.bytes, &len); pixels.destroy_fn = free_buffer; pixels.destroy_fn_data = NULL; mut_pixbuf->storage = STORAGE_PIXELS; mut_pixbuf->s.pixels = pixels; break; } default: g_assert_not_reached (); } }
static GtkBuilder *gtkhash_properties_init_builder(void) { #if (GTK_MAJOR_VERSION > 2) return gtk_builder_new_from_resource(PROPERTIES_XML_RESOURCE); #else GError *error = NULL; GBytes *bytes = g_resources_lookup_data(PROPERTIES_XML_RESOURCE, G_RESOURCE_LOOKUP_FLAGS_NONE, &error); if (G_UNLIKELY(error)) { g_warning("%s", error->message); g_error_free(error); return NULL; } gsize xml_len = 0; char *xml = g_bytes_unref_to_data(bytes, &xml_len); GtkBuilder *builder = gtk_builder_new(); gtk_builder_add_from_string(builder, xml, xml_len, &error); g_free(xml); if (G_UNLIKELY(error)) { g_warning("%s", error->message); g_error_free(error); g_object_unref(builder); return NULL; } return builder; #endif }
/** * g_bytes_unref_to_array: * @bytes: (transfer full): a #GBytes * * Unreferences the bytes, and returns a new mutable #GByteArray containing * the same byte data. * * As an optimization, the byte data is transferred to the array without copying * if this was the last reference to bytes and bytes was created with * g_bytes_new(), g_bytes_new_take() or g_byte_array_free_to_bytes(). In all * other cases the data is copied. * * Returns: (transfer full): a new mutable #GByteArray containing the same byte data * * Since: 2.32 */ GByteArray * g_bytes_unref_to_array (GBytes *bytes) { gpointer data; gsize size; g_return_val_if_fail (bytes != NULL, NULL); data = g_bytes_unref_to_data (bytes, &size); return g_byte_array_new_take (data, size); }
/** * gdk_pixbuf_get_pixels_with_length: (rename-to gdk_pixbuf_get_pixels) * @pixbuf: A pixbuf. * @length: (out): The length of the binary data. * * Queries a pointer to the pixel data of a pixbuf. * * Return value: (array length=length): A pointer to the pixbuf's * pixel data. Please see the section on [image data](image-data) * for information about how the pixel data is stored in memory. * * This function will cause an implicit copy of the pixbuf data if the * pixbuf was created from read-only data. * * Since: 2.26 */ guchar * gdk_pixbuf_get_pixels_with_length (const GdkPixbuf *pixbuf, guint *length) { g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL); if (pixbuf->bytes) { GdkPixbuf *mut_pixbuf = (GdkPixbuf*)pixbuf; gsize len; mut_pixbuf->pixels = g_bytes_unref_to_data (pixbuf->bytes, &len); mut_pixbuf->bytes = NULL; } if (length) *length = gdk_pixbuf_get_byte_length (pixbuf); return pixbuf->pixels; }
int main (int argc, char *argv[]) { char *bad_domains = NULL; GError *error = NULL; gboolean wrote_pidfile = FALSE; gs_free char *pidfile = NULL; gs_unref_object NMDhcpClient *dhcp4_client = NULL; gs_unref_object NMRDisc *rdisc = NULL; GByteArray *hwaddr = NULL; size_t hwaddr_len = 0; gconstpointer tmp; gs_free NMUtilsIPv6IfaceId *iid = NULL; guint sd_id; nm_g_type_init (); setpgid (getpid (), getpid ()); do_early_setup (&argc, &argv); if (global_opt.g_fatal_warnings) { GLogLevelFlags fatal_mask; fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK); fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL; g_log_set_always_fatal (fatal_mask); } if (global_opt.show_version) { fprintf (stdout, NM_DIST_VERSION "\n"); exit (0); } nm_main_utils_ensure_root (); if (!global_opt.ifname || !global_opt.uuid) { fprintf (stderr, _("An interface name and UUID are required\n")); exit (1); } ifindex = if_nametoindex (global_opt.ifname); if (ifindex <= 0) { fprintf (stderr, _("Failed to find interface index for %s (%s)\n"), global_opt.ifname, strerror (errno)); exit (1); } pidfile = g_strdup_printf (NMIH_PID_FILE_FMT, ifindex); nm_main_utils_ensure_not_running_pidfile (pidfile); nm_main_utils_ensure_rundir (); if (!nm_logging_setup (global_opt.opt_log_level, global_opt.opt_log_domains, &bad_domains, &error)) { fprintf (stderr, _("%s. Please use --help to see a list of valid options.\n"), error->message); exit (1); } else if (bad_domains) { fprintf (stderr, _("Ignoring unrecognized log domain(s) '%s' passed on command line.\n"), bad_domains); g_clear_pointer (&bad_domains, g_free); } if (global_opt.become_daemon && !global_opt.debug) { if (daemon (0, 0) < 0) { int saved_errno; saved_errno = errno; fprintf (stderr, _("Could not daemonize: %s [error %u]\n"), g_strerror (saved_errno), saved_errno); exit (1); } if (nm_main_utils_write_pidfile (pidfile)) wrote_pidfile = TRUE; } /* Set up unix signal handling - before creating threads, but after daemonizing! */ main_loop = g_main_loop_new (NULL, FALSE); setup_signals (); nm_logging_syslog_openlog (global_opt.logging_backend ? global_opt.logging_backend : (global_opt.debug ? "debug" : NULL)); nm_log_info (LOGD_CORE, "nm-iface-helper (version " NM_DIST_VERSION ") is starting..."); /* Set up platform interaction layer */ nm_linux_platform_setup (); tmp = nm_platform_link_get_address (NM_PLATFORM_GET, ifindex, &hwaddr_len); if (tmp) { hwaddr = g_byte_array_sized_new (hwaddr_len); g_byte_array_append (hwaddr, tmp, hwaddr_len); } if (global_opt.iid_str) { GBytes *bytes; gsize ignored = 0; bytes = nm_utils_hexstr2bin (global_opt.iid_str); if (!bytes || g_bytes_get_size (bytes) != sizeof (*iid)) { fprintf (stderr, _("(%s): Invalid IID %s\n"), global_opt.ifname, global_opt.iid_str); exit (1); } iid = g_bytes_unref_to_data (bytes, &ignored); } if (global_opt.dhcp4_address) { nm_platform_sysctl_set (NM_PLATFORM_GET, nm_utils_ip4_property_path (global_opt.ifname, "promote_secondaries"), "1"); dhcp4_client = nm_dhcp_manager_start_ip4 (nm_dhcp_manager_get (), global_opt.ifname, ifindex, hwaddr, global_opt.uuid, global_opt.priority_v4, !!global_opt.dhcp4_hostname, global_opt.dhcp4_hostname, global_opt.dhcp4_fqdn, global_opt.dhcp4_clientid, 45, NULL, global_opt.dhcp4_address); g_assert (dhcp4_client); g_signal_connect (dhcp4_client, NM_DHCP_CLIENT_SIGNAL_STATE_CHANGED, G_CALLBACK (dhcp4_state_changed), NULL); } if (global_opt.slaac) { nm_platform_link_set_user_ipv6ll_enabled (NM_PLATFORM_GET, ifindex, TRUE); rdisc = nm_lndp_rdisc_new (NM_PLATFORM_GET, ifindex, global_opt.ifname, global_opt.uuid, global_opt.addr_gen_mode, NULL); g_assert (rdisc); if (iid) nm_rdisc_set_iid (rdisc, *iid); nm_platform_sysctl_set (NM_PLATFORM_GET, nm_utils_ip6_property_path (global_opt.ifname, "accept_ra"), "1"); nm_platform_sysctl_set (NM_PLATFORM_GET, nm_utils_ip6_property_path (global_opt.ifname, "accept_ra_defrtr"), "0"); nm_platform_sysctl_set (NM_PLATFORM_GET, nm_utils_ip6_property_path (global_opt.ifname, "accept_ra_pinfo"), "0"); nm_platform_sysctl_set (NM_PLATFORM_GET, nm_utils_ip6_property_path (global_opt.ifname, "accept_ra_rtr_pref"), "0"); g_signal_connect (NM_PLATFORM_GET, NM_PLATFORM_SIGNAL_IP6_ADDRESS_CHANGED, G_CALLBACK (ip6_address_changed), rdisc); g_signal_connect (rdisc, NM_RDISC_CONFIG_CHANGED, G_CALLBACK (rdisc_config_changed), NULL); g_signal_connect (rdisc, NM_RDISC_RA_TIMEOUT, G_CALLBACK (rdisc_ra_timeout), NULL); nm_rdisc_start (rdisc); } sd_id = nm_sd_event_attach_default (); g_main_loop_run (main_loop); g_clear_pointer (&hwaddr, g_byte_array_unref); if (pidfile && wrote_pidfile) unlink (pidfile); nm_log_info (LOGD_CORE, "exiting"); nm_clear_g_source (&sd_id); exit (0); }
static gboolean create_window(void) { GError *error = NULL; builder = gtk_builder_new_from_resource("/org/chimara-if/player/chimara.ui"); window = GTK_WIDGET(load_object("chimara")); aboutwindow = GTK_WIDGET(load_object("aboutwindow")); prefswindow = GTK_WIDGET(load_object("prefswindow")); recentwindow = GTK_WIDGET(load_object("recentwindow")); glk = chimara_if_new(); g_object_set(glk, "ignore-errors", TRUE, /*"interpreter-number", CHIMARA_IF_ZMACHINE_TANDY_COLOR,*/ NULL); GBytes *css_bytes = g_resources_lookup_data("/org/chimara-if/player/style.css", G_RESOURCE_LOOKUP_FLAGS_NONE, &error); if (!css_bytes) return FALSE; size_t len; char *css = g_bytes_unref_to_data(css_bytes, &len); chimara_glk_set_css_from_string(CHIMARA_GLK(glk), css); g_free(css); /* DON'T UNCOMMENT THIS your eyes will burn but it is a good test of programmatically altering just one style chimara_glk_set_css_from_string(CHIMARA_GLK(glk), "buffer { font-family: 'Comic Sans MS'; }");*/ GtkBox *vbox = GTK_BOX( gtk_builder_get_object(builder, "vbox") ); if(vbox == NULL) return FALSE; create_app_actions(G_ACTION_MAP(app), glk); create_window_actions(G_ACTION_MAP(window), glk); GtkWidget *toolbar = GTK_WIDGET(gtk_builder_get_object(builder, "toolbar")); /* Set the default value of the "View/Toolbar" menu item upon creation of a new window to the "show-toolbar-default" setting, but bind the setting one-way only - we don't want toolbars to disappear suddenly */ GPropertyAction *toolbar_action = g_property_action_new("toolbar", toolbar, "visible"); g_action_map_add_action(G_ACTION_MAP(window), G_ACTION(toolbar_action)); if (g_settings_get_boolean(state_settings, "show-toolbar-default")) gtk_widget_show(toolbar); else gtk_widget_hide(toolbar); g_settings_bind(state_settings, "show-toolbar-default", toolbar, "visible", G_SETTINGS_BIND_SET); gtk_box_pack_end(vbox, glk, TRUE, TRUE, 0); gtk_box_pack_start(vbox, toolbar, FALSE, FALSE, 0); gtk_builder_connect_signals(builder, glk); g_signal_connect(glk, "notify::program-name", G_CALLBACK(change_window_title), window); g_signal_connect(glk, "notify::story-name", G_CALLBACK(change_window_title), window); /* Create preferences window */ preferences_create(CHIMARA_GLK(glk)); return TRUE; }