/* * Copyright 2015 Kai Uwe Broulik * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "trash.h" #include #include #include #include #include #include #include Trash::Trash(QObject *parent) : QObject(parent) { } void Trash::trashUrls(const QList &urls) { KIO::JobUiDelegate uiDelegate; if (uiDelegate.askDeleteConfirmation(urls, KIO::JobUiDelegate::Trash, KIO::JobUiDelegate::DefaultConfirmation)) { KIO::Job *job = KIO::trash(urls); job->ui()->setAutoErrorHandlingEnabled(true); } } void Trash::emptyTrash() { KIO::JobUiDelegate uiDelegate; uiDelegate.setWindow(QApplication::desktop()); if (uiDelegate.askDeleteConfirmation(QList(), KIO::JobUiDelegate::EmptyTrash, KIO::JobUiDelegate::DefaultConfirmation)) { KIO::Job *job = KIO::emptyTrash(); job->ui()->setAutoErrorHandlingEnabled(true); } } bool Trash::canBeTrashed(const QUrl &url) const { return url.isValid() && url.isLocalFile() && QFileInfo(url.toLocalFile()).isWritable(); } QList Trash::trashableUrls(const QList &urls) const { QList validUrls = urls; QMutableListIterator it(validUrls); while (it.hasNext()) { if (!canBeTrashed(it.next())) { it.remove(); } } return validUrls; }