file queue
This commit is contained in:
@@ -369,6 +369,65 @@ double AppController::sendProgress() const
|
||||
return m_sendProgress;
|
||||
}
|
||||
|
||||
QVariantList AppController::pendingFiles() const
|
||||
{
|
||||
return m_pendingFilesList;
|
||||
}
|
||||
|
||||
bool AppController::hasPendingFiles() const
|
||||
{
|
||||
return !m_pendingFilesList.isEmpty();
|
||||
}
|
||||
|
||||
void AppController::addFiles(const QStringList& filePaths)
|
||||
{
|
||||
QMimeDatabase mimeDb;
|
||||
for (const QString& rawPath : filePaths) {
|
||||
QString filePath = rawPath;
|
||||
if (filePath.startsWith(QStringLiteral("file://"))) {
|
||||
filePath = filePath.mid(7);
|
||||
}
|
||||
QFileInfo info(filePath);
|
||||
if (!info.exists() || info.isDir()) {
|
||||
continue;
|
||||
}
|
||||
QVariantMap file;
|
||||
file[QStringLiteral("path")] = info.absoluteFilePath();
|
||||
file[QStringLiteral("fileName")] = info.fileName();
|
||||
file[QStringLiteral("size")] = info.size();
|
||||
file[QStringLiteral("fileType")] = mimeDb.mimeTypeForFile(info).name();
|
||||
m_pendingFilesList.append(file);
|
||||
m_pendingSendPaths.append(info.absoluteFilePath());
|
||||
}
|
||||
emit pendingFilesChanged();
|
||||
}
|
||||
|
||||
void AppController::removePendingFile(int index)
|
||||
{
|
||||
if (index < 0 || index >= m_pendingFilesList.size()) {
|
||||
return;
|
||||
}
|
||||
m_pendingFilesList.removeAt(index);
|
||||
m_pendingSendPaths.removeAt(index);
|
||||
emit pendingFilesChanged();
|
||||
}
|
||||
|
||||
void AppController::clearPendingFiles()
|
||||
{
|
||||
m_pendingFilesList.clear();
|
||||
m_pendingSendPaths.clear();
|
||||
emit pendingFilesChanged();
|
||||
}
|
||||
|
||||
void AppController::sendTo(const QString& deviceFingerprint)
|
||||
{
|
||||
if (m_pendingSendPaths.isEmpty()) {
|
||||
emit sendError(QStringLiteral("No files selected"));
|
||||
return;
|
||||
}
|
||||
sendFiles(deviceFingerprint, m_pendingSendPaths);
|
||||
}
|
||||
|
||||
void AppController::sendFiles(const QString& deviceFingerprint, const QStringList& filePaths)
|
||||
{
|
||||
if (!m_devices.contains(deviceFingerprint)) {
|
||||
@@ -387,7 +446,7 @@ void AppController::sendFiles(const QString& deviceFingerprint, const QStringLis
|
||||
}
|
||||
|
||||
m_currentSendDeviceFingerprint = deviceFingerprint;
|
||||
m_pendingFiles = filePaths;
|
||||
m_pendingSendPaths = filePaths;
|
||||
m_currentFileIndex = 0;
|
||||
m_sendProgress = 0.0;
|
||||
emit sendingChanged();
|
||||
@@ -449,7 +508,8 @@ void AppController::cancelSend()
|
||||
|
||||
m_sessions->cancelSendSession(m_currentSendSessionId);
|
||||
m_currentSendSessionId.clear();
|
||||
m_pendingFiles.clear();
|
||||
m_pendingSendPaths.clear();
|
||||
m_pendingFilesList.clear();
|
||||
m_sendProgress = 0.0;
|
||||
emit sendingChanged();
|
||||
emit sendProgressChanged();
|
||||
@@ -496,7 +556,7 @@ void AppController::onUploadProgress(qint64 sent, qint64 total)
|
||||
{
|
||||
if (total > 0) {
|
||||
double fileProgress = static_cast<double>(sent) / total;
|
||||
int totalFiles = m_pendingFiles.size();
|
||||
int totalFiles = m_pendingSendPaths.size();
|
||||
double overallProgress = (m_currentFileIndex + fileProgress) / totalFiles;
|
||||
m_sendProgress = overallProgress * 100.0;
|
||||
emit sendProgressChanged();
|
||||
@@ -511,7 +571,7 @@ void AppController::onUploadCompleted()
|
||||
|
||||
m_currentFileIndex++;
|
||||
|
||||
if (m_currentFileIndex < m_pendingFiles.size()) {
|
||||
if (m_currentFileIndex < m_pendingSendPaths.size()) {
|
||||
sendNextFile();
|
||||
} else {
|
||||
qDebug() << "[AppController] All files sent successfully";
|
||||
@@ -519,7 +579,10 @@ void AppController::onUploadCompleted()
|
||||
emit sendProgressChanged();
|
||||
emit sendCompleted(m_currentSendSessionId);
|
||||
m_currentSendSessionId.clear();
|
||||
m_pendingFilesList.clear();
|
||||
m_pendingSendPaths.clear();
|
||||
emit sendingChanged();
|
||||
emit pendingFilesChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -534,7 +597,7 @@ void AppController::onUploadError(const QString& error)
|
||||
|
||||
void AppController::sendNextFile()
|
||||
{
|
||||
if (m_currentFileIndex >= m_pendingFiles.size()) {
|
||||
if (m_currentFileIndex >= m_pendingSendPaths.size()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -551,7 +614,7 @@ void AppController::sendNextFile()
|
||||
}
|
||||
|
||||
m_currentSendFileId = fileId;
|
||||
QString filePath = m_pendingFiles[m_currentFileIndex];
|
||||
QString filePath = m_pendingSendPaths[m_currentFileIndex];
|
||||
QString token = session.files[fileId].token;
|
||||
|
||||
LocalSend::Device target = m_devices.value(m_currentSendDeviceFingerprint);
|
||||
|
||||
Reference in New Issue
Block a user