Skip to content

Commit

Permalink
修复已经下载的内容会重复下载,增加了aria2c的下载,不全
Browse files Browse the repository at this point in the history
  • Loading branch information
dependon committed Oct 25, 2024
1 parent 036f82d commit b56a309
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 7 deletions.
5 changes: 4 additions & 1 deletion src/download/downloadmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ void DownloadManager::processDownloadQueue()
DownloadInfo data = downloadQueue.takeFirst();
data.downloadIngTaskCount = downloadQueue.size();
Q_EMIT downloadStarted(data);

#ifdef Q_OS_LINUX
system(data.dowloadCode.toStdString().c_str());
#else
QProcess process;
process.start(data.dowloadCode);
if (!process.waitForStarted()) {
Expand All @@ -53,6 +55,7 @@ void DownloadManager::processDownloadQueue()
Q_EMIT downloadError(data, tr("Download failed."));
continue;
}
#endif
data.bDownloaded = true;
Q_EMIT downloadFinished(data);
}
Expand Down
32 changes: 27 additions & 5 deletions src/listview/onlineclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ OnlineClient::OnlineClient(QWidget *parent) :
connect(m_downloadManger,&DownloadManager::downloadStarted,this,&OnlineClient::downloadStarted);
connect(m_downloadManger,&DownloadManager::downloadFinished,this,&OnlineClient::downloadFinished);
connect(m_downloadManger,&DownloadManager::downloadError,this,&OnlineClient::downloadError);

ui->label_wTip->setWordWrap(true);
}

OnlineClient::~OnlineClient()
Expand Down Expand Up @@ -141,6 +143,10 @@ bool OnlineClient::downloadFileWithCurl(const QString &oldurl, const QString &ou
QString part2 = url.mid(slashIndex + 1);
QString encodedFilename = QUrl::toPercentEncoding(part2);
command = strWget + " -o "+downlog +" -O " + outputFilePath + " " + part1+"/"+encodedFilename;
if(ui->com_tool->currentText() == "aria2")
{
command = "aria2c -d "+outputFilePath+" "+part1+"/"+encodedFilename + " >> " +downlog;
}
} else {
qDebug() << "未找到'/'";
}
Expand Down Expand Up @@ -246,7 +252,6 @@ void OnlineClient::slotClickedChange(const QString &md5)

void OnlineClient::slotDoubleClickedChange(const QString &md5)
{
ui->label_DownloadCount->setText(QString::number(ui->label_DownloadCount->text().toInt()+1));
slotClickedChange(md5);
QString name = m_datas.value(m_currentMd5).fileName;
QString newName = name.replace(QRegExp("\\s+"), "");
Expand All @@ -258,7 +263,7 @@ void OnlineClient::slotDoubleClickedChange(const QString &md5)
ui->label_DTip->setText(tr("Download Ing....."));
bool isExists = QFileInfo(saveFile).exists();
bool isExistsHtml = QFileInfo(saveHtml).exists();
if(!isExists )
if(isExists )
{
if(QFileInfo(saveFile).size() <10)
{
Expand All @@ -267,19 +272,19 @@ void OnlineClient::slotDoubleClickedChange(const QString &md5)
}
}

if(!isExistsHtml )
if(isExistsHtml )
{
if(QFileInfo(saveHtml).size() <10)
{
QFile(saveHtml).remove();
isExists = false;
isExistsHtml = false;
}
}


if(!isExists && !isExistsHtml)
{

ui->label_DownloadCount->setText(QString::number(ui->label_DownloadCount->text().toInt()+1));
//Q_EMIT dApp->sigSetDownloadIng(false);
QString strExtra;
strExtra = m_currentMd5;
Expand Down Expand Up @@ -563,3 +568,20 @@ void OnlineClient::downloadError(const DownloadInfo &data, const QString &errorM
Q_EMIT dApp->sigDownloadError();
ui->label_DownloadCount->setText(QString::number(data.downloadIngTaskCount));
}

void OnlineClient::on_com_tool_currentIndexChanged(const QString &arg1)
{
if(arg1 == "wget")
{
ui->label_wTip->setText(tr("If unable to download, please check if 'wget' is installed on the command line."));
}
else if(arg1 == "aria2")
{
ui->label_wTip->setText(tr("If unable to download, please check if 'aria2' is installed on the command line.But download html web wallpaper need 'wget' ."));
}
else
{
ui->label_wTip->setText(tr("If unable to download, please check if 'wget' is installed on the command line."));
}
}

2 changes: 2 additions & 0 deletions src/listview/onlineclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ private Q_SLOTS:
void downloadFinished(const DownloadInfo &data);
void downloadError(const DownloadInfo &data, const QString &errorMessage);

void on_com_tool_currentIndexChanged(const QString &arg1);

private:
Ui::OnlineClient *ui;
view *m_viewDowload{nullptr};
Expand Down
35 changes: 34 additions & 1 deletion src/listview/onlineclient.ui
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,39 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_9">
<property name="text">
<string>Download Tool</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="com_tool">
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>100</width>
<height>16777215</height>
</size>
</property>
<item>
<property name="text">
<string>wget</string>
</property>
</item>
<item>
<property name="text">
<string>aria2</string>
</property>
</item>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
Expand All @@ -65,7 +98,7 @@
</layout>
</item>
<item>
<widget class="QLabel" name="label_8">
<widget class="QLabel" name="label_wTip">
<property name="text">
<string>If unable to download, please check if 'wget' is installed on the command line.</string>
</property>
Expand Down

0 comments on commit b56a309

Please sign in to comment.