mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 18:56:34 +01:00
Added documentation for i18n and UserScript QML API
This commit is contained in:
parent
68ba798597
commit
9f6bd308cc
@ -37,11 +37,17 @@ void QmlI18n::initTranslations()
|
|||||||
textdomain(domain.toUtf8());
|
textdomain(domain.toUtf8());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief wrapper for gettext function
|
||||||
|
*/
|
||||||
QString QmlI18n::i18n(const QString &string)
|
QString QmlI18n::i18n(const QString &string)
|
||||||
{
|
{
|
||||||
return QString::fromUtf8(gettext(string.toUtf8()));
|
return QString::fromUtf8(gettext(string.toUtf8()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief wrapper for ngettext function
|
||||||
|
*/
|
||||||
QString QmlI18n::i18np(const QString &string1, const QString &string2, int count)
|
QString QmlI18n::i18np(const QString &string1, const QString &string2, int count)
|
||||||
{
|
{
|
||||||
return QString::fromUtf8(ngettext(string1.toUtf8(), string2.toUtf8(), count));
|
return QString::fromUtf8(ngettext(string1.toUtf8(), string2.toUtf8(), count));
|
||||||
|
@ -24,6 +24,9 @@
|
|||||||
// fatal error C1189: #error : The C++ Standard Library forbids macroizing keywords
|
// fatal error C1189: #error : The C++ Standard Library forbids macroizing keywords
|
||||||
#undef inline
|
#undef inline
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The class exposing GNU Gettext to QML
|
||||||
|
*/
|
||||||
class QmlI18n : public QObject
|
class QmlI18n : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -22,25 +22,52 @@
|
|||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QWebEngineScript>
|
#include <QWebEngineScript>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The class exposing QWebEngineScript to QML
|
||||||
|
*/
|
||||||
class FALKON_EXPORT QmlUserScript : public QObject
|
class FALKON_EXPORT QmlUserScript : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
/**
|
||||||
|
* @brief Checks if the UserScript is null
|
||||||
|
*/
|
||||||
Q_PROPERTY(bool null READ null CONSTANT)
|
Q_PROPERTY(bool null READ null CONSTANT)
|
||||||
|
/**
|
||||||
|
* @brief Name of the UserScript
|
||||||
|
*/
|
||||||
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
|
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
|
||||||
|
/**
|
||||||
|
* @brief Checks if the UserScript runs on sub frames
|
||||||
|
*/
|
||||||
Q_PROPERTY(bool runsOnSubFrames READ runsOnSubFrames WRITE setRunsOnSubFrames NOTIFY runsOnSubFramesChanged)
|
Q_PROPERTY(bool runsOnSubFrames READ runsOnSubFrames WRITE setRunsOnSubFrames NOTIFY runsOnSubFramesChanged)
|
||||||
|
/**
|
||||||
|
* @brief WorldId of the UserScript
|
||||||
|
*/
|
||||||
Q_PROPERTY(int worldId READ worldId WRITE setWorldId NOTIFY worldIdChanged)
|
Q_PROPERTY(int worldId READ worldId WRITE setWorldId NOTIFY worldIdChanged)
|
||||||
|
/**
|
||||||
|
* @brief Source code of the UserScript
|
||||||
|
*/
|
||||||
Q_PROPERTY(QString sourceCode READ sourceCode WRITE setSourceCode NOTIFY sourceCodeChanged)
|
Q_PROPERTY(QString sourceCode READ sourceCode WRITE setSourceCode NOTIFY sourceCodeChanged)
|
||||||
|
/**
|
||||||
|
* @brief Injection point of the UserScript
|
||||||
|
*/
|
||||||
Q_PROPERTY(int injectionPoint READ injectionPoint WRITE setInjectionPoint NOTIFY injectionPointChanged)
|
Q_PROPERTY(int injectionPoint READ injectionPoint WRITE setInjectionPoint NOTIFY injectionPointChanged)
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* @brief The enum exposing QWebEngineScript::InjectionPoint
|
||||||
|
*/
|
||||||
enum InjectionPoint {
|
enum InjectionPoint {
|
||||||
DocumentCreation = QWebEngineScript::DocumentCreation,
|
DocumentCreation = QWebEngineScript::DocumentCreation, //!< Represents QWebEngineScript::DocumentCreation
|
||||||
DocumentReady = QWebEngineScript::DocumentReady,
|
DocumentReady = QWebEngineScript::DocumentReady, //!< Represents QWebEngineScript::DocumentReady,
|
||||||
Deferred = QWebEngineScript::Deferred
|
Deferred = QWebEngineScript::Deferred //!< Represents QWebEngineScript::Deferred
|
||||||
};
|
};
|
||||||
|
/**
|
||||||
|
* @brief The enum wrapping QWebEngineScript::ScriptWorldId
|
||||||
|
*/
|
||||||
enum ScriptWorldId {
|
enum ScriptWorldId {
|
||||||
MainWorld = QWebEngineScript::MainWorld,
|
MainWorld = QWebEngineScript::MainWorld, //!< Represents QWebEngineScript::MainWorld
|
||||||
ApplicationWorld = QWebEngineScript::ApplicationWorld,
|
ApplicationWorld = QWebEngineScript::ApplicationWorld, //!< Represents QWebEngineScript::ApplicationWorld
|
||||||
UserWorld = QWebEngineScript::UserWorld
|
UserWorld = QWebEngineScript::UserWorld //! < Represents QWebEngineScript::UserWorld
|
||||||
};
|
};
|
||||||
Q_ENUMS(InjectionPoint)
|
Q_ENUMS(InjectionPoint)
|
||||||
Q_ENUMS(ScriptWorldId)
|
Q_ENUMS(ScriptWorldId)
|
||||||
@ -49,10 +76,25 @@ public:
|
|||||||
QWebEngineScript webEngineScript() const;
|
QWebEngineScript webEngineScript() const;
|
||||||
void setWebEngineScript(const QWebEngineScript &script);
|
void setWebEngineScript(const QWebEngineScript &script);
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
|
/**
|
||||||
|
* @brief The signal emitted when the script name is changed
|
||||||
|
*/
|
||||||
void nameChanged(const QString &name);
|
void nameChanged(const QString &name);
|
||||||
|
/**
|
||||||
|
* @brief The signal emitted when runsOnSubFrame property of the script is changed
|
||||||
|
*/
|
||||||
void runsOnSubFramesChanged(bool runsOnSubFrames);
|
void runsOnSubFramesChanged(bool runsOnSubFrames);
|
||||||
|
/**
|
||||||
|
* @brief The signal emitted when worldId property of the script is changed
|
||||||
|
*/
|
||||||
void worldIdChanged(int worldId);
|
void worldIdChanged(int worldId);
|
||||||
|
/**
|
||||||
|
* @brief The signal emitted when source code of the script is changed
|
||||||
|
*/
|
||||||
void sourceCodeChanged(const QString &sourceCode);
|
void sourceCodeChanged(const QString &sourceCode);
|
||||||
|
/**
|
||||||
|
* @brief The signal emitted when injectionPoint property of the script is changed
|
||||||
|
*/
|
||||||
void injectionPointChanged(int injectionPoint);
|
void injectionPointChanged(int injectionPoint);
|
||||||
private:
|
private:
|
||||||
QWebEngineScript m_webEngineScript;
|
QWebEngineScript m_webEngineScript;
|
||||||
|
@ -51,6 +51,11 @@ QList<QObject *> QmlUserScripts::toQObjectList(QList<QWebEngineScript> list) con
|
|||||||
return userScriptList;
|
return userScriptList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Checks if the script is in collection
|
||||||
|
* @param object of type QmlUserScript
|
||||||
|
* @return true if the the script in in collection, else false
|
||||||
|
*/
|
||||||
bool QmlUserScripts::contains(QObject *object) const
|
bool QmlUserScripts::contains(QObject *object) const
|
||||||
{
|
{
|
||||||
QmlUserScript *userScript = qobject_cast<QmlUserScript*>(object);
|
QmlUserScript *userScript = qobject_cast<QmlUserScript*>(object);
|
||||||
@ -61,6 +66,11 @@ bool QmlUserScripts::contains(QObject *object) const
|
|||||||
return mApp->webProfile()->scripts()->contains(webEngineScript);
|
return mApp->webProfile()->scripts()->contains(webEngineScript);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Finds a script in collection by name
|
||||||
|
* @param name of the script
|
||||||
|
* @return object of type QmlUserScript, representing the script of given name
|
||||||
|
*/
|
||||||
QObject *QmlUserScripts::findScript(const QString &name) const
|
QObject *QmlUserScripts::findScript(const QString &name) const
|
||||||
{
|
{
|
||||||
QWebEngineScript webEngineScript = mApp->webProfile()->scripts()->findScript(name);
|
QWebEngineScript webEngineScript = mApp->webProfile()->scripts()->findScript(name);
|
||||||
@ -69,12 +79,20 @@ QObject *QmlUserScripts::findScript(const QString &name) const
|
|||||||
return qmlUserScript;
|
return qmlUserScript;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Finds all scripts in collection by a given name
|
||||||
|
* @return list of objects, each of type QmlUserScript, representing the script of given name
|
||||||
|
*/
|
||||||
QList<QObject*> QmlUserScripts::findScripts(const QString &name) const
|
QList<QObject*> QmlUserScripts::findScripts(const QString &name) const
|
||||||
{
|
{
|
||||||
QList<QWebEngineScript> list = mApp->webProfile()->scripts()->findScripts(name);
|
QList<QWebEngineScript> list = mApp->webProfile()->scripts()->findScripts(name);
|
||||||
return toQObjectList(list);
|
return toQObjectList(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Inserts a script into collection
|
||||||
|
* @param object of type QmlUserScript
|
||||||
|
*/
|
||||||
void QmlUserScripts::insert(QObject *object) const
|
void QmlUserScripts::insert(QObject *object) const
|
||||||
{
|
{
|
||||||
QmlUserScript *userScript = qobject_cast<QmlUserScript*>(object);
|
QmlUserScript *userScript = qobject_cast<QmlUserScript*>(object);
|
||||||
@ -85,6 +103,10 @@ void QmlUserScripts::insert(QObject *object) const
|
|||||||
mApp->webProfile()->scripts()->insert(webEngineScript);
|
mApp->webProfile()->scripts()->insert(webEngineScript);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Inserts a list of scripts into collection
|
||||||
|
* @param list of objects, each of type QmlUserScript
|
||||||
|
*/
|
||||||
void QmlUserScripts::insert(const QList<QObject *> &list) const
|
void QmlUserScripts::insert(const QList<QObject *> &list) const
|
||||||
{
|
{
|
||||||
for (QObject *object : list) {
|
for (QObject *object : list) {
|
||||||
@ -97,6 +119,10 @@ void QmlUserScripts::insert(const QList<QObject *> &list) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Removes a script from collection
|
||||||
|
* @param object of type QmlUserScript
|
||||||
|
*/
|
||||||
void QmlUserScripts::remove(QObject *object) const
|
void QmlUserScripts::remove(QObject *object) const
|
||||||
{
|
{
|
||||||
QmlUserScript *userScript = qobject_cast<QmlUserScript*>(object);
|
QmlUserScript *userScript = qobject_cast<QmlUserScript*>(object);
|
||||||
@ -107,6 +133,10 @@ void QmlUserScripts::remove(QObject *object) const
|
|||||||
mApp->webProfile()->scripts()->remove(webEngineScript);
|
mApp->webProfile()->scripts()->remove(webEngineScript);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Gets all the scripts of the collection
|
||||||
|
* @return list of objects, each of type QmlUserScript
|
||||||
|
*/
|
||||||
QList<QObject *> QmlUserScripts::toList() const
|
QList<QObject *> QmlUserScripts::toList() const
|
||||||
{
|
{
|
||||||
QList<QWebEngineScript> list = mApp->webProfile()->scripts()->toList();
|
QList<QWebEngineScript> list = mApp->webProfile()->scripts()->toList();
|
||||||
|
@ -20,11 +20,23 @@
|
|||||||
#include "qmluserscript.h"
|
#include "qmluserscript.h"
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The class exposing QWebEngineScriptCollection to QML
|
||||||
|
*/
|
||||||
class FALKON_EXPORT QmlUserScripts : public QObject
|
class FALKON_EXPORT QmlUserScripts : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
/**
|
||||||
|
* @brief Number of elements in the collection
|
||||||
|
*/
|
||||||
Q_PROPERTY(int count READ count CONSTANT)
|
Q_PROPERTY(int count READ count CONSTANT)
|
||||||
|
/**
|
||||||
|
* @brief Size of the collection
|
||||||
|
*/
|
||||||
Q_PROPERTY(int size READ size CONSTANT)
|
Q_PROPERTY(int size READ size CONSTANT)
|
||||||
|
/**
|
||||||
|
* @brief Checks if the collection is empty
|
||||||
|
*/
|
||||||
Q_PROPERTY(bool empty READ empty CONSTANT)
|
Q_PROPERTY(bool empty READ empty CONSTANT)
|
||||||
public:
|
public:
|
||||||
explicit QmlUserScripts(QObject *parent = nullptr);
|
explicit QmlUserScripts(QObject *parent = nullptr);
|
||||||
|
Loading…
Reference in New Issue
Block a user