WIP: icon db

This commit is contained in:
Ray 2021-09-21 15:27:00 +01:00
parent 253365d25e
commit 4c031108f0
3 changed files with 67 additions and 29 deletions

View File

@ -237,7 +237,6 @@ namespace BookmarkManager
protected byte[] ImageToBytes(Image image)
{
MemoryStream stream = new MemoryStream();
//image.Save(stream, ((image.RawFormat == null) ? ImageFormat.Bmp : new ImageFormat(image.RawFormat.Guid)));
image.Save(stream, ImageFormat.Bmp);
stream.Close();

View File

@ -143,10 +143,10 @@ namespace BookmarkManager
rs = parseTagValue_Attr(doc, "//meta[translate(@itemprop, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') = 'image']", "content", string.Empty);
}
//if (string.IsNullOrWhiteSpace(rs))
//{
// rs = "/favicon.ico";
//}
if (string.IsNullOrWhiteSpace(rs))
{
rs = "/favicon.ico";
}
return rs;
}

View File

@ -686,17 +686,20 @@ namespace FizzyLauncher
case Keys.F2:
if (nodeType == BookmarkTreeView.NodeType.Page)
{
BookmarkForm bookmarkForm = new BookmarkForm(treeView1.GetNodeModel(), null);
if (bookmarkForm.ShowDialog() == DialogResult.OK)
{
string iconID = Crypto.GetSHA256Hash(bookmarkForm.Model.Item?.SiteName);
if (!string.IsNullOrWhiteSpace(iconID))
{
iconDatabase.AddIcon(iconID, bookmarkForm.Model.Icon);
}
UpdateBookmarkNode(false);
treeView1.UpdateItem(treeView1.SelectedNode, bookmarkForm.Model.Item);
}
//BookmarkForm bookmarkForm = new BookmarkForm(treeView1.GetNodeModel(), null);
//if (bookmarkForm.ShowDialog() == DialogResult.OK)
//{
// UpdateBookmarkNode(bookmarkForm);
// //string iconID = Crypto.GetSHA256Hash(bookmarkForm.Model.Item?.SiteName);
// //if (!string.IsNullOrWhiteSpace(iconID))
// //{
// // iconDatabase.AddIcon(iconID, bookmarkForm.Model.Icon);
// //}
// //treeView1.UpdateItem(treeView1.SelectedNode, bookmarkForm.Model.Item);
//}
}
break;
@ -720,21 +723,25 @@ namespace FizzyLauncher
node.EnsureVisible();
treeView1.SelectedNode = node;
BookmarkForm bookmarkForm = new BookmarkForm(treeView1.GetNodeModel(), null);
if (bookmarkForm.ShowDialog() == DialogResult.OK)
{
string iconID = Crypto.GetSHA256Hash(bookmarkForm.Model.Item?.SiteName);
if (!string.IsNullOrWhiteSpace(iconID))
{
iconDatabase.AddIcon(iconID, bookmarkForm.Model.Icon);
}
UpdateBookmarkNode(true);
treeView1.UpdateItem(treeView1.SelectedNode, bookmarkForm.Model.Item);
}
else
{
node.Remove();
}
//BookmarkForm bookmarkForm = new BookmarkForm(treeView1.GetNodeModel(), null);
//if (bookmarkForm.ShowDialog() == DialogResult.OK)
//{
// UpdateBookmarkNode(bookmarkForm);
// //string iconID = Crypto.GetSHA256Hash(bookmarkForm.Model.Item?.SiteName);
// //if (!string.IsNullOrWhiteSpace(iconID))
// //{
// // iconDatabase.AddIcon(iconID, bookmarkForm.Model.Icon);
// //}
// //treeView1.UpdateItem(treeView1.SelectedNode, bookmarkForm.Model.Item);
//}
//else
//{
// node.Remove();
//}
}
break;
@ -1078,6 +1085,38 @@ namespace FizzyLauncher
});
}
protected void UpdateBookmarkNode(bool deleteOnCancel)
{
BookmarkItem model = treeView1.GetNodeModel();
Image icon = null;
// retrieve icon from DB
if (!string.IsNullOrWhiteSpace(model.SiteName))
{
string iconID = Crypto.GetSHA256Hash(model?.SiteName);
icon = iconDatabase.FindIcon(iconID);
}
BookmarkForm bookmarkForm = new BookmarkForm(model, icon);
if (bookmarkForm.ShowDialog() == DialogResult.OK)
{
string iconID = Crypto.GetSHA256Hash(bookmarkForm.Model.Item?.SiteName);
if (!string.IsNullOrWhiteSpace(iconID))
{
iconDatabase.AddIcon(iconID, bookmarkForm.Model.Icon);
}
treeView1.UpdateItem(treeView1.SelectedNode, bookmarkForm.Model.Item);
}
else
{
if (deleteOnCancel)
{
treeView1.SelectedNode.Remove();
}
}
}
}
}