diff --git a/CMakeLists.txt b/CMakeLists.txt index 3c2645d..54d9b6b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,99 +1,104 @@ cmake_minimum_required(VERSION 3.0) set(KF5_VERSION "5.51.0") # handled by release scripts set(KF5_DEP_VERSION "5.50.0") # handled by release scripts project(KJobWidgets VERSION ${KF5_VERSION}) include(FeatureSummary) find_package(ECM 5.50.0 NO_MODULE) set_package_properties(ECM PROPERTIES TYPE REQUIRED DESCRIPTION "Extra CMake Modules." URL "https://projects.kde.org/projects/kdesupport/extra-cmake-modules") feature_summary(WHAT REQUIRED_PACKAGES_NOT_FOUND FATAL_ON_MISSING_REQUIRED_PACKAGES) set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR}) include(KDEInstallDirs) include(KDEFrameworkCompilerSettings NO_POLICY_SCOPE) include(KDECMakeSettings) include(ECMQtDeclareLoggingCategory) include(ECMPoQmTools) set(REQUIRED_QT_VERSION 5.8.0) find_package(Qt5 ${REQUIRED_QT_VERSION} CONFIG REQUIRED Widgets DBus) if (NOT APPLE) find_package(X11) endif() set(HAVE_X11 ${X11_FOUND}) find_package(KF5CoreAddons ${KF5_DEP_VERSION} REQUIRED) find_package(KF5WidgetsAddons ${KF5_DEP_VERSION} REQUIRED) include(GenerateExportHeader) include(ECMSetupVersion) include(ECMGenerateHeaders) include(ECMAddQch) option(BUILD_QCH "Build API documentation in QCH format (for e.g. Qt Assistant, Qt Creator & KDevelop)" OFF) add_feature_info(QCH ${BUILD_QCH} "API documentation in QCH format (for e.g. Qt Assistant, Qt Creator & KDevelop)") ecm_setup_version(PROJECT VARIABLE_PREFIX KJOBWIDGETS VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/kjobwidgets_version.h" PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/KF5JobWidgetsConfigVersion.cmake" SOVERSION 5) remove_definitions(-DQT_NO_CAST_FROM_ASCII) remove_definitions(-DQT_NO_CAST_FROM_BYTEARRAY) if (IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/po") ecm_install_po_files_as_qm(po) endif() +add_definitions(-DQT_NO_CAST_FROM_ASCII) +add_definitions(-DQT_NO_CAST_TO_ASCII) +add_definitions(-DQT_NO_NARROWING_CONVERSIONS_IN_CONNECT) +add_definitions(-DQT_NO_URL_CAST_FROM_STRING) +add_definitions(-DQT_USE_QSTRINGBUILDER) add_subdirectory(src) if (BUILD_TESTING) add_subdirectory(tests) add_subdirectory(autotests) endif() # create a Config.cmake and a ConfigVersion.cmake file and install them set(CMAKECONFIG_INSTALL_DIR "${KDE_INSTALL_CMAKEPACKAGEDIR}/KF5JobWidgets") if (BUILD_QCH) ecm_install_qch_export( TARGETS KF5JobWidgets_QCH FILE KF5JobWidgetsQchTargets.cmake DESTINATION "${CMAKECONFIG_INSTALL_DIR}" COMPONENT Devel ) set(PACKAGE_INCLUDE_QCHTARGETS "include(\"\${CMAKE_CURRENT_LIST_DIR}/KF5JobWidgetsQchTargets.cmake\")") endif() include(CMakePackageConfigHelpers) configure_package_config_file( "${CMAKE_CURRENT_SOURCE_DIR}/KF5JobWidgetsConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/KF5JobWidgetsConfig.cmake" PATH_VARS KDE_INSTALL_DBUSINTERFACEDIR INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR} ) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/KF5JobWidgetsConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/KF5JobWidgetsConfigVersion.cmake" DESTINATION "${CMAKECONFIG_INSTALL_DIR}" COMPONENT Devel ) install(EXPORT KF5JobWidgetsTargets DESTINATION "${CMAKECONFIG_INSTALL_DIR}" FILE KF5JobWidgetsTargets.cmake NAMESPACE KF5:: ) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/kjobwidgets_version.h DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5} COMPONENT Devel ) install(FILES kjobwidgets.categories DESTINATION ${KDE_INSTALL_CONFDIR}) feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/src/kwidgetjobtracker.cpp b/src/kwidgetjobtracker.cpp index 6ae2e9b..b30c513 100644 --- a/src/kwidgetjobtracker.cpp +++ b/src/kwidgetjobtracker.cpp @@ -1,695 +1,695 @@ /* This file is part of the KDE project Copyright (C) 2000 Matej Koss Copyright (C) 2007 Kevin Ottens Copyright (C) 2007 Rafael Fernández López Copyright (C) 2009 Shaun Reich This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "kwidgetjobtracker.h" #include "kwidgetjobtracker_p.h" #include "kjobtrackerformatters_p.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include void KWidgetJobTracker::Private::_k_showProgressWidget() { if (progressWidgetsToBeShown.isEmpty()) { return; } KJob *job = progressWidgetsToBeShown.dequeue(); // If the job has been unregistered before reaching this point, widget will // return 0. QWidget *widget = q->widget(job); if (widget) { // Don't steal the focus from the current widget (e. g. Kate) widget->setAttribute(Qt::WA_ShowWithoutActivating); widget->show(); } } KWidgetJobTracker::KWidgetJobTracker(QWidget *parent) : KAbstractWidgetJobTracker(parent), d(new Private(parent, this)) { } KWidgetJobTracker::~KWidgetJobTracker() { delete d; } QWidget *KWidgetJobTracker::widget(KJob *job) { return d->progressWidget.value(job, nullptr); } void KWidgetJobTracker::registerJob(KJob *job) { Private::ProgressWidget *vi = new Private::ProgressWidget(job, this, d->parent); vi->jobRegistered = true; vi->setAttribute(Qt::WA_DeleteOnClose); d->progressWidget.insert(job, vi); d->progressWidgetsToBeShown.enqueue(job); KAbstractWidgetJobTracker::registerJob(job); QTimer::singleShot(500, this, SLOT(_k_showProgressWidget())); } void KWidgetJobTracker::unregisterJob(KJob *job) { KAbstractWidgetJobTracker::unregisterJob(job); d->progressWidgetsToBeShown.removeAll(job); KWidgetJobTracker::Private::ProgressWidget *pWidget = d->progressWidget.value(job, nullptr); if (!pWidget) { return; } pWidget->jobRegistered = false; pWidget->deref(); } bool KWidgetJobTracker::keepOpen(KJob *job) const { KWidgetJobTracker::Private::ProgressWidget *pWidget = d->progressWidget.value(job, nullptr); if (!pWidget) { return false; } return pWidget->keepOpenCheck->isChecked(); } void KWidgetJobTracker::infoMessage(KJob *job, const QString &plain, const QString &rich) { KWidgetJobTracker::Private::ProgressWidget *pWidget = d->progressWidget.value(job, nullptr); if (!pWidget) { return; } pWidget->infoMessage(plain, rich); } void KWidgetJobTracker::description(KJob *job, const QString &title, const QPair &field1, const QPair &field2) { KWidgetJobTracker::Private::ProgressWidget *pWidget = d->progressWidget.value(job, nullptr); if (!pWidget) { return; } pWidget->description(title, field1, field2); } void KWidgetJobTracker::totalAmount(KJob *job, KJob::Unit unit, qulonglong amount) { KWidgetJobTracker::Private::ProgressWidget *pWidget = d->progressWidget.value(job, nullptr); if (!pWidget) { return; } pWidget->totalAmount(unit, amount); } void KWidgetJobTracker::processedAmount(KJob *job, KJob::Unit unit, qulonglong amount) { KWidgetJobTracker::Private::ProgressWidget *pWidget = d->progressWidget.value(job, nullptr); if (!pWidget) { return; } pWidget->processedAmount(unit, amount); } void KWidgetJobTracker::percent(KJob *job, unsigned long percent) { KWidgetJobTracker::Private::ProgressWidget *pWidget = d->progressWidget.value(job, nullptr); if (!pWidget) { return; } pWidget->percent(percent); } void KWidgetJobTracker::speed(KJob *job, unsigned long value) { KWidgetJobTracker::Private::ProgressWidget *pWidget = d->progressWidget.value(job, nullptr); if (!pWidget) { return; } pWidget->speed(value); } void KWidgetJobTracker::slotClean(KJob *job) { KWidgetJobTracker::Private::ProgressWidget *pWidget = d->progressWidget.value(job, nullptr); if (!pWidget) { return; } pWidget->slotClean(); } void KWidgetJobTracker::suspended(KJob *job) { KWidgetJobTracker::Private::ProgressWidget *pWidget = d->progressWidget.value(job, nullptr); if (!pWidget) { return; } pWidget->suspended(); } void KWidgetJobTracker::resumed(KJob *job) { KWidgetJobTracker::Private::ProgressWidget *pWidget = d->progressWidget.value(job, nullptr); if (!pWidget) { return; } pWidget->resumed(); } void KWidgetJobTracker::Private::ProgressWidget::ref() { ++refCount; } void KWidgetJobTracker::Private::ProgressWidget::deref() { if (refCount) { --refCount; } if (!refCount) { if (!keepOpenCheck->isChecked()) { closeNow(); } else { slotClean(); } } } void KWidgetJobTracker::Private::ProgressWidget::closeNow() { close(); // It might happen the next scenario: // - Start a job which opens a progress widget. Keep it open. Address job is 0xdeadbeef // - Start a new job, which is given address 0xdeadbeef. A new window is opened. // This one will take much longer to complete. The key 0xdeadbeef on the widget map now // stores the new widget address. // - Close the first progress widget that was opened (and has already finished) while the // last one is still running. We remove its reference on the map. Wrong. // For that reason we have to check if the map stores the widget as the current one. // ereslibre if (tracker->d->progressWidget[job] == this) { tracker->d->progressWidget.remove(job); tracker->d->progressWidgetsToBeShown.removeAll(job); } } bool KWidgetJobTracker::Private::ProgressWidget::eventFilter(QObject *watched, QEvent *event) { // Handle context menu events for the source/dest labels here, so that we are ref()ed while the // menu is exec()ed, to avoid a crash if the job finishes meanwhile. #159621. if ((watched == sourceEdit || watched == destEdit) && event->type() == QEvent::ContextMenu) { ref(); watched->event(event); deref(); return true; } return QWidget::eventFilter(watched, event); } void KWidgetJobTracker::Private::ProgressWidget::infoMessage(const QString &plain, const QString &/*rich*/) { speedLabel->setText(plain); speedLabel->setAlignment(speedLabel->alignment() & ~Qt::TextWordWrap); } void KWidgetJobTracker::Private::ProgressWidget::description(const QString &title, const QPair &field1, const QPair &field2) { setWindowTitle(title); caption = title; sourceInvite->setText( QCoreApplication::translate("KWidgetJobTracker", "%1:", "%1 is the label, we add a ':' to it" ).arg(field1.first)); sourceEdit->setText(field1.second); if (field2.first.isEmpty()) { setDestVisible(false); } else { setDestVisible(true); checkDestination(QUrl::fromUserInput(field2.second)); // path or URL destInvite->setText( QCoreApplication::translate("KWidgetJobTracker", "%1:", "%1 is the label, we add a ':' to it" ).arg(field2.first)); destEdit->setText(field2.second); } } void KWidgetJobTracker::Private::ProgressWidget::totalAmount(KJob::Unit unit, qulonglong amount) { switch (unit) { case KJob::Bytes: totalSizeKnown = true; // size is measured in bytes if (totalSize == amount) { return; } totalSize = amount; if (startTime.isNull()) { startTime.start(); } break; case KJob::Files: if (totalFiles == amount) { return; } totalFiles = amount; showTotals(); break; case KJob::Directories: if (totalDirs == amount) { return; } totalDirs = amount; showTotals(); break; } } void KWidgetJobTracker::Private::ProgressWidget::processedAmount(KJob::Unit unit, qulonglong amount) { QString tmp; switch (unit) { case KJob::Bytes: if (processedSize == amount) { return; } processedSize = amount; if (totalSizeKnown) { //~ singular %1 of %2 complete //~ plural %1 of %2 complete tmp = QCoreApplication::translate("KWidgetJobTracker", "%1 of %2 complete", "", amount) .arg(KJobTrackerFormatters::byteSize(amount)) .arg(KJobTrackerFormatters::byteSize(totalSize)); } else { tmp = KJobTrackerFormatters::byteSize(amount); } sizeLabel->setText(tmp); if (!totalSizeKnown) { // update jumping progressbar progressBar->setValue(amount); } break; case KJob::Directories: if (processedDirs == amount) { return; } processedDirs = amount; //~ singular %1 / %n folder //~ plural %1 / %n folders tmp = QCoreApplication::translate("KWidgetJobTracker", "%1 / %n folder(s)", "", totalDirs).arg(processedDirs); tmp += QLatin1String(" "); //~ singular %1 / %n file //~ plural %1 / %n files tmp += QCoreApplication::translate("KWidgetJobTracker", "%1 / %n file(s)", "", totalFiles).arg(processedFiles); progressLabel->setText(tmp); break; case KJob::Files: if (processedFiles == amount) { return; } processedFiles = amount; if (totalDirs > 1) { //~ singular %1 / %n folder //~ plural %1 / %n folders tmp = QCoreApplication::translate("KWidgetJobTracker", "%1 / %n folder(s)", "", totalDirs).arg(processedDirs); tmp += QLatin1String(" "); } //~ singular %1 / %n file //~ plural %1 / %n files tmp += QCoreApplication::translate("KWidgetJobTracker", "%1 / %n file(s)", "", totalFiles).arg(processedFiles); progressLabel->setText(tmp); } } void KWidgetJobTracker::Private::ProgressWidget::percent(unsigned long percent) { - QString title = caption + " ("; + QString title = caption + QStringLiteral(" ("); if (totalSizeKnown) { title += QCoreApplication::translate("KWidgetJobTracker", "%1% of %2").arg(percent).arg( KJobTrackerFormatters::byteSize(totalSize)); } else if (totalFiles) { //~ singular %1% of %n file //~ plural %1% of %n files title += QCoreApplication::translate("KWidgetJobTracker", "%1% of %n file(s)", "", totalFiles).arg(percent); } else { title += QCoreApplication::translate("KWidgetJobTracker", "%1%").arg(percent); } - title += ')'; + title += QLatin1Char(')'); progressBar->setMaximum(100); progressBar->setValue(percent); setWindowTitle(title); } void KWidgetJobTracker::Private::ProgressWidget::speed(unsigned long value) { if (value == 0) { speedLabel->setText(QCoreApplication::translate("KWidgetJobTracker", "Stalled")); } else { const QString speedStr = KJobTrackerFormatters::byteSize(value); if (totalSizeKnown) { const int remaining = 1000 * (totalSize - processedSize) / value; //~ singular %1/s (%2 remaining) //~ plural %1/s (%2 remaining) speedLabel->setText(QCoreApplication::translate("KWidgetJobTracker", "%1/s (%2 remaining)", "", remaining).arg(speedStr).arg( KJobTrackerFormatters::duration(remaining))); } else { // total size is not known (#24228) speedLabel->setText(QCoreApplication::translate("KWidgetJobTracker", "%1/s", "speed in bytes per second").arg(speedStr)); } } } void KWidgetJobTracker::Private::ProgressWidget::slotClean() { percent(100); cancelClose->setText(QCoreApplication::translate("KWidgetJobTracker", "&Close")); cancelClose->setIcon(QIcon::fromTheme(QStringLiteral("window-close"))); cancelClose->setToolTip(QCoreApplication::translate("KWidgetJobTracker", "Close the current window or document")); openFile->setEnabled(true); if (!totalSizeKnown || totalSize < processedSize) { totalSize = processedSize; } processedAmount(KJob::Bytes, totalSize); keepOpenCheck->setEnabled(false); pauseButton->setEnabled(false); if (!startTime.isNull()) { int s = startTime.elapsed(); if (!s) { s = 1; } speedLabel->setText(QCoreApplication::translate("KWidgetJobTracker", "%1/s (done)").arg( KJobTrackerFormatters::byteSize(1000 * totalSize / s))); } } void KWidgetJobTracker::Private::ProgressWidget::suspended() { pauseButton->setText(QCoreApplication::translate("KWidgetJobTracker", "&Resume")); suspendedProperty = true; } void KWidgetJobTracker::Private::ProgressWidget::resumed() { pauseButton->setText(QCoreApplication::translate("KWidgetJobTracker", "&Pause")); suspendedProperty = false; } void KWidgetJobTracker::Private::ProgressWidget::closeEvent(QCloseEvent *event) { if (jobRegistered && tracker->stopOnClose(job)) { tracker->slotStop(job); } QWidget::closeEvent(event); } void KWidgetJobTracker::Private::ProgressWidget::init() { setWindowIcon(QIcon::fromTheme(QStringLiteral("document-save"), windowIcon())); QVBoxLayout *topLayout = new QVBoxLayout(this); QGridLayout *grid = new QGridLayout(); topLayout->addLayout(grid); const int spacingHint = style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing); grid->addItem(new QSpacerItem(spacingHint, 0), 0, 1); // filenames or action name sourceInvite = new QLabel(QCoreApplication::translate("KWidgetJobTracker", "Source:", "The source url of a job"), this); grid->addWidget(sourceInvite, 0, 0); sourceEdit = new KSqueezedTextLabel(this); sourceEdit->setTextInteractionFlags(Qt::TextSelectableByMouse); sourceEdit->installEventFilter(this); grid->addWidget(sourceEdit, 0, 2); destInvite = new QLabel(QCoreApplication::translate("KWidgetJobTracker", "Destination:", "The destination url of a job"), this); grid->addWidget(destInvite, 1, 0); destEdit = new KSqueezedTextLabel(this); destEdit->setTextInteractionFlags(Qt::TextSelectableByMouse); destEdit->installEventFilter(this); grid->addWidget(destEdit, 1, 2); QHBoxLayout *progressHBox = new QHBoxLayout(); topLayout->addLayout(progressHBox); progressBar = new QProgressBar(this); progressBar->setMaximum(0); // want a jumping progress bar if percent is not emitted progressHBox->addWidget(progressBar); suspendedProperty = false; // processed info QHBoxLayout *hBox = new QHBoxLayout(); topLayout->addLayout(hBox); arrowButton = new QPushButton(this); arrowButton->setMaximumSize(QSize(32, 25)); arrowButton->setIcon(QIcon::fromTheme(QStringLiteral("arrow-down"))); arrowButton->setToolTip(QCoreApplication::translate("KWidgetJobTracker", "Click this to expand the dialog, to show details")); arrowState = Qt::DownArrow; connect(arrowButton, SIGNAL(clicked()), this, SLOT(_k_arrowToggled())); hBox->addWidget(arrowButton); hBox->addStretch(1); KSeparator *separator1 = new KSeparator(Qt::Horizontal, this); topLayout->addWidget(separator1); sizeLabel = new QLabel(this); hBox->addWidget(sizeLabel, 0, Qt::AlignLeft); resumeLabel = new QLabel(this); hBox->addWidget(resumeLabel); pauseButton = new QPushButton(QCoreApplication::translate("KWidgetJobTracker", "&Pause"), this); pauseButton->setVisible(job && (job->capabilities() & KJob::Suspendable)); connect(pauseButton, SIGNAL(clicked()), this, SLOT(_k_pauseResumeClicked())); hBox->addWidget(pauseButton); hBox = new QHBoxLayout(); topLayout->addLayout(hBox); speedLabel = new QLabel(this); hBox->addWidget(speedLabel, 1); speedLabel->hide(); hBox = new QHBoxLayout(); topLayout->addLayout(hBox); progressLabel = new QLabel(this); progressLabel->setAlignment(Qt::AlignLeft); hBox->addWidget(progressLabel); progressLabel->hide(); keepOpenCheck = new QCheckBox(QCoreApplication::translate("KWidgetJobTracker", "&Keep this window open after transfer is complete"), this); connect(keepOpenCheck, SIGNAL(toggled(bool)), this, SLOT(_k_keepOpenToggled(bool))); topLayout->addWidget(keepOpenCheck); keepOpenCheck->hide(); hBox = new QHBoxLayout(); topLayout->addLayout(hBox); openFile = new QPushButton(QCoreApplication::translate("KWidgetJobTracker", "Open &File"), this); connect(openFile, SIGNAL(clicked()), this, SLOT(_k_openFile())); hBox->addWidget(openFile); openFile->setEnabled(false); openFile->hide(); openLocation = new QPushButton(QCoreApplication::translate("KWidgetJobTracker", "Open &Destination"), this); connect(openLocation, SIGNAL(clicked()), this, SLOT(_k_openLocation())); hBox->addWidget(openLocation); openLocation->hide(); hBox->addStretch(1); cancelClose = new QPushButton(this); cancelClose->setText(QCoreApplication::translate("KWidgetJobTracker", "&Cancel")); cancelClose->setIcon(QIcon::fromTheme(QStringLiteral("dialog-cancel"))); connect(cancelClose, SIGNAL(clicked()), this, SLOT(_k_stop())); hBox->addWidget(cancelClose); resize(sizeHint()); setMaximumHeight(sizeHint().height()); setWindowTitle(QCoreApplication::translate("KWidgetJobTracker", "Progress Dialog")); // show something better than kuiserver } void KWidgetJobTracker::Private::ProgressWidget::showTotals() { // Show the totals in the progress label, if we still haven't // processed anything. This is useful when the stat'ing phase // of CopyJob takes a long time (e.g. over networks). if (processedFiles == 0 && processedDirs == 0) { QString tmps; if (totalDirs > 1) // that we have a singular to translate looks weired but is only logical { //~ singular %n folder //~ plural %n folders - tmps = QCoreApplication::translate("KWidgetJobTracker", "%n folder(s)", "", totalDirs) + " "; + tmps = QCoreApplication::translate("KWidgetJobTracker", "%n folder(s)", "", totalDirs) + QStringLiteral(" "); } //~ singular %n file //~ plural %n files tmps += QCoreApplication::translate("KWidgetJobTracker", "%n file(s)", "", totalFiles); progressLabel->setText(tmps); } } void KWidgetJobTracker::Private::ProgressWidget::setDestVisible(bool visible) { // We can't hide the destInvite/destEdit labels, // because it screws up the QGridLayout. if (visible) { destInvite->show(); destEdit->show(); } else { destInvite->hide(); destEdit->hide(); destInvite->setText(QString()); destEdit->setText(QString()); } setMaximumHeight(sizeHint().height()); } void KWidgetJobTracker::Private::ProgressWidget::checkDestination(const QUrl &dest) { bool ok = true; if (dest.isLocalFile()) { const QString path = dest.toLocalFile(); if (path.contains(QDir::tempPath())) { ok = false; // it's in the tmp directory } } if (ok) { openFile->show(); openLocation->show(); keepOpenCheck->show(); setMaximumHeight(sizeHint().height()); location = dest; } } void KWidgetJobTracker::Private::ProgressWidget::_k_keepOpenToggled(bool keepOpen) { if (keepOpen) { Q_ASSERT(!tracker->d->eventLoopLocker); tracker->d->eventLoopLocker = new QEventLoopLocker; } else { delete tracker->d->eventLoopLocker; tracker->d->eventLoopLocker = nullptr; } } void KWidgetJobTracker::Private::ProgressWidget::_k_openFile() { QProcess::startDetached(QStringLiteral("kde-open"), QStringList() << location.toDisplayString()); } void KWidgetJobTracker::Private::ProgressWidget::_k_openLocation() { QProcess::startDetached(QStringLiteral("kde-open"), QStringList() << location.adjusted(QUrl::RemoveFilename).toString()); } void KWidgetJobTracker::Private::ProgressWidget::_k_pauseResumeClicked() { if (jobRegistered && !suspendedProperty) { tracker->slotSuspend(job); } else if (jobRegistered) { tracker->slotResume(job); } } void KWidgetJobTracker::Private::ProgressWidget::_k_stop() { if (jobRegistered) { tracker->slotStop(job); } closeNow(); } void KWidgetJobTracker::Private::ProgressWidget::_k_arrowToggled() { if (arrowState == Qt::DownArrow) { //The arrow is in the down position, dialog is collapsed, expand it and change icon. progressLabel->show(); speedLabel->show(); arrowButton->setIcon(QIcon::fromTheme(QStringLiteral("arrow-up"))); arrowButton->setToolTip(QCoreApplication::translate("KWidgetJobTracker", "Click this to collapse the dialog, to hide details")); arrowState = Qt::UpArrow; } else { //Collapse the dialog progressLabel->hide(); speedLabel->hide(); arrowButton->setIcon(QIcon::fromTheme(QStringLiteral("arrow-down"))); arrowButton->setToolTip(QCoreApplication::translate("KWidgetJobTracker", "Click this to expand the dialog, to show details")); arrowState = Qt::DownArrow; } setMaximumHeight(sizeHint().height()); } #include "moc_kwidgetjobtracker.cpp" #include "moc_kwidgetjobtracker_p.cpp" diff --git a/tests/kjobtrackerstest.cpp b/tests/kjobtrackerstest.cpp index 7ef9e07..19444a3 100644 --- a/tests/kjobtrackerstest.cpp +++ b/tests/kjobtrackerstest.cpp @@ -1,183 +1,183 @@ /** * This file is part of the KDE libraries * Copyright (C) 2007 Kevin Ottens * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License version 2 as published by the Free Software Foundation. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "kjobtrackerstest.h" #include "kdialogjobuidelegate.h" #include #include #include #include #include #include #include #include KTestJob::KTestJob(int numberOfDirs) : KJob(), m_numberOfDirs(numberOfDirs), m_currentSpeed(1000), m_state(Stopped) { setCapabilities(KJob::Killable | KJob::Suspendable); } KTestJob::~KTestJob() { } void KTestJob::start() { connect(&m_timer, SIGNAL(timeout()), this, SLOT(nextStep())); m_state = StatingDirs; m_timer.start(50); emit description(this, QStringLiteral("Copying"), qMakePair(QStringLiteral("Source"), QStringLiteral("file:/src")), qMakePair(QStringLiteral("Destination"), QStringLiteral("file:/dest"))); } void KTestJob::nextStep() { switch (m_state) { case StatingDirs: emit infoMessage(this, QStringLiteral("Initial listing")); stateNextDir(); break; case CreatingDirs: emit infoMessage(this, QStringLiteral("Folder creation")); createNextDir(); break; case CopyingFiles: emit infoMessage(this, QStringLiteral("Actual file copying")); copyNextFile(); break; case Stopped: qDebug() << "Do nothing, we stopped"; } } void KTestJob::stateNextDir() { if (totalAmount(KJob::Directories) == m_numberOfDirs) { m_state = CreatingDirs; return; } - QString directory_name = "dir" + QString::number(totalAmount(KJob::Directories)); + QString directory_name = QStringLiteral("dir") + QString::number(totalAmount(KJob::Directories)); qDebug() << "Stating " << directory_name; setTotalAmount(KJob::Directories, totalAmount(KJob::Directories) + 1); setTotalAmount(KJob::Files, totalAmount(KJob::Directories) * 10); setTotalAmount(KJob::Bytes, totalAmount(KJob::Files) * 1000); emit warning(this, directory_name, directory_name); - emit description(this, QStringLiteral("Stating"), qMakePair(QStringLiteral("Stating"), QString("file:/src/" + directory_name))); + emit description(this, QStringLiteral("Stating"), qMakePair(QStringLiteral("Stating"), QString(QStringLiteral("file:/src/") + directory_name))); } void KTestJob::createNextDir() { if (processedAmount(KJob::Directories) == totalAmount(KJob::Directories)) { m_state = CopyingFiles; return; } - QString directory_name = "dir" + QString::number(processedAmount(KJob::Directories)); + QString directory_name = QStringLiteral("dir") + QString::number(processedAmount(KJob::Directories)); qDebug() << "Creating " << directory_name; setProcessedAmount(KJob::Directories, processedAmount(KJob::Directories) + 1); - emit description(this, QStringLiteral("Creating Dir"), qMakePair(QStringLiteral("Creating"), QString("file:/dest/" + directory_name))); + emit description(this, QStringLiteral("Creating Dir"), qMakePair(QStringLiteral("Creating"), QString(QStringLiteral("file:/dest/") + directory_name))); } void KTestJob::copyNextFile() { if (processedAmount(KJob::Files) == totalAmount(KJob::Files)) { m_state = Stopped; m_timer.stop(); emitResult(); return; } - QString file_name = "dir" + QString::number(processedAmount(KJob::Files) / 10) - + "/file" + QString::number(processedAmount(KJob::Files) % 10); + QString file_name = QStringLiteral("dir") + QString::number(processedAmount(KJob::Files) / 10) + + QStringLiteral("/file") + QString::number(processedAmount(KJob::Files) % 10); qDebug() << "Copying " << file_name; setProcessedAmount(KJob::Files, processedAmount(KJob::Files) + 1); setProcessedAmount(KJob::Bytes, processedAmount(KJob::Bytes) + 1000); - emit description(this, QStringLiteral("Copying"), qMakePair(QStringLiteral("Source"), QString("file:/src/" + file_name)), - qMakePair(QStringLiteral("Destination"), QString("file:/dest/" + file_name))); + emit description(this, QStringLiteral("Copying"), qMakePair(QStringLiteral("Source"), QString(QStringLiteral("file:/src/") + file_name)), + qMakePair(QStringLiteral("Destination"), QString(QStringLiteral("file:/dest/") + file_name))); emitSpeed(m_currentSpeed); } bool KTestJob::doSuspend() { m_timer.stop(); return true; } bool KTestJob::doResume() { m_timer.start(50); return true; } bool KTestJob::doKill() { m_timer.stop(); m_state = Stopped; return true; } int main(int argc, char **argv) { QApplication::setApplicationName(QStringLiteral("kjobtrackerstest")); QApplication app(argc, argv); KTestJob *testJob = new KTestJob(10 /* 100000 bytes to process */); KWidgetJobTracker *tracker1 = new KWidgetJobTracker(); tracker1->registerJob(testJob); QMainWindow *main = new QMainWindow; main->setWindowTitle(QStringLiteral("Mainwindow with statusbar-job-tracker")); main->show(); QStatusBar *statusBar = new QStatusBar(main); KStatusBarJobTracker *tracker2 = new KStatusBarJobTracker(main, true); tracker2->registerJob(testJob); tracker2->setStatusBarMode(KStatusBarJobTracker::ProgressOnly); statusBar->addWidget(tracker2->widget(testJob)); main->setStatusBar(statusBar); KUiServerJobTracker *tracker3 = new KUiServerJobTracker(main); tracker3->registerJob(testJob); KJobWidgets::setWindow(testJob, main); testJob->setUiDelegate(new KDialogJobUiDelegate()); testJob->start(); tracker1->widget(testJob)->show(); tracker2->widget(testJob)->show(); return app.exec(); }