LibreOffice Module filter (master) 1
typedetection.hxx
Go to the documentation of this file.
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#pragma once
20
21#include "basecontainer.hxx"
22#include <com/sun/star/document/XTypeDetection.hpp>
23#include <com/sun/star/frame/XTerminateListener.hpp>
28
29namespace filter::config {
30
31class TerminateDetection;
32
35class TypeDetection : public ::cppu::ImplInheritanceHelper< BaseContainer ,
36 css::document::XTypeDetection >
37{
38
39// native interface
40
41 css::uno::Reference< css::uno::XComponentContext > m_xContext;
44
45public:
46
47
48 // ctor/dtor
49
56 explicit TypeDetection(const css::uno::Reference< css::uno::XComponentContext >& rxContext);
57
58 void cancel()
59 {
60 m_bCancel = true;
61 }
62
63
66 virtual ~TypeDetection() override;
67
68
69// private helper
70
71private:
72
74 std::unique_lock<std::mutex>& rGuard,
75 const OUString& sPreSelType, const css::util::URL& aParsedURL, FlatDetection& rFlatTypes, bool bDocService);
76
78 std::unique_lock<std::mutex>& rGuard,
79 const OUString& sPreSelDocumentService, const css::util::URL& aParsedURL, FlatDetection& rFlatTypes);
80
81 static OUString impl_getTypeFromFilter(std::unique_lock<std::mutex>& rGuard, const OUString& rFilterName);
82
86 static void impl_getAllFormatTypes(
87 std::unique_lock<std::mutex>& rGuard,
88 const css::util::URL& aParsedURL, utl::MediaDescriptor const & rDescriptor,
89 FlatDetection& rFlatTypes);
90
91
126 OUString impl_detectTypeFlatAndDeep( utl::MediaDescriptor& rDescriptor ,
127 const FlatDetection& lFlatTypes ,
128 bool bAllowDeep ,
129 OUString& rLastChance );
130
131
142 static void impl_seekStreamToZero(utl::MediaDescriptor const & rDescriptor);
143
144
162 OUString impl_askDetectService(const OUString& sDetectService,
163 utl::MediaDescriptor& rDescriptor );
164
165
180
181
215 void impl_openStream(utl::MediaDescriptor& rDescriptor);
216
217
237 const OUString& sType );
238
239
258 utl::MediaDescriptor& rDescriptor,
259 const OUString& sFilter );
260
261
274
275
307 OUString& sType );
308
309
310// uno interface
311
312public:
313
314
315 // XTypeDetection
316
317 virtual OUString SAL_CALL queryTypeByURL(const OUString& sURL) override;
318
319 virtual OUString SAL_CALL queryTypeByDescriptor(css::uno::Sequence< css::beans::PropertyValue >& lDescriptor,
320 sal_Bool bAllowDeep ) override;
321
322};
323
324class TerminateDetection : public comphelper::WeakComponentImplHelper<css::frame::XTerminateListener>
325{
326private:
328
329public:
330
332 virtual void SAL_CALL disposing(const css::lang::EventObject&) override
333 {
334 }
335
336 // XTerminateListener
337 virtual void SAL_CALL queryTermination(const css::lang::EventObject&) override
338 {
340 }
341
342 virtual void SAL_CALL notifyTermination(const css::lang::EventObject&) override
343 {
344 }
345
347 : m_pTypeDetection(pTypeDetection)
348 {
349 }
350};
351
352}
353
354/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void disposing(std::unique_lock< std::mutex > &)
virtual void SAL_CALL notifyTermination(const css::lang::EventObject &) override
virtual void SAL_CALL queryTermination(const css::lang::EventObject &) override
virtual void SAL_CALL disposing(const css::lang::EventObject &) override
TerminateDetection(TypeDetection *pTypeDetection)
implements the service <type scope="com.sun.star.document">TypeDetection</type>.
static void impl_getPreselectionForDocumentService(std::unique_lock< std::mutex > &rGuard, const OUString &sPreSelDocumentService, const css::util::URL &aParsedURL, FlatDetection &rFlatTypes)
TypeDetection(const css::uno::Reference< css::uno::XComponentContext > &rxContext)
standard ctor to connect this interface wrapper to the global filter cache instance ....
OUString impl_askDetectService(const OUString &sDetectService, utl::MediaDescriptor &rDescriptor)
make deep type detection for a specified detect service (threadsafe!).
void impl_checkResultsAndAddBestFilter(utl::MediaDescriptor &rDescriptor, OUString &sType)
search the best suitable filter for the given type and add it into the media descriptor.
static void impl_getAllFormatTypes(std::unique_lock< std::mutex > &rGuard, const css::util::URL &aParsedURL, utl::MediaDescriptor const &rDescriptor, FlatDetection &rFlatTypes)
Get all format types that we handle.
static bool impl_validateAndSetTypeOnDescriptor(utl::MediaDescriptor &rDescriptor, const OUString &sType)
validate the specified type and its relationships and set all needed information related to this type...
rtl::Reference< TerminateDetection > m_xTerminateListener
static OUString impl_askUserForTypeAndFilterIfAllowed(utl::MediaDescriptor &rDescriptor)
try to find an interaction handler and ask him to select a possible filter for this unknown format.
static void impl_seekStreamToZero(utl::MediaDescriptor const &rDescriptor)
seek a might existing stream to position 0.
static OUString impl_getTypeFromFilter(std::unique_lock< std::mutex > &rGuard, const OUString &rFilterName)
static void impl_removeTypeFilterFromDescriptor(utl::MediaDescriptor &rDescriptor)
remove anything related to a TYPE/FILTER entry from the specified MediaDescriptor.
virtual OUString SAL_CALL queryTypeByURL(const OUString &sURL) override
void impl_openStream(utl::MediaDescriptor &rDescriptor)
check if an input stream is already part of the given MediaDescriptor and creates a new one if necess...
virtual ~TypeDetection() override
standard dtor.
css::uno::Reference< css::uno::XComponentContext > m_xContext
virtual OUString SAL_CALL queryTypeByDescriptor(css::uno::Sequence< css::beans::PropertyValue > &lDescriptor, sal_Bool bAllowDeep) override
OUString impl_detectTypeFlatAndDeep(utl::MediaDescriptor &rDescriptor, const FlatDetection &lFlatTypes, bool bAllowDeep, OUString &rLastChance)
make a combined flat/deep type detection
static bool impl_getPreselectionForType(std::unique_lock< std::mutex > &rGuard, const OUString &sPreSelType, const css::util::URL &aParsedURL, FlatDetection &rFlatTypes, bool bDocService)
static bool impl_validateAndSetFilterOnDescriptor(utl::MediaDescriptor &rDescriptor, const OUString &sFilter)
validate the specified filter and its relationships and set all needed information related to this fi...
::std::vector< FlatDetectionInfo > FlatDetection
Definition: cacheitem.hxx:173
unsigned char sal_Bool