diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0ba284890..d62abe272 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,4 +1,4 @@
-
+- Desktop: Allow more than one media file to be imported from web
---
* Always add new entries at the very top of this file above other existing entries and this note.
* Use this layout for new entries: `[Area]: [Details about the change] [reference thread / issue]`
diff --git a/desktop-widgets/divelistview.cpp b/desktop-widgets/divelistview.cpp
index 39ec20de0..ca7d6ccba 100644
--- a/desktop-widgets/divelistview.cpp
+++ b/desktop-widgets/divelistview.cpp
@@ -905,46 +905,53 @@ void DiveListView::loadWebImages()
URLDialog urlDialog(this);
if (!urlDialog.exec())
return;
- loadImageFromURL(QUrl::fromUserInput(urlDialog.url()));
+ loadImagesFromURLs(urlDialog.url());
}
-void DiveListView::loadImageFromURL(QUrl url)
+void DiveListView::loadImagesFromURLs(QString urls)
{
- if (url.isValid()) {
- QEventLoop loop;
- QNetworkRequest request(url);
- QNetworkReply *reply = manager.get(request);
- while (reply->isRunning()) {
- loop.processEvents();
- sleep(1);
- }
- QByteArray imageData = reply->readAll();
+ QStringList validUrls;
+ QStringList urlList = urls.split('\n');
+ QStringList::ConstIterator userUrl;
+ for (userUrl = urlList.constBegin(); userUrl != urlList.constEnd(); ++userUrl) {
+ QUrl url = QUrl::fromUserInput(*userUrl);
+ if (url.isValid()) {
+ QEventLoop loop;
+ QNetworkRequest request(url);
+ QNetworkReply *reply = manager.get(request);
+ while (reply->isRunning()) {
+ loop.processEvents();
+ sleep(1);
+ }
+ QByteArray imageData = reply->readAll();
- QImage image = QImage();
- image.loadFromData(imageData);
- if (image.isNull()) {
- // If this is not an image, maybe it's an html file and Miika can provide some xslr magic to extract images.
- // In this case we would call the function recursively on the list of image source urls;
- report_error(qPrintable(tr("%1 does not appear to be an image").arg(url.toString())));
- return;
- }
+ QImage image = QImage();
+ image.loadFromData(imageData);
+ if (image.isNull()) {
+ // If this is not an image, maybe it's an html file and Miika can provide some xslr magic to extract images.
+ // In this case we would call the function recursively on the list of image source urls;
+ report_error(qPrintable(tr("%1 does not appear to be an image").arg(url.toString())));
+ return;
+ }
- QCryptographicHash hash(QCryptographicHash::Sha1);
- hash.addData(url.toString().toUtf8());
- QString path = QStandardPaths::standardLocations(QStandardPaths::CacheLocation).first();
- QDir dir(path);
- if (!dir.exists())
- dir.mkpath(path);
- QFile imageFile(path.append("/").append(hash.result().toHex()));
- if (imageFile.open(QIODevice::WriteOnly)) {
- QDataStream stream(&imageFile);
- stream.writeRawData(imageData.data(), imageData.length());
- imageFile.waitForBytesWritten(-1);
- imageFile.close();
- learnPictureFilename(url.toString(), imageFile.fileName());
- matchImagesToDives(QStringList(url.toString()));
+ QCryptographicHash hash(QCryptographicHash::Sha1);
+ hash.addData(url.toString().toUtf8());
+ QString path = QStandardPaths::standardLocations(QStandardPaths::CacheLocation).first();
+ QDir dir(path);
+ if (!dir.exists())
+ dir.mkpath(path);
+ QFile imageFile(path.append("/").append(hash.result().toHex()));
+ if (imageFile.open(QIODevice::WriteOnly)) {
+ QDataStream stream(&imageFile);
+ stream.writeRawData(imageData.data(), imageData.length());
+ imageFile.waitForBytesWritten(-1);
+ imageFile.close();
+ learnPictureFilename(url.toString(), imageFile.fileName());
+ validUrls << url.toString();
+ }
}
}
+ matchImagesToDives(validUrls);
}
QString DiveListView::lastUsedImageDir()
diff --git a/desktop-widgets/divelistview.h b/desktop-widgets/divelistview.h
index 1853dab1d..5680f58de 100644
--- a/desktop-widgets/divelistview.h
+++ b/desktop-widgets/divelistview.h
@@ -82,7 +82,7 @@ private:
int lastImageTimeOffset();
void addToTrip(int delta);
void matchImagesToDives(QStringList fileNames);
- void loadImageFromURL(QUrl url);
+ void loadImagesFromURLs(QString urls);
bool eventFilter(QObject *, QEvent *) override;
void mouseDoubleClickEvent(QMouseEvent *event) override;
void contextMenuEvent(QContextMenuEvent *event) override;
diff --git a/desktop-widgets/simplewidgets.cpp b/desktop-widgets/simplewidgets.cpp
index 44d22c595..4fc89ac21 100644
--- a/desktop-widgets/simplewidgets.cpp
+++ b/desktop-widgets/simplewidgets.cpp
@@ -279,7 +279,7 @@ URLDialog::URLDialog(QWidget *parent) : QDialog(parent)
QString URLDialog::url() const
{
- return ui.urlField->text();
+ return ui.urlField->toPlainText();
}
bool isGnome3Session()
diff --git a/desktop-widgets/urldialog.ui b/desktop-widgets/urldialog.ui
index a136d1a9e..2727ed449 100644
--- a/desktop-widgets/urldialog.ui
+++ b/desktop-widgets/urldialog.ui
@@ -6,8 +6,8 @@
0
0
- 397
- 103
+ 806
+ 320
@@ -16,8 +16,8 @@
- 40
- 60
+ 460
+ 280
341
32
@@ -29,27 +29,27 @@
QDialogButtonBox::Cancel|QDialogButtonBox::Ok
-
-
-
- 10
- 30
- 371
- 21
-
-
-
10
10
- 151
+ 281
16
- Enter URL for media files
+ Enter URLs for media files, one URL per line
+
+
+
+
+
+ 10
+ 30
+ 781
+ 251
+