Exemplo n.º 1
0
 public static Image getIcon(PwDatabase db, ImageList imageList, PwUuid customIconId, PwIcon iconId)
 {
     if (!PwUuid.Zero.Equals(customIconId))
     {
         return db.GetCustomIcon(customIconId, 16, 16);
     }
     else
     {
         return imageList.Images[(int)iconId];
     }
 }
Exemplo n.º 2
0
        private static void ExportGroup(StringBuilder sb, PwGroup pg, uint uIndent,
			PwDatabase pd)
        {
            ExportData(sb, uIndent, "<DT><H3", null, false, null, false);
            ExportTimes(sb, pg);
            ExportData(sb, 0, ">", pg.Name, true, "</H3>", true);
            ExportData(sb, uIndent, "<DL><p>", null, false, null, true);

            foreach(PwGroup pgSub in pg.Groups)
            {
                ExportGroup(sb, pgSub, uIndent + 1, pd);
            }

            #if DEBUG
            List<string> l = new List<string>();
            l.Add("Tag 1");
            l.Add("Tag 2");
            Debug.Assert(StrUtil.TagsToString(l, false) == "Tag 1;Tag 2");
            #endif

            foreach(PwEntry pe in pg.Entries)
            {
                string strUrl = pe.Strings.ReadSafe(PwDefs.UrlField);
                if(strUrl.Length == 0) continue;

                // Encode only when really required; '&' does not need
                // to be encoded
                bool bEncUrl = (strUrl.IndexOfAny(new char[] {
                    '\"', '<', '>' }) >= 0);

                ExportData(sb, uIndent + 1, "<DT><A HREF=\"", strUrl, bEncUrl,
                    "\"", false);

                ExportTimes(sb, pe);

                if(!pe.CustomIconUuid.Equals(PwUuid.Zero) && (pd != null))
                {
                    try
                    {
                        Image imgIcon = pd.GetCustomIcon(pe.CustomIconUuid, 16, 16);
                        if(imgIcon != null)
                        {
                            using(MemoryStream msIcon = new MemoryStream())
                            {
                                imgIcon.Save(msIcon, ImageFormat.Png);
                                byte[] pbIcon = msIcon.ToArray();
                                string strIcon = StrUtil.DataToDataUri(pbIcon,
                                    "image/png");

                                ExportData(sb, 0, " ICON=\"", strIcon, false,
                                    "\"", false);
                            }
                        }
                        else { Debug.Assert(false); }
                    }
                    catch(Exception) { Debug.Assert(false); }
                }

                if(pe.Tags.Count > 0)
                {
                    string strTags = StrUtil.TagsToString(pe.Tags, false);
                    strTags = strTags.Replace(';', ','); // Without space

                    ExportData(sb, 0, " TAGS=\"", strTags, true, "\"", false);
                }

                string strTitle = pe.Strings.ReadSafe(PwDefs.TitleField);
                if(strTitle.Length == 0) strTitle = strUrl;

                ExportData(sb, 0, ">", strTitle, true, "</A>", true);

                string strNotes = pe.Strings.ReadSafe(PwDefs.NotesField);
                if(strNotes.Length > 0)
                    ExportData(sb, uIndent + 1, "<DD>", strNotes, true, null, true);
            }

            ExportData(sb, uIndent, "</DL><p>", null, false, null, true);
        }
Exemplo n.º 3
0
        internal static Image GetIcon(PwDatabase pd, PwUuid pwUuid)
        {
            if(pd == null) { Debug.Assert(false); return null; }
            if(pwUuid == null) { Debug.Assert(false); return null; }

            int w = ScaleIntX(16);
            int h = ScaleIntY(16);

            return pd.GetCustomIcon(pwUuid, w, h);
        }
Exemplo n.º 4
0
        public Drawable GetIconDrawable(Resources res, PwDatabase db, PwUuid icon)
        {
            InitBlank (res);
            if (icon.Equals(PwUuid.Zero)) {
                return _blank;
            }
            Drawable draw;
            if (!_customIconMap.TryGetValue(icon, out draw))
            {
                Bitmap bitmap = db.GetCustomIcon(icon);

                // Could not understand custom icon
                if (bitmap == null) {
                    return _blank;
                }

                bitmap = resize (bitmap);

                draw = new BitmapDrawable(res, bitmap);
                _customIconMap[icon] = draw;
            }

            return draw;
        }