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

Generated by: LCOV version 1.10