Gtk-WARNING gtktreestore.c:1047: Invalid column number 1 added to iter
[LibreOffice.git] / dbaccess / source / ui / dlg / generalpage.cxx
blob2030860d1ac66776430bee37bd8f94dc60fbc277
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, u"PageGeneral"_ustr, _rItems)
54 , m_xSpecialMessage(m_xBuilder->weld_label(u"specialMessage"_ustr))
55 , m_eLastMessage(smNone)
56 , m_bInitTypeList(true)
57 , m_xDatasourceType(m_xBuilder->weld_combo_box(u"datasourceType"_ustr))
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 if (!m_pCollection)
230 return {};
231 // first check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa)
232 bool bValid, bReadonly;
233 getFlags( _rSet, bValid, bReadonly );
234 if (!bValid)
235 return {};
237 // compare the DSN prefix with the registered ones
238 OUString sDBURL;
239 if (const SfxStringItem* pUrlItem = _rSet.GetItem<SfxStringItem>(DSID_CONNECTURL))
240 if (dbaccess::ODsnTypeCollection::isEmbeddedDatabase(pUrlItem->GetValue()))
241 sDBURL = pUrlItem->GetValue();
242 if (sDBURL.isEmpty())
243 sDBURL = dbaccess::ODsnTypeCollection::getEmbeddedDatabase();
244 OUString sDisplayName = m_pCollection->getTypeDisplayName(sDBURL);
246 // ensure presence of the correct datasource type
247 if (!sDisplayName.isEmpty() && m_xEmbeddedDBType->find_text(sDisplayName) == -1)
248 { // this indicates it's really a type which is known in general, but not supported on the current platform
249 // show a message saying so
250 // eSpecialMessage = smUnsupportedType;
251 insertEmbeddedDBTypeEntryData(sDBURL, sDisplayName);
254 return sDisplayName;
257 OUString OGeneralPage::getDatasourceName( const SfxItemSet& _rSet )
259 // first check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa)
260 bool bValid, bReadonly;
261 getFlags( _rSet, bValid, bReadonly );
263 // if the selection is invalid, disable everything
264 OUString sConnectURL;
265 if ( bValid )
267 // collect some items and some values
268 const SfxStringItem* pUrlItem = _rSet.GetItem<SfxStringItem>(DSID_CONNECTURL);
269 assert( pUrlItem );
270 sConnectURL = pUrlItem->GetValue();
273 implSetCurrentType( OUString() );
275 // compare the DSN prefix with the registered ones
276 OUString sDisplayName;
278 if (m_pCollection && bValid)
280 implSetCurrentType( m_pCollection->getPrefix( sConnectURL ) );
281 sDisplayName = m_pCollection->getTypeDisplayName( m_eCurrentSelection );
284 // select the correct datasource type
285 if ( approveDatasourceType( m_eCurrentSelection, sDisplayName )
286 && m_xDatasourceType->find_text(sDisplayName) == -1 )
287 { // this indicates it's really a type which is known in general, but not supported on the current platform
288 // show a message saying so
289 // eSpecialMessage = smUnsupportedType;
290 insertDatasourceTypeEntryData( m_eCurrentSelection, sDisplayName );
293 return sDisplayName;
296 // For the databaseWizard we only have one entry for the MySQL Database,
297 // because we have a separate tabpage to retrieve the respective datasource type
298 // ( ::dbaccess::DST_MYSQL_ODBC || ::dbaccess::DST_MYSQL_JDBC). Therefore we use ::dbaccess::DST_MYSQL_JDBC as a temporary
299 // representative for all MySQl databases)
300 // Also, embedded databases (embedded HSQL, at the moment), are not to appear in the list of
301 // databases to connect to.
302 bool OGeneralPage::approveDatasourceType( std::u16string_view _sURLPrefix, OUString& _inout_rDisplayName )
304 return approveDatasourceType( m_pCollection->determineType(_sURLPrefix), _inout_rDisplayName );
307 bool OGeneralPage::approveDatasourceType( ::dbaccess::DATASOURCE_TYPE eType, OUString& _inout_rDisplayName )
309 if ( eType == ::dbaccess::DST_MYSQL_NATIVE_DIRECT )
311 // do not display the Connector/OOo driver itself, it is always wrapped via the MySQL-Driver, if
312 // this driver is installed
313 if ( m_pCollection->hasDriver( u"sdbc:mysql:mysqlc:" ) )
314 _inout_rDisplayName.clear();
317 if ( eType == ::dbaccess::DST_EMBEDDED_HSQLDB
318 || eType == ::dbaccess::DST_EMBEDDED_FIREBIRD )
319 _inout_rDisplayName.clear();
321 return _inout_rDisplayName.getLength() > 0;
324 void OGeneralPage::insertDatasourceTypeEntryData(const OUString& _sType, const OUString& sDisplayName)
326 // insert a (temporary) entry
327 m_xDatasourceType->append_text(sDisplayName);
328 m_aURLPrefixes.push_back(_sType);
331 void OGeneralPageWizard::insertEmbeddedDBTypeEntryData(const OUString& _sType, const OUString& sDisplayName)
333 // insert a (temporary) entry
334 m_xEmbeddedDBType->append_text(sDisplayName);
335 m_aEmbeddedURLPrefixes.push_back(_sType);
338 void OGeneralPage::fillWindows(std::vector< std::unique_ptr<ISaveValueWrapper> >& _rControlList)
340 _rControlList.emplace_back(new ODisableWidgetWrapper<weld::Label>(m_xSpecialMessage.get()));
343 void OGeneralPage::fillControls(std::vector< std::unique_ptr<ISaveValueWrapper> >& _rControlList)
345 _rControlList.emplace_back(new OSaveValueWidgetWrapper<weld::ComboBox>(m_xDatasourceType.get()));
348 void OGeneralPage::implSetCurrentType( const OUString& _eType )
350 if ( _eType == m_eCurrentSelection )
351 return;
353 m_eCurrentSelection = _eType;
356 void OGeneralPage::Reset(const SfxItemSet* _rCoreAttrs)
358 // reset all locale data
359 implSetCurrentType( OUString() );
360 // this ensures that our type selection link will be called, even if the new one is the same as the
361 // current one
362 OGenericAdministrationPage::Reset(_rCoreAttrs);
365 IMPL_LINK( OGeneralPageWizard, OnEmbeddedDBTypeSelected, weld::ComboBox&, _rBox, void )
367 // get the type from the entry data
368 const sal_Int32 nSelected = _rBox.get_active();
369 if (o3tl::make_unsigned(nSelected) >= m_aEmbeddedURLPrefixes.size() )
371 SAL_WARN("dbaccess.ui.generalpage", "Got out-of-range value '" << nSelected << "' from the DatasourceType selection ListBox's GetSelectedEntryPos(): no corresponding URL prefix");
372 return;
374 const OUString sURLPrefix = m_aEmbeddedURLPrefixes[ nSelected ];
376 setParentTitle( sURLPrefix );
377 // let the impl method do all the stuff
378 onTypeSelected( sURLPrefix );
379 // tell the listener we were modified
380 callModifiedHdl();
383 IMPL_LINK( OGeneralPage, OnDatasourceTypeSelected, weld::ComboBox&, _rBox, void )
385 // get the type from the entry data
386 const sal_Int32 nSelected = _rBox.get_active();
387 if (nSelected == -1)
388 return;
389 if (o3tl::make_unsigned(nSelected) >= m_aURLPrefixes.size() )
391 SAL_WARN("dbaccess.ui.generalpage", "Got out-of-range value '" << nSelected << "' from the DatasourceType selection ListBox's GetSelectedEntryPos(): no corresponding URL prefix");
392 return;
394 const OUString sURLPrefix = m_aURLPrefixes[ nSelected ];
396 setParentTitle( sURLPrefix );
397 // let the impl method do all the stuff
398 onTypeSelected( sURLPrefix );
399 // tell the listener we were modified
400 callModifiedHdl();
403 // OGeneralPageDialog
404 OGeneralPageDialog::OGeneralPageDialog(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& _rItems)
405 : OGeneralPage(pPage, pController, u"dbaccess/ui/generalpagedialog.ui"_ustr, _rItems)
409 void OGeneralPageDialog::setParentTitle( const OUString& _sURLPrefix )
411 const OUString sName = m_pCollection->getTypeDisplayName( _sURLPrefix );
412 if ( m_pAdminDialog )
414 OUString sMessage = DBA_RES(STR_PARENTTITLE_GENERAL);
415 m_pAdminDialog->setTitle( sMessage.replaceAll( "#", sName ) );
419 void OGeneralPageDialog::implInitControls( const SfxItemSet& _rSet, bool _bSaveValue )
421 OGeneralPage::implInitControls( _rSet, _bSaveValue );
423 // first check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa)
424 bool bValid, bReadonly;
425 getFlags(_rSet, bValid, bReadonly );
427 m_xDatasourceType->set_sensitive( bValid );
430 bool OGeneralPageDialog::FillItemSet( SfxItemSet* _rCoreAttrs )
432 bool bChangedSomething = false;
434 const sal_Int32 nEntry = m_xDatasourceType->get_active();
435 OUString sURLPrefix = m_aURLPrefixes[ nEntry ];
437 if (m_xDatasourceType->get_value_changed_from_saved())
439 _rCoreAttrs->Put( SfxStringItem( DSID_CONNECTURL, sURLPrefix ) );
440 bChangedSomething = true;
443 return bChangedSomething;
446 // OGeneralPageWizard
447 OGeneralPageWizard::OGeneralPageWizard(weld::Container* pPage, ODbTypeWizDialogSetup* pController, const SfxItemSet& _rItems)
448 : OGeneralPage( pPage, pController, u"dbaccess/ui/generalpagewizard.ui"_ustr, _rItems )
449 , m_xRB_CreateDatabase(m_xBuilder->weld_radio_button(u"createDatabase"_ustr))
450 , m_xRB_OpenExistingDatabase(m_xBuilder->weld_radio_button(u"openExistingDatabase"_ustr))
451 , m_xRB_ConnectDatabase(m_xBuilder->weld_radio_button(u"connectDatabase"_ustr))
452 , m_xFT_EmbeddedDBLabel(m_xBuilder->weld_label(u"embeddeddbLabel"_ustr))
453 , m_xEmbeddedDBType(m_xBuilder->weld_combo_box(u"embeddeddbList"_ustr))
454 , m_xFT_DocListLabel(m_xBuilder->weld_label(u"docListLabel"_ustr))
455 , m_xLB_DocumentList(new OpenDocumentListBox(m_xBuilder->weld_combo_box(u"documentList"_ustr), "com.sun.star.sdb.OfficeDatabaseDocument"))
456 , m_xPB_OpenDatabase(new OpenDocumentButton(m_xBuilder->weld_button(u"openDatabase"_ustr), u"com.sun.star.sdb.OfficeDatabaseDocument"_ustr))
457 , m_xFT_NoEmbeddedDBLabel(m_xBuilder->weld_label(u"noembeddeddbLabel"_ustr))
458 , m_eOriginalCreationMode(eCreateNew)
459 , m_bInitEmbeddedDBList(true)
460 , m_bIsDisplayedTypesEmpty(true)
462 // If no driver for embedded DBs is installed, and no dBase driver, then hide the "Create new database" option
463 sal_Int32 nCreateNewDBIndex = m_pCollection->getIndexOf( dbaccess::ODsnTypeCollection::getEmbeddedDatabase() );
464 if ( nCreateNewDBIndex == -1 )
465 nCreateNewDBIndex = m_pCollection->getIndexOf( u"sdbc:dbase:" );
466 bool bHideCreateNew = ( nCreateNewDBIndex == -1 );
468 // also, if our application policies tell us to hide the option, do it
469 ::utl::OConfigurationTreeRoot aConfig( ::utl::OConfigurationTreeRoot::createWithComponentContext(
470 ::comphelper::getProcessComponentContext(),
471 u"/org.openoffice.Office.DataAccess/Policies/Features/Base"_ustr
472 ) );
473 bool bAllowCreateLocalDatabase( true );
474 OSL_VERIFY( aConfig.getNodeValue( u"CreateLocalDatabase"_ustr ) >>= bAllowCreateLocalDatabase );
475 if ( !bAllowCreateLocalDatabase )
476 bHideCreateNew = true;
478 if ( bHideCreateNew )
480 m_xRB_CreateDatabase->hide();
481 m_xRB_ConnectDatabase->set_active(true);
483 else
484 m_xRB_CreateDatabase->set_active(true);
486 // do some knittings
487 m_xEmbeddedDBType->connect_changed(LINK(this, OGeneralPageWizard, OnEmbeddedDBTypeSelected));
488 m_xRB_CreateDatabase->connect_toggled( LINK( this, OGeneralPageWizard, OnSetupModeSelected ) );
489 m_xRB_ConnectDatabase->connect_toggled( LINK( this, OGeneralPageWizard, OnSetupModeSelected ) );
490 m_xRB_OpenExistingDatabase->connect_toggled( LINK( this, OGeneralPageWizard, OnSetupModeSelected ) );
491 m_xLB_DocumentList->connect_changed( LINK( this, OGeneralPageWizard, OnDocumentSelected ) );
492 m_xPB_OpenDatabase->connect_clicked( LINK( this, OGeneralPageWizard, OnOpenDocument ) );
493 m_xFT_NoEmbeddedDBLabel->hide();
495 pController->SetGeneralPage(this);
498 OGeneralPageWizard::~OGeneralPageWizard()
502 OGeneralPageWizard::CreationMode OGeneralPageWizard::GetDatabaseCreationMode() const
504 if ( m_xRB_CreateDatabase->get_active() )
505 return eCreateNew;
506 if ( m_xRB_ConnectDatabase->get_active() )
507 return eConnectExternal;
508 return eOpenExisting;
511 void OGeneralPageWizard::implInitControls( const SfxItemSet& _rSet, bool _bSaveValue )
513 OGeneralPage::implInitControls( _rSet, _bSaveValue );
515 initializeEmbeddedDBList();
516 m_xEmbeddedDBType->set_active_text(getEmbeddedDBName(_rSet));
518 if(m_bIsDisplayedTypesEmpty)
520 m_xRB_CreateDatabase->set_sensitive(false);
521 m_xFT_EmbeddedDBLabel->hide();
522 m_xEmbeddedDBType->hide();
523 m_xFT_NoEmbeddedDBLabel->show();
524 m_xRB_OpenExistingDatabase->set_active(true);
527 // first check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa)
528 bool bValid, bReadonly;
529 getFlags( _rSet, bValid, bReadonly );
531 SetPageTitle(OUString());
533 if ( !bValid || bReadonly )
535 m_xFT_EmbeddedDBLabel->set_sensitive( false );
536 m_xDatasourceType->set_sensitive( false );
537 m_xPB_OpenDatabase->set_sensitive( false );
538 m_xFT_DocListLabel->set_sensitive( false );
539 m_xLB_DocumentList->set_sensitive( false );
542 if (m_xLB_DocumentList->get_count())
543 m_xLB_DocumentList->set_active(0);
545 m_eOriginalCreationMode = GetDatabaseCreationMode();
547 SetupModeSelected();
550 OUString OGeneralPageWizard::getDatasourceName(const SfxItemSet& _rSet)
552 // Sets the default selected database on startup.
553 if (m_xRB_CreateDatabase->get_active() )
555 return m_pCollection->getTypeDisplayName( u"sdbc:firebird:" );
558 return OGeneralPage::getDatasourceName( _rSet );
561 bool OGeneralPageWizard::approveDatasourceType( ::dbaccess::DATASOURCE_TYPE eType, OUString& _inout_rDisplayName )
563 switch ( eType )
565 case ::dbaccess::DST_MYSQL_JDBC:
566 case ::dbaccess::DST_MYSQL_ODBC:
567 case ::dbaccess::DST_MYSQL_NATIVE:
568 _inout_rDisplayName = "MySQL/MariaDB";
569 break;
570 default:
571 break;
574 return OGeneralPage::approveDatasourceType( eType, _inout_rDisplayName );
577 bool OGeneralPageWizard::FillItemSet(SfxItemSet* _rCoreAttrs)
579 bool bChangedSomething = false;
581 bool bCommitTypeSelection = true;
583 if ( m_xRB_CreateDatabase->get_active() )
585 _rCoreAttrs->Put( SfxStringItem( DSID_CONNECTURL, u"sdbc:dbase:"_ustr ) );
586 bChangedSomething = true;
587 bCommitTypeSelection = false;
589 else if ( m_xRB_OpenExistingDatabase->get_active() )
591 if ( m_xRB_OpenExistingDatabase->get_state_changed_from_saved() )
592 bChangedSomething = true;
594 // TODO
595 bCommitTypeSelection = false;
598 if ( bCommitTypeSelection )
600 const sal_Int32 nEntry = m_xDatasourceType->get_active();
601 OUString sURLPrefix = m_aURLPrefixes[nEntry];
603 if ( m_xDatasourceType->get_value_changed_from_saved()
604 || ( GetDatabaseCreationMode() != m_eOriginalCreationMode )
607 _rCoreAttrs->Put( SfxStringItem( DSID_CONNECTURL,sURLPrefix ) );
608 bChangedSomething = true;
610 else
611 implSetCurrentType( sURLPrefix );
613 return bChangedSomething;
616 OUString OGeneralPageWizard::GetSelectedDocumentURL() const
618 if ( !m_aBrowsedDocumentURL.isEmpty() )
619 return m_aBrowsedDocumentURL;
620 else
621 return m_xLB_DocumentList->GetSelectedDocumentURL();
624 void OGeneralPageWizard::EnableControls()
626 bool bValid, bReadonly;
627 getFlags( GetItemSet(), bValid, bReadonly );
628 if ( bValid && !bReadonly )
630 m_xEmbeddedDBType->set_sensitive(m_xRB_CreateDatabase->get_active());
631 m_xFT_EmbeddedDBLabel->set_sensitive(m_xRB_CreateDatabase->get_active());
632 m_xDatasourceType->set_sensitive(m_xRB_ConnectDatabase->get_active());
633 m_xPB_OpenDatabase->set_sensitive(m_xRB_OpenExistingDatabase->get_active());
634 m_xFT_DocListLabel->set_sensitive(m_xRB_OpenExistingDatabase->get_active());
635 m_xLB_DocumentList->set_sensitive(m_xRB_OpenExistingDatabase->get_active());
639 void OGeneralPageWizard::SetupModeSelected()
641 m_aCreationModeHandler.Call( *this );
643 if (m_xRB_CreateDatabase->get_active())
644 OnEmbeddedDBTypeSelected(*m_xEmbeddedDBType);
645 else
646 OnDatasourceTypeSelected(*m_xDatasourceType);
648 EnableControls();
651 IMPL_LINK(OGeneralPageWizard, OnSetupModeSelected, weld::Toggleable&, rButton, void)
653 if (!rButton.get_active())
654 return;
655 SetupModeSelected();
658 IMPL_LINK_NOARG( OGeneralPageWizard, OnDocumentSelected, weld::ComboBox&, void )
660 m_aDocumentSelectionHandler.Call( *this );
663 IMPL_LINK_NOARG( OGeneralPageWizard, OnOpenDocument, weld::Button&, void )
665 ::sfx2::FileDialogHelper aFileDlg(
666 ui::dialogs::TemplateDescription::FILEOPEN_READONLY_VERSION,
667 FileDialogFlags::NONE, u"sdatabase"_ustr, SfxFilterFlags::NONE, SfxFilterFlags::NONE, GetFrameWeld());
668 aFileDlg.SetContext(sfx2::FileDialogHelper::BaseDataSource);
669 std::shared_ptr<const SfxFilter> pFilter = getStandardDatabaseFilter();
670 if ( pFilter )
672 aFileDlg.SetCurrentFilter(pFilter->GetUIName());
674 if ( aFileDlg.Execute() != ERRCODE_NONE )
675 return;
677 OUString sPath = aFileDlg.GetPath();
678 // check for aFileDlg.GetCurrentFilter used to be here but current fpicker filter
679 // can be set to anything, see tdf#125267 how this breaks if other value
680 // than 'ODF Database' is selected. Let's therefore check only if wildcard matches
681 if (pFilter && !pFilter->GetWildcard().Matches(sPath))
683 OUString sMessage(DBA_RES(STR_ERR_USE_CONNECT_TO));
684 std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(GetFrameWeld(),
685 VclMessageType::Info, VclButtonsType::Ok,
686 sMessage));
687 xInfoBox->run();
688 m_xRB_ConnectDatabase->set_active(true);
689 OnSetupModeSelected( *m_xRB_ConnectDatabase );
690 return;
692 m_aBrowsedDocumentURL = sPath;
693 m_aChooseDocumentHandler.Call( *this );
696 } // namespace dbaui
698 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */