10#include "progressdialog.h"
13#include <KLocalizedString>
21#include <QProgressBar>
28using namespace std::chrono_literals;
31static const int MAX_LABEL_WIDTH = 650;
33class KPIM::OverlayWidgetPrivate
36 OverlayWidgetPrivate() =
default;
38 QWidget *mAlignWidget =
nullptr;
43 , d(new
KPIM::OverlayWidgetPrivate)
45 setAlignWidget(alignWidget);
49OverlayWidget::~OverlayWidget() =
default;
51QWidget *OverlayWidget::alignWidget()
const
53 return d->mAlignWidget;
56void OverlayWidget::reposition()
58 if (!d->mAlignWidget) {
66 p.
setX(d->mAlignWidget->width() -
width());
77void OverlayWidget::setAlignWidget(QWidget *w)
79 if (w == d->mAlignWidget) {
83 if (d->mAlignWidget) {
84 d->mAlignWidget->removeEventFilter(
this);
89 if (d->mAlignWidget) {
90 d->mAlignWidget->installEventFilter(
this);
96bool OverlayWidget::eventFilter(QObject *o, QEvent *e)
104void OverlayWidget::resizeEvent(QResizeEvent *ev)
110TransactionItemView::TransactionItemView(QWidget *parent,
const QString &name)
111 : QScrollArea(parent)
112 , mBigBox(new QWidget(this))
115 setFrameStyle(NoFrame);
117 mBigBoxVBoxLayout->setContentsMargins({});
119 setWidgetResizable(
true);
123TransactionItemView::~TransactionItemView()
128TransactionItem *TransactionItemView::addTransactionItem(
ProgressItem *item,
bool first)
130 auto ti =
new TransactionItem(mBigBox, item, first);
131 mBigBox->layout()->addWidget(ti);
133 resize(mBigBox->width(), mBigBox->height());
138void TransactionItemView::resizeEvent(QResizeEvent *event)
147 if (currentWidth < sz.
width() || currentWidth > sz.
width() + 100) {
148 currentWidth = sz.
width();
155QSize TransactionItemView::sizeHint()
const
157 return minimumSizeHint();
160QSize TransactionItemView::minimumSizeHint()
const
167 QSize sz(mBigBox->minimumSizeHint());
173void TransactionItemView::slotLayoutFirstItem()
191 auto ti = mBigBox->findChild<KPIM::TransactionItem *>(QStringLiteral(
"TransactionItem"));
199TransactionItem::TransactionItem(QWidget *parent,
ProgressItem *item,
bool first)
204 vboxLayout->setSpacing(2);
205 vboxLayout->setContentsMargins(2, 2, 2, 2);
208 mFrame =
new QFrame(
this);
212 layout()->addWidget(mFrame);
216 hHBoxLayout->setContentsMargins({});
217 hHBoxLayout->setSpacing(5);
218 layout()->addWidget(h);
221 h->layout()->addWidget(mItemLabel);
225 hHBoxLayout->addWidget(mProgress);
226 mProgress->setFormat(
i18nc(
"Percent value; %p is the value, % is the percent sign",
"%p%"));
227 mProgress->setMaximum(100);
228 mProgress->setValue(item->
progress());
229 h->layout()->addWidget(mProgress);
233 hHBoxLayout->addWidget(mCancelButton);
234 mCancelButton->setToolTip(
i18nc(
"@info:tooltip",
"Cancel this operation."));
236 h->layout()->addWidget(mCancelButton);
241 hHBoxLayout->setContentsMargins({});
242 hHBoxLayout->setSpacing(5);
244 layout()->addWidget(h);
245 mSSLLabel =
new SSLLabel(h);
246 hHBoxLayout->addWidget(mSSLLabel);
248 h->layout()->addWidget(mSSLLabel);
249 mItemStatus =
new QLabel(h);
250 hHBoxLayout->addWidget(mItemStatus);
252 mItemStatus->setText(fontMetrics().elidedText(item->
status(),
Qt::ElideRight, MAX_LABEL_WIDTH));
253 h->layout()->addWidget(mItemStatus);
260KPIM::TransactionItem::~TransactionItem() =
default;
262void TransactionItem::hideHLine()
267void TransactionItem::setProgress(
int progress)
269 mProgress->setValue(progress);
272void TransactionItem::setLabel(
const QString &label)
277void TransactionItem::setStatus(
const QString &
status)
282void TransactionItem::setCryptoStatus(KPIM::ProgressItem::CryptoStatus
status)
285 case KPIM::ProgressItem::Encrypted:
286 mSSLLabel->setEncrypted(SSLLabel::Encrypted);
288 case KPIM::ProgressItem::Unencrypted:
289 mSSLLabel->setEncrypted(SSLLabel::Unencrypted);
291 case KPIM::ProgressItem::Unknown:
292 mSSLLabel->setEncrypted(SSLLabel::Unknown);
295 mSSLLabel->setState(mSSLLabel->lastState());
298void TransactionItem::setTotalSteps(
int totalSteps)
300 mProgress->setMaximum(totalSteps);
303void TransactionItem::slotItemCanceled()
310void TransactionItem::addSubTransaction(
ProgressItem *item)
317ProgressDialog::ProgressDialog(QWidget *alignWidget, QWidget *parent)
318 : OverlayWidget(alignWidget, parent)
328 setAutoFillBackground(
true);
330 mScrollView =
new TransactionItemView(
this, QStringLiteral(
"ProgressScrollView"));
331 layout()->addWidget(mScrollView);
353bool ProgressDialog::wasLastShown()
const
355 return mWasLastShown;
361ProgressDialog::~ProgressDialog()
363 for (
auto &conn : std::as_const(mConnections))
367void ProgressDialog::setShowTypeProgressItem(
unsigned int type)
369 mShowTypeProgressItem =
type;
372void ProgressDialog::slotTransactionAdded(
ProgressItem *item)
374 if (item->typeProgressItem() == mShowTypeProgressItem) {
376 if (TransactionItem *
parent = mTransactionsToListviewItems.value(item->
parent())) {
377 parent->addSubTransaction(item);
380 const bool first = mTransactionsToListviewItems.empty();
381 TransactionItem *ti = mScrollView->addTransactionItem(item, first);
383 mTransactionsToListviewItems.insert(item, ti);
385 if (first && mWasLastShown) {
392void ProgressDialog::slotTransactionCompleted(
ProgressItem *item)
394 if (TransactionItem *ti = mTransactionsToListviewItems.value(item)) {
395 mTransactionsToListviewItems.remove(item);
396 ti->setItemComplete();
402 if (mTransactionsToListviewItems.empty()) {
407void ProgressDialog::slotTransactionCanceled(
ProgressItem *)
411void ProgressDialog::slotTransactionProgress(
ProgressItem *item,
unsigned int progress)
413 if (TransactionItem *ti = mTransactionsToListviewItems.value(item)) {
414 ti->setProgress(progress);
420 if (TransactionItem *ti = mTransactionsToListviewItems.value(item)) {
425void ProgressDialog::slotTransactionLabel(
ProgressItem *item,
const QString &label)
427 if (TransactionItem *ti = mTransactionsToListviewItems.value(item)) {
432void ProgressDialog::slotTransactionCryptoStatus(
ProgressItem *item, KPIM::ProgressItem::CryptoStatus value)
434 if (TransactionItem *ti = mTransactionsToListviewItems.value(item)) {
435 ti->setCryptoStatus(value);
439void ProgressDialog::slotTransactionUsesBusyIndicator(KPIM::ProgressItem *item,
bool value)
441 if (TransactionItem *ti = mTransactionsToListviewItems.value(item)) {
443 ti->setTotalSteps(0);
445 ti->setTotalSteps(100);
450void ProgressDialog::slotShow()
455void ProgressDialog::slotHide()
458 if (mTransactionsToListviewItems.isEmpty()) {
463 for (
auto it = mConnections.begin(); it != mConnections.end();) {
465 it = mConnections.erase(it);
472void ProgressDialog::slotClose()
474 mWasLastShown =
false;
478void ProgressDialog::setVisible(
bool b)
481 Q_EMIT visibilityChanged(b);
484void ProgressDialog::slotToggleVisibility()
491 if (!
isHidden() || !mTransactionsToListviewItems.isEmpty()) {
494 mWasLastShown = showNow;
498#include "moc_progressdialog.cpp"
CryptoStatus cryptoStatus() const
bool canBeCanceled() const
unsigned int progress() const
const QString & label() const
ProgressItem * parent() const
const QString & status() const
The ProgressManager singleton keeps track of all ongoing transactions and notifies observers (progres...
void progressItemAdded(KPIM::ProgressItem *)
void progressItemLabel(KPIM::ProgressItem *, const QString &)
static ProgressManager * instance()
void progressItemUsesBusyIndicator(KPIM::ProgressItem *, bool)
void progressItemStatus(KPIM::ProgressItem *, const QString &)
void progressItemCryptoStatus(KPIM::ProgressItem *, KPIM::ProgressItem::CryptoStatus)
void progressItemProgress(KPIM::ProgressItem *, unsigned int)
void progressItemCompleted(KPIM::ProgressItem *)
void showProgressDialog()
Emitted when an operation requests the listeners to be shown.
Q_SCRIPTABLE CaptureState status()
QString i18nc(const char *context, const char *text, const TYPE &arg...)
Class KCheckComboBox::KCheckComboBoxPrivate.
VehicleSection::Type type(QStringView coachNumber, QStringView coachClassification)
QIcon fromTheme(const QString &name)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void destroyed(QObject *obj)
bool disconnect(const QMetaObject::Connection &connection)
virtual bool event(QEvent *e)
virtual bool eventFilter(QObject *watched, QEvent *event)
QObject * parent() const const
void setHeight(int height)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)