source: wkhtmltox/trunk/fuentes/src/lib/tempfile.cc @ 51

Last change on this file since 51 was 51, checked in by mabarracus, 4 years ago

wip

File size: 1.7 KB
Line 
1// -*- mode: c++; tab-width: 4; indent-tabs-mode: t; eval: (progn (c-set-style "stroustrup") (c-set-offset 'innamespace 0)); -*-
2// vi:set ts=4 sts=4 sw=4 noet :
3//
4// Copyright 2010 wkhtmltopdf authors
5//
6// This file is part of wkhtmltopdf.
7//
8// wkhtmltopdf is free software: you can redistribute it and/or modify
9// it under the terms of the GNU Lesser General Public License as published by
10// the Free Software Foundation, either version 3 of the License, or
11// (at your option) any later version.
12//
13// wkhtmltopdf is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16// GNU General Public License for more details.
17//
18// You should have received a copy of the GNU Lesser General Public License
19// along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
20
21
22#include "tempfile.hh"
23#include <QDir>
24#include <QFile>
25#include <QUuid>
26
27#include "dllbegin.inc"
28/*!
29  \file tempfile.hh
30  \brief Defines the TempFile class
31*/
32
33
34/*!
35  \class TempFile
36  \brief Class responsible for creating and deleting temporary files
37*/
38TempFile::TempFile() {
39}
40
41TempFile::~TempFile() {
42        removeAll();
43}
44
45/*!
46  \brief Create a new temporary file
47  \param ext The extention of the temporary file
48  \returns Path of the new temporary file
49*/
50QString TempFile::create(const QString & ext) {
51        QString path = QDir::tempPath()+"/wktemp-"+QUuid::createUuid().toString().mid(1,36)+ext;
52        paths.append(path);
53        return path;
54}
55
56/*!
57  \brief Remove all the temporary files held by this object
58*/
59void TempFile::removeAll() {
60        foreach (const QString &path, paths)
61                QFile::remove(path);
62        paths.clear();
63}
Note: See TracBrowser for help on using the repository browser.