mirror of
https://github.com/zealdocs/zeal.git
synced 2024-11-30 03:13:56 +03:00
Select preferred download url from feed's source.
This commit is contained in:
parent
74a2920791
commit
53d5c1c579
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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));
|
||||
|
Loading…
Reference in New Issue
Block a user