Example #1
0
/**
 * entry_properties_set_dn:
 * @eprop: a #EntryProperties widget
 * @dn: a DN to display information for
 *
 * Adjusts the display to show @dn's properties
 */
void
entry_properties_set_dn (EntryProperties *eprop, const gchar *dn)
{
	g_return_if_fail (IS_ENTRY_PROPERTIES (eprop));

	GtkTextBuffer *tbuffer;
	GtkTextIter start, end;

	tbuffer = eprop->priv->text;
	gtk_text_buffer_get_start_iter (tbuffer, &start);
        gtk_text_buffer_get_end_iter (tbuffer, &end);
        gtk_text_buffer_delete (tbuffer, &start, &end);

	if (dn && *dn) {
		GdaLdapEntry *entry;
		entry = t_connection_ldap_describe_entry (eprop->priv->tcnc, dn, NULL);
		if (entry)
			entry_info_fetched_done (eprop, entry);
		else 
			ui_show_message (GTK_WINDOW (gtk_widget_get_toplevel ((GtkWidget*) eprop)),
					      "%s", _("Could not get information about LDAP entry"));
	}
}
Example #2
0
/**
 * class_properties_set_class:
 * @cprop: a #ClassProperties widget
 * @classname: a DN to display information for
 *
 * Adjusts the display to show @classname's properties
 */
void
class_properties_set_class (ClassProperties *cprop, const gchar *classname)
{
	g_return_if_fail (IS_CLASS_PROPERTIES (cprop));

	GtkTextBuffer *tbuffer;
	GtkTextIter start, end;
	GdaLdapClass *lcl;
	GtkTextIter current;
	guint i;

	tbuffer = cprop->priv->text;
	gtk_text_buffer_get_start_iter (tbuffer, &start);
        gtk_text_buffer_get_end_iter (tbuffer, &end);
        gtk_text_buffer_delete (tbuffer, &start, &end);

	if (!classname || !*classname)
		return;

	lcl = t_connection_get_class_info (cprop->priv->tcnc, classname);
	if (!lcl) {
		ui_show_message (GTK_WINDOW (gtk_widget_get_toplevel ((GtkWidget*) cprop)),
				      "%s", _("Could not get information about LDAP class"));
		return;
	}

	gtk_text_buffer_get_start_iter (tbuffer, &current);

	/* Description */
	if (lcl->description) {
		gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current,
							  _("Description:"), -1,
							  "section", NULL);
		gtk_text_buffer_insert (tbuffer, &current, "\n", -1);
		gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current, " ", -1, "starter", NULL);
		gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current, lcl->description, -1,
							  "data", NULL);
		gtk_text_buffer_insert (tbuffer, &current, "\n", -1);
	}

	/* OID */
	gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current,
						  _("Class OID:"), -1,
						  "section", NULL);
	gtk_text_buffer_insert (tbuffer, &current, "\n", -1);
	gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current, " ", -1, "starter", NULL);
	gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current, lcl->oid, -1,
						  "data", NULL);
	gtk_text_buffer_insert (tbuffer, &current, "\n", -1);

	/* Kind */
	const gchar *kind;
	gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current,
						  _("Class kind:"), -1,
						  "section", NULL);
	gtk_text_buffer_insert (tbuffer, &current, "\n", 1);

	gtk_text_buffer_insert_pixbuf (tbuffer, &current, ui_connection_ldap_icon_for_class_kind (lcl->kind)); 

	kind = ui_connection_ldap_class_kind_to_string (lcl->kind);
	gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current, " ", -1, "starter", NULL);
	gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current, kind, -1,
						  "data", NULL);
	gtk_text_buffer_insert (tbuffer, &current, "\n", -1);

	/* Class name */
	gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current,
						  ngettext ("Class name:", "Class names:", lcl->nb_names), -1,
						  "section", NULL);
	gtk_text_buffer_insert (tbuffer, &current, "\n", -1);
	for (i = 0; i < lcl->nb_names; i++) {
		gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current, " ", -1, "starter", NULL);
		gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current, lcl->names[i], -1,
							  "data", NULL);
		gtk_text_buffer_insert (tbuffer, &current, "\n", -1);
	}

	/* obsolete */
	if (lcl->obsolete) {
		gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current,
							  _("This LDAP class is obsolete"), -1,
							  "error", NULL);
		gtk_text_buffer_insert (tbuffer, &current, "\n", -1);
	}
	
	/* req. attributes */
	if (lcl->nb_req_attributes > 0) {
		gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current,
							  ngettext ("Required attribute:",
								    "Required attributes:",
								    lcl->nb_req_attributes), -1,
							  "section", NULL);
		gtk_text_buffer_insert (tbuffer, &current, "\n", -1);
		for (i = 0; i < lcl->nb_req_attributes; i++) {
			gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current, " ", -1, "starter", NULL);
			gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current, lcl->req_attributes[i], -1,
								  "data", NULL);
			gtk_text_buffer_insert (tbuffer, &current, "\n", -1);
		}
	}

	/* opt. attributes */
	if (lcl->nb_opt_attributes > 0) {
		gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current,
							  ngettext ("Optional attribute:",
								    "Optional attributes:",
								    lcl->nb_opt_attributes), -1,
							  "section", NULL);
		gtk_text_buffer_insert (tbuffer, &current, "\n", -1);
		for (i = 0; i < lcl->nb_opt_attributes; i++) {
			gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current, " ", -1, "starter", NULL);
			gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current, lcl->opt_attributes[i], -1,
								  "data", NULL);
			gtk_text_buffer_insert (tbuffer, &current, "\n", -1);
		}
	}

	/* children */
	if (lcl->children) {
		gint nb;
		GSList *list;
		nb = g_slist_length (lcl->children);
		gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current,
							  ngettext ("Children class:",
								    "Children classes:",
								    nb), -1,
							  "section", NULL);
		gtk_text_buffer_insert (tbuffer, &current, "\n", -1);
		for (list = lcl->children; list; list = list->next) {
			GdaLdapClass *olcl;
			gchar *tmp;
			GtkTextTag *tag;
			olcl = (GdaLdapClass*) list->data;
			gtk_text_buffer_insert_pixbuf (tbuffer, &current,
						       ui_connection_ldap_icon_for_class_kind (olcl->kind)); 
			gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current, " ", -1, "starter", NULL);
			tag = gtk_text_buffer_create_tag (tbuffer, NULL,
							  "foreground", "blue",
							  "weight", PANGO_WEIGHT_NORMAL,
							  "underline", PANGO_UNDERLINE_SINGLE,
							  NULL);
			tmp = olcl->names [0];
			g_object_set_data_full (G_OBJECT (tag), "class",
						g_strdup (tmp), g_free);
			gtk_text_buffer_insert_with_tags (tbuffer, &current,
							  tmp, -1,
							  tag, NULL);
			if (olcl->description) {
				gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current,
									  " (", -1,
									  "data", NULL);
				gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current,
									  olcl->description, -1,
									  "data", NULL);
				gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current,
									  ")", -1,
									  "data", NULL);
			}
			gtk_text_buffer_insert (tbuffer, &current, "\n", -1);
		}
	}

	/* parents */
	if (lcl->parents) {
		gint nb;
		GSList *list;
		nb = g_slist_length (lcl->parents);
		gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current,
							  ngettext ("Inherited class:",
								    "Inherited classes:",
								    nb), -1,
							  "section", NULL);
		gtk_text_buffer_insert (tbuffer, &current, "\n", -1);
		for (list = lcl->parents; list; list = list->next) {
			GdaLdapClass *olcl;
			gchar *tmp;
			GtkTextTag *tag;
			olcl = (GdaLdapClass*) list->data;

			gtk_text_buffer_insert_pixbuf (tbuffer, &current,
						       ui_connection_ldap_icon_for_class_kind (olcl->kind)); 
			gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current, " ", -1, "starter", NULL);
			tag = gtk_text_buffer_create_tag (tbuffer, NULL,
							  "foreground", "blue",
							  "weight", PANGO_WEIGHT_NORMAL,
							  "underline", PANGO_UNDERLINE_SINGLE,
							  NULL);
			tmp = olcl->names [0];
			g_object_set_data_full (G_OBJECT (tag), "class",
						g_strdup (tmp), g_free);
			gtk_text_buffer_insert_with_tags (tbuffer, &current,
							  tmp, -1,
							  tag, NULL);

			if (olcl->description) {
				gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current,
									  " (", -1,
									  "data", NULL);
				gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current,
									  olcl->description, -1,
									  "data", NULL);
				gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current,
									  ")", -1,
									  "data", NULL);
			}

			gtk_text_buffer_insert (tbuffer, &current, "\n", -1);
		}
	}

	if (cprop->priv->text_search && gtk_widget_get_visible (cprop->priv->text_search))
		text_search_rerun (TEXT_SEARCH (cprop->priv->text_search));
}
Example #3
0
static void
execute_action_mitem_cb (GtkMenuItem *menuitem, UiFormGrid *formgrid)
{
	TFavoritesAction *act;
	GtkWidget *dlg;
	gchar *tmp;
	gint response;
	GtkWidget *toplevel;

	act = (TFavoritesAction*) g_object_get_data (G_OBJECT (menuitem), "action");
	toplevel = gtk_widget_get_toplevel ((GtkWidget*) formgrid);
	tmp = g_strdup_printf (_("Set or confirm the parameters to execute\n"
				 "action '%s'"), act->name);
	dlg = gdaui_basic_form_new_in_dialog (act->params,
					      (GtkWindow*) toplevel,
					      _("Execution of action"), tmp);
	g_free (tmp);
	response = gtk_dialog_run (GTK_DIALOG (dlg));
	gtk_widget_destroy (dlg);
	if (response == GTK_RESPONSE_ACCEPT) {
                GError *lerror = NULL;
		TConnection *tcnc;
		
		tcnc = get_t_connection (formgrid);
		g_assert (tcnc);

		GObject *result;
		result = t_connection_execute_statement (tcnc, act->stmt, act->params,
                                                               GDA_STATEMENT_MODEL_RANDOM_ACCESS, NULL,
							       &lerror);
		if (result && GDA_IS_DATA_MODEL (result)) {
			GtkWidget *dialog, *label, *fg;
			GtkWidget *dcontents;
			gchar *tmp;
			dialog = gtk_dialog_new_with_buttons (act->name, NULL, 0,
							      _("_Close"), GTK_RESPONSE_CLOSE, NULL);
			dcontents = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
			gtk_box_set_spacing (GTK_BOX (dcontents), 5);
			gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_CLOSE, TRUE);

			tmp = g_markup_printf_escaped ("<b>%s:</b>", act->name);
			label = gtk_label_new ("");
			gtk_label_set_markup (GTK_LABEL (label), tmp);
			g_free (tmp);
			gtk_widget_set_halign (label, GTK_ALIGN_START);
			gtk_box_pack_start (GTK_BOX (dcontents), label, FALSE, FALSE, 5);

			fg = ui_formgrid_new (GDA_DATA_MODEL (result), TRUE,
					      GDAUI_DATA_PROXY_INFO_CURRENT_ROW);
			ui_formgrid_set_connection (UI_FORMGRID (fg), tcnc);

			ActionExecutedData *aed;
			aed = g_new0 (ActionExecutedData, 1);
			aed->formgrid = g_object_ref (formgrid);
			aed->tcnc = g_object_ref (tcnc);
			if (act->name)
				aed->name = g_strdup (act->name);
			aed->stmt = g_object_ref (act->stmt);
			aed->params = g_object_ref (act->params);

			if (GDA_IS_DATA_SELECT (result)) {
				GdaStatement *stmt;
				g_object_get (G_OBJECT (result), "select-stmt", &stmt, NULL);
				if (stmt) {
					ui_formgrid_handle_user_prefs (UI_FORMGRID (fg), NULL, stmt);
					g_object_unref (stmt);
				}
				aed->model = g_object_ref (result);
				g_signal_connect (aed->params, "holder-changed",
						  G_CALLBACK (action_executed_holder_changed_cb), aed);

				aed->formgrid = g_object_ref (fg);
				aed->formgrid->priv->autoupdate_possible = TRUE;
				gtk_widget_show (aed->formgrid->priv->autoupdate_toggle);
			}
			gtk_box_pack_start (GTK_BOX (dcontents), fg, TRUE, TRUE, 0);

			gtk_window_set_default_size (GTK_WINDOW (dialog), 400, 600);
			gtk_widget_show_all (dialog);

			g_signal_connect (dialog, "response",
					  G_CALLBACK (gtk_widget_destroy), NULL);
			g_signal_connect (dialog, "close",
					  G_CALLBACK (gtk_widget_destroy), NULL);
			g_object_set_data_full (G_OBJECT (dialog), "aed", aed,
						(GDestroyNotify) action_executed_data_free);
		}
		else if (result) {
			if (BROWSER_IS_WINDOW (toplevel)) {
				browser_window_show_notice_printf (BROWSER_WINDOW (toplevel),
								   GTK_MESSAGE_INFO,
								   "ActionExecution",
								   "%s", _("Action successfully executed"));
			}
			else
				ui_show_message (GTK_WINDOW (toplevel),
						 "%s", _("Action successfully executed"));
			g_object_unref (result);
		}
		else {
                        ui_show_error (GTK_WINDOW (toplevel),
				       _("Error executing query: %s"),
				       lerror && lerror->message ? lerror->message : _("No detail"));
                        g_clear_error (&lerror);
                }
	}
}