Advance Wayland and KDE package bring-up
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
# tests need dbus due to KUiServerJobTracker
|
||||
if (HAVE_QTDBUS)
|
||||
include(ECMMarkAsTest)
|
||||
|
||||
find_package(Qt6 ${REQUIRED_QT_VERSION} CONFIG REQUIRED Test)
|
||||
|
||||
macro(kjobwidgets_executable_tests)
|
||||
foreach(_testname ${ARGN})
|
||||
add_executable(${_testname} ${_testname}.cpp)
|
||||
target_link_libraries(${_testname} Qt6::Test KF6::JobWidgets KF6::WidgetsAddons)
|
||||
ecm_mark_as_test(${_testname})
|
||||
endforeach(_testname)
|
||||
endmacro()
|
||||
|
||||
kjobwidgets_executable_tests(kjobtrackerstest)
|
||||
|
||||
set(kjobcreator_SRCS kjobcreator.cpp)
|
||||
qt_wrap_ui(kjobcreator_SRCS kjobcreator.ui)
|
||||
add_executable(kjobcreator ${kjobcreator_SRCS})
|
||||
target_link_libraries(kjobcreator Qt6::Widgets KF6::JobWidgets)
|
||||
ecm_mark_as_test(kjobcreator)
|
||||
endif()
|
||||
@@ -0,0 +1,338 @@
|
||||
/*
|
||||
SPDX-FileCopyrightText: 2021 Kai Uwe Broulik <kde@broulik.de>
|
||||
|
||||
SPDX-License-Identifier: LGPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#include "kjobcreator.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QIcon>
|
||||
#include <QPushButton>
|
||||
|
||||
#include <KUiServerJobTracker>
|
||||
#include <KUiServerV2JobTracker>
|
||||
#include <KWidgetJobTracker>
|
||||
|
||||
#include <limits>
|
||||
|
||||
TestJob::TestJob(QObject *parent)
|
||||
: KJob(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void TestJob::start()
|
||||
{
|
||||
m_started = true;
|
||||
}
|
||||
|
||||
bool TestJob::started() const
|
||||
{
|
||||
return m_started;
|
||||
}
|
||||
|
||||
void TestJob::finish()
|
||||
{
|
||||
emitResult();
|
||||
}
|
||||
|
||||
void TestJob::setPercentage(int percent)
|
||||
{
|
||||
setPercent(percent);
|
||||
}
|
||||
|
||||
void TestJob::setProcessedMiB(double bytes)
|
||||
{
|
||||
setProcessedAmount(KJob::Bytes, bytes * 1024 * 1024);
|
||||
}
|
||||
|
||||
void TestJob::setTotalMiB(double bytes)
|
||||
{
|
||||
setTotalAmount(KJob::Bytes, bytes * 1024 * 1024);
|
||||
}
|
||||
|
||||
void TestJob::setProcessedFiles(int files)
|
||||
{
|
||||
setProcessedAmount(KJob::Files, files);
|
||||
}
|
||||
|
||||
void TestJob::setTotalFiles(int files)
|
||||
{
|
||||
setTotalAmount(KJob::Files, files);
|
||||
}
|
||||
|
||||
void TestJob::setProcessedDirectories(int directories)
|
||||
{
|
||||
setProcessedAmount(KJob::Directories, directories);
|
||||
}
|
||||
|
||||
void TestJob::setTotalDirectories(int directories)
|
||||
{
|
||||
setTotalAmount(KJob::Directories, directories);
|
||||
}
|
||||
|
||||
void TestJob::setProcessedItems(int items)
|
||||
{
|
||||
setProcessedAmount(KJob::Items, items);
|
||||
}
|
||||
|
||||
void TestJob::setTotalItems(int items)
|
||||
{
|
||||
setTotalAmount(KJob::Items, items);
|
||||
}
|
||||
|
||||
void TestJob::setSpeedMiB(double speed)
|
||||
{
|
||||
emitSpeed(speed * 1024 * 1024);
|
||||
}
|
||||
|
||||
void TestJob::setErrorState(int errorCode, const QString &errorTest)
|
||||
{
|
||||
setError(errorCode);
|
||||
setErrorText(errorTest);
|
||||
}
|
||||
|
||||
void TestJob::setSuspendable(bool suspendable)
|
||||
{
|
||||
auto caps = capabilities();
|
||||
caps.setFlag(KJob::Suspendable, suspendable);
|
||||
setCapabilities(caps);
|
||||
}
|
||||
|
||||
void TestJob::setKillable(bool killable)
|
||||
{
|
||||
auto caps = capabilities();
|
||||
caps.setFlag(KJob::Killable, killable);
|
||||
setCapabilities(caps);
|
||||
}
|
||||
|
||||
bool TestJob::doKill()
|
||||
{
|
||||
// TODO add checkbox for testing what happens when you try to kill a job that refuses?
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TestJob::doSuspend()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TestJob::doResume()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
TestDialog::TestDialog(QWidget *parent)
|
||||
: QDialog(parent)
|
||||
{
|
||||
m_ui.setupUi(this);
|
||||
|
||||
m_ui.desktopEntry->setText(QGuiApplication::desktopFileName());
|
||||
|
||||
m_ui.processedBytes->setMaximum(std::numeric_limits<double>::max());
|
||||
m_ui.totalBytes->setMaximum(m_ui.processedBytes->maximum());
|
||||
m_ui.processedFiles->setMaximum(std::numeric_limits<int>::max());
|
||||
m_ui.totalFiles->setMaximum(m_ui.processedFiles->maximum());
|
||||
m_ui.processedDirectories->setMaximum(std::numeric_limits<int>::max());
|
||||
m_ui.totalDirectories->setMaximum(m_ui.processedDirectories->maximum());
|
||||
m_ui.processedItems->setMaximum(std::numeric_limits<int>::max());
|
||||
m_ui.totalItems->setMaximum(m_ui.processedItems->maximum());
|
||||
|
||||
m_ui.speed->setMaximum(std::numeric_limits<double>::max());
|
||||
|
||||
m_ui.createButton->setIcon(QIcon::fromTheme(QStringLiteral("document-new")));
|
||||
m_ui.startButton->setIcon(QIcon::fromTheme(QStringLiteral("media-playback-start")));
|
||||
m_ui.suspendButton->setIcon(QIcon::fromTheme(QStringLiteral("media-playback-pause")));
|
||||
m_ui.killButton->setIcon(QIcon::fromTheme(QStringLiteral("media-playback-stop")));
|
||||
m_ui.finishButton->setIcon(QIcon::fromTheme(QStringLiteral("view-task")));
|
||||
|
||||
updateUiState();
|
||||
|
||||
connect(m_ui.desktopEntry, &QLineEdit::editingFinished, this, [this] {
|
||||
QGuiApplication::setDesktopFileName(m_ui.desktopEntry->text());
|
||||
updateUiState();
|
||||
});
|
||||
|
||||
connect(m_ui.destUrl, &QLineEdit::editingFinished, this, &TestDialog::updateJob);
|
||||
|
||||
connect(m_ui.emitDescriptionButton, &QPushButton::clicked, this, [this] {
|
||||
Q_EMIT m_job->description(m_job,
|
||||
m_ui.title->text(),
|
||||
qMakePair(m_ui.descriptionLabel1->text(), m_ui.descriptionValue1->text()),
|
||||
qMakePair(m_ui.descriptionLabel2->text(), m_ui.descriptionValue2->text()));
|
||||
});
|
||||
|
||||
connect(m_ui.percent, &QSlider::valueChanged, this, &TestDialog::updateJob);
|
||||
connect(m_ui.processedBytes, qOverload<double>(&QDoubleSpinBox::valueChanged), this, &TestDialog::updateJob);
|
||||
connect(m_ui.totalBytes, qOverload<double>(&QDoubleSpinBox::valueChanged), this, &TestDialog::updateJob);
|
||||
connect(m_ui.processedFiles, qOverload<int>(&QSpinBox::valueChanged), this, &TestDialog::updateJob);
|
||||
connect(m_ui.totalFiles, qOverload<int>(&QSpinBox::valueChanged), this, &TestDialog::updateJob);
|
||||
connect(m_ui.processedDirectories, qOverload<int>(&QSpinBox::valueChanged), this, &TestDialog::updateJob);
|
||||
connect(m_ui.totalDirectories, qOverload<int>(&QSpinBox::valueChanged), this, &TestDialog::updateJob);
|
||||
connect(m_ui.processedItems, qOverload<int>(&QSpinBox::valueChanged), this, &TestDialog::updateJob);
|
||||
connect(m_ui.totalItems, qOverload<int>(&QSpinBox::valueChanged), this, &TestDialog::updateJob);
|
||||
connect(m_ui.speed, qOverload<double>(&QDoubleSpinBox::valueChanged), this, &TestDialog::updateJob);
|
||||
|
||||
connect(m_ui.infoMessage, &QLineEdit::returnPressed, m_ui.emitInfoMessage, &QPushButton::click);
|
||||
connect(m_ui.emitInfoMessage, &QPushButton::clicked, this, [this] {
|
||||
Q_EMIT m_job->infoMessage(m_job, m_ui.infoMessage->text());
|
||||
});
|
||||
|
||||
connect(m_ui.errorCombo, qOverload<int>(&QComboBox::activated), this, &TestDialog::updateJob);
|
||||
connect(m_ui.errorText, &QLineEdit::editingFinished, this, &TestDialog::updateJob);
|
||||
|
||||
connect(m_ui.suspendableCheck, &QCheckBox::toggled, this, &TestDialog::updateJob);
|
||||
connect(m_ui.killableCheck, &QCheckBox::toggled, this, &TestDialog::updateJob);
|
||||
|
||||
connect(m_ui.createButton, &QPushButton::clicked, this, [this] {
|
||||
Q_ASSERT(!m_job);
|
||||
m_job = new TestJob(this);
|
||||
connect(m_job, &KJob::finished, this, [this] {
|
||||
m_job = nullptr;
|
||||
m_registeredWithWidgetTracker = false;
|
||||
m_registeredWithUiServerTracker = false;
|
||||
m_registeredWithUiServerV2Tracker = false;
|
||||
updateUiState();
|
||||
});
|
||||
connect(m_job, &KJob::suspended, this, &TestDialog::updateUiState);
|
||||
connect(m_job, &KJob::resumed, this, &TestDialog::updateUiState);
|
||||
|
||||
// KJob auto-calculates percent based on processed/total amount, so sync that back into the UI
|
||||
connect(m_job, &KJob::percentChanged, this, [this](KJob *job, unsigned long percent) {
|
||||
Q_UNUSED(job);
|
||||
m_ui.percent->setValue(percent);
|
||||
});
|
||||
|
||||
updateJob();
|
||||
updateUiState();
|
||||
});
|
||||
connect(m_ui.startButton, &QPushButton::clicked, this, [this] {
|
||||
m_job->start();
|
||||
updateUiState();
|
||||
});
|
||||
connect(m_ui.suspendButton, &QPushButton::clicked, this, [this] {
|
||||
if (m_job->isSuspended()) {
|
||||
m_job->resume();
|
||||
} else {
|
||||
m_job->suspend();
|
||||
}
|
||||
});
|
||||
connect(m_ui.killButton, &QPushButton::clicked, this, [this] {
|
||||
m_job->kill();
|
||||
});
|
||||
connect(m_ui.finishButton, &QPushButton::clicked, this, [this] {
|
||||
m_job->finish();
|
||||
});
|
||||
|
||||
connect(m_ui.registerKWidgetJobTracker, &QPushButton::clicked, this, [this] {
|
||||
if (!m_widgetTracker) {
|
||||
// not passing "parent" so it spawns a new window
|
||||
m_widgetTracker.reset(new KWidgetJobTracker(nullptr));
|
||||
}
|
||||
m_widgetTracker->registerJob(m_job.data());
|
||||
m_registeredWithWidgetTracker = true;
|
||||
updateUiState();
|
||||
});
|
||||
connect(m_ui.registerKUIServerJobTracker, &QPushButton::clicked, this, [this] {
|
||||
if (!m_uiServerTracker) {
|
||||
m_uiServerTracker.reset(new KUiServerJobTracker(nullptr));
|
||||
}
|
||||
m_uiServerTracker->registerJob(m_job.data());
|
||||
m_registeredWithUiServerTracker = true;
|
||||
updateUiState();
|
||||
});
|
||||
connect(m_ui.registerKUIServerV2JobTracker, &QPushButton::clicked, this, [this] {
|
||||
if (!m_uiServerV2Tracker) {
|
||||
m_uiServerV2Tracker.reset(new KUiServerV2JobTracker(nullptr));
|
||||
}
|
||||
m_uiServerV2Tracker->registerJob(m_job.data());
|
||||
m_registeredWithUiServerV2Tracker = true;
|
||||
updateUiState();
|
||||
});
|
||||
}
|
||||
|
||||
TestDialog::~TestDialog() = default;
|
||||
|
||||
void TestDialog::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
if (m_job) {
|
||||
m_job->kill(KJob::EmitResult);
|
||||
}
|
||||
}
|
||||
|
||||
void TestDialog::updateUiState()
|
||||
{
|
||||
m_ui.destUrl->setEnabled(m_job);
|
||||
|
||||
m_ui.emitDescriptionButton->setEnabled(m_job);
|
||||
m_ui.emitInfoMessage->setEnabled(m_job);
|
||||
|
||||
m_ui.processedBytes->setEnabled(m_job);
|
||||
m_ui.totalBytes->setEnabled(m_job);
|
||||
m_ui.processedFiles->setEnabled(m_job);
|
||||
m_ui.totalFiles->setEnabled(m_job);
|
||||
m_ui.processedDirectories->setEnabled(m_job);
|
||||
m_ui.totalDirectories->setEnabled(m_job);
|
||||
m_ui.processedItems->setEnabled(m_job);
|
||||
m_ui.totalItems->setEnabled(m_job);
|
||||
|
||||
m_ui.percent->setEnabled(m_job);
|
||||
m_ui.speed->setEnabled(m_job);
|
||||
m_ui.errorCombo->setEnabled(m_job);
|
||||
m_ui.errorText->setEnabled(m_job);
|
||||
|
||||
m_ui.createButton->setEnabled(!m_job);
|
||||
m_ui.startButton->setEnabled(m_job && !m_job->started());
|
||||
m_ui.suspendButton->setEnabled(m_job);
|
||||
m_ui.suspendButton->setChecked(m_job && m_job->isSuspended());
|
||||
m_ui.killButton->setEnabled(m_job);
|
||||
m_ui.finishButton->setEnabled(m_job);
|
||||
|
||||
m_ui.registerKWidgetJobTracker->setEnabled(m_job && !m_registeredWithWidgetTracker);
|
||||
m_ui.registerKUIServerJobTracker->setEnabled(m_job && !m_registeredWithUiServerTracker);
|
||||
m_ui.registerKUIServerV2JobTracker->setEnabled(m_job && !m_registeredWithUiServerV2Tracker && !QGuiApplication::desktopFileName().isEmpty());
|
||||
}
|
||||
|
||||
void TestDialog::updateJob()
|
||||
{
|
||||
if (!m_job) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_job->setProperty("destUrl", m_ui.destUrl->text());
|
||||
m_job->setProperty("immediateProgressReporting", m_ui.immediateCheck->isChecked());
|
||||
m_job->setFinishedNotificationHidden(m_ui.transientCheck->isChecked());
|
||||
|
||||
m_job->setPercentage(m_ui.percent->value());
|
||||
|
||||
m_job->setProcessedMiB(m_ui.processedBytes->value());
|
||||
m_job->setTotalMiB(m_ui.totalBytes->value());
|
||||
m_job->setProcessedFiles(m_ui.processedFiles->value());
|
||||
m_job->setTotalFiles(m_ui.totalFiles->value());
|
||||
m_job->setProcessedDirectories(m_ui.processedDirectories->value());
|
||||
m_job->setTotalDirectories(m_ui.totalDirectories->value());
|
||||
m_job->setProcessedItems(m_ui.processedItems->value());
|
||||
m_job->setTotalItems(m_ui.totalItems->value());
|
||||
|
||||
m_job->setSpeedMiB(m_ui.speed->value());
|
||||
|
||||
m_job->setErrorState(m_ui.errorCombo->currentIndex(), m_ui.errorText->text());
|
||||
|
||||
m_job->setSuspendable(m_ui.suspendableCheck->isChecked());
|
||||
m_job->setKillable(m_ui.killableCheck->isChecked());
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
app.setApplicationName(QStringLiteral("kjobcreator"));
|
||||
app.setDesktopFileName(QStringLiteral("org.kde.dolphin"));
|
||||
|
||||
TestDialog dialog;
|
||||
dialog.show();
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
||||
#include "moc_kjobcreator.cpp"
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
SPDX-FileCopyrightText: 2021 Kai Uwe Broulik <kde@broulik.de>
|
||||
|
||||
SPDX-License-Identifier: LGPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#ifndef KJOBCREATOR_H
|
||||
#define KJOBCREATOR_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QPointer>
|
||||
#include <QScopedPointer>
|
||||
|
||||
#include <KJob>
|
||||
|
||||
#include "ui_kjobcreator.h"
|
||||
|
||||
class KWidgetJobTracker;
|
||||
class KUiServerJobTracker;
|
||||
class KUiServerV2JobTracker;
|
||||
|
||||
class TestJob : public KJob
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TestJob(QObject *parent = nullptr);
|
||||
|
||||
void start() override;
|
||||
bool started() const;
|
||||
|
||||
void finish();
|
||||
|
||||
void setPercentage(int percent);
|
||||
|
||||
void setProcessedMiB(double bytes);
|
||||
void setTotalMiB(double bytes);
|
||||
void setProcessedFiles(int files);
|
||||
void setTotalFiles(int files);
|
||||
void setProcessedDirectories(int directories);
|
||||
void setTotalDirectories(int directories);
|
||||
void setProcessedItems(int items);
|
||||
void setTotalItems(int items);
|
||||
|
||||
void setSpeedMiB(double speed);
|
||||
|
||||
void setErrorState(int errorCode, const QString &errorText);
|
||||
|
||||
void setKillable(bool killable);
|
||||
void setSuspendable(bool suspendable);
|
||||
|
||||
protected:
|
||||
bool doKill() override;
|
||||
bool doSuspend() override;
|
||||
bool doResume() override;
|
||||
|
||||
private:
|
||||
bool m_started = false;
|
||||
};
|
||||
|
||||
class TestDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TestDialog(QWidget *parent = nullptr);
|
||||
~TestDialog() override;
|
||||
|
||||
protected:
|
||||
void closeEvent(QCloseEvent *event) override;
|
||||
|
||||
private:
|
||||
void updateUiState();
|
||||
void updateJob();
|
||||
|
||||
Ui_KJobCreator m_ui;
|
||||
|
||||
QPointer<TestJob> m_job;
|
||||
|
||||
QScopedPointer<KWidgetJobTracker> m_widgetTracker;
|
||||
bool m_registeredWithWidgetTracker = false;
|
||||
QScopedPointer<KUiServerJobTracker> m_uiServerTracker;
|
||||
bool m_registeredWithUiServerTracker = false;
|
||||
QScopedPointer<KUiServerV2JobTracker> m_uiServerV2Tracker;
|
||||
bool m_registeredWithUiServerV2Tracker = false;
|
||||
};
|
||||
|
||||
#endif // KJOBCREATOR_H
|
||||
@@ -0,0 +1,507 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>KJobCreator</class>
|
||||
<widget class="QDialog" name="KJobCreator">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>566</width>
|
||||
<height>644</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>KJobCreator</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QFormLayout" name="formLayout_2">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_10">
|
||||
<property name="text">
|
||||
<string>Desktop Entry</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="desktopEntry"/>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>DestUrl</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLineEdit" name="destUrl"/>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLineEdit" name="descriptionLabel1">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="placeholderText">
|
||||
<string>Label 1</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QLineEdit" name="descriptionValue1">
|
||||
<property name="placeholderText">
|
||||
<string>Description 1</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<widget class="QLineEdit" name="descriptionLabel2">
|
||||
<property name="placeholderText">
|
||||
<string>Label 2</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<widget class="QLineEdit" name="descriptionValue2">
|
||||
<property name="placeholderText">
|
||||
<string>Description 2</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="1">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_5">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="emitDescriptionButton">
|
||||
<property name="text">
|
||||
<string>Emit &Description</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="8" column="0">
|
||||
<widget class="QLabel" name="label_8">
|
||||
<property name="text">
|
||||
<string>Percent</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="1">
|
||||
<widget class="QSlider" name="percent">
|
||||
<property name="maximum">
|
||||
<number>100</number>
|
||||
</property>
|
||||
<property name="tracking">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="tickInterval">
|
||||
<number>1</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="9" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Bytes</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="9" column="1">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QDoubleSpinBox" name="processedBytes">
|
||||
<property name="suffix">
|
||||
<string> MiB</string>
|
||||
</property>
|
||||
<property name="decimals">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<double>-1.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="bytesOfLabel">
|
||||
<property name="text">
|
||||
<string>of</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDoubleSpinBox" name="totalBytes">
|
||||
<property name="suffix">
|
||||
<string> MiB</string>
|
||||
</property>
|
||||
<property name="decimals">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<double>-1.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="14" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Speed</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="14" column="1">
|
||||
<widget class="QDoubleSpinBox" name="speed">
|
||||
<property name="suffix">
|
||||
<string> MiB/s</string>
|
||||
</property>
|
||||
<property name="decimals">
|
||||
<number>6</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="15" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>Info Message</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="15" column="1">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="infoMessage"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="emitInfoMessage">
|
||||
<property name="text">
|
||||
<string>Emit</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="17" column="0">
|
||||
<widget class="QLabel" name="label_7">
|
||||
<property name="text">
|
||||
<string>Error</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="17" column="1">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_7">
|
||||
<item>
|
||||
<widget class="QComboBox" name="errorCombo">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>No Error</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>User Canceled</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Error</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="errorText">
|
||||
<property name="placeholderText">
|
||||
<string>Error message</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Title</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QLineEdit" name="title">
|
||||
<property name="text">
|
||||
<string>Test Job</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="11" column="1">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<widget class="QSpinBox" name="processedFiles"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="filesOfLabel">
|
||||
<property name="text">
|
||||
<string>of</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="totalFiles"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="11" column="0">
|
||||
<widget class="QLabel" name="label_9">
|
||||
<property name="text">
|
||||
<string>Files</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="18" column="1">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_8">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="suspendableCheck">
|
||||
<property name="text">
|
||||
<string>Suspendable</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="killableCheck">
|
||||
<property name="text">
|
||||
<string>Killable</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="immediateCheck">
|
||||
<property name="text">
|
||||
<string>Immediate</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="transientCheck">
|
||||
<property name="text">
|
||||
<string>Transient</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="12" column="0">
|
||||
<widget class="QLabel" name="label_11">
|
||||
<property name="text">
|
||||
<string>Directories</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="13" column="0">
|
||||
<widget class="QLabel" name="label_12">
|
||||
<property name="text">
|
||||
<string>Items</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="12" column="1">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_9">
|
||||
<item>
|
||||
<widget class="QSpinBox" name="processedDirectories"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="directoriesOfLabel">
|
||||
<property name="text">
|
||||
<string>of</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="totalDirectories"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="13" column="1">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_10">
|
||||
<item>
|
||||
<widget class="QSpinBox" name="processedItems"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="itemsOfLabel">
|
||||
<property name="text">
|
||||
<string>of</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="totalItems"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QFrame" name="frame_2">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::HLine</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="text">
|
||||
<string>Register with</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="registerKWidgetJobTracker">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>KWidgetJobTracker</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="registerKUIServerJobTracker">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>KUIServerJobTracker</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="registerKUIServerV2JobTracker">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>KUIServerV2JobTracke&r</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QFrame" name="frame">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::HLine</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_6">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="createButton">
|
||||
<property name="text">
|
||||
<string>&Create</string>
|
||||
</property>
|
||||
<property name="default">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="startButton">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&Start</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="suspendButton">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Sus&pend</string>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="killButton">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&Kill</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="finishButton">
|
||||
<property name="text">
|
||||
<string>Finish</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -0,0 +1,179 @@
|
||||
/*
|
||||
This file is part of the KDE libraries
|
||||
SPDX-FileCopyrightText: 2007 Kevin Ottens <ervin@kde.org>
|
||||
|
||||
SPDX-License-Identifier: LGPL-2.0-only
|
||||
*/
|
||||
|
||||
#include "kjobtrackerstest.h"
|
||||
#include "kdialogjobuidelegate.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDebug>
|
||||
#include <QMainWindow>
|
||||
#include <QStatusBar>
|
||||
|
||||
#include <KJobWidgets>
|
||||
#include <kstatusbarjobtracker.h>
|
||||
#include <kuiserverjobtracker.h>
|
||||
#include <kwidgetjobtracker.h>
|
||||
|
||||
KTestJob::KTestJob(int numberOfDirs, uint durationMs)
|
||||
: KJob()
|
||||
, m_numberOfDirs(numberOfDirs)
|
||||
, m_currentSpeed(1000)
|
||||
, m_state(Stopped)
|
||||
, m_durationMs(durationMs)
|
||||
{
|
||||
setCapabilities(KJob::Killable | KJob::Suspendable);
|
||||
}
|
||||
|
||||
KTestJob::~KTestJob()
|
||||
{
|
||||
}
|
||||
|
||||
void KTestJob::start()
|
||||
{
|
||||
connect(&m_timer, &QTimer::timeout, this, &KTestJob::nextStep);
|
||||
m_state = StatingDirs;
|
||||
m_timer.start(m_durationMs);
|
||||
Q_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:
|
||||
Q_EMIT infoMessage(this, QStringLiteral("Initial listing"));
|
||||
stateNextDir();
|
||||
break;
|
||||
case CreatingDirs:
|
||||
Q_EMIT infoMessage(this, QStringLiteral("Folder creation"));
|
||||
createNextDir();
|
||||
break;
|
||||
case CopyingFiles:
|
||||
Q_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 = 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);
|
||||
|
||||
Q_EMIT warning(this, directory_name);
|
||||
Q_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 = QStringLiteral("dir") + QString::number(processedAmount(KJob::Directories));
|
||||
|
||||
qDebug() << "Creating " << directory_name;
|
||||
setProcessedAmount(KJob::Directories, processedAmount(KJob::Directories) + 1);
|
||||
|
||||
Q_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 =
|
||||
QLatin1String("dir%1/file%2").arg(QString::number(processedAmount(KJob::Files) / 10), QString::number(processedAmount(KJob::Files) % 10));
|
||||
|
||||
qDebug() << "Copying " << file_name;
|
||||
setProcessedAmount(KJob::Files, processedAmount(KJob::Files) + 1);
|
||||
setProcessedAmount(KJob::Bytes, processedAmount(KJob::Bytes) + 1000);
|
||||
|
||||
Q_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();
|
||||
}
|
||||
|
||||
#include "moc_kjobtrackerstest.cpp"
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
This file is part of the KDE libraries
|
||||
SPDX-FileCopyrightText: 2007 Kevin Ottens <ervin@kde.org>
|
||||
|
||||
SPDX-License-Identifier: LGPL-2.0-only
|
||||
*/
|
||||
|
||||
#ifndef KJOBTRACKERSTEST_H
|
||||
#define KJOBTRACKERSTEST_H
|
||||
|
||||
#include <KJob>
|
||||
|
||||
#include <QTimer>
|
||||
|
||||
class KTestJob : public KJob
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum State {
|
||||
StatingDirs,
|
||||
CreatingDirs,
|
||||
CopyingFiles,
|
||||
Stopped,
|
||||
};
|
||||
|
||||
// 10 files per directory
|
||||
// 1000 bytes per files
|
||||
KTestJob(int numberOfDirs = 5, uint durationMs = 50);
|
||||
~KTestJob() override;
|
||||
|
||||
void start() override;
|
||||
|
||||
private Q_SLOTS:
|
||||
void nextStep();
|
||||
|
||||
protected:
|
||||
void stateNextDir();
|
||||
void createNextDir();
|
||||
void copyNextFile();
|
||||
|
||||
bool doSuspend() override;
|
||||
bool doResume() override;
|
||||
bool doKill() override;
|
||||
|
||||
private:
|
||||
qulonglong m_numberOfDirs;
|
||||
qulonglong m_currentSpeed;
|
||||
State m_state;
|
||||
uint m_durationMs;
|
||||
QTimer m_timer;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user