loplugin:flatten in fpicker

Change-Id: Icfad1871686c894379b0e703194307a5bd72b2f7
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92160
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
diff --git a/fpicker/source/office/OfficeControlAccess.cxx b/fpicker/source/office/OfficeControlAccess.cxx
index 296e936..e8f4e39 100644
--- a/fpicker/source/office/OfficeControlAccess.cxx
+++ b/fpicker/source/office/OfficeControlAccess.cxx
@@ -340,52 +340,52 @@ namespace svt
    {
        weld::Widget* pControl = m_pFilePickerController->getControl( nControlId );
        DBG_ASSERT( pControl, "OControlAccess::SetValue: don't have this control in the current mode!" );
        if ( pControl )
        if ( !pControl )
            return;

        PropFlags nPropertyId = PropFlags::Unknown;
        if ( ControlActions::SET_HELP_URL == nControlAction )
        {
            PropFlags nPropertyId = PropFlags::Unknown;
            if ( ControlActions::SET_HELP_URL == nControlAction )
            {
                nPropertyId = PropFlags::HelpUrl;
            }
            else
            {
                switch ( nControlId )
                {
                    case CHECKBOX_AUTOEXTENSION:
                    case CHECKBOX_PASSWORD:
                    case CHECKBOX_FILTEROPTIONS:
                    case CHECKBOX_READONLY:
                    case CHECKBOX_LINK:
                    case CHECKBOX_PREVIEW:
                    case CHECKBOX_SELECTION:
                        nPropertyId = PropFlags::Checked;
                        break;

                    case LISTBOX_FILTER:
                        SAL_WARN( "fpicker.office", "Use the XFilterManager to access the filter listbox" );
                        break;

                    case LISTBOX_VERSION:
                    case LISTBOX_TEMPLATE:
                    case LISTBOX_IMAGE_TEMPLATE:
                    case LISTBOX_IMAGE_ANCHOR:
                        if ( ControlActions::SET_SELECT_ITEM == nControlAction )
                        {
                            nPropertyId = PropFlags::SelectedItemIndex;
                        }
                        else
                        {
                            weld::ComboBox* pComboBox = dynamic_cast<weld::ComboBox*>(pControl);
                            assert(pComboBox && "OControlAccess::SetValue: implGetControl returned nonsense!");
                            implDoListboxAction(pComboBox, nControlAction, rValue);
                        }
                        break;
                }
            }

            if ( PropFlags::Unknown != nPropertyId )
                implSetControlProperty( nControlId, pControl, nPropertyId, rValue );
            nPropertyId = PropFlags::HelpUrl;
        }
        else
        {
            switch ( nControlId )
            {
                case CHECKBOX_AUTOEXTENSION:
                case CHECKBOX_PASSWORD:
                case CHECKBOX_FILTEROPTIONS:
                case CHECKBOX_READONLY:
                case CHECKBOX_LINK:
                case CHECKBOX_PREVIEW:
                case CHECKBOX_SELECTION:
                    nPropertyId = PropFlags::Checked;
                    break;

                case LISTBOX_FILTER:
                    SAL_WARN( "fpicker.office", "Use the XFilterManager to access the filter listbox" );
                    break;

                case LISTBOX_VERSION:
                case LISTBOX_TEMPLATE:
                case LISTBOX_IMAGE_TEMPLATE:
                case LISTBOX_IMAGE_ANCHOR:
                    if ( ControlActions::SET_SELECT_ITEM == nControlAction )
                    {
                        nPropertyId = PropFlags::SelectedItemIndex;
                    }
                    else
                    {
                        weld::ComboBox* pComboBox = dynamic_cast<weld::ComboBox*>(pControl);
                        assert(pComboBox && "OControlAccess::SetValue: implGetControl returned nonsense!");
                        implDoListboxAction(pComboBox, nControlAction, rValue);
                    }
                    break;
            }
        }

        if ( PropFlags::Unknown != nPropertyId )
            implSetControlProperty( nControlId, pControl, nPropertyId, rValue );
    }

    Any OControlAccess::getValue( sal_Int16 nControlId, sal_Int16 nControlAction ) const
diff --git a/fpicker/source/office/RemoteFilesDialog.cxx b/fpicker/source/office/RemoteFilesDialog.cxx
index f8791df..fcbd203 100644
--- a/fpicker/source/office/RemoteFilesDialog.cxx
+++ b/fpicker/source/office/RemoteFilesDialog.cxx
@@ -233,22 +233,22 @@ void RemoteFilesDialog::InitSize()
    // initialize from config
    SvtViewOptions aDlgOpt( EViewType::Dialog, m_sIniKey );

    if( aDlgOpt.Exists() )
    {
        m_xDialog->set_window_state(OUStringToOString(aDlgOpt.GetWindowState(), RTL_TEXTENCODING_UTF8));
    if( !aDlgOpt.Exists() )
        return;

        Any aUserData = aDlgOpt.GetUserItem( "UserData" );
        OUString sCfgStr;
        if( aUserData >>= sCfgStr )
        {
            sal_Int32 nPos1{ sCfgStr.indexOf('|') };
            if (nPos1<0)
                return;
            sal_Int32 nPos2{ sCfgStr.indexOf('|', nPos1+1 ) };
            if (nPos2<0)
                return;
            m_xFileView->SetConfigString( sCfgStr.copy(nPos2+1) );
        }
    m_xDialog->set_window_state(OUStringToOString(aDlgOpt.GetWindowState(), RTL_TEXTENCODING_UTF8));

    Any aUserData = aDlgOpt.GetUserItem( "UserData" );
    OUString sCfgStr;
    if( aUserData >>= sCfgStr )
    {
        sal_Int32 nPos1{ sCfgStr.indexOf('|') };
        if (nPos1<0)
            return;
        sal_Int32 nPos2{ sCfgStr.indexOf('|', nPos1+1 ) };
        if (nPos2<0)
            return;
        m_xFileView->SetConfigString( sCfgStr.copy(nPos2+1) );
    }
}

@@ -339,61 +339,61 @@ void RemoteFilesDialog::AddFilter( const OUString& rFilter, const OUString& rTyp

void RemoteFilesDialog::OpenURL( OUString const & sURL )
{
    if( m_xFileView )
    if( !m_xFileView )
        return;

    DisableControls();

    auto xWait = std::make_unique<weld::WaitObject>(m_xDialog.get());

    if( !sURL.isEmpty() )
    {
        DisableControls();
        OUString sFilter = FILEDIALOG_FILTER_ALL;

        auto xWait = std::make_unique<weld::WaitObject>(m_xDialog.get());

        if( !sURL.isEmpty() )
        if( m_nCurrentFilter != -1)
        {
            OUString sFilter = FILEDIALOG_FILTER_ALL;

            if( m_nCurrentFilter != -1)
            {
                sFilter = m_aFilters[m_nCurrentFilter].second;
            }

            m_xFileView->EndInplaceEditing();

            DBG_ASSERT( !m_pCurrentAsyncAction.is(), "SvtFileDialog::executeAsync: previous async action not yet finished!" );

            m_pCurrentAsyncAction = new AsyncPickerAction( this, m_xFileView.get(), AsyncPickerAction::Action::eOpenURL );

            // -1 timeout - sync
            m_pCurrentAsyncAction->execute( sURL, sFilter, -1, -1, GetBlackList() );

            if( m_eMode != REMOTEDLG_MODE_SAVE )
                m_xName_ed->set_text( "" );

            m_xFileView->grab_focus();
            sFilter = m_aFilters[m_nCurrentFilter].second;
        }
        else
        {
            xWait.reset();

            // content doesn't exist
            ErrorHandler::HandleError( ERRCODE_IO_NOTEXISTS );
        m_xFileView->EndInplaceEditing();

            EnableControls();
        }
        DBG_ASSERT( !m_pCurrentAsyncAction.is(), "SvtFileDialog::executeAsync: previous async action not yet finished!" );

        m_pCurrentAsyncAction = new AsyncPickerAction( this, m_xFileView.get(), AsyncPickerAction::Action::eOpenURL );

        // -1 timeout - sync
        m_pCurrentAsyncAction->execute( sURL, sFilter, -1, -1, GetBlackList() );

        if( m_eMode != REMOTEDLG_MODE_SAVE )
            m_xName_ed->set_text( "" );

        m_xFileView->grab_focus();
    }
    else
    {
        xWait.reset();

        // content doesn't exist
        ErrorHandler::HandleError( ERRCODE_IO_NOTEXISTS );

        EnableControls();
    }
}

void RemoteFilesDialog::AddFileExtension()
{
    if (m_nCurrentFilter != -1)
    if (m_nCurrentFilter == -1)
        return;

    OUString sExt = m_aFilters[m_nCurrentFilter].second;
    OUString sFileName = m_xName_ed->get_text();

    sal_Int32 nDotPos = sFileName.lastIndexOf( '.' );

    if ( nDotPos == -1 )
    {
        OUString sExt = m_aFilters[m_nCurrentFilter].second;
        OUString sFileName = m_xName_ed->get_text();

        sal_Int32 nDotPos = sFileName.lastIndexOf( '.' );

        if ( nDotPos == -1 )
        {
            sFileName += sExt.copy( 1 ); // without '*'
            m_xName_ed->set_text( sFileName );
        }
        sFileName += sExt.copy( 1 ); // without '*'
        m_xName_ed->set_text( sFileName );
    }
}

@@ -725,32 +725,32 @@ IMPL_LINK_NOARG( RemoteFilesDialog, DoubleClickHdl, SvtFileView*, bool )
IMPL_LINK_NOARG( RemoteFilesDialog, SelectHdl, SvtFileView*, void )
{
    SvtContentEntry* pData = m_xFileView->FirstSelected();
    if (pData)
    if (!pData)
        return;

    if( ( pData->mbIsFolder && ( m_eType == REMOTEDLG_TYPE_PATHDLG ) )
        || ( !pData->mbIsFolder && ( m_eType == REMOTEDLG_TYPE_FILEDLG ) ) )
    {
        if( ( pData->mbIsFolder && ( m_eType == REMOTEDLG_TYPE_PATHDLG ) )
            || ( !pData->mbIsFolder && ( m_eType == REMOTEDLG_TYPE_FILEDLG ) ) )
        {
            // url must contain user info, because we need this info in recent files entry
            // (to fill user field in login box by default)
            INetURLObject aURL( pData->maURL );
            INetURLObject aCurrentURL( m_sLastServiceUrl );
            aURL.SetUser( aCurrentURL.GetUser() );
        // url must contain user info, because we need this info in recent files entry
        // (to fill user field in login box by default)
        INetURLObject aURL( pData->maURL );
        INetURLObject aCurrentURL( m_sLastServiceUrl );
        aURL.SetUser( aCurrentURL.GetUser() );

            m_sPath = aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE );
        m_sPath = aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE );

            m_xName_ed->set_text( aURL.GetLastName(INetURLObject::DecodeMechanism::WithCharset) );
        }
        else
        {
            if( m_eMode == REMOTEDLG_MODE_OPEN )
            {
                m_sPath.clear();
                m_xName_ed->set_text( "" );
            }
        }

        EnableControls();
        m_xName_ed->set_text( aURL.GetLastName(INetURLObject::DecodeMechanism::WithCharset) );
    }
    else
    {
        if( m_eMode == REMOTEDLG_MODE_OPEN )
        {
            m_sPath.clear();
            m_xName_ed->set_text( "" );
        }
    }

    EnableControls();
}

IMPL_LINK_NOARG(RemoteFilesDialog, FileNameGetFocusHdl, weld::Widget&, void)
diff --git a/fpicker/source/office/iodlg.cxx b/fpicker/source/office/iodlg.cxx
index e8f50f6..c4c12a6 100644
--- a/fpicker/source/office/iodlg.cxx
+++ b/fpicker/source/office/iodlg.cxx
@@ -163,56 +163,56 @@ namespace
    void lcl_autoUpdateFileExtension( SvtFileDialog* _pDialog, const OUString& _rLastFilterExt )
    {
        // if auto extension is enabled...
        if ( _pDialog->isAutoExtensionEnabled() )
        if ( !_pDialog->isAutoExtensionEnabled() )
            return;

        // automatically switch to the extension of the (maybe just newly selected) extension
        OUString aNewFile = _pDialog->getCurrentFileText( );
        OUString aExt = GetFsysExtension_Impl( aNewFile, _rLastFilterExt );

        // but only if there already is an extension
        if ( aExt.isEmpty() )
            return;

        // check if it is a real file extension, and not only the "post-dot" part in
        // a directory name
        bool bRealExtensions = true;
        if ( -1 != aExt.indexOf( '/' ) )
            bRealExtensions = false;
        else if ( -1 != aExt.indexOf( '\\' ) )
            bRealExtensions = false;
        else
        {
            // automatically switch to the extension of the (maybe just newly selected) extension
            OUString aNewFile = _pDialog->getCurrentFileText( );
            OUString aExt = GetFsysExtension_Impl( aNewFile, _rLastFilterExt );

            // but only if there already is an extension
            if ( !aExt.isEmpty() )
            // no easy way to tell, because the part containing the dot already is the last
            // segment of the complete file name
            // So we have to check if the file name denotes a folder or a file.
            // For performance reasons, we do this for file urls only
            INetURLObject aURL( aNewFile );
            if ( INetProtocol::NotValid == aURL.GetProtocol() )
            {
                // check if it is a real file extension, and not only the "post-dot" part in
                // a directory name
                bool bRealExtensions = true;
                if ( -1 != aExt.indexOf( '/' ) )
                    bRealExtensions = false;
                else if ( -1 != aExt.indexOf( '\\' ) )
                    bRealExtensions = false;
                else
                OUString sURL;
                if ( osl::FileBase::getFileURLFromSystemPath( aNewFile, sURL )
                     == osl::FileBase::E_None )
                    aURL = INetURLObject( sURL );
            }
            if ( INetProtocol::File == aURL.GetProtocol() )
            {
                try
                {
                    // no easy way to tell, because the part containing the dot already is the last
                    // segment of the complete file name
                    // So we have to check if the file name denotes a folder or a file.
                    // For performance reasons, we do this for file urls only
                    INetURLObject aURL( aNewFile );
                    if ( INetProtocol::NotValid == aURL.GetProtocol() )
                    {
                        OUString sURL;
                        if ( osl::FileBase::getFileURLFromSystemPath( aNewFile, sURL )
                             == osl::FileBase::E_None )
                            aURL = INetURLObject( sURL );
                    }
                    if ( INetProtocol::File == aURL.GetProtocol() )
                    {
                        try
                        {
                            bRealExtensions = !_pDialog->ContentIsFolder( aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ) );
                        }
                        catch( const css::uno::Exception& )
                        {
                            SAL_INFO( "fpicker.office", "Exception in lcl_autoUpdateFileExtension" );
                        }
                    }
                    bRealExtensions = !_pDialog->ContentIsFolder( aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ) );
                }

                if ( bRealExtensions )
                catch( const css::uno::Exception& )
                {
                    SetFsysExtension_Impl( aNewFile, _pDialog->GetDefaultExt() );
                    _pDialog->setCurrentFileText( aNewFile );
                    SAL_INFO( "fpicker.office", "Exception in lcl_autoUpdateFileExtension" );
                }
            }
        }

        if ( bRealExtensions )
        {
            SetFsysExtension_Impl( aNewFile, _pDialog->GetDefaultExt() );
            _pDialog->setCurrentFileText( aNewFile );
        }
    }

#if defined( UNX )
@@ -484,25 +484,26 @@ SvtFileDialog::~SvtFileDialog()
    m_xFileView->SetSelectHdl(Link<SvtFileView*,void>());

    // Save bookmarked places
    if (m_xImpl->m_xPlaces->IsUpdated()) {
        const std::vector<PlacePtr> aPlaces = m_xImpl->m_xPlaces->GetPlaces();
        Sequence< OUString > placesUrlsList(m_xImpl->m_xPlaces->GetNbEditablePlaces());
        Sequence< OUString > placesNamesList(m_xImpl->m_xPlaces->GetNbEditablePlaces());
        int i(0);
        for (auto const& place : aPlaces)
        {
            if(place->IsEditable()) {
                placesUrlsList[i] = place->GetUrl();
                placesNamesList[i] = place->GetName();
                ++i;
            }
        }
    if (!m_xImpl->m_xPlaces->IsUpdated())
        return;

        std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create(m_xContext));
        officecfg::Office::Common::Misc::FilePickerPlacesUrls::set(placesUrlsList, batch);
        officecfg::Office::Common::Misc::FilePickerPlacesNames::set(placesNamesList, batch);
        batch->commit();
    const std::vector<PlacePtr> aPlaces = m_xImpl->m_xPlaces->GetPlaces();
    Sequence< OUString > placesUrlsList(m_xImpl->m_xPlaces->GetNbEditablePlaces());
    Sequence< OUString > placesNamesList(m_xImpl->m_xPlaces->GetNbEditablePlaces());
    int i(0);
    for (auto const& place : aPlaces)
    {
        if(place->IsEditable()) {
            placesUrlsList[i] = place->GetUrl();
            placesNamesList[i] = place->GetName();
            ++i;
        }
    }

    std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create(m_xContext));
    officecfg::Office::Common::Misc::FilePickerPlacesUrls::set(placesUrlsList, batch);
    officecfg::Office::Common::Misc::FilePickerPlacesNames::set(placesNamesList, batch);
    batch->commit();
}

IMPL_LINK_NOARG(SvtFileDialog, NewFolderHdl_Impl, weld::Button&, void)
@@ -2266,25 +2267,25 @@ void SvtFileDialog::appendDefaultExtension(OUString& rFileName,
{
    const OUString aType(rFilterExtensions.toAsciiLowerCase());

    if ( aType != FILEDIALOG_FILTER_ALL )
    if ( aType == FILEDIALOG_FILTER_ALL )
        return;

    const OUString aTemp(rFileName.toAsciiLowerCase());
    sal_Int32 nPos = 0;

    do
    {
        const OUString aTemp(rFileName.toAsciiLowerCase());
        sal_Int32 nPos = 0;

        do
        {
            if (nPos+1<aType.getLength() && aType[nPos]=='*') // take care of a leading *
                ++nPos;
            const OUString aExt(aType.getToken( 0, FILEDIALOG_DEF_EXTSEP, nPos ));
            if (aExt.isEmpty())
                continue;
            if (aTemp.endsWith(aExt))
                return;
        }
        while (nPos>=0);

        rFileName += "." + rFilterDefaultExtension;
        if (nPos+1<aType.getLength() && aType[nPos]=='*') // take care of a leading *
            ++nPos;
        const OUString aExt(aType.getToken( 0, FILEDIALOG_DEF_EXTSEP, nPos ));
        if (aExt.isEmpty())
            continue;
        if (aTemp.endsWith(aExt))
            return;
    }
    while (nPos>=0);

    rFileName += "." + rFilterDefaultExtension;
}

void SvtFileDialog::initDefaultPlaces( )