Make plasma libs build.
[amarok.git] / src / deletedialog.cpp
blob0297e69addc2237c5440300dec38731eef7b3b98
1 /***************************************************************************
2 begin : Tue Aug 31 21:59:58 EST 2004
3 copyright : (C) 2004 by Michael Pyne <michael.pyne@kdemail.net>
4 (C) 2006 by Ian Monroe <ian@monroe.nu>
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of
8 the License or (at your option) version 3 or any later version
9 accepted by the membership of KDE e.V. (or its successor approved
10 by the membership of KDE e.V.), which shall act as a proxy
11 defined in Section 14 of version 3 of the license.
13 This program 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.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ***************************************************************************/
22 #include "deletedialog.h"
24 #include "amarok.h"
26 #include "ContextStatusBar.h"
28 #include <KConfigGroup>
29 #include <KDialog>
30 #include <KGlobal>
31 #include <KHBox>
32 #include <KIconLoader>
33 #include <KIO/DeleteJob>
34 #include <KLocale>
35 #include <KStandardGuiItem>
36 #include <KUrl>
37 #include <KVBox>
39 #include <QCheckBox>
40 #include <QLabel>
41 #include <QLayout>
42 #include <QStringList>
43 #include <QTimer>
46 //////////////////////////////////////////////////////////////////////////////
47 // DeleteWidget implementation
48 //////////////////////////////////////////////////////////////////////////////
50 DeleteWidget::DeleteWidget(QWidget *parent)
51 : DeleteDialogBase(parent)
53 KConfigGroup messageGroup(KGlobal::config(), "FileRemover");
55 bool deleteInstead = messageGroup.readEntry("deleteInsteadOfTrash", false);
56 slotShouldDelete(deleteInstead);
57 ddShouldDelete->setChecked(deleteInstead);
60 void DeleteWidget::setFiles(const KUrl::List &files)
62 ddFileList->clear();
63 // ddFileList->insertStringList(files);
64 for( KUrl::List::ConstIterator it = files.begin(); it != files.end(); it++)
66 if( (*it).isLocalFile() ) //path is nil for non-local
67 ddFileList->insertItem( (*it).path() );
68 else
69 ddFileList->insertItem( (*it).url() );
71 ddNumFiles->setText(i18np("<b>1</b> file selected.", "<b>%1</b> files selected.", files.count()));
74 void DeleteWidget::slotShouldDelete(bool shouldDelete)
76 if(shouldDelete) {
77 ddDeleteText->setText(i18n("<qt>These items will be <b>permanently "
78 "deleted</b> from your hard disk.</qt>"));
79 ddWarningIcon->setPixmap(KIconLoader::global()->loadIcon("messagebox_warning",
80 KIconLoader::Desktop, KIconLoader::SizeLarge));
82 else {
83 ddDeleteText->setText(i18n("<qt>These items will be moved to the Trash Bin.</qt>"));
84 ddWarningIcon->setPixmap(KIconLoader::global()->loadIcon("trashcan_full",
85 KIconLoader::Desktop, KIconLoader::SizeLarge));
89 //////////////////////////////////////////////////////////////////////////////
90 // DeleteDialog implementation
91 //////////////////////////////////////////////////////////////////////////////
93 DeleteDialog::DeleteDialog( QWidget *parent, const char *name )
94 : KDialog( parent ),
95 m_trashGuiItem(i18n("&Send to Trash"), "trashcan_full")
97 //Swallow, Qt::WStyle_DialogBorder, parent, name,
98 //true /* modal */, i18n("About to delete selected files"),
99 // Ok | Cancel, Cancel /* Default */, true /* separator */
100 setObjectName( name );
101 setCaption( i18n("About to delete selected files") );
102 setModal( true );
103 setButtons( Ok | Cancel );
104 setDefaultButton( Cancel );
105 showButtonSeparator( true );
107 m_widget = new DeleteWidget(this);
108 m_widget->setObjectName("delete_dialog_widget");
109 setMainWidget(m_widget);
111 m_widget->setMinimumSize(400, 300);
112 setMinimumSize(410, 326);
113 adjustSize();
115 slotShouldDelete(shouldDelete());
116 connect(m_widget->ddShouldDelete, SIGNAL(toggled(bool)), SLOT(slotShouldDelete(bool)));
120 bool DeleteDialog::confirmDeleteList(const KUrl::List& condemnedFiles)
122 m_widget->setFiles(condemnedFiles);
124 return exec() == QDialog::Accepted;
127 void DeleteDialog::setFiles(const KUrl::List &files)
129 m_widget->setFiles(files);
132 void DeleteDialog::accept()
134 KConfigGroup messageGroup(KGlobal::config(), "FileRemover");
136 // Save user's preference
138 messageGroup.writeEntry("deleteInsteadOfTrash", shouldDelete());
139 messageGroup.sync();
141 KDialog::accept();
144 void DeleteDialog::slotShouldDelete(bool shouldDelete)
146 setButtonGuiItem(Ok, shouldDelete ? KStandardGuiItem::del() : m_trashGuiItem);
149 bool DeleteDialog::showTrashDialog(QWidget* parent, const KUrl::List& files)
151 DeleteDialog dialog(parent);
152 bool doDelete = dialog.confirmDeleteList(files);
154 if( doDelete )
156 KIO::Job* job = 0;
157 bool shouldDelete = dialog.shouldDelete();
158 if ( ( shouldDelete && (job = KIO::del( files )) ) ||
159 ( job = Amarok::trashFiles( files ) ) )
161 if(shouldDelete) //amarok::trashFiles already does the progress operation
162 Amarok::ContextStatusBar::instance()->newProgressOperation( job )
163 .setDescription( i18n("Deleting files") );
168 return doDelete;
170 #include "deletedialog.moc"
172 // vim: set et ts=4 sw=4: