MCPcopy Create free account
hub / github.com/KDE/falkon / scriptDownloaded

Method scriptDownloaded

src/plugins/GreaseMonkey/gm_downloader.cpp:48–93  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46}
47
48void GM_Downloader::scriptDownloaded()
49{
50 Q_ASSERT(m_reply == qobject_cast<QNetworkReply*>(sender()));
51
52 deleteLater();
53 m_reply->deleteLater();
54
55 if (m_reply->error() != QNetworkReply::NoError) {
56 qWarning() << "GreaseMonkey: Cannot download script" << m_reply->errorString();
57 Q_EMIT error();
58 return;
59 }
60
61 QString contentType = m_reply->header(QNetworkRequest::ContentTypeHeader).toString();
62 if (!(contentType.startsWith(QSL("text/plain")) || contentType.startsWith(QSL("text/javascript")))) {
63 qWarning() << "GreaseMonkey: Unsupported content type" << contentType;
64 Q_EMIT error();
65 return;
66 }
67
68 const QByteArray response = QString::fromUtf8(m_reply->readAll()).toUtf8();
69
70 if (!response.contains(QByteArray("// ==UserScript=="))) {
71 qWarning() << "GreaseMonkey: Script does not contain UserScript header" << m_reply->request().url();
72 Q_EMIT error();
73 return;
74 }
75
76 if (m_fileName.isEmpty()) {
77 const QString filePath = QSL("%1/%2").arg(m_manager->scriptsDirectory(), QzTools::getFileNameFromUrl(m_reply->url()));
78 m_fileName = QzTools::ensureUniqueFilename(filePath);
79 }
80
81 QFile file(m_fileName);
82
83 if (!file.open(QFile::WriteOnly)) {
84 qWarning() << "GreaseMonkey: Cannot open file for writing" << m_fileName;
85 Q_EMIT error();
86 return;
87 }
88
89 file.write(response);
90 file.close();
91
92 Q_EMIT finished(m_fileName);
93}
94
95void GM_Downloader::requireDownloaded()
96{

Callers

nothing calls this directly

Calls 8

headerMethod · 0.80
scriptsDirectoryMethod · 0.80
openMethod · 0.80
errorMethod · 0.45
errorStringMethod · 0.45
containsMethod · 0.45
urlMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected