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

Generated by: LCOV version 1.10