1 | /* |
2 | This file is part of the KDE libraries |
3 | SPDX-FileCopyrightText: 2013 David Faure <faure@kde.org> |
4 | |
5 | SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
6 | */ |
7 | |
8 | #include "kjobwidgets.h" |
9 | #include <QVariant> |
10 | #include <QWidget> |
11 | #include <QWindow> |
12 | |
13 | void KJobWidgets::setWindow(QObject *job, QWidget *widget) |
14 | { |
15 | job->setProperty(name: "widget" , value: QVariant::fromValue(value: widget)); |
16 | |
17 | QWindow *window = widget ? widget->windowHandle() : nullptr; |
18 | |
19 | job->setProperty(name: "window" , value: QVariant::fromValue(value: window)); |
20 | if (window) { |
21 | job->setProperty(name: "window-id" , value: QVariant::fromValue(value: window->winId())); |
22 | } |
23 | } |
24 | |
25 | QWidget *KJobWidgets::window(QObject *job) |
26 | { |
27 | return job->property(name: "widget" ).value<QWidget *>(); |
28 | } |
29 | |
30 | // duplicated from kwindowsystem |
31 | static int timestampCompare(unsigned long time1_, unsigned long time2_) // like strcmp() |
32 | { |
33 | quint32 time1 = time1_; |
34 | quint32 time2 = time2_; |
35 | if (time1 == time2) { |
36 | return 0; |
37 | } |
38 | return quint32(time1 - time2) < 0x7fffffffU ? 1 : -1; // time1 > time2 -> 1, handle wrapping |
39 | } |
40 | |
41 | void KJobWidgets::updateUserTimestamp(QObject *job, unsigned long time) |
42 | { |
43 | unsigned long currentTimestamp = userTimestamp(job); |
44 | if (currentTimestamp == 0 || timestampCompare(time1_: time, time2_: currentTimestamp) > 0) { |
45 | job->setProperty(name: "userTimestamp" , value: qulonglong(time)); |
46 | } |
47 | } |
48 | |
49 | unsigned long KJobWidgets::userTimestamp(QObject *job) |
50 | { |
51 | return job->property(name: "userTimestamp" ).toULongLong(); |
52 | } |
53 | |