static gboolean tree_store_drag_can_drag_cb (G_GNUC_UNUSED GdauiTreeStore *store, const gchar *path, FavoriteSelector *tsel) { GdaTreeNode *node; node = gda_tree_get_node (tsel->priv->tree, path, FALSE); if (node) { const GValue *cvalue; cvalue = gda_tree_node_get_node_attribute (node, "fav_contents"); if (cvalue) return TRUE; } return FALSE; }
/* * Build a hash where key = column's name as a string, and value = GdaTreeNode */ static GHashTable * hash_for_existing_nodes (const GSList *nodes) { GHashTable *hash; const GSList *list; hash = g_hash_table_new (g_str_hash, g_str_equal); for (list = nodes; list; list = list->next) { const GValue *cvalue; cvalue = gda_tree_node_get_node_attribute ((GdaTreeNode*) list->data, MGR_COLUMNS_COL_NAME_ATT_NAME); if (cvalue && (G_VALUE_TYPE (cvalue) == G_TYPE_STRING)) { const gchar *str = g_value_get_string (cvalue); if (str) g_hash_table_insert (hash, (gpointer) str, list->data); } } return hash; }
static gboolean timout_cb (GdaTreeNode *node) { const GValue *cvalue; GValue *scale; gdouble sc; cvalue = gda_tree_node_get_node_attribute (node, "scale"); g_assert (cvalue && (G_VALUE_TYPE (cvalue) == G_TYPE_DOUBLE)); sc = g_value_get_double (cvalue); sc += 0.005; if (sc > 1.2) sc = .8; g_value_set_double ((scale = gda_value_new (G_TYPE_DOUBLE)), sc); gda_tree_node_set_node_attribute (node, "scale", scale, NULL); gda_value_free (scale); return TRUE; }
static gboolean tree_store_drag_get_cb (G_GNUC_UNUSED GdauiTreeStore *store, const gchar *path, GtkSelectionData *selection_ldap, LdapFavoriteSelector *fsel) { GdaTreeNode *node; node = gda_tree_get_node (fsel->priv->tree, path, FALSE); if (node) { const GValue *cvalue; cvalue = gda_tree_node_get_node_attribute (node, "fav_contents"); if (cvalue) { const gchar *str; str = g_value_get_string (cvalue); gtk_selection_data_set (selection_ldap, gtk_selection_data_get_target (selection_ldap), 8, (guchar*) str, strlen (str)); return TRUE; } } return FALSE; }
static GSList * gda_tree_mgr_xml_update_children (GdaTreeManager *manager, GdaTreeNode *node, G_GNUC_UNUSED const GSList *children_nodes, gboolean *out_error, GError **error) { GdaTreeMgrXml *mgr = GDA_TREE_MGR_XML (manager); GSList *list = NULL; xmlNodePtr xnode, child; const GValue *cvalue; cvalue = gda_tree_node_get_node_attribute (node, "xmlnode"); if (cvalue) xnode = (xmlNodePtr) g_value_get_pointer (cvalue); else xnode = mgr->priv->root; for (child = xnode->children; child; child = child->next) { GString *string = NULL; if (mgr->priv->attributes) { gint i; for (i = 0; ; i++) { xmlChar *prop; if (! mgr->priv->attributes[i]) break; prop = xmlGetProp (child, BAD_CAST mgr->priv->attributes[i]); if (!prop) continue; if (!string) string = g_string_new (""); else g_string_append_c (string, ' '); g_string_append_printf (string, "[%s=%s]", mgr->priv->attributes[i], (gchar*) prop); xmlFree (prop); } } else { /* use all attributes */ xmlAttrPtr attr; for (attr = child->properties; attr; attr = attr->next) { xmlChar *prop; prop = xmlGetProp (child, attr->name); if (!prop) continue; if (!string) string = g_string_new (""); else g_string_append_c (string, ' '); g_string_append_printf (string, "[%s=%s]", (gchar*) attr->name, (gchar*) prop); xmlFree (prop); } } if (string) { GValue *xvalue; GdaTreeNode* snode; snode = gda_tree_manager_create_node (manager, node, string->str); g_string_free (string, TRUE); g_value_set_pointer ((xvalue = gda_value_new (G_TYPE_POINTER)), child); gda_tree_node_set_node_attribute (snode, "xmlnode", xvalue, NULL); gda_value_free (xvalue); list = g_slist_prepend (list, snode); } } return list; }
/* * REM: if @attr_names is not NULL, then @cols_size will have the same number of items * * - Optionally called once with @out_max_prefix_size not %NULL and @in_string %NULL => compute * cols_size[x] and *out_max_prefix_size * - Called once with @in_string not %NULL and @out_max_prefix_size %NULL */ static void tree_node_to_string (GdaTreeNode *node, gboolean has_parent, gboolean has_next_sibling, const gchar *prefix, gchar **attr_names, guint *cols_size, guint max_prefix_size, guint *out_max_prefix_size, GString *in_string) { gchar *pipe = "|"; gchar *prefix2 = "|- "; gchar *prefix3 = "`- "; pipe = "│"; prefix2 = "├─ "; prefix3 = "└─ "; #define SEP " " const GValue *cvalue; gchar *p; const gchar *cstr; guint i; /* prefix */ if (has_next_sibling) p = g_strdup_printf ("%s%s", prefix, prefix2); else p = g_strdup_printf ("%s%s", prefix, prefix3); if (in_string) g_string_append (in_string, p); i = g_utf8_strlen (p, -1); g_free (p); /* node name */ cvalue = gda_tree_node_get_node_attribute (node, GDA_ATTRIBUTE_NAME); cstr = cvalue && g_value_get_string (cvalue)? g_value_get_string (cvalue) : "???"; if (in_string) g_string_append (in_string, cstr); /* padding */ if (in_string) { for (i = i + g_utf8_strlen (cstr, -1); i < max_prefix_size; i++) g_string_append_c (in_string, ' '); } else { guint size = i; if (g_utf8_validate (cstr, -1, NULL)) size += g_utf8_strlen (cstr, -1); else size += strlen (cstr); *out_max_prefix_size = MAX (size, *out_max_prefix_size); } /* some node's attributes */ if (attr_names) { for (i = 0; attr_names[i] && *attr_names[i]; i++) { guint colsize = 0; if (in_string) { if (cols_size [i] == 0) continue; /* ignore this attribute as it's not set */ g_string_append (in_string, SEP); } cvalue = gda_tree_node_get_node_attribute (node, attr_names[i]); if (cvalue && (G_VALUE_TYPE (cvalue) != GDA_TYPE_NULL)) { gchar *tmp = NULL; if (G_VALUE_TYPE (cvalue) == G_TYPE_FLOAT) tmp = g_strdup_printf ("%.01f", g_value_get_float (cvalue)); else { GdaDataHandler *dh; dh = gda_data_handler_get_default (G_VALUE_TYPE (cvalue)); if (dh) tmp = gda_data_handler_get_str_from_value (dh, cvalue); else tmp = gda_value_stringify (cvalue); } if (in_string) { gboolean right = FALSE; if ((G_VALUE_TYPE (cvalue) == G_TYPE_INT) || (G_VALUE_TYPE (cvalue) == G_TYPE_UINT) || (G_VALUE_TYPE (cvalue) == G_TYPE_INT64) || (G_VALUE_TYPE (cvalue) == G_TYPE_UINT64) || (G_VALUE_TYPE (cvalue) == G_TYPE_FLOAT) || (G_VALUE_TYPE (cvalue) == G_TYPE_DOUBLE) || (G_VALUE_TYPE (cvalue) == G_TYPE_CHAR) || (G_VALUE_TYPE (cvalue) == GDA_TYPE_SHORT) || (G_VALUE_TYPE (cvalue) == GDA_TYPE_USHORT)) right = TRUE; if (right) { /* right align */ guint j; for (j = tmp ? g_utf8_strlen (tmp, -1) : 0; j < cols_size [i]; j++) g_string_append_c (in_string, ' '); if (tmp) { if (g_utf8_strlen (tmp, -1) > cols_size[i]) tmp [cols_size [i]] = 0; g_string_append (in_string, tmp); } } else { /* left align */ if (tmp) { if (g_utf8_strlen (tmp, -1) > cols_size[i]) tmp [cols_size [i]] = 0; g_string_append (in_string, tmp); } guint j; for (j = tmp ? g_utf8_strlen (tmp, -1) : 0; j < cols_size [i]; j++) g_string_append_c (in_string, ' '); } } else { if (tmp) { if (g_utf8_validate (tmp, -1, NULL)) colsize += g_utf8_strlen (tmp, -1); else colsize += strlen (tmp); } cols_size [i] = MAX (cols_size [i], colsize); } g_free (tmp); } else if (in_string) { guint j; for (j = 0; j < cols_size [i]; j++) g_string_append_c (in_string, ' '); } } } if (in_string) g_string_append_c (in_string, '\n'); /* children */ gchar *ch_prefix; if (has_next_sibling) ch_prefix = g_strdup_printf ("%s%s ", prefix, pipe); else ch_prefix = g_strdup_printf ("%s ", prefix); GSList *top, *list; top = gda_tree_node_get_children (node); for (list = top; list; list = list->next) tree_node_to_string (GDA_TREE_NODE (list->data), TRUE, list->next ? TRUE : FALSE, ch_prefix, attr_names, cols_size, max_prefix_size, out_max_prefix_size, in_string); g_slist_free (top); g_free (ch_prefix); }