summaryrefslogtreecommitdiff
path: root/sfx2
diff options
context:
space:
mode:
authorKatarina Behrens <Katarina.Behrens@cib.de>2018-03-16 13:42:00 +0100
committerKatarina Behrens <Katarina.Behrens@cib.de>2018-03-20 10:11:53 +0100
commit43446fa03995fb5d1379fc0afbeec36c9dedfde2 (patch)
tree91256c5dd3fdefdd6a598a0250f9f1ebbd9f4950 /sfx2
parentfbadd85ce22d073c10915c0e0198c031a2c01abf (diff)
Show start centre thumbnail indicating the file is encrypted
Change-Id: Ie46096b3198852c6ef70960b22652767c09d4779 Reviewed-on: https://gerrit.libreoffice.org/51532 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Katarina Behrens <Katarina.Behrens@cib.de>
Diffstat (limited to 'sfx2')
-rw-r--r--sfx2/source/control/recentdocsview.cxx80
1 files changed, 68 insertions, 12 deletions
diff --git a/sfx2/source/control/recentdocsview.cxx b/sfx2/source/control/recentdocsview.cxx
index 708fd43b2f67..0318b6bcf140 100644
--- a/sfx2/source/control/recentdocsview.cxx
+++ b/sfx2/source/control/recentdocsview.cxx
@@ -28,6 +28,8 @@
#include <vcl/pngread.hxx>
#include <tools/stream.hxx>
#include <tools/urlobj.hxx>
+#include <com/sun/star/beans/NamedValue.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/util/URLTransformer.hpp>
#include <com/sun/star/frame/Desktop.hpp>
#include <com/sun/star/frame/XFrame.hpp>
@@ -51,11 +53,67 @@ void SetMessageFont(vcl::RenderContext& rRenderContext)
rRenderContext.SetFont(aFont);
}
+bool IsDocEncrypted(const OUString& rURL)
+{
+ uno::Reference< uno::XComponentContext > xContext(::comphelper::getProcessComponentContext());
+ bool bIsEncrypted = false;
+
+ try
+ {
+ uno::Reference<lang::XSingleServiceFactory> xStorageFactory = embed::StorageFactory::create(xContext);
+
+ uno::Sequence<uno::Any> aArgs (2);
+ aArgs[0] <<= rURL;
+ aArgs[1] <<= embed::ElementModes::READ;
+ uno::Reference<embed::XStorage> xDocStorage (
+ xStorageFactory->createInstanceWithArguments(aArgs),
+ uno::UNO_QUERY);
+ uno::Reference< beans::XPropertySet > xStorageProps( xDocStorage, uno::UNO_QUERY );
+ if ( xStorageProps.is() )
+ {
+ try
+ {
+ xStorageProps->getPropertyValue("HasEncryptedEntries")
+ >>= bIsEncrypted;
+ } catch( uno::Exception& ) {}
+ }
+ }
+ catch (const uno::Exception& rException)
+ {
+ SAL_WARN("sfx",
+ "caught exception trying to find out if doc is encrypted"
+ << rURL << ": " << rException);
+ }
+
+ return bIsEncrypted;
+}
+
}
namespace sfx2
{
+static std::map<ApplicationType,OUString> BitmapForExtension =
+{
+ { ApplicationType::TYPE_WRITER, SFX_FILE_THUMBNAIL_TEXT },
+ { ApplicationType::TYPE_CALC, SFX_FILE_THUMBNAIL_SHEET },
+ { ApplicationType::TYPE_IMPRESS, SFX_FILE_THUMBNAIL_PRESENTATION },
+ { ApplicationType::TYPE_DRAW, SFX_FILE_THUMBNAIL_DRAWING },
+ { ApplicationType::TYPE_DATABASE, SFX_FILE_THUMBNAIL_DATABASE },
+ { ApplicationType::TYPE_MATH, SFX_FILE_THUMBNAIL_MATH }
+};
+
+static std::map<ApplicationType,OUString> EncryptedBitmapForExtension =
+{
+ { ApplicationType::TYPE_WRITER, BMP_128X128_WRITER_DOC },
+ { ApplicationType::TYPE_CALC, BMP_128X128_CALC_DOC },
+ { ApplicationType::TYPE_IMPRESS, BMP_128X128_IMPRESS_DOC },
+ { ApplicationType::TYPE_DRAW, BMP_128X128_DRAW_DOC },
+ // FIXME: icon for encrypted db doc doesn't exist
+ { ApplicationType::TYPE_DATABASE, BMP_128X128_CALC_DOC },
+ { ApplicationType::TYPE_MATH, BMP_128X128_MATH_DOC }
+};
+
RecentDocsView::RecentDocsView( vcl::Window* pParent )
: ThumbnailView(pParent)
, mnFileTypes(ApplicationType::TYPE_NONE)
@@ -140,18 +198,16 @@ BitmapEx RecentDocsView::getDefaultThumbnail(const OUString &rURL)
INetURLObject aUrl(rURL);
OUString aExt = aUrl.getExtension();
- if (typeMatchesExtension(ApplicationType::TYPE_WRITER, aExt))
- aImg = BitmapEx(SFX_FILE_THUMBNAIL_TEXT);
- else if (typeMatchesExtension(ApplicationType::TYPE_CALC, aExt))
- aImg = BitmapEx(SFX_FILE_THUMBNAIL_SHEET);
- else if (typeMatchesExtension(ApplicationType::TYPE_IMPRESS, aExt))
- aImg = BitmapEx(SFX_FILE_THUMBNAIL_PRESENTATION);
- else if (typeMatchesExtension(ApplicationType::TYPE_DRAW, aExt))
- aImg = BitmapEx(SFX_FILE_THUMBNAIL_DRAWING);
- else if (typeMatchesExtension(ApplicationType::TYPE_DATABASE, aExt))
- aImg = BitmapEx(SFX_FILE_THUMBNAIL_DATABASE);
- else if (typeMatchesExtension(ApplicationType::TYPE_MATH, aExt))
- aImg = BitmapEx(SFX_FILE_THUMBNAIL_MATH);
+ const std::map<ApplicationType,OUString>& rWhichMap = IsDocEncrypted( rURL) ?
+ EncryptedBitmapForExtension : BitmapForExtension;
+
+ std::map<ApplicationType,OUString>::const_iterator mIt =
+ std::find_if( rWhichMap.begin(), rWhichMap.end(),
+ [aExt] ( const std::pair<ApplicationType,OUString>& aEntry )
+ { return typeMatchesExtension( aEntry.first, aExt); } );
+
+ if (mIt != rWhichMap.end())
+ aImg = BitmapEx(mIt->second);
else
aImg = BitmapEx(SFX_FILE_THUMBNAIL_DEFAULT);