calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / dbaccess / source / ui / dlg / generalpage.cxx
bloba2a48158c56d5e1a0e794b3862fbeb5777647440
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <config_features.h>
21 #include <core_resource.hxx>
22 #include "dsnItem.hxx"
23 #include "generalpage.hxx"
24 #include <connectivity/dbexception.hxx>
25 #include <strings.hrc>
26 #include <dsitems.hxx>
27 #include <sfx2/filedlghelper.hxx>
28 #include <sfx2/docfilt.hxx>
29 #include <utility>
30 #include <vcl/svapp.hxx>
31 #include <vcl/weld.hxx>
32 #include <svl/stritem.hxx>
33 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
34 #include <UITools.hxx>
35 #include <officecfg/Office/Common.hxx>
36 #include <comphelper/processfactory.hxx>
37 #include <unotools/confignode.hxx>
38 #include <o3tl/safeint.hxx>
39 #include <osl/diagnose.h>
40 #include <sal/log.hxx>
41 #include <dbwizsetup.hxx>
43 namespace dbaui
45 using namespace ::com::sun::star;
46 using namespace ::com::sun::star::uno;
47 using namespace ::com::sun::star::sdbc;
48 using namespace ::com::sun::star::beans;
49 using namespace ::com::sun::star::container;
51 // OGeneralPage
52 OGeneralPage::OGeneralPage(weld::Container* pPage, weld::DialogController* pController, const OUString& _rUIXMLDescription, const SfxItemSet& _rItems)
53 : OGenericAdministrationPage(pPage, pController, _rUIXMLDescription, "PageGeneral", _rItems)
54 , m_xSpecialMessage(m_xBuilder->weld_label("specialMessage"))
55 , m_eLastMessage(smNone)
56 , m_bInitTypeList(true)
57 , m_xDatasourceType(m_xBuilder->weld_combo_box("datasourceType"))
58 , m_pCollection(nullptr)
60 // extract the datasource type collection from the item set
61 const DbuTypeCollectionItem* pCollectionItem = dynamic_cast<const DbuTypeCollectionItem*>( _rItems.GetItem(DSID_TYPECOLLECTION) );
62 if (pCollectionItem)
63 m_pCollection = pCollectionItem->getCollection();
64 SAL_WARN_IF(!m_pCollection, "dbaccess.ui.generalpage", "OGeneralPage::OGeneralPage : really need a DSN type collection !");
66 // do some knittings
67 m_xDatasourceType->connect_changed(LINK(this, OGeneralPage, OnDatasourceTypeSelected));
70 OGeneralPage::~OGeneralPage()
74 namespace
76 struct DisplayedType
78 OUString eType;
79 OUString sDisplayName;
81 DisplayedType( OUString _eType, OUString _sDisplayName ) : eType(std::move( _eType )), sDisplayName(std::move( _sDisplayName )) { }
83 typedef std::vector< DisplayedType > DisplayedTypes;
85 struct DisplayedTypeLess
87 bool operator() ( const DisplayedType& _rLHS, const DisplayedType& _rRHS )
89 return _rLHS.eType < _rRHS.eType;
94 void OGeneralPage::initializeTypeList()
96 if ( !m_bInitTypeList )
97 return;
99 m_bInitTypeList = false;
100 m_xDatasourceType->clear();
102 if ( !m_pCollection )
103 return;
105 DisplayedTypes aDisplayedTypes;
107 ::dbaccess::ODsnTypeCollection::TypeIterator aEnd = m_pCollection->end();
108 for ( ::dbaccess::ODsnTypeCollection::TypeIterator aTypeLoop = m_pCollection->begin();
109 aTypeLoop != aEnd;
110 ++aTypeLoop
113 const OUString& sURLPrefix = aTypeLoop.getURLPrefix();
114 if ( !sURLPrefix.isEmpty() )
116 // skip mysql connection variations. It is handled in another window.
117 if(sURLPrefix.startsWith("sdbc:mysql:") && !sURLPrefix.startsWith("sdbc:mysql:jdbc:"))
118 continue;
120 OUString sDisplayName = aTypeLoop.getDisplayName();
121 if (m_xDatasourceType->find_text(sDisplayName) == -1 &&
122 approveDatasourceType(sURLPrefix, sDisplayName))
124 aDisplayedTypes.emplace_back( sURLPrefix, sDisplayName );
128 std::sort( aDisplayedTypes.begin(), aDisplayedTypes.end(), DisplayedTypeLess() );
129 for ( const auto& rDisplayedType : aDisplayedTypes )
130 insertDatasourceTypeEntryData( rDisplayedType.eType, rDisplayedType.sDisplayName );
133 void OGeneralPageWizard::initializeEmbeddedDBList()
135 if ( !m_bInitEmbeddedDBList )
136 return;
138 m_bInitEmbeddedDBList = false;
139 m_xEmbeddedDBType->clear();
141 if ( !m_pCollection )
142 return;
144 DisplayedTypes aDisplayedTypes;
146 ::dbaccess::ODsnTypeCollection::TypeIterator aEnd = m_pCollection->end();
147 for ( ::dbaccess::ODsnTypeCollection::TypeIterator aTypeLoop = m_pCollection->begin();
148 aTypeLoop != aEnd;
149 ++aTypeLoop
152 const OUString& sURLPrefix = aTypeLoop.getURLPrefix();
153 if ( !sURLPrefix.isEmpty() )
155 OUString sDisplayName = aTypeLoop.getDisplayName();
156 if (m_xEmbeddedDBType->find_text(sDisplayName) == -1 &&
157 dbaccess::ODsnTypeCollection::isEmbeddedDatabase(sURLPrefix))
159 #if !HAVE_FEATURE_MACOSX_SANDBOX
160 if( !officecfg::Office::Common::Misc::ExperimentalMode::get()
161 && sURLPrefix.startsWith("sdbc:embedded:firebird") )
162 continue;
163 #endif
164 aDisplayedTypes.emplace_back( sURLPrefix, sDisplayName );
165 m_bIsDisplayedTypesEmpty = false;
169 std::sort( aDisplayedTypes.begin(), aDisplayedTypes.end(), DisplayedTypeLess() );
170 for (auto const& displayedType : aDisplayedTypes)
171 insertEmbeddedDBTypeEntryData( displayedType.eType, displayedType.sDisplayName );
174 void OGeneralPage::setParentTitle(const OUString&)
178 void OGeneralPage::switchMessage(std::u16string_view _sURLPrefix)
180 SPECIAL_MESSAGE eMessage = smNone;
181 if ( _sURLPrefix.empty()/*_eType == m_eNotSupportedKnownType*/ )
183 eMessage = smUnsupportedType;
186 if ( eMessage != m_eLastMessage )
188 TranslateId pResId;
189 if ( smUnsupportedType == eMessage )
190 pResId = STR_UNSUPPORTED_DATASOURCE_TYPE;
191 OUString sMessage;
192 if ( pResId )
193 sMessage = DBA_RES(pResId);
195 m_xSpecialMessage->set_label( sMessage );
196 m_eLastMessage = eMessage;
200 void OGeneralPage::onTypeSelected(const OUString& _sURLPrefix)
202 // the new URL text as indicated by the selection history
203 implSetCurrentType( _sURLPrefix );
205 switchMessage(_sURLPrefix);
207 m_aTypeSelectHandler.Call(*this);
210 void OGeneralPage::implInitControls( const SfxItemSet& _rSet, bool _bSaveValue )
212 initializeTypeList();
214 m_xDatasourceType->set_active_text(getDatasourceName(_rSet));
216 // notify our listener that our type selection has changed (if so)
217 // FIXME: how to detect that it did not changed? (fdo#62937)
218 setParentTitle( m_eCurrentSelection );
219 onTypeSelected( m_eCurrentSelection );
221 // a special message for the current page state
222 switchMessage( m_eCurrentSelection );
224 OGenericAdministrationPage::implInitControls( _rSet, _bSaveValue );
227 OUString OGeneralPageWizard::getEmbeddedDBName( const SfxItemSet& _rSet )
229 // first check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa)
230 bool bValid, bReadonly;
231 getFlags( _rSet, bValid, bReadonly );
233 // if the selection is invalid, disable everything
235 implSetCurrentType( OUString() );
237 // compare the DSN prefix with the registered ones
238 OUString sDisplayName;
240 if (m_pCollection && bValid)
242 implSetCurrentType( dbaccess::ODsnTypeCollection::getEmbeddedDatabase() );
243 sDisplayName = m_pCollection->getTypeDisplayName( m_eCurrentSelection );
244 onTypeSelected(m_eCurrentSelection);
247 // select the correct datasource type
248 if ( dbaccess::ODsnTypeCollection::isEmbeddedDatabase( m_eCurrentSelection )
249 && m_xEmbeddedDBType->find_text(sDisplayName) == -1 )
250 { // this indicates it's really a type which is known in general, but not supported on the current platform
251 // show a message saying so
252 // eSpecialMessage = smUnsupportedType;
253 insertEmbeddedDBTypeEntryData( m_eCurrentSelection, sDisplayName );
256 return sDisplayName;
259 OUString OGeneralPage::getDatasourceName( const SfxItemSet& _rSet )
261 // first check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa)
262 bool bValid, bReadonly;
263 getFlags( _rSet, bValid, bReadonly );
265 // if the selection is invalid, disable everything
266 OUString sConnectURL;
267 if ( bValid )
269 // collect some items and some values
270 const SfxStringItem* pUrlItem = _rSet.GetItem<SfxStringItem>(DSID_CONNECTURL);
271 assert( pUrlItem );
272 sConnectURL = pUrlItem->GetValue();
275 implSetCurrentType( OUString() );
277 // compare the DSN prefix with the registered ones
278 OUString sDisplayName;
280 if (m_pCollection && bValid)
282 implSetCurrentType( m_pCollection->getPrefix( sConnectURL ) );
283 sDisplayName = m_pCollection->getTypeDisplayName( m_eCurrentSelection );
286 // select the correct datasource type
287 if ( approveDatasourceType( m_eCurrentSelection, sDisplayName )
288 && m_xDatasourceType->find_text(sDisplayName) == -1 )
289 { // this indicates it's really a type which is known in general, but not supported on the current platform
290 // show a message saying so
291 // eSpecialMessage = smUnsupportedType;
292 insertDatasourceTypeEntryData( m_eCurrentSelection, sDisplayName );
295 return sDisplayName;
298 // For the databaseWizard we only have one entry for the MySQL Database,
299 // because we have a separate tabpage to retrieve the respective datasource type
300 // ( ::dbaccess::DST_MYSQL_ODBC || ::dbaccess::DST_MYSQL_JDBC). Therefore we use ::dbaccess::DST_MYSQL_JDBC as a temporary
301 // representative for all MySQl databases)
302 // Also, embedded databases (embedded HSQL, at the moment), are not to appear in the list of
303 // databases to connect to.
304 bool OGeneralPage::approveDatasourceType( std::u16string_view _sURLPrefix, OUString& _inout_rDisplayName )
306 return approveDatasourceType( m_pCollection->determineType(_sURLPrefix), _inout_rDisplayName );
309 bool OGeneralPage::approveDatasourceType( ::dbaccess::DATASOURCE_TYPE eType, OUString& _inout_rDisplayName )
311 if ( eType == ::dbaccess::DST_MYSQL_NATIVE_DIRECT )
313 // do not display the Connector/OOo driver itself, it is always wrapped via the MySQL-Driver, if
314 // this driver is installed
315 if ( m_pCollection->hasDriver( "sdbc:mysql:mysqlc:" ) )
316 _inout_rDisplayName.clear();
319 if ( eType == ::dbaccess::DST_EMBEDDED_HSQLDB
320 || eType == ::dbaccess::DST_EMBEDDED_FIREBIRD )
321 _inout_rDisplayName.clear();
323 return _inout_rDisplayName.getLength() > 0;
326 void OGeneralPage::insertDatasourceTypeEntryData(const OUString& _sType, const OUString& sDisplayName)
328 // insert a (temporary) entry
329 m_xDatasourceType->append_text(sDisplayName);
330 m_aURLPrefixes.push_back(_sType);
333 void OGeneralPageWizard::insertEmbeddedDBTypeEntryData(const OUString& _sType, const OUString& sDisplayName)
335 // insert a (temporary) entry
336 m_xEmbeddedDBType->append_text(sDisplayName);
337 m_aEmbeddedURLPrefixes.push_back(_sType);
340 void OGeneralPage::fillWindows(std::vector< std::unique_ptr<ISaveValueWrapper> >& _rControlList)
342 _rControlList.emplace_back(new ODisableWidgetWrapper<weld::Label>(m_xSpecialMessage.get()));
345 void OGeneralPage::fillControls(std::vector< std::unique_ptr<ISaveValueWrapper> >& _rControlList)
347 _rControlList.emplace_back(new OSaveValueWidgetWrapper<weld::ComboBox>(m_xDatasourceType.get()));
350 void OGeneralPage::implSetCurrentType( const OUString& _eType )
352 if ( _eType == m_eCurrentSelection )
353 return;
355 m_eCurrentSelection = _eType;
358 void OGeneralPage::Reset(const SfxItemSet* _rCoreAttrs)
360 // reset all locale data
361 implSetCurrentType( OUString() );
362 // this ensures that our type selection link will be called, even if the new one is the same as the
363 // current one
364 OGenericAdministrationPage::Reset(_rCoreAttrs);
367 IMPL_LINK( OGeneralPageWizard, OnEmbeddedDBTypeSelected, weld::ComboBox&, _rBox, void )
369 // get the type from the entry data
370 const sal_Int32 nSelected = _rBox.get_active();
371 if (o3tl::make_unsigned(nSelected) >= m_aEmbeddedURLPrefixes.size() )
373 SAL_WARN("dbaccess.ui.generalpage", "Got out-of-range value '" << nSelected << "' from the DatasourceType selection ListBox's GetSelectedEntryPos(): no corresponding URL prefix");
374 return;
376 const OUString sURLPrefix = m_aEmbeddedURLPrefixes[ nSelected ];
378 setParentTitle( sURLPrefix );
379 // let the impl method do all the stuff
380 onTypeSelected( sURLPrefix );
381 // tell the listener we were modified
382 callModifiedHdl();
385 IMPL_LINK( OGeneralPage, OnDatasourceTypeSelected, weld::ComboBox&, _rBox, void )
387 // get the type from the entry data
388 const sal_Int32 nSelected = _rBox.get_active();
389 if (nSelected == -1)
390 return;
391 if (o3tl::make_unsigned(nSelected) >= m_aURLPrefixes.size() )
393 SAL_WARN("dbaccess.ui.generalpage", "Got out-of-range value '" << nSelected << "' from the DatasourceType selection ListBox's GetSelectedEntryPos(): no corresponding URL prefix");
394 return;
396 const OUString sURLPrefix = m_aURLPrefixes[ nSelected ];
398 setParentTitle( sURLPrefix );
399 // let the impl method do all the stuff
400 onTypeSelected( sURLPrefix );
401 // tell the listener we were modified
402 callModifiedHdl();
405 // OGeneralPageDialog
406 OGeneralPageDialog::OGeneralPageDialog(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& _rItems)
407 : OGeneralPage(pPage, pController, "dbaccess/ui/generalpagedialog.ui", _rItems)
411 void OGeneralPageDialog::setParentTitle( const OUString& _sURLPrefix )
413 const OUString sName = m_pCollection->getTypeDisplayName( _sURLPrefix );
414 if ( m_pAdminDialog )
416 OUString sMessage = DBA_RES(STR_PARENTTITLE_GENERAL);
417 m_pAdminDialog->setTitle( sMessage.replaceAll( "#", sName ) );
421 void OGeneralPageDialog::implInitControls( const SfxItemSet& _rSet, bool _bSaveValue )
423 OGeneralPage::implInitControls( _rSet, _bSaveValue );
425 // first check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa)
426 bool bValid, bReadonly;
427 getFlags(_rSet, bValid, bReadonly );
429 m_xDatasourceType->set_sensitive( bValid );
432 bool OGeneralPageDialog::FillItemSet( SfxItemSet* _rCoreAttrs )
434 bool bChangedSomething = false;
436 const sal_Int32 nEntry = m_xDatasourceType->get_active();
437 OUString sURLPrefix = m_aURLPrefixes[ nEntry ];
439 if (m_xDatasourceType->get_value_changed_from_saved())
441 _rCoreAttrs->Put( SfxStringItem( DSID_CONNECTURL, sURLPrefix ) );
442 bChangedSomething = true;
445 return bChangedSomething;
448 // OGeneralPageWizard
449 OGeneralPageWizard::OGeneralPageWizard(weld::Container* pPage, ODbTypeWizDialogSetup* pController, const SfxItemSet& _rItems)
450 : OGeneralPage( pPage, pController, "dbaccess/ui/generalpagewizard.ui", _rItems )
451 , m_xRB_CreateDatabase(m_xBuilder->weld_radio_button("createDatabase"))
452 , m_xRB_OpenExistingDatabase(m_xBuilder->weld_radio_button("openExistingDatabase"))
453 , m_xRB_ConnectDatabase(m_xBuilder->weld_radio_button("connectDatabase"))
454 , m_xFT_EmbeddedDBLabel(m_xBuilder->weld_label("embeddeddbLabel"))
455 , m_xEmbeddedDBType(m_xBuilder->weld_combo_box("embeddeddbList"))
456 , m_xFT_DocListLabel(m_xBuilder->weld_label("docListLabel"))
457 , m_xLB_DocumentList(new OpenDocumentListBox(m_xBuilder->weld_combo_box("documentList"), "com.sun.star.sdb.OfficeDatabaseDocument"))
458 , m_xPB_OpenDatabase(new OpenDocumentButton(m_xBuilder->weld_button("openDatabase"), "com.sun.star.sdb.OfficeDatabaseDocument"))
459 , m_xFT_NoEmbeddedDBLabel(m_xBuilder->weld_label("noembeddeddbLabel"))
460 , m_eOriginalCreationMode(eCreateNew)
461 , m_bInitEmbeddedDBList(true)
462 , m_bIsDisplayedTypesEmpty(true)
464 // If no driver for embedded DBs is installed, and no dBase driver, then hide the "Create new database" option
465 sal_Int32 nCreateNewDBIndex = m_pCollection->getIndexOf( dbaccess::ODsnTypeCollection::getEmbeddedDatabase() );
466 if ( nCreateNewDBIndex == -1 )
467 nCreateNewDBIndex = m_pCollection->getIndexOf( u"sdbc:dbase:" );
468 bool bHideCreateNew = ( nCreateNewDBIndex == -1 );
470 // also, if our application policies tell us to hide the option, do it
471 ::utl::OConfigurationTreeRoot aConfig( ::utl::OConfigurationTreeRoot::createWithComponentContext(
472 ::comphelper::getProcessComponentContext(),
473 "/org.openoffice.Office.DataAccess/Policies/Features/Base"
474 ) );
475 bool bAllowCreateLocalDatabase( true );
476 OSL_VERIFY( aConfig.getNodeValue( "CreateLocalDatabase" ) >>= bAllowCreateLocalDatabase );
477 if ( !bAllowCreateLocalDatabase )
478 bHideCreateNew = true;
480 if ( bHideCreateNew )
482 m_xRB_CreateDatabase->hide();
483 m_xRB_ConnectDatabase->set_active(true);
485 else
486 m_xRB_CreateDatabase->set_active(true);
488 // do some knittings
489 m_xEmbeddedDBType->connect_changed(LINK(this, OGeneralPageWizard, OnEmbeddedDBTypeSelected));
490 m_xRB_CreateDatabase->connect_toggled( LINK( this, OGeneralPageWizard, OnSetupModeSelected ) );
491 m_xRB_ConnectDatabase->connect_toggled( LINK( this, OGeneralPageWizard, OnSetupModeSelected ) );
492 m_xRB_OpenExistingDatabase->connect_toggled( LINK( this, OGeneralPageWizard, OnSetupModeSelected ) );
493 m_xLB_DocumentList->connect_changed( LINK( this, OGeneralPageWizard, OnDocumentSelected ) );
494 m_xPB_OpenDatabase->connect_clicked( LINK( this, OGeneralPageWizard, OnOpenDocument ) );
495 m_xFT_NoEmbeddedDBLabel->hide();
497 pController->SetGeneralPage(this);
500 OGeneralPageWizard::~OGeneralPageWizard()
504 OGeneralPageWizard::CreationMode OGeneralPageWizard::GetDatabaseCreationMode() const
506 if ( m_xRB_CreateDatabase->get_active() )
507 return eCreateNew;
508 if ( m_xRB_ConnectDatabase->get_active() )
509 return eConnectExternal;
510 return eOpenExisting;
513 void OGeneralPageWizard::implInitControls( const SfxItemSet& _rSet, bool _bSaveValue )
515 OGeneralPage::implInitControls( _rSet, _bSaveValue );
517 initializeEmbeddedDBList();
518 m_xEmbeddedDBType->set_active_text(getEmbeddedDBName(_rSet));
520 if(m_bIsDisplayedTypesEmpty)
522 m_xRB_CreateDatabase->set_sensitive(false);
523 m_xFT_EmbeddedDBLabel->hide();
524 m_xEmbeddedDBType->hide();
525 m_xFT_NoEmbeddedDBLabel->show();
526 m_xRB_OpenExistingDatabase->set_active(true);
529 // first check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa)
530 bool bValid, bReadonly;
531 getFlags( _rSet, bValid, bReadonly );
533 SetPageTitle(OUString());
535 if ( !bValid || bReadonly )
537 m_xFT_EmbeddedDBLabel->set_sensitive( false );
538 m_xDatasourceType->set_sensitive( false );
539 m_xPB_OpenDatabase->set_sensitive( false );
540 m_xFT_DocListLabel->set_sensitive( false );
541 m_xLB_DocumentList->set_sensitive( false );
544 if (m_xLB_DocumentList->get_count())
545 m_xLB_DocumentList->set_active(0);
547 m_eOriginalCreationMode = GetDatabaseCreationMode();
549 SetupModeSelected();
552 OUString OGeneralPageWizard::getDatasourceName(const SfxItemSet& _rSet)
554 // Sets the default selected database on startup.
555 if (m_xRB_CreateDatabase->get_active() )
557 return m_pCollection->getTypeDisplayName( u"sdbc:firebird:" );
560 return OGeneralPage::getDatasourceName( _rSet );
563 bool OGeneralPageWizard::approveDatasourceType( ::dbaccess::DATASOURCE_TYPE eType, OUString& _inout_rDisplayName )
565 switch ( eType )
567 case ::dbaccess::DST_MYSQL_JDBC:
568 case ::dbaccess::DST_MYSQL_ODBC:
569 case ::dbaccess::DST_MYSQL_NATIVE:
570 _inout_rDisplayName = "MySQL/MariaDB";
571 break;
572 default:
573 break;
576 return OGeneralPage::approveDatasourceType( eType, _inout_rDisplayName );
579 bool OGeneralPageWizard::FillItemSet(SfxItemSet* _rCoreAttrs)
581 bool bChangedSomething = false;
583 bool bCommitTypeSelection = true;
585 if ( m_xRB_CreateDatabase->get_active() )
587 _rCoreAttrs->Put( SfxStringItem( DSID_CONNECTURL, "sdbc:dbase:" ) );
588 bChangedSomething = true;
589 bCommitTypeSelection = false;
591 else if ( m_xRB_OpenExistingDatabase->get_active() )
593 if ( m_xRB_OpenExistingDatabase->get_state_changed_from_saved() )
594 bChangedSomething = true;
596 // TODO
597 bCommitTypeSelection = false;
600 if ( bCommitTypeSelection )
602 const sal_Int32 nEntry = m_xDatasourceType->get_active();
603 OUString sURLPrefix = m_aURLPrefixes[nEntry];
605 if ( m_xDatasourceType->get_value_changed_from_saved()
606 || ( GetDatabaseCreationMode() != m_eOriginalCreationMode )
609 _rCoreAttrs->Put( SfxStringItem( DSID_CONNECTURL,sURLPrefix ) );
610 bChangedSomething = true;
612 else
613 implSetCurrentType( sURLPrefix );
615 return bChangedSomething;
618 OUString OGeneralPageWizard::GetSelectedDocumentURL() const
620 if ( !m_aBrowsedDocumentURL.isEmpty() )
621 return m_aBrowsedDocumentURL;
622 else
623 return m_xLB_DocumentList->GetSelectedDocumentURL();
626 void OGeneralPageWizard::EnableControls()
628 bool bValid, bReadonly;
629 getFlags( GetItemSet(), bValid, bReadonly );
630 if ( bValid && !bReadonly )
632 m_xEmbeddedDBType->set_sensitive(m_xRB_CreateDatabase->get_active());
633 m_xFT_EmbeddedDBLabel->set_sensitive(m_xRB_CreateDatabase->get_active());
634 m_xDatasourceType->set_sensitive(m_xRB_ConnectDatabase->get_active());
635 m_xPB_OpenDatabase->set_sensitive(m_xRB_OpenExistingDatabase->get_active());
636 m_xFT_DocListLabel->set_sensitive(m_xRB_OpenExistingDatabase->get_active());
637 m_xLB_DocumentList->set_sensitive(m_xRB_OpenExistingDatabase->get_active());
641 void OGeneralPageWizard::SetupModeSelected()
643 m_aCreationModeHandler.Call( *this );
645 if (m_xRB_CreateDatabase->get_active())
646 OnEmbeddedDBTypeSelected(*m_xEmbeddedDBType);
647 else
648 OnDatasourceTypeSelected(*m_xDatasourceType);
650 EnableControls();
653 IMPL_LINK(OGeneralPageWizard, OnSetupModeSelected, weld::Toggleable&, rButton, void)
655 if (!rButton.get_active())
656 return;
657 SetupModeSelected();
660 IMPL_LINK_NOARG( OGeneralPageWizard, OnDocumentSelected, weld::ComboBox&, void )
662 m_aDocumentSelectionHandler.Call( *this );
665 IMPL_LINK_NOARG( OGeneralPageWizard, OnOpenDocument, weld::Button&, void )
667 ::sfx2::FileDialogHelper aFileDlg(
668 ui::dialogs::TemplateDescription::FILEOPEN_READONLY_VERSION,
669 FileDialogFlags::NONE, "sdatabase", SfxFilterFlags::NONE, SfxFilterFlags::NONE, GetFrameWeld());
670 aFileDlg.SetContext(sfx2::FileDialogHelper::BaseDataSource);
671 std::shared_ptr<const SfxFilter> pFilter = getStandardDatabaseFilter();
672 if ( pFilter )
674 aFileDlg.SetCurrentFilter(pFilter->GetUIName());
676 if ( aFileDlg.Execute() != ERRCODE_NONE )
677 return;
679 OUString sPath = aFileDlg.GetPath();
680 // check for aFileDlg.GetCurrentFilter used to be here but current fpicker filter
681 // can be set to anything, see tdf#125267 how this breaks if other value
682 // than 'ODF Database' is selected. Let's therefore check only if wildcard matches
683 if (pFilter && !pFilter->GetWildcard().Matches(sPath))
685 OUString sMessage(DBA_RES(STR_ERR_USE_CONNECT_TO));
686 std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(GetFrameWeld(),
687 VclMessageType::Info, VclButtonsType::Ok,
688 sMessage));
689 xInfoBox->run();
690 m_xRB_ConnectDatabase->set_active(true);
691 OnSetupModeSelected( *m_xRB_ConnectDatabase );
692 return;
694 m_aBrowsedDocumentURL = sPath;
695 m_aChooseDocumentHandler.Call( *this );
698 } // namespace dbaui
700 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */