Bump version to 5.0-14
[LibreOffice.git] / filter / source / xsltdialog / xmlfiltersettingsdialog.cxx
blobb1004ec856f3b811135798a59c93a10e5adcbf79
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <com/sun/star/frame/XConfigManager.hpp>
21 #include <com/sun/star/container/XNameAccess.hpp>
22 #include <com/sun/star/util/XFlushable.hpp>
24 #include <com/sun/star/beans/PropertyValue.hpp>
26 #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
27 #include <tools/urlobj.hxx>
28 #include <svtools/headbar.hxx>
29 #include <unotools/streamwrap.hxx>
30 #include <unotools/pathoptions.hxx>
31 #include <osl/file.hxx>
32 #include <o3tl/enumrange.hxx>
33 #include <vcl/msgbox.hxx>
34 #include <vcl/builderfactory.hxx>
35 #include <sfx2/filedlghelper.hxx>
36 #include "svtools/treelistentry.hxx"
38 #include <rtl/uri.hxx>
40 #include <algorithm>
42 #include "xmlfilterdialogstrings.hrc"
43 #include "xmlfiltersettingsdialog.hxx"
44 #include "xmlfiltertabdialog.hxx"
45 #include "xmlfiltertestdialog.hxx"
46 #include "xmlfilterjar.hxx"
48 using namespace osl;
49 using namespace com::sun::star::lang;
50 using namespace com::sun::star::uno;
51 using namespace com::sun::star::io;
52 using namespace com::sun::star::frame;
53 using namespace com::sun::star::container;
54 using namespace com::sun::star::beans;
55 using namespace com::sun::star::util;
57 using ::rtl::Uri;
59 XMLFilterSettingsDialog::XMLFilterSettingsDialog(vcl::Window* pParent,
60 const css::uno::Reference<css::uno::XComponentContext>& rxContext,
61 Dialog::InitFlag eFlag)
62 : ModelessDialog(pParent, "XMLFilterSettingsDialog", "filter/ui/xmlfiltersettings.ui", eFlag)
63 , mxContext( rxContext )
64 , m_bIsClosable(true)
65 , m_sTemplatePath("$(user)/template/")
66 , m_sDocTypePrefix("doctype:")
68 get(m_pCtrlFilterList, "filterlist");
69 get(m_pPBNew, "new");
70 get(m_pPBEdit, "edit");
71 get(m_pPBTest, "test");
72 get(m_pPBDelete, "delete");
73 get(m_pPBSave, "save");
74 get(m_pPBOpen, "open");
75 get(m_pPBClose, "close");
77 m_pFilterListBox = m_pCtrlFilterList->getListBox();
78 m_pFilterListBox->SetSelectHdl( LINK( this, XMLFilterSettingsDialog, SelectionChangedHdl_Impl ) );
79 m_pFilterListBox->SetDeselectHdl( LINK( this, XMLFilterSettingsDialog, SelectionChangedHdl_Impl ) );
80 m_pFilterListBox->SetDoubleClickHdl( LINK( this, XMLFilterSettingsDialog, DoubleClickHdl_Impl ) );
81 m_pFilterListBox->SetAccessibleName(RESIDSTR(STR_XML_FILTER_LISTBOX));
82 m_pCtrlFilterList->SetAccessibleName(RESIDSTR(STR_XML_FILTER_LISTBOX));
83 m_pFilterListBox->SetHelpId(m_pCtrlFilterList->GetHelpId());
85 m_pPBNew->SetClickHdl(LINK( this, XMLFilterSettingsDialog, ClickHdl_Impl ) );
86 m_pPBEdit->SetClickHdl(LINK( this, XMLFilterSettingsDialog, ClickHdl_Impl ) );
87 m_pPBTest->SetClickHdl(LINK( this, XMLFilterSettingsDialog, ClickHdl_Impl ) );
88 m_pPBDelete->SetClickHdl(LINK( this, XMLFilterSettingsDialog, ClickHdl_Impl ) );
89 m_pPBSave->SetClickHdl(LINK( this, XMLFilterSettingsDialog, ClickHdl_Impl ) );
90 m_pPBOpen->SetClickHdl(LINK( this, XMLFilterSettingsDialog, ClickHdl_Impl ) );
91 m_pPBClose->SetClickHdl(LINK( this, XMLFilterSettingsDialog, ClickHdl_Impl ) );
93 try
95 mxFilterContainer = Reference< XNameContainer >::query( rxContext->getServiceManager()->createInstanceWithContext( "com.sun.star.document.FilterFactory", rxContext ) );
96 mxTypeDetection = Reference< XNameContainer >::query( rxContext->getServiceManager()->createInstanceWithContext( "com.sun.star.document.TypeDetection", rxContext ) );
97 mxExtendedTypeDetection = Reference< XNameContainer >::query( rxContext->getServiceManager()->createInstanceWithContext( "com.sun.star.document.ExtendedTypeDetectionFactory", rxContext ) );
99 SvtPathOptions aOptions;
100 m_sTemplatePath = aOptions.SubstituteVariable( m_sTemplatePath );
102 catch(const Exception&)
104 OSL_FAIL( "XMLFilterSettingsDialog::XMLFilterSettingsDialog exception catched!" );
108 XMLFilterSettingsDialog::~XMLFilterSettingsDialog()
110 disposeOnce();
113 void XMLFilterSettingsDialog::dispose()
115 m_pFilterListBox.clear();
116 m_pCtrlFilterList.clear();
117 m_pPBNew.clear();
118 m_pPBEdit.clear();
119 m_pPBTest.clear();
120 m_pPBDelete.clear();
121 m_pPBSave.clear();
122 m_pPBOpen.clear();
123 m_pPBClose.clear();
124 ModelessDialog::dispose();
127 IMPL_LINK(XMLFilterSettingsDialog, ClickHdl_Impl, PushButton *, pButton )
129 m_bIsClosable = false;
131 if (m_pPBNew == pButton)
133 onNew();
135 else if (m_pPBEdit == pButton)
137 onEdit();
139 else if (m_pPBTest == pButton)
141 onTest();
143 else if (m_pPBDelete == pButton)
145 onDelete();
147 else if (m_pPBSave == pButton)
149 onSave();
151 else if (m_pPBOpen == pButton)
153 onOpen();
155 else if (m_pPBClose == pButton)
157 onClose();
160 m_bIsClosable = true;
161 return 0;
164 IMPL_LINK_NOARG(XMLFilterSettingsDialog, SelectionChangedHdl_Impl)
166 updateStates();
167 return 0;
170 IMPL_LINK_NOARG(XMLFilterSettingsDialog, DoubleClickHdl_Impl)
172 onEdit();
173 return 0;
176 short XMLFilterSettingsDialog::Execute()
178 m_pCtrlFilterList->GrabFocus();
179 disposeFilterList();
180 m_pFilterListBox->Clear();
181 initFilterList();
182 updateStates();
184 return ModelessDialog::Execute();
187 void XMLFilterSettingsDialog::updateStates()
189 SvTreeListEntry* pSelectedEntry = m_pFilterListBox->FirstSelected();
191 bool bHasSelection = pSelectedEntry != NULL;
193 bool bMultiSelection = bHasSelection && (m_pFilterListBox->NextSelected( pSelectedEntry ) != NULL );
194 bool bIsReadonly = false;
195 bool bIsDefault = false;
196 if(pSelectedEntry)
198 filter_info_impl* pInfo = static_cast<filter_info_impl*>(pSelectedEntry->GetUserData());
199 bIsReadonly = pInfo->mbReadonly;
201 for( auto nFact : o3tl::enumrange<SvtModuleOptions::EFactory>())
203 OUString sDefault = maModuleOpt.GetFactoryDefaultFilter(nFact);
204 if( sDefault == pInfo->maFilterName )
206 bIsDefault = true;
207 break;
211 m_pPBEdit->Enable( bHasSelection && !bMultiSelection && !bIsReadonly);
212 m_pPBTest->Enable( bHasSelection && !bMultiSelection );
213 m_pPBDelete->Enable( bHasSelection && !bMultiSelection && !bIsReadonly && !bIsDefault);
214 m_pPBSave->Enable( bHasSelection );
217 /** is called when the user clicks on the "New" button */
218 void XMLFilterSettingsDialog::onNew()
220 filter_info_impl aTempInfo;
222 // create a unique filter name
223 aTempInfo.maFilterName = createUniqueFilterName(RESIDSTR(STR_DEFAULT_FILTER_NAME));
225 // init default extension
226 OUString aDefaultExtension(RESIDSTR(STR_DEFAULT_EXTENSION));
227 aTempInfo.maExtension = aDefaultExtension;
229 // set default ui name
230 aTempInfo.maInterfaceName = createUniqueInterfaceName(RESIDSTR(STR_DEFAULT_UI_NAME));
232 // set default application
233 aTempInfo.maDocumentService = "com.sun.star.text.TextDocument";
235 // execute XML Filter Dialog
236 ScopedVclPtrInstance< XMLFilterTabDialog > aDlg( this, *getXSLTDialogResMgr(), mxContext, &aTempInfo );
237 if ( aDlg->Execute() == RET_OK )
239 // insert the new filter
240 insertOrEdit( aDlg->getNewFilterInfo() );
244 /** is called when the user clicks on the "Edit" Button */
245 void XMLFilterSettingsDialog::onEdit()
247 // get selected filter entry
248 SvTreeListEntry* pEntry = m_pFilterListBox->FirstSelected();
249 if( pEntry )
251 // get its filter info
252 filter_info_impl* pOldInfo = static_cast<filter_info_impl*>(pEntry->GetUserData());
254 // execute XML Filter Dialog
255 ScopedVclPtrInstance< XMLFilterTabDialog > aDlg( this, *getXSLTDialogResMgr(), mxContext, pOldInfo );
256 if ( aDlg->Execute() == RET_OK )
258 filter_info_impl* pNewInfo = aDlg->getNewFilterInfo();
260 if( !(*pOldInfo == *pNewInfo) )
262 // change filter
263 insertOrEdit( pNewInfo, pOldInfo );
269 /** helper to create a sequence of strings from an extensions strings
270 "ext1;ext2;ext3" will become { "ext1", "ext2", "ext3" } */
271 static Sequence< OUString > createExtensionsSequence( const OUString& rExtensions )
273 // first count how many extensions we have inside the string
274 int nExtensions = 0;
276 int nLength = rExtensions.getLength();
277 if( nLength )
279 // a non empty string has at least one extension
280 nExtensions++;
282 // now count the delimiters ';'
283 const sal_Unicode * pString = rExtensions.getStr();
284 int i;
285 for( i = 0; i < nLength; i++, pString++ )
287 if( *pString == ';' )
288 nExtensions++;
292 Sequence< OUString > aExtensions( nExtensions );
294 // extract the extensions from the source string and fill the sequence
296 int nLastIndex = 0;
297 int nCurrentIndex = 0;
298 int i;
300 for( i = 0; i < nExtensions; i++ )
302 nLastIndex = rExtensions.indexOf( ';', nLastIndex );
304 if( nLastIndex == -1 )
306 aExtensions[i] = rExtensions.copy( nCurrentIndex );
307 break;
309 else
311 aExtensions[i] = rExtensions.copy( nCurrentIndex, nLastIndex - nCurrentIndex );
312 nCurrentIndex = nLastIndex + 1;
313 nLastIndex = nCurrentIndex;
317 return aExtensions;
320 /** checks if the given name is unique inside the filter factory. If not,
321 numbers are added until the returned name is unique */
322 OUString XMLFilterSettingsDialog::createUniqueFilterName( const OUString& rFilterName )
324 OUString aFilterName( rFilterName );
325 OUString aSpace(" ");
327 sal_Int32 nId = 2;
329 while( mxFilterContainer->hasByName( aFilterName ) )
331 aFilterName = rFilterName;
332 aFilterName += aSpace;
333 aFilterName += OUString::number( nId++ );
336 return aFilterName;
339 /** checks if the given name is unique inside the type detection. If not,
340 numbers are added until the returned name is unique */
341 OUString XMLFilterSettingsDialog::createUniqueTypeName( const OUString& rTypeName )
343 OUString aTypeName( rTypeName );
344 OUString aSpace(" ");
346 sal_Int32 nId = 2;
348 while( mxFilterContainer->hasByName( aTypeName ) )
350 aTypeName = rTypeName;
351 aTypeName += aSpace;
352 aTypeName += OUString::number( nId++ );
355 return aTypeName;
358 /** checks if the given name is a unique ui name inside the filter factory. If not,
359 numbers are added until the returned name is unique */
360 OUString XMLFilterSettingsDialog::createUniqueInterfaceName( const OUString& rInterfaceName )
362 sal_Int32 nDefaultNumber = 0;
366 Sequence< OUString > aFilterNames( mxFilterContainer->getElementNames() );
367 OUString* pFilterName = aFilterNames.getArray();
369 const sal_Int32 nCount = aFilterNames.getLength();
370 sal_Int32 nFilter;
372 Sequence< PropertyValue > aValues;
373 for( nFilter = 0; (nFilter < nCount); nFilter++, pFilterName++ )
375 Any aAny( mxFilterContainer->getByName( *pFilterName ) );
376 if( !(aAny >>= aValues) )
377 continue;
379 const sal_Int32 nValueCount( aValues.getLength() );
380 PropertyValue* pValues = aValues.getArray();
381 sal_Int32 nValue;
383 for( nValue = 0; nValue < nValueCount; nValue++, pValues++ )
385 if ( pValues->Name == "UIName" )
387 OUString aInterfaceName;
388 pValues->Value >>= aInterfaceName;
391 // see if this filter matches our default filter name
392 if( aInterfaceName.match( rInterfaceName ) )
394 // if yes, make sure we generate a unique name with a higher number
395 // this is dump but fast
396 sal_Int32 nNumber = aInterfaceName.copy( rInterfaceName.getLength() ).toInt32();
397 if( nNumber >= nDefaultNumber )
398 nDefaultNumber = nNumber + 1;
404 catch( const Exception& )
406 OSL_FAIL( "XMLFilterSettingsDialog::createUniqueInterfaceName exception catched!" );
409 OUString aInterfaceName( rInterfaceName );
410 if( nDefaultNumber )
412 aInterfaceName += " " + OUString::number( nDefaultNumber );
415 return aInterfaceName;
418 /** inserts a new filter into the ui and configuration if pOldInfo is NULL.
419 If pOldInfo is not null, the old filter will be replaced with the new settings */
420 bool XMLFilterSettingsDialog::insertOrEdit( filter_info_impl* pNewInfo, const filter_info_impl* pOldInfo )
422 bool bOk = true;
424 if( pOldInfo )
426 // see if we need to update the type name
427 if( pOldInfo->maFilterName != pNewInfo->maFilterName )
429 if( pOldInfo->maType == pOldInfo->maFilterName )
431 (pNewInfo->maType).clear();
435 // see if we need to clean up old stuff first
438 // if filter name changed, we need to remove the old filter first
439 if( pOldInfo->maFilterName != pNewInfo->maFilterName )
440 mxFilterContainer->removeByName( pOldInfo->maFilterName );
442 // if type name changed, we need to remove the old type first
443 if( pOldInfo->maType != pNewInfo->maType )
444 mxTypeDetection->removeByName( pOldInfo->maType );
446 catch( const Exception& )
448 OSL_FAIL( "XMLFilterSettingsDialog::insertOrEdit exception catched!" );
449 bOk = false;
453 filter_info_impl* pFilterEntry( NULL );
455 if( bOk )
457 // create or copy filter info
458 if( pOldInfo )
460 // change existing filter entry in filter list box
461 pFilterEntry = const_cast<filter_info_impl*>(pOldInfo);
462 *pFilterEntry = *pNewInfo;
464 else
466 // add new entry to filter list box
467 pFilterEntry = new filter_info_impl( *pNewInfo );
471 // check if we need to copy the template
472 if( !pFilterEntry->maImportTemplate.isEmpty() )
474 if( !pFilterEntry->maImportTemplate.matchIgnoreAsciiCase( m_sTemplatePath ) )
476 INetURLObject aSourceURL( pFilterEntry->maImportTemplate );
477 if( !aSourceURL.GetName().isEmpty() )
479 OUString aDestURL( m_sTemplatePath );
480 aDestURL += pFilterEntry->maFilterName + "/";
481 if( createDirectory( aDestURL ) )
483 aDestURL += aSourceURL.GetName();
485 SvFileStream aInputStream(pFilterEntry->maImportTemplate, StreamMode::READ );
486 Reference< XInputStream > xIS( new utl::OInputStreamWrapper( aInputStream ) );
487 SvFileStream aOutputStream(aDestURL, StreamMode::WRITE );
488 Reference< XOutputStream > xOS( new utl::OOutputStreamWrapper( aOutputStream ) );
490 if( copyStreams( xIS, xOS ) )
491 pFilterEntry->maImportTemplate = aDestURL;
497 if( bOk )
499 if( pFilterEntry->maType.isEmpty() )
501 pFilterEntry->maType = createUniqueTypeName( pNewInfo->maFilterName );
504 // update import/export flags
505 if( !pFilterEntry->maImportXSLT.isEmpty() )
507 pFilterEntry->maFlags |= 1;
509 else
511 pFilterEntry->maFlags &= ~1;
514 if( !pFilterEntry->maExportXSLT.isEmpty() )
516 pFilterEntry->maFlags |= 2;
518 else
520 pFilterEntry->maFlags &= ~2;
522 pFilterEntry->maFlags |= 0x80040;
524 // 2. create user data for filter entry
525 Sequence< OUString > aUserData( pFilterEntry->getFilterUserData());
527 // 3. create property values for filter entry
528 Sequence< PropertyValue > aFilterData( 8 );
530 aFilterData[0].Name = "Type";
531 aFilterData[0].Value <<= pFilterEntry->maType;
533 aFilterData[1].Name = "UIName";
534 aFilterData[1].Value <<= pFilterEntry->maInterfaceName;
536 aFilterData[2].Name = "DocumentService";
537 aFilterData[2].Value <<= pFilterEntry->maDocumentService;
539 aFilterData[3].Name = "FilterService";
540 aFilterData[3].Value <<= OUString( "com.sun.star.comp.Writer.XmlFilterAdaptor" );
542 aFilterData[4].Name = "Flags";
543 aFilterData[4].Value <<= pFilterEntry->maFlags;
545 aFilterData[5].Name = "UserData";
546 aFilterData[5].Value <<= aUserData;
548 aFilterData[6].Name = "FileFormatVersion";
549 aFilterData[6].Value <<= pFilterEntry->maFileFormatVersion;
551 aFilterData[7].Name = "TemplateName";
552 aFilterData[7].Value <<= pFilterEntry->maImportTemplate;
554 // 4. insert new or replace existing filter
557 Any aAny( makeAny( aFilterData ) );
558 if( mxFilterContainer->hasByName( pFilterEntry->maFilterName ) )
560 mxFilterContainer->replaceByName( pFilterEntry->maFilterName, aAny );
562 else
564 mxFilterContainer->insertByName( pFilterEntry->maFilterName, aAny );
567 catch( const Exception& )
569 OSL_FAIL( "XMLFilterSettingsDialog::insertOrEdit exception catched!" );
570 bOk = false;
574 // 5. prepare type information
575 if( bOk )
577 Sequence< PropertyValue > aValues(4);
579 aValues[0].Name = "UIName";
580 aValues[0].Value <<= pFilterEntry->maInterfaceName;
581 aValues[1].Name = "ClipboardFormat";
582 OUString aDocType;
583 if( !pFilterEntry->maDocType.match( m_sDocTypePrefix ) )
585 aDocType = m_sDocTypePrefix;
586 aDocType += pFilterEntry->maDocType;
588 else
590 aDocType = pFilterEntry->maDocType;
592 if (aDocType == m_sDocTypePrefix)
593 aValues[1].Value <<= OUString();
594 else
595 aValues[1].Value <<= aDocType;
597 aValues[2].Name = "DocumentIconID";
598 aValues[2].Value <<= pFilterEntry->mnDocumentIconID;
600 aValues[3].Name = "Extensions";
601 aValues[3].Value <<= createExtensionsSequence( pFilterEntry->maExtension );
603 // the detect service will only be registered, if a doctype/search token was specified
604 if (aDocType.getLength() > m_sDocTypePrefix.getLength())
606 aValues.realloc(5);
607 aValues[4].Name = "DetectService";
608 aValues[4].Value <<= OUString( "com.sun.star.comp.filters.XMLFilterDetect" );
611 // 6. insert new or replace existing type information
612 if( mxTypeDetection.is() )
616 Any aAny( makeAny( aValues ) );
617 if( mxTypeDetection->hasByName( pFilterEntry->maType ) )
619 mxTypeDetection->replaceByName( pFilterEntry->maType, aAny );
621 else
623 mxTypeDetection->insertByName( pFilterEntry->maType, aAny );
626 catch( const Exception& )
628 OSL_FAIL( "XMLFilterSettingsDialog::insertOrEdit exception catched!" );
629 bOk = false;
633 if( bOk )
637 Reference< XFlushable > xFlushable = Reference< XFlushable >::query( mxTypeDetection );
638 if( xFlushable.is() )
639 xFlushable->flush();
641 catch( const Exception& )
643 OSL_FAIL( "XMLFilterSettingsDialog::insertOrEdit exception catched!" );
644 bOk = false;
648 if( !bOk )
650 // we failed to add the type, so lets remove the filter
653 mxFilterContainer->removeByName( pFilterEntry->maFilterName );
655 catch( const Exception& )
657 OSL_FAIL( "XMLFilterSettingsDialog::insertOrEdit exception catched!" );
658 bOk = false;
661 else
663 if( bOk )
667 Reference< XFlushable > xFlushable( mxFilterContainer, UNO_QUERY );
668 if( xFlushable.is() )
669 xFlushable->flush();
671 catch( const Exception& )
673 OSL_FAIL( "XMLFilterSettingsDialog::insertOrEdit exception catched!" );
674 bOk = false;
677 if( !bOk )
679 // we failed to add the filter, so lets remove the type
682 mxTypeDetection->removeByName( pFilterEntry->maType );
684 catch( const Exception& )
686 OSL_FAIL( "XMLFilterSettingsDialog::insertOrEdit exception catched!" );
694 if( bOk )
696 if( mxExtendedTypeDetection.is() )
698 OUString sFilterDetectService( "com.sun.star.comp.filters.XMLFilterDetect" );
699 if( mxExtendedTypeDetection->hasByName( sFilterDetectService ) )
701 Sequence< PropertyValue > aSequence;
702 if( mxExtendedTypeDetection->getByName( sFilterDetectService ) >>= aSequence )
704 sal_Int32 nCount = aSequence.getLength();
705 sal_Int32 nIndex;
706 for( nIndex = 0; nIndex < nCount; nIndex++ )
708 if ( aSequence[nIndex].Name == "Types" )
710 Sequence< OUString > aTypes;
711 if( aSequence[nIndex].Value >>= aTypes )
713 sal_Int32 nStrCount = aTypes.getLength();
714 sal_Int32 nStr;
715 for( nStr = 0; nStr < nStrCount; nStr++ )
717 if( aTypes[nStr] == pFilterEntry->maType )
718 break;
721 if( nStr == nStrCount )
723 aTypes.realloc( nStrCount + 1 );
724 aTypes[nStrCount] = pFilterEntry->maType;
726 aSequence[nIndex].Value <<= aTypes;
728 mxExtendedTypeDetection->replaceByName( sFilterDetectService, makeAny( aSequence ) );
730 Reference< XFlushable > xFlushable( mxExtendedTypeDetection, UNO_QUERY );
731 if( xFlushable.is() )
732 xFlushable->flush();
736 break;
744 // update ui
745 if( bOk )
747 if( pOldInfo )
749 m_pFilterListBox->changeEntry( pFilterEntry );
751 else
753 m_pFilterListBox->addFilterEntry( pFilterEntry );
754 maFilterVector.push_back( pFilterEntry );
758 return bOk;
761 /** is called when the user clicks the "Test" button */
762 void XMLFilterSettingsDialog::onTest()
764 // get the first selected filter
765 SvTreeListEntry* pEntry = m_pFilterListBox->FirstSelected();
766 if( pEntry )
768 filter_info_impl* pInfo = static_cast<filter_info_impl*>(pEntry->GetUserData());
770 ScopedVclPtrInstance< XMLFilterTestDialog > aDlg(this, mxContext);
771 aDlg->test( *pInfo );
775 void XMLFilterSettingsDialog::onDelete()
777 SvTreeListEntry* pEntry = m_pFilterListBox->FirstSelected();
778 if( pEntry )
780 filter_info_impl* pInfo = static_cast<filter_info_impl*>(pEntry->GetUserData());
782 OUString aPlaceHolder( "%s" );
783 OUString aMessage(RESIDSTR(STR_WARN_DELETE));
784 aMessage = aMessage.replaceFirst( aPlaceHolder, pInfo->maFilterName );
786 ScopedVclPtrInstance< WarningBox > aWarnBox(this, (WinBits)(WB_YES_NO | WB_DEF_YES), aMessage );
787 if( aWarnBox->Execute() == RET_YES )
791 if( mxFilterContainer->hasByName( pInfo->maFilterName ) )
793 mxFilterContainer->removeByName( pInfo->maFilterName );
795 bool bTypeStillUsed = false;
797 // now loop over all filter and see if someone else uses the same type
798 Sequence< OUString > aFilterNames( mxFilterContainer->getElementNames() );
799 OUString* pFilterName = aFilterNames.getArray();
801 const sal_Int32 nCount = aFilterNames.getLength();
802 sal_Int32 nFilter;
803 Sequence< PropertyValue > aValues;
805 for( nFilter = 0; (nFilter < nCount) && !bTypeStillUsed; nFilter++, pFilterName++ )
807 Any aAny( mxFilterContainer->getByName( *pFilterName ) );
808 if( !(aAny >>= aValues) )
809 continue;
811 const sal_Int32 nValueCount( aValues.getLength() );
812 PropertyValue* pValues = aValues.getArray();
813 sal_Int32 nValue;
815 for( nValue = 0; (nValue < nValueCount) && !bTypeStillUsed; nValue++, pValues++ )
817 if ( pValues->Name == "Type" )
819 OUString aType;
820 pValues->Value >>= aType;
821 if( aType == pInfo->maType )
822 bTypeStillUsed = true;
824 break;
829 // if the type is not used anymore, remove it also
830 if( !bTypeStillUsed )
832 if( mxTypeDetection->hasByName( pInfo->maType ) )
834 mxTypeDetection->removeByName( pInfo->maType );
838 Reference< XFlushable > xFlushable( mxFilterContainer, UNO_QUERY );
839 if( xFlushable.is() )
840 xFlushable->flush();
842 xFlushable = Reference< XFlushable >::query( mxTypeDetection );
843 if( xFlushable.is() )
844 xFlushable->flush();
846 // now remove entry from ui
847 m_pFilterListBox->RemoveSelection();
849 // and delete the filter entry
850 maFilterVector.erase(std::find( maFilterVector.begin(), maFilterVector.end(), pInfo ));
852 delete pInfo;
855 catch( const Exception& )
857 OSL_FAIL( "XMLFilterSettingsDialog::onDelete exception catched!" );
862 updateStates();
865 void XMLFilterSettingsDialog::onSave()
867 XMLFilterVector aFilters;
869 int nFilters = 0;
871 SvTreeListEntry* pEntry = m_pFilterListBox->FirstSelected();
872 while( pEntry )
874 filter_info_impl* pInfo = static_cast<filter_info_impl*>(pEntry->GetUserData());
875 aFilters.push_back( pInfo );
876 pEntry = m_pFilterListBox->NextSelected( pEntry );
877 nFilters++;
880 // Open Fileopen-Dialog
881 ::sfx2::FileDialogHelper aDlg(
882 com::sun::star::ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION,
883 0 );
885 OUString aExtensions( "*.jar" );
886 OUString aFilterName(RESIDSTR(STR_FILTER_PACKAGE));
887 aFilterName += " (" + aExtensions + ")";
889 aDlg.AddFilter( aFilterName, aExtensions );
891 if ( aDlg.Execute() == ERRCODE_NONE )
893 XMLFilterJarHelper aJarHelper( mxContext );
894 aJarHelper.savePackage( aDlg.GetPath(), aFilters );
896 INetURLObject aURL( aDlg.GetPath() );
898 OUString sPlaceholder( "%s" );
900 OUString aMsg;
901 if( nFilters > 0 )
903 aMsg = RESIDSTR(STR_FILTERS_HAVE_BEEN_SAVED);
904 aMsg = aMsg.replaceFirst( sPlaceholder, OUString::number( nFilters ) );
905 aMsg = aMsg.replaceFirst( sPlaceholder, aURL.GetName() );
907 else
909 aMsg = RESIDSTR(STR_FILTER_HAS_BEEN_SAVED);
910 aMsg = aMsg.replaceFirst( sPlaceholder, (*aFilters.begin())->maFilterName );
911 aMsg = aMsg.replaceFirst( sPlaceholder, aURL.GetName() );
914 ScopedVclPtrInstance< InfoBox > aBox(this, aMsg );
915 aBox->Execute();
919 void XMLFilterSettingsDialog::onOpen()
921 XMLFilterVector aFilters;
923 // Open Fileopen-Dialog
924 ::sfx2::FileDialogHelper aDlg(
925 com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, 0 );
927 OUString aExtensions( "*.jar" );
928 OUString aFilterName(RESIDSTR(STR_FILTER_PACKAGE));
929 aFilterName += " (" + aExtensions + ")";
931 aDlg.AddFilter( aFilterName, aExtensions );
933 if ( aDlg.Execute() == ERRCODE_NONE )
935 OUString aURL( aDlg.GetPath() );
937 XMLFilterJarHelper aJarHelper( mxContext );
938 aJarHelper.openPackage( aURL, aFilters );
940 int nFilters = 0;
941 XMLFilterVector::iterator aIter( aFilters.begin() );
942 while( aIter != aFilters.end() )
944 filter_info_impl* pInfo = (*aIter++);
946 if( insertOrEdit( pInfo ) )
948 aFilterName = pInfo->maFilterName;
949 nFilters++;
952 delete pInfo;
955 disposeFilterList();
956 initFilterList();
958 OUString sPlaceholder( "%s" );
959 OUString aMsg;
960 if( nFilters == 0 )
962 INetURLObject aURLObj( aURL );
963 aMsg = RESIDSTR(STR_NO_FILTERS_FOUND);
964 aMsg = aMsg.replaceFirst( sPlaceholder, aURLObj.GetName() );
966 else if( nFilters == 1 )
968 aMsg = RESIDSTR(STR_FILTER_INSTALLED);
969 aMsg = aMsg.replaceFirst( sPlaceholder, aFilterName );
972 else
974 aMsg = RESIDSTR(STR_FILTERS_INSTALLED);
975 aMsg = aMsg.replaceFirst( sPlaceholder, OUString::number( nFilters ) );
978 ScopedVclPtrInstance< InfoBox > aBox(this, aMsg );
979 aBox->Execute();
983 void XMLFilterSettingsDialog::onClose()
985 Close();
988 bool XMLFilterSettingsDialog::Notify( NotifyEvent& rNEvt )
990 // Because of tab control first call the base class.
991 bool nRet = ModelessDialog::Notify( rNEvt );
992 if ( !nRet )
994 if ( rNEvt.GetType() == MouseNotifyEvent::KEYINPUT )
996 const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
997 vcl::KeyCode aKeyCode = pKEvt->GetKeyCode();
998 sal_uInt16 nKeyCode = aKeyCode.GetCode();
999 bool bMod1 = pKEvt->GetKeyCode().IsMod1();
1001 if( nKeyCode == KEY_ESCAPE || (bMod1 && (nKeyCode == KEY_W)))
1003 Close();
1004 return true;
1009 return nRet;
1012 void XMLFilterSettingsDialog::disposeFilterList()
1014 std::vector< filter_info_impl* >::iterator aIter( maFilterVector.begin() );
1015 while( aIter != maFilterVector.end() )
1017 delete (*aIter++);
1019 maFilterVector.clear();
1021 m_pFilterListBox->Clear();
1024 void XMLFilterSettingsDialog::initFilterList()
1026 if( mxFilterContainer.is() )
1028 Sequence< OUString > aFilterNames( mxFilterContainer->getElementNames() );
1029 OUString* pFilterName = aFilterNames.getArray();
1031 const sal_Int32 nCount = aFilterNames.getLength();
1032 sal_Int32 nFilter;
1034 Sequence< PropertyValue > aValues;
1036 filter_info_impl* pTempFilter = new filter_info_impl;
1037 Sequence< OUString > aUserData;
1039 for( nFilter = 0; nFilter < nCount; nFilter++, pFilterName++ )
1041 aUserData.realloc(0);
1045 Any aAny( mxFilterContainer->getByName( *pFilterName ) );
1046 if( !(aAny >>= aValues) )
1047 continue;
1049 OUString aFilterService;
1050 pTempFilter->maFilterName = *pFilterName;
1052 const sal_Int32 nValueCount( aValues.getLength() );
1053 PropertyValue* pValues = aValues.getArray();
1054 sal_Int32 nValue;
1056 for( nValue = 0; nValue < nValueCount; nValue++, pValues++ )
1058 if ( pValues->Name == "Type" )
1060 pValues->Value >>= pTempFilter->maType;
1062 else if ( pValues->Name == "UIName" )
1064 pValues->Value >>= pTempFilter->maInterfaceName;
1066 else if ( pValues->Name == "DocumentService" )
1068 pValues->Value >>= pTempFilter->maDocumentService;
1070 else if ( pValues->Name == "FilterService" )
1072 pValues->Value >>= aFilterService;
1074 else if ( pValues->Name == "Flags" )
1076 pValues->Value >>= pTempFilter->maFlags;
1078 else if ( pValues->Name == "UserData" )
1080 pValues->Value >>= aUserData;
1082 else if ( pValues->Name == "FileFormatVersion" )
1084 pValues->Value >>= pTempFilter->maFileFormatVersion;
1086 else if ( pValues->Name == "TemplateName" )
1088 pValues->Value >>= pTempFilter->maImportTemplate;
1090 else if ( pValues->Name == "Finalized" )
1092 pValues->Value >>= pTempFilter->mbReadonly;
1096 // if this is not a XmlFilterAdaptor entry, skip it
1097 if( aFilterService != "com.sun.star.comp.Writer.XmlFilterAdaptor" )
1098 continue;
1101 // if we don't have the needed user data, skip it
1102 if( aUserData.getLength() < 6 )
1103 continue;
1105 // if this is not an XSLTFilter entry, skip it
1106 if( aUserData[0] != "com.sun.star.documentconversion.XSLTFilter" )
1107 continue;
1109 // get filter information from userdata
1110 pTempFilter->mbNeedsXSLT2 = aUserData[1].toBoolean();
1111 pTempFilter->maImportService = aUserData[2];
1112 pTempFilter->maExportService = aUserData[3];
1113 pTempFilter->maImportXSLT = aUserData[4];
1114 pTempFilter->maExportXSLT = aUserData[5];
1115 if( aUserData.getLength() >= 8 )
1116 pTempFilter->maComment = aUserData[7];
1118 // get type information
1119 if( mxTypeDetection.is() )
1123 aAny = mxTypeDetection->getByName( pTempFilter->maType );
1124 Sequence< PropertyValue > aValues2;
1126 if( aAny >>= aValues2 )
1128 const sal_Int32 nValueCount2( aValues2.getLength() );
1129 PropertyValue* pValues2 = aValues2.getArray();
1130 sal_Int32 nValue2;
1132 for( nValue2 = 0; nValue2 < nValueCount2; nValue2++, pValues2++ )
1134 if ( pValues2->Name == "ClipboardFormat" )
1136 OUString aDocType;
1137 pValues2->Value >>= aDocType;
1139 if( aDocType.match( m_sDocTypePrefix ) )
1140 aDocType = aDocType.copy( m_sDocTypePrefix.getLength() );
1142 pTempFilter->maDocType = aDocType;
1144 else if ( pValues2->Name == "Extensions" )
1146 Sequence< OUString > aExtensions;
1147 if( pValues2->Value >>= aExtensions )
1149 (pTempFilter->maExtension).clear();
1151 sal_Int32 nCount3( aExtensions.getLength() );
1152 OUString* pExtensions = aExtensions.getArray();
1153 sal_Int32 n;
1154 for( n = 0; n < nCount3; n++ )
1156 if( n > 0 )
1157 pTempFilter->maExtension += ";";
1158 pTempFilter->maExtension += (*pExtensions++);
1162 else if ( pValues2->Name == "DocumentIconID" )
1164 pValues2->Value >>= pTempFilter->mnDocumentIconID;
1166 else if ( pValues2->Name == "Finalized" )
1168 // both the filter and the type may be finalized
1169 bool bTemp = false;
1170 pValues2->Value >>= bTemp;
1171 pTempFilter->mbReadonly |= bTemp;
1176 catch( const ::com::sun::star::container::NoSuchElementException& )
1178 OSL_FAIL( "Type not found, user error?" ); // TODO: error?
1182 // add entry to internal container and to ui filter list box
1183 maFilterVector.push_back( pTempFilter );
1184 m_pFilterListBox->addFilterEntry( pTempFilter );
1187 pTempFilter = new filter_info_impl;
1189 catch( const Exception& )
1191 OSL_FAIL( "XMLFilterSettingsDialog::initFilterList exception catched!" );
1196 delete pTempFilter;
1199 SvTreeListEntry* pEntry = m_pFilterListBox->GetEntry( 0 );
1200 if( pEntry )
1201 m_pFilterListBox->Select( pEntry );
1204 application_info_impl::application_info_impl( const sal_Char * pDocumentService, ResId& rUINameRes, const sal_Char * mpXMLImporter, const sal_Char * mpXMLExporter )
1205 : maDocumentService( pDocumentService, strlen( pDocumentService ), RTL_TEXTENCODING_ASCII_US ),
1206 maDocumentUIName( OUString( rUINameRes ) ),
1207 maXMLImporter( mpXMLImporter, strlen( mpXMLImporter ), RTL_TEXTENCODING_ASCII_US ),
1208 maXMLExporter( mpXMLExporter, strlen( mpXMLExporter ), RTL_TEXTENCODING_ASCII_US )
1212 std::vector< application_info_impl* >& getApplicationInfos()
1214 static std::vector< application_info_impl* > aInfos;
1216 if( aInfos.empty() )
1218 ResId aResId1( STR_APPL_NAME_WRITER, *getXSLTDialogResMgr() );
1219 aInfos.push_back( new application_info_impl(
1220 "com.sun.star.text.TextDocument",
1221 aResId1,
1222 "com.sun.star.comp.Writer.XMLImporter",
1223 "com.sun.star.comp.Writer.XMLExporter" ) );
1225 ResId aResId2( STR_APPL_NAME_CALC, *getXSLTDialogResMgr() );
1226 aInfos.push_back( new application_info_impl(
1227 "com.sun.star.sheet.SpreadsheetDocument",
1228 aResId2,
1229 "com.sun.star.comp.Calc.XMLImporter",
1230 "com.sun.star.comp.Calc.XMLExporter" ) );
1232 ResId aResId3( STR_APPL_NAME_IMPRESS, *getXSLTDialogResMgr() );
1233 aInfos.push_back( new application_info_impl(
1234 "com.sun.star.presentation.PresentationDocument",
1235 aResId3,
1236 "com.sun.star.comp.Impress.XMLImporter",
1237 "com.sun.star.comp.Impress.XMLExporter" ) );
1239 ResId aResId4( STR_APPL_NAME_DRAW, *getXSLTDialogResMgr() );
1240 aInfos.push_back( new application_info_impl(
1241 "com.sun.star.drawing.DrawingDocument",
1242 aResId4,
1243 "com.sun.star.comp.Draw.XMLImporter",
1244 "com.sun.star.comp.Draw.XMLExporter" ) );
1246 // --- oasis file formats...
1247 ResId aResId5( STR_APPL_NAME_OASIS_WRITER, *getXSLTDialogResMgr() );
1248 aInfos.push_back( new application_info_impl(
1249 "com.sun.star.text.TextDocument",
1250 aResId5,
1251 "com.sun.star.comp.Writer.XMLOasisImporter",
1252 "com.sun.star.comp.Writer.XMLOasisExporter" ) );
1254 ResId aResId6( STR_APPL_NAME_OASIS_CALC, *getXSLTDialogResMgr() );
1255 aInfos.push_back( new application_info_impl(
1256 "com.sun.star.sheet.SpreadsheetDocument",
1257 aResId6,
1258 "com.sun.star.comp.Calc.XMLOasisImporter",
1259 "com.sun.star.comp.Calc.XMLOasisExporter" ) );
1261 ResId aResId7( STR_APPL_NAME_OASIS_IMPRESS, *getXSLTDialogResMgr() );
1262 aInfos.push_back( new application_info_impl(
1263 "com.sun.star.presentation.PresentationDocument",
1264 aResId7,
1265 "com.sun.star.comp.Impress.XMLOasisImporter",
1266 "com.sun.star.comp.Impress.XMLOasisExporter" ) );
1268 ResId aResId8( STR_APPL_NAME_OASIS_DRAW, *getXSLTDialogResMgr() );
1269 aInfos.push_back( new application_info_impl(
1270 "com.sun.star.drawing.DrawingDocument",
1271 aResId8,
1272 "com.sun.star.comp.Draw.XMLOasisImporter",
1273 "com.sun.star.comp.Draw.XMLOasisExporter" ) );
1276 return aInfos;
1279 const application_info_impl* getApplicationInfo( const OUString& rServiceName )
1281 std::vector< application_info_impl* >& rInfos = getApplicationInfos();
1282 for (std::vector< application_info_impl* >::const_iterator aIter( rInfos.begin() ), aEnd( rInfos.end() );
1283 aIter != aEnd ; ++aIter)
1285 if( rServiceName == (*aIter)->maXMLExporter ||
1286 rServiceName == (*aIter)->maXMLImporter)
1288 return (*aIter);
1291 return NULL;
1294 OUString getApplicationUIName( const OUString& rServiceName )
1296 const application_info_impl* pInfo = getApplicationInfo( rServiceName );
1297 if( pInfo )
1299 return pInfo->maDocumentUIName;
1301 else
1303 OUString aRet = RESIDSTR(STR_UNKNOWN_APPLICATION);
1304 if( !rServiceName.isEmpty() )
1306 aRet += " (" + rServiceName + ")";
1308 return aRet;
1312 SvxPathControl::SvxPathControl(vcl::Window* pParent)
1313 : Window(pParent, WB_HIDE | WB_CLIPCHILDREN | WB_TABSTOP | WB_DIALOGCONTROL | WB_BORDER)
1314 , bHasBeenShown(false)
1316 m_pVBox = VclPtr<VclVBox>::Create(this);
1318 m_pHeaderBar = VclPtr<HeaderBar>::Create(m_pVBox, WB_BOTTOMBORDER);
1319 m_pHeaderBar->set_height_request(GetTextHeight() + 6);
1321 m_pFocusCtrl = VclPtr<XMLFilterListBox>::Create(m_pVBox, this);
1322 m_pFocusCtrl->set_fill(true);
1323 m_pFocusCtrl->set_expand(true);
1325 m_pVBox->set_hexpand(true);
1326 m_pVBox->set_vexpand(true);
1327 m_pVBox->set_expand(true);
1328 m_pVBox->set_fill(true);
1329 m_pVBox->Show();
1332 #define ITEMID_NAME 1
1333 #define ITEMID_TYPE 2
1335 void SvxPathControl::Resize()
1337 Window::Resize();
1339 if (!m_pVBox)
1340 return;
1342 m_pVBox->SetSizePixel(GetSizePixel());
1344 if (!bHasBeenShown)
1345 bHasBeenShown = IsReallyShown();
1347 if (!bHasBeenShown)
1349 std::vector<long> aWidths;
1350 m_pFocusCtrl->getPreferredDimensions(aWidths);
1351 if (aWidths.empty())
1353 bHasBeenShown = false;
1354 return;
1356 long nFirstColumnWidth = aWidths[1];
1357 m_pHeaderBar->SetItemSize(ITEMID_NAME, nFirstColumnWidth);
1358 m_pHeaderBar->SetItemSize(ITEMID_TYPE, 0xFFFF);
1359 long nTabs[] = {2, 0, nFirstColumnWidth};
1360 m_pFocusCtrl->SetTabs(&nTabs[0], MAP_PIXEL);
1364 Size SvxPathControl::GetOptimalSize() const
1366 Size aDefSize(LogicToPixel(Size(150, 0), MapMode(MAP_APPFONT)));
1367 Size aOptSize(m_pVBox->GetOptimalSize());
1368 long nRowHeight(GetTextHeight());
1369 aOptSize.Height() = nRowHeight * 10;
1370 aOptSize.Width() = std::max(aDefSize.Width(), aOptSize.Width());
1371 return aOptSize;
1374 SvxPathControl::~SvxPathControl()
1376 disposeOnce();
1379 void SvxPathControl::dispose()
1381 m_pFocusCtrl.disposeAndClear();
1382 m_pHeaderBar.disposeAndClear();
1383 m_pVBox.disposeAndClear();
1384 vcl::Window::dispose();
1387 VCL_BUILDER_FACTORY(SvxPathControl)
1389 bool SvxPathControl::Notify(NotifyEvent& rNEvt)
1391 bool nRet = Window::Notify(rNEvt);
1393 if ( m_pFocusCtrl && rNEvt.GetWindow() != m_pFocusCtrl && rNEvt.GetType() == MouseNotifyEvent::GETFOCUS )
1394 m_pFocusCtrl->GrabFocus();
1396 return nRet;
1399 XMLFilterListBox::XMLFilterListBox(Window* pParent, SvxPathControl* pPathControl)
1400 : SvTabListBox(pParent, WB_SORT | WB_HSCROLL | WB_CLIPCHILDREN | WB_TABSTOP)
1401 , m_pHeaderBar(pPathControl->getHeaderBar())
1403 Size aBoxSize( pParent->GetOutputSizePixel() );
1405 m_pHeaderBar->SetEndDragHdl( LINK( this, XMLFilterListBox, HeaderEndDrag_Impl ) );
1407 OUString aStr1(RESIDSTR(STR_COLUMN_HEADER_NAME));
1408 OUString aStr2(RESIDSTR(STR_COLUMN_HEADER_TYPE));
1410 long nTabSize = aBoxSize.Width() / 2;
1412 m_pHeaderBar->InsertItem( ITEMID_NAME, aStr1, nTabSize,
1413 HeaderBarItemBits::LEFT | HeaderBarItemBits::VCENTER );
1414 m_pHeaderBar->InsertItem( ITEMID_TYPE, aStr2, nTabSize,
1415 HeaderBarItemBits::LEFT | HeaderBarItemBits::VCENTER );
1417 static long nTabs[] = {2, 0, nTabSize };
1419 SetSelectionMode( MULTIPLE_SELECTION );
1420 SetTabs( &nTabs[0], MAP_PIXEL );
1421 SetScrolledHdl( LINK( this, XMLFilterListBox, TabBoxScrollHdl_Impl ) );
1422 SetHighlightRange();
1423 Show();
1424 m_pHeaderBar->Show();
1427 XMLFilterListBox::~XMLFilterListBox()
1429 disposeOnce();
1432 void XMLFilterListBox::dispose()
1434 m_pHeaderBar.clear();
1435 SvTabListBox::dispose();
1438 void XMLFilterListBox::Paint(vcl::RenderContext& rRenderContext, const Rectangle& rRect)
1440 SvTabListBox::Paint(rRenderContext, rRect);
1443 IMPL_LINK( XMLFilterListBox, TabBoxScrollHdl_Impl, SvTabListBox*, /* pList */ )
1445 m_pHeaderBar->SetOffset( -GetXOffset() );
1446 return 0;
1449 IMPL_LINK( XMLFilterListBox, HeaderEndDrag_Impl, HeaderBar*, pBar )
1451 if ( pBar && !pBar->GetCurItemId() )
1452 return 0;
1454 if ( !m_pHeaderBar->IsItemMode() )
1456 Size aSz;
1457 sal_uInt16 nTabs = m_pHeaderBar->GetItemCount();
1458 long nTmpSz = 0;
1459 long nWidth = m_pHeaderBar->GetItemSize(ITEMID_NAME);
1460 long nBarWidth = m_pHeaderBar->GetSizePixel().Width();
1462 if(nWidth < 30)
1463 m_pHeaderBar->SetItemSize( ITEMID_TYPE, 30);
1464 else if ( ( nBarWidth - nWidth ) < 30 )
1465 m_pHeaderBar->SetItemSize( ITEMID_TYPE, nBarWidth - 30 );
1467 for ( sal_uInt16 i = 1; i <= nTabs; ++i )
1469 long nW = m_pHeaderBar->GetItemSize(i);
1470 aSz.Width() = nW + nTmpSz;
1471 nTmpSz += nW;
1472 SetTab( i, PixelToLogic( aSz, MapMode(MAP_APPFONT) ).Width(), MAP_APPFONT );
1475 return 1;
1478 /** adds a new filter info entry to the ui filter list */
1479 void XMLFilterListBox::addFilterEntry( const filter_info_impl* pInfo )
1481 const OUString aEntryStr( getEntryString( pInfo ) );
1482 InsertEntryToColumn( aEntryStr, TREELIST_APPEND, 0xffff, (void*)pInfo );
1485 void XMLFilterListBox::changeEntry( const filter_info_impl* pInfo )
1487 const sal_uLong nCount = GetEntryCount();
1488 sal_uLong nPos;
1489 for( nPos = 0; nPos < nCount; nPos++ )
1491 SvTreeListEntry* pEntry = GetEntry( nPos );
1492 if( static_cast<filter_info_impl*>(pEntry->GetUserData()) == pInfo )
1494 OUString aEntryText( getEntryString( pInfo ) );
1495 SetEntryText( aEntryText, pEntry );
1496 break;
1501 OUString XMLFilterListBox::getEntryString( const filter_info_impl* pInfo )
1503 OUString aEntryStr( pInfo->maFilterName + "\t");
1504 if ( !pInfo->maExportService.isEmpty() )
1505 aEntryStr += getApplicationUIName( pInfo->maExportService );
1506 else
1507 aEntryStr += getApplicationUIName( pInfo->maImportService );
1508 aEntryStr += " - ";
1510 if( pInfo->maFlags & 1 )
1512 if( pInfo->maFlags & 2 )
1514 aEntryStr += RESIDSTR(STR_IMPORT_EXPORT);
1516 else
1518 aEntryStr += RESIDSTR(STR_IMPORT_ONLY);
1521 else if( pInfo->maFlags & 2 )
1523 aEntryStr += RESIDSTR(STR_EXPORT_ONLY);
1525 else
1527 aEntryStr += RESIDSTR(STR_UNDEFINED_FILTER);
1530 return aEntryStr;
1533 filter_info_impl::filter_info_impl()
1534 : maFlags(0x00080040)
1535 , maFileFormatVersion(0)
1536 , mnDocumentIconID(0)
1537 , mbReadonly(false)
1538 , mbNeedsXSLT2(false)
1542 filter_info_impl::filter_info_impl( const filter_info_impl& rInfo ) :
1543 maFilterName( rInfo.maFilterName ),
1544 maType( rInfo.maType ),
1545 maDocumentService( rInfo.maDocumentService ),
1546 maFilterService( rInfo.maFilterService ),
1547 maInterfaceName( rInfo.maInterfaceName ),
1548 maComment( rInfo.maComment ),
1549 maExtension( rInfo.maExtension ),
1550 maExportXSLT( rInfo.maExportXSLT ),
1551 maImportXSLT( rInfo.maImportXSLT ),
1552 maImportTemplate( rInfo.maImportTemplate ),
1553 maDocType( rInfo.maDocType ),
1554 maImportService( rInfo.maImportService ),
1555 maExportService( rInfo.maExportService ),
1556 maFlags( rInfo.maFlags ),
1557 maFileFormatVersion( rInfo.maFileFormatVersion ),
1558 mnDocumentIconID( rInfo.mnDocumentIconID ),
1559 mbReadonly( rInfo.mbReadonly ),
1560 mbNeedsXSLT2( rInfo.mbNeedsXSLT2 )
1564 bool filter_info_impl::operator==( const filter_info_impl& r ) const
1566 return maFilterName == r.maFilterName &&
1567 maType == r.maType &&
1568 maDocumentService == r.maDocumentService &&
1569 maFilterService == r.maFilterService &&
1570 maInterfaceName == r.maInterfaceName &&
1571 maComment == r.maComment &&
1572 maExtension == r.maExtension &&
1573 maDocType == r.maDocType &&
1574 maExportXSLT == r.maExportXSLT &&
1575 maImportXSLT == r.maImportXSLT &&
1576 maExportService == r.maExportService &&
1577 maImportService == r.maImportService &&
1578 maImportTemplate == r.maImportTemplate &&
1579 maFlags == r.maFlags &&
1580 maFileFormatVersion == r.maFileFormatVersion &&
1581 mbNeedsXSLT2 == r.mbNeedsXSLT2;
1586 Sequence< OUString > filter_info_impl::getFilterUserData() const
1588 Sequence< OUString > aUserData(8);
1590 aUserData[0] = "com.sun.star.documentconversion.XSLTFilter";
1591 aUserData[1] = OUString::boolean( mbNeedsXSLT2 );
1592 aUserData[2] = maImportService;
1593 aUserData[3] = maExportService;
1594 aUserData[4] = maImportXSLT;
1595 aUserData[5] = maExportXSLT;
1596 aUserData[7] = maComment;
1598 return aUserData;
1601 OUString string_encode( const OUString & rText )
1604 static sal_Bool const aCharClass[] =
1606 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* UricNoSlash */
1607 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1608 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, /* !"#$%&'()*+,-./*/
1609 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, /*0123456789:;<=>?*/
1610 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /*@ABCDEFGHIJKLMNO*/
1611 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, /*PQRSTUVWXYZ[\]^_*/
1612 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /*`abcdefghijklmno*/
1613 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0 /*pqrstuvwxyz{|}~ */
1617 return Uri::encode( rText, aCharClass, rtl_UriEncodeCheckEscapes, RTL_TEXTENCODING_UTF8 );
1620 OUString string_decode( const OUString & rText )
1622 return Uri::decode( rText, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8 );
1625 bool isFileURL( const OUString & rURL )
1627 return rURL.startsWith("file:");
1630 bool copyStreams( Reference< XInputStream > xIS, Reference< XOutputStream > xOS )
1634 sal_Int32 nBufferSize = 512;
1635 Sequence< sal_Int8 > aDataBuffer(nBufferSize);
1637 sal_Int32 nRead;
1640 nRead = xIS->readBytes( aDataBuffer, nBufferSize );
1642 if( nRead )
1644 if( nRead < nBufferSize )
1646 nBufferSize = nRead;
1647 aDataBuffer.realloc(nRead);
1650 xOS->writeBytes( aDataBuffer );
1653 while( nRead );
1655 xOS->flush();
1657 return true;
1659 catch(const Exception&)
1661 OSL_FAIL( "copyStreams() exception catched!" );
1664 return false;
1667 bool createDirectory( OUString& rURL )
1669 sal_Int32 nLastIndex = sizeof( "file:///" ) - 2;
1670 while( nLastIndex != -1 )
1672 nLastIndex = rURL.indexOf( '/', nLastIndex + 1);
1673 if( nLastIndex != -1 )
1675 OUString aDirURL( rURL.copy( 0, nLastIndex ) );
1676 Directory aDir( aDirURL );
1677 Directory::RC rc = aDir.open();
1678 if( rc == Directory::E_NOENT )
1679 rc = osl::Directory::create( aDirURL );
1681 if( rc != Directory::E_None )
1683 return false;
1688 return true;
1691 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */