Dirk, it seems, these never got applied. (one more coming). Best Robert Begin forwarded message:
|
From 7555ca86055a95b5ca2595a4979d85de5e16464a Mon Sep 17 00:00:00 2001 From: "Robert C. Helling" <hell...@atdotde.de> Date: Mon, 2 Mar 2015 15:14:55 +0100 Subject: [PATCH 1/3] When loading an image with geodata create a divesite when the dive has none.
Signed-off-by: Robert C. Helling <hell...@atdotde.de> --- dive.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/dive.c b/dive.c index fc0fbb8..d449acd 100644 --- a/dive.c +++ b/dive.c @@ -2927,8 +2927,12 @@ void dive_set_geodata_from_picture(struct dive *d, struct picture *pic) { struct dive_site *ds = get_dive_site_by_uuid(d->dive_site_uuid); if (!dive_site_has_gps_location(ds) && (pic->latitude.udeg || pic->longitude.udeg)) { - ds->latitude = pic->latitude; - ds->longitude = pic->longitude; + if (ds) { + ds->latitude = pic->latitude; + ds->longitude = pic->longitude; + } else { + d->dive_site_uuid = create_dive_site_with_gps("", pic->latitude, pic->longitude); + } } } -- 1.9.3 (Apple Git-50)
From c16405e8564bc5c0435971c1c6da87e5147db0b9 Mon Sep 17 00:00:00 2001 From: "Robert C. Helling" <hell...@atdotde.de> Date: Mon, 2 Mar 2015 16:17:51 +0100 Subject: [PATCH 2/3] Correct signature of helper function Signed-off-by: Robert C. Helling <hell...@atdotde.de> --- qthelper.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qthelper.h b/qthelper.h index 8b553ba..113aee3 100644 --- a/qthelper.h +++ b/qthelper.h @@ -22,7 +22,7 @@ void write_hashes(); void updateHash(struct picture *picture); QByteArray hashFile(const QString filename); void learnImages(const QDir dir, int max_recursions, bool recursed); -void add_hash(const QString filename, QByteArray &hash); +void add_hash(const QString filename, QByteArray hash); QString localFilePath(const QString originalFilename); QString fileFromHash(char *hash); #endif // QTHELPER_H -- 1.9.3 (Apple Git-50)
From 39082a62cdf7ae9f36b925d43111973496c423f1 Mon Sep 17 00:00:00 2001 From: "Robert C. Helling" <hell...@atdotde.de> Date: Mon, 2 Mar 2015 16:18:16 +0100 Subject: [PATCH 3/3] Load remote images When loading an image by filename and by hash fails, try to interpret the filename as URL and download the image. Signed-off-by: Robert C. Helling <hell...@atdotde.de> --- dives/test39.xml | 29 ++++++++++++++++++++++ qt-ui/divepicturewidget.cpp | 59 ++++++++++++++++++++++++++++++++++++++++++--- qt-ui/divepicturewidget.h | 13 ++++++++++ qthelper.cpp | 7 ++++++ qthelper.h | 1 + 5 files changed, 106 insertions(+), 3 deletions(-) create mode 100644 dives/test39.xml diff --git a/dives/test39.xml b/dives/test39.xml new file mode 100644 index 0000000..9b75754 --- /dev/null +++ b/dives/test39.xml @@ -0,0 +1,29 @@ +<divelog program='subsurface' version='3'> +<settings> +<divecomputerid model='Suunto Vyper' deviceid='7fffffff' serial='00522075' firmware='0.0.33'/> +<divecomputerid model='Suunto Vyper' deviceid='e9237b0a' nickname='Suunto Vyper (e9237b0a)'/> + <autogroup state='1' /> +</settings> +<divesites> +<site uuid='47b3e28c' gps='47.934500 11.334500'/> +</divesites> +<dives> +<trip date='2012-01-08' time='15:30:03'> +<dive number='1' divesiteid='47b3e28c' date='2012-01-08' time='15:30:03' duration='46:06 min'> + <notes>This is a dive with an image on a remote server.</notes> + <cylinder size='24.0 l' workpressure='232.0 bar' description='D12 232 bar' /> + <divecomputer model='manually added dive' date='2014-01-09' time='14:22:03'> + <depth max='15.0 m' mean='13.698 m' /> + <sample time='0:00 min' depth='0.0 m' /> + <sample time='0:50 min' depth='15.0 m' /> + <sample time='1:00 min' depth='15.0 m' /> + <sample time='40:00 min' depth='15.0 m' /> + <sample time='42:00 min' depth='5.0 m' /> + <sample time='45:00 min' depth='5.0 m' /> + <sample time='46:06 min' depth='0.0 m' /> + </divecomputer> + <picture filename='http://euve10195.vserver.de/~robert/wreck.jpg' offset='+21:01 min' /> +</dive> +</trip> +</dives> +</divelog> diff --git a/qt-ui/divepicturewidget.cpp b/qt-ui/divepicturewidget.cpp index a0d209b..9c5ac4f 100644 --- a/qt-ui/divepicturewidget.cpp +++ b/qt-ui/divepicturewidget.cpp @@ -6,16 +6,28 @@ #include <QtConcurrentRun> #include <QDir> #include <QCryptographicHash> +#include <QNetworkAccessManager> +#include <QNetworkReply> #include <mainwindow.h> #include <qthelper.h> +#include <QStandardPaths> + +void loadPicuture(struct picture *picture) +{ + ImageDownloader download(picture); + download.load(); +} SHashedImage::SHashedImage(struct picture *picture) : QImage(picture->filename) { if (isNull()) { // Hash lookup. load(fileFromHash(picture->hash)); - if (!isNull()) + if (!isNull()) { QtConcurrent::run(updateHash, picture); + } else { + QtConcurrent::run(loadPicuture, picture); + } } else { QByteArray hash = hashFile(QString(picture->filename)); free(picture->hash); @@ -23,6 +35,45 @@ SHashedImage::SHashedImage(struct picture *picture) : QImage(picture->filename) } } +ImageDownloader::ImageDownloader(struct picture *pic) +{ + picture = pic; +} + +void ImageDownloader::load(){ + QUrl url(picture->filename); + if (url.isValid()) { + QEventLoop loop; + QNetworkRequest request(url); + connect(&manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(saveImage(QNetworkReply *))); + QNetworkReply *reply = manager.get(request); + while (reply->isRunning()) { + loop.processEvents(); + sleep(1); + } + } + +} + +void ImageDownloader::saveImage(QNetworkReply *reply) +{ + QByteArray imageData = reply->readAll(); + QCryptographicHash hash(QCryptographicHash::Sha1); + hash.addData(imageData); + QFile imageFile(QStandardPaths::standardLocations(QStandardPaths::CacheLocation).first().append("/").append(hash.result().toHex())); + if (imageFile.open(QIODevice::WriteOnly)) { + QDataStream stream(&imageFile); + stream.writeRawData(imageData.data(), imageData.length()); + imageFile.waitForBytesWritten(-1); + imageFile.close(); + add_hash(imageFile.fileName(), hash.result()); + learnHash(picture, hash.result()); + DivePictureModel::instance()->updateDivePictures(); + } + reply->manager()->deleteLater(); + reply->deleteLater(); +} + DivePictureModel *DivePictureModel::instance() { static DivePictureModel *self = new DivePictureModel(); @@ -46,8 +97,10 @@ SPixmap scaleImages(picturepointer picture) ret.second = cache.value(picture->filename); } else { int dim = defaultIconMetrics().sz_pic; - QImage p = SHashedImage(picture).scaled(dim, dim, Qt::KeepAspectRatio); - cache.insert(picture->filename, p); + QImage p = SHashedImage(picture); + if(!p.isNull()) + p = p.scaled(dim, dim, Qt::KeepAspectRatio); + cache.insert(picture->filename, p); ret.second = p; } return ret; diff --git a/qt-ui/divepicturewidget.h b/qt-ui/divepicturewidget.h index e8104a1..f879d31 100644 --- a/qt-ui/divepicturewidget.h +++ b/qt-ui/divepicturewidget.h @@ -4,6 +4,7 @@ #include <QAbstractTableModel> #include <QListView> #include <QThread> +#include <QNetworkReply> typedef QPair<QString, QByteArray> SHashedFilename; @@ -17,6 +18,18 @@ public: SHashedImage(struct picture *picture); }; +class ImageDownloader : public QObject { + Q_OBJECT; +public: + ImageDownloader(struct picture *picture); + void load(); +private: + struct picture *picture; + QNetworkAccessManager manager; +private slots: + void saveImage(QNetworkReply *reply); +}; + class DivePictureModel : public QAbstractTableModel { Q_OBJECT public: diff --git a/qthelper.cpp b/qthelper.cpp index 14e67e0..3b0ce10 100644 --- a/qthelper.cpp +++ b/qthelper.cpp @@ -832,6 +832,13 @@ QByteArray hashFile(const QString filename) return hash.result(); } +void learnHash(struct picture *picture, QByteArray hash) +{ + free(picture->hash); + hashOf[QString(picture->filename)] = hash; + picture->hash = strdup(hash.toHex()); +} + QString localFilePath(const QString originalFilename) { return localFilenameOf[hashOf[originalFilename]]; diff --git a/qthelper.h b/qthelper.h index 113aee3..b0765ae 100644 --- a/qthelper.h +++ b/qthelper.h @@ -25,4 +25,5 @@ void learnImages(const QDir dir, int max_recursions, bool recursed); void add_hash(const QString filename, QByteArray hash); QString localFilePath(const QString originalFilename); QString fileFromHash(char *hash); +void learnHash(struct picture *picture, QByteArray hash); #endif // QTHELPER_H -- 1.9.3 (Apple Git-50)
|
signature.asc
Description: Message signed with OpenPGP using GPGMail
_______________________________________________ subsurface mailing list subsurface@subsurface-divelog.org http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface