KJobWidgets

kjobwidgets.cpp
1 /*
2  This file is part of the KDE libraries
3  SPDX-FileCopyrightText: 2013 David Faure <[email protected]>
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 <KJob>
10 #include <QVariant>
11 #include <QWidget>
12 #include <QWindow>
13 
14 void KJobWidgets::setWindow(KJob *job, QWidget *widget)
15 {
16  job->setProperty("widget", QVariant::fromValue(widget));
17  KJobWindows::setWindow(job, widget ? widget->windowHandle() : nullptr);
18 }
19 
21 {
22  return job->property("widget").value<QWidget *>();
23 }
24 
25 // duplicated from kwindowsystem
26 static int timestampCompare(unsigned long time1_, unsigned long time2_) // like strcmp()
27 {
28  quint32 time1 = time1_;
29  quint32 time2 = time2_;
30  if (time1 == time2) {
31  return 0;
32  }
33  return quint32(time1 - time2) < 0x7fffffffU ? 1 : -1; // time1 > time2 -> 1, handle wrapping
34 }
35 
36 void KJobWidgets::updateUserTimestamp(KJob *job, unsigned long time)
37 {
38  unsigned long currentTimestamp = userTimestamp(job);
39  if (currentTimestamp == 0 || timestampCompare(time, currentTimestamp) > 0) {
40  job->setProperty("userTimestamp", qulonglong(time));
41  }
42 }
43 
44 unsigned long KJobWidgets::userTimestamp(KJob *job)
45 {
46  return job->property("userTimestamp").toULongLong();
47 }
48 
49 void KJobWindows::setWindow(KJob *job, QWindow *window)
50 {
51  job->setProperty("window", QVariant::fromValue(window));
52  if (window) {
53  job->setProperty("window-id", QVariant::fromValue(window->winId()));
54  }
55 }
56 
58 {
59  return job->property("window").value<QWindow *>();
60 }
KJOBWIDGETS_EXPORT void setWindow(KJob *job, QWindow *window)
Associate this job with a window given by window.
Definition: kjobwidgets.cpp:49
QVariant fromValue(const T &value)
T value() const const
KJOBWIDGETS_EXPORT void setWindow(KJob *job, QWidget *widget)
Associate this job with a window given by window.
Definition: kjobwidgets.cpp:14
KJOBWIDGETS_EXPORT unsigned long userTimestamp(KJob *job)
Returns the last user action timestamp.
Definition: kjobwidgets.cpp:44
KJOBWIDGETS_EXPORT QWindow * window(KJob *job)
Return the window associated with this job.
Definition: kjobwidgets.cpp:57
qulonglong toULongLong(bool *ok) const const
bool setProperty(const char *name, const QVariant &value)
QWindow * windowHandle() const const
KJOBWIDGETS_EXPORT void updateUserTimestamp(KJob *job, unsigned long time)
Updates the last user action timestamp to the given time.
Definition: kjobwidgets.cpp:36
WId winId() const const
KJOBWIDGETS_EXPORT QWidget * window(KJob *job)
Return the window associated with this job.
Definition: kjobwidgets.cpp:20
QVariant property(const char *name) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Sep 26 2023 04:01:12 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.