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

Generated by: LCOV version 1.10