From dc101a66dad3bf09336556bfd9fc92bb6f723212 Mon Sep 17 00:00:00 2001 From: Syping Date: Fri, 29 Jun 2018 09:57:06 +0200 Subject: [PATCH] fix remote import --- .gitlab-ci.yml | 4 +- ProfileInterface.cpp | 154 ++++++++++++++++++++++++------------------- ProfileInterface.h | 1 + 3 files changed, 91 insertions(+), 68 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c157980..983f135 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -10,7 +10,7 @@ Windows Portable: script: - .gitlab/gitlab.sh artifacts: - name: "gta5view-{$CI_COMMIT_REF_NAME}-${CI_COMMIT_SHA:0:8}_portable" + name: "gta5view-$CI_COMMIT_REF_NAME-${CI_COMMIT_SHA:0:8}_portable" paths: - "gta5view-*.exe" @@ -23,6 +23,6 @@ Windows Installer: script: - .gitlab/gitlab.sh artifacts: - name: "gta5view-{$CI_COMMIT_REF_NAME}-${CI_COMMIT_SHA:0:8}_setup" + name: "gta5view-$CI_COMMIT_REF_NAME-${CI_COMMIT_SHA:0:8}_setup" paths: - "gta5view-*.exe" diff --git a/ProfileInterface.cpp b/ProfileInterface.cpp index 6de5a01..746b2c9 100644 --- a/ProfileInterface.cpp +++ b/ProfileInterface.cpp @@ -838,6 +838,78 @@ bool ProfileInterface::importUrls(const QMimeData *mimeData) return false; } +bool ProfileInterface::importRemote(QUrl remoteUrl) +{ + bool retValue = false; + QDialog urlPasteDialog(this); +#if QT_VERSION >= 0x050000 + urlPasteDialog.setObjectName(QStringLiteral("UrlPasteDialog")); +#else + urlPasteDialog.setObjectName(QString::fromUtf8("UrlPasteDialog")); +#endif + urlPasteDialog.setWindowFlags(urlPasteDialog.windowFlags()^Qt::WindowContextHelpButtonHint^Qt::WindowCloseButtonHint); + urlPasteDialog.setWindowTitle(tr("Import...")); + urlPasteDialog.setModal(true); + QVBoxLayout urlPasteLayout(&urlPasteDialog); +#if QT_VERSION >= 0x050000 + urlPasteLayout.setObjectName(QStringLiteral("UrlPasteLayout")); +#else + urlPasteLayout.setObjectName(QString::fromUtf8("UrlPasteLayout")); +#endif + urlPasteDialog.setLayout(&urlPasteLayout); + UiModLabel urlPasteLabel(&urlPasteDialog); +#if QT_VERSION >= 0x050000 + urlPasteLabel.setObjectName(QStringLiteral("UrlPasteLabel")); +#else + urlPasteLabel.setObjectName(QString::fromUtf8("UrlPasteLabel")); +#endif + + urlPasteLabel.setText(tr("Prepare Content for Import...")); + urlPasteLayout.addWidget(&urlPasteLabel); + urlPasteDialog.setFixedSize(urlPasteDialog.sizeHint()); + urlPasteDialog.show(); + + QNetworkAccessManager *netManager = new QNetworkAccessManager(); + QNetworkRequest netRequest(remoteUrl); + netRequest.setRawHeader("User-Agent", AppEnv::getUserAgent()); + netRequest.setRawHeader("Accept", "text/html"); + netRequest.setRawHeader("Accept-Charset", "utf-8"); + netRequest.setRawHeader("Accept-Language", "en-US,en;q=0.9"); + netRequest.setRawHeader("Connection", "keep-alive"); + QNetworkReply *netReply = netManager->get(netRequest); + QEventLoop *downloadLoop = new QEventLoop(); + QObject::connect(netReply, SIGNAL(finished()), downloadLoop, SLOT(quit())); + QTimer::singleShot(30000, downloadLoop, SLOT(quit())); + downloadLoop->exec(); + downloadLoop->disconnect(); + delete downloadLoop; + + urlPasteDialog.close(); + + if (netReply->isFinished()) + { + QImage *snapmaticImage = new QImage(); + QImageReader snapmaticImageReader; + snapmaticImageReader.setDecideFormatFromContent(true); + snapmaticImageReader.setDevice(netReply); + if (snapmaticImageReader.read(snapmaticImage)) + { + retValue = importImage(snapmaticImage, QDateTime::currentDateTime()); + } + else + { + delete snapmaticImage; + } + } + else + { + netReply->abort(); + } + delete netReply; + delete netManager; + return retValue; +} + bool ProfileInterface::importImage(QImage *snapmaticImage, QDateTime importDateTime) { SnapmaticPicture *picture = new SnapmaticPicture(":/template/template.g5e"); @@ -1462,72 +1534,22 @@ bool ProfileInterface::eventFilter(QObject *watched, QEvent *event) } else { - QDialog urlPasteDialog(this); -#if QT_VERSION >= 0x050000 - urlPasteDialog.setObjectName(QStringLiteral("UrlPasteDialog")); -#else - urlPasteDialog.setObjectName(QString::fromUtf8("UrlPasteDialog")); -#endif - urlPasteDialog.setWindowFlags(urlPasteDialog.windowFlags()^Qt::WindowContextHelpButtonHint^Qt::WindowCloseButtonHint); - urlPasteDialog.setWindowTitle(tr("Import...")); - urlPasteDialog.setModal(true); - QVBoxLayout urlPasteLayout(&urlPasteDialog); -#if QT_VERSION >= 0x050000 - urlPasteLayout.setObjectName(QStringLiteral("UrlPasteLayout")); -#else - urlPasteLayout.setObjectName(QString::fromUtf8("UrlPasteLayout")); -#endif - urlPasteDialog.setLayout(&urlPasteLayout); - UiModLabel urlPasteLabel(&urlPasteDialog); -#if QT_VERSION >= 0x050000 - urlPasteLabel.setObjectName(QStringLiteral("UrlPasteLabel")); -#else - urlPasteLabel.setObjectName(QString::fromUtf8("UrlPasteLabel")); -#endif - - urlPasteLabel.setText(tr("Prepare Content for Import...")); - urlPasteLayout.addWidget(&urlPasteLabel); - urlPasteDialog.setFixedSize(urlPasteDialog.sizeHint()); - urlPasteDialog.show(); - - QNetworkAccessManager *netManager = new QNetworkAccessManager(); - QNetworkRequest netRequest(clipboardUrl); - netRequest.setRawHeader("User-Agent", AppEnv::getUserAgent()); - netRequest.setRawHeader("Accept", "text/html"); - netRequest.setRawHeader("Accept-Charset", "utf-8"); - netRequest.setRawHeader("Accept-Language", "en-US,en;q=0.9"); - netRequest.setRawHeader("Connection", "keep-alive"); - QNetworkReply *netReply = netManager->get(netRequest); - QEventLoop *downloadLoop = new QEventLoop(); - QObject::connect(netReply, SIGNAL(finished()), downloadLoop, SLOT(quit())); - QTimer::singleShot(30000, downloadLoop, SLOT(quit())); - downloadLoop->exec(); - downloadLoop->disconnect(); - delete downloadLoop; - - urlPasteDialog.close(); - - if (netReply->isFinished()) - { - QImage *snapmaticImage = new QImage(); - QImageReader snapmaticImageReader; - snapmaticImageReader.setDecideFormatFromContent(true); - snapmaticImageReader.setDevice(netReply); - if (snapmaticImageReader.read(snapmaticImage)) - { - importImage(snapmaticImage, QDateTime::currentDateTime()); - } - else - { - delete snapmaticImage; - } - } - else - { - netReply->abort(); - } - delete netReply; - delete netManager; + importRemote(clipboardUrl); + } + } + } + else if (clipboardData->hasText()) + { + QUrl clipboardUrl = QUrl::fromUserInput(clipboardData->text()); + if (clipboardUrl.isValid()) + { + if (clipboardUrl.isLocalFile()) + { + importFile(clipboardUrl.toLocalFile(), QDateTime::currentDateTime(), true); + } + else + { + importRemote(clipboardUrl); } } } diff --git a/ProfileInterface.h b/ProfileInterface.h index 3fbc4d0..980c317 100644 --- a/ProfileInterface.h +++ b/ProfileInterface.h @@ -117,6 +117,7 @@ private: bool isSupportedImageFile(QString selectedFileName); bool importFile(QString selectedFile, QDateTime importDateTime, bool notMultiple); bool importUrls(const QMimeData *mimeData); + bool importRemote(QUrl remoteUrl); bool importImage(QImage *snapmaticImage, QDateTime importDateTime); bool importFilesProgress(QStringList selectedFiles); bool importSnapmaticPicture(SnapmaticPicture *picture, bool warn = true);