private void WriteCollection(MemoryStore substore, Gtk.HTMLStream stream) { string type = null; foreach (Statement stmt in substore) { if (stmt.Predicate.Uri == MetadataStore.Namespaces.Resolve("rdf:type")) { string prefix; MetadataStore.Namespaces.Normalize(stmt.Object.Uri, out prefix, out type); } } stream.Write("<table cellpadding=5 cellspacing=0 width=100%>"); foreach (Statement sub in substore) { if (sub.Object is Literal) { string title; string value = ((Literal)(sub.Object)).Value; string vc = String.Empty; Description.GetDescription(substore, sub, out title, out value); if (type != "Alt") { vc = " bgcolor=" + Color(Style.Backgrounds [(int)Gtk.StateType.Normal]); } if (type == null) { stream.Write(String.Format("<tr bgcolor={3}><td bgcolor={2}>{0}</td><td width=100%>{1}</td></tr>", Escape(title), Escape(value), Color(Style.MidColors [(int)Gtk.StateType.Normal]), Color(Style.Backgrounds [(int)Gtk.StateType.Normal]))); } else { stream.Write(String.Format("<tr><td{1}>{0}</td></tr>", Escape(value), vc)); } } else { if (type == null) { stream.Write("<tr><td>"); MemoryStore substore2 = substore.Select(new Statement((Entity)sub.Object, null, null, null)).Load(); if (substore.StatementCount > 0) { WriteCollection(substore2, stream); } stream.Write("</tr><td>"); } } } stream.Write("</table>"); }
protected override void OnUrlRequested(string url, Gtk.HTMLStream stream) { if (url == "exif:thumbnail") { byte [] data = exif_info.Data; if (data.Length > 0) { stream.Write(data, data.Length); stream.Close(Gtk.HTMLStreamStatus.Ok); } else { stream.Close(Gtk.HTMLStreamStatus.Error); } } }
void LoadURL( string url ) { using ( StreamReader sr = new StreamReader( "en/" + url ) ) { s2 = html_en.Begin(); s2.Write( sr.ReadToEnd() ); html_en.End (s2, Gtk.HTMLStreamStatus.Ok); } using( StreamReader sr = new StreamReader( "es/" + url ) ) { s3 = html_es.Begin(); s3.Write( sr.ReadToEnd() ); html_es.End (s3, Gtk.HTMLStreamStatus.Ok); } }
public Navegador() : base("navegador") { SetDefaultSize( 300, 300); DeleteEvent += new Gtk.DeleteEventHandler( Quit ); hbox = new Gtk.HBox( false, 3 ); Add( hbox ); Gtk.ScrolledWindow sw1 = new Gtk.ScrolledWindow(); Gtk.ScrolledWindow sw2 = new Gtk.ScrolledWindow(); Gtk.ScrolledWindow sw3 = new Gtk.ScrolledWindow(); html_enlaces = new Gtk.HTML(); sw1.Add( html_enlaces ); html_en = new Gtk.HTML(); sw2.Add( html_en ); html_es = new Gtk.HTML(); sw3.Add( html_es ); hbox.PackStart( sw1, true, true, 1 ); hbox.PackStart( sw2, true, true, 1 ); hbox.PackStart( sw3, true, true, 1 ); s1 = html_enlaces.Begin("text/html"); s2 = html_en.Begin("text/html"); s3 = html_es.Begin("text/html"); using (StreamReader sr1 = new StreamReader( "es/index.html") ) { s1.Write( sr1.ReadToEnd() ); } html_enlaces.End (s1, Gtk.HTMLStreamStatus.Ok); html_enlaces.LinkClicked += new Gtk.LinkClickedHandler (OnLinkClicked); html_en.LinkClicked += new Gtk.LinkClickedHandler (OnLinkClicked); html_es.LinkClicked += new Gtk.LinkClickedHandler (OnLinkClicked); LoadURL( "1.html" ); ShowAll(); }
public StreamSink(SemWeb.StatementSource source, Gtk.HTMLStream stream, InfoDisplay info) { this.stream = stream; this.info = info; this.source = source; }
private void Update() { Gtk.HTMLStream stream = this.Begin(null, "text/html; charset=utf-8", Gtk.HTMLBeginFlags.Scroll); string bg = Color(this.Style.Background(Gtk.StateType.Active)); string fg = Color(this.Style.Foreground(Gtk.StateType.Active)); string ig = Color(this.Style.Base(Gtk.StateType.Active)); stream.Write("<table width=100% cellpadding=5 cellspacing=0>"); bool empty = true; bool missing = false; System.Exception error = null; if (exif_info != null) { foreach (Exif.ExifContent content in exif_info.GetContents()) { Exif.ExifEntry [] entries = content.GetEntries(); if (entries.Length > 0) { empty = false; break; } } if (exif_info.Data.Length > 0) { stream.Write(String.Format("<tr><td colspan=2 align=\"center\" bgcolor=\"{0}\">" + "<img center src=\"exif:thumbnail\"></td></tr>", ig)); } int i = 0; foreach (Exif.ExifContent content in exif_info.GetContents()) { Exif.ExifEntry [] entries = content.GetEntries(); i++; if (entries.Length < 1) { continue; } stream.Write("<tr><th align=left bgcolor=\"" + ig + "\" colspan=2>" + Exif.ExifUtil.GetIfdNameExtended((Exif.Ifd)i - 1) + "</th><tr>"); foreach (Exif.ExifEntry entry in entries) { stream.Write("<tr><td valign=top align=right bgcolor=\"" + bg + "\"><small><font color=\"" + fg + "\">"); if (entry.Title != null) { stream.Write(entry.Title); } else { stream.Write("<Unknown Tag ID=" + entry.Tag.ToString() + ">"); } stream.Write("</font></small></td><td>"); string s = entry.Value; if (s != null && s != String.Empty) { stream.Write(s); } stream.Write("</td><tr>"); } } } if (photo != null) { MetadataStore store = new MetadataStore(); try { using (ImageFile img = ImageFile.Create(photo.DefaultVersionUri)) { if (img is SemWeb.StatementSource) { StatementSource source = (StatementSource)img; source.Select(store); } } } catch (System.IO.FileNotFoundException) { missing = true; } catch (System.Exception e) { // Sometimes we don't get the right exception, check for the file if (!System.IO.File.Exists(photo.DefaultVersionUri.LocalPath)) { missing = true; } else { // if the file is there but we still got an exception display it. error = e; } } if (store.StatementCount > 0) { #if false using (System.IO.Stream xmpstream = System.IO.File.OpenWrite("tmp.xmp")) { xmpstream.Length = 0; FSpot.Xmp.XmpFile file; file = new FSpot.Xmp.XmpFile(); store.Select(file); file.Save(xmpstream); } #endif empty = false; stream.Write("<tr><th align=left bgcolor=\"" + ig + "\" colspan=2>" + Catalog.GetString("Extended Metadata") + "</th></tr>"); foreach (Statement stmt in store) { // Skip anonymous subjects because they are // probably part of a collection if (stmt.Subject.Uri == null && store.SelectSubjects(null, stmt.Subject).Length > 0) { continue; } string title; string value; Description.GetDescription(store, stmt, out title, out value); stream.Write("<tr><td valign=top align=right bgcolor=\"" + bg + "\"><small><font color=\"" + fg + "\">"); stream.Write(title); stream.Write("</font></small></td><td width=100%>"); if (value != null) { value = Escape(value); } else { MemoryStore substore = store.Select(new Statement((Entity)stmt.Object, null, null, null)).Load(); WriteCollection(substore, stream); } if (value != null && value != String.Empty) { stream.Write(value); } stream.Write("</td></tr>"); } } if (Core.Database != null && photo is Photo) { stream.Write("<tr><th align=left bgcolor=\"" + ig + "\" colspan=2>" + Catalog.GetString("Exported Locations") + "</th></tr>"); Photo p = photo as Photo; foreach (ExportItem export in Core.Database.Exports.GetByImageId(p.Id, p.DefaultVersionId)) { string url = GetExportUrl(export); string label = GetExportLabel(export); if (url == null || label == null) { continue; } stream.Write("<tr colspan=2><td width=100%>"); stream.Write(String.Format("<a href=\"{0}\">{1}</a>", url, label)); stream.Write("</font></small></td></tr>"); } } } if (empty) { string msg; if (photo == null) { // FIXME we should pass the full selection to the info display and let it // handle multiple items however it wants. msg = String.Format("<tr><td valign=top align=center bgcolor=\"{0}\">" + "<b>{1}</b></td></tr>", ig, Catalog.GetString("No active photo")); } else if (missing) { string text = String.Format(Catalog.GetString("The photo \"{0}\" does not exist"), photo.DefaultVersionUri); msg = String.Format("<tr><td valign=top align=center bgcolor=\"{0}\">" + "<b>{1}</b></td></tr>", ig, text); } else { msg = String.Format("<tr><td valign=top align=center bgcolor=\"{0}\">" + "<b>{1}</b></td></tr>", ig, Catalog.GetString("No metadata available")); if (error != null) { String.Format("<pre>{0}</pre>", error); } } stream.Write(msg); } stream.Write("</table>"); End(stream, Gtk.HTMLStreamStatus.Ok); }
public StreamSink (SemWeb.StatementSource source, Gtk.HTMLStream stream, InfoDisplay info) { this.stream = stream; this.info = info; this.source = source; }