void LoadVCard(string path) { if (!changesSaved) { if (ChangesMade() == DialogResult.Yes) { Save("2.1"); } } openedPath = path; vcards = VCard.ReadVCards(File.ReadAllLines(path)); RefreshVCards(); changesSaved = true; }
void Accept() { List <string> addresses = addressesTPB.Text.Split('\n').ToList(); addresses.RemoveAll(string.IsNullOrWhiteSpace); var card = new VCard() { SurName = nameTBP.Text, LastName = lastnameTBP.Text, DisplayName = displaynamePTB.Text, AllNames = new string[5] { lastnameTBP.Text, nameTBP.Text, vcard.AllNames[2], vcard.AllNames[3], vcard.AllNames[4] }, ProfileImage = pictureBox.Image, Email = emailPTB.Text, Addresses = addresses.ToArray(), Organization = organizationPTB.Text, Url = urlPTB.Text }; card.PhoneNumbers.AddRange(phoneTBP.Text.Split('\n')); card.PhoneNumbers.RemoveAll(string.IsNullOrWhiteSpace); var f = (MainF)Application.OpenForms["MainF"]; if (index < 0) { f.AddCard(card); } else { f.EditCard(card, index); } Close(); }
void RefreshInfo(int index) { VCard vc = vcards[index]; if (vc.ProfileImage == null) { pictureBox.Visible = false; pictureBox.Height = 0; } else { pictureBox.Visible = true; pictureBox.Height = 100; pictureBox.Image = vc.ProfileImage; } StringBuilder info = new StringBuilder(); if (vc.SurName != "") { if (vc.LastName != "") { info.AppendLine(vc.SurName + ", " + vc.LastName); } else { info.AppendLine(vc.SurName); } } else if (vc.LastName != "") { info.AppendLine(vc.LastName); } else { info.AppendLine(unnamed); } StringBuilder phones = new StringBuilder(); foreach (string phone in vc.PhoneNumbers) { phones.AppendLine(phone); } info.AppendLine(phones.ToString()); if (vc.Organization != "") { info.AppendLine(vc.Organization); } if (vc.Url != "") { info.AppendLine(vc.Url); } if (vc.Email != "") { info.AppendLine(vc.Email); } StringBuilder addresses = new StringBuilder(); foreach (string address in vc.Addresses) { addresses.AppendLine(address); } info.AppendLine(addresses.ToString()); infoL.Text = info.ToString(); RefreshInfoLAndMS(); listView.Items[index].Selected = true; listView.Items[index].Focused = true; }
public static VCard[] ReadVCards(string[] vcardlines) { int cards = 0; foreach (string line in vcardlines) { if (line.StartsWith("BEGIN:VCARD")) { cards++; } } VCard[] vcards = new VCard[cards]; for (int i = 0; i < cards; i++) { vcards[i] = new VCard(); } int j = 0; bool isimage = false; var imagetext = new StringBuilder(); foreach (string line in vcardlines) { if (line.StartsWith("N:")) { vcards[j].LastName = line.Split(':')[1].Split(';')[0]; if (line.Split(':')[1].Split(';').Length > 1) // ...? What "N:" is this (<= 1)? { vcards[j].SurName = line.Split(':')[1].Split(';')[1]; } vcards[j].AllNames = line.Split(':')[1].Split(';'); } else if (line.StartsWith("N;CHARSET=")) { if (line.Contains(quotedPrintable)) { string charset = line.Split(new String[] { "N;CHARSET=" }, StringSplitOptions.None)[1].Split(';')[0]; string coded = line.Split(new String[] { quotedPrintable }, StringSplitOptions.RemoveEmptyEntries)[1]; var spl = coded.Split(';'); for (int i = 0; i < spl.Length; i++) { spl[i] = DecodeString(spl[i], charset); } vcards[j].LastName = spl[0]; if (spl.Length > 1) // ...? What "N:" is this (<= 1)? { vcards[j].SurName = spl[1]; } vcards[j].AllNames = spl; } } if (isimage) { if (line == "" || line.StartsWith("END:VCARD")) { vcards[j].ProfileImage = Base64ToImage(imagetext.ToString()); isimage = false; } else if (line.StartsWith(" ")) { imagetext.Append(line); } } if (line.StartsWith("PHOTO;")) { isimage = true; imagetext = new StringBuilder(); imagetext.AppendLine(line.Split(':')[1]); } if (line.StartsWith("FN:")) { vcards[j].DisplayName = line.Split(':')[1]; } if (line.StartsWith("ORG:")) { vcards[j].Organization = line.Split(':')[1]; } if (line.StartsWith("URL:")) { vcards[j].Url = line.Split(':')[1]; } if (line.StartsWith("EMAIL:")) { vcards[j].Email = line.Split(':')[1]; } if (line.StartsWith("TEL;")) { vcards[j].PhoneNumbers.Add(line.Split(':')[1]); } if (line.StartsWith("ADR:")) { vcards[j].Addresses = line.Split(':')[1].Split(new string[] { ";;" }, StringSplitOptions.None); } if (line.Contains("END:VCARD")) { j++; } } return(vcards); }