Not crap after all...
[amarok.git] / src / deletedialog.cpp
blobbc8732214e0b8feda8cc8dae536c44efa6ef03a8
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 ***************************************************************************/
7 /***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
16 #include <kconfiggroup.h>
17 #include <kdialog.h>
18 #include <kglobal.h>
19 #include <kiconloader.h>
20 #include <kio/deletejob.h>
21 #include <klocale.h>
22 #include <kstandardguiitem.h>
23 #include <kurl.h>
25 #include <QStringList>
26 #include <QCheckBox>
27 #include <QLayout>
28 #include <QLabel>
29 #include <QTimer>
30 #include <kvbox.h>
31 #include <khbox.h>
33 #include "amarok.h"
34 #include "playlist.h"
35 #include "deletedialog.h"
36 #include "statusbar.h"
38 //////////////////////////////////////////////////////////////////////////////
39 // DeleteWidget implementation
40 //////////////////////////////////////////////////////////////////////////////
42 DeleteWidget::DeleteWidget(QWidget *parent)
43 : DeleteDialogBase(parent)
45 KConfigGroup messageGroup(KGlobal::config(), "FileRemover");
47 bool deleteInstead = messageGroup.readEntry("deleteInsteadOfTrash", false);
48 slotShouldDelete(deleteInstead);
49 ddShouldDelete->setChecked(deleteInstead);
52 void DeleteWidget::setFiles(const KUrl::List &files)
54 ddFileList->clear();
55 // ddFileList->insertStringList(files);
56 for( KUrl::List::ConstIterator it = files.begin(); it != files.end(); it++)
58 if( (*it).isLocalFile() ) //path is nil for non-local
59 ddFileList->insertItem( (*it).path() );
60 else
61 ddFileList->insertItem( (*it).url() );
63 ddNumFiles->setText(i18nc("<b>1</b> file selected.", "<b>%n</b> files selected.", files.count()));
66 void DeleteWidget::slotShouldDelete(bool shouldDelete)
68 if(shouldDelete) {
69 ddDeleteText->setText(i18n("<qt>These items will be <b>permanently "
70 "deleted</b> from your hard disk.</qt>"));
71 ddWarningIcon->setPixmap(KIconLoader::global()->loadIcon("messagebox_warning",
72 K3Icon::Desktop, K3Icon::SizeLarge));
74 else {
75 ddDeleteText->setText(i18n("<qt>These items will be moved to the Trash Bin.</qt>"));
76 ddWarningIcon->setPixmap(KIconLoader::global()->loadIcon("trashcan_full",
77 K3Icon::Desktop, K3Icon::SizeLarge));
81 //////////////////////////////////////////////////////////////////////////////
82 // DeleteDialog implementation
83 //////////////////////////////////////////////////////////////////////////////
85 DeleteDialog::DeleteDialog(QWidget *parent, const char *name) :
86 KDialog( parent ),
87 m_trashGuiItem(i18n("&Send to Trash"), "trashcan_full")
89 //Swallow, Qt::WStyle_DialogBorder, parent, name,
90 //true /* modal */, i18n("About to delete selected files"),
91 // Ok | Cancel, Cancel /* Default */, true /* separator */
92 setCaption( i18n("About to delete selected files") );
93 setModal( true );
94 setButtons( Ok | Cancel );
95 setDefaultButton( Cancel );
96 showButtonSeparator( true );
98 m_widget = new DeleteWidget(this);
99 m_widget->setObjectName("delete_dialog_widget");
100 setMainWidget(m_widget);
102 m_widget->setMinimumSize(400, 300);
103 setMinimumSize(410, 326);
104 adjustSize();
106 slotShouldDelete(shouldDelete());
107 connect(m_widget->ddShouldDelete, SIGNAL(toggled(bool)), SLOT(slotShouldDelete(bool)));
111 bool DeleteDialog::confirmDeleteList(const KUrl::List& condemnedFiles)
113 m_widget->setFiles(condemnedFiles);
115 return exec() == QDialog::Accepted;
118 void DeleteDialog::setFiles(const KUrl::List &files)
120 m_widget->setFiles(files);
123 void DeleteDialog::accept()
125 KConfigGroup messageGroup(KGlobal::config(), "FileRemover");
127 // Save user's preference
129 messageGroup.writeEntry("deleteInsteadOfTrash", shouldDelete());
130 messageGroup.sync();
132 KDialog::accept();
135 void DeleteDialog::slotShouldDelete(bool shouldDelete)
137 setButtonGuiItem(Ok, shouldDelete ? KStandardGuiItem::del() : m_trashGuiItem);
140 bool DeleteDialog::showTrashDialog(QWidget* parent, const KUrl::List& files)
142 DeleteDialog dialog(parent);
143 bool doDelete = dialog.confirmDeleteList(files);
145 if( doDelete )
147 KIO::Job* job = 0;
148 bool shouldDelete = dialog.shouldDelete();
149 if ( ( shouldDelete && (job = KIO::del( files )) ) ||
150 ( job = Amarok::trashFiles( files ) ) )
152 if(shouldDelete) //amarok::trashFiles already does the progress operation
153 Amarok::StatusBar::instance()->newProgressOperation( job )
154 .setDescription( i18n("Deleting files") );
159 return doDelete;
161 #include "deletedialog.moc"
163 // vim: set et ts=4 sw=4: