-
Notifications
You must be signed in to change notification settings - Fork 1
/
AdbDownloadDialog.cpp
95 lines (82 loc) · 2.59 KB
/
AdbDownloadDialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include "AdbDownloadDialog.h"
#include "ui_ProgressDialog.h"
#include "AdbWrapper.h"
#include <QDir>
#include <QDirIterator>
#include <QTimer>
AdbDownloadDialog::AdbDownloadDialog(QWidget *parent, QString deviceId, QString workingPath) :
ProgressDialog(parent),
m_deviceId(deviceId),
m_workingPath(workingPath)
{
setTitle( "Sync ADB..." );
setActionText(QString( "tracks downloaded" ));
}
AdbDownloadDialog::~AdbDownloadDialog()
{
}
bool AdbDownloadDialog::createDownloadList()
{
//Get all names of files from Wahoo device
AdbWrapper *adbWrap = new AdbWrapper( this );
QStringList trackList = adbWrap->trackList( m_deviceId );
delete adbWrap;
if( trackList.empty() )
{
return false;
}
//What are the new files?
m_downloadList.clear();
QDirIterator it( m_workingPath, QStringList() << "*.fit", QDir::Files, QDirIterator::Subdirectories);
QStringList localList;
while( it.hasNext() ) localList << QFileInfo( it.next() ).fileName();
foreach( QString fitFile, trackList )
{
if( !localList.contains( fitFile ) ) m_downloadList << fitFile;
}
//qDebug() << downloadList;
ui->labelInfo->setText( QString( "%1 / %2 %3..." ).arg( 0 ).arg( m_downloadList.size() ).arg( m_actionText ) );
//ui->labelInfo->setText( "Please wait while downloading tracks..." );
//ui->progressBar->setVisible( false );
m_jobs = m_downloadList.size();
m_todo = m_downloadList.size();
return !m_downloadList.isEmpty();
}
void AdbDownloadDialog::downloadFiles()
{
//Create Directory
if( !QDir( m_workingPath + "New/" ).exists() )
QDir().mkdir( m_workingPath + "New/" );
QTimer::singleShot( 0, this, SLOT(downloadFile()) );
}
void AdbDownloadDialog::downloadFile()
{
//Download all files
AdbWrapper *adbWrap = new AdbWrapper( this );
QString fitFile = m_downloadList.first();
{
if( !adbWrap->downloadTrack( m_deviceId, fitFile, m_workingPath + "New/" ) )
{
m_retVal = RetError;
return;
}
if( m_retVal == RetReject )
{
reject();
return;
}
m_todo--;
ui->progressBar->setValue( 100 * ( (double)m_jobs - (double)m_todo ) / (double)m_jobs );
ui->labelInfo->setText( QString( "%1 / %2 %3..." ).arg( m_jobs - m_todo ).arg( m_jobs ).arg( m_actionText ) );
update();
}
delete adbWrap;
m_downloadList.removeFirst();
if(m_downloadList.empty())
{
accept();
m_retVal = RetAccept;
return;
}
QTimer::singleShot( 0, this, SLOT( downloadFile() ) );
}