1 | /* |
2 | * Copyright (C) 2007-2010 John Tapsell <johnflux@gmail.com> |
3 | * |
4 | * This program is free software; you can redistribute it and/or modify |
5 | * it under the terms of the GNU Library General Public License version 2 as |
6 | * published by the Free Software Foundation |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details |
12 | * |
13 | * You should have received a copy of the GNU Library General Public |
14 | * License along with this program; if not, write to the |
15 | * Free Software Foundation, Inc., |
16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
17 | */ |
18 | |
19 | #ifndef Q_WS_WIN |
20 | |
21 | #include "ksystemactivitydialog.h" |
22 | |
23 | #include <QAbstractScrollArea> |
24 | #include <QCloseEvent> |
25 | #include <QLineEdit> |
26 | #include <QLayout> |
27 | #include <QString> |
28 | #include <QAction> |
29 | #include <QTreeView> |
30 | |
31 | #include <KConfigGroup> |
32 | #include <KGlobal> |
33 | #include <KWindowSystem> |
34 | |
35 | #include "krunnersettings.h" |
36 | |
37 | KSystemActivityDialog::KSystemActivityDialog(QWidget *parent) |
38 | : KDialog(parent), m_processList(0) |
39 | { |
40 | setWindowTitle(i18n("System Activity" )); |
41 | setWindowIcon(KIcon(QLatin1String( "utilities-system-monitor" ))); |
42 | setButtons(0); |
43 | setMainWidget(&m_processList); |
44 | m_processList.setScriptingEnabled(true); |
45 | setSizeGripEnabled(true); |
46 | (void)minimumSizeHint(); //Force the dialog to be laid out now |
47 | layout()->setContentsMargins(0,0,0,0); |
48 | m_processList.treeView()->setCornerWidget(new QWidget); |
49 | |
50 | // Since we kinda act like an application more than just a Window, map the usual ctrl+Q shortcut to close as well |
51 | QAction *closeWindow = new QAction(this); |
52 | closeWindow->setShortcut(QKeySequence::Quit); |
53 | connect(closeWindow, SIGNAL(triggered(bool)), this, SLOT(accept())); |
54 | addAction(closeWindow); |
55 | |
56 | setInitialSize(QSize(650, 420)); |
57 | KConfigGroup cg = KGlobal::config()->group("TaskDialog" ); |
58 | restoreDialogSize(cg); |
59 | |
60 | m_processList.loadSettings(cg); |
61 | // Since we default to forcing the window to be KeepAbove, if the user turns this off, remember this |
62 | const bool keepAbove = KRunnerSettings::keepTaskDialogAbove(); |
63 | if (keepAbove) { |
64 | KWindowSystem::setState(winId(), NET::KeepAbove ); |
65 | } |
66 | } |
67 | |
68 | void KSystemActivityDialog::run() |
69 | { |
70 | show(); |
71 | raise(); |
72 | KWindowSystem::setOnDesktop(winId(), KWindowSystem::currentDesktop()); |
73 | KWindowSystem::forceActiveWindow(winId()); |
74 | } |
75 | |
76 | void KSystemActivityDialog::setFilterText(const QString &filterText) |
77 | { |
78 | m_processList.filterLineEdit()->setText(filterText); |
79 | m_processList.filterLineEdit()->setFocus(); |
80 | } |
81 | |
82 | QString KSystemActivityDialog::filterText() const |
83 | { |
84 | return m_processList.filterLineEdit()->text(); |
85 | } |
86 | |
87 | void KSystemActivityDialog::closeEvent(QCloseEvent *event) |
88 | { |
89 | saveDialogSettings(); |
90 | event->accept(); |
91 | } |
92 | |
93 | |
94 | void KSystemActivityDialog::reject () |
95 | { |
96 | saveDialogSettings(); |
97 | QDialog::reject(); |
98 | } |
99 | |
100 | void KSystemActivityDialog::saveDialogSettings() |
101 | { |
102 | //When the user closes the dialog, save the position and the KeepAbove state |
103 | KConfigGroup cg = KGlobal::config()->group("TaskDialog" ); |
104 | saveDialogSize(cg); |
105 | m_processList.saveSettings(cg); |
106 | |
107 | // Since we default to forcing the window to be KeepAbove, if the user turns this off, remember this |
108 | bool keepAbove = KWindowSystem::windowInfo(winId(), NET::WMState).hasState(NET::KeepAbove); |
109 | KRunnerSettings::setKeepTaskDialogAbove(keepAbove); |
110 | KGlobal::config()->sync(); |
111 | } |
112 | |
113 | #endif // not Q_WS_WIN |
114 | |
115 | |