Exemplo n.º 1
0
static void remmina_file_manager_add_group(GNode* node, const gchar* group)
{
	gint cmp;
	gchar* p1;
	gchar* p2;
	GNode* child;
	gboolean found;
	RemminaGroupData* data;

	if (group == NULL || group[0] == '\0')
		return;

	p1 = g_strdup(group);
	p2 = strchr(p1, '/');

	if (p2)
		*p2++ = '\0';

	found = FALSE;

	for (child = g_node_first_child(node); child; child = g_node_next_sibling(child))
	{
		cmp = g_strcmp0(((RemminaGroupData*) child->data)->name, p1);

		if (cmp == 0)
		{
			found = TRUE;
			break;
		}

		if (cmp > 0)
			break;
	}

	if (!found)
	{
		data = g_new0(RemminaGroupData, 1);
		data->name = p1;
		if (node->data)
		{
			data->group = g_strdup_printf("%s/%s", ((RemminaGroupData*) node->data)->group, p1);
		}
		else
		{
			data->group = g_strdup(p1);
		}
		if (child)
		{
			child = g_node_insert_data_before(node, child, data);
		}
		else
		{
			child = g_node_append_data(node, data);
		}
	}
	remmina_file_manager_add_group(child, p2);

	if (found)
	{
		g_free(p1);
	}
}
Exemplo n.º 2
0
static void
ltable_insert(LTable* lt, const gchar* where, Listener* l)
{
  gchar** dirnames;
  guint i;
  GNode* cur;
  GNode* found = NULL;
  LTableEntry* lte;
  const gchar* noroot_where = where + 1;

  g_return_if_fail(mateconf_valid_key(where, NULL));
  
  if (lt->tree == NULL)
    {
      lte = ltable_entry_new(NULL, 0);
      
      lt->tree = g_node_new(lte);

      lte = NULL; /* paranoia */
    }
  
  /* Add to the tree */
  dirnames = g_strsplit(noroot_where, "/", -1);
  
  cur = lt->tree;
  i = 0;
  while (dirnames[i])
    {
      LTableEntry* ne;
      GNode* across;

      /* Find this dirname on this level, or add it. */
      g_assert (cur != NULL);        

      found = NULL;

      across = cur->children;

      while (across != NULL)
        {
          int cmp;

          lte = across->data;

          cmp = strcmp(lte->name, dirnames[i]);

          if (cmp == 0)
            {
              found = across;
              break;
            }
          else if (cmp > 0)
            {
              /* Past it */
              break;
            }
          else 
            {
              across = g_node_next_sibling(across);
            }
        }

      if (found == NULL)
        {
          ne = ltable_entry_new(dirnames, i);
              
          if (across != NULL) /* Across is at the one past */
            found = g_node_insert_data_before(cur, across, ne);
          else                /* Never went past, append - could speed this up by saving last visited */
            found = g_node_append_data(cur, ne);
        }

      g_assert(found != NULL);

      cur = found;

      ++i;
    }

  /* cur is still the root node ("/") if where was "/" since nothing
     was returned from g_strsplit */
  lte = cur->data;

  lte->listeners = g_list_prepend(lte->listeners, l);

  g_strfreev(dirnames);

  /* Add tree node to the flat table */
  g_ptr_array_set_size(lt->listeners, MAX(CNXN_ID_INDEX(lt->next_cnxn), CNXN_ID_INDEX(l->cnxn)));
  g_ptr_array_index(lt->listeners, CNXN_ID_INDEX(l->cnxn)) = cur;

  lt->active_listeners += 1;

#ifdef DEBUG_LISTENERS
  g_print ("Added %u at %s, spewing:\n",
	   l->cnxn, where);
  ltable_spew(lt);
#endif
}