Commit ca9676e6 authored by Michael Pyne's avatar Michael Pyne

The "Delete" action can again delete files. I've changed the Remove Files...

The "Delete" action can again delete files.  I've changed the Remove Files dialog box to include a checkbox which allows you to delete files instead of moving them to the Trash, and the setting is saved.  The default setting is to move to the Trash Bin instead of deleting.

svn path=/trunk/kdemultimedia/juk/; revision=343637
parent 89bc15ad
......@@ -18,8 +18,10 @@
#include <kstdguiitem.h>
#include <klocale.h>
#include <kiconloader.h>
#include <kconfig.h>
#include <qstringlist.h>
#include <qcheckbox.h>
#include <qlayout.h>
#include <qlabel.h>
#include <qvbox.h>
......@@ -27,39 +29,93 @@
#include "deletedialog.h"
DeleteDialog::DeleteDialog(QWidget *parent, const char *name)
//////////////////////////////////////////////////////////////////////////////
// DeleteWidget implementation
//////////////////////////////////////////////////////////////////////////////
DeleteWidget::DeleteWidget(QWidget *parent, const char *name)
: DeleteDialogBase(parent, name)
{
layout()->setSpacing(KDialog::spacingHint());
ddWarningIcon->setPixmap(KGlobal::iconLoader()->loadIcon("messagebox_warning",
KIcon::Desktop, KIcon::SizeLarge));
KConfigGroup messageGroup(KGlobal::config(), "FileRemover");
bool deleteInstead = messageGroup.readBoolEntry("deleteInsteadOfTrash", false);
slotShouldDelete(deleteInstead);
ddShouldDelete->setChecked(deleteInstead);
}
void DeleteDialog::setFiles(const QStringList &files)
void DeleteWidget::setFiles(const QStringList &files)
{
ddFileList->clear();
ddFileList->insertStringList(files);
ddNumFiles->setText(i18n("<b>1</b> file selected.", "<b>%n</b> files selected.", files.count()));
}
bool DeleteDialog::confirmDeleteList(QWidget *parent, const QStringList &condemnedFiles)
void DeleteWidget::slotShouldDelete(bool shouldDelete)
{
if(shouldDelete) {
ddDeleteText->setText(i18n("<qt>These items will be <b>permanently "
"deleted</b> from your hard disk.</qt>"));
ddWarningIcon->setPixmap(KGlobal::iconLoader()->loadIcon("messagebox_warning",
KIcon::Desktop, KIcon::SizeLarge));
}
else {
ddDeleteText->setText(i18n("<qt>These items will be moved to the Trash Bin.</qt>"));
ddWarningIcon->setPixmap(KGlobal::iconLoader()->loadIcon("trashcan_full",
KIcon::Desktop, KIcon::SizeLarge));
}
}
//////////////////////////////////////////////////////////////////////////////
// DeleteDialog implementation
//////////////////////////////////////////////////////////////////////////////
DeleteDialog::DeleteDialog(QWidget *parent, const char *name) :
KDialogBase(Swallow, WStyle_DialogBorder, parent, name,
true /* modal */, i18n("About to delete selected files"),
Ok | Cancel, Cancel /* Default */, true /* separator */),
m_trashGuiItem(i18n("&Send to Trash"), "trashcan_full")
{
m_widget = new DeleteWidget(this, "delete_dialog_widget");
setMainWidget(m_widget);
m_widget->setMinimumSize(400, 300);
setMinimumSize(410, 326);
adjustSize();
slotShouldDelete(shouldDelete());
connect(m_widget->ddShouldDelete, SIGNAL(toggled(bool)), SLOT(slotShouldDelete(bool)));
}
bool DeleteDialog::confirmDeleteList(const QStringList &condemnedFiles)
{
m_widget->setFiles(condemnedFiles);
return exec() == QDialog::Accepted;
}
void DeleteDialog::setFiles(const QStringList &files)
{
m_widget->setFiles(files);
}
void DeleteDialog::accept()
{
KDialogBase base(KDialogBase::Plain, WStyle_DialogBorder, parent, "delete_dialog",
true /* modal */, i18n("About to delete selected files"), KDialogBase::Ok |
KDialogBase::Cancel, KDialogBase::Cancel /* Default */, true /* separator */);
QWidget *page = base.plainPage();
QVBoxLayout *layout = new QVBoxLayout(page);
DeleteDialog *widget = new DeleteDialog(page);
layout->addWidget(widget);
widget->setFiles(condemnedFiles);
base.setMinimumSize(410, 324);
base.adjustSize();
base.setButtonGuiItem(KDialogBase::Ok, KStdGuiItem::del());
return base.exec() == QDialog::Accepted;
KConfigGroup messageGroup(KGlobal::config(), "FileRemover");
// Save user's preference
messageGroup.writeEntry("deleteInsteadOfTrash", shouldDelete());
messageGroup.sync();
KDialogBase::accept();
}
void DeleteDialog::slotShouldDelete(bool shouldDelete)
{
setButtonGuiItem(Ok, shouldDelete ? KStdGuiItem::del() : m_trashGuiItem);
}
#include "deletedialog.moc"
// vim: set et ts=4 sw=4:
......@@ -16,18 +16,50 @@
#ifndef _DELETEDIALOG_H
#define _DELETEDIALOG_H
#include <kdialogbase.h>
#include <kguiitem.h>
#include <qcheckbox.h>
#include <qvbox.h>
#include "deletedialogbase.h"
class QStringList;
class KListBox;
class QLabel;
class QWidgetStack;
class DeleteWidget : public DeleteDialogBase
{
Q_OBJECT
public:
DeleteWidget(QWidget *parent = 0, const char *name = 0);
class DeleteDialog : public DeleteDialogBase
void setFiles(const QStringList &files);
protected slots:
virtual void slotShouldDelete(bool shouldDelete);
};
class DeleteDialog : public KDialogBase
{
Q_OBJECT
public:
DeleteDialog(QWidget *parent = 0, const char *name = 0);
DeleteDialog(QWidget *parent, const char *name = "delete_dialog");
bool confirmDeleteList(const QStringList &condemnedFiles);
void setFiles(const QStringList &files);
bool shouldDelete() const { return m_widget->ddShouldDelete->isChecked(); }
protected slots:
virtual void accept();
void slotShouldDelete(bool shouldDelete);
static bool confirmDeleteList(QWidget *parent, const QStringList &condemnedFiles);
private:
DeleteWidget *m_widget;
KGuiItem m_trashGuiItem;
};
#endif
......
......@@ -8,8 +8,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>493</width>
<height>473</height>
<width>542</width>
<height>374</height>
</rect>
</property>
<property name="minimumSize">
......@@ -24,7 +24,7 @@
</property>
<widget class="QLayoutWidget">
<property name="name">
<cstring>layout3</cstring>
<cstring>layout4</cstring>
</property>
<hbox>
<property name="name">
......@@ -34,29 +34,49 @@
<property name="name">
<cstring>ddWarningIcon</cstring>
</property>
<property name="text">
<string>Replace me</string>
</property>
</widget>
<widget class="QLabel">
<property name="name">
<cstring>ddWarningLabel</cstring>
</property>
<property name="sizePolicy">
<sizepolicy>
<hsizetype>7</hsizetype>
<vsizetype>5</vsizetype>
<hsizetype>4</hsizetype>
<vsizetype>4</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>&lt;qt&gt;&lt;p&gt;Are you sure that you want to delete these items?&lt;/p&gt;
&lt;p&gt;Deleting these items will &lt;b&gt;permanently remove&lt;/b&gt; them.&lt;/p&gt;&lt;/qt&gt;</string>
<string>Replace me</string>
</property>
<property name="alignment">
<set>WordBreak|AlignCenter</set>
</widget>
<widget class="QLayoutWidget">
<property name="name">
<cstring>layout3</cstring>
</property>
<vbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QLabel">
<property name="name">
<cstring>textLabel1</cstring>
</property>
<property name="text">
<string>Are you sure that you want to remove these items?</string>
</property>
<property name="alignment">
<set>AlignCenter</set>
</property>
</widget>
<widget class="QLabel">
<property name="name">
<cstring>ddDeleteText</cstring>
</property>
<property name="text">
<string>&lt;qt&gt;Deleting these items will &lt;b&gt;permanently remove&lt;/b&gt; them.&lt;/qt&gt;</string>
</property>
<property name="alignment">
<set>WordBreak|AlignCenter</set>
</property>
</widget>
</vbox>
</widget>
</hbox>
</widget>
......@@ -85,10 +105,37 @@
<set>AlignVCenter|AlignRight</set>
</property>
</widget>
<widget class="QCheckBox">
<property name="name">
<cstring>ddShouldDelete</cstring>
</property>
<property name="text">
<string>&amp;Delete files instead of moving them to the Trash Bin.</string>
</property>
<property name="toolTip" stdset="0">
<string>If checked, files will be permanently removed instead of being placed in the Trash Bin</string>
</property>
<property name="whatsThis" stdset="0">
<string>&lt;qt&gt;&lt;p&gt;If this box is checked, files will be &lt;b&gt;permanently removed&lt;/b&gt; instead of being placed in the Trash Bin.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Use this option with caution&lt;/em&gt;: Most filesystems are unable to reliably undelete deleted files.&lt;/p&gt;&lt;/qt&gt;</string>
</property>
</widget>
</vbox>
</widget>
<customwidgets>
</customwidgets>
<connections>
<connection>
<sender>ddShouldDelete</sender>
<signal>toggled(bool)</signal>
<receiver>DeleteDialogBase</receiver>
<slot>slotShouldDelete(bool)</slot>
</connection>
</connections>
<slots>
<slot access="protected">slotShouldDelete(bool)</slot>
</slots>
<layoutdefaults spacing="6" margin="11"/>
<includehints>
<includehint>klistbox.h</includehint>
......
......@@ -740,16 +740,17 @@ void Playlist::removeFromDisk(const PlaylistItemList &items)
KURL trashDir = KGlobalSettings::trashPath();
QString message = i18n("Do you really want to move this item to the trash?",
"Do you really want to move these %n items to the trash?",
files.count());
if(DeleteDialog::confirmDeleteList(this, files)) {
DeleteDialog dialog(this);
if(dialog.confirmDeleteList(files)) {
bool shouldDelete = dialog.shouldDelete();
for(PlaylistItemList::ConstIterator it = items.begin(); it != items.end(); ++it) {
if(m_playingItem == *it)
action("forward")->activate();
if(KIO::NetAccess::move((*it)->file().absFilePath(), trashDir)) {
QString removePath = (*it)->file().absFilePath();
if((!shouldDelete && KIO::NetAccess::move(removePath, trashDir)) ||
(shouldDelete && QFile::remove(removePath))) {
if(!m_randomList.isEmpty() && !m_visibleChanged)
m_randomList.remove(*it);
CollectionList::instance()->clearItem((*it)->collectionItem());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment