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

Generated by: LCOV version 1.10