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 /***************************************************************************
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. *
14 ***************************************************************************/
16 #include "deletedialog.h"
20 #include "statusbar.h"
22 #include <KConfigGroup>
26 #include <KIconLoader>
27 #include <KIO/DeleteJob>
29 #include <KStandardGuiItem>
36 #include <QStringList>
40 //////////////////////////////////////////////////////////////////////////////
41 // DeleteWidget implementation
42 //////////////////////////////////////////////////////////////////////////////
44 DeleteWidget::DeleteWidget(QWidget
*parent
)
45 : DeleteDialogBase(parent
)
47 KConfigGroup
messageGroup(KGlobal::config(), "FileRemover");
49 bool deleteInstead
= messageGroup
.readEntry("deleteInsteadOfTrash", false);
50 slotShouldDelete(deleteInstead
);
51 ddShouldDelete
->setChecked(deleteInstead
);
54 void DeleteWidget::setFiles(const KUrl::List
&files
)
57 // ddFileList->insertStringList(files);
58 for( KUrl::List::ConstIterator it
= files
.begin(); it
!= files
.end(); it
++)
60 if( (*it
).isLocalFile() ) //path is nil for non-local
61 ddFileList
->insertItem( (*it
).path() );
63 ddFileList
->insertItem( (*it
).url() );
65 ddNumFiles
->setText(i18np("<b>1</b> file selected.", "<b>%1</b> files selected.", files
.count()));
68 void DeleteWidget::slotShouldDelete(bool shouldDelete
)
71 ddDeleteText
->setText(i18n("<qt>These items will be <b>permanently "
72 "deleted</b> from your hard disk.</qt>"));
73 ddWarningIcon
->setPixmap(KIconLoader::global()->loadIcon("messagebox_warning",
74 KIconLoader::Desktop
, KIconLoader::SizeLarge
));
77 ddDeleteText
->setText(i18n("<qt>These items will be moved to the Trash Bin.</qt>"));
78 ddWarningIcon
->setPixmap(KIconLoader::global()->loadIcon("trashcan_full",
79 KIconLoader::Desktop
, KIconLoader::SizeLarge
));
83 //////////////////////////////////////////////////////////////////////////////
84 // DeleteDialog implementation
85 //////////////////////////////////////////////////////////////////////////////
87 DeleteDialog::DeleteDialog( QWidget
*parent
, const char *name
)
89 m_trashGuiItem(i18n("&Send to Trash"), "trashcan_full")
91 //Swallow, Qt::WStyle_DialogBorder, parent, name,
92 //true /* modal */, i18n("About to delete selected files"),
93 // Ok | Cancel, Cancel /* Default */, true /* separator */
94 setObjectName( name
);
95 setCaption( i18n("About to delete selected files") );
97 setButtons( Ok
| Cancel
);
98 setDefaultButton( Cancel
);
99 showButtonSeparator( true );
101 m_widget
= new DeleteWidget(this);
102 m_widget
->setObjectName("delete_dialog_widget");
103 setMainWidget(m_widget
);
105 m_widget
->setMinimumSize(400, 300);
106 setMinimumSize(410, 326);
109 slotShouldDelete(shouldDelete());
110 connect(m_widget
->ddShouldDelete
, SIGNAL(toggled(bool)), SLOT(slotShouldDelete(bool)));
114 bool DeleteDialog::confirmDeleteList(const KUrl::List
& condemnedFiles
)
116 m_widget
->setFiles(condemnedFiles
);
118 return exec() == QDialog::Accepted
;
121 void DeleteDialog::setFiles(const KUrl::List
&files
)
123 m_widget
->setFiles(files
);
126 void DeleteDialog::accept()
128 KConfigGroup
messageGroup(KGlobal::config(), "FileRemover");
130 // Save user's preference
132 messageGroup
.writeEntry("deleteInsteadOfTrash", shouldDelete());
138 void DeleteDialog::slotShouldDelete(bool shouldDelete
)
140 setButtonGuiItem(Ok
, shouldDelete
? KStandardGuiItem::del() : m_trashGuiItem
);
143 bool DeleteDialog::showTrashDialog(QWidget
* parent
, const KUrl::List
& files
)
145 DeleteDialog
dialog(parent
);
146 bool doDelete
= dialog
.confirmDeleteList(files
);
151 bool shouldDelete
= dialog
.shouldDelete();
152 if ( ( shouldDelete
&& (job
= KIO::del( files
)) ) ||
153 ( job
= Amarok::trashFiles( files
) ) )
155 if(shouldDelete
) //amarok::trashFiles already does the progress operation
156 Amarok::StatusBar::instance()->newProgressOperation( job
)
157 .setDescription( i18n("Deleting files") );
164 #include "deletedialog.moc"
166 // vim: set et ts=4 sw=4: