5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 #include "process_copy.h"
22 #include "progresswidget.h"
25 #include <QMessageBox>
30 CopyProcess::CopyProcess(const QString
&source
, const QString
&destination
, ProgressWidget
*progress
):
33 destination(destination
),
38 bool CopyProcess::run()
41 // progress->setInfo(tr("Copying file..."));
44 connect(this, SIGNAL(finished()), &loop
, SLOT(quit()));
45 QTimer::singleShot(500, this, SLOT(onTimer()));
51 void CopyProcess::onTimer()
55 QFile
sourceFile(source
);
56 int blocks
= (sourceFile
.size() + BLKSIZE
- 1) / BLKSIZE
;
57 progress
->setMaximum(blocks
-1);
59 if (sourceFile
.open(QIODevice::ReadOnly
)) {
60 QFile
destinationFile(destination
);
61 if (destinationFile
.open(QIODevice::ReadWrite
)) {
62 // progress->addText(tr("Writing file: "));
63 for (int i
=0; i
<blocks
; i
++) {
64 int read
= sourceFile
.read(buf
, BLKSIZE
);
65 if (destinationFile
.write(buf
, read
) == read
) {
66 destinationFile
.flush();
67 progress
->setValue(i
);
70 QMessageBox::warning(NULL
, tr("Error"), tr("Write error"));
75 destinationFile
.close();
78 QMessageBox::warning(NULL
, tr("Error"),tr("Cannot write %1 (reason: %2)").arg(destinationFile
.fileName()).arg(sourceFile
.errorString()));
83 QMessageBox::warning(NULL
, tr("Error"),tr("Cannot open %1 (reason: %2)").arg(sourceFile
.fileName()).arg(sourceFile
.errorString()));
89 progress
->lock(false);