From 4c031108f0a98a334cb6e9c18769b8d91aef4e55 Mon Sep 17 00:00:00 2001 From: Ray Date: Tue, 21 Sep 2021 15:27:00 +0100 Subject: [PATCH] WIP: icon db --- Classes/IconDatabase.cs | 1 - Classes/WebParser.cs | 8 ++-- MainForm.cs | 87 +++++++++++++++++++++++++++++------------ 3 files changed, 67 insertions(+), 29 deletions(-) diff --git a/Classes/IconDatabase.cs b/Classes/IconDatabase.cs index 5b2ca3d..4e1fc98 100644 --- a/Classes/IconDatabase.cs +++ b/Classes/IconDatabase.cs @@ -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(); diff --git a/Classes/WebParser.cs b/Classes/WebParser.cs index f5c185c..5c170b5 100644 --- a/Classes/WebParser.cs +++ b/Classes/WebParser.cs @@ -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; } diff --git a/MainForm.cs b/MainForm.cs index 08274f4..2686d9c 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -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(); + } + } + } } } \ No newline at end of file