1
// vim: set tabstop=4 shiftwidth=4 noexpandtab
3
Gwenview - A simple image viewer for KDE
4
Copyright 2000-2004 Aur�ien G�eau
6
This program is free software; you can redistribute it and/or
7
modify it under the terms of the GNU General Public License
8
as published by the Free Software Foundation; either version 2
9
of the License, or (at your option) any later version.
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
#include <qstylesheet.h>
28
#include <kdeversion.h>
29
#include <kfiledialog.h>
30
#include <kfilefiltercombo.h>
31
#include <kglobalsettings.h>
32
#include <kinputdialog.h>
34
#include <kmessagebox.h>
35
#include <kstandarddirs.h>
36
#include <kurlcombobox.h>
39
#include "fileoperation.h"
40
#include "fileopobject.moc"
45
* A tweaked KFileDialog used to select an existing directory. More efficient
46
* than KDirSelectDialog, since it provides access to bookmarks and let you
49
class DirSelectDialog : public KFileDialog {
51
DirSelectDialog(const QString& startDir, QWidget* parent)
52
: KFileDialog(startDir, QString::null, parent, "dirselectdialog", true) {
53
locationEdit->setEnabled(false);
54
filterWidget->setEnabled(false);
55
setMode(KFile::Directory | KFile::ExistingOnly);
57
// Cast to avoid gcc being confused
58
setPreviewWidget(static_cast<KPreviewWidgetBase*>(0));
63
//-FileOpObject--------------------------------------------------------------------
64
FileOpObject::FileOpObject(const KURL& url,QWidget* parent)
71
FileOpObject::FileOpObject(const KURL::List& list,QWidget* parent)
72
: mParent(parent), mURLList(list)
76
void FileOpObject::slotResult(KIO::Job* job) {
78
job->showErrorDialog(mParent);
83
// Let's shoot ourself in the foot...
88
//-FileOpCopyToObject--------------------------------------------------------------
91
void FileOpCopyToObject::operator()() {
94
if (FileOperation::confirmCopy()) {
95
QString destDir = FileOperation::destDir();
96
if( !destDir.isEmpty()) {
99
if (mURLList.size()==1) {
100
destURL=KFileDialog::getSaveURL(destDir + mURLList.first().fileName(),
101
QString::null, mParent, i18n("Copy File"));
103
DirSelectDialog dialog(destDir, mParent);
104
dialog.setCaption(i18n("Select Folder Where the Files Will be Copied"));
106
destURL=dialog.selectedURL();
109
destURL.setPath(FileOperation::destDir());
111
if (destURL.isEmpty()) return;
114
KIO::Job* copyJob=KIO::copy(mURLList,destURL,true);
115
copyJob->setWindow(mParent->topLevelWidget());
116
connect( copyJob, SIGNAL( result(KIO::Job*) ),
117
this, SLOT( slotResult(KIO::Job*) ) );
122
//-FileOpMoveToObject--------------------------------------------------------------
123
void FileOpMoveToObject::operator()() {
126
if (FileOperation::confirmMove()) {
127
QString destDir = FileOperation::destDir();
128
if( !destDir.isEmpty()) {
131
if (mURLList.size()==1) {
132
destURL=KFileDialog::getSaveURL(destDir + mURLList.first().fileName(),
133
QString::null, mParent, i18n("Move File"));
135
DirSelectDialog dialog(destDir, mParent);
136
dialog.setCaption(i18n("Select Folder Where the Files Will be Moved"));
138
destURL=dialog.selectedURL();
141
destURL.setPath(FileOperation::destDir());
143
if (destURL.isEmpty()) return;
146
KIO::Job* moveJob=KIO::move(mURLList,destURL,true);
147
moveJob->setWindow(mParent->topLevelWidget());
148
connect( moveJob, SIGNAL( result(KIO::Job*) ),
149
this, SLOT( slotResult(KIO::Job*) ) );
154
//-FileOpTrashObject---------------------------------------------------------------
155
void FileOpTrashObject::operator()() {
156
#if KDE_IS_VERSION( 3, 3, 89 )
157
KURL trashURL("trash:/");
160
// Get the trash path (and make sure it exists)
161
QString trashPath=KGlobalSettings::trashPath();
162
if ( !QFile::exists(trashPath) ) {
163
KStandardDirs::makeDir( QFile::encodeName(trashPath) );
165
trashURL.setPath(trashPath);
167
// Check we don't want to trash the trash
168
KURL::List::ConstIterator it=mURLList.begin();
169
for (; it!=mURLList.end(); ++it) {
170
if ( (*it).isLocalFile() && (*it).path(1)==trashPath ) {
171
KMessageBox::sorry(0, i18n("You cannot trash the trash bin."));
178
if (FileOperation::confirmDelete()) {
180
if (mURLList.count()>1) {
181
QStringList fileList;
182
KURL::List::ConstIterator it=mURLList.begin();
183
for (; it!=mURLList.end(); ++it) {
184
fileList.append((*it).filename());
186
response=KMessageBox::warningContinueCancelList(mParent,
187
i18n("Do you really want to trash these files?"),fileList,i18n("Trash used as a verb", "Trash Files"),KGuiItem(i18n("Trash used as a verb", "&Trash"),"edittrash"));
189
QString filename=QStyleSheet::escape(mURLList.first().filename());
190
response=KMessageBox::warningContinueCancel(mParent,
191
i18n("<p>Do you really want to move <b>%1</b> to the trash?</p>").arg(filename),i18n("Trash used as a verb", "Trash File"),KGuiItem(i18n("Trash used as a verb", "&Trash"),"edittrash"));
193
if (response!=KMessageBox::Continue) return;
197
if (mURLList.count()==1) {
198
// If there's only one file, KIO::move will think we want to overwrite
199
// the trash dir with the file to trash, so we add the file name
200
trashURL.addPath(mURLList.first().fileName());
202
KIO::Job* job=KIO::move(mURLList,trashURL);
203
job->setWindow(mParent->topLevelWidget());
204
connect( job, SIGNAL( result(KIO::Job*) ),
205
this, SLOT( slotResult(KIO::Job*) ) );
208
//-FileOpRealDeleteObject----------------------------------------------------------
209
void FileOpRealDeleteObject::operator()() {
211
if (FileOperation::confirmDelete()) {
213
if (mURLList.count()>1) {
214
QStringList fileList;
215
KURL::List::ConstIterator it=mURLList.begin();
216
for (; it!=mURLList.end(); ++it) {
217
fileList.append((*it).filename());
219
response=KMessageBox::warningContinueCancelList(mParent,
220
i18n("Do you really want to delete these files?"),fileList,
221
i18n("Delete Files"),
222
#if KDE_IS_VERSION(3, 3, 0)
225
KGuiItem( i18n( "&Delete" ), "editdelete", i18n( "Delete item(s)" ) )
229
QString filename=QStyleSheet::escape(mURLList.first().filename());
230
response=KMessageBox::warningContinueCancel(mParent,
231
i18n("<p>Do you really want to delete <b>%1</b>?</p>").arg(filename),
233
#if KDE_IS_VERSION(3, 3, 0)
236
KGuiItem( i18n( "&Delete" ), "editdelete", i18n( "Delete item(s)" ) )
240
if (response!=KMessageBox::Continue) return;
244
KIO::Job* removeJob=KIO::del(mURLList,false,true);
245
removeJob->setWindow(mParent->topLevelWidget());
246
connect( removeJob, SIGNAL( result(KIO::Job*) ),
247
this, SLOT( slotResult(KIO::Job*) ) );
251
//-FileOpRenameObject--------------------------------------------------------------
252
void FileOpRenameObject::operator()() {
254
KURL srcURL=mURLList.first();
256
// Prompt for the new filename
257
QString filename=QStyleSheet::escape(srcURL.filename());
258
mNewFilename=KInputDialog::getText(i18n("Renaming File"),
259
i18n("<p>Rename file <b>%1</b> to:</p>").arg(filename),
267
destURL.setFileName(mNewFilename);
268
KIO::Job* job=KIO::move(srcURL,destURL);
269
job->setWindow(mParent->topLevelWidget());
270
connect( job, SIGNAL( result(KIO::Job*) ),
271
this, SLOT( slotResult(KIO::Job*) ) );
275
void FileOpRenameObject::slotResult(KIO::Job* job) {
277
job->showErrorDialog(mParent);
281
emit renamed(mNewFilename);
283
// Let's shoot ourself in the foot...