1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 01:22:10 +01:00

[GreaseMonkey] Fixed loading invalid script when script file is deleted

Also fixed copyright in gm_jsobect.{cpp,h}
This commit is contained in:
nowrep 2013-04-02 11:57:31 +02:00
parent 51f0232ca3
commit 2e853beef4
5 changed files with 18 additions and 10 deletions

View File

@ -1,5 +1,5 @@
/* ============================================================
* QupZilla - WebKit based browser
* GreaseMonkey plugin for QupZilla
* Copyright (C) 2013 David Rosca <nowrep@gmail.com>
*
* This program is free software: you can redistribute it and/or modify

View File

@ -1,5 +1,5 @@
/* ============================================================
* QupZilla - WebKit based browser
* GreaseMonkey plugin for QupZilla
* Copyright (C) 2013 David Rosca <nowrep@gmail.com>
*
* This program is free software: you can redistribute it and/or modify

View File

@ -139,7 +139,7 @@ void GM_Manager::disableScript(GM_Script* script)
bool GM_Manager::addScript(GM_Script* script)
{
if (!script) {
if (!script || !script->isValid()) {
return false;
}

View File

@ -38,7 +38,7 @@ PluginSpec GM_Plugin::pluginSpec()
spec.name = "GreaseMonkey";
spec.info = "Userscripts for QupZilla";
spec.description = "Provides support for userscripts (www.userscripts.org)";
spec.version = "0.3.0";
spec.version = "0.3.1";
spec.author = "David Rosca <nowrep@gmail.com>";
spec.icon = QPixmap(":gm/data/icon.png");
spec.hasSettings = true;

View File

@ -30,7 +30,11 @@ GM_Script::GM_Script(GM_Manager* manager, const QString &filePath)
: QObject(manager)
, m_manager(manager)
, m_fileWatcher(new QFileSystemWatcher(this))
, m_namespace("GreaseMonkeyNS")
, m_startAt(DocumentEnd)
, m_fileName(filePath)
, m_enabled(true)
, m_valid(false)
{
parseScript();
@ -146,6 +150,10 @@ void GM_Script::watchedFileChanged(const QString &file)
if (m_fileName == file) {
parseScript();
if (!isValid()) {
return;
}
m_manager->removeScript(this, false);
m_manager->addScript(this);
}
@ -153,6 +161,12 @@ void GM_Script::watchedFileChanged(const QString &file)
void GM_Script::parseScript()
{
QFile file(m_fileName);
if (!file.open(QFile::ReadOnly)) {
qWarning() << "GreaseMonkey: Cannot open file for reading" << m_fileName;
return;
}
m_name.clear();
m_namespace = "GreaseMonkeyNS";
m_description.clear();
@ -164,12 +178,6 @@ void GM_Script::parseScript()
m_enabled = true;
m_valid = false;
QFile file(m_fileName);
if (!file.open(QFile::ReadOnly)) {
qWarning() << "GreaseMonkey: Cannot open file for reading" << m_fileName;
return;
}
if (!m_fileWatcher->files().contains(m_fileName)) {
m_fileWatcher->addPath(m_fileName);
}