1
/**************************************************************************
3
* Copyright 2014 Canonical Ltd.
4
* Copyright 2014 Carlos J Mazieri <carlos.mazieri@gmail.com>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU Lesser General Public License as published by
8
* the Free Software Foundation; version 3.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU Lesser General Public License for more details.
15
* You should have received a copy of the GNU Lesser General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18
* File: qtrashutilinfo.cpp
22
#include "qtrashutilinfo.h"
28
QLatin1String filesDirString("files");
29
QLatin1String infoDirString("info");
31
void QTrashUtilInfo::clear()
42
QString QTrashUtilInfo::filesTrashDir(const QString &trashDir)
44
QString filesDir(trashDir + QDir::separator() + filesDirString);
49
QString QTrashUtilInfo::infoTrashDir(const QString &trashDir)
51
QString infoDir(trashDir + QDir::separator() + infoDirString);
56
void QTrashUtilInfo::setInfoFromTrashItem(const QString &absTrashItem)
59
QFileInfo item(absTrashItem);
60
if (item.absolutePath().endsWith(filesDirString))
62
QFileInfo filesUnderRoot(item.absolutePath());
63
QTrashUtilInfo::setInfo(filesUnderRoot.absolutePath(), absTrashItem);
72
void QTrashUtilInfo::setInfo(const QString& trashRootDir, const QString& filename)
74
valid = !trashRootDir.isEmpty();
77
QFileInfo f(filename);
78
trashRoot = trashRootDir;
79
filesDir = filesTrashDir(trashRootDir);
80
absFile = filesDir + QDir::separator() + f.fileName();
81
infoDir = infoTrashDir(trashRootDir) ;
82
absInfo = infoDir + QDir::separator() + f.fileName() +
83
QLatin1String(".trashinfo");
92
bool QTrashUtilInfo::isValid()
98
bool QTrashUtilInfo::existsFile()
100
return QFileInfo(absFile).exists();
104
bool QTrashUtilInfo::existsInfoFile()
106
return QFileInfo(absInfo).exists();
110
QString QTrashUtilInfo::getOriginalPathName()
115
QSettings inff(absInfo, QSettings::IniFormat);
116
inff.beginGroup(QLatin1String("Trash Info"));
117
QFileInfo f (inff.value(QLatin1String("Path")).toString());
118
//Path contains the full pathname
119
path = f.absoluteFilePath();
125
bool QTrashUtilInfo::createTrashInfoFile(const QString& orignalPathname)
127
bool ret = isValid();
130
QByteArray content("[Trash Info]\nPath=");
131
content += orignalPathname + QLatin1Char('\n');
132
content += "DeletionDate=";
133
content += QDateTime::currentDateTime().toString(Qt::ISODate) + QLatin1Char('\n');
135
ret = f.open(QFile::WriteOnly | QFile::Truncate) &&
136
f.write(content) == content.size();
144
bool QTrashUtilInfo::removeTrashInfoFile()
146
QFile infoFile(absInfo);
148
if (valid && infoFile.exists())
150
ret = infoFile.remove();