示例#1
0
 public IEnumerable <IdentitySourceItem> GetAllIdentities()
 {
     foreach (var unixUser in UnixUserInfo.GetLocalUsers())
     {
         yield return(new IdentitySourceItem()
         {
             DisplayName = unixUser.RealName, UserName = unixUser.UserName
         });
     }
 }
示例#2
0
        static uint GetUid(string user)
        {
            var  info = new UnixUserInfo(user);
            long uid  = info.UserId;

            if (uid > UInt32.MaxValue || uid <= 0)
            {
                throw new ArgumentOutOfRangeException("user", String.Format("Uid for {0} ({1}) not in range for suid", user, uid));
            }
            return((uint)uid);
        }
示例#3
0
        public UnixUserIdentifier(int uid)
        {
            UserId = (uint)uid;

            try
            {
                var user_info = new UnixUserInfo(uid);
                Username = user_info.UserName;
                GroupId  = (uint)user_info.GroupId;
                Group    = user_info.GroupName;
            }
            catch { }
        }
示例#4
0
        public UnixUserIdentifier(string username)
        {
            Username = username;

            try
            {
                var user_info = new UnixUserInfo(username);
                UserId  = (uint)user_info.UserId;
                GroupId = (uint)user_info.GroupId;
                Group   = user_info.GroupName;
            }
            catch { }
        }
示例#5
0
        public RootUserInfo()
        {
            var currentUser = UnixUserInfo.GetRealUser();

            Info       = currentUser;
            IsUserRoot = currentUser.UserId == 0;
            var rootGroup = new UnixGroupInfo(0);

            IsGroupRoot = rootGroup.GetMembers().Any(x => x.UserId == currentUser.UserId);
            var groups    = UnixGroupInfo.GetLocalGroups();
            var sudoGroup = groups.FirstOrDefault(x => x.GroupName == "sudo");

            IsSudo = sudoGroup != null && sudoGroup.GetMembers().Any(x => x.UserId == currentUser.UserId);
        }
示例#6
0
        public Conf()
        {
            // initialises variables
            // _homedir = Environment.GetEnvironmentVariable ("HOME") + "/.MonoGnomeArt/";
            // Recovers path of the personal repertory of the user
            long         CurrentUserID = UnixEnvironment.RealUserId;
            UnixUserInfo CurrentUser   = new UnixUserInfo(CurrentUserID);

            _homedir = CurrentUser.HomeDirectory + "/.MonoGnomeArt/";

            Console.WriteLine(_homedir);
            // create home dirs if they not exists
            create_home_dirs();
        }
示例#7
0
 public void ListAllUsers_ToString()
 {
     try {
         Console.WriteLine("Listing all users");
         foreach (UnixUserInfo user in UnixUserInfo.GetLocalUsers())
         {
             Console.WriteLine("\t{0}", user);
         }
     }
     catch (Exception e) {
         Assert.Fail(
             string.Format("#TLAU_TS: Exception listing local users: {0}",
                           e.ToString()));
     }
 }
示例#8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PamFtpUser"/> class.
        /// </summary>
        /// <param name="userInfo">The Unix PAM user information.</param>
        internal PamFtpUser([NotNull] UnixUserInfo userInfo)
        {
            var groups     = UnixGroupInfo.GetLocalGroups();
            var userGroups = groups
                             .Where(x => x.GetMemberNames().Any(memberName => memberName == userInfo.UserName))
                             .ToList();

            _userGroupNames = new HashSet <string>(
                userGroups.Select(x => x.GroupName),
                StringComparer.Ordinal);
            Name          = userInfo.UserName;
            HomeDirectory = userInfo.HomeDirectory;
            UserId        = userInfo.UserId;
            GroupId       = userInfo.GroupId;
        }
示例#9
0
        public UnixUserIdentifier(int uid, int gid)
        {
            UserId  = (uint)uid;
            GroupId = (uint)gid;

            try
            {
                var user_info = new UnixUserInfo(uid);
                Username = user_info.UserName;

                var group_info = new UnixGroupInfo(GroupId);
                Group = group_info.GroupName;
            }
            catch { }
        }
示例#10
0
        public UnixUserIdentifier(string username, string group)
        {
            Username = username;
            Group    = group;

            try
            {
                var user_info = new UnixUserInfo(username);
                UserId = (uint)user_info.UserId;

                var group_info = new UnixGroupInfo(group);
                GroupId = (uint)group_info.GroupId;
            }
            catch { }
        }
示例#11
0
        static void Main(string[] args)
        {
            try
            {
                restrictedUser  = new UnixUserInfo(username);
                restrictedGroup = new UnixGroupInfo(groupname);
            }
            catch (ArgumentException argException)
            {
                Console.WriteLine($"Cannot create security objects for the user/group.");
                Environment.Exit(1);
            }

            Recurse(targetPath);
            Environment.Exit(0);
        }
示例#12
0
        public bool Authorize(string Username, string Password)
        {
            CheckSystemType();
            var users = UnixUserInfo.GetLocalUsers();
            var user  = users.FirstOrDefault(a => a.UserName == Username && a.Password == Password);

            authenticated = (user == null);

            if (user == null)
            {
                return(false);
            }

            UserDir = user.HomeDirectory;

            return(authenticated);
        }
示例#13
0
        public void NonReentrantSyscalls()
        {
            ArrayList user_ids = new ArrayList(4);
            IList     users    = UnixUserInfo.GetLocalUsers();

            foreach (UnixUserInfo user in users)
            {
                try
                {
                    Passwd byName = Syscall.getpwnam(user.UserName);
                    Assert.IsNotNull(byName, "#TNRS: access by name");
                    UnixUserInfo n = new UnixUserInfo(byName);
                    Assert.AreEqual(user, n, "#TNRS: construct by name");

                    if (!user_ids.Contains(user.UserId))
                    {
                        user_ids.Add(user.UserId);
                    }
                }
                catch (Exception e)
                {
                    Assert.Fail(
                        string.Format("#TNRS: Exception constructing UnixUserInfo (string): {0}",
                                      e.ToString()));
                }
            }

            foreach (long uid in user_ids)
            {
                try
                {
                    Passwd byId = Syscall.getpwuid(Convert.ToUInt32(uid));
                    Assert.IsNotNull(byId, "#TNRS: access by uid");

                    UnixUserInfo u = new UnixUserInfo(byId);
                    Assert.IsTrue(users.Contains(u), "TNRS: construct by uid");
                }
                catch (Exception e)
                {
                    Assert.Fail(
                        string.Format("#TNRS: Exception constructing UnixUserInfo (uint): {0}",
                                      e.ToString()));
                }
            }
        }
示例#14
0
        public static bool HasPermission(UnixFileSystemInfo fi, FileAccessPermissions fap)
        {
            var effective = fi.FileAccessPermissions & fap;
            var user      = UnixUserInfo.GetRealUser();

            if (user.UserId == fi.OwnerUserId)
            {
                return((effective & FileAccessPermissions.UserReadWriteExecute) == (fap & FileAccessPermissions.UserReadWriteExecute));
            }
            else if (user.GroupId == fi.OwnerGroupId)
            {
                return((effective & FileAccessPermissions.GroupReadWriteExecute) == (fap & FileAccessPermissions.GroupReadWriteExecute));
            }
            else
            {
                return((effective & FileAccessPermissions.OtherReadWriteExecute) == (fap & FileAccessPermissions.OtherReadWriteExecute));
            }
        }
        /// <inheritdoc />
        public Task <MemberValidationResult> ValidateUserAsync(
            string username,
            string password,
            CancellationToken cancellationToken)
        {
            MemberValidationResult result;
            var credentials    = new NetworkCredential(username, password);
            var messageHandler = new CredentialMessageHandler(credentials);

            try
            {
                UnixUserInfo userInfo;

                var pamTransaction = _pamService.Start(messageHandler);
                try
                {
                    pamTransaction.Authenticate();

                    if (!_options.IgnoreAccountManagement)
                    {
                        pamTransaction.AccountManagement();
                    }

                    userInfo = new UnixUserInfo(pamTransaction.UserName);
                }
                catch
                {
                    pamTransaction.Dispose();
                    throw;
                }

                _connectionAccessor.FtpConnection.Features.Set(new PamSessionFeature(pamTransaction));

                result = new MemberValidationResult(
                    MemberValidationStatus.AuthenticatedUser,
                    CreateUnixPrincipal(userInfo));
            }
            catch (PamException)
            {
                result = new MemberValidationResult(MemberValidationStatus.InvalidLogin);
            }

            return(Task.FromResult(result));
        }
示例#16
0
        protected override void OnStart(string [] args)
        {
            var shell = UnixUserInfo.GetRealUser().ShellProgram;

            loop.Interval  = 2000;
            loop.AutoReset = true;
            loop.Elapsed  += (x, y) => Tick();

            lock (consoleLock)
            {
                Console.WriteLine("version: 4");
                Console.WriteLine($"shell: {shell}");
            }

            Tick();
            loop.Start();

            ThreadPool.QueueUserWorkItem(this.HandleInput);
        }
示例#17
0
        public void ReentrantConstructors()
        {
            ArrayList user_ids = new ArrayList(4);
            IList     users    = UnixUserInfo.GetLocalUsers();

            foreach (UnixUserInfo user in users)
            {
                try
                {
                    UnixUserInfo byName = new UnixUserInfo(user.UserName);
                    Assert.AreEqual(user, byName, "#TRC: construct by name");

                    if (!user_ids.Contains(user.UserId))
                    {
                        user_ids.Add(user.UserId);
                    }
                }
                catch (Exception e)
                {
                    Assert.Fail(
                        string.Format("#TRC: Exception constructing UnixUserInfo (string): {0}",
                                      e.ToString()));
                }
            }

            foreach (uint uid in user_ids)
            {
                try
                {
                    UnixUserInfo byId = new UnixUserInfo(uid);
                    Assert.IsTrue(users.Contains(byId), "TRC: construct by uid");
                }
                catch (Exception e)
                {
                    Assert.Fail(
                        string.Format("#TRC: Exception constructing UnixUserInfo (uint): {0}",
                                      e.ToString()));
                }
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="GedcomSourceRecord"/> class.
        /// </summary>
        /// <param name="database">The database to associate with this record.</param>
        public GedcomSourceRecord(GedcomDatabase database)
            : this()
        {
            Database = database;
            Level    = 0;

            Title = "New Source";

            // default to filer being current user
#if __MonoCS__
            // bug in mono code, doesn't correctly get the real name, need to strip off , chars
            FiledBy = UnixUserInfo.GetRealUser().RealName.Trim(new char[] { ',' });
#endif

            if (string.IsNullOrEmpty(FiledBy))
            {
                FiledBy = Environment.UserName;
            }

            XRefID = database.GenerateXref("SOURCE");
            database.Add(XRefID, this);
        }
示例#19
0
        public void ShowPage(PageType type, string [] warnings)
        {
            if (type == PageType.Setup)
            {
                Header      = "Welcome to SparkleShare!";
                Description = "First off, what’s your name and email?\n(visible only to team members)";

                Table table = new Table(2, 3, true)
                {
                    RowSpacing    = 6,
                    ColumnSpacing = 6
                };

                Label name_label = new Label("<b>" + "Full Name:" + "</b>")
                {
                    UseMarkup = true,
                    Xalign    = 1
                };

                Entry name_entry = new Entry()
                {
                    Xalign           = 0,
                    ActivatesDefault = true
                };

                try {
                    UnixUserInfo user_info = UnixUserInfo.GetRealUser();

                    if (user_info != null && user_info.RealName != null)
                    {
                        // Some systems append a series of "," for some reason
                        name_entry.Text = user_info.RealName.TrimEnd(",".ToCharArray());
                    }
                } catch (ArgumentException) {
                    // No username, not a big deal
                }

                Entry email_entry = new Entry()
                {
                    Xalign           = 0,
                    ActivatesDefault = true
                };

                Label email_label = new Label("<b>" + "Email:" + "</b>")
                {
                    UseMarkup = true,
                    Xalign    = 1
                };

                table.Attach(name_label, 0, 1, 0, 1);
                table.Attach(name_entry, 1, 2, 0, 1);
                table.Attach(email_label, 0, 1, 1, 2);
                table.Attach(email_entry, 1, 2, 1, 2);

                VBox wrapper = new VBox(false, 9);
                wrapper.PackStart(table, true, false, 0);

                Button cancel_button   = new Button("Cancel");
                Button continue_button = new Button("Continue")
                {
                    Sensitive = false
                };


                Controller.UpdateSetupContinueButtonEvent += delegate(bool button_enabled) {
                    Application.Invoke(delegate { continue_button.Sensitive = button_enabled; });
                };

                name_entry.Changed    += delegate { Controller.CheckSetupPage(name_entry.Text, email_entry.Text); };
                email_entry.Changed   += delegate { Controller.CheckSetupPage(name_entry.Text, email_entry.Text); };
                cancel_button.Clicked += delegate { Controller.SetupPageCancelled(); };

                continue_button.Clicked += delegate {
                    Controller.SetupPageCompleted(name_entry.Text, email_entry.Text);
                };


                AddButton(cancel_button);
                AddButton(continue_button);
                Add(wrapper);

                Controller.CheckSetupPage(name_entry.Text, email_entry.Text);

                if (name_entry.Text.Equals(""))
                {
                    name_entry.GrabFocus();
                }
                else
                {
                    email_entry.GrabFocus();
                }
            }

            if (type == PageType.Add)
            {
                Header = "Where’s your project hosted?";

                VBox layout_vertical = new VBox(false, 16);
                HBox layout_fields   = new HBox(true, 32);
                VBox layout_address  = new VBox(true, 0);
                VBox layout_path     = new VBox(true, 0);

                ListStore store = new ListStore(typeof(string), typeof(Gdk.Pixbuf), typeof(string), typeof(SparklePlugin));

                SparkleTreeView tree_view = new SparkleTreeView(store)
                {
                    HeadersVisible = false
                };
                ScrolledWindow scrolled_window = new ScrolledWindow()
                {
                    ShadowType = ShadowType.In
                };
                scrolled_window.SetPolicy(PolicyType.Never, PolicyType.Automatic);

                // Padding column
                tree_view.AppendColumn("Padding", new Gtk.CellRendererText(), "text", 0);
                tree_view.Columns [0].Cells [0].Xpad = 4;

                // Icon column
                tree_view.AppendColumn("Icon", new Gtk.CellRendererPixbuf(), "pixbuf", 1);
                tree_view.Columns [1].Cells [0].Xpad = 4;

                // Service column
                TreeViewColumn service_column = new TreeViewColumn()
                {
                    Title = "Service"
                };
                CellRendererText service_cell = new CellRendererText()
                {
                    Ypad = 8
                };
                service_column.PackStart(service_cell, true);
                service_column.SetCellDataFunc(service_cell, new TreeCellDataFunc(RenderServiceColumn));

                foreach (SparklePlugin plugin in Controller.Plugins)
                {
                    store.AppendValues("", new Gdk.Pixbuf(plugin.ImagePath),
                                       "<span size=\"small\"><b>" + plugin.Name + "</b>\n" +
                                       "<span fgcolor=\"" + Program.UI.SecondaryTextColor + "\">" + plugin.Description + "</span>" +
                                       "</span>", plugin);
                }

                tree_view.AppendColumn(service_column);
                scrolled_window.Add(tree_view);

                Entry address_entry = new Entry()
                {
                    Text             = Controller.PreviousAddress,
                    Sensitive        = (Controller.SelectedPlugin.Address == null),
                    ActivatesDefault = true
                };

                Entry path_entry = new Entry()
                {
                    Text             = Controller.PreviousPath,
                    Sensitive        = (Controller.SelectedPlugin.Path == null),
                    ActivatesDefault = true
                };

                Label address_example = new Label()
                {
                    Xalign    = 0,
                    UseMarkup = true,
                    Markup    = "<span size=\"small\" fgcolor=\"" +
                                Program.UI.SecondaryTextColor + "\">" + Controller.SelectedPlugin.AddressExample + "</span>"
                };

                Label path_example = new Label()
                {
                    Xalign    = 0,
                    UseMarkup = true,
                    Markup    = "<span size=\"small\" fgcolor=\"" +
                                Program.UI.SecondaryTextColor + "\">" + Controller.SelectedPlugin.PathExample + "</span>"
                };


                TreeSelection default_selection = tree_view.Selection;
                TreePath      default_path      = new TreePath("" + Controller.SelectedPluginIndex);
                default_selection.SelectPath(default_path);

                tree_view.Model.Foreach(new TreeModelForeachFunc(
                                            delegate(ITreeModel model, TreePath path, TreeIter iter) {
                    string address;

                    try {
                        address = (model.GetValue(iter, 2) as SparklePlugin).Address;
                    } catch (NullReferenceException) {
                        address = "";
                    }

                    if (!string.IsNullOrEmpty(address) &&
                        address.Equals(Controller.PreviousAddress))
                    {
                        tree_view.SetCursor(path, service_column, false);
                        SparklePlugin plugin = (SparklePlugin)model.GetValue(iter, 2);

                        if (plugin.Address != null)
                        {
                            address_entry.Sensitive = false;
                        }

                        if (plugin.Path != null)
                        {
                            path_entry.Sensitive = false;
                        }

                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                                            ));

                layout_address.PackStart(new Label()
                {
                    Markup = "<b>" + "Address" + "</b>",
                    Xalign = 0
                }, true, true, 0);

                layout_address.PackStart(address_entry, false, false, 0);
                layout_address.PackStart(address_example, false, false, 0);

                path_entry.Changed += delegate {
                    Controller.CheckAddPage(address_entry.Text, path_entry.Text, tree_view.SelectedRow);
                };

                layout_path.PackStart(new Label()
                {
                    Markup = "<b>" + "Remote Path" + "</b>",
                    Xalign = 0
                }, true, true, 0);

                layout_path.PackStart(path_entry, false, false, 0);
                layout_path.PackStart(path_example, false, false, 0);

                layout_fields.PackStart(layout_address, true, true, 0);
                layout_fields.PackStart(layout_path, true, true, 0);

                layout_vertical.PackStart(new Label(""), false, false, 0);
                layout_vertical.PackStart(scrolled_window, true, true, 0);
                layout_vertical.PackStart(layout_fields, false, false, 0);

                tree_view.ScrollToCell(new TreePath("" + Controller.SelectedPluginIndex), null, true, 0, 0);

                Add(layout_vertical);


                if (string.IsNullOrEmpty(path_entry.Text))
                {
                    address_entry.GrabFocus();
                    address_entry.Position = -1;
                }
                else
                {
                    path_entry.GrabFocus();
                    path_entry.Position = -1;
                }

                Button cancel_button = new Button("Cancel");
                Button add_button    = new Button("Add")
                {
                    Sensitive = false
                };


                Controller.ChangeAddressFieldEvent += delegate(string text,
                                                               string example_text, FieldState state) {
                    Application.Invoke(delegate {
                        address_entry.Text      = text;
                        address_entry.Sensitive = (state == FieldState.Enabled);
                        address_example.Markup  = "<span size=\"small\" fgcolor=\"" +
                                                  Program.UI.SecondaryTextColor + "\">" + example_text + "</span>";
                    });
                };

                Controller.ChangePathFieldEvent += delegate(string text,
                                                            string example_text, FieldState state) {
                    Application.Invoke(delegate {
                        path_entry.Text      = text;
                        path_entry.Sensitive = (state == FieldState.Enabled);
                        path_example.Markup  = "<span size=\"small\" fgcolor=\""
                                               + Program.UI.SecondaryTextColor + "\">" + example_text + "</span>";
                    });
                };

                Controller.UpdateAddProjectButtonEvent += delegate(bool button_enabled) {
                    Application.Invoke(delegate { add_button.Sensitive = button_enabled; });
                };


                tree_view.CursorChanged += delegate(object sender, EventArgs e) {
                    Controller.SelectedPluginChanged(tree_view.SelectedRow);
                };

                address_entry.Changed += delegate {
                    Controller.CheckAddPage(address_entry.Text, path_entry.Text, tree_view.SelectedRow);
                };

                cancel_button.Clicked += delegate { Controller.PageCancelled(); };
                add_button.Clicked    += delegate { Controller.AddPageCompleted(address_entry.Text, path_entry.Text); };


                CheckButton check_button = new CheckButton("Fetch prior revisions")
                {
                    Active = true
                };
                check_button.Toggled += delegate { Controller.HistoryItemChanged(check_button.Active); };

                AddOption(check_button);
                AddButton(cancel_button);
                AddButton(add_button);

                Controller.HistoryItemChanged(check_button.Active);
                Controller.CheckAddPage(address_entry.Text, path_entry.Text, 1);
            }

            if (type == PageType.Invite)
            {
                Header      = "You’ve received an invite!";
                Description = "Do you want to add this project to SparkleShare?";

                Table table = new Table(2, 3, true)
                {
                    RowSpacing    = 6,
                    ColumnSpacing = 6
                };

                Label address_label = new Label("Address:")
                {
                    Xalign = 1
                };
                Label path_label = new Label("Remote Path:")
                {
                    Xalign = 1
                };

                Label address_value = new Label("<b>" + Controller.PendingInvite.Address + "</b>")
                {
                    UseMarkup = true,
                    Xalign    = 0
                };

                Label path_value = new Label("<b>" + Controller.PendingInvite.RemotePath + "</b>")
                {
                    UseMarkup = true,
                    Xalign    = 0
                };

                table.Attach(address_label, 0, 1, 0, 1);
                table.Attach(address_value, 1, 2, 0, 1);
                table.Attach(path_label, 0, 1, 1, 2);
                table.Attach(path_value, 1, 2, 1, 2);

                VBox wrapper = new VBox(false, 9);
                wrapper.PackStart(table, true, false, 0);

                Button cancel_button = new Button("Cancel");
                Button add_button    = new Button("Add");


                cancel_button.Clicked += delegate { Controller.PageCancelled(); };
                add_button.Clicked    += delegate { Controller.InvitePageCompleted(); };


                AddButton(cancel_button);
                AddButton(add_button);
                Add(wrapper);
            }

            if (type == PageType.Syncing)
            {
                Header      = String.Format("Adding project ‘{0}’…", Controller.SyncingFolder);
                Description = "This may take a while for large projects.\nIsn’t it coffee-o’clock?";

                ProgressBar progress_bar = new ProgressBar();
                progress_bar.Fraction = Controller.ProgressBarPercentage / 100;

                Button cancel_button = new Button()
                {
                    Label = "Cancel"
                };
                Button finish_button = new Button("Finish")
                {
                    Sensitive = false
                };

                Label progress_label = new Label("Preparing to fetch files…")
                {
                    Justify = Justification.Right,
                    Xalign  = 1
                };


                Controller.UpdateProgressBarEvent += delegate(double percentage, string speed) {
                    Application.Invoke(delegate {
                        progress_bar.Fraction = percentage / 100;
                        progress_label.Text   = speed;
                    });
                };

                cancel_button.Clicked += delegate { Controller.SyncingCancelled(); };


                VBox bar_wrapper = new VBox(false, 0);
                bar_wrapper.PackStart(progress_bar, false, false, 21);
                bar_wrapper.PackStart(progress_label, false, true, 0);

                Add(bar_wrapper);
                AddButton(cancel_button);
                AddButton(finish_button);
            }

            if (type == PageType.Error)
            {
                Header = "Oops! Something went wrong" + "…";

                VBox  points           = new VBox(false, 0);
                Image list_point_one   = new Image(SparkleUIHelpers.GetIcon("list-point", 16));
                Image list_point_two   = new Image(SparkleUIHelpers.GetIcon("list-point", 16));
                Image list_point_three = new Image(SparkleUIHelpers.GetIcon("list-point", 16));

                Label label_one = new Label()
                {
                    Markup = "<b>" + Controller.PreviousUrl + "</b> is the address we’ve compiled. " +
                             "Does this look alright?",
                    Wrap   = true,
                    Xalign = 0
                };

                Label label_two = new Label()
                {
                    Text   = "Is this computer’s Client ID known by the host?",
                    Wrap   = true,
                    Xalign = 0
                };

                points.PackStart(new Label("Please check the following:")
                {
                    Xalign = 0
                }, false, false, 6);

                HBox point_one = new HBox(false, 0);
                point_one.PackStart(list_point_one, false, false, 0);
                point_one.PackStart(label_one, true, true, 12);
                points.PackStart(point_one, false, false, 12);

                HBox point_two = new HBox(false, 0);
                point_two.PackStart(list_point_two, false, false, 0);
                point_two.PackStart(label_two, true, true, 12);
                points.PackStart(point_two, false, false, 12);

                if (warnings.Length > 0)
                {
                    string warnings_markup = "";

                    foreach (string warning in warnings)
                    {
                        warnings_markup += "\n<b>" + warning + "</b>";
                    }

                    Label label_three = new Label()
                    {
                        Markup = "Here’s the raw error message:" + warnings_markup,
                        Wrap   = true,
                        Xalign = 0
                    };

                    HBox point_three = new HBox(false, 0);
                    point_three.PackStart(list_point_three, false, false, 0);
                    point_three.PackStart(label_three, true, true, 12);
                    points.PackStart(point_three, false, false, 12);
                }

                points.PackStart(new Label(""), true, true, 0);

                Button cancel_button    = new Button("Cancel");
                Button try_again_button = new Button("Try Again…")
                {
                    Sensitive = true
                };


                cancel_button.Clicked    += delegate { Controller.PageCancelled(); };
                try_again_button.Clicked += delegate { Controller.ErrorPageCompleted(); };


                AddButton(cancel_button);
                AddButton(try_again_button);
                Add(points);
            }

            if (type == PageType.CryptoSetup || type == PageType.CryptoPassword)
            {
                if (type == PageType.CryptoSetup)
                {
                    Header      = "Set up file encryption";
                    Description = "Please a provide a strong password that you don’t use elsewhere.";
                }
                else
                {
                    Header      = "This project contains encrypted files";
                    Description = "Please enter the password to see their contents.";
                }

                Label password_label = new Label("<b>" + "Password" + "</b>")
                {
                    UseMarkup = true,
                    Xalign    = 1
                };

                Entry password_entry = new Entry()
                {
                    Xalign           = 0,
                    Visibility       = false,
                    ActivatesDefault = true
                };

                CheckButton show_password_check_button = new CheckButton("Show password")
                {
                    Active = false,
                    Xalign = 0,
                };

                Table table = new Table(2, 3, true)
                {
                    RowSpacing    = 6,
                    ColumnSpacing = 6
                };

                table.Attach(password_label, 0, 1, 0, 1);
                table.Attach(password_entry, 1, 2, 0, 1);

                table.Attach(show_password_check_button, 1, 2, 1, 2);

                VBox wrapper = new VBox(false, 9);
                wrapper.PackStart(table, true, false, 0);

                Image warning_image = new Image(
                    SparkleUIHelpers.GetIcon("dialog-information", 24));

                Label warning_label = new Label()
                {
                    Xalign = 0,
                    Wrap   = true,
                    Text   = "This password can’t be changed later, and your files can’t be recovered if it’s forgotten."
                };

                HBox warning_layout = new HBox(false, 0);
                warning_layout.PackStart(warning_image, false, false, 15);
                warning_layout.PackStart(warning_label, true, true, 0);

                VBox warning_wrapper = new VBox(false, 0);
                warning_wrapper.PackStart(warning_layout, false, false, 15);

                if (type == PageType.CryptoSetup)
                {
                    wrapper.PackStart(warning_wrapper, false, false, 0);
                }

                Button cancel_button   = new Button("Cancel");
                Button continue_button = new Button("Continue")
                {
                    Sensitive = false
                };


                Controller.UpdateCryptoSetupContinueButtonEvent += delegate(bool button_enabled) {
                    Application.Invoke(delegate { continue_button.Sensitive = button_enabled; });
                };

                Controller.UpdateCryptoPasswordContinueButtonEvent += delegate(bool button_enabled) {
                    Application.Invoke(delegate { continue_button.Sensitive = button_enabled; });
                };

                show_password_check_button.Toggled += delegate {
                    password_entry.Visibility = !password_entry.Visibility;
                };

                password_entry.Changed += delegate {
                    if (type == PageType.CryptoSetup)
                    {
                        Controller.CheckCryptoSetupPage(password_entry.Text);
                    }
                    else
                    {
                        Controller.CheckCryptoPasswordPage(password_entry.Text);
                    }
                };

                cancel_button.Clicked += delegate { Controller.CryptoPageCancelled(); };

                continue_button.Clicked += delegate {
                    if (type == PageType.CryptoSetup)
                    {
                        Controller.CryptoSetupPageCompleted(password_entry.Text);
                    }
                    else
                    {
                        Controller.CryptoPasswordPageCompleted(password_entry.Text);
                    }
                };


                Add(wrapper);

                AddButton(cancel_button);
                AddButton(continue_button);

                password_entry.GrabFocus();
            }

            if (type == PageType.Finished)
            {
                Header      = "Your shared project is ready!";
                Description = "You can find the files in your SparkleShare folder.";

                UrgencyHint = true;

                Button show_files_button = new Button("Show Files…");
                Button finish_button     = new Button("Finish");


                show_files_button.Clicked += delegate { Controller.ShowFilesClicked(); };
                finish_button.Clicked     += delegate { Controller.FinishPageCompleted(); };


                if (warnings.Length > 0)
                {
                    Image warning_image = new Image(SparkleUIHelpers.GetIcon("dialog-information", 24));

                    Label warning_label = new Label(warnings [0])
                    {
                        Xalign = 0,
                        Wrap   = true
                    };

                    HBox warning_layout = new HBox(false, 0);
                    warning_layout.PackStart(warning_image, false, false, 15);
                    warning_layout.PackStart(warning_label, true, true, 0);

                    VBox warning_wrapper = new VBox(false, 0);
                    warning_wrapper.PackStart(warning_layout, false, false, 0);

                    Add(warning_wrapper);
                }
                else
                {
                    Add(null);
                }

                AddButton(show_files_button);
                AddButton(finish_button);
            }

            if (type == PageType.Tutorial)
            {
                switch (Controller.TutorialPageNumber)
                {
                case 1: {
                    Header      = "What’s happening next?";
                    Description = "SparkleShare creates a special folder on your computer " +
                                  "that will keep track of your projects.";

                    Button skip_tutorial_button = new Button("Skip Tutorial");
                    Button continue_button      = new Button("Continue");

                    skip_tutorial_button.Clicked += delegate { Controller.TutorialSkipped(); };
                    continue_button.Clicked      += delegate { Controller.TutorialPageCompleted(); };

                    AddButton(skip_tutorial_button);
                    AddButton(continue_button);

                    break;
                }

                case 2: {
                    Header      = "Sharing files with others";
                    Description = "All files added to your project folders are synced automatically with " +
                                  "the host and your team members.";

                    Button continue_button = new Button("Continue");
                    continue_button.Clicked += delegate { Controller.TutorialPageCompleted(); };
                    AddButton(continue_button);

                    break;
                }

                case 3: {
                    Header      = "The status icon helps you";
                    Description = "It shows the syncing progress, provides easy access to " +
                                  "your projects, and lets you view recent changes.";

                    Button continue_button = new Button("Continue");
                    continue_button.Clicked += delegate { Controller.TutorialPageCompleted(); };
                    AddButton(continue_button);

                    break;
                }

                case 4: {
                    Header      = "Here’s your unique Client ID";
                    Description = "You’ll need it whenever you want to link this computer to a host. " +
                                  "You can also find it in the status icon menu.";

                    Button finish_button   = new Button("Finish");
                    VBox   layout_vertical = new VBox(false, 0)
                    {
                        BorderWidth = 48
                    };
                    HBox layout_horizontal = new HBox(false, 6);

                    Entry link_code_entry = new Entry()
                    {
                        Text      = Program.Controller.CurrentUser.PublicKey,
                        Sensitive = false
                    };

                    Button copy_button = new Button(" Copy ");

                    CheckButton check_button = new CheckButton("Add SparkleShare to startup items");
                    check_button.Active = true;


                    copy_button.Clicked   += delegate { Controller.CopyToClipboardClicked(); };
                    check_button.Toggled  += delegate { Controller.StartupItemChanged(check_button.Active); };
                    finish_button.Clicked += delegate { Controller.TutorialPageCompleted(); };


                    layout_horizontal.PackStart(link_code_entry, true, true, 0);
                    layout_horizontal.PackStart(copy_button, false, false, 0);

                    layout_vertical.PackStart(new Label(""), true, true, 0);
                    layout_vertical.PackStart(layout_horizontal, false, false, 0);
                    layout_vertical.PackStart(new Label(""), true, true, 18);

                    Add(layout_vertical);

                    AddOption(check_button);
                    AddButton(finish_button);

                    break;
                }
                }

                if (Controller.TutorialPageNumber < 4)
                {
                    Image slide = SparkleUIHelpers.GetImage("tutorial-slide-" + Controller.TutorialPageNumber + ".png");
                    Add(slide);
                }
            }
        }
示例#20
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();
        }
示例#21
0
        /*
         * Loads the specific agent assembly into this vm.
         */
        public void Attach(string agent, string args)
        {
            string user = UnixUserInfo.GetRealUser().UserName;

            // Check whenever the attach socket exists
            string socket_file = "/tmp/mono-" + user + "/.mono-" + pid;

            if (!File.Exists(socket_file))
            {
                string     trigger_file = "/tmp/.mono_attach_pid" + pid;
                FileStream trigger      = null;

                try {
                    trigger = File.Create(trigger_file);
                    trigger.Close();

                    // Ask the vm to start the attach mechanism
                    Syscall.kill((int)pid, Signum.SIGQUIT);

                    // Wait for the socket file to materialize
                    int i;
                    for (i = 0; i < 10; ++i)
                    {
                        if (File.Exists(socket_file))
                        {
                            break;
                        }
                        Thread.Sleep(100);
                    }

                    if (i == 10)
                    {
                        throw new Exception(String.Format("Runtime failed to create attach socket '{0}'.", socket_file));
                    }
                } finally {
                    File.Delete(trigger_file);
                }
            }

            /*
             * We communicate with the agent inside the runtime using a simlified
             * version of the .net remoting protocol.
             */

            string path = "/tmp/mono-" + user + "/.mono-" + pid;

            UnixClient client = new UnixClient(path);

            NetworkStream stream = client.GetStream();

            // Compose payload
            MemoryStream ms     = new MemoryStream();
            BinaryWriter writer = new BinaryWriter(ms);

            write_string(writer, "attach");
            write_string(writer, agent);
            write_string(writer, args);

            // Write header
            byte[] magic = new byte [] { (byte)'M', (byte)'O', (byte)'N', (byte)'O', 1, 0 };
            stream.Write(magic, 0, magic.Length);

            // Write payload length
            new BinaryWriter(stream).Write((int)ms.Length);

            // Write payload
            stream.Write(ms.GetBuffer(), 0, (int)ms.Length);
        }
示例#22
0
        public void ShowPage(PageType type, string [] warnings)
        {
            if (type == PageType.Setup)
            {
                Header      = "Welcome to SparkleShare!";
                Description = "First off, what’s your name and email?\n(visible only to team members)";

                Table table = new Table(2, 3, true)
                {
                    RowSpacing    = 6,
                    ColumnSpacing = 6
                };

                Label name_label = new Label("<b>" + "Your Name:" + "</b>")
                {
                    UseMarkup = true,
                    Xalign    = 1
                };

                Entry name_entry = new Entry()
                {
                    Xalign           = 0,
                    ActivatesDefault = true
                };

                try {
                    UnixUserInfo user_info = UnixUserInfo.GetRealUser();

                    if (user_info != null && user_info.RealName != null)
                    {
                        // Some systems append a series of "," for some reason, TODO: Report upstream
                        name_entry.Text = user_info.RealName.TrimEnd(",".ToCharArray());
                    }
                } catch (ArgumentException) {
                    // No username, not a big deal
                }

                Entry email_entry = new Entry()
                {
                    Xalign           = 0,
                    ActivatesDefault = true
                };

                Label email_label = new Label("<b>" + "Email:" + "</b>")
                {
                    UseMarkup = true,
                    Xalign    = 1
                };

                table.Attach(name_label, 0, 1, 0, 1);
                table.Attach(name_entry, 1, 2, 0, 1);
                table.Attach(email_label, 0, 1, 1, 2);
                table.Attach(email_entry, 1, 2, 1, 2);

                VBox wrapper = new VBox(false, 9);
                wrapper.PackStart(table, true, false, 0);

                Button cancel_button   = new Button("Cancel");
                Button continue_button = new Button("Continue")
                {
                    Sensitive = false
                };


                Controller.UpdateSetupContinueButtonEvent += delegate(bool button_enabled) {
                    Application.Invoke(delegate { continue_button.Sensitive = button_enabled; });
                };

                name_entry.Changed    += delegate { Controller.CheckSetupPage(name_entry.Text, email_entry.Text); };
                email_entry.Changed   += delegate { Controller.CheckSetupPage(name_entry.Text, email_entry.Text); };
                cancel_button.Clicked += delegate { Controller.SetupPageCancelled(); };

                continue_button.Clicked += delegate {
                    Controller.SetupPageCompleted(name_entry.Text, email_entry.Text);
                };


                AddButton(cancel_button);
                AddButton(continue_button);
                Add(wrapper);

                Controller.CheckSetupPage(name_entry.Text, email_entry.Text);

                if (name_entry.Text.Equals(""))
                {
                    name_entry.GrabFocus();
                }
                else
                {
                    email_entry.GrabFocus();
                }
            }

            if (type == PageType.Add)
            {
                Header = "Where’s your project hosted?";

                VBox layout_vertical = new VBox(false, 16);
                HBox layout_fields   = new HBox(true, 32);
                VBox layout_address  = new VBox(true, 0);
                VBox layout_path     = new VBox(true, 0);

                ListStore store = new ListStore(typeof(string), typeof(Gdk.Pixbuf), typeof(string), typeof(Preset));

                SparkleTreeView tree_view = new SparkleTreeView(store)
                {
                    HeadersVisible = false,
                    SearchColumn   = -1,
                    EnableSearch   = false
                };

                ScrolledWindow scrolled_window = new ScrolledWindow()
                {
                    ShadowType = ShadowType.In
                };
                scrolled_window.SetPolicy(PolicyType.Never, PolicyType.Automatic);

                // Padding column
                tree_view.AppendColumn("Padding", new Gtk.CellRendererText(), "text", 0);
                tree_view.Columns [0].Cells [0].Xpad = 4;

                // Icon column
                tree_view.AppendColumn("Icon", new Gtk.CellRendererPixbuf(), "pixbuf", 1);
                tree_view.Columns [1].Cells [0].Xpad = 4;

                // Service column
                TreeViewColumn service_column = new TreeViewColumn()
                {
                    Title = "Service"
                };
                CellRendererText service_cell = new CellRendererText()
                {
                    Ypad = 8
                };
                service_column.PackStart(service_cell, true);
                service_column.SetCellDataFunc(service_cell, new TreeCellDataFunc(RenderServiceColumn));

                foreach (Preset preset in Controller.Presets)
                {
                    store.AppendValues("", new Gdk.Pixbuf(preset.ImagePath),
                                       "<span size=\"small\"><b>" + preset.Name + "</b>\n" +
                                       "<span fgcolor=\"" + SparkleShare.UI.SecondaryTextColor + "\">" + preset.Description + "</span>" +
                                       "</span>", preset);
                }

                tree_view.AppendColumn(service_column);
                scrolled_window.Add(tree_view);

                Entry address_entry = new Entry()
                {
                    Text             = Controller.PreviousAddress,
                    Sensitive        = (Controller.SelectedPreset.Address == null),
                    ActivatesDefault = true
                };

                Entry path_entry = new Entry()
                {
                    Text             = Controller.PreviousPath,
                    Sensitive        = (Controller.SelectedPreset.Path == null),
                    ActivatesDefault = true
                };

                tree_view.ButtonReleaseEvent += delegate {
                    path_entry.GrabFocus();
                };

                Label address_example = new Label()
                {
                    Xalign    = 0,
                    UseMarkup = true,
                    Markup    = "<span size=\"small\" fgcolor=\"" +
                                SparkleShare.UI.SecondaryTextColor + "\">" + Controller.SelectedPreset.AddressExample + "</span>"
                };

                Label path_example = new Label()
                {
                    Xalign    = 0,
                    UseMarkup = true,
                    Markup    = "<span size=\"small\" fgcolor=\"" +
                                SparkleShare.UI.SecondaryTextColor + "\">" + Controller.SelectedPreset.PathExample + "</span>"
                };


                TreeSelection default_selection = tree_view.Selection;
                TreePath      default_path      = new TreePath("" + Controller.SelectedPresetIndex);
                default_selection.SelectPath(default_path);

                tree_view.Model.Foreach(new TreeModelForeachFunc(
                                            delegate(ITreeModel model, TreePath path, TreeIter iter) {
                    string address;

                    try {
                        address = (model.GetValue(iter, 2) as Preset).Address;
                    } catch (NullReferenceException) {
                        address = "";
                    }

                    if (!string.IsNullOrEmpty(address) &&
                        address.Equals(Controller.PreviousAddress))
                    {
                        tree_view.SetCursor(path, service_column, false);
                        Preset preset = (Preset)model.GetValue(iter, 2);

                        if (preset.Address != null)
                        {
                            address_entry.Sensitive = false;
                        }

                        if (preset.Path != null)
                        {
                            path_entry.Sensitive = false;
                        }

                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                                            ));

                layout_address.PackStart(new Label()
                {
                    Markup = "<b>" + "Address" + "</b>",
                    Xalign = 0
                }, true, true, 0);

                layout_address.PackStart(address_entry, false, false, 0);
                layout_address.PackStart(address_example, false, false, 0);

                path_entry.Changed += delegate {
                    Controller.CheckAddPage(address_entry.Text, path_entry.Text, tree_view.SelectedRow);
                };

                layout_path.PackStart(new Label()
                {
                    Markup = "<b>" + "Remote Path" + "</b>",
                    Xalign = 0
                }, true, true, 0);

                layout_path.PackStart(path_entry, false, false, 0);
                layout_path.PackStart(path_example, false, false, 0);

                layout_fields.PackStart(layout_address, true, true, 0);
                layout_fields.PackStart(layout_path, true, true, 0);

                layout_vertical.PackStart(scrolled_window, true, true, 0);
                layout_vertical.PackStart(layout_fields, false, false, 0);

                tree_view.ScrollToCell(new TreePath("" + Controller.SelectedPresetIndex), null, true, 0, 0);

                Add(layout_vertical);


                if (string.IsNullOrEmpty(path_entry.Text))
                {
                    address_entry.GrabFocus();
                    address_entry.Position = -1;
                }
                else
                {
                    path_entry.GrabFocus();
                    path_entry.Position = -1;
                }

                Button cancel_button = new Button("Cancel");
                Button add_button    = new Button("Add")
                {
                    Sensitive = false
                };


                Controller.ChangeAddressFieldEvent += delegate(string text,
                                                               string example_text, FieldState state) {
                    Application.Invoke(delegate {
                        address_entry.Text      = text;
                        address_entry.Sensitive = (state == FieldState.Enabled);
                        address_example.Markup  = "<span size=\"small\" fgcolor=\"" +
                                                  SparkleShare.UI.SecondaryTextColor + "\">" + example_text + "</span>";
                    });
                };

                Controller.ChangePathFieldEvent += delegate(string text,
                                                            string example_text, FieldState state) {
                    Application.Invoke(delegate {
                        path_entry.Text      = text;
                        path_entry.Sensitive = (state == FieldState.Enabled);
                        path_example.Markup  = "<span size=\"small\" fgcolor=\""
                                               + SparkleShare.UI.SecondaryTextColor + "\">" + example_text + "</span>";
                    });
                };

                Controller.UpdateAddProjectButtonEvent += delegate(bool button_enabled) {
                    Application.Invoke(delegate { add_button.Sensitive = button_enabled; });
                };


                tree_view.CursorChanged += delegate(object sender, EventArgs e) {
                    Controller.SelectedPresetChanged(tree_view.SelectedRow);
                };

                address_entry.Changed += delegate {
                    Controller.CheckAddPage(address_entry.Text, path_entry.Text, tree_view.SelectedRow);
                };

                cancel_button.Clicked += delegate { Controller.PageCancelled(); };
                add_button.Clicked    += delegate { Controller.AddPageCompleted(address_entry.Text, path_entry.Text); };


                CheckButton check_button = new CheckButton("Fetch prior revisions")
                {
                    Active = false
                };
                check_button.Toggled += delegate { Controller.HistoryItemChanged(check_button.Active); };

                AddOption(check_button);
                AddButton(cancel_button);
                AddButton(add_button);

                Controller.HistoryItemChanged(check_button.Active);
                Controller.CheckAddPage(address_entry.Text, path_entry.Text, 1);
            }

            if (type == PageType.Invite)
            {
                Header      = "You’ve received an invite!";
                Description = "Do you want to add this project to SparkleShare?";

                Table table = new Table(2, 3, true)
                {
                    RowSpacing    = 6,
                    ColumnSpacing = 6
                };

                Label address_label = new Label("Address:")
                {
                    Xalign = 1
                };
                Label path_label = new Label("Remote Path:")
                {
                    Xalign = 1
                };

                Label address_value = new Label("<b>" + Controller.PendingInvite.Address + "</b>")
                {
                    UseMarkup = true,
                    Xalign    = 0
                };

                Label path_value = new Label("<b>" + Controller.PendingInvite.RemotePath + "</b>")
                {
                    UseMarkup = true,
                    Xalign    = 0
                };

                table.Attach(address_label, 0, 1, 0, 1);
                table.Attach(address_value, 1, 2, 0, 1);
                table.Attach(path_label, 0, 1, 1, 2);
                table.Attach(path_value, 1, 2, 1, 2);

                VBox wrapper = new VBox(false, 9);
                wrapper.PackStart(table, true, false, 0);

                Button cancel_button = new Button("Cancel");
                Button add_button    = new Button("Add");


                cancel_button.Clicked += delegate { Controller.PageCancelled(); };
                add_button.Clicked    += delegate { Controller.InvitePageCompleted(); };


                AddButton(cancel_button);
                AddButton(add_button);
                Add(wrapper);
            }

            if (type == PageType.Syncing)
            {
                Header      = String.Format("Adding project ‘{0}’…", Controller.SyncingFolder);
                Description = "This may take a while for large projects.\nIsn’t it coffee-o’clock?";

                ProgressBar progress_bar = new ProgressBar();
                progress_bar.Fraction = Controller.ProgressBarPercentage / 100;

                Button cancel_button = new Button()
                {
                    Label = "Cancel"
                };
                Button finish_button = new Button("Finish")
                {
                    Sensitive = false
                };

                Label progress_label = new Label("Preparing to fetch files…")
                {
                    Justify = Justification.Right,
                    Xalign  = 1
                };


                Controller.UpdateProgressBarEvent += delegate(double percentage, string speed) {
                    Application.Invoke(delegate {
                        progress_bar.Fraction = percentage / 100;
                        progress_label.Text   = speed;
                    });
                };

                cancel_button.Clicked += delegate { Controller.SyncingCancelled(); };


                VBox bar_wrapper = new VBox(false, 0);
                bar_wrapper.PackStart(progress_bar, false, false, 21);
                bar_wrapper.PackStart(progress_label, false, true, 0);

                Add(bar_wrapper);
                AddButton(cancel_button);
                AddButton(finish_button);
            }

            if (type == PageType.Error)
            {
                Header = "Oops! Something went wrong" + "…";

                VBox  points           = new VBox(false, 0);
                Image list_point_one   = new Image(UserInterfaceHelpers.GetIcon("list-point", 16));
                Image list_point_two   = new Image(UserInterfaceHelpers.GetIcon("list-point", 16));
                Image list_point_three = new Image(UserInterfaceHelpers.GetIcon("list-point", 16));

                Label label_one = new Label()
                {
                    Markup = "<b>" + Controller.PreviousUrl + "</b> is the address we’ve compiled. " +
                             "Does this look alright?",
                    Wrap   = true,
                    Xalign = 0
                };

                Label label_two = new Label()
                {
                    Text   = "Is this computer’s Client ID known by the host?",
                    Wrap   = true,
                    Xalign = 0
                };

                points.PackStart(new Label("Please check the following:")
                {
                    Xalign = 0
                }, false, false, 6);

                HBox point_one = new HBox(false, 0);
                point_one.PackStart(list_point_one, false, false, 0);
                point_one.PackStart(label_one, true, true, 12);
                points.PackStart(point_one, false, false, 12);

                HBox point_two = new HBox(false, 0);
                point_two.PackStart(list_point_two, false, false, 0);
                point_two.PackStart(label_two, true, true, 12);
                points.PackStart(point_two, false, false, 12);

                if (warnings.Length > 0)
                {
                    string warnings_markup = "";

                    foreach (string warning in warnings)
                    {
                        warnings_markup += "\n<b>" + warning + "</b>";
                    }

                    Label label_three = new Label()
                    {
                        Markup = "Here’s the raw error message:" + warnings_markup,
                        Wrap   = true,
                        Xalign = 0
                    };

                    HBox point_three = new HBox(false, 0);
                    point_three.PackStart(list_point_three, false, false, 0);
                    point_three.PackStart(label_three, true, true, 12);
                    points.PackStart(point_three, false, false, 12);
                }

                points.PackStart(new Label(""), true, true, 0);

                Button cancel_button    = new Button("Cancel");
                Button try_again_button = new Button("Retry")
                {
                    Sensitive = true
                };


                cancel_button.Clicked    += delegate { Controller.PageCancelled(); };
                try_again_button.Clicked += delegate { Controller.ErrorPageCompleted(); };


                AddButton(cancel_button);
                AddButton(try_again_button);
                Add(points);
            }

            if (type == PageType.StorageSetup)
            {
                Header      = string.Format("Storage type for ‘{0}’", Controller.SyncingFolder);
                Description = "What type of storage would you like to use?";

                VBox layout_vertical      = new VBox(false, 0);
                VBox layout_radio_buttons = new VBox(false, 0)
                {
                    BorderWidth = 12
                };

                foreach (StorageTypeInfo storage_type in SparkleShare.Controller.FetcherAvailableStorageTypes)
                {
                    RadioButton radio_button = new RadioButton(null,
                                                               storage_type.Name + "\n" + storage_type.Description);

                    (radio_button.Child as Label).Markup = string.Format(
                        "<b>{0}</b>\n<span fgcolor=\"{1}\">{2}</span>",
                        storage_type.Name, SparkleShare.UI.SecondaryTextColor, storage_type.Description);

                    (radio_button.Child as Label).Xpad = 9;

                    layout_radio_buttons.PackStart(radio_button, false, false, 9);
                    radio_button.Group = (layout_radio_buttons.Children [0] as RadioButton).Group;
                }

                layout_vertical.PackStart(new Label(""), true, true, 0);
                layout_vertical.PackStart(layout_radio_buttons, false, false, 0);
                layout_vertical.PackStart(new Label(""), true, true, 0);
                Add(layout_vertical);

                Button cancel_button   = new Button("Cancel");
                Button continue_button = new Button("Continue");

                continue_button.Clicked += delegate {
                    int checkbox_index = 0;
                    foreach (RadioButton radio_button in layout_radio_buttons.Children)
                    {
                        if (radio_button.Active)
                        {
                            StorageTypeInfo selected_storage_type = SparkleShare.Controller.FetcherAvailableStorageTypes [checkbox_index];
                            Controller.StoragePageCompleted(selected_storage_type.Type);
                            return;
                        }

                        checkbox_index++;
                    }
                };

                cancel_button.Clicked += delegate {
                    Controller.SyncingCancelled();
                };

                AddButton(cancel_button);
                AddButton(continue_button);
            }

            if (type == PageType.CryptoSetup || type == PageType.CryptoPassword)
            {
                if (type == PageType.CryptoSetup)
                {
                    Header      = string.Format("Encryption password for ‘{0}’", Controller.SyncingFolder);
                    Description = "Please a provide a strong password that you don’t use elsewhere.";
                }
                else
                {
                    Header      = string.Format("‘{0}’ contains encrypted files", Controller.SyncingFolder);
                    Description = "Please enter the password to see their contents.";
                }

                Label password_label = new Label("<b>" + "Password" + "</b>")
                {
                    UseMarkup = true,
                    Xalign    = 1
                };

                Entry password_entry = new Entry()
                {
                    Xalign           = 0,
                    Visibility       = false,
                    ActivatesDefault = true
                };

                CheckButton show_password_check_button = new CheckButton("Make visible")
                {
                    Active = false,
                    Xalign = 0,
                };

                Table table = new Table(2, 3, true)
                {
                    RowSpacing    = 6,
                    ColumnSpacing = 6
                };

                table.Attach(password_label, 0, 1, 0, 1);
                table.Attach(password_entry, 1, 2, 0, 1);

                table.Attach(show_password_check_button, 1, 2, 1, 2);

                VBox wrapper = new VBox(false, 9);
                wrapper.PackStart(table, true, false, 0);

                Image warning_image = new Image(
                    UserInterfaceHelpers.GetIcon("dialog-information", 24));

                Label warning_label = new Label()
                {
                    Xalign = 0,
                    Wrap   = true,
                    Text   = "This password can’t be changed later, and your files can’t be recovered if it’s forgotten."
                };

                HBox warning_layout = new HBox(false, 0);
                warning_layout.PackStart(warning_image, false, false, 15);
                warning_layout.PackStart(warning_label, true, true, 0);

                VBox warning_wrapper = new VBox(false, 0);
                warning_wrapper.PackStart(warning_layout, false, false, 15);

                if (type == PageType.CryptoSetup)
                {
                    wrapper.PackStart(warning_wrapper, false, false, 0);
                }

                Button cancel_button   = new Button("Cancel");
                Button continue_button = new Button("Continue")
                {
                    Sensitive = false
                };


                Controller.UpdateCryptoSetupContinueButtonEvent += delegate(bool button_enabled) {
                    Application.Invoke(delegate { continue_button.Sensitive = button_enabled; });
                };

                Controller.UpdateCryptoPasswordContinueButtonEvent += delegate(bool button_enabled) {
                    Application.Invoke(delegate { continue_button.Sensitive = button_enabled; });
                };

                show_password_check_button.Toggled += delegate {
                    password_entry.Visibility = !password_entry.Visibility;
                };

                password_entry.Changed += delegate {
                    if (type == PageType.CryptoSetup)
                    {
                        Controller.CheckCryptoSetupPage(password_entry.Text);
                    }
                    else
                    {
                        Controller.CheckCryptoPasswordPage(password_entry.Text);
                    }
                };

                cancel_button.Clicked += delegate { Controller.CryptoPageCancelled(); };

                continue_button.Clicked += delegate {
                    if (type == PageType.CryptoSetup)
                    {
                        Controller.CryptoSetupPageCompleted(password_entry.Text);
                    }
                    else
                    {
                        Controller.CryptoPasswordPageCompleted(password_entry.Text);
                    }
                };


                Add(wrapper);

                AddButton(cancel_button);
                AddButton(continue_button);

                password_entry.GrabFocus();
            }

            if (type == PageType.Finished)
            {
                Header      = "Your shared project is ready!";
                Description = "You can find the files in your SparkleShare folder.";

                UrgencyHint = true;

                Button show_files_button = new Button("Show Files");
                Button finish_button     = new Button("Finish");


                show_files_button.Clicked += delegate { Controller.ShowFilesClicked(); };
                finish_button.Clicked     += delegate { Controller.FinishPageCompleted(); };


                if (warnings.Length > 0)
                {
                    Image warning_image = new Image(UserInterfaceHelpers.GetIcon("dialog-information", 24));

                    Label warning_label = new Label(warnings [0])
                    {
                        Xalign = 0,
                        Wrap   = true
                    };

                    HBox warning_layout = new HBox(false, 0);
                    warning_layout.PackStart(warning_image, false, false, 15);
                    warning_layout.PackStart(warning_label, true, true, 0);

                    VBox warning_wrapper = new VBox(false, 0);
                    warning_wrapper.PackStart(warning_layout, false, false, 0);

                    Add(warning_wrapper);
                }
                else
                {
                    Add(null);
                }

                AddButton(show_files_button);
                AddButton(finish_button);
            }
        }
示例#23
0
        public void ShowPage(PageType type, string [] warnings)
        {
            if (type == PageType.Setup)
            {
                Header      = "Welcome to SparkleShare!";
                Description = "First off, what’s your name and email?\n(visible only to team members)";

                FullNameLabel       = new SparkleLabel("Full Name:", NSTextAlignment.Right);
                FullNameLabel.Frame = new RectangleF(165, Frame.Height - 234, 160, 17);

                FullNameTextField = new NSTextField()
                {
                    Frame       = new RectangleF(330, Frame.Height - 238, 196, 22),
                    StringValue = UnixUserInfo.GetRealUser().RealName,
                    Delegate    = new SparkleTextFieldDelegate()
                };

                EmailLabel       = new SparkleLabel("Email:", NSTextAlignment.Right);
                EmailLabel.Frame = new RectangleF(165, Frame.Height - 264, 160, 17);

                EmailTextField = new NSTextField()
                {
                    Frame    = new RectangleF(330, Frame.Height - 268, 196, 22),
                    Delegate = new SparkleTextFieldDelegate()
                };

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

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


                (FullNameTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    Controller.CheckSetupPage(FullNameTextField.StringValue, EmailTextField.StringValue);
                };

                (EmailTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    Controller.CheckSetupPage(FullNameTextField.StringValue, EmailTextField.StringValue);
                };

                ContinueButton.Activated += delegate {
                    string full_name = FullNameTextField.StringValue.Trim();
                    string email     = EmailTextField.StringValue.Trim();

                    Controller.SetupPageCompleted(full_name, email);
                };

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

                Controller.UpdateSetupContinueButtonEvent += delegate(bool button_enabled) {
                    Program.Controller.Invoke(() => {
                        ContinueButton.Enabled = button_enabled;
                    });
                };


                ContentView.AddSubview(FullNameLabel);
                ContentView.AddSubview(FullNameTextField);
                ContentView.AddSubview(EmailLabel);
                ContentView.AddSubview(EmailTextField);

                Buttons.Add(ContinueButton);
                Buttons.Add(CancelButton);

                Controller.CheckSetupPage(FullNameTextField.StringValue, EmailTextField.StringValue);

                if (FullNameTextField.StringValue.Equals(""))
                {
                    MakeFirstResponder((NSResponder)FullNameTextField);
                }
                else
                {
                    MakeFirstResponder((NSResponder)EmailTextField);
                }
            }

            if (type == PageType.Invite)
            {
                Header      = "You’ve received an invite!";
                Description = "Do you want to add this project to SparkleShare?";

                AddressLabel       = new SparkleLabel("Address:", NSTextAlignment.Right);
                AddressLabel.Frame = new RectangleF(165, Frame.Height - 240, 160, 17);

                AddressTextField = new SparkleLabel(Controller.PendingInvite.Address, NSTextAlignment.Left)
                {
                    Frame = new RectangleF(330, Frame.Height - 240, 260, 17),
                    Font  = SparkleUI.BoldFont
                };

                PathLabel       = new SparkleLabel("Remote Path:", NSTextAlignment.Right);
                PathLabel.Frame = new RectangleF(165, Frame.Height - 264, 160, 17);

                PathTextField = new SparkleLabel(Controller.PendingInvite.RemotePath, NSTextAlignment.Left)
                {
                    Frame = new RectangleF(330, Frame.Height - 264, 260, 17),
                    Font  = SparkleUI.BoldFont
                };

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


                CancelButton.Activated += delegate { Controller.PageCancelled(); };
                AddButton.Activated    += delegate { Controller.InvitePageCompleted(); };


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

                Buttons.Add(AddButton);
                Buttons.Add(CancelButton);
            }

            if (type == PageType.Add)
            {
                Header      = "Where’s your project hosted?";
                Description = "";

                AddressLabel = new SparkleLabel("Address:", NSTextAlignment.Left)
                {
                    Frame = new RectangleF(190, Frame.Height - 308, 160, 17),
                    Font  = SparkleUI.BoldFont
                };

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

                AddressTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail;

                PathLabel = new SparkleLabel("Remote Path:", NSTextAlignment.Left)
                {
                    Frame = new RectangleF(190 + 196 + 16, Frame.Height - 308, 160, 17),
                    Font  = SparkleUI.BoldFont
                };

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

                PathTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail;

                PathHelpLabel = new SparkleLabel(Controller.SelectedPlugin.PathExample, NSTextAlignment.Left)
                {
                    TextColor = NSColor.DisabledControlText,
                    Frame     = new RectangleF(190 + 196 + 16, Frame.Height - 355, 204, 17),
                    Font      = NSFontManager.SharedFontManager.FontWithFamily("Lucida Grande",
                                                                               NSFontTraitMask.Condensed, 0, 11),
                };

                AddressHelpLabel = new SparkleLabel(Controller.SelectedPlugin.AddressExample, NSTextAlignment.Left)
                {
                    TextColor = NSColor.DisabledControlText,
                    Frame     = new RectangleF(190, Frame.Height - 355, 204, 17),
                    Font      = NSFontManager.SharedFontManager.FontWithFamily("Lucida Grande",
                                                                               NSFontTraitMask.Condensed, 0, 11),
                };

                if (TableView == null || TableView.RowCount != Controller.Plugins.Count)
                {
                    TableView = new NSTableView()
                    {
                        Frame            = new RectangleF(0, 0, 0, 0),
                        RowHeight        = 34,
                        IntercellSpacing = new SizeF(8, 12),
                        HeaderView       = null,
                        Delegate         = new SparkleTableViewDelegate()
                    };

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

                    IconColumn = new NSTableColumn()
                    {
                        Width         = 36,
                        HeaderToolTip = "Icon",
                        DataCell      = new NSImageCell()
                        {
                            ImageAlignment = NSImageAlignment.Right
                        }
                    };

                    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);

                    // Hi-res display support was added after Snow Leopard
                    if (Environment.OSVersion.Version.Major < 11)
                    {
                        DataSource = new SparkleDataSource(1, Controller.Plugins);
                    }
                    else
                    {
                        DataSource = new SparkleDataSource(BackingScaleFactor, Controller.Plugins);
                    }

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

                    (TableView.Delegate as SparkleTableViewDelegate).SelectionChanged += delegate {
                        Controller.SelectedPluginChanged(TableView.SelectedRow);
                        Controller.CheckAddPage(AddressTextField.StringValue, PathTextField.StringValue, TableView.SelectedRow);
                    };
                }

                TableView.SelectRow(Controller.SelectedPluginIndex, false);
                TableView.ScrollRowToVisible(Controller.SelectedPluginIndex);
                MakeFirstResponder((NSResponder)TableView);

                HistoryCheckButton = new NSButton()
                {
                    Frame = new RectangleF(190, Frame.Height - 400, 300, 18),
                    Title = "Fetch prior revisions"
                };

                if (Controller.FetchPriorHistory)
                {
                    HistoryCheckButton.State = NSCellStateValue.On;
                }

                HistoryCheckButton.SetButtonType(NSButtonType.Switch);

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

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


                Controller.ChangeAddressFieldEvent += delegate(string text, string example_text, FieldState state) {
                    Program.Controller.Invoke(() => {
                        AddressTextField.StringValue = text;
                        AddressTextField.Enabled     = (state == FieldState.Enabled);
                        AddressHelpLabel.StringValue = example_text;
                    });
                };

                Controller.ChangePathFieldEvent += delegate(string text, string example_text, FieldState state) {
                    Program.Controller.Invoke(() => {
                        PathTextField.StringValue = text;
                        PathTextField.Enabled     = (state == FieldState.Enabled);
                        PathHelpLabel.StringValue = example_text;
                    });
                };


                (AddressTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    Controller.CheckAddPage(AddressTextField.StringValue, PathTextField.StringValue, TableView.SelectedRow);
                };

                (PathTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    Controller.CheckAddPage(AddressTextField.StringValue, PathTextField.StringValue, TableView.SelectedRow);
                };


                HistoryCheckButton.Activated += delegate {
                    Controller.HistoryItemChanged(HistoryCheckButton.State == NSCellStateValue.On);
                };

                AddButton.Activated += delegate {
                    Controller.AddPageCompleted(AddressTextField.StringValue, PathTextField.StringValue);
                };

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

                Controller.UpdateAddProjectButtonEvent += delegate(bool button_enabled) {
                    Program.Controller.Invoke(() => {
                        AddButton.Enabled = button_enabled;
                    });
                };

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

                Buttons.Add(AddButton);
                Buttons.Add(CancelButton);

                Controller.CheckAddPage(AddressTextField.StringValue, PathTextField.StringValue, TableView.SelectedRow);
            }

            if (type == PageType.Syncing)
            {
                Header      = "Adding project ‘" + Controller.SyncingFolder + "’…";
                Description = "This may take a while for large projects.\nIsn’t it 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   = Controller.ProgressBarPercentage
                };

                ProgressIndicator.StartAnimation(this);

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

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

                ProgressLabel       = new SparkleLabel("Preparing to fetch files…", NSTextAlignment.Right);
                ProgressLabel.Frame = new RectangleF(Frame.Width - 40 - 250, 185, 250, 25);


                Controller.UpdateProgressBarEvent += delegate(double percentage, string speed) {
                    Program.Controller.Invoke(() => {
                        ProgressIndicator.DoubleValue = percentage;
                        ProgressLabel.StringValue     = speed;
                    });
                };


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


                ContentView.AddSubview(ProgressLabel);
                ContentView.AddSubview(ProgressIndicator);

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

            if (type == PageType.Error)
            {
                Header      = "Oops! 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;" +
                              "  word-wrap: break-word;" +
                              "}" +
                              "ul {" +
                              "  padding-left: 24px;" +
                              "}" +
                              "</style>" +
                              "<ul>" +
                              "  <li><b>" + Controller.PreviousUrl + "</b> is the address we’ve compiled. Does this look alright?</li>" +
                              "  <li>Is this computer’s Client ID known by the host?</li>" +
                              "</ul>";

                if (warnings.Length > 0)
                {
                    string warnings_markup = "";

                    foreach (string warning in warnings)
                    {
                        warnings_markup += "<br><b>" + warning + "</b>";
                    }

                    html = html.Replace("</ul>", "<li>Here’s the raw error message: " + warnings_markup + "</li></ul>");
                }

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

                CancelButton = new NSButton()
                {
                    Title = "Cancel"
                };
                TryAgainButton = new NSButton()
                {
                    Title = "Try Again…"
                };


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


                ContentView.AddSubview(web_view);

                Buttons.Add(TryAgainButton);
                Buttons.Add(CancelButton);
            }

            if (type == PageType.CryptoSetup || type == PageType.CryptoPassword)
            {
                if (type == PageType.CryptoSetup)
                {
                    Header      = "Set up file encryption";
                    Description = "Please a provide a strong password that you don’t use elsewhere.";
                }
                else
                {
                    Header      = "This project contains encrypted files";
                    Description = "Please enter the password to see their contents.";
                }

                int extra_pos_y = 0;

                if (type == PageType.CryptoPassword)
                {
                    extra_pos_y = 20;
                }

                PasswordLabel = new SparkleLabel("Password:"******"Show password",
                    State = NSCellStateValue.Off
                };

                ShowPasswordCheckButton.SetButtonType(NSButtonType.Switch);

                WarningImage      = NSImage.ImageNamed("NSInfo");
                WarningImage.Size = new SizeF(24, 24);

                WarningImageView = new NSImageView()
                {
                    Image = WarningImage,
                    Frame = new RectangleF(200, Frame.Height - 320, 24, 24)
                };

                WarningTextField = new SparkleLabel("This password can’t be changed later, and your files can’t be recovered if it’s forgotten.", NSTextAlignment.Left)
                {
                    Frame = new RectangleF(235, Frame.Height - 390, 325, 100),
                };

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

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


                Controller.UpdateCryptoPasswordContinueButtonEvent += delegate(bool button_enabled) {
                    Program.Controller.Invoke(() => { ContinueButton.Enabled = button_enabled; });
                };

                Controller.UpdateCryptoSetupContinueButtonEvent += delegate(bool button_enabled) {
                    Program.Controller.Invoke(() => { ContinueButton.Enabled = button_enabled; });
                };

                ShowPasswordCheckButton.Activated += delegate {
                    if (PasswordTextField.Superview == ContentView)
                    {
                        PasswordTextField.RemoveFromSuperview();
                        ContentView.AddSubview(VisiblePasswordTextField);
                    }
                    else
                    {
                        VisiblePasswordTextField.RemoveFromSuperview();
                        ContentView.AddSubview(PasswordTextField);
                    }
                };

                (PasswordTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    VisiblePasswordTextField.StringValue = PasswordTextField.StringValue;

                    if (type == PageType.CryptoSetup)
                    {
                        Controller.CheckCryptoSetupPage(PasswordTextField.StringValue);
                    }
                    else
                    {
                        Controller.CheckCryptoPasswordPage(PasswordTextField.StringValue);
                    }
                };

                (VisiblePasswordTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    PasswordTextField.StringValue = VisiblePasswordTextField.StringValue;

                    if (type == PageType.CryptoSetup)
                    {
                        Controller.CheckCryptoSetupPage(PasswordTextField.StringValue);
                    }
                    else
                    {
                        Controller.CheckCryptoPasswordPage(PasswordTextField.StringValue);
                    }
                };

                ContinueButton.Activated += delegate {
                    if (type == PageType.CryptoSetup)
                    {
                        Controller.CryptoSetupPageCompleted(PasswordTextField.StringValue);
                    }
                    else
                    {
                        Controller.CryptoPasswordPageCompleted(PasswordTextField.StringValue);
                    }
                };

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


                ContentView.AddSubview(PasswordLabel);
                ContentView.AddSubview(PasswordTextField);
                ContentView.AddSubview(ShowPasswordCheckButton);

                if (type == PageType.CryptoSetup)
                {
                    ContentView.AddSubview(WarningImageView);
                    ContentView.AddSubview(WarningTextField);
                }

                Buttons.Add(ContinueButton);
                Buttons.Add(CancelButton);

                MakeFirstResponder((NSResponder)PasswordTextField);
                NSApplication.SharedApplication.RequestUserAttention(NSRequestUserAttentionType.CriticalRequest);
            }


            if (type == PageType.Finished)
            {
                Header      = "Your shared project is ready!";
                Description = "You can find the files in your SparkleShare folder.";

                if (warnings.Length > 0)
                {
                    WarningImage      = NSImage.ImageNamed("NSInfo");
                    WarningImage.Size = new SizeF(24, 24);

                    WarningImageView = new NSImageView()
                    {
                        Image = WarningImage,
                        Frame = new RectangleF(200, Frame.Height - 175, 24, 24)
                    };

                    WarningTextField       = new SparkleLabel(warnings [0], NSTextAlignment.Left);
                    WarningTextField.Frame = new RectangleF(235, Frame.Height - 245, 325, 100);

                    ContentView.AddSubview(WarningImageView);
                    ContentView.AddSubview(WarningTextField);
                }

                ShowFilesButton = new NSButton()
                {
                    Title = "Show Files…"
                };
                FinishButton = new NSButton()
                {
                    Title = "Finish"
                };


                ShowFilesButton.Activated += delegate { Controller.ShowFilesClicked(); };
                FinishButton.Activated    += delegate { Controller.FinishPageCompleted(); };


                Buttons.Add(FinishButton);
                Buttons.Add(ShowFilesButton);

                NSApplication.SharedApplication.RequestUserAttention(NSRequestUserAttentionType.CriticalRequest);
            }

            if (type == PageType.Tutorial)
            {
                SlideImage = NSImage.ImageNamed("tutorial-slide-" + Controller.TutorialPageNumber);
                if (SlideImage != null)
                {
                    SlideImage.Size = new SizeF(324, 200);

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

                    ContentView.AddSubview(SlideImageView);
                }

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

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


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


                    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 automatically with " +
                                  "the host and your team members.";

                    ContinueButton = new NSButton()
                    {
                        Title = "Continue"
                    };
                    ContinueButton.Activated += delegate { Controller.TutorialPageCompleted(); };
                    Buttons.Add(ContinueButton);

                    break;
                }

                case 3: {
                    Header      = "The status icon helps you";
                    Description = "It shows the syncing progress, provides easy access to " +
                                  "your projects, and lets you view recent changes.";

                    ContinueButton = new NSButton()
                    {
                        Title = "Continue"
                    };
                    ContinueButton.Activated += delegate { Controller.TutorialPageCompleted(); };
                    Buttons.Add(ContinueButton);

                    break;
                }

                case 4: {
                    Header      = "Here’s your unique Client ID";
                    Description = "You’ll need it whenever you want to link this computer to a host. " +
                                  "You can also find it in the status icon menu.";

                    LinkCodeTextField = new NSTextField()
                    {
                        StringValue = Program.Controller.CurrentUser.PublicKey,
                        Enabled     = false,
                        Selectable  = false,
                        Frame       = new RectangleF(230, Frame.Height - 238, 246, 22)
                    };

                    LinkCodeTextField.Cell.UsesSingleLineMode = true;
                    LinkCodeTextField.Cell.LineBreakMode      = NSLineBreakMode.TruncatingTail;

                    CopyButton = new NSButton()
                    {
                        Title      = "Copy",
                        BezelStyle = NSBezelStyle.RoundRect,
                        Frame      = new RectangleF(480, Frame.Height - 238, 60, 22)
                    };

                    StartupCheckButton = new NSButton()
                    {
                        Frame = new RectangleF(190, Frame.Height - 400, 300, 18),
                        Title = "Add SparkleShare to startup items",
                        State = NSCellStateValue.On
                    };

                    StartupCheckButton.SetButtonType(NSButtonType.Switch);

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


                    StartupCheckButton.Activated += delegate {
                        Controller.StartupItemChanged(StartupCheckButton.State == NSCellStateValue.On);
                    };

                    CopyButton.Activated   += delegate { Controller.CopyToClipboardClicked(); };
                    FinishButton.Activated += delegate { Controller.TutorialPageCompleted(); };


                    ContentView.AddSubview(LinkCodeTextField);
                    ContentView.AddSubview(CopyButton);
                    ContentView.AddSubview(StartupCheckButton);

                    Buttons.Add(FinishButton);

                    break;
                }
                }
            }
        }
示例#24
0
        public void ShowAccountForm()
        {
            Reset();

            VBox layout_vertical = new VBox(false, 0);

            Deletable = false;

            Label header = new Label("<span size='large'><b>" +
                                     _("Welcome to SparkleShare!") +
                                     "</b></span>")
            {
                UseMarkup = true,
                Xalign    = 0
            };

            Label information = new Label(_("Before we can create a SparkleShare folder on this " +
                                            "computer, we need a few bits of information from you."))
            {
                Xalign = 0,
                Wrap   = true
            };

            Table table = new Table(4, 2, true)
            {
                RowSpacing = 6
            };

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

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

            Label name_label = new Label("<b>" + _("Full Name:") + "</b>")
            {
                UseMarkup = true,
                Xalign    = 0
            };

            NameEntry          = new Entry(full_name.TrimEnd(",".ToCharArray()));
            NameEntry.Changed += delegate {
                CheckAccountForm();
            };


            EmailEntry          = new Entry(SparkleShare.Controller.UserEmail);
            EmailEntry.Changed += delegate {
                CheckAccountForm();
            };

            Label email_label = new Label("<b>" + _("Email:") + "</b>")
            {
                UseMarkup = true,
                Xalign    = 0
            };


            table.Attach(name_label, 0, 1, 0, 1);
            table.Attach(NameEntry, 1, 2, 0, 1);
            table.Attach(email_label, 0, 1, 1, 2);
            table.Attach(EmailEntry, 1, 2, 1, 2);

            NextButton = new Button(_("Next"))
            {
                Sensitive = false
            };

            NextButton.Clicked += delegate(object o, EventArgs args) {
                NextButton.Remove(NextButton.Child);
                NextButton.Add(new Label(_("Configuring…")));

                NextButton.Sensitive = false;
                table.Sensitive      = false;

                NextButton.ShowAll();

                SparkleShare.Controller.UserName  = NameEntry.Text;
                SparkleShare.Controller.UserEmail = EmailEntry.Text;

                SparkleShare.Controller.GenerateKeyPair();
                SparkleShare.Controller.AddKey();

                SparkleShare.Controller.FirstRun = false;

                Deletable = true;
                ShowServerForm();
            };

            AddButton(NextButton);

            layout_vertical.PackStart(header, false, false, 0);
            layout_vertical.PackStart(information, false, false, 21);
            layout_vertical.PackStart(new Label(""), false, false, 0);
            layout_vertical.PackStart(table, false, false, 0);

            Add(layout_vertical);

            CheckAccountForm();

            ShowAll();
        }
示例#25
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FsIdChanger"/> class.
 /// </summary>
 /// <param name="logger">The logger.</param>
 public FsIdChanger(
     ILogger <FsIdChanger>?logger = null)
 {
     _serverUser = UnixUserInfo.GetRealUser();
     _logger     = logger;
 }
示例#26
0
        public override string AuthString()
        {
            long uid = UnixUserInfo.GetRealUserId();

            return(uid.ToString());
        }
示例#27
0
        public void ShowPage(PageType type, string [] warnings)
        {
            if (type == PageType.Setup)
            {
                Header      = "Welcome to SparkleShare!";
                Description = "First off, what's your name and email?\n(visible only to team members)";


                FullNameLabel = new NSTextField()
                {
                    Alignment       = NSTextAlignment.Right,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF(165, Frame.Height - 234, 160, 17),
                    StringValue     = "Full Name:",
                    Font            = SparkleUI.Font
                };

                FullNameTextField = new NSTextField()
                {
                    Frame       = new RectangleF(330, Frame.Height - 238, 196, 22),
                    StringValue = UnixUserInfo.GetRealUser().RealName,
                    Delegate    = new SparkleTextFieldDelegate()
                };

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

                EmailTextField = new NSTextField()
                {
                    Frame    = new RectangleF(330, Frame.Height - 268, 196, 22),
                    Delegate = new SparkleTextFieldDelegate()
                };

                EmailHelpLabel = new NSTextField()
                {
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    TextColor       = NSColor.DisabledControlText,
                    Editable        = false,
                    Frame           = new RectangleF(330, Frame.Height - 290, 204, 17),
                    Font            = NSFontManager.SharedFontManager.FontWithFamily("Lucida Grande",
                                                                                     NSFontTraitMask.Condensed, 0, 11),
                    StringValue = "(used to find your Gravatar)"
                };



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

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


                (FullNameTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    Controller.CheckSetupPage(FullNameTextField.StringValue, EmailTextField.StringValue);
                };

                (EmailTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    Controller.CheckSetupPage(FullNameTextField.StringValue, EmailTextField.StringValue);
                };

                ContinueButton.Activated += delegate {
                    string full_name = FullNameTextField.StringValue.Trim();
                    string email     = EmailTextField.StringValue.Trim();

                    Controller.SetupPageCompleted(full_name, email);
                };

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

                Controller.UpdateSetupContinueButtonEvent += delegate(bool button_enabled) {
                    InvokeOnMainThread(delegate {
                        ContinueButton.Enabled = button_enabled;
                    });
                };


                ContentView.AddSubview(FullNameLabel);
                ContentView.AddSubview(FullNameTextField);
                ContentView.AddSubview(EmailLabel);
                ContentView.AddSubview(EmailTextField);
                ContentView.AddSubview(EmailHelpLabel);

                Buttons.Add(ContinueButton);
                Buttons.Add(CancelButton);

                Controller.CheckSetupPage(FullNameTextField.StringValue, EmailTextField.StringValue);
            }

            if (type == PageType.Invite)
            {
                Header      = "You've received an invite!";
                Description = "Do you want to add this project to SparkleShare?";


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

                PathLabel = new NSTextField()
                {
                    Alignment       = NSTextAlignment.Right,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF(165, Frame.Height - 264, 160, 17),
                    StringValue     = "Remote Path:",
                    Font            = SparkleUI.Font
                };

                AddressTextField = new NSTextField()
                {
                    Alignment       = NSTextAlignment.Left,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF(330, Frame.Height - 240, 260, 17),
                    StringValue     = Controller.PendingInvite.Address,
                    Font            = SparkleUI.BoldFont
                };

                PathTextField = new NSTextField()
                {
                    Alignment       = NSTextAlignment.Left,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF(330, Frame.Height - 264, 260, 17),
                    StringValue     = Controller.PendingInvite.RemotePath,
                    Font            = SparkleUI.BoldFont
                };

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

                AddButton = new NSButton()
                {
                    Title = "Add"
                };


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

                AddButton.Activated += delegate {
                    Controller.InvitePageCompleted();
                };


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

                Buttons.Add(AddButton);
                Buttons.Add(CancelButton);
            }

            if (type == 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.BoldFont
                };

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

                AddressTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail;

                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.BoldFont
                };

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

                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),
                    Font            = NSFontManager.SharedFontManager.FontWithFamily("Lucida Grande",
                                                                                     NSFontTraitMask.Condensed, 0, 11),
                    StringValue = "" + Controller.SelectedPlugin.PathExample
                };

                AddressHelpLabel = new NSTextField()
                {
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    TextColor       = NSColor.DisabledControlText,
                    Editable        = false,
                    Frame           = new RectangleF(190, Frame.Height - 355, 204, 17),
                    Font            = NSFontManager.SharedFontManager.FontWithFamily("Lucida Grande",
                                                                                     NSFontTraitMask.Condensed, 0, 11),
                    StringValue = "" + Controller.SelectedPlugin.AddressExample
                };

                TableView = new NSTableView()
                {
                    Frame            = new RectangleF(0, 0, 0, 0),
                    RowHeight        = 34,
                    IntercellSpacing = new SizeF(8, 12),
                    HeaderView       = null,
                    Delegate         = new SparkleTableViewDelegate()
                };

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

                IconColumn = new NSTableColumn(new NSImage())
                {
                    Width         = 36,
                    HeaderToolTip = "Icon",
                    DataCell      = new NSImageCell()
                    {
                        ImageAlignment = NSImageAlignment.Right
                    }
                };

                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(Controller.Plugins);

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

                HistoryCheckButton = new NSButton()
                {
                    Frame = new RectangleF(190, Frame.Height - 400, 300, 18),
                    Title = "Fetch prior revisions"
                };

                if (Controller.FetchPriorHistory)
                {
                    HistoryCheckButton.State = NSCellStateValue.On;
                }

                HistoryCheckButton.SetButtonType(NSButtonType.Switch);

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

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


                Controller.ChangeAddressFieldEvent += delegate(string text,
                                                               string example_text, FieldState state) {
                    InvokeOnMainThread(delegate {
                        AddressTextField.StringValue = text;
                        AddressTextField.Enabled     = (state == FieldState.Enabled);
                        AddressHelpLabel.StringValue = example_text;
                    });
                };

                Controller.ChangePathFieldEvent += delegate(string text,
                                                            string example_text, FieldState state) {
                    InvokeOnMainThread(delegate {
                        PathTextField.StringValue = text;
                        PathTextField.Enabled     = (state == FieldState.Enabled);
                        PathHelpLabel.StringValue = example_text;
                    });
                };

                TableView.SelectRow(Controller.SelectedPluginIndex, false);
                TableView.ScrollRowToVisible(Controller.SelectedPluginIndex);

                (AddressTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    Controller.CheckAddPage(AddressTextField.StringValue, PathTextField.StringValue, TableView.SelectedRow);
                };

                (PathTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    Controller.CheckAddPage(AddressTextField.StringValue, PathTextField.StringValue, TableView.SelectedRow);
                };

                (TableView.Delegate as SparkleTableViewDelegate).SelectionChanged += delegate {
                    Controller.SelectedPluginChanged(TableView.SelectedRow);
                    Controller.CheckAddPage(AddressTextField.StringValue, PathTextField.StringValue, TableView.SelectedRow);
                };

                HistoryCheckButton.Activated += delegate {
                    Controller.HistoryItemChanged(HistoryCheckButton.State == NSCellStateValue.On);
                };

                AddButton.Activated += delegate {
                    Controller.AddPageCompleted(AddressTextField.StringValue, PathTextField.StringValue);
                };

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

                Controller.UpdateAddProjectButtonEvent += delegate(bool button_enabled) {
                    InvokeOnMainThread(delegate {
                        AddButton.Enabled = button_enabled;
                    });
                };


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

                Buttons.Add(AddButton);
                Buttons.Add(CancelButton);

                Controller.CheckAddPage(AddressTextField.StringValue, PathTextField.StringValue, TableView.SelectedRow);
            }

            if (type == PageType.Syncing)
            {
                Header      = "Adding project ‘" + Controller.SyncingFolder + "’…";
                Description = "This may take a while for large projects.\nIsn't it 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   = Controller.ProgressBarPercentage
                };

                ProgressIndicator.StartAnimation(this);

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

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


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

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


                ContentView.AddSubview(ProgressIndicator);

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

            if (type == PageType.Error)
            {
                Header      = "Oops! 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><b>" + Controller.PreviousUrl + "</b> is the address we've compiled. Does this look alright?</li>" +
                              "  <li>Do you have access rights to this remote project?</li>" +
                              "</ul>";

                if (warnings.Length > 0)
                {
                    string warnings_markup = "";

                    foreach (string warning in warnings)
                    {
                        warnings_markup += "<br><b>" + warning + "</b>";
                    }

                    html = html.Replace("</ul>", "<li>Here's the raw error message: " + warnings_markup + "</li></ul>");
                }

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

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

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


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

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


                ContentView.AddSubview(web_view);

                Buttons.Add(TryAgainButton);
                Buttons.Add(CancelButton);
            }

            if (type == PageType.CryptoSetup)
            {
                Header      = "Set up file encryption";
                Description = "This project is supposed to be encrypted, but it doesn't yet have a password set. Please provide one below:";


                PasswordLabel = new NSTextField()
                {
                    Alignment       = NSTextAlignment.Right,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF(155, Frame.Height - 204, 160, 17),
                    StringValue     = "Password:"******"Show password",
                    State = NSCellStateValue.Off
                };

                ShowPasswordCheckButton.SetButtonType(NSButtonType.Switch);

                WarningImage      = NSImage.ImageNamed("NSInfo");
                WarningImage.Size = new SizeF(24, 24);

                WarningImageView = new NSImageView()
                {
                    Image = WarningImage,
                    Frame = new RectangleF(200, Frame.Height - 320, 24, 24)
                };

                WarningTextField = new NSTextField()
                {
                    Frame           = new RectangleF(235, Frame.Height - 390, 325, 100),
                    StringValue     = "This password can't be changed later, and your files can't be recovered if it's forgotten.",
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Font            = SparkleUI.Font
                };

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

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


                ShowPasswordCheckButton.Activated += delegate {
                    if (PasswordTextField.Superview == ContentView)
                    {
                        PasswordTextField.RemoveFromSuperview();
                        ContentView.AddSubview(VisiblePasswordTextField);
                    }
                    else
                    {
                        VisiblePasswordTextField.RemoveFromSuperview();
                        ContentView.AddSubview(PasswordTextField);
                    }
                };

                (PasswordTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    VisiblePasswordTextField.StringValue = PasswordTextField.StringValue;
                    Controller.CheckCryptoSetupPage(PasswordTextField.StringValue);
                };

                (VisiblePasswordTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    PasswordTextField.StringValue = VisiblePasswordTextField.StringValue;
                    Controller.CheckCryptoSetupPage(PasswordTextField.StringValue);
                };


                Controller.UpdateCryptoSetupContinueButtonEvent += delegate(bool button_enabled) {
                    InvokeOnMainThread(() => {
                        ContinueButton.Enabled = button_enabled;
                    });
                };

                ContinueButton.Activated += delegate {
                    Controller.CryptoSetupPageCompleted(PasswordTextField.StringValue);
                };

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


                ContentView.AddSubview(PasswordLabel);
                ContentView.AddSubview(PasswordTextField);
                ContentView.AddSubview(ShowPasswordCheckButton);
                ContentView.AddSubview(WarningImageView);
                ContentView.AddSubview(WarningTextField);

                Buttons.Add(ContinueButton);
                Buttons.Add(CancelButton);

                NSApplication.SharedApplication.RequestUserAttention(NSRequestUserAttentionType.CriticalRequest);
            }

            if (type == PageType.CryptoPassword)
            {
                Header      = "This project contains encrypted files";
                Description = "Please enter the password to see their contents.";

                PasswordLabel = new NSTextField()
                {
                    Alignment       = NSTextAlignment.Right,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF(155, Frame.Height - 224, 160, 17),
                    StringValue     = "Password:"******"Show password",
                    State = NSCellStateValue.Off
                };

                ShowPasswordCheckButton.SetButtonType(NSButtonType.Switch);

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

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


                Controller.UpdateCryptoPasswordContinueButtonEvent += delegate(bool button_enabled) {
                    InvokeOnMainThread(() => {
                        ContinueButton.Enabled = button_enabled;
                    });
                };

                ShowPasswordCheckButton.Activated += delegate {
                    if (PasswordTextField.Superview == ContentView)
                    {
                        PasswordTextField.RemoveFromSuperview();
                        ContentView.AddSubview(VisiblePasswordTextField);
                    }
                    else
                    {
                        VisiblePasswordTextField.RemoveFromSuperview();
                        ContentView.AddSubview(PasswordTextField);
                    }
                };

                (PasswordTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    VisiblePasswordTextField.StringValue = PasswordTextField.StringValue;
                    Controller.CheckCryptoPasswordPage(PasswordTextField.StringValue);
                };

                (VisiblePasswordTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    PasswordTextField.StringValue = VisiblePasswordTextField.StringValue;
                    Controller.CheckCryptoPasswordPage(PasswordTextField.StringValue);
                };

                ContinueButton.Activated += delegate {
                    Controller.CryptoPasswordPageCompleted(PasswordTextField.StringValue);
                };

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


                ContentView.AddSubview(PasswordLabel);
                ContentView.AddSubview(PasswordTextField);
                ContentView.AddSubview(ShowPasswordCheckButton);

                Buttons.Add(ContinueButton);
                Buttons.Add(CancelButton);

                NSApplication.SharedApplication.RequestUserAttention(NSRequestUserAttentionType.CriticalRequest);
            }


            if (type == PageType.Finished)
            {
                Header      = "Your shared project is ready!";
                Description = "You can find the files in your SparkleShare folder.";


                if (warnings.Length > 0)
                {
                    WarningImage      = NSImage.ImageNamed("NSInfo");
                    WarningImage.Size = new SizeF(24, 24);

                    WarningImageView = new NSImageView()
                    {
                        Image = WarningImage,
                        Frame = new RectangleF(200, Frame.Height - 175, 24, 24)
                    };

                    WarningTextField = new NSTextField()
                    {
                        Frame           = new RectangleF(235, Frame.Height - 245, 325, 100),
                        StringValue     = warnings [0],
                        BackgroundColor = NSColor.WindowBackground,
                        Bordered        = false,
                        Editable        = false,
                        Font            = SparkleUI.Font
                    };

                    ContentView.AddSubview(WarningImageView);
                    ContentView.AddSubview(WarningTextField);
                }


                OpenFolderButton = new NSButton()
                {
                    Title = "Show folder"
                };

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


                OpenFolderButton.Activated += delegate {
                    Controller.OpenFolderClicked();
                };

                FinishButton.Activated += delegate {
                    Controller.FinishPageCompleted();
                };


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

                NSApplication.SharedApplication.RequestUserAttention(NSRequestUserAttentionType.CriticalRequest);
            }

            if (type == PageType.Tutorial)
            {
                string slide_image_path = Path.Combine(NSBundle.MainBundle.ResourcePath,
                                                       "Pixmaps", "tutorial-slide-" + Controller.TutorialPageNumber + ".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);


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


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

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


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

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


                    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 automatically with " +
                                  "the host and your team members.";

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

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

                    Buttons.Add(ContinueButton);

                    break;
                }

                case 3: {
                    Header      = "The status icon is here to help";
                    Description = "It shows the syncing progress, provides easy access to " +
                                  "your projects and let's you view recent changes.";

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

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

                    Buttons.Add(ContinueButton);

                    break;
                }

                case 4: {
                    Header      = "Adding projects to SparkleShare";
                    Description = "You can do this through the status icon menu, or by clicking " +
                                  "magic buttons on webpages that look like this:";


                    StartupCheckButton = new NSButton()
                    {
                        Frame = new RectangleF(190, Frame.Height - 400, 300, 18),
                        Title = "Add SparkleShare to startup items",
                        State = NSCellStateValue.On
                    };

                    StartupCheckButton.SetButtonType(NSButtonType.Switch);

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

                    SlideImage.Size = new SizeF(350, 64);


                    StartupCheckButton.Activated += delegate {
                        Controller.StartupItemChanged(StartupCheckButton.State == NSCellStateValue.On);
                    };

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


                    ContentView.AddSubview(StartupCheckButton);
                    Buttons.Add(FinishButton);

                    break;
                }
                }
            }
        }
示例#28
0
        public SparkleSetup() : base()
        {
            Controller.HideWindowEvent += delegate {
                Application.Invoke(delegate {
                    HideAll();
                });
            };

            Controller.ShowWindowEvent += delegate {
                Application.Invoke(delegate {
                    ShowAll();
                    Present();
                });
            };

            Controller.ChangePageEvent += delegate(PageType type, string [] warnings) {
                Application.Invoke(delegate {
                    Reset();

                    switch (type)
                    {
                    case PageType.Setup: {
                        Header      = "Welcome to SparkleShare!";
                        Description = "First off, what's your name and email?\nThis information is only visible to team members.";

                        Table table = new Table(2, 3, true)
                        {
                            RowSpacing    = 6,
                            ColumnSpacing = 6
                        };

                        Label name_label = new Label("<b>" + "Full Name:" + "</b>")
                        {
                            UseMarkup = true,
                            Xalign    = 1
                        };

                        Entry name_entry = new Entry()
                        {
                            Xalign           = 0,
                            ActivatesDefault = true
                        };

                        UnixUserInfo user_info = UnixUserInfo.GetRealUser();

                        if (user_info != null && user_info.RealName != null)
                        {
                            name_entry.Text = user_info.RealName.TrimEnd(",".ToCharArray());
                        }

                        Entry email_entry = new Entry()
                        {
                            Xalign           = 0,
                            ActivatesDefault = true
                        };

                        name_entry.Changed += delegate {
                            Controller.CheckSetupPage(name_entry.Text, email_entry.Text);
                        };

                        email_entry.Changed += delegate {
                            Controller.CheckSetupPage(name_entry.Text, email_entry.Text);
                        };

                        Label email_label = new Label("<b>" + "Email:" + "</b>")
                        {
                            UseMarkup = true,
                            Xalign    = 1
                        };

                        table.Attach(name_label, 0, 1, 0, 1);
                        table.Attach(name_entry, 1, 2, 0, 1);
                        table.Attach(email_label, 0, 1, 1, 2);
                        table.Attach(email_entry, 1, 2, 1, 2);

                        VBox wrapper = new VBox(false, 9);
                        wrapper.PackStart(table, true, false, 0);

                        Button cancel_button = new Button("Cancel");

                        cancel_button.Clicked += delegate {
                            Controller.SetupPageCancelled();
                        };

                        Button continue_button = new Button("Continue")
                        {
                            Sensitive = false
                        };

                        continue_button.Clicked += delegate {
                            Controller.SetupPageCompleted(name_entry.Text, email_entry.Text);
                        };

                        AddButton(cancel_button);
                        AddButton(continue_button);
                        Add(wrapper);


                        Controller.UpdateSetupContinueButtonEvent += delegate(bool button_enabled) {
                            Application.Invoke(delegate {
                                    continue_button.Sensitive = button_enabled;
                                });
                        };

                        Controller.CheckSetupPage(name_entry.Text, email_entry.Text);

                        break;
                    }

                    case PageType.Add: {
                        Header = "Where's your project hosted?";

                        VBox layout_vertical = new VBox(false, 12);
                        HBox layout_fields   = new HBox(true, 12);
                        VBox layout_address  = new VBox(true, 0);
                        VBox layout_path     = new VBox(true, 0);


                        ListStore store = new ListStore(typeof(Gdk.Pixbuf),
                                                        typeof(string), typeof(SparklePlugin));

                        SparkleTreeView tree = new SparkleTreeView(store)
                        {
                            HeadersVisible = false
                        };
                        ScrolledWindow scrolled_window = new ScrolledWindow();
                        scrolled_window.AddWithViewport(tree);

                        // Icon column
                        tree.AppendColumn("Icon", new Gtk.CellRendererPixbuf(), "pixbuf", 0);
                        tree.Columns [0].Cells [0].Xpad = 6;

                        // Service column
                        TreeViewColumn service_column = new TreeViewColumn()
                        {
                            Title = "Service"
                        };
                        CellRendererText service_cell = new CellRendererText()
                        {
                            Ypad = 4
                        };
                        service_column.PackStart(service_cell, true);
                        service_column.SetCellDataFunc(service_cell, new TreeCellDataFunc(RenderServiceColumn));

                        foreach (SparklePlugin plugin in Controller.Plugins)
                        {
                            store.AppendValues(
                                new Gdk.Pixbuf(plugin.ImagePath),
                                "<span size=\"small\"><b>" + plugin.Name + "</b>\n" +
                                "<span fgcolor=\"" + SecondaryTextColorSelected + "\">" +
                                plugin.Description + "</span>" +
                                "</span>",
                                plugin);
                        }

                        tree.AppendColumn(service_column);

                        Entry address_entry = new Entry()
                        {
                            Text             = Controller.PreviousAddress,
                            Sensitive        = (Controller.SelectedPlugin.Address == null),
                            ActivatesDefault = true
                        };

                        Entry path_entry = new Entry()
                        {
                            Text             = Controller.PreviousPath,
                            Sensitive        = (Controller.SelectedPlugin.Path == null),
                            ActivatesDefault = true
                        };

                        Label address_example = new Label()
                        {
                            Xalign    = 0,
                            UseMarkup = true,
                            Markup    = "<span size=\"small\" fgcolor=\"" +
                                        SecondaryTextColor + "\">" + Controller.SelectedPlugin.AddressExample + "</span>"
                        };

                        Label path_example = new Label()
                        {
                            Xalign    = 0,
                            UseMarkup = true,
                            Markup    = "<span size=\"small\" fgcolor=\"" +
                                        SecondaryTextColor + "\">" + Controller.SelectedPlugin.PathExample + "</span>"
                        };


                        // Select the first plugin by default
                        TreeSelection default_selection = tree.Selection;
                        TreePath default_path           = new TreePath("0");
                        default_selection.SelectPath(default_path);
                        Controller.SelectedPluginChanged(0);

                        Controller.ChangeAddressFieldEvent += delegate(string text,
                                                                       string example_text, FieldState state) {
                            Application.Invoke(delegate {
                                    address_entry.Text      = text;
                                    address_entry.Sensitive = (state == FieldState.Enabled);
                                    address_example.Markup  = "<span size=\"small\" fgcolor=\"" +
                                                              SecondaryTextColor + "\">" + example_text + "</span>";
                                });
                        };

                        Controller.ChangePathFieldEvent += delegate(string text,
                                                                    string example_text, FieldState state) {
                            Application.Invoke(delegate {
                                    path_entry.Text      = text;
                                    path_entry.Sensitive = (state == FieldState.Enabled);
                                    path_example.Markup  = "<span size=\"small\" fgcolor=\""
                                                           + SecondaryTextColor + "\">" + example_text + "</span>";
                                });
                        };

                        Controller.CheckAddPage(address_entry.Text, path_entry.Text, 1);

                        // Update the address field text when the selection changes
                        tree.CursorChanged += delegate(object sender, EventArgs e) {
                            Controller.SelectedPluginChanged(tree.SelectedRow);
                            // TODO: Scroll to selected row when using arrow keys
                        };

                        tree.Model.Foreach(new TreeModelForeachFunc(delegate(TreeModel model,
                                                                             TreePath path, TreeIter iter) {
                                string address;

                                try {
                                    address = (model.GetValue(iter, 2) as SparklePlugin).Address;
                                } catch (NullReferenceException) {
                                    address = "";
                                }

                                if (!string.IsNullOrEmpty(address) &&
                                    address.Equals(Controller.PreviousAddress))
                                {
                                    tree.SetCursor(path, service_column, false);
                                    SparklePlugin plugin = (SparklePlugin)model.GetValue(iter, 2);

                                    if (plugin.Address != null)
                                    {
                                        address_entry.Sensitive = false;
                                    }

                                    if (plugin.Path != null)
                                    {
                                        path_entry.Sensitive = false;
                                    }

                                    // TODO: Scroll to the selection

                                    return(true);
                                }
                                else
                                {
                                    return(false);
                                }
                            }));


                        address_entry.Changed += delegate {
                            Controller.CheckAddPage(address_entry.Text, path_entry.Text, tree.SelectedRow);
                        };

                        layout_address.PackStart(new Label()
                            {
                                Markup = "<b>" + "Address:" + "</b>",
                                Xalign = 0
                            }, true, true, 0);

                        layout_address.PackStart(address_entry, false, false, 0);
                        layout_address.PackStart(address_example, false, false, 0);

                        path_entry.Changed += delegate {
                            Controller.CheckAddPage(address_entry.Text, path_entry.Text, tree.SelectedRow);
                        };

                        layout_path.PackStart(new Label()
                            {
                                Markup = "<b>" + "Remote Path:" + "</b>",
                                Xalign = 0
                            }, true, true, 0);

                        layout_path.PackStart(path_entry, false, false, 0);
                        layout_path.PackStart(path_example, false, false, 0);

                        layout_fields.PackStart(layout_address);
                        layout_fields.PackStart(layout_path);

                        layout_vertical.PackStart(new Label(""), false, false, 0);
                        layout_vertical.PackStart(scrolled_window, true, true, 0);
                        layout_vertical.PackStart(layout_fields, false, false, 0);

                        Add(layout_vertical);

                        // Cancel button
                        Button cancel_button = new Button("Cancel");

                        cancel_button.Clicked += delegate {
                            Controller.PageCancelled();
                        };

                        Button add_button = new Button("Add")
                        {
                            Sensitive = false
                        };

                        add_button.Clicked += delegate {
                            Controller.AddPageCompleted(address_entry.Text, path_entry.Text);
                        };

                        Controller.UpdateAddProjectButtonEvent += delegate(bool button_enabled) {
                            Application.Invoke(delegate {
                                    add_button.Sensitive = button_enabled;
                                });
                        };


                        CheckButton check_button = new CheckButton("Fetch prior history")
                        {
                            Active = false
                        };

                        check_button.Toggled += delegate {
                            Controller.HistoryItemChanged(check_button.Active);
                        };

                        AddOption(check_button);
                        AddButton(cancel_button);
                        AddButton(add_button);

                        Controller.CheckAddPage(address_entry.Text, path_entry.Text, 1);

                        break;
                    }

                    case PageType.Invite: {
                        Header      = "You've received an invite!";
                        Description = "Do you want to add this project to SparkleShare?";


                        Table table = new Table(2, 3, true)
                        {
                            RowSpacing    = 6,
                            ColumnSpacing = 6
                        };

                        Label address_label = new Label("Address:")
                        {
                            Xalign = 1
                        };

                        Label path_label = new Label("Remote Path:")
                        {
                            Xalign = 1
                        };

                        Label address_value = new Label("<b>" + Controller.PendingInvite.Address + "</b>")
                        {
                            UseMarkup = true,
                            Xalign    = 0
                        };

                        Label path_value = new Label("<b>" + Controller.PendingInvite.RemotePath + "</b>")
                        {
                            UseMarkup = true,
                            Xalign    = 0
                        };

                        table.Attach(address_label, 0, 1, 0, 1);
                        table.Attach(address_value, 1, 2, 0, 1);
                        table.Attach(path_label, 0, 1, 1, 2);
                        table.Attach(path_value, 1, 2, 1, 2);

                        VBox wrapper = new VBox(false, 9);
                        wrapper.PackStart(table, true, false, 0);

                        Button cancel_button = new Button("Cancel");

                        cancel_button.Clicked += delegate {
                            Controller.PageCancelled();
                        };

                        Button add_button = new Button("Add");

                        add_button.Clicked += delegate {
                            Controller.InvitePageCompleted();
                        };

                        AddButton(cancel_button);
                        AddButton(add_button);
                        Add(wrapper);

                        break;
                    }

                    case PageType.Syncing: {
                        Header      = String.Format("Adding project ‘{0}’…", Controller.SyncingFolder);
                        Description = "This may take a while for large projects.\nIsn't it coffee-o'clock?";

                        this.progress_bar.Fraction = Controller.ProgressBarPercentage / 100;

                        Button finish_button = new Button()
                        {
                            Sensitive = false,
                            Label     = "Finish"
                        };

                        Button cancel_button = new Button()
                        {
                            Label = "Cancel"
                        };

                        cancel_button.Clicked += delegate {
                            Controller.SyncingCancelled();
                        };

                        AddButton(cancel_button);
                        AddButton(finish_button);

                        Controller.UpdateProgressBarEvent += delegate(double percentage) {
                            Application.Invoke(delegate {
                                    this.progress_bar.Fraction = percentage / 100;
                                });
                        };

                        if (this.progress_bar.Parent != null)
                        {
                            (this.progress_bar.Parent as Container).Remove(this.progress_bar);
                        }

                        VBox bar_wrapper = new VBox(false, 0);
                        bar_wrapper.PackStart(this.progress_bar, false, false, 15);

                        Add(bar_wrapper);

                        break;
                    }

                    case PageType.Error: {
                        Header = "Oops! Something went wrong" + "…";

                        VBox points            = new VBox(false, 0);
                        Image list_point_one   = new Image(SparkleUIHelpers.GetIcon("list-point", 16));
                        Image list_point_two   = new Image(SparkleUIHelpers.GetIcon("list-point", 16));
                        Image list_point_three = new Image(SparkleUIHelpers.GetIcon("list-point", 16));

                        Label label_one = new Label()
                        {
                            Markup = "<b>" + Controller.PreviousUrl + "</b> is the address we've compiled. " +
                                     "Does this look alright?",
                            Wrap   = true,
                            Xalign = 0
                        };

                        Label label_two = new Label()
                        {
                            Text   = "Do you have access rights to this remote project?",
                            Wrap   = true,
                            Xalign = 0
                        };

                        points.PackStart(new Label("Please check the following:")
                            {
                                Xalign = 0
                            }, false, false, 6);

                        HBox point_one = new HBox(false, 0);
                        point_one.PackStart(list_point_one, false, false, 0);
                        point_one.PackStart(label_one, true, true, 12);
                        points.PackStart(point_one, false, false, 12);

                        HBox point_two = new HBox(false, 0);
                        point_two.PackStart(list_point_two, false, false, 0);
                        point_two.PackStart(label_two, true, true, 12);
                        points.PackStart(point_two, false, false, 12);

                        if (warnings.Length > 0)
                        {
                            string warnings_markup = "";

                            foreach (string warning in warnings)
                            {
                                warnings_markup += "\n<b>" + warning + "</b>";
                            }

                            Label label_three = new Label()
                            {
                                Markup = "Here's the raw error message:" + warnings_markup,
                                Wrap   = true,
                                Xalign = 0
                            };

                            HBox point_three = new HBox(false, 0);
                            point_three.PackStart(list_point_three, false, false, 0);
                            point_three.PackStart(label_three, true, true, 12);
                            points.PackStart(point_three, false, false, 12);
                        }

                        points.PackStart(new Label(""), true, true, 0);

                        Button cancel_button = new Button("Cancel");

                        cancel_button.Clicked += delegate {
                            Controller.PageCancelled();
                        };

                        Button try_again_button = new Button("Try Again…")
                        {
                            Sensitive = true
                        };

                        try_again_button.Clicked += delegate {
                            Controller.ErrorPageCompleted();
                        };

                        AddButton(cancel_button);
                        AddButton(try_again_button);
                        Add(points);

                        break;
                    }

                    case PageType.CryptoSetup: {
                        Header      = "Set up file encryption";
                        Description = "Please a provide a strong password that you don't use elsewhere below:";

                        Label password_label = new Label("<b>" + "Password:"******"</b>")
                        {
                            UseMarkup = true,
                            Xalign    = 1
                        };

                        Entry password_entry = new Entry()
                        {
                            Xalign           = 0,
                            Visibility       = false,
                            ActivatesDefault = true
                        };

                        CheckButton show_password_check_button = new CheckButton("Show password")
                        {
                            Active = false,
                            Xalign = 0,
                        };

                        show_password_check_button.Toggled += delegate {
                            password_entry.Visibility = !password_entry.Visibility;
                        };

                        password_entry.Changed += delegate {
                            Controller.CheckCryptoSetupPage(password_entry.Text);
                        };


                        Button continue_button = new Button("Continue")
                        {
                            Sensitive = false
                        };

                        continue_button.Clicked += delegate {
                            Controller.CryptoSetupPageCompleted(password_entry.Text);
                        };

                        Button cancel_button = new Button("Cancel");

                        cancel_button.Clicked += delegate {
                            Controller.CryptoPageCancelled();
                        };

                        Controller.UpdateCryptoSetupContinueButtonEvent += delegate(bool button_enabled) {
                            Application.Invoke(delegate {
                                    continue_button.Sensitive = button_enabled;
                                });
                        };


                        Table table = new Table(2, 3, true)
                        {
                            RowSpacing    = 6,
                            ColumnSpacing = 6
                        };


                        table.Attach(password_label, 0, 1, 0, 1);
                        table.Attach(password_entry, 1, 2, 0, 1);

                        table.Attach(show_password_check_button, 1, 2, 1, 2);

                        VBox wrapper = new VBox(false, 9);
                        wrapper.PackStart(table, true, false, 0);


                        Image warning_image = new Image(
                            SparkleUIHelpers.GetIcon("dialog-information", 24)
                            );

                        Label warning_label = new Label()
                        {
                            Xalign = 0,
                            Wrap   = true,
                            Text   = "This password can't be changed later, and your files can't be recovered if it's forgotten."
                        };

                        HBox warning_layout = new HBox(false, 0);
                        warning_layout.PackStart(warning_image, false, false, 15);
                        warning_layout.PackStart(warning_label, true, true, 0);

                        VBox warning_wrapper = new VBox(false, 0);
                        warning_wrapper.PackStart(warning_layout, false, false, 15);

                        wrapper.PackStart(warning_wrapper, false, false, 0);


                        Add(wrapper);



                        AddButton(cancel_button);
                        AddButton(continue_button);

                        break;
                    }

                    case PageType.CryptoPassword: {
                        Header      = "This project contains encrypted files";
                        Description = "Please enter the password to see their contents.";

                        Label password_label = new Label("<b>" + "Password:"******"</b>")
                        {
                            UseMarkup = true,
                            Xalign    = 1
                        };

                        Entry password_entry = new Entry()
                        {
                            Xalign           = 0,
                            Visibility       = false,
                            ActivatesDefault = true
                        };

                        CheckButton show_password_check_button = new CheckButton("Show password")
                        {
                            Active = false,
                            Xalign = 0
                        };

                        show_password_check_button.Toggled += delegate {
                            password_entry.Visibility = !password_entry.Visibility;
                        };

                        password_entry.Changed += delegate {
                            Controller.CheckCryptoPasswordPage(password_entry.Text);
                        };


                        Button continue_button = new Button("Continue")
                        {
                            Sensitive = false
                        };

                        continue_button.Clicked += delegate {
                            Controller.CryptoPasswordPageCompleted(password_entry.Text);
                        };

                        Button cancel_button = new Button("Cancel");

                        cancel_button.Clicked += delegate {
                            Controller.CryptoPageCancelled();
                        };

                        Controller.UpdateCryptoPasswordContinueButtonEvent += delegate(bool button_enabled) {
                            Application.Invoke(delegate {
                                    continue_button.Sensitive = button_enabled;
                                });
                        };

                        Table table = new Table(2, 3, true)
                        {
                            RowSpacing    = 6,
                            ColumnSpacing = 6
                        };

                        table.Attach(password_label, 0, 1, 0, 1);
                        table.Attach(password_entry, 1, 2, 0, 1);

                        table.Attach(show_password_check_button, 1, 2, 1, 2);

                        VBox wrapper = new VBox(false, 9);
                        wrapper.PackStart(table, true, false, 0);

                        Add(wrapper);

                        AddButton(cancel_button);
                        AddButton(continue_button);

                        break;
                    }

                    case PageType.Finished: {
                        UrgencyHint = true;

                        if (!HasToplevelFocus)
                        {
                            string title   = "Your shared project is ready!";
                            string subtext = "You can find the files in your SparkleShare folder.";

                            Program.UI.Bubbles.Controller.ShowBubble(title, subtext, null);
                        }

                        Header      = "Your shared project is ready!";
                        Description = "You can find it in your SparkleShare folder";

                        // A button that opens the synced folder
                        Button show_files_button = new Button("Show Files…");

                        show_files_button.Clicked += delegate {
                            Controller.ShowFilesClicked();
                        };

                        Button finish_button = new Button("Finish");

                        finish_button.Clicked += delegate {
                            Controller.FinishPageCompleted();
                        };


                        if (warnings.Length > 0)
                        {
                            Image warning_image = new Image(
                                SparkleUIHelpers.GetIcon("dialog-information", 24));

                            Label warning_label = new Label(warnings [0])
                            {
                                Xalign = 0,
                                Wrap   = true
                            };

                            HBox warning_layout = new HBox(false, 0);
                            warning_layout.PackStart(warning_image, false, false, 15);
                            warning_layout.PackStart(warning_label, true, true, 0);

                            VBox warning_wrapper = new VBox(false, 0);
                            warning_wrapper.PackStart(warning_layout, false, false, 0);

                            Add(warning_wrapper);
                        }
                        else
                        {
                            Add(null);
                        }


                        AddButton(show_files_button);
                        AddButton(finish_button);

                        break;
                    }


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

                            Button skip_tutorial_button   = new Button("Skip Tutorial");
                            skip_tutorial_button.Clicked += delegate {
                                Controller.TutorialSkipped();
                            };

                            Button continue_button   = new Button("Continue");
                            continue_button.Clicked += delegate {
                                Controller.TutorialPageCompleted();
                            };

                            Image slide = SparkleUIHelpers.GetImage("tutorial-slide-1.png");

                            Add(slide);

                            AddButton(skip_tutorial_button);
                            AddButton(continue_button);

                            break;
                        }

                        case 2: {
                            Header      = "Sharing files with others";
                            Description = "All files added to your project folders are synced automatically with " +
                                          "the host and your team members.";

                            Button continue_button   = new Button("Continue");
                            continue_button.Clicked += delegate {
                                Controller.TutorialPageCompleted();
                            };

                            Image slide = SparkleUIHelpers.GetImage("tutorial-slide-2.png");

                            Add(slide);
                            AddButton(continue_button);

                            break;
                        }

                        case 3: {
                            Header      = "The status icon helps you";
                            Description = "It shows the syncing progress, provides easy access to " +
                                          "your projects and let's you view recent changes.";

                            Button continue_button   = new Button("Continue");
                            continue_button.Clicked += delegate {
                                Controller.TutorialPageCompleted();
                            };

                            Image slide = SparkleUIHelpers.GetImage("tutorial-slide-3.png");

                            Add(slide);
                            AddButton(continue_button);

                            break;
                        }

                        case 4: {
                            Header      = "Here's your unique link code";
                            Description = "You'll need it whenever you want to link this computer to a host" +
                                          " (we keep a copy in your SparkleShare folder).";


                            Button finish_button = new Button("Finish");

                            VBox layout_vertical = new VBox(false, 0)
                            {
                                BorderWidth = 48
                            };

                            HBox layout_horizontal = new HBox(false, 6);

                            Entry link_code_entry = new Entry()
                            {
                                Text      = Program.Controller.CurrentUser.PublicKey,
                                Sensitive = false
                            };

                            Button copy_button = new Button(" Copy ");

                            CheckButton check_button = new CheckButton("Add SparkleShare to startup items")
                            {
                                Active = true
                            };


                            check_button.Toggled += delegate {
                                Controller.StartupItemChanged(check_button.Active);
                            };

                            copy_button.Clicked += delegate {
                                Clipboard clip_board = Clipboard.Get(Gdk.Atom.Intern("CLIPBOARD", false));
                                clip_board.Text      = link_code_entry.Text;
                            };

                            finish_button.Clicked += delegate {
                                Controller.TutorialPageCompleted();
                            };


                            layout_horizontal.PackStart(link_code_entry, true, true, 0);
                            layout_horizontal.PackStart(copy_button, false, false, 0);

                            layout_vertical.PackStart(new Label(""), true, true, 0);
                            layout_vertical.PackStart(layout_horizontal, false, false, 0);
                            layout_vertical.PackStart(new Label(""), true, true, 18);

                            Add(layout_vertical);

                            AddOption(check_button);
                            AddButton(finish_button);

                            break;
                        }
                        }

                        break;
                    }
                    }

                    ShowAll();
                });
            };
        }
示例#29
0
        private static void ExecuteLogin()
        {
            using var services = CreateServices();

            // Enable logging
            var loggerFactory = services.GetRequiredService <ILoggerFactory>();

            loggerFactory.AddSyslog(new SyslogLoggerSettings()
            {
                MessageTransportProtocol = TransportProtocol.UnixSocket,
                UnixSocketPath           = "/dev/log",
            });

            var hostName = services.GetRequiredService <HostNameAccessor>().GetHostName();

            var rootInfo = new RootUserInfo();

            Console.Clear();

            while (true)
            {
                var service        = services.GetRequiredService <IPamService>();
                var messageHandler = services.GetRequiredService <IPamMessageHandler>();
                using var transaction  = service.Start(messageHandler);
                transaction.UserPrompt = $"{hostName} login: "******"No shell specified. Login not possible.");
                    }

                    transaction.OpenSession();
                    try
                    {
                        // Start the shell
                        ProcessStartInfo startInfo;
                        if (rootInfo.IsRoot || rootInfo.IsSudo)
                        {
                            startInfo = new ProcessStartInfo("sudo", $"-i -u #{userInfo.UserId}")
                            {
                                WorkingDirectory = userInfo.HomeDirectory,
                            };
                        }
                        else
                        {
                            if (userInfo.UserId != rootInfo.Info.UserId)
                            {
                                throw new InvalidOperationException(
                                          "A non-root user can only \"login\" with its own credentials.");
                            }
                            else
                            {
                                startInfo = new ProcessStartInfo(userInfo.ShellProgram, "-pl")
                                {
                                    WorkingDirectory = userInfo.HomeDirectory,
                                };
                            }
                        }

                        using var proc = Process.Start(startInfo);
                        if (proc == null)
                        {
                            throw new InvalidOperationException("The shell couldn't be started.");
                        }

                        proc.WaitForExit();
                    }
                    finally
                    {
                        transaction.CloseSession();
                    }

                    // Clear after logout
                    Console.Clear();
                }
                catch (Exception exception)
                {
                    var realException = UnwindException(exception);
                    Console.Error.WriteLine(realException.Message);
                }
            }

            // ReSharper disable once FunctionNeverReturns
        }
示例#30
0
        public static string CollectFilePermissionInformation(string filePath)
        {
            var bldr = new StringBuilder();

            try
            {
                if (Platform.IsWindows)
                {
                    var currentUser = WindowsIdentity.GetCurrent();
                    bldr.AppendLine($"current user is {currentUser.Name}");
                    var              principal          = new WindowsPrincipal(currentUser);
                    bool             isInRoleWithAccess = false;
                    bool             accessDenied       = false;
                    bool             accessAllowed      = false;
                    FileSystemRights accessRights       = FileSystemRights.Write;
                    var              acl   = File.GetAccessControl(filePath);
                    var              rules = acl.GetAccessRules(true, true, typeof(NTAccount));
                    var              sid   = acl.GetOwner(typeof(SecurityIdentifier));
                    var              acct  = sid.Translate(typeof(NTAccount)) as NTAccount;
                    if (acct != null)
                    {
                        bldr.AppendLine($"owner of \"{filePath}\" is {acct.Value}");
                    }
                    var fileAttributes = RobustFile.GetAttributes(filePath);
                    bldr.AppendLine($"{filePath} current ReadOnly attribute of {filePath} is {(fileAttributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly}");
                    foreach (AuthorizationRule rule in rules)
                    {
                        var fsAccessRule = rule as FileSystemAccessRule;
                        if (fsAccessRule == null)
                        {
                            continue;
                        }
                        if ((fsAccessRule.FileSystemRights & accessRights) > 0)
                        {
                            var ntAccount = rule.IdentityReference as NTAccount;
                            if (ntAccount == null)
                            {
                                continue;
                            }
                            if (principal.IsInRole(ntAccount.Value))
                            {
                                if (fsAccessRule.AccessControlType == AccessControlType.Deny)
                                {
                                    bldr.AppendLine($"current user is denied write access to {filePath} by {ntAccount.Value}{(rule.IsInherited ? " (inherited)":"")}");
                                    accessDenied = true;
                                }
                                if (fsAccessRule.AccessControlType == AccessControlType.Allow)
                                {
                                    bldr.AppendLine($"current user is allowed write access to {filePath} by {ntAccount.Value}{(rule.IsInherited ? " (inherited)":"")}");
                                    accessAllowed = true;
                                }
                                isInRoleWithAccess = true;
                            }
                        }
                    }
                    if (isInRoleWithAccess)
                    {
                        if (!accessAllowed)
                        {
                            bldr.AppendLine($"current user is not explicitly allowed write access to {filePath}");
                        }
                        if (!accessDenied)
                        {
                            bldr.AppendLine($"current user is not explicitly denied write access to {filePath}");
                        }
                    }
                    else
                    {
                        bldr.AppendLine($"current user is not explicitly given access to {filePath}");
                    }
                }
                else
                {
                    var folder   = Path.GetDirectoryName(filePath);
                    var fileInfo = new UnixFileInfo(filePath);
                    var dirInfo  = new UnixDirectoryInfo(folder);
                    var userInfo = UnixUserInfo.GetRealUser();
                    bldr.AppendLine($"current user is {userInfo.UserName}");
                    bldr.AppendLine($"owner of \"{filePath}\" is {fileInfo.OwnerUser.UserName}");
                    bldr.AppendLine($"permissions of \"{filePath}\" = {fileInfo.FileAccessPermissions.ToString()}");
                    bldr.AppendLine($"owner of \"{folder}\" is {dirInfo.OwnerUser.UserName}");
                    bldr.AppendLine($"permissions of \"{folder}\" = {dirInfo.FileAccessPermissions.ToString()}");
                }
            }
            catch (Exception e)
            {
                bldr.AppendLine($"Caught exception {e} while trying to collect information about {filePath}");
            }
            return(bldr.ToString());
        }