diff options
Diffstat (limited to 'fpicker/source/office/RemoteFilesDialog.cxx')
-rw-r--r-- | fpicker/source/office/RemoteFilesDialog.cxx | 145 |
1 files changed, 55 insertions, 90 deletions
diff --git a/fpicker/source/office/RemoteFilesDialog.cxx b/fpicker/source/office/RemoteFilesDialog.cxx index 30115abd93e8..ad23cc0dd888 100644 --- a/fpicker/source/office/RemoteFilesDialog.cxx +++ b/fpicker/source/office/RemoteFilesDialog.cxx @@ -12,16 +12,15 @@ #include "fpsmartcontent.hxx" #include "QueryFolderName.hxx" #include "RemoteFilesDialog.hxx" -#include <fpsofficeResMgr.hxx> +#include <fpicker/fpsofficeResMgr.hxx> #include <fpicker/strings.hrc> #include <strings.hrc> #include <comphelper/docpasswordrequest.hxx> -#include <comphelper/stillreadwriteinteraction.hxx> #include <com/sun/star/task/InteractionHandler.hpp> #include <com/sun/star/task/PasswordContainer.hpp> #include <svtools/PlaceEditDialog.hxx> #include <tools/debug.hxx> -#include <ucbhelper/commandenvironment.hxx> +#include <unotools/ucbhelper.hxx> #include <vcl/errinf.hxx> #include <officecfg/Office/Common.hxx> @@ -32,6 +31,7 @@ RemoteFilesDialog::RemoteFilesDialog( weld::Window* pParent, PickerFlags nBits ) , m_xContext( comphelper::getProcessComponentContext() ) , m_xMasterPasswd( PasswordContainer::create( m_xContext ) ) , m_bIsInExecute( false ) + , m_xOk_btn(m_xBuilder->weld_button("ok")) , m_xCancel_btn(m_xBuilder->weld_button("cancel")) , m_xManageServices(m_xBuilder->weld_menu_button("add_service_btn")) , m_xServices_lb(m_xBuilder->weld_combo_box("services_lb")) @@ -61,13 +61,11 @@ RemoteFilesDialog::RemoteFilesDialog( weld::Window* pParent, PickerFlags nBits ) if( m_eMode == REMOTEDLG_MODE_OPEN ) { - m_xOk_btn = m_xBuilder->weld_button("open"); - m_xNewFolder->hide(); } else { - m_xOk_btn = m_xBuilder->weld_button("save"); + m_xOk_btn->set_label(FpsResId(STR_EXPLORERFILE_BUTTONSAVE)); m_xNewFolder->connect_clicked( LINK( this, RemoteFilesDialog, NewFolderHdl ) ); } @@ -75,7 +73,6 @@ RemoteFilesDialog::RemoteFilesDialog( weld::Window* pParent, PickerFlags nBits ) m_xIconView_btn->connect_clicked( LINK( this, RemoteFilesDialog, IconViewHdl ) ); m_xListView_btn->connect_clicked( LINK( this, RemoteFilesDialog, ListViewHdl ) ); - m_xOk_btn->show(); m_xOk_btn->set_sensitive(false); m_xOk_btn->connect_clicked( LINK( this, RemoteFilesDialog, OkHdl ) ); @@ -127,7 +124,7 @@ RemoteFilesDialog::~RemoteFilesDialog() if( !m_sIniKey.isEmpty() ) { SvtViewOptions aDlgOpt( EViewType::Dialog, m_sIniKey ); - aDlgOpt.SetWindowState(OStringToOUString(m_xDialog->get_window_state(WindowStateMask::All), RTL_TEXTENCODING_UTF8)); + aDlgOpt.SetWindowState(m_xDialog->get_window_state(vcl::WindowDataMask::All)); Size aSize(m_xDialog->get_size()); @@ -136,24 +133,26 @@ RemoteFilesDialog::~RemoteFilesDialog() OUString sUserData = m_xFileView->GetConfigString(); aDlgOpt.SetUserItem( "UserData", - makeAny( sSize + sUserData ) ); + Any( sSize + sUserData ) ); } // save services - std::shared_ptr< comphelper::ConfigurationChanges > batch( comphelper::ConfigurationChanges::create( m_xContext ) ); + std::shared_ptr< comphelper::ConfigurationChanges > batch( comphelper::ConfigurationChanges::create() ); officecfg::Office::Common::Misc::FilePickerLastService::set( m_sLastServiceUrl, batch ); if( m_bIsUpdated ) { Sequence< OUString > placesUrlsList( m_aServices.size() ); + auto placesUrlsListRange = asNonConstRange(placesUrlsList); Sequence< OUString > placesNamesList( m_aServices.size() ); + auto placesNamesListRange = asNonConstRange(placesNamesList); int i = 0; for (auto const& service : m_aServices) { - placesUrlsList[i] = service->GetUrl(); - placesNamesList[i] = service->GetName(); + placesUrlsListRange[i] = service->GetUrl(); + placesNamesListRange[i] = service->GetName(); ++i; } @@ -196,8 +195,6 @@ static OUString lcl_GetServiceType( const ServicePtr& pService ) INetProtocol aProtocol = pService->GetUrlObject().GetProtocol(); switch( aProtocol ) { - case INetProtocol::Ftp: - return "FTP"; case INetProtocol::Cmis: { OUString sHost = pService->GetUrlObject().GetHost( INetURLObject::DecodeMechanism::WithCharset ); @@ -237,7 +234,7 @@ void RemoteFilesDialog::InitSize() if( !aDlgOpt.Exists() ) return; - m_xDialog->set_window_state(OUStringToOString(aDlgOpt.GetWindowState(), RTL_TEXTENCODING_UTF8)); + m_xDialog->set_window_state(aDlgOpt.GetWindowState()); Any aUserData = aDlgOpt.GetUserItem( "UserData" ); OUString sCfgStr; @@ -249,7 +246,7 @@ void RemoteFilesDialog::InitSize() sal_Int32 nPos2{ sCfgStr.indexOf('|', nPos1+1 ) }; if (nPos2<0) return; - m_xFileView->SetConfigString( sCfgStr.copy(nPos2+1) ); + m_xFileView->SetConfigString( sCfgStr.subView(nPos2+1) ); } } @@ -259,13 +256,13 @@ void RemoteFilesDialog::FillServicesListbox() m_aServices.clear(); // Load from user settings - Sequence< OUString > placesUrlsList( officecfg::Office::Common::Misc::FilePickerPlacesUrls::get( m_xContext ) ); - Sequence< OUString > placesNamesList( officecfg::Office::Common::Misc::FilePickerPlacesNames::get( m_xContext ) ); + Sequence< OUString > placesUrlsList( officecfg::Office::Common::Misc::FilePickerPlacesUrls::get() ); + Sequence< OUString > placesNamesList( officecfg::Office::Common::Misc::FilePickerPlacesNames::get() ); unsigned int nPos = 0; unsigned int i = 0; - m_sLastServiceUrl = officecfg::Office::Common::Misc::FilePickerLastService::get( m_xContext ); + m_sLastServiceUrl = officecfg::Office::Common::Misc::FilePickerLastService::get(); for( sal_Int32 nPlace = 0; nPlace < placesUrlsList.getLength() && nPlace < placesNamesList.getLength(); ++nPlace ) { @@ -381,21 +378,18 @@ void RemoteFilesDialog::OpenURL( OUString const & sURL ) } } -void RemoteFilesDialog::AddFileExtension() +OUString RemoteFilesDialog::AddFileExtension(const OUString& rFileName) { if (m_nCurrentFilter == -1) - return; + return rFileName; OUString sExt = m_aFilters[m_nCurrentFilter].second; - OUString sFileName = m_xName_ed->get_text(); + sal_Int32 nDotPos = rFileName.lastIndexOf( '.' ); - sal_Int32 nDotPos = sFileName.lastIndexOf( '.' ); + if (nDotPos == -1) + return rFileName + sExt.subView( 1 ); // without '*' - if ( nDotPos == -1 ) - { - sFileName += sExt.subView( 1 ); // without '*' - m_xName_ed->set_text( sFileName ); - } + return rFileName; } void RemoteFilesDialog::EnableControls() @@ -570,9 +564,9 @@ IMPL_LINK_NOARG( RemoteFilesDialog, SelectServiceHdl, weld::ComboBox&, void ) } } -IMPL_LINK ( RemoteFilesDialog, EditServiceMenuHdl, const OString&, rIdent, void ) +IMPL_LINK ( RemoteFilesDialog, EditServiceMenuHdl, const OUString&, rIdent, void ) { - OString sIdent(rIdent); + OUString sIdent(rIdent); if( sIdent == "edit_service" && m_xServices_lb->get_count() > 0 ) { int nSelected = m_xServices_lb->get_active(); @@ -683,16 +677,14 @@ IMPL_LINK ( RemoteFilesDialog, EditServiceMenuHdl, const OString&, rIdent, void { OUString sUserName = aURLEntries.UserList[0].UserName; - ::comphelper::SimplePasswordRequest* pPasswordRequest + rtl::Reference<::comphelper::SimplePasswordRequest> pPasswordRequest = new ::comphelper::SimplePasswordRequest; - Reference< XInteractionRequest > rRequest( pPasswordRequest ); - xInteractionHandler->handle( rRequest ); + xInteractionHandler->handle( pPasswordRequest ); if ( pPasswordRequest->isPassword() ) { - OUString aNewPass = pPasswordRequest->getPassword(); - Sequence<OUString> aPasswd { aNewPass }; + Sequence<OUString> aPasswd { pPasswordRequest->getPassword() }; m_xMasterPasswd->addPersistent( sUrl, sUserName, aPasswd, xInteractionHandler ); @@ -716,7 +708,7 @@ IMPL_LINK_NOARG( RemoteFilesDialog, DoubleClickHdl, SvtFileView*, bool ) if (pData) { if (!pData->mbIsFolder) - m_xDialog->response(RET_OK); + OkHdl(*m_xOk_btn); else OpenURL(pData->maURL); } @@ -828,18 +820,18 @@ IMPL_LINK_NOARG ( RemoteFilesDialog, NewFolderHdl, weld::Button&, void ) IMPL_LINK_NOARG ( RemoteFilesDialog, OkHdl, weld::Button&, void ) { - OUString sNameNoExt = m_xName_ed->get_text(); - OUString sPathNoExt; - - // auto extension - if( m_eMode == REMOTEDLG_MODE_SAVE ) - AddFileExtension(); + OUString sUserSelectedPath; // check if file/path exists - OUString sCurrentPath = m_xFileView->GetViewURL(); OUString sSelectedItem = m_xFileView->GetCurrentURL(); - OUString sName = m_xName_ed->get_text(); + OUString sUserTypedName = m_xName_ed->get_text(); + OUString sFileName; + // auto extension + if( m_eMode == REMOTEDLG_MODE_SAVE ) + sFileName = AddFileExtension(sUserTypedName); + else + sFileName = sUserTypedName; bool bFileDlg = ( m_eType == REMOTEDLG_TYPE_FILEDLG ); bool bSelected = ( m_xFileView->GetSelectionCount() > 0 ); @@ -849,8 +841,8 @@ IMPL_LINK_NOARG ( RemoteFilesDialog, OkHdl, weld::Button&, void ) if( !bSelected ) { - m_sPath = sCurrentPath + INetURLObject::encode( sName, INetURLObject::PART_FPATH, INetURLObject::EncodeMechanism::All ); - sPathNoExt = sCurrentPath + INetURLObject::encode( sNameNoExt, INetURLObject::PART_FPATH, INetURLObject::EncodeMechanism::All ); + m_sPath = sCurrentPath + INetURLObject::encode(sFileName, INetURLObject::PART_FPATH, INetURLObject::EncodeMechanism::All); + sUserSelectedPath = sCurrentPath + INetURLObject::encode(sUserTypedName, INetURLObject::PART_FPATH, INetURLObject::EncodeMechanism::All); } else { @@ -866,6 +858,7 @@ IMPL_LINK_NOARG ( RemoteFilesDialog, OkHdl, weld::Button&, void ) aURL.SetUser( aCurrentURL.GetUser() ); m_sPath = aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ); + sUserSelectedPath = m_sPath; } bool bExists = false; @@ -880,7 +873,7 @@ IMPL_LINK_NOARG ( RemoteFilesDialog, OkHdl, weld::Button&, void ) if( m_eMode == REMOTEDLG_MODE_SAVE ) { OUString sMsg = FpsResId( STR_SVT_ALREADYEXISTOVERWRITE ); - sMsg = sMsg.replaceFirst( "$filename$", sName ); + sMsg = sMsg.replaceFirst("$filename$", sFileName); std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(m_xDialog.get(), VclMessageType::Question, VclButtonsType::YesNo, sMsg)); if (xBox->run() != RET_YES) @@ -889,10 +882,9 @@ IMPL_LINK_NOARG ( RemoteFilesDialog, OkHdl, weld::Button&, void ) } else { - if( ContentIsFolder( sPathNoExt ) ) + if (ContentIsFolder(sUserSelectedPath)) { - OpenURL( sPathNoExt ); - m_xName_ed->set_text( "" ); + OpenURL(sUserSelectedPath); if (!bSelected) m_xName_ed->grab_focus(); @@ -1088,7 +1080,7 @@ void RemoteFilesDialog::UpdateControls( const OUString& rURL ) if( nTitleStart != -1 ) { OUString sTitle( INetURLObject::decode( - aFolderName.copy( nTitleStart + 1 ), + aFolderName.subView( nTitleStart + 1 ), INetURLObject::DecodeMechanism::WithCharset ) ); if( rFolder.mbIsFolder ) @@ -1145,57 +1137,30 @@ bool RemoteFilesDialog::ContentIsFolder( const OUString& rURL ) { try { - Reference< XInteractionHandler > xInteractionHandler( - InteractionHandler::createWithParent( m_xContext, nullptr ), UNO_QUERY_THROW ); - Reference< XCommandEnvironment > xEnv = new ::ucbhelper::CommandEnvironment( xInteractionHandler, Reference< XProgressHandler >() ); - ::ucbhelper::Content aContent( rURL, xEnv, m_xContext ); - - return aContent.isFolder(); + ::ucbhelper::Content content(rURL, + ::utl::UCBContentHelper::getDefaultCommandEnvironment(), + m_xContext); + return content.isFolder(); } - catch( const Exception& ) + catch (css::uno::Exception const&) { - // a content doesn't exist + return false; } - - return false; } bool RemoteFilesDialog::ContentIsDocument( const OUString& rURL ) { try { - Reference< XInteractionHandler > xInteractionHandler( - InteractionHandler::createWithParent( m_xContext, nullptr ), UNO_QUERY_THROW ); - //check if WebDAV or not - if ( !INetURLObject( rURL ).isAnyKnownWebDAVScheme() ) - { - // no webdav, use the interaction handler as is - Reference< XCommandEnvironment > xEnv = new ::ucbhelper::CommandEnvironment( xInteractionHandler, Reference< XProgressHandler >() ); - ::ucbhelper::Content aContent( rURL, xEnv, m_xContext ); - - return aContent.isDocument(); - } - else - { - // It's a webdav URL, so use the same open sequence as in normal open process. - // Let's use a comphelper::StillReadWriteInteraction to trap errors here without showing the user. - // This sequence will result in an exception if the target URL resource is not present - comphelper::StillReadWriteInteraction* pInteraction = new comphelper::StillReadWriteInteraction(xInteractionHandler,xInteractionHandler); - css::uno::Reference< css::task::XInteractionHandler > xInteraction(static_cast< css::task::XInteractionHandler* >(pInteraction), css::uno::UNO_QUERY); - - Reference< XCommandEnvironment > xEnv = new ::ucbhelper::CommandEnvironment( xInteraction, Reference< XProgressHandler >() ); - ::ucbhelper::Content aContent( rURL, xEnv, m_xContext ); - - aContent.openStream(); - return aContent.isDocument(); - } + ::ucbhelper::Content content(rURL, + ::utl::UCBContentHelper::getDefaultCommandEnvironment(), + m_xContext); + return content.isDocument(); } - catch( const Exception& ) + catch (css::uno::Exception const&) { - // a content doesn't exist + return false; } - - return false; } sal_Int32 RemoteFilesDialog::getAvailableWidth() |