public long interestListUpdate(Haggle.Attribute.AttributeList al) { long numberOfAttributesAdded = 0; Haggle.Attribute[] attrs = al.AsArray(); interestListView.BeginUpdate(); foreach (Haggle.Attribute a in attrs) { bool canAdd = true; if (a.GetName() != "Picture") continue; string str = a.GetValue(); // Check that this attribute doesn't already exist: for (int i = 0; i < interestListView.Items.Count && canAdd; i++) { string attrvalue = interestListView.Items[i].Text; string[] avw = attrvalue.Split(':'); if (Equals(avw[0], str)) canAdd = false; } if (canAdd) { // Add weight to string str += ":" + a.GetWeight(); ListViewItem lvi = new ListViewItem(str); interestListView.Items.Add(lvi); numberOfAttributesAdded++; } } interestListView.EndUpdate(); return numberOfAttributesAdded; }
// This will run on a thread associated with the list handle public void doPhotoListUpdate(Haggle.DataObject dObj) { Debug.WriteLine("doPhotoListUpdate"); string filepath = dObj.GetFilePath(); string filename = dObj.GetFileName(); string attribute = dObj.GetAttribute("Picture").GetValue(); Debug.WriteLine("Received photo " + filepath); lock (photoListLock) { // Add photo to image list ListViewItem lvi = new ListViewItem(attribute); // If the image is too big we will get an out of memory // exception. We need to find a good way to scale images. try { photoImageList.Images.Add(new Bitmap(filepath)); lvi.ImageIndex = photoImageList.Images.Count - 1; photoListView.BeginUpdate(); photoListView.Items.Add(lvi); photoListView.EndUpdate(); } catch (Exception) { Debug.WriteLine("Could not create bitmap from image " + filepath); } } }
public int AddInterest(Haggle.Attribute a) { IntPtr nameAnsi = Utility.StringToAnsiIntPtr(a.GetName()); IntPtr valueAnsi = Utility.StringToAnsiIntPtr(a.GetValue()); int ret = UnmanagedAddInterest(this.handle, nameAnsi, valueAnsi); Memory.LocalFree(nameAnsi); Memory.LocalFree(valueAnsi); return ret; }