| 217 | } |
| 218 | |
| 219 | void 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; |
nothing calls this directly
no test coverage detected