예제 #1
0
파일: text-search.c 프로젝트: UIKit0/libgda
/**
 * text_search_new:
 *
 * Returns: a new #GtkWidget
 */
GtkWidget *
text_search_new (GtkTextView *view)
{
	g_return_val_if_fail (GTK_IS_TEXT_VIEW (view), NULL);

	TextSearch *tsearch;
	GtkWidget *wid;

	tsearch = TEXT_SEARCH (g_object_new (TEXT_SEARCH_TYPE, "spacing", 5,
					     "homogeneous", FALSE, NULL));
	tsearch->priv->view = view;
	g_object_ref ((GObject*) tsearch->priv->view);
	tsearch->priv->text = gtk_text_view_get_buffer (view);

	gtk_text_buffer_create_tag (tsearch->priv->text, "search",
                                    "background", "yellow", NULL);

	wid = browser_make_small_button (FALSE, FALSE, NULL, GTK_STOCK_CLOSE,
					 _("Hide search toolbar"));
	gtk_box_pack_start (GTK_BOX (tsearch), wid, FALSE, FALSE, 0);
	g_signal_connect_swapped (wid, "clicked",
				  G_CALLBACK (hide_search_bar), tsearch);
	
	wid = gtk_label_new (_("Search:"));
	gtk_box_pack_start (GTK_BOX (tsearch), wid, FALSE, FALSE, 0);
	
	wid = gtk_entry_new ();
	gtk_box_pack_start (GTK_BOX (tsearch), wid, TRUE, TRUE, 0);
	tsearch->priv->search_entry = wid;
	gtk_container_set_focus_child (GTK_CONTAINER (tsearch), tsearch->priv->search_entry);
	g_signal_connect (wid, "changed",
			  G_CALLBACK (search_text_changed_cb), tsearch);
	
	wid = browser_make_small_button (FALSE, FALSE, NULL, GTK_STOCK_GO_BACK, NULL);
	gtk_box_pack_start (GTK_BOX (tsearch), wid, FALSE, FALSE, 0);
	g_signal_connect (wid, "clicked",
			  G_CALLBACK (go_back_search_cb), tsearch);
	
	wid = browser_make_small_button (FALSE, FALSE, NULL, GTK_STOCK_GO_FORWARD, NULL);
	gtk_box_pack_start (GTK_BOX (tsearch), wid, FALSE, FALSE, 0);
	g_signal_connect (wid, "clicked",
			  G_CALLBACK (go_forward_search_cb), tsearch);
	
	wid = gtk_check_button_new_with_label (_("Case sensitive"));
	gtk_box_pack_start (GTK_BOX (tsearch), wid, FALSE, FALSE, 0);
	tsearch->priv->search_sensitive = GTK_TOGGLE_BUTTON (wid);
	g_signal_connect (wid, "toggled",
			  G_CALLBACK (sensitive_toggled_cb), tsearch);

	gtk_widget_show_all ((GtkWidget*) tsearch);
	gtk_widget_hide ((GtkWidget*) tsearch);

	return (GtkWidget*) tsearch;
}
예제 #2
0
static void
show_search_bar (ClassProperties *cprop)
{
	if (! cprop->priv->text_search) {
		cprop->priv->text_search = text_search_new (GTK_TEXT_VIEW (cprop->priv->view));
		gtk_box_pack_start (GTK_BOX (cprop), cprop->priv->text_search, FALSE, FALSE, 0);
		gtk_widget_show (cprop->priv->text_search);
	}
	else {
		gtk_widget_show (cprop->priv->text_search);
		text_search_rerun (TEXT_SEARCH (cprop->priv->text_search));
	}

	gtk_widget_grab_focus (cprop->priv->text_search);
}
예제 #3
0
static void
show_search_bar (EntryProperties *eprop)
{
	if (! eprop->priv->text_search) {
		eprop->priv->text_search = text_search_new (eprop->priv->view);
		gtk_box_pack_start (GTK_BOX (eprop), eprop->priv->text_search, FALSE, FALSE, 0);
		gtk_widget_show (eprop->priv->text_search);
	}
	else {
		gtk_widget_show (eprop->priv->text_search);
		text_search_rerun (TEXT_SEARCH (eprop->priv->text_search));
	}

	gtk_widget_grab_focus (eprop->priv->text_search);
}
예제 #4
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));
}
예제 #5
0
파일: text-search.c 프로젝트: UIKit0/libgda
static void
text_search_grab_focus (GtkWidget *widget)
{
	gtk_widget_grab_focus (TEXT_SEARCH (widget)->priv->search_entry);
}
예제 #6
0
static void
entry_info_fetched_done (EntryProperties *eprop, GdaLdapEntry *entry)
{
	GtkTextBuffer *tbuffer;
	GtkTextIter start, end;
	TConnection *tcnc = eprop->priv->tcnc;
	
	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);

	guint i;
	GtkTextIter current;

	gtk_text_buffer_get_start_iter (tbuffer, &current);

	/* DN */
	gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current, _("Distinguished Name:"), -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, entry->dn, -1,
						  "data", NULL);
	gtk_text_buffer_insert (tbuffer, &current, "\n", -1);

	/* other attributes */
	const gchar *basedn;
	GdaDataHandler *ts_dh = NULL;
	basedn = t_connection_ldap_get_base_dn (tcnc);

	for (i = 0; i < entry->nb_attributes; i++) {
		GdaLdapAttribute *attr;
		gchar *tmp;
		attr = entry->attributes [i];
		tmp = g_strdup_printf ("%s:", attr->attr_name);
		gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current, tmp, -1, "section", NULL);
		g_free (tmp);
		gtk_text_buffer_insert (tbuffer, &current, "\n", -1);

		guint j;
		for (j = 0; j < attr->nb_values; j++) {
			const GValue *cvalue;
			cvalue = attr->values [j];

			gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current, " ", -1,
								  "starter", NULL);

			if (G_VALUE_TYPE (cvalue) == GDA_TYPE_BINARY) {
				GValue *copyvalue;
				GtkTextTagTable *table;
				GtkTextTag *tag;
				GtkTextMark *mark;

				copyvalue = gda_value_copy (cvalue);
				table = gtk_text_buffer_get_tag_table (tbuffer);
				tag = gtk_text_tag_new (NULL);
				gtk_text_tag_table_add (table, tag);
				g_object_set_data_full ((GObject*) tag, "binvalue",
							copyvalue, (GDestroyNotify) gda_value_free);
				g_object_unref ((GObject*) tag);

				mark = gtk_text_buffer_create_mark (tbuffer, NULL, &current, TRUE);

				GdkPixbuf *pixbuf;
				pixbuf = data_to_pixbuf (cvalue);
				if (pixbuf) {
					gtk_text_buffer_insert_pixbuf (tbuffer, &current, pixbuf); 
					g_object_unref (pixbuf);
				}
				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);
					gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current,
										  tmp, -1,
										  "data", NULL);
					g_free (tmp);
				}
				GtkTextIter before;
				gtk_text_buffer_get_iter_at_mark (tbuffer, &before, mark);
				gtk_text_buffer_apply_tag (tbuffer, tag, &before, &current);
				gtk_text_buffer_delete_mark (tbuffer, mark);
					
				gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current,
									  "\n", 1,
									  "data", NULL);
			}
			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 (tmp) {
					if (*tmp &&
					    ((basedn && g_str_has_suffix (tmp, basedn)) || !basedn) &&
					    gda_ldap_is_dn (tmp)) {
						/* we have a DN */
						GtkTextTag *tag;
						tag = gtk_text_buffer_create_tag (tbuffer, NULL,
										  "foreground", "blue",
										  "weight", PANGO_WEIGHT_NORMAL,
										  "underline", PANGO_UNDERLINE_SINGLE,
										  NULL);
						g_object_set_data_full (G_OBJECT (tag), "dn",
									g_strdup (tmp), g_free);
						gtk_text_buffer_insert_with_tags (tbuffer, &current,
										  tmp, -1,
										  tag, NULL);
					}
					else if (attr->attr_name &&
						 !g_ascii_strcasecmp (attr->attr_name, "objectClass")) {
						GtkTextTag *tag;
						tag = gtk_text_buffer_create_tag (tbuffer, NULL,
										  "foreground", "blue",
										  "weight", PANGO_WEIGHT_NORMAL,
										  "underline", PANGO_UNDERLINE_SINGLE,
										  NULL);
						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);
					}
					else
						gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current, tmp, -1,
											  "data", NULL);

					gchar *extrainfo = NULL;
					if (!strncmp (attr->attr_name, "shadow", 6) &&
					    (!strcmp (attr->attr_name, "shadowLastChange") ||
					     !strcmp (attr->attr_name, "shadowMax") ||
					     !strcmp (attr->attr_name, "shadowMin") ||
					     !strcmp (attr->attr_name, "shadowInactive") ||
					     !strcmp (attr->attr_name, "shadowExpire")))
						extrainfo = unix_shadow_to_string (tmp, attr->attr_name);
					else if (!strcmp (attr->attr_name, "badPasswordTime") ||
						 !strcmp (attr->attr_name, "lastLogon") ||
						 !strcmp (attr->attr_name, "pwdLastSet") ||
						 !strcmp (attr->attr_name, "accountExpires") ||
						 !strcmp (attr->attr_name, "lockoutTime") ||
						 !strcmp (attr->attr_name, "lastLogonTimestamp"))
						extrainfo = ad_1601_timestamp_to_string (tmp, attr->attr_name);
					else if (!strcmp (attr->attr_name, "userAccountControl"))
						extrainfo = ad_1601_uac_to_string (tmp);
					else if (!strcmp (attr->attr_name, "sAMAccountType"))
						extrainfo = ad_sam_account_type_to_string (tmp);

					if (extrainfo) {
						gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current,
											  " ", 1,
											  "data", NULL);
						gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current,
											  extrainfo, -1,
											  "convdata", NULL);
						g_free (extrainfo);
					}
					g_free (tmp);
				}
				else {
					gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current, _("Can't display attribute value"), -1,
										  "error", NULL);
				}
				gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current,
									  "\n", 1,
									  "data", NULL);
			}
		}
	}
	if (ts_dh)
		g_object_unref (ts_dh);
	gda_ldap_entry_free (entry);


	if (eprop->priv->text_search && gtk_widget_get_visible (eprop->priv->text_search))
		text_search_rerun (TEXT_SEARCH (eprop->priv->text_search));
}