Hi Mikhail,
Thank you for the advice, I have corrected them and did a little
polishing to the patch.
One small problem remains is that I can't find the way to convert a
String to OUString. Line 258 in this patch doesn't compile, and I failed
to find a documentation or an example for the conversion. Could you give
me a hint please?
By the way, I haven't come up with a proper name for the method Foo()
yet. I would love to hear your advice.
Thanks and Best Regards,
Felix.
Mikhail Voytenko
Hi Felix,
Thank you for the patch, it looks good in general from the first view.
There are some parts that still can be improved:
- the actual document filter should not be used to load the template;
the best way would be to get the template filter using TypeDetection
- in case the original template is copied back, the configuration
entry, that describes whether the template was changed, should be set
back
Best regards,
Mikhail.
On 12/04/09 10:35, Zhang Xiaofei wrote:
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.
------------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@framework.openoffice.org
For additional commands, e-mail: dev-h...@framework.openoffice.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@framework.openoffice.org
For additional commands, e-mail: dev-h...@framework.openoffice.org
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& rServiceName, 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,10 @@
#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 <com/sun/star/document/XTypeDetection.hpp>
+#include <com/sun/star/frame/XLoadable.hpp>
+#include <com/sun/star/frame/XStorable.hpp>
#include <comphelper/processfactory.hxx>
#include <tools/config.hxx>
#include <svtools/pathoptions.hxx>
@@ -52,9 +56,17 @@
#include <sfx2/mnumgr.hxx>
#include "sfxresid.hxx"
#include <sfx2/sfxuno.hxx>
+#include "syspath.hxx"
+#include <osl/file.hxx>
+#include <osl/security.hxx>
#include "doc.hrc"
+#include <assert.h>
+
+#define DEF_TPL_NAME "/soffice"
+
namespace css = ::com::sun::star;
+using namespace ::com::sun::star;
//========================================================================
@@ -185,13 +197,136 @@
pImpl->pModule = pMod;
}
+void SfxObjectFactory::Foo( const String& rServiceName, 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 );
+
+ ::rtl::OUString aActualFilterName;
+ xApplConfig->getByName(
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
"ooSetupFactoryActualFilter" ) ) ) >>= aActualFilterName;
+ sal_Bool bDefaultTemplateChanged;
+ xApplConfig->getByName(
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
"ooSetupFactorySystemDefaultTemplateChanged" ) ) ) >>= bDefaultTemplateChanged;
+
+ ::rtl::OUString aTypeName;
+ uno::Reference< document::XTypeDetection >
xTypeDetection(
+ xFactory->createInstance(
::rtl::OUString::createFromAscii( "com.sun.star.document.TypeDetection" ) ),
+ uno::UNO_QUERY );
+ aTypeName = xTypeDetection->queryTypeByURL(
rTemplateName );
+
+ uno::Reference< container::XNameAccess > xTypeProps(
xTypeDetection, uno::UNO_QUERY );
+
+ ::rtl::OUString aExt;
+ ::rtl::OUString aFilterName;
+ if ( xTypeProps.is() )
+ {
+ uno::Sequence< beans::PropertyValue >
aTypeNameProps;
+ if ( ( xTypeProps->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];
+ aFilterName =
aTypeNamePropsHM.getUnpackedValueOrDefault(
+
::rtl::OUString::createFromAscii("PreferredFilter"),
+ ::rtl::OUString() );
+ }
+ }
+ aUserTemplatePath += ::rtl::OUString::createFromAscii(
DEF_TPL_NAME );
+ aUserTemplatePath += aExt;
+
+ ::rtl::OUString aBackupPath;
+ ::osl::Security().getConfigDir(aBackupPath);
+ aBackupPath += ::rtl::OUString::createFromAscii(
"/temp" );
+
+ uno::Reference< ucb::XSimpleFileAccess >
xSimpleFileAccess(
+ xFactory->createInstance(
::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ) ),
uno::UNO_QUERY_THROW );
+
+ if ( !xSimpleFileAccess->exists( aBackupPath ) )
+ xSimpleFileAccess->createFolder( aBackupPath );
+
+ aBackupPath += aExt;
+
+ if ( rTemplateName.Len() != 0 )
+ {
+ if ( 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( ::rtl::OUString( rServiceName ) ),
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
+ {
+ DBG_ASSERT( bDefaultTemplateChanged, "invalid
ooSetupFactorySystemDefaultTemplateChanged value!" );
+
+ xSimpleFileAccess->copy( aBackupPath,
aUserTemplatePath );
+ xSimpleFileAccess->kill( aBackupPath );
+ xApplConfig->getByName(
+ ::rtl::OUString(
RTL_CONSTASCII_USTRINGPARAM( "ooSetupFactorySystemDefaultTemplateChanged" ) ) )
<<= sal_False;
+ }
+ }
+ catch( uno::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( rServiceName, 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,42 @@
+/*************************************************************************
+*
+* 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
+{
+public:
+ 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