LCOV - code coverage report
Current view: top level - dbaccess/source/ui/dlg - ConnectionPage.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 154 0.0 %
Date: 2014-04-14 Functions: 0 15 0.0 %
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 <config_features.h>
      21             : #include "ConnectionPage.hxx"
      22             : #include "ConnectionPage.hrc"
      23             : #include "dbu_dlg.hrc"
      24             : #include "dsmeta.hxx"
      25             : #if HAVE_FEATURE_JAVA
      26             : #include <jvmaccess/virtualmachine.hxx>
      27             : #endif
      28             : #include <svl/itemset.hxx>
      29             : #include <unotools/pathoptions.hxx>
      30             : #include <svl/stritem.hxx>
      31             : #include <svl/eitem.hxx>
      32             : #include <svl/intitem.hxx>
      33             : #include <unotools/moduleoptions.hxx>
      34             : #include "dsitems.hxx"
      35             : #include "dbaccess_helpid.hrc"
      36             : #include "localresaccess.hxx"
      37             : #include <osl/process.h>
      38             : #include <vcl/msgbox.hxx>
      39             : #include "dbadmin.hxx"
      40             : #include <comphelper/types.hxx>
      41             : #include <vcl/stdtext.hxx>
      42             : #include "sqlmessage.hxx"
      43             : #include "odbcconfig.hxx"
      44             : #include "dsselect.hxx"
      45             : #include <svl/filenotation.hxx>
      46             : #include "dbustrings.hrc"
      47             : #include <com/sun/star/sdbc/XRow.hpp>
      48             : #include <com/sun/star/awt/XWindow.hpp>
      49             : #include <com/sun/star/task/XInteractionHandler.hpp>
      50             : #include <com/sun/star/ucb/XProgressHandler.hpp>
      51             : #include <com/sun/star/sdbc/XConnection.hpp>
      52             : #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
      53             : #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
      54             : #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
      55             : #include "UITools.hxx"
      56             : #include <unotools/localfilehelper.hxx>
      57             : #include <unotools/ucbhelper.hxx>
      58             : #include <ucbhelper/commandenvironment.hxx>
      59             : #include "finteraction.hxx"
      60             : #include <connectivity/CommonTools.hxx>
      61             : #include <sfx2/docfilt.hxx>
      62             : #include "dsnItem.hxx"
      63             : #if defined(WNT)
      64             : #define _ADO_DATALINK_BROWSE_
      65             : #endif
      66             : 
      67             : #ifdef _ADO_DATALINK_BROWSE_
      68             : #include <vcl/sysdata.hxx>
      69             : #include "adodatalinks.hxx"
      70             : #endif //_ADO_DATALINK_BROWSE_
      71             : 
      72             : #include "AutoControls.hrc"
      73             : 
      74             : namespace dbaui
      75             : {
      76             :     using namespace ::com::sun::star::uno;
      77             :     using namespace ::com::sun::star::ucb;
      78             :     using namespace ::com::sun::star::ui::dialogs;
      79             :     using namespace ::com::sun::star::sdbc;
      80             :     using namespace ::com::sun::star::beans;
      81             :     using namespace ::com::sun::star::lang;
      82             :     using namespace ::com::sun::star::container;
      83             :     using namespace ::dbtools;
      84             :     using namespace ::svt;
      85             : 
      86           0 :     SfxTabPage* OConnectionTabPage::Create( Window* pParent,    const SfxItemSet& _rAttrSet )
      87             :     {
      88           0 :         return ( new OConnectionTabPage( pParent, _rAttrSet ) );
      89             :     }
      90             :     // OConnectionTabPage
      91           0 :     OConnectionTabPage::OConnectionTabPage(Window* pParent, const SfxItemSet& _rCoreAttrs)
      92             :         :OConnectionHelper(pParent, ModuleRes(PAGE_CONNECTION), _rCoreAttrs)
      93             :         ,m_aFL1(this, ModuleRes(FL_SEPARATOR1))
      94             :         ,m_aFL2(this, ModuleRes(FL_SEPARATOR2))
      95             :         ,m_aUserNameLabel(this, ModuleRes(FT_USERNAME))
      96             :         ,m_aUserName(this, ModuleRes(ET_USERNAME))
      97             :         ,m_aPasswordRequired(this, ModuleRes(CB_PASSWORD_REQUIRED))
      98             :         ,m_aFL3(this, ModuleRes(FL_SEPARATOR3))
      99             :         ,m_aJavaDriverLabel(this, ModuleRes(FT_JDBCDRIVERCLASS))
     100             :         ,m_aJavaDriver(this, ModuleRes(ET_JDBCDRIVERCLASS))
     101             :         ,m_aTestJavaDriver(this, ModuleRes(PB_TESTDRIVERCLASS))
     102           0 :         ,m_aTestConnection(this, ModuleRes(PB_TESTCONNECTION))
     103             :     {
     104           0 :         m_aConnectionURL.SetModifyHdl(LINK(this, OConnectionTabPage, OnEditModified));
     105           0 :         m_aJavaDriver.SetModifyHdl(getControlModifiedLink());
     106           0 :         m_aJavaDriver.SetModifyHdl(LINK(this, OConnectionTabPage, OnEditModified));
     107           0 :         m_aUserName.SetModifyHdl(getControlModifiedLink());
     108           0 :         m_aPasswordRequired.SetClickHdl(getControlModifiedLink());
     109             : 
     110           0 :         m_aTestConnection.SetClickHdl(LINK(this,OGenericAdministrationPage,OnTestConnectionClickHdl));
     111           0 :         m_aTestJavaDriver.SetClickHdl(LINK(this,OConnectionTabPage,OnTestJavaClickHdl));
     112             : 
     113           0 :         FreeResource();
     114             : 
     115           0 :         LayoutHelper::fitSizeRightAligned( m_aTestConnection );
     116           0 :     }
     117             : 
     118           0 :     OConnectionTabPage::~OConnectionTabPage()
     119             :     {
     120           0 :     }
     121             : 
     122           0 :     void OConnectionTabPage::implInitControls(const SfxItemSet& _rSet, sal_Bool _bSaveValue)
     123             :     {
     124             :         // check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa)
     125             :         sal_Bool bValid, bReadonly;
     126           0 :         getFlags(_rSet, bValid, bReadonly);
     127             : 
     128           0 :         m_eType = m_pAdminDialog->getDatasourceType(_rSet);
     129           0 :         OConnectionHelper::implInitControls( _rSet, _bSaveValue);
     130             : 
     131           0 :         LocalResourceAccess aLocRes( PAGE_CONNECTION, RSC_TABPAGE );
     132           0 :         ::dbaccess::DATASOURCE_TYPE eType = m_pCollection->determineType(m_eType);
     133           0 :         switch( eType )
     134             :         {
     135             :             case  ::dbaccess::DST_DBASE:
     136           0 :                 m_aFT_Connection.SetText(OUString(ModuleRes(STR_DBASE_PATH_OR_FILE)));
     137           0 :                 m_aConnectionURL.SetHelpId(HID_DSADMIN_DBASE_PATH);
     138           0 :                 break;
     139             :             case  ::dbaccess::DST_FLAT:
     140           0 :                 m_aFT_Connection.SetText(OUString(ModuleRes(STR_FLAT_PATH_OR_FILE)));
     141           0 :                 m_aConnectionURL.SetHelpId(HID_DSADMIN_FLAT_PATH);
     142           0 :                 break;
     143             :             case  ::dbaccess::DST_CALC:
     144           0 :                 m_aFT_Connection.SetText(OUString(ModuleRes(STR_CALC_PATH_OR_FILE)));
     145           0 :                 m_aConnectionURL.SetHelpId(HID_DSADMIN_CALC_PATH);
     146           0 :                 break;
     147             :             case  ::dbaccess::DST_ADO:
     148           0 :                 m_aFT_Connection.SetText(OUString(ModuleRes(STR_COMMONURL)));
     149           0 :                 break;
     150             :             case  ::dbaccess::DST_MSACCESS:
     151             :             case  ::dbaccess::DST_MSACCESS_2007:
     152           0 :                 m_aFT_Connection.SetText(OUString(ModuleRes(STR_MSACCESS_MDB_FILE)));
     153           0 :                 m_aConnectionURL.SetHelpId(HID_DSADMIN_MSACCESS_MDB_FILE);
     154           0 :                 break;
     155             :             case  ::dbaccess::DST_MYSQL_NATIVE:
     156             :             case  ::dbaccess::DST_MYSQL_JDBC:
     157           0 :                 m_aFT_Connection.SetText(OUString(ModuleRes(STR_MYSQL_DATABASE_NAME)));
     158           0 :                 m_aConnectionURL.SetHelpId( HID_DSADMIN_MYSQL_DATABASE );
     159           0 :                 break;
     160             :             case  ::dbaccess::DST_ORACLE_JDBC:
     161           0 :                 m_aFT_Connection.SetText(OUString(ModuleRes(STR_ORACLE_DATABASE_NAME)));
     162           0 :                 m_aConnectionURL.SetHelpId(HID_DSADMIN_ORACLE_DATABASE);
     163           0 :                 break;
     164             :             case  ::dbaccess::DST_MYSQL_ODBC:
     165             :             case  ::dbaccess::DST_ODBC:
     166           0 :                 m_aFT_Connection.SetText(OUString(ModuleRes(STR_NAME_OF_ODBC_DATASOURCE)));
     167           0 :                 m_aConnectionURL.SetHelpId( eType ==  ::dbaccess::DST_MYSQL_ODBC ? HID_DSADMIN_MYSQL_ODBC_DATASOURCE : HID_DSADMIN_ODBC_DATASOURCE);
     168           0 :                 break;
     169             :             case  ::dbaccess::DST_LDAP:
     170           0 :                 m_aFT_Connection.SetText(OUString(ModuleRes(STR_HOSTNAME)));
     171           0 :                 m_aConnectionURL.SetHelpId( HID_DSADMIN_LDAP_HOSTNAME );
     172           0 :                 break;
     173             :             case  ::dbaccess::DST_MOZILLA:
     174           0 :                 m_aFT_Connection.SetText(OUString(ModuleRes(STR_MOZILLA_PROFILE_NAME)));
     175           0 :                 m_aConnectionURL.SetHelpId( HID_DSADMIN_MOZILLA_PROFILE_NAME );
     176           0 :                 break;
     177             :             case  ::dbaccess::DST_THUNDERBIRD:
     178           0 :                 m_aFT_Connection.SetText(OUString(ModuleRes(STR_THUNDERBIRD_PROFILE_NAME)));
     179           0 :                 m_aConnectionURL.SetHelpId( HID_DSADMIN_THUNDERBIRD_PROFILE_NAME );
     180           0 :                 break;
     181             :             case  ::dbaccess::DST_OUTLOOK:
     182             :             case  ::dbaccess::DST_OUTLOOKEXP:
     183             :             case  ::dbaccess::DST_EVOLUTION:
     184             :             case  ::dbaccess::DST_EVOLUTION_GROUPWISE:
     185             :             case  ::dbaccess::DST_EVOLUTION_LDAP:
     186             :             case  ::dbaccess::DST_KAB:
     187             :             case  ::dbaccess::DST_MACAB:
     188           0 :                 m_aFT_Connection.SetText(OUString(ModuleRes(STR_NO_ADDITIONAL_SETTINGS)));
     189             :                 {
     190           0 :                     OUString sText = m_aFT_Connection.GetText();
     191           0 :                     sText = sText.replaceAll("%test",m_aTestConnection.GetText());
     192           0 :                     OUString sTemp;
     193           0 :                     sText = sText.replaceAll("~",sTemp);
     194           0 :                     m_aFT_Connection.SetText(sText);
     195             :                 }
     196           0 :                 m_aConnectionURL.Hide();
     197           0 :                 break;
     198             :             case  ::dbaccess::DST_JDBC:
     199             :             default:
     200           0 :                 m_aFT_Connection.SetText(OUString(ModuleRes(STR_COMMONURL)));
     201           0 :                 break;
     202             :         }
     203             : 
     204             :         ;
     205           0 :         AuthenticationMode eAuthMode( DataSourceMetaData::getAuthentication( m_eType ) );
     206           0 :         bool bShowUserAuthenfication = ( eAuthMode != AuthNone );
     207           0 :         bool bShowUser = ( eAuthMode == AuthUserPwd );
     208             : 
     209           0 :         m_aPB_Connection.SetHelpId(HID_DSADMIN_BROWSECONN);
     210           0 :         m_aFL2.Show( bShowUserAuthenfication );
     211           0 :         m_aUserNameLabel.Show( bShowUser && bShowUserAuthenfication );
     212           0 :         m_aUserName.Show( bShowUser && bShowUserAuthenfication );
     213           0 :         m_aPasswordRequired.Show( bShowUserAuthenfication );
     214           0 :         if ( !bShowUser && bShowUserAuthenfication )
     215           0 :             m_aPasswordRequired.SetPosPixel(m_aUserNameLabel.GetPosPixel());
     216             : 
     217             :         // collect the items
     218           0 :         SFX_ITEMSET_GET(_rSet, pUidItem, SfxStringItem, DSID_USER, true);
     219             : 
     220           0 :         SFX_ITEMSET_GET(_rSet, pJdbcDrvItem, SfxStringItem, DSID_JDBCDRIVERCLASS, true);
     221           0 :         SFX_ITEMSET_GET(_rSet, pUrlItem, SfxStringItem, DSID_CONNECTURL, true);
     222           0 :         SFX_ITEMSET_GET(_rSet, pAllowEmptyPwd, SfxBoolItem, DSID_PASSWORDREQUIRED, true);
     223             : 
     224             :         // forward the values to the controls
     225           0 :         if ( bValid )
     226             :         {
     227           0 :             m_aUserName.SetText(pUidItem->GetValue());
     228           0 :             m_aPasswordRequired.Check(pAllowEmptyPwd->GetValue());
     229             : 
     230           0 :             OUString sUrl = pUrlItem->GetValue();
     231           0 :             setURL( sUrl );
     232             : 
     233           0 :             const sal_Bool bEnableJDBC = m_pCollection->determineType(m_eType) == ::dbaccess::DST_JDBC;
     234           0 :             if ( !pJdbcDrvItem->GetValue().getLength() )
     235             :             {
     236           0 :                 OUString sDefaultJdbcDriverName = m_pCollection->getJavaDriverClass(m_eType);
     237           0 :                 if ( !sDefaultJdbcDriverName.isEmpty() )
     238             :                 {
     239           0 :                     m_aJavaDriver.SetText(sDefaultJdbcDriverName);
     240           0 :                     m_aJavaDriver.SetModifyFlag();
     241           0 :                 }
     242             :             }
     243             :             else
     244           0 :                 m_aJavaDriver.SetText(pJdbcDrvItem->GetValue());
     245             : 
     246           0 :             m_aJavaDriverLabel.Show(bEnableJDBC);
     247           0 :             m_aJavaDriver.Show(bEnableJDBC);
     248           0 :             m_aTestJavaDriver.Show(bEnableJDBC);
     249           0 :             m_aTestJavaDriver.Enable( !m_aJavaDriver.GetText().isEmpty() );
     250           0 :             m_aFL3.Show(bEnableJDBC);
     251             : 
     252           0 :             checkTestConnection();
     253             : 
     254           0 :             m_aUserName.ClearModifyFlag();
     255           0 :             m_aConnectionURL.ClearModifyFlag();
     256           0 :             m_aJavaDriver.ClearModifyFlag();
     257           0 :         }
     258           0 :     }
     259           0 :     void OConnectionTabPage::fillWindows(::std::vector< ISaveValueWrapper* >& _rControlList)
     260             :     {
     261           0 :         _rControlList.push_back(new ODisableWrapper<FixedLine>(&m_aFL1));
     262             : 
     263           0 :         _rControlList.push_back(new ODisableWrapper<FixedLine>(&m_aFL2));
     264           0 :         _rControlList.push_back(new ODisableWrapper<FixedText>(&m_aJavaDriverLabel));
     265           0 :         _rControlList.push_back(new ODisableWrapper<PushButton>(&m_aTestJavaDriver));
     266             : 
     267           0 :         _rControlList.push_back(new ODisableWrapper<FixedLine>(&m_aFL3));
     268           0 :         _rControlList.push_back(new ODisableWrapper<FixedText>(&m_aUserNameLabel));
     269           0 :         _rControlList.push_back(new ODisableWrapper<PushButton>(&m_aTestConnection));
     270           0 :         OConnectionHelper::fillWindows(_rControlList);
     271             : 
     272           0 :     }
     273           0 :     void OConnectionTabPage::fillControls(::std::vector< ISaveValueWrapper* >& _rControlList)
     274             :     {
     275           0 :         _rControlList.push_back(new OSaveValueWrapper<Edit>(&m_aJavaDriver));
     276           0 :         _rControlList.push_back(new OSaveValueWrapper<Edit>(&m_aUserName));
     277           0 :         _rControlList.push_back(new OSaveValueWrapper<CheckBox>(&m_aPasswordRequired));
     278           0 :         OConnectionHelper::fillControls(_rControlList);
     279           0 :     }
     280             : 
     281           0 :     bool OConnectionTabPage::FillItemSet(SfxItemSet& _rSet)
     282             :     {
     283           0 :         sal_Bool bChangedSomething = sal_False;
     284             : 
     285           0 :         if (m_aUserName.GetText() != m_aUserName.GetSavedValue())
     286             :         {
     287           0 :             _rSet.Put(SfxStringItem(DSID_USER, m_aUserName.GetText()));
     288           0 :             _rSet.Put(SfxStringItem(DSID_PASSWORD, OUString()));
     289           0 :             bChangedSomething = sal_True;
     290             :         }
     291             : 
     292           0 :         fillBool(_rSet,&m_aPasswordRequired,DSID_PASSWORDREQUIRED,bChangedSomething);
     293             : 
     294           0 :         if ( m_pCollection->determineType(m_eType) ==  ::dbaccess::DST_JDBC )
     295             :         {
     296           0 :             fillString(_rSet,&m_aJavaDriver, DSID_JDBCDRIVERCLASS, bChangedSomething);
     297             :         }
     298             : 
     299           0 :         fillString(_rSet,&m_aConnectionURL, DSID_CONNECTURL, bChangedSomething);
     300             : 
     301           0 :         return bChangedSomething;
     302             :     }
     303           0 :     IMPL_LINK(OConnectionTabPage, OnTestJavaClickHdl, PushButton*, /*_pButton*/)
     304             :     {
     305             :         OSL_ENSURE(m_pAdminDialog,"No Admin dialog set! ->GPF");
     306           0 :         sal_Bool bSuccess = sal_False;
     307             : #if HAVE_FEATURE_JAVA
     308             :         try
     309             :         {
     310           0 :             if ( !m_aJavaDriver.GetText().isEmpty() )
     311             :             {
     312           0 :                 ::rtl::Reference< jvmaccess::VirtualMachine > xJVM = ::connectivity::getJavaVM( m_pAdminDialog->getORB() );
     313           0 :                 bSuccess = ::connectivity::existsJavaClassByName(xJVM,m_aJavaDriver.GetText());
     314             :             }
     315             :         }
     316           0 :         catch(Exception&)
     317             :         {
     318             :         }
     319             : #endif
     320             : 
     321           0 :         const sal_uInt16 nMessage = bSuccess ? STR_JDBCDRIVER_SUCCESS : STR_JDBCDRIVER_NO_SUCCESS;
     322           0 :         const OSQLMessageBox::MessageType mt = bSuccess ? OSQLMessageBox::Info : OSQLMessageBox::Error;
     323           0 :         OSQLMessageBox aMsg( this, OUString( ModuleRes( nMessage ) ), OUString(), WB_OK | WB_DEF_OK, mt );
     324           0 :         aMsg.Execute();
     325           0 :         return 0L;
     326             :     }
     327           0 :     bool OConnectionTabPage::checkTestConnection()
     328             :     {
     329             :         OSL_ENSURE(m_pAdminDialog,"No Admin dialog set! ->GPF");
     330           0 :         sal_Bool bEnableTestConnection = !m_aConnectionURL.IsVisible() || !m_aConnectionURL.GetTextNoPrefix().isEmpty();
     331           0 :         if ( m_pCollection->determineType(m_eType) ==  ::dbaccess::DST_JDBC )
     332           0 :             bEnableTestConnection = bEnableTestConnection && (!m_aJavaDriver.GetText().isEmpty());
     333           0 :         m_aTestConnection.Enable(bEnableTestConnection);
     334           0 :         return true;
     335             :     }
     336           0 :     IMPL_LINK(OConnectionTabPage, OnEditModified, Edit*, _pEdit)
     337             :     {
     338           0 :         if ( _pEdit == &m_aJavaDriver )
     339           0 :             m_aTestJavaDriver.Enable( !m_aJavaDriver.GetText().isEmpty() );
     340             : 
     341           0 :         checkTestConnection();
     342             :         // tell the listener we were modified
     343           0 :         callModifiedHdl();
     344           0 :         return 0L;
     345             :     }
     346           0 : }   // namespace dbaui
     347             : 
     348             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10