File indexing completed on 2024-04-28 03:59:06
0001 /* 0002 This file is part of the KDE libraries 0003 SPDX-FileCopyrightText: 2013 David Faure <faure@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0006 */ 0007 0008 #include "kjobwidgets.h" 0009 #include <QVariant> 0010 #include <QWidget> 0011 #include <QWindow> 0012 0013 void KJobWidgets::setWindow(QObject *job, QWidget *widget) 0014 { 0015 job->setProperty("widget", QVariant::fromValue(widget)); 0016 0017 QWindow *window = widget ? widget->windowHandle() : nullptr; 0018 0019 job->setProperty("window", QVariant::fromValue(window)); 0020 if (window) { 0021 job->setProperty("window-id", QVariant::fromValue(window->winId())); 0022 } 0023 } 0024 0025 QWidget *KJobWidgets::window(QObject *job) 0026 { 0027 return job->property("widget").value<QWidget *>(); 0028 } 0029 0030 // duplicated from kwindowsystem 0031 static int timestampCompare(unsigned long time1_, unsigned long time2_) // like strcmp() 0032 { 0033 quint32 time1 = time1_; 0034 quint32 time2 = time2_; 0035 if (time1 == time2) { 0036 return 0; 0037 } 0038 return quint32(time1 - time2) < 0x7fffffffU ? 1 : -1; // time1 > time2 -> 1, handle wrapping 0039 } 0040 0041 void KJobWidgets::updateUserTimestamp(QObject *job, unsigned long time) 0042 { 0043 unsigned long currentTimestamp = userTimestamp(job); 0044 if (currentTimestamp == 0 || timestampCompare(time, currentTimestamp) > 0) { 0045 job->setProperty("userTimestamp", qulonglong(time)); 0046 } 0047 } 0048 0049 unsigned long KJobWidgets::userTimestamp(QObject *job) 0050 { 0051 return job->property("userTimestamp").toULongLong(); 0052 }