private void menuAddInterest_Click(object sender, EventArgs e) { DialogResult ret = DialogResult.None; try { ret = ps.addInterestWindow.ShowDialog(); } catch (Exception) { Debug.WriteLine("Could not show addInterest dialog"); } if (ret == DialogResult.OK) { int retval = 0; Haggle.Attribute.AttributeList al = ps.addInterestWindow.getAddInterests(); foreach (Haggle.Attribute a in al.AsArray()) { Debug.WriteLine("Add interest: " + a.ToString()); } if (al.Size() > 0) { retval = ps.hh.AddInterests(al); Debug.WriteLine("Add interests returned: " + retval); } al = ps.addInterestWindow.getDelInterests(); foreach (Haggle.Attribute a in al.AsArray()) { Debug.WriteLine("Delete interest: " + a.ToString()); } if (al.Size() > 0) { retval = ps.hh.DeleteInterests(al); Debug.WriteLine("Delete interests returned: " + retval); photoListView.Clear(); ps.dataObjects.Clear(); ps.addInterestWindow.interestListView.Clear(); ps.hh.RequestInterests(); ps.hh.RequestDataObjects(); } } }
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); }
private void menuTakePicture_Click(object sender, EventArgs e) { CameraCaptureDialog cameraCapture = new CameraCaptureDialog(); cameraCapture.Owner = this; object cameraEnabled = Microsoft.WindowsMobile.Status.SystemState.GetValue(Microsoft.WindowsMobile.Status.SystemProperty.CameraEnabled); cameraCapture.DefaultFileName = "haggle-temp.jpg"; cameraCapture.Title = "Take PhotoShare Picture"; cameraCapture.Mode = CameraCaptureMode.Still; cameraCapture.Resolution = new Size(1024, 768); // The filename of the picure taken string fileName; if (null != cameraEnabled && 0 == (int)cameraEnabled) { MessageBox.Show("The camera is disabled", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); return; } try { if (cameraCapture.ShowDialog() == DialogResult.OK) { fileName = cameraCapture.FileName; Debug.WriteLine("file name of photo is " + fileName); if (cameraCapture.Mode == CameraCaptureMode.Still) { string extension = fileName.Substring(fileName.LastIndexOf(".")); string directory = ""; long extra_digit; if (fileName.LastIndexOf("\\") != -1) { directory = fileName.Substring(0, fileName.LastIndexOf("\\") + 1); } fileName = directory + this.defaultPictureFileName + extension; extra_digit = 0; while (System.IO.File.Exists(fileName)) { fileName = directory + this.defaultPictureFileName + "-" + extra_digit + extension; extra_digit++; } System.IO.File.Move(cameraCapture.FileName, fileName); } FileAttributeWindow fileAttrWin = new FileAttributeWindow(fileName); DialogResult ret = DialogResult.Cancel; try { ret = fileAttrWin.ShowDialog(); } catch (Exception) { Debug.WriteLine("Could not show fileAttrWind dialog"); } //fileAttrWin.BringToFront(); char[] separators = { ';', ' ' }; string[] keywords = fileAttrWin.getResultValueString().Split(separators); Debug.WriteLine("Attributes string is: " + fileAttrWin.getResultValueString()); //DialogResult ret = MessageBox.Show("The picture was saved to:\n" + fileName + // "\nDo you want to publish the picture with Haggle now?", // this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1); if (ret == DialogResult.OK) { try { Haggle.Attribute.AttributeList al = new Haggle.Attribute.AttributeList(); Haggle.DataObject dObj = new Haggle.DataObject(fileName); dObj.AddHash(); // Add thumbnail: dObj.SetThumbnail(GetThumbnail(fileName, 32, 0)); foreach (string kw in keywords) { Haggle.Attribute a = new Haggle.Attribute("Picture", kw); if (!dObj.AddAttribute(a)) { MessageBox.Show("Could not add attribute"); return; } if (fileAttrWin.getAddAsInterest()) { if (ps.addInterestWindow.interestListUpdate(new Haggle.Attribute.AttributeList(a)) > 0) { Debug.WriteLine("Adding interest " + a.ToString()); al.Add(a); } } } // We need to add the interest first if we want the filters to match the // data object we add if (fileAttrWin.getAddAsInterest()) { ps.hh.AddInterests(al); } //Haggle.Attribute attr = dObj.GetAttribute("DeviceName"); //MessageBox.Show("Data object file name is: " + dObj.GetFileName() // + " Attribute is: " + attr.GetValue()); int sent = ps.hh.PublishDataObject(dObj); if (sent < 0) { MessageBox.Show("Could not publish data object on handle=" + ps.hh.handle + " Error=" + sent); } } catch (Haggle.DataObject.NoSuchAttributeException) { MessageBox.Show("No such attribute in data object"); } catch (Haggle.DataObject.DataObjectException ex) { MessageBox.Show(ex.ToString()); } catch (Haggle.Attribute.AttributeNullPtrException) { MessageBox.Show("Attribute null pointer exception"); } catch (Exception) { MessageBox.Show("Unknown error"); } } else if (ret == DialogResult.No) { Debug.WriteLine("camera dialog result \'NO\'"); } else { Debug.WriteLine("Unknown camera dialog result"); MessageBox.Show("Unknown selection."); } Debug.WriteLine("camera exit"); } } catch (ArgumentException ex) { MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); } catch (OutOfMemoryException ex) { MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1); } catch (InvalidOperationException ex) { MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1); } }