Пример #1
0
        private void EditLink_Load(object sender, EventArgs e)
        {
            LocationBox.Text = Trust.Core.User.Settings.Location;

            OpLink link = Trust.GetLink(Core.UserID, ProjectID);

            //if (link != null)
            //    TitleBox.Text = link.Title;
        }
Пример #2
0
        public void GetMenuInfo(InterfaceMenuType menuType, List <MenuItemInfo> menus, ulong user, uint project)
        {
            if (menuType != InterfaceMenuType.Quick)
            {
                return;
            }

            bool unlink = false;

            OpLink remoteLink = Trust.GetLink(user, project);
            OpLink localLink  = Trust.LocalTrust.GetLink(project);

            if (remoteLink == null)
            {
                return;
            }

            // linkup
            if (Core.UserID != user &&
                (localLink == null ||
                 localLink.Uplink == null ||
                 localLink.Uplink.UserID != user)) // not already linked to
            {
                menus.Add(new MenuItemInfo("Trust", LinkRes.linkup, new EventHandler(Menu_Linkup)));
            }

            if (localLink == null)
            {
                return;
            }

            // confirm
            if (localLink.Downlinks.Contains(remoteLink))
            {
                unlink = true;

                if (!localLink.Confirmed.Contains(user)) // not already confirmed
                {
                    menus.Add(new MenuItemInfo("Accept Trust", LinkRes.linkup, new EventHandler(Menu_ConfirmLink)));
                }
            }

            // unlink
            if ((unlink && localLink.Confirmed.Contains(user)) ||
                (localLink.Uplink != null && localLink.Uplink.UserID == user))
            {
                menus.Add(new MenuItemInfo("Revoke Trust", LinkRes.unlink, new EventHandler(Menu_Unlink)));
            }
        }
Пример #3
0
        void Trust_Update(ulong key)
        {
            // copied from linkTree's source
            OpLink link = Trust.GetLink(key, ProjectID);

            if (link == null)
            {
                if (NodeMap.ContainsKey(key))
                {
                    RemoveNode(NodeMap[key]);
                }

                return;
            }

            /*above should do this now
             * if (!link.Projects.Contains(ProjectID) && !link.Downlinks.ContainsKey(ProjectID))
             * {
             *  if (NodeMap.ContainsKey(key))
             *      RemoveNode(NodeMap[key]);
             *
             *  return;
             * }*/

            PlanNode node = null;

            if (NodeMap.ContainsKey(key))
            {
                node = NodeMap[key];
            }

            TreeListNode parent = null;
            OpLink       uplink = GetTreeHigher(link);

            if (uplink == null)
            {
                parent = PlanStructure.virtualParent;
            }

            else if (NodeMap.ContainsKey(uplink.UserID))
            {
                parent = NodeMap[uplink.UserID];
            }

            else if (uplink.IsLoopRoot)
            {
                parent = new TreeListNode(); // ensures that tree is refreshed
            }
            // if nodes status unchanged
            if (node != null && parent != null && node.Parent == parent)
            {
                node.UpdateName();
                Invalidate();
                return;
            }

            // only if parent is visible
            if (parent != null)
            {
                RefreshUplinks();
                RefreshStructure();
            }

            ////////////////////////////////////////////////////////////////////

            /*
             * // update uplinks
             * if (key == DhtID || Uplinks.Contains(key))
             *  RefreshUplinks();
             *
             *
             * // create a node item, or get the current one
             * PlanNode node = null;
             *
             * if (NodeMap.ContainsKey(key))
             *  node = NodeMap[key];
             * else
             *  node = new PlanNode(this, link, key == DhtID);
             *
             *
             * // get the right parent node for this item
             * TreeListNode parent = null;
             *
             * OpLink parentLink = link.GetHigher(ProjectID, false);
             *
             * if (parentLink == null) // dont combine below, causes next if to fail
             *  parent = Uplinks.Contains(key) ? PlanStructure.virtualParent : null;
             *
             * else if (NodeMap.ContainsKey(parentLink.DhtID))
             *  parent = NodeMap[parentLink.DhtID];
             *
             * else
             *  parent = null; // branch this link is apart of is not visible in current display
             *
             *
             * // remember settings
             * bool selected = node.Selected;
             *
             *
             * if (node.Parent != parent)
             * {
             *  List<ulong> visible = new List<ulong>();
             *
             *  // remove previous instance of node
             *  if (node.Parent != null)
             *  {
             *      if (node.IsVisible())
             *          visible.Add(link.DhtID);
             *
             *      UnloadNode(node, visible);
             *      NodeMap.Remove(link.DhtID);
             *      node.Remove();
             *  }
             *
             *
             *  // if node changes to be sub of another root 3 levels down, whole branch must be reloaded
             *  if (parent == null || parent == PlanStructure.virtualParent)
             *  {
             *      if(Uplinks.Contains(key))
             *          RefreshStructure();
             *
             *      return;
             *  }
             *
             *  // if new parent is hidden, dont bother adding till user expands
             *  PlanNode newParent = parent as PlanNode; // null if root
             *
             *  if (newParent != null && newParent.AddSubs == false)
             *      return;
             *
             *
             *  // copy node to start fresh
             *  PlanNode newNode = CreateNode(node.Link);
             *
             *
             *  // check if parent should be moved to project header
             *  if (newParent != null)
             *  {
             *      Utilities.InsertSubNode(newParent, newNode);
             *
             *      // if we are a visible child, must load hidden sub nodes
             *      if (newParent.IsVisible() && newParent.IsExpanded)
             *          LoadNode(newNode);
             *  }
             *
             *  // if node itself is the root
             *  else
             *  {
             *      LoadNode(newNode);
             *
             *      // remove previous
             *      foreach (PlanNode old in PlanStructure.Nodes)
             *          UnloadNode(old, visible);
             *
             *      PlanStructure.Nodes.Clear();
             *      PlanStructure.Nodes.Add(newNode);
             *  }
             *
             *  node = newNode;
             *
             *
             *  // recurse to each previously visible node
             *  foreach (ulong id in visible)
             *  {
             *      List<ulong> uplinks = Links.GetUplinkIDs(id, ProjectID);
             *
             *      foreach (PlanNode root in PlanStructure.Nodes) // should only be one root
             *          VisiblePath(root, uplinks);
             *  }
             * }
             *
             * node.UpdateName();
             *
             *
             * node.Selected = selected;*/
        }
Пример #4
0
        private void RefreshOperationTree()
        {
            BeginUpdate();

            // save selected
            LinkNode selected = GetSelected();

            // save visible while unloading
            List <ulong> visible = new List <ulong>();

            foreach (TreeListNode node in Nodes)
            {
                if (node.GetType() == typeof(LinkNode))
                {
                    UnloadNode((LinkNode)node, visible);
                }
            }

            NodeMap.Clear();
            Nodes.Clear();

            // white space
            if (FirstLineBlank)
            {
                Nodes.Add(new LabelNode(""));
            }

            if (!Trust.ProjectRoots.SafeContainsKey(Project))
            {
                EndUpdate();
                return;
            }

            string rootname = Core.User.Settings.Operation;

            if (Project != 0)
            {
                rootname = Trust.GetProjectName(Project);
            }

            // operation
            ProjectNode      = new ProjectNode(rootname, Project);
            ProjectNode.Font = TrustedFont;
            Nodes.Add(ProjectNode);

            // white space
            Nodes.Add(new LabelNode(""));

            // unlinked
            UnlinkedNode      = new ProjectNode("Untrusted", 0);
            UnlinkedNode.Font = UntrustedFont;

            Nodes.Add(UnlinkedNode);


            // if forced, load specific node as root
            if (ForceRootID != 0)
            {
                OpLink root = Trust.GetLink(ForceRootID, Project);

                if (root != null)
                {
                    SetupRoot(root);
                }
            }

            // get roots for specific project
            else
            {
                ThreadedList <OpLink> roots = null;
                if (Trust.ProjectRoots.SafeTryGetValue(Project, out roots))
                {
                    roots.LockReading(delegate()
                    {
                        foreach (OpLink root in roots)
                        {
                            SetupRoot(root);
                        }
                    });
                }
            }

            // show unlinked if there's something to show
            if (Nodes.IndexOf(UnlinkedNode) + 1 == Nodes.Count)
            {
                UnlinkedNode.Text = "";
            }
            else
            {
                UnlinkedNode.Text = "Untrusted";
            }

            // restore visible
            foreach (ulong id in visible)
            {
                foreach (TreeListNode node in Nodes)
                {
                    if (node.GetType() == typeof(LinkNode))
                    {
                        List <ulong> uplinks = Trust.GetUnconfirmedUplinkIDs(id, Project);
                        uplinks.Add(id);
                        VisiblePath((LinkNode)node, uplinks);
                    }
                }
            }

            // restore selected
            if (selected != null)
            {
                if (NodeMap.ContainsKey(selected.Link.UserID))
                {
                    Select(NodeMap[selected.Link.UserID]);
                }
            }

            EndUpdate();
        }