diff --git a/src/core/copyjob.h b/src/core/copyjob.h --- a/src/core/copyjob.h +++ b/src/core/copyjob.h @@ -269,8 +269,6 @@ Q_PRIVATE_SLOT(d_func(), void slotStart()) Q_PRIVATE_SLOT(d_func(), void slotEntries(KIO::Job *, const KIO::UDSEntryList &list)) Q_PRIVATE_SLOT(d_func(), void slotSubError(KIO::ListJob *, KIO::ListJob *)) - Q_PRIVATE_SLOT(d_func(), void slotProcessedSize(KJob *, qulonglong data_size)) - Q_PRIVATE_SLOT(d_func(), void slotTotalSize(KJob *, qulonglong size)) Q_PRIVATE_SLOT(d_func(), void slotReport()) Q_PRIVATE_SLOT(d_func(), void sourceStated(const KIO::UDSEntry &entry, const QUrl &sourceUrl)) diff --git a/src/core/copyjob.cpp b/src/core/copyjob.cpp --- a/src/core/copyjob.cpp +++ b/src/core/copyjob.cpp @@ -1380,7 +1380,7 @@ qCDebug(KIO_COPYJOB_DEBUG) << files.count() << "files remaining"; // Merge metadata from subjob - KIO::Job *kiojob = dynamic_cast(job); + KIO::Job *kiojob = qobject_cast(job); Q_ASSERT(kiojob); m_incomingMetaData += kiojob->metaData(); q->removeSubjob(job); @@ -1702,10 +1702,12 @@ m_bURLDirty = true; } q->addSubjob(newjob); - q->connect(newjob, SIGNAL(processedSize(KJob*,qulonglong)), - SLOT(slotProcessedSize(KJob*,qulonglong))); - q->connect(newjob, SIGNAL(totalSize(KJob*,qulonglong)), - SLOT(slotTotalSize(KJob*,qulonglong))); + q->connect(newjob, &Job::processedSize, q, [this](KJob *job, qulonglong processedSize) { + slotProcessedSize(job, processedSize); + }); + q->connect(newjob, &Job::totalSize, q, [this](KJob *job, qulonglong totalSize) { + slotTotalSize(job, totalSize); + }); } else { // We're done qCDebug(KIO_COPYJOB_DEBUG) << "copyNextFile finished"; @@ -1880,7 +1882,7 @@ int err = job->error(); const QString errText = job->errorText(); // Merge metadata from subjob - KIO::Job *kiojob = dynamic_cast(job); + KIO::Job *kiojob = qobject_cast(job); Q_ASSERT(kiojob); m_incomingMetaData += kiojob->metaData(); q->removeSubjob(job); diff --git a/src/core/global.h b/src/core/global.h --- a/src/core/global.h +++ b/src/core/global.h @@ -246,7 +246,8 @@ ERR_CANNOT_MOVE_INTO_ITSELF = KJob::UserDefinedError + 71, ///< emitted by KIO::move, @since 5.18 ERR_PASSWD_SERVER = KJob::UserDefinedError + 72, ///< returned by SlaveBase::openPasswordDialogV2, @since 5.24 ERR_CANNOT_CREATE_SLAVE = KJob::UserDefinedError + 73, ///< used by Slave::createSlave, @since 5.30 - ERR_FILE_TOO_LARGE_FOR_FAT32 = KJob::UserDefinedError + 74 ///< @since 5.54 + ERR_FILE_TOO_LARGE_FOR_FAT32 = KJob::UserDefinedError + 74, ///< @since 5.52 + ERR_OWNER_DIED = KJob::UserDefinedError + 75, ///< Value used between kuiserver and views when the job owner disappears unexpectedly. It should not be emitted by slaves. @since 5.54 }; /** diff --git a/src/core/job.cpp b/src/core/job.cpp --- a/src/core/job.cpp +++ b/src/core/job.cpp @@ -78,7 +78,7 @@ //qDebug() << "addSubjob(" << jobBase << ") this=" << this; bool ok = KCompositeJob::addSubjob(jobBase); - KIO::Job *job = dynamic_cast(jobBase); + KIO::Job *job = qobject_cast(jobBase); if (ok && job) { // Copy metadata into subjob (e.g. window-id, user-timestamp etc.) Q_D(Job); @@ -114,40 +114,54 @@ void JobPrivate::emitMoving(KIO::Job *job, const QUrl &src, const QUrl &dest) { - emit job->description(job, i18nc("@title job", "Moving"), - qMakePair(i18nc("The source of a file operation", "Source"), url_description_string(src)), - qMakePair(i18nc("The destination of a file operation", "Destination"), url_description_string(dest))); + static const QString s_title = i18nc("@title job", "Moving"); + static const QString s_source = i18nc("The source of a file operation", "Source"); + static const QString s_destination = i18nc("The destination of a file operation", "Destination"); + emit job->description(job, s_title, + qMakePair(s_source, url_description_string(src)), + qMakePair(s_destination, url_description_string(dest))); } void JobPrivate::emitCopying(KIO::Job *job, const QUrl &src, const QUrl &dest) { - emit job->description(job, i18nc("@title job", "Copying"), - qMakePair(i18nc("The source of a file operation", "Source"), url_description_string(src)), - qMakePair(i18nc("The destination of a file operation", "Destination"), url_description_string(dest))); + static const QString s_title = i18nc("@title job", "Copying"); + static const QString s_source = i18nc("The source of a file operation", "Source"); + static const QString s_destination = i18nc("The destination of a file operation", "Destination"); + emit job->description(job, s_title, + qMakePair(s_source, url_description_string(src)), + qMakePair(s_destination, url_description_string(dest))); } void JobPrivate::emitCreatingDir(KIO::Job *job, const QUrl &dir) { - emit job->description(job, i18nc("@title job", "Creating directory"), - qMakePair(i18n("Directory"), url_description_string(dir))); + static const QString s_title = i18nc("@title job", "Creating directory"); + static const QString s_directory = i18n("Directory"); + emit job->description(job, s_title, + qMakePair(s_directory, url_description_string(dir))); } void JobPrivate::emitDeleting(KIO::Job *job, const QUrl &url) { - emit job->description(job, i18nc("@title job", "Deleting"), - qMakePair(i18n("File"), url_description_string(url))); + static const QString s_title = i18nc("@title job", "Deleting"); + static const QString s_file = i18n("File"); + emit job->description(job, s_title, + qMakePair(s_file, url_description_string(url))); } void JobPrivate::emitStating(KIO::Job *job, const QUrl &url) { - emit job->description(job, i18nc("@title job", "Examining"), - qMakePair(i18n("File"), url_description_string(url))); + static const QString s_title = i18nc("@title job", "Examining"); + static const QString s_file = i18n("File"); + emit job->description(job, s_title, + qMakePair(s_file, url_description_string(url))); } void JobPrivate::emitTransferring(KIO::Job *job, const QUrl &url) { - emit job->description(job, i18nc("@title job", "Transferring"), - qMakePair(i18nc("The source of a file operation", "Source"), url_description_string(url))); + static const QString s_title = i18nc("@title job", "Transferring"); + static const QString s_source = i18nc("The source of a file operation", "Source"); + emit job->description(job, s_title, + qMakePair(s_source, url_description_string(url))); } void JobPrivate::emitMounting(KIO::Job *job, const QString &dev, const QString &point) diff --git a/src/core/slaveinterface.cpp b/src/core/slaveinterface.cpp --- a/src/core/slaveinterface.cpp +++ b/src/core/slaveinterface.cpp @@ -45,6 +45,7 @@ : QObject(parent), d_ptr(&dd) { connect(&d_ptr->speed_timer, &QTimer::timeout, this, &SlaveInterface::calcSpeed); + d_ptr->transfer_details.reserve(max_count); } SlaveInterface::~SlaveInterface() @@ -97,36 +98,24 @@ return; } - const qint64 currentTime = QDateTime::currentMSecsSinceEpoch(); - const qint64 diff = currentTime - d->start_time; - if (diff - d->last_time >= 900) { - d->last_time = diff; - if (d->nums == max_nums) { - // let's hope gcc can optimize that well enough - // otherwise I'd try memcpy :) - for (unsigned int i = 1; i < max_nums; ++i) { - d->times[i - 1] = d->times[i]; - d->sizes[i - 1] = d->sizes[i]; - } - d->nums--; - } - d->times[d->nums] = diff; - d->sizes[d->nums++] = d->filesize - d->offset; - - KIO::filesize_t lspeed = 1000 * (d->sizes[d->nums - 1] - d->sizes[0]) / (d->times[d->nums - 1] - d->times[0]); + // Note for future reference: A list is maintained for sizes and times. + // Minimum list size is 1 and maximum list size is 8. Delta is calculated + // using first and last item from the list. -//qDebug() << (long)d->filesize << diff -// << long(d->sizes[d->nums-1] - d->sizes[0]) -// << d->times[d->nums-1] - d->times[0] -// << long(lspeed) << double(d->filesize) / diff -// << convertSize(lspeed) -// << convertSize(long(double(d->filesize) / diff) * 1000); + const qint64 elapsed_time = d->elapsed_timer.elapsed(); + if (elapsed_time >= 900) { + if (d->transfer_details.count() == max_count) { + d->transfer_details.removeFirst(); + } + const SlaveInterfacePrivate::TransferInfo first = d->transfer_details.first(); + const SlaveInterfacePrivate::TransferInfo last = {elapsed_time, (d->filesize - d->offset)}; + KIO::filesize_t lspeed = 1000 * (last.size - first.size) / (last.time - first.time); if (!lspeed) { - d->nums = 1; - d->times[0] = diff; - d->sizes[0] = d->filesize - d->offset; + d->transfer_details.clear(); } + d->transfer_details.append(last); + emit speed(lspeed); } } @@ -209,13 +198,10 @@ } case INF_TOTAL_SIZE: { KIO::filesize_t size = readFilesize_t(stream); - d->start_time = QDateTime::currentMSecsSinceEpoch(); - d->last_time = 0; d->filesize = d->offset; - d->sizes[0] = d->filesize - d->offset; - d->times[0] = 0; - d->nums = 1; + d->transfer_details.append({0, 0}); d->speed_timer.start(1000); + d->elapsed_timer.start(); d->slave_calcs_speed = false; emit totalSize(size); break; diff --git a/src/core/slaveinterface_p.h b/src/core/slaveinterface_p.h --- a/src/core/slaveinterface_p.h +++ b/src/core/slaveinterface_p.h @@ -29,17 +29,19 @@ #include #include #include +#include +#include #include "kiocoredebug.h" -static const unsigned int max_nums = 8; +static const unsigned int max_count = 8; class KIO::SlaveInterfacePrivate { public: SlaveInterfacePrivate() - : connection(nullptr), filesize(0), offset(0), last_time(0), start_time(0), - nums(0), slave_calcs_speed(false) + : connection(nullptr), filesize(0), offset(0), + slave_calcs_speed(false) { } virtual ~SlaveInterfacePrivate() @@ -53,13 +55,14 @@ // We need some metadata here for our SSL code in messageBox() and for sslMetaData(). MetaData sslMetaData; - KIO::filesize_t sizes[max_nums]; - qint64 times[max_nums]; + struct TransferInfo { + qint64 time; + KIO::filesize_t size; + }; + QVector transfer_details; + QElapsedTimer elapsed_timer; KIO::filesize_t filesize, offset; - size_t last_time; - qint64 start_time; - uint nums; bool slave_calcs_speed; void slotHostInfo(const QHostInfo &info); diff --git a/src/widgets/krun.cpp b/src/widgets/krun.cpp --- a/src/widgets/krun.cpp +++ b/src/widgets/krun.cpp @@ -1418,6 +1418,19 @@ { if (b) { d->m_externalBrowser = KConfigGroup(KSharedConfig::openConfig(), "General").readEntry("BrowserApplication"); + + // If a default browser isn't set in kdeglobals, fall back to mimeapps.list + if (! d->m_externalBrowser.isEmpty()) { + return; + } + + KSharedConfig::Ptr profile = KSharedConfig::openConfig(QStringLiteral("mimeapps.list"), KConfig::NoGlobals, QStandardPaths::GenericConfigLocation); + KConfigGroup defaultApps(profile, "Default Applications"); + + d->m_externalBrowser = defaultApps.readEntry("x-scheme-handler/https"); + if (d->m_externalBrowser.isEmpty()) { + d->m_externalBrowser = defaultApps.readEntry("x-scheme-handler/http"); + } } else { d->m_externalBrowser.clear(); }