Commit 892c5a27 authored by Eugene Popov's avatar Eugene Popov 🇺🇦 Committed by Nate Graham
Browse files

SystemMonitor: Port to KMainWindow

Currently, KSystemActivityDialog is derived from QDialog and therefore has several
limitations:
* it doesn't save and restore its size and position
* it doesn't respect Window Placement settings (it always opens in the center)

Porting it to KMainWindow removes these limitations and saves the user from creating
window rules to get around them.

BUG: 400298
FIXED-IN: 5.25
parent fcb522f8
Pipeline #144899 passed with stage
in 8 minutes and 18 seconds
......@@ -8,6 +8,8 @@
#include "ksystemactivitydialog.h"
#include "processui/ksysguardprocesslist.h"
#include <QAction>
#include <QCloseEvent>
#include <QDBusConnection>
......@@ -16,31 +18,36 @@
#include <QString>
#include <QVBoxLayout>
#include <KConfigGroup>
#include <KLocalizedString>
#include <KSharedConfig>
#include <KWindowSystem>
#include <QDebug>
KSystemActivityDialog::KSystemActivityDialog(QWidget *parent)
: QDialog(parent)
, m_processList(nullptr)
: KMainWindow(parent)
, m_configGroup(KSharedConfig::openConfig()->group("TaskDialog"))
{
setWindowTitle(i18n("System Activity"));
setWindowIcon(QIcon::fromTheme(QStringLiteral("utilities-system-monitor")));
QVBoxLayout *mainLayout = new QVBoxLayout(this);
mainLayout->addWidget(&m_processList);
m_processList.setScriptingEnabled(true);
setSizeGripEnabled(true);
setAutoSaveSettings();
m_processList = new KSysGuardProcessList;
m_processList->setScriptingEnabled(true);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(m_processList);
// Since we kinda act like an application more than just a Window, map the usual ctrl+Q shortcut to close as well
QAction *closeWindow = new QAction(this);
closeWindow->setShortcut(QKeySequence::Quit);
connect(closeWindow, &QAction::triggered, this, &KSystemActivityDialog::accept);
addAction(closeWindow);
QWidget *mainWidget = new QWidget;
mainWidget->setLayout(mainLayout);
setCentralWidget(mainWidget);
KConfigGroup cg = KSharedConfig::openConfig()->group("TaskDialog");
m_processList.loadSettings(cg);
QAction *closeAction = new QAction;
closeAction->setShortcuts({ QKeySequence::Quit, Qt::Key_Escape });
connect(closeAction, &QAction::triggered, this, &KSystemActivityDialog::close);
addAction(closeAction);
if (m_configGroup.exists()) {
m_processList->loadSettings(m_configGroup);
}
QDBusConnection con = QDBusConnection::sessionBus();
con.registerObject(QStringLiteral("/"), this, QDBusConnection::ExportAllSlots);
......@@ -56,33 +63,21 @@ void KSystemActivityDialog::run()
void KSystemActivityDialog::setFilterText(const QString &filterText)
{
m_processList.filterLineEdit()->setText(filterText);
m_processList.filterLineEdit()->setFocus();
m_processList->filterLineEdit()->setText(filterText);
m_processList->filterLineEdit()->setFocus();
}
QString KSystemActivityDialog::filterText() const
{
return m_processList.filterLineEdit()->text();
return m_processList->filterLineEdit()->text();
}
void KSystemActivityDialog::closeEvent(QCloseEvent *event)
{
saveDialogSettings();
event->accept();
}
void KSystemActivityDialog::reject()
{
saveDialogSettings();
QDialog::reject();
}
void KSystemActivityDialog::saveDialogSettings()
{
// When the user closes the dialog, save the process list setup
KConfigGroup cg = KSharedConfig::openConfig()->group("TaskDialog");
m_processList.saveSettings(cg);
m_processList->saveSettings(m_configGroup);
KSharedConfig::openConfig()->sync();
KMainWindow::closeEvent(event);
}
QSize KSystemActivityDialog::sizeHint() const
......
......@@ -8,16 +8,17 @@
#ifndef Q_WS_WIN
#include <QDialog>
#include <KConfigGroup>
#include <KMainWindow>
#include "processui/ksysguardprocesslist.h"
class KSysGuardProcessList;
/** This creates a simple dialog box with a KSysguardProcessList
*
* It remembers the size and position of the dialog, and sets
* the dialog to always be over the other windows
*/
class KSystemActivityDialog : public QDialog
class KSystemActivityDialog : public KMainWindow
{
Q_OBJECT
public:
......@@ -36,16 +37,12 @@ public:
QSize sizeHint() const override;
/** Save the settings if the user presses the ESC key */
void reject() override;
protected:
/** Save the settings if the user clicks (x) button on the window */
void closeEvent(QCloseEvent *event) override;
private:
void saveDialogSettings();
KSysGuardProcessList m_processList;
KSysGuardProcessList *m_processList = nullptr;
KConfigGroup m_configGroup;
};
#endif // not Q_WS_WIN
......@@ -28,6 +28,8 @@ int main(int argc, char **argv)
return 0;
}
KSystemActivityDialog dialog;
return dialog.exec();
KSystemActivityDialog *dialog = new KSystemActivityDialog;
dialog->show();
return app.exec();
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment