diff options
author | Szymon Kłos <eszkadev@gmail.com> | 2015-07-13 14:29:09 +0200 |
---|---|---|
committer | Szymon Kłos <eszkadev@gmail.com> | 2015-07-16 09:53:52 +0200 |
commit | 2239b486bffaeffafc24ed1b135aa70f3cdd8b1a (patch) | |
tree | 916b021e45487e9f55e2051b3f5a4d23ef76b60c /fpicker | |
parent | 1abade4f92a6d1c70ab3e333770e1cb242f29063 (diff) |
RemoteFilesDialog moved to fpicker
Change-Id: I8e978d40ee022d15f482aec4567c3171b75b9720
Diffstat (limited to 'fpicker')
-rw-r--r-- | fpicker/Library_fps_office.mk | 1 | ||||
-rw-r--r-- | fpicker/source/office/OfficeFilePicker.cxx | 2 | ||||
-rw-r--r-- | fpicker/source/office/RemoteFilesDialog.cxx | 959 | ||||
-rw-r--r-- | fpicker/source/office/RemoteFilesDialog.hxx | 170 |
4 files changed, 1131 insertions, 1 deletions
diff --git a/fpicker/Library_fps_office.mk b/fpicker/Library_fps_office.mk index c109dce3a978..6c484a0a4a31 100644 --- a/fpicker/Library_fps_office.mk +++ b/fpicker/Library_fps_office.mk @@ -49,6 +49,7 @@ $(eval $(call gb_Library_add_exception_objects,fps_office,\ fpicker/source/office/OfficeFilePicker \ fpicker/source/office/OfficeFolderPicker \ fpicker/source/office/PlacesListBox \ + fpicker/source/office/RemoteFilesDialog \ )) # vim: set noet sw=4 ts=4: diff --git a/fpicker/source/office/OfficeFilePicker.cxx b/fpicker/source/office/OfficeFilePicker.cxx index 5846e588face..917a5200fafd 100644 --- a/fpicker/source/office/OfficeFilePicker.cxx +++ b/fpicker/source/office/OfficeFilePicker.cxx @@ -20,7 +20,7 @@ #include "OfficeFilePicker.hxx" #include "iodlg.hxx" -#include <svtools/RemoteFilesDialog.hxx> +#include "RemoteFilesDialog.hxx" #include <list> #include <functional> diff --git a/fpicker/source/office/RemoteFilesDialog.cxx b/fpicker/source/office/RemoteFilesDialog.cxx new file mode 100644 index 000000000000..533940d91f76 --- /dev/null +++ b/fpicker/source/office/RemoteFilesDialog.cxx @@ -0,0 +1,959 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "RemoteFilesDialog.hxx" + +class FileViewContainer : public vcl::Window +{ + private: + VclPtr< SvtFileView > m_pFileView; + VclPtr< FolderTree > m_pTreeView; + VclPtr< Splitter > m_pSplitter; + + int m_nCurrentFocus; + vcl::Window* m_pFocusWidgets[4]; + + public: + FileViewContainer( vcl::Window *pParent ) + : Window( pParent, WB_TABSTOP ) + , m_pFileView( NULL ) + , m_pTreeView( NULL ) + , m_pSplitter( NULL ) + { + } + + virtual ~FileViewContainer() + { + disposeOnce(); + } + + virtual void dispose() SAL_OVERRIDE + { + m_pFileView.clear(); + m_pSplitter.clear(); + vcl::Window::dispose(); + } + + void init( SvtFileView* pFileView, + Splitter* pSplitter, + FolderTree* pTreeView, + vcl::Window* pPrevSibling, + vcl::Window* pNextSibling ) + { + m_pFileView = pFileView; + m_pTreeView = pTreeView; + m_pSplitter = pSplitter; + m_pFocusWidgets[0] = pPrevSibling; + m_pFocusWidgets[1] = pTreeView; + m_pFocusWidgets[2] = pFileView; + m_pFocusWidgets[3] = pNextSibling; + } + + virtual void Resize() SAL_OVERRIDE + { + Window::Resize(); + + if( !m_pFileView || !m_pTreeView ) + return; + + Size aSize = GetSizePixel(); + Point aPos( m_pFileView->GetPosPixel() ); + Size aNewSize( aSize.Width() - aPos.X(), aSize.Height() ); + + m_pFileView->SetSizePixel( aNewSize ); + + // Resize the Splitter to fit the height + Size splitterNewSize = m_pSplitter->GetSizePixel(); + splitterNewSize.Height() = aSize.Height(); + m_pSplitter->SetSizePixel( splitterNewSize ); + sal_Int32 nMinX = m_pTreeView->GetPosPixel().X(); + sal_Int32 nMaxX = m_pFileView->GetPosPixel().X() + m_pFileView->GetSizePixel().Width() - nMinX; + m_pSplitter->SetDragRectPixel( Rectangle( Point( nMinX, 0 ), Size( nMaxX, aSize.Width() ) ) ); + + // Resize the tree list box to fit the height of the FileView + Size placesNewSize( m_pTreeView->GetSizePixel() ); + placesNewSize.Height() = aSize.Height(); + m_pTreeView->SetSizePixel( placesNewSize ); + } + + void changeFocus( bool bReverse ) + { + if( !m_pFileView || !m_pTreeView ) + return; + + if( !bReverse && m_nCurrentFocus < 4 ) + { + m_pFocusWidgets[++m_nCurrentFocus]->SetFakeFocus( true ); + m_pFocusWidgets[m_nCurrentFocus]->GrabFocus(); + } + else if( m_nCurrentFocus > 0 ) + { + m_pFocusWidgets[--m_nCurrentFocus]->SetFakeFocus( true ); + m_pFocusWidgets[m_nCurrentFocus]->GrabFocus(); + } + } + + virtual void GetFocus() SAL_OVERRIDE + { + if( !m_pFileView || !m_pTreeView ) + return; + + m_nCurrentFocus = 1; + m_pFocusWidgets[m_nCurrentFocus]->SetFakeFocus( true ); + m_pFocusWidgets[m_nCurrentFocus]->GrabFocus(); + } + + virtual bool Notify( NotifyEvent& rNEvt ) + { + if( rNEvt.GetType() == MouseNotifyEvent::KEYINPUT ) + { + const KeyEvent* pKeyEvent = rNEvt.GetKeyEvent(); + const vcl::KeyCode& rCode = pKeyEvent->GetKeyCode(); + bool bShift = rCode.IsShift(); + if( rCode.GetCode() == KEY_TAB ) + { + changeFocus( bShift ); + return true; + } + } + return Window::Notify( rNEvt ); + } +}; + +RemoteFilesDialog::RemoteFilesDialog( vcl::Window* pParent, WinBits nBits ) + : SvtFileDialog_Base( pParent, "RemoteFilesDialog", "svt/ui/remotefilesdialog.ui" ) + , m_context( comphelper::getProcessComponentContext() ) + , m_pSplitter( NULL ) + , m_pFileView( NULL ) + , m_pContainer( NULL ) +{ + get( m_pCancel_btn, "cancel" ); + get( m_pAddService_btn, "add_service_btn" ); + get( m_pServices_lb, "services_lb" ); + get( m_pFilter_lb, "filter_lb" ); + get( m_pName_ed, "name_ed" ); + + m_eMode = ( nBits & WB_SAVEAS ) ? REMOTEDLG_MODE_SAVE : REMOTEDLG_MODE_OPEN; + m_eType = ( nBits & WB_PATH ) ? REMOTEDLG_TYPE_PATHDLG : REMOTEDLG_TYPE_FILEDLG; + m_bMultiselection = ( nBits & SFXWB_MULTISELECTION ) ? true : false; + m_bIsUpdated = false; + m_bIsConnected = false; + m_nCurrentFilter = LISTBOX_ENTRY_NOTFOUND; + + m_pFilter_lb->Enable( false ); + m_pName_ed->Enable( false ); + + if( m_eMode == REMOTEDLG_MODE_OPEN ) + get( m_pOk_btn, "open" ); + else + get( m_pOk_btn, "save" ); + + m_pOk_btn->Show(); + m_pOk_btn->Enable( false ); + + m_pOk_btn->SetClickHdl( LINK( this, RemoteFilesDialog, OkHdl ) ); + + m_pPath = VclPtr<Breadcrumb>::Create( get< vcl::Window >( "breadcrumb_container" ) ); + m_pPath->set_hexpand( true ); + m_pPath->SetClickHdl( LINK( this, RemoteFilesDialog, SelectBreadcrumbHdl ) ); + m_pPath->SetMode( SvtBreadcrumbMode::ALL_VISITED ); + m_pPath->Show(); + + m_pContainer = VclPtr< FileViewContainer >::Create( get< vcl::Window >("container") ); + + m_pContainer->set_hexpand( true ); + m_pContainer->set_vexpand( true ); + + m_pFileView = VclPtr< SvtFileView >::Create( m_pContainer, WB_BORDER | WB_TABSTOP, + REMOTEDLG_TYPE_PATHDLG == m_eType, + m_bMultiselection ); + + m_pFileView->Show(); + m_pFileView->EnableAutoResize(); + m_pFileView->SetDoubleClickHdl( LINK( this, RemoteFilesDialog, DoubleClickHdl ) ); + m_pFileView->SetSelectHdl( LINK( this, RemoteFilesDialog, SelectHdl ) ); + + m_pSplitter = VclPtr< Splitter >::Create( m_pContainer, WB_HSCROLL ); + m_pSplitter->SetBackground( Wallpaper( Application::GetSettings().GetStyleSettings().GetFaceColor() ) ); + m_pSplitter->SetSplitHdl( LINK( this, RemoteFilesDialog, SplitHdl ) ); + m_pSplitter->Show(); + + m_pTreeView = VclPtr< FolderTree >::Create( m_pContainer, WB_BORDER ); + Size aSize( 100, 200 ); + m_pTreeView->set_height_request( aSize.Height() ); + m_pTreeView->set_width_request( aSize.Width() ); + m_pTreeView->SetSizePixel( aSize ); + m_pTreeView->Show(); + + m_pTreeView->SetSelectHdl( LINK( this, RemoteFilesDialog, TreeSelectHdl ) ); + + sal_Int32 nPosX = m_pTreeView->GetSizePixel().Width(); + m_pSplitter->SetPosPixel( Point( nPosX, 0 ) ); + nPosX += m_pSplitter->GetSizePixel().Width(); + m_pFileView->SetPosPixel( Point( nPosX, 0 ) ); + + m_pContainer->init( m_pFileView, m_pSplitter, m_pTreeView, m_pAddService_btn, m_pFilter_lb ); + m_pContainer->Show(); + m_pContainer->Enable( false ); + + m_pName_ed->SetGetFocusHdl( LINK( this, RemoteFilesDialog, FileNameGetFocusHdl ) ); + m_pName_ed->SetModifyHdl( LINK( this, RemoteFilesDialog, FileNameModifyHdl ) ); + + m_pAddService_btn->SetMenuMode( MENUBUTTON_MENUMODE_TIMED ); + m_pAddService_btn->SetClickHdl( LINK( this, RemoteFilesDialog, AddServiceHdl ) ); + m_pAddService_btn->SetSelectHdl( LINK( this, RemoteFilesDialog, EditServiceMenuHdl ) ); + + FillServicesListbox(); + + m_pServices_lb->SetSelectHdl( LINK( this, RemoteFilesDialog, SelectServiceHdl ) ); + + m_pFilter_lb->SetSelectHdl( LINK( this, RemoteFilesDialog, SelectFilterHdl ) ); +} + +RemoteFilesDialog::~RemoteFilesDialog() +{ + disposeOnce(); +} + +void RemoteFilesDialog::dispose() +{ + m_pFileView->SetSelectHdl( Link<>() ); + + if( m_bIsUpdated ) + { + Sequence< OUString > placesUrlsList( m_aServices.size() ); + Sequence< OUString > placesNamesList( m_aServices.size() ); + + int i = 0; + for( std::vector< ServicePtr >::const_iterator it = m_aServices.begin(); it != m_aServices.end(); ++it ) + { + placesUrlsList[i] = ( *it )->GetUrl(); + placesNamesList[i] = ( *it )->GetName(); + ++i; + } + + std::shared_ptr< comphelper::ConfigurationChanges > batch( comphelper::ConfigurationChanges::create( m_context ) ); + officecfg::Office::Common::Misc::FilePickerPlacesUrls::set( placesUrlsList, batch ); + officecfg::Office::Common::Misc::FilePickerPlacesNames::set( placesNamesList, batch ); + batch->commit(); + } + + m_pContainer.disposeAndClear(); // container must be first! + m_pTreeView.disposeAndClear(); + m_pFileView.disposeAndClear(); + m_pSplitter.disposeAndClear(); + m_pPath.disposeAndClear(); + + m_pOk_btn.clear(); + m_pCancel_btn.clear(); + m_pAddService_btn.clear(); + m_pServices_lb.clear(); + m_pFilter_lb.clear(); + m_pName_ed.clear(); + + ModalDialog::dispose(); +} + +void RemoteFilesDialog::Resize() +{ + ModalDialog::Resize(); + + if( m_pFileView && m_pContainer ) + { + Size aSize = m_pContainer->GetSizePixel(); + m_pFileView->SetSizePixel( aSize ); + } +} + +OUString lcl_GetServiceType( ServicePtr pService ) +{ + INetProtocol aProtocol = pService->GetUrlObject().GetProtocol(); + switch( aProtocol ) + { + case INetProtocol::Ftp: + return OUString( "FTP" ); + case INetProtocol::Cmis: + { + OUString sHost = pService->GetUrlObject().GetHost( INetURLObject::DECODE_WITH_CHARSET ); + + if( sHost.startsWith( GDRIVE_BASE_URL ) ) + return OUString( "Google Drive" ); + else if( sHost.startsWith( ALFRESCO_CLOUD_BASE_URL ) ) + return OUString( "Alfresco Cloud" ); + else if( sHost.startsWith( ONEDRIVE_BASE_URL ) ) + return OUString( "OneDrive" ); + + return OUString( "CMIS" ); + } + case INetProtocol::Smb: + return OUString( "Windows Share" ); + case INetProtocol::File: + return OUString( "SSH" ); + case INetProtocol::Http: + return OUString( "WebDAV" ); + case INetProtocol::Https: + return OUString( "WebDAV" ); + case INetProtocol::Generic: + return OUString( "SSH" ); + default: + return OUString( "" ); + } +} + +void RemoteFilesDialog::FillServicesListbox() +{ + m_pServices_lb->Clear(); + m_aServices.clear(); + + // Load from user settings + Sequence< OUString > placesUrlsList( officecfg::Office::Common::Misc::FilePickerPlacesUrls::get( m_context ) ); + Sequence< OUString > placesNamesList( officecfg::Office::Common::Misc::FilePickerPlacesNames::get( m_context ) ); + + for( sal_Int32 nPlace = 0; nPlace < placesUrlsList.getLength() && nPlace < placesNamesList.getLength(); ++nPlace ) + { + ServicePtr pService( new Place( placesNamesList[nPlace], placesUrlsList[nPlace], true ) ); + m_aServices.push_back( pService ); + + // Add to the listbox only remote services, not local bookmarks + if( !pService->IsLocal() ) + { + OUString sPrefix = lcl_GetServiceType( pService ); + + if( !sPrefix.isEmpty() ) + sPrefix += ": "; + + m_pServices_lb->InsertEntry( sPrefix + placesNamesList[nPlace] ); + } + } + + if( m_pServices_lb->GetEntryCount() > 0 ) + m_pServices_lb->SelectEntryPos( 0 ); + + EnableControls(); +} + +int RemoteFilesDialog::GetSelectedServicePos() +{ + int nSelected = m_pServices_lb->GetSelectEntryPos(); + int nPos = 0; + int i = -1; + + if( m_aServices.size() == 0 ) + return -1; + + while( nPos < ( int )m_aServices.size() ) + { + while( m_aServices[nPos]->IsLocal() ) + nPos++; + i++; + if( i == nSelected ) + break; + nPos++; + } + + return nPos; +} + +void RemoteFilesDialog::AddFilter( const OUString& rFilter, const OUString& rType ) +{ + OUString sName = rFilter; + + if ( rType.isEmpty() ) + sName = "------------------------------------------"; + + m_aFilters.push_back( std::pair< OUString, OUString >( rFilter, rType ) ); + m_pFilter_lb->InsertEntry( sName ); + + if( m_pFilter_lb->GetSelectEntryPos() == LISTBOX_ENTRY_NOTFOUND ) + m_pFilter_lb->SelectEntryPos( 0 ); +} + +OUString RemoteFilesDialog::GetPath() const +{ + return m_sPath; +} + +FileViewResult RemoteFilesDialog::OpenURL( OUString sURL ) +{ + FileViewResult eResult = eFailure; + + if( m_pFileView ) + { + OUString sFilter = FILEDIALOG_FILTER_ALL; + + if( m_nCurrentFilter != LISTBOX_ENTRY_NOTFOUND ) + { + sFilter = m_aFilters[m_nCurrentFilter].second; + } + + m_pFileView->EndInplaceEditing( false ); + eResult = m_pFileView->Initialize( sURL, sFilter, NULL, GetBlackList() ); + + if( eResult == eSuccess ) + { + m_pPath->SetURL( sURL ); + m_pTreeView->SetTreePath( sURL ); + + m_bIsConnected = true; + EnableControls(); + } + } + + return eResult; +} + +void RemoteFilesDialog::AddFileExtension() +{ + if( m_nCurrentFilter != LISTBOX_ENTRY_NOTFOUND ) + { + OUString sExt = m_aFilters[m_nCurrentFilter].second; + OUString sFileName = m_pName_ed->GetText(); + + sal_Int32 nDotPos = sFileName.lastIndexOf( '.' ); + + if ( nDotPos == -1 ) + { + sFileName += sExt.copy( 1 ); // without '*' + m_pName_ed->SetText( sFileName ); + } + } +} + +void RemoteFilesDialog::EnableControls() +{ + if( m_pServices_lb->GetEntryCount() > 0 ) + m_pServices_lb->Enable( true ); + else + m_pServices_lb->Enable( false ); + + if( m_bIsConnected ) + { + m_pFilter_lb->Enable( true ); + m_pName_ed->Enable( true ); + m_pContainer->Enable( true ); + + if( !m_pName_ed->GetText().isEmpty() ) + m_pOk_btn->Enable( true ); + else + m_pOk_btn->Enable( false ); + } + else + { + m_pFilter_lb->Enable( false ); + m_pName_ed->Enable( false ); + m_pContainer->Enable( false ); + m_pOk_btn->Enable( false ); + } +} + +IMPL_LINK_NOARG ( RemoteFilesDialog, AddServiceHdl ) +{ + ScopedVclPtrInstance< PlaceEditDialog > aDlg( this ); + short aRetCode = aDlg->Execute(); + + switch( aRetCode ) + { + case RET_OK : + { + ServicePtr newService = aDlg->GetPlace(); + m_aServices.push_back( newService ); + + OUString sPrefix = lcl_GetServiceType( newService ); + + if(!sPrefix.isEmpty()) + sPrefix += ": "; + + m_pServices_lb->InsertEntry( sPrefix + newService->GetName() ); + m_pServices_lb->SelectEntryPos( m_pServices_lb->GetEntryCount() - 1 ); + + m_bIsUpdated = true; + + EnableControls(); + break; + } + case RET_CANCEL : + default : + // Do Nothing + break; + }; + + return 1; +} + +IMPL_LINK_NOARG ( RemoteFilesDialog, SelectServiceHdl ) +{ + int nPos = GetSelectedServicePos(); + + if( nPos >= 0 ) + { + OUString sURL = m_aServices[nPos]->GetUrl(); + OUString sName = m_aServices[nPos]->GetName(); + + if( OpenURL( sURL ) == eSuccess ) + { + m_pPath->SetRootName( sName ); + m_pTreeView->Clear(); + + SvTreeListEntry* pRoot = m_pTreeView->InsertEntry( sName, NULL, true ); + OUString* sData = new OUString( sURL ); + pRoot->SetUserData( static_cast< void* >( sData ) ); + + m_pTreeView->Expand( pRoot ); + + m_pName_ed->GrabFocus(); + } + } + + return 1; +} + +IMPL_LINK_TYPED ( RemoteFilesDialog, EditServiceMenuHdl, MenuButton *, pButton, void ) +{ + OString sIdent( pButton->GetCurItemIdent() ); + if( sIdent == "edit_service" && m_pServices_lb->GetEntryCount() > 0 ) + { + unsigned int nSelected = m_pServices_lb->GetSelectEntryPos(); + int nPos = GetSelectedServicePos(); + + if( nPos >= 0 ) + { + ScopedVclPtrInstance< PlaceEditDialog > aDlg( this, m_aServices[nPos] ); + short aRetCode = aDlg->Execute(); + + switch( aRetCode ) + { + case RET_OK : + { + ServicePtr pEditedService = aDlg->GetPlace(); + + m_aServices[nPos] = pEditedService; + m_pServices_lb->RemoveEntry( nSelected ); + + OUString sPrefix = lcl_GetServiceType( pEditedService ); + + if(!sPrefix.isEmpty()) + sPrefix += ": "; + + m_pServices_lb->InsertEntry( sPrefix + pEditedService->GetName(), nSelected ); + m_pServices_lb->SelectEntryPos( nSelected ); + + m_bIsUpdated = true; + break; + } + case RET_CANCEL : + default : + // Do Nothing + break; + }; + } + } + else if( sIdent == "delete_service" && m_pServices_lb->GetEntryCount() > 0 ) + { + unsigned int nSelected = m_pServices_lb->GetSelectEntryPos(); + int nPos = GetSelectedServicePos(); + + if( nPos >= 0 ) + { + // TODO: Confirm dialog + + m_aServices.erase( m_aServices.begin() + nPos ); + m_pServices_lb->RemoveEntry( nSelected ); + + if( m_pServices_lb->GetEntryCount() > 0 ) + { + m_pServices_lb->SelectEntryPos( 0 ); + } + else + { + m_pServices_lb->SetNoSelection(); + } + + m_bIsUpdated = true; + } + } + + EnableControls(); +} + +IMPL_LINK_NOARG ( RemoteFilesDialog, DoubleClickHdl ) +{ + SvTreeListEntry* pEntry = m_pFileView->FirstSelected(); + + if( pEntry ) + { + SvtContentEntry* pData = static_cast< SvtContentEntry* >( pEntry->GetUserData() ); + + if( pData ) + { + if( pData->mbIsFolder ) + { + OUString sURL = m_pFileView->GetCurrentURL(); + + OpenURL( sURL ); + } + else + { + EndDialog( RET_OK ); + } + } + } + + return 1; +} + +IMPL_LINK_NOARG ( RemoteFilesDialog, SelectHdl ) +{ + SvTreeListEntry* pEntry = m_pFileView->FirstSelected(); + SvtContentEntry* pData = static_cast< SvtContentEntry* >( pEntry->GetUserData() ); + + if( ( pData->mbIsFolder && ( m_eType == REMOTEDLG_TYPE_PATHDLG ) ) + || ( !pData->mbIsFolder && ( m_eType == REMOTEDLG_TYPE_FILEDLG ) ) ) + { + INetURLObject aURL( pData->maURL ); + m_sPath = pData->maURL; + + m_pName_ed->SetText( INetURLObject::decode( aURL.GetLastName(), INetURLObject::DECODE_WITH_CHARSET ) ); + } + else + { + m_sPath = ""; + m_pName_ed->SetText( "" ); + } + + EnableControls(); + + return 1; +} + +IMPL_LINK_NOARG( RemoteFilesDialog, FileNameGetFocusHdl ) +{ + m_pFileView->SetNoSelection(); + return 1; +} + +IMPL_LINK_NOARG( RemoteFilesDialog, FileNameModifyHdl ) +{ + m_pFileView->SetNoSelection(); + EnableControls(); + + return 1; +} + +IMPL_LINK_NOARG ( RemoteFilesDialog, SplitHdl ) +{ + sal_Int32 nSplitPos = m_pSplitter->GetSplitPosPixel(); + + // Resize the tree list box + sal_Int32 nPlaceX = m_pTreeView->GetPosPixel().X(); + Size placeSize = m_pTreeView->GetSizePixel(); + placeSize.Width() = nSplitPos - nPlaceX; + m_pTreeView->SetSizePixel( placeSize ); + + // Change Pos and size of the fileview + Point fileViewPos = m_pFileView->GetPosPixel(); + sal_Int32 nOldX = fileViewPos.X(); + sal_Int32 nNewX = nSplitPos + m_pSplitter->GetSizePixel().Width(); + fileViewPos.X() = nNewX; + Size fileViewSize = m_pFileView->GetSizePixel(); + fileViewSize.Width() -= ( nNewX - nOldX ); + m_pFileView->SetPosSizePixel( fileViewPos, fileViewSize ); + + m_pSplitter->SetPosPixel( Point( placeSize.Width(), m_pSplitter->GetPosPixel().Y() ) ); + + return 1; +} + +IMPL_LINK_NOARG ( RemoteFilesDialog, SelectFilterHdl ) +{ + unsigned int nPos = m_pFilter_lb->GetSelectEntryPos(); + + if( nPos != LISTBOX_ENTRY_NOTFOUND && !m_aFilters[nPos].second.isEmpty() ) + { + m_nCurrentFilter = nPos; + + OUString sCurrentURL = m_pFileView->GetViewURL(); + + if( !sCurrentURL.isEmpty() ) + OpenURL( sCurrentURL ); + } + + return 1; +} + +IMPL_LINK ( RemoteFilesDialog, TreeSelectHdl, FolderTree *, pBox ) +{ + OUString* sURL = static_cast< OUString* >( pBox->GetHdlEntry()->GetUserData() ); + + if( sURL ) + OpenURL( *sURL ); + + return 1; +} + +IMPL_LINK ( RemoteFilesDialog, SelectBreadcrumbHdl, Breadcrumb*, pPtr ) +{ + if( pPtr ) + { + OpenURL( pPtr->GetHdlURL() ); + } + + return 1; +} + +IMPL_LINK_NOARG ( RemoteFilesDialog, OkHdl ) +{ + // auto extension + if( m_eMode == REMOTEDLG_MODE_SAVE ) + AddFileExtension(); + + // check if file/path exists + + OUString sCurrentPath = m_pFileView->GetViewURL(); + OUString sSelectedItem = m_pFileView->GetCurrentURL(); + OUString sName = m_pName_ed->GetText(); + + bool bFileDlg = ( m_eType == REMOTEDLG_TYPE_FILEDLG ); + bool bSelected = ( m_pFileView->GetSelectionCount() > 0 ); + + if( !sCurrentPath.endsWith( OUString( "/" ) ) ) + sCurrentPath += OUString( "/" ); + + if( !bSelected ) + { + m_sPath = sCurrentPath + INetURLObject::encode( sName, INetURLObject::PART_FPATH, INetURLObject::ENCODE_ALL ); + } + else + { + if( m_eType == REMOTEDLG_TYPE_PATHDLG ) + m_sPath = sCurrentPath; + else + m_sPath = sSelectedItem; + } + + bool bExists = false; + + Reference< XComponentContext > xContext = ::comphelper::getProcessComponentContext(); + Reference< XInteractionHandler > xInteractionHandler( + InteractionHandler::createWithParent( xContext, 0 ), UNO_QUERY_THROW ); + Reference< XCommandEnvironment > xEnv = new ::ucbhelper::CommandEnvironment( + xInteractionHandler, Reference< XProgressHandler >() ); + ::ucbhelper::Content m_aContent( m_sPath, xEnv, xContext ); + + try + { + if( bFileDlg ) + bExists = m_aContent.isDocument(); + else + bExists = m_aContent.isFolder(); + } + catch( const Exception& ) + { + bExists = false; + } + + if ( bExists ) + { + OUString sMsg = ResId( STR_SVT_ALREADYEXISTOVERWRITE, *ResMgrHolder::getOrCreate() ); + sMsg = sMsg.replaceFirst( "$filename$", sName ); + ScopedVclPtrInstance< MessageDialog > aBox( this, sMsg, VCL_MESSAGE_QUESTION, VCL_BUTTONS_YES_NO ); + if( aBox->Execute() != RET_YES ) + return 0; + } + else + { + if( m_eMode == REMOTEDLG_MODE_OPEN ) + return 0; + } + + EndDialog( RET_OK ); + return 1; +} + +// SvtFileDialog_Base + +SvtFileView* RemoteFilesDialog::GetView() +{ + return m_pFileView; +} + +void RemoteFilesDialog::SetHasFilename( bool ) +{ +} + +void RemoteFilesDialog::SetBlackList( const ::com::sun::star::uno::Sequence< OUString >& rBlackList ) +{ + m_aBlackList = rBlackList; + m_pTreeView->SetBlackList( rBlackList ); +} + +const ::com::sun::star::uno::Sequence< OUString >& RemoteFilesDialog::GetBlackList() const +{ + return m_aBlackList; +} + +void RemoteFilesDialog::SetStandardDir( const OUString& rStdDir ) +{ + m_sStdDir = rStdDir; +} + +const OUString& RemoteFilesDialog::GetStandardDir() const +{ + return m_sStdDir; +} + +void RemoteFilesDialog::SetPath( const OUString& rNewURL ) +{ + m_sPath = rNewURL; + + if( m_eMode == REMOTEDLG_MODE_SAVE ) + { + INetURLObject aUrl( m_sPath ); + OUString sFileName = aUrl.GetLastName( INetURLObject::DECODE_WITH_CHARSET ); + + m_pName_ed->SetText( sFileName ); + } +} + +void RemoteFilesDialog::AddFilterGroup( + const OUString& rFilter, + const com::sun::star::uno::Sequence< com::sun::star::beans::StringPair >& rFilters ) +{ + AddFilter( rFilter, OUString() ); + const StringPair* pSubFilters = rFilters.getConstArray(); + const StringPair* pSubFiltersEnd = pSubFilters + rFilters.getLength(); + for ( ; pSubFilters != pSubFiltersEnd; ++pSubFilters ) + AddFilter( pSubFilters->First, pSubFilters->Second ); +} + +OUString RemoteFilesDialog::GetCurFilter() const +{ + OUString sFilter; + + if( m_nCurrentFilter != LISTBOX_ENTRY_NOTFOUND ) + { + sFilter = m_aFilters[m_nCurrentFilter].first; + } + + return sFilter; +} + +OUString RemoteFilesDialog::getCurFilter( ) const +{ + return GetCurFilter(); +} + +void RemoteFilesDialog::SetCurFilter( const OUString& rFilter ) +{ + DBG_ASSERT( !IsInExecute(), "SvtFileDialog::SetCurFilter: currently executing!" ); + + // look for corresponding filter + sal_uInt16 nPos = m_aFilters.size(); + + while ( nPos-- ) + { + if ( m_aFilters[nPos].first == rFilter ) + { + m_nCurrentFilter = nPos; + m_pFilter_lb->SelectEntryPos( m_nCurrentFilter ); + break; + } + } +} + +void RemoteFilesDialog::SetFileCallback( ::svt::IFilePickerListener *pNotifier ) +{ + m_pFileNotifier = pNotifier; +} + +void RemoteFilesDialog::EnableAutocompletion( bool ) +{ + // This dialog contains Breadcrumb, not Edit +} + +const OUString& RemoteFilesDialog::GetPath() +{ + return m_sPath; +} + +std::vector<OUString> RemoteFilesDialog::GetPathList() const +{ + std::vector<OUString> aList; + sal_uLong nCount = m_pFileView->GetSelectionCount(); + SvTreeListEntry* pEntry = nCount ? m_pFileView->FirstSelected() : NULL; + + while( pEntry ) + { + aList.push_back( SvtFileView::GetURL( pEntry ) ); + pEntry = m_pFileView->NextSelected( pEntry ); + } + + if( aList.size() == 0 && !m_sPath.isEmpty() ) + aList.push_back( m_sPath ); + + return aList; +} + +bool RemoteFilesDialog::ContentIsFolder( const OUString& rURL ) +{ + try + { + Reference< XComponentContext > xContext = ::comphelper::getProcessComponentContext(); + Reference< XInteractionHandler > xInteractionHandler( + InteractionHandler::createWithParent( xContext, 0 ), UNO_QUERY_THROW ); + Reference< XCommandEnvironment > xEnv = new ::ucbhelper::CommandEnvironment( xInteractionHandler, Reference< XProgressHandler >() ); + ::ucbhelper::Content aContent( rURL, xEnv, xContext ); + + return aContent.isFolder(); + } + catch( const Exception& ) + { + // a content doesn't exist + } + + return false; +} + +sal_Int32 RemoteFilesDialog::getTargetColorDepth() +{ + // This dialog doesn't contain preview + return 0; +} + +sal_Int32 RemoteFilesDialog::getAvailableWidth() +{ + // This dialog doesn't contain preview + return 0; +} + +sal_Int32 RemoteFilesDialog::getAvailableHeight() +{ + // This dialog doesn't contain preview + return 0; +} + +void RemoteFilesDialog::setImage( sal_Int16, const ::com::sun::star::uno::Any& ) +{ + // This dialog doesn't contain preview +} + +bool RemoteFilesDialog::getShowState() +{ + // This dialog doesn't contain preview + return false; +} + +Control* RemoteFilesDialog::getControl( sal_Int16, bool) const +{ + return NULL; +} +void RemoteFilesDialog::enableControl( sal_Int16, bool ) +{ +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/fpicker/source/office/RemoteFilesDialog.hxx b/fpicker/source/office/RemoteFilesDialog.hxx new file mode 100644 index 000000000000..34623056a8b0 --- /dev/null +++ b/fpicker/source/office/RemoteFilesDialog.hxx @@ -0,0 +1,170 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef INCLUDED_SVTOOLS_REMOTEFILESDIALOG_HXX +#define INCLUDED_SVTOOLS_REMOTEFILESDIALOG_HXX + +#include <svtools/foldertree.hxx> +#include <svtools/place.hxx> +#include <svtools/PlaceEditDialog.hxx> +#include <svtools/breadcrumb.hxx> +#include <svtools/fileview.hxx> + +#include <tools/resid.hxx> + +#include <vcl/button.hxx> +#include <vcl/fpicker.hrc> +#include <vcl/menubtn.hxx> +#include <vcl/dialog.hxx> +#include <vcl/vclptr.hxx> +#include <vcl/split.hxx> +#include <vcl/svapp.hxx> + +#include <officecfg/Office/Common.hxx> +#include <com/sun/star/beans/StringPair.hpp> +#include <com/sun/star/uno/Sequence.hxx> + +#include <vector> + +#include "fpdialogbase.hxx" +#include "fpsofficeResMgr.hxx" + +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::ui::dialogs; + +enum SvtRemoteDlgMode +{ + REMOTEDLG_MODE_OPEN = 0, + REMOTEDLG_MODE_SAVE = 1 +}; + +enum SvtRemoteDlgType +{ + REMOTEDLG_TYPE_FILEDLG = 0, + REMOTEDLG_TYPE_PATHDLG = 1 +}; + +typedef std::shared_ptr< Place > ServicePtr; +typedef ::com::sun::star::uno::Sequence< OUString > OUStringList; + +class FileViewContainer; + +class RemoteFilesDialog : public SvtFileDialog_Base +{ +public: + RemoteFilesDialog( vcl::Window* pParent, WinBits nBits ); + virtual ~RemoteFilesDialog(); + + virtual void dispose() SAL_OVERRIDE; + virtual void Resize() SAL_OVERRIDE; + + OUString GetPath() const; + + // SvtFileDialog_Base + + virtual SvtFileView* GetView(); + + virtual void SetHasFilename( bool ); + virtual void SetBlackList( const ::com::sun::star::uno::Sequence< OUString >& rBlackList ); + virtual const ::com::sun::star::uno::Sequence< OUString >& GetBlackList() const; + virtual void SetStandardDir( const OUString& rStdDir ); + virtual const OUString& GetStandardDir() const; + virtual void SetPath( const OUString& rNewURL ); + virtual const OUString& GetPath(); + virtual std::vector<OUString> GetPathList() const; + virtual bool ContentIsFolder( const OUString& rURL ); + + virtual void AddFilter( const OUString& rFilter, const OUString& rType ); + virtual void AddFilterGroup( const OUString& _rFilter, + const com::sun::star::uno::Sequence< com::sun::star::beans::StringPair >& rFilters ); + virtual OUString GetCurFilter() const; + virtual void SetCurFilter( const OUString& rFilter ); + + virtual void SetFileCallback( ::svt::IFilePickerListener *pNotifier ); + + virtual void EnableAutocompletion( bool ); + + virtual sal_Int32 getTargetColorDepth(); + virtual sal_Int32 getAvailableWidth(); + virtual sal_Int32 getAvailableHeight(); + + virtual void setImage( sal_Int16 aImageFormat, const ::com::sun::star::uno::Any& rImage ); + + virtual bool getShowState(); + + virtual Control* getControl( sal_Int16 nControlId, bool bLabelControl = false ) const SAL_OVERRIDE; + virtual void enableControl( sal_Int16 nControlId, bool bEnable ); + virtual OUString getCurFilter( ) const; + +private: + ::com::sun::star::uno::Reference < com::sun::star::uno::XComponentContext > m_context; + + SvtRemoteDlgMode m_eMode; + SvtRemoteDlgType m_eType; + bool m_bMultiselection; + bool m_bIsUpdated; + bool m_bIsConnected; + + OUString m_sPath; + OUString m_sStdDir; + unsigned int m_nCurrentFilter; + + ::com::sun::star::uno::Sequence< OUString > m_aBlackList; + ::svt::IFilePickerListener* m_pFileNotifier; + + VclPtr< PushButton > m_pOk_btn; + VclPtr< CancelButton > m_pCancel_btn; + VclPtr< MenuButton > m_pAddService_btn; + VclPtr< ListBox > m_pServices_lb; + VclPtr< Breadcrumb > m_pPath; + VclPtr< Splitter > m_pSplitter; + VclPtr< FolderTree > m_pTreeView; + VclPtr< SvtFileView > m_pFileView; + VclPtr< FileViewContainer > m_pContainer; + VclPtr< ListBox > m_pFilter_lb; + VclPtr< Edit > m_pName_ed; + + std::vector< ServicePtr > m_aServices; + std::vector< std::pair< OUString, OUString > > m_aFilters; + + void FillServicesListbox(); + + /* If failure returns < 0 */ + int GetSelectedServicePos(); + + FileViewResult OpenURL( OUString sURL ); + + void AddFileExtension(); + + void EnableControls(); + + DECL_LINK ( AddServiceHdl, void * ); + DECL_LINK ( SelectServiceHdl, void * ); + DECL_LINK_TYPED ( EditServiceMenuHdl, MenuButton *, void ); + + DECL_LINK( DoubleClickHdl, void * ); + DECL_LINK( SelectHdl, void * ); + + DECL_LINK( FileNameGetFocusHdl, void * ); + DECL_LINK( FileNameModifyHdl, void * ); + + DECL_LINK( SplitHdl, void * ); + + DECL_LINK( SelectFilterHdl, void * ); + + DECL_LINK( TreeSelectHdl, FolderTree * ); + + DECL_LINK( SelectBreadcrumbHdl, Breadcrumb * ); + + DECL_LINK( OkHdl, void * ); +}; + +#endif // INCLUDED_SVTOOLS_REMOTEFILESDIALOG_HXX +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |