Example #1
0
RESULT
test_slist_index ()
{
	int i;
	char *foo = "foo";
	char *bar = "bar";
	char *baz = "baz";
	GSList *list;
	list = g_slist_prepend (NULL, baz);
	list = g_slist_prepend (list, bar);
	list = g_slist_prepend (list, foo);

	i = g_slist_index (list, foo);
	if (i != 0)
		return FAILED ("index failed. #0: %d", i);

	i = g_slist_index (list, bar);
	if (i != 1)
		return FAILED ("index failed. #1: %d", i);
	
	i = g_slist_index (list, baz);
	if (i != 2)
		return FAILED ("index failed. #2: %d", i);

	g_slist_free (list);
	return OK;
}
Example #2
0
static void
main_window_view_sort_contacts_cb (GtkRadioAction    *action,
				   GtkRadioAction    *current,
				   EmpathyMainWindow *window)
{
	EmpathyContactListStoreSort value;
	GSList      *group;
	GType        type;
	GEnumClass  *enum_class;
	GEnumValue  *enum_value;

	value = gtk_radio_action_get_current_value (action);
	group = gtk_radio_action_get_group (action);

	/* Get string from index */
	type = empathy_contact_list_store_sort_get_type ();
	enum_class = G_ENUM_CLASS (g_type_class_peek (type));
	enum_value = g_enum_get_value (enum_class, g_slist_index (group, current));

	if (!enum_value) {
		g_warning ("No GEnumValue for EmpathyContactListSort with GtkRadioAction index:%d",
			   g_slist_index (group, action));
	} else {
		empathy_conf_set_string (empathy_conf_get (),
					 EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
					 enum_value->value_nick);
	}
	empathy_contact_list_store_set_sort_criterium (window->list_store, value);
}
Example #3
0
gboolean
vinagre_bookmarks_entry_remove_child (VinagreBookmarksEntry *entry,
				      VinagreBookmarksEntry *child)
{
  GSList *l;

  g_return_val_if_fail (VINAGRE_IS_BOOKMARKS_ENTRY (entry), FALSE);
  g_return_val_if_fail (VINAGRE_IS_BOOKMARKS_ENTRY (child), FALSE);

  if (g_slist_index (entry->priv->children, child) > -1)
    {
      entry->priv->children = g_slist_remove (entry->priv->children, child);
      return TRUE;
    }

  for (l = entry->priv->children; l; l = l->next)
    {
      VinagreBookmarksEntry *e = (VinagreBookmarksEntry *) l->data;

      if (vinagre_bookmarks_entry_get_node (e) != VINAGRE_BOOKMARKS_ENTRY_NODE_FOLDER)
	continue;

      if (vinagre_bookmarks_entry_remove_child (e, child))
	return TRUE;
    }

  return FALSE;
}
Example #4
0
static void channel_config_remove(SETUP_CHANNEL_REC *channel)
{
	CONFIG_NODE *node;

	node = iconfig_node_traverse("channels", FALSE);
	if (node != NULL) iconfig_node_list_remove(node, g_slist_index(setupchannels, channel));
}
Example #5
0
void setupserver_config_remove(SETUP_SERVER_REC *rec)
{
	CONFIG_NODE *node;

	node = iconfig_node_traverse("servers", FALSE);
	if (node != NULL) iconfig_node_list_remove(node, g_slist_index(setupservers, rec));
}
Example #6
0
GSList *procmsg_find_children_func(MsgInfo *info, 
				   GSList *children, GSList *all)
{
	GSList *cur;

	g_return_val_if_fail(info!=NULL, children);
	if (info->msgid == NULL)
		return children;

	for (cur = all; cur != NULL; cur = g_slist_next(cur)) {
		MsgInfo *tmp = (MsgInfo *)cur->data;
		if (tmp->inreplyto && !strcmp(tmp->inreplyto, info->msgid)) {
			/* Check if message is already in the list */
			if ((children == NULL) || 
			    (g_slist_index(children, tmp) == -1)) {
				children = g_slist_prepend(children,
						procmsg_msginfo_new_ref(tmp));
				children = procmsg_find_children_func(tmp, 
							children, 
							all);
			}
		}
	}
	return children;
}
Example #7
0
int GtkToolkitFileChooser::GetSelectedFilter()
{
	GSList* list = gtk_file_chooser_list_filters(GTK_FILE_CHOOSER(m_dialog));
	GtkFileFilter* selected_filter = gtk_file_chooser_get_filter(GTK_FILE_CHOOSER(m_dialog));

	return g_slist_index(list, selected_filter);
}
Example #8
0
CONFIG_NODE *config_node_section_index(CONFIG_NODE *parent, const char *key,
				       int index, int new_type)
{
	CONFIG_NODE *node;
        int nindex;

	g_return_val_if_fail(parent != NULL, NULL);
	g_return_val_if_fail(is_node_list(parent), NULL);

	node = key == NULL ? NULL : config_node_find(parent, key);
	if (node != NULL) {
		g_return_val_if_fail(new_type == -1 || new_type == node->type, NULL);
		nindex = g_slist_index(parent->value, node);
		if (index >= 0 && nindex != index &&
		    nindex <= g_slist_length(parent->value)) {
			/* move it to wanted position */
			parent->value = g_slist_remove(parent->value, node);
			parent->value = g_slist_insert(parent->value, node, index);
		}
		return node;
	}

	if (new_type == -1)
		return NULL;

	node = g_new0(CONFIG_NODE, 1);
	parent->value = index < 0 ? g_slist_append(parent->value, node) :
		g_slist_insert(parent->value, node, index);

	node->type = new_type;
	node->key = key == NULL ? NULL : g_strdup(key);

	return node;
}
static void
scrollmethod_clicked_event (GtkWidget *widget,
				GtkBuilder *dialog)
{
	GtkToggleButton *disabled = GTK_TOGGLE_BUTTON (WID ("scroll_disabled_radio"));

	gtk_widget_set_sensitive (WID ("horiz_scroll_toggle"),
				  !gtk_toggle_button_get_active (disabled));

	gtk_widget_set_sensitive (WID ("natural_scroll_toggle"),
				  !gtk_toggle_button_get_active (disabled));

	GSList *radio_group;
	int new_scroll_method;
	int old_scroll_method = g_settings_get_int (touchpad_settings, "scroll-method");

	if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widget)))
		return;

	radio_group = g_slist_copy (gtk_radio_button_get_group
		(GTK_RADIO_BUTTON (WID ("scroll_disabled_radio"))));
	radio_group = g_slist_reverse (radio_group);
	new_scroll_method = g_slist_index (radio_group, widget);
	g_slist_free (radio_group);
	
	if (new_scroll_method != old_scroll_method)
		g_settings_set_int (touchpad_settings, "scroll-method", new_scroll_method);
}
Example #10
0
void
nsFilePicker::ReadValuesFromFileChooser(GtkWidget *file_chooser)
{
  mFiles.Clear();

  if (mMode == nsIFilePicker::modeOpenMultiple) {
    mFileURL.Truncate();

    GSList *list = _gtk_file_chooser_get_filenames (GTK_FILE_CHOOSER(file_chooser));
    g_slist_foreach(list, ReadMultipleFiles, static_cast<gpointer>(&mFiles));
    g_slist_free(list);
  } else {
    gchar *filename = _gtk_file_chooser_get_uri (GTK_FILE_CHOOSER(file_chooser));
    mFileURL.Assign(filename);
    g_free(filename);
  }

  GtkFileFilter *filter = _gtk_file_chooser_get_filter (GTK_FILE_CHOOSER(file_chooser));
  GSList *filter_list = _gtk_file_chooser_list_filters (GTK_FILE_CHOOSER(file_chooser));

  mSelectedType = static_cast<PRInt16>(g_slist_index (filter_list, filter));
  g_slist_free(filter_list);

  // Remember last used directory.
  nsCOMPtr<nsILocalFile> file;
  GetFile(getter_AddRefs(file));
  if (file) {
    nsCOMPtr<nsIFile> dir;
    file->GetParent(getter_AddRefs(dir));
    nsCOMPtr<nsILocalFile> localDir(do_QueryInterface(dir));
    if (localDir) {
      localDir.swap(mPrevDisplayDirectory);
    }
  }
}
Example #11
0
static void event_ban_list(IRC_SERVER_REC *server, const char *data)
{
    IRC_CHANNEL_REC *chanrec;
    BAN_REC *banrec;
    const char *channel;
    char *params, *ban, *setby, *tims;
    long secs;

    g_return_if_fail(data != NULL);

    params = event_get_params(data, 5, NULL, &channel,
                              &ban, &setby, &tims);
    secs = *tims == '\0' ? 0 :
           (long) (time(NULL) - atol(tims));

    chanrec = irc_channel_find(server, channel);
    banrec = chanrec == NULL ? NULL : banlist_find(chanrec->banlist, ban);

    channel = get_visible_target(server, channel);
    printformat(server, channel, MSGLEVEL_CRAP,
                *setby == '\0' ? IRCTXT_BANLIST : IRCTXT_BANLIST_LONG,
                banrec == NULL ? 0 : g_slist_index(chanrec->banlist, banrec)+1,
                channel, ban, setby, secs);

    g_free(params);
}
Example #12
0
static void hilight_remove_config(HILIGHT_REC *rec)
{
    CONFIG_NODE *node;

    g_return_if_fail(rec != NULL);

    node = iconfig_node_traverse("hilights", FALSE);
    if (node != NULL) iconfig_node_list_remove(node, g_slist_index(hilights, rec));
}
Example #13
0
static void bipartite_graph_test_node(graph_t * graph, int i)
{
    GSList *neighbours = graph_get_neighbours_of(graph, i);
    
    int j = (i % 2 == 0) ? 1 : 0;
    for(; j < graph->n; j += 2)
    {
        g_assert(g_slist_index(neighbours, GINT_TO_POINTER(j)) != -1);
    }
}
Example #14
0
/**
 * gda_batch_remove_statement:
 * @batch: a #GdaBatch object
 * @stmt: a statement to remove from @batch's statements list
 *
 * Removes @stmt from the list of statements managed by @batch. If @stmt is present several
 * times in @batch's statements' list, then only the first one is removed.
 */
void
gda_batch_remove_statement (GdaBatch *batch, GdaStatement *stmt)
{
	g_return_if_fail (GDA_IS_BATCH (batch));
	g_return_if_fail (batch->priv);
	g_return_if_fail (GDA_IS_STATEMENT (stmt));

	if (g_slist_index (batch->priv->statements, stmt) < 0) {
		g_warning (_("Statement could not be found in batch's statements"));
		return;
	}

	batch->priv->statements = g_slist_remove (batch->priv->statements, stmt);
	if (g_slist_index (batch->priv->statements, stmt) < 0) 
		/* @stmt is no more in @batch's list */
		g_signal_handlers_disconnect_by_func (G_OBJECT (stmt),
						      G_CALLBACK (stmt_reset_cb), batch);
	g_object_unref (stmt);
}
Example #15
0
static void
search_type_cb (GtkToggleButton *button, GNCSearchWindow *sw)
{
    GSList * buttongroup = gtk_radio_button_get_group (GTK_RADIO_BUTTON(button));

    if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
    {
        sw->search_type =
            g_slist_length (buttongroup) - g_slist_index (buttongroup, button) - 1;
    }
}
Example #16
0
static void server_setup_remove_config(SERVER_SETUP_REC *rec)
{
	CONFIG_NODE *node;
	int index;

	node = iconfig_node_traverse("servers", FALSE);
	if (node != NULL) {
		index = g_slist_index(setupservers, rec);
		iconfig_node_list_remove(node, index);
	}
}
Example #17
0
/* Add a child before another child. after == NULL means append.
 */
void
icontainer_child_add_before( iContainer *parent, 
	iContainer *child, iContainer *before )
{
	int pos;

	g_assert( !before || IS_ICONTAINER( before ) );
	g_assert( !before || before->parent == parent );

	pos = g_slist_index( parent->children, before );
	icontainer_child_add( parent, child, pos );
}
Example #18
0
/* Returns index for given key */
int config_node_index(CONFIG_NODE *parent, const char *key)
{
	CONFIG_NODE *node;

	g_return_val_if_fail(parent != NULL, -1);
	g_return_val_if_fail(key != NULL, -1);

	node = config_node_find(parent, key);
	if (node == NULL)
		return -1;

        return g_slist_index(parent->value, node);
}
Example #19
0
static void
ctw_button_cb (GtkToggleButton *button, gpointer data)
{
    MTClosure *mt = data;

    if (gtk_toggle_button_get_active (button)) {
	GSList *group;

	group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (button));
	mt_service_set_clicktype (mt->service, 
				  g_slist_index (group, button),
				  NULL);
    }
}
Example #20
0
static void
ctw_menu_toggled (GtkCheckMenuItem *item, gpointer data)
{
    MTClosure *mt = data;
    GSList *group;
    gint index;

    if (!gtk_check_menu_item_get_active (item))
	return;

    group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (item));
    index = g_slist_index (group, item);
    gconf_client_set_int (mt->client, OPT_STYLE, index, NULL);
}
Example #21
0
static void
preferences_radio_button_toggled_cb (GtkWidget *button,
				     gpointer   user_data)
{
	const gchar *key;
	const gchar *value = NULL;

	if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button))) {
		return;
	}

	key = g_object_get_data (G_OBJECT (button), "key");

	if (key && strcmp (key, EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM) == 0) {
		GSList      *group;
		GType        type;
		GEnumClass  *enum_class;
		GEnumValue  *enum_value;
		
		group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (button));
		
		/* Get string from index */
		type = empathy_contact_list_store_sort_get_type ();
		enum_class = G_ENUM_CLASS (g_type_class_peek (type));
		enum_value = g_enum_get_value (enum_class, g_slist_index (group, button));
		
		if (!enum_value) {
			g_warning ("No GEnumValue for EmpathyContactListSort with GtkRadioButton index:%d", 
				   g_slist_index (group, button));
			return;
		}

		value = enum_value->value_nick;
	}

	empathy_conf_set_string (empathy_conf_get (), key, value);
}
Example #22
0
static void _e2_option_sel_activated_cb (GtkMenuItem *menu_item, E2_OptionSet *set)
{
	GtkWidget *controller = g_object_get_data (G_OBJECT (menu_item),
		"e2-controller-widget");
	if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (controller),
		"e2-controller-blocked")))
			return;
	if (!gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (menu_item)))
		return;
//	NEEDCLOSEBGL
	GSList *group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (menu_item));
//	NEEDOPENBGL
	gint index = 2 - g_slist_index (group, menu_item);
	e2_option_sel_set_direct (set, index);
}
Example #23
0
static void key_next_window_item(void)
{
	SERVER_REC *server;
	int index;

	if (active_win->items != NULL)
		signal_emit("command window item next", 3, "", active_win->active_server, active_win->active);
	else if (active_win->active_server != NULL) {
		/* change server */
		index = g_slist_index(servers, active_win->active_server);
		server = index > 0 ? g_slist_nth(servers, index-1)->data :
			g_slist_last(servers)->data;
		signal_emit("command window server", 3, server->tag, active_win->active_server, active_win->active);
	}
}
int FileDialog::GetFilterIndex() const
{
   GtkFileChooser *chooser = GTK_FILE_CHOOSER(m_widget);
   GtkFileFilter *filter = gtk_file_chooser_get_filter(chooser);
   GSList *filters = gtk_file_chooser_list_filters(chooser);
   gint index = g_slist_index(filters, filter);
   g_slist_free(filters);
   
   if (index == -1)
   {
      wxFAIL_MSG( wxT("FileDialog::GetFilterIndex - bad filter index returned by gtk+") );
      return 0;
   }
   else
      return index;
}
Example #25
0
static void
webx_dialog_format_changed (GtkToggleButton *togglebutton,
                            WebxDialog      *dlg)
{
  g_return_if_fail (WEBX_IS_DIALOG (dlg));

  if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (togglebutton)))
    {
      GtkWidget    *widget;
      gint          position;

      position = g_slist_index (dlg->radio_list, togglebutton);
      widget = GTK_WIDGET (g_slist_nth (dlg->target_list, position)->data);
      webx_dialog_format_set (WEBX_DIALOG (dlg), WEBX_TARGET (widget));
    }
}
Example #26
0
int wxGtkFileChooser::GetFilterIndex() const
{
    GtkFileChooser *chooser = m_widget;
    GtkFileFilter *filter = gtk_file_chooser_get_filter( chooser );
    GSList *filters = gtk_file_chooser_list_filters( chooser );
    const gint index = g_slist_index( filters, filter );
    g_slist_free( filters );

    if ( index == -1 )
    {
        wxFAIL_MSG( wxT( "wxGtkFileChooser::GetFilterIndex - bad filter index returned by gtk+" ) );
        return 0;
    }
    else
        return index;
}
Example #27
0
static void
servlist_move_server (ircserver *serv, int delta)
{
	int pos;

	pos = g_slist_index (selected_net->servlist, serv);
	if (pos >= 0)
	{
		pos += delta;
		if (pos >= 0)
		{
			selected_net->servlist = g_slist_remove (selected_net->servlist, serv);
			selected_net->servlist = g_slist_insert (selected_net->servlist, serv, pos);
			servlist_servers_populate (selected_net, edit_tree);
		}
	}
}
Example #28
0
static void
servlist_move_network (ircnet *net, int delta)
{
	int pos;

	pos = g_slist_index (network_list, net);
	if (pos >= 0)
	{
		pos += delta;
		if (pos >= 0)
		{
			network_list = g_slist_remove (network_list, net);
			network_list = g_slist_insert (network_list, net, pos);
			servlist_networks_populate (networks_tree, network_list);
		}
	}
}
Example #29
0
/* Add new idle command to specified position of queue */
int server_idle_insert(IRC_SERVER_REC *server, const char *cmd, const char *arg, int tag, int last, ...)
{
	va_list args;
	SERVER_IDLE_REC *rec;
	int pos;

	g_return_val_if_fail(server != NULL, -1);

	va_start(args, last);

	/* find the position of tag in idle list */
	rec = server_idle_find_rec(server, tag);
	pos = g_slist_index(server->idles, rec);

	rec = server_idle_create(cmd, arg, last, args);
        server->idles = pos < 0 ?
		g_slist_append(server->idles, rec) :
		g_slist_insert(server->idles, rec, pos);
	va_end(args);
	return rec->tag;
}
Example #30
0
iContainer *
icontainer_next( iContainer *parent )
{
	iContainer *child;
	int i;

	if( !parent->children ) 
		return( NULL ); 

	if( !parent->current )
		i = 0;
	else
		i = g_slist_index( parent->children, parent->current ) + 1;

	if( !(child = g_slist_nth_data( parent->children, i )) )
		child = ICONTAINER( parent->children->data );

	icontainer_current( parent, child );

	return( child ); 
}