1 /* Copyright (C) 2003-2006 Jesper K. Pedersen <blackie@kde.org>
3 This program is free software; you can redistribute it and/or
4 modify it under the terms of the GNU General Public
5 License as published by the Free Software Foundation; either
6 version 2 of the License, or (at your option) any later version.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with this program; see the file COPYING. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
19 #include "DeleteDialog.h"
21 #include <QVBoxLayout>
23 #include <kmessagebox.h>
24 #include <qcheckbox.h>
28 #include <kio/deletejob.h>
29 #include "kio/copyjob.h"
30 #include "DB/ImageDB.h"
31 #include "DB/ImageInfo.h"
32 #include "DB/Result.h"
33 #include "DB/ResultId.h"
34 #include "ImageManager/Manager.h"
35 #include "Utilities/ShowBusyCursor.h"
36 #include "Utilities/Util.h"
37 #include "MainWindow/DirtyIndicator.h"
39 using namespace MainWindow
;
41 DeleteDialog::DeleteDialog( QWidget
* parent
)
45 setWindowTitle( i18n("Removing items") );
46 setButtons( Cancel
|User1
);
47 setButtonText( User1
,i18n("OK") );
49 QWidget
* top
= new QWidget
;
50 QVBoxLayout
* lay1
= new QVBoxLayout( top
);
55 lay1
->addWidget( _label
);
57 _useTrash
= new QRadioButton
;
58 lay1
->addWidget( _useTrash
);
60 _deleteFile
= new QRadioButton
;
61 lay1
->addWidget( _deleteFile
);
63 _deleteFromDb
= new QRadioButton
;
64 lay1
->addWidget( _deleteFromDb
);
66 connect( this, SIGNAL( user1Clicked() ), this, SLOT( deleteImages() ) );
69 int DeleteDialog::exec(const DB::Result
& list
)
71 if (!list
.size()) return 0;
73 const QString msg1
= i18np( "Removing 1 item", "Removing %1 items", list
.size() );
74 const QString msg2
= i18np( "Selected item will be removed from the database.<br/>What do you want to do with the file on disk?",
75 "Selected %1 items will be removed from the database.<br/>What do you want to do with the files on disk?",
78 const QString txt
= QString::fromLatin1( "<p><b><center><font size=\"+3\">%1</font><br/>%2</center></b></p>" ).arg(msg1
).arg(msg2
);
80 _useTrash
->setText( i18np("Move file to Trash", "Move files to Trash", list
.size() ) );
81 _deleteFile
->setText( i18np( "Delete file from disk", "Delete files from disk", list
.size() ) );
82 _deleteFromDb
->setText( i18np( "Only remove the item from database", "Only remove the items from database", list
.size() ) );
85 _label
->setText( txt
);
86 _useTrash
->setChecked( true );
89 return KDialog::exec();
92 void DeleteDialog::deleteImages()
94 Utilities::ShowBusyCursor dummy
;
95 DB::Result listToDelete
;
96 KUrl::List listKUrlToDelete
;
99 Q_FOREACH(const DB::ResultId id
, _list
) {
100 const QString fileName
= id
.fetchInfo()->fileName(DB::AbsolutePath
);
101 if ( DB::ImageInfo::imageOnDisk( fileName
) ) {
102 if ( _deleteFile
->isChecked() || _useTrash
->isChecked() ){
103 KUrlToDelete
.setPath(fileName
);
104 listKUrlToDelete
.append(KUrlToDelete
);
105 listToDelete
.append(id
);
106 ImageManager::Manager::instance()->removeThumbnail( fileName
);
108 listToDelete
.append(id
);
109 ImageManager::Manager::instance()->removeThumbnail( fileName
);
112 listToDelete
.append(id
);
115 if ( _deleteFile
->isChecked() || _useTrash
->isChecked() ) {
117 if ( _useTrash
->isChecked() )
118 job
= KIO::trash( listKUrlToDelete
);
120 job
= KIO::del( listKUrlToDelete
);
121 connect( job
, SIGNAL( result( KJob
* ) ), this, SLOT( slotKIOJobCompleted( KJob
* ) ) );
124 if(!listToDelete
.isEmpty()) {
125 if ( _deleteFile
->isChecked() || _useTrash
->isChecked() )
126 DB::ImageDB::instance()->deleteList( listToDelete
);
128 DB::ImageDB::instance()->addToBlockList( listToDelete
);
129 MainWindow::DirtyIndicator::markDirty();
136 void DeleteDialog::slotKIOJobCompleted( KJob
* job
)
139 KMessageBox::error( this, job
->errorString(), i18n( "Error Deleting Files" ) );
142 #include "DeleteDialog.moc"