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 <QPointer>
10#include <QVariant>
11#include <QWidget>
12#include <QWindow>
13
15{
16 QPointer<QWidget> p = widget;
17 job->setProperty("widget", QVariant::fromValue(p));
18
19 QPointer<QWindow> windowHandle = widget ? widget->windowHandle() : nullptr;
21 if (windowHandle) {
23 }
24}
25
26#if KWIDGETSADDONS_BUILD_DEPRECATED_SINCE(6, 5)
28{
29 job->setProperty("window", QVariant::fromValue(window));
30 if (window) {
31 job->setProperty("window-id", QVariant::fromValue(window->winId()));
32 }
33}
34#endif
35
37{
38 return job->property("widget").value<QPointer<QWidget>>();
39}
40
41#if KWIDGETSADDONS_BUILD_DEPRECATED_SINCE(6, 5)
43{
44 return job->property("window").value<QPointer<QWindow>>();
45}
46#endif
47
48// duplicated from kwindowsystem
49static int timestampCompare(unsigned long time1_, unsigned long time2_) // like strcmp()
50{
51 quint32 time1 = time1_;
52 quint32 time2 = time2_;
53 if (time1 == time2) {
54 return 0;
55 }
56 return quint32(time1 - time2) < 0x7fffffffU ? 1 : -1; // time1 > time2 -> 1, handle wrapping
57}
58
59void KJobWidgets::updateUserTimestamp(QObject *job, unsigned long time)
60{
61 unsigned long currentTimestamp = userTimestamp(job);
62 if (currentTimestamp == 0 || timestampCompare(time, currentTimestamp) > 0) {
63 job->setProperty("userTimestamp", qulonglong(time));
64 }
65}
66
68{
69 return job->property("userTimestamp").toULongLong();
70}
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 Sat Dec 21 2024 16:59:27 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.