~ubuntu-branches/ubuntu/gutsy/gwenview/gutsy

« back to all changes in this revision

Viewing changes to src/gvcore/fileopobject.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Richard A. Johnson
  • Date: 2006-09-17 23:01:00 UTC
  • mto: This revision was merged to the branch mainline in revision 13.
  • Revision ID: james.westby@ubuntu.com-20060917230100-b1q0jrz9a0v7cdi1
Tags: upstream-1.4.0
ImportĀ upstreamĀ versionĀ 1.4.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
#include <kurlcombobox.h>
37
37
 
38
38
// Local
 
39
#include "deletedialog.h"
39
40
#include "fileoperation.h"
40
41
#include "fileopobject.moc"
41
42
#include "fileoperationconfig.h"
87
88
}
88
89
 
89
90
 
 
91
void FileOpObject::polishJob(KIO::Job* job) {
 
92
        job->setWindow(mParent->topLevelWidget());
 
93
        connect( job, SIGNAL( result(KIO::Job*) ),
 
94
                this, SLOT( slotResult(KIO::Job*) ) );
 
95
}
 
96
 
 
97
 
90
98
//-FileOpCopyToObject--------------------------------------------------------------
91
99
 
92
100
 
113
121
        if (destURL.isEmpty()) return;
114
122
 
115
123
// Copy the file
116
 
        KIO::Job* copyJob=KIO::copy(mURLList,destURL,true);
117
 
        copyJob->setWindow(mParent->topLevelWidget());
118
 
        connect( copyJob, SIGNAL( result(KIO::Job*) ),
119
 
                this, SLOT( slotResult(KIO::Job*) ) );
 
124
        KIO::Job* job=KIO::copy(mURLList,destURL,true);
 
125
        polishJob(job);
120
126
 
121
127
}
122
128
 
147
153
        if (destURL.isEmpty()) return;
148
154
 
149
155
// Copy the file
150
 
        KIO::Job* copyJob=KIO::link(mURLList,destURL,true);
151
 
        copyJob->setWindow(mParent->topLevelWidget());
152
 
        connect( copyJob, SIGNAL( result(KIO::Job*) ),
153
 
                this, SLOT( slotResult(KIO::Job*) ) );
 
156
        KIO::Job* job=KIO::link(mURLList,destURL,true);
 
157
        polishJob(job);
154
158
}
155
159
 
156
160
 
178
182
        if (destURL.isEmpty()) return;
179
183
 
180
184
// Move the file
181
 
        KIO::Job* moveJob=KIO::move(mURLList,destURL,true);
182
 
        moveJob->setWindow(mParent->topLevelWidget());
183
 
        connect( moveJob, SIGNAL( result(KIO::Job*) ),
184
 
                this, SLOT( slotResult(KIO::Job*) ) );
185
 
 
 
185
        KIO::Job* job=KIO::move(mURLList,destURL,true);
 
186
        polishJob(job);
186
187
}
187
188
 
188
189
 
199
200
        KURL newURL(mURLList.first());
200
201
        newURL.addPath(newDir);
201
202
    KIO::Job* job=KIO::mkdir(newURL);
202
 
        job->setWindow(mParent->topLevelWidget());
203
 
 
204
 
        connect( job, SIGNAL(result(KIO::Job*)),
205
 
        this, SLOT( slotResult(KIO::Job*)) );
 
203
        polishJob(job);
 
204
}
 
205
 
 
206
 
 
207
static KIO::Job* createTrashJob(KURL::List lst) {
 
208
        KURL trashURL("trash:/");
 
209
        // Go do it
 
210
        if (lst.count()==1) {
 
211
                // If there's only one file, KIO::move will think we want to overwrite
 
212
                // the trash dir with the file to trash, so we add the file name
 
213
                trashURL.addPath(lst.first().fileName());
 
214
        }
 
215
        return KIO::move(lst, trashURL);
 
216
}
 
217
 
 
218
static KIO::Job* createDeleteJob(KURL::List lst) {
 
219
        return KIO::del(lst, false, true);
 
220
}
 
221
 
 
222
 
 
223
//-FileOpDelObject-----------------------------------------------------------------
 
224
void FileOpDelObject::operator()() {
 
225
        bool shouldDelete;
 
226
        if (FileOperationConfig::confirmDelete()) {
 
227
                DeleteDialog dlg(mParent);
 
228
                dlg.setURLList(mURLList);
 
229
                if (!dlg.exec()) return;
 
230
                shouldDelete = dlg.shouldDelete();
 
231
        } else {
 
232
                shouldDelete = not FileOperationConfig::deleteToTrash();
 
233
        }
 
234
                
 
235
 
 
236
        KIO::Job* job;
 
237
        if (shouldDelete) {
 
238
                job = createDeleteJob(mURLList);
 
239
        } else {
 
240
                job = createTrashJob(mURLList);
 
241
        }
 
242
        polishJob(job);
206
243
}
207
244
 
208
245
 
209
246
//-FileOpTrashObject---------------------------------------------------------------
210
247
void FileOpTrashObject::operator()() {
211
 
        KURL trashURL("trash:/");
212
 
 
213
248
        // Confirm operation
214
249
        if (FileOperationConfig::confirmDelete()) {
215
250
                int response;
229
264
                if (response!=KMessageBox::Continue) return;
230
265
        }
231
266
 
232
 
        // Go do it
233
 
        if (mURLList.count()==1) {
234
 
                // If there's only one file, KIO::move will think we want to overwrite
235
 
                // the trash dir with the file to trash, so we add the file name
236
 
                trashURL.addPath(mURLList.first().fileName());
237
 
        }
238
 
        KIO::Job* job=KIO::move(mURLList,trashURL);
239
 
        job->setWindow(mParent->topLevelWidget());
240
 
        connect( job, SIGNAL( result(KIO::Job*) ),
241
 
                this, SLOT( slotResult(KIO::Job*) ) );
 
267
        KIO::Job* job = createTrashJob(mURLList);
 
268
        polishJob(job);
242
269
}
243
270
 
244
271
//-FileOpRealDeleteObject----------------------------------------------------------
269
296
        }
270
297
 
271
298
        // Delete the file
272
 
        KIO::Job* removeJob=KIO::del(mURLList,false,true);
273
 
        removeJob->setWindow(mParent->topLevelWidget());
274
 
        connect( removeJob, SIGNAL( result(KIO::Job*) ),
275
 
                this, SLOT( slotResult(KIO::Job*) ) );
 
299
        KIO::Job* job = createDeleteJob(mURLList);
 
300
        polishJob(job);
276
301
}
277
302
 
278
303
 
303
328
        KURL destURL=srcURL;
304
329
        destURL.setFileName(mNewFilename);
305
330
        KIO::Job* job=KIO::move(srcURL,destURL);
306
 
        job->setWindow(mParent->topLevelWidget());
307
 
        connect( job, SIGNAL( result(KIO::Job*) ),
308
 
                this, SLOT( slotResult(KIO::Job*) ) );
 
331
        polishJob(job);
309
332
}
310
333
 
311
334