コード例 #1
0
        partial void okButtonClicked(AppKit.NSButton sender)
        {
            spinner.Hidden = false;
            spinner.StartAnimation(this);

            NSError error;
            var     networkName   = nameTextField.StringValue;
            var     password      = passwordTextField.StringValue;
            var     channelNumber = UInt32.Parse(channelPicker.SelectedItem.Title);
            var     security      = string.IsNullOrEmpty(password) ? CWIbssModeSecurity.None : CWIbssModeSecurity.WEP40;

            CurrentInterface.StartIbssModeWithSsid(new NSData(), security, channelNumber, password, out error);

            spinner.StopAnimation(this);
            spinner.Hidden = true;

            if (error != null)
            {
                NSAlert.WithError(error).RunModal();
            }
            else
            {
                Window.Close();
            }
        }
コード例 #2
0
        partial void okButtonCkicked(Foundation.NSObject sender)
        {
            spinner.Hidden = false;
            spinner.StartAnimation(this);

            if (CurrentInterface == null)
            {
                return;
            }

            NSError error;

            CurrentInterface.AssociateToNetwork(NetworkToJoin, passphraseTextField.StringValue, out error);

            spinner.StopAnimation(this);
            spinner.Hidden = true;

            if (error != null)
            {
                NSAlert.WithError(error).RunModal();
            }
            else
            {
                Window.Close();
            }
        }
コード例 #3
0
ファイル: MyDocument.cs プロジェクト: chamons/mac-samples-1
        public override void WindowControllerDidLoadNib(NSWindowController windowController)
        {
            NSError err;

            // Create a movie, and store the information in memory on an NSMutableData
            movie = new QTMovie(new NSMutableData(1), out err);
            if (movie == null)
            {
                NSAlert.WithError(err).RunModal();
                return;
            }

            movieView.Movie = movie;

            // Find video device
            captureSession = new QTCaptureSession();
            var device = QTCaptureDevice.GetDefaultInputDevice(QTMediaType.Video);

            if (device == null)
            {
                new NSAlert {
                    MessageText = "You do not have a camera connected."
                }.BeginSheet(windowController.Window);
                return;
            }
            else if (!device.Open(out err))
            {
                NSAlert.WithError(err).BeginSheet(windowController.Window);
                return;
            }

            // Add device input
            captureInput = new QTCaptureDeviceInput(device);
            if (!captureSession.AddInput(captureInput, out err))
            {
                NSAlert.WithError(err).BeginSheet(windowController.Window);
                return;
            }

            // Create decompressor for video output, to get raw frames
            decompressedVideo = new QTCaptureDecompressedVideoOutput();
            decompressedVideo.DidOutputVideoFrame += delegate(object sender, QTCaptureVideoFrameEventArgs e) {
                lock (this) {
                    currentImage = e.VideoFrame;
                }
            };
            if (!captureSession.AddOutput(decompressedVideo, out err))
            {
                NSAlert.WithError(err).BeginSheet(windowController.Window);
                return;
            }

            // Activate preview
            captureView.CaptureSession = captureSession;

            // Start running.
            captureSession.StartRunning();
        }
コード例 #4
0
        partial void joinOKButtonPressed(NSObject sender)
        {
            CW8021XProfile profile = null;

            joinSpinner.Hidden = false;
            joinSpinner.StartAnimation(Window);

            if (joinUser8021XProfilePopupButton.Enabled)
            {
                if (String.Equals(joinUser8021XProfilePopupButton, "Default"))
                {
                    profile                 = CW8021XProfile.Profile;
                    profile.Ssid            = joinNetworkNameField.StringValue;
                    profile.UserDefinedName = joinNetworkNameField.StringValue;
                    profile.Username        = !String.IsNullOrEmpty(joinUsernameField.StringValue) ? joinUsernameField.StringValue : null;
                    profile.Password        = !String.IsNullOrEmpty(joinPassphraseField.StringValue) ? joinPassphraseField.StringValue : null;
                }
                else
                {
                    var index = joinUser8021XProfilePopupButton.IndexOfSelectedItem;
                    if (index >= 0)
                    {
                        profile = CW8021XProfile.AllUser8021XProfiles[index];
                    }
                }
            }

            if (JoinDialogContext)
            {
                NSMutableDictionary param = new NSMutableDictionary();
                if (profile != null)
                {
                    param.SetValueForKey(profile, CWConstants.CWAssocKey8021XProfile);
                }

                else
                {
                    param.SetValueForKey(!String.IsNullOrEmpty(joinPassphraseField.StringValue) ? joinPassphraseField.ObjectValue: null, CWConstants.CWAssocKeyPassPhrase);
                }

                NSError error  = null;
                bool    result = CurrentInterface.AssociateToNetwork(SelectedNetwork, NSDictionary.FromDictionary(param), out error);

                joinSpinner.StopAnimation(Window);
                joinSpinner.Hidden = true;

                if (!result)
                {
                    NSAlert.WithError(error).RunModal();
                }

                else
                {
                    joinCancelButtonPressed(this);
                }
            }
        }
コード例 #5
0
        void ChangeWirelessInterfacePower()
        {
            NSError error = null;

            if (!currentInterface.SetPower(WirelessInterfaceToggleButton.SelectedSegment == 0, out error))
            {
                NSAlert.WithError(error).BeginSheet(Window);
            }

            UpdateWirelessInterfaceUI();
        }
コード例 #6
0
        partial void changeChannel(NSObject sender)
        {
            NSError error  = null;
            bool    result = CurrentInterface.SetChannel(Convert.ToUInt32(channelPopup.SelectedItem.Title), out error);

            if (!result)
            {
                NSAlert.WithError(error).RunModal();
            }

            UpdateInterfaceInfoTab();
        }
コード例 #7
0
        partial void changePower(NSObject sender)
        {
            NSError error  = null;
            bool    result = CurrentInterface.SetPower(powerStateControl.SelectedSegment == 0, out error);

            if (!result)
            {
                NSAlert.WithError(error).RunModal();
            }

            UpdateInterfaceInfoTab();
        }
コード例 #8
0
        partial void ibssOKButtonPressed(NSObject sender)
        {
            ibssSpinner.Hidden = false;
            ibssSpinner.StartAnimation(this);

            string   networkName = ibssNetworkNameField.StringValue;
            NSNumber channel     = new NSNumber(Convert.ToInt32(ibssChannelPopupButton.SelectedItem.Title));
            string   passPhrase  = ibssPassphraseField.StringValue;

            NSMutableDictionary ibssParams = new NSMutableDictionary();

            if (!(String.IsNullOrEmpty(networkName)))
            {
                ibssParams.SetValueForKey(ibssNetworkNameField.ObjectValue, CWConstants.CWIBSSKeySSID);
            }


            if (channel.IntValue > 0)
            {
                ibssParams.SetValueForKey(channel, CWConstants.CWIBSSKeyChannel);
            }

            if (!(String.IsNullOrEmpty(passPhrase)))
            {
                ibssParams.SetValueForKey(ibssPassphraseField.ObjectValue, CWConstants.CWIBSSKeyPassphrase);
            }

            NSError error = null;

            bool created = CurrentInterface.EnableIBSSWithParameters(NSDictionary.FromDictionary(ibssParams), out error);

            ibssSpinner.StopAnimation(this);
            ibssSpinner.Hidden = true;

            if (!created)
            {
                NSAlert.WithError(error).RunModal();
            }
            else
            {
                ibssCancelButtonPressed(this);
            }
        }
コード例 #9
0
        private void UpdateScanTab()
        {
            NSDictionary param = NSDictionary.FromObjectAndKey(NSNumber.FromBoolean(mergeScanResultsCheckbox.State == NSCellStateValue.On), new NSString("true"));
            NSError      error = null;

            ScanResults = CurrentInterface.ScanForNetworksWithParameters(param, out error);
            if (error == null)
            {
                Array.Sort(ScanResults, delegate(CWNetwork networkA, CWNetwork networkB)
                {
                    return(networkA.Ssid.CompareTo(networkB.Ssid));
                });
            }
            else
            {
                ScanResults = new CWNetwork[0];
                NSAlert.WithError(error).RunModal();
            }

            scanResultsTable.ReloadData();
        }
コード例 #10
0
        public void SavePDF(Foundation.NSObject sender)
        {
            NSSavePanel panel = NSSavePanel.SavePanel;

            panel.AllowedFileTypes = new string[] { "pdf" };
            panel.BeginSheet(this.Window, (result) => {
                if (result == 1)
                {
                    CGRect r        = this.Bounds;
                    NSData data     = this.DataWithPdfInsideRect(r);
                    NSError error   = null;
                    bool successful = data.Save(panel.Url, false, out error);
                    if (!successful)
                    {
                        NSAlert a = NSAlert.WithError(error);
                        a.RunModal();
                    }
                }
                panel = null;
            });
        }
コード例 #11
0
        void DidFinishRecording(object sender, QTCaptureFileErrorEventArgs e)
        {
            Console.WriteLine("Recorded {0} bytes duration {1}", movieFileOutput.RecordedFileSize, movieFileOutput.RecordedDuration);
            DidChangeValue("Recording");

            // TODO: https://bugzilla.xamarin.com/show_bug.cgi?id=27691
            IntPtr library = Dlfcn.dlopen("/System/Library/Frameworks/QTKit.framework/QTKit", 0);
            var    key     = Dlfcn.GetStringConstant(library, "QTCaptureConnectionAttributeWillChangeNotification");

            if (e.Reason != null && !((NSNumber)e.Reason.UserInfo [key]).BoolValue)
            {
                NSAlert.WithError(e.Reason).BeginSheet(Window, () => {
                });
                return;
            }

            var save = NSSavePanel.SavePanel;

            save.AllowedFileTypes         = new string[] { "mov" };
            save.CanSelectHiddenExtension = true;
            save.BeginSheet(WindowForSheet, code => {
                NSError err2;
                if (code == (int)NSPanelButtonType.Ok)
                {
                    if (NSFileManager.DefaultManager.Move(e.OutputFileURL, save.Url, out err2))
                    {
                        NSWorkspace.SharedWorkspace.OpenUrl(save.Url);
                    }
                    else
                    {
                        save.OrderOut(this);
                    }
                }
                else
                {
                    NSFileManager.DefaultManager.Remove(e.OutputFileURL.Path, out err2);
                }
            });
        }
コード例 #12
0
        public override void WindowControllerDidLoadNib(NSWindowController windowController)
        {
            base.WindowControllerDidLoadNib(windowController);

            // A reference to the window controller must be kept on the managed side
            // to keep the object from being GC'd so that the delegates below resolve.
            // Don't remove unless the framework is updated to track the reference.
            this.windowController = windowController;

            NSError err;

            windowController.Window.WillClose += delegate {
                if (captureSession != null)
                {
                    captureSession.StopRunning();
                }
                var dev = captureInput.Device;
                if (dev.IsOpen)
                {
                    dev.Close();
                }
            };

            // Create a movie, and store the information in memory on an NSMutableData
            movie = new QTMovie(new NSMutableData(1), out err);
            if (movie == null)
            {
                NSAlert.WithError(err).RunModal();
                return;
            }
            movieView.Movie = movie;

            // Find video device
            captureSession = new QTCaptureSession();
            var device = QTCaptureDevice.GetDefaultInputDevice(QTMediaType.Video);

            if (!device.Open(out err))
            {
                NSAlert.WithError(err).RunModal();
                return;
            }

            // Add device input
            captureInput = new QTCaptureDeviceInput(device);
            if (!captureSession.AddInput(captureInput, out err))
            {
                NSAlert.WithError(err).RunModal();
                return;
            }

            // Create decompressor for video output, to get raw frames
            decompressedVideo = new QTCaptureDecompressedVideoOutput();
            decompressedVideo.DidOutputVideoFrame += delegate(object sender, QTCaptureVideoFrameEventArgs e) {
                lock (this){
                    currentImage = e.VideoFrame;
                }
            };
            if (!captureSession.AddOutput(decompressedVideo, out err))
            {
                NSAlert.WithError(err).RunModal();
                return;
            }

            // Activate preview
            captureView.CaptureSession = captureSession;

            // Start running.
            captureSession.StartRunning();
        }
コード例 #13
0
        /*	[Export("initWithCoder:")]
         *      public QTRDocument (NSCoder coder) : base(coder)
         *      {
         *      }*/

        public override void WindowControllerDidLoadNib(NSWindowController windowController)
        {
            NSError error;

            base.WindowControllerDidLoadNib(windowController);

            // Create session
            session = new QTCaptureSession();

            // Attach preview to session
            captureView.CaptureSession   = session;
            captureView.WillDisplayImage = (view, image) => {
                if (videoPreviewFilterDescription == null)
                {
                    return(image);
                }
                var selectedFilter = (NSString)videoPreviewFilterDescription [filterNameKey];

                var filter = CIFilter.FromName(selectedFilter);
                filter.SetDefaults();
                filter.SetValueForKey(image, CIFilterInputKey.Image);

                return((CIImage)filter.ValueForKey(CIFilterOutputKey.Image));
            };

            // Attach outputs to session
            movieFileOutput = new QTCaptureMovieFileOutput();

            movieFileOutput.WillStartRecording += delegate {
                Console.WriteLine("Will start recording");
            };
            movieFileOutput.DidStartRecording += delegate {
                Console.WriteLine("Started Recording");
            };

            movieFileOutput.ShouldChangeOutputFile = (output, url, connections, reason) => {
                // Should change the file on error
                Console.WriteLine(reason.LocalizedDescription);
                return(false);
            };
            movieFileOutput.MustChangeOutputFile += delegate(object sender, QTCaptureFileErrorEventArgs e) {
                Console.WriteLine("Must change file due to error");
            };

            // These ones we care about, some notifications
            movieFileOutput.WillFinishRecording += delegate(object sender, QTCaptureFileErrorEventArgs e) {
                Console.WriteLine("Will finish recording");
                InvokeOnMainThread(delegate {
                    WillChangeValue("Recording");
                });
            };
            movieFileOutput.DidFinishRecording += delegate(object sender, QTCaptureFileErrorEventArgs e) {
                Console.WriteLine("Recorded {0} bytes duration {1}", movieFileOutput.RecordedFileSize, movieFileOutput.RecordedDuration);
                DidChangeValue("Recording");
                if (e.Reason != null)
                {
                    NSAlert.WithError(e.Reason).BeginSheet(Window, () => {});
                    return;
                }
                var save = NSSavePanel.SavePanel;
                save.AllowedFileTypes         = new string[] { "mov" };
                save.CanSelectHiddenExtension = true;
                save.Begin(code => {
                    NSError err2;
                    if (code == (int)NSPanelButtonType.Ok)
                    {
                        NSFileManager.DefaultManager.Move(e.OutputFileURL, save.Url, out err2);
                    }
                    else
                    {
                        NSFileManager.DefaultManager.Remove(e.OutputFileURL.Path, out err2);
                    }
                });
            };

            session.AddOutput(movieFileOutput, out error);

            audioPreviewOutput = new QTCaptureAudioPreviewOutput();
            session.AddOutput(audioPreviewOutput, out error);

            if (VideoDevices.Length > 0)
            {
                SelectedVideoDevice = VideoDevices [0];
            }

            if (AudioDevices.Length > 0)
            {
                SelectedAudioDevice = AudioDevices [0];
            }

            session.StartRunning();

            // events: devices added/removed
            AddObserver(QTCaptureDevice.WasConnectedNotification, DevicesDidChange);
            AddObserver(QTCaptureDevice.WasDisconnectedNotification, DevicesDidChange);

            // events: connection format changes
            AddObserver(QTCaptureConnection.FormatDescriptionDidChangeNotification, FormatDidChange);
            AddObserver(QTCaptureConnection.FormatDescriptionWillChangeNotification, FormatWillChange);

            AddObserver(QTCaptureDevice.AttributeDidChangeNotification, AttributeDidChange);
            AddObserver(QTCaptureDevice.AttributeWillChangeNotification, AttributeWillChange);
        }
コード例 #14
0
 partial void NSAlertWithError(NSObject sender)
 {
     Run(NSAlert.WithError(new NSError(new NSString("org.mono-project.NSAlertSample"), 3000, null)));
 }