20#include <com/sun/star/beans/XPropertySet.hpp>
21#include <com/sun/star/util/XFlushable.hpp>
22#include <com/sun/star/uno/XComponentContext.hpp>
24#include <com/sun/star/beans/PropertyValue.hpp>
26#include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
34#include <osl/file.hxx>
64 const css::uno::Reference<css::uno::XComponentContext>& rxContext)
65 : GenericDialogController(pParent,
"filter/ui/xmlfiltersettings.ui",
"XMLFilterSettingsDialog")
67 , m_sTemplatePath(
"$(user)/template/")
68 , m_sDocTypePrefix(
"doctype:")
69 , m_xPBNew(m_xBuilder->weld_button(
"new"))
70 , m_xPBEdit(m_xBuilder->weld_button(
"edit"))
71 , m_xPBTest(m_xBuilder->weld_button(
"test"))
72 , m_xPBDelete(m_xBuilder->weld_button(
"delete"))
73 , m_xPBSave(m_xBuilder->weld_button(
"save"))
74 , m_xPBOpen(m_xBuilder->weld_button(
"open"))
75 , m_xPBClose(m_xBuilder->weld_button(
"close"))
76 , m_xFilterListBox(m_xBuilder->weld_tree_view(
"filterlist"))
97 mxFilterContainer.set( rxContext->getServiceManager()->createInstanceWithContext(
"com.sun.star.document.FilterFactory", rxContext ), UNO_QUERY );
98 mxTypeDetection.set( rxContext->getServiceManager()->createInstanceWithContext(
"com.sun.star.document.TypeDetection", rxContext ), UNO_QUERY );
99 mxExtendedTypeDetection.set( rxContext->getServiceManager()->createInstanceWithContext(
"com.sun.star.document.ExtendedTypeDetectionFactory", rxContext ), UNO_QUERY );
119 if (m_xPBNew.get() == &rButton)
123 else if (m_xPBEdit.get() == &rButton)
127 else if (m_xPBTest.get() == &rButton)
131 else if (m_xPBDelete.get() == &rButton)
135 else if (m_xPBSave.get() == &rButton)
139 else if (m_xPBOpen.get() == &rButton)
146 if (m_xPBClose.get() == &rButton)
174 bool bHasSelection = !aRows.empty();
176 bool bMultiSelection = aRows.size() > 1;
177 bool bIsReadonly =
false;
178 bool bIsDefault =
false;
194 m_xPBEdit->set_sensitive( bHasSelection && !bMultiSelection && !bIsReadonly);
195 m_xPBTest->set_sensitive( bHasSelection && !bMultiSelection );
196 m_xPBDelete->set_sensitive( bHasSelection && !bMultiSelection && !bIsReadonly && !bIsDefault);
197 m_xPBSave->set_sensitive( bHasSelection );
240 if( !(*pOldInfo == *pNewInfo) )
255 int nLength = rExtensions.getLength();
262 const sal_Unicode * pString = rExtensions.getStr();
266 if( *pString ==
';' )
272 auto aExtensionsRange = asNonConstRange(aExtensions);
277 int nCurrentIndex = 0;
280 for(
i = 0;
i < nExtensions;
i++ )
282 nLastIndex = rExtensions.indexOf(
';', nLastIndex );
284 if( nLastIndex == -1 )
286 aExtensionsRange[
i] = rExtensions.copy( nCurrentIndex );
291 aExtensionsRange[
i] = rExtensions.copy( nCurrentIndex, nLastIndex - nCurrentIndex );
292 nCurrentIndex = nLastIndex + 1;
293 nLastIndex = nCurrentIndex;
304 OUString aFilterName( rFilterName );
310 aFilterName = rFilterName +
" " + OUString::number(
nId++ );
320 OUString aTypeName( rTypeName );
326 aTypeName = rTypeName +
" " + OUString::number(
nId++ );
336 sal_Int32 nDefaultNumber = 0;
343 for( OUString
const & filterName : aFilterNames)
346 if( !(aAny >>= aValues) )
349 const sal_Int32 nValueCount( aValues.getLength() );
350 PropertyValue*
pValues = aValues.getArray();
355 if (
pValues->Name ==
"UIName" )
357 OUString aInterfaceName;
358 pValues->Value >>= aInterfaceName;
362 if( aInterfaceName.match( rInterfaceName ) )
366 sal_Int32 nNumber =
o3tl::toInt32(aInterfaceName.subView( rInterfaceName.getLength() ));
367 if( nNumber >= nDefaultNumber )
368 nDefaultNumber = nNumber + 1;
379 OUString aInterfaceName( rInterfaceName );
382 aInterfaceName +=
" " + OUString::number( nDefaultNumber );
385 return aInterfaceName;
432 *pFilterEntry = *pNewInfo;
456 SvFileStream aOutputStream(aDestURL, StreamMode::WRITE );
468 if( pFilterEntry->
maType.isEmpty() )
491 pFilterEntry->
maFlags |= 0x80040;
511 Any aAny( aFilterData );
554 auto pValues = aValues.getArray();
555 pValues[4].Name =
"DetectService";
556 pValues[4].Value <<= OUString(
"com.sun.star.comp.filters.XMLFilterDetect" );
586 if( xFlushable.is() )
614 if( xFlushable.is() )
643 OUString sFilterDetectService(
"com.sun.star.comp.filters.XMLFilterDetect" );
649 auto aSequenceRange = asNonConstRange(aSequence);
650 sal_Int32
nCount = aSequence.getLength();
659 sal_Int32 nStrCount =
aTypes.getLength();
661 for( nStr = 0; nStr < nStrCount; nStr++ )
667 if( nStr == nStrCount )
669 aTypes.realloc( nStrCount + 1 );
677 if( xFlushable.is() )
700 maFilterVector.push_back( std::unique_ptr<filter_info_impl>(pFilterEntry) );
727 OUString aMessage(FilterResId(STR_WARN_DELETE));
728 aMessage = aMessage.replaceFirst(
"%s", pInfo->
maFilterName );
731 VclMessageType::Warning, VclButtonsType::YesNo,
733 xWarn->set_default_response(
RET_YES);
742 bool bTypeStillUsed =
false;
746 OUString* pFilterName = aFilterNames.getArray();
748 const sal_Int32
nCount = aFilterNames.getLength();
752 for( nFilter = 0; (nFilter <
nCount) && !bTypeStillUsed; nFilter++, pFilterName++ )
755 if( !(aAny >>= aValues) )
758 const sal_Int32 nValueCount( aValues.getLength() );
759 PropertyValue*
pValues = aValues.getArray();
768 if( aType == pInfo->
maType )
769 bTypeStillUsed =
true;
777 if( !bTypeStillUsed )
786 if( xFlushable.is() )
790 if( xFlushable.is() )
798 [&] (std::unique_ptr<filter_info_impl>
const &
p)
799 { return p.get() == pInfo; }));
814 std::vector<filter_info_impl*> aFilters;
820 aFilters.push_back(pInfo);
827 css::ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION,
831 OUString aExtensions(
"*.jar" );
832 OUString aFilterName = FilterResId(STR_FILTER_PACKAGE) +
833 " (" + aExtensions +
")";
835 aDlg.
AddFilter( aFilterName, aExtensions );
845 OUString sPlaceholder(
"%s" );
850 aMsg = FilterResId(STR_FILTERS_HAVE_BEEN_SAVED);
851 aMsg = aMsg.replaceFirst( sPlaceholder, OUString::number( nFilters ) );
852 aMsg = aMsg.replaceFirst(sPlaceholder,
aURL.GetLastName());
856 aMsg = FilterResId(STR_FILTER_HAS_BEEN_SAVED);
857 aMsg = aMsg.replaceFirst( sPlaceholder, (*aFilters.begin())->maFilterName );
858 aMsg = aMsg.replaceFirst(sPlaceholder,
aURL.GetLastName());
862 VclMessageType::Info, VclButtonsType::Ok,
869 std::vector< std::unique_ptr<filter_info_impl> > aFilters;
873 css::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE,
877 OUString aExtensions(
"*.jar" );
878 OUString aFilterName = FilterResId(STR_FILTER_PACKAGE) +
879 " (" + aExtensions +
")";
881 aDlg.
AddFilter( aFilterName, aExtensions );
892 for (
auto&
filter : aFilters)
896 aFilterName =
filter->maFilterName;
906 OUString sPlaceholder(
"%s" );
911 aMsg = FilterResId(STR_NO_FILTERS_FOUND);
912 aMsg = aMsg.replaceFirst(sPlaceholder, aURLObj.
GetLastName());
914 else if( nFilters == 1 )
916 aMsg = FilterResId(STR_FILTER_INSTALLED);
917 aMsg = aMsg.replaceFirst( sPlaceholder, aFilterName );
922 aMsg = FilterResId(STR_FILTERS_INSTALLED);
923 aMsg = aMsg.replaceFirst( sPlaceholder, OUString::number( nFilters ) );
927 VclMessageType::Info, VclButtonsType::Ok,
949 for( OUString
const & filterName : aFilterNames )
951 aUserData.realloc(0);
956 if( !(aAny >>= aValues) )
959 OUString aFilterService;
960 pTempFilter->maFilterName = filterName;
962 const sal_Int32 nValueCount( aValues.getLength() );
963 PropertyValue*
pValues = aValues.getArray();
970 pValues->Value >>= pTempFilter->maType;
972 else if (
pValues->Name ==
"UIName" )
974 pValues->Value >>= pTempFilter->maInterfaceName;
976 else if (
pValues->Name ==
"DocumentService" )
978 pValues->Value >>= pTempFilter->maDocumentService;
980 else if (
pValues->Name ==
"FilterService" )
982 pValues->Value >>= aFilterService;
984 else if (
pValues->Name ==
"Flags" )
986 pValues->Value >>= pTempFilter->maFlags;
988 else if (
pValues->Name ==
"UserData" )
992 else if (
pValues->Name ==
"FileFormatVersion" )
994 pValues->Value >>= pTempFilter->maFileFormatVersion;
996 else if (
pValues->Name ==
"TemplateName" )
998 pValues->Value >>= pTempFilter->maImportTemplate;
1000 else if (
pValues->Name ==
"Finalized" )
1002 pValues->Value >>= pTempFilter->mbReadonly;
1007 if( aFilterService !=
"com.sun.star.comp.Writer.XmlFilterAdaptor" )
1012 if( aUserData.getLength() < 6 )
1016 if( aUserData[0] !=
"com.sun.star.documentconversion.XSLTFilter" )
1020 pTempFilter->mbNeedsXSLT2 = aUserData[1].toBoolean();
1021 pTempFilter->maImportService = aUserData[2];
1022 pTempFilter->maExportService = aUserData[3];
1023 pTempFilter->maImportXSLT = aUserData[4];
1024 pTempFilter->maExportXSLT = aUserData[5];
1025 if( aUserData.getLength() >= 8 )
1026 pTempFilter->maComment = aUserData[7];
1036 if( aAny >>= aValues2 )
1038 const sal_Int32 nValueCount2( aValues2.getLength() );
1039 PropertyValue* pValues2 = aValues2.getArray();
1042 for( nValue2 = 0; nValue2 < nValueCount2; nValue2++, pValues2++ )
1044 if ( pValues2->Name ==
"ClipboardFormat" )
1047 pValues2->Value >>= aDocType;
1052 pTempFilter->maDocType = aDocType;
1054 else if ( pValues2->Name ==
"Extensions" )
1057 if( pValues2->Value >>= aExtensions )
1059 pTempFilter->maExtension.clear();
1061 sal_Int32 nCount3( aExtensions.getLength() );
1062 OUString* pExtensions = aExtensions.getArray();
1064 for(
n = 0;
n < nCount3;
n++ )
1067 pTempFilter->maExtension +=
";";
1068 pTempFilter->maExtension += *pExtensions++;
1072 else if ( pValues2->Name ==
"DocumentIconID" )
1074 pValues2->Value >>= pTempFilter->mnDocumentIconID;
1076 else if ( pValues2->Name ==
"Finalized" )
1080 pValues2->Value >>= bTemp;
1081 pTempFilter->mbReadonly |= bTemp;
1086 catch(
const css::container::NoSuchElementException& )
1088 OSL_FAIL(
"Type not found, user error?" );
1093 maFilterVector.push_back( std::unique_ptr<filter_info_impl>(pTempFilter.get()) );
1115: maDocumentService( pDocumentService, strlen( pDocumentService ), RTL_TEXTENCODING_ASCII_US ),
1117 maXMLImporter( mpXMLImporter, strlen( mpXMLImporter ), RTL_TEXTENCODING_ASCII_US ),
1118 maXMLExporter( mpXMLExporter, strlen( mpXMLExporter ), RTL_TEXTENCODING_ASCII_US )
1124 static std::vector< application_info_impl >
const aInfos
1126 {
"com.sun.star.text.TextDocument",
1128 "com.sun.star.comp.Writer.XMLImporter",
1129 "com.sun.star.comp.Writer.XMLExporter" },
1131 {
"com.sun.star.sheet.SpreadsheetDocument",
1133 "com.sun.star.comp.Calc.XMLImporter",
1134 "com.sun.star.comp.Calc.XMLExporter" },
1136 {
"com.sun.star.presentation.PresentationDocument",
1138 "com.sun.star.comp.Impress.XMLImporter",
1139 "com.sun.star.comp.Impress.XMLExporter" },
1141 {
"com.sun.star.drawing.DrawingDocument",
1143 "com.sun.star.comp.Draw.XMLImporter",
1144 "com.sun.star.comp.Draw.XMLExporter" },
1147 {
"com.sun.star.text.TextDocument",
1149 "com.sun.star.comp.Writer.XMLOasisImporter",
1150 "com.sun.star.comp.Writer.XMLOasisExporter" },
1152 {
"com.sun.star.sheet.SpreadsheetDocument",
1154 "com.sun.star.comp.Calc.XMLOasisImporter",
1155 "com.sun.star.comp.Calc.XMLOasisExporter" },
1157 {
"com.sun.star.presentation.PresentationDocument",
1159 "com.sun.star.comp.Impress.XMLOasisImporter",
1160 "com.sun.star.comp.Impress.XMLOasisExporter" },
1162 {
"com.sun.star.drawing.DrawingDocument",
1164 "com.sun.star.comp.Draw.XMLOasisImporter",
1165 "com.sun.star.comp.Draw.XMLOasisExporter" },
1174 for (
auto const& info : rInfos)
1176 if( rServiceName == info.maXMLExporter ||
1177 rServiceName == info.maXMLImporter)
1194 OUString aRet = FilterResId(STR_UNKNOWN_APPLICATION);
1195 if( !rServiceName.empty() )
1197 aRet += OUString::Concat(
" (") + rServiceName +
")";
1218 if (pEntry == pInfo)
1240 aEntryStr += FilterResId(STR_IMPORT_EXPORT);
1244 aEntryStr += FilterResId(STR_IMPORT_ONLY);
1249 aEntryStr += FilterResId(STR_EXPORT_ONLY);
1253 aEntryStr += FilterResId(STR_UNDEFINED_FILTER);
1260 : maFlags(0x00080040)
1261 , maFileFormatVersion(0)
1262 , mnDocumentIconID(0)
1264 , mbNeedsXSLT2(false)
1292 "com.sun.star.documentconversion.XSLTFilter",
1304 static constexpr auto uricNoSlash = rtl::createUriCharClass(
1305 u8
"!$&'()*+-.0123456789:=?@ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~");
1309 Uri::encode( rText, uricNoSlash.data(), rtl_UriEncodeCheckEscapes, RTL_TEXTENCODING_UTF8 );
1314 return Uri::decode( rText, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8 );
1321 sal_Int32 nBufferSize = 512;
1327 nRead = xIS->readBytes( aDataBuffer, nBufferSize );
1331 if( nRead < nBufferSize )
1333 nBufferSize = nRead;
1334 aDataBuffer.realloc(nRead);
1337 xOS->writeBytes( aDataBuffer );
1356 size_t nLastIndex =
sizeof(
"file:///" ) - 2;
1357 while( nLastIndex != std::u16string_view::npos )
1359 nLastIndex = rURL.find(
'/', nLastIndex + 1);
1360 if( nLastIndex != std::u16string_view::npos )
1362 OUString aDirURL( rURL.substr( 0, nLastIndex ) );
1363 Directory aDir( aDirURL );
1364 Directory::RC rc = aDir.open();
1365 if( rc == Directory::E_NOENT )
1366 rc = osl::Directory::create( aDirURL );
1368 if( rc != Directory::E_None )
const PropertyValue * pValues
Reference< XExecutableDialog > m_xDialog
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, const ILibreOfficeKitNotifier *pNotifier=nullptr)
OUString GetLastName(DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
OUString GetFactoryDefaultFilter(EFactory eFactory) const
OUString SubstituteVariable(const OUString &rVar) const
void openPackage(const OUString &rPackageURL, std::vector< std::unique_ptr< filter_info_impl > > &rFilters)
bool savePackage(const OUString &rPackageURL, const std::vector< filter_info_impl * > &rFilters)
void onEdit()
is called when the user clicks on the "Edit" Button
OUString m_sDocTypePrefix
bool insertOrEdit(filter_info_impl *pNewInfo, const filter_info_impl *pOldInfo=nullptr)
inserts a new filter into the ui and configuration if pOldInfo is NULL.
css::uno::Reference< css::uno::XComponentContext > mxContext
void onTest()
is called when the user clicks the "Test" button
virtual ~XMLFilterSettingsDialog() override
css::uno::Reference< css::container::XNameContainer > mxTypeDetection
void onNew()
is called when the user clicks on the "New" button
std::unique_ptr< weld::TreeView > m_xFilterListBox
css::uno::Reference< css::container::XNameContainer > mxFilterContainer
std::unique_ptr< weld::Button > m_xPBEdit
SvtModuleOptions maModuleOpt
OUString createUniqueInterfaceName(const OUString &rInterfaceName)
checks if the given name is a unique ui name inside the filter factory.
XMLFilterSettingsDialog(weld::Window *pParent, const css::uno::Reference< css::uno::XComponentContext > &rxContext)
OUString createUniqueTypeName(const OUString &rTypeName)
checks if the given name is unique inside the type detection.
void changeEntry(const filter_info_impl *pInfo)
std::unique_ptr< weld::Button > m_xPBDelete
std::unique_ptr< weld::Button > m_xPBTest
OUString createUniqueFilterName(const OUString &rUIName)
checks if the given name is unique inside the filter factory.
css::uno::Reference< css::container::XNameContainer > mxExtendedTypeDetection
std::unique_ptr< weld::Button > m_xPBClose
std::unique_ptr< weld::Button > m_xPBSave
void addFilterEntry(const filter_info_impl *pInfo)
adds a new filter info entry to the ui filter list
static OUString getEntryString(const filter_info_impl *pInfo)
std::unique_ptr< weld::Button > m_xPBNew
std::unique_ptr< weld::Button > m_xPBOpen
std::vector< std::unique_ptr< filter_info_impl > > maFilterVector
filter_info_impl * getNewFilterInfo() const
void test(const filter_info_impl &rFilterInfo)
OUString maDocumentService
sal_Int32 maFileFormatVersion
sal_Int32 mnDocumentIconID
bool operator==(const filter_info_impl &) const
css::uno::Sequence< OUString > getFilterUserData() const
OUString maImportTemplate
void AddFilter(const OUString &rFilterName, const OUString &rExtension)
void SetContext(Context _eNewContext)
std::shared_ptr< weld::Dialog > m_xDialog
#define TOOLS_WARN_EXCEPTION(area, stream)
#define LINK(Instance, Class, Member)
OUString ExpandVariables(const OUString &rString)
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
sal_Int32 toInt32(std::u16string_view str, sal_Int16 radix=10)
OUString toId(const void *pValue)
Sequence< Property > aInfos
constexpr OUStringLiteral STR_DEFAULT_EXTENSION
constexpr OUStringLiteral STR_APPL_NAME_WRITER
constexpr OUStringLiteral STR_APPL_NAME_IMPRESS
constexpr OUStringLiteral STR_APPL_NAME_OASIS_CALC
constexpr OUStringLiteral STR_APPL_NAME_OASIS_IMPRESS
constexpr OUStringLiteral STR_APPL_NAME_OASIS_WRITER
constexpr OUStringLiteral STR_APPL_NAME_DRAW
constexpr OUStringLiteral STR_APPL_NAME_OASIS_DRAW
constexpr OUStringLiteral STR_APPL_NAME_CALC
application_info_impl(const char *pDocumentService, const OUString &rUINameRes, const char *mpXMLImporter, const char *mpXMLExporter)
OUString maDocumentUIName
OUString string_encode(const OUString &rText)
IMPL_LINK(XMLFilterSettingsDialog, ClickHdl_Impl, weld::Button &, rButton, void)
std::vector< application_info_impl > const & getApplicationInfos()
const application_info_impl * getApplicationInfo(std::u16string_view rServiceName)
IMPL_LINK_NOARG(XMLFilterSettingsDialog, SelectionChangedHdl_Impl, weld::TreeView &, void)
bool copyStreams(const Reference< XInputStream > &xIS, const Reference< XOutputStream > &xOS)
static Sequence< OUString > createExtensionsSequence(const OUString &rExtensions)
helper to create a sequence of strings from an extensions strings "ext1;ext2;ext3" will become { "ext...
bool createDirectory(std::u16string_view rURL)
OUString getApplicationUIName(std::u16string_view rServiceName)
OUString string_decode(const OUString &rText)