KWidgetsAddons

kjobwidgets.cpp
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
14{
15 job->setProperty("widget", QVariant::fromValue(widget));
16
17 QWindow *windowHandle = widget ? widget->windowHandle() : nullptr;
19 if (windowHandle) {
21 }
22}
23
24#if KWIDGETSADDONS_BUILD_DEPRECATED_SINCE(6, 5)
26{
27 job->setProperty("window", QVariant::fromValue(window));
28 if (window) {
29 job->setProperty("window-id", QVariant::fromValue(window->winId()));
30 }
31}
32#endif
33
35{
36 return job->property("widget").value<QWidget *>();
37}
38
39#if KWIDGETSADDONS_BUILD_DEPRECATED_SINCE(6, 5)
41{
42 return job->property("window").value<QWindow *>();
43}
44#endif
45
46// duplicated from kwindowsystem
47static int timestampCompare(unsigned long time1_, unsigned long time2_) // like strcmp()
48{
49 quint32 time1 = time1_;
50 quint32 time2 = time2_;
51 if (time1 == time2) {
52 return 0;
53 }
54 return quint32(time1 - time2) < 0x7fffffffU ? 1 : -1; // time1 > time2 -> 1, handle wrapping
55}
56
57void KJobWidgets::updateUserTimestamp(QObject *job, unsigned long time)
58{
59 unsigned long currentTimestamp = userTimestamp(job);
60 if (currentTimestamp == 0 || timestampCompare(time, currentTimestamp) > 0) {
61 job->setProperty("userTimestamp", qulonglong(time));
62 }
63}
64
66{
67 return job->property("userTimestamp").toULongLong();
68}
void setWindow(QObject *job, QWidget *widget)
Associate this job with a window given by window.
void updateUserTimestamp(QObject *job, unsigned long time)
Updates the last user action timestamp to the given time.
unsigned long userTimestamp(QObject *job)
Returns the last user action timestamp.
void setWindowHandle(QObject *job, QWindow *window)
Associate this job with a window given by window.
QWidget * window(QObject *job)
Return the window associated with this job.
QWindow * windowHandle(QObject *job)
Returns the window handle associated with this job.
QVariant property(const char *name) const const
bool setProperty(const char *name, QVariant &&value)
QVariant fromValue(T &&value)
qulonglong toULongLong(bool *ok) const const
T value() const const
QWindow * windowHandle() const const
WId winId() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jul 19 2024 11:51:03 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.