Commit 4c1dd686 authored by hjk's avatar hjk Committed by Christian Kandeler
Browse files

remotelinux/projectexplorer: move processlist closer to the core



Change-Id: Icc33981a625da093600273f84b681e79a5a4fa22
Reviewed-by: default avatarChristian Kandeler <christian.kandeler@nokia.com>
parent e9a81cad
......@@ -32,13 +32,14 @@
#include "maddedevicetester.h"
#include "maemoconstants.h"
#include <projectexplorer/devicesupport/deviceprocessesdialog.h>
#include <projectexplorer/devicesupport/deviceprocesslist.h>
#include <remotelinux/linuxdevicetestdialog.h>
#include <remotelinux/publickeydeploymentdialog.h>
#include <remotelinux/remotelinuxprocessesdialog.h>
#include <remotelinux/remotelinuxprocesslist.h>
#include <remotelinux/remotelinux_constants.h>
#include <utils/qtcassert.h>
using namespace ProjectExplorer;
using namespace RemoteLinux;
namespace Madde {
......@@ -106,14 +107,14 @@ void MaddeDevice::executeAction(Core::Id actionId, QWidget *parent) const
QTC_ASSERT(actionIds().contains(actionId), return);
QDialog *d = 0;
const LinuxDeviceConfiguration::ConstPtr device
= sharedFromThis().staticCast<const LinuxDeviceConfiguration>();
const IDevice::ConstPtr device = sharedFromThis();
if (actionId == Core::Id(MaddeDeviceTestActionId))
d = new LinuxDeviceTestDialog(device, new MaddeDeviceTester, parent);
else if (actionId == Core::Id(MaddeRemoteProcessesActionId))
d = new RemoteLinuxProcessesDialog(new GenericRemoteLinuxProcessList(device), parent);
d = new DeviceProcessesDialog(new GenericLinuxProcessList(device), parent);
else if (actionId == Core::Id(Constants::GenericDeployKeyToDeviceActionId))
d = PublicKeyDeploymentDialog::createDialog(device, parent);
// FIXME: Leak?
if (d)
d->exec();
}
......
......@@ -27,26 +27,26 @@
**
**************************************************************************/
#include "remotelinuxprocessesdialog.h"
#include "ui_remotelinuxprocessesdialog.h"
#include "remotelinuxprocesslist.h"
#include "devicesupport/deviceprocessesdialog.h"
#include "devicesupport/deviceprocesslist.h"
#include "ui_deviceprocessesdialog.h"
#include <QMessageBox>
#include <QSortFilterProxyModel>
namespace RemoteLinux {
namespace ProjectExplorer {
namespace Internal {
class RemoteLinuxProcessesDialogPrivate
class DeviceProcessesDialogPrivate
{
public:
RemoteLinuxProcessesDialogPrivate(AbstractRemoteLinuxProcessList *processList)
DeviceProcessesDialogPrivate(DeviceProcessList *processList)
: processList(processList)
{
}
Ui::RemoteLinuxProcessesDialog ui;
AbstractRemoteLinuxProcessList * const processList;
Ui::DeviceProcessesDialog ui;
DeviceProcessList * const processList;
QSortFilterProxyModel proxyModel;
};
......@@ -54,9 +54,8 @@ public:
using namespace Internal;
RemoteLinuxProcessesDialog::RemoteLinuxProcessesDialog(AbstractRemoteLinuxProcessList *processList,
QWidget *parent)
: QDialog(parent), d(new RemoteLinuxProcessesDialogPrivate(processList))
DeviceProcessesDialog::DeviceProcessesDialog(DeviceProcessList *processList, QWidget *parent)
: QDialog(parent), d(new DeviceProcessesDialogPrivate(processList))
{
processList->setParent(this);
......@@ -88,32 +87,32 @@ RemoteLinuxProcessesDialog::RemoteLinuxProcessesDialog(AbstractRemoteLinuxProces
updateProcessList();
}
RemoteLinuxProcessesDialog::~RemoteLinuxProcessesDialog()
DeviceProcessesDialog::~DeviceProcessesDialog()
{
delete d;
}
void RemoteLinuxProcessesDialog::handleRemoteError(const QString &errorMsg)
void DeviceProcessesDialog::handleRemoteError(const QString &errorMsg)
{
QMessageBox::critical(this, tr("Remote Error"), errorMsg);
d->ui.updateListButton->setEnabled(true);
handleSelectionChanged();
}
void RemoteLinuxProcessesDialog::handleProcessListUpdated()
void DeviceProcessesDialog::handleProcessListUpdated()
{
d->ui.updateListButton->setEnabled(true);
handleSelectionChanged();
}
void RemoteLinuxProcessesDialog::updateProcessList()
void DeviceProcessesDialog::updateProcessList()
{
d->ui.updateListButton->setEnabled(false);
d->ui.killProcessButton->setEnabled(false);
d->processList->update();
}
void RemoteLinuxProcessesDialog::killProcess()
void DeviceProcessesDialog::killProcess()
{
const QModelIndexList &indexes
= d->ui.treeView->selectionModel()->selectedIndexes();
......@@ -124,12 +123,12 @@ void RemoteLinuxProcessesDialog::killProcess()
d->processList->killProcess(d->proxyModel.mapToSource(indexes.first()).row());
}
void RemoteLinuxProcessesDialog::handleProcessKilled()
void DeviceProcessesDialog::handleProcessKilled()
{
updateProcessList();
}
void RemoteLinuxProcessesDialog::handleSelectionChanged()
void DeviceProcessesDialog::handleSelectionChanged()
{
d->ui.killProcessButton->setEnabled(d->ui.treeView->selectionModel()->hasSelection());
}
......
......@@ -26,28 +26,28 @@
**
**
**************************************************************************/
#ifndef REMOTELINUXPROCESSESDIALOG_H
#define REMOTELINUXPROCESSESDIALOG_H
#include "remotelinux_export.h"
#ifndef DEVICEPROCESSESDIALOG_H
#define DEVICEPROCESSESDIALOG_H
#include "../projectexplorer_export.h"
#include <QDialog>
namespace RemoteLinux {
class AbstractRemoteLinuxProcessList;
namespace ProjectExplorer {
class DeviceProcessList;
namespace Internal {
class RemoteLinuxProcessesDialogPrivate;
} // namespace Internal
namespace Internal { class DeviceProcessesDialogPrivate; }
class REMOTELINUX_EXPORT RemoteLinuxProcessesDialog : public QDialog
class PROJECTEXPLORER_EXPORT DeviceProcessesDialog : public QDialog
{
Q_OBJECT
public:
// Note: The dialog takes ownership of processList.
explicit RemoteLinuxProcessesDialog(AbstractRemoteLinuxProcessList *processList,
QWidget *parent = 0);
~RemoteLinuxProcessesDialog();
explicit DeviceProcessesDialog(DeviceProcessList *processList, QWidget *parent = 0);
~DeviceProcessesDialog();
private slots:
void updateProcessList();
......@@ -58,7 +58,7 @@ private slots:
void handleSelectionChanged();
private:
Internal::RemoteLinuxProcessesDialogPrivate * const d;
Internal::DeviceProcessesDialogPrivate * const d;
};
} // namespace RemoteLinux
......
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>RemoteLinux::Internal::RemoteLinuxProcessesDialog</class>
<widget class="QDialog" name="RemoteLinux::Internal::RemoteLinuxProcessesDialog">
<class>ProjectExplorer::Internal::DeviceProcessesDialog</class>
<widget class="QDialog" name="ProjectExplorer::Internal::DeviceProcessesDialog">
<property name="geometry">
<rect>
<x>0</x>
......@@ -99,7 +99,7 @@
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>RemoteLinux::Internal::RemoteLinuxProcessesDialog</receiver>
<receiver>ProjectExplorer::Internal::DeviceProcessesDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
......@@ -115,7 +115,7 @@
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>RemoteLinux::Internal::RemoteLinuxProcessesDialog</receiver>
<receiver>ProjectExplorer::Internal::DeviceProcessesDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
......
......@@ -27,41 +27,36 @@
**
**************************************************************************/
#include "remotelinuxprocesslist.h"
#include "deviceprocesslist.h"
#include <utils/qtcassert.h>
#include <ssh/sshremoteprocessrunner.h>
using namespace ProjectExplorer;
using namespace QSsh;
namespace RemoteLinux {
namespace ProjectExplorer {
namespace Internal {
namespace {
enum State { Inactive, Listing, Killing };
const char Delimiter0[] = "x--";
const char Delimiter1[] = "---";
} // anonymous namespace
static QString visualizeNull(QString s)
{
return s.replace(QLatin1Char('\0'), QLatin1String("<null>"));
}
class AbstractRemoteLinuxProcessListPrivate
class DeviceProcessListPrivate
{
public:
AbstractRemoteLinuxProcessListPrivate(const IDevice::ConstPtr &devConf)
DeviceProcessListPrivate(const IDevice::ConstPtr &devConf)
: deviceConfiguration(devConf),
state(Inactive)
{
}
{ }
const IDevice::ConstPtr deviceConfiguration;
SshRemoteProcessRunner process;
QList<RemoteProcess> remoteProcesses;
QList<DeviceProcess> remoteProcesses;
QString errorMsg;
State state;
};
......@@ -70,18 +65,17 @@ public:
using namespace Internal;
AbstractRemoteLinuxProcessList::AbstractRemoteLinuxProcessList(const IDevice::ConstPtr &devConfig,
QObject *parent)
: QAbstractTableModel(parent), d(new AbstractRemoteLinuxProcessListPrivate(devConfig))
DeviceProcessList::DeviceProcessList(const IDevice::ConstPtr &devConfig, QObject *parent)
: QAbstractTableModel(parent), d(new DeviceProcessListPrivate(devConfig))
{
}
AbstractRemoteLinuxProcessList::~AbstractRemoteLinuxProcessList()
DeviceProcessList::~DeviceProcessList()
{
delete d;
}
void AbstractRemoteLinuxProcessList::update()
void DeviceProcessList::update()
{
QTC_ASSERT(d->state == Inactive, return);
......@@ -94,7 +88,7 @@ void AbstractRemoteLinuxProcessList::update()
startProcess(listProcessesCommandLine());
}
void AbstractRemoteLinuxProcessList::killProcess(int row)
void DeviceProcessList::killProcess(int row)
{
QTC_ASSERT(row >= 0 && row < d->remoteProcesses.count(), return);
QTC_ASSERT(d->state == Inactive, return);
......@@ -103,19 +97,19 @@ void AbstractRemoteLinuxProcessList::killProcess(int row)
startProcess(killProcessCommandLine(d->remoteProcesses.at(row)));
}
RemoteProcess AbstractRemoteLinuxProcessList::at(int row) const
DeviceProcess DeviceProcessList::at(int row) const
{
return d->remoteProcesses.at(row);
}
int AbstractRemoteLinuxProcessList::rowCount(const QModelIndex &parent) const
int DeviceProcessList::rowCount(const QModelIndex &parent) const
{
return parent.isValid() ? 0 : d->remoteProcesses.count();
}
int AbstractRemoteLinuxProcessList::columnCount(const QModelIndex &) const { return 2; }
int DeviceProcessList::columnCount(const QModelIndex &) const { return 2; }
QVariant AbstractRemoteLinuxProcessList::headerData(int section, Qt::Orientation orientation,
QVariant DeviceProcessList::headerData(int section, Qt::Orientation orientation,
int role) const
{
if (orientation != Qt::Horizontal || role != Qt::DisplayRole || section < 0
......@@ -124,14 +118,14 @@ QVariant AbstractRemoteLinuxProcessList::headerData(int section, Qt::Orientation
return section == 0? tr("PID") : tr("Command Line");
}
QVariant AbstractRemoteLinuxProcessList::data(const QModelIndex &index, int role) const
QVariant DeviceProcessList::data(const QModelIndex &index, int role) const
{
if (!index.isValid() || index.row() >= rowCount(index.parent())
|| index.column() >= columnCount())
return QVariant();
if (role == Qt::DisplayRole || role == Qt::ToolTipRole) {
const RemoteProcess &proc = d->remoteProcesses.at(index.row());
const DeviceProcess &proc = d->remoteProcesses.at(index.row());
if (index.column() == 0)
return proc.pid;
else
......@@ -140,7 +134,7 @@ QVariant AbstractRemoteLinuxProcessList::data(const QModelIndex &index, int role
return QVariant();
}
void AbstractRemoteLinuxProcessList::handleConnectionError()
void DeviceProcessList::handleConnectionError()
{
QTC_ASSERT(d->state != Inactive, return);
......@@ -151,7 +145,7 @@ void AbstractRemoteLinuxProcessList::handleConnectionError()
setFinished();
}
void AbstractRemoteLinuxProcessList::handleRemoteProcessFinished(int exitStatus)
void DeviceProcessList::handleRemoteProcessFinished(int exitStatus)
{
QTC_ASSERT(d->state != Inactive, return);
......@@ -169,7 +163,7 @@ void AbstractRemoteLinuxProcessList::handleRemoteProcessFinished(int exitStatus)
if (d->state == Listing) {
beginResetModel();
const QByteArray remoteStdout = d->process.readAllStandardOutput();
QList<RemoteProcess> processes = buildProcessList(QString::fromUtf8(remoteStdout.data(),
QList<DeviceProcess> processes = buildProcessList(QString::fromUtf8(remoteStdout.data(),
remoteStdout.count()));
if (!processes.isEmpty()) {
beginInsertRows(QModelIndex(), 0, processes.count()-1);
......@@ -200,7 +194,7 @@ void AbstractRemoteLinuxProcessList::handleRemoteProcessFinished(int exitStatus)
setFinished();
}
void AbstractRemoteLinuxProcessList::startProcess(const QString &cmdLine)
void DeviceProcessList::startProcess(const QString &cmdLine)
{
connect(&d->process, SIGNAL(connectionError()), SLOT(handleConnectionError()));
connect(&d->process, SIGNAL(processClosed(int)),
......@@ -209,20 +203,20 @@ void AbstractRemoteLinuxProcessList::startProcess(const QString &cmdLine)
d->process.run(cmdLine.toUtf8(), d->deviceConfiguration->sshParameters());
}
void AbstractRemoteLinuxProcessList::setFinished()
void DeviceProcessList::setFinished()
{
disconnect(&d->process, 0, this, 0);
d->state = Inactive;
}
GenericRemoteLinuxProcessList::GenericRemoteLinuxProcessList(const IDevice::ConstPtr &devConfig,
GenericLinuxProcessList::GenericLinuxProcessList(const IDevice::ConstPtr &devConfig,
QObject *parent)
: AbstractRemoteLinuxProcessList(devConfig, parent)
: DeviceProcessList(devConfig, parent)
{
}
QString GenericRemoteLinuxProcessList::listProcessesCommandLine() const
QString GenericLinuxProcessList::listProcessesCommandLine() const
{
return QString::fromLatin1(
"for dir in `ls -d /proc/[0123456789]*`; do "
......@@ -235,14 +229,14 @@ QString GenericRemoteLinuxProcessList::listProcessesCommandLine() const
"done").arg(Delimiter0).arg(Delimiter1);
}
QString GenericRemoteLinuxProcessList::killProcessCommandLine(const RemoteProcess &process) const
QString GenericLinuxProcessList::killProcessCommandLine(const DeviceProcess &process) const
{
return QLatin1String("kill -9 ") + QString::number(process.pid);
}
QList<RemoteProcess> GenericRemoteLinuxProcessList::buildProcessList(const QString &listProcessesReply) const
QList<DeviceProcess> GenericLinuxProcessList::buildProcessList(const QString &listProcessesReply) const
{
QList<RemoteProcess> processes;
QList<DeviceProcess> processes;
const QStringList lines = listProcessesReply.split(QString::fromLatin1(Delimiter0)
+ QString::fromLatin1(Delimiter1), QString::SkipEmptyParts);
foreach (const QString &line, lines) {
......@@ -272,7 +266,7 @@ QList<RemoteProcess> GenericRemoteLinuxProcessList::buildProcessList(const QStri
+ QLatin1Char(']');
}
RemoteProcess process;
DeviceProcess process;
process.pid = pid;
process.cmdLine = command;
process.exe = elements.at(3);
......@@ -283,7 +277,7 @@ QList<RemoteProcess> GenericRemoteLinuxProcessList::buildProcessList(const QStri
return processes;
}
bool RemoteProcess::operator <(const RemoteProcess &other) const
bool DeviceProcess::operator <(const DeviceProcess &other) const
{
if (pid != other.pid)
return pid < other.pid;
......@@ -292,4 +286,4 @@ bool RemoteProcess::operator <(const RemoteProcess &other) const
return cmdLine < other.cmdLine;
}
} // namespace RemoteLinux
} // namespace ProjectExplorer
......@@ -26,44 +26,43 @@
**
**
**************************************************************************/
#ifndef REMOTELINUXPROCESSLIST_H
#define REMOTELINUXPROCESSLIST_H
#include "remotelinux_export.h"
#ifndef DEVICEPROCESSLIST_H
#define DEVICEPROCESSLIST_H
#include <projectexplorer/devicesupport/idevice.h>
#include "idevice.h"
#include <QAbstractTableModel>
#include <QList>
#include <QSharedPointer>
namespace RemoteLinux {
namespace ProjectExplorer {
namespace Internal {
class AbstractRemoteLinuxProcessListPrivate;
class DeviceProcessListPrivate;
}
class REMOTELINUX_EXPORT RemoteProcess
class PROJECTEXPLORER_EXPORT DeviceProcess
{
public:
RemoteProcess() : pid(0) {}
bool operator<(const RemoteProcess &other) const;
DeviceProcess() : pid(0) {}
bool operator<(const DeviceProcess &other) const;
int pid;
QString cmdLine;
QString exe;
};
class REMOTELINUX_EXPORT AbstractRemoteLinuxProcessList : public QAbstractTableModel
class PROJECTEXPLORER_EXPORT DeviceProcessList : public QAbstractTableModel
{
Q_OBJECT
friend class Internal::AbstractRemoteLinuxProcessListPrivate;
friend class Internal::DeviceProcessListPrivate;
public:
~AbstractRemoteLinuxProcessList();
~DeviceProcessList();
void update();
void killProcess(int row);
RemoteProcess at(int row) const;
DeviceProcess at(int row) const;
signals:
void processListUpdated();
......@@ -71,8 +70,7 @@ signals:
void processKilled();
protected:
AbstractRemoteLinuxProcessList(const ProjectExplorer::IDevice::ConstPtr &devConfig,
QObject *parent = 0);
DeviceProcessList(const IDevice::ConstPtr &devConfig, QObject *parent = 0);
private slots:
void handleConnectionError();
......@@ -86,29 +84,30 @@ private:
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
virtual QString listProcessesCommandLine() const = 0;
virtual QString killProcessCommandLine(const RemoteProcess &process) const = 0;
virtual QList<RemoteProcess> buildProcessList(const QString &listProcessesReply) const = 0;
virtual QString killProcessCommandLine(const DeviceProcess &process) const = 0;
virtual QList<DeviceProcess> buildProcessList(const QString &listProcessesReply) const = 0;
void startProcess(const QString &cmdLine);
void setFinished();
Internal::AbstractRemoteLinuxProcessListPrivate * const d;
Internal::DeviceProcessListPrivate * const d;
};
class REMOTELINUX_EXPORT GenericRemoteLinuxProcessList : public AbstractRemoteLinuxProcessList
class PROJECTEXPLORER_EXPORT GenericLinuxProcessList : public DeviceProcessList
{
Q_OBJECT
public:
GenericRemoteLinuxProcessList(const ProjectExplorer::IDevice::ConstPtr &devConfig,
GenericLinuxProcessList(const IDevice::ConstPtr &devConfig,
QObject *parent = 0);
protected:
QString listProcessesCommandLine() const;
QString killProcessCommandLine(const RemoteProcess &process) const;
QList<RemoteProcess> buildProcessList(const QString &listProcessesReply) const;
QString killProcessCommandLine(const DeviceProcess &process) const;
QList<DeviceProcess> buildProcessList(const QString &listProcessesReply) const;
};
} // namespace RemoteLinux
} // namespace ProjectExplorer
#endif // REMOTELINUXPROCESSLIST_H
#endif // DEVICEPROCESSLIST_H
......@@ -121,6 +121,8 @@ HEADERS += projectexplorer.h \
devicesupport/devicemanager.h \
devicesupport/devicemanagermodel.h \
devicesupport/devicefactoryselectiondialog.h \
devicesupport/deviceprocesslist.h \
devicesupport/deviceprocessesdialog.h \
devicesupport/devicesettingswidget.h \
devicesupport/devicesettingspage.h
......@@ -220,6 +222,8 @@ SOURCES += projectexplorer.cpp \
devicesupport/devicemanager.cpp \
devicesupport/devicemanagermodel.cpp \
devicesupport/devicefactoryselectiondialog.cpp \
devicesupport/deviceprocesslist.cpp \
devicesupport/deviceprocessesdialog.cpp \
devicesupport/devicesettingswidget.cpp \
devicesupport/devicesettingspage.cpp
......@@ -233,6 +237,7 @@ FORMS += processstep.ui \
publishing/publishingwizardselectiondialog.ui \
codestylesettingspropertiespage.ui \
devicesupport/devicefactoryselectiondialog.ui \
devicesupport/deviceprocessesdialog.ui \
devicesupport/devicesettingswidget.ui
WINSOURCES += \
......
......@@ -296,6 +296,11 @@ QtcPlugin {
"devicesupport/devicefactoryselectiondialog.cpp",
"devicesupport/devicefactoryselectiondialog.h",
"devicesupport/devicefactoryselectiondialog.ui",
"devicesupport/deviceprocesslist.cpp",
"devicesupport/deviceprocesslist.h",
"devicesupport/deviceprocessesdialog.cpp",
"devicesupport/deviceprocessesdialog.h",
"devicesupport/deviceprocessesdialog.ui",
"devicesupport/devicesettingswidget.cpp",
"devicesupport/devicesettingswidget.h",
"devicesupport/devicesettingswidget.ui",
......
......@@ -33,16 +33,17 @@
#include "genericlinuxdeviceconfigurationwidget.h"
#include "linuxdevicetestdialog.h"
#include "publickeydeploymentdialog.h"
#include "remotelinuxprocessesdialog.h"
#include "remotelinuxprocesslist.h"
#include "remotelinux_constants.h"
#include <coreplugin/id.h>
#include <utils/portlist.h>
#include <projectexplorer/devicesupport/deviceprocesslist.h>
#include <projectexplorer/devicesupport/deviceprocessesdialog.h>
#include <ssh/sshconnection.h>
#include <utils/portlist.h>
#include <utils/qtcassert.h>
using namespace ProjectExplorer;
namespace RemoteLinux {