1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "AppController.hxx"
21 #include "AppDetailView.hxx"
22 #include "AppView.hxx"
23 #include <core_resource.hxx>
24 #include <dbaccess_slotid.hrc>
25 #include <strings.hrc>
26 #include <strings.hxx>
27 #include <defaultobjectnamecheck.hxx>
28 #include <dlgsave.hxx>
29 #include <UITools.hxx>
30 #include "subcomponentmanager.hxx"
32 #include <com/sun/star/container/XChild.hpp>
33 #include <com/sun/star/container/XContainer.hpp>
34 #include <com/sun/star/container/XHierarchicalNameContainer.hpp>
35 #include <com/sun/star/container/XNameAccess.hpp>
36 #include <com/sun/star/sdb/CommandType.hpp>
37 #include <com/sun/star/sdb/XQueriesSupplier.hpp>
38 #include <com/sun/star/sdbcx/XRename.hpp>
39 #include <com/sun/star/sdb/ErrorCondition.hpp>
40 #include <com/sun/star/sdb/application/DatabaseObject.hpp>
41 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
42 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
43 #include <com/sun/star/util/XRefreshable.hpp>
45 #include <cppuhelper/exc_hlp.hxx>
46 #include <comphelper/types.hxx>
47 #include <connectivity/dbexception.hxx>
48 #include <connectivity/dbtools.hxx>
49 #include <connectivity/sqlerror.hxx>
50 #include <sfx2/mailmodelapi.hxx>
51 #include <svx/dbaexchange.hxx>
52 #include <toolkit/helper/vclunohelper.hxx>
53 #include <comphelper/diagnose_ex.hxx>
54 #include <osl/diagnose.h>
55 #include <vcl/mnemonic.hxx>
56 #include <vcl/svapp.hxx>
57 #include <vcl/syswin.hxx>
58 #include <vcl/weld.hxx>
59 #include <osl/mutex.hxx>
63 using namespace ::dbtools
;
64 using namespace ::connectivity
;
65 using namespace ::svx
;
66 using namespace ::com::sun::star
;
67 using namespace ::com::sun::star::uno
;
68 using namespace ::com::sun::star::awt
;
69 using namespace ::com::sun::star::util
;
70 using namespace ::com::sun::star::frame
;
71 using namespace ::com::sun::star::lang
;
72 using namespace ::com::sun::star::ui::dialogs
;
73 using namespace ::com::sun::star::sdb
;
74 using namespace ::com::sun::star::sdbc
;
75 using namespace ::com::sun::star::sdbcx
;
76 using namespace ::com::sun::star::beans
;
77 using namespace ::com::sun::star::container
;
78 using namespace ::com::sun::star::ucb
;
80 using ::com::sun::star::ui::XContextMenuInterceptor
;
82 namespace DatabaseObject
= ::com::sun::star::sdb::application::DatabaseObject
;
83 namespace ErrorCondition
= ::com::sun::star::sdb::ErrorCondition
;
85 void OApplicationController::convertToView(const OUString
& _sName
)
89 SharedConnection
xConnection( getConnection() );
90 Reference
< XQueriesSupplier
> xSup( xConnection
, UNO_QUERY_THROW
);
91 Reference
< XNameAccess
> xQueries( xSup
->getQueries(), UNO_SET_THROW
);
92 Reference
< XPropertySet
> xSourceObject( xQueries
->getByName( _sName
), UNO_QUERY_THROW
);
94 Reference
< XTablesSupplier
> xTablesSup( xConnection
, UNO_QUERY_THROW
);
95 Reference
< XNameAccess
> xTables( xTablesSup
->getTables(), UNO_SET_THROW
);
97 Reference
< XDatabaseMetaData
> xMeta
= xConnection
->getMetaData();
99 const OUString aDefaultName
= ::dbaui::createDefaultName(xMeta
, xTables
, DBA_RES(STR_TBL_TITLE
).getToken(0, ' '));
101 DynamicTableOrQueryNameCheck
aNameChecker( xConnection
, CommandType::TABLE
);
102 OSaveAsDlg
aDlg(getFrameWeld(), CommandType::TABLE
, getORB(), xConnection
, aDefaultName
, aNameChecker
, SADFlags::NONE
);
103 if (aDlg
.run() == RET_OK
)
105 OUString sName
= aDlg
.getName();
106 OUString sCatalog
= aDlg
.getCatalog();
107 OUString sSchema
= aDlg
.getSchema();
109 ::dbtools::composeTableName( xMeta
, sCatalog
, sSchema
, sName
, false, ::dbtools::EComposeRule::InTableDefinitions
) );
110 Reference
<XPropertySet
> xView
= ::dbaui::createView(sNewName
,xConnection
,xSourceObject
);
112 throw SQLException(DBA_RES(STR_NO_TABLE_FORMAT_INSIDE
),*this, "S1000",0,Any());
113 getContainer()->elementAdded(E_TABLE
,sNewName
,Any(xView
));
116 catch(const SQLException
& )
118 showError( SQLExceptionInfo( ::cppu::getCaughtException() ) );
120 catch( const Exception
& )
122 DBG_UNHANDLED_EXCEPTION("dbaccess");
126 void OApplicationController::pasteFormat(SotClipboardFormatId _nFormatId
)
128 if ( _nFormatId
== SotClipboardFormatId::NONE
)
133 const TransferableDataHelper
& rClipboard
= getViewClipboard();
134 ElementType eType
= getContainer()->getElementType();
135 if ( eType
== E_TABLE
)
137 m_aTableCopyHelper
.pasteTable( _nFormatId
, rClipboard
, getDatabaseName(), ensureConnection() );
140 paste( eType
, ODataAccessObjectTransferable::extractObjectDescriptor( rClipboard
) );
143 catch( const Exception
& )
145 DBG_UNHANDLED_EXCEPTION("dbaccess");
149 void OApplicationController::openDialog( const OUString
& _sServiceName
)
153 SolarMutexGuard aSolarGuard
;
154 ::osl::MutexGuard
aGuard( getMutex() );
155 weld::WaitObject
aWO(getFrameWeld());
157 Sequence
< Any
> aArgs(3);
158 auto pArgs
= aArgs
.getArray();
159 sal_Int32 nArgPos
= 0;
161 Reference
< css::awt::XWindow
> xWindow
= getTopMostContainerWindow();
164 OSL_ENSURE( getContainer(), "OApplicationController::Construct: have no view!" );
165 if ( getContainer() )
166 xWindow
= VCLUnoHelper::GetInterface(getView()->Window::GetParent());
169 pArgs
[nArgPos
++] <<= PropertyValue( "ParentWindow",
172 PropertyState_DIRECT_VALUE
);
174 // the initial selection
175 OUString sInitialSelection
;
176 if ( getContainer() )
177 sInitialSelection
= getDatabaseName();
178 if ( !sInitialSelection
.isEmpty() )
180 pArgs
[ nArgPos
++ ] <<= PropertyValue(
181 "InitialSelection", 0,
182 Any( sInitialSelection
), PropertyState_DIRECT_VALUE
);
185 SharedConnection
xConnection( getConnection() );
186 if ( xConnection
.is() )
188 pArgs
[ nArgPos
++ ] <<= PropertyValue(
189 PROPERTY_ACTIVE_CONNECTION
, 0,
190 makeAny( xConnection
), PropertyState_DIRECT_VALUE
);
192 aArgs
.realloc( nArgPos
);
195 Reference
< XExecutableDialog
> xAdminDialog
;
197 getORB()->getServiceManager()->createInstanceWithArgumentsAndContext(_sServiceName
, aArgs
, getORB()),
201 if (xAdminDialog
.is())
202 xAdminDialog
->execute();
204 catch( const Exception
& )
206 DBG_UNHANDLED_EXCEPTION("dbaccess");
210 void OApplicationController::refreshTables()
212 if ( !(getContainer() && getContainer()->getDetailView()) )
215 weld::WaitObject
aWO(getFrameWeld());
216 OSL_ENSURE(getContainer()->getElementType() == E_TABLE
,"Only allowed when the tables container is selected!");
219 Reference
<XRefreshable
> xRefresh(getElements(E_TABLE
),UNO_QUERY
);
223 catch(const Exception
&)
225 OSL_FAIL("Could not refresh tables!");
228 getContainer()->getDetailView()->clearPages(false);
229 getContainer()->getDetailView()->createTablesPage( ensureConnection() );
232 void SAL_CALL
OApplicationController::propertyChange( const PropertyChangeEvent
& evt
)
234 SolarMutexGuard aSolarGuard
;
235 ::osl::MutexGuard
aGuard( getMutex() );
236 if ( evt
.PropertyName
== PROPERTY_USER
)
238 m_bNeedToReconnect
= true;
239 InvalidateFeature(SID_DB_APP_STATUS_USERNAME
);
241 else if ( evt
.PropertyName
== PROPERTY_URL
)
243 m_bNeedToReconnect
= true;
244 InvalidateFeature(SID_DB_APP_STATUS_DBNAME
);
245 InvalidateFeature(SID_DB_APP_STATUS_TYPE
);
246 InvalidateFeature(SID_DB_APP_STATUS_HOSTNAME
);
248 else if ( PROPERTY_NAME
== evt
.PropertyName
)
250 const ElementType eType
= getContainer()->getElementType();
251 if ( eType
== E_FORM
|| eType
== E_REPORT
)
253 OUString sOldName
,sNewName
;
254 evt
.OldValue
>>= sOldName
;
255 evt
.NewValue
>>= sNewName
;
257 // if the old name is empty, then this is a newly inserted content. We're notified of it via the
258 // elementInserted method, so there's no need to handle it here.
260 if ( !sOldName
.isEmpty() )
262 Reference
<XChild
> xChild(evt
.Source
,UNO_QUERY
);
265 Reference
<XContent
> xContent(xChild
->getParent(),UNO_QUERY
);
267 sOldName
= xContent
->getIdentifier()->getContentIdentifier() + "/" + sOldName
;
270 getContainer()->elementReplaced( eType
, sOldName
, sNewName
);
276 aEvt
.Source
= m_xModel
;
280 Reference
< XDataSource
> SAL_CALL
OApplicationController::getDataSource()
282 ::osl::MutexGuard
aGuard( getMutex() );
283 Reference
< XDataSource
> xDataSource( m_xDataSource
, UNO_QUERY
);
287 Reference
< XWindow
> SAL_CALL
OApplicationController::getApplicationMainWindow()
289 ::osl::MutexGuard
aGuard( getMutex() );
290 Reference
< XFrame
> xFrame( getFrame(), UNO_SET_THROW
);
291 Reference
< XWindow
> xWindow( xFrame
->getContainerWindow(), UNO_SET_THROW
);
295 Sequence
< Reference
< XComponent
> > SAL_CALL
OApplicationController::getSubComponents()
297 ::osl::MutexGuard
aGuard( getMutex() );
298 return m_pSubComponentManager
->getSubComponents();
301 Reference
< XConnection
> SAL_CALL
OApplicationController::getActiveConnection()
303 ::osl::MutexGuard
aGuard( getMutex() );
304 return m_xDataSourceConnection
.getTyped();
307 sal_Bool SAL_CALL
OApplicationController::isConnected( )
309 ::osl::MutexGuard
aGuard( getMutex() );
310 return m_xDataSourceConnection
.is();
313 void SAL_CALL
OApplicationController::connect( )
315 SQLExceptionInfo aError
;
316 SharedConnection xConnection
= ensureConnection( &aError
);
317 if ( !xConnection
.is() )
319 if ( aError
.isValid() )
322 // no particular error, but nonetheless could not connect -> throw a generic exception
323 OUString
sConnectingContext( DBA_RES( STR_COULDNOTCONNECT_DATASOURCE
) );
324 ::dbtools::throwGenericSQLException( sConnectingContext
.replaceFirst( "$name$", getStrippedDatabaseName() ), *this );
328 beans::Pair
< ::sal_Int32
, OUString
> SAL_CALL
OApplicationController::identifySubComponent( const Reference
< XComponent
>& i_rSubComponent
)
330 ::osl::MutexGuard
aGuard( getMutex() );
332 sal_Int32 nType
= -1;
335 if ( !m_pSubComponentManager
->lookupSubComponent( i_rSubComponent
, sName
, nType
) )
336 throw IllegalArgumentException( OUString(), *this, 1 );
338 if ( nType
== SID_DB_APP_DSRELDESIGN
)
339 // this is somewhat hacky ... we're expected to return a DatabaseObject value. However, there is no such
340 // value for the relation design. /me thinks we should change the API definition here ...
343 return beans::Pair
< ::sal_Int32
, OUString
>( nType
, sName
);
346 sal_Bool SAL_CALL
OApplicationController::closeSubComponents( )
348 SolarMutexGuard aSolarGuard
;
349 ::osl::MutexGuard
aGuard( getMutex() );
350 return m_pSubComponentManager
->closeSubComponents();
355 ElementType
lcl_objectType2ElementType( const sal_Int32 _nObjectType
)
357 ElementType
eType( E_NONE
);
358 switch ( _nObjectType
)
360 case DatabaseObject::TABLE
: eType
= E_TABLE
; break;
361 case DatabaseObject::QUERY
: eType
= E_QUERY
; break;
362 case DatabaseObject::FORM
: eType
= E_FORM
; break;
363 case DatabaseObject::REPORT
: eType
= E_REPORT
; break;
365 OSL_FAIL( "lcl_objectType2ElementType: unsupported object type!" );
366 // this should have been caught earlier
372 void OApplicationController::impl_validateObjectTypeAndName_throw( const sal_Int32 _nObjectType
, const ::std::optional
< OUString
>& i_rObjectName
)
374 // ensure we're connected
375 if ( !isConnected() )
378 aError
.raiseException( ErrorCondition::DB_NOT_CONNECTED
, *this );
381 // ensure a proper object type
382 if ( ( _nObjectType
!= DatabaseObject::TABLE
)
383 && ( _nObjectType
!= DatabaseObject::QUERY
)
384 && ( _nObjectType
!= DatabaseObject::FORM
)
385 && ( _nObjectType
!= DatabaseObject::REPORT
)
387 throw IllegalArgumentException( OUString(), *this, 1 );
389 if ( !i_rObjectName
)
392 // ensure an existing object
393 Reference
< XNameAccess
> xContainer( getElements( lcl_objectType2ElementType( _nObjectType
) ) );
394 if ( !xContainer
.is() )
395 // all possible reasons for this (e.g. not being connected currently) should
396 // have been handled before
397 throw RuntimeException( OUString(), *this );
399 bool bExistentObject
= false;
400 switch ( _nObjectType
)
402 case DatabaseObject::TABLE
:
403 case DatabaseObject::QUERY
:
404 bExistentObject
= xContainer
->hasByName( *i_rObjectName
);
406 case DatabaseObject::FORM
:
407 case DatabaseObject::REPORT
:
409 Reference
< XHierarchicalNameAccess
> xHierarchy( xContainer
, UNO_QUERY_THROW
);
410 bExistentObject
= xHierarchy
->hasByHierarchicalName( *i_rObjectName
);
415 if ( !bExistentObject
)
416 throw NoSuchElementException( *i_rObjectName
, *this );
419 Reference
< XComponent
> SAL_CALL
OApplicationController::loadComponent( ::sal_Int32 ObjectType
,
420 const OUString
& ObjectName
, sal_Bool ForEditing
)
422 return loadComponentWithArguments( ObjectType
, ObjectName
, ForEditing
, Sequence
< PropertyValue
>() );
425 Reference
< XComponent
> SAL_CALL
OApplicationController::loadComponentWithArguments( ::sal_Int32 ObjectType
,
426 const OUString
& ObjectName
, sal_Bool ForEditing
, const Sequence
< PropertyValue
>& Arguments
)
428 SolarMutexGuard aSolarGuard
;
429 ::osl::MutexGuard
aGuard( getMutex() );
431 impl_validateObjectTypeAndName_throw( ObjectType
, ObjectName
);
433 Reference
< XComponent
> xComponent( openElementWithArguments(
435 lcl_objectType2ElementType( ObjectType
),
436 ForEditing
? ElementOpenMode::Design
: ElementOpenMode::Normal
,
437 ForEditing
? SID_DB_APP_EDIT
: SID_DB_APP_OPEN
,
438 ::comphelper::NamedValueCollection( Arguments
)
444 Reference
< XComponent
> SAL_CALL
OApplicationController::createComponent( ::sal_Int32 i_nObjectType
, Reference
< XComponent
>& o_DocumentDefinition
)
446 return createComponentWithArguments( i_nObjectType
, Sequence
< PropertyValue
>(), o_DocumentDefinition
);
449 Reference
< XComponent
> SAL_CALL
OApplicationController::createComponentWithArguments( ::sal_Int32 i_nObjectType
, const Sequence
< PropertyValue
>& i_rArguments
, Reference
< XComponent
>& o_DocumentDefinition
)
451 SolarMutexGuard aSolarGuard
;
452 ::osl::MutexGuard
aGuard( getMutex() );
454 impl_validateObjectTypeAndName_throw( i_nObjectType
, ::std::optional
< OUString
>() );
456 Reference
< XComponent
> xComponent( newElement(
457 lcl_objectType2ElementType( i_nObjectType
),
458 ::comphelper::NamedValueCollection( i_rArguments
),
465 void SAL_CALL
OApplicationController::registerContextMenuInterceptor( const Reference
< XContextMenuInterceptor
>& Interceptor
)
467 if ( Interceptor
.is() )
468 m_aContextMenuInterceptors
.addInterface( Interceptor
);
471 void SAL_CALL
OApplicationController::releaseContextMenuInterceptor( const Reference
< XContextMenuInterceptor
>& Interceptor
)
473 m_aContextMenuInterceptors
.removeInterface( Interceptor
);
476 void OApplicationController::previewChanged( sal_Int32 _nMode
)
478 SolarMutexGuard aSolarGuard
;
479 ::osl::MutexGuard
aGuard( getMutex() );
481 if ( m_xDataSource
.is() && !isDataSourceReadOnly() )
485 ::comphelper::NamedValueCollection
aLayoutInfo( m_xDataSource
->getPropertyValue( PROPERTY_LAYOUTINFORMATION
) );
486 sal_Int32 nOldMode
= aLayoutInfo
.getOrDefault( "Preview", _nMode
);
487 if ( nOldMode
!= _nMode
)
489 aLayoutInfo
.put( "Preview", _nMode
);
490 m_xDataSource
->setPropertyValue( PROPERTY_LAYOUTINFORMATION
, Any( aLayoutInfo
.getPropertyValues() ) );
493 catch ( const Exception
& )
495 DBG_UNHANDLED_EXCEPTION("dbaccess");
498 InvalidateFeature(SID_DB_APP_DISABLE_PREVIEW
);
499 InvalidateFeature(SID_DB_APP_VIEW_DOCINFO_PREVIEW
);
500 InvalidateFeature(SID_DB_APP_VIEW_DOC_PREVIEW
);
503 void OApplicationController::askToReconnect()
505 if ( !m_bNeedToReconnect
)
508 m_bNeedToReconnect
= false;
510 if ( !m_pSubComponentManager
->empty() )
512 std::unique_ptr
<weld::MessageDialog
> xQry(Application::CreateMessageDialog(getFrameWeld(),
513 VclMessageType::Question
, VclButtonsType::YesNo
,
514 DBA_RES(STR_QUERY_CLOSEDOCUMENTS
)));
518 closeSubComponents();
527 ElementType eType
= getContainer()->getElementType();
529 getContainer()->getDetailView()->clearPages(false);
530 getContainer()->selectContainer(E_NONE
); // invalidate the old selection
531 m_eCurrentType
= E_NONE
;
532 getContainer()->selectContainer(eType
); // reselect the current one again
536 OUString
OApplicationController::getDatabaseName() const
538 OUString sDatabaseName
;
541 if ( m_xDataSource
.is() )
543 OSL_VERIFY( m_xDataSource
->getPropertyValue( PROPERTY_NAME
) >>= sDatabaseName
);
546 catch ( const Exception
& )
548 DBG_UNHANDLED_EXCEPTION("dbaccess");
550 return sDatabaseName
;
553 OUString
OApplicationController::getStrippedDatabaseName() const
555 OUString sDatabaseName
;
556 return ::dbaui::getStrippedDatabaseName( m_xDataSource
, sDatabaseName
);
559 void OApplicationController::onDocumentOpened( const OUString
& _rName
, const sal_Int32 _nType
,
560 const ElementOpenMode _eMode
, const Reference
< XComponent
>& _xDocument
, const Reference
< XComponent
>& _rxDefinition
)
562 if ( !_xDocument
.is() )
567 OSL_ENSURE( _xDocument
.is(), "OApplicationController::onDocumentOpened: is there any *valid* scenario where this fails?" );
568 m_pSubComponentManager
->onSubComponentOpened( _rName
, _nType
, _eMode
, _xDocument
.is() ? _xDocument
: _rxDefinition
);
570 if ( _rxDefinition
.is() )
572 Reference
< XPropertySet
> xProp( _rxDefinition
, UNO_QUERY_THROW
);
573 Reference
< XPropertySetInfo
> xPSI( xProp
->getPropertySetInfo(), UNO_SET_THROW
);
574 xProp
->addPropertyChangeListener( PROPERTY_NAME
, static_cast< XPropertyChangeListener
* >( this ) );
577 catch( const Exception
& )
579 DBG_UNHANDLED_EXCEPTION("dbaccess");
583 bool OApplicationController::insertHierarchyElement(ElementType _eType
, const OUString
& _sParentFolder
, bool _bCollection
, const Reference
<XContent
>& _xContent
, bool _bMove
)
585 Reference
<XHierarchicalNameContainer
> xNames(getElements(_eType
), UNO_QUERY
);
586 return dbaui::insertHierarchyElement(getFrameWeld()
596 bool OApplicationController::isRenameDeleteAllowed(ElementType _eType
, bool _bDelete
) const
598 ElementType eType
= getContainer()->getElementType();
599 bool bEnabled
= !isDataSourceReadOnly() && eType
== _eType
;
603 if ( E_TABLE
== eType
)
604 bEnabled
= !isConnectionReadOnly() && getContainer()->isALeafSelected();
606 bool bCompareRes
= false;
608 bCompareRes
= getContainer()->getSelectionCount() > 0;
611 bCompareRes
= getContainer()->getSelectionCount() == 1;
612 if ( bEnabled
&& bCompareRes
&& E_TABLE
== eType
)
614 std::vector
< OUString
> aList
;
615 getSelectionElementNames(aList
);
619 Reference
< XNameAccess
> xContainer
= const_cast<OApplicationController
*>(this)->getElements(eType
);
620 bEnabled
= (xContainer
.is() && xContainer
->hasByName(*aList
.begin()));
622 bEnabled
= Reference
<XRename
>(xContainer
->getByName(*aList
.begin()),UNO_QUERY
).is();
631 bEnabled
= bEnabled
&& bCompareRes
;
636 void OApplicationController::onLoadedMenu(const Reference
< css::frame::XLayoutManager
>& _xLayoutManager
)
639 if ( !_xLayoutManager
.is() )
642 static constexpr OUStringLiteral s_sStatusbar
= u
"private:resource/statusbar/statusbar";
643 _xLayoutManager
->createElement( s_sStatusbar
);
644 _xLayoutManager
->requestElement( s_sStatusbar
);
646 if ( getContainer() )
648 // we need to share the "mnemonic space":
649 MnemonicGenerator aMnemonicGenerator
;
650 // - the menu already has mnemonics
651 if (SystemWindow
* pSystemWindow
= getContainer()->GetSystemWindow())
652 pSystemWindow
->CollectMenuBarMnemonics(aMnemonicGenerator
);
653 // - the icons should use automatic ones
654 getContainer()->createIconAutoMnemonics( aMnemonicGenerator
);
655 // - as well as the entries in the task pane
656 getContainer()->setTaskExternalMnemonics( aMnemonicGenerator
);
659 Execute( SID_DB_APP_VIEW_FORMS
, Sequence
< PropertyValue
>() );
663 void OApplicationController::doAction(sal_uInt16 _nId
, const ElementOpenMode _eOpenMode
)
665 std::vector
< OUString
> aList
;
666 getSelectionElementNames(aList
);
667 ElementType eType
= getContainer()->getElementType();
668 ::comphelper::NamedValueCollection aArguments
;
669 ElementOpenMode eOpenMode
= _eOpenMode
;
670 if ( eType
== E_REPORT
&& ElementOpenMode::Mail
== _eOpenMode
)
672 aArguments
.put("Hidden",true);
673 eOpenMode
= ElementOpenMode::Normal
;
676 std::vector
< std::pair
< OUString
,Reference
< XModel
> > > aComponents
;
677 for (auto const& elem
: aList
)
679 if ( SID_DB_APP_CONVERTTOVIEW
== _nId
)
683 Reference
< XModel
> xModel( openElementWithArguments( elem
, eType
, eOpenMode
, _nId
,aArguments
), UNO_QUERY
);
684 aComponents
.emplace_back( elem
, xModel
);
688 // special handling for mail, if more than one document is selected attach them all
689 if ( _eOpenMode
!= ElementOpenMode::Mail
)
693 SfxMailModel aSendMail
;
694 SfxMailModel::SendMailResult eResult
= SfxMailModel::SEND_MAIL_OK
;
695 for (auto const& component
: aComponents
)
699 Reference
< XModel
> xModel
= component
.second
;
701 // Send document as e-Mail using stored/default type
702 eResult
= aSendMail
.AttachDocument(xModel
,component
.first
);
703 ::comphelper::disposeComponent(xModel
);
704 if (eResult
!= SfxMailModel::SEND_MAIL_OK
)
707 catch(const Exception
&)
709 DBG_UNHANDLED_EXCEPTION("dbaccess");
712 if ( !aSendMail
.IsEmpty() )
713 aSendMail
.Send( getFrame() );
716 ElementType
OApplicationController::getElementType(const Reference
< XContainer
>& _xContainer
)
718 ElementType eRet
= E_NONE
;
719 Reference
<XServiceInfo
> xServiceInfo(_xContainer
,UNO_QUERY
);
720 if ( xServiceInfo
.is() )
722 if ( xServiceInfo
->supportsService(SERVICE_SDBCX_TABLES
) )
724 else if ( xServiceInfo
->supportsService(SERVICE_NAME_FORM_COLLECTION
) )
726 else if ( xServiceInfo
->supportsService(SERVICE_NAME_REPORT_COLLECTION
) )
736 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */