OSDN Git Service

0fd39ffa97d90c09d15ab786bfb86cd54c89537d
[qt-creator-jp/qt-creator-jp.git] / src / plugins / qt4projectmanager / qt-maemo / maemoremoteprocessesdialog.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of Qt Creator.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file.  Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23 **
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 #include "maemoremoteprocessesdialog.h"
42 #include "ui_maemoremoteprocessesdialog.h"
43
44 #include "maemodeviceconfigurations.h"
45 #include "maemoremoteprocesslist.h"
46
47 #include <QtGui/QMessageBox>
48 #include <QtGui/QSortFilterProxyModel>
49
50 namespace Qt4ProjectManager {
51 namespace Internal {
52
53 MaemoRemoteProcessesDialog::MaemoRemoteProcessesDialog(const MaemoDeviceConfig::ConstPtr &devConfig,
54     QWidget *parent):
55     QDialog(parent),
56     m_ui(new Ui::MaemoRemoteProcessesDialog),
57     m_processList(new MaemoRemoteProcessList(devConfig, this)),
58     m_proxyModel(new QSortFilterProxyModel(this))
59 {
60     m_ui->setupUi(this);
61     m_ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
62     m_proxyModel->setSourceModel(m_processList);
63     m_proxyModel->setDynamicSortFilter(true);
64     m_proxyModel->setFilterKeyColumn(1);
65     m_ui->tableView->setModel(m_proxyModel);
66     connect(m_ui->processFilterLineEdit, SIGNAL(textChanged(QString)),
67         m_proxyModel, SLOT(setFilterRegExp(QString)));
68
69     // Manually gathered process information is missing the command line for
70     // some system processes. Dont's show these lines by default.
71     if (devConfig->osVersion() == MaemoGlobal::Maemo5)
72         m_ui->processFilterLineEdit->setText(QLatin1String("[^ ]+"));
73
74     connect(m_ui->tableView->selectionModel(),
75         SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
76         SLOT(handleSelectionChanged()));
77     connect(m_ui->updateListButton, SIGNAL(clicked()),
78         SLOT(updateProcessList()));
79     connect(m_ui->killProcessButton, SIGNAL(clicked()), SLOT(killProcess()));
80     connect(m_processList, SIGNAL(error(QString)),
81         SLOT(handleRemoteError(QString)));
82     connect(m_processList, SIGNAL(modelReset()),
83         SLOT(handleProcessListUpdated()));
84     connect(m_processList, SIGNAL(processKilled()),
85         SLOT(handleProcessKilled()), Qt::QueuedConnection);
86     connect(m_proxyModel, SIGNAL(layoutChanged()),
87         SLOT(handleProcessListUpdated()));
88     handleSelectionChanged();
89     updateProcessList();
90 }
91
92 MaemoRemoteProcessesDialog::~MaemoRemoteProcessesDialog()
93 {
94     delete m_ui;
95 }
96
97 void MaemoRemoteProcessesDialog::handleRemoteError(const QString &errorMsg)
98 {
99     QMessageBox::critical(this, tr("Remote Error"), errorMsg);
100     m_ui->updateListButton->setEnabled(true);
101     handleSelectionChanged();
102 }
103
104 void MaemoRemoteProcessesDialog::handleProcessListUpdated()
105 {
106     m_ui->updateListButton->setEnabled(true);
107     m_ui->tableView->resizeRowsToContents();
108     handleSelectionChanged();
109 }
110
111 void MaemoRemoteProcessesDialog::updateProcessList()
112 {
113     m_ui->updateListButton->setEnabled(false);
114     m_ui->killProcessButton->setEnabled(false);
115     m_processList->update();
116 }
117
118 void MaemoRemoteProcessesDialog::killProcess()
119 {
120     const QModelIndexList &indexes
121         = m_ui->tableView->selectionModel()->selectedIndexes();
122     if (indexes.empty())
123         return;
124     m_ui->updateListButton->setEnabled(false);
125     m_ui->killProcessButton->setEnabled(false);
126     m_processList->killProcess(m_proxyModel->mapToSource(indexes.first()).row());
127 }
128
129 void MaemoRemoteProcessesDialog::handleProcessKilled()
130 {
131     updateProcessList();
132 }
133
134 void MaemoRemoteProcessesDialog::handleSelectionChanged()
135 {
136     m_ui->killProcessButton->setEnabled(m_ui->tableView->selectionModel()->hasSelection());
137 }
138
139 } // namespace Internal
140 } // namespace Qt4ProjectManager