Select preferred download url from feed's source.

This commit is contained in:
MichaelBeeu 2014-04-27 13:08:45 -05:00
parent 74a2920791
commit 53d5c1c579
3 changed files with 19 additions and 3 deletions

View File

@ -75,6 +75,21 @@ QStringList ZealDocsetMetadata::getUrls() const {
return urls;
}
QString ZealDocsetMetadata::getPrimaryUrl() const {
// Find preferred mirror from feed url host
QUrl feedUrl(getFeedURL());
QRegExp regex("[^:]+://"+feedUrl.host().replace(".", "\\.")+".*");
int idx = urls.indexOf( regex );
if(idx<0){
idx = qrand() % urls.count();
}
return urls[idx];
}
void ZealDocsetMetadata::addUrl(const QString &url){
urls.append(url);
}

View File

@ -9,6 +9,7 @@
#include <QString>
#include <QStringList>
#include <QFile>
#include <QUrl>
class ZealDocsetMetadata //: public QObject
@ -23,6 +24,7 @@ public:
void write(QJsonObject &json) const;
bool isValid() const;
QStringList getUrls() const;
QString getPrimaryUrl() const;
void addUrl(const QString &url);
int getNumUrls() const;
void setVersion(const QString &ver);

View File

@ -188,7 +188,6 @@ void ZealSettingsDialog::updateDocsets()
QList<QListWidgetItem*> items = ui->docsetsList->findItems( QString(name), Qt::MatchFixedString);
if(items.count() > 0){
qDebug()<<"Found!";
items[0]->setCheckState( Qt::Checked );
items[0]->setHidden(false);
reply->setProperty("listItem", ui->docsetsList->row( items[0] ));
@ -359,7 +358,7 @@ void ZealSettingsDialog::extractDocset()
if(metadata.getVersion().isEmpty() || oldMetadata.getVersion() != metadata.getVersion()){
metadata.setFeedURL(reply->request().url().toString());
auto reply2 = startDownload(metadata.getUrls()[0], 1);
auto reply2 = startDownload(metadata.getPrimaryUrl(), 1);
if(listItem != NULL){
listItem->setHidden(false);
@ -697,7 +696,7 @@ QNetworkReply *ZealSettingsDialog::startDownload(const QUrl &url, qint8 retries)
QNetworkReply *ZealSettingsDialog::startDownload(const ZealDocsetMetadata &meta, qint8 retries){
QString url = meta.getFeedURL();
if(url.isEmpty()){
url = meta.getUrls()[0];
url = meta.getPrimaryUrl();
}
QNetworkReply *reply = startDownload( url, retries );
reply->setProperty("metadata", QVariant::fromValue(meta));