File indexing completed on 2024-05-05 04:48:24
0001 /**************************************************************************************** 0002 * Copyright (c) 2004 Michael Pyne <michael.pyne@kdemail.net> * 0003 * Copyright (c) 2006 Ian Monroe <ian@monroe.nu> * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify it under * 0006 * the terms of the GNU General Public License as published by the Free Software * 0007 * Foundation; either version 2 of the License, or (at your option) version 3 or * 0008 * any later version accepted by the membership of KDE e.V. (or its successor approved * 0009 * by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of * 0010 * version 3 of the license. * 0011 * * 0012 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0013 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0014 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0015 * * 0016 * You should have received a copy of the GNU General Public License along with * 0017 * this program. If not, see <http://www.gnu.org/licenses/>. * 0018 ****************************************************************************************/ 0019 0020 #include "deletedialog.h" 0021 0022 #include "core/support/Amarok.h" 0023 0024 #include "App.h" 0025 #include "statusbar/StatusBar.h" 0026 0027 #include <KConfigGroup> 0028 #include <QDialog> 0029 0030 #include <KIconLoader> 0031 #include <KIO/DeleteJob> 0032 #include <KLocalizedString> 0033 #include <KStandardGuiItem> 0034 #include <QUrl> 0035 0036 0037 0038 ////////////////////////////////////////////////////////////////////////////// 0039 // DeleteWidget implementation 0040 ////////////////////////////////////////////////////////////////////////////// 0041 0042 DeleteWidget::DeleteWidget(QWidget *parent) 0043 : DeleteDialogBase(parent) 0044 { 0045 KConfigGroup messageGroup(KGlobal::config(), "FileRemover"); 0046 0047 bool deleteInstead = messageGroup.readEntry("deleteInsteadOfTrash", false); 0048 slotShouldDelete(deleteInstead); 0049 ddShouldDelete->setChecked(deleteInstead); 0050 } 0051 0052 void DeleteWidget::setFiles(const QList<QUrl> &files) 0053 { 0054 ddFileList->clear(); 0055 // ddFileList->insertStringList(files); 0056 for( QList<QUrl>::ConstIterator it = files.constBegin(), end = files.constEnd(); it != end; ++it) 0057 { 0058 if( (*it).isLocalFile() ) //path is nil for non-local 0059 ddFileList->insertItem( (*it).path() ); 0060 else 0061 ddFileList->insertItem( (*it).url() ); 0062 } 0063 ddNumFiles->setText(i18np("<b>1</b> file selected.", "<b>%1</b> files selected.", files.count())); 0064 } 0065 0066 void DeleteWidget::slotShouldDelete(bool shouldDelete) 0067 { 0068 if(shouldDelete) { 0069 ddDeleteText->setText(i18n("<qt>These items will be <b>permanently " 0070 "deleted</b> from your hard disk.</qt>")); 0071 ddWarningIcon->setPixmap(KIconLoader::global()->loadIcon("dialog-warning", 0072 KIconLoader::Desktop, KIconLoader::SizeLarge)); 0073 } 0074 else { 0075 ddDeleteText->setText(i18n("<qt>These items will be moved to the Trash Bin.</qt>")); 0076 ddWarningIcon->setPixmap(KIconLoader::global()->loadIcon("user-trash-full", 0077 KIconLoader::Desktop, KIconLoader::SizeLarge)); 0078 } 0079 } 0080 0081 ////////////////////////////////////////////////////////////////////////////// 0082 // DeleteDialog implementation 0083 ////////////////////////////////////////////////////////////////////////////// 0084 0085 DeleteDialog::DeleteDialog( QWidget *parent, const char *name ) 0086 : QDialog( parent ), 0087 m_trashGuiItem(i18n("&Send to Trash"), "user-trash-full") 0088 { 0089 //Swallow, Qt::WStyle_DialogBorder, parent, name, 0090 //true /* modal */, i18n("About to delete selected files"), 0091 // Ok | Cancel, Cancel /* Default */, true /* separator */ 0092 setObjectName( name ); 0093 setCaption( i18n("About to delete selected files") ); 0094 setModal( true ); 0095 setButtons( Ok | Cancel ); 0096 setDefaultButton( Cancel ); 0097 showButtonSeparator( true ); 0098 0099 m_widget = new DeleteWidget(this); 0100 m_widget->setObjectName("delete_dialog_widget"); 0101 setMainWidget(m_widget); 0102 0103 m_widget->setMinimumSize(400, 300); 0104 setMinimumSize(410, 326); 0105 adjustSize(); 0106 0107 slotShouldDelete(shouldDelete()); 0108 connect(m_widget->ddShouldDelete, &QCheckBox::toggled, this, &DeleteDialog::slotShouldDelete); 0109 0110 } 0111 0112 bool DeleteDialog::confirmDeleteList(const QList<QUrl>& condemnedFiles) 0113 { 0114 m_widget->setFiles(condemnedFiles); 0115 0116 return exec() == QDialog::Accepted; 0117 } 0118 0119 void DeleteDialog::setFiles(const QList<QUrl> &files) 0120 { 0121 m_widget->setFiles(files); 0122 } 0123 0124 void DeleteDialog::accept() 0125 { 0126 KConfigGroup messageGroup(KGlobal::config(), "FileRemover"); 0127 0128 // Save user's preference 0129 0130 messageGroup.writeEntry("deleteInsteadOfTrash", shouldDelete()); 0131 messageGroup.sync(); 0132 0133 QDialog::accept(); 0134 } 0135 0136 void DeleteDialog::slotShouldDelete(bool shouldDelete) 0137 { 0138 setButtonGuiItem(Ok, shouldDelete ? KStandardGuiItem::del() : m_trashGuiItem); 0139 } 0140 0141 bool DeleteDialog::showTrashDialog(QWidget* parent, const QList<QUrl>& files) 0142 { 0143 DeleteDialog dialog(parent); 0144 bool doDelete = dialog.confirmDeleteList(files); 0145 0146 if( doDelete ) 0147 { 0148 KIO::Job* job = 0; 0149 bool shouldDelete = dialog.shouldDelete(); 0150 if ( ( shouldDelete && (job = KIO::del( files )) ) || 0151 ( job = pApp->trashFiles( files ) ) ) 0152 { 0153 if(shouldDelete) //amarok::trashFiles already does the progress operation 0154 The::statusBar()->newProgressOperation( job, i18n("Deleting files") ); 0155 0156 } 0157 0158 } 0159 0160 return doDelete; 0161 } 0162 0163 // vim: set et ts=4 sw=4: 0164