예제 #1
0
        // 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);
                }
            }
        }
예제 #2
0
파일: IPC.cs 프로젝트: iamsamwood/ENCODERS
        public DataObjectEvent(cHaggleEvent e)
            : base(e)
        {
            if (e.type != HaggleEvent.NEW_DATAOBJECT)
                        {
                                throw new Exception("Not a new data object event");
                        }

                        dObj = new DataObject(e.data);
        }
예제 #3
0
        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);
            }
        }
예제 #4
0
        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);
                        }
        }
예제 #5
0
파일: IPC.cs 프로젝트: iamsamwood/ENCODERS
 public int PublishDataObject(DataObject dObj)
 {
     return UnmanagedPublishDataObject(this.handle, dObj.cDataObject);
 }
예제 #6
0
파일: IPC.cs 프로젝트: iamsamwood/ENCODERS
 public int DeleteDataObject(DataObject dObj)
 {
     return UnmanagedDeleteDataObject(handle, dObj.cDataObject);
 }