Exemplo n.º 1
0
static void
_fcitx_client_g_signal(GDBusProxy *proxy,
                       gchar      *sender_name,
                       gchar      *signal_name,
                       GVariant   *parameters,
                       gpointer    user_data)
{
    FCITX_UNUSED(proxy);
    FCITX_UNUSED(sender_name);
    if (strcmp(signal_name, "EnableIM") == 0) {
        g_signal_emit(user_data, signals[ENABLE_IM_SIGNAL], 0);
    }
    else if (strcmp(signal_name, "CloseIM") == 0) {
        g_signal_emit(user_data, signals[CLOSE_IM_SIGNAL], 0);
    }
    else if (strcmp(signal_name, "CommitString") == 0) {
        const gchar* data = NULL;
        g_variant_get(parameters, "(s)", &data);
        if (data) {
            g_signal_emit(user_data, signals[COMMIT_STRING_SIGNAL], 0, data);
        }
    }
    else if (strcmp(signal_name, "ForwardKey") == 0) {
        guint32 key, state;
        gint32 type;
        g_variant_get(parameters, "(uui)", &key, &state, &type);
        g_signal_emit(user_data, signals[FORWARD_KEY_SIGNAL], 0, key, state, type);
    }
    else if (strcmp(signal_name, "DeleteSurroundingText") == 0) {
        guint32 nchar;
        gint32 offset;
        g_variant_get(parameters, "(iu)", &offset, &nchar);
        g_signal_emit(user_data, signals[DELETE_SURROUNDING_TEXT_SIGNAL], 0, offset, nchar);
    }
    else if (strcmp(signal_name, "UpdateClientSideUI") == 0) {
        const gchar* auxup, *auxdown, *preedit, *candidate, *imname;
        int cursor;
        g_variant_get(parameters, "(sssssi)", &auxup, &auxdown, &preedit, &candidate, &imname, &cursor);
        g_signal_emit(user_data, signals[UPDATE_CLIENT_SIDE_UI_SIGNAL], 0, auxup, auxdown, preedit, candidate, imname, cursor);
    }
    else if (strcmp(signal_name, "UpdateFormattedPreedit") == 0) {
        int cursor_pos;
        GPtrArray* array = g_ptr_array_new_with_free_func(_item_free);
        GVariantIter* iter;
        g_variant_get(parameters, "(a(si)i)", &iter, &cursor_pos);

        gchar* string;
        int type;
        while (g_variant_iter_next(iter, "(si)", &string, &type, NULL)) {
            FcitxPreeditItem* item = g_malloc0(sizeof(FcitxPreeditItem));
            item->string = strdup(string);
            item->type = type;
            g_ptr_array_add(array, item);
            g_free(string);
        }
        g_variant_iter_free(iter);
        g_signal_emit(user_data, signals[UPDATED_FORMATTED_PREEDIT_SIGNAL], 0, array, cursor_pos);
        g_ptr_array_free(array, TRUE);
    }
}
Exemplo n.º 2
0
static void onPropertiesChanged(GDBusProxy          *proxy,
                                GVariant            *changed_properties,
                                const gchar* const  *invalidated_properties,
                                gpointer             pp)
{
  if (g_variant_n_children(changed_properties) > 0) {
    GVariantIter *iter;
    gchar *key;
    GVariant *value;

    debug(" *** Properties Changed:\n");
    g_variant_get(changed_properties, "a{sv}", &iter);
    while (g_variant_iter_loop (iter, "{&sv}", &key, &value)) {
      gchar *value_str;
      value_str = g_variant_print(value, TRUE);
      g_print("      %s -> %s\n", key, value_str);
      g_free(value_str);
      if (strncmp(key, "Metadata",8) == 0) {
        trackChanged(value);
      } else if (strcmp(key, "PlaybackStatus") == 0) {
        playbackChanged(g_variant_dup_string(value, NULL));
      } else if (strcmp(key, "LoopStatus") == 0) {
        loopChanged(g_variant_dup_string(value, NULL));
      } else if (strcmp(key, "Shuffle") == 0) {
        shuffleChanged(g_variant_get_boolean(value));
      } else if (strcmp(key, "Position") == 0) {
        positionChanged(g_variant_get_int64(value));
      } else if (strcmp(key, "Volume") == 0) {
        volumeChanged(g_variant_get_double(value));
      }
    }

    g_variant_iter_free (iter);
  }
}
Exemplo n.º 3
0
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;
}
Exemplo n.º 4
0
static Login1Seat *
add_seat (Login1Service *service, const gchar *id, const gchar *path)
{
    Login1Seat *seat;
    GVariant *result;
    GError *error = NULL;

    seat = g_object_new (LOGIN1_SEAT_TYPE, NULL);
    seat->priv->connection = g_object_ref (service->priv->connection);
    seat->priv->id = g_strdup (id);
    seat->priv->path = g_strdup (path);

    seat->priv->signal_id = g_dbus_connection_signal_subscribe (seat->priv->connection,
                                                                LOGIN1_SERVICE_NAME,
                                                                "org.freedesktop.DBus.Properties",
                                                                "PropertiesChanged",
                                                                path,
                                                                "org.freedesktop.login1.Seat",
                                                                G_DBUS_SIGNAL_FLAGS_NONE,
                                                                seat_properties_changed_cb,
                                                                g_object_ref (seat),
                                                                g_object_unref);

    /* Get properties for this seat */
    result = g_dbus_connection_call_sync (seat->priv->connection,
                                          LOGIN1_SERVICE_NAME,
                                          path,
                                          "org.freedesktop.DBus.Properties",
                                          "GetAll",
                                          g_variant_new ("(s)", "org.freedesktop.login1.Seat"),
                                          G_VARIANT_TYPE ("(a{sv})"),
                                          G_DBUS_CALL_FLAGS_NONE,
                                          -1,
                                          NULL,
                                          &error);
    if (error)
        g_warning ("Failed to get seat properties: %s", error->message);
    g_clear_error (&error);
    if (result)
    {
        GVariantIter *properties;
        const gchar *name;
        GVariant *value;

        g_variant_get (result, "(a{sv})", &properties);
        while (g_variant_iter_loop (properties, "{&sv}", &name, &value))
        {
            if (strcmp (name, "CanGraphical") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_BOOLEAN))
                seat->priv->can_graphical = g_variant_get_boolean (value);
            else if (strcmp (name, "CanMultiSession") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_BOOLEAN))
                seat->priv->can_multi_session = g_variant_get_boolean (value);
        }
        g_variant_iter_free (properties);
        g_variant_unref (result);
    }

    service->priv->seats = g_list_append (service->priv->seats, seat);

    return seat;
}
Exemplo n.º 5
0
/**
 * tracker_miner_manager_get_running:
 * @manager: a #trackerMinerManager
 *
 * Returns a list of references for all active miners. Active miners
 * are miners which are running within a process.
 *
 * Returns: (transfer full) (element-type utf8): a #GSList which must
 * be freed with g_slist_free() and all contained data with g_free().
 * Otherwise %NULL is returned if there are no miners.
 *
 * Since: 0.8
 **/
GSList *
tracker_miner_manager_get_running (TrackerMinerManager *manager)
{
	TrackerMinerManagerPrivate *priv;
	GSList *list = NULL;
	GError *error = NULL;
	GVariant *v;
	GVariantIter *iter;
	const gchar *str = NULL;

	g_return_val_if_fail (TRACKER_IS_MINER_MANAGER (manager), NULL);

	priv = TRACKER_MINER_MANAGER_GET_PRIVATE (manager);

	if (!priv->connection) {
		return NULL;
	}

	v = g_dbus_connection_call_sync (priv->connection,
	                                 "org.freedesktop.DBus",
	                                 "/org/freedesktop/DBus",
	                                 "org.freedesktop.DBus",
	                                 "ListNames",
	                                 NULL,
	                                 G_VARIANT_TYPE ("(as)"),
	                                 G_DBUS_CALL_FLAGS_NONE,
	                                 -1,
	                                 NULL,
	                                 &error);

	if (error) {
		g_critical ("Could not get a list of names registered on the session bus, %s",
		            error ? error->message : "no error given");
		g_clear_error (&error);
		return NULL;
	}

	g_variant_get (v, "(as)", &iter);
	while (g_variant_iter_loop (iter, "&s", &str)) {
		if (!g_str_has_prefix (str, TRACKER_MINER_DBUS_NAME_PREFIX)) {
			continue;
		}

		/* Special case miner-fs which has
		 * additional D-Bus interface.
		 */
		if (strcmp (str, "org.freedesktop.Tracker1.Miner.Files.Index") == 0) {
			continue;
		}

		list = g_slist_prepend (list, g_strdup (str));
	}

	g_variant_iter_free (iter);
	g_variant_unref (v);

	list = g_slist_reverse (list);

	return list;
}
Exemplo n.º 6
0
void on_menu_changed(gpointer instance, GVariant *parameters, gpointer user_data)
{
  WorkraveApplet *applet = WORKRAVE_APPLET(user_data);

  GVariantIter *iter;
  g_variant_get (parameters, "(a(sii))", &iter);

  char *text;
  int id;
  int flags;

  gboolean visible[sizeof(menu_data)/sizeof(struct Menuitems)];
  for (int i = 0; i < sizeof(menu_data)/sizeof(struct Menuitems); i++)
    {
      visible[i] = menu_data[i].visible_when_not_running;
    }

  while (g_variant_iter_loop(iter, "(sii)", &text, &id, &flags))
    {
      int index = lookup_menu_index_by_id((enum MenuCommand)id);
      if (index == -1)
        {
          continue;
        }

      GAction *action = g_action_map_lookup_action(G_ACTION_MAP(applet->priv->action_group), menu_data[index].action);

      if (flags & MENU_ITEM_FLAG_SUBMENU_END ||
          flags & MENU_ITEM_FLAG_SUBMENU_BEGIN)
        {
          continue;
        }

      visible[index] = TRUE;

      if (g_action_get_state_type(G_ACTION(action)) != NULL)
        {
          if (menu_data[index].state == NULL)
            {
              g_simple_action_set_state(G_SIMPLE_ACTION(action), g_variant_new_boolean(flags & MENU_ITEM_FLAG_ACTIVE));
            }
          else
            {
              if (flags & MENU_ITEM_FLAG_ACTIVE)
                {
                  g_simple_action_set_state(G_SIMPLE_ACTION(action), g_variant_new_string(menu_data[index].state));
                }
            }
        }
    }

  g_variant_iter_free (iter);

  for (int i = 0; i < sizeof(menu_data)/sizeof(struct Menuitems); i++)
    {
      GAction *action = g_action_map_lookup_action(G_ACTION_MAP(applet->priv->action_group), menu_data[i].action);
      g_simple_action_set_enabled(G_SIMPLE_ACTION(action), visible[i]);
    }
}
Exemplo n.º 7
0
GVariant* GnomeGrabber::Impl::onShellMethodCall(std::string const& method, GVariant* parameters)
{
  LOG_DEBUG(logger) << "Called method '" << method << "'";

  if (method == "GrabAccelerators")
  {
    if (g_variant_is_of_type(parameters, G_VARIANT_TYPE("(a(su))")))
    {
      GVariant* variant;
      GVariantBuilder builder;
      GVariantIter* iterator;
      gchar const* accelerator;
      guint flags;

      g_variant_builder_init(&builder, G_VARIANT_TYPE("au"));
      g_variant_get(parameters, "(a(su))", &iterator);

      while (g_variant_iter_next(iterator, "(&su)", &accelerator, &flags))
        g_variant_builder_add(&builder, "u", grabAccelerator(accelerator, flags));

      g_variant_iter_free(iterator);
      variant = g_variant_builder_end(&builder);
      return g_variant_new_tuple(&variant, 1);
    }
    else
      LOG_WARN(logger) << "Expected arguments of type (a(su))";
  }
  else if (method == "GrabAccelerator")
  {
    if (g_variant_is_of_type(parameters, G_VARIANT_TYPE("(su)")))
    {
      GVariant* variant;
      gchar const* accelerator;
      guint flags;

      g_variant_get(parameters, "(&su)", &accelerator, &flags);
      variant = g_variant_new_uint32(grabAccelerator(accelerator, flags));
      return g_variant_new_tuple(&variant, 1);
    }
    else
      LOG_WARN(logger) << "Expected arguments of type (su)";
  }
  else if (method == "UngrabAccelerator")
  {
    if (g_variant_is_of_type(parameters, G_VARIANT_TYPE("(u)")))
    {
      GVariant* variant;
      guint action;

      g_variant_get(parameters, "(u)", &action);
      variant = g_variant_new_boolean(removeAction(action));
      return g_variant_new_tuple(&variant, 1);
    }
    else
      LOG_WARN(logger) << "Expected arguments of type (u)";
  }

  return nullptr;
}
Exemplo n.º 8
0
void Peer::handle_property_change (const char *name, GVariant *property)
{
    if (g_strcmp0(name, "State") == 0) {
        state_changed (g_variant_get_string (property, NULL));
    } else if (g_strcmp0(name, "Name") == 0) {
        name_changed (g_variant_get_string (property, NULL));
    } else if (g_strcmp0(name, "Services") == 0) {
        GVariantIter *service_array, *services;
        GVariant *spec_val;

        g_variant_get (property, "a(a{sv})", &service_array);
        while (g_variant_iter_loop (service_array, "(a{sv})", &services)) {
            const char *service_name;
            while (g_variant_iter_loop (services, "{sv}", &service_name, &spec_val)) {
                if (g_strcmp0 (service_name, "WiFiDisplayIEs") == 0) {
                    uint8_t *bytes;
                    gsize length;

                    bytes = (uint8_t*)g_variant_get_fixed_array (spec_val, &length, 1);
                    std::unique_ptr<P2P::InformationElementArray> array
                            (new P2P::InformationElementArray(length, bytes));
                    ie_.reset(new P2P::InformationElement (array));
                }
            }
        }
        g_variant_iter_free (service_array);
    } else if (g_strcmp0(name, "IPv4") == 0) {
        GVariantIter *ips;
        GVariant *spec_val;
        char *name;
        const char *remote = "";
        const char *local = "";

        g_variant_get (property, "a{sv}", &ips);
        while (g_variant_iter_loop (ips, "{sv}", &name, &spec_val)) {
            if (g_strcmp0 (name, "Remote") == 0) {
                remote = g_variant_get_string (spec_val, NULL);
            } else if (g_strcmp0 (name, "Local") == 0) {
                local = g_variant_get_string (spec_val, NULL);
            }
        }
        ips_changed (remote, local);

        g_variant_iter_free (ips);
    }
}
Exemplo n.º 9
0
gboolean
login1_service_connect (Login1Service *service)
{
    GVariant *result;
    GVariantIter *seat_iter;
    const gchar *id, *path;
    GError *error = NULL;

    g_return_val_if_fail (service != NULL, FALSE);

    if (service->priv->connected)
        return TRUE;

    service->priv->connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
    if (error)
        g_warning ("Failed to get system bus: %s", error->message);
    g_clear_error (&error);
    if (!service->priv->connection)
        return FALSE;

    service->priv->signal_id = g_dbus_connection_signal_subscribe (service->priv->connection,
                                                                   LOGIN1_SERVICE_NAME,
                                                                   LOGIN1_MANAGER_INTERFACE_NAME,
                                                                   NULL,
                                                                   LOGIN1_OBJECT_NAME,
                                                                   NULL,
                                                                   G_DBUS_SIGNAL_FLAGS_NONE,
                                                                   signal_cb,
                                                                   g_object_ref (service),
                                                                   g_object_unref);

    result = g_dbus_connection_call_sync (service->priv->connection,
                                          LOGIN1_SERVICE_NAME,
                                          LOGIN1_OBJECT_NAME,
                                          LOGIN1_MANAGER_INTERFACE_NAME,
                                          "ListSeats",
                                          g_variant_new ("()"),
                                          G_VARIANT_TYPE ("(a(so))"),
                                          G_DBUS_CALL_FLAGS_NONE,
                                          -1,
                                          NULL,
                                          &error);
    if (error)
        g_warning ("Failed to get list of logind seats: %s", error->message);
    g_clear_error (&error);
    if (!result)
        return FALSE;

    g_variant_get (result, "(a(so))", &seat_iter);
    while (g_variant_iter_loop (seat_iter, "(&s&o)", &id, &path))
        add_seat (service, id, path);
    g_variant_iter_free (seat_iter);
    g_variant_unref (result);

    service->priv->connected = TRUE;

    return TRUE;
}
Exemplo n.º 10
0
static OlLyricSourceCandidate *
ol_lyric_source_candidate_new_with_variant (GVariant *dict)
{
  ol_log_func ();
  OlLyricSourceCandidate *candidate = NULL;
  GVariantIter *dictiter = NULL;
  gchar *key = NULL;
  gchar *title, *artist, *album, *comment, *sourceid;
  GVariant *downloadinfo = NULL;
  GVariant *value = NULL;
  title = artist = album = comment = sourceid = NULL;
  g_variant_get (dict, "a{sv}", &dictiter);
  while (g_variant_iter_loop (dictiter, "{sv}", &key, &value))
  {
    if (strcmp (key, "title") == 0 && title == NULL)
    {
      title = g_variant_dup_string (value, NULL);
    }
    else if (strcmp (key, "artist") == 0 && artist == NULL)
    {
      artist = g_variant_dup_string (value, NULL);
    }
    else if (strcmp (key, "album") == 0 && album == NULL)
    {
      album = g_variant_dup_string (value, NULL);
    }
    else if (strcmp (key, "comment") == 0 && comment == NULL)
    {
      comment = g_variant_dup_string (value, NULL);
    }
    else if (strcmp (key, "sourceid") == 0 && sourceid == NULL)
    {
      sourceid = g_variant_dup_string (value, NULL);
    }
    else if (strcmp (key, "downloadinfo") == 0 && downloadinfo == NULL)
    {
      downloadinfo = g_variant_ref (value);
    }
    else
    {
      ol_errorf ("Unknown candidate key: %s\n", key);
    }
  }
  g_variant_iter_free (dictiter);
  candidate = ol_lyric_source_candidate_new (title,
                                             artist,
                                             album,
                                             comment,
                                             sourceid,
                                             downloadinfo);
  g_free (title);
  g_free (artist);
  g_free (album);
  g_free (comment);
  g_free (sourceid);
  g_variant_unref (downloadinfo);
  return candidate;
}
Exemplo n.º 11
0
static gboolean
scan_commit_object (OtPullData         *pull_data,
                    const char         *checksum,
                    guint               recursion_depth,
                    GCancellable       *cancellable,
                    GError            **error)
{
  gboolean ret = FALSE;
  gs_unref_variant GVariant *commit = NULL;
  gs_unref_variant GVariant *tree_contents_csum = NULL;
  gs_unref_variant GVariant *tree_meta_csum = NULL;
  GVariantIter *iter = NULL;

  if (recursion_depth > OSTREE_MAX_RECURSION)
    {
      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                   "Exceeded maximum recursion");
      goto out;
    }

#ifdef HAVE_GPGME
  if (pull_data->gpg_verify)
    {
      if (!ostree_repo_verify_commit (pull_data->repo,
                                      checksum,
                                      NULL,
                                      NULL,
                                      cancellable,
                                      error))
        goto out;
    }
#endif

  if (!ostree_repo_load_variant (pull_data->repo, OSTREE_OBJECT_TYPE_COMMIT, checksum,
                                 &commit, error))
    goto out;

  /* PARSE OSTREE_SERIALIZED_COMMIT_VARIANT */
  g_variant_get_child (commit, 6, "@ay", &tree_contents_csum);
  g_variant_get_child (commit, 7, "@ay", &tree_meta_csum);

  if (!scan_one_metadata_object (pull_data, ostree_checksum_bytes_peek (tree_contents_csum),
                                 OSTREE_OBJECT_TYPE_DIR_TREE, recursion_depth + 1,
                                 cancellable, error))
    goto out;

  if (!scan_one_metadata_object (pull_data, ostree_checksum_bytes_peek (tree_meta_csum),
                                 OSTREE_OBJECT_TYPE_DIR_META, recursion_depth + 1,
                                 cancellable, error))
    goto out;
  
  ret = TRUE;
 out:
  if (iter)
    g_variant_iter_free (iter);
  return ret;
}
Exemplo n.º 12
0
static gboolean
mtn_connman_initable_init_sync (GInitable     *initable,
                                GCancellable  *cancellable,
                                GError       **error)
{
    GInitableIface *iface_class, *parent_iface_class;
    GVariant *var, *value;
    GVariantIter *iter;
    char *key;
    MtnConnman *connman;

    connman = MTN_CONNMAN (initable);

    /* Chain up the old method */
    iface_class = G_INITABLE_GET_IFACE (initable);
    parent_iface_class = g_type_interface_peek_parent (iface_class);
    if (!parent_iface_class->init (initable, cancellable, error)) {
        return FALSE;
    }

    g_signal_connect (connman, "notify::g-name-owner",
                      G_CALLBACK (_name_owner_notify_cb), NULL);

    var = g_dbus_proxy_call_sync (G_DBUS_PROXY (connman),
                                  "GetProperties",
                                  NULL,
                                  G_DBUS_CALL_FLAGS_NONE,
                                  -1,
                                  NULL,
                                  error);
    if (!var) {
        return FALSE;
    }

    g_variant_get (var, "(a{sv})", &iter);
    while (g_variant_iter_next (iter, "{sv}", &key, &value)) {
        g_hash_table_insert (connman->priv->properties,
                             key, value);
    }
    g_variant_iter_free (iter);
    g_variant_unref (var);

    var = g_dbus_proxy_call_sync (G_DBUS_PROXY (connman),
                                  "GetServices",
                                  NULL,
                                  G_DBUS_CALL_FLAGS_NONE,
                                  -1,
                                  NULL,
                                  error);
    if (!var) {
        return FALSE;
    }

    connman->priv->services = var;

    return TRUE;
}
Exemplo n.º 13
0
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;
}
Exemplo n.º 14
0
/**
 * fcitx_input_method_get_imlist_nofree: (rename-to fcitx_input_method_get_imlist)
 * @im: A #FcitxInputMethod
 *
 * Get Fcitx all im list
 *
 * Returns: (transfer full) (element-type FcitxIMItem): A #FcitxIMItem List
 *
 * Rename to: fcitx_input_method_get_imlist
 **/
FCITX_EXPORT_API
GPtrArray*
fcitx_input_method_get_imlist_nofree(FcitxInputMethod* im)
{
    GPtrArray *array = NULL;
    GVariant* value;
    GVariantIter *iter;
    gchar *name, *unique_name, *langcode;
    gboolean enable;
    value = g_dbus_proxy_get_cached_property(G_DBUS_PROXY(im), "IMList");

    if (value == NULL) {
        GError* error = NULL;
        GVariant* result = g_dbus_connection_call_sync(g_dbus_proxy_get_connection(G_DBUS_PROXY(im)),
                           g_dbus_proxy_get_name(G_DBUS_PROXY(im)),
                           FCITX_IM_DBUS_PATH,
                           "org.freedesktop.DBus.Properties",
                           "Get",
                           g_variant_new("(ss)", FCITX_IM_DBUS_INTERFACE, "IMList"),
                           G_VARIANT_TYPE("(v)"),
                           G_DBUS_CALL_FLAGS_NONE,
                           -1,           /* timeout */
                           NULL,
                           &error);

        if (error) {
            g_warning("%s", error->message);
            g_error_free(error);
        } else if (result) {
            g_variant_get(result, "(v)", &value);
            g_variant_unref(result);
        }
    }

    if (value) {
        array = g_ptr_array_new();
        g_variant_get(value, "a(sssb)", &iter);
        while (g_variant_iter_next(iter, "(sssb)", &name, &unique_name, &langcode, &enable, NULL)) {
            FcitxIMItem *item = g_slice_new(FcitxIMItem);
            item->name = name;
            item->unique_name = unique_name;
            item->langcode = langcode;
            item->enable = enable;
            g_ptr_array_add(array, item);
        }
        g_variant_iter_free(iter);

        g_variant_unref(value);
    }

    return array;
}
gboolean
set_fingerprint_label (GtkWidget *label1,
                       GtkWidget *label2)
{
        GDBusProxy *device;
        GVariant *result;
        GVariantIter *fingers;
        GError *error = NULL;

        if (manager == NULL) {
                create_manager ();
                if (manager == NULL) {
                        return FALSE;
                }
        }

        device = get_first_device ();
        if (device == NULL)
                return FALSE;

        result = g_dbus_proxy_call_sync (device, "ListEnrolledFingers", g_variant_new ("(s)", ""), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
        if (!result) {
                if (!g_dbus_error_is_remote_error (error) ||
                    strcmp (g_dbus_error_get_remote_error(error), "net.reactivated.Fprint.Error.NoEnrolledPrints") != 0) {
                        g_object_unref (device);
                        return FALSE;
                }
        }

        if (result && g_variant_is_of_type (result, G_VARIANT_TYPE ("(as)")))
                g_variant_get (result, "(as)", &fingers);
        else
                fingers = NULL;

        if (fingers == NULL || g_variant_iter_n_children (fingers) == 0) {
                is_disable = FALSE;
                gtk_label_set_text (GTK_LABEL (label1), _("Disabled"));
                gtk_label_set_text (GTK_LABEL (label2), _("Disabled"));
        } else {
                is_disable = TRUE;
                gtk_label_set_text (GTK_LABEL (label1), _("Enabled"));
                gtk_label_set_text (GTK_LABEL (label2), _("Enabled"));
        }

        if (result != NULL)
                g_variant_unref (result);
        if (fingers != NULL)
                g_variant_iter_free (fingers);
        g_object_unref (device);

        return TRUE;
}
Exemplo n.º 16
0
void on_menu_changed(gpointer instance, GVariant *parameters, gpointer user_data)
{
  WorkraveApplet *applet = (WorkraveApplet *)user_data;
  applet->inhibit++;

  GVariantIter *iter;
  g_variant_get (parameters, "(a(sii))", &iter);

  char *text;
  int id;
  int flags;

  gboolean visible[sizeof(menu_data)/sizeof(struct Menuitems)];
  for (int i = 0; i < sizeof(menu_data)/sizeof(struct Menuitems); i++)
    {
      visible[i] = menu_data[i].visible_when_not_running;
    }

  while (g_variant_iter_loop(iter, "(sii)", &text, &id, &flags))
    {
      int index = lookup_menu_index_by_id((enum MenuCommand)id);
      if (index == -1)
        {
          continue;
        }

      GtkAction *action = gtk_action_group_get_action(applet->action_group, menu_data[index].action);

      if (flags & MENU_ITEM_FLAG_SUBMENU_END ||
          flags & MENU_ITEM_FLAG_SUBMENU_BEGIN)
        {
          continue;
        }

      visible[index] = TRUE;

      if (GTK_IS_TOGGLE_ACTION(action))
        {
          GtkToggleAction *toggle = GTK_TOGGLE_ACTION(action);
          gtk_toggle_action_set_active(toggle, flags & MENU_ITEM_FLAG_ACTIVE);
        }
    }

  g_variant_iter_free (iter);

  for (int i = 0; i < sizeof(menu_data)/sizeof(struct Menuitems); i++)
    {
      GtkAction *action = gtk_action_group_get_action(applet->action_group, menu_data[i].action);
      gtk_action_set_visible(action, visible[i]);
    }
  applet->inhibit--;
}
Exemplo n.º 17
0
static void process_proplist(void *data, GVariant *props,
			     void (*func)(void *data,
					  const char *k, GVariant *val))
{
	GVariantIter *iter;
	const char *key;
	GVariant *value;
	g_variant_get (props, "(a{sv})", &iter);
	while (g_variant_iter_loop (iter, "{sv}", &key, &value)) {
		func(data, key, value);
	}
	g_variant_iter_free(iter);
}
static void
poll_with_variant (GPid pid,
                   GVariant *info,
                   GError *error,
                   gpointer user_data)
{
    StoragedLinuxVolumeGroupObject *object = user_data;
    StoragedDaemon *daemon;
    GVariantIter *iter;
    gboolean needs_polling;

    if (pid != object->poll_pid)
    {
        g_object_unref (object);
        return;
    }

    object->poll_pid = 0;

    if (error)
    {
        storaged_warning ("Failed to poll LVM volume group %s: %s",
                          storaged_linux_volume_group_object_get_name (object),
                          error->message);
        g_object_unref (object);
        return;
    }

    daemon = storaged_linux_volume_group_object_get_daemon (object);

    storaged_linux_volume_group_update (STORAGED_LINUX_VOLUME_GROUP (object->iface_volume_group), info, &needs_polling);

    if (g_variant_lookup (info, "lvs", "aa{sv}", &iter))
    {
        GVariant *lv_info = NULL;
        while (g_variant_iter_loop (iter, "@a{sv}", &lv_info))
        {
            const gchar *name;
            StoragedLinuxLogicalVolumeObject *volume;

            g_variant_lookup (lv_info, "name", "&s", &name);
            update_operations (daemon, name, lv_info, &needs_polling);
            volume = g_hash_table_lookup (object->logical_volumes, name);
            if (volume)
                storaged_linux_logical_volume_object_update (volume, lv_info, &needs_polling);
        }
        g_variant_iter_free (iter);
    }

    g_object_unref (object);
}
Exemplo n.º 19
0
static void
list_seats (GDBusConnection *connection)
{
        GDBusProxy   *proxy;
        GError       *error;
        GVariant     *res;
        GVariantIter *iter;
        gchar        *path = NULL;

        proxy = g_dbus_proxy_new_sync (connection,
                                       G_DBUS_PROXY_FLAGS_NONE,
                                       NULL,
                                       CK_NAME,
                                       CK_MANAGER_PATH,
                                       CK_MANAGER_INTERFACE,
                                       NULL,
                                       &error);

        if (proxy == NULL) {
                g_print ("error creating proxy, %s", error->message);
                g_clear_error (&error);
                return;
        }

        error = NULL;
        res = g_dbus_proxy_call_sync (proxy,
                                      "GetSeats",
                                      g_variant_new ("()"),
                                      G_DBUS_CALL_FLAGS_NONE,
                                      6000,
                                      NULL,
                                      &error);

        if (res == NULL) {
                g_warning ("Failed to get list of seats: %s", error->message);
                g_clear_error (&error);
                goto out;
        }

        g_variant_get (res, "(ao)", &iter);
        while (g_variant_iter_next (iter, "o", &path))
        {
                list_sessions (connection, path);
        }
        g_variant_iter_free (iter);
        g_variant_unref (res);

 out:
        g_object_unref (proxy);
}
static void on_response_sap_transfer_apdu(GObject *source_object, GAsyncResult *res, gpointer user_data)
{
	GError *error = NULL;
	GDBusConnection *conn = NULL;
	GVariant *dbus_result;

	GVariantIter *iter = NULL;
	GVariant *param_gv = NULL;
	GVariant *inner_gv = NULL;
	guchar rt_i;
	int i = 0;

	struct tapi_resp_data *evt_cb_data = user_data;
	TelSimSapResultCode_t result = TAPI_SIM_SAP_RESULT_CODE_OK;
	TelSapApduData_t r_apdu;

	dbg("Func Entrance");
	memset(&r_apdu, 0, sizeof(TelSapApduData_t));

	conn = G_DBUS_CONNECTION (source_object);
	dbus_result = g_dbus_connection_call_finish(conn, res, &error);

	if (dbus_result) {
		/*	dbg("dbus_result type_format(%s)", g_variant_get_type_string(dbus_result));*/
		g_variant_get(dbus_result, "(i@v)", &result, &param_gv);
		inner_gv = g_variant_get_variant(param_gv);

		g_variant_get(inner_gv, "ay", &iter);
		while (g_variant_iter_loop(iter, "y", &rt_i)) {
			r_apdu.apdu_data[i] = rt_i;
			i++;
		}
		r_apdu.apdu_len = (int) i;
		g_variant_iter_free(iter);
		g_variant_unref(inner_gv);
		g_variant_unref(param_gv);
		/*		for(i=0; i < (int)r_apdu.apdu_len; i++)
		 dbg("apdu[%d][0x%02x]",i, r_apdu.apdu_data[i]);*/
	}
	else {
		result = TAPI_SIM_SAP_RESULT_CODE_DATA_NOT_AVAILABLE;
		dbg( "g_dbus_conn failed. error (%s)", error->message);
		g_error_free(error);
	}
	if (evt_cb_data->cb_fn) {
		evt_cb_data->cb_fn(evt_cb_data->handle, result, (void*)&r_apdu, evt_cb_data->user_data);
	}

	free(evt_cb_data);
}
static GDBusProxy *
login_dbus_proxy_new (void)
{
  GError *error = NULL;
  GDBusProxy *dbus_proxy =
    g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
                                   G_DBUS_PROXY_FLAGS_NONE,
                                   NULL /* GDBusInterfaceInfo */,
                                   "org.freedesktop.login1",
                                   "/org/freedesktop/login1",
                                   "org.freedesktop.login1.Manager",
                                   NULL /* GCancellable */,
                                   &error);
  if (error)
    {
      g_warning ("Error creating GDBusProxy: %s.", error->message);
      g_error_free (error);
      return NULL;
    }

  g_signal_connect (dbus_proxy, "g-signal", G_CALLBACK (record_login),
                    NULL /* data */);

  GVariant *sessions =
    g_dbus_proxy_call_sync (dbus_proxy, "ListSessions", NULL,
                            G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
  if (error)
    {
      g_warning ("Error calling ListSessions: %s.", error->message);
      g_error_free (error);
      return NULL;
    }

  GVariantIter *session_iter;
  g_variant_get (sessions, "(a(susso))", &session_iter);

  const gchar *session_id;
  guint32 user_id;
  while (g_variant_iter_loop (session_iter, "(&suss&o)", &session_id,
                              &user_id, NULL, NULL, NULL))
    {
      add_session (session_id, user_id);
    }

  g_variant_iter_free (session_iter);
  g_variant_unref (sessions);

  return dbus_proxy;
}
Exemplo n.º 22
0
static void
on_channel_update (GDBusConnection *connection,
                   const gchar *sender_name,
                   const gchar *object_path,
                   const gchar *interface_name,
                   const gchar *signal_name,
                   GVariant *parameters,
                   ReaderEngine *engine)
{
	GVariantIter *iter1, *iter2;
	gchar *class_name;
	gint graph = 0, subject = 0, predicate = 0, object = 0;

	g_variant_get (parameters, "(&sa(iiii)a(iiii))", &class_name, &iter1, &iter2);

	while (g_variant_iter_loop (iter1, "(iiii)", &graph, &subject, &predicate, &object))
		handle_channel_deletes (engine, subject);

	while (g_variant_iter_loop (iter2, "(iiii)", &graph, &subject, &predicate, &object))
		handle_channel_inserts (engine, subject);

	g_variant_iter_free (iter1);
	g_variant_iter_free (iter2);
}
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);
    }
}
Exemplo n.º 24
0
static void
ol_config_proxy_value_changed_cb (OlConfigProxy *proxy,
                                  GVariant *parameters)
{
  GVariantIter *iter = NULL;
  g_variant_get (parameters, "(as)", &iter);
  gchar *name = NULL;
  while (g_variant_iter_loop (iter, "s", &name))
  {
    g_signal_emit (proxy,
                   _signals[SIGNAL_CHANGED],
                   g_quark_from_string (name),
                   name);
  }
  g_variant_iter_free (iter);
}
Exemplo n.º 25
0
static void
names_listed (GObject      *object,
              GAsyncResult *result,
              gpointer      user_data)
{
  NamespaceWatcher *watcher;
  GError *error = NULL;
  GVariant *reply;
  GVariantIter *iter;
  const gchar *name;

  reply = g_dbus_connection_call_finish (G_DBUS_CONNECTION (object), result, &error);

  if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
    {
      g_error_free (error);
      return;
    }

  watcher = user_data;

  if (reply == NULL)
    {
      g_warning ("bus_watch_namespace: error calling org.freedesktop.DBus.ListNames: %s", error->message);
      g_error_free (error);
      return;
    }

  g_variant_get (reply, "(as)", &iter);
  while (g_variant_iter_next (iter, "&s", &name))
    {
      if (dbus_name_has_namespace (name, watcher->name_space))
        {
          GetNameOwnerData *data = g_slice_new (GetNameOwnerData);
          data->watcher = watcher;
          data->name = g_strdup (name);
          g_dbus_connection_call (watcher->connection, "org.freedesktop.DBus", "/",
                                  "org.freedesktop.DBus", "GetNameOwner",
                                  g_variant_new ("(s)", name), G_VARIANT_TYPE ("(s)"),
                                  G_DBUS_CALL_FLAGS_NONE, -1, watcher->cancellable,
                                  got_name_owner, data);
        }
    }

  g_variant_iter_free (iter);
  g_variant_unref (reply);
}
Exemplo n.º 26
0
static void
poll_with_variant (GPid pid,
                   GVariant *info,
                   GError *error,
                   gpointer user_data)
{
  StorageVolumeGroup *self = user_data;
  GVariantIter *iter;
  gboolean needs_polling;

  if (pid != self->poll_pid)
    {
      g_object_unref (self);
      return;
    }

  self->poll_pid = 0;

  if (error)
    {
      g_message ("Failed to poll LVM volume group %s: %s",
                 storage_volume_group_get_name (self), error->message);
      g_object_unref (self);
      return;
    }

  volume_group_update_props (self, info, &needs_polling);

  if (g_variant_lookup (info, "lvs", "aa{sv}", &iter))
    {
      GVariant *lv_info = NULL;
      while (g_variant_iter_loop (iter, "@a{sv}", &lv_info))
        {
          const gchar *name;
          StorageLogicalVolume *volume;

          g_variant_lookup (lv_info, "name", "&s", &name);
          update_operations (name, lv_info, &needs_polling);
          volume = g_hash_table_lookup (self->logical_volumes, name);
          if (volume)
            storage_logical_volume_update (volume, self, lv_info, &needs_polling);
        }
      g_variant_iter_free (iter);
    }

  g_object_unref (self);
}
Exemplo n.º 27
0
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;
}
Exemplo n.º 28
0
static gchar *
get_profile_for_window (GdkWindow *window)
{
  GError *error = NULL;
  guint xid;
  gchar *icc_profile = NULL;
  GVariant *args = NULL;
  GVariant *response = NULL;
  GVariant *response_child = NULL;
  GVariantIter *iter = NULL;

  /* get color profile */
  xid = GDK_WINDOW_XID (window);
  args = g_variant_new ("(u)", xid),
  response = g_dbus_connection_call_sync (connection,
                                          "org.gnome.ColorManager",
                                          "/org/gnome/ColorManager",
                                          "org.gnome.ColorManager",
                                          "GetProfileForWindow",
                                          args,
                                          G_VARIANT_TYPE ("(s)"),
                                          G_DBUS_CALL_FLAGS_NONE,
                                          -1, NULL, &error);
  if (response == NULL)
    {
      /* not a warning, as GCM might not be installed / running */
      g_debug ("The GetProfileForWindow request failed: %s",
               error->message);
      g_error_free (error);
      goto out;
    }

  /* get icc profile filename */
  response_child = g_variant_get_child_value (response, 0);
  icc_profile = g_variant_dup_string (response_child, NULL);
out:
  if (iter != NULL)
    g_variant_iter_free (iter);
  if (args != NULL)
    g_variant_unref (args);
  if (response != NULL)
    g_variant_unref (response);
  return icc_profile;
}
Exemplo n.º 29
0
static void
ol_lyric_source_search_complete_cb (OlLyricSource *source,
                                    GVariant *parameters)
{
  GVariantIter *iter = NULL;
  GVariant *dict = NULL;
  GList *result = NULL;
  gint taskid;
  gint statusid;
  OlLyricSourceTask *task;
  g_variant_get (parameters, "(iiaa{sv})", &taskid, &statusid, &iter);
  task = ol_lyric_source_get_search_task (source, taskid);
  if (task == NULL)
  {
    ol_errorf ("Search task %d not exist\n", taskid);
    return;
  }
  if (statusid < 0 || statusid > OL_LYRIC_SOURCE_STATUS_FALIURE)
  {
    ol_errorf ("Invalid search status %d\n", statusid);
    return;
  }
  while (g_variant_iter_loop (iter, "@a{sv}", &dict))
  {
    OlLyricSourceCandidate *candidate;
    candidate = ol_lyric_source_candidate_new_with_variant (dict);
    result = g_list_prepend (result, candidate);
  }
  g_variant_iter_free (iter);
  result = g_list_reverse (result);
  g_signal_emit (task,
                 _search_signals[SEARCH_SIGNAL_COMPLETE],
                 0,
                 statusid,
                 result);
  while (result)
  {
    OlLyricSourceCandidate *candidate = result->data;
    g_object_unref (candidate);
    result = g_list_delete_link (result, result);
  }
  ol_lyric_source_remove_search_task (source, taskid);
}
Exemplo n.º 30
0
static void
xfpm_dump_remote (GDBusConnection *bus)
{
    XfpmPowerManager *proxy;
    GError *error = NULL;
    GVariant *config;
    GVariantIter *iter;
    GHashTable *hash;
    gchar *key, *value;
    
    proxy = xfpm_power_manager_proxy_new_sync (bus,
					       G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
					       G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
					       "org.xfce.PowerManager",
					       "/org/xfce/PowerManager",
					       NULL,
					       NULL);
	
    xfpm_power_manager_call_get_config_sync (proxy,
					     &config,
					     NULL,
					     &error);
					     
    g_object_unref (proxy);
    
    if ( error )
    {
	g_error ("%s", error->message);
	exit (EXIT_FAILURE);
    }

    hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
    g_variant_get (config, "a{ss}", &iter);
    while (g_variant_iter_next (iter, "{ss}", &key, &value))
    {
        g_hash_table_insert (hash, key, value);
    }
    g_variant_iter_free (iter);
    g_variant_unref (config);
    
    xfpm_dump (hash);
    g_hash_table_destroy (hash);
}