summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPalenik Mihály <palenik.mihaly@gmail.com>2013-07-16 16:37:36 +0200
committerAndras Timar <atimar@suse.com>2013-07-16 18:40:45 +0000
commit9c0a390489dd99aee4beaf73845740776b8083aa (patch)
tree6c833c56639e77c7fe6e7fcd6c7be9a39d96c200
parent22adf4e70a4b4a8d188909f39b386e738e3cd37e (diff)
fdo#63133: Write tools/tempfile.hxx out
I deleted TempFile class and changed it to utl::TempFile class -which in unotools/tempfile.hxx- in the followings: Storage, StgTmpStrm, SwXMailMerge classes; and RenderAsEMF function. I modified header in precompiled_sw.hxx. Change-Id: I3dae5333dc42538e1b905f6a6bbc85534c591dc1 Reviewed-on: https://gerrit.libreoffice.org/4938 Reviewed-by: Andras Timar <atimar@suse.com> Tested-by: Andras Timar <atimar@suse.com>
-rw-r--r--filter/Library_ips.mk1
-rw-r--r--filter/source/graphicfilter/ieps/ieps.cxx6
-rw-r--r--include/tools/tempfile.hxx66
-rw-r--r--sot/source/sdstor/stg.cxx4
-rw-r--r--sot/source/sdstor/stgstrms.cxx4
-rw-r--r--sw/inc/pch/precompiled_sw.hxx1
-rw-r--r--sw/source/ui/uno/unomailmerge.cxx6
-rw-r--r--tools/Library_tl.mk1
-rw-r--r--tools/source/fsys/tempfile.cxx181
9 files changed, 11 insertions, 259 deletions
diff --git a/filter/Library_ips.mk b/filter/Library_ips.mk
index 2a61795fd2b6..59933edd34f6 100644
--- a/filter/Library_ips.mk
+++ b/filter/Library_ips.mk
@@ -27,6 +27,7 @@ $(eval $(call gb_Library_use_libraries,ips,\
vcl \
tl \
sal \
+ utl \
$(gb_UWINAPI) \
))
diff --git a/filter/source/graphicfilter/ieps/ieps.cxx b/filter/source/graphicfilter/ieps/ieps.cxx
index e3bf1173bc10..c857b3f8ce4b 100644
--- a/filter/source/graphicfilter/ieps/ieps.cxx
+++ b/filter/source/graphicfilter/ieps/ieps.cxx
@@ -33,7 +33,7 @@
#include <vcl/virdev.hxx>
#include <vcl/cvtgrf.hxx>
#include <vcl/bmpacc.hxx>
-#include <tools/tempfile.hxx>
+#include <unotools/tempfile.hxx>
#include <osl/process.h>
#include <osl/file.hxx>
@@ -189,14 +189,14 @@ static oslProcessError runProcessWithPathSearch(const OUString &rProgName,
static bool RenderAsEMF(const sal_uInt8* pBuf, sal_uInt32 nBytesRead, Graphic &rGraphic)
{
- TempFile aTemp;
+ utl::TempFile aTemp;
aTemp.EnableKillingFile();
OUString fileName("pstoedit" EXESUFFIX);
OUString arg1("-f");
OUString arg2("emf:-OO");
OUString arg3("-");
OUString output;
- osl::FileBase::getSystemPathFromFileURL(aTemp.GetName(), output);
+ osl::FileBase::getSystemPathFromFileURL(aTemp.GetURL(), output);
rtl_uString *args[] =
{
arg1.pData, arg2.pData, arg3.pData, output.pData
diff --git a/include/tools/tempfile.hxx b/include/tools/tempfile.hxx
deleted file mode 100644
index 8d43c18a6df9..000000000000
--- a/include/tools/tempfile.hxx
+++ /dev/null
@@ -1,66 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed
- * with this work for additional information regarding copyright
- * ownership. The ASF licenses this file to you under the Apache
- * License, Version 2.0 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-#ifndef _TOOLS_TEMPFILE_HXX
-#define _TOOLS_TEMPFILE_HXX
-
-#include <rtl/ustring.hxx>
-#include "tools/toolsdllapi.h"
-
-struct TempFile_Impl;
-class TOOLS_DLLPUBLIC TempFile
-{
- TempFile_Impl* pImp;
- bool bKillingFileEnabled;
-
-public:
- /** Create a temporary file in the default tempfile folder. */
- TempFile();
-
- /** Create a temporary file in the default tempfile folder; its name starts
- with some given characters followed by a counter ( example:
- rLeadingChars="abc" means "abc0", "abc1" and so on, depending on
- existing files in that folder ).
-
- The extension string may be f.e. ".txt" or "", if no extension string is
- given, ".tmp" is used.
- */
- TempFile( const OUString& rLeadingChars, const OUString* pExtension=NULL );
-
- /** TempFile will be removed from disk in dtor if EnableKillingTempFile was
- called before. TempDirs will be removed recursively in that case. */
- ~TempFile();
-
- bool IsValid() const;
-
- /** Returns the real name of the tempfile in file URL scheme. */
- OUString GetName() const;
-
- /** If enabled the file will be removed from disk when the dtor is called
- (default is not enabled) */
- void EnableKillingFile( bool bEnable=true ) { bKillingFileEnabled = bEnable; }
-
- bool IsKillingFileEnabled() const { return bKillingFileEnabled; }
-
- /** Only create a name for a temporary file that would be valid at that moment. */
- static OUString CreateTempName();
-};
-
-#endif
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sot/source/sdstor/stg.cxx b/sot/source/sdstor/stg.cxx
index 2fcf0d58c619..e5d49edb9043 100644
--- a/sot/source/sdstor/stg.cxx
+++ b/sot/source/sdstor/stg.cxx
@@ -20,7 +20,7 @@
#include <sot/storinfo.hxx>
#include <osl/file.hxx>
-#include <tools/tempfile.hxx>
+#include <unotools/tempfile.hxx>
#include <tools/stream.hxx>
#include <tools/debug.hxx>
@@ -371,7 +371,7 @@ Storage::Storage( const OUString& rFile, StreamMode m, bool bDirect )
if( aName.isEmpty() )
{
// no name = temporary name!
- aName = TempFile::CreateTempName();
+ aName = utl::TempFile::CreateTempName();
bTemp = true;
}
// the root storage creates the I/O system
diff --git a/sot/source/sdstor/stgstrms.cxx b/sot/source/sdstor/stgstrms.cxx
index 1561204e1e3e..1afbf2125527 100644
--- a/sot/source/sdstor/stgstrms.cxx
+++ b/sot/source/sdstor/stgstrms.cxx
@@ -22,7 +22,7 @@
#include <string.h> // memcpy()
#include <sal/log.hxx>
#include <osl/file.hxx>
-#include <tools/tempfile.hxx>
+#include <unotools/tempfile.hxx>
#include "sot/stg.hxx"
#include "stgelem.hxx"
@@ -1186,7 +1186,7 @@ void StgTmpStrm::SetSize( sal_uLong n )
{
if( n > THRESHOLD )
{
- aName = TempFile::CreateTempName();
+ aName = utl::TempFile::CreateTempName();
SvFileStream* s = new SvFileStream( aName, STREAM_READWRITE );
sal_uLong nCur = Tell();
sal_uLong i = nEndOfData;
diff --git a/sw/inc/pch/precompiled_sw.hxx b/sw/inc/pch/precompiled_sw.hxx
index e829e8649170..22707f256fdf 100644
--- a/sw/inc/pch/precompiled_sw.hxx
+++ b/sw/inc/pch/precompiled_sw.hxx
@@ -977,7 +977,6 @@
#include <tools/solar.h>
#include <tools/stream.hxx>
#include <tools/string.hxx>
-#include <tools/tempfile.hxx>
#include <tools/time.hxx>
#include <tools/urlobj.hxx>
#include <ucbhelper/content.hxx>
diff --git a/sw/source/ui/uno/unomailmerge.cxx b/sw/source/ui/uno/unomailmerge.cxx
index 21fffaf1f680..86d20e220ed8 100644
--- a/sw/source/ui/uno/unomailmerge.cxx
+++ b/sw/source/ui/uno/unomailmerge.cxx
@@ -23,7 +23,7 @@
#include <svl/urihelper.hxx>
#include <svx/dataaccessdescriptor.hxx>
#include <tools/shl.hxx> // GetAppData
-#include <tools/tempfile.hxx>
+#include <unotools/tempfile.hxx>
#include <sfx2/app.hxx>
#include <sfx2/docfile.hxx>
#include <sfx2/docfilt.hxx>
@@ -755,8 +755,8 @@ uno::Any SAL_CALL SwXMailMerge::execute(
OUString( FILTER_XML ),
SwDocShell::Factory().GetFilterContainer() );
OUString aExtension(comphelper::string::stripStart(pSfxFlt->GetDefaultExtension(), '*'));
- TempFile aTempFile( OUString("SwMM"), &aExtension );
- aTmpFileName = aTempFile.GetName();
+ utl::TempFile aTempFile( OUString("SwMM"), &aExtension );
+ aTmpFileName = aTempFile.GetURL();
Reference< XStorable > xStorable( xCurModel, UNO_QUERY );
bool bStoredAsTemporary = false;
diff --git a/tools/Library_tl.mk b/tools/Library_tl.mk
index 56c48dba5a9a..0676abf656c2 100644
--- a/tools/Library_tl.mk
+++ b/tools/Library_tl.mk
@@ -47,7 +47,6 @@ $(eval $(call gb_Library_add_exception_objects,tl,\
tools/source/datetime/tdate \
tools/source/datetime/ttime \
tools/source/debug/debug \
- tools/source/fsys/tempfile \
tools/source/fsys/urlobj \
tools/source/fsys/wldcrd \
tools/source/generic/b3dtrans \
diff --git a/tools/source/fsys/tempfile.cxx b/tools/source/fsys/tempfile.cxx
deleted file mode 100644
index bfc1a0df5e43..000000000000
--- a/tools/source/fsys/tempfile.cxx
+++ /dev/null
@@ -1,181 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed
- * with this work for additional information regarding copyright
- * ownership. The ASF licenses this file to you under the Apache
- * License, Version 2.0 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-
-#include <tools/tempfile.hxx>
-
-#include <rtl/ustrbuf.hxx>
-#include <osl/file.hxx>
-#include <rtl/instance.hxx>
-#include <tools/time.hxx>
-#include <tools/debug.hxx>
-
-#include <stdio.h>
-
-using namespace osl;
-
-namespace { struct TempNameBase_Impl : public rtl::Static< OUString, TempNameBase_Impl > {}; }
-
-struct TempFile_Impl
-{
- OUString aName;
-};
-
-OUString ConstructTempDir_Impl()
-{
- // use system directory
- OUString& rTempNameBase_Impl = TempNameBase_Impl::get();
- if ( rTempNameBase_Impl.isEmpty() )
- osl::FileBase::getTempDirURL( rTempNameBase_Impl );
- OUString aName = rTempNameBase_Impl;
-
- // Make sure that directory ends with a separator
- if( !aName.endsWith( "/" ) )
- aName += "/";
-
- return aName;
-}
-
-void CreateTempName_Impl( OUString& rName, bool bKeep, bool bDir = true )
-{
- // add a suitable tempname
- // Prefix can have 5 chars, leaving 3 for numbers. 26 ** 3 == 17576
- // ER 13.07.00 why not radix 36 [0-9A-Z] ?!?
- const unsigned nRadix = 26;
- OUString aName( rName );
- aName += "sv";
-
- rName = "";
- static unsigned long u = Time::GetSystemTicks();
- for ( unsigned long nOld = u; ++u != nOld; )
- {
- u %= (nRadix*nRadix*nRadix);
- OUString aTmp = OUStringBuffer(aName).
- append((sal_Int32)(unsigned)u, nRadix).
- append(".tmp").
- makeStringAndClear();
-
- if ( bDir )
- {
- FileBase::RC err = Directory::create( aTmp );
- if ( err == FileBase::E_None )
- {
- // !bKeep: only for creating a name, not a file or directory
- if ( bKeep || Directory::remove( aTmp ) == FileBase::E_None )
- rName = aTmp;
- break;
- }
- else if ( err != FileBase::E_EXIST )
- {
- // if f.e. name contains invalid chars stop trying to create dirs
- break;
- }
- }
- else
- {
- DBG_ASSERT( bKeep, "Too expensive, use directory for creating name!" );
- File aFile( aTmp );
- FileBase::RC err = aFile.open(osl_File_OpenFlag_Create);
- if ( err == FileBase::E_None )
- {
- rName = aTmp;
- aFile.close();
- break;
- }
- else if ( err != FileBase::E_EXIST )
- {
- // if f.e. name contains invalid chars stop trying to create files
- break;
- }
- }
- }
-}
-
-OUString TempFile::CreateTempName()
-{
- // get correct directory
- OUString aName = ConstructTempDir_Impl();
-
- // get TempFile name with default naming scheme
- CreateTempName_Impl( aName, false );
-
- return aName;
-}
-
-TempFile::TempFile()
- : pImp( new TempFile_Impl )
- , bKillingFileEnabled( false )
-{
- // get correct directory
- pImp->aName = ConstructTempDir_Impl();
-
- // get TempFile with default naming scheme
- CreateTempName_Impl( pImp->aName, true, false );
-}
-
-TempFile::TempFile( const OUString& rLeadingChars, const OUString* pExtension )
- : pImp( new TempFile_Impl )
- , bKillingFileEnabled( false )
-{
- // get correct directory
- OUString aName = ConstructTempDir_Impl();
-
- // now use special naming scheme ( name takes leading chars and an index counting up from zero
- aName += rLeadingChars;
- for ( sal_Int32 i=0; ; i++ )
- {
- OUStringBuffer aTmpBuffer(aName);
- aTmpBuffer.append(i);
- if ( pExtension )
- aTmpBuffer.append(*pExtension);
- else
- aTmpBuffer.append(".tmp");
- OUString aTmp = aTmpBuffer.makeStringAndClear();
-
- File aFile( aTmp );
- FileBase::RC err = aFile.open(osl_File_OpenFlag_Create);
- if ( err == FileBase::E_None )
- {
- pImp->aName = aTmp;
- aFile.close();
- break;
- }
- else if ( err != FileBase::E_EXIST )
- // if f.e. name contains invalid chars stop trying to create dirs
- break;
- }
-}
-
-TempFile::~TempFile()
-{
- if ( bKillingFileEnabled )
- {
- File::remove( pImp->aName );
- }
-
- delete pImp;
-}
-
-OUString TempFile::GetName() const
-{
- OUString aTmp;
- aTmp = pImp->aName;
- return aTmp;
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */