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

Method parseScript

src/plugins/GreaseMonkey/gm_script.cpp:219–346  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

217}
218
219void GM_Script::parseScript()
220{
221 m_name.clear();
222 m_namespace = QSL("GreaseMonkeyNS");
223 m_description.clear();
224 m_version.clear();
225 m_include.clear();
226 m_exclude.clear();
227 m_require.clear();
228 m_icon = QIcon();
229 m_iconUrl.clear();
230 m_downloadUrl.clear();
231 m_updateUrl.clear();
232 m_startAt = DocumentEnd;
233 m_noframes = false;
234 m_script.clear();
235 m_enabled = true;
236 m_valid = false;
237
238 QFile file(m_fileName);
239 if (!file.open(QFile::ReadOnly)) {
240 qWarning() << "GreaseMonkey: Cannot open file for reading" << m_fileName;
241 return;
242 }
243
244 if (!m_fileWatcher->files().contains(m_fileName)) {
245 m_fileWatcher->addPath(m_fileName);
246 }
247
248 const QByteArray fileData = file.readAll();
249
250 bool inMetadata = false;
251
252 QTextStream stream(fileData);
253 QString line;
254 while (stream.readLineInto(&line)) {
255 if (line.startsWith(QL1S("// ==UserScript=="))) {
256 inMetadata = true;
257 }
258 if (line.startsWith(QL1S("// ==/UserScript=="))) {
259 break;
260 }
261 if (!inMetadata) {
262 continue;
263 }
264
265 if (!line.startsWith(QLatin1String("// @"))) {
266 continue;
267 }
268
269 line = line.mid(3).replace(QLatin1Char('\t'), QLatin1Char(' '));
270 int index = line.indexOf(QLatin1Char(' '));
271
272 const QString key = line.left(index).trimmed();
273 const QString value = index > 0 ? line.mid(index + 1).trimmed() : QString();
274
275 if (key.isEmpty()) {
276 continue;

Callers

nothing calls this directly

Calls 9

openMethod · 0.80
midMethod · 0.80
indexOfMethod · 0.80
valuesScriptMethod · 0.80
requireScriptsMethod · 0.80
QUrlClass · 0.70
QIconClass · 0.50
clearMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected