Branch data 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 <vcl/msgbox.hxx>
21 : : #include <sot/storinfo.hxx>
22 : :
23 : : #include <moduldlg.hrc>
24 : : #include <moduldlg.hxx>
25 : : #include <basidesh.hrc>
26 : : #include <basidesh.hxx>
27 : : #include <bastypes.hxx>
28 : : #include <basobj.hxx>
29 : : #include <baside2.hrc>
30 : : #include <iderdll.hxx>
31 : : #include <iderdll2.hxx>
32 : : #include <svx/passwd.hxx>
33 : : #include <sbxitem.hxx>
34 : : #include <basdoc.hxx>
35 : : #include <ucbhelper/content.hxx>
36 : : #include "rtl/uri.hxx"
37 : : #include <sfx2/app.hxx>
38 : : #include <sfx2/dinfdlg.hxx>
39 : : #include <sfx2/dispatch.hxx>
40 : : #include <sfx2/request.hxx>
41 : : #include <tools/urlobj.hxx>
42 : : #include <tools/diagnose_ex.h>
43 : :
44 : : #include <sot/storage.hxx>
45 : : #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
46 : : #include <com/sun/star/ui/dialogs/XFolderPicker.hpp>
47 : : #include <com/sun/star/ui/dialogs/XFilterManager.hpp>
48 : : #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
49 : : #include <com/sun/star/script/XLibraryContainer2.hpp>
50 : : #include <com/sun/star/script/XLibraryContainerPassword.hpp>
51 : : #include <com/sun/star/script/XLibraryContainerExport.hpp>
52 : : #include <com/sun/star/ucb/SimpleFileAccess.hpp>
53 : : #include <com/sun/star/ucb/XSimpleFileAccess2.hpp>
54 : : #include "com/sun/star/ucb/XCommandEnvironment.hpp"
55 : : #include <com/sun/star/ucb/NameClash.hpp>
56 : : #include "com/sun/star/packages/manifest/XManifestWriter.hpp"
57 : : #include <unotools/pathoptions.hxx>
58 : : #include <comphelper/processfactory.hxx>
59 : :
60 : : #include <com/sun/star/util/VetoException.hpp>
61 : : #include <com/sun/star/script/ModuleSizeExceededRequest.hpp>
62 : :
63 : : using ::rtl::OUString;
64 : : using namespace ::com::sun::star;
65 : : using namespace ::com::sun::star::uno;
66 : : using namespace ::com::sun::star::lang;
67 : : using namespace ::com::sun::star::ucb;
68 : : using namespace ::com::sun::star::ui::dialogs;
69 : :
70 : :
71 : : typedef ::cppu::WeakImplHelper1< task::XInteractionHandler > HandlerImpl_BASE;
72 : :
73 : 0 : class DummyInteractionHandler : public HandlerImpl_BASE
74 : : {
75 : : Reference< task::XInteractionHandler > m_xHandler;
76 : : public:
77 : 0 : DummyInteractionHandler( const Reference< task::XInteractionHandler >& xHandler ) : m_xHandler( xHandler ){}
78 : :
79 : 0 : virtual void SAL_CALL handle( const Reference< task::XInteractionRequest >& rRequest ) throw (::com::sun::star::uno::RuntimeException)
80 : : {
81 : 0 : if ( m_xHandler.is() )
82 : : {
83 : 0 : script::ModuleSizeExceededRequest aModSizeException;
84 : 0 : if ( rRequest->getRequest() >>= aModSizeException )
85 : 0 : m_xHandler->handle( rRequest );
86 : : }
87 : 0 : }
88 : : };
89 : :
90 : : //----------------------------------------------------------------------------
91 : : // BasicLibUserData
92 : : //----------------------------------------------------------------------------
93 : : class BasicLibUserData
94 : : {
95 : : private:
96 : : ScriptDocument m_aDocument;
97 : :
98 : : public:
99 : 0 : BasicLibUserData( const ScriptDocument& rDocument ) : m_aDocument( rDocument ) { }
100 : 0 : virtual ~BasicLibUserData() {};
101 : :
102 : : const ScriptDocument&
103 : 0 : GetDocument() const { return m_aDocument; }
104 : : };
105 : :
106 : :
107 : : //----------------------------------------------------------------------------
108 : : // BasicLibLBoxString
109 : : //----------------------------------------------------------------------------
110 : :
111 : 0 : class BasicLibLBoxString : public SvLBoxString
112 : : {
113 : : public:
114 : 0 : BasicLibLBoxString( SvLBoxEntry* pEntry, sal_uInt16 nFlags, const String& rTxt ) :
115 : 0 : SvLBoxString( pEntry, nFlags, rTxt ) {}
116 : :
117 : : virtual void Paint( const Point& rPos, SvLBox& rDev, sal_uInt16 nFlags, SvLBoxEntry* pEntry );
118 : : };
119 : :
120 : : //----------------------------------------------------------------------------
121 : :
122 : 0 : void BasicLibLBoxString::Paint( const Point& rPos, SvLBox& rDev, sal_uInt16, SvLBoxEntry* pEntry )
123 : : {
124 : : // Change text color if library is read only:
125 : 0 : bool bReadOnly = false;
126 : 0 : if (pEntry && pEntry->GetUserData())
127 : : {
128 : : ScriptDocument aDocument(
129 : 0 : static_cast< BasicLibUserData * >(pEntry->GetUserData())->
130 : 0 : GetDocument() );
131 : :
132 : : rtl::OUString aLibName(
133 : 0 : static_cast< SvLBoxString * >(pEntry->GetItem(1))->GetText());
134 : : Reference< script::XLibraryContainer2 > xModLibContainer(
135 : 0 : aDocument.getLibraryContainer( E_SCRIPTS ), UNO_QUERY);
136 : : Reference< script::XLibraryContainer2 > xDlgLibContainer(
137 : 0 : aDocument.getLibraryContainer( E_DIALOGS ), UNO_QUERY);
138 : : bReadOnly
139 : 0 : = (xModLibContainer.is() && xModLibContainer->hasByName(aLibName)
140 : 0 : && xModLibContainer->isLibraryReadOnly(aLibName))
141 : 0 : || (xDlgLibContainer.is() && xDlgLibContainer->hasByName(aLibName)
142 : 0 : && xDlgLibContainer->isLibraryReadOnly(aLibName));
143 : : }
144 : 0 : if (bReadOnly)
145 : 0 : rDev.DrawCtrlText(rPos, GetText(), 0, STRING_LEN, TEXT_DRAW_DISABLE);
146 : : else
147 : 0 : rDev.DrawText(rPos, GetText());
148 : 0 : }
149 : :
150 : :
151 : : //----------------------------------------------------------------------------
152 : : // BasicCheckBox
153 : : //----------------------------------------------------------------------------
154 : :
155 : 0 : BasicCheckBox::BasicCheckBox( Window* pParent, const ResId& rResId )
156 : : :SvTabListBox( pParent, rResId )
157 : 0 : ,m_aDocument( ScriptDocument::getApplicationScriptDocument() )
158 : : {
159 : 0 : nMode = NEWOBJECTMODE_MOD;
160 : 0 : long aTabs_[] = { 1, 12 }; // TabPos needs at least one...
161 : : // 12 because of the CheckBox
162 : 0 : SetTabs( aTabs_ );
163 : 0 : Init();
164 : 0 : }
165 : :
166 : : //----------------------------------------------------------------------------
167 : :
168 : 0 : BasicCheckBox::~BasicCheckBox()
169 : : {
170 : 0 : delete pCheckButton;
171 : :
172 : : // delete user data
173 : 0 : SvLBoxEntry* pEntry = First();
174 : 0 : while ( pEntry )
175 : : {
176 : 0 : delete static_cast<BasicLibUserData*>(pEntry->GetUserData());
177 : 0 : pEntry = Next( pEntry );
178 : : }
179 : 0 : }
180 : :
181 : : //----------------------------------------------------------------------------
182 : :
183 : 0 : void BasicCheckBox::Init()
184 : : {
185 : 0 : pCheckButton = new SvLBoxButtonData(this);
186 : :
187 : 0 : if ( nMode == LIBMODE_CHOOSER )
188 : 0 : EnableCheckButton( pCheckButton );
189 : : else
190 : 0 : EnableCheckButton( 0 );
191 : :
192 : 0 : SetHighlightRange();
193 : 0 : }
194 : :
195 : : //----------------------------------------------------------------------------
196 : :
197 : 0 : void BasicCheckBox::SetMode( NewObjectMode n )
198 : : {
199 : 0 : nMode = n;
200 : :
201 : 0 : if ( nMode == LIBMODE_CHOOSER )
202 : 0 : EnableCheckButton( pCheckButton );
203 : : else
204 : 0 : EnableCheckButton( 0 );
205 : 0 : }
206 : :
207 : : //----------------------------------------------------------------------------
208 : :
209 : 0 : SvLBoxEntry* BasicCheckBox::DoInsertEntry( const String& rStr, sal_uLong nPos )
210 : : {
211 : 0 : return SvTabListBox::InsertEntryToColumn( rStr, nPos, 0 );
212 : : }
213 : :
214 : : //----------------------------------------------------------------------------
215 : :
216 : 0 : SvLBoxEntry* BasicCheckBox::FindEntry( const String& rName )
217 : : {
218 : 0 : sal_uLong nCount = GetEntryCount();
219 : 0 : for ( sal_uLong i = 0; i < nCount; i++ )
220 : : {
221 : 0 : SvLBoxEntry* pEntry = GetEntry( i );
222 : : DBG_ASSERT( pEntry, "pEntry?!" );
223 : 0 : if ( rName.CompareIgnoreCaseToAscii( GetEntryText( pEntry, 0 ) ) == COMPARE_EQUAL )
224 : 0 : return pEntry;
225 : : }
226 : 0 : return 0;
227 : : }
228 : :
229 : : //----------------------------------------------------------------------------
230 : :
231 : 0 : void BasicCheckBox::CheckEntryPos( sal_uLong nPos )
232 : : {
233 : 0 : if ( nPos < GetEntryCount() )
234 : : {
235 : 0 : SvLBoxEntry* pEntry = GetEntry( nPos );
236 : :
237 : 0 : if ( GetCheckButtonState( pEntry ) != SV_BUTTON_CHECKED )
238 : 0 : SetCheckButtonState( pEntry, SvButtonState(SV_BUTTON_CHECKED) );
239 : : }
240 : 0 : }
241 : :
242 : : //----------------------------------------------------------------------------
243 : :
244 : 0 : bool BasicCheckBox::IsChecked( sal_uLong nPos ) const
245 : : {
246 : 0 : if ( nPos < GetEntryCount() )
247 : 0 : return GetCheckButtonState(GetEntry(nPos)) == SV_BUTTON_CHECKED;
248 : 0 : return false;
249 : : }
250 : :
251 : : //----------------------------------------------------------------------------
252 : :
253 : 0 : void BasicCheckBox::InitEntry( SvLBoxEntry* pEntry, const XubString& rTxt, const Image& rImg1, const Image& rImg2, SvLBoxButtonKind eButtonKind )
254 : : {
255 : 0 : SvTabListBox::InitEntry( pEntry, rTxt, rImg1, rImg2, eButtonKind );
256 : :
257 : 0 : if ( nMode == NEWOBJECTMODE_MOD )
258 : : {
259 : : // initialize all columns with own string class (column 0 == bitmap)
260 : 0 : sal_uInt16 nCount = pEntry->ItemCount();
261 : 0 : for ( sal_uInt16 nCol = 1; nCol < nCount; ++nCol )
262 : : {
263 : 0 : SvLBoxString* pCol = (SvLBoxString*)pEntry->GetItem( nCol );
264 : 0 : BasicLibLBoxString* pStr = new BasicLibLBoxString( pEntry, 0, pCol->GetText() );
265 : 0 : pEntry->ReplaceItem( pStr, nCol );
266 : : }
267 : : }
268 : 0 : }
269 : :
270 : : //----------------------------------------------------------------------------
271 : :
272 : 0 : sal_Bool BasicCheckBox::EditingEntry( SvLBoxEntry* pEntry, Selection& )
273 : : {
274 : 0 : if ( nMode != NEWOBJECTMODE_MOD )
275 : 0 : return false;
276 : :
277 : : DBG_ASSERT( pEntry, "Kein Eintrag?" );
278 : :
279 : : // check, if Standard library
280 : 0 : ::rtl::OUString aLibName = GetEntryText( pEntry, 0 );
281 : 0 : if ( aLibName.equalsIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "Standard" ) ) )
282 : : {
283 : 0 : ErrorBox( this, WB_OK | WB_DEF_OK, IDE_RESSTR(RID_STR_CANNOTCHANGENAMESTDLIB) ).Execute();
284 : 0 : return false;
285 : : }
286 : :
287 : : // check, if library is readonly
288 : 0 : Reference< script::XLibraryContainer2 > xModLibContainer( m_aDocument.getLibraryContainer( E_SCRIPTS ), UNO_QUERY );
289 : 0 : Reference< script::XLibraryContainer2 > xDlgLibContainer( m_aDocument.getLibraryContainer( E_DIALOGS ), UNO_QUERY );
290 : 0 : if ( ( xModLibContainer.is() && xModLibContainer->hasByName( aLibName ) && xModLibContainer->isLibraryReadOnly( aLibName ) && !xModLibContainer->isLibraryLink( aLibName ) ) ||
291 : 0 : ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aLibName ) && xDlgLibContainer->isLibraryReadOnly( aLibName ) && !xDlgLibContainer->isLibraryLink( aLibName ) ) )
292 : : {
293 : 0 : ErrorBox( this, WB_OK | WB_DEF_OK, IDE_RESSTR(RID_STR_LIBISREADONLY) ).Execute();
294 : 0 : return false;
295 : : }
296 : :
297 : : // i24094: Password verification necessary for renaming
298 : 0 : bool bOK = true;
299 : 0 : if ( xModLibContainer.is() && xModLibContainer->hasByName( aLibName ) && !xModLibContainer->isLibraryLoaded( aLibName ) )
300 : : {
301 : : // check password
302 : 0 : Reference< script::XLibraryContainerPassword > xPasswd( xModLibContainer, UNO_QUERY );
303 : 0 : if ( xPasswd.is() && xPasswd->isLibraryPasswordProtected( aLibName ) && !xPasswd->isLibraryPasswordVerified( aLibName ) )
304 : : {
305 : 0 : ::rtl::OUString aPassword;
306 : 0 : Reference< script::XLibraryContainer > xModLibContainer1( xModLibContainer, UNO_QUERY );
307 : 0 : bOK = QueryPassword( xModLibContainer1, aLibName, aPassword );
308 : : }
309 : 0 : if ( !bOK )
310 : 0 : return false;
311 : : }
312 : :
313 : : // TODO: check if library is reference/link
314 : :
315 : 0 : return true;
316 : : }
317 : :
318 : : //----------------------------------------------------------------------------
319 : :
320 : 0 : sal_Bool BasicCheckBox::EditedEntry( SvLBoxEntry* pEntry, const rtl::OUString& rNewName )
321 : : {
322 : 0 : bool bValid = ( rNewName.getLength() <= 30 ) && BasicIDE::IsValidSbxName( rNewName );
323 : 0 : rtl::OUString aOldName( GetEntryText( pEntry, 0 ) );
324 : 0 : if ( bValid && ( aOldName != rNewName ) )
325 : : {
326 : : try
327 : : {
328 : 0 : Reference< script::XLibraryContainer2 > xModLibContainer( m_aDocument.getLibraryContainer( E_SCRIPTS ), UNO_QUERY );
329 : 0 : if ( xModLibContainer.is() )
330 : 0 : xModLibContainer->renameLibrary( aOldName, rNewName );
331 : :
332 : 0 : Reference< script::XLibraryContainer2 > xDlgLibContainer( m_aDocument.getLibraryContainer( E_DIALOGS ), UNO_QUERY );
333 : 0 : if ( xDlgLibContainer.is() )
334 : 0 : xDlgLibContainer->renameLibrary( aOldName, rNewName );
335 : :
336 : 0 : BasicIDE::MarkDocumentModified( m_aDocument );
337 : 0 : SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
338 : 0 : if ( pBindings )
339 : : {
340 : 0 : pBindings->Invalidate( SID_BASICIDE_LIBSELECTOR );
341 : 0 : pBindings->Update( SID_BASICIDE_LIBSELECTOR );
342 : 0 : }
343 : : }
344 : 0 : catch (const container::ElementExistException& )
345 : : {
346 : 0 : ErrorBox( this, WB_OK | WB_DEF_OK, IDE_RESSTR(RID_STR_SBXNAMEALLREADYUSED) ).Execute();
347 : 0 : return false;
348 : : }
349 : 0 : catch (const container::NoSuchElementException& )
350 : : {
351 : : DBG_UNHANDLED_EXCEPTION();
352 : 0 : return false;
353 : : }
354 : : }
355 : :
356 : 0 : if ( !bValid )
357 : : {
358 : 0 : if ( rNewName.getLength() > 30 )
359 : 0 : ErrorBox( this, WB_OK | WB_DEF_OK, IDE_RESSTR(RID_STR_LIBNAMETOLONG) ).Execute();
360 : : else
361 : 0 : ErrorBox( this, WB_OK | WB_DEF_OK, IDE_RESSTR(RID_STR_BADSBXNAME) ).Execute();
362 : : }
363 : :
364 : 0 : return bValid;
365 : : }
366 : :
367 : : //----------------------------------------------------------------------------
368 : : // NewObjectDialog
369 : : //----------------------------------------------------------------------------
370 : :
371 : 0 : IMPL_LINK_NOARG(NewObjectDialog, OkButtonHandler)
372 : : {
373 : 0 : if (BasicIDE::IsValidSbxName(aEdit.GetText()))
374 : 0 : EndDialog(1);
375 : : else
376 : : {
377 : : ErrorBox(this, WB_OK | WB_DEF_OK,
378 : 0 : IDE_RESSTR(RID_STR_BADSBXNAME)).Execute();
379 : 0 : aEdit.GrabFocus();
380 : : }
381 : 0 : return 0;
382 : : }
383 : :
384 : 0 : NewObjectDialog::NewObjectDialog(Window * pParent, NewObjectMode nMode,
385 : : bool bCheckName)
386 : : : ModalDialog( pParent, IDEResId( RID_DLG_NEWLIB ) ),
387 : : aText( this, IDEResId( RID_FT_NEWLIB ) ),
388 : : aEdit( this, IDEResId( RID_ED_LIBNAME ) ),
389 : : aOKButton( this, IDEResId( RID_PB_OK ) ),
390 : 0 : aCancelButton( this, IDEResId( RID_PB_CANCEL ) )
391 : : {
392 : 0 : FreeResource();
393 : 0 : aEdit.GrabFocus();
394 : :
395 : 0 : switch (nMode)
396 : : {
397 : : case NEWOBJECTMODE_LIB:
398 : 0 : SetText( IDE_RESSTR(RID_STR_NEWLIB) );
399 : 0 : break;
400 : : case NEWOBJECTMODE_MOD:
401 : 0 : SetText( IDE_RESSTR(RID_STR_NEWMOD) );
402 : 0 : break;
403 : : case NEWOBJECTMODE_METH:
404 : 0 : SetText( IDE_RESSTR(RID_STR_NEWMETH) );
405 : 0 : break;
406 : : default:
407 : 0 : SetText( IDE_RESSTR(RID_STR_NEWDLG) );
408 : 0 : break;
409 : : }
410 : :
411 : 0 : if (bCheckName)
412 : 0 : aOKButton.SetClickHdl(LINK(this, NewObjectDialog, OkButtonHandler));
413 : 0 : }
414 : :
415 : : //----------------------------------------------------------------------------
416 : :
417 : 0 : NewObjectDialog::~NewObjectDialog()
418 : : {
419 : 0 : }
420 : :
421 : :
422 : : //----------------------------------------------------------------------------
423 : : // GotoLineDialog
424 : : //----------------------------------------------------------------------------
425 : :
426 : 0 : GotoLineDialog::GotoLineDialog(Window * pParent )
427 : : : ModalDialog( pParent, IDEResId( RID_DLG_GOTOLINE ) ),
428 : : aText( this, IDEResId( RID_FT_LINE ) ),
429 : : aEdit( this, IDEResId( RID_ED_LINE ) ),
430 : : aOKButton( this, IDEResId( RID_PB_OK ) ),
431 : 0 : aCancelButton( this, IDEResId( RID_PB_CANCEL ) )
432 : : {
433 : 0 : FreeResource();
434 : 0 : aEdit.GrabFocus();
435 : :
436 : 0 : SetText( IDE_RESSTR(RID_STR_GETLINE) );
437 : 0 : aOKButton.SetClickHdl(LINK(this, GotoLineDialog, OkButtonHandler));
438 : :
439 : 0 : }
440 : :
441 : 0 : sal_Int32 GotoLineDialog::GetLineNumber()
442 : : {
443 : 0 : return rtl::OUString( aEdit.GetText() ).toInt32();
444 : : }
445 : :
446 : 0 : IMPL_LINK_NOARG(GotoLineDialog, OkButtonHandler)
447 : : {
448 : 0 : if ( GetLineNumber() )
449 : 0 : EndDialog(1);
450 : : else
451 : 0 : aEdit.SetText( aEdit.GetText(), Selection(0, aEdit.GetText().Len() ));
452 : 0 : return 0;
453 : : }
454 : :
455 : :
456 : : //----------------------------------------------------------------------------
457 : : // ExportDialog
458 : : //----------------------------------------------------------------------------
459 : :
460 : 0 : IMPL_LINK_NOARG(ExportDialog, OkButtonHandler)
461 : : {
462 : 0 : mbExportAsPackage = maExportAsPackageButton.IsChecked();
463 : 0 : EndDialog(1);
464 : 0 : return 0;
465 : : }
466 : :
467 : 0 : ExportDialog::ExportDialog( Window * pParent )
468 : : : ModalDialog( pParent, IDEResId( RID_DLG_EXPORT ) ),
469 : : maExportAsPackageButton( this, IDEResId( RB_EXPORTASPACKAGE ) ),
470 : : maExportAsBasicButton( this, IDEResId( RB_EXPORTASBASIC ) ),
471 : : maOKButton( this, IDEResId( RID_PB_OK ) ),
472 : 0 : maCancelButton( this, IDEResId( RID_PB_CANCEL ) )
473 : : {
474 : 0 : FreeResource();
475 : 0 : maExportAsPackageButton.Check();
476 : 0 : maOKButton.SetClickHdl(LINK(this, ExportDialog, OkButtonHandler));
477 : 0 : }
478 : :
479 : : //----------------------------------------------------------------------------
480 : :
481 : 0 : ExportDialog::~ExportDialog()
482 : : {
483 : 0 : }
484 : :
485 : : //----------------------------------------------------------------------------
486 : : // LibPage
487 : : //----------------------------------------------------------------------------
488 : :
489 : 0 : LibPage::LibPage( Window * pParent )
490 : : :TabPage( pParent, IDEResId( RID_TP_LIBS ) )
491 : : ,aBasicsText( this, IDEResId( RID_STR_BASICS ) )
492 : : ,aBasicsBox( this, IDEResId( RID_LB_BASICS ) )
493 : : ,aLibText( this, IDEResId( RID_STR_LIB ) )
494 : : ,aLibBox( this, IDEResId( RID_TRLBOX ) )
495 : : ,aEditButton( this, IDEResId( RID_PB_EDIT ) )
496 : : ,aCloseButton( this, IDEResId( RID_PB_CLOSE ) )
497 : : ,aPasswordButton( this, IDEResId( RID_PB_PASSWORD ) )
498 : : ,aNewLibButton( this, IDEResId( RID_PB_NEWLIB ) )
499 : : ,aInsertLibButton( this, IDEResId( RID_PB_APPEND ) )
500 : : ,aExportButton( this, IDEResId( RID_PB_EXPORT ) )
501 : : ,aDelButton( this, IDEResId( RID_PB_DELETE ) )
502 : 0 : ,m_aCurDocument( ScriptDocument::getApplicationScriptDocument() )
503 : 0 : ,m_eCurLocation( LIBRARY_LOCATION_UNKNOWN )
504 : : {
505 : 0 : FreeResource();
506 : 0 : pTabDlg = 0;
507 : :
508 : 0 : aEditButton.SetClickHdl( LINK( this, LibPage, ButtonHdl ) );
509 : 0 : aNewLibButton.SetClickHdl( LINK( this, LibPage, ButtonHdl ) );
510 : 0 : aPasswordButton.SetClickHdl( LINK( this, LibPage, ButtonHdl ) );
511 : 0 : aExportButton.SetClickHdl( LINK( this, LibPage, ButtonHdl ) );
512 : 0 : aInsertLibButton.SetClickHdl( LINK( this, LibPage, ButtonHdl ) );
513 : 0 : aDelButton.SetClickHdl( LINK( this, LibPage, ButtonHdl ) );
514 : 0 : aCloseButton.SetClickHdl( LINK( this, LibPage, ButtonHdl ) );
515 : 0 : aLibBox.SetSelectHdl( LINK( this, LibPage, TreeListHighlightHdl ) );
516 : :
517 : 0 : aBasicsBox.SetSelectHdl( LINK( this, LibPage, BasicSelectHdl ) );
518 : :
519 : 0 : aLibBox.SetMode( NEWOBJECTMODE_MOD );
520 : 0 : aLibBox.EnableInplaceEditing(true);
521 : 0 : aLibBox.SetStyle( WB_HSCROLL | WB_BORDER | WB_TABSTOP );
522 : 0 : aCloseButton.GrabFocus();
523 : :
524 : 0 : long aTabs[] = { 2, 30, 120 };
525 : 0 : aLibBox.SetTabs( aTabs, MAP_PIXEL );
526 : :
527 : 0 : FillListBox();
528 : 0 : aBasicsBox.SelectEntryPos( 0 );
529 : 0 : SetCurLib();
530 : :
531 : 0 : CheckButtons();
532 : 0 : }
533 : :
534 : : //----------------------------------------------------------------------------
535 : :
536 : 0 : LibPage::~LibPage()
537 : : {
538 : 0 : sal_uInt16 nCount = aBasicsBox.GetEntryCount();
539 : 0 : for ( sal_uInt16 i = 0; i < nCount; ++i )
540 : : {
541 : 0 : BasicDocumentEntry* pEntry = (BasicDocumentEntry*)aBasicsBox.GetEntryData( i );
542 : 0 : delete pEntry;
543 : : }
544 : 0 : }
545 : :
546 : : //----------------------------------------------------------------------------
547 : :
548 : 0 : void LibPage::CheckButtons()
549 : : {
550 : 0 : SvLBoxEntry* pCur = aLibBox.GetCurEntry();
551 : 0 : if ( pCur )
552 : : {
553 : 0 : ::rtl::OUString aLibName = aLibBox.GetEntryText( pCur, 0 );
554 : 0 : Reference< script::XLibraryContainer2 > xModLibContainer( m_aCurDocument.getLibraryContainer( E_SCRIPTS ), UNO_QUERY );
555 : 0 : Reference< script::XLibraryContainer2 > xDlgLibContainer( m_aCurDocument.getLibraryContainer( E_DIALOGS ), UNO_QUERY );
556 : :
557 : 0 : if ( m_eCurLocation == LIBRARY_LOCATION_SHARE )
558 : : {
559 : 0 : aPasswordButton.Disable();
560 : 0 : aNewLibButton.Disable();
561 : 0 : aInsertLibButton.Disable();
562 : 0 : aDelButton.Disable();
563 : : }
564 : 0 : else if ( aLibName.equalsIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "Standard" ) ) )
565 : : {
566 : 0 : aPasswordButton.Disable();
567 : 0 : aNewLibButton.Enable();
568 : 0 : aInsertLibButton.Enable();
569 : 0 : aExportButton.Disable();
570 : 0 : aDelButton.Disable();
571 : 0 : if ( !aLibBox.HasFocus() )
572 : 0 : aCloseButton.GrabFocus();
573 : : }
574 : 0 : else if ( ( xModLibContainer.is() && xModLibContainer->hasByName( aLibName ) && xModLibContainer->isLibraryReadOnly( aLibName ) ) ||
575 : 0 : ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aLibName ) && xDlgLibContainer->isLibraryReadOnly( aLibName ) ) )
576 : : {
577 : 0 : aPasswordButton.Disable();
578 : 0 : aNewLibButton.Enable();
579 : 0 : aInsertLibButton.Enable();
580 : 0 : if ( ( xModLibContainer.is() && xModLibContainer->hasByName( aLibName ) && xModLibContainer->isLibraryReadOnly( aLibName ) && !xModLibContainer->isLibraryLink( aLibName ) ) ||
581 : 0 : ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aLibName ) && xDlgLibContainer->isLibraryReadOnly( aLibName ) && !xDlgLibContainer->isLibraryLink( aLibName ) ) )
582 : 0 : aDelButton.Disable();
583 : : else
584 : 0 : aDelButton.Enable();
585 : : }
586 : : else
587 : : {
588 : 0 : if ( xModLibContainer.is() && !xModLibContainer->hasByName( aLibName ) )
589 : 0 : aPasswordButton.Disable();
590 : : else
591 : 0 : aPasswordButton.Enable();
592 : :
593 : 0 : aNewLibButton.Enable();
594 : 0 : aInsertLibButton.Enable();
595 : 0 : aExportButton.Enable();
596 : 0 : aDelButton.Enable();
597 : 0 : }
598 : : }
599 : 0 : }
600 : :
601 : : //----------------------------------------------------------------------------
602 : :
603 : 0 : void LibPage::ActivatePage()
604 : : {
605 : 0 : SetCurLib();
606 : 0 : }
607 : :
608 : : //----------------------------------------------------------------------------
609 : :
610 : :
611 : 0 : void LibPage::DeactivatePage()
612 : : {
613 : 0 : }
614 : :
615 : : //----------------------------------------------------------------------------
616 : :
617 : :
618 : 0 : IMPL_LINK_INLINE_START( LibPage, TreeListHighlightHdl, SvTreeListBox *, pBox )
619 : : {
620 : 0 : if ( pBox->IsSelected( pBox->GetHdlEntry() ) )
621 : 0 : CheckButtons();
622 : 0 : return 0;
623 : : }
624 : 0 : IMPL_LINK_INLINE_END( LibPage, TreeListHighlightHdl, SvTreeListBox *, pBox )
625 : :
626 : : //----------------------------------------------------------------------------
627 : :
628 : 0 : IMPL_LINK_INLINE_START( LibPage, BasicSelectHdl, ListBox *, pBox )
629 : : {
630 : : (void)pBox;
631 : 0 : SetCurLib();
632 : 0 : CheckButtons();
633 : 0 : return 0;
634 : : }
635 : 0 : IMPL_LINK_INLINE_END( LibPage, BasicSelectHdl, ListBox *, pBox )
636 : :
637 : : //----------------------------------------------------------------------------
638 : :
639 : 0 : IMPL_LINK( LibPage, ButtonHdl, Button *, pButton )
640 : : {
641 : 0 : if ( pButton == &aEditButton )
642 : : {
643 : 0 : SfxAllItemSet aArgs( SFX_APP()->GetPool() );
644 : 0 : SfxRequest aRequest( SID_BASICIDE_APPEAR, SFX_CALLMODE_SYNCHRON, aArgs );
645 : 0 : SFX_APP()->ExecuteSlot( aRequest );
646 : :
647 : 0 : SfxUsrAnyItem aDocItem( SID_BASICIDE_ARG_DOCUMENT_MODEL, makeAny( m_aCurDocument.getDocumentOrNull() ) );
648 : 0 : SvLBoxEntry* pCurEntry = aLibBox.GetCurEntry();
649 : : DBG_ASSERT( pCurEntry, "Entry?!" );
650 : 0 : String aLibName( aLibBox.GetEntryText( pCurEntry, 0 ) );
651 : 0 : SfxStringItem aLibNameItem( SID_BASICIDE_ARG_LIBNAME, aLibName );
652 : 0 : BasicIDEShell* pIDEShell = BasicIDEGlobals::GetShell();
653 : 0 : SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL;
654 : 0 : SfxDispatcher* pDispatcher = pViewFrame ? pViewFrame->GetDispatcher() : NULL;
655 : 0 : if ( pDispatcher )
656 : : {
657 : : pDispatcher->Execute( SID_BASICIDE_LIBSELECTED,
658 : 0 : SFX_CALLMODE_ASYNCHRON, &aDocItem, &aLibNameItem, 0L );
659 : : }
660 : 0 : EndTabDialog( 1 );
661 : 0 : return 0;
662 : : }
663 : 0 : else if ( pButton == &aNewLibButton )
664 : 0 : NewLib();
665 : 0 : else if ( pButton == &aInsertLibButton )
666 : 0 : InsertLib();
667 : 0 : else if ( pButton == &aExportButton )
668 : 0 : Export();
669 : 0 : else if ( pButton == &aDelButton )
670 : 0 : DeleteCurrent();
671 : 0 : else if ( pButton == &aCloseButton )
672 : : {
673 : 0 : EndTabDialog( 0 );
674 : 0 : return 0;
675 : : }
676 : 0 : else if ( pButton == &aPasswordButton )
677 : : {
678 : 0 : SvLBoxEntry* pCurEntry = aLibBox.GetCurEntry();
679 : 0 : ::rtl::OUString aLibName( aLibBox.GetEntryText( pCurEntry, 0 ) );
680 : :
681 : : // load module library (if not loaded)
682 : 0 : Reference< script::XLibraryContainer > xModLibContainer = m_aCurDocument.getLibraryContainer( E_SCRIPTS );
683 : 0 : if ( xModLibContainer.is() && xModLibContainer->hasByName( aLibName ) && !xModLibContainer->isLibraryLoaded( aLibName ) )
684 : : {
685 : 0 : BasicIDEShell* pIDEShell = BasicIDEGlobals::GetShell();
686 : 0 : if ( pIDEShell )
687 : 0 : pIDEShell->GetViewFrame()->GetWindow().EnterWait();
688 : 0 : xModLibContainer->loadLibrary( aLibName );
689 : 0 : if ( pIDEShell )
690 : 0 : pIDEShell->GetViewFrame()->GetWindow().LeaveWait();
691 : : }
692 : :
693 : : // load dialog library (if not loaded)
694 : 0 : Reference< script::XLibraryContainer > xDlgLibContainer = m_aCurDocument.getLibraryContainer( E_DIALOGS );
695 : 0 : if ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aLibName ) && !xDlgLibContainer->isLibraryLoaded( aLibName ) )
696 : : {
697 : 0 : BasicIDEShell* pIDEShell = BasicIDEGlobals::GetShell();
698 : 0 : if ( pIDEShell )
699 : 0 : pIDEShell->GetViewFrame()->GetWindow().EnterWait();
700 : 0 : xDlgLibContainer->loadLibrary( aLibName );
701 : 0 : if ( pIDEShell )
702 : 0 : pIDEShell->GetViewFrame()->GetWindow().LeaveWait();
703 : : }
704 : :
705 : : // check, if library is password protected
706 : 0 : if ( xModLibContainer.is() && xModLibContainer->hasByName( aLibName ) )
707 : : {
708 : 0 : Reference< script::XLibraryContainerPassword > xPasswd( xModLibContainer, UNO_QUERY );
709 : 0 : if ( xPasswd.is() )
710 : : {
711 : 0 : bool const bProtected = xPasswd->isLibraryPasswordProtected( aLibName );
712 : :
713 : : // change password dialog
714 : 0 : SvxPasswordDialog* pDlg = new SvxPasswordDialog( this, true, !bProtected );
715 : 0 : pDlg->SetCheckPasswordHdl( LINK( this, LibPage, CheckPasswordHdl ) );
716 : :
717 : 0 : if ( pDlg->Execute() == RET_OK )
718 : : {
719 : 0 : bool const bNewProtected = xPasswd->isLibraryPasswordProtected( aLibName );
720 : :
721 : 0 : if ( bNewProtected != bProtected )
722 : : {
723 : 0 : sal_uLong nPos = (sal_uLong)aLibBox.GetModel()->GetAbsPos( pCurEntry );
724 : 0 : aLibBox.GetModel()->Remove( pCurEntry );
725 : 0 : ImpInsertLibEntry( aLibName, nPos );
726 : 0 : aLibBox.SetCurEntry( aLibBox.GetEntry( nPos ) );
727 : : }
728 : :
729 : 0 : BasicIDE::MarkDocumentModified( m_aCurDocument );
730 : : }
731 : 0 : delete pDlg;
732 : 0 : }
733 : 0 : }
734 : : }
735 : 0 : CheckButtons();
736 : 0 : return 0;
737 : : }
738 : :
739 : : //----------------------------------------------------------------------------
740 : :
741 : 0 : IMPL_LINK_INLINE_START( LibPage, CheckPasswordHdl, SvxPasswordDialog *, pDlg )
742 : : {
743 : 0 : long nRet = 0;
744 : :
745 : 0 : SvLBoxEntry* pCurEntry = aLibBox.GetCurEntry();
746 : 0 : ::rtl::OUString aLibName( aLibBox.GetEntryText( pCurEntry, 0 ) );
747 : 0 : Reference< script::XLibraryContainerPassword > xPasswd( m_aCurDocument.getLibraryContainer( E_SCRIPTS ), UNO_QUERY );
748 : :
749 : 0 : if ( xPasswd.is() )
750 : : {
751 : : try
752 : : {
753 : 0 : ::rtl::OUString aOldPassword( pDlg->GetOldPassword() );
754 : 0 : ::rtl::OUString aNewPassword( pDlg->GetNewPassword() );
755 : 0 : xPasswd->changeLibraryPassword( aLibName, aOldPassword, aNewPassword );
756 : 0 : nRet = 1;
757 : : }
758 : 0 : catch (...)
759 : : {
760 : : }
761 : : }
762 : :
763 : 0 : return nRet;
764 : : }
765 : 0 : IMPL_LINK_INLINE_END( LibPage, CheckPasswordHdl, SvxPasswordDialog *, pDlg )
766 : :
767 : : //----------------------------------------------------------------------------
768 : :
769 : 0 : void LibPage::NewLib()
770 : : {
771 : 0 : createLibImpl( static_cast<Window*>( this ), m_aCurDocument, &aLibBox, NULL);
772 : 0 : }
773 : :
774 : : //----------------------------------------------------------------------------
775 : :
776 : 0 : void LibPage::InsertLib()
777 : : {
778 : : // file open dialog
779 : 0 : Reference< lang::XMultiServiceFactory > xMSF( ::comphelper::getProcessServiceFactory() );
780 : 0 : Reference < XFilePicker > xFP;
781 : 0 : if( xMSF.is() )
782 : : {
783 : 0 : Sequence <Any> aServiceType(1);
784 : 0 : aServiceType[0] <<= TemplateDescription::FILEOPEN_SIMPLE;
785 : 0 : xFP = Reference< XFilePicker >( xMSF->createInstanceWithArguments(
786 : 0 : ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.FilePicker" ) ), aServiceType ), UNO_QUERY );
787 : : }
788 : 0 : xFP->setTitle( String( IDEResId( RID_STR_APPENDLIBS ) ) );
789 : :
790 : : // filter
791 : 0 : ::rtl::OUString aTitle = String( IDEResId( RID_STR_BASIC ) );
792 : 0 : ::rtl::OUString aFilter;
793 : 0 : aFilter = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "*.sbl;*.xlc;*.xlb" ) ); // library files
794 : 0 : aFilter += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ";*.sdw;*.sxw;*.odt" ) ); // text
795 : 0 : aFilter += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ";*.vor;*.stw;*.ott" ) ); // text template
796 : 0 : aFilter += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ";*.sgl;*.sxg;*.odm" ) ); // master document
797 : 0 : aFilter += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ";*.oth" ) ); // html document template
798 : 0 : aFilter += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ";*.sdc;*.sxc;*.ods" ) ); // spreadsheet
799 : 0 : aFilter += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ";*.stc;*.ots" ) ); // spreadsheet template
800 : 0 : aFilter += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ";*.sda;*.sxd;*.odg" ) ); // drawing
801 : 0 : aFilter += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ";*.std;*.otg" ) ); // drawing template
802 : 0 : aFilter += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ";*.sdd;*.sxi;*.odp" ) ); // presentation
803 : 0 : aFilter += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ";*.sti;*.otp" ) ); // presentation template
804 : 0 : aFilter += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ";*.sxm;*.odf" ) ); // formula
805 : 0 : Reference< XFilterManager > xFltMgr(xFP, UNO_QUERY);
806 : 0 : xFltMgr->appendFilter( aTitle, aFilter );
807 : :
808 : : // set display directory and filter
809 : 0 : ::rtl::OUString aPath( BasicIDEGlobals::GetExtraData()->GetAddLibPath() );
810 : 0 : if ( !aPath.isEmpty() )
811 : 0 : xFP->setDisplayDirectory( aPath );
812 : : else
813 : : {
814 : : // macro path from configuration management
815 : 0 : xFP->setDisplayDirectory( SvtPathOptions().GetWorkPath() );
816 : : }
817 : :
818 : 0 : ::rtl::OUString aLastFilter( BasicIDEGlobals::GetExtraData()->GetAddLibFilter() );
819 : 0 : if ( !aLastFilter.isEmpty() )
820 : 0 : xFltMgr->setCurrentFilter( aLastFilter );
821 : : else
822 : 0 : xFltMgr->setCurrentFilter( IDE_RESSTR(RID_STR_BASIC) );
823 : :
824 : 0 : if ( xFP->execute() == RET_OK )
825 : : {
826 : 0 : BasicIDEGlobals::GetExtraData()->SetAddLibPath( xFP->getDisplayDirectory() );
827 : 0 : BasicIDEGlobals::GetExtraData()->SetAddLibFilter( xFltMgr->getCurrentFilter() );
828 : :
829 : : // library containers for import
830 : 0 : Reference< script::XLibraryContainer2 > xModLibContImport;
831 : 0 : Reference< script::XLibraryContainer2 > xDlgLibContImport;
832 : :
833 : : // file URLs
834 : 0 : Sequence< ::rtl::OUString > aFiles = xFP->getFiles();
835 : 0 : INetURLObject aURLObj( aFiles[0] );
836 : 0 : INetURLObject aModURLObj( aURLObj );
837 : 0 : INetURLObject aDlgURLObj( aURLObj );
838 : :
839 : 0 : ::rtl::OUString aBase = aURLObj.getBase();
840 : 0 : ::rtl::OUString aModBase(RTL_CONSTASCII_USTRINGPARAM("script"));
841 : 0 : ::rtl::OUString aDlgBase(RTL_CONSTASCII_USTRINGPARAM("dialog"));
842 : :
843 : 0 : if ( aBase == aModBase || aBase == aDlgBase )
844 : : {
845 : 0 : aModURLObj.setBase( aModBase );
846 : 0 : aDlgURLObj.setBase( aDlgBase );
847 : : }
848 : :
849 : 0 : if ( xMSF.is() )
850 : : {
851 : 0 : Reference< XSimpleFileAccess2 > xSFA( SimpleFileAccess::create(comphelper::getProcessComponentContext()) );
852 : :
853 : 0 : ::rtl::OUString aModURL( aModURLObj.GetMainURL( INetURLObject::NO_DECODE ) );
854 : 0 : if ( xSFA->exists( aModURL ) )
855 : : {
856 : 0 : Sequence <Any> aSeqModURL(1);
857 : 0 : aSeqModURL[0] <<= aModURL;
858 : 0 : xModLibContImport = Reference< script::XLibraryContainer2 >( xMSF->createInstanceWithArguments(
859 : 0 : ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.script.DocumentScriptLibraryContainer" ) ), aSeqModURL ), UNO_QUERY );
860 : : }
861 : :
862 : 0 : ::rtl::OUString aDlgURL( aDlgURLObj.GetMainURL( INetURLObject::NO_DECODE ) );
863 : 0 : if ( xSFA->exists( aDlgURL ) )
864 : : {
865 : 0 : Sequence <Any> aSeqDlgURL(1);
866 : 0 : aSeqDlgURL[0] <<= aDlgURL;
867 : 0 : xDlgLibContImport = Reference< script::XLibraryContainer2 >( xMSF->createInstanceWithArguments(
868 : 0 : ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.script.DocumentDialogLibraryContainer" ) ), aSeqDlgURL ), UNO_QUERY );
869 : 0 : }
870 : : }
871 : :
872 : 0 : if ( xModLibContImport.is() || xDlgLibContImport.is() )
873 : : {
874 : 0 : LibDialog* pLibDlg = 0;
875 : :
876 : 0 : Reference< script::XLibraryContainer > xModLibContImp( xModLibContImport, UNO_QUERY );
877 : 0 : Reference< script::XLibraryContainer > xDlgLibContImp( xDlgLibContImport, UNO_QUERY );
878 : 0 : Sequence< ::rtl::OUString > aLibNames = BasicIDE::GetMergedLibraryNames( xModLibContImp, xDlgLibContImp );
879 : 0 : sal_Int32 nLibCount = aLibNames.getLength();
880 : 0 : const ::rtl::OUString* pLibNames = aLibNames.getConstArray();
881 : 0 : for ( sal_Int32 i = 0 ; i < nLibCount ; i++ )
882 : : {
883 : : // library import dialog
884 : 0 : if ( !pLibDlg )
885 : : {
886 : 0 : pLibDlg = new LibDialog( this );
887 : 0 : pLibDlg->SetStorageName( aURLObj.getName() );
888 : 0 : pLibDlg->GetLibBox().SetMode( NEWOBJECTMODE_LIB );
889 : : }
890 : :
891 : : // libbox entries
892 : 0 : ::rtl::OUString aLibName( pLibNames[ i ] );
893 : 0 : if ( !( ( xModLibContImport.is() && xModLibContImport->hasByName( aLibName ) && xModLibContImport->isLibraryLink( aLibName ) ) ||
894 : 0 : ( xDlgLibContImport.is() && xDlgLibContImport->hasByName( aLibName ) && xDlgLibContImport->isLibraryLink( aLibName ) ) ) )
895 : : {
896 : 0 : SvLBoxEntry* pEntry = pLibDlg->GetLibBox().DoInsertEntry( aLibName );
897 : 0 : sal_uInt16 nPos = (sal_uInt16) pLibDlg->GetLibBox().GetModel()->GetAbsPos( pEntry );
898 : 0 : pLibDlg->GetLibBox().CheckEntryPos(nPos);
899 : : }
900 : 0 : }
901 : :
902 : 0 : if ( !pLibDlg )
903 : 0 : InfoBox( this, IDE_RESSTR(RID_STR_NOLIBINSTORAGE) ).Execute();
904 : : else
905 : : {
906 : 0 : bool bChanges = false;
907 : 0 : ::rtl::OUString aExtension( aURLObj.getExtension() );
908 : 0 : ::rtl::OUString aLibExtension(RTL_CONSTASCII_USTRINGPARAM("xlb"));
909 : 0 : ::rtl::OUString aContExtension(RTL_CONSTASCII_USTRINGPARAM("xlc"));
910 : :
911 : : // disable reference checkbox for documents and sbls
912 : 0 : if ( aExtension != aLibExtension && aExtension != aContExtension )
913 : 0 : pLibDlg->EnableReference(false);
914 : :
915 : 0 : if ( pLibDlg->Execute() )
916 : : {
917 : 0 : sal_uLong nNewPos = aLibBox.GetEntryCount();
918 : 0 : bool bRemove = false;
919 : 0 : bool bReplace = pLibDlg->IsReplace();
920 : 0 : bool bReference = pLibDlg->IsReference();
921 : 0 : for ( sal_uInt16 nLib = 0; nLib < pLibDlg->GetLibBox().GetEntryCount(); nLib++ )
922 : : {
923 : 0 : if ( pLibDlg->GetLibBox().IsChecked( nLib ) )
924 : : {
925 : 0 : SvLBoxEntry* pEntry = pLibDlg->GetLibBox().GetEntry( nLib );
926 : : DBG_ASSERT( pEntry, "Entry?!" );
927 : 0 : ::rtl::OUString aLibName( pLibDlg->GetLibBox().GetEntryText( pEntry, 0 ) );
928 : 0 : Reference< script::XLibraryContainer2 > xModLibContainer( m_aCurDocument.getLibraryContainer( E_SCRIPTS ), UNO_QUERY );
929 : 0 : Reference< script::XLibraryContainer2 > xDlgLibContainer( m_aCurDocument.getLibraryContainer( E_DIALOGS ), UNO_QUERY );
930 : :
931 : : // check, if the library is already existing
932 : 0 : if ( ( xModLibContainer.is() && xModLibContainer->hasByName( aLibName ) ) ||
933 : 0 : ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aLibName ) ) )
934 : : {
935 : 0 : if ( bReplace )
936 : : {
937 : : // check, if the library is the Standard library
938 : 0 : if ( aLibName == "Standard" )
939 : : {
940 : 0 : ErrorBox( this, WB_OK | WB_DEF_OK, IDE_RESSTR(RID_STR_REPLACESTDLIB) ).Execute();
941 : 0 : continue;
942 : : }
943 : :
944 : : // check, if the library is readonly and not a link
945 : 0 : if ( ( xModLibContainer.is() && xModLibContainer->hasByName( aLibName ) && xModLibContainer->isLibraryReadOnly( aLibName ) && !xModLibContainer->isLibraryLink( aLibName ) ) ||
946 : 0 : ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aLibName ) && xDlgLibContainer->isLibraryReadOnly( aLibName ) && !xDlgLibContainer->isLibraryLink( aLibName ) ) )
947 : : {
948 : 0 : ::rtl::OUString aErrStr( IDE_RESSTR(RID_STR_REPLACELIB) );
949 : 0 : aErrStr = aErrStr.replaceAll("XX", aLibName);
950 : 0 : aErrStr += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\n"));
951 : 0 : aErrStr += IDE_RESSTR(RID_STR_LIBISREADONLY);
952 : 0 : ErrorBox( this, WB_OK | WB_DEF_OK, aErrStr ).Execute();
953 : 0 : continue;
954 : : }
955 : :
956 : : // remove existing libraries
957 : 0 : bRemove = true;
958 : : }
959 : : else
960 : : {
961 : 0 : ::rtl::OUString aErrStr;
962 : 0 : if ( bReference )
963 : 0 : aErrStr = IDE_RESSTR(RID_STR_REFNOTPOSSIBLE);
964 : : else
965 : 0 : aErrStr = IDE_RESSTR(RID_STR_IMPORTNOTPOSSIBLE);
966 : 0 : aErrStr = aErrStr.replaceAll("XX", aLibName);
967 : 0 : aErrStr += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\n"));
968 : 0 : aErrStr += IDE_RESSTR(RID_STR_SBXNAMEALLREADYUSED);
969 : 0 : ErrorBox( this, WB_OK | WB_DEF_OK, aErrStr ).Execute();
970 : 0 : continue;
971 : : }
972 : : }
973 : :
974 : : // check, if the library is password protected
975 : 0 : bool bOK = false;
976 : 0 : ::rtl::OUString aPassword;
977 : 0 : if ( xModLibContImport.is() && xModLibContImport->hasByName( aLibName ) )
978 : : {
979 : 0 : Reference< script::XLibraryContainerPassword > xPasswd( xModLibContImport, UNO_QUERY );
980 : 0 : if ( xPasswd.is() && xPasswd->isLibraryPasswordProtected( aLibName ) && !xPasswd->isLibraryPasswordVerified( aLibName ) && !bReference )
981 : : {
982 : 0 : bOK = QueryPassword( xModLibContImp, aLibName, aPassword, true, true );
983 : :
984 : 0 : if ( !bOK )
985 : : {
986 : 0 : ::rtl::OUString aErrStr( IDE_RESSTR(RID_STR_NOIMPORT) );
987 : 0 : aErrStr = aErrStr.replaceAll("XX", aLibName);
988 : 0 : ErrorBox( this, WB_OK | WB_DEF_OK, aErrStr ).Execute();
989 : 0 : continue;
990 : : }
991 : 0 : }
992 : : }
993 : :
994 : : // remove existing libraries
995 : 0 : if ( bRemove )
996 : : {
997 : : // remove listbox entry
998 : 0 : SvLBoxEntry* pEntry_ = aLibBox.FindEntry( aLibName );
999 : 0 : if ( pEntry_ )
1000 : 0 : aLibBox.SvTreeListBox::GetModel()->Remove( pEntry_ );
1001 : :
1002 : : // remove module library
1003 : 0 : if ( xModLibContainer.is() && xModLibContainer->hasByName( aLibName ) )
1004 : 0 : xModLibContainer->removeLibrary( aLibName );
1005 : :
1006 : : // remove dialog library
1007 : 0 : if ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aLibName ) )
1008 : 0 : xDlgLibContainer->removeLibrary( aLibName );
1009 : : }
1010 : :
1011 : : // copy module library
1012 : 0 : if ( xModLibContImport.is() && xModLibContImport->hasByName( aLibName ) && xModLibContainer.is() && !xModLibContainer->hasByName( aLibName ) )
1013 : : {
1014 : 0 : Reference< container::XNameContainer > xModLib;
1015 : 0 : if ( bReference )
1016 : : {
1017 : : // storage URL
1018 : 0 : INetURLObject aModStorageURLObj( aModURLObj );
1019 : 0 : if ( aExtension == aContExtension )
1020 : : {
1021 : 0 : sal_Int32 nCount = aModStorageURLObj.getSegmentCount();
1022 : 0 : aModStorageURLObj.insertName( aLibName, false, nCount-1 );
1023 : 0 : aModStorageURLObj.setExtension( aLibExtension );
1024 : 0 : aModStorageURLObj.setFinalSlash();
1025 : : }
1026 : 0 : ::rtl::OUString aModStorageURL( aModStorageURLObj.GetMainURL( INetURLObject::NO_DECODE ) );
1027 : :
1028 : : // create library link
1029 : 0 : xModLib = Reference< container::XNameContainer >( xModLibContainer->createLibraryLink( aLibName, aModStorageURL, true ), UNO_QUERY);
1030 : : }
1031 : : else
1032 : : {
1033 : : // create library
1034 : 0 : xModLib = xModLibContainer->createLibrary( aLibName );
1035 : 0 : if ( xModLib.is() )
1036 : : {
1037 : : // get import library
1038 : 0 : Reference< container::XNameContainer > xModLibImport;
1039 : 0 : Any aElement = xModLibContImport->getByName( aLibName );
1040 : 0 : aElement >>= xModLibImport;
1041 : :
1042 : 0 : if ( xModLibImport.is() )
1043 : : {
1044 : : // load library
1045 : 0 : if ( !xModLibContImport->isLibraryLoaded( aLibName ) )
1046 : 0 : xModLibContImport->loadLibrary( aLibName );
1047 : :
1048 : : // copy all modules
1049 : 0 : Sequence< ::rtl::OUString > aModNames = xModLibImport->getElementNames();
1050 : 0 : sal_Int32 nModCount = aModNames.getLength();
1051 : 0 : const ::rtl::OUString* pModNames = aModNames.getConstArray();
1052 : 0 : for ( sal_Int32 i = 0 ; i < nModCount ; i++ )
1053 : : {
1054 : 0 : ::rtl::OUString aModName( pModNames[ i ] );
1055 : 0 : Any aElement_ = xModLibImport->getByName( aModName );
1056 : 0 : xModLib->insertByName( aModName, aElement_ );
1057 : 0 : }
1058 : :
1059 : : // set password
1060 : 0 : if ( bOK )
1061 : : {
1062 : 0 : Reference< script::XLibraryContainerPassword > xPasswd( xModLibContainer, UNO_QUERY );
1063 : 0 : if ( xPasswd.is() )
1064 : : {
1065 : : try
1066 : : {
1067 : 0 : ::rtl::OUString _aPassword( aPassword );
1068 : 0 : xPasswd->changeLibraryPassword( aLibName, ::rtl::OUString(), _aPassword );
1069 : : }
1070 : 0 : catch (...)
1071 : : {
1072 : : }
1073 : 0 : }
1074 : 0 : }
1075 : 0 : }
1076 : : }
1077 : 0 : }
1078 : : }
1079 : :
1080 : : // copy dialog library
1081 : 0 : if ( xDlgLibContImport.is() && xDlgLibContImport->hasByName( aLibName ) && xDlgLibContainer.is() && !xDlgLibContainer->hasByName( aLibName ) )
1082 : : {
1083 : 0 : Reference< container::XNameContainer > xDlgLib;
1084 : 0 : if ( bReference )
1085 : : {
1086 : : // storage URL
1087 : 0 : INetURLObject aDlgStorageURLObj( aDlgURLObj );
1088 : 0 : if ( aExtension == aContExtension )
1089 : : {
1090 : 0 : sal_Int32 nCount = aDlgStorageURLObj.getSegmentCount();
1091 : 0 : aDlgStorageURLObj.insertName( aLibName, false, nCount - 1 );
1092 : 0 : aDlgStorageURLObj.setExtension( aLibExtension );
1093 : 0 : aDlgStorageURLObj.setFinalSlash();
1094 : : }
1095 : 0 : ::rtl::OUString aDlgStorageURL( aDlgStorageURLObj.GetMainURL( INetURLObject::NO_DECODE ) );
1096 : :
1097 : : // create library link
1098 : 0 : xDlgLib = Reference< container::XNameContainer >( xDlgLibContainer->createLibraryLink( aLibName, aDlgStorageURL, true ), UNO_QUERY);
1099 : : }
1100 : : else
1101 : : {
1102 : : // create library
1103 : 0 : xDlgLib = xDlgLibContainer->createLibrary( aLibName );
1104 : 0 : if ( xDlgLib.is() )
1105 : : {
1106 : : // get import library
1107 : 0 : Reference< container::XNameContainer > xDlgLibImport;
1108 : 0 : Any aElement = xDlgLibContImport->getByName( aLibName );
1109 : 0 : aElement >>= xDlgLibImport;
1110 : :
1111 : 0 : if ( xDlgLibImport.is() )
1112 : : {
1113 : : // load library
1114 : 0 : if ( !xDlgLibContImport->isLibraryLoaded( aLibName ) )
1115 : 0 : xDlgLibContImport->loadLibrary( aLibName );
1116 : :
1117 : : // copy all dialogs
1118 : 0 : Sequence< ::rtl::OUString > aDlgNames = xDlgLibImport->getElementNames();
1119 : 0 : sal_Int32 nDlgCount = aDlgNames.getLength();
1120 : 0 : const ::rtl::OUString* pDlgNames = aDlgNames.getConstArray();
1121 : 0 : for ( sal_Int32 i = 0 ; i < nDlgCount ; i++ )
1122 : : {
1123 : 0 : ::rtl::OUString aDlgName( pDlgNames[ i ] );
1124 : 0 : Any aElement_ = xDlgLibImport->getByName( aDlgName );
1125 : 0 : xDlgLib->insertByName( aDlgName, aElement_ );
1126 : 0 : }
1127 : 0 : }
1128 : : }
1129 : 0 : }
1130 : : }
1131 : :
1132 : : // insert listbox entry
1133 : 0 : ImpInsertLibEntry( aLibName, aLibBox.GetEntryCount() );
1134 : 0 : bChanges = true;
1135 : : }
1136 : : }
1137 : :
1138 : 0 : SvLBoxEntry* pFirstNew = aLibBox.GetEntry( nNewPos );
1139 : 0 : if ( pFirstNew )
1140 : 0 : aLibBox.SetCurEntry( pFirstNew );
1141 : : }
1142 : :
1143 : 0 : delete pLibDlg;
1144 : 0 : if ( bChanges )
1145 : 0 : BasicIDE::MarkDocumentModified( m_aCurDocument );
1146 : 0 : }
1147 : 0 : }
1148 : 0 : }
1149 : 0 : }
1150 : :
1151 : : //----------------------------------------------------------------------------
1152 : :
1153 : 0 : void LibPage::Export( void )
1154 : : {
1155 : 0 : SvLBoxEntry* pCurEntry = aLibBox.GetCurEntry();
1156 : 0 : String aLibName( aLibBox.GetEntryText( pCurEntry, 0 ) );
1157 : :
1158 : : // Password verification
1159 : 0 : ::rtl::OUString aOULibName( aLibName );
1160 : 0 : Reference< script::XLibraryContainer2 > xModLibContainer( m_aCurDocument.getLibraryContainer( E_SCRIPTS ), UNO_QUERY );
1161 : :
1162 : 0 : if ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) && !xModLibContainer->isLibraryLoaded( aOULibName ) )
1163 : : {
1164 : 0 : bool bOK = true;
1165 : :
1166 : : // check password
1167 : 0 : Reference< script::XLibraryContainerPassword > xPasswd( xModLibContainer, UNO_QUERY );
1168 : 0 : if ( xPasswd.is() && xPasswd->isLibraryPasswordProtected( aOULibName ) && !xPasswd->isLibraryPasswordVerified( aOULibName ) )
1169 : : {
1170 : 0 : ::rtl::OUString aPassword;
1171 : 0 : Reference< script::XLibraryContainer > xModLibContainer1( xModLibContainer, UNO_QUERY );
1172 : 0 : bOK = QueryPassword( xModLibContainer1, aLibName, aPassword );
1173 : : }
1174 : 0 : if ( !bOK )
1175 : 0 : return;
1176 : : }
1177 : :
1178 : :
1179 : 0 : Window* pWin = static_cast<Window*>( this );
1180 : 0 : std::auto_ptr< ExportDialog > xNewDlg( new ExportDialog( pWin ) );
1181 : :
1182 : 0 : if ( xNewDlg->Execute() == RET_OK )
1183 : : {
1184 : : try
1185 : : {
1186 : 0 : if( xNewDlg->isExportAsPackage() )
1187 : 0 : ExportAsPackage( aLibName );
1188 : : else
1189 : 0 : ExportAsBasic( aLibName );
1190 : : }
1191 : 0 : catch(const util::VetoException& ) // user cancled operation
1192 : : {
1193 : : }
1194 : 0 : }
1195 : : }
1196 : :
1197 : 0 : void LibPage::implExportLib( const String& aLibName, const String& aTargetURL,
1198 : : const Reference< task::XInteractionHandler >& Handler )
1199 : : {
1200 : 0 : ::rtl::OUString aOULibName( aLibName );
1201 : : Reference< script::XLibraryContainerExport > xModLibContainerExport
1202 : 0 : ( m_aCurDocument.getLibraryContainer( E_SCRIPTS ), UNO_QUERY );
1203 : : Reference< script::XLibraryContainerExport > xDlgLibContainerExport
1204 : 0 : ( m_aCurDocument.getLibraryContainer( E_DIALOGS ), UNO_QUERY );
1205 : 0 : if ( xModLibContainerExport.is() )
1206 : 0 : xModLibContainerExport->exportLibrary( aOULibName, aTargetURL, Handler );
1207 : :
1208 : 0 : if ( xDlgLibContainerExport.is() )
1209 : 0 : xDlgLibContainerExport->exportLibrary( aOULibName, aTargetURL, Handler );
1210 : 0 : }
1211 : :
1212 : :
1213 : : //===========================================================================
1214 : : // Implementation XCommandEnvironment
1215 : :
1216 : : typedef cppu::WeakImplHelper1< XCommandEnvironment > LibCommandEnvironmentHelper;
1217 : :
1218 : 0 : class OLibCommandEnvironment : public LibCommandEnvironmentHelper
1219 : : {
1220 : : Reference< task::XInteractionHandler > mxInteraction;
1221 : :
1222 : : public:
1223 : 0 : OLibCommandEnvironment( Reference< task::XInteractionHandler > xInteraction )
1224 : 0 : : mxInteraction( xInteraction )
1225 : 0 : {}
1226 : :
1227 : : // Methods
1228 : : virtual Reference< task::XInteractionHandler > SAL_CALL getInteractionHandler()
1229 : : throw(RuntimeException);
1230 : : virtual Reference< XProgressHandler > SAL_CALL getProgressHandler()
1231 : : throw(RuntimeException);
1232 : : };
1233 : :
1234 : 0 : Reference< task::XInteractionHandler > OLibCommandEnvironment::getInteractionHandler()
1235 : : throw(RuntimeException)
1236 : : {
1237 : 0 : return mxInteraction;
1238 : : }
1239 : :
1240 : 0 : Reference< XProgressHandler > OLibCommandEnvironment::getProgressHandler()
1241 : : throw(RuntimeException)
1242 : : {
1243 : 0 : Reference< XProgressHandler > xRet;
1244 : 0 : return xRet;
1245 : : }
1246 : :
1247 : :
1248 : :
1249 : 0 : void LibPage::ExportAsPackage( const String& aLibName )
1250 : : {
1251 : : // file open dialog
1252 : 0 : Reference< lang::XMultiServiceFactory > xMSF( ::comphelper::getProcessServiceFactory() );
1253 : 0 : Reference< task::XInteractionHandler > xHandler;
1254 : 0 : Reference< XSimpleFileAccess2 > xSFA;
1255 : 0 : Reference < XFilePicker > xFP;
1256 : 0 : if( xMSF.is() )
1257 : : {
1258 : 0 : xHandler = Reference< task::XInteractionHandler >( xMSF->createInstance
1259 : 0 : ( DEFINE_CONST_UNICODE("com.sun.star.task.InteractionHandler") ), UNO_QUERY );
1260 : :
1261 : 0 : xSFA = SimpleFileAccess::create(comphelper::getProcessComponentContext());
1262 : :
1263 : 0 : Sequence <Any> aServiceType(1);
1264 : 0 : aServiceType[0] <<= TemplateDescription::FILESAVE_SIMPLE;
1265 : 0 : xFP = Reference< XFilePicker >( xMSF->createInstanceWithArguments(
1266 : 0 : ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.FilePicker" ) ), aServiceType ), UNO_QUERY );
1267 : : }
1268 : 0 : xFP->setTitle( String( IDEResId( RID_STR_EXPORTPACKAGE ) ) );
1269 : :
1270 : : // filter
1271 : 0 : ::rtl::OUString aTitle = String( IDEResId( RID_STR_PACKAGE_BUNDLE ) );
1272 : 0 : ::rtl::OUString aFilter;
1273 : 0 : aFilter = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "*.oxt" ) ); // library files
1274 : 0 : Reference< XFilterManager > xFltMgr(xFP, UNO_QUERY);
1275 : 0 : xFltMgr->appendFilter( aTitle, aFilter );
1276 : :
1277 : : // set display directory and filter
1278 : 0 : String aPath( BasicIDEGlobals::GetExtraData()->GetAddLibPath() );
1279 : 0 : if ( aPath.Len() )
1280 : : {
1281 : 0 : xFP->setDisplayDirectory( aPath );
1282 : : }
1283 : : else
1284 : : {
1285 : : // macro path from configuration management
1286 : 0 : xFP->setDisplayDirectory( SvtPathOptions().GetWorkPath() );
1287 : : }
1288 : 0 : xFltMgr->setCurrentFilter( aTitle );
1289 : :
1290 : 0 : if ( xFP->execute() == RET_OK )
1291 : : {
1292 : 0 : BasicIDEGlobals::GetExtraData()->SetAddLibPath( xFP->getDisplayDirectory() );
1293 : :
1294 : 0 : Sequence< ::rtl::OUString > aFiles = xFP->getFiles();
1295 : 0 : INetURLObject aURL( aFiles[0] );
1296 : 0 : if( aURL.getExtension().isEmpty() )
1297 : 0 : aURL.setExtension( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "oxt" ) ) );
1298 : :
1299 : 0 : ::rtl::OUString aPackageURL( aURL.GetMainURL( INetURLObject::NO_DECODE ) );
1300 : :
1301 : 0 : String aTmpPath = SvtPathOptions().GetTempPath();
1302 : 0 : INetURLObject aInetObj( aTmpPath );
1303 : 0 : aInetObj.insertName( aLibName, true, INetURLObject::LAST_SEGMENT, true, INetURLObject::ENCODE_ALL );
1304 : 0 : OUString aSourcePath = aInetObj.GetMainURL( INetURLObject::NO_DECODE );
1305 : 0 : if( xSFA->exists( aSourcePath ) )
1306 : 0 : xSFA->kill( aSourcePath );
1307 : 0 : Reference< task::XInteractionHandler > xDummyHandler( new DummyInteractionHandler( xHandler ) );
1308 : 0 : implExportLib( aLibName, aTmpPath, xDummyHandler );
1309 : :
1310 : : Reference< XCommandEnvironment > xCmdEnv =
1311 : 0 : static_cast<XCommandEnvironment*>( new OLibCommandEnvironment( xHandler ) );
1312 : :
1313 : 0 : ::ucbhelper::Content sourceContent( aSourcePath, xCmdEnv );
1314 : :
1315 : 0 : ::rtl::OUStringBuffer buf;
1316 : 0 : buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("vnd.sun.star.zip://") );
1317 : : buf.append( ::rtl::Uri::encode( aPackageURL,
1318 : : rtl_UriCharClassRegName,
1319 : : rtl_UriEncodeIgnoreEscapes,
1320 : 0 : RTL_TEXTENCODING_UTF8 ) );
1321 : 0 : buf.append( static_cast<sal_Unicode>('/') );
1322 : 0 : OUString destFolder( buf.makeStringAndClear() );
1323 : :
1324 : 0 : if( xSFA->exists( aPackageURL ) )
1325 : 0 : xSFA->kill( aPackageURL );
1326 : :
1327 : 0 : ::ucbhelper::Content destFolderContent( destFolder, xCmdEnv );
1328 : : destFolderContent.transferContent(
1329 : : sourceContent, ::ucbhelper::InsertOperation_COPY,
1330 : 0 : OUString(), NameClash::OVERWRITE );
1331 : :
1332 : 0 : INetURLObject aMetaInfInetObj( aTmpPath );
1333 : : aMetaInfInetObj.insertName( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "META-INF" ) ),
1334 : 0 : true, INetURLObject::LAST_SEGMENT, true, INetURLObject::ENCODE_ALL );
1335 : 0 : OUString aMetaInfFolder = aMetaInfInetObj.GetMainURL( INetURLObject::NO_DECODE );
1336 : 0 : if( xSFA->exists( aMetaInfFolder ) )
1337 : 0 : xSFA->kill( aMetaInfFolder );
1338 : 0 : xSFA->createFolder( aMetaInfFolder );
1339 : :
1340 : 0 : ::std::vector< Sequence<beans::PropertyValue> > manifest;
1341 : 0 : const OUString strMediaType = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) );
1342 : 0 : const OUString strFullPath = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FullPath" ) );
1343 : : const OUString strBasicMediaType = ::rtl::OUString
1344 : 0 : ( RTL_CONSTASCII_USTRINGPARAM( "application/vnd.sun.star.basic-library" ) );
1345 : :
1346 : 0 : Sequence<beans::PropertyValue> attribs( 2 );
1347 : 0 : beans::PropertyValue * pattribs = attribs.getArray();
1348 : 0 : pattribs[ 0 ].Name = strFullPath;
1349 : 0 : OUString fullPath = aLibName;
1350 : 0 : fullPath += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/") );
1351 : 0 : pattribs[ 0 ].Value <<= fullPath;
1352 : 0 : pattribs[ 1 ].Name = strMediaType;
1353 : 0 : pattribs[ 1 ].Value <<= strBasicMediaType;
1354 : 0 : manifest.push_back( attribs );
1355 : :
1356 : : // write into pipe:
1357 : 0 : Reference<packages::manifest::XManifestWriter> xManifestWriter( xMSF->createInstance
1358 : 0 : ( DEFINE_CONST_UNICODE("com.sun.star.packages.manifest.ManifestWriter") ), UNO_QUERY );
1359 : 0 : Reference<io::XOutputStream> xPipe( xMSF->createInstance
1360 : 0 : ( DEFINE_CONST_UNICODE("com.sun.star.io.Pipe") ), UNO_QUERY );
1361 : 0 : xManifestWriter->writeManifestSequence(
1362 : : xPipe, Sequence< Sequence<beans::PropertyValue> >(
1363 : 0 : &manifest[ 0 ], manifest.size() ) );
1364 : :
1365 : : aMetaInfInetObj.insertName( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "manifest.xml" ) ),
1366 : 0 : true, INetURLObject::LAST_SEGMENT, true, INetURLObject::ENCODE_ALL );
1367 : :
1368 : : // write buffered pipe data to content:
1369 : 0 : ::ucbhelper::Content manifestContent( aMetaInfInetObj.GetMainURL( INetURLObject::NO_DECODE ), xCmdEnv );
1370 : 0 : manifestContent.writeStream( Reference<io::XInputStream>( xPipe, UNO_QUERY_THROW ), true );
1371 : :
1372 : 0 : ::ucbhelper::Content MetaInfContent( aMetaInfFolder, xCmdEnv );
1373 : : destFolderContent.transferContent(
1374 : : MetaInfContent, ::ucbhelper::InsertOperation_COPY,
1375 : 0 : OUString(), NameClash::OVERWRITE );
1376 : :
1377 : 0 : if( xSFA->exists( aSourcePath ) )
1378 : 0 : xSFA->kill( aSourcePath );
1379 : 0 : if( xSFA->exists( aMetaInfFolder ) )
1380 : 0 : xSFA->kill( aMetaInfFolder );
1381 : 0 : }
1382 : 0 : }
1383 : :
1384 : 0 : void LibPage::ExportAsBasic( const String& aLibName )
1385 : : {
1386 : : // Folder picker
1387 : 0 : Reference< lang::XMultiServiceFactory > xMSF( ::comphelper::getProcessServiceFactory() );
1388 : 0 : Reference< XFolderPicker > xFolderPicker;
1389 : 0 : Reference< task::XInteractionHandler > xHandler;
1390 : 0 : if( xMSF.is() )
1391 : : {
1392 : 0 : xFolderPicker = Reference< XFolderPicker >( xMSF->createInstance(
1393 : 0 : ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.FolderPicker" ) ) ), UNO_QUERY );
1394 : :
1395 : 0 : xHandler = Reference< task::XInteractionHandler >( xMSF->createInstance
1396 : 0 : ( DEFINE_CONST_UNICODE("com.sun.star.task.InteractionHandler") ), UNO_QUERY );
1397 : : }
1398 : :
1399 : 0 : if( xFolderPicker.is() )
1400 : : {
1401 : 0 : xFolderPicker->setTitle( String( IDEResId( RID_STR_EXPORTBASIC ) ) );
1402 : :
1403 : : // set display directory and filter
1404 : 0 : String aPath( BasicIDEGlobals::GetExtraData()->GetAddLibPath() );
1405 : 0 : if( !aPath.Len() )
1406 : 0 : aPath = SvtPathOptions().GetWorkPath();
1407 : :
1408 : : // INetURLObject aURL(m_sSavePath, INET_PROT_FILE);
1409 : 0 : xFolderPicker->setDisplayDirectory( aPath );
1410 : 0 : short nRet = xFolderPicker->execute();
1411 : 0 : if( nRet == RET_OK )
1412 : : {
1413 : 0 : String aTargetURL = xFolderPicker->getDirectory();
1414 : 0 : BasicIDEGlobals::GetExtraData()->SetAddLibPath( aTargetURL );
1415 : :
1416 : 0 : Reference< task::XInteractionHandler > xDummyHandler( new DummyInteractionHandler( xHandler ) );
1417 : 0 : implExportLib( aLibName, aTargetURL, xDummyHandler );
1418 : 0 : }
1419 : 0 : }
1420 : 0 : }
1421 : :
1422 : : //----------------------------------------------------------------------------
1423 : :
1424 : 0 : void LibPage::DeleteCurrent()
1425 : : {
1426 : 0 : SvLBoxEntry* pCurEntry = aLibBox.GetCurEntry();
1427 : 0 : String aLibName( aLibBox.GetEntryText( pCurEntry, 0 ) );
1428 : :
1429 : : // check, if library is link
1430 : 0 : bool bIsLibraryLink = false;
1431 : 0 : ::rtl::OUString aOULibName( aLibName );
1432 : 0 : Reference< script::XLibraryContainer2 > xModLibContainer( m_aCurDocument.getLibraryContainer( E_SCRIPTS ), UNO_QUERY );
1433 : 0 : Reference< script::XLibraryContainer2 > xDlgLibContainer( m_aCurDocument.getLibraryContainer( E_DIALOGS ), UNO_QUERY );
1434 : 0 : if ( ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) && xModLibContainer->isLibraryLink( aOULibName ) ) ||
1435 : 0 : ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aOULibName ) && xDlgLibContainer->isLibraryLink( aOULibName ) ) )
1436 : : {
1437 : 0 : bIsLibraryLink = true;
1438 : : }
1439 : :
1440 : 0 : if ( QueryDelLib( aLibName, bIsLibraryLink, this ) )
1441 : : {
1442 : : // inform BasicIDE
1443 : 0 : SfxUsrAnyItem aDocItem( SID_BASICIDE_ARG_DOCUMENT_MODEL, makeAny( m_aCurDocument.getDocumentOrNull() ) );
1444 : 0 : SfxStringItem aLibNameItem( SID_BASICIDE_ARG_LIBNAME, aLibName );
1445 : 0 : BasicIDEShell* pIDEShell = BasicIDEGlobals::GetShell();
1446 : 0 : SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL;
1447 : 0 : SfxDispatcher* pDispatcher = pViewFrame ? pViewFrame->GetDispatcher() : NULL;
1448 : 0 : if( pDispatcher )
1449 : : {
1450 : : pDispatcher->Execute( SID_BASICIDE_LIBREMOVED,
1451 : 0 : SFX_CALLMODE_SYNCHRON, &aDocItem, &aLibNameItem, 0L );
1452 : : }
1453 : :
1454 : : // remove library from module and dialog library containers
1455 : 0 : if ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) )
1456 : 0 : xModLibContainer->removeLibrary( aOULibName );
1457 : 0 : if ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aOULibName ) )
1458 : 0 : xDlgLibContainer->removeLibrary( aOULibName );
1459 : :
1460 : 0 : ((SvLBox&)aLibBox).GetModel()->Remove( pCurEntry );
1461 : 0 : BasicIDE::MarkDocumentModified( m_aCurDocument );
1462 : 0 : }
1463 : 0 : }
1464 : :
1465 : : //----------------------------------------------------------------------------
1466 : :
1467 : 0 : void LibPage::EndTabDialog( sal_uInt16 nRet )
1468 : : {
1469 : : DBG_ASSERT( pTabDlg, "TabDlg nicht gesetzt!" );
1470 : 0 : if ( pTabDlg )
1471 : 0 : pTabDlg->EndDialog( nRet );
1472 : 0 : }
1473 : :
1474 : : //----------------------------------------------------------------------------
1475 : :
1476 : 0 : void LibPage::FillListBox()
1477 : : {
1478 : 0 : InsertListBoxEntry( ScriptDocument::getApplicationScriptDocument(), LIBRARY_LOCATION_USER );
1479 : 0 : InsertListBoxEntry( ScriptDocument::getApplicationScriptDocument(), LIBRARY_LOCATION_SHARE );
1480 : :
1481 : 0 : ScriptDocuments aDocuments( ScriptDocument::getAllScriptDocuments( ScriptDocument::DocumentsSorted ) );
1482 : 0 : for ( ScriptDocuments::const_iterator doc = aDocuments.begin();
1483 : 0 : doc != aDocuments.end();
1484 : : ++doc
1485 : : )
1486 : : {
1487 : 0 : InsertListBoxEntry( *doc, LIBRARY_LOCATION_DOCUMENT );
1488 : 0 : }
1489 : 0 : }
1490 : :
1491 : : //----------------------------------------------------------------------------
1492 : :
1493 : 0 : void LibPage::InsertListBoxEntry( const ScriptDocument& rDocument, LibraryLocation eLocation )
1494 : : {
1495 : 0 : String aEntryText( rDocument.getTitle( eLocation ) );
1496 : 0 : sal_uInt16 nPos = aBasicsBox.InsertEntry( aEntryText, LISTBOX_APPEND );
1497 : 0 : aBasicsBox.SetEntryData( nPos, new BasicDocumentEntry( rDocument, eLocation ) );
1498 : 0 : }
1499 : :
1500 : : //----------------------------------------------------------------------------
1501 : :
1502 : 0 : void LibPage::SetCurLib()
1503 : : {
1504 : 0 : sal_uInt16 nSelPos = aBasicsBox.GetSelectEntryPos();
1505 : 0 : BasicDocumentEntry* pEntry = (BasicDocumentEntry*)aBasicsBox.GetEntryData( nSelPos );
1506 : 0 : if ( pEntry )
1507 : : {
1508 : 0 : ScriptDocument aDocument( pEntry->GetDocument() );
1509 : : DBG_ASSERT( aDocument.isAlive(), "LibPage::SetCurLib: no document, or document is dead!" );
1510 : 0 : if ( !aDocument.isAlive() )
1511 : 0 : return;
1512 : 0 : LibraryLocation eLocation = pEntry->GetLocation();
1513 : 0 : if ( aDocument != m_aCurDocument || eLocation != m_eCurLocation )
1514 : : {
1515 : 0 : m_aCurDocument = aDocument;
1516 : 0 : m_eCurLocation = eLocation;
1517 : 0 : aLibBox.SetDocument( aDocument );
1518 : 0 : aLibBox.Clear();
1519 : :
1520 : : // get a sorted list of library names
1521 : 0 : Sequence< ::rtl::OUString > aLibNames = aDocument.getLibraryNames();
1522 : 0 : sal_Int32 nLibCount = aLibNames.getLength();
1523 : 0 : const ::rtl::OUString* pLibNames = aLibNames.getConstArray();
1524 : :
1525 : 0 : for ( sal_Int32 i = 0 ; i < nLibCount ; i++ )
1526 : : {
1527 : 0 : String aLibName( pLibNames[ i ] );
1528 : 0 : if ( eLocation == aDocument.getLibraryLocation( aLibName ) )
1529 : 0 : ImpInsertLibEntry( aLibName, i );
1530 : 0 : }
1531 : :
1532 : 0 : SvLBoxEntry* pEntry_ = aLibBox.FindEntry( rtl::OUString("Standard") );
1533 : 0 : if ( !pEntry_ )
1534 : 0 : pEntry_ = aLibBox.GetEntry( 0 );
1535 : 0 : aLibBox.SetCurEntry( pEntry_ );
1536 : 0 : }
1537 : : }
1538 : : }
1539 : :
1540 : : //----------------------------------------------------------------------------
1541 : :
1542 : 0 : SvLBoxEntry* LibPage::ImpInsertLibEntry( const String& rLibName, sal_uLong nPos )
1543 : : {
1544 : : // check, if library is password protected
1545 : 0 : bool bProtected = false;
1546 : 0 : ::rtl::OUString aOULibName( rLibName );
1547 : 0 : Reference< script::XLibraryContainer2 > xModLibContainer( m_aCurDocument.getLibraryContainer( E_SCRIPTS ), UNO_QUERY );
1548 : 0 : if ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) )
1549 : : {
1550 : 0 : Reference< script::XLibraryContainerPassword > xPasswd( xModLibContainer, UNO_QUERY );
1551 : 0 : if ( xPasswd.is() )
1552 : : {
1553 : 0 : bProtected = xPasswd->isLibraryPasswordProtected( aOULibName );
1554 : 0 : }
1555 : : }
1556 : :
1557 : 0 : SvLBoxEntry* pNewEntry = aLibBox.DoInsertEntry( rLibName, nPos );
1558 : 0 : pNewEntry->SetUserData( new BasicLibUserData( m_aCurDocument ) );
1559 : :
1560 : 0 : if (bProtected)
1561 : : {
1562 : 0 : Image aImage(IDEResId(RID_IMG_LOCKED));
1563 : 0 : aLibBox.SetExpandedEntryBmp(pNewEntry, aImage);
1564 : 0 : aLibBox.SetCollapsedEntryBmp(pNewEntry, aImage);
1565 : : }
1566 : :
1567 : : // check, if library is link
1568 : 0 : if ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) && xModLibContainer->isLibraryLink( aOULibName ) )
1569 : : {
1570 : 0 : String aLinkURL = xModLibContainer->getLibraryLinkURL( aOULibName );
1571 : 0 : aLibBox.SetEntryText( aLinkURL, pNewEntry, 1 );
1572 : : }
1573 : :
1574 : 0 : return pNewEntry;
1575 : : }
1576 : :
1577 : : //----------------------------------------------------------------------------
1578 : :
1579 : : // Helper function
1580 : 0 : void createLibImpl( Window* pWin, const ScriptDocument& rDocument,
1581 : : BasicCheckBox* pLibBox, BasicTreeListBox* pBasicBox )
1582 : : {
1583 : : OSL_ENSURE( rDocument.isAlive(), "createLibImpl: invalid document!" );
1584 : 0 : if ( !rDocument.isAlive() )
1585 : 0 : return;
1586 : :
1587 : : // create library name
1588 : 0 : String aLibName;
1589 : 0 : String aLibStdName( String( RTL_CONSTASCII_USTRINGPARAM( "Library" ) ) );
1590 : : //String aLibStdName( IDEResId( RID_STR_STDLIBNAME ) );
1591 : 0 : bool bValid = false;
1592 : 0 : sal_uInt16 i = 1;
1593 : 0 : while ( !bValid )
1594 : : {
1595 : 0 : aLibName = aLibStdName;
1596 : 0 : aLibName += String::CreateFromInt32( i );
1597 : 0 : if ( !rDocument.hasLibrary( E_SCRIPTS, aLibName ) && !rDocument.hasLibrary( E_DIALOGS, aLibName ) )
1598 : 0 : bValid = true;
1599 : 0 : i++;
1600 : : }
1601 : :
1602 : 0 : std::auto_ptr< NewObjectDialog > xNewDlg( new NewObjectDialog( pWin, NEWOBJECTMODE_LIB ) );
1603 : 0 : xNewDlg->SetObjectName( aLibName );
1604 : :
1605 : 0 : if ( xNewDlg->Execute() )
1606 : : {
1607 : 0 : if ( xNewDlg->GetObjectName().Len() )
1608 : 0 : aLibName = xNewDlg->GetObjectName();
1609 : :
1610 : 0 : if ( aLibName.Len() > 30 )
1611 : : {
1612 : 0 : ErrorBox( pWin, WB_OK | WB_DEF_OK, String( IDEResId( RID_STR_LIBNAMETOLONG ) ) ).Execute();
1613 : : }
1614 : 0 : else if ( !BasicIDE::IsValidSbxName( aLibName ) )
1615 : : {
1616 : : ErrorBox( pWin, WB_OK | WB_DEF_OK,
1617 : 0 : String( IDEResId( RID_STR_BADSBXNAME ) ) ).Execute();
1618 : : }
1619 : 0 : else if ( rDocument.hasLibrary( E_SCRIPTS, aLibName ) || rDocument.hasLibrary( E_DIALOGS, aLibName ) )
1620 : : {
1621 : : ErrorBox( pWin, WB_OK | WB_DEF_OK,
1622 : 0 : String( IDEResId( RID_STR_SBXNAMEALLREADYUSED2 ) ) ).Execute();
1623 : : }
1624 : : else
1625 : : {
1626 : : try
1627 : : {
1628 : : // create module and dialog library
1629 : 0 : Reference< container::XNameContainer > xModLib( rDocument.getOrCreateLibrary( E_SCRIPTS, aLibName ) );
1630 : 0 : Reference< container::XNameContainer > xDlgLib( rDocument.getOrCreateLibrary( E_DIALOGS, aLibName ) );
1631 : :
1632 : 0 : if( pLibBox )
1633 : : {
1634 : 0 : SvLBoxEntry* pEntry = pLibBox->DoInsertEntry( aLibName );
1635 : 0 : pEntry->SetUserData( new BasicLibUserData( rDocument ) );
1636 : 0 : pLibBox->SetCurEntry( pEntry );
1637 : : }
1638 : :
1639 : : // create a module
1640 : 0 : String aModName = rDocument.createObjectName( E_SCRIPTS, aLibName );
1641 : 0 : ::rtl::OUString sModuleCode;
1642 : 0 : if ( !rDocument.createModule( aLibName, aModName, true, sModuleCode ) )
1643 : 0 : throw Exception();
1644 : :
1645 : 0 : SbxItem aSbxItem( SID_BASICIDE_ARG_SBX, rDocument, aLibName, aModName, BASICIDE_TYPE_MODULE );
1646 : 0 : BasicIDEShell* pIDEShell = BasicIDEGlobals::GetShell();
1647 : 0 : SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL;
1648 : 0 : SfxDispatcher* pDispatcher = pViewFrame ? pViewFrame->GetDispatcher() : NULL;
1649 : 0 : if( pDispatcher )
1650 : : {
1651 : : pDispatcher->Execute( SID_BASICIDE_SBXINSERTED,
1652 : 0 : SFX_CALLMODE_SYNCHRON, &aSbxItem, 0L );
1653 : : }
1654 : :
1655 : 0 : if( pBasicBox )
1656 : : {
1657 : 0 : SvLBoxEntry* pEntry = pBasicBox->GetCurEntry();
1658 : 0 : SvLBoxEntry* pRootEntry = NULL;
1659 : 0 : while( pEntry )
1660 : : {
1661 : 0 : pRootEntry = pEntry;
1662 : 0 : pEntry = pBasicBox->GetParent( pEntry );
1663 : : }
1664 : :
1665 : 0 : sal_uInt16 nMode = pBasicBox->GetMode();
1666 : 0 : bool bDlgMode = ( nMode & BROWSEMODE_DIALOGS ) && !( nMode & BROWSEMODE_MODULES );
1667 : 0 : sal_uInt16 nId = bDlgMode ? RID_IMG_DLGLIB : RID_IMG_MODLIB;
1668 : : SvLBoxEntry* pNewLibEntry = pBasicBox->AddEntry(
1669 : : aLibName,
1670 : : Image( IDEResId( nId ) ),
1671 : : pRootEntry, false,
1672 : 0 : std::auto_ptr< BasicEntry >( new BasicEntry( OBJ_TYPE_LIBRARY ) ) );
1673 : : DBG_ASSERT( pNewLibEntry, "InsertEntry fehlgeschlagen!" );
1674 : :
1675 : 0 : if( pNewLibEntry )
1676 : : {
1677 : : SvLBoxEntry* pEntry_ = pBasicBox->AddEntry(
1678 : : aModName,
1679 : : Image( IDEResId( RID_IMG_MODULE ) ),
1680 : : pNewLibEntry, false,
1681 : 0 : std::auto_ptr< BasicEntry >( new BasicEntry( OBJ_TYPE_MODULE ) ) );
1682 : : DBG_ASSERT( pEntry_, "InsertEntry fehlgeschlagen!" );
1683 : 0 : pBasicBox->SetCurEntry( pEntry_ );
1684 : 0 : pBasicBox->Select( pBasicBox->GetCurEntry() ); // OV-Bug?!
1685 : : }
1686 : 0 : }
1687 : : }
1688 : 0 : catch (const uno::Exception& )
1689 : : {
1690 : : DBG_UNHANDLED_EXCEPTION();
1691 : : }
1692 : : }
1693 : 0 : }
1694 : : }
1695 : :
1696 : : //----------------------------------------------------------------------------
1697 : :
1698 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|