Changeset View
Changeset View
Standalone View
Standalone View
systemmonitor/ksystemactivitydialog.cpp
Show All 15 Lines | |||||
16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
17 | */ | 17 | */ | ||
18 | 18 | | |||
19 | #ifndef Q_WS_WIN | 19 | #ifndef Q_WS_WIN | ||
20 | 20 | | |||
21 | #include "ksystemactivitydialog.h" | 21 | #include "ksystemactivitydialog.h" | ||
22 | 22 | | |||
23 | #include <QCloseEvent> | 23 | #include <QCloseEvent> | ||
24 | #include <QLayout> | | |||
25 | #include <QString> | 24 | #include <QString> | ||
26 | #include <QAction> | 25 | #include <QAction> | ||
27 | #include <QTreeView> | | |||
28 | #include <QIcon> | 26 | #include <QIcon> | ||
29 | #include <QWindow> | | |||
30 | #include <QDialog> | | |||
31 | #include <QDBusConnection> | 27 | #include <QDBusConnection> | ||
32 | #include <QPushButton> | | |||
33 | #include <QVBoxLayout> | 28 | #include <QVBoxLayout> | ||
34 | #include <QLineEdit> | 29 | #include <QLineEdit> | ||
35 | #include <QScreen> | | |||
36 | #include <QTimer> | | |||
37 | 30 | | |||
38 | #include <KSharedConfig> | 31 | #include <KSharedConfig> | ||
39 | #include <KConfigGroup> | 32 | #include <KConfigGroup> | ||
40 | #include <KWindowConfig> | | |||
41 | #include <KWindowSystem> | 33 | #include <KWindowSystem> | ||
42 | #include <KLocalizedString> | 34 | #include <KLocalizedString> | ||
43 | #include <QDebug> | 35 | #include <QDebug> | ||
44 | 36 | | |||
45 | KSystemActivityDialog::KSystemActivityDialog(QWidget *parent) | 37 | KSystemActivityDialog::KSystemActivityDialog(QWidget *parent) | ||
46 | : QDialog(parent), m_processList(nullptr) | 38 | : QDialog(parent), m_processList(nullptr) | ||
47 | { | 39 | { | ||
48 | setWindowTitle(i18n("System Activity")); | 40 | setWindowTitle(i18n("System Activity")); | ||
49 | setWindowIcon(QIcon::fromTheme(QStringLiteral( "utilities-system-monitor" ))); | 41 | setWindowIcon(QIcon::fromTheme(QStringLiteral( "utilities-system-monitor" ))); | ||
50 | QVBoxLayout *mainLayout = new QVBoxLayout(this); | 42 | QVBoxLayout *mainLayout = new QVBoxLayout(this); | ||
51 | mainLayout->addWidget(&m_processList); | 43 | mainLayout->addWidget(&m_processList); | ||
52 | m_processList.setScriptingEnabled(true); | 44 | m_processList.setScriptingEnabled(true); | ||
53 | setSizeGripEnabled(true); | 45 | setSizeGripEnabled(true); | ||
54 | (void)minimumSizeHint(); //Force the dialog to be laid out now | 46 | | ||
55 | layout()->setContentsMargins(0,0,0,0); | 47 | layout()->setContentsMargins(0,0,0,0); | ||
56 | 48 | | |||
57 | // Since we kinda act like an application more than just a Window, map the usual ctrl+Q shortcut to close as well | 49 | // Since we kinda act like an application more than just a Window, map the usual ctrl+Q shortcut to close as well | ||
58 | QAction *closeWindow = new QAction(this); | 50 | QAction *closeWindow = new QAction(this); | ||
59 | closeWindow->setShortcut(QKeySequence::Quit); | 51 | closeWindow->setShortcut(QKeySequence::Quit); | ||
60 | connect(closeWindow, &QAction::triggered, this, &KSystemActivityDialog::accept); | 52 | connect(closeWindow, &QAction::triggered, this, &KSystemActivityDialog::accept); | ||
61 | addAction(closeWindow); | 53 | addAction(closeWindow); | ||
62 | 54 | | |||
63 | // We need the resizing to be done once the dialog has been initialized | | |||
64 | // otherwise we don't actually have a window. | | |||
65 | QTimer::singleShot(0, this, &KSystemActivityDialog::slotInit); | | |||
66 | } | | |||
67 | | ||||
68 | void KSystemActivityDialog::slotInit() | | |||
69 | { | | |||
70 | resize(QSize(650, 420)); | | |||
71 | | ||||
72 | KConfigGroup cg = KSharedConfig::openConfig()->group("TaskDialog"); | 55 | KConfigGroup cg = KSharedConfig::openConfig()->group("TaskDialog"); | ||
73 | KWindowConfig::restoreWindowSize(windowHandle(), cg); | | |||
74 | | ||||
75 | m_processList.loadSettings(cg); | 56 | m_processList.loadSettings(cg); | ||
76 | // Since we default to forcing the window to be KeepAbove, if the user turns this off, remember this | | |||
77 | const bool keepAbove = true; // KRunnerSettings::keepTaskDialogAbove(); | | |||
78 | if (keepAbove) { | | |||
79 | KWindowSystem::setState(winId(), NET::KeepAbove); | | |||
broulik: Is it intentional you removed the `KeepAbove`? | |||||
Yes, per my interpretation of the comment that application shouldn't force it's window properties like that because it interferes with WM settings. There doesn't really seem to be a consensus if that's right, though? From what I understand there doesn't seem to be any API to set preferred window geometry and keepabove AND respect specific kwin settings. valeriymalov: Yes, per my interpretation of the comment that application shouldn't force it's window… | |||||
broulik: `setWindowFlag(Qt::WindowStaysOnTopHint)`? | |||||
80 | } | | |||
81 | 57 | | |||
82 | QDBusConnection con = QDBusConnection::sessionBus(); | 58 | QDBusConnection con = QDBusConnection::sessionBus(); | ||
83 | con.registerObject(QStringLiteral("/"), this, QDBusConnection::ExportAllSlots); | 59 | con.registerObject(QStringLiteral("/"), this, QDBusConnection::ExportAllSlots); | ||
84 | | ||||
85 | QRect geom = windowHandle()->screen()->geometry(); | | |||
86 | QSize ourSize = windowHandle()->size(); | | |||
87 | | ||||
88 | int w = ourSize.width(); | | |||
89 | int h = ourSize.height(); | | |||
90 | setGeometry((geom.width() - w)/2, (geom.height() - h)/2, w, h); | | |||
91 | } | 60 | } | ||
92 | 61 | | |||
93 | void KSystemActivityDialog::run() | 62 | void KSystemActivityDialog::run() | ||
94 | { | 63 | { | ||
95 | show(); | 64 | show(); | ||
96 | raise(); | 65 | raise(); | ||
97 | KWindowSystem::setOnDesktop(winId(), KWindowSystem::currentDesktop()); | 66 | KWindowSystem::setOnDesktop(winId(), KWindowSystem::currentDesktop()); | ||
98 | KWindowSystem::forceActiveWindow(winId()); | 67 | KWindowSystem::forceActiveWindow(winId()); | ||
99 | } | 68 | } | ||
100 | 69 | | |||
101 | void KSystemActivityDialog::setFilterText(const QString &filterText) | 70 | void KSystemActivityDialog::setFilterText(const QString &filterText) | ||
102 | { | 71 | { | ||
103 | m_processList.filterLineEdit()->setText(filterText); | 72 | m_processList.filterLineEdit()->setText(filterText); | ||
104 | m_processList.filterLineEdit()->setFocus(); | 73 | m_processList.filterLineEdit()->setFocus(); | ||
105 | } | 74 | } | ||
106 | 75 | | |||
107 | QString KSystemActivityDialog::filterText() const | 76 | QString KSystemActivityDialog::filterText() const | ||
108 | { | 77 | { | ||
109 | return m_processList.filterLineEdit()->text(); | 78 | return m_processList.filterLineEdit()->text(); | ||
This doesn't work with scaling, different font settings or different widget themes. Hardcoded sizes are a no-no in general. sebas: This doesn't work with scaling, different font settings or different widget themes. Hardcoded… | |||||
davidedmundson:
>This doesn't work with scaling
Yes it does. | |||||
Right, was actually wondering right after I submitted. In that case, I'm not all that opposed. sebas: Right, was actually wondering right after I submitted. In that case, I'm not all that opposed. | |||||
110 | } | 79 | } | ||
111 | 80 | | |||
112 | void KSystemActivityDialog::closeEvent(QCloseEvent *event) | 81 | void KSystemActivityDialog::closeEvent(QCloseEvent *event) | ||
113 | { | 82 | { | ||
114 | saveDialogSettings(); | 83 | saveDialogSettings(); | ||
115 | event->accept(); | 84 | event->accept(); | ||
116 | } | 85 | } | ||
117 | 86 | | |||
118 | | ||||
119 | void KSystemActivityDialog::reject () | 87 | void KSystemActivityDialog::reject() | ||
120 | { | 88 | { | ||
121 | saveDialogSettings(); | 89 | saveDialogSettings(); | ||
122 | QDialog::reject(); | 90 | QDialog::reject(); | ||
123 | } | 91 | } | ||
124 | 92 | | |||
125 | void KSystemActivityDialog::saveDialogSettings() | 93 | void KSystemActivityDialog::saveDialogSettings() | ||
126 | { | 94 | { | ||
127 | //When the user closes the dialog, save the position and the KeepAbove state | 95 | // When the user closes the dialog, save the process list setup | ||
128 | KConfigGroup cg = KSharedConfig::openConfig()->group("TaskDialog"); | 96 | KConfigGroup cg = KSharedConfig::openConfig()->group("TaskDialog"); | ||
129 | KWindowConfig::saveWindowSize(windowHandle(), cg); | | |||
130 | m_processList.saveSettings(cg); | 97 | m_processList.saveSettings(cg); | ||
131 | | ||||
132 | // Since we default to forcing the window to be KeepAbove, if the user turns this off, remember this | | |||
133 | // vHanda: Temporarily commented out | | |||
134 | // bool keepAbove = KWindowSystem::windowInfo(winId(), NET::WMState).hasState(NET::KeepAbove); | | |||
135 | // KRunnerSettings::setKeepTaskDialogAbove(keepAbove); | | |||
136 | KSharedConfig::openConfig()->sync(); | 98 | KSharedConfig::openConfig()->sync(); | ||
137 | } | 99 | } | ||
138 | 100 | | |||
139 | #endif // not Q_WS_WIN | 101 | QSize KSystemActivityDialog::sizeHint() const | ||
102 | { | ||||
103 | return QSize(650, 420); | ||||
104 | } | ||||
140 | 105 | | |||
106 | #endif // not Q_WS_WIN |
Is it intentional you removed the KeepAbove?