static bool downloadResource (const KUrl& srcUrl, const QString& suggestedName = QString(), QWidget* parent = 0, const KIO::MetaData& metaData = KIO::MetaData()) { const KUrl& destUrl = promptUser(parent, srcUrl, suggestedName); if (!destUrl.isValid()) return false; KIO::Job *job = KIO::file_copy(srcUrl, destUrl); if (!metaData.isEmpty()) job->setMetaData(metaData); job->addMetaData(QL1S("MaxCacheSize"), QL1S("0")); // Don't store in http cache. job->addMetaData(QL1S("cache"), QL1S("cache")); // Use entry from cache if available. job->ui()->setWindow((parent ? parent->window() : 0)); job->ui()->setAutoErrorHandlingEnabled(true); return true; }
static bool downloadResource (const KUrl& srcUrl, const QString& suggestedName = QString(), QWidget* parent = 0, const KIO::MetaData& metaData = KIO::MetaData()) { const QString fileName = suggestedName.isEmpty() ? srcUrl.fileName() : suggestedName; // convert filename to URL using fromPath to avoid trouble with ':' in filenames (#184202) KUrl destUrl = KFileDialog::getSaveFileName(KUrl::fromPath(fileName), QString(), parent); if (!destUrl.isValid()) return false; // Using KIO::copy rather than file_copy, to benefit from "dest already exists" dialogs. KIO::Job *job = KIO::copy(srcUrl, destUrl); if (!metaData.isEmpty()) job->setMetaData(metaData); job->addMetaData(QL1S("MaxCacheSize"), QL1S("0")); // Don't store in http cache. job->addMetaData(QL1S("cache"), QL1S("cache")); // Use entry from cache if available. job->ui()->setWindow((parent ? parent->window() : 0)); job->ui()->setAutoErrorHandlingEnabled(true); return true; }
static bool downloadResource(const KUrl& srcUrl, const KIO::MetaData& metaData = KIO::MetaData(), QWidget * parent = 0, const QString & suggestedName = QString()) { KUrl destUrl; int result = KIO::R_OVERWRITE; const QString fileName((suggestedName.isEmpty() ? srcUrl.fileName() : suggestedName)); do { // follow bug:184202 fixes destUrl = KFileDialog::getSaveFileName(KUrl(KGlobalSettings::downloadPath().append(fileName)), QString(), parent); if (destUrl.isEmpty()) return false; if (destUrl.isLocalFile()) { QFileInfo finfo(destUrl.toLocalFile()); if (finfo.exists()) { QDateTime now = QDateTime::currentDateTime(); QPointer<KIO::RenameDialog> dlg = new KIO::RenameDialog(parent, i18n("Overwrite File?"), srcUrl, destUrl, KIO::RenameDialog_Mode(KIO::M_OVERWRITE | KIO::M_SKIP), -1, finfo.size(), now.toTime_t(), finfo.created().toTime_t(), now.toTime_t(), finfo.lastModified().toTime_t() ); result = dlg->exec(); delete dlg; } } } while (result == KIO::R_CANCEL && destUrl.isValid()); // Save download history DownloadItem *item = rApp->downloadManager()->addDownload(srcUrl.pathOrUrl(), destUrl.pathOrUrl()); if (!KStandardDirs::findExe("kget").isNull() && ReKonfig::kgetDownload()) { //KGet integration: if (!QDBusConnection::sessionBus().interface()->isServiceRegistered("org.kde.kget")) { KToolInvocation::kdeinitExecWait("kget"); } QDBusInterface kget("org.kde.kget", "/KGet", "org.kde.kget.main"); if (!kget.isValid()) return false; QDBusMessage transfer = kget.call(QL1S("addTransfer"), srcUrl.prettyUrl(), destUrl.prettyUrl(), true); if (transfer.arguments().isEmpty()) return true; const QString transferPath = transfer.arguments().first().toString(); item->setKGetTransferDbusPath(transferPath); return true; } KIO::Job *job = KIO::file_copy(srcUrl, destUrl, -1, KIO::Overwrite); if (item) { QObject::connect(job, SIGNAL(percent(KJob *,unsigned long)), item, SLOT(updateProgress(KJob *,unsigned long))); QObject::connect(job, SIGNAL(finished(KJob *)), item, SLOT(onFinished(KJob*))); } if (!metaData.isEmpty()) job->setMetaData(metaData); job->addMetaData(QL1S("MaxCacheSize"), QL1S("0")); // Don't store in http cache. job->addMetaData(QL1S("cache"), QL1S("cache")); // Use entry from cache if available. job->uiDelegate()->setAutoErrorHandlingEnabled(true); return true; }