diff options
author | Caolán McNamara <caolanm@redhat.com> | 2019-08-29 20:17:53 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2019-08-30 22:18:37 +0200 |
commit | 69fbf74d5bf9c474a6ec04101426dfe79b4ad9bf (patch) | |
tree | b7ca5a562f9f2a65a04264e8dfdc0db0439d9da0 /svx | |
parent | 8cecd48af5dbd290d06641b7feeb7c0969752d57 (diff) |
weld addressbook wizard
Change-Id: I118ed34ddaf7d62e5bb15497399cd10533339328
Reviewed-on: https://gerrit.libreoffice.org/78287
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'svx')
-rw-r--r-- | svx/source/form/databaselocationinput.cxx | 259 |
1 files changed, 220 insertions, 39 deletions
diff --git a/svx/source/form/databaselocationinput.cxx b/svx/source/form/databaselocationinput.cxx index 620ab6af29d9..8b90fb2cd7d9 100644 --- a/svx/source/form/databaselocationinput.cxx +++ b/svx/source/form/databaselocationinput.cxx @@ -55,10 +55,208 @@ namespace svx public: DatabaseLocationInputController_Impl( const Reference<XComponentContext>& _rContext, + URLBox& _rLocationInput, + weld::Button& _rBrowseButton, + weld::Window& _rDialog + ); + + bool prepareCommit(); + void setURL( const OUString& _rURL ); + OUString getURL() const; + + private: + void impl_initFilterProperties_nothrow(); + void impl_onBrowseButtonClicked(); + OUString impl_getCurrentURL() const; + + DECL_LINK( OnButtonAction, weld::Button&, void ); + + private: + const Reference<XComponentContext> m_xContext; + URLBox& m_rLocationInput; + weld::Button& m_rBrowseButton; + weld::Window& m_rDialog; + Sequence< OUString > m_aFilterExtensions; + OUString m_sFilterUIName; + bool m_bNeedExistenceCheck; + }; + + DatabaseLocationInputController_Impl::DatabaseLocationInputController_Impl(const Reference<XComponentContext>& _rContext, + URLBox& _rLocationInput, weld::Button& _rBrowseButton, weld::Window& _rDialog) + :m_xContext( _rContext ) + ,m_rLocationInput( _rLocationInput ) + ,m_rBrowseButton( _rBrowseButton ) + ,m_rDialog( _rDialog ) + ,m_aFilterExtensions() + ,m_sFilterUIName() + ,m_bNeedExistenceCheck( true ) + { + impl_initFilterProperties_nothrow(); + + // forward the allowed extensions to the input control + OUStringBuffer aExtensionList; + for ( auto const & extension : std::as_const(m_aFilterExtensions) ) + { + aExtensionList.append( extension ); + aExtensionList.append( ';' ); + } + m_rLocationInput.SetFilter( aExtensionList.makeStringAndClear() ); + m_rBrowseButton.connect_clicked(LINK(this, DatabaseLocationInputController_Impl, OnButtonAction)); + } + + bool DatabaseLocationInputController_Impl::prepareCommit() + { + OUString sURL( impl_getCurrentURL() ); + if ( sURL.isEmpty() ) + return false; + + // check if the name exists + if ( m_bNeedExistenceCheck ) + { + if ( ::utl::UCBContentHelper::Exists( sURL ) ) + { + std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(m_rLocationInput.getWidget(), + VclMessageType::Question, VclButtonsType::YesNo, + SvxResId(RID_STR_ALREADYEXISTOVERWRITE))); + if (xQueryBox->run() != RET_YES) + return false; + } + } + + return true; + } + + void DatabaseLocationInputController_Impl::setURL( const OUString& _rURL ) + { + ::svt::OFileNotation aTransformer( _rURL ); + m_rLocationInput.set_entry_text( aTransformer.get( ::svt::OFileNotation::N_SYSTEM ) ); + } + + OUString DatabaseLocationInputController_Impl::getURL() const + { + return impl_getCurrentURL(); + } + + void DatabaseLocationInputController_Impl::impl_initFilterProperties_nothrow() + { + try + { + // get the name of the default filter for database documents + ::utl::OConfigurationTreeRoot aConfig( + ::utl::OConfigurationTreeRoot::createWithComponentContext( + m_xContext, + "/org.openoffice.Setup/Office/Factories/com.sun.star.sdb.OfficeDatabaseDocument" + ) ); + OUString sDatabaseFilter; + OSL_VERIFY( aConfig.getNodeValue( "ooSetupFactoryActualFilter" ) >>= sDatabaseFilter ); + + // get the type this filter is responsible for + Reference< XNameAccess > xFilterFactory( + m_xContext->getServiceManager()->createInstanceWithContext("com.sun.star.document.FilterFactory", m_xContext), + UNO_QUERY_THROW ); + ::comphelper::NamedValueCollection aFilterProperties( xFilterFactory->getByName( sDatabaseFilter ) ); + OUString sDocumentType = aFilterProperties.getOrDefault( "Type", OUString() ); + + // get the extension(s) for this type + Reference< XNameAccess > xTypeDetection( + m_xContext->getServiceManager()->createInstanceWithContext("com.sun.star.document.TypeDetection", m_xContext), + UNO_QUERY_THROW ); + + ::comphelper::NamedValueCollection aTypeProperties( xTypeDetection->getByName( sDocumentType ) ); + m_aFilterExtensions = aTypeProperties.getOrDefault( "Extensions", m_aFilterExtensions ); + m_sFilterUIName = aTypeProperties.getOrDefault( "UIName", m_sFilterUIName ); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION("svx"); + } + + // ensure we have at least one extension + OSL_ENSURE( m_aFilterExtensions.hasElements(), + "DatabaseLocationInputController_Impl::impl_initFilterProperties_nothrow: unable to determine the file extension(s)!" ); + if ( !m_aFilterExtensions.hasElements() ) + { + m_aFilterExtensions.realloc(1); + m_aFilterExtensions[0] = "*.odb"; + } + } + + IMPL_LINK_NOARG(DatabaseLocationInputController_Impl, OnButtonAction, weld::Button&, void) + { + impl_onBrowseButtonClicked(); + } + + OUString DatabaseLocationInputController_Impl::impl_getCurrentURL() const + { + OUString sCurrentFile( m_rLocationInput.get_active_text() ); + if ( !sCurrentFile.isEmpty() ) + { + ::svt::OFileNotation aCurrentFile( sCurrentFile ); + sCurrentFile = aCurrentFile.get( ::svt::OFileNotation::N_URL ); + } + return sCurrentFile; + } + + void DatabaseLocationInputController_Impl::impl_onBrowseButtonClicked() + { + ::sfx2::FileDialogHelper aFileDlg( + TemplateDescription::FILESAVE_AUTOEXTENSION, + FileDialogFlags::NONE, + &m_rDialog + ); + aFileDlg.SetDisplayDirectory( impl_getCurrentURL() ); + + aFileDlg.AddFilter( m_sFilterUIName, "*." + m_aFilterExtensions[0] ); + aFileDlg.SetCurrentFilter( m_sFilterUIName ); + + if ( aFileDlg.Execute() == ERRCODE_NONE ) + { + INetURLObject aURL( aFileDlg.GetPath() ); + if( aURL.GetProtocol() != INetProtocol::NotValid ) + { + ::svt::OFileNotation aFileNotation( aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ) ); + m_rLocationInput.set_entry_text(aFileNotation.get(::svt::OFileNotation::N_SYSTEM)); + m_rLocationInput.trigger_changed(); + // the dialog already checked for the file's existence, so we don't need to, again + m_bNeedExistenceCheck = false; + } + } + } + + DatabaseLocationInputController::DatabaseLocationInputController( const Reference<XComponentContext>& _rContext, + URLBox& _rLocationInput, weld::Button& _rBrowseButton, weld::Window& _rDialog ) + :m_pImpl( new DatabaseLocationInputController_Impl( _rContext, _rLocationInput, _rBrowseButton, _rDialog ) ) + { + } + + DatabaseLocationInputController::~DatabaseLocationInputController() + { + } + + bool DatabaseLocationInputController::prepareCommit() + { + return m_pImpl->prepareCommit(); + } + + void DatabaseLocationInputController::setURL( const OUString& _rURL ) + { + m_pImpl->setURL( _rURL ); + } + + OUString DatabaseLocationInputController::getURL() const + { + return m_pImpl->getURL(); + } + + class SvxDatabaseLocationInputController_Impl + { + public: + SvxDatabaseLocationInputController_Impl( + const Reference<XComponentContext>& _rContext, ::svt::OFileURLControl& _rLocationInput, PushButton& _rBrowseButton ); - ~DatabaseLocationInputController_Impl(); + ~SvxDatabaseLocationInputController_Impl(); bool prepareCommit(); void setURL( const OUString& _rURL ); @@ -80,9 +278,9 @@ namespace svx bool m_bNeedExistenceCheck; }; - - DatabaseLocationInputController_Impl::DatabaseLocationInputController_Impl( const Reference<XComponentContext>& _rContext, - ::svt::OFileURLControl& _rLocationInput, PushButton& _rBrowseButton ) + SvxDatabaseLocationInputController_Impl::SvxDatabaseLocationInputController_Impl(const Reference<XComponentContext>& _rContext, + ::svt::OFileURLControl& _rLocationInput, + PushButton& _rBrowseButton) :m_xContext( _rContext ) ,m_rLocationInput( _rLocationInput ) ,m_rBrowseButton( _rBrowseButton ) @@ -100,20 +298,17 @@ namespace svx aExtensionList.append( ';' ); } m_rLocationInput.SetFilter( aExtensionList.makeStringAndClear() ); - - m_rBrowseButton.AddEventListener( LINK( this, DatabaseLocationInputController_Impl, OnControlAction ) ); - m_rLocationInput.AddEventListener( LINK( this, DatabaseLocationInputController_Impl, OnControlAction ) ); + m_rBrowseButton.AddEventListener( LINK( this, SvxDatabaseLocationInputController_Impl, OnControlAction ) ); + m_rLocationInput.AddEventListener( LINK( this, SvxDatabaseLocationInputController_Impl, OnControlAction ) ); } - - DatabaseLocationInputController_Impl::~DatabaseLocationInputController_Impl() + SvxDatabaseLocationInputController_Impl::~SvxDatabaseLocationInputController_Impl() { - m_rBrowseButton.RemoveEventListener( LINK( this, DatabaseLocationInputController_Impl, OnControlAction ) ); - m_rLocationInput.RemoveEventListener( LINK( this, DatabaseLocationInputController_Impl, OnControlAction ) ); + m_rBrowseButton.RemoveEventListener( LINK( this, SvxDatabaseLocationInputController_Impl, OnControlAction ) ); + m_rLocationInput.RemoveEventListener( LINK( this, SvxDatabaseLocationInputController_Impl, OnControlAction ) ); } - - bool DatabaseLocationInputController_Impl::prepareCommit() + bool SvxDatabaseLocationInputController_Impl::prepareCommit() { OUString sURL( impl_getCurrentURL() ); if ( sURL.isEmpty() ) @@ -135,21 +330,18 @@ namespace svx return true; } - - void DatabaseLocationInputController_Impl::setURL( const OUString& _rURL ) + void SvxDatabaseLocationInputController_Impl::setURL( const OUString& _rURL ) { ::svt::OFileNotation aTransformer( _rURL ); m_rLocationInput.SetText( aTransformer.get( ::svt::OFileNotation::N_SYSTEM ) ); } - - OUString DatabaseLocationInputController_Impl::getURL() const + OUString SvxDatabaseLocationInputController_Impl::getURL() const { return impl_getCurrentURL(); } - - void DatabaseLocationInputController_Impl::impl_initFilterProperties_nothrow() + void SvxDatabaseLocationInputController_Impl::impl_initFilterProperties_nothrow() { try { @@ -193,8 +385,7 @@ namespace svx } } - - IMPL_LINK( DatabaseLocationInputController_Impl, OnControlAction, VclWindowEvent&, _rEvent, void ) + IMPL_LINK( SvxDatabaseLocationInputController_Impl, OnControlAction, VclWindowEvent&, _rEvent, void ) { if ( ( _rEvent.GetWindow() == &m_rBrowseButton ) && ( _rEvent.GetId() == VclEventId::ButtonClick ) @@ -211,8 +402,7 @@ namespace svx } } - - OUString DatabaseLocationInputController_Impl::impl_getCurrentURL() const + OUString SvxDatabaseLocationInputController_Impl::impl_getCurrentURL() const { OUString sCurrentFile( m_rLocationInput.GetText() ); if ( !sCurrentFile.isEmpty() ) @@ -223,8 +413,7 @@ namespace svx return sCurrentFile; } - - void DatabaseLocationInputController_Impl::impl_onBrowseButtonClicked() + void SvxDatabaseLocationInputController_Impl::impl_onBrowseButtonClicked() { ::sfx2::FileDialogHelper aFileDlg( TemplateDescription::FILESAVE_AUTOEXTENSION, @@ -249,39 +438,31 @@ namespace svx } } } - - - DatabaseLocationInputController::DatabaseLocationInputController( const Reference<XComponentContext>& _rContext, + SvxDatabaseLocationInputController::SvxDatabaseLocationInputController( const Reference<XComponentContext>& _rContext, ::svt::OFileURLControl& _rLocationInput, PushButton& _rBrowseButton ) - :m_pImpl( new DatabaseLocationInputController_Impl( _rContext, _rLocationInput, _rBrowseButton ) ) + :m_pImpl( new SvxDatabaseLocationInputController_Impl( _rContext, _rLocationInput, _rBrowseButton ) ) { } - - DatabaseLocationInputController::~DatabaseLocationInputController() + SvxDatabaseLocationInputController::~SvxDatabaseLocationInputController() { } - - bool DatabaseLocationInputController::prepareCommit() + bool SvxDatabaseLocationInputController::prepareCommit() { return m_pImpl->prepareCommit(); } - - void DatabaseLocationInputController::setURL( const OUString& _rURL ) + void SvxDatabaseLocationInputController::setURL( const OUString& _rURL ) { m_pImpl->setURL( _rURL ); } - - OUString DatabaseLocationInputController::getURL() const + OUString SvxDatabaseLocationInputController::getURL() const { return m_pImpl->getURL(); } - } - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |