LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/cui/source/options - optpath.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 391 0.0 %
Date: 2013-07-09 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/PathSettings.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             :     String          sUserPath;
      96             :     String          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             : #if OSL_DEBUG_LEVEL > 1
     119             :     { SvtPathOptions::PATH_LINGUISTIC,        "Linguistic" },
     120             :     { SvtPathOptions::PATH_DICTIONARY,        "Dictionary" },
     121             : #endif
     122             :     { USHRT_MAX, NULL }
     123             : };
     124             : 
     125           0 : static String getCfgName_Impl( sal_uInt16 _nHandle )
     126             : {
     127           0 :     String 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 : String Convert_Impl( const String& rValue )
     146             : {
     147           0 :     char cDelim = MULTIPATH_DELIMITER;
     148           0 :     sal_uInt16 nCount = comphelper::string::getTokenCount(rValue, cDelim);
     149           0 :     String aReturn;
     150           0 :     for ( sal_uInt16 i=0; i<nCount ; ++i )
     151             :     {
     152           0 :         String aValue = rValue.GetToken( i, cDelim );
     153           0 :         INetURLObject aObj( aValue );
     154           0 :         if ( aObj.GetProtocol() == INET_PROT_FILE )
     155           0 :             aReturn += String(aObj.PathToFileName());
     156           0 :         else if ( ::utl::LocalFileHelper::IsFileContent( aValue ) )
     157           0 :             aReturn += String(aObj.GetURLPath( INetURLObject::DECODE_WITH_CHARSET ));
     158           0 :         if ( i+1 < nCount)
     159           0 :             aReturn += MULTIPATH_DELIMITER;
     160           0 :     }
     161             : 
     162           0 :     return aReturn;
     163             : }
     164             : 
     165             : // class SvxControlFocusHelper ---------------------------------------------
     166             : 
     167           0 : long SvxControlFocusHelper::Notify( NotifyEvent& rNEvt )
     168             : {
     169           0 :     long 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 : sal_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 sal_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             : #if OSL_DEBUG_LEVEL > 1
     306             :             case SvtPathOptions::PATH_LINGUISTIC:
     307             :             case SvtPathOptions::PATH_DICTIONARY:
     308             : #endif
     309             :             case SvtPathOptions::PATH_WORK:
     310             :             {
     311           0 :                 String aStr( CUI_RES( RID_SVXSTR_PATH_NAME_START + i ) );
     312           0 :                 nWidth1 = std::max(nWidth1, pPathBox->GetTextWidth(aStr));
     313           0 :                 aStr += '\t';
     314           0 :                 String sInternal, sUser, sWritable;
     315           0 :                 sal_Bool bReadOnly = sal_False;
     316           0 :                 GetPathList( i, sInternal, sUser, sWritable, bReadOnly );
     317           0 :                 String sTmpPath = sUser;
     318           0 :                 if ( sTmpPath.Len() > 0 && sWritable.Len() > 0 )
     319           0 :                     sTmpPath += MULTIPATH_DELIMITER;
     320           0 :                 sTmpPath += sWritable;
     321           0 :                 String 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 :     String 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 ? '1' : '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 :         String aOldPath = pImpl->m_aDefOpt.GetDefaultPath( pPathImpl->nRealId );
     418             : 
     419           0 :         if ( aOldPath.Len() )
     420             :         {
     421           0 :             String 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 :                 String 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.Len() > 0 )
     440           0 :                         sTemp += MULTIPATH_DELIMITER;
     441           0 :                     sTemp += sOnePath;
     442             :                 }
     443           0 :             }
     444             : 
     445           0 :             String 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.Len() > 0 )
     450           0 :                     sUserPath += 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 String& _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 :     String 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 :     String 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.CompareIgnoreCaseToAscii( sWritable ) != COMPARE_EQUAL );
     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 :     String 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           0 :             pMultiDlg->EnableRadioButtonMode();
     558             : 
     559           0 :             String sPath( sUser );
     560           0 :             if ( sPath.Len() > 0 )
     561           0 :                 sPath += MULTIPATH_DELIMITER;
     562           0 :             sPath += sWritable;
     563           0 :             pMultiDlg->SetPath( sPath );
     564             : 
     565           0 :             String sPathName = pPathBox->GetEntryText( pEntry, 0 );
     566           0 :             String sNewTitle( pImpl->m_sMultiPathDlg );
     567           0 :             sNewTitle.SearchAndReplace( VAR_ONE, sPathName );
     568           0 :             pMultiDlg->SetTitle( sNewTitle );
     569             : 
     570           0 :             if ( pMultiDlg->Execute() == RET_OK && pEntry )
     571             :             {
     572           0 :                 sUser.Erase();
     573           0 :                 sWritable.Erase();
     574           0 :                 String sFullPath;
     575           0 :                 String sNewPath = pMultiDlg->GetPath();
     576           0 :                 char cDelim = MULTIPATH_DELIMITER;
     577           0 :                 sal_uInt16 nCount = comphelper::string::getTokenCount(sNewPath, cDelim);
     578           0 :                 if ( nCount > 0 )
     579             :                 {
     580           0 :                     sal_uInt16 i = 0;
     581           0 :                     for ( ; i < nCount - 1; ++i )
     582             :                     {
     583           0 :                         if ( sUser.Len() > 0 )
     584           0 :                             sUser += cDelim;
     585           0 :                         sUser += sNewPath.GetToken( i, cDelim );
     586             :                     }
     587           0 :                     if ( sFullPath.Len() > 0 )
     588           0 :                         sFullPath += cDelim;
     589           0 :                     sFullPath += sUser;
     590           0 :                     sWritable += sNewPath.GetToken( i, cDelim );
     591           0 :                     if ( sFullPath.Len() > 0 )
     592           0 :                         sFullPath += cDelim;
     593           0 :                     sFullPath += sWritable;
     594             :                 }
     595             : 
     596           0 :                 pPathBox->SetEntryText( Convert_Impl( sFullPath ), pEntry, 1 );
     597             :                 // save modified flag
     598           0 :                 PathUserData_Impl* pPathImpl = (PathUserData_Impl*)pEntry->GetUserData();
     599           0 :                 pPathImpl->eState = SFX_ITEM_SET;
     600           0 :                 pPathImpl->sUserPath = sUser;
     601           0 :                 pPathImpl->sWritablePath = sWritable;
     602             :             }
     603           0 :             delete pMultiDlg;
     604             :         }
     605             :     }
     606           0 :     else if ( pEntry )
     607             :     {
     608             :         try
     609             :         {
     610           0 :             Reference < XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
     611           0 :             xFolderPicker = FolderPicker::create(xContext);;
     612             : 
     613           0 :             INetURLObject aURL( sWritable, INET_PROT_FILE );
     614           0 :             xFolderPicker->setDisplayDirectory( aURL.GetMainURL( INetURLObject::NO_DECODE ) );
     615             : 
     616           0 :             Reference< XAsynchronousExecutableDialog > xAsyncDlg( xFolderPicker, UNO_QUERY );
     617           0 :             if ( xAsyncDlg.is() )
     618           0 :                 xAsyncDlg->startExecuteModal( xDialogListener.get() );
     619             :             else
     620             :             {
     621           0 :                 short nRet = xFolderPicker->execute();
     622           0 :                 if ( ExecutableDialogResults::OK != nRet )
     623           0 :                     return 0;
     624             : 
     625           0 :                 String sFolder( xFolderPicker->getDirectory() );
     626           0 :                 ChangeCurrentEntry( sFolder );
     627           0 :             }
     628             :         }
     629           0 :         catch( Exception& )
     630             :         {
     631             :             SAL_WARN( "cui.options", "SvxPathTabPage::PathHdl_Impl: exception from folder picker" );
     632             :         }
     633             :     }
     634           0 :     return 0;
     635             : }
     636             : 
     637             : // -----------------------------------------------------------------------
     638             : 
     639           0 : IMPL_LINK( SvxPathTabPage, HeaderSelect_Impl, HeaderBar*, pBar )
     640             : {
     641           0 :     if ( pBar && pBar->GetCurItemId() != ITEMID_TYPE )
     642           0 :         return 0;
     643             : 
     644           0 :     HeaderBarItemBits nBits = pBar->GetItemBits(ITEMID_TYPE);
     645           0 :     sal_Bool bUp = ( ( nBits & HIB_UPARROW ) == HIB_UPARROW );
     646           0 :     SvSortMode eMode = SortAscending;
     647             : 
     648           0 :     if ( bUp )
     649             :     {
     650           0 :         nBits &= ~HIB_UPARROW;
     651           0 :         nBits |= HIB_DOWNARROW;
     652           0 :         eMode = SortDescending;
     653             :     }
     654             :     else
     655             :     {
     656           0 :         nBits &= ~HIB_DOWNARROW;
     657           0 :         nBits |= HIB_UPARROW;
     658             :     }
     659           0 :     pBar->SetItemBits( ITEMID_TYPE, nBits );
     660           0 :     SvTreeList* pModel = pPathBox->GetModel();
     661           0 :     pModel->SetSortMode( eMode );
     662           0 :     pModel->Resort();
     663           0 :     return 1;
     664             : }
     665             : 
     666             : // -----------------------------------------------------------------------
     667             : 
     668           0 : IMPL_LINK( SvxPathTabPage, HeaderEndDrag_Impl, HeaderBar*, pBar )
     669             : {
     670           0 :     if ( pBar && !pBar->GetCurItemId() )
     671           0 :         return 0;
     672             : 
     673           0 :     if ( !pBar->IsItemMode() )
     674             :     {
     675           0 :         Size aSz;
     676           0 :         sal_uInt16 nTabs = pBar->GetItemCount();
     677           0 :         long nTmpSz = 0;
     678           0 :         long nWidth = pBar->GetItemSize(ITEMID_TYPE);
     679           0 :         long nBarWidth = pBar->GetSizePixel().Width();
     680             : 
     681           0 :         if(nWidth < TAB_WIDTH_MIN)
     682           0 :             pBar->SetItemSize( ITEMID_TYPE, TAB_WIDTH_MIN);
     683           0 :         else if ( ( nBarWidth - nWidth ) < TAB_WIDTH_MIN )
     684           0 :             pBar->SetItemSize( ITEMID_TYPE, nBarWidth - TAB_WIDTH_MIN );
     685             : 
     686           0 :         for ( sal_uInt16 i = 1; i <= nTabs; ++i )
     687             :         {
     688           0 :             long _nWidth = pBar->GetItemSize(i);
     689           0 :             aSz.Width() =  _nWidth + nTmpSz;
     690           0 :             nTmpSz += _nWidth;
     691           0 :             pPathBox->SetTab( i, PixelToLogic( aSz, MapMode(MAP_APPFONT) ).Width(), MAP_APPFONT );
     692             :         }
     693             :     }
     694           0 :     return 1;
     695             : }
     696             : 
     697             : // -----------------------------------------------------------------------
     698             : 
     699           0 : IMPL_LINK( SvxPathTabPage, DialogClosedHdl, DialogClosedEvent*, pEvt )
     700             : {
     701           0 :     if ( RET_OK == pEvt->DialogResult )
     702             :     {
     703             :         DBG_ASSERT( xFolderPicker.is() == sal_True, "SvxPathTabPage::DialogClosedHdl(): no folder picker" );
     704             : 
     705           0 :         String sURL = String( xFolderPicker->getDirectory() );
     706           0 :         ChangeCurrentEntry( sURL );
     707             :     }
     708           0 :     return 0L;
     709             : }
     710             : 
     711             : // -----------------------------------------------------------------------
     712             : 
     713           0 : void SvxPathTabPage::GetPathList(
     714             :     sal_uInt16 _nPathHandle, String& _rInternalPath,
     715             :     String& _rUserPath, String& _rWritablePath, sal_Bool& _rReadOnly )
     716             : {
     717           0 :     String sCfgName = getCfgName_Impl( _nPathHandle );
     718             : 
     719             :     try
     720             :     {
     721             :         // load PathSettings service if necessary
     722           0 :         if ( !pImpl->m_xPathSettings.is() )
     723             :         {
     724           0 :             Reference< XComponentContext > xContext = comphelper::getProcessComponentContext();
     725           0 :             pImpl->m_xPathSettings = css::util::PathSettings::create( xContext );
     726             :         }
     727             : 
     728             :         // load internal paths
     729           0 :         String sProp( sCfgName );
     730           0 :         sProp += POSTFIX_INTERNAL;
     731           0 :         Any aAny = pImpl->m_xPathSettings->getPropertyValue( sProp );
     732           0 :         Sequence< OUString > aPathSeq;
     733           0 :         if ( aAny >>= aPathSeq )
     734             :         {
     735           0 :             long i, nCount = aPathSeq.getLength();
     736           0 :             const OUString* pPaths = aPathSeq.getConstArray();
     737             : 
     738           0 :             for ( i = 0; i < nCount; ++i )
     739             :             {
     740           0 :                 if ( _rInternalPath.Len() > 0 )
     741           0 :                     _rInternalPath += ';';
     742           0 :                 _rInternalPath += String( pPaths[i] );
     743             :             }
     744             :         }
     745             :         // load user paths
     746           0 :         sProp = sCfgName;
     747           0 :         sProp += POSTFIX_USER;
     748           0 :         aAny = pImpl->m_xPathSettings->getPropertyValue( sProp );
     749           0 :         if ( aAny >>= aPathSeq )
     750             :         {
     751           0 :             long i, nCount = aPathSeq.getLength();
     752           0 :             const OUString* pPaths = aPathSeq.getConstArray();
     753             : 
     754           0 :             for ( i = 0; i < nCount; ++i )
     755             :             {
     756           0 :                 if ( _rUserPath.Len() > 0 )
     757           0 :                     _rUserPath += ';';
     758           0 :                 _rUserPath += String( pPaths[i] );
     759             :             }
     760             :         }
     761             :         // then the writable path
     762           0 :         sProp = sCfgName;
     763           0 :         sProp += POSTFIX_WRITABLE;
     764           0 :         aAny = pImpl->m_xPathSettings->getPropertyValue( sProp );
     765           0 :         OUString sWritablePath;
     766           0 :         if ( aAny >>= sWritablePath )
     767           0 :             _rWritablePath = String( sWritablePath );
     768             : 
     769             :         // and the readonly flag
     770           0 :         sProp = sCfgName;
     771           0 :         Reference< XPropertySetInfo > xInfo = pImpl->m_xPathSettings->getPropertySetInfo();
     772           0 :         Property aProp = xInfo->getPropertyByName( sProp );
     773           0 :         _rReadOnly = ( ( aProp.Attributes & PropertyAttribute::READONLY ) == PropertyAttribute::READONLY );
     774             :     }
     775           0 :     catch( const Exception& )
     776             :     {
     777             :         OSL_FAIL( "SvxPathTabPage::GetPathList(): caught an exception!" );
     778           0 :     }
     779           0 : }
     780             : 
     781             : // -----------------------------------------------------------------------
     782             : 
     783           0 : void SvxPathTabPage::SetPathList(
     784             :     sal_uInt16 _nPathHandle, const String& _rUserPath, const String& _rWritablePath )
     785             : {
     786           0 :     String sCfgName = getCfgName_Impl( _nPathHandle );
     787             : 
     788             :     try
     789             :     {
     790             :         // load PathSettings service if necessary
     791           0 :         if ( !pImpl->m_xPathSettings.is() )
     792             :         {
     793           0 :             Reference< XComponentContext > xContext = comphelper::getProcessComponentContext();
     794           0 :             pImpl->m_xPathSettings = css::util::PathSettings::create( xContext );
     795             :         }
     796             : 
     797             :         // save user paths
     798           0 :         char cDelim = MULTIPATH_DELIMITER;
     799           0 :         sal_uInt16 nCount = comphelper::string::getTokenCount(_rUserPath, cDelim);
     800           0 :         Sequence< OUString > aPathSeq( nCount );
     801           0 :         OUString* pArray = aPathSeq.getArray();
     802           0 :         for ( sal_uInt16 i = 0; i < nCount; ++i )
     803           0 :             pArray[i] = OUString( _rUserPath.GetToken( i, cDelim ) );
     804           0 :         String sProp( sCfgName );
     805           0 :         sProp += POSTFIX_USER;
     806           0 :         Any aValue = makeAny( aPathSeq );
     807           0 :         pImpl->m_xPathSettings->setPropertyValue( sProp, aValue );
     808             : 
     809             :         // then the writable path
     810           0 :         aValue = makeAny( OUString( _rWritablePath ) );
     811           0 :         sProp = sCfgName;
     812           0 :         sProp += POSTFIX_WRITABLE;
     813           0 :         pImpl->m_xPathSettings->setPropertyValue( sProp, aValue );
     814             :     }
     815           0 :     catch( const Exception& e )
     816             :     {
     817             :         SAL_WARN("cui.tabpages", "caught: " << e.Message);
     818           0 :     }
     819           0 : }
     820             : 
     821             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10