private void menuItem2_Click(object sender, EventArgs e) { if (interestListView.Focused) { // Remove interest attribute for (int i = 0; i < interestListView.SelectedIndices.Count; i++) { int index = interestListView.SelectedIndices[i]; string attrvalue = interestListView.Items[index].Text; Debug.WriteLine("remove : " + attrvalue + " at index " + index); // Separate value and weight string[] avw = attrvalue.Split(':'); Haggle.Attribute a = new Haggle.Attribute("Picture", avw[0]); if (!delInterestList.Contains(a)) { if (addInterestList.Contains(a)) { addInterestList.Remove(a); } else { delInterestList.Add(a); } interestListView.Items.RemoveAt(index); menuItem1.Text = "Done"; } } } else if (interestTextBox.Text.Length > 0) { ParseInterestTextBox(); } }
private void ParseInterestTextBox() { // 1. Get the input text in texbox1 and add to interest. // 2. Update listview string[] strArray = interestTextBox.Text.Split(','); interestTextBox.Text = ""; int num = 0; if (strArray.Length == 0) { return; } interestListView.BeginUpdate(); foreach (string str in strArray) { bool canAdd = true; string trimstr = str.TrimEnd(); if (trimstr.Length == 0) { continue; } // 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], trimstr)) { canAdd = false; } } if (canAdd) { Haggle.Attribute a = new Haggle.Attribute("Picture", trimstr, 1); if (!delInterestList.Contains(a)) { // Add weight to string trimstr += ":" + 1; //trimstr += ":" + trackBarWeight.Value; ListViewItem lvi = new ListViewItem(trimstr); interestListView.Items.Add(lvi); addInterestList.Add(a); delInterestList.Remove(a); num++; } } } interestListView.EndUpdate(); if (num > 0) { menuItem1.Text = "Done"; } }
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); } }
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); } }