File indexing completed on 2024-04-14 14:20:37
0001 /* 0002 * Copyright (C) 2004 David Faure <faure@kde.org> 0003 * 0004 * This library is free software; you can redistribute it and/or 0005 * modify it under the terms of the GNU Library General Public 0006 * License version 2 as published by the Free Software Foundation; 0007 * 0008 * This library is distributed in the hope that it will be useful, 0009 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0011 * Library General Public License for more details. 0012 * 0013 * You should have received a copy of the GNU Library General Public License 0014 * along with this library; see the file COPYING.LIB. If not, write to 0015 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0016 * Boston, MA 02110-1301, USA. 0017 */ 0018 0019 #include <QApplication> 0020 #include <QUrl> 0021 #include <QDebug> 0022 #include <kio/netaccess.h> 0023 #include <kio/job.h> 0024 #include <QFile> 0025 #include <QTemporaryFile> 0026 0027 int main(int argc, char **argv) 0028 { 0029 QApplication::setApplicationName("netaccesstest"); 0030 QApplication app(argc, argv); 0031 QUrl srcURL("http://download.kde.org/README"); 0032 QTemporaryFile tmpFile; 0033 0034 if (!tmpFile.open()) { 0035 qCritical() << "temporary file creation failed"; 0036 return 1; 0037 } 0038 0039 QUrl tmpURL(QUrl::fromLocalFile(tmpFile.fileName())); 0040 0041 for (uint i = 0; i < 4; ++i) { 0042 qDebug() << "file_copy"; 0043 KIO::Job *job = KIO::file_copy(srcURL, tmpURL, -1, KIO::Overwrite); 0044 if (!KIO::NetAccess::synchronousRun(job, nullptr)) { 0045 qCritical() << "file_copy failed: " << KIO::NetAccess::lastErrorString(); 0046 return 1; 0047 } else { 0048 QFile f(tmpURL.path()); 0049 if (!f.open(QIODevice::ReadOnly)) { 0050 qCritical() << "Cannot open: " << f.fileName() << ". The error was: " << f.errorString(); 0051 return 2; 0052 } 0053 } 0054 } 0055 0056 return 0; 0057 } 0058