public PhotoViewer(UploadedPhoto p) { q=p; InitializeComponent (); //initializing this.pictureBox1.ImageLocation=p.DirectLink; this.ShowInTaskbar=true; this.Icon=Properties.Resources.favicon; this.Text=q.LocalName+" - Photo viewer"; textBox1.Text=q.DirectLink; textBox2.Text=q.ShortUrl; textBox3.Text=q.Viewer; textBox4.Text="<img src=\""+q.DirectLink+"\" alt=\""+q.ServerName+"\" border=\"0\" />"; textBox5.Text="[img]"+q.DirectLink+"[/img]"; textBox8.Text=q.Miniatura; textBox7.Text="<a href=\""+q.ShortUrl+"\"><img src=\""+q.Miniatura+"\" alt=\""+q.ServerName+"\" border=\"0\" /></a>"; textBox6.Text="[url="+q.ShortUrl+"][img]"+q.Miniatura+"[/img][/url]"; label2.Text="Local name: "+q.LocalName; label3.Text="Server name: "+q.ServerName; this.VisibleChanged+=delegate {Program.IsHistoryFormShowed=true;}; this.FormClosing+=delegate {Program.IsHistoryFormShowed=true;}; if (p.Delete==null) this.button2.Enabled=false; }
void listView1_DoubleClick(object sender, EventArgs e) { //if I double-click a image from the history... if (listView1.SelectedItems.Count==1) { string []s=listView1.SelectedItems[0].Name.Split (":".ToCharArray ()); int id=Convert.ToInt32 (s[1]); //..get the details about it... UploadedPhoto uf=new UploadedPhoto (); foreach (UploadedPhoto up in Program.History) if (id==up.Id) { uf=up; break; } //...and then upload it PhotoViewer pv=new PhotoViewer (uf); this.Hide (); if (pv.ShowDialog ()==DialogResult.Cancel) { button2_Click (null, null); this.Show (); } } }
private static void ParseResponse(string response, string []es=null, string file="null", byte []array=null) { //after uploading the photo, the api will return a Json response containing some data about the photo //that data is stored on a UploadedPhoto class for each single photo, then saved in history string []pe=response.Split (new string [] {"\"status_code\":", ","}, StringSplitOptions.None); if (Convert.ToInt32 (pe[1])!=200) { //something's wrong Program.checker.BuildContextMenu (); DialogResult dr=MessageBox.Show ("Error data: "+response, "Error", MessageBoxButtons.AbortRetryIgnore); if (dr==DialogResult.Abort) { Program.ApplicationRestart (); return; } else if (dr==DialogResult.Retry) { if (file=="null") Upload (array); else Upload (file); return; } else if (dr==DialogResult.Ignore) return; } //collect the data UploadedPhoto up=new UploadedPhoto (); if (es==null) up.LocalName="no local name"; else up.LocalName=es[es.Length-1]; { string []p=response.Split (new string [] {(Program.Chevereto3)?"\"filename\":\"":"\"image_filename\":\"", "\","}, StringSplitOptions.None); up.ServerName=ParseValue (p[(Program.Chevereto3)?12:3]); } { string []p=response.Split (new string [] {(Program.Chevereto3)?"\"url\":":"\"image_url\":", ","}, StringSplitOptions.None); up.DirectLink=ParseValue (p[(Program.Chevereto3)?26:7]); } { string []p=response.Split (new string [] {(Program.Chevereto3)?"\"url\":":"\"image_thumb_url\":", ","}, StringSplitOptions.None); up.Miniatura=ParseValue (p[(Program.Chevereto3)?40:13]); } { string []p=response.Split (new string [] {(Program.Chevereto3)?"\"url_viewer\":":"\"image_viewer\":", ","}, StringSplitOptions.None); up.Viewer=ParseValue (p[(Program.Chevereto3)?27:20]); } { string []p=response.Split (new string [] {(Program.Chevereto3)?"":"\"image_shorturl\":", ","}, StringSplitOptions.None); up.ShortUrl=(Program.Chevereto3)?"":ParseValue (p[21]); } { string []p=response.Split (new string [] {(Program.Chevereto3)?"":"\"image_delete_confirm_url\":", ","}, StringSplitOptions.None); up.Delete=(Program.Chevereto3)?"":ParseValue (p[24]); } { int idtofind=1; while (FindId (idtofind)==true) idtofind++; up.Id=idtofind; } up.FromLastUpload=true; //save the photo to history Program.History.Add (up); Program.WriteHistory (); }
public static void ReadHistory () { /* this function reads the content of history.xml, which contains the links * to the photos you have uploaded in the past.*/ History=new List <UploadedPhoto> (); if (File.Exists (AppPath+"history.xml")==false) { StreamWriter sw=new StreamWriter (AppPath+"history.xml"); sw.WriteLine ("<xml><nr-of-files>0</nr-of-files><files></files></xml>"); sw.Close (); } XmlTextReader reader=new XmlTextReader (AppPath+"history.xml"); int n=0; string ReadedNode=""; UploadedPhoto aux=new UploadedPhoto (); while (reader.Read ()) { switch (reader.NodeType) { case XmlNodeType.Element: ReadedNode=reader.Name; if (reader.Name=="file") aux=new UploadedPhoto (); break; case XmlNodeType.Text: //parse the content of a "photo"... string s=reader.Value; switch (ReadedNode) { case "nr-of-files": n=Convert.ToInt32 (s); break; case "id": aux.Id=Convert.ToInt32 (s); break; case "local-name": aux.LocalName=s; break; case "server-name": aux.ServerName=s; break; case "direct-link": aux.DirectLink=s; break; case "short-url": aux.ShortUrl=s; break; case "viewer": aux.Viewer=s; break; case "mini": aux.Miniatura=s; break; case "from-last-upload": aux.FromLastUpload=Convert.ToBoolean (s); break; case "delete-link": aux.Delete=s; break; default: break; } break; case XmlNodeType.EndElement: //...and add that "photo" to the "history" if (reader.Name=="file") History.Add (aux); break; } } reader.Close (); }