Hi Mikhail,
Here's the improved patch thanks to your suggestions, please have a look
at it and check if anything still needs to be changed.
Thank you and Best Regards,
Felix.
Mikhail Voytenko
Hi Felix,
Thank you for the patch one more time. I will wait for the new version
as we have discussed on IRC meeting today.
Best regards,
Mikhail.
On 12/08/09 10:17, Zhang Xiaofei wrote:
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
------------------------------------------------------------------------
---------------------------------------------------------------------
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 SetSystemTemplate( 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,15 @@
#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>
+
namespace css = ::com::sun::star;
+using namespace ::com::sun::star;
//========================================================================
@@ -185,13 +195,136 @@
pImpl->pModule = pMod;
}
+void SfxObjectFactory::SetSystemTemplate( const String& rServiceName, const
String& rTemplateName )
+{
+ static ::rtl::OUString SERVICE_CONF_PROVIDER =
::rtl::OUString::createFromAscii(
"com.sun.star.configuration.ConfigurationProvider" );
+ static ::rtl::OUString SERVICE_CONF_ACCESS =
::rtl::OUString::createFromAscii(
"com.sun.star.configuration.ConfigurationAccess" );
+ static ::rtl::OUString SERVICE_FILTER_FACTORY =
::rtl::OUString::createFromAscii( "com.sun.star.document.FilterFactory" );
+ static ::rtl::OUString SERVICE_TYPE_DECTECTION =
::rtl::OUString::createFromAscii( "com.sun.star.document.TypeDetection" );
+ static ::rtl::OUString SERVICE_SIMPLE_ACCESS =
::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" );
+
+ static ::rtl::OUString PROP_DEF_TEMPL_CHANGED =
::rtl::OUString::createFromAscii("ooSetupFactorySystemDefaultTemplateChanged");
+ static ::rtl::OUString PROP_ACTUAL_FILTER =
::rtl::OUString::createFromAscii("ooSetupFactoryActualFilter");
+
+ static ::rtl::OUString DEF_TPL_NAME =
::rtl::OUString::createFromAscii("/soffice");
+
+ ::rtl::OUString aUserTemplatePath =
SystemPath::GetUserTemplateLocation();
+
+ if ( aUserTemplatePath.getLength() == 0)
+ {
+ try
+ {
+ uno::Reference< lang::XMultiServiceFactory > xFactory =
::comphelper::getProcessServiceFactory();
+
+ uno::Reference< lang::XMultiServiceFactory >
xConfigProvider(
+ xFactory->createInstance(
SERVICE_CONF_PROVIDER, 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(
SERVICE_CONF_ACCESS, aArgs ), uno::UNO_QUERY_THROW );
+
+ sal_Bool bChanged;
+ xApplConfig->getByName( PROP_DEF_TEMPL_CHANGED ) >>=
bChanged;
+
+ ::rtl::OUString aActualFilter;
+ xApplConfig->getByName( PROP_ACTUAL_FILTER ) >>=
aActualFilter;
+
+ uno::Reference< container::XNameAccess > xFilterFactory(
+ xFactory->createInstance(
SERVICE_FILTER_FACTORY ), uno::UNO_QUERY_THROW );
+ uno::Reference< container::XNameAccess > xTypeDetection(
+ xFactory->createInstance(
SERVICE_TYPE_DECTECTION ), uno::UNO_QUERY_THROW );
+
+ ::rtl::OUString aActualFilterTypeName;
+ uno::Sequence< beans::PropertyValue >
aActuralFilterData;
+ xFilterFactory->getByName( aActualFilter ) >>=
aActuralFilterData;
+ for ( sal_Int32 nInd = 0; nInd <
aActuralFilterData.getLength(); nInd++ )
+ if ( aActuralFilterData[nInd].Name.equalsAscii(
"Type" ) )
+ aActuralFilterData[nInd].Value >>=
aActualFilterTypeName;
+
+ ::comphelper::SequenceAsHashMap aProps1(
xTypeDetector->getByName( aActualFilterTypeName ) );
+ uno::Sequence< ::rtl::OUString > aAllExt =
+ aProps1.getUnpackedValueOrDefault(
::rtl::OUString::createFromAscii( "Extensions" ), Sequence< ::rtl::OUString >()
);
+ ::rtl::OUString aExt = aAllExt[0];
+
+ aUserTemplatePath += ::rtl::OUString::createFromAscii(
DEF_TPL_NAME );
+ aUserTemplatePath += aExt;
+
+ uno::Reference< ucb::XSimpleFileAccess >
xSimpleFileAccess(
+ xFactory->createInstance( SERVICE_SIMPLE_ACCESS
), uno::UNO_QUERY_THROW );
+
+ ::rtl::OUString aBackupPath;
+ ::osl::Security().getConfigDir(aBackupPath);
+ aBackupPath += ::rtl::OUString::createFromAscii(
"/temp" );
+
+ if ( !xSimpleFileAccess->exists( aBackupPath ) )
+ xSimpleFileAccess->createFolder( aBackupPath );
+
+ aBackupPath += ::rtl::OUString::createFromAscii(
DEF_TPL_NAME );
+ aBackupPath += aExt;
+
+ uno::Reference< document::XTypeDetection >
xTypeDetector( xTypeDetection, uno::UNO_QUERY );
+ ::comphelper::SequenceAsHashMap aProps2(
xTypeDetection->getByName( xTypeDetector->queryTypeByURL( rTemplateName ) ) );
+ ::rtl::OUString aFilterName =
+ aProps2.getUnpackedValueOrDefault(
::rtl::OUString::createFromAscii("PreferredFilter"), ::rtl::OUString() );
+
+ if ( rTemplateName.Len() != 0 )
+ {
+ if ( xSimpleFileAccess->exists(
aUserTemplatePath ) )
+ {
+ if( !bChanged )
+ 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 <<= ::rtl::OUString(
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(
PROP_DEF_TEMPL_CHANGED ) <<= sal_True;
+ }
+ }
+ else
+ {
+ DBG_ASSERT( bChanged, "invalid
ooSetupFactorySystemDefaultTemplateChanged value!" );
+
+ xSimpleFileAccess->copy( aBackupPath,
aUserTemplatePath );
+ xSimpleFileAccess->kill( aBackupPath );
+ xApplConfig->getByName( PROP_DEF_TEMPL_CHANGED
) <<= 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)
+ {
+ SetSystemTemplate( 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