From 5715d433f4429a0eca6f8b07e8f2d47af9caf4a1 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Thu, 7 Apr 2022 15:47:32 +0200 Subject: [PATCH] Get rid of SftpFileSystemModel It's being replaced with DeviceFileSystemModel. Change-Id: I062f2a873ecede9755527e8ee7b8b4d578289c4b Reviewed-by: Reviewed-by: Leena Miettinen Reviewed-by: hjk --- src/libs/ssh/CMakeLists.txt | 1 - src/libs/ssh/sftpfilesystemmodel.cpp | 384 ------------------- src/libs/ssh/sftpfilesystemmodel.h | 100 ----- src/libs/ssh/ssh.qbs | 2 - tests/manual/manual.qbs | 1 - tests/manual/ssh/CMakeLists.txt | 1 - tests/manual/ssh/sftpfsmodel/CMakeLists.txt | 18 - tests/manual/ssh/sftpfsmodel/main.cpp | 46 --- tests/manual/ssh/sftpfsmodel/sftpfsmodel.pro | 9 - tests/manual/ssh/sftpfsmodel/sftpfsmodel.qbs | 38 -- tests/manual/ssh/sftpfsmodel/window.cpp | 117 ------ tests/manual/ssh/sftpfsmodel/window.h | 52 --- tests/manual/ssh/sftpfsmodel/window.ui | 201 ---------- tests/manual/ssh/ssh.pro | 2 +- 14 files changed, 1 insertion(+), 971 deletions(-) delete mode 100644 src/libs/ssh/sftpfilesystemmodel.cpp delete mode 100644 src/libs/ssh/sftpfilesystemmodel.h delete mode 100644 tests/manual/ssh/sftpfsmodel/CMakeLists.txt delete mode 100644 tests/manual/ssh/sftpfsmodel/main.cpp delete mode 100644 tests/manual/ssh/sftpfsmodel/sftpfsmodel.pro delete mode 100644 tests/manual/ssh/sftpfsmodel/sftpfsmodel.qbs delete mode 100644 tests/manual/ssh/sftpfsmodel/window.cpp delete mode 100644 tests/manual/ssh/sftpfsmodel/window.h delete mode 100644 tests/manual/ssh/sftpfsmodel/window.ui diff --git a/src/libs/ssh/CMakeLists.txt b/src/libs/ssh/CMakeLists.txt index 290afe5acda..f0722f8083d 100644 --- a/src/libs/ssh/CMakeLists.txt +++ b/src/libs/ssh/CMakeLists.txt @@ -2,7 +2,6 @@ add_qtc_library(QtcSsh DEPENDS Qt5::Core Qt5::Network Qt5::Widgets Utils SOURCES sftpdefs.cpp sftpdefs.h - sftpfilesystemmodel.cpp sftpfilesystemmodel.h sftpsession.cpp sftpsession.h sftptransfer.cpp sftptransfer.h ssh.qrc diff --git a/src/libs/ssh/sftpfilesystemmodel.cpp b/src/libs/ssh/sftpfilesystemmodel.cpp deleted file mode 100644 index 1dedcd3ca47..00000000000 --- a/src/libs/ssh/sftpfilesystemmodel.cpp +++ /dev/null @@ -1,384 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -****************************************************************************/ - -#include "sftpfilesystemmodel.h" - -#include "sftpsession.h" -#include "sshconnection.h" -#include "sshconnectionmanager.h" - -#include -#include - -#include -#include -#include -#include -#include - -namespace QSsh { -namespace Internal { -namespace { - -class SftpDirNode; -class SftpFileNode -{ -public: - SftpFileNode() : parent(nullptr) { } - virtual ~SftpFileNode() { } - - QString path; - SftpFileInfo fileInfo; - SftpDirNode *parent; -}; - -class SftpDirNode : public SftpFileNode -{ -public: - SftpDirNode() : lsState(LsNotYetCalled) { } - ~SftpDirNode() { qDeleteAll(children); } - - enum { LsNotYetCalled, LsRunning, LsFinished } lsState; - QList children; -}; - -typedef QHash DirNodeHash; - -SftpFileNode *indexToFileNode(const QModelIndex &index) -{ - return static_cast(index.internalPointer()); -} - -SftpDirNode *indexToDirNode(const QModelIndex &index) -{ - SftpFileNode * const fileNode = indexToFileNode(index); - QTC_CHECK(fileNode); - return dynamic_cast(fileNode); -} - -} // anonymous namespace - -class SftpFileSystemModelPrivate -{ -public: - SshConnection *sshConnection; - SftpSessionPtr sftpSession; - QString rootDirectory; - SftpFileNode *rootNode; - SftpJobId statJobId; - DirNodeHash lsOps; - QList externalJobs; -}; -} // namespace Internal - -using namespace Internal; - -SftpFileSystemModel::SftpFileSystemModel(QObject *parent) - : QAbstractItemModel(parent), d(new SftpFileSystemModelPrivate) -{ - d->sshConnection = nullptr; - d->rootDirectory = QLatin1Char('/'); - d->rootNode = nullptr; - d->statJobId = SftpInvalidJob; -} - -SftpFileSystemModel::~SftpFileSystemModel() -{ - shutDown(); - delete d; -} - -void SftpFileSystemModel::setSshConnection(const SshConnectionParameters &sshParams) -{ - QTC_ASSERT(!d->sshConnection, return); - d->sshConnection = SshConnectionManager::acquireConnection(sshParams); - connect(d->sshConnection, &SshConnection::errorOccurred, - this, &SftpFileSystemModel::handleSshConnectionFailure); - if (d->sshConnection->state() == SshConnection::Connected) { - handleSshConnectionEstablished(); - return; - } - connect(d->sshConnection, &SshConnection::connected, - this, &SftpFileSystemModel::handleSshConnectionEstablished); - if (d->sshConnection->state() == SshConnection::Unconnected) - d->sshConnection->connectToHost(); -} - -void SftpFileSystemModel::setRootDirectory(const QString &path) -{ - beginResetModel(); - d->rootDirectory = path; - delete d->rootNode; - d->rootNode = nullptr; - d->lsOps.clear(); - d->statJobId = SftpInvalidJob; - endResetModel(); - statRootDirectory(); -} - -QString SftpFileSystemModel::rootDirectory() const -{ - return d->rootDirectory; -} - -SftpJobId SftpFileSystemModel::downloadFile(const QModelIndex &index, const QString &targetFilePath) -{ - QTC_ASSERT(d->rootNode, return SftpInvalidJob); - const SftpFileNode * const fileNode = indexToFileNode(index); - QTC_ASSERT(fileNode, return SftpInvalidJob); - QTC_ASSERT(fileNode->fileInfo.type == FileTypeRegular, return SftpInvalidJob); - const SftpJobId jobId = d->sftpSession->downloadFile(fileNode->path, targetFilePath); - if (jobId != SftpInvalidJob) - d->externalJobs << jobId; - return jobId; -} - -int SftpFileSystemModel::columnCount(const QModelIndex &parent) const -{ - Q_UNUSED(parent) - return 2; // type + name -} - -QVariant SftpFileSystemModel::data(const QModelIndex &index, int role) const -{ - const SftpFileNode * const node = indexToFileNode(index); - if (index.column() == 0 && role == Qt::DecorationRole) { - switch (node->fileInfo.type) { - case FileTypeRegular: - case FileTypeOther: - return Utils::Icons::UNKNOWN_FILE.icon(); - case FileTypeDirectory: - return Utils::Icons::DIR.icon(); - case FileTypeUnknown: - return QIcon(":/ssh/images/help.png"); // Shows a question mark. - } - } - if (index.column() == 1) { - if (role == Qt::DisplayRole) - return node->fileInfo.name; - if (role == PathRole) - return node->path; - } - return QVariant(); -} - -Qt::ItemFlags SftpFileSystemModel::flags(const QModelIndex &index) const -{ - if (!index.isValid()) - return Qt::NoItemFlags; - return Qt::ItemIsSelectable | Qt::ItemIsEnabled; -} - -QVariant SftpFileSystemModel::headerData(int section, Qt::Orientation orientation, int role) const -{ - if (orientation != Qt::Horizontal) - return QVariant(); - if (role != Qt::DisplayRole) - return QVariant(); - if (section == 0) - return tr("File Type"); - if (section == 1) - return tr("File Name"); - return QVariant(); -} - -QModelIndex SftpFileSystemModel::index(int row, int column, const QModelIndex &parent) const -{ - if (row < 0 || row >= rowCount(parent) || column < 0 || column >= columnCount(parent)) - return QModelIndex(); - if (!d->rootNode) - return QModelIndex(); - if (!parent.isValid()) - return createIndex(row, column, d->rootNode); - const SftpDirNode * const parentNode = indexToDirNode(parent); - QTC_ASSERT(parentNode, return QModelIndex()); - QTC_ASSERT(row < parentNode->children.count(), return QModelIndex()); - SftpFileNode * const childNode = parentNode->children.at(row); - return createIndex(row, column, childNode); -} - -QModelIndex SftpFileSystemModel::parent(const QModelIndex &child) const -{ - if (!child.isValid()) // Don't assert on this, since the model tester tries it. - return QModelIndex(); - - const SftpFileNode * const childNode = indexToFileNode(child); - QTC_ASSERT(childNode, return QModelIndex()); - if (childNode == d->rootNode) - return QModelIndex(); - SftpDirNode * const parentNode = childNode->parent; - if (parentNode == d->rootNode) - return createIndex(0, 0, d->rootNode); - const SftpDirNode * const grandParentNode = parentNode->parent; - QTC_ASSERT(grandParentNode, return QModelIndex()); - return createIndex(grandParentNode->children.indexOf(parentNode), 0, parentNode); -} - -int SftpFileSystemModel::rowCount(const QModelIndex &parent) const -{ - if (!d->rootNode) - return 0; - if (!parent.isValid()) - return 1; - if (parent.column() != 0) - return 0; - SftpDirNode * const dirNode = indexToDirNode(parent); - if (!dirNode) - return 0; - if (dirNode->lsState != SftpDirNode::LsNotYetCalled) - return dirNode->children.count(); - d->lsOps.insert(d->sftpSession->ls(dirNode->path), dirNode); - dirNode->lsState = SftpDirNode::LsRunning; - return 0; -} - -void SftpFileSystemModel::statRootDirectory() -{ - d->statJobId = d->sftpSession->ls(d->rootDirectory); -} - -void SftpFileSystemModel::shutDown() -{ - if (d->sftpSession) { - disconnect(d->sftpSession.get(), nullptr, this, nullptr); - d->sftpSession->quit(); - d->sftpSession.release()->deleteLater(); - } - if (d->sshConnection) { - disconnect(d->sshConnection, nullptr, this, nullptr); - SshConnectionManager::releaseConnection(d->sshConnection); - d->sshConnection = nullptr; - } - delete d->rootNode; - d->rootNode = nullptr; -} - -void SftpFileSystemModel::handleSshConnectionFailure() -{ - emit connectionError(d->sshConnection->errorString()); - beginResetModel(); - shutDown(); - endResetModel(); -} - -void SftpFileSystemModel::handleSftpChannelInitialized() -{ - connect(d->sftpSession.get(), &SftpSession::fileInfoAvailable, - this, &SftpFileSystemModel::handleFileInfo); - connect(d->sftpSession.get(), &SftpSession::commandFinished, - this, &SftpFileSystemModel::handleSftpJobFinished); - statRootDirectory(); -} - -void SftpFileSystemModel::handleSshConnectionEstablished() -{ - d->sftpSession = d->sshConnection->createSftpSession(); - connect(d->sftpSession.get(), &SftpSession::started, - this, &SftpFileSystemModel::handleSftpChannelInitialized); - connect(d->sftpSession.get(), &SftpSession::done, - this, &SftpFileSystemModel::handleSftpSessionClosed); - d->sftpSession->start(); -} - -void SftpFileSystemModel::handleSftpSessionClosed(const QString &reason) -{ - emit connectionError(reason); - beginResetModel(); - shutDown(); - endResetModel(); -} - -void SftpFileSystemModel::handleFileInfo(SftpJobId jobId, const QList &fileInfoList) -{ - if (jobId == d->statJobId) { - QTC_ASSERT(!d->rootNode, return); - beginInsertRows(QModelIndex(), 0, 0); - d->rootNode = new SftpDirNode; - d->rootNode->path = d->rootDirectory; - d->rootNode->fileInfo.type = FileTypeDirectory; - d->rootNode->fileInfo.name = d->rootDirectory == QLatin1String("/") - ? d->rootDirectory : QFileInfo(d->rootDirectory).fileName(); - endInsertRows(); - return; - } - SftpDirNode * const parentNode = d->lsOps.value(jobId); - QTC_ASSERT(parentNode, return); - QList filteredList; - foreach (const SftpFileInfo &fi, fileInfoList) { - if (fi.name != QLatin1String(".") && fi.name != QLatin1String("..")) - filteredList << fi; - } - if (filteredList.isEmpty()) - return; - - // In theory beginInsertRows() should suffice, but that fails to have an effect - // if rowCount() returned 0 earlier. - emit layoutAboutToBeChanged(); - - foreach (const SftpFileInfo &fileInfo, filteredList) { - SftpFileNode *childNode; - if (fileInfo.type == FileTypeDirectory) - childNode = new SftpDirNode; - else - childNode = new SftpFileNode; - childNode->path = parentNode->path; - if (!childNode->path.endsWith(QLatin1Char('/'))) - childNode->path += QLatin1Char('/'); - childNode->path += fileInfo.name; - childNode->fileInfo = fileInfo; - childNode->parent = parentNode; - parentNode->children << childNode; - } - emit layoutChanged(); // Should be endInsertRows(), see above. -} - -void SftpFileSystemModel::handleSftpJobFinished(SftpJobId jobId, const QString &errorMessage) -{ - if (jobId == d->statJobId) { - d->statJobId = SftpInvalidJob; - if (!errorMessage.isEmpty()) - emit sftpOperationFailed(tr("Error listing root directory \"%1\": %2") - .arg(rootDirectory(), errorMessage)); - return; - } - - DirNodeHash::Iterator it = d->lsOps.find(jobId); - if (it != d->lsOps.end()) { - QTC_ASSERT(it.value()->lsState == SftpDirNode::LsRunning, return); - it.value()->lsState = SftpDirNode::LsFinished; - if (!errorMessage.isEmpty()) - emit sftpOperationFailed(tr("Error listing contents of directory \"%1\": %2") - .arg(it.value()->path, errorMessage)); - d->lsOps.erase(it); - return; - } - - const int jobIndex = d->externalJobs.indexOf(jobId); - QTC_ASSERT(jobIndex != -1, return); - d->externalJobs.removeAt(jobIndex); - emit sftpOperationFinished(jobId, errorMessage); -} - -} // namespace QSsh diff --git a/src/libs/ssh/sftpfilesystemmodel.h b/src/libs/ssh/sftpfilesystemmodel.h deleted file mode 100644 index ea16568d933..00000000000 --- a/src/libs/ssh/sftpfilesystemmodel.h +++ /dev/null @@ -1,100 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -****************************************************************************/ - -#pragma once - -#include "sftpdefs.h" - -#include "ssh_global.h" - -#include - -namespace QSsh { -class SshConnectionParameters; - -namespace Internal { class SftpFileSystemModelPrivate; } - -// Very simple read-only model. Symbolic links are not followed. -class QSSH_EXPORT SftpFileSystemModel : public QAbstractItemModel -{ - Q_OBJECT -public: - explicit SftpFileSystemModel(QObject *parent = nullptr); - ~SftpFileSystemModel(); - - /* - * Once this is called, an SFTP connection is established and the model is populated. - * The effect of additional calls is undefined. - */ - void setSshConnection(const SshConnectionParameters &sshParams); - - void setRootDirectory(const QString &path); // Default is "/". - QString rootDirectory() const; - - SftpJobId downloadFile(const QModelIndex &index, const QString &targetFilePath); - - // Use this to get the full path of a file or directory. - static const int PathRole = Qt::UserRole; - QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; - -signals: - /* - * E.g. "Permission denied". Note that this can happen without direct user intervention, - * due to e.g. the view calling rowCount() on a non-readable directory. This signal should - * therefore not result in a message box or similar, since it might occur very often. - */ - void sftpOperationFailed(const QString &errorMessage); - - /* - * This error is not recoverable. The model will not have any content after - * the signal has been emitted. - */ - void connectionError(const QString &errorMessage); - - // Success <=> error.isEmpty(). - void sftpOperationFinished(QSsh::SftpJobId, const QString &error); - -private: - void handleSshConnectionEstablished(); - void handleSshConnectionFailure(); - void handleSftpChannelInitialized(); - void handleSftpSessionClosed(const QString &reason); - void handleFileInfo(QSsh::SftpJobId jobId, const QList &fileInfoList); - void handleSftpJobFinished(QSsh::SftpJobId jobId, const QString &errorMessage); - - int columnCount(const QModelIndex &parent = QModelIndex()) const override; - Qt::ItemFlags flags(const QModelIndex &index) const override; - QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; - QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; - QModelIndex parent(const QModelIndex &child) const override; - int rowCount(const QModelIndex &parent = QModelIndex()) const override; - - void statRootDirectory(); - void shutDown(); - - Internal::SftpFileSystemModelPrivate * const d; -}; - -} // namespace QSsh; diff --git a/src/libs/ssh/ssh.qbs b/src/libs/ssh/ssh.qbs index 295117c0714..2c96156a6d9 100644 --- a/src/libs/ssh/ssh.qbs +++ b/src/libs/ssh/ssh.qbs @@ -19,8 +19,6 @@ Project { files: [ "sftpdefs.cpp", "sftpdefs.h", - "sftpfilesystemmodel.cpp", - "sftpfilesystemmodel.h", "sftpsession.cpp", "sftpsession.h", "sftptransfer.cpp", diff --git a/tests/manual/manual.qbs b/tests/manual/manual.qbs index 5a5bddbf29d..625138c49a3 100644 --- a/tests/manual/manual.qbs +++ b/tests/manual/manual.qbs @@ -14,7 +14,6 @@ Project { "proparser/testreader.qbs", "shootout/shootout.qbs", "ssh/shell/shell.qbs", - "ssh/sftpfsmodel/sftpfsmodel.qbs", "widgets/widgets.qbs", ] } diff --git a/tests/manual/ssh/CMakeLists.txt b/tests/manual/ssh/CMakeLists.txt index 91464d83178..b6b516e6347 100644 --- a/tests/manual/ssh/CMakeLists.txt +++ b/tests/manual/ssh/CMakeLists.txt @@ -1,2 +1 @@ -add_subdirectory(sftpfsmodel) add_subdirectory(shell) diff --git a/tests/manual/ssh/sftpfsmodel/CMakeLists.txt b/tests/manual/ssh/sftpfsmodel/CMakeLists.txt deleted file mode 100644 index 3e6119cd911..00000000000 --- a/tests/manual/ssh/sftpfsmodel/CMakeLists.txt +++ /dev/null @@ -1,18 +0,0 @@ -file(RELATIVE_PATH RELATIVE_TEST_PATH "${PROJECT_BINARY_DIR}" "${CMAKE_CURRENT_BINARY_DIR}") -file(RELATIVE_PATH TEST_RELATIVE_LIBEXEC_PATH "/${RELATIVE_TEST_PATH}" "/${IDE_LIBEXEC_PATH}") - -add_qtc_test(tst_manual_sftpfsmodel - MANUALTEST - DEPENDS Utils QtcSsh Qt5::Widgets - INCLUDES "${PROJECT_SOURCE_DIR}/src/shared/modeltest" - DEFINES "TEST_RELATIVE_LIBEXEC_PATH=\"${TEST_RELATIVE_LIBEXEC_PATH}\"" - SOURCES - main.cpp - window.cpp window.h window.ui -) - -extend_qtc_test(tst_manual_sftpfsmodel - SOURCES_PREFIX "${PROJECT_SOURCE_DIR}/src/shared/modeltest/" - SOURCES - modeltest.cpp modeltest.h -) diff --git a/tests/manual/ssh/sftpfsmodel/main.cpp b/tests/manual/ssh/sftpfsmodel/main.cpp deleted file mode 100644 index 15fa8535fac..00000000000 --- a/tests/manual/ssh/sftpfsmodel/main.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -****************************************************************************/ - -#include "window.h" - -#include -#include -#include -#include - -#include -#include - -int main(int argc, char *argv[]) -{ - QApplication app(argc, argv); - Utils::LauncherInterface::setPathToLauncher(qApp->applicationDirPath() + '/' - + QLatin1String(TEST_RELATIVE_LIBEXEC_PATH)); - Utils::TemporaryDirectory::setMasterTemporaryDirectory(QDir::tempPath() - + "/qtc-ssh-shelltest-XXXXXX"); - SftpFsWindow w; - w.show(); - return app.exec(); -} diff --git a/tests/manual/ssh/sftpfsmodel/sftpfsmodel.pro b/tests/manual/ssh/sftpfsmodel/sftpfsmodel.pro deleted file mode 100644 index e768e8ea691..00000000000 --- a/tests/manual/ssh/sftpfsmodel/sftpfsmodel.pro +++ /dev/null @@ -1,9 +0,0 @@ -include(../ssh.pri) -include(../../../../src/shared/modeltest/modeltest.pri) - -QT += widgets - -TARGET=sftpfsmodel -SOURCES+=main.cpp window.cpp -HEADERS+=window.h -FORMS=window.ui diff --git a/tests/manual/ssh/sftpfsmodel/sftpfsmodel.qbs b/tests/manual/ssh/sftpfsmodel/sftpfsmodel.qbs deleted file mode 100644 index 1216d806ec1..00000000000 --- a/tests/manual/ssh/sftpfsmodel/sftpfsmodel.qbs +++ /dev/null @@ -1,38 +0,0 @@ -import qbs -import qbs.FileInfo - -QtcManualtest { - name: "Manual sftpfs model test" - condition: qbs.targetOS.contains("unix") - Depends { name: "Utils" } - Depends { name: "QtcSsh" } - Depends { name: "Qt.widgets" } - - cpp.includePaths: [ "../../../../src/shared/modeltest" ] - - cpp.defines: { - var defines = base; - var absLibExecPath = FileInfo.joinPaths(qbs.installRoot, qbs.installPrefix, - qtc.ide_libexec_path); - var relLibExecPath = FileInfo.relativePath(destinationDirectory, absLibExecPath); - defines.push('TEST_RELATIVE_LIBEXEC_PATH="' + relLibExecPath + '"'); - return defines; - } - - files: [ - "main.cpp", - "window.cpp", - "window.h", - "window.ui", - ] - - Group { - name: "Model test files" - prefix: "../../../../src/shared/modeltest/" - - files: [ - "modeltest.cpp", - "modeltest.h" - ] - } -} diff --git a/tests/manual/ssh/sftpfsmodel/window.cpp b/tests/manual/ssh/sftpfsmodel/window.cpp deleted file mode 100644 index 997d60787b6..00000000000 --- a/tests/manual/ssh/sftpfsmodel/window.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -****************************************************************************/ - -#include "window.h" -#include "ui_window.h" - -#include "modeltest.h" - -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -using namespace QSsh; - -SftpFsWindow::SftpFsWindow(QWidget *parent) : QDialog(parent), m_ui(new Ui::Window) -{ - m_ui->setupUi(this); - connect(m_ui->connectButton, &QAbstractButton::clicked, this, &SftpFsWindow::connectToHost); - connect(m_ui->downloadButton, &QAbstractButton::clicked, this, &SftpFsWindow::downloadFile); -} - -SftpFsWindow::~SftpFsWindow() -{ - delete m_ui; -} - -void SftpFsWindow::connectToHost() -{ - m_ui->connectButton->setEnabled(false); - SshConnectionParameters sshParams; - sshParams.setHost(m_ui->hostLineEdit->text()); - sshParams.setUserName(m_ui->userLineEdit->text()); - sshParams.authenticationType - = SshConnectionParameters::AuthenticationTypeAll; - sshParams.setPort(m_ui->portSpinBox->value()); - sshParams.timeout = 10; - m_fsModel = new SftpFileSystemModel(this); - if (m_ui->useModelTesterCheckBox->isChecked()) - new ModelTest(m_fsModel, this); - connect(m_fsModel, &SftpFileSystemModel::sftpOperationFailed, - this, &SftpFsWindow::handleSftpOperationFailed); - connect(m_fsModel, &SftpFileSystemModel::connectionError, - this, &SftpFsWindow::handleConnectionError); - connect(m_fsModel, &SftpFileSystemModel::sftpOperationFinished, - this, &SftpFsWindow::handleSftpOperationFinished); - m_fsModel->setSshConnection(sshParams); - m_ui->fsView->setModel(m_fsModel); -} - -void SftpFsWindow::downloadFile() -{ - const QModelIndexList selectedIndexes = m_ui->fsView->selectionModel()->selectedIndexes(); - if (selectedIndexes.count() != 2) - return; - const QString targetFilePath = QFileDialog::getSaveFileName(this, tr("Choose Target File"), - QDir::tempPath()); - if (targetFilePath.isEmpty()) - return; - const SftpJobId jobId = m_fsModel->downloadFile(selectedIndexes.at(1), targetFilePath); - QString message; - if (jobId == SftpInvalidJob) - message = tr("Download failed."); - else - message = tr("Queuing download operation %1.").arg(jobId); - m_ui->outputTextEdit->appendPlainText(message); -} - -void SftpFsWindow::handleSftpOperationFailed(const QString &errorMessage) -{ - m_ui->outputTextEdit->appendPlainText(errorMessage); -} - -void SftpFsWindow::handleSftpOperationFinished(SftpJobId jobId, const QString &error) -{ - QString message; - if (error.isEmpty()) - message = tr("Operation %1 finished successfully.").arg(jobId); - else - message = tr("Operation %1 failed: %2.").arg(jobId).arg(error); - m_ui->outputTextEdit->appendPlainText(message); -} - -void SftpFsWindow::handleConnectionError(const QString &errorMessage) -{ - QMessageBox::warning(this, tr("Connection Error"), - tr("Fatal SSH error: %1").arg(errorMessage)); - QCoreApplication::quit(); -} diff --git a/tests/manual/ssh/sftpfsmodel/window.h b/tests/manual/ssh/sftpfsmodel/window.h deleted file mode 100644 index d3ba03c1345..00000000000 --- a/tests/manual/ssh/sftpfsmodel/window.h +++ /dev/null @@ -1,52 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -****************************************************************************/ - -#include - -#include - -QT_BEGIN_NAMESPACE -namespace Ui { class Window; } -QT_END_NAMESPACE - -namespace QSsh { class SftpFileSystemModel; } - -class SftpFsWindow : public QDialog -{ - Q_OBJECT -public: - SftpFsWindow(QWidget *parent = 0); - ~SftpFsWindow(); - -private: - void connectToHost(); - void downloadFile(); - void handleConnectionError(const QString &errorMessage); - void handleSftpOperationFailed(const QString &errorMessage); - void handleSftpOperationFinished(QSsh::SftpJobId jobId, const QString &error); - - QSsh::SftpFileSystemModel *m_fsModel; - Ui::Window *m_ui; -}; diff --git a/tests/manual/ssh/sftpfsmodel/window.ui b/tests/manual/ssh/sftpfsmodel/window.ui deleted file mode 100644 index 314236daa69..00000000000 --- a/tests/manual/ssh/sftpfsmodel/window.ui +++ /dev/null @@ -1,201 +0,0 @@ - - - Window - - - - 0 - 0 - 546 - 676 - - - - Dialog - - - - - - Connection Parameters - - - - - - Remote host: - - - - - - - - - - User: - - - - - - - - - - Port: - - - - - - - - - 22 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - - Use model tester - - - - - - - Remote File System - - - - - - - - - 1 - 1 - - - - - - - - - - Connect - - - - - - - Download... - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - - - - - Debug output - - - - - - - - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Close - - - - - - - - - - - buttonBox - rejected() - Window - reject() - - - 316 - 260 - - - 286 - 274 - - - - - buttonBox - accepted() - Window - accept() - - - 248 - 254 - - - 157 - 274 - - - - - diff --git a/tests/manual/ssh/ssh.pro b/tests/manual/ssh/ssh.pro index 1801bd1d9b0..9efd266c1ee 100644 --- a/tests/manual/ssh/ssh.pro +++ b/tests/manual/ssh/ssh.pro @@ -5,4 +5,4 @@ #------------------------------------------------- TEMPLATE = subdirs -SUBDIRS = shell sftpfsmodel +SUBDIRS = shell