1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  *   Licensed to the Apache Software Foundation (ASF) under one or more
12  *   contributor license agreements. See the NOTICE file distributed
13  *   with this work for additional information regarding copyright
14  *   ownership. The ASF licenses this file to you under the Apache
15  *   License, Version 2.0 (the "License"); you may not use this file
16  *   except in compliance with the License. You may obtain a copy of
17  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 #ifndef INCLUDED_SFX2_DOCFILT_HXX
20 #define INCLUDED_SFX2_DOCFILT_HXX
21 
22 #include <comphelper/documentconstants.hxx>
23 #include <rtl/ustring.hxx>
24 #include <sal/config.h>
25 #include <sal/types.h>
26 #include <sot/formats.hxx>
27 #include <sfx2/dllapi.h>
28 #include <tools/wldcrd.hxx>
29 
30 #include <memory>
31 
32 namespace com::sun::star::embed { class XStorage; }
33 namespace com::sun::star::uno { template <typename > class Reference; }
34 
35 class SotStorage;
36 
37 class SFX2_DLLPUBLIC SfxFilter
38 {
39     friend class SfxFilterContainer;
40 
41     WildCard        aWildCard;
42 
43     OUString aTypeName;
44     OUString aUserData;
45     OUString aServiceName;
46     OUString aMimeType;
47     OUString maFilterName;
48     OUString aUIName;
49     OUString aDefaultTemplate;
50 
51     /**
52      * Custom provider name in case the filter is provided via external
53      * libraries.  Empty for conventional filter types.
54      */
55     OUString const maProvider;
56 
57     SfxFilterFlags  nFormatType;
58     sal_Int32       nVersion;
59     SotClipboardFormatId lFormat;
60     bool mbEnabled;
61 
62 public:
63     SfxFilter( const OUString& rProvider, const OUString& rFilterName );
64 
65     SfxFilter( const OUString &rName,
66                const OUString &rWildCard,
67                SfxFilterFlags nFormatType,
68                SotClipboardFormatId lFormat,
69                const OUString &rTypeName,
70                const OUString &rMimeType,
71                const OUString &rUserData,
72                const OUString& rServiceName,
73                bool bEnabled = true );
74     ~SfxFilter();
75 
IsAllowedAsTemplate() const76     bool IsAllowedAsTemplate() const { return bool(nFormatType & SfxFilterFlags::TEMPLATE); }
IsOwnFormat() const77     bool IsOwnFormat() const { return bool(nFormatType & SfxFilterFlags::OWN); }
78     /// If the filter supports digital signatures.
GetSupportsSigning() const79     bool GetSupportsSigning() const { return bool(nFormatType & SfxFilterFlags::SUPPORTSSIGNING); }
GetGpgEncryption() const80     bool GetGpgEncryption() const { return bool(nFormatType & SfxFilterFlags::GPGENCRYPTION); }
IsOwnTemplateFormat() const81     bool IsOwnTemplateFormat() const { return bool(nFormatType & SfxFilterFlags::TEMPLATEPATH); }
82     /// not our built-in format
IsAlienFormat() const83     bool IsAlienFormat() const { return bool(nFormatType & SfxFilterFlags::ALIEN); }
84     /// an unusual/legacy file to be loading
IsExoticFormat() const85     bool IsExoticFormat() const { return bool(nFormatType & SfxFilterFlags::EXOTIC); }
CanImport() const86     bool CanImport() const { return bool(nFormatType & SfxFilterFlags::IMPORT); }
CanExport() const87     bool CanExport() const { return bool(nFormatType & SfxFilterFlags::EXPORT); }
GetFilterFlags() const88     SfxFilterFlags  GetFilterFlags() const  { return nFormatType; }
GetFilterName() const89     const OUString& GetFilterName() const { return maFilterName; }
GetMimeType() const90     const OUString& GetMimeType() const { return aMimeType; }
GetName() const91     const OUString& GetName() const { return  maFilterName; }
GetWildcard() const92     const WildCard& GetWildcard() const { return aWildCard; }
GetRealTypeName() const93     const OUString& GetRealTypeName() const { return aTypeName; }
GetFormat() const94     SotClipboardFormatId GetFormat() const { return lFormat; }
GetTypeName() const95     const OUString& GetTypeName() const { return aTypeName; }
GetUIName() const96     const OUString& GetUIName() const { return aUIName; }
GetUserData() const97     const OUString& GetUserData() const { return aUserData; }
GetDefaultTemplate() const98     const OUString& GetDefaultTemplate() const { return aDefaultTemplate; }
SetDefaultTemplate(const OUString & rStr)99     void            SetDefaultTemplate( const OUString& rStr ) { aDefaultTemplate = rStr; }
UsesStorage() const100     bool            UsesStorage() const { return GetFormat() != SotClipboardFormatId::NONE; }
SetUIName(const OUString & rName)101     void            SetUIName( const OUString& rName ) { aUIName = rName; }
SetVersion(sal_Int32 nVersionP)102     void            SetVersion( sal_Int32 nVersionP ) { nVersion = nVersionP; }
GetVersion() const103     sal_Int32       GetVersion() const { return nVersion; }
104     OUString GetSuffixes() const;
105     OUString GetDefaultExtension() const;
GetServiceName() const106     const OUString& GetServiceName() const { return aServiceName; }
GetProviderName() const107     const OUString& GetProviderName() const { return maProvider;}
108 
109     static std::shared_ptr<const SfxFilter> GetDefaultFilter( const OUString& rName );
110     static std::shared_ptr<const SfxFilter> GetFilterByName( const OUString& rName );
111     static std::shared_ptr<const SfxFilter> GetDefaultFilterFromFactory( const OUString& rServiceName );
112 
113     static OUString GetTypeFromStorage( const SotStorage& rStg );
114     /// @throws css::beans::UnknownPropertyException
115     /// @throws css::lang::WrappedTargetException
116     /// @throws css::uno::RuntimeException
117     static OUString GetTypeFromStorage(
118         const css::uno::Reference<css::embed::XStorage>& xStorage );
IsEnabled() const119     bool IsEnabled() const  { return mbEnabled; }
120 };
121 
122 #endif
123 
124 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
125