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

Generated by: LCOV version 1.10