LCOV - code coverage report
Current view: top level - dbaccess/source/ui/dlg - generalpage.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 339 0.3 %
Date: 2014-11-03 Functions: 2 51 3.9 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #include "dsnItem.hxx"
      21             : #include "generalpage.hxx"
      22             : #include <connectivity/dbexception.hxx>
      23             : #include "dbu_dlg.hrc"
      24             : #include "dsitems.hxx"
      25             : #include "dbustrings.hrc"
      26             : #include "dbadmin.hxx"
      27             : #include <sfx2/filedlghelper.hxx>
      28             : #include <sfx2/docfilt.hxx>
      29             : #include <vcl/stdtext.hxx>
      30             : #include "localresaccess.hxx"
      31             : #include <vcl/msgbox.hxx>
      32             : #include <svl/stritem.hxx>
      33             : #include <vcl/waitobj.hxx>
      34             : #include <com/sun/star/sdbc/XDriverAccess.hpp>
      35             : #include <com/sun/star/beans/PropertyValue.hpp>
      36             : #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
      37             : #include <com/sun/star/uno/Sequence.hxx>
      38             : #include <com/sun/star/container/XNameAccess.hpp>
      39             : #include "DriverSettings.hxx"
      40             : #include "UITools.hxx"
      41             : #include <comphelper/processfactory.hxx>
      42             : #include <unotools/confignode.hxx>
      43             : #include <osl/diagnose.h>
      44             : 
      45             : namespace dbaui
      46             : {
      47             :     using namespace ::com::sun::star;
      48             :     using namespace ::com::sun::star::uno;
      49             :     using namespace ::com::sun::star::sdbc;
      50             :     using namespace ::com::sun::star::beans;
      51             :     using namespace ::com::sun::star::container;
      52             : 
      53             :     // OGeneralPage
      54           0 :     OGeneralPage::OGeneralPage( vcl::Window* pParent, const OUString& _rUIXMLDescription, const SfxItemSet& _rItems )
      55             :         :OGenericAdministrationPage( pParent, "PageGeneral", _rUIXMLDescription, _rItems )
      56             :         ,m_eNotSupportedKnownType       ( ::dbaccess::DST_UNKNOWN )
      57             :         ,m_pSpecialMessage              ( NULL )
      58             :         ,m_eLastMessage                 ( smNone )
      59             :         ,m_bDisplayingInvalid           ( false )
      60             :         ,m_bInitTypeList                ( true )
      61             :         ,m_pDatasourceType              ( NULL )
      62           0 :         ,m_pCollection                  ( NULL )
      63             :     {
      64           0 :         get( m_pDatasourceType, "datasourceType" );
      65           0 :         get( m_pSpecialMessage, "specialMessage" );
      66             : 
      67             :         // extract the datasource type collection from the item set
      68           0 :         const DbuTypeCollectionItem* pCollectionItem = PTR_CAST(DbuTypeCollectionItem, _rItems.GetItem(DSID_TYPECOLLECTION));
      69           0 :         if (pCollectionItem)
      70           0 :             m_pCollection = pCollectionItem->getCollection();
      71             :         SAL_WARN_IF(!m_pCollection, "dbaccess", "OGeneralPage::OGeneralPage : really need a DSN type collection !");
      72             : 
      73             :         // do some knittings
      74           0 :         m_pDatasourceType->SetSelectHdl(LINK(this, OGeneralPage, OnDatasourceTypeSelected));
      75           0 :     }
      76             : 
      77           0 :     OGeneralPage::~OGeneralPage()
      78             :     {
      79           0 :     }
      80             : 
      81             :     namespace
      82             :     {
      83           0 :         struct DisplayedType
      84             :         {
      85             :             OUString eType;
      86             :             OUString sDisplayName;
      87             : 
      88           0 :             DisplayedType( const OUString& _eType, const OUString& _rDisplayName ) : eType( _eType ), sDisplayName( _rDisplayName ) { }
      89             :         };
      90             :         typedef ::std::vector< DisplayedType > DisplayedTypes;
      91             : 
      92             :         struct DisplayedTypeLess : ::std::binary_function< DisplayedType, DisplayedType, bool >
      93             :         {
      94           0 :             bool operator() ( const DisplayedType& _rLHS, const DisplayedType& _rRHS )
      95             :             {
      96           0 :                 return _rLHS.eType < _rRHS.eType;
      97             :             }
      98             :         };
      99             :     }
     100             : 
     101           0 :     void OGeneralPage::initializeTypeList()
     102             :     {
     103           0 :         if ( m_bInitTypeList )
     104             :         {
     105           0 :             m_bInitTypeList = false;
     106           0 :             m_pDatasourceType->Clear();
     107             : 
     108           0 :             if ( m_pCollection )
     109             :             {
     110           0 :                 DisplayedTypes aDisplayedTypes;
     111             : 
     112           0 :                 ::dbaccess::ODsnTypeCollection::TypeIterator aEnd = m_pCollection->end();
     113           0 :                 for (   ::dbaccess::ODsnTypeCollection::TypeIterator aTypeLoop =  m_pCollection->begin();
     114             :                         aTypeLoop != aEnd;
     115             :                         ++aTypeLoop
     116             :                     )
     117             :                 {
     118           0 :                     const OUString sURLPrefix = aTypeLoop.getURLPrefix();
     119           0 :                     if ( !sURLPrefix.isEmpty() )
     120             :                     {
     121           0 :                         OUString sDisplayName = aTypeLoop.getDisplayName();
     122           0 :                         if (   m_pDatasourceType->GetEntryPos( sDisplayName ) == LISTBOX_ENTRY_NOTFOUND
     123           0 :                             && approveDatasourceType( sURLPrefix, sDisplayName ) )
     124             :                         {
     125           0 :                             aDisplayedTypes.push_back( DisplayedTypes::value_type( sURLPrefix, sDisplayName ) );
     126           0 :                         }
     127             :                     }
     128           0 :                 }
     129           0 :                 ::std::sort( aDisplayedTypes.begin(), aDisplayedTypes.end(), DisplayedTypeLess() );
     130           0 :                 DisplayedTypes::const_iterator aDisplayEnd = aDisplayedTypes.end();
     131           0 :                 for (   DisplayedTypes::const_iterator loop = aDisplayedTypes.begin();
     132             :                         loop != aDisplayEnd;
     133             :                         ++loop
     134             :                     )
     135           0 :                     insertDatasourceTypeEntryData( loop->eType, loop->sDisplayName );
     136             :             }
     137             :         }
     138           0 :     }
     139             : 
     140           0 :     void OGeneralPageWizard::initializeEmbeddedDBList()
     141             :     {
     142           0 :         if ( m_bInitEmbeddedDBList )
     143             :         {
     144           0 :             m_bInitEmbeddedDBList = false;
     145           0 :             m_pEmbeddedDBType->Clear();
     146             : 
     147           0 :             if ( m_pCollection )
     148             :             {
     149           0 :                 DisplayedTypes aDisplayedTypes;
     150             : 
     151           0 :                 ::dbaccess::ODsnTypeCollection::TypeIterator aEnd = m_pCollection->end();
     152           0 :                 for (   ::dbaccess::ODsnTypeCollection::TypeIterator aTypeLoop =  m_pCollection->begin();
     153             :                         aTypeLoop != aEnd;
     154             :                         ++aTypeLoop
     155             :                     )
     156             :                 {
     157           0 :                     const OUString sURLPrefix = aTypeLoop.getURLPrefix();
     158           0 :                     if ( !sURLPrefix.isEmpty() )
     159             :                     {
     160           0 :                         OUString sDisplayName = aTypeLoop.getDisplayName();
     161           0 :                         if ( m_pEmbeddedDBType->GetEntryPos( sDisplayName ) == LISTBOX_ENTRY_NOTFOUND
     162           0 :                             && m_pCollection->isEmbeddedDatabase( sURLPrefix ) )
     163             :                         {
     164           0 :                             aDisplayedTypes.push_back( DisplayedTypes::value_type( sURLPrefix, sDisplayName ) );
     165           0 :                         }
     166             :                     }
     167           0 :                 }
     168           0 :                 ::std::sort( aDisplayedTypes.begin(), aDisplayedTypes.end(), DisplayedTypeLess() );
     169           0 :                 DisplayedTypes::const_iterator aDisplayEnd = aDisplayedTypes.end();
     170           0 :                 for (   DisplayedTypes::const_iterator loop = aDisplayedTypes.begin();
     171             :                         loop != aDisplayEnd;
     172             :                         ++loop
     173             :                     )
     174           0 :                     insertEmbeddedDBTypeEntryData( loop->eType, loop->sDisplayName );
     175             :             }
     176             :         }
     177           0 :     }
     178             : 
     179           0 :     void OGeneralPage::setParentTitle(const OUString&)
     180             :     {
     181           0 :     }
     182             : 
     183           0 :     void OGeneralPage::switchMessage(const OUString& _sURLPrefix)
     184             :     {
     185           0 :         SPECIAL_MESSAGE eMessage = smNone;
     186           0 :         if ( _sURLPrefix.isEmpty()/*_eType == m_eNotSupportedKnownType*/ )
     187             :         {
     188           0 :             eMessage = smUnsupportedType;
     189             :         }
     190             : 
     191           0 :         if ( eMessage != m_eLastMessage )
     192             :         {
     193           0 :             sal_uInt16 nResId = 0;
     194           0 :             if ( smUnsupportedType == eMessage )
     195           0 :                 nResId = STR_UNSUPPORTED_DATASOURCE_TYPE;
     196           0 :             OUString sMessage;
     197           0 :             if ( nResId )
     198           0 :                 sMessage = ModuleRes( nResId );
     199             : 
     200           0 :             m_pSpecialMessage->SetText( sMessage );
     201           0 :             m_eLastMessage = eMessage;
     202             :         }
     203           0 :     }
     204             : 
     205           0 :     void OGeneralPage::onTypeSelected(const OUString& _sURLPrefix)
     206             :     {
     207             :         // the new URL text as indicated by the selection history
     208           0 :         implSetCurrentType( _sURLPrefix );
     209             : 
     210           0 :         switchMessage(_sURLPrefix);
     211             : 
     212           0 :         if ( m_aTypeSelectHandler.IsSet() )
     213           0 :             m_aTypeSelectHandler.Call(this);
     214           0 :     }
     215             : 
     216           0 :     void OGeneralPage::implInitControls( const SfxItemSet& _rSet, bool _bSaveValue )
     217             :     {
     218           0 :         initializeTypeList();
     219             : 
     220           0 :         m_pDatasourceType->SelectEntry( getDatasourceName( _rSet ) );
     221             : 
     222             :         // notify our listener that our type selection has changed (if so)
     223             :         // FIXME: how to detect that it did not changed? (fdo#62937)
     224           0 :         setParentTitle( m_eCurrentSelection );
     225           0 :         onTypeSelected( m_eCurrentSelection );
     226             : 
     227             :         // a special message for the current page state
     228           0 :         switchMessage( m_eCurrentSelection );
     229             : 
     230           0 :         OGenericAdministrationPage::implInitControls( _rSet, _bSaveValue );
     231           0 :     }
     232             : 
     233           0 :     OUString OGeneralPageWizard::getEmbeddedDBName( const SfxItemSet& _rSet )
     234             :     {
     235             :         // first check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa)
     236             :         bool bValid, bReadonly;
     237           0 :         getFlags( _rSet, bValid, bReadonly );
     238             : 
     239             :         // if the selection is invalid, disable everything
     240           0 :         OUString sName,sConnectURL;
     241           0 :         if ( bValid )
     242             :         {
     243             :             // collect some items and some values
     244           0 :             SFX_ITEMSET_GET( _rSet, pNameItem, SfxStringItem, DSID_NAME, true );
     245           0 :             SFX_ITEMSET_GET( _rSet, pUrlItem, SfxStringItem, DSID_CONNECTURL, true );
     246             :             assert( pUrlItem );
     247             :             assert( pNameItem );
     248           0 :             sName = pNameItem->GetValue();
     249           0 :             sConnectURL = pUrlItem->GetValue();
     250             :         }
     251             : 
     252           0 :         m_eNotSupportedKnownType =  ::dbaccess::DST_UNKNOWN;
     253           0 :         implSetCurrentType(  OUString() );
     254             : 
     255             :         // compare the DSN prefix with the registered ones
     256           0 :         OUString sDisplayName;
     257             : 
     258           0 :         if (m_pCollection && bValid)
     259             :         {
     260           0 :             implSetCurrentType( m_pCollection->getEmbeddedDatabase() );
     261           0 :             sDisplayName = m_pCollection->getTypeDisplayName( m_eCurrentSelection );
     262             :         }
     263             : 
     264             :         // select the correct datasource type
     265           0 :         if  (  m_pCollection->isEmbeddedDatabase( m_eCurrentSelection )
     266           0 :             &&  ( LISTBOX_ENTRY_NOTFOUND == m_pEmbeddedDBType->GetEntryPos( sDisplayName ) )
     267             :             )
     268             :         {   // this indicates it's really a type which is known in general, but not supported on the current platform
     269             :             // show a message saying so
     270             :             //  eSpecialMessage = smUnsupportedType;
     271           0 :             insertEmbeddedDBTypeEntryData( m_eCurrentSelection, sDisplayName );
     272             :             // remember this type so we can show the special message again if the user selects this
     273             :             // type again (without changing the data source)
     274           0 :             m_eNotSupportedKnownType = m_pCollection->determineType( m_eCurrentSelection ); // TODO:
     275             :         }
     276             : 
     277           0 :         return sDisplayName;
     278             :     }
     279             : 
     280           0 :     OUString OGeneralPage::getDatasourceName( const SfxItemSet& _rSet )
     281             :     {
     282             :         // first check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa)
     283             :         bool bValid, bReadonly;
     284           0 :         getFlags( _rSet, bValid, bReadonly );
     285             : 
     286             :         // if the selection is invalid, disable everything
     287           0 :         OUString sName,sConnectURL;
     288           0 :         m_bDisplayingInvalid = !bValid;
     289           0 :         if ( bValid )
     290             :         {
     291             :             // collect some items and some values
     292           0 :             SFX_ITEMSET_GET( _rSet, pNameItem, SfxStringItem, DSID_NAME, true );
     293           0 :             SFX_ITEMSET_GET( _rSet, pUrlItem, SfxStringItem, DSID_CONNECTURL, true );
     294             :             assert( pUrlItem );
     295             :             assert( pNameItem );
     296           0 :             sName = pNameItem->GetValue();
     297           0 :             sConnectURL = pUrlItem->GetValue();
     298             :         }
     299             : 
     300           0 :         m_eNotSupportedKnownType =  ::dbaccess::DST_UNKNOWN;
     301           0 :         implSetCurrentType(  OUString() );
     302             : 
     303             :         // compare the DSN prefix with the registered ones
     304           0 :         OUString sDisplayName;
     305             : 
     306           0 :         if (m_pCollection && bValid)
     307             :         {
     308           0 :             implSetCurrentType( m_pCollection->getPrefix( sConnectURL ) );
     309           0 :             sDisplayName = m_pCollection->getTypeDisplayName( m_eCurrentSelection );
     310             :         }
     311             : 
     312             :         // select the correct datasource type
     313           0 :         if  (   approveDatasourceType( m_eCurrentSelection, sDisplayName )
     314           0 :             &&  ( LISTBOX_ENTRY_NOTFOUND == m_pDatasourceType->GetEntryPos( sDisplayName ) )
     315             :             )
     316             :         {   // this indicates it's really a type which is known in general, but not supported on the current platform
     317             :             // show a message saying so
     318             :             //  eSpecialMessage = smUnsupportedType;
     319           0 :             insertDatasourceTypeEntryData( m_eCurrentSelection, sDisplayName );
     320             :             // remember this type so we can show the special message again if the user selects this
     321             :             // type again (without changing the data source)
     322           0 :             m_eNotSupportedKnownType = m_pCollection->determineType( m_eCurrentSelection );
     323             :         }
     324             : 
     325           0 :         return sDisplayName;
     326             :     }
     327             : 
     328             :     // For the databaseWizard we only have one entry for the MySQL Database,
     329             :     // because we have a separate tabpage to retrieve the respective datasource type
     330             :     // ( ::dbaccess::DST_MYSQL_ODBC ||  ::dbaccess::DST_MYSQL_JDBC). Therefore we use  ::dbaccess::DST_MYSQL_JDBC as a temporary
     331             :     // representative for all MySQl databases)
     332             :     // Also, embedded databases (embedded HSQL, at the moment), are not to appear in the list of
     333             :     // databases to connect to.
     334           0 :     bool OGeneralPage::approveDatasourceType( const OUString& _sURLPrefix, OUString& _inout_rDisplayName )
     335             :     {
     336           0 :         return approveDatasourceType( m_pCollection->determineType(_sURLPrefix), _inout_rDisplayName );
     337             :     }
     338             : 
     339           0 :     bool OGeneralPage::approveDatasourceType( ::dbaccess::DATASOURCE_TYPE eType, OUString& _inout_rDisplayName )
     340             :     {
     341           0 :         if ( eType == ::dbaccess::DST_MYSQL_NATIVE_DIRECT )
     342             :         {
     343             :             // do not display the Connector/OOo driver itself, it is always wrapped via the MySQL-Driver, if
     344             :             // this driver is installed
     345           0 :             if ( m_pCollection->hasDriver( "sdbc:mysql:mysqlc:" ) )
     346           0 :                 _inout_rDisplayName = "";
     347             :         }
     348             : 
     349           0 :         if ( eType ==  ::dbaccess::DST_EMBEDDED_HSQLDB
     350           0 :                 || eType ==  ::dbaccess::DST_EMBEDDED_FIREBIRD )
     351           0 :             _inout_rDisplayName = "";
     352             : 
     353           0 :         return _inout_rDisplayName.getLength() > 0;
     354             :     }
     355             : 
     356           0 :     void OGeneralPage::insertDatasourceTypeEntryData(const OUString& _sType, const OUString& sDisplayName)
     357             :     {
     358             :         // insert a (temporary) entry
     359           0 :         sal_uInt16 nPos = m_pDatasourceType->InsertEntry(sDisplayName);
     360           0 :         if ( nPos >= m_aURLPrefixes.size() )
     361           0 :             m_aURLPrefixes.resize(nPos+1);
     362           0 :         m_aURLPrefixes[nPos] = _sType;
     363           0 :     }
     364             : 
     365           0 :     void OGeneralPageWizard::insertEmbeddedDBTypeEntryData(const OUString& _sType, const OUString& sDisplayName)
     366             :     {
     367             :         // insert a (temporary) entry
     368           0 :         sal_uInt16 nPos = m_pEmbeddedDBType->InsertEntry(sDisplayName);
     369           0 :         if ( nPos >= m_aEmbeddedURLPrefixes.size() )
     370           0 :             m_aEmbeddedURLPrefixes.resize(nPos+1);
     371           0 :         m_aEmbeddedURLPrefixes[nPos] = _sType;
     372           0 :     }
     373             : 
     374           0 :     void OGeneralPage::fillWindows(::std::vector< ISaveValueWrapper* >& _rControlList)
     375             :     {
     376           0 :         _rControlList.push_back( new ODisableWrapper<FixedText>( m_pSpecialMessage ) );
     377           0 :     }
     378             : 
     379           0 :     void OGeneralPage::fillControls(::std::vector< ISaveValueWrapper* >& _rControlList)
     380             :     {
     381           0 :         _rControlList.push_back( new OSaveValueWrapper<ListBox>( m_pDatasourceType ) );
     382           0 :     }
     383             : 
     384           0 :     void OGeneralPage::implSetCurrentType( const OUString& _eType )
     385             :     {
     386           0 :         if ( _eType == m_eCurrentSelection )
     387           0 :             return;
     388             : 
     389           0 :         m_eCurrentSelection = _eType;
     390             :     }
     391             : 
     392           0 :     void OGeneralPage::Reset(const SfxItemSet* _rCoreAttrs)
     393             :     {
     394             :         // reset all locale data
     395           0 :         implSetCurrentType(  OUString() );
     396             :             // this ensures that our type selection link will be called, even if the new is is the same as the
     397             :             // current one
     398           0 :         OGenericAdministrationPage::Reset(_rCoreAttrs);
     399           0 :     }
     400             : 
     401           0 :     IMPL_LINK( OGeneralPageWizard, OnEmbeddedDBTypeSelected, ListBox*, _pBox )
     402             :     {
     403             :         // get the type from the entry data
     404           0 :         sal_uInt16 nSelected = _pBox->GetSelectEntryPos();
     405           0 :         if (nSelected >= m_aEmbeddedURLPrefixes.size() )
     406             :         {
     407             :             SAL_WARN("dbaccess.ui.OGeneralPage", "Got out-of-range value '" << nSelected <<  "' from the DatasourceType selection ListBox's GetSelectEntryPos(): no corresponding URL prefix");
     408           0 :             return 0L;
     409             :         }
     410           0 :         const OUString sURLPrefix = m_aEmbeddedURLPrefixes[ nSelected ];
     411             : 
     412           0 :         setParentTitle( sURLPrefix );
     413             :         // let the impl method do all the stuff
     414           0 :         onTypeSelected( sURLPrefix );
     415             :         // tell the listener we were modified
     416           0 :         callModifiedHdl();
     417             :         // outta here
     418           0 :         return 0L;
     419             :     }
     420             : 
     421           0 :     IMPL_LINK( OGeneralPage, OnDatasourceTypeSelected, ListBox*, _pBox )
     422             :     {
     423             :         // get the type from the entry data
     424           0 :         sal_uInt16 nSelected = _pBox->GetSelectEntryPos();
     425           0 :         if (nSelected >= m_aURLPrefixes.size() )
     426             :         {
     427             :             SAL_WARN("dbaccess.ui.OGeneralPage", "Got out-of-range value '" << nSelected <<  "' from the DatasourceType selection ListBox's GetSelectEntryPos(): no corresponding URL prefix");
     428           0 :             return 0L;
     429             :         }
     430           0 :         const OUString sURLPrefix = m_aURLPrefixes[ nSelected ];
     431             : 
     432           0 :         setParentTitle( sURLPrefix );
     433             :         // let the impl method do all the stuff
     434           0 :         onTypeSelected( sURLPrefix );
     435             :         // tell the listener we were modified
     436           0 :         callModifiedHdl();
     437             :         // outta here
     438           0 :         return 0L;
     439             :     }
     440             : 
     441             :     // OGeneralPageDialog
     442           0 :     OGeneralPageDialog::OGeneralPageDialog( vcl::Window* pParent, const SfxItemSet& _rItems )
     443           0 :         :OGeneralPage( pParent, "dbaccess/ui/generalpagedialog.ui", _rItems )
     444             :     {
     445           0 :     }
     446             : 
     447           0 :     void OGeneralPageDialog::setParentTitle( const OUString& _sURLPrefix )
     448             :     {
     449           0 :         const OUString sName = m_pCollection->getTypeDisplayName( _sURLPrefix );
     450           0 :         if ( m_pAdminDialog )
     451             :         {
     452           0 :             OUString sMessage = OUString( ModuleRes( STR_PARENTTITLE_GENERAL ) );
     453           0 :             m_pAdminDialog->setTitle( sMessage.replaceAll( "#", sName ) );
     454           0 :         }
     455           0 :     }
     456             : 
     457           0 :     void OGeneralPageDialog::implInitControls( const SfxItemSet& _rSet, bool _bSaveValue )
     458             :     {
     459           0 :         OGeneralPage::implInitControls( _rSet, _bSaveValue );
     460             : 
     461             :         // first check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa)
     462             :         bool bValid, bReadonly;
     463           0 :         getFlags(_rSet, bValid, bReadonly );
     464             : 
     465           0 :         m_pDatasourceType->Enable( bValid );
     466           0 :     }
     467             : 
     468           0 :     bool OGeneralPageDialog::FillItemSet( SfxItemSet* _rCoreAttrs )
     469             :     {
     470           0 :         bool bChangedSomething = false;
     471             : 
     472           0 :         sal_uInt16 nEntry = m_pDatasourceType->GetSelectEntryPos();
     473           0 :         OUString sURLPrefix = m_aURLPrefixes[ nEntry ];
     474             : 
     475           0 :         if ( m_pDatasourceType->IsValueChangedFromSaved() )
     476             :         {
     477           0 :             _rCoreAttrs->Put( SfxStringItem( DSID_CONNECTURL, sURLPrefix ) );
     478           0 :             bChangedSomething = true;
     479             :         }
     480             : 
     481           0 :         return bChangedSomething;
     482             :     }
     483             : 
     484             :     // OGeneralPageWizard
     485           0 :     OGeneralPageWizard::OGeneralPageWizard( vcl::Window* pParent, const SfxItemSet& _rItems )
     486             :         :OGeneralPage( pParent, "dbaccess/ui/generalpagewizard.ui", _rItems )
     487             :         ,m_pRB_CreateDatabase           ( NULL )
     488             :         ,m_pRB_OpenExistingDatabase     ( NULL )
     489             :         ,m_pRB_ConnectDatabase          ( NULL )
     490             :         ,m_pFT_EmbeddedDBLabel          ( NULL )
     491             :         ,m_pEmbeddedDBType              ( NULL )
     492             :         ,m_pFT_DocListLabel             ( NULL )
     493             :         ,m_pLB_DocumentList             ( NULL )
     494             :         ,m_pPB_OpenDatabase             ( NULL )
     495             :         ,m_eOriginalCreationMode        ( eCreateNew )
     496           0 :         ,m_bInitEmbeddedDBList          ( true )
     497             :     {
     498           0 :         get( m_pRB_CreateDatabase, "createDatabase" );
     499           0 :         get( m_pRB_OpenExistingDatabase, "openExistingDatabase" );
     500           0 :         get( m_pRB_ConnectDatabase, "connectDatabase" );
     501           0 :         get( m_pFT_EmbeddedDBLabel, "embeddeddbLabel" );
     502           0 :         get( m_pEmbeddedDBType, "embeddeddbList" );
     503           0 :         get( m_pFT_DocListLabel, "docListLabel" );
     504           0 :         get( m_pLB_DocumentList, "documentList" );
     505           0 :         get( m_pPB_OpenDatabase, "openDatabase" );
     506             : 
     507             :         // If no driver for embedded DBs is installed, and no dBase driver, then hide the "Create new database" option
     508           0 :         sal_Int32 nCreateNewDBIndex = m_pCollection->getIndexOf( m_pCollection->getEmbeddedDatabase() );
     509           0 :         if ( nCreateNewDBIndex == -1 )
     510           0 :             nCreateNewDBIndex = m_pCollection->getIndexOf( OUString( "sdbc:dbase:" ) );
     511           0 :         bool bHideCreateNew = ( nCreateNewDBIndex == -1 );
     512             : 
     513             :         // also, if our application policies tell us to hide the option, do it
     514             :         ::utl::OConfigurationTreeRoot aConfig( ::utl::OConfigurationTreeRoot::createWithComponentContext(
     515             :             ::comphelper::getProcessComponentContext(),
     516             :             OUString( "/org.openoffice.Office.DataAccess/Policies/Features/Base" )
     517           0 :         ) );
     518           0 :         bool bAllowCreateLocalDatabase( true );
     519           0 :         OSL_VERIFY( aConfig.getNodeValue( "CreateLocalDatabase" ) >>= bAllowCreateLocalDatabase );
     520           0 :         if ( !bAllowCreateLocalDatabase )
     521           0 :             bHideCreateNew = true;
     522             : 
     523           0 :         if ( bHideCreateNew )
     524             :         {
     525           0 :             m_pRB_CreateDatabase->Hide();
     526           0 :             m_pRB_ConnectDatabase->Check();
     527             :         }
     528             :         else
     529           0 :             m_pRB_CreateDatabase->Check();
     530             : 
     531             :         // do some knittings
     532           0 :         m_pEmbeddedDBType->SetSelectHdl(LINK(this, OGeneralPageWizard, OnEmbeddedDBTypeSelected));
     533           0 :         m_pRB_CreateDatabase->SetClickHdl( LINK( this, OGeneralPageWizard, OnCreateDatabaseModeSelected ) );
     534           0 :         m_pRB_ConnectDatabase->SetClickHdl( LINK( this, OGeneralPageWizard, OnSetupModeSelected ) );
     535           0 :         m_pRB_OpenExistingDatabase->SetClickHdl( LINK( this, OGeneralPageWizard, OnSetupModeSelected ) );
     536           0 :         m_pLB_DocumentList->SetSelectHdl( LINK( this, OGeneralPageWizard, OnDocumentSelected ) );
     537           0 :         m_pPB_OpenDatabase->SetClickHdl( LINK( this, OGeneralPageWizard, OnOpenDocument ) );
     538           0 :     }
     539             : 
     540           0 :     OGeneralPageWizard::CreationMode OGeneralPageWizard::GetDatabaseCreationMode() const
     541             :     {
     542           0 :         if ( m_pRB_CreateDatabase->IsChecked() )
     543           0 :             return eCreateNew;
     544           0 :         if ( m_pRB_ConnectDatabase->IsChecked() )
     545           0 :             return eConnectExternal;
     546           0 :         return eOpenExisting;
     547             :     }
     548             : 
     549           0 :     void OGeneralPageWizard::GetFocus()
     550             :     {
     551           0 :         OGeneralPage::GetFocus();
     552           0 :         if ( m_pLB_DocumentList && m_pLB_DocumentList->IsEnabled() )
     553           0 :             m_pLB_DocumentList->GrabFocus();
     554           0 :         else if ( m_pDatasourceType && m_pDatasourceType->IsEnabled() )
     555           0 :             m_pDatasourceType->GrabFocus();
     556           0 :     }
     557             : 
     558           0 :     void OGeneralPageWizard::implInitControls( const SfxItemSet& _rSet, bool _bSaveValue )
     559             :     {
     560           0 :         OGeneralPage::implInitControls( _rSet, _bSaveValue );
     561             : 
     562           0 :         initializeEmbeddedDBList();
     563           0 :         m_pEmbeddedDBType->SelectEntry( getEmbeddedDBName( _rSet ) );
     564             : 
     565             :         // first check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa)
     566             :         bool bValid, bReadonly;
     567           0 :         getFlags( _rSet, bValid, bReadonly );
     568             : 
     569           0 :         SetText( OUString() );
     570             : 
     571           0 :         LayoutHelper::positionBelow( *m_pRB_ConnectDatabase, *m_pDatasourceType, RelatedControls, INDENT_BELOW_RADIO );
     572             : 
     573           0 :         if ( !bValid || bReadonly )
     574             :         {
     575           0 :             m_pFT_EmbeddedDBLabel->Enable( false );
     576           0 :             m_pDatasourceType->Enable( false );
     577           0 :             m_pPB_OpenDatabase->Enable( false );
     578           0 :             m_pFT_DocListLabel->Enable( false );
     579           0 :             m_pLB_DocumentList->Enable( false );
     580             :         }
     581             :         else
     582             :         {
     583           0 :             m_aControlDependencies.enableOnRadioCheck( *m_pRB_CreateDatabase, *m_pEmbeddedDBType, *m_pFT_EmbeddedDBLabel );
     584           0 :             m_aControlDependencies.enableOnRadioCheck( *m_pRB_ConnectDatabase, *m_pDatasourceType );
     585           0 :             m_aControlDependencies.enableOnRadioCheck( *m_pRB_OpenExistingDatabase, *m_pPB_OpenDatabase, *m_pFT_DocListLabel, *m_pLB_DocumentList );
     586             :         }
     587             : 
     588           0 :         m_pLB_DocumentList->SetDropDownLineCount( 20 );
     589           0 :         if ( m_pLB_DocumentList->GetEntryCount() )
     590           0 :             m_pLB_DocumentList->SelectEntryPos( 0 );
     591             : 
     592           0 :         m_eOriginalCreationMode = GetDatabaseCreationMode();
     593           0 :     }
     594             : 
     595           0 :     OUString OGeneralPageWizard::getDatasourceName(const SfxItemSet& _rSet)
     596             :     {
     597             :         // Sets jdbc as the default selected databse on startup.
     598           0 :         if (m_pRB_CreateDatabase->IsChecked() )
     599           0 :             return m_pCollection->getTypeDisplayName( OUString( "jdbc:" ) );
     600             : 
     601           0 :         return OGeneralPage::getDatasourceName( _rSet );
     602             :     }
     603             : 
     604           0 :     bool OGeneralPageWizard::approveDatasourceType( ::dbaccess::DATASOURCE_TYPE eType, OUString& _inout_rDisplayName )
     605             :     {
     606           0 :         switch ( eType )
     607             :         {
     608             :         case ::dbaccess::DST_MYSQL_JDBC:
     609           0 :             _inout_rDisplayName = "MySQL";
     610           0 :             break;
     611             :         case ::dbaccess::DST_MYSQL_ODBC:
     612             :         case ::dbaccess::DST_MYSQL_NATIVE:
     613             :             // don't display those, the decision whether the user connects via JDBC/ODBC/C-OOo is made on another
     614             :             // page
     615           0 :             _inout_rDisplayName = "";
     616           0 :             break;
     617             :         default:
     618           0 :             break;
     619             :         }
     620             : 
     621           0 :         return OGeneralPage::approveDatasourceType( eType, _inout_rDisplayName );
     622             :     }
     623             : 
     624           0 :     bool OGeneralPageWizard::FillItemSet(SfxItemSet* _rCoreAttrs)
     625             :     {
     626           0 :         bool bChangedSomething = false;
     627             : 
     628           0 :         bool bCommitTypeSelection = true;
     629             : 
     630           0 :         if ( m_pRB_CreateDatabase->IsChecked() )
     631             :         {
     632           0 :             _rCoreAttrs->Put( SfxStringItem( DSID_CONNECTURL, OUString( "sdbc:dbase:" ) ) );
     633           0 :             bChangedSomething = true;
     634           0 :             bCommitTypeSelection = false;
     635             :         }
     636           0 :         else if ( m_pRB_OpenExistingDatabase->IsChecked() )
     637             :         {
     638           0 :             if ( m_pRB_OpenExistingDatabase->IsValueChangedFromSaved() )
     639           0 :                 bChangedSomething = true;
     640             : 
     641             :             // TODO
     642           0 :             bCommitTypeSelection = false;
     643             :         }
     644             : 
     645           0 :         if ( bCommitTypeSelection )
     646             :         {
     647           0 :             sal_uInt16 nEntry = m_pDatasourceType->GetSelectEntryPos();
     648           0 :             OUString sURLPrefix = m_aURLPrefixes[nEntry];
     649             : 
     650           0 :             if  (  m_pDatasourceType->IsValueChangedFromSaved()
     651           0 :                 || ( GetDatabaseCreationMode() != m_eOriginalCreationMode )
     652             :                 )
     653             :             {
     654           0 :                 _rCoreAttrs->Put( SfxStringItem( DSID_CONNECTURL,sURLPrefix ) );
     655           0 :                 bChangedSomething = true;
     656             :             }
     657             :             else
     658           0 :                 implSetCurrentType( sURLPrefix );
     659             :         }
     660           0 :         return bChangedSomething;
     661             :     }
     662             : 
     663           0 :     OGeneralPageWizard::DocumentDescriptor OGeneralPageWizard::GetSelectedDocument() const
     664             :     {
     665           0 :         DocumentDescriptor aDocument;
     666           0 :         if ( !m_aBrowsedDocument.sURL.isEmpty() )
     667           0 :             aDocument = m_aBrowsedDocument;
     668             :         else
     669             :         {
     670           0 :             aDocument.sURL = m_pLB_DocumentList->GetSelectedDocumentURL();
     671           0 :             aDocument.sFilter = m_pLB_DocumentList->GetSelectedDocumentFilter();
     672             :         }
     673           0 :         return aDocument;
     674             :     }
     675             : 
     676           0 :     IMPL_LINK( OGeneralPageWizard, OnCreateDatabaseModeSelected, RadioButton*, /*_pBox*/ )
     677             :     {
     678           0 :         if ( m_aCreationModeHandler.IsSet() )
     679           0 :             m_aCreationModeHandler.Call( this );
     680             : 
     681           0 :         OnEmbeddedDBTypeSelected( m_pEmbeddedDBType );
     682           0 :         return 1L;
     683             :     }
     684             : 
     685           0 :     IMPL_LINK( OGeneralPageWizard, OnSetupModeSelected, RadioButton*, /*_pBox*/ )
     686             :     {
     687           0 :         if ( m_aCreationModeHandler.IsSet() )
     688           0 :             m_aCreationModeHandler.Call( this );
     689           0 :         OnDatasourceTypeSelected(m_pDatasourceType);
     690           0 :         return 1L;
     691             :     }
     692             : 
     693           0 :     IMPL_LINK( OGeneralPageWizard, OnDocumentSelected, ListBox*, /*_pBox*/ )
     694             :     {
     695           0 :         m_aDocumentSelectionHandler.Call( this );
     696           0 :         return 0L;
     697             :     }
     698             : 
     699           0 :     IMPL_LINK( OGeneralPageWizard, OnOpenDocument, PushButton*, /*_pBox*/ )
     700             :     {
     701             :         ::sfx2::FileDialogHelper aFileDlg(
     702             :                 ui::dialogs::TemplateDescription::FILEOPEN_READONLY_VERSION,
     703           0 :                 0, OUString("sdatabase") );
     704           0 :         const SfxFilter* pFilter = getStandardDatabaseFilter();
     705           0 :         if ( pFilter )
     706             :         {
     707           0 :             aFileDlg.SetCurrentFilter(pFilter->GetUIName());
     708             :         }
     709           0 :         if ( aFileDlg.Execute() == ERRCODE_NONE )
     710             :         {
     711           0 :             OUString sPath = aFileDlg.GetPath();
     712           0 :             if ( aFileDlg.GetCurrentFilter() != pFilter->GetUIName() || !pFilter->GetWildcard().Matches(sPath) )
     713             :             {
     714           0 :                 OUString sMessage(ModuleRes(STR_ERR_USE_CONNECT_TO));
     715           0 :                 InfoBox aError(this, sMessage);
     716           0 :                 aError.Execute();
     717           0 :                 m_pRB_ConnectDatabase->Check();
     718           0 :                 OnSetupModeSelected( m_pRB_ConnectDatabase );
     719           0 :                 return 0L;
     720             :             }
     721           0 :             m_aBrowsedDocument.sURL = sPath;
     722           0 :             m_aBrowsedDocument.sFilter = "";
     723           0 :             m_aChooseDocumentHandler.Call( this );
     724           0 :             return 1L;
     725             :         }
     726             : 
     727           0 :         return 0L;
     728             :     }
     729             : 
     730          72 : }   // namespace dbaui
     731             : 
     732             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10