LCOV - code coverage report
Current view: top level - dbaccess/source/ui/dlg - adminpages.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 151 0.0 %
Date: 2014-04-14 Functions: 0 29 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "adminpages.hxx"
      21             : #include "dbadmin.hrc"
      22             : #include "dbadmin.hxx"
      23             : #include "dbu_dlg.hrc"
      24             : #include <svl/stritem.hxx>
      25             : #include <svl/eitem.hxx>
      26             : #include <svl/intitem.hxx>
      27             : #include "dbustrings.hrc"
      28             : #include "dsitems.hxx"
      29             : #include "dsselect.hxx"
      30             : #include "localresaccess.hxx"
      31             : #include "odbcconfig.hxx"
      32             : #include "optionalboolitem.hxx"
      33             : #include "sqlmessage.hxx"
      34             : 
      35             : #include <osl/file.hxx>
      36             : #include <vcl/accel.hxx>
      37             : #include <vcl/button.hxx>
      38             : #include <vcl/edit.hxx>
      39             : #include <vcl/field.hxx>
      40             : #include <vcl/lstbox.hxx>
      41             : #include <vcl/msgbox.hxx>
      42             : 
      43             : #include <algorithm>
      44             : #include <stdlib.h>
      45             : 
      46             : namespace dbaui
      47             : {
      48             : 
      49             :     using namespace ::com::sun::star::uno;
      50             :     using namespace ::com::sun::star::sdbc;
      51             :     using namespace ::com::sun::star::beans;
      52             :     using namespace ::com::sun::star::lang;
      53             :     using namespace ::dbtools;
      54             :     using namespace ::svt;
      55             : 
      56           0 :     ISaveValueWrapper::~ISaveValueWrapper()
      57             :     {
      58           0 :     }
      59             : 
      60             :     // OGenericAdministrationPage
      61           0 :     OGenericAdministrationPage::OGenericAdministrationPage(Window* _pParent, const ResId& _rId, const SfxItemSet& _rAttrSet)
      62             :         :SfxTabPage(_pParent, _rId, _rAttrSet)
      63             :         ,m_abEnableRoadmap(sal_False)
      64             :         ,m_pAdminDialog(NULL)
      65             :         ,m_pItemSetHelper(NULL)
      66           0 :         ,m_pFT_HeaderText(NULL)
      67             :     {
      68             : 
      69           0 :         SetExchangeSupport(true);
      70           0 :     }
      71             : 
      72           0 :     OGenericAdministrationPage::OGenericAdministrationPage(Window* _pParent, const OString& _rId, const OUString& _rUIXMLDescription, const SfxItemSet& _rAttrSet)
      73             :         :SfxTabPage(_pParent, _rId, _rUIXMLDescription, _rAttrSet)
      74             :         ,m_abEnableRoadmap(sal_False)
      75             :         ,m_pAdminDialog(NULL)
      76             :         ,m_pItemSetHelper(NULL)
      77           0 :         ,m_pFT_HeaderText(NULL)
      78             :     {
      79             : 
      80           0 :         SetExchangeSupport(true);
      81           0 :     }
      82             : 
      83           0 :     OGenericAdministrationPage::~OGenericAdministrationPage()
      84             :     {
      85           0 :         DELETEZ(m_pFT_HeaderText);
      86             : 
      87           0 :     }
      88             : 
      89           0 :     int OGenericAdministrationPage::DeactivatePage(SfxItemSet* _pSet)
      90             :     {
      91           0 :         if (_pSet)
      92             :         {
      93           0 :             if (!prepareLeave())
      94           0 :                 return KEEP_PAGE;
      95           0 :             FillItemSet(*_pSet);
      96             :         }
      97             : 
      98           0 :         return LEAVE_PAGE;
      99             :     }
     100             : 
     101           0 :     void OGenericAdministrationPage::Reset(const SfxItemSet& _rCoreAttrs)
     102             :     {
     103           0 :         implInitControls(_rCoreAttrs, sal_False);
     104           0 :     }
     105           0 :     void OGenericAdministrationPage::ActivatePage()
     106             :     {
     107           0 :         TabPage::ActivatePage();
     108             :         OSL_ENSURE(m_pItemSetHelper,"NO ItemSetHelper set!");
     109           0 :         if ( m_pItemSetHelper )
     110           0 :             ActivatePage(*m_pItemSetHelper->getOutputSet());
     111           0 :     }
     112           0 :     void OGenericAdministrationPage::ActivatePage(const SfxItemSet& _rSet)
     113             :     {
     114           0 :         implInitControls(_rSet, sal_True);
     115           0 :     }
     116             : 
     117           0 :     void OGenericAdministrationPage::getFlags(const SfxItemSet& _rSet, sal_Bool& _rValid, sal_Bool& _rReadonly)
     118             :     {
     119           0 :         SFX_ITEMSET_GET(_rSet, pInvalid, SfxBoolItem, DSID_INVALID_SELECTION, true);
     120           0 :         _rValid = !pInvalid || !pInvalid->GetValue();
     121           0 :         SFX_ITEMSET_GET(_rSet, pReadonly, SfxBoolItem, DSID_READONLY, true);
     122           0 :         _rReadonly = !_rValid || (pReadonly && pReadonly->GetValue());
     123           0 :     }
     124             : 
     125           0 :     IMPL_LINK_NOARG(OGenericAdministrationPage, OnControlModified)
     126             :     {
     127           0 :         callModifiedHdl();
     128           0 :         return 0L;
     129             :     }
     130           0 :     sal_Bool OGenericAdministrationPage::getSelectedDataSource(OUString& _sReturn,OUString& _sCurr)
     131             :     {
     132             :         // collect all ODBC data source names
     133           0 :         StringBag aOdbcDatasources;
     134           0 :         OOdbcEnumeration aEnumeration;
     135           0 :         if (!aEnumeration.isLoaded())
     136             :         {
     137             :             // show an error message
     138           0 :             OUString sError( ModuleRes( STR_COULD_NOT_LOAD_ODBC_LIB ) );
     139           0 :             sError = sError.replaceFirst("#lib#", aEnumeration.getLibraryName());
     140           0 :             ErrorBox aDialog(this, WB_OK, sError);
     141           0 :             aDialog.Execute();
     142           0 :             return sal_False;
     143             :         }
     144             :         else
     145             :         {
     146           0 :             aEnumeration.getDatasourceNames(aOdbcDatasources);
     147             :             // execute the select dialog
     148           0 :             ODatasourceSelectDialog aSelector(GetParent(), aOdbcDatasources);
     149           0 :             if (!_sCurr.isEmpty())
     150           0 :                 aSelector.Select(_sCurr);
     151           0 :             if ( RET_OK == aSelector.Execute() )
     152           0 :                 _sReturn = aSelector.GetSelected();
     153             :         }
     154           0 :         return sal_True;
     155             :     }
     156             : 
     157           0 :     void OGenericAdministrationPage::implInitControls(const SfxItemSet& _rSet, sal_Bool _bSaveValue)
     158             :     {
     159             :         // check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa)
     160             :         sal_Bool bValid, bReadonly;
     161           0 :         getFlags(_rSet, bValid, bReadonly);
     162             : 
     163           0 :         ::std::vector< ISaveValueWrapper* > aControlList;
     164           0 :         if ( _bSaveValue )
     165             :         {
     166           0 :             fillControls(aControlList);
     167           0 :             ::std::for_each(aControlList.begin(),aControlList.end(),TSaveValueWrapperFunctor());
     168             :         }
     169             : 
     170           0 :         if ( bReadonly )
     171             :         {
     172           0 :             fillWindows(aControlList);
     173           0 :             ::std::for_each(aControlList.begin(),aControlList.end(),TDisableWrapperFunctor());
     174             :         }
     175             : 
     176           0 :         ::std::for_each(aControlList.begin(),aControlList.end(),TDeleteWrapperFunctor());
     177           0 :         aControlList.clear();
     178           0 :     }
     179             : 
     180           0 :     void OGenericAdministrationPage::initializePage()
     181             :     {
     182             :         OSL_ENSURE(m_pItemSetHelper,"NO ItemSetHelper set!");
     183           0 :         if ( m_pItemSetHelper )
     184           0 :             Reset(*m_pItemSetHelper->getOutputSet());
     185           0 :     }
     186           0 :     bool OGenericAdministrationPage::commitPage( ::svt::WizardTypes::CommitPageReason )
     187             :     {
     188           0 :         return true;
     189             :     }
     190           0 :     bool OGenericAdministrationPage::canAdvance() const
     191             :     {
     192           0 :         return true;
     193             :     }
     194           0 :     void OGenericAdministrationPage::fillBool( SfxItemSet& _rSet, CheckBox* _pCheckBox, sal_uInt16 _nID, sal_Bool& _bChangedSomething, bool _bRevertValue )
     195             :     {
     196           0 :         if ( (_pCheckBox != NULL ) && ( _pCheckBox->GetState() != _pCheckBox->GetSavedValue() ) )
     197             :         {
     198           0 :             sal_Bool bValue = _pCheckBox->IsChecked();
     199           0 :             if ( _bRevertValue )
     200           0 :                 bValue = !bValue;
     201             : 
     202           0 :             if ( _pCheckBox->IsTriStateEnabled() )
     203             :             {
     204           0 :                 OptionalBoolItem aValue( _nID );
     205           0 :                 if ( _pCheckBox->GetState() != TRISTATE_INDET )
     206           0 :                     aValue.SetValue( bValue );
     207           0 :                 _rSet.Put( aValue );
     208             :             }
     209             :             else
     210           0 :                 _rSet.Put( SfxBoolItem( _nID, bValue ) );
     211             : 
     212           0 :             _bChangedSomething = sal_True;
     213             :         }
     214           0 :     }
     215           0 :     void OGenericAdministrationPage::fillInt32(SfxItemSet& _rSet,NumericField* _pEdit,sal_uInt16 _nID,sal_Bool& _bChangedSomething)
     216             :     {
     217           0 :         if( (_pEdit != NULL) && (_pEdit->GetValue() != _pEdit->GetSavedValue().toInt32()) )
     218             :         {
     219           0 :             _rSet.Put(SfxInt32Item(_nID, static_cast<sal_Int32>(_pEdit->GetValue())));
     220           0 :             _bChangedSomething = sal_True;
     221             :         }
     222           0 :     }
     223           0 :     void OGenericAdministrationPage::fillString(SfxItemSet& _rSet,Edit* _pEdit,sal_uInt16 _nID,sal_Bool& _bChangedSomething)
     224             :     {
     225           0 :         if( (_pEdit != NULL) && (_pEdit->GetText() != _pEdit->GetSavedValue()) )
     226             :         {
     227           0 :             _rSet.Put(SfxStringItem(_nID, _pEdit->GetText()));
     228           0 :             _bChangedSomething = sal_True;
     229             :         }
     230           0 :     }
     231             : 
     232           0 :     void OGenericAdministrationPage::SetControlFontWeight(Window* _pWindow, FontWeight _eWeight)
     233             :     {
     234           0 :         Font aFont = _pWindow->GetControlFont();
     235           0 :         aFont.SetWeight( _eWeight );
     236           0 :         _pWindow->SetControlFont( aFont );
     237           0 :     }
     238             : 
     239           0 :     IMPL_LINK(OGenericAdministrationPage, OnTestConnectionClickHdl, PushButton*, /*_pButton*/)
     240             :     {
     241             :         OSL_ENSURE(m_pAdminDialog,"No Admin dialog set! ->GPF");
     242           0 :         sal_Bool bSuccess = sal_False;
     243           0 :         if ( m_pAdminDialog )
     244             :         {
     245           0 :             m_pAdminDialog->saveDatasource();
     246           0 :             OGenericAdministrationPage::implInitControls(*m_pItemSetHelper->getOutputSet(), sal_True);
     247           0 :             sal_Bool bShowMessage = sal_True;
     248             :             try
     249             :             {
     250           0 :                 ::std::pair< Reference<XConnection>,sal_Bool> xConnection = m_pAdminDialog->createConnection();
     251           0 :                 bShowMessage = xConnection.second;
     252           0 :                 bSuccess = xConnection.first.is();
     253           0 :                 ::comphelper::disposeComponent(xConnection.first);
     254             :             }
     255           0 :             catch(Exception&)
     256             :             {
     257             :             }
     258           0 :             if ( bShowMessage )
     259             :             {
     260           0 :                 OSQLMessageBox::MessageType eImage = OSQLMessageBox::Info;
     261           0 :                 OUString aMessage,sTitle;
     262           0 :                 sTitle = ModuleRes(STR_CONNECTION_TEST);
     263           0 :                 if ( bSuccess )
     264             :                 {
     265           0 :                     aMessage = ModuleRes(STR_CONNECTION_SUCCESS);
     266             :                 }
     267             :                 else
     268             :                 {
     269           0 :                     eImage = OSQLMessageBox::Error;
     270           0 :                     aMessage = ModuleRes(STR_CONNECTION_NO_SUCCESS);
     271             :                 }
     272           0 :                 OSQLMessageBox aMsg( this, sTitle, aMessage, WB_OK, eImage );
     273           0 :                 aMsg.Execute();
     274             :             }
     275           0 :             if ( !bSuccess )
     276           0 :                 m_pAdminDialog->clearPassword();
     277             :         }
     278           0 :         return 0L;
     279             :     }
     280             : 
     281           0 :     void OGenericAdministrationPage::SetHeaderText( sal_uInt16 _nFTResId, sal_uInt16 _StringResId)
     282             :     {
     283           0 :         delete(m_pFT_HeaderText);
     284           0 :         m_pFT_HeaderText = new FixedText(this, ModuleRes(_nFTResId));
     285           0 :         OUString sHeaderText = ModuleRes(_StringResId);
     286           0 :         m_pFT_HeaderText->SetText(sHeaderText);
     287           0 :         SetControlFontWeight(m_pFT_HeaderText);
     288           0 :     }
     289             : 
     290             :     // LayoutHelper
     291           0 :     void LayoutHelper::positionBelow( const Control& _rReference, Control& _rControl, const ControlRelation _eRelation,
     292             :         const long _nIndentAppFont )
     293             :     {
     294           0 :         Point aReference = _rReference.GetPosPixel();
     295           0 :         aReference.Y() += _rReference.GetSizePixel().Height();
     296             : 
     297           0 :         const Window* pConverter = _rControl.GetParent();
     298           0 :         Size aOffset = pConverter->LogicToPixel( Size( _nIndentAppFont, ( _eRelation == RelatedControls ? 3 : 6 ) ), MAP_APPFONT );
     299             : 
     300           0 :         Point aControlPos( aReference.X() + aOffset.Width(), aReference.Y() + aOffset.Height() );
     301           0 :         _rControl.SetPosPixel( aControlPos );
     302           0 :     }
     303             : 
     304           0 :     void LayoutHelper::fitSizeRightAligned( PushButton& io_button )
     305             :     {
     306           0 :         const Point aOldPos = io_button.GetPosPixel();
     307           0 :         const Size aOldSize = io_button.GetSizePixel();
     308           0 :         const Size aMinSize( io_button.CalcMinimumSize() );
     309           0 :         if ( aMinSize.Width() > aOldSize.Width() )
     310             :         {
     311             :             io_button.setPosSizePixel(
     312           0 :                 aOldPos.X() + aOldSize.Width() - aMinSize.Width(),
     313             :                 0,
     314             :                 aMinSize.Width(),
     315             :                 0,
     316             :                 WINDOW_POSSIZE_X | WINDOW_POSSIZE_WIDTH
     317           0 :             );
     318             :         }
     319           0 :     }
     320             : 
     321           0 : }   // namespace dbaui
     322             : 
     323             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10