Exemple #1
0
static void
sql_favorite_new_mitem_cb (G_GNUC_UNUSED GtkMenuItem *mitem, QueryConsolePage *tconsole)
{
	TFavorites *tfav;
	TFavoritesAttributes fav;
	GError *error = NULL;

	GdaSet *set;
	GtkWidget *dlg, *form;
	gint response;
	const GValue *cvalue;
	set = gda_set_new_inline (1, _("Favorite's name"),
				  G_TYPE_STRING, _("Unnamed query"));
	dlg = gdaui_basic_form_new_in_dialog (set,
					      (GtkWindow*) gtk_widget_get_toplevel (GTK_WIDGET (tconsole)),
					      _("Name of the favorite to create"),
					      _("Enter the name of the favorite to create"));
	form = g_object_get_data (G_OBJECT (dlg), "form");
	g_signal_connect (form, "activated",
			  G_CALLBACK (fav_form_name_activated_cb), dlg);
	response = gtk_dialog_run (GTK_DIALOG (dlg));
	if (response == GTK_RESPONSE_REJECT) {
		g_object_unref (set);
		gtk_widget_destroy (dlg);
		return;
	}

	memset (&fav, 0, sizeof (fav));
	fav.id = -1;
	fav.type = T_FAVORITES_QUERIES;
	fav.contents = query_editor_get_all_text (tconsole->priv->editor);
	cvalue = gda_set_get_holder_value (set, _("Favorite's name"));
	fav.name = (gchar*) g_value_get_string (cvalue);

	tfav = t_connection_get_favorites (tconsole->priv->tcnc);

	if (! t_favorites_add (tfav, 0, &fav, ORDER_KEY_QUERIES, G_MAXINT, &error)) {
		ui_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) tconsole),
			       _("Could not add favorite: %s"),
			       error && error->message ? error->message : _("No detail"));
                if (error)
                        g_error_free (error);
	}
	else
		tconsole->priv->fav_id = fav.id;
	g_free (fav.contents);

	g_object_unref (set);
	gtk_widget_destroy (dlg);
}
Exemple #2
0
static gchar *
tree_to_string_default (GdaTree *tree, FILE *stream, GdaSet *options)
{
    GString *string;
    GSList *top, *list;
    gchar **attr_names = NULL;
    guint attr_names_size = 0;
    guint *cols_size = NULL;
    guint max_prefix_size = 0;

    g_return_val_if_fail (GDA_IS_TREE (tree), NULL);

    if (options) {
        const GValue *cvalue;
        cvalue = gda_set_get_holder_value (options, "GDA_TREE_COLUMN_NAMES");
        if (cvalue && (G_VALUE_TYPE (cvalue) == G_TYPE_STRING) && g_value_get_string (cvalue)) {
            attr_names = g_strsplit (g_value_get_string (cvalue), ",", 0);
            if (attr_names) {
                guint i;
                for (i = 0; attr_names [i]; i++)
                    g_strstrip (attr_names [i]);
                attr_names_size = i;
            }
        }
    }

    string = g_string_new ("");
    top = gda_tree_get_nodes_in_path (tree, NULL, FALSE);
    if (attr_names) {
        /* determine prefix's max size and columns' max size */
        cols_size = g_new0 (guint, attr_names_size);
        for (list = top; list; list = list->next) {
            tree_node_to_string (GDA_TREE_NODE (list->data), FALSE, list->next ? TRUE : FALSE, "",
                                 attr_names, cols_size, 0, &max_prefix_size, NULL);
        }

        guint i, j;
        for (i = 0; attr_names [i]; i++) {
            guint size = 0;
            if (g_utf8_validate (attr_names[i], -1, NULL))
                size += g_utf8_strlen (attr_names[i], -1);
            else
                size += strlen (attr_names[i]);
            cols_size[i] = MAX (cols_size[i], size);
        }

        /* output column names */
        const gchar *title;
        title = (const gchar*) g_object_get_data ((GObject*) tree, "GDA_TREE_TITLE");
        if (title) {
            g_string_append (string, title);
            for (j = g_utf8_strlen (title, -1); j < max_prefix_size; j++)
                g_string_append_c (string, ' ');
        }
        else {
            for (j =  0; j < max_prefix_size; j++)
                g_string_append_c (string, ' ');
        }

        /* output column values */
        for (i = 0; attr_names [i]; i++) {
            if (cols_size[i] == 0)
                continue;
            g_string_append (string, SEP);
            g_string_append (string, attr_names[i]);
            guint size = 0;
            if (g_utf8_validate (attr_names[i], -1, NULL))
                size += g_utf8_strlen (attr_names[i], -1);
            else
                size += strlen (attr_names[i]);
            for (j =  size; j < cols_size[i]; j++)
                g_string_append_c (string, ' ');
        }
        g_string_append_c (string, '\n');
    }

    for (list = top; list; list = list->next)
        tree_node_to_string (GDA_TREE_NODE (list->data), FALSE, list->next ? TRUE : FALSE, "",
                             attr_names, cols_size, max_prefix_size, NULL, string);
    g_slist_free (top);

    if (attr_names) {
        g_strfreev (attr_names);
        g_free (cols_size);
    }

    return g_string_free (string, FALSE);
}