File indexing completed on 2023-12-03 04:08:27
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 <KJob> 0010 #include <QVariant> 0011 #include <QWidget> 0012 #include <QWindow> 0013 0014 void KJobWidgets::setWindow(KJob *job, QWidget *widget) 0015 { 0016 job->setProperty("widget", QVariant::fromValue(widget)); 0017 KJobWindows::setWindow(job, widget ? widget->windowHandle() : nullptr); 0018 } 0019 0020 QWidget *KJobWidgets::window(KJob *job) 0021 { 0022 return job->property("widget").value<QWidget *>(); 0023 } 0024 0025 // duplicated from kwindowsystem 0026 static int timestampCompare(unsigned long time1_, unsigned long time2_) // like strcmp() 0027 { 0028 quint32 time1 = time1_; 0029 quint32 time2 = time2_; 0030 if (time1 == time2) { 0031 return 0; 0032 } 0033 return quint32(time1 - time2) < 0x7fffffffU ? 1 : -1; // time1 > time2 -> 1, handle wrapping 0034 } 0035 0036 void KJobWidgets::updateUserTimestamp(KJob *job, unsigned long time) 0037 { 0038 unsigned long currentTimestamp = userTimestamp(job); 0039 if (currentTimestamp == 0 || timestampCompare(time, currentTimestamp) > 0) { 0040 job->setProperty("userTimestamp", qulonglong(time)); 0041 } 0042 } 0043 0044 unsigned long KJobWidgets::userTimestamp(KJob *job) 0045 { 0046 return job->property("userTimestamp").toULongLong(); 0047 } 0048 0049 void KJobWindows::setWindow(KJob *job, QWindow *window) 0050 { 0051 job->setProperty("window", QVariant::fromValue(window)); 0052 if (window) { 0053 job->setProperty("window-id", QVariant::fromValue(window->winId())); 0054 } 0055 } 0056 0057 QWindow *KJobWindows::window(KJob *job) 0058 { 0059 return job->property("window").value<QWindow *>(); 0060 }