#include "comics_remover.h" #include #include #include "QsLog.h" ComicsRemover::ComicsRemover(QModelIndexList &il, QList &ps, qulonglong parentId, QObject *parent) : QObject(parent), indexList(il), paths(ps), parentId(parentId) { } void ComicsRemover::process() { QString currentComicPath; QListIterator i(indexList); QListIterator i2(paths); i.toBack(); i2.toBack(); while (i.hasPrevious() && i2.hasPrevious()) { QModelIndex mi = i.previous(); currentComicPath = i2.previous(); if (QFile::moveToTrash(currentComicPath)) emit remove(mi.row()); else if (QFile::remove(currentComicPath)) emit remove(mi.row()); else emit removeError(); } emit finished(); emit removedItemsFromFolder(parentId); } FoldersRemover::FoldersRemover(QModelIndexList &il, QList &ps, QObject *parent) : QObject(parent), indexList(il), paths(ps) { } void FoldersRemover::process() { QString currentFolderPath; QListIterator i(indexList); QListIterator i2(paths); i.toBack(); i2.toBack(); QLOG_DEBUG() << "Deleting folders" << paths.at(0); while (i.hasPrevious() && i2.hasPrevious()) { QModelIndex mi = i.previous(); currentFolderPath = i2.previous(); QDir d(currentFolderPath); if (QFile::moveToTrash(currentFolderPath)) emit remove(mi); else if (d.removeRecursively() || !d.exists()) // the folder is in the DB but no in the drive... emit remove(mi); else emit removeError(); } emit finished(); }