Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak downloadDocsetList method #243

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 28 additions & 9 deletions zeal/zealsettingsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,17 +241,14 @@ void ZealSettingsDialog::downloadDocsetList()
{
QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());

qint8 remainingRetries = replies.take(reply);
if (reply->error() != QNetworkReply::NoError) {
endTasks();
if (reply->request().url().host() == "raw.github.com") {
// allow github to fail
// downloadedDocsetsList will be set either here, or in "if (replies.isEmpty())" below
downloadedDocsetsList = ui->docsetsList->count() > 0;
return;
}
if (reply->error() != QNetworkReply::OperationCanceledError) {
QMessageBox::warning(this, "No docsets found", "Failed retrieving list of docsets: " + reply->errorString());
reportDownloadListFault("Failed retrieving list of docsets: " + reply->errorString());
}
return;
}
Expand All @@ -269,8 +266,11 @@ void ZealSettingsDialog::downloadDocsetList()
name = name.replace(".tar.bz2", "");
if (name != "") {
auto feedUrl = url;
if (url.contains("feeds")) // TODO: There must be a better way to do this, or a valid list of available docset feeds.
feedUrl = url.section("/",0,-2) + "/" + name + ".xml"; // Attempt to generate a docset feed url.
// TODO: There must be a better way to do this, or a valid list of available docset feeds.
if (url.contains("feeds")) {
// Attempt to generate a docset feed url.
feedUrl = url.section("/",0,-2) + "/" + name + ".xml";
}

//urls[name] = feedUrl;
ZealDocsetMetadata meta;
Expand All @@ -292,8 +292,11 @@ void ZealSettingsDialog::downloadDocsetList()
}
if (availMetadata.size() > 0) {
ui->downloadableGroup->show();
} else {
reportDownloadListFault("No downloadable docsets found.");
}
} else {
QString invalidDocsetUrl = "";
QString list = reply->readAll();
for (auto item : list.split("\n")) {
QStringList docset = item.split(" ");
Expand All @@ -304,8 +307,9 @@ void ZealSettingsDialog::downloadDocsetList()
meta.setVersion(docset[2]);
availMetadata[docset[0]] = meta;
if (!docset[1].startsWith("http")) {
// meet an invalid docset url
availMetadata.clear();
QMessageBox::warning(this, "No docsets found", "Failed retrieving https://raw.github.com/jkozera/zeal/master/docsets.txt: " + QString(docset[1]));
invalidDocsetUrl = QString(docset[1]);
break;
}
auto *lwi = new QListWidgetItem(docset[0], ui->docsetsList);
Expand All @@ -320,7 +324,13 @@ void ZealSettingsDialog::downloadDocsetList()
if (availMetadata.size() > 0) {
ui->downloadableGroup->show();
} else {
QMessageBox::warning(this, "No docsets found", QString("No downloadable docsets found."));
if (invalidDocsetUrl == "") {
reportDownloadListFault("No downloadable docsets found.");
} else {
reportDownloadListFault(
"Failed retrieving https://raw.github.com/jkozera/zeal/master/docsets.txt: "
+ invalidDocsetUrl);
}
}
}

Expand All @@ -335,6 +345,14 @@ void ZealSettingsDialog::downloadDocsetList()
reply->deleteLater();
}

void ZealSettingsDialog::reportDownloadListFault(const QString &msg)
{
++downloadListFaultCounter;
if (downloadListFaultCounter == downloadListChance) {
QMessageBox::warning(this, "No docsets found", msg);
}
}

const QString ZealSettingsDialog::getTarPath() const
{
#ifdef WIN32
Expand Down Expand Up @@ -596,6 +614,8 @@ void ZealSettingsDialog::downloadDocsetLists()
auto reply = startDownload(QUrl("https://raw.github.com/jkozera/zeal/master/docsets.txt"));
auto reply2 = startDownload(QUrl("http://kapeli.com/docset_links"));

downloadListFaultCounter = 0;
downloadListChance = 2;
connect(reply, SIGNAL(finished()), SLOT(downloadDocsetList()));
connect(reply2, SIGNAL(finished()), SLOT(downloadDocsetList()));
}
Expand Down Expand Up @@ -757,7 +777,6 @@ void ZealSettingsDialog::stopDownloads()
// Hide progress bar
QVariant itemId = reply->property("listItem");
QListWidgetItem *listItem = ui->docsetsList->item(itemId.toInt());

listItem->setData(ProgressItemDelegate::ProgressVisibleRole, false);

reply->abort();
Expand Down
3 changes: 3 additions & 0 deletions zeal/zealsettingsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,12 @@ private slots:
qint32 totalDownload;
qint32 currentDownload;
qint32 tasksRunning;
unsigned int downloadListFaultCounter;
unsigned int downloadListChance;

ZealSettingsDialog::ProxyType proxyType() const;
void setProxyType(ZealSettingsDialog::ProxyType type);
void reportDownloadListFault(const QString &msg);
};

Q_DECLARE_METATYPE(ZealSettingsDialog::ProxyType)
Expand Down