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