SSH: Add download capability to SftpFileSystemModel.

Change-Id: I156fa2ecc179f7f9a75ea0c1357b7e6881f5740f
Reviewed-by: hjk <qthjk@ovi.com>
This commit is contained in:
Christian Kandeler
2012-02-06 12:03:08 +01:00
committed by hjk
parent 051569b998
commit 05aa2b01fe
5 changed files with 142 additions and 31 deletions

View File

@@ -94,6 +94,7 @@ public:
SftpFileNode *rootNode;
SftpJobId statJobId;
DirNodeHash lsOps;
QList<SftpJobId> externalJobs;
};
} // namespace Internal
@@ -143,6 +144,19 @@ 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->sftpChannel->downloadFile(fileNode->path, targetFilePath,
SftpOverwriteExisting);
if (jobId != SftpInvalidJob)
d->externalJobs << jobId;
return jobId;
}
int SftpFileSystemModel::columnCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
@@ -344,21 +358,29 @@ void SftpFileSystemModel::handleFileInfo(SftpJobId jobId, const QList<SftpFileIn
void SftpFileSystemModel::handleSftpJobFinished(SftpJobId jobId, const QString &errorMessage)
{
QString path;
if (jobId == d->statJobId) {
d->statJobId = SftpInvalidJob;
path = rootDirectory();
} else {
DirNodeHash::Iterator it = d->lsOps.find(jobId);
QTC_ASSERT(it != d->lsOps.end(), return);
QTC_CHECK(it.value()->lsState == SftpDirNode::LsRunning);
it.value()->lsState = SftpDirNode::LsFinished;
path = it.value()->path;
d->lsOps.erase(it);
if (!errorMessage.isEmpty())
emit sftpOperationFailed(tr("Error getting 'stat' info about '%1': %2")
.arg(rootDirectory(), errorMessage));
return;
}
if (!errorMessage.isEmpty())
emit sftpOperationFailed(tr("Error reading '%1': %2").arg(path, errorMessage));
DirNodeHash::Iterator it = d->lsOps.find(jobId);
if (it != d->lsOps.end()) {
QTC_CHECK(it.value()->lsState == SftpDirNode::LsRunning);
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 Utils