From afe99617707c92460e66486c0057ef327e8aa017 Mon Sep 17 00:00:00 2001 From: nirnay Date: Tue, 18 Apr 2023 15:05:25 +0530 Subject: tdf#43369: Specific UI for collecting PostgreSQL connection settings strings.hrc is used to add the text visible in the GUI and hence coressponding strings have been defined for postgres GUI. dsntypes.cxx since a new GUI page has been created for postgres a new page routing has been inserted instead of it going to default Since oracle jdbc and mysql jdbc have almost the same GUI the oracle jdbc was used as reference since there is no middle page between the target GUI page, unlike in mysql jdbc. dsntypes.hxx corressponding page id has been added for postgres for routing. dbadmin.cxx new default postgres port id has been added added just like MySQL and defined like all. dsitems.hxx contains the DSID used dbadmin.cxx dbwizsetup.cxx this where the GUI page is being called for generation dbwizsetup.hxx holds the title page string UIConfig_dbaccess.mk includes the new postgres page postgrespage.ui is the UI page where the GUI part has been refered from specialjdbcconnectionpage.ui and the connection string has been taken from dbwizconnectionpage.ui instead of adding a label and edit option so that connection string prefix is handled in the GUI with pre-existing curledit.cxx DBSetupConnectionPage.hxx holds the declaration of all the functions called in the coressponding cxx file. The declaration is a mix of OGeneralSpecialJDBCConnectionPageSetup class from where the GUI is being handled and since there is no test connection from postgres the test driver has not been implemented, OConnectionTabPageSetup from which commit page has been inspired and OConnectionHelper is used to handle the connectionstring just like in the original class minus the file based system implementation. DbAdminminImpl.cxx is where the data is retrevied from GUI and and pasted at the back of the connection string which is now a usual postgres connection string. dbaccess.suppr the supression has been added for gtklabel of postgres which have no corresponding entry widget. Change-Id: Id60fd02a56b10c1cb9b09c9302c6ddf170be8493 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150546 Tested-by: Jenkins Reviewed-by: Michael Weghorn --- dbaccess/source/core/misc/dsntypes.cxx | 3 + dbaccess/source/inc/dsntypes.hxx | 1 + dbaccess/source/ui/dlg/DBSetupConnectionPages.cxx | 171 ++++++++++++++++++++++ dbaccess/source/ui/dlg/DBSetupConnectionPages.hxx | 54 +++++++ dbaccess/source/ui/dlg/DbAdminImpl.cxx | 36 +++++ dbaccess/source/ui/dlg/dbadmin.cxx | 2 + dbaccess/source/ui/dlg/dbwizsetup.cxx | 8 + dbaccess/source/ui/inc/dbwizsetup.hxx | 1 + dbaccess/source/ui/inc/dsitems.hxx | 3 +- 9 files changed, 278 insertions(+), 1 deletion(-) (limited to 'dbaccess/source') diff --git a/dbaccess/source/core/misc/dsntypes.cxx b/dbaccess/source/core/misc/dsntypes.cxx index 28f89b4c7b26..cfeaad56a671 100644 --- a/dbaccess/source/core/misc/dsntypes.cxx +++ b/dbaccess/source/core/misc/dsntypes.cxx @@ -446,6 +446,9 @@ void ODsnTypeCollection::fillPageIds(std::u16string_view _sURL,std::vector +#include +#include + namespace dbaui { using namespace ::com::sun::star; @@ -499,6 +502,174 @@ using namespace ::com::sun::star; return std::make_unique(pPage, pController, _rAttrSet); } + // OPostgresConnectionPageSetup + OPostgresConnectionPageSetup::OPostgresConnectionPageSetup( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& _rCoreAttrs ,sal_uInt16 _nPortId, TranslateId pDefaultPortResId, TranslateId pHelpTextResId, TranslateId pHeaderTextResId, TranslateId pConnectionTextResId) + : OGenericAdministrationPage(pPage, pController, "dbaccess/ui/postgrespage.ui", "SpecialPostgresPage", _rCoreAttrs) + , m_nPortId(_nPortId) + , m_xHeaderText(m_xBuilder->weld_label("header")) + , m_xFTHelpText(m_xBuilder->weld_label("helpLabel")) + , m_xFTDatabasename(m_xBuilder->weld_label("dbNameLabel")) + , m_xETDatabasename(m_xBuilder->weld_entry("dbNameEntry")) + , m_xFTHostname(m_xBuilder->weld_label("hostNameLabel")) + , m_xETHostname(m_xBuilder->weld_entry("hostNameEntry")) + , m_xFTPortNumber(m_xBuilder->weld_label("portNumLabel")) + , m_xFTDefaultPortNumber(m_xBuilder->weld_label("portNumDefLabel")) + , m_xNFPortNumber(m_xBuilder->weld_spin_button("portNumEntry")) + , m_xFTConnection(m_xBuilder->weld_label("connectionStringLabel")) + , m_xConnectionURL(new OConnectionURLEdit(m_xBuilder->weld_entry("browseurl"), m_xBuilder->weld_label("browselabel"))) + // , m_pCollection(nullptr) + { + m_xFTConnection->set_label(DBA_RES(pConnectionTextResId)); + m_xFTDefaultPortNumber->set_label(DBA_RES(pDefaultPortResId)); + OUString sHelpText = DBA_RES(pHelpTextResId); + m_xFTHelpText->set_label(sHelpText); + //TODO this code snippet is redundant + m_xHeaderText->set_label(DBA_RES(pHeaderTextResId)); + + m_xETDatabasename->connect_changed(LINK(this, OGenericAdministrationPage, OnControlEntryModifyHdl)); + m_xETHostname->connect_changed(LINK(this, OGenericAdministrationPage, OnControlEntryModifyHdl)); + m_xNFPortNumber->connect_value_changed(LINK(this, OGenericAdministrationPage, OnControlSpinButtonModifyHdl)); + const DbuTypeCollectionItem* pCollectionItem = dynamic_cast( _rCoreAttrs.GetItem(DSID_TYPECOLLECTION) ); + if (pCollectionItem) + m_pCollection = pCollectionItem->getCollection(); + OSL_ENSURE(m_pCollection, "OConnectionHelper::OConnectionHelper : really need a DSN type collection !"); + m_xConnectionURL->SetTypeCollection(m_pCollection); + + SetRoadmapStateValue(false); + } + + OPostgresConnectionPageSetup::~OPostgresConnectionPageSetup() + { + } + + std::unique_ptr OPostgresConnectionPageSetup::CreatePostgresTabPage( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& _rAttrSet ) + { + return std::make_unique(pPage, pController, + _rAttrSet, + DSID_POSTGRES_PORTNUMBER, + STR_POSTGRES_DEFAULT, + STR_POSTGRES_HELPTEXT, + STR_POSTGRES_HEADERTEXT, + STR_COMMONURL); + } + + void OPostgresConnectionPageSetup::fillControls(std::vector< std::unique_ptr >& _rControlList) + { + _rControlList.emplace_back(new OSaveValueWidgetWrapper(m_xETDatabasename.get())); + _rControlList.emplace_back( new OSaveValueWidgetWrapper( m_xConnectionURL.get() ) ); + _rControlList.emplace_back(new OSaveValueWidgetWrapper(m_xETHostname.get())); + _rControlList.emplace_back(new OSaveValueWidgetWrapper(m_xNFPortNumber.get())); + } + + bool OPostgresConnectionPageSetup::FillItemSet( SfxItemSet* _rSet ) + { + bool bChangedSomething = false; + fillString(*_rSet,m_xConnectionURL.get(), DSID_CONNECTURL, bChangedSomething); + fillString(*_rSet,m_xETHostname.get(),DSID_CONN_HOSTNAME,bChangedSomething); + fillString(*_rSet,m_xETDatabasename.get(),DSID_DATABASENAME,bChangedSomething); + fillInt32(*_rSet,m_xNFPortNumber.get(),m_nPortId,bChangedSomething ); + return bChangedSomething; + } + + void OPostgresConnectionPageSetup::fillWindows(std::vector< std::unique_ptr >& _rControlList) + { + _rControlList.emplace_back(new ODisableWidgetWrapper(m_xFTHelpText.get())); + _rControlList.emplace_back(new ODisableWidgetWrapper(m_xFTDatabasename.get())); + _rControlList.emplace_back(new ODisableWidgetWrapper(m_xFTHostname.get())); + _rControlList.emplace_back(new ODisableWidgetWrapper(m_xFTPortNumber.get())); + _rControlList.emplace_back(new ODisableWidgetWrapper(m_xFTDefaultPortNumber.get())); + _rControlList.emplace_back(new ODisableWidgetWrapper(m_xFTConnection.get())); + } + + void OPostgresConnectionPageSetup::implInitControls(const SfxItemSet& _rSet, bool _bSaveValue) + { + // check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa) + SetRoadmapStateValue(true); + bool bValid, bReadonly; + getFlags(_rSet, bValid, bReadonly); + + m_xFTConnection->show(); + m_xConnectionURL->show(); + m_xConnectionURL->ShowPrefix( false); + + const SfxStringItem* pDatabaseName = _rSet.GetItem(DSID_DATABASENAME); + const SfxStringItem* pUrlItem = _rSet.GetItem(DSID_CONNECTURL); + const SfxStringItem* pHostName = _rSet.GetItem(DSID_CONN_HOSTNAME); + const SfxInt32Item* pPortNumber = _rSet.GetItem(m_nPortId); + + if ( bValid ) + { + m_xETDatabasename->set_text(pDatabaseName->GetValue()); + m_xETDatabasename->save_value(); + + OUString sUrl = pUrlItem->GetValue(); + setURL( sUrl ); + m_xConnectionURL->save_value(); + + m_xETHostname->set_text(pHostName->GetValue()); + m_xETHostname->save_value(); + + m_xNFPortNumber->set_value(pPortNumber->GetValue()); + m_xNFPortNumber->save_value(); + } + + OGenericAdministrationPage::implInitControls(_rSet, _bSaveValue); + + callModifiedHdl(); + } + + bool OPostgresConnectionPageSetup::commitPage( ::vcl::WizardTypes::CommitPageReason /*_eReason*/ ) + { + return commitURL(); + } + + bool OPostgresConnectionPageSetup::commitURL() + { + OUString sURL = m_xConnectionURL->GetTextNoPrefix(); + setURLNoPrefix(sURL); + m_xConnectionURL->SaveValueNoPrefix(); + return true; + } + + void OPostgresConnectionPageSetup::impl_setURL( std::u16string_view _rURL, bool _bPrefix ) + { + OUString sURL( comphelper::string::stripEnd(_rURL, '*') ); + OSL_ENSURE( m_pCollection, "OConnectionHelper::impl_setURL: have no interpreter for the URLs!" ); + if ( _bPrefix ) + m_xConnectionURL->SetText( sURL ); + else + m_xConnectionURL->SetTextNoPrefix( sURL ); + } + + void OPostgresConnectionPageSetup::setURLNoPrefix( std::u16string_view _rURL ) + { + impl_setURL( _rURL,false); + } + + void OPostgresConnectionPageSetup::setURL( std::u16string_view _rURL ) + { + impl_setURL( _rURL, true); + } + + OUString OPostgresConnectionPageSetup::getURLNoPrefix( ) const + { + return impl_getURL(); + } + + OUString OPostgresConnectionPageSetup::impl_getURL() const + { + // get the pure text + OUString sURL = m_xConnectionURL->GetTextNoPrefix(); + OSL_ENSURE( m_pCollection, "OConnectionHelper::impl_getURL: have no interpreter for the URLs!" ); + return sURL; + } + + IMPL_LINK_NOARG(OPostgresConnectionPageSetup, OnEditModified, weld::Entry&, void) + { + SetRoadmapStateValue(true); + callModifiedHdl(); + } + // OMySQLJDBCConnectionPageSetup OJDBCConnectionPageSetup::OJDBCConnectionPageSetup(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rCoreAttrs) : OConnectionTabPageSetup(pPage, pController, "dbaccess/ui/jdbcconnectionpage.ui", "JDBCConnectionPage", rCoreAttrs, diff --git a/dbaccess/source/ui/dlg/DBSetupConnectionPages.hxx b/dbaccess/source/ui/dlg/DBSetupConnectionPages.hxx index 8bc367602fd9..15904be754f0 100644 --- a/dbaccess/source/ui/dlg/DBSetupConnectionPages.hxx +++ b/dbaccess/source/ui/dlg/DBSetupConnectionPages.hxx @@ -25,6 +25,8 @@ #include "admincontrols.hxx" #include "TextConnectionHelper.hxx" +#include + namespace dbaui { class ODbTypeWizDialogSetup; @@ -214,6 +216,58 @@ namespace dbaui DECL_LINK(OnSetupModeSelected, weld::Toggleable&, void); }; + // OPostgresPageSetup + class OPostgresConnectionPageSetup final : public OGenericAdministrationPage + { + public: + OPostgresConnectionPageSetup(weld::Container* pPage, weld::DialogController* pController + , const SfxItemSet& _rCoreAttrs + , sal_uInt16 _nPortId + , TranslateId pDefaultPortResId + , TranslateId pHelpTextResId + , TranslateId pHeaderTextResId + , TranslateId pConnectionTextResId ); + virtual ~OPostgresConnectionPageSetup() override; + static std::unique_ptr CreatePostgresTabPage( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& _rAttrSet ); + ::dbaccess::ODsnTypeCollection* m_pCollection; + + private: + DECL_LINK(OnEditModified, weld::Entry&, void); + virtual bool FillItemSet( SfxItemSet* _rCoreAttrs ) override; + virtual void implInitControls(const SfxItemSet& _rSet, bool _bSaveValue) override; + virtual void fillControls(std::vector< std::unique_ptr >& _rControlList) override; + virtual void fillWindows(std::vector< std::unique_ptr >& _rControlList) override; + virtual bool commitPage( ::vcl::WizardTypes::CommitPageReason _eReason ) override; + + sal_uInt16 m_nPortId; + + std::unique_ptr m_xHeaderText; + std::unique_ptr m_xFTHelpText; + std::unique_ptr m_xFTDatabasename; + std::unique_ptr m_xETDatabasename; + std::unique_ptr m_xFTHostname; + std::unique_ptr m_xETHostname; + std::unique_ptr m_xFTPortNumber; + std::unique_ptr m_xFTDefaultPortNumber; + std::unique_ptr m_xNFPortNumber; + + std::unique_ptr m_xFTConnection; + std::unique_ptr m_xConnectionURL; + + /** used for the connection URL + @param _rURL + The URL to check. + */ + void impl_setURL( std::u16string_view _rURL, bool _bPrefix ); + void setURLNoPrefix( std::u16string_view _rURL ); + void setURL( std::u16string_view _rURL ); + OUString getURLNoPrefix( ) const; + OUString impl_getURL() const; + bool commitURL(); + + }; + + // OAuthentificationPageSetup class OAuthentificationPageSetup final : public OGenericAdministrationPage { diff --git a/dbaccess/source/ui/dlg/DbAdminImpl.cxx b/dbaccess/source/ui/dlg/DbAdminImpl.cxx index 97210e843b00..176eb0a9be49 100644 --- a/dbaccess/source/ui/dlg/DbAdminImpl.cxx +++ b/dbaccess/source/ui/dlg/DbAdminImpl.cxx @@ -62,6 +62,7 @@ #include #include #include +#include namespace dbaui { @@ -523,6 +524,38 @@ OUString ODbDataSourceAdministrationHelper::getConnectionURL() const sNewUrl = pCollection->cutPrefix(pUrlItem->GetValue()) + lcl_createHostWithPort(nullptr,pPortNumber); } break; + case ::dbaccess::DST_POSTGRES: + { + sNewUrl = pCollection->cutPrefix(pUrlItem->GetValue()); + OUString rURL(comphelper::string::stripEnd(pUrlItem->GetValue(), '*')); + const SfxStringItem* pHostName = m_pItemSetHelper->getOutputSet()->GetItem(DSID_CONN_HOSTNAME); + const SfxInt32Item* pPortNumber = m_pItemSetHelper->getOutputSet()->GetItem(DSID_POSTGRES_PORTNUMBER); + const SfxStringItem* pDatabaseName = m_pItemSetHelper->getOutputSet()->GetItem(DSID_DATABASENAME); + if (pHostName && pHostName->GetValue().getLength()) + { + OUString hostname( pHostName->GetValue() ); + hostname = hostname.replaceAll( "\\", "\\\\"); + hostname = hostname.replaceAll( "\'", "\\'"); + hostname = "'" + hostname + "'"; + rURL += " host=" + hostname; + } + if (pPortNumber && pPortNumber->GetValue()) + { + OUString port = "'" + OUString::number(pPortNumber->GetValue()) + "'"; + rURL += " port=" + port; + } + if (pDatabaseName && pDatabaseName->GetValue().getLength()) + { + OUString dbname( pDatabaseName->GetValue() ); + dbname = dbname.replaceAll( "\\", "\\\\"); + dbname = dbname.replaceAll( "\'", "\\'"); + dbname = "'" + dbname + "'"; + rURL += " dbname=" + dbname; + } + sNewUrl = rURL; + return sNewUrl; + } + break; case ::dbaccess::DST_JDBC: // run through default: @@ -1000,6 +1033,9 @@ void ODbDataSourceAdministrationHelper::convertUrl(SfxItemSet& _rDest) case ::dbaccess::DST_LDAP: nPortNumberId = DSID_CONN_LDAP_PORTNUMBER; break; + case ::dbaccess::DST_POSTGRES: + nPortNumberId = DSID_POSTGRES_PORTNUMBER; + break; default: break; } diff --git a/dbaccess/source/ui/dlg/dbadmin.cxx b/dbaccess/source/ui/dlg/dbadmin.cxx index a8a1ce1e51bd..cd741e56051b 100644 --- a/dbaccess/source/ui/dlg/dbadmin.cxx +++ b/dbaccess/source/ui/dlg/dbadmin.cxx @@ -335,6 +335,7 @@ void ODbAdminDialog::createItemSet(std::unique_ptr& _rpSet, rtl::Ref *pCounter++ = new OptionalBoolItem( DSID_PRIMARY_KEY_SUPPORT ); *pCounter++ = new SfxInt32Item(DSID_MAX_ROW_SCAN, 100); *pCounter++ = new SfxBoolItem( DSID_RESPECTRESULTSETTYPE,false ); + *pCounter++ = new SfxInt32Item(DSID_POSTGRES_PORTNUMBER, 5432); // create the pool static SfxItemInfo const aItemInfos[DSID_LAST_ITEM_ID - DSID_FIRST_ITEM_ID + 1] = @@ -399,6 +400,7 @@ void ODbAdminDialog::createItemSet(std::unique_ptr& _rpSet, rtl::Ref {0,false}, {0,false}, {0,false}, + {0,false}, }; OSL_ENSURE(std::size(aItemInfos) == DSID_LAST_ITEM_ID,"Invalid Ids!"); diff --git a/dbaccess/source/ui/dlg/dbwizsetup.cxx b/dbaccess/source/ui/dlg/dbwizsetup.cxx index 8bee3588952e..69662a17bcc6 100644 --- a/dbaccess/source/ui/dlg/dbwizsetup.cxx +++ b/dbaccess/source/ui/dlg/dbwizsetup.cxx @@ -106,6 +106,7 @@ ODbTypeWizDialogSetup::ODbTypeWizDialogSetup(weld::Window* _pParent , m_sRM_JDBCText( DBA_RES( STR_PAGETITLE_JDBC ) ) , m_sRM_MySQLNativePageTitle( DBA_RES( STR_PAGETITLE_MYSQL_NATIVE ) ) , m_sRM_OracleText( DBA_RES( STR_PAGETITLE_ORACLE ) ) + , m_sRM_PostgresText( DBA_RES( STR_PAGETITLE_POSTGRES ) ) , m_sRM_MySQLText( DBA_RES( STR_PAGETITLE_MYSQL ) ) , m_sRM_ODBCText( DBA_RES( STR_PAGETITLE_ODBC ) ) , m_sRM_DocumentOrSpreadSheetText( DBA_RES( STR_PAGETITLE_DOCUMENT_OR_SPREADSHEET ) ) @@ -213,6 +214,9 @@ OUString ODbTypeWizDialogSetup::getStateDisplayName(WizardState _nState) const case PAGE_DBSETUPWIZARD_ORACLE: sRoadmapItem = m_sRM_OracleText; break; + case PAGE_DBSETUPWIZARD_POSTGRES: + sRoadmapItem = m_sRM_PostgresText; + break; case PAGE_DBSETUPWIZARD_MYSQL_INTRO: sRoadmapItem = m_sRM_MySQLText; break; @@ -507,6 +511,10 @@ std::unique_ptr ODbTypeWizDialogSetup::createPage(WizardState _nSta xPage = OGeneralSpecialJDBCConnectionPageSetup::CreateOracleJDBCTabPage(pPageContainer, this, *m_pOutSet); break; + case PAGE_DBSETUPWIZARD_POSTGRES: + xPage = OPostgresConnectionPageSetup::CreatePostgresTabPage(pPageContainer, this, *m_pOutSet); + break; + case PAGE_DBSETUPWIZARD_LDAP: xPage = OLDAPConnectionPageSetup::CreateLDAPTabPage(pPageContainer, this, *m_pOutSet); break; diff --git a/dbaccess/source/ui/inc/dbwizsetup.hxx b/dbaccess/source/ui/inc/dbwizsetup.hxx index f902f35e4c9b..50f463fac42a 100644 --- a/dbaccess/source/ui/inc/dbwizsetup.hxx +++ b/dbaccess/source/ui/inc/dbwizsetup.hxx @@ -71,6 +71,7 @@ private: OUString m_sRM_JDBCText; OUString m_sRM_MySQLNativePageTitle; OUString m_sRM_OracleText; + OUString m_sRM_PostgresText; OUString m_sRM_MySQLText; OUString m_sRM_ODBCText; OUString m_sRM_DocumentOrSpreadSheetText; diff --git a/dbaccess/source/ui/inc/dsitems.hxx b/dbaccess/source/ui/inc/dsitems.hxx index 09410d31b83f..8b7971d80a66 100644 --- a/dbaccess/source/ui/inc/dsitems.hxx +++ b/dbaccess/source/ui/inc/dsitems.hxx @@ -85,11 +85,12 @@ typedef sal_Int32 ItemID; #define DSID_PRIMARY_KEY_SUPPORT 58 #define DSID_MAX_ROW_SCAN 59 #define DSID_RESPECTRESULTSETTYPE 60 +#define DSID_POSTGRES_PORTNUMBER 61 // don't forget to adjust DSID_LAST_ITEM_ID below! // item range. Adjust this if you introduce new items above #define DSID_FIRST_ITEM_ID DSID_NAME -#define DSID_LAST_ITEM_ID DSID_RESPECTRESULTSETTYPE +#define DSID_LAST_ITEM_ID DSID_POSTGRES_PORTNUMBER /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit