refactor(export): streamline export job handling and improve device management

This commit is contained in:
uncor3
2026-02-25 07:57:56 +00:00
parent cfa494b602
commit 561b613087
4 changed files with 23 additions and 20 deletions
+2 -8
View File
@@ -82,15 +82,15 @@ QUuid ExportManager::startExport(iDescriptorDevice *device,
// Create new job
auto job = new ExportJob();
job->jobId = QUuid::createUuid();
job->device = device;
job->items = items;
job->destinationPath = destinationPath;
job->altAfc = altAfc;
job->d_udid = device->udid;
// fixme : pass ExportJob
job->statusBalloonProcessId =
StatusBalloon::sharedInstance()->startExportProcess(
QString("Exporting %1 items").arg(items.size()), items.size(),
QString("Exporting %1 item(s)").arg(items.size()), items.size(),
destinationPath);
// Use ExportManager's own jobId for its internal tracking and signals
@@ -122,12 +122,6 @@ void ExportManager::cancelExport(const QUuid &jobId)
}
}
bool ExportManager::isExporting() const
{
QMutexLocker locker(&m_jobsMutex);
return !m_activeJobs.isEmpty();
}
bool ExportManager::isJobRunning(const QUuid &jobId) const
{
QMutexLocker locker(&m_jobsMutex);
-2
View File
@@ -54,8 +54,6 @@ public:
void cancelExport(const QUuid &jobId);
bool isExporting() const;
bool isJobRunning(const QUuid &jobId) const;
static QString generateUniqueOutputPath(const QString &basePath);
+20 -8
View File
@@ -1,5 +1,6 @@
#include "exportmanagerthread.h"
#include "appcontext.h"
#include "iDescriptor.h"
#include "servicemanager.h"
#include <QDebug>
@@ -10,7 +11,7 @@
// TODO: unfinished
void ExportManagerThread::executeExportJob(ExportJob *job)
{
// FIXME: limit to 1 at a time
// FIXME: limit to 1 at a time per udid/device
QtConcurrent::run([this, job]() { executeExportJobInternal(job); });
}
@@ -43,9 +44,9 @@ void ExportManagerThread::executeExportJobInternal(ExportJob *job)
// emit exportProgress(job->jobId, i + 1, job->items.size(),
// item.suggestedFileName);
ExportResult result = exportSingleItem(
job->device, item, job->destinationPath, job->altAfc,
job->cancelRequested, job->statusBalloonProcessId);
ExportResult result =
exportSingleItem(item, job->destinationPath, job->altAfc,
job->cancelRequested, job->statusBalloonProcessId);
if (result.success) {
summary.successfulItems++;
summary.totalBytesTransferred += result.bytesTransferred;
@@ -53,7 +54,7 @@ void ExportManagerThread::executeExportJobInternal(ExportJob *job)
summary.failedItems++;
}
emit itemExported(job->jobId, result);
emit itemExported(job->statusBalloonProcessId, result);
// // Check for cancellation again after potentially long file
// // operation
@@ -90,9 +91,8 @@ void ExportManagerThread::executeExportJobInternal(ExportJob *job)
}
ExportResult ExportManagerThread::exportSingleItem(
iDescriptorDevice *device, const ExportItem &item,
const QString &destinationDir, std::optional<AfcClientHandle *> altAfc,
std::atomic<bool> &cancelRequested,
const ExportItem &item, const QString &destinationDir,
std::optional<AfcClientHandle *> altAfc, std::atomic<bool> &cancelRequested,
const QUuid &statusBalloonProcessId) // Change parameter name and type
{
ExportResult result;
@@ -119,6 +119,18 @@ ExportResult ExportManagerThread::exportSingleItem(
qDebug() << "About to export file from device:" << item.sourcePathOnDevice
<< "to" << outputPath;
iDescriptorDevice *device =
AppContext::sharedInstance()->getDevice(item.d_udid);
// FIXME: is this way we do it?
if (!device) {
result.errorMessage = QString("Device with UDID %1 not found")
.arg(QString::fromStdString(item.d_udid));
qDebug() << result.errorMessage;
return result;
}
// Export file using ServiceManager
IdeviceFfiError *err = ServiceManager::exportFileToPath(
device, item.sourcePathOnDevice.toUtf8().constData(),
+1 -2
View File
@@ -17,8 +17,7 @@ public:
ExportManagerThread(QObject *parent = nullptr) : QObject(parent) {}
void executeExportJob(ExportJob *job);
ExportResult exportSingleItem(iDescriptorDevice *device,
const ExportItem &item,
ExportResult exportSingleItem(const ExportItem &item,
const QString &destinationDir,
std::optional<AfcClientHandle *> altAfc,
std::atomic<bool> &cancelRequested,