xref: /aoo41x/main/sw/source/ui/uno/swdet2.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sw.hxx"
30 
31 #define _SWLIB_CXX
32 #include <sfx2/docfac.hxx>
33 #include <sfx2/docfilt.hxx>
34 #include <sfx2/fcontnr.hxx>
35 #include <sfx2/docfile.hxx>
36 #include <sfx2/app.hxx>
37 #include <svtools/sfxecode.hxx>
38 #include <vcl/msgbox.hxx>
39 #include <svtools/parhtml.hxx>
40 #include <sot/clsids.hxx>
41 #include <iodetect.hxx>
42 
43 #include <swdetect.hxx>
44 
45 #include <app.hrc>
46 #include <web.hrc>
47 #include <globdoc.hrc>
48 
49 #include <unotools/moduleoptions.hxx>
50 
51 #include <unomid.h>
52 
53 bool IsDocShellRegistered()
54 {
55     return SvtModuleOptions().IsWriter();
56 }
57 
58 //-------------------------------------------------------------------------
59 
60 sal_uLong SwFilterDetect::DetectFilter( SfxMedium& rMedium, const SfxFilter** ppFilter )
61 {
62 	sal_uLong nRet = ERRCODE_NONE;
63     if( *ppFilter )
64     {
65         // verify the given filter
66         String aPrefFlt = (*ppFilter)->GetUserData();
67 
68         // detection for TextFilter needs an additional checking
69         sal_Bool bDetected = SwIoSystem::IsFileFilter( rMedium, aPrefFlt );
70         return bDetected ? nRet : ERRCODE_ABORT;
71     }
72 
73     // mba: without preselection there is no PrefFlt
74     String aPrefFlt;
75     const SfxFilter* pTmp = SwIoSystem::GetFileFilter( rMedium.GetPhysicalName(), aPrefFlt, &rMedium );
76     if( !pTmp )
77         return ERRCODE_ABORT;
78     /*
79     else if( *ppFilter && (*ppFilter)->GetUserData().EqualsAscii( "W4W", 0, 3 )
80                 && pTmp->GetUserData().EqualsAscii( FILTER_TEXT, 0, 4 ) )
81     {
82         // Bug 95262 - if the user (or short  detect) select a
83         //              Word 4 Word filter, but the autodect of mastersoft
84         //              can't detect it, we normally return the ascii filter
85         //              But the user may have a change to use the W4W filter,
86         //              so the SFX must show now a dialog with the 2 filters
87         nRet = ERRCODE_SFX_CONSULTUSER;
88         *ppFilter = pTmp;
89     } */
90 
91     // sollte der voreingestellte Filter ASCII sein und wir haben
92     // ASCII erkannt, dann ist das ein gultiger Filter, ansonsten ist das
93     // ein Fehler und wir wollen die Filterbox sehen
94     /*
95     else if( pTmp->GetUserData().EqualsAscii( FILTER_TEXT ) )
96     {
97         // Bug 28974: "Text" erkannt, aber "Text Dos" "Text ..." eingestellt
98         //  -> keine FilterBox, sondern den eingestellten Filter benutzen
99         if( *ppFilter && (*ppFilter)->GetUserData().EqualsAscii( FILTER_TEXT, 0, 4 ) )
100             ;
101         else
102 //          if( !*ppFilter || COMPARE_EQUAL != pTmp->GetUserData().Compare((*ppFilter)->GetUserData(), 4 ))
103         {
104 //              nRet = ERRCODE_ABORT;
105             *ppFilter = pTmp;
106         }
107     } */
108     else
109     {
110         //Bug 41417: JP 09.07.97: HTML documents should be loaded by WebWriter
111         SfxFilterContainer aFilterContainer( String::CreateFromAscii("swriter/web") );
112         if( pTmp->GetUserData() != C2S(sHTML) ||
113             String::CreateFromAscii( "com.sun.star.text.WebDocument" ) ==
114             String( pTmp->GetServiceName() ) ||
115             0 == ( (*ppFilter) = SwIoSystem::GetFilterOfFormat( C2S(sHTML),
116                     &aFilterContainer ) ) )
117             *ppFilter = pTmp;
118     }
119 
120 	return nRet;
121 }
122 
123