~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to krunner/ksystemactivitydialog.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
void KSystemActivityDialog::closeEvent(QCloseEvent *event)
 
83
{
 
84
    saveDialogSettings();
 
85
    event->accept();
 
86
}
 
87
 
 
88
 
 
89
void KSystemActivityDialog::reject ()
 
90
{
 
91
    saveDialogSettings();
 
92
    QDialog::reject();
 
93
}
 
94
 
 
95
void KSystemActivityDialog::saveDialogSettings()
 
96
{
 
97
    //When the user closes the dialog, save the position and the KeepAbove state
 
98
    KConfigGroup cg = KGlobal::config()->group("TaskDialog");
 
99
    saveDialogSize(cg);
 
100
    m_processList.saveSettings(cg);
 
101
 
 
102
    // Since we default to forcing the window to be KeepAbove, if the user turns this off, remember this
 
103
    bool keepAbove = KWindowSystem::windowInfo(winId(), NET::WMState).hasState(NET::KeepAbove);
 
104
    KRunnerSettings::setKeepTaskDialogAbove(keepAbove);
 
105
    KGlobal::config()->sync();
 
106
}
 
107
 
 
108
#endif // not Q_WS_WIN
 
109