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 *window = widget ? widget->windowHandle() : nullptr;
18
19 job->setProperty("window", QVariant::fromValue(window));
20 if (window) {
21 job->setProperty("window-id", QVariant::fromValue(window->winId()));
22 }
23}
24
26{
27 return job->property("widget").value<QWidget *>();
28}
29
30// duplicated from kwindowsystem
31static 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
41void KJobWidgets::updateUserTimestamp(QObject *job, unsigned long time)
42{
43 unsigned long currentTimestamp = userTimestamp(job);
44 if (currentTimestamp == 0 || timestampCompare(time, currentTimestamp) > 0) {
45 job->setProperty("userTimestamp", qulonglong(time));
46 }
47}
48
50{
51 return job->property("userTimestamp").toULongLong();
52}
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.
QWidget * window(QObject *job)
Return the window 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 Tue Mar 26 2024 11:14:43 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.