From e3a5e27eb78a7ae828c2c28871332dc878c53c95 Mon Sep 17 00:00:00 2001 From: hjk Date: Tue, 24 Jul 2012 17:02:42 +0200 Subject: [PATCH] debugger: merge local and remote core selection Change-Id: I1659eb5a13283814d307c4b4b7adaec87bbbbe9d Reviewed-by: hjk --- src/plugins/debugger/debugger.pro | 4 +- src/plugins/debugger/debugger.qbs | 4 +- src/plugins/debugger/debuggerdialogs.cpp | 130 ------ src/plugins/debugger/debuggerdialogs.h | 30 -- src/plugins/debugger/debuggerplugin.cpp | 56 +-- src/plugins/debugger/loadcoredialog.cpp | 406 ++++++++++++++++++ ...oadremotecoredialog.h => loadcoredialog.h} | 42 +- src/plugins/debugger/loadremotecoredialog.cpp | 266 ------------ 8 files changed, 447 insertions(+), 491 deletions(-) create mode 100644 src/plugins/debugger/loadcoredialog.cpp rename src/plugins/debugger/{loadremotecoredialog.h => loadcoredialog.h} (63%) delete mode 100644 src/plugins/debugger/loadremotecoredialog.cpp diff --git a/src/plugins/debugger/debugger.pro b/src/plugins/debugger/debugger.pro index eea45580cc4..91992214709 100644 --- a/src/plugins/debugger/debugger.pro +++ b/src/plugins/debugger/debugger.pro @@ -42,7 +42,7 @@ HEADERS += \ debuggerprofileinformation.h \ disassembleragent.h \ disassemblerlines.h \ - loadremotecoredialog.h \ + loadcoredialog.h \ logwindow.h \ memoryagent.h \ moduleshandler.h \ @@ -96,7 +96,7 @@ SOURCES += \ debuggerprofileinformation.cpp \ disassembleragent.cpp \ disassemblerlines.cpp \ - loadremotecoredialog.cpp \ + loadcoredialog.cpp \ logwindow.cpp \ memoryagent.cpp \ moduleshandler.cpp \ diff --git a/src/plugins/debugger/debugger.qbs b/src/plugins/debugger/debugger.qbs index 9b98f2c53aa..dad378f7612 100644 --- a/src/plugins/debugger/debugger.qbs +++ b/src/plugins/debugger/debugger.qbs @@ -75,8 +75,8 @@ QtcPlugin { "disassembleragent.h", "disassemblerlines.cpp", "disassemblerlines.h", - "loadremotecoredialog.cpp", - "loadremotecoredialog.h", + "loadcoredialog.cpp", + "loadcoredialog.h", "localsandexpressionsoptionspage.ui", "localsandexpressionswindow.cpp", "localsandexpressionswindow.h", diff --git a/src/plugins/debugger/debuggerdialogs.cpp b/src/plugins/debugger/debuggerdialogs.cpp index ed5fe952e00..c99c4fe4faa 100644 --- a/src/plugins/debugger/debuggerdialogs.cpp +++ b/src/plugins/debugger/debuggerdialogs.cpp @@ -180,136 +180,6 @@ void ProcessListFilterModel::populate } } - -/////////////////////////////////////////////////////////////////////// -// -// AttachCoreDialog -// -/////////////////////////////////////////////////////////////////////// - -class AttachCoreDialogPrivate -{ -public: - PathChooser *execFileName; - PathChooser *coreFileName; - ProfileChooser *profileComboBox; - PathChooser *overrideStartScriptFileName; - QDialogButtonBox *buttonBox; -}; - -AttachCoreDialog::AttachCoreDialog(QWidget *parent) - : QDialog(parent), d(new AttachCoreDialogPrivate) -{ - setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); - setWindowTitle(tr("Start Debugger")); - - d->coreFileName = new PathChooser(this); - d->coreFileName->setExpectedKind(PathChooser::File); - d->coreFileName->setPromptDialogTitle(tr("Select Core File")); - - d->execFileName = new PathChooser(this); - d->execFileName->setExpectedKind(PathChooser::File); - d->execFileName->setPromptDialogTitle(tr("Select Executable")); - - d->overrideStartScriptFileName = new PathChooser(this); - d->overrideStartScriptFileName->setExpectedKind(PathChooser::File); - d->overrideStartScriptFileName->setPromptDialogTitle(tr("Select Startup Script")); - - d->profileComboBox = new ProfileChooser(this, ProfileChooser::RemoteDebugging); - - QFrame *line = new QFrame(this); - line->setFrameShape(QFrame::HLine); - line->setFrameShadow(QFrame::Sunken); - - d->buttonBox = new QDialogButtonBox(this); - d->buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok); - d->buttonBox->button(QDialogButtonBox::Ok)->setDefault(true); - - QFormLayout *formLayout = new QFormLayout; - formLayout->setContentsMargins(0, 0, 0, 0); - formLayout->setHorizontalSpacing(6); - formLayout->setVerticalSpacing(6); - formLayout->addRow(tr("&Executable:"), d->execFileName); - formLayout->addRow(tr("&Core file:"), d->coreFileName); - formLayout->addRow(tr("&Target:"), d->profileComboBox); - formLayout->addRow(tr("Override &start script:"), d->overrideStartScriptFileName); - - QVBoxLayout *vboxLayout = new QVBoxLayout(this); - vboxLayout->addLayout(formLayout); - vboxLayout->addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding)); - vboxLayout->addWidget(line); - vboxLayout->addWidget(d->buttonBox); - - connect(d->buttonBox, SIGNAL(accepted()), SLOT(accept())); - connect(d->buttonBox, SIGNAL(rejected()), SLOT(reject())); - connect(d->coreFileName, SIGNAL(changed(QString)), SLOT(changed())); - changed(); -} - -AttachCoreDialog::~AttachCoreDialog() -{ - delete d; -} - -QString AttachCoreDialog::executableFile() const -{ - return d->execFileName->path(); -} - -void AttachCoreDialog::setExecutableFile(const QString &fileName) -{ - d->execFileName->setPath(fileName); - changed(); -} - -QString AttachCoreDialog::coreFile() const -{ - return d->coreFileName->path(); -} - -void AttachCoreDialog::setCoreFile(const QString &fileName) -{ - d->coreFileName->setPath(fileName); - changed(); -} - -Id AttachCoreDialog::profileId() const -{ - return d->profileComboBox->currentProfileId(); -} - -void AttachCoreDialog::setProfileIndex(int i) -{ - if (i >= 0 && i < d->profileComboBox->count()) - d->profileComboBox->setCurrentIndex(i); -} - -int AttachCoreDialog::profileIndex() const -{ - return d->profileComboBox->currentIndex(); -} - -QString AttachCoreDialog::overrideStartScript() const -{ - return d->overrideStartScriptFileName->path(); -} - -void AttachCoreDialog::setOverrideStartScript(const QString &scriptName) -{ - d->overrideStartScriptFileName->setPath(scriptName); -} - -bool AttachCoreDialog::isValid() const -{ - return d->profileComboBox->currentIndex() >= 0 && - !coreFile().isEmpty(); -} - -void AttachCoreDialog::changed() -{ - d->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(isValid()); -} - /////////////////////////////////////////////////////////////////////// // // AttachExternalDialog diff --git a/src/plugins/debugger/debuggerdialogs.h b/src/plugins/debugger/debuggerdialogs.h index 3875b8047ec..d97fd9cbe44 100644 --- a/src/plugins/debugger/debuggerdialogs.h +++ b/src/plugins/debugger/debuggerdialogs.h @@ -61,36 +61,6 @@ class StartRemoteDialogPrivate; class StartRemoteEngineDialogPrivate; class StartRemoteParameters; -class AttachCoreDialog : public QDialog -{ - Q_OBJECT - -public: - explicit AttachCoreDialog(QWidget *parent); - ~AttachCoreDialog(); - - void setExecutableFile(const QString &executable); - void setCoreFile(const QString &core); - - QString executableFile() const; - QString coreFile() const; - - int profileIndex() const; - void setProfileIndex(int); - Core::Id profileId() const; - - QString overrideStartScript() const; - void setOverrideStartScript(const QString &scriptName); - -private slots: - void changed(); - -private: - bool isValid() const; - - AttachCoreDialogPrivate *d; -}; - class AttachExternalDialog : public QDialog { Q_OBJECT diff --git a/src/plugins/debugger/debuggerplugin.cpp b/src/plugins/debugger/debuggerplugin.cpp index a0a525ed8f2..3e9acd6409c 100644 --- a/src/plugins/debugger/debuggerplugin.cpp +++ b/src/plugins/debugger/debuggerplugin.cpp @@ -62,7 +62,7 @@ #include "watchutils.h" #include "debuggertooltipmanager.h" #include "localsandexpressionswindow.h" -#include "loadremotecoredialog.h" +#include "loadcoredialog.h" #include "snapshothandler.h" #include "threadshandler.h" @@ -768,7 +768,6 @@ public slots: void startRemoteCdbSession(); void startRemoteProcess(); void startRemoteServer(); - void loadRemoteCoreFile(); //bool queryRemoteParameters(DebuggerStartParameters &sp, bool useScript); void attachToRemoteServer(); void attachToRemoteProcess(); @@ -1121,7 +1120,6 @@ public: QAction *m_attachToRemoteServerAction; QAction *m_startRemoteCdbAction; QAction *m_startRemoteLldbAction; - QAction *m_loadRemoteCoreAction; QAction *m_attachToLocalProcessAction; QAction *m_attachToCoreAction; QAction *m_detachAction; @@ -1564,24 +1562,28 @@ void DebuggerPluginPrivate::attachExternalApplication(RunControl *rc) void DebuggerPluginPrivate::attachCore() { AttachCoreDialog dlg(mainWindow()); - dlg.setExecutableFile(configValue(_("LastExternalExecutableFile")).toString()); - dlg.setCoreFile(configValue(_("LastExternalCoreFile")).toString()); - dlg.setProfileIndex(configValue(_("LastExternalProfileIndex")).toInt()); + + dlg.setProfileId(Id(configValue(_("LastExternalProfile")).toString())); + dlg.setLocalExecutableFile(configValue(_("LastExternalExecutableFile")).toString()); + dlg.setLocalCoreFile(configValue(_("LastLocalCoreFile")).toString()); + dlg.setRemoteCoreFile(configValue(_("LastRemoteCoreFile")).toString()); dlg.setOverrideStartScript(configValue(_("LastExternalStartScript")).toString()); if (dlg.exec() != QDialog::Accepted) return; - setConfigValue(_("LastExternalExecutableFile"), dlg.executableFile()); - setConfigValue(_("LastExternalCoreFile"), dlg.coreFile()); - setConfigValue(_("LastExternalProfileIndex"), QVariant(dlg.profileIndex())); + setConfigValue(_("LastExternalExecutableFile"), dlg.localExecutableFile()); + setConfigValue(_("LastLocalCoreFile"), dlg.localCoreFile()); + setConfigValue(_("LastRemoteCoreFile"), dlg.remoteCoreFile()); + setConfigValue(_("LastExternalProfile"), dlg.profileId().toString()); setConfigValue(_("LastExternalStartScript"), dlg.overrideStartScript()); DebuggerStartParameters sp; + QString display = dlg.isLocal() ? dlg.localCoreFile() : dlg.remoteCoreFile(); fillParameters(&sp, dlg.profileId()); - sp.executable = dlg.executableFile(); - sp.coreFile = dlg.coreFile(); - sp.displayName = tr("Core file \"%1\"").arg(dlg.coreFile()); + sp.executable = dlg.localExecutableFile(); + sp.coreFile = dlg.localCoreFile(); + sp.displayName = tr("Core file \"%1\"").arg(display); sp.startMode = AttachCore; sp.closeMode = DetachAtClose; sp.overrideStartScript = dlg.overrideStartScript(); @@ -1694,27 +1696,6 @@ void DebuggerPluginPrivate::gdbServerStarted(const QString &channel, showStatusMessage(tr("gdbserver is now listening at %1").arg(channel)); } -void DebuggerPluginPrivate::loadRemoteCoreFile() -{ - DebuggerStartParameters sp; - { - QTemporaryFile localCoreFile(QDir::tempPath() + "/remotecore-XXXXXX"); - localCoreFile.open(); - sp.coreFile = localCoreFile.fileName(); - } - LoadRemoteCoreFileDialog dlg(mainWindow()); - dlg.setLocalCoreFileName(sp.coreFile); - if (!dlg.exec()) - return; - fillParameters(&sp, dlg.profileId()); - sp.displayName = tr("Core file \"%1\"").arg(sp.coreFile); - sp.startMode = AttachCore; - sp.closeMode = DetachAtClose; - //sp.overrideStartScript = dlg.overrideStartScript(); - if (DebuggerRunControl *rc = createDebugger(sp)) - startDebugger(rc); -} - void DebuggerPluginPrivate::attachToRemoteProcess() { QObject *rl = PluginManager::getObjectByName(_("RemoteLinuxPlugin")); @@ -3094,10 +3075,6 @@ void DebuggerPluginPrivate::extensionsInitialized() act->setText(tr("Attach to Running Remote Process...")); connect(act, SIGNAL(triggered()), SLOT(attachToRemoteProcess())); - act = m_loadRemoteCoreAction = new QAction(this); - act->setText(tr("Load Remote Core File...")); - connect(act, SIGNAL(triggered()), SLOT(loadRemoteCoreFile())); - act = m_attachToQmlPortAction = new QAction(this); act->setText(tr("Attach to QML Port...")); connect(act, SIGNAL(triggered()), SLOT(attachToQmlPort())); @@ -3182,11 +3159,6 @@ void DebuggerPluginPrivate::extensionsInitialized() cmd->setDescription(tr("Attach to Remote Process")); mstart->addAction(cmd, Debugger::Constants::G_AUTOMATIC_REMOTE); - cmd = ActionManager::registerAction(m_loadRemoteCoreAction, - "Debugger.LoadRemoteCore", globalcontext); - cmd->setDescription(tr("Load Remote Core File")); - mstart->addAction(cmd, Debugger::Constants::G_AUTOMATIC_REMOTE); - #ifdef WITH_LLDB cmd = ActionManager::registerAction(m_startRemoteLldbAction, "Debugger.RemoteLldb", globalcontext); diff --git a/src/plugins/debugger/loadcoredialog.cpp b/src/plugins/debugger/loadcoredialog.cpp new file mode 100644 index 00000000000..20854de7e32 --- /dev/null +++ b/src/plugins/debugger/loadcoredialog.cpp @@ -0,0 +1,406 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: http://www.qt-project.org/ +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +**************************************************************************/ + +#include "loadcoredialog.h" + +#include "debuggerconstants.h" +#include "debuggercore.h" +#include "debuggerstartparameters.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace Core; +using namespace ProjectExplorer; +using namespace QSsh; +using namespace Utils; + +namespace Debugger { +namespace Internal { + +/////////////////////////////////////////////////////////////////////// +// +// SelectRemoteFileDialog +// +/////////////////////////////////////////////////////////////////////// + +class SelectRemoteFileDialog : public QDialog +{ + Q_OBJECT + +public: + explicit SelectRemoteFileDialog(QWidget *parent); + + void attachToDevice(Profile *profile); + QString localFile() const { return m_localFile; } + QString remoteFile() const { return m_remoteFile; } + +private slots: + void handleSftpOperationFinished(QSsh::SftpJobId, const QString &error); + void handleSftpOperationFailed(const QString &errorMessage); + void handleConnectionError(const QString &errorMessage); + void handleRemoteError(const QString &errorMessage); + void selectFile(); + +private: + QSortFilterProxyModel m_model; + SftpFileSystemModel m_fileSystemModel; + QTreeView *m_fileSystemView; + QTextBrowser *m_textBrowser; + QDialogButtonBox *m_buttonBox; + QString m_localFile; + QString m_remoteFile; + SftpJobId m_sftpJobId; +}; + +SelectRemoteFileDialog::SelectRemoteFileDialog(QWidget *parent) + : QDialog(parent) +{ + m_model.setSourceModel(&m_fileSystemModel); + + m_fileSystemView = new QTreeView(this); + m_fileSystemView->setModel(&m_model); + m_fileSystemView->setSortingEnabled(true); + m_fileSystemView->setUniformRowHeights(true); + m_fileSystemView->setSelectionMode(QAbstractItemView::SingleSelection); + m_fileSystemView->setSelectionBehavior(QAbstractItemView::SelectRows); + m_fileSystemView->header()->setDefaultSectionSize(100); + m_fileSystemView->header()->setStretchLastSection(true); + + m_textBrowser = new QTextBrowser(this); + m_textBrowser->setEnabled(false); + + m_buttonBox = new QDialogButtonBox(this); + m_buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok); + m_buttonBox->button(QDialogButtonBox::Ok)->setDefault(true); + m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); + + QVBoxLayout *layout = new QVBoxLayout(this); + layout->addWidget(m_fileSystemView); + layout->addWidget(m_textBrowser); + layout->addWidget(m_buttonBox); + + QObject::connect(m_buttonBox, SIGNAL(rejected()), SLOT(reject())); + QObject::connect(m_buttonBox, SIGNAL(accepted()), SLOT(selectFile())); + + connect(&m_fileSystemModel, SIGNAL(sftpOperationFailed(QString)), + SLOT(handleSftpOperationFailed(QString))); + connect(&m_fileSystemModel, SIGNAL(connectionError(QString)), + SLOT(handleConnectionError(QString))); +} + +void SelectRemoteFileDialog::attachToDevice(Profile *profile) +{ + m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true); + QTC_ASSERT(profile, return); + IDevice::ConstPtr device = DeviceProfileInformation::device(profile); + QTC_ASSERT(device, return); + QSsh::SshConnectionParameters sshParams = device->sshParameters(); + m_fileSystemModel.setSshConnection(sshParams); +} + +void SelectRemoteFileDialog::handleSftpOperationFailed(const QString &errorMessage) +{ + m_textBrowser->append(errorMessage); + //reject(); +} + +void SelectRemoteFileDialog::handleConnectionError(const QString &errorMessage) +{ + m_textBrowser->append(errorMessage); + //reject(); +} + +void SelectRemoteFileDialog::handleSftpOperationFinished(QSsh::SftpJobId, const QString &error) +{ + if (error.isEmpty()) { + m_textBrowser->append(tr("Download of remote file succeeded.")); + accept(); + } else { + m_textBrowser->append(error); + //reject(); + } +} + +void SelectRemoteFileDialog::handleRemoteError(const QString &errorMessage) +{ + m_textBrowser->append(errorMessage); +} + +void SelectRemoteFileDialog::selectFile() +{ + const QModelIndexList indexes = + m_fileSystemView->selectionModel()->selectedIndexes(); + if (indexes.empty()) + return; + + m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); + m_fileSystemView->setEnabled(false); + + connect(&m_fileSystemModel, SIGNAL(sftpOperationFinished(QSsh::SftpJobId,QString)), + SLOT(handleSftpOperationFinished(QSsh::SftpJobId,QString))); + + { + QTemporaryFile localFile(QDir::tempPath() + "/remotecore-XXXXXX"); + localFile.open(); + m_localFile = localFile.fileName(); + } + + QModelIndex idx = indexes.at(0); + idx = idx.sibling(idx.row(), 1); + m_remoteFile = m_fileSystemModel.data(idx, SftpFileSystemModel::PathRole).toString(); + m_sftpJobId = m_fileSystemModel.downloadFile(idx, m_localFile); +} + +/////////////////////////////////////////////////////////////////////// +// +// AttachCoreDialog +// +/////////////////////////////////////////////////////////////////////// + +class AttachCoreDialogPrivate +{ +public: + ProfileChooser *profileChooser; + + QSettings *settings; + + PathChooser *localExecFileName; + PathChooser *localCoreFileName; + QLineEdit *remoteCoreFileName; + QPushButton *selectRemoteCoreButton; + + PathChooser *overrideStartScriptFileName; + + QDialogButtonBox *buttonBox; +}; + +AttachCoreDialog::AttachCoreDialog(QWidget *parent) + : QDialog(parent), d(new AttachCoreDialogPrivate) +{ + setWindowTitle(tr("Load Core File")); + setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); + + d->settings = ICore::settings(); + + d->profileChooser = new ProfileChooser(this); + + d->selectRemoteCoreButton = new QPushButton(tr("Browse..."), this); + d->remoteCoreFileName = new QLineEdit(this); + d->remoteCoreFileName->setEnabled(false); + + d->localCoreFileName = new PathChooser(this); + d->localCoreFileName->setExpectedKind(PathChooser::File); + d->localCoreFileName->setPromptDialogTitle(tr("Select Core File")); + + d->localExecFileName = new PathChooser(this); + d->localExecFileName->setExpectedKind(PathChooser::File); + d->localExecFileName->setPromptDialogTitle(tr("Select Executable")); + + d->overrideStartScriptFileName = new PathChooser(this); + d->overrideStartScriptFileName->setExpectedKind(PathChooser::File); + d->overrideStartScriptFileName->setPromptDialogTitle(tr("Select Startup Script")); + + d->buttonBox = new QDialogButtonBox(this); + d->buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok); + d->buttonBox->button(QDialogButtonBox::Ok)->setDefault(true); + d->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); + + QHBoxLayout *coreLayout = new QHBoxLayout; + coreLayout->addWidget(d->localCoreFileName); + coreLayout->addWidget(d->remoteCoreFileName); + coreLayout->addWidget(d->selectRemoteCoreButton); + + QFormLayout *formLayout = new QFormLayout; + formLayout->setContentsMargins(0, 0, 0, 0); + formLayout->setHorizontalSpacing(6); + formLayout->setVerticalSpacing(6); + formLayout->addRow(tr("Target:"), d->profileChooser); + formLayout->addRow(tr("&Executable:"), d->localExecFileName); + formLayout->addRow(tr("Core file:"), coreLayout); + formLayout->addRow(tr("Override &start script:"), d->overrideStartScriptFileName); + + QFrame *line = new QFrame(this); + line->setFrameShape(QFrame::HLine); + line->setFrameShadow(QFrame::Sunken); + + formLayout->addRow(d->buttonBox); + + QVBoxLayout *vboxLayout = new QVBoxLayout(this); + vboxLayout->addLayout(formLayout); + vboxLayout->addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding)); + vboxLayout->addWidget(line); + vboxLayout->addWidget(d->buttonBox); + + connect(d->selectRemoteCoreButton, SIGNAL(clicked()), SLOT(selectRemoteCoreFile())); + connect(d->remoteCoreFileName, SIGNAL(textChanged(QString)), SLOT(changed())); + connect(d->profileChooser, SIGNAL(activated(int)), SLOT(changed())); + connect(d->buttonBox, SIGNAL(rejected()), SLOT(reject())); + connect(d->buttonBox, SIGNAL(accepted()), SLOT(accept())); +} + +AttachCoreDialog::~AttachCoreDialog() +{ + delete d; +} + +bool AttachCoreDialog::isLocal() const +{ + Profile *profile = d->profileChooser->currentProfile(); + QTC_ASSERT(profile, return false); + IDevice::ConstPtr device = DeviceProfileInformation::device(profile); + QTC_ASSERT(device, return false); + SshConnectionParameters sshParams = device->sshParameters(); + d->settings->setValue(QLatin1String("LastProfile"), + d->profileChooser->currentProfileId().toString()); + return sshParams.host.isEmpty(); +} + +void AttachCoreDialog::changed() +{ + bool isValid = d->profileChooser->currentIndex() >= 0 + && !localCoreFile().isEmpty(); + d->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(isValid); + + if (isLocal()) { + d->localCoreFileName->setVisible(true); + d->remoteCoreFileName->setVisible(false); + d->selectRemoteCoreButton->setVisible(false); + } else { + d->remoteCoreFileName->setVisible(true); + d->selectRemoteCoreButton->setVisible(true); + d->localCoreFileName->setVisible(false); + } +} + +void AttachCoreDialog::selectRemoteCoreFile() +{ + changed(); + QTC_ASSERT(!isLocal(), return); + SelectRemoteFileDialog dlg(this); + dlg.setWindowTitle(tr("Select Remote Core File")); + dlg.attachToDevice(d->profileChooser->currentProfile()); + if (dlg.exec() == QDialog::Rejected) + return; + d->localCoreFileName->setPath(dlg.localFile()); + d->remoteCoreFileName->setText(dlg.remoteFile()); + changed(); +} + +QString AttachCoreDialog::localCoreFile() const +{ + return d->localCoreFileName->path(); +} + +QString AttachCoreDialog::localExecutableFile() const +{ + return d->localExecFileName->path(); +} + +void AttachCoreDialog::setLocalExecutableFile(const QString &fileName) +{ + d->localExecFileName->setPath(fileName); +} + +void AttachCoreDialog::setLocalCoreFile(const QString &fileName) +{ + d->localCoreFileName->setPath(fileName); +} + +void AttachCoreDialog::setRemoteCoreFile(const QString &fileName) +{ + d->remoteCoreFileName->setText(fileName); +} + +QString AttachCoreDialog::remoteCoreFile() const +{ + return d->remoteCoreFileName->text(); +} + +void AttachCoreDialog::setProfileId(const Core::Id &id) +{ + d->profileChooser->setCurrentProfileId(id); + changed(); +} + +Core::Id AttachCoreDialog::profileId() const +{ + return d->profileChooser->currentProfileId(); +} + +QString AttachCoreDialog::overrideStartScript() const +{ + return d->overrideStartScriptFileName->path(); +} + +void AttachCoreDialog::setOverrideStartScript(const QString &scriptName) +{ + d->overrideStartScriptFileName->setPath(scriptName); +} + +} // namespace Internal +} // namespace Debugger + +#include "loadcoredialog.moc" diff --git a/src/plugins/debugger/loadremotecoredialog.h b/src/plugins/debugger/loadcoredialog.h similarity index 63% rename from src/plugins/debugger/loadremotecoredialog.h rename to src/plugins/debugger/loadcoredialog.h index 5bd439b98d8..8bc5460da33 100644 --- a/src/plugins/debugger/loadremotecoredialog.h +++ b/src/plugins/debugger/loadcoredialog.h @@ -28,10 +28,8 @@ ** **************************************************************************/ -#ifndef DEBUGGER_LOADREMOTECOREDIALOG_H -#define DEBUGGER_LOADREMOTECOREDIALOG_H - -#include +#ifndef DEBUGGER_ATTACHCOREDIALOG_H +#define DEBUGGER_ATTACHCOREDIALOG_H #include @@ -40,34 +38,40 @@ namespace Core { class Id; } namespace Debugger { namespace Internal { -class LoadRemoteCoreFileDialogPrivate; +class AttachCoreDialogPrivate; -class LoadRemoteCoreFileDialog : public QDialog +class AttachCoreDialog : public QDialog { Q_OBJECT public: - explicit LoadRemoteCoreFileDialog(QWidget *parent); - ~LoadRemoteCoreFileDialog(); + explicit AttachCoreDialog(QWidget *parent); + ~AttachCoreDialog(); - void setLocalCoreFileName(const QString &fileName); - QString localCoreFileName() const; + QString localExecutableFile() const; + QString localCoreFile() const; + QString remoteCoreFile() const; + QString overrideStartScript() const; + bool isLocal() const; + + // For persistance. Core::Id profileId() const; + void setLocalExecutableFile(const QString &executable); + void setLocalCoreFile(const QString &core); + void setRemoteCoreFile(const QString &core); + void setOverrideStartScript(const QString &scriptName); + void setProfileId(const Core::Id &id); private slots: - void handleSftpOperationFinished(QSsh::SftpJobId, const QString &error); - void handleSftpOperationFailed(const QString &errorMessage); - void handleConnectionError(const QString &errorMessage); - void updateButtons(); - void attachToDevice(int modelIndex); - void handleRemoteError(const QString &errorMessage); - void selectCoreFile(); + void changed(); + void selectRemoteCoreFile(); private: - LoadRemoteCoreFileDialogPrivate *d; + AttachCoreDialogPrivate *d; }; + } // namespace Debugger } // namespace Internal -#endif // DEBUGGER_LOADREMOTECOREDIALOG_H +#endif // DEBUGGER_ATTACHCOREDIALOG_H diff --git a/src/plugins/debugger/loadremotecoredialog.cpp b/src/plugins/debugger/loadremotecoredialog.cpp deleted file mode 100644 index f3fc5aafadc..00000000000 --- a/src/plugins/debugger/loadremotecoredialog.cpp +++ /dev/null @@ -1,266 +0,0 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: http://www.qt-project.org/ -** -** -** GNU Lesser General Public License Usage -** -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this file. -** Please review the following information to ensure the GNU Lesser General -** Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** Other Usage -** -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -**************************************************************************/ - -#include "loadremotecoredialog.h" - -#include "debuggerconstants.h" -#include "debuggercore.h" -#include "debuggerstartparameters.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace Core; -using namespace ProjectExplorer; -using namespace QSsh; -using namespace Utils; - -namespace Debugger { -namespace Internal { - -/////////////////////////////////////////////////////////////////////// -// -// LoadRemoteCoreFileDialog -// -/////////////////////////////////////////////////////////////////////// - -class LoadRemoteCoreFileDialogPrivate -{ -public: - DeviceManagerModel *deviceManagerModel; - - QComboBox *deviceComboBox; - QTreeView *fileSystemView; - QPushButton *loadCoreFileButton; - QTextBrowser *textBrowser; - QPushButton *closeButton; - //PathChooser *sysrootPathChooser; - ProfileChooser *profileChooser; - - QSettings *settings; - QString remoteCommandLine; - QString remoteExecutable; - QString localCoreFile; - - SftpFileSystemModel *fileSystemModel; - SftpJobId sftpJobId; -}; - -LoadRemoteCoreFileDialog::LoadRemoteCoreFileDialog(QWidget *parent) - : QDialog(parent), d(new LoadRemoteCoreFileDialogPrivate) -{ - setWindowTitle(tr("Select Remote Core File")); - - d->settings = ICore::settings(); - - d->deviceComboBox = new QComboBox(this); - - d->profileChooser = new ProfileChooser(this, ProfileChooser::RemoteDebugging); - d->fileSystemModel = new SftpFileSystemModel(this); - - //executablePathChooser = new PathChooser(q); - //executablePathChooser->setExpectedKind(PathChooser::File); - //executablePathChooser->setPromptDialogTitle(tr("Select Executable")); - //executablePathChooser->setPath(settings->value(LastLocalExecutable).toString()); - - d->fileSystemView = new QTreeView(this); - d->fileSystemView->setSortingEnabled(true); - d->fileSystemView->header()->setDefaultSectionSize(100); - d->fileSystemView->header()->setStretchLastSection(true); - d->fileSystemView->setSelectionMode(QAbstractItemView::SingleSelection); - d->fileSystemView->setModel(d->fileSystemModel); - - d->loadCoreFileButton = new QPushButton(this); - d->loadCoreFileButton->setText(tr("&Load Selected Core File")); - - d->closeButton = new QPushButton(this); - d->closeButton->setText(tr("Close")); - - d->textBrowser = new QTextBrowser(this); - d->textBrowser->setEnabled(false); - - QFormLayout *formLayout = new QFormLayout(); - formLayout->addRow(tr("Device:"), d->deviceComboBox); - formLayout->addRow(tr("Target:"), d->profileChooser); - - QHBoxLayout *horizontalLayout2 = new QHBoxLayout(); - horizontalLayout2->addStretch(1); - horizontalLayout2->addWidget(d->loadCoreFileButton); - horizontalLayout2->addWidget(d->closeButton); - - formLayout->addRow(d->fileSystemView); - formLayout->addRow(d->textBrowser); - formLayout->addRow(horizontalLayout2); - setLayout(formLayout); - - d->deviceManagerModel = new DeviceManagerModel(DeviceManager::instance(), this); - - QObject::connect(d->closeButton, SIGNAL(clicked()), this, SLOT(reject())); - - d->deviceComboBox->setModel(d->deviceManagerModel); - d->deviceComboBox->setCurrentIndex(d->settings->value(QLatin1String("LastDevice")).toInt()); - - if (d->deviceManagerModel->rowCount() == 0) { - d->fileSystemView->setEnabled(false); - } else { - d->fileSystemView->setSelectionBehavior(QAbstractItemView::SelectRows); - connect(d->fileSystemView->selectionModel(), - SIGNAL(selectionChanged(QItemSelection,QItemSelection)), - SLOT(updateButtons())); - connect(d->profileChooser, SIGNAL(activated(int)), SLOT(updateButtons())); - connect(d->loadCoreFileButton, SIGNAL(clicked()), SLOT(selectCoreFile())); - connect(d->deviceComboBox, SIGNAL(currentIndexChanged(int)), - SLOT(attachToDevice(int))); - updateButtons(); - attachToDevice(d->deviceComboBox->currentIndex()); - } -} - -LoadRemoteCoreFileDialog::~LoadRemoteCoreFileDialog() -{ - delete d; -} - -void LoadRemoteCoreFileDialog::setLocalCoreFileName(const QString &fileName) -{ - d->localCoreFile = fileName; -} - -QString LoadRemoteCoreFileDialog::localCoreFileName() const -{ - return d->localCoreFile; -} - -Id LoadRemoteCoreFileDialog::profileId() const -{ - return d->profileChooser->currentProfileId(); -} - -void LoadRemoteCoreFileDialog::attachToDevice(int modelIndex) -{ - IDevice::ConstPtr device = d->deviceManagerModel->device(modelIndex); - if (!device) - return; - connect(d->fileSystemModel, SIGNAL(sftpOperationFailed(QString)), - SLOT(handleSftpOperationFailed(QString))); - connect(d->fileSystemModel, SIGNAL(connectionError(QString)), - SLOT(handleConnectionError(QString))); - d->fileSystemModel->setSshConnection(device->sshParameters()); - //d->fileSystemModel->setRootDirectory(d->settings->value(QLatin1String("LastSftpRoot")).toString()); -} - -void LoadRemoteCoreFileDialog::handleSftpOperationFailed(const QString &errorMessage) -{ - d->textBrowser->append(errorMessage); - //reject(); -} - -void LoadRemoteCoreFileDialog::handleConnectionError(const QString &errorMessage) -{ - d->textBrowser->append(errorMessage); - //reject(); -} - -void LoadRemoteCoreFileDialog::handleSftpOperationFinished(QSsh::SftpJobId, const QString &error) -{ - if (error.isEmpty()) { - d->textBrowser->append(tr("Download of Core File succeeded.")); - accept(); - } else { - d->textBrowser->append(error); - //reject(); - } -} - -void LoadRemoteCoreFileDialog::handleRemoteError(const QString &errorMessage) -{ - d->textBrowser->append(errorMessage); - updateButtons(); -} - -void LoadRemoteCoreFileDialog::selectCoreFile() -{ - const QModelIndexList &indexes = - d->fileSystemView->selectionModel()->selectedIndexes(); - if (indexes.empty()) - return; - - d->loadCoreFileButton->setEnabled(false); - d->fileSystemView->setEnabled(false); - - d->settings->setValue(QLatin1String("LastProfile"), - d->profileChooser->currentProfileId().toString()); - d->settings->setValue(QLatin1String("LastDevice"), d->deviceComboBox->currentIndex()); - d->settings->setValue(QLatin1String("LastSftpRoot"), d->fileSystemModel->rootDirectory()); - - connect(d->fileSystemModel, SIGNAL(sftpOperationFinished(QSsh::SftpJobId,QString)), - SLOT(handleSftpOperationFinished(QSsh::SftpJobId,QString))); - d->sftpJobId = d->fileSystemModel->downloadFile(indexes.at(0), d->localCoreFile); -} - -void LoadRemoteCoreFileDialog::updateButtons() -{ - d->loadCoreFileButton->setEnabled(d->fileSystemView->selectionModel()->hasSelection()); -} - -} // namespace Internal -} // namespace Debugger