tdf#121935 crash on "set up connect to text files"

Change-Id: I73bc93ebb5010f3a376b3b121e1ac873f1be137a
Reviewed-on: https://gerrit.libreoffice.org/64676
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
diff --git a/dbaccess/source/ui/dlg/DBSetupConnectionPages.cxx b/dbaccess/source/ui/dlg/DBSetupConnectionPages.cxx
index 4a3473e..5d0e19a 100644
--- a/dbaccess/source/ui/dlg/DBSetupConnectionPages.cxx
+++ b/dbaccess/source/ui/dlg/DBSetupConnectionPages.cxx
@@ -69,9 +69,15 @@ using namespace ::com::sun::star;
        : OConnectionTabPageSetup(pParent, "dbaccess/ui/dbwiztextpage.ui", "DBWizTextPage",
                                  rCoreAttrs, STR_TEXT_HELPTEXT, STR_TEXT_HEADERTEXT, STR_TEXT_PATH_OR_FILE)
        , m_xSubContainer(m_xBuilder->weld_widget("TextPageContainer"))
        , m_aTextConnectionHelper(m_xSubContainer.get(), TC_EXTENSION | TC_SEPARATORS)
        , m_xTextConnectionHelper(new OTextConnectionHelper(m_xSubContainer.get(), TC_EXTENSION | TC_SEPARATORS))
    {
        m_aTextConnectionHelper.SetClickHandler(LINK( this, OTextConnectionPageSetup, ImplGetExtensionHdl ) );
        m_xTextConnectionHelper->SetClickHandler(LINK( this, OTextConnectionPageSetup, ImplGetExtensionHdl ) );
    }

    void OTextConnectionPageSetup::dispose()
    {
        m_xTextConnectionHelper.reset();
        OConnectionTabPageSetup::dispose();
    }

    OTextConnectionPageSetup::~OTextConnectionPageSetup()
@@ -81,27 +87,27 @@ using namespace ::com::sun::star;

    IMPL_LINK_NOARG(OTextConnectionPageSetup, ImplGetExtensionHdl, OTextConnectionHelper*, void)
    {
        SetRoadmapStateValue(!m_aTextConnectionHelper.GetExtension().isEmpty() && OConnectionTabPageSetup::checkTestConnection());
        SetRoadmapStateValue(!m_xTextConnectionHelper->GetExtension().isEmpty() && OConnectionTabPageSetup::checkTestConnection());
        callModifiedHdl();
    }

    bool OTextConnectionPageSetup::checkTestConnection()
    {
        bool bDoEnable = OConnectionTabPageSetup::checkTestConnection();
        bDoEnable = !m_aTextConnectionHelper.GetExtension().isEmpty() && bDoEnable;
        bDoEnable = !m_xTextConnectionHelper->GetExtension().isEmpty() && bDoEnable;
        return bDoEnable;
    }

    void OTextConnectionPageSetup::fillControls(std::vector< std::unique_ptr<ISaveValueWrapper> >& _rControlList)
    {
        OConnectionTabPageSetup::fillControls(_rControlList);
        m_aTextConnectionHelper.fillControls(_rControlList);
        m_xTextConnectionHelper->fillControls(_rControlList);
    }

    void OTextConnectionPageSetup::fillWindows(std::vector< std::unique_ptr<ISaveValueWrapper> >& _rControlList)
    {
        OConnectionTabPageSetup::fillWindows(_rControlList);
        m_aTextConnectionHelper.fillWindows(_rControlList);
        m_xTextConnectionHelper->fillWindows(_rControlList);
    }

    void OTextConnectionPageSetup::implInitControls(const SfxItemSet& _rSet, bool _bSaveValue)
@@ -110,18 +116,19 @@ using namespace ::com::sun::star;
        bool bValid, bReadonly;
        getFlags(_rSet, bValid, bReadonly);
        OConnectionTabPageSetup::implInitControls( _rSet, _bSaveValue);
        m_aTextConnectionHelper.implInitControls(_rSet, bValid);
        m_xTextConnectionHelper->implInitControls(_rSet, bValid);
    }

    bool OTextConnectionPageSetup::FillItemSet( SfxItemSet* _rSet )
    {
        bool bChangedSomething = OConnectionTabPageSetup::FillItemSet(_rSet);
        bChangedSomething = m_aTextConnectionHelper.FillItemSet(*_rSet, bChangedSomething);
        bChangedSomething = m_xTextConnectionHelper->FillItemSet(*_rSet, bChangedSomething);
        return bChangedSomething;
    }

    bool OTextConnectionPageSetup::prepareLeave(){
        return m_aTextConnectionHelper.prepareLeave();
    bool OTextConnectionPageSetup::prepareLeave()
    {
        return m_xTextConnectionHelper->prepareLeave();
    }

    VclPtr<OGenericAdministrationPage> OLDAPConnectionPageSetup::CreateLDAPTabPage( vcl::Window* pParent, const SfxItemSet& _rAttrSet )
diff --git a/dbaccess/source/ui/dlg/DBSetupConnectionPages.hxx b/dbaccess/source/ui/dlg/DBSetupConnectionPages.hxx
index 8f9acc5..fdc36ff 100644
--- a/dbaccess/source/ui/dlg/DBSetupConnectionPages.hxx
+++ b/dbaccess/source/ui/dlg/DBSetupConnectionPages.hxx
@@ -56,11 +56,12 @@ namespace dbaui
    {
    public:
        std::unique_ptr<weld::Widget> m_xSubContainer;
        OTextConnectionHelper  m_aTextConnectionHelper;
        std::unique_ptr<OTextConnectionHelper> m_xTextConnectionHelper;

        virtual bool        FillItemSet ( SfxItemSet* _rCoreAttrs ) override;
        static VclPtr<OGenericAdministrationPage> CreateTextTabPage(TabPageParent pParent, const SfxItemSet& _rAttrSet );
        OTextConnectionPageSetup(TabPageParent pParent, const SfxItemSet& _rCoreAttrs);
        virtual void dispose() override;
        virtual ~OTextConnectionPageSetup() override;
    protected:
        virtual bool prepareLeave() override;
diff --git a/dbaccess/source/ui/dlg/detailpages.cxx b/dbaccess/source/ui/dlg/detailpages.cxx
index 65d3bcc..60408c5 100644
--- a/dbaccess/source/ui/dlg/detailpages.cxx
+++ b/dbaccess/source/ui/dlg/detailpages.cxx
@@ -668,7 +668,7 @@ namespace dbaui
    // OTextDetailsPage
    OTextDetailsPage::OTextDetailsPage(TabPageParent pParent, const SfxItemSet& rCoreAttrs)
        : OCommonBehaviourTabPage(pParent, "dbaccess/ui/emptypage.ui", "EmptyPage", rCoreAttrs, OCommonBehaviourTabPageFlags::NONE)
        , m_aTextConnectionHelper(m_xContainer.get(), TC_EXTENSION | TC_HEADER | TC_SEPARATORS | TC_CHARSET)
        , m_xTextConnectionHelper(new OTextConnectionHelper(m_xContainer.get(), TC_EXTENSION | TC_HEADER | TC_SEPARATORS | TC_CHARSET))
    {
    }

@@ -677,6 +677,12 @@ namespace dbaui
        disposeOnce();
    }

    void OTextDetailsPage::dispose()
    {
        m_xTextConnectionHelper.reset();
        OCommonBehaviourTabPage::dispose();
    }

    VclPtr<SfxTabPage> ODriversSettings::CreateText(TabPageParent pParent,  const SfxItemSet* pAttrSet)
    {
        return VclPtr<OTextDetailsPage>::Create(pParent, *pAttrSet);
@@ -685,13 +691,13 @@ namespace dbaui
    void OTextDetailsPage::fillControls(std::vector< std::unique_ptr<ISaveValueWrapper> >& _rControlList)
    {
        OCommonBehaviourTabPage::fillControls(_rControlList);
        m_aTextConnectionHelper.fillControls(_rControlList);
        m_xTextConnectionHelper->fillControls(_rControlList);

    }
    void OTextDetailsPage::fillWindows(std::vector< std::unique_ptr<ISaveValueWrapper> >& _rControlList)
    {
        OCommonBehaviourTabPage::fillWindows(_rControlList);
        m_aTextConnectionHelper.fillWindows(_rControlList);
        m_xTextConnectionHelper->fillWindows(_rControlList);

    }
    void OTextDetailsPage::implInitControls(const SfxItemSet& _rSet, bool _bSaveValue)
@@ -700,20 +706,20 @@ namespace dbaui
        bool bValid, bReadonly;
        getFlags(_rSet, bValid, bReadonly);

        m_aTextConnectionHelper.implInitControls(_rSet, bValid);
        m_xTextConnectionHelper->implInitControls(_rSet, bValid);
        OCommonBehaviourTabPage::implInitControls(_rSet, _bSaveValue);
    }

    bool OTextDetailsPage::FillItemSet( SfxItemSet* rSet )
    {
        bool bChangedSomething = OCommonBehaviourTabPage::FillItemSet(rSet);
        bChangedSomething = m_aTextConnectionHelper.FillItemSet(*rSet, bChangedSomething);
        bChangedSomething = m_xTextConnectionHelper->FillItemSet(*rSet, bChangedSomething);
        return bChangedSomething;
    }

    bool OTextDetailsPage::prepareLeave()
    {
        return m_aTextConnectionHelper.prepareLeave();
        return m_xTextConnectionHelper->prepareLeave();
    }

    VclPtr<SfxTabPage> ODriversSettings::CreateGeneratedValuesPage(TabPageParent pParent, const SfxItemSet* _rAttrSet)
diff --git a/dbaccess/source/ui/dlg/detailpages.hxx b/dbaccess/source/ui/dlg/detailpages.hxx
index b476f2c..6e50f67 100644
--- a/dbaccess/source/ui/dlg/detailpages.hxx
+++ b/dbaccess/source/ui/dlg/detailpages.hxx
@@ -245,10 +245,11 @@ namespace dbaui

        OTextDetailsPage(TabPageParent pParent, const SfxItemSet& rCoreAttrs);

        OTextConnectionHelper m_aTextConnectionHelper;
        std::unique_ptr<OTextConnectionHelper> m_xTextConnectionHelper;

    protected:
        virtual ~OTextDetailsPage() override;
        virtual void dispose() override;
        virtual bool prepareLeave() override;

        virtual void implInitControls(const SfxItemSet& _rSet, bool _bSaveValue) override;