File indexing completed on 2024-04-21 14:55:41

0001 /* This file is part of the KDE libraries
0002  *  Copyright 2006 Jaison Lee <lee.jaison@gmail.com>
0003  *
0004  *  This library is free software; you can redistribute it and/or
0005  *  modify it under the terms of the GNU Library General Public
0006  *  License as published by the Free Software Foundation; either
0007  *  version 2 of the License, or (at your option) any later version.
0008  *
0009  *  This library is distributed in the hope that it will be useful,
0010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012  *  Library General Public License for more details.
0013  *
0014  *  You should have received a copy of the GNU Library General Public License
0015  *  along with this library; see the file COPYING.LIB.  If not, write to
0016  *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017  *  Boston, MA 02110-1301, USA.
0018  */
0019 
0020 #ifndef ktemporaryfile_h
0021 #define ktemporaryfile_h
0022 
0023 #include <kdelibs4support_export.h>
0024 #include "kglobal.h"
0025 
0026 #include <QTemporaryFile>
0027 
0028 class KTemporaryFilePrivate;
0029 
0030 /**
0031  * \class KTemporaryFile ktemporaryfile.h <KTemporaryFile>
0032  *
0033  * @deprecated use QTemporaryFile
0034  *
0035  * By default the filename will start with your application's name,
0036  * followed by six random characters. You can call QTemporaryFile::setFileTemplate()
0037  * to change that.
0038  *
0039  * Porting to QTemporaryFile is simple: in apps, you can probably just use the default constructor.
0040  *
0041  * In parts and plugins, you were probably passing a component data to KTemporaryFile, so instead use:
0042  * QTemporaryFile(QDir::tempPath() + QLatin1Char('/') + componentData.name() + QLatin1String("XXXXXX"))
0043  *
0044  * For setPrefix, change the QDir::tempPath() from the above line.
0045  * For setSuffix, append it after the XXXXXX.
0046  *
0047  * In the simplest case where the application was only calling setSuffix(".txt"), this becomes
0048  * QTemporaryFile(QDir::tempPath() + QLatin1String("/myapp_XXXXXX.txt"))
0049  *
0050  * @see QTemporaryFile
0051  */
0052 class KDELIBS4SUPPORT_DEPRECATED_EXPORT KTemporaryFile : public QTemporaryFile
0053 {
0054 public:
0055     /**
0056      * Construct a new KTemporaryFile. The file will be stored in the temporary
0057      * directory configured in KDE. The default prefix is the value of the
0058      * default KDE temporary directory, plus your application's instance name.
0059      * The default suffix is ".tmp".
0060      *
0061      * \param componentData The KComponentData to use for the name of the file and
0062      * to look up the directory.
0063      */
0064     KDELIBS4SUPPORT_DEPRECATED explicit KTemporaryFile(const KComponentData &componentData = KGlobal::mainComponent());
0065 
0066     /**
0067      * Destructor.
0068      */
0069     ~KTemporaryFile() override;
0070 
0071     /**
0072      * @brief Sets a prefix to use when creating the file.
0073      *
0074      * This function sets a prefix to use when creating the file. The random
0075      * part of the filename will come after this prefix. The prefix can also
0076      * change or modify the target directory. If @p prefix is an absolute
0077      * path it will override the default temporary directory. If @p prefix is
0078      * a relative directory it will be relative to the default temporary
0079      * location. To set a relative directory for the current working directory
0080      * you should use QTemporaryFile::setFileTemplate() directly.
0081      * @param prefix The prefix to use when creating the file. Remember to
0082      *  end the prefix with a '/' if you are designating a directory.
0083      */
0084     void setPrefix(const QString &prefix);
0085 
0086     /**
0087      * @brief Sets a suffix to use when creating the file.
0088      *
0089      * Sets a suffix to use when creating the file. The random part of the
0090      * filename will come before this suffix.
0091      * @param suffix The suffix to use when creating the file.
0092      */
0093     void setSuffix(const QString &suffix);
0094 
0095 private:
0096     KTemporaryFilePrivate *const d;
0097 };
0098 
0099 #endif