fetch the image. Shows a progress dialog
35{
36 Q_ASSERT(!remote.isLocalFile());
37
38 if (remote.scheme() != "data") {
39 QMessageBox msgBox;
40 msgBox.setWindowTitle(i18nc("@title:window", "Krita"));
41 msgBox.setIcon(QMessageBox::Question);
42 msgBox.setText(i18nc("Fetching remote image",
43 "Do you want to download the image from %1?\nClick \"Show Details\" to view the full link "
44 "to the image.")
45 .arg(remote.host()));
46 msgBox.setDetailedText(remote.toDisplayString());
47 msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
48 msgBox.setDefaultButton(QMessageBox::No);
50
51 if (res != QMessageBox::Yes) {
52 return false;
53 }
54 }
55
56 QNetworkAccessManager manager(this);
58 m_request->setRawHeader(
"User-Agent", QString(
"Krita-%1").arg(qApp->applicationVersion()).toUtf8());
60
61 QLocale loc;
62
63 QProgressDialog progress;
64 progress.setWindowTitle(i18nc("@title:window", "Krita"));
65 progress.setLabelText(i18nc("Fetching remote image", "Downloading image from %1...").arg(remote.host()));
66 progress.setMinimum(0);
67 progress.setMaximum(0);
68 progress.setWindowModality(Qt::ApplicationModal);
69 progress.setWindowFlag(Qt::CustomizeWindowHint, true);
70 progress.setWindowFlag(Qt::WindowCloseButtonHint, false);
71 connect(
m_reply, &QNetworkReply::finished, &progress, &QProgressDialog::accept);
72 connect(
m_reply, &QNetworkReply::errorOccurred, &progress, &QProgressDialog::cancel);
73 connect(
m_reply, &QNetworkReply::downloadProgress, &progress, [&](
const int ist,
const int max) {
74 progress.setMaximum(max);
75 progress.setValue(ist);
76 progress.setLabelText(i18nc("Fetching remote image", "Downloading image from %1... (%2 / %3)")
77 .arg(remote.host())
78 .arg(loc.formattedDataSize(ist))
79 .arg(loc.formattedDataSize(max)));
80 });
81
82 connect(&progress, &QProgressDialog::canceled,
m_reply, &QNetworkReply::abort);
83
84 progress.exec();
85
86
88
89 if (
m_reply->error() != QNetworkReply::NoError) {
90 QMessageBox msgBox;
91 msgBox.setWindowTitle(i18nc("@title:window", "Krita"));
92 msgBox.setIcon(QMessageBox::Critical);
93 msgBox.setText(i18nc("Fetching remote image", "Could not download %1.").arg(remote.toDisplayString()));
94 msgBox.setDetailedText(
m_reply->errorString());
95 msgBox.setDefaultButton(QMessageBox::Ok);
96 msgBox.exec();
97 return false;
98 }
99
100 if (!io->isOpen()) {
101 io->open(QIODevice::WriteOnly);
102 }
104 io->close();
105
106 return true;
107}
int doNotAskAgainMessageBoxWrapper(QMessageBox *messageBox, const QString &identifier)
doNotAskAgainMessageBoxWrapper takes a messagebox and an identifier and adds a Do Not Ask Again check...