Browse Source

fix remote import

Syping 5 months ago
parent
commit
dc101a66da
3 changed files with 91 additions and 68 deletions
  1. 2
    2
      .gitlab-ci.yml
  2. 88
    66
      ProfileInterface.cpp
  3. 1
    0
      ProfileInterface.h

+ 2
- 2
.gitlab-ci.yml View File

@@ -10,7 +10,7 @@ Windows Portable:
10 10
   script:
11 11
     - .gitlab/gitlab.sh
12 12
   artifacts:
13
-    name: "gta5view-{$CI_COMMIT_REF_NAME}-${CI_COMMIT_SHA:0:8}_portable"
13
+    name: "gta5view-$CI_COMMIT_REF_NAME-${CI_COMMIT_SHA:0:8}_portable"
14 14
     paths:
15 15
       - "gta5view-*.exe"
16 16
       
@@ -23,6 +23,6 @@ Windows Installer:
23 23
   script:
24 24
     - .gitlab/gitlab.sh
25 25
   artifacts:
26
-    name: "gta5view-{$CI_COMMIT_REF_NAME}-${CI_COMMIT_SHA:0:8}_setup"
26
+    name: "gta5view-$CI_COMMIT_REF_NAME-${CI_COMMIT_SHA:0:8}_setup"
27 27
     paths:
28 28
       - "gta5view-*.exe"

+ 88
- 66
ProfileInterface.cpp View File

@@ -838,6 +838,78 @@ bool ProfileInterface::importUrls(const QMimeData *mimeData)
838 838
     return false;
839 839
 }
840 840
 
841
+bool ProfileInterface::importRemote(QUrl remoteUrl)
842
+{
843
+    bool retValue = false;
844
+    QDialog urlPasteDialog(this);
845
+#if QT_VERSION >= 0x050000
846
+    urlPasteDialog.setObjectName(QStringLiteral("UrlPasteDialog"));
847
+#else
848
+    urlPasteDialog.setObjectName(QString::fromUtf8("UrlPasteDialog"));
849
+#endif
850
+    urlPasteDialog.setWindowFlags(urlPasteDialog.windowFlags()^Qt::WindowContextHelpButtonHint^Qt::WindowCloseButtonHint);
851
+    urlPasteDialog.setWindowTitle(tr("Import..."));
852
+    urlPasteDialog.setModal(true);
853
+    QVBoxLayout urlPasteLayout(&urlPasteDialog);
854
+#if QT_VERSION >= 0x050000
855
+    urlPasteLayout.setObjectName(QStringLiteral("UrlPasteLayout"));
856
+#else
857
+    urlPasteLayout.setObjectName(QString::fromUtf8("UrlPasteLayout"));
858
+#endif
859
+    urlPasteDialog.setLayout(&urlPasteLayout);
860
+    UiModLabel urlPasteLabel(&urlPasteDialog);
861
+#if QT_VERSION >= 0x050000
862
+    urlPasteLabel.setObjectName(QStringLiteral("UrlPasteLabel"));
863
+#else
864
+    urlPasteLabel.setObjectName(QString::fromUtf8("UrlPasteLabel"));
865
+#endif
866
+
867
+    urlPasteLabel.setText(tr("Prepare Content for Import..."));
868
+    urlPasteLayout.addWidget(&urlPasteLabel);
869
+    urlPasteDialog.setFixedSize(urlPasteDialog.sizeHint());
870
+    urlPasteDialog.show();
871
+
872
+    QNetworkAccessManager *netManager = new QNetworkAccessManager();
873
+    QNetworkRequest netRequest(remoteUrl);
874
+    netRequest.setRawHeader("User-Agent", AppEnv::getUserAgent());
875
+    netRequest.setRawHeader("Accept", "text/html");
876
+    netRequest.setRawHeader("Accept-Charset", "utf-8");
877
+    netRequest.setRawHeader("Accept-Language", "en-US,en;q=0.9");
878
+    netRequest.setRawHeader("Connection", "keep-alive");
879
+    QNetworkReply *netReply = netManager->get(netRequest);
880
+    QEventLoop *downloadLoop = new QEventLoop();
881
+    QObject::connect(netReply, SIGNAL(finished()), downloadLoop, SLOT(quit()));
882
+    QTimer::singleShot(30000, downloadLoop, SLOT(quit()));
883
+    downloadLoop->exec();
884
+    downloadLoop->disconnect();
885
+    delete downloadLoop;
886
+
887
+    urlPasteDialog.close();
888
+
889
+    if (netReply->isFinished())
890
+    {
891
+        QImage *snapmaticImage = new QImage();
892
+        QImageReader snapmaticImageReader;
893
+        snapmaticImageReader.setDecideFormatFromContent(true);
894
+        snapmaticImageReader.setDevice(netReply);
895
+        if (snapmaticImageReader.read(snapmaticImage))
896
+        {
897
+            retValue = importImage(snapmaticImage, QDateTime::currentDateTime());
898
+        }
899
+        else
900
+        {
901
+            delete snapmaticImage;
902
+        }
903
+    }
904
+    else
905
+    {
906
+        netReply->abort();
907
+    }
908
+    delete netReply;
909
+    delete netManager;
910
+    return retValue;
911
+}
912
+
841 913
 bool ProfileInterface::importImage(QImage *snapmaticImage, QDateTime importDateTime)
842 914
 {
843 915
     SnapmaticPicture *picture = new SnapmaticPicture(":/template/template.g5e");
@@ -1462,72 +1534,22 @@ bool ProfileInterface::eventFilter(QObject *watched, QEvent *event)
1462 1534
                             }
1463 1535
                             else
1464 1536
                             {
1465
-                                QDialog urlPasteDialog(this);
1466
-#if QT_VERSION >= 0x050000
1467
-                                urlPasteDialog.setObjectName(QStringLiteral("UrlPasteDialog"));
1468
-#else
1469
-                                urlPasteDialog.setObjectName(QString::fromUtf8("UrlPasteDialog"));
1470
-#endif
1471
-                                urlPasteDialog.setWindowFlags(urlPasteDialog.windowFlags()^Qt::WindowContextHelpButtonHint^Qt::WindowCloseButtonHint);
1472
-                                urlPasteDialog.setWindowTitle(tr("Import..."));
1473
-                                urlPasteDialog.setModal(true);
1474
-                                QVBoxLayout urlPasteLayout(&urlPasteDialog);
1475
-#if QT_VERSION >= 0x050000
1476
-                                urlPasteLayout.setObjectName(QStringLiteral("UrlPasteLayout"));
1477
-#else
1478
-                                urlPasteLayout.setObjectName(QString::fromUtf8("UrlPasteLayout"));
1479
-#endif
1480
-                                urlPasteDialog.setLayout(&urlPasteLayout);
1481
-                                UiModLabel urlPasteLabel(&urlPasteDialog);
1482
-#if QT_VERSION >= 0x050000
1483
-                                urlPasteLabel.setObjectName(QStringLiteral("UrlPasteLabel"));
1484
-#else
1485
-                                urlPasteLabel.setObjectName(QString::fromUtf8("UrlPasteLabel"));
1486
-#endif
1487
-
1488
-                                urlPasteLabel.setText(tr("Prepare Content for Import..."));
1489
-                                urlPasteLayout.addWidget(&urlPasteLabel);
1490
-                                urlPasteDialog.setFixedSize(urlPasteDialog.sizeHint());
1491
-                                urlPasteDialog.show();
1492
-
1493
-                                QNetworkAccessManager *netManager = new QNetworkAccessManager();
1494
-                                QNetworkRequest netRequest(clipboardUrl);
1495
-                                netRequest.setRawHeader("User-Agent", AppEnv::getUserAgent());
1496
-                                netRequest.setRawHeader("Accept", "text/html");
1497
-                                netRequest.setRawHeader("Accept-Charset", "utf-8");
1498
-                                netRequest.setRawHeader("Accept-Language", "en-US,en;q=0.9");
1499
-                                netRequest.setRawHeader("Connection", "keep-alive");
1500
-                                QNetworkReply *netReply = netManager->get(netRequest);
1501
-                                QEventLoop *downloadLoop = new QEventLoop();
1502
-                                QObject::connect(netReply, SIGNAL(finished()), downloadLoop, SLOT(quit()));
1503
-                                QTimer::singleShot(30000, downloadLoop, SLOT(quit()));
1504
-                                downloadLoop->exec();
1505
-                                downloadLoop->disconnect();
1506
-                                delete downloadLoop;
1507
-
1508
-                                urlPasteDialog.close();
1509
-
1510
-                                if (netReply->isFinished())
1511
-                                {
1512
-                                    QImage *snapmaticImage = new QImage();
1513
-                                    QImageReader snapmaticImageReader;
1514
-                                    snapmaticImageReader.setDecideFormatFromContent(true);
1515
-                                    snapmaticImageReader.setDevice(netReply);
1516
-                                    if (snapmaticImageReader.read(snapmaticImage))
1517
-                                    {
1518
-                                        importImage(snapmaticImage, QDateTime::currentDateTime());
1519
-                                    }
1520
-                                    else
1521
-                                    {
1522
-                                        delete snapmaticImage;
1523
-                                    }
1524
-                                }
1525
-                                else
1526
-                                {
1527
-                                    netReply->abort();
1528
-                                }
1529
-                                delete netReply;
1530
-                                delete netManager;
1537
+                                importRemote(clipboardUrl);
1538
+                            }
1539
+                        }
1540
+                    }
1541
+                    else if (clipboardData->hasText())
1542
+                    {
1543
+                        QUrl clipboardUrl = QUrl::fromUserInput(clipboardData->text());
1544
+                        if (clipboardUrl.isValid())
1545
+                        {
1546
+                            if (clipboardUrl.isLocalFile())
1547
+                            {
1548
+                                importFile(clipboardUrl.toLocalFile(), QDateTime::currentDateTime(), true);
1549
+                            }
1550
+                            else
1551
+                            {
1552
+                                importRemote(clipboardUrl);
1531 1553
                             }
1532 1554
                         }
1533 1555
                     }

+ 1
- 0
ProfileInterface.h View File

@@ -117,6 +117,7 @@ private:
117 117
     bool isSupportedImageFile(QString selectedFileName);
118 118
     bool importFile(QString selectedFile, QDateTime importDateTime, bool notMultiple);
119 119
     bool importUrls(const QMimeData *mimeData);
120
+    bool importRemote(QUrl remoteUrl);
120 121
     bool importImage(QImage *snapmaticImage, QDateTime importDateTime);
121 122
     bool importFilesProgress(QStringList selectedFiles);
122 123
     bool importSnapmaticPicture(SnapmaticPicture *picture, bool warn = true);