Line data Source code
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 :
20 : #include <SwXFilterOptions.hxx>
21 : #include <shellio.hxx>
22 : #include <swdll.hxx>
23 : #include <unoprnms.hxx>
24 : #include <osl/mutex.hxx>
25 : #include <vcl/svapp.hxx>
26 : #include <vcl/msgbox.hxx>
27 : #include <com/sun/star/lang/XUnoTunnel.hpp>
28 : #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
29 : #include <unotools/ucbstreamhelper.hxx>
30 : #include <unotxdoc.hxx>
31 :
32 : #include "swabstdlg.hxx"
33 : #include "dialog.hrc"
34 :
35 : using namespace ::com::sun::star;
36 : using namespace ::com::sun::star::ui::dialogs;
37 : using namespace ::com::sun::star::document;
38 : using namespace ::com::sun::star::lang;
39 :
40 : #define SWFILTEROPTIONSOBJ_SERVICE RTL_CONSTASCII_USTRINGPARAM("com.sun.star.ui.dialogs.FilterOptionsDialog")
41 : #define SWFILTEROPTIONSOBJ_IMPLNAME RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.Writer.FilterOptionsDialog")
42 : #define FILTER_OPTIONS_NAME RTL_CONSTASCII_USTRINGPARAM("FilterOptions")
43 :
44 0 : SwXFilterOptions::SwXFilterOptions() :
45 0 : bExport( sal_False )
46 : {
47 0 : }
48 :
49 0 : SwXFilterOptions::~SwXFilterOptions()
50 : {
51 0 : }
52 :
53 9 : ::rtl::OUString SwXFilterOptions::getImplementationName_Static()
54 : {
55 9 : return ::rtl::OUString(SWFILTEROPTIONSOBJ_IMPLNAME);
56 : }
57 :
58 0 : uno::Sequence< ::rtl::OUString> SwXFilterOptions::getSupportedServiceNames_Static()
59 : {
60 0 : ::rtl::OUString sService(SWFILTEROPTIONSOBJ_SERVICE);
61 0 : return uno::Sequence< ::rtl::OUString> (&sService, 1);
62 : }
63 :
64 0 : uno::Sequence< beans::PropertyValue > SwXFilterOptions::getPropertyValues() throw (uno::RuntimeException)
65 : {
66 0 : uno::Sequence<beans::PropertyValue> aRet(1);
67 0 : beans::PropertyValue* pArray = aRet.getArray();
68 :
69 0 : pArray[0].Name = rtl::OUString( FILTER_OPTIONS_NAME );
70 0 : pArray[0].Value <<= sFilterOptions;
71 :
72 0 : return aRet;
73 : }
74 :
75 0 : void SwXFilterOptions::setPropertyValues( const uno::Sequence<beans::PropertyValue >& aProps )
76 : throw (beans::UnknownPropertyException, beans::PropertyVetoException,
77 : IllegalArgumentException, WrappedTargetException, uno::RuntimeException)
78 : {
79 0 : const beans::PropertyValue* pPropArray = aProps.getConstArray();
80 0 : long nPropCount = aProps.getLength();
81 0 : for (long i = 0; i < nPropCount; i++)
82 : {
83 0 : const beans::PropertyValue& rProp = pPropArray[i];
84 0 : ::rtl::OUString aPropName = rProp.Name;
85 :
86 0 : if ( aPropName.equalsAscii( SW_PROP_NAME_STR(UNO_NAME_FILTER_NAME) ) )
87 0 : rProp.Value >>= sFilterName;
88 0 : else if ( aPropName == ::rtl::OUString(FILTER_OPTIONS_NAME) )
89 0 : rProp.Value >>= sFilterOptions;
90 0 : else if ( aPropName == "InputStream" )
91 0 : rProp.Value >>= xInputStream;
92 0 : }
93 0 : }
94 :
95 0 : void SwXFilterOptions::setTitle( const ::rtl::OUString& /*rTitle*/ )
96 : throw (uno::RuntimeException)
97 : {
98 0 : }
99 :
100 0 : sal_Int16 SwXFilterOptions::execute() throw (uno::RuntimeException)
101 : {
102 0 : sal_Int16 nRet = ui::dialogs::ExecutableDialogResults::CANCEL;
103 :
104 0 : SvStream* pInStream = NULL;
105 0 : if ( xInputStream.is() )
106 0 : pInStream = utl::UcbStreamHelper::CreateStream( xInputStream );
107 :
108 0 : uno::Reference< XUnoTunnel > xTunnel(xModel, uno::UNO_QUERY);
109 0 : SwDocShell* pDocShell = 0;
110 0 : if(xTunnel.is())
111 : {
112 : SwXTextDocument* pXDoc = reinterpret_cast< SwXTextDocument * >(
113 0 : sal::static_int_cast< sal_IntPtr >(xTunnel->getSomething(SwXTextDocument::getUnoTunnelId())));
114 0 : pDocShell = pXDoc ? pXDoc->GetDocShell() : 0;
115 : }
116 0 : if(pDocShell)
117 : {
118 :
119 0 : SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
120 : OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!");
121 :
122 0 : AbstractSwAsciiFilterDlg* pAsciiDlg = pFact->CreateSwAsciiFilterDlg( NULL, *pDocShell,pInStream, DLG_ASCII_FILTER );
123 : OSL_ENSURE(pAsciiDlg, "Dialogdiet fail!");
124 0 : if(RET_OK == pAsciiDlg->Execute())
125 : {
126 0 : SwAsciiOptions aOptions;
127 0 : pAsciiDlg->FillOptions( aOptions );
128 0 : String sTmp;
129 0 : aOptions.WriteUserData(sTmp);
130 0 : sFilterOptions = sTmp;
131 0 : nRet = ui::dialogs::ExecutableDialogResults::OK;
132 : }
133 0 : delete pAsciiDlg;
134 : }
135 :
136 0 : delete pInStream;
137 :
138 0 : return nRet;
139 : }
140 :
141 0 : void SwXFilterOptions::setTargetDocument( const uno::Reference< XComponent >& xDoc )
142 : throw (IllegalArgumentException, uno::RuntimeException)
143 : {
144 0 : bExport = sal_False;
145 0 : xModel = xDoc;
146 0 : }
147 :
148 0 : void SwXFilterOptions::setSourceDocument( const uno::Reference<XComponent >& xDoc )
149 : throw (IllegalArgumentException,uno::RuntimeException)
150 : {
151 0 : bExport = sal_True;
152 0 : xModel = xDoc;
153 0 : }
154 :
155 0 : ::rtl::OUString SwXFilterOptions::getImplementationName() throw(uno::RuntimeException)
156 : {
157 0 : return ::rtl::OUString(SWFILTEROPTIONSOBJ_IMPLNAME);
158 : }
159 :
160 0 : sal_Bool SwXFilterOptions::supportsService( const ::rtl::OUString& rServiceName )
161 : throw(uno::RuntimeException)
162 : {
163 0 : return rServiceName == ::rtl::OUString(SWFILTEROPTIONSOBJ_SERVICE);
164 : }
165 :
166 0 : uno::Sequence< ::rtl::OUString > SwXFilterOptions::getSupportedServiceNames()
167 : throw(uno::RuntimeException)
168 : {
169 0 : return SwXFilterOptions::getSupportedServiceNames_Static();
170 : }
171 :
172 0 : uno::Reference<uno::XInterface> SAL_CALL SwXFilterOptions_createInstance(
173 : const uno::Reference<lang::XMultiServiceFactory>& )
174 : {
175 0 : SolarMutexGuard aGuard;
176 0 : SwGlobals::ensure();
177 0 : return (::cppu::OWeakObject*) new SwXFilterOptions;
178 30 : }
179 :
180 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|