static void test_g_variant_iter (void) { g_autoptr(GVariant) var = g_variant_new_fixed_array (G_VARIANT_TYPE_UINT32, "", 0, sizeof(guint32)); g_autoptr(GVariantIter) val = g_variant_iter_new (var); g_assert (val != NULL); }
static gboolean do_print_related (OstreeRepo *repo, const char *rev, const char *resolved_rev, GError **error) { gboolean ret = FALSE; const char *name; gs_unref_variant GVariant *csum_v = NULL; gs_unref_variant GVariant *variant = NULL; gs_unref_variant GVariant *related = NULL; GVariantIter *viter = NULL; if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, resolved_rev, &variant, error)) goto out; /* PARSE OSTREE_SERIALIZED_COMMIT_VARIANT */ related = g_variant_get_child_value (variant, 2); viter = g_variant_iter_new (related); while (g_variant_iter_loop (viter, "(&s@ay)", &name, &csum_v)) { gs_free char *checksum = ostree_checksum_from_bytes_v (csum_v); g_print ("%s %s\n", name, checksum); } csum_v = NULL; ret = TRUE; out: if (viter) g_variant_iter_free (viter); return ret; }
static GVariant * read_xattrs_cb (OstreeRepo *repo, const char *relpath, GFileInfo *file_info, gpointer user_data) { int rootfs_fd = GPOINTER_TO_INT (user_data); /* Hardcoded at the moment, we're only taking file caps */ static const char *accepted_xattrs[] = { "security.capability" }; guint i; gs_unref_variant GVariant *existing_xattrs = NULL; gs_free_variant_iter GVariantIter *viter = NULL; GError *local_error = NULL; GError **error = &local_error; GVariant *key, *value; GVariantBuilder builder; if (relpath[0] == '/') relpath++; g_variant_builder_init (&builder, G_VARIANT_TYPE ("a(ayay)")); if (!*relpath) { if (!gs_fd_get_all_xattrs (rootfs_fd, &existing_xattrs, NULL, error)) goto out; } else { if (!gs_dfd_and_name_get_all_xattrs (rootfs_fd, relpath, &existing_xattrs, NULL, error)) goto out; } viter = g_variant_iter_new (existing_xattrs); while (g_variant_iter_loop (viter, "(@ay@ay)", &key, &value)) { for (i = 0; i < G_N_ELEMENTS (accepted_xattrs); i++) { const char *validkey = accepted_xattrs[i]; const char *attrkey = g_variant_get_bytestring (key); if (g_str_equal (validkey, attrkey)) g_variant_builder_add (&builder, "(@ay@ay)", key, value); } } out: if (local_error) { g_variant_builder_clear (&builder); /* Unfortunately we have no way to throw from this callback */ g_printerr ("Failed to read xattrs of '%s': %s\n", relpath, local_error->message); exit (1); } return g_variant_ref_sink (g_variant_builder_end (&builder)); }
static int korva_control_list_devices (KorvaController1 *proxy) { GVariant *devices, *dict, *value; char *key; GVariantIter *outer, *inner; GError *error = NULL; korva_controller1_call_get_devices_sync (proxy, &devices, NULL, &error); if (error != NULL) { g_print ("Could not get device list: %s\n", error->message); g_error_free (error); return 1; } outer = g_variant_iter_new (devices); dict = g_variant_iter_next_value (outer); while (dict != NULL) { g_print ("Device:\n"); inner = g_variant_iter_new (dict); while (g_variant_iter_next (inner, "{sv}", &key, &value)) { if (strcmp (key, "UID") == 0 || strcmp (key, "DisplayName") == 0) { g_print (" %s: %s\n", key, g_variant_get_string (value, NULL)); } g_free (key); g_variant_unref (value); } g_variant_iter_free (inner); g_variant_unref (dict); dict = g_variant_iter_next_value (outer); } g_variant_iter_free (outer); return 0; }
void preferences_load (Preferences* self) { IBusConfig* _tmp0_; GVariant* _tmp1_ = NULL; GVariant* _tmp2_; GVariant* values; GVariant* _tmp3_; g_return_if_fail (self != NULL); _tmp0_ = self->priv->config; _tmp1_ = ibus_config_get_values (_tmp0_, "engine/skk"); _tmp2_ = _g_variant_ref0 (_tmp1_); values = _tmp2_; _tmp3_ = values; if (_tmp3_ != NULL) { GVariant* _tmp4_; GVariantIter* _tmp5_ = NULL; GVariantIter* iter; GVariant* entry; _tmp4_ = values; _tmp5_ = g_variant_iter_new (_tmp4_); iter = _tmp5_; entry = NULL; while (TRUE) { GVariantIter* _tmp6_; GVariant* _tmp7_ = NULL; GVariant* _tmp8_; gchar* name = NULL; GVariant* value = NULL; GVariant* _tmp9_; GeeMap* _tmp10_; const gchar* _tmp11_; GVariant* _tmp12_; _tmp6_ = iter; _tmp7_ = g_variant_iter_next_value (_tmp6_); _g_variant_unref0 (entry); entry = _tmp7_; _tmp8_ = entry; if (!(_tmp8_ != NULL)) { break; } _tmp9_ = entry; g_variant_get (_tmp9_, "{sv}", &name, &value, NULL); _tmp10_ = self->priv->current; _tmp11_ = name; _tmp12_ = value; gee_map_set (_tmp10_, _tmp11_, _tmp12_); _g_variant_unref0 (value); _g_free0 (name); } _g_variant_unref0 (entry); _g_variant_iter_free0 (iter); } _g_variant_unref0 (values); }
deepin_workspace_overview_set_present_windows(DeepinWorkspaceOverview* self, GVariant* xids) { DeepinWorkspaceOverviewPrivate* priv = self->priv; if (xids) { priv->all_window_mode = TRUE; priv->present_xids = g_hash_table_new(g_direct_hash, g_direct_equal); guint32 xid; GVariantIter* vi = g_variant_iter_new(xids); while (g_variant_iter_next(vi, "u", &xid, NULL)) { g_hash_table_insert(priv->present_xids, GINT_TO_POINTER(xid), GINT_TO_POINTER(1)); meta_verbose("presenting xid %d\n", xid); } g_variant_iter_free(vi); } }
GHashTable * ot_util_variant_asv_to_hash_table (GVariant *variant) { GHashTable *ret; GVariantIter *viter; char *key; GVariant *value; ret = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify)g_variant_unref); viter = g_variant_iter_new (variant); while (g_variant_iter_next (viter, "{s@v}", &key, &value)) g_hash_table_replace (ret, key, g_variant_ref_sink (value)); g_variant_iter_free (viter); return ret; }
/* ---------------------------------------------------------------------------------------------------- */ int get_object(GDBusProxy *proxy, GPIO* gpio, object_info* obj_info) { g_print("Checking Presence: %s\n",gpio->name); GError *error; GVariant *parm; GVariant *result; error = NULL; parm = g_variant_new("(ss)","GPIO_PRESENT",gpio->name); result = g_dbus_proxy_call_sync (proxy, "getObjectFromId", parm, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); g_assert_no_error (error); const gchar* bus_name; const gchar* obj_path; gsize bus_name_size; gsize obj_path_size; GVariantIter *iter = g_variant_iter_new(result); GVariant* dict = g_variant_iter_next_value(iter); GVariant* b = g_variant_lookup_value(dict,"bus_name",(const GVariantType *) "s"); bus_name = g_variant_get_string(b,&bus_name_size); GVariant* o = g_variant_lookup_value(dict,"obj_path",(const GVariantType *) "s"); obj_path = g_variant_get_string(o,&obj_path_size); int rc = 0; if (bus_name_size == 0 || obj_path_size == 0) { g_print("ERROR: gpio %s not found in lookup\n",gpio->name); rc = 1; } else { obj_info->bus_name = bus_name; obj_info->path = obj_path; } g_variant_unref(b); g_variant_unref(o); g_variant_unref(dict); g_variant_unref(result); return rc; }
static void on_flash_progress(GDBusConnection* connection, const gchar* sender_name, const gchar* object_path, const gchar* interface_name, const gchar* signal_name, GVariant* parameters, gpointer user_data) { Flash *flash = object_get_flash((Object*)user_data); object_get_shared_resource((Object*)user_data); GVariantIter *iter = g_variant_iter_new(parameters); g_variant_iter_next_value(iter); GVariant* v_progress = g_variant_iter_next_value(iter); uint8_t progress = g_variant_get_byte(v_progress); gchar *s; s = g_strdup_printf("Flashing: %d%%",progress); flash_set_status(flash,s); g_free(s); }
static gboolean do_print_related (OstreeRepo *repo, const char *rev, const char *resolved_rev, GError **error) { g_autoptr(GVariant) variant = NULL; if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, resolved_rev, &variant, error)) return FALSE; /* PARSE OSTREE_SERIALIZED_COMMIT_VARIANT */ g_autoptr(GVariant) related = g_variant_get_child_value (variant, 2); g_autoptr(GVariantIter) viter = g_variant_iter_new (related); const char *name; GVariant* csum_v; while (g_variant_iter_loop (viter, "(&s@ay)", &name, &csum_v)) { g_autofree char *checksum = ostree_checksum_from_bytes_v (csum_v); g_print ("%s %s\n", name, checksum); } return TRUE; }
static const gchar * document_read_contents (YelpDocument *document, const gchar *page_id) { gchar *real, *str, **colors; g_mutex_lock (&document->priv->mutex); if (page_id != NULL && g_str_has_prefix (page_id, "search=")) { gchar *tmp, *tmp2, *txt; GVariant *value; GVariantIter *iter; gchar *url, *title, *desc, *icon; /* do not free */ gchar *index_title; GString *ret = g_string_new ("<html><head><style type='text/css'>"); colors = yelp_settings_get_colors (yelp_settings_get_default ()); g_string_append_printf (ret, "html { height: 100%%; } " "body { margin: 0; padding: 0;" " background-color: %s; color: %s;" " direction: %s; } " "div.header { margin-bottom: 1em; } " "div.trails { " " margin: 0; padding: 0.2em 12px 0 12px;" " background-color: %s;" " border-bottom: solid 1px %s; } " "div.trail { text-indent: -1em;" " margin: 0 1em 0.2em 1em; padding: 0; color: %s; } " "div.body { margin: 0 12px 0 12px; padding: 0 0 12px 0; max-width: 60em; } " "div, p { margin: 1em 0 0 0; padding: 0; } " "div:first-child, p:first-child { margin-top: 0; } " "h1 { margin: 0; padding: 0; color: %s; font-size: 1.44em; } " "a { color: %s; text-decoration: none; } " "a.linkdiv { display: block; } " "div.linkdiv { margin: 0; padding: 0.5em; }" "a:hover div.linkdiv {" " outline: solid 1px %s;" " background: -webkit-gradient(linear, left top, left 80, from(%s), to(%s)); } " "div.title { margin-bottom: 0.2em; font-weight: bold; } " "div.desc { margin: 0; color: %s; } " "</style></head><body><div class='header'>", colors[YELP_SETTINGS_COLOR_BASE], colors[YELP_SETTINGS_COLOR_TEXT], (gtk_widget_get_default_direction() == GTK_TEXT_DIR_RTL ? "rtl" : "ltr"), colors[YELP_SETTINGS_COLOR_GRAY_BASE], colors[YELP_SETTINGS_COLOR_GRAY_BORDER], colors[YELP_SETTINGS_COLOR_TEXT_LIGHT], colors[YELP_SETTINGS_COLOR_TEXT_LIGHT], colors[YELP_SETTINGS_COLOR_LINK], colors[YELP_SETTINGS_COLOR_BLUE_BASE], colors[YELP_SETTINGS_COLOR_BLUE_BASE], colors[YELP_SETTINGS_COLOR_BASE], colors[YELP_SETTINGS_COLOR_TEXT_LIGHT] ); index_title = yelp_storage_get_root_title (yelp_storage_get_default (), document->priv->doc_uri); if (index_title != NULL) { tmp = g_markup_printf_escaped ("<div class='trails'><div class='trail'>" "<a href='xref:'>%s</a> %s " "</div></div>", index_title, (gtk_widget_get_default_direction() == GTK_TEXT_DIR_RTL ? "«" : "»") ); g_string_append (ret, tmp); g_free (tmp); } g_string_append (ret, "</div><div class='body'>"); g_strfreev (colors); str = hash_lookup (document->priv->contents, real); if (str) { str_ref (str); g_mutex_unlock (&document->priv->mutex); return (const gchar *) str; } txt = g_uri_unescape_string (page_id + 7, NULL); tmp2 = g_strdup_printf (_("Search results for “%s”"), txt); tmp = g_markup_printf_escaped ("<h1>%s</h1>", tmp2); g_string_append (ret, tmp); g_free (tmp2); g_free (tmp); value = yelp_storage_search (yelp_storage_get_default (), document->priv->doc_uri, txt); iter = g_variant_iter_new (value); if (g_variant_iter_n_children (iter) == 0) { if (index_title != NULL) { gchar *t = g_strdup_printf (_("No matching help pages found in “%s”."), index_title); tmp = g_markup_printf_escaped ("<p>%s</p>", t); g_free (t); } else { tmp = g_markup_printf_escaped ("<p>%s</p>", _("No matching help pages found.")); } g_string_append (ret, tmp); g_free (tmp); } else { while (g_variant_iter_loop (iter, "(&s&s&s&s)", &url, &title, &desc, &icon)) { tmp = g_markup_printf_escaped ("<div><a class='linkdiv' href='%s'><div class='linkdiv'>" "<div class='title'>%s</div>" "<div class='desc'>%s</div>" "</div></a></div>", url, title, desc); g_string_append (ret, tmp); g_free (tmp); } } g_variant_iter_free (iter); g_variant_unref (value); if (index_title != NULL) g_free (index_title); g_free (txt); g_string_append (ret, "</div></body></html>"); hash_replace (document->priv->contents, page_id, g_string_free (ret, FALSE)); str = hash_lookup (document->priv->contents, page_id); str_ref (str); g_mutex_unlock (&document->priv->mutex); return (const gchar *) str; } real = hash_lookup (document->priv->page_ids, page_id); str = hash_lookup (document->priv->contents, real); if (str) str_ref (str); g_mutex_unlock (&document->priv->mutex); return (const gchar *) str; }
gboolean flatpak_builtin_document_info (int argc, char **argv, GCancellable *cancellable, GError **error) { g_autoptr(GOptionContext) context = NULL; g_autoptr(GDBusConnection) session_bus = NULL; const char *file; XdpDbusDocuments *documents; g_autofree char *mountpoint = NULL; g_autofree char *basename = NULL; g_autofree char *doc_id = NULL; g_autofree char *doc_path = NULL; g_autofree char *origin = NULL; const char *app_id; const char **perms; g_autoptr(GVariant) apps = NULL; g_autoptr(GVariantIter) iter = NULL; context = g_option_context_new (_("FILE - Get information about an exported file")); g_option_context_set_translation_domain (context, GETTEXT_PACKAGE); if (!flatpak_option_context_parse (context, options, &argc, &argv, FLATPAK_BUILTIN_FLAG_NO_DIR, NULL, cancellable, error)) return FALSE; if (argc < 2) return usage_error (context, _("FILE must be specified"), error); file = argv[1]; basename = g_path_get_basename (file); session_bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, error); if (session_bus == NULL) return FALSE; documents = xdp_dbus_documents_proxy_new_sync (session_bus, 0, "org.freedesktop.portal.Documents", "/org/freedesktop/portal/documents", NULL, error); if (documents == NULL) return FALSE; if (!xdp_dbus_documents_call_get_mount_point_sync (documents, &mountpoint, NULL, error)) return FALSE; if (!xdp_dbus_documents_call_lookup_sync (documents, file, &doc_id, NULL, error)) return FALSE; if (strcmp (doc_id, "") == 0) { g_print (_("Not exported\n")); return TRUE; } doc_path = g_build_filename (mountpoint, doc_id, basename, NULL); if (!xdp_dbus_documents_call_info_sync (documents, doc_id, &origin, &apps, NULL, error)) return FALSE; iter = g_variant_iter_new (apps); g_print ("id: %s\n", doc_id); g_print ("path: %s\n", doc_path); g_print ("origin: %s\n", origin); if (g_variant_iter_n_children (iter) > 0) g_print ("permissions:\n"); while (g_variant_iter_next (iter, "{&s^a&s}", &app_id, &perms)) { int i; g_print ("\t%s\t", app_id); for (i = 0; perms[i]; i++) { if (i > 0) g_print (", "); g_print ("%s", perms[i]); } g_print ("\n"); } return TRUE; }
struct UD2_enumerations* enum_objects() { g_type_init(); struct UD2_enumerations* enumerations = g_new(struct UD2_enumerations, 1); GList* UD2_drives = NULL; GList* UD2_blocks = NULL; GDBusProxy* UD2_Proxy = NULL; GError* error=NULL; UD2_Proxy = g_dbus_proxy_new_for_bus_sync( G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, NULL, UD2_DBUS_NAME, UD2_PATH, DBUS_MANAGER_IFACE, NULL, &error); if (!UD2_Proxy) { g_printerr("%s\n", error->message); g_error_free(error); } /* Use the GetManagedObjects method from the ObjectManager interface to * enumerate UD2 objects */ GVariant* UD2_Objects = g_dbus_proxy_call_sync( UD2_Proxy, (gchar*) "GetManagedObjects", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); if (!UD2_Objects) { g_printerr("%s\n", error->message); g_error_free(error); } /* As per http://dbus.freedesktop.org/doc/dbus-specification.html the return type for method GetManagedObjects is DICT<OBJPATH,DICT<STRING,DICT<STRING,VARIANT>>> or (a{oa{sa{sv}}}) in DBus parlance. */ g_assert_cmpstr("(a{oa{sa{sv}}})", ==, g_variant_get_type_string(UD2_Objects)); /* The tuple contains only one dictionary */ g_assert_cmpint(1, ==, g_variant_n_children(UD2_Objects)); /* Re-parent UD2_Objects to the sole element in the tuple */ UD2_Objects = g_variant_get_child_value(UD2_Objects, 0); GVariantIter* dict_iter = g_variant_iter_new(UD2_Objects); GVariant* kv_pair; while(kv_pair = g_variant_iter_next_value(dict_iter)) { gchar* dbus_object_path; GVariant* interface_dict; g_variant_get(kv_pair, "{o*}", &dbus_object_path, &interface_dict); if (0 == g_strcmp0("/org/freedesktop/UDisks2/Manager", dbus_object_path)) goto next_object; /* Store the object's properties in a hash table */ GHashTable* UD2_object_properties = g_hash_table_new(g_str_hash, g_str_equal); g_hash_table_insert(UD2_object_properties, "object_path", g_strdup(dbus_object_path)); /* Parse the object's DBus interfaces */ GVariantIter* interface_iterator = g_variant_iter_new(interface_dict); GVariant* interface_kv_pair; while(interface_kv_pair = g_variant_iter_next_value(interface_iterator)) { gchar* UD2_interface; GVariant* properties_dict; g_variant_get(interface_kv_pair, "{s*}", &UD2_interface, &properties_dict); /* Is this a UD2 drive? */ if (0 == g_strcmp0(UD2_DRIVE_IFACE, UD2_interface)) { GVariant* ejectable = g_variant_lookup_value( properties_dict, "Ejectable", NULL); g_hash_table_insert(UD2_object_properties, (gchar*) "ejectable", GINT_TO_POINTER(g_variant_get_boolean(ejectable))); g_variant_unref(ejectable); GVariant* optical = g_variant_lookup_value( properties_dict, "Optical", NULL); g_hash_table_insert(UD2_object_properties, (gchar*) "optical", GINT_TO_POINTER(g_variant_get_boolean(optical))); g_variant_unref(optical); UD2_drives = g_list_append(UD2_drives, UD2_object_properties); } /* Is this a block device? */ if (0 == g_strcmp0(UD2_BLOCK_IFACE, UD2_interface)) { GVariant* preferred_path = g_variant_lookup_value( properties_dict, "PreferredDevice", NULL); g_hash_table_insert(UD2_object_properties, (gchar*) "dev_path", g_variant_dup_bytestring(preferred_path, NULL)); g_variant_unref(preferred_path); /* In addition to the preferred path, there may * be any number of human-readable symlinks under * /dev */ GVariant* symlinks = g_variant_lookup_value(properties_dict, "Symlinks", NULL); //g_print("Symlinks has %d elements\n", g_variant_n_children(symlinks)); GVariantIter* symlink_iterator = g_variant_iter_new(symlinks); GVariant* symlink; GList* symlink_list = NULL; while(symlink = g_variant_iter_next_value(symlink_iterator)) { symlink_list = g_list_append(symlink_list, (gpointer) g_variant_dup_bytestring(symlink, NULL)); g_variant_unref(symlink); } g_variant_iter_free(symlink_iterator); g_variant_unref(symlinks); g_hash_table_insert(UD2_object_properties, (gchar*) "symlinks", symlink_list); UD2_blocks = g_list_append(UD2_blocks, UD2_object_properties); } /* TODO How shall we handle partition tables? */ if (0 == g_strcmp0(UD2_PTABLE_IFACE, UD2_interface)) { g_hash_table_insert(UD2_object_properties, (gchar*) "has_partition_table", GINT_TO_POINTER((gboolean) TRUE)); } /* Does this block device have a filesystem? */ if (0 == g_strcmp0(UD2_FS_IFACE, UD2_interface)) { g_hash_table_insert(UD2_object_properties, (gchar*) "has_filesystem", GINT_TO_POINTER((gboolean) TRUE)); /* Is the FS mounted? We don't really care where */ GVariant* mountpoints = g_variant_lookup_value( properties_dict, "MountPoints", NULL); if (0 < g_variant_n_children(mountpoints)) { g_hash_table_insert(UD2_object_properties, (gchar*) "mounted", GINT_TO_POINTER((gboolean) TRUE)); } else { g_hash_table_insert(UD2_object_properties, (gchar*) "mounted", GINT_TO_POINTER((gboolean) FALSE)); } g_variant_unref(mountpoints); } g_free(UD2_interface); g_variant_unref(interface_kv_pair); } g_variant_iter_free(interface_iterator); next_object: g_variant_unref(interface_dict); g_free(dbus_object_path); g_variant_unref(kv_pair); } g_variant_iter_free(dict_iter); /* Populate the UD2_enumerations struct */ enumerations->drives = UD2_drives; enumerations->block_devices = UD2_blocks; g_variant_unref(UD2_Objects); g_object_unref(UD2_Proxy); return enumerations; }
static gboolean print_documents (const char *app_id, Column *columns, GCancellable *cancellable, GError **error) { g_autoptr(GDBusConnection) session_bus = NULL; XdpDbusDocuments *documents; g_autoptr(GVariant) apps = NULL; g_autoptr(GVariantIter) iter = NULL; const char *id; const char *origin; FlatpakTablePrinter *printer; g_autofree char *mountpoint = NULL; gboolean need_perms = FALSE; int i; if (columns[0].name == NULL) return TRUE; session_bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, error); if (session_bus == NULL) return FALSE; documents = xdp_dbus_documents_proxy_new_sync (session_bus, 0, "org.freedesktop.portal.Documents", "/org/freedesktop/portal/documents", NULL, error); if (documents == NULL) return FALSE; if (!xdp_dbus_documents_call_list_sync (documents, app_id ? app_id : "", &apps, NULL, error)) return FALSE; if (!xdp_dbus_documents_call_get_mount_point_sync (documents, &mountpoint, NULL, error)) return FALSE; printer = flatpak_table_printer_new (); flatpak_table_printer_set_columns (printer, columns); for (i = 0; columns[i].name; i++) { if (strcmp (columns[i].name, "permissions") == 0 || strcmp (columns[i].name, "application") == 0) { need_perms = TRUE; break; } } iter = g_variant_iter_new (apps); while (g_variant_iter_next (iter, "{&s^&ay}", &id, &origin)) { g_autoptr(GVariant) apps2 = NULL; g_autoptr(GVariantIter) iter2 = NULL; const char *app_id2 = NULL; const char **perms = NULL; gboolean just_perms = FALSE; if (need_perms) { g_autofree char *origin2 = NULL; if (!xdp_dbus_documents_call_info_sync (documents, id, &origin2, &apps2, NULL, error)) return FALSE; iter2 = g_variant_iter_new (apps2); } while ((iter2 && g_variant_iter_next (iter2, "{&s^a&s}", &app_id2, &perms)) || !just_perms) { for (i = 0; columns[i].name; i++) { if (strcmp (columns[i].name, "application") == 0) flatpak_table_printer_add_column (printer, app_id2); else if (strcmp (columns[i].name, "permissions") == 0) { g_autofree char *value = NULL; if (perms) value = g_strjoinv (" ", (char **)perms); flatpak_table_printer_add_column (printer, value); } else if (just_perms) flatpak_table_printer_add_column (printer, ""); else if (strcmp (columns[i].name, "id") == 0) flatpak_table_printer_add_column (printer, id); else if (strcmp (columns[i].name, "origin") == 0) flatpak_table_printer_add_column (printer, origin); else if (strcmp (columns[i].name, "path") == 0) { g_autofree char *basename = g_path_get_basename (origin); g_autofree char *path = g_build_filename (mountpoint, id, basename, NULL); flatpak_table_printer_add_column (printer, path); } } flatpak_table_printer_finish_row (printer); just_perms = TRUE; } } flatpak_table_printer_print (printer); flatpak_table_printer_free (printer); return TRUE; }
static void onNotify(GDBusConnection * connection, const gchar * sender, GVariant * parameters, GDBusMethodInvocation * invocation) { gchar *appname = NULL; guint replaces_id = 0; gchar *icon = NULL; gchar *summary = NULL; gchar *body = NULL; Actions *actions = malloc(sizeof(Actions)); gint timeout = -1; /* hints */ gint urgency = 1; gint progress = -1; gchar *fgcolor = NULL; gchar *bgcolor = NULL; gchar *category = NULL; actions->actions = NULL; actions->count = 0; { GVariantIter *iter = g_variant_iter_new(parameters); GVariant *content; GVariant *dict_value; int idx = 0; while ((content = g_variant_iter_next_value(iter))) { switch (idx) { case 0: if (g_variant_is_of_type (content, G_VARIANT_TYPE_STRING)) appname = g_variant_dup_string(content, NULL); break; case 1: if (g_variant_is_of_type (content, G_VARIANT_TYPE_UINT32)) replaces_id = g_variant_get_uint32(content); break; case 2: if (g_variant_is_of_type (content, G_VARIANT_TYPE_STRING)) icon = g_variant_dup_string(content, NULL); break; case 3: if (g_variant_is_of_type (content, G_VARIANT_TYPE_STRING)) summary = g_variant_dup_string(content, NULL); break; case 4: if (g_variant_is_of_type (content, G_VARIANT_TYPE_STRING)) body = g_variant_dup_string(content, NULL); break; case 5: if (g_variant_is_of_type (content, G_VARIANT_TYPE_STRING_ARRAY)) actions->actions = g_variant_dup_strv(content, &(actions-> count)); break; case 6: if (g_variant_is_of_type (content, G_VARIANT_TYPE_DICTIONARY)) { dict_value = g_variant_lookup_value(content, "urgency", G_VARIANT_TYPE_BYTE); if (dict_value) urgency = g_variant_get_byte (dict_value); dict_value = g_variant_lookup_value(content, "fgcolor", G_VARIANT_TYPE_STRING); if (dict_value) fgcolor = g_variant_dup_string (dict_value, NULL); dict_value = g_variant_lookup_value(content, "bgcolor", G_VARIANT_TYPE_STRING); if (dict_value) bgcolor = g_variant_dup_string (dict_value, NULL); dict_value = g_variant_lookup_value(content, "category", G_VARIANT_TYPE_STRING); if (dict_value) { category = g_variant_dup_string( dict_value, NULL); } dict_value = g_variant_lookup_value(content, "value", G_VARIANT_TYPE_INT32); if (dict_value) { progress = g_variant_get_int32(dict_value); } else { dict_value = g_variant_lookup_value(content, "value", G_VARIANT_TYPE_UINT32); if (dict_value) progress = g_variant_get_uint32(dict_value); } } break; case 7: if (g_variant_is_of_type (content, G_VARIANT_TYPE_INT32)) timeout = g_variant_get_int32(content); break; } idx++; } g_variant_iter_free(iter); } fflush(stdout); if (timeout > 0) { /* do some rounding */ timeout = (timeout + 500) / 1000; if (timeout < 1) { timeout = 1; } } notification *n = malloc(sizeof(notification)); n->appname = appname; n->summary = summary; n->body = body; n->icon = icon; n->timeout = timeout; n->progress = (progress < 0 || progress > 100) ? 0 : progress + 1; n->urgency = urgency; n->category = category; n->dbus_client = strdup(sender); if (actions->count > 0) { n->actions = actions; } else { n->actions = NULL; free(actions); } for (int i = 0; i < ColLast; i++) { n->color_strings[i] = NULL; } n->color_strings[ColFG] = fgcolor; n->color_strings[ColBG] = bgcolor; int id = notification_init(n, replaces_id); wake_up(); GVariant *reply = g_variant_new("(u)", id); g_dbus_method_invocation_return_value(invocation, reply); g_dbus_connection_flush(connection, NULL, NULL, NULL); run(NULL); }
static void onNotify(GDBusConnection *connection, const gchar *sender, GVariant *parameters, GDBusMethodInvocation *invocation) { gchar *app_name = NULL; guint replaces_id = 0; gchar *app_icon = NULL; gchar *summary = NULL; gchar *body = NULL; gint expire_timeout = -1; { GVariantIter *iter = g_variant_iter_new(parameters); GVariant *content; int i = 0; while ((content = g_variant_iter_next_value(iter))) { switch(i) { case 0: if (g_variant_is_of_type(content, G_VARIANT_TYPE_STRING)) app_name = g_variant_dup_string(content, NULL); break; case 1: if (g_variant_is_of_type(content, G_VARIANT_TYPE_UINT32)) replaces_id = g_variant_get_uint32(content); break; case 2: if (g_variant_is_of_type(content, G_VARIANT_TYPE_STRING)) app_icon = g_variant_dup_string(content, NULL); break; case 3: if (g_variant_is_of_type(content, G_VARIANT_TYPE_STRING)) summary = g_variant_dup_string(content, NULL); break; case 4: if (g_variant_is_of_type(content, G_VARIANT_TYPE_STRING)) body = g_variant_dup_string(content, NULL); break; case 5: break; case 6: break; case 7: if (g_variant_is_of_type(content, G_VARIANT_TYPE_INT32)) expire_timeout = g_variant_get_int32(content); break; } g_variant_unref(content); i++; } g_variant_iter_free(iter); } Notification *n = notification_create (app_name, replaces_id, app_icon, summary, body, expire_timeout); n->app_name = app_name; n->replaces_id = replaces_id; n->app_icon = app_icon; n->summary = summary; n->body = body; n->expire_timeout = expire_timeout; int id = 1; GVariant *reply = g_variant_new("(u)", id); g_dbus_method_invocation_return_value(invocation, reply); g_dbus_connection_flush(connection, NULL, NULL, NULL); g_print("About to print the summary from yarn.c\n"); prepare(n); }