Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <tools/urlobj.hxx>
30 : : #include <vcl/msgbox.hxx>
31 : : #include <sfx2/filedlghelper.hxx>
32 : :
33 : : #include "multipat.hxx"
34 : : #include <dialmgr.hxx>
35 : :
36 : : #include "multipat.hrc"
37 : : #include <cuires.hrc>
38 : : #include <comphelper/processfactory.hxx>
39 : : #include <comphelper/string.hxx>
40 : : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
41 : : #include <com/sun/star/ui/dialogs/XFolderPicker.hpp>
42 : : #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
43 : :
44 : : #include <unotools/localfilehelper.hxx>
45 : : #include <unotools/pathoptions.hxx>
46 : :
47 : : using namespace ::com::sun::star::lang;
48 : : using namespace ::com::sun::star::ui::dialogs;
49 : : using namespace ::com::sun::star::uno;
50 : :
51 : : // struct MultiPath_Impl -------------------------------------------------
52 : :
53 : : struct MultiPath_Impl
54 : : {
55 : : sal_Bool bEmptyAllowed;
56 : : sal_Bool bIsClassPathMode;
57 : : bool bIsRadioButtonMode;
58 : :
59 : 0 : MultiPath_Impl( sal_Bool bAllowed ) :
60 : 0 : bEmptyAllowed( bAllowed ), bIsClassPathMode( sal_False ), bIsRadioButtonMode( false ) {}
61 : : };
62 : :
63 : : // class SvxMultiPathDialog ----------------------------------------------
64 : :
65 : 0 : IMPL_LINK_NOARG(SvxMultiPathDialog, SelectHdl_Impl)
66 : : {
67 [ # # ]: 0 : sal_uLong nCount = pImpl->bIsRadioButtonMode ? aRadioLB.GetEntryCount() : aPathLB.GetEntryCount();
68 : : bool bIsSelected = pImpl->bIsRadioButtonMode
69 : 0 : ? aRadioLB.FirstSelected() != NULL
70 [ # # ]: 0 : : aPathLB.GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND;
71 [ # # ][ # # ]: 0 : sal_Bool bEnable = ( pImpl->bEmptyAllowed || nCount > 1 );
72 [ # # ][ # # ]: 0 : aDelBtn.Enable( bEnable && bIsSelected );
73 : 0 : return 0;
74 : : }
75 : :
76 : : // -----------------------------------------------------------------------
77 : :
78 : 0 : IMPL_LINK( SvxMultiPathDialog, CheckHdl_Impl, svx::SvxRadioButtonListBox *, pBox )
79 : : {
80 : : SvLBoxEntry* pEntry =
81 [ # # ]: 0 : pBox ? pBox->GetEntry( pBox->GetCurMousePoint() ) : aRadioLB.FirstSelected();
82 [ # # ]: 0 : if ( pEntry )
83 : 0 : aRadioLB.HandleEntryChecked( pEntry );
84 : 0 : return 0;
85 : : }
86 : :
87 : : // -----------------------------------------------------------------------
88 : :
89 : 0 : IMPL_LINK_NOARG(SvxMultiPathDialog, AddHdl_Impl)
90 : : {
91 [ # # ]: 0 : rtl::OUString aService( RTL_CONSTASCII_USTRINGPARAM( FOLDER_PICKER_SERVICE_NAME ) );
92 [ # # ]: 0 : Reference < XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() );
93 [ # # ][ # # ]: 0 : Reference < XFolderPicker > xFolderPicker( xFactory->createInstance( aService ), UNO_QUERY );
[ # # ]
94 : :
95 [ # # ][ # # ]: 0 : if ( xFolderPicker->execute() == ExecutableDialogResults::OK )
[ # # ]
96 : : {
97 [ # # ][ # # ]: 0 : INetURLObject aPath( xFolderPicker->getDirectory() );
[ # # ]
98 [ # # ]: 0 : aPath.removeFinalSlash();
99 [ # # ][ # # ]: 0 : String aURL = aPath.GetMainURL( INetURLObject::NO_DECODE );
100 [ # # ]: 0 : String sInsPath;
101 [ # # ]: 0 : ::utl::LocalFileHelper::ConvertURLToSystemPath( aURL, sInsPath );
102 : :
103 [ # # ]: 0 : if ( pImpl->bIsRadioButtonMode )
104 : : {
105 [ # # ]: 0 : sal_uLong nPos = aRadioLB.GetEntryPos( sInsPath, 1 );
106 [ # # ]: 0 : if ( 0xffffffff == nPos ) //See svtools/source/contnr/svtabbx.cxx SvTabListBox::GetEntryPos
107 : : {
108 : 0 : rtl::OUString sNewEntry( '\t' );
109 [ # # ]: 0 : sNewEntry += sInsPath;
110 [ # # ][ # # ]: 0 : SvLBoxEntry* pEntry = aRadioLB.InsertEntry( sNewEntry );
[ # # ]
111 [ # # ][ # # ]: 0 : String* pData = new String( aURL );
112 : 0 : pEntry->SetUserData( pData );
113 : : }
114 : : else
115 : : {
116 [ # # ][ # # ]: 0 : String sMsg( CUI_RES( RID_MULTIPATH_DBL_ERR ) );
117 [ # # ]: 0 : sMsg.SearchAndReplaceAscii( "%1", sInsPath );
118 [ # # ][ # # ]: 0 : InfoBox( this, sMsg ).Execute();
[ # # ][ # # ]
119 : : }
120 : : }
121 : : else
122 : : {
123 [ # # ][ # # ]: 0 : if ( LISTBOX_ENTRY_NOTFOUND != aPathLB.GetEntryPos( sInsPath ) )
124 : : {
125 [ # # ][ # # ]: 0 : String sMsg( CUI_RES( RID_MULTIPATH_DBL_ERR ) );
126 [ # # ]: 0 : sMsg.SearchAndReplaceAscii( "%1", sInsPath );
127 [ # # ][ # # ]: 0 : InfoBox( this, sMsg ).Execute();
[ # # ][ # # ]
128 : : }
129 : : else
130 : : {
131 [ # # ]: 0 : sal_uInt16 nPos = aPathLB.InsertEntry( sInsPath, LISTBOX_APPEND );
132 [ # # ][ # # ]: 0 : aPathLB.SetEntryData( nPos, (void*)new String( aURL ) );
[ # # ]
133 : : }
134 : : }
135 [ # # ][ # # ]: 0 : SelectHdl_Impl( NULL );
[ # # ][ # # ]
136 : : }
137 : 0 : return 0;
138 : : }
139 : :
140 : : // -----------------------------------------------------------------------
141 : :
142 : 0 : IMPL_LINK_NOARG(SvxMultiPathDialog, DelHdl_Impl)
143 : : {
144 [ # # ]: 0 : if ( pImpl->bIsRadioButtonMode )
145 : : {
146 : 0 : SvLBoxEntry* pEntry = aRadioLB.FirstSelected();
147 [ # # ]: 0 : delete (String*)pEntry->GetUserData();
148 : 0 : bool bChecked = aRadioLB.GetCheckButtonState( pEntry ) == SV_BUTTON_CHECKED;
149 : 0 : sal_uLong nPos = aRadioLB.GetEntryPos( pEntry );
150 : 0 : aRadioLB.RemoveEntry( pEntry );
151 : 0 : sal_uLong nCnt = aRadioLB.GetEntryCount();
152 [ # # ]: 0 : if ( nCnt )
153 : : {
154 : 0 : nCnt--;
155 [ # # ]: 0 : if ( nPos > nCnt )
156 : 0 : nPos = nCnt;
157 : 0 : pEntry = aRadioLB.GetEntry( nPos );
158 [ # # ]: 0 : if ( bChecked )
159 : : {
160 : 0 : aRadioLB.SetCheckButtonState( pEntry, SV_BUTTON_CHECKED );
161 : 0 : aRadioLB.HandleEntryChecked( pEntry );
162 : : }
163 : : else
164 : 0 : aRadioLB.Select( pEntry );
165 : : }
166 : : }
167 : : else
168 : : {
169 : 0 : sal_uInt16 nPos = aPathLB.GetSelectEntryPos();
170 : 0 : aPathLB.RemoveEntry( nPos );
171 : 0 : sal_uInt16 nCnt = aPathLB.GetEntryCount();
172 : :
173 [ # # ]: 0 : if ( nCnt )
174 : : {
175 : 0 : nCnt--;
176 : :
177 [ # # ]: 0 : if ( nPos > nCnt )
178 : 0 : nPos = nCnt;
179 : 0 : aPathLB.SelectEntryPos( nPos );
180 : : }
181 : : }
182 : 0 : SelectHdl_Impl( NULL );
183 : 0 : return 0;
184 : : }
185 : :
186 : : // -----------------------------------------------------------------------
187 : :
188 : 0 : SvxMultiPathDialog::SvxMultiPathDialog( Window* pParent, sal_Bool bEmptyAllowed ) :
189 : :
190 : 0 : ModalDialog( pParent, CUI_RES( RID_SVXDLG_MULTIPATH ) ),
191 : :
192 [ # # ]: 0 : aPathFL ( this, CUI_RES( FL_MULTIPATH) ),
193 [ # # ]: 0 : aPathLB ( this, CUI_RES( LB_MULTIPATH ) ),
194 [ # # ]: 0 : m_aRadioLBContainer(this, CUI_RES(LB_RADIOBUTTON)),
195 : : aRadioLB(m_aRadioLBContainer),
196 [ # # ]: 0 : aRadioFT ( this, CUI_RES( FT_RADIOBUTTON ) ),
197 [ # # ]: 0 : aAddBtn ( this, CUI_RES( BTN_ADD_MULTIPATH ) ),
198 [ # # ]: 0 : aDelBtn ( this, CUI_RES( BTN_DEL_MULTIPATH ) ),
199 [ # # ]: 0 : aOKBtn ( this, CUI_RES( BTN_MULTIPATH_OK ) ),
200 [ # # ]: 0 : aCancelBtn ( this, CUI_RES( BTN_MULTIPATH_CANCEL ) ),
201 [ # # ]: 0 : aHelpButton ( this, CUI_RES( BTN_MULTIPATH_HELP ) ),
202 [ # # ][ # # ]: 0 : pImpl ( new MultiPath_Impl( bEmptyAllowed ) )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
203 : :
204 : : {
205 : : static long aStaticTabs[]= { 2, 0, 12 };
206 [ # # ]: 0 : aRadioLB.SvxSimpleTable::SetTabs( aStaticTabs );
207 [ # # ][ # # ]: 0 : String sHeader( CUI_RES( STR_HEADER_PATHS ) );
208 [ # # ]: 0 : aRadioLB.SetQuickHelpText( sHeader );
209 [ # # ]: 0 : sHeader.Insert( '\t', 0 );
210 [ # # ][ # # ]: 0 : aRadioLB.InsertHeaderEntry( sHeader, HEADERBAR_APPEND, HIB_LEFT );
211 : :
212 [ # # ]: 0 : FreeResource();
213 : :
214 [ # # ]: 0 : aPathLB.SetSelectHdl( LINK( this, SvxMultiPathDialog, SelectHdl_Impl ) );
215 [ # # ]: 0 : aRadioLB.SetSelectHdl( LINK( this, SvxMultiPathDialog, SelectHdl_Impl ) );
216 [ # # ]: 0 : aRadioLB.SetCheckButtonHdl( LINK( this, SvxMultiPathDialog, CheckHdl_Impl ) );
217 [ # # ]: 0 : aAddBtn.SetClickHdl( LINK( this, SvxMultiPathDialog, AddHdl_Impl ) );
218 [ # # ]: 0 : aDelBtn.SetClickHdl( LINK( this, SvxMultiPathDialog, DelHdl_Impl ) );
219 : :
220 [ # # ]: 0 : SelectHdl_Impl( NULL );
221 : :
222 [ # # ]: 0 : aAddBtn.SetAccessibleRelationMemberOf(&aPathLB);
223 [ # # ][ # # ]: 0 : aDelBtn.SetAccessibleRelationMemberOf(&aPathLB);
224 : 0 : }
225 : :
226 : : // -----------------------------------------------------------------------
227 : :
228 [ # # ][ # # ]: 0 : SvxMultiPathDialog::~SvxMultiPathDialog()
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
229 : : {
230 [ # # ]: 0 : sal_uInt16 nPos = aPathLB.GetEntryCount();
231 [ # # ]: 0 : while ( nPos-- )
232 [ # # ][ # # ]: 0 : delete (String*)aPathLB.GetEntryData(nPos);
[ # # ]
233 : 0 : nPos = (sal_uInt16)aRadioLB.GetEntryCount();
234 [ # # ]: 0 : while ( nPos-- )
235 : : {
236 [ # # ]: 0 : SvLBoxEntry* pEntry = aRadioLB.GetEntry( nPos );
237 [ # # ][ # # ]: 0 : delete (String*)pEntry->GetUserData();
238 : : }
239 : 0 : delete pImpl;
240 [ # # ]: 0 : }
241 : :
242 : : // -----------------------------------------------------------------------
243 : :
244 : 0 : String SvxMultiPathDialog::GetPath() const
245 : : {
246 : 0 : String sNewPath;
247 [ # # ]: 0 : sal_Unicode cDelim = pImpl->bIsClassPathMode ? CLASSPATH_DELIMITER : SVT_SEARCHPATH_DELIMITER;
248 : :
249 [ # # ]: 0 : if ( pImpl->bIsRadioButtonMode )
250 : : {
251 [ # # ]: 0 : String sWritable;
252 [ # # ]: 0 : for ( sal_uInt16 i = 0; i < aRadioLB.GetEntryCount(); ++i )
253 : : {
254 [ # # ]: 0 : SvLBoxEntry* pEntry = aRadioLB.GetEntry(i);
255 [ # # ][ # # ]: 0 : if ( aRadioLB.GetCheckButtonState( pEntry ) == SV_BUTTON_CHECKED )
256 [ # # ]: 0 : sWritable = *(String*)pEntry->GetUserData();
257 : : else
258 : : {
259 [ # # ]: 0 : if ( sNewPath.Len() > 0 )
260 [ # # ]: 0 : sNewPath += cDelim;
261 [ # # ]: 0 : sNewPath += *(String*)pEntry->GetUserData();
262 : : }
263 : : }
264 [ # # ]: 0 : if ( sNewPath.Len() > 0 )
265 [ # # ]: 0 : sNewPath += cDelim;
266 [ # # ][ # # ]: 0 : sNewPath += sWritable;
267 : : }
268 : : else
269 : : {
270 [ # # ][ # # ]: 0 : for ( sal_uInt16 i = 0; i < aPathLB.GetEntryCount(); ++i )
271 : : {
272 [ # # ]: 0 : if ( sNewPath.Len() > 0 )
273 [ # # ]: 0 : sNewPath += cDelim;
274 [ # # ][ # # ]: 0 : sNewPath += *(String*)aPathLB.GetEntryData(i);
275 : : }
276 : : }
277 : 0 : return sNewPath;
278 : : }
279 : :
280 : : // -----------------------------------------------------------------------
281 : :
282 : 0 : void SvxMultiPathDialog::SetPath( const String& rPath )
283 : : {
284 [ # # ]: 0 : sal_Unicode cDelim = pImpl->bIsClassPathMode ? CLASSPATH_DELIMITER : SVT_SEARCHPATH_DELIMITER;
285 [ # # ]: 0 : sal_uInt16 nPos, nCount = comphelper::string::getTokenCount(rPath, cDelim);
286 : :
287 [ # # ]: 0 : for ( sal_uInt16 i = 0; i < nCount; ++i )
288 : : {
289 [ # # ]: 0 : String sPath = rPath.GetToken( i, cDelim );
290 [ # # ]: 0 : String sSystemPath;
291 : : sal_Bool bIsSystemPath =
292 [ # # ]: 0 : ::utl::LocalFileHelper::ConvertURLToSystemPath( sPath, sSystemPath );
293 : :
294 [ # # ]: 0 : if ( pImpl->bIsRadioButtonMode )
295 : : {
296 : 0 : rtl::OUString sEntry( '\t' );
297 [ # # ][ # # ]: 0 : sEntry += (bIsSystemPath ? sSystemPath : sPath);
298 [ # # ][ # # ]: 0 : SvLBoxEntry* pEntry = aRadioLB.InsertEntry( sEntry );
[ # # ]
299 [ # # ][ # # ]: 0 : String* pURL = new String( sPath );
300 : 0 : pEntry->SetUserData( pURL );
301 : : }
302 : : else
303 : : {
304 [ # # ]: 0 : if ( bIsSystemPath )
305 [ # # ]: 0 : nPos = aPathLB.InsertEntry( sSystemPath, LISTBOX_APPEND );
306 : : else
307 [ # # ]: 0 : nPos = aPathLB.InsertEntry( sPath, LISTBOX_APPEND );
308 [ # # ][ # # ]: 0 : aPathLB.SetEntryData( nPos, (void*)new String( sPath ) );
[ # # ]
309 : : }
310 [ # # ][ # # ]: 0 : }
311 : :
312 [ # # ][ # # ]: 0 : if ( pImpl->bIsRadioButtonMode && nCount > 0 )
313 : : {
314 : 0 : SvLBoxEntry* pEntry = aRadioLB.GetEntry( nCount - 1 );
315 [ # # ]: 0 : if ( pEntry )
316 : : {
317 : 0 : aRadioLB.SetCheckButtonState( pEntry, SV_BUTTON_CHECKED );
318 : 0 : aRadioLB.HandleEntryChecked( pEntry );
319 : : }
320 : : }
321 : :
322 : 0 : SelectHdl_Impl( NULL );
323 : 0 : }
324 : :
325 : : // -----------------------------------------------------------------------
326 : :
327 : 0 : void SvxMultiPathDialog::SetClassPathMode()
328 : : {
329 : 0 : pImpl->bIsClassPathMode = sal_True;
330 [ # # ][ # # ]: 0 : SetText( CUI_RES( RID_SVXSTR_ARCHIVE_TITLE ));
[ # # ]
331 [ # # ][ # # ]: 0 : aPathFL.SetText( CUI_RES( RID_SVXSTR_ARCHIVE_HEADLINE ) );
[ # # ]
332 : 0 : }
333 : :
334 : : // -----------------------------------------------------------------------
335 : :
336 : 0 : sal_Bool SvxMultiPathDialog::IsClassPathMode() const
337 : : {
338 : 0 : return pImpl->bIsClassPathMode;
339 : : }
340 : :
341 : : // -----------------------------------------------------------------------
342 : :
343 : 0 : void SvxMultiPathDialog::EnableRadioButtonMode()
344 : : {
345 : 0 : pImpl->bIsRadioButtonMode = true;
346 : :
347 [ # # ]: 0 : aPathFL.Hide();
348 [ # # ]: 0 : aPathLB.Hide();
349 : :
350 [ # # ]: 0 : aRadioLB.ShowTable();
351 [ # # ]: 0 : aRadioFT.Show();
352 : :
353 [ # # ]: 0 : Point aNewPos = aAddBtn.GetPosPixel();
354 [ # # ]: 0 : long nDelta = aNewPos.Y() - aRadioLB.GetPosPixel().Y();
355 : 0 : aNewPos.Y() -= nDelta;
356 [ # # ]: 0 : aAddBtn.SetPosPixel( aNewPos );
357 [ # # ]: 0 : aNewPos = aDelBtn.GetPosPixel();
358 : 0 : aNewPos.Y() -= nDelta;
359 [ # # ]: 0 : aDelBtn.SetPosPixel( aNewPos );
360 : 0 : }
361 : :
362 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|