LCOV - code coverage report
Current view: top level - cui/source/options - optpath.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 394 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 32 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <svx/svxdlg.hxx>
      21             : #include <vcl/msgbox.hxx>
      22             : #include <sfx2/filedlghelper.hxx>
      23             : #include <sfx2/app.hxx>
      24             : #include <svl/aeitem.hxx>
      25             : #include <svtools/svtabbx.hxx>
      26             : #include "svtools/treelistentry.hxx"
      27             : #include <tools/urlobj.hxx>
      28             : #include <vcl/svapp.hxx>
      29             : #include <unotools/defaultoptions.hxx>
      30             : #include <unotools/localfilehelper.hxx>
      31             : #include <unotools/pathoptions.hxx>
      32             : #include <unotools/moduleoptions.hxx>
      33             : #include <unotools/viewoptions.hxx>
      34             : 
      35             : #include "optpath.hxx"
      36             : #include <dialmgr.hxx>
      37             : #include <cuires.hrc>
      38             : #include "helpid.hrc"
      39             : #include <comphelper/configuration.hxx>
      40             : #include <comphelper/processfactory.hxx>
      41             : #include <comphelper/string.hxx>
      42             : #include <com/sun/star/uno/Exception.hpp>
      43             : #include <com/sun/star/beans/XPropertySet.hpp>
      44             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      45             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      46             : #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
      47             : #include <com/sun/star/ui/dialogs/XAsynchronousExecutableDialog.hpp>
      48             : #include <com/sun/star/ui/dialogs/FolderPicker.hpp>
      49             : #include <com/sun/star/util/thePathSettings.hpp>
      50             : #include <officecfg/Office/Common.hxx>
      51             : #include "optHeaderTabListbox.hxx"
      52             : #include <vcl/help.hxx>
      53             : 
      54             : using namespace ::com::sun::star::beans;
      55             : using namespace ::com::sun::star::lang;
      56             : using namespace ::com::sun::star::ui::dialogs;
      57             : using namespace ::com::sun::star::uno;
      58             : using namespace svx;
      59             : 
      60             : // define ----------------------------------------------------------------
      61             : 
      62             : #define TAB_WIDTH_MIN   10
      63             : #define ITEMID_TYPE       1
      64             : #define ITEMID_PATH       2
      65             : 
      66             : #define POSTFIX_INTERNAL    OUString("_internal")
      67             : #define POSTFIX_USER        OUString("_user")
      68             : #define POSTFIX_WRITABLE    OUString("_writable")
      69             : #define VAR_ONE             OUString("%1")
      70             : #define IODLG_CONFIGNAME    OUString("FilePicker_Save")
      71             : 
      72             : // struct OptPath_Impl ---------------------------------------------------
      73             : 
      74           0 : struct OptPath_Impl
      75             : {
      76             :     SvtDefaultOptions           m_aDefOpt;
      77             :     Image                       m_aLockImage;
      78             :     OUString                    m_sMultiPathDlg;
      79             :     Reference< css::util::XPathSettings >   m_xPathSettings;
      80             : 
      81           0 :     OptPath_Impl(const Image& rLockImage, const OUString& rMultiPathDlg)
      82             :         : m_aLockImage(rLockImage)
      83           0 :         , m_sMultiPathDlg(rMultiPathDlg)
      84             :     {
      85           0 :     }
      86             : };
      87             : 
      88             : // struct PathUserData_Impl ----------------------------------------------
      89             : 
      90           0 : struct PathUserData_Impl
      91             : {
      92             :     sal_uInt16      nRealId;
      93             :     SfxItemState    eState;
      94             :     OUString        sUserPath;
      95             :     OUString        sWritablePath;
      96             : 
      97           0 :     PathUserData_Impl( sal_uInt16 nId ) :
      98           0 :         nRealId( nId ), eState( SfxItemState::UNKNOWN ) {}
      99             : };
     100             : 
     101             : struct Handle2CfgNameMapping_Impl
     102             : {
     103             :     sal_uInt16      m_nHandle;
     104             :     const char* m_pCfgName;
     105             : };
     106             : 
     107             : static Handle2CfgNameMapping_Impl const Hdl2CfgMap_Impl[] =
     108             : {
     109             :     { SvtPathOptions::PATH_AUTOCORRECT, "AutoCorrect" },
     110             :     { SvtPathOptions::PATH_AUTOTEXT,    "AutoText" },
     111             :     { SvtPathOptions::PATH_BACKUP,      "Backup" },
     112             :     { SvtPathOptions::PATH_GALLERY,     "Gallery" },
     113             :     { SvtPathOptions::PATH_GRAPHIC,     "Graphic" },
     114             :     { SvtPathOptions::PATH_TEMP,        "Temp" },
     115             :     { SvtPathOptions::PATH_TEMPLATE,    "Template" },
     116             :     { SvtPathOptions::PATH_WORK,        "Work" },
     117             :     { SvtPathOptions::PATH_DICTIONARY,        "Dictionary" },
     118             : #if OSL_DEBUG_LEVEL > 1
     119             :     { SvtPathOptions::PATH_LINGUISTIC,        "Linguistic" },
     120             : #endif
     121             :     { USHRT_MAX, NULL }
     122             : };
     123             : 
     124           0 : static OUString getCfgName_Impl( sal_uInt16 _nHandle )
     125             : {
     126           0 :     OUString sCfgName;
     127           0 :     sal_uInt16 nIndex = 0;
     128           0 :     while ( Hdl2CfgMap_Impl[ nIndex ].m_nHandle != USHRT_MAX )
     129             :     {
     130           0 :         if ( Hdl2CfgMap_Impl[ nIndex ].m_nHandle == _nHandle )
     131             :         {
     132             :             // config name found
     133           0 :             sCfgName = OUString::createFromAscii( Hdl2CfgMap_Impl[ nIndex ].m_pCfgName );
     134           0 :             break;
     135             :         }
     136           0 :         ++nIndex;
     137             :     }
     138             : 
     139           0 :     return sCfgName;
     140             : }
     141             : 
     142             : #define MULTIPATH_DELIMITER     ';'
     143             : 
     144           0 : OUString Convert_Impl( const OUString& rValue )
     145             : {
     146           0 :     char cDelim = MULTIPATH_DELIMITER;
     147           0 :     sal_uInt16 nCount = comphelper::string::getTokenCount(rValue, cDelim);
     148           0 :     OUString aReturn;
     149           0 :     for ( sal_uInt16 i=0; i<nCount ; ++i )
     150             :     {
     151           0 :         OUString aValue = rValue.getToken( i, cDelim );
     152           0 :         INetURLObject aObj( aValue );
     153           0 :         if ( aObj.GetProtocol() == INetProtocol::File )
     154           0 :             aReturn += aObj.PathToFileName();
     155           0 :         else if ( ::utl::LocalFileHelper::IsFileContent( aValue ) )
     156           0 :             aReturn += aObj.GetURLPath( INetURLObject::DECODE_WITH_CHARSET );
     157           0 :         if ( i+1 < nCount)
     158           0 :             aReturn += OUString(MULTIPATH_DELIMITER);
     159           0 :     }
     160             : 
     161           0 :     return aReturn;
     162             : }
     163             : 
     164             : // functions -------------------------------------------------------------
     165             : 
     166           0 : bool IsMultiPath_Impl( const sal_uInt16 nIndex )
     167             : {
     168             : #if OSL_DEBUG_LEVEL > 1
     169             :     return ( SvtPathOptions::PATH_AUTOCORRECT == nIndex ||
     170             :              SvtPathOptions::PATH_AUTOTEXT == nIndex ||
     171             :              SvtPathOptions::PATH_BASIC == nIndex ||
     172             :              SvtPathOptions::PATH_GALLERY == nIndex ||
     173             :              SvtPathOptions::PATH_TEMPLATE == nIndex );
     174             : #else
     175           0 :     return ( SvtPathOptions::PATH_AUTOCORRECT == nIndex ||
     176           0 :              SvtPathOptions::PATH_AUTOTEXT == nIndex ||
     177           0 :              SvtPathOptions::PATH_BASIC == nIndex ||
     178           0 :              SvtPathOptions::PATH_GALLERY == nIndex ||
     179           0 :              SvtPathOptions::PATH_TEMPLATE == nIndex ||
     180           0 :              SvtPathOptions::PATH_LINGUISTIC == nIndex ||
     181           0 :              SvtPathOptions::PATH_DICTIONARY == nIndex  );
     182             : #endif
     183             : }
     184             : 
     185             : // class SvxPathTabPage --------------------------------------------------
     186             : 
     187           0 : SvxPathTabPage::SvxPathTabPage(vcl::Window* pParent, const SfxItemSet& rSet)
     188             :     :SfxTabPage( pParent, "OptPathsPage", "cui/ui/optpathspage.ui", &rSet)
     189           0 :     , xDialogListener ( new ::svt::DialogClosedListener() )
     190             : {
     191           0 :     pImpl = new OptPath_Impl(get<FixedImage>("lock")->GetImage(),
     192           0 :         get<FixedText>("editpaths")->GetText());
     193           0 :     get(m_pStandardBtn, "default");
     194           0 :     get(m_pPathBtn, "edit");
     195           0 :     get(m_pPathCtrl, "paths");
     196             : 
     197           0 :     m_pStandardBtn->SetClickHdl(LINK(this, SvxPathTabPage, StandardHdl_Impl));
     198           0 :     Link<> aLink = LINK( this, SvxPathTabPage, PathHdl_Impl );
     199           0 :     m_pPathBtn->SetClickHdl( aLink );
     200             : 
     201           0 :     Size aControlSize(236 , 147);
     202           0 :     aControlSize = LogicToPixel(aControlSize, MAP_APPFONT);
     203           0 :     m_pPathCtrl->set_width_request(aControlSize.Width());
     204           0 :     m_pPathCtrl->set_height_request(aControlSize.Height());
     205           0 :     WinBits nBits = WB_SORT | WB_HSCROLL | WB_CLIPCHILDREN | WB_TABSTOP;
     206           0 :     pPathBox = VclPtr<svx::OptHeaderTabListBox>::Create( *m_pPathCtrl, nBits );
     207             : 
     208           0 :     HeaderBar &rBar = pPathBox->GetTheHeaderBar();
     209           0 :     rBar.SetSelectHdl( LINK( this, SvxPathTabPage, HeaderSelect_Impl ) );
     210           0 :     rBar.SetEndDragHdl( LINK( this, SvxPathTabPage, HeaderEndDrag_Impl ) );
     211             : 
     212           0 :     rBar.InsertItem( ITEMID_TYPE, get<FixedText>("type")->GetText(),
     213             :                             0,
     214           0 :                             HeaderBarItemBits::LEFT | HeaderBarItemBits::VCENTER | HeaderBarItemBits::CLICKABLE | HeaderBarItemBits::UPARROW );
     215           0 :     rBar.InsertItem( ITEMID_PATH, get<FixedText>("path")->GetText(),
     216             :                             0,
     217           0 :                             HeaderBarItemBits::LEFT | HeaderBarItemBits::VCENTER );
     218             : 
     219           0 :     long nWidth1 = rBar.GetTextWidth(rBar.GetItemText(ITEMID_TYPE));
     220           0 :     long nWidth2 = rBar.GetTextWidth(rBar.GetItemText(ITEMID_PATH));
     221             : 
     222           0 :     long aTabs[] = {3, 0, 0, 0};
     223           0 :     aTabs[2] = nWidth1 + 12;
     224           0 :     aTabs[3] = aTabs[2] + nWidth2 + 12;
     225           0 :     pPathBox->SetTabs(aTabs, MAP_PIXEL);
     226             : 
     227           0 :     pPathBox->SetDoubleClickHdl( aLink );
     228           0 :     pPathBox->SetSelectHdl( LINK( this, SvxPathTabPage, PathSelect_Impl ) );
     229           0 :     pPathBox->SetSelectionMode( MULTIPLE_SELECTION );
     230           0 :     pPathBox->SetHighlightRange();
     231             : 
     232           0 :     xDialogListener->SetDialogClosedLink( LINK( this, SvxPathTabPage, DialogClosedHdl ) );
     233           0 : }
     234             : 
     235             : 
     236             : 
     237           0 : SvxPathTabPage::~SvxPathTabPage()
     238             : {
     239           0 :     disposeOnce();
     240           0 : }
     241             : 
     242           0 : void SvxPathTabPage::dispose()
     243             : {
     244           0 :     if ( pPathBox )
     245             :     {
     246           0 :         for ( sal_uLong i = 0; i < pPathBox->GetEntryCount(); ++i )
     247           0 :             delete static_cast<PathUserData_Impl*>(pPathBox->GetEntry(i)->GetUserData());
     248           0 :         pPathBox.disposeAndClear();
     249             :     }
     250           0 :     delete pImpl;
     251           0 :     pImpl = NULL;
     252           0 :     m_pPathCtrl.clear();
     253           0 :     m_pStandardBtn.clear();
     254           0 :     m_pPathBtn.clear();
     255           0 :     SfxTabPage::dispose();
     256           0 : }
     257             : 
     258           0 : VclPtr<SfxTabPage> SvxPathTabPage::Create( vcl::Window* pParent,
     259             :                                            const SfxItemSet* rAttrSet )
     260             : {
     261           0 :     return VclPtr<SvxPathTabPage>::Create( pParent, *rAttrSet );
     262             : }
     263             : 
     264           0 : bool SvxPathTabPage::FillItemSet( SfxItemSet* )
     265             : {
     266           0 :     for ( sal_uLong i = 0; i < pPathBox->GetEntryCount(); ++i )
     267             :     {
     268           0 :         PathUserData_Impl* pPathImpl = static_cast<PathUserData_Impl*>(pPathBox->GetEntry(i)->GetUserData());
     269           0 :         sal_uInt16 nRealId = pPathImpl->nRealId;
     270           0 :         if ( pPathImpl->eState == SfxItemState::SET )
     271           0 :             SetPathList( nRealId, pPathImpl->sUserPath, pPathImpl->sWritablePath );
     272             :     }
     273           0 :     return true;
     274             : }
     275             : 
     276             : 
     277             : 
     278           0 : void SvxPathTabPage::Reset( const SfxItemSet* )
     279             : {
     280           0 :     pPathBox->Clear();
     281             : 
     282           0 :     HeaderBar &rBar = pPathBox->GetTheHeaderBar();
     283           0 :     long nWidth1 = rBar.GetTextWidth(rBar.GetItemText(1));
     284           0 :     long nWidth2 = rBar.GetTextWidth(rBar.GetItemText(2));
     285             : 
     286           0 :     for( sal_uInt16 i = 0; i <= (sal_uInt16)SvtPathOptions::PATH_WORK; ++i )
     287             :     {
     288             :         // only writer uses autotext
     289           0 :         if ( i == SvtPathOptions::PATH_AUTOTEXT
     290           0 :             && !SvtModuleOptions().IsModuleInstalled( SvtModuleOptions::EModule::WRITER ) )
     291           0 :             continue;
     292             : 
     293           0 :         switch (i)
     294             :         {
     295             :             case SvtPathOptions::PATH_AUTOCORRECT:
     296             :             case SvtPathOptions::PATH_AUTOTEXT:
     297             :             case SvtPathOptions::PATH_BACKUP:
     298             :             case SvtPathOptions::PATH_GALLERY:
     299             :             case SvtPathOptions::PATH_GRAPHIC:
     300             :             case SvtPathOptions::PATH_TEMP:
     301             :             case SvtPathOptions::PATH_TEMPLATE:
     302             :             case SvtPathOptions::PATH_DICTIONARY:
     303             : #if OSL_DEBUG_LEVEL > 1
     304             :             case SvtPathOptions::PATH_LINGUISTIC:
     305             : #endif
     306             :             case SvtPathOptions::PATH_WORK:
     307             :             {
     308           0 :                 OUString aStr( CUI_RES( RID_SVXSTR_PATH_NAME_START + i ) );
     309           0 :                 nWidth1 = std::max(nWidth1, pPathBox->GetTextWidth(aStr));
     310           0 :                 aStr += "\t";
     311           0 :                 OUString sInternal, sUser, sWritable;
     312           0 :                 bool bReadOnly = false;
     313           0 :                 GetPathList( i, sInternal, sUser, sWritable, bReadOnly );
     314           0 :                 OUString sTmpPath = sUser;
     315           0 :                 if ( !sTmpPath.isEmpty() && !sWritable.isEmpty() )
     316           0 :                     sTmpPath += OUString(MULTIPATH_DELIMITER);
     317           0 :                 sTmpPath += sWritable;
     318           0 :                 OUString aValue( sTmpPath );
     319           0 :                 aValue = Convert_Impl( aValue );
     320           0 :                 nWidth2 = std::max(nWidth2, pPathBox->GetTextWidth(aValue));
     321           0 :                 aStr += aValue;
     322           0 :                 SvTreeListEntry* pEntry = pPathBox->InsertEntry( aStr );
     323           0 :                 if ( bReadOnly )
     324             :                 {
     325           0 :                     pPathBox->SetCollapsedEntryBmp( pEntry, pImpl->m_aLockImage );
     326             :                 }
     327           0 :                 PathUserData_Impl* pPathImpl = new PathUserData_Impl(i);
     328           0 :                 pPathImpl->sUserPath = sUser;
     329           0 :                 pPathImpl->sWritablePath = sWritable;
     330           0 :                 pEntry->SetUserData( pPathImpl );
     331             :             }
     332             :         }
     333             :     }
     334             : 
     335           0 :     long aTabs[] = {3, 0, 0, 0};
     336           0 :     aTabs[2] = nWidth1 + 12;
     337           0 :     aTabs[3] = aTabs[2] + nWidth2 + 12;
     338           0 :     pPathBox->SetTabs(aTabs, MAP_PIXEL);
     339             : 
     340             : #if 0
     341             :     String aUserData = GetUserData();
     342             :     if ( aUserData.Len() )
     343             :     {
     344             :         fprintf(stderr, "FOO\n");
     345             : 
     346             :         // restore column width
     347             :         rBar.SetItemSize( ITEMID_TYPE, aUserData.GetToken(0).ToInt32() );
     348             :         HeaderEndDrag_Impl( &rBar );
     349             :         // restore sort direction
     350             :         sal_Bool bUp = (sal_Bool)(sal_uInt16)aUserData.GetToken(1).ToInt32();
     351             :         HeaderBarItemBits nBits = rBar.GetItemBits(ITEMID_TYPE);
     352             : 
     353             :         if ( bUp )
     354             :         {
     355             :             nBits &= ~HeaderBarItemBits::UPARROW;
     356             :             nBits |= HeaderBarItemBits::DOWNARROW;
     357             :         }
     358             :         else
     359             :         {
     360             :             nBits &= ~HeaderBarItemBits::DOWNARROW;
     361             :             nBits |= HeaderBarItemBits::UPARROW;
     362             :         }
     363             :         rBar.SetItemBits( ITEMID_TYPE, nBits );
     364             :         HeaderSelect_Impl( &rBar );
     365             :     }
     366             : #endif
     367           0 :     PathSelect_Impl( NULL );
     368           0 : }
     369             : 
     370             : 
     371             : 
     372           0 : void SvxPathTabPage::FillUserData()
     373             : {
     374           0 :     HeaderBar &rBar = pPathBox->GetTheHeaderBar();
     375             : 
     376           0 :     OUString aUserData = OUString::number( rBar.GetItemSize( ITEMID_TYPE ) ) + ";";
     377           0 :     HeaderBarItemBits nBits = rBar.GetItemBits( ITEMID_TYPE );
     378           0 :     bool bUp = ( ( nBits & HeaderBarItemBits::UPARROW ) == HeaderBarItemBits::UPARROW );
     379           0 :     aUserData += bUp ? OUString("1") : OUString("0");
     380           0 :     SetUserData( aUserData );
     381           0 : }
     382             : 
     383             : 
     384             : 
     385           0 : IMPL_LINK_NOARG(SvxPathTabPage, PathSelect_Impl)
     386             : {
     387           0 :     sal_uInt16 nSelCount = 0;
     388           0 :     SvTreeListEntry* pEntry = pPathBox->FirstSelected();
     389             : 
     390             :     //the entry image indicates whether the path is write protected
     391           0 :     Image aEntryImage;
     392           0 :     if(pEntry)
     393           0 :         aEntryImage = SvTreeListBox::GetCollapsedEntryBmp( pEntry );
     394           0 :     bool bEnable = !aEntryImage;
     395           0 :     while ( pEntry && ( nSelCount < 2 ) )
     396             :     {
     397           0 :         nSelCount++;
     398           0 :         pEntry = pPathBox->NextSelected( pEntry );
     399             :     }
     400             : 
     401           0 :     m_pPathBtn->Enable( 1 == nSelCount && bEnable);
     402           0 :     m_pStandardBtn->Enable( nSelCount > 0 && bEnable);
     403           0 :     return 0;
     404             : }
     405             : 
     406             : 
     407             : 
     408           0 : IMPL_LINK_NOARG(SvxPathTabPage, StandardHdl_Impl)
     409             : {
     410           0 :     SvTreeListEntry* pEntry = pPathBox->FirstSelected();
     411           0 :     while ( pEntry )
     412             :     {
     413           0 :         PathUserData_Impl* pPathImpl = static_cast<PathUserData_Impl*>(pEntry->GetUserData());
     414           0 :         OUString aOldPath = pImpl->m_aDefOpt.GetDefaultPath( pPathImpl->nRealId );
     415             : 
     416           0 :         if ( !aOldPath.isEmpty() )
     417             :         {
     418           0 :             OUString sInternal, sUser, sWritable, sTemp;
     419           0 :             bool bReadOnly = false;
     420           0 :             GetPathList( pPathImpl->nRealId, sInternal, sUser, sWritable, bReadOnly );
     421             : 
     422             :             sal_uInt16 i;
     423           0 :             sal_uInt16 nOldCount = comphelper::string::getTokenCount(aOldPath, MULTIPATH_DELIMITER);
     424           0 :             sal_uInt16 nIntCount = comphelper::string::getTokenCount(sInternal, MULTIPATH_DELIMITER);
     425           0 :             for ( i = 0; i < nOldCount; ++i )
     426             :             {
     427           0 :                 bool bFound = false;
     428           0 :                 OUString sOnePath = aOldPath.getToken( i, MULTIPATH_DELIMITER );
     429           0 :                 for ( sal_uInt16 j = 0; !bFound && j < nIntCount; ++j )
     430             :                 {
     431           0 :                     if ( sInternal.getToken( i, MULTIPATH_DELIMITER ) == sOnePath )
     432           0 :                         bFound = true;
     433             :                 }
     434           0 :                 if ( !bFound )
     435             :                 {
     436           0 :                     if ( !sTemp.isEmpty() )
     437           0 :                         sTemp += OUString(MULTIPATH_DELIMITER);
     438           0 :                     sTemp += sOnePath;
     439             :                 }
     440           0 :             }
     441             : 
     442           0 :             OUString sUserPath, sWritablePath;
     443           0 :             nOldCount = comphelper::string::getTokenCount(sTemp, MULTIPATH_DELIMITER);
     444           0 :             for ( i = 0; nOldCount > 0 && i < nOldCount - 1; ++i )
     445             :             {
     446           0 :                 if ( !sUserPath.isEmpty() )
     447           0 :                     sUserPath += OUString(MULTIPATH_DELIMITER);
     448           0 :                 sUserPath += sTemp.getToken( i, MULTIPATH_DELIMITER );
     449             :             }
     450           0 :             sWritablePath = sTemp.getToken( nOldCount - 1, MULTIPATH_DELIMITER );
     451             : 
     452           0 :             pPathBox->SetEntryText( Convert_Impl( sTemp ), pEntry, 1 );
     453           0 :             pPathImpl->eState = SfxItemState::SET;
     454           0 :             pPathImpl->sUserPath = sUserPath;
     455           0 :             pPathImpl->sWritablePath = sWritablePath;
     456             :         }
     457           0 :         pEntry = pPathBox->NextSelected( pEntry );
     458           0 :     }
     459           0 :     return 0;
     460             : }
     461             : 
     462             : 
     463             : 
     464           0 : void SvxPathTabPage::ChangeCurrentEntry( const OUString& _rFolder )
     465             : {
     466           0 :     SvTreeListEntry* pEntry = pPathBox->GetCurEntry();
     467           0 :     if ( !pEntry )
     468             :     {
     469             :         SAL_WARN( "cui.options", "SvxPathTabPage::ChangeCurrentEntry(): no entry" );
     470           0 :         return;
     471             :     }
     472             : 
     473           0 :     OUString sInternal, sUser, sWritable;
     474           0 :     PathUserData_Impl* pPathImpl = static_cast<PathUserData_Impl*>(pEntry->GetUserData());
     475           0 :     bool bReadOnly = false;
     476           0 :     GetPathList( pPathImpl->nRealId, sInternal, sUser, sWritable, bReadOnly );
     477           0 :     sUser = pPathImpl->sUserPath;
     478           0 :     sWritable = pPathImpl->sWritablePath;
     479           0 :     sal_uInt16 nPos = pPathImpl->nRealId;
     480             : 
     481             :     // old path is an URL?
     482           0 :     INetURLObject aObj( sWritable );
     483           0 :     bool bURL = ( aObj.GetProtocol() != INetProtocol::NotValid );
     484           0 :     OUString aPathStr( _rFolder );
     485           0 :     INetURLObject aNewObj( aPathStr );
     486           0 :     aNewObj.removeFinalSlash();
     487             : 
     488             :     // then the new path also an URL else system path
     489           0 :     OUString sNewPathStr = bURL ? aPathStr : aNewObj.getFSysPath( INetURLObject::FSYS_DETECT );
     490             : 
     491             :     bool bChanged =
     492             : #ifdef UNX
     493             : // Unix is case sensitive
     494           0 :         ( sNewPathStr != sWritable );
     495             : #else
     496             :         ( !sNewPathStr.equalsIgnoreAsciiCase( sWritable ) );
     497             : #endif
     498             : 
     499           0 :     if ( bChanged )
     500             :     {
     501           0 :         pPathBox->SetEntryText( Convert_Impl( sNewPathStr ), pEntry, 1 );
     502           0 :         nPos = (sal_uInt16)pPathBox->GetModel()->GetAbsPos( pEntry );
     503           0 :         pPathImpl = static_cast<PathUserData_Impl*>(pPathBox->GetEntry(nPos)->GetUserData());
     504           0 :         pPathImpl->eState = SfxItemState::SET;
     505           0 :         pPathImpl->sWritablePath = sNewPathStr;
     506           0 :         if ( SvtPathOptions::PATH_WORK == pPathImpl->nRealId )
     507             :         {
     508             :             // Remove view options entry so the new work path
     509             :             // will be used for the next open dialog.
     510           0 :             SvtViewOptions aDlgOpt( E_DIALOG, IODLG_CONFIGNAME );
     511           0 :             aDlgOpt.Delete();
     512             :             // Reset also last used dir in the sfx application instance
     513           0 :             SfxApplication *pSfxApp = SfxGetpApp();
     514           0 :             pSfxApp->ResetLastDir();
     515             : 
     516             :             // Set configuration flag to notify file picker that it's necessary
     517             :             // to take over the path provided.
     518             :             std::shared_ptr< comphelper::ConfigurationChanges > batch(
     519           0 :                 comphelper::ConfigurationChanges::create());
     520             :             officecfg::Office::Common::Path::Info::WorkPathChanged::set(
     521           0 :                 true, batch);
     522           0 :             batch->commit();
     523             :         }
     524           0 :     }
     525             : }
     526             : 
     527             : 
     528             : 
     529           0 : IMPL_LINK_NOARG(SvxPathTabPage, PathHdl_Impl)
     530             : {
     531           0 :     SvTreeListEntry* pEntry = pPathBox->GetCurEntry();
     532           0 :     sal_uInt16 nPos = ( pEntry != NULL ) ? static_cast<PathUserData_Impl*>(pEntry->GetUserData())->nRealId : 0;
     533           0 :     OUString sInternal, sUser, sWritable;
     534           0 :     if ( pEntry )
     535             :     {
     536           0 :         PathUserData_Impl* pPathImpl = static_cast<PathUserData_Impl*>(pEntry->GetUserData());
     537           0 :         bool bReadOnly = false;
     538           0 :         GetPathList( pPathImpl->nRealId, sInternal, sUser, sWritable, bReadOnly );
     539           0 :         sUser = pPathImpl->sUserPath;
     540           0 :         sWritable = pPathImpl->sWritablePath;
     541             :     }
     542             : 
     543           0 :     if(pEntry && !(!SvTreeListBox::GetCollapsedEntryBmp(pEntry)))
     544           0 :         return 0;
     545             : 
     546           0 :     if ( IsMultiPath_Impl( nPos ) )
     547             :     {
     548           0 :         SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
     549           0 :         if ( pFact )
     550             :         {
     551             :             boost::scoped_ptr<AbstractSvxMultiPathDialog> pMultiDlg(
     552           0 :                 pFact->CreateSvxMultiPathDialog( this ));
     553             :             DBG_ASSERT( pMultiDlg, "Dialog creation failed!" );
     554             : 
     555           0 :             OUString sPath( sUser );
     556           0 :             if ( !sPath.isEmpty() )
     557           0 :                 sPath += OUString(MULTIPATH_DELIMITER);
     558           0 :             sPath += sWritable;
     559           0 :             pMultiDlg->SetPath( sPath );
     560             : 
     561           0 :             OUString sPathName = SvTabListBox::GetEntryText( pEntry, 0 );
     562           0 :             OUString sNewTitle( pImpl->m_sMultiPathDlg );
     563           0 :             sNewTitle = sNewTitle.replaceFirst( VAR_ONE, sPathName );
     564           0 :             pMultiDlg->SetTitle( sNewTitle );
     565             : 
     566           0 :             if ( pMultiDlg->Execute() == RET_OK && pEntry )
     567             :             {
     568           0 :                 sUser.clear();
     569           0 :                 sWritable.clear();
     570           0 :                 OUString sFullPath;
     571           0 :                 OUString sNewPath = pMultiDlg->GetPath();
     572           0 :                 char cDelim = MULTIPATH_DELIMITER;
     573           0 :                 sal_uInt16 nCount = comphelper::string::getTokenCount(sNewPath, cDelim);
     574           0 :                 if ( nCount > 0 )
     575             :                 {
     576           0 :                     sal_uInt16 i = 0;
     577           0 :                     for ( ; i < nCount - 1; ++i )
     578             :                     {
     579           0 :                         if ( !sUser.isEmpty() )
     580           0 :                             sUser += OUString(cDelim);
     581           0 :                         sUser += sNewPath.getToken( i, cDelim );
     582             :                     }
     583           0 :                     if ( !sFullPath.isEmpty() )
     584           0 :                         sFullPath += OUString(cDelim);
     585           0 :                     sFullPath += sUser;
     586           0 :                     sWritable += sNewPath.getToken( i, cDelim );
     587           0 :                     if ( !sFullPath.isEmpty() )
     588           0 :                         sFullPath += OUString(cDelim);
     589           0 :                     sFullPath += sWritable;
     590             :                 }
     591             : 
     592           0 :                 pPathBox->SetEntryText( Convert_Impl( sFullPath ), pEntry, 1 );
     593             :                 // save modified flag
     594           0 :                 PathUserData_Impl* pPathImpl = static_cast<PathUserData_Impl*>(pEntry->GetUserData());
     595           0 :                 pPathImpl->eState = SfxItemState::SET;
     596           0 :                 pPathImpl->sUserPath = sUser;
     597           0 :                 pPathImpl->sWritablePath = sWritable;
     598           0 :             }
     599             :         }
     600             :     }
     601           0 :     else if ( pEntry )
     602             :     {
     603             :         try
     604             :         {
     605           0 :             Reference < XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
     606           0 :             xFolderPicker = FolderPicker::create(xContext);;
     607             : 
     608           0 :             INetURLObject aURL( sWritable, INetProtocol::File );
     609           0 :             xFolderPicker->setDisplayDirectory( aURL.GetMainURL( INetURLObject::NO_DECODE ) );
     610             : 
     611           0 :             Reference< XAsynchronousExecutableDialog > xAsyncDlg( xFolderPicker, UNO_QUERY );
     612           0 :             if ( xAsyncDlg.is() )
     613           0 :                 xAsyncDlg->startExecuteModal( xDialogListener.get() );
     614             :             else
     615             :             {
     616           0 :                 short nRet = xFolderPicker->execute();
     617           0 :                 if ( ExecutableDialogResults::OK != nRet )
     618           0 :                     return 0;
     619             : 
     620           0 :                 OUString sFolder( xFolderPicker->getDirectory() );
     621           0 :                 ChangeCurrentEntry( sFolder );
     622           0 :             }
     623             :         }
     624           0 :         catch( Exception& )
     625             :         {
     626             :             SAL_WARN( "cui.options", "SvxPathTabPage::PathHdl_Impl: exception from folder picker" );
     627             :         }
     628             :     }
     629           0 :     return 0;
     630             : }
     631             : 
     632             : 
     633             : 
     634           0 : IMPL_LINK( SvxPathTabPage, HeaderSelect_Impl, HeaderBar*, pBar )
     635             : {
     636           0 :     if (!pBar || pBar->GetCurItemId() != ITEMID_TYPE)
     637           0 :         return 0;
     638             : 
     639           0 :     HeaderBarItemBits nBits = pBar->GetItemBits(ITEMID_TYPE);
     640           0 :     bool bUp = ( ( nBits & HeaderBarItemBits::UPARROW ) == HeaderBarItemBits::UPARROW );
     641           0 :     SvSortMode eMode = SortAscending;
     642             : 
     643           0 :     if ( bUp )
     644             :     {
     645           0 :         nBits &= ~HeaderBarItemBits::UPARROW;
     646           0 :         nBits |= HeaderBarItemBits::DOWNARROW;
     647           0 :         eMode = SortDescending;
     648             :     }
     649             :     else
     650             :     {
     651           0 :         nBits &= ~HeaderBarItemBits::DOWNARROW;
     652           0 :         nBits |= HeaderBarItemBits::UPARROW;
     653             :     }
     654           0 :     pBar->SetItemBits( ITEMID_TYPE, nBits );
     655           0 :     SvTreeList* pModel = pPathBox->GetModel();
     656           0 :     pModel->SetSortMode( eMode );
     657           0 :     pModel->Resort();
     658           0 :     return 1;
     659             : }
     660             : 
     661             : 
     662             : 
     663           0 : IMPL_LINK( SvxPathTabPage, HeaderEndDrag_Impl, HeaderBar*, pBar )
     664             : {
     665           0 :     if (!pBar || !pBar->GetCurItemId())
     666           0 :         return 0;
     667             : 
     668           0 :     if ( !pBar->IsItemMode() )
     669             :     {
     670           0 :         Size aSz;
     671           0 :         sal_uInt16 nTabs = pBar->GetItemCount();
     672           0 :         long nTmpSz = 0;
     673           0 :         long nWidth = pBar->GetItemSize(ITEMID_TYPE);
     674           0 :         long nBarWidth = pBar->GetSizePixel().Width();
     675             : 
     676           0 :         if(nWidth < TAB_WIDTH_MIN)
     677           0 :             pBar->SetItemSize( ITEMID_TYPE, TAB_WIDTH_MIN);
     678           0 :         else if ( ( nBarWidth - nWidth ) < TAB_WIDTH_MIN )
     679           0 :             pBar->SetItemSize( ITEMID_TYPE, nBarWidth - TAB_WIDTH_MIN );
     680             : 
     681           0 :         for ( sal_uInt16 i = 1; i <= nTabs; ++i )
     682             :         {
     683           0 :             long _nWidth = pBar->GetItemSize(i);
     684           0 :             aSz.Width() =  _nWidth + nTmpSz;
     685           0 :             nTmpSz += _nWidth;
     686           0 :             pPathBox->SetTab( i, PixelToLogic( aSz, MapMode(MAP_APPFONT) ).Width(), MAP_APPFONT );
     687             :         }
     688             :     }
     689           0 :     return 1;
     690             : }
     691             : 
     692             : 
     693             : 
     694           0 : IMPL_LINK( SvxPathTabPage, DialogClosedHdl, DialogClosedEvent*, pEvt )
     695             : {
     696           0 :     if ( RET_OK == pEvt->DialogResult )
     697             :     {
     698             :         DBG_ASSERT( xFolderPicker.is(), "SvxPathTabPage::DialogClosedHdl(): no folder picker" );
     699             : 
     700           0 :         OUString sURL = xFolderPicker->getDirectory();
     701           0 :         ChangeCurrentEntry( sURL );
     702             :     }
     703           0 :     return 0L;
     704             : }
     705             : 
     706             : 
     707             : 
     708           0 : void SvxPathTabPage::GetPathList(
     709             :     sal_uInt16 _nPathHandle, OUString& _rInternalPath,
     710             :     OUString& _rUserPath, OUString& _rWritablePath, bool& _rReadOnly )
     711             : {
     712           0 :     OUString sCfgName = getCfgName_Impl( _nPathHandle );
     713             : 
     714             :     try
     715             :     {
     716             :         // load PathSettings service if necessary
     717           0 :         if ( !pImpl->m_xPathSettings.is() )
     718             :         {
     719           0 :             Reference< XComponentContext > xContext = comphelper::getProcessComponentContext();
     720           0 :             pImpl->m_xPathSettings = css::util::thePathSettings::get( xContext );
     721             :         }
     722             : 
     723             :         // load internal paths
     724           0 :         OUString sProp( sCfgName );
     725           0 :         sProp += POSTFIX_INTERNAL;
     726           0 :         Any aAny = pImpl->m_xPathSettings->getPropertyValue( sProp );
     727           0 :         Sequence< OUString > aPathSeq;
     728           0 :         if ( aAny >>= aPathSeq )
     729             :         {
     730           0 :             long i, nCount = aPathSeq.getLength();
     731           0 :             const OUString* pPaths = aPathSeq.getConstArray();
     732             : 
     733           0 :             for ( i = 0; i < nCount; ++i )
     734             :             {
     735           0 :                 if ( !_rInternalPath.isEmpty() )
     736           0 :                     _rInternalPath += ";";
     737           0 :                 _rInternalPath += pPaths[i];
     738             :             }
     739             :         }
     740             :         // load user paths
     741           0 :         sProp = sCfgName;
     742           0 :         sProp += POSTFIX_USER;
     743           0 :         aAny = pImpl->m_xPathSettings->getPropertyValue( sProp );
     744           0 :         if ( aAny >>= aPathSeq )
     745             :         {
     746           0 :             long i, nCount = aPathSeq.getLength();
     747           0 :             const OUString* pPaths = aPathSeq.getConstArray();
     748             : 
     749           0 :             for ( i = 0; i < nCount; ++i )
     750             :             {
     751           0 :                 if ( !_rUserPath.isEmpty() )
     752           0 :                     _rUserPath += ";";
     753           0 :                 _rUserPath += pPaths[i];
     754             :             }
     755             :         }
     756             :         // then the writable path
     757           0 :         sProp = sCfgName;
     758           0 :         sProp += POSTFIX_WRITABLE;
     759           0 :         aAny = pImpl->m_xPathSettings->getPropertyValue( sProp );
     760           0 :         OUString sWritablePath;
     761           0 :         if ( aAny >>= sWritablePath )
     762           0 :             _rWritablePath = sWritablePath;
     763             : 
     764             :         // and the readonly flag
     765           0 :         sProp = sCfgName;
     766           0 :         Reference< XPropertySetInfo > xInfo = pImpl->m_xPathSettings->getPropertySetInfo();
     767           0 :         Property aProp = xInfo->getPropertyByName( sProp );
     768           0 :         _rReadOnly = ( ( aProp.Attributes & PropertyAttribute::READONLY ) == PropertyAttribute::READONLY );
     769             :     }
     770           0 :     catch( const Exception& )
     771             :     {
     772             :         OSL_FAIL( "SvxPathTabPage::GetPathList(): caught an exception!" );
     773           0 :     }
     774           0 : }
     775             : 
     776             : 
     777             : 
     778           0 : void SvxPathTabPage::SetPathList(
     779             :     sal_uInt16 _nPathHandle, const OUString& _rUserPath, const OUString& _rWritablePath )
     780             : {
     781           0 :     OUString sCfgName = getCfgName_Impl( _nPathHandle );
     782             : 
     783             :     try
     784             :     {
     785             :         // load PathSettings service if necessary
     786           0 :         if ( !pImpl->m_xPathSettings.is() )
     787             :         {
     788           0 :             Reference< XComponentContext > xContext = comphelper::getProcessComponentContext();
     789           0 :             pImpl->m_xPathSettings = css::util::thePathSettings::get( xContext );
     790             :         }
     791             : 
     792             :         // save user paths
     793           0 :         char cDelim = MULTIPATH_DELIMITER;
     794           0 :         sal_uInt16 nCount = comphelper::string::getTokenCount(_rUserPath, cDelim);
     795           0 :         Sequence< OUString > aPathSeq( nCount );
     796           0 :         OUString* pArray = aPathSeq.getArray();
     797           0 :         for ( sal_uInt16 i = 0; i < nCount; ++i )
     798           0 :             pArray[i] = _rUserPath.getToken( i, cDelim );
     799           0 :         OUString sProp( sCfgName );
     800           0 :         sProp += POSTFIX_USER;
     801           0 :         Any aValue = makeAny( aPathSeq );
     802           0 :         pImpl->m_xPathSettings->setPropertyValue( sProp, aValue );
     803             : 
     804             :         // then the writable path
     805           0 :         aValue = makeAny( OUString( _rWritablePath ) );
     806           0 :         sProp = sCfgName;
     807           0 :         sProp += POSTFIX_WRITABLE;
     808           0 :         pImpl->m_xPathSettings->setPropertyValue( sProp, aValue );
     809             :     }
     810           0 :     catch( const Exception& e )
     811             :     {
     812             :         SAL_WARN("cui.tabpages", "caught: " << e.Message);
     813           0 :     }
     814           0 : }
     815             : 
     816             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11