LCOV - code coverage report
Current view: top level - dbaccess/source/ui/dlg - generalpage.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 282 0.0 %
Date: 2012-08-25 Functions: 0 32 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 691 0.0 %

           Branch data     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                 :            : 
      21                 :            : #include "dsnItem.hxx"
      22                 :            : #include "generalpage.hxx"
      23                 :            : #include <connectivity/dbexception.hxx>
      24                 :            : #include "dbu_dlg.hrc"
      25                 :            : #include "dbadmin.hrc"
      26                 :            : #include "dsitems.hxx"
      27                 :            : #include "dbustrings.hrc"
      28                 :            : #include "dbadmin.hxx"
      29                 :            : #include <sfx2/filedlghelper.hxx>
      30                 :            : #include <sfx2/docfilt.hxx>
      31                 :            : #include <vcl/stdtext.hxx>
      32                 :            : #include "localresaccess.hxx"
      33                 :            : #include <vcl/msgbox.hxx>
      34                 :            : #include <svl/stritem.hxx>
      35                 :            : #include <vcl/waitobj.hxx>
      36                 :            : #include <com/sun/star/sdbc/XDriverAccess.hpp>
      37                 :            : #include <com/sun/star/beans/PropertyValue.hpp>
      38                 :            : #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
      39                 :            : #include <com/sun/star/uno/Sequence.hxx>
      40                 :            : #include <com/sun/star/container/XNameAccess.hpp>
      41                 :            : #include "DriverSettings.hxx"
      42                 :            : #include "UITools.hxx"
      43                 :            : #include <comphelper/processfactory.hxx>
      44                 :            : #include <unotools/confignode.hxx>
      45                 :            : #include <osl/diagnose.h>
      46                 :            : 
      47                 :            : //.........................................................................
      48                 :            : namespace dbaui
      49                 :            : {
      50                 :            : //.........................................................................
      51                 :            :     using namespace ::com::sun::star;
      52                 :            :     using namespace ::com::sun::star::uno;
      53                 :            :     using namespace ::com::sun::star::sdbc;
      54                 :            :     using namespace ::com::sun::star::beans;
      55                 :            :     using namespace ::com::sun::star::container;
      56                 :            : 
      57                 :            :     //=========================================================================
      58                 :            :     //= OGeneralPage
      59                 :            :     //=========================================================================
      60                 :            :     //-------------------------------------------------------------------------
      61                 :          0 :     OGeneralPage::OGeneralPage(Window* pParent, const SfxItemSet& _rItems, sal_Bool _bDBWizardMode)
      62                 :            :         :OGenericAdministrationPage(pParent, ModuleRes(PAGE_GENERAL), _rItems)
      63                 :            :         ,m_aFTHeaderText                (this, ModuleRes(FT_GENERALHEADERTEXT))
      64                 :            :         ,m_aFTHelpText                  (this, ModuleRes(FT_GENERALHELPTEXT))
      65                 :            :         ,m_aFT_DatasourceTypeHeader     (this, ModuleRes(FT_DATASOURCEHEADER))
      66                 :            :         ,m_aRB_CreateDatabase           (this, ModuleRes(RB_CREATEDBDATABASE))
      67                 :            :         ,m_aRB_OpenDocument             (this, ModuleRes(RB_OPENEXISTINGDOC))
      68                 :            :         ,m_aRB_GetExistingDatabase      (this, ModuleRes(RB_GETEXISTINGDATABASE))
      69                 :            :         ,m_aFT_DocListLabel             (this, ModuleRes(FT_DOCLISTLABEL))
      70         [ #  # ]:          0 :         ,m_pLB_DocumentList             ( new OpenDocumentListBox( this, "com.sun.star.sdb.OfficeDatabaseDocument", ModuleRes( LB_DOCUMENTLIST ) ) )
      71                 :            :         ,m_aPB_OpenDocument             (this, "com.sun.star.sdb.OfficeDatabaseDocument", ModuleRes(PB_OPENDOCUMENT))
      72                 :            :         ,m_aTypePreLabel                (this, ModuleRes(FT_DATASOURCETYPE_PRE))
      73                 :            :         ,m_aDatasourceTypeLabel         (this, ModuleRes(FT_DATATYPE))
      74         [ #  # ]:          0 :         ,m_pDatasourceType              ( new ListBox(this, ModuleRes(LB_DATATYPE)))
      75                 :            :         ,m_aFTDataSourceAppendix        (this, ModuleRes(FT_DATATYPEAPPENDIX))
      76                 :            :         ,m_aTypePostLabel               (this, ModuleRes(FT_DATASOURCETYPE_POST))
      77                 :            :         ,m_aSpecialMessage              (this, ModuleRes(FT_SPECIAL_MESSAGE))
      78                 :            :         ,m_DBWizardMode                 (_bDBWizardMode)
      79                 :            :         ,m_sMySQLEntry                  (ModuleRes(STR_MYSQLENTRY))
      80                 :            :         ,m_eOriginalCreationMode        (eCreateNew)
      81                 :            :         ,m_pCollection                  (NULL)
      82                 :            :         ,m_eNotSupportedKnownType       ( ::dbaccess::DST_UNKNOWN)
      83                 :            :         ,m_eLastMessage                 (smNone)
      84                 :            :         ,m_bDisplayingInvalid           (sal_False)
      85                 :            :         ,m_bUserGrabFocus               (sal_True)
      86 [ #  # ][ #  # ]:          0 :         ,m_bInitTypeList                (true)
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      87                 :            :     {
      88                 :            :         // fill the listbox with the UI descriptions for the possible types
      89                 :            :         // and remember the respective DSN prefixes
      90         [ #  # ]:          0 :         FreeResource();
      91                 :            :         // extract the datasource type collection from the item set
      92 [ #  # ][ #  # ]:          0 :         DbuTypeCollectionItem* pCollectionItem = PTR_CAST(DbuTypeCollectionItem, _rItems.GetItem(DSID_TYPECOLLECTION));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      93         [ #  # ]:          0 :         if (pCollectionItem)
      94                 :          0 :             m_pCollection = pCollectionItem->getCollection();
      95                 :            :         OSL_ENSURE(m_pCollection, "OGeneralPage::OGeneralPage : really need a DSN type collection !");
      96                 :            : 
      97                 :            :         // If no driver for embedded DBs is installed, and no dBase driver, then hide the "Create new database" option
      98 [ #  # ][ #  # ]:          0 :         sal_Int32 nCreateNewDBIndex = m_pCollection->getIndexOf( m_pCollection->getEmbeddedDatabase() );
      99         [ #  # ]:          0 :         if ( nCreateNewDBIndex == -1 )
     100 [ #  # ][ #  # ]:          0 :             nCreateNewDBIndex = m_pCollection->getIndexOf( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:dbase:")) );
     101                 :          0 :         bool bHideCreateNew = ( nCreateNewDBIndex == -1 );
     102                 :            : 
     103                 :            :         // also, if our application policies tell us to hide the option, do it
     104                 :            :         ::utl::OConfigurationTreeRoot aConfig( ::utl::OConfigurationTreeRoot::createWithServiceFactory(
     105                 :            :             ::comphelper::getProcessServiceFactory(),
     106                 :            :             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.DataAccess/Policies/Features/Base" ) )
     107 [ #  # ][ #  # ]:          0 :         ) );
                 [ #  # ]
     108                 :          0 :         sal_Bool bAllowCreateLocalDatabase( sal_True );
     109                 :          0 :         OSL_VERIFY( aConfig.getNodeValue( "CreateLocalDatabase" ) >>= bAllowCreateLocalDatabase );
     110         [ #  # ]:          0 :         if ( !bAllowCreateLocalDatabase )
     111                 :          0 :             bHideCreateNew = true;
     112                 :            : 
     113         [ #  # ]:          0 :         if ( bHideCreateNew )
     114                 :            :         {
     115         [ #  # ]:          0 :             m_aRB_CreateDatabase.Hide();
     116                 :            :             Window* pWindowsToMove[] = {
     117                 :          0 :                 &m_aRB_OpenDocument, &m_aRB_GetExistingDatabase, &m_aFT_DocListLabel, m_pLB_DocumentList.get(),
     118                 :          0 :                 &m_aPB_OpenDocument, &m_aDatasourceTypeLabel, m_pDatasourceType.get(), &m_aFTDataSourceAppendix,
     119                 :            :                 &m_aTypePostLabel
     120                 :          0 :             };
     121 [ #  # ][ #  # ]:          0 :             const long nOffset = m_aRB_OpenDocument.GetPosPixel().Y() - m_aRB_CreateDatabase.GetPosPixel().Y();
     122         [ #  # ]:          0 :             for ( size_t i=0; i < sizeof( pWindowsToMove ) / sizeof( pWindowsToMove[0] ); ++i )
     123                 :            :             {
     124         [ #  # ]:          0 :                 Point aPos( pWindowsToMove[i]->GetPosPixel() );
     125                 :          0 :                 aPos.Y() -= nOffset;
     126         [ #  # ]:          0 :                 pWindowsToMove[i]->SetPosPixel( aPos );
     127                 :            :             }
     128                 :            :         }
     129                 :            : 
     130         [ #  # ]:          0 :         if ( bHideCreateNew )
     131         [ #  # ]:          0 :             m_aRB_GetExistingDatabase.Check();
     132                 :            :         else
     133         [ #  # ]:          0 :             m_aRB_CreateDatabase.Check();
     134                 :            : 
     135                 :            :         // do some knittings
     136         [ #  # ]:          0 :         m_pDatasourceType->SetSelectHdl(LINK(this, OGeneralPage, OnDatasourceTypeSelected));
     137         [ #  # ]:          0 :            m_aRB_CreateDatabase.SetClickHdl(LINK(this, OGeneralPage, OnSetupModeSelected));
     138         [ #  # ]:          0 :            m_aRB_GetExistingDatabase.SetClickHdl(LINK(this, OGeneralPage, OnSetupModeSelected));
     139         [ #  # ]:          0 :            m_aRB_OpenDocument.SetClickHdl(LINK(this, OGeneralPage, OnSetupModeSelected));
     140         [ #  # ]:          0 :         m_pLB_DocumentList->SetSelectHdl( LINK( this, OGeneralPage, OnDocumentSelected ) );
     141 [ #  # ][ #  # ]:          0 :         m_aPB_OpenDocument.SetClickHdl( LINK( this, OGeneralPage, OnOpenDocument ) );
     142                 :          0 :     }
     143                 :            : 
     144                 :            :     //-------------------------------------------------------------------------
     145 [ #  # ][ #  # ]:          0 :     OGeneralPage::~OGeneralPage()
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     146                 :            :     {
     147                 :          0 :         m_pDatasourceType.reset( NULL );
     148                 :          0 :         m_pLB_DocumentList.reset( NULL );
     149         [ #  # ]:          0 :     }
     150                 :            : 
     151                 :            :     //-------------------------------------------------------------------------
     152                 :            :     namespace
     153                 :            :     {
     154 [ #  # ][ #  # ]:          0 :         struct DisplayedType
     155                 :            :         {
     156                 :            :             ::rtl::OUString eType;
     157                 :            :             String          sDisplayName;
     158                 :            : 
     159         [ #  # ]:          0 :             DisplayedType( const ::rtl::OUString& _eType, const String& _rDisplayName ) : eType( _eType ), sDisplayName( _rDisplayName ) { }
     160                 :            :         };
     161                 :            :         typedef ::std::vector< DisplayedType > DisplayedTypes;
     162                 :            : 
     163                 :            :         struct DisplayedTypeLess : ::std::binary_function< DisplayedType, DisplayedType, bool >
     164                 :            :         {
     165                 :          0 :             bool operator() ( const DisplayedType& _rLHS, const DisplayedType& _rRHS )
     166                 :            :             {
     167                 :          0 :                 return _rLHS.eType < _rRHS.eType;
     168                 :            :             }
     169                 :            :         };
     170                 :            :     }
     171                 :            : 
     172                 :            :     //-------------------------------------------------------------------------
     173                 :          0 :     void OGeneralPage::initializeTypeList()
     174                 :            :     {
     175         [ #  # ]:          0 :         if ( m_bInitTypeList )
     176                 :            :         {
     177                 :          0 :             m_bInitTypeList = false;
     178                 :          0 :             m_pDatasourceType->Clear();
     179                 :            : 
     180         [ #  # ]:          0 :             if ( m_pCollection )
     181                 :            :             {
     182         [ #  # ]:          0 :                 DisplayedTypes aDisplayedTypes;
     183                 :            : 
     184         [ #  # ]:          0 :                 ::dbaccess::ODsnTypeCollection::TypeIterator aEnd = m_pCollection->end();
     185 [ #  # ][ #  # ]:          0 :                 for (   ::dbaccess::ODsnTypeCollection::TypeIterator aTypeLoop =  m_pCollection->begin();
         [ #  # ][ #  # ]
     186                 :            :                         aTypeLoop != aEnd;
     187                 :            :                         ++aTypeLoop
     188                 :            :                     )
     189                 :            :                 {
     190         [ #  # ]:          0 :                     const ::rtl::OUString sURLPrefix = aTypeLoop.getURLPrefix();
     191         [ #  # ]:          0 :                     if ( !sURLPrefix.isEmpty() )
     192                 :            :                     {
     193         [ #  # ]:          0 :                         String sDisplayName = aTypeLoop.getDisplayName();
     194 [ #  # ][ #  # ]:          0 :                         if (   m_pDatasourceType->GetEntryPos( sDisplayName ) == LISTBOX_ENTRY_NOTFOUND
         [ #  # ][ #  # ]
     195         [ #  # ]:          0 :                             && approveDataSourceType( sURLPrefix, sDisplayName ) )
     196                 :            :                         {
     197 [ #  # ][ #  # ]:          0 :                             aDisplayedTypes.push_back( DisplayedTypes::value_type( sURLPrefix, sDisplayName ) );
                 [ #  # ]
     198         [ #  # ]:          0 :                         }
     199                 :            :                     }
     200         [ #  # ]:          0 :                 }
     201         [ #  # ]:          0 :                 ::std::sort( aDisplayedTypes.begin(), aDisplayedTypes.end(), DisplayedTypeLess() );
     202         [ #  # ]:          0 :                 DisplayedTypes::const_iterator aDisplayEnd = aDisplayedTypes.end();
     203 [ #  # ][ #  # ]:          0 :                 for (   DisplayedTypes::const_iterator loop = aDisplayedTypes.begin();
                 [ #  # ]
     204                 :            :                         loop != aDisplayEnd;
     205                 :            :                         ++loop
     206                 :            :                     )
     207 [ #  # ][ #  # ]:          0 :                     insertDatasourceTypeEntryData( loop->eType, loop->sDisplayName );
         [ #  # ][ #  # ]
     208                 :            :             }
     209                 :            :         }
     210                 :          0 :     }
     211                 :            : 
     212                 :            : 
     213                 :            : 
     214                 :            :     //-------------------------------------------------------------------------
     215                 :          0 :     void OGeneralPage::setParentTitle(const ::rtl::OUString& _sURLPrefix)
     216                 :            :     {
     217         [ #  # ]:          0 :         if (!m_DBWizardMode)
     218                 :            :         {
     219         [ #  # ]:          0 :             const String sName = m_pCollection->getTypeDisplayName(_sURLPrefix);
     220         [ #  # ]:          0 :             if ( m_pAdminDialog )
     221                 :            :             {
     222         [ #  # ]:          0 :                 LocalResourceAccess aStringResAccess( PAGE_GENERAL, RSC_TABPAGE );
     223 [ #  # ][ #  # ]:          0 :                 String sMessage = String(ModuleRes(STR_PARENTTITLE));
     224         [ #  # ]:          0 :                 sMessage.SearchAndReplaceAscii("#",sName);
     225 [ #  # ][ #  # ]:          0 :                 m_pAdminDialog->setTitle(sMessage);
         [ #  # ][ #  # ]
     226         [ #  # ]:          0 :             }
     227                 :            :         }
     228                 :          0 :     }
     229                 :            : 
     230                 :            :     //-------------------------------------------------------------------------
     231                 :          0 :     OGeneralPage::CreationMode OGeneralPage::GetDatabaseCreationMode() const
     232                 :            :     {
     233         [ #  # ]:          0 :         if ( m_aRB_CreateDatabase.IsChecked() )
     234                 :          0 :             return eCreateNew;
     235         [ #  # ]:          0 :         if ( m_aRB_GetExistingDatabase.IsChecked() )
     236                 :          0 :             return eConnectExternal;
     237                 :          0 :         return eOpenExisting;
     238                 :            :     }
     239                 :            : 
     240                 :            :     //-------------------------------------------------------------------------
     241                 :          0 :     void OGeneralPage::GetFocus()
     242                 :            :     {
     243                 :          0 :         OGenericAdministrationPage::GetFocus();
     244 [ #  # ][ #  # ]:          0 :         if ( m_pLB_DocumentList.get() && m_pLB_DocumentList->IsEnabled() )
                 [ #  # ]
     245                 :          0 :             m_pLB_DocumentList->GrabFocus();
     246 [ #  # ][ #  # ]:          0 :         else if (m_pDatasourceType.get() && m_pDatasourceType->IsEnabled())
                 [ #  # ]
     247                 :          0 :             m_pDatasourceType->GrabFocus();
     248                 :          0 :     }
     249                 :            : 
     250                 :            :     //-------------------------------------------------------------------------
     251                 :          0 :     void OGeneralPage::switchMessage(const ::rtl::OUString& _sURLPrefix)
     252                 :            :     {
     253                 :          0 :         SPECIAL_MESSAGE eMessage = smNone;
     254         [ #  # ]:          0 :         if ( _sURLPrefix.isEmpty()/*_eType == m_eNotSupportedKnownType*/ )
     255                 :            :         {
     256                 :          0 :             eMessage = smUnsupportedType;
     257                 :            :         }
     258                 :            : 
     259                 :            : 
     260         [ #  # ]:          0 :         if ( eMessage != m_eLastMessage )
     261                 :            :         {
     262                 :          0 :             sal_uInt16 nResId = 0;
     263         [ #  # ]:          0 :             if ( smUnsupportedType == eMessage )
     264                 :          0 :                 nResId = STR_UNSUPPORTED_DATASOURCE_TYPE;
     265         [ #  # ]:          0 :             String sMessage;
     266         [ #  # ]:          0 :             if ( nResId )
     267                 :            :             {
     268         [ #  # ]:          0 :                 LocalResourceAccess aStringResAccess( PAGE_GENERAL, RSC_TABPAGE );
     269 [ #  # ][ #  # ]:          0 :                 sMessage = String(ModuleRes(nResId));
         [ #  # ][ #  # ]
                 [ #  # ]
     270                 :            :             }
     271         [ #  # ]:          0 :             m_aSpecialMessage.SetText(sMessage);
     272                 :            : 
     273         [ #  # ]:          0 :             m_eLastMessage = eMessage;
     274                 :            :         }
     275                 :          0 :     }
     276                 :            : 
     277                 :            :     //-------------------------------------------------------------------------
     278                 :          0 :     void OGeneralPage::onTypeSelected(const ::rtl::OUString& _sURLPrefix)
     279                 :            :     {
     280                 :            :         // the the new URL text as indicated by the selection history
     281                 :          0 :         implSetCurrentType( _sURLPrefix );
     282                 :            : 
     283                 :          0 :         switchMessage(_sURLPrefix);
     284                 :            : 
     285         [ #  # ]:          0 :         if ( m_aTypeSelectHandler.IsSet() )
     286                 :          0 :             m_aTypeSelectHandler.Call(this);
     287                 :          0 :     }
     288                 :            : 
     289                 :            :     //-------------------------------------------------------------------------
     290                 :          0 :     void OGeneralPage::implInitControls(const SfxItemSet& _rSet, sal_Bool _bSaveValue)
     291                 :            :     {
     292         [ #  # ]:          0 :         initializeTypeList();
     293                 :            : 
     294                 :            :         // first check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa)
     295                 :            :         sal_Bool bValid, bReadonly;
     296         [ #  # ]:          0 :         getFlags(_rSet, bValid, bReadonly);
     297         [ #  # ]:          0 :         if (m_DBWizardMode)
     298                 :            :         {
     299         [ #  # ]:          0 :             m_aTypePreLabel.Hide();
     300         [ #  # ]:          0 :             m_aTypePostLabel.Hide();
     301         [ #  # ]:          0 :             m_aSpecialMessage.Hide();
     302         [ #  # ]:          0 :             SetControlFontWeight(&m_aFTHeaderText);
     303 [ #  # ][ #  # ]:          0 :             SetText(String());
                 [ #  # ]
     304                 :            : 
     305         [ #  # ]:          0 :             LayoutHelper::positionBelow( m_aRB_GetExistingDatabase, *m_pDatasourceType, RelatedControls, INDENT_BELOW_RADIO );
     306                 :            : 
     307 [ #  # ][ #  # ]:          0 :             if ( !bValid || bReadonly )
     308                 :            :             {
     309         [ #  # ]:          0 :                 m_aDatasourceTypeLabel.Enable( false );
     310         [ #  # ]:          0 :                 m_pDatasourceType->Enable( false );
     311         [ #  # ]:          0 :                 m_aFTDataSourceAppendix.Enable( false );
     312         [ #  # ]:          0 :                 m_aPB_OpenDocument.Enable( false );
     313         [ #  # ]:          0 :                 m_aFT_DocListLabel.Enable( false );
     314         [ #  # ]:          0 :                 m_pLB_DocumentList->Enable( false );
     315                 :            :             }
     316                 :            :             else
     317                 :            :             {
     318         [ #  # ]:          0 :                 m_aControlDependencies.enableOnRadioCheck( m_aRB_GetExistingDatabase, m_aDatasourceTypeLabel, *m_pDatasourceType, m_aFTDataSourceAppendix );
     319         [ #  # ]:          0 :                 m_aControlDependencies.enableOnRadioCheck( m_aRB_OpenDocument, m_aPB_OpenDocument, m_aFT_DocListLabel, *m_pLB_DocumentList );
     320                 :            :             }
     321                 :            : 
     322         [ #  # ]:          0 :             m_pLB_DocumentList->SetDropDownLineCount( 20 );
     323 [ #  # ][ #  # ]:          0 :             if ( m_pLB_DocumentList->GetEntryCount() )
     324         [ #  # ]:          0 :                 m_pLB_DocumentList->SelectEntryPos( 0 );
     325                 :            : 
     326         [ #  # ]:          0 :             m_aDatasourceTypeLabel.Hide();
     327         [ #  # ]:          0 :             m_aFTDataSourceAppendix.Hide();
     328                 :            : 
     329                 :          0 :             m_eOriginalCreationMode = GetDatabaseCreationMode();
     330                 :            :         }
     331                 :            :         else
     332                 :            :         {
     333         [ #  # ]:          0 :             m_aFT_DatasourceTypeHeader.Hide();
     334         [ #  # ]:          0 :             m_aRB_CreateDatabase.Hide();
     335         [ #  # ]:          0 :             m_aRB_GetExistingDatabase.Hide();
     336         [ #  # ]:          0 :             m_aRB_OpenDocument.Hide();
     337         [ #  # ]:          0 :             m_aPB_OpenDocument.Hide();
     338         [ #  # ]:          0 :             m_aFT_DocListLabel.Hide();
     339         [ #  # ]:          0 :             m_pLB_DocumentList->Hide();
     340         [ #  # ]:          0 :             m_aFTHeaderText.Hide();
     341         [ #  # ]:          0 :             m_aFTHelpText.Hide();
     342         [ #  # ]:          0 :             m_aTypePreLabel.Enable(bValid);
     343         [ #  # ]:          0 :             m_aTypePostLabel.Enable(bValid);
     344         [ #  # ]:          0 :             m_aDatasourceTypeLabel.Enable(bValid);
     345         [ #  # ]:          0 :             m_pDatasourceType->Enable(bValid);
     346                 :            :         }
     347                 :            :         // if the selection is invalid, disable evrything
     348 [ #  # ][ #  # ]:          0 :         String sName,sConnectURL;
     349                 :          0 :         m_bDisplayingInvalid = !bValid;
     350         [ #  # ]:          0 :         if ( bValid )
     351                 :            :         {
     352                 :            :             // collect some items and some values
     353 [ #  # ][ #  # ]:          0 :             SFX_ITEMSET_GET(_rSet, pNameItem, SfxStringItem, DSID_NAME, sal_True);
     354 [ #  # ][ #  # ]:          0 :             SFX_ITEMSET_GET(_rSet, pUrlItem, SfxStringItem, DSID_CONNECTURL, sal_True);
     355                 :            :             OSL_ENSURE(pUrlItem, "OGeneralPage::implInitControls : missing the type attribute !");
     356                 :            :             OSL_ENSURE(pNameItem, "OGeneralPage::implInitControls : missing the type attribute !");
     357         [ #  # ]:          0 :             sName = pNameItem->GetValue();
     358         [ #  # ]:          0 :             sConnectURL = pUrlItem->GetValue();
     359                 :            :         }
     360                 :            : 
     361                 :          0 :         ::rtl::OUString eOldSelection = m_eCurrentSelection;
     362                 :          0 :         m_eNotSupportedKnownType =  ::dbaccess::DST_UNKNOWN;
     363                 :          0 :         implSetCurrentType(  ::rtl::OUString() );
     364                 :            : 
     365                 :            :         // compare the DSN prefix with the registered ones
     366         [ #  # ]:          0 :         String sDisplayName;
     367                 :            : 
     368 [ #  # ][ #  # ]:          0 :         if (m_pCollection && bValid)
     369                 :            :         {
     370 [ #  # ][ #  # ]:          0 :             implSetCurrentType( m_pCollection->getPrefix(sConnectURL) );
         [ #  # ][ #  # ]
     371 [ #  # ][ #  # ]:          0 :             sDisplayName = m_pCollection->getTypeDisplayName(m_eCurrentSelection);
                 [ #  # ]
     372                 :            :         }
     373                 :            : 
     374                 :            :         // select the correct datasource type
     375 [ #  # ][ #  # ]:          0 :         if  (   approveDataSourceType( m_eCurrentSelection, sDisplayName )
         [ #  # ][ #  # ]
     376         [ #  # ]:          0 :             &&  ( LISTBOX_ENTRY_NOTFOUND == m_pDatasourceType->GetEntryPos( sDisplayName ) )
     377                 :            :             )
     378                 :            :         {   // this indicates it's really a type which is known in general, but not supported on the current platform
     379                 :            :             // show a message saying so
     380                 :            :             //  eSpecialMessage = smUnsupportedType;
     381 [ #  # ][ #  # ]:          0 :             insertDatasourceTypeEntryData(m_eCurrentSelection, sDisplayName);
                 [ #  # ]
     382                 :            :             // remember this type so we can show the special message again if the user selects this
     383                 :            :             // type again (without changing the data source)
     384 [ #  # ][ #  # ]:          0 :             m_eNotSupportedKnownType = m_pCollection->determineType(m_eCurrentSelection);
                 [ #  # ]
     385                 :            :         }
     386                 :            : 
     387 [ #  # ][ #  # ]:          0 :         if (m_aRB_CreateDatabase.IsChecked() && m_DBWizardMode)
                 [ #  # ]
     388 [ #  # ][ #  # ]:          0 :             sDisplayName = m_pCollection->getTypeDisplayName( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("jdbc:")));
         [ #  # ][ #  # ]
     389         [ #  # ]:          0 :         m_pDatasourceType->SelectEntry(sDisplayName);
     390                 :            : 
     391                 :            :         // notify our listener that our type selection has changed (if so)
     392         [ #  # ]:          0 :         if ( eOldSelection != m_eCurrentSelection )
     393                 :            :         {
     394         [ #  # ]:          0 :             setParentTitle(m_eCurrentSelection);
     395         [ #  # ]:          0 :             onTypeSelected(m_eCurrentSelection);
     396                 :            :         }
     397                 :            : 
     398                 :            :         // a special message for the current page state
     399         [ #  # ]:          0 :         switchMessage(m_eCurrentSelection);
     400                 :            : 
     401 [ #  # ][ #  # ]:          0 :         OGenericAdministrationPage::implInitControls(_rSet, _bSaveValue);
         [ #  # ][ #  # ]
     402                 :          0 :     }
     403                 :            : 
     404                 :            : 
     405                 :            :     // For the databaseWizard we only have one entry for the MySQL Database,
     406                 :            :     // because we have a seperate tabpage to retrieve the respective datasource type
     407                 :            :     // ( ::dbaccess::DST_MYSQL_ODBC ||  ::dbaccess::DST_MYSQL_JDBC). Therefore we use  ::dbaccess::DST_MYSQL_JDBC as a temporary
     408                 :            :     // representative for all MySQl databases)
     409                 :            :     // Also, embedded databases (embedded HSQL, at the moment), are not to appear in the list of
     410                 :            :     // databases to connect to.
     411                 :          0 :     bool OGeneralPage::approveDataSourceType( const ::rtl::OUString& _sURLPrefix, String& _inout_rDisplayName )
     412                 :            :     {
     413         [ #  # ]:          0 :         const ::dbaccess::DATASOURCE_TYPE eType = m_pCollection->determineType(_sURLPrefix);
     414                 :            : 
     415         [ #  # ]:          0 :         if ( m_DBWizardMode )
     416                 :            :         {
     417      [ #  #  # ]:          0 :             switch ( eType )
     418                 :            :             {
     419                 :            :             case ::dbaccess::DST_MYSQL_JDBC:
     420                 :          0 :                 _inout_rDisplayName = m_sMySQLEntry;
     421                 :          0 :                 break;
     422                 :            :             case ::dbaccess::DST_MYSQL_ODBC:
     423                 :            :             case ::dbaccess::DST_MYSQL_NATIVE:
     424                 :            :                 // don't display those, the decision whether the user connects via JDBC/ODBC/C-OOo is made on another
     425                 :            :                 // page
     426         [ #  # ]:          0 :                 _inout_rDisplayName = String();
     427                 :          0 :                 break;
     428                 :            :             default:
     429                 :          0 :                 break;
     430                 :            :             }
     431                 :            :         }
     432                 :            : 
     433         [ #  # ]:          0 :         if ( eType == ::dbaccess::DST_MYSQL_NATIVE_DIRECT )
     434                 :            :         {
     435                 :            :             // do not display the Connector/OOo driver itself, it is always wrapped via the MySQL-Driver, if
     436                 :            :             // this driver is installed
     437         [ #  # ]:          0 :             if ( m_pCollection->hasDriver( "sdbc:mysql:mysqlc:" ) )
     438         [ #  # ]:          0 :                 _inout_rDisplayName = String();
     439                 :            :         }
     440                 :            : 
     441         [ #  # ]:          0 :         if ( eType ==  ::dbaccess::DST_EMBEDDED_HSQLDB )
     442         [ #  # ]:          0 :             _inout_rDisplayName = String();
     443                 :            : 
     444                 :          0 :         return _inout_rDisplayName.Len() > 0;
     445                 :            :     }
     446                 :            : 
     447                 :            : 
     448                 :            :     // -----------------------------------------------------------------------
     449                 :          0 :     void OGeneralPage::insertDatasourceTypeEntryData(const ::rtl::OUString& _sType, String sDisplayName)
     450                 :            :     {
     451                 :            :         // insert a (temporary) entry
     452                 :          0 :         sal_uInt16 nPos = m_pDatasourceType->InsertEntry(sDisplayName);
     453         [ #  # ]:          0 :         if ( nPos >= m_aURLPrefixes.size() )
     454                 :          0 :             m_aURLPrefixes.resize(nPos+1);
     455                 :          0 :         m_aURLPrefixes[nPos] = _sType;
     456                 :          0 :     }
     457                 :            : 
     458                 :            :     // -----------------------------------------------------------------------
     459                 :          0 :     void OGeneralPage::fillWindows(::std::vector< ISaveValueWrapper* >& _rControlList)
     460                 :            :     {
     461 [ #  # ][ #  # ]:          0 :         _rControlList.push_back(new ODisableWrapper<FixedText>(&m_aTypePreLabel));
     462 [ #  # ][ #  # ]:          0 :         _rControlList.push_back(new ODisableWrapper<FixedText>(&m_aDatasourceTypeLabel));
     463 [ #  # ][ #  # ]:          0 :         _rControlList.push_back(new ODisableWrapper<FixedText>(&m_aTypePostLabel));
     464 [ #  # ][ #  # ]:          0 :         _rControlList.push_back(new ODisableWrapper<FixedText>(&m_aSpecialMessage));
     465 [ #  # ][ #  # ]:          0 :         _rControlList.push_back(new ODisableWrapper<FixedText>(&m_aFTDataSourceAppendix));
     466                 :          0 :     }
     467                 :            :     // -----------------------------------------------------------------------
     468                 :          0 :     void OGeneralPage::fillControls(::std::vector< ISaveValueWrapper* >& _rControlList)
     469                 :            :     {
     470 [ #  # ][ #  # ]:          0 :         _rControlList.push_back(new OSaveValueWrapper<ListBox>(m_pDatasourceType.get()));
     471                 :          0 :     }
     472                 :            : 
     473                 :            :     //-------------------------------------------------------------------------
     474                 :          0 :     SfxTabPage* OGeneralPage::Create(Window* _pParent, const SfxItemSet& _rAttrSet, sal_Bool _bWizardMode)
     475                 :            :     {
     476         [ #  # ]:          0 :            return ( new OGeneralPage( _pParent, _rAttrSet, _bWizardMode ) );
     477                 :            :     }
     478                 :            : 
     479                 :            :     //-------------------------------------------------------------------------
     480                 :          0 :     void OGeneralPage::implSetCurrentType( const ::rtl::OUString& _eType )
     481                 :            :     {
     482         [ #  # ]:          0 :         if ( _eType == m_eCurrentSelection )
     483                 :          0 :             return;
     484                 :            : 
     485                 :          0 :         m_eCurrentSelection = _eType;
     486                 :            :     }
     487                 :            : 
     488                 :            :     //-------------------------------------------------------------------------
     489                 :          0 :     void OGeneralPage::Reset(const SfxItemSet& _rCoreAttrs)
     490                 :            :     {
     491                 :            :         // reset all locale data
     492                 :          0 :         implSetCurrentType(  ::rtl::OUString() );
     493                 :            :             // this ensures that our type selection link will be called, even if the new is is the same as the
     494                 :            :             // current one
     495                 :          0 :         OGenericAdministrationPage::Reset(_rCoreAttrs);
     496                 :          0 :     }
     497                 :            : 
     498                 :            :     //-------------------------------------------------------------------------
     499                 :          0 :     sal_Bool OGeneralPage::FillItemSet(SfxItemSet& _rCoreAttrs)
     500                 :            :     {
     501                 :          0 :         sal_Bool bChangedSomething = sal_False;
     502                 :            : 
     503                 :          0 :         bool bCommitTypeSelection = true;
     504         [ #  # ]:          0 :         if ( m_DBWizardMode )
     505                 :            :         {
     506         [ #  # ]:          0 :             if ( m_aRB_CreateDatabase.IsChecked() )
     507                 :            :             {
     508 [ #  # ][ #  # ]:          0 :                 _rCoreAttrs.Put(SfxStringItem(DSID_CONNECTURL, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:dbase:"))));
         [ #  # ][ #  # ]
                 [ #  # ]
     509                 :          0 :                 bChangedSomething = sal_True;
     510                 :          0 :                 bCommitTypeSelection = false;
     511                 :            :             }
     512         [ #  # ]:          0 :             else if ( m_aRB_OpenDocument.IsChecked() )
     513                 :            :             {
     514         [ #  # ]:          0 :                 if ( m_aRB_OpenDocument.GetSavedValue() != m_aRB_OpenDocument.IsChecked() )
     515                 :          0 :                     bChangedSomething = sal_True;
     516                 :            : 
     517                 :            :                 // TODO
     518                 :          0 :                 bCommitTypeSelection = false;
     519                 :            :             }
     520                 :            :         }
     521                 :            : 
     522         [ #  # ]:          0 :         if ( bCommitTypeSelection )
     523                 :            :         {
     524         [ #  # ]:          0 :             sal_uInt16 nEntry = m_pDatasourceType->GetSelectEntryPos();
     525                 :          0 :             ::rtl::OUString sURLPrefix = m_aURLPrefixes[nEntry];
     526         [ #  # ]:          0 :             if (m_DBWizardMode)
     527                 :            :             {
     528   [ #  #  #  # ]:          0 :                 if  (  ( m_pDatasourceType->GetSavedValue() != nEntry )
                 [ #  # ]
     529                 :          0 :                     || ( GetDatabaseCreationMode() != m_eOriginalCreationMode )
     530                 :            :                     )
     531                 :            :                 {
     532 [ #  # ][ #  # ]:          0 :                     _rCoreAttrs.Put(SfxStringItem(DSID_CONNECTURL,sURLPrefix ));
         [ #  # ][ #  # ]
                 [ #  # ]
     533                 :          0 :                     bChangedSomething = sal_True;
     534                 :            :                 }
     535                 :            :                 else
     536                 :          0 :                     implSetCurrentType(sURLPrefix);
     537                 :            :             }
     538                 :            :             else
     539                 :            :             {
     540         [ #  # ]:          0 :                 if ( m_pDatasourceType->GetSavedValue() != nEntry)
     541                 :            :                 {
     542 [ #  # ][ #  # ]:          0 :                     _rCoreAttrs.Put(SfxStringItem(DSID_CONNECTURL, sURLPrefix));
         [ #  # ][ #  # ]
                 [ #  # ]
     543                 :          0 :                     bChangedSomething = sal_True;
     544                 :            :                 }
     545                 :          0 :             }
     546                 :            :         }
     547                 :          0 :         return bChangedSomething;
     548                 :            :     }
     549                 :            : 
     550                 :            :     //-------------------------------------------------------------------------
     551                 :          0 :     IMPL_LINK(OGeneralPage, OnDatasourceTypeSelected, ListBox*, _pBox)
     552                 :            :     {
     553                 :            :         // get the type from the entry data
     554         [ #  # ]:          0 :         sal_Int16 nSelected = _pBox->GetSelectEntryPos();
     555                 :          0 :         const ::rtl::OUString sURLPrefix = m_aURLPrefixes[nSelected];
     556                 :            : 
     557         [ #  # ]:          0 :         setParentTitle(sURLPrefix);
     558                 :            :         // let the impl method do all the stuff
     559         [ #  # ]:          0 :         onTypeSelected(sURLPrefix);
     560                 :            :         // tell the listener we were modified
     561         [ #  # ]:          0 :         callModifiedHdl();
     562                 :            :         // outta here
     563                 :          0 :         return 0L;
     564                 :            :     }
     565                 :            : 
     566                 :            :     //-------------------------------------------------------------------------
     567                 :          0 :     OGeneralPage::DocumentDescriptor OGeneralPage::GetSelectedDocument() const
     568                 :            :     {
     569                 :          0 :         DocumentDescriptor aDocument;
     570         [ #  # ]:          0 :         if ( m_aBrowsedDocument.sURL.Len() )
     571         [ #  # ]:          0 :             aDocument = m_aBrowsedDocument;
     572                 :            :         else
     573                 :            :         {
     574 [ #  # ][ #  # ]:          0 :             aDocument.sURL = m_pLB_DocumentList->GetSelectedDocumentURL();
                 [ #  # ]
     575 [ #  # ][ #  # ]:          0 :             aDocument.sFilter = m_pLB_DocumentList->GetSelectedDocumentFilter();
                 [ #  # ]
     576                 :            :         }
     577                 :          0 :         return aDocument;
     578                 :            :     }
     579                 :            : 
     580                 :            :     //-------------------------------------------------------------------------
     581                 :          0 :     IMPL_LINK(OGeneralPage, OnSetupModeSelected, RadioButton*, /*_pBox*/)
     582                 :            :     {
     583         [ #  # ]:          0 :         if ( m_aCreationModeHandler.IsSet() )
     584                 :          0 :             m_aCreationModeHandler.Call(this);
     585                 :          0 :         return 1L;
     586                 :            :     }
     587                 :            : 
     588                 :            :     //-------------------------------------------------------------------------
     589                 :          0 :     IMPL_LINK(OGeneralPage, OnDocumentSelected, ListBox*, /*_pBox*/)
     590                 :            :     {
     591                 :          0 :         m_aDocumentSelectionHandler.Call( this );
     592                 :          0 :         return 0L;
     593                 :            :     }
     594                 :            : 
     595                 :            :     //-------------------------------------------------------------------------
     596                 :          0 :     IMPL_LINK(OGeneralPage, OnOpenDocument, PushButton*, /*_pBox*/)
     597                 :            :     {
     598                 :            :         ::sfx2::FileDialogHelper aFileDlg(
     599                 :            :                 ui::dialogs::TemplateDescription::FILEOPEN_READONLY_VERSION,
     600 [ #  # ][ #  # ]:          0 :                 0, rtl::OUString::createFromAscii("sdatabase") );
                 [ #  # ]
     601         [ #  # ]:          0 :         const SfxFilter* pFilter = getStandardDatabaseFilter();
     602         [ #  # ]:          0 :         if ( pFilter )
     603                 :            :         {
     604         [ #  # ]:          0 :             aFileDlg.SetCurrentFilter(pFilter->GetUIName());
     605                 :            :         }
     606 [ #  # ][ #  # ]:          0 :         if ( aFileDlg.Execute() == ERRCODE_NONE )
     607                 :            :         {
     608         [ #  # ]:          0 :             String sPath = aFileDlg.GetPath();
     609 [ #  # ][ #  # ]:          0 :             if ( aFileDlg.GetCurrentFilter() != pFilter->GetUIName() || !pFilter->GetWildcard().Matches(sPath) )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
           [ #  #  #  # ]
     610                 :            :             {
     611 [ #  # ][ #  # ]:          0 :                 String sMessage(ModuleRes(STR_ERR_USE_CONNECT_TO));
     612         [ #  # ]:          0 :                 InfoBox aError(this, sMessage);
     613         [ #  # ]:          0 :                 aError.Execute();
     614         [ #  # ]:          0 :                 m_aRB_GetExistingDatabase.Check();
     615         [ #  # ]:          0 :                 OnSetupModeSelected(&m_aRB_GetExistingDatabase);
     616 [ #  # ][ #  # ]:          0 :                 return 0L;
     617                 :            :             }
     618         [ #  # ]:          0 :             m_aBrowsedDocument.sURL = sPath;
     619 [ #  # ][ #  # ]:          0 :             m_aBrowsedDocument.sFilter = String();
                 [ #  # ]
     620         [ #  # ]:          0 :             m_aChooseDocumentHandler.Call( this );
     621         [ #  # ]:          0 :             return 1L;
     622                 :            :         }
     623                 :            : 
     624         [ #  # ]:          0 :         return 0L;
     625                 :            :     }
     626                 :            : 
     627                 :            : //.........................................................................
     628                 :            : }   // namespace dbaui
     629                 :            : //.........................................................................
     630                 :            : 
     631                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10