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, QWidget *widget)
Associate this job with a window given by window.
Definition: kjobwidgets.cpp:14
KJOBWIDGETS_EXPORT QWidget * window(KJob *job)
Return the window associated with this job.
Definition: kjobwidgets.cpp:20
KJOBWIDGETS_EXPORT unsigned long userTimestamp(KJob *job)
Returns the last user action timestamp.
Definition: kjobwidgets.cpp:44
KJOBWIDGETS_EXPORT void updateUserTimestamp(KJob *job, unsigned long time)
Updates the last user action timestamp to the given time.
Definition: kjobwidgets.cpp:36
T value() const const
KJOBWIDGETS_EXPORT void setWindow(KJob *job, QWindow *window)
Associate this job with a window given by window.
Definition: kjobwidgets.cpp:49
qulonglong toULongLong(bool *ok) const const
KJOBWIDGETS_EXPORT QWindow * window(KJob *job)
Return the window associated with this job.
Definition: kjobwidgets.cpp:57
QVariant property(const char *name) const const
QVariant fromValue(const T &value)
QWindow * windowHandle() const const
bool setProperty(const char *name, const QVariant &value)
WId winId() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Thu May 13 2021 22:48:21 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.