From 2293da320034052e5e9d5152f4929b4f653d8812 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 29 Mar 2024 13:40:11 +0300 Subject: NewStory: preview for downloaded pictures --- plugins/NewStory/src/history_array.cpp | 27 +++++++++++++-------------- plugins/NewStory/src/templates.cpp | 9 +++++++++ 2 files changed, 22 insertions(+), 14 deletions(-) (limited to 'plugins/NewStory/src') diff --git a/plugins/NewStory/src/history_array.cpp b/plugins/NewStory/src/history_array.cpp index 9a5185c905..a0e2999cc2 100644 --- a/plugins/NewStory/src/history_array.cpp +++ b/plugins/NewStory/src/history_array.cpp @@ -386,13 +386,20 @@ void ItemData::load(bool bLoadAlways) { DB::FILE_BLOB blob(dbe); if (blob.isOffline()) { + CMStringW buf; + m_bOfflineFile = true; - if (blob.isCompleted()) + if (blob.isCompleted()) { m_bOfflineDownloaded = 100; - else - m_bOfflineDownloaded = uint8_t(100.0 * blob.getTransferred() / blob.getSize()); - CMStringW buf; + auto *pwszLocalName = blob.getLocalName(); + if (ProtoGetAvatarFileFormat(pwszLocalName) != PA_FORMAT_UNKNOWN) + buf.AppendFormat(L"[img]%s[/img]", pwszLocalName); + else + buf.AppendFormat(L"[url]file://%s[/url]", pwszLocalName); + } + else m_bOfflineDownloaded = uint8_t(100.0 * blob.getTransferred() / blob.getSize()); + buf.Append(blob.getName() ? blob.getName() : TranslateT("Unnamed")); if (auto *pwszDescr = blob.getDescr()) { @@ -414,17 +421,9 @@ void ItemData::load(bool bLoadAlways) CMStringW wszFileName = buf; wszFileName.Append(blob.getName()); - // if a filename contains spaces, URL will be broken - if (wszFileName.Find(' ') != -1) { - wchar_t wszShortPath[MAX_PATH]; - if (GetShortPathNameW(wszFileName, wszShortPath, _countof(wszShortPath))) { - wszFileName = wszShortPath; - wszFileName.MakeLower(); - } - } - wszFileName.Replace('\\', '/'); - wszFileName.Insert(0, L"file://"); + wszFileName.Insert(0, L"[url]file://"); + wszFileName.Append(L"[/url]"); wtext = wszFileName.Detach(); } break; diff --git a/plugins/NewStory/src/templates.cpp b/plugins/NewStory/src/templates.cpp index 166a3de63c..ef7bba6b9f 100644 --- a/plugins/NewStory/src/templates.cpp +++ b/plugins/NewStory/src/templates.cpp @@ -113,6 +113,15 @@ static void AppendString(CMStringW &buf, const wchar_t *p) buf.AppendFormat(L"<%ss>", pEnd); p++; } + else if (!wcsncmp(p, L"img]", 4)) { + p += 4; + + if (auto *p2 = wcsstr(p, L"[/img]")) { + CMStringW wszUrl(p, int(p2 - p)); + buf.AppendFormat(L"
", wszUrl.c_str()); + p = p2 + 5; + } + } else if (!wcsncmp(p, L"url]", 4)) { p += 4; -- cgit v1.2.3