[Libreoffice-commits] core.git: dbaccess/source dbaccess/uiconfig
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Wed Oct 24 14:26:21 UTC 2018
dbaccess/source/ui/control/curledit.cxx | 62 ++
dbaccess/source/ui/dlg/ConnectionHelper.cxx | 645 ++++++++++++++++++++++++++++
dbaccess/source/ui/dlg/ConnectionHelper.hxx | 66 ++
dbaccess/source/ui/dlg/ConnectionPage.cxx | 183 +++----
dbaccess/source/ui/dlg/ConnectionPage.hxx | 27 -
dbaccess/source/ui/dlg/adminpages.cxx | 49 ++
dbaccess/source/ui/dlg/adminpages.hxx | 14
dbaccess/source/ui/inc/curledit.hxx | 73 +++
dbaccess/uiconfig/ui/connectionpage.ui | 49 +-
9 files changed, 1037 insertions(+), 131 deletions(-)
New commits:
commit 9dc5234d36ebcafca36aece80b6a9b59da287cda
Author: Caolán McNamara <caolanm at redhat.com>
AuthorDate: Tue Oct 23 10:38:03 2018 +0100
Commit: Caolán McNamara <caolanm at redhat.com>
CommitDate: Wed Oct 24 16:25:53 2018 +0200
weld OConnectionTabPage
Change-Id: Icdbe5d95d0850d131018d21d0a21cb12109d565c
Reviewed-on: https://gerrit.libreoffice.org/62283
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm at redhat.com>
Tested-by: Caolán McNamara <caolanm at redhat.com>
diff --git a/dbaccess/source/ui/control/curledit.cxx b/dbaccess/source/ui/control/curledit.cxx
index 16e681e7189d..a50a2c1fbaef 100644
--- a/dbaccess/source/ui/control/curledit.cxx
+++ b/dbaccess/source/ui/control/curledit.cxx
@@ -150,6 +150,68 @@ void OConnectionURLEdit::ShowPrefix(bool _bShowPrefix)
m_pForcedPrefix->Show(m_bShowPrefix);
}
+DBOConnectionURLEdit::DBOConnectionURLEdit(std::unique_ptr<weld::Entry> xEntry, std::unique_ptr<weld::Label> xForcedPrefix)
+ : m_pTypeCollection(nullptr)
+ , m_bShowPrefix(false)
+ , m_xEntry(std::move(xEntry))
+ , m_xForcedPrefix(std::move(xForcedPrefix))
+{
+}
+
+DBOConnectionURLEdit::~DBOConnectionURLEdit()
+{
+}
+
+void DBOConnectionURLEdit::SetTextNoPrefix(const OUString& _rText)
+{
+ m_xEntry->set_text(_rText);
+}
+
+OUString DBOConnectionURLEdit::GetTextNoPrefix() const
+{
+ return m_xEntry->get_text();
+}
+
+void DBOConnectionURLEdit::SetText(const OUString& _rStr)
+{
+ Selection aNoSelection(0,0);
+ SetText(_rStr, aNoSelection);
+}
+
+void DBOConnectionURLEdit::SetText(const OUString& _rStr, const Selection& /*_rNewSelection*/)
+{
+ m_xForcedPrefix->show(m_bShowPrefix);
+
+ bool bIsEmpty = _rStr.isEmpty();
+ // calc the prefix
+ OUString sPrefix;
+ if (!bIsEmpty)
+ {
+ // determine the type of the new URL described by the new text
+ sPrefix = m_pTypeCollection->getPrefix(_rStr);
+ }
+
+ // the fixed text gets the prefix
+ m_xForcedPrefix->set_label(sPrefix);
+
+ // do the real SetText
+ OUString sNewText( _rStr );
+ if ( !bIsEmpty )
+ sNewText = m_pTypeCollection->cutPrefix( _rStr );
+ m_xEntry->set_text(sNewText);
+}
+
+OUString DBOConnectionURLEdit::GetText() const
+{
+ return m_xForcedPrefix->get_label() + m_xEntry->get_text();
+}
+
+void DBOConnectionURLEdit::ShowPrefix(bool _bShowPrefix)
+{
+ m_bShowPrefix = _bShowPrefix;
+ m_xForcedPrefix->show(m_bShowPrefix);
+}
+
} // namespace dbaui
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/dbaccess/source/ui/dlg/ConnectionHelper.cxx b/dbaccess/source/ui/dlg/ConnectionHelper.cxx
index 79b65147c57a..7642114af693 100644
--- a/dbaccess/source/ui/dlg/ConnectionHelper.cxx
+++ b/dbaccess/source/ui/dlg/ConnectionHelper.cxx
@@ -738,6 +738,651 @@ namespace dbaui
}
}
+ DBOConnectionHelper::DBOConnectionHelper(TabPageParent pParent, const OUString& _rUIXMLDescription, const OString& _rId, const SfxItemSet& _rCoreAttrs)
+ : OGenericAdministrationPage(pParent, _rUIXMLDescription, _rId, _rCoreAttrs)
+ , m_bUserGrabFocus(false)
+ , m_pCollection(nullptr)
+ , m_xFT_Connection(m_xBuilder->weld_label("browseurllabel"))
+ , m_xPB_Connection(m_xBuilder->weld_button("browse"))
+ , m_xPB_CreateDB(m_xBuilder->weld_button("create"))
+ , m_xConnectionURL(new DBOConnectionURLEdit(m_xBuilder->weld_entry("browseurl"), m_xBuilder->weld_label("browselabel")))
+ {
+ // extract the datasource type collection from the item set
+ const DbuTypeCollectionItem* pCollectionItem = dynamic_cast<const DbuTypeCollectionItem*>( _rCoreAttrs.GetItem(DSID_TYPECOLLECTION) );
+ if (pCollectionItem)
+ m_pCollection = pCollectionItem->getCollection();
+ m_xPB_Connection->connect_clicked(LINK(this, DBOConnectionHelper, OnBrowseConnections));
+ m_xPB_CreateDB->connect_clicked(LINK(this, DBOConnectionHelper, OnCreateDatabase));
+ OSL_ENSURE(m_pCollection, "OConnectionHelper::OConnectionHelper : really need a DSN type collection !");
+ m_xConnectionURL->SetTypeCollection(m_pCollection);
+
+ m_xConnectionURL->connect_focus_in(LINK(this, DBOConnectionHelper, GetFocusHdl));
+ m_xConnectionURL->connect_focus_out(LINK(this, DBOConnectionHelper, LoseFocusHdl));
+ }
+
+ DBOConnectionHelper::~DBOConnectionHelper()
+ {
+ }
+
+ void DBOConnectionHelper::dispose()
+ {
+ m_xConnectionURL.reset();
+ OGenericAdministrationPage::dispose();
+ }
+
+ void DBOConnectionHelper::implInitControls(const SfxItemSet& _rSet, bool _bSaveValue)
+ {
+ // check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa)
+ bool bValid, bReadonly;
+ getFlags(_rSet, bValid, bReadonly);
+
+ m_xFT_Connection->show();
+ m_xConnectionURL->show();
+ m_xConnectionURL->ShowPrefix( ::dbaccess::DST_JDBC == m_pCollection->determineType(m_eType) );
+
+ bool bEnableBrowseButton = m_pCollection->supportsBrowsing( m_eType );
+ m_xPB_Connection->show( bEnableBrowseButton );
+
+ bool bEnableCreateButton = m_pCollection->supportsDBCreation( m_eType );
+ m_xPB_CreateDB->show( bEnableCreateButton );
+
+ const SfxStringItem* pUrlItem = _rSet.GetItem<SfxStringItem>(DSID_CONNECTURL);
+
+ // forward the values to the controls
+ if ( bValid )
+ {
+ OUString sUrl = pUrlItem->GetValue();
+ setURL( sUrl );
+
+ checkTestConnection();
+ m_xConnectionURL->save_value();
+ }
+
+ OGenericAdministrationPage::implInitControls(_rSet, _bSaveValue);
+ }
+
+ void DBOConnectionHelper::implUpdateURLDependentStates() const
+ {
+ OSL_PRECOND( m_pAdminDialog && m_pCollection, "OConnectionHelper::implUpdateURLDependentStates: no admin dialog!" );
+ if ( !m_pAdminDialog || !m_pCollection )
+ return;
+
+ if ( m_pCollection->isFileSystemBased(m_eType) )
+ m_pAdminDialog->enableConfirmSettings( !getURLNoPrefix().isEmpty() );
+ }
+
+ IMPL_LINK_NOARG(DBOConnectionHelper, OnBrowseConnections, weld::Button&, void)
+ {
+ OSL_ENSURE(m_pAdminDialog,"No Admin dialog set! ->GPF");
+ const ::dbaccess::DATASOURCE_TYPE eType = m_pCollection->determineType(m_eType);
+ switch ( eType )
+ {
+ case ::dbaccess::DST_DBASE:
+ case ::dbaccess::DST_FLAT:
+ {
+ try
+ {
+ Reference< XFolderPicker2 > xFolderPicker = FolderPicker::create(m_xORB);
+
+ bool bDoBrowse = false;
+ OUString sOldPath = getURLNoPrefix();
+ do
+ {
+ if (!sOldPath.isEmpty())
+ xFolderPicker->setDisplayDirectory(sOldPath);
+ if (0 == xFolderPicker->execute())
+ // cancelled by the user
+ return;
+
+ sOldPath = xFolderPicker->getDirectory();
+ switch (checkPathExistence(sOldPath))
+ {
+ case RET_RETRY:
+ bDoBrowse = true;
+ break;
+ case RET_CANCEL:
+ return;
+ default:
+ break;
+ }
+ }
+ while (bDoBrowse);
+
+ OUString sSelectedDirectory = xFolderPicker->getDirectory();
+ INetURLObject aSelectedDirectory( sSelectedDirectory, INetURLObject::EncodeMechanism::WasEncoded, RTL_TEXTENCODING_UTF8 );
+
+ // for UI purpose, we don't want to have the path encoded
+ sSelectedDirectory = aSelectedDirectory.GetMainURL( INetURLObject::DecodeMechanism::WithCharset );
+
+ setURLNoPrefix( sSelectedDirectory );
+ SetRoadmapStateValue(true);
+ callModifiedHdl();
+ }
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION("dbaccess");
+ }
+ }
+ break;
+ case ::dbaccess::DST_CALC:
+ {
+ SvtModuleOptions aModule;
+ ::sfx2::FileDialogHelper aFileDlg(
+ ui::dialogs::TemplateDescription::FILEOPEN_READONLY_VERSION,
+ FileDialogFlags::NONE,
+ aModule.GetFactoryEmptyDocumentURL(SvtModuleOptions::EFactory::CALC)
+ ,SfxFilterFlags::IMPORT, SfxFilterFlags::NONE, GetFrameWeld());
+ askForFileName(aFileDlg);
+ }
+ break;
+ case ::dbaccess::DST_WRITER:
+ {
+ SvtModuleOptions aModule;
+ ::sfx2::FileDialogHelper aFileDlg(
+ ui::dialogs::TemplateDescription::FILEOPEN_READONLY_VERSION,
+ FileDialogFlags::NONE,
+ aModule.GetFactoryEmptyDocumentURL(SvtModuleOptions::EFactory::WRITER),
+ SfxFilterFlags::IMPORT, SfxFilterFlags::NONE, GetFrameWeld());
+ askForFileName(aFileDlg);
+ }
+ break;
+ case ::dbaccess::DST_MSACCESS:
+ {
+ const OUString sExt("*.mdb;*.mde");
+ OUString sFilterName(DBA_RES (STR_MSACCESS_FILTERNAME));
+ ::sfx2::FileDialogHelper aFileDlg(
+ ui::dialogs::TemplateDescription::FILEOPEN_READONLY_VERSION,
+ FileDialogFlags::NONE, GetFrameWeld());
+ aFileDlg.AddFilter(sFilterName,sExt);
+ aFileDlg.SetCurrentFilter(sFilterName);
+ askForFileName(aFileDlg);
+ }
+ break;
+ case ::dbaccess::DST_MSACCESS_2007:
+ {
+ const OUString sAccdb("*.accdb;*.accde");
+ OUString sFilterName2(DBA_RES (STR_MSACCESS_2007_FILTERNAME));
+ ::sfx2::FileDialogHelper aFileDlg(
+ ui::dialogs::TemplateDescription::FILEOPEN_READONLY_VERSION,
+ FileDialogFlags::NONE, GetFrameWeld());
+ aFileDlg.AddFilter(sFilterName2,sAccdb);
+ aFileDlg.SetCurrentFilter(sFilterName2);
+ askForFileName(aFileDlg);
+ }
+ break;
+ case ::dbaccess::DST_MYSQL_ODBC:
+ case ::dbaccess::DST_ODBC:
+ {
+ // collect all ODBC data source names
+ OUString sCurrDatasource = getURLNoPrefix();
+ OUString sDataSource;
+ if ( getSelectedDataSource(sDataSource,sCurrDatasource) && !sDataSource.isEmpty() )
+ {
+ setURLNoPrefix(sDataSource);
+ SetRoadmapStateValue(true);
+ callModifiedHdl();
+ }
+ else
+ return;
+ }
+ break;
+#if defined _WIN32
+ case ::dbaccess::DST_ADO:
+ {
+ OUString sOldDataSource=getURLNoPrefix();
+ OUString sNewDataSource;
+ HWND hWnd = GetParent()->GetSystemData()->hWnd;
+ sNewDataSource = getAdoDatalink(reinterpret_cast<LONG_PTR>(hWnd),sOldDataSource);
+ if ( !sNewDataSource.isEmpty() )
+ {
+ setURLNoPrefix(sNewDataSource);
+ SetRoadmapStateValue(true);
+ callModifiedHdl();
+ }
+ else
+ return;
+ }
+ break;
+#endif
+ case ::dbaccess::DST_MOZILLA:
+ case ::dbaccess::DST_THUNDERBIRD:
+ {
+ MozillaProductType profileType = MozillaProductType_Mozilla;
+ if (eType == ::dbaccess::DST_THUNDERBIRD)
+ profileType = MozillaProductType_Thunderbird;
+
+ Reference<XComponentContext> xContext = ::comphelper::getProcessComponentContext();
+ Reference<XMozillaBootstrap> xMozillaBootstrap = MozillaBootstrap::create(xContext);
+
+ // collect all Mozilla Profiles
+ css::uno::Sequence< OUString > list;
+
+ xMozillaBootstrap->getProfileList( profileType, list );
+ const OUString * pArray = list.getConstArray();
+
+ sal_Int32 count = list.getLength();
+
+ std::set<OUString> aProfiles;
+ for (sal_Int32 index=0; index < count; index++)
+ aProfiles.insert(pArray[index]);
+
+ // execute the select dialog
+ ScopedVclPtrInstance< ODatasourceSelectDialog > aSelector(GetParent(), aProfiles);
+ OUString sOldProfile=getURLNoPrefix();
+
+ if (!sOldProfile.isEmpty())
+ aSelector->Select(sOldProfile);
+ else
+ aSelector->Select(xMozillaBootstrap->getDefaultProfile(profileType));
+
+ if ( RET_OK == aSelector->Execute() )
+ setURLNoPrefix(aSelector->GetSelected());
+ break;
+ }
+ case ::dbaccess::DST_FIREBIRD:
+ {
+ const OUString sExt("*.fdb");
+ OUString sFilterName(DBA_RES (STR_FIREBIRD_FILTERNAME));
+ ::sfx2::FileDialogHelper aFileDlg(
+ ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE,
+ FileDialogFlags::NONE, GetFrameWeld());
+ aFileDlg.AddFilter(sFilterName,sExt);
+ aFileDlg.SetCurrentFilter(sFilterName);
+ askForFileName(aFileDlg);
+ break;
+ }
+ default:
+ break;
+ }
+
+ checkTestConnection();
+ }
+
+ IMPL_LINK_NOARG(DBOConnectionHelper, OnCreateDatabase, weld::Button&, void)
+ {
+ OSL_ENSURE(m_pAdminDialog,"No Admin dialog set! ->GPF");
+ const ::dbaccess::DATASOURCE_TYPE eType = m_pCollection->determineType(m_eType);
+ switch ( eType )
+ {
+ case ::dbaccess::DST_FIREBIRD:
+ {
+ const OUString sExt("*.fdb");
+ OUString sFilterName(DBA_RES (STR_FIREBIRD_FILTERNAME));
+ ::sfx2::FileDialogHelper aFileDlg(
+ ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION,
+ FileDialogFlags::NONE, GetFrameWeld());
+ aFileDlg.AddFilter(sFilterName,sExt);
+ aFileDlg.SetCurrentFilter(sFilterName);
+ askForFileName(aFileDlg);
+ break;
+ }
+ default:
+ break;
+ }
+
+ checkTestConnection();
+ }
+
+ bool DBOConnectionHelper::checkTestConnection()
+ {
+ return true;
+ }
+
+ void DBOConnectionHelper::impl_setURL( const OUString& _rURL, bool _bPrefix )
+ {
+ OUString sURL( comphelper::string::stripEnd(_rURL, '*') );
+ OSL_ENSURE( m_pCollection, "OConnectionHelper::impl_setURL: have no interpreter for the URLs!" );
+
+ if ( m_pCollection && !sURL.isEmpty() )
+ {
+ if ( m_pCollection->isFileSystemBased( m_eType ) )
+ {
+ // get the two parts: prefix and file URL
+ OUString sTypePrefix, sFileURLEncoded;
+ if ( _bPrefix )
+ {
+ sTypePrefix = m_pCollection->getPrefix( m_eType );
+ sFileURLEncoded = m_pCollection->cutPrefix( sURL );
+ }
+ else
+ {
+ sFileURLEncoded = sURL;
+ }
+
+ // substitute any variables
+ sFileURLEncoded = SvtPathOptions().SubstituteVariable( sFileURLEncoded );
+
+ // decode the URL
+ sURL = sTypePrefix;
+ if ( !sFileURLEncoded.isEmpty() )
+ {
+ OFileNotation aFileNotation(sFileURLEncoded);
+ // set this decoded URL as text
+ sURL += aFileNotation.get(OFileNotation::N_SYSTEM);
+ }
+ }
+ }
+
+ if ( _bPrefix )
+ m_xConnectionURL->SetText( sURL );
+ else
+ m_xConnectionURL->SetTextNoPrefix( sURL );
+
+ implUpdateURLDependentStates();
+ }
+
+ OUString DBOConnectionHelper::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!" );
+
+ if ( m_pCollection && !sURL.isEmpty() )
+ {
+ if ( m_pCollection->isFileSystemBased( m_eType ) )
+ {
+ // get the two parts: prefix and file URL
+ OUString sFileURLDecoded;
+ sFileURLDecoded = sURL;
+
+ sURL = OUString();
+ if ( !sFileURLDecoded.isEmpty() )
+ {
+ OFileNotation aFileNotation( sFileURLDecoded, OFileNotation::N_SYSTEM );
+ sURL += aFileNotation.get( OFileNotation::N_URL );
+ }
+
+ // encode the URL
+ INetURLObject aFileURL( sFileURLDecoded, INetURLObject::EncodeMechanism::All, RTL_TEXTENCODING_UTF8 );
+ sFileURLDecoded = aFileURL.GetMainURL( INetURLObject::DecodeMechanism::NONE );
+ }
+ }
+ return sURL;
+ }
+
+ void DBOConnectionHelper::setURL( const OUString& _rURL )
+ {
+ impl_setURL( _rURL, true );
+ }
+
+ OUString DBOConnectionHelper::getURLNoPrefix( ) const
+ {
+ return impl_getURL();
+ }
+
+ void DBOConnectionHelper::setURLNoPrefix( const OUString& _rURL )
+ {
+ impl_setURL( _rURL, false );
+ }
+
+ sal_Int32 DBOConnectionHelper::checkPathExistence(const OUString& _rURL)
+ {
+ IS_PATH_EXIST e_exists = pathExists(_rURL, false);
+ if (!m_pCollection->supportsDBCreation(m_eType) &&
+ (( e_exists == PATH_NOT_EXIST) || ( e_exists == PATH_NOT_KNOWN)))
+ {
+ OUString sQuery(DBA_RES(STR_ASK_FOR_DIRECTORY_CREATION));
+ OFileNotation aTransformer(_rURL);
+ sQuery = sQuery.replaceFirst("$path$", aTransformer.get(OFileNotation::N_SYSTEM));
+
+ m_bUserGrabFocus = false;
+ vcl::Window* pWin = GetParent();
+ std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(pWin ? pWin->GetFrameWeld() : nullptr,
+ VclMessageType::Question, VclButtonsType::YesNo,
+ sQuery));
+ xQueryBox->set_default_response(RET_YES);
+ sal_Int32 nQueryResult = xQueryBox->run();
+ m_bUserGrabFocus = true;
+
+ switch (nQueryResult)
+ {
+ case RET_YES:
+ {
+ bool bTryCreate = false;
+ do
+ {
+ if ( !createDirectoryDeep(_rURL) )
+ { // could not create the directory
+ sQuery = DBA_RES(STR_COULD_NOT_CREATE_DIRECTORY);
+ sQuery = sQuery.replaceFirst("$name$", aTransformer.get(OFileNotation::N_SYSTEM));
+
+ m_bUserGrabFocus = false;
+
+ std::unique_ptr<weld::MessageDialog> xWhatToDo(Application::CreateMessageDialog(pWin ? pWin->GetFrameWeld() : nullptr,
+ VclMessageType::Question, VclButtonsType::NONE,
+ sQuery));
+ xWhatToDo->add_button(Button::GetStandardText(StandardButtonType::Retry), RET_RETRY);
+ xWhatToDo->add_button(Button::GetStandardText(StandardButtonType::Cancel), RET_CANCEL);
+ xWhatToDo->set_default_response(RET_RETRY);
+ nQueryResult = xWhatToDo->run();
+ m_bUserGrabFocus = true;
+
+ if (RET_RETRY == nQueryResult)
+ bTryCreate = true;
+ else
+ {
+ SetRoadmapStateValue(false);
+ callModifiedHdl();
+ return RET_RETRY;
+ }
+ }
+ }
+ while (bTryCreate);
+ }
+ break;
+
+ case RET_NO:
+ callModifiedHdl();
+ return RET_OK;
+
+ default:
+ // cancelled
+ SetRoadmapStateValue(false);
+ callModifiedHdl();
+ return RET_CANCEL;
+ }
+ }
+/* else
+ {
+ // TODO: error msg
+ return RET_CANCEL;
+ } */
+ SetRoadmapStateValue(true);
+ callModifiedHdl();
+ return RET_OK;
+ }
+
+ IS_PATH_EXIST DBOConnectionHelper::pathExists(const OUString& _rURL, bool bIsFile) const
+ {
+ ::ucbhelper::Content aCheckExistence;
+ IS_PATH_EXIST eExists = PATH_NOT_EXIST;
+ Reference< css::task::XInteractionHandler > xInteractionHandler(
+ task::InteractionHandler::createWithParent(m_xORB, nullptr), UNO_QUERY );
+ OFilePickerInteractionHandler* pHandler = new OFilePickerInteractionHandler(xInteractionHandler);
+ xInteractionHandler = pHandler;
+
+ Reference< XCommandEnvironment > xCmdEnv = new ::ucbhelper::CommandEnvironment( xInteractionHandler, Reference< XProgressHandler >() );
+ try
+ {
+ aCheckExistence = ::ucbhelper::Content(_rURL, xCmdEnv, comphelper::getProcessComponentContext());
+ const bool bExists = bIsFile? aCheckExistence.isDocument(): aCheckExistence.isFolder();
+ eExists = bExists? PATH_EXIST: PATH_NOT_EXIST;
+ }
+ catch (const Exception&)
+ {
+ eExists = pHandler->isDoesNotExist() ? PATH_NOT_EXIST : (bIsFile ? PATH_NOT_EXIST : PATH_NOT_KNOWN);
+ }
+ return eExists;
+ }
+
+ IMPL_LINK_NOARG(DBOConnectionHelper, GetFocusHdl, weld::Widget&, void)
+ {
+ if (!m_pCollection->isFileSystemBased(m_eType))
+ return;
+ if (!m_bUserGrabFocus)
+ return;
+ // URL edit field got the focus
+ m_xConnectionURL->SaveValueNoPrefix();
+ }
+
+ IMPL_LINK_NOARG(DBOConnectionHelper, LoseFocusHdl, weld::Widget&, void)
+ {
+ if (!m_pCollection->isFileSystemBased(m_eType))
+ return;
+ if (!m_bUserGrabFocus)
+ return;
+ // URL edit field lost the focus
+ commitURL();
+ }
+
+ bool DBOConnectionHelper::createDirectoryDeep(const OUString& _rPathURL)
+ {
+ // get an URL object analyzing the URL for us ...
+ INetURLObject aParser;
+ aParser.SetURL(_rPathURL);
+
+ INetProtocol eProtocol = aParser.GetProtocol();
+
+ std::vector< OUString > aToBeCreated; // the to-be-created levels
+
+ // search a level which exists
+ IS_PATH_EXIST eParentExists = PATH_NOT_EXIST;
+ while ( eParentExists == PATH_NOT_EXIST && aParser.getSegmentCount())
+ {
+ aToBeCreated.push_back(aParser.getName()); // remember the local name for creation
+ aParser.removeSegment(); // cut the local name
+ eParentExists = pathExists(aParser.GetMainURL(INetURLObject::DecodeMechanism::NONE), false);
+ }
+
+ if (!aParser.getSegmentCount())
+ return false;
+
+ // create all the missing levels
+ try
+ {
+ // the parent content
+ Reference< XCommandEnvironment > xEmptyEnv;
+ ::ucbhelper::Content aParent(aParser.GetMainURL(INetURLObject::DecodeMechanism::NONE), xEmptyEnv, comphelper::getProcessComponentContext());
+
+ OUString sContentType;
+ if ( INetProtocol::File == eProtocol )
+ {
+ sContentType = "application/vnd.sun.staroffice.fsys-folder";
+ // the file UCP currently does not support the ContentType property
+ }
+ else
+ {
+ Any aContentType = aParent.getPropertyValue("ContentType");
+ aContentType >>= sContentType;
+ }
+
+ // the properties which need to be set on the new content
+ Sequence< OUString > aNewDirectoryProperties { "Title" };
+
+ // the values to be set
+ Sequence< Any > aNewDirectoryAttributes(1);
+
+ // loop
+ for ( std::vector< OUString >::const_reverse_iterator aLocalName = aToBeCreated.rbegin();
+ aLocalName != aToBeCreated.rend();
+ ++aLocalName
+ )
+ {
+ aNewDirectoryAttributes[0] <<= *aLocalName;
+ if (!aParent.insertNewContent(sContentType, aNewDirectoryProperties, aNewDirectoryAttributes, aParent))
+ return false;
+ }
+ }
+ catch ( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION("dbaccess");
+ return false;
+ }
+
+ return true;
+ }
+
+ void DBOConnectionHelper::fillWindows(std::vector< std::unique_ptr<ISaveValueWrapper> >& _rControlList)
+ {
+ _rControlList.emplace_back(new ODisableWidgetWrapper<weld::Label>(m_xFT_Connection.get()));
+ _rControlList.emplace_back(new ODisableWidgetWrapper<weld::Button>(m_xPB_Connection.get()));
+ _rControlList.emplace_back(new ODisableWidgetWrapper<weld::Button>(m_xPB_CreateDB.get()));
+ }
+
+ void DBOConnectionHelper::fillControls(std::vector< std::unique_ptr<ISaveValueWrapper> >& _rControlList)
+ {
+ _rControlList.emplace_back( new OSaveValueWidgetWrapper<DBOConnectionURLEdit>( m_xConnectionURL.get() ) );
+ }
+
+ void DBOConnectionHelper::commitURL()
+ {
+ OUString sURL;
+ OUString sOldPath;
+ sOldPath = m_xConnectionURL->GetSavedValueNoPrefix();
+ sURL = m_xConnectionURL->GetTextNoPrefix();
+
+ if ( m_pCollection->isFileSystemBased(m_eType) )
+ {
+ if ( ( sURL != sOldPath ) && !sURL.isEmpty() )
+ { // the text changed since entering the control
+
+ // the path may be in system notation ....
+ OFileNotation aTransformer(sURL);
+ sURL = aTransformer.get(OFileNotation::N_URL);
+
+ const ::dbaccess::DATASOURCE_TYPE eType = m_pCollection->determineType(m_eType);
+
+ if ( ( ::dbaccess::DST_CALC == eType) || ( ::dbaccess::DST_WRITER == eType) || ( ::dbaccess::DST_MSACCESS == eType) || ( ::dbaccess::DST_MSACCESS_2007 == eType) )
+ {
+ if( pathExists(sURL, true) == PATH_NOT_EXIST )
+ {
+ OUString sFile = DBA_RES( STR_FILE_DOES_NOT_EXIST );
+ sFile = sFile.replaceFirst("$file$", aTransformer.get(OFileNotation::N_SYSTEM));
+ OSQLWarningBox aWarning(GetFrameWeld(), sFile);
+ aWarning.run();
+ setURLNoPrefix(sOldPath);
+ SetRoadmapStateValue(false);
+ callModifiedHdl();
+ return;
+ }
+ }
+ else
+ {
+ switch (checkPathExistence(sURL))
+ {
+ case RET_RETRY:
+ m_bUserGrabFocus = false;
+ m_xConnectionURL->grab_focus();
+ m_bUserGrabFocus = true;
+ return;
+ case RET_CANCEL:
+ setURLNoPrefix(sOldPath);
+ return;
+ }
+ }
+ }
+ }
+
+ setURLNoPrefix(sURL);
+ m_xConnectionURL->SaveValueNoPrefix();
+ }
+
+ void DBOConnectionHelper::askForFileName(::sfx2::FileDialogHelper& _aFileOpen)
+ {
+ OUString sOldPath = getURLNoPrefix();
+ if ( !sOldPath.isEmpty() )
+ _aFileOpen.SetDisplayDirectory(sOldPath);
+ else
+ _aFileOpen.SetDisplayDirectory( SvtPathOptions().GetWorkPath() );
+ if (ERRCODE_NONE == _aFileOpen.Execute())
+ {
+ setURLNoPrefix(_aFileOpen.GetPath());
+ SetRoadmapStateValue(checkTestConnection());
+ callModifiedHdl();
+ }
+ }
+
} // namespace dbaui
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/dbaccess/source/ui/dlg/ConnectionHelper.hxx b/dbaccess/source/ui/dlg/ConnectionHelper.hxx
index e7a1a2f3264b..1aa51976663c 100644
--- a/dbaccess/source/ui/dlg/ConnectionHelper.hxx
+++ b/dbaccess/source/ui/dlg/ConnectionHelper.hxx
@@ -98,6 +98,72 @@ namespace dbaui
void implUpdateURLDependentStates() const;
};
+ class DBOConnectionHelper : public OGenericAdministrationPage
+ {
+ bool m_bUserGrabFocus;
+
+ public:
+ DBOConnectionHelper(TabPageParent pParent, const OUString& _rUIXMLDescription, const OString& _rId, const SfxItemSet& _rCoreAttrs);
+ virtual ~DBOConnectionHelper() override;
+ virtual void dispose() override;
+
+ OUString m_eType; // the type can't be changed in this class, so we hold it as member.
+ // setting/retrieving the current connection URL
+ // necessary because for some types, the URL must be decoded for display purposes
+ ::dbaccess::ODsnTypeCollection* m_pCollection; /// the DSN type collection instance
+
+ std::unique_ptr<weld::Label> m_xFT_Connection;
+ std::unique_ptr<weld::Button> m_xPB_Connection;
+ std::unique_ptr<weld::Button> m_xPB_CreateDB;
+ std::unique_ptr<DBOConnectionURLEdit> m_xConnectionURL;
+
+ public:
+
+ // <method>OGenericAdministrationPage::fillControls</method>
+ virtual void fillControls(std::vector< std::unique_ptr<ISaveValueWrapper> >& _rControlList) override;
+ // <method>OGenericAdministrationPage::fillWindows</method>
+ virtual void fillWindows(std::vector< std::unique_ptr<ISaveValueWrapper> >& _rControlList) override;
+ virtual void implInitControls(const SfxItemSet& _rSet, bool _bSaveValue) override;
+
+ // setting/retrieving the current connection URL
+ // necessary because for some types, the URL must be decoded for display purposes
+ //String getURL( OConnectionURLEdit* _m_pConnection ) const;
+ //void setURL( const OUString& _rURL, OConnectionURLEdit* _m_pConnection );
+
+ OUString getURLNoPrefix( ) const;
+ void setURLNoPrefix( const OUString& _rURL );
+
+ /** checks if the path is existence
+ @param _rURL
+ The URL to check.
+ */
+ sal_Int32 checkPathExistence(const OUString& _rURL);
+
+ IS_PATH_EXIST pathExists(const OUString& _rURL, bool bIsFile) const;
+ bool createDirectoryDeep(const OUString& _rPathNormalized);
+ void commitURL();
+
+ /** opens the FileOpen dialog and asks for a FileName
+ @param _aFileOpen
+ Executes the file open dialog, which must be filled from caller.
+ */
+ void askForFileName(::sfx2::FileDialogHelper& _aFileOpen);
+
+ protected:
+ void setURL( const OUString& _rURL );
+ virtual bool checkTestConnection();
+
+ private:
+ DECL_LINK(OnBrowseConnections, weld::Button&, void);
+ DECL_LINK(OnCreateDatabase, weld::Button&, void);
+ DECL_LINK(GetFocusHdl, weld::Widget&, void);
+ DECL_LINK(LoseFocusHdl, weld::Widget&, void);
+ OUString impl_getURL() const;
+ void impl_setURL( const OUString& _rURL, bool _bPrefix );
+ void implUpdateURLDependentStates() const;
+ };
+
+
} // namespace dbaui
#endif // INCLUDED_DBACCESS_SOURCE_UI_DLG_CONNECTIONHELPER_HXX
diff --git a/dbaccess/source/ui/dlg/ConnectionPage.cxx b/dbaccess/source/ui/dlg/ConnectionPage.cxx
index 3fef20d84ed4..f896451c2919 100644
--- a/dbaccess/source/ui/dlg/ConnectionPage.cxx
+++ b/dbaccess/source/ui/dlg/ConnectionPage.cxx
@@ -76,33 +76,31 @@ namespace dbaui
using namespace ::dbtools;
using namespace ::svt;
- VclPtr<SfxTabPage> OConnectionTabPage::Create( TabPageParent pParent, const SfxItemSet* _rAttrSet )
+ VclPtr<SfxTabPage> OConnectionTabPage::Create(TabPageParent pParent, const SfxItemSet* _rAttrSet)
{
- return VclPtr<OConnectionTabPage>::Create( pParent.pParent, *_rAttrSet );
+ return VclPtr<OConnectionTabPage>::Create(pParent, *_rAttrSet);
}
// OConnectionTabPage
- OConnectionTabPage::OConnectionTabPage(vcl::Window* pParent, const SfxItemSet& _rCoreAttrs)
- :OConnectionHelper(pParent, "ConnectionPage", "dbaccess/ui/connectionpage.ui", _rCoreAttrs)
+ OConnectionTabPage::OConnectionTabPage(TabPageParent pParent, const SfxItemSet& _rCoreAttrs)
+ : DBOConnectionHelper(pParent, "dbaccess/ui/connectionpage.ui", "ConnectionPage", _rCoreAttrs)
+ , m_xFL2(m_xBuilder->weld_label("userlabel"))
+ , m_xUserNameLabel(m_xBuilder->weld_label("userNameLabel"))
+ , m_xUserName(m_xBuilder->weld_entry("userNameEntry"))
+ , m_xPasswordRequired(m_xBuilder->weld_check_button("passCheckbutton"))
+ , m_xFL3(m_xBuilder->weld_label("JDBCLabel"))
+ , m_xJavaDriverLabel(m_xBuilder->weld_label("javaDriverLabel"))
+ , m_xJavaDriver(m_xBuilder->weld_entry("driverEntry"))
+ , m_xTestJavaDriver(m_xBuilder->weld_button("driverButton"))
+ , m_xTestConnection(m_xBuilder->weld_button("connectionButton"))
{
- get(m_pFL2, "userlabel");
- get(m_pUserNameLabel, "userNameLabel");
- get(m_pUserName, "userNameEntry");
- get(m_pPasswordRequired, "passCheckbutton");
- get(m_pFL3, "JDBCLabel");
- get(m_pJavaDriverLabel, "javaDriverLabel");
- get(m_pJavaDriver, "driverEntry");
- get(m_pTestJavaDriver, "driverButton");
- get(m_pTestConnection, "connectionButton");
+ m_xConnectionURL->connect_changed(LINK(this, OConnectionTabPage, OnEditModified));
+ m_xJavaDriver->connect_changed(LINK(this, OConnectionTabPage, OnEditModified));
+ m_xUserName->connect_changed(LINK(this, OGenericAdministrationPage, OnControlEntryModifyHdl));
+ m_xPasswordRequired->connect_toggled(LINK(this, OGenericAdministrationPage, OnControlModifiedButtonClick));
- m_pConnectionURL->SetModifyHdl(LINK(this, OConnectionTabPage, OnEditModified));
- m_pJavaDriver->SetModifyHdl(LINK(this, OGenericAdministrationPage, OnControlEditModifyHdl));
- m_pJavaDriver->SetModifyHdl(LINK(this, OConnectionTabPage, OnEditModified));
- m_pUserName->SetModifyHdl(LINK(this, OGenericAdministrationPage, OnControlEditModifyHdl));
- m_pPasswordRequired->SetClickHdl(LINK(this, OGenericAdministrationPage, OnControlModifiedClick));
-
- m_pTestConnection->SetClickHdl(LINK(this,OGenericAdministrationPage,OnTestConnectionClickHdl));
- m_pTestJavaDriver->SetClickHdl(LINK(this,OConnectionTabPage,OnTestJavaClickHdl));
+ m_xTestConnection->connect_clicked(LINK(this,OGenericAdministrationPage,OnTestConnectionButtonClickHdl));
+ m_xTestJavaDriver->connect_clicked(LINK(this,OConnectionTabPage,OnTestJavaClickHdl));
}
OConnectionTabPage::~OConnectionTabPage()
@@ -110,20 +108,6 @@ namespace dbaui
disposeOnce();
}
- void OConnectionTabPage::dispose()
- {
- m_pFL2.clear();
- m_pUserNameLabel.clear();
- m_pUserName.clear();
- m_pPasswordRequired.clear();
- m_pFL3.clear();
- m_pJavaDriverLabel.clear();
- m_pJavaDriver.clear();
- m_pTestJavaDriver.clear();
- m_pTestConnection.clear();
- OConnectionHelper::dispose();
- }
-
void OConnectionTabPage::implInitControls(const SfxItemSet& _rSet, bool _bSaveValue)
{
// check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa)
@@ -131,60 +115,60 @@ namespace dbaui
getFlags(_rSet, bValid, bReadonly);
m_eType = m_pAdminDialog->getDatasourceType(_rSet);
- OConnectionHelper::implInitControls( _rSet, _bSaveValue);
+ DBOConnectionHelper::implInitControls( _rSet, _bSaveValue);
::dbaccess::DATASOURCE_TYPE eType = m_pCollection->determineType(m_eType);
switch( eType )
{
case ::dbaccess::DST_DBASE:
- m_pFT_Connection->SetText(DBA_RES(STR_DBASE_PATH_OR_FILE));
- m_pConnectionURL->SetHelpId(HID_DSADMIN_DBASE_PATH);
+ m_xFT_Connection->set_label(DBA_RES(STR_DBASE_PATH_OR_FILE));
+ m_xConnectionURL->set_help_id(HID_DSADMIN_DBASE_PATH);
break;
case ::dbaccess::DST_FLAT:
- m_pFT_Connection->SetText(DBA_RES(STR_FLAT_PATH_OR_FILE));
- m_pConnectionURL->SetHelpId(HID_DSADMIN_FLAT_PATH);
+ m_xFT_Connection->set_label(DBA_RES(STR_FLAT_PATH_OR_FILE));
+ m_xConnectionURL->set_help_id(HID_DSADMIN_FLAT_PATH);
break;
case ::dbaccess::DST_CALC:
- m_pFT_Connection->SetText(DBA_RES(STR_CALC_PATH_OR_FILE));
- m_pConnectionURL->SetHelpId(HID_DSADMIN_CALC_PATH);
+ m_xFT_Connection->set_label(DBA_RES(STR_CALC_PATH_OR_FILE));
+ m_xConnectionURL->set_help_id(HID_DSADMIN_CALC_PATH);
break;
case ::dbaccess::DST_WRITER:
- m_pFT_Connection->SetText(DBA_RES(STR_WRITER_PATH_OR_FILE));
- m_pConnectionURL->SetHelpId(HID_DSADMIN_WRITER_PATH);
+ m_xFT_Connection->set_label(DBA_RES(STR_WRITER_PATH_OR_FILE));
+ m_xConnectionURL->set_help_id(HID_DSADMIN_WRITER_PATH);
break;
case ::dbaccess::DST_ADO:
- m_pFT_Connection->SetText(DBA_RES(STR_COMMONURL));
+ m_xFT_Connection->set_label(DBA_RES(STR_COMMONURL));
break;
case ::dbaccess::DST_MSACCESS:
case ::dbaccess::DST_MSACCESS_2007:
- m_pFT_Connection->SetText(DBA_RES(STR_MSACCESS_MDB_FILE));
- m_pConnectionURL->SetHelpId(HID_DSADMIN_MSACCESS_MDB_FILE);
+ m_xFT_Connection->set_label(DBA_RES(STR_MSACCESS_MDB_FILE));
+ m_xConnectionURL->set_help_id(HID_DSADMIN_MSACCESS_MDB_FILE);
break;
case ::dbaccess::DST_MYSQL_NATIVE:
case ::dbaccess::DST_MYSQL_JDBC:
- m_pFT_Connection->SetText(DBA_RES(STR_MYSQL_DATABASE_NAME));
- m_pConnectionURL->SetHelpId( HID_DSADMIN_MYSQL_DATABASE );
+ m_xFT_Connection->set_label(DBA_RES(STR_MYSQL_DATABASE_NAME));
+ m_xConnectionURL->set_help_id( HID_DSADMIN_MYSQL_DATABASE );
break;
case ::dbaccess::DST_ORACLE_JDBC:
- m_pFT_Connection->SetText(DBA_RES(STR_ORACLE_DATABASE_NAME));
- m_pConnectionURL->SetHelpId(HID_DSADMIN_ORACLE_DATABASE);
+ m_xFT_Connection->set_label(DBA_RES(STR_ORACLE_DATABASE_NAME));
+ m_xConnectionURL->set_help_id(HID_DSADMIN_ORACLE_DATABASE);
break;
case ::dbaccess::DST_MYSQL_ODBC:
case ::dbaccess::DST_ODBC:
- m_pFT_Connection->SetText(DBA_RES(STR_NAME_OF_ODBC_DATASOURCE));
- m_pConnectionURL->SetHelpId( eType == ::dbaccess::DST_MYSQL_ODBC ? HID_DSADMIN_MYSQL_ODBC_DATASOURCE : HID_DSADMIN_ODBC_DATASOURCE);
+ m_xFT_Connection->set_label(DBA_RES(STR_NAME_OF_ODBC_DATASOURCE));
+ m_xConnectionURL->set_help_id( eType == ::dbaccess::DST_MYSQL_ODBC ? HID_DSADMIN_MYSQL_ODBC_DATASOURCE : HID_DSADMIN_ODBC_DATASOURCE);
break;
case ::dbaccess::DST_LDAP:
- m_pFT_Connection->SetText(DBA_RES(STR_HOSTNAME));
- m_pConnectionURL->SetHelpId( HID_DSADMIN_LDAP_HOSTNAME );
+ m_xFT_Connection->set_label(DBA_RES(STR_HOSTNAME));
+ m_xConnectionURL->set_help_id( HID_DSADMIN_LDAP_HOSTNAME );
break;
case ::dbaccess::DST_MOZILLA:
- m_pFT_Connection->SetText(DBA_RES(STR_MOZILLA_PROFILE_NAME));
- m_pConnectionURL->SetHelpId( HID_DSADMIN_MOZILLA_PROFILE_NAME );
+ m_xFT_Connection->set_label(DBA_RES(STR_MOZILLA_PROFILE_NAME));
+ m_xConnectionURL->set_help_id( HID_DSADMIN_MOZILLA_PROFILE_NAME );
break;
case ::dbaccess::DST_THUNDERBIRD:
- m_pFT_Connection->SetText(DBA_RES(STR_THUNDERBIRD_PROFILE_NAME));
- m_pConnectionURL->SetHelpId( HID_DSADMIN_THUNDERBIRD_PROFILE_NAME );
+ m_xFT_Connection->set_label(DBA_RES(STR_THUNDERBIRD_PROFILE_NAME));
+ m_xConnectionURL->set_help_id( HID_DSADMIN_THUNDERBIRD_PROFILE_NAME );
break;
case ::dbaccess::DST_OUTLOOK:
case ::dbaccess::DST_OUTLOOKEXP:
@@ -193,18 +177,18 @@ namespace dbaui
case ::dbaccess::DST_EVOLUTION_LDAP:
case ::dbaccess::DST_KAB:
case ::dbaccess::DST_MACAB:
- m_pFT_Connection->SetText(DBA_RES(STR_NO_ADDITIONAL_SETTINGS));
+ m_xFT_Connection->set_label(DBA_RES(STR_NO_ADDITIONAL_SETTINGS));
{
- OUString sText = m_pFT_Connection->GetText();
- sText = sText.replaceAll("%test",m_pTestConnection->GetText());
+ OUString sText = m_xFT_Connection->get_label();
+ sText = sText.replaceAll("%test",m_xTestConnection->get_label());
sText = sText.replaceAll("~","");
- m_pFT_Connection->SetText(sText);
+ m_xFT_Connection->set_label(sText);
}
- m_pConnectionURL->Hide();
+ m_xConnectionURL->hide();
break;
case ::dbaccess::DST_JDBC:
default:
- m_pFT_Connection->SetText(DBA_RES(STR_COMMONURL));
+ m_xFT_Connection->set_label(DBA_RES(STR_COMMONURL));
break;
}
@@ -212,13 +196,11 @@ namespace dbaui
bool bShowUserAuthenfication = ( eAuthMode != AuthNone );
bool bShowUser = ( eAuthMode == AuthUserPwd );
- m_pPB_Connection->SetHelpId(HID_DSADMIN_BROWSECONN);
- m_pFL2->Show( bShowUserAuthenfication );
- m_pUserNameLabel->Show( bShowUser && bShowUserAuthenfication );
- m_pUserName->Show( bShowUser && bShowUserAuthenfication );
- m_pPasswordRequired->Show( bShowUserAuthenfication );
- if ( !bShowUser && bShowUserAuthenfication )
- m_pPasswordRequired->SetPosPixel(m_pUserNameLabel->GetPosPixel());
+ m_xPB_Connection->set_help_id(HID_DSADMIN_BROWSECONN);
+ m_xFL2->show( bShowUserAuthenfication );
+ m_xUserNameLabel->show( bShowUser && bShowUserAuthenfication );
+ m_xUserName->show( bShowUser && bShowUserAuthenfication );
+ m_xPasswordRequired->show( bShowUserAuthenfication );
// collect the items
const SfxStringItem* pUidItem = _rSet.GetItem<SfxStringItem>(DSID_USER);
@@ -230,8 +212,8 @@ namespace dbaui
// forward the values to the controls
if ( bValid )
{
- m_pUserName->SetText(pUidItem->GetValue());
- m_pPasswordRequired->Check(pAllowEmptyPwd->GetValue());
+ m_xUserName->set_text(pUidItem->GetValue());
+ m_xPasswordRequired->set_active(pAllowEmptyPwd->GetValue());
const OUString& sUrl = pUrlItem->GetValue();
setURL( sUrl );
@@ -241,25 +223,22 @@ namespace dbaui
{
OUString sDefaultJdbcDriverName = m_pCollection->getJavaDriverClass(m_eType);
if ( !sDefaultJdbcDriverName.isEmpty() )
- {
- m_pJavaDriver->SetText(sDefaultJdbcDriverName);
- m_pJavaDriver->SetModifyFlag();
- }
+ m_xJavaDriver->set_text(sDefaultJdbcDriverName);
}
else
- m_pJavaDriver->SetText(pJdbcDrvItem->GetValue());
+ m_xJavaDriver->set_text(pJdbcDrvItem->GetValue());
- m_pJavaDriverLabel->Show(bEnableJDBC);
- m_pJavaDriver->Show(bEnableJDBC);
- m_pTestJavaDriver->Show(bEnableJDBC);
- m_pTestJavaDriver->Enable( !m_pJavaDriver->GetText().trim().isEmpty() );
- m_pFL3->Show(bEnableJDBC);
+ m_xJavaDriverLabel->show(bEnableJDBC);
+ m_xJavaDriver->show(bEnableJDBC);
+ m_xTestJavaDriver->show(bEnableJDBC);
+ m_xTestJavaDriver->set_sensitive( !m_xJavaDriver->get_text().trim().isEmpty() );
+ m_xFL3->show(bEnableJDBC);
checkTestConnection();
- m_pUserName->ClearModifyFlag();
- m_pConnectionURL->ClearModifyFlag();
- m_pJavaDriver->ClearModifyFlag();
+ m_xUserName->save_value();
+ m_xConnectionURL->save_value();
+ m_xJavaDriver->save_value();
}
}
@@ -267,36 +246,36 @@ namespace dbaui
{
bool bChangedSomething = false;
- if (m_pUserName->IsValueChangedFromSaved())
+ if (m_xUserName->get_value_changed_from_saved())
{
- _rSet->Put(SfxStringItem(DSID_USER, m_pUserName->GetText()));
+ _rSet->Put(SfxStringItem(DSID_USER, m_xUserName->get_text()));
_rSet->Put(SfxStringItem(DSID_PASSWORD, OUString()));
bChangedSomething = true;
}
- fillBool(*_rSet,m_pPasswordRequired,DSID_PASSWORDREQUIRED,bChangedSomething);
+ fillBool(*_rSet,m_xPasswordRequired.get(),DSID_PASSWORDREQUIRED,false, bChangedSomething);
if ( m_pCollection->determineType(m_eType) == ::dbaccess::DST_JDBC )
{
- fillString(*_rSet,m_pJavaDriver, DSID_JDBCDRIVERCLASS, bChangedSomething);
+ fillString(*_rSet,m_xJavaDriver.get(), DSID_JDBCDRIVERCLASS, bChangedSomething);
}
- fillString(*_rSet,m_pConnectionURL, DSID_CONNECTURL, bChangedSomething);
+ fillString(*_rSet,m_xConnectionURL.get(), DSID_CONNECTURL, bChangedSomething);
return bChangedSomething;
}
- IMPL_LINK_NOARG(OConnectionTabPage, OnTestJavaClickHdl, Button*, void)
+ IMPL_LINK_NOARG(OConnectionTabPage, OnTestJavaClickHdl, weld::Button&, void)
{
OSL_ENSURE(m_pAdminDialog,"No Admin dialog set! ->GPF");
bool bSuccess = false;
#if HAVE_FEATURE_JAVA
try
{
- if ( !m_pJavaDriver->GetText().trim().isEmpty() )
+ if ( !m_xJavaDriver->get_text().trim().isEmpty() )
{
::rtl::Reference< jvmaccess::VirtualMachine > xJVM = ::connectivity::getJavaVM( m_pAdminDialog->getORB() );
- m_pJavaDriver->SetText(m_pJavaDriver->GetText().trim()); // fdo#68341
- bSuccess = ::connectivity::existsJavaClassByName(xJVM,m_pJavaDriver->GetText().trim());
+ m_xJavaDriver->set_text(m_xJavaDriver->get_text().trim()); // fdo#68341
+ bSuccess = ::connectivity::existsJavaClassByName(xJVM,m_xJavaDriver->get_text().trim());
}
}
catch(Exception&)
@@ -312,16 +291,16 @@ namespace dbaui
bool OConnectionTabPage::checkTestConnection()
{
OSL_ENSURE(m_pAdminDialog,"No Admin dialog set! ->GPF");
- bool bEnableTestConnection = !m_pConnectionURL->IsVisible() || !m_pConnectionURL->GetTextNoPrefix().isEmpty();
+ bool bEnableTestConnection = !m_xConnectionURL->get_visible() || !m_xConnectionURL->GetTextNoPrefix().isEmpty();
if ( m_pCollection->determineType(m_eType) == ::dbaccess::DST_JDBC )
- bEnableTestConnection = bEnableTestConnection && (!m_pJavaDriver->GetText().trim().isEmpty());
- m_pTestConnection->Enable(bEnableTestConnection);
+ bEnableTestConnection = bEnableTestConnection && (!m_xJavaDriver->get_text().trim().isEmpty());
+ m_xTestConnection->set_sensitive(bEnableTestConnection);
return true;
}
- IMPL_LINK(OConnectionTabPage, OnEditModified, Edit&, _rEdit, void)
+ IMPL_LINK(OConnectionTabPage, OnEditModified, weld::Entry&, rEdit, void)
{
- if ( &_rEdit == m_pJavaDriver )
- m_pTestJavaDriver->Enable( !m_pJavaDriver->GetText().trim().isEmpty() );
+ if (&rEdit == m_xJavaDriver.get())
+ m_xTestJavaDriver->set_sensitive( !m_xJavaDriver->get_text().trim().isEmpty() );
checkTestConnection();
// tell the listener we were modified
diff --git a/dbaccess/source/ui/dlg/ConnectionPage.hxx b/dbaccess/source/ui/dlg/ConnectionPage.hxx
index 089baf330104..d7d4be7b5fe8 100644
--- a/dbaccess/source/ui/dlg/ConnectionPage.hxx
+++ b/dbaccess/source/ui/dlg/ConnectionPage.hxx
@@ -32,32 +32,31 @@ namespace dbaui
/** implements the connection page of the data source properties dialog.
*/
- class OConnectionTabPage final : public OConnectionHelper
+ class OConnectionTabPage final : public DBOConnectionHelper
{
friend class VclPtr<OConnectionTabPage>;
private:
// user authentication
- VclPtr<FixedText> m_pFL2;
- VclPtr<FixedText> m_pUserNameLabel;
- VclPtr<Edit> m_pUserName;
- VclPtr<CheckBox> m_pPasswordRequired;
+ std::unique_ptr<weld::Label> m_xFL2;
+ std::unique_ptr<weld::Label> m_xUserNameLabel;
+ std::unique_ptr<weld::Entry> m_xUserName;
+ std::unique_ptr<weld::CheckButton> m_xPasswordRequired;
// jdbc driver
- VclPtr<FixedText> m_pFL3;
- VclPtr<FixedText> m_pJavaDriverLabel;
- VclPtr<Edit> m_pJavaDriver;
- VclPtr<PushButton> m_pTestJavaDriver;
+ std::unique_ptr<weld::Label> m_xFL3;
+ std::unique_ptr<weld::Label> m_xJavaDriverLabel;
+ std::unique_ptr<weld::Entry> m_xJavaDriver;
+ std::unique_ptr<weld::Button> m_xTestJavaDriver;
// connection test
- VclPtr<PushButton> m_pTestConnection;
+ std::unique_ptr<weld::Button> m_xTestConnection;
// called when the test connection button was clicked
- DECL_LINK(OnTestJavaClickHdl, Button*, void);
- DECL_LINK(OnEditModified, Edit&, void);
+ DECL_LINK(OnTestJavaClickHdl, weld::Button&, void);
+ DECL_LINK(OnEditModified, weld::Entry&, void);
public:
virtual ~OConnectionTabPage() override;
- virtual void dispose() override;
static VclPtr<SfxTabPage> Create( TabPageParent pParent, const SfxItemSet* _rAttrSet );
virtual bool FillItemSet (SfxItemSet* _rCoreAttrs) override;
@@ -68,7 +67,7 @@ namespace dbaui
affect the type may be changed (compared to the previous URL).</p>
*/
private:
- OConnectionTabPage(vcl::Window* pParent, const SfxItemSet& _rCoreAttrs);
+ OConnectionTabPage(TabPageParent pParent, const SfxItemSet& _rCoreAttrs);
// nControlFlags is a combination of the CBTP_xxx-constants
/** enables the test connection button, if allowed
diff --git a/dbaccess/source/ui/dlg/adminpages.cxx b/dbaccess/source/ui/dlg/adminpages.cxx
index da98c3f41d3c..94563a153fd8 100644
--- a/dbaccess/source/ui/dlg/adminpages.cxx
+++ b/dbaccess/source/ui/dlg/adminpages.cxx
@@ -292,6 +292,14 @@ namespace dbaui
_bChangedSomething = true;
}
}
+ void OGenericAdministrationPage::fillString(SfxItemSet& _rSet, const dbaui::DBOConnectionURLEdit* pEdit, sal_uInt16 _nID, bool& _bChangedSomething)
+ {
+ if (pEdit && pEdit->get_value_changed_from_saved())
+ {
+ _rSet.Put(SfxStringItem(_nID, pEdit->GetText()));
+ _bChangedSomething = true;
+ }
+ }
IMPL_LINK_NOARG(OGenericAdministrationPage, OnTestConnectionClickHdl, Button*, void)
{
@@ -334,6 +342,47 @@ namespace dbaui
}
}
+ IMPL_LINK_NOARG(OGenericAdministrationPage, OnTestConnectionButtonClickHdl, weld::Button&, void)
+ {
+ OSL_ENSURE(m_pAdminDialog,"No Admin dialog set! ->GPF");
+ bool bSuccess = false;
+ if ( m_pAdminDialog )
+ {
+ m_pAdminDialog->saveDatasource();
+ OGenericAdministrationPage::implInitControls(*m_pItemSetHelper->getOutputSet(), true);
+ bool bShowMessage = true;
+ try
+ {
+ std::pair< Reference<XConnection>,bool> aConnectionPair = m_pAdminDialog->createConnection();
+ bShowMessage = aConnectionPair.second;
+ bSuccess = aConnectionPair.first.is();
+ ::comphelper::disposeComponent(aConnectionPair.first);
+ }
+ catch(Exception&)
+ {
+ }
+ if ( bShowMessage )
+ {
+ MessageType eImage = MessageType::Info;
+ OUString aMessage,sTitle;
+ sTitle = DBA_RES(STR_CONNECTION_TEST);
+ if ( bSuccess )
+ {
+ aMessage = DBA_RES(STR_CONNECTION_SUCCESS);
+ }
+ else
+ {
+ eImage = MessageType::Error;
+ aMessage = DBA_RES(STR_CONNECTION_NO_SUCCESS);
+ }
+ OSQLMessageBox aMsg(GetFrameWeld(), sTitle, aMessage, MessBoxStyle::Ok, eImage);
+ aMsg.run();
+ }
+ if ( !bSuccess )
+ m_pAdminDialog->clearPassword();
+ }
+ }
+
// LayoutHelper
void LayoutHelper::positionBelow( const Control& _rReference, Control& _rControl,
const long _nIndentAppFont )
diff --git a/dbaccess/source/ui/dlg/adminpages.hxx b/dbaccess/source/ui/dlg/adminpages.hxx
index 1b2b8b980a59..64c787014e8b 100644
--- a/dbaccess/source/ui/dlg/adminpages.hxx
+++ b/dbaccess/source/ui/dlg/adminpages.hxx
@@ -26,6 +26,7 @@
#include <svtools/wizardmachine.hxx>
#include <vcl/field.hxx>
#include <vcl/fixed.hxx>
+#include <curledit.hxx>
class NumericField;
class Edit;
@@ -73,6 +74,17 @@ namespace dbaui
virtual void Disable() override { m_pSaveValue->set_sensitive(false); }
};
+ template <> class OSaveValueWidgetWrapper<dbaui::DBOConnectionURLEdit> : public ISaveValueWrapper
+ {
+ dbaui::DBOConnectionURLEdit* m_pSaveValue;
+ public:
+ explicit OSaveValueWidgetWrapper(dbaui::DBOConnectionURLEdit* _pSaveValue) : m_pSaveValue(_pSaveValue)
+ { OSL_ENSURE(m_pSaveValue,"Illegal argument!"); }
+
+ virtual void SaveValue() override { m_pSaveValue->save_value(); }
+ virtual void Disable() override { m_pSaveValue->set_sensitive(false); }
+ };
+
template <class T> class ODisableWidgetWrapper : public ISaveValueWrapper
{
T* m_pSaveValue;
@@ -238,6 +250,7 @@ namespace dbaui
*/
static void fillString(SfxItemSet& _rSet,Edit const * _pEdit,sal_uInt16 _nID, bool& _bChangedSomething);
static void fillString(SfxItemSet& _rSet,const weld::Entry* pEdit,sal_uInt16 _nID, bool& _bChangedSomething);
+ static void fillString(SfxItemSet& _rSet,const dbaui::DBOConnectionURLEdit* pEdit,sal_uInt16 _nID, bool& _bChangedSomething);
protected:
/** This link be used for controls where the tabpage does not need to take any special action when the control
@@ -251,6 +264,7 @@ namespace dbaui
DECL_LINK(OnControlModifiedClick, Button*, void);
DECL_LINK(ControlModifiedCheckBoxHdl, CheckBox&, void);
+ DECL_LINK(OnTestConnectionButtonClickHdl, weld::Button&, void);
DECL_LINK(OnTestConnectionClickHdl, Button*, void);
};
diff --git a/dbaccess/source/ui/inc/curledit.hxx b/dbaccess/source/ui/inc/curledit.hxx
index a4a40f3453f9..66168e14ac66 100644
--- a/dbaccess/source/ui/inc/curledit.hxx
+++ b/dbaccess/source/ui/inc/curledit.hxx
@@ -22,6 +22,7 @@
#include <vcl/edit.hxx>
#include <vcl/fixed.hxx>
+#include <vcl/weld.hxx>
#include <dsntypes.hxx>
namespace dbaui
@@ -67,6 +68,78 @@ public:
void SetTypeCollection(::dbaccess::ODsnTypeCollection* _pTypeCollection) { m_pTypeCollection = _pTypeCollection; }
};
+class DBOConnectionURLEdit
+{
+ OUString m_sSavedValue;
+
+ ::dbaccess::ODsnTypeCollection* m_pTypeCollection;
+ OUString m_sSaveValueNoPrefix;
+ bool m_bShowPrefix; // when <TRUE> the prefix will be visible, otherwise not
+
+ std::unique_ptr<weld::Entry> m_xEntry;
+ std::unique_ptr<weld::Label> m_xForcedPrefix;
+
+public:
+ DBOConnectionURLEdit(std::unique_ptr<weld::Entry> xEntry, std::unique_ptr<weld::Label> xForcedPrefix);
+ ~DBOConnectionURLEdit();
+
+public:
+ bool get_visible() const { return m_xEntry->get_visible(); }
+ void connect_changed(const Link<weld::Entry&, void>& rLink) { m_xEntry->connect_changed(rLink); }
+ void set_help_id(const OString& rName) { m_xEntry->set_help_id(rName); }
+ void hide()
+ {
+ m_xEntry->hide();
+ if (m_bShowPrefix)
+ m_xForcedPrefix->hide();
+ }
+ void show()
+ {
+ m_xEntry->show();
+ if (m_bShowPrefix)
+ m_xForcedPrefix->show();
+ }
+ void save_value() { m_sSavedValue = GetText(); }
+ bool get_value_changed_from_saved() const { return m_sSavedValue != GetText(); }
+ void grab_focus()
+ {
+ m_xEntry->grab_focus();
+ }
+ void set_sensitive(bool bSensitive)
+ {
+ m_xEntry->set_sensitive(bSensitive);
+ if (m_bShowPrefix)
+ m_xForcedPrefix->set_sensitive(bSensitive);
+ }
+ void connect_focus_in(const Link<weld::Widget&, void>& rLink)
+ {
+ m_xEntry->connect_focus_in(rLink);
+ }
+ void connect_focus_out(const Link<weld::Widget&, void>& rLink)
+ {
+ m_xEntry->connect_focus_out(rLink);
+ }
+
+ // Edit overridables
+ void SetText(const OUString& _rStr);
+ void SetText(const OUString& _rStr, const Selection& _rNewSelection);
+ OUString GetText() const;
+
+ /** Shows the Prefix
+ @param _bShowPrefix
+ If <TRUE/> than the prefix will be visible, otherwise not.
+ */
+ void ShowPrefix(bool _bShowPrefix);
+ /// get the currently set text, excluding the prefix indicating the type
+ OUString GetTextNoPrefix() const;
+ /// set a new text, leave the current prefix unchanged
+ void SetTextNoPrefix(const OUString& _rText);
+
+ void SaveValueNoPrefix() { m_sSaveValueNoPrefix = GetTextNoPrefix(); }
+ const OUString& GetSavedValueNoPrefix() const { return m_sSaveValueNoPrefix; }
+ void SetTypeCollection(::dbaccess::ODsnTypeCollection* _pTypeCollection) { m_pTypeCollection = _pTypeCollection; }
+};
+
} // namespace dbaui
#endif // INCLUDED_DBACCESS_SOURCE_UI_INC_CURLEDIT_HXX
diff --git a/dbaccess/uiconfig/ui/connectionpage.ui b/dbaccess/uiconfig/ui/connectionpage.ui
index cdb59e5d2153..7e0faa324596 100644
--- a/dbaccess/uiconfig/ui/connectionpage.ui
+++ b/dbaccess/uiconfig/ui/connectionpage.ui
@@ -1,8 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.18.3 -->
+<!-- Generated with glade 3.22.1 -->
<interface domain="dba">
<requires lib="gtk+" version="3.18"/>
- <requires lib="LibreOffice" version="1.0"/>
<object class="GtkBox" id="ConnectionPage">
<property name="visible">True</property>
<property name="can_focus">False</property>
@@ -48,17 +47,6 @@
</packing>
</child>
<child>
- <object class="dbulo-ConnectionURLEdit" id="browseurl">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="hexpand">True</property>
- </object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">1</property>
- </packing>
- </child>
- <child>
<object class="GtkButton" id="create">
<property name="label" translatable="yes" context="connectionpage|create">_Create New</property>
<property name="visible">True</property>
@@ -84,6 +72,37 @@
<property name="top_attach">1</property>
</packing>
</child>
+ <child>
+ <object class="GtkGrid">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkEntry" id="browseurl">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="hexpand">True</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="browselabel">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">0</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">1</property>
+ </packing>
+ </child>
</object>
</child>
</object>
@@ -133,10 +152,10 @@
<object class="GtkLabel" id="userNameLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="xalign">1</property>
<property name="label" translatable="yes" context="connectionpage|userNameLabel">_User name:</property>
<property name="use_underline">True</property>
<property name="mnemonic_widget">userNameEntry</property>
+ <property name="xalign">1</property>
</object>
<packing>
<property name="left_attach">0</property>
@@ -220,10 +239,10 @@
<object class="GtkLabel" id="javaDriverLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="xalign">1</property>
<property name="label" translatable="yes" context="connectionpage|javaDriverLabel">_JDBC driver class:</property>
<property name="use_underline">True</property>
<property name="mnemonic_widget">driverEntry</property>
+ <property name="xalign">1</property>
</object>
<packing>
<property name="expand">False</property>
More information about the Libreoffice-commits
mailing list