LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/dbaccess/source/ui/dlg - adminpages.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 151 0.7 %
Date: 2013-07-09 Functions: 2 29 6.9 %
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 "adminpages.hxx"
      22             : #include "dbadmin.hrc"
      23             : #include "dbadmin.hxx"
      24             : #include "dbu_dlg.hrc"
      25             : #include <svl/stritem.hxx>
      26             : #include <svl/eitem.hxx>
      27             : #include <svl/intitem.hxx>
      28             : #include "dbustrings.hrc"
      29             : #include "dsitems.hxx"
      30             : #include "dsselect.hxx"
      31             : #include "localresaccess.hxx"
      32             : #include "odbcconfig.hxx"
      33             : #include "optionalboolitem.hxx"
      34             : #include "sqlmessage.hxx"
      35             : 
      36             : #include <osl/file.hxx>
      37             : #include <vcl/accel.hxx>
      38             : #include <vcl/button.hxx>
      39             : #include <vcl/edit.hxx>
      40             : #include <vcl/field.hxx>
      41             : #include <vcl/lstbox.hxx>
      42             : #include <vcl/msgbox.hxx>
      43             : 
      44             : #include <algorithm>
      45             : #include <stdlib.h>
      46             : 
      47             : //.........................................................................
      48             : namespace dbaui
      49             : {
      50             : //.........................................................................
      51             : 
      52             :     using namespace ::com::sun::star::uno;
      53             :     using namespace ::com::sun::star::sdbc;
      54             :     using namespace ::com::sun::star::beans;
      55             :     using namespace ::com::sun::star::lang;
      56             :     using namespace ::dbtools;
      57             :     using namespace ::svt;
      58             : 
      59           0 :     ISaveValueWrapper::~ISaveValueWrapper()
      60             :     {
      61           0 :     }
      62             : 
      63             :     //=========================================================================
      64             :     //= OGenericAdministrationPage
      65             :     //=========================================================================
      66             :     DBG_NAME(OGenericAdministrationPage)
      67             :     //-------------------------------------------------------------------------
      68           0 :     OGenericAdministrationPage::OGenericAdministrationPage(Window* _pParent, const ResId& _rId, const SfxItemSet& _rAttrSet)
      69             :         :SfxTabPage(_pParent, _rId, _rAttrSet)
      70             :         ,m_abEnableRoadmap(sal_False)
      71             :         ,m_pAdminDialog(NULL)
      72             :         ,m_pItemSetHelper(NULL)
      73           0 :         ,m_pFT_HeaderText(NULL)
      74             :     {
      75             :         DBG_CTOR(OGenericAdministrationPage,NULL);
      76             : 
      77           0 :         SetExchangeSupport(sal_True);
      78           0 :     }
      79             : 
      80             :     //-------------------------------------------------------------------------
      81           0 :     OGenericAdministrationPage::OGenericAdministrationPage(Window* _pParent, const OString& _rId, const OUString& _rUIXMLDescription, const SfxItemSet& _rAttrSet)
      82             :         :SfxTabPage(_pParent, _rId, _rUIXMLDescription, _rAttrSet)
      83             :         ,m_abEnableRoadmap(sal_False)
      84             :         ,m_pAdminDialog(NULL)
      85             :         ,m_pItemSetHelper(NULL)
      86           0 :         ,m_pFT_HeaderText(NULL)
      87             :     {
      88             :         DBG_CTOR(OGenericAdministrationPage,NULL);
      89             : 
      90           0 :         SetExchangeSupport(sal_True);
      91           0 :     }
      92             : 
      93             :     //-------------------------------------------------------------------------
      94           0 :     OGenericAdministrationPage::~OGenericAdministrationPage()
      95             :     {
      96           0 :         DELETEZ(m_pFT_HeaderText);
      97             : 
      98             :         DBG_DTOR(OGenericAdministrationPage,NULL);
      99           0 :     }
     100             : 
     101             :     //-------------------------------------------------------------------------
     102           0 :     int OGenericAdministrationPage::DeactivatePage(SfxItemSet* _pSet)
     103             :     {
     104           0 :         if (_pSet)
     105             :         {
     106           0 :             if (!prepareLeave())
     107           0 :                 return KEEP_PAGE;
     108           0 :             FillItemSet(*_pSet);
     109             :         }
     110             : 
     111           0 :         return LEAVE_PAGE;
     112             :     }
     113             : 
     114             :     //-------------------------------------------------------------------------
     115           0 :     void OGenericAdministrationPage::Reset(const SfxItemSet& _rCoreAttrs)
     116             :     {
     117           0 :         implInitControls(_rCoreAttrs, sal_False);
     118           0 :     }
     119             :     //-------------------------------------------------------------------------
     120           0 :     void OGenericAdministrationPage::ActivatePage()
     121             :     {
     122           0 :         TabPage::ActivatePage();
     123             :         OSL_ENSURE(m_pItemSetHelper,"NO ItemSetHelper set!");
     124           0 :         if ( m_pItemSetHelper )
     125           0 :             ActivatePage(*m_pItemSetHelper->getOutputSet());
     126           0 :     }
     127             :     //-------------------------------------------------------------------------
     128           0 :     void OGenericAdministrationPage::ActivatePage(const SfxItemSet& _rSet)
     129             :     {
     130           0 :         implInitControls(_rSet, sal_True);
     131           0 :     }
     132             : 
     133             :     // -----------------------------------------------------------------------
     134           0 :     void OGenericAdministrationPage::getFlags(const SfxItemSet& _rSet, sal_Bool& _rValid, sal_Bool& _rReadonly)
     135             :     {
     136           0 :         SFX_ITEMSET_GET(_rSet, pInvalid, SfxBoolItem, DSID_INVALID_SELECTION, sal_True);
     137           0 :         _rValid = !pInvalid || !pInvalid->GetValue();
     138           0 :         SFX_ITEMSET_GET(_rSet, pReadonly, SfxBoolItem, DSID_READONLY, sal_True);
     139           0 :         _rReadonly = !_rValid || (pReadonly && pReadonly->GetValue());
     140           0 :     }
     141             : 
     142             : 
     143             :     // -----------------------------------------------------------------------
     144           0 :     IMPL_LINK_NOARG(OGenericAdministrationPage, OnControlModified)
     145             :     {
     146           0 :         callModifiedHdl();
     147           0 :         return 0L;
     148             :     }
     149             :     // -----------------------------------------------------------------------
     150           0 :     sal_Bool OGenericAdministrationPage::getSelectedDataSource(OUString& _sReturn,OUString& _sCurr)
     151             :     {
     152             :         // collect all ODBC data source names
     153           0 :         StringBag aOdbcDatasources;
     154           0 :         OOdbcEnumeration aEnumeration;
     155           0 :         if (!aEnumeration.isLoaded())
     156             :         {
     157             :             // show an error message
     158           0 :             String sError( ModuleRes( STR_COULD_NOT_LOAD_ODBC_LIB ) );
     159           0 :             sError.SearchAndReplaceAscii("#lib#", aEnumeration.getLibraryName());
     160           0 :             ErrorBox aDialog(this, WB_OK, sError);
     161           0 :             aDialog.Execute();
     162           0 :             return sal_False;
     163             :         }
     164             :         else
     165             :         {
     166           0 :             aEnumeration.getDatasourceNames(aOdbcDatasources);
     167             :             // execute the select dialog
     168           0 :             ODatasourceSelectDialog aSelector(GetParent(), aOdbcDatasources);
     169           0 :             if (!_sCurr.isEmpty())
     170           0 :                 aSelector.Select(_sCurr);
     171           0 :             if ( RET_OK == aSelector.Execute() )
     172           0 :                 _sReturn = aSelector.GetSelected();
     173             :         }
     174           0 :         return sal_True;
     175             :     }
     176             : 
     177             :     // -----------------------------------------------------------------------
     178           0 :     void OGenericAdministrationPage::implInitControls(const SfxItemSet& _rSet, sal_Bool _bSaveValue)
     179             :     {
     180             :         // check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa)
     181             :         sal_Bool bValid, bReadonly;
     182           0 :         getFlags(_rSet, bValid, bReadonly);
     183             : 
     184           0 :         ::std::vector< ISaveValueWrapper* > aControlList;
     185           0 :         if ( _bSaveValue )
     186             :         {
     187           0 :             fillControls(aControlList);
     188           0 :             ::std::for_each(aControlList.begin(),aControlList.end(),TSaveValueWrapperFunctor());
     189             :         }
     190             : 
     191           0 :         if ( bReadonly )
     192             :         {
     193           0 :             fillWindows(aControlList);
     194           0 :             ::std::for_each(aControlList.begin(),aControlList.end(),TDisableWrapperFunctor());
     195             :         }
     196             : 
     197           0 :         ::std::for_each(aControlList.begin(),aControlList.end(),TDeleteWrapperFunctor());
     198           0 :         aControlList.clear();
     199           0 :     }
     200             : 
     201             :     // -----------------------------------------------------------------------
     202           0 :     void OGenericAdministrationPage::initializePage()
     203             :     {
     204             :         OSL_ENSURE(m_pItemSetHelper,"NO ItemSetHelper set!");
     205           0 :         if ( m_pItemSetHelper )
     206           0 :             Reset(*m_pItemSetHelper->getOutputSet());
     207           0 :     }
     208             :     // -----------------------------------------------------------------------
     209           0 :     sal_Bool OGenericAdministrationPage::commitPage( ::svt::WizardTypes::CommitPageReason )
     210             :     {
     211           0 :         return sal_True;
     212             :     }
     213             :     // -----------------------------------------------------------------------
     214           0 :     bool OGenericAdministrationPage::canAdvance() const
     215             :     {
     216           0 :         return true;
     217             :     }
     218             :     // -----------------------------------------------------------------------
     219           0 :     void OGenericAdministrationPage::fillBool( SfxItemSet& _rSet, CheckBox* _pCheckBox, sal_uInt16 _nID, sal_Bool& _bChangedSomething, bool _bRevertValue )
     220             :     {
     221           0 :         if ( (_pCheckBox != NULL ) && ( _pCheckBox->GetState() != _pCheckBox->GetSavedValue() ) )
     222             :         {
     223           0 :             sal_Bool bValue = _pCheckBox->IsChecked();
     224           0 :             if ( _bRevertValue )
     225           0 :                 bValue = !bValue;
     226             : 
     227           0 :             if ( _pCheckBox->IsTriStateEnabled() )
     228             :             {
     229           0 :                 OptionalBoolItem aValue( _nID );
     230           0 :                 if ( _pCheckBox->GetState() != STATE_DONTKNOW )
     231           0 :                     aValue.SetValue( bValue );
     232           0 :                 _rSet.Put( aValue );
     233             :             }
     234             :             else
     235           0 :                 _rSet.Put( SfxBoolItem( _nID, bValue ) );
     236             : 
     237           0 :             _bChangedSomething = sal_True;
     238             :         }
     239           0 :     }
     240             :     // -----------------------------------------------------------------------
     241           0 :     void OGenericAdministrationPage::fillInt32(SfxItemSet& _rSet,NumericField* _pEdit,sal_uInt16 _nID,sal_Bool& _bChangedSomething)
     242             :     {
     243           0 :         if( (_pEdit != NULL) && (_pEdit->GetValue() != _pEdit->GetSavedValue().toInt32()) )
     244             :         {
     245           0 :             _rSet.Put(SfxInt32Item(_nID, static_cast<sal_Int32>(_pEdit->GetValue())));
     246           0 :             _bChangedSomething = sal_True;
     247             :         }
     248           0 :     }
     249             :     // -----------------------------------------------------------------------
     250           0 :     void OGenericAdministrationPage::fillString(SfxItemSet& _rSet,Edit* _pEdit,sal_uInt16 _nID,sal_Bool& _bChangedSomething)
     251             :     {
     252           0 :         if( (_pEdit != NULL) && (_pEdit->GetText() != _pEdit->GetSavedValue()) )
     253             :         {
     254           0 :             _rSet.Put(SfxStringItem(_nID, _pEdit->GetText()));
     255           0 :             _bChangedSomething = sal_True;
     256             :         }
     257           0 :     }
     258             : 
     259           0 :     void OGenericAdministrationPage::SetControlFontWeight(Window* _pWindow, FontWeight _eWeight)
     260             :     {
     261           0 :         Font aFont = _pWindow->GetControlFont();
     262           0 :         aFont.SetWeight( _eWeight );
     263           0 :         _pWindow->SetControlFont( aFont );
     264           0 :     }
     265             : 
     266             :     // -----------------------------------------------------------------------
     267           0 :     IMPL_LINK(OGenericAdministrationPage, OnTestConnectionClickHdl, PushButton*, /*_pButton*/)
     268             :     {
     269             :         OSL_ENSURE(m_pAdminDialog,"No Admin dialog set! ->GPF");
     270           0 :         sal_Bool bSuccess = sal_False;
     271           0 :         if ( m_pAdminDialog )
     272             :         {
     273           0 :             m_pAdminDialog->saveDatasource();
     274           0 :             OGenericAdministrationPage::implInitControls(*m_pItemSetHelper->getOutputSet(), sal_True);
     275           0 :             sal_Bool bShowMessage = sal_True;
     276             :             try
     277             :             {
     278           0 :                 ::std::pair< Reference<XConnection>,sal_Bool> xConnection = m_pAdminDialog->createConnection();
     279           0 :                 bShowMessage = xConnection.second;
     280           0 :                 bSuccess = xConnection.first.is();
     281           0 :                 ::comphelper::disposeComponent(xConnection.first);
     282             :             }
     283           0 :             catch(Exception&)
     284             :             {
     285             :             }
     286           0 :             if ( bShowMessage )
     287             :             {
     288           0 :                 OSQLMessageBox::MessageType eImage = OSQLMessageBox::Info;
     289           0 :                 String aMessage,sTitle;
     290           0 :                 sTitle = String (ModuleRes(STR_CONNECTION_TEST));
     291           0 :                 if ( bSuccess )
     292             :                 {
     293           0 :                     aMessage = String(ModuleRes(STR_CONNECTION_SUCCESS));
     294             :                 }
     295             :                 else
     296             :                 {
     297           0 :                     eImage = OSQLMessageBox::Error;
     298           0 :                     aMessage = String(ModuleRes(STR_CONNECTION_NO_SUCCESS));
     299             :                 }
     300           0 :                 OSQLMessageBox aMsg( this, sTitle, aMessage, WB_OK, eImage );
     301           0 :                 aMsg.Execute();
     302             :             }
     303           0 :             if ( !bSuccess )
     304           0 :                 m_pAdminDialog->clearPassword();
     305             :         }
     306           0 :         return 0L;
     307             :     }
     308             : 
     309           0 :     void OGenericAdministrationPage::SetHeaderText( sal_uInt16 _nFTResId, sal_uInt16 _StringResId)
     310             :     {
     311           0 :         delete(m_pFT_HeaderText);
     312           0 :         m_pFT_HeaderText = new FixedText(this, ModuleRes(_nFTResId));
     313           0 :         String sHeaderText = String(ModuleRes(_StringResId));
     314           0 :         m_pFT_HeaderText->SetText(sHeaderText);
     315           0 :         SetControlFontWeight(m_pFT_HeaderText);
     316           0 :     }
     317             : 
     318             :     //=========================================================================
     319             :     //= LayoutHelper
     320             :     //=========================================================================
     321             :     //-------------------------------------------------------------------------
     322           0 :     void LayoutHelper::positionBelow( const Control& _rReference, Control& _rControl, const ControlRelation _eRelation,
     323             :         const long _nIndentAppFont )
     324             :     {
     325           0 :         Point aReference = _rReference.GetPosPixel();
     326           0 :         aReference.Y() += _rReference.GetSizePixel().Height();
     327             : 
     328           0 :         const Window* pConverter = _rControl.GetParent();
     329           0 :         Size aOffset = pConverter->LogicToPixel( Size( _nIndentAppFont, ( _eRelation == RelatedControls ? 3 : 6 ) ), MAP_APPFONT );
     330             : 
     331           0 :         Point aControlPos( aReference.X() + aOffset.Width(), aReference.Y() + aOffset.Height() );
     332           0 :         _rControl.SetPosPixel( aControlPos );
     333           0 :     }
     334             : 
     335             :     //-------------------------------------------------------------------------
     336           0 :     void LayoutHelper::fitSizeRightAligned( PushButton& io_button )
     337             :     {
     338           0 :         const Point aOldPos = io_button.GetPosPixel();
     339           0 :         const Size aOldSize = io_button.GetSizePixel();
     340           0 :         const Size aMinSize( io_button.CalcMinimumSize() );
     341           0 :         if ( aMinSize.Width() > aOldSize.Width() )
     342             :         {
     343             :             io_button.setPosSizePixel(
     344           0 :                 aOldPos.X() + aOldSize.Width() - aMinSize.Width(),
     345             :                 0,
     346             :                 aMinSize.Width(),
     347             :                 0,
     348             :                 WINDOW_POSSIZE_X | WINDOW_POSSIZE_WIDTH
     349           0 :             );
     350             :         }
     351           0 :     }
     352             : 
     353             : //.........................................................................
     354          12 : }   // namespace dbaui
     355             : //.........................................................................
     356             : 
     357             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10