LCOV - code coverage report
Current view: top level - cui/source/options - optaboutconfig.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 328 0.0 %
Date: 2014-11-03 Functions: 0 20 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             : 
      10             : #include "optaboutconfig.hxx"
      11             : #include "optHeaderTabListbox.hxx"
      12             : 
      13             : #include <svtools/svlbitm.hxx>
      14             : #include <svtools/treelistentry.hxx>
      15             : #include <comphelper/processfactory.hxx>
      16             : #include <comphelper/sequence.hxx>
      17             : #include <com/sun/star/configuration/theDefaultProvider.hpp>
      18             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      19             : #include <com/sun/star/beans/NamedValue.hpp>
      20             : #include <com/sun/star/beans/Property.hpp>
      21             : #include <com/sun/star/beans/XProperty.hpp>
      22             : #include <com/sun/star/container/XNameAccess.hpp>
      23             : #include <com/sun/star/container/XNameReplace.hpp>
      24             : #include <com/sun/star/container/XHierarchicalName.hpp>
      25             : #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
      26             : #include <com/sun/star/util/XChangesBatch.hpp>
      27             : 
      28             : #include <vector>
      29             : #include <boost/shared_ptr.hpp>
      30             : #include <iostream>
      31             : 
      32             : using namespace svx;
      33             : using namespace ::com::sun::star;
      34             : using namespace com::sun::star::uno;
      35             : using namespace com::sun::star::container;
      36             : 
      37             : #define SHORT_LEN_LIMIT     7
      38             : #define LONG_LEN_LIMIT      11
      39             : #define HYPER_LEN_LIMIT     20
      40             : 
      41           0 : struct Prop_Impl
      42             : {
      43             :     OUString    Name;
      44             :     OUString    Property;
      45             :     Any         Value;
      46             : 
      47           0 :     Prop_Impl( const OUString& sName, const OUString& sProperty, const Any& aValue )
      48             :         : Name( sName )
      49             :         , Property( sProperty )
      50           0 :         , Value( aValue )
      51           0 :     {}
      52             : };
      53             : 
      54           0 : extern "C" SAL_DLLPUBLIC_EXPORT vcl::Window* SAL_CALL makeCuiCustomMultilineEdit(vcl::Window *pParent, VclBuilder::stringmap &)
      55             : {
      56           0 :     return new CuiCustomMultilineEdit(pParent, WB_LEFT|WB_VCENTER|WB_BORDER|WB_3DLOOK);
      57             : }
      58             : 
      59             : 
      60           0 : void CuiCustomMultilineEdit::KeyInput( const KeyEvent& rKeyEvent )
      61             : {
      62           0 :     bool bValid = false;
      63           0 :     bool bNonSpace = rKeyEvent.GetKeyCode().GetCode() != KEY_SPACE;
      64           0 :     if( bNumericOnly && bNonSpace )
      65             :     {
      66           0 :         const vcl::KeyCode& rKeyCode = rKeyEvent.GetKeyCode();
      67           0 :         sal_uInt16 nGroup = rKeyCode.GetGroup();
      68           0 :         sal_uInt16 nKey = rKeyCode.GetCode();
      69             : 
      70           0 :         switch ( nGroup ) {
      71             :             case KEYGROUP_NUM :
      72             :             case KEYGROUP_CURSOR :
      73             :             {
      74           0 :                 bValid = true;
      75           0 :                 break;
      76             :             }
      77             : 
      78             :             case KEYGROUP_MISC :
      79             :             {
      80           0 :                 switch ( nKey ) {
      81             :                     case KEY_SUBTRACT :
      82             :                     case KEY_COMMA :
      83             :                     case KEY_POINT :
      84             :                     {
      85           0 :                         bValid = true;
      86           0 :                         break;
      87             :                     }
      88             : 
      89             :                     default :
      90             :                     {
      91           0 :                         if( nKey < KEY_ADD || nKey > KEY_EQUAL )
      92           0 :                             bValid = true;
      93           0 :                         break;
      94             :                     }
      95             :                 }
      96           0 :                 break;
      97             :             }
      98             : 
      99             :             default :
     100             :             {
     101           0 :                 bValid = false;
     102           0 :                 break;
     103             :             }
     104             :         }
     105             : 
     106             :         //Select all, Copy, Paste, Cut, Undo Keys
     107           0 :         if ( !bValid && ( rKeyCode.IsMod1() && (
     108           0 :              KEY_A == nKey || KEY_C == nKey || KEY_V == nKey || KEY_X == nKey || KEY_Z == nKey ) ) )
     109           0 :             bValid = true;
     110             :     }
     111             :     else
     112           0 :         bValid = true;
     113           0 :     if( bValid )
     114           0 :         Edit::KeyInput( rKeyEvent );
     115           0 : }
     116             : 
     117           0 : Size CuiCustomMultilineEdit::GetOptimalSize() const
     118             : {
     119           0 :     return LogicToPixel(Size(150, GetTextHeight()), MAP_APPFONT);
     120             : }
     121             : 
     122           0 : CuiAboutConfigTabPage::CuiAboutConfigTabPage( vcl::Window* pParent/*, const SfxItemSet& rItemSet*/ ) :
     123             :     ModelessDialog( pParent, "AboutConfig", "cui/ui/aboutconfigdialog.ui"),
     124           0 :     m_pPrefCtrl( get<SvSimpleTableContainer>("preferences") ),
     125           0 :     m_pResetBtn( get<PushButton>("reset") ),
     126           0 :     m_pEditBtn( get<PushButton>("edit") ),
     127             :     m_vectorOfModified(),
     128             :     m_pPrefBox( new SvSimpleTable(*m_pPrefCtrl,
     129           0 :                                   WB_SCROLL | WB_HSCROLL | WB_VSCROLL ) )
     130             : {
     131           0 :     Size aControlSize(LogicToPixel(Size(385, 230), MAP_APPFONT));
     132           0 :     m_pPrefCtrl->set_width_request(aControlSize.Width());
     133           0 :     m_pPrefCtrl->set_height_request(aControlSize.Height());
     134             : 
     135           0 :     m_pEditBtn->SetClickHdl( LINK( this, CuiAboutConfigTabPage, StandardHdl_Impl ) );
     136           0 :     m_pResetBtn->SetClickHdl( LINK( this, CuiAboutConfigTabPage, ResetBtnHdl_Impl ) );
     137           0 :     m_pPrefBox->SetDoubleClickHdl( LINK(this, CuiAboutConfigTabPage, StandardHdl_Impl) );
     138             : 
     139           0 :     m_pPrefBox->InsertHeaderEntry(get<FixedText>("preference")->GetText());
     140           0 :     m_pPrefBox->InsertHeaderEntry(get<FixedText>("property")->GetText());
     141           0 :     m_pPrefBox->InsertHeaderEntry(get<FixedText>("type")->GetText());
     142           0 :     m_pPrefBox->InsertHeaderEntry(get<FixedText>("value")->GetText());
     143             : 
     144           0 :     long aTabs[] = {4,0,0,0,0};
     145             : 
     146           0 :     float fWidth = approximate_char_width();
     147             : 
     148           0 :     aTabs[1] = 0;
     149           0 :     aTabs[2] = aTabs[1] + fWidth * 65;
     150           0 :     aTabs[3] = aTabs[2] + fWidth * 20;
     151           0 :     aTabs[4] = aTabs[3] + fWidth * 8;
     152             : 
     153           0 :     m_pPrefBox->SetTabs(aTabs, MAP_PIXEL);
     154           0 :     m_pPrefBox->SetAlternatingRowColors( true );
     155           0 : }
     156             : 
     157           0 : void CuiAboutConfigTabPage::InsertEntry(const OUString& rProp, const OUString& rStatus, const OUString& rType, const OUString& rValue)
     158             : {
     159           0 :     SvTreeListEntry* pEntry = new SvTreeListEntry;
     160             : 
     161           0 :     pEntry->AddItem( new SvLBoxContextBmp( pEntry, 0, Image(), Image(), false)); //It is needed, otherwise causes crash
     162           0 :     pEntry->AddItem( new SvLBoxString( pEntry, 0, rProp));
     163           0 :     pEntry->AddItem( new SvLBoxString( pEntry, 0, rStatus));
     164           0 :     pEntry->AddItem( new SvLBoxString( pEntry, 0, rType));
     165           0 :     pEntry->AddItem( new SvLBoxString( pEntry, 0, rValue));
     166             : 
     167           0 :     m_pPrefBox->Insert( pEntry );
     168           0 : }
     169             : 
     170           0 : void CuiAboutConfigTabPage::Reset()
     171             : {
     172           0 :     m_pPrefBox->Clear();
     173             : 
     174           0 :     m_vectorOfModified.clear();
     175           0 :     m_pPrefBox->GetModel()->SetSortMode( SortNone );
     176             : 
     177           0 :     m_pPrefBox->SetUpdateMode(false);
     178           0 :     Reference< XNameAccess > xConfigAccess = getConfigAccess( "/", false );
     179           0 :     FillItems( xConfigAccess );
     180           0 :     m_pPrefBox->SetUpdateMode(true);
     181           0 : }
     182             : 
     183           0 : bool CuiAboutConfigTabPage::FillItemSet()
     184             : {
     185           0 :     bool bModified = false;
     186             : 
     187           0 :     std::vector< boost::shared_ptr< Prop_Impl > >::iterator pIter;
     188           0 :     for( pIter = m_vectorOfModified.begin() ; pIter != m_vectorOfModified.end(); ++pIter )
     189             :     {
     190           0 :         Reference< XNameAccess > xUpdateAccess = getConfigAccess( (*pIter)->Name , true );
     191           0 :         Reference< XNameReplace > xNameReplace( xUpdateAccess, UNO_QUERY_THROW );
     192             : 
     193           0 :         xNameReplace->replaceByName( (*pIter)->Property, (*pIter)->Value );
     194           0 :         bModified = true;
     195             : 
     196           0 :         Reference< util::XChangesBatch > xChangesBatch( xUpdateAccess, UNO_QUERY_THROW );
     197           0 :         xChangesBatch->commitChanges();
     198           0 :     }
     199             : 
     200           0 :     return bModified;
     201             : }
     202             : 
     203           0 : void CuiAboutConfigTabPage::FillItems(const Reference< XNameAccess >& xNameAccess)
     204             : {
     205             :     OUString sPath = Reference< XHierarchicalName >(
     206           0 :         xNameAccess, uno::UNO_QUERY_THROW )->getHierarchicalName();
     207           0 :     uno::Sequence< OUString > seqItems = xNameAccess->getElementNames();
     208           0 :     for( sal_Int32 i = 0; i < seqItems.getLength(); ++i )
     209             :     {
     210           0 :         Any aNode = xNameAccess->getByName( seqItems[i] );
     211             : 
     212           0 :         bool bNotLeaf = false;
     213             : 
     214           0 :         Reference< XNameAccess > xNextNameAccess;
     215             :         try
     216             :         {
     217           0 :             xNextNameAccess = Reference< XNameAccess >(aNode, uno::UNO_QUERY);
     218           0 :             bNotLeaf = xNextNameAccess.is();
     219             :         }
     220           0 :         catch (const RuntimeException& e)
     221             :         {
     222             :             SAL_WARN( "cui.options", "CuiAboutConfigTabPage: exception " << e.Message);
     223             :         }
     224             : 
     225           0 :         if (bNotLeaf)
     226             :         {
     227             :             // not leaf node
     228           0 :             FillItems( xNextNameAccess );
     229             :         }
     230             :         else
     231             :         {
     232             :             // leaf node
     233           0 :             OUString sType = aNode.getValueTypeName();
     234             : 
     235           0 :             OUString sValue;
     236           0 :             switch( aNode.getValueType().getTypeClass() )
     237             :             {
     238             :             case ::com::sun::star::uno::TypeClass_VOID:
     239           0 :                 break;
     240             : 
     241             :             case ::com::sun::star::uno::TypeClass_BOOLEAN:
     242           0 :                 sValue = OUString::boolean( aNode.get<bool>() );
     243           0 :                 break;
     244             : 
     245             :             case ::com::sun::star::uno::TypeClass_SHORT:
     246             :             case ::com::sun::star::uno::TypeClass_LONG:
     247             :             case ::com::sun::star::uno::TypeClass_HYPER:
     248           0 :                 sValue = OUString::number( aNode.get<sal_Int64>() );
     249           0 :                 break;
     250             : 
     251             :             case ::com::sun::star::uno::TypeClass_DOUBLE:
     252           0 :                 sValue = OUString::number( aNode.get<double>() );
     253           0 :                 break;
     254             : 
     255             :             case ::com::sun::star::uno::TypeClass_STRING:
     256           0 :                 sValue = aNode.get<OUString>();
     257           0 :                 break;
     258             : 
     259             :             case ::com::sun::star::uno::TypeClass_SEQUENCE:
     260           0 :                 if( sType == "[]boolean" )
     261             :                 {
     262           0 :                     uno::Sequence<sal_Bool> seq = aNode.get< uno::Sequence<sal_Bool> >();
     263           0 :                     for( sal_Int32 j = 0; j != seq.getLength(); ++j )
     264             :                     {
     265           0 :                         if( j != 0 )
     266             :                         {
     267           0 :                             sValue += ",";
     268             :                         }
     269           0 :                         sValue += OUString::boolean( seq[j] );
     270           0 :                     }
     271             :                 }
     272           0 :                 else if( sType == "[]byte" )
     273             :                 {
     274           0 :                     uno::Sequence<sal_Int8> seq = aNode.get< uno::Sequence<sal_Int8> >();
     275           0 :                     for( sal_Int32 j = 0; j != seq.getLength(); ++j )
     276             :                     {
     277             :                         OUString s = OUString::number(
     278           0 :                             static_cast<sal_uInt8>(seq[j]), 16 );
     279           0 :                         if( s.getLength() == 1 )
     280             :                         {
     281           0 :                             sValue += "0";
     282             :                         }
     283           0 :                         sValue += s.toAsciiUpperCase();
     284           0 :                     }
     285             :                 }
     286           0 :                 else if( sType == "[][]byte" )
     287             :                 {
     288           0 :                     uno::Sequence< uno::Sequence<sal_Int8> > seq = aNode.get< uno::Sequence< uno::Sequence<sal_Int8> > >();
     289           0 :                     for( sal_Int32 j = 0; j != seq.getLength(); ++j )
     290             :                     {
     291           0 :                         if( j != 0 )
     292             :                         {
     293           0 :                             sValue += ",";
     294             :                         }
     295           0 :                         for( sal_Int32 k = 0; k != seq[j].getLength(); ++k )
     296             :                         {
     297             :                             OUString s = OUString::number(
     298           0 :                                 static_cast<sal_uInt8>(seq[j][k]), 16 );
     299           0 :                             if( s.getLength() == 1 )
     300             :                             {
     301           0 :                                 sValue += "0";
     302             :                             }
     303           0 :                             sValue += s.toAsciiUpperCase();
     304           0 :                         }
     305           0 :                     }
     306             :                 }
     307           0 :                 else if( sType == "[]short" )
     308             :                 {
     309           0 :                     uno::Sequence<sal_Int16> seq = aNode.get< uno::Sequence<sal_Int16> >();
     310           0 :                     for( sal_Int32 j = 0; j != seq.getLength(); ++j )
     311             :                     {
     312           0 :                         if( j != 0 )
     313             :                         {
     314           0 :                             sValue += ",";
     315             :                         }
     316           0 :                         sValue += OUString::number( seq[j] );
     317           0 :                     }
     318             :                 }
     319           0 :                 else if( sType == "[]long" )
     320             :                 {
     321           0 :                     uno::Sequence<sal_Int32> seq = aNode.get< uno::Sequence<sal_Int32> >();
     322           0 :                     for( sal_Int32 j = 0; j != seq.getLength(); ++j )
     323             :                     {
     324           0 :                         if( j != 0 )
     325             :                         {
     326           0 :                             sValue += ",";
     327             :                         }
     328           0 :                         sValue += OUString::number( seq[j] );
     329           0 :                     }
     330             :                 }
     331           0 :                 else if( sType == "[]hyper" )
     332             :                 {
     333           0 :                     uno::Sequence<sal_Int64> seq = aNode.get< uno::Sequence<sal_Int64> >();
     334           0 :                     for( sal_Int32 j = 0; j != seq.getLength(); ++j )
     335             :                     {
     336           0 :                         if( j != 0 )
     337             :                         {
     338           0 :                             sValue += ",";
     339             :                         }
     340           0 :                         sValue += OUString::number( seq[j] );
     341           0 :                     }
     342             :                 }
     343           0 :                 else if( sType == "[]double" )
     344             :                 {
     345           0 :                     uno::Sequence<double> seq = aNode.get< uno::Sequence<double> >();
     346           0 :                     for( sal_Int32 j = 0; j != seq.getLength(); ++j )
     347             :                     {
     348           0 :                         if( j != 0 )
     349             :                         {
     350           0 :                             sValue += ",";
     351             :                         }
     352           0 :                         sValue += OUString::number( seq[j] );
     353           0 :                     }
     354             :                 }
     355           0 :                 else if( sType == "[]string" )
     356             :                 {
     357           0 :                     uno::Sequence<OUString> seq = aNode.get< uno::Sequence<OUString> >();
     358           0 :                     for( sal_Int32 j = 0; j != seq.getLength(); ++j )
     359             :                     {
     360           0 :                         if( j != 0 )
     361             :                         {
     362           0 :                             sValue += ",";
     363             :                         }
     364           0 :                         sValue += seq[j];
     365           0 :                     }
     366             :                 }
     367             :                 else
     368             :                 {
     369             :                     SAL_WARN(
     370             :                         "cui.options",
     371             :                         "path \"" << sPath << "\" member " << seqItems[i]
     372             :                             << " of unsupported type " << sType);
     373             :                 }
     374           0 :                 break;
     375             : 
     376             :             default:
     377             :                 SAL_WARN(
     378             :                     "cui.options",
     379             :                     "path \"" << sPath << "\" member " << seqItems[i]
     380             :                         << " of unsupported type " << sType);
     381           0 :                 break;
     382             :             }
     383             : 
     384           0 :             InsertEntry( sPath, seqItems[i], sType, sValue);
     385             :         }
     386           0 :     }
     387           0 : }
     388             : 
     389           0 : Reference< XNameAccess > CuiAboutConfigTabPage::getConfigAccess( const OUString& sNodePath, bool bUpdate )
     390             : {
     391           0 :     uno::Reference< uno::XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
     392             : 
     393             :     uno::Reference< lang::XMultiServiceFactory > xConfigProvider(
     394           0 :                 com::sun::star::configuration::theDefaultProvider::get( xContext  ) );
     395             : 
     396           0 :     beans::NamedValue aProperty;
     397           0 :     aProperty.Name = "nodepath";
     398           0 :     aProperty.Value = uno::makeAny( sNodePath );
     399             : 
     400           0 :     uno::Sequence< uno::Any > aArgumentList( 1 );
     401           0 :     aArgumentList[0] = uno::makeAny( aProperty );
     402             : 
     403           0 :     OUString sAccessString;
     404             : 
     405           0 :     if( bUpdate )
     406           0 :         sAccessString = "com.sun.star.configuration.ConfigurationUpdateAccess";
     407             :     else
     408           0 :         sAccessString = "com.sun.star.configuration.ConfigurationAccess";
     409             : 
     410             :     uno::Reference< container::XNameAccess > xNameAccess(
     411           0 :                 xConfigProvider->createInstanceWithArguments(
     412           0 :                     sAccessString, aArgumentList ),
     413           0 :                 uno::UNO_QUERY_THROW );
     414             : 
     415           0 :     return xNameAccess;
     416             : }
     417             : 
     418           0 : void CuiAboutConfigTabPage::AddToModifiedVector( const boost::shared_ptr< Prop_Impl >& rProp )
     419             : {
     420           0 :     bool isModifiedBefore = false;
     421             :     //Check if value modified before
     422           0 :     for( size_t nInd = 0; nInd < m_vectorOfModified.size() ; ++nInd )
     423             :     {
     424           0 :         if( rProp->Name == m_vectorOfModified[nInd]->Name && rProp->Property == m_vectorOfModified[nInd]->Property )
     425             :         {
     426             :             //property modified before. assing reference to the modified value
     427             :             //do your changes on this object. They will be saved later.
     428           0 :             m_vectorOfModified[nInd] = rProp;
     429           0 :             isModifiedBefore = true;
     430           0 :             break;
     431             :         }
     432             :     }
     433             : 
     434           0 :     if( !isModifiedBefore )
     435           0 :         m_vectorOfModified.push_back( rProp );
     436             :     //property is not modified before
     437           0 : }
     438             : 
     439           0 : std::vector< OUString > CuiAboutConfigTabPage::commaStringToSequence( const OUString& rCommaSepString )
     440             : {
     441           0 :     std::vector<OUString> tempVector;
     442             : 
     443           0 :     sal_Int32 index = 0;
     444           0 :     do
     445             :     {
     446           0 :         OUString word = rCommaSepString.getToken(0, static_cast<sal_Unicode> (','), index);
     447           0 :         word = word.trim();
     448           0 :         if( !word.isEmpty())
     449           0 :             tempVector.push_back(word);
     450           0 :     }while( index >= 0 );
     451           0 :     return tempVector;
     452             : }
     453             : 
     454           0 : CuiAboutConfigValueDialog::CuiAboutConfigValueDialog( vcl::Window* pWindow,
     455             :                                                       const OUString& rValue,
     456             :                                                       int limit ) :
     457             :     ModalDialog( pWindow, "AboutConfigValueDialog", "cui/ui/aboutconfigvaluedialog.ui" ),
     458           0 :     m_pEDValue( get<CuiCustomMultilineEdit>("valuebox") )
     459             : {
     460           0 :     m_pEDValue->bNumericOnly = ( limit !=0 );
     461           0 :     m_pEDValue->SetMaxTextLen( limit == 0 ? EDIT_NOLIMIT : limit);
     462           0 :     m_pEDValue->SetText( rValue );
     463             : 
     464           0 : }
     465             : 
     466           0 : IMPL_LINK_NOARG( CuiAboutConfigTabPage, ResetBtnHdl_Impl )
     467             : {
     468           0 :     Reset();
     469           0 :     return 0;
     470             : }
     471             : 
     472           0 : IMPL_LINK_NOARG( CuiAboutConfigTabPage, StandardHdl_Impl )
     473             : {
     474           0 :     SvTreeListEntry* pEntry = m_pPrefBox->FirstSelected();
     475             : 
     476           0 :     OUString sPropertyPath = m_pPrefBox->GetEntryText( pEntry, 0 );
     477           0 :     OUString sPropertyName = m_pPrefBox->GetEntryText( pEntry, 1 );
     478           0 :     OUString sPropertyType = m_pPrefBox->GetEntryText( pEntry, 2 );
     479           0 :     OUString sPropertyValue = m_pPrefBox->GetEntryText( pEntry, 3 );
     480             : 
     481           0 :     boost::shared_ptr< Prop_Impl > pProperty (new Prop_Impl( sPropertyPath, sPropertyName, makeAny( sPropertyValue ) ) );
     482             : 
     483             :     bool bOpenDialog;
     484           0 :     OUString sDialogValue;
     485           0 :     OUString sNewValue;
     486             : 
     487           0 :     if( sPropertyType == "boolean" )
     488             :     {
     489             :         bool bValue;
     490           0 :         if( sPropertyValue == "true" )
     491             :         {
     492           0 :             sDialogValue = "false";
     493           0 :             bValue = false;
     494             :         }
     495             :         else
     496             :         {
     497           0 :             sDialogValue = "true";
     498           0 :             bValue = true;
     499             :         }
     500             : 
     501           0 :         pProperty->Value = uno::makeAny( bValue );
     502           0 :         bOpenDialog = false;
     503             :     }
     504           0 :     else if ( sPropertyType == "void" )
     505             :     {
     506           0 :         bOpenDialog = false;
     507             :     }
     508             :     else
     509             :     {
     510           0 :         sDialogValue = sPropertyValue;
     511           0 :         bOpenDialog = true;
     512             :     }
     513             : 
     514             :     try
     515             :     {
     516           0 :         if( bOpenDialog )
     517             :         {
     518             :             //Cosmetic length limit for integer values.
     519           0 :             int limit=0;
     520           0 :             if( sPropertyType == "short" )
     521           0 :                 limit = SHORT_LEN_LIMIT;
     522           0 :             else if( sPropertyType == "long" )
     523           0 :                 limit = LONG_LEN_LIMIT;
     524           0 :             else if( sPropertyType == "hyper" )
     525           0 :                 limit = HYPER_LEN_LIMIT;
     526             : 
     527           0 :             CuiAboutConfigValueDialog* pValueDialog = new CuiAboutConfigValueDialog(0, sDialogValue, limit);
     528             : 
     529           0 :             if( pValueDialog->Execute() == RET_OK )
     530             :             {
     531           0 :                 sNewValue = pValueDialog->getValue();
     532           0 :                 if ( sPropertyType == "short")
     533             :                 {
     534             :                     sal_Int16 nShort;
     535           0 :                     sal_Int32 nNumb = sNewValue.toInt32();
     536             : 
     537             :                     //if the value is 0 and length is not 1, there is something wrong
     538           0 :                     if( !( nNumb==0 && sNewValue.getLength()!=1 ) && nNumb < SAL_MAX_INT16 && nNumb > SAL_MIN_INT16)
     539           0 :                         nShort = (sal_Int16) nNumb;
     540             :                     else
     541           0 :                         throw uno::Exception();
     542           0 :                     pProperty->Value = uno::makeAny( nShort );
     543             :                 }
     544             :                 else
     545           0 :                     if( sPropertyType == "long" )
     546             :                     {
     547           0 :                         sal_Int32 nLong = sNewValue.toInt32();
     548           0 :                         if( !( nLong==0 && sNewValue.getLength()!=1 ) && nLong < SAL_MAX_INT32 && nLong > SAL_MIN_INT32)
     549           0 :                             pProperty->Value = uno::makeAny( nLong );
     550             :                         else
     551           0 :                             throw uno::Exception();
     552             :                     }
     553           0 :                     else if( sPropertyType == "hyper")
     554             :                     {
     555           0 :                         sal_Int64 nHyper = sNewValue.toInt64();
     556           0 :                         if( !( nHyper==0 && sNewValue.getLength()!=1 ) && nHyper < SAL_MAX_INT32 && nHyper > SAL_MIN_INT32)
     557           0 :                             pProperty->Value = uno::makeAny( nHyper );
     558             :                         else
     559           0 :                             throw uno::Exception();
     560             :                     }
     561           0 :                     else if( sPropertyType == "double")
     562             :                     {
     563           0 :                         double nDoub = sNewValue.toDouble();
     564           0 :                         if( !( nDoub ==0 && sNewValue.getLength()!=1 ) && nDoub < SAL_MAX_INT32 && nDoub > SAL_MIN_INT32)
     565           0 :                             pProperty->Value = uno::makeAny( nDoub );
     566             :                         else
     567           0 :                             throw uno::Exception();
     568             :                     }
     569           0 :                     else if( sPropertyType == "float")
     570             :                     {
     571           0 :                         float nFloat = sNewValue.toFloat();
     572           0 :                         if( !( nFloat ==0 && sNewValue.getLength()!=1 ) && nFloat < SAL_MAX_INT32 && nFloat > SAL_MIN_INT32)
     573           0 :                             pProperty->Value = uno::makeAny( nFloat );
     574             :                         else
     575           0 :                             throw uno::Exception();
     576             :                     }
     577           0 :                     else if( sPropertyType == "string" )
     578             :                     {
     579           0 :                         pProperty->Value = uno::makeAny( sNewValue );
     580             :                     }
     581           0 :                     else if( sPropertyType == "[]short" )
     582             :                     {
     583             :                         //create string sequence from comma separated string
     584             :                         //uno::Sequence< OUString > seqStr;
     585           0 :                         std::vector< OUString > seqStr;
     586           0 :                         seqStr = commaStringToSequence( sNewValue );
     587             : 
     588             :                         //create appropriate sequence with same size as string sequence
     589           0 :                         uno::Sequence< sal_Int16 > seqShort( seqStr.size() );
     590             :                         //convert all strings to appropriate type
     591           0 :                         for( size_t i = 0; i < seqStr.size(); ++i )
     592             :                         {
     593           0 :                             seqShort[i] = (sal_Int16) seqStr[i].toInt32();
     594             :                         }
     595           0 :                         pProperty->Value = uno::makeAny( seqShort );
     596             :                     }
     597           0 :                     else if( sPropertyType == "[]long" )
     598             :                     {
     599           0 :                         std::vector< OUString > seqStrLong;
     600           0 :                         seqStrLong = commaStringToSequence( sNewValue );
     601             : 
     602           0 :                         uno::Sequence< sal_Int32 > seqLong( seqStrLong.size() );
     603           0 :                         for( size_t i = 0; i < seqStrLong.size(); ++i )
     604             :                         {
     605           0 :                             seqLong[i] = seqStrLong[i].toInt32();
     606             :                         }
     607           0 :                         pProperty->Value = uno::makeAny( seqLong );
     608             :                     }
     609           0 :                     else if( sPropertyType == "[]hyper" )
     610             :                     {
     611           0 :                         std::vector< OUString > seqStrHyper;
     612           0 :                         seqStrHyper = commaStringToSequence( sNewValue );
     613           0 :                         uno::Sequence< sal_Int64 > seqHyper( seqStrHyper.size() );
     614           0 :                         for( size_t i = 0; i < seqStrHyper.size(); ++i )
     615             :                         {
     616           0 :                             seqHyper[i] = seqStrHyper[i].toInt64();
     617             :                         }
     618           0 :                         pProperty->Value = uno::makeAny( seqHyper );
     619             :                     }
     620           0 :                     else if( sPropertyType == "[]double" )
     621             :                     {
     622           0 :                         std::vector< OUString > seqStrDoub;
     623           0 :                         seqStrDoub = commaStringToSequence( sNewValue );
     624           0 :                         uno::Sequence< double > seqDoub( seqStrDoub.size() );
     625           0 :                         for( size_t i = 0; i < seqStrDoub.size(); ++i )
     626             :                         {
     627           0 :                             seqDoub[i] = seqStrDoub[i].toDouble();
     628             :                         }
     629           0 :                         pProperty->Value = uno::makeAny( seqDoub );
     630             :                     }
     631           0 :                     else if( sPropertyType == "[]float" )
     632             :                     {
     633           0 :                         std::vector< OUString > seqStrFloat;
     634           0 :                         seqStrFloat = commaStringToSequence( sNewValue );
     635           0 :                         uno::Sequence< sal_Int16 > seqFloat( seqStrFloat.size() );
     636           0 :                         for( size_t i = 0; i < seqStrFloat.size(); ++i )
     637             :                         {
     638           0 :                             seqFloat[i] = seqStrFloat[i].toFloat();
     639             :                         }
     640           0 :                         pProperty->Value = uno::makeAny( seqFloat );
     641             :                     }
     642           0 :                     else if( sPropertyType == "[]string" )
     643             :                     {
     644           0 :                         pProperty->Value = uno::makeAny( comphelper::containerToSequence( commaStringToSequence( sNewValue )));
     645             :                     }
     646             :                     else //unknown
     647           0 :                         throw uno::Exception();
     648             : 
     649             : 
     650           0 :                 sDialogValue = sNewValue;
     651             :             }
     652             :         }
     653           0 :         AddToModifiedVector( pProperty );
     654             : 
     655             :         //update listbox value.
     656           0 :         m_pPrefBox->SetEntryText( sDialogValue,  pEntry, 3 );
     657             :     }
     658           0 :     catch( uno::Exception& )
     659             :     {
     660             :     }
     661             : 
     662           0 :     return 0;
     663           0 : }
     664             : 
     665             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10