コード例 #1
0
ファイル: SparkleIntro.cs プロジェクト: ktze/SparkleShare
        public void ShowAccountForm()
        {
            Reset ();

                Header       = "Welcome to SparkleShare!";
                Description  = "Before we can create a SparkleShare folder on this " +
                               "computer, we need some information from you.";

                UserInfoForm = new NSForm (new RectangleF (250, 115, 350, 64));
                UserInfoForm.AddEntry ("Full Name:");
                UserInfoForm.AddEntry ("Email Address:");
                UserInfoForm.CellSize = new SizeF (280, 22);
                UserInfoForm.IntercellSpacing = new SizeF (4, 4);
                UserInfoForm.Cells [0].LineBreakMode = NSLineBreakMode.TruncatingTail;
                UserInfoForm.Cells [1].LineBreakMode = NSLineBreakMode.TruncatingTail;

                UserInfoForm.Cells [0].StringValue = SparkleShare.Controller.UserName;
                UserInfoForm.Cells [1].StringValue = SparkleShare.Controller.UserEmail;

                ContinueButton = new NSButton () {
                    Title    = "Continue",
                    Enabled = false
                };

                ContinueButton.Activated += delegate {
                    SparkleShare.Controller.UserName  = UserInfoForm.Cells [0].StringValue.Trim ();
                    SparkleShare.Controller.UserEmail = UserInfoForm.Cells [1].StringValue.Trim ();
                    SparkleShare.Controller.GenerateKeyPair ();
                    SparkleUI.StatusIcon.CreateMenu ();

                    InvokeOnMainThread (delegate {
                        ShowServerForm ();
                    });
                };

                // TODO: Ugly hack, do properly with events
                Timer timer = new Timer () {
                    Interval = 50
                };

                timer.Elapsed += delegate {
                    InvokeOnMainThread (delegate {
                        bool name_is_correct =
                            !UserInfoForm.Cells [0].StringValue.Trim ().Equals ("");

                        bool email_is_correct = SparkleShare.Controller.IsValidEmail (
                            UserInfoForm.Cells [1].StringValue.Trim ());

                        ContinueButton.Enabled = (name_is_correct && email_is_correct);
                    });
                };

                timer.Start ();

                ContentView.AddSubview (UserInfoForm);
                Buttons.Add (ContinueButton);

            ShowAll ();
        }
コード例 #2
0
        public SparkleSetup()
            : base()
        {
            Controller.ChangePageEvent += delegate (PageType type) {
                InvokeOnMainThread (delegate {
                    Reset ();

                    switch (type) {
                    case PageType.Setup:

                        Header       = "Welcome to SparkleShare!";
                        Description  = "Before we can create a SparkleShare folder on this " +
                                       "computer, we need some information from you.";

                        UserInfoForm = new NSForm (new RectangleF (250, 115, 350, 64));

                        UserInfoForm.AddEntry ("Full Name:");
                        UserInfoForm.AddEntry ("Email Address:");

                        UserInfoForm.CellSize                = new SizeF (280, 22);
                        UserInfoForm.IntercellSpacing        = new SizeF (4, 4);
                        UserInfoForm.Cells [0].LineBreakMode = NSLineBreakMode.TruncatingTail;
                        UserInfoForm.Cells [1].LineBreakMode = NSLineBreakMode.TruncatingTail;

                        UserInfoForm.Cells [0].StringValue   = SparkleShare.Controller.UserName;
                        UserInfoForm.Cells [1].StringValue   = SparkleShare.Controller.UserEmail;

                        // TODO: Ugly hack, do properly with events
                        timer = new Timer () {
                            Interval = 50
                        };

                        ContinueButton = new NSButton () {
                            Title    = "Continue",
                            Enabled  = false
                        };

                        ContinueButton.Activated += delegate {
                            timer.Stop ();
                            timer = null;

                            string full_name = UserInfoForm.Cells [0].StringValue.Trim ();
                            string email = UserInfoForm.Cells [1].StringValue.Trim ();

                            Controller.SetupPageCompleted (full_name, email);
                        };

                        timer.Elapsed += delegate {
                            InvokeOnMainThread (delegate {
                                bool name_is_valid = !UserInfoForm.Cells [0].StringValue.Trim ().Equals ("");

                                bool email_is_valid = SparkleShare.Controller.IsValidEmail (
                                    UserInfoForm.Cells [1].StringValue.Trim ());

                                ContinueButton.Enabled = (name_is_valid && email_is_valid);
                            });
                        };

                        timer.Start ();

                        ContentView.AddSubview (UserInfoForm);
                        Buttons.Add (ContinueButton);

                        break;

                    case PageType.Add:

                        Header       = "Where is your remote folder?";
                        Description  = "";

                        ServerTypeLabel  = new NSTextField () {
                            Alignment       = NSTextAlignment.Right,
                            BackgroundColor = NSColor.WindowBackground,
                            Bordered        = false,
                            Editable        = false,
                            Frame           = new RectangleF (150, Frame.Height - 139 , 160, 17),
                            StringValue     = "Server Type:",
                            Font            = SparkleUI.Font
                        };

                        AddressLabel = new NSTextField () {
                            Alignment       = NSTextAlignment.Right,
                            BackgroundColor = NSColor.WindowBackground,
                            Bordered        = false,
                            Editable        = false,
                            Frame           = new RectangleF (150, Frame.Height - 237 , 160, 17),
                            StringValue     = "Address:",
                            Font            = SparkleUI.Font
                        };

                        FolderNameLabel = new NSTextField () {
                            Alignment       = NSTextAlignment.Right,
                            BackgroundColor = NSColor.WindowBackground,
                            Bordered        = false,
                            Editable        = false,
                            Frame           = new RectangleF (150, Frame.Height - 264 , 160, 17),
                            StringValue     = "Folder Name:",
                            Font            = SparkleUI.Font
                        };

                        AddressTextField = new NSTextField () {
                            Frame       = new RectangleF (320, Frame.Height - 240 , 256, 22),
                            Font        = SparkleUI.Font,
                            StringValue = Controller.PreviousServer
                        };

                        AddressTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail;

                        FolderNameTextField = new NSTextField () {
                            Frame           = new RectangleF (320, Frame.Height - (240 + 22 + 4) , 256, 22),
                            StringValue     = Controller.PreviousFolder
                        };

                        FolderNameTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail;

                        FolderNameHelpLabel = new NSTextField () {
                            BackgroundColor = NSColor.WindowBackground,
                            Bordered        = false,
                            TextColor       = NSColor.DisabledControlText,
                            Editable        = false,
                            Frame           = new RectangleF (320, Frame.Height - 285 , 200, 17),
                            StringValue     = "e.g. ‘rupert/website-design’"
                        };

                        ServerType = 0;

                        ButtonCellProto = new NSButtonCell ();
                        ButtonCellProto.SetButtonType (NSButtonType.Radio) ;

                        Matrix = new NSMatrix (new RectangleF (315, 180, 256, 78),
                            NSMatrixMode.Radio, ButtonCellProto, 4, 1);

                        Matrix.CellSize = new SizeF (256, 18);

                        Matrix.Cells [0].Title = "My own server";
                        Matrix.Cells [1].Title = "Github";
                        Matrix.Cells [2].Title = "Gitorious";
                        Matrix.Cells [3].Title = "The GNOME Project";

                        foreach (NSCell cell in Matrix.Cells)
                            cell.Font = SparkleUI.Font;

                        // TODO: Ugly hack, do properly with events
                        timer = new Timer () {
                            Interval = 50
                        };

                        timer.Elapsed += delegate {
                            InvokeOnMainThread (delegate {
                                if (Matrix.SelectedRow != ServerType) {
                                    ServerType = Matrix.SelectedRow;

                                    AddressTextField.Enabled = (ServerType == 0);

                                    switch (ServerType) {
                                    case 0:
                                        AddressTextField.StringValue = "";
                                        FolderNameHelpLabel.StringValue = "e.g. ‘rupert/website-design’";
                                        break;
                                    case 1:
                                        AddressTextField.StringValue = "ssh://[email protected]/";
                                        FolderNameHelpLabel.StringValue = "e.g. ‘rupert/website-design’";
                                        break;
                                    case 2:
                                        AddressTextField.StringValue = "ssh://[email protected]/";
                                        FolderNameHelpLabel.StringValue = "e.g. ‘project/website-design’";
                                        break;
                                    case 3:
                                        AddressTextField.StringValue = "ssh://[email protected]/git/";
                                        FolderNameHelpLabel.StringValue = "e.g. ‘gnome-icon-theme’";
                                        break;
                                    }
                                }

                                if (ServerType == 0 && !AddressTextField.StringValue.Trim ().Equals ("")
                                    && !FolderNameTextField.StringValue.Trim ().Equals ("")) {

                                    SyncButton.Enabled = true;

                                } else if (ServerType != 0 &&
                                           !FolderNameTextField.StringValue.Trim ().Equals ("")) {

                                    SyncButton.Enabled = true;

                                } else {
                                    SyncButton.Enabled = false;
                                }
                            });

                        };

                        timer.Start ();

                        ContentView.AddSubview (ServerTypeLabel);
                        ContentView.AddSubview (Matrix);

                        ContentView.AddSubview (AddressLabel);
                        ContentView.AddSubview (AddressTextField);

                        ContentView.AddSubview (FolderNameLabel);
                        ContentView.AddSubview (FolderNameTextField);
                        ContentView.AddSubview (FolderNameHelpLabel);

                        SyncButton = new NSButton () {
                            Title = "Sync",
                            Enabled = false
                        };

                            SyncButton.Activated += delegate {
                                timer.Stop ();
                                timer = null;

                                string folder_name    = FolderNameTextField.StringValue;
                                string server         = AddressTextField.StringValue;
                                Controller.AddPageCompleted (server, folder_name);
                            };

                        Buttons.Add (SyncButton);

                            CancelButton = new NSButton () {
                                Title = "Cancel"
                            };

                            CancelButton.Activated += delegate {
                                InvokeOnMainThread (delegate {
                                    PerformClose (this);
                                });
                            };

                            Buttons.Add (CancelButton);

                        break;

                    case PageType.Syncing:

                        Header      = "Syncing folder ‘" + Controller.SyncingFolder + "’…";
                        Description = "This may take a while.\n" +
                                      "Are you sure it’s not coffee o'clock?";

                        ProgressIndicator = new NSProgressIndicator () {
                            Frame = new RectangleF (190, Frame.Height - 200, 640 - 150 - 80, 20),
                            Style = NSProgressIndicatorStyle.Bar
                        };

                        ProgressIndicator.StartAnimation (this);
                        ContentView.AddSubview (ProgressIndicator);

                        FinishButton = new NSButton () {
                            Title = "Finish",
                            Enabled = false
                        };

                        Buttons.Add (FinishButton);

                        break;

                    case PageType.Error:

                        Header      = "Something went wrong…";
                        Description = "";

                        TryAgainButton = new NSButton () {
                            Title = "Try again…"
                        };

                        TryAgainButton.Activated += delegate {
                            Controller.ErrorPageCompleted ();
                        };

                        Buttons.Add (TryAgainButton);

                        break;

                    case PageType.Finished:

                        Header      = "Folder synced succesfully!";
                        Description = "Now you can access the synced files from " +
                                      "‘" + Controller.SyncingFolder + "’ in " +
                                      "your SparkleShare folder.";

                        FinishButton = new NSButton () {
                            Title = "Finish"
                        };

                        FinishButton.Activated += delegate {
                            InvokeOnMainThread (delegate {
                                PerformClose (this);
                            });
                        };

                        OpenFolderButton = new NSButton () {
                            Title = "Open Folder"
                        };

                        OpenFolderButton.Activated += delegate {
                            SparkleShare.Controller.OpenSparkleShareFolder (Controller.SyncingFolder);
                        };

                        Buttons.Add (FinishButton);
                        Buttons.Add (OpenFolderButton);

                        NSApplication.SharedApplication.RequestUserAttention
                            (NSRequestUserAttentionType.CriticalRequest);

                        break;
                    }

                    ShowAll ();
                });
            };
        }
コード例 #3
0
        public void ShowAccountForm()
        {
            Reset();

            Header      = "Welcome to SparkleShare!";
            Description = "Before we can create a SparkleShare folder on this " +
                          "computer, we need some information from you.";


            UserInfoForm = new NSForm(new RectangleF(250, 115, 350, 64));
            UserInfoForm.AddEntry("Full Name:");
            UserInfoForm.AddEntry("Email Address:");
            UserInfoForm.CellSize         = new SizeF(280, 22);
            UserInfoForm.IntercellSpacing = new SizeF(4, 4);

            string full_name = new UnixUserInfo(UnixEnvironment.UserName).RealName;

            if (string.IsNullOrEmpty(full_name))
            {
                full_name = "";
            }

            UserInfoForm.Cells [0].StringValue = full_name.TrimEnd(",".ToCharArray());;
            UserInfoForm.Cells [1].StringValue = SparkleShare.Controller.UserEmail;


            ContinueButton = new NSButton()
            {
                Title   = "Continue",
                Enabled = false
            };

            ContinueButton.Activated += delegate {
                SparkleShare.Controller.UserName  = UserInfoForm.Cells [0].StringValue.Trim();
                SparkleShare.Controller.UserEmail = UserInfoForm.Cells [1].StringValue.Trim();
                SparkleShare.Controller.GenerateKeyPair();
                SparkleShare.Controller.FirstRun = false;

                InvokeOnMainThread(delegate {
                    ShowServerForm();
                });
            };


            // TODO: Ugly hack, do properly with events
            Timer timer = new Timer()
            {
                Interval = 50
            };

            timer.Elapsed += delegate {
                InvokeOnMainThread(delegate {
                    bool name_is_correct =
                        !UserInfoForm.Cells [0].StringValue.Trim().Equals("");

                    bool email_is_correct = SparkleShare.Controller.IsValidEmail
                                                (UserInfoForm.Cells [1].StringValue.Trim());

                    ContinueButton.Enabled = (name_is_correct && email_is_correct);
                });
            };

            timer.Start();

            ContentView.AddSubview(UserInfoForm);
            Buttons.Add(ContinueButton);

            ShowAll();
        }
コード例 #4
0
        public SparkleSetup()
            : base()
        {
            Controller.ChangePageEvent += delegate (PageType type) {
                InvokeOnMainThread (delegate {
                    Reset ();

                    switch (type) {
                    case PageType.Setup: {

                        Header       = "Welcome to SparkleShare!";
                        Description  = "Before we can create a SparkleShare folder on this " +
                                       "computer, we need some information from you.";

                        UserInfoForm = new NSForm (new RectangleF (250, Frame.Height - 280, 350, 64));

                        UserInfoForm.AddEntry ("Full Name:");
                        UserInfoForm.AddEntry ("Email Address:");

                        UserInfoForm.CellSize                = new SizeF (280, 22);
                        UserInfoForm.IntercellSpacing        = new SizeF (4, 4);
                        UserInfoForm.Cells [0].LineBreakMode = NSLineBreakMode.TruncatingTail;
                        UserInfoForm.Cells [1].LineBreakMode = NSLineBreakMode.TruncatingTail;

                        UserInfoForm.Cells [0].StringValue   = Controller.GuessedUserName;
                        UserInfoForm.Cells [1].StringValue   = Controller.GuessedUserEmail;

                        // TODO: Ugly hack, do properly with events
                        timer = new Timer () {
                            Interval = 50
                        };

                        ContinueButton = new NSButton () {
                            Title    = "Continue",
                            Enabled  = false
                        };

                        ContinueButton.Activated += delegate {
                            timer.Stop ();
                            timer = null;

                            string full_name = UserInfoForm.Cells [0].StringValue.Trim ();
                            string email = UserInfoForm.Cells [1].StringValue.Trim ();

                            Controller.SetupPageCompleted (full_name, email);
                        };

                        timer.Elapsed += delegate {
                            InvokeOnMainThread (delegate {
                                bool name_is_valid = !UserInfoForm.Cells [0].StringValue.Trim ().Equals ("");

                                bool email_is_valid = Program.Controller.IsValidEmail (
                                    UserInfoForm.Cells [1].StringValue.Trim ());

                                ContinueButton.Enabled = (name_is_valid && email_is_valid);
                            });
                        };

                        timer.Start ();

                        ContentView.AddSubview (UserInfoForm);
                        Buttons.Add (ContinueButton);

                        break;
                    }

                    case PageType.Add: {

                        Header       = "Where's your project hosted?";
                        Description  = "";

                        AddressLabel = new NSTextField () {
                            Alignment       = NSTextAlignment.Left,
                            BackgroundColor = NSColor.WindowBackground,
                            Bordered        = false,
                            Editable        = false,
                            Frame           = new RectangleF (190, Frame.Height - 308, 160, 17),
                            StringValue     = "Address:",
                            Font            = SparkleUI.Font
                        };

                        AddressTextField = new NSTextField () {
                            Frame       = new RectangleF (190, Frame.Height - 336, 196, 22),
                            Font        = SparkleUI.Font,
                            StringValue = Controller.PreviousAddress,
                            Enabled     = (Controller.SelectedPlugin.Address == null)
                        };

                        PathLabel = new NSTextField () {
                            Alignment       = NSTextAlignment.Left,
                            BackgroundColor = NSColor.WindowBackground,
                            Bordered        = false,
                            Editable        = false,
                            Frame           = new RectangleF (190 + 196 + 16, Frame.Height - 308, 160, 17),
                            StringValue     = "Remote Path:",
                            Font            = SparkleUI.Font
                        };

                        PathTextField = new NSTextField () {
                            Frame           = new RectangleF (190 + 196 + 16, Frame.Height - 336, 196, 22),
                            StringValue     = Controller.PreviousPath,
                            Enabled         = (Controller.SelectedPlugin.Path == null)
                        };

                        AddressTextField.Cell.LineBreakMode    = NSLineBreakMode.TruncatingTail;
                        PathTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail;

                        PathHelpLabel = new NSTextField () {
                            BackgroundColor = NSColor.WindowBackground,
                            Bordered        = false,
                            TextColor       = NSColor.DisabledControlText,
                            Editable        = false,
                            Frame           = new RectangleF (190 + 196 + 16, Frame.Height - 355, 204, 17),
                            StringValue     = "e.g. ‘rupert/website-design’",
                            Font            = NSFontManager.SharedFontManager.FontWithFamily
                                                  ("Lucida Grande", NSFontTraitMask.Condensed, 0, 11)
                        };

                        TableView = new NSTableView () {
                            Frame            = new RectangleF (0, 0, 0, 0),
                            RowHeight        = 30,
                            IntercellSpacing = new SizeF (0, 12),
                            HeaderView       = null
                        };

                        ScrollView = new NSScrollView () {
                            Frame               = new RectangleF (190, Frame.Height - 280, 408, 175),
                            DocumentView        = TableView,
                            HasVerticalScroller = true,
                            BorderType          = NSBorderType.BezelBorder
                        };

                        IconColumn = new NSTableColumn (new NSImage ()) {
                            Width = 42,
                            HeaderToolTip = "Icon",
                            DataCell = new NSImageCell ()
                        };

                        DescriptionColumn = new NSTableColumn () {
                            Width         = 350,
                            HeaderToolTip = "Description",
                            Editable      = false
                        };

                        DescriptionColumn.DataCell.Font =
                            NSFontManager.SharedFontManager.FontWithFamily (
                                "Lucida Grande", NSFontTraitMask.Condensed, 0, 11);

                        TableView.AddColumn (IconColumn);
                        TableView.AddColumn (DescriptionColumn);

                        DataSource = new SparkleDataSource ();

                        foreach (SparklePlugin plugin in Controller.Plugins)
                            DataSource.Items.Add (plugin);

                        TableView.DataSource = DataSource;
                        TableView.ReloadData ();

                        Controller.ChangeAddressFieldEvent += delegate (string text,
                            string example_text, FieldState state) {

                            InvokeOnMainThread (delegate {
                                AddressTextField.StringValue = text;
                                AddressTextField.Enabled     = (state == FieldState.Enabled);
                            });
                        };

                        Controller.ChangePathFieldEvent += delegate (string text,
                            string example_text, FieldState state) {

                            InvokeOnMainThread (delegate {
                                PathTextField.StringValue = text;
                                PathTextField.Enabled     = (state == FieldState.Enabled);

                                if (!string.IsNullOrEmpty (example_text))
                                    PathHelpLabel.StringValue = "e.g. " + example_text;
                            });
                        };

                        TableView.SelectRow (Controller.SelectedPluginIndex, false);

                        timer = new Timer () {
                            Interval = 50
                        };

                        // TODO: Use an event
                        timer.Elapsed += delegate {
                            if (TableView.SelectedRow != Controller.SelectedPluginIndex)
                                Controller.SelectedPluginChanged (TableView.SelectedRow);

                            InvokeOnMainThread (delegate {
                                // TODO: Move checking logic to controller
                                if (!string.IsNullOrWhiteSpace (AddressTextField.StringValue) &&
                                    !string.IsNullOrWhiteSpace (PathTextField.StringValue)) {

                                    SyncButton.Enabled = true;

                                } else {
                                    SyncButton.Enabled = false;
                                }
                            });
                        };

                        timer.Start ();

                        ContentView.AddSubview (ScrollView);
                        ContentView.AddSubview (AddressLabel);
                        ContentView.AddSubview (AddressTextField);
                        ContentView.AddSubview (PathLabel);
                        ContentView.AddSubview (PathTextField);
                        ContentView.AddSubview (PathHelpLabel);

                        SyncButton = new NSButton () {
                            Title = "Add",
                            Enabled = false
                        };

                            SyncButton.Activated += delegate {
                                timer.Stop ();
                                timer = null;

                                Controller.AddPageCompleted (
                                    AddressTextField.StringValue,
                                    PathTextField.StringValue
                                );
                            };

                        Buttons.Add (SyncButton);

                            CancelButton = new NSButton () {
                                Title = "Cancel"
                            };

                            CancelButton.Activated += delegate {
                                InvokeOnMainThread (delegate {
                                    PerformClose (this);
                                });
                            };

                        Buttons.Add (CancelButton);

                        break;
                    }

                    case PageType.Syncing: {

                        Header      = "Adding project ‘" + Controller.SyncingFolder + "’…";
                        Description = "This may take a while.\n" +
                                      "Are you sure it’s not coffee o'clock?";

                        ProgressIndicator = new NSProgressIndicator () {
                            Frame    = new RectangleF (190, Frame.Height - 200, 640 - 150 - 80, 20),
                            Style    = NSProgressIndicatorStyle.Bar,
                            MinValue = 0.0,
                            MaxValue = 100.0,
                            Indeterminate = false,
                            DoubleValue = 1.0
                        };

                        ProgressIndicator.StartAnimation (this);

                        Controller.UpdateProgressBarEvent += delegate (double percentage) {
                            InvokeOnMainThread (delegate {
                                ProgressIndicator.DoubleValue = percentage;
                            });
                        };

                        ContentView.AddSubview (ProgressIndicator);

                        FinishButton = new NSButton () {
                            Title = "Finish",
                            Enabled = false
                        };

                        CancelButton = new NSButton () {
                            Title = "Cancel"
                        };

                        CancelButton.Activated += delegate {
                            Controller.SyncingCancelled ();
                        };

                        Buttons.Add (FinishButton);
                        Buttons.Add (CancelButton);

                        break;
                    }

                    case PageType.Error: {

                        Header      = "Something went wrong…";
                        Description = "Please check the following:";

                        // Displaying marked up text with Cocoa is
                        // a pain, so we just use a webview instead
                        WebView web_view = new WebView ();
                        web_view.Frame = new RectangleF (190, Frame.Height - 525, 375, 400);

                        string html = "<style>" +
                            "* {" +
                            "  font-family: 'Lucida Grande';" +
                            "  font-size: 12px; cursor: default;" +
                            "}" +
                            "body {" +
                            "  -webkit-user-select: none;" +
                            "  margin: 0;" +
                            "  padding: 3px;" +
                            "}" +
                            "li {" +
                            "  margin-bottom: 16px;" +
                            "  margin-left: 0;" +
                            "  padding-left: 0;" +
                            "  line-height: 20px;" +
                            "}" +
                            "ul {" +
                            "  padding-left: 24px;" +
                            "}" +
                            "</style>" +
                            "<ul>" +
                            "  <li>First, have you tried turning it off and on again?</li>" +
                            "  <li><b>" + Controller.PreviousUrl + "</b> is the address we've compiled. Does this look alright?</li>" +
                            "  <li>The host needs to know who you are. Did you upload the key that's in your SparkleShare folder?</li>" +
                            "</ul>";

                        web_view.MainFrame.LoadHtmlString (html, new NSUrl (""));
                        web_view.DrawsBackground = false;

                        ContentView.AddSubview (web_view);

                        TryAgainButton = new NSButton () {
                            Title = "Try again…"
                        };

                        TryAgainButton.Activated += delegate {
                            Controller.ErrorPageCompleted ();
                        };

                        Buttons.Add (TryAgainButton);

                        break;
                    }

                    case PageType.Finished: {

                        Header      = "Project succesfully added!";
                        Description = "Now you can access the files from " +
                                      "‘" + Controller.SyncingFolder + "’ in " +
                                      "your SparkleShare folder.";

                        FinishButton = new NSButton () {
                            Title = "Finish"
                        };

                        FinishButton.Activated += delegate {
                            InvokeOnMainThread (delegate {
                                Controller.FinishedPageCompleted ();
                                PerformClose (this);
                            });
                        };

                        OpenFolderButton = new NSButton () {
                            Title = "Open Folder"
                        };

                        OpenFolderButton.Activated += delegate {
                            Program.Controller.OpenSparkleShareFolder (Controller.SyncingFolder);
                        };

                        Buttons.Add (FinishButton);
                        Buttons.Add (OpenFolderButton);

                        NSApplication.SharedApplication.RequestUserAttention
                            (NSRequestUserAttentionType.CriticalRequest);

                        NSSound.FromName ("Glass").Play ();

                        break;
                    }

                    case PageType.Tutorial: {

                        switch (Controller.TutorialPageNumber) {
                        case 1: {
                            Header      = "What's happening next?";
                            Description = "SparkleShare creates a special folder in your personal folder " +
                                "that will keep track of your projects.";

                            SkipTutorialButton = new NSButton () {
                                Title = "Skip Tutorial"
                            };

                            SkipTutorialButton.Activated += delegate {
                                Controller.TutorialSkipped ();
                            };

                            ContinueButton = new NSButton () {
                                Title = "Continue"
                            };

                            ContinueButton.Activated += delegate {
                                Controller.TutorialPageCompleted ();
                            };

                            string slide_image_path = Path.Combine (NSBundle.MainBundle.ResourcePath,
                                "Pixmaps", "tutorial-slide-1.png");

                            SlideImage = new NSImage (slide_image_path) {
                                Size = new SizeF (350, 200)
                            };

                            SlideImageView = new NSImageView () {
                                Image = SlideImage,
                                Frame = new RectangleF (215, Frame.Height - 350, 350, 200)
                            };

                            ContentView.AddSubview (SlideImageView);
                            Buttons.Add (ContinueButton);
                            Buttons.Add (SkipTutorialButton);

                            break;
                        }

                        case 2: {
                            Header      = "Sharing files with others";
                            Description = "All files added to your project folders are synced with the host " +
                                "automatically, as well as with your collaborators.";

                            ContinueButton = new NSButton () {
                                Title = "Continue"
                            };

                            ContinueButton.Activated += delegate {
                                Controller.TutorialPageCompleted ();
                            };

                            string slide_image_path = Path.Combine (NSBundle.MainBundle.ResourcePath,
                                "Pixmaps", "tutorial-slide-2.png");

                            SlideImage = new NSImage (slide_image_path) {
                                Size = new SizeF (350, 200)
                            };

                            SlideImageView = new NSImageView () {
                                Image = SlideImage,
                                Frame = new RectangleF (215, Frame.Height - 350, 350, 200)
                            };

                            ContentView.AddSubview (SlideImageView);
                            Buttons.Add (ContinueButton);

                            break;
                        }

                        case 3: {
                            Header      = "The status icon is here to help";
                            Description = "It shows the syncing process status, " +
                                "and contains links to your projects and the event log.";

                            ContinueButton = new NSButton () {
                                Title = "Continue"
                            };

                            ContinueButton.Activated += delegate {
                                Controller.TutorialPageCompleted ();
                            };

                            string slide_image_path = Path.Combine (NSBundle.MainBundle.ResourcePath,
                                "Pixmaps", "tutorial-slide-3.png");

                            SlideImage = new NSImage (slide_image_path) {
                                Size = new SizeF (350, 200)
                            };

                            SlideImageView = new NSImageView () {
                                Image = SlideImage,
                                Frame = new RectangleF (215, Frame.Height - 350, 350, 200)
                            };

                            ContentView.AddSubview (SlideImageView);
                            Buttons.Add (ContinueButton);

                            break;
                        }

                        case 4: {
                            Header      = "Adding projects to SparkleShare";
                            Description = "Just click this button when you see it on the web, and " +
                                "the project will be automatically added:";

                            AddProjectTextField = new NSTextField () {
                                Frame           = new RectangleF (190, Frame.Height - 290, 640 - 240, 44),
                                BackgroundColor = NSColor.WindowBackground,
                                Bordered        = false,
                                Editable        = false,
                                Font            = SparkleUI.Font,
                                StringValue     = "…or select ‘Add Project…’ from the status icon menu " +
                                "to add one by hand."
                            };

                            AddProjectButton = new NSButton () {
                                Title = "Add Project…"
                            };

                            AddProjectButton.Activated += delegate {
                                Controller.TutorialPageCompleted ();
                            };

                            FinishButton = new NSButton () {
                                Title = "Finish"
                            };

                            FinishButton.Activated += delegate {
                                InvokeOnMainThread (delegate {
                                    PerformClose (this);
                                });
                            };

                            string slide_image_path = Path.Combine (NSBundle.MainBundle.ResourcePath,
                                "Pixmaps", "tutorial-slide-4.png");

                            SlideImage = new NSImage (slide_image_path) {
                                Size = new SizeF (350, 64)
                            };

                            SlideImageView = new NSImageView () {
                                Image = SlideImage,
                                Frame = new RectangleF (215, Frame.Height - 215, 350, 64)
                            };

                            ContentView.AddSubview (SlideImageView);
                            ContentView.AddSubview (AddProjectTextField);
                            Buttons.Add (FinishButton);
                            Buttons.Add (AddProjectButton);

                            break;
                        }
                        }

                        break;
                    }
                    }

                    ShowAll ();
                });
            };
        }
コード例 #5
0
ファイル: SparkleSetup.cs プロジェクト: kkris/SparkleShare
        public SparkleSetup()
            : base()
        {
            Controller.ChangePageEvent += delegate (PageType type) {
                InvokeOnMainThread (delegate {
                    Reset ();

                    switch (type) {
                    case PageType.Setup: {

                        Header       = "Welcome to SparkleShare!";
                        Description  = "Before we can create a SparkleShare folder on this " +
                                       "computer, we need some information from you.";

                        UserInfoForm = new NSForm (new RectangleF (250, Frame.Height - 280, 350, 64));

                        UserInfoForm.AddEntry ("Full Name:");
                        UserInfoForm.AddEntry ("Email Address:");

                        UserInfoForm.CellSize                = new SizeF (280, 22);
                        UserInfoForm.IntercellSpacing        = new SizeF (4, 4);
                        UserInfoForm.Cells [0].LineBreakMode = NSLineBreakMode.TruncatingTail;
                        UserInfoForm.Cells [1].LineBreakMode = NSLineBreakMode.TruncatingTail;

                        UserInfoForm.Cells [0].StringValue   = Controller.GuessedUserName;
                        UserInfoForm.Cells [1].StringValue   = Controller.GuessedUserEmail;

                        // TODO: Ugly hack, do properly with events
                        timer = new Timer () {
                            Interval = 50
                        };

                        ContinueButton = new NSButton () {
                            Title    = "Continue",
                            Enabled  = false
                        };

                        ContinueButton.Activated += delegate {
                            timer.Stop ();
                            timer = null;

                            string full_name = UserInfoForm.Cells [0].StringValue.Trim ();
                            string email = UserInfoForm.Cells [1].StringValue.Trim ();

                            Controller.SetupPageCompleted (full_name, email);
                        };

                        timer.Elapsed += delegate {
                            InvokeOnMainThread (delegate {
                                bool name_is_valid = !UserInfoForm.Cells [0].StringValue.Trim ().Equals ("");

                                bool email_is_valid = Program.Controller.IsValidEmail (
                                    UserInfoForm.Cells [1].StringValue.Trim ());

                                ContinueButton.Enabled = (name_is_valid && email_is_valid);
                            });
                        };

                        timer.Start ();

                        ContentView.AddSubview (UserInfoForm);
                        Buttons.Add (ContinueButton);

                        break;
                    }

                    case PageType.Add: {

                        Header       = "Where is your project?";
                        Description  = "";

                        ServerTypeLabel  = new NSTextField () {
                            Alignment       = NSTextAlignment.Right,
                            BackgroundColor = NSColor.WindowBackground,
                            Bordered        = false,
                            Editable        = false,
                            Frame           = new RectangleF (150, Frame.Height - 159 , 160, 17),
                            StringValue     = "Host Type:",
                            Font            = SparkleUI.Font
                        };

                        AddressLabel = new NSTextField () {
                            Alignment       = NSTextAlignment.Right,
                            BackgroundColor = NSColor.WindowBackground,
                            Bordered        = false,
                            Editable        = false,
                            Frame           = new RectangleF (150, Frame.Height - 257 , 160, 17),
                            StringValue     = "Address:",
                            Font            = SparkleUI.Font
                        };

                        FolderNameLabel = new NSTextField () {
                            Alignment       = NSTextAlignment.Right,
                            BackgroundColor = NSColor.WindowBackground,
                            Bordered        = false,
                            Editable        = false,
                            Frame           = new RectangleF (150, Frame.Height - 284 , 160, 17),
                            StringValue     = "Folder Name:",
                            Font            = SparkleUI.Font
                        };

                        AddressTextField = new NSTextField () {
                            Frame       = new RectangleF (320, Frame.Height - 260 , 256, 22),
                            Font        = SparkleUI.Font,
                            StringValue = Controller.PreviousServer
                        };

                        AddressTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail;

                        FolderNameTextField = new NSTextField () {
                            Frame           = new RectangleF (320, Frame.Height - (260 + 22 + 4) , 256, 22),
                            StringValue     = Controller.PreviousFolder
                        };

                        FolderNameTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail;

                        FolderNameHelpLabel = new NSTextField () {
                            BackgroundColor = NSColor.WindowBackground,
                            Bordered        = false,
                            TextColor       = NSColor.DisabledControlText,
                            Editable        = false,
                            Frame           = new RectangleF (320, Frame.Height - 305 , 200, 17),
                            StringValue     = "e.g. ‘rupert/website-design’"
                        };

                        ServerType = 0;

                        ButtonCellProto = new NSButtonCell ();
                        ButtonCellProto.SetButtonType (NSButtonType.Radio) ;

                        Matrix = new NSMatrix (new RectangleF (315, Frame.Height - 220, 256, 78),
                            NSMatrixMode.Radio, ButtonCellProto, 4, 1);

                        Matrix.CellSize = new SizeF (256, 18);

                        Matrix.Cells [0].Title = "My own server";
                        Matrix.Cells [1].Title = "Github";
                        Matrix.Cells [2].Title = "Gitorious";
                        Matrix.Cells [3].Title = "The GNOME Project";

                        foreach (NSCell cell in Matrix.Cells)
                            cell.Font = SparkleUI.Font;

                        // TODO: Ugly hack, do properly with events
                        timer = new Timer () {
                            Interval = 50
                        };

                        timer.Elapsed += delegate {
                            InvokeOnMainThread (delegate {
                                if (Matrix.SelectedRow != ServerType) {
                                    ServerType = Matrix.SelectedRow;

                                    AddressTextField.Enabled = (ServerType == 0);

                                    switch (ServerType) {
                                    case 0:
                                        AddressTextField.StringValue = "";
                                        FolderNameHelpLabel.StringValue = "e.g. ‘rupert/website-design’";
                                        break;
                                    case 1:
                                        AddressTextField.StringValue = "ssh://[email protected]/";
                                        FolderNameHelpLabel.StringValue = "e.g. ‘rupert/website-design’";
                                        break;
                                    case 2:
                                        AddressTextField.StringValue = "ssh://[email protected]/";
                                        FolderNameHelpLabel.StringValue = "e.g. ‘project/website-design’";
                                        break;
                                    case 3:
                                        AddressTextField.StringValue = "ssh://[email protected]/git/";
                                        FolderNameHelpLabel.StringValue = "e.g. ‘gnome-icon-theme’";
                                        break;
                                    }
                                }

                                if (ServerType == 0 && !AddressTextField.StringValue.Trim ().Equals ("")
                                    && !FolderNameTextField.StringValue.Trim ().Equals ("")) {

                                    SyncButton.Enabled = true;

                                } else if (ServerType != 0 &&
                                           !FolderNameTextField.StringValue.Trim ().Equals ("")) {

                                    SyncButton.Enabled = true;

                                } else {
                                    SyncButton.Enabled = false;
                                }
                            });

                        };

                        timer.Start ();

                        ContentView.AddSubview (ServerTypeLabel);
                        ContentView.AddSubview (Matrix);

                        ContentView.AddSubview (AddressLabel);
                        ContentView.AddSubview (AddressTextField);

                        ContentView.AddSubview (FolderNameLabel);
                        ContentView.AddSubview (FolderNameTextField);
                        ContentView.AddSubview (FolderNameHelpLabel);

                        SyncButton = new NSButton () {
                            Title = "Add",
                            Enabled = false
                        };

                            SyncButton.Activated += delegate {
                                timer.Stop ();
                                timer = null;

                                string folder_name    = FolderNameTextField.StringValue;
                                string server         = AddressTextField.StringValue;
                                Controller.AddPageCompleted (server, folder_name);
                            };

                        Buttons.Add (SyncButton);

                            CancelButton = new NSButton () {
                                Title = "Cancel"
                            };

                            CancelButton.Activated += delegate {
                                InvokeOnMainThread (delegate {
                                    PerformClose (this);
                                });
                            };

                            Buttons.Add (CancelButton);

                        break;
                    }

                    case PageType.Syncing: {

                        Header      = "Adding project ‘" + Controller.SyncingFolder + "’…";
                        Description = "This may take a while.\n" +
                                      "Are you sure it’s not coffee o'clock?";

                        ProgressIndicator = new NSProgressIndicator () {
                            Frame    = new RectangleF (190, Frame.Height - 200, 640 - 150 - 80, 20),
                            Style    = NSProgressIndicatorStyle.Bar,
                            MinValue = 0.0,
                            MaxValue = 100.0,
                            Indeterminate = false,
                            DoubleValue = 1.0
                        };

                        ProgressIndicator.StartAnimation (this);

                        Controller.UpdateProgressBarEvent += delegate (double percentage) {
                            InvokeOnMainThread (delegate {
                                ProgressIndicator.DoubleValue = percentage;
                            });
                        };

                        ContentView.AddSubview (ProgressIndicator);

                        FinishButton = new NSButton () {
                            Title = "Finish",
                            Enabled = false
                        };

                        CancelButton = new NSButton () {
                            Title = "Cancel"
                        };

                        CancelButton.Activated += delegate {
                            Controller.SyncingCancelled ();
                        };

                        Buttons.Add (FinishButton);
                        Buttons.Add (CancelButton);

                        break;
                    }

                    case PageType.Error: {

                        Header      = "Something went wrong…";
                        Description = "";

                        TryAgainButton = new NSButton () {
                            Title = "Try again…"
                        };

                        TryAgainButton.Activated += delegate {
                            Controller.ErrorPageCompleted ();
                        };

                        Buttons.Add (TryAgainButton);

                        break;
                    }

                    case PageType.Finished: {

                        Header      = "Project succesfully added!";
                        Description = "Now you can access the files from " +
                                      "‘" + Controller.SyncingFolder + "’ in " +
                                      "your SparkleShare folder.";

                        FinishButton = new NSButton () {
                            Title = "Finish"
                        };

                        FinishButton.Activated += delegate {
                            InvokeOnMainThread (delegate {
                                Controller.FinishedPageCompleted ();
                                PerformClose (this);
                            });
                        };

                        OpenFolderButton = new NSButton () {
                            Title = "Open Folder"
                        };

                        OpenFolderButton.Activated += delegate {
                            Program.Controller.OpenSparkleShareFolder (Controller.SyncingFolder);
                        };

                        Buttons.Add (FinishButton);
                        Buttons.Add (OpenFolderButton);

                        NSApplication.SharedApplication.RequestUserAttention
                            (NSRequestUserAttentionType.CriticalRequest);

                        NSSound.FromName ("Glass").Play ();

                        break;
                    }

                    case PageType.Tutorial: {

                        switch (Controller.TutorialPageNumber) {
                        case 1: {
                            Header      = "What's happening next?";
                            Description = "SparkleShare creates a special folder in your personal folder " +
                                "that will keep track of your projects.";

                            SkipTutorialButton = new NSButton () {
                                Title = "Skip Tutorial"
                            };

                            SkipTutorialButton.Activated += delegate {
                                Controller.TutorialSkipped ();
                            };

                            ContinueButton = new NSButton () {
                                Title = "Continue"
                            };

                            ContinueButton.Activated += delegate {
                                Controller.TutorialPageCompleted ();
                            };

                            string slide_image_path = Path.Combine (NSBundle.MainBundle.ResourcePath,
                                "Pixmaps", "tutorial-slide-1.png");

                            SlideImage = new NSImage (slide_image_path) {
                                Size = new SizeF (350, 200)
                            };

                            SlideImageView = new NSImageView () {
                                Image = SlideImage,
                                Frame = new RectangleF (215, Frame.Height - 350, 350, 200)
                            };

                            ContentView.AddSubview (SlideImageView);
                            Buttons.Add (ContinueButton);
                            Buttons.Add (SkipTutorialButton);

                            break;
                        }

                        case 2: {
                            Header      = "Sharing files with others";
                            Description = "All files added to your project folders are synced with the host " +
                                "automatically, as well as with your collaborators.";

                            ContinueButton = new NSButton () {
                                Title = "Continue"
                            };

                            ContinueButton.Activated += delegate {
                                Controller.TutorialPageCompleted ();
                            };

                            string slide_image_path = Path.Combine (NSBundle.MainBundle.ResourcePath,
                                "Pixmaps", "tutorial-slide-2.png");

                            SlideImage = new NSImage (slide_image_path) {
                                Size = new SizeF (350, 200)
                            };

                            SlideImageView = new NSImageView () {
                                Image = SlideImage,
                                Frame = new RectangleF (215, Frame.Height - 350, 350, 200)
                            };

                            ContentView.AddSubview (SlideImageView);
                            Buttons.Add (ContinueButton);

                            break;
                        }

                        case 3: {
                            Header      = "The status icon is here to help";
                            Description = "It shows the syncing process status, " +
                                "and contains links to your projects and the event log.";

                            ContinueButton = new NSButton () {
                                Title = "Continue"
                            };

                            ContinueButton.Activated += delegate {
                                Controller.TutorialPageCompleted ();
                            };

                            string slide_image_path = Path.Combine (NSBundle.MainBundle.ResourcePath,
                                "Pixmaps", "tutorial-slide-3.png");

                            SlideImage = new NSImage (slide_image_path) {
                                Size = new SizeF (350, 200)
                            };

                            SlideImageView = new NSImageView () {
                                Image = SlideImage,
                                Frame = new RectangleF (215, Frame.Height - 350, 350, 200)
                            };

                            ContentView.AddSubview (SlideImageView);
                            Buttons.Add (ContinueButton);

                            break;
                        }

                        case 4: {
                            Header      = "Adding projects to SparkleShare";
                            Description = "Just click this button when you see it on the web, and " +
                                "the project will be automatically added:";

                            AddProjectTextField = new NSTextField () {
                                Frame           = new RectangleF (190, Frame.Height - 290, 640 - 240, 44),
                                BackgroundColor = NSColor.WindowBackground,
                                Bordered        = false,
                                Editable        = false,
                                Font            = SparkleUI.Font,
                                StringValue     = "…or select ‘Add Project…’ from the status icon menu " +
                                "to add one by hand."
                            };

                            AddProjectButton = new NSButton () {
                                Title = "Add Project…"
                            };

                            AddProjectButton.Activated += delegate {
                                Controller.TutorialPageCompleted ();
                            };

                            FinishButton = new NSButton () {
                                Title = "Finish"
                            };

                            FinishButton.Activated += delegate {
                                InvokeOnMainThread (delegate {
                                    PerformClose (this);
                                });
                            };

                            string slide_image_path = Path.Combine (NSBundle.MainBundle.ResourcePath,
                                "Pixmaps", "tutorial-slide-4.png");

                            SlideImage = new NSImage (slide_image_path) {
                                Size = new SizeF (350, 64)
                            };

                            SlideImageView = new NSImageView () {
                                Image = SlideImage,
                                Frame = new RectangleF (215, Frame.Height - 215, 350, 64)
                            };

                            ContentView.AddSubview (SlideImageView);
                            ContentView.AddSubview (AddProjectTextField);
                            Buttons.Add (FinishButton);
                            Buttons.Add (AddProjectButton);

                            break;
                        }
                        }

                        break;
                    }
                    }

                    ShowAll ();
                });
            };
        }