Пример #1
0
        /// <summary>
        /// Opens the database.
        /// </summary>
        /// <param name='filePath'>
        /// File path.
        /// </param>
        /// <param name='password'>
        /// Password.
        /// </param>
        private void OpenDatabase(string filePath, string password)
        {
            try
            {
                StartProgress("Opening password database...");
                databaseCommands.OpenDatabase(filePath, password);

                // store the path of this db..
                NSUserDefaults userDefaults = NSUserDefaults.StandardUserDefaults;
                userDefaults.SetString(filePath, "lastdbpath");
            }
            catch (Exception ex)
            {
                NSAlert alert = new NSAlert();
                alert.AlertStyle  = NSAlertStyle.Critical;
                alert.MessageText = ex.Message;
//            alert.AddButton("Yes");
//            alert.AddButton("No");
                alert.RunModal();

                return;
            }
            finally
            {
                EndProgress();
            }



            //SetupSidebar();
            TreeGroupModel groups = databaseCommands.FindGroups();

            FillGroups(groups);
        }
Пример #2
0
        public TreeGroupModel FindGroups()
        {
            TreeGroupModel model         = new TreeGroupModel();
            DateTime       m_dtCachedNow = DateTime.Now;
            GroupModel     root          = null;

            // add root if exists
            if (db.RootGroup != null)
            {
                int nIconID = ((!db.RootGroup.CustomIconUuid.EqualsValue(PwUuid.Zero)) ?
                               ((int)PwIcon.Count + db.GetCustomIconIndex(
                                    db.RootGroup.CustomIconUuid)) : (int)db.RootGroup.IconId);

                if (db.RootGroup.Expires && (db.RootGroup.ExpiryTime <= m_dtCachedNow))
                {
                    nIconID = (int)PwIcon.Expired;
                }

                root = new GroupModel()
                {
                    Name               = db.RootGroup.Name,
                    ImageIndex         = nIconID,
                    SelectedImageIndex = nIconID,
                    Group              = db.RootGroup,
                    Expires            = db.RootGroup.Expires,
                    ExpiryTime         = db.RootGroup.ExpiryTime
                };

                model.Nodes.Add(root);
            }

            RecursiveAddGroup(model, root, db.RootGroup, null);

            return(model);
        }
Пример #3
0
        private void RecursiveAddGroup(TreeGroupModel tree, GroupModel parent, PwGroup pgContainer, PwGroup pgFind)
        {
            if (pgContainer == null)
            {
                return;
            }

            IList <GroupModel> tnc;

            if (parent == null)
            {
                tnc = tree.Nodes;
            }
            else
            {
                tnc = parent.Childs;
            }


            foreach (PwGroup pg in pgContainer.Groups)
            {
                string strName = pg.Name; // + GetGroupSuffixText(pg);

                int  nIconID  = ((!pg.CustomIconUuid.EqualsValue(PwUuid.Zero)) ? ((int)PwIcon.Count + db.GetCustomIconIndex(pg.CustomIconUuid)) : (int)pg.IconId);
                bool bExpired = (pg.Expires && (pg.ExpiryTime <= m_dtCachedNow));

                if (bExpired)
                {
                    nIconID = (int)PwIcon.Expired;
                }

                GroupModel node = new GroupModel()
                {
                    Name               = strName,
                    ImageIndex         = nIconID,
                    SelectedImageIndex = nIconID,
                    Group              = pg,
                    Expires            = pg.Expires,
                    ExpiryTime         = pg.ExpiryTime
                };

                tnc.Add(node);

                RecursiveAddGroup(tree, node, pg, pgFind);
            }
        }
Пример #4
0
        private void FillGroups(TreeGroupModel tree)
        {
            List <SidebarListItem> roots = new List <SidebarListItem> ();

            foreach (GroupModel group in tree.Nodes)
            {
                SidebarListItem rootItem = new SidebarListItem(group.Name);
                rootItem.DataObject = group;
                rootItem.IsHeader   = true;
                rootItem.Expandable = true;

                FillGroupsRecursive(rootItem, group);

                roots.Add(rootItem);
            }

            GroupsSourceList.DataSource = new SidebarDataSource(roots);

            // expand the 1st item and all childs
            GroupsSourceList.ExpandItem(GroupsSourceList.ItemAtRow(0), true);
        }