Hi Mikhail,
Here is another preliminary patch for i40233, please help me to review
it and tell me if anything needs to be modified.
Thank you, and Best Regards,
Felix.
Index: officecfg/registry/data/org/openoffice/Setup.xcu
===================================================================
--- officecfg/registry/data/org/openoffice/Setup.xcu (revision 276217)
+++ officecfg/registry/data/org/openoffice/Setup.xcu (working copy)
@@ -89,6 +89,9 @@
<prop oor:name="ooSetupFactoryTemplateFile">
<value ></value>
</prop>
+ <prop
oor:name="ooSetupFactorySystemDefaultTemplateChanged">
+ <value ></value>
+ </prop>
<prop oor:name="ooSetupFactoryShortName">
<value >scalc</value>
</prop>
@@ -130,6 +133,9 @@
<prop oor:name="ooSetupFactoryTemplateFile">
<value ></value>
</prop>
+ <prop
oor:name="ooSetupFactorySystemDefaultTemplateChanged">
+ <value ></value>
+ </prop>
<prop oor:name="ooSetupFactoryShortName">
<value >sdraw</value>
</prop>
@@ -171,6 +177,9 @@
<prop oor:name="ooSetupFactoryTemplateFile">
<value ></value>
</prop>
+ <prop
oor:name="ooSetupFactorySystemDefaultTemplateChanged">
+ <value ></value>
+ </prop>
<prop oor:name="ooSetupFactoryShortName">
<value >simpress</value>
</prop>
@@ -210,6 +219,9 @@
<prop oor:name="ooSetupFactoryTemplateFile">
<value ></value>
</prop>
+ <prop
oor:name="ooSetupFactorySystemDefaultTemplateChanged">
+ <value ></value>
+ </prop>
<prop oor:name="ooSetupFactoryShortName">
<value >smath</value>
</prop>
@@ -249,6 +261,9 @@
<prop oor:name="ooSetupFactoryTemplateFile">
<value ></value>
</prop>
+ <prop
oor:name="ooSetupFactorySystemDefaultTemplateChanged">
+ <value ></value>
+ </prop>
<prop oor:name="ooSetupFactoryShortName">
<value >sglobal</value>
</prop>
@@ -290,6 +305,9 @@
<prop oor:name="ooSetupFactoryTemplateFile">
<value ></value>
</prop>
+ <prop
oor:name="ooSetupFactorySystemDefaultTemplateChanged">
+ <value ></value>
+ </prop>
<prop oor:name="ooSetupFactoryShortName">
<value >swriter</value>
</prop>
@@ -438,6 +456,9 @@
<prop oor:name="ooSetupFactoryTemplateFile">
<value ></value>
</prop>
+ <prop
oor:name="ooSetupFactorySystemDefaultTemplateChanged">
+ <value ></value>
+ </prop>
<prop oor:name="ooSetupFactoryShortName">
<value >sweb</value>
</prop>
@@ -690,6 +711,9 @@
<prop oor:name="ooSetupFactoryTemplateFile">
<value ></value>
</prop>
+ <prop
oor:name="ooSetupFactorySystemDefaultTemplateChanged">
+ <value ></value>
+ </prop>
<prop oor:name="ooSetupFactoryShortName">
<value >schart</value>
</prop>
@@ -729,6 +753,9 @@
<prop oor:name="ooSetupFactoryTemplateFile">
<value ></value>
</prop>
+ <prop
oor:name="ooSetupFactorySystemDefaultTemplateChanged">
+ <value ></value>
+ </prop>
<prop oor:name="ooSetupFactoryShortName">
<value >dbapp</value>
</prop>
Index: officecfg/registry/schema/org/openoffice/Setup.xcs
===================================================================
--- officecfg/registry/schema/org/openoffice/Setup.xcs (revision 276217)
+++ officecfg/registry/schema/org/openoffice/Setup.xcs (working copy)
@@ -138,6 +138,12 @@
<desc>Specifies the name of the
standard template file for the factory.</desc>
</info>
</prop>
+ <prop
oor:name="ooSetupFactorySystemDefaultTemplateChanged" oor:type="xs:boolean">
+ <!-- UIHints: setup -->
+ <info>
+ <desc>Indicates if the system default
template has been changed.</desc>
+ </info>
+ </prop>
<prop oor:name="ooSetupFactoryWindowAttributes"
oor:type="xs:string">
<!-- UIHints: setup -->
<info>
Index: sfx2/inc/sfx2/docfac.hxx
===================================================================
--- sfx2/inc/sfx2/docfac.hxx (revision 275286)
+++ sfx2/inc/sfx2/docfac.hxx (working copy)
@@ -100,6 +100,7 @@
const SfxFilter* GetTemplateFilter() const;
static String GetStandardTemplate( const String& rServiceName );
static void SetStandardTemplate( const String&
rServiceName, const String& rTemplateName );
+ static void Foo( const String& rTemplateName );
void SetDocumentServiceName( const rtl::OUString&
rServiceName );
const rtl::OUString& GetDocumentServiceName() const;
Property changes on: sfx2\source\doc
___________________________________________________________________
Added: svn:ignore
+ ¸´¼þ syspath.hxx
Index: sfx2/source/doc/docfac.cxx
===================================================================
--- sfx2/source/doc/docfac.cxx (revision 275286)
+++ sfx2/source/doc/docfac.cxx (working copy)
@@ -33,6 +33,7 @@
#include <com/sun/star/registry/MergeConflictException.hpp>
#include <com/sun/star/registry/XSimpleRegistry.hpp>
#include <com/sun/star/container/XNameAccess.hpp>
+#include <com/sun/star/ucb/XSimpleFileAccess.hpp>
#include <comphelper/processfactory.hxx>
#include <tools/config.hxx>
#include <svtools/pathoptions.hxx>
@@ -52,8 +53,12 @@
#include <sfx2/mnumgr.hxx>
#include "sfxresid.hxx"
#include <sfx2/sfxuno.hxx>
+#include "syspath.hxx"
+#include <osl/file.hxx>
#include "doc.hrc"
+#define DEF_TPL_NAME "/soffice"
+
namespace css = ::com::sun::star;
//========================================================================
@@ -185,13 +190,142 @@
pImpl->pModule = pMod;
}
+void SfxObjectFactory::Foo( const String& rTemplateName )
+{
+ ::rtl::OUString aUserTemplatePath =
SystemPath::GetUserTemplateLocation();
+
+ if ( aUserTemplatePath.getLength() == 0)
+ {
+ try
+ {
+ uno::Reference< lang::XMultiServiceFactory > xFactory =
::comphelper::getProcessServiceFactory();
+ if ( !xFactory.is() )
+ throw uno::RuntimeException();
+
+ uno::Reference< lang::XMultiServiceFactory >
xConfigProvider(
+ xFactory->createInstance(
+ ::rtl::OUString::createFromAscii(
"com.sun.star.configuration.ConfigurationProvider" ) ),
+ uno::UNO_QUERY_THROW );
+
+ uno::Sequence< uno::Any > aArgs( 1 );
+ beans::PropertyValue aPathProp;
+ aPathProp.Name = ::rtl::OUString::createFromAscii(
"nodepath" );
+ aPathProp.Value <<= ::rtl::OUString(
RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Setup/Office/Factories/" ) );
+ aArgs[0] <<= aPathProp;
+
+ uno::Reference< container::XNameAccess > xApplConfig(
+ xConfigProvider->createInstanceWithArguments(
+ ::rtl::OUString::createFromAscii(
"com.sun.star.configuration.ConfigurationAccess" ),
+ aArgs ),
+ uno::UNO_QUERY_THROW );
+
+ // get default template file path
+ aUserTemplatePath += ::rtl::OUString( DEF_TPL_NAME );
+
+ ::rtl::OUString aFilterName;
+ xApplConfig->getByName( ::rtl::OUString(
RTL_CONSTASCII_USTRINGPARAM( "ooSetupFactoryActualFilter" ) ) ) >>= aFilterName;
+ ::rtl::OUString aTypeName;
+
+ uno::Reference< container::XNameAccess > xFilterFactory(
+ xFactory->createInstance(
::rtl::OUString::createFromAscii( "com.sun.star.document.FilterFactory" ) ),
+ uno::UNO_QUERY_THROW );
+
+ uno::Sequence< beans::PropertyValue > aFilterData;
+ xFilterFactory->getByName( aFilterName ) >>=
aFilterData;
+ for ( sal_Int32 nInd = 0; nInd <
aFilterData.getLength(); nInd++ )
+ if ( aFilterData[nInd].Name.equalsAscii( "Type"
) )
+ aFilterData[nInd].Value >>= aTypeName;
+
+ uno::Reference< container::XNameAccess > xTypeDetection
= uno::Reference< container::XNameAccess >( // Todo: simplify this
+ xFactory->createInstance(
::rtl::OUString::createFromAscii( "com.sun.star.document.TypeDetection" ) ),
+ uno::UNO_QUERY );
+ ::rtl::OUString aExt;
+ if ( xTypeDetection.is() )
+ {
+ uno::Sequence< beans::PropertyValue >
aTypeNameProps;
+ if ( ( xTypeDetection->getByName( aTypeName )
>>= aTypeNameProps ) && aTypeNameProps.getLength() )
+ {
+ ::comphelper::SequenceAsHashMap
aTypeNamePropsHM( aTypeNameProps );
+ uno::Sequence< ::rtl::OUString >
aExtensions = aTypeNamePropsHM.getUnpackedValueOrDefault(
+
::rtl::OUString::createFromAscii( "Extensions" ),
+ ::uno::Sequence<
::rtl::OUString >() );
+ aExt = aExtensions[0];
+ }
+ }
+
+ aUserTemplatePath += aExt;
+
+ // check if default template has been changed
+ sal_Bool bDefaultTemplateChanged;
+ xApplConfig->getByName( ::rtl::OUString(
RTL_CONSTASCII_USTRINGPARAM( "ooSetupFactorySystemDefaultTemplateChanged" ) ) )
>>= bDefaultTemplateChanged;
+
+
+ uno::Reference< ucb::XSimpleFileAccess >
xSimpleFileAccess(
+ xFactory->createInstance(
::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ) ),
uno::UNO_QUERY_THROW );
+
+ ::rtl::OUString aBackupPath;
+ ::osl::Security().getConfigDir(aBackupPath);
+ aBackupPath += ::rtl::OUString::createFromAscii(
"/temp" );
+
+ if ( !xSimpleFileAccess->exists( aBackupPath ) )
+ xSimpleFileAccess->createFolder( aBackupPath );
+
+ aBackupPath += aExt;
+
+ if ( rTemplateName.length() != 0
+ && xSimpleFileAccess->exists( aUserTemplatePath
) )
+ {
+ if( !bDefaultTemplateChanged )
+ xSimpleFileAccess->copy(
aUserTemplatePath, aBackupPath );
+
+ uno::Sequence< beans::PropertyValue > aArgs( 3
);
+ aArgs[0].Name =
::rtl::OUString::createFromAscii( "FilterName" );
+ aArgs[0].Value <<= aFilterName;
+ aArgs[1].Name =
::rtl::OUString::createFromAscii( "AsTemplate" );
+ aArgs[1].Value <<= sal_True;
+ aArgs[2].Name =
::rtl::OUString::createFromAscii( "URL" );
+ aArgs[2].Value <<= rTemplateName;
+
+ uno::Reference< frame::XLoadable > xLoadable(
xFactory->createInstance( GetDocumentServiceName() ), uno::UNO_QUERY );
+ xLoadable->load( aArgs );
+
+ aArgs.realloc( 2 );
+ aArgs[1].Name =
::rtl::OUString::createFromAscii( "Overwrite" );
+ aArgs[1].Value <<= sal_True;
+
+ uno::Reference< frame::XStorable > xStorable(
xLoadable, uno::UNO_QUERY );
+ xStorable->storeToURL( aUserTemplatePath, aArgs
);
+
+ xApplConfig->getByName( ::rtl::OUString(
RTL_CONSTASCII_USTRINGPARAM( "ooSetupFactorySystemDefaultTemplateChanged" ) ) )
<<= sal_True;
+ }
+ else
+ {
+ if ( bDefaultTemplateChanged )
+ {
+ xSimpleFileAccess->copy( aBackupPath,
aUserTemplatePath );
+ xSimpleFileAccess->kill( aBackupPath );
+ }
+ else
+ {
+ }
+ }
+ catch( Exception& )
+ {
+ }
+ }
+ }
+}
+
void SfxObjectFactory::SetStandardTemplate( const String& rServiceName, const
String& rTemplate )
{
SvtModuleOptions::EFactory eFac =
SvtModuleOptions::ClassifyFactoryByServiceName(rServiceName);
if (eFac == SvtModuleOptions::E_UNKNOWN_FACTORY)
eFac = SvtModuleOptions::ClassifyFactoryByShortName(rServiceName);
if (eFac != SvtModuleOptions::E_UNKNOWN_FACTORY)
+ {
+ Foo( rTemplate );
SvtModuleOptions().SetFactoryStandardTemplate(eFac, rTemplate);
+ }
}
String SfxObjectFactory::GetStandardTemplate( const String& rServiceName )
Index: sfx2/source/doc/makefile.mk
===================================================================
--- sfx2/source/doc/makefile.mk (revision 275286)
+++ sfx2/source/doc/makefile.mk (working copy)
@@ -88,7 +88,8 @@
$(SLO)$/Metadatable.obj \
$(SLO)$/sfxmodelfactory.obj \
$(SLO)$/docstoragemodifylistener.obj \
- $(SLO)$/querytemplate.obj
+ $(SLO)$/querytemplate.obj \
+ $(SLO)$/syspathw32.obj
# --- Tagets -------------------------------------------------------
Index: sfx2/source/doc/syspath.hxx
===================================================================
--- sfx2/source/doc/syspath.hxx (revision 0)
+++ sfx2/source/doc/syspath.hxx (revision 0)
@@ -0,0 +1,41 @@
+/*************************************************************************
+*
+* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+*
+* Copyright 2008 by Sun Microsystems, Inc.
+*
+* OpenOffice.org - a multi-platform office productivity suite
+*
+* $RCSfile: shutdowniconw32.cxx,v $
+* $Revision: 1.48 $
+*
+* This file is part of OpenOffice.org.
+*
+* OpenOffice.org is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Lesser General Public License version 3
+* only, as published by the Free Software Foundation.
+*
+* OpenOffice.org is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Lesser General Public License version 3 for more details
+* (a copy is included in the LICENSE file that accompanied this code).
+*
+* You should have received a copy of the GNU Lesser General Public License
+* version 3 along with OpenOffice.org. If not, see
+* <http://www.openoffice.org/license.html>
+* for a copy of the LGPLv3 License.
+*
+************************************************************************/
+
+#ifndef __SYSPATH_HXX__
+#define __SYSPATH_HXX__
+
+#include <rtl/ustring.hxx>
+
+class SFX2_DLLPUBLIC SystemPath
+{
+ static ::rtl::OUString GetUserTemplateLocation();
+};
+
+#endif
\ No newline at end of file
Index: sfx2/source/doc/syspathw32.cxx
===================================================================
--- sfx2/source/doc/syspathw32.cxx (revision 0)
+++ sfx2/source/doc/syspathw32.cxx (revision 0)
@@ -0,0 +1,80 @@
+/*************************************************************************
+*
+* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+*
+* Copyright 2008 by Sun Microsystems, Inc.
+*
+* OpenOffice.org - a multi-platform office productivity suite
+*
+* $RCSfile: shutdowniconw32.cxx,v $
+* $Revision: 1.48 $
+*
+* This file is part of OpenOffice.org.
+*
+* OpenOffice.org is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Lesser General Public License version 3
+* only, as published by the Free Software Foundation.
+*
+* OpenOffice.org is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Lesser General Public License version 3 for more details
+* (a copy is included in the LICENSE file that accompanied this code).
+*
+* You should have received a copy of the GNU Lesser General Public License
+* version 3 along with OpenOffice.org. If not, see
+* <http://www.openoffice.org/license.html>
+* for a copy of the LGPLv3 License.
+*
+************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include "syspath.hxx"
+#include <shlobj.h>
+
+using namespace ::rtl;
+
+#ifdef WNT
+
+#define ALLOC(type, n) ((type *) HeapAlloc(GetProcessHeap(), 0, sizeof(type) *
n ))
+#define FREE(p) HeapFree(GetProcessHeap(), 0, p)
+
+static OUString _SHGetSpecialFolderW32( int nFolderID )
+{
+ LPITEMIDLIST pidl;
+ HRESULT hHdl = SHGetSpecialFolderLocation( NULL,
nFolderID, &pidl );
+ OUString aFolder;
+
+ if( hHdl == NOERROR )
+ {
+ WCHAR *lpFolderA;
+ lpFolderA = ALLOC( WCHAR, 16000 );
+
+ SHGetPathFromIDListW( pidl, lpFolderA );
+ aFolder = OUString( reinterpret_cast<const
sal_Unicode*>(lpFolderA) );
+
+ FREE( lpFolderA );
+ IMalloc *pMalloc;
+ if( NOERROR == SHGetMalloc(&pMalloc) )
+ {
+ pMalloc->Free( pidl );
+ pMalloc->Release();
+ }
+ }
+ return aFolder;
+}
+
+#endif
+
+static OUString SystemPath::GetUserTemplateLocation()
+{
+#ifdef WNT
+ return _SHGetSpecialFolderW32(CSIDL_TEMPLATES);
+#endif
+#ifdef UNX
+ return ::rtl::OUString();
+#endif
+}
+
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@framework.openoffice.org
For additional commands, e-mail: dev-h...@framework.openoffice.org