LCOV - code coverage report
Current view: top level - cui/source/options - optaboutconfig.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 387 0.0 %
Date: 2015-06-13 12:38:46 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             : 
      10             : #include "optaboutconfig.hxx"
      11             : #include "optHeaderTabListbox.hxx"
      12             : 
      13             : #include <vcl/builderfactory.hxx>
      14             : #include <svtools/svlbitm.hxx>
      15             : #include <svtools/treelistentry.hxx>
      16             : #include <comphelper/processfactory.hxx>
      17             : #include <comphelper/sequence.hxx>
      18             : #include <com/sun/star/configuration/theDefaultProvider.hpp>
      19             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      20             : #include <com/sun/star/beans/NamedValue.hpp>
      21             : #include <com/sun/star/beans/Property.hpp>
      22             : #include <com/sun/star/beans/XProperty.hpp>
      23             : #include <com/sun/star/container/XNameAccess.hpp>
      24             : #include <com/sun/star/container/XNameReplace.hpp>
      25             : #include <com/sun/star/container/XHierarchicalName.hpp>
      26             : #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
      27             : #include <com/sun/star/util/XChangesBatch.hpp>
      28             : #include <com/sun/star/i18n/TransliterationModules.hpp>
      29             : #include <com/sun/star/util/SearchFlags.hpp>
      30             : #include <unotools/textsearch.hxx>
      31             : 
      32             : #include <vector>
      33             : #include <boost/shared_ptr.hpp>
      34             : #include <iostream>
      35             : 
      36             : using namespace svx;
      37             : using namespace ::com::sun::star;
      38             : using namespace com::sun::star::uno;
      39             : using namespace com::sun::star::container;
      40             : 
      41             : #define SHORT_LEN_LIMIT     7
      42             : #define LONG_LEN_LIMIT      11
      43             : #define HYPER_LEN_LIMIT     20
      44             : 
      45           0 : struct Prop_Impl
      46             : {
      47             :     OUString    Name;
      48             :     OUString    Property;
      49             :     Any         Value;
      50             : 
      51           0 :     Prop_Impl( const OUString& sName, const OUString& sProperty, const Any& aValue )
      52             :         : Name( sName )
      53             :         , Property( sProperty )
      54           0 :         , Value( aValue )
      55           0 :     {}
      56             : };
      57             : 
      58           0 : VCL_BUILDER_FACTORY_ARGS(CuiCustomMultilineEdit,WB_LEFT|WB_VCENTER|WB_BORDER|WB_3DLOOK)
      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             :     m_pPrefCtrl( get<SvSimpleTableContainer>("preferences") ),
     125             :     m_pResetBtn( get<PushButton>("reset") ),
     126             :     m_pEditBtn( get<PushButton>("edit") ),
     127             :     m_pSearchBtn( get<PushButton>("searchButton") ),
     128             :     m_pSearchEdit( get<Edit>("searchEntry") ),
     129             :     m_vectorOfModified(),
     130           0 :     m_pPrefBox( VclPtr<SvSimpleTable>::Create(*m_pPrefCtrl, WB_SCROLL | WB_HSCROLL | WB_VSCROLL ) )
     131             : {
     132           0 :     Size aControlSize(LogicToPixel(Size(385, 230), MAP_APPFONT));
     133           0 :     m_pPrefCtrl->set_width_request(aControlSize.Width());
     134           0 :     m_pPrefCtrl->set_height_request(aControlSize.Height());
     135             : 
     136           0 :     m_pEditBtn->SetClickHdl( LINK( this, CuiAboutConfigTabPage, StandardHdl_Impl ) );
     137           0 :     m_pResetBtn->SetClickHdl( LINK( this, CuiAboutConfigTabPage, ResetBtnHdl_Impl ) );
     138           0 :     m_pPrefBox->SetDoubleClickHdl( LINK(this, CuiAboutConfigTabPage, StandardHdl_Impl) );
     139           0 :     m_pSearchBtn->SetClickHdl( LINK(this, CuiAboutConfigTabPage, SearchHdl_Impl) );
     140             : 
     141           0 :     m_pPrefBox->InsertHeaderEntry(get<FixedText>("preference")->GetText());
     142           0 :     m_pPrefBox->InsertHeaderEntry(get<FixedText>("property")->GetText());
     143           0 :     m_pPrefBox->InsertHeaderEntry(get<FixedText>("type")->GetText());
     144           0 :     m_pPrefBox->InsertHeaderEntry(get<FixedText>("value")->GetText());
     145             : 
     146           0 :     long aTabs[] = {4,0,0,0,0};
     147             : 
     148           0 :     float fWidth = approximate_char_width();
     149             : 
     150           0 :     aTabs[1] = 0;
     151           0 :     aTabs[2] = aTabs[1] + fWidth * 65;
     152           0 :     aTabs[3] = aTabs[2] + fWidth * 20;
     153           0 :     aTabs[4] = aTabs[3] + fWidth * 8;
     154             : 
     155           0 :     m_options.algorithmType = util::SearchAlgorithms_ABSOLUTE;
     156           0 :     m_options.transliterateFlags |= i18n::TransliterationModules_IGNORE_CASE;
     157             :     m_options.searchFlag |= (util::SearchFlags::REG_NOT_BEGINOFLINE |
     158           0 :                                         util::SearchFlags::REG_NOT_ENDOFLINE);
     159             : 
     160           0 :     m_pPrefBox->SetTabs(aTabs, MAP_PIXEL);
     161           0 :     m_pPrefBox->SetAlternatingRowColors( true );
     162           0 : }
     163             : 
     164           0 : CuiAboutConfigTabPage::~CuiAboutConfigTabPage()
     165             : {
     166           0 :     disposeOnce();
     167           0 : }
     168             : 
     169           0 : void CuiAboutConfigTabPage::dispose()
     170             : {
     171           0 :     m_pPrefBox.disposeAndClear();
     172           0 :     m_pPrefCtrl.clear();
     173           0 :     m_pResetBtn.clear();
     174           0 :     m_pEditBtn.clear();
     175           0 :     m_pSearchBtn.clear();
     176           0 :     m_pSearchEdit.clear();
     177           0 :     ModelessDialog::dispose();
     178           0 : }
     179             : 
     180           0 : void CuiAboutConfigTabPage::InsertEntry(const OUString& rProp, const OUString& rStatus, const OUString& rType, const OUString& rValue)
     181             : {
     182           0 :     SvTreeListEntry* pEntry = new SvTreeListEntry;
     183             : 
     184           0 :     pEntry->AddItem( new SvLBoxContextBmp( pEntry, 0, Image(), Image(), false)); //It is needed, otherwise causes crash
     185           0 :     pEntry->AddItem( new SvLBoxString( pEntry, 0, rProp));
     186           0 :     pEntry->AddItem( new SvLBoxString( pEntry, 0, rStatus));
     187           0 :     pEntry->AddItem( new SvLBoxString( pEntry, 0, rType));
     188           0 :     pEntry->AddItem( new SvLBoxString( pEntry, 0, rValue));
     189             : 
     190           0 :     m_pPrefBox->Insert( pEntry );
     191             : 
     192           0 :     SvTreeListEntry* pEntryClone = new SvTreeListEntry;
     193           0 :     pEntryClone->Clone( pEntry );
     194           0 :     m_prefBoxEntries.push_back( pEntryClone );
     195           0 : }
     196             : 
     197           0 : void CuiAboutConfigTabPage::Reset()
     198             : {
     199           0 :     m_pPrefBox->Clear();
     200             : 
     201           0 :     m_vectorOfModified.clear();
     202           0 :     m_pPrefBox->GetModel()->SetSortMode( SortNone );
     203             : 
     204           0 :     m_pPrefBox->SetUpdateMode(false);
     205           0 :     Reference< XNameAccess > xConfigAccess = getConfigAccess( "/", false );
     206           0 :     FillItems( xConfigAccess );
     207           0 :     m_pPrefBox->SetUpdateMode(true);
     208           0 : }
     209             : 
     210           0 : bool CuiAboutConfigTabPage::FillItemSet()
     211             : {
     212           0 :     bool bModified = false;
     213             : 
     214           0 :     std::vector< boost::shared_ptr< Prop_Impl > >::iterator pIter;
     215           0 :     for( pIter = m_vectorOfModified.begin() ; pIter != m_vectorOfModified.end(); ++pIter )
     216             :     {
     217           0 :         Reference< XNameAccess > xUpdateAccess = getConfigAccess( (*pIter)->Name , true );
     218           0 :         Reference< XNameReplace > xNameReplace( xUpdateAccess, UNO_QUERY_THROW );
     219             : 
     220           0 :         xNameReplace->replaceByName( (*pIter)->Property, (*pIter)->Value );
     221           0 :         bModified = true;
     222             : 
     223           0 :         Reference< util::XChangesBatch > xChangesBatch( xUpdateAccess, UNO_QUERY_THROW );
     224           0 :         xChangesBatch->commitChanges();
     225           0 :     }
     226             : 
     227           0 :     return bModified;
     228             : }
     229             : 
     230           0 : void CuiAboutConfigTabPage::FillItems(const Reference< XNameAccess >& xNameAccess)
     231             : {
     232             :     OUString sPath = Reference< XHierarchicalName >(
     233           0 :         xNameAccess, uno::UNO_QUERY_THROW )->getHierarchicalName();
     234           0 :     uno::Sequence< OUString > seqItems = xNameAccess->getElementNames();
     235           0 :     for( sal_Int32 i = 0; i < seqItems.getLength(); ++i )
     236             :     {
     237           0 :         Any aNode = xNameAccess->getByName( seqItems[i] );
     238             : 
     239           0 :         bool bNotLeaf = false;
     240             : 
     241           0 :         Reference< XNameAccess > xNextNameAccess;
     242             :         try
     243             :         {
     244           0 :             xNextNameAccess = Reference< XNameAccess >(aNode, uno::UNO_QUERY);
     245           0 :             bNotLeaf = xNextNameAccess.is();
     246             :         }
     247           0 :         catch (const RuntimeException& e)
     248             :         {
     249             :             SAL_WARN( "cui.options", "CuiAboutConfigTabPage: exception " << e.Message);
     250             :         }
     251             : 
     252           0 :         if (bNotLeaf)
     253             :         {
     254             :             // not leaf node
     255           0 :             FillItems( xNextNameAccess );
     256             :         }
     257             :         else
     258             :         {
     259             :             // leaf node
     260           0 :             OUString sType = aNode.getValueTypeName();
     261             : 
     262           0 :             OUString sValue;
     263           0 :             switch( aNode.getValueType().getTypeClass() )
     264             :             {
     265             :             case ::com::sun::star::uno::TypeClass_VOID:
     266           0 :                 break;
     267             : 
     268             :             case ::com::sun::star::uno::TypeClass_BOOLEAN:
     269           0 :                 sValue = OUString::boolean( aNode.get<bool>() );
     270           0 :                 break;
     271             : 
     272             :             case ::com::sun::star::uno::TypeClass_SHORT:
     273             :             case ::com::sun::star::uno::TypeClass_LONG:
     274             :             case ::com::sun::star::uno::TypeClass_HYPER:
     275           0 :                 sValue = OUString::number( aNode.get<sal_Int64>() );
     276           0 :                 break;
     277             : 
     278             :             case ::com::sun::star::uno::TypeClass_DOUBLE:
     279           0 :                 sValue = OUString::number( aNode.get<double>() );
     280           0 :                 break;
     281             : 
     282             :             case ::com::sun::star::uno::TypeClass_STRING:
     283           0 :                 sValue = aNode.get<OUString>();
     284           0 :                 break;
     285             : 
     286             :             case ::com::sun::star::uno::TypeClass_SEQUENCE:
     287           0 :                 if( sType == "[]boolean" )
     288             :                 {
     289           0 :                     uno::Sequence<sal_Bool> seq = aNode.get< uno::Sequence<sal_Bool> >();
     290           0 :                     for( sal_Int32 j = 0; j != seq.getLength(); ++j )
     291             :                     {
     292           0 :                         if( j != 0 )
     293             :                         {
     294           0 :                             sValue += ",";
     295             :                         }
     296           0 :                         sValue += OUString::boolean( seq[j] );
     297           0 :                     }
     298             :                 }
     299           0 :                 else if( sType == "[]byte" )
     300             :                 {
     301           0 :                     uno::Sequence<sal_Int8> seq = aNode.get< uno::Sequence<sal_Int8> >();
     302           0 :                     for( sal_Int32 j = 0; j != seq.getLength(); ++j )
     303             :                     {
     304             :                         OUString s = OUString::number(
     305           0 :                             static_cast<sal_uInt8>(seq[j]), 16 );
     306           0 :                         if( s.getLength() == 1 )
     307             :                         {
     308           0 :                             sValue += "0";
     309             :                         }
     310           0 :                         sValue += s.toAsciiUpperCase();
     311           0 :                     }
     312             :                 }
     313           0 :                 else if( sType == "[][]byte" )
     314             :                 {
     315           0 :                     uno::Sequence< uno::Sequence<sal_Int8> > seq = aNode.get< uno::Sequence< uno::Sequence<sal_Int8> > >();
     316           0 :                     for( sal_Int32 j = 0; j != seq.getLength(); ++j )
     317             :                     {
     318           0 :                         if( j != 0 )
     319             :                         {
     320           0 :                             sValue += ",";
     321             :                         }
     322           0 :                         for( sal_Int32 k = 0; k != seq[j].getLength(); ++k )
     323             :                         {
     324             :                             OUString s = OUString::number(
     325           0 :                                 static_cast<sal_uInt8>(seq[j][k]), 16 );
     326           0 :                             if( s.getLength() == 1 )
     327             :                             {
     328           0 :                                 sValue += "0";
     329             :                             }
     330           0 :                             sValue += s.toAsciiUpperCase();
     331           0 :                         }
     332           0 :                     }
     333             :                 }
     334           0 :                 else if( sType == "[]short" )
     335             :                 {
     336           0 :                     uno::Sequence<sal_Int16> seq = aNode.get< uno::Sequence<sal_Int16> >();
     337           0 :                     for( sal_Int32 j = 0; j != seq.getLength(); ++j )
     338             :                     {
     339           0 :                         if( j != 0 )
     340             :                         {
     341           0 :                             sValue += ",";
     342             :                         }
     343           0 :                         sValue += OUString::number( seq[j] );
     344           0 :                     }
     345             :                 }
     346           0 :                 else if( sType == "[]long" )
     347             :                 {
     348           0 :                     uno::Sequence<sal_Int32> seq = aNode.get< uno::Sequence<sal_Int32> >();
     349           0 :                     for( sal_Int32 j = 0; j != seq.getLength(); ++j )
     350             :                     {
     351           0 :                         if( j != 0 )
     352             :                         {
     353           0 :                             sValue += ",";
     354             :                         }
     355           0 :                         sValue += OUString::number( seq[j] );
     356           0 :                     }
     357             :                 }
     358           0 :                 else if( sType == "[]hyper" )
     359             :                 {
     360           0 :                     uno::Sequence<sal_Int64> seq = aNode.get< uno::Sequence<sal_Int64> >();
     361           0 :                     for( sal_Int32 j = 0; j != seq.getLength(); ++j )
     362             :                     {
     363           0 :                         if( j != 0 )
     364             :                         {
     365           0 :                             sValue += ",";
     366             :                         }
     367           0 :                         sValue += OUString::number( seq[j] );
     368           0 :                     }
     369             :                 }
     370           0 :                 else if( sType == "[]double" )
     371             :                 {
     372           0 :                     uno::Sequence<double> seq = aNode.get< uno::Sequence<double> >();
     373           0 :                     for( sal_Int32 j = 0; j != seq.getLength(); ++j )
     374             :                     {
     375           0 :                         if( j != 0 )
     376             :                         {
     377           0 :                             sValue += ",";
     378             :                         }
     379           0 :                         sValue += OUString::number( seq[j] );
     380           0 :                     }
     381             :                 }
     382           0 :                 else if( sType == "[]string" )
     383             :                 {
     384           0 :                     uno::Sequence<OUString> seq = aNode.get< uno::Sequence<OUString> >();
     385           0 :                     for( sal_Int32 j = 0; j != seq.getLength(); ++j )
     386             :                     {
     387           0 :                         if( j != 0 )
     388             :                         {
     389           0 :                             sValue += ",";
     390             :                         }
     391           0 :                         sValue += seq[j];
     392           0 :                     }
     393             :                 }
     394             :                 else
     395             :                 {
     396             :                     SAL_WARN(
     397             :                         "cui.options",
     398             :                         "path \"" << sPath << "\" member " << seqItems[i]
     399             :                             << " of unsupported type " << sType);
     400             :                 }
     401           0 :                 break;
     402             : 
     403             :             default:
     404             :                 SAL_WARN(
     405             :                     "cui.options",
     406             :                     "path \"" << sPath << "\" member " << seqItems[i]
     407             :                         << " of unsupported type " << sType);
     408           0 :                 break;
     409             :             }
     410             : 
     411           0 :             InsertEntry( sPath, seqItems[i], sType, sValue);
     412             :         }
     413           0 :     }
     414           0 : }
     415             : 
     416           0 : Reference< XNameAccess > CuiAboutConfigTabPage::getConfigAccess( const OUString& sNodePath, bool bUpdate )
     417             : {
     418           0 :     uno::Reference< uno::XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
     419             : 
     420             :     uno::Reference< lang::XMultiServiceFactory > xConfigProvider(
     421           0 :                 com::sun::star::configuration::theDefaultProvider::get( xContext  ) );
     422             : 
     423           0 :     beans::NamedValue aProperty;
     424           0 :     aProperty.Name = "nodepath";
     425           0 :     aProperty.Value = uno::makeAny( sNodePath );
     426             : 
     427           0 :     uno::Sequence< uno::Any > aArgumentList( 1 );
     428           0 :     aArgumentList[0] = uno::makeAny( aProperty );
     429             : 
     430           0 :     OUString sAccessString;
     431             : 
     432           0 :     if( bUpdate )
     433           0 :         sAccessString = "com.sun.star.configuration.ConfigurationUpdateAccess";
     434             :     else
     435           0 :         sAccessString = "com.sun.star.configuration.ConfigurationAccess";
     436             : 
     437             :     uno::Reference< container::XNameAccess > xNameAccess(
     438           0 :                 xConfigProvider->createInstanceWithArguments(
     439           0 :                     sAccessString, aArgumentList ),
     440           0 :                 uno::UNO_QUERY_THROW );
     441             : 
     442           0 :     return xNameAccess;
     443             : }
     444             : 
     445           0 : void CuiAboutConfigTabPage::AddToModifiedVector( const boost::shared_ptr< Prop_Impl >& rProp )
     446             : {
     447           0 :     bool isModifiedBefore = false;
     448             :     //Check if value modified before
     449           0 :     for( size_t nInd = 0; nInd < m_vectorOfModified.size() ; ++nInd )
     450             :     {
     451           0 :         if( rProp->Name == m_vectorOfModified[nInd]->Name && rProp->Property == m_vectorOfModified[nInd]->Property )
     452             :         {
     453             :             //property modified before. assing reference to the modified value
     454             :             //do your changes on this object. They will be saved later.
     455           0 :             m_vectorOfModified[nInd] = rProp;
     456           0 :             isModifiedBefore = true;
     457           0 :             break;
     458             :         }
     459             :     }
     460             : 
     461           0 :     if( !isModifiedBefore )
     462           0 :         m_vectorOfModified.push_back( rProp );
     463             :     //property is not modified before
     464           0 : }
     465             : 
     466           0 : std::vector< OUString > CuiAboutConfigTabPage::commaStringToSequence( const OUString& rCommaSepString )
     467             : {
     468           0 :     std::vector<OUString> tempVector;
     469             : 
     470           0 :     sal_Int32 index = 0;
     471           0 :     do
     472             :     {
     473           0 :         OUString word = rCommaSepString.getToken(0, static_cast<sal_Unicode> (','), index);
     474           0 :         word = word.trim();
     475           0 :         if( !word.isEmpty())
     476           0 :             tempVector.push_back(word);
     477           0 :     }while( index >= 0 );
     478           0 :     return tempVector;
     479             : }
     480             : 
     481           0 : CuiAboutConfigValueDialog::CuiAboutConfigValueDialog( vcl::Window* pWindow,
     482             :                                                       const OUString& rValue,
     483             :                                                       int limit ) :
     484             :     ModalDialog( pWindow, "AboutConfigValueDialog", "cui/ui/aboutconfigvaluedialog.ui" ),
     485           0 :     m_pEDValue( get<CuiCustomMultilineEdit>("valuebox") )
     486             : {
     487           0 :     m_pEDValue->bNumericOnly = ( limit !=0 );
     488           0 :     m_pEDValue->SetMaxTextLen( limit == 0 ? EDIT_NOLIMIT : limit);
     489           0 :     m_pEDValue->SetText( rValue );
     490             : 
     491           0 : }
     492             : 
     493           0 : CuiAboutConfigValueDialog::~CuiAboutConfigValueDialog()
     494             : {
     495           0 :     disposeOnce();
     496           0 : }
     497             : 
     498           0 : void CuiAboutConfigValueDialog::dispose()
     499             : {
     500           0 :     m_pEDValue.clear();
     501           0 :     ModalDialog::dispose();
     502           0 : }
     503             : 
     504           0 : IMPL_LINK_NOARG( CuiAboutConfigTabPage, ResetBtnHdl_Impl )
     505             : {
     506           0 :     Reset();
     507           0 :     return 0;
     508             : }
     509             : 
     510           0 : IMPL_LINK_NOARG( CuiAboutConfigTabPage, StandardHdl_Impl )
     511             : {
     512           0 :     SvTreeListEntry* pEntry = m_pPrefBox->FirstSelected();
     513             : 
     514           0 :     OUString sPropertyPath = SvTabListBox::GetEntryText( pEntry, 0 );
     515           0 :     OUString sPropertyName = SvTabListBox::GetEntryText( pEntry, 1 );
     516           0 :     OUString sPropertyType = SvTabListBox::GetEntryText( pEntry, 2 );
     517           0 :     OUString sPropertyValue = SvTabListBox::GetEntryText( pEntry, 3 );
     518             : 
     519           0 :     boost::shared_ptr< Prop_Impl > pProperty (new Prop_Impl( sPropertyPath, sPropertyName, makeAny( sPropertyValue ) ) );
     520             : 
     521             :     bool bOpenDialog;
     522           0 :     OUString sDialogValue;
     523           0 :     OUString sNewValue;
     524             : 
     525           0 :     if( sPropertyType == "boolean" )
     526             :     {
     527             :         bool bValue;
     528           0 :         if( sPropertyValue == "true" )
     529             :         {
     530           0 :             sDialogValue = "false";
     531           0 :             bValue = false;
     532             :         }
     533             :         else
     534             :         {
     535           0 :             sDialogValue = "true";
     536           0 :             bValue = true;
     537             :         }
     538             : 
     539           0 :         pProperty->Value = uno::makeAny( bValue );
     540           0 :         bOpenDialog = false;
     541             :     }
     542           0 :     else if ( sPropertyType == "void" )
     543             :     {
     544           0 :         bOpenDialog = false;
     545             :     }
     546             :     else
     547             :     {
     548           0 :         sDialogValue = sPropertyValue;
     549           0 :         bOpenDialog = true;
     550             :     }
     551             : 
     552             :     try
     553             :     {
     554           0 :         if( bOpenDialog )
     555             :         {
     556             :             //Cosmetic length limit for integer values.
     557           0 :             int limit=0;
     558           0 :             if( sPropertyType == "short" )
     559           0 :                 limit = SHORT_LEN_LIMIT;
     560           0 :             else if( sPropertyType == "long" )
     561           0 :                 limit = LONG_LEN_LIMIT;
     562           0 :             else if( sPropertyType == "hyper" )
     563           0 :                 limit = HYPER_LEN_LIMIT;
     564             : 
     565           0 :             VclPtrInstance<CuiAboutConfigValueDialog> pValueDialog(nullptr, sDialogValue, limit);
     566             : 
     567           0 :             if( pValueDialog->Execute() == RET_OK )
     568             :             {
     569           0 :                 sNewValue = pValueDialog->getValue();
     570           0 :                 if ( sPropertyType == "short")
     571             :                 {
     572             :                     sal_Int16 nShort;
     573           0 :                     sal_Int32 nNumb = sNewValue.toInt32();
     574             : 
     575             :                     //if the value is 0 and length is not 1, there is something wrong
     576           0 :                     if( !( nNumb==0 && sNewValue.getLength()!=1 ) && nNumb < SAL_MAX_INT16 && nNumb > SAL_MIN_INT16)
     577           0 :                         nShort = (sal_Int16) nNumb;
     578             :                     else
     579           0 :                         throw uno::Exception();
     580           0 :                     pProperty->Value = uno::makeAny( nShort );
     581             :                 }
     582             :                 else
     583           0 :                     if( sPropertyType == "long" )
     584             :                     {
     585           0 :                         sal_Int32 nLong = sNewValue.toInt32();
     586           0 :                         if( !( nLong==0 && sNewValue.getLength()!=1 ) && nLong < SAL_MAX_INT32 && nLong > SAL_MIN_INT32)
     587           0 :                             pProperty->Value = uno::makeAny( nLong );
     588             :                         else
     589           0 :                             throw uno::Exception();
     590             :                     }
     591           0 :                     else if( sPropertyType == "hyper")
     592             :                     {
     593           0 :                         sal_Int64 nHyper = sNewValue.toInt64();
     594           0 :                         if( !( nHyper==0 && sNewValue.getLength()!=1 ) && nHyper < SAL_MAX_INT32 && nHyper > SAL_MIN_INT32)
     595           0 :                             pProperty->Value = uno::makeAny( nHyper );
     596             :                         else
     597           0 :                             throw uno::Exception();
     598             :                     }
     599           0 :                     else if( sPropertyType == "double")
     600             :                     {
     601           0 :                         double nDoub = sNewValue.toDouble();
     602           0 :                         if( !( nDoub ==0 && sNewValue.getLength()!=1 ) && nDoub < SAL_MAX_INT32 && nDoub > SAL_MIN_INT32)
     603           0 :                             pProperty->Value = uno::makeAny( nDoub );
     604             :                         else
     605           0 :                             throw uno::Exception();
     606             :                     }
     607           0 :                     else if( sPropertyType == "float")
     608             :                     {
     609           0 :                         float nFloat = sNewValue.toFloat();
     610           0 :                         if( !( nFloat ==0 && sNewValue.getLength()!=1 ) && nFloat < SAL_MAX_INT32 && nFloat > SAL_MIN_INT32)
     611           0 :                             pProperty->Value = uno::makeAny( nFloat );
     612             :                         else
     613           0 :                             throw uno::Exception();
     614             :                     }
     615           0 :                     else if( sPropertyType == "string" )
     616             :                     {
     617           0 :                         pProperty->Value = uno::makeAny( sNewValue );
     618             :                     }
     619           0 :                     else if( sPropertyType == "[]short" )
     620             :                     {
     621             :                         //create string sequence from comma separated string
     622             :                         //uno::Sequence< OUString > seqStr;
     623           0 :                         std::vector< OUString > seqStr;
     624           0 :                         seqStr = commaStringToSequence( sNewValue );
     625             : 
     626             :                         //create appropriate sequence with same size as string sequence
     627           0 :                         uno::Sequence< sal_Int16 > seqShort( seqStr.size() );
     628             :                         //convert all strings to appropriate type
     629           0 :                         for( size_t i = 0; i < seqStr.size(); ++i )
     630             :                         {
     631           0 :                             seqShort[i] = (sal_Int16) seqStr[i].toInt32();
     632             :                         }
     633           0 :                         pProperty->Value = uno::makeAny( seqShort );
     634             :                     }
     635           0 :                     else if( sPropertyType == "[]long" )
     636             :                     {
     637           0 :                         std::vector< OUString > seqStrLong;
     638           0 :                         seqStrLong = commaStringToSequence( sNewValue );
     639             : 
     640           0 :                         uno::Sequence< sal_Int32 > seqLong( seqStrLong.size() );
     641           0 :                         for( size_t i = 0; i < seqStrLong.size(); ++i )
     642             :                         {
     643           0 :                             seqLong[i] = seqStrLong[i].toInt32();
     644             :                         }
     645           0 :                         pProperty->Value = uno::makeAny( seqLong );
     646             :                     }
     647           0 :                     else if( sPropertyType == "[]hyper" )
     648             :                     {
     649           0 :                         std::vector< OUString > seqStrHyper;
     650           0 :                         seqStrHyper = commaStringToSequence( sNewValue );
     651           0 :                         uno::Sequence< sal_Int64 > seqHyper( seqStrHyper.size() );
     652           0 :                         for( size_t i = 0; i < seqStrHyper.size(); ++i )
     653             :                         {
     654           0 :                             seqHyper[i] = seqStrHyper[i].toInt64();
     655             :                         }
     656           0 :                         pProperty->Value = uno::makeAny( seqHyper );
     657             :                     }
     658           0 :                     else if( sPropertyType == "[]double" )
     659             :                     {
     660           0 :                         std::vector< OUString > seqStrDoub;
     661           0 :                         seqStrDoub = commaStringToSequence( sNewValue );
     662           0 :                         uno::Sequence< double > seqDoub( seqStrDoub.size() );
     663           0 :                         for( size_t i = 0; i < seqStrDoub.size(); ++i )
     664             :                         {
     665           0 :                             seqDoub[i] = seqStrDoub[i].toDouble();
     666             :                         }
     667           0 :                         pProperty->Value = uno::makeAny( seqDoub );
     668             :                     }
     669           0 :                     else if( sPropertyType == "[]float" )
     670             :                     {
     671           0 :                         std::vector< OUString > seqStrFloat;
     672           0 :                         seqStrFloat = commaStringToSequence( sNewValue );
     673           0 :                         uno::Sequence< sal_Int16 > seqFloat( seqStrFloat.size() );
     674           0 :                         for( size_t i = 0; i < seqStrFloat.size(); ++i )
     675             :                         {
     676           0 :                             seqFloat[i] = seqStrFloat[i].toFloat();
     677             :                         }
     678           0 :                         pProperty->Value = uno::makeAny( seqFloat );
     679             :                     }
     680           0 :                     else if( sPropertyType == "[]string" )
     681             :                     {
     682           0 :                         pProperty->Value = uno::makeAny( comphelper::containerToSequence( commaStringToSequence( sNewValue )));
     683             :                     }
     684             :                     else //unknown
     685           0 :                         throw uno::Exception();
     686             : 
     687             : 
     688           0 :                 sDialogValue = sNewValue;
     689           0 :             }
     690             :         }
     691           0 :         AddToModifiedVector( pProperty );
     692             : 
     693             :         //update listbox value.
     694           0 :         m_pPrefBox->SetEntryText( sDialogValue,  pEntry, 3 );
     695             :         //update m_prefBoxEntries
     696             :         SvTreeListEntries::iterator it = std::find_if(m_prefBoxEntries.begin(), m_prefBoxEntries.end(),
     697           0 :           [&sPropertyPath, &sPropertyName](SvTreeListEntry &entry) -> bool
     698             :           {
     699           0 :               return static_cast< SvLBoxString* >( entry.GetItem(1) )->GetText().equals( sPropertyPath ) &&
     700           0 :                       static_cast< SvLBoxString* >( entry.GetItem(2) )->GetText().equals( sPropertyName );
     701             :           }
     702           0 :         );
     703           0 :         if (it != m_prefBoxEntries.end())
     704           0 :             it->ReplaceItem( new SvLBoxString( &(*it), 0, sDialogValue ), 4 );
     705             :     }
     706           0 :     catch( uno::Exception& )
     707             :     {
     708             :     }
     709             : 
     710           0 :     return 0;
     711             : }
     712             : 
     713           0 : IMPL_LINK_NOARG( CuiAboutConfigTabPage, SearchHdl_Impl)
     714             : {
     715           0 :     m_pPrefBox->Clear();
     716           0 :     m_pPrefBox->SetUpdateMode( false );
     717             : 
     718           0 :     SvSortMode sortMode = m_pPrefBox->GetModel()->GetSortMode();
     719           0 :     sal_uInt16 sortedCol = m_pPrefBox->GetSortedCol();
     720             : 
     721           0 :     if( sortMode != SortNone )
     722           0 :         m_pPrefBox->SortByCol( 0xFFFF );
     723             : 
     724           0 :     if( m_pSearchEdit->GetText().isEmpty() )
     725             :     {
     726           0 :         for( auto it = m_prefBoxEntries.begin(); it != m_prefBoxEntries.end(); ++it )
     727             :         {
     728           0 :             SvTreeListEntry* pEntry = new SvTreeListEntry;
     729           0 :             pEntry->Clone( &(*it) ) ;
     730           0 :             m_pPrefBox->Insert( pEntry );
     731             :         }
     732             :     }
     733             :     else
     734             :     {
     735           0 :         m_options.searchString = m_pSearchEdit->GetText();
     736           0 :         utl::TextSearch textSearch( m_options );
     737             : 
     738           0 :         for(auto it = m_prefBoxEntries.begin(); it != m_prefBoxEntries.end(); ++it)
     739             :         {
     740           0 :             sal_Int32 endPos, startPos = 0;
     741             : 
     742           0 :             for(size_t i = 1; i < it->ItemCount(); ++i)
     743             :             {
     744           0 :                 OUString scrTxt = static_cast< SvLBoxString* >( it->GetItem(i) )->GetText();
     745           0 :                 endPos = scrTxt.getLength();
     746           0 :                 if( textSearch.SearchForward( scrTxt, &startPos, &endPos ) )
     747             :                 {
     748           0 :                     SvTreeListEntry* pEntry = new SvTreeListEntry;
     749           0 :                     pEntry->Clone( &(*it) ) ;
     750           0 :                     m_pPrefBox->Insert( pEntry );
     751           0 :                     break;
     752             :                 }
     753           0 :             }
     754           0 :         }
     755             :     }
     756             : 
     757           0 :     if( sortMode != SortNone )
     758           0 :         m_pPrefBox->SortByCol(sortedCol, sortMode == SortAscending);
     759             : 
     760           0 :     m_pPrefBox->SetUpdateMode( true );
     761             : 
     762           0 :     return 0;
     763           0 : }
     764             : 
     765             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11