KJobWidgets

kjobwidgets.cpp
1 /* This file is part of the KDE libraries
2  * Copyright (c) 2013 David Faure <[email protected]>
3  *
4  * This library is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation; either version 2 of the License or ( at
7  * your option ) version 3 or, at the discretion of KDE e.V. ( which shall
8  * act as a proxy as in section 14 of the GPLv3 ), any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this library; see the file COPYING.LIB. If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 #include "kjobwidgets.h"
22 #include <KJob>
23 #include <QVariant>
24 #include <QWidget>
25 #include <QWindow>
26 
27 void KJobWidgets::setWindow(KJob *job, QWidget *widget)
28 {
29  job->setProperty("widget", QVariant::fromValue(widget));
30  KJobWindows::setWindow(job, widget ? widget->windowHandle() : nullptr);
31 }
32 
34 {
35  return job->property("widget").value<QWidget *>();
36 }
37 
38 // duplicated from kwindowsystem
39 static int timestampCompare(unsigned long time1_, unsigned long time2_) // like strcmp()
40 {
41  quint32 time1 = time1_;
42  quint32 time2 = time2_;
43  if (time1 == time2) {
44  return 0;
45  }
46  return quint32(time1 - time2) < 0x7fffffffU ? 1 : -1; // time1 > time2 -> 1, handle wrapping
47 }
48 
49 void KJobWidgets::updateUserTimestamp(KJob *job, unsigned long time)
50 {
51  unsigned long currentTimestamp = userTimestamp(job);
52  if (currentTimestamp == 0 || timestampCompare(time, currentTimestamp) > 0) {
53  job->setProperty("userTimestamp", qulonglong(time));
54  }
55 }
56 
57 unsigned long KJobWidgets::userTimestamp(KJob *job)
58 {
59  return job->property("userTimestamp").toULongLong();
60 }
61 
62 
63 void KJobWindows::setWindow(KJob *job, QWindow *window)
64 {
65  job->setProperty("window", QVariant::fromValue(window));
66  if (window) {
67  job->setProperty("window-id", QVariant::fromValue(window->winId()));
68  }
69 }
70 
71 QWindow *KJobWindows::window(KJob *job)
72 {
73  return job->property("window").value<QWindow *>();
74 }
KJOBWIDGETS_EXPORT void setWindow(KJob *job, QWidget *widget)
Associate this job with a window given by window.
Definition: kjobwidgets.cpp:27
KJOBWIDGETS_EXPORT QWidget * window(KJob *job)
Return the window associated with this job.
Definition: kjobwidgets.cpp:33
KJOBWIDGETS_EXPORT unsigned long userTimestamp(KJob *job)
Returns the last user action timestamp.
Definition: kjobwidgets.cpp:57
KJOBWIDGETS_EXPORT void updateUserTimestamp(KJob *job, unsigned long time)
Updates the last user action timestamp to the given time.
Definition: kjobwidgets.cpp:49
T value() const const
qulonglong toULongLong(bool *ok) const const
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-2020 The KDE developers.
Generated on Tue Jul 14 2020 22:48:15 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.